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