Go to the documentation of this file.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 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
00025 include_once('Modules/Course/classes/class.ilCourseAgreement.php');
00026 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
00027 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00028
00038 class ilCourseAgreementGUI
00039 {
00040 private $ref_id;
00041 private $obj_id;
00042
00043 private $db;
00044 private $ctrl;
00045 private $lng;
00046 private $tpl;
00047
00048 private $privacy;
00049 private $agreement;
00050
00057 public function __construct($a_ref_id)
00058 {
00059 global $ilDB,$ilCtrl,$lng,$tpl,$ilUser,$ilObjDataCache;
00060
00061 $this->ref_id = $a_ref_id;
00062 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
00063 $this->ctrl = $ilCtrl;
00064 $this->tpl = $tpl;
00065 $this->lng = $lng;
00066 $this->lng->loadLanguageModule('ps');
00067
00068 $this->privacy = ilPrivacySettings::_getInstance();
00069 $this->agreement = new ilCourseAgreement($ilUser->getId(),$this->obj_id);
00070 $this->init();
00071 }
00072
00079 public function executeCommand()
00080 {
00081 $next_class = $this->ctrl->getNextClass($this);
00082 $cmd = $this->ctrl->getCmd();
00083
00084 switch($next_class)
00085 {
00086 default:
00087 if(!$cmd)
00088 {
00089 $cmd = 'showAgreement';
00090 }
00091 $this->$cmd();
00092 break;
00093 }
00094 }
00095
00102 private function showAgreement($send_info = true)
00103 {
00104
00105 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.crs_user_agreement.html','Modules/Course');
00106 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00107
00108 if($send_info)
00109 {
00110 $this->sendInfoMessage();
00111 }
00112 $this->showCourseDefinedFields();
00113
00114 include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
00115 $fields_info = ilExportFieldsInfo::_getInstance();
00116
00117 foreach($fields_info->getExportableFields() as $field)
00118 {
00119 $this->tpl->setCurrentBlock('field');
00120 $this->tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
00121 $this->tpl->parseCurrentBlock();
00122 }
00123
00124 $this->tpl->setVariable('AGREEMENT_HEADER',$this->lng->txt('crs_agreement_header'));
00125 $this->tpl->setVariable('TXT_AGREEMENT',$this->lng->txt('crs_user_agreement'));
00126 $this->tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt('crs_info_agreement'));
00127
00128 if($this->privacy->confirmationRequired() or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
00129 {
00130 $this->tpl->setCurrentBlock('agreement');
00131 $this->tpl->setVariable('CHECK_AGREE',ilUtil::formCheckbox(0,'agreed',1));
00132 $this->tpl->setVariable('INFO_AGREE',$this->lng->txt('crs_info_agree'));
00133 $this->tpl->setVariable('TXT_AGREE',$this->lng->txt('crs_agree'));
00134 $this->tpl->parseCurrentBlock();
00135 }
00136 $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
00137 }
00138
00146 private function save()
00147 {
00148 if(!$this->checkCourseDefinedFields())
00149 {
00150 ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
00151 $this->showAgreement(false);
00152 return false;
00153 }
00154 if(!$this->checkAgreement())
00155 {
00156 ilUtil::sendInfo($this->lng->txt('crs_agreement_required'));
00157 $this->showAgreement(false);
00158 return false;
00159 }
00160 $this->agreement->setAccepted(true);
00161 $this->agreement->setAcceptanceTime(time());
00162 $this->agreement->save();
00163
00164 $this->ctrl->returnToParent($this);
00165 }
00166
00167 private function showCourseDefinedFields()
00168 {
00169 global $ilUser;
00170
00171 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00172 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
00173
00174 if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id)))
00175 {
00176 return true;
00177 }
00178
00179 foreach($cdf_fields as $field_obj)
00180 {
00181 $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
00182
00183 switch($field_obj->getType())
00184 {
00185 case IL_CDF_TYPE_SELECT:
00186 $this->tpl->setCurrentBlock('sel_row');
00187 $this->tpl->setVariable('SEL_SELECT',ilUtil::formSelect($course_user_data->getValue(),
00188 'cdf['.$field_obj->getId().']',
00189 $field_obj->prepareSelectBox(),
00190 false,
00191 true));
00192 break;
00193 case IL_CDF_TYPE_TEXT:
00194 $this->tpl->setCurrentBlock('txt_row');
00195 $this->tpl->setVariable('TXT_ROW_NAME',$field_obj->getId());
00196 $this->tpl->setVariable('TXT_ROW_VALUE',$course_user_data->getValue());
00197 break;
00198 }
00199 if($field_obj->isRequired())
00200 {
00201 $this->show_required_info = true;
00202 $this->tpl->touchBlock('cdf_required');
00203 }
00204
00205 $this->tpl->setCurrentBlock('cdf_row');
00206 $this->tpl->setVariable('CDF_FIELD_NAME',$field_obj->getName());
00207 $this->tpl->parseCurrentBlock();
00208 }
00209 $this->tpl->setCurrentBlock('cdf');
00210 $this->tpl->setVariable('CDF_TXT',$this->lng->txt('ps_cdf_info'));
00211 $this->tpl->parseCurrentBlock();
00212 }
00213
00220 private function checkCourseDefinedFields()
00221 {
00222 global $ilUser;
00223
00224 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00225 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
00226
00227 $all_required = true;
00228 foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
00229 {
00230 switch($field_obj->getType())
00231 {
00232 case IL_CDF_TYPE_SELECT:
00233 $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
00234 break;
00235
00236 case IL_CDF_TYPE_TEXT:
00237 $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
00238 break;
00239 }
00240 $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
00241 $course_user_data->setValue($value);
00242 $course_user_data->update();
00243
00244 if($field_obj->isRequired() and !strlen($value))
00245 {
00246 $all_required = false;
00247 }
00248 }
00249 return $all_required;
00250 }
00251
00252
00259 private function checkAgreement()
00260 {
00261 global $ilUser;
00262
00263 if($_POST['agreed'])
00264 {
00265 return true;
00266 }
00267 if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
00268 {
00269 return true;
00270 }
00271 return false;
00272 }
00273
00274
00275
00283 private function init()
00284 {
00285 global $ilUser;
00286
00287 $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
00288 $this->agreement_required = $this->agreement->agreementRequired();
00289 }
00290
00296 private function sendInfoMessage()
00297 {
00298 $message = '';
00299 if($this->agreement_required)
00300 {
00301 $message = $this->lng->txt('ps_agreement_req_info');
00302 }
00303 if(!$this->required_fullfilled)
00304 {
00305 if(strlen($message))
00306 {
00307 $message .= '<br />';
00308 }
00309 $message .= $this->lng->txt('ps_required_info');
00310 }
00311
00312 if(strlen($message))
00313 {
00314 ilUtil::sendInfo($message);
00315 }
00316 }
00317 }
00318
00319
00320 ?>