Skip to content

Commit

Permalink
Make script source local, and fix client_events.php
Browse files Browse the repository at this point in the history
  • Loading branch information
o-psi committed Feb 15, 2024
1 parent 767e0ec commit a2f8f8f
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 7 deletions.
2 changes: 1 addition & 1 deletion calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<?php require_once "footer.php";
?>

<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.10/index.global.min.js'></script>
<script src='plugins/fullcalendar-6.1.10/dist/index.global.js'></script>

<script>
document.addEventListener('DOMContentLoaded', function() {
Expand Down
127 changes: 121 additions & 6 deletions client_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

?>

<link href='plugins/fullcalendar/main.min.css' rel='stylesheet' />
<link href='plugins/fullcalendar-6.1.10/dist/index.global.js' rel='stylesheet' />

<!-- So that when hovering over a created event it turns into a hand instead of cursor -->
<style>
Expand Down Expand Up @@ -48,10 +48,9 @@

?>

<script src='plugins/fullcalendar/main.min.js'></script>
<script src='plugins/fullcalendar-6.1.10/dist/index.global.js'></script>

<script>

document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');

Expand All @@ -60,13 +59,15 @@
defaultView: 'dayGridMonth',
customButtons: {
addEvent: {
bootstrapFontAwesome: 'fa fa-fw fa-plus',
text: 'Add Event',
bootstrapFontAwesome: 'fa fa-plus',
click: function() {
$("#addCalendarEventModal").modal();
}
},
addCalendar: {
bootstrapFontAwesome: 'fa fa-fw fa-calendar-plus',
text: 'Add Calendar',
bootstrapFontAwesome: 'fa fa-calendar-plus',
click: function() {
$("#addCalendarModal").modal();
}
Expand All @@ -77,6 +78,33 @@
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth addEvent addCalendar'
},
<?php if (!$session_mobile) {
?>aspectRatio: 2.5,
<?php } else { ?>
aspectRatio: 0.7,
<?php } ?>
navLinks: true, // can click day/week names to navigate views
selectable: true,
height: '90vh',

selectMirror: true,
eventClick: function(editEvent) {
$('#editEventModal' + editEvent.event.id).modal();
},
dayMaxEvents: true, // allow "more" link when too many events
views: {
timeGrid: {
dayMaxEventRows: 3, // adjust to 6 only for timeGridWeek/timeGridDay
expandRows: true,
nowIndicator: true,
eventMaxStack: 1,
},
dayGrid: {
dayMaxEvents: 3, // adjust to 6 only for timeGridWeek/timeGridDay
expandRows: true,
},

},
events: [
<?php
$sql = mysqli_query($mysqli, "SELECT * FROM calendars LEFT JOIN events ON calendar_id = event_calendar_id WHERE event_client_id = $client_id");
Expand All @@ -91,11 +119,98 @@

echo "{ id: $event_id, title: $event_title, start: $event_start, end: $event_end, color: $calendar_color },";
}

//Invoices Created
$sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN invoices ON client_id = invoice_client_id WHERE client_id = $client_id");
while ($row = mysqli_fetch_array($sql)) {
$event_id = intval($row['invoice_id']);
$scope = strval($row['invoice_scope']);
if (empty($scope)) {
$scope = "Not Set";
}
$event_title = json_encode($row['invoice_prefix'] . $row['invoice_number'] . " created -scope: " . $scope);
$event_start = json_encode($row['invoice_date']);


echo "{ id: $event_id, title: $event_title, start: $event_start, display: 'list-item', color: 'blue', url: 'invoice.php?invoice_id=$event_id' },";
}

//Quotes Created
$sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN quotes ON client_id = quote_client_id WHERE client_id = $client_id");
while ($row = mysqli_fetch_array($sql)) {
$event_id = intval($row['quote_id']);
$event_title = json_encode($row['quote_prefix'] . $row['quote_number'] . " " . $row['quote_scope']);
$event_start = json_encode($row['quote_date']);

echo "{ id: $event_id, title: $event_title, start: $event_start, display: 'list-item', color: 'purple', url: 'quote.php?quote_id=$event_id' },";
}

//Tickets Created
$sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN tickets ON client_id = ticket_client_id LEFT JOIN users ON ticket_assigned_to = user_id WHERE client_id = $client_id");
while ($row = mysqli_fetch_array($sql)) {
$event_id = intval($row['ticket_id']);
$ticket_status = strval($row['ticket_status']);
$username = $row['user_name'];
if (empty($username)) {
$username = "";
} else {
//Limit to characters and add ...
$username = "[". substr($row['user_name'], 0, 9) . "...]";
}

$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " created - " . $row['ticket_subject'] . " " . $username . "{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_created_at']);


if ($ticket_status == "Closed") {
$event_color = "black";
} else if ($ticket_status == "Scheduled") {
$event_color = "grey";
} else if ($ticket_status == "Pending-Assignment") {
$event_color = "red";
} else {
$event_color = "blue";
}

echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
}

//Tickets Scheduled
$sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN tickets ON client_id = ticket_client_id LEFT JOIN users ON ticket_assigned_to = user_id WHERE ticket_schedule IS NOT NULL AND client_id = $client_id");
while ($row = mysqli_fetch_array($sql)) {
$event_id = intval($row['ticket_id']);
$username = $row['user_name'];
if (empty($username)) {
$username = "";
} else {
//Limit to characters and add ...
$username = substr($row['user_name'], 0, 9) . "...";
}

if (strtotime($row['ticket_schedule']) < time()) {
if ($row['ticket_status'] == 'Scheduled') {
$event_color = "red";
} else {
$event_color = "green";
}
} else {
$event_color = "grey";
}

$ticket_status = strval($row['ticket_status']);
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " scheduled - " . $row['ticket_subject'] . " [" . $username . "]{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_schedule']);


echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
}
?>
],
eventClick: function(editEvent) {
$('#editEventModal'+editEvent.event.id).modal();
}
},
eventOrder: 'allDay,start,-duration,title',

});

calendar.render();
Expand Down

0 comments on commit a2f8f8f

Please sign in to comment.