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 " );
2007-11-17 21:59:59 +00:00
require_once ( " committee.inc.php " );
2007-11-16 06:30:42 +00:00
if ( ! isset ( $_SESSION [ 'users_type' ])) {
/* No type set, invalid session */
echo " ERROR: session is invalid " ;
exit ;
}
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' ),
'email' => array ( 'name' => 'Email Address' ),
'username' => array ( 'name' => 'Username' ),
'password' => array ( 'name' => 'Password' ),
'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 */
user_auth_required ( 'committee' , 'admin' );
}
2009-11-26 18:29:03 +00:00
$type = $_SESSION [ 'users_type' ];
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 ();
2007-11-16 06:30:42 +00:00
foreach ( $u [ 'types' ] as $t ) {
2007-11-26 02:28:45 +00:00
$fields = array_merge ( $fields ,
2007-11-16 06:30:42 +00:00
user_personal_fields ( $t ));
2007-11-26 02:28:45 +00:00
$required = array_merge ( $required ,
2007-11-16 06:30:42 +00:00
user_personal_required_fields ( $t ));
}
2007-11-17 21:59:59 +00:00
if ( committee_auth_has_access ( 'super' )) {
2007-11-26 02:28:45 +00:00
/* If the editer is super, let them see/edit/save the user/pass */
$fields [] = 'username' ;
2007-11-17 21:59:59 +00:00
$fields [] = 'password' ;
}
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' ]);
if ( $users_id != $_SESSION [ 'users_id' ]) {
user_auth_required ( 'committee' , 'admin' );
}
$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-02-11 18:13:15 +00:00
$u [ $f ] = iconv ( " UTF-8 " , " ISO-8859-1 " , 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-03-29 19:33:29 +00:00
if ( ! in_array ( 'username' , $fields ) || ! array_key_exists ( 'username' , $u ) || $u [ 'username' ] == '' ) {
2007-11-29 18:37:40 +00:00
$u [ 'username' ] = $u [ 'email' ];
}
2007-11-17 21:59:59 +00:00
if ( in_array ( 'committee' , $u [ 'types' ])) {
/* 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
if ( committee_auth_has_access ( 'super' )) {
/* But only superusers can save these ones */
$u [ 'access_admin' ] = ( $_POST [ 'access_admin' ] == 'yes' ) ? 'yes' : 'no' ;
$u [ 'access_config' ] = ( $_POST [ 'access_config' ] == 'yes' ) ? 'yes' : 'no' ;
$u [ 'access_super' ] = ( $_POST [ 'access_super' ] == 'yes' ) ? 'yes' : 'no' ;
}
}
/* Check for an email collision */
$em = mysql_escape_string ( stripslashes ( $_POST [ 'email' ]));
2010-02-10 16:02:51 +00:00
$q = mysql_query ( " SELECT *,max(year) FROM users WHERE email=' $em ' HAVING uid!=' { $u [ 'uid' ] } ' AND deleted='no' " );
2007-11-17 21:59:59 +00:00
if ( mysql_num_rows ( $q ) > 0 ) {
2009-09-25 22:46:37 +00:00
error_ ( " That email address is in use by another user " );
2009-09-26 18:18:43 +00:00
echo " email error " ;
2007-12-21 09:47:18 +00:00
$save = false ;
}
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' ] } " ,
array ( $user_what [ $type ] . " Registration " => " { $type } _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 ()
{
$ ( " #debug " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_personal.php?action=save " , $ ( " #personal_form " ) . serializeArray ());
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
if ( count ( $u [ 'types' ]) > 1 ) {
$roles = '' ;
foreach ( $u [ 'types' ] as $t ) {
$roles .= (( $roles == '' ) ? '' : ', ' ) . i18n ( $user_what [ $t ]);
}
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:' ) . ' ' . $roles );
2007-11-16 06:30:42 +00:00
}
2007-12-21 09:47:18 +00:00
function item ( $user , $fname , $subtext = '' )
2007-11-16 06:30:42 +00:00
{
global $fields , $required ;
2007-12-21 09:47:18 +00:00
global $errorfields ;
global $user_personal_fields ;
2007-11-16 06:30:42 +00:00
if ( in_array ( $fname , $fields )) {
2007-12-21 09:47:18 +00:00
$text = i18n ( $user_personal_fields [ $fname ][ 'name' ]);
if ( in_array ( $fname , $errorfields )) $style = 'style="color:red;"' ;
echo " <td><span $style > $text </span>: " ;
2007-11-29 18:37:40 +00:00
if ( $subtext != '' ) echo '<br /><span style="font-size: 0.5em;">' . i18n ( $subtext ) . '</span>' ;
2008-02-23 03:28:43 +00:00
echo '</td><td>' ;
$req = in_array ( $fname , $required ) ? REQUIREDFIELD : '' ;
switch ( $user_personal_fields [ $fname ][ 'type' ]) {
case 'yesno' :
echo " <select name= \" $fname\ " > " ;
$sel = ( $user [ $fname ] == 'yes' ) ? 'selected="selected"' : '' ;
echo " <option value= \" yes \" $sel > " . i18n ( " Yes " ) . " </option> \n " ;
$sel = ( $user [ $fname ] == 'no' ) ? 'selected="selected"' : '' ;
echo " <option value= \" no \" $sel > " . i18n ( " No " ) . " </option> \n " ;
echo " </select> $req " ;
break ;
default :
echo " <input onchange= \" fieldChanged() \" type= \" text \" name= \" $fname\ " value = \ " { $user [ $fname ] } \" /> $req " ;
break ;
}
2007-11-16 06:30:42 +00:00
echo '</td>' ;
} else {
echo '<td></td><td></td>' ;
}
}
2009-09-25 22:46:37 +00:00
echo " <form name= \" personalform \" id= \" personal_form \" > \n " ;
echo " <input type= \" hidden \" name= \" users_id \" value= \" { $u [ 'id' ] } \" /> " ;
2007-11-16 06:30:42 +00:00
echo " <table> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'firstname' );
item ( $u , 'lastname' );
2007-11-16 06:30:42 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'email' );
2009-09-09 00:26:12 +00:00
item ( $u , 'salutation' );
2007-11-26 02:28:45 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'username' , '(if different from Email)' );
item ( $u , 'password' );
2007-11-16 06:30:42 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'address' );
item ( $u , 'city' );
2007-11-16 06:30:42 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'address2' );
2007-11-16 06:30:42 +00:00
if ( in_array ( 'province' , $fields )) {
2008-07-16 17:23:53 +00:00
echo '<td>' . i18n ( $config [ 'provincestate' ]) . ': </td>' ;
2007-11-16 06:30:42 +00:00
echo '<td>' ;
2007-12-12 23:56:33 +00:00
emit_province_selector ( " province " , $u [ 'province' ], " onchange= \" fieldChanged() \" " );
2007-11-16 06:30:42 +00:00
if ( in_array ( 'province' , $required )) echo REQUIREDFIELD ;
echo '</td>' ;
} else {
echo '<td></td><td></td>' ;
}
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'postalcode' );
2007-11-16 06:30:42 +00:00
echo " <td></td><td></td> " ;
echo " </tr> \n " ;
echo " <tr> " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'phonehome' );
item ( $u , 'phonecell' );
2007-11-16 06:30:42 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'organization' );
item ( $u , 'phonework' );
2007-11-16 06:30:42 +00:00
echo " </tr> " ;
echo " <tr> \n " ;
2007-12-21 09:47:18 +00:00
item ( $u , 'fax' );
2008-02-15 23:08:33 +00:00
if ( in_array ( 'sex' , $fields )) {
echo '<td>' . i18n ( 'Gender' ) . ': </td>' ;
echo '<td>' ;
echo " <select name= \" sex \" > " ;
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 " ;
echo " </select> " ;
if ( in_array ( 'sex' , $required )) echo REQUIREDFIELD ;
echo '</td>' ;
} else {
echo '<td></td><td></td>' ;
}
2007-11-16 06:30:42 +00:00
echo " </tr> " ;
2008-02-23 03:28:43 +00:00
echo " <tr> \n " ;
item ( $u , 'firstaid' );
item ( $u , 'cpr' );
echo " </tr> " ;
2009-11-28 20:07:02 +00:00
echo " <tr> \n " ;
if ( in_array ( 'lang' , $fields )) {
echo '<td>' . i18n ( 'Preferred Lang' ) . ': </td>' ;
echo '<td>' ;
echo " <select name= \" lang \" > " ;
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> " ;
if ( in_array ( 'lang' , $required )) echo REQUIREDFIELD ;
echo '</td>' ;
} else {
echo '<td></td><td></td>' ;
}
echo " <td></td><td></td> " ;
echo " </tr> " ;
2008-02-23 03:28:43 +00:00
2007-11-16 06:30:42 +00:00
echo " <tr><td colspan= \" 4 \" ><hr /></td></tr> " ;
echo " </table> " ;
2007-11-17 21:59:59 +00:00
/* Committee specific fields */
if ( in_array ( 'committee' , $u [ 'types' ])) {
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 " );
if ( committee_auth_has_access ( " super " ))
{
/* 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> " ;
$ch = ( $u [ 'access_admin' ] == " yes " ) ? 'checked="checked"' : '' ;
echo " <input type= \" checkbox \" name= \" access_admin \" value= \" yes \" $ch /> " . i18n ( " Administration " ) . " <br /> " ;
$ch = ( $u [ 'access_config' ] == " yes " ) ? 'checked="checked"' : '' ;
echo " <input type= \" checkbox \" name= \" access_config \" value= \" yes \" $ch /> " . i18n ( " Configuration " ) . " <br /> " ;
$ch = ( $u [ 'access_super' ] == " yes " ) ? 'checked="checked"' : '' ;
echo " <input type= \" checkbox \" name= \" access_super \" value= \" yes \" $ch /> " . i18n ( " Superuser " ) . " <br /> " ;
echo " </td></tr> " ;
}
echo '</table>' ;
}
2009-09-25 22:46:37 +00:00
echo " <input type= \" submit \" onclick= \" personal_save();return false; \" value= \" " . i18n ( " Save Personal Information " ) . " \" /> \n " ;
2007-11-16 06:30:42 +00:00
echo " </form> " ;
echo " <br /> " ;
2009-09-09 00:26:12 +00:00
if ( $_SESSION [ 'embed' ] != true ) {
send_footer ();
}
2007-11-16 06:30:42 +00:00
?>