Code

Backport from trunk
[gosa.git] / gosa-plugins / netatalk / personal / netatalk / class_netatalk.inc
index c09a13a9eb3221448d96b380eaefdf119ad4f99e..88b9fc2dd0cef7c84d309131d2871e36f20a6c37 100644 (file)
@@ -34,7 +34,7 @@ class netatalk extends plugin {
 
   /* Definitions */
   var $plHeadline     = "Netatalk";
-  var $plDescription  = "Manage netatalk account";
+  var $plDescription  = "Manage Netatalk account";
 
   var $view_logged = FALSE;
 
@@ -102,6 +102,10 @@ class netatalk extends plugin {
     $this->get_netatalk_shares(); 
     $this->apple_user_share = $this->selectedshare;
 
+    if(!$this->is_account){
+        $this->apple_user_share = key($this->shares);
+    }
+
     /* Save initial account state */
     $this->initially_was_account = $this->is_account;
   }
@@ -114,18 +118,11 @@ class netatalk extends plugin {
     /* Get netatalk shares */
     $this->shares = array();
     $ldap = $this->config->get_ldap_link();
-
-    if($this->dn === "new" || $this->dn === NULL) {
-      $base  = session::get('CurrentMainBase');
-    } else {
-      $base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/')."/","",$this->dn);
-    }
-
-    $ldap->cd($base);
+    $ldap->cd($this->config->current['BASE']);
     $ldap->search ("(&(objectClass=mount)(|(mountType=url)(mountType=nfs))(cn=*))");
 
     while ($attrs = $ldap->fetch()){
-      $tmp  = split(":", $attrs["cn"][0]);
+      $tmp  = explode(":", $attrs["cn"][0]);
       $host = trim($tmp[0]);
       $dir  = trim($tmp[1]);
       $mountType = trim($attrs["mountType"][0]);
@@ -173,7 +170,7 @@ class netatalk extends plugin {
     /* Do we represent a valid account? */
     if (!$this->is_account && $this->parent === NULL) {
       $display = "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
-        msgPool::noValidExtension(_("netatalk"))."</b>";
+        msgPool::noValidExtension(_("Netatalk"))."</b>";
       $display .= back_to_main();
       return ($display);
     }
@@ -181,20 +178,20 @@ class netatalk extends plugin {
     /* Show tab dialog headers */
     if ($this->parent !== NULL) {
       if ($this->is_account) {
-        $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("netatalk")), 
-            msgPool::featuresEnabled(_("netatalk")));
+        $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("Netatalk")), 
+            msgPool::featuresEnabled(_("Netatalk")));
       } else {
         $errmsg="";
         $obj = $this->parent->by_object['posixAccount'];
         if  (!($obj->is_account) ) {
-          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("netatalk")), 
-              msgPool::featuresDisabled(_("netatalk"), _("POSIX")), TRUE);
+          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("Netatalk")), 
+              msgPool::featuresDisabled(_("Netatalk"), _("POSIX")), TRUE);
         } elseif (count($this->shares)== 0) {
-          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("netatalk")), 
-              msgPool::featuresDisabled(_("netatalk"), _("netatalk or NFS share")), TRUE);
+          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("Netatalk")), 
+              msgPool::featuresDisabled(_("Netatalk"), _("Netatalk or NFS share")), TRUE);
         } else {
-          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("netatalk")), 
-              msgPool::featuresDisabled(_("netatalk")));
+          $display = $this->show_enable_header(msgPool::addFeaturesButton(_("Netatalk")), 
+              msgPool::featuresDisabled(_("Netatalk")));
         } 
         return ($display);
       }
@@ -203,15 +200,14 @@ class netatalk extends plugin {
     /* Assign attributes 
      */
     foreach ($this->smarty_attributes as $val) {
-      $smarty->assign("$val", $this-> $val);
+      $smarty->assign("$val", set_post($this-> $val));
     }
 
     /* Assign ACLs 
      */
     $tmp = $this->plInfo();
-    $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
     foreach($tmp['plProvidedAcls'] as $name => $desc){
-      $smarty->assign($name."ACL",$this->getacl($name,$SkipWrite));
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
 
     /* Let smarty fetch and process the page. */
@@ -251,7 +247,7 @@ class netatalk extends plugin {
       if($mountType=="url") {
         $this->apple_user_homeurl_xml = '<home_dir><url>afp://'.$host.$dir . '</url><path>'.
           $this->apple_user_homepath_raw.'</path></home_dir>';
-        $this->apple_user_homeurl = base64_encode($this->apple_user_homeurl_xml);
+        $this->apple_user_homeurl = $this->apple_user_homeurl_xml;
       } else {
         $this->apple_user_homeurl = "";
       }
@@ -314,7 +310,7 @@ class netatalk extends plugin {
       foreach($this->post_attributes as $acl => $val) {
         if(!preg_match("/w/",$this->getacl($acl))) continue;
         if (isset ($_POST[$val])) {
-          $this->$val = $_POST[$val];
+          $this->$val = get_post($val);
         } else {
           $this->$val = "";
         }
@@ -376,13 +372,43 @@ class netatalk extends plugin {
           "plSection"     => array("personal" => _("My account")),
           "plCategory"    => array("users"),
           "plOptions"         => array(),
-
+          "plRequirements"=> array(
+              'ldapSchema' => array('apple-user' => ''),
+              'onFailureDisablePlugin' => array(get_class())),
           "plProvidedAcls"  => array(
             "netatalkUserHomepath"   =>  _("User home path"),
             "netatalkShare"          =>  _("Share"))
           ));
   }
 
+  function adapt_from_template($dn, $skip= array())
+  {
+    /* As the 'apple-user-homeDirectory' LDAP attribute is stored as
+     * 'apple_user_homeDirectory' internally by GOsa (to avoid problem with
+     * dashes as variable names), we need to add the dashed version to
+     * $this->attributes so that the adapt_from_template function in the plugin
+     * class will find the dashed LDAP attribute and substitute possibly
+     * placeholders like %uid. We remove the dashed version of
+     * 'apple_user_homeDirectory' from the attributes again afterwards. */
+    array_push($this->attributes, "apple-user-homeDirectory");
+    plugin::adapt_from_template($dn, $skip);
+    array_pop($this->attributes);
+  
+    /* Loop through the available shares and find out which is the share from
+     * 'apple-user-homeDirectory'. Remove its host and directory (as well as
+     * the default 'mountDirectory' prefix) to get 'apple_user_homepath_raw'
+     * and store that share as 'selectedshare' so that it gets displayed by
+     * default in the netatalk tab. */
+    foreach($this->shares as $share) {
+      $apple_user_homepath = $this->mountDirectory."/".
+                       $this->shares_settings[$share]["host"].
+                       $this->shares_settings[$share]["dir"]."/";
+      if (preg_match("#$apple_user_homepath#", $this->{'apple-user-homeDirectory'})) {
+        $this->apple_user_homepath_raw =  preg_replace("#$apple_user_homepath#", "", $this->{'apple-user-homeDirectory'});
+        $this->selectedshare = $share;
+      }
+    }
+  }   
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: