<?php
	include "../db_connection/db_connection.php";
	include "../config/config.php";
	
	$action=base64_decode(base64_decode(base64_decode(base64_decode($_GET["action"]))));
	
	$current_username = $_POST['curr_name'];
	//$new_uname= $_POST["new_username"];
	$new_pwd= $_POST['new_pass'];
	
	$SLCT1 = "SELECT * FROM admin WHERE admin_id='1'";
	$QURY1 = mysqli_query($connect,$SLCT1);
	$FTCH1 = mysqli_fetch_object($QURY1);	
	$emailid1=$FTCH1->email_id;
	
	$SLCT = "SELECT * FROM admin WHERE admin_id='$_SESSION[admin_login_id]'";
	//echo $SLCT;
	$QURY = mysqli_query($connect,$SLCT);
	$FTCH = mysqli_fetch_object($QURY);
	$emailid=$FTCH->email_id;
	
	/*$SLCT3 = "SELECT * FROM login_details WHERE admin_id='$FTCH->admin_id'";
	//echo $SLCT3;
	$QURY3 = mysqli_query($connect,$SLCT3);
	$FTCH3 = mysqli_fetch_object($QURY3);
	
	
	$SLCT_des = "SELECT * FROM master_employee WHERE master_employee_id='$FTCH3->master_employee_id'";
	$QURY_des = mysqli_query($connect,$SLCT_des);
	$FTCH_des = mysqli_fetch_object($QURY_des);*/	
	$empname=$FTCH->user_name;
	
	if($action == 'edit')
	{
		if($current_username != '' || $new_pwd != '')
		{
			$UPDATE = "UPDATE admin SET user_name = '$current_username', pass_word = '$new_pwd' WHERE admin_id='$FTCH->admin_id'";
			 //echo $UPDATE;
			$QRY    = mysqli_query($connect,$UPDATE);
			 
			$email_ida="$emailid1,$emailid";
			$subject ="Reg:Login Details"; 
			$message = "Dear $empname,	
					
					
			  Plz go through the Login Details below				
						
					Your User Name  :   $current_username 
					
					Your Password	: 	$new_pwd
			 
	This User Name and Password is only in office hours inside the campus, outside the campus is restricted ..";
				
			$headers .= 'From:'.$email_ida."\r\n";
			$headers .= 'Bcc:'.$cc_id. "\r\n";	
			if(mail($emailid, $subject,$message,$headers));
			
			
			/*$subject1 ="Reg:Username and Password Changes"; 
			$message1 = "Dear Admin,			
					
			  	The User $empname ( $current_username ) was change his User Name and Password 				
						
					His User Name  :   $current_username  
					
					His Password	: 	$new_pwd";
					
			if(mail($emailid1, $subject1,$message1, "From:" . $email_ida1));*/
			
			echo "<script>window.location='../home.php';</script>";
			
		}
		else
		{
			echo "<script>alert('Oops! Something went wrong, Try again.');window.location='../index.php?admin_panel=change-admin-pwd';</script>";
		}
	}
	
?>