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