Add registration/fields API

Fix $roles array use colliding with global $roles array ($roles should never be used anywhere! its a master list of all of the roles set in the bootstrap!)
This commit is contained in:
james 2010-10-22 15:06:49 +00:00
parent bae700dead
commit a035a6f8e3
2 changed files with 41 additions and 4 deletions

View File

@ -97,7 +97,7 @@ case 'save':
<script type="text/javascript"> <script type="text/javascript">
user_update_tab_status('activities','<?=$newstatus?>'); user_update_tab_status('activities','<?=$newstatus?>');
</script> </script>
<?php <?
exit; exit;
} }

43
api.php
View File

@ -548,17 +548,17 @@ switch($request[0]) {
*/ */
case "list": case "list":
$q=mysql_query("SELECT * FROM roles ORDER BY name"); $q=mysql_query("SELECT * FROM roles ORDER BY name");
$roles=array(); $reqroles=array();
while($r=mysql_fetch_assoc($q)) { while($r=mysql_fetch_assoc($q)) {
if($config[$r['type']."_registration_type"]) { if($config[$r['type']."_registration_type"]) {
$r['registration']=$config[$r['type']."_registration_type"]; $r['registration']=$config[$r['type']."_registration_type"];
} }
else else
$r['registration']="not available"; $r['registration']="not available";
$roles[]=$r; $reqroles[]=$r;
} }
$ret['status']="ok"; $ret['status']="ok";
$ret['roles']=$roles; $ret['roles']=$reqroles;
break; break;
@ -630,6 +630,43 @@ switch($request[0]) {
} }
break; break;
case 'registration':
switch($request[1]){
/* APIDOC: registration/fields
description(retreives the list of fields required. If an array of roles is passed in it retrieves the fields for those roles, if no roles are passed in, then it uses the roles from the currently logged in user
post(roles[] array) optional
return(fields array)
*/
case 'fields':
$reqroles=$_POST['roles'];
if(is_array($reqroles)) {
$ret['status']="ok";
echo "reqroles=";
$ret['fields']=user_get_fields($reqroles);
} else {
//load the currently logged in user
if($_SESSION['users_id']) {
$u = user_load($_SESSION['users_id']);
if(is_array($u['roles']) && count($u['roles']>0)) {
$ret['status']="ok";
$ret['fields']=user_get_fields(array_keys($u['roles']));
} else {
$ret['status']="error";
$ret['error']="Currently logged in user has no roles";
}
} else {
$ret['status']="error";
$ret['error']="No roles submitted and not logged in";
}
}
break;
default:
$ret['status']="error";
$ret['error']="invalid registration API command ({$request[1]})";
}
break;
default: default:
$ret['status']="error"; $ret['status']="error";
$ret['error']="invalid API command ({$request[0]})"; $ret['error']="invalid API command ({$request[0]})";