ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCDataTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPCDataTable.php");
5 require_once("./Services/COPage/classes/class.ilPCTableGUI.php");
6 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7 
19 {
20 
25  function ilPCDataTableGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
26  {
27  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
28  $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
29  }
30 
34  function &executeCommand()
35  {
36  $this->getCharacteristicsOfCurrentStyle("table"); // scorm-2004
37 
38  // get next class that processes or forwards current command
39  $next_class = $this->ctrl->getNextClass($this);
40 
41  // get current command
42  $cmd = $this->ctrl->getCmd();
43 
44  switch($next_class)
45  {
46  default:
47  $ret =& $this->$cmd();
48  break;
49  }
50 
51  return $ret;
52  }
53 
54 
58 
62  function editDataCl()
63  {
64  global $lng, $ilCtrl;
65 //var_dump($_GET);
66 //var_dump($_POST);
67 
68  $this->setTabs();
69 
70  $this->displayValidationError();
71 
72  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
73 
74  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata.html", "Services/COPage");
75  $dtpl = $this->tpl;
76  //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage");
77  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
78  $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0"));
79 
80  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
81  $this->tpl->addJavascript("./Services/COPage/js/page_editing.js");
82 
83  // get all rows
84  $xpc = xpath_new_context($this->dom);
85  $path = "//PageContent[@HierId='".$this->getHierId()."']".
86  "/Table/TableRow";
87  $res =& xpath_eval($xpc, $path);
88 
89  for($i = 0; $i < count($res->nodeset); $i++)
90  {
91 
92  $xpc2 = xpath_new_context($this->dom);
93  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
94  "/Table/TableRow[$i+1]/TableData";
95  $res2 =& xpath_eval($xpc2, $path2);
96 
97  // if this is the first row -> col icons
98  if ($i == 0)
99  {
100  for($j = 0; $j < count($res2->nodeset); $j++)
101  {
102  if ($j == 0)
103  {
104  $dtpl->touchBlock("empty_td");
105  }
106 
107  if ($j == 0)
108  {
109  if (count($res2->nodeset) == 1)
110  {
111  $move_type = "none";
112  }
113  else
114  {
115  $move_type = "forward";
116  }
117  }
118  else if ($j == (count($res2->nodeset) - 1))
119  {
120  $move_type = "backward";
121  }
122  else
123  {
124  $move_type = "both";
125  }
126  $dtpl->setCurrentBlock("col_icon");
127  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
128  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.png"));
129  $dtpl->setVariable("COL_ONCLICK", "COL_".$move_type);
130  $dtpl->setVariable("NR", $j);
131  $dtpl->parseCurrentBlock();
132  }
133  $dtpl->setCurrentBlock("row");
134  $dtpl->parseCurrentBlock();
135  }
136 
137 
138  for($j = 0; $j < count($res2->nodeset); $j++)
139  {
140  // first col: row icons
141  if ($j == 0)
142  {
143  if ($i == 0)
144  {
145  if (count($res->nodeset) == 1)
146  {
147  $move_type = "none";
148  }
149  else
150  {
151  $move_type = "forward";
152  }
153  }
154  else if ($i == (count($res->nodeset) - 1))
155  {
156  $move_type = "backward";
157  }
158  else
159  {
160  $move_type = "both";
161  }
162  $dtpl->setCurrentBlock("row_icon");
163  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
164  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.png"));
165  $dtpl->setVariable("ROW_ONCLICK", "ROW_".$move_type);
166  $dtpl->setVariable("NR", $i);
167  $dtpl->parseCurrentBlock();
168  }
169 
170  // cell
171  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y")
172  {
173  $dtpl->setCurrentBlock("cell");
174 
175  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update")
176  {
177  $s_text = ilUtil::stripSlashes("cell_".$i."_".$j, false);
178  }
179  else
180  {
181  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j));
182  }
183 
184  $dtpl->setVariable("PAR_TA_NAME", "cell[".$i."][".$j."]");
185  $dtpl->setVariable("PAR_TA_ID", "cell_".$i."_".$j);
186  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
187 
188  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
189  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
190 // $dtpl->setVariable("WIDTH", "140");
191 // $dtpl->setVariable("HEIGHT", "80");
192  if ($cs > 1)
193  {
194  $dtpl->setVariable("COLSPAN", 'colspan="'.$cs.'"');
195  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
196  }
197  if ($rs > 1)
198  {
199  $dtpl->setVariable("ROWSPAN", 'rowspan="'.$rs.'"');
200  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
201  }
202  $dtpl->parseCurrentBlock();
203  }
204  }
205  $dtpl->setCurrentBlock("row");
206  $dtpl->parseCurrentBlock();
207  }
208 
209  // init menues
210  $types = array("row", "col");
211  $moves = array("none", "backward", "both", "forward");
212  $commands = array(
213  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
214  "newRowBefore" => "cont_ed_new_row_before",
215  "moveRowUp" => "cont_ed_row_up",
216  "moveRowDown" => "cont_ed_row_down",
217  "deleteRow" => "cont_ed_delete_row"),
218  "col" => array( "newColAfter" => "cont_ed_new_col_after",
219  "newColBefore" => "cont_ed_new_col_before",
220  "moveColLeft" => "cont_ed_col_left",
221  "moveColRight" => "cont_ed_col_right",
222  "deleteCol" => "cont_ed_delete_col")
223  );
224 
225  foreach($types as $type)
226  {
227  foreach($moves as $move)
228  {
229  foreach($commands[$type] as $command => $lang_var)
230  {
231  if ($move == "none" && (substr($command, 0, 4) == "move"))
232  {
233  continue;
234  }
235  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
236  ($move == "forward" && (in_array($command, array("moveup", "moveleft")))))
237  {
238  continue;
239  }
240  $this->tpl->setCurrentBlock("menu_item");
241  $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
242  $this->tpl->setVariable("CMD", $command);
243  $this->tpl->setVariable("TYPE", $type);
244  $this->tpl->parseCurrentBlock();
245  }
246  $this->tpl->setCurrentBlock("menu");
247  $this->tpl->setVariable("TYPE", $type);
248  $this->tpl->setVariable("MOVE", $move);
249  $this->tpl->parseCurrentBlock();
250  }
251  }
252 
253  // update/cancel
254  $this->tpl->setCurrentBlock("commands");
255  $this->tpl->setVariable("BTN_NAME", "update");
256  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
257  $this->tpl->parseCurrentBlock();
258 
259  $this->tpl->setVariable("FORMACTION2",
260  $ilCtrl->getFormAction($this, "tableAction"));
261  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
262 
263  }
264 
268  function update($a_redirect = true)
269  {
270  global $ilBench, $lng;
271 
272  $ilBench->start("Editor","Data_Table_update");
273 
274  // handle input data
275  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
276  $data = array();
277 //var_dump($_POST["cell"]);
278 //var_dump($_GET);
279  if (is_array($_POST["cell"]))
280  {
281  foreach ($_POST["cell"] as $i => $row)
282  {
283  if (is_array($row))
284  {
285  foreach ($row as $j => $cell)
286  {
287  $data[$i][$j] =
289  $this->content_obj->getLanguage());
290  }
291  }
292  }
293  }
294 
295  $this->updated = $this->content_obj->setData($data);
296 
297  if ($this->updated !== true)
298  {
299  $ilBench->stop("Editor","Data_Table_update");
300  $this->editData();
301  return;
302  }
303 
304  $this->updated = $this->pg_obj->update();
305  $ilBench->stop("Editor","Data_Table_update");
306 
307  if ($a_redirect)
308  {
309  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
310  $this->ctrl->redirect($this, "editData");
311  }
312  }
313 
317  function updateJS()
318  {
319  global $ilBench, $lng, $ilCtrl;
320 
321  if ($_POST["cancel_update"])
322  {
323 // $this->ctrl->redirect($this, "editData");
324  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
325  }
326 
327  // handle input data
328  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
329  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
330  $data = array();
331  foreach ($_POST as $k => $content)
332  {
333  if (substr($k, 0, 5) != "cell_")
334  {
335  continue;
336  }
337 
338  // determine cell content
339  $div = ilUtil::stripSlashes($content, false);
340  $p1 = strpos($div, '>');
341  $div = substr($div, $p1 + 1);
342  $div = "<div class='ilc_text_block_TableContent'>".$div;
343  $text = ilPCParagraph::handleAjaxContent($div);
344  if ($text === false)
345  {
346  $ilCtrl->returnToParent($this, "jump".$this->hier_id);
347  }
348  $text = $text["text"];
349 
350  $text = ilPCParagraph::_input2xml($text,
351  $this->content_obj->getLanguage(), true, false);
353 
354  // set content in data array
355  $id = explode("_", $k);
356  $data[(int) $id[1]][(int) $id[2]] = $text;
357  }
358 
359  // update data
360  $this->updated = $this->content_obj->setData($data);
361 
362  if ($this->updated !== true)
363  {
364  $this->editData();
365  return;
366  }
367 
368  $this->updated = $this->pg_obj->update();
369 
370 
371  // perform table action? (move...?)
372  //$this->update(false);
373  $this->pg_obj->addHierIDs();
374 
375  if ($_POST["tab_cmd"] != "")
376  {
377  $cell_hier_id = ($_POST["tab_cmd_type"] == "col")
378  ? $this->hier_id."_1_".($_POST["tab_cmd_id"] + 1)
379  : $this->hier_id."_".($_POST["tab_cmd_id"] + 1)."_1";
380  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
381  if (is_object($cell_obj))
382  {
383  $cell_obj->$_POST["tab_cmd"]();
384  $_SESSION["il_pg_error"] = $this->pg_obj->update();
385  }
386  }
387 
388  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
389  if ($_POST["save_return"])
390  {
391  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
392  }
393  else
394  {
395  $this->ctrl->redirect($this, "editData");
396  }
397  }
398 
399 
403  function getNewTableObject()
404  {
405  return new ilPCDataTable($this->dom);
406  }
407 
411  function afterCreation()
412  {
413  global $ilCtrl;
414 
415  $this->pg_obj->stripHierIDs();
416  $this->pg_obj->addHierIDs();
417  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
418  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
419  $this->content_obj->setHierId($this->content_obj->readHierId());
420  $this->setHierId($this->content_obj->readHierId());
421  $this->content_obj->setPCId($this->content_obj->readPCId());
422  $this->editData();
423  }
424 
428  function tableAction()
429  {
430  global $ilCtrl;
431 
432  $this->update(false);
433  $this->pg_obj->addHierIDs();
434 
435  $cell_hier_id = ($_POST["type"] == "col")
436  ? $this->hier_id."_1_".($_POST["id"] + 1)
437  : $this->hier_id."_".($_POST["id"] + 1)."_1";
438  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
439  if (is_object($cell_obj))
440  {
441  $cell_obj->$_POST["action"]();
442  $_SESSION["il_pg_error"] = $this->pg_obj->update();
443  }
444  $ilCtrl->redirect($this, "editData");
445  }
446 
450  function setTabs()
451  {
452  global $ilCtrl, $ilTabs;
453 
454  parent::setTabs();
455 
456  $ilTabs->addTarget("cont_ed_edit_data",
457  $ilCtrl->getLinkTarget($this, "editData"), "editData",
458  get_class($this));
459 
460  }
461 
462 
466 
470  function editData()
471  {
472  global $lng, $ilCtrl;
473 
475  {
476  return $this->editDataCl();
477  }
478 
479 //var_dump($_GET);
480 //var_dump($_POST);
481 
482  $this->setTabs();
483 
484  $this->displayValidationError();
485 
486  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
487 
488  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata2.html", "Services/COPage");
489  $dtpl = $this->tpl;
490  //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage");
491  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
492 // $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0"));
493 
494 // $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
495 // $this->tpl->addJavascript("./Services/COPage/js/page_editing.js");
496 
497 
498  $this->tpl->setVariable("WYSIWYG_ACTION",
499  $ilCtrl->getFormAction($this, "updateJS"));
500 
501 
502  // get all rows
503  $xpc = xpath_new_context($this->dom);
504  $path = "//PageContent[@HierId='".$this->getHierId()."']".
505  "/Table/TableRow";
506  $res =& xpath_eval($xpc, $path);
507 
508  for($i = 0; $i < count($res->nodeset); $i++)
509  {
510 
511  $xpc2 = xpath_new_context($this->dom);
512  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
513  "/Table/TableRow[$i+1]/TableData";
514  $res2 =& xpath_eval($xpc2, $path2);
515 
516  // if this is the first row -> col icons
517  if ($i == 0)
518  {
519  for($j = 0; $j < count($res2->nodeset); $j++)
520  {
521  if ($j == 0)
522  {
523  $dtpl->touchBlock("empty_td");
524  }
525 
526  if ($j == 0)
527  {
528  if (count($res2->nodeset) == 1)
529  {
530  $move_type = "none";
531  }
532  else
533  {
534  $move_type = "forward";
535  }
536  }
537  else if ($j == (count($res2->nodeset) - 1))
538  {
539  $move_type = "backward";
540  }
541  else
542  {
543  $move_type = "both";
544  }
545  $dtpl->setCurrentBlock("col_icon");
546  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
547  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.png"));
548  $dtpl->setVariable("COL_ONCLICK", "COL_".$move_type);
549  $dtpl->setVariable("NR", $j);
550  $dtpl->parseCurrentBlock();
551  }
552  $dtpl->setCurrentBlock("row");
553  $dtpl->parseCurrentBlock();
554  }
555 
556 
557  for($j = 0; $j < count($res2->nodeset); $j++)
558  {
559  // first col: row icons
560  if ($j == 0)
561  {
562  if ($i == 0)
563  {
564  if (count($res->nodeset) == 1)
565  {
566  $move_type = "none";
567  }
568  else
569  {
570  $move_type = "forward";
571  }
572  }
573  else if ($i == (count($res->nodeset) - 1))
574  {
575  $move_type = "backward";
576  }
577  else
578  {
579  $move_type = "both";
580  }
581  $dtpl->setCurrentBlock("row_icon");
582  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
583  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.png"));
584  $dtpl->setVariable("ROW_ONCLICK", "ROW_".$move_type);
585  $dtpl->setVariable("NR", $i);
586  $dtpl->parseCurrentBlock();
587  }
588 
589  // cell
590  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y")
591  {
592  $dtpl->setCurrentBlock("cell");
593 
594  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update")
595  {
596  $s_text = ilUtil::stripSlashes("cell_".$i."_".$j, false);
597  }
598  else
599  {
600  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j),
601  true, false);
602  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
603  $s_text = ilPCParagraphGUI::xml2outputJS($s_text, "TableContent",
604  $this->content_obj->readPCId()."_".$i."_".$j);
605  }
606 
607  $dtpl->setVariable("PAR_TA_NAME", "cell[".$i."][".$j."]");
608  $dtpl->setVariable("PAR_TA_ID", "cell_".$i."_".$j);
609  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
610 
611  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
612  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
613  $dtpl->setVariable("WIDTH", "140");
614  $dtpl->setVariable("HEIGHT", "80");
615  if ($cs > 1)
616  {
617  $dtpl->setVariable("COLSPAN", 'colspan="'.$cs.'"');
618  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
619  }
620  if ($rs > 1)
621  {
622  $dtpl->setVariable("ROWSPAN", 'rowspan="'.$rs.'"');
623  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
624  }
625  $dtpl->parseCurrentBlock();
626  }
627  }
628  $dtpl->setCurrentBlock("row");
629  $dtpl->parseCurrentBlock();
630  }
631 
632  // init menues
633  $types = array("row", "col");
634  $moves = array("none", "backward", "both", "forward");
635  $commands = array(
636  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
637  "newRowBefore" => "cont_ed_new_row_before",
638  "moveRowUp" => "cont_ed_row_up",
639  "moveRowDown" => "cont_ed_row_down",
640  "deleteRow" => "cont_ed_delete_row"),
641  "col" => array( "newColAfter" => "cont_ed_new_col_after",
642  "newColBefore" => "cont_ed_new_col_before",
643  "moveColLeft" => "cont_ed_col_left",
644  "moveColRight" => "cont_ed_col_right",
645  "deleteCol" => "cont_ed_delete_col")
646  );
647 
648  foreach($types as $type)
649  {
650  foreach($moves as $move)
651  {
652  foreach($commands[$type] as $command => $lang_var)
653  {
654  if ($move == "none" && (substr($command, 0, 4) == "move"))
655  {
656  continue;
657  }
658  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
659  ($move == "forward" && (in_array($command, array("moveup", "moveleft")))))
660  {
661  continue;
662  }
663  $this->tpl->setCurrentBlock("menu_item");
664  $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
665  $this->tpl->setVariable("CMD", $command);
666  $this->tpl->setVariable("TYPE", $type);
667  $this->tpl->parseCurrentBlock();
668  }
669  $this->tpl->setCurrentBlock("menu");
670  $this->tpl->setVariable("TYPE", $type);
671  $this->tpl->setVariable("MOVE", $move);
672  $this->tpl->parseCurrentBlock();
673  }
674  }
675 
676 
677  $this->tpl->setVariable("FORMACTION2",
678  $ilCtrl->getFormAction($this, "tableAction"));
679  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
680 
681  // js editing preparation
682  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
685  ilYuiUtil::initPanel(false);
686  $GLOBALS["tpl"]->addJavascript("Services/RTE/tiny_mce_3_3_9_2/il_tiny_mce_src.js");
687  $GLOBALS["tpl"]->addJavaScript("./Services/COPage/js/ilcopagecallback.js");
688  $GLOBALS["tpl"]->addJavascript("Services/COPage/js/page_editing.js");
689 
690  $GLOBALS["tpl"]->addOnloadCode("var preloader = new Image();
691  preloader.src = './templates/default/images/loader.gif';
692  ilCOPage.setContentCss('".
694  ", ".ilUtil::getStyleSheetLocation().", ./Services/COPage/css/tiny_extra.css');
695  ilCOPage.editTD('cell_0_0');
696  ");
697 
698 
699  $this->tpl->setVariable("IL_TINY_MENU",
701  $this->pg_obj->getParentType(),
702  false,
703  $this->pg_obj->getParentType() == "wpg",
704  false,
705  $this->getStyleId(),
706  false, true));
707 
708 
709  }
710 
711 
712 }
713 ?>