Файловый менеджер - Редактировать - /var/www/jonas-eriksen.dk/pic/private/event.tar
Назад
index.php 0000644 00000005634 15233477763 0006415 0 ustar 00 <?php include_once('../include.php'); $event = new event($db); $admin = new admin($db); $admin->passwordResetCheck(); include('../static/header.php'); if (!isset($_GET['year'])) { $getYear = date("Y"); } else { $getYear = $_GET['year']; } $result = $event->getAll($getYear); ?> <div class="container"> <div class="row"> <div class="col-lg-12"> <?php echo "<h2>Træningsresultater i $getYear</h2>"; foreach ($event->getYears() as $year) { ?> <a href="?year=<?php echo $year[0] ?>"> <button class="btn btn-primary" type="button"> <?php echo $year[0] ?> <span class="badge"><?php $event->getYearCount($year[0]) ?></span> </button> </a> <?php } ?> <table id="eventTable" class="table-bordered" cellspacing="0" width="100%"> <thead> <tr> <th style="display: none"></th> <th>Skyttenavn</th> <th>Point</th> <th>Krydstier</th> <th>Våbentype</th> <?php if ($admin->admin_level(0)) { ?> <th></th> <?php } ?> </tr> </thead> <tfoot> <tr> <th style="display: none"></th> <th>Skyttenavn</th> <th>Point</th> <th>Krydstier</th> <th>Våbentype</th> <?php if ($admin->admin_level(0)) { ?> <th></th> <?php } ?> </tr> </tfoot> <tbody> <?php foreach ($result as $row) { echo "<tr>"; echo "<td style='display: none'>$row[9]</td>"; echo "<td><a href='/user/profile.php?user=$row[5]'>$row[0]</a></td>"; echo "<td>$row[1]</a></td>"; echo "<td>$row[2]</td>"; echo "<td>$row[3]</td>"; if ($admin->admin_level(0)) { echo "<td><a href='/event/edit.php?event=" . $row[9] . "'>Edit</a></td>"; } echo "</tr>"; } ?> </tbody> </table> </div> </div> </div> <script> $(document).ready(function () { $('#eventTable').DataTable({ "order": [[0, "desc"]] }); }); </script> <?php include('../static/footer.php'); Class.event.php 0000644 00000014324 15233477763 0007467 0 ustar 00 <?php class event { private $db; function __construct($DB_con) { $this->db = $DB_con; } public function newEvent($year, $shooterId, $point, $crossTen, $typeId) { try { $stmt = $this->db->prepare("INSERT INTO result_event (year, shooterId, point, `cross`, type, date) VALUES (:year, :userId, :point, :crossTen, :typeId, :date)"); $stmt->execute(array(":year" => $year, ":userId" => $shooterId, ":point" => $point, ":crossTen" => $crossTen, ":typeId" => $typeId, ":date" => date("Y/m/d"))); return $stmt; } catch (PDOException $e) { echo $e->getMessage(); } } public function getAll($eventYear) { try { $stmt = $this->db->prepare("SELECT result_users.fullname, result_event.point, result_event.`cross`, result_weapon.name, result_event.shooterId, result_users.id, result_weapon.id, result_event.`type`, result_event.year, result_event.id FROM result_event JOIN result_users on result_event.shooterId = result_users.id JOIN result_weapon on result_event.type = result_weapon.id WHERE result_event.year = :eventYear AND result_users.isDeleted != 1 ORDER BY result_event.id"); $stmt->execute(array(":eventYear" => $eventYear)); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } public function getAllForUser($eventYear, $userId) { try { $stmt = $this->db->prepare("SELECT result_event.id, result_event.point, result_event.`cross`, result_weapon.name, result_event.shooterId, result_users.id, result_weapon.id, result_event.`type`, result_event.year, result_event.date FROM result_event JOIN result_users on result_event.shooterId = result_users.id JOIN result_weapon on result_event.type = result_weapon.id WHERE result_event.year = :eventYear AND result_users.id = :userId ORDER BY result_event.id"); $stmt->execute(array(":eventYear" => $eventYear, ":userId" => $userId)); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } public function getAllForUserForPrint($userId) { try { $stmt = $this->db->prepare("SELECT result_event.id, result_event.point, result_event.`cross`, result_weapon.name, result_event.shooterId, result_users.id, result_weapon.id, result_event.`type`, result_event.year, result_event.date FROM result_event JOIN result_users on result_event.shooterId = result_users.id JOIN result_weapon on result_event.type = result_weapon.id WHERE result_users.id = :userId ORDER BY result_event.year, result_event.id"); $stmt->execute(array( ":userId" => $userId)); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } public function getYearCount($eventYear) { try { $stmt = $this->db->prepare("SELECT id FROM result_event WHERE result_event.year = :eventYear"); $stmt->execute(array(":eventYear" => $eventYear)); echo $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); } } public function getYearCountForUser($eventYear, $userId) { try { $stmt = $this->db->prepare("SELECT id FROM result_event WHERE result_event.year = :eventYear AND shooterId = :userId"); $stmt->execute(array(":eventYear" => $eventYear, ":userId" => $userId)); echo $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); } } public function getYears() { try { $stmt = $this->db->prepare("SELECT year FROM result_event GROUP BY year ORDER BY year DESC LIMIT 10"); $stmt->execute(); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } public function getYearsForUser($userId) { try { $stmt = $this->db->prepare("SELECT year FROM result_event WHERE shooterId = :shooterId GROUP BY year ORDER BY year DESC LIMIT 10"); $stmt->execute(array(":shooterId" => $userId)); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } public function getEvent($eventId) { try { $stmt = $this->db->prepare("SELECT point, `cross`, date, user2.shooterId, fullname, user2.id, rw.name, rw.id FROM result_event JOIN result_users user2 on result_event.shooterId = user2.id JOIN result_weapon rw on result_event.type = rw.id WHERE result_event.id = :eventId"); $stmt->execute(array(":eventId" => $eventId)); $event = $stmt->fetch(); return $event; } catch (PDOException $e) { echo $e->getMessage(); } } public function updateEvent($eventId, $point, $cross) { try { $stmt = $this->db->prepare("UPDATE result_event SET point = :point, `cross` = :cross WHERE id = :id"); $stmt->execute(array(":point" => $point, ":cross" => $cross, ":id" => $eventId)); return true; } catch (PDOException $e) { echo $e->getMessage(); } } public function deleteEvent($eventId) { try { $stmt = $this->db->prepare("DELETE FROM `result_event` WHERE `id` = :id"); $stmt->execute(array(":id" => $eventId)); return true; } catch (PDOException $e) { echo $e->getMessage(); } } public function getEventDates() { try { $stmt = $this->db->prepare("SELECT `result_event`.`date` FROM `result_event` GROUP BY `result_event`.`date` ORDER BY `result_event`.`date`; "); $stmt->execute(); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { echo $e->getMessage(); } } } edit.php 0000644 00000005635 15233477763 0006234 0 ustar 00 <?php include_once('../include.php'); $event = new event($db); $admin = new admin($db); $admin->passwordResetCheck(); $log = new log($db); if (!$admin->admin_level(0)) { $admin->redirect('../static/401.php'); } $e = $event->getEvent($_GET['event']); if (isset($_POST['saveEvent'])) { $event->updateEvent($_GET['event'], $_POST['point'], $_POST['cross']); $log->addLog($_SESSION['userId'], "Event opdateret", "Event", "/event/edit.php?event=" . $_GET['event']); $admin->redirect('/user/profile.php?user=' . $e[5]); } if (isset($_POST['deleteEvent'])) { if($event->deleteEvent($_GET['event'])) { $log->addLog($_SESSION['userId'], "Event deleted", "Event", "/event/edit.php?event=" . $_GET['event']); $admin->redirect('/user/profile.php?user=' . $e[5]); } } $weaponStmt = $db->prepare("SELECT id, name FROM result_weapon WHERE id != " . $e[7] . " ORDER BY CASE WHEN name LIKE 'Riffel%' THEN 1 ELSE 2 END, name"); $weaponStmt->execute(); include('../static/header.php'); if (isset($_GET['event'])) { ?> <h2>Skud af <a href="/user/profile.php?user=<?php echo $e[5] ?>"><?php echo $e[4] ?></a></h2> <form method="post"> <table class="table-bordered"> <tr> <th>Point</th> <td><input type="number" value="<?php echo $e[0] ?>" name="point"></td> </tr> <tr> <th>Cross</th> <td><input type="number" value="<?php echo $e[1] ?>" name="cross"></td> </tr> <tr> <th>Date</th> <td> <?php $date = new DateTime($e[2]); echo '<input value="' . $date->format('d-m-Y') . '" required pattern="\d{2}-\d{2}-\d{4}">'; ?> </td> </tr> <tr> <th>Våben</th> <td> <select name="weaponSelect"> <option value="<?php echo $e[7] ?>"><?php echo $e[6] ?></option> <?php foreach ($weaponStmt->fetchAll() as $weaponType) { ?> <option value="<?php echo $weaponType[0] ?>"><?php echo $weaponType[1] ?></option> <?php } ?> </select> </td> </tr> <tr> <th>Skyttenummer</th> <td><a href="/user/profile.php?user=<?php echo $e[5] ?>"><?php echo $e[3] ?></a></td> </tr> <tr> <th>Skytte</th> <td><a href="/user/profile.php?user=<?php echo $e[5] ?>"><?php echo $e[4] ?></a></td> </tr> <tr> <td><input type="submit" name="saveEvent"><input type="submit" name="deleteEvent" value="Delete event"></td> </tr> </table> </form> <?php } else { echo '<b>Intet event er valgt</b>'; } include('../static/footer.php'); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка