if ($_POST["mass_update"]) { if ($_POST["select"]) { $allowed_auto_fields = array("dateTargetStart", "dateTargetCompletion", "dateActualStart", "dateActualCompletion", "managerID", "timeLimit", "timeBest", "timeWorst", "timeExpected", "priority", "taskTypeID", "taskStatus", "personID"); foreach ($_POST["select"] as $taskID => $selected) { $task = new task(); $task->set_id($taskID); $task->select(); // Special case: projectID and parentTaskID have to be done together if ($_POST["update_action"] == "projectIDAndParentTaskID") { // Can't set self to be parent if ($_POST["parentTaskID"] != $task->get_id()) { $task->set_value("parentTaskID", $_POST["parentTaskID"]); } // If task is a parent, change the project of that tasks children if ($_POST["projectID"] != $task->get_value("projectID") && $task->get_value("taskTypeID") == "Parent") { $task->update_children("projectID", $_POST["projectID"]); } $task->set_value("projectID", $_POST["projectID"]); $task->updateSearchIndexLater = true; $task->save(); // All other cases are generic and can be handled by a single clause } else { if ($_POST["update_action"] && in_array($_POST["update_action"], $allowed_auto_fields)) { $task->set_value($_POST["update_action"], $_POST[$_POST["update_action"]]); $task->updateSearchIndexLater = true; $task->save(); } } } $TPL["message_good"][] = "Tasks updated."; $url = $_POST["returnURL"] or $url = $TPL["url_alloc_taskList"];
function update_children($field, $value = "") { $q = prepare("SELECT * FROM task WHERE parentTaskID = %d", $this->get_id()); $db = new db_alloc(); $db->query($q); while ($db->row()) { $t = new task(); $t->read_db_record($db); $t->set_value($field, $value); $t->save(); if ($t->get_value("taskTypeID") == "Parent") { $t->update_children($field, $value); } } }