\n");
}
}
}
function pagination ($count, $url, $offset ) {
global $config;
require ("include/languages/language_".$config["language"].".php");
/* URL passed render links with some parameter
&offset - Offset records passed to next page
&counter - Number of items to be blocked
Pagination needs $url to build the base URL to render links, its a base url, like
" http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs "
*/
$block_limit = 15; // Visualize only $block_limit blocks
if ($count > $config["block_size"]){
// If exists more registers than I can put in a page, calculate index markers
$index_counter = ceil($count/$config["block_size"]); // Number of blocks of block_size with data
$index_page = ceil($offset/$config["block_size"])-(ceil($block_limit/2)); // block to begin to show data;
if ($index_page < 0)
$index_page = 0;
// This calculate index_limit, block limit for this search.
if (($index_page + $block_limit) > $index_counter)
$index_limit = $index_counter;
else
$index_limit = $index_page + $block_limit;
// This calculate if there are more blocks than visible (more than $block_limit blocks)
if ($index_counter > $block_limit )
$paginacion_maxima = 1; // If maximum blocks ($block_limit), show only 10 and "...."
else
$paginacion_maxima = 0;
// This setup first block of query
if ( $paginacion_maxima == 1)
if ($index_page == 0)
$inicio_pag = 0;
else
$inicio_pag = $index_page;
else
$inicio_pag = 0;
echo "
";
// Show GOTO FIRST button
echo '';
echo "";
echo "";
echo " ";
// Show PREVIOUS button
if ($index_page > 0){
$index_page_prev= ($index_page-(floor($block_limit/2)))*$config["block_size"];
if ($index_page_prev < 0)
$index_page_prev = 0;
echo '';
}
echo " ";echo " ";
// Draw blocks markers
// $i stores number of page
for ($i = $inicio_pag; $i < $index_limit; $i++) {
$inicio_bloque = ($i * $config["block_size"]);
$final_bloque = $inicio_bloque + $config["block_size"];
if ($final_bloque > $count){ // if upper limit is beyond max, this shouldnt be possible !
$final_bloque = ($i-1)*$config["block_size"] + $count-(($i-1) * $config["block_size"]);
}
echo "";
$inicio_bloque_fake = $inicio_bloque + 1;
// To Calculate last block (doesnt end with round data,
// it must be shown if not round to block limit)
echo '';
if ($inicio_bloque == $offset)
echo "[ $i ]";
else
echo "[ $i ]";
echo ' ';
echo "";
}
echo " ";echo " ";
// Show NEXT PAGE (fast forward)
// Index_counter stores max of blocks
if (($paginacion_maxima == 1) AND (($index_counter - $i) > 0)) {
$prox_bloque = ($i+ceil($block_limit/2))*$config["block_size"];
if ($prox_bloque > $count)
$prox_bloque = ($count -1) - $config["block_size"];
echo '';
echo " ";
$i = $index_counter;
}
// if exists more registers than i can put in a page (defined by $block_size config parameter)
// get offset for index calculation
// Draw "last" block link, ajust for last block will be the same
// as painted in last block (last integer block).
if (($count - $config["block_size"]) > 0){
$myoffset = floor(($count-1)/ $config["block_size"])* $config["block_size"];
echo '';
echo "";
echo "";
}
// End div and layout
echo "
";
}
}
// ---------------------------------------------------------------
// Render data in a fashion way :-)
// ---------------------------------------------------------------
function format_numeric ( $number, $decimals=2, $dec_point=".", $thousands_sep=",") {
if ($number == 0)
return 0;
// 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);
}
// ---------------------------------------------------------------
// Render numeric data in a easy way to the user
// ---------------------------------------------------------------
function format_for_graph ( $number , $decimals=2, $dec_point=".", $thousands_sep=",") {
if ($number > "1000000")
if (fmod ($number, 1000000) > 0)
return number_format ($number/1000000, $decimals, $dec_point, $thousands_sep)." M";
else
return number_format ($number/1000000, 0, $dec_point, $thousands_sep)." M";
if ($number > "1000")
if (fmod ($number, 1000) > 0)
return number_format ($number/1000, $decimals, $dec_point, $thousands_sep )." K";
else
return number_format ($number/1000, 0, $dec_point, $thousands_sep )." K";
// 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);
}
function give_parameter_get ( $name, $default = "" ){
$output = $default;
if (isset ($_GET[$name])){
$output = $_GET[$name];
}
return $output;
}
function give_parameter_post ( $name, $default = "" ){
$output = $default;
if (isset ($_POST[$name])){
$output = $_POST[$name];
}
return $output;
}
function give_parameter_get_numeric ( $name, $default = "-1" ){
$output = $default;
if (isset ($_GET[$name])){
$output = $_GET[$name];
}
if (is_numeric($output))
return $output;
else
return -1;
}
function give_parameter_post_numeric ( $name, $default = "" ){
$output = $default;
if (isset ($_POST[$name])){
$output = $_POST[$name];
}
if (is_numeric($output))
return $output;
else
return -1;
}
function human_time_comparation ( $timestamp ){
global $lang_label;
if ($timestamp != ""){
$ahora=date("Y/m/d H:i:s");
$seconds = strtotime($ahora) - strtotime($timestamp);
} else
$seconds = 0;
if ($seconds < 3600)
$render = format_numeric($seconds/60,1)." ".$lang_label["minutes"];
elseif (($seconds >= 3600) and ($seconds < 86400))
$render = format_numeric ($seconds/3600,1)." ".$lang_label["hours"];
elseif (($seconds >= 86400) and ($seconds < 2592000))
$render = format_numeric ($seconds/86400,1)." ".$lang_label["days"];
elseif (($seconds >= 2592000) and ($seconds < 15552000))
$render = format_numeric ($seconds/2592000,1)." ".$lang_label["months"];
elseif ($seconds >= 15552000)
$render = " +6 ".$lang_label["months"];
return $render;
}
function human_time_description_raw ($seconds){
global $lang_label;
if ($seconds < 3600)
$render = format_numeric($seconds/60,2)." ".$lang_label["minutes"];
elseif (($seconds >= 3600) and ($seconds < 86400))
$render = format_numeric ($seconds/3600,2)." ".$lang_label["hours"];
elseif ($seconds >= 86400)
$render = format_numeric ($seconds/86400,2)." ".$lang_label["days"];
return $render;
}
function human_time_description ($period){
global $lang_label;
switch ($period) {
case 3600: $period_label = $lang_label["hour"];
break;
case 7200: $period_label = $lang_label["2_hours"];
break;
case 21600: $period_label = $lang_label["6_hours"];
break;
case 43200: $period_label = $lang_label["12_hours"];
break;
case 86400: $period_label = $lang_label["last_day"];
break;
case 172800: $period_label = $lang_label["two_days"];
break;
case 432000: $period_label = $lang_label["five_days"];
break;
case 604800: $period_label = $lang_label["last_week"];
break;
case 1296000: $period_label = $lang_label["15_days"];
break;
case 2592000: $period_label = $lang_label["last_month"];
break;
case 5184000: $period_label = $lang_label["two_month"];
break;
case 15552000: $period_label = $lang_label["six_months"];
break;
default: $period_label = human_time_description_raw ($period);
}
return $period_label;
}
// This function returns MYSQL Date from now - seconds passed as parameter
function human_date_relative ( $seconds ) {
$ahora=date("Y/m/d H:i:s");
$ahora_s = date("U");
$ayer = date ("Y/m/d H:i:s", $ahora_s - $seconds);
return $ayer;
}
function render_time ($lapse) {
$myhour = intval(($lapse*30)/60);
if ($myhour == 0)
$output = "00";
else
$output = $myhour;
$output .=":";
$mymin = fmod(($lapse*30),60);
if ($mymin == 0)
$output .= "00";
else
$output .= $mymin;
return $output;
}
function get_parameter ($name, $default = '') {
// POST has precedence
if (isset($_POST[$name]))
return get_parameter_post ($name, $default);
if (isset($_GET[$name]))
return get_parameter_get ($name, $default);
return $default;
}
function get_parameter_get ($name, $default = "") {
if ((isset ($_GET[$name])) && ($_GET[$name] != ""))
return safe_input ($_GET[$name]);
return $default;
}
function get_parameter_post ( $name, $default = "" ){
if ((isset ($_POST[$name])) && ($_POST[$name] != ""))
return safe_input ($_POST[$name]);
return $default;
}
function get_alert_priority ( $prio ){
$priority = "NORMAL";
switch ($prio){
case 0:
$priority = "NORMAL";
break;
case 1:
$priority = "WARNING";
break;
case 2:
$priority = "MINOR";
break;
case 3:
$priority = "MAJOR";
break;
case 4:
$priority = "CRITICAL";
break;
}
return $priority;
}
function get_alert_days ( $row ){
global $config;
global $lang_label;
$days_output = "";
$check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"]+ $row["friday"] + $row["saturday"] + $row["sunday"];
if ($row["monday"] != 0)
$days_output .= "Mo";
if ($row["tuesday"] != 0)
$days_output .= "Tu";
if ($row["wednesday"] != 0)
$days_output .= "We";
if ($row["thursday"] != 0)
$days_output .= "Th";
if ($row["friday"] != 0)
$days_output .= "Fr";
if ($row["saturday"] != 0)
$days_output .= "Sa";
if ($row["sunday"] != 0)
$days_output .= "Su";
if ($days_output == "")
$days_output = lang_string ("none");
if ($check == 7)
$days_output = lang_string ("all");
return $days_output;
}
function get_alert_times ($row2){
global $config;
global $lang_label;
if ($row2["time_from"]){
$time_from_table = $row2["time_from"];
} else {
$time_from_table = lang_string("N/A");
}
if ($row2["time_to"]){
$time_to_table = $row2["time_to"];
} else {
$time_to_table = lang_string("N/A");
}
$string = "";
if ($time_to_table == $time_from_table)
$string .= $lang_label["N/A"];
else
$string .= substr($time_from_table,0,5)." - ".substr($time_to_table,0,5);
return $string;
}
function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $combined = 0){
global $config;
global $lang_label;
$string = "";
if ($row2["disable"] == 1){
$string .= "
";
return $string;
}
function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){
global $config;
global $lang_label;
if ($combined == 0){
$module_name = get_db_sql ("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]);
$agent_name = get_db_sql ("SELECT tagente.nombre FROM tagente_modulo, tagente WHERE tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.id_agente_modulo = ".$data["id_agente_modulo"]);
$id_agente = get_db_sql ("SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]);
} else {
$agent_name = get_db_sql ("SELECT nombre FROM tagente WHERE id_agente =".$data["id_agent"]);
$id_agente = $data["id_agent"];
}
$alert_name = get_db_sql ("SELECT nombre FROM talerta WHERE id_alerta = ".$data["id_alerta"]);
echo "