<?php
// check user is loged in or not
if($_SESSION['seas_user_id'] <=0) {
	header("location: home");
}

if(!isset($_SESSION['trg_sel_market'])) {
	$_SESSION['trg_sel_market'] = $_SESSION['seas_user_market'][0];
}
if(isset($_REQUEST['lst_market'])) {
	$_SESSION['trg_sel_market'] = $_REQUEST['lst_market'];
}

$seltrid =0;
if(isset($_REQUEST['trid'])) {
	$seltrid = $_REQUEST['trid'];
}

require_once($application_path . "class/target.class.php");
$SEAS_Target = new mst_targets();

require_once($application_path . "model/target.mdl.php");
$SEAS_Target_Model = new target_Model();

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

$sel_survey_details = $SEAS_Survey_Model->get_survey_details($_SESSION['seas_srv_id']);
$lst_markets = $SEAS_Survey_Model->list_market();




if(isset($_REQUEST['new_target_txt'])) {
	$SEAS_Target->set_srv_mrkt($_REQUEST['lst_market']);
	$SEAS_Target->set_trg_name($_REQUEST['new_target_txt']);
	$SEAS_Target->set_trg_grp(1);
	$SEAS_Target->set_trg_grpdesc("Group: 1");
	$SEAS_Target->set_factorid(0);
	$SEAS_Target->set_opt_id(0);
	$SEAS_Target->set_user_id($_SESSION['seas_user_id']);
	
	$SEAS_Target_Model->new_target($SEAS_Target);
}

if(isset($_REQUEST['edittarg'])) {
	$mrktid = $_REQUEST['mrktid'];
	$trid   = $_REQUEST['trid'];
	$newtarg =$_REQUEST['newtarg'];
	
	$seltrid = $trid;
	
	$SEAS_Target_Model->update_target($_SESSION['seas_user_id'],$mrktid,$trid,$newtarg);
}

if(isset($_REQUEST['deltarg'])) {
	$mrktid = $_REQUEST['mrktid'];
	$trid   = $_REQUEST['trid'];
	$seltrid = $trid;
	$SEAS_Target_Model->del_target($_SESSION['seas_user_id'],$mrktid,$trid);
}
if(isset($_REQUEST['deltargfact'])) {
	$mrktid = $_REQUEST['mrktid'];
	$trid   = $_REQUEST['trid'];
	$factid = $_REQUEST['factid'];
	$optid  = $_REQUEST['optid'];
	
	$seltrid = $trid;
	
	$SEAS_Target_Model->del_target_factor($_SESSION['seas_user_id'],$mrktid,$trid,$factid,$optid);
}


$list_targets = $SEAS_Target_Model->list_target($_SESSION['seas_user_id'],$_SESSION['trg_sel_market']);


?>