00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 require_once "./classes/class.ilObjectGUI.php";
00035
00036 class ilObjCourseGroupingGUI
00037 {
00038 var $crs_obj;
00039 var $tpl;
00040 var $ctrl;
00041 var $lng;
00042
00047 function ilObjCourseGroupingGUI(&$crs_obj,$a_obj_id = 0)
00048 {
00049 global $tpl,$ilCtrl,$lng;
00050
00051 $this->tpl =& $tpl;
00052 $this->ctrl =& $ilCtrl;
00053 $this->lng =& $lng;
00054
00055 $this->type = "crsg";
00056 $this->crs_obj =& $crs_obj;
00057
00058 $this->id = $a_obj_id;
00059 $this->ctrl->saveParameter($this,'obj_id');
00060
00061 $this->__initGroupingObject();
00062
00063 }
00064
00065 function create()
00066 {
00067 $options = array('login' => 'login',
00068 'email' => 'email',
00069 'matriculation' => 'matriculation');
00070
00071
00072 $title = ilUtil::prepareFormOutput($_POST["title"],true);
00073 $desc = ilUtil::stripSlashes($_POST["description"]);
00074 $unique = $_POST['unique'] ? $_POST['unique'] : 'login';
00075
00076 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_add.html","course");
00077
00078 $this->tpl->setVariable("TITLE",$title);
00079 $this->tpl->setVariable("DESC",$desc);
00080 $this->tpl->setVariable("UNAM_SELECT",ilUtil::formSelect($unique,'unique',$options));
00081
00082 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00083 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('crs_add_grouping'));
00084 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt('title'));
00085 $this->tpl->setVariable("TXT_DESC",$this->lng->txt('description'));
00086 $this->tpl->setVariable("TXT_UNAM",$this->lng->txt('unambiguousness'));
00087 $this->tpl->setVariable("TXT_REQUIRED_FLD",$this->lng->txt('required'));
00088 $this->tpl->setVariable("CMD_SUBMIT",'add');
00089 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt('add'));
00090 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00091 }
00092
00093 function cancel()
00094 {
00095 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00096 }
00097
00098 function add()
00099 {
00100 if(!$_POST['title'])
00101 {
00102 sendInfo($this->lng->txt('crs_grp_enter_title'));
00103 $this->create();
00104
00105 return false;
00106 }
00107
00108 $this->grp_obj->setTitle(ilUtil::stripSlashes($_POST['title']));
00109 $this->grp_obj->setDescription(ilUtil::stripSlashes($_POST['description']));
00110 $this->grp_obj->setUniqueField($_POST['unique']);
00111 if($this->grp_obj->create($this->crs_obj->getRefId(),$this->crs_obj->getId()))
00112 {
00113 sendInfo($this->lng->txt('crs_grp_added_grouping'));
00114 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00115
00116 return true;
00117 }
00118 sendInfo($this->lng->txt('crs_grp_err_adding_grouping'));
00119 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00120
00121 return false;
00122 }
00123
00124 function edit()
00125 {
00126 $options = array('login' => 'login',
00127 'email' => 'email',
00128 'matriculation' => 'matriculation');
00129
00130 $title = isset($_POST['title']) ? ilUtil::stripSlashes($_POST['title']) : $this->grp_obj->getTitle();
00131 $description = isset($_POST["description"]) ? ilUtil::stripSlashes($_POST['description']) : $this->grp_obj->getDescription();
00132 $unique = $_POST['unique'] ? $_POST['unique'] : $this->grp_obj->getUniqueField();
00133
00134 if(!$this->id)
00135 {
00136 sendInfo($this->lng->txt('crs_grp_no_grouping_id_given'));
00137 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00138
00139 return false;
00140 }
00141 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_edit.html","course");
00142
00143 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00144
00145
00146 $this->tpl->setCurrentBlock("btn_cell");
00147 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTargetByClass('ilobjcoursegui','listGroupings'));
00148 $this->tpl->setVariable("BTN_TXT",$this->lng->txt('back'));
00149 $this->tpl->parseCurrentBlock();
00150
00151 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00152 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_crs.gif'));
00153 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('crs_groupings'));
00154 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('crs_grouping').' ('.$this->grp_obj->getTitle().')');
00155 $this->tpl->setVariable("BTN_UPDATE",$this->lng->txt('update'));
00156 $this->tpl->setVariable("BTN_ADD",$this->lng->txt('crs_add_grp_assignment'));
00157 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt('title'));
00158 $this->tpl->setVariable("TXT_DESCRIPTION",$this->lng->txt('description'));
00159
00160 $this->tpl->setVariable("TXT_UNAM",$this->lng->txt('unambiguousness'));
00161 $this->tpl->setVariable("UNAM_SELECT",ilUtil::formSelect($unique,'unique',$options));
00162
00163 $this->tpl->setVariable("TITLE",$title);
00164 $this->tpl->setVariable("DESCRIPTION",$description);
00165
00166 if($this->grp_obj->getCountAssignedCourses())
00167 {
00168 foreach($this->grp_obj->getAssignedCourses() as $cond_data)
00169 {
00170 if($cond_data['target_ref_id'] == $this->crs_obj->getRefId())
00171 {
00172 continue;
00173 }
00174 $tmp_obj =& ilObjectFactory::getInstanceByRefId($cond_data['target_ref_id']);
00175
00176 $this->tpl->setCurrentBlock("list_courses");
00177
00178 $this->ctrl->setParameter($this,'cond_id',$cond_data['id']);
00179 $this->tpl->setVariable("DELETE_LINK",$this->ctrl->getLinkTarget($this,'deleteAssignment'));
00180 $this->tpl->setVariable("LIST_CRS_TITLE",$tmp_obj->getTitle());
00181 $this->tpl->setVariable("TXT_DELETE",$this->lng->txt('delete'));
00182 $this->tpl->parseCurrentBlock();
00183 }
00184 $this->tpl->setCurrentBlock("assigned");
00185 $this->tpl->setVariable("ASS_ROWSPAN",$this->grp_obj->getCountAssignedCourses());
00186 $this->tpl->setVariable("ASS_COURSES",$this->lng->txt('crs_grp_table_assigned_courses'));
00187 $this->tpl->setVariable("CRS_TITLE",$this->crs_obj->getTitle());
00188 $this->tpl->parseCurrentBlock();
00189 }
00190 else
00191 {
00192 $this->tpl->setCurrentBlock("no_assigned");
00193 $this->tpl->setVariable("MESSAGE_NO_COURSES",$this->lng->txt('crs_grp_no_courses_assigned'));
00194 $this->tpl->parseCurrentBlock();
00195 }
00196 }
00197
00198 function deleteAssignment()
00199 {
00200 include_once './classes/class.ilConditionHandler.php';
00201
00202 if(!$this->id)
00203 {
00204 sendInfo($this->lng->txt('crs_grp_no_grouping_id_given'));
00205 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00206
00207 return false;
00208 }
00209 $condh =& new ilConditionHandler();
00210 $condh->deleteCondition((int) $_GET['cond_id']);
00211
00212
00213 if($this->grp_obj->getCountAssignedCourses() == 1)
00214 {
00215 $condh->deleteByObjId($this->id);
00216 }
00217 sendInfo($this->lng->txt('crs_grp_deassigned_courses'));
00218 $this->edit();
00219 }
00220
00221
00222 function selectCourse()
00223 {
00224 global $tree;
00225
00226 if(!$this->id)
00227 {
00228 sendInfo($this->lng->txt('crs_grp_no_grouping_id_given'));
00229 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00230
00231 return false;
00232 }
00233 if(count($courses = ilUtil::getObjectsByOperations('crs','write',false)) == 1)
00234 {
00235 sendInfo($this->lng->txt('crs_grp_no_course_found'));
00236 $this->edit();
00237
00238 return false;
00239 }
00240 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_select_crs.html","course");
00241
00242 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00243
00244
00245 $this->tpl->setCurrentBlock("btn_cell");
00246 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'edit'));
00247 $this->tpl->setVariable("BTN_TXT",$this->lng->txt('back'));
00248 $this->tpl->parseCurrentBlock();
00249
00250 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00251 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_crs.gif'));
00252 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('crs_groupings'));
00253 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('crs_grp_assign_crs').' ('.$this->grp_obj->getTitle().')');
00254 $this->tpl->setVariable("BTN_ASSIGN",$this->lng->txt('crs_grp_assign_crs'));
00255 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
00256 $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
00257
00258 $counter = 0;
00259 foreach($courses as $course_data)
00260 {
00261 if($course_data['ref_id'] == $this->crs_obj->getRefId())
00262 {
00263 continue;
00264 }
00265 $tmp_obj =& ilObjectFactory::getInstanceByRefId($course_data['ref_id']);
00266
00267 #if(ilObjCourseGrouping::_isInGrouping($tmp_obj->getId()))
00268 #{
00269 # continue;
00270 #}
00271 if(strlen($tmp_obj->getDescription()))
00272 {
00273 $this->tpl->setCurrentBlock("description");
00274 $this->tpl->setVariable("DESCRIPTION_CRS",$tmp_obj->getDescription());
00275 $this->tpl->parseCurrentBlock();
00276 }
00277
00278 $this->tpl->setCurrentBlock("crs_row");
00279 $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00280 $this->tpl->setVariable("CHECK_CRS",ilUtil::formCheckbox(0,'crs_ids[]',$course_data['ref_id']));
00281 $this->tpl->setVariable("CRS_TITLE",$tmp_obj->getTitle());
00282
00283 $path = $this->__formatPath($tree->getPathFull($course_data['ref_id']));
00284 $this->tpl->setVariable("CRS_PATH",$this->lng->txt('path').": ".$path);
00285
00286
00287 $this->tpl->parseCurrentBlock();
00288
00289 }
00290
00291 return true;
00292 }
00293
00294 function assignCourse()
00295 {
00296 include_once './classes/class.ilConditionHandler.php';
00297
00298 if(!$this->id)
00299 {
00300 sendInfo($this->lng->txt('crs_grp_no_grouping_id_given'));
00301 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00302
00303 return false;
00304 }
00305 if(!count($_POST['crs_ids']))
00306 {
00307 sendInfo($this->lng->txt('crs_grp_no_course_selected'));
00308 $this->selectCourse();
00309
00310 return true;
00311 }
00312
00313 $added = 0;
00314 foreach($_POST['crs_ids'] as $course_ref_id)
00315 {
00316 $tmp_crs =& ilObjectFactory::getInstanceByRefId($course_ref_id);
00317 $tmp_condh =& new ilConditionHandler();
00318 $tmp_condh->enableAutomaticValidation(false);
00319
00320 $tmp_condh->setTargetRefId($course_ref_id);
00321 $tmp_condh->setTargetObjId($tmp_crs->getId());
00322 $tmp_condh->setTargetType('crs');
00323 $tmp_condh->setTriggerRefId(0);
00324 $tmp_condh->setTriggerObjId($this->id);
00325 $tmp_condh->setTriggerType('crsg');
00326 $tmp_condh->setOperator('not_member');
00327 $tmp_condh->setValue($this->grp_obj->getUniqueField());
00328
00329 if(!$tmp_condh->checkExists())
00330 {
00331 $tmp_condh->storeCondition();
00332 ++$added;
00333 }
00334 }
00335 if($added)
00336 {
00337
00338
00339 $tmp_condh =& new ilConditionHandler();
00340 $tmp_condh->enableAutomaticValidation(false);
00341
00342 $tmp_condh->setTargetRefId($this->crs_obj->getRefId());
00343 $tmp_condh->setTargetObjId($this->crs_obj->getId());
00344 $tmp_condh->setTargetType('crs');
00345 $tmp_condh->setTriggerRefId(0);
00346 $tmp_condh->setTriggerObjId($this->id);
00347 $tmp_condh->setTriggerType('crsg');
00348 $tmp_condh->setOperator('not_member');
00349 $tmp_condh->setValue($this->grp_obj->getUniqueField());
00350
00351 if(!$tmp_condh->checkExists())
00352 {
00353 $tmp_condh->storeCondition();
00354 }
00355 sendInfo($this->lng->txt('crs_grp_assigned_courses'));
00356 $this->edit();
00357
00358 return true;
00359 }
00360 else
00361 {
00362 sendInfo($this->lng->txt('crs_grp_courses_already_assigned'));
00363 $this->edit();
00364
00365 return true;
00366 }
00367 }
00368
00369
00370 function update()
00371 {
00372 if(!$this->id)
00373 {
00374 sendInfo($this->lng->txt('crs_grp_no_grouping_id_given'));
00375 $this->ctrl->redirectByClass('ilObjCourseGUI','listGroupings');
00376
00377 return false;
00378 }
00379 if(!$_POST['title'])
00380 {
00381 sendInfo($this->lng->txt('crs_grp_enter_title'));
00382 $this->edit();
00383
00384 return false;
00385 }
00386 $this->grp_obj->setTitle(ilUtil::stripSlashes($_POST['title']));
00387 $this->grp_obj->setDescription(ilUtil::stripSlashes($_POST['description']));
00388 $this->grp_obj->setUniqueField($_POST['unique']);
00389
00390 $this->grp_obj->update();
00391
00392 sendInfo($this->lng->txt('crs_grp_modified_grouping'));
00393 $this->edit();
00394
00395 return true;
00396 }
00397
00398 function &executeCommand()
00399 {
00400 $cmd = $this->ctrl->getCmd();
00401 if (!$cmd = $this->ctrl->getCmd())
00402 {
00403 $cmd = "edit";
00404 }
00405 $this->$cmd();
00406 }
00407
00408 function otherSelectAssign()
00409 {
00410 include_once './course/classes/class.ilObjCourseGrouping.php';
00411
00412 global $rbacsystem,$tree;
00413
00414 if(!$rbacsystem->checkAccess("write", $this->crs_obj->getRefId()))
00415 {
00416 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00417 }
00418
00419 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.crs_other_assign.html","course");
00420 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00421
00422
00423 $this->tpl->setCurrentBlock("btn_cell");
00424 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'edit'));
00425 $this->tpl->setVariable("BTN_TXT",$this->lng->txt('back'));
00426 $this->tpl->parseCurrentBlock();
00427
00428 if(!count($groupings = ilObjCourseGrouping::_getAllGroupings($this->crs_obj->getRefId(),false)))
00429 {
00430 sendInfo($this->lng->txt('crs_no_groupings_crs_can_be_assigned_to'));
00431
00432 return true;
00433 }
00434
00435 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00436 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_crs.gif'));
00437 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('crs_groupings'));
00438 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('crs_groupings'));
00439 $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
00440 $this->tpl->setVariable("HEADER_UNAMBIGUOUSNESS",$this->lng->txt('unambiguousness'));
00441 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
00442 $this->tpl->setVariable("BTN_ASSIGN",$this->lng->txt('crs_grouping_assign'));
00443
00444
00445 $counter = 0;
00446 foreach($groupings as $grouping_id)
00447 {
00448 $tmp_obj =& new ilObjCourseGrouping($grouping_id);
00449
00450 $tmp_crs = ilObjectFactory::getInstanceByRefId($tmp_obj->getCourseRefId());
00451
00452 if(strlen($tmp_obj->getDescription()))
00453 {
00454 $this->tpl->setCurrentBlock("description");
00455 $this->tpl->setVariable("DESCRIPTION_GRP",$tmp_obj->getDescription());
00456 $this->tpl->parseCurrentBlock();
00457 }
00458 foreach($tmp_obj->getAssignedCourses() as $condition)
00459 {
00460 $this->tpl->setCurrentBlock("path");
00461 $this->tpl->setVariable("ASS_PATH",' '.
00462 $this->__formatPath($tree->getPathFull($condition['target_ref_id'])));
00463 $this->tpl->parseCurrentBlock();
00464 }
00465
00466 $disabled = !$rbacsystem->checkAccess('write',$tmp_obj->getCourseRefId());
00467
00468 $this->tpl->setCurrentBlock("grouping_row");
00469 $this->tpl->setVariable("GRP_TITLE",$tmp_obj->getTitle().' ('.$tmp_crs->getTitle().')');
00470 $this->tpl->setVariable("CHECK_GRP",ilUtil::formCheckbox((int) $tmp_obj->isAssigned($this->crs_obj->getId()),
00471 'grouping[]',
00472 $grouping_id,
00473 $disabled));
00474
00475 $this->tpl->setVariable("AMB_GRP",$this->lng->txt($tmp_obj->getUniqueField()));
00476 $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00477
00478
00479 if($num_courses = $tmp_obj->getCountAssignedCourses())
00480 {
00481 $this->tpl->setVariable("ASSIGNED_COURSES",$this->lng->txt('crs_grp_assigned_courses_info')." <b>$num_courses</b> ");
00482 }
00483 else
00484 {
00485 $this->tpl->setVariable("ASSIGNED_COURSES",$this->lng->txt('crs_grp_no_courses_assigned'));
00486 }
00487 $this->tpl->parseCurrentBlock();
00488 }
00489 }
00490
00491 function otherAssign()
00492 {
00493 include_once './course/classes/class.ilObjCourseGrouping.php';
00494
00495 global $rbacsystem,$tree;
00496
00497 if(!$rbacsystem->checkAccess("write", $this->crs_obj->getRefId()))
00498 {
00499 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00500 }
00501
00502 $_POST['grouping'] = $_POST['grouping'] ? $_POST['grouping'] : array();
00503 foreach(ilObjCourseGrouping::_getAllGroupings($this->crs_obj->getRefId()) as $grouping_id)
00504 {
00505 $tmp_obj =& new ilObjCourseGrouping($grouping_id);
00506
00507 if($tmp_obj->isAssigned($this->crs_obj->getId()) and !in_array($grouping_id,$_POST['grouping']))
00508 {
00509 $tmp_obj->deassign($this->crs_obj->getRefId(),$this->crs_obj->getId());
00510 continue;
00511 }
00512 if(!$tmp_obj->isAssigned($this->crs_obj->getId()) and in_array($grouping_id,$_POST['grouping']))
00513 {
00514 $tmp_obj->assign($this->crs_obj->getRefId(),$this->crs_obj->getId());
00515 continue;
00516 }
00517 }
00518 sendInfo($this->lng->txt('crs_grouping_modified_assignment'));
00519 $this->otherSelectAssign();
00520
00521 return true;
00522 }
00523
00524 function __initGroupingObject()
00525 {
00526 include_once './course/classes/class.ilObjCourseGrouping.php';
00527
00528 $this->grp_obj =& new ilObjCourseGrouping($this->id);
00529 }
00530
00531 function __formatPath($a_path_arr)
00532 {
00533 $counter = 0;
00534 foreach($a_path_arr as $data)
00535 {
00536 if($counter++)
00537 {
00538 $path .= " -> ";
00539 }
00540 $path .= $data['title'];
00541 }
00542
00543 if(strlen($path) > 40)
00544 {
00545 return '...'.substr($path,-40);
00546 }
00547 return $path;
00548 }
00549
00550 }
00551 ?>