<?php 
require_once ('includes/functions.php');

$id = trim($_REQUEST['id']);
if(isset($_REQUEST['action']) && $_REQUEST['action']=='tech_pass'){
	$userType = 'tech';	
	$name = getTechnicianName($id);
} else if(isset($_REQUEST['action']) && $_REQUEST['action']=='user_pass'){
	$userType = 'user';
	$name = getUserName($id);
} else if(isset($_REQUEST['action']) && $_REQUEST['action']=='partner_pass'){
	$userType = 'partner';
	$name = getPartnerName($id);
} else {
	$error = 'Something went wrong. Param missing';
}



if(isset($_POST['submit'])) {
	
	if(isset($_POST['re_password']) && strlen($_POST['re_password'])>0) {
		$re_password = trim($_POST['re_password']);
		if(isset($_POST['password']) && strlen($_POST['password'])>0) {
			if($re_password == $_POST['password']){
				//ok
			} else {
				$error = 'Password mis-match error!';
			}
		}
	} else {
		$error = 'Please re-enter Password';
	}
	
	if(isset($_POST['password']) && strlen($_POST['password'])>0) {
		$password = trim($_POST['password']);
		if(strlen($password)<6){
			$error = 'Password should contain a minimum of 6 chars.';
		}
	} else {
		$error = 'Please enter Password';
	}
	
	if(empty($error)) {
		
		if($userType == 'tech'){
			$update = mysqli_query($con, "UPDATE tbl_technician SET password = '".$password."' WHERE id = '".$id."'");
			if($update){
				$success = 'Technician password has been changed';
			}
		} else if($userType == 'user'){
			$update = mysqli_query($con, "UPDATE tbl_user SET password = '".$password."' WHERE id = '".$id."'");
			if($update){
				$success = 'User password has been changed';
			}
		} else if($userType == 'partner'){
			$update = mysqli_query($con, "UPDATE tbl_purchase_partner SET password = '".$password."' WHERE id = '".$id."'");
			if($update){
				$success = 'User partner password has been changed';
			}
		} else {
			$error = 'Something went wrong';
		}	
		
		
		?><script language="javascript">
		//window.location='index.php?page=manage_admin';
		</script><?php
	}      
}



?>