<?php
require_once($application_path . "view/header.tpl.php");
?>
<style>
	.maintable {
		border: solid 2px #639;
		padding:10px;
	}
	.maintable thead {
		font-size:14px;
		color:#FFF;
		font-weight:bold;
		text-align:left;
		background-color: #639;
	}
	.maintable thead td {
		height:40px;
		padding: 10px;
	}
	.maintable tr td {
		height:20px;
		padding: 4px;
	}
	
	.subtable {
		border: 0px;
		padding:0px;
	}
	.subtable tr td {
		height:15px;
		padding: 0px;
		margin:0px;
	}
	
	.trcls:hover { 
		background-color: #CCC;
	}	
	
	.targetmg {
		text-decoration:none;
		font-size:12px;
	}
	
	.targetmg a:visited { color: blue}
	.targetmg a:link { color: blue }
	.targetmg a:hover { color: black }
	.targetmg a:active { color: blue }
	
	.tar_fdesc {
		font-family:Verdana, Geneva, sans-serif;
		font-size:10px;
		font-weight:bold;
		font-style:italic;
		color:#666;
	}
	.tar_fopt {
		font-family:Verdana, Geneva, sans-serif;
		font-size:10px;	
		font-weight: normal;
		font-style:italic;
		color:#666;
	}
	.tar_frmv {
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;	
		font-weight: bolder;
		color:#F00;
		text-decoration:none;
	}
	.tar_fadd {
		font-family:Verdana, Geneva, sans-serif;
		font-size:10px;	
		font-weight: bolder;
		color: #00F;
		text-decoration:none;
	}	
	.tar_fadd a:hover{
		color:#003;
		font-size:10px;	
	}
	
</style>

        <!-- page content -->
        <div class="right_col" role="main">
		  
          <!-- Body First Row Items -->
          <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
				<h2>Manage Targets</h2>
                <br />
                <form name="trgForm" id="trgForm" action="target" method="post">
                <span style="font-size: 16px">Market: </span>
                <select name="lst_market" id="lst_market" style="height:35px; padding:5px; font-size: 15px" onchange="this.form.submit()">
                	<option value=""></option>
                	<?php
					foreach($lst_markets as $mkts) {
						echo '<option value="' . $mkts['mkt_code'] . '"';
						if($_SESSION['trg_sel_market'] == $mkts['mkt_code']) {
							echo " selected ";
						}
						echo ' >'. $mkts['mkt_name'] .'</option>';
					}
					?>
                </select>
                &nbsp;
                <input type="text" name="new_target_txt" style="height:35px; padding:5px; font-size:15px" value="" placeholder="Enter New target Name" />
                <button type="submit" class="btn btn-primary" >Add New</button>
                <table style="width:100%" class="responsive maintable">
					<thead>
                        <td width="2%"></td>
                        <td width="2%"></td>
                        <td width="53%">Target Description</td>
                        <td width="15%">Survey Market</td>
                    </thead>
                    
                    <?php
					foreach($list_targets as $slist) {
					?>
                        <tr class="trcls">
                            <td><a href="#" onclick="delete_target(<?php echo $_SESSION['trg_sel_market']; ?>,<?php echo $slist['trg_id']; ?>)" title="Delete Target"><img src="view/images/trash.png"  /></a></td>
                            <td><a href="#" onclick='edit_target(<?php echo $_SESSION['trg_sel_market']; ?>,<?php echo $slist['trg_id']; ?>,"<?php echo $slist['trg_name']; ?>")' title="Edit Target"><img src="view/images/edit.gif"  /></a></td>
                            <td><a href="#" onclick="showdesc(<?php echo "trg_". $slist['trg_id']; ?>)" ><?php echo $slist['trg_name']; ?></a></td>
                            <td><?php echo $sel_survey_details['market']; ?></td>
                        </tr>
                        <tr id="trg_<?php echo $slist['trg_id']; ?>" <?php if($seltrid != $slist['trg_id']) echo ' style="display:none" '; ?>>
                            <td colspan="6">                        
	                            <table cellpadding="0" cellspacing="0" class="subtable" width="100%">
									<?php
                                        $fact_list = $SEAS_Target_Model->list_target_factors($_SESSION['seas_user_id'],$sel_survey_details['srv_mrkt'],$slist['trg_id']);
                                        foreach($fact_list as $flist) {
                                        ?>
                                            <tr>
                                            	<td>
												 <a href="#" onclick="delete_target_fact(<?php echo $_SESSION['trg_sel_market']; ?>,<?php echo $slist['trg_id']; ?>,<?php echo $flist['factorid']; ?>,<?php echo $flist['opt_id']; ?>);" title="Delete Varibale Defintion"  class="tar_frmv">[-]</a>
												 <a href="#" class="tar_fdesc"><?php echo $flist['factordes']; ?> =</a>
                                                 <a href="#" class="tar_fopt"><?php echo  $flist['opt_desc']; ?></a>            
                                                </td>
                                            </tr>
                                        <?
                                        }
                                        ?>
                                        
                                        <tr>
                                            <td> 
                                            	<a href="#" title="Add New Varibale Defintion"  class="tar_fadd">[+]</a>
												<a href="#" class="tar_fadd" onclick="Add_Newvar(<?php echo $_SESSION['trg_sel_market']; ?>,<?php echo $slist['trg_id']; ?>,'<?php echo $slist['trg_name']; ?>')">Add New Variable</a>
                                                <a href="#" class="tar_fopt">&nbsp;</a>   
                                            </td>
                                        </tr>                                         
                               </table>
    						</td>
                        </tr>
					
                    <?
                    }
					?>
				</table>
                </form>
            </div>
          </div>
          <!-- End Body First Row Items -->          
          
          <br />

		  

        
        </div>
        <!-- /page content -->

<?php
require_once($application_path . "view/footer.tpl.php");
?>

<script>
	function showdesc(tr) {
		if(tr.style.display=="none") {
			tr.style.display="";
		}
		else {
			tr.style.display="none";	
		}
	}
	
	function delete_target(mrkt,trid) {
		if(confirm("Do you wish to delete this target?")) {
			window.location = "target?deltarg=1&mrktid=" + mrkt + "&trid=" + trid;
		}
	}
	
	function delete_target_fact(mrkt,trid,factid,optid) {
		if(confirm("Do you wish to delete this target variable?")) {
			window.location = "target?deltargfact=1&mrktid=" + mrkt + "&trid=" + trid + "&factid=" + factid + "&optid=" + optid;
		}
	}	
	
	function edit_target(mrkt,trid,trg) {
		var newtarget = prompt("Please Enter Target Name: ", trg);	
		
		if(newtarget!=trg && newtarget!= null) {
			window.location = "target?edittarg=1&mrktid=" + mrkt + "&trid=" + trid + "&newtarg=" + newtarget;
		}
	}
	function Add_Newvar(Mrkt,TargID,TargName) {
			var w = 600;
			var h = 400;
			var left = (window.screen.width / 2) - ((w / 2) + 10);
			var top = (window.screen.height / 2) - ((h / 2) + 50);
			
			myWindow2 = window.open('add_newvar?fisrtcall=1&mrkt='+ Mrkt +'&tarid='+TargID +'&targname='+TargName, 'tinyWindow22','toolbar=false,width='+w+',height='+h+',left='+left+',top='+top+',resizable=no,scrollbars=yes');	
	}	
	
</script>
