<?php 
$PageSecurity = 11;
$title = _('Currency Master');
include('includes/SQL_CommonFunctions.inc');
?>
<style type="text/css">
  .cap{
    text-transform:uppercase
    };
</style>
<?php 
if($_REQUEST['action']=='delete' && $_GET['id']!='')
{
	$del_sql=DB_query("Delete from currency_master where id='".$_GET['id']."'",$db);
	echo "<script>location.href='index.php?route=currency_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'] != '')
{
	$sql="INSERT INTO currency_master(country,currency,abbreviation,rate,CompanyId) VALUES('".$_REQUEST['country']."','".$_REQUEST['currency']."','".$_REQUEST['abbreviation']."','".$_REQUEST['rate']."','".$_SESSION['ACGCompanyId']."')";

	$result=DB_query($sql,$db);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=currency_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from currency_master where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['country']=$get_row['country'];
	$_REQUEST['currency']=$get_row['currency'];
	$_REQUEST['abbreviation']=$get_row['abbreviation'];
	$_REQUEST['rate']=$get_row['rate'];
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
$update_sql="Update currency_master SET country='".$_REQUEST['country']."', currency='".$_REQUEST['currency']."',  abbreviation='".$_REQUEST['abbreviation']."',  rate='".$_REQUEST['rate']."' where id='".$_REQUEST['row_id']."' ";
$update_res=DB_query($update_sql,$db);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=currency_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<h2 align="center"><strong>Currency Master</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>Country</strong></th>
    <td><label>
      <select name="country">
	  <?php 
	  $countrysql=DB_query("select * from country_master",$db);
	  while($countryrow=DB_fetch_array($countrysql))
	  {
	  ?>
	  <option value="<?php echo $countryrow['id'];?>"<?php echo ($_REQUEST['country']==$countryrow['id']?'selected':'')?>><?php echo $countryrow['country'];?></option>
	  <?php }?>
      </select>
    </label></td>
  </tr>
  <tr>
    <th><strong>Currency</strong></th>
    <td><input name="currency" type="text" id="currency" value="<?php echo $_REQUEST['currency'];?>" size="30" class="cap"></td>
  </tr>
  <tr>
    <th><strong>Abbreviation</strong></th>
    <td><input name="abbreviation" type="text" id="abbreviation" value="<?php echo $_REQUEST['abbreviation'];?>" size="30" class="cap"></td>
  </tr>
  <tr>
    <th>Rate</th>
    <td><input name="rate" type="text" id="rate" value="<?php echo $_REQUEST['rate'];?>" size="30" class="cap"></td>
  </tr>
</table>
<p align="center">
<?php if($_GET['action']=='edit'){?>
<input type="submit" value="Update" name="Update">
<input type="hidden" name="row_id" value="<?php echo $_GET['id'];?>" id="row_id">
<?php } else {?>
<input type="submit" value="Submit" name="Submit">
<?php }?>
</p>
</form>
<?php 
$curr_sql=DB_query("Select * from currency_master",$db);
?>
<table width="50%" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<th><strong>Country</strong></th>
<th><strong>Currency</strong></th>
<th><strong>Abbreviation</strong></th>
<th><strong>Rate</strong></th>
<th colspan="2"><strong>ACTION</strong></th>
</tr>
<?php
if(DB_num_rows($curr_sql)>0){
while($curr_row=DB_fetch_array($curr_sql))
{ 
?>
<tr>
<td><?php 
$countryname=$s->getField('country_master','id',$curr_row['country'],'country');
echo $countryname;?></td>
<td><?php echo $curr_row['currency'];?></td>
<td><?php echo $curr_row['abbreviation'];?></td>
<td><?php echo $curr_row['rate'];?></td>
<td><a href="index.php?route=currency_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $curr_row['id'];?>&action=edit">Edit</a></td>
<td><a href="index.php?route=currency_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $curr_row['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this record?')">Delete</a></td>
</tr>
<?php } }
else
{?>
<tr>
<td colspan="6"><h3 align="center"><strong><font color="#FF0000">NO RECORD FOUND!</font></strong></h3></td>
</tr>
<?php 
}?>
</table>
<?php 
include('includes/footer.inc');
?>