function getVendors( ) { global $db; $query = "select * from Vendors"; if (!$result = $db->sql_query($query)) { RestLog("Error 16522 in query: $query\n".$db->sql_error()); RestUtils::sendResponse(500, "16522 - There was a problem attempting to locate the PO"); //Internal Server Error return false; } $i = 0; while ( $row = $db->sql_fetchrow( $result ) ) { $vendors[$i]['VendorID'] = $row['VendorID']; $vendors[$i]['VendorName'] = $row['VendorName']; $i++; } RestLog("Successful Request\n"); //08.10.2012 naj - return code 200 OK. RestUtils::sendResponse(200,json_encode( stripHTML( $vendors ) )); return true; }
public function executeApi(sfWebRequest $request) { $data = RestUtils::processRequest(); $res = ""; $code = 200; try { switch ($data->getMethod()) { case 'get': $method = $request->getParameter('method'); $res = $this->{$method}($data); break; case 'post': //parse_str(file_get_contents('php://input'), $put_vars); $method = "post_" . $request->getParameter('method', 'review'); $res = $this->{$method}($data); break; } } catch (BadRequestException $e) { $res = $e->getMessage(); $code = 400; } catch (Exception $e) { $res = $e->getMessage(); $code = 500; } RestUtils::sendResponse($code, json_encode($res), 'application/json'); }
function getItemInfo($vars, $responsetype) { global $db; $ar = $vars; if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ItemNumber'])) { RestLog("16584 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n"); RestUtils::sendResponse(400, "16584 - Insufficient data provided"); //Internal Server Error return false; } //now we grab inventory records for the requested item and build up our package to return //to the dealer //08.28.2015 ghh - added weight field $query = "select Items.ItemID, Items.MSRP, NLA, CloseOut,\n\t\t\t\tPriceCode, Cost, MAP, Category, \n\t\t\t\tManufItemNumber, ManufName, SupersessionID, Weight\n\t\t\t\tfrom Items\n\t\t\t\twhere \n\t\t\t\tItemNumber='{$ar['ItemNumber']}' and\n\t\t\t\tVendorID={$ar['VendorID']}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16585 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16585 - There was a problem getting item information."); //Internal Server Error return false; } $row = $db->sql_fetchrow($result); $item['OrigManufName'] = $row['ManufName']; $item['OrigManufNumber'] = $row['ManufItemNumber']; $item['NLA'] = $row['NLA']; $item['CloseOut'] = $row['CloseOut']; $item['MSRP'] = $row['MSRP']; $item['Category'] = $row['Category']; $item['MAP'] = $row['MAP']; $item['Weight'] = $row['Weight']; //08.28.2015 ghh - if ($row['ItemID'] > 0) { $item['Cost'] = getItemCost($row['ItemID'], $ar['DealerID'], $row['PriceCode'], $row['Cost'], $row['MSRP']); } //08.25.2015 ghh - if BSV asked for full detail then we're also going to send back //images data and other items of interest if ($row['SupersessionID'] > 0) { $query = "select ItemNumber from Items where ItemID={$row['SupersessionID']}"; if (!($tmpresult = $db->sql_query($query))) { RestLog("Error 16586 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16586 - There was a problem retrieving the supersession number"); //Internal Server Error return false; } $tmprow = $db->sql_fetchrow($tmpresult); $item['SupersessionNumber'] = $tmprow['ItemNumber']; } RestLog("Successful Request\n"); //08.10.2012 naj - return code 200 OK. RestUtils::sendResponse(200, json_encode(stripHTML($item))); return true; }
function send($data, $send_data) { //dependiendo de si nuestro cliente quiere json o xml se lo enviaremos de una forma u otra. //echo $data->getHttpAccept(); RestUtils::sendResponse(200, json_encode($send_data), 'application/json'); /*if($data->getHttpAccept() == 'json'){ RestUtils::sendResponse(200, json_encode($send_data),'application/json'); }/*else if($data->getHttpAccept() == 'xml'){ // Usamos el serializador de xml de PEAR $options = array ('indent' => ' ','addDecl' => false,'rootName' => $fc->getAction(), XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); RestUtils::sendResponse(200, $serializer->serialize($send_data),'application/xml'); }//*/ }
public function action_preview_syllabus() { return false; # This needs to be revamped, but the coding for previews is still usable. $rest = new RestServer(); $request = RestUtils::processRequest(); $required = array("filename", "dept"); $keys = array_keys($request); if (count(array_intersect($required, $keys)) != count($required)) { return RestUtils::sendResponse(308); } if (isset($_REQUEST["filename"], $_REQUEST["dept"])) { $width = isset($_REQUEST["w"]) ? $_REQUEST["w"] : 600; $height = isset($_REQUEST["h"]) ? $_REQUEST["h"] : 300; $dept = $_REQUEST["dept"]; $filename = $_REQUEST["filename"]; $user = Yii::app()->user->getState("_user"); if (!$user->has_permission($dept)) { return print "You do not have permission to view this syllabus."; } $file = "C:/archive/" . $dept . "/" . $filename; $pathinfo = pathinfo($file); if ($pathinfo["extension"] == "pdf") { return print '<embed src="http://compass.colorado.edu/archive/' . $dept . '/' . $filename . '#view=FitH" width="' . $width . 'px" height="' . $height . 'px"/>'; } elseif ($pathinfo["extension"] == "doc" or $pathinfo["extension"] == "docx") { return print '<iframe src="//docs.google.com/viewer?url=http%3A%2F%2Fcompass.colorado.edu%2Farchive%2F' . $dept . '%2F' . $filename . '&embedded=true" width="' . $width . 'px" height="' . $height . '" style="border: none;"></iframe>'; } elseif ($pathinfo["extension"] == "txt" or $pathinfo["extension"] == "html") { return print file_get_contents($file); } return print ""; } $syllabus = new SyllabusObj(@$_REQUEST["sid"]); if (!$syllabus->loaded) { return print "Could not load syllabus with id: " . $_REQUEST["sid"]; } $class = new ClassObj($syllabus->classid); if (!$syllabus->loaded) { return print "Could not load class with id: " . $syllabus->classid; } $width = isset($_REQUEST["w"]) ? $_REQUEST["w"] - 50 : 600; $height = isset($_REQUEST["h"]) ? $_REQUEST["h"] - 70 : 300; if ($syllabus->type == "pdf") { return print '<embed src="http://compass.colorado.edu/archive/' . $class->course->prefix . '/' . $syllabus->filename . '#view=FitH" width="' . $width . 'px" height="' . $height . 'px"/>'; } elseif ($syllabus->type == "doc" or $syllabus->type == "docx") { return print '<iframe src="//docs.google.com/viewer?url=http%3A%2F%2Fcompass.colorado.edu%2Farchive%2F' . $class->course->prefix . '%2F' . $syllabus->filename . '&embedded=true" width="' . $width . 'px" height="' . $height . '" style="border: none;"></iframe>'; } return print ""; }
public static function processRequest() { include 'config.php'; $auth_username = $user; $auth_pass = $password; // figure out if we need to challenge the user if (empty($_SERVER['PHP_AUTH_DIGEST'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Digest realm="' . AUTH_REALM . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5(AUTH_REALM) . '"'); // show the error if they hit cancel die(RestUtils::sendResponse(401)); } // now, analayze the PHP_AUTH_DIGEST var if (!($data = self::http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || $auth_username != $data['username']) { // show the error due to bad auth die(RestUtils::sendResponse(401)); } // so far, everything's good, let's now check the response a bit more... $A1 = md5($data['username'] . ':' . AUTH_REALM . ':' . $auth_pass); $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']); $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2); // last check.. if ($data['response'] != $valid_response) { die(RestUtils::sendResponse(401)); } // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our data here $data = array(); if (strcmp($request_method, 'post') == 0) { $data = $_POST; // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however you want $return_obj->setData(json_decode($data['data'])); } return $return_obj; } }
public function actionFBLookup() { $rest = new RestServer(); $request = RestUtils::processRequest(); $required = array("q"); $keys = array_keys($request); if (count(array_intersect($required, $keys)) != count($required)) { return RestUtils::sendResponse(308); } # The Directory we're connecting with is the Active Directory for the Campus # (not to be confused with this application's name) $ldap = new ADAuth("directory"); $ldap->bind_anon(); $info = $ldap->lookup_user($request["q"]); if ($info["count"] == 0) { return print json_encode(array()); } return print json_encode(array($request["attribute"] => @$info[0][$request["attribute"]][0])); }
$pNEG = $pNEG / $pTotal; $pNEU = $pNEU / $pTotal; $pPOS = $pPOS / $pTotal; } // No need to hit the DB again $lab = "NEG"; $score = $pNEG; if ($pNEU > $score) { $lab = "NEU"; $score = $pNEU; } if ($pPOS > $score) { $lab = "POS"; } $probs = array('NEG' => $pNEG, 'NEU' => $pNEU, 'POS' => $pPOS); $res = array('likelihood' => $probs, 'label' => $lab); RestUtils::sendResponse(200, json_encode($res), 'application/json'); } else { RestUtils::sendResponse(400); } break; default: // incorrect method RestUtils::sendResponse(400); } } else { RestUtils::sendResponse(401); } } else { RestUtils::sendResponse(401); }
$from = date("Y.m.d", strtotime($params['rangeFrom'])); $to = date("Y.m.d H-i-s", mktime(23, 59, 59, date("m", strtotime($params['rangeFrom'])), date("d", strtotime($params['rangeFrom'])), date("Y", strtotime($params['rangeFrom'])))); //echo $to; RestUtils::sendResponse(200, json_encode(getSessionsInRange($from, $to)), 'application/json'); } else { RestUtils::sendResponse(400); } } } } else { RestUtils::sendResponse(400); } } } } else { RestUtils::sendResponse(400); } // break; } //returns 1, 0, or -1 // engaged, vacant, error function getBogState() { $query = "SELECT * FROM boglog.session WHERE end_time IS NULL ORDER BY start_time DESC LIMIT 1"; mysql_query($query); return strval(mysql_affected_rows()); } //returns success boolean function disengage() {
} else { $itemType = 'track'; } } // Default to track search } else { $itemType = 'track'; // Default to track search } if (!isset($_GET['limit'])) { $_GET['limit'] = 999; } $retour = API::search($_GET['query'], intval($_GET['id']), $itemType, $_GET['limit']); // $retour = 0 : no result // $retour = null : platform Timeout if ($retour === null) { $status = 204; } else { $status = 200; } if (isset($_GET['json_key'])) { $json_key = $_GET['json_key']; } else { $json_key = null; } RestUtils::sendResponse($status, $retour, "json", false, $json_key); // false = not api mode } else { RestUtils::sendResponse(404, null, "json", false, $json_key); // false = not api mode }
function getShipVendorName($shipvendorid) { global $db; $query = "select ShipVendorName from ShippingVendors where\n\t\t\t\tShipVendorID={$shipvendorid}"; if (!($tmpresult = $db->sql_query($query))) { RestLog("Error 16601 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16601 - There was a problem getting shipping vendor"); //Internal Server Error return false; } $shiprow = $db->sql_fetchrow($tmpresult); return $shiprow['ShipVendorName']; }
} $pathh = "/var/www/StartSync.php {$auth_id['id']} '0.0.0.0' {$new_port}"; error_log("Starting Sync server on port {$new_port} for ID: {$auth_id['id']}"); exec("php -f {$pathh} >/dev/null &"); sleep(2); $results['connection'] = array('ip' => '66.228.33.88', 'port' => $new_port); RestUtils::sendResponse(200, json_encode($results), 'application/json'); } if (isset($get_data['role']) && $get_data['role'] == 'slave') { $active_masters = $auth->get_active_masters('login, id, server_pid, port'); $active_masters_res = array(); foreach ($active_masters as $val) { if (!file_exists("/proc/{$val['server_pid']}")) { $auth->update_auth($val['id'], array('active' => 'no', 'server_pid' => null, 'port' => null)); } else { $active_masters_res[] = array('login' => $val['login'], 'id' => $val['id'], 'server_url' => '66.228.33.88', 'port' => $val['port']); } } if (isset($get_data['master_id'])) { $playlist = new playlist($dbcon); $track = new track($dbcon); $get_playlist = $playlist->get_slave_playlist($get_data['master_id'], 'id, title, description, last_update'); $get_tracks = $track->get_slave_tracks($get_playlist['id'], 't.*'); $get_playlist['tracks'] = $get_tracks; RestUtils::sendResponse(200, json_encode($get_playlist), 'application/json'); } RestUtils::sendResponse(200, json_encode($active_masters_res), 'application/json'); } } break; }
include 'Groups.class.php'; include 'Conversations.class.php'; $request = RestUtils::processRequest(); switch (strtolower($request->getElement())) { case 'restsystem': $element = new System($request); break; case 'restprofiles': $element = new Profiles($request); break; case 'restgroups': $element = new Groups($request); break; case 'restcontacts': $element = new Contacts($request); break; case 'restconversations': $element = new Conversations($request); break; } $response = $element->dispatcher($request); if ($response === false) { RestUtils::error(501); } if (strpos($request->getHttpAccept(), 'xml')) { $type = 'xml'; } else { $type = 'json'; } RestUtils::sendResponse($response->getStatus(), $response->getBody(), $type);
public static function processAPICall($calledMethod, $data) { $valid = API::validateCall(); if (!$valid) { $returnedData = null; $statusCode = 401; } else { switch ($calledMethod) { case 'lookup': if (isset($data->getData()->q)) { $returnedData = API::lookup($data->getData()->q, "api"); $statusCode = 200; } else { // bad request, lacking query $returnedData = null; $statusCode = 400; } break; case 'search': if (isset($data->getData()->q) && isset($data->getData()->platform) && isset($data->getData()->type)) { if (isset($data->getData()->limit)) { $limit = $data->getData()->limit; } else { $limit = 999; } $returnedData = API::search($data->getData()->q, $data->getData()->platform, $data->getData()->type, $limit); if ($returnedData == null) { $returnedData = null; $statusCode = 204; } else { if ($returnedData == -42) { $returnedData = null; $statusCode = 406; } else { $statusCode = 200; } } } else { // bad request, lacking query $returnedData = null; $statusCode = 400; } break; case 'aggregate': if (isset($data->getData()->q) && isset($data->getData()->type)) { if (isset($data->getData()->limit)) { $limit = $data->getData()->limit; } else { $limit = 999; } if (isset($data->getData()->platforms)) { $platforms = explode(',', $data->getData()->platforms); } else { $platforms = null; } $returnedData = API::aggregate($data->getData()->q, $data->getData()->type, $platforms, $limit); $statusCode = 200; } else { // bad request, lacking query $returnedData = null; $statusCode = 400; } break; default: // Method name is not good $returnedData = null; $statusCode = 501; break; } } RestUtils::sendResponse($statusCode, $returnedData, $data->getHttpAccept(), true, null); // true = api mode, null = no key for json }
$podcasts[$i] = new Podcast($bdd_drupal, $elem, $date); } } } for ($i = $second; $i != 24; $i++) { if (!isset($podcasts[$i])) { $entries = get_paulo_entries($date, $i, $bdd_paulo, ".."); if ($entries && count($entries) > 0) { $podcasts[$i] = new Podcast($bdd_drupal, $i, $entries, 1, $date); } } } // on modifie les écoutes, et on ajoute les titres pour les 100% foreach ($podcasts as $p) { $p->setEcoutes($ecoutes); if ($p->is100p100()) { $entries = get_paulo_entries($date, $p->time, $bdd_paulo, ".."); $p->set_paulo_entries($entries); } } // retour switch ($data->getMethod()) { case 'get': RestUtils::sendResponse(200, json_encode($podcasts, JSON_HEX_APOS), 'application/json'); break; case 'post': RestUtils::sendResponse(200, json_encode($podcasts, JSON_HEX_APOS), 'application/json'); break; default: break; }
RestUtils::sendResponse('ERROR: No resource data found', 404); } // FORMAT RESULTS TO JSON $strJson = RestUtils::getJson($mixData[1]); // SEND RESULT RestUtils::sendResponse($strJson, 200); break; // POST // POST case 'post': // SET VARIABLES $arrVariables = $_POST; // BASED ON ROUTING INFO, CALL ORM FUNCTION $objResource = new ResourceUtils(); $txtResponse = $objResource->postData($strResourceName, $intResourceID, $arrVariables); // SEND RESPONSE if ($txtResponse[0]) { RestUtils::sendResponse($txtResponse[1], 500); } else { RestUtils::sendResponse($txtResponse[1], 201); } break; // PUT // PUT case 'put': break; // DELETE // DELETE case 'delete': break; }
//08.25.2015 ghh - added getinventory request RestLog("Getting Order Status"); require_once "getorderstatus.php"; getOrderStatus($requestvars, $responsetype); break; default: die(RestUtils::sendResponse(400, 'Error 16542: Bad Request')); //Bad Request break; } break; //08.20.2015 ghh - send requests enter here //08.20.2015 ghh - send requests enter here case 'post': switch ($requesttype) { case 'sendorder': RestLog("Send Order Called"); require_once "sendorder.php"; sendOrder($requestvars, $responsetype); break; default: die(RestUtils::sendResponse(400, 'Error 16543 Bad Request')); //Bad Request break; } break; default: die(RestUtils::sendResponse(400, 'Error 16544 Bad Post/Get Request')); //Bad Request break; }
require _PATH . 'include/api/RestUtils.class.php'; // Somehow secure AJAX Request // For those that don't set the HTTP REFERER, it works (au cas ou...) if (strtolower(@$_SERVER['HTTP_X_REQUESTED_WITH']) != "xmlhttprequest" || isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER["HTTP_REFERER"], _SITE_URL) === false) { header("Location: /503"); exit; } if (isset($_GET['str'])) { $retour = API::lookup($_GET['str'], "playlist"); if ($retour['lookedUpPlatform'] != -1) { try { $retour = API::getPlatform($retour['lookedUpPlatform'])->retrievePlaylist($_GET['str']); } catch (PlatformTimeoutException $e) { $retour = null; } } else { $retour = null; } // $retour = 0 : no result // $retour = null : platform Timeout if ($retour === null) { $status = 204; } else { $status = 200; } RestUtils::sendResponse($status, $retour, "json", false, null); // false = not api mode, null = no key for json } else { RestUtils::sendResponse(404, null, "json", false, null); // false = not api mode, null = no key for json }
public static function getJson($mixData) { // START JSON $strJson = '{'; // IS DATA ARRAY if (is_array($mixData)) { if (!empty($mixData)) { $objFirst = $mixData[0]; $strNoun = get_class($objFirst); $strJson .= '"' . $strNoun . 'List":'; $strJson .= '{"' . $strNoun . '":['; foreach ($mixData as $objData) { $strJson .= json_encode($objData->GetArray()) . ','; } $strJson = substr($strJson, 0, -1) . ']}'; } else { RestUtils::sendResponse('ERROR: No resource data found', 404); } } else { $strNoun = get_class($mixData); $strJson .= '"' . $strNoun . '":' . json_encode($mixData->GetArray()); } // END JSON $strJson .= '}'; return $strJson; }
function getInventory($vars, $responsetype) { global $db; $ar = $vars; if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ItemNumber'])) { RestLog("16575 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n"); RestUtils::sendResponse(400, "16575 - Insufficient data provided"); //Internal Server Error return false; } //now we grab inventory records for the requested item and build up our package to return //to the dealer //08.26.2015 rch - Moving ItemStock,Warehouses,DaysToFullfill to left outer joins //to account for not stocking an item or not putting in warehouse //08.28.2015 ghh - added Weight $query = "select Items.ItemID, Items.MSRP, NLA, CloseOut,\n\t\t\t\tPriceCode, Cost, MAP, Category, WarehouseName, \n\t\t\t\tWarehouseState, Qty, DaysToArrive, Weight\n\t\t\t\tManufItemNumber, ManufName, SupersessionID\n\t\t\t\tfrom Items\n\t\t\t\tleft outer join ItemStock on ItemStock.ItemID = Items.ItemID \n\t\t\t\tleft outer join Warehouses on Warehouses.WarehouseID = ItemStock.WarehouseID\n\t\t\t\tleft outer join DaysToFullfill on DaysToFullfill.WarehouseID = ItemStock.WarehouseID\n\t\t\t\twhere Items.ItemNumber='{$ar['ItemNumber']}' and\n\t\t\t\tItems.VendorID={$ar['VendorID']} and\n\t\t\t\tDaysToFullfill.DealerID={$ar['DealerID']} order by DaysToArrive"; if (!($result = $db->sql_query($query))) { RestLog("Error 16576 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16576 - There was a problem getting inventory information."); //Internal Server Error return false; } $i = 0; $itemid = 0; while ($row = $db->sql_fetchrow($result)) { //grabbing our details on first run through as no sense in grabbing //more than once. if ($itemid == 0) { $itemid = $row['ItemID']; $OrigManufName = $row['ManufName']; $OrigManufNumber = $row['ManufItemNumber']; $NLA = $row['NLA']; $CloseOut = $row['CloseOut']; $MSRP = $row['MSRP']; $Category = $row['Category']; $MAP = $row['MAP']; $Weight = $row['Weight']; //08.28.2015 ghh - } $rst[$i]['WarehouseName'] = $row['WarehouseName']; $rst[$i]['WarehouseState'] = $row['WarehouseState']; $rst[$i]['Qty'] = $row['Qty']; $rst[$i]['DaysToArrive'] = $row['DaysToArrive']; $i++; } if ($itemid > 0) { $item['Warehouses'] = $rst; $item['MSRP'] = $MSRP; if ($itemid > 0) { $item['Cost'] = getItemCost($itemid, $ar['DealerID'], $row['PriceCode'], $row['Cost'], $row['MSRP']); } //08.25.2015 ghh - if BSV asked for full detail then we're also going to send back //images data and other items of interest if ($row['SupersessionID'] > 0) { $query = "select ItemNumber from Items where ItemID={$row['SupersessionID']}"; if (!($tmpresult = $db->sql_query($query))) { RestLog("Error 16578 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16578 - There was a problem retrieving the supersession number"); //Internal Server Error return false; } $tmprow = $db->sql_fetchrow($tmpresult); $item['SupersessionNumber'] = $tmprow['ItemNumber']; } $item['OrigManufName'] = $ManufName; $item['OrigManufNumber'] = $ManufItemNumber; $item['NLA'] = $NLA; $item['Category'] = $Category; $item['MAP'] = $MAP; //08.25.2015 ghh - now we're getting a list of images that may exist for this //item $query = "select * from ItemImages where ItemID={$itemid}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16577 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16577 - There was a problem retrieving a list of images"); //Internal Server Error return false; } $i = 0; while ($row = $db->sql_fetchrow($result)) { $img[$i]['ImageURL'] = $row['ImageURL']; $img[$i]['ImageSize'] = $row['ImageSize']; $i++; } $item['Images'] = $img; } else { RestLog("Error 16635 The item number being requested doesn't exist\n"); RestUtils::sendResponse(500, "16635 - The Item you requested was not found."); //Internal Server Error return false; } RestLog("Successful Request\n"); //08.10.2012 naj - return code 200 OK. RestUtils::sendResponse(200, json_encode(stripHTML($item))); return true; }
function sendOrder($vars, $responsetype) { global $db; $ar = json_decode($vars['Data']['Data'], true, 5); if (empty($ar) || !isset($ar['PONumber']) || !isset($ar['Status']) || empty($ar['Items']) && empty($ar['Units'])) { RestLog("16521 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n"); RestUtils::sendResponse(400, "16521 - Insufficient data provided"); //Internal Server Error return false; } //08.21.2015 ghh - before we get started we need to see if the current dealer //already has a PO in the system matching what they are now sending. If so we're //going to be updating it if its pending or if it hasn't been pulled by the primary //vendor system yet. $query = "select POID, Status from PurchaseOrders where PONumber='{$ar['PONumber']}' and\n\t\t\t\tDealerID={$vars['DealerID']}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16522 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16522 - There was a problem attempting to locate the PO"); //Internal Server Error return false; } //if we have no purchase order at all then we're going to be inserting a new one if ($db->sql_numrows($result) == 0) { $shiptofields = ''; $shiptovals = ''; if ($ar['ShipToAddress1'] != '') { $shiptofields = "ShipToFirstName, ShipToLastName, ShipToCompany,\n\t\t\t\t\t\t\t\tShipToAddress1, ShipToAddress2, ShipToCity, ShipToState,\n\t\t\t\t\t\t\t\tShipToZip, ShipToCountry, ShipToPhone, ShipToEmail,"; if ($ar['ShipToFirstName'] == '') { $shiptovals = "'',"; } else { $shiptovals = "'{$ar['ShipToFirstName']}',"; } if ($ar['ShipToLastName'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToLastName']}',"; } if ($ar['ShipToCompany'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToCompany']}',"; } if ($ar['ShipToAddress1'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToAddress1']}',"; } if ($ar['ShipToAddress2'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToAddress2']}',"; } if ($ar['ShipToCity'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToCity']}',"; } if ($ar['ShipToState'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToState']}',"; } if ($ar['ShipToZip'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToZip']}',"; } if ($ar['ShipToCountry'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToCountry']}',"; } if ($ar['ShipToPhone'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToPhone']}',"; } if ($ar['ShipToEmail'] == '') { $shiptovals .= "'',"; } else { $shiptovals .= "'{$ar['ShipToEmail']}',"; } if ($ar['PaymentMethod'] == '') { $shiptovals .= "1,"; } else { $shiptovals .= "'{$ar['PaymentMethod']}',"; } if ($ar['ShipMethod'] == '') { $shiptovals .= "1,"; } else { $shiptovals .= "'{$ar['ShipMethod']}',"; } } $query = "insert into PurchaseOrders (Status, DealerID, BSVKeyID, PONumber,\n\t\t\t\tDateCreated, {$shiptofields} LastFour,OrderType) values \n\t\t\t\t( {$ar['Status']}, {$vars['DealerID']}, {$vars['BSVKeyID']}, '{$ar['PONumber']}', now(),\n\t\t\t\t{$shiptovals} '{$ar['LastFour']}',{$ar['OrderType']} )\n\t\t\t\t"; } else { //if we do have a purchase order we need to determine if its ok to update it or not //and return error if its not. $row = $db->sql_fetchrow($result); $poid = $row['POID']; //08.21.2015 ghh - if the status is greater than 2 it means the supplier has already //started pulling the order and we can no longer update it. In this case we're going //to die and return error if ($row['Status'] > 2) { RestLog("Purchase has already been pulled by supplier {$ar['PONumber']}\n"); RestUtils::sendResponse(409, "Order has already been pulled by supplier"); //Internal Server Error return false; } //if we reach here then it must be ok to update the purchase order data so will build the //query here $query = "update PurchaseOrders set "; if ($ar['ShipToAddress1'] != '') { if ($ar['ShipToFirstName'] != '') { $query1 .= "ShipToFirstName='{$ar['ShipToFirstName']}',"; } if ($ar['ShipToLastName'] != '') { $query1 .= "ShipToLastName='{$ar['ShipToLastName']}',"; } if ($ar['ShipToCompany'] != '') { $query1 .= "ShipToCompany='{$ar['ShipToCompany']}',"; } if ($ar['ShipToAddress1'] != '') { $query1 .= "ShipToAddress1='{$ar['ShipToAddress1']}',"; } if ($ar['ShipToAddress2'] != '') { $query1 .= "ShipToAddress2='{$ar['ShipToAddress2']}',"; } if ($ar['ShipToCity'] != '') { $query1 .= "ShipToCity='{$ar['ShipToCity']}',"; } if ($ar['ShipToState'] != '') { $query1 .= "ShipToState='{$ar['ShipToState']}',"; } if ($ar['ShipToZip'] != '') { $query1 .= "ShipToZip='{$ar['ShipToZip']}',"; } if ($ar['ShipToCountry'] != '') { $query1 .= "ShipToCountry='{$ar['ShipToCountry']}',"; } if ($ar['ShipToPhone'] != '') { $query1 .= "ShipToPhone='{$ar['ShipToPhone']}',"; } if ($ar['ShipToEmail'] != '') { $query1 .= "ShipToEmail='{$ar['ShipToEmail']}',"; } } if ($ar['PaymentMethod'] != '') { $query1 .= "PaymentMethod={$ar['PaymentMethod']},"; } if ($ar['LastFour'] != '') { $query1 .= "LastFour='{$ar['LastFour']}',"; } if ($ar['ShipMethod'] != '') { $query1 .= "ShipMethod='{$ar['ShipMethod']}',"; } //if we are actually updating the PO then we're also going ot update the //poreceiveddate if ($query1 != '') { $query1 .= " DateLastModified=now() "; $query .= "{$query1} where DealerID={$vars['DealerID']} and PONumber='{$ar['PONumber']}'"; } else { $query = ''; } } //08.21.2015 ghh - now we execute either of the two queries above to update or insert //the purchase order itself. if ($query != '') { if (!($result = $db->sql_query($query))) { RestLog("Error 16523 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16523 - There was a problem attempting to insert/update the PO"); return false; } } //if we don't already have a poid then we must have done an insert so we'll grab it now if (!$poid > 0) { $poid = $db->sql_nextid($result); } ####################################################PARTS########################################### //now that the purchase order has been updated we'll next start taking a look //at the items and units arrays //08.21.2015 rch - we need to loop through each item that is passed in and evaluate whether or not //we are inserting the po or updating the po $i = 0; foreach ($ar['Items'] as $value => $key) { //08.21.2015 rch - first we need to see if the item is already on the order $query = "select POItemID, Quantity \n\t\t\t\t\tfrom PurchaseOrderItems\n\t\t\t\t\twhere POID='{$poid}' and ItemNumber = '{$key['ItemNumber']}'\n\t\t\t\t\tand VendorID = '{$key['VendorID']}'"; if (!($result = $db->sql_query($query))) { RestLog("Error 16524 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16524 - There was an error locating purchase order items"); return false; } //08.21.2015 rch - we want to make sure that we have a partnumber and vendorid //before attempting to insert. if ($key['ItemNumber'] != '' && $key['VendorID'] != '') { //08.21.2015 ghh - before we bother inserting the item we're going to first grab some //details from items so we can build up our response. $query = "select ItemID, NLA, CloseOut, PriceCode, Category, SupersessionID, \n\t\t\t\t\tMSRP, Cost\n\t\t\t\t\tfrom\n\t\t\t\t\tItems where ItemNumber='{$key['ItemNumber']}' and VendorID={$key['VendorID']}"; if (!($itemresult = $db->sql_query($query))) { RestLog("Error 16526 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16526 - There was an error locating the order item"); return false; } $itemrow = $db->sql_fetchrow($itemresult); if ($db->sql_numrows($itemresult) == 0) { RestLog("Error 16545 The ItemNumber or VendorID you sent are not valid"); RestUtils::sendResponse(500, "16545 - The Item Number or VendorID passed are invalid"); return false; } //now lets see if we can calculate the cost for the current dealer $cost = getItemCost($itemrow['ItemID'], $vars['DealerID'], $itemrow['PriceCode'], $itemrow['Cost'], $itemrow['MSRP']); } else { RestLog("{$row['PONumber']} is missing a vendor id\n"); RestUtils::sendResponse(409, "{$key['ItemNumber']} is missing a vendor id"); return false; } //08.21.2015 rch - if we enter here,the partnumber does not exist on the po if ($db->sql_numrows($result) == 0) { //08.21.2015 ghh - make sure the non required fields have a value if ($key['FillStatus'] == '') { $key['FillStatus'] = 0; } if ($key['OrderType'] == '') { $key['OrderType'] = 2; } $query = "insert into PurchaseOrderItems (POItemID,POID,ItemNumber,Quantity,\n\t\t\t\t\t FillStatus,ItemID,VendorID) values ( '','{$poid}','{$key['ItemNumber']}',{$key['Qty']},\n\t\t\t\t\t {$key['FillStatus']},{$itemrow['ItemID']}, {$key['VendorID']})"; } else { //08.21.2015 rch - if we enter here,the item is already in the table and just needs to be //updated $row = $db->sql_fetchrow($result); //08.21.2015 rch - here we are updating the purchase order items table $query = "update PurchaseOrderItems set "; if ($key['Qty'] != '') { $query1 = "Quantity={$key['Qty']}"; } if ($query1 != '') { $query .= "{$query1} where POItemID={$row['POItemID']}"; } else { $query = ''; } } //08.21.2015 rch - now we need to execute the query if ($query != '') { if (!($result = $db->sql_query($query))) { RestLog("Error 16525 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16525 - There was a problem attempting to insert/update the PO"); //Internal Server Error return false; } //08.24.2015 ghh - update the PO with the current time for last modified date $query = "update PurchaseOrders set DateLastModified=now() where POID = {$poid}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16548 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16548 - There was a problem updating the last modified date"); //Internal Server Error return false; } } //08.21.2015 ghh - now we need to figure out what our current inventory is //minus any items already on orders so that we pass back a fairly reasonable //backorder response $query = "select (ifnull(sum(p1.Quantity), 0) - ifnull(sum(p2.QtyShipped),0)) as qty \n\t\t\t\t\tfrom PurchaseOrderItems p1 \n\t\t\t\t\tleft outer join PurchaseOrderShipped p2 on p1.POItemID=p2.POItemID \n\t\t\t\t\twhere ItemID={$itemrow['ItemID']}"; if (!($qtyresult = $db->sql_query($query))) { RestLog("Error 16529 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16529 - There was an error getting total on order"); return false; } $qtyrow = $db->sql_fetchrow($qtyresult); $qtyonorder = $qtyrow['qty']; $query = "select sum( Qty ) as Qty from ItemStock where ItemID={$itemrow['ItemID']}"; if (!($qtyresult = $db->sql_query($query))) { RestLog("Error 16530 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16530 - There was an error getting total stock qty"); return false; } $qtyrow = $db->sql_fetchrow($qtyresult); $qtyinstock = $qtyrow['Qty']; //08.21.2015 ghh - now we have all of our return information and have updated or //inserted into the items list for the purchase order so we only need to build our //response now. $items[$i]['VendorID'] = $key['VendorID']; $items[$i]['ItemNumber'] = $key['ItemNumber']; $items[$i]['Superseded'] = $itemrow['SupersessionID']; $items[$i]['NLA'] = $itemrow['NLA']; $items[$i]['Closeout'] = $itemrow['CloseOut']; $items[$i]['MSRP'] = $itemrow['MSRP']; $items[$i]['Cost'] = $cost; if ($qtyinstock - $qtyonorder < 0) { $items[$i]['BackorderQty'] = abs($qtyinstock - $qtyonorder); } else { $items[$i]['BackorderQty'] = 0; } $i++; } $rst['PONumber'] = $ar['PONumber']; $rst['InternalID'] = $poid; $rst['DealerKey'] = $vars['DealerKey']; $rst['Items'] = $items; ########################################UNITS################################### //08.25.2015 ghh - this section deals with unit purchase orders $i = 0; foreach ($ar['Units'] as $value => $key) { $key['ModelNumberNoFormat'] = preg_replace('/[^a-zA-Z0-9]/', '', $key['ModelNumber']); //strip formatting. //08.21.2015 rch - first we need to see if the item is already on the order $query = "select POUnitID\n\t\t\t\t\tfrom PurchaseOrderUnits\n\t\t\t\t\twhere POID='{$poid}' and ModelNumber = '{$key['ModelNumber']}'\n\t\t\t\t\tand VendorID = '{$key['VendorID']}'"; if (!($result = $db->sql_query($query))) { RestLog("Error 16549 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16549 - There was an error locating purchase order unit"); return false; } //08.21.2015 rch - we want to make sure that we have a partnumber and vendorid //before attempting to insert. if ($key['ModelNumberNoFormat'] != '' && $key['VendorID'] != '') { if (isset($key['Year'])) { $year = $key['Year']; } else { $year = 0; } //08.21.2015 ghh - before we bother inserting the item we're going to first grab some //details from items so we can build up our response. $query = "select ModelID, NLA, CloseOut, Cost, OrderCode \n\t\t\t\t\tMSRP from UnitModel \n\t\t\t\t\twhere ModelNumberNoFormat='{$key['ModelNumberNoFormat']}' and VendorID={$key['VendorID']}\n\t\t\t\t\tand Year={$year}"; if (!($unitresult = $db->sql_query($query))) { RestLog("Error 16560 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16560 - There was an error locating the order model"); return false; } $unitrow = $db->sql_fetchrow($unitresult); if ($db->sql_numrows($unitresult) == 0) { RestLog("Error 16561 The Unit Model you sent is not valid"); RestUtils::sendResponse(500, "16561 - The Model Number or VendorID passed are invalid"); return false; } //now lets see if we can calculate the cost for the current dealer $cost = getUnitCost($unitrow['ModelID'], $vars['DealerID'], $unitrow['Cost']); } else { RestLog("Error 16563 {$row['PONumber']} is missing a vendor id\n"); RestUtils::sendResponse(409, "Error 16563 {$key['ModelNumber']} is missing a vendor id"); return false; } //08.25.2015 ghh - if we have less line items on the PO than the qty we need then //we're going to insert a few more rows until they match. if ($db->sql_numrows($result) < $key['Qty']) { for ($i = 0; $i < $key['Qty'] - $db->sql_numrows($result); $i++) { $query = "insert into PurchaseOrderUnits (POID,ModelNumber,\n\t\t\t\t\t ModelID,OrderCode,Year, Colors, VendorID, Cost) values \n\t\t\t\t\t ( '{$poid}','{$key['ModelNumber']}',{$unitrow['ModelID']},'{$unitrow['OrderCode']}',\n\t\t\t\t\t {$year},'{$key['Colors']}', {$key['VendorID']}, '{$cost}')"; if (!($tmpresult = $db->sql_query($query))) { RestLog("Error 16564 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16564 - There was an error trying to add the unit to the order"); return false; } } //08.25.2015 ghh - update the PO with the current time for last modified date $query = "update PurchaseOrders set DateLastModified=now() where POID = {$poid}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16565 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16565 - There was a problem updating the last modified date"); //Internal Server Error return false; } } else { if ($db->sql_numrows($result) > $key['Qty']) { $qtytoremove = $db->sql_numrows($result) - $key['Qty']; $query = "select POUnitID from PurchaseOrderUnits where POID={$poid}\n\t\t\t\t\t\tand ModelID={$unitrow['ModelID']} limit {$qtytoremove}"; if (!($tmpresult = $db->sql_query($query))) { RestLog("Error 16566 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16566 - There was a problem deleting changed models"); //Internal Server Error return false; } while ($tmprow = $db->sql_fetchrow($tmpresult)) { $query = "delete from PurchaseOrderUnits where POUnitID={$tmprow['POUnitID']}"; if (!($tmp2result = $db->sql_query($query))) { RestLog("Error 16567 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16567 - There was a problem deleting changed models"); //Internal Server Error return false; } } //08.25.2015 ghh - update the PO with the current time for last modified date $query = "update PurchaseOrders set DateLastModified=now() where POID = {$poid}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16568 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16568 - There was a problem updating the last modified date"); //Internal Server Error return false; } } } //08.25.2015 ghh - first lets grab total qty for the current model $query = "select sum(Qty) as Qty from UnitModelStock where ModelID={$unitrow['ModelID']}"; if (!($qtyresult = $db->sql_query($query))) { RestLog("Error 16570 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16570 - There was an error getting total instock"); return false; } $tmprow = $db->sql_fetchrow($qtyresult); $stockqty = $tmprow['Qty']; $query = "select count(POUnitID) as Qty from PurchaseOrderUnits \n\t\t\t\twhere ModelID={$unitrow['ModelID']} and SerialVin is null"; if (!($qtyresult = $db->sql_query($query))) { RestLog("Error 16571 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16571 - There was an error getting total instock"); return false; } $tmprow = $db->sql_fetchrow($qtyresult); $orderqty = $tmprow['Qty']; //08.21.2015 ghh - now we have all of our return information and have updated or //inserted into the items list for the purchase order so we only need to build our //response now. $units[$i]['VendorID'] = $key['VendorID']; $units[$i]['ModelNumber'] = $key['ModelNumber']; $units[$i]['NLA'] = $unitrow['NLA']; $units[$i]['Closeout'] = $unitrow['CloseOut']; $units[$i]['MSRP'] = $unitrow['MSRP']; $units[$i]['Cost'] = $cost; if ($stockqty - $onorderqty < 0) { $units[$i]['BackorderQty'] = abs($stockqty - $onorderqty); } else { $units[$i]['BackorderQty'] = 0; } $i++; } $rst['Units'] = $units; RestLog("Successful Request\n"); //08.10.2012 naj - return code 200 OK. RestUtils::sendResponse(200, json_encode(stripHTML($rst))); return true; }
<?php $responceContentType = "text/html"; try { // set config file $CONFIGFILENAME = "../config/smintapi.ini"; // bootstrap the API // defines autoloader // creates logger require_once "../lib/bootstrapapi.php"; MyLog::printWithDuration("Starting Request: " . RestUtils::getFullUrl($_SERVER)); // search for Class to handle request $apiClass = RestUtils::getApiMethod($_SERVER, $apiConfig["known_api_methods"]); // hande Request depending on apiClass if (strlen($apiClass) > 0) { // only if a class was identified try { class_exists($apiClass); $service = new $apiClass(); $service->handleRawRequest($_SERVER, $_GET, $_POST); MyLog::printWithDuration("Finished Request: " . RestUtils::getFullUrl($_SERVER)); } catch (Exception $e) { // catch error if the class was not found RestUtils::sendResponse(404, $e->getMessage(), $responceContentType); } } else { RestUtils::sendResponse(404); } } catch (Exception $e) { RestUtils::sendResponse(500, $e->getMessage(), $responceContentType); }
break; case "list": default: $resultatGlobal = searchPodcast(false); break; } } catch (Exception $e) { // En cas d'erreur précédemment, on affiche un message et on arrête tout die('Erreur : ' . $e->getMessage()); } switch ($data->getMethod()) { case 'get': RestUtils::sendResponse(200, json_encode($resultatGlobal, JSON_HEX_APOS), 'application/json'); break; case 'post': RestUtils::sendResponse(200, json_encode($resultatGlobal, JSON_HEX_APOS), 'application/json'); break; default: break; } function get_json($date) { $file_day = "../../OK/" . $date . "/config.txt"; if (file_exists($file_day)) { return json_decode(file_get_contents($file_day)); } else { return null; } } function simplify_strings($string) {
function getOrderStatus($vars, $responsetype) { global $db; $ar = safetycheck($vars, $responsetype); if (!isset($ar) || !$ar['InternalID'] > 0) { RestLog("16587 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n"); RestUtils::sendResponse(400, "16587 - Insufficient data provided"); //Internal Server Error return false; } //08.26.2015 ghh - to insure a dealer can't get a status on another dealers //orders we need to make sure we include their internal id plus their dealerid $query = "select * from PurchaseOrders where POID={$ar['InternalID']} and\n\t\t\t\tDealerID={$ar['DealerID']}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16588 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16588 - There was a problem locating the order"); //Internal Server Error return false; } //08.26.2015 ghh - if no order was found then return if ($db->sql_numrows($result) == 0) { RestLog("Error 16589 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16589 - There was a problem locating the order"); //Internal Server Error return false; } //08.26.2015 ghh - now we grab what we need from the PO in order to return it //to the caller $row = $db->sql_fetchrow($result); $rst['InternalID'] = $row['POID']; $rst['PONumber'] = $row['PONumber']; $rst['Discount'] = $row['Discount']; $rst['ExpectedDelivery'] = $row['ExpectedDeliveryDate']; $rst['PayByDiscAmt'] = $row['PaybyDiscountAmount']; $rst['PayByDiscPercent'] = $row['PaybyDiscountPercent']; $rst['PayByDiscDate'] = $row['PaybyDiscountDate']; $rst['Status'] = $row['Status']; //08.26.2015 ghh - now we're going to start grabbing shipping information $query = "select distinct( BoxID )\n\t\t\tfrom PurchaseOrderItems a, PurchaseOrderShipped b \n\t\t\twhere b.POItemID=a.POItemID and a.POID={$ar['InternalID']}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16590 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16590 - There was a problem locating the order"); //Internal Server Error return false; } //now we loop through our boxes and grab related items $i = 0; while ($row = $db->sql_fetchrow($result)) { //as we loop through each item, we need to gra $query = "select a.POItemID, a.BoxID, a.QtyShipped, a.Cost, b.ItemNumber, \n\t\t\t\t\tb.VendorID, b.Quantity, b.SupersessionID, b.CrossreferenceID,\n\t\t\t\t\tc.WarehouseID, c.TrackingNumber, c.VendorInvoiceNumber,\n\t\t\t\t\tc.DueDate, c.ShipVendorID, c.ShipDate, c.ShipCost, c.BoxNumber\n\t\t\t\t\tfrom PurchaseOrderShipped a, PurchaseOrderItems b, ShippedBoxes c\n\t\t\t\t\twhere a.POItemID=b.POItemID and b.POID={$ar['InternalID']} and\n\t\t\t\t\ta.BoxID={$row['BoxID']} order by BoxID, ItemNumber"; if (!($boxresult = $db->sql_query($query))) { RestLog("Error 16591 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16591 - There was a problem getting list of shipped boxes"); //Internal Server Error return false; } //now loop through boxes and their items and lets build up our box //array $shipvendorid = 0; $boxid = 0; $j = 0; $items = array(); while ($boxrow = $db->sql_fetchrow($boxresult)) { //08.26.2015 ghh - we only enter the main box section when //we actually change boxes since we don't want to repeat this if ($boxid != $boxrow['BoxID']) { $boxid = $boxrow['BoxID']; $box[$i]['BoxNumber'] = $boxrow['BoxNumber']; $box[$i]['ShipVendor'] = getShipVendorName($boxrow['ShipVendorID']); $box[$i]['ShipVendor'] = $shippingvendor; $box[$i]['TrackingNumber'] = $boxrow['TrackingNumber']; $box[$i]['VendorInvoice'] = $boxrow['VendorInvoice']; $box[$i]['DueDate'] = $boxrow['DueDate']; $box[$i]['ShipCost'] = $boxrow['ShipCost']; $box[$i]['ShipDate'] = $boxrow['ShipDate']; } //now we build up our list of items $items[$j]['VendorID'] = $boxrow['VendorID']; $items[$j]['ItemNumber'] = $boxrow['ItemNumber']; $items[$j]['QtyShipped'] = $boxrow['QtyShipped']; $items[$j]['Cost'] = $boxrow['Cost']; //this deals with supersession data and would only be supplied if the supplier //elected to ship the super part instead of the original one ordered. if ($boxrow['SupersessionID'] > 0) { $query = "select ItemNumber from Items where ItemID={$boxrow['SupersessionID']}"; if (!($superresult = $db->sql_query($query))) { RestLog("Error 16597 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16597 - There was a problem getting supersession number"); //Internal Server Error return false; } $superrow = $db->sql_fetchrow($superresult); $items[$j]['SuppersessionNumber'] = $superrow['ItemNumber']; } //this grabs crossreference information if it was entered and would only be //entered if the supplier elected to ship a different vendors part than what //was ordered if ($boxrow['CrossReferenceID'] > 0) { $query = "select ItemNumber, VendorID from Items \n\t\t\t\t\t\t\twhere ItemID={$boxrow['CrossreferenceID']}"; if (!($crossresult = $db->sql_query($query))) { RestLog("Error 16598 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16598 - There was a problem getting supersession number"); //Internal Server Error return false; } $crossrow = $db->sql_fetchrow($crossresult); $items[$j]['CrossRefNumber'] = $crossrow['ItemNumber']; $items[$j]['CrossRefVendorID'] = $crossrow['VendorID']; } $j++; } //08.26.2015 ghh - now we need to save our items into our box $box[$i]['Items'] = $items; $i++; } //now that we're done looping through boxes we need to save them as part of the return //array $rst['Boxes'] = $box; ##########################################UNITS############################################################### //now we're going to grab a list of units that may have been shipped so we can send that //information back as well. $query = "select * from PurchaseOrderUnits where POID={$ar['InternalID']} and\n\t\t\t\tShipDate is not null"; if (!($result = $db->sql_query($query))) { RestLog("Error 16599 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16599 - There was a problem getting supersession number"); //Internal Server Error return false; } $i = 0; while ($row = $db->sql_fetchrow($result)) { $units[$i]['VendorID'] = $row['VendorID']; $units[$i]['ModelNumber'] = $row['ModelNumber']; //need to lookup up ship vendor name to send back $units[$i]['ShipVendor'] = getShipVendorName($row['ShipVendorID']); $units[$i]['TrackingNumber'] = $row['TrackingNumber']; $units[$i]['OrderCode'] = $row['OrderCode']; $units[$i]['Year'] = $row['Year']; $units[$i]['Colors'] = $row['Colors']; $units[$i]['Details'] = $row['Details']; $units[$i]['Serial-VIN'] = $row['SerialVIN']; $units[$i]['Cost'] = $row['Cost']; $units[$i]['ShipCharge'] = $row['ShipCharge']; $units[$i]['ShipDate'] = $row['ShipDate']; $units[$i]['EstShipDate'] = $row['EstShipDate']; $i++; } $rst['Units'] = $units; ###############################BACKORDERS############################## //lastly we're going to go grab the list of backorders that might exist so that we //can return them as well. $query = "select b.*, a.ItemNumber, a.VendorID\n\t\t\t\tfrom PurchaseOrderItems a, PurchaseOrderBackOrder b\n\t\t\t\twhere a.POID={$ar['InternalID']} and\n\t\t\t\ta.POItemID=b.POItemID"; if (!($result = $db->sql_query($query))) { RestLog("Error 16602 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16602 - There was a problem getting backorder information"); //Internal Server Error return false; } $i = 0; while ($row = $db->sql_fetchrow($result)) { $back[$i]['ItemNumber'] = $row['ItemID']; $back[$i]['VendorID'] = $row['VendorID']; $back[$i]['QtyPending'] = $row['QtyPending']; $back[$i]['EstShipDate'] = $row['EstShipDate']; $back[$i]['ShipNote'] = $row['ShipNote']; $i++; } $rst['Backorders'] = $back; RestLog("Successful Request\n"); RestUtils::sendResponse(200, json_encode(stripHTML($rst))); return true; }
private static function authenticate() { // figure out if we need to challenge the user if(empty($_SERVER['PHP_AUTH_DIGEST'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Digest realm="' . AUTH_REALM . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5(AUTH_REALM) . '"'); // show the error if they hit cancel die(RestControllerLib::error(401, true)); } // now, analayze the PHP_AUTH_DIGEST var if(!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || $auth_username != $data['username']) { // show the error due to bad auth die(RestUtils::sendResponse(401)); } // so far, everything's good, let's now check the response a bit more... $A1 = md5($data['username'] . ':' . AUTH_REALM . ':' . $auth_pass); $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']); $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2); // last check.. if($data['response'] != $valid_response) { die(RestUtils::sendResponse(401)); } }
public static function getId() { //Get Token if (isset($_GET['token'])) { //Verify token $token = new Token(); if (!$token->verify($_GET['token'])) { //Connect $sql = new DataBase(); $sql->connect(); $sql->query("\r\n\t\t\t\t\tSELECT DISTINCT *\r\n\t\t\t\t\tFROM token\r\n\t\t\t\t\tWHERE token = '" . $_GET['token'] . "'\r\n\t\t\t\t"); //Data while ($data = mysql_fetch_array($sql->result)) { return $data['profile_id']; break; } } else { RestUtils::sendResponse('400', array('data' => 'token', 'message' => 'A verificação do token falhou.')); exit; } } else { RestUtils::sendResponse('412', array('data' => 'token', 'message' => 'O token não foi passado pela URL.')); exit; } }
function report($report = '') { RestUtils::sendResponse(500, $report); exit; }
// $loggedInUser->redirect = 'false'; // $loggedInUser->remember_me_sessid = generateHash(uniqid(rand(), true)); // //Update last sign in // $loggedInUser->updatelast_sign_in(); // if($loggedInUser->remember_me == 0) // $_SESSION["userPieUser"] = $loggedInUser; // else if($loggedInUser->remember_me == 1) { // $db->sql_query("INSERT INTO ".$db_table_prefix."sessions VALUES('".time()."', '".serialize($loggedInUser)."', '".$loggedInUser->remember_me_sessid."')"); // setcookie("userPieUser", $loggedInUser->remember_me_sessid, time()+parseLength($remember_me_length)); // } //LOG $sql4->query("INSERT INTO log(type,message,application_id,profile_id) VALUES ('login','O usuario logou no sistema. Token: " . $generateToken . "','" . $data['id'] . "','" . $userdetails['id'] . "')"); //Retorno /*if($data['return_url'] != '' && !isset($_DATA['redirect'])): header("Location: ".$data['return_url']."?token=".$generateToken); else:*/ echo $generateToken; /*endif;*/ break; } $sql->close(); break; } break; /////////////////////////////////////DEFAULT /////////////////////////////////////DEFAULT default: RestUtils::sendResponse('405'); exit; break; }
public static function error($status = '500', $body = '') { //DEBUG Mode RestUtils::sendResponse($status, $body, $type = 'text/html'); //Production Mode //RestUtils::sendResponse(500); exit; }
function getModel($vars, $responsetype) { global $db; $ar = $vars; if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ModelNumber']) || !isset($ar['Year'])) { RestLog("16579 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n"); RestUtils::sendResponse(400, "16579 - Insufficient data provided"); //Internal Server Error return false; } $ar['ModelNumberNoFormat'] = preg_replace('/[^a-zA-Z0-9]/', '', $ar['ModelNumber']); //strip formatting. //now we grab inventory records for the requested item and build up our package to return //to the dealer $query = "select ModelID, OrderCode, Colors, ModelName, VehicleTypeID, NLA, CloseOut,\n\t\t\t\t\tCost, MSRP, MAP, Description from UnitModel where VendorID=\n\t\t\t\t\t{$ar['VendorID']} and ModelNumberNoFormat='{$ar['ModelNumberNoFormat']}' and\n\t\t\t\t\tYear={$ar['Year']}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16581 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16581 - There was a problem getting model information."); //Internal Server Error return false; } $row = $db->sql_fetchrow($result); $unit['OrderCode'] = $row['OrderCode']; $unit['Colors'] = $row['Colors']; $unit['ModelName'] = $row['ModelName']; $unit['NLA'] = $row['NLA']; $unit['CloseOut'] = $row['CloseOut']; $unit['Cost'] = getUnitCost($row['ModelID'], $ar['DealerID'], $row['Cost']); $unit['MSRP'] = $row['MSRP']; $unit['MAP'] = $row['MAP']; $unit['Description'] = $row['Description']; $modelid = $row['ModelID']; if ($modelid > 0) { //08.25.2015 ghh - now we grab unit inventory information $query = "select Warehouses.WarehouseName, Warehouses.WarehouseState,\n\t\t\t\t\tQty, DaysToArrive \n\t\t\t\t\tfrom Warehouses, UnitModelStock, DaysToFullfill\n\t\t\t\t\twhere Warehouses.WarehouseID=UnitModelStock.WarehouseID and\n\t\t\t\t\tUnitModelStock.ModelID={$row['ModelID']} and\n\t\t\t\t\tUnitModelStock.WarehouseID=DaysToFullfill.WarehouseID and\n\t\t\t\t\tDaysToFullfill.DealerID={$ar['DealerID']} order by DaysToArrive"; if (!($result = $db->sql_query($query))) { RestLog("Error 16582 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16582 - There was a problem getting model warehouse information."); //Internal Server Error return false; } $i = 0; while ($row = $db->sql_fetchrow($result)) { $rst[$i]['WarehouseName'] = $row['WarehouseName']; $rst[$i]['WarehouseState'] = $row['WarehouseState']; $rst[$i]['Qty'] = $row['Qty']; $rst[$i]['DaysToArrive'] = $row['DaysToArrive']; $i++; } $unit['Warehouses'] = $rst; //08.25.2015 ghh - now we're getting a list of images that may exist for this //item $query = "select * from UnitModelImages where ModelID={$modelid}"; if (!($result = $db->sql_query($query))) { RestLog("Error 16583 in query: {$query}\n" . $db->sql_error()); RestUtils::sendResponse(500, "16583 - There was a problem retrieving a list of images"); //Internal Server Error return false; } $i = 0; while ($row = $db->sql_fetchrow($result)) { $img[$i]['ImageURL'] = $row['ImageURL']; $img[$i]['ImageSize'] = $row['ImageSize']; $i++; } $unit['Images'] = $img; } RestLog("Successful Request\n"); RestUtils::sendResponse(200, json_encode(stripHTML($unit))); return true; }