fmc1962 icon

Button Disabling

fmc1962 | PRO | 11/22/15 08:51:11 PM UTC | 0 ⭐ | 329 👁️ | Never ⏰ | []
HTML 5 |

0 B

|

None

|

0 👍

/

0 👎

<?php
    session_start(['cookie_lifetime' => 2400,
                        'use_only_cookies' => true,
    ]);
    
    require_once '../root_login.php';
    
    // The following makes sure the pages load using HTTPS  
    /*if ($_SERVER['HTTPS'] != "on") {
    $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
   } */
 
    if ($_SESSION["memberid"] == "") {
    header("Location: wslogin.php");
    exit();
    } 
    
    //$_SESSION['id'] = $_POST['view'];
    //$_SESSION['groupid'] = $_POST['groupid'];
?>
 
<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->
        
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
        <script>
            window.jQuery || document.write('<script src="js/jquery-2.0.0.min.js"><\/script>')
        </script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        
        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
        
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        
        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        
        <script src='https://www.google.com/recaptcha/api.js'></script>
        
        <!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
        
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        
        <style type="text/css">
            td {
                color: #fff;
                text-transform: uppercase;                  
                width: auto;
             }
            th {
                color: #000;
                background-color: #F5FFFA;
                text-transform: uppercase;                  
                width: auto;
             }
             
        </style>
        <script type="text/javascript">
            function flushOn() {
                document.getElementById("flushBtn").setAttribute('disabled',false);
            }
            function flushOff() {
                document.getElementById("flushBtn").setAttribute('disabled',true);
            }
        </script>
    
    </head>
        <body>
        <!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
        <div class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
        <div class="container">
                <div class="navbar-header">
                    <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" style="font-weight: bold"><?php echo $_SESSION['uname']; ?>'s Work Station</a>
                </div>
                <div id="navbarCollapse" class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Attendee<strong class="caret"></strong></a>
                                <ul class="dropdown-menu">
                                    <li><a href="wsaddattendees.php">Add</a></li>                                       
                                    <li><a href="wsdeleteattendees.php">Delete</a></li>
                                    <li><a href="wseditattendees.php">Edit</a></li>
                                </ul>
                        </li>   
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Payment<strong class="caret"></strong></a>
                                <ul class="dropdown-menu">
                                    <li><a href="wsadjustpayments.php">Rollback</a></li>
                                    <li><a href="wseditpayments.php">Edit Payment / Subsidy</a></li>
                                    <li><a href="wspostpayments.php">Post</a></li>  
                                    <li><a href="wssuspendpayments.php">Suspend</a></li>                                
                                </ul>               
                        </li>   
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">View<strong class="caret"></strong></a>
                                <ul class="dropdown-menu">
                                    <li><a href="wsviewattendance.php">Attendance</a></li>
                                    <li><a href="wsviewattendees.php">Attendees</a></li>
                                    <li><a href="wsviewattendeesbygroup.php">Attendees by Group</a></li>
                                    <li><a href="wsviewattendeesbypo.php">Attendees by P.O.</a></li>
                                    <li><a href="wsviewpayments.php">Payments</a></li>
                                    <li><a href="wsviewsuspendedpayments.php">Suspended Payments</a></li>
                                    <li><a href="wsviewfiscalquarters.php">Fiscal Quarters</a></li>
                                </ul>                   
                        </li>       
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Assignments<strong class="caret"></strong></a>                     
                                <ul class="dropdown-menu">
                                <li><a href="#">Completed</a></li>
                                <li><a href="#">Current</a></li>
                                </ul>                                           
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Upcoming<strong class="caret"></strong></a>                    
                                <ul class="dropdown-menu">
                                <li><a href="#">Polygraphs</a></li>
                                <li><a href="#">Evaluations</a></li>
                                <li><a href="#">Other</a></li>
                                </ul>                                           
                        </li>
                        <li>
                            <a href="#">DRA</a>
                        </li>   
                        <li>
                            <a href="wshelp.php">Help</a>
                        </li>
                        <!--<li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Help<strong class="caret"></strong></a>                    
                                <ul class="dropdown-menu">
                                    <li><a href="#">Attendees</a></li>
                                <li><a href="#">Payments</a></li>
                                </ul>                                           
                        </li>   -->         
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row" style="margin-top:51px">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2>Post Attendee Payments</h2>
                    </div>
                </div>
            </div>
            <form method="post" class="subform" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
                <div class="row" style="background: skyblue; margin-top:-23px">
                    <div class="col-sm-2">
                        <div class="input-group">
                            <select class="form-control" name="groupid" onchange="this.form.submit();">
                                <option name="0"<?php echo ($_POST['groupid'] == '0') ? ' selected="selected"' : ''; ?> value="0" >GROUP</option>
                                <option name="1"<?php echo ($_POST['groupid'] == '1') ? ' selected="selected"' : ''; ?> value="1" >1</option>
                                <option name="2"<?php echo ($_POST['groupid'] == '2') ? ' selected="selected"' : ''; ?> value="2" >2</option>
                                <option name="3"<?php echo ($_POST['groupid'] == '3') ? ' selected="selected"' : ''; ?> value="3" >3</option>
                                <option name="4"<?php echo ($_POST['groupid'] == '4') ? ' selected="selected"' : ''; ?> value="4" >4</option>
                                <option name="5"<?php echo ($_POST['groupid'] == '5') ? ' selected="selected"' : ''; ?> value="5" >5</option>
                                <option name="6"<?php echo ($_POST['groupid'] == '6') ? ' selected="selected"' : ''; ?> value="6" >6</option>
                                <option name="7"<?php echo ($_POST['groupid'] == '7') ? ' selected="selected"' : ''; ?> value="7" >7</option>
                                <option name="8"<?php echo ($_POST['groupid'] == '8') ? ' selected="selected"' : ''; ?> value="8" >8</option>
                                <option name="9"<?php echo ($_POST['groupid'] == '9') ? ' selected="selected"' : ''; ?> value="9" >9</option>    
                                <option name="10"<?php echo ($_POST['groupid'] == '10') ? ' selected="selected"' : ''; ?> value="10" >10</option>
                                <option name="11"<?php echo ($_POST['groupid'] == '11') ? ' selected="selected"' : ''; ?> value="11" >11</option>
                                <option name="12"<?php echo ($_POST['groupid'] == '12') ? ' selected="selected"' : ''; ?> value="12" >12</option>
                                <option name="13"<?php echo ($_POST['groupid'] == '13') ? ' selected="selected"' : ''; ?> value="13" >13</option>
                                <option name="14"<?php echo ($_POST['groupid'] == '14') ? ' selected="selected"' : ''; ?> value="14" >14</option>
                                <option name="15"<?php echo ($_POST['groupid'] == '15') ? ' selected="selected"' : ''; ?> value="15" >15</option>
                                <option name="16"<?php echo ($_POST['groupid'] == '16') ? ' selected="selected"' : ''; ?> value="16" >16</option>
                                <option name="17"<?php echo ($_POST['groupid'] == '17') ? ' selected="selected"' : ''; ?> value="17" >17</option>
                                <option name="18"<?php echo ($_POST['groupid'] == '18') ? ' selected="selected"' : ''; ?> value="18" >18</option>
                                <option name="19"<?php echo ($_POST['groupid'] == '19') ? ' selected="selected"' : ''; ?> value="19" >19</option>
                                <option name="20"<?php echo ($_POST['groupid'] == '20') ? ' selected="selected"' : ''; ?> value="20" >20</option>
                                <option name="21"<?php echo ($_POST['groupid'] == '21') ? ' selected="selected"' : ''; ?> value="21" >21</option>
                                <option name="22"<?php echo ($_POST['groupid'] == '22') ? ' selected="selected"' : ''; ?> value="22" >22</option>
                                <option name="23"<?php echo ($_POST['groupid'] == '23') ? ' selected="selected"' : ''; ?> value="23" >23</option>
                                <option name="24"<?php echo ($_POST['groupid'] == '24') ? ' selected="selected"' : ''; ?> value="24" >24</option>
                                <option name="25"<?php echo ($_POST['groupid'] == '25') ? ' selected="selected"' : ''; ?> value="25" >25</option>
                                <option name="26"<?php echo ($_POST['groupid'] == '26') ? ' selected="selected"' : ''; ?> value="26" >26</option>
                                <option name="27"<?php echo ($_POST['groupid'] == '27') ? ' selected="selected"' : ''; ?> value="27" >27</option>
                                <option name="28"<?php echo ($_POST['groupid'] == '28') ? ' selected="selected"' : ''; ?> value="28" >28</option>
                                <option name="29"<?php echo ($_POST['groupid'] == '29') ? ' selected="selected"' : ''; ?> value="29" >29</option>
                                <option name="30"<?php echo ($_POST['groupid'] == '30') ? ' selected="selected"' : ''; ?> value="30" >30</option>                               
                            </select>
                    <span class="input-group-btn">
                        <!--<input type="submit" name="load" class="btn btn-default" value="Load">-->                   
                        <input type="submit" id="dumpBtn" name="dump" class="btn btn-danger" value="Dump">
                    </span>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="input-group">
                        <select class="form-control" name="view" style="text-transform: uppercase"> 
                            <option value="">Select</option>
                                <?php               
                                if ($_SERVER["REQUEST_METHOD"] == "POST") { // First brace  
                                    
                                    $payment = $paymentErr = "";                        
                                    $_SESSION['groupid'] = $_POST['groupid'];
                                    /* $memberid = $_SESSION["memberid"];  We use $memberid to load the Select options box (below) to make
                                                                                sure that that ONLY attendee information for THAT member is loaded */
                                    $_SESSION['id'] = $_POST['view'];
                                    
                                    /* Set session vars for uname and pwd1 from invalidlogin.php to be able to login using login.php */
                                    //$uname = $_SESSION['uname']; // Set $name for login.php
                                    //$pwd1 = $_SESSION['pwd1'];  // Set $pwd1 for login.php
                                    //require_once '../root_login.php'; // This file contains database access credentials                                       
                                    
                                    // Load the Select Box with names that match the groupid and memberid
                                        $stmt = $db->prepare('SELECT a.attendeeid, fname, lname, a.groupid, a.memberid, s.attendeeid, suspend
                                                                        FROM attendees AS a
                                                                        JOIN suspended AS s ON a.attendeeid = s.attendeeid 
                                                                        WHERE a.memberid = :memberid 
                                                                        AND suspend = "N"
                                                                        AND a.groupid = :groupid
                                                                        ORDER BY lname');
                                        $stmt->bindValue(':memberid', $_SESSION["memberid"], PDO::PARAM_INT);
                                        $stmt->bindValue(':groupid', $_SESSION['groupid'], PDO::PARAM_INT);
                                        $stmt->execute();
                                        $result = $stmt->fetchAll();
                                        foreach($result as $row){ 
                                            
                                            // Load the flush Table with the IDs from the selected group
                                            if($_SESSION['flush'] == 0) {
                                                $stmt = $db->prepare('INSERT INTO flush (attendeeid, memberid)
                                                                                VALUES(:attendeeid, :memberid)');
                                                $stmt->bindValue(':attendeeid', $row[0], PDO::PARAM_INT);
                                                $stmt->bindValue(':memberid', $row[4], PDO::PARAM_INT);
                                                $stmt->execute();
                                            }
                                            echo "<option value='$row[0]'"; // Holds selected name from click to click without resetting to Select
                                          if(isset($_SESSION['id']) and $_SESSION['id'] == $row[0]) {
                                             echo ' selected="selected"';
                                          }
                                          echo ">$row[2], $row[1]</option>"; 
                                        }?>
                            </select>
                        <?php $_SESSION['flush'] = 1; ?> 
                            <span class="input-group-btn">
                        <input type="submit" id="fetchBtn" name="fetch" class="btn btn-default" value="Fetch"  onclick="flushOff()">
                    </span>
                        </div>
                    </div>
                    <div class="col-sm-offset-6">
                        <div class="input-group">
                            <span class="input-group-btn">
                        <input type="submit" id="flushBtn" name="flush" class="btn btn-danger" value="Flush">
                    </span>
                        </div>
                    </div>
                </div>
                <?php if(($_POST['dump']) || ($_POST['flush'])) { ?>
                <div class="row" style="margin-top:20px">
                    <div class="col-sm-3">
                        <label style="text-transform: uppercase; color: red" class="control-label">Dumped Group <?php echo $_SESSION['groupid']; ?></label>             
                    </div>
                </div>
                <?php } else{ ?>
                <div class="row" style="margin-top:20px">
                    <div class="col-sm-3">
                        <label style="text-transform: uppercase; color: red" class="control-label">Group <?php echo $_SESSION['groupid']; ?> Loaded</label>             
                    </div>
                </div>
                <?php } ?>
                <div class="row" style="margin-top:20px">
                    <div class="col-sm-3">
                        <label style="text-transform: uppercase" class="control-label">Payment:</label>             
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <span class="input-group-addon">$</span>
                            <input class="form-control" type="text" name="payment" placeholder="0.00" 
                                value="<?php if (isset($_POST['payment'])) { echo $payment; } ?>">
                            <span class="input-group-btn">
                          <input type="submit" name="postpayment" class="btn btn-primary" value="Post">
                       </span>
                                <span class="error"><?php echo $paymentErr;?></span>
                        </div>
                    </div>
                </div>
                <?php                   
                if($_POST['dump']) { 
                    $stmt = $db->prepare('DELETE FROM flush WHERE memberid = :memberid');
                    $stmt->bindValue(':memberid', $_SESSION['memberid'], PDO::PARAM_INT);
                    $stmt->execute();   
                    $_SESSION['flush'] = 0;
                    echo '<script type="text/javascript">alert("Please select a new Group"); </script>';
                }
                if($_POST['fetch']) {
                    $id = $_POST['view']; // Pass this to see which attendee was selected in the Selection box options
                    $_SESSION['id'] = $_POST['view'];
                    $i = 0; // Set to use below in alternating bg-colors with function getbgc($i)
                    if($id == '') { exit(); // Nothing was selected
                        
                } else {
                    try { 
                        $stmt = $db->prepare('SELECT fname, lname, amount, subsidy, last_payment, amount_paid, balance, a.groupid, a.attendeeid, h.historyid
                                                        FROM history AS h 
                                                        INNER JOIN attendees AS a ON a.attendeeid = h.attendeeid
                                                        where h.attendeeid = :id
                                                        ORDER BY h.historyid DESC LIMIT 1');
                        $stmt->bindValue(':id', $_SESSION['id'], PDO::PARAM_INT);
                        $stmt->execute();
                        $result = $stmt->fetchAll(); ?> 
                        
                        <div class="row">
                            <div class="table-repsonsive">
                                <table class="table" style="margin-top:30px">
                                    <thead>
                                        <tr>
                                            <th style="width:auto">F-Name</th>
                                            <th style="width:auto">L-Name</th>
                                            <th style="width:auto">Group ID</th>
                                            <th style="width:auto">Weekly Amt</th>
                                            <th style="width:auto">Subsidy</th> 
                                            <th style="width:auto">Last Payment</th>
                                            <th style="width:auto">Amount Paid</th>
                                            <th style="width:auto">Balance</th>
                                        </tr>
                                    </thead>
                                            
                        <?php foreach($result as $row ) { $i++;
                            if($row[6] > 0) { ?>
                                                <!-- Need to show $row[5] red here -->          
                                        <tbody> 
                                            <?php   echo '<tr style="'.getbgc($i). '">' ?>
                                                <td style="width:auto"><?php echo $row[0] ?></td>
                                                <td style="width:auto"><?php echo $row[1] ?></td>
                                                <td style="width:auto"><?php echo $row[7] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
                                                <td style="width:auto"><?php echo $row[3] ?></td>
                                                <td style="width:auto"><?php echo $row[4] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
                                                <td style="width:auto;background-color:red"><?php echo '$'.number_format($row[6],2) ?></td>                                 
                                            </tr>
                                        </tbody>    
                                    </table>
                                </div>
                             </div>                     
                                        
                                <?php } else { ?>
                                
                                        <tbody> 
                                            <?php   echo '<tr style="'.getbgc($i). '">' ?>                  
                                                <td style="width:auto"><?php echo $row[0] ?></td>
                                                <td style="width:auto"><?php echo $row[1] ?></td>
                                                <td style="width:auto"><?php echo $row[7] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
                                                <td style="width:auto"><?php echo $row[3] ?></td>
                                                <td style="width:auto"><?php echo $row[4] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[6],2) ?></td>
                                            </tr>
                                        </tbody>    
                                    </table>
                                </div>
                             </div> 
                        
                            <?php   }
                            }
                            $_SESSION['bal1'] = $row[6] + $row[2]; /* bal1 is set to be used with $newbal on line 318. This is how the 
                                                                                    overall balance is maintained. */
                            $_SESSION['btnhs'] = 0; // Set this when Fetch has been clicked. Carried over to 'postpayment' click.
                    } catch (PDOException $ex) {
                            echo '<script type="text/javascript">alert("There was an unforeseen database error."+"\\n"+"The database administrator has been contacted."+"\\n"+"\\n"+"Please try again later. Thank you"); </script>';
                            mail_error($ex);    
                    }   
                }
                        
                } elseif($_POST['postpayment'])  { 
                    
                    if($_POST['view'] == '') { // Nothing was selected
                        failed_fetch(); 
                    } 
                    if($_SESSION['btnhs'] == 3) { /* At login, this var is set to 3. If it is still set to 3 at this point, it
                                                                means the user made a name selection but did not click FETCH. */
                        failed_fetch();
                    }
                    if($_SESSION['btnhs'] == 0) { // Set to 1 here so the user can use the Post button event
                        $_SESSION['btnhs'] = 1;   // Increase to 1 to eliminate double-clicking Post on one Fetch
                    } elseif($_SESSION['btnhs'] = 1) { // If var == 1 then exit coz the user is double-clicking Post on just one Fetch
                        failed_fetch();
                    }
                    
                    if (empty($_POST["payment"])) {
                            $payment = "0.0";
                    } else {
                        $payment = test_input($_POST["payment"]);
                        if (!preg_match("/^[0-9.]*$/",$payment)) {
                      $paymentErr = "*  Numerals and decimal point only";
                        }
                    } 
                    
                    if(empty($paymentErr)) {                    
                        $newbal = $_SESSION['bal1'] - $payment; // Refer to line 299
                        $id = $_SESSION['id'];
                    try {
                        $stmt = $db->prepare('SELECT * FROM history WHERE attendeeid = :id ORDER BY historyid DESC LIMIT 1');
                        $stmt->bindParam(':id', $id, PDO::PARAM_INT);
                        $stmt->execute();
                        //$row_count = $stmt->rowCount();
                        $result = $stmt->fetchAll();
                        foreach($result as $row) {
                            $amount = $row[1];          
                            $subsidy = $row[2];
                            $last_pymt = $row[3];
                            $groupid = $row[7];
                            $attid = $row[9];
                            $memid = $row[10];
                        }
                        
                        $id = $_SESSION['id'];
 
                        if($payment > 0) { // Obviously the attendee was present (we hope)
                            $attend = "Y";  // Set the attend flag to reflect they attended the meeting
                            
                            /* Since $payment is greater than 0, the attendee made a payment and in attendance
                                for the meeting. Therefore, last_payment and attendance are set to CURDATE(). */                            
                            $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance, 
                                                                attend, attend_date, groupid, attendeeid, memberid)
                                                            VALUES(:amt, :sub, CURDATE(), :amt_paid, :newbal, :attend, CURDATE(), 
                                                                :groupid, :attid, :memid)');
                            $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
                            $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);     
                            $stmt->bindParam(':amt_paid', $payment, PDO::PARAM_STR);
                            $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR); // Refer to line 333
                            $stmt->bindParam(':attend', $attend, PDO::PARAM_STR);
                            $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
                            $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
                            $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
                            $stmt->execute();
                        } else {
                            $attend = "Y";  // Set the attend flag to reflect they attended the meeting
                            
                            /* Since $payment equals 0, the attendee didn't make a payment but was present
                                for the meeting. Therefore, last_payment will reflect the last_payment made and 
                                attendance is set to CURDATE(). */      
                            $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance, 
                                                                attend, attend_date, groupid, attendeeid, memberid)
                                                            VALUES(:amt, :sub, :last, :amt_paid, :newbal, :attend, CURDATE(), 
                                                                :groupid, :attid, :memid)');
                            $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
                            $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);
                            $stmt->bindParam(':last', $last_pymt, PDO::PARAM_STR);
                            $stmt->bindParam(':amt_paid', $payment, PDO::PARAM_STR);
                            $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR); // Refer to line 333
                            $stmt->bindParam(':attend', $attend, PDO::PARAM_STR);
                            $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
                            $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
                            $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
                            $stmt->execute();
                        }
                        
                        $stmt = $db->prepare('UPDATE balances SET balance = :newbal WHERE attendeeid = :id');
                        $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR);
                        $stmt->bindParam(':id', $id, PDO::PARAM_STR);
                        $stmt->execute();
                        
                        // Delete the attendee from the flush Table
                        $stmt = $db->prepare('DELETE FROM flush WHERE attendeeid = :attid');
                        $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
                        $stmt->execute();
                        
                        $stmt = $db->prepare('SELECT  fname, lname, amount, subsidy, last_payment, amount_paid, balance, a.groupid, a.attendeeid, h.historyid
                                                    FROM history AS h 
                                                    INNER JOIN attendees AS a ON a.attendeeid = h.attendeeid
                                                    where h.attendeeid = :id
                                                    ORDER BY h.historyid DESC LIMIT 1');
                        $stmt->bindValue(':id', $id, PDO::PARAM_INT);
                        $stmt->execute();
                        $result = $stmt->fetchAll();    ?>
                                                
                        <div class="row">   
                            <div class="table-repsonsive">
                                <table class="table table-bordered table hover" style="margin-top:30px">
                                    <caption style = 'color: red; font-size: 1.2em; font-weight: bold;'>*** ACCOUNT UPDATED ***</caption>
                                        <thead>
                                            <tr>
                                                <th style="width:auto">F-Name</th>
                                                <th style="width:auto">L-Name</th>
                                                <th style="width:auto">Group ID</th>
                                                <th style="width:auto">Weekly Amt</th>
                                                <th style="width:auto">Subsidy</th> 
                                                <th style="width:auto">Last Payment</th>
                                                <th style="width:auto">Amount Paid</th>
                                                <th style="width:auto">Balance</th>
                                            </tr>
                                        </thead>    
                                                            
                        <?php   foreach($result as $row ) { $i++;
                            if($row[6] > 0) { ?>    
                                                
                                        <tbody> 
                                            <?php   echo '<tr style="'.getbgc($i). '">' ?>
                                                <td style="width:auto"><?php echo $row[0] ?></td>
                                                <td style="width:auto"><?php echo $row[1] ?></td>
                                                <td style="width:auto"><?php echo $row[7] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
                                                <td style="width:auto"><?php echo $row[3] ?></td>
                                                <td style="width:auto"><?php echo $row[4] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
                                                <td style="width:auto;background-color: red"><?php echo '$'.number_format($row[6],2) ?></td>                                    
                                            </tr>
                                        </tbody>    
                                    </table>
                                </div>
                             </div>                                         
                                <?php } else { ?>                               
                                        <tbody> 
                                            <?php   echo '<tr style="'.getbgc($i). '">' ?>                      
                                                <td style="width:auto"><?php echo $row[0] ?></td>
                                                <td style="width:auto"><?php echo $row[1] ?></td>
                                                <td style="width:auto"><?php echo $row[7] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
                                                <td style="width:auto"><?php echo $row[3] ?></td>
                                                <td style="width:auto"><?php echo $row[4] ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
                                                <td style="width:auto"><?php echo '$'.number_format($row[6],2) ?></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                             </div>                         
                            <?php   }
                            }
                        }catch (PDOException $ex){
                            echo '<script type="text/javascript">alert("There was an unforeseen database error."+"\\n"+"The database administrator has been contacted."+"\\n"+"\\n"+"Please try again later. Thank you"); </script>';
                            mail_error($ex);                
                        }
                    }
                }   
                if($_POST['flush']) {
                    try {
                        $stmt = $db->prepare('SELECT attendeeid, memberid 
                                                    FROM flush
                                                    WHERE memberid = :memberid');   
                        $stmt->bindValue(':memberid', $_SESSION['memberid'], PDO::PARAM_INT);
                        $stmt->execute();   
                        $result = $stmt->fetchAll();
                        foreach($result as $row) {
                            $one = $row[0];
                            $stmt = $db->prepare('SELECT amount, subsidy, last_payment, amount_paid, balance, 
                                                                attend_date, groupid, attendeeid, memberid
                                                        FROM history 
                                                        WHERE attendeeid = :attendeeid
                                                        ORDER BY historyid DESC LIMIT 1
                                                        ');                                                     
                            $stmt->bindValue(':attendeeid', $one, PDO::PARAM_INT);
                            $stmt->execute();
                            $result = $stmt->fetchAll();
                            foreach($result as $row) { 
                                $amount = $row[0];          
                                $subsidy = $row[1];
                                $last_pymt = $row[2];
                                $amtpaid = $row[3];
                                $balance = $row[0] + $row[4];
                                $groupid = $row[6];                         
                                $attid = $row[7];
                                $memid = $row[8];   
                                    $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance, 
                                                                    attend_date, groupid, attendeeid, memberid)
                                                                VALUES(:amt, :sub, :lastpayment, :amt_paid, :bal, CURDATE(), :groupid,
                                                                    :attid, :memid)');
                                    $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
                                    $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);     
                                    $stmt->bindParam(':lastpayment', $last_pymt, PDO::PARAM_STR);
                                    $stmt->bindParam(':amt_paid', $amtpaid, PDO::PARAM_STR);
                                    $stmt->bindParam(':bal', $balance, PDO::PARAM_STR);
                                    $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
                                    $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
                                    $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
                                    $stmt->execute();                           
                                }                       
                            }
                        // Delete the attendees from flush Table via the memberid as the history Table is now updated for attendees
                        // who were not present
                        $stmt = $db->prepare('DELETE FROM flush where memberid = :memberid');
                        $stmt->bindParam(':memberid', $memid, PDO::PARAM_STR);
                        $stmt->execute();
                        $_SESSION['flush'] = 0;
                        
                    } catch (PDOException $ex) {
                            echo '<script type="text/javascript">alert("There was an unforeseen database error while flushing."+"\\n"+"The database administrator has been contacted."+"\\n"+"\\n"+"Please try again later. Thank you"); </script>';
                            mail_error($ex);    
                        }                               
                    }
}// Last Brace
 
function failed_fetch() {
    echo '<script type="text/javascript">alert("You must first Fetch before you can Post"); </script>';
    exit;   
}
 
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}       
        
function getbgc($trcount) { // Nice way to alternate table row colors
    $blue="background-color: #191970;"; // Midnight Blue
    $black="background-color: #000;";
    $odd= $trcount % 2;
        if($odd == 1){ return $blue; }
        else{ return $black; }      
} 
 
function mail_error($ex) {
    $from = "[email protected]"; // this is the sender's Email address
    $to = "[email protected]";
    $subject = "ERROR!";
    $message = "An ERROR occured in wspostpayments.php: ".$ex."\n\nwith user: ".$_SESSION['uname']."\n\n"."Upon resolution, email them.";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    header("Location: error.html"); 
} ?>
            </form>
        </div>
    </body>
</html>

Comments