diff --git a/classes/api.php b/classes/api.php
index c5fafd9..60fdf4f 100644
--- a/classes/api.php
+++ b/classes/api.php
@@ -190,6 +190,71 @@ private function get_user() {
return \core_user::get_user($this->userid);
}
+ private function get_watermark_text() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_hide_print() {
+ return false;
+ }
+
+ private function get_hide_save() {
+ return false;
+ }
+
+ private function get_hide_export() {
+ return false;
+ }
+
+ private function get_enable_owner_termination() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'enable_owner_termination', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_disable_print() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'disable_print', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_disable_export() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'disable_export', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_disable_copy() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'disable_copy', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_enable_insert_remote_image() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->docrecord->id]);
+ }
+
+ // If set to 'true', the user-list on the status bar will be hidden.
+ // If set to 'mobile' | 'tablet' | 'desktop', it will be hidden on the
+ // specified device(s) only (multiples values can be delimited by comma,
+ // e.g. 'mobile,tablet').
+ private function get_hide_user_list() {
+ return 'false';
+ }
+
+ private function get_disable_change_tracking_record() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_disable_change_tracking_show() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->docrecord->id]);
+ }
+
+ private function get_hide_change_tracking_controls() {
+ global $DB;
+ return $DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->docrecord->id]);
+ }
+
/**
* Handle getfile requests.
*/
@@ -234,7 +299,21 @@ private function handle_checkfileinfo() {
'UserCanWrite' => !$this->is_readonly(),
'UserCanNotWriteRelative' => true,
'LastModifiedTime' => date('c', $file->get_timemodified()),
+ 'WatermarkText' => $this->get_watermark_text(),
+ 'HidePrintOption' => $this->get_hide_print(),
+ 'HideSaveOption' => $this->get_hide_save(),
+ 'HideExportOption' => $this->get_hide_export(),
+ 'EnableOwnerTermination' => $this->get_enable_owner_termination(),
+ 'DisablePrint' => $this->get_disable_print(),
+ 'DisableExport' => $this->get_disable_export(),
+ 'DisableCopy' => $this->get_disable_copy(),
+ 'EnableInsertRemoteImage' => $this->get_enable_insert_remote_image(),
+ 'HideUserList' => $this->get_hide_user_list(),
+ 'DisableChangeTrackingRecord' => $this->get_disable_change_tracking_record(),
+ 'DisableChangeTrackingShow' => $this->get_disable_change_tracking_show(),
+ 'HideChangeTrackingControls' => $this->get_hide_change_tracking_controls(),
];
+
die(json_encode($ret));
}
}
diff --git a/classes/collabora.php b/classes/collabora.php
index 278fd6f..b19a423 100644
--- a/classes/collabora.php
+++ b/classes/collabora.php
@@ -118,19 +118,8 @@ public function process_lock_unlock() {
if (!$this->can_lock_unlock()) {
return;
}
- $lock = optional_param('lock', null, PARAM_INT);
- if ($lock !== $this->groupid) {
- $lock = null;
- }
- $unlock = optional_param('unlock', null, PARAM_INT);
- if ($unlock !== $this->groupid) {
- $unlock = null;
- }
- if ($lock === null && $unlock === null) {
- return;
- }
require_sesskey();
- $locked = ($lock !== null) ? 1 : 0;
+ $locked = optional_param('locked', null, PARAM_INT) ? 1 : 0;
$this->document->locked = $locked;
$DB->set_field('collabora_document', 'locked', $locked, ['id' => $this->document->id]);
if ($locked) {
@@ -365,6 +354,182 @@ public function get_lock_icon() {
return $OUTPUT->render_from_template('mod_collabora/lockicon', $data);
}
+ public function get_settings_panel($cmid) {
+ global $PAGE, $OUTPUT, $DB;
+ $canupdate = $this->can_lock_unlock();
+ $islocked = $this->is_locked();
+ $url = null;
+ if ($canupdate) {
+ $params = ['sesskey' => sesskey()];
+ if ($islocked) {
+ $params['unlock'] = $this->groupid;
+ } else {
+ $params['lock'] = $this->groupid;
+ }
+
+ $url = new \moodle_url($PAGE->url);
+ }
+
+ $hideuserslist = $DB->get_field('collabora_document', 'hide_user_list', ['id' => $this->document->id]);
+ $labelstyle = '';
+
+ $data = (object)[
+ 'canupdate' => $this->can_lock_unlock(),
+ 'islocked' => $islocked,
+ 'url' => $PAGE->url,
+ 'id' => $cmid,
+ 'sesskey' => sesskey(),
+ 'fieldsets' => [
+ [
+ 'title' => get_string('docsetting_security_title', 'mod_collabora'),
+ 'fields' => [
+ [
+ 'name' => 'locked',
+ 'type' => 'checkbox',
+ 'checked' => $DB->get_field('collabora_document', 'locked', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => '1',
+ 'label' => get_string('docsetting_locked_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_locked_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_no', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'disableprint',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'disable_print', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_disableprint_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_disableprint_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'disableexport',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'disable_export', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_disableexport_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_disableexport_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'disablecopy',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'disable_copy', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_disablecopy_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_disablecopy_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'remoteimage',
+ 'hide' => 'true',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => 'Enable Inserting Remote Images',
+ 'labelstyle' => $labelstyle,
+ 'tip' => 'Enable/Disable users to insert remote images.',
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'watermark',
+ 'type' => 'editbox',
+ 'value' => $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->document->id]),
+ 'widgetstyle' => 'max-width:100% !important',
+ 'label' => get_string('docsetting_watermark_label', 'mod_collabora'),
+ 'tip' => get_string('docsetting_watermark_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_blank', 'mod_collabora'),
+ ],
+ ],
+ ],
+
+ [
+ 'title' => get_string('docsetting_changetracking_title', 'mod_collabora'),
+ 'fields' => [
+ [
+ 'name' => 'disablechangerecord',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_disablechangerecord_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_disablechangerecord_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'disablechangeshow',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_disablechangeshow_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_disablechangeshow_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ [
+ 'name' => 'hidechangecontrols',
+ 'type' => 'checkbox',
+ 'checked' => !$DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->document->id]) ? 'checked' : '',
+ 'value' => 'true',
+ 'label' => get_string('docsetting_hidechangecontrols_label', 'mod_collabora'),
+ 'labelstyle' => $labelstyle,
+ 'tip' => get_string('docsetting_hidechangecontrols_tip', 'mod_collabora'),
+ 'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
+ ],
+ ],
+ ],
+ ],
+ ];
+
+ return $OUTPUT->render_from_template('mod_collabora/settings_panel', $data);
+ }
+
+ public function process_document_settings() {
+ global $DB, $PAGE;
+ if (!$this->can_lock_unlock()) {
+ return;
+ }
+ $sesskey = optional_param('sesskey', null, PARAM_TEXT);
+ if ($sesskey === null) {
+ return;
+ }
+
+ require_sesskey();
+
+ $disableprint = !optional_param('disableprint', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'disable_print', $disableprint, ['id' => $this->document->id]);
+
+ $disableexport = !optional_param('disableexport', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'disable_export', $disableexport, ['id' => $this->document->id]);
+
+ $disablecopy = !optional_param('disablecopy', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'disable_copy', $disablecopy, ['id' => $this->document->id]);
+
+ $disablechangerecord = !optional_param('disablechangerecord', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'disable_change_tracking_record', $disablechangerecord, ['id' => $this->document->id]);
+
+ $disablechangeshow = !optional_param('disablechangeshow', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'disable_change_tracking_show', $disablechangeshow, ['id' => $this->document->id]);
+
+ $hidechangecontrols = !optional_param('hidechangecontrols', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'hide_change_tracking_controls', $hidechangecontrols, ['id' => $this->document->id]);
+
+ $ownertermination = optional_param('ownertermination', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'enable_owner_termination', $ownertermination, ['id' => $this->document->id]);
+
+ $remoteimage = !optional_param('remoteimage', null, PARAM_TEXT) ? 1 : 0;
+ $DB->set_field('collabora_document', 'enable_insert_remote_image', $remoteimage, ['id' => $this->document->id]);
+
+ $watermark = optional_param('watermark', null, PARAM_TEXT);
+ $DB->set_field('collabora_document', 'watermark_text', $watermark, ['id' => $this->document->id]);
+
+ // Process the lock state and reload.
+ $this->process_lock_unlock();
+ }
+
/**
* Choose an appropriate filetype icon based on the mimetype.
* @return string|false Icon URL to be used in `cached_cm_info` or false if there is no appropriate icon.
diff --git a/db/install.xml b/db/install.xml
index 89eda41..190f2cd 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -1,5 +1,5 @@
-
@@ -31,7 +31,16 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -54,4 +63,4 @@
-
\ No newline at end of file
+
diff --git a/db/upgrade.php b/db/upgrade.php
index cb91d5a..19d8225 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -24,5 +24,60 @@
defined('MOODLE_INTERNAL') || die();
function xmldb_collabora_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
+ if ($oldversion < 2020091300) {
+
+ $table = new xmldb_table('collabora_document');
+
+ $field = new xmldb_field('watermark_text', XMLDB_TYPE_CHAR, '127', null, null, null, null, 'locked');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('enable_owner_termination', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'watermark_text');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('disable_print', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_owner_termination');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('disable_export', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_print');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('disable_copy', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_export');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('enable_insert_remote_image', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_copy');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('disable_change_tracking_record', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_insert_remote_image');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('disable_change_tracking_show', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_record');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ $field = new xmldb_field('hide_change_tracking_controls', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_show');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Collabora savepoint reached.
+ upgrade_mod_savepoint(true, 2020091300, 'collabora');
+ }
+
return true;
}
diff --git a/lang/en/collabora.php b/lang/en/collabora.php
index 4652d4e..128b57c 100644
--- a/lang/en/collabora.php
+++ b/lang/en/collabora.php
@@ -66,6 +66,33 @@
$string['unlockedlock'] = 'Document currently unlocked, click here to lock it and prevent editing';
$string['width'] = 'Width (0 for automatic)';
$string['wordprocessor'] = 'Wordprocessor document';
+$string['document_settings'] = 'Document settings';
+$string['docsetting_disableprint_label'] = 'Allow Printing';
+$string['docsetting_disableprint_tip'] = 'Disable/Enable the print commands from the UI.';
+$string['docsetting_disableexport_label'] = 'Allow Exporting';
+$string['docsetting_disableexport_tip'] = 'Disable/Enable the export commands from the UI.';
+$string['docsetting_disablecopy_label'] = 'Allow Copying Externally';
+$string['docsetting_disablecopy_tip'] = 'Disable/Enable copying from the document externally. Internal copy/paste are always allowed.';
+$string['docsetting_changetracking_title'] = 'Change Tracking';
+$string['docsetting_disablechangerecord_label'] = 'Enable Change Tracking';
+$string['docsetting_disablechangerecord_tip'] = 'Disable/Enable recording changes.';
+$string['docsetting_disablechangeshow_label'] = 'Show Changes';
+$string['docsetting_disablechangeshow_tip'] = 'Hide/Show change-tracking changes.';
+$string['docsetting_hidechangecontrols_label'] = 'Show Change Tracking Controls';
+$string['docsetting_hidechangecontrols_tip'] = 'Hide/Show change-tracking controls and the ability to modify change-tracking settings.';
+$string['docsetting_locked_label'] = 'Lock Document';
+$string['docsetting_locked_tip'] = 'Lock/Unlock the document to restrict editing or allow for all.';
+$string['docsetting_ownertermination_label'] = 'Enable Owner Termination';
+$string['docsetting_ownertermination_tip'] = 'Enable/Disable owner termination, which automatically closes the document for all users when the owner does.';
+$string['docsetting_watermarking_title'] = 'Watermarking';
+$string['docsetting_watermark_label'] = 'Watermark Text';
+$string['docsetting_watermark_tip'] = 'Set a watermark text to show on the document.';
+$string['docsetting_security_title'] = 'Security';
+$string['docsetting_default_yes'] = 'Default: Yes';
+$string['docsetting_default_no'] = 'Default: No';
+$string['docsetting_default_blank'] = 'Default: Blank';
+
+// $string[''] = '';
// Privacy API.
$string['privacy:metadata:core_files'] = 'mod_collabora stores the collaborative files.';
$string['privacy:metadata:collabora_extsystem'] = 'File infos and content are shared with Collabora to allow collaborative work';
diff --git a/version.php b/version.php
index d810a15..bd62eb7 100644
--- a/version.php
+++ b/version.php
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2020090100;
+$plugin->version = 2020091300;
$plugin->requires = 2018051700; // M3.5.
$plugin->component = 'mod_collabora';
$plugin->maturity = MATURITY_STABLE;
diff --git a/view.php b/view.php
index a2d60a7..d248b5a 100644
--- a/view.php
+++ b/view.php
@@ -66,7 +66,7 @@
// Load the collabora details for this page.
$collabora = new \mod_collabora\collabora($rec, $PAGE->context, $groupid, $USER->id);
-$collabora->process_lock_unlock();
+$collabora->process_document_settings();
// Set up the page.
$PAGE->set_title($rec->name);
@@ -107,7 +107,10 @@
if ($groupid >= 0) {
groups_print_activity_menu($cm, $PAGE->url, false, true);
- echo $collabora->get_lock_icon();
+ if ($collabora->can_lock_unlock()) {
+ print_collapsible_region($collabora->get_settings_panel($cmid), 'collabora', 'documentsettings', get_string('document_settings', 'mod_collabora'), '', true);
+ }
+
echo '
';
$viewurl = $collabora->get_view_url();