ILIAS  Release_4_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-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  var $items = array();
16 
17  function __construct()
18  {
19 
20  }
21 
27  function setFormAction($a_val, $a_multipart = false)
28  {
29  $this->form_action = $a_val;
30  $this->multipart = $a_multipart;
31  }
32 
38  function getFormAction()
39  {
40  return $this->form_action;
41  }
42 
46  function setLeadingImage($a_img, $a_alt)
47  {
48  $this->lead_img = array("img" => $a_img, "alt" => $a_alt);
49  }
50 
59  function addButton($a_txt, $a_cmd, $a_target = "", $a_acc_key = "")
60  {
61  $this->items[] = array("type" => "button", "txt" => $a_txt, "cmd" => $a_cmd,
62  "target" => $a_target, "acc_key" => $a_acc_key);
63  }
64 
72  function addFormButton($a_txt, $a_cmd, $a_acc_key = "")
73  {
74  $this->items[] = array("type" => "fbutton", "txt" => $a_txt, "cmd" => $a_cmd,
75  "acc_key" => $a_acc_key);
76  }
77 
81  function addInputItem($a_item, $a_output_label = false)
82  {
83  $this->items[] = array("type" => "input", "input" => $a_item, "label" => $a_output_label);
84  }
85 
89  function addSeparator()
90  {
91  $this->items[] = array("type" => "separator");
92  }
93 
97  function addSpacer()
98  {
99  $this->items[] = array("type" => "spacer");
100  }
101 
105  function getHTML()
106  {
107  global $lng;
108 
109  $tpl = new ilTemplate("tpl.toolbar.html", true, true, "Services/UIComponent/Toolbar");
110  if (count($this->items) > 0)
111  {
112  foreach($this->items as $item)
113  {
114  switch ($item["type"])
115  {
116  case "button":
117  $tpl->setCurrentBlock("button");
118  $tpl->setVariable("BTN_TXT", $item["txt"]);
119  $tpl->setVariable("BTN_LINK", $item["cmd"]);
120  if ($item["target"] != "")
121  {
122  $tpl->setVariable("BTN_TARGET", 'target="'.$item["target"].'"');
123  }
124  if ($item["acc_key"] != "")
125  {
126  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
127  $tpl->setVariable("BTN_ACC_KEY",
128  ilAccessKeyGUI::getAttribute($item["acc_key"]));
129  }
130  $tpl->parseCurrentBlock();
131  $tpl->touchBlock("item");
132  break;
133 
134  case "fbutton":
135  $tpl->setCurrentBlock("form_button");
136  $tpl->setVariable("SUB_TXT", $item["txt"]);
137  $tpl->setVariable("SUB_CMD", $item["cmd"]);
138  $tpl->parseCurrentBlock();
139  $tpl->touchBlock("item");
140  break;
141 
142  case "input":
143  if ($item["label"])
144  {
145  $tpl->setCurrentBlock("input_label");
146  $tpl->setVariable("TXT_INPUT", $item["input"]->getTitle());
147  $tpl->parseCurrentBlock();
148  }
149  $tpl->setCurrentBlock("input");
150  $tpl->setVariable("INPUT_HTML", $item["input"]->getToolbarHTML());
151  $tpl->parseCurrentBlock();
152  $tpl->touchBlock("item");
153  break;
154 
155  case "separator":
156  $tpl->touchBlock("separator");
157  $tpl->touchBlock("item");
158  break;
159 
160  case "spacer":
161  $tpl->touchBlock("spacer");
162  $tpl->touchBlock("item");
163  break;
164  }
165  }
166 
167  $tpl->setVariable("TXT_FUNCTIONS", $lng->txt("functions"));
168  if ($this->lead_img["img"] != "")
169  {
170  $tpl->setCurrentBlock("lead_image");
171  $tpl->setVariable("IMG_SRC", $this->lead_img["img"]);
172  $tpl->setVariable("IMG_ALT", $this->lead_img["alt"]);
173  $tpl->parseCurrentBlock();
174  }
175 
176  // form?
177  if ($this->getFormAction() != "")
178  {
179  $tpl->setCurrentBlock("form_open");
180  $tpl->setVariable("FORMACTION", $this->getFormAction());
181  if ($this->multipart)
182  {
183  $tpl->setVariable("ENC_TYPE", 'enctype="multipart/form-data"');
184  }
185  $tpl->parseCurrentBlock();
186  $tpl->touchBlock("form_close");
187  }
188 
189  return $tpl->get();
190  }
191  return "";
192  }
193 }