ILIAS  Release_4_4_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->setTitleIcon(ilUtil::getImagePath("icon_pd_b.png"),
160 // "");
161  $this->tpl->setTitle($this->lng->txt("bookmarks"));
162  }
163 
164  /*
165  * display content of bookmark folder
166  */
167  function view()
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  $objects = ilBookmarkFolder::getObjects($this->id);
176 
177  include_once 'Services/Bookmarks/classes/class.ilBookmarkAdministrationTableGUI.php';
178  $table = new ilBookmarkAdministrationTableGUI($this);
179  $table->setId('bookmark_adm_table');
180  $table->setData($objects);
181  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
182  }
183 
187  function add_cell($val, $link = "")
188  {
189  if(!empty($link))
190  {
191  $this->tpl->setCurrentBlock("begin_link");
192  $this->tpl->setVariable("LINK_TARGET", $link);
193  $this->tpl->parseCurrentBlock();
194  $this->tpl->touchBlock("end_link");
195  }
196 
197  $this->tpl->setCurrentBlock("text");
198  $this->tpl->setVariable("TEXT_CONTENT", $val);
199  $this->tpl->parseCurrentBlock();
200  $this->tpl->setCurrentBlock("table_cell");
201  $this->tpl->parseCurrentBlock();
202  }
203 
207  function displayLocator()
208  {
209  global $lng;
210 
211  if(empty($this->id))
212  {
213  return;
214  }
215 
216  if(!$this->tree->isInTree($this->id))
217  {
218  return;
219  }
220 
221  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
222 
223  $path = $this->tree->getPathFull($this->id);
224 //print_r($path);
225  $modifier = 1;
226 
227  return;
228  $this->tpl->setVariable("TXT_LOCATOR", $this->lng->txt("locator"));
229  $this->tpl->touchBlock("locator_separator");
230  $this->tpl->touchBlock("locator_item");
231  //$this->tpl->setCurrentBlock("locator_item");
232  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
233  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
234  //$this->tpl->setVariable("LINK_TARGET","target=\"".
235  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
236  //$this->tpl->parseCurrentBlock();
237 
238  foreach($path as $key => $row)
239  {
240  if($key < count($path) - $modifier)
241  {
242  $this->tpl->touchBlock("locator_separator");
243  }
244 
245  $this->tpl->setCurrentBlock("locator_item");
246  $title = ($row["child"] == 1) ?
247  $lng->txt("bookmarks") :
248  $row["title"];
249  $this->tpl->setVariable("ITEM", $title);
250  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
251  $this->tpl->setVariable("LINK_ITEM",
252  $this->ctrl->getLinkTarget($this));
253  $this->tpl->parseCurrentBlock();
254  }
255 
256  $this->tpl->setCurrentBlock("locator");
257 
258  $this->tpl->parseCurrentBlock();
259  }
260 
264  function newForm($type)
265  {
266  if(!$type)
267  $type = $_POST["type"];
268  switch($type)
269  {
270  case "bmf":
271  $this->newFormBookmarkFolder();
272  break;
273 
274  case "bm":
275  $this->newFormBookmark();
276  break;
277  }
278  }
279 
284  {
285  if(!$this->tree->isInTree($this->id))
286  {
287  $this->ctrl->setParameter($this, 'bmf_id', '');
288  $this->ctrl->redirect($this);
289  }
290 
291  $form = $this->initFormBookmarkFolder();
292  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
293  }
294 
299  private function initFormBookmarkFolder($action = 'createBookmarkFolder')
300  {
301  global $lng, $ilCtrl, $ilUser;
302 
303  if(!$this->tree->isInTree($this->id))
304  {
305  $this->ctrl->setParameter($this, 'bmf_id', '');
306  $this->ctrl->redirect($this);
307  }
308 
309  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
310  $form = new ilPropertyFormGUI();
311  $form->setTopAnchor("bookmark_top");
312 
313  $form->setTitle($lng->txt("bookmark_folder_new"));
314 
315  if($action == 'updateBookmarkFolder')
316  {
317  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
318  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
319  }
320 
321  $hash = ($ilUser->prefs["screen_reader_optimization"])
322  ? "bookmark_top"
323  : "";
324 
325  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
326 
327  $ilCtrl->clearParameters($this);
328 
329  // title
330  $prop = new ilTextInputGUI($lng->txt("title"), "title");
331  $prop->setRequired(true);
332  $form->addItem($prop);
333 
334  // buttons
335  $form->addCommandButton($action, $lng->txt('save'));
336  $form->addCommandButton('cancel', $lng->txt('cancel'));
337  return $form;
338  }
339 
344  {
345  if(!$this->tree->isInTree($_GET["obj_id"]))
346  {
347  $this->ctrl->setParameter($this, 'bmf_id', '');
348  $this->ctrl->setParameter($this, 'obj_id', '');
349  $this->ctrl->redirect($this);
350  }
351 
352  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
353  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
354  $form->setValuesByArray
355  (
356  array
357  (
358  "title" => $this->get_last("title", $bmf->getTitle()),
359  "obj_id" => $_GET["obj_id"],
360  )
361  );
362  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
363  }
364 
365 
370  private function initFormBookmark($action = 'createBookmark')
371  {
372  global $lng, $ilCtrl, $ilUser;
373 
374  if(!$this->tree->isInTree($this->id))
375  {
376  $this->ctrl->setParameter($this, 'bmf_id', '');
377  $this->ctrl->redirect($this);
378  }
379 
380  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
381  $form = new ilPropertyFormGUI();
382  $form->setTopAnchor("bookmark_top");
383 
384  $form->setTitle($lng->txt("bookmark_new"));
385 
386  if($action == 'updateBookmark')
387  {
388  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
389  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
390  }
391 
392  $hash = ($ilUser->prefs["screen_reader_optimization"])
393  ? "bookmark_top"
394  : "";
395 
396  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
397  $ilCtrl->clearParameters($this);
398  // title
399  $prop = new ilTextInputGUI($lng->txt("title"), "title");
400  $prop->setValue($_GET['bm_title']);
401  $prop->setRequired(true);
402  $form->addItem($prop);
403 
404  // description
405  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
406  $form->addItem($prop);
407 
408  // target link
409  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
410  $prop->setValue($_GET['bm_link']);
411  $prop->setRequired(true);
412  $form->addItem($prop);
413 
414  // hidden redirect field
415  if($_GET['return_to'])
416  {
417  $prop = new ilHiddenInputGUI('return_to');
418  $prop->setValue($_GET['return_to']);
419  $form->addItem($prop);
420 
421  $prop = new ilHiddenInputGUI('return_to_url');
422  if($_GET['return_to_url'])
423  $prop->setValue($_GET['return_to_url']);
424  else
425  $prop->setValue($_GET['bm_link']);
426  $form->addItem($prop);
427  }
428 
429  // buttons
430  $form->addCommandButton($action, $lng->txt('save'));
431  $form->addCommandButton('cancel', $lng->txt('cancel'));
432 
433  // keep imports?
434  /*
435  $this->tpl->setCurrentBlock('bkm_import');
436  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
437  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
438  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
439  $this->tpl->parseCurrentBlock();
440  //vd($_POST);
441  */
442 
443  return $form;
444  }
445 
450  private function initImportBookmarksForm()
451  {
452  global $lng, $ilCtrl, $ilUser;
453 
454  if(!$this->tree->isInTree($this->id))
455  {
456  $this->ctrl->setParameter($this, 'bmf_id', '');
457  $this->ctrl->redirect($this);
458  }
459 
460  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
461  $form = new ilPropertyFormGUI();
462  $form->setFormAction($ilCtrl->getFormAction($this, "importFile")); // #16133
463  $form->setTopAnchor("bookmark_top");
464  $form->setTitle($lng->txt("bkm_import"));
465 
466  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
467  $fi->setRequired(true);
468  $form->addItem($fi);
469 
470  $form->addCommandButton("importFile", $lng->txt('import'));
471  $form->addCommandButton('cancel', $lng->txt('cancel'));
472 
473  return $form;
474  }
475 
479  function newFormBookmark()
480  {
481  $form = $this->initFormBookmark();
482  $html1 = $form->getHTML();
483  $html2 = '';
484  if(!$_REQUEST["bm_link"])
485  {
486  $form2 = $this->initImportBookmarksForm();
487  $html2 = "<br />" . $form2->getHTML();
488  }
489  $this->tpl->setVariable("ADM_CONTENT", $html1 . $html2);
490  }
491 
492 
496  function get_last($a_var, $a_value)
497  {
498  return (!empty($_POST[$a_var])) ?
499  ilUtil::prepareFormOutput(($_POST[$a_var]), true) :
500  ilUtil::prepareFormOutput($a_value);
501  }
502 
506  function editFormBookmark()
507  {
508  global $lng, $ilCtrl;
509 
510  if(!$this->tree->isInTree($_GET["obj_id"]))
511  {
512  $this->ctrl->setParameter($this, 'obj_id', '');
513  $this->ctrl->setParameter($this, 'bmf_id', '');
514  $this->ctrl->redirect($this);
515  }
516 
517  $form = $this->initFormBookmark('updateBookmark');
518  $bookmark = new ilBookmark($_GET["obj_id"]);
519  $form->setValuesByArray
520  (
521  array
522  (
523  "title" => $bookmark->getTitle(),
524  "target" => $bookmark->getTarget(),
525  "description" => $bookmark->getDescription(),
526  "obj_id" => $_GET["obj_id"],
527  )
528  );
529  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
530  }
531 
532 
537  {
538  if(!$this->tree->isInTree($this->id))
539  {
540  $this->ctrl->setParameter($this, 'bmf_id', '');
541  $this->ctrl->redirect($this);
542  }
543 
544  // check title
545  if(empty($_POST["title"]))
546  {
547  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
548  $this->newFormBookmarkFolder();
549  }
550  else
551  {
552  // create bookmark folder
553  $bmf = new ilBookmarkFolder();
554  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
555  $bmf->setParent($this->id);
556  $bmf->create();
557 
558  global $ilCtrl;
559  $ilCtrl->saveParameter($this, 'bmf_id');
560  $ilCtrl->redirect($this, 'view');
561  }
562  }
563 
564 
569  {
570  if(!$this->tree->isInTree($_GET["obj_id"]))
571  {
572  $this->ctrl->setParameter($this, 'obj_id', '');
573  $this->ctrl->setParameter($this, 'bmf_id', '');
574  $this->ctrl->redirect($this);
575  }
576 
577  // check title
578  if(empty($_POST["title"]))
579  {
580  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
581  $this->editFormBookmarkFolder();
582  }
583  else
584  {
585  // update bookmark folder
586  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
587  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
588  $bmf->update();
589 
590  global $ilCtrl;
591  $ilCtrl->saveParameter($this, 'bmf_id');
592  $ilCtrl->redirect($this, 'view');
593  }
594  }
595 
596 
600  function createBookmark()
601  {
602  global $lng, $ilCtrl;
603 
604  if(!$this->tree->isInTree($this->id))
605  {
606  $this->ctrl->setParameter($this, 'bmf_id', '');
607  $this->ctrl->redirect($this);
608  }
609 
610  // check title and target
611  if(empty($_POST["title"]))
612  {
613  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
614  $this->newFormBookmark();
615  }
616  else if(empty($_POST["target"]))
617  {
618  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
619  $this->newFormBookmark();
620  }
621  else
622  {
623  // create bookmark
624  $bm = new ilBookmark();
625  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
626  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
627  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
628  $bm->setParent($this->id);
629  $bm->create();
630 
631  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
632 
633  if($_POST['return_to'])
634  ilUtil::redirect($_POST['return_to_url']);
635  else
636  {
637  $ilCtrl->saveParameter($this, 'bmf_id');
638  $ilCtrl->redirect($this, 'view');
639  }
640  }
641  }
642 
646  function updateBookmark()
647  {
648  if(!$this->tree->isInTree($_GET["obj_id"]))
649  {
650  $this->ctrl->setParameter($this, 'obj_id', '');
651  $this->ctrl->setParameter($this, 'bmf_id', '');
652  $this->ctrl->redirect($this);
653  }
654 
655  // check title and target
656  if(empty($_POST["title"]))
657  {
658  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
659  $this->editFormBookmark();
660  }
661  else if(empty($_POST["target"]))
662  {
663  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
664  $this->editFormBookmark();
665  }
666  else
667  {
668  // update bookmark
669  $bm = new ilBookmark($_GET["obj_id"]);
670  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
671  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
672  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
673  $bm->update();
674 
675  $this->view();
676  }
677  }
678 
682  function export($deliver = true)
683  {
684  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
685  if(!$bm_ids)
686  {
687  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
688  }
689  $export_ids = array();
690  foreach($bm_ids as $id)
691  {
692  if($this->tree->isInTree($id))
693  {
694  //list($type, $obj_id) = explode(":", $id);
695  //$export_ids[]=$obj_id;
696  $export_ids[] = $id;
697  }
698  }
699 
700  require_once ("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
701  $html_content = ilBookmarkImportExport::_exportBookmark($export_ids, true,
702  $this->lng->txt("bookmarks_of") . " " . $this->ilias->account->getFullname());
703 
704  if($deliver)
705  {
706  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
707  }
708  else
709  {
710  return $html_content;
711  }
712  }
713 
717  function sendmail()
718  {
719  global $ilUser;
720  include_once './Services/Mail/classes/class.ilFileDataMail.php';
721  require_once "Services/Mail/classes/class.ilFormatMail.php";
722  $mfile = new ilFileDataMail($ilUser->getId());
723  $umail = new ilFormatMail($ilUser->getId());
724 
725  $html_content = $this->export(false);
726  $tempfile = ilUtil::ilTempnam();
727  $fp = fopen($tempfile, 'w');
728  fwrite($fp, $html_content);
729  fclose($fp);
730  $filename = 'bookmarks.html';
731  $mfile->copyAttachmentFile($tempfile, $filename);
732  $umail->savePostData($ilUser->getId(), array($filename),
733  '', '', '', '', '',
734  '',
735  '', 0);
736 
737  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
738  ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, '', array(), array('type' => 'attach')));
739  }
740 
744  function delete()
745  {
746  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
747  if(!$bm_ids)
748  {
749  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
750  }
751 
752  $this->ctrl->setParameter($this, "bmf_id", $this->id);
753 
754  // display confirmation message
755  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
756  $cgui = new ilConfirmationGUI();
757  $cgui->setFormAction($this->ctrl->getFormAction($this));
758  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
759  $cgui->setCancel($this->lng->txt("cancel"), "cancel");
760  $cgui->setConfirm($this->lng->txt("confirm"), "confirm");
761 
762  foreach($bm_ids as $obj_id)
763  {
764  $type = ilBookmark::_getTypeOfId($obj_id);
765 
766  if(!$this->tree->isInTree($obj_id))
767  {
768  continue;
769  }
770 
771  switch($type)
772  {
773  case "bmf":
774  $BookmarkFolder = new ilBookmarkFolder($obj_id);
775  $title = $BookmarkFolder->getTitle();
776  $target = "";
777  unset($BookmarkFolder);
778  break;
779 
780  case "bm":
781  $Bookmark = new ilBookmark($obj_id);
782  $title = $Bookmark->getTitle();
783  $target = $Bookmark->getTarget();
784  unset($Bookmark);
785  break;
786  }
787 
788  $caption = ilUtil::getImageTagByType($type, $this->tpl->tplPath) .
789  " " . $title;
790  if($target)
791  {
792  $caption .= " (" . ilUtil::shortenText($target, $this->textwidth, true) . ")";
793  }
794 
795  $cgui->addItem("id[]", $obj_id, $caption);
796  }
797 
798  $this->tpl->setContent($cgui->getHTML());
799  }
800 
804  function cancel()
805  {
806  if($_POST['return_to'])
807  ilUtil::redirect($_POST['return_to_url']);
808  else
809  $this->view();
810  }
811 
815  function confirm()
816  {
817  global $tree, $rbacsystem, $rbacadmin;
818  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
819  if(!$_POST["id"])
820  {
821  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
822  }
823 
824  // FOR ALL SELECTED OBJECTS
825  foreach($_POST["id"] as $id)
826  {
827  $type = ilBookmark::_getTypeOfId($id);
828 
829  // get node data and subtree nodes
830  if($this->tree->isInTree($id))
831  {
832  $node_data = $this->tree->getNodeData($id);
833  $subtree_nodes = $this->tree->getSubTree($node_data);
834  }
835  else
836  {
837  continue;
838  }
839 
840  // delete tree
841  $this->tree->deleteTree($node_data);
842 
843  // delete objects of subtree nodes
844  foreach($subtree_nodes as $node)
845  {
846  switch($node["type"])
847  {
848  case "bmf":
849  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
850  $BookmarkFolder->delete();
851  break;
852 
853  case "bm":
854  $Bookmark = new ilBookmark($node["obj_id"]);
855  $Bookmark->delete();
856  break;
857  }
858  }
859  }
860 
861  // Feedback
862  ilUtil::sendSuccess($this->lng->txt("info_deleted"), true);
863 
864  $this->view();
865  }
866 
867 
872  {
873  $actions = array(
874  "delete" => $this->lng->txt("delete"),
875  "export" => $this->lng->txt("export"),
876  "sendmail"=> $this->lng->txt("bkm_sendmail"),
877  );
878 
879  $subobj = array("bm", "bmf");
880 
881  if(is_array($subobj))
882  {
883  //build form
884  $opts = ilUtil::formSelect("", "type", $subobj);
885 
886  $this->tpl->setCurrentBlock("add_object");
887  $this->tpl->setVariable("COLUMN_COUNTS", 7);
888  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
889  $this->tpl->setVariable("BTN_NAME", "newForm");
890  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
891  $this->tpl->parseCurrentBlock();
892  }
893 
894  $this->tpl->setVariable("TPLPATH", $this->tpl->tplPath);
895 
896  $this->tpl->setCurrentBlock("tbl_action_select");
897  $this->tpl->setVariable("SELECT_ACTION", ilUtil::formSelect($_SESSION["error_post_vars"]['action'], "action", $actions, false, true));
898  $this->tpl->setVariable("BTN_NAME", "executeAction");
899  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("execute"));
900 
901  /*
902  $this->tpl->setVariable("BTN_NAME","delete");
903  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
904  $this->tpl->parseCurrentBlock();
905 
906  $this->tpl->setVariable("BTN_NAME","export");
907  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
908  $this->tpl->parseCurrentBlock();
909  */
910  $this->tpl->parseCurrentBlock();
911 
912  }
913 
917  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  function importFile()
932  {
933  if(!$this->tree->isInTree($this->id))
934  {
935  $this->ctrl->setParameter($this, 'bmf_id', '');
936  $this->ctrl->redirect($this);
937  }
938 
939  if($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
940  {
941  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
942  $this->newFormBookmark();
943  return;
944  }
945  require_once ("./Services/Bookmarks/classes/class.ilBookmarkImportExport.php");
946  $objects = ilBookmarkImportExport::_parseFile($_FILES["bkmfile"]['tmp_name']);
947  if($objects === false)
948  {
949  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
950  $this->newFormBookmark();
951  return;
952  }
953  // holds the number of created objects
954  $num_create = array('bm'=> 0, 'bmf'=> 0);
955  $this->__importBookmarks($objects, $num_create, $this->id, 0);
956 
957  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"), $num_create['bm'],
958  $num_create['bmf']));
959  $this->view();
960 
961 
962  }
963 
972  function __importBookmarks(&$objects, &$num_create, $folder_id, $start_key = 0)
973  {
974  if(is_array($objects[$start_key]))
975  {
976  foreach($objects[$start_key] as $obj_key=> $object)
977  {
978  switch($object['type'])
979  {
980  case 'bm':
981  if(!$object["title"]) continue;
982  if(!$object["target"]) continue;
983  $bm = new ilBookmark();
984  $bm->setTitle($object["title"]);
985  $bm->setDescription($object["description"]);
986  $bm->setTarget($object["target"]);
987  $bm->setParent($folder_id);
988  $bm->create();
989  $num_create['bm']++;
990  break;
991  case 'bmf':
992  if(!$object["title"]) continue;
993  $bmf = new ilBookmarkFolder();
994  $bmf->setTitle($object["title"]);
995  $bmf->setParent($folder_id);
996  $bmf->create();
997  $num_create['bmf']++;
998  if(is_array($objects[$obj_key]))
999  {
1000  $this->__importBookmarks($objects, $num_create,
1001  $bmf->getId(), $obj_key);
1002  }
1003  break;
1004  }
1005  }
1006  }
1007  }
1008 
1009  function move()
1010  {
1011  global $ilUser, $ilTabs, $tpl;
1012 
1013  $bm_ids = $_REQUEST['bm_id'];
1014  if(!$bm_ids && $_GET["bm_id_tgt"] == "")
1015  {
1016  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1017  return $this->view();
1018  }
1019 
1020  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this));
1021 
1022  $this->ctrl->setParameter($this, "bm_id_tgt", $_GET["bm_id_tgt"] ? $_GET["bm_id_tgt"] : implode(";", $bm_ids));
1023  ilUtil::sendInfo($this->lng->txt("bookmark_select_target"));
1024  include_once("./Services/Bookmarks/classes/class.ilBookmarkMoveExplorerGUI.php");
1025  $exp = new ilBookmarkMoveExplorerGUI($this, "move");
1026  if (!$exp->handleCommand())
1027  {
1028  $this->mode = "flat";
1029  $this->tpl->setContent($exp->getHTML());
1030  }
1031  }
1032 
1033  function confirmedMove()
1034  {
1035  global $ilUser;
1036 
1037  $tgt = (int)$_REQUEST["bmfmv_id"];
1038  $bm_ids = explode(";", $_REQUEST['bm_id_tgt']);
1039  if(!$bm_ids || !$tgt)
1040  {
1041  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
1042  return $this->view();
1043  }
1044 
1045  $tree = new ilTree($ilUser->getId());
1046  $tree->setTableNames('bookmark_tree', 'bookmark_data');
1047 
1048  $tgt_node = $tree->getNodeData($tgt);
1049 
1050  // sanity check
1051  foreach($bm_ids as $node_id)
1052  {
1053  if($tree->isGrandChild($node_id, $tgt))
1054  {
1055  ilUtil::sendFailure($this->lng->txt("error"), true);
1056  $this->ctrl->redirect($this, "view");
1057  }
1058 
1059  $node = $tree->getNodeData($node_id);
1060 
1061  // already at correct position
1062  if($node["parent"] == $tgt)
1063  {
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 }