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