From c52995125a18519428d1f7bb5d7bb3ffbcb8c091 Mon Sep 17 00:00:00 2001
From: mdtrooper <tres.14159@gmail.com>
Date: Mon, 8 Jul 2013 10:15:49 +0000
Subject: [PATCH] 2013-07-08 Miguel de Dios <miguel.dedios@artica.es>

	* mobile/operation/alerts.php, mobile/operation/events.php,
	mobile/operation/modules.php, mobile/operation/networkmaps.php,
	mobile/operation/agents.php, mobile/include/ui.class.php,
	mobile/include/style/main.css: some fixes.

	MERGED FROM BRANCH 4.0




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8492 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  9 ++
 pandora_console/mobile/include/style/main.css |  4 +-
 pandora_console/mobile/include/ui.class.php   | 11 ++-
 pandora_console/mobile/operation/agents.php   | 36 ++++++--
 pandora_console/mobile/operation/alerts.php   | 48 +++++++++--
 pandora_console/mobile/operation/events.php   | 85 ++++++++++++++-----
 pandora_console/mobile/operation/modules.php  | 60 ++++++++++---
 .../mobile/operation/networkmaps.php          | 42 +++++++--
 8 files changed, 240 insertions(+), 55 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index ad59b0eaf7..bc6305176d 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,12 @@
+2013-07-08 Miguel de Dios <miguel.dedios@artica.es>
+	
+	* mobile/operation/alerts.php, mobile/operation/events.php,
+	mobile/operation/modules.php, mobile/operation/networkmaps.php,
+	mobile/operation/agents.php, mobile/include/ui.class.php,
+	mobile/include/style/main.css: some fixes.
+	
+	MERGED FROM BRANCH 4.0
+
 2013-07-05 Miguel de Dios <miguel.dedios@artica.es>
 	
 	* include/functions_events.php: erased lost debug trace.
diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css
index a56b8944f1..f79e03bd20 100644
--- a/pandora_console/mobile/include/style/main.css
+++ b/pandora_console/mobile/include/style/main.css
@@ -289,7 +289,8 @@ table#list_events th {
 	font-weight: bolder !important;
 }
 
-@media screen and (max-width: 320px)
+/*
+@media screen and (max-width: 25em)
 {
 	.pandora_responsive th {
 		padding-right: 10px;
@@ -411,6 +412,7 @@ table#list_events th {
 		width: 300px;
 	}
 }
+*/
 
 #list_events a {
 	color: #333333 !important;
diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php
index a475e7533a..93e803405f 100755
--- a/pandora_console/mobile/include/ui.class.php
+++ b/pandora_console/mobile/include/ui.class.php
@@ -524,8 +524,15 @@ class Ui {
 			
 			$selected = '';
 			if (isset($options['selected'])) {
-				if ($options['selected'] === $item_id) {
-					$selected = "selected = 'selected'";
+				if (is_numeric($options['selected'])) {
+					if (floatval($options['selected']) === floatval($item_id)) {
+						$selected = "selected = 'selected'";
+					}
+				}
+				else {
+					if ($options['selected'] === $item_id) {
+						$selected = "selected = 'selected'";
+					}
 				}
 			}
 			
diff --git a/pandora_console/mobile/operation/agents.php b/pandora_console/mobile/operation/agents.php
index a68f734ce3..1212d84276 100644
--- a/pandora_console/mobile/operation/agents.php
+++ b/pandora_console/mobile/operation/agents.php
@@ -17,6 +17,8 @@ class Agents {
 	private $acl = "AR";
 	
 	private $default = true;
+	private $default_filters = array();
+	
 	private $group = 0;
 	private $status = -1;
 	private $free_search = '';
@@ -97,9 +99,14 @@ class Agents {
 		$system = System::getInstance();
 		$user = User::getInstance();
 		
+		$this->default_filters['group'] = true;
+		$this->default_filters['status'] = true;
+		$this->default_filters['free_search'] = true;
+		
 		$this->free_search = $system->getRequest('free_search', '');
 		if ($this->free_search != '') {
 			$this->default = false;
+			$this->default_filters['free_search'] = false;
 		}
 		
 		$this->status = $system->getRequest('status', __("Status"));
@@ -108,6 +115,7 @@ class Agents {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['status'] = false;
 		}
 		
 		$this->group = (int)$system->getRequest('group', __("Group"));
@@ -119,6 +127,7 @@ class Agents {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['group'] = false;
 		}
 	}
 	
@@ -406,13 +415,30 @@ class Agents {
 			return __("(Default)");
 		}
 		else {
-			$status = $this->list_status[$this->status];
-			$group = groups_get_name($this->group, true);
+			$filters_to_serialize = array();
 			
+			if (!$this->default_filters['group']) {
+				$filters_to_serialize[] = sprintf(__("Group: %s"),
+					groups_get_name($this->group, true));
+			}
+			if (!$this->default_filters['status']) {
+				$filters_to_serialize[] = sprintf(__("Status: %s"),
+					$this->list_status[$this->status]);
+			}
+			if (!$this->default_filters['free_search']) {
+				$filters_to_serialize[] = sprintf(__("Free Search: %s"),
+					$this->free_search);
+			}
 			
-			$string = sprintf(
-				__("(Status: %s - Group: %s - Free Search: %s)"),
-				$status, $group, $this->free_search);
+			$string = '(' . implode(' - ', $filters_to_serialize) . ')';
+			
+			//~ $status = $this->list_status[$this->status];
+			//~ $group = groups_get_name($this->group, true);
+			//~ 
+			//~ 
+			//~ $string = sprintf(
+				//~ __("(Status: %s - Group: %s - Free Search: %s)"),
+				//~ $status, $group, $this->free_search);
 			
 			return $string;
 		}
diff --git a/pandora_console/mobile/operation/alerts.php b/pandora_console/mobile/operation/alerts.php
index af0dbe46f2..f6f97c9511 100644
--- a/pandora_console/mobile/operation/alerts.php
+++ b/pandora_console/mobile/operation/alerts.php
@@ -17,6 +17,7 @@ class Alerts {
 	private $acl = "LM";
 	
 	private $default = true;
+	private $default_filters = array();
 	
 	private $free_search = '';
 	private $group = 0;
@@ -59,17 +60,25 @@ class Alerts {
 		$system = System::getInstance();
 		$user = User::getInstance();
 		
+		
+		$this->default_filters['standby'] = true;
+		$this->default_filters['group'] = true;
+		$this->default_filters['status'] = true;
+		$this->default_filters['free_search'] = true;
+		
 		$this->free_search = $system->getRequest('free_search', '');
 		if ($this->free_search != '') {
 			$this->default = false;
+			$this->default_filters['free_search'] = false;
 		}
 		
 		$this->status = $system->getRequest('status', __("Status"));
-		if ($this->status === __("Status")) {
+		if (($this->status === __("Status")) || ($this->status == 'all')) {
 			$this->status = 'all';
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['status'] = false;
 		}
 		
 		$this->group = $system->getRequest('group', __("Group"));
@@ -81,14 +90,16 @@ class Alerts {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['group'] = false;
 		}
 		
 		$this->standby = $system->getRequest('standby', __('Stand by'));
-		if ($this->standby === __('Stand by')) {
+		if (($this->standby === __('Stand by')) || ($this->standby == -1)) {
 			$this->standby = -1;
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['standby'] = false;
 		}
 	}
 	
@@ -291,12 +302,35 @@ class Alerts {
 			return __("(Default)");
 		}
 		else {
-			$status_text = $this->alert_status_items[$this->status];
-			$standby_text = $this->alert_standby_items[$this->standby];
-			$group_text = groups_get_name($this->group, true);
+			$filters_to_serialize = array();
 			
-			return sprintf(__('(Status: %s - Standby: %s - Group: %s - Free Search: %s)'),
-				$status_text, $standby_text, $group_text, $this->free_search);
+			if (!$this->default_filters['standby']) {
+				$filters_to_serialize[] = sprintf(__("Standby: %s"),
+					$this->alert_standby_items[$this->standby]);
+			}
+			if (!$this->default_filters['group']) {
+				$filters_to_serialize[] = sprintf(__("Group: %s"),
+					groups_get_name($this->group, true));
+			}
+			if (!$this->default_filters['status']) {
+				$filters_to_serialize[] = sprintf(__("Status: %s"),
+					$this->alert_status_items[$this->status]);
+			}
+			if (!$this->default_filters['free_search']) {
+				$filters_to_serialize[] = sprintf(__("Free Search: %s"),
+					$this->free_search);
+			}
+			
+			$string = '(' . implode(' - ', $filters_to_serialize) . ')';
+			
+			return $string;
+			
+			//~ $status_text = $this->alert_status_items[$this->status];
+			//~ $standby_text = $this->alert_standby_items[$this->standby];
+			//~ $group_text = groups_get_name($this->group, true);
+			
+			//~ return sprintf(__('(Status: %s - Standby: %s - Group: %s - Free Search: %s)'),
+				//~ $status_text, $standby_text, $group_text, $this->free_search);
 		}
 	}
 }
diff --git a/pandora_console/mobile/operation/events.php b/pandora_console/mobile/operation/events.php
index 7ba8bda630..6aa8b132cf 100644
--- a/pandora_console/mobile/operation/events.php
+++ b/pandora_console/mobile/operation/events.php
@@ -17,6 +17,8 @@ class Events {
 	private $acl = "ER";
 	
 	private $default = true;
+	private $default_filters = array();
+	
 	private $free_search = '';
 	private $hours_old = 8;
 	private $status = 3;
@@ -153,13 +155,20 @@ class Events {
 								'</a>';
 						}
 						
+						if ($event['id_agente'] > 0) {
+							$event['agent'] = "<a style='color: black;'" .
+								"href='index.php?page=agent&id=" . 
+								$event['id_agente'] . "'>" .								
+								agents_get_name($event['id_agente']) .
+								"</a>";
+						}
 						
 						$event['evento'] = io_safe_output($event['evento']);
 						
 						$event['clean_tags'] = events_clean_tags($event['tags']);
 						$event["timestamp"] = date($system->getConfig("date_format"), strtotime($event["timestamp"]));
-						if(empty($event["owner_user"])) {
-							$event["owner_user"] = '<i>'.__('N/A').'</i>';
+						if (empty($event["owner_user"])) {
+							$event["owner_user"] = '<i>' . __('N/A') . '</i>';
 						}
 						else {
 							$user_owner = db_get_value('fullname', 'tusuario', 'id_user', $event["owner_user"]);
@@ -175,15 +184,15 @@ class Events {
 							$group_rep = 0;
 						
 						if ($group_rep != 0) {
-							if($event["event_rep"] <= 1) {
-								$event["event_repeated"] = '<i>'.__('No').'</i>';
+							if ($event["event_rep"] <= 1) {
+								$event["event_repeated"] = '<i>' . __('No') . '</i>';
 							}
 							else {
 								$event["event_repeated"] = sprintf("%d Times",$event["event_rep"]);
 							}
 						}
 						else {
-							$event["event_repeated"] = '<i>'.__('No').'</i>';
+							$event["event_repeated"] = '<i>' . __('No') . '</i>';
 						}
 						
 						$event_criticity = get_priority_name ($event["criticity"]);
@@ -231,11 +240,11 @@ class Events {
 								' (' . $date_ack . ')';
 						}
 						else {
-							$event["acknowledged_by"] = '<i>'.__('N/A').'</i>';
+							$event["acknowledged_by"] = '<i>' . __('N/A') . '</i>';
 						}
 						
 						// Get Status
-						switch($event['estado']) {
+						switch ($event['estado']) {
 							case 0:
 								$img_st = "images/star.png";
 								$title_st = __('New event');
@@ -293,14 +302,23 @@ class Events {
 		$system = System::getInstance();
 		$user = User::getInstance();
 		
+		$this->default_filters['severity'] = true;
+		$this->default_filters['group'] = true;
+		$this->default_filters['type'] = true;
+		$this->default_filters['status'] = true;
+		$this->default_filters['free_search'] = true;
+		$this->default_filters['hours_old'] = true;
+		
 		$this->hours_old = $system->getRequest('hours_old', 8);
 		if ($this->hours_old != 8) {
 			$this->default = false;
+			$this->default_filters['hours_old'] = false;
 		}
 		
 		$this->free_search = $system->getRequest('free_search', '');
 		if ($this->free_search != '') {
 			$this->default = false;
+			$this->default_filters['free_search'] = false;
 		}
 		
 		$this->status = $system->getRequest('status', __("Status"));
@@ -310,6 +328,7 @@ class Events {
 		else {
 			$this->status = (int)$this->status;
 			$this->default = false;
+			$this->default_filters['status'] = false;
 		}
 		
 		$this->type = $system->getRequest('type', __("Type"));
@@ -318,6 +337,7 @@ class Events {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['type'] = false;
 		}
 		
 		$this->group = $system->getRequest('group', __("Group"));
@@ -329,6 +349,7 @@ class Events {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['group'] = false;
 		}
 		
 		$this->severity = $system->getRequest('severity', __("Severity"));
@@ -337,6 +358,7 @@ class Events {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['severity'] = false;
 		}
 		
 		$this->filter = $system->getRequest('filter', __('Preset Filters'));
@@ -450,6 +472,10 @@ class Events {
 						<th><?php echo __('Module Graph');?></th>
 						<td class="cell_module_graph"></td>
 					</tr>
+					<tr class="event_agent">
+						<th><?php echo __('Agent');?></th>
+						<td class="cell_agent"></td>
+					</tr>
 					<tr class="event_tags">
 						<th><?php echo __('Tags');?></th>
 						<td class="cell_event_tags"></td>
@@ -1029,21 +1055,38 @@ class Events {
 				return sprintf(__('Filter: %s'), $filter['id_name']);
 			}
 			else {
-				$status = "";
-				if (!empty($this->status))
-					$status = events_get_status($this->status);
-				$type = "";
-				if (!empty($this->type))
-					$type = get_event_types($this->type);
-				$severity = "";
-				if ($this->severity != -1)
-					$severity = get_priorities($this->severity);
+				$filters_to_serialize = array();
+			
+			
+				if (!$this->default_filters['severity']) {
+					$filters_to_serialize[] = sprintf(__("Severity: %s"),
+						get_priorities($this->severity));
+				}
+				if (!$this->default_filters['group']) {
+					$groups = users_get_groups_for_select(
+						$system->getConfig('id_user'), "ER", true, true, false, 'id_grupo');
 				
-				
-				$string = sprintf(
-					__("(Status: %s - Hours: %s - Type: %s - Severity: %s - Free Search: %s)"),
-					$status, $this->hours_old, $type, $severity,
-					$this->free_search);
+					$filters_to_serialize[] = sprintf(__("Group: %s"),
+						$groups[$this->group]);
+				}
+				if (!$this->default_filters['type']) {
+					$filters_to_serialize[] = sprintf(__("Type: %s"),
+						get_event_types($this->type));
+				}
+				if (!$this->default_filters['status']) {
+					$filters_to_serialize[] = sprintf(__("Status: %s"),
+						events_get_status($this->status));
+				}
+				if (!$this->default_filters['free_search']) {
+					$filters_to_serialize[] = sprintf(__("Free search: %s"),
+						$this->free_search);
+				}
+				if (!$this->default_filters['hours_old']) {
+					$filters_to_serialize[] = sprintf(__("Hours: %s"),
+						$this->hours_old);
+				}
+			
+				$string = '(' . implode(' - ', $filters_to_serialize) . ')';
 				
 				return $string;
 			}
diff --git a/pandora_console/mobile/operation/modules.php b/pandora_console/mobile/operation/modules.php
index 666167e433..c1a298066a 100644
--- a/pandora_console/mobile/operation/modules.php
+++ b/pandora_console/mobile/operation/modules.php
@@ -17,6 +17,8 @@ class Modules {
 	private $acl = "AR";
 	
 	private $default = true;
+	private $default_filters = array();
+	
 	private $group = 0;
 	private $status = AGENT_MODULE_STATUS_NOT_NORMAL;
 	private $free_search = '';
@@ -102,9 +104,15 @@ class Modules {
 		$system = System::getInstance();
 		$user = User::getInstance();
 		
+		$this->default_filters['module_group'] = true;
+		$this->default_filters['group'] = true;
+		$this->default_filters['status'] = true;
+		$this->default_filters['free_search'] = true;
+		
 		$this->free_search = $system->getRequest('free_search', '');
 		if ($this->free_search != '') {
 			$this->default = false;
+			$this->default_filters['free_search'] = false;
 		}
 		
 		$this->status = $system->getRequest('status', __("Status"));
@@ -113,6 +121,7 @@ class Modules {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['status'] = false;
 		}
 		
 		$this->group = (int)$system->getRequest('group', __("Group"));
@@ -124,15 +133,18 @@ class Modules {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['group'] = false;
 		}
 		
 		$this->module_group = (int)$system->getRequest('module_group', __("Module group"));
-		if (($this->module_group === __("Module group")) || ($this->module_group == -1)
+		if (($this->module_group === __("Module group")) || ($this->module_group === -1)
 			|| ($this->module_group == 0)) {
 			$this->module_group = -1;
 		}
 		else {
 			$this->default = false;
+			$this->module_group = (int) $this->module_group;
+			$this->default_filters['module_group'] = false;
 		}
 		
 		$this->tag = (int)$system->getRequest('tag', __("Tag"));
@@ -198,6 +210,7 @@ class Modules {
 						);
 					$ui->formAddSelectBox($options);
 					
+					
 					$module_groups = db_get_all_rows_sql("SELECT *
 						FROM tmodule_group
 						ORDER BY name");
@@ -618,18 +631,45 @@ class Modules {
 			return __("(Default)");
 		}
 		else {
-			$status = $this->list_status[$this->status];
 			
-			$group = groups_get_name($this->group, true);
+			$filters_to_serialize = array();
 			
-			$module_group = db_get_value('name',
-				'tmodule_group', 'id_mg', $this->module_group);
-			$module_group = io_safe_output($module_group);
-			$tag = tags_get_name($this->tag);
+			if (!$this->default_filters['group']) {
+				$filters_to_serialize[] = sprintf(__("Group: %s"),
+					groups_get_name($this->group, true));
+			}
+			if (!$this->default_filters['module_group']) {
+				$module_group = db_get_value('name',
+					'tmodule_group', 'id_mg', $this->module_group);
+				$module_group = io_safe_output($module_group);
+				
+				$filters_to_serialize[] = sprintf(__("Module group: %s"),
+					$module_group);
+			}
+			if (!$this->default_filters['status']) {
+				$filters_to_serialize[] = sprintf(__("Status: %s"),
+					$this->list_status[$this->status]);
+			}
+			if (!$this->default_filters['free_search']) {
+				$filters_to_serialize[] = sprintf(__("Free Search: %s"),
+					$this->free_search);
+			}
 			
-			$string = sprintf(
-				__("(Status: %s - Group: %s - Module group: %s - Tag: %s - Free Search: %s)"),
-				$status, $group, $module_group, $tag, $this->free_search);
+			$string = '(' . implode(' - ', $filters_to_serialize) . ')';
+			
+			
+			
+			//~ $status = $this->list_status[$this->status];
+			//~ 
+			//~ $group = groups_get_name($this->group, true);
+			//~ 
+			//~ $module_group = db_get_value('name',
+				//~ 'tmodule_group', 'id_mg', $this->module_group);
+			//~ $module_group = io_safe_output($module_group);
+			//~ 
+			//~ $string = sprintf(
+				//~ __("(Status: %s - Group: %s - Module group: %s - Free Search: %s)"),
+				//~ $status, $group, $module_group, $this->free_search);
 			
 			return $string;
 		}
diff --git a/pandora_console/mobile/operation/networkmaps.php b/pandora_console/mobile/operation/networkmaps.php
index d5d9a6c188..34b911f02c 100755
--- a/pandora_console/mobile/operation/networkmaps.php
+++ b/pandora_console/mobile/operation/networkmaps.php
@@ -21,6 +21,8 @@ class Networkmaps {
 	private $acl = "AR";
 	
 	private $default = true;
+	private $default_filters = array();
+	
 	private $group = 0;
 	private $type = 0;
 	
@@ -57,6 +59,9 @@ class Networkmaps {
 		$system = System::getInstance();
 		$user = User::getInstance();
 		
+		$this->default_filters['group'] = true;
+		$this->default_filters['type'] = true;
+		
 		$this->group = (int)$system->getRequest('group', __("Group"));
 		if (!$user->isInGroup($this->acl, $this->group)) {
 			$this->group = 0;
@@ -66,14 +71,16 @@ class Networkmaps {
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['group'] = false;
 		}
 		
 		$this->type = $system->getRequest('type', __("Type"));
-		if (($this->type === __("Type")) || ($this->type == 0)) {
-			$this->type = 0;
+		if (($this->type === __("Type")) || ($this->type === '0')) {
+			$this->type = '0';
 		}
 		else {
 			$this->default = false;
+			$this->default_filters['type'] = false;
 		}
 	}
 	
@@ -192,15 +199,32 @@ class Networkmaps {
 			return __("(Default)");
 		}
 		else {
-			$networkmap_types = networkmap_get_filter_types();
-			$networkmap_types[0] = __('All');
-			$type = $networkmap_types[$this->type];
-			$group = groups_get_name($this->group, true);
+			$filters_to_serialize = array();
+			
+			if (!$this->default_filters['group']) {
+				$filters_to_serialize[] = sprintf(__("Group: %s"),
+					groups_get_name($this->group, true));
+			}
+			if (!$this->default_filters['type']) {
+				$networkmap_types = networkmap_get_filter_types();
+				$networkmap_types[0] = __('All');
+				
+				$filters_to_serialize[] = sprintf(__("Type: %s"),
+					$networkmap_types[$this->type]);
+			}
+			
+			$string = '(' . implode(' - ', $filters_to_serialize) . ')';
 			
 			
-			$string = sprintf(
-				__("(Type: %s - Group: %s)"),
-				$type, $group);
+			//~ $networkmap_types = networkmap_get_filter_types();
+			//~ $networkmap_types[0] = __('All');
+			//~ $type = $networkmap_types[$this->type];
+			//~ $group = groups_get_name($this->group, true);
+			//~ 
+			//~ 
+			//~ $string = sprintf(
+				//~ __("(Type: %s - Group: %s)"),
+				//~ $type, $group);
 			
 			return $string;
 		}