Fix api registration fields when roles ar epassed in

roles can be passed in as array of ids or array of types
This commit is contained in:
james 2010-10-25 23:12:35 +00:00
parent bb40bf4da1
commit 19e146547f
2 changed files with 7 additions and 1 deletions

View File

@ -640,8 +640,13 @@ switch($request[0]) {
case 'fields': case 'fields':
$reqroles=$_POST['roles']; $reqroles=$_POST['roles'];
if(is_array($reqroles)) { if(is_array($reqroles)) {
for($x=0;$x<count($reqroles);$x++) {
if(is_numeric($reqroles[$x]))
$reqroles[$x]=$roles_by_id[$reqroles[$x]];
if(!array_key_exists($reqroles[$x],$roles))
unset($reqroles[$x]);
}
$ret['status']="ok"; $ret['status']="ok";
echo "reqroles=";
$ret['fields']=user_get_fields($reqroles); $ret['fields']=user_get_fields($reqroles);
} else { } else {
//load the currently logged in user //load the currently logged in user

View File

@ -252,6 +252,7 @@ $roles=array();
$q = mysql_query("SELECT * FROM roles"); $q = mysql_query("SELECT * FROM roles");
while(($r = mysql_fetch_assoc($q))) { while(($r = mysql_fetch_assoc($q))) {
$roles[$r['type']] = $r; $roles[$r['type']] = $r;
$roles_by_id[$r['id']]=$r;
} }
//and now pull the theme //and now pull the theme