<?php
session_start();
include_once("config.php");
$error_msg="";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arabic Translation</title>
<style>
	body {
		font-family: Tahoma, Geneva, sans-serif;
		font-size: 14px;
		font-weight: bold;
	}
	th {
		background-color:#999;
		font-family: Tahoma, Geneva, sans-serif;
		font-size: 14px;
		font-weight: bold;
	}
	td {
		font-family: Tahoma, Geneva, sans-serif;
		font-size: 12px;
	}
	.err_msg {
		font-family: Tahoma, Geneva, sans-serif;
		font-size: 12px;
		color:#F00;
	}
	
</style>
</head>
<?php
if(isset($_REQUEST['submit_button'])) {
	foreach($_POST as $frmky=>$frm_itms) {
		if(substr($frmky,0,2) == "ID") {
			$frm_ary = explode("_",$frmky);
			$frm_en_text = "lan_".$frm_ary[1]."_en";
			$frm_ar_text = "lan_".$frm_ary[1]."_ar";

			$upsql = 'update seas_brd_target set tar_desc = "' . trim($_POST[$frm_en_text]) . '", tar_desc_ar = "' . trim($_POST[$frm_ar_text]) . '" where tar_id = '.$frm_ary[1];
			
			mysql_query($upsql);
			
			if(strlen(mysql_error()) >0) {
				$error_msg .= "<br>Updation failed for Key: " . $frm_itms . " Error: " . mysql_error();
			}
		}
	}
}
?>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
  <?php
$sql  = "select tar_id,tar_desc,tar_desc_ar from seas_brd_target order by tar_id";
$rslt = mysql_query($sql);
?>
<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border-collapse:collapse; border: thin #000">
<tr>
	<th width="20%" height="30px">Key</th>
    <th width="40%">English Text</th>
    <th width="40%">Arabic Text</th>
</tr>
<?php
while($row=mysql_fetch_assoc($rslt)) {
	echo "<tr>";
		echo '<td  align="left" valign="top" bgcolor="#FFFFFF">';
		echo '<input name="ID_'. $row['tar_id'] .'" type="text" style="width:98%;border:0px" maxlength="100" value="'. $row['tar_id'].'" readonly="readonly" />'; 
		echo "</td>";
		echo '<td  align="left" valign="top" bgcolor="#FFFFFF">';
		echo '<textarea name="lan_'. $row['tar_id'] .'_en" cols="45" rows="2" style="width:98%;border:0px" >'.$row['tar_desc'].'</textarea>';
		echo "</td>";
		echo '<td  align="left" valign="top" bgcolor="#FFFFFF">';
		echo '<textarea name="lan_'. $row['tar_id'] .'_ar" cols="45" rows="2" style="width:98%;border:0px" dir="rtl" >'.$row['tar_desc_ar'].'</textarea>';
		echo "</td>";
	echo "</tr>";
}
?>
</table>
	
  <table width="100%" border="1" cellspacing="0" cellpadding="5" style="border-collapse:collapse; border: thin #000">
    <tr>
      <td height="30" colspan="3" bgcolor="#FFFF33"><input type="submit" name="submit_button" id="button" value="Save" /><span class="err_msg">
      <?php
      
	  echo $error_msg;
	  
	  ?></span></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>
