diff --git a/web/documentserver-example/php/common.php b/web/documentserver-example/php/common.php index 54eff0b2..061b8b10 100644 --- a/web/documentserver-example/php/common.php +++ b/web/documentserver-example/php/common.php @@ -171,6 +171,17 @@ function getInternalExtension($filename) { return ""; } +// get image url for templates +function getTemplateImageUrl($filename) { + $ext = strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)); + $path = serverPath(true) . "/css/images/"; + + if (in_array($ext, $GLOBALS['ExtsDocument'])) return $path . "file_docx.svg"; // for text document extensions + if (in_array($ext, $GLOBALS['ExtsSpreadsheet'])) return $path . "file_xlsx.svg"; // for spreadsheet extensions + if (in_array($ext, $GLOBALS['ExtsPresentation'])) return $path . "file_pptx.svg"; // for presentation extensions + return $path . "file_docx.svg"; +} + // get the document type function getDocumentType($filename) { $ext = strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION)); diff --git a/web/documentserver-example/php/doceditor.php b/web/documentserver-example/php/doceditor.php index e841f1a7..9eeb2e9c 100644 --- a/web/documentserver-example/php/doceditor.php +++ b/web/documentserver-example/php/doceditor.php @@ -62,6 +62,21 @@ $mode = $canEdit && $editorsMode != "view" ? "edit" : "view"; // define if the editing mode is edit or view $type = empty($_GET["type"]) ? "desktop" : $_GET["type"]; + $templatesImageUrl = getTemplateImageUrl($filename); // templates image url in the "From Template" section + $createUrl = getCreateUrl($filename, $user->id, $type); + $templates = array( + array ( + "image" => $templatesImageUrl, + "title" => "Blank", + "url" => $createUrl + ), + array ( + "image" => $templatesImageUrl, + "title" => "With sample content", + "url" => $createUrl . "&sample=true" + ) + ); + // specify the document config $config = [ "type" => $type, @@ -94,7 +109,8 @@ "mode" => $mode, "lang" => empty($_COOKIE["ulang"]) ? "en" : $_COOKIE["ulang"], "callbackUrl" => getCallbackUrl($filename), // absolute URL to the document storage service - "createUrl" => getCreateUrl($filename, $user->id, $type), + "createUrl" => $user->id != "uid-0" ? $createUrl : null, + "templates" => $user->templates ? $templates : null, "user" => [ // the user currently viewing or editing the document "id" => $user->id, "name" => $user->name, @@ -177,10 +193,10 @@ function getCreateUrl($fileName, $uid, $type) { $ext = trim(getInternalExtension($fileName),'.'); return serverPath(false) . '/' - . "doceditor.php" - . "?fileExt=" . $ext - . "&user=" . $uid - . "&type=" . $type; + . "doceditor.php" + . "?fileExt=" . $ext + . "&user=" . $uid + . "&type=" . $type; } function getDownloadUrl($fileName) { diff --git a/web/documentserver-example/php/users.php b/web/documentserver-example/php/users.php index 014503f5..1a583fac 100644 --- a/web/documentserver-example/php/users.php +++ b/web/documentserver-example/php/users.php @@ -18,7 +18,7 @@ */ class User { - function __construct($id, $name, $email, $group, $reviewGroups, $favorite, $deniedPermissions, $descriptions) + function __construct($id, $name, $email, $group, $reviewGroups, $favorite, $deniedPermissions, $descriptions, $templates) { $this->id = $id; $this->name = $name; @@ -28,6 +28,7 @@ class User { $this->favorite = $favorite; $this->deniedPermissions = $deniedPermissions; $this->descriptions = $descriptions; + $this->templates = $templates; } } @@ -62,10 +63,10 @@ $descr_user_0 = [ ]; $users = [ - new User("uid-1", "John Smith", "smith@mial.ru", null, null, null, [], $descr_user_1), - new User("uid-2", "Mark Pottato", "pottato@mial.ru", "group-2", ["group-2", ""], true, [], $descr_user_2), - new User("uid-3", "Hamish Mitchell", "mitchell@mial.ru", "group-3", ["group-2"], false, ["copy", "download", "print"], $descr_user_3), - new User("uid-0", null, null, null, null, null, [], $descr_user_0) + new User("uid-1", "John Smith", "smith@mial.ru", null, null, null, [], $descr_user_1, true), + new User("uid-2", "Mark Pottato", "pottato@mial.ru", "group-2", ["group-2", ""], true, [], $descr_user_2, false), + new User("uid-3", "Hamish Mitchell", "mitchell@mial.ru", "group-3", ["group-2"], false, ["copy", "download", "print"], $descr_user_3, false), + new User("uid-0", null, null, null, null, null, [], $descr_user_0, false) ]; function getAllUsers() {