From 46555cb26ee31917ffcc02c1230d4bc42dd6d911 Mon Sep 17 00:00:00 2001 From: Maxime Delorme Date: Sat, 5 May 2007 11:40:08 +1200 Subject: [PATCH] Handle calendar upload. --- htdocs/user.php | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/htdocs/user.php b/htdocs/user.php index 1da57ff4..f949e5d0 100644 --- a/htdocs/user.php +++ b/htdocs/user.php @@ -35,6 +35,17 @@ $c->page_title = $user->Get("user_no"). " - " . $user->Get("fullname"); } } + if ( $_FILES['ics_file']['name'] && $_POST['path_ics'] ) { + $ics = file_get_contents($_FILES['ics_file']['tmp_name']); + $ics = trim($ics); + $path_ics = $_POST['path_ics']; + + 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 + } + else { + unset($ics); + } } else { /** @@ -50,12 +61,38 @@ if ( $session->AllowedTo("Admin") ) $user_menu->AddOption(translate("New User"),"$c->base_url/user.php?create",translate("Add a new user"), false, 10); - if ( $user->user_no > 0 && $user->AllowedTo('update') ) { - $user_menu->AddOption(translate("View"),"$c->base_url/user.php?user_no=$user->user_no",translate("View this user record") ); - $user_menu->AddOption(translate("Edit"),"$c->base_url/user.php?edit=1&user_no=$user->user_no",translate("Edit this user record"), $user->EditMode ); + + if ( $user->user_no > 0 ) { + if ( $user->AllowedTo('update') ) { + $user_menu->AddOption( translate($user->EditMode?"View":"Edit")." ".$user->Values->fullname, "$c->base_url/user.php?user_no=$user->user_no".($user->EditMode?"":"&edit=1"), translate(($user->EditMode?"View":"Edit")." this user record"), true, 900 ); + } + else { + $user_menu->AddOption( translate("View")." ".$user->Values->fullname, "$c->base_url/user.php?user_no=$user->user_no", translate("View this user record"), true, 900 ); + } } include("page-header.php"); echo $user->Render($c->page_title); include("page-footer.php"); -?> \ No newline at end of file + if ( $ics !='' ) { + /** + * If the user has uploaded a .ics file as a calendar, we fake this out + * as if it were a "PUT" request against a collection. This is something + * of a hack, especially since it doesn't provide quality feedback to the + * user about what is happening. It works though :-) + * + * TODO: Extract the important code from caldav-PUT-collection.php into a + * function which can be included here and shared. That way we can perhaps + * show the user a useful error message, if needed. + */ + include('check_UTF8.php'); + if ( check_string($ics) ) { + $_SERVER['REQUEST_METHOD'] = 'PUT'; + $_SERVER['PATH_INFO'] = "/".$user->Get("username").$path_ics; + require_once("CalDAVRequest.php"); + $request = new CalDAVRequest(); + $request->raw_post = $ics; + include_once("caldav-PUT.php"); + } + } +?>