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