HEX
Server: Apache
System: Linux www3.pit.tblive.com 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64
User: awaldron (1020)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //home/awaldron/_accomods/admin.accomods.com/codes.php
<?php
error_reporting(E_ALL);
include('_helpers.php');


// CONNECT TO DB
$db = connectDB();

if ($_POST['submitnew']) {
    $ins = "INSERT INTO school_codes (school_name, school_code, code_expires, code_active) VALUES (";
    $ins .= "'".$_POST['school_name']."', ";
    $ins .= "'".$_POST['school_code']."', ";
    $ins .= "'".$_POST['code_expires']."', ";
    $ins .= "'".$_POST['code_active']."'";
    $ins .= ")";
    //echo $ins;
    $insert = $db->query($ins);
    header('Location: /codes.php');
}

if ($_POST['submitedit']) {
	// UPDATE SCHOOL RECORD
	$upd1 = "UPDATE school_codes SET ";
	$upd1 .= "school_name='".$_POST['school_name']."', ";
	$upd1 .= "school_code='".$_POST['school_code']."', ";
	$upd1 .= "code_expires='".$_POST['code_expires']."', ";
	$upd1 .= "code_active='".$_POST['code_active']."' ";
	$upd1 .= "WHERE school_id=".$_POST['school_id'];
	
	// UPDATE USER RECORDS
	$upd2 = "UPDATE users SET 
				school_name='".$_POST['school_name']."', 
				school_code='".$_POST['school_code']."', 
				expires='".$_POST['code_expires']."'
			WHERE school_code='".$_POST['old_code']."'";

	$update1 = $db->query($upd1);
	$update2 = $db->query($upd2);
	
	header("Location: /codes.php");
}

// GET SCHOOL CODES
$sql = "SELECT A.*, COUNT(B.school_code) as members
		FROM school_codes as A 
		LEFT JOIN users as B ON A.school_code = B.school_code
	    GROUP BY A.school_code
		ORDER BY A.code_active DESC, A.school_name ASC";
$result = $db->query($sql);

include '_header.php';
?>
<style>
<!--
	.badge { color: #FFFFFF; }
-->	
</style>

<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <h1>School Code Editor</h1>
            <p><a href="/">Back to Admin Panel</a></p>


			<table class="table table-striped table-hover">
				<thead>
				<tr>
					<th>School Name</th>
					<th>School Code</th>
					<th>Members</th>
					<th>Expires</th>
					<th>Active</th>
					<th>Actions</th>
				</tr>
				</thead>
				<tbody>
                <?php
	            echo '<form action="/codes.php" method="post">';
				echo '<input type="hidden" name="school_id" value="new">';
				echo '<input type="hidden" name="old_code" value="new">';
	                echo '<tr id="sch-0">';
	                echo '<td><input type="text" name="school_name" class="form-control" value="" placeholder="New School Name"></td>';
	                echo '<td><input type="text" name="school_code" class="form-control" value="" placeholder="School Code"></td>';
	                echo '<td align="center">-</td>';
	                echo '<td><input type="text" name="code_expires" class="form-control" value="" placeholder="YYYY-MM-DD"></td>';
	                echo '<td align="center">';
						echo '<select name="code_active" class="form-control">';
						echo '<option value=1>Yes</option>';
						echo '<option value=2>No</option>';
						echo '</select>';
	                echo '</td>';
	                echo '<td align="center">
										<input type="submit" name="submitnew" class="btn btn-sm btn-success" value="Create Code" />
									</td>';
	                echo '</tr>';
                echo '</form>';
                ?>
					<?php
						$i=0;
						while($row = $result->fetch_assoc()) {
							
							$expires = strtotime($row['code_expires']." 23:59:59");
							$danger = $expires - time() < 90*24*60*60;



							if ($_GET['edit'] == $row['school_id']) {
								echo '<form action="/codes.php" method="post">';
								echo '<input type="hidden" name="school_id" value="'.$row['school_id'].'">'; 
								echo '<input type="hidden" name="old_code" value="'.$row['school_code'].'">'; 

								echo '<tr id="sch-'.$row['school_id'].'">';
								echo '<td><input type="text" name="school_name" class="form-control" value="'.$row['school_name'].'"></td>';
								echo '<td><input type="text" name="school_code" class="form-control" value="'.$row['school_code'].'"></td>';
								echo '<td align="center">'.$row['members'].'</td>';
								echo '<td'.($danger ? ' style="color:#BB0000;font-weight:bold;"' : '').'><input type="text" name="code_expires" class="form-control" value="'.$row['code_expires'].'"></td>';
								echo '<td align="center"><select name="code_active" class="form-control">';
									echo '<option value=1'.($row['code_active']?' selected="true"':'').'>Yes</option>';
									echo '<option value=2'.(!$row['code_active']?' selected="true"':'').'>No</option>';
								echo '</select></td>';
								echo '<td align="center">
									<a class="btn btn-sm btn-danger" href="codes.php">Cancel</a>
									<input type="submit" name="submitedit" class="btn btn-sm btn-success" value="Submit" />
								</td>';
								echo '</tr>';
							} 
							else {
								echo '<tr id="sch-'.$row['school_id'].'">';
								echo '<td>'.$row['school_name'].'</td>';
								echo '<td>'.$row['school_code'].'</td>';
								echo '<td align="center">'.$row['members'].'</td>';
								echo '<td align="center"'.($danger ? ' style="color:#BB0000;font-weight:bold;"' : '').'>'.$row['code_expires'].'</td>';
								echo '<td align="center">'.($row['code_active'] ? '<span class="badge bg-success">Yes</span>' : '<span class="badge bg-danger">No</span>').'</td>';
								echo '<td align="center"><a class="btn btn-sm btn-primary" href="codes.php?edit='.$row['school_id'].'#sch-'.$row['school_id'].'">Edit</a></td>';
								echo '</tr>';								
							}
						}
					?>
				</tbody>
			</table>
        </div>
    </div>
</div>


<?php
include '_footer.php';
?>