<?php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('meterinfo');
global $db;
$comz = $_SESSION['comnum'];
?>
<?
if ($_SESSION['access']<4){
if ($_GET['submitType']=='meterCO1') {
    if (isset($_GET['meternum'])) {
        $zzx = $_GET['meternum'];
    } else {
        $zzx = "z1";
    }

$test = bill_insert_meterco($_GET['masterid'], $zzx, $_GET['endread'], $_GET['nmid'], $_GET['newread'],
     date('Y-m-d', strtotime($_GET['codate'])));
if ($test) {
    $log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum']);
    ?>
    echo 'Meter reads Saved';
<?
} else {
    $log->warn($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum']);

    echo 'There was a database error';
}
} else if ($_GET['submitType']=='cust'){
    $test= $result = bill_get_customer($_SESSION['comnum'], $_GET['id']);
    if ($test){
?>
    <script>
    $(function() {
        $( "#codate" ).datepicker({
            showOn: "button",
            buttonImage: "assets/img/calendar.gif",
            buttonImageOnly: true
        });
    });
    </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/meterinfo.php',
    data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#accinfo').html(data);}});return false;">
    <table border="1">
        <tr>
            <td>
    <label for="masterid">Account</label>
            </td>
            <td>
    <input type="hidden" name="masterid" id="masterid" value="<?echo $result[0]['masterid']?>">
    <?echo $result[0]['account']?>
            </td>
        </tr><tr>
            <td>
    <label for="mid">Old Meter ID</label>
            </td>
            <td>
    <input type="hidden" name="meternum" id="meternum" value="<?if ($result[0]['meternum']>0) {
        echo $result[0]['meternum'];} else {echo $mresult[0]['meternum'];};?>">
    <?if ($result[0]['meternum']>0) {
        echo $result[0]['meternum'];} else {echo $mresult[0]['meternum'];};?>
            </td></tr>
            <tr><td>
    <label for="maddr">Meter Address</label>
            </td>
            <td>
    <?echo @$result[0]['maddr'];?>
            </td>
        </tr>
        <tr>
            <td>
    <label for="endread">End Reading</label>
            </td>
            <td>
    <input type="text" name="endread" id="endread" >
            </td>
        </tr><tr>
            <td>
    <label for="nmid">New Meter ID</label>
            </td>
            <td>
    <input type="text" name="nmid" id="nmid" >
            </td>
        </tr>
        <tr>
            <td>
    <label for="newread">New Meter Read</label>
            </td>
            <td>
    <input type="text" name="newread" id="newread" >
            </td>
            </tr><tr>
            <td>
    <label for="codate">Date Completed</label>
            </td>
            <td>
    <input type="text" name="codate" id="codate" >
            </td>
        </tr>
        <tr>
            <td>
    <input type="hidden" name="submitType">
    <input type="submit" onclick="setType('meterCO1')" value="Change Out Meter"/>
            </td>
        </tr>
    </table>
</form>
<?php
} else {
?>
<script>dynamic_Select('includes/acinfo.php', '#accinfo','worder', <?echo $_GET['id'];?>, <?echo $_SESSION['comnum']?>);</script>
<?
}
}
} else {
?>
<script>alert('You do not have a high enough access level to post payments\n\
or charges!\n\
Please see your administrator.');</script>
    <?
}
?>