ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
5
14{
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;
63
64 $ilToolbar->addButton(
65 $lng->txt('didactic_import_btn'),
66 $ilCtrl->getLinkTarget($this,'showImportForm')
67 );
68
69 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettingsTableGUI.php';
70 $table = new ilDidacticTemplateSettingsTableGUI($this,'overview');
71 $table->init();
72 $table->parse();
73
74 $GLOBALS['tpl']->setContent($table->getHTML());
75 }
76
82 protected function showImportForm(ilPropertyFormGUI $form = NULL)
83 {
84 global $ilTabs, $ilCtrl;
85
86 $ilTabs->clearTargets();
87 $ilTabs->setBackTarget(
88 $this->lng->txt('didactic_back_to_overview'),
89 $ilCtrl->getLinkTarget($this,'overview')
90 );
91
92 if(!$form instanceof ilPropertyFormGUI)
93 {
94 $form = $this->createImportForm();
95 }
96 $GLOBALS['tpl']->setContent($form->getHTML());
97 }
98
103 protected function createImportForm()
104 {
105 global $ilCtrl;
106
107 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
108 $form = new ilPropertyFormGUI();
109 $form->setShowTopButtons(false);
110 $form->setFormAction($ilCtrl->getFormAction($this));
111 $form->setTitle($this->lng->txt('didactic_import_table_title'));
112 $form->addCommandButton('importTemplate', $this->lng->txt('import'));
113 $form->addCommandButton('overview', $this->lng->txt('cancel'));
114
115 $file = new ilFileInputGUI($this->lng->txt('import_file'), 'file');
116 $file->setSuffixes(array('xml'));
117 $file->setRequired(TRUE);
118 $form->addItem($file);
119
120 $created = true;
121
122 return $form;
123 }
124
128 protected function importTemplate()
129 {
130 global $ilCtrl;
131
132 $form = $this->createImportForm();
133 if(!$form->checkInput())
134 {
135 ilUtil::sendFailure($this->lng->txt('err_check_input'));
136 $form->setValuesByPost();
137 return $this->showImportForm($form);
138 }
139
140 // Do import
141 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateImport.php';
142
144
145 $file = $form->getInput('file');
146 $tmp = ilUtil::ilTempnam();
147
148 // move uploaded file
150 $file['tmp_name'],
151 $file['name'],
152 $tmp
153 );
154 $import->setInputFile($tmp);
155
156 $GLOBALS['ilLog']->write(__METHOD__.': Using '.$tmp);
157
158 try {
159 $import->import();
160 }
162 {
163 $GLOBALS['ilLog']->write(__METHOD__.': Import failed with message: '. $e->getMessage());
164 ilUtil::sendFailure($this->lng->txt('didactic_import_failed').': '.$e->getMessage());
165 }
166
167 ilUtil::sendSuccess($this->lng->txt('didactic_import_success'),TRUE);
168 $ilCtrl->redirect($this,'overview');
169 }
170
175 protected function editTemplate(ilPropertyFormGUI $form = null)
176 {
177 global $ilCtrl,$ilTabs;
178
179 if(!$_REQUEST['tplid'])
180 {
181 ilUtil::sendFailure($this->lng->txt('select_one'));
182 return $ilCtrl->redirect($this,'overview');
183 }
184
185 $ilTabs->clearTargets();
186 $ilTabs->setBackTarget(
187 $this->lng->txt('didactic_back_to_overview'),
188 $ilCtrl->getLinkTarget($this,'overview')
189 );
190
191
192 $ilCtrl->saveParameter($this,'tplid');
193
194 if(!$form instanceof ilPropertyFormGUI)
195 {
196 $settings = new ilDidacticTemplateSetting((int) $_REQUEST['tplid']);
197 $form = $this->initEditTemplate($settings);
198 }
199 $GLOBALS['tpl']->setContent($form->getHTML());
200 }
201
205 protected function updateTemplate()
206 {
207 global $ilCtrl;
208
209 $temp = new ilDidacticTemplateSetting((int) $_REQUEST['tplid']);
210 $form = $this->initEditTemplate($temp);
211
212 if($form->checkInput())
213 {
214 $temp->setTitle($form->getInput('title'));
215 $temp->setDescription($form->getInput('description'));
216 $temp->setInfo($form->getInput('info'));
217 $temp->setAssignments(array($form->getInput('type')));
218 $temp->update();
219
220 ilUtil::sendSuccess($this->lng->txt('save_settings'));
221 $ilCtrl->redirect($this,'overview');
222 }
223
224 ilUtil::sendFailure($this->lng->txt('err_check_input'));
225 $form->setValuesByPost();
226 $this->editTemplate($form);
227 }
228
233 {
234 global $ilCtrl,$objDefinition;
235
236 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
237 $form = new ilPropertyFormGUI();
238 $form->setShowTopButtons(false);
239 $form->setFormAction($ilCtrl->getFormAction($this,'updateTemplate'));
240 $form->setTitle($this->lng->txt('didactic_edit_tpl'));
241 $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
242 $form->addCommandButton('overview', $this->lng->txt('cancel'));
243
244 // title
245 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
246 $title->setValue($set->getTitle());
247 $title->setSize(40);
248 $title->setMaxLength(64);
249 $title->setRequired(true);
250 $form->addItem($title);
251
252 // desc
253 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
254 $desc->setValue($set->getDescription());
255 $desc->setRows(3);
256 $form->addItem($desc);
257
258 // info
259 $info = new ilTextAreaInputGUI($this->lng->txt('didactic_install_info'), 'info');
260 $info->setValue($set->getInfo());
261 $info->setRows(6);
262 $form->addItem($info);
263
264 // object type
265 $type = new ilSelectInputGUI($this->lng->txt('obj_type'),'type');
266 $type->setRequired(true);
267 $assigned = $set->getAssignments();
268 $type->setValue(isset($assigned[0]) ? $assigned[0] : '');
269 $subs = $objDefinition->getCreatableSubobjects('root', false);
270 $options = array();
271 foreach(array_merge($subs,array('fold' => 1)) as $obj => $null)
272 {
273 if($objDefinition->isAllowedInRepository($obj))
274 {
275 $options[$obj] = $this->lng->txt('obj_'.$obj);
276 }
277 }
278 $type->setOptions($options);
279 $form->addItem($type);
280
281 return $form;
282 }
283
287 protected function copyTemplate()
288 {
289 global $ilErr, $ilCtrl;;
290
291 if(!$_REQUEST['tplid'])
292 {
293 ilUtil::sendFailure($this->lng->txt('select_one'));
294 return $ilCtrl->redirect($this,'overview');
295 }
296
297 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateCopier.php';
298
299 $copier = new ilDidacticTemplateCopier((int) $_REQUEST['tplid']);
300 $copier->start();
301
302 ilUtil::sendSuccess($this->lng->txt('didactic_copy_suc_message'), true);
303 $ilCtrl->redirect($this,'overview');
304 }
305
309 protected function exportTemplate()
310 {
311 global $ilErr, $ilCtrl;
312
313 if(!$_REQUEST['tplid'])
314 {
315 ilUtil::sendFailure($this->lng->txt('select_one'));
316 return $ilCtrl->redirect($this,'overview');
317 }
318
319 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateXmlWriter.php';
320 $writer = new ilDidacticTemplateXmlWriter((int) $_REQUEST['tplid']);
321 $writer->write();
322
324 $writer->xmlDumpMem(TRUE),
325 $writer->getSetting()->getTitle().'.xml',
326 'application/xml'
327 );
328 }
329
333 protected function confirmDelete()
334 {
335 global $ilErr, $ilCtrl;
336
337 if(!$_REQUEST['tpls'])
338 {
339 ilUtil::sendFailure($this->lng->txt('select_one'));
340 return $ilCtrl->redirect($this,'overview');
341 }
342
343 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
344
345 $confirm = new ilConfirmationGUI();
346 $confirm->setFormAction($ilCtrl->getFormAction($this));
347 $confirm->setConfirm($this->lng->txt('delete'), 'deleteTemplates');
348 $confirm->setCancel($this->lng->txt('cancel'), 'overview');
349
350 foreach((array) $_REQUEST['tpls'] as $tplid)
351 {
352 $tpl = new ilDidacticTemplateSetting($tplid);
353 $confirm->addItem('tpls[]', $tpl->getId(), $tpl->getTitle());
354 }
355
356 ilUtil::sendQuestion($this->lng->txt('didactic_confirm_delete_msg'));
357 $GLOBALS['tpl']->setContent($confirm->getHTML());
358 }
359
366 protected function deleteTemplates()
367 {
368 global $ilErr, $ilCtrl;
369
370 if(!$_REQUEST['tpls'])
371 {
372 ilUtil::sendFailure($this->lng->txt('select_one'));
373 return $ilCtrl->redirect($this,'overview');
374 }
375
376 foreach((array) $_REQUEST['tpls'] as $tplid)
377 {
378 $tpl = new ilDidacticTemplateSetting($tplid);
379 $tpl->delete();
380 }
381
382 ilUtil::sendSuccess($this->lng->txt('didactic_delete_msg'),true);
383 $ilCtrl->redirect($this,'overview');
384 }
385
392 protected function activateTemplates()
393 {
394 global $ilErr, $ilCtrl;
395
396 if(!$_REQUEST['tpls'])
397 {
398 ilUtil::sendFailure($this->lng->txt('select_one'));
399 return $ilCtrl->redirect($this,'overview');
400 }
401
402 foreach($_REQUEST['tpls'] as $tplid)
403 {
404 $tpl = new ilDidacticTemplateSetting($tplid);
405 $tpl->enable(true);
406 $tpl->update();
407 }
408
409 ilUtil::sendSuccess($this->lng->txt('didactic_activated_msg'),true);
410 $ilCtrl->redirect($this,'overview');
411 }
412
419 protected function deactivateTemplates()
420 {
421 global $ilErr, $ilCtrl;
422
423 if(!$_REQUEST['tpls'])
424 {
425 ilUtil::sendFailure($this->lng->txt('select_one'));
426 return $ilCtrl->redirect($this,'overview');
427 }
428
429 foreach($_REQUEST['tpls'] as $tplid)
430 {
431 $tpl = new ilDidacticTemplateSetting($tplid);
432 $tpl->enable(false);
433 $tpl->update();
434 }
435
436 ilUtil::sendSuccess($this->lng->txt('didactic_deactivated_msg'),true);
437 $ilCtrl->redirect($this,'overview');
438 }
439
440
441}
442?>
print $file
global $tpl
Definition: ilias.php:8
Confirmation screen class.
Copy a didactic template and all subitems.
Description of ilDidacticTemplateImportException.
Description of ilDidacticTemplateImport.
getInfo()
Get installation info text.
Settings for a single didactic template.
deactivateTemplates()
Activate didactic templates @global ilErrorHandling $ilErr @global ilCtrl $ilCtrl.
initEditTemplate(ilDidacticTemplateSetting $set)
Init edit template form.
overview()
Show didactic template administration.
showImportForm(ilPropertyFormGUI $form=NULL)
Show template import form.
confirmDelete()
Show delete confirmation screen.
activateTemplates()
Activate didactic templates @global ilErrorHandling $ilErr @global ilCtrl $ilCtrl.
editTemplate(ilPropertyFormGUI $form=null)
Edit template.
deleteTemplates()
Delete chosen didactic templates @global ilErrorHandling $ilErr @global ilCtrl $ilCtrl.
Description of ilDidacticTemplateSettingsTableGUI.
This class represents a file property in a property form.
This class represents a property form user interface.
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 moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static ilTempnam()
Create a temporary file in an ILIAS writable directory.
$GLOBALS['ct_recipient']
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if(!is_array($argv)) $options