<?PHP
include "../inc/var.php";
include "../inc/connect.php";
# include $server_inc."/whm_functions.php";
include $server_inc."/client_functions.php";
include $server_inc."/login_functions.php";

if (isset($submit))
	{
	if (strlen(trim($service_name))==0) 
		{ 
		$err0=true; 
		} 
	else 
		{ 
		if (isset($srid))
			{
			$update="update ";
			$update.="invoice_service set ";
			$update.="service_show_description='".addslashes(trim($service_show_description))."', ";
			if ($service_show_description==1) { $update.="service_description='".addslashes(trim($service_description))."', "; }
			else { $update.="service_description='', "; }

			$update.="service_cost='".addslashes(trim($service_cost))."', ";
			$update.="service_name='".addslashes(trim($service_name))."' ";
			$update.="where srid='".addslashes(trim($srid))."'";

			mysql_query($update);
			}
		else
			{
			$insert="insert into ";
			$insert.="invoice_service set ";
			$insert.="service_show_description='".addslashes(trim($service_show_description))."', ";
			if ($service_show_description==1) { $insert.="service_description='".addslashes(trim($service_description))."', "; }
			
			$insert.="service_cost='".addslashes(trim($service_cost))."', ";
			$insert.="service_name='".addslashes(trim($service_name))."'";

			mysql_query($insert);

			$srid=mysql_insert_id();
			}

		$done=true;
		}
	}

include $server_admin_inc."/header.php";

echo("
	<table width='725' cellpadding='0' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
			<td width='99%' align='left' valign='top'>
			<table width='725' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'> <a href='".$http_admin."/invoice.php?sid=".$sid."'>Invoice Home</a> &gt; [ <a href='".$http_admin."/invoice_add_billable_service.php?sid=".$sid."'>".((isset($srid))?"":"<font color='#990000'>")."Add Billable Services".((isset($srid))?"":"</font>")."</a> ] [ <a href='".$http_admin."/invoice_edit_billable_service.php?sid=".$sid."'>".((isset($srid))?"<font color='#990000'>":"")."Edit Billable Services".((isset($srid))?"":"</font>")."</a> ] [ <a href='".$http_admin."/invoice_delete_billable_service.php?sid=".$sid."'>Delete Billable Services</a> ]</td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><hr color='#F0EFED'></td>
				</tr>
			</table>
	");

if (isset($done))
	{
	echo("
		<table width='725' cellpadding='2' cellspacing='0' border='0'>
			<tr>
				<td align='left' valign='top'><font color='#990000'>The service was ".((isset($srid))?"edited":"created")." successfully!</font></td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><a href='".$http_admin."/invoice_add_billable_service.php?sid=".$sid."'>Add new billable services</a>.</td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><a href='".$http_admin."/invoice_edit_billable_service.php?sid=".$sid."'>Edit existing billable services</a>.</td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><a href='".$http_admin."/invoice_delete_billable_service.php?sid=".$sid."'>Delete existing billable services</a>.</td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'>Make edits to <b>this service</b> below:</td>
			</tr>
			<tr>
				<td align='left' valign='top'><hr align='left' valign='top' color='#F0EFED' width='725'></td>
			</tr>
		</table>
		");
	}

if (isset($srid))
	{
	$query="select ";
	$query.="service_name, ";				// 0
	$query.="service_description, ";		// 1
	$query.="service_show_description, ";	// 2
	$query.="service_cost ";				// 3
	$query.="from invoice_service ";
	$query.="where srid='".addslashes(trim($srid))."'";

	$rs=mysql_fetch_row(mysql_query($query));

	$service_name=stripslashes(trim($rs[0]));
	$service_description=stripslashes(trim($rs[1]));
	$service_show_description=stripslashes(trim($rs[2]));
	$service_cost=stripslashes(trim($rs[3]));
	}

if (isset($err0))
	{
	echo("
			<table width='100%' cellpadding='4' cellspacing='1' border='0'>
				<tr>
					<td><img src='".$http_images."/error_arrow.gif'> You must enter an <b>service Name</b> to continue.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='1' height='4'></td>
				</tr>
			</table>
		");
	}

echo("
			<form action='".$PHP_SELF."' method='POST' name='form1'>
			<input type='hidden' name='sid' value='".$sid."'>
			".((isset($srid))?"<input type='hidden' name='srid' value='".$srid."'>":"")."
			<table width='100%' cellpadding='4' cellspacing='1' border='0'>
				<tr>
					<td width='25%' align='left' valign='middle'>Service Cost:</td>
					<td width='75%' align='left' valign='middle'>".$currency." <input ".$input_style." type='text' size='6' name='service_cost' value='".((isset($service_cost))?"".(($service_cost==0)?"":"".$service_cost."")."":"")."'>&nbsp;".$currency_type."&nbsp;</td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='middle'>Service Name:</td>
					<td width='75%' align='left' valign='middle'><input ".$input_style." type='text' size='30' name='service_name' value='".((isset($service_name))?"".$service_name."":"")."'></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='top'>Service Description:</td>
					<td width='75%' align='left' valign='middle'><font color='#990000'>Show the description below?</font> <input onclick='document.form1.service_description.disabled=false;' type='radio' name='service_show_description' value='1'".((isset($service_show_description))?"".(($service_show_description==1)?" checked":"")."":" checked")."> Yes&nbsp;&nbsp;&nbsp;<input onclick='document.form1.service_description.disabled=true;' type='radio' name='service_show_description' value='0'".((isset($service_show_description))?"".(($service_show_description==0)?" checked":"")."":" checked")."> No<br><textarea name='service_description' rows='3' cols='62' ".$input_style."".((isset($service_show_description))?"".(($service_show_description==0)?" disabled":"")."":"disabled").">".((isset($service_description))?"".$service_description."":"")."</textarea></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='middle'></td>
					<td width='75%' align='left' valign='middle'><img src='".$http_images."/space.gif' width='1' height='12'></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='middle'></td>
					<td width='75%' align='left' valign='middle'><input ".$button_style." type='submit' name='submit' value='".((isset($srid))?"Edit This service Now":"Create This service Now")."'></td>
				</tr>
			</table>
			</form>

			</td>
		</tr>
	</table>
	");

include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>