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