<?php 
$form_name = "Reimbursement Master";
$table_name = "custom_reimbursement";
$primary_key = "reimbrsmnt_id";

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : "";
	
include_once("includes/config.php");
include_once("includes/common_functions.php");

$common = new General_Functions();
$css_class = "x-gray";
// $common->SetCssClass($css_class);

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : "";
$act_type = isset($_REQUEST['act_type']) ? $_REQUEST['act_type'] : "";
$cancel_link = $_SERVER['SCRIPT_NAME'].'?page='.$_REQUEST['page'];
$action = $_SERVER['SCRIPT_NAME']."?page=".$_REQUEST['page']."&mode=submit";

switch($mode)
{
	case "submit":
		print_r($_REQUEST);
		exit;
		$vchr_no = $_REQUEST['vchr_no'];
		$reimburs_id = $_REQUEST['reimburs_id'];
		$reimburs_amt = $_REQUEST['reimburs_amt'];
		$last_id = $_REQUEST['partcpnt_id'];
		$vchr_pay_amt = $_REQUEST['vchr_pay_amt'];
		$sts = 'Y';
		
		$_query = "UPDATE ".$table_name."	SET	  reimbrsmnt_pay_amt  	= '".$vchr_pay_amt."',
												  reimbrsmnt_pay_status = '".$sts."'
											WHERE reimbrsmnt_vchr_no  	= '".$vchr_no."'";
		$rec = $common->sql->exeQuery($_query);
		$common->UserLog($form_name, $table_name, $_REQUEST['id'], 'Update');
		$link = $_SERVER['SCRIPT_NAME'].'?page='.$_REQUEST['page'];
		header("location:".$link);
		exit;
	break;
	
	case "edit":
		$query = "Select * FROM ".$table_name." 
					INNER JOIN custom_participant_registration 
						ON (custom_participant_registration.reg_participant_id = ".$table_name.".reimbrsmnt_particpnt_id)
				  WHERE reimbrsmnt_particpnt_id = '".$_REQUEST['id']."'";
		$common->sql->query($query, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		
		$id = $_REQUEST['id'];
		$vchr_no = $rec[0]['reimbrsmnt_vchr_no'];
		$partcpnt_id = $rec[0]['reg_participant_id'];
		$survey_id = $rec[0]['reimbrsmnt_survy_id'];
		$vchr_dt = $rec[0]['reimbrsmnt_vchr_dt'];
		$vchr_amt = $rec[0]['reimbrsmnt_tot_amt'];
		include("edit.php");
	break;
	
	case "delete":
		if(isset($_REQUEST[$prefix.'id']))
			$id = $_REQUEST[$prefix.'id'];
		else
			$id = implode("', '", $_REQUEST[$primary_key]);

		$query = "DELETE FROM ".$table_name." WHERE reimbrsmnt_particpnt_id IN ('".$id."')";

		$rec = $common->sql->exeQuery($query);

		if($rec)
		{
			$_SESSION['msg'] = 'Selected record has been deleted successfully';
			if(isset($_REQUEST['id']))
				$common->UserLog($form_name, $table_name, $_REQUEST['id'], 'Delete');
			else
				for($i=0; $i<count($_REQUEST[$primary_key]); $i++)
					$common->UserLog($form_name, $table_name, $_REQUEST[$primary_key][$i], 'Delete');
		}

		$query_string = str_replace("&mode=delete","",$_SERVER['QUERY_STRING']);
		$link = $_SERVER['SCRIPT_NAME'].'?page='.$_REQUEST['page'];
		header("location:".$link);
	break;
	
	case 'print':
		$query = "SELECT * FROM custom_participant_registration WHERE reg_participant_id = '".$_REQUEST['id']."'";
		$common->sql->query($query, SQL_ALL, SQL_ASSOC);
		$reg = $common->sql->record;
		$partid = $reg[0]['reg_id'];
		$partid = $_REQUEST['id'];
		
		$qry = "SELECT ".$table_name.".reimbrsmnt_head_id, reimbrsmnt_head_name, reimbrsmnt_amt, sur_title, sur_id, 
                            reimbrsmnt_vchr_no, reimbrsmnt_vchr_dt
                                FROM ".$table_name." 
					INNER JOIN custom_survey_master ON (custom_survey_master.sur_code = reimbrsmnt_survy_id)
					LEFT JOIN custom_reimbursement_heads_master 
                                            ON (custom_reimbursement_heads_master.reimbrsmnt_head_id = ".$table_name.".reimbrsmnt_head_id)
				WHERE reimbrsmnt_particpnt_id = '".$partid."' AND reimbrsmnt_survy_id = '".$_REQUEST['sur_id']."'";
		$common->sql->query($qry, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		$vchr_no = $rec[0]['reimbrsmnt_vchr_no'];
		$vchr_dt = $rec[0]['reimbrsmnt_vchr_dt'];
		$vchr_pay_amt = $rec[0]['reimbrsmnt_pay_amt'];
		include("print.php");
	break;
	
	default:
		echo '<div class="content_bg">';
			include("add.php");
		echo '</div>';
	break;
}
?>