<?php 
$form_name = "Survey Master";
$table_name = "custom_survey_master";
$primary_key = "sur_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)";
        
		$query = "SELECT * FROM ".$table_name;
		$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" />
		<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" charset="utf-8">
			var asInitVals = new Array();
			
			$(document).ready(function() {
				var oTable = $('#example').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "full_numbers",
				} );
				
				$("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(40);
				$(".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;
					sur_id = '#sur_id_'+j;
					sur_code = '#sur_code_'+j;
					sur_title = '#sur_title_'+j;
					sur_url = '#sur_url_'+j;
					sur_onlne_id = '#sur_onlne_id_'+j;
					sur_pid = '#sur_pid_'+j;
					sur_pri_db_name = '#sur_pri_db_name_'+j;
					sur_pri_db_server = '#sur_pri_db_server_'+j;
					sur_pri_db_usrnme = '#sur_pri_db_usrnme_'+j;
					sur_pri_db_paswrd = '#sur_pri_db_paswrd_'+j;
					sur_sec_db_name = '#sur_sec_db_name_'+j;
					sur_sec_db_server = '#sur_sec_db_server_'+j;
					sur_sec_db_usrnme = '#sur_sec_db_usrnme_'+j;
					sur_sec_db_paswrd = '#sur_sec_db_paswrd_'+j;
					status = '#status_'+j;
					
					frmval["sur_id"] = $(sur_id).val();
					frmval["sur_code"] = $(sur_code).val();
					frmval["sur_title"] = $(sur_title).val();
					frmval["sur_url"] = $(sur_url).val();
					frmval["sur_onlne_id"] = $(sur_onlne_id).val();
					frmval["sur_pid"] = $(sur_pid).val();
					frmval["sur_pri_db_name"] = $(sur_pri_db_name).val();
					frmval["sur_pri_db_server"] = $(sur_pri_db_server).val();
					frmval["sur_pri_db_usrnme"] = $(sur_pri_db_usrnme).val();
					frmval["sur_pri_db_paswrd"] = $(sur_pri_db_paswrd).val();
					frmval["sur_sec_db_name"] = $(sur_sec_db_name).val();
					frmval["sur_sec_db_server"] = $(sur_sec_db_server).val();
					frmval["sur_sec_db_usrnme"] = $(sur_sec_db_usrnme).val();
					frmval["sur_sec_db_paswrd"] = $(sur_sec_db_paswrd).val();
					frmval["status"] = $(status).val();
                                        
					parent.frm_edit_val(frmval);
				});
			} );
		</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;">&nbsp;</th>
                            <th>Survey Code</th>
                            <th>Survey Title</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $part_id = "";
                            
                            for($i=0; $i<count($rec); $i++)
                            {
                                if($part_id == "")
                                {
                                    $part_id = $rec[$i]['sur_code'];
                                    $j = 0;
                                    echo '<tr>
                                            <td style="display: none;">'.$i.'</td>
                                            <td>
                                                '.$rec[$i]['sur_code'].'
                                                <input type="hidden" name="sur_id" id="sur_id_'.$i.'" value="'.$rec[$i]['sur_id'].'" />
                                                <input type="hidden" name="sur_code" id="sur_code_'.$i.'" value="'.$rec[$i]['sur_code'].'" />
                                                <input type="hidden" name="sur_title" id="sur_title_'.$i.'" value="'.$rec[$i]['sur_title'].'" />
                                                <input type="hidden" name="sur_url" id="sur_url_'.$i.'" value="'.$rec[$i]['sur_url'].'" />
                                                <input type="hidden" name="sur_onlne_id" id="sur_onlne_id_'.$i.'" value="'.$rec[$i]['sur_onlne_id'].'" />
                                                <input type="hidden" name="sur_pid" id="sur_pid_'.$i.'" value="'.$rec[$i]['sur_pid'].'" />
                                                <input type="hidden" name="sur_pri_db_name" id="sur_pri_db_name_'.$i.'" value="'.$rec[$i]['sur_pri_db_name'].'" />
                                                <input type="hidden" name="sur_pri_db_server" id="sur_pri_db_server_'.$i.'" value="'.$rec[$i]['sur_pri_db_server'].'" />
                                                <input type="hidden" name="sur_pri_db_usrnme" id="sur_pri_db_usrnme_'.$i.'" value="'.$rec[$i]['sur_pri_db_usrnme'].'" />
                                                <input type="hidden" name="sur_pri_db_paswrd" id="sur_pri_db_paswrd_'.$i.'" value="'.$rec[$i]['sur_pri_db_paswrd'].'" />
                                                <input type="hidden" name="sur_sec_db_name" id="sur_sec_db_name_'.$i.'" value="'.$rec[$i]['sur_sec_db_name'].'" />
                                                <input type="hidden" name="sur_sec_db_server" id="sur_sec_db_server_'.$i.'" value="'.$rec[$i]['sur_sec_db_server'].'" />
                                                <input type="hidden" name="sur_sec_db_usrnme" id="sur_sec_db_usrnme_'.$i.'" value="'.$rec[$i]['sur_sec_db_usrnme'].'" />
                                                <input type="hidden" name="sur_sec_db_paswrd" id="sur_sec_db_paswrd_'.$i.'" value="'.$rec[$i]['sur_sec_db_paswrd'].'" />
                                                <input type="hidden" name="status" id="status_'.$i.'" value="'.$rec[$i]['status'].'" />
                                            </td>
                                            <td>'.$rec[$i]['sur_title'].'</td>
                                        </tr>';
                                }
                                else
                                {
                                    echo '<tr style="display: none;">
                                            <td style="display: none;">'.$i.'</td>
                                            <td>&nbsp;
                                                <input type="hidden" name="sur_id" id="sur_id_'.$i.'" value="'.$rec[$i]['sur_id'].'" />
                                                <input type="hidden" name="sur_code" id="sur_code_'.$i.'" value="'.$rec[$i]['sur_code'].'" />
                                                <input type="hidden" name="sur_title" id="sur_title_'.$i.'" value="'.$rec[$i]['sur_title'].'" />
                                                <input type="hidden" name="sur_url" id="sur_url_'.$i.'" value="'.$rec[$i]['sur_url'].'" />
                                                <input type="hidden" name="sur_onlne_id" id="sur_onlne_id_'.$i.'" value="'.$rec[$i]['sur_onlne_id'].'" />
                                                <input type="hidden" name="sur_pid" id="sur_pid_'.$i.'" value="'.$rec[$i]['sur_pid'].'" />
                                                <input type="hidden" name="sur_pri_db_name" id="sur_pri_db_name_'.$i.'" value="'.$rec[$i]['sur_pri_db_name'].'" />
                                                <input type="hidden" name="sur_pri_db_server" id="sur_pri_db_server_'.$i.'" value="'.$rec[$i]['sur_pri_db_server'].'" />
                                                <input type="hidden" name="sur_pri_db_usrnme" id="sur_pri_db_usrnme_'.$i.'" value="'.$rec[$i]['sur_pri_db_usrnme'].'" />
                                                <input type="hidden" name="sur_pri_db_paswrd" id="sur_pri_db_paswrd_'.$i.'" value="'.$rec[$i]['sur_pri_db_paswrd'].'" />
                                                <input type="hidden" name="sur_sec_db_name" id="sur_sec_db_name_'.$i.'" value="'.$rec[$i]['sur_sec_db_name'].'" />
                                                <input type="hidden" name="sur_sec_db_server" id="sur_sec_db_server_'.$i.'" value="'.$rec[$i]['sur_sec_db_server'].'" />
                                                <input type="hidden" name="sur_sec_db_usrnme" id="sur_sec_db_usrnme_'.$i.'" value="'.$rec[$i]['sur_sec_db_usrnme'].'" />
                                                <input type="hidden" name="sur_sec_db_paswrd" id="sur_sec_db_paswrd_'.$i.'" value="'.$rec[$i]['sur_sec_db_paswrd'].'" />
                                                <input type="hidden" name="status" id="status_'.$i.'" value="'.$rec[$i]['status'].'" />
                                            </td>
                                            <td>&nbsp;</td>
                                        </tr>';
                                }
                                
                                $j++;
                                if($part_id == $rec[$i+1]['sur_code'])
                                    $part_id = $rec[$i+1]['sur_code'];
                                else
                                    $part_id = "";
                            }
                        ?>
                    </tbody>
                    <thead>
                        <tr>
                            <th style="display: none;"><input type="text" name="search_engine" value="Search Survey Code" class="search_init" /></th>
                            <th><input type="text" name="search_engine" value="Search Survey Code" class="search_init" /></th>
                            <th><input type="text" name="search_browser" value="Search Survey Title" class="search_init" /></th>
                        </tr>
                    </thead>
                </table>
            </form>
        </div>
        <?php
	break;
}
?>