00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031 class ilRegisterGUI
00032 {
00033 var $lng;
00034 var $ilias;
00035 var $tpl;
00036 var $tree;
00037 var $objDefinition;
00038 var $ctrl;
00039 var $cmd;
00040 var $ilErr;
00041 var $object;
00042
00047 function ilRegisterGUI()
00048 {
00049 global $lng, $ilias, $tpl, $tree, $objDefinition, $ilCtrl, $ilErr;
00050
00051 $this->lng =& $lng;
00052 $this->lng->loadLanguageModule('crs');
00053
00054 $this->ilias =& $ilias;
00055 $this->tpl =& $tpl;
00056 $this->tree =& $tree;
00057 $this->objDefinition =& $objDefinition;
00058 $this->ilErr =& $ilErr;
00059
00060 $this->ctrl =& $ilCtrl;
00061 $this->ctrl->saveParameter($this,array("ref_id"));
00062 $this->ctrl->setParameter($this,"user_id",$this->ilias->account->getId());
00063
00064
00065 $this->object =& $this->ilias->obj_factory->getInstanceByRefId($_GET["ref_id"]);
00066 }
00067
00071 function &executeCommand()
00072 {
00073 if ($this->isUserAlreadyRegistered())
00074 {
00075 $this->ilErr->raiseError($this->lng->txt("grp_already_applied"),$this->ilErr->MESSAGE);
00076 }
00077
00078 $cmd = $this->ctrl->getCmd();
00079
00080 if (empty($cmd))
00081 {
00082 $cmd = "cancel";
00083 }
00084
00085 $this->cmd = $cmd;
00086 $this->$cmd();
00087 }
00088
00089 function showRegistrationForm()
00090 {
00091 include_once 'Modules/Course/classes/class.ilObjCourseGrouping.php';
00092
00093 global $rbacsystem, $ilias, $lng;
00094
00095 switch ($this->object->getRegistrationFlag())
00096 {
00097 case 0:
00098 $stat = $this->lng->txt("group_no_registration");
00099 $msg = $this->lng->txt("group_no_registration_msg");
00100 $readonly ="readonly";
00101 $subject ="";
00102 $cmd_submit = "subscribe";
00103 $txt_submit = $this->lng->txt("grp_register");
00104 break;
00105
00106 case 1:
00107 if ($this->object->registrationPossible() == true)
00108 {
00109 $stat = $this->lng->txt("group_req_registration");
00110 $msg = $this->lng->txt("group_req_registration_msg");
00111 $cmd_submit = "apply";
00112 $txt_submit = $this->lng->txt("request_membership");
00113 $txt_subject =$this->lng->txt("subject").":";
00114 $textfield = "<textarea name=\"subject\" value=\"{SUBJECT}\" cols=\"50\" rows=\"5\" size=\"255\"></textarea>";
00115 }
00116 else
00117 {
00118 $no_cancel = true;
00119 $msg = $this->lng->txt("group_registration_expired_msg");
00120 $msg_send = "ilias.php?baseClass=ilMailGUI&mobj_id=3&type=new&rcp_to=root";
00121 $cmd_submit = "cancel";
00122 $txt_submit = $this->lng->txt("grp_back");
00123 $readonly = "readonly";
00124 $stat = $this->lng->txt("group_registration_expired");
00125 ilUtil::sendInfo($this->lng->txt("registration_expired"));
00126 }
00127 break;
00128
00129 case 2:
00130 if ($this->object->registrationPossible() == true)
00131 {
00132 $stat = $this->lng->txt("group_req_password");
00133 $msg = $this->lng->txt("group_password_registration_msg");
00134 $txt_subject =$this->lng->txt("password").":";
00135 $txt_submit = $this->lng->txt("grp_register");
00136 $textfield = "<input name=\"subject\" value=\"{SUBJECT}\" type=\"password\" size=\"40\" maxlength=\"70\" style=\"width:300px;\"/>";
00137 $cmd_submit = "apply";
00138 }
00139 else
00140 {
00141 $no_cancel = true;
00142 $msg = $this->lng->txt("group_registration_expired_msg");
00143 $msg_send = "ilias.php?baseClass=ilMailGUI&mobj_id=3&type=new&rcp_to=root";
00144 $cmd_submit = "cancel";
00145 $txt_submit = $this->lng->txt("grp_back");
00146 $readonly = "readonly";
00147 $stat = $this->lng->txt("group_registration_expired");
00148 ilUtil::sendInfo($this->lng->txt("registration_expired"));
00149 }
00150 break;
00151 }
00152
00153 if ($no_cancel !== true)
00154 {
00155 $this->tpl->setCurrentBlock("btn_cancel");
00156 $this->tpl->setVariable("CMD_CANCEL","cancel");
00157 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
00158 $this->tpl->parseCurrentBlock();
00159 }
00160
00161 if(!$rbacsystem->checkAccess("join", $_GET["ref_id"]))
00162 {
00163 $ilias->raiseError($lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
00164 return;
00165 }
00166
00167 $submit_btn = true;
00168 if(!ilObjCourseGrouping::_checkGroupingDependencies($this->object))
00169 {
00170 ilUtil::sendInfo($this->object->getMessage());
00171 $submit_btn = false;
00172 }
00173
00174 $this->tpl->addBlockFile("ADM_CONTENT", "tbldesc", "tpl.grp_accessdenied.html");
00175 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_grp.gif"));
00176 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_grp"));
00177 $this->tpl->setVariable("TITLE",$this->lng->txt("grp_registration"));
00178 $this->tpl->setVariable("TXT_MESSAGE",$msg);
00179 $this->tpl->setVariable("TXT_GRP_NAME", $this->lng->txt("group_name"));
00180 $this->tpl->setVariable("GRP_NAME",$this->object->getTitle());
00181 $this->tpl->setVariable("TXT_GRP_DESC",$this->lng->txt("group_desc"));
00182 $this->tpl->setVariable("GRP_DESC",$this->object->getDescription());
00183
00184
00185
00186
00187 $this->tpl->setVariable("TXT_INFO_REG",$this->lng->txt("group_info_reg"));
00188 $this->tpl->setVariable("INFO_REG", $msg);
00189
00190 if(strlen($txt_subject))
00191 {
00192 $this->tpl->setVariable("TXT_SUBJECT",$txt_subject);
00193 $this->tpl->setVariable("SUBJECT",$textfield);
00194 }
00195 if(strlen($message = ilObjCourseGrouping::_getGroupingItemsAsString($this->object)))
00196 {
00197 $this->tpl->setVariable("TXT_MEMBER_LIMIT",$this->lng->txt('groupings'));
00198 $this->tpl->setVariable("MEMBER_LIMIT",$this->lng->txt('crs_grp_info_reg').$message);
00199 }
00200
00201 if($submit_btn)
00202 {
00203 $this->tpl->setVariable("TXT_SUBMIT",$txt_submit);
00204 $this->tpl->setVariable("CMD_SUBMIT",$cmd_submit);
00205 }
00206 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this,'apply'));
00207 $this->tpl->parseCurrentBlock();
00208 }
00209
00210 function cancel()
00211 {
00212 ilUtil::sendInfo($this->lng->txt("action_aborted"),true);
00213
00214
00215 ilUtil::redirect("repository.php?ref_id=".$this->getReturnRefId());
00216 }
00217
00218 function subscribe()
00219 {
00220 if (!$this->object->addMember($this->ilias->account->getId(), $this->object->getDefaultMemberRole()))
00221 {
00222 $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00223 }
00224
00225 $this->ilias->account->addDesktopItem($this->object->getRefId(),"grp");
00226
00227 ilUtil::sendInfo($this->lng->txt("grp_registration_completed"),true);
00228 $this->ctrl->returnToParent($this);
00229 }
00230
00231 function apply()
00232 {
00233 global $ilDB;
00234
00235
00236
00237 switch ($this->object->getRegistrationFlag())
00238 {
00239
00240 case 1:
00241 $q = "INSERT INTO grp_registration VALUES (".
00242 $ilDB->quote($this->object->getId()).",".
00243 $ilDB->quote($this->ilias->account->getId()).",".
00244 $ilDB->quote($_POST["subject"]).",".
00245 $ilDB->quote(date("Y-m-d H:i:s")).")";
00246 $this->ilias->db->query($q);
00247
00248 ilUtil::sendInfo($this->lng->txt("application_completed"),true);
00249 ilUtil::redirect("repository.php?ref_id=".$this->getReturnRefId());
00250 break;
00251
00252
00253 case 2:
00254 if (strcmp($this->object->getPassword(),$_POST["subject"]) == 0 && $this->object->registrationPossible() == true)
00255 {
00256 $this->object->addMember($this->ilias->account->getId(),$this->object->getDefaultMemberRole());
00257
00258 $this->ilias->account->addDesktopItem($this->object->getRefId(),"grp");
00259
00260 ilUtil::sendInfo($this->lng->txt("grp_registration_completed"),true);
00261 $this->ctrl->returnToParent($this);
00262 }
00263
00264
00265 ilUtil::sendInfo($this->lng->txt("err_wrong_password"),true);
00266 $this->ctrl->returnToParent($this);
00267
00268
00269 break;
00270
00271 default:
00272 $this->ilErr->raiseError($this->lng->txt("err_unknown_error"),$this->ilErr->MESSAGE);
00273 break;
00274 }
00275 }
00276
00277 function getReturnRefId()
00278 {
00279 if ($_SESSION["il_rep_ref_id"] == $this->object->getRefId())
00280 {
00281 return $this->tree->getParentId($this->object->getRefId());
00282 }
00283 else
00284 {
00285 return $_SESSION["il_rep_ref_id"];
00286 }
00287 }
00288
00289 function isUserAlreadyRegistered ()
00290 {
00291 global $ilDB;
00292
00293
00294
00295 $q = "SELECT * FROM grp_registration WHERE grp_id=".
00296 $ilDB->quote($this->object->getId())." AND user_id=".
00297 $ilDB->quote($this->ilias->account->getId());
00298 $res = $this->ilias->db->query($q);
00299
00300 if ($res->numRows() > 0)
00301 {
00302 return true;
00303 }
00304
00305 return false;
00306 }
00307 }
00308 ?>