ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjPDFGenerationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
5require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
6require_once 'Services/Object/classes/class.ilObject2GUI.php';
7require_once 'Services/PDFGeneration/classes/class.ilPDFGeneratorUtils.php';
8require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
9
17{
21 protected $active_tab;
22
26 protected $toolbar;
27
31 protected $ctrl;
32
36 protected $tabs;
37
43 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
44 {
45 global $DIC;
47 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
48 $this->lng->loadLanguageModule('pdfgen');
49 $this->toolbar = $DIC['ilToolbar'];
50 $this->ctrl = $DIC['ilCtrl'];
51 $this->tabs = $DIC['ilTabs'];
52 }
53
57 protected function hasWritePermission()
58 {
59 return $this->checkPermissionBool('write');
60 }
61
65 public function getType()
66 {
67 return 'pdfg';
68 }
69
73 public function executeCommand()
74 {
75 $next_class = $this->ctrl->getNextClass();
76 $cmd = $this->ctrl->getCmd();
77 $this->prepareOutput();
78
79 switch ($next_class) {
80 case 'ilpermissiongui':
81 $this->tabs_gui->setTabActive('perm_settings');
82 $perm_gui = new ilPermissionGUI($this);
83 $this->ctrl->forwardCommand($perm_gui);
84 break;
85
86 default:
87 if ($cmd == '' || $cmd == 'view') {
88 $cmd = 'configForm';
89 }
90 if (substr($cmd, 0, 21) == 'saveandconf_selected_') {
91 $this->handleSaveAndConf(substr($cmd, 21));
92 } else {
93 $this->$cmd();
94 }
95 break;
96 }
97 }
98
99 public function configForm()
100 {
101 $form = new ilPropertyFormGUI();
102 $form->setFormAction($this->ctrl->getFormAction($this, 'view'));
103 $purpose_map = ilPDFGeneratorUtils::getPurposeMap();
104 $selection_map = ilPDFGeneratorUtils::getSelectionMap();
106 foreach ($purpose_map as $service => $purposes) {
107 foreach ($purposes as $purpose) {
109 $section->setTitle(ucfirst($service) . ' / ' . ucfirst($purpose));
110 $form->addItem($section);
111
112 $preferred = new ilTextInputGUI($this->lng->txt('preferred_renderer'));
113 $preferred->setValue($selection_map[$service][$purpose]['preferred']);
114 $preferred->setDisabled(true);
115 $form->addItem($preferred);
116
117 $selected = new ilSelectInputGUI($this->lng->txt('selected_renderer'), 'selected_' . $service . '::' . $purpose);
118 $selected->setOptions($renderers[$service][$purpose]);
119 $selected_renderer = $selection_map[$service][$purpose]['selected'];
120 $selected_index = 0;
121 foreach ($renderers[$service][$purpose] as $key => $value) {
122 if ($value == $selected_renderer) {
123 $selected_index = $key;
124 }
125 }
126 $selected->setValue($selected_index);
127 $form->addItem($selected);
128
129 $s_button = ilSubmitButton::getInstance();
130 $s_button->setCaption('configure');
131 $s_button->setCommand('saveandconf_selected_' . $service . '::' . $purpose);
132 if (!$this->hasWritePermission()) {
133 $s_button->setDisabled(true);
134 }
135 $input_selected = new ilCustomInputGUI($this->lng->txt('configure'));
136 $input_selected->setHtml($s_button->getToolbarHTML());
137 $form->addItem($input_selected);
138 }
139 }
140
141 if ($this->hasWritePermission()) {
142 $form->addCommandButton("saveSettings", $this->lng->txt("save"));
143 }
144
146 ilUtil::sendInfo($this->lng->txt('problem_with_purposes'));
147 $clean_btn = ilLinkButton::getInstance();
148 $clean_btn->setCaption('cleanup');
149 $clean_btn->setUrl($this->ctrl->getLinkTarget($this, 'doCleanUp'));
150 $this->toolbar->addButtonInstance($clean_btn);
151 }
152 $this->tpl->setContent($form->getHTML());
153 $this->setActiveTab('settings');
154 }
155
159 public function saveSettings($redirect_after = true)
160 {
161 if ($this->hasWritePermission()) {
162 $form = new ilPropertyFormGUI();
163 $purpose_map = ilPDFGeneratorUtils::getPurposeMap();
164 $selection_map = ilPDFGeneratorUtils::getSelectionMap();
166
167 foreach ($purpose_map as $service => $purposes) {
168 foreach ($purposes as $purpose) {
169 $posted_renderer = $renderers[$service][$purpose][$_POST['selected_' . $service . '::' . $purpose]];
170 $selected_renderer = $selection_map[$service][$purpose]['selected'];
171 if ($posted_renderer != $selected_renderer) {
172 ilPDFGeneratorUtils::updateRendererSelection($service, $purpose, $posted_renderer);
173 }
174 }
175 }
176 $form->setTitle($this->lng->txt('pdf_config'));
177
178 if ($redirect_after) {
179 ilUtil::sendSuccess($this->lng->txt('config_saved'), true);
180 $this->ctrl->redirect($this, "view");
181 }
182 } else {
183 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
184 $this->ctrl->redirect($this, "view");
185 }
186 }
187
191 protected function handleSaveAndConf($command)
192 {
193 if ($this->checkPermissionBool('edit')) {
194 $this->saveSettings(false);
195
196 $parts = explode('::', $command);
197 $service = $parts[0];
198 $purpose = $parts[1];
199
201 $posted_renderer = $renderers[$service][$purpose][$_POST['selected_' . $service . '::' . $purpose]];
202
203
204 $form = new ilPropertyFormGUI();
205 $form->setFormAction($this->ctrl->getFormAction($this, 'view'));
206
207 $form->setTitle($this->lng->txt('settings') . ' ' . $posted_renderer . ' / ' . $service . ' / ' . $purpose);
208 $service_hidden = new ilHiddenInputGUI('service');
209 $service_hidden->setValue($service);
210 $form->addItem($service_hidden);
211
212 $purpose_hidden = new ilHiddenInputGUI('purpose');
213 $purpose_hidden->setValue($purpose);
214 $form->addItem($purpose_hidden);
215
216 $renderer_hidden = new ilHiddenInputGUI('renderer');
217 $renderer_hidden->setValue($posted_renderer);
218 $form->addItem($renderer_hidden);
219
220 // Add In RendererConfig
221 $renderer = ilPDFGeneratorUtils::getRendererInstance($posted_renderer);
222 $config = ilPDFGeneratorUtils::getRendererConfig($service, $purpose, $posted_renderer);
223
225 $renderer->addConfigElementsToForm($form, $service, $purpose);
226 $renderer->populateConfigElementsInForm($form, $service, $purpose, $config);
227
228 $form->addCommandButton("saveConfig", $this->lng->txt("save"));
229 $form->addCommandButton("view", $this->lng->txt("cancel"));
230 $form->addCommandButton("resetSettings", $this->lng->txt("reset_to_default"));
231 $this->tpl->setContent($form->getHTML());
232 $this->setActiveTab('settings');
233 } else {
234 ilUtil::sendFailure($this->lng->txt('no_permission'), true);
235 $this->ctrl->redirect($this, "view");
236 }
237 }
238
239 public function resetSettings()
240 {
241 $renderer = ilUtil::stripSlashes($_POST['renderer']);
243 $purpose = ilUtil::stripSlashes($_POST['purpose']);
244
246 $this->ctrl->redirect($this, "view");
247 }
248
249 protected function saveConfig()
250 {
251 $form = new ilPropertyFormGUI();
252
253 $renderer = $_POST['renderer'];
254 $service = $_POST['service'];
255 $purpose = $_POST['purpose'];
256
258 $renderer_obj = ilPDFGeneratorUtils::getRendererInstance($renderer);
259 $renderer_obj->addConfigElementsToForm($form, $service, $purpose);
260
261 $form->setValuesByPost();
262 if ($renderer_obj->validateConfigInForm($form, $service, $purpose)) {
263 $config = $renderer_obj->getConfigFromForm($form, $service, $purpose);
264 ilPDFGeneratorUtils::saveRendererPurposeConfig($service, $purpose, $renderer, $config);
265 ilUtil::sendSuccess($this->lng->txt('config_saved'), true);
266 $this->ctrl->redirect($this, "view");
267 } else {
268 ilUtil::sendFailure($this->lng->txt('config_not_saved'), true); // TODO: Needs better handling.
269 $this->ctrl->redirect($this, "view");
270 }
271 }
272
273 protected function doCleanUp()
274 {
276 ilUtil::sendSuccess($this->lng->txt('config_saved'), true);
277 $this->ctrl->redirect($this, "view");
278 }
279
283 public function getAdminTabs()
284 {
285 if (strpos($this->ctrl->getCmd(), 'saveandconf') !== 0) {
286 if ($this->checkPermissionBool('read')) {
287 $this->tabs->addTarget('settings', $this->ctrl->getLinkTarget($this, 'view'), array(), __CLASS__);
288 }
289
290 if ($this->checkPermissionBool('edit_permission')) {
291 $this->tabs->addTarget(
292 'perm_settings',
293 $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
294 array(),
295 'ilpermissiongui'
296 );
297 }
298 } else {
299 $this->tabs->setBackTarget(
300 $this->lng->txt("back"),
301 $this->ctrl->getLinkTargetByClass("ilobjpdfgenerationgui", "view")
302 );
303 }
304 }
305
309 protected function setActiveTab($tab = '')
310 {
311 $this->tabs->setTabActive($tab == '' ? $this->active_tab : $tab);
312 }
313}
$section
Definition: Utf8Test.php:83
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a custom property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
static getInstance()
Factory.
Class ilObjPDFGenerationGUI.
getAdminTabs()
{administration tabs show only permissions and trash folder}
saveSettings($redirect_after=true)
getType()
{Functions that must be overwritten.}
New implementation of ilObjectGUI.
prepareOutput($a_show_subobjects=true)
prepare output
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_node_id=null)
Check permission.
static checkForMultipleServiceAndPurposeCombination()
static removeRendererConfig($service, $purpose, $renderer)
static updateRendererSelection($service, $purpose, $renderer)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a selection list property in a property form.
static getInstance()
Factory.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$service
Definition: result.php:17