ILIAS  Release_4_4_x_branch Revision 61816
 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  'description' => $this->table->getDescription(),
122  );
123  if(!$this->table->getLimitStart())
124  $values['limit_start'] = NULL;
125  if(!$this->table->getLimitEnd())
126  $values['limit_end'] = NULL;
127  $this->form->setValuesByArray($values);
128  }
129 
133  public function getStandardValues()
134  {
135  $values = array(
136  'title' => "",
137  'is_visible' => 1,
138  'add_perm' => 1,
139  'edit_perm' => 1,
140  'delete_perm' => 1,
141  'edit_by_owner' => 1,
142  'export_enabled' => 0,
143  'limited' => 0,
144  'limit_start' => NULL,
145  'limit_end' => NULL
146  );
147  $this->form->setValuesByArray($values);
148  }
149 
150  /*
151  * cancel
152  */
153  public function cancel()
154  {
155  global $ilCtrl;
156 
157  $ilCtrl->redirectByClass("ilDataCollectionFieldListGUI", "listFields");
158  }
159 
165  public function initForm($a_mode = "create")
166  {
167  global $ilCtrl, $ilErr, $lng;
168 
169  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
170  $this->form = new ilPropertyFormGUI();
171 
172  $item = new ilTextInputGUI($lng->txt('title'),'title');
173  $item->setRequired(true);
174  $this->form->addItem($item);
175  $item = new ilCheckboxInputGUI($lng->txt('dcl_visible'),'is_visible');
176  $this->form->addItem($item);
177 
178  $item = new ilTextAreaInputGUI($lng->txt('additional_info'), 'description');
179  $item->setUseRte(true);
180 // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
181  $item->setRteTagSet('mini');
182  $this->form->addItem($item);
183 
185  $section->setTitle($lng->txt('dcl_permissions_form'));
186  $this->form->addItem($section);
187 
188  $item = new ilCustomInputGUI();
189  $item->setHtml($lng->txt('dcl_table_info'));
190  $item->setTitle($lng->txt('dcl_table_info_title'));
191  $this->form->addItem($item);
192 
193  $item = new ilCheckboxInputGUI($lng->txt('dcl_add_perm'),'add_perm');
194 // $item->setInfo($lng->txt("dcl_add_perm_info"));
195  $this->form->addItem($item);
196  $item = new ilCheckboxInputGUI($lng->txt('dcl_edit_perm'),'edit_perm');
197 // $item->setInfo($lng->txt("dcl_edit_perm_info"));
198  $this->form->addItem($item);
199  $item = new ilCheckboxInputGUI($lng->txt('dcl_delete_perm'),'delete_perm');
200 // $item->setInfo($lng->txt("dcl_delete_perm_info"));
201  $this->form->addItem($item);
202  $item = new ilCheckboxInputGUI($lng->txt('dcl_edit_by_owner'),'edit_by_owner');
203 // $item->setInfo($lng->txt("dcl_edit_by_owner_info"));
204  $this->form->addItem($item);
205 
206  $item = new ilCheckboxInputGUI($lng->txt('dcl_export_enabled'), 'export_enabled');
207  $this->form->addItem($item);
208 
209  $item = new ilCheckboxInputGUI($lng->txt('dcl_limited'),'limited');
210  $sitem1 = new ilDateTimeInputGUI($lng->txt('dcl_limit_start'),'limit_start');
211  $sitem1->setShowTime(true);
212  $sitem2 = new ilDateTimeInputGUI($lng->txt('dcl_limit_end'),'limit_end');
213  $sitem2->setShowTime(true);
214 // $item->setInfo($lng->txt("dcl_limited_info"));
215  $item->addSubItem($sitem1);
216  $item->addSubItem($sitem2);
217  $this->form->addItem($item);
218  if($a_mode == "edit")
219  {
220  $this->form->addCommandButton('update', $lng->txt('dcl_table_'.$a_mode));
221  }
222  else
223  {
224  $this->form->addCommandButton('save', $lng->txt('dcl_table_'.$a_mode));
225  }
226 
227  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
228  $this->form->setFormAction($ilCtrl->getFormAction($this, $a_mode));
229  if($a_mode == "edit")
230  {
231  $this->form->setTitle($lng->txt('dcl_edit_table'));
232  }
233  else
234  {
235  $this->form->setTitle($lng->txt('dcl_new_table'));
236  }
237  }
238 
239 
245  public function save($a_mode = "create")
246  {
247  global $ilCtrl, $ilTabs, $lng;
248 
249  if(!ilObjDataCollection::_checkAccess($this->obj_id))
250  {
251  $this->accessDenied();
252  return;
253  }
254 
255  $ilTabs->activateTab("id_fields");
256 
257  $this->initForm($a_mode);
258 
259  if($this->checkInput($a_mode))
260  {
261  if($a_mode != "update")
262  {
263  $this->table = ilDataCollectionCache::getTableCache();
264  }
265  elseif($this->table_id)
266  {
267  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
268  }
269  else
270  {
271  $ilCtrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
272  }
273 
274 
275  $this->table->setTitle($this->form->getInput("title"));
276  $this->table->setObjId($this->obj_id);
277  $this->table->setIsVisible($this->form->getInput("is_visible"));
278  $this->table->setAddPerm($this->form->getInput("add_perm"));
279  $this->table->setEditPerm($this->form->getInput("edit_perm"));
280  $this->table->setDeletePerm($this->form->getInput("delete_perm"));
281  $this->table->setEditByOwner($this->form->getInput("edit_by_owner"));
282  $this->table->setExportEnabled($this->form->getInput("export_enabled"));
283  $this->table->setDescription($this->form->getInput('description'));
284  $this->table->setLimited($this->form->getInput("limited"));
285  $limit_start = $this->form->getInput("limit_start");
286  $limit_end = $this->form->getInput("limit_end");
287  $this->table->setLimitStart($limit_start["date"]." ".$limit_start["time"]);
288  $this->table->setLimitEnd($limit_end["date"]." ".$limit_end["time"]);
289 
290  if(!$this->table->hasPermissionToAddTable($this->parent_object->ref_id))
291  {
292  $this->accessDenied();
293  return;
294  }
295  if($a_mode == "update")
296  {
297  $this->table->doUpdate();
298  ilUtil::sendSuccess($lng->txt("dcl_msg_table_edited"), true);
299  $ilCtrl->redirectByClass("ildatacollectiontableeditgui", "edit");
300  }
301  else
302  {
303 
304 
305 
306  $this->table->doCreate();
307  ilUtil::sendSuccess($lng->txt("dcl_msg_table_created"), true);
308  $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui","table_id", $this->table->getId());
309  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
310  }
311  }
312  else
313  {
314  global $tpl;
315  $this->form->setValuesByPost();
316  $tpl->setContent($this->form->getHTML());
317  }
318  }
319 
325  protected function checkInput($a_mode) {
326  global $lng;
327  $return = $this->form->checkInput();
328 
329  // Title of table must be unique in one DC
330  if ($a_mode == 'create') {
331  if ($title = $this->form->getInput('title')) {
332  if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
333  $inputObj = $this->form->getItemByPostVar('title');
334  $inputObj->setAlert($lng->txt("dcl_table_title_unique"));
335  $return = false;
336  }
337  }
338  }
339 
340  if (!$return) ilUtil::sendFailure($lng->txt("form_input_not_valid"));
341  return $return;
342  }
343 
344  /*
345  * accessDenied
346  */
347  public function accessDenied()
348  {
349  global $tpl;
350 
351  $tpl->setContent("Access denied.");
352  }
353 
357  public function confirmDelete()
358  {
359  global $ilCtrl, $lng, $tpl;
360 
361  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
362  $conf = new ilConfirmationGUI();
363  $conf->setFormAction($ilCtrl->getFormAction($this));
364  $conf->setHeaderText($lng->txt('dcl_confirm_delete_table'));
365 
366  $conf->addItem('table', (int) $this->table->getId(), $this->table->getTitle());
367 
368  $conf->setConfirm($lng->txt('delete'), 'delete');
369  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
370 
371  $tpl->setContent($conf->getHTML());
372  }
373 
377  public function cancelDelete()
378  {
379  global $ilCtrl;
380 
381  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
382  }
383 
384  /*
385  * delete
386  */
387  public function delete()
388  {
389  global $ilCtrl, $lng;
390  $mainTableId = $this->table->getCollectionObject()->getMainTableId();
391  if($mainTableId == $this->table->getId()){
392  ilUtil::sendFailure($lng->txt("dcl_cant_delete_main_table"), true);
393  }
394  else{
395  $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $mainTableId);
396  }
397 
398  $this->table->doDelete();
399  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
400  }
401 
405  protected function checkPermission()
406  {
407  $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
409  }
410 
411 }
412 
413 ?>