Code

Fixed undefined index
[gosa.git] / plugins / personal / connectivity / class_kolabAccount.inc
index 0983e5b43e7603480753e3b6cd1e7ec81db29e5f..874220e71a0a189e79a2e93e628db294bcb8129e 100644 (file)
@@ -2,27 +2,24 @@
 class kolabAccount extends plugin
 {
   /* Definitions */
-  var $plHeadline= "Kolab";
-  var $plDescription= "This does something";
-
-  /* CLI vars */
-  var $cli_summary= "Manage users Kolab account";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+  var $plHeadline       = "Kolab";
+  var $plDescription    = "This does something";
 
   /* Kolab attributes */
-  var $kolabInvitationPolicy= array();
-  var $kolabFreeBusyFuture= 60;
-  var $unrestrictedMailSize= 0;
-  var $calFBURL= "";
-  var $kolabDelegate= array();
+  var $kolabInvitationPolicy  = array();
+  var $kolabFreeBusyFuture    = 60;
+  var $unrestrictedMailSize   = 0;
+  var $calFBURL               = "";
+  var $kolabDelegate          = array();
 
   /* attribute list for save action */
-  var $attributes= array( "kolabFreeBusyFuture", "unrestrictedMailSize", "calFBURL");
-  var $objectclasses= array();
+  var $attributes     = array("kolabFreeBusyFuture", "unrestrictedMailSize", "calFBURL","kolabDelegate");
+  var $objectclasses  = array("kolabInetOrgPerson");
 
   /* Helper */
   var $imapping= array();
+  var $mail_Account   = false;
+  var $ReadOnly = false;
 
   function kolabAccount ($config, $dn= NULL)
   {
@@ -31,9 +28,11 @@ class kolabAccount extends plugin
     /* Pull arrays */
     foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
       if (isset($this->attrs["$attr"]["count"])){
+        $tmp = array();
         for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
-          array_push($this->$attr, $this->attrs["$attr"][$i]);
+          $tmp[]=$this->attrs["$attr"][$i];
         }
+        $this->$attr = $tmp;
       }
     }
 
@@ -42,12 +41,31 @@ class kolabAccount extends plugin
        $this->kolabInvitationPolicy= array("ACT_MANUAL");
     }
 
+    /* Check is account state */
+    $this->is_account = false;
+    if(count($this->kolabDelegate)){
+      $this->is_account = true;
+    }
+    foreach(array("calFBURL","unrestrictedMailSize") as $attr){
+      if(!empty($this->$attr)){
+        $this->is_account = true;
+      }
+    } 
+
+    /* Transfer account states for this union */
+    if (isset($this->parent) && $this->parent->by_object['mailAccount']->is_account){
+      $this->mail_Account = true;
+    } elseif($this-> initially_was_account && (isset($this->attrs['objectClass']) && (in_array("kolabInetOrgPerson",$this->attrs['objectClass'])))){
+      $this->mail_Account = true;
+    }
   }
 
+
   function execute()
   {
        /* Call parent execute */
-       plugin::execute();
+       plugin::execute();
+
     /* Show tab dialog headers */
     $display= "";
 
@@ -57,7 +75,21 @@ class kolabAccount extends plugin
     /* Load attributes */
     foreach($this->attributes as $val){
       $smarty->assign("$val", $this->$val);
-      $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
+    }
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $acl => $description){
+      $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
+      $smarty->assign($acl."_W", $this->acl_is_writeable($acl,$this->ReadOnly));
+    }
+    $smarty->assign("is_account" ,  $this->is_account); 
+
+    if($this->ReadOnly){
+      $smarty->assign("is_removeable",false); 
+      $smarty->assign("is_createable",false); 
+    }else{
+      $smarty->assign("is_removeable",$this->acl_is_removeable()); 
+      $smarty->assign("is_createable",$this->acl_is_createable()); 
     }
 
     /* Check for invitation action */
@@ -81,9 +113,6 @@ class kolabAccount extends plugin
     /* Unify addresses */
     $new= array();
     foreach($this->kolabInvitationPolicy as $value){
-      if (preg_match('/^:/', $value)){
-        continue;
-      }
       $address= preg_replace('/^([^:]+:).*$/', '\1', $value);
       $new[$address]= $value;
     }
@@ -107,7 +136,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 {
@@ -117,7 +146,7 @@ class kolabAccount extends plugin
 
         if ($valid){
           /* Add it */
-          if (chkacl ($this->acl, "kolabDelegate") == ""){
+          if ($this->acl_is_writeable("kolabDelegate")){
             $this->addDelegate ($address);
             $this->is_modified= TRUE;
           }
@@ -127,10 +156,8 @@ class kolabAccount extends plugin
     }
 
     /* Delete forward email addresses */
-    if (isset($_POST['delete_delegation'])){
-      if (count($_POST['delegate_list'])
-          && chkacl ($this->acl, "kolabDelegate") == ""){
-
+    if ((isset($_POST['delete_delegation'])) && (isset($_POST['delegate_list']))){
+      if (count($_POST['delegate_list']) && $this->acl_is_writeable("kolabDelegate")){
         $this->delDelegate ($_POST['delegate_list']);
       }
     }
@@ -150,13 +177,6 @@ class kolabAccount extends plugin
       $smarty->assign('unrestrictedMailSizeState', "");
     }
 
-    /* Transfer account states for this union */
-    if (isset($this->parent) && $this->parent->by_object['mailAccount']->is_account){
-      $smarty->assign('is_account', 'true');
-    } else {
-      $smarty->assign('is_account', '');
-    }
-
     /* Transfer delegation list */
     if (!count($this->kolabDelegate)){
       /* Smarty will produce <option value=""></option> and tidy don't like that, so tell smarty to create no option (array();)*/
@@ -164,16 +184,35 @@ class kolabAccount extends plugin
     } else {
       $smarty->assign("kolabDelegate", $this->kolabDelegate);
     }
-    $smarty->assign("kolabDelegateACL", chkacl($this->acl, $this->kolabDelegate));
+
+    $smarty->assign("mail_account",$this->mail_Account);
 
     /* Create InvitationPolicy table */
     $invitation= "";
     $this->imapping= array();
     $nr= 0;
-    $acl= chkacl($this->acl, "kolabInvitationPolicy");
+    $changeState  = "";
     foreach ($this->kolabInvitationPolicy as $entry){
+
+      if($this->acl_is_writeable("kolabInvitationPolicy")){
+        $changeState .= "changeState('address".$nr."'); \n changeState('policy".$nr."'); \n
+          changeState('add".$nr."'); \n changeState('remove".$nr."'); \n";
+      }
+
+      if(!$this->acl_is_writeable("kolabInvitationPolicy")){
+        $dis = " disabled ";
+      }else{
+        if($this->is_account){
+          $dis = " ";
+        }else{
+          $dis = " disabled ";
+        }
+      }
       $invitation.= "<tr><td>";
 
+      if(!$this->acl_is_readable("kolabInvitationPolicy"))    {
+      }
+
       /* The default entry does not have colons... */
       if (!preg_match('/:/', $entry)){
         $invitation.= _("Anonymous");
@@ -182,12 +221,16 @@ class kolabAccount extends plugin
       } else {
         $name= preg_replace('/:.*$/', '', $entry);
         $mode= preg_replace('/^[^:]*: */', '', $entry);
-        $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\">";
+
+        if(!$this->acl_is_readable("kolabInvitationPolicy")){
+          $name='';
+        }
+        $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\" id='address".$nr."' ".$dis.">";
       }
       $invitation.= "</td>";
 
       /* Add mode switch */
-      $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
+      $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl  id='policy".$nr."' ".$dis.">";
       foreach($policies as $key => $value){
         if ($key == $mode){
           $invitation.= "<option value=\"$key\" selected>$value</option>";
@@ -199,10 +242,10 @@ class kolabAccount extends plugin
       /* Assign buttons */
       $button= "";
       if ($nr == count($this->kolabInvitationPolicy)-1){
-        $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\">";
+        $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\" id='add".$nr."' ".$dis.">";
       }
       if ($nr != 0) {
-        $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\">";
+        $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\" id='remove".$nr."' ".$dis.">";
       }
       
       $invitation.= "</select>&nbsp;$button</td></tr>\n";
@@ -210,21 +253,37 @@ class kolabAccount extends plugin
       $nr++;
     }
     $smarty->assign("invitation", $invitation);
-
+    $smarty->assign("changeState", $changeState);
+    $smarty->assign("kolabState",$this->is_account);
     $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
+
+
     return ($display);
   }
 
   function remove_from_parent()
   {
     /* Optionally execute a command after we're done */
+    plugin::remove_from_parent();
+    
+    if(!in_array("kolabInetOrgPerson",$this->attrs['objectClass'])){
+      $this->attrs['objectClass'][] = "kolabInetOrgPerson";
+    }
+
+    $ldap = $this->config->get_ldap_linK(); 
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->cd ($this->dn);
+    $ldap->modify($this->attrs);
+
     $this->handle_post_events('remove');
+    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/kolab account with dn '%s' failed."),$this->dn));
   }
 
 
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     /* FBFuture is in days... */
     if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
@@ -232,7 +291,7 @@ 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.");
     }
 
@@ -253,7 +312,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){
           $message[]= sprintf(_("There's no mail user with address '%s' for your invitation policy!"), $address);
         } else {
@@ -270,7 +329,18 @@ class kolabAccount extends plugin
   {
     /* Do we need to flip is_account state? */
     if (isset($_POST['connectivityTab'])){
-      if (chkacl('unrestrictedMailSize', $this->acl == "")){
+
+      if(isset($_POST["kolabState"])){
+        if($this->acl_is_createable()){
+          $this->is_account = true;
+        }
+      }else{
+        if($this->acl_is_removeable()){
+          $this->is_account = false;
+        }
+      }
+      
+      if ($this->acl_is_writeable("unrestrictedMailSize")){
         if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
           $this->unrestrictedMailSize= 1;
         } else {
@@ -282,25 +352,26 @@ class kolabAccount extends plugin
     plugin::save_object();
 
     /* Save changes done in invitation policies */
-    $nr= 0;
-    $this->kolabInvitationPolicy= array();
-    while (isset($_POST["policy$nr"])){
+    if($this->acl_is_writeable("kolabInvitationPolicy")){
+      $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"];
+        }
 
-      /* Anonymous? */
-      if (!isset($_POST["address$nr"])){
-        $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
-      } else {
-        $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
+        $nr++;
       }
-      
-      $nr++;
-    }
-    
-    /* If this one is empty, preset with ACT_MANUAL for anonymous users */
-    if (count ($this->kolabInvitationPolicy) == 0){
-      $this->kolabInvitationPolicy= array("ACT_MANUAL");
-    }
 
+      /* If this one is empty, preset with ACT_MANUAL for anonymous users */
+      if (count ($this->kolabInvitationPolicy) == 0){
+        $this->kolabInvitationPolicy= array("ACT_MANUAL");
+      }
+    }
   }
 
 
@@ -314,11 +385,20 @@ class kolabAccount extends plugin
     $this->attrs['kolabDelegate']= $this->kolabDelegate;
     $this->attrs['kolabInvitationPolicy']= $this->kolabInvitationPolicy;
 
+    /* unrestrictedMailSize is boolean */
+    if($this->attrs['unrestrictedMailSize']){
+      $this->attrs['unrestrictedMailSize'] = "TRUE";
+    }else{
+      $this->attrs['unrestrictedMailSize'] = "FALSE";
+    }
+  
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/kolab account with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -348,6 +428,28 @@ class kolabAccount extends plugin
     $this->is_modified= TRUE;
   }
 
+
+  /* Return plugin informations for acl handling  */
+  function plInfo()
+  {
+    return (array(     
+          "plShortName"     => _("Kolab"),
+          "plDescription"   => _("Kolab account settings"),
+          "plSelfModify"    => TRUE,
+          "plDepends"       => array("user"),
+          "plPriority"      => 2,                                 // Position in tabs
+          "plSection"       => "personal",                        // This belongs to personal
+          "plCategory"      => array("users"),
+          "plOptions"       => array(),
+
+          "plProvidedAcls"  => array(
+            "kolabFreeBusyFuture"   => _("Free busy future"),
+            "unrestrictedMailSize"  => _("Mail size restriction"),
+            "calFBURL"              => _("Free busy information"),
+            "kolabDelegate"         => _("Delegations"),
+            "kolabInvitationPolicy" => _("Invitation policy"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: