1 <?php
3 class gotoLogView extends plugin
4 {
6 var $mac;
7 var $logs;
8 var $event;
9 var $parent;
10 var $config;
12 var $o_queue;
14 var $selected_date;
15 var $selected_file = 0;
16 var $selected_type;
18 var $attributes = array("macAddress");
19 var $macAddress = "";
21 var $sort_by = "time";
22 var $sort_dir = 1; // 1 => up, 0 => down
24 var $ignore_account = TRUE;
25 var $standalone = FALSE;
27 function __construct(&$config,$dn,$parent)
28 {
29 $this->config = $config;
30 $this->parent = $parent;
32 /* Try to fetch logs for the given event (mac)
33 */
34 $this->o_queue = new gosaSupportDaemon();
36 /* Load ldap object if given
37 and use this macAddress.
38 */
39 if(is_object($parent) && $dn != "" && $dn != "new"){
40 plugin::plugin($config,$dn,$parent);
41 }
43 /* Get correct macAddress.
44 Check if an event is given or a ldap object.
45 */
46 if(is_array($this->parent) && isset($this->parent['MACADDRESS'])){
47 $this->mac = $this->parent['MACADDRESS'];
48 $this->standalone = TRUE;
49 }elseif(isset($parent->attrs['macAddress'][0])){
50 $this->mac = $parent->attrs['macAddress'][0];
51 $this->standalone = FALSE;
52 }
54 /* Query for log files
55 */
56 $res = $this->o_queue->get_log_info_for_mac($this->mac);
57 if($this->o_queue->is_configured() && $this->o_queue->is_error()){
58 msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
59 }
61 /* Check if there is at least one log file
62 */
63 if(!isset($res[$this->mac]) || !is_array($res[$this->mac])){
64 $this->logs = array();
65 }else{
66 $this->selected_date = key($res[$this->mac]);
67 $this->logs = $res;
68 }
70 }
73 function execute()
74 {
75 $smarty = get_smarty();
76 $smarty->assign("logs",$this->logs);
77 $smarty->assign("logs_available", isset($this->logs[$this->mac]));
78 $smarty->assign("mac",$this->mac);
79 $smarty->assign("selected_file",$this->selected_file);
80 $smarty->assign("selected_date",$this->selected_date);
81 $smarty->assign("selected_type",$this->selected_type);
82 $smarty->assign("log_file", $this->get_log($this->mac,$this->selected_date,$this->selected_file, $this->selected_type));
83 $smarty->assign("standalone",$this->standalone);
85 if (isset($this->logs[$this->mac])){
86 $date = date("d.m.Y H:i:s",$this->logs[$this->mac][$this->selected_date]['REAL_DATE']);
87 }
88 if (isset($this->logs[$this->mac])){
89 $type = $this->logs[$this->mac][$this->selected_date]['FAI_ACTION'];
90 }
91 $file = $this->selected_file;
92 $smarty->assign("selected_log",_("none"));
93 if(!empty($file)){
94 $smarty->assign("selected_log",$file.", ".$date);
95 }
97 $divlist = new divlist("log_view");
99 /* Create sort direction images
100 */
101 if($this->sort_dir){
102 $img = "<img src='images/lists/sort-down.png' border='0' alt='\\/'>";
103 }else{
104 $img = "<img src='images/lists/sort-up.png' border='0' alt='/\\'";
105 }
107 $file_img = "";
108 $type_img = "";
109 $date_img = "";
110 switch($this->sort_by) {
111 case "file":
112 $file_img = $img;
113 $type_img = "";
114 $date_img = "";
115 break;
116 case "time":
117 $date_img = $img;
118 $type_img = "";
119 $file_img = "";
120 break;
121 case "type":
122 $type_img = $img;
123 $date_img = "";
124 $file_img = "";
125 break;
126 }
128 /* Create list header
129 */
130 $divlist->SetHeader(array(
131 array("string"=>"<a href='?plug=".$_GET['plug']."&sort_by=file'>"._("File")." ".$file_img."</a>",
132 "attach"=>"width='200px;'"),
133 array("string"=>"<a href='?plug=".$_GET['plug']."&sort_by=type'>"._("Type")." ".$type_img."</a>",
134 "attach" => "style='border-right:none;'"),
135 array("string"=>"<a href='?plug=".$_GET['plug']."&sort_by=time'>"._("Date")." ".$date_img."</a>",
136 "attach" => "style='border-right:none;'"),
138 ));
140 /* Create divlist list
141 */
142 $divlist->SetEntriesPerPage(0);
143 $divlist->SetHeight(150);
145 /* Create sortable array
146 */
147 $link = "<a href='?plug=".$_GET['plug']."&time=%time%&file=%file%&mac=%mac%&type=%type%'>%str%</a>";
148 $to_add = array();
149 $sort_by = $this->sort_by;
150 foreach($this->logs as $mac => $times){
151 foreach($times as $time => $data){
152 $rtime = $data['REAL_DATE'];
153 $type = $data['FAI_ACTION'];
154 switch($type) {
155 case 'softupdate':
156 $type = _("Software update");
157 break;
158 case 'install':
159 $type = _("Installation");
160 break;
161 }
162 foreach($data['FILES'] as $file){
164 $highlight = "";
165 if($file == $this->selected_file && $time == $this->selected_date && $mac == $this->mac && $type == $this->selected_type){
166 $highlight = "background-color:#CCCCCC";
167 }
169 $use_link = preg_replace(array("/%mac%/","/%time%/","/%file%/"),array($mac,$time,$file),$link);
170 $to_add[$$sort_by.$file.$time] = array(
171 array("string" => preg_replace("/%str%/",$file,$use_link),
172 "attach" => "style='width:200px; $highlight'"),
173 array("string" => preg_replace("/%str%/",$type,$use_link),
174 "attach" => "style='width:200px; $highlight'"),
175 array("string" => preg_replace("/%str%/",date("d.m.Y H:i:s",$rtime),$use_link),
176 "attach" => "style='border-right:none; $highlight'"),
177 );
178 }
179 }
180 }
182 /* Sort entries
183 */
184 if(!$this->sort_dir){
185 uksort($to_add, "strnatcasecmp");
186 }else{
187 uksort($to_add, "strnatcasecmp");
188 $to_add = array_reverse($to_add);
189 }
191 /* Append entries to list
192 */
193 foreach($to_add as $entry){
194 $divlist->AddEntry($entry);
195 }
197 $smarty->assign("ACL",preg_match("/r/",$this->getacl("")));
198 $smarty->assign("divlist",$divlist->DrawList());
199 return($smarty->fetch(get_template_path('log_view.tpl', TRUE,dirname(__FILE__))));
200 }
203 function get_log($mac,$date,$file,$type)
204 {
205 $res = $this->o_queue->get_log_file($mac,$date,$file, $type);
206 if($this->o_queue->is_configured() && $this->o_queue->is_error()){
207 msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
208 }
209 $res = nl2br(htmlentities($res));
210 return($res);
211 }
214 function save_object()
215 {
216 foreach(array("time"=>"selected_date","file"=>"selected_file","type"=>"selected_type") as $attr => $dest){
217 if(isset($_GET[$attr])){
218 $this->$dest = $_GET[$attr];
219 }
220 }
221 if(isset($_GET['sort_by']) && in_array($_GET['sort_by'],array("file","time", "type"))){
222 if($_GET['sort_by'] == $this->sort_by){
223 $this->sort_dir = !$this->sort_dir;
224 }
225 $this->sort_by = $_GET['sort_by'];
226 }
227 }
230 /* Return plugin informations for acl handling */
231 static function plInfo()
232 {
233 return (array(
234 "plShortName" => _("Log view"),
235 "plDescription" => _("GOto log view"),
236 "plSelfModify" => FALSE,
237 "plDepends" => array(),
238 "plPriority" => 30,
239 "plSection" => array("administration"),
240 "plCategory" => array("workstation","server"),
242 "plProvidedAcls"=> array()
243 ));
244 }
245 }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>