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>"; } }
/** * 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; } }
/** * create a new effort @ingroup pages */ function effortNew() { global $PH; global $auth; $name = get('new_name') ? get('new_name') : __("New Effort"); ### first try single project-id ### $project = NULL; if ($ids = getPassedIds('prj', 'projects_*')) { if (!($project = Project::getVisibleById($ids[0]))) { $PH->abortWarning("ERROR: could not get Project"); return; } } ### try to get task ### $task_id = 0; if ($task_ids = getPassedIds('parent_task', 'tasks_*')) { if (count($task_ids) > 1) { new FeedbackWarning(__("only expected one task. Used the first one.")); } $task_id = $task_ids[0]; } else { if ($task_ids = getPassedIds('', 'folders_*')) { if (count($task_ids) > 1) { new FeedbackWarning(__("only expected one task. Used the first one.")); } $task_id = $task_ids[0]; } } if (!$project) { if (!$task_id) { $PH->abortWarning("Could not get project", ERROR_NOTE); } if (!($task = Task::getVisibleById($task_id))) { $PH->abortWarning("Invalid task id?", ERROR_BUG); } if (!($project = Project::getVisibleById($task->project))) { $PH->abortWarning("Invalid project for task?", ERROR_BUG); } } if (!$project->isPersonVisibleTeamMember($auth->cur_user)) { $PH->abortWarning("ERROR: Insufficient rights"); } $now = getGMTString(); ### last effort selected? ### if ($effort_ids = getPassedIds('', 'efforts_*')) { $last_effort = Effort::getVisibleById($effort_ids[0]); $last = $last_effort->time_end; $now = $last_effort->time_end; } else { if ($last = Effort::getDateCreatedLast()) { $last_day = getdate(strToGMTime($last)); } else { $last_day = "1980-01-01"; } $today = getdate(time()); if ($last_day['yday'] != $today['yday']) { $last = getGMTString(); } } ### log efforts as durations? ### $as_duration = 0; if ($pp = $project->getCurrentProjectPerson()) { if ($pp->adjust_effort_style == 2) { if ($last = Effort::getDateCreatedLast()) { $last_day = $last; } else { $last_day = "1980-01-01"; } $str_time = sprintf("%02d:%02d:%02d", floor((time() - strToGMTime($last_day)) / 60 / 60 % 24), floor((time() - strToGMTime($last_day)) / 60 % 60), floor((time() - strToGMTime($last_day)) % 60)); $now = gmdate("Y-m-d", time()) . " " . $str_time; $last = gmdate("Y-m-d") . " " . "00:00:00"; $as_duration = 1; } } ### build new object ### $newEffort = new Effort(array('id' => 0, 'name' => $name, 'project' => $project->id, 'time_start' => $last, 'time_end' => $now, 'task' => $task_id, 'as_duration' => $as_duration, 'person' => $auth->cur_user->id)); $PH->show('effortEdit', array('effort' => $newEffort->id), $newEffort); }
/** * 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(); }
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>"; }