ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPDFGenerationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
36 include_once "./classes/class.ilObjectGUI.php";
37 
39 {
45 
46  function ilObjPDFGenerationGUI($a_data,$a_id,$a_call_by_reference)
47  {
48  global $rbacsystem, $lng;
49 
50  $this->type = "spdf";
51  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
52  $this->lng->loadLanguageModule('spdf');
53  $this->lng->loadLanguageModule('meta');
54 
55  if (!$rbacsystem->checkAccess('read',$this->object->getRefId()))
56  {
57  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read_spdf"),$this->ilias->error_obj->WARNING);
58  }
59  }
60 
61  function &executeCommand()
62  {
63  $next_class = $this->ctrl->getNextClass($this);
64  $cmd = $this->ctrl->getCmd();
65  $this->prepareOutput();
66 
67  switch($next_class)
68  {
69 
70  case 'ilpermissiongui':
71  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
72  $perm_gui =& new ilPermissionGUI($this);
73  $ret =& $this->ctrl->forwardCommand($perm_gui);
74  break;
75 
76  default:
77  if($cmd == "" || $cmd == "view")
78  {
79  $cmd = "settings";
80  }
81  $cmd .= "Object";
82  $this->$cmd();
83 
84  break;
85  }
86  return true;
87  }
88 
89 
94  function saveObject()
95  {
96  global $rbacadmin;
97 
98  // create and insert object in objecttree
99  $newObj = parent::saveObject();
100 
101  // put here object specific stuff
102 
103  // always send a message
104  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
105 
106  $this->ctrl->redirect($this);
107  //header("Location:".$this->getReturnLocation("save","adm_object.php?".$this->link_params));
108  //exit();
109  }
110 
111  public function settingsObject()
112  {
113  global $ilAccess, $ilias;
114 
115  if (!$ilAccess->checkAccess("visible", "", $_GET['ref_id']))
116  {
117  $ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
118  }
119 
120  $pdfSetting = new ilSetting("pdf");
121 
122  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
123  $form = new ilPropertyFormGUI();
124  $form->setFormAction($this->ctrl->getFormAction($this));
125  $form->setTableWidth("100%");
126  $form->setId("settings");
127 
128  // general properties
129  $header = new ilFormSectionHeaderGUI();
130  $header->setTitle($this->lng->txt("pdf_html_to_pdf_settings"));
131  $form->addItem($header);
132 
133  $method = new ilSelectInputGUI($this->lng->txt("pdf_html_to_pdf_method"), "html_to_pdf_method");
134  $options = array();
135  $options['none'] = $this->lng->txt('pdf_html_to_pdf_method_not_available');
136  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
137  if(ilRPCServerSettings::getInstance()->isEnabled())
138  {
139  $options['fop'] = $this->lng->txt('pdf_html_to_pdf_method_fop');
140  }
141  if (strlen($pdfSetting->get("path_to_wkhtml")))
142  {
143  $options['webkit'] = $this->lng->txt('pdf_html_to_pdf_method_webkit');
144  }
145  $method->setOptions($options);
146  $method->setValue((strlen($pdfSetting->get('html_to_pdf_method'))) ? $pdfSetting->get('html_to_pdf_method') : 'none');
147  $method->setRequired(true);
148  $form->addItem($method);
149 
150  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
151  {
152  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
153  }
154  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
155  }
156 
157  public function saveSettingsObject()
158  {
159  global $ilCtrl, $ilAccess;
160 
161  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) $ilCtrl->redirect($this, "settings");
162  $pdfSetting = new ilSetting("pdf");
163  $pdfSetting->set("html_to_pdf_method", $_POST["html_to_pdf_method"]);
164  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
165  $ilCtrl->redirect($this, "settings");
166  }
167 
168  public function webkitObject()
169  {
170  global $ilAccess;
171 
172  global $ilAccess, $ilias;
173 
174  if (!$ilAccess->checkAccess("visible", "", $_GET['ref_id']))
175  {
176  $ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
177  }
178 
179  $pdfSetting = new ilSetting("pdf");
180  $wkhtmltopdf = array_key_exists("path_to_wkhtml", $_GET) ? $_GET["path_to_wkhtml"] : $pdfSetting->get("path_to_wkhtml");
181 
182  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
183  $form = new ilPropertyFormGUI();
184  $form->setFormAction($this->ctrl->getFormAction($this));
185  $form->setTableWidth("100%");
186  $form->setId("settings");
187 
188  // general properties
189  $header = new ilFormSectionHeaderGUI();
190  $header->setTitle($this->lng->txt("pdf_wkhtml_settings"));
191  $form->addItem($header);
192 
193  $path_to_wkhtml = new ilTextInputGUI($this->lng->txt("pdf_path_to_wkhtml"), "path_to_wkhtml");
194  $path_to_wkhtml->setSize(60);
195  $path_to_wkhtml->setValue($wkhtmltopdf);
196  if (!@file_exists($wkhtmltopdf) && strlen($wkhtmltopdf)) $path_to_wkhtml->setAlert($this->lng->txt('pdf_file_path_not_found'));
197  $form->addItem($path_to_wkhtml);
198 
199  $wkhtml_info = new ilNonEditableValueGUI();
200  $wkhtml_info->setInfo($this->lng->txt('pdf_wkhtml_info'));
201  $form->addItem($wkhtml_info);
202 
203  $headers_footer = new ilFormSectionHeaderGUI();
204  $headers_footer->setTitle($this->lng->txt("pdf_headers_footer_options"));
205  $form->addItem($headers_footer);
206 
207  $header_font_size = new ilNumberInputGUI($this->lng->txt("pdf_header_font_size"), "args_header_font_size");
208  $header_font_size->setSuffix('pt');
209  $header_font_size->setSize(3);
210  $header_font_size->setValue(strlen($pdfSetting->get("args_header_font_size")) ? $pdfSetting->get("args_header_font_size") : "9");
211  $form->addItem($header_font_size);
212 
213  $header_left = new ilTextInputGUI($this->lng->txt("pdf_header_left"), "args_header_left");
214  $header_left->setSize(20);
215  $header_left->setValue(strlen($pdfSetting->get("args_header_left")) ? $pdfSetting->get("args_header_left") : "[date]");
216  $form->addItem($header_left);
217 
218  $header_center = new ilTextInputGUI($this->lng->txt("pdf_header_center"), "args_header_center");
219  $header_center->setSize(20);
220  $header_center->setValue(strlen($pdfSetting->get("args_header_center")) ? $pdfSetting->get("args_header_center") : "ILIAS Open Source");
221  $form->addItem($header_center);
222 
223  $header_right = new ilTextInputGUI($this->lng->txt("pdf_header_right"), "args_header_right");
224  $header_right->setSize(20);
225  $header_right->setValue(strlen($pdfSetting->get("args_header_right")) ? $pdfSetting->get("args_header_right") : "[time]");
226  $form->addItem($header_right);
227 
228  $header_line = new ilCheckboxInputGUI($this->lng->txt("pdf_header_line"), "args_header_line");
229  $header_line->setValue(1);
230  $header_line->setChecked((strcmp($pdfSetting->get("args_header_line"), '--header-line') == 0) ? true : false);
231  $header_line->setOptionTitle($this->lng->txt("pdf_header_line_desc"));
232  $form->addItem($header_line);
233 
234  $footer_font_size = new ilNumberInputGUI($this->lng->txt("pdf_footer_font_size"), "args_footer_font_size");
235  $footer_font_size->setSize(3);
236  $footer_font_size->setSuffix('pt');
237  $footer_font_size->setValue(strlen($pdfSetting->get("args_footer_font_size")) ? $pdfSetting->get("args_footer_font_size") : "9");
238  $form->addItem($footer_font_size);
239 
240  $footer_left = new ilTextInputGUI($this->lng->txt("pdf_footer_left"), "args_footer_left");
241  $footer_left->setSize(20);
242  $footer_left->setValue(strlen($pdfSetting->get("args_footer_left")) ? $pdfSetting->get("args_footer_left") : "");
243  $form->addItem($footer_left);
244 
245  $footer_center = new ilTextInputGUI($this->lng->txt("pdf_footer_center"), "args_footer_center");
246  $footer_center->setSize(20);
247  $footer_center->setValue(strlen($pdfSetting->get("args_footer_center")) ? $pdfSetting->get("args_footer_center") : "");
248  $form->addItem($footer_center);
249 
250  $footer_right = new ilTextInputGUI($this->lng->txt("pdf_footer_right"), "args_footer_right");
251  $footer_right->setSize(20);
252  $footer_right->setValue(strlen($pdfSetting->get("args_footer_right")) ? $pdfSetting->get("args_footer_right") : "[page]/[toPage]");
253  $form->addItem($footer_right);
254 
255  $footer_line = new ilCheckboxInputGUI($this->lng->txt("pdf_footer_line"), "args_footer_line");
256  $footer_line->setValue(1);
257  $footer_line->setChecked((strcmp($pdfSetting->get("args_footer_line"), '--footer-line') == 0) ? true : false);
258  $footer_line->setOptionTitle($this->lng->txt("pdf_footer_line_desc"));
259  $form->addItem($footer_line);
260 
261  $headers_info = new ilNonEditableValueGUI();
262  $headers_info->setInfo($this->lng->txt('pdf_header_footer_parm_desc'));
263  $form->addItem($headers_info);
264 
265  $page_options = new ilFormSectionHeaderGUI();
266  $page_options->setTitle($this->lng->txt("pdf_page_options"));
267  $form->addItem($page_options);
268 
269  $zoom = new ilNumberInputGUI($this->lng->txt("pdf_zoom"), "args_zoom");
270  $zoom->setSuffix($this->lng->txt("pdf_zoom_suffix"));
271  $zoom->setSize(20);
272  $zoom->setValue(strlen($pdfSetting->get("args_zoom")) ? $pdfSetting->get("args_zoom") : 0.75);
273  $form->addItem($zoom);
274 
275  $external_links = new ilCheckboxInputGUI($this->lng->txt("pdf_external_links"), "args_external_links");
276  $external_links->setValue(1);
277  $external_links->setChecked((strlen($pdfSetting->get("args_footer_line")) == 0 || strcmp($pdfSetting->get("args_footer_line"), '--enable-external-links') == 1) ? true : false);
278  $external_links->setOptionTitle($this->lng->txt("pdf_external_links_desc"));
279  $form->addItem($external_links);
280 
281  $enable_forms = new ilCheckboxInputGUI($this->lng->txt("pdf_enable_forms"), "args_enable_forms");
282  $enable_forms->setValue(1);
283  $enable_forms->setChecked((strcmp($pdfSetting->get("args_enable_forms"), '--enable-forms') == 1) ? true : false);
284  $enable_forms->setOptionTitle($this->lng->txt("pdf_enable_forms_desc"));
285  $form->addItem($enable_forms);
286 
287  $user_style_sheet = new ilTextInputGUI($this->lng->txt("pdf_user_style_sheet"), "args_user_style_sheet");
288  $user_style_sheet->setInfo($this->lng->txt("pdf_user_style_sheet_desc"));
289  $user_style_sheet->setSuffix($this->lng->txt("url"));
290  $user_style_sheet->setSize(50);
291  $user_style_sheet->setValue(strlen($pdfSetting->get("args_user_style_sheet")) ? $pdfSetting->get("args_user_style_sheet") : "");
292  $form->addItem($user_style_sheet);
293 
294  $page_size = new ilSelectInputGUI($this->lng->txt("pdf_page_size"), "args_page_size");
295  $pagesizes = array('A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','B0','B1','B2','B3','B4','B5','B6','B7','B8','B9','B10','CSE','Comm10E','DLE','Executive','Folio','Ledger','Legal','Letter','Tabloid');
296  $options = array();
297  foreach ($pagesizes as $size)
298  {
299  $options[$size] = $size;
300  }
301  $page_size->setOptions($options);
302  $page_size->setValue((strlen($pdfSetting->get('args_page_size')) == 0) ? 'A4' : $pdfSetting->get('args_page_size'));
303  $page_size->setRequired(true);
304  $form->addItem($page_size);
305 
306  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
307  {
308  $form->addCommandButton("saveWebkit", $this->lng->txt("save"));
309  }
310  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
311  }
312 
316  function saveWebkitObject()
317  {
318  global $ilCtrl, $ilAccess;
319 
320  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) $ilCtrl->redirect($this, "settings");
321  $pdfSetting = new ilSetting("pdf");
322  $pdfSetting->set("path_to_wkhtml", $_POST["path_to_wkhtml"]);
323  $pdfSetting->set("args_header_font_size", $_POST["args_header_font_size"]);
324  $pdfSetting->set("args_header_left", $_POST["args_header_left"]);
325  $pdfSetting->set("args_header_center", $_POST["args_header_center"]);
326  $pdfSetting->set("args_header_right", $_POST["args_header_right"]);
327  $pdfSetting->set("args_header_line", ($_POST["args_header_line"] == 1) ? '--header-line' : '--no-header-line');
328  $pdfSetting->set("args_footer_font_size", $_POST["args_footer_font_size"]);
329  $pdfSetting->set("args_footer_left", $_POST["args_footer_left"]);
330  $pdfSetting->set("args_footer_center", $_POST["args_footer_center"]);
331  $pdfSetting->set("args_footer_right", $_POST["args_footer_right"]);
332  $pdfSetting->set("args_footer_line", ($_POST["args_footer_line"] == 1) ? '--footer-line' : '--no-footer-line');
333  $pdfSetting->set("args_zoom", $_POST["args_zoom"]);
334  $pdfSetting->set("args_external_links", ($_POST["args_external_links"] == 1) ? '--enable-external-links' : '--disable-external-links');
335  $pdfSetting->set("args_enable_forms", ($_POST["args_enable_forms"] == 1) ? '--enable-forms' : '--disable-forms');
336  $pdfSetting->set("args_user_style_sheet", $_POST["args_user_style_sheet"]);
337  $pdfSetting->set("args_page_size", $_POST["args_page_size"]);
338  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
339  $ilCtrl->redirect($this, "webkit");
340  }
341 
342  function getAdminTabs(&$tabs_gui)
343  {
344  $this->getTabs($tabs_gui);
345  }
346 
352  function getTabs(&$tabs_gui)
353  {
354  global $ilAccess;
355 
356  if ($ilAccess->checkAccess("read",'',$this->object->getRefId()))
357  {
358  $tabs_gui->addTarget("spdf_settings", $this->ctrl->getLinkTarget($this, "settings"), array("settings", "saveSettings","","view"), "", "");
359  $tabs_gui->addTarget("webkit", $this->ctrl->getLinkTarget($this, "webkit"), array("webkit", "saveWebkit"), "", "");
360  }
361  if ($ilAccess->checkAccess("edit_permission",'',$this->object->getRefId()))
362  {
363  $tabs_gui->addTarget("perm_settings",
364  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
365  }
366  }
367 } // END class.ilObjAdvancedEditingGUI
368 ?>