function ProcessSaveDeal() { /*///////////////////////////////////////////////////////////// Author: Plottery Corp. Created: v1.0.0 - 2011-02-13 Revisions: None Purpose: Toggles the save state of a deal Returns: Nothing */ ///////////////////////////////////////////////////////////// global $Response; global $UserID; $Response->J = 'PopErr();'; $Strings = GSA('1658'); if (isset($_POST['O']) && isset($_POST['DID']) && isset($_POST['ULID']) && isset($_POST['DT'])) { if (is_numeric($_POST['O']) && is_numeric($_POST['DID']) && is_numeric($_POST['ULID']) && is_numeric($_POST['DT'])) { if ((int) $_POST['DID'] >= 0) { list($QR, $DR, $T) = QuerySingle("SELECT UF.FavoriteID, UF.DealID, L.LocationLatitude AS Lat, L.LocationLongitude AS Lng\n FROM 3000_Locations L \n LEFT JOIN 1200_User_Favorites UF ON UF.LocationID = L.LocationID AND UF.DealID = " . (int) $_POST['DID'] . " AND UF.UserID = " . $UserID . "\n WHERE L.LocationID = " . (int) $_POST['ULID'] . ";"); } else { list($QR, $DR, $T) = QuerySingle("SELECT UMF.FavoriteID, 0 AS DealID\n FROM 1210_User_Manual_Favorites UMF\n WHERE UMF.FavoriteID = " . -(int) $_POST['DID'] . "\n AND UMF.LocationID = " . (int) $_POST['ULID'] . "\n AND UMF.UserID = " . $UserID . ";"); } if ($QR < 0) { SysLogIt('Error searching for user favorite.', StatusError, ActionSelect); } elseif (!is_null($DR['FavoriteID']) && (int) $_POST['O'] == 0) { $Table = (int) $_POST['DID'] < 0 ? "1210_User_Manual_Favorites" : "1200_User_Favorites"; if (ExecCommand("DELETE FROM " . $Table . " WHERE FavoriteID = " . $DR['FavoriteID'] . ";")) { $Response->S = true; $Response->R = 0; $Response->C = $DR['DealID']; $Response->D = (int) $_POST['DID'] < 0 ? -$DR['FavoriteID'] : $DR['FavoriteID']; $Response->J = ''; if ((int) $_POST['DT'] == 1 && (int) $_POST['DID'] > 0) { $Response->J = 'RstDet(' . (int) $_POST['DID'] . ');'; } } else { SysLogIt('Error deleting user favorite.', StatusError, ActionInsert); } } elseif (is_null($DR['FavoriteID']) && (int) $_POST['O'] == 1) { if (ExecCommand("INSERT INTO 1200_User_Favorites (DealID, LocationID, UserID) VALUES (" . (int) $_POST['DID'] . "," . (int) $_POST['ULID'] . "," . $UserID . ");")) { list($QR, $SDR, $T) = QuerySingle('SELECT LAST_INSERT_ID() AS ID;'); if ($QR > 0) { $ASDeal = new FDeal(); $ASDeal->FID = $SDR['ID']; list($QR, $SDR, $T) = QuerySingle('SELECT UNIX_TIMESTAMP(D.DateExpiry) AS ExpDate, S.StoreID, S.StoreName AS SName, COALESCE(ST.Icon, SC.Icon, "Blank") AS Icon, D.DealValue AS DValue FROM 4000_Deals D INNER JOIN 2000_Stores S ON D.StoreID = S.StoreID LEFT JOIN 2110_Store_Types ST ON S.TypeID = ST.TypeID LEFT JOIN 2100_Store_Categories SC ON ST.CategoryID = SC.CategoryID WHERE D.DealID = ' . (int) $_POST['DID'] . ';'); if ($QR > 0) { //$Response->J .= $DR['Lat'].', '.$DR['Lng']; $ASDeal->EDate = $SDR['ExpDate'] == 0 || date('Y', $SDR['ExpDate']) == 1969 ? 0 : (int) $SDR['ExpDate']; $ASDeal->Desc = StringAdjust($SDR['SName']); $ASDeal->Icon = $SDR['Icon']; $ASDeal->Value = (double) $SDR['DValue']; $ASDeal->DID = (int) $_POST['DID']; list($SSQR, $SSRS, $T) = QuerySet('SELECT LD.LocationID, LD.LocationLatitude AS Lat, LD.LocationLongitude AS Lng, GetDistance(' . $DR['Lat'] . ', ' . $DR['Lng'] . ', LD.LocationLatitude, LD.LocationLongitude) AS Distance FROM 2200_Store_Locations SL INNER JOIN 3000_Locations LD ON LD.LocationID = SL.LocationID WHERE SL.StoreID = ' . $SDR['StoreID'] . ' HAVING Distance <= 100 OR Lat = -1;'); if ($SSQR > 0) { while ($SSDR = mysql_fetch_array($SSRS)) { if ($SSDR['Lat'] == -1) { $ASDeal->Web = true; break; } $ASLocation = new SLocation(); $ASLocation->Lat = (double) $SSDR['Lat']; $ASLocation->Lng = (double) $SSDR['Lng']; $ASLocation->Dist = (double) $SSDR['Distance']; $ASDeal->Locs[$SSDR['LocationID']] = $ASLocation; } $Response->S = true; $Response->R = 1; $Response->C = $ASDeal; $Response->J = ''; if ((int) $_POST['DT'] == 1) { $Response->J = 'RstDet(' . (int) $_POST['DID'] . ');'; } } elseif ($SSQR < 0) { SysLogIt('Error searching for deal\'s store locations.', StatusError, ActionSelect); } } else { SysLogIt('Error searching for favorite deal information.', StatusError, ActionSelect); } } else { SysLogIt('Error selecting new favorite ID.', StatusError, ActionSelect); } } else { SysLogIt('Error inserting new user favorite.', StatusError, ActionInsert); } } SetFilter((int) $_POST['ULID'], FilterDeal, (int) $_POST['DID'], 0, -1, false); } } $Response->Send(); }
function GSA($SIDs, $LID = 0, $Block = false, $HTML = false) { global $LanguageID; $QueryLanguage = $LID == 0 ? $LanguageID : $LID; ExecCommand("SET SESSION group_concat_max_len = 20480"); list($QR, $DR, $T) = QuerySingle("SELECT GROUP_CONCAT(CONCAT_WS('\\\\', StringID, StringText) SEPARATOR '|') AS AllStrings\n FROM 0200_Language_Strings\n WHERE StringID IN (" . $SIDs . ")\n AND LanguageID = " . $QueryLanguage . "\n GROUP BY LanguageID\n ORDER BY StringID;"); if ($QR < 1) { return ''; } $TempArray = explode('|', $DR['AllStrings']); $RealArray = array(); foreach ($TempArray as $TempItem) { $SplitItem = explode('\\', $TempItem); if (count($SplitItem) == 2) { $RealArray[(int) $SplitItem[0]] = StringAdjust($SplitItem[1], $HTML, $Block); } } //Fill in missing fields $IDs = explode(',', $SIDs); foreach ($IDs as $ID) { if (!array_key_exists($ID, $RealArray)) { $RealArray[$ID] = '?'; } } return $RealArray; }
function SendDigests($ST) { if ((int) date('G') >= 18) { $TimeOfDay = 4; } elseif ((int) date('G') >= 12) { $TimeOfDay = 2; } elseif ((int) date('G') >= 7) { $TimeOfDay = 1; } else { return true; } //Read users list($QR, $RS, $T) = QuerySet('SELECT UN.NotificationID AS NID, UN.UserID, UN.DealID, UN.Settings, UN.CancelKey, U.LanguageID AS LID, U.UserEmail FROM 1400_User_Notifications UN INNER JOIN 1000_Users U ON UN.UserID = U.UserID WHERE UN.SentDate < ' . date('YmdHis', mktime(date('H') - 12, date('i'), date('s'), date('n'), date('j'), date('Y'))) . ' AND ((UN.Settings & ' . $TimeOfDay . ') = ' . $TimeOfDay . ') AND ((U.UserFlags & ' . UserActive . ') = ' . UserActive . ') AND (U.UserEmailVerified = 1);'); if ($QR < 0) { return SysLogIt('Error searching for user notification settings.', StatusError, ActionSelect); } if ($QR > 0) { SysLogIt('Sending daily digests (' . $QR . ' pending)', StatusInfo, ActionNotSpecified, 1); $Strings = array(); list($QR, $SRS, $T) = QuerySet("SELECT LanguageID FROM 0000_Languages WHERE LanguageActive = 1;"); while ($SDR = mysql_fetch_array($SRS)) { $Strings[$SDR['LanguageID']] = GSA('2100,2101,2102,2103,2104,2105,2106,2107,2108,2109,2110,2111,2113,2114,2115', $SDR['LanguageID'], false, true); } while ($DR = mysql_fetch_array($RS)) { if (time() - $ST > 300) { return SysLogIt('Sending of digests has exceeded 5 minutes; stopping until next cycle.', StatusInfo, ActionNotSpecified, -1); } $MaxDealID = 0; if (($DR['Settings'] & 16) == 16) { $Output = '<html><head><title>Dealplotter - ' . $Strings[$DR['LID']][2100] . ' - ' . date('Y-m-d') . '</title><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><style type="text/css">A { text-decoration: none; } A:hover { border-bottom: 1px solid #0179ff; } TD EM { font-style: normal; }</style></head><body bgcolor="#FFFFFF" style="font-family: Calibri, sans-serif; font-size: 13px;"><table style="border: 1px solid #E0E0E0; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; background-color: #F8F8F8;" WIDTH="100%"><tr><td width="210"><a href="http://www.dealplotter.com"><img src="http://www.dealplotter.com/IF/LogoXS.png" border=0></a></td><td><h2 style="font-size: 18px;"><b>' . $Strings[$DR['LID']][2100] . '<br />' . date('Y-m-d') . '</b></h2></tr></tr></table><table border=0 cellpadding=3 style="font-size: 13px;">'; } else { $Output = 'Dealplotter - ' . $Strings[$DR['LID']][2100] . ' - ' . date('Y-m-d') . chr(13) . chr(10) . chr(13) . chr(10); } list($QR, $SRS, $T) = QuerySet('SELECT L.LocationID, L.LocationLatitude AS Lat, L.LocationLongitude AS Lng, L.CountryID AS CID, UL.UserLocationName AS UName, C.CountryCurrency AS CurS, COALESCE(GROUP_CONCAT(UFT.FilterSourceID),0) AS TFilt, COALESCE(GROUP_CONCAT(UFD.FilterSourceID),0) AS DFilt, GROUP_CONCAT(CONCAT_WS(",", UFC.FilterSourceID, UFC.FilterValue) SEPARATOR "|") AS CFilt FROM 1000_Users U INNER JOIN 1100_User_Locations UL ON U.UserID = UL.UserID INNER JOIN 3000_Locations L ON L.LocationID = UL.LocationID INNER JOIN 3100_Countries C ON C.CountryID = L.CountryID LEFT JOIN 1110_User_Filters UFC ON UFC.UserLocationID = UL.UserLocationID AND UFC.FilterType = ' . FilterCategory . ' LEFT JOIN 1110_User_Filters UFT ON UFT.UserLocationID = UL.UserLocationID AND UFT.FilterType = ' . FilterType . ' LEFT JOIN ( SELECT UF.UserLocationID, UF.FilterSourceID FROM 1110_User_Filters UF INNER JOIN 4000_Deals D ON UF.FilterSourceID = D.DealID WHERE UF.FilterType = ' . FilterDeal . ' AND D.DateEnds > ' . date('YmdHis') . ' AND UF.FilterValue = 1 ) UFD ON UFD.UserLocationID = UL.LocationID WHERE U.UserID = ' . $DR['UserID'] . ' GROUP BY UL.UserLocationID;'); if ($QR < 0) { return SysLogIt('Error searching for user location settings.', StatusError, ActionSelect); } if ($QR > 0) { while ($SDR = mysql_fetch_array($SRS)) { if ($SDR['CFilt'] == '') { $Categories = array(); } else { $Categories = explode("|", $SDR['CFilt']); foreach ($Categories as $Key => $Category) { $Categories[$Key] = explode(',', $Category); } } if (($DR['Settings'] & 16) == 16) { $Output .= '<tr><td colspan=3><h2 style="font-size: 18px;"><b><br />' . $Strings[$DR['LID']][2101] . ' ' . StringAdjust($SDR['UName']) . ''; } else { $Output .= chr(13) . chr(10) . $Strings[$DR['LID']][2101] . ' ' . StringAdjust($SDR['UName']); } list($QR, $SSRS, $T) = QuerySet('SELECT D.DealID, UNIX_TIMESTAMP(D.DateEnds) AS DateEnds, COALESCE(LSDa.StringText, LSDb.StringText) AS Descr, D.DealPrice AS SPrice, D.DealValue AS RPrice, COALESCE(STy.Icon, SC.Icon, "Blank") AS Icon, LD.LocationLatitude AS Lat, GetDistance(' . $SDR['Lat'] . ', ' . $SDR['Lng'] . ', LD.LocationLatitude, LD.LocationLongitude) AS Dist, COALESCE(STy.CategoryID, 0) AS CAID FROM 4000_Deals D LEFT JOIN 0200_Language_Strings LSDa ON D.StringID = LSDa.StringID AND LSDa.LanguageID = ' . $DR['LID'] . ' LEFT JOIN 0200_Language_Strings LSDb ON D.StringID = LSDb.StringID AND LSDb.LanguageID = 1 INNER JOIN 2000_Stores ST ON D.StoreID = St.StoreID INNER JOIN 2200_Store_Locations SL ON SL.StoreID = ST.StoreID INNER JOIN 3000_Locations LD ON LD.LocationID = SL.LocationID LEFT JOIN 2110_Store_Types STy ON ST.TypeID = STy.TypeID LEFT JOIN 2100_Store_Categories SC ON STy.CategoryID = SC.CategoryID WHERE D.DateEnds > ' . date('YmdHis') . ' AND (GetDistance(' . $SDR['Lat'] . ', ' . $SDR['Lng'] . ', LD.LocationLatitude, LD.LocationLongitude) <= 100 OR (LD.LocationLatitude = -1 AND LD.LocationLongitude = -1 AND (LD.CountryID = ' . $SDR['CID'] . ' OR LD.CountryID = 0))) AND (ST.TypeID NOT IN (' . $SDR['TFilt'] . ')) AND (D.DealID NOT IN (' . $SDR['DFilt'] . ')) AND (D.DealID > ' . $DR['DealID'] . ') GROUP BY D.DealID ORDER BY Dist;'); if ($QR == 0) { if (($DR['Settings'] & 16) == 16) { $Output .= '<hr style="border: 0; height: 1px; background-color: #C0C0C0;"></b></h2></td></tr><tr><td colspan=3><div style="color: #FF0000; font-weight: bold; font-size: 14px;">' . $Strings[$DR['LID']][2102] . '</div>' . $Strings[$DR['LID']][2103] . '</td></tr>'; } else { $Output .= chr(13) . chr(10) . '-------------------------------------------------' . chr(13) . chr(10) . chr(13) . chr(10) . $Strings[$DR['LID']][2102] . chr(13) . chr(10) . $Strings[$DR['LID']][2103] . chr(13) . chr(10) . chr(13) . chr(10); } } elseif ($QR > 0) { $Total = 0; $SubOut = ''; while ($SSDR = mysql_fetch_array($SSRS)) { if ($SSDR['DealID'] > $MaxDealID) { $MaxDealID = $SSDR['DealID']; } $Match = true; if ($SSDR['Lat'] != -1) { foreach ($Categories as $Category) { if ($Category[0] == $SSDR['CAID']) { if ($SSDR['Dist'] > $Category[1]) { $Match = false; break; } } } } if ($Match) { if ($SSDR['Lat'] == -1) { $Dist = 'Web'; } else { $Dist = $SSDR['Dist'] . ' km'; } $Days = (int) (($SSDR['DateEnds'] - time()) / 60 / 60 / 24); if ($Days == 0) { $When = $Strings[$DR['LID']][2104]; } elseif ($Days == 1) { $When = $Strings[$DR['LID']][2105]; } else { $When = str_ireplace('%a', $Days, $Strings[$DR['LID']][2106]); } if (($DR['Settings'] & 16) == 16) { $SubOut .= '<tr valign="top"><td><a href="http://www.dealplotter.com/?' . $SSDR['DealID'] . '"><img src="http://www.dealplotter.com/IF/Marker-' . $SSDR['Icon'] . '.png" border=0></a></td><td style="padding-top: 8px;"><a style="color: #000080;" href="http://www.dealplotter.com/out.php?' . $SSDR['DealID'] . '"><em>' . $SSDR['Descr'] . '</em></a><div style="padding-top: 8px; font-size: 11px;"><a href="http://www.dealplotter.com/?' . $SSDR['DealID'] . '"><em>' . $Strings[$DR['LID']][2107] . '</em></a></div></td><td><table style="width: 90px; text-align: center; border: 1px solid #E0E0E0; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; font-weight: bold; color: #000080;" cellspacing=0><tr><td style="font-size: 15px; color: #00C000;"><span style="text-decoration: line-through; color: #404040; font-size: 12px;"><span style="color: #C0C0C0;"><del>' . number_format($SSDR['RPrice']) . '</del></span></span> ' . $SDR['CurS'] . number_format($SSDR['SPrice']) . '</td></tr><tr><td style="font-size: 14px;">' . $Dist . '</td></tr><tr><td><h6 style="font-size: 11px;">' . $When . '</h6></td></tr></table></td></tr>'; } else { $SubOut .= $SSDR['Descr'] . chr(13) . chr(10) . '- ' . $Strings[$DR['LID']][2113] . ': ' . $SDR['CurS'] . number_format($SSDR['RPrice']) . chr(13) . chr(10) . '- ' . $Strings[$DR['LID']][2114] . ': ' . $SDR['CurS'] . number_format($SSDR['SPrice']) . chr(13) . chr(10) . '- ' . $Strings[$DR['LID']][2115] . ': http://www.dealplotter.com/out.php?' . $SSDR['DealID'] . chr(13) . chr(10) . '- ' . $Strings[$DR['LID']][2107] . ': http://www.dealplotter.com/?' . $SSDR['DealID'] . chr(13) . chr(10) . chr(13) . chr(10); } $Total++; } } if ($Total == 0) { if (($DR['Settings'] & 16) == 16) { $Output .= '<hr style="border: 0; height: 1px; background-color: #C0C0C0;"></td></tr><tr><td colspan=3><div style="color: #FF0000; font-weight: bold; font-size: 14px;">' . $Strings[$DR['LID']][2102] . '</div>' . $Strings[$DR['LID']][2103] . '</td></tr>'; } else { $Output .= chr(13) . chr(10) . '-------------------------------------------------' . chr(13) . chr(10) . chr(13) . chr(10) . $Strings[$DR['LID']][2102] . chr(13) . chr(10) . $Strings[$DR['LID']][2103] . chr(13) . chr(10) . chr(13) . chr(10); } } else { if (($DR['Settings'] & 16) == 16) { $Output .= ' <span style="color: #000080;">(' . $Total . ')</span><hr style="border: 0; height: 1px; background-color: #C0C0C0;"></td></tr>'; } else { $Output .= ' (' . $Total . ')' . chr(13) . chr(10) . '-------------------------------------------------' . chr(13) . chr(10) . chr(13) . chr(10); } if ($Total > 15) { if (($DR['Settings'] & 16) == 16) { $Output .= '<tr><td colspan=3><table cellpadding=8 style="border: 1px solid #E0E0E0; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; background-color: #F8F8F8;"><tr><td width=20><img src="http://www.dealplotter.com/IF/Icon-Info.png"></td><td>' . $Strings[$DR['LID']][2111] . ' ' . $Strings[$DR['LID']][2103] . '</td></tr></table></td></tr>'; } else { $Output .= $Strings[$DR['LID']][2111] . ' ' . $Strings[$DR['LID']][2103] . chr(13) . chr(10) . chr(13) . chr(10); } } $Output .= $SubOut; } } } } if (($DR['Settings'] & 16) == 16) { $Output .= '</table><br /><table style="font-size: 13px; border: 1px solid #E0E0E0; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; background-color: #F8F8F8;" cellpadding=8><tr><td>' . $Strings[$DR['LID']][2108] . ' <b><a href="http://www.dealplotter.com/?Shaddap&Key=' . $DR['CancelKey'] . '">' . $Strings[$DR['LID']][2109] . '</a></b> ' . $Strings[$DR['LID']][2110] . '</td></tr></table></body></html>'; } else { $Output .= CleanHTML($Strings[$DR['LID']][2108]) . ': http://www.dealplotter.com/?Shaddap&Key=' . $DR['CancelKey'] . ' ' . CleanHTML(str_ireplace('<br />', chr(13) . chr(10), $Strings[$DR['LID']][2110]), false); } if (SendMail($Output, $Strings[$DR['LID']][2100] . ' - ' . date('Y-m-d'), $DR['UserEmail'])) { SysLogIt('Successfully sent digest for user with ID of ' . $DR['UserID'] . '.', StatusInfo, ActionNotSpecified, 0); if (!ExecCommand("UPDATE 1400_User_Notifications SET SentDate = " . date('YmdHis') . ", DealID = " . $MaxDealID . " WHERE NotificationID = " . $DR['NID'] . ";")) { SysLogIt('Error updating notification entry with ID of ' . $DR['NID'] . '.', StatusError, ActionNotSpecified, 0); } } else { SysLogIt('Error sending digest for user with ID of ' . $DR['UserID'] . '.', StatusError); } //file_put_contents("Mail.html", $Output); } SysLogIt('Finished sending digests.', StatusInfo, ActionNotSpecified, 0); } return true; }
function GetUserLocations() { global $Response; global $UserID; global $SessionID; list($QR, $RS, $T) = QuerySet('SELECT L.LocationID, L.LocationLatitude AS Lat, L.LocationLongitude AS Lng, L.CountryID AS CID, UL.UserLocationName AS UName FROM 0700_Sessions S INNER JOIN 1000_Users U ON S.UserID = U.UserID INNER JOIN 1100_User_Locations UL ON U.UserID = UL.UserID INNER JOIN 3000_Locations L ON L.LocationID = UL.LocationID WHERE S.SessionID = ' . $SessionID . ' AND U.UserID = ' . $UserID . ' ORDER BY UL.UserLocationName;'); if ($QR < 0) { SysLogIt('Error searching for locations for user with ID of ' . $UserID . '.', StatusError, ActionSelect); } elseif ($QR > 0) { $Strings = GSA('1100,1312,1317'); $Response->R = '<DIV CLASS="ttlw">' . $Strings[1100] . '<HR></DIV><DIV CLASS="abs mvb algc">'; if ($QR < 5) { $Response->R .= '<HR><INPUT TYPE="button" CLASS="butt mrgbxs pnt" VALUE="' . $Strings[1312] . '" onClick="NewLoc();">'; } $Response->R .= '</DIV><DIV CLASS="fullsb fktbl">'; while ($DR = mysql_fetch_array($RS)) { $Response->R .= '<DIV CLASS="fll sz18 b algc padrs w30" ID="LDC' . $DR['LocationID'] . '"></DIV><DIV CLASS="flr w30 mrgtxs"><INPUT TYPE="image" CLASS="butt fklnk" SRC="/IF/Icon-Trash.png" onClick="PopQ(\'' . Pacify(Pacify(str_replace('%a', StringAdjust($DR['UName']), $Strings[1317])), true) . '\', \'DelLoc(' . $DR['LocationID'] . ');\');" onMouseOver="DoHlp(this,1366);" onMouseOut="KlHlp();"></DIV><DIV CLASS="sz12"><SPAN CLASS="fklnk sz15" onClick="SetCLoc(' . $DR['LocationID'] . ');">' . StringAdjust($DR['UName']) . '</SPAN><BR />' . $DR['Lat'] . ', ' . $DR['Lng'] . '</DIV><DIV CLASS="clr"></DIV>'; } $Response->R .= '</DIV>'; $Response->J = 'UpLTot();'; $Response->S = true; } $Response->Send(); }