<?php
/* $Revision: 1.19 $ */

$PageSecurity = 11;

include('includes/session.inc');

$title = _('Overhead Maintenance');

include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['SelectedOverhead'])){
	$SelectedOverhead = strtoupper($_GET['SelectedOverhead']);
} else if (isset($_POST['SelectedOverhead'])){
	$SelectedOverhead = strtoupper($_POST['SelectedOverhead']);
}

if (isset($_GET['delete'])){

	 $sql = "DELETE FROM overheadcost WHERE overhead_id=" . $_GET['SelectedOverhead'];
	$result = DB_query($sql,$db,$ErrMsg);
	echo "<meta http-equiv='Refresh' content='0; url=" . $rootpath ."/Overheadcost.php?" . SID . "'>";
}


if (isset($_POST['submit'])) {
$InputError = 0;

			if (strlen($_POST['overheaddescription'])==0)
				 {
					$InputError = 1;
					prnMsg(_('The Overhead Description must be Filled'),'error');
				} 


			if (isset($_POST['submit']) and $InputError !=1){
			 $code=GetNextTransNo(501,$db);
			 
			  $overheaddescription=ucwords($_POST['overheaddescription']); 
			 $sql = 'INSERT INTO overheadcost  set overhead_code="' . $code .'",
					overhead_description="' . $overheaddescription . '"';
												   

					$result = DB_query($sql,$db,$ErrMsg);
					$msg = _('Record inserted');
					prnMsg($msg,'success');
					$ErrMsg = _('Could not insert the new Overhead cost');

	}
	}
	
  $sql = "SELECT * FROM overheadcost";
	$result = DB_query($sql,$db);

	echo "<br><table border=1>\n";
	echo '<tr><th>' . _('Overhead Code') . '</th>
            <th>' . _('Description') . '</th>
           </tr>';

	$k=0; //row colour counter

	while ($myrow = DB_fetch_row($result)) {
		if ($k==1){
			echo '<tr class="EvenTableRows">';
			$k=0;
		} else {
			echo '<tr class="OddTableRows">';
			$k=1;
		}
		printf("<td>%s</td>
            		<td>%s</td>
            		<td><a href=\"%sSelectedOverhead=%s&delete=yes\" onclick=\"return confirm('" . _('Are you sure you wish to delete.') . "');\">" . _('Delete') . "</td>
            		</tr>",
            		$myrow[1],
            		$myrow[2],
            		$_SERVER['PHP_SELF'] . '?' . SID,
            		$myrow[0]);
	}
	
	
	echo '<table width="400" border="1" style="margin-top:50px;">';
	echo '<form name="CategoryForm" method="post" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">';
  echo '<tr>
    <td>Overhead Description</td>
    <td><input type="text" name="overheaddescription" value="'.$myrow2[2].'" /></td>
  </tr>
  <tr>
    
    <td colspan="2" align="center"><input type="submit" name="submit" value="Submit" /></td>
  </tr>
  </form>
</table>';
include('includes/footer.inc');
?>
