2020-11-19 23:11:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once ('dbutils.php');
|
|
|
|
require_once ('commonutils.php');
|
|
|
|
require_once ('admin.php');
|
|
|
|
|
|
|
|
class Pickup {
|
|
|
|
public static function handleCommand($command) {
|
2020-11-19 23:12:00 +01:00
|
|
|
if (!in_array($command, array("getjobs","getmodus","declarepickready","declarepicknotready","deleteallcompletedjobs"))) {
|
2020-11-19 23:11:52 +01:00
|
|
|
echo json_encode(array("status" => "ERROR", "code" => ERROR_COMMAND_NOT_FOUND, "msg" => ERROR_COMMAND_NOT_FOUND_MSG));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(session_id() == '') {
|
|
|
|
session_start();
|
|
|
|
}
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
if($command == 'getmodus') {
|
|
|
|
$ret = self::getmodus($pdo);
|
|
|
|
} else if ($command == "getjobs") {
|
|
|
|
$ret = self::getjobs($pdo);
|
|
|
|
} else if ($command == "declarepickready") {
|
|
|
|
$ret = self::declarepickready($pdo,$_POST["id"]);
|
|
|
|
} else if ($command == "declarepicknotready") {
|
|
|
|
$ret = self::declarepicknotready($pdo,$_POST["id"]);
|
2020-11-19 23:12:00 +01:00
|
|
|
} else if ($command == "deleteallcompletedjobs") {
|
|
|
|
$ret = self::deleteallcompletedjobs($pdo);
|
2020-11-19 23:11:52 +01:00
|
|
|
}
|
|
|
|
echo json_encode($ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static function hasRightToRequestIncompleteJobs() {
|
|
|
|
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2020-11-19 23:11:57 +01:00
|
|
|
return $_SESSION['right_extendedpickup'];
|
2020-11-19 23:11:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private static function hasRightToRequestCompleteJobs() {
|
|
|
|
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return ($_SESSION['right_pickups']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getmodus($pdo) {
|
|
|
|
if (self::hasRightToRequestIncompleteJobs()) {
|
|
|
|
return array("status" => "OK","msg" => 2);
|
|
|
|
}
|
|
|
|
if (self::hasRightToRequestCompleteJobs()) {
|
|
|
|
return array("status" => "OK","msg" => 1);
|
|
|
|
}
|
|
|
|
return array("status" => "OK","msg" => 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getjobsoftype($pdo,$pickready) {
|
|
|
|
if ($pickready == false) {
|
|
|
|
$where = " pickready is null ";
|
|
|
|
$limit = "";
|
|
|
|
} else {
|
|
|
|
$where = " pickready = '1' ";
|
|
|
|
$showpickno = CommonUtils::getConfigValue($pdo, "showpickupsno", 20);
|
|
|
|
$limit = " LIMIT $showpickno";
|
|
|
|
}
|
|
|
|
$sql = "SELECT id,content FROM %printjobs% WHERE type=? AND $where ORDER BY id DESC $limit";
|
|
|
|
$result = CommonUtils::fetchSqlAll($pdo, $sql, array(7));
|
|
|
|
$outNumbers = array();
|
|
|
|
for ($i=count($result)-1;$i>=0;$i--) {
|
|
|
|
$entry = $result[$i];
|
|
|
|
$entryDecoded = json_decode($entry["content"],true);
|
|
|
|
$outNumbers[] = array("id" => $entry["id"], "workid" => $entryDecoded["workid"]);
|
|
|
|
}
|
|
|
|
return $outNumbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function getjobs($pdo) {
|
|
|
|
$incompletes = array();
|
|
|
|
$completes = array();
|
|
|
|
if (self::hasRightToRequestIncompleteJobs()) {
|
|
|
|
$incompletes = self::getjobsoftype($pdo, false);
|
|
|
|
$completes = self::getjobsoftype($pdo, true);
|
|
|
|
} else if (self::hasRightToRequestCompleteJobs()) {
|
|
|
|
$completes = self::getjobsoftype($pdo, true);
|
|
|
|
}
|
|
|
|
return array("status" => "OK","msg" => array("incompletes" => $incompletes,"completes" => $completes));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function declarepickready($pdo,$id) {
|
|
|
|
if (self::hasRightToRequestIncompleteJobs()) {
|
|
|
|
$sql = "UPDATE %printjobs% SET pickready=? WHERE id=?";
|
|
|
|
CommonUtils::execSql($pdo, $sql, array(1,$id));
|
|
|
|
}
|
|
|
|
return self::getjobs($pdo);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function declarepicknotready($pdo,$id) {
|
|
|
|
if (self::hasRightToRequestIncompleteJobs()) {
|
|
|
|
$sql = "UPDATE %printjobs% SET pickready = null WHERE id=?";
|
|
|
|
CommonUtils::execSql($pdo, $sql, array($id));
|
|
|
|
}
|
|
|
|
return self::getjobs($pdo);
|
|
|
|
}
|
2020-11-19 23:12:00 +01:00
|
|
|
|
|
|
|
private static function deleteallcompletedjobs($pdo) {
|
|
|
|
if (self::hasRightToRequestIncompleteJobs()) {
|
|
|
|
$sql = "DELETE FROM %printjobs% WHERE type=? AND pickready=?";
|
|
|
|
CommonUtils::execSql($pdo, $sql, array(7,1));
|
|
|
|
}
|
|
|
|
return self::getjobs($pdo);
|
|
|
|
}
|
2020-11-19 23:11:52 +01:00
|
|
|
}
|