/** * Submit changes to multiple tasks * * @ingroup pages */ function taskEditMultipleSubmit() { global $PH; $ids = getPassedIds('tsk', 'tasks_*'); if (!$ids) { $PH->abortWarning(__("Select some task(s) to mark as approved"), ERROR_NOTE); return; } $count = 0; $errors = 0; $number = get('number'); ### cancel? ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('home'); } exit; } foreach ($ids as $id) { if ($task = Task::getEditableById($id)) { $count++; $change = false; $status_old = $task->status; ### status ### if ($count == 1) { if (!($project = Project::getVisibleById($task->project))) { $PH->abortWarning('could not get project'); } $team = array(); foreach ($project->getPeople() as $p) { $team[$p->id] = $p; } } $task_assigned_people = array(); $task_assignments = array(); $task_people_overwrite = array(); $task_people_new = array(); $task_people_delete = array(); ## previous assigend people ## if ($task_people = $task->getAssignedPeople(false)) { foreach ($task_people as $tp) { $task_assigned_people[$tp->id] = $tp; } } ## previous assignements ## if ($task_assign = $task->getAssignments()) { foreach ($task_assign as $ta) { $task_assignments[$ta->person] = $ta; } } ## different assigned people ## ## overwrite ?? ## $ass1 = get('task_assignement_diff'); if ($ass1 && $ass1 != '__dont_change__') { $task_people_overwrite[] = $ass1; foreach ($task_assignments as $key => $value) { $task_people_delete[] = $value; } $change = true; } ## new ?? ## $ass2 = get('task_assignement_also_diff'); if ($ass2 && $ass2 != '__select_person__') { $task_people_new[] = $ass2; $change = true; } $different = get('different_ass'); if (isset($different) && !$different) { if (isset($task_assignments) && count($task_assignments) != 0) { foreach ($task_assignments as $tid => $t_old) { $id_new = get('task_assign_to_' . $tid); ## no changes ## if ($tid == $id_new) { continue; } if ($id_new == '__none__') { if (!$t_old) { continue; } $task_people_delete[] = $t_old; continue; } $task_people_delete[] = $t_old; $task_people_overwrite[] = $id_new; } } else { $id_new = get('task_assign_to___none__'); if ($id_new && $id_new != '__none__') { $task_people_new[] = $id_new; } } $id_new = get('task_assign_to_0'); if ($id_new != '__select_person__') { if (!isset($task_assignments[$id_new])) { $task_people_new[] = $id_new; } } $change = true; } ### category ### $v = get('task_category'); if (!is_null($v) && $v != '__dont_change__' && $v != $task->category) { $task->category = $v; $change = true; } ### status ### $status = get('task_status'); if ($status && $status != '__dont_change__' && $status != $task->status) { $task->status = $status; $change = true; } ### prio ### $prio = get('task_prio'); if ($prio && $prio != '__dont_change__' && $prio != $task->prio) { $task->prio = $prio; $change = true; } ### pub level ### $pub_level = get('task_pub_level'); if ($pub_level && $pub_level != '__dont_change__' && $pub_level != $task->pub_level) { if ($pub_level > $task->getValidUserSetPublicLevel()) { $PH->abortWarning('invalid data', ERROR_RIGHTS); } $task->pub_level = $pub_level; $change = true; } ### label ### $label = get('task_label'); if ($label && $label != '__dont_change__' && $label != $task->label) { $task->label = $label; $change = true; } ### for milestone ### $fm = get('task_for_milestone'); if (!is_null($fm) && $fm != '__dont_change__' && $task->for_milestone != $fm) { if ($fm) { if (($m = Task::getVisibleById($fm)) && $m->isMilestoneOrVersion()) { $task->for_milestone = $fm; $change = true; } else { continue; } } else { $task->for_milestone = 0; $change = true; } } ### resolve version ### $rv = get('task_resolved_version'); if (!is_null($rv) && $rv != '__dont_change__' && $task->resolved_version != $rv) { if ($rv && $rv != -1) { if ($v = Task::getVisibleById($rv)) { if ($v->isMilestoneOrVersion()) { $task->resolved_version = $rv; $change = true; } } else { continue; } } else { if ($rv == -1) { $task->resolved_version = $rv; $change = true; } else { $task->resolved_version = 0; $change = true; } } } ### resolve reason ### $rs = get('task_resolve_reason'); if ($rs && $rs != '__dont_change__' && $rs != $rs->resolve_reason) { $task->resolve_reason = $rs; $change = true; } if ($change) { ### Check if now longer new ### if ($status_old == $task->status && $task->status == STATUS_NEW) { global $auth; if ($task->created < $auth->cur_user->last_login) { $task->status = STATUS_OPEN; } } ## overwrite assigend people ## if (isset($task_people_overwrite)) { if (isset($task_people_delete)) { foreach ($task_people_delete as $tpd) { $tpd->delete(); } } foreach ($task_people_overwrite as $tpo) { $task_pers_over = new TaskPerson(array('person' => $team[$tpo]->id, 'task' => $task->id, 'comment' => '', 'project' => $project->id)); $task_pers_over->insert(); } } ## add new person ## if (isset($task_people_new)) { foreach ($task_people_new as $tpn) { if (!isset($task_assigned_people[$tpn])) { $task_pers_new = new TaskPerson(array('person' => $team[$tpn]->id, 'task' => $task->id, 'comment' => '', 'project' => $project->id)); $task_pers_new->insert(); } } } ##update## $task->update(); $task->nowChangedByUser(); } } else { $errors++; } } ### compose message ### if ($errors) { new FeedbackWarning(sprintf(__('%s tasks could not be written'), $errors)); } else { if ($count) { new FeedbackMessage(sprintf(__('Updated %s tasks tasks'), $count)); } } ### return to from-page? ### if (!$PH->showFromPage()) { $PH->show('taskView', array('tsk' => $task->id)); } }