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 switch($cmd = $this->ctrl->getCmd())
00072 {
00073 case 'archive':
00074 case '':
00075 $cmd = "showRegistrationForm";
00076 break;
00077 }
00078 $this->$cmd();
00079 }
00080
00081 function cancel()
00082 {
00083 sendInfo($this->lng->txt("action_aborted"),true);
00084
00085 $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00086 $this->ctrl->redirectByClass("ilRepositoryGUI","ShowList");
00087
00088 }
00089
00090 function subscribe()
00091 {
00092 switch($this->course_obj->getSubscriptionType())
00093 {
00094 case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00095 $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00096 exit;
00097
00098 case $this->course_obj->SUBSCRIPTION_DIRECT:
00099
00100 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00101
00102 if($this->course_obj->members_obj->add($tmp_obj,$this->course_obj->members_obj->ROLE_MEMBER))
00103 {
00104 $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00105 ilObjUser::updateActiveRoles($this->user_id);
00106 sendInfo($this->lng->txt("crs_subscription_successful"),true);
00107 $this->ctrl->returnToParent($this);
00108 }
00109 else
00110 {
00111 sendInfo("err_unknown_error");
00112 $this->showRegistrationForm();
00113 }
00114 break;
00115
00116 case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00117
00118 if($this->course_obj->members_obj->addSubscriber($this->user_id))
00119 {
00120 $this->course_obj->members_obj->sendNotification($this->course_obj->members_obj->NOTIFY_ADMINS,$this->user_id);
00121 sendInfo($this->lng->txt("crs_subscription_successful"),true);
00122 $this->ctrl->setParameterByClass("ilRepositoryGUI","ref_id",$this->tree->getParentId($this->course_id));
00123 $this->ctrl->redirectByClass("ilRepositoryGUI","ShowList");
00124 }
00125 else
00126 {
00127 sendInfo("err_unknown_error");
00128 $this->showRegistrationForm();
00129 }
00130 break;
00131
00132 case $this->course_obj->SUBSCRIPTION_PASSWORD:
00133
00134 $tmp_obj =& ilObjectFactory::getInstanceByObjId($this->user_id);
00135
00136 if($this->course_obj->getSubscriptionPassword() != $_POST["password"])
00137 {
00138 sendInfo($this->lng->txt("crs_password_not_valid"),true);
00139 $this->showRegistrationForm();
00140 }
00141 else 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 $this->ctrl->returnToParent($this);
00147 }
00148 else
00149 {
00150 sendInfo("err_unknown_error");
00151 $this->showRegistrationForm();
00152 }
00153 break;
00154 }
00155 }
00156
00157 function showRegistrationForm()
00158 {
00159 $really_submit = $this->__validateStatus();
00160
00161 if($this->course_obj->getMessage())
00162 {
00163 sendInfo($this->course_obj->getMessage());
00164 }
00165
00166 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_subscription.html","course");
00167 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormActionByClass("ilObjCourseGUI"));
00168
00169 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_crs.gif"));
00170 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_crs"));
00171 $this->tpl->setVariable("TITLE",$this->lng->txt("crs_registration"));
00172
00173 $this->tpl->setVariable("TXT_SYLLABUS",$this->lng->txt("crs_syllabus"));
00174 $this->tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus()));
00175
00176 $this->tpl->setVariable("TXT_INFO_REG",$this->lng->txt("crs_info_reg"));
00177
00178 if($courses = $this->__getGroupingCourses())
00179 {
00180 $this->tpl->setVariable("INFO_REG_PRE",$this->lng->txt('crs_grp_info_reg').$courses.'<br>');
00181 }
00182
00183 switch($this->course_obj->getSubscriptionType())
00184 {
00185 case $this->course_obj->SUBSCRIPTION_DEACTIVATED:
00186 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_deactivated"));
00187 break;
00188 case $this->course_obj->SUBSCRIPTION_CONFIRMATION:
00189 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_confirmation"));
00190 break;
00191 case $this->course_obj->SUBSCRIPTION_DIRECT:
00192 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_direct"));
00193 break;
00194 case $this->course_obj->SUBSCRIPTION_PASSWORD:
00195 $this->tpl->setVariable("INFO_REG",$this->lng->txt("crs_info_reg_password"));
00196 break;
00197 }
00198
00199 if($this->course_obj->getSubscriptionType() != $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00200 {
00201 $this->tpl->setCurrentBlock("reg_until");
00202 $this->tpl->setVariable("TXT_REG_UNTIL",$this->lng->txt("crs_reg_until"));
00203
00204 if($this->course_obj->getSubscriptionUnlimitedStatus())
00205 {
00206 $this->tpl->setVariable("REG_UNTIL",$this->lng->txt("crs_unlimited"));
00207 }
00208 else if($this->course_obj->getSubscriptionStart() < time())
00209 {
00210 $this->tpl->setVariable("FROM",$this->lng->txt("crs_to"));
00211 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionEnd()));
00212 }
00213 else if($this->course_obj->getSubscriptionStart() > time())
00214 {
00215 $this->tpl->setVariable("FROM",$this->lng->txt("crs_from"));
00216 $this->tpl->setVariable("REG_UNTIL",strftime("%c",$this->course_obj->getSubscriptionStart()));
00217 }
00218 $this->tpl->parseCurrentBlock();
00219 }
00220
00221 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_PASSWORD and
00222 $this->course_obj->inSubscriptionTime())
00223 {
00224 $this->tpl->setCurrentBlock("pass");
00225 $this->tpl->setVariable("TXT_PASSWORD",$this->lng->txt("crs_access_password"));
00226 $this->tpl->parseCurrentBlock();
00227 }
00228
00229 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
00230
00231 if($really_submit)
00232 {
00233 $this->tpl->setCurrentBlock("go");
00234 $this->tpl->setVariable("CMD_SUBMIT","subscribe");
00235 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("register"));
00236 $this->tpl->parseCurrentBlock();
00237 }
00238
00239
00240 return true;
00241 }
00242
00243
00244
00245 function __initCourseObject()
00246 {
00247 if(!$this->course_obj =& ilObjectFactory::getInstanceByRefId($this->course_id,false))
00248 {
00249 $this->ilErr->raiseError("ilCourseRegisterGUI: cannot create course object",$this->ilErr->MESSAGE);
00250 exit;
00251 }
00252 $this->course_obj->initCourseMemberObject();
00253
00254 return true;
00255 }
00256
00257 function __validateStatus()
00258 {
00259 $this->course_obj->setMessage('');
00260
00261 if($this->course_obj->members_obj->isAssigned($this->user_id))
00262 {
00263 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_assigned"));
00264 }
00265 if($this->course_obj->members_obj->isBlocked($this->user_id))
00266 {
00267 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_blocked"));
00268 }
00269 if($this->course_obj->members_obj->isSubscriber($this->user_id))
00270 {
00271 $this->course_obj->appendMessage($this->lng->txt("crs_reg_user_already_subscribed"));
00272 }
00273 if($this->course_obj->getSubscriptionType() == $this->course_obj->SUBSCRIPTION_DEACTIVATED)
00274 {
00275 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_deactivated"));
00276 }
00277 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00278 ( time() < $this->course_obj->getSubscriptionStart()))
00279 {
00280 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_start_later"));
00281 }
00282 if(!$this->course_obj->getSubscriptionUnlimitedStatus() and
00283 ( time() > $this->course_obj->getSubscriptionEnd()))
00284 {
00285 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_end_earlier"));
00286 }
00287 if($this->course_obj->getSubscriptionMaxMembers() and
00288 ($this->course_obj->members_obj->getCountMembers() >= $this->course_obj->getSubscriptionMaxMembers()))
00289 {
00290 $this->course_obj->appendMessage($this->lng->txt("crs_reg_subscription_max_members_reached"));
00291 }
00292 $this->__checkGroupingDependencies();
00293
00294 return $this->course_obj->getMessage() ? false : true;
00295 }
00296 function __checkGroupingDependencies()
00297 {
00298 global $ilUser;
00299
00300 include_once './classes/class.ilConditionHandler.php';
00301 include_once './course/classes/class.ilCourseMembers.php';
00302
00303 $trigger_ids = array();
00304 foreach(ilConditionHandler::_getConditionsOfTarget($this->course_obj->getId(),'crs') as $condition)
00305 {
00306 if($condition['operator'] == 'not_member')
00307 {
00308 $trigger_ids[] = $condition['trigger_obj_id'];
00309 break;
00310 }
00311 }
00312 if(!count($trigger_ids))
00313 {
00314 return false;
00315 }
00316
00317 foreach($trigger_ids as $trigger_id)
00318 {
00319 foreach(ilConditionHandler::_getConditionsOfTrigger('crsg',$trigger_id) as $condition)
00320 {
00321 if($condition['operator'] == 'not_member')
00322 {
00323 switch($condition['value'])
00324 {
00325 case 'matriculation':
00326 if(!strlen($ilUser->getMatriculation()))
00327 {
00328 if(!$matriculation_message)
00329 {
00330 $matriculation_message = $this->lng->txt('crs_grp_matriculation_required');
00331 }
00332 }
00333 }
00334 if(ilCourseMembers::_isMember($ilUser->getId(),$condition['target_obj_id'],$condition['value']))
00335 {
00336 if(!$assigned_message)
00337 {
00338 $assigned_message = $this->lng->txt('crs_grp_already_assigned');
00339 }
00340 }
00341 }
00342 }
00343 }
00344 if($matriculation_message)
00345 {
00346 $this->course_obj->appendMessage($matriculation_message);
00347 }
00348 elseif($assigned_message)
00349 {
00350 $this->course_obj->appendMessage($assigned_message);
00351 }
00352 return false;
00353 }
00354 function __getGroupingCourses()
00355 {
00356 global $tree;
00357
00358 include_once './classes/class.ilConditionHandler.php';
00359 include_once './course/classes/class.ilCourseMembers.php';
00360
00361 $trigger_ids = array();
00362 foreach(ilConditionHandler::_getConditionsOfTarget($this->course_obj->getId(),'crs') as $condition)
00363 {
00364 if($condition['operator'] == 'not_member')
00365 {
00366 $trigger_ids[] = $condition['trigger_obj_id'];
00367 }
00368 }
00369 if(!count($trigger_ids))
00370 {
00371 return false;
00372 }
00373 foreach($trigger_ids as $trigger_id)
00374 {
00375 foreach(ilConditionHandler::_getConditionsOfTrigger('crsg',$trigger_id) as $condition)
00376 {
00377 if($condition['operator'] == 'not_member')
00378 {
00379 if(!$hash_table[$condition['target_ref_id']])
00380 {
00381 $tmp_obj =& ilObjectFactory::getInstanceByRefId($condition['target_ref_id']);
00382 $courses .= (' <br/>'.$this->__formatPath($tree->getPathFull($tmp_obj->getRefId())));
00383 }
00384 $hash_table[$condition['target_ref_id']] = true;
00385 }
00386 }
00387 }
00388 return $courses;
00389 }
00390
00391 function __formatPath($a_path_arr)
00392 {
00393 $counter = 0;
00394 foreach($a_path_arr as $data)
00395 {
00396 if($counter++)
00397 {
00398 $path .= " -> ";
00399 }
00400 $path .= $data['title'];
00401 }
00402
00403 if(strlen($path) > 40)
00404 {
00405 return '...'.substr($path,-40);
00406 }
00407 return $path;
00408 }
00409 }
00410 ?>