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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 require_once("classes/class.ilExplorer.php");
00035
00036 class ilBookmarkExplorer extends ilExplorer
00037 {
00043 var $user_id;
00044
00050 var $root_id;
00051
00057 var $allowed_types;
00058
00065 function ilBookmarkExplorer($a_target,$a_user_id)
00066 {
00067 parent::ilExplorer($a_target);
00068 $this->tree = new ilTree($a_user_id);
00069 $this->tree->setTableNames('bookmark_tree','bookmark_data');
00070 $this->root_id = $this->tree->readRootId();
00071 $this->user_id = $a_user_id;
00072 $this->allowed_types= array ('bmf','dum');
00073 }
00074
00081 function getOutput()
00082 {
00083 global $ilBench, $tpl;
00084
00085 $this->format_options[0]["tab"] = array();
00086
00087 $depth = $this->tree->getMaximumDepth();
00088
00089 for ($i=0;$i<$depth;++$i)
00090 {
00091 $this->createLines($i);
00092 }
00093
00094 $tpl_tree = new ilTemplate("tpl.tree_tooltip.html", true, true);
00095
00096 $cur_depth = -1;
00097 foreach ($this->format_options as $key => $options)
00098 {
00099 if (!$options["visible"])
00100 {
00101 continue;
00102 }
00103
00104
00105
00106 $this->handleListEndTags($tpl_tree, $cur_depth, $options["depth"]);
00107
00108
00109 $this->handleListStartTags($tpl_tree, $cur_depth, $options["depth"]);
00110
00111 $cur_depth = $options["depth"];
00112
00113 if ($options["visible"] and $key != 0)
00114 {
00115 $this->formatObject($tpl_tree, $options["child"],$options,$options['obj_id']);
00116 }
00117 if ($key == 0)
00118 {
00119
00120 }
00121 }
00122
00123 $this->handleListEndTags($tpl_tree, $cur_depth, -1);
00124
00125 return $tpl_tree->get();
00126 }
00127
00128
00137 function setOutput($a_parent, $a_depth = 1)
00138 {
00139 global $lng;
00140 static $counter = 0;
00141
00142 if ($objects = $this->tree->getChilds($a_parent,"type DESC,title"))
00143 {
00144
00145 $tab = ++$a_depth - 2;
00146
00147 if($a_depth < 4)
00148 {
00149 for($i=0;$i<count($objects);++$i)
00150 {
00151
00152
00153 }
00154 }
00155
00156 foreach ($objects as $key => $object)
00157 {
00158 if (!in_array($object["type"],$this->allowed_types))
00159 {
00160 continue;
00161 }
00162
00163
00164 if ($object["child"] != $this->root_id)
00165 {
00166
00167 $parent_index = $this->getIndex($object);
00168 }
00169
00170 if ($object["type"]=='bm') {
00171 $this->bm_targets[$object["child"]]=$object["target"];
00172 };
00173 $this->format_options["$counter"]["parent"] = $object["parent"];
00174 $this->format_options["$counter"]["child"] = $object["child"];
00175 $this->format_options["$counter"]["title"] = $object["title"];
00176 $this->format_options["$counter"]["description"] = $object["description"];
00177 $this->format_options["$counter"]["type"] = $object["type"];
00178 $this->format_options["$counter"]["depth"] = $tab;
00179 $this->format_options["$counter"]["container"] = false;
00180 $this->format_options["$counter"]["visible"] = true;
00181
00182
00183 for ($i = 0; $i < $tab; ++$i)
00184 {
00185 $this->format_options["$counter"]["tab"][] = 'blank';
00186 }
00187
00188 if ($object["child"] != $this->root_id and (!in_array($object["parent"],$this->expanded)
00189 or !$this->format_options["$parent_index"]["visible"]))
00190 {
00191 $this->format_options["$counter"]["visible"] = false;
00192 }
00193
00194
00195 if ($object["child"] != $this->root_id)
00196 {
00197 $this->format_options["$parent_index"]["container"] = true;
00198
00199 if (in_array($object["parent"],$this->expanded))
00200 {
00201 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
00202 }
00203 else
00204 {
00205 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'plus';
00206 }
00207 }
00208
00209 ++$counter;
00210
00211
00212 $this->setOutput($object["child"],$a_depth);
00213 }
00214 }
00215 }
00226 function formatObject(&$tpl, $a_node_id,$a_option,$a_obj_id = 0)
00227 {
00228 global $lng;
00229
00230 if (!isset($a_node_id) or !is_array($a_option))
00231 {
00232 $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
00233 "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
00234 }
00235
00236 $pic = false;
00237 foreach ($a_option["tab"] as $picture)
00238 {
00239
00240
00241
00242 if ($picture == 'plus')
00243 {
00244 $tpl->setCurrentBlock("exp_desc");
00245 $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
00246 $tpl->parseCurrentBlock();
00247 $target = $this->createTarget('+',$a_node_id);
00248 $tpl->setCurrentBlock("expander");
00249 $tpl->setVariable("LINK_NAME", $a_node_id);
00250 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
00251 $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.gif"));
00252 $tpl->parseCurrentBlock();
00253 $pic = true;
00254 }
00255
00256 if ($picture == 'minus')
00257 {
00258 $tpl->setCurrentBlock("exp_desc");
00259 $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
00260 $tpl->parseCurrentBlock();
00261 $target = $this->createTarget('-',$a_node_id);
00262 $tpl->setCurrentBlock("expander");
00263 $tpl->setVariable("LINK_NAME", $a_node_id);
00264 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
00265 $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.gif"));
00266 $tpl->parseCurrentBlock();
00267 $pic = true;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 }
00281
00282 if (!$pic)
00283 {
00284 $tpl->setCurrentBlock("blank");
00285 $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.gif"));
00286 $tpl->parseCurrentBlock();
00287 }
00288
00289 if ($this->output_icons)
00290 {
00291 $tpl->setCurrentBlock("icon");
00292 $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"].".gif", $a_option["type"], $a_obj_id));
00293 $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
00294 $this->iconList[] = "iconid_".$a_node_id;
00295 $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["type"]));
00296 $tpl->parseCurrentBlock();
00297 }
00298
00299 if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id))
00300 {
00301 $tpl->setCurrentBlock("link");
00302
00303
00304
00305 $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
00306 if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
00307 {
00308 $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
00309 }
00310 if (($tooltip = $this->buildToolTip($a_node_id, $a_option["type"],$a_option["description"])) != "")
00311 {
00312 $tpl->setVariable("TOOLTIP", 'title="'.ilUtil::prepareFormOutput($tooltip).'"');
00313 }
00314 $tpl->setVariable("LINK_NAME", $a_node_id);
00315 $tpl->setVariable("TITLE", ilUtil::prepareFormOutput(ilUtil::shortenText(
00316 $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
00317 $this->textwidth, true)));
00318 $tpl->setVariable("DESC",
00319 $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]));
00320 $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
00321 if ($frame_target != "")
00322 {
00323 $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
00324 }
00325 $tpl->parseCurrentBlock();
00326 }
00327 else
00328 {
00329 $tpl->setCurrentBlock("text");
00330 $tpl->setVariable("OBJ_TITLE",ilUtil::prepareFormOutput(ilUtil::shortenText(
00331 $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]), $this->textwidth, true)));
00332 $tpl->setVariable("OBJ_DESC",
00333 $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]));
00334 $tpl->parseCurrentBlock();
00335 }
00336
00337 $tpl->setCurrentBlock("list_item");
00338 $tpl->parseCurrentBlock();
00339 $tpl->touchBlock("element");
00340 }
00341
00349 function formatHeader($a_obj_id,$a_option)
00350 {
00351 global $lng, $ilias;
00352
00353 $tpl->setCurrentBlock("link");
00354 $tpl->setVariable("TYPE", $a_option["type"]);
00355 $tpl->setVariable("TITLE", $lng->txt("bookmarks_of")." ".$ilias->account->getFullname());
00356 $sep = (is_int(strpos($this->target, "?")))
00357 ? "&"
00358 : "?";
00359 $tpl->setVariable("LINK_TARGET", $this->target.$sep.$this->target_get."=1");
00360 $tpl->setVariable("TARGET", " target=\"content\"");
00361 $tpl->parseCurrentBlock();
00362
00363 $tpl->setCurrentBlock("element");
00364 $tpl->parseCurrentBlock();
00365
00366 }
00367
00374 function setExpand($a_node_id)
00375 {
00376
00377 if(!is_array($_SESSION["mexpand"]))
00378 {
00379 $_SESSION["mexpand"] = array();
00380 }
00381
00382 if($a_node_id > 0 && !in_array($a_node_id,$_SESSION["mexpand"]))
00383 {
00384 array_push($_SESSION["mexpand"],$a_node_id);
00385 }
00386
00387 if($a_node_id < 0)
00388 {
00389 $key = array_keys($_SESSION["mexpand"],-(int) $a_node_id);
00390 unset($_SESSION["mexpand"][$key[0]]);
00391 }
00392 $this->expanded = $_SESSION["mexpand"];
00393 }
00398 function buildLinkTarget($a_node_id, $a_type)
00399 {
00400 switch ($a_type) {
00401 case 'bm':
00402
00403 return $this->bm_targets[$a_node_id];
00404 break;
00405 default:
00406 $target = (strpos($this->target, "?") === false)
00407 ? $this->target."?"
00408 : $this->target."&";
00409 return $target.$this->target_get."=".$a_node_id.$this->params_get;
00410 }
00411 }
00416 function buildFrameTarget($a_type, $a_child = 0, $a_obj_id = 0)
00417 {
00418 switch ($a_type) {
00419 case 'bm':
00420
00421 return '_blank';
00422 break;
00423 default:
00424 return '';
00425 }
00426 }
00427
00431 function buildToolTip($a_node_id, $a_type, $a_desc)
00432 {
00433 if ($this->show_details!='y' && !empty($a_desc))
00434 {
00435 return $a_desc;
00436 }
00437 else
00438 {
00439 return "";
00440 }
00441 }
00442
00448 function setAllowedTypes($a_types)
00449 {
00450 $this->allowed_types = $a_types;
00451 }
00457 function setShowDetails($s_details)
00458 {
00459 $this->show_details = $s_details;
00460 }
00461
00466 function buildDescription($a_desc, $a_id, $a_type)
00467 {
00468 if ($this->show_details=='y' && !empty($a_desc))
00469 {
00470 return '<br />'.ilUtil::prepareFormOutput($a_desc);
00471
00472 }
00473 else
00474 {
00475 return "";
00476 }
00477
00478 }
00479 }
00480 ?>