loco_response.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. header("Expires: 0");
  3. session_start();
  4. $response = $_SESSION['login'];
  5. if (!$response) {
  6. return;
  7. }
  8. include 'auth.php';
  9. include 'functions.php';
  10. include 'CheckPoint.php';
  11. include 'CheckPointType.php';
  12. require_once "doctrine/bootstrap.php";
  13. require_once "src/Location.php";
  14. use CheckPoints\CheckPoint;
  15. use CheckPointTypes\CheckPointType;
  16. require_once 'api/vendor/autoload.php';
  17. require_once 'api/vendor/yiisoft/yii2/Yii.php';
  18. $config = require_once 'api/config/web.php';
  19. (new yii\web\Application($config));
  20. foreach (array_keys($_REQUEST) as $var) {
  21. ${$var} = $_REQUEST[$var];
  22. // echo "<b>$var:</b> ${$var} <br>";
  23. }
  24. /**
  25. * @var $section Section
  26. */
  27. /**
  28. * @var $proj Project
  29. */
  30. if ($dayplan_clear_all)
  31. {
  32. $str = "delete from asusg_dayplan";
  33. mysqli_query($link, $str);
  34. echo "clear";
  35. }
  36. if ($dayplan_clear)
  37. {
  38. $str = "delete from asusg_dayplan where day=cast(now() as date)";
  39. mysqli_query($link, $str);
  40. echo "clear";
  41. }
  42. if ($dayplan)
  43. {
  44. if ($loco_number && $date && $letter && $company && $priority)
  45. {
  46. $str = "insert into asusg_dayplan (letter, loco_num, priority, day, company) values ('$letter', $loco_number, $priority, '$date', $company)";
  47. mysqli_query($link, $str);
  48. echo "$loco_number $date $letter $company $priority";
  49. }
  50. }
  51. if ($get_sections_from_twx)
  52. {
  53. // var_dump($get_sections_from_twx);
  54. $proj = Project::Find($get_sections_from_twx);
  55. if (isset($proj))
  56. {
  57. $sections = $proj->getSections();
  58. foreach ($sections as $section)
  59. {
  60. $dm = $section->diagnostic_map;
  61. // echo $section->getSectionSubnumber()." dm $dm";
  62. echo $section->UpdateDiagnosticMap(true);
  63. }
  64. }
  65. //request section from twx
  66. //if ok - write to base, else = echo data fail
  67. }
  68. if ($letter_tasktype && $letter)
  69. {
  70. $tt = Tasktype::Find($letter_tasktype);
  71. if ($tt != null)
  72. {
  73. $tt->letter = $letter;
  74. $tt->Save();
  75. }
  76. //echo "letter_tasktype $letter_tasktype";
  77. }
  78. if ($project_complete)
  79. {
  80. $proj = Project::Find($project_complete);
  81. if ($proj)
  82. {
  83. $res = $proj->Complete($userId);
  84. echo "project_complete: $project_complete" ;
  85. // var_dump($res);
  86. }
  87. }
  88. if ($write_project_to_twx)
  89. {
  90. $proj = Project::Find($write_project_to_twx);
  91. if ($proj)
  92. {
  93. $res = $proj->checkPointsWrite();
  94. // echo "write_project_to_twx:" ;
  95. // var_dump($res);
  96. }
  97. }
  98. if ($pt_addseries)
  99. {
  100. $ptype = ProjectType::Find($pt_addseries);
  101. if ($ptype != null) {
  102. if (sizeof($ptype->series) > 0) {
  103. echo "<b>Доступные серии локомотивов:</b><br>";
  104. foreach ($ptype->series as $serie)
  105. echo "$serie->name<br>";
  106. }
  107. $serie = LocoSeries::Find($series);
  108. if ($serie) {
  109. $ptype->addSeries($serie);
  110. $ptype->Save();
  111. }
  112. }
  113. }
  114. if ($showseries)
  115. {
  116. /**
  117. * @var $ptype ProjectType
  118. */
  119. $ptype = ProjectType::Find($showseries);
  120. if ($ptype != null) {
  121. if (sizeof($ptype->series) > 0) {
  122. echo "<b>Добавленные серии локомотивов:</b><br>";
  123. foreach ($ptype->series as $serie)
  124. echo "$serie->name<br>";
  125. }
  126. $tts = $ptype->getTasktypes();
  127. if (sizeof($tts) > 0) {
  128. /**
  129. * @var $tt Tasktype
  130. */
  131. $letters = array();
  132. foreach ($tts as $tt) {
  133. if ($tt->letter != '' && !in_array($tt->letter, $letters)) {
  134. $letters[] = $tt->letter;
  135. }
  136. }
  137. sort($letters);
  138. if (sizeof($letters) > 0) {
  139. echo "<br><b>Введите субномера секций:</b><br>";
  140. foreach ($letters as $letter) {
  141. echo "$letter: <input id='letter$letter' type='number' min='0' max='99999999' name='$letter'><br>";
  142. }
  143. }
  144. }
  145. }
  146. }
  147. if ($getsectionlist)
  148. {
  149. require_once "api_getsectionlist.php";
  150. echo TWXrequest();
  151. }
  152. if (intval($delsection)> 0) {
  153. $section = Section::Find($delsection);
  154. if ($section) {
  155. if (sizeof($section->projects) == 0) {
  156. Section::Delete($delsection);
  157. echo "Section $delsection deleted!!";
  158. }
  159. else
  160. echo "Error: Section has projects";
  161. }
  162. }
  163. if ($getseries)
  164. {
  165. if ($getseries > 0)
  166. {
  167. $pt = ProjectType::Find($getseries);
  168. $series = $pt->series;
  169. }
  170. else
  171. $series = LocoSeries::GetAll();
  172. $arr = array();
  173. //$series = $getseries
  174. foreach ($series as $serie) {
  175. /**
  176. * @var $serie LocoSeries
  177. */
  178. $numsec = sizeof($serie->getSectionsWithUUID());
  179. $numproj = $serie->projectsAmount();
  180. $numsecall = sizeof($serie->sections);
  181. $arr[$serie->id] = array($serie->name, $numsec, $numsecall, $numproj);
  182. }
  183. echo json_encode($arr);
  184. }
  185. if ($addseries)
  186. {
  187. $serie = new LocoSeries();
  188. $serie->name = $addseries;
  189. $serie->Save();
  190. }
  191. /** @var string $addsections серия локомотива */
  192. /** @var int $number номер локомотива */
  193. /** @var int $subnumber номер секции */
  194. /** @var string $section_letter буква секции */
  195. if ($addsections)
  196. {
  197. $serie = LocoSeries::Find($addsections);
  198. if ($serie != null) {
  199. $section = new Section();
  200. $section->setSectionNumber($number);
  201. $section->setSectionSubnumber($subnumber);
  202. $section->setLetter($section_letter);
  203. $serie->addSection($section);
  204. $serie->Save();
  205. echo "Секция добавлена!";
  206. } else {
  207. echo "serie not found";
  208. }
  209. }
  210. if ($getsections)
  211. {
  212. // FindBySeries
  213. $arr = array();
  214. $ls = LocoSeries::Find($getsections);
  215. $sections = $ls->sections;
  216. // $sections = $ls->getSectionsWithUUID(true);
  217. // $sections = Section::FindBySeries($getsections, true);
  218. // $array = $hydrator->extract($data);
  219. foreach ($sections as $section) {
  220. $section->projectsAmount = sizeof($section->projects);
  221. array_push($arr, $section->toArray());
  222. }
  223. // echo sizeof($arr);
  224. echo json_encode($arr);
  225. // var_dump($arr);
  226. // echo "Get Sections!! $section";
  227. }
  228. if ($getsectioncontent)
  229. {
  230. $section = Section::Find($getsectioncontent);
  231. $retarr = array();
  232. if ($section != null)
  233. {
  234. // $section->diagnostic_maps = $section->diagnostic_maps->toArray();
  235. // $proj = $section->project;
  236. $projIds = array();
  237. foreach ($section->projects as $p)
  238. {
  239. array_push($projIds, $p->id);
  240. }
  241. $section->test = $projIds;
  242. array_push($retarr,$section->toArray());
  243. array_push($retarr,$section->diagnostic_maps->toArray());
  244. array_push($retarr,$projIds);
  245. // echo "DK: ".sizeof($section->diagnostic_maps);
  246. echo json_encode($retarr);
  247. //echo json_encode($section->toArray());
  248. //echo json_encode($section->diagnostic_maps->toArray());
  249. }
  250. }