ILIAS  Release_4_2_x_branch Revision 61807
 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  'ilChatroomBlockGUI' => 'Modules/Chatroom/'
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  'ilChatroomBlockGUI' => '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  "ilChatroomBlockGUI" => 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 
172  public static function addCustomBlockLocation($className, $path)
173  {
174  self::$locations[$className] = $path;
175  }
176 
187  public static function addCustomBlockType($className, $identifier)
188  {
189  self::$block_types[$className] = $identifier;
190  }
191 
197  static function getCmdSide()
198  {
199  return $_GET["col_side"];
200  }
201 
207  function setColType($a_coltype)
208  {
209  $this->coltype = $a_coltype;
210  }
211 
217  function getColType()
218  {
219  return $this->coltype;
220  }
221 
227  function setSide($a_side)
228  {
229  $this->side = $a_side;
230  }
231 
237  function getSide()
238  {
239  return $this->side;
240  }
241 
247  function setEnableEdit($a_enableedit)
248  {
249  $this->enableedit = $a_enableedit;
250  }
251 
257  function getEnableEdit()
258  {
259  return $this->enableedit;
260  }
261 
267  function setRepositoryMode($a_repositorymode)
268  {
269  $this->repositorymode = $a_repositorymode;
270  }
271 
277  function getRepositoryMode()
278  {
279  return $this->repositorymode;
280  }
281 
287  function setAdminCommands($a_admincommands)
288  {
289  $this->admincommands = $a_admincommands;
290  }
291 
297  function getAdminCommands()
298  {
299  return $this->admincommands;
300  }
301 
307  function setMovementMode($a_movementmode)
308  {
309  $this->movementmode = $a_movementmode;
310  }
311 
317  function getMovementMode()
318  {
319  return $this->movementmode;
320  }
321 
327  function setEnableMovement($a_enablemovement)
328  {
329  $this->enablemovement = $a_enablemovement;
330  }
331 
337  function getEnableMovement()
338  {
339  return $this->enablemovement;
340  }
341 
345  static function getScreenMode()
346  {
347  global $ilCtrl;
348 
349  if ($ilCtrl->getCmdClass() == "ilcolumngui")
350  {
351  switch ($ilCtrl->getCmd())
352  {
353  case "addBlock":
354  return IL_SCREEN_CENTER;
355  }
356  }
357 
358  $cur_block_type = "";
359  if (isset($_GET["block_type"]) && $_GET["block_type"])
360  {
361  $cur_block_type = $_GET["block_type"];
362  }
363  else if (isset($_POST["block_type"]))
364  {
365  $cur_block_type = $_POST["block_type"];
366  }
367 
368  if ($class = array_search($cur_block_type, self::$block_types))
369  {
370  include_once("./".self::$locations[$class]."classes/".
371  "class.".$class.".php");
372  return call_user_func(array($class, 'getScreenMode'));
373  }
374 
375  return IL_SCREEN_SIDE;
376  }
377 
385  function setBlockProperty($a_block_type, $a_property, $a_value)
386  {
387  $this->block_property[$a_block_type][$a_property] = $a_value;
388  }
389 
390  function getBlockProperties($a_block_type)
391  {
392  return $this->block_property[$a_block_type];
393  }
394 
395  function setAllBlockProperties($a_block_properties)
396  {
397  $this->block_property = $a_block_properties;
398  }
399 
405  function setRepositoryItems($a_repositoryitems)
406  {
407  $this->repositoryitems = $a_repositoryitems;
408  }
409 
416  {
417  return $this->repositoryitems;
418  }
419 
423  function &executeCommand()
424  {
425  global $ilCtrl;
426 
427  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
428  //$ilCtrl->saveParameter($this, "col_side");
429 
430  $next_class = $ilCtrl->getNextClass();
431  $cmd = $ilCtrl->getCmd("getHTML");
432 
433  $cur_block_type = ($_GET["block_type"])
434  ? $_GET["block_type"]
435  : $_POST["block_type"];
436 
437  if ($next_class != "")
438  {
439  // forward to block
440  if ($gui_class = array_search($cur_block_type, self::$block_types))
441  {
442  include_once("./".self::$locations[$gui_class]."classes/".
443  "class.".$gui_class.".php");
444  $ilCtrl->setParameter($this, "block_type", $cur_block_type);
445  $block_gui = new $gui_class();
446  $block_gui->setProperties($this->block_property[$cur_block_type]);
447  $block_gui->setRepositoryMode($this->getRepositoryMode());
448  $block_gui->setEnableEdit($this->getEnableEdit());
449  $block_gui->setAdminCommands($this->getAdminCommands());
450  $block_gui->setConfigMode($this->getMovementMode());
451 
452  if (in_array($gui_class, $this->custom_blocks[$this->getColType()]) ||
453  in_array($cur_block_type, $this->rep_block_types))
454  {
455  $block_class = substr($gui_class, 0, strlen($gui_class)-3);
456  include_once("./".self::$locations[$gui_class]."classes/".
457  "class.".$block_class.".php");
458  $app_block = new $block_class($_GET["block_id"]);
459  $block_gui->setBlock($app_block);
460  }
461  $html = $ilCtrl->forwardCommand($block_gui);
462  $ilCtrl->setParameter($this, "block_type", "");
463 
464  return $html;
465  }
466  }
467  else
468  {
469  return $this->$cmd();
470  }
471  }
472 
476  function getHTML()
477  {
478  global $ilCtrl, $ilBench;
479 
480  $ilBench->start("Column", "getHTML");
481 
482  $ilCtrl->setParameter($this, "col_side" ,$this->getSide());
483 
484  $this->tpl = new ilTemplate("tpl.column.html", true, true, "Services/Block");
485 
486  $ilBench->start("Column", "determineBlocks");
487  $this->determineBlocks();
488  $ilBench->stop("Column", "determineBlocks");
489 
490  $ilBench->start("Column", "showBlocks");
491  $this->showBlocks();
492  $ilBench->stop("Column", "showBlocks");
493 
494  if ($this->getEnableEdit() || !$this->getRepositoryMode())
495  {
496  $this->addHiddenBlockSelector();
497  }
498 
499  $ilBench->stop("Column", "getHTML");
500 
501  return $this->tpl->get();
502  }
503 
507  function showBlocks()
508  {
509  global $ilCtrl, $lng, $ilUser, $ilBench;
510 
511  $blocks = array();
512 
513  $i = 1;
514  $sum_moveable = count($this->blocks[$this->getSide()]);
515 
516  foreach($this->blocks[$this->getSide()] as $block)
517  {
518  if ($ilCtrl->getContextObjType() != "user" ||
519  ilBlockSetting::_lookupDetailLevel($block["type"],
520  $ilUser->getId(), $block["id"]) > 0)
521  {
522  $gui_class = $block["class"];
523  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
524 
525  // get block gui class
526  include_once("./".self::$locations[$gui_class]."classes/".
527  "class.".$gui_class.".php");
528  $ilBench->start("Column", "instantiate-".$block["type"]);
529  $block_gui = new $gui_class();
530  $ilBench->stop("Column", "instantiate-".$block["type"]);
531  if (isset($this->block_property[$block["type"]]))
532  {
533  $block_gui->setProperties($this->block_property[$block["type"]]);
534  }
535  $block_gui->setRepositoryMode($this->getRepositoryMode());
536  $block_gui->setEnableEdit($this->getEnableEdit());
537  $block_gui->setAdminCommands($this->getAdminCommands());
538  $block_gui->setConfigMode($this->getMovementMode());
539  $this->setPossibleMoves($block_gui, $i, $sum_moveable);
540 
541  // get block for custom blocks
542  if ($block["custom"])
543  {
544  include_once("./".self::$locations[$gui_class]."classes/".
545  "class.".$block_class.".php");
546  $app_block = new $block_class($block["id"]);
547  $block_gui->setBlock($app_block);
548  if (isset($block["ref_id"]))
549  {
550  $block_gui->setRefId($block["ref_id"]);
551  }
552  }
553 
554  $ilCtrl->setParameter($this, "block_type", $block_gui->getBlockType());
555  $this->tpl->setCurrentBlock("col_block");
556 
557  $ilBench->start("Column", "showBlocks-".$block_gui->getBlockType());
558  $html = $ilCtrl->getHTML($block_gui);
559  $ilBench->stop("Column", "showBlocks-".$block_gui->getBlockType());
560 
561  // dummy block, if non visible, but movement is ongoing
562  if ($html == "" && $this->getRepositoryMode() &&
563  $this->getMovementMode())
564  {
565  include_once("./Services/Block/classes/class.ilDummyBlockGUI.php");
566  $bl = new ilDummyBlockGUI();
567  $bl->setBlockId($block["id"]);
568  $bl->setBlockType($block["type"]);
569  $bl->setTitle($lng->txt("invisible_block"));
570  $this->setPossibleMoves($bl, $i, $sum_moveable);
571  $bl->setConfigMode($this->getMovementMode());
572  $html = $bl->getHTML();
573  }
574 
575  // don't render a block if it's empty
576  if ($html != "")
577  {
578  $this->tpl->setVariable("BLOCK", $html);
579  $this->tpl->parseCurrentBlock();
580  $ilCtrl->setParameter($this, "block_type", "");
581  }
582 
583  // count (moveable) blocks
584  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb" &&
585  $block["type"] != "news")
586  {
587  $i++;
588  }
589  else
590  {
591  $sum_moveable--;
592  }
593  }
594  }
595  }
596 
597  function setPossibleMoves($a_block_gui, $i, $sum_moveable)
598  {
599  if ($this->getSide() == IL_COL_LEFT)
600  {
601  $a_block_gui->setAllowMove("right");
602  }
603  else if ($this->getSide() == IL_COL_RIGHT && !$this->getRepositoryMode())
604  {
605  $a_block_gui->setAllowMove("left");
606  }
607  if ($i > 1)
608  {
609  $a_block_gui->setAllowMove("up");
610  }
611  if ($i < $sum_moveable)
612  {
613  $a_block_gui->setAllowMove("down");
614  }
615  }
616 
621  {
622  global $lng, $ilUser, $ilCtrl, $ilSetting;
623 
624  $bl_management = false;
625 
626  // show selector for hidden blocks
627  include_once("Services/Block/classes/class.ilBlockSetting.php");
628  $hidden_blocks = array();
629  $blocks = array("pdmail" => $lng->txt("mail"),
630  "pdnotes" => $lng->txt("notes"),
631  "pdusers" => $lng->txt("users_online"),
632  "pdnews" => $lng->txt("news"),
633  "pdbookm" => $lng->txt("my_bms"),
634  "news" => $lng->txt("news_internal_news"),
635  "feed" => $lng->txt("feed"),
636  "pdfeed" => $lng->txt("feed"),
637  "html" => $lng->txt("html_block"),
638  "pdtag" => $lng->txt("tagging_my_tags"),
639  "pdcal" => $lng->txt('calendar'),
640  "chatviewer" => $lng->txt('chat_chatviewer'),
641  );
642 
643  foreach($this->blocks[$this->getSide()] as $block)
644  {
645  include_once("./".self::$locations[$block["class"]]."classes/".
646  "class.".$block["class"].".php");
647 
648  if ($block["custom"] == false)
649  {
650  if ($ilCtrl->getContextObjType() == "user") // personal desktop
651  {
652  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId()) == 0)
653  {
654  $hidden_blocks[$block["type"]] = $blocks[$block["type"]];
655  }
656  }
657  else if ($ilCtrl->getContextObjType() != "")
658  {
659  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
660  $ilCtrl->getContextObjId()) == 0)
661  {
662  $hidden_blocks[$block["type"]."_".$ilCtrl->getContextObjId()] = $blocks[$block["type"]];
663  }
664  }
665  }
666  else
667  {
668  if (ilBlockSetting::_lookupDetailLevel($block["type"], $ilUser->getId(),
669  $block["id"]) == 0)
670  {
671  include_once("./Services/Block/classes/class.ilCustomBlock.php");
672  $cblock = new ilCustomBlock($block["id"]);
673  $hidden_blocks[$block["type"]."_".$block["id"]] =
674  $cblock->getTitle();
675  }
676  }
677  }
678  if (count($hidden_blocks) > 0)
679  {
680  $this->tpl->setCurrentBlock("hidden_block_selector");
681  $this->tpl->setVariable("HB_ACTION", $ilCtrl->getFormAction($this));
682  $this->tpl->setVariable("BLOCK_SEL", ilUtil::formSelect("", "block", $hidden_blocks,
683  false, true, 0, "ilEditSelect", array("id" => "il_show_bl_sel_".$this->getSide())));
684  $this->tpl->setVariable("LAB_ID", "il_show_bl_sel_".$this->getSide());
685  $this->tpl->setVariable("TXT_ACTIVATE", $lng->txt("show"));
686  $this->tpl->setVariable("TXT_SHOW_HIDDEN_BLOCK",
687  $lng->txt("show_hidden_block"));
688  $this->tpl->parseCurrentBlock();
689  $bl_management = true;
690  }
691 
692  // create block selection list
693  if (!$this->getRepositoryMode() || $this->getEnableEdit())
694  {
695  $add_blocks = array();
696  if ($this->getSide() == IL_COL_RIGHT)
697  {
698  if (is_array($this->custom_blocks[$this->getColType()]))
699  {
700  foreach($this->custom_blocks[$this->getColType()] as $block_class)
701  {
702  include_once("./".self::$locations[$block_class]."classes/".
703  "class.".$block_class.".php");
704  $block_type = call_user_func(array($block_class, 'getBlockType'));
705 
706  // check if block type is globally (de-)activated
707  if ($this->isGloballyActivated($block_type))
708  {
709  // check if number of blocks is limited
710  if (!$this->exceededLimit($block_type))
711  {
712  $add_blocks[$block_type] = $blocks[$block_type];
713  }
714  }
715  }
716  }
717  }
718  if (count($add_blocks) > 0)
719  {
720  $this->tpl->setCurrentBlock("add_block_selector");
721  $ilCtrl->setParameter($this, "block_type", "");
722  $this->tpl->setVariable("AB_ACTION", $ilCtrl->getFormAction($this));
723  $this->tpl->setVariable("ADD_BLOCK_SEL", ilUtil::formSelect("", "block_type", $add_blocks,
724  false, true, 0, "ilEditSelect", array("id" => "il_add_bl_sel_".$this->getSide())));
725  $this->tpl->setVariable("LAB_ID", "il_add_bl_sel_".$this->getSide());
726  $this->tpl->setVariable("TXT_ADD", $lng->txt("create"));
727  $this->tpl->setVariable("TXT_CREATE_BLOCK",
728  $lng->txt("create_block"));
729  $this->tpl->parseCurrentBlock();
730  $bl_management = true;
731  }
732  }
733 
734  if ($this->getSide() == IL_COL_RIGHT && $this->getEnableMovement())
735  {
736  $this->tpl->setCurrentBlock("toggle_movement");
737  $this->tpl->setVariable("HREF_TOGGLE_MOVEMENT",
738  $ilCtrl->getLinkTarget($this, "toggleMovement"));
739  if ($_SESSION["col_".$this->getColType()."_movement"] == "on")
740  {
741  $this->tpl->setVariable("TXT_TOGGLE_MOVEMENT",
742  $lng->txt("stop_moving_blocks"));
743  }
744  else
745  {
746  $this->tpl->setVariable("TXT_TOGGLE_MOVEMENT",
747  $lng->txt("move_blocks"));
748  }
749  $this->tpl->parseCurrentBlock();
750  $bl_management = true;
751  }
752 
753  if ($bl_management)
754  {
755  $this->tpl->setCurrentBlock("block_management");
756  $this->tpl->setVariable("TXT_BLOCK_MANAGEMENT",
757  $lng->txt("block_management"));
758  $this->tpl->parseCurrentBlock();
759  }
760 
761  //return $tpl->get();
762 
763  }
764 
765  function toggleMovement()
766  {
767  global $ilCtrl;
768 
769  if ($_SESSION["col_".$this->getColType()."_movement"] == "on")
770  {
771  $_SESSION["col_".$this->getColType()."_movement"] = "off";
772  }
773  else
774  {
775  $_SESSION["col_".$this->getColType()."_movement"] = "on";
776  }
777  $ilCtrl->returnToParent($this);
778  }
779 
783  function updateBlock()
784  {
785  global $ilCtrl, $ilBench;
786 
787  $this->determineBlocks();
788  $i = 1;
789  $sum_moveable = count($this->blocks[$this->getSide()]);
790 
791  foreach ($this->blocks[$this->getSide()] as $block)
792  {
793 
794  include_once("./".self::$locations[$block["class"]]."classes/".
795  "class.".$block["class"].".php");
796 
797  // set block id to context obj id,
798  // if block is not a custom block and context is not personal desktop
799  if (!$block["custom"] && $ilCtrl->getContextObjType() != "" && $ilCtrl->getContextObjType() != "user")
800  {
801  $block["id"] = $ilCtrl->getContextObjId();
802  }
803 
804  //if (is_int(strpos($_GET["block_id"], "block_".$block["type"]."_".$block["id"])))
805 
806  if ($_GET["block_id"] == "block_".$block["type"]."_".$block["id"])
807  {
808  $gui_class = $block["class"];
809  $block_class = substr($block["class"], 0, strlen($block["class"])-3);
810 
811  $block_gui = new $gui_class();
812  $block_gui->setProperties($this->block_property[$block["type"]]);
813  $block_gui->setRepositoryMode($this->getRepositoryMode());
814  $block_gui->setEnableEdit($this->getEnableEdit());
815  $block_gui->setAdminCommands($this->getAdminCommands());
816  $block_gui->setConfigMode($this->getMovementMode());
817 
818  if ($this->getSide() == IL_COL_LEFT)
819  {
820  $block_gui->setAllowMove("right");
821  }
822  else if ($this->getSide() == IL_COL_RIGHT &&
823  !$this->getRepositoryMode())
824  {
825  $block_gui->setAllowMove("left");
826  }
827  if ($i > 1)
828  {
829  $block_gui->setAllowMove("up");
830  }
831  if ($i < $sum_moveable)
832  {
833  $block_gui->setAllowMove("down");
834  }
835 
836  // get block for custom blocks
837  if ($block["custom"])
838  {
839  include_once("./".self::$locations[$gui_class]."classes/".
840  "class.".$block_class.".php");
841  $app_block = new $block_class($block["id"]);
842  $block_gui->setBlock($app_block);
843  $block_gui->setRefId($block["ref_id"]);
844  }
845 
846  $ilCtrl->setParameter($this, "block_type", $block["type"]);
847  echo $ilCtrl->getHTML($block_gui);
848  $ilBench->save();
849  exit;
850  }
851 
852  // count (moveable) blocks
853  if ($block["type"] != "pdsysmess" && $block["type"] != "pdfeedb"
854  && $block["type"] != "news")
855  {
856  $i++;
857  }
858  else
859  {
860  $sum_moveable--;
861  }
862  }
863  echo "Error: ilColumnGUI::updateBlock: Block '".
864  $_GET["block_id"]."' unknown.";
865  exit;
866  }
867 
871  function activateBlock()
872  {
873  global $ilUser, $ilCtrl;
874 
875  if ($_POST["block"] != "")
876  {
877  $block = explode("_", $_POST["block"]);
878  include_once("Services/Block/classes/class.ilBlockSetting.php");
879  ilBlockSetting::_writeDetailLevel($block[0], 2, $ilUser->getId(), $block[1]);
880  }
881 
882  $ilCtrl->returnToParent($this);
883  }
884 
888  function addBlock()
889  {
890  global $ilCtrl;
891 
892  $class = array_search($_POST["block_type"], self::$block_types);
893 
894  $ilCtrl->setCmdClass($class);
895  $ilCtrl->setCmd("create");
896  include_once("./".self::$locations[$class]."classes/class.".$class.".php");
897  $block_gui = new $class();
898  $block_gui->setProperties($this->block_property[$_POST["block_type"]]);
899  $block_gui->setRepositoryMode($this->getRepositoryMode());
900  $block_gui->setEnableEdit($this->getEnableEdit());
901  $block_gui->setAdminCommands($this->getAdminCommands());
902  $block_gui->setConfigMode($this->getMovementMode());
903 
904  $ilCtrl->setParameter($this, "block_type", $_POST["block_type"]);
905  $html = $ilCtrl->forwardCommand($block_gui);
906  $ilCtrl->setParameter($this, "block_type", "");
907  return $html;
908  }
909 
913  function determineBlocks()
914  {
915  global $ilUser, $ilCtrl, $ilSetting;
916 
917  include_once("./Services/Block/classes/class.ilBlockSetting.php");
918  $this->blocks[IL_COL_LEFT] = array();
919  $this->blocks[IL_COL_RIGHT] = array();
920  $this->blocks[IL_COL_CENTER] = array();
921 
922  $user_id = ($this->getColType() == "pd")
923  ? $ilUser->getId()
924  : 0;
925 
926  $def_nr = 1000;
927  if (is_array($this->default_blocks[$this->getColType()]))
928  {
929  foreach($this->default_blocks[$this->getColType()] as $class => $def_side)
930  {
931  $type = self::$block_types[$class];
932 
933  if ($this->isGloballyActivated($type))
934  {
935  $nr = ilBlockSetting::_lookupNr($type, $user_id);
936  if ($nr === false)
937  {
938  $nr = $def_nr++;
939  }
940 
941 
942  // extra handling for system messages, feedback block and news
943  if ($type == "news") // always show news first
944  {
945  $nr = -15;
946  }
947  if ($type == "cal") // show calendar after news
948  {
949  $nr = -8;
950  }
951  if ($type == "pdsysmess") // always show sys mess first
952  {
953  $nr = -15;
954  }
955  if ($type == "pdfeedb") // always show feedback request second
956  {
957  $nr = -10;
958  }
960  if ($side === false)
961  {
962  $side = $def_side;
963  }
964 
965  $this->blocks[$side][] = array(
966  "nr" => $nr,
967  "class" => $class,
968  "type" => $type,
969  "id" => 0,
970  "custom" => false);
971  }
972  }
973  }
974 
975  if (!$this->getRepositoryMode())
976  {
977  include_once("./Services/Block/classes/class.ilCustomBlock.php");
978  $costum_block = new ilCustomBlock();
979  $costum_block->setContextObjId($ilCtrl->getContextObjId());
980  $costum_block->setContextObjType($ilCtrl->getContextObjType());
981  $c_blocks = $costum_block->queryBlocksForContext();
982 
983  foreach($c_blocks as $c_block)
984  {
985  $type = $c_block["type"];
986 
987  if ($this->isGloballyActivated($type))
988  {
989  $class = array_search($type, self::$block_types);
990  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
991  if ($nr === false)
992  {
993  $nr = $def_nr++;
994  }
995  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
996  if ($side === false)
997  {
999  }
1000 
1001  $this->blocks[$side][] = array(
1002  "nr" => $nr,
1003  "class" => $class,
1004  "type" => $type,
1005  "id" => $c_block["id"],
1006  "custom" => true);
1007  }
1008  }
1009  }
1010  else // get all subitems
1011  {
1012  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1013  $rep_items = $this->getRepositoryItems();
1014 
1015  foreach($this->rep_block_types as $block_type)
1016  {
1017  if ($this->isGloballyActivated($block_type))
1018  {
1019  if (!is_array($rep_items[$block_type]))
1020  {
1021  continue;
1022  }
1023  foreach($rep_items[$block_type] as $item)
1024  {
1025  $costum_block = new ilCustomBlock();
1026  $costum_block->setContextObjId($item["obj_id"]);
1027  $costum_block->setContextObjType($block_type);
1028  $c_blocks = $costum_block->queryBlocksForContext();
1029  $c_block = $c_blocks[0];
1030 
1031  $type = $block_type;
1032  $class = array_search($type, self::$block_types);
1033  $nr = ilBlockSetting::_lookupNr($type, $user_id, $c_block["id"]);
1034  if ($nr === false)
1035  {
1036  $nr = $def_nr++;
1037  }
1038  $side = ilBlockSetting::_lookupSide($type, $user_id, $c_block["id"]);
1039  if ($side === false)
1040  {
1041  $side = IL_COL_RIGHT;
1042  }
1043 
1044  $this->blocks[$side][] = array(
1045  "nr" => $nr,
1046  "class" => $class,
1047  "type" => $type,
1048  "id" => $c_block["id"],
1049  "custom" => true,
1050  "ref_id" => $item["ref_id"]);
1051  }
1052  }
1053  }
1054  }
1055 
1056 
1057  $this->blocks[IL_COL_LEFT] =
1058  ilUtil::sortArray($this->blocks[IL_COL_LEFT], "nr", "asc", true);
1059  $this->blocks[IL_COL_RIGHT] =
1060  ilUtil::sortArray($this->blocks[IL_COL_RIGHT], "nr", "asc", true);
1061  $this->blocks[IL_COL_CENTER] =
1062  ilUtil::sortArray($this->blocks[IL_COL_CENTER], "nr", "asc", true);
1063 
1064  }
1065 
1066  function moveBlock()
1067  {
1068  global $ilUser, $ilCtrl;
1069 
1070  $this->determineBlocks();
1071 
1072  if (in_array($this->getColType(), array("pd", "crs", "cat", "grp")))
1073  {
1074  $bid = explode("_", $_GET["block_id"]);
1075  $i = 2;
1076  foreach($this->blocks[$this->getCmdSide()] as $block)
1077  {
1078  // only handle non-hidden blocks (or repository mode, here we cannot hide blocks)
1079  if ($this->getRepositoryMode() || ilBlockSetting::_lookupDetailLevel($block["type"],
1080  $ilUser->getId(), $block["id"]) != 0)
1081  {
1082  $user_id = ($this->getRepositoryMode())
1083  ? 0
1084  : $ilUser->getId();
1085 
1086  ilBlockSetting::_writeNumber($block["type"], $i, $user_id, $block["id"]);
1087 
1088  if ($block["type"] == $bid[0] && $block["id"] == $bid[1])
1089  {
1090  if ($_GET["move_dir"] == "up")
1091  {
1092  ilBlockSetting::_writeNumber($block["type"], $i-3, $user_id, $block["id"]);
1093  }
1094  if ($_GET["move_dir"] == "down")
1095  {
1096  ilBlockSetting::_writeNumber($block["type"], $i+3, $user_id, $block["id"]);
1097  }
1098  if ($_GET["move_dir"] == "left")
1099  {
1100  ilBlockSetting::_writeNumber($block["type"], 200, $user_id, $block["id"]);
1101  ilBlockSetting::_writeSide($block["type"], IL_COL_LEFT, $user_id, $block["id"]);
1102  }
1103  if ($_GET["move_dir"] == "right")
1104  {
1105  ilBlockSetting::_writeNumber($block["type"], 200, $user_id, $block["id"]);
1106  ilBlockSetting::_writeSide($block["type"], IL_COL_RIGHT, $user_id, $block["id"]);
1107  }
1108  }
1109  else
1110  {
1111  ilBlockSetting::_writeNumber($block["type"], $i, $user_id, $block["id"]);
1112  }
1113  $i+=2;
1114  }
1115  }
1116  }
1117  $ilCtrl->returnToParent($this);
1118  }
1119 
1123  protected function isGloballyActivated($a_type)
1124  {
1125  global $ilSetting;
1126  if (isset($this->check_global_activation[$a_type]) && $this->check_global_activation[$a_type])
1127  {
1128  if ($a_type == 'pdbookm')
1129  {
1130  if (!$ilSetting->get("disable_bookmarks"))
1131  {
1132  return true;
1133  }
1134  return false;
1135  }
1136  else if ($a_type == 'pdnotes')
1137  {
1138  if (!$ilSetting->get("disable_notes"))
1139  {
1140  return true;
1141  }
1142  return false;
1143  }
1144  else if ($ilSetting->get("block_activated_".$a_type))
1145  {
1146  return true;
1147  }
1148  elseif($a_type == 'cal' || $a_type == 'pdcal')
1149  {
1150  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
1151  return ilCalendarSettings::_getInstance()->isEnabled();
1152  }
1153  return false;
1154  }
1155  return true;
1156  }
1157 
1161  protected function exceededLimit($a_type)
1162  {
1163  global $ilSetting, $ilCtrl;
1164 
1165  if ($this->check_nr_limit[$a_type])
1166  {
1167  if (!$this->getRepositoryMode())
1168  {
1169  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1170  $costum_block = new ilCustomBlock();
1171  $costum_block->setContextObjId($ilCtrl->getContextObjId());
1172  $costum_block->setContextObjType($ilCtrl->getContextObjType());
1173  $costum_block->setType($a_type);
1174  $res = $costum_block->queryCntBlockForContext();
1175  $cnt = (int) $res[0]["cnt"];
1176  }
1177  else
1178  {
1179  return false; // not implemented for repository yet
1180  }
1181 
1182 
1183  if ($ilSetting->get("block_limit_".$a_type) > $cnt)
1184  {
1185  return false;
1186  }
1187  else
1188  {
1189  return true;
1190  }
1191  }
1192  return false;
1193  }
1194 
1195 }