<?php
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('rtypeinfo');
if ($_SESSION['access']<3){
if ($_GET['submitType']=='cust') {
global $db;
$zid = $_SESSION['comnum'];
//if (empty($arr)){
$sql = 'SELECT * FROM r_types WHERE comnum = "'.$zid.'"';
$st = $db->prepare($sql);
$st->execute();
$result = $st->fetchAll();
echo '<script>
   function setType(type)
   {
      //formName is the name of your form
      document.accinform.submitType.value = type;
   }
</script>
<table border="1"><tr><th>Name</th><th>Type</th></tr>';
    extract($result);
    for ($i=0;$i<count($result);$i++) {
    $res1 = $result[$i];
    echo '<tr><td><button type="button" value="Edit" onClick="';?>
    dynamic_Select('/bill/includes/rtypeinfo.php', '#setinfo', 'Edit',<? echo 
    $_res1['id'].','.$_SESSION['comnum'].')">'.$res1['name'].'</button></td><td>'.$res1['type'].'</td></tr>';
    }
    echo '</table>';

} else if ($_GET['submitType']=='cUpdate') {
    
$sql = 'UPDATE company SET name = "'.$_GET['name'].'", shortname = "'.$_GET['shortname'].
        '", addr = "'.$_GET['addr'].'", addr1 = "'.$_GET['addr1'].'", city = "'.$_GET['city'].
        '", state = "'.$_GET['state'].'", zip ="'.$_GET['zip'].'", phone = "'.$_GET['phone'].
        '", fax = "'.$_GET['fax'].'", web = "'.$_GET['web'].'", bill_email = "'.
        $_GET['bill_email'].'", oncall_email = "'.$_GET['oncall_email'].'", office_email = "'.
        $_GET['office_email'].'", oncall_phone = "'.$_GET['oncall_phone'].
        '" WHERE id = "'.$_GET['id'].'"';
//echo $sql;
$st = $db->prepare($sql);
$st->execute();
$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
$sql = 'SELECT * FROM company WHERE id = "'.$_GET['id'].'"';
$st = $db->prepare($sql);
$st->execute();
$result = $st->fetchAll();
//echo print_r($sql);
?>
<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:'/bill/includes/rtypeinfo.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="<? echo $result[0]['id']?>" disabled="disabled"></td><td>
    <label for="shortname">Short Name</label></td><td>
    <input type="text" name="shortname" id="shortname" value="<? echo $result[0]['shortname']?>"> </td></tr><tr><td>
    <label for="name">Name</label></td><td>
    <input type="text" name="name" id="name" value="<? echo $result[0]['name']?>"></td><td>
    <label for="phone">Phone Number</label></td><td>
    <input type="text" name="phone" id="phone" value="<? echo $result[0]['phone']?>"></td></tr><tr><td> 
    <label for="addr">Address</label></td><td>
    <input type="text" name="addr" id="addr" value="<? echo $result[0]['addr']?>"></td><td> 
    <label for="fax">Fax Number</label></td><td>
    <input type="text" name="fax" id="fax" value="<? echo $result[0]['fax']?>"></td></tr><tr><td>
    <label for="addr1">Address 1</label></td><td>
    <input type="text" name="addr1" id="addr1" value="<? 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="<? echo $result[0]['bill_email']?>"></td></tr><tr><td>
    <label for="city">City</label></td><td>
    <input type="text" name="city" id="city" value="<? 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="<? echo $result[0]['office_email']?>"></td></tr><tr><td>
    <label for="state">State</label></td><td>
    <input type="text" name="state" id="state" value="<? 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="<? echo $result[0]['oncall_email']?>"></td></tr><tr><td>
    <label for="zip">Zip</label></td><td>
    <input type="text" name="zip" id="zip" value="<? 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="<? echo $result[0]['oncall_phone']?>"></td></tr><tr><td>
    <input type="hidden" name="submitType">
    <input type="hidden" name="id" value="<? echo $result[0]['id']?>">
    <label for="web">Web Address</label></td><td>
    <input type="text" name="web" id="web" value="<? 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="Hide Information"/></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>
    <?    
}
?>
