Location: PHPKode > projects > SiteX > admin/profile.php
<?PHP
ob_start();
session_start();
ini_set("memory_limit","100M");
include("../includes/globals.php.inc");
include("../includes/functions.php");
include("../lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("../lang/".$sxSetup['Language'].".php");
include("../themes/$THEME_FOLDER/config.php.inc");

if(!loggedIn())
	loginError($sxLang['LoginRequired']);

if($Submit)
{
	if(($firstnameNew)AND($lastnameNew)AND($emailNew))
	{
		$passwordNew = htmlspecialchars($passwordNew);
		$firstnameNew = htmlspecialchars($firstnameNew);
		$lastnameNew = htmlspecialchars($lastnameNew);
		$locationNew = htmlspecialchars($locationNew);
		$emailNew = htmlspecialchars($emailNew);
		$websiteNew = htmlspecialchars($websiteNew);
		$signatureNew = $signatureNew;
		
		// Change password
		if($changePassword)
		{
			$query = "UPDATE $DB_Users SET password='$passwordNew' WHERE id='$THIS_USER'";	
			$result = mysql_query($query, $Link) or queryError("97", mysql_error());
		}
		
		// Delete avatar first if needed... order is important!
		if(($deleteAvatar)OR($AvatarFile))
		{
			$query = "SELECT * FROM $DB_Users WHERE id='$THIS_USER'";
			$result = mysql_query($query, $Link) or queryError("99", mysql_error());
			$ROW = mysql_fetch_object($result);
			
			@unlink("../".$sxContentDir['Avatar'].$ROW->avatar);
			
			$query = "UPDATE $DB_Users SET avatar='' WHERE id='$THIS_USER'";	
			$result = mysql_query($query, $Link) or queryError("98", mysql_error());
		}
		
		// Upload new avatar file
		if(strlen($_FILES['AvatarFile']['name']) > 0)
		{
			$sxAvatarFileName = basename($_FILES['AvatarFile']['name']);
			
			// Check to make sure file is an acceptable jpg
			if (eregi ("(.)+\\.(jp(e){0,1}g$|gif$|png$|bmp$)", strtolower($sxAvatarFileName)))
			{
				$sxFileNameParts = explode('.',str_replace(".php","",$sxAvatarFileName));
				$filename = $THIS_USER."_".$NOW.".".$sxFileNameParts[1];
				
				if (@move_uploaded_file($_FILES['AvatarFile']['tmp_name'], "../".$sxContentDir['Avatar'].$filename))
				{
					if((imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal"))
					{
						$sxImageInfo = getimagesize("../".$sxContentDir['Avatar'].$filename);
						
						switch($sxImageInfo[2])
						{
							case 1: $image = imagecreatefromgif("../".$sxContentDir['Avatar'].$filename); 	break;
							case 2: $image = imagecreatefromjpeg("../".$sxContentDir['Avatar'].$filename); 	break;
							case 3: $image = imagecreatefrompng("../".$sxContentDir['Avatar'].$filename); 	break;
							case 6: $image = imagecreatefromwbmp("../".$sxContentDir['Avatar'].$filename); 	break;
						}
						$width_original = $sxImageInfo[0];
						$height_original = $sxImageInfo[1];
					}
					
					$dimensions = resizeDimensionsMaxWidth($width_original, $height_original, $sxSetup['UserAvatarMaxWidth']);
					$dimensions = resizeDimensionsMaxHeight($dimensions[0], $dimensions[1], $sxSetup['UserAvatarMaxHeight']);
					
					if(imageCompatibility() == "truecolor")
					{
						$image_avatar = imagecreatetruecolor($dimensions[0]+1, $dimensions[1]+1);
						imagecopyresampled($image_avatar, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
					}
					elseif(imageCompatibility() == "normal")
					{
						$image_avatar = imagecreate($dimensions[0]+1, $dimensions[1]+1);
						imagecopyresized($image_avatar, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
					}
					
					switch($sxImageInfo[2])
					{
						case 1: imagegif($image_avatar, "../".$sxContentDir['Avatar'].$filename); 		break;
						case 2: imagejpeg($image_avatar, "../".$sxContentDir['Avatar'].$filename, $sxThemeConfig['AvatarCompression']); break;
						case 3: imagepng($image_avatar, "../".$sxContentDir['Avatar'].$filename); 		break;
						case 6: imagewbmp($image_avatar, "../".$sxContentDir['Avatar'].$filename); 	break;
					}
					
					imagedestroy($image_avatar);
					
					$photo_message = $sxLang['MessageProfileAvatarSucessful'];
					
					$query = "UPDATE $DB_Users SET avatar='$filename' WHERE id='$THIS_USER'";	
					$result = mysql_query($query, $Link) or queryError("98", mysql_error());			
				}
				else $photo_message = $sxLang['MessageFileCopyError'];
				@unlink($File);
				
			}else $photo_message = $sxLang['MessagePhotoResourceError'];
		} // End if avatar
		
		$query = "UPDATE $DB_Users 
	              SET firstname='$firstnameNew', 
				      lastname='$lastnameNew', 
					  email='$emailNew', 
					  website='$websiteNew',
					  skypeid='$skypeidNew',
					  msnid='$msnidNew',
					  bio='$bioNew',
					  location='$locationNew',
					  signature='$signatureNew',
					  timezone='$my_timezoneNew',
					  showemail='$showemailNew',
					  newsletter='$newsletterNew'
			       WHERE id='$THIS_USER'";	
		$result = mysql_query($query, $Link) or queryError("98", mysql_error());
		
		$query = "SELECT * FROM $DB_Users WHERE id='$THIS_USER'";
		$result = mysql_query($query, $Link) or queryError("99", mysql_error());
		$ROW = mysql_fetch_object($result);
		
		session_unset(); session_destroy(); session_start();
		authenticate($ROW->username, $ROW->password);
		
		$message = $sxLang['MessageProfileChangesSucessful']."<br />".$photo_message;
	}		
}

$query = "SELECT * FROM $DB_Users WHERE id='$THIS_USER'";
$result = mysql_query($query, $Link) or queryError("99", mysql_error());
$ROW = mysql_fetch_object($result);

$sxTitleAddendum = $sxLang['Profile'];
include("../themes/$THEME_FOLDER/header.php");
?>   
<script language="JavaScript" type="text/JavaScript">
<!--
function submitIt(myForm){
	if(myForm.firstnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSFirstName']; ?>");
		myForm.firstnameNew.select();
		return false;
	}
	if(myForm.lastnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSLastName']; ?>");
		myForm.lastnameNew.select();
		return false;
	}
	if(emailCheck(myForm.emailNew.value) == false){
		myForm.emailNew.select();
		return false;
	}
	if(myForm.changePassword.checked == true){
		if(myForm.passwordNew.value.length < 5){
			alert("<?PHP echo $sxLang['UserJSPassword1']; ?>");
			myForm.passwordNew.select();
			return false;
		}
		if(myForm.passwordNew.value != myForm.passwordNewConf.value){
			alert("<?PHP echo $sxLang['UserJSPassword2']; ?>");
			myForm.passwordNew.select();
			return false;
		}
	}
}
function emailCheck (emailStr) {

	// Adapted from V1.1.3: Sandeep V. Tamhankar (hide@address.com)

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		alert("<?PHP echo $sxLang['UserJSEmail11']; ?>");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail12']; ?>");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail13']; ?>");
			return false;
	   }
	}
	
	if (user.match(userPat)==null) {
		alert("<?PHP echo $sxLang['UserJSEmail14']; ?>");
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("<?PHP echo $sxLang['UserJSEmail15']; ?>");
				return false;
	   		}
		}
		return true;
	}
	
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("<?PHP echo $sxLang['UserJSEmail16']; ?>");
			return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("<?PHP echo $sxLang['UserJSEmail17']; ?>");
		return false;
	}
	
	if (len<2) {
		alert("<?PHP echo $sxLang['UserJSEmail18']; ?>");
		return false;
	}
	
	return true;
}
function delAvatarSwitch(){
	if(document.sxProfile.deleteAvatar.checked == true){
		document.sxProfile.changeAvatar.checked = false;
		document.sxProfile.changeAvatar.disabled = true;
		document.sxProfile.AvatarFile.value = "";
		document.sxProfile.AvatarFile.disabled = true;
	}else{
		document.sxProfile.changeAvatar.disabled = false;
		document.sxProfile.AvatarFile.disabled = false;
	}
}
function changePW(){
	if(document.sxProfile.changePassword.checked == true){
		document.sxProfile.passwordNew.disabled = false;
		document.sxProfile.passwordNewConf.disabled = false;
	}else{
		document.sxProfile.passwordNew.disabled = true;
		document.sxProfile.passwordNewConf.disabled = true;
		document.sxProfile.passwordNew.value = "";
		document.sxProfile.passwordNewConf.value = "";
	}
}
//-->
</script>
<div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['UserHeadingProfile']; ?></h1>
   <?PHP echoMessage($message); ?>
	<form name="sxProfile" method="post" action="<?PHP echo $PHP_SELF; ?>" onSubmit="return submitIt(this)" enctype="multipart/form-data">
	  <div class="sxSection"><?PHP echo $sxLang['UserSectionAccountInfo']; ?></div>
	  <table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="0" cellpadding="5">
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemUsername']; ?>*</td>
		  <td> <?PHP echo  htmlspecialchars($ROW->username); ?>
		  </td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemChangePassword']; ?></td>
		  <td><input name="changePassword" type="checkbox" id="changePassword" value="true" onclick="changePW()" /></td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemNewPassword']; ?>*</td>
		  <td><input name="passwordNew" type="password" id="passwordNew" maxlength="32" disabled="disabled" /> 
		  </td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemConfirm']; ?>*</td>
		  <td><input name="passwordNewConf" type="password" id="passwordNewConf" maxlength="32" disabled="disabled" /> 
		  </td>
		</tr>
	  </table>
	  <div class="sxSection"><?PHP echo $sxLang['UserSectionPersonalInfo']; ?></div>
	  <table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="0" cellpadding="5">
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemFirstName']; ?>*</td>
		  <td><input name="firstnameNew" type="text" value="<?PHP echo htmlspecialchars($ROW->firstname); ?>" maxlength="40" /> 
		  </td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemLastName']; ?>*</td>
		  <td><input type="text" name="lastnameNew"  value="<?PHP echo htmlspecialchars($ROW->lastname); ?>" maxlength="40" /> 
		  </td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemEmail']; ?>*</td>
		  <td><input type="text" name="emailNew"  value="<?PHP echo htmlspecialchars($ROW->email); ?>" maxlength="80" /> 
		  </td>
		</tr>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemWebsite']; ?></td>
		  <td><input type="text" name="websiteNew" maxlength="80" value="<?PHP echo htmlspecialchars($ROW->website); ?>" /> 
			<em>(http://www.google.com)</em></td>
		</tr>
		  <?PHP if($sxSetup['UserSkype']){ ?>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemSkypeID']; ?></td>
	<td> <input type="text" name="skypeidNew" maxlength="150" value="<?PHP echo htmlspecialchars($ROW->skypeid); ?>" /></td>
  </tr>
  <?PHP } ?>
  <?PHP if($sxSetup['UserMSN']){ ?>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemMSNID']; ?></td>
	<td> <input type="text" name="msnidNew" maxlength="150" value="<?PHP echo htmlspecialchars($ROW->msnid); ?>" />
	<em>(hide@address.com)</em></td>
  </tr>
  <?PHP } ?>
  <?PHP if($sxSetup['UserBio']){ ?>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemBio']; ?></td>
	<td> <textarea name="bioNew" style="width:300px;height:100px;" /><?PHP echo htmlspecialchars($ROW->bio); ?></textarea></td>
  </tr>
  <?PHP } ?>
		<tr> 
		  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemLocation']; ?></td>
		  <td><input type="text" name="locationNew"  value="<?PHP echo htmlspecialchars($ROW->location); ?>" maxlength="80" /></td>
		</tr>
	  <?PHP if(($sxSetup['UserAvatar'])OR($sxSetup['UserSignature'])){ ?></table>
	  <div class="sxSection"><?PHP echo $sxLang['UserSectionPersonalization']; ?></div>
	  <table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="0" cellpadding="5">
		<?PHP } if(($sxSetup['UserAvatar'])AND($sxSetup['ContentWriteable'])){ ?>
		<tr>
		  <td valign="top" width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemAvatar']; ?></td>
		  <td><?PHP if($ROW->avatar){ ?>
			  <input name="changeAvatar" type="checkbox" value="true" />
			  <?PHP echo $sxLang['UserChangeTo']; ?> <?PHP } ?><input name="AvatarFile" type="file" />
			  <?PHP if($ROW->avatar){ ?><br /><input name="deleteAvatar" type="checkbox" value="true" onChange="delAvatarSwitch()" /> <?PHP echo $sxLang['UserDeleteAvatar']; ?><?PHP } ?>
			  <?PHP if($ROW->avatar){ ?><p><img alt="<?PHP echo $ROW->avatar; ?>" src="<?PHP echo "../".$sxContentDir['Avatar'].$ROW->avatar; ?>" /></p><?PHP } ?></td>
		</tr><?PHP } ?><?PHP if($sxSetup['UserSignature']){ ?>
		<tr>
		  <td valign="top" width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemSignature']; ?></td>
		  <td><textarea name="signatureNew" style="width:300px;height:100px;"><?PHP echo htmlspecialchars(stripslashes($ROW->signature)); ?></textarea></td>
		</tr><?PHP } ?>
		</table>
		<div class="sxSection"><?PHP echo $sxLang['GeneralSectionSettings']; ?></div>
		<table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="0" cellpadding="5">
		  <tr> 
			<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" valign="top" class="sxTdItem"><?PHP echo $sxLang['UserItemTimezone']; ?></td>
			<td><select name="my_timezoneNew"><?PHP
				for($i = -24; $i <= 24; $i++){
					echo '<option value="' . $i . '"';
					if($i == $ROW->timezone) echo ' selected';
					echo '>';
					if($i > 0) echo '+ ';
					echo $i . '</option>';
				}
				?></select> <span class="sxSmallText"><?PHP echo $sxLang['UserHoursFrom']; ?><br />(<?PHP echo $sxLang['CurrentTime']; ?>: <?PHP echo fetchDate($NOW, 99, 1); ?>)</span>
			</td>
		  </tr>
		  <tr> 
			<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" valign="top" class="sxTdItem"><?PHP echo $sxLang['UserItemShowEmail']; ?></td>
			<td><input name="showemailNew" type="checkbox" value="1"<?PHP if($ROW->showemail) echo ' checked'; ?> /></td>
		  </tr>
		  <tr> 
			<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" valign="top" class="sxTdItem"><?PHP echo $sxLang['UserItemNewsletter']; ?></td>
			<td><input name="newsletterNew" type="checkbox" value="1"<?PHP if($ROW->newsletter) echo ' checked'; ?> /></td>
		  </tr>
	  </table>
	  <p align="center"><input style="width:200px;" type="submit" name="Submit" value="<?PHP echo $sxLang['UserButtonEdit']; ?>" class="sxButton" /></p>
  </form>
  </div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX