Location: PHPKode > projects > SiteX > admin/user_edit.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((!userEditor())AND(!userAdmin()))  loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsUsersEdit']))  loginError($sxLang['LoginRequired']);

	$query2 = "SELECT * FROM $DB_Users_Types";
	$result2 = mysql_query($query2, $Link) or queryError("31", mysql_error());
	while($ROW2 = mysql_fetch_object($result2)){
		
		$query3 = "SELECT * FROM $DB_Users_Assoc WHERE userid='$edit_userid' AND typeid='1'";
		$result3 = mysql_query($query3, $Link) or queryError("31", mysql_error());
		if(mysql_num_rows($result3)) $noeditadmin = "1";
		else $noeditadmin = "";
		//echo '<input name="user_types[' . $ROW2->id . ']" type="checkbox" id="user_types" value="1"' . $checked;
		//if($ROW->id == 1) echo ' onclick="document.form1.user_types.checked=true"';
		if((userEditor())AND($noeditadmin == 1)) header("Location: user_manager.php?message=".$sxLang['MessageUserEditorNotAdmin']."");
	}

if($Submit)
{
	$query = "SELECT * FROM $DB_Users WHERE username='$usernameNew' AND id!='$edit_userid'";
	$result = mysql_query($query, $Link) or queryError("98", mysql_error());
	if(!mysql_num_rows($result))
	{
		if($deleteAvatar)
		{
			$query = "UPDATE $DB_Users SET avatar='' WHERE id='$edit_userid'";	
			$result = mysql_query($query, $Link) or queryError("98", mysql_error());
			@unlink("../".$sxContentDir['Avatar'].$edit_userid.'.jpg');
		}
		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$)", strtolower($sxAvatarFileName)))
			{
				$sxFileNameParts = explode('.',$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='$edit_userid'";	
					$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
				  username='$usernameNew',
				  firstname='$firstnameNew', 
				  lastname='$lastnameNew', 
				  location='$locationNew', 
				  email='$emailNew', 
				  website='$websiteNew',
				  skypeid='$skypeidNew',
				  msnid='$msnidNew',
				  bio='$bioNew',
				  signature='$signatureNew',
				  timezone='$my_timezoneNew',
				  newsletter='$newsletterNew',
				  showemail='$showemailNew',
				  validated='$validatedNew',
				  active='$activeNew'
				  WHERE id='$edit_userid'";
		$result = mysql_query($query, $Link) or queryError("29", mysql_error());
		
		if($changePassword == 1){
			$query = "UPDATE $DB_Users SET
					  password='$passwordNew'
					  WHERE id='$edit_userid'";
			$result = mysql_query($query, $Link) or queryError("30", mysql_error());
		}
		
		$query = "DELETE FROM $DB_Users_Assoc WHERE userid='$edit_userid'";
		$result = mysql_query($query, $Link) or queryError("31", mysql_error());
		
		foreach ($user_types as $k => $v) {
			$query = "INSERT INTO $DB_Users_Assoc (userid, typeid) VALUES ('$edit_userid', '$k')";
			$result = mysql_query($query, $Link) or queryError("31", mysql_error());
		}
		$message = $sxLang['MessageProfileChangesSucessful']."<br />".$photo_message;
	}else{
		$error = 1;
		$message = $sxLang['MessageUserUsernameInUse'];
	}
}

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

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function submitIt(myForm){

	if(myForm.usernameNew.value.length < 3){
		alert("<?PHP echo $sxLang['UserJSUsername']; ?>");
		myForm.usernameNew.select();
		return false;
	}
	if(myForm.firstnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSFirstName']; ?>");
		myForm.firstname.select();
		return false;
	}
	if(myForm.lastnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSLastName']; ?>");
		myForm.lastname.select();
		return false;
	}
	if(myForm.emailNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSEmail1']; ?>");
		myForm.email.select();
		return false;
	}
	if(myForm.passwordNew.value != myForm.passwordNewConfirm.value){
		alert("<?PHP echo $sxLang['UserJSPassword2']; ?>");
		myForm.passwordNew.select();
		return false;
	}
}
function delAvatarSwitch(){
	if(document.form1.deleteAvatar.checked == true){
		document.form1.changeAvatar.checked = false;
		document.form1.changeAvatar.disabled = true;
		document.form1.AvatarFile.value = "";
		document.form1.AvatarFile.disabled = true;
	}else{
		document.form1.changeAvatar.disabled = false;
		document.form1.AvatarFile.disabled = false;
	}
}
function changePW(){
	if(document.form1.changePassword.checked == true){
		document.form1.passwordNew.disabled = false;
		document.form1.passwordNewConf.disabled = false;
	}else{
		document.form1.passwordNew.disabled = true;
		document.form1.passwordNewConf.disabled = true;
		document.form1.passwordNew.value = "";
		document.form1.passwordNewConf.value = "";
	}
}
//-->
</script>
<div class="bodyWrapper">
<h1 class="sxAdminHeading"><?PHP echo $sxLang['UserHeadingEdit']; ?></h1>
<div class="sxAdminBreadcrumbs"><?PHP if(userAdmin()) { ?><a href="index.php"><?PHP echo $sxLang['AdminBreadcrumb']; ?><?PHP }?><?PHP if(userEditor()) { ?><a href="editor_index.php"><?PHP echo $sxLang['EditorBreadcrumb']; ?><?PHP }?></a> > <a href="user_manager.php"><?PHP echo $sxLang['UserHeadingManager']; ?></a> > <?PHP echo $sxLang['UserHeadingEdit']; ?></div>
<?PHP echoMessage($message); ?>
<form action="<?PHP echo $PHP_SELF; ?>" method="post" name="form1" enctype="multipart/form-data" onSubmit="return submitIt(this)">
<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><input type="text" name="usernameNew" maxlength="40"<?PHP echo ' value="' . 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" maxlength="32" value="1" 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" maxlength="40"<?PHP echo ' value="' . htmlspecialchars($ROW->firstname) . '"'; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemLastName']; ?></td>
	<td><input type="text" name="lastnameNew" maxlength="40"<?PHP echo ' value="' . htmlspecialchars($ROW->lastname) . '"'; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemEmail']; ?></td>
	<td><input type="text" name="emailNew" maxlength="80"<?PHP echo ' value="' . htmlspecialchars($ROW->email) . '"'; ?> /> 
	</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"<?PHP echo ' value="' . htmlspecialchars($ROW->website) . '"'; ?> />
	<em><span class="sxSmallText">(ex. http://www.google.com)</span></em></td>
  </tr>
  <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>
  <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>
  <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>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemLocation']; ?></td>
	<td><input type="text" name="locationNew" maxlength="80"<?PHP echo ' value="' . htmlspecialchars($ROW->location) . '"'; ?> /></td>
  </tr><?PHP if(($sxSetup['UserAvatar'])OR($sxSetup['UserSignature'])){ ?>
</table>
<div class="sxSection"><?PHP echo $sxLang['UserSectionPersonalInfo']; ?></div>
<table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="0" cellpadding="5"><?PHP } ?>
<?PHP if($sxSetup['UserAvatar']){ ?>
  <tr> 
	<td 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="Avatar" src="<?PHP echo "../".$sxContentDir['Avatar'].$ROW->avatar; ?>" /></p><?PHP } ?></td>
  </tr><?PHP } ?>
  <?PHP if($sxSetup['UserSignature']){ ?><tr>
	  <td 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; ?>" 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; ?>" 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; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemNewsletter']; ?></td>
	<td><input name="newsletterNew" type="checkbox" value="1"<?PHP if($ROW->newsletter) echo ' checked'; ?> /></td>
  </tr>
 <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemValidated']; ?></td>
	<td><input name="validatedNew" type="checkbox" value="1"<?PHP if($ROW->validated) echo ' checked'; ?> /></td>
  </tr>
 <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemActivated']; ?></td>
	<td><input name="activeNew" type="checkbox" value="1"<?PHP if($ROW->active) echo ' checked'; ?> /></td>
  </tr>

</table>
<div class="sxSection"><?PHP echo $sxLang['UserSectionSetup']; ?></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['UserItemUserType']; ?></td>
	<td> 
	<?PHP
	$query2 = "SELECT * FROM $DB_Users_Types";
	$result2 = mysql_query($query2, $Link) or queryError("31", mysql_error());
	while($ROW2 = mysql_fetch_object($result2)){
		
		$query3 = "SELECT * FROM $DB_Users_Assoc WHERE userid='$edit_userid' AND typeid='$ROW2->id'";
		$result3 = mysql_query($query3, $Link) or queryError("31", mysql_error());
		if(mysql_num_rows($result3)) $checked = " checked";
		else $checked = "";
		
		echo '<input name="user_types[' . $ROW2->id . ']" type="checkbox" id="user_types" value="1"' . $checked;
		//if($ROW->id == 1) echo ' onclick="document.form1.user_types.checked=true"';
		if((userEditor())AND($ROW2->id == 1)) echo ' disabled';
		echo ' />' . $ROW2->name . '<br />';
	}
	?>
	</td>
  </tr>
</table>
<p align="center">
<input name="edit_userid" type="hidden" value="<?PHP echo $edit_userid; ?>" />
<input name="Submit" type="submit" value="<?PHP echo $sxLang['UserButtonEditUser']; ?>" style="width:180px;" class="sxButton" />
</p>
</form>
</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX