• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

course/classes/class.ilCourseRegisterGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00035 class ilCourseRegisterGUI
00036 {
00037         var $ctrl;
00038         var $ilias;
00039         var $tree;
00040         var $ilErr;
00041         var $lng;
00042         var $tpl;
00043 
00044         var $course_obj;
00045         var $course_id;
00046         var $user_id;
00047 
00048 
00049         var $validation = true;
00050         
00051         function ilCourseRegisterGUI($a_course_id)
00052         {
00053                 global $ilCtrl,$lng,$ilErr,$ilias,$tpl,$tree;
00054 
00055                 $this->ctrl =& $ilCtrl;
00056                 $this->ctrl->saveParameter($this,array("ref_id"));
00057 
00058                 $this->ilErr =& $ilErr;
00059                 $this->lng =& $lng;
00060                 $this->tpl =& $tpl;
00061                 $this->tree =& $tree;
00062 
00063                 $this->user_id = $ilias->account->getId();
00064 
00065                 $this->course_id = $a_course_id;
00066                 $this->__initCourseObject();
00067                 $this->__initWaitingList();
00068         }
00069 
00073         function &executeCommand()
00074         {
00075                 switch($cmd = $this->ctrl->getCmd())
00076                 {
00077                         case 'archive':
00078                         case 'join':
00079                         case 'view':
00080                         case '':
00081                                 $cmd = "showRegistrationForm";
00082                                 break;
00083                 }
00084                 $this->$cmd();
00085         }
00086 
00087         function cancel()
00088         {
00089                 sendInfo($this->lng->txt("action_aborted"),true);
00090 
00091                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00092         }
00093 
00094         function subscribe()
00095         {
00096                 if((($this->course_obj->getSubscriptionMaxMembers() <= $this->course_obj->members_obj->getCountMembers())
00097                         and $this->course_obj->getSubscriptionMaxMembers() != 0) or
00098                    $this->waiting_list->getCountUsers())
00099                 {
00100                         // First check password
00101                         if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD)
00102                         {
00103                                 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00104                                 {
00105                                         sendInfo($this->lng->txt("crs_password_not_valid"));
00106                                         $this->validation = false;
00107                                         $this->showRegistrationForm();
00108 
00109                                         return false;
00110                                 }
00111                         }
00112 
00113 
00114                         include_once 'course/classes/class.ilCourseWaitingList.php';
00115 
00116                         if(!$this->waiting_list->isOnList($this->user_id))
00117                         {
00118                                 $this->waiting_list->addToList($this->user_id);
00119                                 
00120                                 $info = sprintf($this->lng->txt('crs_added_to_list'),$this->waiting_list->getPosition($this->user_id));
00121                                 sendInfo($info,true);
00122 
00123                                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00124                         }
00125                         else
00126                         {
00127                                 sendInfo($this->lng->txt('crs_already_assigned_to_list'),true);
00128                                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00129                         }                               
00130                 }                               
00131                 switch($this->course_obj->getSubscriptionType())
00132                 {
00133                         case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00134                                 $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00135                                 exit;
00136 
00137                         case $this->course_obj->SUBSCRIPTION_DIRECT:
00138                                 
00139                                 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00140 
00141                                 if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00142                                 {
00143                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00144                                         ilObjUser::updateActiveRoles($this->user_id);
00145                                         sendInfo($this->lng->txt("crs_subscription_successful"),true);
00146                                         
00147                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00148                                 }
00149                                 else
00150                                 {
00151                                         sendInfo("err_unknown_error");
00152                                         $this->showRegistrationForm();
00153                                 }
00154                                 break;
00155 
00156                         case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00157 
00158                                 if($this->course_obj->members_obj->addSubscriber($this->user_id))
00159                                 {
00160                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00161                                         sendInfo($this->lng->txt("crs_subscription_successful"),true);
00162                                         $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00163 
00164                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00165                                 }
00166                                 else
00167                                 {
00168                                         sendInfo("err_unknown_error");
00169                                         $this->showRegistrationForm();
00170                                 }
00171                                 break;
00172 
00173                         case $this->course_obj->SUBSCRIPTION_PASSWORD:
00174 
00175                                 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00176 
00177                                 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00178                                 {
00179                                         sendInfo($this->lng->txt("crs_password_not_valid"),true);
00180                                         $this->showRegistrationForm();
00181                                 }
00182                                 else if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00183                                 {
00184                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00185                                         ilObjUser::updateActiveRoles($this->user_id);
00186                                         sendInfo($this->lng->txt("crs_subscription_successful"),true);
00187 
00188                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00189                                 }
00190                                 else
00191                                 {
00192                                         sendInfo("err_unknown_error");
00193                                         $this->showRegistrationForm();
00194                                 }
00195                                 break;
00196                 }
00197         }
00198 
00199         function showRegistrationForm()
00200         {
00201                 $really_submit = true;
00202                 if($this->validation)
00203                 {
00204                         $really_submit = $this->__validateStatus();
00205                 }
00206 
00207                 if($this->course_obj->getMessage())
00208                 {
00209                         sendInfo($this->course_obj->getMessage());
00210                 }
00211 
00212                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_subscription.html","course");
00213                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormActionByClass("ilObjCourseGUI"));
00214                 
00215                 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_crs.gif"));
00216                 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_crs"));
00217                 $this->tpl->setVariable("TITLE",$this->lng->txt("crs_registration"));
00218 
00219                 $this->tpl->setVariable("TXT_SYLLABUS",$this->lng->txt("crs_syllabus"));
00220                 $this->tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus()));
00221 
00222                 $this->tpl->setVariable("TXT_INFO_REG",$this->lng->txt("crs_info_reg"));
00223 
00224 
00225                 // Waiting list
00226                 if($this->course_obj->getSubscriptionMaxMembers())
00227                 {
00228                         $this->tpl->setCurrentBlock("waiting_list");
00229                         $this->tpl->setVariable("TXT_WAITING_LIST",$this->lng->txt('crs_free_places'));
00230                         $free_places = $this->course_obj->getSubscriptionMaxMembers() - $this->course_obj->members_obj->getCountMembers();
00231                         $this->tpl->setVariable("FREE_PLACES",$free_places);
00232                         $this->tpl->parseCurrentBlock();
00233 
00234                         if($this->waiting_list->isOnList($this->user_id))
00235                         {
00236                                 $this->tpl->setCurrentBlock("waiting_list_info");
00237                                 $this->tpl->setVariable("TXT_WAITING_LIST_INFO",$this->lng->txt('crs_youre_position'));
00238                                 $this->tpl->setVariable("POSITION",$this->waiting_list->getPosition($this->user_id));
00239                                 $this->tpl->parseCurrentBlock();
00240                         }
00241                         else
00242                         {
00243                                 $this->tpl->setCurrentBlock("waiting_list_info");
00244                                 $this->tpl->setVariable("TXT_WAITING_LIST_INFO",$this->lng->txt('crs_persons_on_waiting_list'));
00245                                 $this->tpl->setVariable("POSITION",$this->waiting_list->getCountUsers());
00246                                 $this->tpl->parseCurrentBlock();
00247                         }
00248 
00249                 }
00250 
00251                 if($courses = $this->__getGroupingCourses())
00252                 {
00253                         $this->tpl->setVariable("INFO_REG_PRE",$this->lng->txt('crs_grp_info_reg').$courses.'<br>');
00254                 }
00255 
00256                 switch($this->course_obj->getSubscriptionType())
00257                 {
00258                         case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00259                                 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_deactivated"));
00260                                 break;
00261                         case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00262                                 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_confirmation"));
00263                                 break;
00264                         case $this->course_obj->SUBSCRIPTION_DIRECT:
00265                                 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_direct"));
00266                                 break;
00267                         case $this->course_obj->SUBSCRIPTION_PASSWORD:
00268                                 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_password"));
00269                                 break;
00270                 }
00271 
00272                 if($this->course_obj->getSubscriptionType() != $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00273                 {
00274                         $this->tpl->setCurrentBlock("reg_until");
00275                         $this->tpl->setVariable("TXT_REG_UNTIL",$this->lng->txt("crs_reg_until"));
00276 
00277                         if($this->course_obj->getSubscriptionUnlimitedStatus())
00278                         {
00279                                 $this->tpl->setVariable("REG_UNTIL",$this->lng->txt("crs_unlimited"));
00280                         }
00281                         else if($this->course_obj->getSubscriptionStart() < time())
00282                         {
00283                                 $this->tpl->setVariable("FROM",$this->lng->txt("crs_to"));
00284                                 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionEnd()));
00285                         }
00286                         else if($this->course_obj->getSubscriptionStart() > time())
00287                         {
00288                                 $this->tpl->setVariable("FROM",$this->lng->txt("crs_from"));
00289                                 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionStart()));
00290                         }
00291                         $this->tpl->parseCurrentBlock();
00292                 }
00293 
00294                 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD and
00295                    $this->course_obj->inSubscriptionTime())
00296                 {
00297                         $this->tpl->setCurrentBlock("pass");
00298                         $this->tpl->setVariable("TXT_PASSWORD",$this->lng->txt("crs_access_password"));
00299                         $this->tpl->parseCurrentBlock();
00300                 }
00301 
00302                 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
00303 
00304                 if($really_submit)
00305                 {
00306                         $this->tpl->setCurrentBlock("go");
00307                         $this->tpl->setVariable("CMD_SUBMIT","subscribe");
00308                         $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("register"));
00309                         $this->tpl->parseCurrentBlock();
00310                 }
00311                         
00312 
00313                 return true;
00314         }
00315 
00316 
00317         // PRIVATE
00318         function __initCourseObject()
00319         {
00320                 if(!$this->course_obj =& ilObjectFactory::getInstanceByRefId($this->course_id,false))
00321                 {
00322                         $this->ilErr->raiseError("ilCourseRegisterGUI: cannot create course object",$this->ilErr->MESSAGE);
00323                         exit;
00324                 }
00325                 $this->course_obj->initCourseMemberObject();
00326 
00327                 return true;
00328         }
00329 
00330         function __initWaitingList()
00331         {
00332                 include_once 'course/classes/class.ilCourseWaitingList.php';
00333 
00334                 $this->waiting_list =& new ilCourseWaitingList($this->course_obj->getId());
00335 
00336                 return true;
00337         }
00338 
00339         function __validateStatus()
00340         {
00341                 $allow_subscription = true;
00342 
00343                 $this->course_obj->setMessage('');
00344 
00345                 if($this->course_obj->members_obj->isAssigned($this->user_id))
00346                 {
00347                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_assigned"));
00348                         $allow_subscription = false;
00349                 }
00350                 if($this->course_obj->members_obj->isBlocked($this->user_id))
00351                 {
00352                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_blocked"));
00353                         $allow_subscription = false;
00354                 }
00355                 if($this->course_obj->members_obj->isSubscriber($this->user_id))
00356                 {
00357                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_subscribed"));
00358                         $allow_subscription = false;
00359                 }
00360                 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00361                 {
00362                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_deactivated"));
00363                         $allow_subscription = false;
00364 
00365                         return false;
00366                 }
00367                 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00368                    ( time() < $this->course_obj->getSubscriptionStart()))
00369                 {
00370                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_start_later"));
00371                         $allow_subscription = false;
00372                 }
00373                 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00374                    ( time() > $this->course_obj->getSubscriptionEnd()))
00375                 {
00376                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_end_earlier"));
00377                         $allow_subscription = false;
00378                 }
00379                 if(!$this->__checkGroupingDependencies())
00380                 {
00381                         $allow_subscription = false;
00382                 }
00383                 if($this->waiting_list->isOnList($this->user_id) and $allow_subscription)
00384                 {
00385                         $this->course_obj->appendMessage($this->lng->txt('crs_already_assigned_to_list'));
00386                         $allow_subscription = false;
00387                 }
00388                 elseif($this->course_obj->getSubscriptionMaxMembers() and 
00389                            ($this->course_obj->members_obj->getCountMembers() >= $this->course_obj->getSubscriptionMaxMembers()) and
00390                            $allow_subscription)
00391                 {
00392                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_max_members_reached"));
00393                         $this->course_obj->appendMessage($this->lng->txt('crs_set_on_waiting_list'));
00394                 }
00395                 elseif($this->waiting_list->getCountUsers() and $allow_subscription)
00396                 {
00397                         $this->course_obj->appendMessage($this->lng->txt('crs_set_on_waiting_list'));
00398                 }
00399                         
00400 
00401                 return $allow_subscription;
00402         }
00403         function __checkGroupingDependencies()
00404         {
00405                 global $ilUser;
00406 
00407                 include_once './classes/class.ilConditionHandler.php';
00408                 include_once './course/classes/class.ilCourseMembers.php';
00409 
00410                 $trigger_ids = array();
00411                 foreach(ilConditionHandler::_getConditionsOfTarget($this->course_obj->getId(),'crs') as $condition)
00412                 {
00413                         if($condition['operator'] == 'not_member')
00414                         {
00415                                 $trigger_ids[] = $condition['trigger_obj_id'];
00416                                 break;
00417                         }
00418                 }
00419                 if(!count($trigger_ids))
00420                 {
00421                         return true;
00422                 }
00423 
00424                 foreach($trigger_ids as $trigger_id)
00425                 {
00426                         foreach(ilConditionHandler::_getConditionsOfTrigger('crsg',$trigger_id) as $condition)
00427                         {
00428                                 if($condition['operator'] == 'not_member')
00429                                 {
00430                                         switch($condition['value'])
00431                                         {
00432                                                 case 'matriculation':
00433                                                         if(!strlen($ilUser->getMatriculation()))
00434                                                         {
00435                                                                 if(!$matriculation_message)
00436                                                                 {
00437                                                                         $matriculation_message = $this->lng->txt('crs_grp_matriculation_required');
00438                                                                 }
00439                                                         }
00440                                         }
00441                                         if(ilCourseMembers::_isMember($ilUser->getId(),$condition['target_obj_id'],$condition['value']))
00442                                         {
00443                                                 if(!$assigned_message)
00444                                                 {
00445                                                         $assigned_message = $this->lng->txt('crs_grp_already_assigned');
00446                                                 }
00447                                         }
00448                                 }
00449                         }
00450                 }
00451                 if($matriculation_message)
00452                 {
00453                         $this->course_obj->appendMessage($matriculation_message);
00454                         return false;
00455                 }
00456                 elseif($assigned_message)
00457                 {
00458                         $this->course_obj->appendMessage($assigned_message);
00459                         return false;
00460                 }
00461                 return true;
00462         }
00463         function __getGroupingCourses()
00464         {
00465                 global $tree;
00466 
00467                 include_once './classes/class.ilConditionHandler.php';
00468                 include_once './course/classes/class.ilCourseMembers.php';
00469 
00470                 $trigger_ids = array();
00471                 foreach(ilConditionHandler::_getConditionsOfTarget($this->course_obj->getId(),'crs') as $condition)
00472                 {
00473                         if($condition['operator'] == 'not_member')
00474                         {
00475                                 $trigger_ids[] = $condition['trigger_obj_id'];
00476                         }
00477                 }
00478                 if(!count($trigger_ids))
00479                 {
00480                         return false;
00481                 }
00482                 foreach($trigger_ids as $trigger_id)
00483                 {
00484                         foreach(ilConditionHandler::_getConditionsOfTrigger('crsg',$trigger_id) as $condition)
00485                         {
00486                                 if($condition['operator'] == 'not_member')
00487                                 {
00488                                         if(!$hash_table[$condition['target_ref_id']])
00489                                         {
00490                                                 $tmp_obj =& ilObjectFactory::getInstanceByRefId($condition['target_ref_id']);
00491                                                 $courses .= (' <br/>'.$this->__formatPath($tree->getPathFull($tmp_obj->getRefId())));
00492                                         }
00493                                         $hash_table[$condition['target_ref_id']] = true;
00494                                 }
00495                         }
00496                 }
00497                 return $courses;
00498         }
00499 
00500         function __formatPath($a_path_arr)
00501         {
00502                 $counter = 0;
00503                 foreach($a_path_arr as $data)
00504                 {
00505                         if($counter++)
00506                         {
00507                                 $path .= " -> ";
00508                         }
00509                         $path .= $data['title'];
00510                 }
00511 
00512                 if(strlen($path) > 40)
00513                 {
00514                         return '...'.substr($path,-40);
00515                 }
00516                 return $path;
00517         }
00518 }
00519 ?>

Generated on Fri Dec 13 2013 10:18:30 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1