Code

Set DNS hidden if acount is disabled
[gosa.git] / plugins / personal / connectivity / class_kolabAccount.inc
index aadc9cd34e4b42f90e2865f3ba1a80b5d251f713..2b5ae71c864e4d6a8fca2f7367dc92493ea134f6 100644 (file)
@@ -11,32 +11,44 @@ class kolabAccount extends plugin
   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* Kolab attributes */
-  var $kolabInvitationPolicy= "ACT_MANUAL";
+  var $kolabInvitationPolicy= array();
   var $kolabFreeBusyFuture= 60;
   var $unrestrictedMailSize= 0;
   var $calFBURL= "";
   var $kolabDelegate= array();
 
   /* attribute list for save action */
-  var $attributes= array( "kolabInvitationPolicy", "kolabFreeBusyFuture",
-                          "unrestrictedMailSize", "calFBURL");
-  var $objectclasses= array();
+  var $attributes= array( "kolabFreeBusyFuture", "unrestrictedMailSize", "calFBURL");
+  var $objectclasses= array("kolab");
+
+  /* Helper */
+  var $imapping= array();
 
   function kolabAccount ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
 
-    /* Pull delegation array */
-    if (isset($this->attrs["kolabDelegate"]["count"])){
-      for ($i= 0; $i<$this->attrs["kolabDelegate"]["count"]; $i++){
-        array_push($this->kolabDelegate, $this->attrs["kolabDelegate"][$i]);
+    /* Pull arrays */
+    foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
+      if (isset($this->attrs["$attr"]["count"])){
+        for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
+          array_push($this->$attr, $this->attrs["$attr"][$i]);
+        }
       }
     }
 
+    /* If this one is empty, preset with ACT_MANUAL for anonymous users */
+    if (count ($this->kolabInvitationPolicy) == 0){
+       $this->kolabInvitationPolicy= array("ACT_MANUAL");
+    }
+
   }
 
   function execute()
   {
+       /* Call parent execute */
+//     plugin::execute();
+
     /* Show tab dialog headers */
     $display= "";
 
@@ -49,6 +61,38 @@ class kolabAccount extends plugin
       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
     }
 
+    /* Check for invitation action */
+    $nr= 0;
+    while (isset($_POST["policy$nr"])){
+      if (isset($_POST["add$nr"])){
+        $this->kolabInvitationPolicy[]= ": ACT_MANUAL";
+      }
+      if (isset($_POST["remove$nr"])){
+        $new= array();
+        foreach ($this->kolabInvitationPolicy as $entry){
+          if (!preg_match("/^".$this->imapping[$nr].":/", $entry)){
+            $new[]= $entry;
+          }
+        }
+        $this->kolabInvitationPolicy= $new;
+      }
+      $nr++;
+    }
+
+    /* Unify addresses */
+    $new= array();
+    foreach($this->kolabInvitationPolicy as $value){
+      if (preg_match('/^:/', $value)){
+        continue;
+      }
+      $address= preg_replace('/^([^:]+:).*$/', '\1', $value);
+      $new[$address]= $value;
+    }
+    $this->kolabInvitationPolicy= array();
+    foreach($new as $value){
+      $this->kolabInvitationPolicy[]= $value;
+    }
+
     /* Add delegation */
     if (isset($_POST['add_delegation'])){
       if ($_POST['delegate_address'] != ""){
@@ -64,7 +108,7 @@ class kolabAccount extends plugin
 
           $ldap= $this->config->get_ldap_link();
           $ldap->cd ($this->config->current['BASE']);
-          $ldap->search('(mail='.$address.')');
+          $ldap->search('(mail='.$address.')',array("mail"));
           if ($ldap->count() == 0){
             print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
           } else {
@@ -108,14 +152,65 @@ class kolabAccount extends plugin
     }
 
     /* Transfer account states for this union */
-    if ($this->parent->by_object['mailAccount']->is_account){
+    if (isset($this->parent) && $this->parent->by_object['mailAccount']->is_account){
       $smarty->assign('is_account', 'true');
     } else {
       $smarty->assign('is_account', '');
     }
 
     /* Transfer delegation list */
-    $smarty->assign("kolabDelegate", $this->kolabDelegate);
+    if (!count($this->kolabDelegate)){
+      /* Smarty will produce <option value=""></option> and tidy don't like that, so tell smarty to create no option (array();)*/
+      $smarty->assign("kolabDelegate", array());
+    } else {
+      $smarty->assign("kolabDelegate", $this->kolabDelegate);
+    }
+    $smarty->assign("kolabDelegateACL", chkacl($this->acl, $this->kolabDelegate));
+
+    /* Create InvitationPolicy table */
+    $invitation= "";
+    $this->imapping= array();
+    $nr= 0;
+    $acl= chkacl($this->acl, "kolabInvitationPolicy");
+    foreach ($this->kolabInvitationPolicy as $entry){
+      $invitation.= "<tr><td>";
+
+      /* The default entry does not have colons... */
+      if (!preg_match('/:/', $entry)){
+        $invitation.= _("Anonymous");
+        $name= "";
+        $mode= $entry;
+      } else {
+        $name= preg_replace('/:.*$/', '', $entry);
+        $mode= preg_replace('/^[^:]*: */', '', $entry);
+        $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\">";
+      }
+      $invitation.= "</td>";
+
+      /* Add mode switch */
+      $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
+      foreach($policies as $key => $value){
+        if ($key == $mode){
+          $invitation.= "<option value=\"$key\" selected>$value</option>";
+        } else {
+          $invitation.= "<option value=\"$key\">$value</option>";
+        }
+      }
+      
+      /* Assign buttons */
+      $button= "";
+      if ($nr == count($this->kolabInvitationPolicy)-1){
+        $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\">";
+      }
+      if ($nr != 0) {
+        $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\">";
+      }
+      
+      $invitation.= "</select>&nbsp;$button</td></tr>\n";
+      $this->imapping[$nr]= $name;
+      $nr++;
+    }
+    $smarty->assign("invitation", $invitation);
 
     $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
     return ($display);
@@ -138,10 +233,36 @@ class kolabAccount extends plugin
     }
 
     /* Check for URL scheme... */
-    if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
+    if ($this->calFBURL != "" && !@preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
       $message[]= _("The value specified as Free Busy Information URL is invalid.");
     }
 
+    /* Check invitation policy for existing mail addresses */
+    foreach($this->kolabInvitationPolicy as $policy){
+      
+      /* Ignore anonymous string */
+      if (!preg_match('/:/', $policy)){
+        continue;
+      }
+      
+      $address= preg_replace('/^([^:]+).*$/', '\1', $policy);
+      if (!is_email($address)){
+        if (!is_email($address, TRUE)){
+          $message[]= sprintf(_("The invitation policy entry for address '%s' is not valid."), $address);
+        }
+      } else {
+
+        $ldap= $this->config->get_ldap_link();
+        $ldap->cd ($this->config->current['BASE']);
+        $ldap->search('(mail='.$address.')',array("mail"));
+        if ($ldap->count() == 0){
+          $message[]= sprintf(_("There's no mail user with address '%s' for your invitation policy!"), $address);
+        } else {
+          $valid= TRUE;
+        }
+      }
+    }
+
     return ($message);
   }
 
@@ -160,21 +281,46 @@ class kolabAccount extends plugin
     }
 
     plugin::save_object();
+
+    /* Save changes done in invitation policies */
+    $nr= 0;
+    $this->kolabInvitationPolicy= array();
+    while (isset($_POST["policy$nr"])){
+
+      /* Anonymous? */
+      if (!isset($_POST["address$nr"])){
+        $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
+      } else {
+        $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
+      }
+      
+      $nr++;
+    }
+    
+    /* If this one is empty, preset with ACT_MANUAL for anonymous users */
+    if (count ($this->kolabInvitationPolicy) == 0){
+      $this->kolabInvitationPolicy= array("ACT_MANUAL");
+    }
+
   }
 
 
   /* Save to LDAP */
   function save()
   {
+    /* Check mailmethod before doing something useful */
     plugin::save();
 
-    /* Transfer delegation array */
+    /* Transfer arrays */
     $this->attrs['kolabDelegate']= $this->kolabDelegate;
+    $this->attrs['kolabInvitationPolicy']= $this->kolabInvitationPolicy;
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
+    $this->cleanup();
+$ldap->modify ($this->attrs); 
+
     show_ldap_error($ldap->get_error());
 
     /* Optionally execute a command after we're done */