Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'influxconnect.php';
- include_once 'nexusconnect.php';
- header("Access-Control-Allow-Origin: *");
- header("Access-Control-Allow-Credentials: true");
- header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
- header('Access-Control-Max-Age: 1000');
- header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
- /* gets the feedwins and vin scrub attributes */
- /* $attribute takes parameter of eitehr vin scrub or feed win column in influxconf table of database */
- /* scrubattributemap = vin scrubbing column */
- /* mergeattributemap = feed win column */
- function getLatestRun($accountId,$provider) {
- global $influxConnect;
- $latestRun = mysqli_query( $influxConnect , "SELECT datefinished FROM importjob WHERE parentid = '$accountId' AND provider ='$provider' ORDER BY datefinished DESC LIMIT 0,1");
- if(!$latestRun){
- echo mysqli_error($influxConnect);
- }
- else if( mysqli_num_rows( $latestRun ) ) {
- $run = mysqli_fetch_array( $latestRun, MYSQLI_ASSOC );
- $date = $run['datefinished'];
- return $date;
- }
- else {
- return false;
- }
- }
- function getInventoryDelimeter($str) {
- $lines = preg_split ('/$\R?^/m', $str);
- $delimiter = 'not found';
- for ($i = 0; $i < sizeof($lines); $i ++) {
- if(strpos($lines[$i],'inv_delimiter')) {
- $delimiter = get_delimited($lines[$i]);
- }
- }
- return $delimiter[0];
- }
- /*
- if ($conf->{'inv_delimiter'} eq 'fixedwidth') {
- @veh_array = unpack($conf->{'inv_fixed_template'},$line);
- }
- elsif ($conf->{'inv_delimiter'} eq "pipe") {
- @veh_array = split(/\|/,$line);
- }
- elsif ($conf->{'inv_delimiter'} eq "pipe_quoted") {
- $line =~ s/\"//g;
- @veh_array = split(/\|/,$line);
- }elsif( $conf->{'inv_delimiter'} eq "whitespace_quoted" ){
- $line =~ s/\"//g;
- @veh_array = split(/\s+/,$line);
- }
- elsif ($conf->{'inv_delimiter'} eq "comma_quoted") {
- $line =~ s/\"\"//g;
- @veh_array = parse_line($line);
- }
- elsif ($conf->{'inv_delimiter'} eq "comma_piped") {
- $line =~ s/\|//;
- @veh_array = split( /\|\,\|/, $line) ;
- }elsif ($conf->{'inv_delimiter'} eq "tab_quoted") {
- $line =~ s/\"//g;
- @veh_array = split(/\t/,$line);
- }elsif ($conf->{'inv_delimiter'} eq "caret_piped"){
- @veh_array = split( /\|\^\|/, $line) ;
- }
- else {
- @veh_array = split(/$conf->{'inv_delimiter'}/,$line);
- }
- */
- function getActualDelimiter($str) {
- switch ($str) {
- case 'pipe':
- $delimiter = '|';
- break;
- case 'comma_quoted':
- $delimiter = '"';
- break;
- default:
- # code...
- break;
- }
- return $delimiter;
- }
- function get_delimited($str, $delimiter="'") {
- $escapedDelimiter = preg_quote($delimiter, '/');
- if (preg_match_all('/' . $escapedDelimiter . '(.*?)' . $escapedDelimiter . '/s', $str, $matches)) {
- return $matches[1];
- }
- }
- function getHeaderMap($parser) {
- $path = 'http://supporttoolbox.dealerdotcom.corp/staging/hotdog/conf/parser_' . $parser . '.conf';
- $mapArray = array();
- $map = file_get_contents($path);
- $map2 = explode('@{$header_map}',$map);
- $map = $map2[1];
- $inv_del = $map2[0];
- $map = explode(');', $map);
- $map = $map[0];
- $map = get_delimited($map);
- $inv_map['headers'] = $map;
- $inv_map['inv_delimiter'] = getInventoryDelimeter($inv_del);
- return $inv_map;
- }
- function hasFilter($accountId,$parser) {
- $path = 'http://supporttoolbox.dealerdotcom.corp/staging/hotdog/conf/parser_' . $parser . '.conf';
- $filter = array();
- $filters = file_get_contents($path);
- if($filters) {
- $filters = explode('#F',$filters);
- for($i = 0; $i < sizeof($filters); $i++){
- if(strpos($filters[$i],$accountId . ' ')) {
- $tmp = explode("\nif",$filters[$i],2);
- $array['task'] = $tmp[0];
- $array['filter'] = 'if' . $tmp[1];
- array_push($filter, $array);
- }
- }
- if(sizeof($filter) > 0) {
- return $filter;
- }
- else {
- return false;
- }
- }
- return $parser;
- }
- function getInfluxFeed($accountId,$parser) {
- $username = 'ddchenryl';
- $password = 'Dumptruck69';
- // $url = 'http://influxtools.dealer.com/cgi-bin/feed_archives.cgi?action=viewRawText&provider=autobase&dealerid=&txt=171chrysler.txt';
- $url = 'http://influxtools.dealer.com/cgi-bin/feed_archives.cgi?action=viewRawText&provider=' . $parser . '&dealerid=&txt=' . $accountId . '.txt';
- $context = stream_context_create(array(
- 'http' => array(
- 'header' => "Authorization: Basic " . base64_encode("$username:$password")
- )
- ));
- // logged in, reading contents
- $data = file_get_contents($url, false, $context);
- // splitting string of entire feed into array based on the end of each line
- $feedList = preg_split ('/$\R?^/m', $data);
- $headMap = getHeaderMap($parser);
- $delimiter = getActualDelimiter($headMap['inv_delimiter']);
- $headers = $headMap['headers'];
- $vehicles = array();
- $vehicle = array();
- $vehMap = array();
- for($i = 0; $i < sizeof($feedList); $i++) {
- $vehicle = get_delimited($feedList[$i],$delimiter);
- if(sizeof($vehicle) == sizeof($headers)) {
- for ($j = 0; $j < sizeof($vehicle); $j ++) {
- $vehMap[$headers[$j]] = $vehicle[$j];
- }
- array_push($vehicles, $vehMap);
- }
- }
- $vehiclesMapped['headers'] = $headers;
- $vehiclesMapped['vehicles'] = $vehicles;
- // splitting each line into it's own array inside the feed array
- echo json_encode($vehiclesMapped);
- }
- function getInfluxConfigs($id,$accountId) {
- $attsArray = [
- 'Year' => '',
- 'Make' => '',
- 'Model' => '',
- 'Mileage' => '',
- 'BodyStyle' => '',
- 'AskingPrice' => '',
- 'Options' => '',
- 'Trim' => '',
- 'Doors' => '',
- 'Engine' => '',
- 'EngineSize' => '',
- 'Transmission' => '',
- 'Comments' => '',
- 'WholesalePrice' => '',
- 'InvoicePrice' => '',
- 'SalePrice' => '',
- 'RetailValue' => '',
- 'ExteriorColor' => '',
- 'InteriorColor' => '',
- 'Certified' => '',
- 'Image' => '',
- 'ModelCode' => '',
- 'StockNumber' => '',
- 'MSRP' => '',
- 'LotDate' => '',
- 'OptionCodes' => '',
- 'ExtColorCode' => '',
- 'IntColorCode' => '',
- 'PackageCode' => '',
- 'Wheelbase' => '',
- 'Fuel' => '',
- 'DriveLine' => '',
- 'WarrantyDescription' => '',
- 'HighwayMPG' => '',
- 'CityMPG' => '',
- 'Cab' => '',
- 'Bed' => '',
- ];
- global $influxConnect;
- $influxConfigs = mysqli_query( $influxConnect , "SELECT * from importfeedconf where id = '$id'");
- if( mysqli_num_rows( $influxConfigs ) ) {
- $config = mysqli_fetch_array( $influxConfigs, MYSQLI_ASSOC );
- $inv_types = getInventoryTypes($config['exclusivetypes'],$accountId);
- $feedWins = $config['mergeattributemap'];
- $scrubAtts = $config['scrubattributemap'];
- $provider = $config['provider'];
- $getLatestRun = getLatestRun($accountId,$provider);
- $hasFilter = hasFilter($accountId,$provider);
- $feedMap = getFeedWins($feedWins);
- $scrubMap = getFeedWins($scrubAtts,$attsArray);
- $config_array = [
- 'provider' => $provider,
- 'feedWins' => $feedMap,
- 'scrubAtts'=> $scrubMap,
- 'inventory_types'=> $inv_types,
- 'scrubString'=> $scrubAtts,
- 'lastRan'=> $getLatestRun,
- 'hasFilter' => $hasFilter
- ];
- return $config_array;
- }
- else {
- return false;
- }
- }
- function classMap($num){
- if($num === 4) {
- return 'Primary';
- }
- elseif($num === 5){
- return 'Fleet';
- }
- elseif($num === 6){
- return 'Exotic';
- }
- elseif($num === 7){
- return 'Wholesale';
- }
- elseif($num === 8){
- return 'Classified';
- }
- }
- function getInventoryName($type,$accountId){
- $type = trim ( $type, " ");
- if ($type === '4-1') {
- $typeName = "Primary Used Vehicles";
- }
- elseif($type === '5-1') {
- $typeName = "Fleet Used Vehicles";
- }
- elseif($type === '6-1'){
- $typeName = "Exotic Used Vehicles";
- }
- elseif($type === '7-1'){
- $typeName = "Wholesale Used Vehicles";
- }
- elseif($type === '8-1'){
- $typeName = "Classified Used Vehicles";
- }
- elseif(strpos($type, '4-2') || $type == '4-2'){
- $typeName = "Primary New Vehicles";
- }
- elseif($type === '5-2'){
- $typeName = "Fleet New Vehicles";
- }
- elseif($type === '6-2'){
- $typeName = "Exotic New Vehicles";
- }
- elseif($type === '7-2'){
- $typeName = "Wholesale New Vehicles";
- }
- elseif($type === '8-2'){
- $typeName = "Classified New Vehicles";
- }
- else {
- $typeName = "Type Not Found";
- }
- $typeArray = explode('-',$type);
- $count = getInventoryCounts($typeArray[1],$typeArray[0],$accountId);
- $typeMap = [
- 'name' => $typeName,
- 'classification' => $typeArray[0],
- 'type' => $typeArray[1],
- 'count' => $count['count']
- ];
- return $typeMap;
- }
- function getInventoryCounts($type,$classification,$accountId) {
- global $nexusConnect;
- $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");
- if( mysqli_num_rows( $counts ) ) {
- $count = mysqli_fetch_array( $counts, MYSQLI_ASSOC );
- $invCount = $count['stagingcount'];
- $returnCounts = [
- 'type' => $type,
- 'classification' => $classification,
- 'count' => $invCount,
- 'accountId' => $accountId
- ];
- return $returnCounts;
- }
- return false;
- }
- function getInventoryTypes($types,$accountId) {
- $typesArray = explode(",",$types);
- $size = sizeof($typesArray);
- $return = array();
- for($i = 0; $i < $size; $i++) {
- $returnName = getInventoryName($typesArray[$i],$accountId);
- $return[$i] = $returnName;
- }
- // $return['size'] = sizeOf($typesArray);
- return $return;
- }
- function getFeedWins($wins, $array = null) {
- if($array == null) {
- $feedWinsArray = [
- 'Year' => '',
- 'Make' => '',
- 'Model' => '',
- 'Mileage' => '',
- 'BodyStyle' => '',
- 'AskingPrice' => '',
- 'Options' => '',
- 'Trim' => '',
- 'Doors' => '',
- 'Engine' => '',
- 'EngineSize' => '',
- 'Transmission' => '',
- 'Comments' => '',
- 'WholesalePrice' => '',
- 'InvoicePrice' => '',
- 'SalePrice' => '',
- 'RetailValue' => '',
- 'ExteriorColor' => '',
- 'InteriorColor' => '',
- 'Certified' => '',
- 'Image' => '',
- 'ModelCode' => '',
- 'StockNumber' => '',
- 'MSRP' => '',
- 'LotDate' => '',
- 'OptionCodes' => '',
- 'ExtColorCode' => '',
- 'IntColorCode' => '',
- 'PackageCode' => '',
- 'Wheelbase' => '',
- 'Fuel' => '',
- 'DriveLine' => '',
- 'WarrantyDescription' => '',
- 'HighwayMPG' => '',
- 'CityMPG' => '',
- 'Cab' => '',
- 'Bed' => ''
- ];
- }
- else {
- $feedWinsArray = $array;
- }
- $feedMap = array();
- $strlen = strlen( $wins );
- $char_array = array();
- for( $i = 0; $i <= $strlen; $i++ ) {
- $char = substr( $wins, $i, 1 );
- $char_array[$i] = $char;
- }
- $j = 0;
- foreach($feedWinsArray as $key => $value) {
- $feedWinsArray[$key] = $char_array[$j];
- $j = $j + 1;
- }
- $important = getImportFields($feedWinsArray);
- return $important;
- }
- function getImportFields($obj) {
- $wins = array();
- $i = 0;
- foreach($obj as $key => $value) {
- if($value == 'F' || $value =='Y') {
- $wins[$i]['key'] = $key;
- $wins[$i]['value'] = true;
- }
- else {
- $wins[$i]['key'] = $key;
- $wins[$i]['value'] = false;
- }
- $i++;
- }
- return $wins;
- }
- ?>
- <?php
- if($_SERVER['REQUEST_METHOD'] == "GET") {
- header('Access-Control-Allow-Origin: http://localhost:4200');
- header('Access-Control-Allow-Credentials: true');
- header('Cache-Control: no-cache');
- header('Pragma: no-cache');
- header('Content-Type: text/plain');
- echo 'request method is GET';
- // First See if There Is a Cookie
- if (!isset($_COOKIE["pageAccess"])) {
- setcookie("pageAccess", 1, time()+2592000);
- echo 'I do not know you or anyone like you so I am going to';
- echo 'mark you with a Cookie :-)';
- } else {
- $accesses = $_COOKIE['pageAccess'];
- setcookie('pageAccess', ++$accesses, time()+2592000);
- echo 'at least ', $accesses-1, ' time(s) before!';
- }
- } elseif($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
- // Tell the Client this preflight holds good for only 20 days
- if($_SERVER['HTTP_ORIGIN'] == "http://localhost:4200") {
- header('Access-Control-Allow-Origin: http://localhost:4200');
- header('Access-Control-Allow-Methods: GET, OPTIONS');
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 1728000');
- header("Content-Length: 0");
- header("Content-Type: text/plain");
- echo 'request method is OPTIONS';
- } else {
- header("HTTP/1.1 403 Access Forbidden");
- header("Content-Type: text/plain");
- echo "You cannot repeat this request";
- }
- }
- ?>
- <?php
- include_once 'nexusconnect.php';
- function getAccountDBID($accountId){
- global $nexusConnect;
- $get_post = mysqli_query( $nexusConnect, "SELECT id FROM account_metadata WHERE account_id = '$accountId'");
- if( mysqli_num_rows( $get_post ) ) {
- $post = mysqli_fetch_array( $get_post, MYSQLI_ASSOC );
- return $post['id'];
- }
- else {
- return mysqli_error($nexusConnect);
- }
- }
- function getAPIConfigs($accountId) {
- global $nexusConnect;
- $get_apis = mysqli_query($nexusConnect, "SELECT access type FROM aclentry WHERE accountid = '$accountId' and resource='VAuto' and not aclentry.isremoved and access=1");
- if(mysqli_num_rows($get_apis)) {
- $api = mysqli_fetch_array( $get_apis, MYSQLI_ASSOC );
- $array = [
- 'type' => $api['type'],
- ];
- return $array;
- }
- else {
- $array = [
- 'type' => 0,
- ];
- return $array;
- }
- }
- /*
- Angular2 Model:
- accountId: string;
- name: string;
- publicUrl: string;
- internalUrl: string;
- address1: string;
- address2: string;
- city: string;
- state: string;
- zip: string;
- country: string;
- */
- function getAddress($accountId){
- global $nexusConnect;
- $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;");
- if( mysqli_num_rows( $get_address ) ) {
- $address = mysqli_fetch_array( $get_address, MYSQLI_ASSOC );
- $internalUrl = 'http://' . $address['ownerid'] . '.cms.dealer.com';
- $publicUrl = 'http://' . $address['url'];
- $account = [
- 'accountId' => $address['ownerid'],
- 'name' => $address['company'],
- 'publicUrl' => $publicUrl,
- 'internalUrl' => $internalUrl,
- 'address1' => $address['address1'],
- 'address2' => $address['address2'],
- 'city' => $address['city'],
- 'state' => $address['state'],
- 'zip' => $address['postalcode'],
- 'country' => $address['country']
- ];
- return $account;
- }
- else {
- $account = [
- 'accountId' => 'no results found',
- 'name' => 'Please try searching again',
- 'address1' => 'Henrys House'
- ];
- return $account;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment