<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

$showm = '8';
include('header.php');

if(!empty($_POST['submit']) && $_POST['submit'] == 'Update password') 
{
	$username = $userdata['username'];
	$query = mysql_query("SELECT * FROM pm_users where username = '".$username."' AND power = '".U_ADMIN."'");
	$rows = mysql_num_rows($query);
	$r = mysql_fetch_array($query);
	
	// ** IF USER DOESN'T EXIST REDIRECT TO HOMEPAGE ** //
	if($rows == 0) {
		header("Location: "._URL.""); 
		exit;
	}
	
	if(isset($_POST['submit']) && $_POST['submit'] == "Update password" ) 
	{
		$current_pass = md5(trim($_POST['pass']));
		$sql_pass = $r['password'];
		
		if($current_pass == $sql_pass) 
		{
			$new_pass = trim($_POST['new_pass']);
			if(!empty($new_pass)) 
			{
				$new_pass = md5($new_pass);
				@mysql_query("UPDATE pm_users SET password = '".$new_pass."' WHERE username = '".$r['username']."' AND power = '1'");
				$info_msg = '<div class="info_msg_ok">The admin password has been updated. It would be best to re-login.</div>';
			} 
			else 
			{
				$info_msg = '<div class="info_msg_err">Your new password must be at least 5 characters long.</div>';
			}
		} 
		elseif($current_pass != $sql_pass) 
		{
			$info_msg = '<div class="info_msg_err">Try again! This is not your current password.</div>';
		}
	}	
} 
else 
{
	$info_msg = '<div class="info_msg">Please make sure your password is easy to remember but hard to guess.</div>';
}
?>
<div id="sub_menu">
<li><a href="password.php">Update admin password</a></li>
<li><a href="add_tracking.php">Manage counter</a></li>
<li><a href="sitemap.php" class="hintanchor" onMouseover="showhint('This may take some time. After clicking this link please wait for the sitemap to be generated.', this, event, '250px')">Generate Sitemap</a></li>	
<li><a href="video-sitemap.php">Generate Video Sitemap</a></li>
</div>
<div id="content">
<h2>Update Admin Password</h2>

<?php echo $info_msg; ?>
<table width="100%" border="0" cellspacing="2" cellpadding="5">
  <tr>
    <td>
	<form name="register-form" method="post" action="password.php">
	<table>
	<tr>
			<td width="23%" class="fieldtitle">Current Password:</td>
			<td width="77%"><input name="pass" type="password" maxlength="32" class="inputtext" /><br />
			</td>
		  </tr>
		  <tr>
			<td class="fieldtitle"><strong>New Password</strong>:</td>
			<td><input name="new_pass" type="password" maxlength="32" class="inputtext" /><br />
			</td>
	 </tr>
		  <tr>
		    <td>&nbsp;</td>
		    <td><input type="submit" name="submit" value="Update password" class="inputbutton" /></td>
	      </tr>
	</table>
	</form>
	</td>
    </tr>
</table>
</div>
<?php
include('footer.php');
?>