ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCTableGUI.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 
24 require_once("./Services/COPage/classes/class.ilPCTable.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCTableGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  $ret =& $this->$cmd();
64  break;
65  }
66 
67  return $ret;
68  }
69 
70 
74  function setTabs()
75  {
76  global $ilTabs, $ilCtrl, $lng;
77 
78  $ilTabs->setBackTarget($lng->txt("pg"),
79  $this->ctrl->getParentReturn($this));
80 
81  $ilTabs->addTarget("cont_table_properties",
82  $ilCtrl->getLinkTarget($this, "edit"), "edit",
83  get_class($this));
84 
85  $ilTabs->addTarget("cont_table_cell_properties",
86  $ilCtrl->getLinkTarget($this, "editCells"), "editCells",
87  get_class($this));
88 
89  }
90 
94  function edit()
95  {
96  global $ilCtrl, $lng, $tpl;
97 
98  $this->displayValidationError();
99  $this->setTabs();
100 
101  // edit form
102  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
103  $form = new ilPropertyFormGUI();
104  $form->setFormAction($ilCtrl->getFormAction($this));
105  $form->setTitle($this->lng->txt("cont_table_properties"));
106 
107  // width
108  $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
109  $width->setValue($this->content_obj->getWidth());
110  $width->setSize(6);
111  $width->setMaxLength(6);
112  $form->addItem($width);
113 
114  // border
115  $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
116  $border->setValue($this->content_obj->getBorder());
117  $border->setSize(6);
118  $border->setMaxLength(6);
119  $form->addItem($border);
120 
121  // padding
122  $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
123  $padding->setValue($this->content_obj->getCellPadding());
124  $padding->setSize(6);
125  $padding->setMaxLength(6);
126  $form->addItem($padding);
127 
128  // spacing
129  $spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
130  $spacing->setValue($this->content_obj->getCellSpacing());
131  $spacing->setSize(6);
132  $spacing->setMaxLength(6);
133  $form->addItem($spacing);
134 
135  // alignment
136  $align_opts = array("Left" => $lng->txt("cont_left"),
137  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
138  "LeftFloat" => $lng->txt("cont_left_float"),
139  "RightFloat" => $lng->txt("cont_right_float"));
140  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
141  $align->setOptions($align_opts);
142  $align->setValue($this->content_obj->getHorizontalAlign());
143  $form->addItem($align);
144 
145  // caption
146  $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
147  $caption->setValue($this->content_obj->getCaption());
148  $caption->setSize(60);
149  $form->addItem($caption);
150 
151  // caption align
152  $ca_opts = array("top" => $lng->txt("cont_top"),
153  "bottom" => $lng->txt("cont_bottom"));
154  $ca = new ilSelectInputGUI($this->lng->txt("cont_align"),
155  "cap_align");
156  $ca->setOptions($ca_opts);
157  $ca->setValue($this->content_obj->getCaptionAlign());
158  $caption->addSubItem($ca);
159 
160  // language
161  $s_lang = $this->content_obj->getLanguage();
162  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
164  //$select_language = ilUtil::formSelect ($s_lang, "tab_language", $lang, false, true);
165  $language = new ilSelectInputGUI($this->lng->txt("language"), "tab_language");
166  $language->setOptions($lang);
167  $language->setValue($s_lang);
168  $form->addItem($language);
169 
170  $form->addCommandButton("saveProperties", $lng->txt("save"));
171 
172  $html = $form->getHTML();
173  $html.= "<br />".$this->renderTable("");
174  $tpl->setContent($html);
175  }
176 
180  function renderTable($a_mode = "table_edit")
181  {
182  global $ilUser;
183 
184  $tab_node = $this->content_obj->getNode();
185  $content = $this->dom->dump_node($tab_node);
186  $trans = $this->pg_obj->getLanguageVariablesXML();
187  $mobs = $this->pg_obj->getMultimediaXML();
188  $content = "<dummy>".$content.$mobs.$trans."</dummy>";
189 
190  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
191  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
192  $xh = xslt_create();
193 //echo "<b>XML</b>:".htmlentities($content).":<br>";
194 //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
195  $med_disabled_path = ilUtil::getImagePath("media_disabled.gif");
196  $wb_path = ilUtil::getWebspaceDir("output");
197  $enlarge_path = ilUtil::getImagePath("enlarge.gif");
198  $params = array ('mode' => $a_mode,
199  'med_disabled_path' => $med_disabled_path,
200  'media_mode' => $ilUser->getPref("ilPageEditor_MediaMode"),
201  'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
202  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
203  echo xslt_error($xh);
204  xslt_free($xh);
205 
206  // unmask user html
207  $output = str_replace("&lt;","<",$output);
208  $output = str_replace("&gt;",">",$output);
209  $output = str_replace("&amp;","&",$output);
210 
211  return '<div style="float:left;">'.$output.'</div>';
212  }
213 
217  function editCells()
218  {
219  global $ilCtrl, $tpl, $lng;
220 
221  $this->displayValidationError();
222  $this->setTabs();
223 
224  // edit form
225  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
226  $form = new ilPropertyFormGUI();
227  $form->setFormAction($ilCtrl->getFormAction($this));
228  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
229 
230  // first row style
231  require_once("./Services/Form/classes/class.ilRadioMatrixInputGUI.php");
232  $style = new ilRadioMatrixInputGUI($this->lng->txt("cont_style"), "style");
233  $options = array("" => $this->lng->txt("none"), "ilc_Cell1" => "Cell1", "ilc_Cell2" => "Cell2",
234  "ilc_Cell3" => "Cell3", "ilc_Cell4" => "Cell4");
235  foreach($options as $k => $option)
236  {
237  $options[$k] = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="'.$k.'">'.
238  $option.'</td></tr></table>';
239  }
240 
241  $style->setValue("");
242  $style->setInfo($lng->txt("cont_set_tab_style_info"));
243  $style->setOptions($options);
244  $form->addItem($style);
245  $form->setKeepOpen(true);
246 
247  $form->addCommandButton("setStylesAndWidths", $lng->txt("cont_set_styles_and_widths"));
248 
249  $html = $form->getHTML();
250  $html.= "<br />".$this->renderTable()."</form>";
251  $tpl->setContent($html);
252 
253  }
254 
259  {
260  if (is_array($_POST["target"]))
261  {
262  foreach ($_POST["target"] as $k => $value)
263  {
264  if ($value > 0)
265  {
266  $cid = explode(":", $k);
267  $this->content_obj->setTDClass($cid[0], $_POST["style"], $cid[1]);
268  }
269  }
270  }
271  if (is_array($_POST["width"]))
272  {
273  foreach ($_POST["width"] as $k => $width)
274  {
275  $cid = explode(":", $k);
276  $this->content_obj->setTDWidth($cid[0], $width, $cid[1]);
277  }
278  }
279  $this->updated = $this->pg_obj->update();
280  $this->ctrl->redirect($this, "editCells");
281  }
282 
286  function setWidth()
287  {
288  if (is_array($_POST["target"]))
289  {
290  foreach ($_POST["target"] as $target)
291  {
292  $cid = explode(":", $target);
293  $this->content_obj->setTDWidth($cid[0], $_POST["td_width"], $cid[1]);
294  }
295  }
296 
297  $this->setProperties();
298  $this->updated = $this->pg_obj->update();
299  $this->pg_obj->addHierIDs();
300  $this->edit();
301  }
302 
306  function setClass()
307  {
308  if (is_array($_POST["target"]))
309  {
310  foreach ($_POST["target"] as $target)
311  {
312  $cid = explode(":", $target);
313  $this->content_obj->setTDClass($cid[0], $_POST["td_class"], $cid[1]);
314  }
315  }
316  $this->setProperties();
317  $this->updated = $this->pg_obj->update();
318  $this->pg_obj->addHierIDs();
319  $this->edit();
320  }
321 
322 
323  function setProperties()
324  {
325  // mask html
326  $caption = ilUtil::stripSlashes($_POST["caption"]);
327  $caption = str_replace("&","&amp;", $caption);
328  $caption = str_replace("<","&lt;", $caption);
329  $caption = str_replace(">","&gt;", $caption);
330 
331  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
332  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
333  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
334  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
335  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
336  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
337  $this->content_obj->setCaption($caption,
338  ilUtil::stripSlashes($_POST["cap_align"]));
339  }
340 
344  function saveProperties()
345  {
346  $this->setProperties();
347  $this->updated = $this->pg_obj->update();
348  if ($this->updated === true)
349  {
350  $this->ctrl->redirect($this, "edit");
351  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
352  }
353  else
354  {
355  $this->pg_obj->addHierIDs();
356  $this->edit();
357  }
358  }
359 
363  function rightAlign()
364  {
365  $this->content_obj->setHorizontalAlign("Right");
366  $_SESSION["il_pg_error"] = $this->pg_obj->update();
367  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
368  }
369 
373  function leftAlign()
374  {
375  $this->content_obj->setHorizontalAlign("Left");
376  $_SESSION["il_pg_error"] = $this->pg_obj->update();
377  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
378  }
379 
383  function centerAlign()
384  {
385  $this->content_obj->setHorizontalAlign("Center");
386  $_SESSION["il_pg_error"] = $this->pg_obj->update();
387  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
388  }
389 
393  function leftFloatAlign()
394  {
395  $this->content_obj->setHorizontalAlign("LeftFloat");
396  $_SESSION["il_pg_error"] = $this->pg_obj->update();
397  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
398  }
399 
403  function rightFloatAlign()
404  {
405  $this->content_obj->setHorizontalAlign("RightFloat");
406  $_SESSION["il_pg_error"] = $this->pg_obj->update();
407  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
408  }
409 
413  function insert()
414  {
415  global $ilUser, $ilCtrl, $tpl, $lng;
416 
417  $this->displayValidationError();
418 
419  // edit form
420  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
421  $form = new ilPropertyFormGUI();
422  $form->setFormAction($ilCtrl->getFormAction($this));
423  $form->setTitle($this->lng->txt("cont_insert_table"));
424 
425  $nr = array();
426  for($i=1; $i<=20; $i++)
427  {
428  $nr[$i] = $i;
429  }
430 
431  // cols
432  $cols = new ilSelectInputGUI($this->lng->txt("cont_nr_cols"), "nr_cols");
433  $cols->setOptions($nr);
434  $cols->setValue(2);
435  $form->addItem($cols);
436 
437  // rows
438  $rows = new ilSelectInputGUI($this->lng->txt("cont_nr_rows"), "nr_rows");
439  $rows->setOptions($nr);
440  $rows->setValue(2);
441  $form->addItem($rows);
442 
443  // width
444  $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
445  $width->setValue("");
446  $width->setSize(6);
447  $width->setMaxLength(6);
448  $form->addItem($width);
449 
450  // border
451  $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
452  $border->setValue("1px");
453  $border->setSize(6);
454  $border->setMaxLength(6);
455  $form->addItem($border);
456 
457  // padding
458  $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
459  $padding->setValue("2px");
460  $padding->setSize(6);
461  $padding->setMaxLength(6);
462  $form->addItem($padding);
463 
464  // spacing
465  $spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
466  $spacing->setValue("0px");
467  $spacing->setSize(6);
468  $spacing->setMaxLength(6);
469  $form->addItem($spacing);
470 
471  // first row style
472  require_once("./Services/Form/classes/class.ilRadioMatrixInputGUI.php");
473  $fr_style = new ilRadioMatrixInputGUI($this->lng->txt("cont_first_row_style"), "first_row_style");
474  $options = array("" => $this->lng->txt("none"), "ilc_Cell1" => "Cell1", "ilc_Cell2" => "Cell2",
475  "ilc_Cell3" => "Cell3", "ilc_Cell4" => "Cell4");
476  foreach($options as $k => $option)
477  {
478  $options[$k] = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="'.$k.'">'.
479  $option.'</td></tr></table>';
480  }
481 
482  $fr_style->setValue("");
483  $fr_style->setOptions($options);
484  $form->addItem($fr_style);
485 
486  // alignment
487  $align_opts = array("Left" => $lng->txt("cont_left"),
488  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
489  "LeftFloat" => $lng->txt("cont_left_float"),
490  "RightFloat" => $lng->txt("cont_right_float"));
491  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
492  $align->setOptions($align_opts);
493  $align->setValue("Center");
494  $form->addItem($align);
495 
496  // import table
497  $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
498  $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
499  $import->addOption($op);
500  $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
501 
502  $import_data = new ilTextAreaInputGUI("", "import_table");
503  $import_data->setRows(8);
504  $import_data->setCols(50);
505  $op2->addSubItem($import_data);
506 
507  $import->addOption($op2);
508  $import->setValue("html");
509  $form->addItem($import);
510 
511  // language
512  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
513  {
514  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
515  }
516  else
517  {
518  $s_lang = $ilUser->getLanguage();
519  }
520  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
522  //$select_language = ilUtil::formSelect ($s_lang, "tab_language", $lang, false, true);
523  $language = new ilSelectInputGUI($this->lng->txt("language"), "tab_language");
524  $language->setOptions($lang);
525  $language->setValue($s_lang);
526  $form->addItem($language);
527 
528  $form->addCommandButton("create_tab", $lng->txt("save"));
529  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
530 
531  $html = $form->getHTML();
532  $tpl->setContent($html);
533 return;
534 
535  // new table form (input of rows and columns)
536  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.table_new.html", "Services/COPage");
537  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_table"));
538  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
539 
540  for($i=1; $i<=10; $i++)
541  {
542  $nr[$i] = $i;
543  }
544 
545  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
546  {
547  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
548  }
549  else
550  {
551  $s_lang = $ilUser->getLanguage();
552  }
553 
554  // select fields for number of columns
555  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
556  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
558  $select_language = ilUtil::formSelect ($s_lang, "tab_language", $lang, false, true);
559  $this->tpl->setVariable("SELECT_LANGUAGE", $select_language);
560  $this->tpl->setVariable("TXT_COLS", $this->lng->txt("cont_nr_cols"));
561  $select_cols = ilUtil::formSelect ("2","nr_cols",$nr,false,true);
562  $this->tpl->setVariable("SELECT_COLS", $select_cols);
563  $this->tpl->setVariable("TXT_ROWS", $this->lng->txt("cont_nr_rows"));
564  $select_rows = ilUtil::formSelect ("2","nr_rows",$nr,false,true);
565  $this->tpl->setVariable("SELECT_ROWS", $select_rows);
566 
567  //import html table
568  $this->tpl->setVariable("TXT_HTML_IMPORT", $this->lng->txt("cont_table_html_import"));
569  $this->tpl->setVariable("TXT_SPREADSHEET", $this->lng->txt("cont_table_spreadsheet_import"));
570  $this->tpl->setVariable("TXT_BTN_HTML_IMPORT", $this->lng->txt("import"));
571  $this->tpl->setVariable("TXT_HTML_IMPORT_INFO", $this->lng->txt("cont_table_html_import_info"));
572  $this->tpl->setVariable("TXT_SPREADSHEET_IMPORT_INFO", $this->lng->txt("cont_table_spreadsheet_import_info"));
573  $this->tpl->setVariable("CMD_HTML_IMPORT", "create_tab");
574  $this->tpl->setVariable("SELECT_ROWS", $select_rows);
575 
576 // $this->tpl->parseCurrentBlock();
577 
578  // operations
579  $this->tpl->setCurrentBlock("commands");
580  $this->tpl->setVariable("BTN_NAME", "create_tab");
581  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
582  $this->tpl->setVariable("BTN_CANCEL", "cancelCreate");
583  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
584  $this->tpl->parseCurrentBlock();
585 
586  }
587 
588 
592  function create()
593  {
594  global $lng;
595  $this->content_obj = new ilPCTable($this->dom);
596  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
597  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["tab_language"]));
598  $import_table = trim($_POST["import_table"]);
599 
600  // import xhtml or spreadsheet table
601  if (!empty ($import_table))
602  {
603  switch($_POST["import_type"])
604  {
605  // xhtml import
606  case "html":
607  if (!$this->content_obj->importHtml ($_POST["tab_language"], $import_table))
608  {
609  $this->insert();
610  return;
611  }
612  break;
613 
614  // spreadsheet
615  case "spreadsheet":
616  $this->content_obj->importSpreadsheet($_POST["tab_language"], $import_table);
617  break;
618  }
619  }
620  else
621  {
622  $this->content_obj->addRows(ilUtil::stripSlashes($_POST["nr_rows"]),
623  ilUtil::stripSlashes($_POST["nr_cols"]));
624  }
625  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
626  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
627  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
628  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
629  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
630 
631  $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
632  if ($frtype != "")
633  {
634  $this->content_obj->setFirstRowStyle($frtype);
635  }
636 
637  $this->updated = $this->pg_obj->update();
638 
639  if ($this->updated === true)
640  {
641  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
642  }
643  else
644  {
645  $this->insert();
646  }
647  }
648 }
649 ?>