<?php
// - rateinfo.php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('rateinfo');
if ($_SESSION['access']<3){
    if ($_GET['submitType']=='rates') {
        $result = bill_get_customer($_SESSION['comnum'], $_GET['id']);
        $result1 = bill_get_rates($_SESSION['comnum']);
        extract($result);
        extract($result1);
        if (count($result1)<1) {
            echo 'There are no rate codes set up!  Please go to settings and click on the rate codes button.';
        } else {
?>
            <script>
                function setType(type)
                {
                    //formName is the name of your form
                    document.accinform.submitType.value = type;
                }
            </script>
            Please use the Rate Codes required for this customer from the table on the right<br/>
            You may enter multiple codes by using a colon between the codes. Example (W1:WW3:G2)<br/>
            <form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/rateinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#accinfo').html(data);}});return false;">
            <table>
                <tr>
                    <td>
                        <table border="1">
                            <tr>
                                <td><input type="hidden" name="id" value="<?php echo $zid ?>">
                                    <label for="name">Billing Name</label>
                                </td>
                                <td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>" disabled="disabled">></td>
                            </tr>
                            <tr>
                                <td><label for="account">Account Number</label></td>
                                <td><input type="text" name="account" id="account" value="<?php echo $result[0]['account']?>" disabled="disabled"></td>
                            </tr>
                            <tr>
                                <td><label for="rates">Rate Codes</label></td>
                                <td><input type="hidden" name="submitType">
                                    <input type="text" name="rates" id="rates" value="<?php echo $result[0]['rates']?>"></td>
                            </tr>
                            <tr>
                                <td><input type="submit" onclick="setType('rupdate')" value="Update Customer"/></td>
                                <td></td>
                            </tr>
                        </table>                            
                    </td>
                    <td>
                        <table Border="1">
                            <tr>
                                <th>Name</th>
                                <th>Description</th>
                            </tr>
							<?php
                            for ($i=0;$i<count($result1);$i++) {
                                echo '<tr><td>'.$result1[$i]['name'].'</td><td>'.$result1[$i]['rdesc'].'</td></tr>';    
                            }
							?>
                        </table>
                    </td>
                </tr>   
            </table>                    
            </form>
	<?php   
        }
    } else if ($_GET['submitType']=='rupdate') {
        global $db;
        $log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
        $test = bill_update_custrate($_GET['id'], $_GET['rates']);
        $result = bill_get_customer($_SESSION['comnum'], $_GET['id']);
        $result1 = bill_get_rates($_SESSION['comnum']);
        extract($result);
        extract($result1);
        if (count($result1)<1) {
            echo 'There are no rate codes set up!  Please go to settings and click on the rate codes button.';
        } else {
?>           
            <script>
                function setType(type)
                {
                    //formName is the name of your form
                    document.accinform.submitType.value = type;
                }
            </script>
            Please use the Rate Codes required for this customer from the table on the right<br/>
            You may enter multiple codes by using a colon between the codes. Example (W1:WW3:G2)<br />
            <table>
                <tr>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Amount</th>
                    <th>Code</th>
                </tr>
<?php
                for ($i=0;$i<count($result1);$i++) {
                    echo '<tr><td>'.$result1[$i]['name'].'</td><td>'.$result1[$i]['rdesc'].'</td><td>'.$result1[$i]['amount'].'</td><td>'.$result1[$i]['id'].'</td></tr>';    
                }
?>
            </table>
            <form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/rateinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#accinfo').html(data);}});return false;">
                <table border="1">
                    <tr>
                        <td><input type="hidden" name="id" value="<?php echo $zid ?>">
                            <label for="name">Billing Name</label>
                        </td>
                        <td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="account">Account Number</label></td>
                        <td><input type="text" name="account" id="account" value="<?php echo $result[0]['account']?>" disabled="disabled"></td>
                    </tr>
                    <tr>
                        <td><label for="rates">Rate Codes</label></td>
                        <td><input type="text" name="rates" id="rates" value="<?php echo $result[0]['rates']?>"></td>
                    </tr>
                    <tr>
                        <td><input type="submit" onclick="setType('rupdate')" value="Update Customer"/></td>
                        <td></td>
                    </tr>
                </table>
            </form>
<?php
        } //end result if statment
    } //end submit type
} 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   
}
?>