ILIAS  Release_4_4_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  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 = "", $a_class = 'submit')
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, "class" => $a_class);
110  }
111 
119  function addFormButton($a_txt, $a_cmd, $a_acc_key = "", $a_primary = false)
120  {
121  $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
122  "acc_key" => $a_acc_key, "primary" => $a_primary);
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->setVariable('BTN_CLASS',$item['class']);
267  $tpl->parseCurrentBlock();
268  $tpl->touchBlock("item");
269  break;
270 
271  case "fbutton":
272  $tpl->setCurrentBlock("form_button");
273  $tpl->setVariable("SUB_TXT", $item["txt"]);
274  $tpl->setVariable("SUB_CMD", $item["cmd"]);
275  if($item["primary"])
276  {
277  $tpl->setVariable("SUB_CLASS", " emphsubmit");
278  }
279  $tpl->parseCurrentBlock();
280  $tpl->touchBlock("item");
281  break;
282 
283  case "input":
284  if ($item["label"])
285  {
286  $tpl->setCurrentBlock("input_label");
287  $tpl->setVariable("TXT_INPUT", $item["input"]->getTitle());
288  $tpl->parseCurrentBlock();
289  }
290  $tpl->setCurrentBlock("input");
291  $tpl->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
292  $tpl->parseCurrentBlock();
293  $tpl->touchBlock("item");
294  break;
295 
296  case "separator":
297  $tpl->touchBlock("separator");
298  $tpl->touchBlock("item");
299  break;
300 
301  case "text":
302  $tpl->setCurrentBlock("text");
303  $tpl->setVariable("VAL_TEXT", $item["text"]);
304  $tpl->touchBlock("item");
305  break;
306 
307  case "spacer":
308  $tpl->touchBlock("spacer");
309  if(!$item["width"])
310  {
311  $item["width"] = 2;
312  }
313  $tpl->setVariable("SPACER_WIDTH", $item["width"]);
314  $tpl->touchBlock("item");
315  break;
316 
317  case "link":
318  if ($item["disabled"] == false) {
319  $tpl->setCurrentBlock("link");
320  $tpl->setVariable("LINK_TXT", $item["txt"]);
321  $tpl->setVariable("LINK_URL", $item["cmd"]);
322  $tpl->parseCurrentBlock();
323  $tpl->touchBlock("item");
324  break;
325  }
326  else {
327  $tpl->setCurrentBlock("link_disabled");
328  $tpl->setVariable("LINK_DISABLED_TXT", $item["txt"]);
329  //$tpl->setVariable("LINK_URL", $item["cmd"]);
330  $tpl->parseCurrentBlock();
331  $tpl->touchBlock("item");
332  break;
333  }
334  }
335  }
336 
337  $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
338  if ($this->lead_img["img"] != "")
339  {
340  $tpl->setCurrentBlock("lead_image");
341  $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
342  $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
343  $tpl->parseCurrentBlock();
344  }
345 
346  // form?
347  if ($this->getFormAction() != "")
348  {
349  if ($this->getOpenFormTag())
350  {
351  $tpl->setCurrentBlock("form_open");
352  $tpl->setVariable("FORMACTION", $this->getFormAction());
353  if ($this->multipart)
354  {
355  $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
356  }
357  if ($this->form_target != "")
358  {
359  $tpl->setVariable("TARGET", ' target="'.$this->form_target.'" ');
360  }
361  if ($this->form_name != "")
362  {
363  $tpl->setVariable("FORMNAME", 'name="'.$this->getFormName().'"');
364  }
365 
366  $tpl->parseCurrentBlock();
367  }
368  if ($this->getCloseFormTag())
369  {
370  $tpl->touchBlock("form_close");
371  }
372  }
373 
374  // id
375  if ($this->getId() != "")
376  {
377  $tpl->setVariable("ID", ' id="'.$this->getId().'" ');
378  }
379 
380  // hidden style
381  if ($this->getHidden())
382  {
383  $tpl->setVariable("STYLE", ' style="display:none;" ');
384  }
385 
386  return $tpl->get();
387  }
388  return "";
389  }
390 }