• Main Page
  • Related Pages
  • Modules
  • 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                 global $ilTabs;
00076 
00077                 $ilTabs->setTabActive('join');
00078 
00079                 switch($cmd = $this->ctrl->getCmd())
00080                 {
00081                         case '':
00082                                 $this->ctrl->returnToParent($this);
00083                                 break;
00084 
00085                         case 'archive':
00086                         case 'join':
00087                         case 'view':
00088                                 $cmd = "showRegistrationForm";
00089                                 break;
00090                 }
00091                 $this->$cmd();
00092         }
00093 
00094         function cancel()
00095         {
00096                 sendInfo($this->lng->txt("action_aborted"),true);
00097 
00098                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00099         }
00100 
00101         function subscribe()
00102         {
00103                 global $ilAccess,$ilErr;
00104 
00105                 if(!$ilAccess->checkAccess("join","",$this->course_obj->getRefId(),'crs'))
00106                 {
00107                         $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
00108                 }
00109 
00110                 if($this->course_obj->getSubscriptionMaxMembers())
00111                 {
00112                         $free = $this->course_obj->getSubscriptionMaxMembers() - 
00113                                 $this->course_obj->members_obj->getCountMembers() - $this->course_obj->members_obj->getCountSubscribers();
00114                         $free = $free > 0 ? true : false;
00115                 }
00116                 if($this->course_obj->getSubscriptionMaxMembers() and
00117                    !$free and
00118                    !$this->course_obj->enabledWaitingList())
00119                 {
00120                         $ilErr->raiseError($this->lng->txt("crs_reg_subscription_max_members_reached"),$ilErr->MESSAGE);
00121                 }
00122 
00123                 if($this->course_obj->getSubscriptionMaxMembers() and (!$free or $this->waiting_list->getCountUsers()))
00124                 {
00125                         #if((($this->course_obj->getSubscriptionMaxMembers() <= $this->course_obj->members_obj->getCountMembers())
00126                         #       and $this->course_obj->getSubscriptionMaxMembers() != 0) or
00127                         #   $this->waiting_list->getCountUsers())
00128                         // First check password
00129                         if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD)
00130                         {
00131                                 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00132                                 {
00133                                         sendInfo($this->lng->txt("crs_password_not_valid"));
00134                                         $this->validation = false;
00135                                         $this->showRegistrationForm();
00136 
00137                                         return false;
00138                                 }
00139                         }
00140 
00141 
00142                         include_once 'course/classes/class.ilCourseWaitingList.php';
00143 
00144                         if(!$this->waiting_list->isOnList($this->user_id))
00145                         {
00146                                 $this->waiting_list->addToList($this->user_id);
00147                                 
00148                                 $info = sprintf($this->lng->txt('crs_added_to_list'),$this->waiting_list->getPosition($this->user_id));
00149                                 sendInfo($info,true);
00150 
00151                                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00152                         }
00153                         else
00154                         {
00155                                 sendInfo($this->lng->txt('crs_already_assigned_to_list'),true);
00156                                 ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00157                         }                               
00158                 }
00159 
00160                 if($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
00161                 {
00162                         $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00163                 }
00164 
00165                 switch($this->course_obj->getSubscriptionType())
00166                 {
00167                         case $this->course_obj->SUBSCRIPTION_DIRECT:
00168                                 
00169                                 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00170 
00171                                 if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00172                                 {
00173                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00174                                         ilObjUser::updateActiveRoles($this->user_id);
00175                                         sendInfo($this->lng->txt("crs_subscription_successful"),true);
00176                                         
00177                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00178                                 }
00179                                 else
00180                                 {
00181                                         sendInfo("err_unknown_error");
00182                                         $this->showRegistrationForm();
00183                                 }
00184                                 break;
00185 
00186                         case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00187 
00188                                 if($this->course_obj->members_obj->addSubscriber($this->user_id))
00189                                 {
00190                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_SUBSCRIPTION_REQUEST,
00191                                                                                                                                          $this->user_id);
00192                                         sendInfo($this->lng->txt("crs_subscription_requested"),true);
00193                                         $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00194 
00195                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00196                                 }
00197                                 else
00198                                 {
00199                                         sendInfo("err_unknown_error");
00200                                         $this->showRegistrationForm();
00201                                 }
00202                                 break;
00203 
00204                         case $this->course_obj->SUBSCRIPTION_PASSWORD:
00205 
00206                                 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00207 
00208                                 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00209                                 {
00210                                         sendInfo($this->lng->txt("crs_password_not_valid"),true);
00211                                         $this->showRegistrationForm();
00212                                 }
00213                                 else if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00214                                 {
00215                                         $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00216                                         ilObjUser::updateActiveRoles($this->user_id);
00217                                         sendInfo($this->lng->txt("crs_subscription_successful"),true);
00218 
00219                                         ilUtil::redirect('repository.php?ref_id='.$this->tree->getParentId($this->course_id));
00220                                 }
00221                                 else
00222                                 {
00223                                         sendInfo("err_unknown_error");
00224                                         $this->showRegistrationForm();
00225                                 }
00226                                 break;
00227                 }
00228         }
00229 
00230         function showRegistrationForm()
00231         {
00232                 $really_submit = true;
00233                 if($this->validation)
00234                 {
00235                         $really_submit = $this->__validateStatus();
00236                 }
00237 
00238                 if($this->course_obj->getMessage())
00239                 {
00240                         sendInfo($this->course_obj->getMessage());
00241                 }
00242 
00243                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_subscription.html","course");
00244                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormActionByClass("ilObjCourseGUI"));
00245                 
00246                 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_crs.gif"));
00247                 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_crs"));
00248                 $this->tpl->setVariable("TITLE",$this->lng->txt("crs_registration"));
00249 
00250                 if(strlen($this->course_obj->getSyllabus()))
00251                 {
00252                         $this->tpl->setVariable("TXT_SYLLABUS",$this->lng->txt("crs_syllabus"));
00253                         $this->tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus()));
00254                 }
00255 
00256                 $this->tpl->setVariable("TXT_INFO_REG",$this->lng->txt("crs_info_reg"));
00257 
00258 
00259                 // Waiting list
00260                 if($this->course_obj->getSubscriptionMaxMembers() and $this->course_obj->enabledWaitingList())
00261                 {
00262                         $this->tpl->setCurrentBlock("waiting_list");
00263                         $this->tpl->setVariable("TXT_WAITING_LIST",$this->lng->txt('crs_free_places'));
00264 
00265                         $free_places = $this->course_obj->getSubscriptionMaxMembers() - 
00266                                 $this->course_obj->members_obj->getCountMembers() -
00267                                 $this->course_obj->members_obj->getCountSubscribers();
00268 
00269                         $free_places = $free_places >= 0 ? $free_places : 0;
00270                         $this->tpl->setVariable("FREE_PLACES",$free_places);
00271                         $this->tpl->parseCurrentBlock();
00272 
00273                         if($this->waiting_list->isOnList($this->user_id))
00274                         {
00275                                 $this->tpl->setCurrentBlock("waiting_list_info");
00276                                 $this->tpl->setVariable("TXT_WAITING_LIST_INFO",$this->lng->txt('crs_youre_position'));
00277                                 $this->tpl->setVariable("POSITION",$this->waiting_list->getPosition($this->user_id));
00278                                 $this->tpl->parseCurrentBlock();
00279                         }
00280                         else
00281                         {
00282                                 $this->tpl->setCurrentBlock("waiting_list_info");
00283                                 $this->tpl->setVariable("TXT_WAITING_LIST_INFO",$this->lng->txt('crs_persons_on_waiting_list'));
00284                                 $this->tpl->setVariable("POSITION",$this->waiting_list->getCountUsers());
00285                                 $this->tpl->parseCurrentBlock();
00286                         }
00287 
00288                 }
00289                 if($courses = ilObjCourseGrouping::_getGroupingItemsAsString($this->course_obj))
00290                 {
00291                         $this->tpl->setVariable("INFO_REG_PRE",$this->lng->txt('crs_grp_info_reg').$courses.'<br>');
00292                 }
00293 
00294                 if($this->course_obj->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED)
00295                 {
00296                         switch($this->course_obj->getSubscriptionType())
00297                         {
00298                                 case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00299                                         $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_confirmation"));
00300                                         break;
00301                                 case $this->course_obj->SUBSCRIPTION_DIRECT:
00302                                         $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_direct"));
00303                                         break;
00304                                 case $this->course_obj->SUBSCRIPTION_PASSWORD:
00305                                         $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_password"));
00306                                         break;
00307                         }
00308 
00309                         $this->tpl->setCurrentBlock("reg_until");
00310                         $this->tpl->setVariable("TXT_REG_UNTIL",$this->lng->txt("crs_reg_until"));
00311 
00312                         if($this->course_obj->getSubscriptionUnlimitedStatus())
00313                         {
00314                                 $this->tpl->setVariable("REG_UNTIL",$this->lng->txt("crs_unlimited"));
00315                         }
00316                         else if($this->course_obj->getSubscriptionStart() < time())
00317                         {
00318                                 $this->tpl->setVariable("FROM",$this->lng->txt("crs_to"));
00319                                 $this->tpl->setVariable("REG_UNTIL",ilFormat::formatUnixTime($this->course_obj->getSubscriptionEnd(),true));
00320                         }
00321                         else if($this->course_obj->getSubscriptionStart() > time())
00322                         {
00323                                 $this->tpl->setVariable("FROM",$this->lng->txt("crs_from"));
00324                                 $this->tpl->setVariable("REG_UNTIL",ilFormat::formatUnixTime($this->course_obj->getSubscriptionStart(),true));
00325                         }
00326                         $this->tpl->parseCurrentBlock();
00327                 }
00328                 else
00329                 {
00330                         // Deactivated
00331                         $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_deactivated"));
00332                 }
00333 
00334                 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD and
00335                    $this->course_obj->inSubscriptionTime())
00336                 {
00337                         $this->tpl->setCurrentBlock("pass");
00338                         $this->tpl->setVariable("TXT_PASSWORD",$this->lng->txt("crs_access_password"));
00339                         $this->tpl->parseCurrentBlock();
00340                 }
00341 
00342                 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
00343 
00344                 if($really_submit)
00345                 {
00346                         $this->tpl->setCurrentBlock("go");
00347                         $this->tpl->setVariable("CMD_SUBMIT","subscribe");
00348                         if ($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_CONFIRMATION)
00349                         {
00350                                 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("request_membership"));
00351                         }
00352                         else
00353                         {
00354                                 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("join"));
00355                         }
00356                         $this->tpl->parseCurrentBlock();
00357                 }
00358                         
00359 
00360                 return true;
00361         }
00362 
00363 
00364         // PRIVATE
00365         function __initCourseObject()
00366         {
00367                 if(!$this->course_obj =& ilObjectFactory::getInstanceByRefId($this->course_id,false))
00368                 {
00369                         $this->ilErr->raiseError("ilCourseRegisterGUI: cannot create course object",$this->ilErr->MESSAGE);
00370                         exit;
00371                 }
00372                 $this->course_obj->initCourseMemberObject();
00373 
00374                 return true;
00375         }
00376 
00377         function __initWaitingList()
00378         {
00379                 include_once 'course/classes/class.ilCourseWaitingList.php';
00380 
00381                 $this->waiting_list =& new ilCourseWaitingList($this->course_obj->getId());
00382 
00383                 return true;
00384         }
00385 
00386         function __validateStatus()
00387         {
00388                 include_once 'course/classes/class.ilObjCourseGrouping.php';
00389 
00390                 $allow_subscription = true;
00391 
00392                 $this->course_obj->setMessage('');
00393 
00394                 if($this->course_obj->members_obj->isAssigned($this->user_id))
00395                 {
00396                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_assigned"));
00397                         $allow_subscription = false;
00398                 }
00399                 if($this->course_obj->members_obj->isBlocked($this->user_id))
00400                 {
00401                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_blocked"));
00402                         $allow_subscription = false;
00403                 }
00404                 if($this->course_obj->members_obj->isSubscriber($this->user_id))
00405                 {
00406                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_subscribed"));
00407                         $allow_subscription = false;
00408                 }
00409                 if($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
00410                 {
00411                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_deactivated"));
00412                         $allow_subscription = false;
00413 
00414                         return false;
00415                 }
00416                 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00417                    ( time() < $this->course_obj->getSubscriptionStart()))
00418                 {
00419                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_start_later"));
00420                         $allow_subscription = false;
00421                 }
00422                 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00423                    ( time() > $this->course_obj->getSubscriptionEnd()))
00424                 {
00425                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_end_earlier"));
00426                         $allow_subscription = false;
00427                 }
00428                 if(!ilObjCourseGrouping::_checkGroupingDependencies($this->course_obj))
00429                 {
00430                         $allow_subscription = false;
00431                 }
00432                 if($this->waiting_list->isOnList($this->user_id) and $allow_subscription)
00433                 {
00434                         $this->course_obj->appendMessage($this->lng->txt('crs_already_assigned_to_list'));
00435                         $allow_subscription = false;
00436                 }
00437                 elseif($this->course_obj->getSubscriptionMaxMembers() and 
00438                            (($this->course_obj->members_obj->getCountMembers() + $this->course_obj->members_obj->getCountSubscribers()) 
00439                                 >= $this->course_obj->getSubscriptionMaxMembers()) and
00440                            $allow_subscription)
00441                 {
00442                         $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_max_members_reached"));
00443                         if($this->course_obj->enabledWaitingList())
00444                         {
00445                                 $this->course_obj->appendMessage($this->lng->txt('crs_set_on_waiting_list'));
00446                         }
00447                         else
00448                         {
00449                                 $allow_subscription = false;
00450                         }
00451                 }
00452                 elseif($this->waiting_list->getCountUsers() 
00453                            and $allow_subscription
00454                            and $this->course_obj->enabledWaitingList())
00455                 {
00456                         $this->course_obj->appendMessage($this->lng->txt('crs_set_on_waiting_list'));
00457                 }
00458                 return $allow_subscription;
00459         }
00460 
00461 
00462 
00463         function __formatPath($a_path_arr)
00464         {
00465                 $counter = 0;
00466                 foreach($a_path_arr as $data)
00467                 {
00468                         if(!$counter++)
00469                         {
00470                                 continue;
00471                         }
00472                         if($counter++ > 2)
00473                         {
00474                                 $path .= " -> ";
00475                         }
00476                         $path .= $data['title'];
00477                 }
00478 
00479                 return $path;
00480         }
00481 }
00482 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1