function SetTags($LID = 1) { /*///////////////////////////////////////////////////////////// Author: Plottery Corp. Created: v1.0.0 - 2010-12-19 Revisions: None Purpose: Saves category and type keywords Returns: Nothing */ ///////////////////////////////////////////////////////////// global $Response; $Response->J = 'F5();'; if (isset($_POST['Key'])) { if ($AKey = ValidAccessKey($_POST['Key'])) { //Validation //Save DeleteAccessKey($AKey); $Response->J = 'EdtTag(true);'; $TypeID = 0; $LastID = 0; $LastKey = ''; $CategoryID = 0; foreach ($_POST as $Key => $Value) { if ($Key != 'Key') { $ID = (int) substr($Key, 1); switch (strtolower(substr($Key, 0, 1))) { case 'c': if ($ID < 0) { //Create new category and matching string if (!($StringID = CreateNewString($LID, 10000, 19999, 'Category', $Value))) { $Response->Send(); } if (!($CategoryID = InsertAndRetrieveID("INSERT INTO 2100_Store_Categories (CategoryName, StringID) VALUES ('" . Pacify($Value) . "'," . $StringID . ");", "category"))) { $Response->Send(); } $LastID = $ID; } else { //Find category ID list($QR, $DR, $T) = QuerySingle("SELECT SC.CategoryID, SC.StringID FROM 2100_Store_Categories SC WHERE SC.CategoryID = " . (int) $ID . ";"); if ($QR < 1) { SysLogIt('Error retrieving category with ID of ' . $ID . '.', StatusError, ActionSelect); $Response->Send(); } if ($LID > 1) { //Update category if (ExecCommand("UPDATE 2100_Store_Categories SET CategoryName = '" . Pacify($Value) . "' WHERE CategoryID = " . $DR['CategoryID'] . ";")) { SysLogIt('Updated category with ID of ' . $DR['CategoryID'] . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating category with ID of ' . $DR['CategoryID'] . '.', StatusError, ActionUpdate); $Response->Send(); } } //Update string if (ExecCommand("UPDATE 0200_Language_Strings SET StringText = '" . Pacify($Value) . "' WHERE StringID = " . $DR['StringID'] . " AND LanguageID = " . $LID . ";")) { SysLogIt('Updated string with ID of ' . $DR['CategoryID'] . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating string with ID of ' . $DR['StringID'] . '.', StatusError, ActionUpdate); $Response->Send(); } } break; //----------- //----------- case 'x': if ($ID < 0 && ($LastID = $ID && $CategoryID > 0)) { //Create new category keywords if (ExecCommand("INSERT INTO 2101_Store_Category_Keywords (CategoryID, LanguageID, Keywords) VALUES (" . $CategoryID . "," . $LID . ",'" . Pacify($Value) . "');")) { SysLogIt('Created keywords for category with ID of ' . $CategoryID . '.', StatusInfo, ActionInsert); } else { SysLogIt('Error creating keywords for category with ID ' . $CategoryID . '.', StatusError, ActionInsert); $Response->Send(); } } elseif ($ID > 0) { //Update existing category keywords if (ExecCommand("UPDATE 2101_Store_Category_Keywords SET Keywords = '" . Pacify($Value) . "' WHERE KeywordsID = " . $ID . ";")) { SysLogIt('Updated category keywords with ID of ' . $ID . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating category keywords with ID of ' . $ID . '.', StatusError, ActionUpdate); $Response->Send(); } } break; //----------- //----------- case 'j': $UpdateID = 0; if ($ID < 0 && ($LastID = $ID && $CategoryID > 0)) { $UpdateID = $CategoryID; } else { $UpdateID = $ID; } if ($UpdateID > 0 && trim($Value) != '') { //Update existing category keywords if (ExecCommand("UPDATE 2100_Store_Categories SET Icon = '" . Pacify(trim($Value)) . "' WHERE CategoryID = " . $UpdateID . ";")) { SysLogIt('Updated icon for category with ID of ' . $UpdateID . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating icon for category with ID of ' . $UpdateID . '.', StatusError, ActionUpdate); $Response->Send(); } } break; //----------- //----------- case 't': if (stripos($ID, '-', 1) !== false) { $ID = (int) substr($ID, 0, stripos($ID, '-', 1)); } if ($ID < 0) { //Create new type and matching string if (!($StringID = CreateNewString($LID, 10000, 19999, 'Type', $Value))) { $Response->Send(); } if (!($TypeID = InsertAndRetrieveID("INSERT INTO 2110_Store_Types (CategoryID, TypeName, StringID) VALUES (" . -$ID . ",'" . Pacify($Value) . "'," . $StringID . ");", "type"))) { $Response->Send(); } $LastID = $ID; $LastKey = substr($Key, 1); } else { //Find type ID list($QR, $DR, $T) = QuerySingle("SELECT TypeID, StringID FROM 2110_Store_Types WHERE TypeID = " . (int) $ID . ";"); if ($QR < 1) { SysLogIt('Error retrieving type with ID of ' . $ID . '.', StatusError, ActionSelect); $Response->Send(); } if ($LID > 1) { //Update type if (ExecCommand("UPDATE 2110_Store_Types SET TypeName = '" . Pacify($Value) . "' WHERE TypeID = " . $DR['TypeID'] . ";")) { SysLogIt('Updated type with ID of ' . $DR['TypeID'] . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating type with ID of ' . $DR['TypeID'] . '.', StatusError, ActionUpdate); $Response->Send(); } } //Update string if (ExecCommand("UPDATE 0200_Language_Strings SET StringText = '" . Pacify($Value) . "' WHERE StringID = " . $DR['StringID'] . " AND LanguageID = " . $LID . ";")) { SysLogIt('Updated string with ID of ' . $DR['TypeID'] . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating string with ID of ' . $DR['StringID'] . '.', StatusError, ActionUpdate); $Response->Send(); } } break; //----------- //----------- case 'k': if (stripos($ID, '-', 1) !== false) { $ID = (int) substr($ID, 0, stripos($ID, '-', 1)); } if ($ID < 0 && substr($Key, 1) == $LastKey && $TypeID > 0) { //Create new type keywords if (ExecCommand("INSERT INTO 2111_Store_Type_Keywords (TypeID, LanguageID, Keywords) VALUES (" . $TypeID . "," . $LID . ",'" . Pacify($Value) . "');")) { SysLogIt('Created keywords for type with ID ' . $TypeID . '.', StatusInfo, ActionInsert); } else { SysLogIt('Error creating keywords for type with ID ' . $TypeID . '.', StatusError, ActionInsert); $Response->Send(); } } elseif ($ID > 0) { //Update existing type keywords if (ExecCommand("UPDATE 2111_Store_Type_Keywords SET Keywords = '" . Pacify($Value) . "' WHERE KeywordsID = " . $ID . ";")) { SysLogIt('Updated type keywords with ID ' . $ID . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating type keywords with ID of ' . $ID . '.', StatusError, ActionUpdate); $Response->Send(); } } break; //----------- //----------- case 'i': if (stripos($ID, '-', 1) !== false) { $ID = (int) substr($ID, 0, stripos($ID, '-', 1)); } $UpdateID = 0; if ($ID < 0 && substr($Key, 1) == $LastKey && $TypeID > 0) { $UpdateID = $TypeID; } else { $UpdateID = $ID; } if ($UpdateID > 0 && trim($Value) != '') { //Update existing type keywords if (ExecCommand("UPDATE 2110_Store_Types SET Icon = '" . Pacify(trim($Value)) . "' WHERE TypeID = " . $UpdateID . ";")) { SysLogIt('Updated icon for type with ID of ' . $UpdateID . '.', StatusInfo, ActionUpdate); } else { SysLogIt('Error updating icon for type with ID of ' . $UpdateID . '.', StatusError, ActionUpdate); $Response->Send(); } } break; } } } $Response->S = true; $Response->Send(); } } }
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; }