response.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. <?php
  2. header("Expires: 0");
  3. session_start();
  4. ini_set('error_reporting', 'E_ALL');
  5. ini_set('display_errors', '1');
  6. ini_set('display_startup_errors', '1');
  7. $response = $_SESSION['login'];
  8. if (!$response) {
  9. return;
  10. }
  11. include 'auth.php';
  12. //include 'functions.php';
  13. require_once 'functions.php';
  14. include 'CheckPoint.php';
  15. include 'CheckPointType.php';
  16. require_once "doctrine/bootstrap.php";
  17. require_once "src/Location.php";
  18. use CheckPoints\CheckPoint;
  19. use CheckPointTypes\CheckPointType;
  20. foreach (array_keys($_REQUEST) as $var) {
  21. ${$var} = $_REQUEST[$var];
  22. // echo "<b>$var:</b> ${$var} <br>";
  23. }
  24. if (isset($get_user_tasks))
  25. {
  26. $retarr = array();
  27. $str = "select id, input_id, accepted_time, finished_time from tasks where assignees_arr = $get_user_tasks";
  28. $query = mysqli_query($link, $str);
  29. while ($res = mysqli_fetch_assoc($query))
  30. {
  31. $retarr[] = [$res['id'], $res['input_id'], $res['accepted_time'], $res['finished_time']];
  32. }
  33. echo json_encode($retarr);
  34. }
  35. if (isset($quitaccount))
  36. {
  37. require_once "server.php";
  38. Quit($quitaccount, true);
  39. }
  40. if (isset($seturgent))
  41. {
  42. /**
  43. * @var $proj Project
  44. */
  45. $proj = Project::Find($seturgent);
  46. if ($proj != null)
  47. {
  48. $proj->urgent = abs($proj->urgent-1);
  49. $proj->Save();
  50. }
  51. }
  52. if (isset($newjob_accid))
  53. {
  54. $acc = Account::Find($newjob_accid);
  55. if ($acc != null) {
  56. $acc->UpdateJob($jobvalue, $index, $previous);
  57. }
  58. else
  59. echo "Account not found";
  60. }
  61. if (isset($basic_count))
  62. {
  63. $acc = Account::Find($accid);
  64. $acc->basic_jobs_count = $basic_count;
  65. $acc->Save();
  66. echo $basic_count;
  67. }
  68. if (isset($beacons_loc))
  69. {
  70. $query = mysqli_query($link,"select * from beacons where location_id=$beacons_loc");
  71. $arr = array();
  72. while ($query && $res = mysqli_fetch_array($query))
  73. {
  74. $x = $res['x'];
  75. $y = $res['y'];
  76. $uuid = $res['uuid'];
  77. $myarr = array("id"=>$uuid, 'x'=>$x,'y'=>$y);
  78. array_push($arr, $myarr);
  79. // echo "<div>[$uuid] X: $x Y: $y</div>";
  80. }
  81. echo json_encode($arr);
  82. //echo "No beacons";
  83. }
  84. if (isset($users_loc))
  85. {
  86. if ($users_loc == '22') {
  87. $query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
  88. if ($query && $res = mysqli_fetch_row($query))
  89. {
  90. $x = $res[1];
  91. $y = $res[2];
  92. $zone = $res[6];
  93. }
  94. $query = mysqli_query($link,"select * from zones where id=$zone");
  95. if ($query && $res = mysqli_fetch_row($query))
  96. {
  97. $zone = $res[2];
  98. }
  99. $arr = array("id"=>9, "name"=>'Петр Петров','x'=>$x,'y'=>$y,'Zone'=>$zone);
  100. echo json_encode($arr);
  101. // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
  102. }
  103. else
  104. echo "No users";
  105. }
  106. /*
  107. if (isset($users_markers))
  108. {
  109. $contTime = date('Y-m-d H:i:s');
  110. $beginTime = strtotime($contTime) - 3600;
  111. $beginTime = date('Y-m-d H:i:s', $beginTime);
  112. if ($users_markers != null && $depo_markers != null ) {//&& $time_markers != null
  113. if ($date_start != null && $date_stop != null){
  114. $beginTime = $date_start;
  115. $contTime = $date_stop;
  116. } else {
  117. echo json_encode('');
  118. }
  119. //if ($date_stop != null ){
  120. // $contTime = $date_stop;
  121. //}
  122. $queryString = "select * from user_positions WHERE `acc_id` = " . $users_markers . " AND `location_id` = " . $depo_markers . " AND `ts` BETWEEN '" . $beginTime . "' AND '" . $contTime . "' ORDER BY id DESC ";
  123. //$query = mysqli_query($link,"select * from user_positions WHERE `acc_id` = " . $users_markers . " AND `location_id` = " . $depo_markers . " ORDER BY id DESC ");
  124. $query = mysqli_query($link,$queryString);
  125. //2019-07-08 15:22:28
  126. //$query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
  127. $result = [];
  128. $num_rows = mysqli_num_rows($query);
  129. $module = round(1/$num_rows, 4 , PHP_ROUND_HALF_DOWN);
  130. $i = 0;
  131. while ($query && $res = mysqli_fetch_assoc($query))
  132. {
  133. $red = ( 255 * (1 - $moduleTemp)) + ( 0 * $moduleTemp );
  134. $blue = ( 0 * (1 - $moduleTemp)) + ( 255 * $moduleTemp );
  135. //$count = round($red) . ', 0 ,' . round($blue);
  136. $moduleTemp += $module;
  137. $res['c'] = $module;//$count;
  138. $res['num'] = $num_rows;
  139. $res['rgb'] = fromRGB(round($red), 0, round($blue));//$count;
  140. $res['radius'] = 4;
  141. $res['tip'] = 'You are over 100,100';
  142. $result[$i] = $res;
  143. $i++;
  144. }
  145. //$result['datetime'] = $queryString;
  146. echo json_encode($result);
  147. //echo json_encode($arr);
  148. // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
  149. }
  150. //else
  151. // echo "No users";
  152. }
  153. */
  154. if (isset($users_markers))
  155. {
  156. $contTime = date('Y-m-d H:i:s');
  157. $beginTime = strtotime($contTime) - 3600;
  158. $beginTime = date('Y-m-d H:i:s', $beginTime);
  159. if ($users_markers != null && $depo_markers != null ) {//&& $time_markers != null
  160. if ($date_start != null && $date_stop != null){
  161. $beginTime = $date_start;
  162. $contTime = $date_stop;
  163. } else {
  164. echo json_encode('');
  165. }
  166. //if ($date_stop != null ){
  167. // $contTime = $date_stop;
  168. //}
  169. $smooth = 5;
  170. /*
  171. $queryString = "select * from user_positions WHERE `acc_id` = " . $users_markers . " AND `location_id` = " . $depo_markers . " AND `ts` BETWEEN '" . $beginTime . "' AND '" . $contTime . "' ORDER BY id DESC ";*/
  172. $queryString = "select up.coord_x ,up.coord_y, ts from user_positions as up LEFT JOIN locations as l ON l.id = up.location_id WHERE up.acc_id = " . $users_markers . " AND l.company_id = " . $depo_markers . " AND up.ts BETWEEN '" . $beginTime . "' AND '" . $contTime . "' ORDER BY up.id ASC";
  173. $query = mysqli_query($link,$queryString);
  174. //2019-07-08 15:22:28
  175. //$query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
  176. $result = [];
  177. $resultTest = [];
  178. $num_rows = mysqli_num_rows($query);
  179. $module = round(1/$num_rows, 4 , PHP_ROUND_HALF_DOWN);
  180. $i = 0;
  181. while ($query && $res = mysqli_fetch_assoc($query))
  182. {
  183. $red = ( 255 * (1 - $moduleTemp)) + ( 0 * $moduleTemp );
  184. $blue = ( 0 * (1 - $moduleTemp)) + ( 255 * $moduleTemp );
  185. //$count = round($red) . ', 0 ,' . round($blue);
  186. $moduleTemp += $module;
  187. $res['c'] = $module;//$count;
  188. $res['num'] = $num_rows;
  189. $res['rgb'] = fromRGB(round($red), 0, round($blue));//$count;
  190. $res['radius'] = 4;
  191. $resultTest[] = [ 'time' => $res['ts'], 'coord_x' => ($res['coord_x']*8), 'coord_y' => ($res['coord_y']*8)];
  192. $res['tip'] = 'You are over 100,100';
  193. $result[$i] = $res;
  194. $i++;
  195. }
  196. //$result['datetime'] = $queryString;
  197. $curResult = [];
  198. $i = 0;
  199. foreach( $resultTest as $key =>$coord ){
  200. //if( $key < $smooth) {
  201. $curResult[] = $coord;
  202. $result[$i]['coord_x'] = $coord['coord_x'];
  203. $result[$i]['coord_y'] = $coord['coord_y'];
  204. $i++;
  205. continue;
  206. //}
  207. $begin = $key - $smooth;
  208. //echo "<pre>";
  209. $sumX = 0;
  210. $sumY = 0;
  211. for($r = 0;$r < $smooth; $r++){
  212. $sumX += $resultTest[$i + $r]["coord_x"];
  213. $sumY += $resultTest[$i + $r]["coord_y"];
  214. }
  215. $sumX = $sumX/$smooth;
  216. $sumY = $sumY/$smooth;
  217. $result[$i]['coord_x'] = $sumX;//$sumX*8;
  218. $result[$i]['coord_y'] = $sumY;//$sumY*8;
  219. $result[$i]['time'] = $coord['time'];//$sumY*8;
  220. //var_dump((int)round($sumX, 0),(int)round($sumY, 0));
  221. //echo "</pre>";
  222. $i++;
  223. }
  224. //$result['f'] = $result
  225. //$result = $queryString;
  226. echo json_encode($result);
  227. //echo json_encode($arr);
  228. // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
  229. }
  230. //else
  231. // echo "No users";
  232. }
  233. if (isset($beacon_item)){
  234. $taskType = mysqli_query($link, "insert into `beacons` (`x`, `y` ,`location_id` , `uuid`) values ($x, $y,$location_id,'$uuid')");
  235. if ('' == mysqli_error($link)){
  236. echo json_encode("good");
  237. } else {
  238. echo json_encode(mysqli_error($link));
  239. }
  240. }
  241. if (isset($dwnl_beacons)){
  242. //$repair = 'asdasdasd';
  243. /*
  244. $filePath = $_SERVER['DOCUMENT_ROOT'].'/uploads/coord.xlsx';
  245. $Excel = \PHPExcel_IOFactory::load($filePath);
  246. $maxCell = $Excel->setActiveSheetIndex(0);
  247. $repair = $Excel->getActiveSheet()->getCell('A3')->getValue();
  248. $result = [];
  249. for( $i = 3 ; $i < 36; $i++){
  250. //$tempArray = [];
  251. $minor = $Excel->getActiveSheet()->getCell('A'.$i)->getValue();
  252. $x = $Excel->getActiveSheet()->getCell('B'.$i)->getValue();
  253. $y = $Excel->getActiveSheet()->getCell('C'.$i)->getValue();
  254. $query = "insert into `beacons` (`x`, `y` ,`location_id` , `uuid`,`major`,`minor`,`enabled`) values ($x, $y,1,'e2c56db5-dffb-48d2-b060-d0f5a71096e0',5 , $minor,1)";
  255. $taskType = mysqli_query($link, $query);
  256. }
  257. */
  258. //echo "<pre>";
  259. // var_dump('repair');
  260. // var_dump($query);
  261. //echo "</pre>";
  262. echo json_encode($_FILES['file']);
  263. }
  264. if (isset($get_img)){
  265. $result = [];
  266. if ( $depo_markers ) {
  267. $queryString = "select * from locations WHERE `company_id` = " . $depo_markers . "";
  268. $query = mysqli_query($link,$queryString);
  269. if ($query && $res = mysqli_fetch_assoc($query))
  270. {
  271. $result['image'] = $res['img'];
  272. } else {
  273. $result['image'] = '';
  274. }
  275. }
  276. $queryString = "select `x`,`y` from beacons WHERE `location_id` = " . $depo_markers . "";
  277. $query = mysqli_query($link,$queryString);
  278. $result['point_beacons'] = [];
  279. while ($res = mysqli_fetch_assoc($query))
  280. {
  281. $result['point_beacons'][] = ['x' => $res['x'],'y'=>$res['y']];
  282. }
  283. $queryString = "select * from zones WHERE `location_id` = " . $depo_markers . "";
  284. $query = mysqli_query($link,$queryString);
  285. $result['point_zones'] = [];
  286. while ($res = mysqli_fetch_assoc($query))
  287. {
  288. $result['point_zones'][] = $res;
  289. }
  290. $query = mysqli_query($link, "select uuid from beacons");
  291. while ($res = mysqli_fetch_row($query)) {
  292. $result['uuids'][] = $res['uuid'];
  293. }
  294. echo json_encode($result);
  295. }
  296. if (isset($depo_zone)){
  297. $result = [];
  298. $depo_zone = json_encode($depo_zone);
  299. mysqli_query($link, "insert into `zones` (`description`, `borders` ,`location_id`) values ('$depo_name', '$depo_zone' , $depo_num )");
  300. if ('' == mysqli_error($link)){
  301. echo json_encode(["good"]);
  302. } else {
  303. echo json_encode(mysqli_error($link));
  304. }
  305. echo json_encode($result);
  306. }
  307. /// получение списка точек для сотрудников находящихся в онлайне
  308. if (isset($depo_markers_ol)) {
  309. $dd = TempFuncInsert();
  310. $company = Company::Find($depo_markers_ol);
  311. $accounts = $company->accounts;
  312. $result = [];
  313. $userList = [];
  314. foreach( $accounts as $account ) {
  315. $last_seen_mobile = $account->getLastSeenMobile();
  316. $online_mobile = OnlineAccountCheck(TimeString($last_seen_mobile));
  317. //$userList[] = [$account->id,$online_mobile];
  318. if ($online_mobile) {
  319. $userList[] = $account->id;
  320. }
  321. }
  322. $queryString = "select * from locations WHERE `company_id` = " . $depo_markers_ol;
  323. $query = mysqli_query($link,$queryString);
  324. $comp = mysqli_fetch_assoc($query);
  325. $query1 = "SELECT max(ts) AS date, acc_id, max(id) AS id FROM user_positions WHERE acc_id IN (".implode(',', $userList).") AND `location_id` = " .$comp['id']. " GROUP BY acc_id";
  326. $query = mysqli_query($link,$query1);
  327. $idList = [];
  328. while ($res = mysqli_fetch_assoc($query)) {
  329. $idList[] = $res['id'];
  330. }
  331. $queryString = "select `ts`, `acc_id`,`coord_x`,`coord_y` from user_positions WHERE `id` IN (".implode(',', $idList).")";
  332. $query = mysqli_query($link,$queryString);
  333. $i = 0;
  334. while ($query && $res = mysqli_fetch_assoc($query))
  335. {
  336. $result[$i] = $res;
  337. //$result = $res;
  338. $i++;
  339. }
  340. //$result['req'] = $query1;//$result;
  341. echo json_encode($result);
  342. }
  343. function TempFuncInsert(){
  344. global $link;
  345. $x = 100;
  346. $y = 200;
  347. $rand = rand(1,10);
  348. switch ($rand) {
  349. case 1:
  350. $x -= 10;
  351. $y += 10;
  352. break;
  353. case 2:
  354. $x += 10;
  355. $y -= 10;
  356. break;
  357. case 3:
  358. $x -= 10;
  359. $y -= 10;
  360. break;
  361. case 4:
  362. $x += 20;
  363. $y += 20;
  364. break;
  365. case 5:
  366. $x -= 20;
  367. $y += 20;
  368. break;
  369. case 6:
  370. $x += 30;
  371. $y -= 20;
  372. break;
  373. case 7:
  374. $x += 20;
  375. $y -= 40;
  376. break;
  377. case 8:
  378. $x -= 30;
  379. $y -= 30;
  380. break;
  381. case 9:
  382. $x += 40;
  383. $y -= 20;
  384. break;
  385. default:
  386. break;
  387. }
  388. $query = "insert into user_positions (coord_x, coord_y,ts, acc_id, location_id, zone_id) values (".$x.", ".$y.", '".date('Y-m-d H:i:s')."', 315 , 1, 1)";
  389. $query1 = "insert into user_positions (coord_x, coord_y,ts, acc_id, location_id, zone_id) values (".($y+$rand).", ".($x-$rand).", '".date('Y-m-d H:i:s')."', 316 , 1, 1)";
  390. mysqli_query($link, $query1);
  391. mysqli_query($link, $query);
  392. return $query;
  393. }
  394. if(isset($idLastMsg)){
  395. $company = $_SESSION['company'];
  396. $result = [];
  397. if ( true === $idLastMsg ) {
  398. $idMsg = 0;
  399. } else {
  400. $idMsg = explode('_',$idLastMsg)[0];
  401. }
  402. $query = "select ch.id,ch.msg,ch.acc_id,ch.date_massage,ch.company_id,ch.file,ch.file_name,ch.file_ext,acc.login from chat as ch left join accounts_internal as acc ON ch.acc_id = acc.id where ch.id > " . $idMsg ." and ch.company_id = " . $company . "";
  403. $res_query = mysqli_query($link, $query);
  404. $insertMass = '';
  405. $plugFileImg = '';
  406. while ($res = mysqli_fetch_assoc($res_query)) {
  407. $plugFileImg = $res['file'];
  408. if ( null != $res['file'] ){
  409. $plugFileImg = '<a href="'."/uploads/chat/" . $res['file'] . '" target="_blank" style="color: #fff;">
  410. ' . $res['file_name'] . '<br>
  411. <i class="fa fa-2x fa-file direct-chat-img" style="color: #fff;float: left;"></i>
  412. </a><br><br>';
  413. }
  414. if ($res['acc_id'] == $_SESSION['id']) {
  415. $insertMass .='<div id="'.$res['id'].'_msgId" class="direct-chat-msg right"><div class="direct-chat-info clearfix"><span class="direct-chat-name pull-right">'.$res['login'].'</span><span class="direct-chat-timestamp pull-left">'.$res['date_massage'].'</span></div><i class="fa fa-3x fa-user direct-chat-img"></i><div class="direct-chat-text">'. $plugFileImg. $res['msg'].'</div></div>';
  416. } else {
  417. $insertMass .= '<div id="'.$res['id'].'_msgId" class="direct-chat-msg"><div class="direct-chat-info clearfix"><span class="direct-chat-name pull-left">'.$res['login'].'</span><span class="direct-chat-timestamp pull-right">'.$res['date_massage'].'</span></div><i class="fa fa-3x fa-user direct-chat-img"></i><div class="direct-chat-text">'.$plugFileImg . $res['msg'].'</div></div>';
  418. }
  419. //$result[] = $res;
  420. }
  421. echo json_encode($insertMass);
  422. }
  423. if(isset($addNewMsg))
  424. {
  425. $logPath = $_SERVER['DOCUMENT_ROOT'] . '/uploads/chat/' . 'log.txt';
  426. $result = $addNewMsg;//'';
  427. if ('' != $addNewMsg || !empty($_FILES['file_v']['tmp_name'])) {
  428. $info = new SplFileInfo($_FILES['file_v']['name']);
  429. $fileRandomName = strtotime(date("Y-m-d H:i:s")) . "." . $info->getExtension();
  430. $path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/chat/' . $fileRandomName;
  431. $fileName = '';
  432. if (copy($_FILES['file_v']['tmp_name'], $path)) {
  433. $fileName = $_FILES['file_v']['name'];
  434. }
  435. $company = $_SESSION['company'];
  436. $acc_id = $_SESSION['id'];
  437. $pattern = "/((http|https):\/\/(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|”|\"|'|:|\<|$|\.\s)/i";
  438. $replacement = "<a href='$0' target='_blank' style='color:#0011FF;text-decoration: underline !important;'>$0</a>";
  439. $addNewMsg = preg_replace($pattern, $replacement, $addNewMsg);
  440. if ('' != $fileName) {
  441. $query = "insert into `chat` (`company_id`, `msg` ,`acc_id`,`file`,`file_name`,`file_ext`) values ($company,\"".$addNewMsg."\",$acc_id, '$fileRandomName', '$fileName','".$info->getExtension()."')";
  442. //Добавление файла в файлотеку
  443. //Получаем логин и имя пользователя
  444. $q = 'select login, name from accounts_internal where id = ' . $acc_id;
  445. $result = mysqli_query($link, $q);
  446. $account = mysqli_fetch_array($result);
  447. if ($account) {
  448. $login = $account['login'];
  449. $userName = $account['name'];
  450. //Ищем папку с именем пользователя
  451. $q = 'select id from subj where pId = 1 and name = "' . $login . '" and isFolder = 1';
  452. $result = mysqli_query($link, $q);
  453. $row = mysqli_fetch_array($result);
  454. $subjId = $row['id'] ?? null;
  455. //Если такой нет, то создаём
  456. if (!$subjId) {
  457. $now = (new DateTime())->format('Y-m-d H:i:s');
  458. $q = 'insert into subj (pId, isFolder, name, note, date, acc_download) VALUES ' .
  459. ' (1, 1, "' . $login . '", "' . $userName . '", "' . $now . '", ' . $acc_id . ')';
  460. if ($result = mysqli_query($link, $q)) {
  461. $subjId = mysqli_insert_id($link);
  462. } else {
  463. file_put_contents($logPath, mysqli_error($link), FILE_APPEND);
  464. }
  465. }
  466. //Добавляем в неё файл
  467. $q = 'insert into subj (pId, isFolder, path, fname, name, size, date, acc_download) VALUES ' .
  468. ' (' . $subjId . ', 0, "/uploadfiles/", "' . $fileRandomName . '", "' . $fileName . '", ' . filesize($path) . ', "' . $now . '", ' . $acc_id . ')';
  469. $result = mysqli_query($link, $q);
  470. //Копируем файл в файлотеку
  471. if (copy($_FILES['file_v']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/filelib/uploadfiles/' . $fileRandomName)) {
  472. file_put_contents($logPath, 'Файл сохранён под именем: ' . $fileRandomName, FILE_APPEND);
  473. }
  474. if (!$result) {
  475. file_put_contents($logPath, 'second: ' . mysqli_error($link), FILE_APPEND);
  476. file_put_contents($logPath, $q, FILE_APPEND);
  477. }
  478. }
  479. } else {
  480. $query = "insert into `chat` (`company_id`, `msg` ,`acc_id`) values ($company,\"".$addNewMsg."\",$acc_id)";
  481. }
  482. $result = mysqli_query($link, $query);
  483. }
  484. echo json_encode($result);
  485. }
  486. if (isset($del_loc))
  487. {
  488. Location::Delete($del_loc);
  489. }
  490. if (isset($load_locs))
  491. {
  492. Location::EchoLocations();
  493. }
  494. if (isset($add_loc))
  495. {
  496. Location::Add($add_loc, $desc);
  497. }
  498. if (isset($delete_cpt))
  499. {
  500. CheckPointType::Delete($delete_cpt);
  501. }
  502. if (isset($add_to_task))
  503. {
  504. global $link;
  505. $taskType = mysqli_query($link, "insert into checkpoint_types_for_tasks (tasktype_id, cp_type_id) values ($taskType, $add_to_task)");
  506. //add_to_task - id of cpt to add
  507. }
  508. if (isset($addcpt))
  509. {
  510. CheckPointType::CreateFromScratch($addcpt, $name);
  511. }
  512. if (isset($toggletwx))
  513. {
  514. $cp = CheckPointType::CreateFromID($toggletwx);
  515. $newtwx = abs($cp->getWriteToTWX()-1);
  516. $cp->setWriteToTWX($newtwx);
  517. $writeTWX = "нет";
  518. if ($cp->getWriteToTWX())
  519. $writeTWX = "да";
  520. echo "Запись в АСУ СГ: <input id='toggleTWX' type='button' value='$writeTWX'>";
  521. }
  522. if (isset($showcheckbox))
  523. {
  524. $cp = CheckPointType::CreateFromID($showcheckbox);
  525. $writeTWX = "нет";
  526. if ($cp->getWriteToTWX())
  527. $writeTWX = "да";
  528. echo "Запись в АСУ СГ: <input id='toggleTWX' type='button' value='$writeTWX'>";
  529. }
  530. if (isset($show))
  531. {
  532. EchoTypesOfClass($show);
  533. }
  534. if (isset($show_cb_list))
  535. {
  536. EchoCheckBoxTemplate();
  537. }
  538. if (isset($add_cb))
  539. {
  540. $parent = CheckPointType::CreateFromID($parent_id);
  541. if ($parent->class != "MultiSelect" && $parent->class != "DropList" ) {
  542. echo "Не для этого типа чекпойнтов! $parent_id $parent->class";
  543. return;
  544. }
  545. CheckPointType::AddChildToDB($add_cb, $parent_id);
  546. }
  547. if (isset($remove_cb, $parent_id))
  548. {
  549. CheckPointType::CreateFromID($parent_id)->RemoveChildFromDB($remove_cb);
  550. }
  551. if (isset($id))
  552. {
  553. $cpt = CheckPointType::CreateFromID($id);
  554. EchoContents($cpt);
  555. }
  556. if (isset($jobtype) && isset($acc))
  557. {
  558. global $link;
  559. $userId = $_SESSION['id'];
  560. $task = mysqli_query($link, "CALL change_jobtype_priority($acc, $jobtype, $userId)");
  561. }
  562. if (isset($asusg_id) && isset($project_type) )
  563. {
  564. global $link;
  565. $resultArray = [];
  566. //$userId = $_SESSION['id'];
  567. $task = mysqli_query($link, "CALL asusg_bind_projecttype($asusg_id, $project_type)");
  568. }
  569. if (isset($asusg_id) && isset($user_id) )
  570. {
  571. global $link;
  572. //var_dump($user_id, $asusg_id);
  573. $task = mysqli_query($link, "CALL asusg_start_projects($user_id, $asusg_id)");
  574. }
  575. if (isset($asutask_id) && isset($projecttype_id) )
  576. {
  577. global $link;
  578. //var_dump($user_id, $asusg_id);
  579. $task = mysqli_query($link, "CALL asusg_bind_jt2task($asutask_id, $projecttype_id)");
  580. echo json_encode([$asutask_id, $projecttype_id, $task ]);
  581. }
  582. if (isset($employee_uuid) && isset($employee_id) )
  583. {
  584. global $link;
  585. $task = mysqli_query($link, "CALL asusg_bind_employee('$employee_uuid', $employee_id)");
  586. echo json_encode(["CALL asusg_bind_employee(".$employee_uuid.", ".$employee_id.")" ]);
  587. }
  588. if (isset($listItems))
  589. {
  590. global $link;
  591. $listItems = explode(',',$listItems);
  592. $result = false;
  593. if ( 0 < count($listItems)) {
  594. $params = [];
  595. $i = 0;
  596. $asusg_job_id = 0;
  597. $paramsString = "INSERT INTO asusg_job2command (`asusg_job_id`,`smopp_cmd_id`,`jobtype_id`,`asusg_projecttype_id`,`cmd_order`) values";
  598. foreach($listItems as $item){
  599. $tempArray = explode('_',$item);
  600. $params[] = ['asusg_job_id' =>$tempArray[0],'smopp_cmd_id' =>$tempArray[1],'cmd_order' => $i];
  601. $paramsString .= "($tempArray[0],$tempArray[1],$tempArray[3],$tempArray[4],$i),";
  602. $asusg_job_id = $tempArray[0];
  603. $i++;
  604. }
  605. $paramsString = substr($paramsString,0,-1);
  606. $resDelete = mysqli_query($link,"delete from asusg_job2command where asusg_job_id = $asusg_job_id and smopp_cmd_id >= 0 and cmd_order >= 0");
  607. $resInsert = mysqli_query($link,$paramsString);
  608. //if ($res) {
  609. $result = $res;
  610. //}
  611. }
  612. echo json_encode('Удаление =>'.$resDelete . " вставка =>" . json_encode($paramsString) );//mysqli_error($link));
  613. }
  614. if (isset($loco_series) and isset($typefix)) {
  615. global $link;
  616. $paramsString = "INSERT INTO asusg_projecttype (`repair_type`,`loco_serie_id`) values ( $typefix, $loco_series )";
  617. $res = mysqli_query($link,$paramsString);
  618. echo json_encode($res);
  619. }
  620. if (isset($loco_seria) and isset($typefix)) {
  621. global $link;
  622. $paramsString = "SELECT * FROM asusg_projecttype WHERE `repair_type` = $typefix and `loco_serie_id` = $loco_seria";
  623. $res = mysqli_query($link,$paramsString);
  624. echo json_encode($res);
  625. }
  626. if (isset($removeProjectTypeAsusg)) {
  627. global $link;
  628. $queryParams = explode('@',$removeProjectTypeAsusg);
  629. $paramsString = "DELETE FROM asusg_projecttype WHERE `loco_serie_id` = " . $queryParams[0] . " and `repair_type`=" . $queryParams[1];
  630. $res = mysqli_query($link,$paramsString);
  631. echo json_encode($res);
  632. }
  633. if (isset($listItemsAsusg)) {
  634. global $link;
  635. $listItems = explode(',',$listItemsAsusg);
  636. $result = false;
  637. if ( 0 < count($listItems)) {
  638. $params = [];
  639. $i = 0;
  640. $asusg_job_id = 0;
  641. $paramsString = "INSERT INTO asusg_job2project (`asusg_projecttype_id`,`asusg_jobplan_id`,`job_order`) values";
  642. foreach($listItems as $item){
  643. $tempArray = explode('_',$item);
  644. $asusg_job_id = $tempArray[0];
  645. $params[] = ['asusg_projecttype_id'=> $job_id,'asusg_jobplan_id' =>$item,'job_order' => $i];
  646. $paramsString .= "($job_id,$asusg_job_id,$i),";
  647. $i++;
  648. }
  649. $paramsString = substr($paramsString,0,-1);
  650. $resDelete = mysqli_query($link,"delete from asusg_job2project where asusg_projecttype_id = $job_id and asusg_jobplan_id >= 0 and job_order >= 0");
  651. $resInsert = mysqli_query($link,$paramsString);
  652. //if ($res) {
  653. $result = $res;
  654. //}
  655. }
  656. echo json_encode('Удаление =>'.$resDelete . " вставка =>" . $paramsString );//mysqli_error($link));
  657. }
  658. if (isset($taskName)) {
  659. global $link;
  660. $paramsString = "INSERT INTO asusg_jobplan (`name`) values ( '$taskName' )";
  661. $res = mysqli_query($link,$paramsString);
  662. echo json_encode("вставка =>" + $res );
  663. }
  664. if (isset($moveToPlan))
  665. {
  666. global $link;
  667. $id_user = $_SESSION['id'];
  668. $query = "CALL asusg_build_project( $id_user, 194, 734, '$loco', $loco_number, $id_asusg_job)";
  669. $res = mysqli_query($link,$query);
  670. echo json_encode($res);//mysqli_error($link));
  671. }
  672. function EchoTypesOfClass($show)
  673. {
  674. $classes = CheckPoint::GetClasses();
  675. $search = array_search($show, $classes, true);
  676. if ($search) {
  677. $list = CheckPointType::GetCheckPointTypes($show);
  678. EchoSelect($list, $show."s", $show."_list");
  679. }
  680. }
  681. function EchoContents($cpt)
  682. {
  683. echo "Варианты для \"[$cpt->id] $cpt->name\":<br>";
  684. foreach ($cpt->childrenCheckpointTypes as $child) {
  685. echo '<div class="content__main__imgwrap">';
  686. echo "<img src='ProSysNew/delete.svg' alt='удалить' class='content__main__imgdel' onclick='delCheckbox($child->id, $cpt->id)' title='Удалить'>";
  687. //echo "<img src='images/change.svg' alt='заменить' class='content__main__imgchange' onclick='changeCheckbox($child->id)' title='Заменить'>";
  688. echo "[$child->id]<b> $child->name</b><br>";
  689. echo "</div>";
  690. }
  691. echo "<div id='add_new_checkbox' style='display: inline-block; position: absolute; margin-top: 9px; font-size: 25px;' class='round deepskyblue'>+</div><br><br>";
  692. }
  693. function EchoCheckBoxTemplate()
  694. {
  695. $typesCheckBox = CheckPointType::GetCheckPointTypes("CheckBox");
  696. echo "<div id='cb_template'><p>Выберите чекпойнт для добавления:</p>";
  697. EchoCheckPointType($typesCheckBox, 'cb_template');
  698. echo "</div>";
  699. }
  700. function EchoCheckPointType($list, $id)
  701. {
  702. echo "<select id='select_$id' data-contentsFlag='noHideContents' style='width: 400px' class='form-input content__main__form__series' name='cptype'>";
  703. $str = '<option value="0"><Выберите тип чекпойнта из списка></option>';
  704. foreach ($list as $type)
  705. {
  706. $str .= "<option value='$type->id'>[$type->id] $type->name</option>";
  707. }
  708. echo "$str</select>";
  709. }
  710. function EchoSelect($list, $name, $id)
  711. {
  712. echo "<div id='checkpoint_list' style='display: table'>";
  713. echo "<div style='float: left'><br>";
  714. EchoCheckPointType($list, $id);
  715. echo "</div>";
  716. echo "<div id='remove_checktype' title='Удалить тип' style='display: none; margin-top: 29px; font-size: 25px;' class='round red'>-</div>";
  717. echo "<div id='add_to_task' title='Добавить в текущий тип команд' style='display: none; margin-top: 29px; font-size: 25px;' class='round green'>+</div><br><br>";
  718. echo "</div><br>";
  719. }
  720. function fromRGB($R, $G, $B)
  721. {
  722. $R = dechex($R);
  723. if (strlen($R)<2)
  724. $R = '0'.$R;
  725. $G = dechex($G);
  726. if (strlen($G)<2)
  727. $G = '0'.$G;
  728. $B = dechex($B);
  729. if (strlen($B)<2)
  730. $B = '0'.$B;
  731. return '#' . $R . $G . $B;
  732. }