ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWkhtmlToPdfConfigFormGUI.php
Go to the documentation of this file.
1<?php
2
4{
8 protected $lng;
9
13 public function __construct()
14 {
15 global $DIC;
16 $this->setLanguage($DIC['lng']);
17 }
18
22 protected function setLanguage($lng)
23 {
24 $this->lng = $lng;
25 }
26
30 public function addConfigForm($form)
31 {
32 $path = new ilTextInputGUI($this->translate('path'), 'path');
33 $form->addItem($path);
34
35 $this->appendOutputOptionsForm($form);
36 $this->appendPageSettingsForm($form);
37 }
38
43 protected function translate($txt)
44 {
45 return $this->lng->txt($txt);
46 }
47
52 {
53 $section_header = new ilFormSectionHeaderGUI();
54 $section_header->setTitle($this->translate('output_options'));
55 $form->addItem($section_header);
56
57 $form->addItem($this->buildExternalLinksForm());
58 $form->addItem($this->buildEnableFormsForm());
59 $form->addItem($this->buildUserStylesheetForm());
60 $form->addItem($this->buildLowQualityForm());
61 $form->addItem($this->buildGreyScaleForm());
62 $form->addItem($this->buildPrintMediaTypeForm());
63 $form->addItem($this->buildJavascriptDelayForm());
64 $form->addItem($this->buildCheckboxSvgForm());
65 $form->addItem($this->buildCheckedCheckboxSvgForm());
66 $form->addItem($this->buildRadiobuttonSvgForm());
68 $form->addItem($this->buildOverwriteDefaultFont());
69 }
70
74 protected function buildExternalLinksForm()
75 {
76 $external_links = new ilCheckboxInputGUI($this->translate('external_links'), 'external_links');
77 $external_links->setInfo($this->translate('external_links_info'));
78 return $external_links;
79 }
80
84 protected function buildEnableFormsForm()
85 {
86 $enable_forms = new ilCheckboxInputGUI($this->translate('enable_forms'), 'enable_forms');
87 $enable_forms->setInfo($this->translate('enable_forms_info'));
88 return $enable_forms;
89 }
90
94 protected function buildUserStylesheetForm()
95 {
96 $user_stylesheet = new ilTextInputGUI($this->translate('user_stylesheet'), 'user_stylesheet');
97 return $user_stylesheet;
98 }
99
103 protected function buildLowQualityForm()
104 {
105 $low_quality = new ilCheckboxInputGUI($this->translate('low_quality'), 'low_quality');
106 $low_quality->setInfo($this->translate('low_quality_info'));
107 return $low_quality;
108 }
109
113 protected function buildGreyScaleForm()
114 {
115 $grey_scale = new ilCheckboxInputGUI($this->translate('greyscale'), 'greyscale');
116 $grey_scale->setInfo($this->translate('greyscale_info'));
117 return $grey_scale;
118 }
119
123 protected function buildPrintMediaTypeForm()
124 {
125 $print_media = new ilCheckboxInputGUI($this->translate('print_media_type'), 'print_media_type');
126 $print_media->setInfo($this->translate('print_media_info'));
127 return $print_media;
128 }
129
133 protected function buildJavascriptDelayForm()
134 {
135 $javascript_delay = new ilTextInputGUI($this->translate('javascript_delay'), 'javascript_delay');
136 $javascript_delay->setInfo($this->translate('javascript_delay_info'));
137 return $javascript_delay;
138 }
139
143 protected function buildCheckboxSvgForm()
144 {
145 return new ilTextInputGUI($this->translate('checkbox_svg'), 'checkbox_svg');
146 }
147
151 protected function buildCheckedCheckboxSvgForm()
152 {
153 return new ilTextInputGUI($this->translate('checkbox_checked_svg'), 'checkbox_checked_svg');
154 }
155
159 protected function buildRadiobuttonSvgForm()
160 {
161 return new ilTextInputGUI($this->translate('radio_button_svg'), 'radio_button_svg');
162 }
163
168 {
169 return new ilTextInputGUI($this->translate('radio_button_checked_svg'), 'radio_button_checked_svg');
170 }
171
175 protected function buildOverwriteDefaultFont()
176 {
177 $overwrite_font = new ilTextInputGUI($this->translate('overwrite_font'), 'overwrite_font');
178 $overwrite_font->setInfo($this->translate('overwrite_font_info'));
179 return $overwrite_font;
180 }
181
186 {
187 $section_header = new ilFormSectionHeaderGUI();
188 $section_header->setTitle($this->translate('page_settings'));
189 $form->addItem($section_header);
190
191 $form->addItem($this->buildZoomForm());
192 $form->addItem($this->buildOrientationsForm());
193 $form->addItem($this->buildPageSizesForm());
194 $form->addItem($this->buildMarginLeftForm());
195 $form->addItem($this->buildMarginRightForm());
196 $form->addItem($this->buildMarginTopForm());
197 $form->addItem($this->buildMarginBottomForm());
198 $form->addItem($this->buildHeaderForm());
199 $form->addItem($this->buildFooterForm());
200 }
201
205 protected function buildZoomForm()
206 {
207 return new ilTextInputGUI($this->translate('zoom'), 'zoom');
208 }
209
213 protected function buildOrientationsForm()
214 {
215 $orientation = new ilSelectInputGUI($this->translate('orientation'), 'orientation');
216 $orientation->setOptions(ilPDFGenerationConstants::getOrientations());
217 return $orientation;
218 }
219
223 protected function buildPageSizesForm()
224 {
225 $page_size = new ilSelectInputGUI($this->translate('page_size'), 'page_size');
226 $page_size->setOptions(ilPDFGenerationConstants::getPageSizesNames());
227 return $page_size;
228 }
229
233 protected function buildMarginLeftForm()
234 {
235 $margin_left = new ilTextInputGUI($this->translate('margin_left'), 'margin_left');
236 $margin_left->setInfo($this->translate('margin_info'));
237 return $margin_left;
238 }
239
243 protected function buildMarginRightForm()
244 {
245 $margin_right = new ilTextInputGUI($this->translate('margin_right'), 'margin_right');
246 $margin_right->setInfo($this->translate('margin_info'));
247 return $margin_right;
248 }
249
253 protected function buildMarginTopForm()
254 {
255 $margin_top = new ilTextInputGUI($this->translate('margin_top'), 'margin_top');
256 $margin_top->setInfo($this->translate('margin_info'));
257 return $margin_top;
258 }
259
263 protected function buildMarginBottomForm()
264 {
265 $margin_bottom = new ilTextInputGUI($this->translate('margin_bottom'), 'margin_bottom');
266 $margin_bottom->setInfo($this->translate('margin_info'));
267 return $margin_bottom;
268 }
269
273 protected function buildHeaderForm()
274 {
275 $header_select = new ilRadioGroupInputGUI($this->translate('header_type'), 'header_select');
276 $header_select->addOption(new ilRadioOption($this->translate('none'), ilPDFGenerationConstants::HEADER_NONE, ''));
277 $header_select->addOption($this->buildHeaderTextForm());
278 $header_select->addOption($this->buildHeaderHtmlForm());
279
280 return $header_select;
281 }
282
286 protected function buildHeaderTextForm()
287 {
288 $header_text_option = new ilRadioOption($this->translate('text'), ilPDFGenerationConstants::HEADER_TEXT, '');
289
290 $header_text_left = new ilTextInputGUI($this->translate('header_text_left'), 'head_text_left');
291 $header_text_option->addSubItem($header_text_left);
292
293 $header_text_center = new ilTextInputGUI($this->translate('header_text_center'), 'head_text_center');
294 $header_text_option->addSubItem($header_text_center);
295
296 $header_text_right = new ilTextInputGUI($this->translate('header_text_right'), 'head_text_right');
297 $header_text_option->addSubItem($header_text_right);
298
299 $head_text_spacing = new ilTextInputGUI($this->translate('spacing'), 'head_text_spacing');
300 $header_text_option->addSubItem($head_text_spacing);
301
302 $head_text_line = new ilCheckboxInputGUI($this->translate('header_line'), 'head_text_line');
303
304 $header_text_option->addSubItem($head_text_line);
305 return $header_text_option;
306 }
307
311 protected function buildHeaderHtmlForm()
312 {
313 $header_html_option = new ilRadioOption($this->translate("html"), ilPDFGenerationConstants::HEADER_HTML, '');
314
315 $header_html = new ilTextInputGUI($this->translate('html'), 'head_html');
316 $header_html_option->addSubItem($header_html);
317
318 $head_html_spacing = new ilTextInputGUI($this->translate('spacing'), 'head_html_spacing');
319 $header_html_option->addSubItem($head_html_spacing);
320
321 $head_html_line = new ilCheckboxInputGUI($this->translate('header_line'), 'head_html_line');
322 $header_html_option->addSubItem($head_html_line);
323 return $header_html_option;
324 }
325
329 protected function buildFooterForm()
330 {
331 $footer_select = new ilRadioGroupInputGUI($this->translate('footer_type'), 'footer_select');
332 $footer_select->addOption(new ilRadioOption($this->translate("none"), ilPDFGenerationConstants::FOOTER_NONE, ''));
333 $footer_select->addOption($this->buildFooterTextForm());
334 $footer_select->addOption($this->buildFooterHtmlForm());
335
336 return $footer_select;
337 }
338
342 protected function buildFooterTextForm()
343 {
344 $footer_text_option = new ilRadioOption($this->translate('text'), ilPDFGenerationConstants::FOOTER_TEXT, '');
345
346 $footer_text_left = new ilTextInputGUI($this->translate('footer_text_left'), 'footer_text_left');
347 $footer_text_option->addSubItem($footer_text_left);
348
349 $footer_text_center = new ilTextInputGUI($this->translate('footer_text_center'), 'footer_text_center');
350 $footer_text_option->addSubItem($footer_text_center);
351
352 $footer_text_right = new ilTextInputGUI($this->translate('footer_text_right'), 'footer_text_right');
353 $footer_text_option->addSubItem($footer_text_right);
354
355 $footer_text_spacing = new ilTextInputGUI($this->translate('spacing'), 'footer_text_spacing');
356 $footer_text_option->addSubItem($footer_text_spacing);
357
358 $footer_text_line = new ilCheckboxInputGUI($this->translate('footer_line'), 'footer_text_line');
359
360 $footer_text_option->addSubItem($footer_text_line);
361 return $footer_text_option;
362 }
363
367 protected function buildFooterHtmlForm()
368 {
369 $footer_html_option = new ilRadioOption($this->translate('html'), ilPDFGenerationConstants::FOOTER_HTML, '');
370
371 $footer_html = new ilTextInputGUI($this->translate('footer_html'), 'footer_html');
372 $footer_html_option->addSubItem($footer_html);
373
374 $footer_html_spacing = new ilTextInputGUI($this->translate('spacing'), 'footer_html_spacing');
375 $footer_html_option->addSubItem($footer_html_spacing);
376
377 $footer_html_line = new ilCheckboxInputGUI($this->translate('footer_line'), 'footer_html_line');
378 $footer_html_option->addSubItem($footer_html_line);
379 return $footer_html_option;
380 }
381
385 public function validateForm()
386 {
387 $everything_ok = true;
389 $path = realpath(ilUtil::escapeShellCmd($_POST['path']));
390 $config->setPath($path);
391 if (mb_stripos($config->getPath(), 'wkhtmlto') === false) {
392 ilUtil::sendFailure($this->lng->txt("file_not_found"), true);
393 $everything_ok = false;
394 } else {
395 $config->setZoom((float) $_POST['zoom']);
396 $config->setExternalLinks((int) $_POST['external_links']);
397 $config->setEnabledForms((int) $_POST['enable_forms']);
398 $config->setUserStylesheet(ilUtil::stripSlashes($_POST['user_stylesheet']));
399 $config->setLowQuality((int) $_POST['low_quality']);
400 $config->setGreyscale((int) $_POST['greyscale']);
401 $config->setOrientation(ilUtil::stripSlashes($_POST['orientation']));
402 $config->setPageSize(ilUtil::stripSlashes($_POST['page_size']));
403 $config->setMarginLeft(ilUtil::stripSlashes($_POST['margin_left']));
404 $config->setMarginRight(ilUtil::stripSlashes($_POST['margin_right']));
405 $config->setMarginTop(ilUtil::stripSlashes($_POST['margin_top']));
406 $config->setMarginBottom(ilUtil::stripSlashes($_POST['margin_bottom']));
407 $config->setPrintMediaType((int) $_POST['print_media_type']);
408 $config->setJavascriptDelay((int) $_POST['javascript_delay']);
409 $config->setCheckboxSvg(ilUtil::stripSlashes($_POST['checkbox_svg']));
410 $config->setCheckboxCheckedSvg(ilUtil::stripSlashes($_POST['checkbox_checked_svg']));
411 $config->setRadioButtonSvg(ilUtil::stripSlashes($_POST['radio_button_svg']));
412 $config->setRadioButtonCheckedSvg(ilUtil::stripSlashes($_POST['radio_button_checked_svg']));
413 $config->setHeaderType((int) $_POST['header_select']);
414 $config->setHeaderTextLeft(ilUtil::stripSlashes($_POST['head_text_left']));
415 $config->setHeaderTextCenter(ilUtil::stripSlashes($_POST['head_text_center']));
416 $config->setHeaderTextRight(ilUtil::stripSlashes($_POST['head_text_right']));
417 $config->setHeaderTextSpacing((int) $_POST['head_text_spacing']);
418 $config->setHeaderTextLine((int) $_POST['head_text_line']);
419 $config->setHeaderHtmlLine((int) $_POST['head_html_line']);
420 $config->setHeaderHtmlSpacing((int) $_POST['head_html_spacing']);
421 $config->setHeaderHtml(ilUtil::stripSlashes($_POST['head_html']));
422 $config->setFooterType((int) $_POST['footer_select']);
423 $config->setFooterTextLeft(ilUtil::stripSlashes($_POST['footer_text_left']));
424 $config->setFooterTextCenter(ilUtil::stripSlashes($_POST['footer_text_center']));
425 $config->setFooterTextRight(ilUtil::stripSlashes($_POST['footer_text_right']));
426 $config->setFooterTextSpacing((int) $_POST['footer_text_spacing']);
427 $config->setFooterTextLine((int) $_POST['footer_text_line']);
428 $config->setFooterHtmlLine((int) $_POST['footer_html_line']);
429 $config->setFooterHtmlSpacing((int) $_POST['footer_html_spacing']);
430 $config->setFooterHtml(ilUtil::stripSlashes($_POST['footer_html']));
431 $config->setOverwriteDefaultFont(ilUtil::stripSlashes($_POST['overwrite_font']));
432 $this->saveNewDefaultBinaryPath($config->getPath());
433 }
434
435 return $everything_ok;
436 }
437
441 protected function saveNewDefaultBinaryPath($path){
442 $settings = new ilSetting('wkhtmltopdfrenderer');
443 $settings->set('path', $path);
444 }
445
451 {
452 return array(
453 'path' => $form->getItemByPostVar('path')->getValue(),
454 'zoom' => $form->getItemByPostVar('zoom')->getValue(),
455 'external_links' => $form->getItemByPostVar('external_links')->getChecked(),
456 'enable_forms' => $form->getItemByPostVar('enable_forms')->getChecked(),
457 'user_stylesheet' => $form->getItemByPostVar('user_stylesheet')->getValue(),
458 'low_quality' => $form->getItemByPostVar('low_quality')->getChecked(),
459 'greyscale' => $form->getItemByPostVar('greyscale')->getChecked(),
460 'orientation' => $form->getItemByPostVar('orientation')->getValue(),
461 'page_size' => $form->getItemByPostVar('page_size')->getValue(),
462 'margin_left' => $form->getItemByPostVar('margin_left')->getValue(),
463 'margin_right' => $form->getItemByPostVar('margin_right')->getValue(),
464 'margin_top' => $form->getItemByPostVar('margin_top')->getValue(),
465 'margin_bottom' => $form->getItemByPostVar('margin_bottom')->getValue(),
466 'print_media_type' => $form->getItemByPostVar('print_media_type')->getChecked(),
467 'javascript_delay' => $form->getItemByPostVar('javascript_delay')->getValue(),
468 'checkbox_svg' => $form->getItemByPostVar('checkbox_svg')->getValue(),
469 'checkbox_checked_svg' => $form->getItemByPostVar('checkbox_checked_svg')->getValue(),
470 'radio_button_svg' => $form->getItemByPostVar('radio_button_svg')->getValue(),
471 'radio_button_checked_svg' => $form->getItemByPostVar('radio_button_checked_svg')->getValue(),
472 'header_select' => $form->getItemByPostVar('header_select')->getValue(),
473 'head_text_left' => $form->getItemByPostVar('head_text_left')->getValue(),
474 'head_text_center' => $form->getItemByPostVar('head_text_center')->getValue(),
475 'head_text_right' => $form->getItemByPostVar('head_text_right')->getValue(),
476 'head_text_spacing' => $form->getItemByPostVar('head_text_spacing')->getValue(),
477 'head_text_line' => $form->getItemByPostVar('head_text_line')->getValue(),
478 'head_html_line' => $form->getItemByPostVar('head_html_line')->getValue(),
479 'head_html_spacing' => $form->getItemByPostVar('head_html_spacing')->getValue(),
480 'head_html' => $form->getItemByPostVar('head_html')->getValue(),
481 'footer_select' => $form->getItemByPostVar('footer_select')->getValue(),
482 'footer_text_left' => $form->getItemByPostVar('footer_text_left')->getValue(),
483 'footer_text_right' => $form->getItemByPostVar('footer_text_right')->getValue(),
484 'footer_text_spacing' => $form->getItemByPostVar('footer_text_spacing')->getValue(),
485 'footer_text_center' => $form->getItemByPostVar('footer_text_center')->getValue(),
486 'footer_text_line' => $form->getItemByPostVar('footer_text_line')->getValue(),
487 'footer_html' => $form->getItemByPostVar('footer_html')->getValue(),
488 'footer_html_spacing' => $form->getItemByPostVar('footer_html_spacing')->getValue(),
489 'overwrite_font' => $form->getItemByPostVar('overwrite_font')->getValue()
490 );
491 }
492
497 public function populateForm($form, $config)
498 {
499 $form->getItemByPostVar('path')->setValue($config->getWKHTMLToPdfDefaultPath());
500 $form->getItemByPostVar('zoom')->setValue($config->getZoom());
501 $form->getItemByPostVar('external_links')->setValue(1);
502 $form->getItemByPostVar('external_links')->setChecked($config->getExternalLinks());
503 $form->getItemByPostVar('enable_forms')->setValue(1);
504 $form->getItemByPostVar('enable_forms')->setChecked($config->getEnabledForms());
505 $form->getItemByPostVar('user_stylesheet')->setValue($config->getUserStylesheet());
506 $form->getItemByPostVar('low_quality')->setValue(1);
507 $form->getItemByPostVar('low_quality')->setChecked($config->getLowQuality());
508 $form->getItemByPostVar('greyscale')->setValue(1);
509 $form->getItemByPostVar('greyscale')->setChecked($config->getGreyscale());
510 $form->getItemByPostVar('orientation')->setValue($config->getOrientation());
511 $form->getItemByPostVar('page_size')->setValue($config->getPageSize());
512 $form->getItemByPostVar('margin_left')->setValue($config->getMarginLeft());
513 $form->getItemByPostVar('margin_right')->setValue($config->getMarginRight());
514 $form->getItemByPostVar('margin_top')->setValue($config->getMarginTop());
515 $form->getItemByPostVar('margin_bottom')->setValue($config->getMarginBottom());
516 $form->getItemByPostVar('print_media_type')->setValue(1);
517 $form->getItemByPostVar('print_media_type')->setChecked($config->getPrintMediaType());
518 $form->getItemByPostVar('javascript_delay')->setValue($config->getJavascriptDelay());
519 $form->getItemByPostVar('checkbox_svg')->setValue($config->getCheckboxSvg());
520 $form->getItemByPostVar('checkbox_checked_svg')->setValue($config->getCheckboxCheckedSvg());
521 $form->getItemByPostVar('radio_button_svg')->setValue($config->getRadioButtonSvg());
522 $form->getItemByPostVar('radio_button_checked_svg')->setValue($config->getRadioButtonCheckedSvg());
523 $form->getItemByPostVar('header_select')->setValue($config->getHeaderType());
524 $form->getItemByPostVar('head_text_left')->setValue($config->getHeaderTextLeft());
525 $form->getItemByPostVar('head_text_center')->setValue($config->getHeaderTextCenter());
526 $form->getItemByPostVar('head_text_right')->setValue($config->getHeaderTextRight());
527 $form->getItemByPostVar('head_text_spacing')->setValue($config->getHeaderTextSpacing());
528 $form->getItemByPostVar('head_text_line')->setValue(1);
529 $form->getItemByPostVar('head_text_line')->setChecked($config->isHeaderTextLine());
530 $form->getItemByPostVar('head_html_line')->setValue(1);
531 $form->getItemByPostVar('head_html_line')->setChecked($config->isHeaderHtmlLine());
532 $form->getItemByPostVar('head_html_spacing')->setValue($config->getHeaderHtmlSpacing());
533 $form->getItemByPostVar('head_html')->setValue($config->getHeaderHtml());
534 $form->getItemByPostVar('footer_select')->setValue($config->getFooterType());
535 $form->getItemByPostVar('footer_text_left')->setValue($config->getFooterTextLeft());
536 $form->getItemByPostVar('footer_text_center')->setValue($config->getFooterTextCenter());
537 $form->getItemByPostVar('footer_text_right')->setValue($config->getFooterTextRight());
538 $form->getItemByPostVar('footer_text_spacing')->setValue($config->getFooterTextSpacing());
539 $form->getItemByPostVar('footer_text_line')->setValue(1);
540 $form->getItemByPostVar('footer_text_line')->setChecked($config->isFooterTextLine());
541 $form->getItemByPostVar('footer_html_line')->setValue(1);
542 $form->getItemByPostVar('footer_html_line')->setChecked($config->isFooterHtmlLine());
543 $form->getItemByPostVar('footer_html')->setValue($config->getFooterHtml());
544 $form->getItemByPostVar('footer_html_spacing')->setValue($config->getFooterHtmlSpacing());
545 $form->getItemByPostVar('overwrite_font')->setValue($config->getOverwriteDefaultFont(false));
546
548 }
549}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This class represents a section header in a property form.
static setCheckedIfTrue(\ilPropertyFormGUI $form)
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getItemByPostVar($a_post_var)
Get Item by POST variable.
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.
ILIAS Setting Class.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static escapeShellCmd($a_arg)
escape shell cmd
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct()
ilWkhtmlToPdfConfigFormGUI constructor.
appendOutputOptionsForm(ilPropertyFormGUI $form)
$txt
Definition: error.php:13
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
$DIC
Definition: xapitoken.php:46