ILIAS  Release_5_0_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;
31  protected $lng;
35  protected $ctrl;
39  protected $tpl;
40 
41 
47  public function __construct(ilObjDataCollectionGUI $a_parent_obj) {
48  global $ilCtrl, $lng, $tpl;
49 
50  $this->ctrl = $ilCtrl;
51  $this->lng = $lng;
52  $this->tpl = $tpl;
53  $this->parent_object = $a_parent_obj;
54  $this->obj_id = $a_parent_obj->obj_id;
55  $this->table_id = $_GET['table_id'];
56  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
57  if (! $this->checkPermission()) {
58  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
59  $this->ctrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
60  }
61  }
62 
63 
67  public function executeCommand() {
68  $cmd = $this->ctrl->getCmd();
69  $this->tpl->getStandardTemplate();
70 
71  switch ($cmd) {
72  case 'update':
73  $this->save("update");
74  break;
75  default:
76  $this->$cmd();
77  break;
78  }
79 
80  return true;
81  }
82 
83 
87  public function create() {
88  $this->initForm();
89  $this->getStandardValues();
90  $this->tpl->setContent($this->form->getHTML());
91  }
92 
93 
97  public function edit() {
98  if (! $this->table_id) {
99  $this->ctrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
100 
101  return;
102  } else {
103  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
104  }
105  $this->initForm("edit");
106  $this->getValues();
107  $this->tpl->setContent($this->form->getHTML());
108  }
109 
110 
114  public function getValues() {
115  $values = array(
116  'title' => $this->table->getTitle(),
117  'add_perm' => $this->table->getAddPerm(),
118  'edit_perm' => $this->table->getEditPerm(),
119  'delete_perm' => $this->table->getDeletePerm(),
120  'edit_by_owner' => $this->table->getEditByOwner(),
121  'export_enabled' => $this->table->getExportEnabled(),
122  'limited' => $this->table->getLimited(),
123  'limit_start' => array( "date" => substr($this->table->getLimitStart(), 0, 10), "time" => substr($this->table->getLimitStart(), - 8) ),
124  'limit_end' => array( "date" => substr($this->table->getLimitEnd(), 0, 10), "time" => substr($this->table->getLimitEnd(), - 8) ),
125  'is_visible' => $this->table->getIsVisible(),
126  'default_sort_field' => $this->table->getDefaultSortField(),
127  'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
128  'description' => $this->table->getDescription(),
129  'public_comments' => $this->table->getPublicCommentsEnabled(),
130  'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
131  );
132  if (! $this->table->getLimitStart()) {
133  $values['limit_start'] = NULL;
134  }
135  if (! $this->table->getLimitEnd()) {
136  $values['limit_end'] = NULL;
137  }
138  $this->form->setValuesByArray($values);
139  }
140 
141 
145  public function getStandardValues() {
146  $values = array(
147  'title' => "",
148  'is_visible' => 1,
149  'add_perm' => 1,
150  'edit_perm' => 1,
151  'delete_perm' => 1,
152  'edit_by_owner' => 1,
153  'export_enabled' => 0,
154  'limited' => 0,
155  'limit_start' => NULL,
156  'limit_end' => NULL
157  );
158  $this->form->setValuesByArray($values);
159  }
160 
161 
162  /*
163  * cancel
164  */
165  public function cancel() {
166  $this->ctrl->redirectByClass("ilDataCollectionFieldListGUI", "listFields");
167  }
168 
169 
175  public function initForm($a_mode = "create") {
176  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
177  $this->form = new ilPropertyFormGUI();
178 
179  $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
180  $item->setRequired(true);
181  $this->form->addItem($item);
182  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_visible'), 'is_visible');
183  $this->form->addItem($item);
184 
185  // Show default order field and direction only in edit mode, because table id is not yet given and there are no fields to select
186  if ($a_mode != 'create') {
187  $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
188  $fields = $this->table->getVisibleFields();
189  $options = array( 0 => $this->lng->txt('dcl_please_select') );
190  foreach ($fields as $field) {
191  $options[$field->getId()] = $field->getTitle();
192  }
193  $item->setOptions($options);
194  $this->form->addItem($item);
195 
196  $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
197  $options = array( 'asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc') );
198  $item->setOptions($options);
199  $this->form->addItem($item);
200  }
201 
202  $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
203  $item->setUseRte(true);
204  // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
205  $item->setRteTagSet('mini');
206  $this->form->addItem($item);
207 
208  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_public_comments'), 'public_comments');
209  $this->form->addItem($item);
210 
212  $section->setTitle($this->lng->txt('dcl_permissions_form'));
213  $this->form->addItem($section);
214 
215  $item = new ilCustomInputGUI();
216  $item->setHtml($this->lng->txt('dcl_table_info'));
217  $item->setTitle($this->lng->txt('dcl_table_info_title'));
218  $this->form->addItem($item);
219 
220  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
221  // $item->setInfo($this->lng->txt("dcl_add_perm_info"));
222  $this->form->addItem($item);
223  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
224  // $item->setInfo($this->lng->txt("dcl_edit_perm_info"));
225  $this->form->addItem($item);
226  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
227  // $item->setInfo($this->lng->txt("dcl_delete_perm_info"));
228  $this->form->addItem($item);
229  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_by_owner'), 'edit_by_owner');
230  // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
231  $this->form->addItem($item);
232 
233  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
234  // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
235  $this->form->addItem($item);
236 
237  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
238  $this->form->addItem($item);
239 
240  $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
241  $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
242  $sitem1->setShowTime(true);
243  $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
244  $sitem2->setShowTime(true);
245  // $item->setInfo($this->lng->txt("dcl_limited_info"));
246  $item->addSubItem($sitem1);
247  $item->addSubItem($sitem2);
248  $this->form->addItem($item);
249 
250  if ($a_mode == "edit") {
251  $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
252  } else {
253  $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
254  }
255 
256  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
257  $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
258  if ($a_mode == "edit") {
259  $this->form->setTitle($this->lng->txt('dcl_edit_table'));
260  } else {
261  $this->form->setTitle($this->lng->txt('dcl_new_table'));
262  }
263  }
264 
265 
271  public function save($a_mode = "create") {
272  global $ilTabs;
273 
274  if (! ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
275  $this->accessDenied();
276 
277  return;
278  }
279 
280  $ilTabs->activateTab("id_fields");
281 
282  $this->initForm($a_mode);
283 
284  if ($this->checkInput($a_mode)) {
285  if ($a_mode != "update") {
286  $this->table = ilDataCollectionCache::getTableCache();
287  } elseif ($this->table_id) {
288  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
289  } else {
290  $this->ctrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
291  }
292 
293  $this->table->setTitle($this->form->getInput("title"));
294  $this->table->setObjId($this->obj_id);
295  $this->table->setIsVisible($this->form->getInput("is_visible"));
296  $this->table->setAddPerm($this->form->getInput("add_perm"));
297  $this->table->setEditPerm($this->form->getInput("edit_perm"));
298  $this->table->setDeletePerm($this->form->getInput("delete_perm"));
299  $this->table->setEditByOwner($this->form->getInput("edit_by_owner"));
300  $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
301  $this->table->setExportEnabled($this->form->getInput("export_enabled"));
302  $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
303  $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
304  $this->table->setPublicCommentsEnabled($this->form->getInput('public_comments'));
305  $this->table->setLimited($this->form->getInput("limited"));
306  $this->table->setDescription($this->form->getInput('description'));
307  $limit_start = $this->form->getInput("limit_start");
308  $limit_end = $this->form->getInput("limit_end");
309  $this->table->setLimitStart($limit_start["date"] . " " . $limit_start["time"]);
310  $this->table->setLimitEnd($limit_end["date"] . " " . $limit_end["time"]);
311 
312  if (! $this->table->hasPermissionToAddTable($this->parent_object->ref_id)) {
313  $this->accessDenied();
314 
315  return;
316  }
317  if ($a_mode == "update") {
318  $this->table->doUpdate();
319  ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
320  $this->ctrl->redirectByClass("ildatacollectiontableeditgui", "edit");
321  } else {
322  $this->table->doCreate();
323  ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
324  $this->ctrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->table->getId());
325  $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
326  }
327  } else {
328  $this->form->setValuesByPost();
329  $this->tpl->setContent($this->form->getHTML());
330  }
331  }
332 
333 
341  protected function checkInput($a_mode) {
342  $return = $this->form->checkInput();
343 
344  // Title of table must be unique in one DC
345  if ($a_mode == 'create') {
346  if ($title = $this->form->getInput('title')) {
347  if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
348  $inputObj = $this->form->getItemByPostVar('title');
349  $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
350  $return = false;
351  }
352  }
353  }
354 
355  if (! $return) {
356  ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
357  }
358 
359  return $return;
360  }
361 
362 
363  /*
364  * accessDenied
365  */
366  public function accessDenied() {
367  $this->tpl->setContent("Access denied.");
368  }
369 
370 
374  public function confirmDelete() {
375  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
376  $conf = new ilConfirmationGUI();
377  $conf->setFormAction($this->ctrl->getFormAction($this));
378  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
379 
380  $conf->addItem('table', (int)$this->table->getId(), $this->table->getTitle());
381 
382  $conf->setConfirm($this->lng->txt('delete'), 'delete');
383  $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
384 
385  $this->tpl->setContent($conf->getHTML());
386  }
387 
388 
392  public function cancelDelete() {
393  $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
394  }
395 
396 
397  /*
398  * delete
399  */
400  public function delete() {
401  $mainTableId = $this->table->getCollectionObject()->getMainTableId();
402  if ($mainTableId == $this->table->getId()) {
403  ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_main_table"), true);
404  } else {
405  $this->ctrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $mainTableId);
406  }
407 
408  $this->table->doDelete();
409  $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
410  }
411 
412 
416  protected function checkPermission() {
417  $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
418 
420  }
421 }
422 
423 ?>