Esempio n. 1
0
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();
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
function GetStatus()
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2011-04-09
        Revisions: None
          Purpose: Display status
          Returns: Nothing
      */
    /////////////////////////////////////////////////////////////
    global $Response;
    $Response->J = 'F5();';
    if ($RandomKey = GetNewAccessKey()) {
        list($QR, $RS, $T) = QuerySet('
          SELECT DS.DealSourceName AS Name, COALESCE(Dx.DCnt, 0) AS DCount, COALESCE(Dy.ACnt, 0) AS ACount
            FROM 4100_Deal_Sources DS
            LEFT JOIN (SELECT D.DealSourceID, COUNT(D.DealID) AS DCnt FROM 4000_Deals D WHERE D.DateEnds > ' . date('YmdHis') . ' GROUP BY D.DealSourceID) Dx ON DS.DealSourceID = Dx.DealSourceID
            LEFT JOIN (SELECT D.DealSourceID, ROUND(COUNT(D.DealID)/30, 0) AS ACnt FROM 4000_Deals D WHERE D.DateListed > ' . date('YmdHis', mktime(date('H'), date('i'), date('s'), date('n'), date('j') - 30, date('Y'))) . ' GROUP BY D.DealSourceID) Dy ON DS.DealSourceID = Dy.DealSourceID
           WHERE DS.DealSourceStatus & 1 = 1
           GROUP BY DS.DealSourceID
           ORDER BY DS.DealSourceName ASC;');
        if ($QR < 0) {
            SysLogIt('Error searching for source deal counts.', StatusError, ActionSelect);
        } else {
            $Response->S = true;
            $Response->R = '<DIV CLASS="ttlw">Status<INPUT TYPE="hidden" ID="Key" VALUE="' . $RandomKey . '"><HR></DIV><DIV ID="SttDiv" CLASS="abs fulls flwa algc"><TABLE CELLPADDING=1 CELLSPACING=0 BORDER=0 ID="SttTbl" CLASS="fra rbrds mgrx"><TBODY><TR><TD COLSPAN=3 CLASS="b padbs algc">Deal Counts<HR></TD></TR><TR CLASS="sz10 b algc"><TD CLASS="padls algl">Name</TD><TD>Cur.</TD><TD>Avg.</TD></TR>';
            if ($QR > 0) {
                $Entries = 0;
                while ($DR = mysql_fetch_array($RS)) {
                    $Entries++;
                    $RowClass = 'sz14';
                    if ($Entries % 2 == 0) {
                        $RowClass .= ' row';
                    }
                    $Response->R .= '<TR CLASS="sz14 ' . $RowClass . '">
                               <TD CLASS="padrs padls" NOWRAP><DIV>' . $DR['Name'] . '</DIV></TD>
                               <TD CLASS="padrs padls algc" NOWRAP><DIV>' . $DR['DCount'] . '</DIV></TD>
                               <TD CLASS="padrs padls algc" NOWRAP><DIV>' . $DR['ACount'] . '</DIV></TD>
                            </TR>';
                }
            }
            $Response->R .= '</TBODY></TABLE></DIV>';
            $Response->J = '';
        }
    }
    $Response->Send();
}
Esempio n. 4
0
function GetDetails()
{
    global $LanguageID;
    global $Response;
    global $UserID;
    $Strings = GSA('1000,1329,1330,1331,1332,1334,1339,1350,1367,1650,1651,1652,1653,1654,1655,1656,1657,1658,1659,1660,1661,1662,1663,1664,1665,1666,1667,1669,1670,1671,1672,1673', $LanguageID, false, true);
    if (isset($_POST['DID'])) {
        if (is_numeric($_POST['DID'])) {
            list($QR, $DR, $T) = QuerySingle("SELECT COALESCE(LSDa.StringText, LSDb.StringText) AS DText, D.DealPrice AS DPrice, D.DealQR AS QR, DC.MPrice, COALESCE(DC.DCount, 1) AS DCount,\n                COALESCE(UR.RAvg, 0) AS RAvg, COALESCE(UR.RCount, 0) AS RCount, COALESCE(DCT.CCount, 0) AS CCount, COALESCE(URx.Score, 0) AS MyScore,\n                S.StoreID, S.StoreName AS SName, S.StoreWebsite AS SWeb, L.LocationAddress AS Adr, DS.DealSourceName AS DSName, DS.DealSourceFileName AS FName,\n                UNIX_TIMESTAMP(D.DateExpiry) AS ExpDate, COUNT(L.LocationID) AS LCount, UF.FavoriteID AS FavID, L.LocationLatitude AS Lat, L.LocationLongitude AS Lng, DSU.URLID\n               FROM 4000_Deals D\n              INNER JOIN 4100_Deal_Sources DS ON DS.DealSourceID = D.DealSourceID\n              INNER JOIN 2000_Stores S ON D.StoreID = S.StoreID\n               LEFT JOIN (SELECT StoreID, AVG(Score) AS RAvg, COUNT(ReviewID) AS RCount FROM 1300_User_Reviews WHERE Status = 1 GROUP BY StoreID) UR ON UR.StoreID = S.StoreID\n               LEFT JOIN (SELECT StoreID, UserID, Score FROM 1300_User_Reviews) URx ON URx.UserID = " . $UserID . " AND URx.StoreID = S.StoreID\n               LEFT JOIN 2200_Store_Locations SL ON SL.StoreID = S.StoreID\n               LEFT JOIN 3000_Locations L ON SL.LocationID = L.LocationID AND L.LocationLatitude != -1\n               LEFT JOIN 0200_Language_Strings LSDa ON D.StringID = LSDa.StringID AND LSDa.LanguageID = " . $LanguageID . "\n               LEFT JOIN 0200_Language_Strings LSDb ON D.StringID = LSDb.StringID AND LSDb.LanguageID = 1\n               LEFT JOIN (SELECT StoreID, COUNT(DealID) AS DCount, MIN(DealPrice) AS MPrice FROM 4000_Deals GROUP BY StoreID) DC ON DC.StoreID = S.StoreID\n               LEFT JOIN (SELECT DealID, COUNT(ClickID) AS CCount FROM 4200_Deal_Clickthroughs WHERE DealID = " . (int) $_POST['DID'] . " GROUP BY DealID) DCT ON DCT.DealID = D.DealID\n               LEFT JOIN 1200_User_Favorites UF ON UF.DealID = D.DealID AND UF.UserID = " . $UserID . "\n               LEFT JOIN (SELECT URLID, Latitude, Longitude FROM 4110_Deal_Source_URLs GROUP BY Latitude, Longitude) DSU ON DSU.Latitude = L.LocationLatitude AND DSU.Longitude = L.LocationLongitude\n              WHERE D.DealID = " . (int) $_POST['DID'] . "\n              GROUP BY D.DealID;");
            if ($QR < 0) {
                SysLogIt('Error finding deal with ID of ' . (int) $_POST['DID'] . '.', StatusError, ActionSelect);
            } elseif ($QR > 0) {
                $Response->S = true;
                $Response->C = (int) $_POST['DID'];
                $Response->R = array();
                $Response->R[2] = 0;
                $Response->R[3] = 0;
                //Do header
                //-------------------
                $Response->R[0] = '';
                if (!isset($_POST['SM'])) {
                    $Response->R[0] = ' <DIV CLASS="cls z3" onClick="HPanR();">' . Pacify($Strings[1000]) . '</DIV>';
                }
                $Response->R[0] .= '<DIV CLASS="b sz18 padr w100p nowr flwh">' . $DR['SName'] . '</DIV>
                            <DIV CLASS="sz13">';
                if (!(is_null($DR['SWeb']) || trim($DR['SWeb']) == '')) {
                    $Response->R[0] .= '<DIV><A HREF="' . $DR['SWeb'] . '" TARGET="_blank">' . $Strings[1650] . '</A></DIV><DIV>';
                }
                if ($DR['LCount'] > 0) {
                    $Response->R[0] .= '   <DIV>' . ($DR['LCount'] == 1 ? $DR['Adr'] : str_replace('%a', $DR['LCount'], $Strings[1665]));
                }
                $Response->R[0] .= '</DIV><HR>';
                //Do buttons
                //-------------------
                $Response->R[0] .= '<DIV CLASS="sz14 w100p nowr flwh h30" ID="DetB">
                             <DIV CLASS="din butt dtb tibu mgrrxs" onClick="Buy(' . (int) $_POST['DID'] . ')" onMouseOver="DoHlp(this,1305);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1330] . '</DIV></DIV>';
                if (!isset($_POST['SM'])) {
                    //if (($UserID > 0) && (is_null($DR['FavID']))) $Response->R[0] .= ' <DIV CLASS="din butt dtb tisv mgrrxs" onClick="TogSav(1,'.(int)$_POST['DID'].'); RstDet('.(int)$_POST['DID'].');" onMouseOver="DoHlp(this,1306);" onMouseOut="KlHlp();"><DIV CLASS="padlm">'.$Strings[1331].'</DIV></DIV>';
                    if ($UserID > 0) {
                        if (is_null($DR['FavID'])) {
                            $Response->R[0] .= ' <DIV CLASS="din butt dtb tisv mgrrxs" onClick="TogSav(1,' . (int) $_POST['DID'] . ',1);" onMouseOver="DoHlp(this,1306);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1331] . '</DIV></DIV>';
                        } else {
                            $Response->R[0] .= ' <DIV CLASS="din dbutt dtb tisvd mgrrxs"><DIV CLASS="padlm">' . $Strings[1367] . '</DIV></DIV>';
                        }
                    } else {
                        $Response->R[0] .= ' <DIV CLASS="din dbutt dtb tidsv mgrrxs" onMouseOver="DoHlp(this,1334,1);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1331] . '</DIV></DIV>';
                    }
                    if (is_null($DR['FavID'])) {
                        $Response->R[0] .= '  <DIV CLASS="din butt dtb tihi mgrrxs" onClick="KlD(' . (int) $_POST['DID'] . '); HPanR();" onMouseOver="DoHlp(this,1307);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1332] . '</DIV></DIV>';
                    } else {
                        $Response->R[0] .= '  <DIV CLASS="din butt dtb tihi mgrrxs" onClick="TogSav(0,' . (int) $_POST['DID'] . ',1);" onMouseOver="DoHlp(this,1352);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1339] . '</DIV></DIV>';
                    }
                }
                $Response->R[0] .= '   <DIV CLASS="din butt dtb tish mgrrxs" onClick="Share(' . (int) $_POST['DID'] . ')" onMouseOver="DoHlp(this,1351);" onMouseOut="KlHlp();"><DIV CLASS="padlm">' . $Strings[1350] . '</DIV></DIV>
                               </DIV>';
                $Response->R[0] .= '</DIV>';
                //Do content
                //-------------------
                $Response->D .= '<DIV CLASS="sz13 dkbl" ID="DetC">
                             <DIV CLASS="sech"><IMG SRC="/IF/H-Des.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1651] . '</B></DIV>
                             <DIV CLASS="padls">' . $DR['DText'] . '</DIV>
                             <DIV CLASS="padls">
                               <UL>';
                if ($DR['ExpDate'] > 0 && date('Y', $DR['ExpDate']) > 1969) {
                    if ($DR['ExpDate'] < time()) {
                        $DLeft = $Strings[1329];
                    } else {
                        $DLeft = round(($DR['ExpDate'] - time()) / 60 / 60 / 24);
                        if ($DLeft < 180) {
                            $DLeft = '<span class="red">' . $DLeft . '</span>';
                        }
                        $DLeft = $DLeft . ' ' . $Strings[1653];
                    }
                    $Response->D .= '<LI>' . $Strings[1652] . ' ' . date('Y-m-d', $DR['ExpDate']) . ' (' . $DLeft . ')</LI>';
                }
                $Response->D .= '     <LI>' . $Strings[1667] . ' <SPAN CLASS="fklnk" onClick="Buy(' . (int) $_POST['DID'] . ')" onMouseOver="DoHlp(this,1305);" onMouseOut="KlHlp();">' . $DR['DSName'] . '</SPAN>.</LI>
                              </UL>
                            </DIV>
                             <DIV CLASS="sech padts"><IMG SRC="/IF/H-Stat.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1654] . '</B></DIV>
                             <DIV CLASS="padls">
                               <UL>
                                 <LI>' . str_replace('%a', $DR['DCount'] > 1 ? '<DIV CLASS="nbutt" onClick="DHist(' . (int) $_POST['DID'] . ');" onMouseOver="DoHlp(this,1144);" onMouseOut="KlHlp();">' . $DR['DCount'] . ' ' . $Strings[1672] . '</DIV>' : '<B>' . $DR['DCount'] . '</B> ' . $Strings[1673], $Strings[1655]) . '</LI>
                                 <LI>';
                $Response->D .= is_null($DR['MPrice']) || $DR['DPrice'] <= $DR['MPrice'] ? $Strings[1656] : $Strings[1657];
                $Response->D .= '     </LI>';
                if ($DR['CCount'] > 0) {
                    $Response->D .= '<LI>' . str_replace('%a', $DR['CCount'], $Strings[1658]) . '</LI>';
                }
                $Response->D .= '   </UL>
                            </DIV>
                             <DIV CLASS="sech"><IMG SRC="/IF/H-Rev.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1659] . '</B></DIV>
                             <DIV CLASS="padls"><SPAN CLASS="fll sz24 mgrrxs dkgray fra algc"><B>' . ($DR['RAvg'] == 0 ? '--' : number_format($DR['RAvg'], 1)) . '</B></SPAN>' . str_replace('%a', $DR['RCount'], $Strings[1660]) . '<BR />';
                if ($DR['RCount'] > 0) {
                    $Response->D .= '<DIV CLASS="nbutt" onClick="GetRvw(' . (int) $_POST['DID'] . ',0)">' . $Strings[1661] . '</DIV> &bull; ';
                }
                if ($UserID > 0) {
                    $Response->D .= (int) $DR['MyScore'] == 0 ? '<DIV CLASS="nbutt" onClick="AddRvw(' . (int) $_POST['DID'] . ');">' . $Strings[1662] . '</DIV>' : '<SPAN>' . str_replace('%a', (int) $DR['MyScore'], $Strings[1663]) . '</SPAN>';
                } else {
                    $Response->D .= '<SPAN CLASS="fklnk" onClick="NewAcct();">' . $Strings[1664] . '</SPAN>';
                }
                $Response->D .= '   <DIV CLASS="clr"></DIV>
                           </DIV>';
                if ($DR['LCount'] > 1) {
                    $Response->D .= '<DIV CLASS="sech padts"><IMG SRC="/IF/H-Adr.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1666] . '</B></DIV><DIV CLASS="padls"><UL>';
                    list($SQR, $SRS, $T) = QuerySet('SELECT LD.LocationID, LD.LocationAddress AS Adr
                 FROM 2200_Store_Locations SL
                INNER JOIN 3000_Locations LD ON LD.LocationID = SL.LocationID
                WHERE SL.StoreID = ' . $DR['StoreID'] . ';');
                    if ($SQR > 0) {
                        while ($SDR = mysql_fetch_array($SRS)) {
                            $Response->D .= '<LI>' . $SDR['Adr'] . '</LI>';
                        }
                    } elseif ($SQR < 0) {
                        SysLogIt('Error searching for saved deal\'s store locations.', StatusError, ActionSelect);
                        $Response->S = false;
                        $Response->Send();
                    }
                    $Response->D .= '</UL>
                           </DIV>';
                } elseif (is_null($DR['URLID'])) {
                    if ($DR['LCount'] > 0) {
                        $Response->D .= '<DIV CLASS="sech padt"><IMG SRC="/IF/H-Eye.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1669] . '</B></DIV>
                               <DIV ID="GSVDIV" CLASS="mrgls gsv"></DIV>';
                        $Response->R[2] = $DR['Lat'];
                        $Response->R[3] = $DR['Lng'];
                    }
                }
                if (!is_null($DR['QR'])) {
                    $Response->D .= '<DIV CLASS="sech padt"><IMG SRC="/IF/H-Pho.png" WIDTH=20 HEIGHT=20 ALT="" CLASS="valgm padrxs"><B>' . $Strings[1670] . '</B></DIV>
                             <DIV CLASS="mrgl padbxs">' . $Strings['1671'] . '</DIV>
                             <DIV CLASS="mrgls algc"><IMG SRC="/QR/' . $DR['QR'] . '" CLASS="rbrds fra padaxs" WIDTH=150 HEIGHT=150 ALT=""></DIV>';
                }
                $Response->D .= '</DIV>';
                if (isset($_POST['ULID'])) {
                    if (is_numeric($_POST['ULID'])) {
                        if ((int) $_POST['ULID'] > 0) {
                            SetFilter((int) $_POST['ULID'], FilterDeal, (int) $_POST['DID'], 0, -1, false);
                        }
                    }
                }
                $Response->Send();
            }
        }
    }
    $Response->S = false;
    $Response->Send();
}