Branch 'kolab-webadmin-3.0' - doc/kolab_wap-3.0.sql lib/api lib/client lib/kolab_client_task.php lib/kolab_form.php lib/kolab_html.php

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Tue Jun 25 16:04:14 CEST 2013


 doc/kolab_wap-3.0.sql                     |    4 ++--
 lib/api/kolab_api_service_user.php        |    7 +++++++
 lib/client/kolab_client_task_settings.php |    1 +
 lib/kolab_client_task.php                 |    4 ++++
 lib/kolab_form.php                        |    6 ++++++
 lib/kolab_html.php                        |   27 +++++++++++++++++++++++++++
 6 files changed, 47 insertions(+), 2 deletions(-)

New commits:
commit 97b097dc5042263a5cdba516367bc491c7f1c80e
Author: Timotheus Pokorra (Tbits.net) <tp at tbits.net>
Date:   Tue Jun 25 14:58:51 2013 +0100

    In Kolab 3, the mail quota is displayed in KB.
    A quota of 2 GB becomes 2*1024*1024 = 2097152
    This is quite difficult to read and to calculate as well.
    
    The attached patch finds the closest unit that works without cutting something off (only use the next unit if modulo is 0).
    
    The admin is presented a select box for KB, MB and GB.
    The value is displayed either in KB, MB or GB.
    When saving, the value is replaced again with the KB value, depending on the selected unit.
    
    See: https://issues.kolab.org/show_bug.cgi?id=1966
    
    Conflicts:
    	doc/kolab_wap-3.0.sql
    	doc/kolab_wap-3.1.sql

diff --git a/doc/kolab_wap-3.0.sql b/doc/kolab_wap-3.0.sql
index 4a3c231..6448412 100644
--- a/doc/kolab_wap-3.0.sql
+++ b/doc/kolab_wap-3.0.sql
@@ -136,9 +136,9 @@ CREATE TABLE IF NOT EXISTS `user_types` (
 --
 
 INSERT INTO `user_types` (`id`, `key`, `name`, `description`, `attributes`, `used_for`) VALUES
-(1, 'kolab', 'Kolab User', 'A Kolab User', '{"auto_form_fields":{"alias":{"type":"list","data":["givenname","preferredlanguage","sn"]},"cn":{"data":["givenname","sn"]},"displayname":{"data":["givenname","sn"]},"mail":{"data":["givenname","preferredlanguage","sn"]},"mailhost":{"optional":true},"uid":{"data":["givenname","preferredlanguage","sn"]},"userpassword":{"optional":true}},"form_fields":{"alias":{"optional":true},"givenname":[],"initials":{"optional":true},"kolabdelegate":{"type":"list","autocomplete":true,"optional":true},"kolabinvitationpolicy":{"type":"select","values":["","ACT_MANUAL","ACT_REJECT"],"optional":true},"kolaballowsmtprecipient":{"type":"list","optional":true},"kolaballowsmtpsender":{"type":"list","optional":true},"l":{"optional":true},"mailalternateaddress":{"type":"list","optional":true},"mailquota":{"optional":true},"mobile":{"optional":true},"nsroledn":{"type":"list","autocomplete":true,"optional":true},"o":{"optional":true},"ou":{"type":"select"},"
 pager":{"optional":true},"postalcode":{"optional":true},"preferredlanguage":{"type":"select"},"sn":[],"street":{"optional":true},"telephonenumber":{"optional":true},"title":{"optional":true},"userpassword":{"optional":true}},"fields":{"objectclass":["top","inetorgperson","kolabinetorgperson","mailrecipient","organizationalperson","person"]}}', NULL),
+(1, 'kolab', 'Kolab User', 'A Kolab User', '{"auto_form_fields":{"alias":{"type":"list","data":["givenname","preferredlanguage","sn"]},"cn":{"data":["givenname","sn"]},"displayname":{"data":["givenname","sn"]},"mail":{"data":["givenname","preferredlanguage","sn"]},"mailhost":{"optional":true},"uid":{"data":["givenname","preferredlanguage","sn"]},"userpassword":{"optional":true}},"form_fields":{"alias":{"optional":true},"givenname":[],"initials":{"optional":true},"kolabdelegate":{"type":"list","autocomplete":true,"optional":true},"kolabinvitationpolicy":{"type":"select","values":["","ACT_MANUAL","ACT_REJECT"],"optional":true},"kolaballowsmtprecipient":{"type":"list","optional":true},"kolaballowsmtpsender":{"type":"list","optional":true},"l":{"optional":true},"mailalternateaddress":{"type":"list","optional":true},"mailquota":{"type":"text-quota","optional":true},"mobile":{"optional":true},"nsroledn":{"type":"list","autocomplete":true,"optional":true},"o":{"optional":true},"ou"
 :{"type":"select"},"pager":{"optional":true},"postalcode":{"optional":true},"preferredlanguage":{"type":"select"},"sn":[],"street":{"optional":true},"telephonenumber":{"optional":true},"title":{"optional":true},"userpassword":{"optional":true}},"fields":{"objectclass":["top","inetorgperson","kolabinetorgperson","mailrecipient","organizationalperson","person"]}}', NULL),
 (2, 'posix', 'POSIX User', 'A POSIX user (with a home directory and shell access)', '{"auto_form_fields":{"cn":{"data":["givenname","sn"]},"displayname":{"data":["givenname","sn"]},"gidnumber":[],"homedirectory":{"data":["givenname","preferredlanguage","sn"]},"uid":{"data":["givenname","preferredlanguage","sn"]},"uidnumber":[],"userpassword":{"optional":true}},"form_fields":{"givenname":[],"initials":{"optional":true},"preferredlanguage":{"type":"select","values":["en_US","de_DE","de_CH","en_GB","fi_FI","fr_FR","hu_HU"]},"loginshell":{"type":"select","values":["/bin/bash","/usr/bin/git-shell","/sbin/nologin"]},"ou":{"type":"select"},"sn":[],"title":{"optional":true},"userpassword":{"optional":true}},"fields":{"objectclass":["top","inetorgperson","organizationalperson","person","posixaccount"]}}', NULL),
-(3, 'kolab_posix', 'Mail-enabled POSIX User', 'A mail-enabled POSIX User', '{"auto_form_fields":{"alias":{"data":["givenname","preferredlanguage","sn"]},"cn":{"data":["givenname","preferredlanguage","sn"]},"displayname":{"data":["givenname","preferredlanguage","sn"]},"gidnumber":[],"homedirectory":{"data":["givenname","preferredlanguage","sn"]},"mail":{"data":["givenname","preferredlanguage","sn"]},"mailhost":{"optional":true},"uid":{"data":["givenname","preferredlanguage","sn"]},"uidnumber":[],"userpassword":{"optional":true}},"form_fields":{"alias":{"optional":true},"givenname":[],"initials":{"optional":true},"kolabdelegate":{"type":"list","autocomplete":true,"optional":true},"kolabinvitationpolicy":{"type":"select","values":["","ACT_MANUAL","ACT_REJECT"],"optional":true},"kolaballowsmtprecipient":{"type":"list","optional":true},"kolaballowsmtpsender":{"type":"list","optional":true},"l":{"optional":true},"loginshell":{"type":"select","values":["/bin/bash","/usr/bin/git-she
 ll","/sbin/nologin"]},"mailalternateaddress":{"type":"list","optional":true},"mailquota":{"optional":true},"mobile":{"optional":true},"nsroledn":{"type":"list","autocomplete":true,"optional":true},"o":{"optional":true},"ou":{"type":"select"},"pager":{"optional":true},"postalcode":{"optional":true},"preferredlanguage":{"type":"select"},"sn":[],"street":{"optional":true},"telephonenumber":{"optional":true},"title":{"optional":true},"userpassword":{"optional":true}},"fields":{"objectclass":["top","inetorgperson","kolabinetorgperson","mailrecipient","organizationalperson","person","posixaccount"]}}', NULL);
+(3, 'kolab_posix', 'Mail-enabled POSIX User', 'A mail-enabled POSIX User', '{"auto_form_fields":{"alias":{"type":"list","data":["givenname","preferredlanguage","sn"]},"cn":{"data":["givenname","preferredlanguage","sn"]},"displayname":{"data":["givenname","preferredlanguage","sn"]},"gidnumber":[],"homedirectory":{"data":["givenname","preferredlanguage","sn"]},"mail":{"data":["givenname","preferredlanguage","sn"]},"mailhost":{"optional":true},"uid":{"data":["givenname","preferredlanguage","sn"]},"uidnumber":[],"userpassword":{"optional":true}},"form_fields":{"alias":{"optional":true},"givenname":[],"initials":{"optional":true},"kolabdelegate":{"type":"list","autocomplete":true,"optional":true},"kolabinvitationpolicy":{"type":"select","values":["","ACT_MANUAL","ACT_REJECT"],"optional":true},"kolaballowsmtprecipient":{"type":"list","optional":true},"kolaballowsmtpsender":{"type":"list","optional":true},"l":{"optional":true},"loginshell":{"type":"select","values":["/bin/bash","/u
 sr/bin/git-shell","/sbin/nologin"]},"mailalternateaddress":{"type":"list","optional":true},"mailquota":{"type":"text-quota","optional":true},"mobile":{"optional":true},"nsroledn":{"type":"list","autocomplete":true,"optional":true},"o":{"optional":true},"ou":{"type":"select"},"pager":{"optional":true},"postalcode":{"optional":true},"preferredlanguage":{"type":"select"},"sn":[],"street":{"optional":true},"telephonenumber":{"optional":true},"title":{"optional":true},"userpassword":{"optional":true}},"fields":{"objectclass":["top","inetorgperson","kolabinetorgperson","mailrecipient","organizationalperson","person","posixaccount"]}}', NULL);
 
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 578e102..3da41bd 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -128,6 +128,13 @@ class kolab_api_service_user extends kolab_api_service
     {
         //console("\$postdata to user_edit()", $postdata);
 
+        if ($postdata['mailquota-unit'] == 'gb') {
+            $postdata['mailquota'] *= 1024*1024;
+        }
+        if ($postdata['mailquota-unit'] == 'mb') {
+            $postdata['mailquota'] *= 1024;
+        }
+
         $user_attributes = $this->parse_input_attributes('user', $postdata);
         $user            = $postdata['id'];
 
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index ec55c73..8b1bba5 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -33,6 +33,7 @@ class kolab_client_task_settings extends kolab_client_task
 
     protected $form_element_types = array(
         'text', 'select', 'multiselect', 'list', 'list-autocomplete', 'checkbox', 'password', 'ldap_url',
+        'text-quota',
     );
 
 
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 8583e01..72dfd31 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -849,6 +849,10 @@ class kolab_client_task
             }
             break;
 
+        case 'text-quota':
+            $result['type'] = kolab_form::INPUT_TEXTQUOTA;
+            break;
+
         default:
             $result['type'] = kolab_form::INPUT_TEXT;
             if (isset($field['maxlength'])) {
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index 353d993..2fe3e9c 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -38,6 +38,7 @@ class kolab_form
     const INPUT_HIDDEN   = 9;
     const INPUT_CUSTOM   = 10;
     const INPUT_CONTENT  = 20;
+    const INPUT_TEXTQUOTA = 30;
 
     const TYPE_LIST = 1;
 
@@ -277,6 +278,11 @@ class kolab_form
             $content = kolab_html::input($attribs);
             break;
 
+        case self::INPUT_TEXTQUOTA:
+            $attribs['type'] = 'text';
+            $content = kolab_html::inputquota($attribs);
+            break;
+
         case self::INPUT_CHECKBOX:
             $attribs['type'] = 'checkbox';
             $content = kolab_html::input($attribs);
diff --git a/lib/kolab_html.php b/lib/kolab_html.php
index 33bc705..c0ef529 100644
--- a/lib/kolab_html.php
+++ b/lib/kolab_html.php
@@ -154,6 +154,33 @@ class kolab_html
     }
 
     /**
+     * Input element for mail quota. user can select the unit (GB, MB)
+     *
+     * @param array  $attribs  Element attributes
+     *
+     * @return string HTML output of the input
+     */
+    public static function inputquota($attribs = array())
+    {
+        $elem_attribs = array_merge(self::$input_attribs, self::$input_event_attribs,
+            self::$common_attribs, self::$event_attribs);
+        $selected_option_mb = $selected_option_gb = "";
+        $selected_option_kb = "selected";
+        if ($attribs['value'] >= 1024 && $attribs['value'] % 1024 == 0) {
+            $attribs['value'] /= 1024;
+            $selected_option_kb = "";
+            $selected_option_mb = "selected";
+        }
+        if ($attribs['value'] >= 1024 && $attribs['value'] % 1024 == 0) {
+            $attribs['value'] /= 1024;
+            $selected_option_mb = "";
+            $selected_option_gb = "selected";
+        }
+
+        return sprintf('<input%s /><select name="%s-unit"><option value="kb" %s>KB</option><option value="mb" %s>MB</option><option value="gb" %s>GB</option></select>', self::attrib_string($attribs, $elem_attribs), $attribs['name'], $selected_option_kb, $selected_option_mb, $selected_option_gb);
+    }
+
+    /**
      * Textarea element.
      *
      * @param array $attribs  Element attributes





More information about the commits mailing list