Exemplo n.º 1
0
 /**
  * tries to build a valid a href-link to an item.
  *
  * - uses $this->name
  * - sets -this-html
  * - does all the neccessary security checks, styles and conversions
  */
 static function renderLinkFromItemId($target_id, $name = "")
 {
     global $PH;
     $target_id = intval($target_id);
     $html = "";
     if (!($item = DbProjectItem::getVisibleById($target_id))) {
         $html = '<em>' . sprintf(__("Unkwown item %s"), $target_id) . '</em>';
     } else {
         switch ($item->type) {
             case ITEM_TASK:
                 if ($task = Task::getVisibleById($item->id)) {
                     $style_isdone = $task->status >= STATUS_COMPLETED ? 'isDone' : '';
                     if ($name) {
                         $html = $PH->getLink('taskView', $name, array('tsk' => $task->id), $style_isdone, true);
                     } else {
                         $html = $task->getLink(false);
                     }
                 }
                 break;
             case ITEM_FILE:
                 require_once confGet('DIR_STREBER') . "db/class_file.inc.php";
                 if ($file = File::getVisibleById($item->id)) {
                     if ($name) {
                         $html = $PH->getLink('fileDownloadAsImage', $name, array('file' => $file->id), NULL, true);
                     } else {
                         $html = $PH->getLink('fileDownloadAsImage', $file->name, array('file' => $file->id));
                     }
                 }
                 break;
             case ITEM_COMMENT:
                 require_once confGet('DIR_STREBER') . "db/class_comment.inc.php";
                 if ($comment = Comment::getVisibleById($item->id)) {
                     if ($name) {
                         $html = $PH->getLink('commentView', $name, array('comment' => $comment->id), NULL, true);
                     } else {
                         $html = $PH->getLink('commentView', $comment->name, array('comment' => $comment->id));
                     }
                 }
                 break;
             case ITEM_PERSON:
                 if ($person = Person::getVisibleById($item->id)) {
                     if ($name) {
                         $html = $PH->getLink('personView', $name, array('person' => $person->id), NULL, true);
                     } else {
                         $html = $PH->getLink('personView', $person->name, array('person' => $person->id));
                     }
                 }
                 break;
             case ITEM_PROJECT:
                 if ($project = Project::getVisibleById($item->id)) {
                     if ($name == "") {
                         $name = asHtml($project->name);
                     }
                     $html = $PH->getLink('projView', $name, array('prj' => $project->id), NULL, true);
                 }
                 break;
             default:
                 $html = '<em>' . sprintf(__('Cannot link to item #%s of type %s'), intval($target_id), $item->type) . '</em>';
                 break;
         }
     }
     return $html;
 }
Exemplo n.º 2
0
/**
* move comments to folder...
*/
function commentsMoveToFolder()
{
    global $PH;
    $comment_ids = getPassedIds('comment', 'comments_*');
    if (!$comment_ids) {
        $PH->abortWarning(__("Select some comments to move"));
        return;
    }
    /**
     * if folder was given, directly move tasks...
     */
    $target_id = -1;
    # target is unknown
    $folder_ids = getPassedIds('folder', 'folders_*');
    if (count($folder_ids) == 1) {
        if ($folder_task = Task::getVisibleById($folder_ids[0])) {
            $target_id = $folder_task->id;
        }
    } else {
        if (get('from_selection')) {
            $target_id = 0;
            # to ungrout to root?
        }
    }
    if ($target_id != -1) {
        if ($target_id != 0) {
            if (!($target_task = Task::getEditableById($target_id))) {
                $PH->abortWarning(__("insufficient rights"));
            }
        }
        $count = 0;
        foreach ($comment_ids as $id) {
            if ($comment = Comment::getEditableById($id)) {
                $comment->task = $target_id;
                /**
                 * @@@ do we have to reset ->comment as well?
                 *
                 * this splits discussions into separate comments...
                 */
                $comment->comment = 0;
                $comment->update();
            } else {
                new FeedbackWarning(sprintf(__("Can not edit comment %s"), asHtml($comment->name)));
            }
        }
        ### return to from-page? ###
        if (!$PH->showFromPage()) {
            $PH->show('home');
        }
        exit;
    }
    /**
     * build page folder list to select target...
     */
    require_once confGet('DIR_STREBER') . 'lists/list_tasks.inc.php';
    ### get project ####
    if (!($comment = Comment::getVisibleById($comment_ids[0]))) {
        $PH->abortWarning("could not get comment", ERROR_BUG);
    }
    if (!($project = Project::getVisibleById($comment->project))) {
        $PH->abortWarning("task without project?", ERROR_BUG);
    }
    $page = new Page(array('use_jscalendar' => false, 'autofocus_field' => 'company_name'));
    $page->cur_tab = 'projects';
    $page->type = __("Edit tasks");
    $page->title = $project->name;
    $page->title_minor = __("Select one folder to move comments into");
    $page->crumbs = build_project_crumbs($project);
    $page->options[] = new NaviOption(array('target_id' => 'commentsMoveToFolder'));
    echo new PageHeader();
    echo new PageContentOpen();
    echo __("... or select nothing to move to project root");
    ### write selected comments as hidden fields ###
    foreach ($comment_ids as $id) {
        if ($comment = Comment::getEditableById($id)) {
            echo "<input type=hidden name='comments_{$id}_chk' value='1'>";
        }
    }
    $list = new ListBlock_tasks();
    $list->reduced_header = true;
    $list->query_options['show_folders'] = true;
    $list->query_options['folders_only'] = true;
    $list->query_options['project'] = $project->id;
    $list->groupings = NULL;
    $list->block_functions = NULL;
    $list->id = 'folders';
    unset($list->columns['project']);
    unset($list->columns['status']);
    unset($list->columns['date_start']);
    unset($list->columns['days_left']);
    unset($list->columns['created_by']);
    unset($list->columns['label']);
    $list->no_items_html = __("No folders in this project...");
    $list->functions = array();
    $list->active_block_function = 'tree';
    $list->print_automatic($project);
    echo "<input type=hidden name='from_selection' value='1'>";
    # keep flag to ungroup comments
    echo "<input type=hidden name='project' value='{$project->id}'>";
    $button_name = __("Move items");
    echo "<input class=button2 type=submit value='{$button_name}'>";
    $PH->go_submit = 'commentsMoveToFolder';
    echo new PageContentClose();
    echo new PageHtmlEnd();
}
Exemplo n.º 3
0
 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>&nbsp;</td>";
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
     }
 }
Exemplo n.º 5
0
/**
* 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();
}
Exemplo n.º 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>";
 }