} // Option 9 - Mark as inactive } elseif ($bulk_task_other == '9') { $upd_task->task_status = '-1'; $result = $upd_task->store($AppUI); if (is_array($result)) { break; } //Option 10 - Empty tasks description } elseif ($bulk_task_other == '10') { $upd_task->task_description = ''; $result = $upd_task->store($AppUI); if (is_array($result)) { break; } //Option 99 (always at the bottom) - Delete } elseif ($bulk_task_other == '99') { $result = $upd_task->delete($AppUI); if (is_array($result)) { break; } } } } echo db_error(); } } if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); } $AppUI->redirect('m=projectdesigner&project_id=' . $project_id);
/** * @todo Parent store could be partially used * @todo Can't delete a task with children */ public function delete(CAppUI $AppUI = null) { global $AppUI; $perms = $AppUI->acl(); $this->_error = array(); if ($perms->checkModuleItem('tasks', 'delete', $this->task_id)) { //load it before deleting it because we need info on it to update the parents later on $this->load($this->task_id); // delete children $childrenlist = $this->getChildren(); foreach ($childrenlist as $child) { $task = new CTask(); $task->task_id = $child; $task->delete($AppUI); } $taskList = $childrenlist + array($this->task_id); $implodedTaskList = implode(',', $taskList); $q = new w2p_Database_Query(); // delete linked user tasks $q->setDelete('user_tasks'); $q->addWhere('task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); // delete affiliated task_dependencies $q->setDelete('task_dependencies'); $q->addWhere('dependencies_task_id IN (' . $implodedTaskList . ') OR dependencies_req_task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); // delete affiliated task_dependencies $q->setDelete('task_contacts'); $q->addWhere('task_id = ' . $this->task_id); if (!$q->exec()) { return db_error(); } if ($msg = parent::delete()) { return $msg; } if ($this->task_parent != $this->task_id) { $this->updateDynamics(); } $last_task_data = $this->getLastTaskData($this->task_project); CProject::updateTaskCache($this->task_project, $last_task_data['task_id'], $last_task_data['last_date'], $this->getTaskCount($this->task_project)); return true; } return false; }
} 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; $upd_task->store(); //Option 6 - Add Task Reminder } elseif ($bulk_task_other == '6') { $upd_task->addReminder(); //Option 7 - Mark as non dynamic } elseif ($bulk_task_other == '7') { $upd_task->clearReminder(true); //Option 8 - Mark as active } elseif ($bulk_task_other == '8') { $upd_task->task_status = '0'; $upd_task->store(); //Option 9 - Mark as inactive } elseif ($bulk_task_other == '9') { $upd_task->task_status = '-1'; $upd_task->store(); //Option 99 (always at the bottom) - Delete } elseif ($bulk_task_other == '99') { $upd_task->delete(); } } } echo db_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 **/ public function importTasks($from_project_id) { global $AppUI; $errors = array(); // Load the original $origProject = new CProject(); $origProject->load($from_project_id); $q = $this->_query; $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_project =' . (int) $from_project_id); $tasks = array_flip($q->loadColumn()); $q->clear(); $origDate = new w2p_Utilities_Date($origProject->project_start_date); $destDate = new w2p_Utilities_Date($this->project_start_date); $timeOffset = $origDate->dateDiff($destDate); if ($origDate->compare($origDate, $destDate) > 0) { $timeOffset = -1 * $timeOffset; } // 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->copy($this->project_id); $tasks[$orig] = $destTask; $deps[$orig] = $objTask->getDependencies(); } // Fix record integrity foreach ($tasks as $old_id => $newTask) { // Fix parent Task // This task had a parent task, adjust it to new parent task_id if ($newTask->task_id != $newTask->task_parent) { $newTask->task_parent = $tasks[$newTask->task_parent]->task_id; } // Fix task start date from project start date offset $origDate->setDate($newTask->task_start_date); $origDate->addDays($timeOffset); $destDate = $origDate; $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL); // Fix task end date from start date + work duration if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') { $origDate->setDate($newTask->task_end_date); $origDate->addDays($timeOffset); $destDate = $origDate; $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL); } // Dependencies if (!empty($deps[$old_id])) { $oldDeps = explode(',', $deps[$old_id]); // New dependencies array $newDeps = array(); foreach ($oldDeps as $dep) { $newDeps[] = $tasks[$dep]->task_id; } // Update the new task dependencies $csList = implode(',', $newDeps); $newTask->updateDependencies($csList); } // end of update dependencies $result = $newTask->store($AppUI); $newTask->addReminder(); $importedTasks[] = $newTask->task_id; if (is_array($result) && count($result)) { foreach ($result as $key => $error_msg) { $errors[] = $newTask->task_name . ': ' . $error_msg; } } } // end Fix record integrity // We have errors, so rollback everything we've done so far if (count($errors)) { foreach ($importedTasks as $badTask) { $delTask = new CTask(); $delTask->task_id = $badTask; $delTask->delete($AppUI); } } return $errors; }
/** * Delete Request Handler * * This method is called when a request is a DELETE * * @return array */ public function executeDelete() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } $username = $this->getParam('username'); $password = $this->getParam('password'); $task_id = $this->getParam('task_id', self::TYPE_INT); // 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'); } $task = new CTask(); $task->load($task_id); if (!$task->delete($AppUI)) { throw new Frapi_Error('PERMISSION_ERROR'); } $this->data['success'] = true; return $this->toArray(); }
/** * @todo Parent store could be partially used * @todo Can't delete a task with children */ public function delete(CAppUI $AppUI = null) { global $AppUI; $q = new DBQuery(); $this->_action = 'deleted'; //load it before deleting it because we need info on it to update the parents later on $this->load($this->task_id); addHistory('tasks', $this->task_id, 'delete', $this->task_name, $this->task_project); // delete children $childrenlist = $this->getChildren(); foreach ($childrenlist as $child) { $task = new CTask(); $task->task_id = $child; $task->delete($AppUI); } $taskList = $childrenlist + array($this->task_id); $implodedTaskList = implode(',', $taskList); // delete linked user tasks $q->setDelete('user_tasks'); $q->addWhere('task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); $q->setDelete('tasks'); $q->addWhere('task_id=' . (int) $this->task_id); if (!$q->exec()) { return db_error(); } elseif ($this->task_parent != $this->task_id) { // Has parent, run the update sequence, this child will no longer be in the // database $this->updateDynamics(); } $q->clear(); // delete affiliated task_logs $q->setDelete('task_log'); $q->addWhere('task_log_task IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); // delete affiliated task_dependencies $q->setDelete('task_dependencies'); $q->addWhere('dependencies_task_id IN (' . $implodedTaskList . ') OR dependencies_req_task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } else { $this->_action = 'deleted'; } $q->clear(); CProject::updateTaskCount($this->task_project, $this->getTaskCount($this->task_project)); return null; }
$t->store(); } if (isset($children)) { foreach ($children as $child_id) { if ($perms->checkModuleItem('tasks', 'edit', $child_t->task_id)) { $child_t = new CTask(); $child_t->load($child_id); $child_t->task_percent_complete = 100; $child_t->store(); } } } } else { if ($action == 'd') { //delete task $t->delete(); //Now task deletion deletes children no matter what. /* //delete children if (isset($children)) { foreach($children as $child) { $t->load($child); $t->delete(); } } */ } else { if ($action == 'm') { //move task if (isset($children)) { $t->deepMove($new_project, $new_task);
} 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; $upd_task->store($AppUI); //Option 6 - Add Task Reminder } elseif ($bulk_task_other == '6') { $upd_task->addReminder(); //Option 7 - Mark as non dynamic } elseif ($bulk_task_other == '7') { $upd_task->clearReminder(true); //Option 8 - Mark as active } elseif ($bulk_task_other == '8') { $upd_task->task_status = '0'; $upd_task->store($AppUI); //Option 10 - Empty tasks description } elseif ($bulk_task_other == '10') { $upd_task->task_description = ''; $upd_task->store($AppUI); //Option 99 (always at the bottom) - Delete } elseif ($bulk_task_other == '99') { $upd_task->delete($AppUI); } } } echo db_error(); } } $AppUI->redirect('m=projectdesigner&project_id=' . $project_id);
$date = new CDate($obj->task_end_date); $obj->task_end_date = $date->format(FMT_DATETIME_MYSQL); } if ($obj->task_start_date_ir) { $date = new CDate($obj->task_start_date_ir); $obj->task_start_date_ir = $date->format(FMT_DATETIME_MYSQL); } if ($obj->task_end_date_ir) { $date = new CDate($obj->task_end_date_ir); $obj->task_end_date_ir = $date->format(FMT_DATETIME_MYSQL); } require_once "./classes/CustomFields.class.php"; //echo '<pre>';print_r( $hassign );echo '</pre>';die; // prepare (and translate) the module name ready for the suffix if ($del) { if ($msg = $obj->delete()) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } else { $AppUI->setMsg('Task deleted'); $AppUI->redirect('', -1); } } else { if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); // Store failed don't continue? } else { $custom_fields = new CustomFields($m, 'addedit', $obj->task_id, "edit"); $custom_fields->bind($_POST); $sql = $custom_fields->store($obj->task_id);
// convert dates to SQL format first if ($obj->task_start_date) { $date = new CDate($obj->task_start_date); $obj->task_start_date = $date->format(FMT_DATETIME_MYSQL); } $end_date = null; if ($obj->task_end_date) { if (strpos($obj->task_end_date, '2400') !== false) { $obj->task_end_date = str_replace('2400', '2359', $obj->task_end_date); } $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)) {
} // Option 9 - Mark as inactive } elseif ($bulk_task_other == '9') { $upd_task->task_status = '-1'; $result = $upd_task->store(); if (!$result) { break; } //Option 10 - Empty tasks description } elseif ($bulk_task_other == '10') { $upd_task->task_description = ''; $result = $upd_task->store(); if (!$result) { break; } //Option 99 (always at the bottom) - Delete } elseif ($bulk_task_other == '99') { $result = $upd_task->delete(); if (!$result) { break; } } } } $AppUI->setMsg($upd_task->getError(), UI_MSG_ERROR); } } if (!$result) { $AppUI->setMsg($result, UI_MSG_ERROR); } $AppUI->redirect('m=projectdesigner&project_id=' . $project_id);