public function print_automatic()
 {
     global $PH;
     global $auth;
     $this->active_block_function = 'list';
     $this->query_options['person'] = $auth->cur_user->id;
     $this->query_options['forward'] = 1;
     $this->query_options['state'] = 1;
     $task_people = TaskPerson::getTaskPeople($this->query_options);
     $this->render_list($task_people);
 }
Пример #2
0
 /**
  * query if editable for current user
  */
 static function getEditableById($id)
 {
     if ($tp = TaskPerson::getById(intval($id))) {
         if ($p = Project::getById($tp->project)) {
             if ($p->validateEditItem($tp)) {
                 return $tp;
             }
         }
     }
     return NULL;
 }
Пример #3
0
/**
* 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));
    }
}
Пример #4
0
/**
* Submit changes to a task
*
* @ingroup pages
*/
function taskEditSubmit()
{
    global $PH;
    global $auth;
    require_once confGet('DIR_STREBER') . 'db/class_taskperson.inc.php';
    /**
     * keep a list of items linking to this task, task is new
     * we have to change the linking id after(!) inserting the task
     */
    $link_items = array();
    ### temporary object or from database? ###
    $tsk_id = getOnePassedId('tsk', '', true, 'invalid id');
    if ($tsk_id == 0) {
        $task = new Task(array('id' => 0, 'project' => get('task_project')));
        $was_category = 0;
        # undefined category for new tasks
        $was_resolved_version = 0;
    } else {
        if (!($task = Task::getVisiblebyId($tsk_id))) {
            $PH->abortWarning("invalid task-id");
        }
        $was_category = $task->category;
        $was_resolved_version = $task->resolved_version;
        $task->validateEditRequestTime();
    }
    ### cancel? ###
    if (get('form_do_cancel')) {
        if (!$PH->showFromPage()) {
            $PH->show('taskView', array('tsk' => $task->id));
        }
        exit;
    }
    ### Validate integrety ###
    if (!validateFormCrc()) {
        $PH->abortWarning(__('Invalid checksum for hidden form elements'));
    }
    validateFormCaptcha(true);
    $was_a_folder = $task->category == TCATEGORY_FOLDER ? true : false;
    $was_released_as = $task->is_released;
    ### get project ###
    if (!($project = Project::getVisiblebyId($task->project))) {
        $PH->abortWarning("task without project?");
    }
    /**
     * adding comment (from quick edit) does only require view right...
     */
    $added_comment = false;
    ### check for request feedback
    if ($request_feedback = get('request_feedback')) {
        $team_members_by_nickname = array();
        foreach ($project->getProjectPeople() as $pp) {
            $team_members_by_nickname[$pp->getPerson()->nickname] = $pp->getPerson();
        }
        $requested_people = array();
        foreach (explode('\\s*,\\s*', $request_feedback) as $nickname) {
            ### now check if this nickname is a team member
            if ($nickname = trim($nickname)) {
                if (isset($team_members_by_nickname[$nickname])) {
                    $person = $team_members_by_nickname[$nickname];
                    ### update to itemperson table...
                    if ($view = ItemPerson::getAll(array('person' => $person->id, 'item' => $task->id))) {
                        $view[0]->feedback_requested_by = $auth->cur_user->id;
                        $view[0]->update();
                    } else {
                        $new_view = new ItemPerson(array('item' => $task->id, 'person' => $person->id, 'feedback_requested_by' => $auth->cur_user->id));
                        $new_view->insert();
                    }
                    $requested_people[] = "<b>" . asHtml($nickname) . "</b>";
                } else {
                    new FeedbackWarning(sprintf(__("Nickname not known in this project: %s"), "<b>" . asHtml($nickname) . "</b>"));
                }
            }
        }
        if ($requested_people) {
            new FeedbackMessage(sprintf(__('Requested feedback from: %s.'), join($requested_people, ", ")));
        }
    }
    ### only insert the comment, when comment name or description are valid
    if (get('comment_name') || get('comment_description')) {
        require_once confGet('DIR_STREBER') . 'pages/comment.inc.php';
        $valid_comment = true;
        ### new object? ###
        $comment = new Comment(array('name' => get('comment_name'), 'description' => get('comment_description'), 'project' => $task->project, 'task' => $task->id));
        validateNotSpam($comment->name . $comment->description);
        ### write to db ###
        if ($valid_comment) {
            if (!$comment->insert()) {
                new FeedbackWarning(__("Failed to add comment"));
            } else {
                ### change task update modification date ###
                if (isset($task)) {
                    ### Check if now longer new ###
                    if ($task->status == STATUS_NEW) {
                        global $auth;
                        if ($task->created < $auth->cur_user->last_login) {
                            $task->status = STATUS_OPEN;
                        }
                    }
                    $task->update(array('modified', 'status'));
                }
                $added_comment = true;
            }
        }
    }
    if ($task->id != 0 && !Task::getEditableById($task->id)) {
        if ($added_comment) {
            ### display taskView ####
            if (!$PH->showFromPage()) {
                $PH->show('home', array());
            }
            exit;
        } else {
            $PH->abortWarning(__("Not enough rights to edit task"));
        }
    }
    $task->validateEditRequestTime();
    $status_old = $task->status;
    # retrieve all possible values from post-data (with field->view_in_forms == true)
    # NOTE:
    # - this could be an security-issue.
    # @@@ TODO: as some kind of form-edit-behaviour to field-definition
    foreach ($task->fields as $f) {
        $name = $f->name;
        $f->parseForm($task);
    }
    $task->fields['parent_task']->parseForm($task);
    ### category ###
    $was_of_category = $task->category;
    if (!is_null($c = get('task_category'))) {
        global $g_tcategory_names;
        if (isset($g_tcategory_names[$c])) {
            $task->category = $c;
        } else {
            trigger_error("ignoring unknown task category '{$c}'", E_USER_NOTICE);
        }
    }
    /**
     * @@@pixtur 2006-11-17: actually this has been depreciated. is_folder updated
     * for backward compatibility only.
     */
    $task->is_folder = $task->category == TCATEGORY_FOLDER ? 1 : 0;
    ### 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;
        }
    }
    $assigned_people = array();
    $task_assignments = array();
    if ($task->id) {
        foreach ($task->getAssignedPeople() as $p) {
            $assigned_people[$p->id] = $p;
        }
        foreach ($task->getAssignments() as $ta) {
            $task_assignments[$ta->person] = $ta;
        }
    }
    $team = array();
    foreach ($project->getPeople() as $p) {
        $team[$p->id] = $p;
    }
    $new_task_assignments = array();
    # store assigments after(!) validation
    $forwarded = 0;
    $forward_comment = '';
    $old_task_assignments = array();
    if (isset($task_assignments)) {
        foreach ($task_assignments as $id => $t_old) {
            $id_new = get('task_assigned_to_' . $id);
            $forward_state = get('task_forward_to_' . $id);
            if ($forward_state) {
                $forwarded = 1;
            } else {
                $forwarded = 0;
            }
            $forward_comment = get('task_forward_comment_to_' . $id);
            if ($id_new === NULL) {
                log_message("failure. Can't change no longer existing assigment (person-id={$id} item-id={$t_old->id})", LOG_MESSAGE_DEBUG);
                #$PH->abortWarning("failure. Can't change no longer existing assigment",ERROR_NOTE);
                continue;
            }
            if ($id == $id_new) {
                if ($tp = TaskPerson::getTaskPeople(array('person' => $id, 'task' => $task->id))) {
                    $tp[0]->forward = $forwarded;
                    $tp[0]->forward_comment = $forward_comment;
                    $old_task_assignments[] = $tp[0];
                }
                #echo " [$id] {$team[$id]->name} still assigned<br>";
                continue;
            }
            if ($id_new == 0) {
                if (!$t_old) {
                    continue;
                }
                #echo " [$id] {$team[$id]->name} unassigned<br>";
                $t_old->delete();
                continue;
            }
            #$t_new= $task_assignments[$id_new];
            $p_new = @$team[$id_new];
            if (!isset($p_new)) {
                $PH->abortWarning("failure during form-value passing", ERROR_BUG);
            }
            #echo " [$id] assignment changed from {$team[$id]->name} to {$team[$id_new]->name}<br>";
            $t_old->comment = sprintf(__("unassigned to %s", "task-assignment comment"), $team[$id_new]->name);
            $t_old->update();
            $t_old->delete();
            $new_assignment = new TaskPerson(array('person' => $team[$id_new]->id, 'task' => $task->id, 'comment' => sprintf(__("formerly assigned to %s", "task-assigment comment"), $team[$id]->name), 'project' => $project->id, 'forward' => $forwarded, 'forward_comment' => $forward_comment));
            $new_task_assignments[] = $new_assignment;
            $link_items[] = $new_assignment;
        }
    }
    ### check new assigments ###
    $count = 0;
    while ($id_new = get('task_assign_to_' . $count)) {
        $forward_state = get('task_forward_to_' . $count);
        if ($forward_state) {
            $forwarded = 1;
        } else {
            $forwarded = 0;
        }
        $forward_comment = get('task_forward_comment_to_' . $count);
        $count++;
        ### check if already assigned ###
        if (isset($task_assignments[$id_new])) {
            if ($tp = TaskPerson::getTaskPeople(array('person' => $id_new, 'task' => $task->id))) {
                $tp[0]->forward = $forwarded;
                $tp[0]->forward_comment = $forward_comment;
                $old_task_assignments[] = $tp[0];
            }
            #new FeedbackMessage(sprintf(__("task was already assigned to %s"),$team[$id_new]->name));
        } else {
            if (!isset($team[$id_new])) {
                $PH->abortWarning("unknown person id {$id_new}", ERROR_DATASTRUCTURE);
            }
            $new_assignment = new TaskPerson(array('person' => $team[$id_new]->id, 'task' => $task->id, 'comment' => "", 'project' => $project->id, 'forward' => $forwarded, 'forward_comment' => $forward_comment));
            /**
             * BUG?
             * - inserting the new assigment before sucessfully validating the
             *   task will lead to double-entries in the database.
             */
            $new_task_assignments[] = $new_assignment;
            #$new_assignment->insert();
            $link_items[] = $new_assignment;
        }
    }
    if ($task->isOfCategory(array(TCATEGORY_VERSION, TCATEGORY_MILESTONE))) {
        if ($is_released = get('task_is_released')) {
            if (!is_null($is_released)) {
                $task->is_released = $is_released;
            }
        }
    }
    ### pub level ###
    if ($pub_level = get('task_pub_level')) {
        if ($task->id) {
            if ($pub_level > $task->getValidUserSetPublicLevels()) {
                $PH->abortWarning('invalid data', ERROR_RIGHTS);
            }
        }
        #else {
        #    #@@@ check for person create rights
        #}
        $task->pub_level = $pub_level;
    }
    ### check project ###
    if ($task->id == 0) {
        if (!($task->project = get('task_project'))) {
            $PH->abortWarning("task requires project to be set");
        }
    }
    ### get parent_task ###
    $is_ok = true;
    $parent_task = NULL;
    if ($task->parent_task) {
        $parent_task = Task::getVisibleById($task->parent_task);
    }
    ### validate ###
    if (!$task->name) {
        new FeedbackWarning(__("Task requires name"));
        $task->fields['name']->required = true;
        $task->fields['name']->invalid = true;
        $is_ok = false;
    } else {
        if ($task->id == 0) {
            $other_tasks = array();
            if ($parent_task) {
                $other_tasks = Task::getAll(array('project' => $project->id, 'parent_task' => $parent_task->id, 'status_min' => STATUS_NEW, 'status_max' => STATUS_CLOSED, 'visible_only' => false));
            } else {
                $other_tasks = Task::getAll(array('project' => $project->id, 'parent_task' => 0, 'status_min' => STATUS_NEW, 'status_max' => STATUS_CLOSED, 'visible_only' => false));
            }
            foreach ($other_tasks as $ot) {
                if (!strcasecmp($task->name, $ot->name)) {
                    $is_ok = false;
                    new FeedbackWarning(sprintf(__('Task called %s already exists'), $ot->getLink(false)));
                    break;
                }
            }
        }
    }
    ### automatically close resolved tasks ###
    if ($task->resolve_reason && $task->status < STATUS_COMPLETED) {
        $task->status = STATUS_COMPLETED;
        new FeedbackMessage(sprintf(__('Because task is resolved, its status has been changed to completed.')));
    }
    ### Check if resolved tasks should be completed ###
    if ($task->resolved_version != 0 && $task->status < STATUS_COMPLETED) {
        new FeedbackWarning(sprintf(__('Task has resolved version but is not completed?')));
        $task->fields['resolved_version']->invalid = true;
        $task->fields['status']->invalid = true;
        $is_ok = false;
    }
    ### Check if completion should be 100% ###
    if ($task->status >= STATUS_COMPLETED) {
        $task->completion = 100;
    }
    ### repeat form if invalid data ###
    if (!$is_ok) {
        $PH->show('taskEdit', NULL, $task);
        exit;
    }
    #--- write to database -----------------------------------------------------------------------
    #--- be sure parent-task is folder ---
    if ($parent_task) {
        if ($parent_task->isMilestoneOrVersion()) {
            if ($parent_task->is_folder) {
                $parent_task->is_folder = 0;
                $parent_task->update(array('is_folder'), false);
            }
            $PH->abortWarning(__("Milestones may not have sub tasks"));
        } else {
            if ($parent_task->category != TCATEGORY_FOLDER) {
                $parent_task->category = TCATEGORY_FOLDER;
                $parent_task->is_folder = 1;
                if ($parent_task->update()) {
                    new FeedbackMessage(__("Turned parent task into a folder. Note, that folders are only listed in tree"));
                } else {
                    trigger_error(__("Failed, adding to parent-task"), E_USER_WARNING);
                    $PH->abortWarning(__("Failed, adding to parent-task"));
                }
            }
        }
    }
    ### ungroup child tasks? ###
    if ($was_a_folder && $task->category != TCATEGORY_FOLDER) {
        $num_subtasks = $task->ungroupSubtasks();
        # @@@ does this work???
        /**
         * note: ALSO invisible tasks should be updated, so do not check for visibility here.
         */
        $parent = Task::getById($task->parent_task);
        $parent_str = $parent ? $parent->name : __('Project');
        if ($num_subtasks) {
            new FeedbackMessage(sprintf(__("NOTICE: Ungrouped %s subtasks to <b>%s</b>"), $num_subtasks, $parent_str));
        }
    }
    if ($task->id && !get('task_issue_report')) {
        $task_issue_report = $task->issue_report;
    } else {
        if ($task->issue_report != get('task_issue_report')) {
            trigger_error("Requesting invalid issue report id for task!", E_USER_WARNING);
            $task_issue_report = get('task_issue_report');
        } else {
            $task_issue_report = 0;
        }
    }
    ### consider issue-report? ###
    #$task_issue_report= get('task_issue_report');
    if ($task->category == TCATEGORY_BUG || isset($task_issue_report) && $task_issue_report) {
        ### new report as / temporary ###
        if ($task_issue_report == 0 || $task_issue_report == -1) {
            $issue = new Issue(array('id' => 0, 'project' => $project->id, 'task' => $task->id));
            ### querry form-information ###
            foreach ($issue->fields as $f) {
                $name = $f->name;
                $f->parseForm($issue);
            }
            global $g_reproducibility_names;
            if (!is_null($rep = get('issue_reproducibility'))) {
                if (isset($g_reproducibility_names[$rep])) {
                    $issue->reproducibility = intval($rep);
                } else {
                    $issue->reproducibility = REPRODUCIBILITY_UNDEFINED;
                }
            }
            global $g_severity_names;
            if (!is_null($sev = get('issue_severity'))) {
                if (isset($g_severity_names[$sev])) {
                    $issue->severity = intval($sev);
                } else {
                    $issue->severity = SEVERITY_UNDEFINED;
                }
            }
            ### write to db ###
            if (!$issue->insert()) {
                trigger_error("Failed to insert issue to db", E_USER_WARNING);
            } else {
                $link_items[] = $issue;
                $task->issue_report = $issue->id;
            }
        } else {
            if ($issue = Issue::getById($task_issue_report)) {
                ### querry form-information ###
                foreach ($issue->fields as $f) {
                    $name = $f->name;
                    $f->parseForm($issue);
                }
                global $g_reproducibility_names;
                if (!is_null($rep = get('issue_reproducibility'))) {
                    if (isset($g_reproducibility_names[$rep])) {
                        $issue->reproducibility = intval($rep);
                    } else {
                        $issue->reproducibility = REPRODUCIBILITY_UNDEFINED;
                    }
                }
                global $g_severity_names;
                if (!is_null($sev = get('issue_severity'))) {
                    if (isset($g_severity_names[$sev])) {
                        $issue->severity = intval($sev);
                    } else {
                        $issue->severity = SEVERITY_UNDEFINED;
                    }
                }
                ### write to db ###
                if (!$issue->update()) {
                    trigger_error("Failed to write issue to DB (id={$issue->id})", E_USER_WARNING);
                }
                if ($task->issue_report != $issue->id) {
                    # additional check, actually not necessary
                    trigger_error("issue-report as invalid id ({$issue->id}). Should be ({$task->issue_report}) Please report this bug.", E_USER_WARNING);
                }
            } else {
                trigger_error("Could not get issue with id {$task->issue_report} from database", E_USER_WARNING);
            }
        }
    }
    ### write to db ###
    if ($task->id == 0) {
        $task->insert();
        ### write task-assigments ###
        foreach ($new_task_assignments as $nta) {
            $nta->insert();
        }
        ### now we now the id of the new task, link the other items
        foreach ($link_items as $i) {
            $i->task = $task->id;
            $i->update();
        }
        new FeedbackMessage(sprintf(__("Created %s %s with ID %s", "Created <type> <name> with ID <id>..."), $task->getLabel(), $task->getLink(false), $task->id));
    } else {
        ### write task-assigments ###
        foreach ($new_task_assignments as $nta) {
            $nta->insert();
        }
        foreach ($old_task_assignments as $ota) {
            $ota->update();
        }
        new FeedbackMessage(sprintf(__("Changed %s %s with ID %s", "type,link,id"), $task->getLabel(), $task->getLink(false), $task->id));
        $task->update();
        $project->update(array(), true);
    }
    ### add any recently resolved tasks if this is a just released version  ###
    if ($task->category == TCATEGORY_VERSION && $was_category != TCATEGORY_VERSION) {
        if ($resolved_tasks = Task::getAll(array('project' => $task->project, 'status_min' => 0, 'status_max' => 10, 'resolved_version' => RESOLVED_IN_NEXT_VERSION))) {
            foreach ($resolved_tasks as $rt) {
                $rt->resolved_version = $task->id;
                $rt->update(array('resolved_version'));
            }
            new FeedbackMessage(sprintf(__('Marked %s tasks to be resolved in this version.'), count($resolved_tasks)));
        }
    }
    ### notify on change ###
    $task->nowChangedByUser();
    ### create another task ###
    if (get('create_another')) {
        ### build dummy form ###
        $newtask = new Task(array('id' => 0, 'name' => __('Name'), 'project' => $task->project, 'state' => 1, 'prio' => $task->prio, 'label' => $task->label, 'parent_task' => $task->parent_task, 'for_milestone' => $task->for_milestone, 'category' => $task->category));
        $PH->show('taskEdit', array('tsk' => $newtask->id), $newtask);
    } else {
        ### go to task, if new
        if ($tsk_id == 0) {
            $PH->show('taskView', array('tsk' => $task->id));
            exit;
        } else {
            if (!$PH->showFromPage()) {
                $PH->show('home', array());
            }
        }
    }
}
Пример #5
0
 static function getChangeLines($query_options)
 {
     global $PH;
     global $auth;
     fillMissingValues($query_options, array('alive_only' => false));
     $date_compare = isset($query_options['date_min']) ? $query_options['date_min'] : "0000-00-00";
     /**
      * get list of items touched by other people
      */
     $changed_items = DbProjectItem::getAll($query_options);
     /**
      * go through list
      */
     $changes = array();
     foreach ($changed_items as $i) {
         $change_type = NULL;
         if (!isset($query_options['project'])) {
             $project = Project::getVisibleById($i->project);
         } else {
             $project = NULL;
         }
         /**
          * get item-change-type depeding on dates
          */
         if ($i->deleted >= $i->modified) {
             $change_type = ITEM_DELETED;
         } else {
             if ($i->modified > $i->created) {
                 $change_type = ITEM_MODIFIED;
             } else {
                 $change_type = ITEM_NEW;
             }
         }
         /**
          * build up change-list
          */
         switch ($change_type) {
             case ITEM_NEW:
                 if ($i->type == ITEM_TASK) {
                     if (!($task = Task::getVisibleById($i->id))) {
                         continue;
                     }
                     if ($assigned_people = $task->getAssignedPeople()) {
                         $tmp = array();
                         foreach ($assigned_people as $ap) {
                             $tmp[] = $ap->getLink();
                         }
                         $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp);
                     } else {
                         $html_assignment = '';
                     }
                     $html_details = '';
                     if ($tmp = $task->getFolderLinks(true, $project)) {
                         $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp;
                     }
                     if ($task->prio != PRIO_NORMAL && $task->prio != PRIO_UNDEFINED) {
                         global $g_prio_names;
                         $html_details .= ' / ' . $g_prio_names[$task->prio];
                     }
                     $change = new ChangeLine(array('item' => $task, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => '<span class=new>' . __('new') . ' ' . $task->getLabel() . '</span>', 'txt_what' => __('new') . ' ' . $task->getLabel(), 'type' => ChangeLine::NEW_TASK, 'html_assignment' => $html_assignment, 'html_details' => $html_details));
                     $changes[] = $change;
                 } else {
                     if ($i->type == ITEM_FILE) {
                         require_once confGet('DIR_STREBER') . 'db/class_file.inc.php';
                         if ($file = File::getVisibleById($i->id)) {
                             $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('New file'), 'txt_what' => __('New file'), 'type' => ChangeLine::NEW_FILE, 'html_details' => $file->name));
                             $changes[] = $change;
                         }
                     }
                 }
                 break;
             case ITEM_MODIFIED:
                 $timestamp_last_change = $date_compare;
                 # make sure we use the last occured change type
                 /**
                  * modified tasks
                  */
                 $type = ChangeLine::UPDATED;
                 if ($i->type == ITEM_TASK) {
                     if (!($task = Task::getVisibleById($i->id))) {
                         continue;
                     }
                     if ($assigned_people = $task->getAssignedPeople()) {
                         $tmp = array();
                         foreach ($assigned_people as $ap) {
                             $tmp[] = $ap->getLink();
                         }
                         $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp);
                     } else {
                         $html_assignment = '';
                     }
                     $html_details = '';
                     if ($tmp = $task->getFolderLinks(true, $project)) {
                         $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp;
                     }
                     $txt_what = $html_what = __('modified');
                     $type = ChangeLine::UPDATED;
                     $html_comment = '';
                     if ($comments = Comment::getAll(array('person' => $i->modified_by, 'task' => $task->id, 'date_min' => $timestamp_last_change, 'order_by' => 'created ASC'))) {
                         $last_comment = $comments[count($comments) - 1];
                         $timestamp_last_change = $last_comment->created;
                         if ($last_comment->name && $last_comment->name != __('New Comment')) {
                             # ignore default title
                             $html_comment = strip_tags($last_comment->name) . ': ';
                         }
                         $html_comment .= strip_tags($last_comment->description);
                         $html_comment = asHtml($html_comment);
                     }
                     ### get changed fields ###
                     $changed_fields_hash = array();
                     $html_functions = false;
                     if ($changed_fields_list = ItemChange::getItemChanges(array('item' => $i->id, 'person' => $i->modified_by, 'date_min' => $date_compare))) {
                         foreach ($changed_fields_list as $cf) {
                             $changed_fields_hash[$cf->field] = $cf;
                         }
                         if (isset($changed_fields_hash['status'])) {
                             $status_old = $changed_fields_hash['status']->value_old;
                             if ($task->status == STATUS_COMPLETED && $task->status > $status_old) {
                                 $txt_what = $html_what = __('completed') . ' ' . $task->getLabel();
                                 $html_functions = $PH->getLink('tasksApproved', __('Approve Task'), array('tsk' => $task->id));
                                 unset($changed_fields_hash['status']);
                             } else {
                                 if ($task->status == STATUS_APPROVED && $task->status > $status_old) {
                                     $txt_what = $html_what = __('approved');
                                     unset($changed_fields_hash['status']);
                                 } else {
                                     if ($task->status == STATUS_CLOSED && $task->status > $status_old) {
                                         $txt_what = $html_what = __('closed');
                                         unset($changed_fields_hash['status']);
                                     } else {
                                         if ($task->status == STATUS_OPEN && $task->status < $status_old) {
                                             $txt_what = $html_what = __('reopened');
                                             unset($changed_fields_hash['status']);
                                         } else {
                                             if ($task->status == STATUS_OPEN) {
                                                 unset($changed_fields_hash['status']);
                                             } else {
                                                 if ($task->status == STATUS_BLOCKED) {
                                                     $txt_what = $html_what = __('is blocked');
                                                     unset($changed_fields_hash['status']);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($changed_fields_hash['parent_task'])) {
                         $txt_what = $html_what = __('moved');
                         $type = ChangeLine::MOVED;
                         unset($changed_fields_hash['parent_task']);
                     } else {
                         if (count($changed_fields_hash) == 1 && isset($changed_fields_hash['name'])) {
                             $txt_what = $html_what = __('renamed');
                             $type = ChangeLine::RENAMED;
                         } else {
                             if (count($changed_fields_hash) == 1 && isset($changed_fields_hash['description'])) {
                                 $txt_what = $html_what = __('edit wiki');
                                 $type = ChangeLine::EDITED_WIKI;
                             } else {
                                 if (count($changed_fields_hash)) {
                                     # status does not count
                                     $html_details .= ' / ' . __('changed:') . ' ' . implode(', ', array_keys($changed_fields_hash));
                                 } else {
                                     if ($html_comment) {
                                         $txt_what = $html_what = __('commented');
                                         $type = ChangeLine::COMMENTED;
                                     }
                                 }
                             }
                         }
                     }
                     if ($html_comment) {
                         $html_details .= ' / ' . $html_comment;
                     }
                     /**
                      * any recents assignments ?
                      * - to avoid confusion only list assignmets if it was to last action,
                      *
                      */
                     require_once "db/class_taskperson.inc.php";
                     $count_assignments = 0;
                     if ($assignments = TaskPerson::getTaskPeople(array('task' => $task->id, 'project' => $task->project, 'date_min' => $task->modified))) {
                         $t_timestamp = '';
                         foreach ($assignments as $a) {
                             if ($a->person != $task->modified_by && $a->created_by == $task->modified_by && $a->assigntype != ASSIGNTYPE_INITIAL) {
                                 $t_timestamp = $a->created;
                                 $count_assignments++;
                             }
                         }
                         if ($count_assignments && $timestamp_last_change < $t_timestamp) {
                             $type = ChangeLine::ASSIGNED;
                             $txt_what = $html_what = __('assigned');
                             $timestamp_last_change = $t_timestamp;
                         }
                         if ($html_comment) {
                             $html_details .= ' / ' . $html_comment;
                         }
                     }
                     /**
                      * any recents attachments by last editor ?
                      */
                     require_once "db/class_file.inc.php";
                     if ($files = File::getAll(array('parent_item' => $task->id, 'project' => $task->project, 'date_min' => $date_compare, 'created_by' => $task->modified_by))) {
                         $count_attached_files = 0;
                         $html_attached = __("attached") . ": ";
                         $t_timestamp = '';
                         $separator = '';
                         foreach ($files as $f) {
                             if ($task->modified_by == $f->modified_by) {
                                 $t_timestamp = $f->created;
                                 $count_attached_files++;
                                 $html_attached .= $separator . $PH->getLink('fileView', $f->name, array('file' => $f->id));
                                 $separator = ', ';
                             }
                         }
                         if ($count_attached_files) {
                             $type = ChangeLine::ATTACHED_FILE;
                             $txt_what = $html_what = __('attached file to');
                             if ($timestamp_last_change < $t_timestamp) {
                                 $html_details .= ' / ' . $html_attached;
                                 $timestamp_last_change = $t_timestamp;
                             }
                         }
                     }
                     if (count($changed_fields_hash)) {
                         $html_details .= " / " . $PH->getLink('itemViewDiff', NULL, array('item' => $task->id, 'date1' => $date_compare, 'date2' => gmdate("Y-m-d H:i:s")));
                     }
                     if ($html_functions) {
                         $html_details .= " | " . $html_functions;
                     }
                     $change = new ChangeLine(array('person_by' => $i->modified_by, 'timestamp' => $i->modified, 'item_id' => $i->id, 'item' => $task, 'type' => $type, 'txt_what' => $txt_what, 'html_what' => $html_what, 'html_assignment' => $html_assignment, 'html_details' => $html_details));
                     $changes[] = $change;
                 } else {
                     if ($i->type == ITEM_FILE) {
                         require_once confGet('DIR_STREBER') . 'db/class_file.inc.php';
                         if ($file = File::getVisibleById($i->id)) {
                             $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('changed File'), 'txt_what' => __('changed File'), 'type' => ChangeLine::NEW_FILE, 'html_details' => $file->name));
                             $changes[] = $change;
                         }
                     }
                 }
                 break;
             case ITEM_DELETED:
                 /**
                  * deleted tasks
                  */
                 if ($i->type == ITEM_TASK) {
                     if (!($task = Task::getVisibleById($i->id))) {
                         continue;
                     }
                     if ($assigned_people = $task->getAssignedPeople()) {
                         $tmp = array();
                         foreach ($assigned_people as $ap) {
                             $tmp[] = $ap->getLink();
                         }
                         $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp);
                     } else {
                         $html_assignment = '';
                     }
                     $html_details = '';
                     if ($tmp = $task->getFolderLinks(true, $project)) {
                         $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp;
                     }
                     $html_details .= '|' . $PH->getLink('itemsRestore', __('restore'), array('item' => $task->id));
                     $txt_what = $html_what = __('deleted');
                     $change = new ChangeLine(array('item' => $task, 'person_by' => $i->deleted_by, 'timestamp' => $i->deleted, 'item_id' => $i->id, 'type' => ChangeLine::DELETED, 'txt_what' => $txt_what, 'html_what' => $html_what, 'html_assignment' => $html_assignment, 'html_details' => $html_details));
                     $changes[] = $change;
                 } else {
                     if ($i->type == ITEM_FILE) {
                         require_once confGet('DIR_STREBER') . 'db/class_file.inc.php';
                         if ($file = File::getVisibleById($i->id)) {
                             $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('deleted File'), 'txt_what' => ChangeLine::DELETED, 'html_details' => $file->name));
                             $changes[] = $change;
                         }
                     }
                 }
                 break;
             default:
                 trigger_error("unknown change-type {$change_type}", E_USER_WARNING);
                 break;
         }
     }
     return $changes;
 }
Пример #6
0
 function render_tr(&$obj, $style = "")
 {
     global $PH;
     $str_url = "";
     $str_name = "";
     $str_addon = "";
     switch ($obj->type) {
         case ITEM_PROJECT:
             if ($project = Project::getVisibleById($obj->id)) {
                 $str_name = asHtml($project->name);
                 $str_url = $PH->getUrl('projView', array('prj' => $project->id));
             }
             break;
         case ITEM_TASK:
             if ($task = Task::getVisibleById($obj->id)) {
                 $str_name = asHtml($task->name);
                 $str_url = $PH->getUrl('taskView', array('tsk' => $task->id));
                 if ($project = Project::GetVisibleById($task->project)) {
                     $str_addon = "(" . $project->getLink(false) . ")";
                 }
             }
             break;
         case ITEM_COMMENT:
             if ($comment = Comment::getVisibleById($obj->id)) {
                 if ($comment->name == '') {
                     $str_name = "-";
                 } else {
                     $str_name = asHtml($comment->name);
                 }
                 $str_url = $PH->getUrl('taskView', array('tsk' => $comment->task));
                 $str_addon .= "(";
                 if ($task = Task::getVisibleById($comment->task)) {
                     if ($project = Project::getVisibleById($task->project)) {
                         $str_addon .= $project->getLink(false) . " > ";
                     }
                     $str_addon .= $task->getLink(false);
                     if ($comment->comment) {
                         if ($comm = Comment::getVisibleById($comment->comment)) {
                             $str_addon .= " > " . $comm->name;
                         }
                     }
                 }
                 $str_addon .= ")";
             }
             break;
         case ITEM_COMPANY:
             if ($c = Company::getVisibleById($obj->id)) {
                 $str_name = asHtml($c->name);
                 $str_url = $PH->getUrl('companyView', array('company' => $c->id));
             }
             break;
         case ITEM_PERSON:
             if ($person = Person::getVisibleById($obj->id)) {
                 $str_name = asHtml($person->name);
                 $str_url = $PH->getUrl('personView', array('person' => $person->id));
             }
             break;
         case ITEM_PROJECTPERSON:
             if ($pp = ProjectPerson::getVisibleById($obj->id)) {
                 if (!($person = new Person($pp->person))) {
                     $PH->abortWarning("ProjectPerson has invalid person-pointer!", ERROR_BUG);
                 }
                 $str_name = asHtml($person->name);
                 $str_url = $PH->getUrl('personView', array('person' => $person->id));
                 if ($project = Project::getVisibleById($pp->project)) {
                     $str_addon = "(" . $project->getLink(false) . ")";
                 }
             }
             break;
         case ITEM_EMPLOYMENT:
             if ($emp = Employment::getById($obj->id)) {
                 if ($person = Person::getVisibleById($emp->person)) {
                     $str_name = asHtml($person->name);
                     $str_url = $PH->getUrl('personView', array('person' => $person->id));
                 }
                 if ($company = Company::getVisibleById($emp->company)) {
                     $str_addon = "(" . $company->getLink(false) . ")";
                 }
             }
             break;
         case ITEM_EFFORT:
             if ($e = Effort::getVisibleById($obj->id)) {
                 $str_name = asHtml($e->name);
                 $str_url = $PH->getUrl('effortEdit', array('effort' => $e->id));
                 if ($task = Task::getVisibleById($e->task)) {
                     if ($project = Project::getVisibleById($task->project)) {
                         $str_addon .= "(" . $project->getLink(false);
                         $str_addon .= " > " . $task->getLink(false) . ")";
                     }
                 }
             }
             break;
         case ITEM_FILE:
             if ($f = File::getVisibleById($obj->id)) {
                 $str_name = asHtml($f->org_filename);
                 $str_url = $PH->getUrl('fileView', array('file' => $f->id));
                 $str_addon .= "(";
                 if ($p = Project::getVisibleById($f->project)) {
                     $str_addon .= $p->getLink(false);
                 }
                 if ($t = Task::getVisibleById($f->parent_item)) {
                     $str_addon .= " > " . $t->getLink(false);
                 }
                 $str_addon .= ")";
             }
             break;
         case ITEM_ISSUE:
             if ($i = Issue::getVisibleById($obj->id)) {
                 if ($t = Task::getVisibleById($i->task)) {
                     $str_name = asHtml($t->name);
                     $str_url = $PH->getUrl('taskView', array('tsk' => $t->id));
                     if ($p = Project::getVisibleById($t->project)) {
                         $str_addon .= "(" . $p->getLink(false) . ")";
                     }
                 }
             }
             break;
         case ITEM_TASKPERSON:
             if ($tp = TaskPerson::getVisibleById($obj->id)) {
                 if ($person = Person::getVisibleById($tp->person)) {
                     $str_name = asHtml($person->name);
                     $str_url = $PH->getUrl('personView', array('person' => $person->id));
                 }
                 if ($task = Task::getVisibleById($tp->task)) {
                     if ($project = Project::getVisibleById($task->project)) {
                         $str_addon .= "(" . $project->getLink(false);
                         $str_addon .= " > " . $task->getLink(false) . ")";
                     }
                 }
             }
             break;
         default:
             break;
     }
     print "<td><a href='{$str_url}'>{$str_name}</a><span class='sub who'> {$str_addon}</span></td>";
 }