forked from science-ation/science-ation
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:
parent
bae700dead
commit
a035a6f8e3
@ -97,7 +97,7 @@ case 'save':
|
||||
<script type="text/javascript">
|
||||
user_update_tab_status('activities','<?=$newstatus?>');
|
||||
</script>
|
||||
<?php
|
||||
<?
|
||||
exit;
|
||||
}
|
||||
|
||||
|
43
api.php
43
api.php
@ -548,17 +548,17 @@ switch($request[0]) {
|
||||
*/
|
||||
case "list":
|
||||
$q=mysql_query("SELECT * FROM roles ORDER BY name");
|
||||
$roles=array();
|
||||
$reqroles=array();
|
||||
while($r=mysql_fetch_assoc($q)) {
|
||||
if($config[$r['type']."_registration_type"]) {
|
||||
$r['registration']=$config[$r['type']."_registration_type"];
|
||||
}
|
||||
else
|
||||
$r['registration']="not available";
|
||||
$roles[]=$r;
|
||||
$reqroles[]=$r;
|
||||
}
|
||||
$ret['status']="ok";
|
||||
$ret['roles']=$roles;
|
||||
$ret['roles']=$reqroles;
|
||||
|
||||
break;
|
||||
|
||||
@ -630,6 +630,43 @@ switch($request[0]) {
|
||||
}
|
||||
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:
|
||||
$ret['status']="error";
|
||||
$ret['error']="invalid API command ({$request[0]})";
|
||||
|
Loading…
Reference in New Issue
Block a user