<?php

$err_msg = "";
require_once($application_path . "class/survey.class.php");
$SEAS_Survey = new survey();

require_once($application_path . "model/survey.mdl.php");
$SEAS_Survey_Model = new survey_Model();

$market_list = $SEAS_Survey_Model->list_market();
$stype_list  = $SEAS_Survey_Model->list_stype();

if(isset($_REQUEST['new'])) {
	$SEAS_Survey->set_srv_id(0);
	$SEAS_Survey->set_srv_desc("");
	$SEAS_Survey->set_srv_type(0);
	$SEAS_Survey->set_srv_mrkt(0);
	$SEAS_Survey->set_srv_stdt("");
	$SEAS_Survey->set_srv_eddt("");
	$SEAS_Survey->set_user_id(0);
}

if(isset($_REQUEST['edit'])) {
	
	$sdetial = $SEAS_Survey_Model->get_survey_details($_REQUEST['edit']);

	$SEAS_Survey->set_srv_id($sdetial['id']);
	$SEAS_Survey->set_srv_desc($sdetial['name']);
	$SEAS_Survey->set_srv_type($sdetial['type']);
	$SEAS_Survey->set_srv_mrkt($sdetial['srv_mrkt']);
	$SEAS_Survey->set_srv_stdt($sdetial['rw_srv_stdt']);
	$SEAS_Survey->set_srv_eddt($sdetial['rw_srv_eddt']);
	$SEAS_Survey->set_user_id($sdetial['uid']);
	
}

if(isset($_REQUEST['save_btn'])) {
	$SEAS_Survey->set_srv_id($_REQUEST['txt_srv_id']);
	$SEAS_Survey->set_srv_desc($_REQUEST['txt_srv_desc']);
	$SEAS_Survey->set_srv_type($_REQUEST['txt_srv_type']);
	$SEAS_Survey->set_srv_mrkt($_REQUEST['txt_srv_mrkt']);
	$SEAS_Survey->set_srv_stdt($_REQUEST['txt_srv_stdt']);
	$SEAS_Survey->set_srv_eddt($_REQUEST['txt_srv_eddt']);
	$SEAS_Survey->set_user_id($_SESSION['seas_user_id']);
	
	if($_REQUEST['txt_srv_id'] <=0) {
		$rv = $SEAS_Survey_Model->new_survey($SEAS_Survey);
		
		if($rv) {
			?>	
			<script>
				window.opener.location.reload()
				window.close()
			</script>
            <?
		}
		else {
			$err_msg = "Error while creating new survey";
		}
	}
	else {
		$rv = $SEAS_Survey_Model->update_survey($SEAS_Survey);
		if($rv) {
			?>	
			<script>
				window.opener.location.reload()
				window.close()
			</script>
            <?	
		}
		else {
			$err_msg = "Error while updating survey";
		}
	}
}



?>