Guest User

Untitled

a guest
Sep 6th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.75 KB | None | 0 0
  1. <?php
  2. include_once 'influxconnect.php';
  3. include_once 'nexusconnect.php';
  4.     header("Access-Control-Allow-Origin: *");
  5.     header("Access-Control-Allow-Credentials: true");
  6.     header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
  7.     header('Access-Control-Max-Age: 1000');
  8.     header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
  9.  
  10. /* gets the feedwins and vin scrub attributes */
  11. /* $attribute takes parameter of eitehr vin scrub or feed win column in influxconf table of database */
  12.  
  13. /* scrubattributemap = vin scrubbing column */
  14. /* mergeattributemap = feed win column */
  15.  
  16. function getLatestRun($accountId,$provider) {
  17.     global $influxConnect;
  18.     $latestRun = mysqli_query( $influxConnect , "SELECT datefinished FROM importjob WHERE parentid = '$accountId' AND provider ='$provider' ORDER BY datefinished DESC LIMIT 0,1");
  19.     if(!$latestRun){
  20.         echo mysqli_error($influxConnect);
  21.     }
  22.     else if( mysqli_num_rows( $latestRun ) ) {
  23.         $run = mysqli_fetch_array( $latestRun, MYSQLI_ASSOC );
  24.         $date = $run['datefinished'];
  25.         return $date;
  26.     }
  27.     else {
  28.         return false;
  29.     }
  30. }
  31.  
  32. function getInventoryDelimeter($str) {
  33.     $lines = preg_split ('/$\R?^/m', $str);
  34.     $delimiter = 'not found';
  35.     for ($i = 0; $i < sizeof($lines); $i ++) {
  36.         if(strpos($lines[$i],'inv_delimiter')) {
  37.             $delimiter = get_delimited($lines[$i]);
  38.         }
  39.     }
  40.     return $delimiter[0];
  41. }
  42. /*
  43.     if ($conf->{'inv_delimiter'} eq 'fixedwidth') {
  44.                 @veh_array = unpack($conf->{'inv_fixed_template'},$line);
  45.         }
  46.         elsif ($conf->{'inv_delimiter'} eq "pipe") {
  47.                 @veh_array = split(/\|/,$line);
  48.         }
  49.         elsif ($conf->{'inv_delimiter'} eq "pipe_quoted") {
  50.                 $line =~ s/\"//g;
  51.                 @veh_array = split(/\|/,$line);
  52.         }elsif( $conf->{'inv_delimiter'} eq "whitespace_quoted" ){
  53.                 $line =~ s/\"//g;
  54.                 @veh_array = split(/\s+/,$line);
  55.         }
  56.         elsif ($conf->{'inv_delimiter'} eq "comma_quoted") {
  57.                 $line =~ s/\"\"//g;
  58.                 @veh_array = parse_line($line);
  59.         }
  60.         elsif ($conf->{'inv_delimiter'} eq "comma_piped") {
  61.         $line =~ s/\|//;
  62.         @veh_array = split( /\|\,\|/, $line) ;
  63.         }elsif ($conf->{'inv_delimiter'} eq "tab_quoted") {
  64.                 $line =~ s/\"//g;
  65.                 @veh_array = split(/\t/,$line);
  66.         }elsif ($conf->{'inv_delimiter'} eq "caret_piped"){
  67.                 @veh_array = split( /\|\^\|/, $line) ;
  68.                 }
  69.         else {
  70.                 @veh_array = split(/$conf->{'inv_delimiter'}/,$line);
  71.         }
  72. */
  73. function getActualDelimiter($str) {
  74.     switch ($str) {
  75.         case 'pipe':
  76.             $delimiter = '|';
  77.             break;
  78.         case 'comma_quoted':
  79.             $delimiter = '"';
  80.         break;
  81.         default:
  82.             # code...
  83.            break;
  84.     }
  85.     return $delimiter;
  86. }
  87. function get_delimited($str, $delimiter="'") {
  88.     $escapedDelimiter = preg_quote($delimiter, '/');
  89.     if (preg_match_all('/' . $escapedDelimiter . '(.*?)' . $escapedDelimiter . '/s', $str, $matches)) {
  90.         return $matches[1];
  91.     }
  92. }
  93.  
  94. function getHeaderMap($parser) {
  95.     $path = 'http://supporttoolbox.dealerdotcom.corp/staging/hotdog/conf/parser_' . $parser . '.conf';
  96.     $mapArray = array();
  97.     $map = file_get_contents($path);
  98.  
  99.     $map2 = explode('@{$header_map}',$map);
  100.     $map = $map2[1];
  101.     $inv_del = $map2[0];
  102.     $map = explode(');', $map);
  103.     $map = $map[0];
  104.     $map = get_delimited($map);
  105.     $inv_map['headers'] = $map;
  106.     $inv_map['inv_delimiter'] = getInventoryDelimeter($inv_del);
  107.  
  108.     return $inv_map;
  109. }
  110.  
  111. function hasFilter($accountId,$parser) {
  112.     $path = 'http://supporttoolbox.dealerdotcom.corp/staging/hotdog/conf/parser_' . $parser . '.conf';
  113.     $filter = array();
  114.     $filters = file_get_contents($path);
  115.  
  116.     if($filters) {
  117.         $filters = explode('#F',$filters);
  118.         for($i = 0; $i < sizeof($filters); $i++){
  119.             if(strpos($filters[$i],$accountId . ' ')) {
  120.                 $tmp = explode("\nif",$filters[$i],2);
  121.                 $array['task'] = $tmp[0];
  122.                 $array['filter'] = 'if' . $tmp[1];
  123.                 array_push($filter, $array);
  124.             }
  125.         }
  126.         if(sizeof($filter) > 0) {
  127.             return $filter;
  128.         }
  129.         else {
  130.             return false;
  131.         }
  132.     }
  133.     return $parser;
  134. }
  135.  
  136. function getInfluxFeed($accountId,$parser) {
  137.     $username = 'ddchenryl';
  138.     $password = 'Dumptruck69';
  139.  
  140.  
  141.     // $url = 'http://influxtools.dealer.com/cgi-bin/feed_archives.cgi?action=viewRawText&provider=autobase&dealerid=&txt=171chrysler.txt';
  142.  
  143.     $url = 'http://influxtools.dealer.com/cgi-bin/feed_archives.cgi?action=viewRawText&provider=' . $parser . '&dealerid=&txt=' . $accountId . '.txt';
  144.  
  145.     $context = stream_context_create(array(
  146.         'http' => array(
  147.             'header'  => "Authorization: Basic " . base64_encode("$username:$password")
  148.         )
  149.     ));
  150.  
  151.     // logged in, reading contents
  152.     $data = file_get_contents($url, false, $context);
  153.  
  154.     // splitting string of entire feed into array based on the end of each line
  155.     $feedList = preg_split ('/$\R?^/m', $data);
  156.  
  157.     $headMap = getHeaderMap($parser);
  158.  
  159.     $delimiter = getActualDelimiter($headMap['inv_delimiter']);
  160.     $headers = $headMap['headers'];
  161.  
  162.     $vehicles = array();
  163.     $vehicle = array();
  164.     $vehMap = array();
  165.     for($i = 0; $i < sizeof($feedList); $i++) {
  166.         $vehicle = get_delimited($feedList[$i],$delimiter);
  167.         if(sizeof($vehicle) == sizeof($headers)) {
  168.             for ($j = 0; $j < sizeof($vehicle); $j ++) {
  169.                 $vehMap[$headers[$j]] = $vehicle[$j];
  170.             }
  171.             array_push($vehicles, $vehMap);
  172.         }
  173.     }
  174.  
  175.     $vehiclesMapped['headers'] = $headers;
  176.     $vehiclesMapped['vehicles'] = $vehicles;
  177.  
  178.  
  179.     // splitting each line into it's own array inside the feed array
  180.    echo json_encode($vehiclesMapped);
  181.  
  182. }
  183.  
  184. function getInfluxConfigs($id,$accountId) {
  185.     $attsArray = [
  186.     'Year' => '',
  187.     'Make' => '',
  188.     'Model' => '',
  189.     'Mileage' => '',
  190.     'BodyStyle' => '',
  191.     'AskingPrice' => '',
  192.     'Options' => '',
  193.     'Trim' => '',
  194.     'Doors' => '',
  195.     'Engine' => '',
  196.     'EngineSize' => '',
  197.     'Transmission' => '',
  198.     'Comments' => '',
  199.     'WholesalePrice' => '',
  200.     'InvoicePrice' => '',
  201.     'SalePrice' => '',
  202.     'RetailValue' => '',
  203.     'ExteriorColor' => '',
  204.     'InteriorColor' => '',
  205.     'Certified' => '',
  206.     'Image' => '',
  207.     'ModelCode' => '',
  208.     'StockNumber' => '',
  209.     'MSRP' => '',
  210.     'LotDate' => '',
  211.     'OptionCodes' => '',
  212.     'ExtColorCode' => '',
  213.     'IntColorCode' => '',
  214.     'PackageCode' => '',
  215.     'Wheelbase' => '',
  216.     'Fuel' => '',
  217.     'DriveLine' => '',
  218.     'WarrantyDescription' => '',
  219.     'HighwayMPG' => '',
  220.     'CityMPG' => '',
  221.     'Cab' => '',
  222.     'Bed' => '',
  223.     ];
  224.     global $influxConnect;
  225.     $influxConfigs = mysqli_query( $influxConnect , "SELECT * from importfeedconf where id = '$id'");
  226.     if( mysqli_num_rows( $influxConfigs ) ) {
  227.         $config = mysqli_fetch_array( $influxConfigs, MYSQLI_ASSOC );
  228.         $inv_types = getInventoryTypes($config['exclusivetypes'],$accountId);
  229.         $feedWins = $config['mergeattributemap'];
  230.         $scrubAtts = $config['scrubattributemap'];
  231.         $provider = $config['provider'];
  232.         $getLatestRun = getLatestRun($accountId,$provider);
  233.         $hasFilter = hasFilter($accountId,$provider);
  234.         $feedMap = getFeedWins($feedWins);
  235.         $scrubMap = getFeedWins($scrubAtts,$attsArray);
  236.         $config_array = [
  237.         'provider' => $provider,
  238.         'feedWins' => $feedMap,
  239.         'scrubAtts'=> $scrubMap,
  240.         'inventory_types'=> $inv_types,
  241.         'scrubString'=> $scrubAtts,
  242.         'lastRan'=> $getLatestRun,
  243.         'hasFilter' => $hasFilter
  244.         ];
  245.         return $config_array;
  246.     }
  247.     else {
  248.         return false;
  249.     }
  250. }
  251.  
  252.     function classMap($num){
  253.             if($num === 4) {
  254.                 return 'Primary';
  255.             }
  256.             elseif($num === 5){
  257.                 return 'Fleet';
  258.             }
  259.  
  260.             elseif($num === 6){
  261.                 return 'Exotic';
  262.             }
  263.  
  264.             elseif($num === 7){
  265.                 return 'Wholesale';
  266.             }
  267.  
  268.             elseif($num === 8){
  269.                 return 'Classified';
  270.             }
  271.     }
  272.  
  273. function getInventoryName($type,$accountId){
  274.     $type = trim ( $type, " ");
  275.  
  276.     if ($type === '4-1') {
  277.         $typeName = "Primary Used Vehicles";
  278.     }
  279.     elseif($type === '5-1') {
  280.         $typeName = "Fleet Used Vehicles";
  281.     }
  282.     elseif($type === '6-1'){
  283.         $typeName = "Exotic Used Vehicles";
  284.     }
  285.     elseif($type === '7-1'){
  286.         $typeName = "Wholesale Used Vehicles";
  287.     }
  288.     elseif($type === '8-1'){
  289.         $typeName = "Classified Used Vehicles";
  290.     }
  291.     elseif(strpos($type, '4-2') || $type == '4-2'){
  292.         $typeName = "Primary New Vehicles";
  293.     }
  294.     elseif($type === '5-2'){
  295.         $typeName = "Fleet New Vehicles";
  296.     }
  297.     elseif($type === '6-2'){
  298.         $typeName = "Exotic New Vehicles";
  299.     }
  300.     elseif($type === '7-2'){
  301.         $typeName = "Wholesale New Vehicles";
  302.     }
  303.     elseif($type === '8-2'){
  304.         $typeName = "Classified New Vehicles";
  305.     }
  306.     else {
  307.         $typeName = "Type Not Found";
  308.     }
  309.     $typeArray = explode('-',$type);
  310.     $count = getInventoryCounts($typeArray[1],$typeArray[0],$accountId);
  311.     $typeMap = [
  312.         'name' => $typeName,
  313.         'classification' => $typeArray[0],
  314.         'type' => $typeArray[1],
  315.         'count' => $count['count']
  316.     ];
  317.     return $typeMap;
  318. }
  319.  
  320. function getInventoryCounts($type,$classification,$accountId) {
  321.     global $nexusConnect;
  322.     $counts = mysqli_query( $nexusConnect , "SELECT count(*) AS stagingcount from vehicle where parentid = '$accountId' and type = $type and classification = $classification and status > 0 and isremoved = 0");
  323.     if( mysqli_num_rows( $counts ) ) {
  324.         $count = mysqli_fetch_array( $counts, MYSQLI_ASSOC );
  325.         $invCount = $count['stagingcount'];
  326.         $returnCounts = [
  327.             'type' => $type,
  328.             'classification' => $classification,
  329.             'count' => $invCount,
  330.             'accountId' => $accountId
  331.         ];
  332.         return $returnCounts;
  333.     }
  334.     return false;
  335. }
  336.  
  337. function getInventoryTypes($types,$accountId) {
  338.     $typesArray = explode(",",$types);
  339.     $size = sizeof($typesArray);
  340.     $return = array();
  341.     for($i = 0; $i < $size; $i++) {
  342.         $returnName = getInventoryName($typesArray[$i],$accountId);
  343.         $return[$i] = $returnName;
  344.     }
  345.     // $return['size'] = sizeOf($typesArray);
  346.     return $return;
  347. }
  348.  
  349. function getFeedWins($wins, $array = null) {
  350.  if($array == null) {
  351.     $feedWinsArray = [
  352.     'Year' => '',
  353.     'Make' => '',
  354.     'Model' => '',
  355.     'Mileage' => '',
  356.     'BodyStyle' => '',
  357.     'AskingPrice' => '',
  358.     'Options' => '',
  359.     'Trim' => '',
  360.     'Doors' => '',
  361.     'Engine' => '',
  362.     'EngineSize' => '',
  363.     'Transmission' => '',
  364.     'Comments' => '',
  365.     'WholesalePrice' => '',
  366.     'InvoicePrice' => '',
  367.     'SalePrice' => '',
  368.     'RetailValue' => '',
  369.     'ExteriorColor' => '',
  370.     'InteriorColor' => '',
  371.     'Certified' => '',
  372.     'Image' => '',
  373.     'ModelCode' => '',
  374.     'StockNumber' => '',
  375.     'MSRP' => '',
  376.     'LotDate' => '',
  377.     'OptionCodes' => '',
  378.     'ExtColorCode' => '',
  379.     'IntColorCode' => '',
  380.     'PackageCode' => '',
  381.     'Wheelbase' => '',
  382.     'Fuel' => '',
  383.     'DriveLine' => '',
  384.     'WarrantyDescription' => '',
  385.     'HighwayMPG' => '',
  386.     'CityMPG' => '',
  387.     'Cab' => '',
  388.     'Bed' => ''
  389.     ];
  390. }
  391. else {
  392.     $feedWinsArray = $array;
  393. }
  394. $feedMap = array();
  395. $strlen = strlen( $wins );
  396. $char_array = array();
  397. for( $i = 0; $i <= $strlen; $i++ ) {
  398.     $char = substr( $wins, $i, 1 );
  399.     $char_array[$i] = $char;
  400. }
  401. $j = 0;
  402. foreach($feedWinsArray as $key => $value) {
  403.     $feedWinsArray[$key] = $char_array[$j];
  404.     $j = $j + 1;
  405. }
  406. $important = getImportFields($feedWinsArray);
  407. return $important;
  408. }
  409.  
  410. function getImportFields($obj) {
  411.     $wins = array();
  412.     $i = 0;
  413.     foreach($obj as $key => $value) {
  414.         if($value == 'F' || $value =='Y') {
  415.             $wins[$i]['key'] = $key;
  416.             $wins[$i]['value'] = true;
  417.         }
  418.         else {
  419.             $wins[$i]['key'] = $key;
  420.             $wins[$i]['value'] = false;
  421.         }
  422.         $i++;
  423.     }
  424.     return $wins;
  425. }
  426. ?>
  427.  
  428.  
  429.  
  430. <?php
  431.  
  432. if($_SERVER['REQUEST_METHOD'] == "GET") {
  433.   header('Access-Control-Allow-Origin: http://localhost:4200');
  434.   header('Access-Control-Allow-Credentials: true');
  435.   header('Cache-Control: no-cache');
  436.   header('Pragma: no-cache');
  437.   header('Content-Type: text/plain');
  438.   echo 'request method is GET';
  439.   // First See if There Is a Cookie  
  440.   if (!isset($_COOKIE["pageAccess"])) {
  441.     setcookie("pageAccess", 1, time()+2592000);
  442.     echo 'I do not know you or anyone like you so I am going to';
  443.     echo 'mark you with a Cookie :-)';    
  444.   } else {
  445.     $accesses = $_COOKIE['pageAccess'];
  446.     setcookie('pageAccess', ++$accesses, time()+2592000);
  447.    
  448.     echo 'at least ', $accesses-1, ' time(s) before!';
  449.   }  
  450. } elseif($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
  451.   // Tell the Client this preflight holds good for only 20 days
  452.   if($_SERVER['HTTP_ORIGIN'] == "http://localhost:4200") {
  453.     header('Access-Control-Allow-Origin: http://localhost:4200');
  454.     header('Access-Control-Allow-Methods: GET, OPTIONS');
  455.     header('Access-Control-Allow-Credentials: true');
  456.     header('Access-Control-Max-Age: 1728000');
  457.     header("Content-Length: 0");
  458.     header("Content-Type: text/plain");
  459.     echo 'request method is OPTIONS';
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.   } else {
  467.     header("HTTP/1.1 403 Access Forbidden");
  468.     header("Content-Type: text/plain");
  469.     echo "You cannot repeat this request";
  470.  
  471.   }
  472. }
  473.  
  474. ?>
  475.  
  476.  
  477.  
  478. <?php
  479. include_once 'nexusconnect.php';
  480.    
  481.     function getAccountDBID($accountId){
  482.         global $nexusConnect;
  483.         $get_post = mysqli_query( $nexusConnect, "SELECT id FROM account_metadata WHERE account_id = '$accountId'");
  484.         if( mysqli_num_rows( $get_post ) ) {
  485.              $post = mysqli_fetch_array( $get_post, MYSQLI_ASSOC );
  486.             return $post['id'];
  487.         }
  488.         else {
  489.             return mysqli_error($nexusConnect);
  490.         }
  491.     }
  492.  
  493.     function getAPIConfigs($accountId) {
  494.         global $nexusConnect;
  495.         $get_apis = mysqli_query($nexusConnect, "SELECT access type FROM aclentry WHERE accountid = '$accountId' and resource='VAuto' and not aclentry.isremoved and access=1");
  496.         if(mysqli_num_rows($get_apis)) {
  497.             $api = mysqli_fetch_array( $get_apis, MYSQLI_ASSOC );
  498.             $array = [
  499.                 'type' => $api['type'],
  500.             ];
  501.             return $array;        
  502.         }
  503.         else {
  504.             $array = [
  505.                 'type' => 0,
  506.             ];
  507.             return $array;
  508.         }
  509.     }
  510.  
  511.     /*
  512.         Angular2 Model:
  513.             accountId: string;
  514.             name: string;
  515.             publicUrl: string;
  516.             internalUrl: string;
  517.             address1: string;
  518.             address2: string;
  519.             city: string;
  520.             state: string;
  521.             zip: string;
  522.             country: string;
  523.     */
  524.  
  525.     function getAddress($accountId){
  526.         global $nexusConnect;
  527.         $get_address = mysqli_query( $nexusConnect, "SELECT contact.ownerid,contact.company,contact.url,address.address1, address.address2, address.city, address.state, address.postalcode, address.country FROM address, contact WHERE address.isprimary = '1' AND address.parentid = contact.id AND contact.ownerid = '$accountId' GROUP BY ownerid;");
  528.         if( mysqli_num_rows( $get_address ) ) {
  529.              $address = mysqli_fetch_array( $get_address, MYSQLI_ASSOC );
  530.              $internalUrl = 'http://' . $address['ownerid'] . '.cms.dealer.com';
  531.              $publicUrl = 'http://' . $address['url'];
  532.              $account = [
  533.                 'accountId' => $address['ownerid'],
  534.                 'name' => $address['company'],
  535.                 'publicUrl' => $publicUrl,
  536.                 'internalUrl' => $internalUrl,
  537.                 'address1' => $address['address1'],
  538.                 'address2' => $address['address2'],
  539.                 'city' => $address['city'],
  540.                 'state' => $address['state'],
  541.                 'zip' => $address['postalcode'],
  542.                 'country' => $address['country']
  543.              ];
  544.              return $account;
  545.         }
  546.         else {
  547.             $account = [
  548.                 'accountId' => 'no results found',  
  549.                 'name' => 'Please try searching again',
  550.                 'address1' => 'Henrys House'
  551.             ];  
  552.             return $account;
  553.         }
  554.     }
  555.  
  556. ?>
Add Comment
Please, Sign In to add comment