<?php
include("db.php");
include("checklogin.php");

$id="";
	
if(isset($_SESSION["user"]["uid"]))$id=$_SESSION["user"]["uid"];
else{
  redirect(URL_ROOT."index.php");
}

$profiledetail=$objindex->profile($_SESSION['user']['uid']);

    
if($_POST)
{
	$oldpass=$db->getVal("select password from student where idno=".$_SESSION['user']['uid']);
 if($oldpass!=$_POST['currentpass']){
	 $err="Invalid Current Password";
 }elseif($_POST['currentpass']=="")
 {
	 $err="Please enter Current Password";
 }elseif($_POST['newpass']==""){
	 $err="Please enter New Password";
 }elseif($_POST['confirmpass']==""){
	 $err="Please enter Conferm Password";
 }elseif($_POST['confirmpass']!=$_POST['newpass']){
	 $err="Password not match";
 }else{
	$update_pass=$db->updateAry("student",array("password"=>$_POST['newpass'])," where idno=".$_SESSION["user"]["uid"]);
  	if(!is_null($update_pass)){
	   	$err="password changed succesfully";
	  }else{
	   $err=$db->getErMsg();
	  }
 } 
 }
	
//print_r($err);echo "$err";exit;

if($err!="")
{
 $smarty->assign("err",$err);
}
else{
 $smarty->assign("err",'404');
}
$smarty->assign("profile",$profiledetail);

$smarty->assign("error",$alert_err);

//echo "<pre>";print_r($_SESSION);print_r($objindex->profile($_SESSION['user']['uid']));echo "</pre>";


$profile=$objindex->profile($_SESSION['user']['uid']);


$smarty->display('changepassword.html');