function GetDealID($Source, $LanguageID, $CountryID, $StoreID, $D, $DoHist) { //Find deal list($QR, $DR, $T) = QuerySingle("SELECT D.DealID, D.DealPrice, D.DealValue, D.DealStatus, D.StringID, LS.StringText AS Title, D.DealURL\n FROM 4000_Deals D\n INNER JOIN 0200_Language_Strings LS ON D.StringID = LS.StringID AND LS.LanguageID = " . $LanguageID . "\n WHERE D.DealSourceID = " . $Source . "\n AND ((D.RemoteID = '" . Pacify($D['DRID']) . "')\n OR (LS.StringText = '" . Pacify($D['Title']) . "' AND LENGTH(LS.StringText) > 15))\n AND D.DateEnds >= " . date('YmdHis') . ";"); if ($QR < 0) { return SysLogIt('Error searching for deal.', StatusError, ActionSelect); } if ($QR == 0) { if ($StringID = CreateNewString($LanguageID, $Source * 1000000, ($Source + 1) * 1000000 - 1, 'Title for deal with remote ID of ' . $D['DRID'], $D['Title'])) { $CID = $CountryID; if (array_key_exists("Country", $D)) { $CID = GetCountry($D['Country'], $CountryID); } //Insert new deal if (!ExecCommand("INSERT INTO 4000_Deals (DealSourceID, CountryID, StoreID, StringID, RemoteID, DealURL, DateListed, DateEnds, DateExpiry, DealPrice, DealValue, DealStatus)\n VALUES (" . $Source . "," . $CID . "," . $StoreID . "," . $StringID . ",'" . Pacify($D['DRID']) . "','" . Pacify($D['URL']) . "'," . date('YmdHis', $D['SDate']) . "," . date('YmdHis', $D['EDate']) . "," . date('YmdHis', $D['VDate']) . "," . round((double) $D['Price']) . "," . round((double) $D['Value']) . "," . $D['Status'] . ");")) { return SysLogIt('Error creating new deal.', StatusError, ActionInsert); } //Get new store record list($QR, $DR, $T) = QuerySingle("SELECT last_insert_id() AS ID;"); if ($QR < 0) { return SysLogIt('Error retrieving newly inserted deal ID.', StatusError, ActionSelect); } $DealID = $DR['ID']; SysLogIt('Created new deal with ID of ' . $DealID . '.', StatusInfo, ActionInsert); if ($DoHist) { DoHistoryGraph($StoreID); } DoQR($DealID, $StoreID, $D); } else { return false; } } else { $DealID = $DR['DealID']; $StringID = $DR['StringID']; //Update deal data if necessary if ((int) $DR['DealPrice'] != (int) $D['Price'] || (int) $DR['DealValue'] != (int) $D['Value']) { // || ($DR['DealURL'] != $D['URL']) ) { if (!ExecCommand("UPDATE 4000_Deals SET DealPrice = " . (double) $D['Price'] . ", DealValue = " . (double) $D['Value'] . ", DealStatus = " . ($DR['DealStatus'] | $D['Status']) . ", DealURL = '" . Pacify($D['URL']) . "' WHERE DealID = " . $DR['DealID'] . ";")) { return SysLogIt('Error updating deal with ID of ' . $DR['DealID'] . '.', StatusError, ActionUpdate); } SysLogIt('Updated deal with ID of ' . $DR['DealID'] . '.', StatusInfo, ActionUpdate); DoQR($DealID, $StoreID, $D, true); } else { SysLogIt('Deal already exists with ID of ' . $DealID . ' and no need to update.'); } //Update string if necessary if ($DR['Title'] != $D['Title']) { if (!ExecCommand("UPDATE 0200_Language_Strings SET StringText = '" . Pacify($D['Title']) . "' WHERE StringID = " . $StringID . " AND LanguageID = " . $LanguageID . ";")) { return SysLogIt('Error updating string with ID of ' . $StringID . '.', StatusError, ActionUpdate); } SysLogIt('Updated string with ID of ' . $StringID . '.', StatusInfo, ActionUpdate); } } //Do translations if ($StringID > 0) { TranslateOtherLanguages($D, $LanguageID, $StringID); } return $DealID; }
function DisplayHistory() { global $UserID; global $Response; $Response->J = 'ClWin(); PopErr();'; if (isset($_POST['DID'])) { if (is_numeric($_POST['DID'])) { list($QR, $DR, $T) = QuerySingle("SELECT D.DealID, D.StoreID, S.StoreName, SH.Filename\n FROM 4000_Deals D\n INNER JOIN 2000_Stores S ON D.StoreID = S.StoreID\n LEFT JOIN 2600_Store_History SH ON D.StoreID = SH.StoreID\n WHERE D.DealID = " . (int) $_POST['DID'] . ";"); if ($QR < 0) { SysLogIt('Error searching for deal information for history.', StatusError, ActionSelect); } elseif ($QR > 0) { //if (1 == 1) { if (is_null($DR['Filename'])) { $Filename = DoHistoryGraph($DR['StoreID']); } else { $Filename = $DR['Filename']; } if ($Filename !== false) { $Strings = GSA('1695,1696'); $Response->S = true; $Response->J = ''; $Response->R = ' <DIV CLASS="ttlw"><DIV>' . $Strings[1695] . ' ' . StringAdjust($DR['StoreName']) . '</DIV><HR></DIV> <DIV CLASS="abs fulls flwa sz13 algc"> <OBJECT TYPE="image/svg+xml" CLASS="mgrx" WIDTH="400" DATA="/Hist/' . $Filename . '"> ' . $Strings[1696] . ' </OBJECT> </DIV>'; } } } } $Response->Send(); }