00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00037 require_once ("classes/class.ilBookmarkExplorer.php");
00038 require_once ("classes/class.ilBookmarkFolder.php");
00039 require_once ("classes/class.ilBookmark.php");
00040 require_once ("classes/class.ilTableGUI.php");
00041
00042 class ilBookmarkAdministrationGUI
00043 {
00049 var $user_id;
00050
00056 var $ilias;
00057 var $tpl;
00058 var $lng;
00059
00060 var $tree;
00061 var $id;
00062 var $data;
00063 var $textwidth=100;
00064
00070 function ilBookmarkAdministrationGUI()
00071 {
00072 global $ilias, $tpl, $lng, $ilCtrl;
00073
00074
00075 $this->id = (empty($_GET["bmf_id"]))
00076 ? $bmf_id = 1
00077 : $_GET["bmf_id"];
00078
00079
00080 $this->ilias =& $ilias;
00081 $this->tpl =& $tpl;
00082 $this->lng =& $lng;
00083 $this->ctrl =& $ilCtrl;
00084 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00085 $this->user_id = $_SESSION["AccountId"];
00086
00087 $this->tree = new ilTree($_SESSION["AccountId"]);
00088 $this->tree->setTableNames('bookmark_tree','bookmark_data');
00089 $this->root_id = $this->tree->readRootId();
00090
00091 if (!empty($_GET["set_mode"]))
00092 {
00093 $this->ilias->account->writePref("il_bkm_mode", $_GET["set_mode"]);
00094 }
00095 $this->mode = $this->ilias->account->getPref("il_bkm_mode");
00096 }
00097
00101 function &executeCommand()
00102 {
00103 $next_class = $this->ctrl->getNextClass();
00104
00105 switch($next_class)
00106 {
00107 default:
00108 $cmd = $this->ctrl->getCmd("view");
00109 $this->displayHeader();
00110 $this->$cmd();
00111 if ($this->getMode() == 'tree')
00112 {
00113 $this->explorer();
00114 }
00115 break;
00116 }
00117 $this->tpl->show(true);
00118 return true;
00119 }
00120 function executeAction()
00121 {
00122 switch($_POST["action"])
00123 {
00124 case "delete":
00125 $this->delete();
00126 break;
00127 case "export":
00128 $this->export();
00129 break;
00130 case "sendmail":
00131 $this->sendmail();
00132 break;
00133 default:
00134 $this->view();
00135 break;
00136 }
00137 return true;
00138 }
00139
00144 function getMode() {
00145 return $this->mode;
00146 }
00147
00151 function explorer()
00152 {
00153 $this->tpl->setCurrentBlock("left_column");
00154 $this->tpl->addBlockFile("LEFT_CONTENT", "adm_tree_content", "tpl.bookmark_explorer.html");
00155 $exp = new ilBookmarkExplorer($this->ctrl->getLinkTarget($this),$_SESSION["AccountId"]);
00156 $exp->setAllowedTypes(array('dum','bmf'));
00157 $exp->setTargetGet("bmf_id");
00158 $exp->setSessionExpandVariable('mexpand');
00159 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00160 $exp->setExpandTarget($this->ctrl->getLinkTarget($this));
00161 if ($_GET["mexpand"] == "")
00162 {
00163 $mtree = new ilTree($_SESSION["AccountId"]);
00164 $mtree->setTableNames('bookmark_tree','bookmark_data');
00165 $expanded = $mtree->readRootId();
00166 }
00167 else
00168 {
00169 $expanded = $_GET["mexpand"];
00170 }
00171
00172 $exp->setExpand($expanded);
00173
00174
00175 $exp->setOutput(0);
00176 $output = $exp->getOutput();
00177
00178 $this->tpl->setCurrentBlock("adm_tree_content");
00179 $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("bookmarks"));
00180 $this->ctrl->setParameter($this, "bmf_id", 1);
00181 $this->tpl->setVariable("LINK_EXPLORER_HEADER",$this->ctrl->getLinkTarget($this));
00182
00183 $this->tpl->setVariable("EXPLORER",$output);
00184 $this->tpl->parseCurrentBlock();
00185 }
00186
00187
00191 function displayHeader()
00192 {
00193
00194 $this->displayLocator();
00195
00196
00197 if($this->message)
00198 {
00199 sendInfo($this->message);
00200 }
00201 infoPanel();
00202
00203 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
00204 $this->lng->txt("personal_desktop"));
00205 $this->tpl->setTitle($this->lng->txt("personal_desktop"));
00206 }
00207
00208
00209
00210
00211 function view()
00212 {
00213 global $tree;
00214
00215 include_once("classes/class.ilFrameTargetInfo.php");
00216
00217 $mtree = new ilTree($_SESSION["AccountId"]);
00218 $mtree->setTableNames('bookmark_tree','bookmark_data');
00219
00220 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.table.html");
00221
00222 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00223 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00224
00225 $objects = ilBookmarkFolder::getObjects($this->id);
00226
00227 $s_mode = ($this->mode == "tree")
00228 ? "flat"
00229 : "tree";
00230 $this->tpl->setCurrentBlock("tree_mode");
00231 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00232 $this->tpl->setTreeFlatIcon($this->ctrl->getLinkTarget($this)."&set_mode=".$s_mode,
00233 $s_mode);
00234 $this->tpl->parseCurrentBlock();
00235
00236
00237 $this->tpl->setCurrentBlock("objects");
00238 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.bookmark_row.html");
00239 $cnt = 0;
00240
00241
00242 if ($this->id != $mtree->readRootId() || $this->id =="")
00243 {
00244 $this->tpl->setCurrentBlock("tbl_content");
00245
00246
00247 $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
00248
00249 $this->tpl->setVariable("CHECKBOX", " ");
00250 $this->tpl->setVariable("ROWCOL", $css_row);
00251
00252 $val = ilUtil::getImagePath("icon_cat.gif");
00253 $this->tpl->setVariable("IMG", $val);
00254 $this->tpl->setVariable("ALT_IMG", $this->lng->txt("bmf"));
00255
00256
00257 $this->ctrl->setParameter($this, "bmf_id", $mtree->getParentId($this->id));
00258 $link = $this->ctrl->getLinkTarget($this);
00259 $this->tpl->setVariable("TXT_TITLE", "..");
00260 $this->tpl->setVariable("LINK_TARGET", $link);
00261 $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
00262
00263 $this->tpl->parseCurrentBlock();
00264 }
00265
00266 $a_ids=array();
00267 foreach ($objects as $key => $object)
00268 {
00269 $a_ids[]=$object["type"].":".$object["obj_id"];
00270
00271 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00272 $this->ctrl->setParameter($this, "obj_id", $object["obj_id"]);
00273 $link = ($object["type"] == "bmf")
00274 ? $this->ctrl->getLinkTarget($this, "editFormBookmarkFolder")
00275 : $this->ctrl->getLinkTarget($this, "editFormBookmark");
00276
00277
00278
00279
00280 $this->tpl->setCurrentBlock("edit");
00281 $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
00282 $this->tpl->setVariable("LINK_EDIT", $link);
00283 $this->tpl->parseCurrentBlock();
00284
00285 if (!empty($object["target"]))
00286 {
00287 $this->tpl->setCurrentBlock("target");
00288 $this->tpl->setVariable("TXT_TARGET",
00289 ilUtil::prepareFormOutput(ilUtil::shortenText(
00290 $object["target"],$this->textwidth, true)));
00291 $this->tpl->setVariable("LINK_TARGET", $object["target"]);
00292 $this->tpl->parseCurrentBlock();
00293 }
00294
00295 if (!empty($object["description"]))
00296 {
00297 $this->tpl->setCurrentBlock("description");
00298 $this->tpl->setVariable("TXT_DESCRIPTION",
00299 ilUtil::prepareFormOutput($object["description"]));
00300 $this->tpl->parseCurrentBlock();
00301 }
00302
00303 $this->tpl->setCurrentBlock("tbl_content");
00304
00305 $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
00306
00307
00308
00309 $this->tpl->setVariable("CHECKBOX",
00310 ilUtil::formCheckBox("", "id[]", $object["type"].":".$object["obj_id"]));
00311 $this->tpl->setVariable("ROWCOL", $css_row);
00312
00313 $img_type = ($object["type"] == "bmf") ? "cat" : $object["type"];
00314 $val = ilUtil::getImagePath("icon_".$img_type.".gif");
00315 $this->tpl->setVariable("IMG", $val);
00316 $this->tpl->setVariable("ALT_IMG", $this->lng->txt($object["type"]));
00317
00318
00319 $this->ctrl->setParameter($this, "bmf_id", $object["obj_id"]);
00320 $link = ($object["type"] == "bmf") ?
00321 $this->ctrl->getLinkTarget($this) :
00322 $object["target"];
00323 $this->tpl->setVariable("TXT_TITLE", ilUtil::prepareFormOutput($object["title"]));
00324 $this->tpl->setVariable("LINK_TARGET", $link);
00325
00326 if ($object["type"] == "bmf")
00327 {
00328 $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
00329 }
00330 else
00331 {
00332 $this->tpl->setVariable("FRAME_TARGET", ilFrameTargetInfo::_getFrame("ExternalContent"));
00333 }
00334
00335
00336 $this->tpl->parseCurrentBlock();
00337 }
00338
00339 $tbl = new ilTableGUI();
00340
00341 if (!empty($this->id) && $this->id != 1)
00342 {
00343 $BookmarkFolder = new ilBookmarkFolder($this->id);
00344 $addstr = " ".$this->lng->txt("in")." ".$BookmarkFolder->getTitle();
00345 }
00346 else
00347 {
00348 $addstr = "";
00349 }
00350
00351
00352 $tbl->setTitle($this->lng->txt("bookmarks").$addstr,
00353 "icon_bm.gif", $this->lng->txt("bookmarks"));
00354
00355 $tbl->setHeaderNames(array("", $this->lng->txt("type"), $this->lng->txt("title"),""));
00356 $tbl->setHeaderVars(array("", "type", "title","commands"),
00357 array("bmf_id" => $this->id));
00358 $tbl->setColumnWidth(array("1%", "1%", "100%", ""));
00359
00360
00361
00362 $tbl->setLimit($limit);
00363 $tbl->setOffset($offset);
00364 $tbl->setMaxCount($maxcount);
00365
00366
00367 $tbl->setFooter("tblfooter", $this->lng->txt("previous"),$this->lng->txt("next"));
00368
00369 $tbl->disable("footer");
00370 $tbl->disable("header");
00371
00372
00373 $tbl->render();
00374
00375
00376 if (!empty($a_ids))
00377 {
00378 $this->tpl->setCurrentBlock("tbl_select_all");
00379 $this->tpl->setVariable("COLUMN_COUNTS",4);
00380 $this->tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
00381 $this->tpl->parseCurrentBlock();
00382 }
00383
00384
00385 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00386 $this->tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
00387 $this->tpl->setVariable("NUM_COLS", 5);
00388 $this->showPossibleSubObjects();
00389
00390 $this->tpl->setCurrentBlock("tbl_action_row");
00391 $this->tpl->setVariable("COLUMN_COUNTS",4);
00392 $this->tpl->parseCurrentBlock();
00393
00394 }
00395
00399 function add_cell($val, $link = "")
00400 {
00401 if (!empty($link))
00402 {
00403 $this->tpl->setCurrentBlock("begin_link");
00404 $this->tpl->setVariable("LINK_TARGET", $link);
00405 $this->tpl->parseCurrentBlock();
00406 $this->tpl->touchBlock("end_link");
00407 }
00408
00409 $this->tpl->setCurrentBlock("text");
00410 $this->tpl->setVariable("TEXT_CONTENT", $val);
00411 $this->tpl->parseCurrentBlock();
00412 $this->tpl->setCurrentBlock("table_cell");
00413 $this->tpl->parseCurrentBlock();
00414 }
00415
00419 function displayLocator()
00420 {
00421 global $lng;
00422
00423 if (empty($this->id))
00424 {
00425 return;
00426 }
00427
00428 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00429
00430 $path = $this->tree->getPathFull($this->id);
00431
00432 $modifier = 1;
00433
00434 return;
00435 $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
00436 $this->tpl->touchBlock("locator_separator");
00437 $this->tpl->touchBlock("locator_item");
00438
00439
00440
00441
00442
00443
00444
00445 foreach ($path as $key => $row)
00446 {
00447 if ($key < count($path)-$modifier)
00448 {
00449 $this->tpl->touchBlock("locator_separator");
00450 }
00451
00452 $this->tpl->setCurrentBlock("locator_item");
00453 $title = ($row["child"] == 1) ?
00454 $lng->txt("bookmarks") :
00455 $row["title"];
00456 $this->tpl->setVariable("ITEM", $title);
00457 $this->ctrl->setParameter($this, "bmf_id", $row["child"]);
00458 $this->tpl->setVariable("LINK_ITEM",
00459 $this->ctrl->getLinkTarget($this));
00460 $this->tpl->parseCurrentBlock();
00461 }
00462
00463 $this->tpl->setCurrentBlock("locator");
00464
00465 $this->tpl->parseCurrentBlock();
00466 }
00467
00471 function newForm()
00472 {
00473 switch($_POST["type"])
00474 {
00475 case "bmf":
00476 $this->newFormBookmarkFolder();
00477 break;
00478
00479 case "bm":
00480 $this->newFormBookmark();
00481 break;
00482 }
00483 }
00484
00488 function newFormBookmarkFolder()
00489 {
00490 global $lng;
00491
00492 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_newfolder.html");
00493 $this->tpl->setVariable("TITLE", $this->get_last("title", ""));
00494 $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
00495 $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00496 $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
00497 $this->tpl->setVariable("TXT_FOLDER_NEW", $lng->txt("bookmark_folder_new"));
00498 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00499 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00500 $this->tpl->setVariable("VAL_CMD", "createBookmarkFolder");
00501 $this->tpl->parseCurrentBlock();
00502 }
00503
00504
00508 function editFormBookmarkFolder()
00509 {
00510 global $lng;
00511
00512 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_newfolder.html");
00513
00514 $bmf = new ilBookmarkFolder($_GET["obj_id"]);
00515
00516 $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
00517 $this->tpl->setVariable("TITLE", $this->get_last("title", $bmf->getTitle()));
00518 $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00519 $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
00520 $this->tpl->setVariable("TXT_FOLDER_NEW", $lng->txt("bookmark_folder_edit"));
00521 $this->tpl->setVariable("VAL_CMD", "updateBookmarkFolder");
00522 $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
00523 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00524 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00525
00526 }
00527
00528
00532 function newFormBookmark()
00533 {
00534 global $lng;
00535
00536 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_new.html");
00537 $this->tpl->setVariable("TXT_BOOKMARK_NEW", $lng->txt("bookmark_new"));
00538 $this->tpl->setVariable("TXT_TARGET", $lng->txt("bookmark_target"));
00539 $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
00540 $this->tpl->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
00541
00542 $this->tpl->setVariable("TITLE", $this->get_last("title", ""));
00543 $this->tpl->setVariable("TARGET", $this->get_last("target", "http://"));
00544 $this->tpl->setVariable("DESCRIPTION",$this->get_last("description", ""));
00545 $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00546 $this->tpl->setVariable("VAL_CMD", "createBookmark");
00547 $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
00548
00549 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00550 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00551 $this->tpl->parseCurrentBlock();
00552
00553
00554 $this->tpl->setCurrentBlock('bkm_import');
00555 $this->tpl->setVariable("TXT_IMPORT_BKM", $this->lng->txt("bkm_import"));
00556 $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file_add"));
00557 $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
00558 $this->tpl->parseCurrentBlock();
00559
00560 }
00561
00562
00566 function get_last($a_var, $a_value)
00567 {
00568 return (!empty($_POST[$a_var])) ?
00569 ilUtil::prepareFormOutput(($_POST[$a_var]),true) :
00570 ilUtil::prepareFormOutput($a_value);
00571 }
00572
00576 function editFormBookmark()
00577 {
00578 global $lng;
00579
00580 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.bookmark_new.html");
00581
00582 $this->tpl->setVariable("TXT_BOOKMARK_NEW", $lng->txt("bookmark_edit"));
00583 $this->tpl->setVariable("TXT_TARGET", $lng->txt("bookmark_target"));
00584 $this->tpl->setVariable("TXT_TITLE", $lng->txt("title"));
00585 $this->tpl->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
00586
00587 $Bookmark = new ilBookmark($_GET["obj_id"]);
00588 $this->tpl->setVariable("TITLE", $this->get_last("title", $Bookmark->getTitle()));
00589 $this->tpl->setVariable("TARGET", $this->get_last("target", $Bookmark->getTarget()));
00590 $this->tpl->setVariable("DESCRIPTION", $this->get_last("description", $Bookmark->getDescription()));
00591
00592 $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00593 $this->tpl->setVariable("VAL_CMD", "updateBookmark");
00594 $this->tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
00595 $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
00596 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00597 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00598
00599 $this->tpl->parseCurrentBlock();
00600 }
00601
00602
00606 function createBookmarkFolder()
00607 {
00608
00609 if (empty($_POST["title"]))
00610 {
00611 sendInfo($this->lng->txt("please_enter_title"));
00612 $this->newFormBookmarkFolder();
00613 }
00614 else
00615 {
00616
00617 $bmf = new ilBookmarkFolder();
00618 $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
00619 $bmf->setParent($this->id);
00620 $bmf->create();
00621
00622 $this->view();
00623 }
00624 }
00625
00626
00630 function updateBookmarkFolder()
00631 {
00632
00633 if (empty($_POST["title"]))
00634 {
00635 sendInfo($this->lng->txt("please_enter_title"));
00636 $this->editFormBookmarkFolder();
00637 }
00638 else
00639 {
00640
00641 $bmf = new ilBookmarkFolder($_GET["obj_id"]);
00642 $bmf->setTitle(ilUtil::stripSlashes($_POST["title"]));
00643 $bmf->update();
00644
00645 $this->view();
00646 }
00647 }
00648
00649
00653 function createBookmark()
00654 {
00655
00656 if (empty($_POST["title"]))
00657 {
00658 sendInfo($this->lng->txt("please_enter_title"));
00659 $this->newFormBookmark();
00660 }
00661 else if (empty($_POST["target"]))
00662 {
00663 sendInfo($this->lng->txt("please_enter_target"));
00664 $this->newFormBookmark();
00665 }
00666 else
00667 {
00668
00669 $bm = new ilBookmark();
00670 $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
00671 $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
00672 $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
00673 $bm->setParent($this->id);
00674 $bm->create();
00675
00676 $this->view();
00677 }
00678 }
00679
00683 function updateBookmark()
00684 {
00685
00686 if (empty($_POST["title"]))
00687 {
00688 sendInfo($this->lng->txt("please_enter_title"));
00689 $this->editFormBookmark();
00690 }
00691 else if (empty($_POST["target"]))
00692 {
00693 sendInfo($this->lng->txt("please_enter_target"));
00694 $this->editFormBookmark();
00695 }
00696 else
00697 {
00698
00699 $bm = new ilBookmark($_GET["obj_id"]);
00700 $bm->setTitle(ilUtil::stripSlashes($_POST["title"]));
00701 $bm->setTarget(ilUtil::stripSlashes($_POST["target"]));
00702 $bm->setDescription(ilUtil::stripSlashes($_POST["description"]));
00703 $bm->update();
00704
00705 $this->view();
00706 }
00707 }
00708
00712 function export($deliver=true)
00713 {
00714 if (!isset($_POST["id"]))
00715 {
00716 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00717 }
00718 $export_ids=array();
00719 foreach($_POST["id"] as $id)
00720 {
00721 list($type, $obj_id) = explode(":", $id);
00722 $export_ids[]=$obj_id;
00723 }
00724 require_once ("classes/class.ilBookmarkImportExport.php");
00725 $html_content=ilBookmarkImportExport::_exportBookmark ($export_ids,true,
00726 $this->lng->txt("bookmarks_of")." ".$this->ilias->account->getFullname());
00727 if ($deliver)
00728 {
00729 ilUtil::deliverData($html_content, 'bookmarks.html', "application/save", $charset = "");
00730 }
00731 else
00732 {
00733 return $html_content;
00734 }
00735 }
00739 function sendmail()
00740 {
00741 global $ilUser;
00742 include_once 'classes/class.ilFileDataMail.php';
00743 require_once "classes/class.ilFormatMail.php";
00744 $mfile = new ilFileDataMail($ilUser->getId());
00745 $umail = new ilFormatMail($ilUser->getId());
00746
00747
00748 $html_content=$this->export(false);
00749 $tempfile=ilUtil::ilTempnam();
00750 $fp=fopen($tempfile,'w');
00751 fwrite($fp, $html_content);
00752 fclose($fp);
00753 $filename='bookmarks.html';
00754 $mfile->copyAttachmentFile($tempfile,$filename);
00755 $umail->savePostData($ilUser->getId(),array($filename),
00756 '','','','','',
00757 '',
00758 '');
00759 ilUtil::redirect('mail_frameset.php?target='.urlencode("mail_new.php?type=attach"));
00760 }
00764 function delete()
00765 {
00766 if (!isset($_POST["id"]))
00767 {
00768 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00769 }
00770
00771 $this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.obj_confirm.html");
00772
00773 sendInfo($this->lng->txt("info_delete_sure"));
00774 $this->ctrl->setParameter($this, "bmf_id", $this->id);
00775 $this->tpl->setVariable("FORMACTION",
00776 $this->ctrl->getFormAction($this));
00777
00778
00779 $cols = array("type", "title");
00780 foreach ($cols as $key)
00781 {
00782 $this->tpl->setCurrentBlock("table_header");
00783 $this->tpl->setVariable("TEXT",$this->lng->txt($key));
00784 $this->tpl->parseCurrentBlock();
00785 }
00786
00787 $_SESSION["saved_post"] = $_POST["id"];
00788
00789 foreach($_POST["id"] as $id)
00790 {
00791 list($type, $obj_id) = explode(":", $id);
00792 switch($type)
00793 {
00794 case "bmf":
00795 $BookmarkFolder = new ilBookmarkFolder($obj_id);
00796 $title = $BookmarkFolder->getTitle();
00797 $target = "";
00798 unset($BookmarkFolder);
00799 break;
00800
00801 case "bm":
00802 $Bookmark = new ilBookmark($obj_id);
00803 $title = $Bookmark->getTitle();
00804 $target = $Bookmark->getTarget();
00805 unset($Bookmark);
00806 break;
00807 }
00808
00809
00810 $this->tpl->setCurrentBlock("table_cell");
00811 $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($type, $this->tpl->tplPath));
00812 $this->tpl->parseCurrentBlock();
00813
00814
00815 $this->tpl->setCurrentBlock("table_cell");
00816 $this->tpl->setVariable("TEXT_CONTENT",ilUtil::prepareFormOutput($title));
00817
00818
00819 if ($target)
00820 {
00821 $this->tpl->setVariable("DESC",ilUtil::prepareFormOutput(ilUtil::shortenText(
00822 $target,$this->textwidth, true)));
00823 }
00824 $this->tpl->parseCurrentBlock();
00825
00826
00827 $this->tpl->setCurrentBlock("table_row");
00828 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00829 $this->tpl->parseCurrentBlock();
00830 }
00831
00832
00833 $buttons = array( "cancel" => $this->lng->txt("cancel"),
00834 "confirm" => $this->lng->txt("confirm"));
00835
00836 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00837 foreach($buttons as $name => $value)
00838 {
00839 $this->tpl->setCurrentBlock("operation_btn");
00840 $this->tpl->setVariable("BTN_NAME",$name);
00841 $this->tpl->setVariable("BTN_VALUE",$value);
00842 $this->tpl->parseCurrentBlock();
00843 }
00844 }
00845
00849 function cancel()
00850 {
00851 session_unregister("saved_post");
00852 $this->view();
00853 }
00854
00858 function confirm()
00859 {
00860 global $tree, $rbacsystem, $rbacadmin, $objDefinition;
00861
00862
00863 if (!isset($_SESSION["saved_post"]))
00864 {
00865 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00866 }
00867
00868
00869 foreach ($_SESSION["saved_post"] as $id)
00870 {
00871 list($type, $id) = explode(":", $id);
00872
00873
00874 $node_data = $this->tree->getNodeData($id);
00875 $subtree_nodes = $this->tree->getSubTree($node_data);
00876
00877
00878 $this->tree->deleteTree($node_data);
00879
00880
00881 foreach ($subtree_nodes as $node)
00882 {
00883 switch ($node["type"])
00884 {
00885 case "bmf":
00886 $BookmarkFolder = new ilBookmarkFolder($node["obj_id"]);
00887 $BookmarkFolder->delete();
00888 break;
00889
00890 case "bm":
00891 $Bookmark = new ilBookmark($node["obj_id"]);
00892 $Bookmark->delete();
00893 break;
00894 }
00895 }
00896 }
00897
00898
00899 sendInfo($this->lng->txt("info_deleted"),true);
00900
00901 $this->view();
00902 }
00903
00904
00905
00909 function showActions()
00910 {
00911 global $objDefinition;
00912
00913 $notoperations = array();
00914
00915 if (empty($_SESSION["clipboard"]))
00916 {
00917 $notoperations[] = "paste";
00918 $notoperations[] = "clear";
00919 }
00920
00921 if ($_SESSION["clipboard"])
00922 {
00923 $notoperations[] = "cut";
00924 $notoperations[] = "copy";
00925 $notoperations[] = "link";
00926 }
00927
00928 $operations = array();
00929
00930 $d = $objDefinition->getActions("bmf");
00931
00932 foreach ($d as $row)
00933 {
00934 if (!in_array($row["name"], $notoperations))
00935 {
00936 $operations[] = $row;
00937 }
00938 }
00939
00940 if (count($operations)>0)
00941 {
00942 foreach ($operations as $val)
00943 {
00944 $this->tpl->setCurrentBlock("operation_btn");
00945 $this->tpl->setVariable("BTN_NAME", $val["lng"]);
00946 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
00947 $this->tpl->parseCurrentBlock();
00948 }
00949
00950 $this->tpl->setCurrentBlock("operation");
00951 $this->tpl->parseCurrentBlock();
00952 }
00953 }
00954
00958 function showPossibleSubObjects()
00959 {
00960 global $objDefinition;
00961 $d = $objDefinition->getCreatableSubObjects("bmf");
00962 $actions = array(
00963 "delete"=>$this->lng->txt("delete"),
00964 "export"=>$this->lng->txt("export"),
00965 "sendmail"=>$this->lng->txt("bkm_sendmail"),
00966 );
00967
00968 if (count($d) > 0)
00969 {
00970 foreach ($d as $row)
00971 {
00972 $count = 0;
00973 if ($row["max"] > 0)
00974 {
00975
00976 for ($i=0; $i<count($this->data["ctrl"]); $i++)
00977 {
00978 if ($this->data["ctrl"][$i]["type"] == $row["name"])
00979 {
00980 $count++;
00981 }
00982 }
00983 }
00984 if ($row["max"] == "" || $count < $row["max"])
00985 {
00986 $subobj[] = $row["name"];
00987 }
00988 }
00989 }
00990
00991 if (is_array($subobj))
00992 {
00993
00994 $opts = ilUtil::formSelect("","type",$subobj);
00995
00996 $this->tpl->setCurrentBlock("add_object");
00997 $this->tpl->setVariable("COLUMN_COUNTS", 7);
00998 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00999 $this->tpl->setVariable("BTN_NAME", "newForm");
01000 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
01001 $this->tpl->parseCurrentBlock();
01002 }
01003
01004 $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
01005
01006 $this->tpl->setCurrentBlock("tbl_action_select");
01007 $this->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect($_SESSION["error_post_vars"]['action'],"action",$actions,false,true));
01008 $this->tpl->setVariable("BTN_NAME","executeAction");
01009 $this->tpl->setVariable("BTN_VALUE",$this->lng->txt("execute"));
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020 $this->tpl->parseCurrentBlock();
01021
01022 }
01023
01027 function getPDBookmarkListHTML()
01028 {
01029 if ($this->ilias->account->getPref("il_pd_bkm_mode") == 'tree')
01030 {
01031 return $this->getPDBookmarkListHTMLTree();
01032 }
01033 else
01034 {
01035 return $this->getPDBookmarkListHTMLFlat();
01036 }
01037 }
01038
01042 function getPDBookmarkListHTMLTree()
01043 {
01044 $showdetails = $this->ilias->account->getPref('show_bookmark_details') == 'y';
01045 $tpl = new ilTemplate("tpl.bookmark_pd_tree.html", true, true);
01046
01047 $exp = new ilBookmarkExplorer($this->ctrl->getParentReturn($this),$_SESSION["AccountId"]);
01048
01049
01050
01051 $exp->setAllowedTypes(array('dum','bmf','bm'));
01052 $exp->setTargetGet("bmf_id");
01053 $exp->setSessionExpandVariable('mexpand');
01054 $this->ctrl->setParameter($this, "bmf_id", $this->id);
01055 $exp->setExpandTarget($this->ctrl->getParentReturn($this));
01056 if ($_GET["mexpand"] == "")
01057 {
01058 $expanded = $this->id;
01059 }
01060 else
01061 {
01062 $expanded = $_GET["mexpand"];
01063 }
01064 $exp->setExpand($expanded);
01065 $exp->setShowDetails($showdetails);
01066
01067
01068 $exp->setOutput(0);
01069 $output = $exp->getOutput();
01070 $tpl->setCurrentBlock();
01071 if (empty($output))
01072 {
01073 $tpl->setCurrentBlock("tbl_no_bm");
01074 $tpl->setVariable("ROWCOL","tblrow".(($i % 2)+1));
01075 $tpl->setVariable("TXT_NO_BM", $this->lng->txt("no_bm_in_personal_list"));
01076 $tpl->parseCurrentBlock();
01077 }
01078
01079
01080
01081 $tpl->setVariable("EXPLORER",$output);
01082 $tpl->setVariable("TXT_BM_HEADER", $this->lng->txt("my_bms"));
01083
01084
01085 if ($showdetails)
01086 {
01087 $text = $this->lng->txt("hide_details");
01088 $cmd = "hideBookmarkDetails";
01089 }
01090 else
01091 {
01092 $text = $this->lng->txt("show_details");
01093 $cmd = "showBookmarkDetails";
01094 }
01095
01096 $tpl->setVariable("LINK_BKM_DETAILS",
01097 $this->ctrl->getLinkTarget($this,$cmd));
01098 $tpl->setVariable("TXT_BKM_DETAILS", $text);
01099
01100
01101
01102
01103
01104 $this->insertBlockFooter($tpl);
01105
01106 $tpl->parseCurrentBlock();
01107 return $tpl->get();
01108 }
01109
01113 function insertBlockFooter(&$tpl)
01114 {
01115
01116 $tpl->setCurrentBlock("footer_link");
01117 $tpl->setVariable("HREF_FOOT_LINK", $this->ctrl->getLinkTarget($this,'setPdFlatMode'));
01118 $tpl->setVariable("TXT_FOOT_LINK", $this->lng->txt("flatview"));
01119 $tpl->parseCurrentBlock();
01120 $tpl->touchBlock("footer_item");
01121
01122 $tpl->touchBlock("footer_separator");
01123 $tpl->touchBlock("footer_item");
01124
01125
01126 $tpl->setCurrentBlock("footer_link");
01127 $tpl->setVariable("HREF_FOOT_LINK", $this->ctrl->getLinkTarget($this,'setPdTreeMode'));
01128 $tpl->setVariable("TXT_FOOT_LINK", $this->lng->txt("treeview"));
01129 $tpl->parseCurrentBlock();
01130 $tpl->touchBlock("footer_item");
01131
01132 $tpl->setCurrentBlock("block_footer");
01133 $tpl->parseCurrentBlock();
01134 }
01135
01139 function getPDBookmarkListHTMLFlat()
01140 {
01141 $showdetails = $this->ilias->account->getPref('show_bookmark_details') == 'y';
01142 $tpl = new ilTemplate("tpl.bookmark_pd_list.html", true, true);
01143 include_once("classes/class.ilBookmarkFolder.php");
01144
01145 $bm_items = ilBookmarkFolder::getObjects($_SESSION["ilCurBMFolder"]);
01146
01147 if(ilBookmarkFolder::isRootFolder($_SESSION['ilCurBMFolder']) or !$_SESSION['ilCurBMFolder'])
01148 {
01149 $colspan = 2;
01150 }
01151
01152 $i = 0;
01153 $title_append = "";
01154 if (!ilBookmarkFolder::isRootFolder($_SESSION["ilCurBMFolder"])
01155 && !empty($_SESSION["ilCurBMFolder"]))
01156 {
01157 $i++;
01158 $tpl->setCurrentBlock("tbl_bm_row");
01159 $rowcol = ($rowcol == "tblrow1")
01160 ? "tblrow2"
01161 : "tblrow1";
01162 $tpl->setVariable("ROWCOL", $rowcol);
01163 $tpl->setVariable("IMG_BM", ilUtil::getImagePath("icon_cat.gif"));
01164 $tpl->setVariable("IMG_ALT", $this->lng->txt("bmf"));
01165 $tpl->setVariable("BM_TITLE", "..");
01166 $this->ctrl->setParameter($this, "curBMFolder",
01167 ilBookmarkFolder::_getParentId($_SESSION["ilCurBMFolder"]));
01168 $tpl->setVariable("BM_LINK",
01169 $this->ctrl->getLinkTarget($this, "setCurrentBookmarkFolder"));
01170
01171 $tpl->setVariable("BM_DESCRIPTION", "");
01172 $tpl->setVariable("BM_TARGET", "");
01173 $tpl->parseCurrentBlock();
01174
01175 $title_append = ": ".ilBookmarkFolder::_lookupTitle($_SESSION["ilCurBMFolder"]);
01176 }
01177
01178 foreach ($bm_items as $bm_item)
01179 {
01180 $i++;
01181
01182 $tpl->setCurrentBlock("tbl_bm_row");
01183 $rowcol = ($rowcol == "tblrow1")
01184 ? "tblrow2"
01185 : "tblrow1";
01186 $tpl->setVariable("ROWCOL", $rowcol);
01187
01188 switch ($bm_item["type"])
01189 {
01190 case "bmf":
01191 $tpl->setVariable("IMG_BM", ilUtil::getImagePath("icon_cat.gif"));
01192 $tpl->setVariable("IMG_ALT", $this->lng->txt("bmf"));
01193 $tpl->setVariable("BM_TITLE", ilUtil::prepareFormOutput($bm_item["title"]));
01194 $this->ctrl->setParameter($this, "curBMFolder", $bm_item["obj_id"]);
01195 $tpl->setVariable("BM_LINK",
01196 $this->ctrl->getLinkTarget($this, "setCurrentBookmarkFolder"));
01197 $tpl->setVariable("BM_TARGET", "");
01198 break;
01199
01200 case "bm":
01201 $tpl->setVariable("IMG_BM", ilUtil::getImagePath("icon_bm.gif"));
01202 $tpl->setVariable("IMG_ALT", $this->lng->txt("bm"));
01203 $tpl->setVariable("BM_TITLE", ilUtil::prepareFormOutput($bm_item["title"]));
01204 $tpl->setVariable("BM_LINK", ilUtil::prepareFormOutput($bm_item["target"]));
01205 $tpl->setVariable("BM_TARGET", "_blank");
01206 break;
01207 }
01208 if (!empty($bm_item["desc"]))
01209 {
01210 if ($showdetails)
01211 {
01212 $tpl->setVariable("BM_DESCRIPTION", ilUtil::prepareFormOutput($bm_item["desc"]));
01213 }
01214 else
01215 {
01216 $tpl->setVariable("BM_TOOLTIP", ilUtil::prepareFormOutput($bm_item["desc"]));
01217 }
01218 }
01219
01220 $tpl->parseCurrentBlock();
01221 }
01222
01223 if ($i == 0)
01224 {
01225 $tpl->setCurrentBlock("tbl_no_bm");
01226 $tpl->setVariable("ROWCOL","tblrow".(($i % 2)+1));
01227 $tpl->setVariable("TXT_NO_BM", $this->lng->txt("no_bm_in_personal_list"));
01228 $tpl->parseCurrentBlock();
01229 }
01230
01231 $tpl->setCurrentBlock();
01232 $tpl->setVariable("TXT_BM_HEADER", $this->lng->txt("my_bms").$title_append);
01233
01234 if ($showdetails)
01235 {
01236 $text = $this->lng->txt("hide_details");
01237 $cmd = "hideBookmarkDetails";
01238 }
01239 else
01240 {
01241 $text = $this->lng->txt("show_details");
01242 $cmd = "showBookmarkDetails";
01243 }
01244 $tpl->setVariable("LINK_BKM_DETAILS",
01245 $this->ctrl->getLinkTarget($this,$cmd));
01246 $tpl->setVariable("TXT_BKM_DETAILS", $text);
01247
01248
01249
01250
01251
01252
01253 $this->insertBlockFooter($tpl);
01254 $tpl->parseCurrentBlock();
01255
01256 return $tpl->get();
01257 }
01258
01262 function setCurrentBookmarkFolder()
01263 {
01264 $_SESSION["ilCurBMFolder"] = $_GET["curBMFolder"];
01265 $this->ctrl->returnToParent($this);
01266 }
01274 function importFile()
01275 {
01276 if ($_FILES["bkmfile"]["error"] > UPLOAD_ERR_OK)
01277 {
01278 sendInfo($this->lng->txt("import_file_not_valid"));
01279 $this->newFormBookmark();
01280 return;
01281 }
01282 require_once ("classes/class.ilBookmarkImportExport.php");
01283 $objects=ilBookmarkImportExport::_parseFile ($_FILES["bkmfile"]['tmp_name']);
01284 if ($objects===false)
01285 {
01286 sendInfo($this->lng->txt("import_file_not_valid"));
01287 $this->newFormBookmark();
01288 return;
01289 }
01290
01291 $num_create=array('bm'=>0,'bmf'=>0);
01292 $this->__importBookmarks($objects,$num_create,$this->id,0);
01293
01294 sendInfo(sprintf($this->lng->txt("bkm_import_ok"),$num_create['bm'],
01295 $num_create[ 'bmf']));
01296 $this->view();
01297
01298
01299 }
01308 function __importBookmarks(&$objects,&$num_create,$folder_id,$start_key=0)
01309 {
01310 if (is_array($objects[$start_key]))
01311 {
01312 foreach ($objects[$start_key] as $obj_key=>$object)
01313 {
01314 switch ($object['type'])
01315 {
01316 case 'bm':
01317 if (!$object["title"]) continue;
01318 if (!$object["target"]) continue;
01319 $bm = new ilBookmark();
01320 $bm->setTitle($object["title"]);
01321 $bm->setDescription($object["description"]);
01322 $bm->setTarget($object["target"]);
01323 $bm->setParent($folder_id);
01324 $bm->create();
01325 $num_create['bm']++;
01326 break;
01327 case 'bmf':
01328 if (!$object["title"]) continue;
01329 $bmf = new ilBookmarkFolder();
01330 $bmf->setTitle($object["title"]);
01331 $bmf->setParent($folder_id);
01332 $bmf->create();
01333 $num_create['bmf']++;
01334 if (is_array($objects[$obj_key]))
01335 {
01336 $this->__importBookmarks($objects,$num_create,
01337 $bmf->getId(),$obj_key);
01338 }
01339 break;
01340 }
01341 }
01342 }
01343 }
01347 function showBookmarkDetails()
01348 {
01349 $this->ilias->account->writePref('show_bookmark_details','y');
01350 $this->ctrl->returnToParent($this);
01351 }
01352
01356 function hideBookmarkDetails()
01357 {
01358 $this->ilias->account->writePref('show_bookmark_details','n');
01359 $this->ctrl->returnToParent($this);
01360 }
01364 function setPdFlatMode()
01365 {
01366 $this->ilias->account->writePref("il_pd_bkm_mode", 'flat');
01367 $this->ctrl->returnToParent($this);
01368 }
01372 function setPdTreeMode()
01373 {
01374 $this->ilias->account->writePref("il_pd_bkm_mode", 'tree');
01375 $this->ctrl->returnToParent($this);
01376 }
01377 }
01378 ?>