SergeyMosin / Appointments

Nextcloud Appointments App
GNU Affero General Public License v3.0
163 stars 48 forks source link

[Feature Request] How to make sure all appointments are booked #396

Open funktionierbar opened 1 year ago

funktionierbar commented 1 year ago

Hi, I love your plugin, and have been using it for a while. Now I want to try it with a new usecase: The group of volunteers staffsa small shop, and we want to use the plugin to manage who staffs the shop on which days. I created an external source calendar with the opening hours that should be staffed. The volunteers then "book" one of the days, and are reminded 24h before the day they're supposed to be there. But, sometimes no one books a certain date, and nobody notices that nobody booked that date. It would be great if we had a place in the UI where we could see which appointments are not booked yet, so kind of (Source - Destination). It would be even greater If there was some kind of alarm mechanism that sends a mail two weeks or two days ahead if there is a appointment that is not booked.

SergeyMosin commented 1 year ago

Currently this is not possible, but it is a good feature request.

funktionierbar commented 1 year ago

May be it would be the easiest to just set the status of the appointment in the source calender to busy when booking an appointment? I would consider the issue solved if I can open a page that shows clearly which appointments are open/unbooked in a calendar view. Maybe I will open a serperate feature request for the alarm function. I am not able to contribute code, but I could contribute a bounty. Would that be appreciated?

funktionierbar commented 1 year ago

I posted a bounty on https://app.bountysource.com/issues/116035001-feature-request-how-to-make-sure-all-appointments-are-booked

martin-77 commented 1 year ago

Should be easy to do: Warning: not tested: generated with chatGPT...

<?php
// Laden Sie die PHPMailer-Bibliothek herunter: https://github.com/PHPMailer/PHPMailer
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

// Die URL des Kalenders und die Anmeldeinformationen des Benutzers
$calendar_url = 'https://example.com/calendar';
$username = 'username';
$password = 'password';

// Eine CalDAV-Abfrage zum Abrufen der Ereignisse im Kalender
$query = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
  <d:prop>
    <cs:getctag />
  </d:prop>
</d:propfind>
EOD;

// Eine Anfrage an den Kalenderserver, um die Ereignisse im Kalender abzurufen
$ch = curl_init($calendar_url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PROPFIND');
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

// Verarbeiten Sie die Antwort und extrahieren Sie die Anzahl der Ereignisse
if ($response) {
  $xml = simplexml_load_string($response);
  $xml->registerXPathNamespace('d', 'DAV:');
  $xml->registerXPathNamespace('cs', 'http://calendarserver.org/ns/');
  $ctag = $xml->xpath('//cs:getctag');
  $event_count = count($xml->xpath('//d:response/d:propstat/d:prop/icalendar:calendar-data/icalendar:vevent'));
  if ($event_count > 0) {
    echo "Der Kalender '$calendar_url' enthält $event_count Ereignisse (CTag: $ctag[0]).";
  } else {
    // Keine Ereignisse gefunden - senden Sie eine E-Mail-Benachrichtigung
    $to = 'meine-email@example.com';
    $subject = 'Keine Ereignisse im Kalender gefunden';
    $message = "Es gibt keine Ereignisse im Kalender '$calendar_url'.";

    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->isSMTP();
    $mail->Host = 'mail.example.com'; // SMTP-Host Ihres Mail-Servers
    $mail->Port = 587; // Port für SMTP-Verbindung
    $mail->SMTPSecure = 'tls'; // Art der Verschlüsselung für SMTP-Verbindung
    $mail->SMTPAuth = true; // SMTP-Authentifizierung aktivieren
    $mail->Username = 'your-email@example.com'; // Benutzername für SMTP-Authentifizierung
    $mail->Password = 'your-password'; // Passwort für SMTP-Authentifizierung
    $mail->setFrom('webmaster@example.com', 'Webmaster'); // Absender-Adresse und Name
    $mail->addAddress($to);

now: generate a cronjob, run it daily an you should be good to go...