ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
17 {
18  var $ilias;
19  var $tpl;
20  var $lng;
21  var $obj;
22  var $ctrl;
24  var $actions;
25 
26 
32  function ilLMObjectGUI(&$a_content_obj)
33  {
34  global $ilias, $tpl, $lng, $ilCtrl;
35 
36  $this->ilias =& $ilias;
37  $this->tpl =& $tpl;
38  $this->lng =& $lng;
39  $this->ctrl =& $ilCtrl;
40  $this->content_object =& $a_content_obj;
41  }
42 
43 
51  function setActions($a_actions = "")
52  {
53  if (is_array($a_actions))
54  {
55  foreach ($a_actions as $name => $lng)
56  {
57  $this->actions[$name] = array("name" => $name, "lng" => $lng);
58  }
59  }
60  else
61  {
62  $this->actions = "";
63  }
64  }
65 
66 
74  function getTargetFrame($a_cmd, $a_target_frame = "")
75  {
76  if ($this->target_frame[$a_cmd] != "")
77  {
78  return $this->target_frame[$a_cmd];
79  }
80  elseif (!empty($a_target_frame))
81  {
82  return "target=\"".$a_target_frame."\"";
83  }
84  else
85  {
86  return;
87  }
88  }
89 
98  function getTemplateFile($a_cmd,$a_type = "")
99  {
100  if (!$a_type)
101  {
102  $a_type = $_GET["type"];
103  }
104 
105  $template = "tpl.".$a_type."_".$a_cmd.".html";
106 
107  if (!$this->tpl->fileExists($template))
108  {
109  $template = "tpl.obj_".$a_cmd.".html";
110  }
111 
112  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", $template);
113  }
114 
115 
119  function create()
120  {
121  global $rbacsystem;
122 
123  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
124 
125  // fill in saved values in case of error
126  $data = array();
127  $data["fields"] = array();
128  $data["fields"]["title"] = $_SESSION["error_post_vars"]["Fobject"]["title"];
129  $data["fields"]["desc"] = $_SESSION["error_post_vars"]["Fobject"]["desc"];
130 
131  $this->getTemplateFile("edit",$new_type);
132 
133  foreach ($data["fields"] as $key => $val)
134  {
135  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
136  $this->tpl->setVariable(strtoupper($key), $val);
137 
138  if ($this->prepare_output)
139  {
140  $this->tpl->parseCurrentBlock();
141  }
142  }
143  $this->ctrl->setParameter($this, "new_type", $new_type);
144 //echo "<br>lmobjectgui_formaction";
145 //echo ":".$this->ctrl->getFormAction($this, "save", "bla").":";
146  $this->tpl->setVariable("FORMACTION",
147  $this->ctrl->getFormAction($this, "save"));
148  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
149  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
150  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
151  $this->tpl->setVariable("CMD_SUBMIT", "save");
152  $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
153  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
154 
155  }
156 
157 
161  function putInTree()
162  {
163  $tree = new ilTree($this->content_object->getId());
164  $tree->setTableNames('lm_tree', 'lm_data');
165  $tree->setTreeTablePK("lm_id");
166 
167  $parent_id = (!empty($_GET["obj_id"]))
168  ? $_GET["obj_id"]
169  : $tree->getRootId();
170 
171  if (!empty($_GET["target"]))
172  {
173  $target = $_GET["target"];
174  }
175  else
176  {
177  // determine last child of current type
178  $childs =& $tree->getChildsByType($parent_id, $this->obj->getType());
179  if (count($childs) == 0)
180  {
181  $target = IL_FIRST_NODE;
182  }
183  else
184  {
185  $target = $childs[count($childs) - 1]["obj_id"];
186  }
187  }
188  if (!$tree->isInTree($this->obj->getId()))
189  {
190  $tree->insertNode($this->obj->getId(), $parent_id, $target);
191  }
192  }
193 
194 
198  function delete()
199  {
200  $this->setTabs();
201 
202  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
203  true, false);
204  $cont_obj_gui->delete($this->obj->getId());
205  }
206 
207 
211  function cancelDelete()
212  {
213  session_unregister("saved_post");
214  $this->ctrl->redirect($this, $_GET["backcmd"]);
215  }
216 
217 
221  function confirmedDelete()
222  {
223  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
224  true, false);
225  $cont_obj_gui->confirmedDelete($this->obj->getId());
226  $this->ctrl->redirect($this, $_GET["backcmd"]);
227  }
228 
229 
233  function add_cell($val, $link = "")
234  {
235  if(!empty($link))
236  {
237  $this->tpl->setCurrentBlock("begin_link");
238  $this->tpl->setVariable("LINK_TARGET", $link);
239  $this->tpl->parseCurrentBlock();
240  $this->tpl->touchBlock("end_link");
241  }
242 
243  $this->tpl->setCurrentBlock("text");
244  $this->tpl->setVariable("TEXT_CONTENT", $val);
245  $this->tpl->parseCurrentBlock();
246  $this->tpl->setCurrentBlock("table_cell");
247  $this->tpl->parseCurrentBlock();
248  }
249 
250 
256  function showActions($a_actions)
257  {
258  foreach ($a_actions as $name => $lng)
259  {
260  $d[$name] = array("name" => $name, "lng" => $lng);
261  }
262 
263  $notoperations = array();
264  $operations = array();
265 
266  $operations = $d;
267 
268  if (count($operations) > 0)
269  {
270  foreach ($operations as $val)
271  {
272  $this->tpl->setCurrentBlock("operation_btn");
273  $this->tpl->setVariable("BTN_NAME", $val["name"]);
274  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
275  $this->tpl->parseCurrentBlock();
276  }
277 
278  $this->tpl->setCurrentBlock("operation");
279  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
280  $this->tpl->parseCurrentBlock();
281  }
282  }
283 
287  function checkTree()
288  {
289  $this->content_object->checkTree();
290  }
291 }
292 ?>