<%
# $Id: account.php,v 1.21 2005/04/18 12:44:50 hirokai Exp $
include_once( "modules/utils.inc.php" );
$site = getSiteUrl();
$tok = $authenticated = $_COOKIE["c_pass_token"];
$u = $sessionUserId = $_COOKIE["c_uid"];
$max_profile_image_size = 100000;
%>
<title> Feed Me Links : My Profile </title>
<% include( "$modules/header.inc.php" ); %>
<br />
<%
if( $tok && $tok == md5( getPasswdForUser( $u )) ) {
$con_account = mysql_connect();
mysql_selectdb( getDBName() );
if( $op == "update-email" ) {
if( $email ) {
$email = urlencode( $email );
$qs = "UPDATE linksUsers SET email = '$email' WHERE userId = '$u'";
$successEmail = mysql_query( $qs );
$showForm = 1;
%>
<div class="attention">
<div class="warning">
Updating your email address to <u><%= urldecode( $email ) %></u> ...
<%
if( $successEmail )
echo "DONE!";
else
echo "failed.";
$showForm = 1;
%>
</div>
</div>
<%
} else {
$showForm = 1;
warn( "Please enter your new email address first." );
}
} else if( $op == "update-password" ) {
if( $password1 == $password2 ) {
$password = urlencode( $password1 );
$qs = "UPDATE linksUsers SET password = '$password' WHERE userId = '$u'";
$successPass = mysql_query( $qs );
%>
<div class="attention">
<div class="warning">
Updating your password...
<%
# SLOPPY / WRONG:
if( $successPass )
echo "DONE!";
else
echo "failed.";
$showForm = 1;
%>
</div>
</div>
<%
} else {
warn( "Sorry, the password you typed doesn't match what we have on file."
. "<p />"
. "<a class='hot' href='/misc/forgot-password'>Did you forget your password? No worries, we’ll mail it to you!"
. " <b>Click to have it re-sent via email</b></a>"
);
}
} else if( $op == "update-profile-image" ) {
echo "Uploading your new profile image...";
$ext = substr( $_FILES['profile_image']['name'], -3);
if( !strcasecmp( $ext, "gif" ) || !strcasecmp( $ext, "jpg" ) || !strcasecmp( $ext, "png" ) ) {
if( $_FILES['profile_image']['size '] < $max_profile_image_size ) {
$uploadDir = get_root() . "/usr/$u";
$uploadFile = $uploadDir . "/profile." . strtolower( $ext );
if( !is_dir( $uploadDir ) || !is_writable( $uploadDir )) {
$old_umask = umask(0);
mkdir( $uploadDir );
umask($old_umask);
}
removeOldProfileImage( $u );
if( move_uploaded_file($_FILES['profile_image']['tmp_name'], $uploadFile)) {
# fix perms:
chmod( $uploadFile, 0666 );
%>
<div class="attention">
Your new image was successfully added to your profile.
</div>
<br />
<%
showUserImage( $u );
%>
<h2><a style="color: #ff6600;" href="/account">« Back to your profile.</a></h2>
or <h2><a style="color: #ff6600;" href="/">« Back to your links.</a></h2>
<%
} else {
warn( "Owch, invalid file upload!" );
print "<pre>Here's some debugging info:\n";
print_r($_FILES);
print "</pre>";
}
} else { # file too big
warn( "Sorry, your profile image must be smaller than 100k. Please try again." );
}
} else {
# bad file extension or no FILE
if( $_FILES['profile_image']['name'] ) {
warn( "Sorry, your profile image can only be a GIF, JPEG, or PNG file. "
. "Did you remember to click <b>Browse</b> and select the image "
. "to upload first? Please try again." );
}
$showForm = 1;
}
} else {
$showForm = 1;
}
if( $showForm == 1 ) {
$qs = "SELECT * FROM linksUsers WHERE userId = '$u'";
$q = mysql_query( $qs );
$numRows = mysql_num_rows($q);
if( $numRows ) {
$email = urldecode( mysql_result($q,0,"email"));
}
conClose( $con_account );
%>
<script language="javascript">
<!--
function check_email( f ) {
var e = f.email.value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if( e == '' ) {
alert( "Please enter your email address." );
return false;
} else if( ! filter.test( e )) {
alert( "Please double-check your email address." );
return false;
} else {
return true;
}
}
function check_passwords( f ) {
var p1 = f.password1.value;
var p2 = f.password2.value;
if( p1 == '' && p2 == '' ) {
alert( "Please enter a new password." );
return false;
} else if( p1 == '' ) {
alert( "Please confirm your new password by entering it in both fields." );
return false;
} else if( p2 == '' ) {
alert( "Please confirm your new password by entering it in both fields." );
return false;
} else if( p1 != p2 ) {
alert( "Please make sure your password is typed correctly in both fields." );
return false;
} else {
return true;
}
}
// -->
</script>
<form method="post" action="/account" name="profile_email_form"
onSubmit="return check_email(document.forms.profile_email_form);">
<input type="hidden" name="op" value="update-email" />
<div id="accountBox" style="width: 48em;">
<div class="subhead">
MY PROFILE:
</div>
<div class="r0" style="width: 47em; height: 24em;">
<div style="float: left;">
<table border="0" width="450">
<tr>
<td>
<b>MY EMAIL ADDRESS:</b>
</td>
<td>
<%= getEmailAddressForUser( $u ) %>
</td>
</tr>
<tr height="40" valign="top">
<td align="right">
New Email:
</td>
<td>
<input type="text" name="email" size="24" value="" />
<input type="submit" class="default button" value="Update" />
<br />
<br />
<br />
</td>
</tr>
</form>
<br />
<form method="post" action="/account" name="profile_password_form"
onSubmit="return check_passwords(document.forms.profile_password_form);">
<input type="hidden" name="op" value="update-password" />
<tr>
<td colspan="2">
<b>MY PASSWORD:</b>
</td>
</tr>
<tr>
<td align="right">
New Password:
</td>
<td>
<input type="password" name="password1" size="24" value="<%= $password %>" />
</td>
</tr>
<tr>
<td align="right" valign="top">
Again:
</td>
<td>
<input type="password" name="password2" size="24" value="<%= $password %>" />
<input type="submit" class="default button" value="Update" />
<br />
<br />
<br />
</td>
</tr>
</form>
<form method="post" action="/account" enctype="multipart/form-data" name="profile_image_form">
<input type="hidden" name="MAX_FILE_SIZE" value="<%= $max_profile_image_size %>" />
<input type="hidden" name="op" value="update-profile-image" />
<tr>
<td colspan="2">
<b>MY PROFILE IMAGE:</b>
</td>
</tr>
<tr>
<td align="right" valign="top">
Select an image:
</td>
<td>
<input name="profile_image" size="14" type="file" />
<input type="submit" class="default button" value="Update" />
<br />
<br />
<br />
</td>
</tr>
</table>
<br />
<br />
<br />
</div>
</div>
</form>
</div>
<br />
</div>
<div>
<% include_once( "$modules/user-fields.inc.php" ); %>
</div>
<%
}
include( "$modules/footer.inc.php" );
} else {
echo bounceTo( $site . "/login?bounceToPage=" . urlencode( "account" ));
}
%>