$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 = new CTask(); $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 process_dependencies($i) { global $tasks, $option_advance_if_possible; if ($tasks[$i]["fixed"]) { return; } log_info("<div style='padding-left: 1em'>Dependecies for '" . $tasks[$i]["task_name"] . "':<br />"); // query dependencies for this task $query = mysql_query("select tasks.* from tasks,task_dependencies where task_id=dependencies_req_task_id and dependencies_task_id=" . $tasks[$i]["task_id"]); if (mysql_num_rows($query) != 0) { $all_fixed = true; $latest_end_date = null; // store dependencies in an array (for adding more entries on the fly) $dependencies = array(); while ($row = mysql_fetch_array($query)) { array_push($dependencies, $row); } $d = 0; while ($d < count($dependencies)) { $row = $dependencies[$d]; $index = search_task($row["task_id"]); if ($index == -1) { // task is not listed => it's a task group // => $i depends on all its subtasks // => add all subtasks to the dependencies array log_info("- task '" . $row["task_name"] . "' is a task group (processing subtask's dependencies)"); $children = get_last_children($row); // replace this taskgroup with all its subtasks array_splice($dependencies, $d, 1, $children); continue; } log_info(" - '" . $tasks[$index]["task_name"] . ($tasks[$index]["fixed"] ? " (FIXED)" : "") . "'"); // TODO: Detect dependencies loops (A->B, B->C, C->A) process_dependencies($index); if (!$tasks[$index]["fixed"]) { $all_fixed = false; } else { // ignore dependencies of finished tasks if option is enabled if (!$option_advance_if_possible || $tasks[$index]["task_percent_complete"] != 100) { // get latest end_date $end_date = db_dateTime2unix($tasks[$index]["task_end_date"]); if (!$latest_end_date || $end_date > $latest_end_date) { $latest_end_date = $end_date; $dep_on_task = $row; } } else { log_info("this task is complete => don't check dependency"); } $d++; } } if ($all_fixed) { // this task depends only on fixated tasks log_info("all dependencies are fixed"); fixate_task($i, $latest_end_date, $dep_on_task); } else { log_error("task has not fixed dependencies"); } } else { // task has no dependencies log_info("no dependencies => "); fixate_task($i, time(), ""); } log_info("</div><br />\n"); }
function upgrade($old_version) { $success = 1; switch ($old_version) { case "0.1": // Drop unused columns, add some new columns $bulk_sql[] = "\n ALTER TABLE `helpdesk_items`\n ADD `item_requestor_phone` varchar(30) NOT NULL default '' AFTER `item_requestor_email`,\n ADD `item_company_id` int(11) NOT NULL default '0' AFTER `item_project_id`,\n ADD `item_requestor_type` tinyint NOT NULL default '0' AFTER `item_requestor_phone`,\n ADD `item_notify` int(1) DEFAULT '1' NOT NULL AFTER `item_assigned_to`,\n ADD `item_created_by` int(11) NOT NULL default '0',\n\t\t ADD `item_updated` datetime default NULL,\n DROP `item_receipt_target`,\n DROP `item_receipt_custom`,\n DROP `item_receipted`,\n DROP `item_resolve_target`,\n DROP `item_resolve_custom`,\n DROP `item_resolved`,\n DROP `item_assetno`\n "; // Add help desk item id to task log table $bulk_sql[] = "\n ALTER TABLE `task_log`\n ADD `task_log_help_desk_id` int(11) NOT NULL default '0' AFTER `task_log_task`\n "; // Add help desk item status log table $bulk_sql[] = "\n CREATE TABLE `helpdesk_item_status` (\n `status_id` INT NOT NULL AUTO_INCREMENT,\n `status_item_id` INT NOT NULL,\n `status_code` TINYINT NOT NULL,\n `status_date` TIMESTAMP NOT NULL,\n `status_modified_by` INT NOT NULL,\n `status_comment` TEXT DEFAULT '',\n PRIMARY KEY (`status_id`)\n )\n "; // Execute the above SQL foreach ($bulk_sql as $s) { db_exec($s); if (db_error()) { $success = 0; } } // Add audit trail to system values $sql = "SELECT syskey_id\n FROM syskeys\n WHERE syskey_name = 'HelpDeskList'"; $syskey_id = db_loadResult($sql); $sv = new CSysVal($syskey_id, 'HelpDeskAuditTrail', "0|Created\n1|Title\n2|Requestor Name\n3|Requestor E-mail\n4|Requestor Phone\n5|Assigned To\n6|Notify by e-mail\n7|Company\n8|Project\n9|Call Type\n10|Call Source\n11|Status\n12|Priority\n13|Severity\n14|Operating System\n15|Application\n16|Summary\n17|Deleted"); $sv->store(); // Update help desk status values $sql = "UPDATE sysvals\n SET sysval_value='0|Unassigned\n1|Open\n2|Closed\n3|On Hold\n4|Testing'\n WHERE sysval_title='HelpDeskStatus'\n LIMIT 1"; db_exec($sql); /* Get data for conversion update */ $sql = "SELECT item_id,item_requestor_id,item_created,item_project_id\n FROM helpdesk_items"; $items = db_loadList($sql); /* Populate the status log table with the item's creation date */ foreach ($items as $item) { $timestamp = date('Ymdhis', db_dateTime2unix($item['item_created'])); $sql = "INSERT INTO helpdesk_item_status\n (status_item_id,status_code,status_date,status_modified_by)\n VALUES ({$item['item_id']},0,'{$timestamp}',\n {$item['item_requestor_id']})"; db_exec($sql); } /* Figure out the company for each item based on project id or based on requestor id */ foreach ($items as $item) { if ($item['item_project_id']) { $sql = "SELECT project_company\n FROM projects\n WHERE project_id='{$item['item_project_id']}'"; $company_id = db_loadResult($sql); } else { if ($item['item_requestor_id']) { $sql = "SELECT user_company\n FROM users\n WHERE user_id='{$item['item_requestor_id']}'"; $company_id = db_loadResult($sql); } } if ($company_id) { $sql = "UPDATE helpdesk_items\n SET item_company_id='{$company_id}'\n WHERE item_id='{$item['item_id']}'"; db_exec($sql); } } // If our status was 5 (Testing), now it is 4 (Testing) $sql = "UPDATE helpdesk_items\n SET item_status='4'\n WHERE item_status='5'"; db_exec($sql); break; case 0.2: // Version 0.3 features new permissions $success = 1; break; case 0.3: // Version 0.31 includes new watchers functionality $sql = "\n\t\tCREATE TABLE helpdesk_item_watchers (\n\t\t `item_id` int(11) NOT NULL default '0',\n\t\t `user_id` int(11) NOT NULL default '0',\n\t\t `notify` char(1) NOT NULL default ''\n\t\t) TYPE=MyISAM"; db_exec($sql); case 0.31: $sql = "\n ALTER TABLE `helpdesk_items`\n\t\t ADD `item_updated` datetime default NULL\n "; db_exec($sql); $sql = "SELECT `item_id` FROM helpdesk_items"; $rows = db_loadList($sql); $sql = ''; foreach ($rows as $row) { $sql = "SELECT MAX(status_date) status_date FROM helpdesk_item_status WHERE status_item_id =" . $row['item_id']; $sdrow = db_loadList($sql); $sql = ''; $sql = "UPDATE `helpdesk_items`\n \t \tSET `item_updated`='" . $sdrow[0]['status_date'] . "' \n \t \tWHERE `item_id`=" . $row['item_id']; db_exec($sql); } if (db_error()) { $success = 0; } else { $success = 1; } break; default: $success = 0; } // NOTE: Need to return true, not null, if all is good return $success; }
$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);