Skip to content

Commit

Permalink
Calendar start day
Browse files Browse the repository at this point in the history
Allow customising the calendar to start on a Monday instead of Sunday
  • Loading branch information
wrongecho committed May 26, 2024
1 parent 5210fae commit fbc8757
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
10 changes: 9 additions & 1 deletion calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@
?>
],
eventOrder: 'allDay,start,-duration,title',

<?php
// User preference for Calendar start day (Sunday/Monday)
// Fetch User Dashboard Settings
$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT user_config_calendar_first_day FROM user_settings WHERE user_id = $session_user_id"));
$user_config_calendar_first_day = intval($row['user_config_calendar_first_day']);
?>
firstDay: <?php echo $user_config_calendar_first_day ?>,
});

calendar.render();
Expand Down Expand Up @@ -293,4 +301,4 @@ function updateIncrementEndTime() {
// Update the end date field
document.getElementById("event_add_end").value = new_end;
}
</script>
</script>
12 changes: 9 additions & 3 deletions database_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1912,10 +1912,16 @@
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.1'");
}

// if (CURRENT_DATABASE_VERSION == '1.3.1') {
// // Insert queries here required to update to DB version 1.3.1
if (CURRENT_DATABASE_VERSION == '1.3.1') {
mysqli_query($mysqli, "ALTER TABLE `user_settings` ADD `user_config_calendar_first_day` TINYINT(1) NOT NULL DEFAULT 0 AFTER `user_config_dashboard_technical_enable`");

mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.2'");
}

// if (CURRENT_DATABASE_VERSION == '1.3.2') {
// // Insert queries here required to update to DB version 1.3.2
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.2'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.3'");
// }

} else {
Expand Down
2 changes: 1 addition & 1 deletion database_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/

DEFINE("LATEST_DATABASE_VERSION", "1.3.1");
DEFINE("LATEST_DATABASE_VERSION", "1.3.2");
1 change: 1 addition & 0 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ CREATE TABLE `user_settings` (
`user_config_records_per_page` int(11) NOT NULL DEFAULT 10,
`user_config_dashboard_financial_enable` tinyint(1) NOT NULL DEFAULT 0,
`user_config_dashboard_technical_enable` tinyint(1) NOT NULL DEFAULT 0,
`user_config_calendar_first_day` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
Expand Down
9 changes: 8 additions & 1 deletion post/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@
header('Location: post.php?logout');
}

if (isset($_POST['edit_your_user_browser_extention'])) {
if (isset($_POST['edit_your_user_preferences'])) {

// CSRF Check
validateCSRFToken($_POST['csrf_token']);

$calendar_first_day = intval($_POST['calendar_first_day']);

// Calendar
if (isset($calendar_first_day)) {
mysqli_query($mysqli, "UPDATE user_settings SET user_config_calendar_first_day = $calendar_first_day WHERE user_id = $session_user_id");
}

// Enable extension access, only if it isn't already setup (user doesn't have cookie)
if (isset($_POST['extension']) && $_POST['extension'] == 'Yes') {
if (!isset($_COOKIE['user_extension_key'])) {
Expand Down
24 changes: 20 additions & 4 deletions user_preferences.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
<?php
require_once "inc_all_user.php";

$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT user_config_calendar_first_day FROM user_settings WHERE user_id = $session_user_id"));
$user_config_calendar_first_day = intval($row['user_config_calendar_first_day']);

?>

<div class="card card-dark">
<div class="card-header py-3">
<h3 class="card-title"><i class="fas fa-fw fa-globe mr-2"></i>Browser Extension</h3>
<h3 class="card-title"><i class="fas fa-fw fa-globe mr-2"></i>Preferences</h3>
</div>
<div class="card-body">

<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">

<div class="form-group">
<label>Calendar starts on<strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
</div>
<select class="form-control select2" name="calendar_first_day" required>
<option <?php if ($user_config_calendar_first_day == '0') { echo "selected"; } ?> value="0" >Sunday</option>
<option <?php if ($user_config_calendar_first_day == '1') { echo "selected"; } ?> value="1" >Monday</option>
</select>
</div>
</div>

<?php if ($session_user_role > 1) { ?>

<div class="form-group">
<div class="form-check">
<input type="checkbox" class="form-check-input" name="extension" id="extension" value="Yes" <?php if (isset($_COOKIE['user_extension_key'])) {echo "checked";} ?>>
<input disabled="disabled" type="checkbox" class="form-check-input" name="extension" id="extension" value="Yes" <?php if (isset($_COOKIE['user_extension_key'])) {echo "checked";} ?>>
<label class="form-check-label" for="extension">Enable Browser Extention?</label>
<p class="small">Note: You must log out and back in again for these changes take effect.</p>
<p class="small">Not currently in use / Note: You must log out and back in again for these changes take effect.</p>
</div>
</div>

<?php } ?>

<button type="submit" name="edit_your_user_browser_extension" class="btn btn-primary btn-block mt-3"><i class="fas fa-check mr-2"></i>Save</button>
<button type="submit" name="edit_your_user_preferences" class="btn btn-primary btn-block mt-3"><i class="fas fa-check mr-2"></i>Save</button>

</form>

Expand Down

0 comments on commit fbc8757

Please sign in to comment.