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 ilTabsGUI
00034 {
00035 var $target_script;
00036 var $obj_type;
00037 var $tpl;
00038 var $lng;
00039 var $tabs;
00040 var $objDefinition;
00041 var $target = array();
00042 var $sub_target = array();
00043
00048 function ilTabsGUI()
00049 {
00050 global $tpl, $objDefinition, $lng;
00051
00052 $this->tpl =& $tpl;
00053 $this->lng =& $lng;
00054 $this->objDefinition =& $objDefinition;
00055 $this->manual_activation = false;
00056 $this->subtab_manual_activation = false;
00057 $this->temp_var = "TABS";
00058 $this->sub_tabs = false;
00059 $this->back_title = "";
00060 $this->back_target = "";
00061 $this->back_2_target = "";
00062 $this->back_2_title = "";
00063 }
00064
00068 function setBackTarget($a_title, $a_target, $a_frame = "")
00069 {
00070 $this->back_title = $a_title;
00071 $this->back_target = $a_target;
00072 $this->back_frame = $a_frame;
00073 }
00074
00078 function setBack2Target($a_title, $a_target, $a_frame = "")
00079 {
00080 $this->back_2_title = $a_title;
00081 $this->back_2_target = $a_target;
00082 $this->back_2_frame = $a_frame;
00083 }
00084
00085 function getTargetsByObjectType(&$a_gui_obj, $a_type)
00086 {
00087 global $ilCtrl;
00088
00089 $d = $this->objDefinition->getProperties($a_type);
00090
00091 foreach ($d as $key => $row)
00092 {
00093 $this->addTarget($row["lng"],
00094 $ilCtrl->getLinkTarget($a_gui_obj, $row["name"]),
00095 $row["name"], get_class($a_gui_obj));
00096 }
00097 }
00098
00112 function addTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false)
00113 {
00114
00115 if(!$a_cmdClass)
00116 {
00117 $a_cmdClass = array();
00118 }
00119 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
00120 #$a_cmdClass = strtolower($a_cmdClass);
00121
00122 if ($a_activate)
00123 {
00124 $this->manual_activation = true;
00125 }
00126 $this->target[] = array("text" => $a_text, "link" => $a_link,
00127 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
00128 "activate" => $a_activate);
00129 }
00130
00134 function clearTargets()
00135 {
00136 $this->target = array();
00137 $this->back_title = "";
00138 $this->back_target = "";
00139 $this->back_2_target = "";
00140 $this->back_2_title = "";
00141 }
00142
00156 function addSubTabTarget($a_text, $a_link, $a_cmd = "", $a_cmdClass = "", $a_frame = "", $a_activate = false)
00157 {
00158
00159 if(!$a_cmdClass)
00160 {
00161 $a_cmdClass = array();
00162 }
00163 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
00164 #$a_cmdClass = strtolower($a_cmdClass);
00165
00166 if ($a_activate)
00167 {
00168 $this->subtab_manual_activation = true;
00169 }
00170 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
00171 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
00172 "activate" => $a_activate);
00173 }
00174
00182 function setTabActive($a_text)
00183 {
00184 for($i = 0; $i < count($this->target);$i++)
00185 {
00186 $this->target[$i]['activate'] = $this->target[$i]['text'] == $a_text;
00187 }
00188 if ($a_text != "")
00189 {
00190 $this->manual_activation = true;
00191 }
00192 else
00193 {
00194 $this->manual_activation = false;
00195 }
00196 return true;
00197 }
00198
00206 function setSubTabActive($a_text)
00207 {
00208 for($i = 0; $i < count($this->sub_target);$i++)
00209 {
00210 $this->sub_target[$i]['activate'] = $this->sub_target[$i]['text'] == $a_text;
00211 }
00212 $this->subtab_manual_activation = true;
00213 return true;
00214 }
00215
00219 function getHTML()
00220 {
00221 return $this->__getHTML(false,$this->manual_activation);
00222 }
00223
00227 function getSubTabHTML()
00228 {
00229 return $this->__getHTML(true,$this->subtab_manual_activation);
00230 }
00231
00232
00233
00240 function __getHTML($a_get_sub_tabs,$a_manual)
00241 {
00242 global $ilCtrl, $lng;
00243
00244 $cmd = $ilCtrl->getCmd();
00245 $cmdClass = $ilCtrl->getCmdClass();
00246
00247 if ($a_get_sub_tabs)
00248 {
00249 $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
00250 $pre = "sub";
00251 $pre2 = "SUB_";
00252 }
00253 else
00254 {
00255 $tpl = new ilTemplate("tpl.tabs.html", true, true);
00256 $pre = $pre2 = "";
00257 }
00258
00259 if ($this->back_2_title != "")
00260 {
00261 $tpl->setCurrentBlock("back_2_tab");
00262 $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
00263 $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
00264 $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
00265 $tpl->parseCurrentBlock();
00266 }
00267
00268
00269 if ($this->back_title != "")
00270 {
00271 $tpl->setCurrentBlock("back_tab");
00272 $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
00273 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
00274 $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
00275 $tpl->parseCurrentBlock();
00276 }
00277
00278 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
00279
00280 if ((count($targets) > 1) || $this->back_title != "")
00281 {
00282 foreach ($targets as $target)
00283 {
00284 $i++;
00285
00286 if (!is_array($target["cmd"]))
00287 {
00288 $target["cmd"] = array($target["cmd"]);
00289 }
00290
00291 if (!$a_manual &&
00292 (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
00293 (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
00294 {
00295 $tabtype = $pre."tabactive";
00296 }
00297 else
00298 {
00299 $tabtype = $pre."tabinactive";
00300 }
00301
00302 if ($a_manual && $target["activate"])
00303 {
00304 $tabtype = $pre."tabactive";
00305 }
00306
00307 $tpl->setCurrentBlock($pre."tab");
00308 $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
00309 $tpl->setVariable($pre2."TAB_LINK", $target["link"]);
00310 $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
00311 $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
00312 $tpl->parseCurrentBlock();
00313 }
00314 return $tpl->get();
00315 }
00316 else
00317 {
00318 return "";
00319 }
00320 }
00321 }
00322 ?>