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