123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?
- require_once "functions.php";
- function LoginChief($login, $p)
- {
- global $link;
- if (isset($login) && isset($p))
- {
- $query = mysqli_query($link, "select * from accounts where login='$login' and password='$p'");
- if ($res = mysqli_fetch_array($query)) {
- $cmdlevel = intval($res['cmdlevel']);
- $buf=pack("CCC",28, 1, $cmdlevel); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
- echo base64_encode($buf);
- }
- else
- {
- $buf=pack("CCC",28, 0, 0); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
- echo base64_encode($buf);
- }
- }
- }
- function LoginPassword($packetnum, $login, $p, $did, $ver, $app, $tagid)
- {
- //
- // формат пакета теперь такой:
- //string str = "pnum=30&login=" + login + "&p=" + md5hash+ "&did=" + deviceID + "&app=" + Application.identifier + "&ver=" + Application.version;
- // в общем, я от тебя в логинрезалте должен получить три переменные
- //"http://corp.prmsys.net/apk/", "smopp_v0.2.123.apk", "69c73d15fe46eb7f08939fc4f23ea2b2"
- global $link;
- if (isset($login) && isset($p))
- {
- $query = mysqli_query($link, "select * from accounts where login='$login' and password='$p'");
- if ($res = mysqli_fetch_array($query)) {
- $allowed = 1;//GetAppData($ver, $app);
- if ($allowed) {
- $cmdlevel = intval($res['cmdlevel']);
- $accountID = $res['id'];
- $name = $res['name'];
- $answer = 1;
- mysqli_query($link, "update accounts set quit_set = 0, overplan_mode=0 where id=$accountID");
- mysqli_query($link, "insert into sessions (account_id, start, device_id) values ($accountID, NOW(), '$did')");
- $buf = pack("CClv", $answer, $cmdlevel, $accountID, strlen($name)); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
- $buf .= $name;
- OCSlogin($accountID);
- /**
- * @var $acc Account
- */
- $acc = Account::Find($accountID);
- if ($acc)
- {
- $jobtypeName = $acc->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."<br>";
- }
- $counter = "Всего было проблем: $counter";
- $reporttext .= $counter."\n";
- $htmlText .= $counter."<br>";
- 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);
- }
- ?>
|