ILIAS  eassessment Revision 61809
 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 
785  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
786  ilUtil::redirect(ilMailFormCall::_getRedirectTarget($this, '', array(), array('type' => 'attach')));
787  }
791  function delete()
792  {
793  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
794  if (!$bm_ids)
795  {
796  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
797  }
798 
799  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
800 
801  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
802  $this->ctrl->setParameter($this, "bmf_id", $this->id);
803  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
804 
805  // output table header
806  $cols = array("type", "title");
807  foreach ($cols as $key)
808  {
809  $this->tpl->setCurrentBlock("table_header");
810  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
811  $this->tpl->parseCurrentBlock();
812  }
813 
814  $_SESSION["saved_post"] = $bm_ids;
815 
816  foreach($bm_ids as $obj_id)
817  {
818  $type = ilBookmark::_getTypeOfId($obj_id);
819 
820  if (!$this->tree->isInTree($obj_id))
821  {
822  continue;
823  }
824  switch($type)
825  {
826  case "bmf":
827  $BookmarkFolder = new ilBookmarkFolder($obj_id);
828  $title = $BookmarkFolder->getTitle();
829  $target = "";
830  unset($BookmarkFolder);
831  break;
832 
833  case "bm":
834  $Bookmark = new ilBookmark($obj_id);
835  $title = $Bookmark->getTitle();
836  $target = $Bookmark->getTarget();
837  unset($Bookmark);
838  break;
839  }
840 
841  // output type icon
842  $this->tpl->setCurrentBlock("table_cell");
843  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
844  $this->tpl->parseCurrentBlock();
845 
846  // output title
847  $this->tpl->setCurrentBlock("table_cell");
848  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
849 
850  // output target
851  if ($target)
852  {
853  $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
854  $target,$this->textwidth, true)));
855  }
856  $this->tpl->parseCurrentBlock();
857 
858  // output table row
859  $this->tpl->setCurrentBlock("table_row");
860  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
861  $this->tpl->parseCurrentBlock();
862  }
863 
864  // cancel and confirm button
865  $buttons = array( "cancel" => $this->lng->txt("cancel"),
866  "confirm" => $this->lng->txt("confirm"));
867 
868  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
869  foreach($buttons as $name => $value)
870  {
871  $this->tpl->setCurrentBlock("operation_btn");
872  $this->tpl->setVariable("BTN_NAME",$name);
873  $this->tpl->setVariable("BTN_VALUE",$value);
874  $this->tpl->parseCurrentBlock();
875  }
876  }
877 
881  function cancel()
882  {
883  session_unregister("saved_post");
884  if ($_POST['return_to'])
885  ilUtil::redirect($_POST['return_to_url']);
886  else
887  $this->view();
888  }
889 
893  function confirm()
894  {
895  global $tree, $rbacsystem, $rbacadmin;
896  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
897  if (!isset($_SESSION["saved_post"]))
898  {
899  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
900  }
901 
902  // FOR ALL SELECTED OBJECTS
903  foreach ($_SESSION["saved_post"] as $id)
904  {
906 
907  // get node data and subtree nodes
908  if ($this->tree->isInTree($id))
909  {
910  $node_data = $this->tree->getNodeData($id);
911  $subtree_nodes = $this->tree->getSubTree($node_data);
912  }
913  else
914  {
915  continue;
916  }
917 
918  // delete tree
919  $this->tree->deleteTree($node_data);
920 
921  // delete objects of subtree nodes
922  foreach ($subtree_nodes as $node)
923  {
924  switch ($node["type"])
925  {
926  case "bmf":
927  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
928  $BookmarkFolder->delete();
929  break;
930 
931  case "bm":
932  $Bookmark = new ilBookmark($node["obj_id"]);
933  $Bookmark->delete();
934  break;
935  }
936  }
937  }
938 
939  // Feedback
940  ilUtil::sendSuccess($this->lng->txt("info_deleted"),true);
941 
942  $this->view();
943  }
944 
945 
950  {
951  $actions = array(
952  "delete"=>$this->lng->txt("delete"),
953  "export"=>$this->lng->txt("export"),
954  "sendmail"=>$this->lng->txt("bkm_sendmail"),
955  );
956 
957  $subobj = array("bm", "bmf");
958 
959  if (is_array($subobj))
960  {
961  //build form
962  $opts = ilUtil::formSelect("","type",$subobj);
963 
964  $this->tpl->setCurrentBlock("add_object");
965  $this->tpl->setVariable("COLUMN_COUNTS", 7);
966  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
967  $this->tpl->setVariable("BTN_NAME", "newForm");
968  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
969  $this->tpl->parseCurrentBlock();
970  }
971 
972  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
973 
974  $this->tpl->setCurrentBlock("tbl_action_select");
975  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
976  $this->tpl->setVariable("BTN_NAME","executeAction");
977  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
978 
979  /*
980  $this->tpl->setVariable("BTN_NAME","delete");
981  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
982  $this->tpl->parseCurrentBlock();
983 
984  $this->tpl->setVariable("BTN_NAME","export");
985  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
986  $this->tpl->parseCurrentBlock();
987  */
988  $this->tpl->parseCurrentBlock();
989 
990  }
991 
995  function &getHTML()
996  {
997  include_once("./Services/PersonalDesktop/classes/class.ilBookmarkBlockGUI.php");
998  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
999 
1000  return $bookmark_block_gui->getHTML();
1001  }
1002 
1010  function importFile()
1011  {
1012  if (!$this->tree->isInTree($this->id))
1013  {
1014  return;
1015  }
1016 
1017  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
1018  {
1019  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1020  $this->newFormBookmark();
1021  return;
1022  }
1023  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
1024  $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
1025  if ($objects===false)
1026  {
1027  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1028  $this->newFormBookmark();
1029  return;
1030  }
1031  // holds the number of created objects
1032  $num_create=array('bm'=>0,'bmf'=>0);
1033  $this->__importBookmarks($objects,$num_create,$this->id,0);
1034 
1035  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
1036  $num_create[ 'bmf']));
1037  $this->view();
1038 
1039 
1040  }
1049  function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
1050  {
1051  if (is_array($objects[$start_key]))
1052  {
1053  foreach ($objects[$start_key] as $obj_key=>$object)
1054  {
1055  switch ($object['type'])
1056  {
1057  case 'bm':
1058  if (!$object["title"]) continue;
1059  if (!$object["target"]) continue;
1060  $bm = new ilBookmark();
1061  $bm->setTitle($object["title"]);
1062  $bm->setDescription($object["description"]);
1063  $bm->setTarget($object["target"]);
1064  $bm->setParent($folder_id);
1065  $bm->create();
1066  $num_create['bm']++;
1067  break;
1068  case 'bmf':
1069  if (!$object["title"]) continue;
1070  $bmf = new ilBookmarkFolder();
1071  $bmf->setTitle($object["title"]);
1072  $bmf->setParent($folder_id);
1073  $bmf->create();
1074  $num_create['bmf']++;
1075  if (is_array($objects[$obj_key]))
1076  {
1077  $this->__importBookmarks($objects,$num_create,
1078  $bmf->getId(),$obj_key);
1079  }
1080  break;
1081  }
1082  }
1083  }
1084  }
1085 
1086 }
1087 ?>