<?php 
$form_name = "";
$table_name = "custom_participant_registration";
$primary_key = "reg_id";

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

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

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : "";
$attr = isset($_REQUEST['attr']) ? $_REQUEST['attr'] : "";
$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";
$action = $_SERVER['SCRIPT_NAME']."?page=".$_REQUEST['page']."&mode=edit";

if(isset($_REQUEST['excel']))
	$attr = "excel";
//if(isset($_REQUEST['pdf']))
//	$attr = "pdf";

switch($mode)
{
	case "submit":
		echo $last_id = $_REQUEST['partcpnt_id'];
		exit;
		$qry = "SELECT * FROM custom_participant_registration WHERE reg_participant_id = '".$_REQUEST['partcpnt_id']."'";
		$common->sql->query($qry, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		
		$last_id = $rec[0]['reg_id'];
		for($i=0; $i<count($_REQUEST['cupn_lst']); $i++)
		{
			$_REQUEST['cupn_dt'] = $common->date_format($_REQUEST['cupn_dt'], DT_FMT);
			$_REQUEST['cupn_vld_dt'] = $common->date_format($_REQUEST['cupn_vld_dt'], DT_FMT);
			
			$_query = sprintf("insert into custom_coupon_master values(0, '%s', '%s', '%s', '%s', '%s', 'Y', now(), '%s', 0, 0)",
				mysql_escape_string($last_id),
				mysql_escape_string($_REQUEST['cupn']),
				mysql_escape_string($_REQUEST['cupn_lst'][$i]),
				mysql_escape_string($_REQUEST['cupn_dt']),
				mysql_escape_string($_REQUEST['cupn_vld_dt']),
				mysql_escape_string(USR)
			);
			$rec = $common->sql->query($_query);
		}
		$link = $_SERVER['SCRIPT_NAME'].'?page='.$_REQUEST['page'];
		header("location:".$link);
		exit;
	break;
	
	case "edit":
		$query = "Select * FROM ".$table_name." WHERE lab_mapng_sur_id = '".$_REQUEST['id']."'";
		$common->sql->query($query, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		
		$id = $_REQUEST['id'];
		$survey_id = $rec[0]['lab_mapng_sur_id'];
		include("edit.php");
	break;
	
	default:
		echo '<div class="content_bg">';
			include("add.php");
		echo '</div>';
	break;
}
?>