ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookmarkAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
37 require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkExplorer.php");
38 require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php");
39 require_once ("./Services/PersonalDesktop/classes/class.ilBookmark.php");
40 require_once ("./Services/Table/classes/class.ilTableGUI.php");
41 
43 {
49  var $user_id;
50 
56  var $ilias;
57  var $tpl;
58  var $lng;
59 
60  var $tree;
61  var $id;
62  var $data;
63  var $textwidth=100;
64 
71  {
72  global $ilias, $tpl, $lng, $ilCtrl;
73  //print_r($_SESSION["error_post_vars"]);
74  // if no bookmark folder id is given, take dummy root node id (that is 1)
75  $this->id = (empty($_GET["bmf_id"]))
76  ? $bmf_id = 1
77  : $_GET["bmf_id"];
78 
79  // initiate variables
80  $this->ilias =& $ilias;
81  $this->tpl =& $tpl;
82  $this->lng =& $lng;
83  $this->ctrl =& $ilCtrl;
84  $this->ctrl->setParameter($this, "bmf_id", $this->id);
85  $this->user_id = $_SESSION["AccountId"];
86 
87  $this->tree = new ilTree($_SESSION["AccountId"]);
88  $this->tree->setTableNames('bookmark_tree','bookmark_data');
89  $this->root_id = $this->tree->readRootId();
90  // set current bookmark view mode
91  if (!empty($_GET["set_mode"]))
92  {
93  $this->ilias->account->writePref("il_bkm_mode", $_GET["set_mode"]);
94  }
95  $this->mode = $this->ilias->account->getPref("il_bkm_mode");
96  }
97 
101  function &executeCommand()
102  {
103  $next_class = $this->ctrl->getNextClass();
104 
105  switch($next_class)
106  {
107  default:
108  $cmd = $this->ctrl->getCmd("view");
109  $this->displayHeader();
110  $this->$cmd();
111  if ($this->getMode() == 'tree')
112  {
113  $this->explorer();
114  }
115  break;
116  }
117  $this->tpl->show(true);
118  return true;
119  }
120  function executeAction()
121  {
122  switch($_POST["action"])
123  {
124  case "delete":
125  $this->delete();
126  break;
127  case "export":
128  $this->export();
129  break;
130  case "sendmail":
131  $this->sendmail();
132  break;
133  default:
134  $this->view();
135  break;
136  }
137  return true;
138  }
139 
144  function getMode() {
145  return $this->mode;
146  }
147 
151  function explorer()
152  {
153  $this->tpl->setCurrentBlock("left_column");
154  $this->tpl->addBlockFile("LEFT_CONTENT", "adm_tree_content", "tpl.bookmark_explorer.html");
155  $exp = new ilBookmarkExplorer($this->ctrl->getLinkTarget($this),$_SESSION["AccountId"]);
156  $exp->setAllowedTypes(array('dum','bmf'));
157  $exp->setTargetGet("bmf_id");
158  $exp->setSessionExpandVariable('mexpand');
159  $this->ctrl->setParameter($this, "bmf_id", $this->id);
160  $exp->setExpandTarget($this->ctrl->getLinkTarget($this));
161  if ($_GET["mexpand"] == "")
162  {
163  $mtree = new ilTree($_SESSION["AccountId"]);
164  $mtree->setTableNames('bookmark_tree','bookmark_data');
165  $expanded = $mtree->readRootId();
166  }
167  else
168  {
169  $expanded = $_GET["mexpand"];
170  }
171 
172  $exp->setExpand($expanded);
173 
174  // build html-output
175  $exp->setOutput(0);
176  $output = $exp->getOutput();
177 
178  $this->tpl->setCurrentBlock("adm_tree_content");
179  $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("bookmarks"));
180  $this->ctrl->setParameter($this, "bmf_id", 1);
181  $this->tpl->setVariable("LINK_EXPLORER_HEADER",$this->ctrl->getLinkTarget($this));
182 
183  $this->tpl->setVariable("EXPLORER",$output);
184  $this->tpl->parseCurrentBlock();
185  }
186 
187 
191  function displayHeader()
192  {
193  // output locator
194  $this->displayLocator();
195 
196  // output message
197  if($this->message)
198  {
199  ilUtil::sendInfo($this->message);
200  }
202 
203  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
204  $this->lng->txt("personal_desktop"));
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;
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  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.table.html");
226 
227  $this->ctrl->setParameter($this, "bmf_id", $this->id);
228  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
229 
230  $objects = ilBookmarkFolder::getObjects($this->id);
231 
232  $s_mode = ($this->mode == "tree")
233  ? "flat"
234  : "tree";
235  $this->tpl->setCurrentBlock("tree_mode");
236  $this->ctrl->setParameter($this, "bmf_id", $this->id);
237  $this->tpl->setTreeFlatIcon($this->ctrl->getLinkTarget($this)."&set_mode=".$s_mode,
238  $s_mode);
239  $this->tpl->parseCurrentBlock();
240 
241 
242  $this->tpl->setCurrentBlock("objects");
243  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.bookmark_row.html");
244  $cnt = 0;
245 
246  // return to parent folder
247  if ($this->id != $mtree->readRootId() || $this->id =="")
248  {
249  $this->tpl->setCurrentBlock("tbl_content");
250 
251  // color changing
252  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
253 
254  $this->tpl->setVariable("CHECKBOX", "&nbsp;");
255  $this->tpl->setVariable("ROWCOL", $css_row);
256 
257  $val = ilUtil::getImagePath("icon_cat.gif");
258  $this->tpl->setVariable("IMG", $val);
259  $this->tpl->setVariable("ALT_IMG", $this->lng->txt("bmf"));
260 
261  // title
262  $this->ctrl->setParameter($this, "bmf_id", $mtree->getParentId($this->id));
263  $link = $this->ctrl->getLinkTarget($this);
264  $this->tpl->setVariable("TXT_TITLE", "..");
265  $this->tpl->setVariable("LINK_TARGET", $link);
266  $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
267 
268  $this->tpl->parseCurrentBlock();
269  }
270  // all checkbox ids
271  $a_ids=array();
272  foreach ($objects as $key => $object)
273  {
274  $a_ids[]=$object["type"].":".$object["obj_id"];
275  // type icon
276  $this->ctrl->setParameter($this, "bmf_id", $this->id);
277  $this->ctrl->setParameter($this, "obj_id", $object["obj_id"]);
278  $link = ($object["type"] == "bmf")
279  ? $this->ctrl->getLinkTarget($this, "editFormBookmarkFolder")
280  : $this->ctrl->getLinkTarget($this, "editFormBookmark");
281 
282 
283 
284  // edit link
285  $this->tpl->setCurrentBlock("edit");
286  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
287  $this->tpl->setVariable("LINK_EDIT", $link);
288  $this->tpl->parseCurrentBlock();
289  // target
290  if (!empty($object["target"]))
291  {
292  $this->tpl->setCurrentBlock("target");
293  $this->tpl->setVariable("TXT_TARGET",
295  $object["target"],$this->textwidth, true)));
296  $this->tpl->setVariable("LINK_TARGET", htmlentities($object["target"]));
297  $this->tpl->parseCurrentBlock();
298  }
299  // description
300  if (!empty($object["description"]))
301  {
302  $this->tpl->setCurrentBlock("description");
303  $this->tpl->setVariable("TXT_DESCRIPTION",
304  ilUtil::prepareFormOutput($object["description"]));
305  $this->tpl->parseCurrentBlock();
306  }
307 
308  $this->tpl->setCurrentBlock("tbl_content");
309  // color changing
310  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
311 
312  // surpress checkbox for particular object types
313  //$this->tpl->setVariable("CHECKBOX_ID", $object["type"].":".$object["obj_id"]);
314  $this->tpl->setVariable("CHECKBOX",
315  ilUtil::formCheckBox("", "id[]", $object["type"].":".$object["obj_id"]));
316  $this->tpl->setVariable("ROWCOL", $css_row);
317 
318  $img_type = ($object["type"] == "bmf") ? "cat" : $object["type"];
319  $val = ilUtil::getImagePath("icon_".$img_type.".gif");
320  $this->tpl->setVariable("IMG", $val);
321  $this->tpl->setVariable("ALT_IMG", $this->lng->txt($object["type"]));
322 
323  // title
324  $this->ctrl->setParameter($this, "bmf_id", $object["obj_id"]);
325  $link = ($object["type"] == "bmf") ?
326  $this->ctrl->getLinkTarget($this) :
327  $object["target"];
328  $this->tpl->setVariable("TXT_TITLE", ilUtil::prepareFormOutput($object["title"]));
329  $this->tpl->setVariable("LINK_TARGET", htmlentities($link));
330 
331  if ($object["type"] == "bmf")
332  {
333  $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
334  }
335  else
336  {
337  $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("ExternalContent"));
338  }
339 
340 
341  $this->tpl->parseCurrentBlock();
342  }
343 
344  $tbl = new ilTableGUI();
345 
346  if (!empty($this->id) && $this->id != 1)
347  {
348  $BookmarkFolder = new ilBookmarkFolder($this->id);
349  $addstr = " ".$this->lng->txt("in")." ".$BookmarkFolder->getTitle();
350  }
351  else
352  {
353  $addstr = "";
354  }
355 
356  // title & header columns
357  $tbl->setTitle($this->lng->txt("bookmarks").$addstr,
358  "icon_bm.gif", $this->lng->txt("bookmarks"));
359  //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
360  $tbl->setHeaderNames(array("", $this->lng->txt("type"), $this->lng->txt("title"),""));
361  $tbl->setHeaderVars(array("", "type", "title","commands"),
362  array("bmf_id" => $this->id));
363  $tbl->setColumnWidth(array("1%", "1%", "100%", ""));
364 
365  //$tbl->setOrderColumn($_GET["sort_by"]);
366  //$tbl->setOrderDirection($_GET["sort_order"]);
367  $tbl->setLimit($limit);
368  $tbl->setOffset($offset);
369  $tbl->setMaxCount($maxcount);
370 
371  $tbl->enable("select_all");
372  $tbl->setFormName("cmd");
373  $tbl->setSelectAllCheckbox("id");
374 
375  // footer
376  $tbl->setFooter("tblfooter", $this->lng->txt("previous"),$this->lng->txt("next"));
377  //$tbl->disable("content");
378  $tbl->disable("footer");
379  $tbl->disable("header");
380 
381  // render table
382  $tbl->render();
383 
384  // SHOW POSSIBLE SUB OBJECTS
385  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
386  $this->tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
387  $this->tpl->setVariable("NUM_COLS", 5);
388  $this->showPossibleSubObjects();
389 
390  $this->tpl->setCurrentBlock("tbl_action_row");
391  $this->tpl->setVariable("COLUMN_COUNTS",4);
392  $this->tpl->parseCurrentBlock();
393 
394  }
395 
399  function add_cell($val, $link = "")
400  {
401  if (!empty($link))
402  {
403  $this->tpl->setCurrentBlock("begin_link");
404  $this->tpl->setVariable("LINK_TARGET", $link);
405  $this->tpl->parseCurrentBlock();
406  $this->tpl->touchBlock("end_link");
407  }
408 
409  $this->tpl->setCurrentBlock("text");
410  $this->tpl->setVariable("TEXT_CONTENT", $val);
411  $this->tpl->parseCurrentBlock();
412  $this->tpl->setCurrentBlock("table_cell");
413  $this->tpl->parseCurrentBlock();
414  }
415 
419  function displayLocator()
420  {
421  global $lng;
422 
423  if (empty($this->id))
424  {
425  return;
426  }
427 
428  if (!$this->tree->isInTree($this->id))
429  {
430  return;
431  }
432 
433  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
434 
435  $path = $this->tree->getPathFull($this->id);
436 //print_r($path);
437  $modifier = 1;
438 
439 return;
440  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
441  $this->tpl->touchBlock("locator_separator");
442  $this->tpl->touchBlock("locator_item");
443  //$this->tpl->setCurrentBlock("locator_item");
444  //$this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
445  //$this->tpl->setVariable("LINK_ITEM", $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
446  //$this->tpl->setVariable("LINK_TARGET","target=\"".
447  // ilFrameTargetInfo::_getFrame("MainContent")."\"");
448  //$this->tpl->parseCurrentBlock();
449 
450  foreach ($path as $key => $row)
451  {
452  if ($key < count($path)-$modifier)
453  {
454  $this->tpl->touchBlock("locator_separator");
455  }
456 
457  $this->tpl->setCurrentBlock("locator_item");
458  $title = ($row["child"] == 1) ?
459  $lng->txt("bookmarks") :
460  $row["title"];
461  $this->tpl->setVariable("ITEM", $title);
462  $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
463  $this->tpl->setVariable("LINK_ITEM",
464  $this->ctrl->getLinkTarget($this));
465  $this->tpl->parseCurrentBlock();
466  }
467 
468  $this->tpl->setCurrentBlock("locator");
469 
470  $this->tpl->parseCurrentBlock();
471  }
472 
476  function newForm()
477  {
478  switch($_POST["type"])
479  {
480  case "bmf":
481  $this->newFormBookmarkFolder();
482  break;
483 
484  case "bm":
485  $this->newFormBookmark();
486  break;
487  }
488  }
489 
494  {
495  global $lng;
496 
497  if (!$this->tree->isInTree($this->id))
498  {
499  return;
500  }
501 
502  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_newfolder.html");
503  $this->tpl->setVariable("TITLE", $this->get_last("title", ""));
504  $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
505  $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
506  $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
507  $this->tpl->setVariable("TXT_FOLDER_NEW", $lng->txt("bookmark_folder_new"));
508  $this->ctrl->setParameter($this, "bmf_id", $this->id);
509  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
510  $this->tpl->setVariable("VAL_CMD", "createBookmarkFolder");
511  $this->tpl->parseCurrentBlock();
512  }
513 
514 
519  {
520  global $lng;
521 
522  if (!$this->tree->isInTree($_GET["obj_id"]))
523  {
524  return;
525  }
526 
527  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_newfolder.html");
528 
529  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
530 
531  $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
532  $this->tpl->setVariable("TITLE", $this->get_last("title", $bmf->getTitle()));
533  $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
534  $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
535  $this->tpl->setVariable("TXT_FOLDER_NEW", $lng->txt("bookmark_folder_edit"));
536  $this->tpl->setVariable("VAL_CMD", "updateBookmarkFolder");
537  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
538  $this->ctrl->setParameter($this, "bmf_id", $this->id);
539  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
540 
541  }
542 
543 
547  function newFormBookmark()
548  {
549  global $lng;
550 
551  if (!$this->tree->isInTree($this->id))
552  {
553  return;
554  }
555 
556 
557  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_new.html");
558  $this->tpl->setVariable("TXT_BOOKMARK_NEW", $lng->txt("bookmark_new"));
559  $this->tpl->setVariable("TXT_TARGET", $lng->txt("bookmark_target"));
560  $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
561  $this->tpl->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
562 
563  $this->tpl->setVariable("TITLE", $this->get_last("title", ""));
564  $this->tpl->setVariable("TARGET", $this->get_last("target", "http://"));
565  $this->tpl->setVariable("DESCRIPTION",$this->get_last("description", ""));
566  $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
567  $this->tpl->setVariable("VAL_CMD", "createBookmark");
568  $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
569 
570  $this->ctrl->setParameter($this, "bmf_id", $this->id);
571  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
572  $this->tpl->parseCurrentBlock();
573 
574 
575  $this->tpl->setCurrentBlock('bkm_import');
576  $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
577  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
578  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
579  $this->tpl->parseCurrentBlock();
580  //vd($_POST);
581  }
582 
583 
587  function get_last($a_var, $a_value)
588  {
589  return (!empty($_POST[$a_var])) ?
590  ilUtil::prepareFormOutput(($_POST[$a_var]),true) :
591  ilUtil::prepareFormOutput($a_value);
592  }
593 
597  function editFormBookmark()
598  {
599  global $lng;
600 
601  if (!$this->tree->isInTree($_GET["obj_id"]))
602  {
603  return;
604  }
605  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_new.html");
606 
607  $this->tpl->setVariable("TXT_BOOKMARK_NEW", $lng->txt("bookmark_edit"));
608  $this->tpl->setVariable("TXT_TARGET", $lng->txt("bookmark_target"));
609  $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
610  $this->tpl->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
611 
612  $Bookmark = new ilBookmark($_GET["obj_id"]);
613  $this->tpl->setVariable("TITLE", $this->get_last("title", $Bookmark->getTitle()));
614  $this->tpl->setVariable("TARGET", $this->get_last("target", $Bookmark->getTarget()));
615  $this->tpl->setVariable("DESCRIPTION", $this->get_last("description", $Bookmark->getDescription()));
616 
617  $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
618  $this->tpl->setVariable("VAL_CMD", "updateBookmark");
619  $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
620  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
621  $this->ctrl->setParameter($this, "bmf_id", $this->id);
622  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
623 
624  $this->tpl->parseCurrentBlock();
625  }
626 
627 
632  {
633  if (!$this->tree->isInTree($this->id))
634  {
635  return;
636  }
637 
638  // check title
639  if (empty($_POST["title"]))
640  {
641  ilUtil::sendInfo($this->lng->txt("please_enter_title"));
642  $this->newFormBookmarkFolder();
643  }
644  else
645  {
646  // create bookmark folder
647  $bmf = new ilBookmarkFolder();
648  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
649  $bmf->setParent($this->id);
650  $bmf->create();
651 
652  $this->view();
653  }
654  }
655 
656 
661  {
662  if (!$this->tree->isInTree($_GET["obj_id"]))
663  {
664  return;
665  }
666 
667  // check title
668  if (empty($_POST["title"]))
669  {
670  ilUtil::sendInfo($this->lng->txt("please_enter_title"));
671  $this->editFormBookmarkFolder();
672  }
673  else
674  {
675  // update bookmark folder
676  $bmf = new ilBookmarkFolder($_GET["obj_id"]);
677  $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
678  $bmf->update();
679 
680  $this->view();
681  }
682  }
683 
684 
688  function createBookmark()
689  {
690  if (!$this->tree->isInTree($this->id))
691  {
692  return;
693  }
694 
695  // check title and target
696  if (empty($_POST["title"]))
697  {
698  ilUtil::sendInfo($this->lng->txt("please_enter_title"));
699  $this->newFormBookmark();
700  }
701  else if (empty($_POST["target"]))
702  {
703  ilUtil::sendInfo($this->lng->txt("please_enter_target"));
704  $this->newFormBookmark();
705  }
706  else
707  {
708  // create bookmark
709  $bm = new ilBookmark();
710  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
711  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
712  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
713  $bm->setParent($this->id);
714  $bm->create();
715 
716  $this->view();
717  }
718  }
719 
723  function updateBookmark()
724  {
725  if (!$this->tree->isInTree($_GET["obj_id"]))
726  {
727  return;
728  }
729 
730  // check title and target
731  if (empty($_POST["title"]))
732  {
733  ilUtil::sendInfo($this->lng->txt("please_enter_title"));
734  $this->editFormBookmark();
735  }
736  else if (empty($_POST["target"]))
737  {
738  ilUtil::sendInfo($this->lng->txt("please_enter_target"));
739  $this->editFormBookmark();
740  }
741  else
742  {
743  // update bookmark
744  $bm = new ilBookmark($_GET["obj_id"]);
745  $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
746  $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
747  $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
748  $bm->update();
749 
750  $this->view();
751  }
752  }
753 
757  function export($deliver=true)
758  {
759  if (!isset($_POST["id"]))
760  {
761  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
762  }
763  $export_ids=array();
764  foreach($_POST["id"] as $id)
765  {
766  if ($this->tree->isInTree($id))
767  {
768  list($type, $obj_id) = explode(":", $id);
769  $export_ids[]=$obj_id;
770  }
771  }
772  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
773  $html_content=ilBookmarkImportExport::_exportBookmark ($export_ids,true,
774  $this->lng->txt("bookmarks_of")." ".$this->ilias->account->getFullname());
775  if ($deliver)
776  {
777  ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
778  }
779  else
780  {
781  return $html_content;
782  }
783  }
787  function sendmail()
788  {
789  global $ilUser;
790  include_once 'classes/class.ilFileDataMail.php';
791  require_once "Services/Mail/classes/class.ilFormatMail.php";
792  $mfile = new ilFileDataMail($ilUser->getId());
793  $umail = new ilFormatMail($ilUser->getId());
794 
795 
796  $html_content=$this->export(false);
797  $tempfile=ilUtil::ilTempnam();
798  $fp=fopen($tempfile,'w');
799  fwrite($fp, $html_content);
800  fclose($fp);
801  $filename='bookmarks.html';
802  $mfile->copyAttachmentFile($tempfile,$filename);
803  $umail->savePostData($ilUser->getId(),array($filename),
804  '','','','','',
805  '',
806  '', 0);
807  ilUtil::redirect('ilias.php?baseClass=ilMailGUI&type=attach');
808  }
812  function delete()
813  {
814  if (!isset($_POST["id"]))
815  {
816  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
817  }
818 
819  $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
820 
821  ilUtil::sendInfo($this->lng->txt("info_delete_sure"));
822  $this->ctrl->setParameter($this, "bmf_id", $this->id);
823  $this->tpl->setVariable("FORMACTION",
824  $this->ctrl->getFormAction($this));
825 
826  // output table header
827  $cols = array("type", "title");
828  foreach ($cols as $key)
829  {
830  $this->tpl->setCurrentBlock("table_header");
831  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
832  $this->tpl->parseCurrentBlock();
833  }
834 
835  $_SESSION["saved_post"] = $_POST["id"];
836 
837  foreach($_POST["id"] as $id)
838  {
839 
840  list($type, $obj_id) = explode(":", $id);
841  if (!$this->tree->isInTree($obj_id))
842  {
843  continue;
844  }
845  switch($type)
846  {
847  case "bmf":
848  $BookmarkFolder = new ilBookmarkFolder($obj_id);
849  $title = $BookmarkFolder->getTitle();
850  $target = "";
851  unset($BookmarkFolder);
852  break;
853 
854  case "bm":
855  $Bookmark = new ilBookmark($obj_id);
856  $title = $Bookmark->getTitle();
857  $target = $Bookmark->getTarget();
858  unset($Bookmark);
859  break;
860  }
861 
862  // output type icon
863  $this->tpl->setCurrentBlock("table_cell");
864  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
865  $this->tpl->parseCurrentBlock();
866 
867  // output title
868  $this->tpl->setCurrentBlock("table_cell");
869  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
870 
871  // output target
872  if ($target)
873  {
874  $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
875  $target,$this->textwidth, true)));
876  }
877  $this->tpl->parseCurrentBlock();
878 
879  // output table row
880  $this->tpl->setCurrentBlock("table_row");
881  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
882  $this->tpl->parseCurrentBlock();
883  }
884 
885  // cancel and confirm button
886  $buttons = array( "cancel" => $this->lng->txt("cancel"),
887  "confirm" => $this->lng->txt("confirm"));
888 
889  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
890  foreach($buttons as $name => $value)
891  {
892  $this->tpl->setCurrentBlock("operation_btn");
893  $this->tpl->setVariable("BTN_NAME",$name);
894  $this->tpl->setVariable("BTN_VALUE",$value);
895  $this->tpl->parseCurrentBlock();
896  }
897  }
898 
902  function cancel()
903  {
904  session_unregister("saved_post");
905  $this->view();
906  }
907 
911  function confirm()
912  {
913  global $tree, $rbacsystem, $rbacadmin;
914 
915  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
916  if (!isset($_SESSION["saved_post"]))
917  {
918  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
919  }
920 
921  // FOR ALL SELECTED OBJECTS
922  foreach ($_SESSION["saved_post"] as $id)
923  {
924  list($type, $id) = explode(":", $id);
925 
926  // get node data and subtree nodes
927  if ($this->tree->isInTree($id))
928  {
929  $node_data = $this->tree->getNodeData($id);
930  $subtree_nodes = $this->tree->getSubTree($node_data);
931  }
932  else
933  {
934  continue;
935  }
936 
937  // delete tree
938  $this->tree->deleteTree($node_data);
939 
940  // delete objects of subtree nodes
941  foreach ($subtree_nodes as $node)
942  {
943  switch ($node["type"])
944  {
945  case "bmf":
946  $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
947  $BookmarkFolder->delete();
948  break;
949 
950  case "bm":
951  $Bookmark = new ilBookmark($node["obj_id"]);
952  $Bookmark->delete();
953  break;
954  }
955  }
956  }
957 
958  // Feedback
959  ilUtil::sendInfo($this->lng->txt("info_deleted"),true);
960 
961  $this->view();
962  }
963 
964 
969  {
970  $actions = array(
971  "delete"=>$this->lng->txt("delete"),
972  "export"=>$this->lng->txt("export"),
973  "sendmail"=>$this->lng->txt("bkm_sendmail"),
974  );
975 
976  $subobj = array("bm", "bmf");
977 
978  if (is_array($subobj))
979  {
980  //build form
981  $opts = ilUtil::formSelect("","type",$subobj);
982 
983  $this->tpl->setCurrentBlock("add_object");
984  $this->tpl->setVariable("COLUMN_COUNTS", 7);
985  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
986  $this->tpl->setVariable("BTN_NAME", "newForm");
987  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
988  $this->tpl->parseCurrentBlock();
989  }
990 
991  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
992 
993  $this->tpl->setCurrentBlock("tbl_action_select");
994  $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
995  $this->tpl->setVariable("BTN_NAME","executeAction");
996  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
997 
998  /*
999  $this->tpl->setVariable("BTN_NAME","delete");
1000  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
1001  $this->tpl->parseCurrentBlock();
1002 
1003  $this->tpl->setVariable("BTN_NAME","export");
1004  $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("export"));
1005  $this->tpl->parseCurrentBlock();
1006  */
1007  $this->tpl->parseCurrentBlock();
1008 
1009  }
1010 
1014  function &getHTML()
1015  {
1016  include_once("./Services/PersonalDesktop/classes/class.ilBookmarkBlockGUI.php");
1017  $bookmark_block_gui = new ilBookmarkBlockGUI("ilpersonaldesktopgui", "show");
1018 
1019  return $bookmark_block_gui->getHTML();
1020  }
1021 
1029  function importFile()
1030  {
1031  if (!$this->tree->isInTree($this->id))
1032  {
1033  return;
1034  }
1035 
1036  if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
1037  {
1038  ilUtil::sendInfo($this->lng->txt("import_file_not_valid"));
1039  $this->newFormBookmark();
1040  return;
1041  }
1042  require_once ("./Services/PersonalDesktop/classes/class.ilBookmarkImportExport.php");
1043  $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
1044  if ($objects===false)
1045  {
1046  ilUtil::sendInfo($this->lng->txt("import_file_not_valid"));
1047  $this->newFormBookmark();
1048  return;
1049  }
1050  // holds the number of created objects
1051  $num_create=array('bm'=>0,'bmf'=>0);
1052  $this->__importBookmarks($objects,$num_create,$this->id,0);
1053 
1054  ilUtil::sendInfo(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
1055  $num_create[ 'bmf']));
1056  $this->view();
1057 
1058 
1059  }
1068  function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
1069  {
1070  if (is_array($objects[$start_key]))
1071  {
1072  foreach ($objects[$start_key] as $obj_key=>$object)
1073  {
1074  switch ($object['type'])
1075  {
1076  case 'bm':
1077  if (!$object["title"]) continue;
1078  if (!$object["target"]) continue;
1079  $bm = new ilBookmark();
1080  $bm->setTitle($object["title"]);
1081  $bm->setDescription($object["description"]);
1082  $bm->setTarget($object["target"]);
1083  $bm->setParent($folder_id);
1084  $bm->create();
1085  $num_create['bm']++;
1086  break;
1087  case 'bmf':
1088  if (!$object["title"]) continue;
1089  $bmf = new ilBookmarkFolder();
1090  $bmf->setTitle($object["title"]);
1091  $bmf->setParent($folder_id);
1092  $bmf->create();
1093  $num_create['bmf']++;
1094  if (is_array($objects[$obj_key]))
1095  {
1096  $this->__importBookmarks($objects,$num_create,
1097  $bmf->getId(),$obj_key);
1098  }
1099  break;
1100  }
1101  }
1102  }
1103  }
1104 
1105 }
1106 ?>