protected function _preCalcData() { $taskList = $this->obj->getAllowedTaskList(null, 1); foreach ($taskList as $item) { $tmpTask = new CTask(); $tmpTask->load($item['task_id']); if ($tmpTask->task_dynamic == 1) { $tmpTask->updateDynamics(true); $tmpTask->store(); } } }
/** * Updates the variable information on the task. * * @param int $task_log_task that task id of task this task log is for * * @return void * * @access private */ private function updateTaskSummary(CAppUI $AppUI, $task_id) { $perms = $AppUI->acl(); $q = $this->_query; if ($perms->checkModuleItem('tasks', 'edit', $task_id)) { if ($this->task_log_percent_complete < 100) { $q->addQuery('task_log_percent_complete, task_log_date, task_log_task_end_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $q->addOrder('task_log_date DESC, task_log_id DESC'); $q->setLimit(1); $results = $q->loadHash(); $q->clear(); $percentComplete = $results['task_log_percent_complete']; /* * TODO: In theory, we shouldn't just use the task_log_task_end_date, * because if we're after that date and someone is still adding * logs to a task, obviously the task isn't complete. We may want * to check to see if task_log_date > task_log_task_end_date and * use the later one as the end date.. not sure yet. */ $taskEndDate = $results['task_log_task_end_date']; } else { $percentComplete = 100; $taskEndDate = $this->task_log_date; } $task = new CTask(); $task->load($task_id); $task->task_percent_complete = $percentComplete; $task->task_end_date = $taskEndDate; $msg = $task->store($AppUI); if (is_array($msg)) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } $task->pushDependencies($task_id, $task->task_end_date); } $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_log_task); $totalHours = $q->loadResult(); CTask::updateHoursWorked($task_id, $totalHours); }
/** * * @param CAppUI $AppUI * @param CProject $projectId * * The point of this function is to create/update a task to represent a * subproject. * */ public static function storeTokenTask(CAppUI $AppUI, $project_id) { $subProject = new CProject(); $subProject->load($project_id); if ($subProject->project_id != $subProject->project_parent) { $q = new w2p_Database_Query(); $q->addTable('tasks'); $q->addQuery('MIN(task_start_date) AS min_task_start_date'); $q->addQuery('MAX(task_end_date) AS max_task_end_date'); $q->addWhere('task_project = ' . $subProject->project_id); $projectDates = $q->loadList(); $q->clear(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_represents_project = ' . $subProject->project_id); $task_id = $q->loadResult(); $task = new CTask(); if ($task_id) { $task->load($task_id); } else { $task->task_description = $task->task_name; $task->task_priority = $subProject->project_priority; $task->task_project = $subProject->project_parent; $task->task_represents_project = $subProject->project_id; $task->task_owner = $AppUI->user_id; } $task->task_name = $AppUI->_('Subproject') . ': ' . $subProject->project_name; $task->task_duration_type = 1; $task->task_duration = $subProject->getTotalProjectHours(); $task->task_start_date = $projectDates[0]['min_task_start_date']; $task->task_end_date = $projectDates[0]['max_task_end_date']; $task->task_percent_complete = $subProject->project_percent_complete; $result = $task->store($AppUI); //TODO: we should do something with this store result? } }
} //Action: Unassign User if (isset($_POST['bulk_task_unassign']) && $bulk_task_unassign != '') { $upd_task = new CTask(); $upd_task->load($key); if ($upd_task->task_id) { $upd_task->removeAssigned($bulk_task_unassign); } } // Action: Allow user to add task logs for others if (isset($_POST['bulk_task_allow_other_user_tasklogs']) && $bulk_task_allow_other_user_tasklogs != '') { $upd_task = new CTask(); $upd_task->load($key); if ($upd_task->task_id) { $upd_task->task_allow_other_user_tasklogs = $bulk_task_allow_other_user_tasklogs; $result = $upd_task->store($AppUI); if (is_array($result)) { break; } } } //Action: Other Actions if (isset($_POST['bulk_task_other']) && $bulk_task_other != '') { if ($upd_task->task_id) { //Option 1 - Mark as finished if ($bulk_task_other == '1') { $upd_task->task_percent_complete = 100; if (!$upd_task->task_end_date || $upd_task->task_end_date == '0000-00-00 00:00:00') { $end_date = null; $end_date = new w2p_Utilities_Date(); $upd_task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL);
public function updateDynamics($fromChildren = false) { global $AppUI; //Has a parent or children, we will check if it is dynamic so that it's info is updated also $q = new DBQuery(); $modified_task = new CTask(); if ($fromChildren) { $modified_task =& $this; } else { $modified_task->load($this->task_parent); $modified_task->htmlDecode(); } if ($modified_task->task_dynamic == '1') { //Update allocated hours based on children with duration type of 'hours' $q->addTable('tasks'); $q->addQuery('SUM(task_duration * task_duration_type)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_duration_type = 1 '); $q->addGroup('task_parent'); $children_allocated_hours1 = (double) $q->loadResult(); $q->clear(); /* * Update allocated hours based on children with duration type of 'days' * use the daily working hours instead of the full 24 hours to calculate * dynamic task duration! */ $q->addTable('tasks'); $q->addQuery(' SUM(task_duration * ' . w2PgetConfig('daily_working_hours') . ')'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_duration_type <> 1 '); $q->addGroup('task_parent'); $children_allocated_hours2 = (double) $q->loadResult(); $q->clear(); // sum up the two distinct duration values for the children with duration type 'hrs' // and for those with the duration type 'day' $children_allocated_hours = $children_allocated_hours1 + $children_allocated_hours2; if ($modified_task->task_duration_type == 1) { $modified_task->task_duration = round($children_allocated_hours, 2); } else { $modified_task->task_duration = round($children_allocated_hours / w2PgetConfig('daily_working_hours'), 2); } //Update worked hours based on children $q->addTable('tasks', 't'); $q->innerJoin('task_log', 'tl', 't.task_id = tl.task_log_task'); $q->addQuery('SUM(task_log_hours)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_dynamic <> 1 '); $children_hours_worked = (double) $q->loadResult(); $q->clear(); //Update worked hours based on dynamic children tasks $q->addTable('tasks'); $q->addQuery('SUM(task_hours_worked)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_dynamic = 1 '); $children_hours_worked += (double) $q->loadResult(); $q->clear(); $modified_task->task_hours_worked = $children_hours_worked; //Update percent complete //hours $q->addTable('tasks'); $q->addQuery('SUM(task_percent_complete * task_duration * task_duration_type)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_duration_type = 1 '); $real_children_hours_worked = (double) $q->loadResult(); $q->clear(); //days $q->addTable('tasks'); $q->addQuery('SUM(task_percent_complete * task_duration * ' . w2PgetConfig('daily_working_hours') . ')'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND task_duration_type <> 1 '); $real_children_hours_worked += (double) $q->loadResult(); $q->clear(); $total_hours_allocated = (double) ($modified_task->task_duration * ($modified_task->task_duration_type > 1 ? w2PgetConfig('daily_working_hours') : 1)); if ($total_hours_allocated > 0) { $modified_task->task_percent_complete = ceil($real_children_hours_worked / $total_hours_allocated); } else { $q->addTable('tasks'); $q->addQuery('AVG(task_percent_complete)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id); $modified_task->task_percent_complete = $q->loadResult(); $q->clear(); } //Update start date $q->addTable('tasks'); $q->addQuery('MIN(task_start_date)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND NOT ISNULL(task_start_date)' . ' AND task_start_date <> \'0000-00-00 00:00:00\''); $d = $q->loadResult(); $q->clear(); if ($d) { $modified_task->task_start_date = $d; } else { $modified_task->task_start_date = '0000-00-00 00:00:00'; } //Update end date $q->addTable('tasks'); $q->addQuery('MAX(task_end_date)'); $q->addWhere('task_parent = ' . (int) $modified_task->task_id . ' AND task_id <> ' . $modified_task->task_id . ' AND NOT ISNULL(task_end_date)'); $modified_task->task_end_date = $q->loadResult(); $q->clear(); //If we are updating a dynamic task from its children we don't want to store() it //when the method exists the next line in the store calling function will do that if ($fromChildren == false) { $modified_task->store($AppUI); } } }
/** * Post Request Handler * * This method is called when a request is a POST * * @return array */ public function executePost() { /** * @todo Remove this once we figure out how to reference vars in file * that is autoloaded */ global $tracking_dynamics; $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } $username = $this->getParam('username'); $password = $this->getParam('password'); $project_id = $this->getParam('project_id', self::TYPE_INT); $hassign = $this->getParam('hassign'); $hdependencies = $this->getParam('hdependencies'); $notify = $this->getParam('task_notify'); $comment = $this->getParam('email_comment'); $task_id = $this->getParam('task_id'); $adjustStartDate = $this->getParam('set_task_start_date'); $task = new CTask(); // Attempt to login as user, a little bit of a hack as we currently // require the $_POST['login'] var to be set as well as a global AppUI $AppUI = new CAppUI(); $GLOBALS['AppUI'] = $AppUI; $_POST['login'] = '******'; if (!$AppUI->login($username, $password)) { throw new Frapi_Error('INVALID_LOGIN'); } $post_data = array('task_id' => $this->getParam('task_id'), 'task_name' => $this->getParam('task_name'), 'task_status' => $this->getParam('task_status'), 'task_percent_complete' => $this->getParam('task_percent_complete'), 'task_milestone' => $this->getParam('task_milestone'), 'task_owner' => $this->getParam('task_owner'), 'task_access' => $this->getParam('task_access'), 'task_related_url' => $this->getParam('task_related_url'), 'task_parent' => $this->getParam('task_parent'), 'task_type' => $this->getParam('task_type'), 'task_target_budget' => $this->getParam('task_target_budget'), 'task_description' => $this->getParam('task_description'), 'task_start_date' => $this->getParam('task_start_date'), 'task_end_date' => $this->getParam('task_end_date'), 'task_duration' => $this->getParam('task_duration'), 'task_duration_type' => $this->getParam('task_duration_type'), 'task_dynamic' => $this->getParam('task_dynamic'), 'task_allow_other_user_tasklogs' => $this->getParam('task_allow_other_user_tasklogs'), 'task_project' => $this->getParam('task_project'), 'task_priority' => $this->getParam('task_priority')); // Include any files for handling module-specific requirements foreach (findTabModules('tasks', 'addedit') as $mod) { $fname = W2P_BASE_DIR . '/modules/' . $mod . '/tasks_dosql.addedit.php'; if (file_exists($fname)) { require_once $fname; } } // Find the task if we are set $task_end_date = null; if ($task_id) { $task->load($task_id); $task_end_date = new w2p_Utilities_Date($task->task_end_date); } $task = new CTask(); if (!$task->bind($post_data)) { throw new Frapi_Error('SAVE_ERROR', $task->getError()); } if ($task->task_dynamic != 1) { $task_dynamic_delay = $this->getParam('task_dynamic_nodelay') ? $this->getParam('task_dynamic_nodelay') : '0'; if (in_array($task->task_dynamic, $tracking_dynamics)) { $task->task_dynamic = $task_dynamic_delay ? 21 : 31; } else { $task->task_dynamic = $task_dynamic_delay ? 11 : 0; } } // Let's check if task_dynamic is unchecked if (!$this->getParam('task_dynamic')) { $task->task_dynamic = false; } // Make sure task milestone is set or reset as appropriate if ($this->getParam('task_milestone')) { $task->task_milestone = false; } //format hperc_assign user_id=percentage_assignment;user_id=percentage_assignment;user_id=percentage_assignment; $tmp_ar = explode(';', $this->getParam('hperc_assign')); $i_cmp = sizeof($tmp_ar); $hperc_assign_ar = array(); for ($i = 0; $i < $i_cmp; $i++) { $tmp = explode('=', $tmp_ar[$i]); if (count($tmp) > 1) { $hperc_assign_ar[$tmp[0]] = $tmp[1]; } elseif ($tmp[0] != '') { $hperc_assign_ar[$tmp[0]] = 100; } } // let's check if there are some assigned departments to task $task->task_departments = implode(',', $this->getParam('dept_ids', self::TYPE_ARRAY)); // convert dates to SQL format first if ($task->task_start_date) { $date = new w2p_Utilities_Date($task->task_start_date); $task->task_start_date = $date->format(FMT_DATETIME_MYSQL); } $end_date = null; if ($task->task_end_date) { if (strpos($task->task_end_date, '2400') !== false) { $task->task_end_date = str_replace('2400', '2359', $task->task_end_date); } $end_date = new w2p_Utilities_Date($task->task_end_date); $task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL); } $error_array = $task->store($AppUI); // Return all the validation messages if ($error_array !== true) { $error_message = ''; foreach ($error_array as $error) { $error_message .= $error . '. '; } throw new Frapi_Error('SAVE_ERROR', $error_message); } $task_parent = $this->getParam('task_parent') ? $this->getParam('task_parent', SELF::TYPE_INT) : 0; $old_task_parent = $this->getParam('old_task_parent') ? $this->getParam('old_task_parent', SELF::TYPE_INT) : 0; if ($task_parent != $old_task_parent) { $oldTask = new CTask(); $oldTask->load($old_task_parent); $oldTask->updateDynamics(false); } // How to handle custom fields? Do we support it in api? // Now add any task reminders // If there wasn't a task, but there is one now, and // that task date is set, we need to set a reminder. if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) { $task->addReminder(); } if (isset($hassign)) { $task->updateAssigned($hassign, $hperc_assign_ar); } if (isset($hdependencies)) { // && !empty($hdependencies)) { // there are dependencies set! // backup initial start and end dates $tsd = new w2p_Utilities_Date($task->task_start_date); $ted = new w2p_Utilities_Date($task->task_end_date); // updating the table recording the // dependency relations with this task $task->updateDependencies($hdependencies, $task_parent); // we will reset the task's start date based upon dependencies // and shift the end date appropriately if ($adjustStartDate && !is_null($hdependencies)) { // load already stored task data for this task $tempTask = new CTask(); $tempTask->load($task->task_id); // shift new start date to the last dependency end date $nsd = new w2p_Utilities_Date($tempTask->get_deps_max_end_date($tempTask)); // prefer Wed 8:00 over Tue 16:00 as start date $nsd = $nsd->next_working_day(); // prepare the creation of the end date $ned = new w2p_Utilities_Date(); $ned->copy($nsd); if (empty($task->task_start_date)) { // appropriately calculated end date via start+duration $ned->addDuration($task->task_duration, $task->task_duration_type); } else { // calc task time span start - end $d = $tsd->calcDuration($ted); // Re-add (keep) task time span for end date. // This is independent from $obj->task_duration. // The value returned by Date::Duration() is always in hours ('1') $ned->addDuration($d, '1'); } // prefer tue 16:00 over wed 8:00 as an end date $ned = $ned->prev_working_day(); $task->task_start_date = $nsd->format(FMT_DATETIME_MYSQL); $task->task_end_date = $ned->format(FMT_DATETIME_MYSQL); $q = new w2p_Database_Query(); $q->addTable('tasks', 't'); $q->addUpdate('task_start_date', $task->task_start_date); $q->addUpdate('task_end_date', $task->task_end_date); $q->addWhere('task_id = ' . (int) $task->task_id); $q->addWhere('task_dynamic <> 1'); $q->exec(); $q->clear(); } $task->pushDependencies($task->task_id, $task->task_end_date); } //$task = (array)$task; $task->load($task_id); unset($task->_query, $task->_error, $task->_tbl_prefix, $task->_tbl, $task->_tbl_key, $task->_tbl_module); $this->data['task'] = $task; $this->data['success'] = true; return $this->toArray(); }
/** * Updates the variable information on the task. * * @param int $task_log_task that task id of task this task log is for * * @return void * * @access private */ protected function updateTaskSummary($AppUI = null, $task_id) { $q = $this->_getQuery(); if ($this->_perms->checkModuleItem('tasks', 'edit', $task_id)) { if ($this->task_log_percent_complete < 100) { $q->addQuery('task_log_percent_complete, task_log_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $q->addOrder('task_log_date DESC, task_log_id DESC'); $q->setLimit(1); $results = $q->loadHash(); $percentComplete = $results['task_log_percent_complete']; } else { $percentComplete = 100; } $task = new CTask(); $task->overrideDatabase($this->_query); $task->load($task_id); $task->task_percent_complete = $percentComplete; $diff = strtotime($this->task_log_task_end_date) - strtotime($task->task_end_date); $task->task_end_date = 0 == $diff ? $task->task_end_date : $this->task_log_task_end_date; $success = $task->store(); if (!$success) { $this->_AppUI->setMsg($task->getError(), UI_MSG_ERROR, true); } $task->pushDependencies($task_id, $task->task_end_date); } $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $totalHours = $q->loadResult(); CTask::updateHoursWorked($task_id, $totalHours); }
if ($upd_task->task_id) { $upd_task->removeAssigned($bulk_task_unassign); } } //Action: Other Actions if (isset($_POST['bulk_task_other']) && $bulk_task_other != '') { if ($upd_task->task_id) { //Option 1 - Mark as finished if ($bulk_task_other == '1') { $upd_task->task_percent_complete = 100; if (!$upd_task->task_end_date || $upd_task->task_end_date == '0000-00-00 00:00:00') { $end_date = null; $end_date = new CDate(); $upd_task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL); } $upd_task->store($AppUI); //Option 2 - Mark as milestone } elseif ($bulk_task_other == '2') { $upd_task->task_milestone = 1; $upd_task->store($AppUI); //Option 3 - Mark as non milestone } elseif ($bulk_task_other == '3') { $upd_task->task_milestone = 0; $upd_task->store($AppUI); //Option 4 - Mark as dynamic } elseif ($bulk_task_other == '4') { $upd_task->task_dynamic = 1; $upd_task->store($AppUI); //Option 5 - Mark as non dynamic } elseif ($bulk_task_other == '5') { $upd_task->task_dynamic = 0;
$task->load($obj->task_log_task); $canEditTask = $perms->checkModuleItem('tasks', 'edit', $task_id); if ($canEditTask) { $task->htmlDecode(); $task->check(); $task_end_date = new w2p_Utilities_Date($task->task_end_date); $task->task_percent_complete = w2PgetParam($_POST, 'task_percent_complete', null); if (w2PgetParam($_POST, 'task_end_date', '') != '') { $new_date = new w2p_Utilities_Date($_POST['task_end_date']); $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second); $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL); } if ($task->task_percent_complete >= 100 && (!$task->task_end_date || $task->task_end_date == '0000-00-00 00:00:00')) { $task->task_end_date = $obj->task_log_date; } $msg = $task->store($AppUI); if (is_array($msg)) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } $new_task_end = new w2p_Utilities_Date($task->task_end_date); if ($new_task_end->dateDiff($task_end_date)) { $task->addReminder(); } $task->pushDependencies($task->task_id, $task->task_end_date); } if ('on' == $notify_owner) { if ($msg = $task->notifyOwner()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } } // Check if we need to email the task log to anyone.
/** Import tasks from another project * * @param int Project ID of the tasks come from. * @return bool **/ function importTasks($from_project_id) { // Load the original $origProject = new CProject(); $origProject->load($from_project_id); $q = new DBQuery(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $from_project_id); $sql = $q->prepare(); $q->clear(); $tasks = array_flip(db_loadColumn($sql)); $origDate = new CDate($origProject->project_start_date); $destDate = new CDate($this->project_start_date); $dateOffset = $destDate->dateDiff($origDate); // Old dependencies array from imported tasks $deps = array(); // New dependencies array for new copies of imported tasks $newDeps = array(); // Old2New task ID array $taskXref = array(); // New task ID to old parent array $nid2op = array(); // Copy each task into this project and get their deps foreach ($tasks as $orig => $void) { $objTask = new CTask(); $objTask->load($orig); // Grab the old parent id $oldParent = (int) $objTask->task_parent; $deps[$orig] = $objTask->getDependencies(); $destTask = $objTask->copy($this->project_id, 0); $nid2op[$destTask->task_id] = $oldParent; $tasks[$orig] = $destTask; $taskXref[$orig] = (int) $destTask->task_id; } // Build new dependencies array foreach ($deps as $odkey => $od) { $ndt = ''; $ndkey = $taskXref[$odkey]; $odep = explode(',', $od); foreach ($odep as $odt) { $ndt = $ndt . $taskXref[$odt] . ','; } $ndt = rtrim($ndt, ','); $newDeps[$ndkey] = $ndt; } $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $this->project_id); $tasks = $q->loadColumn(); // Update dates based on new project's start date. foreach ($tasks as $task_id) { $newTask = new CTask(); $newTask->load($task_id); if (in_array($task_id, $taskXref)) { // Fix task start date from project start date offset $origDate->setDate($newTask->task_start_date); $destDate->setDate($newTask->task_start_date); $destDate->addDays($dateOffset); $destDate = $destDate->next_working_day(); $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL); // Fix task end date from start date + work duration //$newTask->calc_task_end_date(); if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') { $origDate->setDate($newTask->task_end_date); $destDate->setDate($newTask->task_end_date); $destDate->addDays($dateOffset); $destDate = $destDate->next_working_day(); $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL); } $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]]; $newTask->store(); $newTask->updateDependencies($newDeps[$task_id]); } // end check if imported task $newTask->store(); } // end Fix record integrity }
// Re-add (keep) task time span for end date. // This is independent from $obj->task_duration. // The value returned by Date::Duration() is always in hours ('1') $ned->addDuration($d, '1'); } // prefer tue 16:00 over wed 8:00 as an end date $ned = $ned->prev_working_day(); $obj->task_start_date = $nsd->format(FMT_DATETIME_MYSQL); $obj->task_end_date = $ned->format(FMT_DATETIME_MYSQL); $obj->task_start_date = $AppUI->convertToSystemTZ($obj->task_start_date); $obj->task_end_date = $AppUI->convertToSystemTZ($obj->task_end_date); $updateTask = new CTask(); $updateTask->load((int) $obj->task_id); $updateTask->task_start_date = $obj->task_start_date; $updateTask->task_end_date = $obj->task_end_date; $updateTask->store($AppUI); } $obj->pushDependencies($obj->task_id, $obj->task_end_date); } // If there is a set of post_save functions, then we process them if (isset($post_save)) { foreach ($post_save as $post_save_function) { $post_save_function(); } } if ($notify) { if ($msg = $obj->notify($comment)) { $AppUI->setMsg($msg, UI_MSG_ERROR); } } $AppUI->redirect('m=projects&a=view&project_id=' . $obj->task_project);
if ($obj->task_log_date) { $date = new CDate($obj->task_log_date); $obj->task_log_date = $date->format(FMT_DATETIME_MYSQL); } // prepare (and translate) the module name ready for the suffix $AppUI->setMsg('Task Log'); if ($del) { if ($msg = $obj->delete()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { $AppUI->setMsg("deleted", UI_MSG_ALERT); } $AppUI->redirect("m=timecard&tab=0"); } else { $obj->task_log_costcode = cleanText($obj->task_log_costcode); if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } else { // update task percent complete $task = new CTask(); if ($task_id) { $task->load($task_id); $task->task_percent_complete = $task_percent_complete; $task->store(); } $AppUI->setMsg(@$_POST['task_log_id'] ? 'updated' : 'inserted', UI_MSG_OK, true); $AppUI->redirect("m=timecard&tab=0"); } } $AppUI->redirect();
} if ($column == "task_description") { $task_obj->task_description = $value; } if ($column == "task_percent_complete") { $task_obj->task_percent_complete = (int) $value; } if ($column == "task_start_date") { $userTZ = $AppUI->getPref('TIMEZONE'); $start_date_userTZ = $start_date = new w2p_Utilities_Date($value, $userTZ); $start_date->convertTZ('UTC'); $ts = $start_date->format(FMT_DATETIME_MYSQL); $task_obj->task_start_date = $ts; } if ($column == "task_end_date") { $userTZ = $AppUI->getPref('TIMEZONE'); $start_date_userTZ = $start_date = new w2p_Utilities_Date($value, $userTZ); $start_date->convertTZ('UTC'); $ts = $start_date->format(FMT_DATETIME_MYSQL); $task_obj->task_end_date = $ts; } // if (column=="task_start_date") $task_obj->task_name=$value; // if (column=="task_end_date") $task_obj->task_name=$value; /* Update a record using information about id, columnName (property of the object or column in the table) and value that should be set */ if ($id > 0 && $task_obj->store()) { echo $value; } else { echo "cannot store/edit task name"; }
protected function _processTask(CAppUI $AppUI, $project_id, $task) { $myTask = new CTask(); $myTask->task_name = w2PgetCleanParam($task, 'task_name', null); $myTask->task_project = $project_id; $myTask->task_description = w2PgetCleanParam($task, 'task_description', ''); $myTask->task_start_date = $task['task_start_date']; $myTask->task_end_date = $task['task_end_date']; $myTask->task_duration = $task['task_duration']; $myTask->task_milestone = (int) $task['task_milestone']; $myTask->task_owner = (int) $task['task_owner']; $myTask->task_dynamic = (int) $task['task_dynamic']; $myTask->task_priority = (int) $task['task_priority']; $myTask->task_percent_complete = $task['task_percent_complete']; $myTask->task_duration_type = 1; $result = $myTask->store($AppUI); return is_array($result) ? $result : $myTask->task_id; }
} $end_date = new CDate($obj->task_end_date); $obj->task_end_date = $end_date->format(FMT_DATETIME_MYSQL); } // prepare (and translate) the module name ready for the suffix if ($del) { $result = $obj->delete(); if (is_array($result)) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } else { $AppUI->setMsg('Task deleted'); $AppUI->redirect('', -1); } } $result = $obj->store($AppUI); if ($taskRecount) { $myTask = new CTask(); CProject::updateTaskCount($taskRecount, $myTask->getTaskCount($taskRecount)); } //$obj->task_project if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR, true); $AppUI->holdObject($obj); $AppUI->redirect('m=tasks&a=addedit'); } if ($result) { $task_parent = (int) w2PgetParam($_POST, 'task_parent', 0); $old_task_parent = (int) w2PgetParam($_POST, 'old_task_parent', 0); if ($task_parent != $old_task_parent) { $oldTask = new CTask();
} //Action: Unassign User if (isset($_POST['bulk_task_unassign']) && $bulk_task_unassign != '') { $upd_task = new CTask(); $upd_task->load($val); if ($upd_task->task_id) { $upd_task->removeAssigned($bulk_task_unassign); } } // Action: Allow user to add task logs for others if (isset($_POST['bulk_task_allow_other_user_tasklogs']) && $bulk_task_allow_other_user_tasklogs != '') { $upd_task = new CTask(); $upd_task->load($val); if ($upd_task->task_id) { $upd_task->task_allow_other_user_tasklogs = $bulk_task_allow_other_user_tasklogs; $result = $upd_task->store(); if (!$result) { break; } } } //Action: Set user task priority for current user ($APPUI->userid) if ($upd_task->task_id && $bulk_task_user_priority != "") { $assigned_users = $upd_task->assignees($upd_task->task_id); if (array_key_exists("{$AppUI->user_id}", $assigned_users)) { $upd_task->updateUserSpecificTaskPriority($bulk_task_user_priority, $AppUI->user_id); } } //Action: Other Actions if (isset($_POST['bulk_task_other']) && $bulk_task_other != '') { if ($upd_task->task_id) {
$AppUI->setMsg('User unassigned from Task', UI_MSG_OK); } } if (isset($hassign) && !$del == 1) { $overAssignment = $obj->updateAssigned($hassign, $hperc_assign_ar, false, false); //check if OverAssignment occured, database has not been updated in this case if ($overAssignment) { $AppUI->setMsg('The following Users have not been assigned in order to prevent from Over-Assignment:', UI_MSG_ERROR); $AppUI->setMsg('<br>' . $overAssignment, UI_MSG_ERROR, true); } else { $AppUI->setMsg('User(s) assigned to Task', UI_MSG_OK); } } // process the user specific task priority if ($chUTP == 1) { $obj->updateUserSpecificTaskPriority($user_task_priority, $user_id); $AppUI->setMsg('User specific Task Priority updated', UI_MSG_OK, true); } if ($store == 1) { if ($msg = $obj->store($AppUI)) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } else { $AppUI->setMsg('Task(s) updated', UI_MSG_OK, true); } } } } if ($rm && $del) { $AppUI->setMsg('User(s) unassigned from Task', UI_MSG_OK); } $AppUI->redirect();
$ass = $AppUI->user_id; if ($id == 0) { $ev1->updateAssigned($ass); } } else { echo "0"; } } else { $tsk = new CTask(); $tsk->load($task_id); if ($do_task === "resize") { $tsk->task_end_date = $end; } else { if ($do_task === "drag") { $tsk->task_start_date = $start; $tsk->task_end_date = $end; } else { if ($do_task === "pcpl") { //change % complete $tsk->task_percent_complete = $perc_compl; } } } //echo "0"; $res = $tsk->store(); if ($res) { echo "{$tsk->task_id}"; } else { echo "0"; } }
} $task = new CTask(); $task->load($obj->task_log_task); $task->htmlDecode(); $task->check(); $task_end_date = new CDate($task->task_end_date); $task->task_percent_complete = dPgetParam($_POST, 'task_percent_complete', null); if (dPgetParam($_POST, 'task_end_date', '') != '') { $new_date = new CDate($_POST['task_end_date']); $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second); $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL); } if ($task->task_percent_complete >= 100 && (!$task->task_end_date || $task->task_end_date == '0000-00-00 00:00:00')) { $task->task_end_date = $obj->task_log_date; } if ($msg = $task->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } $new_task_end = new CDate($task->task_end_date); if ($new_task_end->dateDiff($task_end_date)) { $task->addReminder(); } if ($notify_owner && ($msg = $task->notifyOwner())) { $AppUI->setMsg($msg, UI_MSG_ERROR); } // Check if we need to email the task log to anyone. $email_assignees = dPgetParam($_POST, 'email_assignees', null); $email_task_contacts = dPgetParam($_POST, 'email_task_contacts', null); $email_project_contacts = dPgetParam($_POST, 'email_project_contacts', null); $email_others = dPgetParam($_POST, 'email_others', ''); $email_extras = dPgetParam($_POST, 'email_extras', null);
function updateDynamics($fromChildren = false) { global $dPconfig; //Has a parent or children, we will check if it is dynamic so that it's info is updated also $modified_task = new CTask(); if ($fromChildren) { $modified_task =& $this; } else { $modified_task->load($this->task_parent); } if ($modified_task->task_dynamic == '1') { //Update allocated hours based on children with duration type of 'hours' $sql1 = "SELECT SUM( task_duration * task_duration_type ) from " . $this->_tbl . " WHERE task_parent = " . $modified_task->task_id . " and task_id != " . $modified_task->task_id . " AND task_duration_type = 1 " . " GROUP BY task_parent;"; $children_allocated_hours1 = (double) db_loadResult($sql1); //Update allocated hours based on children with duration type of 'days' // use here the daily working hours instead of the full 24 hours to calculate dynamic task duration! $sql2 = "SELECT SUM( task_duration * " . $dPconfig['daily_working_hours'] . " ) from " . $this->_tbl . " WHERE task_parent = " . $modified_task->task_id . " and task_id != " . $modified_task->task_id . " AND task_duration_type > 1" . " GROUP BY task_parent;"; $children_allocated_hours2 = (double) db_loadResult($sql2); // sum up the two distinct duration values for the children with duration type 'hrs' // and for those with the duration type 'day' $children_allocated_hours = $children_allocated_hours1 + $children_allocated_hours2; if ($modified_task->task_duration_type == 1) { $modified_task->task_duration = round($children_allocated_hours, 2); } else { $modified_task->task_duration = round($children_allocated_hours / $modified_task->task_duration_type, 2); } //Update worked hours based on children $sql = "SELECT sum( task_log_hours ) FROM tasks, task_log\n\t\t\t\t\tWHERE task_id = task_log_task AND task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id . " AND task_dynamic != 1"; $children_hours_worked = (double) db_loadResult($sql); //Update worked hours based on dynamic children tasks $sql = "SELECT sum( task_hours_worked ) FROM tasks\n\t\t\t\t\tWHERE task_dynamic = 1 AND task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id; $children_hours_worked += (double) db_loadResult($sql); $modified_task->task_hours_worked = $children_hours_worked; //Update percent complete $sql = "SELECT sum(task_percent_complete * task_duration * task_duration_type )\n\t\t\t\t\tFROM tasks WHERE task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id; $real_children_hours_worked = (double) db_loadResult($sql); $total_hours_allocated = (double) ($modified_task->task_duration * $modified_task->task_duration_type); if ($total_hours_allocated > 0) { $modified_task->task_percent_complete = $real_children_hours_worked / $total_hours_allocated; } else { $sql = "SELECT avg(task_percent_complete)\n \t\t\t\t\tFROM tasks WHERE task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id; $modified_task->task_percent_complete = db_loadResult($sql); } //Update start date $sql = "SELECT min( task_start_date ) FROM tasks\n\t\t\t\t\tWHERE task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id . " AND ! isnull( task_start_date ) AND task_start_date != '0000-00-00 00:00:00'"; $modified_task->task_start_date = db_loadResult($sql); //Update end date $sql = "SELECT max( task_end_date ) FROM tasks\n\t\t\t\t\tWHERE task_parent = " . $modified_task->task_id . " AND task_id != " . $modified_task->task_id . " AND ! isnull( task_end_date ) AND task_end_date != '0000-00-00 00:00:00'"; $modified_task->task_end_date = db_loadResult($sql); //If we are updating a dynamic task from its children we don't want to store() it //when the method exists the next line in the store calling function will do that if ($fromChildren == false) { $modified_task->store(); } } }
$t2 = $t->deepCopy($new_project, $new_task); } else { $t2 = $t->copy($new_project, $new_task); } $t2->store(); } else { if ($action > -2 && $action < 2) { //set priority $t->task_priority = $action; $t->store(); if (isset($children)) { foreach ($children as $child_id) { $child_t = new CTask(); $child_t->load($child_id); $child_t->task_priority = $action; $child_t->store(); } } } } } } } } } $AppUI->savePlace(); $proj = new CProject(); $tobj = new CTask(); $q = new DBQuery(); $allowedProjects = $proj->getAllowedSQL($AppUI->user_id, 'p.project_id'); $allowedTasks = $tobj->getAllowedSQL($AppUI->user_id, 't.task_id');
$end_date = ''; if ($elements['add_task_end_date_' . $on]) { $date = new w2p_Utilities_Date($elements['add_task_end_date_' . $on]); $end_date = $date->format(FMT_DATETIME_MYSQL); $end_date = $AppUI->convertToSystemTZ($end_date); } $tline->task_end_date = $end_date; $tline->task_duration = $elements['add_task_duration_' . $on]; $tline->task_duration_type = $elements['add_task_durntype_' . $on]; $tline->task_priority = $elements['add_task_priority_' . $on]; $tline->task_type = $elements['add_task_type_' . $on]; $tline->task_access = $elements['add_task_access_' . $on]; $tline->task_description = $elements['add_task_description_' . $on] ? $elements['add_task_description_' . $on] : ''; $tline->task_owner = $AppUI->user_id; if ($elements['add_task_extra_' . $on] == '1') { $tline->task_milestone = '1'; } elseif ($elements['add_task_extra_' . $on] == '2') { $tline->task_dynamic = '1'; } elseif ($elements['add_task_extra_' . $on] == '3') { $tline->task_status = '-1'; } $result = $tline->store(); if (is_array($result)) { $taskErrors[] = $result; } } } if (count($taskErrors) > 0) { $AppUI->setMsg($result, UI_MSG_ERROR); } $AppUI->redirect('m=projectdesigner&project_id=' . $project_id);
/** Import tasks from another project * * @param int Project ID of the tasks come from. * @return bool **/ function importTasks($from_project_id, $scale_project = false) { // Load the original $origProject = new CProject(); $origProject->load($from_project_id); $q = new DBQuery(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $from_project_id); $sql = $q->prepare(); $q->clear(); $tasks = array_flip(db_loadColumn($sql)); //Pristine Start and End Dates of Source and Destination Projects $origStartDate = new CDate($origProject->project_start_date); $origEndDate = new CDate($origProject->project_end_date); $destStartDate = new CDate($this->project_start_date); $destEndDate = new CDate($this->project_end_date); $dateOffset = $destStartDate->dateDiff($origStartDate); //Check that we have enough information to scale properly //(i.e. no information is missing or "zero") if (empty($origProject->project_start_date) || empty($origProject->project_end_date) || empty($this->project_start_date) || empty($this->project_end_date) || $origProject->project_start_date == '0000-00-00 00:00:00' || $origProject->project_end_date == '0000-00-00 00:00:00' || $this->project_start_date == '0000-00-00 00:00:00' || $this->project_end_date == '0000-00-00 00:00:00') { $scale_project = false; } if ($scale_project) { //get ratio for scaling, protect from division by 0 $ratio = (abs($destEndDate->dateDiff($destStartDate)) + 1) / (abs($origEndDate->dateDiff($origStartDate)) + 1); } // Old dependencies array from imported tasks $deps = array(); // New dependencies array for new copies of imported tasks $newDeps = array(); // Old2New task ID array $taskXref = array(); // New task ID to old parent array $nid2op = array(); // Copy each task into this project and get their deps foreach ($tasks as $orig => $void) { $objTask = new CTask(); $objTask->load($orig); // Grab the old parent id $oldParent = (int) $objTask->task_parent; $deps[$orig] = $objTask->getDependencies(); $destTask = $objTask->copy($this->project_id, 0); $nid2op[$destTask->task_id] = $oldParent; $tasks[$orig] = $destTask; $taskXref[$orig] = (int) $destTask->task_id; } // Build new dependencies array foreach ($deps as $odkey => $od) { $ndt = ''; $ndkey = $taskXref[$odkey]; $odep = explode(',', $od); foreach ($odep as $odt) { $ndt = $ndt . $taskXref[$odt] . ','; } $ndt = rtrim($ndt, ','); $newDeps[$ndkey] = $ndt; } $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $this->project_id); $tasks = $q->loadColumn(); // Update dates based on new project's start date. $origDate = new CDate($origProject->project_start_date); $origStartHour = new CDate($this->project_start_date); $destDate = new CDate($this->project_start_date); foreach ($tasks as $task_id) { $newTask = new CTask(); $newTask->load($task_id); if (in_array($task_id, $taskXref)) { $task_date_vars = array('task_start_date', 'task_end_date'); //Adjust task dates based on calculated offsets foreach ($task_date_vars as $my_date) { if (!empty($newTask->{$my_date}) && $newTask->{$my_date} != '0000-00-00 00:00:00') { $origDate->setDate($newTask->{$my_date}); $origStartHour->setDate($newTask->{$my_date}); $origStartHour->setTime(intval(dPgetConfig('cal_day_start'))); $destDate->setDate($newTask->{$my_date}); $destDate->addDays($dateOffset); if ($scale_project) { $offsetAdd = round($origDate->dateDiff($origStartDate) * $ratio) - $origDate->dateDiff($origStartDate); $destDate->addDays($offsetAdd); $hours_in = $origStartHour->calcDuration($origDate); $offsetAddHours = round($hours_in * $ratio) - $hours_in; if ($offsetAddHours % dPgetConfig('daily_working_hours')) { $destDate->addDuration($offsetAddHours); } } $destDate = $destDate->next_working_day(); $newTask->{$my_date} = $destDate->format(FMT_DATETIME_MYSQL); } } //Adjust durration to scale if ($scale_project) { $newTask->task_duration = round($newTask->task_duration * $ratio, 2); } $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]]; $newTask->store(); $newTask->updateDependencies($newDeps[$task_id]); } // end check if imported task $newTask->store(); } // end Fix record integrity }
/** * * @param w2p_Core_CAppUI $AppUI * @param CProject $project_id * * The point of this function is to create/update a task to represent a * subproject. * */ public static function storeTokenTask(w2p_Core_CAppUI $AppUI, $project_id) { $subProject = new CProject(); //TODO: We need to convert this from static to use ->overrideDatabase() for testing. $subProject->load($project_id); if ($subProject->project_parent > 0 && $subProject->project_id != $subProject->project_parent) { $q = new w2p_Database_Query(); $q->addTable('tasks'); $q->addQuery('MIN(task_start_date) AS min_task_start_date'); $q->addQuery('MAX(task_end_date) AS max_task_end_date'); $q->addWhere('task_project = ' . $subProject->project_id); $q->addWhere('task_status <> -1'); $projectDates = $q->loadList(); $q->clear(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_represents_project = ' . $subProject->project_id); $task_id = (int) $q->loadResult(); $task = new CTask(); //TODO: We need to convert this from static to use ->overrideDatabase() for testing. if ($task_id) { $task->load($task_id); } else { $task->task_description = $task->task_name; $task->task_priority = $subProject->project_priority; $task->task_project = $subProject->project_parent; $task->task_represents_project = $subProject->project_id; $task->task_owner = $AppUI->user_id; } $task->task_name = $AppUI->_('Subproject') . ': ' . $subProject->project_name; $task->task_duration_type = 1; $task->task_duration = $subProject->project_scheduled_hours; $task->task_start_date = $projectDates[0]['min_task_start_date']; $task->task_end_date = $projectDates[0]['max_task_end_date']; $task->task_percent_complete = $subProject->project_percent_complete; $task->store(); //TODO: we should do something with this store result? } }
if ($upd_task->task_id) { $upd_task->removeAssigned($bulk_task_unassign); } } //Action: Other Actions if (isset($_POST['bulk_task_other']) && $bulk_task_other != '') { if ($upd_task->task_id) { //Option 1 - Mark as finished if ($bulk_task_other == '1') { $upd_task->task_percent_complete = 100; if (!$upd_task->task_end_date || $upd_task->task_end_date == '0000-00-00 00:00:00') { $end_date = null; $end_date = new CDate(); $upd_task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL); } $upd_task->store(); //Option 2 - Mark as milestone } elseif ($bulk_task_other == '2') { $upd_task->task_milestone = 1; $upd_task->store(); //Option 3 - Mark as non milestone } elseif ($bulk_task_other == '3') { $upd_task->task_milestone = 0; $upd_task->store(); //Option 4 - Mark as dynamic } elseif ($bulk_task_other == '4') { $upd_task->task_dynamic = 1; $upd_task->store(); //Option 5 - Mark as non dynamic } elseif ($bulk_task_other == '5') { $upd_task->task_dynamic = 0;
$date = new CDate($elements['add_task_start_date_' . $on]); $start_date = $date->format(FMT_DATETIME_MYSQL); } $tline->task_start_date = $start_date; $end_date = ''; if ($elements['add_task_end_date_' . $on]) { $date = new CDate($elements['add_task_end_date_' . $on]); $end_date = $date->format(FMT_DATETIME_MYSQL); } $tline->task_end_date = $end_date; $tline->task_duration = $elements['add_task_duration_' . $on]; $tline->task_duration_type = $elements['add_task_durntype_' . $on]; $tline->task_priority = $elements['add_task_priority_' . $on]; $tline->task_type = $elements['add_task_type_' . $on]; $tline->task_access = $elements['add_task_access_' . $on]; $tline->task_description = $elements['add_task_description_' . $on]; $tline->task_owner = "{$AppUI->user_id}"; if ($elements['add_task_extra_' . $on] == '1') { $tline->task_milestone = '1'; } elseif ($elements['add_task_extra_' . $on] == '2') { $tline->task_dynamic = '1'; } elseif ($elements['add_task_extra_' . $on] == '3') { $tline->task_status = '-1'; } if ($msg = $tline->store()) { $nrerrors++; } // print_r($msg);die; } } $AppUI->redirect('m=projectdesigner&project_id=' . $project_id);
function deepMove($destProject_id = 0, $destTask_id = 0) { $children = $this->getChildren(); $this->move($destProject_id, $destTask_id); if (!empty($children)) { foreach ($children as $child) { $tempChild = new CTask(); $tempChild->peek($child); $tempChild->htmlDecode($child); $tempChild->deepMove($destProject_id, $this->task_id); $tempChild->store(); } } $this->store(); }
} $end_date = new w2p_Utilities_Date($obj->task_end_date); $obj->task_end_date = $end_date->format(FMT_DATETIME_MYSQL); } // prepare (and translate) the module name ready for the suffix if ($del) { $result = $obj->delete(); if ($result) { $AppUI->setMsg('Task deleted'); $AppUI->redirect('m=projects&a=view&project_id=' . $obj->task_project); } else { $AppUI->setMsg($obj->getError(), UI_MSG_ERROR); $AppUI->redirect('m=tasks&a=view&task_id=' . $task_id); } } $result = $obj->store(); if ($result) { if (isset($hassign)) { $obj->updateAssigned($hassign, $hperc_assign_ar); } // This call has to be here to make sure that old dependencies are // cleared on save, even if there's no new dependencies $obj->updateDependencies($hdependencies, $obj->task_id); if (isset($hdependencies) && '' != $hdependencies) { // there are dependencies set! $nsd = new w2p_Utilities_Date($obj->get_deps_max_end_date($obj)); if (isset($start_date)) { $shift = $nsd->compare($start_date, $nsd); if ($shift < 1) { //$obj->task_start_date = $nsd->format(FMT_DATETIME_MYSQL); $osd = new w2p_Utilities_Date($obj->task_start_date);
} } } if (isset($hassign) && !$del == 1) { $overAssignment = $obj->updateAssigned($hassign, $hperc_assign_ar, false, false); //check if OverAssignment occured, database has not been updated in this case if ($overAssignment) { $AppUI->setMsg('The following Users have not been assigned in order to prevent' . ' from Over-Assignment:', UI_MSG_ERROR); $AppUI->setMsg('<br />' . $overAssignment, UI_MSG_ERROR, true); } else { $AppUI->setMsg('User(s) assigned to Task', UI_MSG_OK); } } // process the user specific task priority if ($chUTP == 1) { $obj->updateUserSpecificTaskPriority($user_task_priority, $user_id); $AppUI->setMsg('User specific Task Priority updated', UI_MSG_OK, true); } if ($store == 1) { if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } else { $AppUI->setMsg('Task(s) updated', UI_MSG_OK, true); } } } } if ($rm && $del) { $AppUI->setMsg('User(s) unassigned from Task', UI_MSG_OK); } $AppUI->redirect();
/** Import tasks from another project * * @param int Project ID of the tasks come from. * @return bool **/ function importTasks($from_project_id) { // Load the original $origProject = new CProject(); $origProject->load($from_project_id); $q = new DBQuery(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $from_project_id); $q->addWhere('task_id = task_parent'); $sql = $q->prepare(); $q->clear(); $tasks = array_flip(db_loadColumn($sql)); $origDate = new CDate($origProject->project_start_date); $destDate = new CDate($this->project_start_date); $timeOffset = $destDate->getTime() - $origDate->getTime(); // Dependencies array $deps = array(); // Copy each task into this project and get their deps foreach ($tasks as $orig => $void) { $objTask = new CTask(); $objTask->load($orig); $destTask = $objTask->deepCopy($this->project_id); $tasks[$orig] = $destTask; $deps[$orig] = $objTask->getDependencies(); } $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . $this->project_id); $tasks = $q->loadColumn(); // Update dates based on new project's start date. $newTask = new CTask(); foreach ($tasks as $task_id) { $newTask->load($task_id); // Fix task start date from project start date offset $origDate->setDate($newTask->task_start_date); $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME); $destDate = $destDate->next_working_day(); $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL); // Fix task end date from start date + work duration //$newTask->calc_task_end_date(); if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') { $origDate->setDate($newTask->task_end_date); $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME); $destDate = $destDate->next_working_day(); $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL); } $newTask->store(); } // end Fix record integrity }