ILIAS  release_4-4 Revision
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 
27  const SETTINGS_USER = "usrf";
28  const SETTINGS_GENERAL = "adm";
29  const SETTINGS_FILE = "facs";
30  const SETTINGS_ROLE = "rolf";
31  const SETTINGS_FORUM = "frma";
32  const SETTINGS_LRES = "lrss";
33  const SETTINGS_REPOSITORY = "reps";
34  const SETTINGS_PD = "pdts";
35  const SETTINGS_COURSE = "crss";
36  const SETTINGS_GROUP = "grps";
38  const SETTINGS_CALENDAR = "cals";
39  const SETTINGS_AUTH = "auth";
40  const SETTINGS_WIKI = "wiks";
41  const SETTINGS_PORTFOLIO = "prfa";
42 
43  const VALUE_BOOL = "bool";
44 
45  protected static function initObjectMap()
46  {
47  global $tree;
48 
49  $map = array("adm" => SYSTEM_FOLDER_ID);
50  foreach($tree->getChilds(SYSTEM_FOLDER_ID) as $obj)
51  {
52  $map[$obj["type"]] = $obj["ref_id"];
53  }
54 
55  self::$OBJ_MAP = $map;
56  }
57 
58  protected static function getRefId($a_obj_type)
59  {
60  if(!is_array(self::$OBJ_MAP))
61  {
62  self::initObjectMap();
63  }
64  return self::$OBJ_MAP[$a_obj_type];
65  }
66 
67  public static function getSettingsGUIInstance($a_settings_obj_type)
68  {
69  global $objDefinition, $ilCtrl;
70 
71  $ref_id = self::getRefId($a_settings_obj_type);
72  $obj_type = ilObject::_lookupType($ref_id, true);
73 
74  $class_name = $objDefinition->getClassName($obj_type);
75  $class_name = "ilObj".$class_name."GUI";
76 
77  $class_path = $ilCtrl->lookupClassPath($class_name);
78  include_once($class_path);
79 
80  if(is_subclass_of($class_name, "ilObject2GUI"))
81  {
82  $gui_obj = new $class_name($ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
83  }
84  else
85  {
86  $gui_obj = new $class_name("", $ref_id, true, false);
87  }
88 
89  $gui_obj->setCreationMode(true);
90 
91  return $gui_obj;
92  }
93 
94  public static function addFieldsToForm($a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
95  {
96  switch($a_form_id)
97  {
98  case self::FORM_SECURITY:
99  $types = array(self::SETTINGS_GENERAL, self::SETTINGS_USER, self::SETTINGS_FILE, self::SETTINGS_ROLE);
100  break;
101 
102  case self::FORM_PRIVACY:
103  $types = array(self::SETTINGS_ROLE, self::SETTINGS_FORUM, self::SETTINGS_LRES);
104  break;
105 
106  case self::FORM_FILES_QUOTA:
107  $types = array(self::SETTINGS_PD);
108  break;
109 
110  case self::FORM_LP:
111  $types = array(self::SETTINGS_REPOSITORY);
112  break;
113 
114  case self::FORM_ACCESSIBILITY:
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 
122  case self::FORM_COURSE:
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 
131  default:
132  $types = null;
133  break;
134  }
135 
136  if(is_array($types))
137  {
138  foreach($types as $type)
139  {
140  $gui = self::getSettingsGUIInstance($type);
141  if($gui && method_exists($gui, "addToExternalSettingsForm"))
142  {
143  $data = $gui->addToExternalSettingsForm($a_form_id);
144  if(is_array($data))
145  {
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(sizeof($data))
162  {
163  self::parseFieldDefinition("cron", $a_form, $parent_gui, $data);
164  }
165  }
166 
167  protected static function parseFieldValue($a_field_type, &$a_field_value)
168  {
169  global $lng;
170 
171  switch($a_field_type)
172  {
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  {
183  $a_field_value = "-";
184  }
185 
186  if(is_numeric($a_field_value) || $a_field_value !== "")
187  {
188  return true;
189  }
190  return false;
191  }
192 
193  protected static function parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)
194  {
195  global $lng, $rbacsystem, $ilCtrl;
196 
197  if(!is_array($a_data))
198  {
199  return;
200  }
201 
202  foreach($a_data as $area_caption => $fields)
203  {
204  if(is_numeric($area_caption) || !trim($area_caption))
205  {
206  $area_caption = "obj_".$a_type;
207  }
208 
209  if(is_array($fields) && sizeof($fields) == 2)
210  {
211  $cmd = $fields[0];
212  $fields = $fields[1];
213  if(is_array($fields))
214  {
215  $ftpl = new ilTemplate("tpl.external_settings.html", true, true, "Services/Administration");
216 
217 
218  $stack = array();
219  foreach($fields as $field_caption_id => $field_value)
220  {
221  $field_type = $subitems = null;
222  if(is_array($field_value))
223  {
224  $field_type = $field_value[1];
225  $subitems = $field_value[2];
226  $field_value = $field_value[0];
227  }
228 
229  if(self::parseFieldValue($field_type, $field_value))
230  {
231  $ftpl->setCurrentBlock("value_bl");
232  $ftpl->setVariable("VALUE", $field_value);
233  $ftpl->parseCurrentBlock();
234  }
235 
236  if(is_array($subitems))
237  {
238  $ftpl->setCurrentBlock("subitem_bl");
239  foreach($subitems as $sub_caption_id => $sub_value)
240  {
241  $sub_type = null;
242  if(is_array($sub_value))
243  {
244  $sub_type = $sub_value[1];
245  $sub_value = $sub_value[0];
246  }
247  self::parseFieldValue($sub_type, $sub_value);
248 
249  $ftpl->setVariable("SUBKEY", $lng->txt($sub_caption_id));
250  $ftpl->setVariable("SUBVALUE", $sub_value);
251  $ftpl->parseCurrentBlock();
252  }
253  }
254 
255  $ftpl->setCurrentBlock("row_bl");
256  $ftpl->setVariable("KEY", $lng->txt($field_caption_id));
257  $ftpl->parseCurrentBlock();
258  }
259 
260  if ($rbacsystem->checkAccess("visible,read", $a_gui->object->getRefId()))
261  {
262  if(!$cmd)
263  {
264  $cmd = "view";
265  }
266  $ilCtrl->setParameter($a_gui, "ref_id", $a_gui->object->getRefId());
267 
268  $ftpl->setCurrentBlock("edit_bl");
269  $ftpl->setVariable("URL_EDIT", $ilCtrl->getLinkTargetByClass(array("ilAdministrationGUI", get_class($a_gui)), $cmd));
270  $ftpl->setVariable("TXT_EDIT", $lng->txt("adm_external_setting_edit"));
271  $ftpl->parseCurrentBlock();
272  }
273 
274  $ext = new ilCustomInputGUI($lng->txt($area_caption));
275  $ext->setHtml($ftpl->get());
276  $a_form->addItem($ext);
277  }
278  }
279  }
280  }
281 }
282 
283 ?>
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
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.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:40
Class ilCronManagerGUI.
static parseFieldDefinition($a_type, ilPropertyFormGUI $a_form, ilObjectGUI $a_gui, $a_data)