Code

Fixed post handling.
[gosa.git] / gosa-plugins / goto / addons / goto / class_gotoLogView.inc
1 <?php
3 class gotoLogView extends plugin
4 {
6     var $mac;
7     var $event;
8     var $parent;
9     var $config;
11     var $o_queue;  
13     var $selected_date;
14     var $selected_file = 0;
16     var $attributes = array("macAddress");
17     var $macAddress = "";
19     var $sort_by  = "time";
20     var $sort_dir = 1; // 1 => up, 0 => down
22     var $ignore_account = TRUE;
23     var $standalone = FALSE;
25     var $logs = array();
26     var $logSelector = NULL;
28     function __construct(&$config,$dn,$parent)
29     {
30         $this->config = $config;
31         $this->parent = $parent;
33         /* Try to fetch logs for the given event (mac)
34          */
35         $this->o_queue = new gosaSupportDaemon();
37         /* Load ldap object if given 
38            and use this macAddress.
39          */
40         if(is_object($parent) && $dn != "" && $dn != "new"){
41             plugin::plugin($config,$dn,$parent);
42         } 
44         /* Get correct macAddress.
45            Check if an event is given or a ldap object.
46          */      
47         if(is_array($this->parent) && isset($this->parent['MACADDRESS'])){
48             $this->mac = $this->parent['MACADDRESS'];
49             $this->standalone = TRUE;
50         }elseif(isset($parent->attrs['macAddress'][0])){
51             $this->mac = $parent->attrs['macAddress'][0];
52             $this->standalone = FALSE;
53         }
55         /* Query for log files
56          */
57         $res = $this->o_queue->get_log_info_for_mac($this->mac);
58         if($this->o_queue->is_configured() && $this->o_queue->is_error()){
59             msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
60         }else{
61             $tmp = array();
62             foreach($res as $mac => $logs){
63                 if($mac != $this->mac) continue;
65                 foreach($logs as $name => $log){
66                     if(isset($log['FILES'])){
67                         foreach($log['FILES'] as $fkey => $fval){
68                             $tmp[] = array(
69                                     'MAC'     => $mac,
70                                     'DATE'    => $log['REAL_DATE'],
71                                     'DATE_STR'=> $log['DATE_STR'],
72                                     'FILE'    => $fval);
73                         }
74                     }
75                 }
76             } 
78             /* Check if there is at least one log file 
79              */
80             $this->logs = $tmp;
81         }
83         // Create the filter list
84         $this->logSelector= new sortableListing($this->logs, $this->convertFilterList($this->logs));
85         $this->logSelector->setDeleteable(false);
86         $this->logSelector->setEditable(true);
87         $this->logSelector->setAcl("rwcdm");
88         $this->logSelector->setWidth("100%");
89         $this->logSelector->setHeight("120px");
90         $this->logSelector->setHeader(array(_("Date"),_("Filename")));
91         $this->logSelector->setColspecs(array('80px', '100px', '200px', '120px','150px'));
92     }
95     /*! \brief    Converts the list of filters ($this->filters) into data which is useable
96      *             for the sortableList object ($this->filterWidget).
97      *  @return   Array   An array containg data useable for sortableLists ($this->filterWidget)
98      */
99     function convertFilterList($logs)
100     {
101         $data = array();
102         foreach($logs as $key => $log){
103             $data[$key] = array('data' => 
104                     array(date('d.m.Y H:i:s',$log['DATE']),$log['FILE']));
105         }
106         return($data);
107     }
110     function execute()
111     {
112         plugin::execute();
114         // Act on edit requests
115         $this->logSelector->save_object();
116         $action = $this->logSelector->getAction();
118         if(isset($action['action']) && $action['action'] == 'edit'){
119             $id = $action['targets'][0];
120             $entry = $this->logs[$id];
121             $this->selected_file = $entry['FILE'];
122             $this->selected_date = $entry['DATE'];
123         }
126         $smarty = get_smarty();
127         $smarty->assign("logs",            $this->logs);   
128         $smarty->assign("logs_available",  count($this->logs));
129         $smarty->assign("mac",             set_post($this->mac));
130         $smarty->assign("selected_file",   set_post($this->selected_file));
131         $smarty->assign("selected_date",   set_post($this->selected_date));
132         $smarty->assign("log_file",        $this->get_log($this->mac,$this->selected_date,$this->selected_file));        
133         $smarty->assign("standalone",      $this->standalone);
134         if (isset($this->logs[$this->mac])){
135             $date = date("d.m.Y H:i:s",$this->logs[$this->mac][$this->selected_date]['REAL_DATE']);
136         }
137         $file = $this->selected_file;
138         $smarty->assign("selected_log",_("none"));
139         if(!empty($file)){
140             $smarty->assign("selected_log", $file.", ".date('d.m.Y H:i:s', $this->selected_date));
141         }
142         $smarty->assign("ACL",preg_match("/r/",$this->getacl("")));
143         $this->logSelector->setAcl($this->getacl(""));
144         $smarty->assign("listing", $this->logSelector->render());
145         return($smarty->fetch(get_template_path('log_view.tpl', TRUE,dirname(__FILE__))));
146     }
149     function get_log($mac,$date,$file)
150     {
151         $res = $this->o_queue->get_log_file($mac,$date,$file);
152         if($this->o_queue->is_configured() && $this->o_queue->is_error()){
153             msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
154         }
155         $res = nl2br(htmlentities($res));
156         return($res);
157     }
160     function save_object()
161     {
162         foreach(array("time"=>"selected_date","file"=>"selected_file") as $attr => $dest){
163             if(isset($_GET[$attr])){
164                 $this->$dest = $_GET[$attr];
165             }
166         }
167         if(isset($_GET['sort_by']) && in_array($_GET['sort_by'],array("file","time"))){
168             if($_GET['sort_by'] == $this->sort_by){
169                 $this->sort_dir = !$this->sort_dir;
170             }
171             $this->sort_by = $_GET['sort_by'];
172         }
173     }
176     /* Return plugin informations for acl handling */
177     static function plInfo()
178     {
179         return (array(
180                     "plShortName"   => _("Log view"),
181                     "plDescription" => _("GOto log view"),
182                     "plSelfModify"  => FALSE,
183                     "plDepends"     => array(),
184                     "plPriority"    => 30,
185                     "plSection"     => array("administration"),
186                     "plCategory"    => array("workstation","server"),
188                     "plProvidedAcls"=> array()
189                     ));
190     }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>