projects.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?
  2. if (!$logged_me_in_successfully234) return;
  3. EchoScriptName(basename(__FILE__, '.php'));
  4. $company = Company::Find($companyID);
  5. if (isset($assign_id) && isset($assign_act)) {
  6. if (StartProject($assign_act, $assign_id))
  7. TasksAssign('', true, $assign_id);
  8. }
  9. //Создание проекта
  10. if ($new == "2") {
  11. /** @var int $loco_number */
  12. /** @var string $loco_type */
  13. /** @var int $action_num тип проекта */
  14. /** @var int $А */
  15. /** @var int $Б */
  16. /** @var int $В */
  17. /** @var int $Г */
  18. /** @var bool $urgent срочность проекта */
  19. /** @var int $sections ИД секции */
  20. //$task_string = FillArrayString("subtask");
  21. if (!$loco_number) {
  22. /** @var $section Section */
  23. $section = Section::Find($sections);
  24. if ($section) {
  25. $loco_number = $section->getSectionNumber();
  26. }
  27. } else {
  28. //буква секции на кириллице
  29. CheckSection("А", $loco_type, $loco_number, $А);
  30. CheckSection("Б", $loco_type, $loco_number, $Б);
  31. CheckSection("В", $loco_type, $loco_number, $В);
  32. CheckSection("Г", $loco_type, $loco_number, $Г);
  33. }
  34. $projs = $entityManager->getRepository('Project')->findBy(array('company' => $companyID, 'loco_number' => $loco_number, 'loco_type' => $loco_type));
  35. $nostart = false;
  36. foreach ($projs as $proj)
  37. {
  38. //родной статус похоже не проставляется при выполнении
  39. if (intval(GetProjectStatus($proj->id)) < 5 && $proj->getAction() == $action_num)
  40. {
  41. $nostart = $proj->id;
  42. echo "<span style='color:red'><b>Ошибка: для данного типа уже запущен проект $nostart с тем же локомотивом</b></span>";
  43. break;
  44. }
  45. }
  46. if (!$nostart && $loco_type) {
  47. $urgent = ($urgent == "on") ? 1 : 0;
  48. //$qstr = "insert into projects_locotech (action, company, status, loco_type,loco_number,depo,depo_service, created, tasks ) values (" . $action_num . "," . $companyID . ",1,'$loco_type',$loco_number,'$depo','$depo_service', NOW(),'$task_string' )";
  49. $qstr = "insert into projects_locotech (action, company, status, loco_type,loco_number,depo,depo_service, created, urgent) values (" . $action_num . "," . $companyID . ",1,'$loco_type','$loco_number','$depo','$depo_service', NOW(), $urgent)";
  50. //echo "qstr $qstr ";
  51. mysqli_query($link, $qstr);
  52. $activeid = mysqli_insert_id($link);
  53. $project = Project::Find($activeid);
  54. if ($project != null) {
  55. /**
  56. * @var $project Project
  57. */
  58. if ($section) {
  59. $project->section = $section;
  60. $project->Save();
  61. }
  62. }
  63. if ($activeid > 0) {
  64. echo "<span style='color:green'><b>Запись добавлена!</b></span>";
  65. $sort = 1;
  66. if (StartProject($action_num, $activeid))
  67. TasksAssign('', true, $assign_id);
  68. } else
  69. echo "<span style='color:red'><b>Ошибка ввода данных!</b></span>";
  70. }
  71. }
  72. else if ($new == "3") {
  73. echo "<span style='color:red'><b>Проект $del_id и его задачи удалены!</b></span>";
  74. //CleanTasks($del_id);
  75. $textlog = new app\models\entity\Textlog();
  76. $textlog->msg = "Пользователь: ". $id.", Попытка удалить проект (номер): " . $del_id;
  77. $textlog->save();
  78. $companyIDfake = (int)$companyID + 1000;
  79. echo "UPDATE projects_locotech SET `company`=".$companyIDfake ." WHERE `id` = $del_id";
  80. //die();
  81. OCSremoveproject($del_id);
  82. $project = Project::Find($del_id);
  83. if (isset($project))
  84. $project->reopenTasks();
  85. mysqli_query($link, "UPDATE projects_locotech SET `company`=".$companyIDfake." WHERE `id`= $del_id");
  86. //mysqli_query($link, "delete from projects_locotech where id = $del_id");
  87. }
  88. // else if ($new == "4") {
  89. // echo "<p style='color: red'>Не предоставлен образец входного документа!</p>";
  90. //}
  91. else if ($new == "5") {
  92. //echo "<span style='color: green'>Все проекты удалены!</span>";
  93. echo "<span style='color: green'>Удаление всех проектов временно отключено! Обратитесь к разработчику!</span>";
  94. // $projs = $entityManager->getRepository('Project')->findAll();
  95. // foreach ($projs as $proj) {
  96. // CleanTasks($proj->id);
  97. // mysqli_query($link, "delete from projects_locotech where id = $proj->id");
  98. // }
  99. }
  100. if (!isset($sort))
  101. {
  102. $sort = $_SESSION['sorttasks'];
  103. if (!isset($sort)) {
  104. $sort = 1;
  105. }
  106. }
  107. $_SESSION['sorttasks'] = $sort;
  108. echo "<input type='hidden' id='scroll' value=$scroll>";
  109. $active1 = '';
  110. $active2 = '';
  111. $active3 = '';
  112. $active4 = '';
  113. $active5 = '';
  114. switch ($sort)
  115. {
  116. case '1': $active1 = 'control-btn_active'; break;
  117. case '2': $active2 = 'control-btn_active'; break;
  118. case '3': $active2 = 'control-btn_active'; break;
  119. case '4': $active4 = 'control-btn_active'; break;
  120. case '5': $active5 = 'control-btn_active'; break;
  121. }
  122. if (!$project_limit)
  123. $project_limit = '20';
  124. echo
  125. "
  126. <div class='main__content'>
  127. <div class='content__menu'>
  128. <h2 class='content__title content__menu__title' style='margin-bottom: 20px'>
  129. Проекты
  130. </h2>
  131. <p class='content__main__item__text' style='padding: 0; text-align: center'>Показывать на странице: <input type='button' id='project_limit' value='$project_limit'></p>
  132. <div class='content__filter'>
  133. <img src='ProSysNew/search.svg' alt='search' class='content__search'>
  134. <div class='content__controls'>
  135. <button class='control-btn control-btn_red content__filter__btn $active1' onclick='SortElements(1, \"projects\")'>Новые</button>
  136. <button class='control-btn control-btn_yellow content__filter__btn $active2' onclick='SortElements(2, \"projects\")'>В работе</button>
  137. <button class='control-btn control-btn_green content__filter__btn $active5' onclick='SortElements(5, \"projects\")'>Готово</button>
  138. </div>
  139. </div>";
  140. echo '<div class="content__menu__list">';
  141. echo ' <div class="content__menu__newproj content__menu__newproj_active" onclick = "NewListElement(\'projects\')">
  142. <div class="content__menu__newproj__plus">
  143. +
  144. </div>
  145. <div class="content__menu__newproj__text">
  146. Новый проект
  147. </div>
  148. </div><br>';
  149. EchoProjects($sort);
  150. echo '</div>';
  151. echo '</div>';
  152. //PARENT TITLE IN CHILDREN LIST
  153. if ($new == 1)
  154. AddNewProject();
  155. else if ($activeid && $activeid != "undefined") {
  156. // $proj = GetProject($activeid);
  157. /**
  158. * @var $proj Project
  159. */
  160. $proj = Project::Find($activeid);
  161. if ($proj != null) {
  162. $action = FindAction($proj->getAction());
  163. $actionid = $action['id'];
  164. // $types = ProjectType::GrabTasktypesByProjectType($actionid);
  165. $acname = $action['name'];
  166. // $section = $proj->section;
  167. // if ($section != null) {
  168. // $loco_type = $section->locomotive_series;//$proj['loco_type'];
  169. // $loco_number = $section->getSectionNumber();//intval($proj['loco_number']);
  170. // }
  171. $loco_number = $proj->loco_number;
  172. $depo = $proj->getDepo();
  173. $depos = $proj->getDepoService();
  174. if ($activeid) {
  175. $project_comment = '';
  176. $cmt = $proj->getUuid();
  177. if ('' != $cmt)
  178. {
  179. $project_comment = "Комментарий: <i>".$cmt."</i><br>";
  180. }
  181. echo "<div class='content__main'>
  182. <h2 class='content__title content__main__title'>$activeid. $acname</h2>
  183. <p class='content__main__item__text'>
  184. <span style='color: black'>".
  185. $project_comment
  186. ."
  187. Тип проекта: <a href='?act=project_types&activeid=$actionid'>$actionid. $acname</a><br>
  188. Локомотив серии: $loco_type № $loco_number <br>
  189. Депо приписки: $depo<br>
  190. Депо обслуживания: $depos<br><br></span>";
  191. echo "<span style='color: black'>Созданные задачи:</span><br><br>";
  192. // $tasks = GetTasksForProject($activeid);
  193. $tasks = $proj->getTasks();
  194. // ПОЛУЧЕНИЕ XML НАЧАЛО
  195. $parents = $entityManager->getRepository('Task')->findBy(array('parent_id' => 0, 'input_id' => $activeid), array('id' => 'DESC'));
  196. $tasktypesIds = GrabTasktypesIDs();
  197. $array_children = [];
  198. $array_parent = [];
  199. foreach ($parents as $parent) {
  200. if (!in_array(intval($parent->type), $tasktypesIds)) {
  201. continue;
  202. }
  203. $status = GetTaskStatus($parent->id);
  204. if ($status == 5) {
  205. $array_parent[$parent->id] = $parent;
  206. $children = $entityManager->getRepository('Task')->findBy(array('parent_id' => $parent->id));
  207. $array_children[$parent->id] = $children;
  208. }
  209. }
  210. $array_type = [];
  211. $array_id = [];
  212. $_SESSION['array_children'] = $array_children;
  213. $_SESSION['array_parent'] = $array_parent;
  214. $arrayTasksId = [];
  215. foreach ($tasks as $task) {
  216. $type = $task->type;
  217. $id = $task->id;
  218. $_SESSION['actid'] = $id;
  219. foreach ($array_children as $parent_id => $children) {
  220. if ($id == $parent_id) {
  221. foreach ($children as $res1) {
  222. $array_type[] = $res1->type;
  223. $array_id[] = $res1->id;
  224. }
  225. }
  226. }
  227. $xmltype = implode(',', $array_type);
  228. $xmlid = implode(',', $array_id);
  229. $name = GetTaskNameAndDesc($type)[0];
  230. $sortTask = GetTaskStatus($id);
  231. if ($task->parent_id == '0') {
  232. // echo $task->id;
  233. $arrayTasksId[] = $id;
  234. //echo "<a href = '?act=tasks&activeid=$id&sort=$sort'>$id [$sort]. $name </a><br>";
  235. echo "<a href = '?act=tasks&activeid=$id&sort=$sort'>$id. $name </a><br>";
  236. echo $task->text . "<br>";
  237. // if ($task->getAccount() != null) {
  238. if ($sortTask < 5 && $sortTask > 1) {
  239. if ($task->status == 2) {
  240. $sname = "Выдана";
  241. $ass = "[".TimeString($task->assigned)."]";
  242. }
  243. else if ($task->status == 3) {
  244. $sname = "Принята";
  245. $ass = "[выдана: ".TimeString($task->assigned)."]";;
  246. }
  247. $sname = "<span style='color: darkgoldenrod'>$sname $ass:</span> ";
  248. }
  249. else if ($sortTask <= 1)
  250. $sname = "<span style='color: red'>Не выдана</span> ";
  251. else
  252. $sname = "<span style='color: green'>Выполнена:</span> ";
  253. if ($task->getAccount() != null) {
  254. $assignee_names_parent = $task->getAccount()->name;
  255. echo "$sname $assignee_names_parent<br><br>";
  256. }
  257. else
  258. echo "$sname<br><br>";
  259. // }
  260. }
  261. }
  262. // echo "<br><span style='color: black'>Доступные типы задач:</span><br><br>";
  263. //
  264. // foreach ($types as $type) {
  265. // //if ($type['main_task']) {
  266. // if ($type->main_task) {
  267. // echo "[Главная] ";
  268. // $sort = '1';
  269. // }
  270. // $tid = $type->GetId();
  271. // $tname = $type->name;
  272. // echo "<a href = '?act=tasktypes&activeid=" . $tid . "&sort=$sort'>$tid. $tname</a>";
  273. // echo '<br>';
  274. // }
  275. echo "<input type='hidden' id='activeproj' value=$activeid>";
  276. $sections = $proj->getSections();
  277. $numDM = 0;
  278. foreach ($sections as $section)
  279. {
  280. $dm = $section->diagnostic_map;
  281. if ($dm != null && $dm != '00000000-0000-0000-0000-000000000000')
  282. {
  283. $numDM++;
  284. }
  285. }
  286. $sizes = sizeof($sections);
  287. if ($sizes > 0 && $numDM == $sizes)
  288. $disabled = "";
  289. else
  290. $disabled = "disabled";
  291. if ($disabled) {
  292. echo "<span style='color: red'>Нет полных данных от АСУ СГ по секциям локомотива из данного проекта</span><br>";
  293. echo "<br><input id='get_sections_from_twx' type='button' value='Получить данные секций локомотива из АСУ СГ'>";
  294. }
  295. else {
  296. echo "<br><input id='write_project_to_twx' type='button' value='Запись в АСУ СГ'>";
  297. }
  298. if (intval($sort) < 5) {
  299. echo "<br><input id='project_complete' type='button' value='Закрыть проект (Завершение)'>";
  300. }
  301. echo '<input id="userId" hidden value="' . $id . '">';
  302. echo '<div id="result"></div>';
  303. echo '</p></div>';
  304. }
  305. }
  306. }
  307. $_SESSION['array_tasksid'] = $arrayTasksId;
  308. $_SESSION['proj_sort'] = $sort;
  309. echo '<p><a class="xlsbutton" href = XLSProjectList.php?activeid=' . $activeid . '&type=' . $xmltype . '&id=' . $xmlid . '><button class="control-bigbtn content__main__toexec-btn" >Скачать XLS акт</button></a></p>';
  310. echo '<p><a class="xlsbutton" href = XLStu162table.php?activeid=' . $activeid . '&type=' . $xmltype . '&id=' . $xmlid . '> <button class="control-bigbtn content__main__toexec-btn" >Скачать ТУ-162</button></a></p>';
  311. // ПОЛУЧЕНИЕ XML КОНЕЦ
  312. echo '</div>'; //main__content
  313. echo "<br><form id='form5' name='form5' method='post'>
  314. <input type='submit' value='Удалить все проекты' class='control-bigbtn'>
  315. <input type='hidden' name='new' value='5'>
  316. </form>";
  317. function EchoProjects($sort)
  318. {
  319. // echo "sort $sort";
  320. global $companyID, $link, $activeid, $project_limit;
  321. if ($project_limit == '20') {
  322. $project_limit = "limit 20";
  323. }
  324. else
  325. $project_limit = 'limit 2500';
  326. $str = "select * from projects_locotech where company=$companyID order by id desc $project_limit";
  327. $query1 = mysqli_query($link, $str); // limit 20
  328. $projects = array();
  329. while ($res1 = mysqli_fetch_array($query1)) {
  330. $data_id = $res1['id'];
  331. $status = $res1['status'];
  332. // $status = GetProjectStatus($data_id);
  333. // $status = intval($res1['status']);
  334. // echo "id $data_id status $status";
  335. if ($status != $sort){
  336. if ( !(2 == $sort and 3 == $status) ){
  337. continue;
  338. }
  339. }
  340. // $proj = Project::Find($data_id);
  341. // if ($proj == null) {
  342. //// echo "not found $data_id<br>";
  343. // continue;
  344. // }
  345. $loco_number = "Не найден!";//intval($res1['loco_number']);
  346. $subnumber = "Не найден!";
  347. /**
  348. * @var $section Section
  349. */
  350. // $section = $proj->section;
  351. // if ($section != null) {
  352. // echo "Section not found $data_id<br>";
  353. // $loco_number = $section->getSectionNumber();//intval($res1['loco_number']);
  354. // $subnumber = $section->getSectionSubnumber();
  355. // }
  356. $loco_number = intval($res1['loco_number']);
  357. $action = $res1['action'];
  358. // $status = intval($res1['status']);
  359. $loco_type = $res1['loco_type'];
  360. $depo = $res1['depo'];
  361. $created = $res1['created'];
  362. $depo_service = $res1['depo_service'];
  363. $class = 'content__menu__project';
  364. if ($activeid == $data_id)
  365. $class .= ' content__menu__project_active';
  366. else
  367. $class .= ' list';
  368. $action_data = FindAction($action);
  369. echo "<div onclick='SelectProject($data_id)' class='$class'>";
  370. echo "<div class=\"content__menu__project-title\">";
  371. echo $data_id.". ".$action_data["name"] ." <br> $loco_type № $loco_number";
  372. echo "</div>";
  373. echo '<div class="content__menu___project-text">';
  374. if (intval($res1['urgent']))
  375. $urgent = "<span style='color: #bf800c'> Срочный</span>";
  376. else
  377. $urgent = "";
  378. echo "Поступил: $created.$urgent";
  379. echo '<br><br></div>';
  380. if($status == '1')
  381. echo "<input type='button' onclick='AssignTask($data_id, $action, $companyID)' value='В работу!'>";
  382. echo " <input type='button' onclick='DelProj($data_id)' value='Удалить'>";
  383. echo " <input type='button' onclick='EditGantt($data_id)' value='План'>";
  384. echo '</div>';
  385. }
  386. }
  387. //new project
  388. function AddNewProject()
  389. {
  390. global $action, $company;
  391. echo
  392. '
  393. <div class="content__main">
  394. <h2 class="content__title content__new__title">
  395. Введите данные <br>
  396. для нового проекта
  397. </h2>';
  398. $series = LocoSeries::GetAllNames();
  399. // \Doctrine\Common\Util\Debug::dump($series);
  400. // $series = $series->toArray();
  401. //foreach ($series as $serie)
  402. //{
  403. // echo $serie."<br>";
  404. //}
  405. echo '<form action="?act=projects" method="post" class="content__main__form">
  406. <div class="content__main__form__item">
  407. <p class="content__main__form__text">
  408. Тип проекта
  409. <select id="projecttypes" class="form-input content__main__form__goal" name="action_num">';
  410. //ActionsForm(FindActions());
  411. ActionsForm(FindActions(), $action);
  412. echo '</select>
  413. <br>
  414. <div id="chooseseries"></div>
  415. </p>
  416. </div>
  417. <p class="content__main__form__text">Срочный: <input type="checkbox" name="urgent" style="width:20px; height:20px; margin-left: 5px"></p>
  418. <div class="content__main__form__item">';
  419. include "loco.php";
  420. echo '<div>';
  421. // <select class="form-input content__main__form__series" name="loco_type">';
  422. // foreach ($series as $serie) {
  423. // echo "<option value = '$serie' >$serie</option >";
  424. // }
  425. //echo '</select>
  426. echo '<p class="content__main__form__text">Номер локомотива - ручной ввод:</p><input type="text" min="1" name="loco_number" >';
  427. echo '</div>
  428. </div>
  429. ';
  430. // if ($company != null)
  431. // {
  432. // foreach ($company->locations as $location)
  433. // {
  434. // if ($location->type == "sld")
  435. // echo "<option value='$location->id'>$location->name</option>";
  436. // }
  437. // }
  438. //<option value="Братское">Братское</option>
  439. echo '
  440. <input type="submit" value="Добавить в новые и отправить в работу">
  441. <input type="hidden" name="new" value="2">
  442. </form>
  443. </div>
  444. ';
  445. }
  446. ?>