Code

Updated placeholder handling in templates, case is ignored now.
[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;
32     
33         $this->initTime = microtime(TRUE);
35         /* Try to fetch logs for the given event (mac)
36          */
37         $this->o_queue = new gosaSupportDaemon();
39         /* Load ldap object if given 
40            and use this macAddress.
41          */
42         if(is_object($parent) && $dn != "" && $dn != "new"){
43             plugin::plugin($config,$dn,$parent);
44         } 
46         /* Get correct macAddress.
47            Check if an event is given or a ldap object.
48          */      
49         if(is_array($this->parent) && isset($this->parent['MACADDRESS'])){
50             $this->mac = $this->parent['MACADDRESS'];
51             $this->standalone = TRUE;
52         }elseif(isset($parent->attrs['macAddress'][0])){
53             $this->mac = $parent->attrs['macAddress'][0];
54             $this->standalone = FALSE;
55         }
57         /* Query for log files
58          */
59         $res = $this->o_queue->get_log_info_for_mac($this->mac);
60         if($this->o_queue->is_configured() && $this->o_queue->is_error()){
61             msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
62         }else{
63             $tmp = array();
64             foreach($res as $mac => $logs){
65                 if($mac != $this->mac) continue;
67                 foreach($logs as $name => $log){
68                     if(isset($log['FILES'])){
69                         foreach($log['FILES'] as $fkey => $fval){
70                             $tmp[] = array(
71                                     'MAC'     => $mac,
72                                     'DATE'    => $log['REAL_DATE'],
73                                     'DATE_STR'=> $log['DATE_STR'],
74                                     'FILE'    => $fval);
75                         }
76                     }
77                 }
78             } 
80             /* Check if there is at least one log file 
81              */
82             $this->logs = $tmp;
83         }
85         // Create the filter list
86         $this->logSelector= new sortableListing($this->logs, $this->convertFilterList($this->logs));
87         $this->logSelector->setDeleteable(false);
88         $this->logSelector->setEditable(true);
89         $this->logSelector->setAcl("rwcdm");
90         $this->logSelector->setWidth("100%");
91         $this->logSelector->setHeight("120px");
92         $this->logSelector->setHeader(array(_("Date"),_("Filename")));
93         $this->logSelector->setColspecs(array('80px', '100px', '200px', '120px','150px'));
94     }
97     /*! \brief    Converts the list of filters ($this->filters) into data which is useable
98      *             for the sortableList object ($this->filterWidget).
99      *  @return   Array   An array containg data useable for sortableLists ($this->filterWidget)
100      */
101     function convertFilterList($logs)
102     {
103         $data = array();
104         foreach($logs as $key => $log){
105             $data[$key] = array('data' => 
106                     array(date('d.m.Y H:i:s',$log['DATE']),$log['FILE']));
107         }
108         return($data);
109     }
112     function execute()
113     {
114         plugin::execute();
116         // Act on edit requests
117         $this->logSelector->save_object();
118         $action = $this->logSelector->getAction();
120         if(isset($action['action']) && $action['action'] == 'edit'){
121             $id = $action['targets'][0];
122             $entry = $this->logs[$id];
123             $this->selected_file = $entry['FILE'];
124             $this->selected_date = $entry['DATE'];
125         }
128         $smarty = get_smarty();
129         $smarty->assign("logs",            $this->logs);   
130         $smarty->assign("logs_available",  count($this->logs));
131         $smarty->assign("mac",             set_post($this->mac));
132         $smarty->assign("selected_file",   set_post($this->selected_file));
133         $smarty->assign("selected_date",   set_post($this->selected_date));
134         $smarty->assign("log_file",        $this->get_log($this->mac,$this->selected_date,$this->selected_file));        
135         $smarty->assign("standalone",      $this->standalone);
136         if (isset($this->logs[$this->mac])){
137             $date = date("d.m.Y H:i:s",$this->logs[$this->mac][$this->selected_date]['REAL_DATE']);
138         }
139         $file = $this->selected_file;
140         $smarty->assign("selected_log",_("none"));
141         if(!empty($file)){
142             $smarty->assign("selected_log", $file.", ".date('d.m.Y H:i:s', $this->selected_date));
143         }
144         $smarty->assign("ACL",preg_match("/r/",$this->getacl("")));
145         $this->logSelector->setAcl($this->getacl(""));
146         $smarty->assign("listing", $this->logSelector->render());
147         return($smarty->fetch(get_template_path('log_view.tpl', TRUE,dirname(__FILE__))));
148     }
151     function get_log($mac,$date,$file)
152     {
153         $res = $this->o_queue->get_log_file($mac,$date,$file);
154         if($this->o_queue->is_configured() && $this->o_queue->is_error()){
155             msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
156         }
157         $res = nl2br(htmlentities($res));
158         return($res);
159     }
162     function save_object()
163     {
164         foreach(array("time"=>"selected_date","file"=>"selected_file") as $attr => $dest){
165             if(isset($_GET[$attr])){
166                 $this->$dest = $_GET[$attr];
167             }
168         }
169         if(isset($_GET['sort_by']) && in_array($_GET['sort_by'],array("file","time"))){
170             if($_GET['sort_by'] == $this->sort_by){
171                 $this->sort_dir = !$this->sort_dir;
172             }
173             $this->sort_by = $_GET['sort_by'];
174         }
175     }
178     /* Return plugin informations for acl handling */
179     static function plInfo()
180     {
181         return (array(
182                     "plShortName"   => _("Log view"),
183                     "plDescription" => _("GOto log view"),
184                     "plSelfModify"  => FALSE,
185                     "plDepends"     => array(),
186                     "plPriority"    => 30,
187                     "plSection"     => array("administration"),
188                     "plCategory"    => array("workstation","server"),
190                     "plProvidedAcls"=> array()
191                     ));
192     }
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>