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
00221 function clearSubTabs()
00222 {
00223 $this->sub_target = array();
00224 return true;
00225 }
00226
00230 function getHTML()
00231 {
00232 return $this->__getHTML(false,$this->manual_activation);
00233 }
00234
00238 function getSubTabHTML()
00239 {
00240 return $this->__getHTML(true,$this->subtab_manual_activation);
00241 }
00242
00243
00244
00251 function __getHTML($a_get_sub_tabs,$a_manual)
00252 {
00253 global $ilCtrl, $lng;
00254
00255 $cmd = $ilCtrl->getCmd();
00256 $cmdClass = $ilCtrl->getCmdClass();
00257
00258 if ($a_get_sub_tabs)
00259 {
00260 $tpl = new ilTemplate("tpl.sub_tabs.html", true, true);
00261 $pre = "sub";
00262 $pre2 = "SUB_";
00263 }
00264 else
00265 {
00266 $tpl = new ilTemplate("tpl.tabs.html", true, true);
00267 $pre = $pre2 = "";
00268 }
00269
00270 if ($this->back_2_title != "")
00271 {
00272 $tpl->setCurrentBlock("back_2_tab");
00273 $tpl->setVariable("BACK_2_TAB_LINK", $this->back_2_target);
00274 $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
00275 $tpl->setVariable("BACK_2_TAB_TARGET", $this->back_2_frame);
00276 $tpl->parseCurrentBlock();
00277 }
00278
00279
00280 if ($this->back_title != "")
00281 {
00282 $tpl->setCurrentBlock("back_tab");
00283 $tpl->setVariable("BACK_TAB_LINK", $this->back_target);
00284 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
00285 $tpl->setVariable("BACK_TAB_TARGET", $this->back_frame);
00286 $tpl->parseCurrentBlock();
00287 }
00288
00289 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
00290
00291 if ((count($targets) > 1) || $this->back_title != "")
00292 {
00293 foreach ($targets as $target)
00294 {
00295 $i++;
00296
00297 if (!is_array($target["cmd"]))
00298 {
00299 $target["cmd"] = array($target["cmd"]);
00300 }
00301
00302 if (!$a_manual &&
00303 (in_array($cmd, $target["cmd"]) || ($target["cmd"][0] == "" && count($target["cmd"]) == 1)) &&
00304 (in_array($cmdClass,$target["cmdClass"]) || !$target["cmdClass"]))
00305 {
00306 $tabtype = $pre."tabactive";
00307 }
00308 else
00309 {
00310 $tabtype = $pre."tabinactive";
00311 }
00312
00313 if ($a_manual && $target["activate"])
00314 {
00315 $tabtype = $pre."tabactive";
00316 }
00317
00318 $tpl->setCurrentBlock($pre."tab");
00319 $tpl->setVariable($pre2."TAB_TYPE", $tabtype);
00320 $tpl->setVariable($pre2."TAB_LINK", $target["link"]);
00321 $tpl->setVariable($pre2."TAB_TEXT", $lng->txt($target["text"]));
00322 $tpl->setVariable($pre2."TAB_TARGET", $target["frame"]);
00323 $tpl->parseCurrentBlock();
00324 }
00325 return $tpl->get();
00326 }
00327 else
00328 {
00329 return "";
00330 }
00331 }
00332 }
00333 ?>