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 "$var: ${$var}
";
//}
}
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: $var: ${$var}
";
//}
}
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 "
";
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 "
"; // var_dump($arr); //echo ""; 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 ; } ?>