Example #1
0
function CheckUnsubscribe()
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2011-08-14
        Revisions: None
          Purpose: Unsubscribes a user from all notifications
          Returns: Nothing
      */
    /////////////////////////////////////////////////////////////
    if (isset($_GET['Key'])) {
        list($QR, $DR, $T) = QuerySingle("SELECT UN.NotificationID AS NID, UN.UserID AS UID\n             FROM 1400_User_Notifications UN\n            WHERE UN.CancelKey = '" . Pacify($_GET['Key']) . "';");
        if ($QR < 0) {
            SysLogIt('Error searching for cancel key ' . Pacify($_GET['Key']) . '.', StatusError, ActionSelect);
        } else {
            $Strings = GSA('2112');
            if ($QR > 0) {
                if (ExecCommand("UPDATE 1000_Users SET UserFlags = (UserFlags & ~" . UserReminders . ") WHERE UserID = " . $DR['UID'] . ";")) {
                    SysLogIt('Successfully disabled reminders for user with ID of ' . $DR['UID'] . '.', StatusInfo);
                    if (ExecCommand("UPDATE 1400_User_Notifications SET Settings = 0 WHERE NotificationID = " . $DR['NID'] . ";")) {
                        SysLogIt('Successfully disabled digests for user with ID of ' . $DR['UID'] . '.', StatusInfo);
                        return DisplayMainScreen("SetBackMap(); PopC('" . Pacify(Pacify($Strings[2112]), true) . "','GH();');");
                    } else {
                        SysLogIt('Could not disable digests for user with ID of ' . $UID . '.', StatusError, ActionInsert);
                    }
                } else {
                    SysLogIt('Could not disable reminders for user with ID of ' . $UID . '.', StatusError, ActionInsert);
                }
            }
        }
    }
    return DisplayMainScreen('PopErr();');
}
Example #2
0
function ValidAccessKey($InKey)
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2010-12-07
        Revisions: None
          Purpose: Verifies an existing access key
          Returns: True or false
      */
    /////////////////////////////////////////////////////////////
    if (!ExecCommand("DELETE FROM 0600_Access_Keys WHERE UNIX_TIMESTAMP(CreateDate) < " . mktime(date('H') - 3, date('i'), date('s'), date('n'), date('j'), date('Y')) . ";")) {
        return SysLogIt('Error flushing old access keys.', StatusError, ActionDelete);
    }
    list($QR, $DR, $T) = QuerySingle("SELECT KeyID FROM 0600_Access_Keys WHERE UniqueKey = '" . Pacify($InKey) . "';");
    if ($QR < 0) {
        return SysLogIt('Error searching for access key.', StatusError, ActionSelect);
    }
    if ($QR == 0) {
        return false;
    }
    return (int) $DR['KeyID'];
}
Example #3
0
function DoHistoryGraph($SID)
{
    $Filepath = dirname(__FILE__) . '/../Hist/';
    list($QR, $DR, $T) = QuerySingle("SELECT SH.HistoryID AS HID, SH.Filename AS FName, COUNT(D.DealID) AS Deals, MAX(GREATEST(D.DealPrice, D.DealValue)) AS MaxVal,\n            AVG(D.DealValue) AS AvgVal, AVG(D.DealPrice) AS AvgPrc\n           FROM 4000_Deals D\n           LEFT JOIN 2600_Store_History SH ON D.StoreID = SH.StoreID\n          WHERE D.StoreID = " . $SID . "\n          GROUP BY D.StoreID;");
    if ($QR < 0) {
        return SysLogIt('Error searching deals for history.', StatusError, ActionSelect);
    }
    if ($QR > 0) {
        list($QR, $SDR, $T) = QuerySingle('SELECT GROUP_CONCAT(X.DealID) AS DIDs, GROUP_CONCAT(X.DealPrice) AS DPrcs, GROUP_CONCAT(X.DealValue) AS DVals, GROUP_CONCAT(X.DealSourceName) AS SNams, GROUP_CONCAT(X.DEnd) AS DEnds
             FROM (
               SELECT D.StoreID, D.DealID, D.DealPrice, D.DealValue, DS.DealSourceName, UNIX_TIMESTAMP(D.DateEnds) AS DEnd
                 FROM 4000_Deals D
                INNER JOIN 4100_Deal_Sources DS ON D.DealSourceID = DS.DealSourceID
                WHERE D.StoreID = ' . $SID . '
                ORDER BY D.DateEnds
             ) X
             GROUP BY X.StoreID;');
        if ($QR < 0) {
            return SysLogIt('Error searching deal details for history.', StatusError, ActionSelect);
        }
        if ($QR > 0) {
            if ($DR['Deals'] <= 1) {
                return false;
            }
            if (!is_null($DR['FName'])) {
                if (file_exists($Filepath . $DR['FName'])) {
                    unlink($Filepath . $DR['FName']);
                }
            }
            $Filename = md5($SID . time()) . '.svg';
            $LMarg = 15;
            $RMarg = 30;
            $TMarg = 25;
            $VHeight = 80;
            $HSpacing = (int) ((400 - $LMarg - $RMarg) / ($DR['Deals'] - 1));
            $DPrcs = explode(',', $SDR['DPrcs']);
            $DVals = explode(',', $SDR['DVals']);
            $SNams = explode(',', $SDR['SNams']);
            $DEnds = explode(',', $SDR['DEnds']);
            $LPrc = 0;
            $MSav = 0;
            $MSvP = 0;
            for ($x = 0; $x < $DR['Deals']; $x++) {
                if ((int) $DPrcs[$x] < $LPrc || $LPrc == 0) {
                    $LPrc = (int) $DPrcs[$x];
                }
                if ((int) $DVals[$x] - (int) $DPrcs[$x] > $MSav) {
                    $MSav = (int) $DVals[$x] - (int) $DPrcs[$x];
                }
                if ((int) (100 - $DPrcs[$x] / $DVals[$x] * 100) > $MSvP) {
                    $MSvP = (int) (100 - $DPrcs[$x] / $DVals[$x] * 100);
                }
            }
            $Output = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400" height="' . ($TMarg + $VHeight + 20 + ($DR['Deals'] * 20 + 10) + 10 + 30) . '">';
            //Grid
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<path d="M' . $LMarg . ',' . ($TMarg + ($VHeight - (int) ($DPrcs[$x] / $DR['MaxVal'] * $VHeight))) . ' L' . ($LMarg + ($DR['Deals'] - 1) * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) ($DPrcs[$x] / $DR['MaxVal'] * $VHeight))) . '" style="stroke: #C0C0C0; stroke-width: 1; fill: none;"/>';
                $Output .= '<path d="M' . $LMarg . ',' . ($TMarg + ($VHeight - (int) ($DVals[$x] / $DR['MaxVal'] * $VHeight))) . ' L' . ($LMarg + ($DR['Deals'] - 1) * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) ($DVals[$x] / $DR['MaxVal'] * $VHeight))) . '" style="stroke: #C0C0C0; stroke-width: 1; fill: none;"/>';
                $Output .= '<path d="M' . $LMarg . ',' . ($TMarg + ($VHeight - (int) (($DVals[$x] - $DPrcs[$x]) / $DR['MaxVal'] * $VHeight))) . ' L' . ($LMarg + ($DR['Deals'] - 1) * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) (($DVals[$x] - $DPrcs[$x]) / $DR['MaxVal'] * $VHeight))) . '" style="stroke: #C0C0C0; stroke-width: 1; fill: none;"/>';
            }
            $Output .= '<path d="M' . $LMarg . ',' . $TMarg . ' L' . ($LMarg + ($DR['Deals'] - 1) * $HSpacing) . ',' . $TMarg . '" style="stroke: #607080; stroke-width: 1; fill: none;"/>';
            $Output .= '<text x="' . ($LMarg + (400 - $RMarg) - 10) . '" y="' . ($TMarg + 5) . '" style="font-family: Arial; font-size:12px; stroke: #607080;">' . $DR['MaxVal'] . '</text>';
            $Output .= '<path d="M' . $LMarg . ',' . ($TMarg + $VHeight) . ' L' . ($LMarg + ($DR['Deals'] - 1) * $HSpacing) . ',' . ($TMarg + $VHeight) . '" style="stroke: #607080; stroke-width: 1; fill: none;"/>';
            $Output .= '<text x="' . ($LMarg + (400 - $RMarg) - 10) . '" y="' . ($TMarg + $VHeight + 5) . '" style="font-family: Arial; font-size:12px; stroke: #607080;">0</text>';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<path d="M' . ($LMarg + $x * $HSpacing) . ',' . $TMarg . ' L' . ($LMarg + $x * $HSpacing) . ',' . ($TMarg + $VHeight) . '" style="stroke: #607080; stroke-width: 1; fill: none;"/>';
            }
            //Text
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<circle cx="' . ($LMarg + $x * $HSpacing) . '" cy="' . ($TMarg - 15) . '" r="8" style="fill:#000000"/>';
                $Output .= '<text x="' . ($LMarg + $x * $HSpacing) . '" y="' . ($TMarg - 11) . '" style="font-family: Arial; font-size:10px; fill: #FFFFFF; stroke: #FFFFFF;" text-anchor="middle">' . ($x + 1) . '</text>';
            }
            /*
            for ($x=0; $x<$DR['Deals']; $x++) {
              $Output .= '<text x="'.($LMarg+0+($x*$HSpacing)).'" y="'.($TMarg-10).'" transform="rotate(270 '.($LMarg+0+($x*$HSpacing)).','.($TMarg-10).')" style="font-family: Arial; font-size:12px;">'.date('Y.m.d', $DEnds[$x]).'</text>';
              $Output .= '<text x="'.($LMarg+10+($x*$HSpacing)).'" y="'.($TMarg-10).'" transform="rotate(270 '.($LMarg+10+($x*$HSpacing)).','.($TMarg-10).')" style="font-family: Arial; font-size:12px;">'.$SNams[$x].'</text>';
            }
            */
            //Values
            $Output .= '<path d="';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= ($x == 0 ? 'M' : 'L') . ($LMarg + $x * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) ($DVals[$x] / $DR['MaxVal'] * $VHeight))) . ' ';
            }
            $Output .= '" style="stroke: #974d57; stroke-width: 2; fill: none;"/>';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<circle cx="' . ($LMarg + $x * $HSpacing) . '" cy="' . ($TMarg + ($VHeight - (int) ($DVals[$x] / $DR['MaxVal'] * $VHeight))) . '" r="4" style="fill:#974d57"/>';
            }
            //Prices
            $Output .= '<path d="';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= ($x == 0 ? 'M' : 'L') . ($LMarg + $x * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) ($DPrcs[$x] / $DR['MaxVal'] * $VHeight))) . ' ';
            }
            $Output .= '" style="stroke: #448541; stroke-width: 2; fill: none;"/>';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<circle cx="' . ($LMarg + $x * $HSpacing) . '" cy="' . ($TMarg + ($VHeight - (int) ($DPrcs[$x] / $DR['MaxVal'] * $VHeight))) . '" r="4" style="fill:#448541"/>';
            }
            //Savings
            $Output .= '<path d="';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= ($x == 0 ? 'M' : 'L') . ($LMarg + $x * $HSpacing) . ',' . ($TMarg + ($VHeight - (int) (($DVals[$x] - $DPrcs[$x]) / $DR['MaxVal'] * $VHeight))) . ' ';
            }
            $Output .= '" style="stroke: #0000FF; stroke-width: 2; fill: none;"/>';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                $Output .= '<circle cx="' . ($LMarg + $x * $HSpacing) . '" cy="' . ($TMarg + ($VHeight - (int) (($DVals[$x] - $DPrcs[$x]) / $DR['MaxVal'] * $VHeight))) . '" r="4" style="fill:#0000FF"/>';
                //$Output .= '<text x="'.($LMarg+3+($x*$HSpacing)).'" y="'.(($TMarg+($VHeight-((int)(($DVals[$x] - $DPrcs[$x]) / $DR['MaxVal'] * $VHeight))))-5).'" style="font-family: Arial; font-size:10px; fill: #0000FF;">'.(int)($DPrcs[$x] / $DVals[$x] * 100).'%</text>';
            }
            //Tables
            for ($x = 0; $x < $DR['Deals']; $x++) {
                if ($x % 2 != 0) {
                    $Output .= '<rect x="0" y="' . ($TMarg + $VHeight + 25 + $x * 20) . '" width="400" height="20" style="stroke-width: 0; fill: #F0F0F0;" />';
                }
            }
            $Output .= '<rect x="0" y="' . ($TMarg + $VHeight + 20) . '" rx="10" ry="10" width="400" height="' . (($DR['Deals'] + 1) * 20 + 20) . '" style="stroke: #C0C0C0; fill: none;" />';
            for ($x = 0; $x < $DR['Deals']; $x++) {
                if ((int) $DPrcs[$x] == $LPrc) {
                    $Output .= '<rect x="298" y="' . ($TMarg + $VHeight + 25 + $x * 20) . '" rx="5" ry="5" width="40" height="20" style="stroke: #009900; stroke-width: 1; fill: none;" />';
                }
                if ((int) $DVals[$x] - (int) $DPrcs[$x] == $MSav) {
                    $Output .= '<rect x="248" y="' . ($TMarg + $VHeight + 25 + $x * 20) . '" rx="5" ry="5" width="40" height="20" style="stroke: #009900; stroke-width: 1; fill: none;" />';
                }
                if ((int) (100 - $DPrcs[$x] / $DVals[$x] * 100) == $MSvP) {
                    $Output .= '<rect x="348" y="' . ($TMarg + $VHeight + 25 + $x * 20) . '" rx="5" ry="5" width="40" height="20" style="stroke: #009900; stroke-width: 1; fill: none;" />';
                }
                $Output .= '<text x="0" y="' . ($TMarg + $VHeight + 40 + $x * 20) . '" style="font-family: Arial; font-size:12px;">';
                $Output .= '<tspan x="5" style="font-weight: bold;">' . ($x + 1) . '.</tspan>';
                $Output .= '<tspan x="22">' . date('Y.m.d', $DEnds[$x]) . '</tspan>';
                $Output .= '<tspan x="90">' . $SNams[$x] . '</tspan>';
                $Output .= '<tspan x="200" style="fill: #974d57">' . $DVals[$x] . '</tspan>';
                $Output .= '<tspan x="240">-</tspan>';
                $Output .= '<tspan x="250" style="fill: #0000FF">' . ($DVals[$x] - $DPrcs[$x]) . '</tspan>';
                $Output .= '<tspan x="290">=</tspan>';
                $Output .= '<tspan x="300" style="fill: #448541">' . $DPrcs[$x] . '</tspan>';
                $Output .= '<tspan x="350" style="fill: #0000FF">(' . (int) (100 - $DPrcs[$x] / $DVals[$x] * 100) . '%)</tspan>';
                $Output .= '</text>';
            }
            $Output .= '<line x1="0" y1="' . ($TMarg + $VHeight + 20 + ($DR['Deals'] * 20 + 10)) . '" x2="400" y2="' . ($TMarg + $VHeight + 20 + ($DR['Deals'] * 20 + 10)) . '" style="stroke: #C0C0C0;" />';
            $Output .= '<text x="0" y="' . ($TMarg + $VHeight + 20 + ($DR['Deals'] * 20 + 10) + 20) . '" style="font-family: Arial; font-size:12px; font-weight: bold;">';
            $Output .= '<tspan x="20" style="font-weight: bold;">=</tspan>';
            $Output .= '<tspan x="200" style="fill: #974d57">' . (int) $DR['AvgVal'] . '</tspan>';
            $Output .= '<tspan x="240">-</tspan>';
            $Output .= '<tspan x="250" style="fill: #0000FF">' . ((int) $DR['AvgVal'] - (int) $DR['AvgPrc']) . '</tspan>';
            $Output .= '<tspan x="290">=</tspan>';
            $Output .= '<tspan x="300" style="fill: #448541">' . (int) $DR['AvgPrc'] . '</tspan>';
            $Output .= '<tspan x="350" style="fill: #0000FF">(' . (int) (100 - (int) $DR['AvgPrc'] / (int) $DR['AvgVal'] * 100) . '%)</tspan>';
            $Output .= '</text>';
            $Output .= '<image width="11" height="12" x="5" y="' . ($TMarg + $VHeight + 20 + ($DR['Deals'] * 20 + 10) + 8) . '" xlink:href="/IF/Avg.png" />';
            $Output .= '</svg>';
            $File = fopen($Filepath . $Filename, 'x');
            if ($File === false) {
                return SysLogIt('Error opening history graph for output.', StatusError);
            }
            fwrite($File, $Output);
            fclose($File);
            if (file_exists($Filepath . $Filename)) {
                if (is_null($DR['HID'])) {
                    if (!ExecCommand("INSERT INTO 2600_Store_History (StoreID, Filename, LastUpdated) VALUES (" . $SID . ", '" . Pacify($Filename) . "', " . date('YmdHis') . ");")) {
                        return SysLogIt('Error adding history graph for store with ID of ' . $SID . '. File ' . $Filename . ' is orphaned.', StatusError, ActionInsert);
                    }
                } else {
                    if (!ExecCommand("UPDATE 2600_Store_History SET Filename = '" . Pacify($Filename) . "', LastUpdated = " . date('YmdHis') . " WHERE HistoryID = " . $DR['HID'] . ";")) {
                        return SysLogIt('Error updating history graph for store with ID of ' . $SID . '. File ' . $Filename . ' is orphaned.', StatusError, ActionUpdate);
                    }
                }
                SysLogIt('Created history graph for store with ID of ' . $SID . '.', StatusInfo);
                return $Filename;
            }
            SysLogIt('Could not find generated history file for store with ID of ' . $SID . '.', StatusError);
            unlink($Filepath . $Filename);
        }
    } else {
        return SysLogIt('Could not find deals for history.', StatusError, ActionSelect);
    }
    return false;
}
Example #4
0
function SetStrings()
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2010-12-09
        Revisions: None
          Purpose: Set language strings
          Returns: Nothing
      */
    /////////////////////////////////////////////////////////////
    global $Response;
    $Response->J = 'F5();';
    if (isset($_POST['Key'])) {
        if ($AKey = ValidAccessKey($_POST['Key'])) {
            if ($NumLanguages = CountLanguages()) {
                //Validation
                foreach ($_POST as $Key => $Value) {
                    $ID = (int) substr($Key, 1);
                    switch (strtolower(substr($Key, 0, 1))) {
                        case 's':
                            if (!is_numeric($Value) || (int) $Value == 0) {
                                $Response->R = 'Valid number required.';
                                $Response->J = "Foc('" . $Key . "');";
                                $Response->Send();
                            }
                            if ($ID < 0) {
                                list($QR, $DR, $T) = QuerySingle("SELECT StringID FROM 0100_Strings WHERE StringID = " . (int) $Value . ";");
                                if ($QR > 0) {
                                    $Response->R = 'This ID is already in use.';
                                    $Response->J = "Foc('" . $Key . "');";
                                    $Response->Send();
                                }
                            }
                            for ($x = 1; $x <= $NumLanguages; $x++) {
                                if (!isset($_POST['X' . $ID . '-' . $x])) {
                                    $Response->R = 'Missing strings for language with ID of ' . $x . '.';
                                    $Response->J = "Foc('" . $Key . "');";
                                    $Response->Send();
                                }
                            }
                            break;
                        case 'd':
                            if (trim($Value) == '') {
                                $Response->R = 'Field can not be blank.';
                                $Response->J = "Foc('" . $Key . "');";
                                $Response->Send();
                            }
                            break;
                    }
                }
                //Saving
                DeleteAccessKey($AKey);
                $Response->J = 'EdtStr(true);';
                $LastID = 0;
                $StringID = 0;
                foreach ($_POST as $Key => $Value) {
                    $ID = (int) substr($Key, 1);
                    $UpdateID = 0;
                    switch (strtolower(substr($Key, 0, 1))) {
                        case 's':
                            if ($ID < 0) {
                                if (!($StringID = InsertNewString("INSERT INTO 0100_Strings (StringID) VALUES (" . (int) $Value . ");", (int) $Value))) {
                                    $Response->Send();
                                }
                                $LastID = $ID;
                            }
                            break;
                        case 'd':
                            if ($ID < 0 && $LastID == $ID && $StringID > 0) {
                                $UpdateID = $StringID;
                            } elseif ($ID > 0) {
                                $UpdateID = $ID;
                            }
                            if ($UpdateID > 0) {
                                if (ExecCommand("UPDATE 0100_Strings SET Description = '" . Pacify($Value) . "' WHERE StringID = " . $UpdateID . ";")) {
                                    SysLogIt('Updated string description with ID of ' . $UpdateID . '.', StatusInfo, ActionUpdate);
                                } else {
                                    SysLogIt('Error updating string description with ID of ' . $UpdateID . '.', StatusError, ActionUpdate);
                                    $Response->Send();
                                }
                            }
                            break;
                        case 'l':
                            if (ExecCommand("UPDATE 0200_Language_Strings SET StringText = '" . Pacify($Value) . "' WHERE LinkID = " . $ID . ";")) {
                                SysLogIt('Updated language string with ID of ' . $ID . '.', StatusInfo, ActionUpdate);
                            } else {
                                SysLogIt('Error updating language string with ID of ' . $ID . '.', StatusError, ActionUpdate);
                                $Response->Send();
                            }
                            break;
                        case 'x':
                            $ID = (int) substr($Key, 1, strlen($Key) - 3);
                            $Lang = (int) substr($Key, strlen($Key) - 1);
                            if ($Lang > 0 && $Lang <= $NumLanguages) {
                                if ($ID < 0 && ($LastID = $ID && $StringID > 0)) {
                                    $UpdateID = $StringID;
                                } elseif ($ID > 0) {
                                    $UpdateID = $ID;
                                }
                                if ($UpdateID > 0) {
                                    if (!InsertAndRetrieveID("INSERT INTO 0200_Language_Strings (LanguageID, StringID, StringText) VALUES (" . $Lang . "," . $UpdateID . ",'" . Pacify($Value) . "');", 'language string')) {
                                        $Response->Send();
                                    }
                                }
                            }
                            break;
                    }
                }
                $Response->S = true;
            }
        }
    }
    $Response->Send();
}
Example #5
0
function CreateNewString($LID, $RangeStart, $RangeEnd, $Description, $StringText)
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2010-12-05
        Revisions: None
          Purpose: Creates a new string based on an available range of IDs
          Returns: Newly created string ID, or false
      */
    /////////////////////////////////////////////////////////////
    //Get next available string ID
    list($QR, $DR, $T) = QuerySingle("SELECT MAX(StringID) AS MID FROM 0100_Strings WHERE StringID BETWEEN " . $RangeStart . " AND " . $RangeEnd . ";");
    if ($QR < 0) {
        return SysLogIt('Error retrieving available string ID.', StatusError, ActionSelect);
    }
    $StringID = is_null($DR['MID']) ? $RangeStart : (int) $DR['MID'] + 1;
    //Insert new string header
    if (!InsertNewString("INSERT INTO 0100_Strings (StringID, Description) VALUES (" . $StringID . ",'" . Pacify($Description) . "');", $StringID)) {
        return false;
    }
    //Insert new string entry
    if (!ExecCommand("INSERT INTO 0200_Language_Strings (LanguageID, StringID, StringText) VALUES (" . (int) $LID . "," . $StringID . ",'" . Pacify($StringText) . "');")) {
        return SysLogIt('Error creating new string entry.', StatusError, ActionInsert);
    }
    SysLogIt('Created new string entry.', StatusInfo, ActionInsert);
    return $StringID;
}
Example #6
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();
}
Example #7
0
function ValidateForm($InArray)
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery Corp.
          Created: v1.0.0 - 2009-07-30
        Revisions: None
          Purpose: Validates a webform based on passed parameters
          Returns: (Boolean) Validation success, (String) Return message(s)
          
       Parameters: An array of sub-arrays, defining the validation.
                   Each sub-array is structured as follows:
                    Element 0 (Type):
                      0: GET variable
                      1: POST variable
                    Element 1 (Name):
                      Name of variable
                    Element 2 (Enforcement):
                     -1: Must not exist
                      0: Can exist
                      1: Must exist
                    Element 3 (Validation):
                      0: No validation
                      1: Must exist between inclusive range (numeric only)
                      2: Must exist as result of DB query
                      3: Must not be blank (string only)
                      4: Must be at least X characters long (string only)
                    Element 4 (Comparison):
                      Either a numeric value representing the lower limit of a range (ValidateRange),
                       or a number representing the minimum string length (ValidateLength),
                       or a string representing the query to run (ValidateQuery),
                       or null
                    Element 5 (Comparison):
                      Either a numeric value representing the upper limit of a range (ValidateLength),
                       or null
                    Element 6 (Error):
                      Numeric value representing an error that should be returned
      */
    /////////////////////////////////////////////////////////////
    //Check if parameter is an array
    if (is_null($InArray) || !is_array($InArray)) {
        BadValidation('E1017');
    }
    $ErrorRaised = false;
    $Errors = array();
    //Loop through sub-arrays
    foreach ($InArray as $Entry) {
        //Check if sub-array is structured correctly
        if (count($Entry) != 7) {
            BadValidation('E1018');
        }
        if (!is_numeric($Entry[6])) {
            BadValidation('E1019');
        }
        //Check if requested variable exists
        switch ($Entry[0]) {
            case TypeGET:
                $Exists = isset($_GET[$Entry[1]]);
                break;
            case TypePOST:
                $Exists = isset($_POST[$Entry[1]]);
                break;
            default:
                BadValidation('E1020');
        }
        if ($Entry[2] == -1 && $Exists || $Entry[2] == 1 && !$Exists) {
            $ErrorRaised = true;
            $Errors[] = $Entry[6];
        } elseif ($Exists) {
            //Read requested variable
            switch ($Entry[0]) {
                case TypeGET:
                    $Value = $_GET[$Entry[1]];
                    break;
                case TypePOST:
                    $Value = $_POST[$Entry[1]];
                    break;
            }
            switch ($Entry[3]) {
                case NoValidation:
                    break;
                case ValidateRange:
                    if (!is_numeric($Value)) {
                        $ErrorRaised = true;
                        $Errors[] = $Entry[6];
                    } else {
                        if (is_null($Entry[4]) && is_null($Entry[5])) {
                            BadValidation('E1021');
                        }
                        if (!is_null($Entry[4]) && (double) $Value < (double) $Entry[4] || !is_null($Entry[5]) && (double) $Value > (double) $Entry[5]) {
                            $ErrorRaised = true;
                            $Errors[] = $Entry[6];
                        }
                    }
                    break;
                case ValidateQuery:
                    list($QR, $DR, $T) = QuerySingle(str_replace('%a', $Value, $Entry[4]));
                    if ($QR < 1) {
                        $ErrorRaised = true;
                        $Errors[] = $Entry[6];
                    }
                    break;
                case ValidateString:
                    if (trim($Value) == '') {
                        $ErrorRaised = true;
                        $Errors[] = $Entry[6];
                    }
                    break;
                case ValidateLength:
                    if (strlen(trim($Value)) < (int) $Entry[4]) {
                        $ErrorRaised = true;
                        $Errors[] = $Entry[6];
                    }
                    break;
                default:
                    BadValidation('E1021');
            }
        }
    }
    return array(!$ErrorRaised, $Errors);
}
Example #8
0
function ReadCookies()
{
    /*/////////////////////////////////////////////////////////////
           Author: Plottery
          Created: v1.0.0 - 2010-12-09
        Revisions: None
          Purpose: Reads browser cookies and retrieves session and user information
          Returns: True if valid data found, or false
      */
    /////////////////////////////////////////////////////////////
    global $UserID;
    global $UserName;
    global $UserSort;
    global $UserFlags;
    global $SessionID;
    global $SessionCoords;
    global $LanguageID;
    global $LanguageCode;
    $UserID = 0;
    $UserFlags = 0;
    $SessionID = 0;
    //Check for language information
    if (isset($_COOKIE['LID'])) {
        if (is_numeric($_COOKIE['LID'])) {
            list($QR, $DR, $T) = QuerySingle("SELECT LanguageID, LanguageCode FROM 0000_Languages WHERE LanguageID = " . (int) $_COOKIE['LID'] . " AND LanguageActive = 1;");
            if ($QR > 0) {
                $LanguageID = $DR['LanguageID'];
                $LanguageCode = $DR['LanguageCode'];
            }
        }
    }
    //Check for registered user session
    if (isset($_COOKIE['SKEY'])) {
        list($QR, $DR, $T) = QuerySingle("SELECT S.SessionID, S.SessionPort, S.SessionIP, S.Latitude, S.Longitude, S.Country, U.UserID, U.UserFlags, U.UserSort, COALESCE(U.UserName, U.UserUsername) AS Name, L.LanguageID, L.LanguageCode\n                                            FROM 0700_Sessions S\n                                            LEFT JOIN 1000_Users U ON S.UserID = U.UserID\n                                            LEFT JOIN 0000_Languages L ON U.LanguageID = L.LanguageID\n                                           WHERE SessionKey = '" . Pacify($_COOKIE['SKEY']) . "';");
        if ($QR < 0) {
            return SysLogIt('Error looking up session key. Requested key was: ' . $_COOKIE['SKEY'], StatusError, ActionSelect);
        }
        if ($QR > 0) {
            //Retrieve coordinates for non-registered users
            if (!(is_null($DR['Latitude']) || is_null($DR['Longitude']))) {
                $SessionCoords = array($DR['Latitude'], $DR['Longitude'], $DR['Country']);
            }
            //Set session ID and update
            $SessionID = $DR['SessionID'];
            if (!ExecCommand("UPDATE 0700_Sessions SET SessionAccessDate = " . date('YmdHis') . " WHERE SessionID = " . $SessionID . ";")) {
                SysLogIt('Error updating session with ID of ' . $SessionID . '.', StatusError, ActionUpdate);
            }
            if (is_null($DR['UserID'])) {
                //Retrieve coordinates for non-registered users
                return count($SessionCoords) > 0;
            } else {
                //Retrieve data for registered users
                if (($DR['UserFlags'] & UserActive) == UserActive) {
                    if ($DR['SessionPort'] == 1 || $DR['SessionIP'] == $_SERVER["REMOTE_ADDR"]) {
                        //Regular user
                        $UserID = $DR['UserID'];
                        $UserName = $DR['Name'];
                        $UserSort = $DR['UserSort'];
                        $UserFlags = $DR['UserFlags'];
                        if (!is_null($DR['LanguageID'])) {
                            $LanguageID = $DR['LanguageID'];
                            $LanguageCode = $DR['LanguageCode'];
                        }
                        if ($DR['SessionPort'] == 1) {
                            setcookie('SKEY', $_COOKIE['SKEY'], time() + 60 * 60 * 24 * 90);
                            //Extend cookie another 90 days if portable session
                        } else {
                            setcookie('SKEY', $_COOKIE['SKEY'], time() + 60 * 60);
                        }
                        return true;
                    } else {
                        //Mismatched IP on non-portable session.
                        FlushSession($DR['UserID']);
                        return false;
                    }
                } else {
                    //Disabled user
                    FlushSession($DR['UserID']);
                    return false;
                }
            }
        }
        return true;
    }
    /*
    //Check for home location information
    if (isset($_COOKIE['LNG']) && isset($_COOKIE['LAT'])) {
      if (is_numeric($_COOKIE['LNG']) && is_numeric($_COOKIE['LAT'])) {
        if ( (double)$_COOKIE['LNG'] >= -180 && (double)$_COOKIE['LNG'] <= 180 && (double)$_COOKIE['LAT'] >= -90 && (double)$_COOKIE['LAT'] <= 90 ) return true;
      }
    }
    */
    return false;
}
Example #9
0
$UserName = '';
$UserSort = 0;
$UserFlags = 0;
$SessionID = 0;
$SessionCoords = array();
$LanguageID = 0;
require_once './Code/Cookies.php';
require_once './Code/DB.php';
require_once './Code/Logging.php';
require_once './Code/Validator.php';
ReadCookies();
if (!empty($_GET)) {
    if (is_array($_GET)) {
        foreach ($_GET as $ID => $Value) {
            if (is_numeric($ID)) {
                OpenDB();
                list($QR, $DR, $T) = QuerySingle("SELECT D.DealURL, DS.DealSourceRefCode\n                                                FROM 4000_Deals D\n                                               INNER JOIN 4100_Deal_Sources DS ON DS.DealSourceID = D.DealSourceID\n                                               WHERE D.DealID = " . (int) $ID . ";");
                if ($QR > 0) {
                    if (!ExecCommand("INSERT INTO 4200_Deal_Clickthroughs (DealID, UserID, ClickDate) VALUES (" . (int) $ID . "," . $UserID . "," . date('YmdHis') . ");")) {
                        SysLogIt('Error inserting clickthrough data.', StatusError, ActionInsert);
                    }
                    header('Location: ' . $DR['DealURL'] . $DR['DealSourceRefCode']);
                    exit;
                }
                CloseDB();
                break;
            }
        }
    }
}
header('Location: /index.php');