Skip to content

Commit

Permalink
more profile features
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsalisbury committed Dec 1, 2023
1 parent 8a063ec commit debd412
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 23 deletions.
12 changes: 12 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ h2 {
font-size: 1.5rem;
}

h3 {
font-size: 1.25rem;
}

h4 {
font-size: 1rem;
}

label {
font-size: 0.9rem;
}

main {
flex: 1;
}
Expand Down
21 changes: 21 additions & 0 deletions public/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ function do_login() {
}
}

function save_profile() {
global $db;
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = $_POST['new_password'];
$password_confirm = $_POST['password_confirm'];
if ($password !== $password_confirm) {
$_SESSION['error'] = 'Passwords do not match';
header('Location: /profile');
exit;
}
$password = password_hash($password, PASSWORD_DEFAULT);
$sql = "UPDATE users SET firstname = '$firstname', lastname = '$lastname', email = '$email', phone = '$phone', password = '$password' WHERE id = " . $_SESSION['user_id'];
$db->exec($sql);
$_SESSION['success'] = 'Profile updated successfully';
header('Location: /profile');
exit;
}

function do_logout() {
session_destroy();
header('Location: /');
Expand Down
17 changes: 13 additions & 4 deletions public/layouts/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,35 @@
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<div class="container">
<a class="navbar-brand" href="#">Crop Insurance Alerts</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/">Management Dashboard</a>
<a class="nav-link
<?php if ($_SERVER['REQUEST_URI'] == '/') : ?>
active
<?php endif; ?>
" aria-current="page" href="/">Management Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/profile">My Grower Profile</a>
<a class="

<?php if ($_SERVER['REQUEST_URI'] == '/profile') : ?>
active
<?php endif; ?>
nav-link" href="/profile">My Grower Profile</a>
</li>
</ul>
</div>
<!-- login/logout -->
<div class="d-flex">
<?php if (isset($_SESSION['user_id'])) : ?>
<span class="me-3">Welcome, <?php echo $_SESSION['firstname']; ?></span>
<a href="/logout" class="btn btn-danger">Logout</a>=
<a href="/logout" class="btn btn-danger">Logout</a>
<?php else : ?>
<a href="/login" class="btn btn-primary me-2">Login</a>
<a href="/register" class="btn btn-secondary">Register</a>
Expand Down
30 changes: 15 additions & 15 deletions public/pages/home.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="page page-home container-fluid">
<div class="page page-home container">
<header class="page-header">
<h2>Management Dashboard</h2>
</header>
Expand Down Expand Up @@ -26,7 +26,7 @@
<input type="text" name="crop" id="crop">
<button type="submit" class="btn btn-primary">Add Crop</button>
</div>

</div>
</form>
</div>
Expand All @@ -46,9 +46,9 @@
</table>
<form action="/crops" method="post">
<div class="mb-3">
<label for="crop">Crops</label>
<input type="text" name="crop" id="crop">
<button type="submit">Add Crop</button>
<label for="crop">Crops</label>
<input type="text" name="crop" id="crop">
<button type="submit">Add Crop</button>
</div>
</form>
</div>
Expand All @@ -64,19 +64,19 @@
<div id="statesCollapse" class="accordion-collapse collapse" aria-labelledby="statesHeading" data-bs-parent="#accordionSections">
<div class="accordion-body">
<div class="card">
<form action="/states" method="post">
<h5 class="card-header">Add State</h5>
<div class="card-body">
<form action="/states" method="post">
<h5 class="card-header">Add State</h5>
<div class="card-body">

<div class="mb-3">
<label for="state">State</label>
<input type="text" name="state" id="state">
<button type="submit" class="btn btn-primary">Add State</button>
</div>
</div>



</div>
</form>
</div>

Expand Down Expand Up @@ -118,7 +118,7 @@
<div class="card">
<h5 class="card-header">Add Deadline</h5>
<div class="card-body">

<form action="/deadlines" method="post">
<div class="mb-3">
<label for="state">State</label>
Expand Down Expand Up @@ -146,7 +146,7 @@
</div>

<button type="submit" class="btn btn-primary">Add Deadline</button>

</form>
</div>
</div>
Expand Down
106 changes: 102 additions & 4 deletions public/pages/profile.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,114 @@
<?php
<?php

require_once 'functions.php';
$states=get_all_states();
$crops=get_all_crops();

?>
<div class="page page-profile container">
<header class="page-header">
<h2>My Profile</h2>
</header>
<div class="row">
<div class="row mt-3">
<div class="col-md-6">
<h4>Basic Information</h4>
<!-- firstname, lastname, email address, state, and crops -->
<h3>Basic Information</h3>
<form action="/post/profile" method="post">
<div class="mb-3">
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" value="<?php echo $_SESSION['user']['firstname']; ?>">
</div>
<div class="mb-3">
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname" value="<?php echo $_SESSION['user']['lastname']; ?>">
</div>
<div class="mb-3">
<label for="email">Email Address</label>
<input type="email" name="email" id="email" value="<?php echo $_SESSION['user']['email']; ?>">
</div>

<div class="mb-3">
<label for="phone">Phone Number</label>
<input type="text" name="phone" id="phone" value="<?php echo $_SESSION['user']['phone']; ?>">
</div>




<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>

<div class="col-md-6">
<h3>Change Password</h3>
<form action="/post/password" method="post">
<div class="mb-3">
<label for="password">Password</label>
<input type="password" name="password" id="password">
</div>
<!-- confirm password -->
<div class="mb-3">
<label for="password_confirm">Confirm Password</label>
<input type="password" name="password_confirm" id="password_confirm">
</div>
<button type="submit" class="btn btn-primary">Change Password</button>
</form>
</div>

<div class="col-md-10 mt-5">
<h3>My Crops</h3>
<!-- card for subscribing to a reminder: select a state, select a crop -->
<div class="card">
<h5 class="card-header">Subscribe to a Reminder</h5>
<div class="card-body">
<form action="/post/subscribe" method="post">
<div class="mb-3">
<label for="state">State</label>
<select name="state" id="state">
<?php foreach ($states as $state) : ?>
<option value="<?php echo $state['id']; ?>"><?php echo $state['state']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="crop">Crop</label>
<select name="crop" id="crop">
<?php foreach ($crops as $crop) : ?>
<option value="<?php echo $crop['id']; ?>"><?php echo $crop['crop']; ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
</div>
</div>

<h4 class="mt-5">My Reminders</h4>

<!-- table of subscribed reminders -->
<table class="table">
<tr>
<th>State</th>
<th>Crop</th>
<th>Deadline Name</th>
<th>Deadline Date</th>
<th>Actions</th>
</tr>
<?php
$deadlines = get_all_deadlines($_SESSION['user_id']);
foreach ($deadlines as $deadline) {
echo '<tr>';
echo '<td>' . $deadline['state'] . '</td>';
echo '<td>' . $deadline['crop'] . '</td>';
echo '<td>' . $deadline['deadline_name'] . '</td>';
echo '<td>' . $deadline['deadline'] . '</td>';
echo '<td><a href="/post/unsubscribe/' . $deadline['id'] . '" class="btn btn-danger">Unsubscribe</a></td>';
echo '</tr>';
}
?>
</table>



</div>
</div>
</div>
Expand Down

0 comments on commit debd412

Please sign in to comment.