2008-06-15 Esteban Sanchez <estebans@artica.es>

* include/functions_html.php: Added to repository. Implements HTML
        functions.

        * reporting/fgraph.php: Many style correction fixes, including those
        regardings tabs and blank spaces, variable names and indentation 
        levels for checkings. Improved dame_fecha(). Added date support to 
        graphic_combined_module(), grafico_modulo_sparse(). The selection of
        the graphic to show based on parameters has been replaced by a switch.
        The parameters are parsed with get_parameter()

        * include/functions_db.php: Style correction of tabs and blanks
        spaces. Use Pandora database functions on simple querying functions
        such as dame_perfil(), give_disabled_group(), dame_grupo(),  
        give_note_author(), dame_agente_id(), dame_agente_modulo_id() and many
        more, there are a lot more to change. Function comprueba_admin()
        renamed to check_admin (wrap created for old function). Added some
        checks to get_db_value(), get_db_row() so the SQL is build based on
        the parameter types. Added get_db_all_rows_sqlfree(),
        get_db_all_rows_in_table(), get_db_all_rows_field_filter(),
        get_db_all_fields_in_table(). Added date support to
        return_moduledata_avg_value(), return_moduledata_max_value(),
        return_moduledata_min_value(). Added function
        return_moduledata_sum_value() to get the sum of the values in a
        module.

        * include/functions.php: If input is numeric on safe_input, do not
        clean it, since it's safe by itself. Use mysql_escape_string() on
        salida_sql(). Added get_report_types(), get_report_name(),
        get_report_type_data_source() relatives to reports. Added also 
        is_module_data(), is_module_proc(), is_module_inc(),
        is_module_data_string() to know if a module is from a type. Replaced
        form_priority() with get_event_types() so the caller of this function  
        will print the select (using print_select).

        * operation/events/events.php: Replaced form_priorit() with
        get_event_types().

        * ChangeLog: Tab style correction with previous commit.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@863 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2008-06-16 10:45:08 +00:00
parent 9b5a2695bc
commit 5d800de367
6 changed files with 2246 additions and 1572 deletions

View File

@ -1,13 +1,55 @@
2008-06-15 Esteban Sanchez <estebans@artica.es>
* include/functions_html.php: Added to repository. Implements HTML
functions.
* reporting/fgraph.php: Many style correction fixes, including those
regardings tabs and blank spaces, variable names and indentation
levels for checkings. Improved dame_fecha(). Added date support to
graphic_combined_module(), grafico_modulo_sparse(). The selection of
the graphic to show based on parameters has been replaced by a switch.
The parameters are parsed with get_parameter()
* include/functions_db.php: Style correction of tabs and blanks
spaces. Use Pandora database functions on simple querying functions
such as dame_perfil(), give_disabled_group(), dame_grupo(),
give_note_author(), dame_agente_id(), dame_agente_modulo_id() and many
more, there are a lot more to change. Function comprueba_admin()
renamed to check_admin (wrap created for old function). Added some
checks to get_db_value(), get_db_row() so the SQL is build based on
the parameter types. Added get_db_all_rows_sqlfree(),
get_db_all_rows_in_table(), get_db_all_rows_field_filter(),
get_db_all_fields_in_table(). Added date support to
return_moduledata_avg_value(), return_moduledata_max_value(),
return_moduledata_min_value(). Added function
return_moduledata_sum_value() to get the sum of the values in a
module.
* include/functions.php: If input is numeric on safe_input, do not
clean it, since it's safe by itself. Use mysql_escape_string() on
salida_sql(). Added get_report_types(), get_report_name(),
get_report_type_data_source() relatives to reports. Added also
is_module_data(), is_module_proc(), is_module_inc(),
is_module_data_string() to know if a module is from a type. Replaced
form_priority() with get_event_types() so the caller of this function
will print the select (using print_select).
* operation/events/events.php: Replaced form_priorit() with
get_event_types().
* ChangeLog: Tab style correction with previous commit.
2008-06-13 Sancho Lerena <slerena@gmail.com>
* status_events: added to view new events in agentg view
* status_events: added to view new events in agentg view.
* index.php: Added pure (Fullscreen). HTML code cleanup and user session.
* index.php: Added pure (Fullscreen). HTML code cleanup and user
session.
* pandoradb.sql: talert_snmp: Added priority field.
* pandoradb_data.sql: Changes default values in talerta. tconfig_os, tgrupo
and some links.
* pandoradb_data.sql: Changes default values in talerta. tconfig_os,
tgrupo and some links.
* header.php: Fixed some user session management.
@ -17,39 +59,41 @@
* agent_disk_conf_editor.php: Minor fix in view link.
* configurar_agente.php, agent_manager.php: Added parent combo and better
ACL checks. New remote configuration control for get timestamp info of
config file.
* configurar_agente.php, agent_manager.php: Added parent combo and
better ACL checks. New remote configuration control for get timestamp
info of config file.
* modify_alert.php: Changes to use new internal Mail alert.
* config.php: Some items moved to config_process. (font, attachment and
default style).
* config.php: Some items moved to config_process. (font, attachment
and default style).
* functions.php: Added form_agent_combo(), form_event_type_combo(),
form_priority() and return_priority() functions.
* functions_db.php: Added smal_event_table() to render a variable table
with latest events (filtered).
* functions_db.php: Added smal_event_table() to render a variable
table with latest events (filtered).
* pandora.css. Added pure and priority colors.
* pandora.css: Added pure and priority colors.
* estado_alertas.php: Fixed ACL problems.
* stado_generalagente.php: Graph of modules now represents modules that
has generated events. Old graph is not used anymore. Also display parent.
* stado_generalagente.php: Graph of modules now represents modules
that has generated events. Old graph is not used anymore. Also display
parent.
* estado_grupo.php: Border of boxes is now thicker.
* tactical.php: New screen, almost all code changed. Odometer is not used
anymore, added some new items, like module LAG meter, module sanity, and
other general metrics.
* tactical.php: New screen, almost all code changed. Odometer is not
used anymore, added some new items, like module LAG meter, module
sanity, and other general metrics.
* ver_agente.php: Now renders also event for each agent view. Alert manual
validation generate a new event.
* ver_agente.php: Now renders also event for each agent view. Alert
manual validation generate a new event.
* events.php: New event system. 90% new code. A LOT of new features,
including full screen, coloured (by priority) and filters by six fields.
including full screen, coloured (by priority) and filters by six
fields.
* snmp_alert.php: Added support for alert priority.
@ -58,9 +102,9 @@
* render_view.php: Added fullscreen support for visual maps.
* fgraph.php: Added support for session checking in graphs (at least!).
New graphics for events (some changed it's function like events by group),
and feature added to progress GD implementation.
* fgraph.php: Added support for session checking in graphs (at
least!). New graphics for events (some changed it's function like
events by group), and feature added to progress GD implementation.
2008-06-09 Sancho Lerena <slerena@gmail.com>

View File

@ -16,6 +16,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require ('functions_html.php');
function pandora_help ($id, $return = false) {
global $config;
@ -39,8 +40,10 @@ function safe_output ($string) {
// Get parameter, using UTF8 encoding, and cleaning bad codes
// ---------------------------------------------------------------
function safe_input ($string) {
return htmlentities(utf8_decode($string), ENT_QUOTES);
function safe_input ($value) {
if (is_numeric ($value))
return $value;
return htmlentities (utf8_decode ($value), ENT_QUOTES);
}
// ---------------------------------------------------------------
@ -49,8 +52,7 @@ function safe_input ($string) {
// ---------------------------------------------------------------
function salida_sql ($string) {
$body = str_replace("\'", "'", $string);
return $body;
return mysql_escape_string ($string);
}
@ -100,7 +102,6 @@ function salida_limpia ($string){
function clean_output_breaks ($string){
$myoutput = salida_limpia($string);
return preg_replace ('/\n/',"<br>", $myoutput);
}
@ -144,7 +145,7 @@ function parametro_limpio($texto){
// string closeOpenTags(string string [, string beginChar [, stringEndChar [, string CloseChar]]]);
function closeOpenTags($str, $open = "<", $close = ">", $end = "/", $tokens = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
function closeOpenTags ($str, $open = "<", $close = ">", $end = "/", $tokens = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
{ $chars = array();
for ($i = 0; $i < strlen($tokens); $i++)
{ $chars[] = substr($tokens, $i, 1); }
@ -194,8 +195,7 @@ function closeOpenTags($str, $open = "<", $close = ">", $end = "/", $tokens = "_
function give_human_time ($int_seconds){
$key_suffix = 's';
$periods = array(
'year' => 31556926,
$periods = array('year' => 31556926,
'month' => 2629743,
'day' => 86400,
'hour' => 3600,
@ -207,14 +207,12 @@ function give_human_time ($int_seconds){
$flag_hide_zero = true;
// do the loop thang
foreach( $periods as $key => $length )
{
foreach( $periods as $key => $length ) {
// calculate
$temp = floor( $int_seconds / $length );
// determine if temp qualifies to be passed to output
if( !$flag_hide_zero || $temp > 0 )
{
if( !$flag_hide_zero || $temp > 0 ) {
// store in an array
$build[] = $temp.' '.$key.($temp!=1?'s':null);
@ -297,8 +295,7 @@ function list_files($directory, $stringSearch, $searchHandler, $outputHandler) {
}
if (($errorHandler == true) && (@count ($result) === 0)) {
echo ("<pre>\nerror: no filetype \"$fileExtension\" found!\n</pre>\n");
}
else {
} else {
sort ($result);
if ($outputHandler == 0) {
return $result;
@ -417,7 +414,7 @@ function pagination ($count, $url, $offset ) {
// ---------------------------------------------------------------
// Render data in a fashion way :-)
// ---------------------------------------------------------------
function format_numeric ( $number, $decimals=2, $dec_point=".", $thousands_sep=",") {
function format_numeric ($number, $decimals = 2, $dec_point = ".", $thousands_sep = ",") {
if ($number == 0)
return 0;
// If has decimals
@ -445,7 +442,6 @@ function format_for_graph ( $number , $decimals=2, $dec_point=".", $thousands_se
// If has decimals
if (fmod ($number , 1)> 0)
return number_format ($number, $decimals, $dec_point, $thousands_sep);
else
return number_format ($number, 0, $dec_point, $thousands_sep);
}
@ -600,26 +596,26 @@ function get_parameter_post ( $name, $default = "" ){
return $default;
}
function get_alert_priority ( $prio = 0){
function get_alert_priority ($priority = 0) {
global $config;
switch ($prio){
switch ($prio) {
case 0:
$priority = lang_string("Maintenance");
return lang_string("Maintenance");
break;
case 1:
$priority = lang_string("Informational");
return lang_string("Informational");
break;
case 2:
$priority = lang_string("Normal");
return lang_string("Normal");
break;
case 3:
$priority = lang_string("Warning");
return lang_string("Warning");
break;
case 4:
$priority = lang_string("Critical");
return lang_string("Critical");
break;
}
return $priority;
return '';
}
function get_alert_days ( $row ){
@ -630,24 +626,23 @@ function get_alert_days ( $row ){
$check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"]+ $row["friday"] + $row["saturday"] + $row["sunday"];
if ($row["monday"] != 0)
$days_output .= "Mo";
return "Mo";
if ($row["tuesday"] != 0)
$days_output .= "Tu";
return "Tu";
if ($row["wednesday"] != 0)
$days_output .= "We";
return "We";
if ($row["thursday"] != 0)
$days_output .= "Th";
return "Th";
if ($row["friday"] != 0)
$days_output .= "Fr";
return "Fr";
if ($row["saturday"] != 0)
$days_output .= "Sa";
return "Sa";
if ($row["sunday"] != 0)
$days_output .= "Su";
if ($days_output == "")
$days_output = lang_string ("none");
return "Su";
if ($check == 7)
$days_output = lang_string ("all");
return $days_output;
return lang_string ("all");
return lang_string ("none");
}
function get_alert_times ($row2){
@ -692,7 +687,7 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
}
$string = $string."<td class='$tdcolor'>".human_time_description($row2["time_threshold"]);
if ($row2["dis_min"]!=0){
if ($row2["dis_min"]) {
$mytempdata = fmod($row2["dis_min"], 1);
if ($mytempdata == 0)
$mymin = intval($row2["dis_min"]);
@ -714,7 +709,7 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
$mymax = 0;
}
if (($mymin == 0) && ($mymax == 0)){
if (($mymin == 0) && ($mymax == 0)) {
$mymin = lang_string ("N/A");
$mymax = $mymin;
}
@ -744,7 +739,7 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
$priority = get_alert_priority ($row2["priority"]);
// calculare firing conditions
if ($row2["alert_text"] != ""){
if ($row2["alert_text"] != "") {
$firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")";
} else {
$firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"];
@ -776,7 +771,6 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
<tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr>
</table></span></A>";
return $string;
}
@ -795,7 +789,7 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
$alert_name = get_db_sql ("SELECT nombre FROM talerta WHERE id_alerta = ".$data["id_alerta"]);
echo "<td class='".$tdcolor."'>".$alert_name."</td>";
if ($combined == 0){
if ($combined == 0) {
echo "<td class='".$tdcolor."'>".substr($module_name,0,21)."</td>";
} else {
echo "<td class='".$tdcolor."'>";
@ -835,8 +829,7 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
src='images/eye.png' alt=''>";
// Add float info table
echo "
<span>
echo "<span>
<table cellspacing='2' cellpadding='0'
style='margin-left:2px;'>
<tr><th colspan='2' width='91'>".
@ -851,7 +844,7 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
<tr><th colspan='2' width='91'>".
lang_string("Firing days")."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr>
</table></span></A>";
</table></span></a>";
$mytempdata = fmod($data["dis_min"], 1);
if ($mytempdata == 0)
@ -876,8 +869,7 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
echo "<td align='center' class='".$tdcolor."'>".human_time_description($data["time_threshold"]);
if ($data["last_fired"] == "0000-00-00 00:00:00") {
echo "<td align='center' class='".$tdcolor."f9'>".$lang_label["never"]."</td>";
}
else {
} else {
echo "<td align='center' class='".$tdcolor."f9'>".human_time_comparation ($data["last_fired"])."</td>";
}
echo "<td align='center' class='".$tdcolor."'>".$data["times_fired"]."</td>";
@ -887,45 +879,171 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
$id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente);
if (give_acl($config["id_user"], $id_grupo_alerta, "AW") == 1) {
echo "<td align='center' class='".$tdcolor."'>";
echo "<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=$id_agente&validate_alert=".$data["id_aam"]."'><img src='images/ok.png'></a>";
echo "<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&
id_agente=$id_agente&validate_alert=".$data["id_aam"]."'><img src='images/ok.png'></a>";
echo "</td>";
}
} else
echo "<td class='".$tdcolor."' align='center'><img width='20' height='9' src='images/pixel_green.png' title='".$lang_label["not_fired"]."'></td>";
} else {
echo "<td class='".$tdcolor."' align='center'>
<img width='20' height='9' src='images/pixel_green.png' title='".$lang_label["not_fired"]."'></td>";
}
}
function form_render_check ($name_form, $value_form = 1){
echo "<input name='$name_form' type='checkbox' ";
if ($value_form != 0){
if ($value_form != 0) {
echo "checked='1' ";
}
echo "value=1>";
}
/**
* Get report types in an array.
*
* @return An array with all the possible reports in Pandora where the array index is the report id.
*/
function get_report_types () {
$types = array ();
$types['simple_graph'] = lang_string ('simple_graph');
$types['custom_graph'] = lang_string ('custom_graph');
$types['SLA'] = lang_string ('SLA');
$types['event_report'] = lang_string ('event_report');
$types['alert_report'] = lang_string ('alert_report');
$types['monitor_report'] = lang_string ('monitor_report');
$types['avg_value'] = lang_string ('avg_value');
$types['max_value'] = lang_string ('max_value');
$types['min_value'] = lang_string ('min_value');
$types['sumatory'] = lang_string ('sumatory');
$types['general_group_report'] = lang_string ('general_group_report');
function form_event_type_combo ($name_form, $value_form = ""){
echo "<select name='$name_form'>";
if ($value_form != ""){
echo "<option>".$value_form;
} else {
echo "<option>all";;
}
echo "<option>unknown";
echo "<option>monitor_up";
echo "<option>monitor_down";
echo "<option>alert_fired";
echo "<option>alert_recovered";
echo "<option>alert_ceased";
echo "<option>alert_manual_validation";
echo "<option>recon_host_detected";
echo "<option>system";
echo "<option>error";
echo "</select>";
return $types;
}
/**
* Get report type name from type id.
*
* @param $type Type id of the report.
*
* @return Report type name.
*/
function get_report_name ($type) {
$types = get_report_types ();
if (! isset ($types[$type]))
return lang_string ('unknown');
return $types[$type];
}
function form_priority ($priority = 0, $form_name = "priority", $show_all = 0){
/**
* Get report type name from type id.
*
* @param $type Type id of the report.
*
* @return Report type name.
*/
function get_report_type_data_source ($type) {
switch ($type) {
case 1:
case 'simple_graph':
case 7:
case 'avg_value':
case 8:
case 'max_value':
case 9:
case 'min_value':
case 10:
case 'sumatory':
return 'module';
case 2:
case 'custom_graph':
return 'custom-graph';
case 3:
case 'SLA':
case 4:
case 'event_report':
case 5:
case 'alert_report':
case 6:
case 'monitor_report':
case 11:
case 'general_group_report':
return 'agent-group';
}
return 'unknown';
}
/**
* Checks if a module is of type "data"
*
* @param $module_name Module name to check.
*
* @return true if the module is of type "date"
*/
function is_module_data ($module_name) {
$result = ereg ("^(.*_data)$", $module_name);
if ($result === false)
return false;
return true;
}
/**
* Checks if a module is of type "proc"
*
* @param $module_name Module name to check.
*
* @return true if the module is of type "proc"
*/
function is_module_proc ($module_name) {
$result = ereg ('^(.*_proc)$', $module_name);
if ($result === false)
return false;
return true;
}
/**
* Checks if a module is of type "inc"
*
* @param $module_name Module name to check.
*
* @return true if the module is of type "inc"
*/
function is_module_inc ($module_name) {
$result = ereg ('^(.*_inc)$', $module_name);
if ($result === false)
return false;
return true;
}
/**
* Checks if a module is of type "string"
*
* @param $module_name Module name to check.
*
* @return true if the module is of type "string"
*/
function is_module_data_string ($module_name) {
$result = ereg ('^(.*string)$', $module_name);
if ($result === false)
return false;
return true;
}
function get_event_types () {
$types = array ();
$types['unknown'] = lang_string ('unknown');
$types['monitor_up'] = lang_string ('monitor_up');
$types['monitor_down'] = lang_string ('monitor_down');
$types['alert_fired'] = lang_string ('alert_fired');
$types['alert_recovered'] = lang_string ('alert_recovered');
$types['alert_ceased'] = lang_string ('alert_ceased');
$types['alert_manual_validation'] = lang_string ('alert_manual_validation');
$types['recon_host_detected'] = lang_string ('recon_host_detected');
$types['system'] = lang_string ('sytem');
$types['error'] = lang_string ('error');
return $types;
}
function form_priority ($priority = 0, $form_name = "priority", $show_all = 0) {
global $config;
echo '<select name="'.$form_name.'">';
@ -985,31 +1103,31 @@ function return_priority ($priority){
switch ($priority) {
case 0:
return lang_string("Maintenance");
return lang_string ("Maintenance");
case 1:
return lang_string("Informational");
return lang_string ("Informational");
case 2:
return lang_string("Normal");
return lang_string ("Normal");
case 3:
return lang_string("Warning");
return lang_string ("Warning");
case 4:
return lang_string("Critical");
return lang_string ("Critical");
case -1:
return lang_string("All");
return lang_string ("All");
}
}
// Show combo with agents
function form_agent_combo ($id_agent = 0, $form_name = "id_agent"){
function form_agent_combo ($id_agent = 0, $form_name = "id_agent") {
global $config;
echo '<select name="'.$form_name.'" style="width:120px">';
if ($id_agent != 0)
echo "<option value='".$id_agent."'>".dame_nombre_agente($id_agent)."</option>";
else
echo "<option value='0'>".lang_string("None")."</option>";
$sql1='SELECT * FROM tagente';
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
$sql = 'SELECT * FROM tagente';
$result = mysql_query($sql);
while ($row = mysql_fetch_array ($result)) {
// if (give_acl($config["id_user"], $row["id_grupo"], "AR")==1)
echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>";
}

View File

@ -136,30 +136,16 @@ function logoff_db($id,$ip){
// Returns profile given ID
// ---------------------------------------------------------------
function dame_perfil($id){
require("config.php");
$query1="SELECT * FROM tperfil WHERE id_perfil =".$id;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1)){
$cat=$rowdup["name"];
}
else $cat = "";
return $cat;
function dame_perfil ($id_profile) {
return (string) get_db_value ('name', 'tperfil', 'id_perfil', (int) $id_profile);
}
// ---------------------------------------------------------------
// Returns disabled from a given group_id
// ---------------------------------------------------------------
function give_disabled_group($id){
require("config.php");
$query1="SELECT * FROM tgrupo WHERE id_grupo =".$id;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1)){
$cat=$rowdup["disabled"];
}
else $cat = "";
return $cat;
function give_disabled_group ($id_group) {
return (bool) get_db_value ('disabled', 'tgroup', 'id_grupo', (int) $id_group);
}
@ -168,45 +154,24 @@ function give_disabled_group($id){
// Returns group given ID
// ---------------------------------------------------------------
function dame_grupo($id){
require("config.php");
$query1="SELECT * FROM tgrupo WHERE id_grupo =".$id;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1)){
$cat=$rowdup["nombre"];
}
else $cat = "";
return $cat;
function dame_grupo ($id_group) {
return (string) get_db_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group);
}
// ---------------------------------------------------------------
// Returns icon name given group ID
// ---------------------------------------------------------------
function dame_grupo_icono($id){
require("config.php");
$query1="SELECT * FROM tgrupo WHERE id_grupo =".$id;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1)){
$cat=$rowdup["icon"];
}
else $cat = "";
return $cat;
function dame_grupo_icono ($id_group) {
return (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group);
}
// ---------------------------------------------------------------
// Return agent id given name of agent
// ---------------------------------------------------------------
function dame_agente_id($nombre){
require("config.php");
$query1="SELECT * FROM tagente WHERE nombre = '".$nombre."'";
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1))
$pro=$rowdup["id_agente"];
else
$pro = "";
return $pro;
function dame_agente_id ($agent_name) {
return (int) get_db_value ('id_agente', 'tagente', 'nombre', $agent_name);
}
@ -214,15 +179,8 @@ function dame_agente_id($nombre){
// Returns userid given name an note id
// ---------------------------------------------------------------
function give_note_author ($id_note){
require("config.php");
$query1="SELECT * FROM tnota WHERE id_nota = ".$id_note;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1))
$pro=$rowdup["id_usuario"];
else
$pro = "";
return $pro;
function give_note_author ($id_note) {
return (int) get_db_value ('id_usuario', 'tnota', 'id_nota', (int) $id_note);
}
@ -230,15 +188,12 @@ function give_note_author ($id_note){
// Returns agent id given name of agent
// ---------------------------------------------------------------
function dame_agente_modulo_id($id_agente, $id_tipomodulo, $nombre){
require("config.php");
$query1="SELECT * FROM tagente_modulo WHERE id_agente = ".$id_agente." and id_tipo_modulo = ".$id_tipomodulo." and nombre = '".$nombre."'";
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1))
$pro=$rowdup["id_agente_modulo"];
else
$pro = "";
return $pro;
function dame_agente_modulo_id ($id_agente, $id_tipomodulo, $nombre) {
$sql = sprintf ('SELECT id_agente_modulo FROM tagente_modulo
WHERE id_agente = %d
AND id_tipo_modulo = %d AND nombre = "%s"',
$id_agent, $id_tipomodulo, $nombre);
return get_db_sql ($sql);
}
@ -398,30 +353,18 @@ function giveme_module_type($id){
// Returns agent name, given a ID of agente_module table
// ---------------------------------------------------------------
function dame_nombre_agente_agentemodulo($id_agente_modulo){
require("config.php");
$query1="SELECT * FROM tagente_modulo WHERE id_agente_modulo = ".$id_agente_modulo;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1))
$pro = dame_nombre_agente($rowdup["id_agente"]);
else
$pro = "";
return $pro;
function dame_nombre_agente_agentemodulo ($id_agente_modulo) {
$id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agente_modulo);
if ($id_agent)
return dame_nombre_agente ($id_agent);
return '';
}
// ---------------------------------------------------------------
// Return agent module name, given a ID of agente_module table
// ---------------------------------------------------------------
function dame_nombre_modulo_agentemodulo($id_agente_modulo){
require("config.php");
$query1="SELECT * FROM tagente_modulo WHERE id_agente_modulo = ".$id_agente_modulo;
$resq1=mysql_query($query1);
if ($rowdup=mysql_fetch_array($resq1))
$pro = $rowdup["nombre"];
else
$pro = "";
return $pro;
function dame_nombre_modulo_agentemodulo ($id_agente_modulo) {
return get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $id_agente_modulo);
}
@ -674,24 +617,10 @@ function dame_admin($id){
return $admin;
}
// ---------------------------------------------------------------
// Gives error message and stops execution if user
//doesn't have an open session and this session is from an valid user
// ---------------------------------------------------------------
// Wrapper function since we change all functions to english
function comprueba_login() {
if (isset($_SESSION["id_usuario"])){
$id = $_SESSION["id_usuario"];
require("config.php");
$query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'";
$resq1=mysql_query($query1);
$rowdup=mysql_fetch_array($resq1);
$nombre=$rowdup["id_usuario"];
if ( $id == $nombre ){
return 0 ;
}
}
return 1;
return check_login ();
}
// ---------------------------------------------------------------
@ -699,7 +628,7 @@ function comprueba_login() {
//doesn't have an open session and this session is from an administrator
// ---------------------------------------------------------------
function comprueba_admin() {
function check_admin () {
if (isset($_SESSION["id_usuario"])){
$iduser=$_SESSION['id_usuario'];
if (dame_admin($iduser)==1){
@ -718,6 +647,9 @@ function comprueba_admin() {
return 1;
}
function comprueba_admin() {
return check_admin ();
}
// ---------------------------------------------------------------
// Returns number of alerts fired by this agent
@ -1144,44 +1076,111 @@ function give_agent_id_from_module_id ($id_module){
// Generic access to a field ($field) given a table
// ---------------------------------------------------------------
function get_db_value ($field, $table, $field_search, $condition_value){
$query = "SELECT $field FROM $table WHERE $field_search = '$condition_value' ";
$resq1 = mysql_query($query);
if ($rowdup = mysql_fetch_array($resq1))
$pro = $rowdup[$field];
else
$pro = "";
return $pro;
}
function get_db_value ($field, $table, $field_search, $condition){
if (is_int ($condition)) {
$sql = sprintf ('SELECT %s FROM %s WHERE %s = %d', $field, $table, $field_search, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ('SELECT %s FROM %s WHERE %s = %f', $field, $table, $field_search, $condition);
} else {
$sql = sprintf ('SELECT %s FROM %s WHERE %s = "%s"', $field, $table, $field_search, $condition);
}
function give_db_value ($field, $table, $field_search, $condition_value){
return get_db_value ($field, $table, $field_search, $condition_value);
$result = mysql_query ($sql);
if (! $result) {
echo '<strong>Error:</strong> get_db_value("'.$sql.'") :'. mysql_error ().'<br />';
return NULL;
}
if ($row = mysql_fetch_array ($result))
return $row[0];
return NULL;
}
// ---------------------------------------------------------------
// Wrapper for old function name. Should be upgraded/renamed in next versions
// ---------------------------------------------------------------
function give_db_value ($field, $table, $field_search, $condition) {
return get_db_value ($field, $table, $field_search, $condition);
}
function get_db_row ($table, $field_search, $condition_value){
$query = "SELECT * FROM $table WHERE $field_search = '$condition_value' ";
$resq1 = mysql_query($query);
if ($rowdup = mysql_fetch_array($resq1))
return $rowdup;
else
return 0;
function get_db_row ($table, $field_search, $condition) {
global $config;
if (is_int ($condition)) {
$sql = sprintf ('SELECT * FROM %s WHERE %s = %d', $table, $field_search, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ('SELECT * FROM %s WHERE %s = %f', $table, $field_search, $condition);
} else {
$sql = sprintf ('SELECT * FROM %s WHERE %s = "%s"', $table, $field_search, $condition);
}
$result = mysql_query ($sql);
if (! $result) {
echo '<strong>Error:</strong> get_db_row("'.$sql.'") :'. mysql_error ().'<br />';
return NULL;
}
if ($row = mysql_fetch_array ($result))
return $row;
return NULL;
}
// ---------------------------------------------------------------
// Generic access to single field using a free SQL sentence
// ---------------------------------------------------------------
function get_db_sql ($sentence, $field = 0){
if ($rowdup = mysql_fetch_array(mysql_query($sentence)))
return $rowdup[$field];
else
return "";
function get_db_sql ($sql, $field = 0){
global $config;
$result = mysql_query ($sql);
if (! $result) {
echo '<strong>Error:</strong> get_db_sql ("'.$sql.'") :'. mysql_error ().'<br />';
return NULL;
}
if ($row = mysql_fetch_array ($result))
return $row[$field];
return NULL;
}
function get_db_all_rows_sqlfree ($sql) {
global $config;
$retval = array ();
$result = mysql_query ($sql);
if (! $result) {
echo mysql_error ();
return array();
}
while ($row = mysql_fetch_array ($result)) {
array_push ($retval, $row);
}
return $retval;
}
function get_db_all_rows_in_table ($table) {
return get_db_all_rows_sqlfree ('SELECT * FROM '.$table);
}
function get_db_all_rows_field_filter ($table, $field, $condition) {
if (is_int ($condition)) {
$sql = sprintf ('SELECT * FROM %s WHERE %s = %d', $table, $field, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ('SELECT * FROM %s WHERE %s = %f', $table, $field, $condition);
} else {
$sql = sprintf ('SELECT * FROM %s WHERE %s = "%s"', $table, $field, $condition);
}
return get_db_all_rows_sqlfree ($sql);
}
function get_db_all_fields_in_table ($table, $field) {
return get_db_all_rows_sqlfree ('SELECT '.$field.' FROM '. $table);
}
// ---------------------------------------------------------------
// Return current status from a given agent module (1 alive, 0 down)
// ---------------------------------------------------------------
@ -1287,61 +1286,117 @@ function return_coordinate_y_layoutdata ($id_layoutdata){
return (0);
}
function return_moduledata_avg_value ($id_agent_module, $period){
$datelimit = time() - $period; // limit date
function return_moduledata_avg_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$query1="SELECT AVG(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit";
$resq1=mysql_query($query1);
if ($resq1 != 0) {
$rowdup=mysql_fetch_array($resq1);
return ($rowdup[0]);
} else
return (0);
$sql = sprintf ("SELECT AVG(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
}
function return_moduledata_max_value ($id_agent_module, $period){
$datelimit = time() - $period; // limit date
function return_moduledata_max_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$query1="SELECT MAX(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit";
$resq1=mysql_query($query1);
if ($resq1 != 0) {
$rowdup=mysql_fetch_array($resq1);
return ($rowdup[0]);
} else
return (0);
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
}
function return_moduledata_min_value ($id_agent_module, $period){
$datelimit = time() - $period; // limit date
function return_moduledata_min_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$query1="SELECT MIN(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit";
$resq1=mysql_query($query1);
if ($resq1 != 0) {
$rowdup=mysql_fetch_array($resq1);
return ($rowdup[0]);
} else
return (0);
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
}
function lang_string ($string){
function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$agent_module = get_db_row ('tagente_modulo', 'id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $agent_module['id_tipo_modulo']);
echo $module_name;
if (is_module_data_string ($module_name)) {
return lang_string ('wrong_module_type');
}
$interval = get_db_value ('current_interval', 'tagente_estado', 'id_agente_modulo', $id_agent_module);
// Get the whole interval of data
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d',
$agent_module['id_agente'], $id_agent_module, $datelimit, $date);
$datas = get_db_all_rows_sqlfree ($sql);
$last_data = "";
$total_badtime = 0;
$interval_begin = 0;
$interval_last = 0;
if (sizeof ($datas) == 0) {
return 0;
}
$sum = 0;
$previous_data = 0;
foreach ($datas as $data) {
if ($interval_begin != 0) {
$interval_last = $data["utimestamp"];
$elapsed = $interval_last - $interval_begin;
$times = intval ($elapsed / $interval);
} else {
$times = 1;
}
if (is_module_data_proc ($module_name)) {
$previous_data = $data['datos'] * $interval;
} else {
$previous_data = $data['datos'];
}
$interval_begin = $data["utimestamp"];
}
/* The last interval value must be get from tagente_estado, but
it will count only if it's not older than date demanded
*/
$interval_last = give_db_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module);
if ($interval_last <= $datelimit) {
$elapsed = $interval_last - $interval_begin;
$times = intval ($elapsed / $interval);
$sum += $times * $previous_data;
}
return (float) $sum;
}
function lang_string ($string) {
global $config;
require ($config["homedir"]."/include/languages/language_".$config["language"].".php");
if (isset ($lang_label[$string]))
return $lang_label[$string];
else
return $string;
}
function check_server_status (){
function check_server_status () {
global $config;
// This check assumes that server_keepalive should be AT LEAST 15 MIN
$sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 AND keepalive > NOW() - INTERVAL 15 MINUTE";
$res = get_db_sql ($sql);
// Set servers to down
if ($res == 0){
$res2 = mysql_query("UPDATE tserver SET status = 0");
$res2 = mysql_query ("UPDATE tserver SET status = 0");
}
return $res;
}

View File

@ -0,0 +1,524 @@
<?php
// Pandora FMS - the Free Monitoring System
// ========================================
// Copyright (c) 2008 Artica Soluciones Tecnológicas, http://www.artica.es
// Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/**
* Prints an array of fields in a popup menu of a form.
*
* Based on choose_from_menu() from Moodle
*
* $fields Array with dropdown values. Example: $fields["value"] = "label"
* $name Select form name
* $selected Current selected value.
* $script Javascript onChange code.
* $nothing Label when nothing is selected.
* $nothing_value Value when nothing is selected
*/
function print_select ($fields, $name, $selected = '', $script = '', $nothing = 'select', $nothing_value = '0', $return = false) {
$output = "\n";
$attributes = ($script) ? 'onchange="'. $script .'"' : '';
$output .= '<select id="'.$name.'" name="'.$name.'" '.$attributes.">\n";
if ($nothing != '') {
$output .= ' <option value="'.$nothing_value.'"';
if ($nothing_value == $selected) {
$output .= " selected";
}
$output .= '>'.lang_string ($nothing)."</option>\n";
}
if (!empty ($fields)) {
foreach ($fields as $value => $label) {
$output .= ' <option value="'. $value .'"';
if ($value == $selected) {
$output .= ' selected';
}
if ($label === '') {
$output .= '>'. $value ."</option>\n";
} else {
$output .= '>'. $label ."</option>\n";
}
}
}
$output .= "</select>\n";
if ($return)
return $output;
echo $output;
}
/**
* Prints an array of fields in a popup menu of a form based on a SQL query.
* The first and second columns of the query will be used.
*
* Based on choose_from_menu() from Moodle
*
* $sql SQL sentence, the first field will be the identifier of the option.
* The second field will be the shown value in the dropdown.
* $name Select form name
* $selected Current selected value.
* $script Javascript onChange code.
* $nothing Label when nothing is selected.
* $nothing_value Value when nothing is selected
*/
function print_select_from_sql ($sql, $name, $selected = '', $script = '', $nothing = 'select', $nothing_value = '0', $return = false) {
$fields = array ();
$result = mysql_query ($sql);
if (! $result) {
echo mysql_error ();
return "";
}
while ($row = mysql_fetch_array ($result)) {
$fields[$row[0]] = $row[1];
}
$output = print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, true);
if ($return)
return $output;
echo $output;
}
/**
* Render an input text element. Extended version, use print_input_text() to simplify.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $alt Alternative HTML string.
* @param int $size Size of the input.
* @param int $maxlength Maximum length allowed.
* @param bool $disabled Disable the button (optional, button enabled by default).
* @param string $alt Alternative HTML string.
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_input_text_extended ($name, $value, $id, $alt, $size, $maxlength, $disabled, $script, $attributes, $return = false) {
static $idcounter = 0;
++$idcounter;
if (empty ($name)) {
$name = 'unnamed';
}
if (empty ($alt)) {
$alt = 'textfield';
}
if (! empty ($maxlength)) {
$maxlength = ' maxlength="'.$maxlength.'" ';
}
$output = '<input name="'.$name.'" type="text" value="'.$value.'" size="'.$size.'" '.$maxlength.' alt="'.$alt.'" ';
if ($id != '') {
$output .= ' id="'.$id.'"';
} else {
$htmlid = 'text-'.sprintf ('%04d', $idcounter);
$output .= ' id="'.$htmlid.'"';
}
if ($disabled)
$output .= ' disabled';
if ($attributes != '')
$output .= ' '.$attributes;
$output .= ' />';
if ($return)
return $output;
echo $output;
}
/**
* Render an input text element.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $alt Alternative HTML string (optional).
* @param int $size Size of the input (optional).
* @param int $maxlength Maximum length allowed (optional).
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_input_text ($name, $value, $alt = '', $size = 50, $maxlength = 0, $return = false) {
$output = print_input_text_extended ($name, $value, 'text-'.$name, $alt, $size, $maxlength, false, '', '', true);
if ($return)
return $output;
echo $output;
}
/**
* Render an input hidden element.
*
* @param string $name Input name.
* @param string $value Input value.
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_input_hidden ($name, $value, $return = false) {
$output = '<input id="hidden-'.$name.'" name="'.$name.'" type="hidden" value="'.$value.'" />';
if ($return)
return $output;
echo $output;
}
function print_submit_button ($label = 'OK', $name = '', $disabled = false, $attributes = '', $return = false) {
$output = '';
$output .= '<input type="submit" id="submit-'.$name.'" name="'.$name.'" value="'. $label .'" '. $attributes;
if ($disabled)
$output .= ' disabled';
$output .= ' />';
if ($return)
return $output;
echo $output;
}
function print_button ($label = 'OK', $name = '', $disabled = false, $script = '', $attributes = '', $return = false) {
$output = '';
$output .= '<input type="button" id="button-'.$name.'" name="'.$name.'" value="'. $label .'" onClick="'. $script.'" '.$attributes;
if ($disabled)
$output .= ' disabled';
$output .= ' />';
if ($return)
return $output;
echo $output;
}
function print_textarea ($name, $rows, $columns, $value = '', $attributes = '', $return = false) {
$output = '<textarea name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.' />';
$output .= $value;
$output .= '</textarea>';
if ($return)
return $output;
echo $output;
}
/**
* Print a nicely formatted table. Code taken from moodle.
*
* @param array $table is an object with several properties:
* $table->head - An array of heading names.
* $table->align - An array of column alignments
* $table->valign - An array of column alignments
* $table->size - An array of column sizes
* $table->wrap - An array of "nowrap"s or nothing
* $table->style - An array of personalized style for each column.
* $table->rowstyle - An array of personalized style of each row.
* $table->rowclass - An array of personalized classes of each row (odd-evens classes will be ignored).
* $table->colspan - An array of colspans of each column.
* $table->data[] - An array of arrays containing the data.
* $table->width - A percentage of the page
* $table->border - Border of the table.
* $table->tablealign - Align the whole table
* $table->cellpadding - Padding on each cell
* $table->cellspacing - Spacing between cells
* $table->class - CSS table class
* @param bool $return whether to return an output string or echo now
*/
function print_table ($table, $return = false) {
$output = '';
static $table_count = 0;
$table_count++;
if (isset ($table->align)) {
foreach ($table->align as $key => $aa) {
if ($aa) {
$align[$key] = ' text-align:'. $aa.';';
} else {
$align[$key] = '';
}
}
}
if (isset ($table->valign)) {
foreach ($table->valign as $key => $aa) {
if ($aa) {
$valign[$key] = ' vertical-align:'. $aa.';';
} else {
$valign[$key] = '';
}
}
}
if (isset ($table->size)) {
foreach ($table->size as $key => $ss) {
if ($ss) {
$size[$key] = ' width:'. $ss .';';
} else {
$size[$key] = '';
}
}
}
if (isset ($table->style)) {
foreach ($table->style as $key => $st) {
if ($st) {
$style[$key] = ' '. $st .';';
} else {
$style[$key] = '';
}
}
}
if (isset ($table->rowstyle)) {
foreach ($table->rowstyle as $key => $st) {
$rowstyle[$key] = ' '. $st .';';
}
}
if (isset ($table->rowclass)) {
foreach ($table->rowclass as $key => $class) {
$rowclass[$key] = $st;
}
}
if (isset ($table->colspan)) {
foreach ($table->colspan as $keyrow => $colspan) {
foreach ($colspan as $key => $span) {
$colspan[$keyrow][$key] = ' colspan="'.$span.'"';
}
}
}
if (empty ($table->width)) {
$table->width = '80%';
}
if (empty ($table->border)) {
$table->border = '0px';
}
if (empty ($table->tablealign)) {
$table->tablealign = 'center';
}
if (empty ($table->cellpadding)) {
$table->cellpadding = '4';
}
if (empty ($table->cellspacing)) {
$table->cellspacing = '4';
}
if (empty ($table->class)) {
$table->class = 'databox_color';
}
$tableid = empty ($table->id) ? 'table'.$table_count : $table->id;
$output .= '<table width="'.$table->width.'" ';
$output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" ";
$output .= " border=\"$table->border\" 'class=\"$table->class\" id=\"$tableid\" >\n";
$countcols = 0;
if (!empty ($table->head)) {
$countcols = count ($table->head);
$output .= '<tr>';
foreach ($table->head as $key => $heading) {
if (!isset ($size[$key])) {
$size[$key] = '';
}
if (!isset ($align[$key])) {
$align[$key] = '';
}
$output .= '<th class="header c'.$key.'" scope="col">'. $heading .'</th>';
}
$output .= '</tr>'."\n";
}
if (!empty ($table->data)) {
$oddeven = 1;
foreach ($table->data as $keyrow => $row) {
if (!isset ($rowstyle[$keyrow])) {
$rowstyle[$keyrow] = '';
}
$oddeven = $oddeven ? 0 : 1;
$class = 'datos'.($oddeven ? "" : "2");
if (isset ($rowclass[$keyrow])) {
$class = $rowclass[$keyrow];
}
$output .= '<tr id="'.$tableid."-".$keyrow.'" style="'.$rowstyle[$keyrow].'" class="'.$class.'">'."\n";
/* Special separator rows */
if ($row == 'hr' and $countcols) {
$output .= '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
continue;
}
/* It's a normal row */
foreach ($row as $key => $item) {
if (!isset ($size[$key])) {
$size[$key] = '';
}
if (!isset ($colspan[$key])) {
$colspan[$keyrow][$key] = '';
}
if (!isset ($align[$key])) {
$align[$key] = '';
}
if (!isset ($valign[$key])) {
$valign[$key] = '';
}
if (!isset ($wrap[$key])) {
$wrap[$key] = '';
}
if (!isset ($style[$key])) {
$style[$key] = '';
}
$output .= '<td id="'.$tableid.'-'.$keyrow.'-'.$key.'" style="'. $style[$key].$valign[$key].$align[$key].$size[$key].$wrap[$key] .'" '.$colspan[$key].' class="datos'.($oddeven ? "" : "2").'">'. $item .'</td>'."\n";
}
$output .= '</tr>'."\n";
}
}
$output .= '</table>'."\n";
if ($return)
return $output;
echo $output;
}
/**
* Render a radio button input. Extended version, use print_radio_button() to simplify.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $checked Set the button to be marked (optional, unmarked by default).
* @param bool $disabled Disable the button (optional, button enabled by default).
* @param string $script Script to execute when onClick event is triggered (optional).
* @param string $attributes Optional HTML attributes. It's a free string which will be
inserted into the HTML tag, use it carefully (optional).
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_radio_button_extended ($name, $value, $label, $checkedvalue, $disabled, $script, $attributes, $return = false) {
static $idcounter = 0;
$output = '';
$output = '<input type="radio" name="'.$name.'" value="'.$value.'"';
$htmlid = 'radiobtn'.sprintf ('%04d', ++$idcounter);
$output .= ' id="'.$htmlid.'"';
if ($value == $checkedvalue) {
$output .= ' checked="checked"';
}
if ($disabled) {
$output .= ' disabled';
}
if ($script != '') {
$output .= ' onClick="'. $script . '"';
}
$output .= ' ' . $attributes ;
$output .= ' />';
if ($label != '') {
$output .= '<label for="'.$htmlid.'">'. $label .'</label>' . "\n";
}
if ($return)
return $output;
echo $output;
}
/**
* Render a radio button input.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $label Label to add after the radio button (optional).
* @param string $checkedvalue Checked and selected value, the button will be selected if it matches $value (optional).
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_radio_button ($name, $value, $label = '', $checkedvalue = '', $return = false) {
$output = print_radio_button_extended ($name, $value, $label, $checkedvalue, false, '', '', true);
if ($return)
return $output;
echo $output;
}
/**
* Render a checkbox button input. Extended version, use print_checkbox() to simplify.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $checked Set the button to be marked (optional, unmarked by default).
* @param bool $disabled Disable the button (optional, button enabled by default).
* @param string $script Script to execute when onClick event is triggered (optional).
* @param string $attributes Optional HTML attributes. It's a free string which will be
inserted into the HTML tag, use it carefully (optional).
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_checkbox_extended ($name, $value, $checked, $disabled, $script, $attributes, $return = false) {
static $idcounter = 0;
$htmlid = 'checkbox'.sprintf ('%04d', ++$idcounter);
$output = '<input name="'.$name.'" type="checkbox" value="'.$value.'" '. ($checked ? 'checked': '');
$output .= ' id="'.$htmlid.'"';
if ($script != '') {
$output .= ' onClick="'. $script . '"';
}
if ($disabled) {
$output .= ' disabled';
}
$output .= ' />';
$output .= "\n";
if ($return)
return $output;
echo $output;
}
/**
* Render a checkbox button input.
*
* @param string $name Input name.
* @param string $value Input value.
* @param string $checked Set the button to be marked (optional, unmarked by default).
* @param bool $return Whether to return an output string or echo now (optional, echo by default).
*/
function print_checkbox ($name, $value, $checked = false, $return = false) {
$output = print_checkbox_extended ($name, $value, (bool) $checked, false, '', '', true);
if ($return)
return $output;
echo $output;
}
/**
* Prints only a tip button which shows a text when the user puts the mouse over it.
*
* @param string $text Complete text to show in the tip
* @param bool $return whether to return an output string or echo now
*
* @return
*/
function print_help_tip ($text, $return = false) {
$output = '<a href="#" class="tip">&nbsp;<span>'.$text.'</span></a>';
if ($return)
return $output;
echo $output;
}
?>

View File

@ -218,7 +218,7 @@ echo "</select></td>";
// Event type
echo "<td>".lang_string ("Event type")."</td>";
echo "<td>";
echo form_event_type_combo ("event_type", $event_type);
echo print_select (get_event_types (), 'event_type', $event_type, '', 'all', 0);
echo "<tr>";
// Severity

File diff suppressed because it is too large Load Diff