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 .
*/
?>
< ?
require_once ( " common.inc.php " );
require_once ( " user.inc.php " );
2010-07-15 09:18:02 +00:00
/* Ensure they're logged in as something, anything */
user_auth_required ();
2007-11-16 06:30:42 +00:00
2007-12-21 09:47:18 +00:00
$user_personal_fields = array (
2009-09-09 00:26:12 +00:00
'salutation' => array ( 'name' => 'Salutation' ),
2007-12-21 09:47:18 +00:00
'firstname' => array ( 'name' => 'First Name' ),
'lastname' => array ( 'name' => 'Last Name' ),
'address' => array ( 'name' => 'Address 1' ),
'address2' => array ( 'name' => 'Address 2' ),
'city' => array ( 'name' => 'City' ),
2009-11-28 20:07:02 +00:00
'lang' => array ( 'name' => 'Preferred Language' ),
2008-07-16 17:23:53 +00:00
'province' => array ( 'name' => $config [ 'provincestate' ]),
2007-12-21 09:47:18 +00:00
'organization' => array ( 'name' => 'Organization' ),
2008-02-15 23:08:33 +00:00
'sex' => array ( 'name' => 'Gender' ),
2008-02-23 03:28:43 +00:00
'firstaid' => array ( 'name' => 'First Aid Training' ,
'type' => 'yesno' ),
'cpr' => array ( 'name' => 'CPR Training' ,
'type' => 'yesno' ),
2007-12-21 09:47:18 +00:00
'phonehome' => array ( 'name' => 'Phone (Home)' ,
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}( x[0-9]{1,5})?$' ,
'format' => '\'NNN-NNN-NNNN\' or \'NNN-NNN-NNNN xEXT\'' ,),
'phonecell' => array ( 'name' => 'Phone (Cell)' ,
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}$' ,
'format' => '\'NNN-NNN-NNNN\'' ,),
'phonework' => array ( 'name' => 'Phone (Work)' ,
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}( x[0-9]{1,5})?$' ,
'format' => '\'NNN-NNN-NNNN\' or \'NNN-NNN-NNNN xEXT\'' ,),
'fax' => array ( 'name' => 'Fax' ,
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}$' ,
'format' => '\'NNN-NNN-NNNN\'' ,),
2008-07-16 17:23:53 +00:00
'postalcode' => array ( 'name' => $config [ 'postalzip' ],
2009-11-26 18:29:03 +00:00
'regexp' => '^(([A-Za-z][0-9][A-Za-z]( )?[0-9][A-Za-z][0-9])|([0-9]{5}))$' ,
2009-11-26 17:50:00 +00:00
'format' => '\'ANA NAN\' or \'ANANAN\' or \'NNNNN\'' ,),
2007-12-21 09:47:18 +00:00
);
2009-09-25 22:46:37 +00:00
/* Sort out who we're editting */
if ( $_POST [ 'users_id' ])
$eid = intval ( $_POST [ 'users_id' ]); /* From a save form */
else if ( array_key_exists ( 'embed_edit_id' , $_SESSION ))
$eid = $_SESSION [ 'embed_edit_id' ]; /* From the embedded editor */
else
$eid = $_SESSION [ 'users_id' ]; /* Regular entry */
if ( $eid != $_SESSION [ 'users_id' ]) {
/* Not editing ourself , we had better be
* a committee member */
2010-07-13 03:30:26 +00:00
user_auth_required ( 'admin' );
2009-09-25 22:46:37 +00:00
}
2007-12-21 09:47:18 +00:00
2009-09-09 00:26:12 +00:00
$u = user_load ( $eid );
2007-11-16 06:30:42 +00:00
/* Load the fields the user can edit, and theones that are required */
$fields = array ();
$required = array ();
2007-12-21 09:47:18 +00:00
$errorfields = array ();
2010-07-13 03:30:26 +00:00
foreach ( array_keys ( $u [ 'roles' ]) as $r ) {
2007-11-26 02:28:45 +00:00
$fields = array_merge ( $fields ,
2010-07-13 03:30:26 +00:00
user_personal_fields ( $r ));
2007-11-26 02:28:45 +00:00
$required = array_merge ( $required ,
2010-07-13 03:30:26 +00:00
user_personal_required_fields ( $r ));
2007-11-16 06:30:42 +00:00
}
2009-09-25 22:46:37 +00:00
switch ( $_GET [ 'action' ]) {
case 'save' :
$users_id = intval ( $_POST [ 'users_id' ]);
2010-07-13 03:30:26 +00:00
/* Only admin can pass in a different users_id */
2009-09-25 22:46:37 +00:00
if ( $users_id != $_SESSION [ 'users_id' ]) {
2010-07-13 03:30:26 +00:00
user_auth_required ( 'admin' );
2009-09-25 22:46:37 +00:00
}
$u = user_load ( $users_id );
2007-12-21 09:47:18 +00:00
$save = true ;
2007-11-16 06:30:42 +00:00
/* Set values */
foreach ( $fields as $f ) {
2010-06-04 20:23:59 +00:00
$u [ $f ] = stripslashes ( $_POST [ $f ]);
2009-09-26 18:18:43 +00:00
/* Allow the user to clear a field regardless of regex */
if ( $u [ $f ] == '' ) continue ;
2007-12-21 09:47:18 +00:00
/* See if this field has a validate */
if ( isset ( $user_personal_fields [ $f ][ 'regexp' ])) {
/* Match the regex */
2009-09-26 18:18:43 +00:00
if ( ! ereg ( $user_personal_fields [ $f ][ 'regexp' ], $u [ $f ])) {
2007-12-21 09:47:18 +00:00
/* Bad */
2009-11-26 17:50:00 +00:00
error_ ( " Invalid format for $f expecting ( { $user_personal_fields [ $f ][ 'format' ] } ) " );
2007-12-21 09:47:18 +00:00
$save = false ;
$errorfields [] = $f ;
}
}
2007-11-16 06:30:42 +00:00
}
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 */
user_remove_role ( $u , 'admin' );
}
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 */
user_remove_role ( $u , 'config' );
}
/* 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
}
}
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_
$u = user_load ( $users_id );
$newstatus = user_personal_info_status ( $u );
echo " <script type= \" text/javascript \" > " ;
echo " personal_update_status(' $newstatus '); \n " ;
echo " </script> \n " ;
2009-09-25 22:46:37 +00:00
exit ;
}
2007-11-17 21:59:59 +00:00
2007-11-16 06:30:42 +00:00
2007-11-17 21:59:59 +00:00
//send the header
2009-09-09 00:26:12 +00:00
if ( $_SESSION [ 'embed' ] == true ) {
echo " <br/> " ;
2009-09-25 22:53:40 +00:00
display_messages ();
2009-09-09 00:26:12 +00:00
echo " <h3> " . i18n ( " Personal Information " ) . " </h3> " ;
echo " <br/> " ;
2007-11-17 21:59:59 +00:00
} else {
2009-09-09 00:26:12 +00:00
send_header ( " Personal Information for { $u [ 'firstname' ] } { $u [ 'lastname' ] } " ,
2010-07-13 03:30:26 +00:00
array ( " Main " => " user_main.php " )
2008-08-27 17:52:46 +00:00
, " edit_profile "
2007-11-17 21:59:59 +00:00
);
}
2009-11-26 18:29:03 +00:00
$newstatus = user_personal_info_status ( $u );
2009-09-25 22:46:37 +00:00
?>
< script type = " text/javascript " >
function personal_save ()
{
2010-08-08 09:09:38 +00:00
$ ( " #debug " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_personal.php?action=save " , $ ( " #personalform " ) . serializeArray ());
2009-09-25 22:46:37 +00:00
return false ;
}
2009-11-26 18:29:03 +00:00
function personal_update_status ( s ) {
if ( s != 'complete' ) {
$ ( " #personal_info_status " ) . html ( '<?=error(i18n("Personal Information Incomplete"))?>' );
}
else
$ ( " #personal_info_status " ) . html ( '<?=happy(i18n("Personal Information Complete"))?>' );
}
2009-09-25 22:46:37 +00:00
2009-11-26 18:29:03 +00:00
//when we're ready, output the status
$ ( document ) . ready ( function () { personal_update_status ( '<?=$newstatus?>' );});
2009-09-25 22:46:37 +00:00
2009-11-26 18:29:03 +00:00
</ script >
< ?
echo " <div id= \" personal_info_status \" ></div> " ;
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-07-13 03:30:26 +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:38 +00:00
function item ( & $u , $label , $fname , $type = 'textbox' )
2007-11-16 06:30:42 +00:00
{
2010-08-08 09:09:38 +00:00
global $required , $fields , $config ;
if ( ! in_array ( $fname , $fields )) {
2007-11-16 06:30:42 +00:00
echo '<td></td><td></td>' ;
2010-08-08 09:09:38 +00:00
return ;
2007-11-16 06:30:42 +00:00
}
2010-08-08 09:09:38 +00:00
$req = in_array ( $fname , $required ) ? REQUIREDFIELD : '' ;
$c = ( $label == '' ) ? '' : ':' ;
echo " <td><label for= \" $fname\ " > $req " .i18n( $label ). " $c </ label ></ td > " ;
2007-11-16 06:30:42 +00:00
2008-02-15 23:08:33 +00:00
echo '<td>' ;
2010-08-08 09:09:38 +00:00
switch ( $type ) {
case 'textbox' :
echo " <input id= \" $fname\ " name = \ " $fname\ " type = \ " text \" value= \" { $u [ $fname ] } \" > " ;
break ;
case 'province' :
emit_province_selector ( $fname , $u [ $fname ]);
break ;
case 'yesno' :
echo " <select name= \" $fname\ " > " ;
$sel = ( $u [ $fname ] == 'yes' ) ? 'selected="selected"' : '' ;
echo " <option value= \" yes \" $sel > " . i18n ( " Yes " ) . " </option> \n " ;
$sel = ( $u [ $fname ] == 'no' ) ? 'selected="selected"' : '' ;
echo " <option value= \" no \" $sel > " . i18n ( " No " ) . " </option> \n " ;
echo " </select> " ;
break ;
case 'sex' :
echo " <select name= \" $fname\ " > " ;
echo " <option value= \" \" > " . i18n ( " Choose " ) . " </option> \n " ;
if ( $u [ 'sex' ] == " male " ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option value= \" male \" $sel > " . i18n ( " Male " ) . " </option> \n " ;
if ( $u [ 'sex' ] == " female " ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option value= \" female \" $sel > " . i18n ( " Female " ) . " </option> \n " ;
break ;
case 'language' :
echo " <select name= \" $fname\ " > " ;
echo " <option value= \" \" > " . i18n ( " Choose " ) . " </option> \n " ;
foreach ( $config [ 'languages' ] AS $l => $ln ) {
if ( $u [ 'lang' ] == $l ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option value= \" $l\ " $sel > " .i18n( $ln ). " </ option > \n " ;
}
echo " </select> " ;
break ;
2009-11-28 20:07:02 +00:00
}
echo '</td>' ;
2010-08-08 09:09:38 +00:00
}
/*
< tr >< td style = " text-align: right " colspan = " 2 " >< input type = " submit " value = " <?=i18n( " Save " )?> " /></ td ></ tr >
< tr >< td style = " text-align: left " colspan = " 2 " >< h4 > Address </ h4 >< hr /></ td ></ tr >
*/
?>
< center >
< form class = " editor " name = " personalform " id = " personal_form " >
< input type = " hidden " name = " users_id " value = " <?= $u['id'] ?> " />
< table width = " 50% " >
< tr >< td style = " text-align: left " colspan = " 2 " >< h4 > Name </ h4 >< hr /></ td ></ tr >
< tr >< ? = item ( $u , 'Salutation' , 'salutation' ) ?> </tr>
< tr >< ? = item ( $u , 'First Name' , 'firstname' ) ?> </tr>
< tr >< ? = item ( $u , 'Last Name' , 'lastname' ) ?> </tr>
< tr >< ? = item ( $u , 'Address' , 'address' ) ?> </tr>
< tr >< ? = item ( $u , '' , 'address2' ) ?> </tr>
< tr >< ? = item ( $u , 'City' , 'city' ) ?> </tr>
< tr >< ? = item ( $u , i18n ( $config [ 'provincestate' ]), 'province' , 'province' ) ?> </tr>
< tr >< ? = item ( $u , i18n ( $$config [ 'postalzip' ]), 'postalcode' ) ?> </tr>
< tr >< td style = " text-align: right " colspan = " 2 " >< input type = " submit " value = " <?=i18n( " Save " )?> " /></ td ></ tr >
< tr >< td style = " text-align: left " colspan = " 2 " >< h4 > Phone </ h4 >< hr /></ td ></ tr >
< tr >< ? = item ( $u , 'Home Phone' , 'phonehome' ) ?> </tr>
< tr >< ? = item ( $u , 'Cell' , 'phonecell' ) ?> </tr>
< tr >< td style = " text-align: right " colspan = " 2 " >< input type = " submit " value = " <?=i18n( " Save " )?> " /></ td ></ tr >
< tr >< td style = " text-align: left " colspan = " 2 " >< h4 > Misc </ h4 >< hr /></ td ></ tr >
< tr >< ? = item ( $u , 'Preferred Language' , 'lang' , 'language' ) ?> </tr>
< tr >< ? = item ( $u , 'Gender' , 'sex' , 'sex' ) ?> </tr>
< tr >< ? = item ( $u , 'First Aid Training' , 'firstaid' , 'yesno' ) ?> </tr>
< tr >< ? = item ( $u , 'CPR Training' , 'cpr' , 'yesno' ) ?> </tr>
< tr >< td style = " text-align: right " colspan = " 2 " >< input type = " submit " value = " <?=i18n( " Save " )?> " /></ td ></ tr >
< tr >< td style = " text-align: left " colspan = " 2 " >< h4 > Organization </ h4 >< hr /></ td ></ tr >
< tr >< ? = item ( $u , 'Organization Name' , 'organization' ) ?> </tr>
< tr >< ? = item ( $u , 'Phone' , 'firstaid' ) ?> </tr>
< tr >< ? = item ( $u , 'Fax' , 'fax' ) ?> </tr>
2009-11-28 20:07:02 +00:00
2008-02-23 03:28:43 +00:00
2010-08-08 09:09:38 +00:00
< ?
2007-11-16 06:30:42 +00:00
echo " </table> " ;
2007-11-17 21:59:59 +00:00
/* Committee specific fields */
2010-07-13 03:30:26 +00:00
if ( array_key_exists ( 'committee' , $u [ 'roles' ])) {
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: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 >
</ center >
< br />
2007-11-17 21:59:59 +00:00
2010-08-08 09:09:38 +00:00
< script type = " text/javascript " >
$ () . ready ( function () {
$ ( " #personalform " ) . validate ({
rules : {
firstname : {
required : true ,
},
lastname : {
required : true ,
}
},
messages : {
firstname : {
required : " <?=i18n('Please enter your first (given) name')?> " ,
},
lastnmae : {
required : " <?=i18n('Please enter your last name')?> " ,
}
},
submitHandler : function () {
personal_save ();
return false ;
},
cancelHandler : function () {
personal_save ();
return false ;
}
});
2007-11-16 06:30:42 +00:00
2010-08-08 09:09:38 +00:00
< ?
2007-11-16 06:30:42 +00:00
2009-09-09 00:26:12 +00:00
if ( $_SESSION [ 'embed' ] != true ) {
send_footer ();
}
2007-11-16 06:30:42 +00:00
?>