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:
parent
1b261b4f27
commit
10d0c0e238
|
@ -1,67 +1,111 @@
|
|||
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.
|
||||
|
||||
* pandoradb.sql: talert_snmp: Added priority field.
|
||||
|
||||
* pandoradb_data.sql: Changes default values in talerta. tconfig_os,
|
||||
tgrupo and some links.
|
||||
|
||||
* header.php: Fixed some user session management.
|
||||
|
||||
* logon_ok.php: New design for welcome screen, odometer is over.
|
||||
|
||||
* menu.php, godmode/menu.php: Some ACL improvements.
|
||||
|
||||
* 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.
|
||||
|
||||
* modify_alert.php: Changes to use new internal Mail alert.
|
||||
|
||||
* 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).
|
||||
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
|
||||
* snmp_alert.php: Added support for alert priority.
|
||||
|
||||
* operation/users/user.php: No longer a user with UM privileges could
|
||||
see any other user.
|
||||
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
|
||||
* header.php: Fixed some user session management.
|
||||
|
||||
* logon_ok.php: New design for welcome screen, odometer is over.
|
||||
|
||||
* menu.php, godmode/menu.php: Some ACL improvements.
|
||||
|
||||
* 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.
|
||||
|
||||
* modify_alert.php: Changes to use new internal Mail alert.
|
||||
|
||||
* 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).
|
||||
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
|
||||
* snmp_alert.php: Added support for alert priority.
|
||||
|
||||
* operation/users/user.php: No longer a user with UM privileges could
|
||||
see any other user.
|
||||
|
||||
* 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.
|
||||
|
||||
2008-06-09 Sancho Lerena <slerena@gmail.com>
|
||||
|
||||
* operation/agentes/status_monitor.php,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,25 +15,25 @@
|
|||
|
||||
|
||||
function check_login() {
|
||||
global $config;
|
||||
if (!isset($config["homedir"])){
|
||||
// No exists $config. Exit inmediatly
|
||||
include ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) {
|
||||
$id = $_SESSION["id_usuario"];
|
||||
$query1="SELECT id_usuario FROM tusuario WHERE id_usuario= '$id'";
|
||||
$resq1 = mysql_query($query1);
|
||||
$rowdup = mysql_fetch_array($resq1);
|
||||
$nombre = $rowdup[0];
|
||||
if ( $id == $nombre ){
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
audit_db("N/A", getenv("REMOTE_ADDR"), "No session", "Trying to access without a valid session");
|
||||
include ($config["homedir"]."/general/noaccess.php");
|
||||
exit;
|
||||
global $config;
|
||||
if (!isset($config["homedir"])){
|
||||
// No exists $config. Exit inmediatly
|
||||
include ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) {
|
||||
$id = $_SESSION["id_usuario"];
|
||||
$query1="SELECT id_usuario FROM tusuario WHERE id_usuario= '$id'";
|
||||
$resq1 = mysql_query($query1);
|
||||
$rowdup = mysql_fetch_array($resq1);
|
||||
$nombre = $rowdup[0];
|
||||
if ( $id == $nombre ){
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
audit_db("N/A", getenv("REMOTE_ADDR"), "No session", "Trying to access without a valid session");
|
||||
include ($config["homedir"]."/general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
@ -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 give_db_value ($field, $table, $field_search, $condition_value){
|
||||
return get_db_value ($field, $table, $field_search, $condition_value);
|
||||
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);
|
||||
}
|
||||
|
||||
$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,172 +1286,228 @@ 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){
|
||||
global $config;
|
||||
require ($config["homedir"]."/include/languages/language_".$config["language"].".php");
|
||||
if (isset ($lang_label[$string]))
|
||||
return $lang_label[$string];
|
||||
else
|
||||
return $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 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");
|
||||
}
|
||||
return $res;
|
||||
function lang_string ($string) {
|
||||
global $config;
|
||||
require ($config["homedir"]."/include/languages/language_".$config["language"].".php");
|
||||
if (isset ($lang_label[$string]))
|
||||
return $lang_label[$string];
|
||||
return $string;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function show_alert_row_mini ($id_combined_alert){
|
||||
global $config;
|
||||
global $lang_label;
|
||||
|
||||
$color=1;
|
||||
$sql_com = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert;
|
||||
$result_com = mysql_query ($sql_com);
|
||||
echo "<table width=400 cellpadding=2 cellspacing=2 class='databox'>";
|
||||
echo "<th>".lang_string("Name");
|
||||
echo "<th>".lang_string("Oper");
|
||||
echo "<th>".lang_string("Tt");
|
||||
echo "<th>".lang_string("Firing");
|
||||
echo "<th>".lang_string("Time");
|
||||
echo "<th>".lang_string("Desc");
|
||||
echo "<th>".lang_string("Recovery");
|
||||
echo "<th>".lang_string("MinMax.Al");
|
||||
echo "<th>".lang_string("Days");
|
||||
echo "<th>".lang_string("Fired");
|
||||
while ($row2=mysql_fetch_array($result_com)){
|
||||
global $config;
|
||||
global $lang_label;
|
||||
|
||||
if ($color == 1){
|
||||
$tdcolor = "datos";
|
||||
$color = 0;
|
||||
}
|
||||
else {
|
||||
$tdcolor = "datos2";
|
||||
$color = 1;
|
||||
}
|
||||
echo "<tr>";
|
||||
|
||||
if ($row2["disable"] == 1){
|
||||
$tdcolor = "datos3";
|
||||
}
|
||||
echo "<td class=$tdcolor>".get_db_sql("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo =".$row2["id_agente_modulo"]);
|
||||
echo "<td class=$tdcolor>".$row2["operation"];
|
||||
|
||||
echo "<td class='$tdcolor'>".human_time_description($row2["time_threshold"]);
|
||||
|
||||
if ($row2["dis_min"]!=0){
|
||||
$mytempdata = fmod($row2["dis_min"], 1);
|
||||
if ($mytempdata == 0)
|
||||
$mymin = intval($row2["dis_min"]);
|
||||
else
|
||||
$mymin = $row2["dis_min"];
|
||||
$mymin = format_for_graph($mymin );
|
||||
} else {
|
||||
$mymin = 0;
|
||||
}
|
||||
|
||||
if ($row2["dis_max"]!=0){
|
||||
$mytempdata = fmod($row2["dis_max"], 1);
|
||||
if ($mytempdata == 0)
|
||||
$mymax = intval($row2["dis_max"]);
|
||||
else
|
||||
$mymax = $row2["dis_max"];
|
||||
$mymax = format_for_graph($mymax );
|
||||
} else {
|
||||
$mymax = 0;
|
||||
}
|
||||
|
||||
if (($mymin == 0) && ($mymax == 0)){
|
||||
$mymin = lang_string ("N/A");
|
||||
$mymax = $mymin;
|
||||
}
|
||||
|
||||
// We have alert text ?
|
||||
if ($row2["alert_text"]!= "") {
|
||||
echo "<td class='$tdcolor'>".$lang_label["text"]."</td>";
|
||||
} else {
|
||||
echo "<td class='$tdcolor'>".$mymin."/".$mymax."</td>";
|
||||
}
|
||||
|
||||
// Alert times
|
||||
echo "<td class='$tdcolor'>";
|
||||
echo get_alert_times ($row2);
|
||||
|
||||
// Description
|
||||
echo "</td><td class='$tdcolor'>".substr($row2["descripcion"],0,20);
|
||||
|
||||
// Has recovery notify activated ?
|
||||
if ($row2["recovery_notify"] > 0)
|
||||
$recovery_notify = lang_string("Yes");
|
||||
else
|
||||
$recovery_notify = lang_string("No");
|
||||
|
||||
echo "</td><td class='$tdcolor'>".$recovery_notify;
|
||||
|
||||
// calculare firing conditions
|
||||
if ($row2["alert_text"] != ""){
|
||||
$firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")";
|
||||
} else {
|
||||
$firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"];
|
||||
}
|
||||
echo "</td><td class='$tdcolor'>".$firing_cond;
|
||||
$color=1;
|
||||
$sql_com = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert;
|
||||
$result_com = mysql_query ($sql_com);
|
||||
echo "<table width=400 cellpadding=2 cellspacing=2 class='databox'>";
|
||||
echo "<th>".lang_string("Name");
|
||||
echo "<th>".lang_string("Oper");
|
||||
echo "<th>".lang_string("Tt");
|
||||
echo "<th>".lang_string("Firing");
|
||||
echo "<th>".lang_string("Time");
|
||||
echo "<th>".lang_string("Desc");
|
||||
echo "<th>".lang_string("Recovery");
|
||||
echo "<th>".lang_string("MinMax.Al");
|
||||
echo "<th>".lang_string("Days");
|
||||
echo "<th>".lang_string("Fired");
|
||||
while ($row2=mysql_fetch_array($result_com)){
|
||||
|
||||
// calculate days
|
||||
$firing_days = get_alert_days ( $row2 );
|
||||
echo "</td><td class='$tdcolor'>".$firing_days;
|
||||
if ($color == 1){
|
||||
$tdcolor = "datos";
|
||||
$color = 0;
|
||||
}
|
||||
else {
|
||||
$tdcolor = "datos2";
|
||||
$color = 1;
|
||||
}
|
||||
echo "<tr>";
|
||||
|
||||
// Fired ?
|
||||
if ($row2["times_fired"]>0)
|
||||
echo "<td class='".$tdcolor."' align='center'><img width='20' height='9' src='images/pixel_red.png' title='".lang_string("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>";
|
||||
if ($row2["disable"] == 1){
|
||||
$tdcolor = "datos3";
|
||||
}
|
||||
echo "<td class=$tdcolor>".get_db_sql("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo =".$row2["id_agente_modulo"]);
|
||||
echo "<td class=$tdcolor>".$row2["operation"];
|
||||
|
||||
}
|
||||
echo "</table>";
|
||||
echo "<td class='$tdcolor'>".human_time_description($row2["time_threshold"]);
|
||||
|
||||
if ($row2["dis_min"]!=0){
|
||||
$mytempdata = fmod($row2["dis_min"], 1);
|
||||
if ($mytempdata == 0)
|
||||
$mymin = intval($row2["dis_min"]);
|
||||
else
|
||||
$mymin = $row2["dis_min"];
|
||||
$mymin = format_for_graph($mymin );
|
||||
} else {
|
||||
$mymin = 0;
|
||||
}
|
||||
|
||||
if ($row2["dis_max"]!=0){
|
||||
$mytempdata = fmod($row2["dis_max"], 1);
|
||||
if ($mytempdata == 0)
|
||||
$mymax = intval($row2["dis_max"]);
|
||||
else
|
||||
$mymax = $row2["dis_max"];
|
||||
$mymax = format_for_graph($mymax );
|
||||
} else {
|
||||
$mymax = 0;
|
||||
}
|
||||
|
||||
if (($mymin == 0) && ($mymax == 0)){
|
||||
$mymin = lang_string ("N/A");
|
||||
$mymax = $mymin;
|
||||
}
|
||||
|
||||
// We have alert text ?
|
||||
if ($row2["alert_text"]!= "") {
|
||||
echo "<td class='$tdcolor'>".$lang_label["text"]."</td>";
|
||||
} else {
|
||||
echo "<td class='$tdcolor'>".$mymin."/".$mymax."</td>";
|
||||
}
|
||||
|
||||
// Alert times
|
||||
echo "<td class='$tdcolor'>";
|
||||
echo get_alert_times ($row2);
|
||||
|
||||
// Description
|
||||
echo "</td><td class='$tdcolor'>".substr($row2["descripcion"],0,20);
|
||||
|
||||
// Has recovery notify activated ?
|
||||
if ($row2["recovery_notify"] > 0)
|
||||
$recovery_notify = lang_string("Yes");
|
||||
else
|
||||
$recovery_notify = lang_string("No");
|
||||
|
||||
echo "</td><td class='$tdcolor'>".$recovery_notify;
|
||||
|
||||
// calculare firing conditions
|
||||
if ($row2["alert_text"] != ""){
|
||||
$firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")";
|
||||
} else {
|
||||
$firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"];
|
||||
}
|
||||
echo "</td><td class='$tdcolor'>".$firing_cond;
|
||||
|
||||
// calculate days
|
||||
$firing_days = get_alert_days ( $row2 );
|
||||
echo "</td><td class='$tdcolor'>".$firing_days;
|
||||
|
||||
// Fired ?
|
||||
if ($row2["times_fired"]>0)
|
||||
echo "<td class='".$tdcolor."' align='center'><img width='20' height='9' src='images/pixel_red.png' title='".lang_string("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>";
|
||||
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
function smal_event_table ($filter = "", $limit = 10, $width=440){
|
||||
global $config;
|
||||
|
|
|
@ -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"> <span>'.$text.'</span></a>';
|
||||
|
||||
if ($return)
|
||||
return $output;
|
||||
echo $output;
|
||||
}
|
||||
|
||||
?>
|
|
@ -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
Loading…
Reference in New Issue