ILIAS  Release_4_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-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  // $this->lng->txt("personal_desktop"));
203  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
204  "");
205  $this->tpl->setTitle($this->lng->txt("personal_desktop"));
206  }
207 
208  /*
209  * display content of bookmark folder
210  */
211  function view()
212  {
213  global $tree, $ilCtrl;
214 
215  include_once("classes/class.ilFrameTargetInfo.php");
216 
217  if ($this->id > 0 && !$this->tree->isInTree($this->id))
218  {
219  return;
220  }
221 
222  $mtree = new ilTree($_SESSION["AccountId"]);
223  $mtree->setTableNames('bookmark_tree','bookmark_data');
224 
225  $objects = ilBookmarkFolder::getObjects($this->id);
226 
227  $s_mode = ($this->mode == "tree")
228  ? "flat"
229  : "tree";
230 
231 // $this->tpl->setTreeFlatIcon($this->ctrl->getLinkTarget($this)."&set_mode=".$s_mode,
232 // $s_mode);
233 
234  include_once 'Services/PersonalDesktop/classes/class.ilBookmarkAdministrationTableGUI.php';
235  $table = new ilBookmarkAdministrationTableGUI($this);
236  $table->setId('bookmark_adm_table');
237  /*
238  // return to parent folder
239  // disabled
240  if ($this->id != $mtree->readRootId() || $this->id =="")
241  {
242  $ilCtrl->setParameter($this, "bmf_id", $mtree->getParentId($this->id));
243  $objects = array_merge
244  (
245  array
246  (
247  array
248  (
249  "title" => "..",
250  "target" => $ilCtrl->getLinkTarget($this),
251  "type" => 'parent',
252  "obj_id" => $mtree->getParentId($this->id),
253  )
254  ),
255  $objects
256  );
257  }
258  */
259  $table->setData($objects);
260  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
261  }
262 
266  function add_cell($val, $link = "")
267  {
268  if (!empty($link))
269  {
270  $this->tpl->setCurrentBlock("begin_link");
271  $this->tpl->setVariable("LINK_TARGET", $link);
272  $this->tpl->parseCurrentBlock();
273  $this->tpl->touchBlock("end_link");
274  }
275 
276  $this->tpl->setCurrentBlock("text");
277  $this->tpl->setVariable("TEXT_CONTENT", $val);
278  $this->tpl->parseCurrentBlock();
279  $this->tpl->setCurrentBlock("table_cell");
280  $this->tpl->parseCurrentBlock();
281  }
282 
286  function displayLocator()
287  {
288  global $lng;
289 
290  if (empty($this->id))
291  {
292  return;
293  }
294 
295  if (!$this->tree->isInTree($this->id))
296  {
297  return;
298  }
299 
300  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
301 
302  $path = $this->tree->getPathFull($this->id);
303 //print_r($path);
304  $modifier = 1;
305 
306 return;
307  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
308  $this->tpl->touchBlock("locator_separator");
309  $this->tpl->touchBlock("locator_item");
310  //$this->tpl->setCurrentBlock("locator_item");
311  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
312  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
313  //$this->tpl->setVariable("LINK_TARGET","target=\"".
314  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
315  //$this->tpl->parseCurrentBlock();
316 
317  foreach ($path as $key => $row)
318  {
319  if ($key < count($path)-$modifier)
320  {
321  $this->tpl->touchBlock("locator_separator");
322  }
323 
324  $this->tpl->setCurrentBlock("locator_item");
325  $title = ($row["child"] == 1) ?
326  $lng->txt("bookmarks") :
327  $row["title"];
328  $this->tpl->setVariable("ITEM", $title);
329  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
330  $this->tpl->setVariable("LINK_ITEM",
331  $this->ctrl->getLinkTarget($this));
332  $this->tpl->parseCurrentBlock();
333  }
334 
335  $this->tpl->setCurrentBlock("locator");
336 
337  $this->tpl->parseCurrentBlock();
338  }
339 
343  function newForm($type)
344  {
345  if (!$type)
346  $type = $_POST["type"];
347  switch($type)
348  {
349  case "bmf":
350  $this->newFormBookmarkFolder();
351  break;
352 
353  case "bm":
354  $this->newFormBookmark();
355  break;
356  }
357  }
358 
363  {
364  if (!$this->tree->isInTree($this->id))
365  {
366  return;
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  return;
384  }
385 
386  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
387  $form = new ilPropertyFormGUI();
388  $form->setTopAnchor("bookmark_top");
389 
390  $form->setTitle($lng->txt("bookmark_folder_new"));
391 
392  if ($action == 'updateBookmarkFolder')
393  {
394  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
395  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
396  }
397 
398  $hash = ($ilUser->prefs["screen_reader_optimization"])
399  ? "bookmark_top"
400  : "";
401 
402  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
403 
404  $ilCtrl->clearParameters($this);
405 
406  // title
407  $prop = new ilTextInputGUI($lng->txt("title"), "title");
408  $prop->setRequired(true);
409  $form->addItem($prop);
410 
411  // buttons
412  $form->addCommandButton($action, $lng->txt('save'));
413  $form->addCommandButton('cancel', $lng->txt('cancel'));
414  return $form;
415  }
416 
421  {
422  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
423  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
424  $form->setValuesByArray
425  (
426  array
427  (
428  "title" => $this->get_last("title", $bmf->getTitle()),
429  "obj_id" => $_GET["obj_id"],
430  )
431  );
432  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
433  }
434 
435 
440  private function initFormBookmark($action = 'createBookmark')
441  {
442  global $lng, $ilCtrl, $ilUser;
443 
444  if (!$this->tree->isInTree($this->id))
445  {
446  return;
447  }
448 
449  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
450  $form = new ilPropertyFormGUI();
451  $form->setTopAnchor("bookmark_top");
452 
453  $form->setTitle($lng->txt("bookmark_new"));
454 
455  if ($action == 'updateBookmark')
456  {
457  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
458  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
459  }
460 
461  $hash = ($ilUser->prefs["screen_reader_optimization"])
462  ? "bookmark_top"
463  : "";
464 
465  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
466  $ilCtrl->clearParameters($this);
467  // title
468  $prop = new ilTextInputGUI($lng->txt("title"), "title");
469  $prop->setValue($_GET['bm_title']);
470  $prop->setRequired(true);
471  $form->addItem($prop);
472 
473  // description
474  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
475  $form->addItem($prop);
476 
477  // target link
478  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
479  $prop->setValue($_GET['bm_link']);
480  $prop->setRequired(true);
481  $form->addItem($prop);
482 
483  // hidden redirect field
484  if ($_GET['return_to'])
485  {
486  $prop = new ilHiddenInputGUI('return_to');
487  $prop->setValue($_GET['return_to']);
488  $form->addItem($prop);
489 
490  $prop = new ilHiddenInputGUI('return_to_url');
491  if ($_GET['return_to_url'])
492  $prop->setValue($_GET['return_to_url']);
493  else
494  $prop->setValue($_GET['bm_link']);
495  $form->addItem($prop);
496  }
497 
498  // buttons
499  $form->addCommandButton($action, $lng->txt('save'));
500  $form->addCommandButton('cancel', $lng->txt('cancel'));
501 
502  // keep imports?
503  /*
504  $this->tpl->setCurrentBlock('bkm_import');
505  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
506  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
507  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
508  $this->tpl->parseCurrentBlock();
509  //vd($_POST);
510  */
511 
512  return $form;
513  }
514 
519  private function initImportBookmarksForm()
520  {
521  global $lng, $ilCtrl, $ilUser;
522 
523  if (!$this->tree->isInTree($this->id))
524  {
525  return;
526  }
527 
528  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
529  $form = new ilPropertyFormGUI();
530  $form->setTopAnchor("bookmark_top");
531  $form->setTitle($lng->txt("bkm_import"));
532 
533  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
534  $fi->setRequired(true);
535  $form->addItem($fi);
536 
537  $form->addCommandButton("importFile", $lng->txt('import'));
538  $form->addCommandButton('cancel', $lng->txt('cancel'));
539 
540  return $form;
541  }
542 
546  function newFormBookmark()
547  {
548  $form = $this->initFormBookmark();
549  $html1 = $form->getHTML();
550  $html2 = '';
551  if (!$_REQUEST["bm_link"])
552  {
553  $form2 = $this->initImportBookmarksForm();
554  $html2 = "<br />" . $form2->getHTML();
555  }
556  $this->tpl->setVariable("ADM_CONTENT", $html1.$html2);
557  }
558 
559 
563  function get_last($a_var, $a_value)
564  {
565  return (!empty($_POST[$a_var])) ?
566  ilUtil::prepareFormOutput(($_POST[$a_var]),true) :
567  ilUtil::prepareFormOutput($a_value);
568  }
569 
573  function editFormBookmark()
574  {
575  global $lng, $ilCtrl;
576  if (!$this->tree->isInTree($_GET["obj_id"]))
577  {
578  return;
579  }
580  $form = $this->initFormBookmark('updateBookmark');
581  $bookmark = new ilBookmark($_GET["obj_id"]);
582  $form->setValuesByArray
583  (
584  array
585  (
586  "title" => $bookmark->getTitle(),
587  "target" => $bookmark->getTarget(),
588  "description" => $bookmark->getDescription(),
589  "obj_id" => $_GET["obj_id"],
590  )
591  );
592  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
593  }
594 
595 
600  {
601  if (!$this->tree->isInTree($this->id))
602  {
603  return;
604  }
605 
606  // check title
607  if (empty($_POST["title"]))
608  {
609  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
610  $this->newFormBookmarkFolder();
611  }
612  else
613  {
614  // create bookmark folder
615  $bmf = new ilBookmarkFolder();
616  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
617  $bmf->setParent($this->id);
618  $bmf->create();
619 
620  $this->view();
621  }
622  }
623 
624 
629  {
630  if (!$this->tree->isInTree($_GET["obj_id"]))
631  {
632  return;
633  }
634 
635  // check title
636  if (empty($_POST["title"]))
637  {
638  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
639  $this->editFormBookmarkFolder();
640  }
641  else
642  {
643  // update bookmark folder
644  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
645  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
646  $bmf->update();
647 
648  $this->view();
649  }
650  }
651 
652 
656  function createBookmark()
657  {
658  global $lng;
659  if (!$this->tree->isInTree($this->id))
660  {
661  return;
662  }
663 
664  // check title and target
665  if (empty($_POST["title"]))
666  {
667  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
668  $this->newFormBookmark();
669  }
670  else if (empty($_POST["target"]))
671  {
672  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
673  $this->newFormBookmark();
674  }
675  else
676  {
677  // create bookmark
678  $bm = new ilBookmark();
679  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
680  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
681  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
682  $bm->setParent($this->id);
683  $bm->create();
684 
685  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
686 
687  if ($_POST['return_to'])
688  ilUtil::redirect($_POST['return_to_url']);
689  else
690  $this->view();
691  }
692  }
693 
697  function updateBookmark()
698  {
699  if (!$this->tree->isInTree($_GET["obj_id"]))
700  {
701  return;
702  }
703 
704  // check title and target
705  if (empty($_POST["title"]))
706  {
707  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
708  $this->editFormBookmark();
709  }
710  else if (empty($_POST["target"]))
711  {
712  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
713  $this->editFormBookmark();
714  }
715  else
716  {
717  // update bookmark
718  $bm = new ilBookmark($_GET["obj_id"]);
719  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
720  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
721  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
722  $bm->update();
723 
724  $this->view();
725  }
726  }
727 
731  function export($deliver=true)
732  {
733  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
734  if (!$bm_ids)
735  {
736  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
737  }
738  $export_ids=array();
739  foreach($bm_ids as $id)
740  {
741  if ($this->tree->isInTree($id))
742  {
743  //list($type, $obj_id) = explode(":", $id);
744  //$export_ids[]=$obj_id;
745  $export_ids[]=$id;
746  }
747  }
748 
749  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
750  $html_content=ilBookmarkImportExport::_exportBookmark ($export_ids,true,
751  $this->lng->txt("bookmarks_of")." ".$this->ilias->account->getFullname());
752 
753  if ($deliver)
754  {
755  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
756  }
757  else
758  {
759  return $html_content;
760  }
761  }
765  function sendmail()
766  {
767  global $ilUser;
768  include_once 'classes/class.ilFileDataMail.php';
769  require_once "Services/Mail/classes/class.ilFormatMail.php";
770  $mfile = new ilFileDataMail($ilUser->getId());
771  $umail = new ilFormatMail($ilUser->getId());
772 
773  $html_content=$this->export(false);
774  $tempfile=ilUtil::ilTempnam();
775  $fp=fopen($tempfile,'w');
776  fwrite($fp, $html_content);
777  fclose($fp);
778  $filename='bookmarks.html';
779  $mfile->copyAttachmentFile($tempfile,$filename);
780  $umail->savePostData($ilUser->getId(),array($filename),
781  '','','','','',
782  '',
783  '', 0);
784  ilUtil::redirect('ilias.php?baseClass=ilMailGUI&type=attach');
785  }
789  function delete()
790  {
791  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
792  if (!$bm_ids)
793  {
794  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
795  }
796 
797  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
798 
799  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
800  $this->ctrl->setParameter($this, "bmf_id", $this->id);
801  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
802 
803  // output table header
804  $cols = array("type", "title");
805  foreach ($cols as $key)
806  {
807  $this->tpl->setCurrentBlock("table_header");
808  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
809  $this->tpl->parseCurrentBlock();
810  }
811 
812  $_SESSION["saved_post"] = $bm_ids;
813 
814  foreach($bm_ids as $obj_id)
815  {
816  $type = ilBookmark::_getTypeOfId($obj_id);
817 
818  if (!$this->tree->isInTree($obj_id))
819  {
820  continue;
821  }
822  switch($type)
823  {
824  case "bmf":
825  $BookmarkFolder = new ilBookmarkFolder($obj_id);
826  $title = $BookmarkFolder->getTitle();
827  $target = "";
828  unset($BookmarkFolder);
829  break;
830 
831  case "bm":
832  $Bookmark = new ilBookmark($obj_id);
833  $title = $Bookmark->getTitle();
834  $target = $Bookmark->getTarget();
835  unset($Bookmark);
836  break;
837  }
838 
839  // output type icon
840  $this->tpl->setCurrentBlock("table_cell");
841  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
842  $this->tpl->parseCurrentBlock();
843 
844  // output title
845  $this->tpl->setCurrentBlock("table_cell");
846  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
847 
848  // output target
849  if ($target)
850  {
851  $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
852  $target,$this->textwidth, true)));
853  }
854  $this->tpl->parseCurrentBlock();
855 
856  // output table row
857  $this->tpl->setCurrentBlock("table_row");
858  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
859  $this->tpl->parseCurrentBlock();
860  }
861 
862  // cancel and confirm button
863  $buttons = array( "cancel" => $this->lng->txt("cancel"),
864  "confirm" => $this->lng->txt("confirm"));
865 
866  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
867  foreach($buttons as $name => $value)
868  {
869  $this->tpl->setCurrentBlock("operation_btn");
870  $this->tpl->setVariable("BTN_NAME",$name);
871  $this->tpl->setVariable("BTN_VALUE",$value);
872  $this->tpl->parseCurrentBlock();
873  }
874  }
875 
879  function cancel()
880  {
881  session_unregister("saved_post");
882  if ($_POST['return_to'])
883  ilUtil::redirect($_POST['return_to_url']);
884  else
885  $this->view();
886  }
887 
891  function confirm()
892  {
893  global $tree, $rbacsystem, $rbacadmin;
894  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
895  if (!isset($_SESSION["saved_post"]))
896  {
897  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
898  }
899 
900  // FOR ALL SELECTED OBJECTS
901  foreach ($_SESSION["saved_post"] as $id)
902  {
904 
905  // get node data and subtree nodes
906  if ($this->tree->isInTree($id))
907  {
908  $node_data = $this->tree->getNodeData($id);
909  $subtree_nodes = $this->tree->getSubTree($node_data);
910  }
911  else
912  {
913  continue;
914  }
915 
916  // delete tree
917  $this->tree->deleteTree($node_data);
918 
919  // delete objects of subtree nodes
920  foreach ($subtree_nodes as $node)
921  {
922  switch ($node["type"])
923  {
924  case "bmf":
925  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
926  $BookmarkFolder->delete();
927  break;
928 
929  case "bm":
930  $Bookmark = new ilBookmark($node["obj_id"]);
931  $Bookmark->delete();
932  break;
933  }
934  }
935  }
936 
937  // Feedback
938  ilUtil::sendSuccess($this->lng->txt("info_deleted"),true);
939 
940  $this->view();
941  }
942 
943 
948  {
949  $actions = array(
950  "delete"=>$this->lng->txt("delete"),
951  "export"=>$this->lng->txt("export"),
952  "sendmail"=>$this->lng->txt("bkm_sendmail"),
953  );
954 
955  $subobj = array("bm", "bmf");
956 
957  if (is_array($subobj))
958  {
959  //build form
960  $opts = ilUtil::formSelect("","type",$subobj);
961 
962  $this->tpl->setCurrentBlock("add_object");
963  $this->tpl->setVariable("COLUMN_COUNTS", 7);
964  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
965  $this->tpl->setVariable("BTN_NAME", "newForm");
966  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
967  $this->tpl->parseCurrentBlock();
968  }
969 
970  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
971 
972  $this->tpl->setCurrentBlock("tbl_action_select");
973  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
974  $this->tpl->setVariable("BTN_NAME","executeAction");
975  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
976 
977  /*
978  $this->tpl->setVariable("BTN_NAME","delete");
979  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
980  $this->tpl->parseCurrentBlock();
981 
982  $this->tpl->setVariable("BTN_NAME","export");
983  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
984  $this->tpl->parseCurrentBlock();
985  */
986  $this->tpl->parseCurrentBlock();
987 
988  }
989 
993  function &getHTML()
994  {
995  include_once("./Services/PersonalDesktop/classes/class.ilBookmarkBlockGUI.php");
996  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
997 
998  return $bookmark_block_gui->getHTML();
999  }
1000 
1008  function importFile()
1009  {
1010  if (!$this->tree->isInTree($this->id))
1011  {
1012  return;
1013  }
1014 
1015  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
1016  {
1017  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1018  $this->newFormBookmark();
1019  return;
1020  }
1021  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
1022  $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
1023  if ($objects===false)
1024  {
1025  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1026  $this->newFormBookmark();
1027  return;
1028  }
1029  // holds the number of created objects
1030  $num_create=array('bm'=>0,'bmf'=>0);
1031  $this->__importBookmarks($objects,$num_create,$this->id,0);
1032 
1033  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
1034  $num_create[ 'bmf']));
1035  $this->view();
1036 
1037 
1038  }
1047  function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
1048  {
1049  if (is_array($objects[$start_key]))
1050  {
1051  foreach ($objects[$start_key] as $obj_key=>$object)
1052  {
1053  switch ($object['type'])
1054  {
1055  case 'bm':
1056  if (!$object["title"]) continue;
1057  if (!$object["target"]) continue;
1058  $bm = new ilBookmark();
1059  $bm->setTitle($object["title"]);
1060  $bm->setDescription($object["description"]);
1061  $bm->setTarget($object["target"]);
1062  $bm->setParent($folder_id);
1063  $bm->create();
1064  $num_create['bm']++;
1065  break;
1066  case 'bmf':
1067  if (!$object["title"]) continue;
1068  $bmf = new ilBookmarkFolder();
1069  $bmf->setTitle($object["title"]);
1070  $bmf->setParent($folder_id);
1071  $bmf->create();
1072  $num_create['bmf']++;
1073  if (is_array($objects[$obj_key]))
1074  {
1075  $this->__importBookmarks($objects,$num_create,
1076  $bmf->getId(),$obj_key);
1077  }
1078  break;
1079  }
1080  }
1081  }
1082  }
1083 
1084 }
1085 ?>