forked from science-ation/science-ation
Removed some usage of old user functions. Added role handling in testapi.php
This commit is contained in:
parent
835047f3a8
commit
7d5f5cccd0
42
testapi.php
42
testapi.php
@ -1,7 +1,32 @@
|
||||
<?
|
||||
include "common.inc.php";
|
||||
?>
|
||||
<html><body>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="js/jquery/1.3.2/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$.get('api/role/list', {}, function(results){
|
||||
var list, disabled;
|
||||
var selector = [];
|
||||
selector[0] = $('<select name="role_id"></select>');
|
||||
selector[1] = $('<select name="role_id"></select>');
|
||||
eval('list = ' + results);
|
||||
for(n in list['roles']){
|
||||
disabled = '';
|
||||
if(list['roles'][n].registration == 'not available'){
|
||||
disabled = ' disabled ';
|
||||
}
|
||||
selector[0].append($('<option ' + disabled + ' value="' + list['roles'][n].id + '">' + list['roles'][n].name + '</option>'));
|
||||
selector[1].append($('<option ' + disabled + ' value="' + list['roles'][n].id + '">' + list['roles'][n].name + '</option>'));
|
||||
}
|
||||
$('#rolediv_1').prepend(selector[0]);
|
||||
$('#rolediv_2').prepend(selector[1]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>General Commands</h1>
|
||||
|
||||
@ -76,8 +101,23 @@ Schedule ID: <input type="text" name="schedule_id"></input>
|
||||
<input type="submit" value="Unregister"></input>
|
||||
</form>
|
||||
|
||||
<h1>Roles</h1>
|
||||
<a href="api/role/list">Get a list of roles for this conference</a><br/>
|
||||
|
||||
Add a role to this account
|
||||
<form method="post" action="api/role/add">
|
||||
<div id="rolediv_1">
|
||||
Password: <input name="password" type="password"></input>
|
||||
<input type="submit" value="Add Role"></input>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Remove a role from this account
|
||||
<form method="post" action="api/role/remove">
|
||||
<div id="rolediv_2">
|
||||
<input type="submit" value="Remove Role"></input>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h1>Session Variables</h1>
|
||||
<?
|
||||
|
24
user.inc.php
24
user.inc.php
@ -408,20 +408,12 @@ function user_deactivate_role($users_id, $roles_id){
|
||||
function user_remove_role(&$u, $role)
|
||||
{
|
||||
global $roles;
|
||||
$row = mysql_fetch_assoc(mysql_query("SELECT conferences_id FROM users WHERE id = " . $u['id']));
|
||||
if(!is_array($q)){
|
||||
return 'no conference';
|
||||
}
|
||||
$conference_id = $q['conferences_id'];
|
||||
$result = account_remove_role($u['accounts_id'], $roles[$role]['id'], $conference_id);
|
||||
$result = account_remove_role($u['accounts_id'], $roles[$role]['id'], $u['conferences_id']);
|
||||
|
||||
// Delete the role
|
||||
if(array_key_exists($role, $u['roles'])) {
|
||||
unset($u['roles'][$role]);
|
||||
}
|
||||
|
||||
// Save this user
|
||||
user_save($u);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -435,15 +427,23 @@ function user_delete($u, $role=false)
|
||||
$u = user_load($u);
|
||||
}
|
||||
if($role != false) {
|
||||
user_remove_role($u, $role);
|
||||
account_remove_role($u['accounts_id'], $roles[$role]['id'], $u['conferences_id']);
|
||||
if(array_key_exists($role, $u['roles'])) {
|
||||
unset($u['roles'][$role]);
|
||||
}
|
||||
|
||||
if(count($u['roles']) == 0) {
|
||||
/* No roles left, finish the delete */
|
||||
$finish_delete = true;
|
||||
}
|
||||
} else {
|
||||
/* Delete the whole user, every role */
|
||||
foreach(array_keys($u['roles']) as $r)
|
||||
user_remove_role($u, $r);
|
||||
foreach(array_keys($u['roles']) as $r){
|
||||
account_remove_role($u['accounts_id'], $roles[$r]['id'], $u['conferences_id']);
|
||||
if(array_key_exists($role, $u['roles'])) {
|
||||
unset($u['roles'][$role]);
|
||||
}
|
||||
}
|
||||
|
||||
$finish_delete = true;
|
||||
}
|
||||
|
@ -86,7 +86,9 @@ if(0) {
|
||||
|
||||
if($access_admin == 'no' && array_key_exists('admin', $u['roles'])) {
|
||||
/* Admin removed */
|
||||
user_remove_role($u, 'admin');
|
||||
// FIXME - if this block of code is ever used (surrounded by the if(0) above), then
|
||||
// the line below should be replaced with a call to account_remove_role
|
||||
//user_remove_role($u, 'admin');
|
||||
}
|
||||
|
||||
if($access_config == 'yes' && !array_key_exists('config', $u['roles'])) {
|
||||
@ -96,7 +98,9 @@ if(0) {
|
||||
|
||||
if($access_config == 'no' && array_key_exists('config', $u['roles'])) {
|
||||
/* Config removed */
|
||||
user_remove_role($u, 'config');
|
||||
// FIXME - if this block of code is ever used (surrounded by the if(0) above), then
|
||||
// the line below should be replaced with a call to account_remove_role
|
||||
//user_remove_role($u, 'config');
|
||||
}
|
||||
|
||||
/* Update superuser */
|
||||
|
Loading…
Reference in New Issue
Block a user