2007-11-16 06:30:42 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
Copyright ( C ) 2007 David Grant < dave @ lightbox . org >
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation , version 2.
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; see the file COPYING . If not , write to
the Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
Boston , MA 02111 - 1307 , USA .
*/
?>
< ?
2010-08-08 09:09:46 +00:00
require_once ( 'common.inc.php' );
require_once ( 'user.inc.php' );
2010-08-08 09:09:49 +00:00
require_once ( 'user_edit.inc.php' );
2007-11-16 06:30:42 +00:00
2010-08-08 09:09:46 +00:00
/* Ensure they're logged in as something, anything */
user_auth_required ();
2007-11-16 06:30:42 +00:00
2010-08-08 09:09:46 +00:00
$edit_id = isset ( $_GET [ 'users_id' ]) ? intval ( $_GET [ 'users_id' ]) : $_SESSION [ 'users_id' ];
if ( $edit_id != $_SESSION [ 'users_id' ])
2010-07-13 03:30:26 +00:00
user_auth_required ( 'admin' );
2010-08-08 09:09:46 +00:00
else
user_auth_required ();
2007-12-21 09:47:18 +00:00
2010-08-08 09:09:46 +00:00
$u = user_load ( $edit_id );
2007-11-16 06:30:42 +00:00
/* Load the fields the user can edit, and theones that are required */
2010-08-08 09:09:49 +00:00
$fields = array ();
$required = array ();
foreach ( array_keys ( $u [ 'roles' ]) as $r ) {
2007-11-26 02:28:45 +00:00
$fields = array_merge ( $fields ,
2010-08-08 09:09:49 +00:00
user_fields_enabled ( $r ));
2007-11-26 02:28:45 +00:00
$required = array_merge ( $required ,
2010-08-08 09:09:49 +00:00
user_fields_required ( $r ));
}
/* Filter fields, only the ones we care about */
$our_fields = array ( 'salutation' , 'firstname' , 'lastname' , 'address' ,
'address2' , 'city' , 'province' , 'postalcode' ,
'phonehome' , 'phonecell' , 'language' , 'sex' ,
2011-03-03 20:52:17 +00:00
'firstaid' , 'cpr' , 'birthdate' , 'grade' );
2010-08-08 09:09:49 +00:00
$fields = array_intersect ( $our_fields , $fields );
$required = array_intersect ( $our_fields , $required );
2007-11-16 06:30:42 +00:00
2009-09-25 22:46:37 +00:00
switch ( $_GET [ 'action' ]) {
case 'save' :
2007-12-21 09:47:18 +00:00
$save = true ;
2010-08-08 09:09:49 +00:00
/* Cleanup POST data */
2007-11-16 06:30:42 +00:00
foreach ( $fields as $f ) {
2010-06-04 20:23:59 +00:00
$u [ $f ] = stripslashes ( $_POST [ $f ]);
2010-08-08 09:09:49 +00:00
/* Allow the user to clear a field */
2009-09-26 18:18:43 +00:00
if ( $u [ $f ] == '' ) continue ;
2007-11-16 06:30:42 +00:00
}
2010-08-08 09:09:49 +00:00
if ( 0 ) {
2010-07-13 03:30:26 +00:00
if ( array_key_exists ( 'committee' , $u [ 'roles' ])) {
2007-11-17 21:59:59 +00:00
/* Trying to save a committee member eh ? Well , we established above
* that we ' re allowed to be here , so go ahead and save it */
$u [ 'displayemail' ] = ( $_POST [ 'displayemail' ] == 'yes' ) ? 'yes' : 'no' ;
2009-09-25 22:46:37 +00:00
$u [ 'emailprivate' ] = mysql_real_escape_string ( stripslashes ( $_POST [ 'emailprivate' ]));
2007-11-17 21:59:59 +00:00
2010-07-13 03:30:26 +00:00
if ( $_SESSION [ 'superuser' ] == 'yes' ) {
/* Check for a change in the access flags */
$access_admin = $_POST [ 'access_admin' ];
$access_config = $_POST [ 'access_config' ];
$access_super = $_POST [ 'access_super' ];
if ( $access_admin == 'yes' && ! array_key_exists ( 'admin' , $u [ 'roles' ])) {
/* Admin added */
user_add_role ( $u , 'admin' );
}
if ( $access_admin == 'no' && array_key_exists ( 'admin' , $u [ 'roles' ])) {
/* Admin removed */
2010-10-08 18:43:20 +00:00
// FIXME - if this block of code is ever used (surrounded by the if(0) above), then
// the line below should be replaced with a call to account_remove_role
//user_remove_role($u, 'admin');
2010-07-13 03:30:26 +00:00
}
if ( $access_config == 'yes' && ! array_key_exists ( 'config' , $u [ 'roles' ])) {
/* Config added */
user_add_role ( $u , 'config' );
}
if ( $access_config == 'no' && array_key_exists ( 'config' , $u [ 'roles' ])) {
/* Config removed */
2010-10-08 18:43:20 +00:00
// FIXME - if this block of code is ever used (surrounded by the if(0) above), then
// the line below should be replaced with a call to account_remove_role
//user_remove_role($u, 'config');
2010-07-13 03:30:26 +00:00
}
/* Update superuser */
if ( $u [ 'superuser' ] != $access_super ) {
mysql_query ( " UPDATE accounts SET superuser=' $s ' WHERE id=' { $u [ 'accounts_id' ] } " );
}
2007-11-17 21:59:59 +00:00
}
}
2010-08-08 09:09:49 +00:00
}
2007-11-17 21:59:59 +00:00
2007-12-21 09:47:18 +00:00
if ( $save == true ) {
2007-11-17 21:59:59 +00:00
user_save ( $u );
2010-02-11 18:13:15 +00:00
happy_ ( " %1 %2 successfully updated " , array ( $u [ 'firstname' ], $u [ 'lastname' ]));
2009-09-26 18:18:43 +00:00
}
2009-11-26 18:29:03 +00:00
//reload the user record because we dont know if we saved or didnt save above, we just want
//to know what the user looks like _now_
2010-08-08 09:09:49 +00:00
$u = user_load ( $u [ 'id' ]);
2007-11-17 21:59:59 +00:00
2010-08-08 09:09:49 +00:00
/* Update the status */
$newstatus = user_personal_info_status ( $u );
2009-09-25 22:46:37 +00:00
?>
2010-08-08 09:09:49 +00:00
< script type = " text/javascript " >
user_update_tab_status ( 'personal' , '<?=$newstatus?>' );
</ script >
< ?
exit ;
2009-11-26 18:29:03 +00:00
}
2009-09-25 22:46:37 +00:00
2007-11-17 21:59:59 +00:00
2010-07-13 03:30:26 +00:00
if ( count ( $u [ 'roles' ]) > 1 ) {
$str = '' ;
foreach ( array_keys ( $u [ 'roles' ]) as $r ) {
$str .= (( $str == '' ) ? '' : ', ' ) . i18n ( $roles [ $r ][ 'name' ]);
2007-11-17 21:59:59 +00:00
}
2010-08-08 09:09:49 +00:00
// echo notice(i18n('This user has multiple roles, the fields shown below are a combination of every role. Some may not apply to some roles. This user has the following roles:').' '.$str);
2007-11-16 06:30:42 +00:00
}
2010-08-08 09:09:49 +00:00
?>
< h4 >< ? = i18n ( " Personal Information " ) ?> - <span class="status_personal"></span></h4>
< br />
2010-08-08 09:09:38 +00:00
2010-08-08 09:09:46 +00:00
< form class = " editor " id = " personalform " >
< table width = " 90% " >
< tr >< td style = " text-align: left " colspan = " 2 " >< b > Name </ b ' >< hr /></ td ></ tr >
2010-08-08 09:09:49 +00:00
< tr >< ? = user_edit_item ( $u , 'Salutation' , 'salutation' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'First Name' , 'firstname' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'Last Name' , 'lastname' ) ?> </tr>
2010-08-08 09:09:46 +00:00
< tr >< td style = " text-align: left " colspan = " 2 " >< b > Address </ b >< hr /></ td ></ tr >
2010-08-08 09:09:49 +00:00
< tr >< ? = user_edit_item ( $u , 'Address' , 'address' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , '' , 'address2' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'City' , 'city' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , i18n ( $config [ 'provincestate' ]), 'province' , 'province' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , i18n ( $config [ 'postalzip' ]), 'postalcode' ) ?> </tr>
2010-08-08 09:09:46 +00:00
< ? /*<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
?>
2010-08-08 09:09:38 +00:00
2010-08-08 09:09:46 +00:00
< tr >< td style = " text-align: left " colspan = " 2 " >< b > Phone </ b ' >< hr /></ td ></ tr >
2010-08-08 09:09:49 +00:00
< tr >< ? = user_edit_item ( $u , 'Home Phone' , 'phonehome' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'Cell' , 'phonecell' ) ?> </tr>
2010-08-08 09:09:46 +00:00
< ? /*<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
?>
2010-08-08 09:09:38 +00:00
2010-08-08 09:09:46 +00:00
< tr >< td style = " text-align: left " colspan = " 2 " >< b > Other Information </ b ' >< hr /></ td ></ tr >
2010-08-08 09:09:49 +00:00
< tr >< ? = user_edit_item ( $u , 'Preferred Language' , 'lang' , 'language' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'Gender' , 'sex' , 'sex' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'First Aid Training' , 'firstaid' , 'yesno' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'CPR Training' , 'cpr' , 'yesno' ) ?> </tr>
2011-03-03 20:52:17 +00:00
< tr >< ? = user_edit_item ( $u , 'Birth Date' , 'birthdate' ) ?> </tr>
< tr >< ? = user_edit_item ( $u , 'Grade' , 'grade' ) ?> </tr>
2009-11-28 20:07:02 +00:00
2010-08-08 09:09:49 +00:00
</ table >
2008-02-23 03:28:43 +00:00
2010-08-08 09:09:38 +00:00
< ?
2007-11-16 06:30:42 +00:00
2010-08-08 09:09:46 +00:00
2007-11-17 21:59:59 +00:00
/* Committee specific fields */
2010-08-08 09:09:46 +00:00
if ( array_key_exists ( 'committee' , $u [ 'roles' ]) && false ) {
2007-11-26 02:28:45 +00:00
echo " <table> " ;
2007-11-17 21:59:59 +00:00
echo " <tr><td> " . i18n ( " Email (Private) " ) . " :</td><td><input size= \" 25 \" type= \" text \" name= \" emailprivate \" value= \" { $u [ 'emailprivate' ] } \" /></td></tr> \n " ;
echo " <tr><td> " . i18n ( " Display Emails " ) . " :</td><td> " ;
if ( $u [ 'displayemail' ] == " no " ) $checked = " checked= \" checked \" " ; else $checked = " " ;
echo " <input type= \" radio \" name= \" displayemail \" value= \" no \" $checked /> " . i18n ( " No " );
echo " " ;
if ( $u [ 'displayemail' ] == " yes " ) $checked = " checked= \" checked \" " ; else $checked = " " ;
echo " <input type= \" radio \" name= \" displayemail \" value= \" yes \" $checked /> " . i18n ( " Yes " );
2010-07-13 03:30:26 +00:00
if ( $_SESSION [ 'superuser' ] == 'yes' ) {
2007-11-17 21:59:59 +00:00
/* If the user is a committee member , only print these fields
* if the editer has super access */
echo " <tr><td align= \" center \" colspan= \" 2 \" ><hr /></td></tr> " ;
echo " <tr><td> " . i18n ( " Access Controls " ) . " :</td><td> " ;
2010-07-13 03:30:26 +00:00
$ch = ( array_key_exists ( 'admin' , $u [ 'roles' ])) ? 'checked="checked"' : '' ;
2007-11-17 21:59:59 +00:00
echo " <input type= \" checkbox \" name= \" access_admin \" value= \" yes \" $ch /> " . i18n ( " Administration " ) . " <br /> " ;
2010-07-13 03:30:26 +00:00
$ch = ( array_key_exists ( 'config' , $u [ 'roles' ])) ? 'checked="checked"' : '' ;
2007-11-17 21:59:59 +00:00
echo " <input type= \" checkbox \" name= \" access_config \" value= \" yes \" $ch /> " . i18n ( " Configuration " ) . " <br /> " ;
2010-07-13 03:30:26 +00:00
$ch = ( $u [ 'superuser' ] == " yes " ) ? 'checked="checked"' : '' ;
2007-11-17 21:59:59 +00:00
echo " <input type= \" checkbox \" name= \" access_super \" value= \" yes \" $ch /> " . i18n ( " Superuser " ) . " <br /> " ;
echo " </td></tr> " ;
}
echo '</table>' ;
}
2010-08-08 09:09:49 +00:00
function vreq ( $field )
{
global $required ;
/* Return 'true' or 'false' as text for the
* validator plugin to use for the 'required' param */
if ( in_array ( $field , $required )) return 'true' ;
return 'false' ;
}
2010-08-08 09:09:38 +00:00
?>
2007-11-17 21:59:59 +00:00
2010-08-08 09:09:38 +00:00
< input type = " submit " value = " <?=i18n( " Save Personal Information " )?> " />
</ form >
< br />
2007-11-17 21:59:59 +00:00
2010-08-08 09:09:38 +00:00
< script type = " text/javascript " >
2010-08-08 09:09:49 +00:00
function personal_save ()
{
$ ( " #debug " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_personal.php?action=save&users_id=<?= $edit_id ?> " , $ ( " #personalform " ) . serializeArray ());
return false ;
}
2010-08-08 09:09:46 +00:00
/* This method from the form validator additional methods script , modified to not
* allow spaces or parentheses */
jQuery . validator . addMethod ( " phoneUS " , function ( phone_number , element ) {
phone_number = phone_number . replace ( / \s +/ g , " " );
return this . optional ( element ) || phone_number . length > 9 &&
phone_number . match ( /^ [ 2 - 9 ] \d { 2 } - [ 2 - 9 ] \d { 2 } - \d { 4 } $ / );
2010-10-14 19:42:20 +00:00
}, " Please specify a valid phone number (NNN-NNN-NNNN) " );
2010-08-08 09:09:46 +00:00
2010-08-08 09:09:49 +00:00
$ ( document ) . ready ( function () {
2010-08-08 09:09:38 +00:00
$ ( " #personalform " ) . validate ({
rules : {
2010-08-08 09:09:49 +00:00
firstname : { required : < ? = vreq ( 'firstname' ) ?> },
lastname : { required : < ? = vreq ( 'lastname' ) ?> },
address : { required : < ? = vreq ( 'address' ) ?> },
city : { required : < ? = vreq ( 'city' ) ?> },
province : { required : < ? = vreq ( 'province' ) ?> },
postalcode : { required : < ? = vreq ( 'postalcode' ) ?> },
2010-08-08 09:09:46 +00:00
phonehome : {
2010-08-08 09:09:49 +00:00
required : < ? = vreq ( 'phonehome' ) ?> ,
2010-08-08 09:09:46 +00:00
phoneUS : true
2010-08-08 09:09:38 +00:00
},
2010-08-08 09:09:46 +00:00
phonecell : {
2010-08-08 09:09:49 +00:00
required : < ? = vreq ( 'phonecell' ) ?> ,
2010-08-08 09:09:46 +00:00
phoneUS : true
},
2010-08-08 09:09:49 +00:00
lang : { required : < ? = vreq ( 'lang' ) ?> },
sex : { required : < ? = vreq ( 'sex' ) ?> },
firstaid : { required : < ? = vreq ( 'firstaid' ) ?> },
cpr : { required : < ? = vreq ( 'cpr' ) ?> }
2010-08-08 09:09:38 +00:00
},
messages : {
2010-08-08 09:09:46 +00:00
firstname : { required : " <?=i18n('Please enter your first (given) name')?> " },
lastname : { required : " <?=i18n('Please enter your last name')?> " },
address : { required : " <?=i18n('Please enter your street address')?> " },
city : { required : " <?=i18n('Please enter your city')?> " },
province : { required : " <?=i18n('Please enter your province')?> " },
postalcode : { required : " <?=i18n('Please enter your postal code')?> " },
phonehome : {
required : " <?=i18n('Please enter your home phone number')?> " ,
phoneUS : " <?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?> "
},
phonecell : {
required : " <?=i18n('Please enter your cell phone number')?> " ,
phoneUS : " <?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?> "
},
lang : { required : " <?=i18n('Please select your preferred language of communication')?> " },
sex : { required : " <?=i18n('Please select your gender')?> " },
firstaid : { required : " <?=i18n('Please select yes or no')?> " },
cpr : { required : " <?=i18n('Please select yes or no')?> " }
2010-08-08 09:09:38 +00:00
},
submitHandler : function () {
personal_save ();
return false ;
},
2010-08-08 09:09:49 +00:00
invalidHandler : function () {
2010-08-08 09:09:38 +00:00
personal_save ();
return false ;
}
});
2010-08-08 09:09:49 +00:00
user_update_tab_status ( 'personal' );
2010-08-08 09:09:46 +00:00
});
</ script >
2007-11-16 06:30:42 +00:00