public function print_automatic()
 {
     global $PH;
     if (!($this->active_block_function = $this->getBlockStyleFromCookie())) {
         $this->active_block_function = 'list';
     }
     $this->query_options['alive_only'] = true;
     $this->group_by = get("blockstyle_{$PH->cur_page->id}_{$this->id}_grouping");
     $s_cookie = "sort_{$PH->cur_page->id}_{$this->id}_{$this->active_block_function}";
     if ($sort = get($s_cookie)) {
         $this->query_options['order_by'] = $sort;
     } else {
         $this->query_options['order_by'] = 'time_end DESC';
     }
     ### add filter options ###
     foreach ($this->filters as $f) {
         foreach ($f->getQuerryAttributes() as $k => $v) {
             $this->query_options[$k] = $v;
         }
     }
     ### grouped view ###
     if ($this->active_block_function == 'grouped') {
         /**
          * @@@ later use only once...
          *
          *   $this->columns= filterOptions($this->columns,"CURPAGE.BLOCKS[{$this->id}].STYLE[{$this->active_block_function}].COLUMNS");
          */
         if (isset($this->columns[$this->group_by])) {
             unset($this->columns[$this->group_by]);
         }
         ### prepend key to sorting ###
         if (isset($this->query_options['order_by'])) {
             if ($this->groupings->getActiveFromCookie() == 'project') {
                 $this->query_options['order_by'] = "i.project," . $this->query_options['order_by'];
             } else {
                 $this->query_options['order_by'] = $this->groupings->getActiveFromCookie() . "," . $this->query_options['order_by'];
             }
         } else {
             $this->query_options['order_by'] = $this->groupings->getActiveFromCookie();
         }
     } else {
         $pass = true;
     }
     $efforts = Effort::getAll($this->query_options);
     $this->render_list($efforts);
 }
function ajaxUserEfforts()
{
    global $PH;
    global $auth;
    require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php';
    $efforts = Effort::getAll(array('person' => $auth->cur_user->id, 'effort_time_min' => getGMTString(time() - 7 * 24 * 60 * 60)));
    $result = array();
    foreach ($efforts as $e) {
        $p = Project::getById($e->project);
        $task_name = "";
        if ($t = Task::getVisibleById($e->task)) {
            $task_name = $t->name . " — ";
        }
        $result[$e->id] = array('start' => strToClientTime($e->time_start), 'duration' => strToClientTime($e->time_end) - strToClientTime($e->time_start), 'id' => $e->id, 'productivity' => $e->productivity, 'color' => $p->color ? "#" . $p->color : "#ff8080", 'title' => $p->name, 'tooltip' => $task_name . $e->name);
    }
    echo json_encode($result);
}
Exemple #3
0
/**
* View efforts for a task
*
* @ingroup pages
*/
function TaskViewEfforts()
{
    global $PH;
    require_once confGet('DIR_STREBER') . 'lists/list_efforts.inc.php';
    ### get current project ###
    $id = getOnePassedId('task', 'tasks_*');
    if (!($task = Task::getVisibleById($id))) {
        $PH->abortWarning("invalid task-id");
        return;
    }
    ### create from handle ###
    $PH->defineFromHandle(array('task' => $task->id));
    if (!($project = Project::getVisibleById($task->project))) {
        $PH->abortWarning("not enough rights");
    }
    $page = new Page();
    initPageForTask($page, $task, $project);
    $page->title_minor = __("Task Efforts");
    ### page functions ###
    $page->add_function(new PageFunction(array('target' => 'effortNew', 'params' => array('task' => $task->id), 'icon' => 'new', 'name' => __('new Effort'))));
    ### render title ###
    echo new PageHeader();
    echo new PageContentOpen();
    $order_by = get('sort_' . $PH->cur_page->id . "_efforts");
    require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php';
    $efforts = Effort::getAll(array('task' => $task->id, 'order_by' => $order_by));
    $list = new ListBlock_efforts();
    $list->render_list($efforts);
    ### 'add new task'-field ###
    $PH->go_submit = 'effortNew';
    echo '<input type="hidden" name="task" value="' . $id . '">';
    echo new PageContentClose();
    echo new PageHtmlEnd();
}
 /**
  * get Open Efforts sum
  * sums up open and new efforts (e.I. everything that's not closed, balanced or not billable)
  */
 function getOpenEffortsSum()
 {
     $sum = 0.0;
     require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php';
     $efforts = Effort::getAll(array('project' => $this->id, 'effort_status_max' => EFFORT_STATUS_OPEN));
     foreach ($efforts as $e) {
         $sum += 1.0 * strToGMTime($e->time_end) - 1.0 * strToGMTime($e->time_start);
     }
     return $sum;
 }
/**
* duplicate a project including all belonging items (tasks, efforts, etc.) @ingroup pages
*
* - This function is a massive database-process and should be protected
*   from parallel database accesses. Failure of this procedure can lead to
*   inconsistent db-structures. Maybe we should add a db-structure validation
*   somewhere
* - all items (even the already deleted) are duplicated because there might
*   be some relationships (like effort on an deleted task, is still an effort)
* - does NOT change the name of the project. The caller has to change this to "copy of ..."
*
* returns...
*    - On Success: new project-object (which has already been added to db) for fine
*      tuning of fields.
*    - On Failure: NULL (error's have been triggered)
*/
function projDuplicate($org_project_id = NULL)
{
    require_once confGet('DIR_STREBER') . "db/class_effort.inc.php";
    require_once confGet('DIR_STREBER') . "db/class_file.inc.php";
    require_once confGet('DIR_STREBER') . "db/class_issue.inc.php";
    global $PH;
    global $auth;
    $count_items = 0;
    if (!$org_project_id) {
        trigger_error("projDuplicate() called without project-id", E_USER_WARNING);
        return;
    }
    /**
     * normally the project-id is already been checked by caller, but just to be sure...
     */
    if (!($org_project = Project::getEditableById($org_project_id))) {
        trigger_error("could not get Project", E_USER_NOTICE);
        return;
    }
    /**
     * @Warning: getting the project a second time might give a reference to
     * the first one. Since caching of project-requests has not yet be activated
     * this works for now. Later be sure to use array_clone().
     */
    if (!($new_project = Project::getEditableById($org_project_id))) {
        trigger_error("could not get Project", E_USER_NOTICE);
        return;
    }
    ### duplicate project ###
    $new_project->id = 0;
    $new_project->created_by = $auth->cur_user->id;
    $new_project->modified_by = $auth->cur_user->id;
    $new_project->date_start = getGMTString();
    $new_project->status = 3;
    #@@@ avoid majic numbers
    $new_project->state = 1;
    # be sure project is no deleted
    if (!$new_project->insert()) {
        trigger_error("Failed to insert new project. Datastructure might have been corrupted", E_USER_WARNING);
        return;
    }
    $flag_cur_user_in_project = false;
    ### copy projectpeople ###
    if ($org_ppeople = $org_project->getProjectPeople(array('alive_only' => false, 'visible_only' => false))) {
        foreach ($org_ppeople as $pp) {
            $pp->id = 0;
            $pp->project = $new_project->id;
            ### make current user project admin ###
            if ($pp->person == $auth->cur_user->id) {
                $pp->initWithUserProfile(PROFILE_ADMIN);
                $flag_cur_user_in_project = true;
            }
            if (!$pp->insert()) {
                trigger_error(__("Failed to insert new project person. Data structure might have been corrupted"), E_USER_WARNING);
                return;
            }
            $count_items++;
        }
    }
    ### be sure, current user is admin ###
    if (!$flag_cur_user_in_project) {
        $pp_new = new ProjectPerson(array('id' => 0, 'person' => $auth->cur_user->id, 'project' => $new_project->id));
        $pp_new->initWithUserProfile(PROFILE_ADMIN);
        if (!$pp_new->insert()) {
            trigger_error(__("Failed to insert new project person. Data structure might have been corrupted"), E_USER_WARNING);
            return;
        }
    }
    ### copy issues ###
    $dict_issues = array(0 => 0);
    $org_issues = $org_project->getIssues(NULL, false, false);
    foreach ($org_issues as $i) {
        $org_issue_id = $i->id;
        $i->project = $new_project->id;
        $i->id = 0;
        if (!$i->insert()) {
            trigger_error(__("Failed to insert new issue. DB structure might have been corrupted."), E_USER_WARNING);
            return;
        }
        $count_items++;
        $dict_issues[$org_issue_id] = $i->id;
    }
    ### pass1 ###
    $dict_tasks = array(0 => 0);
    # assoc array of old / new task-ids
    $new_tasks = array();
    if ($org_tasks = $org_project->getTasks(array('show_folders' => true, 'status_min' => 0, 'status_max' => 10, 'visible_only' => false, 'alive_only' => false))) {
        foreach ($org_tasks as $t) {
            $org_task_id = $t->id;
            $t->id = 0;
            $t->project = $new_project->id;
            if (!isset($dict_issues[$t->issue_report])) {
                trigger_error("undefined issue-id {$t->issue_report}. DB structure might have been corrupted.", E_USER_NOTICE);
            } else {
                $t->issue_report = $dict_issues[$t->issue_report];
            }
            if (!$t->insert()) {
                trigger_error("Failed to insert new task. DB structure might have been corrupted.", E_USER_WARNING);
                return;
            }
            $count_items++;
            $dict_tasks[$org_task_id] = $t->id;
            $new_tasks[] = $t;
        }
    }
    ### pass2: tasks / parent_task ###
    foreach ($new_tasks as $nt) {
        if (isset($dict_tasks[$nt->parent_task])) {
            $nt->parent_task = $dict_tasks[$nt->parent_task];
            $nt->for_milestone = $dict_tasks[$nt->for_milestone];
        } else {
            trigger_error("undefined task-id {$nt->parent_task}", E_USER_WARNING);
        }
        if (!$nt->update()) {
            trigger_error(__("Failed to update new task. DB structure might have been corrupted."), E_USER_WARNING);
            return;
        }
    }
    ### copy efforts ###
    $dict_efforts = array(0 => 0);
    if ($org_efforts = Effort::getAll(array('project' => $org_project->id, 'visible_only' => false, 'alive_only' => false))) {
        foreach ($org_efforts as $e) {
            $org_effort_id = $e->id;
            if (isset($dict_tasks[$e->task])) {
                $e->task = $dict_tasks[$e->task];
            } else {
                trigger_error("undefined task-id {$e->task}", E_USER_NOTICE);
            }
            $e->id = 0;
            $e->project = $new_project->id;
            if (!$e->insert()) {
                trigger_error("Failed to insert new effort. DB structure might have been corrupted.", E_USER_WARNING);
                return;
            }
            $count_items++;
            $dict_efforts[$org_effort_id] = $e->id;
        }
    }
    ### copy task_assigments ###
    $dict_taskpeople = array(0 => 0);
    # this hash is not required
    if ($org_taskpeople = $org_project->getTaskPeople("", false, false)) {
        foreach ($org_taskpeople as $tp) {
            $org_taskperson_id = $tp->id;
            if (isset($dict_tasks[$tp->task])) {
                $tp->task = $dict_tasks[$tp->task];
            } else {
                trigger_error("undefined task-id {$e->task}", E_USER_WARNING);
            }
            $tp->id = 0;
            $tp->project = $new_project->id;
            if (!$tp->insert()) {
                trigger_error("Failed to insert new taskperson. DB structure might have been corrupted.", E_USER_WARNING);
                return;
            }
            $count_items++;
            $dict_taskpeople[$org_taskperson_id] = $tp->id;
        }
    }
    $dict_comments = array(0 => 0);
    $new_comments = array();
    if ($org_comments = $org_project->getComments("", false, false)) {
        foreach ($org_comments as $c) {
            $org_comment_id = $c->id;
            if (isset($dict_tasks[$c->task])) {
                $c->task = $dict_tasks[$c->task];
            }
            if (isset($dict_efforts[$c->effort])) {
                $c->effort = $dict_efforts[$c->effort];
            }
            if (isset($dict_effort[$c->effort])) {
                $c->effort = $dict_efforts[$c->effort];
            }
            $c->id = 0;
            $c->project = $new_project->id;
            if (!$c->insert()) {
                trigger_error(__("Failed to insert new comment. DB structure might have been corrupted."), E_USER_WARNING);
                return;
            }
            $count_items++;
            $dict_comments[$org_comment_id] = $c->id;
            $new_comments[] = $c;
        }
    }
    ### pass2: comment / on comment ###
    foreach ($new_comments as $nc) {
        $nc->comment = $dict_comments[$nc->comment];
        if (!$nc->update()) {
            trigger_error("Failed to update new comment. DB structure might have been corrupted.", E_USER_WARNING);
            return;
        }
    }
    #new FeedbackMessage(sprintf(__("Project duplicated (including %s items)"), $count_items));
    #if(!$new_project->insert()) {
    #    trigger_error("Inserting new project failed. DB structure might have been corrupted.", E_USER_WARNING);
    #    return;
    #}
    return $new_project;
    #$PH->show('projEdit',array('prj'=>$new_project->id),$new_project);
}
Exemple #6
0
 static function getForQuery($search_query, $project = NULL)
 {
     $count_overall = 0;
     $results = array();
     global $PH;
     require_once confGet('DIR_STREBER') . "db/class_company.inc.php";
     $args = array('order_str' => NULL, 'has_id' => NULL, 'search' => $search_query);
     foreach ($companies = Company::getAll($args) as $company) {
         $rate = RATE_TYPE_COMPANY;
         $rate *= SearchResult::RateItem($company);
         $rate *= SearchResult::RateTitle($company, $search_query);
         $results[] = new SearchResult(array('name' => $company->name, 'rating' => $rate, 'type' => __('Company'), 'jump_id' => 'companyView', 'jump_params' => array('company' => $company->id, 'q' => $search_query), 'item' => $company));
     }
     require_once confGet('DIR_STREBER') . "db/class_person.inc.php";
     foreach ($people = Person::getPeople(array('search' => $search_query)) as $person) {
         $rate = RATE_TYPE_PERSON;
         $rate *= SearchResult::RateItem($person);
         $rate *= SearchResult::RateTitle($person, $search_query);
         $results[] = new SearchResult(array('name' => $person->name, 'rating' => $rate, 'type' => __('Person'), 'jump_id' => 'personView', 'jump_params' => array('person' => $person->id, 'q' => $search_query), 'item' => $person));
     }
     require_once confGet('DIR_STREBER') . "db/class_project.inc.php";
     $projects = Project::getAll(array('status_min' => 0, 'status_max' => 10, 'search' => $search_query));
     if ($projects) {
         foreach ($projects as $project) {
             $rate = RATE_TYPE_PROJECT;
             if ($project->status == STATUS_TEMPLATE) {
                 $rate *= RATE_PROJECT_IS_TEMPLATE;
             } else {
                 if ($project->status < STATUS_COMPLETED) {
                     $rate *= RATE_PROJECT_IS_OPEN;
                 } else {
                     $rate *= RATE_PROJECT_IS_CLOSED;
                 }
             }
             if ($diz = SearchResult::getExtract($project, $search_query)) {
                 $rate *= RATE_IN_DETAILS;
             }
             ### status ###
             global $g_status_names;
             $status = isset($g_status_names[$project->status]) ? $g_status_names[$project->status] : '';
             if ($project->status > STATUS_COMPLETED) {
                 $rate *= RATE_TASK_STATUS_CLOSED;
             } else {
                 if ($project->status >= STATUS_COMPLETED) {
                     $rate *= RATE_TASK_STATUS_COMPLETED;
                 }
             }
             ### for company ###
             $html_location = '';
             if ($company = Company::getVisibleById($project->company)) {
                 $html_location = __('for') . ' ' . $company->getLink();
             }
             $rate *= SearchResult::RateItem($project);
             $rate *= SearchResult::RateTitle($project, $search_query);
             $results[] = new SearchResult(array('name' => $project->name, 'rating' => $rate, 'item' => $project, 'type' => __('Project'), 'jump_id' => 'projView', 'jump_params' => array('prj' => $project->id, 'q' => $search_query), 'extract' => $diz, 'status' => $status, 'html_location' => $html_location));
         }
     }
     require_once confGet('DIR_STREBER') . "db/class_task.inc.php";
     $order_str = get('sort_' . $PH->cur_page->id . "_tasks");
     $tasks = Task::getAll(array('order_by' => $order_str, 'search' => $search_query, 'status_min' => STATUS_UPCOMING, 'status_max' => STATUS_CLOSED));
     if ($tasks) {
         foreach ($tasks as $task) {
             $rate = RATE_TYPE_TASK;
             $rate *= SearchResult::RateItem($task);
             $rate *= SearchResult::RateTitle($task, $search_query);
             if ($task->category == TCATEGORY_FOLDER) {
                 $rate *= RATE_TASK_IS_FOLDER;
             }
             if ($diz = SearchResult::getExtract($task, $search_query)) {
                 $rate *= RATE_IN_DETAILS;
             }
             global $g_status_names;
             $status = isset($g_status_names[$task->status]) ? $g_status_names[$task->status] : '';
             if ($task->status > STATUS_COMPLETED) {
                 $rate *= RATE_TASK_STATUS_CLOSED;
             } else {
                 if ($task->status >= STATUS_COMPLETED) {
                     $rate *= RATE_TASK_STATUS_COMPLETED;
                 }
             }
             if ($project = Project::getVisibleById($task->project)) {
                 $prj = $project->getLink();
             } else {
                 $prj = '';
             }
             $html_location = __('in') . " <b>{$prj}</b> &gt; " . $task->getFolderLinks();
             $is_done = $task->status < STATUS_COMPLETED ? false : true;
             $results[] = new SearchResult(array('name' => $task->name, 'rating' => $rate, 'extract' => $diz, 'item' => $task, 'type' => $task->getLabel(), 'status' => $status, 'html_location' => $html_location, 'is_done' => $is_done, 'jump_id' => 'taskView', 'jump_params' => array('tsk' => $task->id, 'q' => $search_query)));
         }
     }
     require_once confGet('DIR_STREBER') . "db/class_comment.inc.php";
     $comments = Comment::getAll(array('search' => $search_query));
     if ($comments) {
         foreach ($comments as $comment) {
             $rate = RATE_TYPE_COMMENT;
             $rate *= SearchResult::RateItem($comment);
             $rate *= SearchResult::RateTitle($comment, $search_query);
             if ($diz = SearchResult::getExtract($comment, $search_query)) {
                 $rate *= RATE_IN_DETAILS;
             }
             if ($project = Project::getVisibleById($comment->project)) {
                 $prj = $project->getLink();
             } else {
                 $prj = '';
             }
             $html_location = __('on') . " <b>{$prj}</b>";
             $is_done = false;
             if ($task = Task::getVisibleById($comment->task)) {
                 if ($folders = $task->getFolderLinks()) {
                     $html_location .= ' &gt; ' . $folders;
                 }
                 $html_location .= ' &gt; ' . $task->getLink(false);
                 if ($task->status >= STATUS_COMPLETED) {
                     $is_done = true;
                 }
             } else {
                 $html_location = '';
             }
             $results[] = new SearchResult(array('name' => $comment->name, 'rating' => $rate, 'extract' => $diz, 'type' => __('Comment'), 'html_location' => $html_location, 'jump_id' => 'commentView', 'jump_params' => array('comment' => $comment->id, 'q' => $search_query), 'item' => $comment, 'is_done' => $is_done));
         }
     }
     $count_overall += count($comments);
     require_once confGet('DIR_STREBER') . "db/class_effort.inc.php";
     $efforts = Effort::getAll(array('search' => $search_query));
     if ($efforts) {
         foreach ($efforts as $effort) {
             $rate = RATE_TYPE_EFFORT;
             $rate *= SearchResult::RateItem($effort);
             $rate *= SearchResult::RateTitle($effort, $search_query);
             if ($diz = SearchResult::getExtract($effort, $search_query)) {
                 $rate *= RATE_IN_DETAILS;
             }
             if ($project = Project::getVisibleById($effort->project)) {
                 $prj = $project->getLink();
             } else {
                 $prj = '';
             }
             $html_location = __('on') . " <b>{$prj}</b>";
             $is_done = false;
             if ($task = Task::getVisibleById($effort->task)) {
                 if ($folders = $task->getFolderLinks()) {
                     $html_location .= ' &gt; ' . $folders;
                 }
                 $html_location .= ' &gt; ' . $task->getLink(false);
                 if ($task->status >= STATUS_COMPLETED) {
                     $is_done = true;
                 }
             } else {
                 $html_location = '';
             }
             $results[] = new SearchResult(array('name' => $effort->name, 'rating' => $rate, 'extract' => $diz, 'type' => __('Effort'), 'html_location' => $html_location, 'jump_id' => 'effortView', 'jump_params' => array('effort' => $effort->id, 'q' => $search_query), 'item' => $effort, 'is_done' => $is_done));
         }
     }
     $count_overall += count($efforts);
     return $results;
 }
Exemple #7
0
function _moveTask($task_id, $target_project_id, $target_task_id)
{
    $task = Task::getEditableById($task_id);
    if (!$task) {
        new FeedbackWarning(sprintf(__("Can not edit tasks with ID %s"), $task_id));
        return false;
    }
    $target_parents = _getParentOfTaskId($target_task_id);
    if (_isTaskInList($task, $target_parents)) {
        new FeedbackWarning(sprintf(__("Can not move task <b>%s</b> to own child."), $task->name));
        return false;
    }
    $task->parent_task = $target_task_id;
    $task->update();
    ### move task to another project
    if ($target_project_id != $task->project) {
        $task->project = $target_project_id;
        ### move linked comments
        if ($comments = Comment::getAll(array('visible_only' => false, 'alive_only' => false, 'task' => $task->id))) {
            foreach ($comments as $c) {
                $c->project = $target_project_id;
                $c->update();
            }
        }
        ### move linked efforts
        if ($efforts = Effort::getAll(array('visible_only' => false, 'alive_only' => false, 'task' => $task->id))) {
            foreach ($efforts as $e) {
                $e->project = $target_project_id;
                $e->update();
            }
        }
        ### move subtasks
        foreach ($task->getSubtasksRecursiveAll(array('visible_only' => true, 'alive_only' => false)) as $subtask) {
            _moveTask($subtask->id, $target_project_id, $subtask->parent_task);
        }
        ### move linked issue
        if ($task->issue_report) {
            $task->issue_report->project = $target_project_id;
        }
    }
    $task->update();
    $task->nowChangedByUser();
    return true;
}
 /**
  *  get user efforts
  *
  * @@@ does NOT check for admin-rights to view all efforts
  */
 function getEfforts($f_order_by = NULL)
 {
     /*
             global $auth;
             $prefix= confGet('DB_TABLE_PREFIX');
             require_once(confGet('DIR_STREBER') . 'db/class_effort.inc.php');
     
             $dbh = new DB_Mysql;
             $sth= $dbh->prepare(
                     "SELECT i.*, e.*  from {$prefix}item i, {$prefix}effort e, {$prefix}project p, {$prefix}projectperson upp
                     WHERE
                             upp.person = {$auth->cur_user->id}
                         AND upp.state = 1
     
                         AND i.type = '".ITEM_EFFORT."'
                         AND i.state = 1
                         AND i.project = upp.project
                         AND i.created_by = $this->id
                         AND (
                             i.pub_level >= upp.level_view
                             OR
                             i.created_by= {$auth->cur_user->id}
                         )
     
                         AND e.id= i.id
                         AND p.id= i.project
                     ". getOrderByString($f_order_by, 'time_end DESC')
             );
             $sth->execute("",1);
             $tmp=$sth->fetchall_assoc();
             $efforts=array();
             foreach($tmp as $t) {
                 $efforts[]=new Effort($t);
             }*/
     require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php';
     $efforts = Effort::getAll(array('person' => $this->id));
     return $efforts;
 }