ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDidacticTemplateSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
5 
14 {
15  private $parent_object;
16 
17  private $lng;
18 
22  public function __construct($a_parent_obj)
23  {
24  global $lng;
25 
26  $this->parent_object = $a_parent_obj;
27  $this->lng = $lng;
28  }
29 
34  public function executeCommand()
35  {
36  global $ilCtrl;
37 
38  $next_class = $ilCtrl->getNextClass($this);
39  $cmd = $ilCtrl->getCmd();
40 
41  switch($next_class)
42  {
43  default:
44  if(!$cmd)
45  {
46  $cmd = 'overview';
47  }
48  $this->$cmd();
49 
50  break;
51  }
52  return true;
53  }
54 
60  protected function overview()
61  {
62  global $ilToolbar,$lng, $ilCtrl, $ilAccess;
63 
64  if($ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
65  {
66  $ilToolbar->addButton(
67  $lng->txt('didactic_import_btn'),
68  $ilCtrl->getLinkTarget($this,'showImportForm')
69  );
70  }
71 
72 
73  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettingsTableGUI.php';
74  $table = new ilDidacticTemplateSettingsTableGUI($this,'overview');
75  $table->init();
76  $table->parse();
77 
78  $GLOBALS['tpl']->setContent($table->getHTML());
79  }
80 
86  protected function showImportForm(ilPropertyFormGUI $form = NULL)
87  {
88  global $ilTabs, $ilCtrl;
89 
90  $ilTabs->clearTargets();
91  $ilTabs->setBackTarget(
92  $this->lng->txt('didactic_back_to_overview'),
93  $ilCtrl->getLinkTarget($this,'overview')
94  );
95 
96  if(!$form instanceof ilPropertyFormGUI)
97  {
98  $form = $this->createImportForm();
99  }
100  $GLOBALS['tpl']->setContent($form->getHTML());
101  }
102 
107  protected function createImportForm()
108  {
109  global $ilCtrl;
110 
111  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
112  $form = new ilPropertyFormGUI();
113  $form->setShowTopButtons(false);
114  $form->setFormAction($ilCtrl->getFormAction($this));
115  $form->setTitle($this->lng->txt('didactic_import_table_title'));
116  $form->addCommandButton('importTemplate', $this->lng->txt('import'));
117  $form->addCommandButton('overview', $this->lng->txt('cancel'));
118 
119  $file = new ilFileInputGUI($this->lng->txt('import_file'), 'file');
120  $file->setSuffixes(array('xml'));
121  $file->setRequired(TRUE);
122  $form->addItem($file);
123 
124  $created = true;
125 
126  return $form;
127  }
128 
132  protected function importTemplate()
133  {
134  global $ilCtrl, $ilAccess;
135 
136  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
137  {
138  $this->ctrl->redirect($this, "overview");
139  }
140 
141  $form = $this->createImportForm();
142  if(!$form->checkInput())
143  {
144  ilUtil::sendFailure($this->lng->txt('err_check_input'));
145  $form->setValuesByPost();
146  return $this->showImportForm($form);
147  }
148 
149  // Do import
150  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateImport.php';
151 
153 
154  $file = $form->getInput('file');
155  $tmp = ilUtil::ilTempnam();
156 
157  // move uploaded file
159  $file['tmp_name'],
160  $file['name'],
161  $tmp
162  );
163  $import->setInputFile($tmp);
164 
165  try {
166  $import->import();
167  }
169  {
170  ilLoggerFactory::getLogger('otpl')->error('Import failed with message: ' . $e->getMessage());
171  ilUtil::sendFailure($this->lng->txt('didactic_import_failed').': '.$e->getMessage());
172  }
173 
174  ilUtil::sendSuccess($this->lng->txt('didactic_import_success'),TRUE);
175  $ilCtrl->redirect($this,'overview');
176  }
177 
182  protected function editTemplate(ilPropertyFormGUI $form = null)
183  {
184  global $ilCtrl,$ilTabs;
185 
186  if(!$_REQUEST['tplid'])
187  {
188  ilUtil::sendFailure($this->lng->txt('select_one'));
189  return $ilCtrl->redirect($this,'overview');
190  }
191 
192  $ilTabs->clearTargets();
193  $ilTabs->setBackTarget(
194  $this->lng->txt('didactic_back_to_overview'),
195  $ilCtrl->getLinkTarget($this,'overview')
196  );
197 
198 
199  $ilCtrl->saveParameter($this,'tplid');
200 
201  if(!$form instanceof ilPropertyFormGUI)
202  {
203  $settings = new ilDidacticTemplateSetting((int) $_REQUEST['tplid']);
204  $form = $this->initEditTemplate($settings);
205  }
206  $GLOBALS['tpl']->setContent($form->getHTML());
207  }
208 
212  protected function updateTemplate()
213  {
214  global $ilCtrl, $ilAccess;
215 
216  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
217  {
218  $this->ctrl->redirect($this, "overview");
219  }
220 
221  $temp = new ilDidacticTemplateSetting((int) $_REQUEST['tplid']);
222  $form = $this->initEditTemplate($temp);
223 
224  if($form->checkInput())
225  {
226  $temp->setTitle($form->getInput('title'));
227  $temp->setDescription($form->getInput('description'));
228  $temp->setInfo($form->getInput('info'));
229  $temp->setAssignments(array($form->getInput('type')));
230  $temp->update();
231 
232  ilUtil::sendSuccess($this->lng->txt('save_settings'));
233  $ilCtrl->redirect($this,'overview');
234  }
235 
236  ilUtil::sendFailure($this->lng->txt('err_check_input'));
237  $form->setValuesByPost();
238  $this->editTemplate($form);
239  }
240 
245  {
246  global $ilCtrl,$objDefinition;
247 
248  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
249  $form = new ilPropertyFormGUI();
250  $form->setShowTopButtons(false);
251  $form->setFormAction($ilCtrl->getFormAction($this,'updateTemplate'));
252  $form->setTitle($this->lng->txt('didactic_edit_tpl'));
253  $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
254  $form->addCommandButton('overview', $this->lng->txt('cancel'));
255 
256  // title
257  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
258  $title->setValue($set->getTitle());
259  $title->setSize(40);
260  $title->setMaxLength(64);
261  $title->setRequired(true);
262  $form->addItem($title);
263 
264  // desc
265  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
266  $desc->setValue($set->getDescription());
267  $desc->setRows(3);
268  $form->addItem($desc);
269 
270  // info
271  $info = new ilTextAreaInputGUI($this->lng->txt('didactic_install_info'), 'info');
272  $info->setValue($set->getInfo());
273  $info->setRows(6);
274  $form->addItem($info);
275 
276  // object type
277  $type = new ilSelectInputGUI($this->lng->txt('obj_type'),'type');
278  $type->setRequired(true);
279  $assigned = $set->getAssignments();
280  $type->setValue(isset($assigned[0]) ? $assigned[0] : '');
281  $subs = $objDefinition->getCreatableSubobjects('root', false);
282  $options = array();
283  foreach(array_merge($subs,array('fold' => 1)) as $obj => $null)
284  {
285  if($objDefinition->isAllowedInRepository($obj))
286  {
287  $options[$obj] = $this->lng->txt('obj_'.$obj);
288  }
289  }
290  $type->setOptions($options);
291  $form->addItem($type);
292 
293  return $form;
294  }
295 
299  protected function copyTemplate()
300  {
301  global $ilErr, $ilCtrl, $ilAccess;
302 
303  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
304  {
305  $this->ctrl->redirect($this, "overview");
306  }
307 
308  if(!$_REQUEST['tplid'])
309  {
310  ilUtil::sendFailure($this->lng->txt('select_one'));
311  return $ilCtrl->redirect($this,'overview');
312  }
313 
314  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateCopier.php';
315 
316  $copier = new ilDidacticTemplateCopier((int) $_REQUEST['tplid']);
317  $copier->start();
318 
319  ilUtil::sendSuccess($this->lng->txt('didactic_copy_suc_message'), true);
320  $ilCtrl->redirect($this,'overview');
321  }
322 
326  protected function exportTemplate()
327  {
328  global $ilErr, $ilCtrl;
329 
330  if(!$_REQUEST['tplid'])
331  {
332  ilUtil::sendFailure($this->lng->txt('select_one'));
333  return $ilCtrl->redirect($this,'overview');
334  }
335 
336  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateXmlWriter.php';
337  $writer = new ilDidacticTemplateXmlWriter((int) $_REQUEST['tplid']);
338  $writer->write();
339 
341  $writer->xmlDumpMem(TRUE),
342  $writer->getSetting()->getTitle().'.xml',
343  'application/xml'
344  );
345  }
346 
350  protected function confirmDelete()
351  {
352  global $ilErr, $ilCtrl;
353 
354  if(!$_REQUEST['tpls'])
355  {
356  ilUtil::sendFailure($this->lng->txt('select_one'));
357  return $ilCtrl->redirect($this,'overview');
358  }
359 
360  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
361 
362  $confirm = new ilConfirmationGUI();
363  $confirm->setFormAction($ilCtrl->getFormAction($this));
364  $confirm->setConfirm($this->lng->txt('delete'), 'deleteTemplates');
365  $confirm->setCancel($this->lng->txt('cancel'), 'overview');
366 
367  foreach((array) $_REQUEST['tpls'] as $tplid)
368  {
369  $tpl = new ilDidacticTemplateSetting($tplid);
370  $confirm->addItem('tpls[]', $tpl->getId(), $tpl->getTitle());
371  }
372 
373  ilUtil::sendQuestion($this->lng->txt('didactic_confirm_delete_msg'));
374  $GLOBALS['tpl']->setContent($confirm->getHTML());
375  }
376 
383  protected function deleteTemplates()
384  {
385  global $ilErr, $ilCtrl, $ilAccess;
386 
387  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
388  {
389  $this->ctrl->redirect($this, "overview");
390  }
391 
392  if(!$_REQUEST['tpls'])
393  {
394  ilUtil::sendFailure($this->lng->txt('select_one'));
395  return $ilCtrl->redirect($this,'overview');
396  }
397 
398  foreach((array) $_REQUEST['tpls'] as $tplid)
399  {
400  $tpl = new ilDidacticTemplateSetting($tplid);
401  $tpl->delete();
402  }
403 
404  ilUtil::sendSuccess($this->lng->txt('didactic_delete_msg'),true);
405  $ilCtrl->redirect($this,'overview');
406  }
407 
414  protected function activateTemplates()
415  {
416  global $ilErr, $ilCtrl, $ilAccess;
417 
418  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
419  {
420  $this->ctrl->redirect($this, "overview");
421  }
422  if(!$_REQUEST['tpls'])
423  {
424  ilUtil::sendFailure($this->lng->txt('select_one'));
425  return $ilCtrl->redirect($this,'overview');
426  }
427 
428  foreach($_REQUEST['tpls'] as $tplid)
429  {
430  $tpl = new ilDidacticTemplateSetting($tplid);
431  $tpl->enable(true);
432  $tpl->update();
433  }
434 
435  ilUtil::sendSuccess($this->lng->txt('didactic_activated_msg'),true);
436  $ilCtrl->redirect($this,'overview');
437  }
438 
445  protected function deactivateTemplates()
446  {
447  global $ilErr, $ilCtrl, $ilAccess;
448 
449  if(!$ilAccess->checkAccess('write','',$_REQUEST["ref_id"]))
450  {
451  $this->ctrl->redirect($this, "overview");
452  }
453 
454  if(!$_REQUEST['tpls'])
455  {
456  ilUtil::sendFailure($this->lng->txt('select_one'));
457  return $ilCtrl->redirect($this,'overview');
458  }
459 
460  foreach($_REQUEST['tpls'] as $tplid)
461  {
462  $tpl = new ilDidacticTemplateSetting($tplid);
463  $tpl->enable(false);
464  $tpl->update();
465  }
466 
467  ilUtil::sendSuccess($this->lng->txt('didactic_deactivated_msg'),true);
468  $ilCtrl->redirect($this,'overview');
469  }
470 
471 
472 }
473 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
print $file
Description of ilDidacticTemplateSettingsTableGUI.
deleteTemplates()
Delete chosen didactic templates ilErrorHandling $ilErr ilCtrl $ilCtrl.
deactivateTemplates()
Activate didactic templates ilErrorHandling $ilErr ilCtrl $ilCtrl.
This class represents a selection list property in a property form.
This class represents a property form user interface.
This class represents a file property in a property form.
$cmd
Definition: sahs_server.php:35
setValue($a_value)
Set Value.
initEditTemplate(ilDidacticTemplateSetting $set)
Init edit template form.
showImportForm(ilPropertyFormGUI $form=NULL)
Show template import form.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
$info
Definition: example_052.php:80
editTemplate(ilPropertyFormGUI $form=null)
Edit template.
if(!is_array($argv)) $options
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
This class represents a text property in a property form.
Description of ilDidacticTemplateImportException.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
Description of ilDidacticTemplateImport.
Copy a didactic template and all subitems.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
This class represents a text area property in a property form.
getInfo()
Get installation info text.
Settings for a single didactic template.
static getLogger($a_component_id)
Get component logger.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
setValue($a_value)
Set Value.
confirmDelete()
Show delete confirmation screen.
activateTemplates()
Activate didactic templates ilErrorHandling $ilErr ilCtrl $ilCtrl.
setRequired($a_required)
Set Required.
Confirmation screen class.
overview()
Show didactic template administration.