function store() { global $AppUI; // Update the last modified time and user $this->item_modified = db_unix2dateTime(time()); $this->item_summary = strip_tags($this->item_summary); //if type indicates a contact or a user, then look up that phone and email //for those entries switch ($this->item_requestor_type) { case '0': //it's not a user or a contact break; case '1': //it's a system user $sql = "SELECT user_id as id,\n contact_email as email,\n contact_phone as phone,\n CONCAT(contact_first_name,' ', contact_last_name) as name\n FROM users\n LEFT JOIN contacts ON user_contact = contact_id\n WHERE user_id='{$this->item_requestor_id}'"; break; case '2': $sql = "SELECT contact_id as id,\n contact_email as email,\n contact_phone as phone,\n CONCAT(contact_first_name,' ', contact_last_name) as name\n FROM contacts\n WHERE contact_id='{$this->item_requestor_id}'"; break; default: break; } if (isset($sql)) { db_loadHash($sql, $result); $this->item_requestor_email = $result['email']; $this->item_requestor_phone = $result['phone']; $this->item_requestor = $result['name']; } /* if the store is successful, pull the new id value and insert it into the object. */ if ($msg = parent::store()) { return $msg; } else { if (!$this->item_id) { $this->item_id = mysql_insert_id(); } return $msg; } }
$orrarr[] = array('task_id' => 0, 'order_up' => 0, 'order' => ''); $end_max = '0000-00-00 00:00:00'; $start_min = date('Y-m-d H:i:s'); //pull the tasks into an array foreach ($proTasks as $rec) { if ($rec['task_start_date'] == '0000-00-00 00:00:00') { $rec['task_start_date'] = date('Y-m-d H:i:s'); } $tsd = new w2p_Utilities_Date($rec['task_start_date']); if ($tsd->before(new w2p_Utilities_Date($start_min))) { $start_min = $rec['task_start_date']; } // calculate or set blank task_end_date if unset if ($rec['task_end_date'] == '0000-00-00 00:00:00') { if ($rec['task_duration']) { $rec['task_end_date'] = db_unix2dateTime(db_dateTime2unix($rec['task_start_date']) + SECONDS_PER_DAY * convert2days($rec['task_duration'], $rec['task_duration_type'])); } else { $rec['task_end_date'] = ''; } } $ted = new w2p_Utilities_Date($rec['task_end_date']); if ($ted->after(new w2p_Utilities_Date($end_max))) { $end_max = $rec['task_end_date']; } $projects[$rec['task_project']]['tasks'][] = $rec; } $q->clear(); reset($projects); foreach ($projects as $p) { $tnums = count($p['tasks']); for ($i = 0; $i < $tnums; $i++) {
$task->setAllowedSQL($AppUI->user_id, $q); $proTasks = $q->loadHashList('task_id'); $q->clear(); $orrarr[] = array('task_id' => 0, 'order_up' => 0, 'order' => ''); $end_max = '0000-00-00 00:00:00'; $start_min = date('Y-m-d H:i:s'); //pull the tasks into an array $criticalTasks = $project->getCriticalTasks($project_id); $actual_end_date = new CDate($criticalTasks[0]['task_end_date']); $p_end_date = $actual_end_date->after($project->project_end_date) ? $criticalTasks[0]['task_end_date'] : $project->project_end_date; foreach ($proTasks as $row) { // calculate or set blank task_end_date if unset if ($row['task_end_date'] == '0000-00-00 00:00:00') { if ($row['task_duration'] && $row['task_start_date'] != '0000-00-00 00:00:00') { $start_date_unix_time = db_dateTime2unix($row['task_start_date']) + SECONDS_PER_DAY * convert2days($row['task_duration'], $row['task_duration_type']); $row['task_end_date'] = substr(db_unix2dateTime($start_date_unix_time), 1, -1); } else { $row['task_end_date'] = $p_end_date; } } if ($row['task_start_date'] == '0000-00-00 00:00:00') { $row['task_start_date'] = $project->project_start_date; //date('Y-m-d H:i:s'); } if ($row['task_start_date'] == '0000-00-00 00:00:00') { $row['task_start_date'] = date(mktime(0, 0, 0, 1, 1, date('Y')), 'Y-m-d H:i:s'); } $tsd = new CDate($row['task_start_date']); if ($tsd->before(new CDate($start_min))) { $start_min = $row['task_start_date']; }
function fixate_task($task_index, $time, $dep_on_task) { // WARNING: task_index != task_id !!! global $tasks, $do, $option_advance_if_possible, $AppUI, $df; // don't fixate tasks before now if ($time < time()) { $time = time(); } $start_date = $time; $end_date = $start_date; $durn = convert2days($tasks[$task_index]["task_duration"], $tasks[$task_index]["task_duration_type"]); $end_date += $durn * SECONDS_PER_DAY; // Complex SQL explanation: // // Objective: Check tasks overlapping only when // a user is vital for both tasks // // Definition of "vital for one task": when a task is assigned to user and total_users <= 2 // (for example: if task is assigned to tree o more users, he is not vital). // // Thus, a user is vital for both tasks <=> // - total_users <= 2 for both tasks // - and he apears in both tasks // // Thus, in both tasks (say 4 and 10), a there will be a vital user <=> // - "number of tasks with total_users <= 2" // = rows("select count(*) as num_users from user_tasks // where task_id=4 or task_id=10 // group by task_id having num_users <= 2") == 2; // // - and "number of users which appears in both tasks" // = rows("select count(*) as frec // from user_tasks where task_id=4 or task_id=10 // group by user_id having frec = 2") > 0 $t1_start = $start_date; $t1_end = $end_date; foreach ($tasks as $task2) { $t2_start = db_dateTime2unix($task2["task_start_date"]); $t2_end = db_dateTime2unix($task2["task_end_date"]); if ($task2["fixed"] && ($t1_start >= $t2_start && $t1_start <= $t2_end || $t1_end >= $t2_start && $t1_end <= $t2_end)) { // tasks are overlapping if (!$option_advance_if_possible || $task2["task_percent_complete"] != 100) { $t1 = $tasks[$task_index]["task_id"]; $t2 = $task2["task_id"]; if ($option_check_vital_users) { $sql1 = "select count(*) as num_users from user_tasks where task_id={$t1} or task_id={$t2} group by task_id having num_users <= 2"; $sql2 = "select count(*) as frec from user_tasks where task_id={$t1} or task_id={$t2} group by user_id having frec = 2"; $vital = mysql_num_rows(mysql_query($sql1)) == 2 && mysql_num_rows(mysql_query($sql2)) > 0; } else { $vital = true; } if ($vital) { log_info("Task can't be set to [" . formatTime($start_date) . " - " . formatTime($end_date) . "] due to conflicts with task " . task_link($task2) . "."); // OBS: I'm asuming the dependent task will start next day fixate_task($task_index, $t2_end + SECONDS_PER_DAY, $dep_on_task); return; } else { log_info("Task conflicts with task " . task_link($task2) . " but there are no vital users."); } } else { log_info("Task " . task_link($task2) . " is complete, I won't check if it is overllaping"); } } } $tasks[$task_index]["fixed"] = true; // be quite if nothing changes if (db_dateTime2unix($tasks[$task_index]["task_start_date"]) == $start_date && db_dateTime2unix($tasks[$task_index]["task_end_date"]) == $end_date) { log_info("Nothing changed, still programmed for [" . formatTime($start_date) . " - " . formatTime($end_date) . "]"); return; } $tasks[$task_index]["task_start_date"] = db_unix2dateTime($start_date); $tasks[$task_index]["task_end_date"] = db_unix2dateTime($end_date); if ($do == "ask") { if ($dep_on_task) { log_action("I will fixate task " . task_link($tasks[$task_index]) . " to " . formatTime($start_date) . " (depends on " . task_link($dep_on_task) . ")"); } else { log_action("I will fixate task " . task_link($tasks[$task_index]) . " to " . formatTime($start_date) . " (no dependencies)"); } // echo "<input type=hidden name=fixate_task[" . $tasks[$task_index]["task_id"] . "] value=y>"; } else { if ($do == "fixate") { log_action("Task " . task_link($tasks[$task_index]) . " fixated to " . formatTime($start_date)); $sql = "update tasks set task_start_date = '" . db_unix2dateTime($start_date) . "', task_end_date = '" . db_unix2dateTime($end_date) . "' where task_id = " . $tasks[$task_index]["task_id"]; mysql_query($sql); } } }
$tsql = "SELECT {$select} FROM {$from} {$join} WHERE {$where} ORDER BY project_id, task_start_date"; ##echo "<pre>$tsql</pre>".mysql_error();## $ptrc = db_exec($tsql); $nums = db_num_rows($ptrc); echo db_error(); $orrarr[] = array("task_id" => 0, "order_up" => 0, "order" => ""); //pull the tasks into an array for ($x = 0; $x < $nums; $x++) { $row = db_fetch_assoc($ptrc); if ($row["task_start_date"] == "0000-00-00 00:00:00") { $row["task_start_date"] = date("Y-m-d H:i:s"); } // calculate or set blank task_end_date if unset if ($row["task_end_date"] == "0000-00-00 00:00:00") { if ($row["task_duration"]) { $row["task_end_date"] = db_unix2dateTime(db_dateTime2unix($row["task_start_date"]) + SECONDS_PER_DAY * convert2days($row["task_duration"], $row["task_duration_type"])); } else { $row["task_end_date"] = ""; } } $projects[$row['task_project']]['tasks'][] = $row; } $width = dPgetParam($_GET, 'width', 600); //consider critical (concerning end date) tasks as well $project_end = $projects[$project_id]["project_end_date"] > $criticalTasks[0]['task_end_date'] ? $projects[$project_id]["project_end_date"] : $criticalTasks[0]['task_end_date']; $start_date = dPgetParam($_GET, 'start_date', $projects[$project_id]["project_start_date"]); $end_date = dPgetParam($_GET, 'end_date', $project_end); $count = 0; $graph = new GanttGraph($width); $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK); //$graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY);