Removed some usage of old user functions. Added role handling in testapi.php

This commit is contained in:
jacob 2010-10-08 18:43:20 +00:00
parent 835047f3a8
commit 7d5f5cccd0
3 changed files with 59 additions and 15 deletions

View File

@ -1,7 +1,32 @@
<? <?
include "common.inc.php"; 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> <h1>General Commands</h1>
@ -76,8 +101,23 @@ Schedule ID: <input type="text" name="schedule_id"></input>
<input type="submit" value="Unregister"></input> <input type="submit" value="Unregister"></input>
</form> </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> <h1>Session Variables</h1>
<? <?

View File

@ -408,20 +408,12 @@ function user_deactivate_role($users_id, $roles_id){
function user_remove_role(&$u, $role) function user_remove_role(&$u, $role)
{ {
global $roles; global $roles;
$row = mysql_fetch_assoc(mysql_query("SELECT conferences_id FROM users WHERE id = " . $u['id'])); $result = account_remove_role($u['accounts_id'], $roles[$role]['id'], $u['conferences_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);
// Delete the role // Delete the role
if(array_key_exists($role, $u['roles'])) { if(array_key_exists($role, $u['roles'])) {
unset($u['roles'][$role]); unset($u['roles'][$role]);
} }
// Save this user
user_save($u);
return $result; return $result;
} }
@ -435,15 +427,23 @@ function user_delete($u, $role=false)
$u = user_load($u); $u = user_load($u);
} }
if($role != false) { 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) { if(count($u['roles']) == 0) {
/* No roles left, finish the delete */ /* No roles left, finish the delete */
$finish_delete = true; $finish_delete = true;
} }
} else { } else {
/* Delete the whole user, every role */ /* Delete the whole user, every role */
foreach(array_keys($u['roles']) as $r) foreach(array_keys($u['roles']) as $r){
user_remove_role($u, $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; $finish_delete = true;
} }

View File

@ -86,7 +86,9 @@ if(0) {
if($access_admin == 'no' && array_key_exists('admin', $u['roles'])) { if($access_admin == 'no' && array_key_exists('admin', $u['roles'])) {
/* Admin removed */ /* 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'])) { 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'])) { if($access_config == 'no' && array_key_exists('config', $u['roles'])) {
/* Config removed */ /* 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 */ /* Update superuser */