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