ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOpenIdSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/OpenId/classes/class.ilOpenIdSettings.php';
5 
14 {
15  private $ctrl;
16  private $lng;
17  private $tpl;
18 
19  private $ref_id;
20  private $settings;
21 
22  private $form = null;
23  private $provider = null;
24 
25 
29  public function __construct($a_ref_id)
30  {
31  $this->ref_id = $a_ref_id;
32  $this->ctrl = $GLOBALS['ilCtrl'];
33  $this->lng = $GLOBALS['lng'];
34  $this->tpl = $GLOBALS['tpl'];
35  $this->lng->loadLanguageModule('auth');
37  }
38 
43  public function executeCommand()
44  {
45  global $ilAccess, $ilErr, $lng;
46 
47  if(!$ilAccess->checkAccess('read','',$this->getRefId()))
48  {
49  $ilErr->raiseError($lng->txt('msg_no_perm_read'),$ilErr->WARNING);
50  }
51  switch($this->ctrl->getNextClass($this))
52  {
53  default:
54  if(!$cmd = $this->ctrl->getCmd())
55  {
56  $cmd = 'settings';
57  }
58  $this->$cmd();
59  break;
60  }
61  }
62 
68  private function setSubTabs()
69  {
70  global $ilTabs;
71 
72  $ilTabs->addSubTabTarget(
73  "auth_openid_settings",
74  $this->ctrl->getLinkTarget($this,'settings')
75  );
76  $ilTabs->addSubTabTarget(
77  'auth_openid_provider',
78  $this->ctrl->getLinkTarget($this,'provider')
79  );
80  }
81 
82 
87  public function getRefId()
88  {
89  return $this->ref_id;
90  }
91 
96  protected function settings()
97  {
98  global $tpl,$lng,$ilTabs;
99 
100  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
101 
102  $tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.openid_settings.html','Services/OpenId');
103 
104  $this->setSubTabs();
105  $ilTabs->setSubTabActive('auth_openid_settings');
106 
107  $this->form = new ilPropertyFormGUI();
108  $this->form->setTableWidth('75%');
109  $this->form->setFormAction($this->ctrl->getFormAction($this,'save'));
110 
111  $this->form->setTitle($this->lng->txt('auth_openid_configure'));
112 
113  // Activation
114  $check = new ilCheckboxInputGUI($this->lng->txt('auth_openid_enable'),'active');
115  $check->setChecked($this->settings->isActive() ? 1 : 0);
116  $check->setValue(1);
117  $this->form->addItem($check);
118 
119  // Selection
120  $sel = new ilCheckboxInputGUI($this->lng->txt('auth_openid_uncontrolled_selection'),'free');
121  $sel->setChecked(!$this->settings->forcedProviderSelection() ? 1 : 0);
122  $sel->setValue(1);
123  $sel->setInfo($this->lng->txt('auth_openid_uncontrolled_selection_info'));
124  $this->form->addItem($sel);
125 
126  // Creation
127  $check = new ilCheckboxInputGUI($this->lng->txt('auth_openid_sync'),'sync');
128  $check->setInfo($this->lng->txt('auth_openid_sync_info'));
129  $check->setChecked($this->settings->isCreationEnabled() ? 1 : 0);
130  $check->setValue(1);
131 
132  // Role selection
133  $select = new ilSelectInputGUI($this->lng->txt('auth_openid_role_select'),'role');
134  $select->setOptions($this->prepareRoleSelection());
135  $select->setValue($this->settings->getDefaultRole());
136  $check->addSubItem($select);
137 
138  $migr = new ilCheckboxInputGUI($this->lng->txt('auth_openid_migration'),'migration');
139  $migr->setInfo($this->lng->txt('auth_openid_migration_info'));
140  $migr->setChecked($this->settings->isAccountMigrationEnabled() ? 1 : 0);
141  $migr->setValue(1);
142  $check->addSubItem($migr);
143  $this->form->addItem($check);
144 
145  $this->form->addCommandButton('save',$this->lng->txt('save'));
146 
147  $tpl->setVariable('SETTINGS_FORM',$this->form->getHTML());
148 
149  return true;
150  }
151 
156  protected function save()
157  {
158  $this->settings->setActive((int) $_POST['active']);
159  $this->settings->forceProviderSelection((int) !$_POST['free']);
160  $this->settings->enableCreation((int) $_POST['sync']);
161  $this->settings->enableAccountMigration((int) $_POST['migration']);
162  $this->settings->setDefaultRole((int) $_POST['role']);
163  $this->settings->update();
164 
165  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
166  $this->ctrl->redirect($this,'settings');
167  }
168 
169 
174  protected function provider()
175  {
176  global $ilTabs;
177 
178  $this->setSubTabs();
179  $ilTabs->setSubTabActive('auth_openid_provider');
180 
181  include_once './Services/OpenId/classes/class.ilOpenIdProviderTableGUI.php';
182  $table = new ilOpenIdProviderTableGUI($this,'provider');
183  $table->parse();
184 
185  $GLOBALS['tpl']->setContent($table->getHTML());
186  return true;
187  }
188 
193  protected function deleteProvider()
194  {
195  if(!isset($_POST['provider_ids']) or !$_POST['provider_ids'])
196  {
197  ilUtil::sendFailure($this->lng->txt('select_one'));
198  $this->provider();
199  return true;
200  }
201 
202  foreach($_POST['provider_ids'] as $provider)
203  {
204  $this->initProvider($provider);
205  $this->provider->delete();
206  }
207  ilUtil::sendSuccess($this->lng->txt('auth_openid_deleted_provider'),TRUE);
208  $this->ctrl->redirect($this,'provider');
209  }
210 
215  protected function addProvider()
216  {
217  global $ilTabs;
218 
219  $this->setSubTabs();
220  $ilTabs->setSubTabActive('auth_openid_provider');
221 
222  $this->initProvider(0);
223  $this->initFormProvider('add');
224  $this->tpl->setContent($this->form->getHTML());
225  }
226 
231  protected function editProvider()
232  {
233  global $ilTabs;
234 
235  $this->setSubTabs();
236  $ilTabs->setSubTabActive('auth_openid_provider');
237 
238  $this->ctrl->setParameter($this,'provider_id',$_GET['provider_id']);
239 
240  $this->initProvider((int) $_GET['provider_id']);
241  $this->initFormProvider('edit');
242  $this->tpl->setContent($this->form->getHTML());
243  }
244 
249  protected function createProvider()
250  {
251  global $tpl;
252 
253  $this->initProvider(0);
254  $this->initFormProvider('add');
255 
256  if(!$this->form->checkInput())
257  {
258  $this->form->setValuesByPost();
259  ilUtil::sendFailure($this->lng->txt('err_check_input'));
260  $tpl->setContent($this->form->getHTML());
261  return false;
262  }
263  $this->loadProviderFromPost();
264  $this->provider->add();
265  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
266  $this->ctrl->redirect($this,'provider');
267  }
268 
273  protected function updateProvider()
274  {
275  global $tpl;
276 
277  $this->initProvider((int) $_GET['provider_id']);
278  $this->initFormProvider('edit');
279 
280  if(!$this->form->checkInput())
281  {
282  $this->form->setValuesByPost();
283  ilUtil::sendFailure($this->lng->txt('err_check_input'));
284  $tpl->setContent($this->form->getHTML());
285  return false;
286  }
287  $this->loadProviderFromPost();
288  $this->provider->update();
289  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
290  $this->ctrl->redirect($this,'provider');
291  }
292 
298  protected function initFormProvider($a_mode = 'edit')
299  {
300  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
301  $this->form = new ilPropertyFormGUI();
302  $this->form->setFormAction($this->ctrl->getFormAction($this,'provider'));
303  $this->form->setTableWidth('75%');
304 
305  switch($a_mode)
306  {
307  case 'edit':
308  $this->form->setTitle($this->lng->txt('auth_openid_provider_edit'));
309  $this->form->addCommandButton('updateProvider', $this->lng->txt('save'));
310  $this->form->addCommandButton('provider', $this->lng->txt('cancel'));
311  break;
312 
313  case 'add':
314  $this->form->setTitle($this->lng->txt('auth_openid_provider_add'));
315  $this->form->addCommandButton('createProvider', $this->lng->txt('btn_add'));
316  $this->form->addCommandButton('provider', $this->lng->txt('cancel'));
317  break;
318  }
319 
320  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
321  $title->setRequired(true);
322  $title->setMaxLength(128);
323  $title->setSize(32);
324  $title->setValue($this->provider->getName());
325  $this->form->addItem($title);
326 
327  $url = new ilTextInputGUI($this->lng->txt('url'),'url');
328  $url->setValidationRegexp('/http.*%s.*/');
329  $url->setRequired(true);
330  $url->setMaxLength(255);
331  $url->setSize(32);
332  $url->setInfo($this->lng->txt('auth_openid_url_info'));
333  $url->setValue($this->provider->getURL());
334  $this->form->addItem($url);
335  }
336 
342  protected function initProvider($a_provider_id)
343  {
344  include_once './Services/OpenId/classes/class.ilOpenIdProvider.php';
345 
346  $this->provider = new ilOpenIdProvider($a_provider_id);
347  return $this->provider;
348  }
349 
353  protected function loadProviderFromPost()
354  {
355  $this->provider->setName($this->form->getInput('title'));
356  $this->provider->setURL($this->form->getInput('url'));
357  return $this->provider();
358  }
359 
360 
365  private function prepareRoleSelection()
366  {
367  global $rbacreview,$ilObjDataCache;
368 
369  $global_roles = ilUtil::_sortIds($rbacreview->getGlobalRoles(),
370  'object_data',
371  'title',
372  'obj_id');
373 
374  $select[0] = $this->lng->txt('links_select_one');
375  foreach($global_roles as $role_id)
376  {
377  $select[$role_id] = ilObject::_lookupTitle($role_id);
378  }
379 
380  return $select;
381  }
382 }
383 ?>