ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
36 {
37  var $ilias;
38  var $tpl;
39  var $lng;
40  var $obj;
41  var $ctrl;
43  var $actions;
44 
45 
51  function ilLMObjectGUI(&$a_content_obj)
52  {
53  global $ilias, $tpl, $lng, $ilCtrl;
54 
55  $this->ilias =& $ilias;
56  $this->tpl =& $tpl;
57  $this->lng =& $lng;
58  $this->ctrl =& $ilCtrl;
59  $this->content_object =& $a_content_obj;
60  }
61 
62 
70  function setActions($a_actions = "")
71  {
72  if (is_array($a_actions))
73  {
74  foreach ($a_actions as $name => $lng)
75  {
76  $this->actions[$name] = array("name" => $name, "lng" => $lng);
77  }
78  }
79  else
80  {
81  $this->actions = "";
82  }
83  }
84 
85 
93  function getTargetFrame($a_cmd, $a_target_frame = "")
94  {
95  if ($this->target_frame[$a_cmd] != "")
96  {
97  return $this->target_frame[$a_cmd];
98  }
99  elseif (!empty($a_target_frame))
100  {
101  return "target=\"".$a_target_frame."\"";
102  }
103  else
104  {
105  return;
106  }
107  }
108 
117  function getTemplateFile($a_cmd,$a_type = "")
118  {
119  if (!$a_type)
120  {
121  $a_type = $_GET["type"];
122  }
123 
124  $template = "tpl.".$a_type."_".$a_cmd.".html";
125 
126  if (!$this->tpl->fileExists($template))
127  {
128  $template = "tpl.obj_".$a_cmd.".html";
129  }
130 
131  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", $template);
132  }
133 
134 
138  function create()
139  {
140  global $rbacsystem;
141 
142  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
143 
144  // fill in saved values in case of error
145  $data = array();
146  $data["fields"] = array();
147  $data["fields"]["title"] = $_SESSION["error_post_vars"]["Fobject"]["title"];
148  $data["fields"]["desc"] = $_SESSION["error_post_vars"]["Fobject"]["desc"];
149 
150  $this->getTemplateFile("edit",$new_type);
151 
152  foreach ($data["fields"] as $key => $val)
153  {
154  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
155  $this->tpl->setVariable(strtoupper($key), $val);
156 
157  if ($this->prepare_output)
158  {
159  $this->tpl->parseCurrentBlock();
160  }
161  }
162  $this->ctrl->setParameter($this, "new_type", $new_type);
163 //echo "<br>lmobjectgui_formaction";
164 //echo ":".$this->ctrl->getFormAction($this, "save", "bla").":";
165  $this->tpl->setVariable("FORMACTION",
166  $this->ctrl->getFormAction($this, "save"));
167  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
168  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
169  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
170  $this->tpl->setVariable("CMD_SUBMIT", "save");
171  $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
172  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
173 
174  }
175 
176 
180  function putInTree()
181  {
182  $tree = new ilTree($this->content_object->getId());
183  $tree->setTableNames('lm_tree', 'lm_data');
184  $tree->setTreeTablePK("lm_id");
185 
186  $parent_id = (!empty($_GET["obj_id"]))
187  ? $_GET["obj_id"]
188  : $tree->getRootId();
189 
190  if (!empty($_GET["target"]))
191  {
192  $target = $_GET["target"];
193  }
194  else
195  {
196  // determine last child of current type
197  $childs =& $tree->getChildsByType($parent_id, $this->obj->getType());
198  if (count($childs) == 0)
199  {
200  $target = IL_FIRST_NODE;
201  }
202  else
203  {
204  $target = $childs[count($childs) - 1]["obj_id"];
205  }
206  }
207  if (!$tree->isInTree($this->obj->getId()))
208  {
209  $tree->insertNode($this->obj->getId(), $parent_id, $target);
210  }
211  }
212 
213 
217  function delete()
218  {
219  $this->setTabs();
220 
221  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
222  true, false);
223  $cont_obj_gui->delete($this->obj->getId());
224  }
225 
226 
230  function cancelDelete()
231  {
232  session_unregister("saved_post");
233  $this->ctrl->redirect($this, $_GET["backcmd"]);
234  }
235 
236 
240  function confirmedDelete()
241  {
242  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
243  true, false);
244  $cont_obj_gui->confirmedDelete($this->obj->getId());
245  $this->ctrl->redirect($this, $_GET["backcmd"]);
246  }
247 
248 
252  function add_cell($val, $link = "")
253  {
254  if(!empty($link))
255  {
256  $this->tpl->setCurrentBlock("begin_link");
257  $this->tpl->setVariable("LINK_TARGET", $link);
258  $this->tpl->parseCurrentBlock();
259  $this->tpl->touchBlock("end_link");
260  }
261 
262  $this->tpl->setCurrentBlock("text");
263  $this->tpl->setVariable("TEXT_CONTENT", $val);
264  $this->tpl->parseCurrentBlock();
265  $this->tpl->setCurrentBlock("table_cell");
266  $this->tpl->parseCurrentBlock();
267  }
268 
269 
275  function showActions($a_actions)
276  {
277  foreach ($a_actions as $name => $lng)
278  {
279  $d[$name] = array("name" => $name, "lng" => $lng);
280  }
281 
282  $notoperations = array();
283  $operations = array();
284 
285  $operations = $d;
286 
287  if (count($operations) > 0)
288  {
289  foreach ($operations as $val)
290  {
291  $this->tpl->setCurrentBlock("operation_btn");
292  $this->tpl->setVariable("BTN_NAME", $val["name"]);
293  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
294  $this->tpl->parseCurrentBlock();
295  }
296 
297  $this->tpl->setCurrentBlock("operation");
298  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
299  $this->tpl->parseCurrentBlock();
300  }
301  }
302 
306  function checkTree()
307  {
308  $this->content_object->checkTree();
309  }
310 }
311 ?>