4 * Script to load a calendar from an ICS file from the command line.
13 $basename davical.example.com replace /username/calendar/ calendarfile.ics
16 'davical.example.com' is the hostname of your DAViCal server.
17 'replace' is either 'replace' or 'append'
18 '/username/calendar/' is the (sub-)path of the calendar to be updated.
19 'calendarfile.ics' is the iCalendar file to be loaded.
21 This script can be used to load events or whole calendars from an external
24 If the mode is 'replace' and the target calendar does not exist then it will
25 be created. For appending the calendar must always exist.
31 $_SERVER['SERVER_NAME'] = $argv[1];
36 if ( ! is_readable($source) ) {
37 printf( "The iCalendar source file '%s' was not found.\n", $source );
40 $ics = trim(file_get_contents($source));
41 if ( strlen($ics) < 29 ) {
42 printf( "The iCalendar source file '%s' was missing or invalid.\n", $source );
47 $script_file = __FILE__
;
48 chdir(preg_replace('{/scripts/[^/]+.php$}','/htdocs',$script_file));
50 require_once("./always.php");
51 require_once('caldav-PUT-functions.php');
52 require_once('check_UTF8.php');
53 $c->readonly_webdav_collections
= false; // Override any active default.
55 dbg_error_log('load-collection',':Write: Loaded %d bytes from %s', strlen($ics), $source );
56 if ( !check_string($ics) ) {
57 $ics = force_utf8($ics);
58 if ( !check_string($ics) ) {
59 printf( "The source file '%s' contains some non-UTF-8 characters.\n", $source );
74 function __construct($user_no = null) {
75 if ( empty($user_no) ) {
77 $this->principal_id
= -1;
78 $this->logged_in
= false;
82 $this->user_no
= $user_no;
83 $principal = new Principal('user_no',$user_no);
84 // Assign each field in the selected record to the object
85 foreach( $principal AS $k => $v ) {
88 $this->username
= $principal->username();
89 $this->principal_id
= $principal->principal_id();
90 $this->email
= $principal->email();
91 $this->dav_name
= $principal->dav_name();
92 $this->principal
= $principal;
94 $this->logged_in
= true;
98 function AllowedTo($do_something) {
99 return $this->logged_in
;
102 $session = new FakeSession();
104 $dest = new DAVResource($target);
105 $session = new FakeSession($dest->user_no());
106 if ( $mode == 'append' && ! $dest->Exists() ) {
107 printf( "The target '%s' does not exist.\n", $target );
111 if ( ! $dest->IsCollection() ) {
112 printf( "The target '%s' is not a collection.\n", $target );
116 $user_no = $dest->user_no();
117 $username = $session->username
;
118 param_to_global('mode');
119 include_once('caldav-PUT-functions.php');
120 controlRequestContainer( $session->username
, $dest->user_no(), $target, false, ($dest->IsPublic() ?
true : false));
121 import_collection( $ics, $dest->user_no(), $target, $session->user_no
, ($mode == 'append') );
122 printf(translate("Calendar '%s' was loaded from file.\n"), $target);