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];
$project_id = \Yii::$app->request->get('project_id');
$projEntity = \app\models\entity\ProjectsLocotech::findOne(['id' => $project_id]);
//$taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $project_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC,'type'=> SORT_ASC,'text'=> SORT_ASC])->all();
$taskEntity = \app\models\entity\Tasks::find()->where(['input_id' => $project_id])->orderBy(['parent_id' => SORT_ASC,'priority'=> SORT_ASC])->all();
$arrayTest = explode(',',$projEntity->tasks);
$priorityarray = [];
$count = 1;
foreach ( $arrayTest as $m ) {
$priorityarray[$count * 1000] = $m;
$count++;
}
$priorityarray = array_flip($priorityarray);
//var_dump($priorityarray);
$data = '{
"data": [';
$currentTime = strtotime(date("Y-m-d H:i:s"));
$start_date = $currentTime;
$tempArrayForTasks = [];
$tempArrayDuringForTasks = [];
$parent_id = '';
$tempArrayForStartTime = [];
$start_date_str = date ( "d-m-Y H:i",$currentTime );
$tempArrayCountDuringForTasks = [];
$tempArrayDuringForTasksPlus = [];
$progress = 0;
$counter = 0;
foreach ( $taskEntity as $task ) {
$duration = $task->tasktypes->time_to_complete_minutes;
$tempArrayDuringForTasks[$task->parent_id][] = $duration;
}
foreach( $tempArrayDuringForTasks as $key => &$a) {
$tempArrayDuringForTasks[$key] = array_sum($a)*60;
}
$e = 0;
foreach ( $taskEntity as $task ) {
$text = \app\models\HelperModel::stripWhitespaces($task->text);
$readonly = 'true';
if ( (null != $task->created) and (null == $task->accepted_time) and (null == $task->finished_time) ) {
$readonly = 'false';
}
if ( 0 == $task->parent_id) {//echo "
";
preg_match('/#(.*)#/', $text, $matches);
$id_job = $matches[1];
if ( null == $tempArrayDuringForTasksPlus[$id_job]) {
$tempArrayForStartTime[$task->id] = 0;
} else {
$tempArrayForStartTime[$task->id] += $tempArrayDuringForTasksPlus[$id_job]/60;
}
if ( null != $task->accepted_time && null == $task->finished_time){
$start_date_str = date ( "d-m-Y H:i",strtotime($task->accepted_time) );
}
} else {
$start_date = $currentTime + ($tempArrayForStartTime[$task->parent_id] * 60 );
$start_date_str = date ( "d-m-Y H:i",$start_date );
if ( null != $task->finished_time ){
$start_date_str = date ( "d-m-Y H:i",strtotime($task->accepted_time) );
}
if ( null != $task->accepted_time && null == $task->finished_time){
$start_date_str = date ( "d-m-Y H:i",strtotime($task->accepted_time) );
}
//var_dump($tempArrayForStartTime[$task->parent_id]);
$tempArrayForStartTime[$task->parent_id] += $task->tasktypes->time_to_complete_minutes;
}
if ( 0 != $task->parent_id) {
$parent_id = ', "parent": "'.$task->parent_id.'"';
}
switch ($task->status) {
case 5:
$progress = 1.0;
break;
case 1:
$progress = 0.0;
break;
default:
$progress = 0.5;
break;
}
$start_finish_time = '';
$duration = $task->tasktypes->time_to_complete_minutes;
if ( null != $task->accepted_time ){
$start_finish_time = '/' . date ('H:i' , strtotime($task->accepted_time));
}
if ( 'true' === $readonly ) {
$start_finish_time = '/' . date ('H:i' , strtotime($task->accepted_time)). ' - ' . date ('H:i' , strtotime($task->finished_time));
}
// ЕСЛИ ККОМАНДА ЗАВЕРШЕНА НАЧАЛО
if ( null != $task->finished_time ){
$duration_sec = strtotime($task->finished_time) - strtotime($task->accepted_time);
$duration = floor($duration_sec/60);
}
// ЕСЛИ ККОМАНДА ЗАВЕРШЕНА КОНЕЦ
// ЕСЛИ ККОМАНДА ВЫПОЛНЯЕТСЯ НО НЕ ЗАВЕРШЕНА НАЧАЛО
if ( null != $task->accepted_time && null == $task->finished_time){
$duration_sec = $currentTime - strtotime($task->accepted_time);
$duration = floor($duration_sec/60);
}
// ЕСЛИ ККОМАНДА ВЫПОЛНЯЕТСЯ НО НЕ ЗАВЕРШЕНА КОНЕЦ
if ( 0 == $task->parent_id) {
preg_match('/#(.*)#/', $text, $matches);
$id_job = $matches[1];
$query = 'SELECT min(coalesce(accepted_time, NOW())) as time FROM tasks WHERE parent_id = ' . $task->id;
$res = \Yii::$app->db->createCommand($query)->queryOne();
$timeCompare = $start_date_str = date ('d-m-Y H:i' , strtotime($res['time']));
$start_date_str = date ('d-m-Y H:i' ,strtotime($start_date_str)+$tempArrayCountDuringForTasks[$id_job]);
if(strtotime($timeCompare) == (strtotime($start_date_str)+$tempArrayCountDuringForTasks[$id_job])) {
$prior[$id_job] = $priorityarray[$task->id];
//var_dump($prior[$id_job], '$priorityarray['.$task->id.']'); echo "
";
} else {//echo $prior[$task->id];
$prior[$id_job] += 100;
//var_dump($prior[$id_job], '$priorityarray['.$task->id.']');
}
//var_dump($task->id);
//var_dump($id_job, $prior[$id_job],$task->id,$priorityarray[$task->id]); echo "
";
$priorParent[$task->id] = $prior[$id_job];
$tempArrayCountDuringForTasks[$id_job] += $tempArrayDuringForTasks[$task->id];
$tempArrayDuringForTasksPlus[$id_job] = $tempArrayCountDuringForTasks[$id_job];
// ЕСЛИ ККОМАНДА ЗАВЕРШЕНА НАЧАЛО
$oneTaskEntity = \app\models\entity\Tasks::find()->where(['parent_id' => $task->id])->orderBy(['priority'=> SORT_ASC ])->all();
$Finished = false;
$Accepted = false;
foreach( $oneTaskEntity as $one) {
if ( 1 == $one->priority ){
$Accepted = $one->accepted_time;
}
$Finished = $one->finished_time;
}
if ( null != $Finished and null != $Accepted ){
$duration_sec = strtotime($Finished) - strtotime($Accepted);
$duration = floor($duration_sec/60);
}
if ( null != $Accepted ){
$start_date_str = date ( "d-m-Y H:i",strtotime($Accepted) );
}
// ЕСЛИ ККОМАНДА ЗАВЕРШЕНА КОНЕЦ
} else {
$prior[$id_job] = $priorParent[$task->parent_id] + $task->priority;
}
//var_dump($prior[$id_job], $task->id);
$text = preg_replace('/#(.*)#/', '', $text);
$text = preg_replace('/([0-9]|[0-9][0-9])\/[АБВГ](.*)$/u', '', $text);
if ( 0 != $task->parent_id && 0 != $task->assignees_arr) {
$accountsEntity = \app\models\entity\Accounts::findOne($task->assignees_arr);
$text = $accountsEntity->name;
}
//echo " |name=". $task->id."=>".$prior[$id_job]." |" ;
$tasktypesName = \app\models\HelperModel::stripWhitespaces($task->tasktypes->name);
$tasktypesName = addslashes($tasktypesName);
//echo $priorityarray[$task->id].'-';
$prior[$id_job] = sprintf("%08d", $prior[$id_job]);
$tempArrayForTasks[$id_job][] = '{ "id": ' . $task->id . ', "calendar_id": "global", "text": " ' . $tasktypesName . ':' . $text . ''.$start_finish_time.' ", "type": "project", "start_date": "' . $start_date_str . '", "duration": "' . $duration . '","progress": '.$progress.', "open": true, "readonly" : '.$readonly.$parent_id.',"sort": "'.$prior[$id_job].'"}';
$counter++;
//$prior = '';
}
foreach( $tempArrayForTasks as &$items){
$items = implode(',', $items);
}
ksort($tempArrayForTasks);
$data .= implode(',', $tempArrayForTasks);
$data .= '],
"links": []
}';
?>