diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..1c13d28 --- /dev/null +++ b/TODO.md @@ -0,0 +1,41 @@ +1. Admin + - accounts + - famat.php L2: this + - import-account.php L48: bad + - bubbles + - createPDF.php L77: Implement team selection + - createPDF.php L144: make better + - competitions + - compTracker.php L136: Make this better, this is really, really bad! + - compTracker.php L181: Move functions out + - compTracker.php L197: I REALLY don't like this! I REALLY DON'T!!! + - compTracker.php L223: Do it right + - helper.php L59: Integrate "Comptition Fee" (not a generic payment) so that it is either paid or not + - reports + - comp-checkoff.php L54: Although this is admin only, make more secure + - comp-checkoff.php L89: make function + - comp-checkoff.php L91: make not bad +2. custom + - update background.png +3. docs + - update DOCS +4. img +5. shared + - accounts.php L9: implement into codebase + - accounts.php L273: comp info update (student and >=officer) + - accounts.php L286: Rethink end of school year + - accounts.php L299: implement getDivision function + - competitions.php L115: enumerate possibilities + - snippets.php L57: Reconsider placement (might need to move higher up in call list; ASK: "Should it be handled here?") + - snippets.php L199: use `second` parameter?? + - sql.php L15: Lord, the security + - transactions.php L3: implement into codebase + - transactions.php L57: review +6. student + - info.php L13: don't use $_POST['select-id'] + - info.php L77: This is bad and ugly and makes me want to cry. I hate my old code :( + - transactions.php L130: fix +7. favicon.ico + - update icon +8. index.php + - create a homepage diff --git a/account/login.php b/account/login.php index b715648..f2c57e5 100644 --- a/account/login.php +++ b/account/login.php @@ -11,7 +11,8 @@ try { $cycle_and_email_result = cycleLoginCode($_POST['id']); } catch (\PHPMailer\PHPMailer\Exception $e) { - } // TODO: error message + $error_message = "Eror: Unable to process cycle login. " . $e->getMessage(); + } else if (isset($_POST['login'])) { if (getAccountDetail('login', 'code', $_POST['id']) == strtoupper($_POST['code'])) { $_SESSION['id'] = $_POST['id']; // Login (session) @@ -36,9 +37,7 @@
- +
diff --git a/admin/accounts/delete.php b/admin/accounts/delete.php index ddb7e68..62a003e 100644 --- a/admin/accounts/delete.php +++ b/admin/accounts/delete.php @@ -42,8 +42,6 @@ personSelectForm(); personSelect(); ?>
- -
Account Information diff --git a/admin/competitions/CUD.php b/admin/competitions/CUD.php index f14ec9a..9ae1132 100644 --- a/admin/competitions/CUD.php +++ b/admin/competitions/CUD.php @@ -1,65 +1,82 @@ prepare( - "INSERT INTO competitions (competition_name, start_date, end_date, payment_id, show_forms, show_bus, show_room, description) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $create_competition_stmt = $sql_conn->prepare( + "INSERT INTO competitions (competition_name, start_date, end_date, payment_id, show_forms, show_bus, show_room, description, hidden) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" + ); - if (empty($payment_id)) - $payment_id = null; - $create_competition_stmt->bind_param('ssssiiis', - $comp_name, $start_date, $end_date, $payment_id, - $show_forms, $show_bus, $show_room, - $comp_desc); + if (empty($payment_id)) + $payment_id = null; + $create_competition_stmt->bind_param('ssssiiisi', + $comp_name, $start_date, $end_date, $payment_id, + $show_forms, $show_bus, $show_room, + $comp_desc, $hidden + ); - return $create_competition_stmt->execute() && $sql_conn->close(); + return $create_competition_stmt->execute() && $sql_conn->close(); } -function updateCompetition($comp_name, $start_date, $end_date, $payment_id, $show_forms, $show_bus, $show_room, $comp_desc): bool +function updateCompetition($comp_name, $start_date, $end_date, $payment_id, $show_forms, $show_bus, $show_room, $comp_desc, $hidden): bool { - require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/sql.php"; - $sql_conn = getDBConn(); - - $update_competition_stmt = $sql_conn->prepare( - "UPDATE competitions SET start_date = ?, end_date = ?, payment_id = ?, show_forms = ?, show_bus = ?, show_room = ?, description = ? - WHERE competition_name = ?"); - - if (empty($payment_id)) - $payment_id = null; - $update_competition_stmt->bind_param('sssiiiss', - $start_date, $end_date, $payment_id, - $show_forms, $show_bus, $show_room, - $comp_desc, - $comp_name); - - return $update_competition_stmt->execute() && $sql_conn->close(); + require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/sql.php"; + $sql_conn = getDBConn(); + + $update_competition_stmt = $sql_conn->prepare( + "UPDATE competitions SET start_date = ?, end_date = ?, payment_id = ?, show_forms = ?, show_bus = ?, show_room = ?, description = ?, hidden = ? + WHERE competition_name = ?" + ); + + if (empty($payment_id)) + $payment_id = null; + $update_competition_stmt->bind_param('sssiiissi', + $start_date, $end_date, $payment_id, + $show_forms, $show_bus, $show_room, + $comp_desc, $hidden, + $comp_name + ); + + return $update_competition_stmt->execute() && $sql_conn->close(); } -// Deletes corresponding competitions and transactions -function deleteCompetition($comp_name): bool +function hideCompetition($comp_name): bool { - require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/sql.php"; - $sql_conn = getDBConn(); - - // Competition - $delete_comp_stmt = $sql_conn->prepare("DELETE FROM competitions WHERE competition_name = ?"); - $delete_comp_stmt->bind_param('s', $comp_name); - $result_comp = $delete_comp_stmt->execute(); - - // Competition Data - $delete_comp_data_stmt = $sql_conn->prepare("DELETE FROM competition_data WHERE competition_name = ?"); - $delete_comp_data_stmt->bind_param('s', $comp_name); - $result_comp_data = $delete_comp_data_stmt->execute(); - - // Competition Selections - $delete_comp_selections_stmt = $sql_conn->prepare("DELETE FROM competition_selections WHERE competition_name = ?"); - $delete_comp_selections_stmt->bind_param('s', $comp_name); - $result_comp_selections = $delete_comp_selections_stmt->execute(); - - $sql_conn->close(); - return ($result_comp && $result_comp_data && $result_comp_selections); + require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/sql.php"; + $sql_conn = getDBConn(); + + // Update hidden attribute + $hide_comp_stmt = $sql_conn->prepare("UPDATE competitions SET hidden = 1 WHERE competition_name = ?"); + $hide_comp_stmt->bind_param('s', $comp_name); + $result_comp = $hide_comp_stmt->execute(); + + $sql_conn->close(); + return $result_comp; } + +function deleteCompetition($comp_name): bool +{ + require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/sql.php"; + $sql_conn = getDBConn(); + + // Competition + $delete_comp_stmt = $sql_conn->prepare("DELETE FROM competitions WHERE competition_name = ?"); + $delete_comp_stmt->bind_param('s', $comp_name); + $result_comp = $delete_comp_stmt->execute(); + + // Competition Data + $delete_comp_data_stmt = $sql_conn->prepare("DELETE FROM competition_data WHERE competition_name = ?"); + $delete_comp_data_stmt->bind_param('s', $comp_name); + $result_comp_data = $delete_comp_data_stmt->execute(); + + // Competition Selections + $delete_comp_selections_stmt = $sql_conn->prepare("DELETE FROM competition_selections WHERE competition_name = ?"); + $delete_comp_selections_stmt->bind_param('s', $comp_name); + $result_comp_selections = $delete_comp_selections_stmt->execute(); + + $sql_conn->close(); + return ($result_comp && $result_comp_data && $result_comp_selections); +} \ No newline at end of file diff --git a/admin/competitions/manage.php b/admin/competitions/manage.php index 9faade7..844a5f0 100644 --- a/admin/competitions/manage.php +++ b/admin/competitions/manage.php @@ -9,150 +9,166 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/permissions.php"; checkPerms(OFFICER_PERMS); -if (isset($_POST['create'])) { - require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/competitions/CUD.php"; - - $created = createCompetition( // Create competition - $_POST['comp_name'], $_POST['start_date'], $_POST['end_date'], $_POST['payment_id'], - isset($_POST['forms']), isset($_POST['bus']), isset($_POST['room']), - $_POST['info']); - - redirect(currentURL(false) . '?comp_name=' . rawurlencode($_POST['comp_name'])); // Redirect to created competition manage page -} else if (isset($_POST['update'])) { - require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/competitions/CUD.php"; - - updateCompetition( // Update competition - $_POST['comp_name'], $_POST['start_date'], $_POST['end_date'], $_POST['payment_id'], - isset($_POST['forms']), isset($_POST['bus']), isset($_POST['room']), - $_POST['info']); - - redirect(currentURL()); -} else if (isset($_POST['delete'])) { - require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/competitions/CUD.php"; - - deleteCompetition($_POST['comp_name']); // Delete competition - - redirect(currentURL(false)); // Redirect to deselected manage page +// Establishing the database connection +$sql_conn = getDBConn(); +if (!$sql_conn) { + // Log the error if connection fails + error_log("Failed to connect to database: " . mysqli_connect_error()); + die("Database connection failed. Check error log for details."); } require_once $_SERVER['DOCUMENT_ROOT'] . "/shared/competitions.php"; $comp = null; -if (isset($_GET['comp_name']) && existsComp($_GET['comp_name'])) - $comp = $_GET['comp_name'] +if (isset($_GET['comp_name']) && existsComp($_GET['comp_name'])) { + $comp = $_GET['comp_name']; + // Fetch competition details including hidden state + $start_date = getAssociatedCompInfo($comp, 'start_date'); + $end_date = getAssociatedCompInfo($comp, 'end_date'); + $payment_id = getAssociatedCompInfo($comp, 'payment_id'); + $check_status_forms = (getAssociatedCompInfo($comp, 'show_forms') ?? true) ? 'checked' : ''; + $check_status_bus = (getAssociatedCompInfo($comp, 'show_bus') ?? true) ? 'checked' : ''; + $check_status_room = (getAssociatedCompInfo($comp, 'show_room') ?? true) ? 'checked' : ''; + $check_status_hidden = (getAssociatedCompInfo($comp, 'hidden') ?? true) ? 'checked' : ''; + $description = getDetail('competitions', 'description', 'competition_name', $comp); +} else { + // Initialize variables if no competition is selected + $start_date = ''; + $end_date = ''; + $payment_id = ''; + $check_status_forms = ''; + $check_status_bus = ''; + $check_status_room = ''; + $check_status_hidden = ''; + $description = ''; +} + +// Handle form submission +if ($_SERVER["REQUEST_METHOD"] == "POST") { + if (isset($_POST['update'])) { + // Get form data + $comp_name = $_POST['comp_name']; + $start_date = $_POST['start_date']; + $end_date = $_POST['end_date']; + $payment_id = $_POST['payment_id']; + $show_forms = isset($_POST['forms']) ? 1 : 0; + $show_bus = isset($_POST['bus']) ? 1 : 0; + $show_room = isset($_POST['room']) ? 1 : 0; + $hidden = isset($_POST['hidden']) ? 1 : 0; + $description = $_POST['info']; + + // Update competition details in the database + $update_stmt = $sql_conn->prepare("UPDATE competitions SET start_date=?, end_date=?, payment_id=?, show_forms=?, show_bus=?, show_room=?, hidden=?, description=? WHERE competition_name=?"); + $update_stmt->bind_param("ssiiiiiss", $start_date, $end_date, $payment_id, $show_forms, $show_bus, $show_room, $hidden, $description, $comp_name); + if ($update_stmt->execute()) { + echo ""; + echo ""; // Refresh the page after the successful update + } else { + echo "Error updating competition: " . $update_stmt->error; + } + $update_stmt->close(); + } +} ?> MAO | Competitions

Competitions

- -
- Competition - - - -
- - -
- -
- - - -
-
-

Information

- -
- - > - "; - ?>
- - -
- - -
- - - + + prepare("SELECT competition_name FROM competitions"); + $comp_names_stmt->bind_result($curr_comp_name); + $comp_names_stmt->execute(); + + while ($comp_names_stmt->fetch()) { + if ($curr_comp_name == $comp) { + echo ""; + } else { + echo ""; + } + } + $comp_names_stmt->close(); // Close statement after use + ?> -
-
- -

Show Fields

- -
- > -
- - > -
- - > -
-
-
- -

Description

- -
-
- > - > - > -
-
\ No newline at end of file +
+ + +
+
+

Information

+ +
+ + > + "; + ?>
+ + +
+ + +
+ + + +
+
+ +

Show Fields

+ +
+ > +
+ + > +
+ + > +
+ + > +
+
+
+ +

Description

+
+
+ > + > + > +
+
+
\ No newline at end of file diff --git a/config.ini b/config.ini index 2414d18..babb23f 100644 --- a/config.ini +++ b/config.ini @@ -1,8 +1,8 @@ [sql] hostname = "localhost" -username = "mrnoops" -password = "" -database = "mao" +username = "maomanagement" +password = "maomanagement" +database = "maomanagement" [email] name = "MAO Management System" diff --git a/custom/calendar.php b/custom/calendar.php deleted file mode 100644 index 604bbda..0000000 --- a/custom/calendar.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/mao.sql b/mao.sql index 65894ff..f72900a 100644 --- a/mao.sql +++ b/mao.sql @@ -48,7 +48,8 @@ CREATE TABLE `competitions` ( `payment_id` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `show_forms` tinyint(1) NOT NULL DEFAULT 1, `show_bus` tinyint(1) NOT NULL DEFAULT 1, - `show_room` tinyint(1) NOT NULL DEFAULT 1 + `show_room` tinyint(1) NOT NULL DEFAULT 1, + `hidden` tinyint(1) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- diff --git a/student/selections.php b/student/selections.php index a47ca0e..0d01bf0 100644 --- a/student/selections.php +++ b/student/selections.php @@ -90,7 +90,7 @@ $sql_conn = getDBConn(); - $stmt = $sql_conn->prepare("SELECT c.competition_name AS comp, c.description AS comp_desc, c.start_date, c.end_date, (cs.unique_id IS NOT NULL) AS is_selected FROM competitions c LEFT OUTER JOIN competition_selections cs ON c.competition_name = cs.competition_name AND cs.id = ? ORDER BY c.start_date, c.end_date, c.competition_name"); + $stmt = $sql_conn->prepare("SELECT c.competition_name AS comp, c.description AS comp_desc, c.start_date, c.end_date, (cs.unique_id IS NOT NULL) AS is_selected FROM competitions c LEFT OUTER JOIN competition_selections cs ON c.competition_name = cs.competition_name AND cs.id = ? WHERE NOT c.hidden ORDER BY c.start_date, c.end_date, c.competition_name"); $stmt->bind_param('s', $id); $stmt->bind_result($comp, $comp_desc, $start_date, $end_date, $is_selected); $stmt->execute();