ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBookmarkAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Services/Bookmarks/classes/class.ilBookmarkFolder.php");
6 require_once("./Services/Bookmarks/classes/class.ilBookmark.php");
7 require_once("./Services/Table/classes/class.ilTableGUI.php");
8 
20 {
24  protected $ctrl;
25 
29  protected $user;
30 
34  protected $toolbar;
35 
39  protected $error;
40 
44  protected $tabs;
45 
51  public $user_id;
52 
58  public $tpl;
59  public $lng;
60 
61  public $tree;
62  public $id;
63  public $data;
64  public $textwidth = 100;
65 
71  public function __construct()
72  {
73  global $DIC;
74 
75  $this->user = $DIC->user();
76  $this->toolbar = $DIC->toolbar();
77  $this->error = $DIC["ilErr"];
78  $this->tabs = $DIC->tabs();
79  $tpl = $DIC["tpl"];
80  $lng = $DIC->language();
81  $ilCtrl = $DIC->ctrl();
82  $ilUser = $DIC->user();
83 
84  // $tpl->enableAdvancedColumnLayout(true, false);
85 
86  $tpl->getStandardTemplate();
87 
88  //print_r($_SESSION["error_post_vars"]);
89  // if no bookmark folder id is given, take dummy root node id (that is 1)
90  $this->id = (empty($_GET["bmf_id"]))
91  ? 1
92  : $_GET["bmf_id"];
93 
94  // initiate variables
95  $this->tpl = $tpl;
96  $this->lng = $lng;
97  $this->ctrl = $ilCtrl;
98  $this->ctrl->setParameter($this, "bmf_id", $this->id);
99  $this->user_id = $ilUser->getId();
100 
101  $this->tree = new ilTree($this->user_id);
102  $this->tree->setTableNames('bookmark_tree', 'bookmark_data');
103  $this->root_id = $this->tree->readRootId();
104 
105  $this->lng->loadLanguageModule("bkm");
106 
107  $this->mode = "tree";
108  }
109 
113  public function executeCommand()
114  {
115  $next_class = $this->ctrl->getNextClass();
116 
117  switch ($next_class) {
118  default:
119  $cmd = $this->ctrl->getCmd("view");
120  $this->displayHeader();
121  $this->$cmd();
122  if ($this->getMode() == 'tree') {
123  $this->explorer();
124  }
125  break;
126  }
127  $this->tpl->show(true);
128  return true;
129  }
130 
131  public function executeAction()
132  {
133  switch ($_POST["selected_cmd"]) {
134  case "delete":
135  $this->delete();
136  break;
137  case "export":
138  $this->export();
139  break;
140  case "sendmail":
141  $this->sendmail();
142  break;
143  default:
144  $this->view();
145  break;
146  }
147  return true;
148  }
149 
154  public function getMode()
155  {
156  return $this->mode;
157  }
158 
162  public function explorer()
163  {
164  $tpl = $this->tpl;
165 
166  include_once("./Services/Bookmarks/classes/class.ilBookmarkExplorerGUI.php");
167  $exp = new ilBookmarkExplorerGUI($this, "explorer");
168  if (!$exp->handleCommand()) {
169  $tpl->setLeftNavContent($exp->getHTML());
170  }
171  }
172 
173 
177  public function displayHeader()
178  {
179  // output locator
180  $this->displayLocator();
181 
182  // output message
183  if ($this->message) {
184  ilUtil::sendInfo($this->message);
185  }
187 
188  $this->tpl->setTitle($this->lng->txt("bookmarks"));
189  }
190 
191  /*
192  * display content of bookmark folder
193  */
194  public function view()
195  {
196  $ilToolbar = $this->toolbar;
197 
198  if ($this->id > 0 && !$this->tree->isInTree($this->id)) {
199  $this->ctrl->setParameter($this, 'bmf_id', '');
200  $this->ctrl->redirect($this);
201  }
202 
203  $ilToolbar->addButton(
204  $this->lng->txt("bookmark_new"),
205  $this->ctrl->getLinkTarget($this, "newFormBookmark")
206  );
207  $ilToolbar->addButton(
208  $this->lng->txt("bookmark_folder_new"),
209  $this->ctrl->getLinkTarget($this, "newFormBookmarkFolder")
210  );
211 
212  $objects = ilBookmarkFolder::getObjects($this->id);
213 
214  include_once 'Services/Bookmarks/classes/class.ilBookmarkAdministrationTableGUI.php';
216  $table->setId('bookmark_adm_table');
217  $table->setData($objects);
218  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
219  }
220 
224  public function add_cell($val, $link = "")
225  {
226  if (!empty($link)) {
227  $this->tpl->setCurrentBlock("begin_link");
228  $this->tpl->setVariable("LINK_TARGET", $link);
229  $this->tpl->parseCurrentBlock();
230  $this->tpl->touchBlock("end_link");
231  }
232 
233  $this->tpl->setCurrentBlock("text");
234  $this->tpl->setVariable("TEXT_CONTENT", $val);
235  $this->tpl->parseCurrentBlock();
236  $this->tpl->setCurrentBlock("table_cell");
237  $this->tpl->parseCurrentBlock();
238  }
239 
243  public function displayLocator()
244  {
245  $lng = $this->lng;
246 
247  if (empty($this->id)) {
248  return;
249  }
250 
251  if (!$this->tree->isInTree($this->id)) {
252  return;
253  }
254 
255  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
256 
257  $path = $this->tree->getPathFull($this->id);
258  //print_r($path);
259  $modifier = 1;
260 
261  return;
262  $this->tpl->setVariable("TXT_LOCATOR", $this->lng->txt("locator"));
263  $this->tpl->touchBlock("locator_separator");
264  $this->tpl->touchBlock("locator_item");
265  //$this->tpl->setCurrentBlock("locator_item");
266  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
267  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
268  //$this->tpl->setVariable("LINK_TARGET","target=\"".
269  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
270  //$this->tpl->parseCurrentBlock();
271 
272  foreach ($path as $key => $row) {
273  if ($key < count($path) - $modifier) {
274  $this->tpl->touchBlock("locator_separator");
275  }
276 
277  $this->tpl->setCurrentBlock("locator_item");
278  $title = ($row["child"] == 1) ?
279  $lng->txt("bookmarks") :
280  $row["title"];
281  $this->tpl->setVariable("ITEM", $title);
282  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
283  $this->tpl->setVariable(
284  "LINK_ITEM",
285  $this->ctrl->getLinkTarget($this)
286  );
287  $this->tpl->parseCurrentBlock();
288  }
289 
290  $this->tpl->setCurrentBlock("locator");
291 
292  $this->tpl->parseCurrentBlock();
293  }
294 
298  public function newForm($type)
299  {
300  if (!$type) {
301  $type = $_POST["type"];
302  }
303  switch ($type) {
304  case "bmf":
305  $this->newFormBookmarkFolder();
306  break;
307 
308  case "bm":
309  $this->newFormBookmark();
310  break;
311  }
312  }
313 
317  public function newFormBookmarkFolder()
318  {
319  if (!$this->tree->isInTree($this->id)) {
320  $this->ctrl->setParameter($this, 'bmf_id', '');
321  $this->ctrl->redirect($this);
322  }
323 
324  $form = $this->initFormBookmarkFolder();
325  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
326  }
327 
332  private function initFormBookmarkFolder($action = 'createBookmarkFolder')
333  {
334  $lng = $this->lng;
337 
338  if (!$this->tree->isInTree($this->id)) {
339  $this->ctrl->setParameter($this, 'bmf_id', '');
340  $this->ctrl->redirect($this);
341  }
342 
343  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
344  $form = new ilPropertyFormGUI();
345  $form->setTopAnchor("bookmark_top");
346 
347  $form->setTitle($lng->txt("bookmark_folder_new"));
348 
349  if ($action == 'updateBookmarkFolder') {
350  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
351  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
352  }
353 
354  $hash = ($ilUser->prefs["screen_reader_optimization"])
355  ? "bookmark_top"
356  : "";
357 
358  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
359 
360  $ilCtrl->clearParameters($this);
361 
362  // title
363  $prop = new ilTextInputGUI($lng->txt("title"), "title");
364  $prop->setRequired(true);
365  $form->addItem($prop);
366 
367  // buttons
368  $form->addCommandButton($action, $lng->txt('save'));
369  $form->addCommandButton('cancel', $lng->txt('cancel'));
370  return $form;
371  }
372 
376  public function editFormBookmarkFolder()
377  {
378  if (!$this->tree->isInTree($_GET["obj_id"])) {
379  $this->ctrl->setParameter($this, 'bmf_id', '');
380  $this->ctrl->setParameter($this, 'obj_id', '');
381  $this->ctrl->redirect($this);
382  }
383 
384  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
385  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
386  $form->setValuesByArray(
387  array(
388  "title" => $this->get_last("title", $bmf->getTitle()),
389  "obj_id" => $_GET["obj_id"],
390  )
391  );
392  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
393  }
394 
395 
400  private function initFormBookmark($action = 'createBookmark')
401  {
402  $lng = $this->lng;
405 
406  if (!$this->tree->isInTree($this->id)) {
407  $this->ctrl->setParameter($this, 'bmf_id', '');
408  $this->ctrl->redirect($this);
409  }
410 
411  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
412  $form = new ilPropertyFormGUI();
413  $form->setTopAnchor("bookmark_top");
414 
415  $form->setTitle($lng->txt("bookmark_new"));
416 
417  if ($action == 'updateBookmark') {
418  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
419  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
420  }
421 
422  $hash = ($ilUser->prefs["screen_reader_optimization"])
423  ? "bookmark_top"
424  : "";
425 
426  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
427  $ilCtrl->clearParameters($this);
428  // title
429  $prop = new ilTextInputGUI($lng->txt("title"), "title");
430  $prop->setValue($_GET['bm_title']);
431  $prop->setRequired(true);
432  $form->addItem($prop);
433 
434  // description
435  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
436  $form->addItem($prop);
437 
438  // target link
439  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
440  $prop->setValue($_GET['bm_link']);
441  $prop->setRequired(true);
442  $form->addItem($prop);
443 
444  // hidden redirect field
445  if ($_GET['return_to']) {
446  $prop = new ilHiddenInputGUI('return_to');
447  $prop->setValue($_GET['return_to']);
448  $form->addItem($prop);
449 
450  $prop = new ilHiddenInputGUI('return_to_url');
451  if ($_GET['return_to_url']) {
452  $prop->setValue($_GET['return_to_url']);
453  } else {
454  $prop->setValue($_GET['bm_link']);
455  }
456  $form->addItem($prop);
457  }
458 
459  // buttons
460  $form->addCommandButton($action, $lng->txt('save'));
461  $form->addCommandButton('cancel', $lng->txt('cancel'));
462 
463  // keep imports?
464  /*
465  $this->tpl->setCurrentBlock('bkm_import');
466  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
467  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
468  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
469  $this->tpl->parseCurrentBlock();
470  //vd($_POST);
471  */
472 
473  return $form;
474  }
475 
480  private function initImportBookmarksForm()
481  {
482  $lng = $this->lng;
485 
486  if (!$this->tree->isInTree($this->id)) {
487  $this->ctrl->setParameter($this, 'bmf_id', '');
488  $this->ctrl->redirect($this);
489  }
490 
491  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
492  $form = new ilPropertyFormGUI();
493  $form->setFormAction($ilCtrl->getFormAction($this, "importFile")); // #16133
494  $form->setTopAnchor("bookmark_top");
495  $form->setTitle($lng->txt("bkm_import"));
496 
497  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
498  $fi->setRequired(true);
499  $form->addItem($fi);
500 
501  $form->addCommandButton("importFile", $lng->txt('import'));
502  $form->addCommandButton('cancel', $lng->txt('cancel'));
503 
504  return $form;
505  }
506 
510  public function newFormBookmark()
511  {
512  $form = $this->initFormBookmark();
513  $html1 = $form->getHTML();
514  $html2 = '';
515  if (!$_REQUEST["bm_link"]) {
516  $form2 = $this->initImportBookmarksForm();
517  $html2 = "<br />" . $form2->getHTML();
518  }
519  $this->tpl->setVariable("ADM_CONTENT", $html1 . $html2);
520  }
521 
522 
526  public function get_last($a_var, $a_value)
527  {
528  return (!empty($_POST[$a_var])) ?
529  ilUtil::prepareFormOutput(($_POST[$a_var]), true) :
530  ilUtil::prepareFormOutput($a_value);
531  }
532 
536  public function editFormBookmark()
537  {
538  $lng = $this->lng;
540 
541  if (!$this->tree->isInTree($_GET["obj_id"])) {
542  $this->ctrl->setParameter($this, 'obj_id', '');
543  $this->ctrl->setParameter($this, 'bmf_id', '');
544  $this->ctrl->redirect($this);
545  }
546 
547  $form = $this->initFormBookmark('updateBookmark');
548  $bookmark = new ilBookmark($_GET["obj_id"]);
549  $form->setValuesByArray(
550  array(
551  "title" => $bookmark->getTitle(),
552  "target" => $bookmark->getTarget(),
553  "description" => $bookmark->getDescription(),
554  "obj_id" => $_GET["obj_id"],
555  )
556  );
557  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
558  }
559 
560 
564  public function createBookmarkFolder()
565  {
566  if (!$this->tree->isInTree($this->id)) {
567  $this->ctrl->setParameter($this, 'bmf_id', '');
568  $this->ctrl->redirect($this);
569  }
570 
571  // check title
572  if (empty($_POST["title"])) {
573  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
574  $this->newFormBookmarkFolder();
575  } else {
576  // create bookmark folder
577  $bmf = new ilBookmarkFolder();
578  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
579  $bmf->setParent($this->id);
580  $bmf->create();
581 
582  ilUtil::sendSuccess($this->lng->txt("bkm_fold_created"), true);
583 
585  $ilCtrl->saveParameter($this, 'bmf_id');
586  $ilCtrl->redirect($this, 'view');
587  }
588  }
589 
590 
594  public function updateBookmarkFolder()
595  {
596  if (!$this->tree->isInTree($_GET["obj_id"])) {
597  $this->ctrl->setParameter($this, 'obj_id', '');
598  $this->ctrl->setParameter($this, 'bmf_id', '');
599  $this->ctrl->redirect($this);
600  }
601 
602  // check title
603  if (empty($_POST["title"])) {
604  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
605  $this->editFormBookmarkFolder();
606  } else {
607  // update bookmark folder
608  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
609  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
610  $bmf->update();
611 
613  $ilCtrl->saveParameter($this, 'bmf_id');
614  $ilCtrl->redirect($this, 'view');
615  }
616  }
617 
618 
622  public function createBookmark()
623  {
624  $lng = $this->lng;
626 
627  if (!$this->tree->isInTree($this->id)) {
628  $this->ctrl->setParameter($this, 'bmf_id', '');
629  $this->ctrl->redirect($this);
630  }
631 
632  // check title and target
633  if (empty($_POST["title"])) {
634  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
635  $this->newFormBookmark();
636  } elseif (empty($_POST["target"])) {
637  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
638  $this->newFormBookmark();
639  } else {
640  // create bookmark
641  $bm = new ilBookmark();
642  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
643  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
644  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
645  $bm->setParent($this->id);
646  $bm->create();
647 
648  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
649 
650  $ilCtrl->saveParameter($this, 'bmf_id');
651  $ilCtrl->redirect($this, 'view');
652  }
653  }
654 
658  public function updateBookmark()
659  {
660  if (!$this->tree->isInTree($_GET["obj_id"])) {
661  $this->ctrl->setParameter($this, 'obj_id', '');
662  $this->ctrl->setParameter($this, 'bmf_id', '');
663  $this->ctrl->redirect($this);
664  }
665 
666  // check title and target
667  if (empty($_POST["title"])) {
668  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
669  $this->editFormBookmark();
670  } elseif (empty($_POST["target"])) {
671  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
672  $this->editFormBookmark();
673  } else {
674  // update bookmark
675  $bm = new ilBookmark($_GET["obj_id"]);
676  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
677  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
678  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
679  $bm->update();
680 
681  $this->view();
682  }
683  }
684 
688  public function export($deliver = true)
689  {
692 
693  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
694  if (!$bm_ids) {
695  $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
696  }
697  $export_ids = array();
698  foreach ($bm_ids as $id) {
699  if ($this->tree->isInTree($id)) {
700  //list($type, $obj_id) = explode(":", $id);
701  //$export_ids[]=$obj_id;
702  $export_ids[] = $id;
703  }
704  }
705 
706  require_once("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
708  $export_ids,
709  true,
710  $this->lng->txt("bookmarks_of") . " " . $ilUser->getFullname()
711  );
712 
713  if ($deliver) {
714  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
715  } else {
716  return $html_content;
717  }
718  }
719 
723  public function sendmail()
724  {
726  include_once './Services/Mail/classes/class.ilFileDataMail.php';
727  require_once "Services/Mail/classes/class.ilFormatMail.php";
728  $mfile = new ilFileDataMail($ilUser->getId());
729  $umail = new ilFormatMail($ilUser->getId());
730 
731  $html_content = $this->export(false);
732  $tempfile = ilUtil::ilTempnam();
733  $fp = fopen($tempfile, 'w');
734  fwrite($fp, $html_content);
735  fclose($fp);
736  $filename = 'bookmarks.html';
737  $mfile->copyAttachmentFile($tempfile, $filename);
738  $umail->savePostData(
739  $ilUser->getId(),
740  array($filename),
741  '',
742  '',
743  '',
744  '',
745  '',
746  '',
747  '',
748  0
749  );
750 
751  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
752  ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, '', array(), array('type' => 'attach')));
753  }
754 
758  public function delete()
759  {
761 
762  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
763  if (!$bm_ids) {
764  $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
765  }
766 
767  $this->ctrl->setParameter($this, "bmf_id", $this->id);
768 
769  // display confirmation message
770  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
771  $cgui = new ilConfirmationGUI();
772  $cgui->setFormAction($this->ctrl->getFormAction($this));
773  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
774  $cgui->setCancel($this->lng->txt("cancel"), "cancel");
775  $cgui->setConfirm($this->lng->txt("confirm"), "confirm");
776 
777  foreach ($bm_ids as $obj_id) {
778  $type = ilBookmark::_getTypeOfId($obj_id);
779 
780  if (!$this->tree->isInTree($obj_id)) {
781  continue;
782  }
783 
784  switch ($type) {
785  case "bmf":
786  $BookmarkFolder = new ilBookmarkFolder($obj_id);
787  $title = $BookmarkFolder->getTitle();
788  $target = "";
789  unset($BookmarkFolder);
790  break;
791 
792  case "bm":
793  $Bookmark = new ilBookmark($obj_id);
794  $title = $Bookmark->getTitle();
795  $target = $Bookmark->getTarget();
796  unset($Bookmark);
797  break;
798  }
799 
800  $caption = ilUtil::getImageTagByType($type, $this->tpl->tplPath) .
801  " " . $title;
802  if ($target) {
803  $caption .= " (" . ilUtil::shortenText($target, $this->textwidth, true) . ")";
804  }
805 
806  $cgui->addItem("id[]", $obj_id, $caption);
807  }
808 
809  $this->tpl->setContent($cgui->getHTML());
810  }
811 
815  public function cancel()
816  {
817  $this->view();
818  }
819 
823  public function confirm()
824  {
826 
827  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
828  if (!$_POST["id"]) {
829  $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
830  }
831 
832  // FOR ALL SELECTED OBJECTS
833  foreach ($_POST["id"] as $id) {
835 
836  // get node data and subtree nodes
837  if ($this->tree->isInTree($id)) {
838  $node_data = $this->tree->getNodeData($id);
839  $subtree_nodes = $this->tree->getSubTree($node_data);
840  } else {
841  continue;
842  }
843 
844  // delete tree
845  $this->tree->deleteTree($node_data);
846 
847  // delete objects of subtree nodes
848  foreach ($subtree_nodes as $node) {
849  switch ($node["type"]) {
850  case "bmf":
851  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
852  $BookmarkFolder->delete();
853  break;
854 
855  case "bm":
856  $Bookmark = new ilBookmark($node["obj_id"]);
857  $Bookmark->delete();
858  break;
859  }
860  }
861  }
862 
863  // Feedback
864  ilUtil::sendSuccess($this->lng->txt("info_deleted"), true);
865 
866  $this->view();
867  }
868 
869 
873  public function showPossibleSubObjects()
874  {
875  $actions = array(
876  "delete" => $this->lng->txt("delete"),
877  "export" => $this->lng->txt("export"),
878  "sendmail" => $this->lng->txt("bkm_sendmail"),
879  );
880 
881  $subobj = array("bm", "bmf");
882 
883  if (is_array($subobj)) {
884  //build form
885  $opts = ilUtil::formSelect("", "type", $subobj);
886 
887  $this->tpl->setCurrentBlock("add_object");
888  $this->tpl->setVariable("COLUMN_COUNTS", 7);
889  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
890  $this->tpl->setVariable("BTN_NAME", "newForm");
891  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
892  $this->tpl->parseCurrentBlock();
893  }
894 
895  $this->tpl->setVariable("TPLPATH", $this->tpl->tplPath);
896 
897  $this->tpl->setCurrentBlock("tbl_action_select");
898  $this->tpl->setVariable("SELECT_ACTION", ilUtil::formSelect($_SESSION["error_post_vars"]['action'], "action", $actions, false, true));
899  $this->tpl->setVariable("BTN_NAME", "executeAction");
900  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("execute"));
901 
902  /*
903  $this->tpl->setVariable("BTN_NAME","delete");
904  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
905  $this->tpl->parseCurrentBlock();
906 
907  $this->tpl->setVariable("BTN_NAME","export");
908  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
909  $this->tpl->parseCurrentBlock();
910  */
911  $this->tpl->parseCurrentBlock();
912  }
913 
917  public function getHTML()
918  {
919  include_once("./Services/Bookmarks/classes/class.ilBookmarkBlockGUI.php");
920  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
921 
922  return $bookmark_block_gui->getHTML();
923  }
924 
931  public function importFile()
932  {
933  if (!$this->tree->isInTree($this->id)) {
934  $this->ctrl->setParameter($this, 'bmf_id', '');
935  $this->ctrl->redirect($this);
936  }
937 
938  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK) {
939  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
940  $this->newFormBookmark();
941  return;
942  }
943  require_once("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
944  $objects = ilBookmarkImportExport::_parseFile($_FILES["bkmfile"]['tmp_name']);
945  if ($objects === false) {
946  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
947  $this->newFormBookmark();
948  return;
949  }
950  // holds the number of created objects
951  $num_create = array('bm' => 0, 'bmf' => 0);
952  $this->__importBookmarks($objects, $num_create, $this->id, 0);
953 
954  ilUtil::sendSuccess(sprintf(
955  $this->lng->txt("bkm_import_ok"),
956  $num_create['bm'],
957  $num_create['bmf']
958  ));
959  $this->view();
960  }
961 
970  public function __importBookmarks(&$objects, &$num_create, $folder_id, $start_key = 0)
971  {
972  if (is_array($objects[$start_key])) {
973  foreach ($objects[$start_key] as $obj_key => $object) {
974  switch ($object['type']) {
975  case 'bm':
976  if (!$object["title"]) {
977  continue 2;
978  }
979  if (!$object["target"]) {
980  continue 2;
981  }
982  $bm = new ilBookmark();
983  $bm->setTitle($object["title"]);
984  $bm->setDescription($object["description"]);
985  $bm->setTarget($object["target"]);
986  $bm->setParent($folder_id);
987  $bm->create();
988  $num_create['bm']++;
989  break;
990  case 'bmf':
991  if (!$object["title"]) {
992  continue 2;
993  }
994  $bmf = new ilBookmarkFolder();
995  $bmf->setTitle($object["title"]);
996  $bmf->setParent($folder_id);
997  $bmf->create();
998  $num_create['bmf']++;
999  if (is_array($objects[$obj_key])) {
1000  $this->__importBookmarks(
1001  $objects,
1002  $num_create,
1003  $bmf->getId(),
1004  $obj_key
1005  );
1006  }
1007  break;
1008  }
1009  }
1010  }
1011  }
1012 
1013  public function move()
1014  {
1015  $ilUser = $this->user;
1016  $ilTabs = $this->tabs;
1017  $tpl = $this->tpl;
1018 
1019  $bm_ids = $_REQUEST['bm_id'];
1020  if (!$bm_ids && $_GET["bm_id_tgt"] == "") {
1021  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1022  return $this->view();
1023  }
1024 
1025  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this));
1026 
1027  $this->ctrl->setParameter($this, "bm_id_tgt", $_GET["bm_id_tgt"] ? $_GET["bm_id_tgt"] : implode(";", $bm_ids));
1028  ilUtil::sendInfo($this->lng->txt("bookmark_select_target"));
1029  include_once("./Services/Bookmarks/classes/class.ilBookmarkMoveExplorerGUI.php");
1030  $exp = new ilBookmarkMoveExplorerGUI($this, "move");
1031  if (!$exp->handleCommand()) {
1032  $this->mode = "flat";
1033  $this->tpl->setContent($exp->getHTML());
1034  }
1035  }
1036 
1037  public function confirmedMove()
1038  {
1039  $ilUser = $this->user;
1040 
1041  $tgt = (int) $_REQUEST["bmfmv_id"];
1042  $bm_ids = explode(";", $_REQUEST['bm_id_tgt']);
1043  if (!$bm_ids || !$tgt) {
1044  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1045  return $this->view();
1046  }
1047 
1048  $tree = new ilTree($ilUser->getId());
1049  $tree->setTableNames('bookmark_tree', 'bookmark_data');
1050 
1051  $tgt_node = $tree->getNodeData($tgt);
1052 
1053  // sanity check
1054  foreach ($bm_ids as $node_id) {
1055  if ($tree->isGrandChild($node_id, $tgt)) {
1056  ilUtil::sendFailure($this->lng->txt("error"), true);
1057  $this->ctrl->redirect($this, "view");
1058  }
1059 
1060  $node = $tree->getNodeData($node_id);
1061 
1062  // already at correct position
1063  if ($node["parent"] == $tgt) {
1064  continue;
1065  }
1066 
1067  $tree->moveTree($node_id, $tgt);
1068  }
1069 
1070  ilUtil::sendSuccess($this->lng->txt("bookmark_moved_ok"), true);
1071  $this->ctrl->setParameter($this, "bmf_id", $tgt);
1072  $this->ctrl->redirect($this, "view");
1073  }
1074 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
Class Bookmarks Bookmark management.
$path
Definition: aliased.php:25
initImportBookmarksForm()
Init import bookmark form.
getMode()
return display mode flat or tree
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$_SESSION["AccountId"]
createBookmarkFolder()
create new bookmark folder in db
This class represents a property form user interface.
BlockGUI class for Bookmarks block.
$action
$type
global $DIC
Definition: saml.php:7
editFormBookmarkFolder()
display edit bookmark folder form
$_GET["client_id"]
Class ilFileDataMail.
export($deliver=true)
export bookmarks
This class represents a file property in a property form.
static getImageTagByType($a_type, $a_path, $a_big=false)
Builds an html image tag TODO: function still in use, but in future use getImagePath and move HTML-Co...
showPossibleSubObjects()
display subobject addition selection
__importBookmarks(&$objects, &$num_create, $folder_id, $start_key=0)
creates the bookmarks and folders
editFormBookmark()
display edit bookmark form
$html1
user()
Definition: user.php:4
$ilErr
Definition: raiseError.php:18
Bookmark explorer GUI class.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
confirm()
deletion confirmed -> delete folders / bookmarks
Class UserMail this class handles user mails.
importFile()
imports a bookmark file into database display status information or report errors messages in case of...
if(isset($_POST['submit'])) $form
explorer()
output explorer tree with bookmark folders
This class represents a text property in a property form.
static infoPanel($a_keep=true)
$ilUser
Definition: imgupload.php:18
GUI class for personal bookmark administration.
add_cell($val, $link="")
output a cell in object list
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _getTypeOfId($a_id)
get type of a given id
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
initFormBookmark($action='createBookmark')
init Bookmark create/edit form
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$filename
Definition: buildRTE.php:89
$row
static _exportBookmark($obj_ids, $recursive=true, $title='')
export bookmarks static method return html string
initFormBookmarkFolder($action='createBookmarkFolder')
init bookmark folder create/edit form
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
bookmark folder (note: this class handles personal bookmarks folders only)
static getRedirectTarget($gui, $cmd, array $gui_params=array(), array $mail_params=array(), array $context_params=array())
This class represents a text area property in a property form.
newFormBookmarkFolder()
display new bookmark folder form
$html2
static getObjects($a_id)
static
if(empty($password)) $table
Definition: pwgen.php:24
getHTML()
Get Bookmark list for personal desktop.
setValue($a_value)
Set Value.
static redirect($a_script)
$target
Definition: test.php:19
cancel()
cancel deletion,insert, update
$key
Definition: croninfo.php:18
$_POST["username"]
setRequired($a_required)
Set Required.
static _parseFile($file)
parse Bookmark file static method returns 3 dimensional array of bookmarks and folders ...
get_last($a_var, $a_value)
get stored post var in case of an error/warning otherwise return passed value
Confirmation screen class.