public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
[Web] Fix implementation of multiple bookings for resources, fixes #1358
2ee983c1
data/web/edit.php | 17 +++++++++-----
data/web/inc/functions.mailbox.inc.php | 15 ++++++++-----
data/web/inc/init_db.inc.php | 4 ++--
data/web/js/edit.js | 17 +++++++++++++-
data/web/js/mailbox.js | 9 +++++++-
data/web/lang/lang.de.php | 6 +++++
data/web/lang/lang.en.php | 6 +++++
data/web/mailbox.php | 6 +++++
data/web/modals/mailbox.php | 41 +++++++++++++++++++++++++++++-----
9 files changed, 100 insertions(+), 21 deletions(-)
Diff
diff --git a/data/web/edit.php b/data/web/edit.php
index b2f6c27e..b7f65e40 100644
--- a/data/web/edit.php
+++ b/data/web/edit.php
@@ -572,7 +572,6 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<h4><?=$lang['edit']['resource'];?></h4>
<form class="form-horizontal" role="form" method="post" data-id="editresource">
<input type="hidden" value="0" name="active">
- <input type="hidden" value="0" name="multiple_bookings">
<div class="form-group">
<label class="control-label col-sm-2" for="description"><?=$lang['add']['description'];?></label>
<div class="col-sm-10">
@@ -590,16 +589,24 @@ if (isset($_SESSION['mailcow_cc_role'])) {
</div>
</div>
<div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <div class="checkbox">
- <label><input type="checkbox" value="1" name="active" <?=($result['active_int']=="1") ? "checked" : null;?>> <?=$lang['edit']['active'];?></label>
+ <label class="control-label col-sm-2" for="multiple_bookings_select"><?=$lang['add']['multiple_bookings'];?>:</label>
+ <div class="col-sm-10">
+ <select name="multiple_bookings_select" id="multiple_bookings_select" title="<?=$lang['add']['select'];?>" required>
+ <option value="0" <?=($result['multiple_bookings'] == 0) ? "selected" : null;?>><?=$lang['mailbox']['booking_0'];?></option>
+ <option value="-1" <?=($result['multiple_bookings'] == -1) ? "selected" : null;?>><?=$lang['mailbox']['booking_lt0'];?></option>
+ <option value="custom" <?=($result['multiple_bookings'] >= 1) ? "selected" : null;?>><?=$lang['mailbox']['booking_custom'];?></option>
+ </select>
+ <div style="display:none" id="multiple_bookings_custom_div">
+ <hr>
+ <input type="number" class="form-control" name="multiple_bookings_custom" id="multiple_bookings_custom" value="<?=($result['multiple_bookings'] >= 1) ? $result['multiple_bookings'] : null;?>">
</div>
+ <input type="hidden" name="multiple_bookings" id="multiple_bookings">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
- <label><input type="checkbox" value="1" name="multiple_bookings" <?=($result['multiple_bookings_int']=="1") ? "checked" : null;?>> <?=$lang['edit']['multiple_bookings'];?></label>
+ <label><input type="checkbox" value="1" name="active" <?=($result['active_int']=="1") ? "checked" : null;?>> <?=$lang['edit']['active'];?></label>
</div>
</div>
</div>
diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php
index 18db3fa9..a37f5e78 100644
--- a/data/web/inc/functions.mailbox.inc.php
+++ b/data/web/inc/functions.mailbox.inc.php
@@ -945,8 +945,8 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
$local_part = preg_replace('/[^\da-z]/i', '', preg_quote($description, '/'));
$name = $local_part . '@' . $domain;
$kind = $_data['kind'];
+ $multiple_bookings = intval($_data['multiple_bookings']);
$active = intval($_data['active']);
- $multiple_bookings = intval($_data['multiple_bookings']);
if (!filter_var($name, FILTER_VALIDATE_EMAIL)) {
$_SESSION['return'] = array(
'type' => 'danger',
@@ -961,7 +961,9 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
);
return false;
}
-
+ if (!isset($multiple_bookings) || $multiple_bookings < -1) {
+ $multiple_bookings = -1;
+ }
if ($kind != 'location' && $kind != 'group' && $kind != 'thing') {
$_SESSION['return'] = array(
'type' => 'danger',
@@ -2184,7 +2186,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
$is_now = mailbox('get', 'resource_details', $name);
if (!empty($is_now)) {
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
- $multiple_bookings = (isset($_data['multiple_bookings'])) ? intval($_data['multiple_bookings']) : $is_now['multiple_bookings_int'];
+ $multiple_bookings = (isset($_data['multiple_bookings'])) ? intval($_data['multiple_bookings']) : $is_now['multiple_bookings'];
$description = (!empty($_data['description'])) ? $_data['description'] : $is_now['description'];
$kind = (!empty($_data['kind'])) ? $_data['kind'] : $is_now['kind'];
}
@@ -2202,6 +2204,9 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
);
return false;
}
+ if (!isset($multiple_bookings) || $multiple_bookings < -1) {
+ $multiple_bookings = -1;
+ }
if (empty($description)) {
$_SESSION['return'] = array(
'type' => 'danger',
@@ -3133,10 +3138,9 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
`username`,
`name`,
`kind`,
- `multiple_bookings` AS `multiple_bookings_int`,
+ `multiple_bookings`,
`local_part`,
`active` AS `active_int`,
- CASE `multiple_bookings` WHEN 1 THEN '".$lang['mailbox']['yes']."' ELSE '".$lang['mailbox']['no']."' END AS `multiple_bookings`,
CASE `active` WHEN 1 THEN '".$lang['mailbox']['yes']."' ELSE '".$lang['mailbox']['no']."' END AS `active`,
`domain`
FROM `mailbox` WHERE `kind` REGEXP 'location|thing|group' AND `username` = :resource");
@@ -3147,7 +3151,6 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
$resourcedata['name'] = $row['username'];
$resourcedata['kind'] = $row['kind'];
$resourcedata['multiple_bookings'] = $row['multiple_bookings'];
- $resourcedata['multiple_bookings_int'] = $row['multiple_bookings_int'];
$resourcedata['description'] = $row['name'];
$resourcedata['active'] = $row['active'];
$resourcedata['active_int'] = $row['active_int'];
diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php
index 8ece750c..20f12eb0 100644
--- a/data/web/inc/init_db.inc.php
+++ b/data/web/inc/init_db.inc.php
@@ -3,7 +3,7 @@ function init_db_schema() {
try {
global $pdo;
- $db_version = "06052018_1239";
+ $db_version = "06052018_1839";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@@ -191,7 +191,7 @@ function init_db_schema() {
"domain" => "VARCHAR(255) NOT NULL",
"attributes" => "JSON",
"kind" => "VARCHAR(100) NOT NULL DEFAULT ''",
- "multiple_bookings" => "TINYINT(1) NOT NULL DEFAULT '0'",
+ "multiple_bookings" => "INT NOT NULL DEFAULT -1",
"created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
"modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
"active" => "TINYINT(1) NOT NULL DEFAULT '1'"
diff --git a/data/web/js/edit.js b/data/web/js/edit.js
index fbd5deca..8cf0889c 100644
--- a/data/web/js/edit.js
+++ b/data/web/js/edit.js
@@ -12,7 +12,22 @@ $(document).ready(function() {
});
$("#script_data").numberedtextarea({allowTabChar: true});
});
-
+if ($("#multiple_bookings_select").val() == "custom") {
+ $("#multiple_bookings_custom_div").show();
+ $("#multiple_bookings").val($("#multiple_bookings_custom").val());
+}
+$("#multiple_bookings_select").change(function() {
+ $("#multiple_bookings").val($("#multiple_bookings_select").val());
+ if ($("#multiple_bookings").val() == "custom") {
+ $("#multiple_bookings_custom_div").show();
+ }
+ else {
+ $("#multiple_bookings_custom_div").hide();
+ }
+});
+$("#multiple_bookings_custom").bind("change keypress keyup blur", function() {
+ $("#multiple_bookings").val($("#multiple_bookings_custom").val());
+});
jQuery(function($){
// http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
function validateEmail(email) {
diff --git a/data/web/js/mailbox.js b/data/web/js/mailbox.js
index 513f0d95..3bd75262 100644
--- a/data/web/js/mailbox.js
+++ b/data/web/js/mailbox.js
@@ -294,7 +294,7 @@ jQuery(function($){
{"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
{"name":"kind","title":lang.kind},
{"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
- {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
+ {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
{"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
{"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
],
@@ -308,6 +308,13 @@ jQuery(function($){
},
success: function (data) {
$.each(data, function (i, item) {
+ if (item.multiple_bookings == '0') {
+ item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
+ } else if (item.multiple_bookings == '-1') {
+ item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
+ } else {
+ item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
+ }
item.action = '<div class="btn-group">' +
'<a href="/edit.php?resource=' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
'<a href="#" id="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php
index 2f508e53..efa3310b 100644
--- a/data/web/lang/lang.de.php
+++ b/data/web/lang/lang.de.php
@@ -185,6 +185,12 @@ $lang['header']['mailcow_settings'] = 'Konfiguration';
$lang['header']['administration'] = 'Administration';
$lang['header']['mailboxes'] = 'Mailboxen';
$lang['header']['user_settings'] = 'Benutzereinstellungen';
+$lang['mailbox']['booking_0'] = 'Immer als verfügbar anzeigen';
+$lang['mailbox']['booking_lt0'] = 'Unbegrenzt, jedoch anzeigen, wenn gebucht';
+$lang['mailbox']['booking_custom'] = 'Benutzerdefiniertes Limit';
+$lang['mailbox']['booking_0_short'] = 'Immer verfügbar';
+$lang['mailbox']['booking_lt0_short'] = 'Weiches Limit';
+$lang['mailbox']['booking_custom_short'] = 'Hartes Limit';
$lang['mailbox']['domain'] = 'Domain';
$lang['mailbox']['spam_aliases'] = 'Temp. Alias';
$lang['mailbox']['alias'] = 'Alias';
diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php
index 6a0d7419..01fbca00 100644
--- a/data/web/lang/lang.en.php
+++ b/data/web/lang/lang.en.php
@@ -183,6 +183,12 @@ $lang['header']['mailcow_settings'] = 'Configuration';
$lang['header']['administration'] = 'Administration';
$lang['header']['mailboxes'] = 'Mailboxes';
$lang['header']['user_settings'] = 'User settings';
+$lang['mailbox']['booking_0'] = 'Always show as free';
+$lang['mailbox']['booking_lt0'] = 'Unlimited, but show as busy when booked';
+$lang['mailbox']['booking_custom'] = 'Hard-limit to a custom amount of bookings';
+$lang['mailbox']['booking_0_short'] = 'Always free';
+$lang['mailbox']['booking_lt0_short'] = 'Soft limit';
+$lang['mailbox']['booking_custom_short'] = 'Hard limit';
$lang['mailbox']['domain'] = 'Domain';
$lang['mailbox']['spam_aliases'] = 'Temp. alias';
$lang['mailbox']['multiple_bookings'] = 'Multiple bookings';
diff --git a/data/web/mailbox.php b/data/web/mailbox.php
index 73a628c4..58a569dd 100644
--- a/data/web/mailbox.php
+++ b/data/web/mailbox.php
@@ -100,6 +100,12 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
<a class="btn btn-sm btn-success" href="#" data-toggle="modal" data-target="#addResourceModal"><span class="glyphicon glyphicon-plus"></span> <?=$lang['mailbox']['add_resource'];?></a>
</div>
</div>
+ <hr>
+ <div class="panel-body help-block">
+ <p><span class="label label-success"><?=$lang['mailbox']['booking_0_short'];?></span> - <?=$lang['mailbox']['booking_0'];?></p>
+ <p><span class="label label-warning"><?=$lang['mailbox']['booking_lt0_short'];?></span> - <?=$lang['mailbox']['booking_lt0'];?></p>
+ <p><span class="label label-danger"><?=$lang['mailbox']['booking_custom_short'];?></span> - <?=$lang['mailbox']['booking_custom'];?></p>
+ </div>
</div>
</div>
diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php
index 2f4e010c..c593ef95 100644
--- a/data/web/modals/mailbox.php
+++ b/data/web/modals/mailbox.php
@@ -192,16 +192,24 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</div>
</div>
<div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <div class="checkbox">
- <label><input type="checkbox" value="1" name="active" checked> <?=$lang['add']['active'];?></label>
- </div>
+ <label class="control-label col-sm-2" for="multiple_bookings_select"><?=$lang['add']['multiple_bookings'];?>:</label>
+ <div class="col-sm-10">
+ <select name="multiple_bookings_select" id="multiple_bookings_select" title="<?=$lang['add']['select'];?>" required>
+ <option value="0"><?=$lang['mailbox']['booking_0'];?></option>
+ <option value="-1" selected><?=$lang['mailbox']['booking_lt0'];?></option>
+ <option value="custom"><?=$lang['mailbox']['booking_custom'];?></option>
+ </select>
+ <div style="display:none" id="multiple_bookings_custom_div">
+ <hr>
+ <input type="number" class="form-control" name="multiple_bookings_custom" id="multiple_bookings_custom">
+ </div>
+ <input type="hidden" name="multiple_bookings" id="multiple_bookings">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
- <label><input type="checkbox" value="1" name="multiple_bookings" checked> <?=$lang['add']['multiple_bookings'];?></label>
+ <label><input type="checkbox" value="1" name="active" checked> <?=$lang['add']['active'];?></label>
</div>
</div>
</div>
@@ -656,4 +664,25 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</div>
</div>
</div>
-</div><!-- DNS info modal -->
\ No newline at end of file
+</div><!-- DNS info modal -->
+<script>
+$('#addResourceModal').on('shown.bs.modal', function() {
+ $("#multiple_bookings").val($("#multiple_bookings_select").val());
+ if ($("#multiple_bookings").val() == "custom") {
+ $("#multiple_bookings_custom_div").show();
+ $("#multiple_bookings").val($("#multiple_bookings_custom").val());
+ }
+})
+$("#multiple_bookings_select").change(function() {
+ $("#multiple_bookings").val($("#multiple_bookings_select").val());
+ if ($("#multiple_bookings").val() == "custom") {
+ $("#multiple_bookings_custom_div").show();
+ }
+ else {
+ $("#multiple_bookings_custom_div").hide();
+ }
+});
+$("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
+ $("#multiple_bookings").val($("#multiple_bookings_custom").val());
+});
+</script>
\ No newline at end of file