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