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