getJobtypes()[0]->name; $buf .= pack("v", strlen($jobtypeName)); $buf .= $jobtypeName; } if ($tagid) VagrantRequest($accountID, $tagid, $name, 1); } else { $answer = 0; $buf=pack("C", $answer); } } else { $answer = 0; $buf=pack("C", $answer); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint } $c = ConstructVariablePacket($packetnum, $buf); echo base64_encode($c); } } function GetAppData($ver, $app) { global $link; $version_allowed = 0; $query = mysqli_query($link, "select * from app_versions where app_version='$ver' and app_name='$app'"); if ($res = mysqli_fetch_array($query)) { $version_allowed = intval($res['version_allowed']); } if ($version_allowed == 0) { $query2 = mysqli_query($link, "select * from app_versions where version_allowed=1 ORDER BY id DESC limit 1"); if ($res2 = mysqli_fetch_array($query2)) { return $res2; } } return false; } function ProblemsQuit($type) { FindProblemsToReport(); // global $link; // mysqli_query($link,"update problems set time_end=NOW() where id=$id"); } function EndProblem($id) { global $link; mysqli_query($link,"update problems set time_end=NOW() where id=$id"); } function FindProblem($id) { global $link; $str = "select * from problems where id=$id"; $query = mysqli_query($link, $str); if ($res = mysqli_fetch_array($query)) { return $res; } } function FindProblemsToReport() { global $link; $str = "select * from problems where in_report IS NULL ORDER BY id ASC"; $query = mysqli_query($link, $str); $reporttext = ""; $htmlText = ""; $counter = 0; while ($res = mysqli_fetch_array($query)) { $counter++; $id = $res['id']; $typeid = $res['type']; $type = GetProblemName($typeid); $comment = $res['comment']; $resolved = $res['time_end']; $time_create = date('d.m.Y H:i', strtotime($res['time_create'])); $time_accept = date('d.m.Y H:i', strtotime($res['time_accept'])); if (strlen($resolved) == 0) $resolved = "нет"; else $resolved = date('d.m.Y H:i', strtotime($resolved)); $addtext = "$id: $type [$comment], "; $addtext .= "Создана: $time_create, "; $addtext .= "Принята: $time_accept, "; $addtext .= "Решена: $resolved"; $reporttext .= $addtext."\n"; $htmlText .= $addtext."
"; } $counter = "Всего было проблем: $counter"; $reporttext .= $counter."\n"; $htmlText .= $counter."
"; AddToReport($reporttext, $htmlText); mysqli_query($link, "update problems set in_report = 1 where in_report IS NULL and time_end IS NOT NULL"); } function GetProblemName($type) { $probDict = array(); $probDict['1'] = "Оборудование"; $probDict['2'] = "ТМЦ"; $probDict['3'] = "Приемщик РЖД"; $probDict['4'] = "Маневры"; $probDict['5'] = "Координация"; $probDict['6'] = "Нет персонала"; return $probDict[$type]; } function AddToReport($text, $htmlText) { $date = date("d-m-Y--H-i"); $reportfilename = "report-".$date.".txt"; $file = fopen("problem_reports/$reportfilename", "w"); fwrite($file, $text); fclose($file); $report = "problem_reports/$reportfilename"; $reportname = $reportfilename; include("phpmail.php"); SendMail($report, $reportname, $htmlText); } function ResolveProblemStart($id) { global $link; mysqli_query($link, "update problems set time_accept=NOW() where id=$id"); // $problem = FindProblem($id); // $typeid = $problem['type']; // $type = GetProblemName($typeid); // AddToReport(); } function AcceptProblem($type, $comment) { global $link; $str = "INSERT into problems (time_create, type, comment) values (NOW(), $type, '$comment')"; mysqli_query($link, $str); } function CheckProblem2() { // $buf = pack("C*", 24); //1 $buf =''; global $link; $str = "select * from problems where time_end IS NULL"; $query = mysqli_query($link, $str); if ($res = mysqli_fetch_array($query)) { $type = intval($res['type']); $comment = $res['comment']; $id = intval($res['id']); $buf .= pack("l*", $id); //4 $buf .= pack("v*", $type); //2 if ($comment != '') $buf .= $comment; mysqli_query($link,"update problems set sent=NOW() where id=".$id); } echo base64_encode(ConstructVariablePacket(24, $buf)); //echo base64_encode($buf); } function CheckProblem() { $problemsQueue = ""; global $link; $query = mysqli_query($link, "select * from problems where time_end IS NULL"); while ($res = mysqli_fetch_array($query)) { //$buf = pack("C*", 24); //1 $buf = ''; $comment = $res['comment']; $id = intval($res['id']); $buf .= pack("l*", $id); //4 $buf .= pack("v*", intval($res['type'])); //2 if ($comment != '') $buf .= $comment; mysqli_query($link,"update problems set sent=NOW() where id=".$id); $problemsQueue .= ConstructVariablePacket(24, $buf); } echo base64_encode($problemsQueue); } ?>