ILIAS  Release_4_2_x_branch Revision 61807
 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-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
18 require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkExplorer.php");
19 require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php");
20 require_once ("./Services/PersonalDesktop/classes/class.ilBookmark.php");
21 require_once ("./Services/Table/classes/class.ilTableGUI.php");
22 
24 {
30  var $user_id;
31 
37  var $ilias;
38  var $tpl;
39  var $lng;
40 
41  var $tree;
42  var $id;
43  var $data;
44  var $textwidth=100;
45 
52  {
53  global $ilias, $tpl, $lng, $ilCtrl;
54 
55 // $tpl->enableAdvancedColumnLayout(true, false);
56 
57  //print_r($_SESSION["error_post_vars"]);
58  // if no bookmark folder id is given, take dummy root node id (that is 1)
59  $this->id = (empty($_GET["bmf_id"]))
60  ? $bmf_id = 1
61  : $_GET["bmf_id"];
62 
63  // initiate variables
64  $this->ilias =& $ilias;
65  $this->tpl =& $tpl;
66  $this->lng =& $lng;
67  $this->ctrl =& $ilCtrl;
68  $this->ctrl->setParameter($this, "bmf_id", $this->id);
69  $this->user_id = $_SESSION["AccountId"];
70 
71  $this->tree = new ilTree($_SESSION["AccountId"]);
72  $this->tree->setTableNames('bookmark_tree','bookmark_data');
73  $this->root_id = $this->tree->readRootId();
74  // set current bookmark view mode
75  //if (!empty($_GET["set_mode"]))
76  //{
77  // $this->ilias->account->writePref("il_bkm_mode", $_GET["set_mode"]);
78  //}
79  //$this->mode = $this->ilias->account->getPref("il_bkm_mode");
80  $this->mode = "tree";
81  }
82 
86  function &executeCommand()
87  {
88  $next_class = $this->ctrl->getNextClass();
89 
90  switch($next_class)
91  {
92  default:
93  $cmd = $this->ctrl->getCmd("view");
94  $this->displayHeader();
95  $this->$cmd();
96  if ($this->getMode() == 'tree')
97  {
98  $this->explorer();
99  }
100  break;
101  }
102  $this->tpl->show(true);
103  return true;
104  }
105  function executeAction()
106  {
107  switch($_POST["selected_cmd"])
108  {
109  case "delete":
110  $this->delete();
111  break;
112  case "export":
113  $this->export();
114  break;
115  case "sendmail":
116  $this->sendmail();
117  break;
118  default:
119  $this->view();
120  break;
121  }
122  return true;
123  }
124 
129  function getMode() {
130  return $this->mode;
131  }
132 
136  function explorer()
137  {
138  global $tpl;
139 
140  $etpl = new ilTemplate("tpl.bookmark_explorer.html", true, true,
141  "Services/PersonalDesktop");
142  $exp = new ilBookmarkExplorer($this->ctrl->getLinkTarget($this),$_SESSION["AccountId"]);
143  $exp->setAllowedTypes(array('dum','bmf'));
144  $exp->setTargetGet("bmf_id");
145  $exp->setSessionExpandVariable('mexpand');
146  $exp->setExpand($this->id);
147  $this->ctrl->setParameter($this, "bmf_id", $this->id);
148  $exp->setExpandTarget($this->ctrl->getLinkTarget($this));
149  if ($_GET["mexpand"] == "")
150  {
151  $mtree = new ilTree($_SESSION["AccountId"]);
152  $mtree->setTableNames('bookmark_tree','bookmark_data');
153  $expanded = $mtree->readRootId();
154  }
155  else
156  {
157  $expanded = $_GET["mexpand"];
158  }
159 
160  $exp->setExpand($expanded);
161  $exp->highlightNode($_GET["bmf_id"]);
162 
163  // build html-output
164  $exp->setOutput(0);
165  $exp->highlightNode($this->id);
166  $output = $exp->getOutput();
167 
168 // $etpl->setCurrentBlock("adm_tree_content");
169  $etpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("bookmarks"));
170  $this->ctrl->setParameter($this, "bmf_id", 1);
171 
172  if ($_REQUEST['bm_link'])
173  {
174  $link = $_SERVER['REQUEST_URI'];
175  $link = ereg_replace('bmf_id=[0-9]*', 'bmf_id=1', $link);
176  $etpl->setVariable("LINK_EXPLORER_HEADER",$link);
177  }
178  else
179  $etpl->setVariable("LINK_EXPLORER_HEADER",$this->ctrl->getLinkTarget($this));
180 
181  $etpl->setVariable("EXPLORER",$output);
182  $tpl->setLeftContent($etpl->get());;
183  }
184 
185 
189  function displayHeader()
190  {
191  // output locator
192  $this->displayLocator();
193 
194  // output message
195  if($this->message)
196  {
197  ilUtil::sendInfo($this->message);
198  }
200 
201 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
202 // "");
203  $this->tpl->setTitle($this->lng->txt("bookmarks"));
204  }
205 
206  /*
207  * display content of bookmark folder
208  */
209  function view()
210  {
211  global $tree, $ilCtrl;
212 
213  include_once("classes/class.ilFrameTargetInfo.php");
214 
215  if ($this->id > 0 && !$this->tree->isInTree($this->id))
216  {
217  $this->ctrl->setParameter($this, 'bmf_id', '');
218  $this->ctrl->redirect($this);
219  }
220 
221  $mtree = new ilTree($_SESSION["AccountId"]);
222  $mtree->setTableNames('bookmark_tree','bookmark_data');
223 
224  $objects = ilBookmarkFolder::getObjects($this->id);
225 
226  $s_mode = ($this->mode == "tree")
227  ? "flat"
228  : "tree";
229 
230 // $this->tpl->setTreeFlatIcon($this->ctrl->getLinkTarget($this)."&set_mode=".$s_mode,
231 // $s_mode);
232 
233  include_once 'Services/PersonalDesktop/classes/class.ilBookmarkAdministrationTableGUI.php';
234  $table = new ilBookmarkAdministrationTableGUI($this);
235  $table->setId('bookmark_adm_table');
236  /*
237  // return to parent folder
238  // disabled
239  if ($this->id != $mtree->readRootId() || $this->id =="")
240  {
241  $ilCtrl->setParameter($this, "bmf_id", $mtree->getParentId($this->id));
242  $objects = array_merge
243  (
244  array
245  (
246  array
247  (
248  "title" => "..",
249  "target" => $ilCtrl->getLinkTarget($this),
250  "type" => 'parent',
251  "obj_id" => $mtree->getParentId($this->id),
252  )
253  ),
254  $objects
255  );
256  }
257  */
258  $table->setData($objects);
259  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
260  }
261 
265  function add_cell($val, $link = "")
266  {
267  if (!empty($link))
268  {
269  $this->tpl->setCurrentBlock("begin_link");
270  $this->tpl->setVariable("LINK_TARGET", $link);
271  $this->tpl->parseCurrentBlock();
272  $this->tpl->touchBlock("end_link");
273  }
274 
275  $this->tpl->setCurrentBlock("text");
276  $this->tpl->setVariable("TEXT_CONTENT", $val);
277  $this->tpl->parseCurrentBlock();
278  $this->tpl->setCurrentBlock("table_cell");
279  $this->tpl->parseCurrentBlock();
280  }
281 
285  function displayLocator()
286  {
287  global $lng;
288 
289  if (empty($this->id))
290  {
291  return;
292  }
293 
294  if (!$this->tree->isInTree($this->id))
295  {
296  return;
297  }
298 
299  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
300 
301  $path = $this->tree->getPathFull($this->id);
302 //print_r($path);
303  $modifier = 1;
304 
305 return;
306  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
307  $this->tpl->touchBlock("locator_separator");
308  $this->tpl->touchBlock("locator_item");
309  //$this->tpl->setCurrentBlock("locator_item");
310  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
311  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
312  //$this->tpl->setVariable("LINK_TARGET","target=\"".
313  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
314  //$this->tpl->parseCurrentBlock();
315 
316  foreach ($path as $key => $row)
317  {
318  if ($key < count($path)-$modifier)
319  {
320  $this->tpl->touchBlock("locator_separator");
321  }
322 
323  $this->tpl->setCurrentBlock("locator_item");
324  $title = ($row["child"] == 1) ?
325  $lng->txt("bookmarks") :
326  $row["title"];
327  $this->tpl->setVariable("ITEM", $title);
328  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
329  $this->tpl->setVariable("LINK_ITEM",
330  $this->ctrl->getLinkTarget($this));
331  $this->tpl->parseCurrentBlock();
332  }
333 
334  $this->tpl->setCurrentBlock("locator");
335 
336  $this->tpl->parseCurrentBlock();
337  }
338 
342  function newForm($type)
343  {
344  if (!$type)
345  $type = $_POST["type"];
346  switch($type)
347  {
348  case "bmf":
349  $this->newFormBookmarkFolder();
350  break;
351 
352  case "bm":
353  $this->newFormBookmark();
354  break;
355  }
356  }
357 
362  {
363  if (!$this->tree->isInTree($this->id))
364  {
365  $this->ctrl->setParameter($this, 'bmf_id', '');
366  $this->ctrl->redirect($this);
367  }
368 
369  $form = $this->initFormBookmarkFolder();
370  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
371  }
372 
377  private function initFormBookmarkFolder($action = 'createBookmarkFolder')
378  {
379  global $lng, $ilCtrl, $ilUser;
380 
381  if (!$this->tree->isInTree($this->id))
382  {
383  $this->ctrl->setParameter($this, 'bmf_id', '');
384  $this->ctrl->redirect($this);
385  }
386 
387  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
388  $form = new ilPropertyFormGUI();
389  $form->setTopAnchor("bookmark_top");
390 
391  $form->setTitle($lng->txt("bookmark_folder_new"));
392 
393  if ($action == 'updateBookmarkFolder')
394  {
395  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
396  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
397  }
398 
399  $hash = ($ilUser->prefs["screen_reader_optimization"])
400  ? "bookmark_top"
401  : "";
402 
403  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
404 
405  $ilCtrl->clearParameters($this);
406 
407  // title
408  $prop = new ilTextInputGUI($lng->txt("title"), "title");
409  $prop->setRequired(true);
410  $form->addItem($prop);
411 
412  // buttons
413  $form->addCommandButton($action, $lng->txt('save'));
414  $form->addCommandButton('cancel', $lng->txt('cancel'));
415  return $form;
416  }
417 
422  {
423  if(!$this->tree->isInTree($_GET["obj_id"]))
424  {
425  $this->ctrl->setParameter($this, 'bmf_id', '');
426  $this->ctrl->setParameter($this, 'obj_id', '');
427  $this->ctrl->redirect($this);
428  }
429 
430  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
431  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
432  $form->setValuesByArray
433  (
434  array
435  (
436  "title" => $this->get_last("title", $bmf->getTitle()),
437  "obj_id" => $_GET["obj_id"],
438  )
439  );
440  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
441  }
442 
443 
448  private function initFormBookmark($action = 'createBookmark')
449  {
450  global $lng, $ilCtrl, $ilUser;
451 
452  if (!$this->tree->isInTree($this->id))
453  {
454  $this->ctrl->setParameter($this, 'bmf_id', '');
455  $this->ctrl->redirect($this);
456  }
457 
458  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
459  $form = new ilPropertyFormGUI();
460  $form->setTopAnchor("bookmark_top");
461 
462  $form->setTitle($lng->txt("bookmark_new"));
463 
464  if ($action == 'updateBookmark')
465  {
466  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
467  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
468  }
469 
470  $hash = ($ilUser->prefs["screen_reader_optimization"])
471  ? "bookmark_top"
472  : "";
473 
474  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
475  $ilCtrl->clearParameters($this);
476  // title
477  $prop = new ilTextInputGUI($lng->txt("title"), "title");
478  $prop->setValue($_GET['bm_title']);
479  $prop->setRequired(true);
480  $form->addItem($prop);
481 
482  // description
483  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
484  $form->addItem($prop);
485 
486  // target link
487  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
488  $prop->setValue($_GET['bm_link']);
489  $prop->setRequired(true);
490  $form->addItem($prop);
491 
492  // hidden redirect field
493  if ($_GET['return_to'])
494  {
495  $prop = new ilHiddenInputGUI('return_to');
496  $prop->setValue($_GET['return_to']);
497  $form->addItem($prop);
498 
499  $prop = new ilHiddenInputGUI('return_to_url');
500  if ($_GET['return_to_url'])
501  $prop->setValue($_GET['return_to_url']);
502  else
503  $prop->setValue($_GET['bm_link']);
504  $form->addItem($prop);
505  }
506 
507  // buttons
508  $form->addCommandButton($action, $lng->txt('save'));
509  $form->addCommandButton('cancel', $lng->txt('cancel'));
510 
511  // keep imports?
512  /*
513  $this->tpl->setCurrentBlock('bkm_import');
514  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
515  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
516  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
517  $this->tpl->parseCurrentBlock();
518  //vd($_POST);
519  */
520 
521  return $form;
522  }
523 
528  private function initImportBookmarksForm()
529  {
530  global $lng, $ilCtrl, $ilUser;
531 
532  if (!$this->tree->isInTree($this->id))
533  {
534  $this->ctrl->setParameter($this, 'bmf_id', '');
535  $this->ctrl->redirect($this);
536  }
537 
538  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
539  $form = new ilPropertyFormGUI();
540  $form->setTopAnchor("bookmark_top");
541  $form->setTitle($lng->txt("bkm_import"));
542 
543  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
544  $fi->setRequired(true);
545  $form->addItem($fi);
546 
547  $form->addCommandButton("importFile", $lng->txt('import'));
548  $form->addCommandButton('cancel', $lng->txt('cancel'));
549 
550  return $form;
551  }
552 
556  function newFormBookmark()
557  {
558  $form = $this->initFormBookmark();
559  $html1 = $form->getHTML();
560  $html2 = '';
561  if (!$_REQUEST["bm_link"])
562  {
563  $form2 = $this->initImportBookmarksForm();
564  $html2 = "<br />" . $form2->getHTML();
565  }
566  $this->tpl->setVariable("ADM_CONTENT", $html1.$html2);
567  }
568 
569 
573  function get_last($a_var, $a_value)
574  {
575  return (!empty($_POST[$a_var])) ?
576  ilUtil::prepareFormOutput(($_POST[$a_var]),true) :
577  ilUtil::prepareFormOutput($a_value);
578  }
579 
583  function editFormBookmark()
584  {
585  global $lng, $ilCtrl;
586  if (!$this->tree->isInTree($_GET["obj_id"]))
587  {
588  $this->ctrl->setParameter($this, 'bmf_id', '');
589  $this->ctrl->setParameter($this, 'obj_id', '');
590  $this->ctrl->redirect($this);
591  }
592  $form = $this->initFormBookmark('updateBookmark');
593  $bookmark = new ilBookmark($_GET["obj_id"]);
594  $form->setValuesByArray
595  (
596  array
597  (
598  "title" => $bookmark->getTitle(),
599  "target" => $bookmark->getTarget(),
600  "description" => $bookmark->getDescription(),
601  "obj_id" => $_GET["obj_id"],
602  )
603  );
604  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
605  }
606 
607 
612  {
613  if (!$this->tree->isInTree($this->id))
614  {
615  $this->ctrl->setParameter($this, 'bmf_id', '');
616  $this->ctrl->redirect($this);
617  }
618 
619  // check title
620  if (empty($_POST["title"]))
621  {
622  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
623  $this->newFormBookmarkFolder();
624  }
625  else
626  {
627  // create bookmark folder
628  $bmf = new ilBookmarkFolder();
629  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
630  $bmf->setParent($this->id);
631  $bmf->create();
632 
633  global $ilCtrl;
634  $ilCtrl->saveParameter($this, 'bmf_id');
635  $ilCtrl->redirect($this, 'view');
636  }
637  }
638 
639 
644  {
645  if (!$this->tree->isInTree($_GET["obj_id"]))
646  {
647  $this->ctrl->setParameter($this, 'bmf_id', '');
648  $this->ctrl->setParameter($this, 'obj_id', '');
649  $this->ctrl->redirect($this);
650  }
651 
652  // check title
653  if (empty($_POST["title"]))
654  {
655  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
656  $this->editFormBookmarkFolder();
657  }
658  else
659  {
660  // update bookmark folder
661  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
662  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
663  $bmf->update();
664 
665  global $ilCtrl;
666  $ilCtrl->saveParameter($this, 'bmf_id');
667  $ilCtrl->redirect($this, 'view');
668  }
669  }
670 
671 
675  function createBookmark()
676  {
677  global $lng, $ilCtrl;
678  if (!$this->tree->isInTree($this->id))
679  {
680  $this->ctrl->setParameter($this, 'bmf_id', '');
681  $this->ctrl->redirect($this);
682  }
683 
684  // check title and target
685  if (empty($_POST["title"]))
686  {
687  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
688  $this->newFormBookmark();
689  }
690  else if (empty($_POST["target"]))
691  {
692  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
693  $this->newFormBookmark();
694  }
695  else
696  {
697  // create bookmark
698  $bm = new ilBookmark();
699  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
700  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
701  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
702  $bm->setParent($this->id);
703  $bm->create();
704 
705  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
706 
707  if ($_POST['return_to'])
708  ilUtil::redirect($_POST['return_to_url']);
709  else {
710  $ilCtrl->saveParameter($this, 'bmf_id');
711  $ilCtrl->redirect($this, 'view');
712  }
713  }
714  }
715 
719  function updateBookmark()
720  {
721  if (!$this->tree->isInTree($_GET["obj_id"]))
722  {
723  $this->ctrl->setParameter($this, 'bmf_id', '');
724  $this->ctrl->setParameter($this, 'obj_id', '');
725  $this->ctrl->redirect($this);
726  }
727 
728  // check title and target
729  if (empty($_POST["title"]))
730  {
731  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
732  $this->editFormBookmark();
733  }
734  else if (empty($_POST["target"]))
735  {
736  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
737  $this->editFormBookmark();
738  }
739  else
740  {
741  // update bookmark
742  $bm = new ilBookmark($_GET["obj_id"]);
743  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
744  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
745  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
746  $bm->update();
747 
748  $this->view();
749  }
750  }
751 
755  function export($deliver=true)
756  {
757  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
758  if (!$bm_ids)
759  {
760  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
761  }
762  $export_ids=array();
763  foreach($bm_ids as $id)
764  {
765  if ($this->tree->isInTree($id))
766  {
767  //list($type, $obj_id) = explode(":", $id);
768  //$export_ids[]=$obj_id;
769  $export_ids[]=$id;
770  }
771  }
772 
773  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
774  $html_content=ilBookmarkImportExport::_exportBookmark ($export_ids,true,
775  $this->lng->txt("bookmarks_of")." ".$this->ilias->account->getFullname());
776 
777  if ($deliver)
778  {
779  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
780  }
781  else
782  {
783  return $html_content;
784  }
785  }
789  function sendmail()
790  {
791  global $ilUser;
792  include_once 'classes/class.ilFileDataMail.php';
793  require_once "Services/Mail/classes/class.ilFormatMail.php";
794  $mfile = new ilFileDataMail($ilUser->getId());
795  $umail = new ilFormatMail($ilUser->getId());
796 
797  $html_content=$this->export(false);
798  $tempfile=ilUtil::ilTempnam();
799  $fp=fopen($tempfile,'w');
800  fwrite($fp, $html_content);
801  fclose($fp);
802  $filename='bookmarks.html';
803  $mfile->copyAttachmentFile($tempfile,$filename);
804  $umail->savePostData($ilUser->getId(),array($filename),
805  '','','','','',
806  '',
807  '', 0);
808 
809  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
810  ilUtil::redirect(ilMailFormCall::_getRedirectTarget($this, '', array(), array('type' => 'attach')));
811  }
815  function delete()
816  {
817  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
818  if (!$bm_ids)
819  {
820  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
821  }
822 
823  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
824 
825  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
826  $this->ctrl->setParameter($this, "bmf_id", $this->id);
827  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
828 
829  // output table header
830  $cols = array("type", "title");
831  foreach ($cols as $key)
832  {
833  $this->tpl->setCurrentBlock("table_header");
834  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
835  $this->tpl->parseCurrentBlock();
836  }
837 
838  $_SESSION["saved_post"] = $bm_ids;
839 
840  foreach($bm_ids as $obj_id)
841  {
842  $type = ilBookmark::_getTypeOfId($obj_id);
843 
844  if (!$this->tree->isInTree($obj_id))
845  {
846  continue;
847  }
848  switch($type)
849  {
850  case "bmf":
851  $BookmarkFolder = new ilBookmarkFolder($obj_id);
852  $title = $BookmarkFolder->getTitle();
853  $target = "";
854  unset($BookmarkFolder);
855  break;
856 
857  case "bm":
858  $Bookmark = new ilBookmark($obj_id);
859  $title = $Bookmark->getTitle();
860  $target = $Bookmark->getTarget();
861  unset($Bookmark);
862  break;
863  }
864 
865  // output type icon
866  $this->tpl->setCurrentBlock("table_cell");
867  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
868  $this->tpl->parseCurrentBlock();
869 
870  // output title
871  $this->tpl->setCurrentBlock("table_cell");
872  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
873 
874  // output target
875  if ($target)
876  {
877  $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
878  $target,$this->textwidth, true)));
879  }
880  $this->tpl->parseCurrentBlock();
881 
882  // output table row
883  $this->tpl->setCurrentBlock("table_row");
884  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
885  $this->tpl->parseCurrentBlock();
886  }
887 
888  // cancel and confirm button
889  $buttons = array( "cancel" => $this->lng->txt("cancel"),
890  "confirm" => $this->lng->txt("confirm"));
891 
892  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
893  foreach($buttons as $name => $value)
894  {
895  $this->tpl->setCurrentBlock("operation_btn");
896  $this->tpl->setVariable("BTN_NAME",$name);
897  $this->tpl->setVariable("BTN_VALUE",$value);
898  $this->tpl->parseCurrentBlock();
899  }
900  }
901 
905  function cancel()
906  {
907  session_unregister("saved_post");
908  if ($_POST['return_to'])
909  ilUtil::redirect($_POST['return_to_url']);
910  else
911  $this->view();
912  }
913 
917  function confirm()
918  {
919  global $tree, $rbacsystem, $rbacadmin;
920  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
921  if (!isset($_SESSION["saved_post"]))
922  {
923  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
924  }
925 
926  // FOR ALL SELECTED OBJECTS
927  foreach ($_SESSION["saved_post"] as $id)
928  {
929  $type = ilBookmark::_getTypeOfId($id);
930 
931  // get node data and subtree nodes
932  if ($this->tree->isInTree($id))
933  {
934  $node_data = $this->tree->getNodeData($id);
935  $subtree_nodes = $this->tree->getSubTree($node_data);
936  }
937  else
938  {
939  continue;
940  }
941 
942  // delete tree
943  $this->tree->deleteTree($node_data);
944 
945  // delete objects of subtree nodes
946  foreach ($subtree_nodes as $node)
947  {
948  switch ($node["type"])
949  {
950  case "bmf":
951  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
952  $BookmarkFolder->delete();
953  break;
954 
955  case "bm":
956  $Bookmark = new ilBookmark($node["obj_id"]);
957  $Bookmark->delete();
958  break;
959  }
960  }
961  }
962 
963  // Feedback
964  ilUtil::sendSuccess($this->lng->txt("info_deleted"),true);
965 
966  $this->view();
967  }
968 
969 
974  {
975  $actions = array(
976  "delete"=>$this->lng->txt("delete"),
977  "export"=>$this->lng->txt("export"),
978  "sendmail"=>$this->lng->txt("bkm_sendmail"),
979  );
980 
981  $subobj = array("bm", "bmf");
982 
983  if (is_array($subobj))
984  {
985  //build form
986  $opts = ilUtil::formSelect("","type",$subobj);
987 
988  $this->tpl->setCurrentBlock("add_object");
989  $this->tpl->setVariable("COLUMN_COUNTS", 7);
990  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
991  $this->tpl->setVariable("BTN_NAME", "newForm");
992  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
993  $this->tpl->parseCurrentBlock();
994  }
995 
996  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
997 
998  $this->tpl->setCurrentBlock("tbl_action_select");
999  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
1000  $this->tpl->setVariable("BTN_NAME","executeAction");
1001  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
1002 
1003  /*
1004  $this->tpl->setVariable("BTN_NAME","delete");
1005  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
1006  $this->tpl->parseCurrentBlock();
1007 
1008  $this->tpl->setVariable("BTN_NAME","export");
1009  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
1010  $this->tpl->parseCurrentBlock();
1011  */
1012  $this->tpl->parseCurrentBlock();
1013 
1014  }
1015 
1019  function &getHTML()
1020  {
1021  include_once("./Services/PersonalDesktop/classes/class.ilBookmarkBlockGUI.php");
1022  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
1023 
1024  return $bookmark_block_gui->getHTML();
1025  }
1026 
1034  function importFile()
1035  {
1036  if (!$this->tree->isInTree($this->id))
1037  {
1038  $this->ctrl->setParameter($this, 'bmf_id', '');
1039  $this->ctrl->redirect($this);
1040  }
1041 
1042  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
1043  {
1044  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1045  $this->newFormBookmark();
1046  return;
1047  }
1048  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
1049  $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
1050  if ($objects===false)
1051  {
1052  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1053  $this->newFormBookmark();
1054  return;
1055  }
1056  // holds the number of created objects
1057  $num_create=array('bm'=>0,'bmf'=>0);
1058  $this->__importBookmarks($objects,$num_create,$this->id,0);
1059 
1060  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
1061  $num_create[ 'bmf']));
1062  $this->view();
1063 
1064 
1065  }
1074  function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
1075  {
1076  if (is_array($objects[$start_key]))
1077  {
1078  foreach ($objects[$start_key] as $obj_key=>$object)
1079  {
1080  switch ($object['type'])
1081  {
1082  case 'bm':
1083  if (!$object["title"]) continue;
1084  if (!$object["target"]) continue;
1085  $bm = new ilBookmark();
1086  $bm->setTitle($object["title"]);
1087  $bm->setDescription($object["description"]);
1088  $bm->setTarget($object["target"]);
1089  $bm->setParent($folder_id);
1090  $bm->create();
1091  $num_create['bm']++;
1092  break;
1093  case 'bmf':
1094  if (!$object["title"]) continue;
1095  $bmf = new ilBookmarkFolder();
1096  $bmf->setTitle($object["title"]);
1097  $bmf->setParent($folder_id);
1098  $bmf->create();
1099  $num_create['bmf']++;
1100  if (is_array($objects[$obj_key]))
1101  {
1102  $this->__importBookmarks($objects,$num_create,
1103  $bmf->getId(),$obj_key);
1104  }
1105  break;
1106  }
1107  }
1108  }
1109  }
1110 
1111 }
1112 ?>