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