<?php
/*
	File     : adminMyPassword.php
	Version  : 0.2.1 Beta
	Copyright: Attila Soki 2001
	e-mail   : atiware@gmx.net
	Date     : 2001-05-12
*/

	if (strlen($cancel)>0) {
		header("Location: adminMenu.php");
		printf('<a href="adminMenu.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	define("INVERTCOLOR","#F2F2E0");

	include_once("Admin.class.php");
	function TfColor($error,$control) {
		global $invert,$invert2;
		if ($error&$control)
			$retval='bgcolor="'.ERRORCOLOR.'"';
		elseif ($invert>0)
			$retval='bgcolor="'.INVERTCOLOR.'"';
		else
			$retval="";
		$invert*=-1;
		return $retval;
	}

	$saved=false;
	$invert=-1;
	$error=0;

	include_once("checkLogin.inc.php");
/*
	if (!$login->isRoot())
		$rights=false;
	else
*/

	if (strlen($submitButton)>0) {
		$submitButton=true;
	}
		$rights=true;
	$admin=new Admin((int)$id);
	if ($submitButton) {
		$tfpasswordold=trim($tfpasswordold);
		$tfpassword=trim($tfpassword);
		$tfpassword2=trim($tfpassword2);

		if ((strcmp($tfpassword,$tfpassword2)!=0) || (strlen($tfpassword)==0) || (!$login->checkPassword($tfpasswordold))) {
			$error|=1;
			$error|=2;
			$error|=4;
		}
		if (!$error) {
			if ((DEMOMODE) && ($login->getId()==1)) {
				;
			}
			else
				$login->setPassword($tfpassword);
			$saved=true;
		}
	}
	$headline="Change my password";
	if ((DEMOMODE) && ($login->getId()==1)) {
		$headline="<i>(You can't modify this password in demo mode!)</i> ".$headline;
	}
	require("head.inc.php");
?>
  <tr> 
    <td colspan="2" align="left" valign="top"> 
<?php
	if (($rights) && (!$saved)) {
?>
      <form method="post" action="adminMyPassword.php" name="form1" ENCTYPE="multipart/form-data">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" vspace="0" hspace="0">
          <tr> 
            <td colspan="2" bgcolor="#0099CC"> 
              <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="2"><?php echo $headline ?></font></b></font></div>
            </td>
          </tr>
          <tr <?php echo TfColor($error,2) ?>> 
            <td width="50%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Old password:</font></td>
            <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
              <input type="password" name="tfpasswordold" size="40" maxlength="63" value="<?php echo $tfpasswordold ?>">
              </font></td>
          </tr>

          <tr <?php echo TfColor($error,2) ?>> 
            <td width="50%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">New password:</font></td>
            <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
              <input type="password" name="tfpassword" size="40" maxlength="63" value="<?php echo $tfpassword ?>">
              </font></td>
          </tr>
          <tr <?php echo TfColor($error,4) ?>> 
            <td width="50%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Retype new password:</font></td>
            <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
              <input type="password" name="tfpassword2" size="40" maxlength="63" value="<?php echo $tfpassword2 ?>">
              </font></td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="#FFFFCC" align="center" valign="middle"> 
              <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                <input type="submit" name="submitButton" value="Save">
                <input type="submit" name="cancel" value="Cancel">
                </font></div>
            </td>
          </tr>
        </table>
      </form>
<?php
	}
	elseif (!$rights)
		require("norights.inc.php");
	else  {
?>
		<div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="3"><a href="adminMenu.php">
		The your password is successfully changed. Click here to continue...
		</a></b></font></div>
<?php
	}
?>
    </td>
  </tr>
<?php
	require("foot.inc.php");
?>