<?php
// - compinfo.php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('compinfo');
if ($_SESSION['access']<4){
	if ($_GET['submitType']=='cust') {
		$result = bill_get_company($_SESSION['comnum']);
?>
	<script>
   		function setType(type)
   		{
      		//formName is the name of your form
      		document.accinform.submitType.value = type;
   		}
	</script>
	<form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/compinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#setinfo').html(data);}});return false;">
    	<table border="1">
        	<tr>
           	 	<td><label for="id1">Company ID Number</label></td>
            	<td><input type="text" name="id1" id="id1" value="<?php echo $result[0]['id']?>" disabled="disabled"></td>
            	<td><label for="shortname">Short Name</label></td>
            	<td><input type="text" name="shortname" id="shortname" value="<?php echo $result[0]['shortname']?>"> </td>
        	</tr>
        	<tr>
            	<td><label for="name">Name</label></td>
            	<td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>"></td>
            	<td><label for="phone">Phone Number</label></td>
            	<td><input type="text" name="phone" id="phone" value="<?php echo $result[0]['phone']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="addr">Address</label></td>
            	<td><input type="text" name="addr" id="addr" value="<?php echo $result[0]['addr']?>"></td>
            	<td><label for="fax">Fax Number</label></td>
            	<td><input type="text" name="fax" id="fax" value="<?php echo $result[0]['fax']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="addr1">Address 1</label></td>
            	<td><input type="text" name="addr1" id="addr1" value="<?php echo $result[0]['addr1']?>"></td>
            	<td><label for="bill_email">Billing Email</label></td>
            	<td><input type="text" name="bill_email" id="bill_email" value="<?php echo $result[0]['bill_email']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="city">City</label></td>
            	<td><input type="text" name="city" id="city" value="<?php echo $result[0]['city']?>"></td>
            	<td><label for="office_email">Office Email</label></td>
            	<td><input type="text" name="office_email" id="office_email" value="<?php echo $result[0]['office_email']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="state">State</label></td>
    	        <td><input type="text" name="state" id="state" value="<?php echo $result[0]['state']?>"> </td>
        	    <td><label for="oncall_email">Oncall Email</label></td>
            	<td><input type="text" name="oncall_email" id="oncall_email" value="<?php echo $result[0]['oncall_email']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="zip">Zip</label></td>
    	        <td><input type="text" name="zip" id="zip" value="<?php echo $result[0]['zip']?>"> </td>
        	    <td><label for="oncall_phone">Oncall Phone</label></td>
            	<td><input type="text" name="oncall_phone" id="oncall_phone" value="<?php echo $result[0]['oncall_phone']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="bonecodeid">Bill USPS BarCode</label></td>
	            <td><input type="text" name="bonecodeid" id="bonecodeid" value="<?php echo $result[0]['bonecodeid']?>"></td>
    	        <td><label for="nonecodeid">Notice USPS BarCode</label></td>
        	    <td><input type="text" name="nonecodeid" id="nonecodeid" value="<?php echo $result[0]['nonecodeid']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="uspstrack">USPS Tracking</label></td>
    	        <td><input type="text" name="uspstrack" id="uspstrack" value="<?php echo $result[0]['uspstrack']?>"></td>
        	    <td><label for="uspspermit">USPS Permit Label 1</label></td>
            	<td><input type="text" name="uspspermit" id="uspspermit" value="<?php echo $result[0]['uspspermit']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="uspspermit1">USPS Permit Label 2</label></td>
    	        <td><input type="text" name="uspspermit1" id="uspspermit1" value="<?php echo $result[0]['uspspermit1']?>"></td>
        	    <td><label for="uspspermit2">USPS Permit Label 3</label></td>
            	<td><input type="text" name="uspspermit2" id="uspspermit2" value="<?php echo $result[0]['uspspermit2']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="uspspermit3">USPS Permit Label 4</label></td>
            	<td><input type="text" name="uspspermit3" id="uspspermit3" value="<?php echo $result[0]['uspspermit3']?>"></td>
            	<td><label for="uspspermit4">USPS Permit Label 5</label></td>
            	<td><input type="text" name="uspspermit4" id="uspspermit4" value="<?php echo $result[0]['uspspermit4']?>"></td>
        	</tr>
			<tr>
				<td><label for="uspspermit5">USPS Permit Label 6</label></td>
            	<td><input type="text" name="uspspermit5" id="uspspermit5" value="<?php echo $result[0]['uspspermit5']?>"></td>
            	<td><label for="billformat">Bill Format</label></td>
            	<td><input type="text" name="billformat" id="billformat" value="<?php echo $result[0]['billformat']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="lateformat">Notice Format</label></td>
    	        <td><input type="text" name="lateformat" id="lateformat" value="<?php echo $result[0]['lateformat']?>"></td>
        	    <td><label for="aread">Auto Read Settings</label></td>
            	<td><input type="text" name="aread" id="aread" value="<?php echo $result[0]['aread']?>"></td>
        	</tr>
        	<tr>
				<td><label for="nmrows">Batch Rows</label></td>
            	<td><input type="text" name="nmrows" id="nmrows" value="<?php echo $result[0]['nmrows']?>"> </td>
            	<td><label for="webs">WEBS (Future)</label></td>
            	<td><input type="text" name="webs" id="webs" value="<?php echo $result[0]['webs']?>"></td>
        	</tr>
            <tr>
				<td><label for="highlimit">Leak Limit</label></td>
            	<td><input type="text" name="highlimit" id="highlimit" value="<?php echo $result[0]['highlimit']?>"> </td>
        	</tr>
        	<tr>
            	<td><input type="hidden" name="submitType">
                	<input type="hidden" name="id" value="<?php echo $result[0]['id']?>">
                	<label for="web">Web Address</label>
				</td>
            	<td><input type="text" name="web" id="web" value="<?php echo $result[0]['web']?>"> </td>
            	<td><input type="submit" onclick="setType('cUpdate')" value="Update Company Information"></td>
            	<td><input type="submit" onclick="setType('hpdate')" value="Cancel"></td>
        	</tr>
    	</table>
</form>
	<?php } 
	else if ($_GET['submitType']=='cUpdate') {
		$res1 = bill_update_company($_GET['name'], $_GET['shortname'], $_GET['addr'], $_GET['addr1'],
        	$_GET['city'], $_GET['state'], $_GET['zip'], $_GET['phone'], $_GET['fax'], $_GET['web'],
        	$_GET['bill_email'], $_GET['oncall_email'], $_GET['office_email'], $_GET['oncall_phone'],
        	$_GET['webs'], $_GET['aread'], $_GET['nmrows'], $_GET['lateformat'], $_GET['billformat'],
        	$_GET['uspstrack'], $_GET['uspspermit'], $_GET['uspspermit1'], $_GET['uspspermit2'],
        	$_GET['uspspermit3'], $_GET['uspspermit4'], $_GET['uspspermit5'], $_GET['bonecodeid'],
        	$_GET['nonecodeid'], $_GET['highlimit'] ,$_SESSION['comnum']);
		$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
		$result = bill_get_company($_GET['id']);
		if ($result){
			echo '<script type=text/javascript>alert("Account updated successfully!");</script>';
		}
	?>
		<script>
   			function setType(type)
   			{
      			//formName is the name of your form
      			document.accinform.submitType.value = type;
   			}
		</script>
		<form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/compinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#setinfo').html(data);}});return false;">
    	<table border="1">
			<tr>
            	<td><label for="id1">Company ID Number</label></td>
            	<td><input type="text" name="id1" id="id1" value="<?php echo $result[0]['id']?>" disabled="disabled"></td>
            	<td><label for="shortname">Short Name</label></td>
            	<td><input type="text" name="shortname" id="shortname" value="<?php echo $result[0]['shortname']?>"> </td>
        	</tr>
        	<tr>
            	<td><label for="name">Name</label></td>
            	<td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>"></td>
            	<td><label for="phone">Phone Number</label></td>
            	<td><input type="text" name="phone" id="phone" value="<?php echo $result[0]['phone']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="addr">Address</label></td>
            	<td><input type="text" name="addr" id="addr" value="<?php echo $result[0]['addr']?>"></td>
            	<td><label for="fax">Fax Number</label></td>
            	<td><input type="text" name="fax" id="fax" value="<?php echo $result[0]['fax']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="addr1">Address 1</label></td>
            	<td><input type="text" name="addr1" id="addr1" value="<?php echo $result[0]['addr1']?>"></td>
            	<td><label for="bill_email">Billing Email</label></td>
            	<td><input type="text" name="bill_email" id="bill_email" value="<?php echo $result[0]['bill_email']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="city">City</label></td>
            	<td><input type="text" name="city" id="city" value="<?php echo $result[0]['city']?>"></td>
            	<td><label for="office_email">Office Email</label></td>
            	<td><input type="text" name="office_email" id="office_email" value="<?php echo $result[0]['office_email']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="state">State</label></td>
            	<td><input type="text" name="state" id="state" value="<?php echo $result[0]['state']?>"> </td>
            	<td><label for="oncall_email">Oncall Email</label></td>
            	<td><input type="text" name="oncall_email" id="oncall_email" value="<?php echo $result[0]['oncall_email']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="zip">Zip</label></td>
            	<td><input type="text" name="zip" id="zip" value="<?php echo $result[0]['zip']?>"> </td>
            	<td><label for="oncall_phone">Oncall Phone</label></td>
            	<td><input type="text" name="oncall_phone" id="oncall_phone" value="<?php echo $result[0]['oncall_phone']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="bonecodeid">Bill USPS BarCode</label></td>
            	<td><input type="text" name="bonecodeid" id="bonecodeid" value="<?php echo $result[0]['bonecodeid']?>"></td>
            	<td><label for="nonecodeid">Notice USPS BarCode</label></td>
            	<td><input type="text" name="nonecodeid" id="nonecodeid" value="<?php echo $result[0]['nonecodeid']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="uspstrack">USPS Tracking</label></td>
            	<td><input type="text" name="uspstrack" id="uspstrack" value="<?php echo $result[0]['uspstrack']?>"></td>
            	<td><label for="uspspermit">USPS Permit Label 1</label></td>
            	<td><input type="text" name="uspspermit" id="uspspermit" value="<?php echo $result[0]['uspspermit']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="uspspermit1">USPS Permit Label 2</label></td>
            	<td><input type="text" name="uspspermit1" id="uspspermit1" value="<?php echo $result[0]['uspspermit1']?>"></td>
            	<td><label for="uspspermit2">USPS Permit Label 3</label></td>
            	<td><input type="text" name="uspspermit2" id="uspspermit2" value="<?php echo $result[0]['uspspermit2']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="uspspermit3">USPS Permit Label 4</label></td>
    	        <td><input type="text" name="uspspermit3" id="uspspermit3" value="<?php echo $result[0]['uspspermit3']?>"></td>
        	    <td><label for="uspspermit4">USPS Permit Label 5</label></td>
            	<td><input type="text" name="uspspermit4" id="uspspermit4" value="<?php echo $result[0]['uspspermit4']?>"></td>
        	</tr>
        	<tr>
	            <td><label for="uspspermit5">USPS Permit Label 6</label></td>
    	        <td><input type="text" name="uspspermit5" id="uspspermit5" value="<?php echo $result[0]['uspspermit5']?>"></td>
        	    <td><label for="billformat">Bill Format</label></td>
            	<td><input type="text" name="billformat" id="billformat" value="<?php echo $result[0]['billformat']?>"></td>
	        </tr>
    	    <tr>
        	    <td><label for="lateformat">Notice Format</label></td>
            	<td><input type="text" name="lateformat" id="lateformat" value="<?php echo $result[0]['lateformat']?>"></td>
            	<td><label for="aread">Auto Read Settings</label></td>
            	<td><input type="text" name="aread" id="aread" value="<?php echo $result[0]['aread']?>"></td>
        	</tr>
        	<tr>
            	<td><label for="nmrows">Batch Rows</label></td>
            	<td><input type="text" name="nmrows" id="nmrows" value="<?php echo $result[0]['nmrows']?>"></td>
            	<td><label for="webs">WEBS (Future)</label></td>
            	<td><input type="text" name="webs" id="webs" value="<?php echo $result[0]['webs']?>"></td>
        	</tr>
            <tr>
				<td><label for="highlimit">Leak Limit</label></td>
            	<td><input type="text" name="highlimit" id="highlimit" value="<?php echo $result[0]['highlimit']?>"> </td>
        	</tr>
        	<tr>
            	<td><input type="hidden" name="submitType">
            		<input type="hidden" name="id" value="<?php echo $result[0]['id']?>">
            		<label for="web">Web Address</label>
				</td>
            	<td><input type="text" name="web" id="web" value="<?php echo $result[0]['web']?>"> </td>
            	<td><input type="submit" onclick="setType('cUpdate')" value="Update Company Information"/></td>
            	<td><input type="submit" onclick="setType('hpdate')" value="Cancel"/></td>
        	</tr>
    	</table>
		</form>
<?php
	} else {
    	echo '';
	}
} else {
?>
<script>alert('You do not have a high enough access level to post payments\n\
or charges!\n\
Please see your administrator.');</script>
<?php } ?>