ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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_PD = "pdts";
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 
48  const VALUE_BOOL = "bool";
49 
50  protected static function initObjectMap()
51  {
52  global $DIC;
53 
54  $tree = $DIC->repositoryTree();
55 
56  $map = array("adm" => SYSTEM_FOLDER_ID);
57  foreach ($tree->getChilds(SYSTEM_FOLDER_ID) as $obj) {
58  $map[$obj["type"]] = $obj["ref_id"];
59  }
60 
61  self::$OBJ_MAP = $map;
62  }
63 
64  protected static function getRefId($a_obj_type)
65  {
66  if (!is_array(self::$OBJ_MAP)) {
67  self::initObjectMap();
68  }
69  return self::$OBJ_MAP[$a_obj_type];
70  }
71 
72  public static function getSettingsGUIInstance($a_settings_obj_type)
73  {
74  global $DIC;
75 
76  $objDefinition = $DIC["objDefinition"];
77  $ilCtrl = $DIC->ctrl();
78 
79  $ref_id = self::getRefId($a_settings_obj_type);
80  $obj_type = ilObject::_lookupType($ref_id, true);
81 
82  $class_name = $objDefinition->getClassName($obj_type);
83  $class_name = "ilObj" . $class_name . "GUI";
84 
85  $class_path = $ilCtrl->lookupClassPath($class_name);
86  include_once($class_path);
87 
88  if (is_subclass_of($class_name, "ilObject2GUI")) {
89  $gui_obj = new $class_name($ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
90  } else {
91  $gui_obj = new $class_name("", $ref_id, true, false);
92  }
93 
94  $gui_obj->setCreationMode(true);
95 
96  return $gui_obj;
97  }
98 
99  public static function addFieldsToForm($a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
100  {
101  switch ($a_form_id) {
102  case self::FORM_SECURITY:
103  $types = array(self::SETTINGS_GENERAL, self::SETTINGS_USER, self::SETTINGS_FILE, self::SETTINGS_ROLE);
104  break;
105 
106  case self::FORM_PRIVACY:
107  $types = array(self::SETTINGS_ROLE, self::SETTINGS_FORUM, self::SETTINGS_LRES);
108  break;
109 
110  case self::FORM_FILES_QUOTA:
111  $types = array(self::SETTINGS_PD);
112  break;
113 
114  case self::FORM_LP:
115  $types = array(self::SETTINGS_REPOSITORY);
116  break;
117 
118  case self::FORM_ACCESSIBILITY:
119  $types = array(self::SETTINGS_FORUM, self::SETTINGS_AUTH, self::SETTINGS_WIKI);
120  break;
121 
122  case self::FORM_MAIL:
123  $types = array(self::SETTINGS_COURSE, self::SETTINGS_GROUP);
124  break;
125 
126  case self::FORM_COURSE:
127  case self::FORM_GROUP:
128  $types = array(self::SETTINGS_PRIVACY_SECURITY, self::SETTINGS_CALENDAR, self::SETTINGS_GENERAL);
129  break;
130 
131  case self::FORM_WSP:
132  $types = array(self::SETTINGS_PORTFOLIO);
133  break;
134 
135  case self::FORM_TAGGING:
136  $types = array(self::SETTINGS_REPOSITORY);
137  break;
138 
139  case self::FORM_CERTIFICATE:
140  $types = array(self::SETTINGS_LP_COMPLETION_STATUS);
141  break;
142 
143  default:
144  $types = null;
145  break;
146  }
147 
148  if (is_array($types)) {
149  foreach ($types as $type) {
150  $gui = self::getSettingsGUIInstance($type);
151  if ($gui && method_exists($gui, "addToExternalSettingsForm")) {
152  $data = $gui->addToExternalSettingsForm($a_form_id);
153  if (is_array($data)) {
154  self::parseFieldDefinition($type, $a_form, $gui, $data);
155  }
156  }
157  }
158  }
159 
160  // cron jobs - special handling
161 
162  include_once "Modules/SystemFolder/classes/class.ilObjSystemFolderGUI.php";
163  $parent_gui = new ilObjSystemFolderGUI(null, SYSTEM_FOLDER_ID, true);
164  $parent_gui->setCreationMode(true);
165 
166  include_once "Services/Cron/classes/class.ilCronManagerGUI.php";
167  $gui = new ilCronManagerGUI();
168  $data = $gui->addToExternalSettingsForm($a_form_id);
169  if (is_array($data) && sizeof($data)) {
170  self::parseFieldDefinition("cron", $a_form, $parent_gui, $data);
171  }
172  }
173 
174  protected static function parseFieldValue($a_field_type, &$a_field_value)
175  {
176  global $DIC;
177 
178  $lng = $DIC->language();
179 
180  switch ($a_field_type) {
181  case self::VALUE_BOOL:
182  $a_field_value = (bool) $a_field_value ?
183  $lng->txt("enabled") :
184  $lng->txt("disabled");
185  return $a_field_value;
186  }
187 
188  if (!is_numeric($a_field_value) &&
189  $a_field_value !== null && !trim($a_field_value)) {
190  $a_field_value = "-";
191  }
192 
193  if (is_numeric($a_field_value) || $a_field_value !== "") {
194  return true;
195  }
196  return false;
197  }
198 
199  protected static function parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)
200  {
201  global $DIC;
202 
203  $lng = $DIC->language();
204  $rbacsystem = $DIC->rbac()->system();
205  $ilCtrl = $DIC->ctrl();
206  $ilAccess = $DIC->access();
207 
208  if (!is_array($a_data)) {
209  return;
210  }
211 
212  // write permission for current gui?
213  $has_write = $ilAccess->checkAccess("write", "", (int) $_REQUEST["ref_id"]);
214 
215  foreach ($a_data as $area_caption => $fields) {
216  if (is_numeric($area_caption) || !trim($area_caption)) {
217  $area_caption = "obj_" . $a_type;
218  }
219 
220  if (is_array($fields) && sizeof($fields) == 2) {
221  $cmd = $fields[0];
222  $fields = $fields[1];
223  if (is_array($fields)) {
224  $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "Services/Administration");
225 
226 
227  $stack = array();
228  foreach ($fields as $field_caption_id => $field_value) {
229  $field_type = $subitems = null;
230  if (is_array($field_value)) {
231  $field_type = $field_value[1];
232  $subitems = $field_value[2];
233  $field_value = $field_value[0];
234  }
235 
236  if (self::parseFieldValue($field_type, $field_value)) {
237  $ftpl->setCurrentBlock("value_bl");
238  $ftpl->setVariable("VALUE", $field_value);
239  $ftpl->parseCurrentBlock();
240  }
241 
242  if (is_array($subitems)) {
243  $ftpl->setCurrentBlock("subitem_bl");
244  foreach ($subitems as $sub_caption_id => $sub_value) {
245  $sub_type = null;
246  if (is_array($sub_value)) {
247  $sub_type = $sub_value[1];
248  $sub_value = $sub_value[0];
249  }
250  self::parseFieldValue($sub_type, $sub_value);
251 
252  $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
253  $ftpl->setVariable("SUBVALUE", $sub_value);
254  $ftpl->parseCurrentBlock();
255  }
256  }
257 
258  $ftpl->setCurrentBlock("row_bl");
259  $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
260  $ftpl->parseCurrentBlock();
261  }
262 
263  if ($has_write &&
264  $rbacsystem->checkAccess("visible,read", $a_gui->object->getRefId())) {
265  if (!$cmd) {
266  $cmd = "view";
267  }
268  $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->object->getRefId());
269 
270  $ftpl->setCurrentBlock("edit_bl");
271  $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass(array("ilAdministrationGUI", get_class($a_gui)), $cmd));
272  $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
273  $ftpl->parseCurrentBlock();
274  }
275 
276  $ext = new ilCustomInputGUI($lng->txt($area_caption));
277  $ext->setHtml($ftpl->get());
278  $a_form->addItem($ext);
279  }
280  }
281  }
282  }
283 }
setHtml($a_html)
Set Html.
This class represents a property form user interface.
$type
global $DIC
Definition: saml.php:7
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.
special template class to simplify handling of ITX/PEAR
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a custom property in a property form.
Class ilCronManagerGUI.
static parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)
$data
Definition: bench.php:6