Code

Updated FAI package plugin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 29 Jun 2009 07:56:37 +0000 (07:56 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 29 Jun 2009 07:56:37 +0000 (07:56 +0000)
-Allow to add free-text fai packages.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13812 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiPackage.inc
gosa-plugins/fai/admin/fai/faiPackage.tpl

index 4380ba3c7a10ec1bc44349d5393c21e9e5cf1f76..a18c3c8eaf9761d7d8aa83a7766b4a3b90843bb9 100644 (file)
@@ -40,7 +40,7 @@ class faiPackage extends plugin
 
   var $usedPackages     = array();
   var $buffer           = NULL; 
-  var $newDialogShown   =false;
+  var $newDialogShown   = false;
 
   var $FAIstate         = "";
   var $view_logged      = FALSE;
@@ -198,12 +198,88 @@ class faiPackage extends plugin
      * Add 
      ******/
 
+    if(isset($_POST['AddManualpkg']) && 
+        isset($_POST['addPpkgsText']) &&
+        strlen($_POST['addPpkgsText']) && 
+        $this->acl_is_writeable("FAIpackage") && 
+        !preg_match("/freeze/",$this->FAIstate)){
+
+      // Check all splitted packages for valid package names
+      $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
+      if( is_array($add_packages) ) {
+        $invalid_packages = array();
+        foreach ($add_packages as $value) {
+          if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
+            $invalid_packages[] = trim($value);
+          }else{
+            $valid_packages[] = trim($value);
+          }
+        }
+        if(count($invalid_packages)){
+          $str = implode(", ",$invalid_packages);
+          msg_dialog::display(_("Invalid package names"), 
+              sprintf(_("The following package names don't match the Debian policy: %s"),$str),
+              ERROR_DIALOG);
+        }
+
+
+        // If we have a complete list of valid packages, add them
+        if(count($valid_packages)){
+
+          foreach($valid_packages as $key =>  $value){
+            if(array_key_exists($value,$this->usedPackages)) {
+              unset($valid_packages[$key]);
+            }
+          }
+
+          // Query SI-Deamon for additional package information
+          $daemon       = new gosaSupportDaemon();
+          $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
+          $do_si_query  = true;
+
+
+          foreach ($valid_packages as $value) {
+            
+            if( $do_si_query == true ) {
+              $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
+              if( ! $daemon->is_error()){
+                
+                if(count($res)){
+
+                  // We just use the last answer - there shouldn't be multiple
+                  $res_attrs = array_pop( $res );
+                  $this->list[$value] = $res_attrs;
+                  $this->usedPackages[$value] = $res_attrs['PACKAGE'];
+
+                }else{
+                  $this->usedPackages[$value] = $value;
+                }
+              }else{
+                msg_dialog::display(_("Service infrastructure"),
+                    msgPool::siError($daemon->get_error()),
+                    ERROR_DIALOG);
+                $do_si_query = false;
+              }
+            }
+          }
+
+          ksort($this->usedPackages);
+
+          /* Generate package list */
+          $this->list= $this->genPkgs(TRUE);
+        }
+      }
+    }
+
     /* + was pressed to open the package dialog */
-    if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
+    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;
     }
 
+
     /* Check image Posts 
      */
     foreach($_POST as $name => $value){
index 3ab7fdebb87c4772b33eae9ec94daee8b9edce18..cfe8ca80cc5fe1c2b2fc388c9a7139d28665da6f 100644 (file)
 <p class="seperator">&nbsp;</p>
 <table width="99%" summary="">
        <tr>
-               <td> 
+               <td colspan="2"
                        <h2><img class="center" alt="" src="plugins/fai/images/fai_packages.png" align="middle" title="{t}Used packages{/t}">&nbsp;{t}Used packages{/t}</h2>
                        {$divlist}
-                       <br>
+               </td>
+       </tr>
 {render acl=$FAIpackageACL}
-                       <input type="submit" name="Addpkg" value="{msgPool type=addButton}">
-{/render}
+       <tr>
+               <td>
+                       {t}Manually add packages{/t}: 
+      <input type="text" size="25" name="addPpkgsText" value="" />
+                       <input type="submit" name="AddManualpkg" value="{msgPool type=addButton}" />
+               </td>
+               <td align="right">
+      {t}Add from list{/t}: 
+                       <input type="submit" name="Addpkg" value="{msgPool type=addButton}" />
                </td>
        </tr>
+{/render}
 </table>
 
 <!-- Place cursor -->