<?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");

$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)
{
	default:
		$query = "SELECT *, CASE WHEN ".$table_name.".status = 'Y' THEN 'Active' ELSE 'Inactive' END as status 
						FROM ".$table_name."
					LEFT JOIN custom_coupon_master ON (custom_coupon_master.coupn_reg_id = ".$table_name.".reg_id)
					LEFT JOIN custom_location ON (custom_location.loc_code = ".$table_name.".reg_location)
					LEFT JOIN custom_survey_master ON (custom_survey_master.sur_id = ".$table_name.".reg_survey_id)
				  GROUP BY reg_id";

		$query = "SELECT *, CASE WHEN ".$table_name.".status = 'Y' THEN 'Active' ELSE 'Inactive' END as status 
						FROM ".$table_name."
					LEFT JOIN custom_coupon_master ON (custom_coupon_master.coupn_reg_id = ".$table_name.".reg_coupon_code)
					LEFT JOIN custom_location ON (custom_location.loc_code = ".$table_name.".reg_location)
					LEFT JOIN custom_survey_master ON (custom_survey_master.sur_code = ".$table_name.".reg_survey_id)
				  WHERE ".$table_name.".status is NOT NULL GROUP BY reg_id";
		$common->sql->query($query, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		?>
		<link rel="stylesheet" href="includes/media/css/demo_page.css" type="text/css" />
		<link rel="stylesheet" href="includes/media/css/demo_table.css" type="text/css" />
		<link rel="stylesheet" href="includes/media/css/TableTools_JUI.css" type="text/css" />
		<script type="text/javascript" language="javascript" src="includes/media/js/jquery.js"></script>
		<script type="text/javascript" language="javascript" src="includes/media/js/jquery.dataTables.js"></script>
		<script type="text/javascript" language="javascript" src="includes/media/js/ZeroClipboard.js"></script>
		<script type="text/javascript" language="javascript" src="includes/media/js/TableTools.js"></script>
                <script type="text/javascript" charset="utf-8">
			var asInitVals = new Array();
			
			$(document).ready(function() {
				var oTable = $('#example').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "full_numbers"/*,
					"sDom": '<"H"Tfr>t<"F"ip>',
					"oTableTools": {
							"sSwfPath" : "includes/media/swf/copy_csv_xls_pdf.swf",
							"aButtons": [
									"copy", "csv", "pdf"
							]
					}*/
				} );
				
				$("thead input").keyup( function () {
					oTable.fnFilter( this.value, $("thead input").index(this) );
				} );
				
				$("thead input").each( function (i) {
					asInitVals[i] = this.value;
				} );
				
				$("thead input").focus( function () {
					if ( this.className == "search_init" )
					{
						this.className = "";
						this.value = "";
					}
				} );
				
				$("thead input").blur( function (i) {
					if ( this.value == "" )
					{
						this.className = "search_init";
						this.value = asInitVals[$("thead input").index(this)];
					}
				} );
				
				$(".fg-toolbar").height(30);
				$(".dataTables_length").hide();
				$(".dataTables_filter").hide();
				$("#example_info").hide();
				
				$('#example tbody tr').live('click', function () {
					var frmval = new Array();
					var nTds = $('td', this);
					var row = $(nTds[0]).text();
					
					j = row;
					reg_id = '#reg_id_'+j;
					participant_id = '#participant_id_'+j;
					survey = '#survey_'+j;
					reg_location = '#reg_location'+j;
					participant_type = '#participant_type_'+j;
					cupn_code = '#cupn_code_'+j;
					dor = '#dor_'+j;
					ns = '#ns_'+j;
					dob = '#dob_'+j;
					age = '#age_'+j;
					sex = '#sex_'+j;
					biometric_ref = '#biometric_ref_'+j;
					coupon_count = '#coupon_count_'+j;
					cupn_dt = '#cupn_dt_'+j;
					cupn_prd = '#cupn_prd_'+j;
					prd_type = '#prd_type_'+j;
					cupn_vld_dt = '#cupn_vld_dt_'+j;
					
					frmval["reg_id"] = $(reg_id).val();
					frmval["participant_id"] = $(participant_id).val();
					frmval["survey"] = $(survey).val();
					frmval["reg_location"] = $(reg_location).val();
					frmval["participant_type"] = $(participant_type).val();
					frmval["cupn_code"] = $(cupn_code).val();
					frmval["dor"] = $(dor).val();
					frmval["ns"] = $(ns).val();
					frmval["dob"] = $(dob).val();
					frmval["age"] = $(age).val();
					frmval["sex"] = $(sex).val();
					frmval["biometric_ref"] = $(biometric_ref).val();
					frmval["coupon_count"] = $(coupon_count).val();
					frmval["cupn_dt"] = $(cupn_dt).val();
					frmval["cupn_prd"] = $(cupn_prd).val();
					frmval["prd_type"] = $(prd_type).val();
					frmval["cupn_vld_dt"] = $(cupn_vld_dt).val();
					
					for(i=0; i<frmval["coupon_count"]; i++)
					{
						t_id = "coupn_part_id_"+frmval["reg_id"]+"_"+i;
						frmval[t_id] = $("#"+t_id).val();
					}
					
					parent.frm_edit_val(frmval);
					/*alert("participant_id "+$(participant_id).val());
					alert("survey "+$(survey).val());
					alert("reg_location "+$(reg_location).val());
					alert("participant_type "+$(participant_type).val());
					alert("cupn_code "+$(cupn_code).val());
					alert("dor "+$(dor).val());
					alert("ns "+$(ns).val());
					alert("dob "+$(dob).val());
					alert("age "+$(age).val());
					alert("sex "+$(sex).val());*/
				});

				// frm_val(this.form)
			} );
		</script>
        <br /><br />
        <div id="demo" style="width: 95%; margin: 0 auto;">
            <form name="view" method="post">
                <table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
                    <thead>
                        <tr>
                            <th style="display: none;">S.No</th>
                            <th>Participant ID</th>
                            <!-- Vidhya - Commented below line on 27-10-2017 -->
                            <!--  <th>Participant Type</th> -->
                            <!--  <th>Location</th>-->
                            <!-- Vidhya - Commented below line on 27-10-2017 -->
                            <!-- <th>Survey</th> -->
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $part_id = "";
                            
                            for($i=0; $i<count($rec); $i++)
                            {
                                if($rec[$i]['reg_participant_type'] == 'S')
                                        $type = 'Seed';
                                else
                                        $type = 'Recruit';
                                if($part_id == "")
                                {
                                    //$part_id = $rec[$i]['reg_participant_id'];
                                    $j = 0;
                                    echo '<tr>
                                            <td style="display: none;">'.$i.'</td>
                                            <td>
                                                '.$rec[$i]['reg_participant_id'].'
                                                <input type="hidden" name="reg_id" id="reg_id_'.$i.'" value="'.$rec[$i]['reg_id'].'" />
                                                <input type="hidden" name="participant_id" id="participant_id_'.$i.'" value="'.$rec[$i]['reg_participant_id'].'" />
                                                <input type="hidden" name="survey" id="survey_'.$i.'" value="'.$rec[$i]['reg_survey_id'].'" />
                                                <input type="hidden" name="reg_location" id="reg_location'.$i.'" value="'.$rec[$i]['reg_location'].'" />
                                                <input type="hidden" name="participant_type" id="participant_type_'.$i.'" value="'.$rec[$i]['reg_participant_type'].'" />
                                                <input type="hidden" name="cupn_code" id="cupn_code_'.$i.'" value="'.$rec[$i]['reg_coupon_code'].'" />
                                                <input type="hidden" name="dor" id="dor_'.$i.'" value="'.$rec[$i]['reg_date_of_recurit'].'" />
                                                <input type="hidden" name="ns" id="ns_'.$i.'" value="'.$rec[$i]['reg_network_size'].'" />
                                                <input type="hidden" name="dob" id="dob_'.$i.'" value="'.$rec[$i]['reg_date_of_birth'].'" />
                                                <input type="hidden" name="age" id="age_'.$i.'" value="'.$rec[$i]['reg_age'].'" />
                                                <input type="hidden" name="sex" id="sex_'.$i.'" value="'.$rec[$i]['reg_sex'].'" />
                                                <input type="hidden" name="biometric_ref" id="biometric_ref_'.$i.'" value="'.$rec[$i]['reg_biometric_reference'].'" />
                                                <input type="hidden" name="coupon_count" id="coupon_count_'.$i.'" value="'.$rec[$i]['coupn_count'].'" />
                                                <input type="hidden" name="coupn_part_id" id="coupn_part_id_'.$rec[$i]['reg_id'].'_'.$j.'" value="'.$rec[$i]['coupn_participant_id'].'" />
                                                <input type="hidden" name="cupn_dt" id="cupn_dt_'.$i.'" value="'.$rec[$i]['coupn_issue_date'].'" />
                                                <input type="hidden" name="cupn_prd" id="cupn_prd_'.$i.'" value="'.$rec[$i]['coupn_valid_period_no'].'" />
                                                <input type="hidden" name="prd_type" id="prd_type_'.$i.'" value="'.$rec[$i]['coupn_valid_period_type'].'" />
                                                <input type="hidden" name="cupn_vld_dt" id="cupn_vld_dt_'.$i.'" value="'.$rec[$i]['coupn_valid_period'].'" />
                                            </td>
											<!-- Vidhya - Commented below line on 27-10-2017 -->
                                            <!--<td>'.$type.'</td>-->
                                           <!-- <td>'.$rec[$i]['loc_name'].'</td> -->
											<!-- Vidhya - Commented below line on 27-10-2017 -->
                                            <!-- <td>'.$rec[$i]['sur_title'].'</td> -->
                                        </tr>';
                                }
                                else
                                {
                                    /*echo '<tr style="display: none;">
                                            <td style="display: none;">&nbsp;</td>
                                            <td>&nbsp;
                                                <input type="hidden" name="reg_id" id="reg_id_'.$i.'" value="'.$rec[$i]['reg_id'].'" />
                                                <input type="hidden" name="participant_id" id="participant_id_'.$i.'" value="'.$rec[$i]['reg_participant_id'].'" />
                                                <input type="hidden" name="survey" id="survey_'.$i.'" value="'.$rec[$i]['reg_survey_id'].'" />
                                                <input type="hidden" name="reg_location" id="reg_location'.$i.'" value="'.$rec[$i]['reg_location'].'" />
                                                <input type="hidden" name="participant_type" id="participant_type_'.$i.'" value="'.$rec[$i]['reg_participant_type'].'" />
                                                <input type="hidden" name="cupn_code" id="cupn_code_'.$i.'" value="'.$rec[$i]['reg_coupon_code'].'" />
                                                <input type="hidden" name="dor" id="dor_'.$i.'" value="'.$rec[$i]['reg_date_of_recurit'].'" />
                                                <input type="hidden" name="ns" id="ns_'.$i.'" value="'.$rec[$i]['reg_network_size'].'" />
                                                <input type="hidden" name="dob" id="dob_'.$i.'" value="'.$rec[$i]['reg_date_of_birth'].'" />
                                                <input type="hidden" name="age" id="age_'.$i.'" value="'.$rec[$i]['reg_age'].'" />
                                                <input type="hidden" name="sex" id="sex_'.$i.'" value="'.$rec[$i]['reg_sex'].'" />
                                                <input type="hidden" name="biometric_ref" id="biometric_ref_'.$i.'" value="'.$rec[$i]['reg_biometric_reference'].'" />
                                                <input type="hidden" name="coupon_count" id="coupon_count_'.$i.'" value="'.$rec[$i]['coupn_count'].'" />
                                                <input type="hidden" name="cupn_dt" id="cupn_dt_'.$i.'" value="'.$rec[$i]['coupn_issue_date'].'" />
                                                <input type="hidden" name="cupn_prd" id="cupn_prd_'.$i.'" value="'.$rec[$i]['coupn_valid_period_no'].'" />
                                                <input type="hidden" name="prd_type" id="prd_type_'.$i.'" value="'.$rec[$i]['coupn_valid_period_type'].'" />
                                                <input type="hidden" name="cupn_vld_dt" id="cupn_vld_dt_'.$i.'" value="'.$rec[$i]['coupn_valid_period'].'" />
                                                <input type="hidden" name="coupn_part_id" id="coupn_part_id_'.$rec[$i]['reg_id'].'_'.$j.'" value="'.$rec[$i]['coupn_participant_id'].'" />
                                            </td>
                                            <td>&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td>&nbsp;</td>
                                        </tr>';*/
                                }
                                
                                $j++;
                                /*if($part_id == $rec[$i+1]['reg_participant_id'])
                                    $part_id = $rec[$i+1]['reg_participant_id'];
                                else
                                    $part_id = "";*/
                            }
                        ?>
                    </tbody>
                    <thead>
                        <tr>
                            <th style="display: none;"><input type="text" name="search_engine" value="Search Particiapnt ID" class="search_init" /></th>
                            <th><input type="text" name="search_engine" value="Search Participant ID" class="search_init" /></th>
                            <!-- Vidhya - Commented below line on 27-10-2017 -->
                            <!-- <th><input type="text" name="search_browser" value="Search Particiapnt Type" class="search_init" /></th> -->
                           <!--  <th><input type="text" name="search_platform" value="Search Location" class="search_init" /></th>-->
                            <!-- Vidhya - Commented below line on 27-10-2017 -->
                            <!-- <th><input type="text" name="search_version" value="Search Survey" class="search_init" /></th>-->
                        </tr>
                    </thead>
                </table>
            </form>
        </div>
        <?php
	break;
}
?>