ILIAS  Release_5_0_x_branch Revision 61816
 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  protected $prevent_double_submission = false;
22 
23  function __construct()
24  {
25 
26  }
27 
33  function setFormAction($a_val, $a_multipart = false, $a_target = "")
34  {
35  $this->form_action = $a_val;
36  $this->multipart = $a_multipart;
37  $this->form_target = $a_target;
38  }
39 
45  function getFormAction()
46  {
47  return $this->form_action;
48  }
49 
53  function setLeadingImage($a_img, $a_alt)
54  {
55  $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
56  }
57 
63  function setHidden($a_val)
64  {
65  $this->hidden = $a_val;
66  }
67 
73  function getHidden()
74  {
75  return $this->hidden;
76  }
77 
83  function setId($a_val)
84  {
85  $this->id = $a_val;
86  }
87 
93  function getId()
94  {
95  return $this->id;
96  }
97 
103  public function setPreventDoubleSubmission($a_val)
104  {
105  $this->prevent_double_submission = $a_val;
106  }
107 
113  public function getPreventDoubleSubmission()
114  {
116  }
117 
128  public function addButton($a_txt, $a_cmd, $a_target = "", $a_acc_key = "", $a_additional_attrs = '',
129  $a_id = "", $a_class = 'submit')
130  {
131  $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
132  "target" => $a_target, "acc_key" => $a_acc_key, 'add_attrs' => $a_additional_attrs,
133  "id" => $a_id, "class" => $a_class);
134  }
135 
147  function addFormButton($a_txt, $a_cmd, $a_acc_key = "", $a_primary = false, $a_class = false)
148  {
149  $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
150  "acc_key" => $a_acc_key, "primary" => $a_primary, "class" => $a_class);
151  }
152 
156  public function addInputItem(ilToolbarItem $a_item, $a_output_label = false)
157  {
158  $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
159  }
160 
166  public function addButtonInstance(ilButton $a_button)
167  {
168  $this->items[] = array("type" => "button_obj", "instance" => $a_button);
169  }
170 
171  // bs-patch start
175  public function addDropDown($a_txt, $a_dd_html)
176  {
177  $this->items[] = array("type" => "dropdown", "txt" => $a_txt, "dd_html" => $a_dd_html);
178  }
179  // bs-patch end
180 
184  function addSeparator()
185  {
186  $this->items[] = array("type" => "separator");
187  }
188 
192  function addText($a_text)
193  {
194  $this->items[] = array("type" => "text", "text" => $a_text);
195  }
196 
200  function addSpacer($a_width = null)
201  {
202  $this->items[] = array("type" => "spacer", "width" => $a_width);
203  }
204 
205 
213  function addLink($a_caption, $a_url, $a_disabled = false)
214  {
215  $this->items[] = array("type" => "link", "txt" => $a_caption, "cmd" => $a_url, "disabled" => $a_disabled);
216  }
217 
223  function setOpenFormTag($a_val)
224  {
225  $this->open_form_tag = $a_val;
226  }
227 
233  function getOpenFormTag()
234  {
235  return $this->open_form_tag;
236  }
237 
243  function setCloseFormTag($a_val)
244  {
245  $this->close_form_tag = $a_val;
246  }
247 
253  function getCloseFormTag()
254  {
255  return $this->close_form_tag;
256  }
257 
263  function setFormName($a_val)
264  {
265  $this->form_name = $a_val;
266  }
267 
273  function getFormName()
274  {
275  return $this->form_name;
276  }
277 
281  function getHTML()
282  {
283  global $lng;
284 
285  $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
286  if (count($this->items) > 0)
287  {
288  foreach($this->items as $item)
289  {
290  switch ($item["type"])
291  {
292  case "button":
293  $tpl->setCurrentBlock("button");
294  $tpl->setVariable("BTN_TXT", $item["txt"]);
295  $tpl->setVariable("BTN_LINK", $item["cmd"]);
296  if ($item["target"] != "")
297  {
298  $tpl->setVariable("BTN_TARGET", 'target="'.$item["target"].'"');
299  }
300  if ($item["id"] != "")
301  {
302  $tpl->setVariable("BID", 'id="'.$item["id"].'"');
303  }
304  if ($item["acc_key"] != "")
305  {
306  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
307  $tpl->setVariable("BTN_ACC_KEY",
308  ilAccessKeyGUI::getAttribute($item["acc_key"]));
309  }
310  if(($item['add_attrs']))
311  {
312  $tpl->setVariable('BTN_ADD_ARG',$item['add_attrs']);
313  }
314  $tpl->setVariable('BTN_CLASS',$item['class']);
315  $tpl->parseCurrentBlock();
316  $tpl->touchBlock("item");
317  break;
318 
319  case "fbutton":
320  $tpl->setCurrentBlock("form_button");
321  $tpl->setVariable("SUB_TXT", $item["txt"]);
322  $tpl->setVariable("SUB_CMD", $item["cmd"]);
323  if($item["primary"])
324  {
325  $tpl->setVariable("SUB_CLASS", " emphsubmit");
326  }
327  else if($item["class"])
328  {
329  $tpl->setVariable("SUB_CLASS", " ".$item["class"]);
330  }
331  $tpl->parseCurrentBlock();
332  $tpl->touchBlock("item");
333  break;
334 
335  case "button_obj":
336  $tpl->setCurrentBlock("button_instance");
337  $tpl->setVariable("BUTTON_OBJ", $item["instance"]->render());
338  $tpl->parseCurrentBlock();
339  $tpl->touchBlock("item");
340  break;
341 
342  case "input":
343  if ($item["label"])
344  {
345  $tpl->setCurrentBlock("input_label");
346  $tpl->setVariable("TXT_INPUT", $item["input"]->getTitle());
347  $tpl->parseCurrentBlock();
348  }
349  $tpl->setCurrentBlock("input");
350  $tpl->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
351  $tpl->parseCurrentBlock();
352  $tpl->touchBlock("item");
353  break;
354 
355  // bs-patch start
356  case "dropdown":
357  $tpl->setCurrentBlock("dropdown");
358  $tpl->setVariable("TXT_DROPDOWN", $item["txt"]);
359  $tpl->setVariable("DROP_DOWN", $item["dd_html"]);
360  $tpl->parseCurrentBlock();
361  $tpl->touchBlock("item");
362  break;
363  // bs-patch end
364 
365 
366  case "separator":
367  $tpl->touchBlock("separator");
368  $tpl->touchBlock("item");
369  break;
370 
371  case "text":
372  $tpl->setCurrentBlock("text");
373  $tpl->setVariable("VAL_TEXT", $item["text"]);
374  $tpl->touchBlock("item");
375  break;
376 
377  case "spacer":
378  $tpl->touchBlock("spacer");
379  if(!$item["width"])
380  {
381  $item["width"] = 2;
382  }
383  $tpl->setVariable("SPACER_WIDTH", $item["width"]);
384  $tpl->touchBlock("item");
385  break;
386 
387  case "link":
388  if ($item["disabled"] == false) {
389  $tpl->setCurrentBlock("link");
390  $tpl->setVariable("LINK_TXT", $item["txt"]);
391  $tpl->setVariable("LINK_URL", $item["cmd"]);
392  $tpl->parseCurrentBlock();
393  $tpl->touchBlock("item");
394  break;
395  }
396  else {
397  $tpl->setCurrentBlock("link_disabled");
398  $tpl->setVariable("LINK_DISABLED_TXT", $item["txt"]);
399  //$tpl->setVariable("LINK_URL", $item["cmd"]);
400  $tpl->parseCurrentBlock();
401  $tpl->touchBlock("item");
402  break;
403  }
404  }
405  }
406 
407  $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
408  if ($this->lead_img["img"] != "")
409  {
410  $tpl->setCurrentBlock("lead_image");
411  $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
412  $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
413  $tpl->parseCurrentBlock();
414  }
415 
416  // form?
417  if ($this->getFormAction() != "")
418  {
419  if ($this->getOpenFormTag())
420  {
421  $tpl->setCurrentBlock("form_open");
422  $tpl->setVariable("FORMACTION", $this->getFormAction());
423  if($this->getPreventDoubleSubmission())
424  {
425  $tpl->setVariable("FORM_CLASS", "preventDoubleSubmission");
426  }
427  if ($this->multipart)
428  {
429  $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
430  }
431  if ($this->form_target != "")
432  {
433  $tpl->setVariable("TARGET", ' target="'.$this->form_target.'" ');
434  }
435  if ($this->form_name != "")
436  {
437  $tpl->setVariable("FORMNAME", 'name="'.$this->getFormName().'"');
438  }
439 
440  $tpl->parseCurrentBlock();
441  }
442  if ($this->getCloseFormTag())
443  {
444  $tpl->touchBlock("form_close");
445  }
446  }
447 
448  // id
449  if ($this->getId() != "")
450  {
451  $tpl->setVariable("ID", ' id="'.$this->getId().'" ');
452  }
453 
454  // hidden style
455  if ($this->getHidden())
456  {
457  $tpl->setVariable("HIDDEN_CLASS", 'ilNoDisplay');
458  }
459 
460  return $tpl->get();
461  }
462  return "";
463  }
464 }