Code

mailQueue is now able to handle more than one server
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 8 Nov 2005 06:56:32 +0000 (06:56 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 8 Nov 2005 06:56:32 +0000 (06:56 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1858 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/addons/mailqueue/class_mailqueue.inc
plugins/addons/mailqueue/class_parseMailQueue.inc
plugins/addons/mailqueue/contents.tpl

index 1828e3ad750f5c2bd0b65ba814eed2ab518620d3..086bfc1583c7f6c38530355704683e25d01c57ff 100644 (file)
@@ -39,33 +39,100 @@ class mailqueue extends plugin
     /* Call parent execute */
     plugin::execute();
     $smarty= get_smarty();
-     
-    $q_cmd = preg_replace("/%server/",$this->Server,$this->QueryCommand);
-
-    /* Only display this if the query cmd is executeable */
-    if($str = @shell_exec ($q_cmd)){
-       
-      /* Parse returned data */
-      $mailQueueParser = new parseMailQueue($str);
-
-      /* Delete entry if requested */
-      if(isset($_GET['del'])){
-        if($mailQueueParser->IDExists($_GET['del'])){
-          $r_cmd = preg_replace("/%server/", $this->Server,$this->RemoveCommand);  
-          $r_cmd = preg_replace("/%id/",     $_GET['del'] ,$r_cmd);  
-          print $r_cmd;
+
+    $error =false;
+
+    if(empty($this->QueryCommand)){
+      print_red(_("Please check your 'gosa.conf', there is no 'MAILQUEUE_QUERY_COMMAND' specified."));
+      $error = true;
+    }else{
+
+      /* tell smarty to display the search results*/
+      $smarty->assign("all_ok"      , "true");
+
+      /* A single server is selected */
+      if($this->Server != "all"){    
+
+        /* Create Query cmd */ 
+        $q_cmd = preg_replace("/%server/",$this->Server,$this->QueryCommand);
+
+        /* Only display this if the query cmd is executeable */
+        if($str = @shell_exec ($q_cmd)){
+
+          /* Parse returned data */
+          $mailQueueParser = new parseMailQueue($str,$this->Server);
+
+        }else{
+
+          /* Can't Execute cmd */
+          print_red(sprintf(_("Please check your 'gosa.conf' the given '%s' can't be executed."),$q_cmd));
+          $error = true;
         }
-      }
 
-      /* Filter data with the given */
-      $mailQueueParser->OrderBy($this->OrderBy,$this->SortType);
-      $mailQueueParser->OnlyDaysAgo($this->Time);
-      $mailQueueParser->CreateDate();
-      $mailQueueParser->Search($this->Search,array("MailID","Size","Sender","Recipient","Error","Arrival"));
+      }else{
+
+        $mailQueueParser = NULL;
+        foreach($this->getServer() as $ServerID=>$ServerName){
+          if($ServerID == "all") continue;
+
+          $q_cmd = preg_replace("/%server/",$ServerName,$this->QueryCommand);
+
+          if($str = @shell_exec ($q_cmd)){
+            if($mailQueueParser == NULL){
+              $mailQueueParser = new parseMailQueue($str,$ServerID);
+            }else{
+              $mailQueueParser->parseAdditionalQueue($str,$ServerID);
+            }
+          }else{
+            print_red(sprintf(_("Please check your 'gosa.conf' the given '%s' can't be executed."),$q_cmd));
+            $error = true;
+          }
+        }
+
+      }     
+
+      if(!$error){
+
+        /* Delete entry if requested */
+        if(isset($_GET['del'])){
+          if($mailQueueParser->IDExists($_GET['del'])){
+            $r_cmd = preg_replace("/%server/", $this->Server,$this->RemoveCommand);  
+            $r_cmd = preg_replace("/%id/",     $_GET['del'] ,$r_cmd);  
+            print $r_cmd;
+          }
+        }
+
+        /* Filter data with the given */
+        $mailQueueParser->OrderBy($this->OrderBy,$this->SortType);
+        $mailQueueParser->OnlyDaysAgo($this->Time);
+        $mailQueueParser->CreateDate();
+        $mailQueueParser->Search($this->Search,array("MailID","Size","Sender","Recipient","Error","Arrival"));
+
+        /* */
+        $entries = $mailQueueParser->GetAll(); 
+        $smarty->assign("entries"       , array_slice($entries,$this->Page,20));
+        $smarty->assign("plug"          , "?plug=".$_GET['plug']);
+        $smarty->assign("p_server"      , $this->Server);
+        $smarty->assign("p_servers"     , $this->getServer());
+        $smarty->assign("p_serverKeys"  , array_flip($this->getServer()));
+        $smarty->assign("p_time"        , $this->Time);
+        $smarty->assign("p_times"       , $this->getTimes());
+        $smarty->assign("p_timeKeys"    , array_flip($this->getTimes()));
+        $smarty->assign("search_for"    , $this->Search);
+        $smarty->assign("range_selector", range_selector(count($entries), $this->Page, 20)); 
+        $smarty->assign("OrderBy"       , $this->OrderBy);
+
+        /* Display sort arrow */
+        if($this->SortType == "up"){
+          $smarty->assign("SortType","<img src='images/sort_up.png' alt='"._("up")."' border='0'>");
+        }else{
+          $smarty->assign("SortType","<img src='images/sort_down.png' alt='"._("down")."' border='0'>");
+        }
+      }
+    }
 
-      /* */
-      $entries = $mailQueueParser->GetAll(); 
-      $smarty->assign("entries"       , array_slice($entries,$this->Page,20));
+    if($error){  
+      $smarty->assign("all_ok"        , "false");
       $smarty->assign("plug"          , "?plug=".$_GET['plug']);
       $smarty->assign("p_server"      , $this->Server);
       $smarty->assign("p_servers"     , $this->getServer());
@@ -74,19 +141,7 @@ class mailqueue extends plugin
       $smarty->assign("p_times"       , $this->getTimes());
       $smarty->assign("p_timeKeys"    , array_flip($this->getTimes()));
       $smarty->assign("search_for"    , $this->Search);
-      $smarty->assign("range_selector", range_selector(count($entries), $this->Page, 20)); 
       $smarty->assign("OrderBy"       , $this->OrderBy);
-
-      /* Display sort arrow */
-      if($this->SortType == "up"){
-        $smarty->assign("SortType","<img src='images/sort_up.png' alt='"._("up")."' border='0'>");
-      }else{
-        $smarty->assign("SortType","<img src='images/sort_down.png' alt='"._("down")."' border='0'>");
-      }
-    }else{
-      $smarty->assign("entries",array());
-      print_red(_("Please check your 'gosa.conf' the value for 'MAILQUEUE_QUERY_COMMAND' can't be executed."));
     }
     return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
   }
index eabba97a7d64893a8f0eb612d0bd8f4d3b43d85d..c7f687e8d0281bbaf1c6d5b33184c0671604db7f 100644 (file)
@@ -9,10 +9,11 @@ class parseMailQueue
   /* Contructor
    * $s_data specifies the data that shuold be parse
    */
-       function parseMailQueue($s_data)
+       function parseMailQueue($s_data,$server)
        {
     $this->s_dataToParse = $s_data;            
-         $this->_parse();
+         $this->a_parsedData = array();
+    $this->_parse($s_data,$server);
   }
 
 
@@ -75,9 +76,8 @@ class parseMailQueue
   function OrderBy($str = "Arrival",$type = "up" )
   {
     $tmp = array();
-
     /* If the given field is not valid */
-    if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error"))){
+    if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error","Server"))){
       return(false);
     }
 
@@ -89,12 +89,12 @@ class parseMailQueue
         for($i = strlen($data['Size']); $i < 10 ; $i++  ){
           $struse .="0";
         }
-        $struse .= $data[$str].$data['MailID'];
+        $struse .= $data[$str].$data['MailID'].$data['Server'];
         $tmp[$struse]= $data;
       }
     }else{
       foreach($this->a_parsedData as $data){
-        $tmp[strtolower($data[$str]).$data['MailID']]= $data;
+        $tmp[strtolower($data[$str]).$data['MailID']."-".$data['Server']]= $data;
       }
     } 
     ksort($tmp);
@@ -103,8 +103,9 @@ class parseMailQueue
     }
     $this->a_parsedData = array();
     foreach($tmp as $data){
-      $this->a_parsedData[$data['MailID']] = $data;
+      $this->a_parsedData[$data['MailID']."-".$data['Server']] = $data;
     }
+    return(true);
   }
   
   function GetAll()
@@ -118,10 +119,15 @@ class parseMailQueue
     return(((isset($this->a_parsedData[$id]))&&(is_array($this->a_parsedData[$id]))));
   }
 
+  function parseAdditionalQueue($str, $server)
+  {
+    $this->_parse($str, $server);
+  }
+
   /* This function parses the given data 
    * it creates an array with all given queue entries
    */
-  function _parse()
+  function _parse($str, $server)
   {
     $i              =  0;       // Temp var 
     $entries        = array();  // Contains an array with the raw data for every single entry
@@ -136,7 +142,7 @@ class parseMailQueue
 
     /* Remove header
      */
-    $this->s_dataToParse = preg_replace("/^.*------\n/","",$this->s_dataToParse);
+    $this->s_dataToParse = preg_replace("/^.*------\n/","",$str);
 
     /* Create array with single entries
      */
@@ -172,12 +178,13 @@ class parseMailQueue
       $s_Recipient  = $s_buffer[2];
 
       /* Append data */
-      $this->a_parsedData[$s_mailID]['MailID']     = $s_mailID; 
-      $this->a_parsedData[$s_mailID]['Size']       = $s_Size; 
-      $this->a_parsedData[$s_mailID]['Arrival']    = $s_Arrival; 
-      $this->a_parsedData[$s_mailID]['Sender']     = $s_Sender; 
-      $this->a_parsedData[$s_mailID]['Recipient']  = $s_Recipient; 
-      $this->a_parsedData[$s_mailID]['Error']      = $this->_parseError($s_Error); 
+      $this->a_parsedData[$s_mailID."-".$server]['Server']     = $server; 
+      $this->a_parsedData[$s_mailID."-".$server]['MailID']     = $s_mailID; 
+      $this->a_parsedData[$s_mailID."-".$server]['Size']       = $s_Size; 
+      $this->a_parsedData[$s_mailID."-".$server]['Arrival']    = $s_Arrival; 
+      $this->a_parsedData[$s_mailID."-".$server]['Sender']     = $s_Sender; 
+      $this->a_parsedData[$s_mailID."-".$server]['Recipient']  = $s_Recipient; 
+      $this->a_parsedData[$s_mailID."-".$server]['Error']      = $this->_parseError($s_Error); 
     }
     return($this->a_parsedData);
   }
index 29fb6401d314bd6412feea0d60b0422cf0c11e89..947270e4c14863c5cb56ea3656dfb97c7689f81d 100644 (file)
  </p>
 </div>
 <br>
+
+{if $all_ok != "true"}
+<b>{t}Search returned no results{/t}...</b>
+{else}
+
 <table style="border: 1px solid rgb(176, 176, 176); width: 100%; vertical-align: top; text-align: left;"
  border="0" cellpadding="2" cellspacing="1" rules="cols">
        <tr style="background-color: rgb(232, 232, 232); height: 26px; font-weight: bold;">
                <td><a href="{$plug}&sort=MailID"               >{t}ID{/t}                      {if $OrderBy == "MailID"}       {$SortType}{/if}</a></td>
+               <td><a href="{$plug}&sort=Server"               >{t}Server{/t}          {if $OrderBy == "Server"}       {$SortType}{/if}</a></td>
                <td><a href="{$plug}&sort=Size"                 >{t}Size{/t}            {if $OrderBy == "Size"}         {$SortType}{/if}</a></td>
                <td><a href="{$plug}&sort=Arrival"              >{t}Arrival{/t}         {if $OrderBy == "Arrival"}      {$SortType}{/if}</a></td>
                <td><a href="{$plug}&sort=Sender"               >{t}Sender{/t}          {if $OrderBy == "Sender"}       {$SortType}{/if}</a></td>
                <tr style="height: 22px; background-color: rgb(245, 245, 245);">
        {/if}
                <td>{$entries[$key].MailID}</td>
+               <td>{$entries[$key].Server}</td>
                <td>{$entries[$key].Size}</td>
                <td>{$entries[$key].Arrival}</td>
                <td>{$entries[$key].Sender}</td>
                <td>{$entries[$key].Recipient}</td>
                <td titel="{$entries[$key].Error}">{$entries[$key].Error}</td>
-               <td><a href="{$plug}&del={$entries[$key].MailID}"><img src="images/edittrash.png" border=0 alt="deleted"></a></td>
+               <td><a href="{$plug}&del={$key}"><img src="images/edittrash.png" border=0 alt="deleted"></a></td>
        </tr>
        {counter}
 {/foreach}
@@ -61,4 +68,5 @@
  &nbsp;
 </p>
 
+{/if}