ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.ilBookmarkExplorer.php");
6 require_once ("./Services/Bookmarks/classes/class.ilBookmarkFolder.php");
7 require_once ("./Services/Bookmarks/classes/class.ilBookmark.php");
8 require_once ("./Services/Table/classes/class.ilTableGUI.php");
9 
21 {
27  var $user_id;
28 
34  var $ilias;
35  var $tpl;
36  var $lng;
37 
38  var $tree;
39  var $id;
40  var $data;
41  var $textwidth = 100;
42 
49  {
50  global $ilias, $tpl, $lng, $ilCtrl, $ilUser;
51 
52 // $tpl->enableAdvancedColumnLayout(true, false);
53 
54  $tpl->getStandardTemplate();
55 
56  //print_r($_SESSION["error_post_vars"]);
57  // if no bookmark folder id is given, take dummy root node id (that is 1)
58  $this->id = (empty($_GET["bmf_id"]))
59  ? 1
60  : $_GET["bmf_id"];
61 
62  // initiate variables
63  $this->ilias =& $ilias;
64  $this->tpl =& $tpl;
65  $this->lng =& $lng;
66  $this->ctrl =& $ilCtrl;
67  $this->ctrl->setParameter($this, "bmf_id", $this->id);
68  $this->user_id = $ilUser->getId();
69 
70  $this->tree = new ilTree($this->user_id);
71  $this->tree->setTableNames('bookmark_tree', 'bookmark_data');
72  $this->root_id = $this->tree->readRootId();
73 
74  $this->mode = "tree";
75  }
76 
80  function &executeCommand()
81  {
82  $next_class = $this->ctrl->getNextClass();
83 
84  switch($next_class)
85  {
86  default:
87  $cmd = $this->ctrl->getCmd("view");
88  $this->displayHeader();
89  $this->$cmd();
90  if($this->getMode() == 'tree')
91  {
92  $this->explorer();
93  }
94  break;
95  }
96  $this->tpl->show(true);
97  return true;
98  }
99 
100  function executeAction()
101  {
102  switch($_POST["selected_cmd"])
103  {
104  case "delete":
105  $this->delete();
106  break;
107  case "export":
108  $this->export();
109  break;
110  case "sendmail":
111  $this->sendmail();
112  break;
113  default:
114  $this->view();
115  break;
116  }
117  return true;
118  }
119 
124  function getMode()
125  {
126  return $this->mode;
127  }
128 
132  function explorer()
133  {
134  global $tpl;
135 
136  $etpl = new ilTemplate("tpl.bookmark_explorer.html", true, true,
137  "Services/Bookmarks");
138  $exp = new ilBookmarkExplorer($this->ctrl->getLinkTarget($this), $this->user_id);
139  $exp->setAllowedTypes(array('dum', 'bmf'));
140  $exp->setTargetGet("bmf_id");
141  $exp->setSessionExpandVariable('mexpand');
142  $exp->setExpand($this->id);
143  $this->ctrl->setParameter($this, "bmf_id", $this->id);
144  $exp->setExpandTarget($this->ctrl->getLinkTarget($this));
145  if($_GET["mexpand"] == "")
146  {
147  $mtree = new ilTree($this->user_id);
148  $mtree->setTableNames('bookmark_tree', 'bookmark_data');
149  $expanded = $mtree->readRootId();
150  }
151  else
152  {
153  $expanded = $_GET["mexpand"];
154  }
155 
156  $exp->setExpand($expanded);
157  $exp->highlightNode($_GET["bmf_id"]);
158 
159  // build html-output
160  $exp->setOutput(0);
161  $exp->highlightNode($this->id);
162  $output = $exp->getOutput();
163 
164 // $etpl->setCurrentBlock("adm_tree_content");
165  $etpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("bookmarks"));
166  $this->ctrl->setParameter($this, "bmf_id", 1);
167 
168  if($_REQUEST['bm_link'])
169  {
170  $link = $_SERVER['REQUEST_URI'];
171  $link = ereg_replace('bmf_id=[0-9]*', 'bmf_id=1', $link);
172  $etpl->setVariable("LINK_EXPLORER_HEADER", $link);
173  }
174  else
175  $etpl->setVariable("LINK_EXPLORER_HEADER", $this->ctrl->getLinkTarget($this));
176 
177  $etpl->setVariable("EXPLORER", $output);
178  $tpl->setLeftNavContent($etpl->get());
179  ;
180  }
181 
182 
186  function displayHeader()
187  {
188  // output locator
189  $this->displayLocator();
190 
191  // output message
192  if($this->message)
193  {
194  ilUtil::sendInfo($this->message);
195  }
197 
198 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.png"),
199 // "");
200  $this->tpl->setTitle($this->lng->txt("bookmarks"));
201  }
202 
203  /*
204  * display content of bookmark folder
205  */
206  function view()
207  {
208  if($this->id > 0 && !$this->tree->isInTree($this->id))
209  {
210  $this->ctrl->setParameter($this, 'bmf_id', '');
211  $this->ctrl->redirect($this);
212  }
213 
214  $objects = ilBookmarkFolder::getObjects($this->id);
215 
216  include_once 'Services/Bookmarks/classes/class.ilBookmarkAdministrationTableGUI.php';
217  $table = new ilBookmarkAdministrationTableGUI($this);
218  $table->setId('bookmark_adm_table');
219  $table->setData($objects);
220  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
221  }
222 
226  function add_cell($val, $link = "")
227  {
228  if(!empty($link))
229  {
230  $this->tpl->setCurrentBlock("begin_link");
231  $this->tpl->setVariable("LINK_TARGET", $link);
232  $this->tpl->parseCurrentBlock();
233  $this->tpl->touchBlock("end_link");
234  }
235 
236  $this->tpl->setCurrentBlock("text");
237  $this->tpl->setVariable("TEXT_CONTENT", $val);
238  $this->tpl->parseCurrentBlock();
239  $this->tpl->setCurrentBlock("table_cell");
240  $this->tpl->parseCurrentBlock();
241  }
242 
246  function displayLocator()
247  {
248  global $lng;
249 
250  if(empty($this->id))
251  {
252  return;
253  }
254 
255  if(!$this->tree->isInTree($this->id))
256  {
257  return;
258  }
259 
260  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
261 
262  $path = $this->tree->getPathFull($this->id);
263 //print_r($path);
264  $modifier = 1;
265 
266  return;
267  $this->tpl->setVariable("TXT_LOCATOR", $this->lng->txt("locator"));
268  $this->tpl->touchBlock("locator_separator");
269  $this->tpl->touchBlock("locator_item");
270  //$this->tpl->setCurrentBlock("locator_item");
271  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
272  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
273  //$this->tpl->setVariable("LINK_TARGET","target=\"".
274  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
275  //$this->tpl->parseCurrentBlock();
276 
277  foreach($path as $key => $row)
278  {
279  if($key < count($path) - $modifier)
280  {
281  $this->tpl->touchBlock("locator_separator");
282  }
283 
284  $this->tpl->setCurrentBlock("locator_item");
285  $title = ($row["child"] == 1) ?
286  $lng->txt("bookmarks") :
287  $row["title"];
288  $this->tpl->setVariable("ITEM", $title);
289  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
290  $this->tpl->setVariable("LINK_ITEM",
291  $this->ctrl->getLinkTarget($this));
292  $this->tpl->parseCurrentBlock();
293  }
294 
295  $this->tpl->setCurrentBlock("locator");
296 
297  $this->tpl->parseCurrentBlock();
298  }
299 
303  function newForm($type)
304  {
305  if(!$type)
306  $type = $_POST["type"];
307  switch($type)
308  {
309  case "bmf":
310  $this->newFormBookmarkFolder();
311  break;
312 
313  case "bm":
314  $this->newFormBookmark();
315  break;
316  }
317  }
318 
323  {
324  if(!$this->tree->isInTree($this->id))
325  {
326  $this->ctrl->setParameter($this, 'bmf_id', '');
327  $this->ctrl->redirect($this);
328  }
329 
330  $form = $this->initFormBookmarkFolder();
331  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
332  }
333 
338  private function initFormBookmarkFolder($action = 'createBookmarkFolder')
339  {
340  global $lng, $ilCtrl, $ilUser;
341 
342  if(!$this->tree->isInTree($this->id))
343  {
344  $this->ctrl->setParameter($this, 'bmf_id', '');
345  $this->ctrl->redirect($this);
346  }
347 
348  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
349  $form = new ilPropertyFormGUI();
350  $form->setTopAnchor("bookmark_top");
351 
352  $form->setTitle($lng->txt("bookmark_folder_new"));
353 
354  if($action == 'updateBookmarkFolder')
355  {
356  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
357  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
358  }
359 
360  $hash = ($ilUser->prefs["screen_reader_optimization"])
361  ? "bookmark_top"
362  : "";
363 
364  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
365 
366  $ilCtrl->clearParameters($this);
367 
368  // title
369  $prop = new ilTextInputGUI($lng->txt("title"), "title");
370  $prop->setRequired(true);
371  $form->addItem($prop);
372 
373  // buttons
374  $form->addCommandButton($action, $lng->txt('save'));
375  $form->addCommandButton('cancel', $lng->txt('cancel'));
376  return $form;
377  }
378 
383  {
384  if(!$this->tree->isInTree($_GET["obj_id"]))
385  {
386  $this->ctrl->setParameter($this, 'bmf_id', '');
387  $this->ctrl->setParameter($this, 'obj_id', '');
388  $this->ctrl->redirect($this);
389  }
390 
391  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
392  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
393  $form->setValuesByArray
394  (
395  array
396  (
397  "title" => $this->get_last("title", $bmf->getTitle()),
398  "obj_id" => $_GET["obj_id"],
399  )
400  );
401  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
402  }
403 
404 
409  private function initFormBookmark($action = 'createBookmark')
410  {
411  global $lng, $ilCtrl, $ilUser;
412 
413  if(!$this->tree->isInTree($this->id))
414  {
415  $this->ctrl->setParameter($this, 'bmf_id', '');
416  $this->ctrl->redirect($this);
417  }
418 
419  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
420  $form = new ilPropertyFormGUI();
421  $form->setTopAnchor("bookmark_top");
422 
423  $form->setTitle($lng->txt("bookmark_new"));
424 
425  if($action == 'updateBookmark')
426  {
427  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
428  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
429  }
430 
431  $hash = ($ilUser->prefs["screen_reader_optimization"])
432  ? "bookmark_top"
433  : "";
434 
435  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
436  $ilCtrl->clearParameters($this);
437  // title
438  $prop = new ilTextInputGUI($lng->txt("title"), "title");
439  $prop->setValue($_GET['bm_title']);
440  $prop->setRequired(true);
441  $form->addItem($prop);
442 
443  // description
444  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
445  $form->addItem($prop);
446 
447  // target link
448  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
449  $prop->setValue($_GET['bm_link']);
450  $prop->setRequired(true);
451  $form->addItem($prop);
452 
453  // hidden redirect field
454  if($_GET['return_to'])
455  {
456  $prop = new ilHiddenInputGUI('return_to');
457  $prop->setValue($_GET['return_to']);
458  $form->addItem($prop);
459 
460  $prop = new ilHiddenInputGUI('return_to_url');
461  if($_GET['return_to_url'])
462  $prop->setValue($_GET['return_to_url']);
463  else
464  $prop->setValue($_GET['bm_link']);
465  $form->addItem($prop);
466  }
467 
468  // buttons
469  $form->addCommandButton($action, $lng->txt('save'));
470  $form->addCommandButton('cancel', $lng->txt('cancel'));
471 
472  // keep imports?
473  /*
474  $this->tpl->setCurrentBlock('bkm_import');
475  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
476  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
477  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
478  $this->tpl->parseCurrentBlock();
479  //vd($_POST);
480  */
481 
482  return $form;
483  }
484 
489  private function initImportBookmarksForm()
490  {
491  global $lng, $ilCtrl, $ilUser;
492 
493  if(!$this->tree->isInTree($this->id))
494  {
495  $this->ctrl->setParameter($this, 'bmf_id', '');
496  $this->ctrl->redirect($this);
497  }
498 
499  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
500  $form = new ilPropertyFormGUI();
501  $form->setFormAction($ilCtrl->getFormAction($this, "importFile")); // #16133
502  $form->setTopAnchor("bookmark_top");
503  $form->setTitle($lng->txt("bkm_import"));
504 
505  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
506  $fi->setRequired(true);
507  $form->addItem($fi);
508 
509  $form->addCommandButton("importFile", $lng->txt('import'));
510  $form->addCommandButton('cancel', $lng->txt('cancel'));
511 
512  return $form;
513  }
514 
518  function newFormBookmark()
519  {
520  $form = $this->initFormBookmark();
521  $html1 = $form->getHTML();
522  $html2 = '';
523  if(!$_REQUEST["bm_link"])
524  {
525  $form2 = $this->initImportBookmarksForm();
526  $html2 = "<br />" . $form2->getHTML();
527  }
528  $this->tpl->setVariable("ADM_CONTENT", $html1 . $html2);
529  }
530 
531 
535  function get_last($a_var, $a_value)
536  {
537  return (!empty($_POST[$a_var])) ?
538  ilUtil::prepareFormOutput(($_POST[$a_var]), true) :
539  ilUtil::prepareFormOutput($a_value);
540  }
541 
545  function editFormBookmark()
546  {
547  global $lng, $ilCtrl;
548 
549  if(!$this->tree->isInTree($_GET["obj_id"]))
550  {
551  $this->ctrl->setParameter($this, 'obj_id', '');
552  $this->ctrl->setParameter($this, 'bmf_id', '');
553  $this->ctrl->redirect($this);
554  }
555 
556  $form = $this->initFormBookmark('updateBookmark');
557  $bookmark = new ilBookmark($_GET["obj_id"]);
558  $form->setValuesByArray
559  (
560  array
561  (
562  "title" => $bookmark->getTitle(),
563  "target" => $bookmark->getTarget(),
564  "description" => $bookmark->getDescription(),
565  "obj_id" => $_GET["obj_id"],
566  )
567  );
568  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
569  }
570 
571 
576  {
577  if(!$this->tree->isInTree($this->id))
578  {
579  $this->ctrl->setParameter($this, 'bmf_id', '');
580  $this->ctrl->redirect($this);
581  }
582 
583  // check title
584  if(empty($_POST["title"]))
585  {
586  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
587  $this->newFormBookmarkFolder();
588  }
589  else
590  {
591  // create bookmark folder
592  $bmf = new ilBookmarkFolder();
593  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
594  $bmf->setParent($this->id);
595  $bmf->create();
596 
597  global $ilCtrl;
598  $ilCtrl->saveParameter($this, 'bmf_id');
599  $ilCtrl->redirect($this, 'view');
600  }
601  }
602 
603 
608  {
609  if(!$this->tree->isInTree($_GET["obj_id"]))
610  {
611  $this->ctrl->setParameter($this, 'obj_id', '');
612  $this->ctrl->setParameter($this, 'bmf_id', '');
613  $this->ctrl->redirect($this);
614  }
615 
616  // check title
617  if(empty($_POST["title"]))
618  {
619  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
620  $this->editFormBookmarkFolder();
621  }
622  else
623  {
624  // update bookmark folder
625  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
626  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
627  $bmf->update();
628 
629  global $ilCtrl;
630  $ilCtrl->saveParameter($this, 'bmf_id');
631  $ilCtrl->redirect($this, 'view');
632  }
633  }
634 
635 
639  function createBookmark()
640  {
641  global $lng, $ilCtrl;
642 
643  if(!$this->tree->isInTree($this->id))
644  {
645  $this->ctrl->setParameter($this, 'bmf_id', '');
646  $this->ctrl->redirect($this);
647  }
648 
649  // check title and target
650  if(empty($_POST["title"]))
651  {
652  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
653  $this->newFormBookmark();
654  }
655  else if(empty($_POST["target"]))
656  {
657  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
658  $this->newFormBookmark();
659  }
660  else
661  {
662  // create bookmark
663  $bm = new ilBookmark();
664  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
665  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
666  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
667  $bm->setParent($this->id);
668  $bm->create();
669 
670  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
671 
672  if($_POST['return_to'])
673  ilUtil::redirect($_POST['return_to_url']);
674  else
675  {
676  $ilCtrl->saveParameter($this, 'bmf_id');
677  $ilCtrl->redirect($this, 'view');
678  }
679  }
680  }
681 
685  function updateBookmark()
686  {
687  if(!$this->tree->isInTree($_GET["obj_id"]))
688  {
689  $this->ctrl->setParameter($this, 'obj_id', '');
690  $this->ctrl->setParameter($this, 'bmf_id', '');
691  $this->ctrl->redirect($this);
692  }
693 
694  // check title and target
695  if(empty($_POST["title"]))
696  {
697  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
698  $this->editFormBookmark();
699  }
700  else if(empty($_POST["target"]))
701  {
702  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
703  $this->editFormBookmark();
704  }
705  else
706  {
707  // update bookmark
708  $bm = new ilBookmark($_GET["obj_id"]);
709  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
710  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
711  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
712  $bm->update();
713 
714  $this->view();
715  }
716  }
717 
721  function export($deliver = true)
722  {
723  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
724  if(!$bm_ids)
725  {
726  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
727  }
728  $export_ids = array();
729  foreach($bm_ids as $id)
730  {
731  if($this->tree->isInTree($id))
732  {
733  //list($type, $obj_id) = explode(":", $id);
734  //$export_ids[]=$obj_id;
735  $export_ids[] = $id;
736  }
737  }
738 
739  require_once ("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
740  $html_content = ilBookmarkImportExport::_exportBookmark($export_ids, true,
741  $this->lng->txt("bookmarks_of") . " " . $this->ilias->account->getFullname());
742 
743  if($deliver)
744  {
745  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
746  }
747  else
748  {
749  return $html_content;
750  }
751  }
752 
756  function sendmail()
757  {
758  global $ilUser;
759  include_once './Services/Mail/classes/class.ilFileDataMail.php';
760  require_once "Services/Mail/classes/class.ilFormatMail.php";
761  $mfile = new ilFileDataMail($ilUser->getId());
762  $umail = new ilFormatMail($ilUser->getId());
763 
764  $html_content = $this->export(false);
765  $tempfile = ilUtil::ilTempnam();
766  $fp = fopen($tempfile, 'w');
767  fwrite($fp, $html_content);
768  fclose($fp);
769  $filename = 'bookmarks.html';
770  $mfile->copyAttachmentFile($tempfile, $filename);
771  $umail->savePostData($ilUser->getId(), array($filename),
772  '', '', '', '', '',
773  '',
774  '', 0);
775 
776  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
777  ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, '', array(), array('type' => 'attach')));
778  }
779 
783  function delete()
784  {
785  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
786  if(!$bm_ids)
787  {
788  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
789  }
790 
791  $this->ctrl->setParameter($this, "bmf_id", $this->id);
792 
793  // display confirmation message
794  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
795  $cgui = new ilConfirmationGUI();
796  $cgui->setFormAction($this->ctrl->getFormAction($this));
797  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
798  $cgui->setCancel($this->lng->txt("cancel"), "cancel");
799  $cgui->setConfirm($this->lng->txt("confirm"), "confirm");
800 
801  foreach($bm_ids as $obj_id)
802  {
803  $type = ilBookmark::_getTypeOfId($obj_id);
804 
805  if(!$this->tree->isInTree($obj_id))
806  {
807  continue;
808  }
809 
810  switch($type)
811  {
812  case "bmf":
813  $BookmarkFolder = new ilBookmarkFolder($obj_id);
814  $title = $BookmarkFolder->getTitle();
815  $target = "";
816  unset($BookmarkFolder);
817  break;
818 
819  case "bm":
820  $Bookmark = new ilBookmark($obj_id);
821  $title = $Bookmark->getTitle();
822  $target = $Bookmark->getTarget();
823  unset($Bookmark);
824  break;
825  }
826 
827  $caption = ilUtil::getImageTagByType($type, $this->tpl->tplPath) .
828  " " . $title;
829  if($target)
830  {
831  $caption .= " (" . ilUtil::shortenText($target, $this->textwidth, true) . ")";
832  }
833 
834  $cgui->addItem("id[]", $obj_id, $caption);
835  }
836 
837  $this->tpl->setContent($cgui->getHTML());
838  }
839 
843  function cancel()
844  {
845  if($_POST['return_to'])
846  ilUtil::redirect($_POST['return_to_url']);
847  else
848  $this->view();
849  }
850 
854  function confirm()
855  {
856  global $tree, $rbacsystem, $rbacadmin;
857  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
858  if(!$_POST["id"])
859  {
860  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
861  }
862 
863  // FOR ALL SELECTED OBJECTS
864  foreach($_POST["id"] as $id)
865  {
866  $type = ilBookmark::_getTypeOfId($id);
867 
868  // get node data and subtree nodes
869  if($this->tree->isInTree($id))
870  {
871  $node_data = $this->tree->getNodeData($id);
872  $subtree_nodes = $this->tree->getSubTree($node_data);
873  }
874  else
875  {
876  continue;
877  }
878 
879  // delete tree
880  $this->tree->deleteTree($node_data);
881 
882  // delete objects of subtree nodes
883  foreach($subtree_nodes as $node)
884  {
885  switch($node["type"])
886  {
887  case "bmf":
888  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
889  $BookmarkFolder->delete();
890  break;
891 
892  case "bm":
893  $Bookmark = new ilBookmark($node["obj_id"]);
894  $Bookmark->delete();
895  break;
896  }
897  }
898  }
899 
900  // Feedback
901  ilUtil::sendSuccess($this->lng->txt("info_deleted"), true);
902 
903  $this->view();
904  }
905 
906 
911  {
912  $actions = array(
913  "delete" => $this->lng->txt("delete"),
914  "export" => $this->lng->txt("export"),
915  "sendmail"=> $this->lng->txt("bkm_sendmail"),
916  );
917 
918  $subobj = array("bm", "bmf");
919 
920  if(is_array($subobj))
921  {
922  //build form
923  $opts = ilUtil::formSelect("", "type", $subobj);
924 
925  $this->tpl->setCurrentBlock("add_object");
926  $this->tpl->setVariable("COLUMN_COUNTS", 7);
927  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
928  $this->tpl->setVariable("BTN_NAME", "newForm");
929  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
930  $this->tpl->parseCurrentBlock();
931  }
932 
933  $this->tpl->setVariable("TPLPATH", $this->tpl->tplPath);
934 
935  $this->tpl->setCurrentBlock("tbl_action_select");
936  $this->tpl->setVariable("SELECT_ACTION", ilUtil::formSelect($_SESSION["error_post_vars"]['action'], "action", $actions, false, true));
937  $this->tpl->setVariable("BTN_NAME", "executeAction");
938  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("execute"));
939 
940  /*
941  $this->tpl->setVariable("BTN_NAME","delete");
942  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
943  $this->tpl->parseCurrentBlock();
944 
945  $this->tpl->setVariable("BTN_NAME","export");
946  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
947  $this->tpl->parseCurrentBlock();
948  */
949  $this->tpl->parseCurrentBlock();
950 
951  }
952 
956  function getHTML()
957  {
958  include_once("./Services/Bookmarks/classes/class.ilBookmarkBlockGUI.php");
959  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
960 
961  return $bookmark_block_gui->getHTML();
962  }
963 
970  function importFile()
971  {
972  if(!$this->tree->isInTree($this->id))
973  {
974  $this->ctrl->setParameter($this, 'bmf_id', '');
975  $this->ctrl->redirect($this);
976  }
977 
978  if($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
979  {
980  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
981  $this->newFormBookmark();
982  return;
983  }
984  require_once ("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
985  $objects = ilBookmarkImportExport::_parseFile($_FILES["bkmfile"]['tmp_name']);
986  if($objects === false)
987  {
988  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
989  $this->newFormBookmark();
990  return;
991  }
992  // holds the number of created objects
993  $num_create = array('bm'=> 0, 'bmf'=> 0);
994  $this->__importBookmarks($objects, $num_create, $this->id, 0);
995 
996  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"), $num_create['bm'],
997  $num_create['bmf']));
998  $this->view();
999 
1000 
1001  }
1002 
1011  function __importBookmarks(&$objects, &$num_create, $folder_id, $start_key = 0)
1012  {
1013  if(is_array($objects[$start_key]))
1014  {
1015  foreach($objects[$start_key] as $obj_key=> $object)
1016  {
1017  switch($object['type'])
1018  {
1019  case 'bm':
1020  if(!$object["title"]) continue;
1021  if(!$object["target"]) continue;
1022  $bm = new ilBookmark();
1023  $bm->setTitle($object["title"]);
1024  $bm->setDescription($object["description"]);
1025  $bm->setTarget($object["target"]);
1026  $bm->setParent($folder_id);
1027  $bm->create();
1028  $num_create['bm']++;
1029  break;
1030  case 'bmf':
1031  if(!$object["title"]) continue;
1032  $bmf = new ilBookmarkFolder();
1033  $bmf->setTitle($object["title"]);
1034  $bmf->setParent($folder_id);
1035  $bmf->create();
1036  $num_create['bmf']++;
1037  if(is_array($objects[$obj_key]))
1038  {
1039  $this->__importBookmarks($objects, $num_create,
1040  $bmf->getId(), $obj_key);
1041  }
1042  break;
1043  }
1044  }
1045  }
1046  }
1047 
1048  function move()
1049  {
1050  global $ilUser, $ilTabs;
1051 
1052  $bm_ids = $_REQUEST['bm_id'];
1053  if(!$bm_ids)
1054  {
1055  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1056  return $this->view();
1057  }
1058 
1059  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this));
1060 
1061  $this->ctrl->setParameter($this, "bm_id_tgt", implode(";", $bm_ids));
1062  $exp = new ilBookmarkExplorer($this->ctrl->getLinkTarget($this, "confirmedMove"), $ilUser->getId());
1063  $exp->setAllowedTypes(array('bmf'));
1064  $exp->setTargetGet("bmfmv_id");
1065  $exp->forceExpandAll(true, false);
1066  $exp->addRoot($this->lng->txt("bookmarks"));
1067  $exp->setOutput(0);
1068 
1069  ilUtil::sendInfo($this->lng->txt("bookmark_select_target"));
1070  $this->tpl->setContent($exp->getOutput());
1071 
1072  // do not display navigation tree
1073  $this->mode = "flat";
1074  }
1075 
1076  function confirmedMove()
1077  {
1078  global $ilUser;
1079 
1080  $tgt = (int)$_REQUEST["bmfmv_id"];
1081  $bm_ids = explode(";", $_REQUEST['bm_id_tgt']);
1082  if(!$bm_ids || !$tgt)
1083  {
1084  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1085  return $this->view();
1086  }
1087 
1088  $tree = new ilTree($ilUser->getId());
1089  $tree->setTableNames('bookmark_tree', 'bookmark_data');
1090 
1091  $tgt_node = $tree->getNodeData($tgt);
1092 
1093  // sanity check
1094  foreach($bm_ids as $node_id)
1095  {
1096  if($tree->isGrandChild($node_id, $tgt))
1097  {
1098  ilUtil::sendFailure($this->lng->txt("error"), true);
1099  $this->ctrl->redirect($this, "view");
1100  }
1101 
1102  $node = $tree->getNodeData($node_id);
1103 
1104  // already at correct position
1105  if($node["parent"] == $tgt)
1106  {
1107  continue;
1108  }
1109 
1110  $tree->moveTree($node_id, $tgt);
1111  }
1112 
1113  ilUtil::sendSuccess($this->lng->txt("bookmark_moved_ok"), true);
1114  $this->ctrl->setParameter($this, "bmf_id", $tgt);
1115  $this->ctrl->redirect($this, "view");
1116  }
1117 }