From: hickert Date: Tue, 4 Mar 2008 14:40:05 +0000 (+0000) Subject: Updated log view. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a7becb3b88ca478adac43ef54fcfc5d0d9eaf062;p=gosa.git Updated log view. -A message will be shown now, if the database isn't up to date git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9324 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/log/addons/logview/class_gosa_logview.inc b/gosa-plugins/log/addons/logview/class_gosa_logview.inc index 2e98fcad9..856af273e 100644 --- a/gosa-plugins/log/addons/logview/class_gosa_logview.inc +++ b/gosa-plugins/log/addons/logview/class_gosa_logview.inc @@ -207,6 +207,14 @@ class gosa_logview extends plugin return ($smarty->fetch (get_template_path('gosa_log_contents.tpl', TRUE))); } + /* Prepare order setting */ + if ($this->sort_direction == "down"){ + $desc= "DESC"; + $sort_sign = "\/"; + } else { + $desc= ""; + $sort_sign = "/\"; + } /**** * Query stuff @@ -222,64 +230,73 @@ class gosa_logview extends plugin } else { if (! @mysql_select_db($cfg['DB'])){ - msg_dialog::display(_("Error"), sprintf(_("Cannot select %s database!"), "GOsa LOG"), ERROR_DIALOG); + msg_dialog::display(_("Error"), sprintf(_("Cannot select %s database!"), "GOsa LOG"), ERROR_DIALOG); new log("debug","logview","",array(),@mysql_error()); } else { - /* Prepare order setting */ - if ($this->sort_direction == "down"){ - $desc= "DESC"; - $sort_sign = "\/"; - } else { - $desc= ""; - $sort_sign = "/\"; + /* Check for required tables + */ + $query = "SHOW TABLES;"; + $res = @mysql_query($query,$con); + $tables = array(); + while($attrs = @mysql_fetch_row($res)){ + $tables[] = $attrs[0]; } + $error = FALSE; + foreach(array("gosa_log","gosa_locations") as $required){ + if(!in_array($required,$tables)){ + msg_dialog::display(_("Error"), + sprintf(_("Missing logging table (%s.%s) update your GOsa logging database schema."), + $cfg['DB'],$required), ERROR_DIALOG); + $error = TRUE; + } + } + if(!$error){ - /* Get start time */ - $start = $date_select_[$this->time]; - - /* Prepare search filter */ - $sql_regex =trim(preg_replace("/\*/","%",$this->regex)); - $sql_regex = "%".trim($sql_regex,"%")."%"; + /* Get start time */ + $start = $date_select_[$this->time]; - /* Create search filter */ - $query_base= "FROM gosa_log WHERE timestamp >= $start "; - - /* Append action filter */ - if($this->action != "!ALL"){ - $query_base .=" AND action like '".$this->action."' "; - } + /* Prepare search filter */ + $sql_regex =trim(preg_replace("/\*/","%",$this->regex)); + $sql_regex = "%".trim($sql_regex,"%")."%"; - /* Append search filter */ - if($sql_regex != "%%"){ - $query_base .=" AND ( result like '".$sql_regex."' OR user like '".$sql_regex."') "; - } + /* Create search filter */ + $query_base= "FROM gosa_log WHERE timestamp >= $start "; - /* Appen location */ - $query_base .= " AND location_id='".$this->location_id."' "; + /* Append action filter */ + if($this->action != "!ALL"){ + $query_base .=" AND action like '".$this->action."' "; + } - /* Get number of entries */ - $query= "SELECT COUNT(`user`) ".$query_base.";"; - $result = mysql_query($query); - if(!$result){ - new log("debug","logview","",array(),@mysql_error()); - } - $line= mysql_fetch_array($result, MYSQL_ASSOC); - $count= $line['COUNT(`user`)']; - if ($count > 25){ - $smarty->assign("range_selector", range_selector($count, $this->start, $this->range,"EntriesPerPage")); - } else { - $smarty->assign("range_selector", ""); - } + /* Append search filter */ + if($sql_regex != "%%"){ + $query_base .=" AND ( result like '".$sql_regex."' OR user like '".$sql_regex."') "; + } - /* Query results that will be displayed */ - $query= "SELECT * ".$query_base." ORDER BY ".$this->fields[$this->sort]." ".$desc." LIMIT ".$this->start.",".$this->range.";"; - @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__, $query, "Database query"); - $result = @mysql_query($query); - if(!$result){ - new log("debug","logview","",array(),@mysql_error()); - msg_dialog::display(_("Error"), sprintf(_("Cannot query %s database!"), "GOsa LOG"), ERROR_DIALOG); - }else{ + /* Appen location */ + $query_base .= " AND location_id='".$this->location_id."' "; + + /* Get number of entries */ + $query= "SELECT COUNT(`user`) ".$query_base.";"; + $result = mysql_query($query); + if(!$result){ + new log("debug","logview","",array(),@mysql_error()); + } + $line= mysql_fetch_array($result, MYSQL_ASSOC); + $count= $line['COUNT(`user`)']; + if ($count > 25){ + $smarty->assign("range_selector", range_selector($count, $this->start, $this->range,"EntriesPerPage")); + } else { + $smarty->assign("range_selector", ""); + } + + /* Query results that will be displayed */ + $query= "SELECT * ".$query_base." ORDER BY ".$this->fields[$this->sort]." ".$desc." LIMIT ".$this->start.",".$this->range.";"; + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__, $query, "Database query"); + $result = @mysql_query($query); + if(!$result){ + new log("debug","logview","",array(),@mysql_error()); + } /* Display results */ $mod= 0;