// Moved all validation over into task.inc.php save() $success = $task->save(); count($msg) and $msg = "&message_good=" . urlencode(implode("<br>", $msg)); if ($success) { interestedParty::make_interested_parties("task", $task->get_id(), $_POST["interestedParty"]); // A task can only have a pending task or pending reopen date - pending task is fixed up in JS, but check here too if ($task->get_value("taskStatus") != "pending_tasks") { $_POST['pendingTaskIDs'] = ''; } $task->add_pending_tasks($_POST["pendingTasksIDs"]); $task->add_tags($_POST["tags"]); // This is only valid on pending_, but not on pending_task (because it has a different field) if (strpos($task->get_value("taskStatus"), "pending_") !== 0 || $task->get_value("taskStatus") == "pending_tasks") { $_POST['reopen_task'] = ''; } $task->add_reopen_reminder($_POST["reopen_task"]); // Create reminders if necessary if ($_POST["createTaskReminder"] == true) { $task->create_task_reminder(); } if ($_POST["save"] && $_POST["view"] == "brief") { #$url = $TPL["url_alloc_taskList"]; $url = $TPL["url_alloc_task"] . "taskID=" . $task->get_id(); } else { if ($_POST["save"] || $_POST["close_task"]) { $url = $TPL["url_alloc_task"] . "taskID=" . $task->get_id(); } else { if ($_POST["save_and_back"]) { $url = $TPL["url_alloc_project"] . "projectID=" . $task->get_value("projectID"); } else { if ($_POST["save_and_summary"]) {
function edit_task($commands, $email_receive) { $task_fields = $this->get_fields("task"); // Task commands if ($commands["task"]) { unset($changes); $taskPriorities = config::get_config_item("taskPriorities") or $taskPriorities = array(); foreach ($taskPriorities as $k => $v) { $priorities[strtolower($v["label"])] = $k; } $people_by_username = person::get_people_by_username(); // Else edit/create the task ... $task = new task(); if ($commands["task"] && strtolower($commands["task"]) != "new") { $task->set_id($commands["task"]); if (!$task->select()) { alloc_error("Unable to select task with ID: " . $commands["task"]); } } foreach ($commands as $k => $v) { // transform from username to personID if ($k == "assign") { $changes[$k] = "personID"; $v = $people_by_username[$v]["personID"]; $v or alloc_error("Unrecognized username."); } if ($k == "manage") { $changes[$k] = "managerID"; $v = $people_by_username[$v]["personID"]; $v or alloc_error("Unrecognized username."); } if ($k == "estimator") { $changes[$k] = "estimatorID"; $v = $people_by_username[$v]["personID"]; $v or alloc_error("Unrecognized username."); } // transform from priority label to priority ID if ($k == "priority" && !in_array($v, array(1, 2, 3, 4, 5))) { $v = $priorities[strtolower($v)]; } // so that --type parent becomes --type Parent // mysql's referential integrity is case-insensitive :( if ($k == "type") { $v = ucwords($v); } // Plug the value in if ($task_fields[$k][0]) { $changes[$k] = $task_fields[$k][0]; $task->set_value($task_fields[$k][0], sprintf("%s", $v)); } } if (isset($commands["pend"])) { $changes["pend"] = implode(",", (array) $task->get_pending_tasks()); } if (isset($commands["reopen"])) { $reopen_rows = $task->get_reopen_reminders(); unset($rr_bits); foreach ($reopen_rows as $rr) { $rr_bits[] = $rr["reminderTime"]; } $changes["reopen"] = implode(",", (array) $rr_bits); } if (isset($commands["tags"])) { $changes["tags"] = implode(",", $task->get_tags()); } if (strtolower($commands["task"]) == "new") { if (!$commands["desc"] && is_object($email_receive)) { $task->set_value("taskDescription", $email_receive->get_converted_encoding()); } } $after_label = "After: "; if (strtolower($commands["task"]) != "new") { $str = $this->condense_changes($changes, $task->row()); $str and $status[] = "msg"; $str and $message[] = "Before: " . $str; } else { $after_label = "Fields: "; } // Save task $err = $task->validate(); if (!$err && $task->save()) { $task->select(); if (isset($commands["pend"])) { $task->add_pending_tasks($commands["pend"]); $changes["pend"] = implode(",", (array) $task->get_pending_tasks()); } if (isset($commands["reopen"])) { $task->add_reopen_reminder($commands["reopen"]); $reopen_rows = $task->get_reopen_reminders(); unset($rr_bits); foreach ($reopen_rows as $rr) { $rr_bits[] = $rr["reminderTime"]; } $changes["reopen"] = implode(",", (array) $rr_bits); } if (isset($commands["tags"])) { $task->add_tags(array($commands["tags"])); $changes["tags"] = implode(",", $task->get_tags()); } $str = $this->condense_changes($changes, $task->row()); $str and $status[] = "msg"; $str and $message[] = $after_label . $str; if ($commands["dip"]) { interestedParty::add_remove_ips($commands["dip"], "task", $task->get_id(), $task->get_value("projectID")); } if (strtolower($commands["task"]) == "new") { $status[] = "yay"; $message[] = "Task " . $task->get_id() . " created."; } else { $status[] = "yay"; $message[] = "Task " . $task->get_id() . " updated."; } // Problems } else { alloc_error("Problem updating task: " . implode("\n", (array) $err)); } } return array($status, $message); }