ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilColumnGUI.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 define ("IL_COL_LEFT", "left");
5 define ("IL_COL_RIGHT", "right");
6 define ("IL_COL_CENTER", "center");
7 
8 define ("IL_SCREEN_SIDE", "");
9 define ("IL_SCREEN_CENTER", "center");
10 define ("IL_SCREEN_FULL", "full");
11 
23 {
24  protected $side = IL_COL_RIGHT;
25  protected $type;
26  protected $enableedit = false;
27  protected $repositorymode = false;
28  protected $repositoryitems = array();
29 
30  // all blocks that are repository objects
31  protected $rep_block_types = array("feed");
32  protected $block_property = array();
33  protected $admincommands = null;
34  protected $movementmode = null;
35  protected $enablemovement = false;
36 
37  //
38  // This two arrays may be replaced by some
39  // xml or other magic in the future...
40  //
41 
42  static protected $locations = array(
43  "ilNewsForContextBlockGUI" => "Services/News/",
44  "ilCalendarBlockGUI" => "Services/Calendar/",
45  "ilPDCalendarBlockGUI" => "Services/Calendar/",
46  "ilPDNotesBlockGUI" => "Services/Notes/",
47  "ilPDMailBlockGUI" => "Services/Mail/",
48  "ilUsersOnlineBlockGUI" => "Services/PersonalDesktop/",
49  "ilPDSysMessageBlockGUI" => "Services/Mail/",
50  "ilPDSelectedItemsBlockGUI" => "Services/PersonalDesktop/",
51  "ilBookmarkBlockGUI" => "Services/PersonalDesktop/",
52  "ilPDNewsBlockGUI" => "Services/News/",
53  "ilExternalFeedBlockGUI" => "Services/Block/",
54  "ilPDExternalFeedBlockGUI" => "Services/Feeds/",
55  "ilHtmlBlockGUI" => "Services/Block/",
56  "ilPDFeedbackBlockGUI" => "Services/Feedback/",
57  'ilPDTaggingBlockGUI' => 'Services/Tagging/',
58  'ilChatBlockGUI' => 'Modules/Chat/'
59  );
60 
61  static protected $block_types = array(
62  "ilPDMailBlockGUI" => "pdmail",
63  "ilPDNotesBlockGUI" => "pdnotes",
64  "ilUsersOnlineBlockGUI" => "pdusers",
65  "ilPDNewsBlockGUI" => "pdnews",
66  "ilBookmarkBlockGUI" => "pdbookm",
67  "ilNewsForContextBlockGUI" => "news",
68  "ilCalendarBlockGUI" => "cal",
69  "ilPDCalendarBlockGUI" => "pdcal",
70  "ilExternalFeedBlockGUI" => "feed",
71  "ilPDExternalFeedBlockGUI" => "pdfeed",
72  "ilPDFeedbackBlockGUI" => "pdfeedb",
73  "ilPDSysMessageBlockGUI" => "pdsysmess",
74  "ilPDSelectedItemsBlockGUI" => "pditems",
75  "ilHtmlBlockGUI" => "html",
76  'ilPDTaggingBlockGUI' => 'pdtag',
77  'ilChatBlockGUI' => 'chatviewer'
78  );
79 
80 
81  protected $default_blocks = array(
82  "cat" => array("ilNewsForContextBlockGUI" => IL_COL_RIGHT),
83  "crs" => array(
84  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
85  "ilCalendarBlockGUI" => IL_COL_RIGHT
86  ),
87  "grp" => array(
88  "ilNewsForContextBlockGUI" => IL_COL_RIGHT,
89  "ilCalendarBlockGUI" => IL_COL_RIGHT),
90  "frm" => array("ilNewsForContextBlockGUI" => IL_COL_RIGHT),
91  "root" => array(),
92  "info" => array(
93  "ilNewsForContextBlockGUI" => IL_COL_RIGHT),
94  "pd" => array(
95  "ilPDCalendarBlockGUI" => IL_COL_RIGHT,
96  "ilPDSysMessageBlockGUI" => IL_COL_LEFT,
97  "ilPDFeedbackBlockGUI" => IL_COL_LEFT,
98  "ilPDNewsBlockGUI" => IL_COL_LEFT,
99  "ilPDSelectedItemsBlockGUI" => IL_COL_CENTER,
100  "ilPDMailBlockGUI" => IL_COL_RIGHT,
101  "ilPDNotesBlockGUI" => IL_COL_RIGHT,
102  "ilUsersOnlineBlockGUI" => IL_COL_RIGHT,
103  "ilBookmarkBlockGUI" => IL_COL_RIGHT,
104  "ilPDTaggingBlockGUI" => IL_COL_RIGHT,
105  "ilChatBlockGUI" => IL_COL_RIGHT,
106  )
107  );
108 
109  // these are only for pd blocks
110  // other blocks are rep objects now
111  protected $custom_blocks = array(
112  "cat" => array(),
113  "crs" => array(),
114  "grp" => array(),
115  "frm" => array(),
116  "root" => array(),
117  "info" => array(),
118  "pd" => array("ilPDExternalFeedBlockGUI")
119  );
120 
121  // check global activation for these block types
122  // @todo: add calendar
124  array("news" => true,
125  "cal" => true,
126  "pdcal" => true,
127  "pdnews" => true,
128  "pdfeed" => true,
129  "pdusers" => true,
130  "pdbookm" => true,
131  "pdtag" => true,
132  "pdnotes" => true,
133  "chatviewer" => true);
134 
135  protected $check_nr_limit =
136  array("pdfeed" => true);
137 
143  function ilColumnGUI($a_col_type = "", $a_side = "", $use_std_context = false)
144  {
145  global $ilUser, $tpl, $ilCtrl;
146 
147  $this->setColType($a_col_type);
148  //if ($a_side == "")
149  //{
150  // $a_side = $_GET["col_side"];
151  //}
152 
153  if (isset($_SESSION["col_".$this->getColType()."_movement"]) &&
154  $_SESSION["col_".$this->getColType()."_movement"] == "on")
155  {
156  $this->setMovementMode(true);
157  }
158 
159  $this->setSide($a_side);
160  }
161 
167  static function getCmdSide()
168  {
169  return $_GET["col_side"];
170  }
171 
177  function setColType($a_coltype)
178  {
179  $this->coltype = $a_coltype;
180  }
181 
187  function getColType()
188  {
189  return $this->coltype;
190  }
191 
197  function setSide($a_side)
198  {
199  $this->side = $a_side;
200  }
201 
207  function getSide()
208  {
209  return $this->side;
210  }
211 
217  function setEnableEdit($a_enableedit)
218  {
219  $this->enableedit = $a_enableedit;
220  }
221 
227  function getEnableEdit()
228  {
229  return $this->enableedit;
230  }
231 
237  function setRepositoryMode($a_repositorymode)
238  {
239  $this->repositorymode = $a_repositorymode;
240  }
241 
247  function getRepositoryMode()
248  {
249  return $this->repositorymode;
250  }
251 
257  function setAdminCommands($a_admincommands)
258  {
259  $this->admincommands = $a_admincommands;
260  }
261 
267  function getAdminCommands()
268  {
269  return $this->admincommands;
270  }
271 
277  function setMovementMode($a_movementmode)
278  {
279  $this->movementmode = $a_movementmode;
280  }
281 
287  function getMovementMode()
288  {
289  return $this->movementmode;
290  }
291 
297  function setEnableMovement($a_enablemovement)
298  {
299  $this->enablemovement = $a_enablemovement;
300  }
301 
307  function getEnableMovement()
308  {
309  return $this->enablemovement;
310  }
311 
315  static function getScreenMode()
316  {
317  global $ilCtrl;
318 
319  if ($ilCtrl->getCmdClass() == "ilcolumngui")
320  {
321  switch ($ilCtrl->getCmd())
322  {
323  case "addBlock":
324  return IL_SCREEN_CENTER;
325  }
326  }
327 
328  $cur_block_type = "";
329  if (isset($_GET["block_type"]) && $_GET["block_type"])
330  {
331  $cur_block_type = $_GET["block_type"];
332  }
333  else if (isset($_POST["block_type"]))
334  {
335  $cur_block_type = $_POST["block_type"];
336  }
337 
338  if ($class = array_search($cur_block_type, self::$block_types))
339  {
340  include_once("./".self::$locations[$class]."classes/".
341  "class.".$class.".php");
342  return call_user_func(array($class, 'getScreenMode'));
343  }
344 
345  return IL_SCREEN_SIDE;
346  }
347 
355  function setBlockProperty($a_block_type, $a_property, $a_value)
356  {
357  $this->block_property[$a_block_type][$a_property] = $a_value;
358  }
359 
360  function getBlockProperties($a_block_type)
361  {
362  return $this->block_property[$a_block_type];
363  }
364 
365  function setAllBlockProperties($a_block_properties)
366  {
367  $this->block_property = $a_block_properties;
368  }
369 
375  function setRepositoryItems($a_repositoryitems)
376  {
377  $this->repositoryitems = $a_repositoryitems;
378  }
379 
386  {
387  return $this->repositoryitems;
388  }
389 
393  function &executeCommand()
394  {
395  global $ilCtrl;
396 
397  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
398  //$ilCtrl->saveParameter($this, "col_side");
399 
400  $next_class = $ilCtrl->getNextClass();
401  $cmd = $ilCtrl->getCmd("getHTML");
402 
403  $cur_block_type = ($_GET["block_type"])
404  ? $_GET["block_type"]
405  : $_POST["block_type"];
406 
407  if ($next_class != "")
408  {
409  // forward to block
410  if ($gui_class = array_search($cur_block_type, self::$block_types))
411  {
412  include_once("./".self::$locations[$gui_class]."classes/".
413  "class.".$gui_class.".php");
414  $ilCtrl->setParameter($this, "block_type", $cur_block_type);
415  $block_gui = new $gui_class();
416  $block_gui->setProperties($this->block_property[$cur_block_type]);
417  $block_gui->setRepositoryMode($this->getRepositoryMode());
418  $block_gui->setEnableEdit($this->getEnableEdit());
419  $block_gui->setAdminCommands($this->getAdminCommands());
420  $block_gui->setConfigMode($this->getMovementMode());
421 
422  if (in_array($gui_class, $this->custom_blocks[$this->getColType()]) ||
423  in_array($cur_block_type, $this->rep_block_types))
424  {
425  $block_class = substr($gui_class, 0, strlen($gui_class)-3);
426  include_once("./".self::$locations[$gui_class]."classes/".
427  "class.".$block_class.".php");
428  $app_block = new $block_class($_GET["block_id"]);
429  $block_gui->setBlock($app_block);
430  }
431  $html = $ilCtrl->forwardCommand($block_gui);
432  $ilCtrl->setParameter($this, "block_type", "");
433 
434  return $html;
435  }
436  }
437  else
438  {
439  return $this->$cmd();
440  }
441  }
442 
446  function getHTML()
447  {
448  global $ilCtrl, $ilBench;
449 
450  $ilBench->start("Column", "getHTML");
451 
452  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
453 
454  $this->tpl = new ilTemplate("tpl.column.html", true, true, "Services/Block");
455 
456  $ilBench->start("Column", "determineBlocks");
457  $this->determineBlocks();
458  $ilBench->stop("Column", "determineBlocks");
459 
460  $ilBench->start("Column", "showBlocks");
461  $this->showBlocks();
462  $ilBench->stop("Column", "showBlocks");
463 
464  if ($this->getEnableEdit() || !$this->getRepositoryMode())
465  {
466  $this->addHiddenBlockSelector();
467  }
468 
469  $ilBench->stop("Column", "getHTML");
470 
471  return $this->tpl->get();
472  }
473 
477  function showBlocks()
478  {
479  global $ilCtrl, $lng, $ilUser, $ilBench;
480 
481  $blocks = array();
482 
483  $i = 1;
484  $sum_moveable = count($this->blocks[$this->getSide()]);
485 
486  foreach($this->blocks[$this->getSide()] as $block)
487  {
488  if ($ilCtrl->getContextObjType() != "user" ||
489  ilBlockSetting::_lookupDetailLevel($block["type"],
490  $ilUser->getId(), $block["id"]) > 0)
491  {
492  $gui_class = $block["class"];
493  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
494 
495  // get block gui class
496  include_once("./".self::$locations[$gui_class]."classes/".
497  "class.".$gui_class.".php");
498  $ilBench->start("Column", "instantiate-".$block["type"]);
499  $block_gui = new $gui_class();
500  $ilBench->stop("Column", "instantiate-".$block["type"]);
501  if (isset($this->block_property[$block["type"]]))
502  {
503  $block_gui->setProperties($this->block_property[$block["type"]]);
504  }
505  $block_gui->setRepositoryMode($this->getRepositoryMode());
506  $block_gui->setEnableEdit($this->getEnableEdit());
507  $block_gui->setAdminCommands($this->getAdminCommands());
508  $block_gui->setConfigMode($this->getMovementMode());
509  $this->setPossibleMoves($block_gui, $i, $sum_moveable);
510 
511  // get block for custom blocks
512  if ($block["custom"])
513  {
514  include_once("./".self::$locations[$gui_class]."classes/".
515  "class.".$block_class.".php");
516  $app_block = new $block_class($block["id"]);
517  $block_gui->setBlock($app_block);
518  if (isset($block["ref_id"]))
519  {
520  $block_gui->setRefId($block["ref_id"]);
521  }
522  }
523 
524  $ilCtrl->setParameter($this, "block_type", $block_gui->getBlockType());
525  $this->tpl->setCurrentBlock("col_block");
526 
527  $ilBench->start("Column", "showBlocks-".$block_gui->getBlockType());
528  $html = $ilCtrl->getHTML($block_gui);
529  $ilBench->stop("Column", "showBlocks-".$block_gui->getBlockType());
530 
531  // dummy block, if non visible, but movement is ongoing
532  if ($html == "" && $this->getRepositoryMode() &&
533  $this->getMovementMode())
534  {
535  include_once("./Services/Block/classes/class.ilDummyBlockGUI.php");
536  $bl = new ilDummyBlockGUI();
537  $bl->setBlockId($block["id"]);
538  $bl->setBlockType($block["type"]);
539  $bl->setTitle($lng->txt("invisible_block"));
540  $this->setPossibleMoves($bl, $i, $sum_moveable);
541  $bl->setConfigMode($this->getMovementMode());
542  $html = $bl->getHTML();
543  }
544 
545  // don't render a block if it's empty
546  if ($html != "")
547  {
548  $this->tpl->setVariable("BLOCK", $html);
549  $this->tpl->parseCurrentBlock();
550  $ilCtrl->setParameter($this, "block_type", "");
551  }
552 
553  // count (moveable) blocks
554  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb" &&
555  $block["type"] != "news")
556  {
557  $i++;
558  }
559  else
560  {
561  $sum_moveable--;
562  }
563  }
564  }
565  }
566 
567  function setPossibleMoves($a_block_gui, $i, $sum_moveable)
568  {
569  if ($this->getSide() == IL_COL_LEFT)
570  {
571  $a_block_gui->setAllowMove("right");
572  }
573  else if ($this->getSide() == IL_COL_RIGHT && !$this->getRepositoryMode())
574  {
575  $a_block_gui->setAllowMove("left");
576  }
577  if ($i > 1)
578  {
579  $a_block_gui->setAllowMove("up");
580  }
581  if ($i < $sum_moveable)
582  {
583  $a_block_gui->setAllowMove("down");
584  }
585  }
586 
591  {
592  global $lng, $ilUser, $ilCtrl, $ilSetting;
593 
594  $bl_management = false;
595 
596  // show selector for hidden blocks
597  include_once("Services/Block/classes/class.ilBlockSetting.php");
598  $hidden_blocks = array();
599  $blocks = array("pdmail" => $lng->txt("mail"),
600  "pdnotes" => $lng->txt("notes"),
601  "pdusers" => $lng->txt("users_online"),
602  "pdnews" => $lng->txt("news"),
603  "pdbookm" => $lng->txt("my_bms"),
604  "news" => $lng->txt("news_internal_news"),
605  "feed" => $lng->txt("feed"),
606  "pdfeed" => $lng->txt("feed"),
607  "html" => $lng->txt("html_block"),
608  "pdtag" => $lng->txt("tagging_my_tags"),
609  "pdcal" => $lng->txt('calendar'),
610  "chatviewer" => $lng->txt('chat'),
611  );
612 
613  foreach($this->blocks[$this->getSide()] as $block)
614  {
615  include_once("./".self::$locations[$block["class"]]."classes/".
616  "class.".$block["class"].".php");
617 
618  if ($block["custom"] == false)
619  {
620  if ($ilCtrl->getContextObjType() == "user") // personal desktop
621  {
622  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId()) == 0)
623  {
624  $hidden_blocks[$block["type"]] = $blocks[$block["type"]];
625  }
626  }
627  else if ($ilCtrl->getContextObjType() != "")
628  {
629  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
630  $ilCtrl->getContextObjId()) == 0)
631  {
632  $hidden_blocks[$block["type"]."_".$ilCtrl->getContextObjId()] = $blocks[$block["type"]];
633  }
634  }
635  }
636  else
637  {
638  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
639  $block["id"]) == 0)
640  {
641  include_once("./Services/Block/classes/class.ilCustomBlock.php");
642  $cblock = new ilCustomBlock($block["id"]);
643  $hidden_blocks[$block["type"]."_".$block["id"]] =
644  $cblock->getTitle();
645  }
646  }
647  }
648  if (count($hidden_blocks) > 0)
649  {
650  $this->tpl->setCurrentBlock("hidden_block_selector");
651  $this->tpl->setVariable("HB_ACTION", $ilCtrl->getFormAction($this));
652  $this->tpl->setVariable("BLOCK_SEL", ilUtil::formSelect("", "block", $hidden_blocks,
653  false, true, 0, "ilEditSelect", array("id" => "il_show_bl_sel_".$this->getSide())));
654  $this->tpl->setVariable("LAB_ID", "il_show_bl_sel_".$this->getSide());
655  $this->tpl->setVariable("TXT_ACTIVATE", $lng->txt("show"));
656  $this->tpl->setVariable("TXT_SHOW_HIDDEN_BLOCK",
657  $lng->txt("show_hidden_block"));
658  $this->tpl->parseCurrentBlock();
659  $bl_management = true;
660  }
661 
662  // create block selection list
663  if (!$this->getRepositoryMode() || $this->getEnableEdit())
664  {
665  $add_blocks = array();
666  if ($this->getSide() == IL_COL_RIGHT)
667  {
668  if (is_array($this->custom_blocks[$this->getColType()]))
669  {
670  foreach($this->custom_blocks[$this->getColType()] as $block_class)
671  {
672  include_once("./".self::$locations[$block_class]."classes/".
673  "class.".$block_class.".php");
674  $block_type = call_user_func(array($block_class, 'getBlockType'));
675 
676  // check if block type is globally (de-)activated
677  if ($this->isGloballyActivated($block_type))
678  {
679  // check if number of blocks is limited
680  if (!$this->exceededLimit($block_type))
681  {
682  $add_blocks[$block_type] = $blocks[$block_type];
683  }
684  }
685  }
686  }
687  }
688  if (count($add_blocks) > 0)
689  {
690  $this->tpl->setCurrentBlock("add_block_selector");
691  $ilCtrl->setParameter($this, "block_type", "");
692  $this->tpl->setVariable("AB_ACTION", $ilCtrl->getFormAction($this));
693  $this->tpl->setVariable("ADD_BLOCK_SEL", ilUtil::formSelect("", "block_type", $add_blocks,
694  false, true, 0, "ilEditSelect", array("id" => "il_add_bl_sel_".$this->getSide())));
695  $this->tpl->setVariable("LAB_ID", "il_add_bl_sel_".$this->getSide());
696  $this->tpl->setVariable("TXT_ADD", $lng->txt("create"));
697  $this->tpl->setVariable("TXT_CREATE_BLOCK",
698  $lng->txt("create_block"));
699  $this->tpl->parseCurrentBlock();
700  $bl_management = true;
701  }
702  }
703 
704  if ($this->getSide() == IL_COL_RIGHT && $this->getEnableMovement())
705  {
706  $this->tpl->setCurrentBlock("toggle_movement");
707  $this->tpl->setVariable("HREF_TOGGLE_MOVEMENT",
708  $ilCtrl->getLinkTarget($this, "toggleMovement"));
709  if ($_SESSION["col_".$this->getColType()."_movement"] == "on")
710  {
711  $this->tpl->setVariable("TXT_TOGGLE_MOVEMENT",
712  $lng->txt("stop_moving_blocks"));
713  }
714  else
715  {
716  $this->tpl->setVariable("TXT_TOGGLE_MOVEMENT",
717  $lng->txt("move_blocks"));
718  }
719  $this->tpl->parseCurrentBlock();
720  $bl_management = true;
721  }
722 
723  if ($bl_management)
724  {
725  $this->tpl->setCurrentBlock("block_management");
726  $this->tpl->setVariable("TXT_BLOCK_MANAGEMENT",
727  $lng->txt("block_management"));
728  $this->tpl->parseCurrentBlock();
729  }
730 
731  //return $tpl->get();
732 
733  }
734 
735  function toggleMovement()
736  {
737  global $ilCtrl;
738 
739  if ($_SESSION["col_".$this->getColType()."_movement"] == "on")
740  {
741  $_SESSION["col_".$this->getColType()."_movement"] = "off";
742  }
743  else
744  {
745  $_SESSION["col_".$this->getColType()."_movement"] = "on";
746  }
747  $ilCtrl->returnToParent($this);
748  }
749 
753  function updateBlock()
754  {
755  global $ilCtrl, $ilBench;
756 
757  $this->determineBlocks();
758  $i = 1;
759  $sum_moveable = count($this->blocks[$this->getSide()]);
760 
761  foreach ($this->blocks[$this->getSide()] as $block)
762  {
763 
764  include_once("./".self::$locations[$block["class"]]."classes/".
765  "class.".$block["class"].".php");
766 
767  // set block id to context obj id,
768  // if block is not a custom block and context is not personal desktop
769  if (!$block["custom"] && $ilCtrl->getContextObjType() != "" && $ilCtrl->getContextObjType() != "user")
770  {
771  $block["id"] = $ilCtrl->getContextObjId();
772  }
773 
774  //if (is_int(strpos($_GET["block_id"], "block_".$block["type"]."_".$block["id"])))
775 
776  if ($_GET["block_id"] == "block_".$block["type"]."_".$block["id"])
777  {
778  $gui_class = $block["class"];
779  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
780 
781  $block_gui = new $gui_class();
782  $block_gui->setProperties($this->block_property[$block["type"]]);
783  $block_gui->setRepositoryMode($this->getRepositoryMode());
784  $block_gui->setEnableEdit($this->getEnableEdit());
785  $block_gui->setAdminCommands($this->getAdminCommands());
786  $block_gui->setConfigMode($this->getMovementMode());
787 
788  if ($this->getSide() == IL_COL_LEFT)
789  {
790  $block_gui->setAllowMove("right");
791  }
792  else if ($this->getSide() == IL_COL_RIGHT &&
793  !$this->getRepositoryMode())
794  {
795  $block_gui->setAllowMove("left");
796  }
797  if ($i > 1)
798  {
799  $block_gui->setAllowMove("up");
800  }
801  if ($i < $sum_moveable)
802  {
803  $block_gui->setAllowMove("down");
804  }
805 
806  // get block for custom blocks
807  if ($block["custom"])
808  {
809  include_once("./".self::$locations[$gui_class]."classes/".
810  "class.".$block_class.".php");
811  $app_block = new $block_class($block["id"]);
812  $block_gui->setBlock($app_block);
813  $block_gui->setRefId($block["ref_id"]);
814  }
815 
816  $ilCtrl->setParameter($this, "block_type", $block["type"]);
817  echo $ilCtrl->getHTML($block_gui);
818  $ilBench->save();
819  exit;
820  }
821 
822  // count (moveable) blocks
823  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb"
824  && $block["type"] != "news")
825  {
826  $i++;
827  }
828  else
829  {
830  $sum_moveable--;
831  }
832  }
833  echo "Error: ilColumnGUI::updateBlock: Block '".
834  $_GET["block_id"]."' unknown.";
835  exit;
836  }
837 
841  function activateBlock()
842  {
843  global $ilUser, $ilCtrl;
844 
845  if ($_POST["block"] != "")
846  {
847  $block = explode("_", $_POST["block"]);
848  include_once("Services/Block/classes/class.ilBlockSetting.php");
849  ilBlockSetting::_writeDetailLevel($block[0], 2, $ilUser->getId(), $block[1]);
850  }
851 
852  $ilCtrl->returnToParent($this);
853  }
854 
858  function addBlock()
859  {
860  global $ilCtrl;
861 
862  $class = array_search($_POST["block_type"], self::$block_types);
863 
864  $ilCtrl->setCmdClass($class);
865  $ilCtrl->setCmd("create");
866  include_once("./".self::$locations[$class]."classes/class.".$class.".php");
867  $block_gui = new $class();
868  $block_gui->setProperties($this->block_property[$_POST["block_type"]]);
869  $block_gui->setRepositoryMode($this->getRepositoryMode());
870  $block_gui->setEnableEdit($this->getEnableEdit());
871  $block_gui->setAdminCommands($this->getAdminCommands());
872  $block_gui->setConfigMode($this->getMovementMode());
873 
874  $ilCtrl->setParameter($this, "block_type", $_POST["block_type"]);
875  $html = $ilCtrl->forwardCommand($block_gui);
876  $ilCtrl->setParameter($this, "block_type", "");
877  return $html;
878  }
879 
883  function determineBlocks()
884  {
885  global $ilUser, $ilCtrl, $ilSetting;
886 
887  include_once("./Services/Block/classes/class.ilBlockSetting.php");
888  $this->blocks[IL_COL_LEFT] = array();
889  $this->blocks[IL_COL_RIGHT] = array();
890  $this->blocks[IL_COL_CENTER] = array();
891 
892  $user_id = ($this->getColType() == "pd")
893  ? $ilUser->getId()
894  : 0;
895 
896  $def_nr = 1000;
897  if (is_array($this->default_blocks[$this->getColType()]))
898  {
899  foreach($this->default_blocks[$this->getColType()] as $class => $def_side)
900  {
901  $type = self::$block_types[$class];
902 
903  if ($this->isGloballyActivated($type))
904  {
905  $nr = ilBlockSetting::_lookupNr($type, $user_id);
906  if ($nr === false)
907  {
908  $nr = $def_nr++;
909  }
910 
911 
912  // extra handling for system messages, feedback block and news
913  if ($type == "news") // always show news first
914  {
915  $nr = -15;
916  }
917  if ($type == "cal") // show calendar after news
918  {
919  $nr = -8;
920  }
921  if ($type == "pdsysmess") // always show sys mess first
922  {
923  $nr = -15;
924  }
925  if ($type == "pdfeedb") // always show feedback request second
926  {
927  $nr = -10;
928  }
930  if ($side === false)
931  {
932  $side = $def_side;
933  }
934 
935  $this->blocks[$side][] = array(
936  "nr" => $nr,
937  "class" => $class,
938  "type" => $type,
939  "id" => 0,
940  "custom" => false);
941  }
942  }
943  }
944 
945  if (!$this->getRepositoryMode())
946  {
947  include_once("./Services/Block/classes/class.ilCustomBlock.php");
948  $costum_block = new ilCustomBlock();
949  $costum_block->setContextObjId($ilCtrl->getContextObjId());
950  $costum_block->setContextObjType($ilCtrl->getContextObjType());
951  $c_blocks = $costum_block->queryBlocksForContext();
952 
953  foreach($c_blocks as $c_block)
954  {
955  $type = $c_block["type"];
956 
957  if ($this->isGloballyActivated($type))
958  {
959  $class = array_search($type, self::$block_types);
960  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
961  if ($nr === false)
962  {
963  $nr = $def_nr++;
964  }
965  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
966  if ($side === false)
967  {
969  }
970 
971  $this->blocks[$side][] = array(
972  "nr" => $nr,
973  "class" => $class,
974  "type" => $type,
975  "id" => $c_block["id"],
976  "custom" => true);
977  }
978  }
979  }
980  else // get all subitems
981  {
982  include_once("./Services/Block/classes/class.ilCustomBlock.php");
983  $rep_items = $this->getRepositoryItems();
984 
985  foreach($this->rep_block_types as $block_type)
986  {
987  if ($this->isGloballyActivated($block_type))
988  {
989  if (!is_array($rep_items[$block_type]))
990  {
991  continue;
992  }
993  foreach($rep_items[$block_type] as $item)
994  {
995  $costum_block = new ilCustomBlock();
996  $costum_block->setContextObjId($item["obj_id"]);
997  $costum_block->setContextObjType($block_type);
998  $c_blocks = $costum_block->queryBlocksForContext();
999  $c_block = $c_blocks[0];
1000 
1001  $type = $block_type;
1002  $class = array_search($type, self::$block_types);
1003  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
1004  if ($nr === false)
1005  {
1006  $nr = $def_nr++;
1007  }
1008  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
1009  if ($side === false)
1010  {
1011  $side = IL_COL_RIGHT;
1012  }
1013 
1014  $this->blocks[$side][] = array(
1015  "nr" => $nr,
1016  "class" => $class,
1017  "type" => $type,
1018  "id" => $c_block["id"],
1019  "custom" => true,
1020  "ref_id" => $item["ref_id"]);
1021  }
1022  }
1023  }
1024  }
1025 
1026 
1027  $this->blocks[IL_COL_LEFT] =
1028  ilUtil::sortArray($this->blocks[IL_COL_LEFT], "nr", "asc", true);
1029  $this->blocks[IL_COL_RIGHT] =
1030  ilUtil::sortArray($this->blocks[IL_COL_RIGHT], "nr", "asc", true);
1031  $this->blocks[IL_COL_CENTER] =
1032  ilUtil::sortArray($this->blocks[IL_COL_CENTER], "nr", "asc", true);
1033 
1034  }
1035 
1036  function moveBlock()
1037  {
1038  global $ilUser, $ilCtrl;
1039 
1040  $this->determineBlocks();
1041 
1042  if (in_array($this->getColType(), array("pd", "crs", "cat", "grp")))
1043  {
1044  $bid = explode("_", $_GET["block_id"]);
1045  $i = 2;
1046  foreach($this->blocks[$this->getCmdSide()] as $block)
1047  {
1048  // only handle non-hidden blocks (or repository mode, here we cannot hide blocks)
1049  if ($this->getRepositoryMode() || ilBlockSetting::_lookupDetailLevel($block["type"],
1050  $ilUser->getId(), $block["id"]) != 0)
1051  {
1052  $user_id = ($this->getRepositoryMode())
1053  ? 0
1054  : $ilUser->getId();
1055 
1056  ilBlockSetting::_writeNumber($block["type"], $i, $user_id, $block["id"]);
1057 
1058  if ($block["type"] == $bid[0] && $block["id"] == $bid[1])
1059  {
1060  if ($_GET["move_dir"] == "up")
1061  {
1062  ilBlockSetting::_writeNumber($block["type"], $i-3, $user_id, $block["id"]);
1063  }
1064  if ($_GET["move_dir"] == "down")
1065  {
1066  ilBlockSetting::_writeNumber($block["type"], $i+3, $user_id, $block["id"]);
1067  }
1068  if ($_GET["move_dir"] == "left")
1069  {
1070  ilBlockSetting::_writeNumber($block["type"], 200, $user_id, $block["id"]);
1071  ilBlockSetting::_writeSide($block["type"], IL_COL_LEFT, $user_id, $block["id"]);
1072  }
1073  if ($_GET["move_dir"] == "right")
1074  {
1075  ilBlockSetting::_writeNumber($block["type"], 200, $user_id, $block["id"]);
1076  ilBlockSetting::_writeSide($block["type"], IL_COL_RIGHT, $user_id, $block["id"]);
1077  }
1078  }
1079  else
1080  {
1081  ilBlockSetting::_writeNumber($block["type"], $i, $user_id, $block["id"]);
1082  }
1083  $i+=2;
1084  }
1085  }
1086  }
1087  $ilCtrl->returnToParent($this);
1088  }
1089 
1093  protected function isGloballyActivated($a_type)
1094  {
1095  global $ilSetting;
1096  if (isset($this->check_global_activation[$a_type]) && $this->check_global_activation[$a_type])
1097  {
1098  if ($a_type == 'pdbookm')
1099  {
1100  if (!$ilSetting->get("disable_bookmarks"))
1101  {
1102  return true;
1103  }
1104  return false;
1105  }
1106  else if ($a_type == 'pdnotes')
1107  {
1108  if (!$ilSetting->get("disable_notes"))
1109  {
1110  return true;
1111  }
1112  return false;
1113  }
1114  else if ($ilSetting->get("block_activated_".$a_type))
1115  {
1116  return true;
1117  }
1118  elseif($a_type == 'cal' || $a_type == 'pdcal')
1119  {
1120  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1121  return ilCalendarSettings::_getInstance()->isEnabled();
1122  }
1123  return false;
1124  }
1125  return true;
1126  }
1127 
1131  protected function exceededLimit($a_type)
1132  {
1133  global $ilSetting, $ilCtrl;
1134 
1135  if ($this->check_nr_limit[$a_type])
1136  {
1137  if (!$this->getRepositoryMode())
1138  {
1139  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1140  $costum_block = new ilCustomBlock();
1141  $costum_block->setContextObjId($ilCtrl->getContextObjId());
1142  $costum_block->setContextObjType($ilCtrl->getContextObjType());
1143  $costum_block->setType($a_type);
1144  $res = $costum_block->queryCntBlockForContext();
1145  $cnt = (int) $res[0]["cnt"];
1146  }
1147  else
1148  {
1149  return false; // not implemented for repository yet
1150  }
1151 
1152 
1153  if ($ilSetting->get("block_limit_".$a_type) > $cnt)
1154  {
1155  return false;
1156  }
1157  else
1158  {
1159  return true;
1160  }
1161  }
1162  return false;
1163  }
1164 
1165 }