ILIAS  eassessment Revision 61809
 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-2009 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 
20  function __construct()
21  {
22 
23  }
24 
30  function setFormAction($a_val, $a_multipart = false, $a_target = "")
31  {
32  $this->form_action = $a_val;
33  $this->multipart = $a_multipart;
34  $this->form_target = $a_target;
35  }
36 
42  function getFormAction()
43  {
44  return $this->form_action;
45  }
46 
50  function setLeadingImage($a_img, $a_alt)
51  {
52  $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
53  }
54 
63  function addButton($a_txt, $a_cmd, $a_target = "", $a_acc_key = "", $a_additional_attrs = '')
64  {
65  $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
66  "target" => $a_target, "acc_key" => $a_acc_key, 'add_attrs' => $a_additional_attrs);
67  }
68 
76  function addFormButton($a_txt, $a_cmd, $a_acc_key = "")
77  {
78  $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
79  "acc_key" => $a_acc_key);
80  }
81 
85  function addInputItem(ilToolbarItem $a_item, $a_output_label = false)
86  {
87  $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
88  }
89 
93  function addSeparator()
94  {
95  $this->items[] = array("type" => "separator");
96  }
97 
101  function addSpacer()
102  {
103  $this->items[] = array("type" => "spacer");
104  }
105 
111  function setOpenFormTag($a_val)
112  {
113  $this->open_form_tag = $a_val;
114  }
115 
121  function getOpenFormTag()
122  {
123  return $this->open_form_tag;
124  }
125 
131  function setCloseFormTag($a_val)
132  {
133  $this->close_form_tag = $a_val;
134  }
135 
141  function getCloseFormTag()
142  {
143  return $this->close_form_tag;
144  }
145 
149  function getHTML()
150  {
151  global $lng;
152 
153  $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
154  if (count($this->items) > 0)
155  {
156  foreach($this->items as $item)
157  {
158  switch ($item["type"])
159  {
160  case "button":
161  $tpl->setCurrentBlock("button");
162  $tpl->setVariable("BTN_TXT", $item["txt"]);
163  $tpl->setVariable("BTN_LINK", $item["cmd"]);
164  if ($item["target"] != "")
165  {
166  $tpl->setVariable("BTN_TARGET", 'target="'.$item["target"].'"');
167  }
168  if ($item["acc_key"] != "")
169  {
170  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
171  $tpl->setVariable("BTN_ACC_KEY",
172  ilAccessKeyGUI::getAttribute($item["acc_key"]));
173  }
174  if(($item['add_attrs']))
175  {
176  $tpl->setVariable('BTN_ADD_ARG',$item['add_attrs']);
177  }
178  $tpl->parseCurrentBlock();
179  $tpl->touchBlock("item");
180  break;
181 
182  case "fbutton":
183  $tpl->setCurrentBlock("form_button");
184  $tpl->setVariable("SUB_TXT", $item["txt"]);
185  $tpl->setVariable("SUB_CMD", $item["cmd"]);
186  $tpl->parseCurrentBlock();
187  $tpl->touchBlock("item");
188  break;
189 
190  case "input":
191  if ($item["label"])
192  {
193  $tpl->setCurrentBlock("input_label");
194  $tpl->setVariable("TXT_INPUT", $item["input"]->getTitle());
195  $tpl->parseCurrentBlock();
196  }
197  $tpl->setCurrentBlock("input");
198  $tpl->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
199  $tpl->parseCurrentBlock();
200  $tpl->touchBlock("item");
201  break;
202 
203  case "separator":
204  $tpl->touchBlock("separator");
205  $tpl->touchBlock("item");
206  break;
207 
208  case "spacer":
209  $tpl->touchBlock("spacer");
210  $tpl->touchBlock("item");
211  break;
212  }
213  }
214 
215  $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
216  if ($this->lead_img["img"] != "")
217  {
218  $tpl->setCurrentBlock("lead_image");
219  $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
220  $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
221  $tpl->parseCurrentBlock();
222  }
223 
224  // form?
225  if ($this->getFormAction() != "")
226  {
227  if ($this->getOpenFormTag())
228  {
229  $tpl->setCurrentBlock("form_open");
230  $tpl->setVariable("FORMACTION", $this->getFormAction());
231  if ($this->multipart)
232  {
233  $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
234  }
235  if ($this->form_target != "")
236  {
237  $tpl->setVariable("TARGET", ' target="'.$this->form_target.'" ');
238  }
239  $tpl->parseCurrentBlock();
240  }
241  if ($this->getCloseFormTag())
242  {
243  $tpl->touchBlock("form_close");
244  }
245  }
246 
247  return $tpl->get();
248  }
249  return "";
250  }
251 }