ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGroupRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
25 
36 {
43  public function __construct($a_container)
44  {
45  parent::__construct($a_container);
46  }
47 
53  public function executeCommand()
54  {
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  switch($next_class)
58  {
59  default:
60  $cmd = $this->ctrl->getCmd("show");
61  $this->$cmd();
62  break;
63  }
64  return true;
65  }
66 
67 
74  protected function getFormTitle()
75  {
76  return $this->lng->txt('grp_registration');
77  }
78 
86  protected function fillInformations()
87  {
88  if($this->container->getInformation())
89  {
90  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'));
91  $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
92  $imp->setValue($value);
93  $this->form->addItem($imp);
94  }
95  }
96 
102  protected function fillRegistrationPeriod()
103  {
104  include_once('./Services/Calendar/classes/class.ilDateTime.php');
105  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
106 
107  if($this->container->isRegistrationUnlimited())
108  {
109  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
110  $reg->setValue($this->lng->txt('mem_unlimited'));
111  $this->form->addItem($reg);
112  return true;
113  }
114 
115  $start = $this->container->getRegistrationStart();
116  $end = $this->container->getRegistrationEnd();
117 
118 
119  if(ilDateTime::_before($now,$start))
120  {
121  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
122  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
123  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
124 
125  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
126  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
127 
128  $warning = $this->lng->txt('mem_reg_not_started');
129  }
130  elseif(ilDateTime::_after($now,$end))
131  {
132  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
133  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
134  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
135 
136  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
137  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
138 
139  $warning = $this->lng->txt('mem_reg_expired');
140  }
141  else
142  {
143  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
144  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
145  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
146  }
147 
148  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
149  $reg->setHtml($tpl->get());
150  if(strlen($warning))
151  {
152  // Disable registration
153  $this->enableRegistration(false);
154  $reg->setAlert($warning);
155  }
156  $this->form->addItem($reg);
157  return true;
158  }
159 
166  protected function fillMaxMembers()
167  {
168  global $ilUser;
169 
170  if(!$this->container->isMembershipLimited())
171  {
172  return true;
173  }
174  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
175  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
176  $tpl->setVariable('NUM_MAX',$this->container->getMaxMembers());
177 
178  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
179  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
180  $tpl->setVariable('NUM_FREE',$free);
181 
182  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
183  $waiting_list = new ilGroupWaitingList($this->container->getId());
184  if($this->container->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
185  {
186  if($waiting_list->isOnList($ilUser->getId()))
187  {
188  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
189  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
190 
191  }
192  else
193  {
194  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
195  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
196  }
197  }
198 
199  $alert = '';
200  if(!$free and !$this->container->isWaitingListEnabled())
201  {
202  // Disable registration
203  $this->enableRegistration(false);
204  $alert = $this->lng->txt('mem_alert_no_places');
205  }
206  elseif($this->container->isWaitingListEnabled() and $waiting_list->isOnList($ilUser->getId()))
207  {
208  // Disable registration
209  $this->enableRegistration(false);
210  $alert = $this->lng->txt('mem_already_on_list');
211  }
212  elseif(!$free and $this->container->isWaitingListEnabled())
213  {
214  $alert = $this->lng->txt('grp_set_on_waiting_list');
215  }
216  elseif($waiting_list->getCountUsers() and $this->container->isWaitingListEnabled())
217  {
218  $alert = $this->lng->txt('grp_set_on_waiting_list');
219  }
220 
221  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
222  $max->setHtml($tpl->get());
223  if(strlen($alert))
224  {
225  $max->setAlert($alert);
226  }
227  $this->form->addItem($max);
228  }
229 
237  protected function fillRegistrationType()
238  {
239  global $ilUser;
240 
241  switch($this->container->getRegistrationType())
242  {
244  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
245  $reg->setValue($this->lng->txt('grp_reg_disabled'));
246  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
247  $this->form->addItem($reg);
248 
249  // Disable registration
250  $this->enableRegistration(false);
251 
252  break;
253 
255  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
256  $txt->setValue($this->lng->txt('grp_pass_request'));
257 
258 
259  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
260  $pass->setInputType('password');
261  $pass->setSize(12);
262  $pass->setMaxLength(32);
263  #$pass->setRequired(true);
264  $pass->setInfo($this->lng->txt('group_password_registration_msg'));
265 
266  $txt->addSubItem($pass);
267  $this->form->addItem($txt);
268  break;
269 
271  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
272  $txt->setValue($this->lng->txt('grp_reg_request'));
273 
274  $sub = new ilTextAreaInputGUI($this->lng->txt('subject'),'grp_subject');
275  $sub->setValue($_POST['grp_subject']);
276  $sub->setInfo($this->lng->txt('group_req_registration_msg'));
277  $sub->setCols(40);
278  $sub->setRows(5);
279  if($this->participants->isSubscriber($ilUser->getId()))
280  {
281  $sub->setAlert($this->lng->txt('grp_already_applied'));
282  $this->enableRegistration(false);
283  }
284  $txt->addSubItem($sub);
285  $this->form->addItem($txt);
286  break;
287 
289  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
290  $txt->setValue($this->lng->txt('group_req_direct'));
291 
292  $this->form->addItem($txt);
293  break;
294 
295  default:
296  return true;
297  }
298 
299  return true;
300  }
301 
308  protected function validate()
309  {
310  global $ilUser;
311 
312  if($ilUser->getId() == ANONYMOUS_USER_ID)
313  {
314  $this->join_error = $this->lng->txt('permission_denied');
315  return false;
316  }
317 
318  if(!$this->isRegistrationPossible())
319  {
320  $this->join_error = $this->lng->txt('mem_error_preconditions');
321  return false;
322  }
323  if($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD)
324  {
325  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
326  {
327  $this->join_error = $this->lng->txt('err_wrong_password');
328  return false;
329  }
330  if(strcmp($pass,$this->container->getPassword()) !== 0)
331  {
332  $this->join_error = $this->lng->txt('err_wrong_password');
333  return false;
334  }
335  }
336  return true;
337  }
338 
346  protected function add()
347  {
348  global $ilUser,$tree, $rbacreview, $lng;
349 
350  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
351  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
352  $waiting_list = new ilGroupWaitingList($this->container->getId());
353  if($this->container->isMembershipLimited() and $this->container->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
354  {
355  $waiting_list->addToList($ilUser->getId());
356  $info = sprintf($this->lng->txt('grp_added_to_list'),$waiting_list->getPosition($ilUser->getId()));
357  ilUtil::sendInfo($info,true);
358  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
359  }
360 
361 
362  switch($this->container->getRegistrationType())
363  {
365  $this->participants->addSubscriber($ilUser->getId());
366  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
367  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['grp_subject']));
368 
369 
370  foreach($this->participants->getNotificationRecipients() as $rcp)
371  {
372  global $ilIliasIniFile;
373 
374  $rcp = ilObjUser::_lookupLogin($rcp);
375 
376  $mail = new ilMail($_SESSION["AccountId"]);
377  // XXX - The message should be sent in the language of the receiver,
378  // instead of in the language of the current user
379  $mail->sendMail($rcp,"","",
380  sprintf($lng->txt('grp_membership_request_subject'), $ilUser->getFirstname(), $ilUser->getLastname(), $this->container->getTitle()),
381  sprintf(str_replace('\n',"\n",$lng->txt('grp_membership_request_body')), $ilUser->getFirstname(), $ilUser->getLastname(), $ilUser->getLogin(), $ilUser->getEmail(),
382  $this->container->getTitle(), $ilIliasIniFile->readVariable('server','http_path').'/goto.php?client_id='.CLIENT_ID.'&target=grp_'.$this->container->getRefId(), $_POST["grp_subject"]),
383  array(),array('system'));
384  }
385 
386  ilUtil::sendInfo($this->lng->txt("application_completed"),true);
387  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
388  break;
389 
390  default:
391  $this->participants->add($ilUser->getId(),IL_GRP_MEMBER);
392  ilUtil::sendInfo($this->lng->txt("grp_registration_completed"),true);
393  $this->ctrl->returnToParent($this);
394  break;
395  }
396  }
397 
398 
404  protected function initParticipants()
405  {
406  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
407  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
408  }
409 
410 }
411 ?>