The API depends on a return value from the user_save function, which was not being generated.

Updated user_save to return 'ok' on success, and an error message otherwise.
Updated api.php to make use of user_save's retun value.
This commit is contained in:
jacob 2010-11-17 21:02:32 +00:00
parent 6c5669c3f4
commit 1b098f85b3
2 changed files with 16 additions and 8 deletions

View File

@ -26,12 +26,13 @@ include "common.inc.php";
require_once("account.inc.php");
require_once("user.inc.php");
require_once("schedule.inc.php");
/*
if($_SERVER['HTTPS']!="on") {
$ret['status']="error";
$ret['error']="SSL is required for API access, please access the API over https";
echo json_encode($ret);
exit;
}
}*/
$request=explode("/",$_GET['request']);
$ret=array();
@ -562,13 +563,13 @@ switch($request[0]) {
}
$u['orig']=$origu['orig'];
if(user_save($u)) {
$result = user_save($u);
if($result == 'ok') {
$ret['status']="ok";
$ret['user']=$u;
} else {
$ret['status']="error";
$ret['error']="Error saving user";
$ret['error']=$result;
}
}
else {

View File

@ -619,18 +619,19 @@ function user_save(&$u)
global $conference;
global $roles;
$errMessage = '';
/* Sanity check */
if($u['conferences_id'] != $u['orig']['conferences_id']) {
//echo "The user's conference changed. Can't save a user to a difference conference, use user_dupe to copy the user to a new conference.\n";
return -1;
return "The user's conference changed. Can't save a user to a difference conference, use user_dupe to copy the user to a new conference.";
}
// Update 'active' status for all roles
$new_roles = array_keys($u['roles']);
foreach($new_roles as $r) {
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}' WHERE roles_id='{$u['roles'][$r]['roles_id']}' AND users_id='{$u['id']}'");
echo mysql_error();
if(mysql_error() != '') break;
}
if(mysql_error() != '') return mysql_error();
$fields = array('salutation','firstname','lastname',
'phonehome','phonework','phonecell','fax','organization',
@ -675,8 +676,8 @@ function user_save(&$u)
if($set != "") {
$query = "UPDATE users SET $set WHERE id='{$u['id']}'";
mysql_query($query);
echo mysql_error();
}
if(mysql_error() != '') return mysql_error();
// Save the other user data that is not stored in the users table
@ -692,6 +693,7 @@ function user_save(&$u)
mysql_query($query);
}
}
if(mysql_error() != '') return mysql_error();
if( // if this user has an altered available judging times selection, we need to save it
array_key_exists('available_times', $u) &&
@ -715,6 +717,7 @@ function user_save(&$u)
mysql_query($query);
}
}
if(mysql_error() != '') return mysql_error();
if( // if this user has an altered event availability selection, we need to save it
array_key_exists('available_events', $u) &&
@ -728,6 +731,7 @@ function user_save(&$u)
mysql_query($query);
}
}
if(mysql_error() != '') return mysql_error();
if( // if this user has an altered selection of volunteer positions, we'll need to change that too
array_key_exists('volunteer_positions', $u) &&
@ -741,6 +745,7 @@ function user_save(&$u)
mysql_query($query);
}
}
if(mysql_error() != '') return mysql_error();
/* Record all the data in orig that we saved so subsequent
* calls to user_save don't try to overwrite data already
@ -749,6 +754,8 @@ function user_save(&$u)
$orig = $u;
$u['orig'] = $orig;
// and return a notification of success
return 'ok';
}
// mark the role as complete if it's qualifications are met