Code

Backport from trunk
[gosa.git] / gosa-plugins / kolab / personal / connectivity / kolab / class_kolabAccount.inc
index d1d54190e9673aac770e72f022e54d728ef326c0..f5ef63436f7723aef9391ade6c1a6e6aa389f230 100644 (file)
@@ -3,7 +3,7 @@ class kolabAccount extends plugin
 {
   /* Definitions */
   var $plHeadline       = "Kolab";
-  var $plDescription    = "This does something";
+  var $plDescription    = "Manage Kolab user settings";
 
   /* Kolab attributes */
   var $kolabInvitationPolicy  = array();
@@ -51,6 +51,12 @@ class kolabAccount extends plugin
       }
     }
 
+    /* Get Boolean value */
+    $this->unrestrictedMailSize = FALSE;
+    if(isset($this->attrs['unrestrictedMailSize'][0]) && preg_match("/true/i",$this->attrs['unrestrictedMailSize'][0])){
+      $this->unrestrictedMailSize = TRUE;
+    }
+
     /* If this one is empty, preset with ACT_MANUAL for anonymous users */
     if (count ($this->kolabInvitationPolicy) == 0){
        $this->kolabInvitationPolicy= array("ACT_MANUAL");
@@ -61,10 +67,10 @@ class kolabAccount extends plugin
     if(count($this->kolabDelegate)){
       $this->is_account = true;
     }
-    foreach(array("calFBURL","unrestrictedMailSize") as $attr){
-      if(!empty($this->$attr)){
-        $this->is_account = true;
-      }
+
+    /* Propose FreeBusy URL if empty */
+    if(!empty($this->calFBURL)){
+      $this->is_account = true;
     } 
 
     /* Transfer account states for this union */
@@ -76,6 +82,7 @@ class kolabAccount extends plugin
        $this->is_account  = false;
       $this->mail_Account = false;
     }
+
   }
 
     
@@ -83,9 +90,15 @@ class kolabAccount extends plugin
    */
   function execute()
   {
-         /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
+    /* Fill proposed FB URL if empty */
+    if (empty($this->calFBURL)) {
+      $this->calFBURL= "https://".$this->parent->by_object['mailAccount']->gosaMailServer.
+                       "/freebusy/".$this->parent->by_object['mailAccount']->mail.".ifb";
+    }
+    
     /* Log view */
     if($this->is_account && !$this->view_logged){
       $this->view_logged = TRUE;
@@ -100,7 +113,7 @@ class kolabAccount extends plugin
 
     /* Load attributes */
     foreach($this->attributes as $val){
-      $smarty->assign("$val", $this->$val);
+      $smarty->assign("$val", set_post($this->$val));
     }
 
     $tmp = $this->plInfo();
@@ -158,22 +171,22 @@ class kolabAccount extends plugin
       if ($_POST['delegate_address'] != ""){
 
         /* Valid email address specified? */
-        $address= $_POST['delegate_address'];
+        $address= get_post('delegate_address');
         $valid= FALSE;
         if (!tests::is_email($address)){
           if (!tests::is_email($address, TRUE)){
-            msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"), "","", "example@your-domain.com"));
+            msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"), "","", "your-domain@your-domain.com"));
           }
         } else {
 
-          $ldap= $this->config->get_ldap_link();
-          $ldap->cd ($this->config->current['BASE']);
-          $ldap->search('(mail='.$address.')',array("mail"));
-          if ($ldap->count() == 0){
-            msg_dialog::display(_("Error"), msgPool::duplicated(_("Primary mail address")));
-          } else {
+#         $ldap= $this->config->get_ldap_link();
+#         $ldap->cd ($this->config->current['BASE']);
+#         $ldap->search('(mail='.$address.')',array("mail"));
+#         if ($ldap->count() == 0){
+#           msg_dialog::display(_("Error"), msgPool::duplicated(_("Primary mail address")));
+#         } else {
             $valid= TRUE;
-          }
+#          }
         }
 
         if ($valid){
@@ -190,7 +203,7 @@ class kolabAccount extends plugin
     /* Delete forward email addresses */
     if ((isset($_POST['delete_delegation'])) && (isset($_POST['delegate_list']))){
       if (count($_POST['delegate_list']) && $this->acl_is_writeable("kolabDelegate")){
-        $this->delDelegate ($_POST['delegate_list']);
+        $this->delDelegate (get_post('delegate_list'));
       }
     }
 
@@ -200,7 +213,7 @@ class kolabAccount extends plugin
                       'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
                       'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
                       'ACT_MANUAL'              => _("Manual"));
-    $smarty->assign('policies', $policies);
+    $smarty->assign('policies', set_post($policies));
 
     /* Adjust checkbox */
     if ($this->unrestrictedMailSize){
@@ -214,7 +227,7 @@ class kolabAccount extends plugin
       /* 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("kolabDelegate", set_post($this->kolabDelegate));
     }
 
     $smarty->assign("mail_account",$this->mail_Account);
@@ -257,7 +270,7 @@ class kolabAccount extends plugin
         if(!$this->acl_is_readable("kolabInvitationPolicy")){
           $name='';
         }
-        $invitation.= "<input name=\"address$nr\" size=16 maxlength=60  value=\"$name\" id='address".$nr."' ".$dis.">";
+        $invitation.= "<input type='text'name=\"address$nr\" size=16 maxlength=60  value=\"".set_post($name)."\" id='address".$nr."' ".$dis.">";
       }
       $invitation.= "</td>";
 
@@ -274,10 +287,10 @@ class kolabAccount extends plugin
       /* Assign buttons */
       $button= "";
       if ($nr == count($this->kolabInvitationPolicy)-1){
-        $button= "<input type='image' name=\"add_inv_".$nr."\" src='images/list_new.png' id='add".$nr."' ".$dis.">";
+        $button= "<button type='submit' name=\"add_inv_".$nr."\" id='add".$nr."' ".$dis.">".msgPool::addButton()."</button>";
       }
       if ($nr != 0) {
-        $button.= "<input type='image' name=\"del_inv_".$nr."\" src='images/edittrash.png' id='remove".$nr."' ".$dis.">";
+        $button.= "<button type='submit' name=\"del_inv_".$nr."\" id='remove".$nr."' ".$dis.">".msgPool::delButton()."</button>";
       }
       
       $invitation.= "</select>&nbsp;</td>
@@ -290,13 +303,12 @@ class kolabAccount extends plugin
     $smarty->assign("changeState", $changeState);
     $smarty->assign("kolabState",$this->is_account);
 
-  
     $smarty->assign("multiple_support",$this->multiple_support_active);
     foreach($this->attributes as $attr){
-      $smarty->assign("use_".$attr,in_array($attr,$this->multi_boxes));
+      $smarty->assign("use_".$attr,in_array_strict($attr,$this->multi_boxes));
     }
     foreach(array("kolabState") as $attr){
-      $smarty->assign("use_".$attr,in_array($attr,$this->multi_boxes));
+      $smarty->assign("use_".$attr,in_array_strict($attr,$this->multi_boxes));
     }
 
     if($this->multiple_support_active){
@@ -316,7 +328,7 @@ class kolabAccount extends plugin
     /* Optionally execute a command after we're done */
     plugin::remove_from_parent();
     
-    if(!in_array("kolabInetOrgPerson",$this->attrs['objectClass'])){
+    if(!in_array_strict("kolabInetOrgPerson",$this->attrs['objectClass'])){
       $this->attrs['objectClass'][] = "kolabInetOrgPerson";
     }
 
@@ -329,7 +341,9 @@ class kolabAccount extends plugin
     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
     $this->handle_post_events('remove',array("uid" => $this->uid));
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/kolab account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
   }
 
 
@@ -339,7 +353,7 @@ class kolabAccount extends plugin
     $message= plugin::check();
 
     /* FBFuture is in days... */
-    if ($this->kolabFreeBusyFuture != ""){
+    if ($this->kolabFreeBusyFuture == ""){
       $message[]= msgPool::required(_("Free Busy future"));
     }
     if(!preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
@@ -347,11 +361,11 @@ class kolabAccount extends plugin
     }
 
     /* Check for URL scheme... */
-    if(!empty($this->calFBURL)){
-      $message[]= msgPool::required(_("Free Busy url"));
+    if(empty($this->calFBURL)){
+      $message[]= msgPool::required(_("Free Busy URL"));
     }
     if(!preg_match("/^http+(s)*:\/\//",$this->calFBURL)){
-      $message[]= msgPool::invalid(_("Free Busy url"), $this->calFBURL, "/^http+(s)*:\/\//");
+      $message[]= msgPool::invalid(_("Free Busy URL"), $this->calFBURL, "/^http+(s)*:\/\//");
     }
 
     /* Check invitation policy for existing mail addresses */
@@ -418,9 +432,9 @@ class kolabAccount extends plugin
 
         /* Anonymous? */
         if (!isset($_POST["address$nr"])){
-          $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
+          $this->kolabInvitationPolicy[]= get_post("policy$nr");
         } else {
-          $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
+          $this->kolabInvitationPolicy[]= get_post("address$nr").": ".get_post("policy$nr");
         }
 
         $nr++;
@@ -464,7 +478,9 @@ class kolabAccount extends plugin
       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/kolab account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -500,13 +516,17 @@ class kolabAccount extends plugin
   {
     return (array(     
           "plShortName"     => _("Kolab"),
-          "plDescription"   => _("Kolab account settings")."&nbsp;:&nbsp;<u>"._("Connectivity addon")."</u>",
+          "plDescription"   => _("Kolab account settings")."&nbsp;("._("Connectivity add-on").")",
           "plSelfModify"    => TRUE,
           "plDepends"       => array("user"),
           "plPriority"      => 20,                                 // Position in tabs
           "plSection"     => array("personal" => _("My account")),
           "plCategory"    => array("users"),
           "plOptions"       => array(),
+          "plRequirements"=> array(
+              'ldapSchema' => array('kolabInetOrgPerson' => ''),
+              'onFailureDisablePlugin' => array(get_class())
+              ),
 
           "plProvidedAcls"  => array(
             "kolabFreeBusyFuture"   => _("Free busy future"),
@@ -551,12 +571,9 @@ class kolabAccount extends plugin
   public function get_multi_edit_values()
   {
     $ret = plugin::get_multi_edit_values();
-    if(in_array("kolabState",$this->multi_boxes)){
+    if(in_array_strict("kolabState",$this->multi_boxes)){
       $ret['is_account'] = $this->is_account;
     }
-
-    print_a($ret);
-  
     return($ret);
   }
 
@@ -582,7 +599,7 @@ class kolabAccount extends plugin
   public function init_multiple_support($attrs,$all)
   {
     plugin::init_multiple_support($attrs,$all);
-    if(isset($attrs['objectClass']) && in_array("kolabInetOrgPerson",$attrs['objectClass'])){
+    if(isset($attrs['objectClass']) && in_array_strict("kolabInetOrgPerson",$attrs['objectClass'])){
       $this->is_account = TRUE;
     }
 
@@ -602,6 +619,66 @@ class kolabAccount extends plugin
        $this->kolabInvitationPolicy= array("ACT_MANUAL");
     }
   }
+
+  /* Adapt from template, using 'dn' */
+  function adapt_from_template($dn, $skip= array())
+  {
+    plugin::adapt_from_template($dn, $skip);
+
+    /* Setting uid to default */
+    if(isset($this->attrs['uid'][0]) && !in_array_strict("uid", $skip)){
+      $this->uid = $this->attrs['uid'][0];
+    }
+
+    /* Pull arrays */
+    foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
+
+      if (in_array_strict($attr, $skip)){
+        continue;
+      }
+
+      if (isset($this->attrs["$attr"]["count"])){
+        $tmp = array();
+        for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
+          $tmp[]=$this->attrs["$attr"][$i];
+        }
+        $this->$attr = $tmp;
+      }
+    }
+
+    /* If this one is empty, preset with ACT_MANUAL for anonymous users */
+    if (count ($this->kolabInvitationPolicy) == 0){
+      $this->kolabInvitationPolicy= array("ACT_MANUAL");
+    }
+
+    /* Get Boolean value */
+    $this->unrestrictedMailSize = FALSE;
+    if(isset($this->attrs['unrestrictedMailSize'][0]) && preg_match("/true/i",$this->attrs['unrestrictedMailSize'][0])){
+      $this->unrestrictedMailSize = TRUE;
+    }
+
+    /* Check is account state */
+    $this->is_account = false;
+    if(count($this->kolabDelegate)){
+      $this->is_account = true;
+    }
+    foreach(array("calFBURL") as $attr){
+      if(!empty($this->$attr)){
+        $this->is_account = true;
+      }
+    }
+  }
+
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    $this->is_account = FALSE;
+
+    if(isset($source['kolabDelegate']) || isset($source['calFBURL'])){
+      $this->is_account = TRUE;
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: