Code

Updated FAI template entry.
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPackage.inc
index 0134210477b17521a83064c293eaf486732ca785..4380ba3c7a10ec1bc44349d5393c21e9e5cf1f76 100644 (file)
@@ -33,24 +33,19 @@ class faiPackage extends plugin
   var $FAIdebianRelease          = ""; // The selected release
   var $FAIdebianSection          = array(); // selected section
   var $FAIinstallMethod          = "aptitude"; // hard coded
-  var $mirror                    = ""; // selected mirror
 
-  var $servers          = array();  // All available servers
-  var $releases         = array();  // All possible releases 
   var $sections         = array();  // All section types
 
   var $list             = NULL;
 
-  var $mirrors          = array();  // The combination of server/release/section
-  var $confDir          = "";
   var $usedPackages     = array();
   var $buffer           = NULL; 
-  var $strID            ="";
   var $newDialogShown   =false;
 
   var $FAIstate         = "";
   var $view_logged      = FALSE;
   var $base;
+  var $FAIpackage ;
 
   var $FAIinstallMethods  = array( "install", "ninstall", "remove", 
       "dselect-upgrade", "taskinst", "taskrm",
@@ -70,30 +65,22 @@ class faiPackage extends plugin
     if($dn != "new"){
       $this->dn =$dn;
 
-      /* Get FAIstate
+      /* Check if there are already some packages in this list 
        */
-      if(isset($this->attrs['FAIstate'][0])){
-        $this->FAIstate = $this->attrs['FAIstate'][0];
-      }
-    }
-
-    if(isset($this->attrs['FAIpackage'])){
-      unset($this->attrs['FAIpackage']['count']);
-      foreach($this->attrs['FAIpackage'] as $pkg){
-        $this->usedPackages[$pkg] = $pkg;
-      }
-      ksort($this->usedPackages);
-    }else{
       $this->usedPackages = array();
-    }  
-
-    if($dn != "new"){
+      if(isset($this->attrs['FAIpackage'])){
+        unset($this->attrs['FAIpackage']['count']);
+        foreach($this->attrs['FAIpackage'] as $pkg){
+          $name = preg_replace("/\-$/","",$pkg);
+          $this->usedPackages[$name] = $pkg;
+        }
+        ksort($this->usedPackages);
+      }  
 
-      /* Create one filter with all package names, 
-         instead of calling $ldap->search for every single package 
+      /* Fetch all package configurations from ldap 
        */
       $PackageFilter = "";
-      foreach($this->usedPackages as $name){
+      foreach($this->usedPackages as $name => $value){
         $PackageFilter .= "(FAIpackage=".$name.")";
       }
       $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
@@ -101,9 +88,11 @@ class faiPackage extends plugin
       /* Search for configuration objects */ 
       $ldap = $this->config->get_ldap_link();
       $ldap->cd($this->dn);
-      $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
+      $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
+            "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
 
-      /* Walk through configurations and append them to our list of ConfiguredPackages */
+      /* Walk through configurations and append them to our list of ConfiguredPackages 
+       */
       while($attr = $ldap->fetch()){
 
         /* Skip objects, that are tagged as removed */
@@ -130,37 +119,38 @@ class faiPackage extends plugin
           $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
         }
       }
-    }
 
-    if (isset($this->attrs['FAIdebianSection']['count'])){
-      unset($this->attrs['FAIdebianSection']['count']);
-    }
-    if((isset($this->attrs['FAIdebianSection']))&&(is_array($this->attrs['FAIdebianSection']))){
       $this->FAIdebianSection = array();
-      foreach($this->attrs['FAIdebianSection'] as $sec){
-        $this->FAIdebianSection[$sec]=$sec;
+      if(isset($this->attrs['FAIdebianSection'])){
+        for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){ 
+          $sec = $this->attrs['FAIdebianSection'][$i];
+          $this->FAIdebianSection[$sec]=$sec;
+        }
       }
-    }
-
-    if((isset($this->attrs['FAIdebianSection']))&&(is_string($this->attrs['FAIdebianSection']))){
-      $this->FAIdebianSection=array($this->attrs['FAIdebianSection']=>$this->attrs['FAIdebianSection']) ;
-    }
-    $this->confDir = CONFIG_DIR."/fai/";
-    $this->FAIpackage = array();
+      $this->FAIpackage = array();
 
+    } // ENDE  dn != new  
 
     $methods = array();
     foreach($this->FAIinstallMethods as $method){
       $methods[$method] = $method;
     }
     $this->FAIinstallMethods = $methods;
+
     /* Check if we exist already - no need to ask for revisions, etc. then */
     if ($this->dn != "new"){
       $this->newDialogShown= true;
     }
+    $this->is_new = FALSE;
+    if($this->dn == "new"){
+      $this->is_new =TRUE;
+    }
 
+    /* Generate package list */
+    $this->list= $this->genPkgs(TRUE);
   }
 
+
   function execute()
   {
     /* Call parent execute */
@@ -175,20 +165,22 @@ class faiPackage extends plugin
     $smarty= get_smarty();
     $display= "";
 
-    $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
-
+    /******
+     * Initialize a new Package List with release and section name
+     ******/
+    
     if(!$this->is_account){
 
       /* Assemble release name */
-      $faifilter = session::get('faifilter');
-      $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']);
+      $release = $this->parent->parent->fai_release;
+      $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
       $tmp= preg_replace('/ou=/', '', $tmp);
       $rev= array_reverse(split(',', $tmp));
-      $this->FAIdebianRelease= "";
+      $this->FAIdebianRelease= "/";
       foreach ($rev as $part){
         $this->FAIdebianRelease.= "/$part";
       }
-      $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
+      $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
 
       /* Assemble sections */
       $repos= $this->getServerInfos();
@@ -200,29 +192,68 @@ class faiPackage extends plugin
       /* Assign Repository settings*/ 
       $this->is_account     = true;
     }
+  
 
-    /* Assign variables */
-    foreach($this->attributes as $attrs){
-      $smarty->assign($attrs,$this->$attrs);
-    }
-
-    /* Generate package list */
-    $this->list= $this->genPkgs();
+    /******
+     * Add 
+     ******/
 
     /* + was pressed to open the package dialog */
-    if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage")){
-      $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->list,$this->usedPackages);
+    if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
+      $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
       $this->is_dialog =true;
     }
 
-    /* Delte selected package */ 
-    if(isset($_POST['Delpkg']) && $this->acl_is_writeable("FAIpackage")){
-      if($this->FAIstate != "freeze"){
-        foreach($_POST['usedPackages'] as $del){
-          if(isset($this->usedPackages[$del])){
-            unset($this->usedPackages[$del]);
+    /* Check image Posts 
+     */
+    foreach($_POST as $name => $value){
+
+      /******
+       * Mark as removed  
+       ******/
+      
+      if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
+        $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
+        if(isset($this->usedPackages[$id])){
+          $pkg = $this->usedPackages[$id]; 
+          if (preg_match('/\-$/', $pkg)){
+            $pkg= preg_replace('/\-$/', '', $pkg);
+          } else {
+            $pkg= preg_replace('/$/', '-', $pkg);
           }
+          $this->usedPackages[$id] = $pkg;
         }
+        break;
+      }
+
+      /******
+       * Delete Pkgs   
+       ******/
+      if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
+        $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
+        if(isset($this->usedPackages[$id])){
+          unset($this->usedPackages[$id]);
+        }
+        break;
+      }
+
+      /******
+       * Configure Pkgs   
+       ******/
+      if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
+        $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
+         
+        if(isset($this->usedPackages[$pkg])){
+
+          /* Configuration dialog open*/
+          $pkg_config = array();
+          if(isset($this->ConfiguredPackages[$pkg])){
+            $pkg_config = $this->ConfiguredPackages[$pkg];
+          }
+          $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
+          $this->is_dialog =true;
+        }
+        break;
       }
     }
 
@@ -234,7 +265,7 @@ class faiPackage extends plugin
 
     /* attach new packages */
     if(isset($_POST['SaveSubObject'])) {
-      if($this->FAIstate != "freeze"){
+      if(!preg_match("/freeze/i", $this->FAIstate)){
         $this->dialog->save_object();
         if(count($this->dialog->check())){
           foreach($this->dialog->check() as $msgs){
@@ -246,6 +277,9 @@ class faiPackage extends plugin
           $this->dialog = false;
           $this->is_dialog=false;
           ksort($this->usedPackages);
+
+          /* Generate package list */
+          $this->list= $this->genPkgs(TRUE);
         }
       }else{
         $this->dialog = false;
@@ -253,40 +287,9 @@ class faiPackage extends plugin
       }
     }
 
-    /* Configuration dialog open*/
-    if((isset($_POST['Conpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages'][0])) && $this->acl_is_writeable("FAIdebconfInfo")){
-      $path = CONFIG_DIR."/fai/".$this->FAIdebianRelease."/debconf.d";
-      $pkg_config = array();
-      $pkg = $_POST['usedPackages'][0];
-
-      if(isset($this->ConfiguredPackages[$pkg])){
-        $pkg_config = $this->ConfiguredPackages[$pkg];
-      }
-
-      $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
-      $this->is_dialog =true;
-    }
-
-    /* Configuration dialog open*/
-    if($this->FAIstate != "freeze" && $this->acl_is_writeable("FAIpackage")){
-      if((isset($_POST['Markpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages']))){
-        foreach($_POST['usedPackages'] as $pkg){
-          if (isset($this->usedPackages[$pkg])){
-            unset($this->usedPackages[$pkg]);
-            if (preg_match('/^-/', $pkg)){
-              $pkg= preg_replace('/^-/', '', $pkg);
-            } else {
-              $pkg= preg_replace('/^/', '-', $pkg);
-            }
-            $this->usedPackages[$pkg]= $pkg;
-          }
-        }
-      }
-    }
-
     /* Save Configuration */
     if(isset($_POST['SaveObjectConfig'])){
-      if($this->FAIstate != "freeze"){
+      if(!preg_match("/^freeze/", $this->FAIstate)){
         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
       }
       $this->dialog = false;
@@ -301,9 +304,81 @@ class faiPackage extends plugin
 
     /* Display dialog */ 
     if($this->is_dialog){
+      $this->dialog->save_object();
       return $this->dialog->execute();
     }
 
+
+    /******
+     * Display UI / HTML / smarty 
+     ******/
+
+    /* Create divlist to display a list of all currently used packages
+     */
+    $divlist = new divSelectBox("faiPackages");
+
+    ksort($this->usedPackages);
+    if(is_array($this->usedPackages)){
+      foreach($this->usedPackages as $usedName => $name){
+    
+        $actions = "";
+
+        /* Append message if package is configured */
+        $configured = "<img src='images/empty.png' alt=' '  class='center'>";
+        if(isset($this->ConfiguredPackages[$usedName])){
+          $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
+                      title='"._("Configured")."' class='center'>";
+        }
+
+        /* Adapt used name if we're marked for removal */
+        $removal = "<img src='images/empty.png' alt=' '  class='center'>";
+        if (preg_match('/\-$/', $name)){
+          $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
+                      title='"._("Package marked for removal")."' class='center'>";
+        }
+
+        /* Get Version */
+        $version = "&nbsp;";
+        if(isset($this->list[$usedName]['VERSION'])){
+          $version = $this->list[$usedName]['VERSION'];
+        }
+    
+        /* Get description */
+        $description = "&nbsp;";
+        if(isset($this->list[$usedName]['DESCRIPTION'])){
+          $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
+        }
+        if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
+          $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
+            src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
+        }
+
+        if(isset($this->list[$usedName]['TEMPLATE']) && 
+           !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
+          $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
+            src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
+        }
+        if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
+          $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
+            src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
+        }
+
+        $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
+        $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
+        $field3 = array("string" => $version);
+        $field4 = array("string" => $description);
+        $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
+        $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
+      }
+    }
+
+    /* Assign variables */
+    foreach($this->attributes as $attrs){
+      $smarty->assign($attrs,$this->$attrs);
+    }
+    $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
+
     /* Assign section to smarty */
     $strsec = "";
     foreach($this->FAIdebianSection as $sec){
@@ -314,40 +389,31 @@ class faiPackage extends plugin
     foreach($tmp['plProvidedAcls'] as $name => $translated){
       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
     }
-
-    $smarty->assign("releases",$this->releases);
+    $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
+    $smarty->assign("divlist",$divlist->DrawList());
     $smarty->assign("release" ,$this->FAIdebianRelease);
     $smarty->assign("sections",$this->sections);
     $smarty->assign("section" ,$strsec);
-    $smarty->assign("usedPackages",$this->printUsedPackages());
     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
     return($display);
   }
 
-  /* Delete me, and all my subtrees
+
+  /*! \brief  Removes this packageList from the ldap database 
    */
   function remove_from_parent()
   {
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
-
-    $faifilter = session::get('faifilter');
-    $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
-    if($faifilter['branch'] == "main"){
-      $use_dn = $this->dn;
-    }
-
+    $release = $this->parent->parent->fai_release;
+    $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
-
     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
-
     foreach($this->ConfiguredPackages as $pkgname => $attrs){
       foreach($attrs as $name => $attr){
         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
-        $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $pkgdn);
-        if($faifilter['branch'] == "main"){
-          $use_dn = $obj['dn'];
-        }
+        $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
       }
     }
@@ -355,16 +421,18 @@ class faiPackage extends plugin
   }
 
 
-  /* Save data to object 
+  /*! \brief  Collect all relevant POST vars for this plugin 
    */
   function save_object()
   {
-    if($this->FAIstate == "freeze") return;  
+    if(preg_match("/^freeze/", $this->FAIstate)) return;
     plugin::save_object();
   }
 
 
-  /* Check supplied data */
+  /*! \brief  Check given inputs for this package list
+      @return Array Containing all error messages, or an empty array if no error occured
+   */
   function check()
   {
     /* Call common method to give check the hook */
@@ -378,107 +446,56 @@ class faiPackage extends plugin
       $message[]=_("Please choose a valid release/section combination for your repository setup!");
     }
 
+    /* Ensure that we do not overwrite an allready existing entry 
+     */
+    if($this->is_new){
+      $release = $this->parent->parent->fai_release;
+      $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
+      $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
+      if(isset($res[$this->cn])){
+        $message[] = msgPool::duplicated(_("Name"));
+      }
+    }
     return ($message);
   }
 
-  function printUsedPackages(){
-    $a_ret=array(); 
-    if(is_array($this->usedPackages)) {
-      foreach($this->usedPackages as $usedName){
 
-        $config = 0;
+  /*! \brief  Reload the list of cached packages.
+      @return Returns the currently cached list of packages. 
+   */
+  function genPkgs($force = false)
+  {
+    if(empty($this->FAIdebianRelease)) return;
 
-        foreach($this->ConfiguredPackages as $name => $value){
-          if($name == $usedName){
-            $config ++;
-          }
-        }
+    if(!count($this->buffer) || $force){
+      $q = new gosaSupportDaemon();
+      $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
 
-        $c_str ="";
-        if($config){
-          $c_str = " - "._("package is configured");
-        }
+      $packages = array_keys($this->usedPackages);
 
-        /* Adapt used name if we're marked for removal */
-        $dsc= "";
-        if (preg_match('/^-/', $usedName)){
-          $dsc= " - "._("Package marked for removal");
-          // Generally a bad idea here, because the toggel triggers on -, not on !
-          //$usedName= preg_replace('/^-/', '! ', $usedName);
-        }else{
-          $usedName2= $usedName;
-        }
-
-        if(isset($this->list[$usedName][1])){
-          $a_ret[$usedName] = $usedName2." [".$this->list[$usedName][1]."]".$c_str.$dsc;
-        }else{
-          $a_ret[$usedName] = $usedName2.$c_str.$dsc;
+      $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
+      if($q->is_error()){
+        msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
+      }else{
+        foreach($ret as $attr){
+          $this->buffer[$attr['PACKAGE']] = $attr;
         }
       }
     }
-    return($a_ret);
-  }
-
-  function genPkgs()
-  {
-    if($this->buffer === NULL || !count($this->buffer)){
-      $this->buffer = array();
-      $q = new gosaSupportDaemon();
-      $ret = $q->FAI_get_packages($this->FAIdebianRelease);
-      foreach($ret as $attr){
-        $this->buffer[$attr['PACKAGE']] = array($attr['PACKAGE'],$attr['VERSION'],$attr['SECTION'],$attr['DESCRIPTION']);
-      }
-    }
     return $this->buffer;
-#   /* Generate a list off available packages for this mirror, section and release
-#    */
-#   /* Only read this file if it wasn't read before */
-#   $this->buffer = NULL;
-#   if($this->buffer === NULL){
-#     $this->buffer=array();
-#     $a_ret = array();
-#     foreach($this->FAIdebianSection as $sec){
-#       $strID= CONFIG_DIR."/fai/".$this->FAIdebianRelease."/".$sec;
-#
-#       if(!is_file($strID)){
-#         msg_dialog::display(_("Error"), sprintf(_("Package file '%s' does not exist!"), $strID), ERROR_DIALOG);
-#         unset($this->buffer);
-#         return(array());
-#       }
-#       $fp = fopen($strID,"r");
-#
-#       /* Parse every line and create an array */
-#       while(!feof($fp)){
-#         $str= fgets($fp,512);
-#         $stra= split("\|",$str);
-#         if(count($stra)==4){
-#           $a_ret[$stra[0]] = $stra;
-#         break;
-#         }
-#       }
-#       fclose($fp);
-#       /* Save our Data, to avoid reading it again */
-#     }
-#     $this->buffer = $a_ret;
-#     ksort($a_ret);
-#     print_a($this->buffer);
-#     return($a_ret);
-#   }else{
-#     print_a($this->buffer);
-#     return $this->buffer;
-#   }
   }
 
 
-  /* Save to LDAP */
+  /*! \brief Save packages and their configuration to ldap 
+   */
   function save()
   {
 
     /* Assemble release name */
     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
-      $faifilter = session::get('faifilter');
-      $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']);
+
+      $current_release  = $this->parent->parent->fai_release;
+      $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
       $tmp= preg_replace('/ou=/', '', $tmp);
       $rev= array_reverse(split(',', $tmp));
       $this->FAIdebianRelease= "";
@@ -493,7 +510,7 @@ class faiPackage extends plugin
     $ldap = $this->config->get_ldap_link();
 
     $this->attrs['FAIpackage'] = array();
-    foreach($this->usedPackages as $pkg => $obj){
+    foreach($this->usedPackages as $pkg){
       $this->attrs['FAIpackage'][] = $pkg;
     } 
 
@@ -503,9 +520,6 @@ class faiPackage extends plugin
     }
 
     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
-    if (!$ldap->success()){
-      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
-    }
     
     if($this->initially_was_account){
       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
@@ -534,17 +548,25 @@ class faiPackage extends plugin
         $pkgattrs['FAIvariableContent']   = $attr['Value'];
         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
 
-       /* Tag object */
-       $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
+        /* Tag object */
+        $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
 
         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
-          FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
+
+          if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
+            gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
+          }else{
+            FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
+          }
         }
       }
     }
   }
 
-  /* Return plugin informations for acl handling */ 
+
+  /*! \brief  Return plugin informations for acl handling 
+      @return Array ACL infos of this plugin.
+   */ 
   static function plInfo()
   {
     return (array( 
@@ -567,8 +589,9 @@ class faiPackage extends plugin
   }
 
 
-
-
+  /*! \brief prepares this plugin to be inserted after it was copied or cut.
+      @param Array  All attributes from the source object. 
+   */
   function PrepareForCopyPaste($source)
   {
     plugin::PrepareForCopyPaste($source);
@@ -640,6 +663,9 @@ class faiPackage extends plugin
   }
 
 
+  /*! \brief  Returns a list of all configured servers with repositories.
+      @return Array  All repository server 
+   */
   function getServerInfos()
   {
     $ret = array();
@@ -665,6 +691,32 @@ class faiPackage extends plugin
   }
 
 
+  /*! \brief  Used for copy & paste.
+    Returns a HTML input mask, which allows to change the cn of this entry.
+    @param  Array   Array containing current status && a HTML template.
+   */
+  function getCopyDialog()
+  {
+    $vars = array("cn");
+    $smarty = get_smarty();
+    $smarty->assign("cn", htmlentities($this->cn));
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+
+  /*! \brief  Used for copy & paste.
+    Some entries must be renamed to avaoid duplicate entries.
+   */
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = get_post('cn');
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: