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
00033 class ilFileExplorer
00034 {
00040 var $ilias;
00041
00047 var $output;
00048
00054 var $format_options;
00055
00061 var $directory;
00062
00068 var $target;
00069
00075 var $target_get;
00076
00082 var $params_get;
00083
00089 var $expanded;
00090
00096 var $order_column;
00097
00103 var $expand_target;
00104
00110 var $output_icons;
00111
00117 function ilFileExplorer($a_directory, $a_target)
00118 {
00119 global $ilias;
00120
00121 if (!isset($a_target) or !is_string($a_target))
00122 {
00123 $this->ilias->raiseError(get_class($this)."::Constructor(): No target given!",$this->ilias->error_obj->WARNING);
00124 }
00125
00126 if (!isset($a_directory) or !is_string($a_directory))
00127 {
00128 $this->ilias->raiseError(get_class($this)."::Constructor(): No directory given!",$this->ilias->error_obj->WARNING);
00129 }
00130
00131 $this->ilias =& $ilias;
00132 $this->directory = $a_directory;
00133 $this->output = array();
00134 $this->expanded = array();
00135 $this->target = $a_target;
00136 $this->target_get = 'ref_id';
00137 $this->frame_target = "_top";
00138 $this->order_column = "title";
00139 $this->expand_target = $_SERVER["PATH_INFO"];
00140 $this->rbac_check = true;
00141 $this->output_icons = true;
00142 }
00143
00149 function setOrderColumn($a_column)
00150 {
00151 $this->order_column = $a_column;
00152 }
00153
00159 function setTargetGet($a_target_get)
00160 {
00161 if (!isset($a_target_get) or !is_string($a_target_get))
00162 {
00163 $this->ilias->raiseError(get_class($this)."::setTargetGet(): No target given!",$this->ilias->error_obj->WARNING);
00164 }
00165
00166 $this->target_get = $a_target_get;
00167 }
00168
00174 function setParamsGet($a_params_get)
00175 {
00176 if (!isset($a_params_get) or !is_array($a_params_get))
00177 {
00178 $this->ilias->raiseError(get_class($this)."::setTargetGet(): No target given!",$this->ilias->error_obj->WARNING);
00179 }
00180
00181 foreach ($a_params_get as $key => $val)
00182 {
00183 $str .= "&".$key."=".$val;
00184 }
00185
00186 $this->params_get = $str;
00187 }
00188
00189
00196 function setExpandTarget($a_exp_target)
00197 {
00198 $this->expand_target = $a_exp_target;
00199 }
00200
00206 function checkPermissions($a_check)
00207 {
00208 $this->rbac_check = $a_check;
00209 }
00210
00216 function outputIcons($a_icons)
00217 {
00218 $this->output_icons = $a_icons;
00219 }
00220
00221
00230 function setOutput($a_parent_dir, $a_depth = 1)
00231 {
00232 static $counter = 0;
00233
00234 if (!isset($a_parent_id))
00235 {
00236 $this->ilias->raiseError(get_class($this)."::setOutput(): No node_id given!",$this->ilias->error_obj->WARNING);
00237 }
00238 $files = $this->getFiles($a_parent_dir, $this->order_column);
00239 if (count($files) > 0)
00240 {
00241 $tab = ++$a_depth - 2;
00242 foreach ($objects as $key => $object)
00243 {
00244
00245 if ($this->filtered == false || $this->checkFilter($object["type"])==true)
00246 {
00247 if ($object["child"] != $this->tree->getRootId())
00248 {
00249 $parent_index = $this->getIndex($object);
00250 }
00251 $this->format_options["$counter"]["parent"] = $object["parent"];
00252 $this->format_options["$counter"]["child"] = $object["child"];
00253 $this->format_options["$counter"]["title"] = $object["title"];
00254 $this->format_options["$counter"]["type"] = $object["type"];
00255 $this->format_options["$counter"]["desc"] = "obj_".$object["type"];
00256 $this->format_options["$counter"]["depth"] = $tab;
00257 $this->format_options["$counter"]["container"] = false;
00258 $this->format_options["$counter"]["visible"] = true;
00259
00260
00261 for ($i = 0; $i < $tab; ++$i)
00262 {
00263 $this->format_options["$counter"]["tab"][] = 'blank';
00264 }
00265
00266
00267 if ($object["child"] != $this->tree->getRootId() and (!in_array($object["parent"],$this->expanded)
00268 or !$this->format_options["$parent_index"]["visible"]))
00269 {
00270 $this->format_options["$counter"]["visible"] = false;
00271 }
00272
00273
00274 if ($object["child"] != $this->tree->getRootId())
00275 {
00276 $this->format_options["$parent_index"]["container"] = true;
00277
00278 if (in_array($object["parent"],$this->expanded))
00279 {
00280 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
00281 }
00282 else
00283 {
00284 $this->format_options["$parent_index"]["tab"][($tab-2)] = 'plus';
00285 }
00286 }
00287
00288 ++$counter;
00289
00290
00291 $this->setOutput($object["child"],$a_depth);
00292 }
00293 }
00294 }
00295 }
00296
00297
00298 function getFiles($a_parent_dir, $a_order)
00299 {
00300 $files = array();
00301 $handle = opendir($a_parent_dir);
00302 while (false !== ($file = readdir($handle)))
00303 {
00304 if (!is_dir($file))
00305 {
00306 $files[] = array("type" => "file", "name" => $file);
00307 }
00308 else
00309 {
00310 $files[] = array("type" => "dir", "name" => $file);
00311 }
00312 }
00313 return $files;
00314 }
00315
00322 function getOutput()
00323 {
00324 $this->format_options[0]["tab"] = array();
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 foreach ($this->format_options as $key => $options)
00335 {
00336 if ($options["visible"] and $key != 0)
00337 {
00338 $this->formatObject($options["child"],$options);
00339 }
00340 if ($key == 0)
00341 {
00342 $this->formatHeader($options["child"],$options);
00343 }
00344 }
00345
00346 return implode('',$this->output);
00347 }
00348
00357 function formatHeader($a_obj_id,$a_option)
00358 {
00359 }
00360
00369 function formatObject($a_node_id,$a_option)
00370 {
00371 global $lng;
00372
00373 if (!isset($a_node_id) or !is_array($a_option))
00374 {
00375 $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
00376 "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
00377 }
00378
00379 $tpl = new ilTemplate("tpl.tree.html", true, true);
00380
00381 foreach ($a_option["tab"] as $picture)
00382 {
00383 if ($picture == 'plus')
00384 {
00385 $target = $this->createTarget('+',$a_node_id);
00386 $tpl->setCurrentBlock("expander");
00387 $tpl->setVariable("LINK_TARGET", $target);
00388 $tpl->setVariable("IMGPATH", ilUtil::getImagePath("browser/plus.gif"));
00389 $tpl->parseCurrentBlock();
00390 }
00391
00392 if ($picture == 'minus')
00393 {
00394 $target = $this->createTarget('-',$a_node_id);
00395 $tpl->setCurrentBlock("expander");
00396 $tpl->setVariable("LINK_TARGET", $target);
00397 $tpl->setVariable("IMGPATH", ilUtil::getImagePath("browser/minus.gif"));
00398 $tpl->parseCurrentBlock();
00399 }
00400
00401 if ($picture == 'blank' or $picture == 'winkel'
00402 or $picture == 'hoch' or $picture == 'quer' or $picture == 'ecke')
00403 {
00404 $tpl->setCurrentBlock("expander");
00405 $tpl->setVariable("IMGPATH", ilUtil::getImagePath("browser/".$picture.".gif"));
00406 $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
00407 $tpl->parseCurrentBlock();
00408 }
00409 }
00410
00411 if ($this->output_icons)
00412 {
00413 $tpl->setCurrentBlock("icon");
00414 $tpl->setVariable("ICON_IMAGE" ,ilUtil::getImagePath("icon_".$a_option["type"].".gif"));
00415 $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
00416 $tpl->parseCurrentBlock();
00417 }
00418 $tpl->setCurrentBlock("row");
00419 $target = (strpos($this->target, "?") === false) ?
00420 $this->target."?" : $this->target."&";
00421 $tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
00422 $tpl->setVariable("TITLE", $a_option["title"]);
00423
00424 if ($this->frame_target != "")
00425 {
00426 $tpl->setVariable("TARGET", " target=\"".$this->frame_target."\"");
00427 }
00428
00429 $tpl->parseCurrentBlock();
00430
00431 $this->output[] = $tpl->get();
00432 }
00433
00441 function createTarget($a_type,$a_node_id)
00442 {
00443 if (!isset($a_type) or !is_string($a_type) or !isset($a_node_id))
00444 {
00445 $this->ilias->raiseError(get_class($this)."::createTarget(): Missing parameter or wrong datatype! ".
00446 "type: ".$a_type." node_id:".$a_node_id,$this->ilias->error_obj->WARNING);
00447 }
00448
00449
00450
00451
00452 $a_node_id = $a_type == '+' ? $a_node_id : -(int) $a_node_id;
00453
00454 $sep = (is_int(strpos($this->expand_target, "?")))
00455 ? "&"
00456 : "?";
00457 return $this->expand_target.$sep."expand=".$a_node_id.$this->params_get;
00458 }
00459
00466 function setFrameTarget($a_target)
00467 {
00468 $this->frame_target = $a_target;
00469 }
00470
00476 function createLines($a_depth)
00477 {
00478 for ($i = 0; $i < count($this->format_options); ++$i)
00479 {
00480 if ($this->format_options[$i]["depth"] == $a_depth+1
00481 and !$this->format_options[$i]["container"]
00482 and $this->format_options[$i]["depth"] != 1)
00483 {
00484 $this->format_options[$i]["tab"]["$a_depth"] = "quer";
00485 }
00486
00487 if ($this->format_options[$i]["depth"] == $a_depth+2)
00488 {
00489 if ($this->is_in_array($i+1,$this->format_options[$i]["depth"]))
00490 {
00491 $this->format_options[$i]["tab"]["$a_depth"] = "winkel";
00492 }
00493 else
00494 {
00495 $this->format_options[$i]["tab"]["$a_depth"] = "ecke";
00496 }
00497 }
00498
00499 if ($this->format_options[$i]["depth"] > $a_depth+2)
00500 {
00501 if ($this->is_in_array($i+1,$a_depth+2))
00502 {
00503 $this->format_options[$i]["tab"]["$a_depth"] = "hoch";
00504 }
00505 }
00506 }
00507 }
00508
00516 function is_in_array($a_start,$a_depth)
00517 {
00518 for ($i=$a_start;$i<count($this->format_options);++$i)
00519 {
00520 if ($this->format_options[$i]["depth"] < $a_depth)
00521 {
00522 break;
00523 }
00524
00525 if ($this->format_options[$i]["depth"] == $a_depth)
00526 {
00527 return true;
00528 }
00529 }
00530 return false;
00531 }
00532
00539 function getIndex($a_data)
00540 {
00541 foreach ($this->format_options as $key => $value)
00542 {
00543 if (($value["child"] == $a_data["parent"]))
00544 {
00545 return $key;
00546 }
00547 }
00548
00549
00550 $this->ilias->raiseError(get_class($this)."::getIndex(): Error in tree. No index found!",$this->ilias->error_obj->FATAL);
00551 }
00552
00559 function addFilter($a_item)
00560 {
00561 $ispresent = 0;
00562
00563 if (is_array($this->filter))
00564 {
00565
00566 foreach ($this->filter as $item)
00567 {
00568 if ($item == $a_item)
00569 {
00570 $is_present = 1;
00571
00572 return false;
00573 }
00574 }
00575 }
00576 else
00577 {
00578 $this->filter = array();
00579 }
00580
00581 if ($is_present == 0)
00582 {
00583 $this->filter[] = $a_item;
00584
00585 }
00586
00587 return true;
00588 }
00589
00596 function delFilter($a_item)
00597 {
00598
00599 if (is_array($this->filter))
00600 {
00601
00602 $tmp = array();
00603
00604 foreach ($this->filter as $item)
00605 {
00606 if ($item != $a_item)
00607 {
00608 $tmp[] = $item;
00609 }
00610 else
00611 {
00612 $deleted = 1;
00613 }
00614 }
00615 $this->filter = $tmp;
00616 }
00617 else
00618 {
00619 return false;
00620 }
00621
00622 if ($deleted == 1)
00623 {
00624 return true;
00625 }
00626 else
00627 {
00628 return false;
00629 }
00630 }
00631
00638 function setExpand($a_node_id)
00639 {
00640
00641 if(!is_array($_SESSION["expand"]))
00642 {
00643 $_SESSION["expand"] = array($this->tree->getRootId());
00644 }
00645
00646 if ($a_node_id > 0 && !in_array($a_node_id,$_SESSION["expand"]))
00647 {
00648 array_push($_SESSION["expand"],$a_node_id);
00649 }
00650
00651 if ($a_node_id < 0)
00652 {
00653 $key = array_keys($_SESSION["expand"],-(int) $a_node_id);
00654 unset($_SESSION["expand"][$key[0]]);
00655 }
00656 $this->expanded = $_SESSION["expand"];
00657 }
00658
00665 function setFiltered($a_bool)
00666 {
00667 $this->filtered = $a_bool;
00668 return true;
00669 }
00670
00677 function checkFilter($a_item)
00678 {
00679 if (is_array($this->filter))
00680 {
00681 return in_array($a_item, $this->filter);
00682 }
00683 else
00684 {
00685 return false;
00686 }
00687 }
00688 }
00689 ?>