<?php 
	$lang 		= $_GET['lang'];	
	$cid 		= $_GET['cid'];	
	$tagidx 	= $_GET['tagidx'];
	$tagnew 	= $_POST['tagnew'];
	
	if (isset($tagnew)) {
		include('r_dbc.php');
		$sql = "insert into ccmanager_tags (cid,tag) values  ('".$cid."','".$tagnew."')";
		$result = mysqli_query($conn, $sql);
		// echo $sql;
	mysqli_close($conn);	
	}

	
	if (isset($tagidx)) { 
		include('r_dbc.php');
		$sql = "delete from ccmanager_tags where id = '".$tagidx."'";
		$result = mysqli_query($conn, $sql);
		// echo $sql;
	mysqli_close($conn);
	}


	include('config.php');
	include('field_names.php'); 
?>

<?php
// RECORD DATA
include('r_dbc.php');

$sql = "SELECT r.code_center,c.desc_center,r.code_categ, k.desc_categ, r.mid, m.desc_manager,r.pid,
		date_format(r.rab_date,'%d-%m-%Y') as rab_datec,
		r.rab_number
		from ccmanager r, centers c, categs k, ccmanager_id m
		where r.cid = '".$cid."'
		and r.pid = c.pid and r.code_center = c.code_center
		and r.pid = k.pid and r.code_categ 	= k.code_categ
		and r.pid = m.pid and r.mid 		= m.mid
		order by 1";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
	printf("<div style='overflow-x:auto;'>");
	printf("<table>");
      while($row = mysqli_fetch_assoc($result)) {
		$pid 			= $row["pid"];  
		$mid 			= $row["mid"];
		$rab_datec 		= $row["rab_datec"];				
		$desc_manager 	= $row["desc_manager"];		
		$code_center 	= $row["code_center"];
		$desc_center 	= $row["desc_center"];		
		$code_categ 	= $row["code_categ"];
		$desc_categ 	= $row["desc_categ"];				
		$rab_number 	= $row["rab_number"];
		$c_rab_number	= number_format($rab_number, 2, $septh, $sepdc);
    }
} 

mysqli_close($conn);
?> 

<!DOCTYPE html>
<html>
<head>
<title>
	  <?php include('title.php'); ?>
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 20%;
  border: 0px solid black;
}
td {
  font-family:verdana;
  padding: 8px;
  border: 0px solid black;
}

th {
  font-family:verdana;
  padding: 8px;
  border: 0px solid black;
  background-color: #d6d6d6
}

tr:nth-child(even){background-color: #f2f2f2}


p.a {
  font-family:verdana;
  text-align:center;
}

</style>
</head>
<body>




<p class="a">
<?php
		printf("<b>$htitle</b>");
		printf("<br><br>");		
		printf("<b>$n_manager </b> : $desc_manager");
		printf("<br>");				
		printf("<b>$n_center </b> : $code_center $desc_center <b>$n_categ </b> : $code_categ $desc_categ");
		printf("<br>");		
		printf("<b>$n_rab_date </b> : $rab_datec <b> $n_rab_number </b> : $c_rab_number");		
		printf("<br><br>");				
		printf("<b>$n_tags</b>");
		printf("<br>");				
?>
</p>



<?php

	printf("<div style='overflow-x:auto;'>");
	printf("<table align=center 	>");
			printf("<tr><th style='text-align:center' colspan=2 >$n_tags</th>
						</tr>");	

// TAGS REPORT
include('r_dbc.php');

$sql = "SELECT tag,id
		from ccmanager_tags
		where cid = '".$cid."'
		order by 1";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
      while($row = mysqli_fetch_assoc($result)) {
		$tag 	= $row["tag"];
		$tagid 	= $row["id"];
			printf("<tr><td style='text-align:center' >$tag</td>
						<td style='text-align:center' ><a href='nf_manager_tags.php?cid=$cid&tagidx=$tagid'><img src='delete.png' height=18 width=18 title='$n_deltag'/></a></td>
						</tr>");

    }
} 

mysqli_close($conn);

?> 

<form action="nf_manager_tags.php?cid=<?php echo $cid ?>" method="post">
<tr>
	<th style='text-align:center' >
		<input type="text" name="tagnew" size="40" maxlength="200">
	</th>
	<th style='text-align:center' >
		<button type="submit" name="submit" class="button">
			<img src="add.png" height=18 width=18 title='<?php echo $n_addnewtag ?>'/>
		</button>
	</th>
</tr>	
</form>


</table>
</div>

</body>
</html>