This commit is contained in:
2025-11-26 18:08:49 +01:00
commit c1385699ab
3 changed files with 133 additions and 0 deletions

61
caldav.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
if (!defined('INCLUDE_DIR')) die('Fatal error');
class CaldavPlugin extends Plugin {
public $config_class = 'CaldavConfig';
public function getConfigurationForm() {
return array(
'calendar_url' => new TextboxField(array(
'label' => 'Calendar URL',
'configuration' => array(
'size' => 60,
'length' => 255
),
'required' => true
)),
'app_token' => new TextboxField(array(
'label' => 'App Token',
'configuration' => array(
'size' => 60,
'length' => 255
),
'required' => true,
'widget' => 'Password'
)),
);
}
public function getAgentActions() {
return array(
'create_calendar_entry' => array(
'label' => 'Create Calendar Entry',
'action' => 'createCalendarEntry'
)
);
}
public function createCalendarEntry($ticket) {
// Implementation will go here
}
}
class CaldavConfig extends PluginConfig {
public function getOptions() {
return array(
'calendar_url' => $this->getConfig('calendar_url'),
'app_token' => $this->getConfig('app_token')
);
}
public function pre_save($config, &$errors) {
if (!$config['calendar_url']) {
$errors['calendar_url'] = 'Calendar URL is required';
}
if (!$config['app_token']) {
$errors['app_token'] = 'App Token is required';
}
return true;
}
}
?>

61
hooks.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
// Hook into osTicket events
class CaldavHooks {
static function onTicketCreated($ticket) {
// Trigger calendar entry creation when ticket is created
$config = Plugin::getConfig('caldav');
if ($config && $config['calendar_url'] && $config['app_token']) {
self::createCalendarEntry($ticket, $config);
}
}
static function createCalendarEntry($ticket, $config) {
// Your CalDAV implementation here
$url = $config['calendar_url'];
$token = $config['app_token'];
// Example using cURL for CalDAV operations:
$icalData = self::generateIcalEvent($ticket);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $icalData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: text/calendar',
'Authorization: Bearer ' . $token
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Handle response (log errors, etc.)
if ($httpCode >= 200 && $httpCode < 300) {
// Success
} else {
// Log error
error_log("CalDAV Error: " . $response);
}
}
static function generateIcalEvent($ticket) {
$summary = 'Ticket #' . $ticket->getNumber();
$description = $ticket->getSubject();
return "BEGIN:VCALENDAR\n" .
"VERSION:2.0\n" .
"PRODID:-//osTicket CalDAV Plugin\n" .
"BEGIN:VEVENT\n" .
"UID:" . uniqid() . "@osticket.com\n" .
"DTSTAMP:" . date('Ymd\THis\Z') . "\n" .
"DTSTART:" . date('Ymd\THis\Z') . "\n" .
"SUMMARY:" . $summary . "\n" .
"DESCRIPTION:" . $description . "\n" .
"END:VEVENT\n" .
"END:VCALENDAR";
}
}
?>

11
plugin.php.disabled Normal file
View File

@@ -0,0 +1,11 @@
<?php
return array(
'id' => 'caldav',
'name' => 'CalDAV Integration',
'version' => '1.0',
'author' => 'Your Name',
'description' => 'Integrate with external CalDAV servers for creating calendar entries',
'url' => 'https://yourdomain.com',
'plugin' => 'caldav.php:CaldavPlugin'
);
?>