123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- header("Expires: 0");
- session_start();
- $response = $_SESSION['login'];
- if (!$response) {
- return;
- }
- include 'auth.php';
- include 'functions.php';
- include 'CheckPoint.php';
- include 'CheckPointType.php';
- require_once "doctrine/bootstrap.php";
- require_once "src/Location.php";
- use CheckPoints\CheckPoint;
- use CheckPointTypes\CheckPointType;
- require_once 'api/vendor/autoload.php';
- require_once 'api/vendor/yiisoft/yii2/Yii.php';
- $config = require_once 'api/config/web.php';
- (new yii\web\Application($config));
- foreach (array_keys($_REQUEST) as $var) {
- ${$var} = $_REQUEST[$var];
- // echo "<b>$var:</b> ${$var} <br>";
- }
- /**
- * @var $section Section
- */
- /**
- * @var $proj Project
- */
- if ($dayplan_clear_all)
- {
- $str = "delete from asusg_dayplan";
- mysqli_query($link, $str);
- echo "clear";
- }
- if ($dayplan_clear)
- {
- $str = "delete from asusg_dayplan where day=cast(now() as date)";
- mysqli_query($link, $str);
- echo "clear";
- }
- if ($dayplan)
- {
- if ($loco_number && $date && $letter && $company && $priority)
- {
- $str = "insert into asusg_dayplan (letter, loco_num, priority, day, company) values ('$letter', $loco_number, $priority, '$date', $company)";
- mysqli_query($link, $str);
- echo "$loco_number $date $letter $company $priority";
- }
- }
- if ($get_sections_from_twx)
- {
- // var_dump($get_sections_from_twx);
- $proj = Project::Find($get_sections_from_twx);
- if (isset($proj))
- {
- $sections = $proj->getSections();
- foreach ($sections as $section)
- {
- $dm = $section->diagnostic_map;
- // echo $section->getSectionSubnumber()." dm $dm";
- echo $section->UpdateDiagnosticMap(true);
- }
- }
- //request section from twx
- //if ok - write to base, else = echo data fail
- }
- if ($letter_tasktype && $letter)
- {
- $tt = Tasktype::Find($letter_tasktype);
- if ($tt != null)
- {
- $tt->letter = $letter;
- $tt->Save();
- }
- //echo "letter_tasktype $letter_tasktype";
- }
- if ($project_complete)
- {
- $proj = Project::Find($project_complete);
- if ($proj)
- {
- $res = $proj->Complete($userId);
- echo "project_complete: $project_complete" ;
- // var_dump($res);
- }
- }
- if ($write_project_to_twx)
- {
- $proj = Project::Find($write_project_to_twx);
- if ($proj)
- {
- $res = $proj->checkPointsWrite();
- // echo "write_project_to_twx:" ;
- // var_dump($res);
- }
- }
- if ($pt_addseries)
- {
- $ptype = ProjectType::Find($pt_addseries);
- if ($ptype != null) {
- if (sizeof($ptype->series) > 0) {
- echo "<b>Доступные серии локомотивов:</b><br>";
- foreach ($ptype->series as $serie)
- echo "$serie->name<br>";
- }
- $serie = LocoSeries::Find($series);
- if ($serie) {
- $ptype->addSeries($serie);
- $ptype->Save();
- }
- }
- }
- if ($showseries)
- {
- /**
- * @var $ptype ProjectType
- */
- $ptype = ProjectType::Find($showseries);
- if ($ptype != null) {
- if (sizeof($ptype->series) > 0) {
- echo "<b>Добавленные серии локомотивов:</b><br>";
- foreach ($ptype->series as $serie)
- echo "$serie->name<br>";
- }
- $tts = $ptype->getTasktypes();
- if (sizeof($tts) > 0) {
- /**
- * @var $tt Tasktype
- */
- $letters = array();
- foreach ($tts as $tt) {
- if ($tt->letter != '' && !in_array($tt->letter, $letters)) {
- $letters[] = $tt->letter;
- }
- }
- sort($letters);
- if (sizeof($letters) > 0) {
- echo "<br><b>Введите субномера секций:</b><br>";
- foreach ($letters as $letter) {
- echo "$letter: <input id='letter$letter' type='number' min='0' max='99999999' name='$letter'><br>";
- }
- }
- }
- }
- }
- if ($getsectionlist)
- {
- require_once "api_getsectionlist.php";
- echo TWXrequest();
- }
- if (intval($delsection)> 0) {
- $section = Section::Find($delsection);
- if ($section) {
- if (sizeof($section->projects) == 0) {
- Section::Delete($delsection);
- echo "Section $delsection deleted!!";
- }
- else
- echo "Error: Section has projects";
- }
- }
- if ($getseries)
- {
- if ($getseries > 0)
- {
- $pt = ProjectType::Find($getseries);
- $series = $pt->series;
- }
- else
- $series = LocoSeries::GetAll();
- $arr = array();
- //$series = $getseries
- foreach ($series as $serie) {
- /**
- * @var $serie LocoSeries
- */
- $numsec = sizeof($serie->getSectionsWithUUID());
- $numproj = $serie->projectsAmount();
- $numsecall = sizeof($serie->sections);
- $arr[$serie->id] = array($serie->name, $numsec, $numsecall, $numproj);
- }
- echo json_encode($arr);
- }
- if ($addseries)
- {
- $serie = new LocoSeries();
- $serie->name = $addseries;
- $serie->Save();
- }
- /** @var string $addsections серия локомотива */
- /** @var int $number номер локомотива */
- /** @var int $subnumber номер секции */
- /** @var string $section_letter буква секции */
- if ($addsections)
- {
- $serie = LocoSeries::Find($addsections);
- if ($serie != null) {
- $section = new Section();
- $section->setSectionNumber($number);
- $section->setSectionSubnumber($subnumber);
- $section->setLetter($section_letter);
- $serie->addSection($section);
- $serie->Save();
- echo "Секция добавлена!";
- } else {
- echo "serie not found";
- }
- }
- if ($getsections)
- {
- // FindBySeries
- $arr = array();
- $ls = LocoSeries::Find($getsections);
- $sections = $ls->sections;
- // $sections = $ls->getSectionsWithUUID(true);
- // $sections = Section::FindBySeries($getsections, true);
- // $array = $hydrator->extract($data);
- foreach ($sections as $section) {
- $section->projectsAmount = sizeof($section->projects);
- array_push($arr, $section->toArray());
- }
- // echo sizeof($arr);
- echo json_encode($arr);
- // var_dump($arr);
- // echo "Get Sections!! $section";
- }
- if ($getsectioncontent)
- {
- $section = Section::Find($getsectioncontent);
- $retarr = array();
- if ($section != null)
- {
- // $section->diagnostic_maps = $section->diagnostic_maps->toArray();
- // $proj = $section->project;
- $projIds = array();
- foreach ($section->projects as $p)
- {
- array_push($projIds, $p->id);
- }
- $section->test = $projIds;
- array_push($retarr,$section->toArray());
- array_push($retarr,$section->diagnostic_maps->toArray());
- array_push($retarr,$projIds);
- // echo "DK: ".sizeof($section->diagnostic_maps);
- echo json_encode($retarr);
- //echo json_encode($section->toArray());
- //echo json_encode($section->diagnostic_maps->toArray());
- }
- }
|