ILIAS  Release_4_1_x_branch Revision 61804
 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  if(!$this->tree->isInTree($_GET["obj_id"]))
423  {
424  return;
425  }
426 
427  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
428  $form = $this->initFormBookmarkFolder('updateBookmarkFolder', $this->id);
429  $form->setValuesByArray
430  (
431  array
432  (
433  "title" => $this->get_last("title", $bmf->getTitle()),
434  "obj_id" => $_GET["obj_id"],
435  )
436  );
437  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
438  }
439 
440 
445  private function initFormBookmark($action = 'createBookmark')
446  {
447  global $lng, $ilCtrl, $ilUser;
448 
449  if (!$this->tree->isInTree($this->id))
450  {
451  return;
452  }
453 
454  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
455  $form = new ilPropertyFormGUI();
456  $form->setTopAnchor("bookmark_top");
457 
458  $form->setTitle($lng->txt("bookmark_new"));
459 
460  if ($action == 'updateBookmark')
461  {
462  $ilCtrl->setParameter($this, 'bmf_id', $this->id);
463  $ilCtrl->setParameter($this, 'obj_id', $_GET["obj_id"]);
464  }
465 
466  $hash = ($ilUser->prefs["screen_reader_optimization"])
467  ? "bookmark_top"
468  : "";
469 
470  $form->setFormAction($ilCtrl->getFormAction($this, $action, $hash));
471  $ilCtrl->clearParameters($this);
472  // title
473  $prop = new ilTextInputGUI($lng->txt("title"), "title");
474  $prop->setValue($_GET['bm_title']);
475  $prop->setRequired(true);
476  $form->addItem($prop);
477 
478  // description
479  $prop = new ilTextAreaInputGUI($lng->txt('description'), 'description');
480  $form->addItem($prop);
481 
482  // target link
483  $prop = new ilTextInputGUI($lng->txt('bookmark_target'), 'target');
484  $prop->setValue($_GET['bm_link']);
485  $prop->setRequired(true);
486  $form->addItem($prop);
487 
488  // hidden redirect field
489  if ($_GET['return_to'])
490  {
491  $prop = new ilHiddenInputGUI('return_to');
492  $prop->setValue($_GET['return_to']);
493  $form->addItem($prop);
494 
495  $prop = new ilHiddenInputGUI('return_to_url');
496  if ($_GET['return_to_url'])
497  $prop->setValue($_GET['return_to_url']);
498  else
499  $prop->setValue($_GET['bm_link']);
500  $form->addItem($prop);
501  }
502 
503  // buttons
504  $form->addCommandButton($action, $lng->txt('save'));
505  $form->addCommandButton('cancel', $lng->txt('cancel'));
506 
507  // keep imports?
508  /*
509  $this->tpl->setCurrentBlock('bkm_import');
510  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
511  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
512  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
513  $this->tpl->parseCurrentBlock();
514  //vd($_POST);
515  */
516 
517  return $form;
518  }
519 
524  private function initImportBookmarksForm()
525  {
526  global $lng, $ilCtrl, $ilUser;
527 
528  if (!$this->tree->isInTree($this->id))
529  {
530  return;
531  }
532 
533  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
534  $form = new ilPropertyFormGUI();
535  $form->setTopAnchor("bookmark_top");
536  $form->setTitle($lng->txt("bkm_import"));
537 
538  $fi = new ilFileInputGUI($lng->txt("file_add"), "bkmfile");
539  $fi->setRequired(true);
540  $form->addItem($fi);
541 
542  $form->addCommandButton("importFile", $lng->txt('import'));
543  $form->addCommandButton('cancel', $lng->txt('cancel'));
544 
545  return $form;
546  }
547 
551  function newFormBookmark()
552  {
553  $form = $this->initFormBookmark();
554  $html1 = $form->getHTML();
555  $html2 = '';
556  if (!$_REQUEST["bm_link"])
557  {
558  $form2 = $this->initImportBookmarksForm();
559  $html2 = "<br />" . $form2->getHTML();
560  }
561  $this->tpl->setVariable("ADM_CONTENT", $html1.$html2);
562  }
563 
564 
568  function get_last($a_var, $a_value)
569  {
570  return (!empty($_POST[$a_var])) ?
571  ilUtil::prepareFormOutput(($_POST[$a_var]),true) :
572  ilUtil::prepareFormOutput($a_value);
573  }
574 
578  function editFormBookmark()
579  {
580  global $lng, $ilCtrl;
581  if (!$this->tree->isInTree($_GET["obj_id"]))
582  {
583  return;
584  }
585  $form = $this->initFormBookmark('updateBookmark');
586  $bookmark = new ilBookmark($_GET["obj_id"]);
587  $form->setValuesByArray
588  (
589  array
590  (
591  "title" => $bookmark->getTitle(),
592  "target" => $bookmark->getTarget(),
593  "description" => $bookmark->getDescription(),
594  "obj_id" => $_GET["obj_id"],
595  )
596  );
597  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
598  }
599 
600 
605  {
606  if (!$this->tree->isInTree($this->id))
607  {
608  return;
609  }
610 
611  // check title
612  if (empty($_POST["title"]))
613  {
614  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
615  $this->newFormBookmarkFolder();
616  }
617  else
618  {
619  // create bookmark folder
620  $bmf = new ilBookmarkFolder();
621  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
622  $bmf->setParent($this->id);
623  $bmf->create();
624 
625  $this->view();
626  }
627  }
628 
629 
634  {
635  if (!$this->tree->isInTree($_GET["obj_id"]))
636  {
637  return;
638  }
639 
640  // check title
641  if (empty($_POST["title"]))
642  {
643  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
644  $this->editFormBookmarkFolder();
645  }
646  else
647  {
648  // update bookmark folder
649  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
650  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
651  $bmf->update();
652 
653  $this->view();
654  }
655  }
656 
657 
661  function createBookmark()
662  {
663  global $lng;
664  if (!$this->tree->isInTree($this->id))
665  {
666  return;
667  }
668 
669  // check title and target
670  if (empty($_POST["title"]))
671  {
672  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
673  $this->newFormBookmark();
674  }
675  else if (empty($_POST["target"]))
676  {
677  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
678  $this->newFormBookmark();
679  }
680  else
681  {
682  // create bookmark
683  $bm = new ilBookmark();
684  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
685  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
686  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
687  $bm->setParent($this->id);
688  $bm->create();
689 
690  ilUtil::sendInfo($lng->txt('bookmark_added'), true);
691 
692  if ($_POST['return_to'])
693  ilUtil::redirect($_POST['return_to_url']);
694  else
695  $this->view();
696  }
697  }
698 
702  function updateBookmark()
703  {
704  if (!$this->tree->isInTree($_GET["obj_id"]))
705  {
706  return;
707  }
708 
709  // check title and target
710  if (empty($_POST["title"]))
711  {
712  ilUtil::sendFailure($this->lng->txt("please_enter_title"));
713  $this->editFormBookmark();
714  }
715  else if (empty($_POST["target"]))
716  {
717  ilUtil::sendFailure($this->lng->txt("please_enter_target"));
718  $this->editFormBookmark();
719  }
720  else
721  {
722  // update bookmark
723  $bm = new ilBookmark($_GET["obj_id"]);
724  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
725  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
726  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
727  $bm->update();
728 
729  $this->view();
730  }
731  }
732 
736  function export($deliver=true)
737  {
738  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
739  if (!$bm_ids)
740  {
741  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
742  }
743  $export_ids=array();
744  foreach($bm_ids as $id)
745  {
746  if ($this->tree->isInTree($id))
747  {
748  //list($type, $obj_id) = explode(":", $id);
749  //$export_ids[]=$obj_id;
750  $export_ids[]=$id;
751  }
752  }
753 
754  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
755  $html_content=ilBookmarkImportExport::_exportBookmark ($export_ids,true,
756  $this->lng->txt("bookmarks_of")." ".$this->ilias->account->getFullname());
757 
758  if ($deliver)
759  {
760  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
761  }
762  else
763  {
764  return $html_content;
765  }
766  }
770  function sendmail()
771  {
772  global $ilUser;
773  include_once 'classes/class.ilFileDataMail.php';
774  require_once "Services/Mail/classes/class.ilFormatMail.php";
775  $mfile = new ilFileDataMail($ilUser->getId());
776  $umail = new ilFormatMail($ilUser->getId());
777 
778  $html_content=$this->export(false);
779  $tempfile=ilUtil::ilTempnam();
780  $fp=fopen($tempfile,'w');
781  fwrite($fp, $html_content);
782  fclose($fp);
783  $filename='bookmarks.html';
784  $mfile->copyAttachmentFile($tempfile,$filename);
785  $umail->savePostData($ilUser->getId(),array($filename),
786  '','','','','',
787  '',
788  '', 0);
789 
790  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
791  ilUtil::redirect(ilMailFormCall::_getRedirectTarget($this, '', array(), array('type' => 'attach')));
792  }
796  function delete()
797  {
798  $bm_ids = $_GET['bm_id'] ? array($_GET['bm_id']) : $_POST['bm_id'];
799  if (!$bm_ids)
800  {
801  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
802  }
803 
804  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
805 
806  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
807  $this->ctrl->setParameter($this, "bmf_id", $this->id);
808  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
809 
810  // output table header
811  $cols = array("type", "title");
812  foreach ($cols as $key)
813  {
814  $this->tpl->setCurrentBlock("table_header");
815  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
816  $this->tpl->parseCurrentBlock();
817  }
818 
819  $_SESSION["saved_post"] = $bm_ids;
820 
821  foreach($bm_ids as $obj_id)
822  {
823  $type = ilBookmark::_getTypeOfId($obj_id);
824 
825  if (!$this->tree->isInTree($obj_id))
826  {
827  continue;
828  }
829  switch($type)
830  {
831  case "bmf":
832  $BookmarkFolder = new ilBookmarkFolder($obj_id);
833  $title = $BookmarkFolder->getTitle();
834  $target = "";
835  unset($BookmarkFolder);
836  break;
837 
838  case "bm":
839  $Bookmark = new ilBookmark($obj_id);
840  $title = $Bookmark->getTitle();
841  $target = $Bookmark->getTarget();
842  unset($Bookmark);
843  break;
844  }
845 
846  // output type icon
847  $this->tpl->setCurrentBlock("table_cell");
848  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
849  $this->tpl->parseCurrentBlock();
850 
851  // output title
852  $this->tpl->setCurrentBlock("table_cell");
853  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
854 
855  // output target
856  if ($target)
857  {
858  $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
859  $target,$this->textwidth, true)));
860  }
861  $this->tpl->parseCurrentBlock();
862 
863  // output table row
864  $this->tpl->setCurrentBlock("table_row");
865  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
866  $this->tpl->parseCurrentBlock();
867  }
868 
869  // cancel and confirm button
870  $buttons = array( "cancel" => $this->lng->txt("cancel"),
871  "confirm" => $this->lng->txt("confirm"));
872 
873  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
874  foreach($buttons as $name => $value)
875  {
876  $this->tpl->setCurrentBlock("operation_btn");
877  $this->tpl->setVariable("BTN_NAME",$name);
878  $this->tpl->setVariable("BTN_VALUE",$value);
879  $this->tpl->parseCurrentBlock();
880  }
881  }
882 
886  function cancel()
887  {
888  session_unregister("saved_post");
889  if ($_POST['return_to'])
890  ilUtil::redirect($_POST['return_to_url']);
891  else
892  $this->view();
893  }
894 
898  function confirm()
899  {
900  global $tree, $rbacsystem, $rbacadmin;
901  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
902  if (!isset($_SESSION["saved_post"]))
903  {
904  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
905  }
906 
907  // FOR ALL SELECTED OBJECTS
908  foreach ($_SESSION["saved_post"] as $id)
909  {
910  $type = ilBookmark::_getTypeOfId($id);
911 
912  // get node data and subtree nodes
913  if ($this->tree->isInTree($id))
914  {
915  $node_data = $this->tree->getNodeData($id);
916  $subtree_nodes = $this->tree->getSubTree($node_data);
917  }
918  else
919  {
920  continue;
921  }
922 
923  // delete tree
924  $this->tree->deleteTree($node_data);
925 
926  // delete objects of subtree nodes
927  foreach ($subtree_nodes as $node)
928  {
929  switch ($node["type"])
930  {
931  case "bmf":
932  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
933  $BookmarkFolder->delete();
934  break;
935 
936  case "bm":
937  $Bookmark = new ilBookmark($node["obj_id"]);
938  $Bookmark->delete();
939  break;
940  }
941  }
942  }
943 
944  // Feedback
945  ilUtil::sendSuccess($this->lng->txt("info_deleted"),true);
946 
947  $this->view();
948  }
949 
950 
955  {
956  $actions = array(
957  "delete"=>$this->lng->txt("delete"),
958  "export"=>$this->lng->txt("export"),
959  "sendmail"=>$this->lng->txt("bkm_sendmail"),
960  );
961 
962  $subobj = array("bm", "bmf");
963 
964  if (is_array($subobj))
965  {
966  //build form
967  $opts = ilUtil::formSelect("","type",$subobj);
968 
969  $this->tpl->setCurrentBlock("add_object");
970  $this->tpl->setVariable("COLUMN_COUNTS", 7);
971  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
972  $this->tpl->setVariable("BTN_NAME", "newForm");
973  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
974  $this->tpl->parseCurrentBlock();
975  }
976 
977  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
978 
979  $this->tpl->setCurrentBlock("tbl_action_select");
980  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
981  $this->tpl->setVariable("BTN_NAME","executeAction");
982  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
983 
984  /*
985  $this->tpl->setVariable("BTN_NAME","delete");
986  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
987  $this->tpl->parseCurrentBlock();
988 
989  $this->tpl->setVariable("BTN_NAME","export");
990  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
991  $this->tpl->parseCurrentBlock();
992  */
993  $this->tpl->parseCurrentBlock();
994 
995  }
996 
1000  function &getHTML()
1001  {
1002  include_once("./Services/PersonalDesktop/classes/class.ilBookmarkBlockGUI.php");
1003  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
1004 
1005  return $bookmark_block_gui->getHTML();
1006  }
1007 
1015  function importFile()
1016  {
1017  if (!$this->tree->isInTree($this->id))
1018  {
1019  return;
1020  }
1021 
1022  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
1023  {
1024  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1025  $this->newFormBookmark();
1026  return;
1027  }
1028  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
1029  $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
1030  if ($objects===false)
1031  {
1032  ilUtil::sendFailure($this->lng->txt("import_file_not_valid"));
1033  $this->newFormBookmark();
1034  return;
1035  }
1036  // holds the number of created objects
1037  $num_create=array('bm'=>0,'bmf'=>0);
1038  $this->__importBookmarks($objects,$num_create,$this->id,0);
1039 
1040  ilUtil::sendSuccess(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
1041  $num_create[ 'bmf']));
1042  $this->view();
1043 
1044 
1045  }
1054  function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
1055  {
1056  if (is_array($objects[$start_key]))
1057  {
1058  foreach ($objects[$start_key] as $obj_key=>$object)
1059  {
1060  switch ($object['type'])
1061  {
1062  case 'bm':
1063  if (!$object["title"]) continue;
1064  if (!$object["target"]) continue;
1065  $bm = new ilBookmark();
1066  $bm->setTitle($object["title"]);
1067  $bm->setDescription($object["description"]);
1068  $bm->setTarget($object["target"]);
1069  $bm->setParent($folder_id);
1070  $bm->create();
1071  $num_create['bm']++;
1072  break;
1073  case 'bmf':
1074  if (!$object["title"]) continue;
1075  $bmf = new ilBookmarkFolder();
1076  $bmf->setTitle($object["title"]);
1077  $bmf->setParent($folder_id);
1078  $bmf->create();
1079  $num_create['bmf']++;
1080  if (is_array($objects[$obj_key]))
1081  {
1082  $this->__importBookmarks($objects,$num_create,
1083  $bmf->getId(),$obj_key);
1084  }
1085  break;
1086  }
1087  }
1088  }
1089  }
1090 
1091 }
1092 ?>