/** * query if editable for current user */ static function getEditableById($id) { if ($e = Effort::getById(intval($id))) { if ($p = Project::getById($e->project)) { if ($p->validateEditItem($e)) { return $e; } } } return NULL; }
function render_tr(&$obj, $style = "") { if (!isset($obj) || !$obj instanceof Project) { trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING); return; } $sum = 0.0; $sum_sal = 0.0; $sum_all = 0.0; $sum_cal = 0.0; $diff_value = false; if ($effort_people = Effort::getEffortPeople(array('project' => $obj->id))) { foreach ($effort_people as $ep) { if ($person = Person::getVisibleById($ep->person)) { /*if($obj->getStatus()){ $sum_sal = Effort::getSumEfforts(array('project'=>$obj->id, 'person'=>$person->id, 'status'=>$obj->status)); } else{*/ $sum_sal = Effort::getSumEfforts(array('project' => $obj->id, 'person' => $person->id)); #} if ($sum_sal) { $sum = round($sum_sal / 60 / 60, 1) * 1.0; if ($pp = $obj->getProjectPeople(array('person_id' => $person->id))) { if ($pp[0]->salary_per_hour) { $sum_all = $sum * $pp[0]->salary_per_hour; } else { $sum_all = $sum * $person->salary_per_hour; } } else { $sum_all = $sum * $person->salary_per_hour; } //$sum_all += ($sum * $person->salary_per_hour); } } } } if ($effort_tasks = Effort::getEffortTasks(array('project' => $obj->id))) { foreach ($effort_tasks as $et) { if ($task = Task::getById($et->task)) { if ($task->calculation) { $sum_cal += $task->calculation; } } } } if ($sum_all && $sum_cal) { $max_length_value = 3; $get_percentage = $sum_all / $sum_cal * 100; if ($get_percentage > 100) { $diff = $get_percentage - 100; $get_percentage = 100; $diff_value = true; } $show_rate = $get_percentage * $max_length_value; echo "<td>"; echo "<nobr>"; echo "<img src='" . getThemeFile("img/pixel.gif") . "' style='width:{$show_rate}px;height:12px;background-color:#f00;'>"; if ($diff_value) { $show_rate = $diff * $max_length_value; echo "<img src='" . getThemeFile("img/pixel.gif") . "' style='width:{$show_rate}px;height:12px;background-color:#ff9900;'>"; echo " " . round($get_percentage, 1) . "% / " . round($diff, 1) . " %"; } else { echo " " . round($get_percentage, 1) . "%"; } echo "</nobr>"; echo "</td>"; } else { echo "<td>-</td>"; } }
/** * returns visible object of correct type by an itemId * * this is useful, eg. if you when to access common parameters like name, * regardless of the object's type. * * DbProjectItem::getById() would only load to basic fields. Getting the * complete date required check for type. * * @NOTE: This function causes a awkward dependency to classes derived from * DbProjectItem. It's somehow weird, that this method is placed inside the * parent class. */ public static function getObjectById($id) { $id = intval($id); if (!($item = DbProjectItem::getById($id))) { return NULL; } if ($type = $item->type) { switch ($type) { case ITEM_TASK: require_once "db/class_task.inc.php"; $item_full = Task::getVisibleById($item->id); break; case ITEM_COMMENT: require_once "db/class_comment.inc.php"; $item_full = Comment::getVisibleById($item->id); break; case ITEM_PERSON: require_once "db/class_person.inc.php"; $item_full = Person::getVisibleById($item->id); break; case ITEM_EFFORT: require_once "db/class_effort.inc.php"; $item_full = Effort::getVisibleById($item->id); break; case ITEM_FILE: require_once "db/class_file.inc.php"; $item_full = File::getVisibleById($item->id); break; case ITEM_PROJECT: require_once "db/class_project.inc.php"; $item_full = Project::getVisibleById($item->id); break; case ITEM_COMPANY: require_once "db/class_company.inc.php"; $item_full = Company::getVisibleById($item->id); break; case ITEM_VERSION: require_once "db/class_task.inc.php"; $item_full = Task::getVisibleById($item->id); break; default: $item_full = NULL; } return $item_full; } }
function render_tr(&$obj, $style = "") { global $PH; $str = ""; if (isset($obj->name)) { if ($effort = Effort::getById($obj->id)) { $str = $PH->getLink('effortView', $effort->name, array('effort' => $effort->id)); } } print "<td><b>{$str}</b></td>"; }
function render_tr(&$obj, $style = "") { global $PH; if (!isset($obj) || !$obj instanceof Effort) { trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING); return; } $sum = 0.0; $diff_str = ''; $estimated_str = ''; $str = ''; $percent = ''; /*if($obj->getStatus()){ $sum_task = Effort::getSumEfforts(array('project'=>$obj->project, 'task'=>$obj->task, 'status'=>$obj->status)); } else{*/ $sum_task = Effort::getSumEfforts(array('project' => $obj->project, 'task' => $obj->task)); #} if ($sum_task) { $sum = $sum_task; } if ($task = Task::getVisibleById($obj->task)) { $estimated = $task->estimated; $estimated_max = $task->estimated_max; if ($estimated_max) { $estimated_str = round($estimated_max / 60 / 60, 1) . "h"; $diff = $estimated_max - $sum; } else { $estimated_str = round($estimated / 60 / 60, 1) . "h"; $diff = $estimated - $sum; } if ($diff) { $diff_str = "(" . round($diff / 60 / 60, 1) . "h)"; } $str = $estimated_str . " / " . round($sum / 60 / 60, 1) . "h {$diff_str}"; $percent = __('Completion:') . " " . $task->completion . "%"; } print "<td class=nowrap title='" . __("Relation between estimated time and booked efforts") . "'>{$str}<br><span class='sub who'>{$percent}</span></td>"; }
/** * 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(); }
function newEffortFromTimeTracking() { global $PH; global $auth; require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php'; $time_end = intval(get('effort_end_seconds')); if ($time_end == 0) { $time_end = null; } $new_effort = new Effort(array('id' => 0, 'time_start' => getGMTString(get('effort_start_seconds')), 'time_end' => getGMTString($time_end), 'name' => get('description'), 'billing' => get('billing'), 'productivity' => get('productivity'))); ### get project ### $new_effort->project = get('effort_project_id'); if (!($project = Project::getVisibleById($new_effort->project))) { $PH->abortWarning(__("Could not get project of effort")); } if (!$project->isPersonVisibleTeamMember($auth->cur_user)) { $PH->abortWarning("ERROR: Insufficient rights"); } ### link to task ### $task_id = get('effort_task_id'); if (!(is_null($task_id) || $task_id == 0)) { if ($task_id == 0) { $new_effort->task = 0; } else { if ($task = Task::getVisibleById($task_id)) { $new_effort->task = $task->id; } } } else { if (get('task_name') != "") { ### create new task $newtask = new Task(array('id' => 0, 'name' => get('task_name'), 'project' => $project->id)); $newtask->insert(); $new_effort->task = $newtask->id; } } ### get person ### $new_effort->person = $auth->cur_user->id; ### go back to from if validation fails ### $failure = false; if (strToGMTime($new_effort->time_end) - strToGMTime($new_effort->time_start) < 0) { $failure = true; new FeedbackWarning(__("Cannot start before end.")); } ### write to db ### $new_effort->insert(); ### display taskView #### if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $effort->project)); } }
function render_tr(&$obj, $style = "") { if (!isset($obj) || !$obj instanceof Effort) { trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING); return; } if ($obj->as_duration) { echo "<td>-</td>"; } else { /*if($obj->getStatus()){ $sum_task = Effort::getSumEfforts(array('project'=>$obj->project, 'task'=>$obj->task, 'status'=>$obj->status)); $sum_proj = Effort::getSumEfforts(array('project'=>$obj->project, 'status'=>$obj->status)); } else{*/ $sum_task = Effort::getSumEfforts(array('project' => $obj->project, 'task' => $obj->task)); $sum_proj = Effort::getSumEfforts(array('project' => $obj->project)); #} if ($sum_task && $sum_proj) { $max_length_value = 3; $get_percentage = $sum_task / $sum_proj * 100; $show_rate = $get_percentage * $max_length_value; echo "<td>"; echo "<nobr>"; echo "<img src='" . getThemeFile("img/pixel.gif") . "' style='width:{$show_rate}px;height:12px;background-color:#f00;'>"; echo " " . round($get_percentage, 1) . "%"; echo "</nobr>"; echo "</td>"; } else { echo "<td>-</td>"; } } }
/** * edit several bookmarks @ingroup pages */ function itemBookmarkEditMultiple($thebookmarks = NULL) { global $PH; global $auth; global $g_notitychange_period; $is_already_bookmark = array(); $bookmarks = array(); $items = array(); $edit_fields = array('notify_if_unchanged', 'notify_on_change'); $different_fields = array(); # hash containing fieldnames which are different in bookmarks if (!$thebookmarks) { $item_ids = getPassedIds('bookmark', 'bookmarks_*'); foreach ($item_ids as $is) { if ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = true; } } } } else { $item_ids = $thebookmarks; foreach ($item_ids as $is) { if ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 0))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = false; } } elseif ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 1))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = true; } } else { $date = getGMTString(); $bookmark = new ItemPerson(array('id' => 0, 'item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 1, 'notify_if_unchanged' => 0, 'notify_on_change' => 0, 'created' => $date)); if ($item = DbProjectItem::getById($is)) { $bookmarks[] = $bookmark; $items[] = $item; $is_already_bookmark[$bookmark->id] = false; } } } } if (!$items) { $PH->abortWarning(__("Please select some items")); } $page = new Page(); $page->cur_tab = 'home'; $page->options = array(new NaviOption(array('target_id' => 'itemBookmarkEdit', 'name' => __('Edit bookmarks')))); $page->type = __('Edit multiple bookmarks', 'page title'); $page->title = sprintf(__('Edit %s bookmark(s)'), count($items)); $page->title_minor = __('Edit'); echo new PageHeader(); echo new PageContentOpen(); echo "<ol>"; foreach ($items as $item) { ## get item name ## $str_link = ''; if ($type = $item->type) { switch ($type) { case ITEM_TASK: require_once "db/class_task.inc.php"; if ($task = Task::getVisibleById($item->id)) { $str_link = $task->getLink(false); } break; case ITEM_COMMENT: require_once "db/class_comment.inc.php"; if ($comment = Comment::getVisibleById($item->id)) { $str_link = $comment->getLink(false); } break; case ITEM_PERSON: require_once "db/class_person.inc.php"; if ($person = Person::getVisibleById($item->id)) { $str_link = $person->getLink(false); } break; case ITEM_EFFORT: require_once "db/class_effort.inc.php"; if ($e = Effort::getVisibleById($item->id)) { $str_link = $e->getLink(false); } break; case ITEM_FILE: require_once "db/class_file.inc.php"; if ($f = File::getVisibleById($item->id)) { $str_link = $f->getLink(false); } break; case ITEM_PROJECT: require_once "db/class_project.inc.php"; if ($prj = Project::getVisibleById($item->id)) { $str_link = $prj->getLink(false); } break; case ITEM_COMPANY: require_once "db/class_company.inc.php"; if ($c = Company::getVisibleById($item->id)) { $str_link = $c->getLink(false); } break; case ITEM_VERSION: require_once "db/class_task.inc.php"; if ($tsk = Task::getVisibleById($item->id)) { $str_link = $tsk->getLink(false); } break; default: break; } } echo "<li>" . $str_link . "</li>"; } echo "</ol>"; foreach ($bookmarks as $bookmark) { foreach ($edit_fields as $field_name) { if ($bookmark->{$field_name} != $bookmarks[0]->{$field_name}) { $different_fields[$field_name] = true; } } } $block = new PageBlock(array('id' => 'functions')); $block->render_blockStart(); $form = new PageForm(); $form->button_cancel = true; $b = array(); $b[0] = __('no'); $b[1] = __('yes'); if (isset($different_fields['notify_on_change'])) { $b[-1] = '-- ' . __('keep different') . ' --'; $form->add(new Form_Dropdown('notify_on_change', __("Notify on change"), array_flip($b), -1)); } else { $form->add(new Form_Dropdown('notify_on_change', __("Notify on change"), array_flip($b), $bookmarks[0]->notify_on_change)); } $a = array(); foreach ($g_notitychange_period as $key => $value) { $a[$key] = $value; } if (isset($different_fields['notify_if_unchanged'])) { $a[-1] = '-- ' . __('keep different') . ' --'; $form->add(new Form_Dropdown('notify_if_unchanged', __("Notify if unchanged in"), array_flip($a), -1)); } else { $form->add(new Form_Dropdown('notify_if_unchanged', __("Notify if unchanged in"), array_flip($a), $bookmarks[0]->notify_if_unchanged)); } $number = 0; foreach ($bookmarks as $bm) { $form->add(new Form_HiddenField("bookmark_id_{$number}", '', $bm->id)); $form->add(new Form_HiddenField("bookmark_item_{$number}", '', $bm->item)); $form->add(new Form_HiddenField("is_already_bookmark_{$number}", '', $is_already_bookmark[$bm->id])); $number++; } $form->add(new Form_HiddenField("number", '', $number)); echo $form; $block->render_blockEnd(); $PH->go_submit = 'itemBookmarkEditMultipleSubmit'; echo new PageContentClose(); echo new PageHtmlEnd(); }
/** * Delete several efforts @ingroup pages */ function effortsDelete() { global $PH; ### get effort #### $ids = getPassedIds('effort', 'efforts_*'); if (!$ids) { $PH->abortWarning(__("Select some efforts to delete")); return; } $counter = 0; $errors = 0; foreach ($ids as $id) { $e = Effort::getEditableById($id); if (!$e) { $PH->abortWarning("Invalid effort-id!"); } if ($e->delete()) { $counter++; } else { $errors++; } } if ($errors) { new FeedbackWarning(sprintf(__("Failed to delete %s efforts"), $errors)); } else { new FeedbackMessage(sprintf(__("Moved %s efforts to trash"), $counter)); } if (!$PH->showFromPage()) { $PH->show('home'); } }
/** * 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); }
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> > " . $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 .= ' > ' . $folders; } $html_location .= ' > ' . $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 .= ' > ' . $folders; } $html_location .= ' > ' . $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; }
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; }
function render_tr(&$item, $style = "") { global $PH; $str_url = ""; $str_name = ""; $str_addon = ""; $isDone = ""; $html_details = ""; $link = ""; if ($type = $item->type) { switch ($type) { case ITEM_TASK: require_once "db/class_task.inc.php"; if ($task = Task::getVisibleById($item->id)) { $str_name = asHtml($task->name); $str_url = $PH->getUrl('taskView', array('tsk' => $task->id)); if ($task->status >= STATUS_COMPLETED) { $isDone = "class=isDone"; } if ($prj = Project::getVisibleById($task->project)) { $link = $PH->getLink('projView', $prj->getShort(), array('prj' => $prj->id)); $html_details .= __('in', 'very short for IN folder...') . ' ' . $link; if ($tmp = $task->getFolderLinks()) { $html_details .= ' > ' . $tmp; } } } break; case ITEM_COMMENT: require_once "db/class_comment.inc.php"; if ($comment = Comment::getVisibleById($item->id)) { $str_name = asHtml($comment->name); if ($comment->comment) { $str_url = $PH->getUrl('taskView', array('tsk' => $comment->task)); $str_addon = __("(on comment)"); } else { if ($comment->task) { $str_url = $PH->getUrl('taskView', array('tsk' => $comment->task)); $str_addon = __("(on task)"); } else { $str_url = $PH->getUrl('projView', array('prj' => $comment->project)); $str_addon = __("(on project)"); } } } break; case ITEM_PERSON: require_once "db/class_person.inc.php"; if ($person = Person::getVisibleById($item->id)) { $str_name = asHtml($person->name); $str_url = $PH->getUrl('personView', array('person' => $person->id)); } break; case ITEM_EFFORT: require_once "db/class_effort.inc.php"; if ($e = Effort::getVisibleById($item->id)) { $str_name = asHtml($e->name); $str_url = $PH->getUrl('effortEdit', array('effort' => $e->id)); } if ($prj = Project::getVisibleById($e->project)) { $link = $PH->getLink('projView', $prj->getShort(), array('prj' => $prj->id)); $html_details .= __('in', 'very short for IN folder...') . ' ' . $link; } break; case ITEM_FILE: require_once "db/class_file.inc.php"; if ($f = File::getVisibleById($item->id)) { $str_name = asHtml($f->org_filename); $str_url = $PH->getUrl('fileView', array('file' => $f->id)); if ($f->status >= STATUS_COMPLETED) { $isDone = "class=isDone"; } if ($prj = Project::getVisibleById($f->project)) { $link = $PH->getLink('projView', $prj->getShort(), array('prj' => $prj->id)); $html_details .= __('in', 'very short for IN folder...') . ' ' . $link; } } break; case ITEM_PROJECT: require_once "db/class_project.inc.php"; if ($prj = Project::getVisibleById($item->id)) { $str_name = asHtml($prj->name); $str_url = $PH->getUrl('projView', array('prj' => $prj->id)); if ($prj->status >= STATUS_COMPLETED) { $isDone = "class=isDone"; } } break; case ITEM_COMPANY: require_once "db/class_company.inc.php"; if ($c = Company::getVisibleById($item->id)) { $str_name = asHtml($c->name); $str_url = $PH->getUrl('companyView', array('company' => $c->id)); } break; case ITEM_VERSION: require_once "db/class_task.inc.php"; if ($tsk = Task::getVisibleById($item->id)) { $str_name = asHtml($tsk->name); $str_url = $PH->getUrl('taskView', array('tsk' => $tsk->id)); if ($tsk->status >= STATUS_COMPLETED) { $isDone = "class=isDone"; } if ($prj = Project::getVisibleById($task->project)) { $link = $PH->getLink('projView', $prj->getShort(), array('prj' => $prj->id)); $html_details .= __('in', 'very short for IN folder...') . ' ' . $link; } } break; default: break; } print "<td class='nowrap'><span {$isDone}><a href='{$str_url}'>{$str_name}</a> {$str_addon}</span>"; if ($html_details) { print "<br><span class='sub who'>{$html_details}</span>"; } print "</td>"; } else { $PH->abortWarning("Could not get type of the element.", ERROR_BUG); print "<td> </td>"; } }
/** * 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; }
/** * export selected efforts as a CSV ready for copy and paste into a spread-sheet @ingroup pages ** */ function effortShowAsCSV() { global $PH; global $g_effort_status_names; $effort_ids = getPassedIds('effort', 'efforts_*'); if (!$effort_ids) { $PH->abortWarning(__("Select some efforts(s) to show")); exit; } $efforts = array(); $different_fields = array(); $edit_fields = array('status', 'pub_level', 'task'); foreach ($effort_ids as $id) { if ($effort = Effort::getEditableById($id)) { $efforts[] = $effort; ### check project for first task if (count($efforts) == 1) { ### make sure all are of same project ### if (!($project = Project::getVisibleById($effort->project))) { $PH->abortWarning('could not get project'); } } else { if ($effort->project != $efforts[0]->project) { $PH->abortWarning(__("For editing all efforts must be of same project.")); } foreach ($edit_fields as $field_name) { if ($effort->{$field_name} != $efforts[0]->{$field_name}) { $different_fields[$field_name] = true; } } } } } $page = new Page(array('use_jscalendar' => true)); $page->cur_tab = 'projects'; $page->options[] = new naviOption(array('target_id' => 'effortEdit')); $page->type = __("Edit multiple efforts", "Page title"); $page->title = sprintf(__("%s efforts for copy and pasting into a spread-sheet", "Page title"), count($efforts)); echo new PageHeader(); echo new PageContentOpen(); $block = new PageBlock(array('id' => 'functions', 'reduced_header' => true)); $block->render_blockStart(); $format = "[Date][Weekday][Task][Comment][Duration]"; preg_match_all("/\\[(.*?)\\]/", $format, $matches); $overallDuration = 0; echo "<textarea style='width:96%; height:300px;'>"; echo join("\t", $matches[1]) . "\n"; foreach ($efforts as $e) { preg_match_all("/\\[(.*?)\\]/", $format, $matches); $separator = ""; foreach ($matches[1] as $matchedFormat) { echo $separator; switch ($matchedFormat) { case "Date": echo gmstrftime("%Y-%m-%d", strToGMTime($e->time_start)); break; case "Weekday": echo gmstrftime("%a", strToGMTime($e->time_start)); break; case "Task": if ($t = Task::getVisibleById($e->task)) { echo $t->name; } break; case "Comment": echo $e->name; break; case "Duration": $durationInMinutes = round((strToGMTime($e->time_end) - strToGMTime($e->time_start)) / 60, 0); $roundUpTo15 = ceil($durationInMinutes / 15) * 15 / 60; $overallDuration += $roundUpTo15; echo number_format($roundUpTo15, 2, $dec_point = ',', ''); break; } $separator = "\t"; } echo "\n"; } echo "</textarea>"; echo "<br>"; echo __("Overall Duration:") . $overallDuration . "h"; $block->render_blockEnd(); echo new PageContentClose(); echo new PageHtmlEnd(); exit; }
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>"; }