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 $user_ids = $rbacreview->assignedUsers($this->getId());
00305
00306 $last_role_user_ids = array();
00307
00308 foreach ($user_ids as $user_id)
00309 {
00310
00311 $role_ids = $rbacreview->assignedRoles($user_id);
00312
00313
00314 if (count($role_ids) == 1)
00315 {
00316 $last_role_user_ids[] = $user_id;
00317 }
00318 }
00319
00320
00321 if (count($last_role_user_ids) > 0)
00322 {
00323 foreach ($last_role_user_ids as $user_id)
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 ?>