00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 function ilCourseRegisterGUI($a_course_id)
00049 {
00050 global $ilCtrl,$lng,$ilErr,$ilias,$tpl,$tree;
00051
00052 $this->ctrl =& $ilCtrl;
00053 $this->ctrl->saveParameter($this,array("ref_id"));
00054
00055 $this->ilErr =& $ilErr;
00056 $this->lng =& $lng;
00057 $this->tpl =& $tpl;
00058 $this->tree =& $tree;
00059
00060 $this->user_id = $ilias->account->getId();
00061
00062 $this->course_id = $a_course_id;
00063 $this->__initCourseObject();
00064 }
00065
00069 function &executeCommand()
00070 {
00071 $cmd = $this->ctrl->getCmd();
00072
00073 if (!$cmd = $this->ctrl->getCmd())
00074 {
00075 $cmd = "showRegistrationForm";
00076 }
00077 $this->$cmd();
00078 }
00079
00080 function cancel()
00081 {
00082 sendInfo($this->lng->txt("action_aborted"),true);
00083
00084 $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00085 $this->ctrl->redirectByClass("ilRepositoryGUI","ShowList");
00086
00087 }
00088
00089 function subscribe()
00090 {
00091 switch($this->course_obj->getSubscriptionType())
00092 {
00093 case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00094 $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00095 exit;
00096
00097 case $this->course_obj->SUBSCRIPTION_DIRECT:
00098
00099 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00100
00101 if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00102 {
00103 $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00104 ilObjUser::updateActiveRoles($this->user_id);
00105 sendInfo($this->lng->txt("crs_subscription_successful"),true);
00106 $this->ctrl->returnToParent($this);
00107 }
00108 else
00109 {
00110 sendInfo("err_unknown_error");
00111 $this->showRegistrationForm();
00112 }
00113 break;
00114
00115 case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00116
00117 if($this->course_obj->members_obj->addSubscriber($this->user_id))
00118 {
00119 $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00120 sendInfo($this->lng->txt("crs_subscription_successful"),true);
00121 $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00122 $this->ctrl->redirectByClass("ilRepositoryGUI","ShowList");
00123 }
00124 else
00125 {
00126 sendInfo("err_unknown_error");
00127 $this->showRegistrationForm();
00128 }
00129 break;
00130
00131 case $this->course_obj->SUBSCRIPTION_PASSWORD:
00132
00133 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00134
00135 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00136 {
00137 sendInfo($this->lng->txt("crs_password_not_valid"),true);
00138 $this->showRegistrationForm();
00139 }
00140 else if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00141 {
00142 $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00143 ilObjUser::updateActiveRoles($this->user_id);
00144 sendInfo($this->lng->txt("crs_subscription_successful"),true);
00145 $this->ctrl->returnToParent($this);
00146 }
00147 else
00148 {
00149 sendInfo("err_unknown_error");
00150 $this->showRegistrationForm();
00151 }
00152 break;
00153 }
00154 }
00155
00156 function showRegistrationForm()
00157 {
00158 $really_submit = $this->__validateStatus();
00159
00160 if($this->course_obj->getMessage())
00161 {
00162 sendInfo($this->course_obj->getMessage());
00163 }
00164
00165 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_subscription.html","course");
00166 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormActionByClass("ilObjCourseGUI"));
00167
00168 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_crs.gif"));
00169 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_crs"));
00170 $this->tpl->setVariable("TITLE",$this->lng->txt("crs_registration"));
00171
00172 $this->tpl->setVariable("TXT_SYLLABUS",$this->lng->txt("crs_syllabus"));
00173 $this->tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus()));
00174
00175 $this->tpl->setVariable("TXT_INFO_REG",$this->lng->txt("crs_info_reg"));
00176
00177 switch($this->course_obj->getSubscriptionType())
00178 {
00179 case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00180 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_deactivated"));
00181 break;
00182 case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00183 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_confirmation"));
00184 break;
00185 case $this->course_obj->SUBSCRIPTION_DIRECT:
00186 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_direct"));
00187 break;
00188 case $this->course_obj->SUBSCRIPTION_PASSWORD:
00189 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_password"));
00190 break;
00191 }
00192
00193 if($this->course_obj->getSubscriptionType() != $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00194 {
00195 $this->tpl->setCurrentBlock("reg_until");
00196 $this->tpl->setVariable("TXT_REG_UNTIL",$this->lng->txt("crs_reg_until"));
00197
00198 if($this->course_obj->getSubscriptionUnlimitedStatus())
00199 {
00200 $this->tpl->setVariable("REG_UNTIL",$this->lng->txt("crs_unlimited"));
00201 }
00202 else if($this->course_obj->getSubscriptionStart() < time())
00203 {
00204 $this->tpl->setVariable("FROM",$this->lng->txt("crs_to"));
00205 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionEnd()));
00206 }
00207 else if($this->course_obj->getSubscriptionStart() > time())
00208 {
00209 $this->tpl->setVariable("FROM",$this->lng->txt("crs_from"));
00210 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionStart()));
00211 }
00212 $this->tpl->parseCurrentBlock();
00213 }
00214
00215 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD and
00216 $this->course_obj->inSubscriptionTime())
00217 {
00218 $this->tpl->setCurrentBlock("pass");
00219 $this->tpl->setVariable("TXT_PASSWORD",$this->lng->txt("crs_access_password"));
00220 $this->tpl->parseCurrentBlock();
00221 }
00222
00223 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
00224
00225 if($really_submit)
00226 {
00227 $this->tpl->setCurrentBlock("go");
00228 $this->tpl->setVariable("CMD_SUBMIT","subscribe");
00229 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("register"));
00230 $this->tpl->parseCurrentBlock();
00231 }
00232
00233
00234 return true;
00235 }
00236
00237
00238
00239 function __initCourseObject()
00240 {
00241 if(!$this->course_obj =& ilObjectFactory::getInstanceByRefId($this->course_id,false))
00242 {
00243 $this->ilErr->raiseError("ilCourseRegisterGUI: cannot create course object",$this->ilErr->MESSAGE);
00244 exit;
00245 }
00246 $this->course_obj->initCourseMemberObject();
00247
00248 return true;
00249 }
00250
00251 function __validateStatus()
00252 {
00253 $this->course_obj->setMessage('');
00254
00255 if($this->course_obj->members_obj->isAssigned($this->user_id))
00256 {
00257 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_assigned"));
00258 }
00259 if($this->course_obj->members_obj->isBlocked($this->user_id))
00260 {
00261 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_blocked"));
00262 }
00263 if($this->course_obj->members_obj->isSubscriber($this->user_id))
00264 {
00265 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_subscribed"));
00266 }
00267 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00268 {
00269 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_deactivated"));
00270 }
00271 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00272 ( time() < $this->course_obj->getSubscriptionStart()))
00273 {
00274 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_start_later"));
00275 }
00276 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00277 ( time() > $this->course_obj->getSubscriptionEnd()))
00278 {
00279 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_end_earlier"));
00280 }
00281 if($this->course_obj->getSubscriptionMaxMembers() and
00282 ($this->course_obj->members_obj->getCountMembers() >= $this->course_obj->getSubscriptionMaxMembers()))
00283 {
00284 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_max_members_reached"));
00285 }
00286
00287 return $this->course_obj->getMessage() ? false : true;
00288 }
00289 }
00290 ?>