<?php

/**

** author:  aslapai
**
** date created: 26/06/2015
**
** this page serves ajax call to update password sent from function.js
*/


//include the headers resources
require_once('includes/functions_.php');


//collect the user id
 $user_id = get_user_id();

//collec the password
$old_password = $_POST['old_password'];
 $old_password = md5($old_password);


 $new_password = $_POST['new_password'];




$q1 = "SELECT password FROM staff  WHERE id = '$user_id'";
$r1 = mysqli_query($dbc, $q1);
$row1 = mysqli_fetch_assoc($r1);

 $old_password_db = $row1['password']; //coollect old pssword from db




if($old_password == $old_password_db)
{
	//query
	$q = "UPDATE staff SET password  = md5('$new_password') WHERE id = '$user_id'";
	$r = mysqli_query($dbc, $q);

	if($r)
	{
		echo  '<img src="images/info.png" />&nbsp;<label class="label label-success">Your Passsword has been changed.</label>';
	}
	else
	{
		echo  '<img src="images/blocked.png" />&nbsp;<label class="label label-danger">Your Passsword has NOT been changed.</label>';
	}

}
else
{


		echo  '<img src="images/blocked.png" />&nbsp;<label class="label label-danger">Please ensure is a valid old password</label>';

}





?>
