123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828 |
- <?php
- header("Expires: 0");
- session_start();
- ini_set('error_reporting', 'E_ALL');
- ini_set('display_errors', '1');
- ini_set('display_startup_errors', '1');
- $response = $_SESSION['login'];
- if (!$response) {
- return;
- }
- include 'auth.php';
- //include 'functions.php';
- require_once 'functions.php';
- include 'CheckPoint.php';
- include 'CheckPointType.php';
- require_once "doctrine/bootstrap.php";
- require_once "src/Location.php";
- use CheckPoints\CheckPoint;
- use CheckPointTypes\CheckPointType;
- foreach (array_keys($_REQUEST) as $var) {
- ${$var} = $_REQUEST[$var];
- // echo "<b>$var:</b> ${$var} <br>";
- }
- if (isset($get_user_tasks))
- {
- $retarr = array();
- $str = "select id, input_id, accepted_time, finished_time from tasks where assignees_arr = $get_user_tasks";
- $query = mysqli_query($link, $str);
- while ($res = mysqli_fetch_assoc($query))
- {
- $retarr[] = [$res['id'], $res['input_id'], $res['accepted_time'], $res['finished_time']];
- }
- echo json_encode($retarr);
- }
- if (isset($quitaccount))
- {
- require_once "server.php";
- Quit($quitaccount, true);
- }
- if (isset($seturgent))
- {
- /**
- * @var $proj Project
- */
- $proj = Project::Find($seturgent);
- if ($proj != null)
- {
- $proj->urgent = abs($proj->urgent-1);
- $proj->Save();
- }
- }
- if (isset($newjob_accid))
- {
-
- $acc = Account::Find($newjob_accid);
-
- if ($acc != null) {
- $acc->UpdateJob($jobvalue, $index, $previous);
- }
- else
- echo "Account not found";
-
- }
- if (isset($basic_count))
- {
- $acc = Account::Find($accid);
- $acc->basic_jobs_count = $basic_count;
- $acc->Save();
- echo $basic_count;
- }
- if (isset($beacons_loc))
- {
- $query = mysqli_query($link,"select * from beacons where location_id=$beacons_loc");
- $arr = array();
- while ($query && $res = mysqli_fetch_array($query))
- {
- $x = $res['x'];
- $y = $res['y'];
- $uuid = $res['uuid'];
- $myarr = array("id"=>$uuid, 'x'=>$x,'y'=>$y);
- array_push($arr, $myarr);
- // echo "<div>[$uuid] X: $x Y: $y</div>";
- }
- echo json_encode($arr);
- //echo "No beacons";
- }
- if (isset($users_loc))
- {
- if ($users_loc == '22') {
- $query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
- if ($query && $res = mysqli_fetch_row($query))
- {
- $x = $res[1];
- $y = $res[2];
- $zone = $res[6];
- }
- $query = mysqli_query($link,"select * from zones where id=$zone");
- if ($query && $res = mysqli_fetch_row($query))
- {
- $zone = $res[2];
- }
- $arr = array("id"=>9, "name"=>'Петр Петров','x'=>$x,'y'=>$y,'Zone'=>$zone);
- echo json_encode($arr);
- // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
- }
- else
- echo "No users";
- }
- /*
- if (isset($users_markers))
- {
- $contTime = date('Y-m-d H:i:s');
- $beginTime = strtotime($contTime) - 3600;
- $beginTime = date('Y-m-d H:i:s', $beginTime);
- if ($users_markers != null && $depo_markers != null ) {//&& $time_markers != null
-
- if ($date_start != null && $date_stop != null){
- $beginTime = $date_start;
- $contTime = $date_stop;
- } else {
- echo json_encode('');
- }
- //if ($date_stop != null ){
- // $contTime = $date_stop;
- //}
-
- $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 ";
-
-
- //$query = mysqli_query($link,"select * from user_positions WHERE `acc_id` = " . $users_markers . " AND `location_id` = " . $depo_markers . " ORDER BY id DESC ");
- $query = mysqli_query($link,$queryString);
- //2019-07-08 15:22:28
- //$query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
- $result = [];
-
- $num_rows = mysqli_num_rows($query);
-
- $module = round(1/$num_rows, 4 , PHP_ROUND_HALF_DOWN);
- $i = 0;
- while ($query && $res = mysqli_fetch_assoc($query))
- {
- $red = ( 255 * (1 - $moduleTemp)) + ( 0 * $moduleTemp );
- $blue = ( 0 * (1 - $moduleTemp)) + ( 255 * $moduleTemp );
- //$count = round($red) . ', 0 ,' . round($blue);
- $moduleTemp += $module;
- $res['c'] = $module;//$count;
- $res['num'] = $num_rows;
- $res['rgb'] = fromRGB(round($red), 0, round($blue));//$count;
- $res['radius'] = 4;
- $res['tip'] = 'You are over 100,100';
-
- $result[$i] = $res;
- $i++;
- }
- //$result['datetime'] = $queryString;
- echo json_encode($result);
-
- //echo json_encode($arr);
- // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
- }
- //else
- // echo "No users";
- }
- */
- if (isset($users_markers))
- {
- $contTime = date('Y-m-d H:i:s');
- $beginTime = strtotime($contTime) - 3600;
- $beginTime = date('Y-m-d H:i:s', $beginTime);
- if ($users_markers != null && $depo_markers != null ) {//&& $time_markers != null
-
- if ($date_start != null && $date_stop != null){
- $beginTime = $date_start;
- $contTime = $date_stop;
- } else {
- echo json_encode('');
- }
- //if ($date_stop != null ){
- // $contTime = $date_stop;
- //}
- $smooth = 5;
- /*
- $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 ";*/
- $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";
-
-
- $query = mysqli_query($link,$queryString);
- //2019-07-08 15:22:28
- //$query = mysqli_query($link,"select * from user_positions ORDER BY id DESC LIMIT 1");
- $result = [];
- $resultTest = [];
- $num_rows = mysqli_num_rows($query);
-
- $module = round(1/$num_rows, 4 , PHP_ROUND_HALF_DOWN);
- $i = 0;
- while ($query && $res = mysqli_fetch_assoc($query))
- {
- $red = ( 255 * (1 - $moduleTemp)) + ( 0 * $moduleTemp );
- $blue = ( 0 * (1 - $moduleTemp)) + ( 255 * $moduleTemp );
- //$count = round($red) . ', 0 ,' . round($blue);
- $moduleTemp += $module;
- $res['c'] = $module;//$count;
- $res['num'] = $num_rows;
- $res['rgb'] = fromRGB(round($red), 0, round($blue));//$count;
- $res['radius'] = 4;
- $resultTest[] = [ 'time' => $res['ts'], 'coord_x' => ($res['coord_x']*8), 'coord_y' => ($res['coord_y']*8)];
- $res['tip'] = 'You are over 100,100';
-
- $result[$i] = $res;
- $i++;
- }
- //$result['datetime'] = $queryString;
-
- $curResult = [];
- $i = 0;
- foreach( $resultTest as $key =>$coord ){
-
- //if( $key < $smooth) {
- $curResult[] = $coord;
- $result[$i]['coord_x'] = $coord['coord_x'];
- $result[$i]['coord_y'] = $coord['coord_y'];
- $i++;
- continue;
- //}
- $begin = $key - $smooth;
- //echo "<pre>";
- $sumX = 0;
- $sumY = 0;
- for($r = 0;$r < $smooth; $r++){
- $sumX += $resultTest[$i + $r]["coord_x"];
- $sumY += $resultTest[$i + $r]["coord_y"];
-
- }
- $sumX = $sumX/$smooth;
- $sumY = $sumY/$smooth;
- $result[$i]['coord_x'] = $sumX;//$sumX*8;
- $result[$i]['coord_y'] = $sumY;//$sumY*8;
- $result[$i]['time'] = $coord['time'];//$sumY*8;
-
- //var_dump((int)round($sumX, 0),(int)round($sumY, 0));
- //echo "</pre>";
- $i++;
- }
-
- //$result['f'] = $result
- //$result = $queryString;
- echo json_encode($result);
-
- //echo json_encode($arr);
- // echo "[9] Петр Петров X: $x Y: $y <b>Зона:</b> $zone";
- }
- //else
- // echo "No users";
- }
- if (isset($beacon_item)){
- $taskType = mysqli_query($link, "insert into `beacons` (`x`, `y` ,`location_id` , `uuid`) values ($x, $y,$location_id,'$uuid')");
- if ('' == mysqli_error($link)){
- echo json_encode("good");
- } else {
- echo json_encode(mysqli_error($link));
- }
- }
- if (isset($dwnl_beacons)){
- //$repair = 'asdasdasd';
- /*
- $filePath = $_SERVER['DOCUMENT_ROOT'].'/uploads/coord.xlsx';
- $Excel = \PHPExcel_IOFactory::load($filePath);
- $maxCell = $Excel->setActiveSheetIndex(0);
- $repair = $Excel->getActiveSheet()->getCell('A3')->getValue();
- $result = [];
- for( $i = 3 ; $i < 36; $i++){
- //$tempArray = [];
- $minor = $Excel->getActiveSheet()->getCell('A'.$i)->getValue();
- $x = $Excel->getActiveSheet()->getCell('B'.$i)->getValue();
- $y = $Excel->getActiveSheet()->getCell('C'.$i)->getValue();
-
- $query = "insert into `beacons` (`x`, `y` ,`location_id` , `uuid`,`major`,`minor`,`enabled`) values ($x, $y,1,'e2c56db5-dffb-48d2-b060-d0f5a71096e0',5 , $minor,1)";
-
- $taskType = mysqli_query($link, $query);
- }
- */
- //echo "<pre>";
- // var_dump('repair');
- // var_dump($query);
- //echo "</pre>";
- echo json_encode($_FILES['file']);
-
- }
- if (isset($get_img)){
-
- $result = [];
- if ( $depo_markers ) {
- $queryString = "select * from locations WHERE `company_id` = " . $depo_markers . "";
- $query = mysqli_query($link,$queryString);
- if ($query && $res = mysqli_fetch_assoc($query))
- {
- $result['image'] = $res['img'];
- } else {
- $result['image'] = '';
- }
-
-
- }
- $queryString = "select `x`,`y` from beacons WHERE `location_id` = " . $depo_markers . "";
- $query = mysqli_query($link,$queryString);
- $result['point_beacons'] = [];
- while ($res = mysqli_fetch_assoc($query))
- {
- $result['point_beacons'][] = ['x' => $res['x'],'y'=>$res['y']];
- }
-
- $queryString = "select * from zones WHERE `location_id` = " . $depo_markers . "";
- $query = mysqli_query($link,$queryString);
- $result['point_zones'] = [];
- while ($res = mysqli_fetch_assoc($query))
- {
- $result['point_zones'][] = $res;
- }
-
- $query = mysqli_query($link, "select uuid from beacons");
- while ($res = mysqli_fetch_row($query)) {
- $result['uuids'][] = $res['uuid'];
- }
- echo json_encode($result);
- }
- if (isset($depo_zone)){
-
- $result = [];
- $depo_zone = json_encode($depo_zone);
- mysqli_query($link, "insert into `zones` (`description`, `borders` ,`location_id`) values ('$depo_name', '$depo_zone' , $depo_num )");
- if ('' == mysqli_error($link)){
- echo json_encode(["good"]);
- } else {
- echo json_encode(mysqli_error($link));
- }
-
-
- echo json_encode($result);
- }
- /// получение списка точек для сотрудников находящихся в онлайне
- if (isset($depo_markers_ol)) {
- $dd = TempFuncInsert();
- $company = Company::Find($depo_markers_ol);
- $accounts = $company->accounts;
- $result = [];
- $userList = [];
-
- foreach( $accounts as $account ) {
- $last_seen_mobile = $account->getLastSeenMobile();
- $online_mobile = OnlineAccountCheck(TimeString($last_seen_mobile));
- //$userList[] = [$account->id,$online_mobile];
- if ($online_mobile) {
- $userList[] = $account->id;
- }
- }
- $queryString = "select * from locations WHERE `company_id` = " . $depo_markers_ol;
- $query = mysqli_query($link,$queryString);
- $comp = mysqli_fetch_assoc($query);
- $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";
- $query = mysqli_query($link,$query1);
- $idList = [];
- while ($res = mysqli_fetch_assoc($query)) {
- $idList[] = $res['id'];
- }
-
- $queryString = "select `ts`, `acc_id`,`coord_x`,`coord_y` from user_positions WHERE `id` IN (".implode(',', $idList).")";
- $query = mysqli_query($link,$queryString);
- $i = 0;
- while ($query && $res = mysqli_fetch_assoc($query))
- {
- $result[$i] = $res;
- //$result = $res;
- $i++;
- }
- //$result['req'] = $query1;//$result;
- echo json_encode($result);
- }
- function TempFuncInsert(){
- global $link;
- $x = 100;
- $y = 200;
- $rand = rand(1,10);
- switch ($rand) {
- case 1:
- $x -= 10;
- $y += 10;
- break;
- case 2:
- $x += 10;
- $y -= 10;
- break;
- case 3:
- $x -= 10;
- $y -= 10;
- break;
- case 4:
- $x += 20;
- $y += 20;
- break;
- case 5:
- $x -= 20;
- $y += 20;
- break;
- case 6:
- $x += 30;
- $y -= 20;
- break;
- case 7:
- $x += 20;
- $y -= 40;
- break;
- case 8:
- $x -= 30;
- $y -= 30;
- break;
- case 9:
- $x += 40;
- $y -= 20;
- break;
-
- default:
- break;
-
- }
- $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)";
- $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)";
- mysqli_query($link, $query1);
- mysqli_query($link, $query);
- return $query;
- }
- if(isset($idLastMsg)){
- $company = $_SESSION['company'];
- $result = [];
- if ( true === $idLastMsg ) {
- $idMsg = 0;
- } else {
- $idMsg = explode('_',$idLastMsg)[0];
- }
- $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 . "";
- $res_query = mysqli_query($link, $query);
- $insertMass = '';
- $plugFileImg = '';
- while ($res = mysqli_fetch_assoc($res_query)) {
- $plugFileImg = $res['file'];
- if ( null != $res['file'] ){
- $plugFileImg = '<a href="'."/uploads/chat/" . $res['file'] . '" target="_blank" style="color: #fff;">
- ' . $res['file_name'] . '<br>
- <i class="fa fa-2x fa-file direct-chat-img" style="color: #fff;float: left;"></i>
- </a><br><br>';
- }
- if ($res['acc_id'] == $_SESSION['id']) {
- $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>';
- } else {
- $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>';
- }
- //$result[] = $res;
- }
- echo json_encode($insertMass);
- }
- if(isset($addNewMsg))
- {
- $logPath = $_SERVER['DOCUMENT_ROOT'] . '/uploads/chat/' . 'log.txt';
- $result = $addNewMsg;//'';
- if ('' != $addNewMsg || !empty($_FILES['file_v']['tmp_name'])) {
- $info = new SplFileInfo($_FILES['file_v']['name']);
- $fileRandomName = strtotime(date("Y-m-d H:i:s")) . "." . $info->getExtension();
- $path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/chat/' . $fileRandomName;
- $fileName = '';
- if (copy($_FILES['file_v']['tmp_name'], $path)) {
- $fileName = $_FILES['file_v']['name'];
- }
- $company = $_SESSION['company'];
- $acc_id = $_SESSION['id'];
- $pattern = "/((http|https):\/\/(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|”|\"|'|:|\<|$|\.\s)/i";
- $replacement = "<a href='$0' target='_blank' style='color:#0011FF;text-decoration: underline !important;'>$0</a>";
- $addNewMsg = preg_replace($pattern, $replacement, $addNewMsg);
- if ('' != $fileName) {
- $query = "insert into `chat` (`company_id`, `msg` ,`acc_id`,`file`,`file_name`,`file_ext`) values ($company,\"".$addNewMsg."\",$acc_id, '$fileRandomName', '$fileName','".$info->getExtension()."')";
- //Добавление файла в файлотеку
- //Получаем логин и имя пользователя
- $q = 'select login, name from accounts_internal where id = ' . $acc_id;
- $result = mysqli_query($link, $q);
- $account = mysqli_fetch_array($result);
- if ($account) {
- $login = $account['login'];
- $userName = $account['name'];
- //Ищем папку с именем пользователя
- $q = 'select id from subj where pId = 1 and name = "' . $login . '" and isFolder = 1';
- $result = mysqli_query($link, $q);
- $row = mysqli_fetch_array($result);
- $subjId = $row['id'] ?? null;
- //Если такой нет, то создаём
- if (!$subjId) {
- $now = (new DateTime())->format('Y-m-d H:i:s');
- $q = 'insert into subj (pId, isFolder, name, note, date, acc_download) VALUES ' .
- ' (1, 1, "' . $login . '", "' . $userName . '", "' . $now . '", ' . $acc_id . ')';
- if ($result = mysqli_query($link, $q)) {
- $subjId = mysqli_insert_id($link);
- } else {
- file_put_contents($logPath, mysqli_error($link), FILE_APPEND);
- }
- }
- //Добавляем в неё файл
- $q = 'insert into subj (pId, isFolder, path, fname, name, size, date, acc_download) VALUES ' .
- ' (' . $subjId . ', 0, "/uploadfiles/", "' . $fileRandomName . '", "' . $fileName . '", ' . filesize($path) . ', "' . $now . '", ' . $acc_id . ')';
- $result = mysqli_query($link, $q);
- //Копируем файл в файлотеку
- if (copy($_FILES['file_v']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/filelib/uploadfiles/' . $fileRandomName)) {
- file_put_contents($logPath, 'Файл сохранён под именем: ' . $fileRandomName, FILE_APPEND);
- }
- if (!$result) {
- file_put_contents($logPath, 'second: ' . mysqli_error($link), FILE_APPEND);
- file_put_contents($logPath, $q, FILE_APPEND);
- }
- }
- } else {
- $query = "insert into `chat` (`company_id`, `msg` ,`acc_id`) values ($company,\"".$addNewMsg."\",$acc_id)";
- }
- $result = mysqli_query($link, $query);
- }
- echo json_encode($result);
- }
- if (isset($del_loc))
- {
- Location::Delete($del_loc);
- }
- if (isset($load_locs))
- {
- Location::EchoLocations();
- }
- if (isset($add_loc))
- {
- Location::Add($add_loc, $desc);
- }
- if (isset($delete_cpt))
- {
- CheckPointType::Delete($delete_cpt);
- }
- if (isset($add_to_task))
- {
- global $link;
- $taskType = mysqli_query($link, "insert into checkpoint_types_for_tasks (tasktype_id, cp_type_id) values ($taskType, $add_to_task)");
- //add_to_task - id of cpt to add
- }
- if (isset($addcpt))
- {
- CheckPointType::CreateFromScratch($addcpt, $name);
- }
- if (isset($toggletwx))
- {
- $cp = CheckPointType::CreateFromID($toggletwx);
- $newtwx = abs($cp->getWriteToTWX()-1);
- $cp->setWriteToTWX($newtwx);
- $writeTWX = "нет";
- if ($cp->getWriteToTWX())
- $writeTWX = "да";
- echo "Запись в АСУ СГ: <input id='toggleTWX' type='button' value='$writeTWX'>";
- }
- if (isset($showcheckbox))
- {
- $cp = CheckPointType::CreateFromID($showcheckbox);
- $writeTWX = "нет";
- if ($cp->getWriteToTWX())
- $writeTWX = "да";
- echo "Запись в АСУ СГ: <input id='toggleTWX' type='button' value='$writeTWX'>";
- }
- if (isset($show))
- {
- EchoTypesOfClass($show);
- }
- if (isset($show_cb_list))
- {
- EchoCheckBoxTemplate();
- }
- if (isset($add_cb))
- {
- $parent = CheckPointType::CreateFromID($parent_id);
- if ($parent->class != "MultiSelect" && $parent->class != "DropList" ) {
- echo "Не для этого типа чекпойнтов! $parent_id $parent->class";
- return;
- }
- CheckPointType::AddChildToDB($add_cb, $parent_id);
- }
- if (isset($remove_cb, $parent_id))
- {
- CheckPointType::CreateFromID($parent_id)->RemoveChildFromDB($remove_cb);
- }
- if (isset($id))
- {
- $cpt = CheckPointType::CreateFromID($id);
- EchoContents($cpt);
- }
- if (isset($jobtype) && isset($acc))
- {
- global $link;
- $userId = $_SESSION['id'];
- $task = mysqli_query($link, "CALL change_jobtype_priority($acc, $jobtype, $userId)");
- }
- if (isset($asusg_id) && isset($project_type) )
- {
- global $link;
- $resultArray = [];
- //$userId = $_SESSION['id'];
- $task = mysqli_query($link, "CALL asusg_bind_projecttype($asusg_id, $project_type)");
- }
- if (isset($asusg_id) && isset($user_id) )
- {
- global $link;
- //var_dump($user_id, $asusg_id);
- $task = mysqli_query($link, "CALL asusg_start_projects($user_id, $asusg_id)");
- }
- if (isset($asutask_id) && isset($projecttype_id) )
- {
- global $link;
- //var_dump($user_id, $asusg_id);
-
- $task = mysqli_query($link, "CALL asusg_bind_jt2task($asutask_id, $projecttype_id)");
- echo json_encode([$asutask_id, $projecttype_id, $task ]);
- }
- if (isset($employee_uuid) && isset($employee_id) )
- {
- global $link;
- $task = mysqli_query($link, "CALL asusg_bind_employee('$employee_uuid', $employee_id)");
- echo json_encode(["CALL asusg_bind_employee(".$employee_uuid.", ".$employee_id.")" ]);
- }
- if (isset($listItems))
- {
- global $link;
- $listItems = explode(',',$listItems);
- $result = false;
- if ( 0 < count($listItems)) {
- $params = [];
- $i = 0;
- $asusg_job_id = 0;
- $paramsString = "INSERT INTO asusg_job2command (`asusg_job_id`,`smopp_cmd_id`,`jobtype_id`,`asusg_projecttype_id`,`cmd_order`) values";
- foreach($listItems as $item){
- $tempArray = explode('_',$item);
- $params[] = ['asusg_job_id' =>$tempArray[0],'smopp_cmd_id' =>$tempArray[1],'cmd_order' => $i];
- $paramsString .= "($tempArray[0],$tempArray[1],$tempArray[3],$tempArray[4],$i),";
- $asusg_job_id = $tempArray[0];
- $i++;
- }
- $paramsString = substr($paramsString,0,-1);
- $resDelete = mysqli_query($link,"delete from asusg_job2command where asusg_job_id = $asusg_job_id and smopp_cmd_id >= 0 and cmd_order >= 0");
-
- $resInsert = mysqli_query($link,$paramsString);
- //if ($res) {
- $result = $res;
- //}
- }
- echo json_encode('Удаление =>'.$resDelete . " вставка =>" . json_encode($paramsString) );//mysqli_error($link));
- }
- if (isset($loco_series) and isset($typefix)) {
- global $link;
- $paramsString = "INSERT INTO asusg_projecttype (`repair_type`,`loco_serie_id`) values ( $typefix, $loco_series )";
- $res = mysqli_query($link,$paramsString);
- echo json_encode($res);
- }
- if (isset($loco_seria) and isset($typefix)) {
- global $link;
- $paramsString = "SELECT * FROM asusg_projecttype WHERE `repair_type` = $typefix and `loco_serie_id` = $loco_seria";
- $res = mysqli_query($link,$paramsString);
- echo json_encode($res);
- }
- if (isset($removeProjectTypeAsusg)) {
- global $link;
- $queryParams = explode('@',$removeProjectTypeAsusg);
- $paramsString = "DELETE FROM asusg_projecttype WHERE `loco_serie_id` = " . $queryParams[0] . " and `repair_type`=" . $queryParams[1];
- $res = mysqli_query($link,$paramsString);
- echo json_encode($res);
- }
- if (isset($listItemsAsusg)) {
-
- global $link;
- $listItems = explode(',',$listItemsAsusg);
- $result = false;
- if ( 0 < count($listItems)) {
- $params = [];
- $i = 0;
- $asusg_job_id = 0;
- $paramsString = "INSERT INTO asusg_job2project (`asusg_projecttype_id`,`asusg_jobplan_id`,`job_order`) values";
- foreach($listItems as $item){
- $tempArray = explode('_',$item);
- $asusg_job_id = $tempArray[0];
- $params[] = ['asusg_projecttype_id'=> $job_id,'asusg_jobplan_id' =>$item,'job_order' => $i];
- $paramsString .= "($job_id,$asusg_job_id,$i),";
-
- $i++;
- }
- $paramsString = substr($paramsString,0,-1);
- $resDelete = mysqli_query($link,"delete from asusg_job2project where asusg_projecttype_id = $job_id and asusg_jobplan_id >= 0 and job_order >= 0");
-
- $resInsert = mysqli_query($link,$paramsString);
- //if ($res) {
- $result = $res;
- //}
- }
- echo json_encode('Удаление =>'.$resDelete . " вставка =>" . $paramsString );//mysqli_error($link));
- }
- if (isset($taskName)) {
- global $link;
- $paramsString = "INSERT INTO asusg_jobplan (`name`) values ( '$taskName' )";
- $res = mysqli_query($link,$paramsString);
- echo json_encode("вставка =>" + $res );
- }
- if (isset($moveToPlan))
- {
- global $link;
- $id_user = $_SESSION['id'];
- $query = "CALL asusg_build_project( $id_user, 194, 734, '$loco', $loco_number, $id_asusg_job)";
- $res = mysqli_query($link,$query);
- echo json_encode($res);//mysqli_error($link));
- }
- function EchoTypesOfClass($show)
- {
- $classes = CheckPoint::GetClasses();
- $search = array_search($show, $classes, true);
- if ($search) {
- $list = CheckPointType::GetCheckPointTypes($show);
- EchoSelect($list, $show."s", $show."_list");
- }
- }
- function EchoContents($cpt)
- {
- echo "Варианты для \"[$cpt->id] $cpt->name\":<br>";
- foreach ($cpt->childrenCheckpointTypes as $child) {
- echo '<div class="content__main__imgwrap">';
- echo "<img src='ProSysNew/delete.svg' alt='удалить' class='content__main__imgdel' onclick='delCheckbox($child->id, $cpt->id)' title='Удалить'>";
- //echo "<img src='images/change.svg' alt='заменить' class='content__main__imgchange' onclick='changeCheckbox($child->id)' title='Заменить'>";
- echo "[$child->id]<b> $child->name</b><br>";
- echo "</div>";
- }
- echo "<div id='add_new_checkbox' style='display: inline-block; position: absolute; margin-top: 9px; font-size: 25px;' class='round deepskyblue'>+</div><br><br>";
- }
- function EchoCheckBoxTemplate()
- {
- $typesCheckBox = CheckPointType::GetCheckPointTypes("CheckBox");
- echo "<div id='cb_template'><p>Выберите чекпойнт для добавления:</p>";
- EchoCheckPointType($typesCheckBox, 'cb_template');
- echo "</div>";
- }
- function EchoCheckPointType($list, $id)
- {
- echo "<select id='select_$id' data-contentsFlag='noHideContents' style='width: 400px' class='form-input content__main__form__series' name='cptype'>";
- $str = '<option value="0"><Выберите тип чекпойнта из списка></option>';
- foreach ($list as $type)
- {
- $str .= "<option value='$type->id'>[$type->id] $type->name</option>";
- }
- echo "$str</select>";
- }
- function EchoSelect($list, $name, $id)
- {
- echo "<div id='checkpoint_list' style='display: table'>";
- echo "<div style='float: left'><br>";
- EchoCheckPointType($list, $id);
- echo "</div>";
- echo "<div id='remove_checktype' title='Удалить тип' style='display: none; margin-top: 29px; font-size: 25px;' class='round red'>-</div>";
- echo "<div id='add_to_task' title='Добавить в текущий тип команд' style='display: none; margin-top: 29px; font-size: 25px;' class='round green'>+</div><br><br>";
- echo "</div><br>";
- }
- function fromRGB($R, $G, $B)
- {
- $R = dechex($R);
- if (strlen($R)<2)
- $R = '0'.$R;
- $G = dechex($G);
- if (strlen($G)<2)
- $G = '0'.$G;
- $B = dechex($B);
- if (strlen($B)<2)
- $B = '0'.$B;
- return '#' . $R . $G . $B;
- }
|