Beispiel #1
0
 protected function onValidate()
 {
     if ($this->ac == "set") {
         if (issetval("status")) {
             $status = $_POST["status"];
             if ($status == "RE" || $status == "CA") {
                 $oldStatus = queryOne("SELECT status FROM Ordr WHERE id={$this->id}");
                 if ($oldStatus != "CR") {
                     throw new MyException(E_FORBIDDEN, "forbidden to change status to {$status}");
                 }
                 $this->onAfterActions[] = function () use($status) {
                     $orderId = $this->id;
                     $empId = $_SESSION["empId"];
                     $sql = sprintf("INSERT INTO OrderLog (orderId, action, tm, empId) VALUES ({$orderId},'{$status}','%s', {$empId})", date(FMT_DT));
                     execOne($sql);
                 };
             } else {
                 throw new MyException(E_FORBIDDEN, "forbidden to change status to {$_POST['status']}");
             }
         }
     }
 }
Beispiel #2
0
 function logAfter()
 {
     global $DBH;
     global $X_RET_STR;
     global $X_RET;
     if ($DBH == null) {
         return;
     }
     $iv = sprintf("%.0f", (microtime(true) - $this->startTm) * 1000);
     // ms
     if ($X_RET_STR == null) {
         $X_RET_STR = json_encode($X_RET, $GLOBALS["JSON_FLAG"]);
     }
     $content = $this->myVarExport($X_RET_STR);
     $userIdStr = "";
     if ($this->ac == 'login' && is_array($X_RET[1]) && @$X_RET[1]['id']) {
         $userIdStr = ", userId={$X_RET[1]['id']}";
     }
     $sql = sprintf("UPDATE ApiLog SET t={$iv}, retval=%d, ressz=%d, res=%s {$userIdStr} WHERE id={$this->id}", $X_RET[0], strlen($X_RET_STR), Q($content));
     $rv = execOne($sql);
     // 		$logStr = "=== id={$this->logId} t={$iv} >>>$content<<<\n";
 }
Beispiel #3
0
function addToPwdTable($pwd)
{
    if (substr($pwd, 0, strlen(AUTO_PWD_PREFIX)) == AUTO_PWD_PREFIX) {
        return;
    }
    $id = queryOne("SELECT id FROM Pwd WHERE pwd=" . Q($pwd));
    if ($id === false) {
        $sql = sprintf("INSERT INTO Pwd (pwd, cnt) VALUES (%s, 1)", Q($pwd));
        execOne($sql);
    } else {
        $sql = "UPDATE Pwd SET cnt=cnt+1 WHERE id={$id}";
        execOne($sql);
    }
}