ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
5require_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;
43 protected $form;
44
50 public function __construct(ilObjDataCollectionGUI $a_parent_obj) {
51 global $ilCtrl, $lng, $tpl;
52
53 $this->ctrl = $ilCtrl;
54 $this->lng = $lng;
55 $this->tpl = $tpl;
56 $this->parent_object = $a_parent_obj;
57 $this->obj_id = $a_parent_obj->obj_id;
58 $this->table_id = $_GET['table_id'];
59 $this->table = ilDataCollectionCache::getTableCache($this->table_id);
60 if (!$this->checkPermission()) {
61 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
62 $this->ctrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
63 }
64 }
65
66
70 public function executeCommand() {
71 $cmd = $this->ctrl->getCmd();
72 $this->tpl->getStandardTemplate();
73
74 switch ($cmd) {
75 case 'update':
76 $this->save("update");
77 break;
78 default:
79 $this->$cmd();
80 break;
81 }
82
83 return true;
84 }
85
86
90 public function create() {
91 $this->initForm();
92 $this->getStandardValues();
93 $this->tpl->setContent($this->form->getHTML());
94 }
95
96
100 public function edit() {
101 if (!$this->table_id) {
102 $this->ctrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
103
104 return;
105 } else {
106 $this->table = ilDataCollectionCache::getTableCache($this->table_id);
107 }
108 $this->initForm("edit");
109 $this->getValues();
110 $this->tpl->setContent($this->form->getHTML());
111 }
112
113
117 public function getValues() {
118 $values = array(
119 'title' => $this->table->getTitle(),
120 'add_perm' => (int) $this->table->getAddPerm(),
121 'edit_perm' => (int) $this->table->getEditPerm(),
122 'edit_perm_mode' => $this->table->getEditByOwner() ? 'own' : 'all',
123 'delete_perm' => (int) $this->table->getDeletePerm(),
124 'delete_perm_mode' => $this->table->getDeleteByOwner() ? 'own' : 'all',
125 'export_enabled' => $this->table->getExportEnabled(),
126 'limited' => $this->table->getLimited(),
127 'limit_start' => array( "date" => substr($this->table->getLimitStart(), 0, 10), "time" => substr($this->table->getLimitStart(), - 8) ),
128 'limit_end' => array( "date" => substr($this->table->getLimitEnd(), 0, 10), "time" => substr($this->table->getLimitEnd(), - 8) ),
129 'is_visible' => $this->table->getIsVisible(),
130 'default_sort_field' => $this->table->getDefaultSortField(),
131 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
132 'description' => $this->table->getDescription(),
133 'public_comments' => $this->table->getPublicCommentsEnabled(),
134 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
135 );
136 if (!$this->table->getLimitStart()) {
137 $values['limit_start'] = NULL;
138 }
139 if (!$this->table->getLimitEnd()) {
140 $values['limit_end'] = NULL;
141 }
142 $this->form->setValuesByArray($values);
143 }
144
145
149 public function getStandardValues() {
150 $values = array(
151 'title' => "",
152 'is_visible' => 1,
153 'add_perm' => 1,
154 'edit_perm' => 1,
155 'edit_perm_mode' => 'all',
156 'delete_perm_mode' => 'all',
157 'delete_perm' => 1,
158 'edit_by_owner' => 1,
159 'export_enabled' => 0,
160 'limited' => 0,
161 'limit_start' => NULL,
162 'limit_end' => NULL
163 );
164 $this->form->setValuesByArray($values);
165 }
166
167
168 /*
169 * cancel
170 */
171 public function cancel() {
172 $this->ctrl->redirectByClass("ilDataCollectionFieldListGUI", "listFields");
173 }
174
175
181 public function initForm($a_mode = "create") {
182 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
183 $this->form = new ilPropertyFormGUI();
184
185 $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
186 $item->setRequired(true);
187 $this->form->addItem($item);
188
189 //#0019146: Main Table is always visible in the menu-dropdown, if some other table is visible too
190 if ($this->table_id != $this->parent_object->getDataCollectionObject()->getMainTableId()) {
191 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_visible'), 'is_visible');
192 $item->setInfo($this->lng->txt('dcl_visible_desc'));
193 $this->form->addItem($item);
194 }
195
196 // Show default order field and direction only in edit mode, because table id is not yet given and there are no fields to select
197 if ($a_mode != 'create') {
198 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
199 $item->setInfo($this->lng->txt('dcl_default_sort_field_desc'));
200 $fields = $this->table->getVisibleFields();
201 $options = array( 0 => $this->lng->txt('dcl_please_select') );
202 foreach ($fields as $field) {
203 $options[$field->getId()] = $field->getTitle();
204 }
205 $item->setOptions($options);
206 $this->form->addItem($item);
207
208 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
209 $options = array( 'asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc') );
210 $item->setOptions($options);
211 $this->form->addItem($item);
212 }
213
214 $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
215 $item->setUseRte(true);
216 $item->setInfo($this->lng->txt('dcl_additional_info_desc'));
217 // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
218 $item->setRteTagSet('mini');
219 $this->form->addItem($item);
220
221 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_public_comments'), 'public_comments');
222 $item->setInfo($this->lng->txt('dcl_public_comments_desc'));
223 $this->form->addItem($item);
224
226 $section->setTitle($this->lng->txt('dcl_permissions_form'));
227 $this->form->addItem($section);
228
229 $item = new ilCustomInputGUI();
230 $item->setHtml($this->lng->txt('dcl_table_info'));
231 $item->setTitle($this->lng->txt('dcl_table_info_title'));
232 $this->form->addItem($item);
233
234 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
235 $item->setInfo($this->lng->txt("dcl_add_perm_desc"));
236 $this->form->addItem($item);
237
238 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
239 // $item->setInfo($this->lng->txt("dcl_edit_perm_info"));
240 $this->form->addItem($item);
241
242 $radios = new ilRadioGroupInputGUI('', 'edit_perm_mode');
243 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
244 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
245 $item->addSubItem($radios);
246
247 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
248 // $item->setInfo($this->lng->txt("dcl_delete_perm_info"));
249 $this->form->addItem($item);
250
251 $radios = new ilRadioGroupInputGUI('', 'delete_perm_mode');
252 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
253 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
254 $item->addSubItem($radios);
255
256 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
257 // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
258 $this->form->addItem($item);
259
260 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
261 $item->setInfo($this->lng->txt('dcl_export_enabled_desc'));
262 $this->form->addItem($item);
263
264 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
265 $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
266 $sitem1->setShowTime(true);
267 $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
268 $sitem2->setShowTime(true);
269 $item->setInfo($this->lng->txt("dcl_limited_desc"));
270 $item->addSubItem($sitem1);
271 $item->addSubItem($sitem2);
272 $this->form->addItem($item);
273
274 if ($a_mode == "edit") {
275 $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
276 } else {
277 $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
278 }
279
280 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
281 $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
282 if ($a_mode == "edit") {
283 $this->form->setTitle($this->lng->txt('dcl_edit_table'));
284 } else {
285 $this->form->setTitle($this->lng->txt('dcl_new_table'));
286 }
287 }
288
289
295 public function save($a_mode = "create") {
296 global $ilTabs;
297
298 if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
299 $this->accessDenied();
300 return;
301 }
302
303 $ilTabs->activateTab("id_fields");
304 $this->initForm($a_mode);
305
306 if ($this->checkInput($a_mode)) {
307 if ($a_mode != "update") {
309 } elseif ($this->table_id) {
310 $this->table = ilDataCollectionCache::getTableCache($this->table_id);
311 } else {
312 $this->ctrl->redirectByClass("ildatacollectionfieldeditgui", "listFields");
313 }
314
315 $this->table->setTitle($this->form->getInput("title"));
316 $this->table->setObjId($this->obj_id);
317 $this->table->setIsVisible((bool)$this->form->getInput("is_visible"));
318 $this->table->setAddPerm((bool)$this->form->getInput("add_perm"));
319 $this->table->setEditPerm((bool)$this->form->getInput("edit_perm"));
320 if ($this->table->getEditPerm()) {
321 $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
322 $this->table->setEditByOwner($edit_by_owner);
323 }
324 $this->table->setDeletePerm((bool)$this->form->getInput("delete_perm"));
325 if ($this->table->getDeletePerm()) {
326 $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
327 $this->table->setDeleteByOwner($delete_by_owner);
328 }
329 $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
330 $this->table->setExportEnabled($this->form->getInput("export_enabled"));
331 $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
332 $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
333 $this->table->setPublicCommentsEnabled($this->form->getInput('public_comments'));
334 $this->table->setLimited($this->form->getInput("limited"));
335 $this->table->setDescription($this->form->getInput('description'));
336 $limit_start = $this->form->getInput("limit_start");
337 $limit_end = $this->form->getInput("limit_end");
338 $this->table->setLimitStart($limit_start["date"] . " " . $limit_start["time"]);
339 $this->table->setLimitEnd($limit_end["date"] . " " . $limit_end["time"]);
340 if ($a_mode == "update") {
341 $this->table->doUpdate();
342 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
343 $this->ctrl->redirectByClass("ildatacollectiontableeditgui", "edit");
344 } else {
345 $this->table->doCreate();
346 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
347 $this->ctrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->table->getId());
348 $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
349 }
350 } else {
351 $this->form->setValuesByPost();
352 $this->tpl->setContent($this->form->getHTML());
353 }
354 }
355
356
364 protected function checkInput($a_mode) {
365 $return = $this->form->checkInput();
366
367 // Title of table must be unique in one DC
368 if ($a_mode == 'create') {
369 if ($title = $this->form->getInput('title')) {
370 if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
371 $inputObj = $this->form->getItemByPostVar('title');
372 $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
373 $return = false;
374 }
375 }
376 }
377
378 if (! $return) {
379 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
380 }
381
382 return $return;
383 }
384
385
386 /*
387 * accessDenied
388 */
389 public function accessDenied() {
390 $this->tpl->setContent("Access denied.");
391 }
392
393
397 public function confirmDelete() {
398 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
399 $conf = new ilConfirmationGUI();
400 $conf->setFormAction($this->ctrl->getFormAction($this));
401 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
402
403 $conf->addItem('table', (int)$this->table->getId(), $this->table->getTitle());
404
405 $conf->setConfirm($this->lng->txt('delete'), 'delete');
406 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
407
408 $this->tpl->setContent($conf->getHTML());
409 }
410
411
415 public function cancelDelete() {
416 $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
417 }
418
419
420 /*
421 * delete
422 */
423 public function delete() {
424 $mainTableId = $this->table->getCollectionObject()->getMainTableId();
425 if ($mainTableId == $this->table->getId()) {
426 ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_main_table"), true);
427 } else {
428 $this->ctrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $mainTableId);
429 }
430
431 $this->table->doDelete();
432 $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
433 }
434
435
439 protected function checkPermission() {
440 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
441
443 }
444}
$section
Definition: Utf8Test.php:84
$_GET["client_id"]
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a custom property in a property form.
checkInput($a_mode)
Custom checks for the form input.
__construct(ilObjDataCollectionGUI $a_parent_obj)
Constructor.
initForm($a_mode="create")
initEditCustomForm
This class represents a date/time property in a property form.
This class represents a section header in a property form.
static checkActionForObjId($action, $obj_id)
Class ilObjDataCollectionGUI.
static _hasTableByTitle($title, $obj_id)
Checks if a DataCollection has a table with a given title.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
if(!is_array($argv)) $options