function ProjView()
{
    global $PH;
    global $auth;
    require_once confGet('DIR_STREBER') . "render/render_wiki.inc.php";
    ### get current project ###
    $id = getOnePassedId('prj', 'projects_*');
    if ($project = Project::getEditableById($id)) {
        $editable = true;
    } else {
        if ($project = Project::getVisibleById($id)) {
            $editable = false;
        } else {
            $PH->abortWarning(__("invalid project-id"));
            return;
        }
    }
    ### define from-handle ###
    $PH->defineFromHandle(array('prj' => $project->id));
    ## is viewed by user ##
    $project->nowViewedByUser();
    ## next milestone ##
    $next = $project->getNextMilestone();
    $page = new Page();
    $page->crumbs = build_project_crumbs($project);
    $page->options = build_projView_options($project);
    $page->cur_tab = 'projects';
    $page->title = $project->name;
    $page->title_minor = __("Project overview");
    if ($project->status == STATUS_TEMPLATE) {
        $page->type = __("Project Template");
    } else {
        if ($project->status >= STATUS_COMPLETED) {
            $page->type = __("Inactive Project");
        } else {
            $page->type = __("Project", "Page Type");
        }
    }
    ### page functions ###
    if ($project->isPersonVisibleTeamMember($auth->cur_user)) {
        if ($editable) {
            $page->add_function(new PageFunction(array('target' => 'projEdit', 'params' => array('prj' => $project->id), 'icon' => 'edit', 'tooltip' => __('Edit this project'), 'name' => __('Edit project'))));
        }
        /*
        $item = ItemPerson::getAll(array(
            'person'=>$auth->cur_user->id,
            'item'=>$project->id
        ));
        if((!$item) || ($item[0]->is_bookmark == 0)){
            $page->add_function(new PageFunction(array(
                'target'    =>'itemsAsBookmark',
                'params'    =>array('proj'=>$project->id),
                'tooltip'   =>__('Mark this project as bookmark'),
                'name'      =>__('Bookmark'),
            )));
        }
        else{
            $page->add_function(new PageFunction(array(
                'target'    =>'itemsRemoveBookmark',
                'params'    =>array('proj'=>$project->id),
                'tooltip'   =>__('Remove this bookmark'),
                'name'      =>__('Remove Bookmark'),
            )));
        }
        */
        /*
        if($project->state == 1) {
                $page->add_function(new PageFunction(array(
                    'target'=>'projDelete',
                    'params'=>array('prj'=>$project->id),
                    'icon'=>'delete',
                    'tooltip'=>__('Delete this project'),
                    'name'=>__('Delete')
                )));
        }
        */
        #$page->add_function(new PageFunctionGroup(array(
        #    'name'      => __('new')
        #)));
        /*
        $page->add_function(new PageFunction(array(
            'target'    =>'projAddPerson',
            'params'    =>array('prj'=>$project->id),
            'icon'      =>'add',
            'tooltip'   =>__('Add person as team-member to project'),
            'name'      =>__('Team member')
        )));
        */
        if ($project->settings & PROJECT_SETTING_ENABLE_TASKS) {
            $page->add_function(new PageFunction(array('target' => 'taskNew', 'params' => array('prj' => $project->id), 'icon' => 'new', 'tooltip' => __('Create task'), 'name' => __('New task'))));
        }
        if ($project->settings & PROJECT_SETTING_ENABLE_BUGS) {
            $page->add_function(new PageFunction(array('target' => 'taskNewBug', 'params' => array('prj' => $project->id, 'add_issue' => 1), 'icon' => 'new', 'tooltip' => __('Create task with issue-report'), 'name' => __('New bug'))));
        }
        $page->add_function(new PageFunction(array('target' => 'taskNewDocu', 'params' => array('prj' => $project->id), 'icon' => 'new', 'tooltip' => __('Create wiki documentation page or start discussion topic'), 'name' => __('New topic'))));
        if ($project->settings & PROJECT_SETTING_ENABLE_EFFORTS && $auth->cur_user->settings & USER_SETTING_ENABLE_EFFORTS) {
            $page->add_function(new PageFunction(array('target' => 'effortNew', 'params' => array('prj' => $project->id), 'icon' => 'loghours', 'tooltip' => __('Book effort for this project'), 'name' => __('Book effort'))));
        }
    }
    $url = $PH->getUrl("projViewAsRSS", array('prj' => $project->id));
    $page->extra_header_html .= '<link rel="alternate" type="application/rss+xml" title="' . asHtml($project->name) . ' ' . __("News") . '"' . ' href="' . $url . '" />';
    ### render title ###
    echo new PageHeader();
    echo new PageContentOpen_Columns();
    measure_stop('current milestone');
    require_once confGet('DIR_STREBER') . 'blocks/current_milestone_block.inc.php';
    $block = new CurrentMilestoneBlock($project);
    $block->render();
    measure_stop('current milestone');
    measure_start('team');
    require_once confGet('DIR_STREBER') . 'lists/list_docustructure.inc.php';
    if (Task::getDocuTasks($project->id, 0)) {
        $list = new Block_DocuNavigation(array('project_id' => $project->id));
        $list->print_all();
    }
    #--- list team -----------------------------------------------------------
    /*
    {
    
        $list= new ListBlock_projectTeam();
        $list->title= __('Team members');
        $list->show_icons=true;
        $list->active_block_function = 'list';
        $list->print_automatic($project);
    }
    measure_stop('team');
    */
    echo new PageContentNextCol();
    echo "<div class=description>";
    echo wikifieldAsHtml($project, 'description', array('empty_text' => "[quote]" . __("This project does not have any text yet.\nDoubleclick here to add some.") . "[/quote]"));
    echo "</div>";
    #--- news -----------------------------------------------------------
    if ($project->settings & PROJECT_SETTING_ENABLE_NEWS) {
        require_once confGet('DIR_STREBER') . './blocks/project_news_block.inc.php';
        print new ProjectNewsBlock($project);
    }
    require_once confGet('DIR_STREBER') . './lists/list_recentchanges.inc.php';
    printRecentChanges(array($project), false);
    /*
    measure_start('changes');
    {
        require_once(confGet('DIR_STREBER') . './lists/list_changes.inc.php');
    
        $list= new ListBlock_changes();
        $list->query_options['date_min']= $auth->cur_user->last_logout;
        $list->query_options['not_modified_by']= $auth->cur_user->id;
        $list->query_options['project']= $project->id;
        //$list->print_automatic($project);
        $list->print_automatic();
    }
    measure_stop('changes');
    */
    echo "<br><br>";
    # @@@ hack for firefox overflow problems
    ### HACKING: 'add new task'-field ###
    $PH->go_submit = 'taskNew';
    echo '<input type="hidden" name="prj" value="' . $project->id . '">';
    #$rss_url = confGet('SELF_PROTOCOL').'://'.confGet('SELF_URL');
    #$rss_url = str_replace("index.php", "rss/", $rss_url);
    #$prj_id  = $this->page->options[0]->target_params['prj'];
    $url = $PH->getUrl('projViewAsRSS', array('prj' => $project->id));
    echo "<a style='margin:0px; border-width:0px;' href='{$url}' target='_blank'>" . "<img style='margin:0px; border-width:0px;' src='" . getThemeFile("icons/rss_icon.gif") . "'>" . "</a>";
    echo new PageContentClose();
    echo new PageHtmlEnd();
}
Example #2
0
/**
* 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);
}