Implement user/edit

Remove saving some stuff from user_save
This commit is contained in:
james 2010-10-01 19:42:52 +00:00
parent 895bcc36e2
commit a92544bbea
2 changed files with 36 additions and 14 deletions

41
api.php
View File

@ -437,14 +437,8 @@ switch($request[0]) {
*/ */
case "view": case "view":
if($u=user_load($_SESSION['users_id'])) { if($u=user_load($_SESSION['users_id'])) {
//we dont need to send the 'orig' part of it
unset($u['orig']); unset($u['orig']);
unset($u['types']);
unset($u['username']);
unset($u['password']);
unset($u['year']);
unset($u['access_admin']);
unset($u['access_config']);
unset($u['access_super']);
$ret['status']="ok"; $ret['status']="ok";
$ret['user']=$u; $ret['user']=$u;
} }
@ -453,14 +447,43 @@ switch($request[0]) {
$ret['error']="Error loading user"; $ret['error']="Error loading user";
} }
break; break;
}
/* APIDOC: user/edit /* APIDOC: user/edit
notimplemented
description(edit user information for current conference) description(edit user information for current conference)
post(user array) post(user array)
return(user array) return(user array)
*/ */
case "edit":
if($origu=user_load($_SESSION['users_id'])) {
$u=json_decode($_POST['user']);
if(!is_array($u)) {
$ret['status']="error";
$ret['error']="user (array) is required";
break;
}
if($origu['id']!=$u['id']) {
$ret['status']="error";
$ret['error']="User ID mismatch";
break;
}
$u['orig']=$origu['orig'];
if(user_save($u)) {
$ret['status']="ok";
$ret['user']=$u;
} else {
$ret['status']="error";
$ret['error']="Error saving user";
}
}
else {
$ret['status']="error";
$ret['error']="Error loading user in order to edit";
}
break;
}
break; break;
default: default:

View File

@ -241,8 +241,8 @@ function user_save(&$u)
/* Sanity check */ /* Sanity check */
if($u['conferences_id'] != $u['orig']['conferences_id']) { 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"; //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";
exit; return -1;
} }
/* Add any new roles */ /* Add any new roles */
@ -277,13 +277,12 @@ function user_save(&$u)
} }
$fields = array('salutation','firstname','lastname','username', $fields = array('salutation','firstname','lastname',
'phonehome','phonework','phonecell','fax','organization', 'phonehome','phonework','phonecell','fax','organization',
'address','address2','city','province','postalcode','sex', 'address','address2','city','province','postalcode','sex',
'firstaid', 'cpr', 'lang', 'notes'); 'firstaid', 'cpr', 'lang', 'notes');
$fields_for_role['committee'] = array('emailprivate','ord','displayemail', $fields_for_role['committee'] = array('emailprivate','ord','displayemail');
'access_admin','access_config','access_super');
$fields_for_role['judge'] = array('years_school','years_regional','years_national', $fields_for_role['judge'] = array('years_school','years_regional','years_national',
'willing_chair','special_award_only', 'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs', 'cat_prefs','div_prefs','divsub_prefs',