Пример #1
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();
}
Пример #2
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;
}