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