fmc1962

Button Disabling

Nov 22nd, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 30.88 KB | None | 0 0
  1. <?php
  2.     session_start(['cookie_lifetime' => 2400,
  3.                         'use_only_cookies' => true,
  4.     ]);
  5.    
  6.     require_once '../root_login.php';
  7.    
  8.     // The following makes sure the pages load using HTTPS 
  9.     /*if ($_SERVER['HTTPS'] != "on") {
  10.     $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  11.     header("Location: $url");
  12.     exit;
  13.    } */
  14.  
  15.     if ($_SESSION["memberid"] == "") {
  16.     header("Location: wslogin.php");
  17.     exit();
  18.     }
  19.    
  20.     //$_SESSION['id'] = $_POST['view'];
  21.     //$_SESSION['groupid'] = $_POST['groupid'];
  22. ?>
  23.  
  24. <!doctype html>
  25. <html class="no-js" lang="en">
  26.     <head>
  27.         <meta charset="utf-8">
  28.         <meta http-equiv="x-ua-compatible" content="ie=edge">
  29.         <title></title>
  30.         <meta name="description" content="">
  31.         <meta name="viewport" content="width=device-width, initial-scale=1">
  32.        
  33.         <link rel="apple-touch-icon" href="apple-touch-icon.png">
  34.         <!-- Place favicon.ico in the root directory -->
  35.        
  36.         <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
  37.         <script>
  38.             window.jQuery || document.write('<script src="js/jquery-2.0.0.min.js"><\/script>')
  39.         </script>
  40.         <script src="js/plugins.js"></script>
  41.         <script src="js/main.js"></script>
  42.        
  43.         <!-- Latest compiled and minified CSS -->
  44.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  45.        
  46.         <!-- Optional theme -->
  47.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
  48.        
  49.         <!-- Latest compiled and minified JavaScript -->
  50.         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  51.        
  52.         <link rel="stylesheet" href="css/normalize.css">
  53.         <link rel="stylesheet" href="css/main.css">
  54.         <script src="js/vendor/modernizr-2.8.3.min.js"></script>
  55.        
  56.         <script src='https://www.google.com/recaptcha/api.js'></script>
  57.        
  58.         <!--[if lt IE 8]>
  59.         <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>
  60.         <![endif]-->
  61.        
  62.         <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  63.         <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  64.         <!--[if lt IE 9]>
  65.         <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  66.         <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  67.         <![endif]-->
  68.        
  69.         <style type="text/css">
  70.             td {
  71.                 color: #fff;
  72.                 text-transform: uppercase;                 
  73.                 width: auto;
  74.              }
  75.             th {
  76.                 color: #000;
  77.                 background-color: #F5FFFA;
  78.                 text-transform: uppercase;                 
  79.                 width: auto;
  80.              }
  81.              
  82.         </style>
  83.         <script type="text/javascript">
  84.             function flushOn() {
  85.                 document.getElementById("flushBtn").setAttribute('disabled',false);
  86.             }
  87.             function flushOff() {
  88.                 document.getElementById("flushBtn").setAttribute('disabled',true);
  89.             }
  90.         </script>
  91.    
  92.     </head>
  93.         <body>
  94.         <!--[if lt IE 8]>
  95.         <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>
  96.         <![endif]-->
  97.         <div class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
  98.         <div class="container">
  99.                 <div class="navbar-header">
  100.                     <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
  101.                         <span class="sr-only">Toggle navigation</span>
  102.                         <span class="icon-bar"></span>
  103.                         <span class="icon-bar"></span>
  104.                         <span class="icon-bar"></span>
  105.                     </button>
  106.                     <a class="navbar-brand" style="font-weight: bold"><?php echo $_SESSION['uname']; ?>'s Work Station</a>
  107.                 </div>
  108.                 <div id="navbarCollapse" class="collapse navbar-collapse">
  109.                     <ul class="nav navbar-nav">
  110.                         <li class="dropdown">
  111.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Attendee<strong class="caret"></strong></a>
  112.                                 <ul class="dropdown-menu">
  113.                                     <li><a href="wsaddattendees.php">Add</a></li>                                      
  114.                                     <li><a href="wsdeleteattendees.php">Delete</a></li>
  115.                                     <li><a href="wseditattendees.php">Edit</a></li>
  116.                                 </ul>
  117.                         </li>  
  118.                         <li class="dropdown">
  119.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Payment<strong class="caret"></strong></a>
  120.                                 <ul class="dropdown-menu">
  121.                                     <li><a href="wsadjustpayments.php">Rollback</a></li>
  122.                                     <li><a href="wseditpayments.php">Edit Payment / Subsidy</a></li>
  123.                                     <li><a href="wspostpayments.php">Post</a></li> 
  124.                                     <li><a href="wssuspendpayments.php">Suspend</a></li>                               
  125.                                 </ul>              
  126.                         </li>  
  127.                         <li class="dropdown">
  128.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">View<strong class="caret"></strong></a>
  129.                                 <ul class="dropdown-menu">
  130.                                     <li><a href="wsviewattendance.php">Attendance</a></li>
  131.                                     <li><a href="wsviewattendees.php">Attendees</a></li>
  132.                                     <li><a href="wsviewattendeesbygroup.php">Attendees by Group</a></li>
  133.                                     <li><a href="wsviewattendeesbypo.php">Attendees by P.O.</a></li>
  134.                                     <li><a href="wsviewpayments.php">Payments</a></li>
  135.                                     <li><a href="wsviewsuspendedpayments.php">Suspended Payments</a></li>
  136.                                     <li><a href="wsviewfiscalquarters.php">Fiscal Quarters</a></li>
  137.                                 </ul>                  
  138.                         </li>      
  139.                         <li class="dropdown">
  140.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Assignments<strong class="caret"></strong></a>                    
  141.                                 <ul class="dropdown-menu">
  142.                                 <li><a href="#">Completed</a></li>
  143.                                 <li><a href="#">Current</a></li>
  144.                                 </ul>                                          
  145.                         </li>
  146.                         <li class="dropdown">
  147.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Upcoming<strong class="caret"></strong></a>                   
  148.                                 <ul class="dropdown-menu">
  149.                                 <li><a href="#">Polygraphs</a></li>
  150.                                 <li><a href="#">Evaluations</a></li>
  151.                                 <li><a href="#">Other</a></li>
  152.                                 </ul>                                          
  153.                         </li>
  154.                         <li>
  155.                             <a href="#">DRA</a>
  156.                         </li>  
  157.                         <li>
  158.                             <a href="wshelp.php">Help</a>
  159.                         </li>
  160.                         <!--<li class="dropdown">
  161.                             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Help<strong class="caret"></strong></a>                   
  162.                                 <ul class="dropdown-menu">
  163.                                     <li><a href="#">Attendees</a></li>
  164.                                 <li><a href="#">Payments</a></li>
  165.                                 </ul>                                          
  166.                         </li>   -->        
  167.                     </ul>
  168.                     <ul class="nav navbar-nav navbar-right">
  169.                         <li>
  170.                             <a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a>
  171.                         </li>
  172.                     </ul>
  173.                 </div>
  174.             </div>
  175.         </div>
  176.         <div class="container">
  177.             <div class="row" style="margin-top:51px">
  178.                 <div class="panel panel-default">
  179.                     <div class="panel-heading">
  180.                         <h2>Post Attendee Payments</h2>
  181.                     </div>
  182.                 </div>
  183.             </div>
  184.             <form method="post" class="subform" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
  185.                 <div class="row" style="background: skyblue; margin-top:-23px">
  186.                     <div class="col-sm-2">
  187.                         <div class="input-group">
  188.                             <select class="form-control" name="groupid" onchange="this.form.submit();">
  189.                                 <option name="0"<?php echo ($_POST['groupid'] == '0') ? ' selected="selected"' : ''; ?> value="0" >GROUP</option>
  190.                                 <option name="1"<?php echo ($_POST['groupid'] == '1') ? ' selected="selected"' : ''; ?> value="1" >1</option>
  191.                                 <option name="2"<?php echo ($_POST['groupid'] == '2') ? ' selected="selected"' : ''; ?> value="2" >2</option>
  192.                                 <option name="3"<?php echo ($_POST['groupid'] == '3') ? ' selected="selected"' : ''; ?> value="3" >3</option>
  193.                                 <option name="4"<?php echo ($_POST['groupid'] == '4') ? ' selected="selected"' : ''; ?> value="4" >4</option>
  194.                                 <option name="5"<?php echo ($_POST['groupid'] == '5') ? ' selected="selected"' : ''; ?> value="5" >5</option>
  195.                                 <option name="6"<?php echo ($_POST['groupid'] == '6') ? ' selected="selected"' : ''; ?> value="6" >6</option>
  196.                                 <option name="7"<?php echo ($_POST['groupid'] == '7') ? ' selected="selected"' : ''; ?> value="7" >7</option>
  197.                                 <option name="8"<?php echo ($_POST['groupid'] == '8') ? ' selected="selected"' : ''; ?> value="8" >8</option>
  198.                                 <option name="9"<?php echo ($_POST['groupid'] == '9') ? ' selected="selected"' : ''; ?> value="9" >9</option>    
  199.                                 <option name="10"<?php echo ($_POST['groupid'] == '10') ? ' selected="selected"' : ''; ?> value="10" >10</option>
  200.                                 <option name="11"<?php echo ($_POST['groupid'] == '11') ? ' selected="selected"' : ''; ?> value="11" >11</option>
  201.                                 <option name="12"<?php echo ($_POST['groupid'] == '12') ? ' selected="selected"' : ''; ?> value="12" >12</option>
  202.                                 <option name="13"<?php echo ($_POST['groupid'] == '13') ? ' selected="selected"' : ''; ?> value="13" >13</option>
  203.                                 <option name="14"<?php echo ($_POST['groupid'] == '14') ? ' selected="selected"' : ''; ?> value="14" >14</option>
  204.                                 <option name="15"<?php echo ($_POST['groupid'] == '15') ? ' selected="selected"' : ''; ?> value="15" >15</option>
  205.                                 <option name="16"<?php echo ($_POST['groupid'] == '16') ? ' selected="selected"' : ''; ?> value="16" >16</option>
  206.                                 <option name="17"<?php echo ($_POST['groupid'] == '17') ? ' selected="selected"' : ''; ?> value="17" >17</option>
  207.                                 <option name="18"<?php echo ($_POST['groupid'] == '18') ? ' selected="selected"' : ''; ?> value="18" >18</option>
  208.                                 <option name="19"<?php echo ($_POST['groupid'] == '19') ? ' selected="selected"' : ''; ?> value="19" >19</option>
  209.                                 <option name="20"<?php echo ($_POST['groupid'] == '20') ? ' selected="selected"' : ''; ?> value="20" >20</option>
  210.                                 <option name="21"<?php echo ($_POST['groupid'] == '21') ? ' selected="selected"' : ''; ?> value="21" >21</option>
  211.                                 <option name="22"<?php echo ($_POST['groupid'] == '22') ? ' selected="selected"' : ''; ?> value="22" >22</option>
  212.                                 <option name="23"<?php echo ($_POST['groupid'] == '23') ? ' selected="selected"' : ''; ?> value="23" >23</option>
  213.                                 <option name="24"<?php echo ($_POST['groupid'] == '24') ? ' selected="selected"' : ''; ?> value="24" >24</option>
  214.                                 <option name="25"<?php echo ($_POST['groupid'] == '25') ? ' selected="selected"' : ''; ?> value="25" >25</option>
  215.                                 <option name="26"<?php echo ($_POST['groupid'] == '26') ? ' selected="selected"' : ''; ?> value="26" >26</option>
  216.                                 <option name="27"<?php echo ($_POST['groupid'] == '27') ? ' selected="selected"' : ''; ?> value="27" >27</option>
  217.                                 <option name="28"<?php echo ($_POST['groupid'] == '28') ? ' selected="selected"' : ''; ?> value="28" >28</option>
  218.                                 <option name="29"<?php echo ($_POST['groupid'] == '29') ? ' selected="selected"' : ''; ?> value="29" >29</option>
  219.                                 <option name="30"<?php echo ($_POST['groupid'] == '30') ? ' selected="selected"' : ''; ?> value="30" >30</option>                              
  220.                             </select>
  221.                     <span class="input-group-btn">
  222.                         <!--<input type="submit" name="load" class="btn btn-default" value="Load">-->                  
  223.                         <input type="submit" id="dumpBtn" name="dump" class="btn btn-danger" value="Dump">
  224.                     </span>
  225.                     </div>
  226.                 </div>
  227.                 <div class="col-sm-3">
  228.                     <div class="input-group">
  229.                         <select class="form-control" name="view" style="text-transform: uppercase">
  230.                             <option value="">Select</option>
  231.                                 <?php              
  232.                                 if ($_SERVER["REQUEST_METHOD"] == "POST") { // First brace 
  233.                                    
  234.                                     $payment = $paymentErr = "";                       
  235.                                     $_SESSION['groupid'] = $_POST['groupid'];
  236.                                     /* $memberid = $_SESSION["memberid"];  We use $memberid to load the Select options box (below) to make
  237.                                                                                 sure that that ONLY attendee information for THAT member is loaded */
  238.                                     $_SESSION['id'] = $_POST['view'];
  239.                                    
  240.                                     /* Set session vars for uname and pwd1 from invalidlogin.php to be able to login using login.php */
  241.                                     //$uname = $_SESSION['uname']; // Set $name for login.php
  242.                                     //$pwd1 = $_SESSION['pwd1'];  // Set $pwd1 for login.php
  243.                                     //require_once '../root_login.php'; // This file contains database access credentials                                      
  244.                                    
  245.                                     // Load the Select Box with names that match the groupid and memberid
  246.                                         $stmt = $db->prepare('SELECT a.attendeeid, fname, lname, a.groupid, a.memberid, s.attendeeid, suspend
  247.                                                                         FROM attendees AS a
  248.                                                                         JOIN suspended AS s ON a.attendeeid = s.attendeeid
  249.                                                                         WHERE a.memberid = :memberid
  250.                                                                         AND suspend = "N"
  251.                                                                         AND a.groupid = :groupid
  252.                                                                         ORDER BY lname');
  253.                                         $stmt->bindValue(':memberid', $_SESSION["memberid"], PDO::PARAM_INT);
  254.                                         $stmt->bindValue(':groupid', $_SESSION['groupid'], PDO::PARAM_INT);
  255.                                         $stmt->execute();
  256.                                         $result = $stmt->fetchAll();
  257.                                         foreach($result as $row){
  258.                                            
  259.                                             // Load the flush Table with the IDs from the selected group
  260.                                             if($_SESSION['flush'] == 0) {
  261.                                                 $stmt = $db->prepare('INSERT INTO flush (attendeeid, memberid)
  262.                                                                                 VALUES(:attendeeid, :memberid)');
  263.                                                 $stmt->bindValue(':attendeeid', $row[0], PDO::PARAM_INT);
  264.                                                 $stmt->bindValue(':memberid', $row[4], PDO::PARAM_INT);
  265.                                                 $stmt->execute();
  266.                                             }
  267.                                             echo "<option value='$row[0]'"; // Holds selected name from click to click without resetting to Select
  268.                                           if(isset($_SESSION['id']) and $_SESSION['id'] == $row[0]) {
  269.                                              echo ' selected="selected"';
  270.                                           }
  271.                                           echo ">$row[2], $row[1]</option>";
  272.                                         }?>
  273.                             </select>
  274.                         <?php $_SESSION['flush'] = 1; ?>
  275.                             <span class="input-group-btn">
  276.                         <input type="submit" id="fetchBtn" name="fetch" class="btn btn-default" value="Fetch"  onclick="flushOff()">
  277.                     </span>
  278.                         </div>
  279.                     </div>
  280.                     <div class="col-sm-offset-6">
  281.                         <div class="input-group">
  282.                             <span class="input-group-btn">
  283.                         <input type="submit" id="flushBtn" name="flush" class="btn btn-danger" value="Flush">
  284.                     </span>
  285.                         </div>
  286.                     </div>
  287.                 </div>
  288.                 <?php if(($_POST['dump']) || ($_POST['flush'])) { ?>
  289.                 <div class="row" style="margin-top:20px">
  290.                     <div class="col-sm-3">
  291.                         <label style="text-transform: uppercase; color: red" class="control-label">Dumped Group <?php echo $_SESSION['groupid']; ?></label>            
  292.                     </div>
  293.                 </div>
  294.                 <?php } else{ ?>
  295.                 <div class="row" style="margin-top:20px">
  296.                     <div class="col-sm-3">
  297.                         <label style="text-transform: uppercase; color: red" class="control-label">Group <?php echo $_SESSION['groupid']; ?> Loaded</label>            
  298.                     </div>
  299.                 </div>
  300.                 <?php } ?>
  301.                 <div class="row" style="margin-top:20px">
  302.                     <div class="col-sm-3">
  303.                         <label style="text-transform: uppercase" class="control-label">Payment:</label>            
  304.                     </div>
  305.                 </div>
  306.                 <div class="row">
  307.                     <div class="col-sm-3">
  308.                         <div class="input-group">
  309.                             <span class="input-group-addon">$</span>
  310.                             <input class="form-control" type="text" name="payment" placeholder="0.00"
  311.                                 value="<?php if (isset($_POST['payment'])) { echo $payment; } ?>">
  312.                             <span class="input-group-btn">
  313.                           <input type="submit" name="postpayment" class="btn btn-primary" value="Post">
  314.                        </span>
  315.                                 <span class="error"><?php echo $paymentErr;?></span>
  316.                         </div>
  317.                     </div>
  318.                 </div>
  319.                 <?php                  
  320.                 if($_POST['dump']) {
  321.                     $stmt = $db->prepare('DELETE FROM flush WHERE memberid = :memberid');
  322.                     $stmt->bindValue(':memberid', $_SESSION['memberid'], PDO::PARAM_INT);
  323.                     $stmt->execute();  
  324.                     $_SESSION['flush'] = 0;
  325.                     echo '<script type="text/javascript">alert("Please select a new Group"); </script>';
  326.                 }
  327.                 if($_POST['fetch']) {
  328.                     $id = $_POST['view']; // Pass this to see which attendee was selected in the Selection box options
  329.                     $_SESSION['id'] = $_POST['view'];
  330.                     $i = 0; // Set to use below in alternating bg-colors with function getbgc($i)
  331.                     if($id == '') { exit(); // Nothing was selected
  332.                        
  333.                 } else {
  334.                     try {
  335.                         $stmt = $db->prepare('SELECT fname, lname, amount, subsidy, last_payment, amount_paid, balance, a.groupid, a.attendeeid, h.historyid
  336.                                                         FROM history AS h
  337.                                                         INNER JOIN attendees AS a ON a.attendeeid = h.attendeeid
  338.                                                         where h.attendeeid = :id
  339.                                                         ORDER BY h.historyid DESC LIMIT 1');
  340.                         $stmt->bindValue(':id', $_SESSION['id'], PDO::PARAM_INT);
  341.                         $stmt->execute();
  342.                         $result = $stmt->fetchAll(); ?>
  343.                        
  344.                         <div class="row">
  345.                             <div class="table-repsonsive">
  346.                                 <table class="table" style="margin-top:30px">
  347.                                     <thead>
  348.                                         <tr>
  349.                                             <th style="width:auto">F-Name</th>
  350.                                             <th style="width:auto">L-Name</th>
  351.                                             <th style="width:auto">Group ID</th>
  352.                                             <th style="width:auto">Weekly Amt</th>
  353.                                             <th style="width:auto">Subsidy</th>
  354.                                             <th style="width:auto">Last Payment</th>
  355.                                             <th style="width:auto">Amount Paid</th>
  356.                                             <th style="width:auto">Balance</th>
  357.                                         </tr>
  358.                                     </thead>
  359.                                            
  360.                         <?php foreach($result as $row ) { $i++;
  361.                             if($row[6] > 0) { ?>
  362.                                                 <!-- Need to show $row[5] red here -->         
  363.                                         <tbody>
  364.                                             <?php   echo '<tr style="'.getbgc($i). '">' ?>
  365.                                                 <td style="width:auto"><?php echo $row[0] ?></td>
  366.                                                 <td style="width:auto"><?php echo $row[1] ?></td>
  367.                                                 <td style="width:auto"><?php echo $row[7] ?></td>
  368.                                                 <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
  369.                                                 <td style="width:auto"><?php echo $row[3] ?></td>
  370.                                                 <td style="width:auto"><?php echo $row[4] ?></td>
  371.                                                 <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
  372.                                                 <td style="width:auto;background-color:red"><?php echo '$'.number_format($row[6],2) ?></td>                                
  373.                                             </tr>
  374.                                         </tbody>   
  375.                                     </table>
  376.                                 </div>
  377.                              </div>                    
  378.                                        
  379.                                 <?php } else { ?>
  380.                                
  381.                                         <tbody>
  382.                                             <?php   echo '<tr style="'.getbgc($i). '">' ?>                 
  383.                                                 <td style="width:auto"><?php echo $row[0] ?></td>
  384.                                                 <td style="width:auto"><?php echo $row[1] ?></td>
  385.                                                 <td style="width:auto"><?php echo $row[7] ?></td>
  386.                                                 <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
  387.                                                 <td style="width:auto"><?php echo $row[3] ?></td>
  388.                                                 <td style="width:auto"><?php echo $row[4] ?></td>
  389.                                                 <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
  390.                                                 <td style="width:auto"><?php echo '$'.number_format($row[6],2) ?></td>
  391.                                             </tr>
  392.                                         </tbody>   
  393.                                     </table>
  394.                                 </div>
  395.                              </div>
  396.                        
  397.                             <?php   }
  398.                             }
  399.                             $_SESSION['bal1'] = $row[6] + $row[2]; /* bal1 is set to be used with $newbal on line 318. This is how the
  400.                                                                                     overall balance is maintained. */
  401.                             $_SESSION['btnhs'] = 0; // Set this when Fetch has been clicked. Carried over to 'postpayment' click.
  402.                     } catch (PDOException $ex) {
  403.                             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>';
  404.                             mail_error($ex);   
  405.                     }  
  406.                 }
  407.                        
  408.                 } elseif($_POST['postpayment'])  {
  409.                    
  410.                     if($_POST['view'] == '') { // Nothing was selected
  411.                         failed_fetch();
  412.                     }
  413.                     if($_SESSION['btnhs'] == 3) { /* At login, this var is set to 3. If it is still set to 3 at this point, it
  414.                                                                 means the user made a name selection but did not click FETCH. */
  415.                         failed_fetch();
  416.                     }
  417.                     if($_SESSION['btnhs'] == 0) { // Set to 1 here so the user can use the Post button event
  418.                         $_SESSION['btnhs'] = 1;   // Increase to 1 to eliminate double-clicking Post on one Fetch
  419.                     } elseif($_SESSION['btnhs'] = 1) { // If var == 1 then exit coz the user is double-clicking Post on just one Fetch
  420.                         failed_fetch();
  421.                     }
  422.                    
  423.                     if (empty($_POST["payment"])) {
  424.                             $payment = "0.0";
  425.                     } else {
  426.                         $payment = test_input($_POST["payment"]);
  427.                         if (!preg_match("/^[0-9.]*$/",$payment)) {
  428.                       $paymentErr = "*  Numerals and decimal point only";
  429.                         }
  430.                     }
  431.                    
  432.                     if(empty($paymentErr)) {                   
  433.                         $newbal = $_SESSION['bal1'] - $payment; // Refer to line 299
  434.                         $id = $_SESSION['id'];
  435.                     try {
  436.                         $stmt = $db->prepare('SELECT * FROM history WHERE attendeeid = :id ORDER BY historyid DESC LIMIT 1');
  437.                         $stmt->bindParam(':id', $id, PDO::PARAM_INT);
  438.                         $stmt->execute();
  439.                         //$row_count = $stmt->rowCount();
  440.                         $result = $stmt->fetchAll();
  441.                         foreach($result as $row) {
  442.                             $amount = $row[1];         
  443.                             $subsidy = $row[2];
  444.                             $last_pymt = $row[3];
  445.                             $groupid = $row[7];
  446.                             $attid = $row[9];
  447.                             $memid = $row[10];
  448.                         }
  449.                        
  450.                         $id = $_SESSION['id'];
  451.  
  452.                         if($payment > 0) { // Obviously the attendee was present (we hope)
  453.                             $attend = "Y";  // Set the attend flag to reflect they attended the meeting
  454.                            
  455.                             /* Since $payment is greater than 0, the attendee made a payment and in attendance
  456.                                 for the meeting. Therefore, last_payment and attendance are set to CURDATE(). */                           
  457.                             $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance,
  458.                                                                 attend, attend_date, groupid, attendeeid, memberid)
  459.                                                             VALUES(:amt, :sub, CURDATE(), :amt_paid, :newbal, :attend, CURDATE(),
  460.                                                                 :groupid, :attid, :memid)');
  461.                             $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
  462.                             $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);    
  463.                             $stmt->bindParam(':amt_paid', $payment, PDO::PARAM_STR);
  464.                             $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR); // Refer to line 333
  465.                             $stmt->bindParam(':attend', $attend, PDO::PARAM_STR);
  466.                             $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
  467.                             $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
  468.                             $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
  469.                             $stmt->execute();
  470.                         } else {
  471.                             $attend = "Y";  // Set the attend flag to reflect they attended the meeting
  472.                            
  473.                             /* Since $payment equals 0, the attendee didn't make a payment but was present
  474.                                 for the meeting. Therefore, last_payment will reflect the last_payment made and
  475.                                 attendance is set to CURDATE(). */     
  476.                             $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance,
  477.                                                                 attend, attend_date, groupid, attendeeid, memberid)
  478.                                                             VALUES(:amt, :sub, :last, :amt_paid, :newbal, :attend, CURDATE(),
  479.                                                                 :groupid, :attid, :memid)');
  480.                             $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
  481.                             $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);
  482.                             $stmt->bindParam(':last', $last_pymt, PDO::PARAM_STR);
  483.                             $stmt->bindParam(':amt_paid', $payment, PDO::PARAM_STR);
  484.                             $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR); // Refer to line 333
  485.                             $stmt->bindParam(':attend', $attend, PDO::PARAM_STR);
  486.                             $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
  487.                             $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
  488.                             $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
  489.                             $stmt->execute();
  490.                         }
  491.                        
  492.                         $stmt = $db->prepare('UPDATE balances SET balance = :newbal WHERE attendeeid = :id');
  493.                         $stmt->bindParam(':newbal', $newbal, PDO::PARAM_STR);
  494.                         $stmt->bindParam(':id', $id, PDO::PARAM_STR);
  495.                         $stmt->execute();
  496.                        
  497.                         // Delete the attendee from the flush Table
  498.                         $stmt = $db->prepare('DELETE FROM flush WHERE attendeeid = :attid');
  499.                         $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
  500.                         $stmt->execute();
  501.                        
  502.                         $stmt = $db->prepare('SELECT  fname, lname, amount, subsidy, last_payment, amount_paid, balance, a.groupid, a.attendeeid, h.historyid
  503.                                                     FROM history AS h
  504.                                                     INNER JOIN attendees AS a ON a.attendeeid = h.attendeeid
  505.                                                     where h.attendeeid = :id
  506.                                                     ORDER BY h.historyid DESC LIMIT 1');
  507.                         $stmt->bindValue(':id', $id, PDO::PARAM_INT);
  508.                         $stmt->execute();
  509.                         $result = $stmt->fetchAll();    ?>
  510.                                                
  511.                         <div class="row">  
  512.                             <div class="table-repsonsive">
  513.                                 <table class="table table-bordered table hover" style="margin-top:30px">
  514.                                     <caption style = 'color: red; font-size: 1.2em; font-weight: bold;'>*** ACCOUNT UPDATED ***</caption>
  515.                                         <thead>
  516.                                             <tr>
  517.                                                 <th style="width:auto">F-Name</th>
  518.                                                 <th style="width:auto">L-Name</th>
  519.                                                 <th style="width:auto">Group ID</th>
  520.                                                 <th style="width:auto">Weekly Amt</th>
  521.                                                 <th style="width:auto">Subsidy</th>
  522.                                                 <th style="width:auto">Last Payment</th>
  523.                                                 <th style="width:auto">Amount Paid</th>
  524.                                                 <th style="width:auto">Balance</th>
  525.                                             </tr>
  526.                                         </thead>   
  527.                                                            
  528.                         <?php   foreach($result as $row ) { $i++;
  529.                             if($row[6] > 0) { ?>   
  530.                                                
  531.                                         <tbody>
  532.                                             <?php   echo '<tr style="'.getbgc($i). '">' ?>
  533.                                                 <td style="width:auto"><?php echo $row[0] ?></td>
  534.                                                 <td style="width:auto"><?php echo $row[1] ?></td>
  535.                                                 <td style="width:auto"><?php echo $row[7] ?></td>
  536.                                                 <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
  537.                                                 <td style="width:auto"><?php echo $row[3] ?></td>
  538.                                                 <td style="width:auto"><?php echo $row[4] ?></td>
  539.                                                 <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
  540.                                                 <td style="width:auto;background-color: red"><?php echo '$'.number_format($row[6],2) ?></td>                                   
  541.                                             </tr>
  542.                                         </tbody>   
  543.                                     </table>
  544.                                 </div>
  545.                              </div>                                        
  546.                                 <?php } else { ?>                              
  547.                                         <tbody>
  548.                                             <?php   echo '<tr style="'.getbgc($i). '">' ?>                     
  549.                                                 <td style="width:auto"><?php echo $row[0] ?></td>
  550.                                                 <td style="width:auto"><?php echo $row[1] ?></td>
  551.                                                 <td style="width:auto"><?php echo $row[7] ?></td>
  552.                                                 <td style="width:auto"><?php echo '$'.number_format($row[2],2) ?></td>
  553.                                                 <td style="width:auto"><?php echo $row[3] ?></td>
  554.                                                 <td style="width:auto"><?php echo $row[4] ?></td>
  555.                                                 <td style="width:auto"><?php echo '$'.number_format($row[5],2) ?></td>
  556.                                                 <td style="width:auto"><?php echo '$'.number_format($row[6],2) ?></td>
  557.                                             </tr>
  558.                                         </tbody>
  559.                                     </table>
  560.                                 </div>
  561.                              </div>                        
  562.                             <?php   }
  563.                             }
  564.                         }catch (PDOException $ex){
  565.                             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>';
  566.                             mail_error($ex);               
  567.                         }
  568.                     }
  569.                 }  
  570.                 if($_POST['flush']) {
  571.                     try {
  572.                         $stmt = $db->prepare('SELECT attendeeid, memberid
  573.                                                     FROM flush
  574.                                                     WHERE memberid = :memberid');  
  575.                         $stmt->bindValue(':memberid', $_SESSION['memberid'], PDO::PARAM_INT);
  576.                         $stmt->execute();  
  577.                         $result = $stmt->fetchAll();
  578.                         foreach($result as $row) {
  579.                             $one = $row[0];
  580.                             $stmt = $db->prepare('SELECT amount, subsidy, last_payment, amount_paid, balance,
  581.                                                                 attend_date, groupid, attendeeid, memberid
  582.                                                         FROM history
  583.                                                         WHERE attendeeid = :attendeeid
  584.                                                         ORDER BY historyid DESC LIMIT 1
  585.                                                         ');                                                    
  586.                             $stmt->bindValue(':attendeeid', $one, PDO::PARAM_INT);
  587.                             $stmt->execute();
  588.                             $result = $stmt->fetchAll();
  589.                             foreach($result as $row) {
  590.                                 $amount = $row[0];         
  591.                                 $subsidy = $row[1];
  592.                                 $last_pymt = $row[2];
  593.                                 $amtpaid = $row[3];
  594.                                 $balance = $row[0] + $row[4];
  595.                                 $groupid = $row[6];                        
  596.                                 $attid = $row[7];
  597.                                 $memid = $row[8];  
  598.                                     $stmt = $db->prepare('INSERT INTO history(amount, subsidy, last_payment, amount_paid, balance,
  599.                                                                     attend_date, groupid, attendeeid, memberid)
  600.                                                                 VALUES(:amt, :sub, :lastpayment, :amt_paid, :bal, CURDATE(), :groupid,
  601.                                                                     :attid, :memid)');
  602.                                     $stmt->bindParam(':amt', $amount, PDO::PARAM_STR);
  603.                                     $stmt->bindParam(':sub', $subsidy, PDO::PARAM_STR);    
  604.                                     $stmt->bindParam(':lastpayment', $last_pymt, PDO::PARAM_STR);
  605.                                     $stmt->bindParam(':amt_paid', $amtpaid, PDO::PARAM_STR);
  606.                                     $stmt->bindParam(':bal', $balance, PDO::PARAM_STR);
  607.                                     $stmt->bindParam(':groupid', $groupid, PDO::PARAM_STR);
  608.                                     $stmt->bindParam(':attid', $attid, PDO::PARAM_STR);
  609.                                     $stmt->bindParam(':memid', $memid, PDO::PARAM_STR);
  610.                                     $stmt->execute();                          
  611.                                 }                      
  612.                             }
  613.                         // Delete the attendees from flush Table via the memberid as the history Table is now updated for attendees
  614.                         // who were not present
  615.                         $stmt = $db->prepare('DELETE FROM flush where memberid = :memberid');
  616.                         $stmt->bindParam(':memberid', $memid, PDO::PARAM_STR);
  617.                         $stmt->execute();
  618.                         $_SESSION['flush'] = 0;
  619.                        
  620.                     } catch (PDOException $ex) {
  621.                             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>';
  622.                             mail_error($ex);   
  623.                         }                              
  624.                     }
  625. }// Last Brace
  626.  
  627. function failed_fetch() {
  628.     echo '<script type="text/javascript">alert("You must first Fetch before you can Post"); </script>';
  629.     exit;  
  630. }
  631.  
  632. function test_input($data) {
  633.   $data = trim($data);
  634.   $data = stripslashes($data);
  635.   $data = htmlspecialchars($data);
  636.   return $data;
  637. }      
  638.        
  639. function getbgc($trcount) { // Nice way to alternate table row colors
  640.     $blue="background-color: #191970;"; // Midnight Blue
  641.     $black="background-color: #000;";
  642.     $odd= $trcount % 2;
  643.         if($odd == 1){ return $blue; }
  644.         else{ return $black; }     
  645. }
  646.  
  647. function mail_error($ex) {
  648.     $from = "[email protected]"; // this is the sender's Email address
  649.     $to = "[email protected]";
  650.     $subject = "ERROR!";
  651.     $message = "An ERROR occured in wspostpayments.php: ".$ex."\n\nwith user: ".$_SESSION['uname']."\n\n"."Upon resolution, email them.";
  652.     $headers = "From:" . $from;
  653.     mail($to,$subject,$message,$headers);
  654.     header("Location: error.html");
  655. } ?>
  656.             </form>
  657.         </div>
  658.     </body>
  659. </html>
Advertisement
Add Comment
Please, Sign In to add comment