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 require_once "class.ilObject.php";
00025
00034 class ilObjRole extends ilObject
00035 {
00043 var $parent;
00044
00045 var $allow_register;
00046 var $assign_users;
00047
00054 function ilObjRole($a_id = 0,$a_call_by_reference = false)
00055 {
00056 $this->type = "role";
00057 $this->ilObject($a_id,$a_call_by_reference);
00058 }
00059
00060 function toggleAssignUsersStatus($a_assign_users)
00061 {
00062 $this->assign_users = (int) $a_assign_users;
00063 }
00064 function getAssignUsersStatus()
00065 {
00066 return $this->assign_users;
00067 }
00068
00069 function _getAssignUsersStatus($a_role_id)
00070 {
00071 global $ilDB;
00072
00073 $query = "SELECT assign_users FROM role_data WHERE role_id = ".$ilDB->quote($a_role_id)." ";
00074
00075 $res = $ilDB->query($query);
00076 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00077 {
00078 return $row->assign_users ? true : false;
00079 }
00080 return false;
00081 }
00082
00087 function read ()
00088 {
00089 global $ilDB;
00090
00091 $q = "SELECT * FROM role_data WHERE role_id= ".$ilDB->quote($this->id)." ";
00092 $r = $this->ilias->db->query($q);
00093
00094 if ($r->numRows() > 0)
00095 {
00096 $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00097
00098
00099 $this->assignData($data);
00100 }
00101 else
00102 {
00103 $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);
00104 }
00105
00106 parent::read();
00107 }
00108
00114 function assignData($a_data)
00115 {
00116 $this->setTitle(ilUtil::stripSlashes($a_data["title"]));
00117 $this->setDescription(ilUtil::stripslashes($a_data["desc"]));
00118 $this->setAllowRegister($a_data["allow_register"]);
00119 $this->toggleAssignUsersStatus($a_data['assign_users']);
00120 }
00121
00126 function update ()
00127 {
00128 global $ilDB;
00129
00130 $q = "UPDATE role_data SET ".
00131 "allow_register= ".$ilDB->quote($this->allow_register).", ".
00132 "assign_users = ".$ilDB->quote($this->getAssignUsersStatus())." ".
00133 "WHERE role_id= ".$ilDB->quote($this->id)." ";
00134
00135 $this->ilias->db->query($q);
00136
00137 parent::update();
00138
00139 $this->read();
00140
00141 return true;
00142 }
00143
00151 function create()
00152 {
00153 global $ilDB;
00154
00155 $this->id = parent::create();
00156
00157 $q = "INSERT INTO role_data ".
00158 "(role_id,allow_register,assign_users) ".
00159 "VALUES ".
00160 "(".$ilDB->quote($this->id).",".$ilDB->quote($this->getAllowRegister()).",".$ilDB->quote($this->getAssignUsersStatus()).")";
00161 $this->ilias->db->query($q);
00162
00163 return $this->id;
00164 }
00165
00172 function setAllowRegister($a_allow_register)
00173 {
00174 if (empty($a_allow_register))
00175 {
00176 $a_allow_register == 0;
00177 }
00178
00179 $this->allow_register = (int) $a_allow_register;
00180 }
00181
00188 function getAllowRegister()
00189 {
00190 return $this->allow_register;
00191 }
00192
00199 function _lookupRegisterAllowed()
00200 {
00201 global $ilDB;
00202
00203 $q = "SELECT * FROM role_data ".
00204 "LEFT JOIN object_data ON object_data.obj_id = role_data.role_id ".
00205 "WHERE allow_register = 1";
00206
00207 $r = $ilDB->query($q);
00208
00209 $roles = array();
00210 while ($role = $r->fetchRow(DB_FETCHMODE_ASSOC))
00211 {
00212 $roles[] = array("id" => $role["obj_id"],
00213 "title" => $role["title"],
00214 "auth_mode" => $role['auth_mode']);
00215 }
00216
00217 return $roles;
00218 }
00219
00226 function _lookupAllowRegister($a_role_id)
00227 {
00228 global $ilDB;
00229
00230 $q = "SELECT * FROM role_data ".
00231 " WHERE role_id =".$ilDB->quote($a_role_id);
00232
00233 $role_set = $ilDB->query($q);
00234
00235 if ($role_rec = $role_set->fetchRow(DB_FETCHMODE_ASSOC))
00236 {
00237 if ($role_rec["allow_register"])
00238 {
00239 return true;
00240 }
00241 }
00242 return false;
00243 }
00244
00252 function setParent($a_parent_ref)
00253 {
00254 $this->parent = $a_parent_ref;
00255 }
00256
00263 function getParent()
00264 {
00265 return $this->parent;
00266 }
00267
00268
00275 function delete()
00276 {
00277 global $rbacadmin, $rbacreview,$ilDB;
00278
00279 $role_folders = $rbacreview->getFoldersAssignedToRole($this->getId());
00280
00281 if ($rbacreview->isAssignable($this->getId(),$this->getParent()))
00282 {
00283
00284
00285
00286
00287 $user_ids = $rbacreview->assignedUsers($this->getId());
00288
00289 $last_role_user_ids = array();
00290
00291 foreach ($user_ids as $user_id)
00292 {
00293
00294
00295 $role_ids = $rbacreview->assignedRoles($user_id);
00296
00297
00298 if (count($role_ids) == 1)
00299 {
00300 $last_role_user_ids[] = $user_id;
00301 }
00302 }
00303
00304
00305 if (count($last_role_user_ids) > 0)
00306 {
00307 foreach ($last_role_user_ids as $user_id)
00308 {
00309
00310
00311 $tmp_obj = $this->ilias->obj_factory->getInstanceByObjId($user_id);
00312 $user_names[] = $tmp_obj->getFullname();
00313 unset($tmp_obj);
00314 }
00315
00316
00317
00318
00319 $users = implode(', ',$user_names);
00320 $this->ilias->raiseError($this->lng->txt("msg_user_last_role1")." ".
00321 $users."<br/>".$this->lng->txt("msg_user_last_role2"),$this->ilias->error_obj->WARNING);
00322 }
00323 else
00324 {
00325
00326 $rbacadmin->deleteRole($this->getId(),$this->getParent());
00327
00328
00329 include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMappingSettings.php');
00330 ilLDAPRoleGroupMappingSettings::_deleteByRole($this->getId());
00331
00332
00333 parent::delete();
00334
00335
00336 $q = "DELETE FROM role_data WHERE role_id = ".$ilDB->quote($this->getId())." ";
00337 $this->ilias->db->query($q);
00338
00339 include_once './classes/class.ilRoleDesktopItem.php';
00340 $role_desk_item_obj =& new ilRoleDesktopItem($this->getId());
00341 $role_desk_item_obj->deleteAll();
00342
00343 }
00344 }
00345 else
00346 {
00347
00348 $rbacadmin->deleteLocalRole($this->getId(),$this->getParent());
00349 }
00350
00351
00352 foreach ($role_folders as $rolf)
00353 {
00354 if (ilObject::_exists($rolf,true))
00355 {
00356 $rolfObj = $this->ilias->obj_factory->getInstanceByRefId($rolf);
00357 $rolfObj->purge();
00358 unset($roleObj);
00359 }
00360 }
00361
00362 return true;
00363 }
00364
00365 function getCountMembers()
00366 {
00367 global $rbacreview;
00368
00369 return count($rbacreview->assignedUsers($this->getId()));
00370 }
00371
00380 function _search(&$a_search_obj)
00381 {
00382 global $ilBench;
00383
00384
00385
00386 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
00387
00388
00389 $query = "SELECT obj_id FROM object_data AS od ".
00390 $where_condition." ".
00391 "AND od.type = 'role' ";
00392
00393 $ilBench->start("Search", "ilObjRole_search");
00394 $res = $a_search_obj->ilias->db->query($query);
00395 $ilBench->stop("Search", "ilObjRole_search");
00396
00397 $counter = 0;
00398
00399 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00400 {
00401 $result_data[$counter++]["id"] = $row->obj_id;
00402 }
00403
00404 return $result_data ? $result_data : array();
00405 }
00406
00407
00408 function _getTranslation($a_role_title)
00409 {
00410 global $lng;
00411
00412 $test_str = explode('_',$a_role_title);
00413
00414 if ($test_str[0] == 'il')
00415 {
00416 $test2 = (int) $test_str[3];
00417 if ($test2 > 0)
00418 {
00419 unset($test_str[3]);
00420 }
00421
00422 return $lng->txt(implode('_',$test_str));
00423 }
00424
00425 return $a_role_title;
00426 }
00427
00428
00429
00430 function _updateAuthMode($a_roles)
00431 {
00432 global $ilDB;
00433
00434 foreach ($a_roles as $role_id => $auth_mode)
00435 {
00436 $q = "UPDATE role_data SET ".
00437 "auth_mode= ".$ilDB->quote($auth_mode)." ".
00438 "WHERE role_id= ".$ilDB->quote($role_id)." ";
00439 $ilDB->query($q);
00440 }
00441 }
00442
00443 function _getAuthMode($a_role_id)
00444 {
00445 global $ilDB;
00446
00447 $q = "SELECT auth_mode FROM role_data ".
00448 "WHERE role_id= ".$ilDB->quote($a_role_id)." ";
00449 $r = $ilDB->query($q);
00450 $row = $r->fetchRow();
00451
00452 return $row[0];
00453 }
00454
00462 public static function _getRolesByAuthMode($a_auth_mode)
00463 {
00464 global $ilDB;
00465
00466 $query = "SELECT * FROM role_data ".
00467 "WHERE auth_mode = ".$ilDB->quote($a_auth_mode);
00468 $res = $ilDB->query($query);
00469 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00470 {
00471 $roles[] = $row->role_id;
00472 }
00473 return $roles ? $roles : array();
00474 }
00475
00484 public static function _resetAuthMode($a_auth_mode)
00485 {
00486 global $ilDB;
00487
00488 $query = "UPDATE role_data SET auth_mode = 'default' WHERE auth_mode = ".$ilDB->quote($a_auth_mode);
00489 $ilDB->query($query);
00490 }
00491
00492
00493
00494 function __getPermissionDefinitions()
00495 {
00496 global $ilDB, $lng, $objDefinition;
00497
00498
00499 $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00500 "JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00501 "JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00502 $r = $ilDB->query($q);
00503
00504 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00505 {
00506 if($objDefinition->getDevMode($row->title))
00507 {
00508 continue;
00509 }
00510
00511 #if(in_array($row->title,$to_filter))
00512 #{
00513 # continue;
00514 #}
00515 $rbac_objects[$row->typ_id] = array("obj_id" => $row->typ_id,
00516 "type" => $row->title
00517 );
00518
00519 $rbac_operations[$row->typ_id][$row->ops_id] = array(
00520 "ops_id" => $row->ops_id,
00521 "title" => $row->operation,
00522 "name" => $lng->txt($row->title."_".$row->operation)
00523 );
00524 }
00525 return array($rbac_objects,$rbac_operations);
00526 }
00527 }
00528 ?>