mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-23 02:14:16 +00:00
Fix tools.php to allow importing of a directory of calendars again.
This commit is contained in:
parent
2fd4a95285
commit
4d1f936a8b
@ -17,6 +17,9 @@ require_once("DataEntry.php");
|
||||
require_once("interactive-page.php");
|
||||
require_once("classBrowser.php");
|
||||
|
||||
require_once("caldav-PUT-functions.php");
|
||||
include_once('check_UTF8.php');
|
||||
|
||||
if ( !$session->AllowedTo("Admin" ) )
|
||||
exit;
|
||||
|
||||
@ -43,7 +46,7 @@ class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
function renderSyncLDAP(){
|
||||
static function renderSyncLDAP(){
|
||||
$html = '<div id="entryform">';
|
||||
$html .= '<h1>'.translate('Sync LDAP with DAViCal') .'</h1>';
|
||||
|
||||
@ -71,18 +74,19 @@ class Tools {
|
||||
return $html;
|
||||
}
|
||||
|
||||
function renderImportFromDirectory(){
|
||||
static function renderImportFromDirectory(){
|
||||
$html = '<div id="entryform">';
|
||||
$html .= '<h1>'.translate('Import all .ics files of a directory') .'</h1>';
|
||||
|
||||
$data = (object) array('directory_path' => '/path/to/your/ics/files','calendar_path' => 'home');
|
||||
$html .= '<p>'.translate('This process will import each file in a directory named "username.ics" and create a user and calendar for each file to import.') .'</p>';
|
||||
|
||||
$data = (object) array('directory_path' => '/path/to/your/ics/files','calendar_path' => 'calendar');
|
||||
$ef = new EntryForm( $_SERVER['REQUEST_URI'],$data , true,true );
|
||||
$html .= "<table width=\"100%\" class=\"data\">\n";
|
||||
$html .= $ef->StartForm( array("autocomplete" => "off" ) );
|
||||
|
||||
$html .= $ef->DataEntryLine( translate("path to store your ics"), "%s", "text", "calendar_path",
|
||||
array( "size" => 20,
|
||||
"title" => translate("Set the path to store your ics e.g. 'home' will be referenced as /caldav.php/me/home/"),
|
||||
"title" => translate("Set the path to store your ics e.g. 'calendar' will be referenced as /caldav.php/username/calendar/"),
|
||||
"help" => translate("<b>WARNING: all events in this path will be deleted before inserting allof the ics file</b>")
|
||||
)
|
||||
, '' );
|
||||
@ -98,9 +102,9 @@ class Tools {
|
||||
return $html;
|
||||
}
|
||||
|
||||
function importFromDirectory(){
|
||||
static function importFromDirectory(){
|
||||
global $c;
|
||||
if(!isset($_POST["calendar_path"])){
|
||||
if(empty($_POST["calendar_path"])){
|
||||
dbg_error_log( "importFromDirectory", "calendar path not given");
|
||||
return ;
|
||||
}
|
||||
@ -108,7 +112,7 @@ class Tools {
|
||||
if ( substr($path_ics,-1,1) != '/' ) $path_ics .= '/'; // ensure that we target a collection
|
||||
if ( substr($path_ics,0,1) != '/' ) $path_ics = '/'.$path_ics; // ensure that we target a collection
|
||||
|
||||
if(!isset($_POST["directory_path"])){
|
||||
if(empty($_POST["directory_path"])){
|
||||
dbg_error_log( "importFromDirectory", "directory path not given");
|
||||
return ;
|
||||
}
|
||||
@ -119,6 +123,7 @@ class Tools {
|
||||
return ;
|
||||
}
|
||||
if ($handle = opendir($dir)) {
|
||||
$c->readonly_webdav_collections = false; // Override this setting so we can create collections/events on import.
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == "." || $file == ".." || substr($file,-4) != '.ics') continue;
|
||||
if ( !is_readable($dir.'/'.$file) ) {
|
||||
@ -130,24 +135,23 @@ class Tools {
|
||||
|
||||
|
||||
if ( $ics != '' ) {
|
||||
include_once('check_UTF8.php');
|
||||
if ( check_string($ics) ) {
|
||||
$username = substr($file,0,-4);
|
||||
$path = "/".$username.$path_ics;
|
||||
dbg_error_log( "importFromDirectory", "importing to $path");
|
||||
$c->readonly_webdav_collections = false; // Override this setting so we can create collections/events on import.
|
||||
require_once("caldav-PUT-functions.php");
|
||||
if ( $principal = new Principal('username',$username) ) {
|
||||
$user_no = $principal->user_no();
|
||||
}
|
||||
if ( controlRequestContainer($username, $user_no, $path, false) === -1)
|
||||
continue;
|
||||
import_collection($ics,$user_no,$path,1);
|
||||
$c->messages[] = sprintf(translate('all events of user %s were deleted and replaced by those from file %s'),substr($file,0,-4),$dir.'/'.$file);
|
||||
if ( ! check_string($ics) ) {
|
||||
$c->messages[] = sprintf(translate('The file "%s" is not UTF-8 encoded, please check error for more details'),$dir.'/'.$file);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$c->messages[] = sprintf(translate('the file %s is not UTF-8 encoded, please check error for more details'),$dir.'/'.$file);
|
||||
$username = substr($file,0,-4);
|
||||
$principal = new Principal('username',$username);
|
||||
if ( !$principal->Exists() ) {
|
||||
$c->messages[] = sprintf(translate('The principal "%s" does not exist'),$username);
|
||||
continue;
|
||||
}
|
||||
$path = "/".$username.$path_ics;
|
||||
$user_no = $principal->user_no();
|
||||
if ( controlRequestContainer($username, $user_no, $path, false) === -1)
|
||||
continue;
|
||||
dbg_error_log( "importFromDirectory", "importing to $path");
|
||||
import_collection($ics,$user_no,$path,1);
|
||||
$c->messages[] = sprintf(translate('All events of user "%s" were deleted and replaced by those from file %s'),substr($file,0,-4),$dir.'/'.$file);
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
@ -317,7 +317,7 @@ function handle_schedule_reply ( vCalendar $ical ) {
|
||||
*/
|
||||
function do_scheduling_requests( vCalendar $resource, $create ) {
|
||||
global $request, $c;
|
||||
if ( isset($c->enable_auto_schedule) && !$c->enable_auto_schedule ) return;
|
||||
if ( !isset($request) || (isset($c->enable_auto_schedule) && !$c->enable_auto_schedule) ) return;
|
||||
|
||||
if ( ! is_object($resource) ) {
|
||||
dbg_error_log( 'PUT', 'do_scheduling_requests called with non-object parameter (%s)', gettype($resource) );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user