ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPortfolioGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Portfolio/classes/class.ilObjPortfolio.php");
5 include_once('./Services/Portfolio/classes/class.ilPortfolioAccessHandler.php');
6 
19 {
20  protected $user_id; // [int]
21  protected $portfolio; // [ilObjPortfolio]
22  protected $access_handler; // [ilPortfolioAccessHandler]
23  protected $additional = array();
24  protected $perma_link; // [string]
25 
29  function __construct()
30  {
31  global $ilCtrl, $lng, $ilUser;
32 
33  $lng->loadLanguageModule("prtf");
34 
35  $this->user_id = $ilUser->getId();
36  $this->access_handler = new ilPortfolioAccessHandler();
37 
38  $portfolio_id = $_REQUEST["prt_id"];
39  $ilCtrl->setParameter($this, "prt_id", $portfolio_id);
40 
41  if($portfolio_id)
42  {
43  $this->initPortfolioObject($portfolio_id);
44  }
45  }
46 
47  protected function checkAccess($a_permission, $a_portfolio_id = null)
48  {
49  if(!$a_portfolio_id && $this->portfolio)
50  {
51  $a_portfolio_id = $this->portfolio->getId();
52  }
53  if($a_portfolio_id)
54  {
55  return $this->access_handler->checkAccess($a_permission, "", $a_portfolio_id);
56  }
57  }
58 
64  function initPortfolioObject($a_id)
65  {
66  $portfolio = new ilObjPortfolio($a_id, false);
67  if($portfolio->getId() && $this->access_handler->checkAccess("read", "", $a_id))
68  {
69  $this->portfolio = $portfolio;
70  }
71  }
72 
76  function &executeCommand()
77  {
78  global $ilCtrl, $ilTabs, $lng, $tpl, $ilUser;
79 
80  $next_class = $ilCtrl->getNextClass($this);
81  $cmd = $ilCtrl->getCmd("show");
82 
83  $lng->loadLanguageModule("user");
84 
85  $title = $lng->txt("portfolio");
86  if($this->portfolio)
87  {
88  $title .= ": ".$this->portfolio->getTitle();
89  }
90  $tpl->setTitle($title);
91  $tpl->setTitleIcon(ilUtil::getImagePath("icon_prtf_b.png"),
92  $lng->txt("portfolio"));
93 
94  switch($next_class)
95  {
96  case "ilworkspaceaccessgui";
97  if($this->checkAccess("write"))
98  {
99  $ilTabs->clearTargets();
100  $ilCtrl->setParameter($this, "prt_id", "");
101  $ilTabs->setBackTarget($lng->txt("back"),
102  $ilCtrl->getLinkTarget($this, "show"));
103  $ilCtrl->setParameter($this, "prt_id", $this->portfolio->getId());
104 
105  $this->setPagesTabs();
106  $ilTabs->activateTab("share");
107 
108  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
109  $plink = new ilPermanentLinkGUI("prtf", $this->portfolio->getId());
110  $plink = $plink->getHTML();
111 
112  include_once('./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php');
113  $wspacc = new ilWorkspaceAccessGUI($this->portfolio->getId(), $this->access_handler, true, $plink);
114  $ilCtrl->forwardCommand($wspacc);
115  }
116  break;
117 
118  case 'ilportfoliopagegui':
119  $ilTabs->clearTargets();
120  $ilTabs->setBackTarget($lng->txt("back"),
121  $ilCtrl->getLinkTarget($this, "pages"));
122 
123  // edit
124  if(isset($_REQUEST["ppage"]) && $this->checkAccess("write"))
125  {
126  $this->setLocator($_REQUEST["ppage"]);
127 
128  $page_id = $_REQUEST["ppage"];
129  $ilCtrl->setParameter($this, "ppage", $_REQUEST["ppage"]);
130  }
131  // preview
132  else
133  {
134  $page_id = $_REQUEST["user_page"];
135  $ilCtrl->setParameter($this, "user_page", $_REQUEST["user_page"]);
136  }
137 
138  include_once("Services/Portfolio/classes/class.ilPortfolioPageGUI.php");
139  $page_gui = new ilPortfolioPageGUI($this->portfolio->getId(),
140  $page_id, 0, $this->portfolio->hasPublicComments());
141  $page_gui->setAdditional($this->getAdditional());
142 
143  $ret = $ilCtrl->forwardCommand($page_gui);
144 
145  if ($ret != "" && $ret !== true)
146  {
147  // preview (fullscreen)
148  if(isset($_REQUEST["user_page"]))
149  {
150  // suppress (portfolio) notes for blog postings
151  $this->preview(false, $ret, ($cmd != "previewEmbedded"));
152  }
153  // edit
154  else
155  {
156  $tpl->setContent($ret);
157  }
158  }
159  break;
160 
161  case "ilnotegui";
162  $this->preview();
163  break;
164 
165  default:
166  if($cmd != "preview")
167  {
168  $this->setLocator();
169  $this->setTabs();
170  }
171  $this->$cmd();
172  break;
173  }
174 
175  return true;
176  }
177 
184  function setTabs()
185  {
186  global $ilTabs, $lng, $ilCtrl, $ilHelp;
187 
188  $ilHelp->setScreenIdComponent("prtf");
189 
190  $ilTabs->addTab("mypf", $lng->txt("prtf_tab_portfolios"),
191  $ilCtrl->getLinkTarget($this));
192 
193  $ilTabs->addTab("otpf", $lng->txt("prtf_tab_other_users"),
194  $ilCtrl->getLinkTarget($this, "showother"));
195 
196  $ilTabs->activateTab("mypf");
197  }
198 
202  protected function show()
203  {
204  global $tpl, $lng, $ilToolbar, $ilCtrl, $ilTabs;
205 
206  $ilToolbar->addButton($lng->txt("prtf_add_portfolio"),
207  $ilCtrl->getLinkTarget($this, "add"));
208 
209  include_once "Services/Portfolio/classes/class.ilPortfolioTableGUI.php";
210  $table = new ilPortfolioTableGUI($this, "show", $this->user_id);
211 
212  $tpl->setContent($table->getHTML());
213  }
214 
215  protected function saveTitles()
216  {
217  global $ilCtrl, $lng;
218 
219  foreach($_POST["title"] as $id => $title)
220  {
221  if(trim($title))
222  {
223  if($this->checkAccess("write", $id))
224  {
225  $portfolio = new ilObjPortfolio($id, false);
226  $portfolio->setTitle($title);
227 
228  if(is_array($_POST["online"]) && in_array($id, $_POST["online"]))
229  {
230  $portfolio->setOnline(true);
231  }
232  else
233  {
234  $portfolio->setOnline(false);
235  }
236 
237  $portfolio->update();
238  }
239  }
240  }
241 
242  ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
243  $ilCtrl->redirect($this, "show");
244  }
245 
249  protected function add()
250  {
251  global $tpl;
252 
253  $form = $this->initForm();
254 
255  $tpl->setContent($form->getHTML());
256  }
257 
261  protected function save()
262  {
263  global $tpl, $lng, $ilCtrl;
264 
265  $form = $this->initForm();
266  if($form->checkInput())
267  {
268  $portfolio = new ilObjPortfolio();
269  $portfolio->setTitle($form->getInput("title"));
270  // $portfolio->setDescription($form->getInput("desc"));
271  $portfolio->create();
272 
273  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
274  $page = new ilPortfolioPage($portfolio->getId());
275  if($form->getInput("ptype") == "page")
276  {
278  $page->setTitle($form->getInput("fpage"));
279 
280  // use template as basis
281  $layout_id = $form->getInput("tmpl");
282  if($layout_id)
283  {
284  include_once("./Services/Style/classes/class.ilPageLayout.php");
285  $layout_obj = new ilPageLayout($layout_id);
286  $page->setXMLContent($layout_obj->getXMLContent());
287  }
288  }
289  else
290  {
291  $page->setType(ilPortfolioPage::TYPE_BLOG);
292  $page->setTitle($form->getInput("blog"));
293  }
294  $page->create();
295 
296  ilUtil::sendSuccess($lng->txt("prtf_portfolio_created"), true);
297  $ilCtrl->setParameter($this, "prt_id", $portfolio->getId());
298  $ilCtrl->redirect($this, "pages");
299  }
300 
301  $form->setValuesByPost();
302  $tpl->setContent($form->getHTML());
303  }
304 
308  protected function edit()
309  {
310  global $tpl, $ilTabs, $ilCtrl, $lng;
311 
312  $ilTabs->clearTargets();
313  $ilCtrl->setParameter($this, "prt_id", "");
314  $ilTabs->setBackTarget($lng->txt("back"),
315  $ilCtrl->getLinkTarget($this, "show"));
316  $ilCtrl->setParameter($this, "prt_id", $this->portfolio->getId());
317 
318  $this->setPagesTabs();
319  $ilTabs->activateTab("edit");
320 
321  $form = $this->initForm("edit");
322 
323  $tpl->setContent($form->getHTML());
324  }
325 
329  protected function update()
330  {
331  global $tpl, $lng, $ilCtrl, $ilUser;
332 
333  $form = $this->initForm("edit");
334  if($form->checkInput() && $this->checkAccess("write"))
335  {
336  $this->portfolio->setTitle($form->getInput("title"));
337  $this->portfolio->setDescription($form->getInput("desc"));
338  $this->portfolio->setOnline($form->getInput("online"));
339  $this->portfolio->setPublicComments($form->getInput("comments"));
340  $this->portfolio->setProfilePicture($form->getInput("ppic"));
341  $this->portfolio->setBackgroundColor($form->getInput("bg_color"));
342  $this->portfolio->setFontcolor($form->getInput("font_color"));
343 
344  $prfa_set = new ilSetting("prfa");
345 
346  if($_FILES["banner"]["tmp_name"])
347  {
348  $this->portfolio->uploadImage($_FILES["banner"]);
349  }
350  else if($prfa_set->get('banner') and $form->getItemByPostVar("banner")->getDeletionFlag())
351  {
352  $this->portfolio->deleteImage();
353  }
354 
355  $this->portfolio->update();
356 
357  // if portfolio is not online, it cannot be default
358  if(!$form->getInput("online"))
359  {
360  ilObjPortfolio::setUserDefault($ilUser->getId(), 0);
361  }
362 
363  ilUtil::sendSuccess($lng->txt("prtf_portfolio_updated"), true);
364  $ilCtrl->redirect($this, "pages");
365  }
366 
367  $form->setValuesByPost();
368  $tpl->setContent($form->getHTML());
369  }
370 
377  protected function initForm($a_mode = "create")
378  {
379  global $lng, $ilCtrl, $ilUser, $ilSetting;
380 
381  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
382  $form = new ilPropertyFormGUI();
383  $form->setFormAction($ilCtrl->getFormAction($this));
384 
385  // title
386  $ti = new ilTextInputGUI($lng->txt("title"), "title");
387  $ti->setMaxLength(128);
388  $ti->setSize(40);
389  $ti->setRequired(true);
390  $form->addItem($ti);
391 
392  /* description
393  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
394  $ta->setCols(40);
395  $ta->setRows(2);
396  $form->addItem($ta);
397  */
398 
399  if($a_mode == "create")
400  {
401  $type = new ilRadioGroupInputGUI($lng->txt("prtf_first_page_title"), "ptype");
402  $type->setRequired(true);
403  $form->addItem($type);
404 
405  $type_page = new ilRadioOption($lng->txt("page"), "page");
406  $type->addOption($type_page);
407 
408  // 1st page
409  $tf = new ilTextInputGUI($lng->txt("title"), "fpage");
410  $tf->setMaxLength(128);
411  $tf->setSize(40);
412  $tf->setRequired(true);
413  $type_page->addSubItem($tf);
414 
415  include_once "Services/Style/classes/class.ilPageLayout.php";
417  if($templates)
418  {
419  $options = array(0 => $lng->txt("none"));
420  foreach ($templates as $templ)
421  {
422  $templ->readObject();
423  $options[$templ->getId()] = $templ->getTitle();
424  }
425 
426  $use_template = new ilSelectInputGUI($lng->txt("prtf_use_page_layout"), "tmpl");
427  $use_template->setRequired(true);
428  $use_template->setOptions($options);
429  $type_page->addSubItem($use_template);
430  }
431 
432  if(!$ilSetting->get('disable_wsp_blogs'))
433  {
434  $options = array();
435  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
436  $tree = new ilWorkspaceTree($ilUser->getId());
437  $root = $tree->readRootId();
438  if($root)
439  {
440  $root = $tree->getNodeData($root);
441  foreach ($tree->getSubTree($root) as $node)
442  {
443  if ($node["type"] == "blog")
444  {
445  $options[$node["obj_id"]] = $node["title"];
446  }
447  }
448  asort($options);
449  }
450  if(sizeof($options))
451  {
452  $type_blog = new ilRadioOption($lng->txt("obj_blog"), "blog");
453  $type->addOption($type_blog);
454 
455  $obj = new ilSelectInputGUI($lng->txt("obj_blog"), "blog");
456  $obj->setRequired(true);
457  $obj->setOptions($options);
458  $type_blog->addSubItem($obj);
459  }
460  else
461  {
462  ilUtil::sendInfo($lng->txt("prtf_no_blogs_info"));
463  $type->setValue("page");
464  }
465  }
466 
467  $form->setTitle($lng->txt("prtf_create_portfolio"));
468  $form->addCommandButton("save", $lng->txt("save"));
469  $form->addCommandButton("show", $lng->txt("cancel"));
470  }
471  else
472  {
473  // online
474  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
475  $form->addItem($online);
476 
477  // comments
478  $comments = new ilCheckboxInputGUI($lng->txt("prtf_public_comments"), "comments");
479  $form->addItem($comments);
480 
481  // profile picture
482  $ppic = new ilCheckboxInputGUI($lng->txt("prtf_profile_picture"), "ppic");
483  $form->addItem($ppic);
484 
485  $prfa_set = new ilSetting("prfa");
486  if($prfa_set->get("banner"))
487  {
488  $dimensions = " (".$prfa_set->get("banner_width")."x".
489  $prfa_set->get("banner_height").")";
490 
491  $img = new ilImageFileInputGUI($lng->txt("prtf_banner").$dimensions, "banner");
492  $form->addItem($img);
493 
494  // show existing file
495  $file = $this->portfolio->getImageFullPath(true);
496  if($file)
497  {
498  $img->setImage($file);
499  }
500  }
501 
502  $bg_color = new ilColorPickerInputGUI($lng->txt("prtf_background_color"), "bg_color");
503  $form->addItem($bg_color);
504 
505  $font_color = new ilColorPickerInputGUI($lng->txt("prtf_font_color"), "font_color");
506  $form->addItem($font_color);
507 
508  $ti->setValue($this->portfolio->getTitle());
509  // $ta->setValue($this->portfolio->getDescription());
510  $online->setChecked($this->portfolio->isOnline());
511  $comments->setChecked($this->portfolio->hasPublicComments());
512  $ppic->setChecked($this->portfolio->hasProfilePicture());
513  $bg_color->setValue($this->portfolio->getBackgroundColor());
514  $font_color->setValue($this->portfolio->getFontColor());
515 
516  $form->setTitle($lng->txt("prtf_edit_portfolio"));
517  $form->addCommandButton("update", $lng->txt("save"));
518  $form->addCommandButton("show", $lng->txt("cancel"));
519  }
520 
521  return $form;
522  }
523 
527  protected function setDefaultConfirmation()
528  {
529  global $ilCtrl, $lng, $tpl;
530 
531  if($this->portfolio && $this->checkAccess("write"))
532  {
533  // if already shared, no need to ask again
534  if($this->access_handler->hasRegisteredPermission($this->portfolio->getId()) ||
535  $this->access_handler->hasGlobalPermission($this->portfolio->getId()))
536  {
537  return $this->setDefault();
538  }
539 
540  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
541  $cgui = new ilConfirmationGUI();
542  $cgui->setFormAction($ilCtrl->getFormAction($this));
543  $cgui->setHeaderText($lng->txt("prtf_set_default_publish_confirmation"));
544  $cgui->setCancel($lng->txt("yes"), "setDefaultGlobal");
545  $cgui->setConfirm($lng->txt("no"), "setDefaultRegistered");
546 
547  $tpl->setContent($cgui->getHTML());
548  return;
549  }
550  $ilCtrl->redirect($this, "show");
551  }
552 
553  protected function setDefaultGlobal()
554  {
555  global $ilCtrl;
556 
557  if($this->portfolio && $this->checkAccess("write"))
558  {
559  $this->access_handler->addPermission($this->portfolio->getId(), ilWorkspaceAccessGUI::PERMISSION_ALL);
560  $this->setDefault();
561  }
562  $ilCtrl->redirect($this, "show");
563  }
564 
565  protected function setDefaultRegistered()
566  {
567  global $ilCtrl;
568 
569  if($this->portfolio && $this->checkAccess("write"))
570  {
571  $this->access_handler->addPermission($this->portfolio->getId(), ilWorkspaceAccessGUI::PERMISSION_REGISTERED);
572  $this->setDefault();
573  }
574  $ilCtrl->redirect($this, "show");
575  }
576 
580  protected function setDefault()
581  {
582  global $ilCtrl, $lng, $ilUser;
583 
584  if($this->portfolio && $this->checkAccess("write"))
585  {
586  // #12845
587  if($this->access_handler->hasGlobalPermission($this->portfolio->getId()))
588  {
589  $ilUser->setPref("public_profile", "g");
590  $ilUser->writePrefs();
591  }
592  else if($this->access_handler->hasRegisteredPermission($this->portfolio->getId()))
593  {
594  $ilUser->setPref("public_profile", "y");
595  $ilUser->writePrefs();
596  }
597  else
598  {
599  return;
600  }
601  ilObjPortfolio::setUserDefault($this->user_id, $this->portfolio->getId());
602  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
603  }
604  $ilCtrl->redirect($this, "show");
605  }
606 
610  protected function unsetDefault()
611  {
612  global $ilCtrl, $lng, $ilUser;
613 
614  if($this->portfolio && $this->checkAccess("write"))
615  {
616  // #12845
617  $ilUser->setPref("public_profile", "n");
618  $ilUser->writePrefs();
619 
620  ilObjPortfolio::setUserDefault($this->user_id);
621  ilUtil::sendSuccess($lng->txt("prtf_unset_default_share_info"), true);
622  }
623  $ilCtrl->redirect($this, "show");
624  }
625 
630  {
631  global $ilCtrl, $tpl, $lng;
632 
633  if (!is_array($_POST["prtfs"]) || count($_POST["prtfs"]) == 0)
634  {
635  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
636  $ilCtrl->redirect($this, "show");
637  }
638  else
639  {
640  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
641  $cgui = new ilConfirmationGUI();
642  $cgui->setFormAction($ilCtrl->getFormAction($this));
643  $cgui->setHeaderText($lng->txt("prtf_sure_delete_portfolios"));
644  $cgui->setCancel($lng->txt("cancel"), "show");
645  $cgui->setConfirm($lng->txt("delete"), "deletePortfolios");
646 
647  foreach ($_POST["prtfs"] as $id)
648  {
649  $cgui->addItem("prtfs[]", $id, ilObjPortfolio::_lookupTitle($id));
650  }
651 
652  $tpl->setContent($cgui->getHTML());
653  }
654  }
655 
659  function deletePortfolios()
660  {
661  global $lng, $ilCtrl;
662 
663  if (is_array($_POST["prtfs"]))
664  {
665  foreach ($_POST["prtfs"] as $id)
666  {
667  if($this->checkAccess("write", $id))
668  {
669  $portfolio = new ilObjPortfolio($id, false);
670  if ($portfolio->getOwner() == $this->user_id)
671  {
672  $this->access_handler->removePermission($id);
673  $portfolio->delete();
674  }
675  }
676  }
677  }
678  ilUtil::sendSuccess($lng->txt("prtf_portfolio_deleted"), true);
679  $ilCtrl->redirect($this, "show");
680  }
681 
682 
683  //
684  // PAGES
685  //
686 
687  protected function setPagesTabs()
688  {
689  global $lng, $ilTabs, $ilCtrl, $ilHelp;
690 
691  if($this->checkAccess("write"))
692  {
693  $ilHelp->setScreenIdComponent("prtf");
694 
695  $ilTabs->addTab("pages",
696  $lng->txt("content"),
697  $ilCtrl->getLinkTarget($this, "pages"));
698 
699  $ilTabs->addTab("edit",
700  $lng->txt("settings"),
701  $ilCtrl->getLinkTarget($this, "edit"));
702 
703  $lng->loadLanguageModule("wsp");
704  $ilTabs->addTab("share",
705  $lng->txt("wsp_permissions"),
706  $ilCtrl->getLinkTargetByClass("ilworkspaceaccessgui", "share"));
707  }
708 
709  $ilTabs->addNonTabbedLink("preview",
710  $lng->txt("user_profile_preview"),
711  $ilCtrl->getLinkTarget($this, "preview"));
712  }
713 
717  protected function pages()
718  {
719  global $tpl, $lng, $ilToolbar, $ilCtrl, $ilTabs, $ilUser, $ilSetting, $tree;
720 
721  if(!$this->checkAccess("write"))
722  {
723  return;
724  }
725 
726  $ilTabs->clearTargets();
727 
728  $ilCtrl->setParameter($this, "prt_id", "");
729  $ilTabs->setBackTarget($lng->txt("back"),
730  $ilCtrl->getLinkTarget($this, "show"));
731  $ilCtrl->setParameter($this, "prt_id", $this->portfolio->getId());
732 
733  $this->setPagesTabs();
734  $ilTabs->activateTab("pages");
735 
736  $ilToolbar->addButton($lng->txt("prtf_add_page"),
737  $ilCtrl->getLinkTarget($this, "addPage"));
738 
739  if(!$ilSetting->get('disable_wsp_blogs'))
740  {
741  $ilToolbar->addButton($lng->txt("prtf_add_blog"),
742  $ilCtrl->getLinkTarget($this, "addBlog"));
743  }
744 
745  $ilToolbar->addSeparator();
746 
747  $ilToolbar->addButton($lng->txt("export"),
748  $ilCtrl->getLinkTarget($this, "export"));
749 
750  include_once "Services/Portfolio/classes/class.ilPortfolioPageTableGUI.php";
751  $table = new ilPortfolioPageTableGUI($this, "pages", $this->portfolio);
752 
753  // exercise portfolio?
754  include_once "Modules/Exercise/classes/class.ilObjExercise.php";
755  $exercises = ilObjExercise::findUserFiles($ilUser->getId(), $this->portfolio->getId());
756  if($exercises)
757  {
758  $info = array();
759  foreach($exercises as $exercise)
760  {
761  // #9988
762  $active_ref = false;
763  foreach(ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id)
764  {
765  if(!$tree->isSaved($ref_id))
766  {
767  $active_ref = true;
768  break;
769  }
770  }
771  if($active_ref)
772  {
773  $part = $this->getExerciseInfo($exercise["ass_id"], $table->dataExists());
774  if($part)
775  {
776  $info[] = $part;
777  }
778  }
779  }
780  if(sizeof($info))
781  {
782  ilUtil::sendInfo(implode("<br />", $info));
783  }
784  }
785 
786  $tpl->setContent($table->getHTML());
787  }
788 
789  function getExerciseInfo($a_assignment_id, $a_add_submit = false)
790  {
791  global $lng, $ilCtrl, $ilUser;
792 
793  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
794  $ass = new ilExAssignment($a_assignment_id);
795  $exercise_id = $ass->getExerciseId();
796  if(!$exercise_id)
797  {
798  return;
799  }
800 
801  // is the assignment still open?
802  $times_up = false;
803  if($ass->getDeadline() && $ass->getDeadline() - time() <= 0)
804  {
805  $times_up = true;
806  }
807 
808  // exercise goto
809  include_once "./Services/Link/classes/class.ilLink.php";
810  $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
811  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
812 
813  $info = sprintf($lng->txt("prtf_exercise_info"),
814  $ass->getTitle(),
815  "<a href=\"".$exc_link."\">".
816  ilObject::_lookupTitle($exercise_id)."</a>");
817 
818  // submit button
819  if($a_add_submit && !$times_up)
820  {
821  $ilCtrl->setParameter($this, "exc", $exercise_id);
822  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
823  $submit_link = $ilCtrl->getLinkTarget($this, "finalize");
824  $ilCtrl->setParameter($this, "ass", "");
825  $ilCtrl->setParameter($this, "exc", "");
826  $info .= " <a class=\"submit\" href=\"".$submit_link."\">".$lng->txt("prtf_finalize_portfolio")."</a>";
827  }
828 
829  // submitted files
830  $submitted = ilExAssignment::getDeliveredFiles($exercise_id, $a_assignment_id, $ilUser->getId(), true);
831  if($submitted)
832  {
833  $submitted = array_pop($submitted);
834 
835  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
836  $dl_link = $ilCtrl->getLinkTarget($this, "downloadExcSubFile");
837  $ilCtrl->setParameter($this, "ass", "");
838 
841 
842  $info .= "<br />".sprintf($lng->txt("prtf_exercise_submitted_info"),
844  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
845 
847  }
848 
849 
850  // work instructions incl. files
851 
852  $tooltip = "";
853 
854  $ass = $ass->getInstruction();
855  if($ass)
856  {
857  $tooltip .= nl2br($ass);
858  }
859 
860  $ass_files = ilExAssignment::getFiles($exercise_id, $a_assignment_id);
861  if (count($ass_files) > 0)
862  {
863  $tooltip .= "<br /><br />";
864 
865  foreach($ass_files as $file)
866  {
867  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
868  $ilCtrl->setParameter($this, "file", urlencode($file["name"]));
869  $dl_link = $ilCtrl->getLinkTarget($this, "downloadExcAssFile");
870  $ilCtrl->setParameter($this, "file", "");
871  $ilCtrl->setParameter($this, "ass", "");
872 
873  $tooltip .= $file["name"].": <a href=\"".$dl_link."\">".
874  $lng->txt("download")."</a>";
875  }
876  }
877 
878  if($tooltip)
879  {
880  $ol_id = "exc_ass_".$a_assignment_id;
881 
882  include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
883  $overlay = new ilOverlayGUI($ol_id);
884 
885  // overlay
886  $overlay->setAnchor($ol_id."_tr");
887  $overlay->setTrigger($ol_id."_tr", "click", $ol_id."_tr");
888  $overlay->setAutoHide(false);
889  // $overlay->setCloseElementId($cl_id);
890  $overlay->add();
891 
892  // trigger
893  $overlay->addTrigger($ol_id."_tr", "click", $ol_id."_tr");
894 
895  $info .= "<div id=\"".$ol_id."_tr\"><a href=\"#\">".$lng->txt("exc_instruction")."</a></div>".
896  "<div id=\"".$ol_id."\" style=\"display:none; background-color:white; border: 1px solid #bbb; padding: 10px;\">".$tooltip."</div>";
897  }
898 
899  return $info;
900  }
901 
903  {
904  if($_GET["ass"] && $_GET["file"])
905  {
906  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
907  $ass = new ilExAssignment((int)$_GET["ass"]);
908 
909  $ass_files = ilExAssignment::getFiles($ass->getExerciseId(), $ass->getId());
910  if (count($ass_files) > 0)
911  {
912  foreach($ass_files as $file)
913  {
914  if($file["name"] == $_GET["file"])
915  {
916  ilUtil::deliverFile($file["fullpath"], $file["name"]);
917  }
918  }
919  }
920  }
921  }
922 
924  {
925  global $ilUser;
926 
927  if($_GET["ass"])
928  {
929  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
930  $ass = new ilExAssignment((int)$_GET["ass"]);
931 
932  $submitted = ilExAssignment::getDeliveredFiles($ass->getExerciseId(), $ass->getId(), $ilUser->getId());
933  if (count($submitted) > 0)
934  {
935  $submitted = array_pop($submitted);
936 
937  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
938  $title = ilObject::_lookupTitle($submitted["obj_id"])." - ".
939  $ass->getTitle()." - ".
940  $user_data["firstname"]." ".
941  $user_data["lastname"]." (".
942  $user_data["login"].").zip";
943 
944  ilUtil::deliverFile($submitted["filename"], $title);
945  }
946  }
947  }
948 
952  protected function addPage()
953  {
954  global $tpl, $lng, $ilTabs, $ilCtrl;
955 
956  $ilTabs->clearTargets();
957  $ilTabs->setBackTarget($lng->txt("back"),
958  $ilCtrl->getLinkTarget($this, "pages"));
959 
960  $form = $this->initPageForm("create");
961  $tpl->setContent($form->getHTML());
962  }
963 
970  public function initPageForm($a_mode = "create")
971  {
972  global $lng, $ilCtrl, $ilUser;
973 
974  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
975  $form = new ilPropertyFormGUI();
976  $form->setFormAction($ilCtrl->getFormAction($this));
977 
978  // title
979  $ti = new ilTextInputGUI($lng->txt("title"), "title");
980  $ti->setMaxLength(200);
981  $ti->setRequired(true);
982  $form->addItem($ti);
983 
984  // save and cancel commands
985  if ($a_mode == "create")
986  {
987  include_once "Services/Style/classes/class.ilPageLayout.php";
989  if($templates)
990  {
991  $use_template = new ilRadioGroupInputGUI($lng->txt("prtf_use_page_layout"), "tmpl");
992  $use_template->setRequired(true);
993  $form->addItem($use_template);
994 
995  $opt = new ilRadioOption($lng->txt("none"), 0);
996  $use_template->addOption($opt);
997 
998  foreach ($templates as $templ)
999  {
1000  $templ->readObject();
1001 
1002  $opt = new ilRadioOption($templ->getTitle().$templ->getPreview(), $templ->getId());
1003  $use_template->addOption($opt);
1004  }
1005  }
1006 
1007  $form->setTitle($lng->txt("prtf_add_page").": ".
1008  $this->portfolio->getTitle());
1009  $form->addCommandButton("savePage", $lng->txt("save"));
1010  $form->addCommandButton("pages", $lng->txt("cancel"));
1011  }
1012  else
1013  {
1014  /* edit is done directly in table gui
1015  $form->setTitle($lng->txt("prtf_edit_page"));
1016  $form->addCommandButton("updatePage", $lng->txt("save"));
1017  $form->addCommandButton("pages", $lng->txt("cancel"));
1018  */
1019  }
1020 
1021  return $form;
1022  }
1023 
1027  public function savePage()
1028  {
1029  global $tpl, $lng, $ilCtrl, $ilTabs;
1030 
1031  $form = $this->initPageForm("create");
1032  if ($form->checkInput() && $this->checkAccess("write"))
1033  {
1034  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
1035  $page = new ilPortfolioPage($this->portfolio->getId());
1037  $page->setTitle($form->getInput("title"));
1038 
1039  // use template as basis
1040  $layout_id = $form->getInput("tmpl");
1041  if($layout_id)
1042  {
1043  include_once("./Services/Style/classes/class.ilPageLayout.php");
1044  $layout_obj = new ilPageLayout($layout_id);
1045  $page->setXMLContent($layout_obj->getXMLContent());
1046  }
1047 
1048  $page->create();
1049 
1050  ilUtil::sendSuccess($lng->txt("prtf_page_created"), true);
1051  $ilCtrl->redirect($this, "pages");
1052  }
1053 
1054  $ilTabs->clearTargets();
1055  $ilTabs->setBackTarget($lng->txt("back"),
1056  $ilCtrl->getLinkTarget($this, "pages"));
1057 
1058  $form->setValuesByPost();
1059  $tpl->setContent($form->getHtml());
1060  }
1061 
1065  protected function addBlog()
1066  {
1067  global $tpl, $lng, $ilTabs, $ilCtrl;
1068 
1069  $ilTabs->clearTargets();
1070  $ilTabs->setBackTarget($lng->txt("back"),
1071  $ilCtrl->getLinkTarget($this, "pages"));
1072 
1073  $form = $this->initBlogForm("create");
1074  $tpl->setContent($form->getHTML());
1075  }
1076 
1083  public function initBlogForm($a_mode = "create")
1084  {
1085  global $lng, $ilCtrl, $ilUser;
1086 
1087  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1088  $form = new ilPropertyFormGUI();
1089  $form->setFormAction($ilCtrl->getFormAction($this));
1090 
1091  $options = array();
1092  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1093  $tree = new ilWorkspaceTree($ilUser->getId());
1094  $root = $tree->readRootId();
1095  if($root)
1096  {
1097  $root = $tree->getNodeData($root);
1098  foreach ($tree->getSubTree($root) as $node)
1099  {
1100  if ($node["type"] == "blog")
1101  {
1102  $options[$node["obj_id"]] = $node["title"];
1103  }
1104  }
1105  asort($options);
1106  }
1107 
1108  // no blogs to add?
1109  if(!sizeof($options))
1110  {
1111  ilUtil::sendInfo($lng->txt("prtf_no_blogs_info"), true);
1112  $ilCtrl->redirect($this, "pages");
1113  }
1114 
1115  $obj = new ilSelectInputGUI($lng->txt("obj_blog"), "blog");
1116  $obj->setRequired(true);
1117  $obj->setOptions($options);
1118  $form->addItem($obj);
1119 
1120  // save and cancel commands
1121  if ($a_mode == "create")
1122  {
1123  $form->setTitle($lng->txt("prtf_add_blog").": ".
1124  $this->portfolio->getTitle());
1125  $form->addCommandButton("saveBlog", $lng->txt("save"));
1126  $form->addCommandButton("pages", $lng->txt("cancel"));
1127 
1128  }
1129  else
1130  {
1131  /* edit is done directly in table gui
1132  $form->setTitle($lng->txt("prtf_edit_page"));
1133  $form->addCommandButton("updatePage", $lng->txt("save"));
1134  $form->addCommandButton("pages", $lng->txt("cancel"));
1135  */
1136  }
1137 
1138  return $form;
1139  }
1140 
1144  public function saveBlog()
1145  {
1146  global $tpl, $lng, $ilCtrl, $ilTabs;
1147 
1148  $form = $this->initBlogForm("create");
1149  if ($form->checkInput() && $this->checkAccess("write"))
1150  {
1151  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
1152  $page = new ilPortfolioPage($this->portfolio->getId());
1154  $page->setTitle($form->getInput("blog"));
1155  $page->create();
1156 
1157  ilUtil::sendSuccess($lng->txt("prtf_page_created"), true);
1158  $ilCtrl->redirect($this, "pages");
1159  }
1160 
1161  $ilTabs->clearTargets();
1162  $ilTabs->setBackTarget($lng->txt("back"),
1163  $ilCtrl->getLinkTarget($this, "pages"));
1164 
1165  $form->setValuesByPost();
1166  $tpl->setContent($form->getHtml());
1167  }
1168 
1173  {
1174  global $ilCtrl, $ilUser, $lng;
1175 
1176  if(!$this->checkAccess("write"))
1177  {
1178  return;
1179  }
1180 
1181  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
1182 
1183  if (is_array($_POST["order"]))
1184  {
1185  foreach ($_POST["order"] as $k => $v)
1186  {
1187  $page = new ilPortfolioPage($this->portfolio->getId(),
1188  ilUtil::stripSlashes($k));
1189  if($_POST["title"][$k])
1190  {
1191  $page->setTitle(ilUtil::stripSlashes($_POST["title"][$k]));
1192  }
1193  $page->setOrderNr(ilUtil::stripSlashes($v));
1194  $page->update();
1195  }
1196  ilPortfolioPage::fixOrdering($this->portfolio->getId());
1197  }
1198 
1199  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1200  $ilCtrl->redirect($this, "pages");
1201  }
1202 
1207  {
1208  global $ilCtrl, $tpl, $lng;
1209 
1210  if (!is_array($_POST["prtf_pages"]) || count($_POST["prtf_pages"]) == 0)
1211  {
1212  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1213  $ilCtrl->redirect($this, "pages");
1214  }
1215  else
1216  {
1217  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1218  $cgui = new ilConfirmationGUI();
1219  $cgui->setFormAction($ilCtrl->getFormAction($this));
1220  $cgui->setHeaderText($lng->txt("prtf_sure_delete_portfolio_pages"));
1221  $cgui->setCancel($lng->txt("cancel"), "pages");
1222  $cgui->setConfirm($lng->txt("delete"), "deletePortfolioPages");
1223 
1224  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
1225  foreach ($_POST["prtf_pages"] as $id)
1226  {
1227  $page = new ilPortfolioPage($this->portfolio->getId(), $id);
1228  $title = $page->getTitle();
1229  if($page->getType() == ilPortfolioPage::TYPE_BLOG)
1230  {
1231  $title = $lng->txt("obj_blog").": ".ilObject::_lookupTitle((int)$title);
1232  }
1233  $cgui->addItem("prtf_pages[]", $id, $title);
1234  }
1235 
1236  $tpl->setContent($cgui->getHTML());
1237  }
1238  }
1239 
1244  {
1245  global $lng, $ilCtrl;
1246 
1247  if(!$this->checkAccess("write"))
1248  {
1249  return;
1250  }
1251 
1252  include_once("Services/Portfolio/classes/class.ilPortfolioPage.php");
1253  if (is_array($_POST["prtf_pages"]))
1254  {
1255  foreach ($_POST["prtf_pages"] as $id)
1256  {
1257  $page = new ilPortfolioPage($this->portfolio->getId(), $id);
1258  $page->delete();
1259  }
1260  }
1261  ilUtil::sendSuccess($lng->txt("prtf_portfolio_page_deleted"), true);
1262  $ilCtrl->redirect($this, "pages");
1263  }
1264 
1268  function preview($a_return = false, $a_content = false, $a_show_notes = true)
1269  {
1270  global $ilUser, $tpl, $ilCtrl, $ilTabs, $lng;
1271 
1272  // public profile
1273  if($_REQUEST["back_url"])
1274  {
1275  $back = $_REQUEST["back_url"];
1276  }
1277  // shared
1278  else if($_GET["baseClass"] != "ilPublicUserProfileGUI" &&
1279  $ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
1280  {
1281  if(!$this->checkAccess("write"))
1282  {
1283  $ilCtrl->setParameter($this, "user", $this->portfolio->getOwner());
1284  $back = $ilCtrl->getLinkTarget($this, "showOther");
1285  $ilCtrl->setParameter($this, "user", "");
1286  }
1287  // owner
1288  else
1289  {
1290  $back = $ilCtrl->getLinkTarget($this, "pages");
1291  }
1292  }
1293  $tpl->setTopBar($back);
1294 
1295  $portfolio_id = $this->portfolio->getId();
1296  $user_id = $this->portfolio->getOwner();
1297 
1298  $ilTabs->clearTargets();
1299 
1300  include_once("./Services/Portfolio/classes/class.ilPortfolioPage.php");
1301  $pages = ilPortfolioPage::getAllPages($portfolio_id);
1302  $current_page = $_GET["user_page"];
1303 
1304  // display first page of portfolio if none given
1305  if(!$current_page && $pages)
1306  {
1307  $current_page = $pages;
1308  $current_page = array_shift($current_page);
1309  $current_page = $current_page["id"];
1310  }
1311 
1312  // render tabs
1313  $current_blog = null;
1314  if(count($pages) > 1)
1315  {
1316  foreach ($pages as $p)
1317  {
1318  if($p["type"] == ilPortfolioPage::TYPE_BLOG)
1319  {
1320  // needed for blog comments (see below)
1321  if($p["id"] == $current_page)
1322  {
1323  $current_blog = (int)$p["title"];
1324  }
1325  include_once "Modules/Blog/classes/class.ilObjBlog.php";
1326  $p["title"] = ilObjBlog::_lookupTitle($p["title"]);
1327  }
1328 
1329  $ilCtrl->setParameter($this, "user_page", $p["id"]);
1330  $ilTabs->addTab("user_page_".$p["id"],
1331  $p["title"],
1332  $ilCtrl->getLinkTarget($this, "preview"));
1333  }
1334 
1335  $ilTabs->activateTab("user_page_".$current_page);
1336  }
1337 
1338  $ilCtrl->setParameter($this, "user_page", $current_page);
1339 
1340  if(!$a_content)
1341  {
1342  // get current page content
1343  include_once("./Services/Portfolio/classes/class.ilPortfolioPageGUI.php");
1344  $page_gui = new ilPortfolioPageGUI($portfolio_id, $current_page, 0,
1345  $this->portfolio->hasPublicComments());
1346  $page_gui->setEmbedded(true);
1347  $page_gui->setAdditional($this->getAdditional());
1348 
1349  $content = $ilCtrl->getHTML($page_gui);
1350  }
1351  else
1352  {
1353  $content = $a_content;
1354  }
1355 
1356  if($a_return && $this->checkAccess("write"))
1357  {
1358  return $content;
1359  }
1360 
1361  // blog posting comments are handled within the blog
1362  $notes = "";
1363  if($a_show_notes && $this->portfolio->hasPublicComments() && !$current_blog)
1364  {
1365  include_once("./Services/Notes/classes/class.ilNoteGUI.php");
1366  $note_gui = new ilNoteGUI($portfolio_id, $current_page, "pfpg");
1367  $note_gui->setRepositoryMode(false);
1368  $note_gui->enablePublicNotes(true);
1369  $note_gui->enablePrivateNotes(false);
1370  $note_gui->enablePublicNotesDeletion($ilUser->getId() == $user_id);
1371 
1372  $next_class = $ilCtrl->getNextClass($this);
1373  if ($next_class == "ilnotegui")
1374  {
1375  $notes = $ilCtrl->forwardCommand($note_gui);
1376  }
1377  else
1378  {
1379  $notes = $note_gui->getNotesHTML();
1380  }
1381  }
1382 
1383  if($this->perma_link === null)
1384  {
1385  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
1386  $plink = new ilPermanentLinkGUI("prtf", $this->portfolio->getId());
1387  $plink = $plink->getHTML();
1388  }
1389  else
1390  {
1391  $plink = $this->perma_link;
1392  }
1393 
1394  self::renderFullscreenHeader($this->portfolio, $tpl, $user_id);
1395 
1396  // wiki/forum will set locator items
1397  $tpl->setVariable("LOCATOR", "");
1398 
1399  // #10717
1400  $tpl->setContent($content.
1401  '<div class="ilClearFloat">'.$notes.$plink.'</div>');
1402  $tpl->setFrameFixedWidth(true);
1403 
1404  echo $tpl->show("DEFAULT", true, true);
1405  exit();
1406  }
1407 
1415  public static function renderFullscreenHeader($a_portfolio, $a_tpl, $a_user_id, $a_export = false)
1416  {
1417  $name = ilObjUser::_lookupName($a_user_id);
1418  $name = $name["lastname"].", ".($t = $name["title"] ? $t . " " : "").$name["firstname"];
1419 
1420  // show banner?
1421  $banner = $banner_width = $banner_height = false;
1422  $prfa_set = new ilSetting("prfa");
1423  if($prfa_set->get("banner"))
1424  {
1425  $banner = $a_portfolio->getImageFullPath();
1426  $banner_width = $prfa_set->get("banner_width");
1427  $banner_height = $prfa_set->get("banner_height");
1428  if($a_export)
1429  {
1430  $banner = basename($banner);
1431  }
1432  }
1433 
1434  // profile picture
1435  $ppic = null;
1436  if($a_portfolio->hasProfilePicture())
1437  {
1438  $ppic = ilObjUser::_getPersonalPicturePath($a_user_id, "big");
1439  if($a_export)
1440  {
1441  $ppic = basename($ppic);
1442  }
1443  }
1444 
1445  include_once("./Services/User/classes/class.ilUserUtil.php");
1446  $a_tpl->setFullscreenHeader($a_portfolio->getTitle(),
1447  $name,
1448  $ppic,
1449  $banner,
1450  $a_portfolio->getBackgroundColor(),
1451  $a_portfolio->getFontColor(),
1452  $banner_width,
1453  $banner_height,
1454  $a_export);
1455  $a_tpl->setBodyClass("std ilExternal ilPortfolio");
1456  }
1457 
1458  function export()
1459  {
1460  include_once "Services/Portfolio/classes/class.ilPortfolioHTMLExport.php";
1461  $export = new ilPortfolioHTMLExport($this, $this->portfolio);
1462  $zip = $export->buildExportFile();
1463 
1464  ilUtil::deliverFile($zip, $this->portfolio->getTitle().".zip", '', false, true);
1465  }
1466 
1470  protected function finalize()
1471  {
1472  global $ilUser, $ilCtrl, $lng;
1473 
1474  // to make exercise gui load assignment
1475  $_GET["ass_id"] = $_REQUEST["ass"];
1476 
1477  // #11173 - ref_id is needed for notifications
1478  $exc_ref_id = array_shift(ilObject::_getAllReferences($_REQUEST["exc"]));
1479 
1480  include_once "Modules/Exercise/classes/class.ilObjExerciseGUI.php";
1481  $exc_gui = new ilObjExerciseGUI(null, $exc_ref_id, true);
1482  $exc_gui->submitPortfolio($this->portfolio->getId());
1483 
1484  ilUtil::sendSuccess($lng->txt("prtf_finalized"), true);
1485  $ilCtrl->redirect($this, "pages");
1486  }
1487 
1488  protected function setLocator($a_page_id = null)
1489  {
1490  global $ilLocator, $lng, $ilCtrl, $tpl;
1491 
1492  $ilCtrl->setParameter($this, "prt_id", "");
1493  $ilLocator->addItem($lng->txt("portfolio"),
1494  $ilCtrl->getLinkTarget($this, "show"));
1495 
1496  if($this->portfolio)
1497  {
1498  $ilCtrl->setParameter($this, "prt_id", $this->portfolio->getId());
1499  $ilLocator->addItem($this->portfolio->getTitle(),
1500  $ilCtrl->getLinkTarget($this, "pages"));
1501  }
1502 
1503  if($a_page_id)
1504  {
1505  include_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
1506  $page = new ilPortfolioPage($this->portfolio->getId(), $a_page_id);
1507  $title = $page->getTitle();
1508  if($page->getType() == ilPortfolioPage::TYPE_BLOG)
1509  {
1510  $title = ilObject::_lookupTitle($title);
1511  }
1512  $ilCtrl->setParameterByClass("ilportfoliopagegui", "ppage", $a_page_id);
1513  $ilLocator->addItem($title,
1514  $ilCtrl->getLinkTargetByClass("ilportfoliopagegui", "edit"));
1515  }
1516 
1517  $tpl->setLocator();
1518  }
1519 
1523  function copyPageForm($a_form = null)
1524  {
1525  global $ilCtrl, $tpl, $lng, $ilUser;
1526 
1527  if (!is_array($_POST["prtf_pages"]) || count($_POST["prtf_pages"]) == 0)
1528  {
1529  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1530  $ilCtrl->redirect($this, "pages");
1531  }
1532  else
1533  {
1534  if(!$a_form)
1535  {
1536  $a_form = $this->initCopyPageForm();
1537  }
1538 
1539  foreach($_POST["prtf_pages"] as $page_id)
1540  {
1541  $item = new ilHiddenInputGUI("prtf_pages[]");
1542  $item->setValue($page_id);
1543  $a_form->addItem($item);
1544  }
1545 
1546  $tpl->setContent($a_form->getHTML());
1547  }
1548  }
1549 
1550  function copyPage()
1551  {
1552  global $ilCtrl, $lng;
1553 
1554  $form = $this->initCopyPageForm();
1555  if($form->checkInput())
1556  {
1557  // existing
1558  if($form->getInput("target") == "old")
1559  {
1560  $portfolio_id = $form->getInput("prtf");
1561  $portfolio = new ilObjPortfolio($portfolio_id, false);
1562  }
1563  // new
1564  else
1565  {
1566  $portfolio = new ilObjPortfolio();
1567  $portfolio->setTitle($form->getInput("title"));
1568  $portfolio->create();
1569  $portfolio_id = $portfolio->getId();
1570  }
1571 
1572  // copy page(s)
1573  include_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
1574  foreach($_POST["prtf_pages"] as $page_id)
1575  {
1576  $source = new ilPortfolioPage($portfolio_id, $page_id);
1577 
1578  $target = new ilPortfolioPage($portfolio_id);
1579  $target->setXMLContent($source->copyXmlContent());
1580  $target->setType($source->getType());
1581  $target->setTitle($source->getTitle());
1582  $target->create();
1583  }
1584 
1585  ilUtil::sendSuccess($lng->txt("prtf_pages_copied"), true);
1586  $ilCtrl->redirect($this, "pages");
1587  }
1588 
1589  $form->setValuesByPost();
1590  $this->copyPageForm($form);
1591  }
1592 
1593  function initCopyPageForm()
1594  {
1595  global $lng, $ilCtrl, $ilUser;
1596 
1597  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1598  $form = new ilPropertyFormGUI();
1599  $form->setFormAction($ilCtrl->getFormAction($this));
1600  $form->setTitle($lng->txt("prtf_copy_page"));
1601 
1602  $tgt = new ilRadioGroupInputGUI($lng->txt("target"), "target");
1603  $tgt->setRequired(true);
1604  $form->addItem($tgt);
1605 
1606  $all = ilObjPortfolio::getPortfoliosOfUser($ilUser->getId());
1607  if(sizeof($all) > 1)
1608  {
1609  $old = new ilRadioOption($lng->txt("prtf_existing_portfolio"), "old");
1610  $tgt->addOption($old);
1611 
1612  $options = array();
1613  foreach($all as $item)
1614  {
1615  if($item["id"] != $this->portfolio->getId())
1616  {
1617  $options[$item["id"]] = $item["title"];
1618  }
1619  }
1620  $prtf = new ilSelectInputGUI($lng->txt("portfolio"), "prtf");
1621  $prtf->setRequired(true);
1622  $prtf->setOptions($options);
1623  $old->addSubItem($prtf);
1624  }
1625 
1626  $new = new ilRadioOption($lng->txt("prtf_new_portfolio"), "new");
1627  $tgt->addOption($new);
1628 
1629  // 1st page
1630  $tf = new ilTextInputGUI($lng->txt("title"), "title");
1631  $tf->setMaxLength(128);
1632  $tf->setSize(40);
1633  $tf->setRequired(true);
1634  $new->addSubItem($tf);
1635 
1636  $form->addCommandButton("copyPage", $lng->txt("save"));
1637  $form->addCommandButton("pages", $lng->txt("cancel"));
1638 
1639  return $form;
1640  }
1641 
1642  protected function showOther()
1643  {
1644  global $tpl, $lng, $ilCtrl, $ilToolbar, $ilTabs;
1645 
1646  $ilTabs->activateTab("otpf");
1647 
1648  include_once('./Services/Portfolio/classes/class.ilPortfolioAccessHandler.php');
1649  $handler = new ilPortfolioAccessHandler();
1650  $users = $handler->getSharedOwners();
1651 
1652  // user selection
1653  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1654  $si = new ilSelectInputGUI($lng->txt("user"), "user");
1655  $si->setOptions(array(""=>"-")+$users);
1656  $ilToolbar->addInputItem($si);
1657 
1658  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1659  $ilToolbar->addFormButton($lng->txt("ok"), "showOther");
1660 
1661  if(!$_REQUEST["user"])
1662  {
1663  ilUtil::sendInfo($lng->txt("wsp_share_select_user"));
1664  }
1665  else
1666  {
1667  $si->setValue($_REQUEST["user"]);
1668 
1669  include_once "Services/Portfolio/classes/class.ilPortfolioTableGUI.php";
1670  $table = new ilPortfolioTableGUI($this, "showOther", $_REQUEST["user"], true);
1671  $tpl->setContent($table->getHTML());
1672  }
1673  }
1674 
1680  function setAdditional($a_additional)
1681  {
1682  $this->additional = $a_additional;
1683  }
1684 
1690  function getAdditional()
1691  {
1692  return $this->additional;
1693  }
1694 
1695  function setPermaLink($a_link)
1696  {
1697  $this->perma_link = $a_link;
1698  }
1699 
1700  function _goto($a_target)
1701  {
1702  $id = explode("_", $a_target);
1703 
1704  $_GET["baseClass"] = "ilsharedresourceGUI";
1705  $_GET["prt_id"] = $id[0];
1706 
1707  include("ilias.php");
1708  exit;
1709  }
1710 }
1711 
1712 ?>