Code

Added feature checking to distribution list
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Oct 2010 15:52:51 +0000 (15:52 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 11 Oct 2010 15:52:51 +0000 (15:52 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19984 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/groupware/admin/ogroups/DistributionList/class_DistributionList.inc
gosa-plugins/groupware/admin/ogroups/DistributionList/generic.tpl

index 0d08fa5009402ec716dfa1e316b0f21e96a90394..d8a0997bcaedf4874c52c2c1715028ea5cc6b817 100644 (file)
@@ -43,6 +43,16 @@ class DistributionList extends plugin
     }
 
 
+    /*! \brief      Check whether a feature is enabled or not.
+     *  @param      The feature name to check for
+     *  @return     TRUE on success else FALSE
+     */
+    function featureEnabled($name)
+    {
+        return(isset($this->featuresEnabled[$name]) && $this->featuresEnabled[$name]);
+    }
+
+
     /*! \brief      Try to initialize the plugin using a json-rpc connection
      *               to the gosa-ng server.
      */
@@ -117,27 +127,31 @@ class DistributionList extends plugin
             }
 
             // Load alternate mail address 
-            $alternateAddresses = $rpc->gwDistGetAlternateMailAddresses($this->orig_cn); 
-            if(!$rpc->success()){
-                $this->rpcError = TRUE;
-                $this->rpcErrorMessage = $rpc->get_error();
-                $message = sprintf(_("Failed to load alternate mail addresses for distribution list '%s'! Error was: '%s'."), 
-                        $this->orig_cn, $rpc->get_error());
-                msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
-                return;
+            if($this->featureEnabled('alternateAddresses')){
+                $alternateAddresses = $rpc->gwDistGetAlternateMailAddresses($this->orig_cn); 
+                if(!$rpc->success()){
+                    $this->rpcError = TRUE;
+                    $this->rpcErrorMessage = $rpc->get_error();
+                    $message = sprintf(_("Failed to load alternate mail addresses for distribution list '%s'! Error was: '%s'."), 
+                            $this->orig_cn, $rpc->get_error());
+                    msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+                    return;
+                }
             }
 
             // Load mail size limitation settings 
-            $mailSizeLimit = $rpc->gwDistGetMailLimit($this->orig_cn); 
-            if(!$rpc->success()){
-                $this->rpcError = TRUE;
-                $this->rpcErrorMessage = $rpc->get_error();
-                $message = sprintf(_("Failed to load mail size limit for distribution list '%s'! Error was: '%s'."), 
-                        $this->orig_cn, $rpc->get_error());
-                msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
-                return;
+            if($this->featureEnabled('mailSizeLimit')){
+                $mailSizeLimit = $rpc->gwDistGetMailLimit($this->orig_cn); 
+                if(!$rpc->success()){
+                    $this->rpcError = TRUE;
+                    $this->rpcErrorMessage = $rpc->get_error();
+                    $message = sprintf(_("Failed to load mail size limit for distribution list '%s'! Error was: '%s'."), 
+                            $this->orig_cn, $rpc->get_error());
+                    msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+                    return;
+                }
+                $mailSizeLimit = $mailSizeLimit['receive'];
             }
-            $mailSizeLimit = $mailSizeLimit['receive'];
         }
 
         // Store values as current and initial values (saved_attributes) 
@@ -256,6 +270,10 @@ class DistributionList extends plugin
             $smarty->assign("{$attr}ACL", $this->getacl($attr));
             $smarty->assign($attr, set_post($this->$attr));
         }
+        foreach(array('mailSizeLimit','alternateAddresses') as $feature){
+            $smarty->assign("{$feature}_isActive", $this->featureEnabled($feature));
+        }
+        
 
         $smarty->assign("useMailSizeLimit", ($this->mailSizeLimit != NULL));
         $smarty->assign("memberList", set_post($this->memberList));
@@ -399,33 +417,34 @@ class DistributionList extends plugin
         // Updated mail size limitations, if needed:  
         //  -> is a new distribution list or
         //  -> the value for 'mailSizeLimit' has changed.
-        if(!$this->initially_was_account || $this->mailSizeLimit != $this->saved_attributes['mailSizeLimit']){
-            $rpc->gwDistSetMailLimit($this->cn, $this->mailSizeLimit);
-            if(!$rpc->success()){
-                $message = sprintf(_("Failed to update mail size limitations for distribution list '%s'! Error was: '%s'."), 
-                        $this->cn, $rpc->get_error());
-                msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+        if($this->featureEnabled('mailSizeLimit')){
+            if(!$this->initially_was_account || $this->mailSizeLimit != $this->saved_attributes['mailSizeLimit']){
+                $rpc->gwDistSetMailLimit($this->cn, $this->mailSizeLimit);
+                if(!$rpc->success()){
+                    $message = sprintf(_("Failed to update mail size limitations for distribution list '%s'! Error was: '%s'."), 
+                            $this->cn, $rpc->get_error());
+                    msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+                }
             }
         }
 
         // Updated alternate mail addresses, if needed:  
         //  -> is a new distribution list or
         //  -> the value for 'alternateAddresses' has changed.
-        sort($this->alternateAddresses);
-        sort($this->saved_attributes['alternateAddresses']);
-        $changed = array_differs($this->alternateAddresses,$this->saved_attributes['alternateAddresses']);
-        if(!$this->initially_was_account || $changed){
-            $rpc->gwDistSetAlternateMailAddresses($this->cn, $this->alternateAddresses);
-            if(!$rpc->success()){
-                $message = sprintf(_("Failed to update alternate addresses for distribution list '%s'! Error was: '%s'."), 
-                        $this->cn, $rpc->get_error());
-                msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+        if($this->featureEnabled('alternateAddresses')){
+            sort($this->alternateAddresses);
+            sort($this->saved_attributes['alternateAddresses']);
+            $changed = array_differs($this->alternateAddresses,$this->saved_attributes['alternateAddresses']);
+            if(!$this->initially_was_account || $changed){
+                $rpc->gwDistSetAlternateMailAddresses($this->cn, $this->alternateAddresses);
+                if(!$rpc->success()){
+                    $message = sprintf(_("Failed to update alternate addresses for distribution list '%s'! Error was: '%s'."), 
+                            $this->cn, $rpc->get_error());
+                    msg_dialog::display(_("Error"),msgPool::rpcError($message), ERROR_DIALOG);
+                }
             }
         }
 
-        // Update member list       
-        $this->memberList = $this->getOgroupMemberList();
-
         // Check which accounts have valid groupware mail addresses.
         $uids = $this->getOgroupMemberList();
         $rpc = $this->config->getRpcHandle(); 
index 1f48768356350538972cc31c739b7d29fbe1d271..085ed73c18e80ba1e8c0740cec9164f349e2f8c8 100644 (file)
@@ -1,46 +1,50 @@
 
 <table summary="{t}Groupware{/t}" width="100%">
     <tr>
-        <td style='width:50%; vertical-align: top;' class='right-border'>
+        <td style='width:50%; vertical-align: top;'>
             <h3>{t}Groupware{/t}</h3>
 
             {t}Mail address{/t}:
             {render acl=$primaryMailAddressACL}
                 <input type='text' name="primaryMailAddress" value="{$primaryMailAddress}">
             {/render}
-            <hr>
 
-            {render acl=$mailSizeLimitACL}
-                <input type='checkbox' name="useMailSizeLimit" 
-                    onClick="changeState('mailSizeLimit')" 
-                    {if $useMailSizeLimit} checked {/if} value="1">
-            {/render}
-            {t}Use incoming mail size limitation{/t}
-            {render acl=$mailSizeLimitACL}
-                <input type='text' name='mailSizeLimit' id="mailSizeLimit" 
-                    {if $useMailSizeLimit} value="{$mailSizeLimit}" {else} value="" disabled {/if}>
-            {/render}
-        </td>
-        <td style='width:50%; vertical-align: top;'>
-            <h3><label for="alternateAddressList">{t}Alternative addresses{/t}</label></h3>
-            {render acl=$alternateAddressesACL}
-                <select id="alternateAddressList" style="width:100%;height:100px;" name="alternateAddressList[]" size="15" multiple
-                    title="{t}List of alternative mail addresses{/t}">
-                    {html_options values=$alternateAddresses output=$alternateAddresses}
-                    <option disabled>&nbsp;</option>
-                </select>
-                <br>
-            {/render}
-            {render acl=$alternateAddressesACL}
-                <input type='text' name="alternateAddressInput">
-            {/render}
-            {render acl=$alternateAddressesACL}
-                <button type='submit' name='addAlternateAddress'>{msgPool type=addButton}</button>
-            {/render}
-            {render acl=$alternateAddressesACL}
-                <button type='submit' name='deleteAlternateAddress'>{msgPool type=delButton}</button>
-            {/render}
+            {if $mailSizeLimit_isActive}
+                <hr>
+                {render acl=$mailSizeLimitACL}
+                    <input type='checkbox' name="useMailSizeLimit" 
+                        onClick="changeState('mailSizeLimit')" 
+                        {if $useMailSizeLimit} checked {/if} value="1">
+                {/render}
+                {t}Use incoming mail size limitation{/t}
+                {render acl=$mailSizeLimitACL}
+                    <input type='text' name='mailSizeLimit' id="mailSizeLimit" 
+                        {if $useMailSizeLimit} value="{$mailSizeLimit}" {else} value="" disabled {/if}>
+                {/render}
+            {/if}
         </td>
+        {if $alternateAddresses_isActive}
+            <td style='width:50%; vertical-align: top; padding-left:5px;' class='left-border'>
+                <h3><label for="alternateAddressList">{t}Alternative addresses{/t}</label></h3>
+                {render acl=$alternateAddressesACL}
+                    <select id="alternateAddressList" style="width:100%;height:100px;" name="alternateAddressList[]" size="15" multiple
+                        title="{t}List of alternative mail addresses{/t}">
+                        {html_options values=$alternateAddresses output=$alternateAddresses}
+                        <option disabled>&nbsp;</option>
+                    </select>
+                    <br>
+                {/render}
+                {render acl=$alternateAddressesACL}
+                    <input type='text' name="alternateAddressInput">
+                {/render}
+                {render acl=$alternateAddressesACL}
+                    <button type='submit' name='addAlternateAddress'>{msgPool type=addButton}</button>
+                {/render}
+                {render acl=$alternateAddressesACL}
+                    <button type='submit' name='deleteAlternateAddress'>{msgPool type=delButton}</button>
+                {/render}
+            </td>
+        {/if}
     </tr>
 </table>