Code

Fixed si function
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
index b12358acec0911452a2e7f38d7961ecdc27979a7..7d8a4f494c94a1a8a041f0909cff547805d6fbcf 100644 (file)
@@ -76,7 +76,7 @@ class gosaSupportDaemon
       }else{
         $this->set_error($this->o_sock->get_error());
         $this->disconnect();
-        new log("debug","gosaSupportDaemon::connect()", "Could not connect to server.", array(),$this->get_error());
+        new log("debug","gosaSupportDaemon::connect()", "Cannot connect to si-server", array(),$this->get_error());
       }
     }else{
       $this->set_error(msgPool::cmdnotfound("GOSA_SI",_("GOsa support daemon")));
@@ -134,7 +134,98 @@ class gosaSupportDaemon
   }
 
 
-  public function FAI_get_packages($release,$attrs, $package="")
+  public function FAI_get_kernels($release)
+  {
+    $xml_msg = 
+      "<xml>".
+      "<header>gosa_get_available_kernel</header>".
+      "<source>GOSA</source>".
+      "<target>GOSA</target>".
+      "<release>".$release."</release>".
+      "</xml>";
+
+    $ret = array();
+    if($this->connect()){
+      $this->o_sock->write($xml_msg);
+      $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
+      $entries = $this->xml_to_array($str);
+      if(isset($entries['XML']) && is_array($entries['XML'])){
+
+        /* Check if returned values represent a valid answer */
+        if(isset($entries['XML'])){
+          if(isset($entries['XML']['ERROR_STRING'])) {
+            $this->set_error($entries['XML']['ERROR_STRING']);
+            new log("debug","GOsa-si",
+                get_class($this)."::".__FUNCTION__, array(),
+                "FAILED error was ".$this->get_error());
+            return($ret);
+          }
+
+          /* Unset header tags */
+          $ret = $entries['XML'];
+          foreach($ret as $key => $entry){
+            if(!preg_match("/^answer/i",$key)){
+              unset($ret[$key]);
+            }
+          }
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+  public function FAI_get_package_sections($release)
+  {
+    $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+      "<select>distinct section</select>".
+      "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where></xml>";
+
+    if($this->connect()){
+      $this->o_sock->write($xml_msg);
+      $str = trim($this->o_sock->read());
+
+      /* Check if something went wrong while reading */
+      if($this->o_sock->is_error()){
+        $this->set_error($this->o_sock->get_error());
+        return($ret);
+      }
+
+      $entries = $this->xml_to_array($str);
+      if(isset($entries['XML']) && is_array($entries['XML'])){
+
+        /* Check if returned values represent a valid answer */
+        if(isset($entries['XML'])){
+          if(isset($entries['XML']['ERROR_STRING'])) {
+            $this->set_error($entries['XML']['ERROR_STRING']);
+            new log("debug","GOsa-si",
+                get_class($this)."::".__FUNCTION__, array(),
+                "FAILED error was ".$this->get_error());
+            return($ret);
+          }
+
+          /* Unset header tags */
+          foreach(array("HEADER","SOURCE","TARGET","SESSION_ID") as $type){
+            if(isset($entries['XML'][$type])){
+              unset($entries['XML'][$type]);
+            }
+          }
+          $ret = $entries['XML'];
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+  public function FAI_get_packages($release,$attrs,$package,$from=-1,$to=-1)
   {
     $this->reset_error();
     $ret = array();
@@ -145,29 +236,45 @@ class gosaSupportDaemon
       return($ret);
     }
 
+    /* Check Parameter */
+    if(!is_array($package)){
+      trigger_error("Third parameter must be an array. With at least one attribute name.");
+      return($ret);
+    }
+
     /* Create list of attributes to fetch */
     $attr = ""; 
     foreach($attrs as $at){
-      $attr.= $at.", ";
+      $attr.= "<select>".$at."</select>";
     }
 
-    /* Create Daemon query */
-    if(empty($package)){
-      $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
-        "<select> ".trim($attr,", ")." </select>".
-        "<where><clause><phrase><distribution>".$release."</distribution></phrase></clause></where>
-        </xml>";
+    /* If no package is given, search for all */
+    if(!count($package)) $package = array("%");
+
+    /* Create limit tag */
+    if($from == -1){
+      $limit =""; 
     }else{
-         $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
-        "<select> ".trim($attr,", ")." </select>".
-        "<where><clause>
-            <connector>AND</connector>
-            <phrase><distribution>".$release."</distribution></phrase>
-            <phrase><package>".$package."</package></phrase>
-            </clause></where>
-        </xml>";
+      $limit = "<limit><from>".$from."</from><to>".$to."</to></limit>";
     }
 
+    /* Create list of attributes to fetch */
+    $pkgs = ""; 
+    foreach($package as $pkg){
+      $pkgs .="<phrase><operator>like</operator><package>".$pkg."</package></phrase>";
+    }
+
+    $xml_msg = "<xml><header>gosa_query_packages_list</header><target>GOSA</target><source>GOSA</source>".
+      $attr.
+      "<where>
+      <clause><phrase><distribution>".$release."</distribution></phrase></clause>
+      <clause><connector>OR</connector>
+      ".$pkgs."
+      </clause>
+      </where>".
+      $limit.
+      "</xml>";
+
     if($this->connect()){
       $this->o_sock->write($xml_msg);
       $str = trim($this->o_sock->read());
@@ -313,21 +420,21 @@ class gosaSupportDaemon
     }
 
     $xml_msg = 
-"<xml>
+      "<xml>
       <header>gosa_query_jobdb</header>
       <target>GOSA</target>
       <source>GOSA</source>
       ".$tags."
 
       <orderby>".$sort."</orderby>";
-if($from != -1 && $to != -1){
-$xml_msg.= "
-      <limit>
-       <from>".$from."</from>
-       <to>".$to."</to>
-      </limit>";
-}
-$xml_msg.= "
+    if($from != -1 && $to != -1){
+      $xml_msg.= "
+        <limit>
+        <from>".$from."</from>
+        <to>".$to."</to>
+        </limit>";
+    }
+    $xml_msg.= "
       </xml>";
 
     if($this->connect()){
@@ -811,8 +918,29 @@ $xml_msg.= "
   /*! \brief  Returns the number of currently queued objects.
       @return Integer  
    */
-  public function number_of_queued_entries()
+  public function number_of_queued_entries($event_types)
   {
+    $tags = "";
+    foreach($event_types as $type){
+      $tags .= "<phrase><headertag>".$type."</headertag></phrase>";
+    }
+    if(count($event_types) > 1){
+      $tags = "<connector>or</connector>".$tags;
+    }
+    if(count($event_types)){
+      $tags = "<where><clause>".$tags."</clause></where>";
+    }
+
+
+    $xml_msg =
+      "<xml>".
+      "<header>gosa_query_jobdb</header>".
+      "<target>GOSA</target>".
+      "<source>GOSA</source>".
+      "<select> count ID</select>".
+      $tags.
+      "</xml>";
+
     $xml_msg ="<xml><header>gosa_count_jobdb</header><target>GOSA</target><source>GOSA</source></xml>";
     $this->connect();
     if($this->connect()){