ILIAS  Release_4_0_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  function editData()
59  {
60  global $lng, $ilCtrl;
61 //var_dump($_GET);
62 //var_dump($_POST);
63 
64  $this->setTabs();
65 
66  $this->displayValidationError();
67 
68  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
69 
70  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata.html", "Services/COPage");
71  $dtpl = $this->tpl;
72  //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage");
73  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
74  $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0"));
75 
76  $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js");
77  $this->tpl->addJavascript("./Services/COPage/js/page_editing.js");
78 
79  // get all rows
80  $xpc = xpath_new_context($this->dom);
81  $path = "//PageContent[@HierId='".$this->getHierId()."']".
82  "/Table/TableRow";
83  $res =& xpath_eval($xpc, $path);
84 
85  for($i = 0; $i < count($res->nodeset); $i++)
86  {
87 
88  $xpc2 = xpath_new_context($this->dom);
89  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
90  "/Table/TableRow[$i+1]/TableData";
91  $res2 =& xpath_eval($xpc2, $path2);
92 
93  // if this is the first row -> col icons
94  if ($i == 0)
95  {
96  for($j = 0; $j < count($res2->nodeset); $j++)
97  {
98  if ($j == 0)
99  {
100  $dtpl->touchBlock("empty_td");
101  }
102 
103  if ($j == 0)
104  {
105  if (count($res2->nodeset) == 1)
106  {
107  $move_type = "none";
108  }
109  else
110  {
111  $move_type = "forward";
112  }
113  }
114  else if ($j == (count($res2->nodeset) - 1))
115  {
116  $move_type = "backward";
117  }
118  else
119  {
120  $move_type = "both";
121  }
122  $dtpl->setCurrentBlock("col_icon");
123  $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column"));
124  $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.gif"));
125  $dtpl->setVariable("COL_ONCLICK", "COL_".$move_type);
126  $dtpl->setVariable("NR", $j);
127  $dtpl->parseCurrentBlock();
128  }
129  $dtpl->setCurrentBlock("row");
130  $dtpl->parseCurrentBlock();
131  }
132 
133 
134  for($j = 0; $j < count($res2->nodeset); $j++)
135  {
136  // first col: row icons
137  if ($j == 0)
138  {
139  if ($i == 0)
140  {
141  if (count($res->nodeset) == 1)
142  {
143  $move_type = "none";
144  }
145  else
146  {
147  $move_type = "forward";
148  }
149  }
150  else if ($i == (count($res->nodeset) - 1))
151  {
152  $move_type = "backward";
153  }
154  else
155  {
156  $move_type = "both";
157  }
158  $dtpl->setCurrentBlock("row_icon");
159  $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row"));
160  $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.gif"));
161  $dtpl->setVariable("ROW_ONCLICK", "ROW_".$move_type);
162  $dtpl->setVariable("NR", $i);
163  $dtpl->parseCurrentBlock();
164  }
165 
166  // cell
167  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y")
168  {
169  $dtpl->setCurrentBlock("cell");
170 
171  if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update")
172  {
173  $s_text = ilUtil::stripSlashes("cell_".$i."_".$j, false);
174  }
175  else
176  {
177  $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j));
178  }
179 
180  $dtpl->setVariable("PAR_TA_NAME", "cell[".$i."][".$j."]");
181  $dtpl->setVariable("PAR_TA_ID", "cell_".$i."_".$j);
182  $dtpl->setVariable("PAR_TA_CONTENT", $s_text);
183 
184  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
185  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
186  $dtpl->setVariable("WIDTH", "140");
187  $dtpl->setVariable("HEIGHT", "80");
188  if ($cs > 1)
189  {
190  $dtpl->setVariable("COLSPAN", 'colspan="'.$cs.'"');
191  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
192  }
193  if ($rs > 1)
194  {
195  $dtpl->setVariable("ROWSPAN", 'rowspan="'.$rs.'"');
196  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
197  }
198  $dtpl->parseCurrentBlock();
199  }
200  }
201  $dtpl->setCurrentBlock("row");
202  $dtpl->parseCurrentBlock();
203  }
204 
205  // init menues
206  $types = array("row", "col");
207  $moves = array("none", "backward", "both", "forward");
208  $commands = array(
209  "row" => array( "newRowAfter" => "cont_ed_new_row_after",
210  "newRowBefore" => "cont_ed_new_row_before",
211  "moveRowUp" => "cont_ed_row_up",
212  "moveRowDown" => "cont_ed_row_down",
213  "deleteRow" => "cont_ed_delete_row"),
214  "col" => array( "newColAfter" => "cont_ed_new_col_after",
215  "newColBefore" => "cont_ed_new_col_before",
216  "moveColLeft" => "cont_ed_col_left",
217  "moveColRight" => "cont_ed_col_right",
218  "deleteCol" => "cont_ed_delete_col")
219  );
220 
221  foreach($types as $type)
222  {
223  foreach($moves as $move)
224  {
225  foreach($commands[$type] as $command => $lang_var)
226  {
227  if ($move == "none" && (substr($command, 0, 4) == "move"))
228  {
229  continue;
230  }
231  if (($move == "backward" && (in_array($command, array("movedown", "moveright")))) ||
232  ($move == "forward" && (in_array($command, array("moveup", "moveleft")))))
233  {
234  continue;
235  }
236  $this->tpl->setCurrentBlock("menu_item");
237  $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var));
238  $this->tpl->setVariable("CMD", $command);
239  $this->tpl->setVariable("TYPE", $type);
240  $this->tpl->parseCurrentBlock();
241  }
242  $this->tpl->setCurrentBlock("menu");
243  $this->tpl->setVariable("TYPE", $type);
244  $this->tpl->setVariable("MOVE", $move);
245  $this->tpl->parseCurrentBlock();
246  }
247  }
248 
249  // update/cancel
250  $this->tpl->setCurrentBlock("commands");
251  $this->tpl->setVariable("BTN_NAME", "update");
252  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
253  $this->tpl->parseCurrentBlock();
254 
255  $this->tpl->setVariable("FORMACTION2",
256  $ilCtrl->getFormAction($this, "tableAction"));
257  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
258 
259  }
260 
264  function update($a_redirect = true)
265  {
266  global $ilBench, $lng;
267 
268  $ilBench->start("Editor","Data_Table_update");
269 
270  // handle input data
271  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
272  $data = array();
273 //var_dump($_POST);
274 //var_dump($_GET);
275  if (is_array($_POST["cell"]))
276  {
277  foreach ($_POST["cell"] as $i => $row)
278  {
279  if (is_array($row))
280  {
281  foreach ($row as $j => $cell)
282  {
283  $data[$i][$j] =
285  $this->content_obj->getLanguage());
286  }
287  }
288  }
289  }
290 
291  $this->updated = $this->content_obj->setData($data);
292 
293  if ($this->updated !== true)
294  {
295  $ilBench->stop("Editor","Data_Table_update");
296  $this->editData();
297  return;
298  }
299 
300  $this->updated = $this->pg_obj->update();
301  $ilBench->stop("Editor","Data_Table_update");
302 
303  if ($a_redirect)
304  {
305  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
306  $this->ctrl->redirect($this, "editData");
307  }
308  }
309 
313  function getNewTableObject()
314  {
315  return new ilPCDataTable($this->dom);
316  }
317 
321  function afterCreation()
322  {
323  global $ilCtrl;
324 
325  $this->pg_obj->stripHierIDs();
326  $this->pg_obj->addHierIDs();
327  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
328  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
329  $this->content_obj->setHierId($this->content_obj->readHierId());
330  $this->setHierId($this->content_obj->readHierId());
331  $this->content_obj->setPCId($this->content_obj->readPCId());
332  $this->editData();
333  }
334 
338  function tableAction()
339  {
340  global $ilCtrl;
341 
342  $this->update(false);
343  $this->pg_obj->addHierIDs();
344 
345  $cell_hier_id = ($_POST["type"] == "col")
346  ? $this->hier_id."_1_".($_POST["id"] + 1)
347  : $this->hier_id."_".($_POST["id"] + 1)."_1";
348  $cell_obj = $this->pg_obj->getContentObject($cell_hier_id);
349  if (is_object($cell_obj))
350  {
351  $cell_obj->$_POST["action"]();
352  $_SESSION["il_pg_error"] = $this->pg_obj->update();
353  }
354  $ilCtrl->redirect($this, "editData");
355  }
356 
360  function setTabs()
361  {
362  global $ilCtrl, $ilTabs;
363 
364  parent::setTabs();
365 
366  $ilTabs->addTarget("cont_ed_edit_data",
367  $ilCtrl->getLinkTarget($this, "editData"), "editData",
368  get_class($this));
369 
370  }
371 
372 }
373 ?>