2011-02-28 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_db.php: cleaned source code, and erased the deprecated
	functions "dame_nombre_real" and "show_alert_row_mini".
	
	* operation/incidents/incident_detail.php,
	operation/snmpconsole/snmp_view.php: replaced obsolete "dame_nombre_real"
	to "get_user_fullname". 



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4030 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-02-28 17:47:22 +00:00
parent 2636584aa8
commit 27f912c861
4 changed files with 791 additions and 882 deletions

View File

@ -1,3 +1,11 @@
2011-02-28 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_db.php: cleaned source code, and erased the deprecated
functions "dame_nombre_real" and "show_alert_row_mini".
* operation/incidents/incident_detail.php,
operation/snmpconsole/snmp_view.php: replaced obsolete "dame_nombre_real"
to "get_user_fullname".
2011-02-28 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_db.php: cleaned source code, and erased the deprecated
function "dame_admin".

View File

@ -682,15 +682,15 @@ function get_agentmodule_is_init ($id_agentmodule) {
* @param bool Wheter to return the modules indexed by the id_agente_modulo or
* not. Default is indexed.
* Example:
<code>
Both are similars:
$modules = get_agent_modules ($id_agent, false, array ('disabled' => 0));
$modules = get_agent_modules ($id_agent, false, 'disabled = 0');
<code>
Both are similars:
$modules = get_agent_modules ($id_agent, false, array ('disabled' => 0));
$modules = get_agent_modules ($id_agent, false, 'disabled = 0');
Both are similars:
$modules = get_agent_modules ($id_agent, '*', array ('disabled' => 0, 'history_data' => 0));
$modules = get_agent_modules ($id_agent, '*', 'disabled = 0 AND history_data = 0');
</code>
Both are similars:
$modules = get_agent_modules ($id_agent, '*', array ('disabled' => 0, 'history_data' => 0));
$modules = get_agent_modules ($id_agent, '*', 'disabled = 0 AND history_data = 0');
</code>
*
* @return array An array with all modules in the agent.
* If multiple rows are selected, they will be in an array
@ -1008,13 +1008,6 @@ function get_agentmodule_type ($id_agentmodule) {
return (int) get_db_value ('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', (int) $id_agentmodule);
}
/**
* DEPRECATED: User get_user_fullname
*/
function dame_nombre_real ($id_user) {
return get_user_fullname ($id_user);
}
/**
* Get all the times a monitor went down during a period.
*
@ -1840,6 +1833,7 @@ function show_icon_type ($id_type) {
*/
function show_server_type ($id) {
global $config;
switch ($id) {
case 1:
return print_image("images/database.png", true, array("title" => "Pandora FMS Data server"));
@ -1861,6 +1855,7 @@ function show_server_type ($id) {
break;
default:
return "--";
break;
}
}
@ -1886,6 +1881,7 @@ function give_modulecategory_name ($id_category) {
return __('Network agent monitor');
break;
}
return __('Unknown');
}
@ -1985,6 +1981,7 @@ function get_agent_with_ip ($ip_address) {
WHERE tagente.id_agente = taddress_agent.id_agent
AND taddress_agent.id_a = taddress.id_a
AND ip = "%s"', $ip_address);
return get_db_row_sql ($sql);
}
@ -2055,17 +2052,17 @@ function get_db_value($field, $table, $field_search = 1, $condition = 1, $search
* array with filter conditions.
*
* Example:
<code>
get_db_value_filter ('name', 'talert_templates',
<code>
get_db_value_filter ('name', 'talert_templates',
array ('value' => 2, 'type' => 'equal'));
// Equivalent to:
// SELECT name FROM talert_templates WHERE value = 2 AND type = 'equal' LIMIT 1
// Equivalent to:
// SELECT name FROM talert_templates WHERE value = 2 AND type = 'equal' LIMIT 1
get_db_value_filter ('description', 'talert_templates',
get_db_value_filter ('description', 'talert_templates',
array ('name' => 'My alert', 'type' => 'regex'), 'OR');
// Equivalent to:
// SELECT description FROM talert_templates WHERE name = 'My alert' OR type = 'equal' LIMIT 1
</code>
// Equivalent to:
// SELECT description FROM talert_templates WHERE name = 'My alert' OR type = 'equal' LIMIT 1
</code>
*
* @param string Field name to get
* @param string Table to retrieve the data
@ -2166,16 +2163,16 @@ function get_db_row ($table, $field_search, $condition, $fields = false) {
* (keys would be the field name and value the expected value, and would be
* joined with an AND operator) or a string, including any SQL clause (without
* the WHERE keyword). Example:
<code>
Both are similars:
get_db_row_filter ('table', array ('disabled', 0));
get_db_row_filter ('table', 'disabled = 0');
<code>
Both are similars:
get_db_row_filter ('table', array ('disabled', 0));
get_db_row_filter ('table', 'disabled = 0');
Both are similars:
get_db_row_filter ('table', array ('disabled' => 0, 'history_data' => 0), 'name, description', 'OR');
get_db_row_filter ('table', 'disabled = 0 OR history_data = 0', 'name, description');
get_db_row_filter ('table', array ('disabled' => 0, 'history_data' => 0), array ('name', 'description'), 'OR');
</code>
Both are similars:
get_db_row_filter ('table', array ('disabled' => 0, 'history_data' => 0), 'name, description', 'OR');
get_db_row_filter ('table', 'disabled = 0 OR history_data = 0', 'name, description');
get_db_row_filter ('table', array ('disabled' => 0, 'history_data' => 0), array ('name', 'description'), 'OR');
</code>
* @param mixed Fields of the table to retrieve. Can be an array or a coma
* separated string. All fields are retrieved by default
* @param string Condition to join the filters (AND, OR).
@ -2185,7 +2182,8 @@ get_db_row_filter ('table', array ('disabled' => 0, 'history_data' => 0), array
function get_db_row_filter ($table, $filter, $fields = false, $where_join = 'AND') {
if (empty ($fields)) {
$fields = '*';
} else {
}
else {
if (is_array ($fields))
$fields = implode (',', $fields);
else if (! is_string ($fields))
@ -2215,8 +2213,10 @@ function get_db_row_filter ($table, $filter, $fields = false, $where_join = 'AND
function get_db_sql ($sql, $field = 0, $search_history_db = false) {
$result = get_db_all_rows_sql ($sql, $search_history_db);
if($result === false)
return false;
$ax = 0;
foreach ($result[0] as $f){
if ($field == $ax)
@ -2348,7 +2348,9 @@ function sql_error_handler ($errno, $errstr) {
if (error_reporting () <= $errno)
return false;
echo "<strong>SQL error</strong>: ".$errstr."<br />\n";
return true;
}
@ -2462,14 +2464,17 @@ function get_db_all_rows_in_table ($table, $order_field = "", $order = 'ASC') {
function get_db_all_rows_field_filter ($table, $field, $condition, $order_field = "") {
if (is_int ($condition) || is_bool ($condition)) {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = %d", $table, $field, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
}
else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = %f", $table, $field, $condition);
} else {
}
else {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = '%s'", $table, $field, $condition);
}
if ($order_field != "")
$sql .= sprintf (" ORDER BY %s", $order_field);
return get_db_all_rows_sql ($sql);
}
@ -2530,11 +2535,14 @@ function format_array_to_update_sql ($values) {
if ($value === NULL) {
$sql = sprintf ("`%s` = NULL", $field);
} elseif (is_int ($value) || is_bool ($value)) {
}
elseif (is_int ($value) || is_bool ($value)) {
$sql = sprintf ("`%s` = %d", $field, $value);
} elseif (is_float ($value) || is_double ($value)) {
}
elseif (is_float ($value) || is_double ($value)) {
$sql = sprintf ("`%s` = %f", $field, $value);
} else {
}
else {
/* String */
if (isset ($value[0]) && $value[0] == '`')
/* Don't round with quotes if it references a field */
@ -2553,14 +2561,14 @@ function format_array_to_update_sql ($values) {
*
* This function is useful to generate a WHERE clause for a SQL sentence from
* a list of values. Example code:
<code>
$values = array ();
$values['name'] = "Name";
$values['description'] = "Long description";
$values['limit'] = $config['block_size']; // Assume it's 20
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
echo $sql;
</code>
<code>
$values = array ();
$values['name'] = "Name";
$values['description'] = "Long description";
$values['limit'] = $config['block_size']; // Assume it's 20
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
echo $sql;
</code>
* Will return:
* <code>
* SELECT * FROM table WHERE `name` = "Name" AND `description` = "Long description" LIMIT 20
@ -2571,42 +2579,42 @@ echo $sql;
* as ORDER, LIMIT and OFFSET clauses respectively. Since LIMIT and OFFSET are
* numerics, ORDER can receive a field name or a SQL function and a the ASC or
* DESC clause. Examples:
<code>
$values = array ();
$values['value'] = 10;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// SELECT * FROM table WHERE VALUE = 10
<code>
$values = array ();
$values['value'] = 10;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// SELECT * FROM table WHERE VALUE = 10
$values = array ();
$values['value'] = 10;
$values['order'] = 'name DESC';
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// SELECT * FROM table WHERE VALUE = 10 ORDER BY name DESC
$values = array ();
$values['value'] = 10;
$values['order'] = 'name DESC';
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// SELECT * FROM table WHERE VALUE = 10 ORDER BY name DESC
</code>
</code>
* @param string Join operator. AND by default.
* @param string A prefix to be added to the string. It's useful when limit and
* offset could be given to avoid this cases:
<code>
$values = array ();
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// Wrong SQL: SELECT * FROM table WHERE LIMIT 10 OFFSET 20
<code>
$values = array ();
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
// Wrong SQL: SELECT * FROM table WHERE LIMIT 10 OFFSET 20
$values = array ();
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values, 'AND', 'WHERE');
// Good SQL: SELECT * FROM table LIMIT 10 OFFSET 20
$values = array ();
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values, 'AND', 'WHERE');
// Good SQL: SELECT * FROM table LIMIT 10 OFFSET 20
$values = array ();
$values['value'] = 5;
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values, 'AND', 'WHERE');
// Good SQL: SELECT * FROM table WHERE value = 5 LIMIT 10 OFFSET 20
</code>
$values = array ();
$values['value'] = 5;
$values['limit'] = 10;
$values['offset'] = 20;
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values, 'AND', 'WHERE');
// Good SQL: SELECT * FROM table WHERE value = 5 LIMIT 10 OFFSET 20
</code>
*
* @return string Values joined into an SQL string that can fits into the WHERE
* clause of an SQL sentence.
@ -2728,7 +2736,7 @@ function format_array_to_where_clause_sql ($values, $join = 'AND', $prefix = fal
* @return int Module status. Value 4 means that some alerts assigned to the
* module were fired.
*/
function get_agentmodule_status ($id_agentmodule = 0) {
function get_agentmodule_status($id_agentmodule = 0) {
$current_timestamp = get_system_time ();
$times_fired = get_db_value ('SUM(times_fired)', 'talert_template_modules', 'id_agent_module', $id_agentmodule);
@ -2748,7 +2756,7 @@ function get_agentmodule_status ($id_agentmodule = 0) {
*
* @return int Module last status.
*/
function get_agentmodule_last_status ($id_agentmodule = 0) {
function get_agentmodule_last_status($id_agentmodule = 0) {
$status_row = get_db_row ("tagente_estado", "id_agente_modulo", $id_agentmodule);
return $status_row['last_status'];
@ -2762,7 +2770,7 @@ function get_agentmodule_last_status ($id_agentmodule = 0) {
* @return int Worst status of an agent for all of its modules.
* The value -1 is returned in case the agent has exceed its interval.
*/
function get_agent_status ($id_agent = 0) {
function get_agent_status($id_agent = 0) {
$modules = get_agent_modules ($id_agent, 'id_agente_modulo', array('disabled' => 0), true, false);
$modules_status = array();
@ -2937,7 +2945,8 @@ function get_previous_data ($id_agent_module, $utimestamp = 0, $string = 0) {
if ($string == 1) {
$table = 'tagente_datos_string';
} else {
}
else {
$table = 'tagente_datos';
}
@ -2966,7 +2975,8 @@ function get_next_data ($id_agent_module, $utimestamp = 0, $string = 0) {
if ($string == 1) {
$table = 'tagente_datos_string';
} else {
}
else {
$table = 'tagente_datos';
}
@ -3026,10 +3036,10 @@ function get_agentmodule_data ($id_agent_module, $period, $date = 0) {
* @param string String to translate. It can have special format characters like
* a printf
* @param mixed Optional parameters to be replaced in string. Example:
<code>
echo __('Hello!');
echo __('Hello, %s!', $user);
</code>
<code>
echo __('Hello!');
echo __('Hello, %s!', $user);
</code>
*
* @return string The translated string. If not defined, the same string will be returned
*/
@ -3088,122 +3098,6 @@ function check_server_status () {
return $status;
}
/**
* @deprecated Will show a small HTML table with some compound alert information
*/
function show_alert_row_mini ($id_combined_alert) {
$color=1;
$sql = sprintf ("SELECT talert_template_modules.*,tcompound_alert.operation
FROM talert_template_modules, tcompound_alert
WHERE tcompound_alert.id_aam = talert_template_modules.id
AND tcompound_alert.id = %d", $id_combined_alert);
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return;
echo "<table width=400 cellpadding=2 cellspacing=2 class='databox'>";
echo "<th>".__('Name')."</th>";
echo "<th>".__('Oper')."</th>";
/* Translators: Abbrevation for Time threshold */
echo "<th>".__('Tt')."</th>";
echo "<th>".__('Firing')."</th>";
echo "<th>".__('Time')."</th>";
/* Translators: Abbrevation for Description */
echo "<th>".__('Desc')."</th>";
echo "<th>".__('Recovery')."</th>";
echo "<th>".__('MinMax.Al')."</th>";
echo "<th>".__('Days')."</th>";
echo "<th>".__('Fired')."</th>";
foreach ($result as $row2) {
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"])."</td>";
echo "<td class=$tdcolor>".$row2["operation"]."</td>";
echo "<td class='$tdcolor'>".human_time_description ($row2["time_threshold"])."</td>";
if ($row2["dis_min"]!=0) {
$mytempdata = fmod ($row2["dis_min"], 1);
if ($mytempdata == 0) {
$mymin = intval ($row2["dis_min"]);
} else {
$mymin = format_for_graph ($row2["dis_min"]);
}
} else {
$mymin = 0;
}
if ($row2["dis_max"]!=0) {
$mytempdata = fmod ($row2["dis_max"], 1);
if ($mytempdata == 0) {
$mymax = intval ($row2["dis_max"]);
} else {
$mymax = format_for_graph ($row2["dis_max"]);
}
} else {
$mymax = 0;
}
if (($mymin == 0) && ($mymax == 0)) {
$mymin = __('N/A');
$mymax = $mymin;
}
// We have alert text ?
if ($row2["alert_text"]!= "") {
echo "<td class='$tdcolor'>".__('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 = __('Yes');
} else {
$recovery_notify = __('No');
}
echo "</td><td class='$tdcolor'>".$recovery_notify;
// calculare firing conditions
if ($row2["alert_text"] != ""){
$firing_cond = __('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'>" . print_image('images/pixel_red.png', true, array("title" => __('Alert fired'), "width" => '20', "height" => '9')) . "</td>";
} else {
echo "<td class='".$tdcolor."' align='center'>" . print_image('images/pixel_green.png', true, array("title" => __('Alert not fired'), "width" => '20', "height" => '9')) . "</td>";
}
}
echo "</table>";
}
/**
* @deprecated use get_server_info instead
* Get statistical information for a given server
@ -3211,7 +3105,7 @@ function show_alert_row_mini ($id_combined_alert) {
* @param int Server id to get status.
*
* @return array Server info array
*/
*/
function server_status ($id_server) {
$serverinfo = get_server_info ($id_server);
return $serverinfo[$id_server];
@ -3238,7 +3132,7 @@ function temp_sql_delete ($table, $row, $value) {
* @param bool Disable the ACL checking, for default false.
*
* @return bool False if error, true if success.
*/
*/
function delete_agent ($id_agents, $disableACL = false) {
global $config;
@ -3356,7 +3250,8 @@ function delete_agent ($id_agents, $disableACL = false) {
if ($error) {
process_sql_rollback ();
return false;
} else {
}
else {
process_sql_commit ();
return true;
}
@ -3506,7 +3401,8 @@ function process_sql_update ($table, $values, $where = false, $where_join = 'AND
if (is_string ($where)) {
// No clean, the caller should make sure all input is clean, this is a raw function
$query .= " WHERE ".$where;
} else if (is_array ($where)) {
}
else if (is_array ($where)) {
$query .= format_array_to_where_clause_sql ($where, $where_join, ' WHERE ');
}
}
@ -3554,7 +3450,8 @@ function process_sql_delete ($table, $where, $where_join = 'AND') {
/* FIXME: Should we clean the string for sanity?
Who cares if this is deleting data... */
$query .= $where;
} else if (is_array ($where)) {
}
else if (is_array ($where)) {
$query .= format_array_to_where_clause_sql ($where, $where_join);
}
}
@ -3596,7 +3493,9 @@ function process_sql_rollback () {
function get_group_users ($id_group, $filter = false) {
if (! is_array ($filter))
$filter = array ();
$filter['id_grupo'] = $id_group;
$resulta = array();
$resulta = get_db_all_rows_filter ("tusuario_perfil", $filter);
@ -3616,13 +3515,15 @@ function get_group_users ($id_group, $filter = false) {
if ($result === false)
return array ();
//This removes stale users from the list. This can happen if switched to another auth scheme
//(internal users still exist) or external auth has users removed/inactivated from the list (eg. LDAP)
$retval = array ();
foreach ($result as $key => $user) {
if (!is_user ($user)) {
unset ($result[$key]);
} else {
}
else {
array_push ($retval, get_user_info ($user));
}
}

View File

@ -276,7 +276,7 @@ echo '</td><td class="datos"><b>'.__('Creator').'</b></td><td class="datos">';
if (empty ($id_creator)) {
echo 'SYSTEM';
} else {
echo $id_creator.' (<i>'.dame_nombre_real ($id_creator).'</i>)';
echo $id_creator.' (<i>'.get_user_fullname($id_creator).'</i>)';
}
echo '</td></tr><tr><td class="datos2" colspan="4">';

View File

@ -352,7 +352,7 @@ if ($traps !== false) {
//User
if (!empty ($trap["status"])) {
$data[5] = '<a href="index.php?sec=usuarios&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
$data[5] .= '<a href="#" class="tip">&nbsp;<span>'.dame_nombre_real($trap["id_usuario"]).'</span></a>';
$data[5] .= '<a href="#" class="tip">&nbsp;<span>'.get_user_fullname($trap["id_usuario"]).'</span></a>';
} else {
$data[5] = '--';
}