<?php
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('nminfo');
global $db;
$comz = $_SESSION['comnum'];
if ($_SESSION['access']<4){
if ($_GET['submitType']=='Add') {
   //global $db;
$sql = 'Insert into meters ( id,company,mid, serial,addr,addr1,city,state,zip,lat,lon )'.
        ' VALUES ( NULL, "'.$_GET['comnum'].'","'.$_GET['mid'].'","'.$_GET['serial'].'","'.
        $_GET['addr'].'","'.$_GET['addr1'].'","'.$_GET['city'].'","'.$_GET['state'].'","'.
        $_GET['zip'].'","'.$_GET['lat'].'","'.$_GET['lon'].'")';  


$st = $db->prepare($sql);
$test = $st->execute();
if ($test) {
    echo 'Account Added Successfully';
    $log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);

} else {
    echo 'There was a database error';
    $log->warn($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);

};
echo '<script type=text/javascript>
parent.location.href = parent.location.href;</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/nminfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#accinfo').html(data);}});return false;">
    <table border="1"><tr><td>
    <label for="serial">Serial Number</label></td><td>
    <input type="text" name="serial" id="serial" </td><td> 
    <label for="addr">Address</label></td><td>
    <input type="text" name="addr" id="addr" ></td></tr><tr><td>
    <label for="mid">Meter ID</label></td><td>
    <input type="text" name="mid" id="mid" ></td><td>
    <label for="addr1">Address 1</label></td><td>
    <input type="text" name="addr1" id="addr1" ></td></tr><tr><td> 
    <label for="lat">Latitude</label></td><td>
    <input type="text" name="lat" id="lat" ></td><td>
    <label for="city">City</label></td><td>
    <input type="text" name="city" id="city" ></td></tr><tr><td>
    <label for="lon">Longitude</label></td><td>
    <input type="text" name="lon" id="lon" ></td><td>
    <label for="state">State</label></td><td>
    <input type="text" name="state" id="state" ></td></tr><tr><td>
    <input type="hidden" name="submitType">
    <input type="hidden" name="id" >
    <input type="hidden" name="comnum" value="<?echo $comz; ?>">
    <input type="submit" onclick="setType('Add')"value="Add"/></td><td></td><td>           
    <label for="zip">Zip</label></td><td>
    <input type="text" name="zip" id="zip" ></td></tr>
    </table>
</form>

<?
} else {
?>
<script>alert('You do not have a high enough access level to post payments\n\
or charges!\n\
Please see your administrator.');</script>
    <?    
}