Code

Updated mailqueue text
[gosa.git] / gosa-plugins / mail / addons / mailqueue / class_mailqueue.inc
1 <?php
3 class mailqueue extends plugin
4 {
5   /* Definitions */
6   var $plHeadline     = "Mail queue";
7   var $plDescription  = "This does something";
8   var $plIcon         = "plugins/mail/images/mailqueue.png";
10   /* attribute list for save action */
11   var $attributes     = array();
12   var $objectclasses  = array();
14   var $Server         = "all";
15   var $ServerList     = array(); // The list of all available servers.
16   var $Search         = "*";
17   var $Time           = 0;
18   var $Page           = 0;
19   var $Stat           = "all";
20   var $OrderBy        = "Arrival";
21   var $SortType       = "up";
22   var $disp_header    = false;
23   var $range          = 20;   
25   /* Logging detection */
26   var $view_logged    = FALSE;
28   function mailqueue(&$config, $dn= NULL)
29   {
30     $this->config   = &$config;
31     $this->si_queue = new si_mailqueue($this->config);
32     $this->getServer();
33   }
36   function execute()
37   {
38     /* Call parent execute */
39     plugin::execute();
41     /* Log view */
42     if(!$this->view_logged){
43       $this->view_logged = TRUE;
44       new log("view","mailqueue/".get_class($this),$this->dn);
45     }
47     $smarty= get_smarty();
48     $error =false;
50     /******************
51       Handle options 
52      ******************/
54     $action = $server = $entry = "";
55     $types = array("delete","hold","unhold","header","requeue");
56     foreach($_POST as $name => $value){
57       foreach($types as $type){
58         if(preg_match("/^".$type."__/",$name)){
59           $action = $type;
60           $entry  = preg_replace("/^".$type."__([^_]*)__.*/","\\1",$name); 
61           $server = preg_replace("/^".$type."__[^_]*__([^_]*)_.*/","\\1",$name); 
62           break;
63         }
64       }
65     }
67     /* Send action for given mail id */
68     if(in_array($action,array("hold","unhold","requeue"))){
69       $this->si_queue->send_queue_action(array($entry),$server,$action);
70     }
73     /******************
74       Display mail header
75      ******************/
77     if($action == "header"){
79       /* Create table which displays the header informations */
80       $this->disp_header = $this->si_queue->header($entry);
81     }
83     /* Back is posted from the header display page */
84     if(isset($_POST['back'])){
85       $this->disp_header = false;
86     }
88     /* If there is a header in disp_header, then display it */
89     if($this->disp_header){
90       $smarty->assign("header",$this->disp_header);
91       return ($smarty->fetch (get_template_path('header.tpl', TRUE)));
92     }
95     /******************
96       Query mailqueues 
97      ******************/
99     if($this->Server == "all"){
100       $entries = array();
101       foreach($this->ServerList as $mac => $name){
102         if(!tests::is_mac($mac)) continue;
103         $entries = array_merge($entries,$this->si_queue->query_mailqueue($mac,$this->OrderBy,$this->SortType,$this->range));
104         if($this->si_queue->is_error()){
105           unset($this->ServerList[$mac]);
106           msg_dialog::display(_("Error"),sprintf(_("The server '%s' was removed from the server list, due to communication problems with the GOsa daemon, the error was: %s"),$name,"<b>".msgPool::siError($this->si_queue->get_error()."</b>")),ERROR_DIALOG);
107         }
108       }
109     }else{
110       $entries = $this->si_queue->query_mailqueue($this->Server,$this->OrderBy,$this->SortType,$this->Limit);
111       if($this->si_queue->is_error()){
112         msg_dialog::display(_("Error"),msgPool::siError($this->si_queue->get_error()),ERROR_DIALOG);
113       }
114     }
116     
117     /******************
118       create html output 
119      ******************/
121     $smarty->assign("all_ok"        , count($entries));
122     $smarty->assign("entries"       , $entries);
123     $smarty->assign("plug"          , "?plug=".$_GET['plug']);
125     $smarty->assign("r_stats"       , $this->getStats());
126     $smarty->assign("stats"         , array_flip($this->getStats()));
128     $smarty->assign("stat"          , $this->Stat);
129     $smarty->assign("p_server"      , $this->Server);
130     $smarty->assign("p_servers"     , $this->ServerList);
131     $smarty->assign("p_serverKeys"  , array_flip($this->ServerList));
132     $smarty->assign("p_time"        , $this->Time);
133     $smarty->assign("p_times"       , $this->getTimes());
134     $smarty->assign("p_timeKeys"    , array_flip($this->getTimes()));
135     $smarty->assign("search_for"    , $this->Search);
136     $smarty->assign("range_selector", range_selector(count($entries), $this->Page, $this->range,"EntriesPerPage")); 
137     $smarty->assign("OrderBy"       , $this->OrderBy);
139     /* Display sort arrow */
140     if($this->SortType == "up"){
141       $smarty->assign("SortType","<img src='images/lists/sort-up.png' alt='"._("up")."' border='0'>");
142     }else{
143       $smarty->assign("SortType","<img src='images/lists/sort-down.png' alt='"._("down")."' border='0'>");
144     }
145     return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
146   }
149   /* return selectable server 
150    */
151   function getServer()
152   {
153     $ret= array("all"=>_("All"));
155     /* First of all, detect all servers that supports the mailqueue extension 
156         -If this fails, the mailqueue(s) can't be queried.
157      */
158     $hosts          = $this->si_queue->get_hosts_with_module("mailqueue_com");
159     $this->si_error = $this->si_queue->is_error();
160     if(!count($hosts)){
161       return(array());
162     }    
164     /* Create search filter and try to resolv mac to hostname 
165      */
166     $filter = "";
167     foreach($hosts as $mac){
168       $filter .= "(macAddress=".$mac.")";
169     }
170     $filter = "(&(objectClass=GOhard)(|".$filter."))";
171     $res = get_list($filter,"no_acls",$this->config->current['BASE'],
172         array("cn","macAddress"),GL_SUBSEARCH | GL_NO_ACL_CHECK); 
174     /* Create result array 
175      */
176     foreach($hosts as $mac){
177       $found = FALSE;
178       foreach($res as $entry){
179         if(preg_match("/^".normalizePreg($mac)."$/i",$entry['macAddress'][0])){
180           $ret[$mac] = $entry['cn'][0];
181           $found = TRUE;
182           break;
183         }
184       }
185       if(!$found){
186         $ret[$mac] = $mac;
187       }
188     }
189     $this->ServerList = $ret;
190   }
193   /* Return selectable times*/
194   function getTimes()
195   {
196     $ret = array();
197     $ret['nolimit']=_("no limit"); 
198     foreach(array(1,2,4,8,12,24,36,48) as $i){
199       if($i == 1){
200         $ret[$i] = $i."&nbsp;"._("hour");
201       }else{
202         $ret[$i] = $i."&nbsp;"._("hours");
203       }
204     }
205     return($ret);
206   }
209   /* Save post values*/
210   function save_object($save_current= FALSE)
211   {
212     /* Update amount of entries displayed */
213     if(isset($_POST['EntriesPerPage'])){
214       $this->range = $_POST['EntriesPerPage'];
215     }
217     if(isset($_POST['p_server']) && isset($this->ServerList[$_POST['p_server']])){
218       $this->Server = $_POST['p_server'];
219     }
221     if(isset($_POST['p_time'])){
222       $this->Time = $_POST['p_time'];
223     }
224     if(isset($_POST['search_for'])){
225       $this->Search = $_POST['search_for'];
226     }
227     if(isset($_POST['Stat'])){
228       $this->Stat = $_POST['Stat'];
229     }
230     if((isset($_GET['start']))&&(is_numeric($_GET['start']))&&($_GET['start']>=0)){
231       $this->Page = $_GET['start'];
232     }
234     if((isset($_GET['sort']))&&(!empty($_GET['sort']))){
235       $old = $this->OrderBy;
236       $this->OrderBy = $_GET['sort'];
237       if($this->OrderBy == $old)
238       {
239         if($this->SortType== "up"){
240           $this->SortType = "down";
241         }else{
242           $this->SortType = "up";
243         }
244       }
245     }
247   }
249   /* Return stats */
250   function getStats()
251   {
252     return(array(
253           "all"     =>_("All"),
254           "hold"    =>_("Hold"),
255           "unhold"  =>_("Un hold"),
256           "active"  =>_("Active"),
257           "nonactive"  =>_("Not active")
258           ));
259   }
261   /* Return plugin informations for acl handling
262      #FIXME You can only read attributes within this report plugin */
263   static function plInfo()
264   {
265     return (array(
266         "plShortName"   => _("Mail queue"),
267         "plDescription" => _("Mail queue addon"),
268         "plSelfModify"  => FALSE,
269         "plDepends"     => array(),
270         "plPriority"    => 1,
271         "plSection"     => array("addon"),
272         "plCategory"    => array("mailqueue" => array("objectClass" => "none", "description" => _("Mail queue addon"))),
274         "plProvidedAcls" => array(
275             "unhold_all"      => _("Unhold all messages"),
276             "hold_all"        => _("Hold all messages"),
277             "del_all"         => _("Delete all messages"),
278             "requeue_all"     => _("Requeue all messages"),
279             "unhold"          => _("Unhold message"),
280             "hold"            => _("Hold message"),
281             "del"             => _("Delete message"),
282             "requeue"         => _("Requeue message"),
283             "query"           => _("Gathering queue data"),
284             "header"          => _("Get header information")
285           )
286         ));
287   }
292 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
293 ?>