problems.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?
  2. require_once "functions.php";
  3. function LoginChief($login, $p)
  4. {
  5. global $link;
  6. if (isset($login) && isset($p))
  7. {
  8. $query = mysqli_query($link, "select * from accounts where login='$login' and password='$p'");
  9. if ($res = mysqli_fetch_array($query)) {
  10. $cmdlevel = intval($res['cmdlevel']);
  11. $buf=pack("CCC",28, 1, $cmdlevel); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
  12. echo base64_encode($buf);
  13. }
  14. else
  15. {
  16. $buf=pack("CCC",28, 0, 0); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
  17. echo base64_encode($buf);
  18. }
  19. }
  20. }
  21. function LoginPassword($packetnum, $login, $p, $did, $ver, $app, $tagid)
  22. {
  23. //
  24. // формат пакета теперь такой:
  25. //string str = "pnum=30&login=" + login + "&p=" + md5hash+ "&did=" + deviceID + "&app=" + Application.identifier + "&ver=" + Application.version;
  26. // в общем, я от тебя в логинрезалте должен получить три переменные
  27. //"http://corp.prmsys.net/apk/", "smopp_v0.2.123.apk", "69c73d15fe46eb7f08939fc4f23ea2b2"
  28. global $link;
  29. if (isset($login) && isset($p))
  30. {
  31. $query = mysqli_query($link, "select * from accounts where login='$login' and password='$p'");
  32. if ($res = mysqli_fetch_array($query)) {
  33. $allowed = 1;//GetAppData($ver, $app);
  34. if ($allowed) {
  35. $cmdlevel = intval($res['cmdlevel']);
  36. $accountID = $res['id'];
  37. $name = $res['name'];
  38. $answer = 1;
  39. mysqli_query($link, "update accounts set quit_set = 0, overplan_mode=0 where id=$accountID");
  40. mysqli_query($link, "insert into sessions (account_id, start, device_id) values ($accountID, NOW(), '$did')");
  41. $buf = pack("CClv", $answer, $cmdlevel, $accountID, strlen($name)); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
  42. $buf .= $name;
  43. OCSlogin($accountID);
  44. /**
  45. * @var $acc Account
  46. */
  47. $acc = Account::Find($accountID);
  48. if ($acc)
  49. {
  50. $jobtypeName = $acc->getJobtypes()[0]->name;
  51. $buf .= pack("v", strlen($jobtypeName));
  52. $buf .= $jobtypeName;
  53. }
  54. if ($tagid)
  55. VagrantRequest($accountID, $tagid, $name, 1);
  56. }
  57. else {
  58. $answer = 0;
  59. $buf=pack("C", $answer);
  60. }
  61. }
  62. else
  63. {
  64. $answer = 0;
  65. $buf=pack("C", $answer); //заголовок - v-ushort, c- byte, C- ubyte, s - short, L - int, l - uint
  66. }
  67. $c = ConstructVariablePacket($packetnum, $buf);
  68. echo base64_encode($c);
  69. }
  70. }
  71. function GetAppData($ver, $app)
  72. {
  73. global $link;
  74. $version_allowed = 0;
  75. $query = mysqli_query($link, "select * from app_versions where app_version='$ver' and app_name='$app'");
  76. if ($res = mysqli_fetch_array($query)) {
  77. $version_allowed = intval($res['version_allowed']);
  78. }
  79. if ($version_allowed == 0)
  80. {
  81. $query2 = mysqli_query($link, "select * from app_versions where version_allowed=1 ORDER BY id DESC limit 1");
  82. if ($res2 = mysqli_fetch_array($query2)) {
  83. return $res2;
  84. }
  85. }
  86. return false;
  87. }
  88. function ProblemsQuit($type)
  89. {
  90. FindProblemsToReport();
  91. // global $link;
  92. // mysqli_query($link,"update problems set time_end=NOW() where id=$id");
  93. }
  94. function EndProblem($id)
  95. {
  96. global $link;
  97. mysqli_query($link,"update problems set time_end=NOW() where id=$id");
  98. }
  99. function FindProblem($id)
  100. {
  101. global $link;
  102. $str = "select * from problems where id=$id";
  103. $query = mysqli_query($link, $str);
  104. if ($res = mysqli_fetch_array($query))
  105. {
  106. return $res;
  107. }
  108. }
  109. function FindProblemsToReport()
  110. {
  111. global $link;
  112. $str = "select * from problems where in_report IS NULL ORDER BY id ASC";
  113. $query = mysqli_query($link, $str);
  114. $reporttext = "";
  115. $htmlText = "";
  116. $counter = 0;
  117. while ($res = mysqli_fetch_array($query))
  118. {
  119. $counter++;
  120. $id = $res['id'];
  121. $typeid = $res['type'];
  122. $type = GetProblemName($typeid);
  123. $comment = $res['comment'];
  124. $resolved = $res['time_end'];
  125. $time_create = date('d.m.Y H:i', strtotime($res['time_create']));
  126. $time_accept = date('d.m.Y H:i', strtotime($res['time_accept']));
  127. if (strlen($resolved) == 0)
  128. $resolved = "нет";
  129. else
  130. $resolved = date('d.m.Y H:i', strtotime($resolved));
  131. $addtext = "$id: $type [$comment], ";
  132. $addtext .= "Создана: $time_create, ";
  133. $addtext .= "Принята: $time_accept, ";
  134. $addtext .= "Решена: $resolved";
  135. $reporttext .= $addtext."\n";
  136. $htmlText .= $addtext."<br>";
  137. }
  138. $counter = "Всего было проблем: $counter";
  139. $reporttext .= $counter."\n";
  140. $htmlText .= $counter."<br>";
  141. AddToReport($reporttext, $htmlText);
  142. mysqli_query($link, "update problems set in_report = 1 where in_report IS NULL and time_end IS NOT NULL");
  143. }
  144. function GetProblemName($type)
  145. {
  146. $probDict = array();
  147. $probDict['1'] = "Оборудование";
  148. $probDict['2'] = "ТМЦ";
  149. $probDict['3'] = "Приемщик РЖД";
  150. $probDict['4'] = "Маневры";
  151. $probDict['5'] = "Координация";
  152. $probDict['6'] = "Нет персонала";
  153. return $probDict[$type];
  154. }
  155. function AddToReport($text, $htmlText)
  156. {
  157. $date = date("d-m-Y--H-i");
  158. $reportfilename = "report-".$date.".txt";
  159. $file = fopen("problem_reports/$reportfilename", "w");
  160. fwrite($file, $text);
  161. fclose($file);
  162. $report = "problem_reports/$reportfilename";
  163. $reportname = $reportfilename;
  164. include("phpmail.php");
  165. SendMail($report, $reportname, $htmlText);
  166. }
  167. function ResolveProblemStart($id)
  168. {
  169. global $link;
  170. mysqli_query($link, "update problems set time_accept=NOW() where id=$id");
  171. // $problem = FindProblem($id);
  172. // $typeid = $problem['type'];
  173. // $type = GetProblemName($typeid);
  174. // AddToReport();
  175. }
  176. function AcceptProblem($type, $comment)
  177. {
  178. global $link;
  179. $str = "INSERT into problems (time_create, type, comment) values (NOW(), $type, '$comment')";
  180. mysqli_query($link, $str);
  181. }
  182. function CheckProblem2()
  183. {
  184. // $buf = pack("C*", 24); //1
  185. $buf ='';
  186. global $link;
  187. $str = "select * from problems where time_end IS NULL";
  188. $query = mysqli_query($link, $str);
  189. if ($res = mysqli_fetch_array($query))
  190. {
  191. $type = intval($res['type']);
  192. $comment = $res['comment'];
  193. $id = intval($res['id']);
  194. $buf .= pack("l*", $id); //4
  195. $buf .= pack("v*", $type); //2
  196. if ($comment != '')
  197. $buf .= $comment;
  198. mysqli_query($link,"update problems set sent=NOW() where id=".$id);
  199. }
  200. echo base64_encode(ConstructVariablePacket(24, $buf));
  201. //echo base64_encode($buf);
  202. }
  203. function CheckProblem()
  204. {
  205. $problemsQueue = "";
  206. global $link;
  207. $query = mysqli_query($link, "select * from problems where time_end IS NULL");
  208. while ($res = mysqli_fetch_array($query))
  209. {
  210. //$buf = pack("C*", 24); //1
  211. $buf = '';
  212. $comment = $res['comment'];
  213. $id = intval($res['id']);
  214. $buf .= pack("l*", $id); //4
  215. $buf .= pack("v*", intval($res['type'])); //2
  216. if ($comment != '')
  217. $buf .= $comment;
  218. mysqli_query($link,"update problems set sent=NOW() where id=".$id);
  219. $problemsQueue .= ConstructVariablePacket(24, $buf);
  220. }
  221. echo base64_encode($problemsQueue);
  222. }
  223. ?>