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