ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilToolbarGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  var $items = array();
16  var $open_form_tag = true;
17  var $close_form_tag = true;
18  var $form_target = "";
19  var $form_name = "";
20 
21  function __construct()
22  {
23 
24  }
25 
31  function setFormAction($a_val, $a_multipart = false, $a_target = "")
32  {
33  $this->form_action = $a_val;
34  $this->multipart = $a_multipart;
35  $this->form_target = $a_target;
36  }
37 
43  function getFormAction()
44  {
45  return $this->form_action;
46  }
47 
51  function setLeadingImage($a_img, $a_alt)
52  {
53  $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
54  }
55 
61  function setHidden($a_val)
62  {
63  $this->hidden = $a_val;
64  }
65 
71  function getHidden()
72  {
73  return $this->hidden;
74  }
75 
81  function setId($a_val)
82  {
83  $this->id = $a_val;
84  }
85 
91  function getId()
92  {
93  return $this->id;
94  }
95 
104  public function addButton($a_txt, $a_cmd, $a_target = "", $a_acc_key = "", $a_additional_attrs = '',
105  $a_id = "")
106  {
107  $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
108  "target" => $a_target, "acc_key" => $a_acc_key, 'add_attrs' => $a_additional_attrs,
109  "id" => $a_id);
110  }
111 
119  function addFormButton($a_txt, $a_cmd, $a_acc_key = "")
120  {
121  $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
122  "acc_key" => $a_acc_key);
123  }
124 
128  public function addInputItem(ilToolbarItem $a_item, $a_output_label = false)
129  {
130  $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
131  }
132 
136  function addSeparator()
137  {
138  $this->items[] = array("type" => "separator");
139  }
140 
144  function addText($a_text)
145  {
146  $this->items[] = array("type" => "text", "text" => $a_text);
147  }
148 
152  function addSpacer($a_width = null)
153  {
154  $this->items[] = array("type" => "spacer", "width" => $a_width);
155  }
156 
157 
165  function addLink($a_caption, $a_url, $a_disabled = false)
166  {
167  $this->items[] = array("type" => "link", "txt" => $a_caption, "cmd" => $a_url, "disabled" => $a_disabled);
168  }
169 
175  function setOpenFormTag($a_val)
176  {
177  $this->open_form_tag = $a_val;
178  }
179 
185  function getOpenFormTag()
186  {
187  return $this->open_form_tag;
188  }
189 
195  function setCloseFormTag($a_val)
196  {
197  $this->close_form_tag = $a_val;
198  }
199 
205  function getCloseFormTag()
206  {
207  return $this->close_form_tag;
208  }
209 
215  function setFormName($a_val)
216  {
217  $this->form_name = $a_val;
218  }
219 
225  function getFormName()
226  {
227  return $this->form_name;
228  }
229 
233  function getHTML()
234  {
235  global $lng;
236 
237  $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
238  if (count($this->items) > 0)
239  {
240  foreach($this->items as $item)
241  {
242  switch ($item["type"])
243  {
244  case "button":
245  $tpl->setCurrentBlock("button");
246  $tpl->setVariable("BTN_TXT", $item["txt"]);
247  $tpl->setVariable("BTN_LINK", $item["cmd"]);
248  if ($item["target"] != "")
249  {
250  $tpl->setVariable("BTN_TARGET", 'target="'.$item["target"].'"');
251  }
252  if ($item["id"] != "")
253  {
254  $tpl->setVariable("BID", 'id="'.$item["id"].'"');
255  }
256  if ($item["acc_key"] != "")
257  {
258  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
259  $tpl->setVariable("BTN_ACC_KEY",
260  ilAccessKeyGUI::getAttribute($item["acc_key"]));
261  }
262  if(($item['add_attrs']))
263  {
264  $tpl->setVariable('BTN_ADD_ARG',$item['add_attrs']);
265  }
266  $tpl->parseCurrentBlock();
267  $tpl->touchBlock("item");
268  break;
269 
270  case "fbutton":
271  $tpl->setCurrentBlock("form_button");
272  $tpl->setVariable("SUB_TXT", $item["txt"]);
273  $tpl->setVariable("SUB_CMD", $item["cmd"]);
274  $tpl->parseCurrentBlock();
275  $tpl->touchBlock("item");
276  break;
277 
278  case "input":
279  if ($item["label"])
280  {
281  $tpl->setCurrentBlock("input_label");
282  $tpl->setVariable("TXT_INPUT", $item["input"]->getTitle());
283  $tpl->parseCurrentBlock();
284  }
285  $tpl->setCurrentBlock("input");
286  $tpl->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
287  $tpl->parseCurrentBlock();
288  $tpl->touchBlock("item");
289  break;
290 
291  case "separator":
292  $tpl->touchBlock("separator");
293  $tpl->touchBlock("item");
294  break;
295 
296  case "text":
297  $tpl->setCurrentBlock("text");
298  $tpl->setVariable("VAL_TEXT", $item["text"]);
299  $tpl->touchBlock("item");
300  break;
301 
302  case "spacer":
303  $tpl->touchBlock("spacer");
304  if(!$item["width"])
305  {
306  $item["width"] = 2;
307  }
308  $tpl->setVariable("SPACER_WIDTH", $item["width"]);
309  $tpl->touchBlock("item");
310  break;
311 
312  case "link":
313  if ($item["disabled"] == false) {
314  $tpl->setCurrentBlock("link");
315  $tpl->setVariable("LINK_TXT", $item["txt"]);
316  $tpl->setVariable("LINK_URL", $item["cmd"]);
317  $tpl->parseCurrentBlock();
318  $tpl->touchBlock("item");
319  break;
320  }
321  else {
322  $tpl->setCurrentBlock("link_disabled");
323  $tpl->setVariable("LINK_DISABLED_TXT", $item["txt"]);
324  //$tpl->setVariable("LINK_URL", $item["cmd"]);
325  $tpl->parseCurrentBlock();
326  $tpl->touchBlock("item");
327  break;
328  }
329  }
330  }
331 
332  $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
333  if ($this->lead_img["img"] != "")
334  {
335  $tpl->setCurrentBlock("lead_image");
336  $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
337  $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
338  $tpl->parseCurrentBlock();
339  }
340 
341  // form?
342  if ($this->getFormAction() != "")
343  {
344  if ($this->getOpenFormTag())
345  {
346  $tpl->setCurrentBlock("form_open");
347  $tpl->setVariable("FORMACTION", $this->getFormAction());
348  if ($this->multipart)
349  {
350  $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
351  }
352  if ($this->form_target != "")
353  {
354  $tpl->setVariable("TARGET", ' target="'.$this->form_target.'" ');
355  }
356  if ($this->form_name != "")
357  {
358  $tpl->setVariable("FORMNAME", 'name="'.$this->getFormName().'"');
359  }
360 
361  $tpl->parseCurrentBlock();
362  }
363  if ($this->getCloseFormTag())
364  {
365  $tpl->touchBlock("form_close");
366  }
367  }
368 
369  // id
370  if ($this->getId() != "")
371  {
372  $tpl->setVariable("ID", ' id="'.$this->getId().'" ');
373  }
374 
375  // hidden style
376  if ($this->getHidden())
377  {
378  $tpl->setVariable("STYLE", ' style="display:none;" ');
379  }
380 
381  return $tpl->get();
382  }
383  return "";
384  }
385 }