protected function createPortfolioFromTemplateProcess($a_process_form = true)
 {
     global $ilSetting, $ilUser, $ilAccess;
     $title = trim($_REQUEST["pt"]);
     $prtt_id = (int) $_REQUEST["prtt"];
     // valid template?
     include_once "Modules/Portfolio/classes/class.ilObjPortfolioTemplate.php";
     $templates = array_keys(ilObjPortfolioTemplate::getAvailablePortfolioTemplates());
     if (!sizeof($templates) || !in_array($prtt_id, $templates)) {
         $this->toRepository();
     }
     unset($templates);
     // build page recipe (aka import form values)
     $recipe = null;
     if ($a_process_form) {
         $this->ctrl->setParameter($this, "prtt", $prtt_id);
         $form = $this->initCreatePortfolioFromTemplateForm($prtt_id, $title);
         if ($form->checkInput()) {
             include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
             foreach (ilPortfolioTemplatePage::getAllPages($prtt_id) as $page) {
                 switch ($page["type"]) {
                     case ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE:
                         if (!$ilSetting->get('disable_wsp_blogs')) {
                             $field_id = "blog_" . $page["id"];
                             switch ($form->getInput($field_id)) {
                                 case "blog_create":
                                     $recipe[$page["id"]] = array("blog", "create", trim($form->getInput($field_id . "_create_title")));
                                     break;
                                 case "blog_resuse":
                                     $recipe[$page["id"]] = array("blog", "reuse", (int) $form->getInput($field_id . "_reuse_blog"));
                                     break;
                                 case "blog_ignore":
                                     $recipe[$page["id"]] = array("blog", "ignore");
                                     break;
                             }
                         }
                         break;
                 }
             }
             $recipe["skills"] = (array) $form->getInput("skill_ids");
         } else {
             $form->setValuesByPost();
             return $this->createPortfolioFromTemplate($form);
         }
     }
     $source = new ilObjPortfolioTemplate($prtt_id, false);
     // create portfolio
     include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
     $target = new ilObjPortfolio();
     $target->setTitle($title);
     $target->create();
     $target_id = $target->getId();
     $source->clonePagesAndSettings($source, $target, $recipe);
     // link portfolio to exercise assignment
     $exc_ref_id = (int) $_REQUEST["exc_id"];
     $ass_id = (int) $_REQUEST["ass_id"];
     if ($exc_ref_id && $ass_id && $ilAccess->checkAccess("read", "", $exc_ref_id)) {
         include_once "Modules/Exercise/classes/class.ilObjExercise.php";
         include_once "Modules/Exercise/classes/class.ilExAssignment.php";
         $exc = new ilObjExercise($exc_ref_id);
         $ass = new ilExAssignment($ass_id);
         if ($ass->getExerciseId() == $exc->getId() && $ass->getType() == ilExAssignment::TYPE_PORTFOLIO) {
             $exc->addResourceObject($target_id, $ass_id, $ilUser->getId());
         }
     }
     ilUtil::sendSuccess($this->lng->txt("prtf_portfolio_created"), true);
     $this->ctrl->setParameter($this, "prt_id", $target_id);
     $this->ctrl->redirect($this, "view");
 }