ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionTableEditGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
6 
19 {
23  private $table_id;
27  private $table;
28 
34  public function __construct(ilObjDataCollectionGUI $a_parent_obj)
35  {
36  global $ilCtrl, $lng;
37 
38  $this->parent_object = $a_parent_obj;
39  $this->obj_id = $a_parent_obj->obj_id;
40  $this->table_id = $_GET['table_id'];
41  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
42  if ( ! $this->checkPermission()) {
43  ilUtil::sendFailure($lng->txt('permission_denied'), true);
44  $ilCtrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
45  }
46  }
47 
48 
52  public function executeCommand()
53  {
54  global $tpl, $ilCtrl, $ilUser;
55 
56  $cmd = $ilCtrl->getCmd();
57  $tpl->getStandardTemplate();
58 
59  switch($cmd)
60  {
61  case 'update':
62  $this->save("update");
63  break;
64  default:
65  $this->$cmd();
66  break;
67  }
68 
69  return true;
70  }
71 
75  public function create()
76  {
77  global $ilTabs, $tpl;
78 
79  $this->initForm();
80  $this->getStandardValues();
81  $tpl->setContent($this->form->getHTML());
82  }
83 
87  public function edit()
88  {
89  global $ilCtrl, $tpl;
90 
91  if(!$this->table_id)
92  {
93  $ilCtrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
94  return;
95  }
96  else
97  {
98  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
99  }
100  $this->initForm("edit");
101  $this->getValues();
102  $tpl->setContent($this->form->getHTML());
103  }
104 
108  public function getValues()
109  {
110  $values = array(
111  'title' => $this->table->getTitle(),
112  'add_perm' => $this->table->getAddPerm(),
113  'edit_perm' => $this->table->getEditPerm(),
114  'delete_perm' => $this->table->getDeletePerm(),
115  'edit_by_owner' => $this->table->getEditByOwner(),
116  'export_enabled' => $this->table->getExportEnabled(),
117  'limited' => $this->table->getLimited(),
118  'limit_start' => array("date" => substr($this->table->getLimitStart(),0,10), "time" => substr($this->table->getLimitStart(),-8)),
119  'limit_end' => array("date" => substr($this->table->getLimitEnd(),0,10), "time" => substr($this->table->getLimitEnd(),-8)),
120  'is_visible' => $this->table->getIsVisible()
121  );
122  if(!$this->table->getLimitStart())
123  $values['limit_start'] = NULL;
124  if(!$this->table->getLimitEnd())
125  $values['limit_end'] = NULL;
126  $this->form->setValuesByArray($values);
127  }
128 
132  public function getStandardValues()
133  {
134  $values = array(
135  'title' => "",
136  'is_visible' => 1,
137  'add_perm' => 1,
138  'edit_perm' => 1,
139  'delete_perm' => 1,
140  'edit_by_owner' => 1,
141  'export_enabled' => 0,
142  'limited' => 0,
143  'limit_start' => NULL,
144  'limit_end' => NULL
145  );
146  $this->form->setValuesByArray($values);
147  }
148 
149  /*
150  * cancel
151  */
152  public function cancel()
153  {
154  global $ilCtrl;
155 
156  $ilCtrl->redirectByClass("ilDataCollectionFieldListGUI", "listFields");
157  }
158 
164  public function initForm($a_mode = "create")
165  {
166  global $ilCtrl, $ilErr, $lng;
167 
168  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
169  $this->form = new ilPropertyFormGUI();
170 
171  $item = new ilTextInputGUI($lng->txt('title'),'title');
172  $item->setRequired(true);
173  $this->form->addItem($item);
174  $item = new ilCheckboxInputGUI($lng->txt('dcl_visible'),'is_visible');
175  $this->form->addItem($item);
176 
178  $section->setTitle($lng->txt('dcl_permissions_form'));
179  $this->form->addItem($section);
180 
181  $item = new ilCustomInputGUI();
182  $item->setHtml($lng->txt('dcl_table_info'));
183  $item->setTitle($lng->txt('dcl_table_info_title'));
184  $this->form->addItem($item);
185 
186  $item = new ilCheckboxInputGUI($lng->txt('dcl_add_perm'),'add_perm');
187 // $item->setInfo($lng->txt("dcl_add_perm_info"));
188  $this->form->addItem($item);
189  $item = new ilCheckboxInputGUI($lng->txt('dcl_edit_perm'),'edit_perm');
190 // $item->setInfo($lng->txt("dcl_edit_perm_info"));
191  $this->form->addItem($item);
192  $item = new ilCheckboxInputGUI($lng->txt('dcl_delete_perm'),'delete_perm');
193 // $item->setInfo($lng->txt("dcl_delete_perm_info"));
194  $this->form->addItem($item);
195  $item = new ilCheckboxInputGUI($lng->txt('dcl_edit_by_owner'),'edit_by_owner');
196 // $item->setInfo($lng->txt("dcl_edit_by_owner_info"));
197  $this->form->addItem($item);
198 
199  $item = new ilCheckboxInputGUI($lng->txt('dcl_export_enabled'), 'export_enabled');
200  $this->form->addItem($item);
201 
202  $item = new ilCheckboxInputGUI($lng->txt('dcl_limited'),'limited');
203  $sitem1 = new ilDateTimeInputGUI($lng->txt('dcl_limit_start'),'limit_start');
204  $sitem2 = new ilDateTimeInputGUI($lng->txt('dcl_limit_end'),'limit_end');
205 // $item->setInfo($lng->txt("dcl_limited_info"));
206  $item->addSubItem($sitem1);
207  $item->addSubItem($sitem2);
208  $this->form->addItem($item);
209  if($a_mode == "edit")
210  {
211  $this->form->addCommandButton('update', $lng->txt('dcl_table_'.$a_mode));
212  }
213  else
214  {
215  $this->form->addCommandButton('save', $lng->txt('dcl_table_'.$a_mode));
216  }
217 
218  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
219  $this->form->setFormAction($ilCtrl->getFormAction($this, $a_mode));
220  if($a_mode == "edit")
221  {
222  $this->form->setTitle($lng->txt('dcl_edit_table'));
223  }
224  else
225  {
226  $this->form->setTitle($lng->txt('dcl_new_table'));
227  }
228  }
229 
230 
236  public function save($a_mode = "create")
237  {
238  global $ilCtrl, $ilTabs, $lng;
239 
240  if(!ilObjDataCollection::_checkAccess($this->obj_id))
241  {
242  $this->accessDenied();
243  return;
244  }
245 
246  $ilTabs->activateTab("id_fields");
247 
248  $this->initForm($a_mode);
249 
250  if($this->checkInput($a_mode))
251  {
252  if($a_mode != "update")
253  {
254  $this->table = ilDataCollectionCache::getTableCache();
255  }
256  elseif($this->table_id)
257  {
258  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
259  }
260  else
261  {
262  $ilCtrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
263  }
264 
265 
266  $this->table->setTitle($this->form->getInput("title"));
267  $this->table->setObjId($this->obj_id);
268  $this->table->setIsVisible($this->form->getInput("is_visible"));
269  $this->table->setAddPerm($this->form->getInput("add_perm"));
270  $this->table->setEditPerm($this->form->getInput("edit_perm"));
271  $this->table->setDeletePerm($this->form->getInput("delete_perm"));
272  $this->table->setEditByOwner($this->form->getInput("edit_by_owner"));
273  $this->table->setExportEnabled($this->form->getInput("export_enabled"));
274  $this->table->setLimited($this->form->getInput("limited"));
275  $limit_start = $this->form->getInput("limit_start");
276  $limit_end = $this->form->getInput("limit_end");
277  $this->table->setLimitStart($limit_start["date"]." ".$limit_start["time"]);
278  $this->table->setLimitEnd($limit_end["date"]." ".$limit_end["time"]);
279 
280  if(!$this->table->hasPermissionToAddTable($this->parent_object->ref_id))
281  {
282  $this->accessDenied();
283  return;
284  }
285  if($a_mode == "update")
286  {
287  $this->table->doUpdate();
288  ilUtil::sendSuccess($lng->txt("dcl_msg_table_edited"), true);
289  $ilCtrl->redirectByClass("ildatacollectiontableeditgui", "edit");
290  }
291  else
292  {
293 
294 
295 
296  $this->table->doCreate();
297  ilUtil::sendSuccess($lng->txt("dcl_msg_table_created"), true);
298  $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui","table_id", $this->table->getId());
299  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
300  }
301  }
302  else
303  {
304  global $tpl;
305  $this->form->setValuesByPost();
306  $tpl->setContent($this->form->getHTML());
307  }
308  }
309 
315  protected function checkInput($a_mode) {
316  global $lng;
317  $return = $this->form->checkInput();
318 
319  // Title of table must be unique in one DC
320  if ($a_mode == 'create') {
321  if ($title = $this->form->getInput('title')) {
322  if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
323  $inputObj = $this->form->getItemByPostVar('title');
324  $inputObj->setAlert($lng->txt("dcl_table_title_unique"));
325  $return = false;
326  }
327  }
328  }
329 
330  if (!$return) ilUtil::sendFailure($lng->txt("form_input_not_valid"));
331  return $return;
332  }
333 
334  /*
335  * accessDenied
336  */
337  public function accessDenied()
338  {
339  global $tpl;
340 
341  $tpl->setContent("Access denied.");
342  }
343 
347  public function confirmDelete()
348  {
349  global $ilCtrl, $lng, $tpl;
350 
351  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
352  $conf = new ilConfirmationGUI();
353  $conf->setFormAction($ilCtrl->getFormAction($this));
354  $conf->setHeaderText($lng->txt('dcl_confirm_delete_table'));
355 
356  $conf->addItem('table', (int) $this->table->getId(), $this->table->getTitle());
357 
358  $conf->setConfirm($lng->txt('delete'), 'delete');
359  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
360 
361  $tpl->setContent($conf->getHTML());
362  }
363 
367  public function cancelDelete()
368  {
369  global $ilCtrl;
370 
371  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
372  }
373 
374  /*
375  * delete
376  */
377  public function delete()
378  {
379  global $ilCtrl, $lng;
380  $mainTableId = $this->table->getCollectionObject()->getMainTableId();
381  if($mainTableId == $this->table->getId()){
382  ilUtil::sendFailure($lng->txt("dcl_cant_delete_main_table"), true);
383  }
384  else{
385  $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $mainTableId);
386  }
387 
388  $this->table->doDelete();
389  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
390  }
391 
395  protected function checkPermission()
396  {
397  $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
399  }
400 
401 }
402 
403 ?>