123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <?php
- defined('YII_DEBUG') or define('YII_DEBUG', true);
- defined('YII_ENV') or define('YII_ENV', 'dev');
- require __DIR__ . '/api/vendor/autoload.php';
- require __DIR__ . '/api/vendor/yiisoft/yii2/Yii.php';
- $config = require __DIR__ . '/api/config/web.php';
- (new yii\web\Application($config));
- require_once "doctrine/bootstrap.php";
- include 'CheckPoint.php';
- include 'CheckPointType.php';
- use CheckPoints\CheckPoint;
- use CheckPointTypes\CheckPointType;
- header("Expires: 0");
- header("Content-Type: text/html; charset=utf-8");
- session_start();
- if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 6000)) {
- // last request was more than 30 minutes ago
- session_unset(); // unset $_SESSION variable for the run-time
- session_destroy(); // destroy session data in storage
- }
- $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
- $add = 'Login Area';
- foreach (array_keys($_REQUEST) as $var) {
- ${$var} = $_REQUEST[$var];
- //if ($name == "Admin12") {
- // echo "<b>$var:</b> ${$var} <br>";
- //}
- }
- if ($act == "exit")
- {
- session_unset();
- session_destroy();
- session_start();
- }
- if ($_SESSION['cmdlevel'])
- $cmdlevel = $_SESSION['cmdlevel'];
- if ($_SESSION['hostid'])
- $agent_id = $_SESSION['hostid'];
- if ($_SESSION['add'])
- $add = $_SESSION['add'];
- if ($_SESSION['id'])
- $id = $_SESSION['id'];
- if ($_SESSION['login'])
- $login = $_SESSION['login'];
- if ($_SESSION['name'])
- $name = $_SESSION['name'];
- foreach (array_keys($_SESSION) as $var) {
- ${$var} = $_SESSION[$var];
- //if ($name == "Admin12") {
- //echo "from session: <b>$var:</b> ${$var} <br>";
- //}
- }
- include 'functions.php';
- include 'auth.php';
- $logged_me_in_successfully234 = 0;
- $incl = '';
- if (!$_SESSION['pass'] && !$_SESSION['login'])
- {
- $table = 'accounts';
- $result=mysqli_query($link, "SELECT id, login, name, cmdlevel FROM $table WHERE login='".$login."' AND password='".md5($pass)."'");
- $res1 = mysqli_fetch_array($result);
- $cmdlevel = $res1['cmdlevel'];
- $name = $res1['name'];
- $id = $res1['id'];
- if ($cmdlevel == '10')
- {
- $add = "Head Administrator";
- }
- else if ($cmdlevel == '1')
- {
- $add = "Company Administrator";
- }
- else if ($cmdlevel == '2')
- {
- $add = "Company Operator";
- }
- if (mysqli_num_rows($result))
- {
- $_SESSION['pass']=$pass;
- $_SESSION['login']=$login;
- $_SESSION['name']=$name;
- $_SESSION['add']=$add;
- $_SESSION['cmdlevel']=$cmdlevel;
- $_SESSION['id']=$id;
- $logged_me_in_successfully234 = 1;
- }
- }
- else
- $logged_me_in_successfully234 = 1;
- $query = mysqli_query($link, "update accounts set last_seen_web =NOW() where id=".$id);
- $getincl = GetInclude($act, intval($cmdlevel));
- $incl = $getincl[0];
- $accnum = $getincl[1];
- // ДОБАВЛЕНИ НОВОГО ПРОЕКТА
- if ( isset($loco_seria) and isset($typefix) and '' == $get_param){
- $marker = 0;
- $count = 1;
- $arr = [];
- $tempArray = [];
- $post = \Yii::$app->request->post();
- $asusgProjectEntity = new \app\models\entity\AsusgProject();
- $errorArr = [];
-
- foreach ($post as $key => $item) {
-
- $marker = explode("-",$key);
-
- if ( 4 > strlen($marker[0])) {
- $arr[$marker[0]][] = $item;
- } else {
- $tempArray[$marker[0]] = $item;
- }
- }
-
- $asusgProjectEntity->loco_serie_id = $tempArray["loco_seria"];
- $asusgProjectEntity->repair_type = explode('_',$tempArray['typefix'])[0];
- $asusgProjectEntity->loco_number = $tempArray["loco_number"];
- /*$asusgProjectEntity->section_a = $tempArray["section_a"];
- $asusgProjectEntity->section_b = $tempArray["section_b"];
- $asusgProjectEntity->section_c = $tempArray["section_c"];*/
- $asusgProjectEntity->order_a = $tempArray["section_a"];
- $asusgProjectEntity->order_b = $tempArray["section_b"];
- $asusgProjectEntity->order_c = $tempArray["section_c"];
-
- $asusgProjectEntity->save();
- if ( !empty($asusgProjectEntity->errors)) {
- $errorArr[] = $asusgProjectEntity->errors;
- }
-
-
- $counter_order = 1;
-
- foreach ($arr as $key => $item) {
- $asusgJob2LaunchEntity = new \app\models\entity\AsusgJob2Launch();
- $asusgJob2LaunchEntity->asusg_project_id = (int)$asusgProjectEntity->id;
- $asusgJob2LaunchEntity->asusg_jobplan_id = (int)$item[0];
- $asusgJob2LaunchEntity->asusg_employee_id1 = (int)$item[1];
- $asusgJob2LaunchEntity->asusg_employee_id2 = (int)$item[3];
- $asusgJob2LaunchEntity->asusg_employee_id3 = (int)$item[5];
-
- $asusgJob2LaunchEntity->jobtype_id1 = (int)$item[2];
- $asusgJob2LaunchEntity->jobtype_id2 = (int)$item[4];
- $asusgJob2LaunchEntity->jobtype_id3 = (int)$item[6];
-
- $asusgJob2LaunchEntity->job_order = $counter_order;
- $asusgJob2LaunchEntity->save();
- if ( !empty($asusgJob2LaunchEntity->errors)) {
- $errorArr[] = $asusgJob2LaunchEntity->errors;
- }
- $counter_order++;
- }
-
- if ( empty($errorArr) ){
- $errorArr = [0 => true, 'id' => (int)$asusgProjectEntity->id];
- }
-
- echo json_encode($errorArr);
- }
- // РЕДАКТИРОВАНИЕ ПРОЕКТА
- if ( '' != $get_param){
- $errorArr = [];
-
- $marker = 0;
- $count = 1;
- $arr = [];
- $tempArray = [];
- $post = \Yii::$app->request->post();
- $asusgProjectEntity = \app\models\entity\AsusgJob2Launch::find()->where(['asusg_project_id' => $get_param])->orderBy(['id' => SORT_ASC])->all();
-
-
- foreach ($post as $key => $item) {
- $marker = explode("-",$key);
- if ( 4 > strlen($marker[0])) {
- $arr[$marker[0]][] = $item;
- } else {
- $tempArray[$marker[0]] = $item;
- }
- }
- $counter_order = 1;
- $tempArray1 = [];
- $tempArray2 = [];
- foreach($asusgProjectEntity as $item) {
- $tempArray1[] = ['job_order' => $item->job_order,'asusg_jobplan_id' => $item->asusg_jobplan_id];
-
- }
- foreach ($arr as $key => $item) {
- $tempArray2[] = ['job_order' => $counter_order,'asusg_jobplan_id' => (int)$item[0]];
- $counter_order++;
- }
- $tempArray1 = json_encode($tempArray1);
- $tempArray2 = json_encode($tempArray2);
- $counter_order = 1;
- if ( 0 != strcmp($tempArray1,$tempArray2)) {
-
- $asusgProjectEntity2 = \app\models\entity\AsusgProject::findOne(['id' => $get_param]);
- if ( 1 == $asusgProjectEntity2->status ) {
- \app\models\entity\AsusgJob2Launch::deleteAll(['asusg_project_id' => $get_param]);
- }
-
- foreach ($arr as $key => $item) {
- $asusgJob2LaunchEntity = new \app\models\entity\AsusgJob2Launch();
- $asusgJob2LaunchEntity->asusg_project_id = (int)$get_param;
- $asusgJob2LaunchEntity->asusg_jobplan_id = (int)$item[0];
- $asusgJob2LaunchEntity->asusg_employee_id1 = (int)$item[1];
- $asusgJob2LaunchEntity->asusg_employee_id2 = (int)$item[3];
- $asusgJob2LaunchEntity->asusg_employee_id3 = (int)$item[5];
-
- $asusgJob2LaunchEntity->jobtype_id1 = (int)$item[2];
- $asusgJob2LaunchEntity->jobtype_id2 = (int)$item[4];
- $asusgJob2LaunchEntity->jobtype_id3 = (int)$item[6];
- $asusgJob2LaunchEntity->job_order = $counter_order;
- $rrrr[] = $asusgJob2LaunchEntity->attributes;
- $asusgJob2LaunchEntity->save();
- if ( !empty($asusgJob2LaunchEntity->errors)) {
- $errorArr[] = $asusgJob2LaunchEntity->errors;
- }
- $counter_order++;
- }
-
- }
-
- if ( empty($errorArr) ){
- $errorArr = [0 => true,'id' => $get_param];
- }
-
- echo json_encode($errorArr);
- }
- // ЗАПУСК ПРОЕКТА
- if ( isset($user_id_gogo) and isset($id_proj_gogo) ) {
- $arr = ['initiator' => (int)$user_id_gogo, 'project_id' => (int)$id_proj_gogo];
- $res = \Yii::$app->db->createCommand('call asusg_build_and_start_project('.$arr["initiator"].','.$arr["project_id"].')')->execute();// queryOne();
- echo json_encode($res);
- }
- if ( isset($arrayGantTasks) ) {
- $input_id = 0;
- $arrayGantTasks = json_decode($arrayGantTasks);
- $flag = true;
- $arrayPriorityPos = [];
- foreach( $arrayGantTasks as $task ) {
- if ( $flag ){
-
- $arraycheckChange = checkChange($task->input_id,$arrayGantTasks);
-
- $arrayPriorityPos = getMapForPriority($task->input_id);
- foreach($arraycheckChange as $key => $task2) {
- global $id;
- $query = "call `asusg_change_parent_task`( ".$id.",".$key.",".$task2.")";
- $re = mysqli_query($link, $query);
- }
- $flag = false;
- }
-
- if ( 0 == $task->parent ){continue;}
- //var_dump($task);
- $input_id = $task->input_id;
- $priority = $arrayPriorityPos['pos'][$task->parent] + $task->position;
- if ( 5 == $arrayPriorityPos['status'][$task->id]) {continue;}
- $stringParam = '`parent_id`= ' . $task->parent .', `priority`='. $priority .' ';
- $query = 'UPDATE `tasks` SET ' . $stringParam . ' WHERE `id`=' . $task->id ;
- //echo $task->id.'=>'.$task->parent ; echo "<br>";
- mysqli_query($link, $query);
- }
- //call asusg_change_parent_task( initiator integer,task_id integer,parent_task integer);
- echo 'true';
-
-
- }
- if (isset($tasks_id_map)){
- $tasks_id_map = (int)$tasks_id_map;
- $res = \Yii::$app->db->createCommand('SELECT `asusg_job_mapped_id` FROM `tasks` WHERE `id` =' . $tasks_id_map)->queryOne();
- $res = \Yii::$app->db->createCommand('SELECT `id` FROM `tasks` WHERE `asusg_job_mapped_id` =' . $res['asusg_job_mapped_id'])->queryAll();
- echo json_encode($res);
- }
- //var_dump(getMapForPriority(2881)_;
- function getMapForPriority($project_id = null ) {
-
- if ( null == $project_id) {
- return [];
- }
- $taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $project_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC])->all();
- $arr = [];
- $arrayStatus = [];
- $resultPos = [];
- $result = [];
- foreach( $taskEntity as $task){
- if ( 0 == $task->parent_id ) { continue;}
- $arr[$task->parent_id][] = ['priority' => $task->priority, 'status' => $task->status];
- $arrayStatus[$task->id] = $task->status;
- }
- foreach($arr as $key => $arr2){
- $pos = 0;
- foreach ( $arr2 as $it) {
-
- if ( 5 == $it['status'] ){
- $pos = $it['priority'];
- }
- }
- $resultPos[$key] = $pos;
- }
-
- //echo "<pre>";
- // var_dump($arr);
- //echo "</pre>";
- return $result = ['pos' => $resultPos, 'status' => $arrayStatus,'taskEntity' => $taskEntity];
- /**/
- }
- function checkChange($proj_id,$gantTasks){
-
- $result = [];
- $taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $proj_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC])->all();
- $data = [];
- $data = yii\helpers\ArrayHelper::toArray($taskEntity, ['app\models\entity\Tasks' => ['id','parent_id']]);
- $tmpArray = [];
- foreach( $data as $task){
- $tmpArray[$task['id']] = $task['parent_id'];
- }
- foreach( $gantTasks as $task2){
- if ( $tmpArray[$task2->id] != $task2->parent) {
- $result[$task2->id] = $task2->parent;
- }
- }
- return $result ;
- }
- ?>
|