ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAdministrationSettingsFormHandler.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  protected static $OBJ_MAP;
13 
14  const FORM_PRIVACY = 1;
15  const FORM_SECURITY = 2;
16  const FORM_FILES_QUOTA = 3;
17  const FORM_LP = 4;
18  const FORM_MAIL = 5;
19  const FORM_COURSE = 6;
20  const FORM_GROUP = 7;
21  const FORM_REPOSITORY = 8;
22  const FORM_LDAP = 9;
23  const FORM_FORUM = 10;
24  const FORM_ACCESSIBILITY = 11;
25  const FORM_WSP = 12;
26  const FORM_TAGGING = 13;
27  const FORM_CERTIFICATE = 14;
28  const FORM_META_COPYRIGHT = 15;
29 
30 
31  const SETTINGS_USER = "usrf";
32  const SETTINGS_GENERAL = "adm";
33  const SETTINGS_FILE = "facs";
34  const SETTINGS_ROLE = "rolf";
35  const SETTINGS_FORUM = "frma";
36  const SETTINGS_LRES = "lrss";
37  const SETTINGS_REPOSITORY = "reps";
38  const SETTINGS_PR = "prss";
39  const SETTINGS_COURSE = "crss";
40  const SETTINGS_GROUP = "grps";
42  const SETTINGS_CALENDAR = "cals";
43  const SETTINGS_AUTH = "auth";
44  const SETTINGS_WIKI = "wiks";
45  const SETTINGS_PORTFOLIO = "prfa";
47  const SETTINGS_LEARNINGSEQUENCE = "lsos";
48 
49  const VALUE_BOOL = "bool";
50 
51  protected static function initObjectMap()
52  {
53  global $DIC;
54 
55  $tree = $DIC->repositoryTree();
56 
57  $map = array("adm" => SYSTEM_FOLDER_ID);
58  foreach ($tree->getChilds(SYSTEM_FOLDER_ID) as $obj) {
59  $map[$obj["type"]] = $obj["ref_id"];
60  }
61 
62  self::$OBJ_MAP = $map;
63  }
64 
65  protected static function getRefId($a_obj_type)
66  {
67  if (!is_array(self::$OBJ_MAP)) {
68  self::initObjectMap();
69  }
70  return self::$OBJ_MAP[$a_obj_type];
71  }
72 
73  public static function getSettingsGUIInstance($a_settings_obj_type)
74  {
75  global $DIC;
76 
77  $objDefinition = $DIC["objDefinition"];
78  $ilCtrl = $DIC->ctrl();
79 
80  $ref_id = self::getRefId($a_settings_obj_type);
81  $obj_type = ilObject::_lookupType($ref_id, true);
82 
83  $class_name = $objDefinition->getClassName($obj_type);
84  $class_name = "ilObj" . $class_name . "GUI";
85  $class_path = $ilCtrl->lookupClassPath($class_name);
86 
87  if (is_subclass_of($class_name, "ilObject2GUI")) {
88  $gui_obj = new $class_name($ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
89  } else {
90  $gui_obj = new $class_name("", $ref_id, true, false);
91  }
92 
93  $gui_obj->setCreationMode(true);
94 
95  return $gui_obj;
96  }
97 
98  public static function addFieldsToForm($a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
99  {
100  switch ($a_form_id) {
101  case self::FORM_SECURITY:
102  $types = array(self::SETTINGS_GENERAL, self::SETTINGS_USER, self::SETTINGS_FILE, self::SETTINGS_ROLE);
103  break;
104 
105  case self::FORM_PRIVACY:
106  $types = array(self::SETTINGS_ROLE, self::SETTINGS_FORUM, self::SETTINGS_LRES);
107  break;
108 
109  case self::FORM_FILES_QUOTA:
110  $types = array(self::SETTINGS_PR);
111  break;
112 
113  case self::FORM_LP:
114  $types = array(self::SETTINGS_REPOSITORY);
115  break;
116 
117  case self::FORM_ACCESSIBILITY:
118  $types = array(self::SETTINGS_FORUM, self::SETTINGS_AUTH, self::SETTINGS_WIKI);
119  break;
120 
121  case self::FORM_MAIL:
122  $types = array(self::SETTINGS_COURSE, self::SETTINGS_GROUP, self::SETTINGS_LEARNINGSEQUENCE);
123  break;
124 
125  case self::FORM_COURSE:
126  case self::FORM_GROUP:
127  $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL);
128  break;
129 
130  case self::FORM_WSP:
131  $types = array(self::SETTINGS_PORTFOLIO);
132  break;
133 
134  case self::FORM_TAGGING:
135  $types = array(self::SETTINGS_REPOSITORY);
136  break;
137 
138  case self::FORM_CERTIFICATE:
139  $types = array(self::SETTINGS_LP_COMPLETION_STATUS);
140  break;
141 
142  default:
143  $types = null;
144  break;
145  }
146 
147  if (is_array($types)) {
148  foreach ($types as $type) {
149  $gui = self::getSettingsGUIInstance($type);
150  if ($gui && method_exists($gui, "addToExternalSettingsForm")) {
151  $data = $gui->addToExternalSettingsForm($a_form_id);
152  if (is_array($data)) {
153  self::parseFieldDefinition($type, $a_form, $gui, $data);
154  }
155  }
156  }
157  }
158 
159  // cron jobs - special handling
160 
161  include_once "Modules/SystemFolder/classes/class.ilObjSystemFolderGUI.php";
162  $parent_gui = new ilObjSystemFolderGUI(null, SYSTEM_FOLDER_ID, true);
163  $parent_gui->setCreationMode(true);
164 
165  include_once "Services/Cron/classes/class.ilCronManagerGUI.php";
166  $gui = new ilCronManagerGUI();
167  $data = $gui->addToExternalSettingsForm($a_form_id);
168  if (is_array($data) && sizeof($data)) {
169  self::parseFieldDefinition("cron", $a_form, $parent_gui, $data);
170  }
171  }
172 
173  protected static function parseFieldValue($a_field_type, &$a_field_value)
174  {
175  global $DIC;
176 
177  $lng = $DIC->language();
178 
179  switch ($a_field_type) {
180  case self::VALUE_BOOL:
181  $a_field_value = (bool) $a_field_value ?
182  $lng->txt("enabled") :
183  $lng->txt("disabled");
184  return $a_field_value;
185  }
186 
187  if (!is_numeric($a_field_value) &&
188  $a_field_value !== null && !trim($a_field_value)) {
189  $a_field_value = "-";
190  }
191 
192  if (is_numeric($a_field_value) || $a_field_value !== "") {
193  return true;
194  }
195  return false;
196  }
197 
198  protected static function parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)
199  {
200  global $DIC;
201 
202  $lng = $DIC->language();
203  $rbacsystem = $DIC->rbac()->system();
204  $ilCtrl = $DIC->ctrl();
205  $ilAccess = $DIC->access();
206 
207  if (!is_array($a_data)) {
208  return;
209  }
210 
211  // write permission for current gui?
212  $has_write = $ilAccess->checkAccess("write", "", (int) $_REQUEST["ref_id"]);
213 
214  foreach ($a_data as $area_caption => $fields) {
215  if (is_numeric($area_caption) || !trim($area_caption)) {
216  $area_caption = "obj_" . $a_type;
217  }
218 
219  if (is_array($fields) && sizeof($fields) == 2) {
220  $cmd = $fields[0];
221  $fields = $fields[1];
222  if (is_array($fields)) {
223  $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "Services/Administration");
224 
225 
226  $stack = array();
227  foreach ($fields as $field_caption_id => $field_value) {
228  $field_type = $subitems = null;
229  if (is_array($field_value)) {
230  $field_type = $field_value[1];
231  $subitems = $field_value[2];
232  $field_value = $field_value[0];
233  }
234 
235  if (self::parseFieldValue($field_type, $field_value)) {
236  $ftpl->setCurrentBlock("value_bl");
237  $ftpl->setVariable("VALUE", $field_value);
238  $ftpl->parseCurrentBlock();
239  }
240 
241  if (is_array($subitems)) {
242  $ftpl->setCurrentBlock("subitem_bl");
243  foreach ($subitems as $sub_caption_id => $sub_value) {
244  $sub_type = null;
245  if (is_array($sub_value)) {
246  $sub_type = $sub_value[1];
247  $sub_value = $sub_value[0];
248  }
249  self::parseFieldValue($sub_type, $sub_value);
250 
251  $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
252  $ftpl->setVariable("SUBVALUE", $sub_value);
253  $ftpl->parseCurrentBlock();
254  }
255  }
256 
257  $ftpl->setCurrentBlock("row_bl");
258  $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
259  $ftpl->parseCurrentBlock();
260  }
261 
262  if ($has_write &&
263  $rbacsystem->checkAccess("visible,read", $a_gui->object->getRefId())) {
264  if (!$cmd) {
265  $cmd = "view";
266  }
267  $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->object->getRefId());
268 
269  $ftpl->setCurrentBlock("edit_bl");
270  $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass(array("ilAdministrationGUI", get_class($a_gui)), $cmd));
271  $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
272  $ftpl->parseCurrentBlock();
273  }
274 
275  $ext = new ilCustomInputGUI($lng->txt($area_caption));
276  $ext->setHtml($ftpl->get());
277  $a_form->addItem($ext);
278  }
279  }
280  }
281  }
282 }
setHtml($a_html)
Set Html.
$data
Definition: storeScorm.php:23
This class represents a property form user interface.
$type
addItem($a_item)
Add Item (Property, SectionHeader).
Class ilObjSystemFolderGUI.
static addFieldsToForm($a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
global $ilCtrl
Definition: ilias.php:18
$a_type
Definition: workflow.php:92
$lng
Class ilObjectGUI Basic methods of all Output classes.
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a custom property in a property form.
$DIC
Definition: xapitoken.php:46
Class ilCronManagerGUI.
static parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)