<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
include_once("adminfunctions.inc");

if (is_writable('modules/settings.inc')) {
	$writeablesettings = "<img src='./images/green.png' border=0>" ;
	$showchangeform = '1';
} else {
	$writeablesettings = "<img src='./images/red.png' border=0>" ;
}

	if (isset($_POST['submit'])) { 
		//$_POST['Old_pass']  $_POST['new_pass'] $_POST['new_pass2']
		if (sha1($_POST['Old_pass']) == $pass) {
			if ($_POST['new_pass'] == $_POST['new_pass2']) {
				$passc = strlen($_POST['new_pass']) ;
				if ($passc <= '6') {
					echo "Password need to be longer then 6 characters";
				} else {
					$newpass = $_POST['new_pass'] ;
					$settingsadminfile = '<?php
						$db_host = "' . $db_host . '";
						$db_user = "' . $db_user . '";
						$db_password = "' . $db_password. '";
						$db_database = "' . $db_database . '";
						$username = "' . $username . '";
						$pass = "' . sha1($newpass) . '";
						?>';
					$fp = fopen('modules/settings.inc', 'r+');
					fwrite($fp, $settingsadminfile);
					fclose($fp);
					echo "Password is changed" ;
				}
			} else {
				echo "New passwords did not match, try again" ;		
			}
		
		} else {
			echo "Old password not correct, please try again." ;
		}

		
	}

?>

<h2>Change admin password</h2>


<div class="settings">

	<fieldset>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
		<tr>
			<h4>Make sure to set settings.inc in folder /modules/ to permission 755 or 777 and after pass change set it back to 644.</h4>
		</tr>
			<tr>
				<td>Folder /modules/settings.inc:</td>
				<td><?=$writeablesettings?></td>
			</tr>
			<?php if ($showchangeform == '1') { ?>
			<tr>
				<td>Old Password:</td>
				<td><input type="password" size="25" name="Old_pass"></td>
			</tr>
			<tr>
				<td>New Password:</td>
				<td><input type="password" size="25" name="new_pass"></td>
			</tr>
			<tr>
				<td>New Password repaet:</td>
				<td><input type="password" size="25" name="new_pass2"></td>
			</tr>
			<?php } ?>
			<tr>	
				<td><input class="submitbutton" type="submit" name="submit" value="Change Pass" /></td>
			</tr>
		</table>
		</form>

	</fieldset>
</div>
