asusg_response.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. defined('YII_DEBUG') or define('YII_DEBUG', true);
  3. defined('YII_ENV') or define('YII_ENV', 'dev');
  4. require __DIR__ . '/api/vendor/autoload.php';
  5. require __DIR__ . '/api/vendor/yiisoft/yii2/Yii.php';
  6. $config = require __DIR__ . '/api/config/web.php';
  7. (new yii\web\Application($config));
  8. require_once "doctrine/bootstrap.php";
  9. include 'CheckPoint.php';
  10. include 'CheckPointType.php';
  11. use CheckPoints\CheckPoint;
  12. use CheckPointTypes\CheckPointType;
  13. header("Expires: 0");
  14. header("Content-Type: text/html; charset=utf-8");
  15. session_start();
  16. if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 6000)) {
  17. // last request was more than 30 minutes ago
  18. session_unset(); // unset $_SESSION variable for the run-time
  19. session_destroy(); // destroy session data in storage
  20. }
  21. $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
  22. $add = 'Login Area';
  23. foreach (array_keys($_REQUEST) as $var) {
  24. ${$var} = $_REQUEST[$var];
  25. //if ($name == "Admin12") {
  26. // echo "<b>$var:</b> ${$var} <br>";
  27. //}
  28. }
  29. if ($act == "exit")
  30. {
  31. session_unset();
  32. session_destroy();
  33. session_start();
  34. }
  35. if ($_SESSION['cmdlevel'])
  36. $cmdlevel = $_SESSION['cmdlevel'];
  37. if ($_SESSION['hostid'])
  38. $agent_id = $_SESSION['hostid'];
  39. if ($_SESSION['add'])
  40. $add = $_SESSION['add'];
  41. if ($_SESSION['id'])
  42. $id = $_SESSION['id'];
  43. if ($_SESSION['login'])
  44. $login = $_SESSION['login'];
  45. if ($_SESSION['name'])
  46. $name = $_SESSION['name'];
  47. foreach (array_keys($_SESSION) as $var) {
  48. ${$var} = $_SESSION[$var];
  49. //if ($name == "Admin12") {
  50. //echo "from session: <b>$var:</b> ${$var} <br>";
  51. //}
  52. }
  53. include 'functions.php';
  54. include 'auth.php';
  55. $logged_me_in_successfully234 = 0;
  56. $incl = '';
  57. if (!$_SESSION['pass'] && !$_SESSION['login'])
  58. {
  59. $table = 'accounts';
  60. $result=mysqli_query($link, "SELECT id, login, name, cmdlevel FROM $table WHERE login='".$login."' AND password='".md5($pass)."'");
  61. $res1 = mysqli_fetch_array($result);
  62. $cmdlevel = $res1['cmdlevel'];
  63. $name = $res1['name'];
  64. $id = $res1['id'];
  65. if ($cmdlevel == '10')
  66. {
  67. $add = "Head Administrator";
  68. }
  69. else if ($cmdlevel == '1')
  70. {
  71. $add = "Company Administrator";
  72. }
  73. else if ($cmdlevel == '2')
  74. {
  75. $add = "Company Operator";
  76. }
  77. if (mysqli_num_rows($result))
  78. {
  79. $_SESSION['pass']=$pass;
  80. $_SESSION['login']=$login;
  81. $_SESSION['name']=$name;
  82. $_SESSION['add']=$add;
  83. $_SESSION['cmdlevel']=$cmdlevel;
  84. $_SESSION['id']=$id;
  85. $logged_me_in_successfully234 = 1;
  86. }
  87. }
  88. else
  89. $logged_me_in_successfully234 = 1;
  90. $query = mysqli_query($link, "update accounts set last_seen_web =NOW() where id=".$id);
  91. $getincl = GetInclude($act, intval($cmdlevel));
  92. $incl = $getincl[0];
  93. $accnum = $getincl[1];
  94. // ДОБАВЛЕНИ НОВОГО ПРОЕКТА
  95. if ( isset($loco_seria) and isset($typefix) and '' == $get_param){
  96. $marker = 0;
  97. $count = 1;
  98. $arr = [];
  99. $tempArray = [];
  100. $post = \Yii::$app->request->post();
  101. $asusgProjectEntity = new \app\models\entity\AsusgProject();
  102. $errorArr = [];
  103. foreach ($post as $key => $item) {
  104. $marker = explode("-",$key);
  105. if ( 4 > strlen($marker[0])) {
  106. $arr[$marker[0]][] = $item;
  107. } else {
  108. $tempArray[$marker[0]] = $item;
  109. }
  110. }
  111. $asusgProjectEntity->loco_serie_id = $tempArray["loco_seria"];
  112. $asusgProjectEntity->repair_type = explode('_',$tempArray['typefix'])[0];
  113. $asusgProjectEntity->loco_number = $tempArray["loco_number"];
  114. /*$asusgProjectEntity->section_a = $tempArray["section_a"];
  115. $asusgProjectEntity->section_b = $tempArray["section_b"];
  116. $asusgProjectEntity->section_c = $tempArray["section_c"];*/
  117. $asusgProjectEntity->order_a = $tempArray["section_a"];
  118. $asusgProjectEntity->order_b = $tempArray["section_b"];
  119. $asusgProjectEntity->order_c = $tempArray["section_c"];
  120. $asusgProjectEntity->save();
  121. if ( !empty($asusgProjectEntity->errors)) {
  122. $errorArr[] = $asusgProjectEntity->errors;
  123. }
  124. $counter_order = 1;
  125. foreach ($arr as $key => $item) {
  126. $asusgJob2LaunchEntity = new \app\models\entity\AsusgJob2Launch();
  127. $asusgJob2LaunchEntity->asusg_project_id = (int)$asusgProjectEntity->id;
  128. $asusgJob2LaunchEntity->asusg_jobplan_id = (int)$item[0];
  129. $asusgJob2LaunchEntity->asusg_employee_id1 = (int)$item[1];
  130. $asusgJob2LaunchEntity->asusg_employee_id2 = (int)$item[3];
  131. $asusgJob2LaunchEntity->asusg_employee_id3 = (int)$item[5];
  132. $asusgJob2LaunchEntity->jobtype_id1 = (int)$item[2];
  133. $asusgJob2LaunchEntity->jobtype_id2 = (int)$item[4];
  134. $asusgJob2LaunchEntity->jobtype_id3 = (int)$item[6];
  135. $asusgJob2LaunchEntity->job_order = $counter_order;
  136. $asusgJob2LaunchEntity->save();
  137. if ( !empty($asusgJob2LaunchEntity->errors)) {
  138. $errorArr[] = $asusgJob2LaunchEntity->errors;
  139. }
  140. $counter_order++;
  141. }
  142. if ( empty($errorArr) ){
  143. $errorArr = [0 => true, 'id' => (int)$asusgProjectEntity->id];
  144. }
  145. echo json_encode($errorArr);
  146. }
  147. // РЕДАКТИРОВАНИЕ ПРОЕКТА
  148. if ( '' != $get_param){
  149. $errorArr = [];
  150. $marker = 0;
  151. $count = 1;
  152. $arr = [];
  153. $tempArray = [];
  154. $post = \Yii::$app->request->post();
  155. $asusgProjectEntity = \app\models\entity\AsusgJob2Launch::find()->where(['asusg_project_id' => $get_param])->orderBy(['id' => SORT_ASC])->all();
  156. foreach ($post as $key => $item) {
  157. $marker = explode("-",$key);
  158. if ( 4 > strlen($marker[0])) {
  159. $arr[$marker[0]][] = $item;
  160. } else {
  161. $tempArray[$marker[0]] = $item;
  162. }
  163. }
  164. $counter_order = 1;
  165. $tempArray1 = [];
  166. $tempArray2 = [];
  167. foreach($asusgProjectEntity as $item) {
  168. $tempArray1[] = ['job_order' => $item->job_order,'asusg_jobplan_id' => $item->asusg_jobplan_id];
  169. }
  170. foreach ($arr as $key => $item) {
  171. $tempArray2[] = ['job_order' => $counter_order,'asusg_jobplan_id' => (int)$item[0]];
  172. $counter_order++;
  173. }
  174. $tempArray1 = json_encode($tempArray1);
  175. $tempArray2 = json_encode($tempArray2);
  176. $counter_order = 1;
  177. if ( 0 != strcmp($tempArray1,$tempArray2)) {
  178. $asusgProjectEntity2 = \app\models\entity\AsusgProject::findOne(['id' => $get_param]);
  179. if ( 1 == $asusgProjectEntity2->status ) {
  180. \app\models\entity\AsusgJob2Launch::deleteAll(['asusg_project_id' => $get_param]);
  181. }
  182. foreach ($arr as $key => $item) {
  183. $asusgJob2LaunchEntity = new \app\models\entity\AsusgJob2Launch();
  184. $asusgJob2LaunchEntity->asusg_project_id = (int)$get_param;
  185. $asusgJob2LaunchEntity->asusg_jobplan_id = (int)$item[0];
  186. $asusgJob2LaunchEntity->asusg_employee_id1 = (int)$item[1];
  187. $asusgJob2LaunchEntity->asusg_employee_id2 = (int)$item[3];
  188. $asusgJob2LaunchEntity->asusg_employee_id3 = (int)$item[5];
  189. $asusgJob2LaunchEntity->jobtype_id1 = (int)$item[2];
  190. $asusgJob2LaunchEntity->jobtype_id2 = (int)$item[4];
  191. $asusgJob2LaunchEntity->jobtype_id3 = (int)$item[6];
  192. $asusgJob2LaunchEntity->job_order = $counter_order;
  193. $rrrr[] = $asusgJob2LaunchEntity->attributes;
  194. $asusgJob2LaunchEntity->save();
  195. if ( !empty($asusgJob2LaunchEntity->errors)) {
  196. $errorArr[] = $asusgJob2LaunchEntity->errors;
  197. }
  198. $counter_order++;
  199. }
  200. }
  201. if ( empty($errorArr) ){
  202. $errorArr = [0 => true,'id' => $get_param];
  203. }
  204. echo json_encode($errorArr);
  205. }
  206. // ЗАПУСК ПРОЕКТА
  207. if ( isset($user_id_gogo) and isset($id_proj_gogo) ) {
  208. $arr = ['initiator' => (int)$user_id_gogo, 'project_id' => (int)$id_proj_gogo];
  209. $res = \Yii::$app->db->createCommand('call asusg_build_and_start_project('.$arr["initiator"].','.$arr["project_id"].')')->execute();// queryOne();
  210. echo json_encode($res);
  211. }
  212. if ( isset($arrayGantTasks) ) {
  213. $input_id = 0;
  214. $arrayGantTasks = json_decode($arrayGantTasks);
  215. $flag = true;
  216. $arrayPriorityPos = [];
  217. foreach( $arrayGantTasks as $task ) {
  218. if ( $flag ){
  219. $arraycheckChange = checkChange($task->input_id,$arrayGantTasks);
  220. $arrayPriorityPos = getMapForPriority($task->input_id);
  221. foreach($arraycheckChange as $key => $task2) {
  222. global $id;
  223. $query = "call `asusg_change_parent_task`( ".$id.",".$key.",".$task2.")";
  224. $re = mysqli_query($link, $query);
  225. }
  226. $flag = false;
  227. }
  228. if ( 0 == $task->parent ){continue;}
  229. //var_dump($task);
  230. $input_id = $task->input_id;
  231. $priority = $arrayPriorityPos['pos'][$task->parent] + $task->position;
  232. if ( 5 == $arrayPriorityPos['status'][$task->id]) {continue;}
  233. $stringParam = '`parent_id`= ' . $task->parent .', `priority`='. $priority .' ';
  234. $query = 'UPDATE `tasks` SET ' . $stringParam . ' WHERE `id`=' . $task->id ;
  235. //echo $task->id.'=>'.$task->parent ; echo "<br>";
  236. mysqli_query($link, $query);
  237. }
  238. //call asusg_change_parent_task( initiator integer,task_id integer,parent_task integer);
  239. echo 'true';
  240. }
  241. if (isset($tasks_id_map)){
  242. $tasks_id_map = (int)$tasks_id_map;
  243. $res = \Yii::$app->db->createCommand('SELECT `asusg_job_mapped_id` FROM `tasks` WHERE `id` =' . $tasks_id_map)->queryOne();
  244. $res = \Yii::$app->db->createCommand('SELECT `id` FROM `tasks` WHERE `asusg_job_mapped_id` =' . $res['asusg_job_mapped_id'])->queryAll();
  245. echo json_encode($res);
  246. }
  247. //var_dump(getMapForPriority(2881)_;
  248. function getMapForPriority($project_id = null ) {
  249. if ( null == $project_id) {
  250. return [];
  251. }
  252. $taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $project_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC])->all();
  253. $arr = [];
  254. $arrayStatus = [];
  255. $resultPos = [];
  256. $result = [];
  257. foreach( $taskEntity as $task){
  258. if ( 0 == $task->parent_id ) { continue;}
  259. $arr[$task->parent_id][] = ['priority' => $task->priority, 'status' => $task->status];
  260. $arrayStatus[$task->id] = $task->status;
  261. }
  262. foreach($arr as $key => $arr2){
  263. $pos = 0;
  264. foreach ( $arr2 as $it) {
  265. if ( 5 == $it['status'] ){
  266. $pos = $it['priority'];
  267. }
  268. }
  269. $resultPos[$key] = $pos;
  270. }
  271. //echo "<pre>";
  272. // var_dump($arr);
  273. //echo "</pre>";
  274. return $result = ['pos' => $resultPos, 'status' => $arrayStatus,'taskEntity' => $taskEntity];
  275. /**/
  276. }
  277. function checkChange($proj_id,$gantTasks){
  278. $result = [];
  279. $taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $proj_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC])->all();
  280. $data = [];
  281. $data = yii\helpers\ArrayHelper::toArray($taskEntity, ['app\models\entity\Tasks' => ['id','parent_id']]);
  282. $tmpArray = [];
  283. foreach( $data as $task){
  284. $tmpArray[$task['id']] = $task['parent_id'];
  285. }
  286. foreach( $gantTasks as $task2){
  287. if ( $tmpArray[$task2->id] != $task2->parent) {
  288. $result[$task2->id] = $task2->parent;
  289. }
  290. }
  291. return $result ;
  292. }
  293. ?>