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
00035 require_once "class.ilObject.php";
00036
00037 class ilObjRole extends ilObject
00038 {
00046 var $parent;
00047
00048 var $allow_register;
00049 var $assign_users;
00050
00057 function ilObjRole($a_id = 0,$a_call_by_reference = false)
00058 {
00059 $this->type = "role";
00060 $this->ilObject($a_id,$a_call_by_reference);
00061 }
00062
00063 function toggleAssignUsersStatus($a_assign_users)
00064 {
00065 $this->assign_users = (int) $a_assign_users;
00066 }
00067 function getAssignUsersStatus()
00068 {
00069 return $this->assign_users;
00070 }
00071
00072 function _getAssignUsersStatus($a_role_id)
00073 {
00074 global $ilDB;
00075
00076 $query = "SELECT assign_users FROM role_data WHERE role_id = '".$a_role_id."'";
00077
00078 $res = $ilDB->query($query);
00079 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00080 {
00081 return $row->assign_users ? true : false;
00082 }
00083 return false;
00084 }
00085
00090 function read ()
00091 {
00092 $q = "SELECT * FROM role_data WHERE role_id='".$this->id."'";
00093 $r = $this->ilias->db->query($q);
00094
00095 if ($r->numRows() > 0)
00096 {
00097 $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00098
00099
00100 $this->assignData($data);
00101 }
00102 else
00103 {
00104 $this->ilias->raiseError("<b>Error: There is no dataset with id ".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $this->ilias->FATAL);
00105 }
00106
00107 parent::read();
00108 }
00109
00115 function assignData($a_data)
00116 {
00117 $this->setTitle(ilUtil::stripSlashes($a_data["title"]));
00118 $this->setDescription(ilUtil::stripslashes($a_data["desc"]));
00119 $this->setAllowRegister($a_data["allow_register"]);
00120 $this->toggleAssignUsersStatus($a_data['assign_users']);
00121 }
00122
00127 function update ()
00128 {
00129 $q = "UPDATE role_data SET ".
00130 "allow_register='".$this->allow_register."', ".
00131 "assign_users = '".$this->getAssignUsersStatus()."' ".
00132 "WHERE role_id='".$this->id."'";
00133
00134 $this->ilias->db->query($q);
00135
00136 parent::update();
00137
00138 $this->read();
00139
00140 return true;
00141 }
00142
00150 function create()
00151 {
00152 $this->id = parent::create();
00153
00154 $q = "INSERT INTO role_data ".
00155 "(role_id,allow_register,assign_users) ".
00156 "VALUES ".
00157 "('".$this->id."','".$this->getAllowRegister()."','".$this->getAssignUsersStatus()."')";
00158 $this->ilias->db->query($q);
00159
00160 return $this->id;
00161 }
00162
00169 function setAllowRegister($a_allow_register)
00170 {
00171 if (empty($a_allow_register))
00172 {
00173 $a_allow_register == 0;
00174 }
00175
00176 $this->allow_register = (int) $a_allow_register;
00177 }
00178
00185 function getAllowRegister()
00186 {
00187 return $this->allow_register;
00188 }
00189
00196 function _lookupRegisterAllowed()
00197 {
00198 global $ilDB;
00199
00200 $q = "SELECT * FROM role_data ".
00201 "LEFT JOIN object_data ON object_data.obj_id = role_data.role_id ".
00202 "WHERE allow_register = 1";
00203
00204 $r = $ilDB->query($q);
00205
00206 $roles = array();
00207 while ($role = $r->fetchRow(DB_FETCHMODE_ASSOC))
00208 {
00209 $roles[] = array("id" => $role["obj_id"],
00210 "title" => $role["title"],
00211 "auth_mode" => $role['auth_mode']);
00212 }
00213
00214 return $roles;
00215 }
00216
00223 function _lookupAllowRegister($a_role_id)
00224 {
00225 global $ilDB;
00226
00227 $q = "SELECT * FROM role_data ".
00228 " WHERE role_id =".$ilDB->quote($a_role_id);
00229
00230 $role_set = $ilDB->query($q);
00231
00232 if ($role_rec = $role_set->fetchRow(DB_FETCHMODE_ASSOC))
00233 {
00234 if ($role_rec["allow_register"])
00235 {
00236 return true;
00237 }
00238 }
00239 return false;
00240 }
00241
00249 function setParent($a_parent_ref)
00250 {
00251 $this->parent = $a_parent_ref;
00252 }
00253
00260 function getParent()
00261 {
00262 return $this->parent;
00263 }
00264
00271 function ilClone($a_parent_ref)
00272 {
00273
00274 return false;
00275
00276 global $rbacadmin;
00277
00278
00279 $new_ref_id = parent::ilClone($a_parent_ref);
00280
00281
00282
00283
00284 return $new_ref_id;
00285 }
00286
00293 function delete()
00294 {
00295 global $rbacadmin, $rbacreview;
00296
00297 $role_folders = $rbacreview->getFoldersAssignedToRole($this->getId());
00298
00299 if ($rbacreview->isAssignable($this->getId(),$this->getParent()))
00300 {
00301
00302
00303
00304
00305 $user_ids = $rbacreview->assignedUsers($this->getId());
00306
00307 $last_role_user_ids = array();
00308
00309 foreach ($user_ids as $user_id)
00310 {
00311
00312
00313 $role_ids = $rbacreview->assignedRoles($user_id);
00314
00315
00316 if (count($role_ids) == 1)
00317 {
00318 $last_role_user_ids[] = $user_id;
00319 }
00320 }
00321
00322
00323 if (count($last_role_user_ids) > 0)
00324 {
00325 foreach ($last_role_user_ids as $user_id)
00326 {
00327
00328
00329 $tmp_obj = $this->ilias->obj_factory->getInstanceByObjId($user_id);
00330 $user_names[] = $tmp_obj->getFullname();
00331 unset($tmp_obj);
00332 }
00333
00334
00335
00336
00337 $users = implode(', ',$user_names);
00338 $this->ilias->raiseError($this->lng->txt("msg_user_last_role1")." ".
00339 $users."<br/>".$this->lng->txt("msg_user_last_role2"),$this->ilias->error_obj->WARNING);
00340 }
00341 else
00342 {
00343
00344 $rbacadmin->deleteRole($this->getId(),$this->getParent());
00345
00346
00347 parent::delete();
00348
00349
00350 $q = "DELETE FROM role_data WHERE role_id = '".$this->getId()."'";
00351 $this->ilias->db->query($q);
00352
00353 include_once './classes/class.ilRoleDesktopItem.php';
00354
00355 $role_desk_item_obj =& new ilRoleDesktopItem($this->getId());
00356 $role_desk_item_obj->deleteAll();
00357
00358 }
00359 }
00360 else
00361 {
00362
00363 $rbacadmin->deleteLocalRole($this->getId(),$this->getParent());
00364 }
00365
00366
00367 foreach ($role_folders as $rolf)
00368 {
00369 if (ilObject::_exists($rolf,true))
00370 {
00371 $rolfObj = $this->ilias->obj_factory->getInstanceByRefId($rolf);
00372 $rolfObj->purge();
00373 unset($roleObj);
00374 }
00375 }
00376
00377 return true;
00378 }
00379
00380 function getCountMembers()
00381 {
00382 global $rbacreview;
00383
00384 return count($rbacreview->assignedUsers($this->getId()));
00385 }
00386
00395 function _search(&$a_search_obj)
00396 {
00397 global $ilBench;
00398
00399
00400
00401 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
00402
00403
00404 $query = "SELECT obj_id FROM object_data AS od ".
00405 $where_condition." ".
00406 "AND od.type = 'role' ";
00407
00408 $ilBench->start("Search", "ilObjRole_search");
00409 $res = $a_search_obj->ilias->db->query($query);
00410 $ilBench->stop("Search", "ilObjRole_search");
00411
00412 $counter = 0;
00413
00414 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00415 {
00416 $result_data[$counter++]["id"] = $row->obj_id;
00417 }
00418
00419 return $result_data ? $result_data : array();
00420 }
00421
00422
00423 function _updateSessionRoles($a_selected_users)
00424 {
00425 global $ilDB, $rbacreview;
00426
00427 $online_users_all = ilUtil::getUsersOnline();
00428
00429
00430 $affected_users = array_intersect(array_keys($online_users_all),$a_selected_users);
00431
00432 foreach ($affected_users as $user)
00433 {
00434 $role_arr = $rbacreview->assignedRoles($user);
00435
00436
00437 if ($user == $_SESSION["AccountId"])
00438 {
00439 $_SESSION["RoleId"] = $role_arr;
00440 }
00441 else
00442 {
00443 $roles = "RoleId|".serialize($role_arr);
00444 $modified_data = preg_replace("/RoleId.*?;\}/",$roles,$online_users_all[$user]["data"]);
00445
00446 $q = "UPDATE usr_session SET data='".$modified_data."' WHERE user_id = '".$user."'";
00447 $ilDB->query($q);
00448 }
00449 }
00450 }
00451
00452 function _getTranslation($a_role_title)
00453 {
00454 global $lng;
00455
00456 $test_str = explode('_',$a_role_title);
00457
00458 if ($test_str[0] == 'il')
00459 {
00460 $test2 = (int) $test_str[3];
00461 if ($test2 > 0)
00462 {
00463 unset($test_str[3]);
00464 }
00465
00466 return $lng->txt(implode('_',$test_str));
00467 }
00468
00469 return $a_role_title;
00470 }
00471
00472 function _updateAuthMode($a_roles)
00473 {
00474 global $ilDB;
00475
00476 foreach ($a_roles as $role_id => $auth_mode)
00477 {
00478 $q = "UPDATE role_data SET ".
00479 "auth_mode='".$auth_mode."' ".
00480 "WHERE role_id='".$role_id."'";
00481 $ilDB->query($q);
00482 }
00483 }
00484
00485 function _getAuthMode($a_role_id)
00486 {
00487 global $ilDB;
00488
00489 $q = "SELECT auth_mode FROM role_data ".
00490 "WHERE role_id='".$a_role_id."'";
00491 $r = $ilDB->query($q);
00492 $row = $r->fetchRow();
00493
00494 return $row[0];
00495 }
00496
00497
00498
00499 function __getPermissionDefinitions()
00500 {
00501 global $ilDB, $lng, $objDefinition;
00502 #$to_filter = $objDefinition->getSubobjectsToFilter();
00503
00504
00505 $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00506 "LEFT JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00507 "LEFT JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00508 $r = $ilDB->query($q);
00509
00510 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00511 {
00512
00513 #if(in_array($row->title,$to_filter))
00514 #{
00515 # continue;
00516 #}
00517 $rbac_objects[$row->typ_id] = array("obj_id" => $row->typ_id,
00518 "type" => $row->title
00519 );
00520
00521 $rbac_operations[$row->typ_id][$row->ops_id] = array(
00522 "ops_id" => $row->ops_id,
00523 "title" => $row->operation,
00524 "name" => $lng->txt($row->title."_".$row->operation)
00525 );
00526 }
00527
00528 return array($rbac_objects,$rbac_operations);
00529 }
00530 }
00531 ?>