Code

Make package filters for sections work (#6576)
authorpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 12 Apr 2011 08:38:35 +0000 (08:38 +0000)
committerpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 12 Apr 2011 08:38:35 +0000 (08:38 +0000)
- Add support to FAI_get_packages function to filter by section,
  by adding a new attribute exclude_sections which allows the
  specification of an array with sections as keys (and arbitrary
  values).
  (This way its possible to create the array with array_filter and the
  existing package_sections array in class_faiPackageEntry)
- Extend class_faiPackageEntry to hand the list of unselected sections
  to FAI_get_packages
- Extend class_faiPackageEntry to keep the state of the section
  selection on page reload

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@20706 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-core/include/class_gosaSupportDaemon.inc
trunk/gosa-plugins/fai/admin/fai/class_faiPackageEntry.inc

index af297df05da0b8655b465b1e022912d05f46f949..e887252354804d877b9db9c3db12564feb2f2715 100644 (file)
@@ -280,7 +280,7 @@ class gosaSupportDaemon
   }
 
 
-  public function FAI_get_packages($release,$attrs,$package,$from=-1,$to=-1)
+  public function FAI_get_packages($release,$attrs,$package,$from=-1,$to=-1, $exclude_sections=array())
   {
     $ret = array();
 
@@ -305,6 +305,18 @@ class gosaSupportDaemon
     /* If no package is given, search for all */
     if(!count($package)) $package = array("%");
 
+    /* If no section is given, search for all */
+    $section_filter = "";
+    if(count($exclude_sections)) {
+      $section_filter = '<clause><connector>AND</connector>';
+          foreach ($exclude_sections as $section => $value) {
+            $section_filter .= "<phrase><operator>ne</operator><section>"
+              .$section
+              ."</section></phrase>";
+          }
+        $section_filter .= "</clause>";
+    }
+
     /* Create limit tag */
     if($from == -1){
       $limit =""; 
@@ -325,6 +337,7 @@ class gosaSupportDaemon
       <clause><connector>OR</connector>
       ".$pkgs."
       </clause>
+      ".$section_filter."
       </where>".
       $limit.
       "</xml>";
index f86f89a96aff64eefcd72d3697101ef4e5c5789e..0ee58e8ebf1069dec7554586aa5272b5b68133aa 100644 (file)
@@ -79,18 +79,21 @@ class faiPackageEntry extends plugin
             <input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
     $i = 0;
     foreach($this->package_sections as $cat => $selected){
+      $Section_boxes .= "<input type='hidden' value=1 name='CAT$cat'>";
+
       if($i == 2){
         $Section_boxes .="</tr><tr>";
         $i = 0;
       }
       if($selected){
-        $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked ".
+        $Section_boxes .="<td><input type='checkbox' value='1' name='useCAT".$cat."' checked ".
           "onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
       }else{
-        $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' ".
+        $Section_boxes .="<td><input type='checkbox' value='1' name='useCAT".$cat."' ".
           "onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
       }
       $i ++ ;
+
     }
     $Section_boxes .= "</tr></table></div>";
 
@@ -129,7 +132,6 @@ class faiPackageEntry extends plugin
             array("string"=>htmlentities($desc), 
               "attach" => "style='border-right:0px;text-align:left;'")));
     }
-
     $smarty->assign("Section_boxes"          , $Section_boxes);
     $smarty->assign("searchStrPKG"  , $this->searchStrPKG);
     $smarty->assign("faihead"       , "");
@@ -163,6 +165,15 @@ class faiPackageEntry extends plugin
         }
 
       }
+      if(preg_match("/^CAT/i", $name)) {
+        $key = "use$name";
+        $section = preg_replace("/^CAT/i", "", $name);
+          if (isset($_POST[$key])) {
+            $this->package_sections[$section] = TRUE;
+          }else {
+            $this->package_sections[$section] = FALSE;
+          }
+      }
     }
 
     /* Get Posted search filter 
@@ -187,8 +198,13 @@ class faiPackageEntry extends plugin
     $this->pkgs = array(); 
     $q          = new gosaSupportDaemon();
     $filter     = preg_replace("/\*/","%",array($this->searchStrPKG));
+
+    /* Determine filter sections */
+    $cb = create_function('$a', 'return $a != TRUE;');
+    $exclude_sections = array_filter($this->package_sections, $cb);
+    
     $attrs      = array("distribution", "package","version", "section", "description", "timestamp");
-    $ret        = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$filter,0,200);
+    $ret        = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$filter,0,200, $exclude_sections);
     if($q->is_error()){
       msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
     }else{