Passed
Push — master ( 0a83f6...9e9438 )
by Patrick
01:49
created
library/Trapdirector/TrapsProcess/TrapConfig.php 3 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -15,197 +15,197 @@
 block discarded – undo
15 15
 trait TrapConfig
16 16
 {
17 17
 
18
-    /** @return \Trapdirector\Logging   */
19
-    abstract public function getLogging();
20
-    /** @return \Trapdirector\TrapApi   */
21
-    abstract public function getTrapApi();
18
+	/** @return \Trapdirector\Logging   */
19
+	abstract public function getLogging();
20
+	/** @return \Trapdirector\TrapApi   */
21
+	abstract public function getTrapApi();
22 22
 
23
-    // TODO : Get default values from TrapModuleConfig 
24
-    /** @var bool	Use SnmpTrapAddess as source adress */
25
-    public $useSnmpTrapAddess=TRUE;
26
-    /** @var string	Special OID to get IP source address of trap emitter */
27
-    public $snmpTrapAddressOID='.1.3.6.1.6.3.18.1.3';
23
+	// TODO : Get default values from TrapModuleConfig 
24
+	/** @var bool	Use SnmpTrapAddess as source adress */
25
+	public $useSnmpTrapAddess=TRUE;
26
+	/** @var string	Special OID to get IP source address of trap emitter */
27
+	public $snmpTrapAddressOID='.1.3.6.1.6.3.18.1.3';
28 28
     
29
-    /**
30
-     * Get option from array of ini file, send message if empty
31
-     * @param string $option_array Array of ini file
32
-     * @param string $option_category category in ini file
33
-     * @param string $option_name name of option in category
34
-     * @param mixed $option_var variable to fill if found, left untouched if not found
35
-     * @param integer $log_level default 2 (warning)
36
-     * @param string $message warning message if not found
37
-     * @return boolean true if found, or false
38
-     */
39
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
40
-    {
41
-        if (!isset($option_array[$option_category][$option_name]))
42
-        {
43
-            if ($message === null)
44
-            {
45
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
46
-            }
47
-            $this->getLogging()->log($message,$log_level);
48
-            return false;
49
-        }
50
-        else
51
-        {
52
-            $option_var=$option_array[$option_category][$option_name];
53
-            return true;
54
-        }
55
-    }
29
+	/**
30
+	 * Get option from array of ini file, send message if empty
31
+	 * @param string $option_array Array of ini file
32
+	 * @param string $option_category category in ini file
33
+	 * @param string $option_name name of option in category
34
+	 * @param mixed $option_var variable to fill if found, left untouched if not found
35
+	 * @param integer $log_level default 2 (warning)
36
+	 * @param string $message warning message if not found
37
+	 * @return boolean true if found, or false
38
+	 */
39
+	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
40
+	{
41
+		if (!isset($option_array[$option_category][$option_name]))
42
+		{
43
+			if ($message === null)
44
+			{
45
+				$message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
46
+			}
47
+			$this->getLogging()->log($message,$log_level);
48
+			return false;
49
+		}
50
+		else
51
+		{
52
+			$option_var=$option_array[$option_category][$option_name];
53
+			return true;
54
+		}
55
+	}
56 56
 
57
-    /**
58
-     * Get options in database
59
-     */
60
-    protected function getDatabaseOptions()
61
-    {
62
-        // Database options
63
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
64
-        {
65
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
68
-        }
69
-        
70
-        $tmpVal = -1; // Get boolean coded in database as 1/0
71
-        $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
73
-        
74
-        $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75
-        $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
76
-    }
77
-        
78
-    /** Set $variable to value if $element found in database config table
79
-     * @param string $element
80
-     * @param string $variable
81
-     */
82
-    protected function getDBConfigIfSet($element,&$variable)
83
-    {
84
-        $value=$this->getDBConfig($element);
85
-        if ($value != null) $variable=$value;
86
-    }
57
+	/**
58
+	 * Get options in database
59
+	 */
60
+	protected function getDatabaseOptions()
61
+	{
62
+		// Database options
63
+		if ($this->logSetup === false) // Only if logging was no setup in constructor
64
+		{
65
+			$this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
+			$this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67
+			$this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
68
+		}
69
+        
70
+		$tmpVal = -1; // Get boolean coded in database as 1/0
71
+		$this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
+		if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
73
+        
74
+		$this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75
+		$this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
76
+	}
77
+        
78
+	/** Set $variable to value if $element found in database config table
79
+	 * @param string $element
80
+	 * @param string $variable
81
+	 */
82
+	protected function getDBConfigIfSet($element,&$variable)
83
+	{
84
+		$value=$this->getDBConfig($element);
85
+		if ($value != null) $variable=$value;
86
+	}
87 87
     
88
-    /**
89
-     *   Get data from db_config
90
-     *	@param $element string name of param
91
-     *	@return mixed : value (or null)
92
-     */
93
-    protected function getDBConfig($element)  // TODO : put this in DB class
94
-    {
95
-        $db_conn=$this->trapsDB->db_connect_trap();
96
-        $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
97
-        if (($ret_code=$db_conn->query($sql)) === false) {
98
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
99
-            return null;
100
-        }
101
-        $value=$ret_code->fetch();
102
-        if ($value != null && isset($value['value']))
103
-        {
104
-            return $value['value'];
105
-        }
106
-        return null;
107
-    }
88
+	/**
89
+	 *   Get data from db_config
90
+	 *	@param $element string name of param
91
+	 *	@return mixed : value (or null)
92
+	 */
93
+	protected function getDBConfig($element)  // TODO : put this in DB class
94
+	{
95
+		$db_conn=$this->trapsDB->db_connect_trap();
96
+		$sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
97
+		if (($ret_code=$db_conn->query($sql)) === false) {
98
+			$this->logging->log('No result in query : ' . $sql,WARN,'');
99
+			return null;
100
+		}
101
+		$value=$ret_code->fetch();
102
+		if ($value != null && isset($value['value']))
103
+		{
104
+			return $value['value'];
105
+		}
106
+		return null;
107
+	}
108 108
     
109
-    /**
110
-     * Get options from ini file
111
-     * @param array $trap_config : ini file array
112
-     */
113
-    protected function getMainOptions($trapConfig)
114
-    {
115
-        
116
-        $nodeStatus='';
117
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
118
-        if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
119
-        {
120
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
121
-            $this->getTrapApi()->setStatusMaster();
122
-        }
123
-        else 
124
-        {
125
-            if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126
-            {
127
-                // Get options to connect to API
128
-                $IP = $port = $user =  $pass = null;
129
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
130
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
131
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
132
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
133
-                $this->getTrapApi()->setParams($IP, $port, $user, $pass);
134
-                return;
135
-            }
136
-        }
137
-        
138
-        // Snmptranslate binary path
139
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
140
-        
141
-        // mibs path
142
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
143
-        
144
-        // icinga2cmd path
145
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
146
-        
147
-        // table prefix
148
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
149
-        
150
-        // API options
151
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
152
-        {
153
-            $this->apiUse=true;
154
-            // Get API options or throw exception as not configured correctly
155
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
156
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
157
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
158
-        }
159
-    }
109
+	/**
110
+	 * Get options from ini file
111
+	 * @param array $trap_config : ini file array
112
+	 */
113
+	protected function getMainOptions($trapConfig)
114
+	{
115
+        
116
+		$nodeStatus='';
117
+		$this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
118
+		if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
119
+		{
120
+			$this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
121
+			$this->getTrapApi()->setStatusMaster();
122
+		}
123
+		else 
124
+		{
125
+			if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126
+			{
127
+				// Get options to connect to API
128
+				$IP = $port = $user =  $pass = null;
129
+				$this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
130
+				$this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
131
+				$this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
132
+				$this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
133
+				$this->getTrapApi()->setParams($IP, $port, $user, $pass);
134
+				return;
135
+			}
136
+		}
137
+        
138
+		// Snmptranslate binary path
139
+		$this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
140
+        
141
+		// mibs path
142
+		$this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
143
+        
144
+		// icinga2cmd path
145
+		$this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
146
+        
147
+		// table prefix
148
+		$this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
149
+        
150
+		// API options
151
+		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
152
+		{
153
+			$this->apiUse=true;
154
+			// Get API options or throw exception as not configured correctly
155
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
156
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
157
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
158
+		}
159
+	}
160 160
     
161
-    /**
162
-     * Create and setup database class for trap & ido (if no api) db
163
-     * @param array $trap_config : ini file array
164
-     */
165
-    protected function setupDatabase($trapConfig)
166
-    {
167
-        // Trap database
168
-        if (!array_key_exists('database',$trapConfig['config']))
169
-        {
170
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
171
-            return;
172
-        }
173
-        $dbTrapName=$trapConfig['config']['database'];
174
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
175
-        
176
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
177
-        {
178
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
179
-            return;
180
-        }
181
-        if (!array_key_exists($dbTrapName,$dbConfig))
182
-        {
183
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
184
-            return;
185
-        }
186
-        
187
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
188
-        
189
-        $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
190
-        
191
-        //TODO enable this again when API queries are all done :
192
-        //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
193
-        
194
-        // IDO Database
195
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
196
-        {
197
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
198
-        }
199
-        $dbIdoName=$trapConfig['config']['IDOdatabase'];
200
-        
201
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
202
-        if (!array_key_exists($dbIdoName,$dbConfig))
203
-        {
204
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
205
-            return;
206
-        }
207
-        
208
-        $this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
209
-    }
161
+	/**
162
+	 * Create and setup database class for trap & ido (if no api) db
163
+	 * @param array $trap_config : ini file array
164
+	 */
165
+	protected function setupDatabase($trapConfig)
166
+	{
167
+		// Trap database
168
+		if (!array_key_exists('database',$trapConfig['config']))
169
+		{
170
+			$this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
171
+			return;
172
+		}
173
+		$dbTrapName=$trapConfig['config']['database'];
174
+		$this->logging->log("Found database in config file: ".$dbTrapName,INFO );
175
+        
176
+		if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
177
+		{
178
+			$this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
179
+			return;
180
+		}
181
+		if (!array_key_exists($dbTrapName,$dbConfig))
182
+		{
183
+			$this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
184
+			return;
185
+		}
186
+        
187
+		$this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
188
+        
189
+		$this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
190
+        
191
+		//TODO enable this again when API queries are all done :
192
+		//if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
193
+        
194
+		// IDO Database
195
+		if (!array_key_exists('IDOdatabase',$trapConfig['config']))
196
+		{
197
+			$this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
198
+		}
199
+		$dbIdoName=$trapConfig['config']['IDOdatabase'];
200
+        
201
+		$this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
202
+		if (!array_key_exists($dbIdoName,$dbConfig))
203
+		{
204
+			$this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
205
+			return;
206
+		}
207
+        
208
+		$this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
209
+	}
210 210
     
211 211
 }
212 212
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
      * @param string $message warning message if not found
37 37
      * @return boolean true if found, or false
38 38
      */
39
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
39
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null)
40 40
     {
41 41
         if (!isset($option_array[$option_category][$option_name]))
42 42
         {
43 43
             if ($message === null)
44 44
             {
45
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
45
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
46 46
             }
47
-            $this->getLogging()->log($message,$log_level);
47
+            $this->getLogging()->log($message, $log_level);
48 48
             return false;
49 49
         }
50 50
         else
@@ -62,24 +62,24 @@  discard block
 block discarded – undo
62 62
         // Database options
63 63
         if ($this->logSetup === false) // Only if logging was no setup in constructor
64 64
         {
65
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
65
+            $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel);
66
+            $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode);
67
+            $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile);
68 68
         }
69 69
         
70
-        $tmpVal = -1; // Get boolean coded in database as 1/0
70
+        $tmpVal=-1; // Get boolean coded in database as 1/0
71 71
         $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
72
+        if ($tmpVal != -1) $this->useSnmpTrapAddess=($tmpVal == 1) ? TRUE : FALSE;
73 73
         
74 74
         $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75
-        $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
75
+        $this->snmpTrapAddressOID=preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
76 76
     }
77 77
         
78 78
     /** Set $variable to value if $element found in database config table
79 79
      * @param string $element
80 80
      * @param string $variable
81 81
      */
82
-    protected function getDBConfigIfSet($element,&$variable)
82
+    protected function getDBConfigIfSet($element, &$variable)
83 83
     {
84 84
         $value=$this->getDBConfig($element);
85 85
         if ($value != null) $variable=$value;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $db_conn=$this->trapsDB->db_connect_trap();
96 96
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
97 97
         if (($ret_code=$db_conn->query($sql)) === false) {
98
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
98
+            $this->logging->log('No result in query : '.$sql, WARN, '');
99 99
             return null;
100 100
         }
101 101
         $value=$ret_code->fetch();
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
     {
115 115
         
116 116
         $nodeStatus='';
117
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
117
+        $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus);
118 118
         if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
119 119
         {
120
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
120
+            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN);
121 121
             $this->getTrapApi()->setStatusMaster();
122 122
         }
123 123
         else 
@@ -125,36 +125,36 @@  discard block
 block discarded – undo
125 125
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126 126
             {
127 127
                 // Get options to connect to API
128
-                $IP = $port = $user =  $pass = null;
129
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
130
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
131
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
132
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
128
+                $IP=$port=$user=$pass=null;
129
+                $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR);
130
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR);
131
+                $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR);
132
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR);
133 133
                 $this->getTrapApi()->setParams($IP, $port, $user, $pass);
134 134
                 return;
135 135
             }
136 136
         }
137 137
         
138 138
         // Snmptranslate binary path
139
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
139
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
140 140
         
141 141
         // mibs path
142
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
142
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
143 143
         
144 144
         // icinga2cmd path
145
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
145
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
146 146
         
147 147
         // table prefix
148
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
148
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
149 149
         
150 150
         // API options
151
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
151
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
152 152
         {
153 153
             $this->apiUse=true;
154 154
             // Get API options or throw exception as not configured correctly
155
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
156
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
157
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
155
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR);
156
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR);
157
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR);
158 158
         }
159 159
     }
160 160
     
@@ -165,43 +165,43 @@  discard block
 block discarded – undo
165 165
     protected function setupDatabase($trapConfig)
166 166
     {
167 167
         // Trap database
168
-        if (!array_key_exists('database',$trapConfig['config']))
168
+        if (!array_key_exists('database', $trapConfig['config']))
169 169
         {
170
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
170
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
171 171
             return;
172 172
         }
173 173
         $dbTrapName=$trapConfig['config']['database'];
174
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
174
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
175 175
         
176
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
176
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
177 177
         {
178
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
178
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
179 179
             return;
180 180
         }
181
-        if (!array_key_exists($dbTrapName,$dbConfig))
181
+        if (!array_key_exists($dbTrapName, $dbConfig))
182 182
         {
183
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
183
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
184 184
             return;
185 185
         }
186 186
         
187
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
187
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
188 188
         
189
-        $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
189
+        $this->logging->log("API Use : ".print_r($this->apiUse, true), DEBUG);
190 190
         
191 191
         //TODO enable this again when API queries are all done :
192 192
         //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
193 193
         
194 194
         // IDO Database
195
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
195
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
196 196
         {
197
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
197
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
198 198
         }
199 199
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
200 200
         
201
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
202
-        if (!array_key_exists($dbIdoName,$dbConfig))
201
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
202
+        if (!array_key_exists($dbIdoName, $dbConfig))
203 203
         {
204
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
204
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
205 205
             return;
206 206
         }
207 207
         
Please login to merge, or discard this patch.
Braces   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@  discard block
 block discarded – undo
46 46
             }
47 47
             $this->getLogging()->log($message,$log_level);
48 48
             return false;
49
-        }
50
-        else
49
+        } else
51 50
         {
52 51
             $option_var=$option_array[$option_category][$option_name];
53 52
             return true;
@@ -60,16 +59,20 @@  discard block
 block discarded – undo
60 59
     protected function getDatabaseOptions()
61 60
     {
62 61
         // Database options
63
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
62
+        if ($this->logSetup === false) {
63
+        	// Only if logging was no setup in constructor
64 64
         {
65 65
             $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
+        }
66 67
             $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67 68
             $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
68 69
         }
69 70
         
70 71
         $tmpVal = -1; // Get boolean coded in database as 1/0
71 72
         $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
73
+        if ($tmpVal != -1) {
74
+        	$this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
75
+        }
73 76
         
74 77
         $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75 78
         $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
@@ -82,7 +85,9 @@  discard block
 block discarded – undo
82 85
     protected function getDBConfigIfSet($element,&$variable)
83 86
     {
84 87
         $value=$this->getDBConfig($element);
85
-        if ($value != null) $variable=$value;
88
+        if ($value != null) {
89
+        	$variable=$value;
90
+        }
86 91
     }
87 92
     
88 93
     /**
@@ -119,8 +124,7 @@  discard block
 block discarded – undo
119 124
         {
120 125
             $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
121 126
             $this->getTrapApi()->setStatusMaster();
122
-        }
123
-        else 
127
+        } else 
124 128
         {
125 129
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126 130
             {
Please login to merge, or discard this patch.
library/Trapdirector/Tables/HandlerTable.php 3 patches
Braces   +6 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
     {
32 32
         if ($this->groupingColumn == 'rule_type')
33 33
         {
34
-            if ($this->categories == NULL || (! isset($this->categories[$value])))
35
-                return 'Unknown category ('.$value.')';
34
+            if ($this->categories == NULL || (! isset($this->categories[$value]))) {
35
+                            return 'Unknown category ('.$value.')';
36
+            }
36 37
             return 'Category : '. $this->categories[$value];
37 38
         }
38 39
         $html = "$value";
@@ -86,13 +87,11 @@  discard block
 block discarded – undo
86 87
                               if (isset($oidName['name']))
87 88
                               {
88 89
                                   $val=$oidName['name'];
89
-                              }
90
-                              else
90
+                              } else
91 91
                               {
92 92
                                   $val = $row->$rowkey;
93 93
                               }
94
-                          }
95
-                          else
94
+                          } else
96 95
                           {
97 96
                               $val = $row->$rowkey;
98 97
                           }
@@ -101,8 +100,7 @@  discard block
 block discarded – undo
101 100
                           if ($row->$rowkey == null)
102 101
                           {
103 102
                               $val = $row->host_group_name;
104
-                          }
105
-                          else
103
+                          } else
106 104
                           {
107 105
                               $val = $row->$rowkey;
108 106
                           }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -20,22 +20,22 @@  discard block
 block discarded – undo
20 20
     protected $MIB;
21 21
     
22 22
     // categories
23
-    protected $categories = NULL;
23
+    protected $categories=NULL;
24 24
     
25 25
     public function setCategoriesArray(array $categories)
26 26
     {
27
-        $this->categories = $categories;
27
+        $this->categories=$categories;
28 28
     }
29 29
     
30
-    public function groupingPrintData( string $value)
30
+    public function groupingPrintData(string $value)
31 31
     {
32 32
         if ($this->groupingColumn == 'rule_type')
33 33
         {
34
-            if ($this->categories == NULL || (! isset($this->categories[$value])))
34
+            if ($this->categories == NULL || (!isset($this->categories[$value])))
35 35
                 return 'Unknown category ('.$value.')';
36
-            return 'Category : '. $this->categories[$value];
36
+            return 'Category : '.$this->categories[$value];
37 37
         }
38
-        $html = "$value";
38
+        $html="$value";
39 39
         return $html;
40 40
     }
41 41
     
@@ -58,16 +58,16 @@  discard block
 block discarded – undo
58 58
     
59 59
     public function getCurrentURL()
60 60
     {
61
-        return Url::fromPath($this->urlPath . '/handler');
61
+        return Url::fromPath($this->urlPath.'/handler');
62 62
     }
63 63
     
64 64
     public function renderLine($row)
65 65
       {
66
-          $html = '';
67
-          $firstCol = true;
66
+          $html='';
67
+          $firstCol=true;
68 68
                
69
-          $titleNames = array_keys($this->titles);
70
-          foreach ($titleNames as $rowkey )
69
+          $titleNames=array_keys($this->titles);
70
+          foreach ($titleNames as $rowkey)
71 71
           {        
72 72
               // Check missing value
73 73
               if (property_exists($row, $rowkey))
@@ -82,57 +82,57 @@  discard block
 block discarded – undo
82 82
                           
83 83
                           if ($this->doTranslate === true)
84 84
                           {
85
-                              $oidName = $this->MIB->translateOID($row->$rowkey);
85
+                              $oidName=$this->MIB->translateOID($row->$rowkey);
86 86
                               if (isset($oidName['name']))
87 87
                               {
88 88
                                   $val=$oidName['name'];
89 89
                               }
90 90
                               else
91 91
                               {
92
-                                  $val = $row->$rowkey;
92
+                                  $val=$row->$rowkey;
93 93
                               }
94 94
                           }
95 95
                           else
96 96
                           {
97
-                              $val = $row->$rowkey;
97
+                              $val=$row->$rowkey;
98 98
                           }
99 99
                           break;
100 100
                       case 'host_name': // switch to hostgroup if name is null
101 101
                           if ($row->$rowkey == null)
102 102
                           {
103
-                              $val = $row->host_group_name;
103
+                              $val=$row->host_group_name;
104 104
                           }
105 105
                           else
106 106
                           {
107
-                              $val = $row->$rowkey;
107
+                              $val=$row->$rowkey;
108 108
                           }
109 109
                           break;
110 110
                       default:
111
-                          $val = $row->$rowkey;
111
+                          $val=$row->$rowkey;
112 112
                   }
113
-                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
113
+                  if ($rowkey == 'trap_oid' && $this->doTranslate === true)
114 114
                   {
115 115
                       
116 116
                   }
117 117
               } else {
118
-                  $val = '-';
118
+                  $val='-';
119 119
               }
120 120
               if ($firstCol === true) { // Put link in first column for trap detail.
121
-                  $html .= '<td class="traphover">'
121
+                  $html.='<td class="traphover">'
122 122
                       . $this->view->qlink(
123 123
                           $this->view->escape($val),
124 124
                           Url::fromPath(
125
-                              $this->urlPath . '/handler/add',
125
+                              $this->urlPath.'/handler/add',
126 126
                               array('ruleid' => $row->id)
127 127
                               )
128 128
                           );
129 129
                   if ($row->comment != '')
130 130
                   {
131
-                      $html.= '<span class="tohover">'. $row->comment .'</span></td>';
131
+                      $html.='<span class="tohover">'.$row->comment.'</span></td>';
132 132
                   }
133
-                  $html.= '</td>';
133
+                  $html.='</td>';
134 134
               } else {
135
-                  $html .= '<td>' . $this->view->escape($val) . '</td>';
135
+                  $html.='<td>'.$this->view->escape($val).'</td>';
136 136
               }
137 137
               $firstCol=false;
138 138
               
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -7,136 +7,136 @@
 block discarded – undo
7 7
 class HandlerTable extends TrapDirectorTable
8 8
 {
9 9
 
10
-    protected $status_display=array(
11
-        -2	=>'ignore',
12
-        -1 => '-',
13
-        0	=> 'OK',
14
-        1	=> 'warning',
15
-        2	=> 'critical',
16
-        3	=> 'unknown',);
10
+	protected $status_display=array(
11
+		-2	=>'ignore',
12
+		-1 => '-',
13
+		0	=> 'OK',
14
+		1	=> 'warning',
15
+		2	=> 'critical',
16
+		3	=> 'unknown',);
17 17
     
18
-    // translate
19
-    protected $doTranslate=false;
20
-    protected $MIB;
18
+	// translate
19
+	protected $doTranslate=false;
20
+	protected $MIB;
21 21
     
22
-    // categories
23
-    protected $categories = NULL;
22
+	// categories
23
+	protected $categories = NULL;
24 24
     
25
-    public function setCategoriesArray(array $categories)
26
-    {
27
-        $this->categories = $categories;
28
-    }
25
+	public function setCategoriesArray(array $categories)
26
+	{
27
+		$this->categories = $categories;
28
+	}
29 29
     
30
-    public function groupingPrintData( string $value)
31
-    {
32
-        if ($this->groupingColumn == 'rule_type')
33
-        {
34
-            if ($this->categories == NULL || (! isset($this->categories[$value])))
35
-                return 'Unknown category ('.$value.')';
36
-            return 'Category : '. $this->categories[$value];
37
-        }
38
-        $html = "$value";
39
-        return $html;
40
-    }
30
+	public function groupingPrintData( string $value)
31
+	{
32
+		if ($this->groupingColumn == 'rule_type')
33
+		{
34
+			if ($this->categories == NULL || (! isset($this->categories[$value])))
35
+				return 'Unknown category ('.$value.')';
36
+			return 'Category : '. $this->categories[$value];
37
+		}
38
+		$html = "$value";
39
+		return $html;
40
+	}
41 41
     
42
-    public function setMibloader($mibloader)
43
-    {
44
-        $this->MIB=$mibloader;
45
-        $this->doTranslate=true;
46
-    }
42
+	public function setMibloader($mibloader)
43
+	{
44
+		$this->MIB=$mibloader;
45
+		$this->doTranslate=true;
46
+	}
47 47
 
48
-    public function titleOrder($name)
49
-    {
50
-        switch ($name)
51
-        {
52
-            case 'host_name' : return $this->content[$name]; break;
53
-            case 'source_ip' : return 'ip4'; break;
54
-            default: return $this->content[$name];	
55
-        }
56
-    }
48
+	public function titleOrder($name)
49
+	{
50
+		switch ($name)
51
+		{
52
+			case 'host_name' : return $this->content[$name]; break;
53
+			case 'source_ip' : return 'ip4'; break;
54
+			default: return $this->content[$name];	
55
+		}
56
+	}
57 57
     
58
-    public function getCurrentURL()
59
-    {
60
-        return Url::fromPath($this->urlPath . '/handler');
61
-    }
58
+	public function getCurrentURL()
59
+	{
60
+		return Url::fromPath($this->urlPath . '/handler');
61
+	}
62 62
     
63
-    public function renderLine($row)
64
-      {
65
-          $html = '';
66
-          $firstCol = true;
63
+	public function renderLine($row)
64
+	  {
65
+		  $html = '';
66
+		  $firstCol = true;
67 67
                
68
-          $titleNames = array_keys($this->titles);
69
-          foreach ($titleNames as $rowkey )
70
-          {        
71
-              // Check missing value
72
-              if (property_exists($row, $rowkey))
73
-              {
74
-                  switch ($rowkey)
75
-                  {
76
-                      case 'action_match': // display text levels
77
-                      case 'action_nomatch':
78
-                          $val=$this->status_display[$row->$rowkey];
79
-                          break;
80
-                      case 'trap_oid': // try to traslate oids.
68
+		  $titleNames = array_keys($this->titles);
69
+		  foreach ($titleNames as $rowkey )
70
+		  {        
71
+			  // Check missing value
72
+			  if (property_exists($row, $rowkey))
73
+			  {
74
+				  switch ($rowkey)
75
+				  {
76
+					  case 'action_match': // display text levels
77
+					  case 'action_nomatch':
78
+						  $val=$this->status_display[$row->$rowkey];
79
+						  break;
80
+					  case 'trap_oid': // try to traslate oids.
81 81
                           
82
-                          if ($this->doTranslate === true)
83
-                          {
84
-                              $oidName = $this->MIB->translateOID($row->$rowkey);
85
-                              if (isset($oidName['name']))
86
-                              {
87
-                                  $val=$oidName['name'];
88
-                              }
89
-                              else
90
-                              {
91
-                                  $val = $row->$rowkey;
92
-                              }
93
-                          }
94
-                          else
95
-                          {
96
-                              $val = $row->$rowkey;
97
-                          }
98
-                          break;
99
-                      case 'host_name': // switch to hostgroup if name is null
100
-                          if ($row->$rowkey == null)
101
-                          {
102
-                              $val = $row->host_group_name;
103
-                          }
104
-                          else
105
-                          {
106
-                              $val = $row->$rowkey;
107
-                          }
108
-                          break;
109
-                      default:
110
-                          $val = $row->$rowkey;
111
-                  }
112
-                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
113
-                  {
82
+						  if ($this->doTranslate === true)
83
+						  {
84
+							  $oidName = $this->MIB->translateOID($row->$rowkey);
85
+							  if (isset($oidName['name']))
86
+							  {
87
+								  $val=$oidName['name'];
88
+							  }
89
+							  else
90
+							  {
91
+								  $val = $row->$rowkey;
92
+							  }
93
+						  }
94
+						  else
95
+						  {
96
+							  $val = $row->$rowkey;
97
+						  }
98
+						  break;
99
+					  case 'host_name': // switch to hostgroup if name is null
100
+						  if ($row->$rowkey == null)
101
+						  {
102
+							  $val = $row->host_group_name;
103
+						  }
104
+						  else
105
+						  {
106
+							  $val = $row->$rowkey;
107
+						  }
108
+						  break;
109
+					  default:
110
+						  $val = $row->$rowkey;
111
+				  }
112
+				  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
113
+				  {
114 114
                       
115
-                  }
116
-              } else {
117
-                  $val = '-';
118
-              }
119
-              if ($firstCol === true) { // Put link in first column for trap detail.
120
-                  $html .= '<td class="traphover">'
121
-                      . $this->view->qlink(
122
-                          $this->view->escape($val),
123
-                          Url::fromPath(
124
-                              $this->urlPath . '/handler/add',
125
-                              array('ruleid' => $row->id)
126
-                              )
127
-                          );
128
-                  if ($row->comment != '')
129
-                  {
130
-                      $html.= '<span class="tohover">'. $row->comment .'</span></td>';
131
-                  }
132
-                  $html.= '</td>';
133
-              } else {
134
-                  $html .= '<td>' . $this->view->escape($val) . '</td>';
135
-              }
136
-              $firstCol=false;
115
+				  }
116
+			  } else {
117
+				  $val = '-';
118
+			  }
119
+			  if ($firstCol === true) { // Put link in first column for trap detail.
120
+				  $html .= '<td class="traphover">'
121
+					  . $this->view->qlink(
122
+						  $this->view->escape($val),
123
+						  Url::fromPath(
124
+							  $this->urlPath . '/handler/add',
125
+							  array('ruleid' => $row->id)
126
+							  )
127
+						  );
128
+				  if ($row->comment != '')
129
+				  {
130
+					  $html.= '<span class="tohover">'. $row->comment .'</span></td>';
131
+				  }
132
+				  $html.= '</td>';
133
+			  } else {
134
+				  $html .= '<td>' . $this->view->escape($val) . '</td>';
135
+			  }
136
+			  $firstCol=false;
137 137
               
138
-          }
139
-          return $html;
140
-      }
138
+		  }
139
+		  return $html;
140
+	  }
141 141
 
142 142
 }
143 143
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 3 patches
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -209,7 +209,9 @@  discard block
 block discarded – undo
209 209
 		if ($this->MIBData == null)
210 210
 		{
211 211
 		    $dbConn = $this->getUIDatabase()->getDbConn();
212
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
212
+		    if ($dbConn === null) {
213
+		    	throw new \ErrorException('uncatched db error');
214
+		    }
213 215
 			$this->MIBData=new MIBLoader(
214 216
 				$this->Config()->get('config', 'snmptranslate'),
215 217
 				$this->Config()->get('config', 'snmptranslate_dirs'),
@@ -279,7 +281,9 @@  discard block
 block discarded – undo
279 281
 	    $catString='';
280 282
 	    foreach ($catArray as $index => $value)
281 283
 	    {
282
-	        if ($catString != '' ) $catString .= '!';
284
+	        if ($catString != '' ) {
285
+	        	$catString .= '!';
286
+	        }
283 287
 	        $catString .= $index . ':' . $value;
284 288
 	    }
285 289
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
@@ -289,8 +293,12 @@  discard block
 block discarded – undo
289 293
 	{
290 294
 	    $catArray = $this->getHandlersCategory();
291 295
 	    $i=1;
292
-	    while (isset($catArray[$i]) && $i < 100) $i++;
293
-	    if ($i == 100) throw new ProgrammingError('Category array error');
296
+	    while (isset($catArray[$i]) && $i < 100) {
297
+	    	$i++;
298
+	    }
299
+	    if ($i == 100) {
300
+	    	throw new ProgrammingError('Category array error');
301
+	    }
294 302
 	    $catArray[$i] = $catName;
295 303
 	    $this->setHandlerCategory($catArray);
296 304
 	}
Please login to merge, or discard this patch.
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	
47 47
 	
48 48
 	/** Get instance of TrapModuleConfig class
49
-	*	@return TrapModuleConfig
50
-	*/
49
+	 *	@return TrapModuleConfig
50
+	 */
51 51
 	public function getModuleConfig() 
52 52
 	{
53 53
 		if ($this->moduleConfig == Null) 
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function getTrapHostListTable()
81 81
 	{
82
-	    if ($this->trapTableHostList == Null) 
82
+		if ($this->trapTableHostList == Null) 
83 83
 		{
84
-	        $this->trapTableHostList = new TrapTableHostList();
85
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
86
-	    }
87
-	    return $this->trapTableHostList;
84
+			$this->trapTableHostList = new TrapTableHostList();
85
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
86
+		}
87
+		return $this->trapTableHostList;
88 88
 	}
89 89
 	
90 90
 	/**
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function getUIDatabase()
107 107
 	{
108
-	    if ($this->UIDatabase == Null)
109
-	    {
110
-	        $this->UIDatabase = new UIDatabase($this);
108
+		if ($this->UIDatabase == Null)
109
+		{
110
+			$this->UIDatabase = new UIDatabase($this);
111 111
 	       
112
-	    }
113
-	    return $this->UIDatabase;
112
+		}
113
+		return $this->UIDatabase;
114 114
 	}
115 115
 
116 116
 	/**
@@ -119,34 +119,34 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function getIdoConn()
121 121
 	{
122
-	    if ($this->icingaAPI === NULL)
123
-	    {
124
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
125
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
126
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
127
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
128
-    	    $this->icingaAPI = new Icinga2API($host,$port);
129
-    	    $this->icingaAPI->setCredentials($user, $pass);
130
-    	    list($ret,$message) = $this->icingaAPI->test(array());
131
-    	    if ($ret === TRUE)
132
-    	    {
133
-    	        return $this->getUIDatabase();
134
-    	    }
122
+		if ($this->icingaAPI === NULL)
123
+		{
124
+			$host = $this->Config()->get('config', 'icingaAPI_host');
125
+			$port = $this->Config()->get('config', 'icingaAPI_port');
126
+			$user = $this->Config()->get('config', 'icingaAPI_user');
127
+			$pass = $this->Config()->get('config', 'icingaAPI_password');
128
+			$this->icingaAPI = new Icinga2API($host,$port);
129
+			$this->icingaAPI->setCredentials($user, $pass);
130
+			list($ret,$message) = $this->icingaAPI->test(array());
131
+			if ($ret === TRUE)
132
+			{
133
+				return $this->getUIDatabase();
134
+			}
135 135
     	    
136
-	    }
137
-	    return $this->icingaAPI;
136
+		}
137
+		return $this->icingaAPI;
138 138
 	    
139 139
 	}
140 140
 	
141
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
142
-    {
143
-        $limit = $this->params->get('limit', $limit);
144
-        $page = $this->params->get('page', $offset);
141
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
142
+	{
143
+		$limit = $this->params->get('limit', $limit);
144
+		$page = $this->params->get('page', $offset);
145 145
 
146
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
146
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
147 147
 
148
-        return $paginatable;
149
-    }	
148
+		return $paginatable;
149
+	}	
150 150
 	
151 151
 	public function displayExitError($source,$message)
152 152
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -155,33 +155,33 @@  discard block
 block discarded – undo
155 155
 	
156 156
 	protected function checkReadPermission()
157 157
 	{
158
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
159
-            $this->displayExitError('Permissions','No permission fo view content');
160
-        }		
158
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
159
+			$this->displayExitError('Permissions','No permission fo view content');
160
+		}		
161 161
 	}
162 162
 
163 163
 	protected function checkConfigPermission()
164 164
 	{
165
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
166
-            $this->displayExitError('Permissions','No permission fo configure');
167
-        }		
165
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
166
+			$this->displayExitError('Permissions','No permission fo configure');
167
+		}		
168 168
 	}
169 169
 	
170
-    /**
171
-     * Check if user has write permission
172
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
173
-     * @return boolean : user has permission
174
-     */
170
+	/**
171
+	 * Check if user has write permission
172
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
173
+	 * @return boolean : user has permission
174
+	 */
175 175
 	protected function checkModuleConfigPermission($check=0)
176 176
 	{
177
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
178
-            if ($check == 0)
179
-            {
180
-                $this->displayExitError('Permissions','No permission fo configure module');
181
-            }
182
-            return false;
183
-        }
184
-        return true;
177
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
178
+			if ($check == 0)
179
+			{
180
+				$this->displayExitError('Permissions','No permission fo configure module');
181
+			}
182
+			return false;
183
+		}
184
+		return true;
185 185
 	}
186 186
 
187 187
 	/*************************  Trap class get **********************/
@@ -201,18 +201,18 @@  discard block
 block discarded – undo
201 201
 	/************************** MIB related **************************/
202 202
 	
203 203
 	/** Get MIBLoader class
204
-	*	@return MIBLoader class
205
-	*/
204
+	 *	@return MIBLoader class
205
+	 */
206 206
 	protected function getMIB()
207 207
 	{
208 208
 		if ($this->MIBData == null)
209 209
 		{
210
-		    $dbConn = $this->getUIDatabase()->getDbConn();
211
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
210
+			$dbConn = $this->getUIDatabase()->getDbConn();
211
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
212 212
 			$this->MIBData=new MIBLoader(
213 213
 				$this->Config()->get('config', 'snmptranslate'),
214 214
 				$this->Config()->get('config', 'snmptranslate_dirs'),
215
-			    $dbConn,
215
+				$dbConn,
216 216
 				$this->getModuleConfig()
217 217
 			);
218 218
 		}
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
 	/**************************  Database queries *******************/		
223 223
 	
224 224
 	/** Check if director is installed
225
-	*	@return bool true/false
226
-	*/
225
+	 *	@return bool true/false
226
+	 */
227 227
 	protected function isDirectorInstalled()
228 228
 	{
229
-	    $output=array();
230
-	    exec('icingacli module list',$output);
231
-	    foreach ($output as $line)
229
+		$output=array();
230
+		exec('icingacli module list',$output);
231
+		foreach ($output as $line)
232 232
 		{
233 233
 			if (preg_match('/^director .*enabled/',$line))
234 234
 			{
@@ -241,72 +241,72 @@  discard block
 block discarded – undo
241 241
 
242 242
 	/************************ UI elements **************************/
243 243
 	
244
-    /**
245
-     * get max rows to display before paging.
246
-     * @return number
247
-     */
244
+	/**
245
+	 * get max rows to display before paging.
246
+	 * @return number
247
+	 */
248 248
 	public function itemListDisplay()
249 249
 	{
250
-	    return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
250
+		return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
251 251
 	}
252 252
 
253 253
 	public function setitemListDisplay(int $maxRows)
254 254
 	{
255
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
255
+		return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
256 256
 	}
257 257
 	
258
-    /**
259
-     * get Handlers categories list (index => textvalue).
260
-     * @return array
261
-     */	
258
+	/**
259
+	 * get Handlers categories list (index => textvalue).
260
+	 * @return array
261
+	 */	
262 262
 	public function getHandlersCategory()
263 263
 	{
264
-	    //<index>:<name>!<index>:<name>
265
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
266
-	    $catListArray=explode('!',$catList);
267
-	    $retArray=array();
268
-	    foreach ($catListArray as $category)
269
-	    {
270
-	        $catArray=explode(':',$category);
271
-	        $retArray[$catArray[0]] = $catArray[1];
272
-	    }
273
-	    return $retArray; 
264
+		//<index>:<name>!<index>:<name>
265
+		$catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
266
+		$catListArray=explode('!',$catList);
267
+		$retArray=array();
268
+		foreach ($catListArray as $category)
269
+		{
270
+			$catArray=explode(':',$category);
271
+			$retArray[$catArray[0]] = $catArray[1];
272
+		}
273
+		return $retArray; 
274 274
 	}
275 275
 
276 276
 	public function setHandlerCategory(array $catArray)
277 277
 	{
278
-	    $catString='';
279
-	    foreach ($catArray as $index => $value)
280
-	    {
281
-	        if ($catString != '' ) $catString .= '!';
282
-	        $catString .= $index . ':' . $value;
283
-	    }
284
-	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
278
+		$catString='';
279
+		foreach ($catArray as $index => $value)
280
+		{
281
+			if ($catString != '' ) $catString .= '!';
282
+			$catString .= $index . ':' . $value;
283
+		}
284
+		$this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
285 285
 	}
286 286
 	
287 287
 	public function addHandlersCategory(string $catName)
288 288
 	{
289
-	    $catArray = $this->getHandlersCategory();
290
-	    $i=1;
291
-	    while (isset($catArray[$i]) && $i < 100) $i++;
292
-	    if ($i == 100) throw new ProgrammingError('Category array error');
293
-	    $catArray[$i] = $catName;
294
-	    $this->setHandlerCategory($catArray);
289
+		$catArray = $this->getHandlersCategory();
290
+		$i=1;
291
+		while (isset($catArray[$i]) && $i < 100) $i++;
292
+		if ($i == 100) throw new ProgrammingError('Category array error');
293
+		$catArray[$i] = $catName;
294
+		$this->setHandlerCategory($catArray);
295 295
 	}
296 296
 	
297 297
 	public function delHandlersCategory(int $catIndex)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
300
-	    unset($catArray[$catIndex]);
301
-	    $this->setHandlerCategory($catArray);
302
-	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
299
+		$catArray = $this->getHandlersCategory();
300
+		unset($catArray[$catIndex]);
301
+		$this->setHandlerCategory($catArray);
302
+		$this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
303 303
 	}
304 304
 	
305 305
 	public function renameHandlersCategory(int $catIndex, string $catName)
306 306
 	{
307
-	    $catArray = $this->getHandlersCategory();
308
-	    $catArray[$catIndex] = $catName;
309
-	    $this->setHandlerCategory($catArray);
307
+		$catArray = $this->getHandlersCategory();
308
+		$catArray[$catIndex] = $catName;
309
+		$this->setHandlerCategory($catArray);
310 310
 	}
311 311
 	
312 312
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	/** @var UIDatabase $UIDatabase */
42 42
 	protected $UIDatabase;
43 43
 	/** @var Icinga2API $IcingaAPI */
44
-	protected $icingaAPI = NULL;
44
+	protected $icingaAPI=NULL;
45 45
 	
46 46
 	
47 47
 	
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 			{
58 58
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
59 59
 			}
60
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
60
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
61 61
 		}
62 62
 		return $this->moduleConfig;
63 63
 	}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function getTrapListTable() {
70 70
 		if ($this->trapTableList == Null) {
71
-			$this->trapTableList = new TrapTableList();
71
+			$this->trapTableList=new TrapTableList();
72 72
 			$this->trapTableList->setConfig($this->getModuleConfig());
73 73
 		}
74 74
 		return $this->trapTableList;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	{
82 82
 	    if ($this->trapTableHostList == Null) 
83 83
 		{
84
-	        $this->trapTableHostList = new TrapTableHostList();
84
+	        $this->trapTableHostList=new TrapTableHostList();
85 85
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
86 86
 	    }
87 87
 	    return $this->trapTableHostList;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	{
95 95
 		if ($this->handlerTableList == Null) 
96 96
 		{
97
-			$this->handlerTableList = new HandlerTableList();
97
+			$this->handlerTableList=new HandlerTableList();
98 98
 			$this->handlerTableList->setConfig($this->getModuleConfig());
99 99
 		}
100 100
 		return $this->handlerTableList;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 	    if ($this->UIDatabase == Null)
109 109
 	    {
110
-	        $this->UIDatabase = new UIDatabase($this);
110
+	        $this->UIDatabase=new UIDatabase($this);
111 111
 	       
112 112
 	    }
113 113
 	    return $this->UIDatabase;
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 	    if ($this->icingaAPI === NULL)
123 123
 	    {
124
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
125
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
126
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
127
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
128
-    	    $this->icingaAPI = new Icinga2API($host,$port);
124
+    	    $host=$this->Config()->get('config', 'icingaAPI_host');
125
+    	    $port=$this->Config()->get('config', 'icingaAPI_port');
126
+    	    $user=$this->Config()->get('config', 'icingaAPI_user');
127
+    	    $pass=$this->Config()->get('config', 'icingaAPI_password');
128
+    	    $this->icingaAPI=new Icinga2API($host, $port);
129 129
     	    $this->icingaAPI->setCredentials($user, $pass);
130
-    	    list($ret,$message) = $this->icingaAPI->test(array());
130
+    	    list($ret, $message)=$this->icingaAPI->test(array());
131 131
     	    if ($ret === TRUE)
132 132
     	    {
133 133
     	        return $this->getUIDatabase();
@@ -138,32 +138,32 @@  discard block
 block discarded – undo
138 138
 	    
139 139
 	}
140 140
 	
141
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
141
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
142 142
     {
143
-        $limit = $this->params->get('limit', $limit);
144
-        $page = $this->params->get('page', $offset);
143
+        $limit=$this->params->get('limit', $limit);
144
+        $page=$this->params->get('page', $offset);
145 145
 
146 146
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
147 147
 
148 148
         return $paginatable;
149 149
     }	
150 150
 	
151
-	public function displayExitError($source,$message)
151
+	public function displayExitError($source, $message)
152 152
 	{	// TODO : check better ways to transmit data (with POST ?)
153 153
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
154 154
 	}
155 155
 	
156 156
 	protected function checkReadPermission()
157 157
 	{
158
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
159
-            $this->displayExitError('Permissions','No permission fo view content');
158
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
159
+            $this->displayExitError('Permissions', 'No permission fo view content');
160 160
         }		
161 161
 	}
162 162
 
163 163
 	protected function checkConfigPermission()
164 164
 	{
165
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
166
-            $this->displayExitError('Permissions','No permission fo configure');
165
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
166
+            $this->displayExitError('Permissions', 'No permission fo configure');
167 167
         }		
168 168
 	}
169 169
 	
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
      */
175 175
 	protected function checkModuleConfigPermission($check=0)
176 176
 	{
177
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
177
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
178 178
             if ($check == 0)
179 179
             {
180
-                $this->displayExitError('Permissions','No permission fo configure module');
180
+                $this->displayExitError('Permissions', 'No permission fo configure module');
181 181
             }
182 182
             return false;
183 183
         }
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	{ // TODO : try/catch here ? or within caller
190 190
 		if ($this->trapClass == null)
191 191
 		{
192
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
192
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
193 193
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
194 194
 			//$debug_level=4;
195
-			$this->trapClass = new Trap($icingaweb2_etc);
195
+			$this->trapClass=new Trap($icingaweb2_etc);
196 196
 			//$Trap->setLogging($debug_level,'syslog');
197 197
 		}
198 198
 		return $this->trapClass;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	{
208 208
 		if ($this->MIBData == null)
209 209
 		{
210
-		    $dbConn = $this->getUIDatabase()->getDbConn();
210
+		    $dbConn=$this->getUIDatabase()->getDbConn();
211 211
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
212 212
 			$this->MIBData=new MIBLoader(
213 213
 				$this->Config()->get('config', 'snmptranslate'),
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	protected function isDirectorInstalled()
228 228
 	{
229 229
 	    $output=array();
230
-	    exec('icingacli module list',$output);
230
+	    exec('icingacli module list', $output);
231 231
 	    foreach ($output as $line)
232 232
 		{
233
-			if (preg_match('/^director .*enabled/',$line))
233
+			if (preg_match('/^director .*enabled/', $line))
234 234
 			{
235 235
 				return true;
236 236
 			}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 	public function setitemListDisplay(int $maxRows)
254 254
 	{
255
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
255
+	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows);
256 256
 	}
257 257
 	
258 258
     /**
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	public function getHandlersCategory()
263 263
 	{
264 264
 	    //<index>:<name>!<index>:<name>
265
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
266
-	    $catListArray=explode('!',$catList);
265
+	    $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories');
266
+	    $catListArray=explode('!', $catList);
267 267
 	    $retArray=array();
268 268
 	    foreach ($catListArray as $category)
269 269
 	    {
270
-	        $catArray=explode(':',$category);
271
-	        $retArray[$catArray[0]] = $catArray[1];
270
+	        $catArray=explode(':', $category);
271
+	        $retArray[$catArray[0]]=$catArray[1];
272 272
 	    }
273 273
 	    return $retArray; 
274 274
 	}
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
 	    $catString='';
279 279
 	    foreach ($catArray as $index => $value)
280 280
 	    {
281
-	        if ($catString != '' ) $catString .= '!';
282
-	        $catString .= $index . ':' . $value;
281
+	        if ($catString != '') $catString.='!';
282
+	        $catString.=$index.':'.$value;
283 283
 	    }
284 284
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
285 285
 	}
286 286
 	
287 287
 	public function addHandlersCategory(string $catName)
288 288
 	{
289
-	    $catArray = $this->getHandlersCategory();
289
+	    $catArray=$this->getHandlersCategory();
290 290
 	    $i=1;
291 291
 	    while (isset($catArray[$i]) && $i < 100) $i++;
292 292
 	    if ($i == 100) throw new ProgrammingError('Category array error');
293
-	    $catArray[$i] = $catName;
293
+	    $catArray[$i]=$catName;
294 294
 	    $this->setHandlerCategory($catArray);
295 295
 	}
296 296
 	
297 297
 	public function delHandlersCategory(int $catIndex)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
299
+	    $catArray=$this->getHandlersCategory();
300 300
 	    unset($catArray[$catIndex]);
301 301
 	    $this->setHandlerCategory($catArray);
302 302
 	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	
305 305
 	public function renameHandlersCategory(int $catIndex, string $catName)
306 306
 	{
307
-	    $catArray = $this->getHandlersCategory();
308
-	    $catArray[$catIndex] = $catName;
307
+	    $catArray=$this->getHandlersCategory();
308
+	    $catArray[$catIndex]=$catName;
309 309
 	    $this->setHandlerCategory($catArray);
310 310
 	}
311 311
 	
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/TrapDBQuery.php 3 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -20,245 +20,245 @@
 block discarded – undo
20 20
 trait TrapDBQuery
21 21
 {
22 22
     
23
-    /** @return TrapsController */
24
-    abstract protected function getTrapCtrl();
23
+	/** @return TrapsController */
24
+	abstract protected function getTrapCtrl();
25 25
 
26
-    /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */
27
-    abstract public function getDbConn();
26
+	/** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */
27
+	abstract public function getDbConn();
28 28
     
29
-    /** Add handler rule in traps DB
30
-     *	@param array $params : array(<db item>=><value>)
31
-     *	@return int inserted id
32
-     */
33
-    public function addHandlerRule($params)
34
-    {
35
-        // TODO Check for rule consistency
29
+	/** Add handler rule in traps DB
30
+	 *	@param array $params : array(<db item>=><value>)
31
+	 *	@return int inserted id
32
+	 */
33
+	public function addHandlerRule($params)
34
+	{
35
+		// TODO Check for rule consistency
36 36
         
37
-        $dbConn = $this->getDbConn();
38
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
39
-        // Add last modified date = creation date and username
40
-        $params['created'] = new Zend_Db_Expr('NOW()');
41
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
42
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
37
+		$dbConn = $this->getDbConn();
38
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
39
+		// Add last modified date = creation date and username
40
+		$params['created'] = new Zend_Db_Expr('NOW()');
41
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
42
+		$params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
43 43
         
44
-        $query=$dbConn->insert(
45
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46
-            $params
47
-            );
48
-        if($query==false)
49
-        {
50
-            return null;
51
-        }
52
-        return $dbConn->lastInsertId();
53
-    }
44
+		$query=$dbConn->insert(
45
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46
+			$params
47
+			);
48
+		if($query==false)
49
+		{
50
+			return null;
51
+		}
52
+		return $dbConn->lastInsertId();
53
+	}
54 54
     
55
-    /** Update handler rule in traps DB
56
-     *	@param array $params : (<db item>=><value>)
57
-     *   @param integer $ruleID : rule id in db
58
-     *	@return array affected rows
59
-     */
60
-    public function updateHandlerRule($params,$ruleID)
61
-    {
62
-        // TODO Check for rule consistency
63
-        $dbConn = $this->getDbConn();
64
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
65
-        // Add last modified date = creation date and username
66
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
67
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
55
+	/** Update handler rule in traps DB
56
+	 *	@param array $params : (<db item>=><value>)
57
+	 *   @param integer $ruleID : rule id in db
58
+	 *	@return array affected rows
59
+	 */
60
+	public function updateHandlerRule($params,$ruleID)
61
+	{
62
+		// TODO Check for rule consistency
63
+		$dbConn = $this->getDbConn();
64
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
65
+		// Add last modified date = creation date and username
66
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
67
+		$params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
68 68
         
69
-        $numRows=$dbConn->update(
70
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
71
-            $params,
72
-            'id='.$ruleID
73
-            );
74
-        return $numRows;
75
-    }
69
+		$numRows=$dbConn->update(
70
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
71
+			$params,
72
+			'id='.$ruleID
73
+			);
74
+		return $numRows;
75
+	}
76 76
     
77
-    /**
78
-     * ON category removal, put back cat to 0 on handlers with this category.
79
-     * @param int $catIndex
80
-     * @throws \ErrorException
81
-     * @return number
82
-     */
83
-    public function updateHandlersOnCategoryDelete($catIndex)
84
-    {
85
-        // TODO Check for rule consistency
86
-        $dbConn = $this->getDbConn();
87
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
77
+	/**
78
+	 * ON category removal, put back cat to 0 on handlers with this category.
79
+	 * @param int $catIndex
80
+	 * @throws \ErrorException
81
+	 * @return number
82
+	 */
83
+	public function updateHandlersOnCategoryDelete($catIndex)
84
+	{
85
+		// TODO Check for rule consistency
86
+		$dbConn = $this->getDbConn();
87
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
88 88
         
89
-        $numRows=$dbConn->update(
90
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
91
-            array('rule_type' => 0),
92
-            'rule_type='.$catIndex
93
-            );
94
-        return $numRows;
95
-    }
89
+		$numRows=$dbConn->update(
90
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
91
+			array('rule_type' => 0),
92
+			'rule_type='.$catIndex
93
+			);
94
+		return $numRows;
95
+	}
96 96
     
97
-    /** Delete rule by id
98
-     *	@param int $ruleID rule id
99
-     */
100
-    public function deleteRule($ruleID)
101
-    {
102
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
97
+	/** Delete rule by id
98
+	 *	@param int $ruleID rule id
99
+	 */
100
+	public function deleteRule($ruleID)
101
+	{
102
+		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
103 103
         
104
-        $dbConn = $this->getDbConn();
105
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
104
+		$dbConn = $this->getDbConn();
105
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
106 106
         
107
-        $query=$dbConn->delete(
108
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
109
-            'id='.$ruleID
110
-            );
111
-        return $query;
112
-    }
107
+		$query=$dbConn->delete(
108
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
109
+			'id='.$ruleID
110
+			);
111
+		return $query;
112
+	}
113 113
 
114
-    /**
115
-     * Get last trap rule table modification
116
-     * @throws \ErrorException
117
-     * @return Zend_Db_Select
118
-     */
119
-    public function lastModification()
120
-    {
121
-        $dbConn = $this->getDbConn();
122
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
114
+	/**
115
+	 * Get last trap rule table modification
116
+	 * @throws \ErrorException
117
+	 * @return Zend_Db_Select
118
+	 */
119
+	public function lastModification()
120
+	{
121
+		$dbConn = $this->getDbConn();
122
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
123 123
         
124
-        $query = $dbConn->select()
125
-        ->from(
126
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
127
-            array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
128
-        $returnRow=$dbConn->fetchRow($query);
129
-        return $returnRow->lastmodified;
130
-    }
124
+		$query = $dbConn->select()
125
+		->from(
126
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
127
+			array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
128
+		$returnRow=$dbConn->fetchRow($query);
129
+		return $returnRow->lastmodified;
130
+	}
131 131
     
132
-    /** Delete trap by ip & oid
133
-     *	@param $ipAddr string source IP (v4 or v6)
134
-     *	@param $oid string oid
135
-     */
136
-    public function deleteTrap($ipAddr,$oid)
137
-    {
132
+	/** Delete trap by ip & oid
133
+	 *	@param $ipAddr string source IP (v4 or v6)
134
+	 *	@param $oid string oid
135
+	 */
136
+	public function deleteTrap($ipAddr,$oid)
137
+	{
138 138
         
139
-        $dbConn = $this->getDbConn();
140
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
141
-        $condition=null;
142
-        if ($ipAddr != null)
143
-        {
144
-            $condition="source_ip='$ipAddr'";
145
-        }
146
-        if ($oid != null)
147
-        {
148
-            $condition=($condition===null)?'':$condition.' AND ';
149
-            $condition.="trap_oid='$oid'";
150
-        }
151
-        if($condition === null) return null;
152
-        $query=$dbConn->delete(
153
-            $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
154
-            $condition
155
-            );
156
-        // TODO test ret code etc...
157
-        return $query;
158
-    }
139
+		$dbConn = $this->getDbConn();
140
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
141
+		$condition=null;
142
+		if ($ipAddr != null)
143
+		{
144
+			$condition="source_ip='$ipAddr'";
145
+		}
146
+		if ($oid != null)
147
+		{
148
+			$condition=($condition===null)?'':$condition.' AND ';
149
+			$condition.="trap_oid='$oid'";
150
+		}
151
+		if($condition === null) return null;
152
+		$query=$dbConn->delete(
153
+			$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
154
+			$condition
155
+			);
156
+		// TODO test ret code etc...
157
+		return $query;
158
+	}
159 159
     
160 160
     
161
-    /** count trap by ip & oid
162
-     *	@param $ipAddr string source IP (v4 or v6)
163
-     *	@param $oid string oid
164
-     */
165
-    public function countTrap($ipAddr,$oid)
166
-    {
161
+	/** count trap by ip & oid
162
+	 *	@param $ipAddr string source IP (v4 or v6)
163
+	 *	@param $oid string oid
164
+	 */
165
+	public function countTrap($ipAddr,$oid)
166
+	{
167 167
         
168
-        $dbConn = $this->getDbConn();
169
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
168
+		$dbConn = $this->getDbConn();
169
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
170 170
         
171
-        $condition=null;
172
-        if ($ipAddr != null)
173
-        {
174
-            $condition="source_ip='$ipAddr'";
175
-        }
176
-        if ($oid != null)
177
-        {
178
-            $condition=($condition===null)?'':$condition.' AND ';
179
-            $condition.="trap_oid='$oid'";
180
-        }
181
-        if($condition === null) return 0;
182
-        $query=$dbConn->select()
183
-            ->from(
184
-                $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
185
-                array('num'=>'count(*)'))
186
-            ->where($condition);
187
-        $returnRow=$dbConn->fetchRow($query);
188
-        return $returnRow->num;
189
-    }
171
+		$condition=null;
172
+		if ($ipAddr != null)
173
+		{
174
+			$condition="source_ip='$ipAddr'";
175
+		}
176
+		if ($oid != null)
177
+		{
178
+			$condition=($condition===null)?'':$condition.' AND ';
179
+			$condition.="trap_oid='$oid'";
180
+		}
181
+		if($condition === null) return 0;
182
+		$query=$dbConn->select()
183
+			->from(
184
+				$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
185
+				array('num'=>'count(*)'))
186
+			->where($condition);
187
+		$returnRow=$dbConn->fetchRow($query);
188
+		return $returnRow->num;
189
+	}
190 190
     
191
-    /** get configuration value
192
-     *	@param string $element : configuration name in db
193
-     */
194
-    public function getDBConfigValue($element)
195
-    {
191
+	/** get configuration value
192
+	 *	@param string $element : configuration name in db
193
+	 */
194
+	public function getDBConfigValue($element)
195
+	{
196 196
         
197
-        $dbConn = $this->getDbConn();
198
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
197
+		$dbConn = $this->getDbConn();
198
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
199 199
         
200
-        $query=$dbConn->select()
201
-        ->from(
202
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
203
-            array('value'=>'value'))
204
-            ->where('name=?',$element);
205
-            $returnRow=$dbConn->fetchRow($query);
206
-            if ($returnRow==null)  // value does not exists
207
-            {
208
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
209
-                if ( ! isset($default[$element])) return null; // no default and not value
200
+		$query=$dbConn->select()
201
+		->from(
202
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
203
+			array('value'=>'value'))
204
+			->where('name=?',$element);
205
+			$returnRow=$dbConn->fetchRow($query);
206
+			if ($returnRow==null)  // value does not exists
207
+			{
208
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
209
+				if ( ! isset($default[$element])) return null; // no default and not value
210 210
                 
211
-                $this->addDBConfigValue($element,$default[$element]);
212
-                return $default[$element];
213
-            }
214
-            if ($returnRow->value == null) // value id empty
215
-            {
216
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
217
-                if ( ! isset($default[$element])) return null; // no default and not value
218
-                $this->setDBConfigValue($element,$default[$element]);
219
-                return $default[$element];
220
-            }
221
-            return $returnRow->value;
222
-    }
211
+				$this->addDBConfigValue($element,$default[$element]);
212
+				return $default[$element];
213
+			}
214
+			if ($returnRow->value == null) // value id empty
215
+			{
216
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
217
+				if ( ! isset($default[$element])) return null; // no default and not value
218
+				$this->setDBConfigValue($element,$default[$element]);
219
+				return $default[$element];
220
+			}
221
+			return $returnRow->value;
222
+	}
223 223
     
224
-    /** add configuration value
225
-     *	@param string $element : name of config element
226
-     *   @param string $value : value
227
-     */
224
+	/** add configuration value
225
+	 *	@param string $element : name of config element
226
+	 *   @param string $value : value
227
+	 */
228 228
     
229
-    public function addDBConfigValue($element,$value)
230
-    {
229
+	public function addDBConfigValue($element,$value)
230
+	{
231 231
         
232
-        $dbConn = $this->getDbConn();
233
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
232
+		$dbConn = $this->getDbConn();
233
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
234 234
         
235
-        $query=$dbConn->insert(
236
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
237
-            array(
238
-                'name' => $element,
239
-                'value'=>$value
240
-            )
241
-            );
242
-        return $query;
243
-    }
235
+		$query=$dbConn->insert(
236
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
237
+			array(
238
+				'name' => $element,
239
+				'value'=>$value
240
+			)
241
+			);
242
+		return $query;
243
+	}
244 244
     
245
-    /** set configuration value
246
-     *	@param string $element : name of config element
247
-     *   @param string $value : value
248
-     */
249
-    public function setDBConfigValue($element,$value)
250
-    {
245
+	/** set configuration value
246
+	 *	@param string $element : name of config element
247
+	 *   @param string $value : value
248
+	 */
249
+	public function setDBConfigValue($element,$value)
250
+	{
251 251
         
252
-        $dbConn = $this->getDbConn();
253
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
252
+		$dbConn = $this->getDbConn();
253
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
254 254
         
255
-        $query=$dbConn->update(
256
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
257
-            array('value'=>$value),
258
-            'name=\''.$element.'\''
259
-            );
260
-        return $query;
261
-    }
255
+		$query=$dbConn->update(
256
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
257
+			array('value'=>$value),
258
+			'name=\''.$element.'\''
259
+			);
260
+		return $query;
261
+	}
262 262
     
263 263
     
264 264
 }
265 265
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
     {
35 35
         // TODO Check for rule consistency
36 36
         
37
-        $dbConn = $this->getDbConn();
37
+        $dbConn=$this->getDbConn();
38 38
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
39 39
         // Add last modified date = creation date and username
40
-        $params['created'] = new Zend_Db_Expr('NOW()');
41
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
42
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
40
+        $params['created']=new Zend_Db_Expr('NOW()');
41
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
42
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
43 43
         
44 44
         $query=$dbConn->insert(
45 45
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46 46
             $params
47 47
             );
48
-        if($query==false)
48
+        if ($query == false)
49 49
         {
50 50
             return null;
51 51
         }
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
      *   @param integer $ruleID : rule id in db
58 58
      *	@return array affected rows
59 59
      */
60
-    public function updateHandlerRule($params,$ruleID)
60
+    public function updateHandlerRule($params, $ruleID)
61 61
     {
62 62
         // TODO Check for rule consistency
63
-        $dbConn = $this->getDbConn();
63
+        $dbConn=$this->getDbConn();
64 64
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
65 65
         // Add last modified date = creation date and username
66
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
67
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
66
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
67
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
68 68
         
69 69
         $numRows=$dbConn->update(
70 70
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     public function updateHandlersOnCategoryDelete($catIndex)
84 84
     {
85 85
         // TODO Check for rule consistency
86
-        $dbConn = $this->getDbConn();
86
+        $dbConn=$this->getDbConn();
87 87
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
88 88
         
89 89
         $numRows=$dbConn->update(
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function deleteRule($ruleID)
101 101
     {
102
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
102
+        if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
103 103
         
104
-        $dbConn = $this->getDbConn();
104
+        $dbConn=$this->getDbConn();
105 105
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
106 106
         
107 107
         $query=$dbConn->delete(
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
      */
119 119
     public function lastModification()
120 120
     {
121
-        $dbConn = $this->getDbConn();
121
+        $dbConn=$this->getDbConn();
122 122
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
123 123
         
124
-        $query = $dbConn->select()
124
+        $query=$dbConn->select()
125 125
         ->from(
126 126
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
127 127
             array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
      *	@param $ipAddr string source IP (v4 or v6)
134 134
      *	@param $oid string oid
135 135
      */
136
-    public function deleteTrap($ipAddr,$oid)
136
+    public function deleteTrap($ipAddr, $oid)
137 137
     {
138 138
         
139
-        $dbConn = $this->getDbConn();
139
+        $dbConn=$this->getDbConn();
140 140
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
141 141
         $condition=null;
142 142
         if ($ipAddr != null)
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
         }
146 146
         if ($oid != null)
147 147
         {
148
-            $condition=($condition===null)?'':$condition.' AND ';
148
+            $condition=($condition === null) ? '' : $condition.' AND ';
149 149
             $condition.="trap_oid='$oid'";
150 150
         }
151
-        if($condition === null) return null;
151
+        if ($condition === null) return null;
152 152
         $query=$dbConn->delete(
153 153
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
154 154
             $condition
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
      *	@param $ipAddr string source IP (v4 or v6)
163 163
      *	@param $oid string oid
164 164
      */
165
-    public function countTrap($ipAddr,$oid)
165
+    public function countTrap($ipAddr, $oid)
166 166
     {
167 167
         
168
-        $dbConn = $this->getDbConn();
168
+        $dbConn=$this->getDbConn();
169 169
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
170 170
         
171 171
         $condition=null;
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
         }
176 176
         if ($oid != null)
177 177
         {
178
-            $condition=($condition===null)?'':$condition.' AND ';
178
+            $condition=($condition === null) ? '' : $condition.' AND ';
179 179
             $condition.="trap_oid='$oid'";
180 180
         }
181
-        if($condition === null) return 0;
181
+        if ($condition === null) return 0;
182 182
         $query=$dbConn->select()
183 183
             ->from(
184 184
                 $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -194,28 +194,28 @@  discard block
 block discarded – undo
194 194
     public function getDBConfigValue($element)
195 195
     {
196 196
         
197
-        $dbConn = $this->getDbConn();
197
+        $dbConn=$this->getDbConn();
198 198
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
199 199
         
200 200
         $query=$dbConn->select()
201 201
         ->from(
202 202
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
203 203
             array('value'=>'value'))
204
-            ->where('name=?',$element);
204
+            ->where('name=?', $element);
205 205
             $returnRow=$dbConn->fetchRow($query);
206
-            if ($returnRow==null)  // value does not exists
206
+            if ($returnRow == null)  // value does not exists
207 207
             {
208 208
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
209
-                if ( ! isset($default[$element])) return null; // no default and not value
209
+                if (!isset($default[$element])) return null; // no default and not value
210 210
                 
211
-                $this->addDBConfigValue($element,$default[$element]);
211
+                $this->addDBConfigValue($element, $default[$element]);
212 212
                 return $default[$element];
213 213
             }
214 214
             if ($returnRow->value == null) // value id empty
215 215
             {
216 216
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
217
-                if ( ! isset($default[$element])) return null; // no default and not value
218
-                $this->setDBConfigValue($element,$default[$element]);
217
+                if (!isset($default[$element])) return null; // no default and not value
218
+                $this->setDBConfigValue($element, $default[$element]);
219 219
                 return $default[$element];
220 220
             }
221 221
             return $returnRow->value;
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
      *   @param string $value : value
227 227
      */
228 228
     
229
-    public function addDBConfigValue($element,$value)
229
+    public function addDBConfigValue($element, $value)
230 230
     {
231 231
         
232
-        $dbConn = $this->getDbConn();
232
+        $dbConn=$this->getDbConn();
233 233
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
234 234
         
235 235
         $query=$dbConn->insert(
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
      *	@param string $element : name of config element
247 247
      *   @param string $value : value
248 248
      */
249
-    public function setDBConfigValue($element,$value)
249
+    public function setDBConfigValue($element, $value)
250 250
     {
251 251
         
252
-        $dbConn = $this->getDbConn();
252
+        $dbConn=$this->getDbConn();
253 253
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
254 254
         
255 255
         $query=$dbConn->update(
Please login to merge, or discard this patch.
Braces   +50 added lines, -16 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
         // TODO Check for rule consistency
36 36
         
37 37
         $dbConn = $this->getDbConn();
38
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
38
+        if ($dbConn === null) {
39
+        	throw new \ErrorException('uncatched db error');
40
+        }
39 41
         // Add last modified date = creation date and username
40 42
         $params['created'] = new Zend_Db_Expr('NOW()');
41 43
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
@@ -61,7 +63,9 @@  discard block
 block discarded – undo
61 63
     {
62 64
         // TODO Check for rule consistency
63 65
         $dbConn = $this->getDbConn();
64
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
66
+        if ($dbConn === null) {
67
+        	throw new \ErrorException('uncatched db error');
68
+        }
65 69
         // Add last modified date = creation date and username
66 70
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
67 71
         $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
@@ -84,7 +88,9 @@  discard block
 block discarded – undo
84 88
     {
85 89
         // TODO Check for rule consistency
86 90
         $dbConn = $this->getDbConn();
87
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
91
+        if ($dbConn === null) {
92
+        	throw new \ErrorException('uncatched db error');
93
+        }
88 94
         
89 95
         $numRows=$dbConn->update(
90 96
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -102,7 +108,9 @@  discard block
 block discarded – undo
102 108
         if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
103 109
         
104 110
         $dbConn = $this->getDbConn();
105
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
111
+        if ($dbConn === null) {
112
+        	throw new \ErrorException('uncatched db error');
113
+        }
106 114
         
107 115
         $query=$dbConn->delete(
108 116
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -119,7 +127,9 @@  discard block
 block discarded – undo
119 127
     public function lastModification()
120 128
     {
121 129
         $dbConn = $this->getDbConn();
122
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
130
+        if ($dbConn === null) {
131
+        	throw new \ErrorException('uncatched db error');
132
+        }
123 133
         
124 134
         $query = $dbConn->select()
125 135
         ->from(
@@ -137,7 +147,9 @@  discard block
 block discarded – undo
137 147
     {
138 148
         
139 149
         $dbConn = $this->getDbConn();
140
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
150
+        if ($dbConn === null) {
151
+        	throw new \ErrorException('uncatched db error');
152
+        }
141 153
         $condition=null;
142 154
         if ($ipAddr != null)
143 155
         {
@@ -148,7 +160,9 @@  discard block
 block discarded – undo
148 160
             $condition=($condition===null)?'':$condition.' AND ';
149 161
             $condition.="trap_oid='$oid'";
150 162
         }
151
-        if($condition === null) return null;
163
+        if($condition === null) {
164
+        	return null;
165
+        }
152 166
         $query=$dbConn->delete(
153 167
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
154 168
             $condition
@@ -166,7 +180,9 @@  discard block
 block discarded – undo
166 180
     {
167 181
         
168 182
         $dbConn = $this->getDbConn();
169
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
183
+        if ($dbConn === null) {
184
+        	throw new \ErrorException('uncatched db error');
185
+        }
170 186
         
171 187
         $condition=null;
172 188
         if ($ipAddr != null)
@@ -178,7 +194,9 @@  discard block
 block discarded – undo
178 194
             $condition=($condition===null)?'':$condition.' AND ';
179 195
             $condition.="trap_oid='$oid'";
180 196
         }
181
-        if($condition === null) return 0;
197
+        if($condition === null) {
198
+        	return 0;
199
+        }
182 200
         $query=$dbConn->select()
183 201
             ->from(
184 202
                 $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -195,7 +213,9 @@  discard block
 block discarded – undo
195 213
     {
196 214
         
197 215
         $dbConn = $this->getDbConn();
198
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
216
+        if ($dbConn === null) {
217
+        	throw new \ErrorException('uncatched db error');
218
+        }
199 219
         
200 220
         $query=$dbConn->select()
201 221
         ->from(
@@ -203,18 +223,28 @@  discard block
 block discarded – undo
203 223
             array('value'=>'value'))
204 224
             ->where('name=?',$element);
205 225
             $returnRow=$dbConn->fetchRow($query);
206
-            if ($returnRow==null)  // value does not exists
226
+            if ($returnRow==null) {
227
+            	// value does not exists
207 228
             {
208 229
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
209
-                if ( ! isset($default[$element])) return null; // no default and not value
230
+            }
231
+                if ( ! isset($default[$element])) {
232
+                	return null;
233
+                }
234
+                // no default and not value
210 235
                 
211 236
                 $this->addDBConfigValue($element,$default[$element]);
212 237
                 return $default[$element];
213 238
             }
214
-            if ($returnRow->value == null) // value id empty
239
+            if ($returnRow->value == null) {
240
+            	// value id empty
215 241
             {
216 242
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
217
-                if ( ! isset($default[$element])) return null; // no default and not value
243
+            }
244
+                if ( ! isset($default[$element])) {
245
+                	return null;
246
+                }
247
+                // no default and not value
218 248
                 $this->setDBConfigValue($element,$default[$element]);
219 249
                 return $default[$element];
220 250
             }
@@ -230,7 +260,9 @@  discard block
 block discarded – undo
230 260
     {
231 261
         
232 262
         $dbConn = $this->getDbConn();
233
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
263
+        if ($dbConn === null) {
264
+        	throw new \ErrorException('uncatched db error');
265
+        }
234 266
         
235 267
         $query=$dbConn->insert(
236 268
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
@@ -250,7 +282,9 @@  discard block
 block discarded – undo
250 282
     {
251 283
         
252 284
         $dbConn = $this->getDbConn();
253
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
285
+        if ($dbConn === null) {
286
+        	throw new \ErrorException('uncatched db error');
287
+        }
254 288
         
255 289
         $query=$dbConn->update(
256 290
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +261 added lines, -262 removed lines patch added patch discarded remove patch
@@ -12,13 +12,12 @@  discard block
 block discarded – undo
12 12
 
13 13
 //use Icinga\Web\Form as Form;
14 14
 /** Rules management
15
-
16
-*/
15
+ */
17 16
 class HandlerController extends TrapsController
18 17
 {
19 18
 
20 19
 	/** index : list existing rules 
21
-	*/
20
+	 */
22 21
 	public function indexAction()
23 22
 	{	
24 23
 		$this->checkReadPermission();
@@ -28,13 +27,13 @@  discard block
 block discarded – undo
28 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
29 28
 		
30 29
 		$handlerTable = new HandlerTable(
31
-		      $this->moduleConfig->getTrapRuleName(),
32
-		      $this->moduleConfig->getHandlerListTitles(),
33
-		      $this->moduleConfig->getHandlerListDisplayColumns(),
34
-		      $this->moduleConfig->getHandlerColumns(),
35
-		      $dbConn->getConnection(),
36
-		      $this->view,
37
-		      $this->moduleConfig->urlPath());
30
+			  $this->moduleConfig->getTrapRuleName(),
31
+			  $this->moduleConfig->getHandlerListTitles(),
32
+			  $this->moduleConfig->getHandlerListDisplayColumns(),
33
+			  $this->moduleConfig->getHandlerColumns(),
34
+			  $dbConn->getConnection(),
35
+			  $this->view,
36
+			  $this->moduleConfig->urlPath());
38 37
 		
39 38
 		$handlerTable->setMaxPerPage($this->itemListDisplay());
40 39
 		
@@ -56,7 +55,7 @@  discard block
 block discarded – undo
56 55
 		
57 56
 		// TODO : Obsolete remove after new table validation.
58 57
 		
59
-	    /**
58
+		/**
60 59
 		$this->getHandlerListTable()->setConnection($dbConn);
61 60
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
62 61
 		// Apply pagination limits 
@@ -73,22 +72,22 @@  discard block
 block discarded – undo
73 72
 	 */
74 73
 	public function testruleAction()
75 74
 	{
76
-	    $this->checkReadPermission();
77
-	    $this->getTabs()->add('get',array(
78
-	        'active'	=> true,
79
-	        'label'		=> $this->translate('Test Rule'),
80
-	        'url'		=> Url::fromRequest()
81
-	    ));
75
+		$this->checkReadPermission();
76
+		$this->getTabs()->add('get',array(
77
+			'active'	=> true,
78
+			'label'		=> $this->translate('Test Rule'),
79
+			'url'		=> Url::fromRequest()
80
+		));
82 81
 	    
83 82
 
84
-	    if ($this->params->get('rule') !== null) 
85
-	    {
86
-	        $this->view->rule= $this->params->get('rule');
87
-	    }
88
-	    else
89
-	    {
90
-	        $this->view->rule='';
91
-	    }
83
+		if ($this->params->get('rule') !== null) 
84
+		{
85
+			$this->view->rule= $this->params->get('rule');
86
+		}
87
+		else
88
+		{
89
+			$this->view->rule='';
90
+		}
92 91
 	}
93 92
 	
94 93
 	/**
@@ -96,31 +95,31 @@  discard block
 block discarded – undo
96 95
 	 */
97 96
 	private function add_setup_vars()
98 97
 	{
99
-	    // variables to send to view
100
-	    $this->view->hostlist=array(); // host list to input datalist
101
-	    $this->view->hostname=''; // Host name in input text
102
-	    $this->view->serviceGet=false; // Set to true to get list of service if only one host set
103
-	    $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
104
-	    $this->view->mainoid=''; // Trap OID
105
-	    $this->view->mib=''; // Trap mib
106
-	    $this->view->name=''; // Trap name
107
-	    $this->view->trapListForMIB=array(); // Trap list if mib exists for trap
108
-	    $this->view->objectList=array(); // objects sent with trap
109
-	    $this->view->display=''; // Initial display
110
-	    $this->view->rule=''; // rule display
111
-	    $this->view->revertOK=''; // revert OK in seconds
112
-	    $this->view->hostid=-1; // normally set by javascript serviceGet()
113
-	    $this->view->ruleid=-1; // Rule id in DB for update & delete
114
-	    $this->view->setToUpdate=false; // set form as update form
115
-	    $this->view->setRuleMatch=-1; // set action on rule match (default nothing)
116
-	    $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
98
+		// variables to send to view
99
+		$this->view->hostlist=array(); // host list to input datalist
100
+		$this->view->hostname=''; // Host name in input text
101
+		$this->view->serviceGet=false; // Set to true to get list of service if only one host set
102
+		$this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
103
+		$this->view->mainoid=''; // Trap OID
104
+		$this->view->mib=''; // Trap mib
105
+		$this->view->name=''; // Trap name
106
+		$this->view->trapListForMIB=array(); // Trap list if mib exists for trap
107
+		$this->view->objectList=array(); // objects sent with trap
108
+		$this->view->display=''; // Initial display
109
+		$this->view->rule=''; // rule display
110
+		$this->view->revertOK=''; // revert OK in seconds
111
+		$this->view->hostid=-1; // normally set by javascript serviceGet()
112
+		$this->view->ruleid=-1; // Rule id in DB for update & delete
113
+		$this->view->setToUpdate=false; // set form as update form
114
+		$this->view->setRuleMatch=-1; // set action on rule match (default nothing)
115
+		$this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
117 116
 	    
118
-	    $this->view->selectGroup=false; // Select by group if true
119
-	    $this->view->hostgroupid=-1; // host group id
120
-	    $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
117
+		$this->view->selectGroup=false; // Select by group if true
118
+		$this->view->hostgroupid=-1; // host group id
119
+		$this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
121 120
 	    
122
-	    $this->view->modifier=null;
123
-	    $this->view->modified=null;
121
+		$this->view->modifier=null;
122
+		$this->view->modified=null;
124 123
 	}
125 124
 	
126 125
 	/**
@@ -129,102 +128,102 @@  discard block
 block discarded – undo
129 128
 	 */
130 129
 	private function add_from_existing($trapid)
131 130
 	{
132
-	    /********** Setup from existing trap ***************/
133
-	    // Get the full trap info
134
-	    $trapDetail=$this->getTrapDetail($trapid);
131
+		/********** Setup from existing trap ***************/
132
+		// Get the full trap info
133
+		$trapDetail=$this->getTrapDetail($trapid);
135 134
 	    
136
-	    $hostfilter=$trapDetail->source_ip;
135
+		$hostfilter=$trapDetail->source_ip;
137 136
 	    
138
-	    // Get host
139
-	    try
140
-	    {
141
-	        $hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
142
-	    }
143
-	    catch (Exception $e)
144
-	    {
145
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
146
-	    }
137
+		// Get host
138
+		try
139
+		{
140
+			$hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
141
+		}
142
+		catch (Exception $e)
143
+		{
144
+			$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
145
+		}
147 146
 	    
148 147
 	    
149
-	    // if one unique host found -> put id text input
150
-	    if (count($hosts)==1) {
151
-	        $this->view->hostname=$hosts[0]->name;
152
-	        //$hostid=$hosts[0]->id;
153
-	        // Tell JS to get services when page is loaded
154
-	        $this->view->serviceGet=true;
148
+		// if one unique host found -> put id text input
149
+		if (count($hosts)==1) {
150
+			$this->view->hostname=$hosts[0]->name;
151
+			//$hostid=$hosts[0]->id;
152
+			// Tell JS to get services when page is loaded
153
+			$this->view->serviceGet=true;
155 154
 	        
156
-	    }
157
-	    else
158
-	    {
159
-	        foreach($hosts as $key=>$val)
160
-	        {
161
-	            array_push($this->view->hostlist,$hosts[$key]->name);
162
-	        }
163
-	    }
155
+		}
156
+		else
157
+		{
158
+			foreach($hosts as $key=>$val)
159
+			{
160
+				array_push($this->view->hostlist,$hosts[$key]->name);
161
+			}
162
+		}
164 163
 	    
165
-	    // set up trap oid and objects received by the trap
164
+		// set up trap oid and objects received by the trap
166 165
 	    
167
-	    $this->view->mainoid=$trapDetail->trap_oid;
168
-	    if ($trapDetail->trap_name_mib != null)
169
-	    {
170
-	        $this->view->mib=$trapDetail->trap_name_mib;
171
-	        $this->view->name=$trapDetail->trap_name;
172
-	        $this->view->trapListForMIB=$this->getMIB()
173
-	        ->getTrapList($trapDetail->trap_name_mib);
174
-	    }
166
+		$this->view->mainoid=$trapDetail->trap_oid;
167
+		if ($trapDetail->trap_name_mib != null)
168
+		{
169
+			$this->view->mib=$trapDetail->trap_name_mib;
170
+			$this->view->name=$trapDetail->trap_name;
171
+			$this->view->trapListForMIB=$this->getMIB()
172
+			->getTrapList($trapDetail->trap_name_mib);
173
+		}
175 174
 	    
176
-	    // Get all objects that can be in trap from MIB
177
-	    $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
178
-	    // Get all objects in current Trap
179
-	    $currentTrapObjects=$this->getTrapobjects($trapid);
180
-	    $oid_index=1;
181
-	    foreach ($currentTrapObjects as $key => $val)
182
-	    {
183
-	        $currentObjectType='Unknown';
184
-	        $currentObjectTypeEnum='Unknown';
185
-	        if (isset($allObjects[$val->oid]['type']))
186
-	        {
187
-	            $currentObjectType=$allObjects[$val->oid]['type'];
188
-	            $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
189
-	        }
190
-	        $currentObject=array(
191
-	            $oid_index,
192
-	            $val->oid,
193
-	            $val->oid_name_mib,
194
-	            $val->oid_name,
195
-	            $val->value,
196
-	            $currentObjectType,
197
-	            $currentObjectTypeEnum
198
-	        );
199
-	        $oid_index++;
200
-	        array_push($this->view->objectList,$currentObject);
201
-	        // set currrent object to null in allObjects
202
-	        if (isset($allObjects[$val->oid]))
203
-	        {
204
-	            $allObjects[$val->oid]=null;
205
-	        }
206
-	    }
207
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
208
-	    {
209
-	        foreach ($allObjects as $key => $val)
210
-	        {
211
-	            if ($val==null) { continue; }
212
-	            array_push($this->view->objectList, array(
213
-	                $oid_index,
214
-	                $key,
215
-	                $allObjects[$key]['mib'],
216
-	                $allObjects[$key]['name'],
217
-	                '',
218
-	                $allObjects[$key]['type'],
219
-	                $allObjects[$key]['type_enum']
220
-	            ));
221
-	            $oid_index++;
222
-	        }
223
-	    }
175
+		// Get all objects that can be in trap from MIB
176
+		$allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
177
+		// Get all objects in current Trap
178
+		$currentTrapObjects=$this->getTrapobjects($trapid);
179
+		$oid_index=1;
180
+		foreach ($currentTrapObjects as $key => $val)
181
+		{
182
+			$currentObjectType='Unknown';
183
+			$currentObjectTypeEnum='Unknown';
184
+			if (isset($allObjects[$val->oid]['type']))
185
+			{
186
+				$currentObjectType=$allObjects[$val->oid]['type'];
187
+				$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
188
+			}
189
+			$currentObject=array(
190
+				$oid_index,
191
+				$val->oid,
192
+				$val->oid_name_mib,
193
+				$val->oid_name,
194
+				$val->value,
195
+				$currentObjectType,
196
+				$currentObjectTypeEnum
197
+			);
198
+			$oid_index++;
199
+			array_push($this->view->objectList,$currentObject);
200
+			// set currrent object to null in allObjects
201
+			if (isset($allObjects[$val->oid]))
202
+			{
203
+				$allObjects[$val->oid]=null;
204
+			}
205
+		}
206
+		if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
207
+		{
208
+			foreach ($allObjects as $key => $val)
209
+			{
210
+				if ($val==null) { continue; }
211
+				array_push($this->view->objectList, array(
212
+					$oid_index,
213
+					$key,
214
+					$allObjects[$key]['mib'],
215
+					$allObjects[$key]['name'],
216
+					'',
217
+					$allObjects[$key]['type'],
218
+					$allObjects[$key]['type_enum']
219
+				));
220
+				$oid_index++;
221
+			}
222
+		}
224 223
 	    
225
-	    // Add a simple display
226
-	    $this->view->display='Trap '.$trapDetail->trap_name.' received';
227
-	    $this->view->create_basic_rule=true;
224
+		// Add a simple display
225
+		$this->view->display='Trap '.$trapDetail->trap_name.' received';
226
+		$this->view->create_basic_rule=true;
228 227
 	}
229 228
 
230 229
 	/**
@@ -233,29 +232,29 @@  discard block
 block discarded – undo
233 232
 	 */
234 233
 	private function add_check_host_exists($ruleDetail)
235 234
 	{
236
-	    // Check if hostname still exists
237
-	    $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
235
+		// Check if hostname still exists
236
+		$host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
238 237
 	    
239
-	    if (count($host_get)==0)
240
-	    {
241
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
242
-	        $this->view->serviceGet=false;
243
-	    }
244
-	    else
245
-	    {
246
-	        // Tell JS to get services when page is loaded
247
-	        $this->view->serviceGet=true;
248
-	        // get service id for form to set :
249
-	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
250
-	        if (count($serviceID) ==0)
251
-	        {
252
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
253
-	        }
254
-	        else
255
-	        {
256
-	            $this->view->serviceSet=$serviceID[0]->id;
257
-	        }
258
-	    }
238
+		if (count($host_get)==0)
239
+		{
240
+			$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
241
+			$this->view->serviceGet=false;
242
+		}
243
+		else
244
+		{
245
+			// Tell JS to get services when page is loaded
246
+			$this->view->serviceGet=true;
247
+			// get service id for form to set :
248
+			$serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
249
+			if (count($serviceID) ==0)
250
+			{
251
+				$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
252
+			}
253
+			else
254
+			{
255
+				$this->view->serviceSet=$serviceID[0]->id;
256
+			}
257
+		}
259 258
 	}
260 259
 
261 260
 	/**
@@ -264,33 +263,33 @@  discard block
 block discarded – undo
264 263
 	 */
265 264
 	private function add_check_hostgroup_exists($ruleDetail)
266 265
 	{
267
-	    // Check if groupe exists
268
-	    $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
269
-	    if (count($group_get)==0)
270
-	    {
271
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
272
-	        $this->view->serviceGroupGet=false;
273
-	    }
274
-	    else
275
-	    {
276
-	        $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
277
-	        $foundGrpService=0;
278
-	        foreach ($grpServices as $grpService)
279
-	        {
280
-	            if ($grpService[0] == $ruleDetail->service_name)
281
-	            {
282
-	                $foundGrpService=1;
283
-	                $this->view->serviceSet=$ruleDetail->service_name;
284
-	            }
285
-	        }
266
+		// Check if groupe exists
267
+		$group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
268
+		if (count($group_get)==0)
269
+		{
270
+			$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
271
+			$this->view->serviceGroupGet=false;
272
+		}
273
+		else
274
+		{
275
+			$grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
276
+			$foundGrpService=0;
277
+			foreach ($grpServices as $grpService)
278
+			{
279
+				if ($grpService[0] == $ruleDetail->service_name)
280
+				{
281
+					$foundGrpService=1;
282
+					$this->view->serviceSet=$ruleDetail->service_name;
283
+				}
284
+			}
286 285
 	        
287
-	        // Tell JS to get services when page is loaded
288
-	        $this->view->serviceGroupGet=true;
289
-	        if ($foundGrpService==0)
290
-	        {
291
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
292
-	        }
293
-	    }
286
+			// Tell JS to get services when page is loaded
287
+			$this->view->serviceGroupGet=true;
288
+			if ($foundGrpService==0)
289
+			{
290
+				$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
291
+			}
292
+		}
294 293
 	}
295 294
 	
296 295
 	/**
@@ -302,52 +301,52 @@  discard block
 block discarded – undo
302 301
 	 */
303 302
 	private function add_create_trap_object_list(&$display, &$rule)
304 303
 	{
305
-	    $curObjectList=array();
306
-	    $index=1;
307
-	    // check in display & rule for : OID(<oid>)
308
-	    $matches=array();
309
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
310
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
311
-	    {
312
-	        $curOid=$matches[1];
304
+		$curObjectList=array();
305
+		$index=1;
306
+		// check in display & rule for : OID(<oid>)
307
+		$matches=array();
308
+		while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
309
+			preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
310
+		{
311
+			$curOid=$matches[1];
313 312
 	        
314
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
315
-	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
316
-	        {
317
-	            array_push($curObjectList, array(
318
-	                $index,
319
-	                $curOid,
320
-	                $object['mib'],
321
-	                $object['name'],
322
-	                '',
323
-	                $object['type'],
324
-	                $object['type_enum']
325
-	            ));
326
-	        }
327
-	        else
328
-	        {
329
-	            array_push($curObjectList, array(
330
-	                $index,
331
-	                $curOid,
332
-	                'not found',
333
-	                'not found',
334
-	                '',
335
-	                'not found',
336
-	                'not found'
337
-	            ));
338
-	        }
339
-	        $curOid = preg_replace('/\*/','\*',$curOid);
340
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
341
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
342
-	        $index++;
343
-	    }
344
-	    return $curObjectList;
313
+			if ( (preg_match('/\*/',$curOid) == 0 ) 
314
+				&& ($object=$this->getMIB()->translateOID($curOid)) != null)
315
+			{
316
+				array_push($curObjectList, array(
317
+					$index,
318
+					$curOid,
319
+					$object['mib'],
320
+					$object['name'],
321
+					'',
322
+					$object['type'],
323
+					$object['type_enum']
324
+				));
325
+			}
326
+			else
327
+			{
328
+				array_push($curObjectList, array(
329
+					$index,
330
+					$curOid,
331
+					'not found',
332
+					'not found',
333
+					'',
334
+					'not found',
335
+					'not found'
336
+				));
337
+			}
338
+			$curOid = preg_replace('/\*/','\*',$curOid);
339
+			$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
340
+			$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
341
+			$index++;
342
+		}
343
+		return $curObjectList;
345 344
 	}
346 345
 	
347 346
 	/** Add a handler  
348
-	*	Get params fromid : setup from existing trap (id of trap table)
349
-	*	Get param ruleid : edit from existing handler (id of rule table)
350
-	*/
347
+	 *	Get params fromid : setup from existing trap (id of trap table)
348
+	 *	Get param ruleid : edit from existing handler (id of rule table)
349
+	 */
351 350
 	public function addAction()
352 351
 	{
353 352
 		$this->checkConfigPermission();
@@ -370,8 +369,8 @@  discard block
 block discarded – undo
370 369
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
371 370
 		
372 371
 		if (($trapid = $this->params->get('fromid')) !== null) {
373
-		    /********** Setup from existing trap ***************/
374
-            $this->add_from_existing($trapid);
372
+			/********** Setup from existing trap ***************/
373
+			$this->add_from_existing($trapid);
375 374
 			return;
376 375
 		}
377 376
 		
@@ -399,14 +398,14 @@  discard block
 block discarded – undo
399 398
 			$this->view->warning_message='';
400 399
 			if ($this->view->hostname != null)
401 400
 			{
402
-			    $this->view->selectGroup=false;
403
-			    // Check if hostname still exists
404
-			    $this->add_check_host_exists($ruleDetail);
401
+				$this->view->selectGroup=false;
402
+				// Check if hostname still exists
403
+				$this->add_check_host_exists($ruleDetail);
405 404
 			}
406 405
 			else
407 406
 			{
408
-			    $this->view->selectGroup=true;
409
-			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
407
+				$this->view->selectGroup=true;
408
+				$this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
410 409
 			}
411 410
 			
412 411
 			$this->view->mainoid=$ruleDetail->trap_oid;
@@ -434,9 +433,9 @@  discard block
 block discarded – undo
434 433
 	}
435 434
 	
436 435
 	/** Validate form and output message to user  
437
-	*	@param in postdata 
438
-	* 	@return string status : OK / <Message>
439
-	**/
436
+	 *	@param in postdata 
437
+	 * 	@return string status : OK / <Message>
438
+	 **/
440 439
 	protected function handlerformAction()
441 440
 	{
442 441
 		$postData=$this->getRequest()->getPost();
@@ -451,8 +450,8 @@  discard block
 block discarded – undo
451 450
 			'host_group_name'=>	array('post' => null,            'val' => null,  'db'=>true),
452 451
 			'serviceid'		=>	array('post' => 'serviceid',                     'db'=>false),
453 452
 			'service_name'	=>	array('post' => 'serviceName',                    'db'=>true),
454
-		    'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
455
-		    'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
453
+			'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
454
+			'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
456 455
 			'trap_oid'		=>	array('post' => 'oid',                            'db'=>true),
457 456
 			'revert_ok'		=>	array('post' => 'revertOK',      'val' => 0,      'db'=>true),
458 457
 			'display'		=>	array('post' => 'display',        'val' => '',     'db'=>true),
@@ -461,7 +460,7 @@  discard block
 block discarded – undo
461 460
 			'action_nomatch'=>	array('post' => 'ruleNoMatch',    'val' => -1,    'db'=>true),					
462 461
 			'ip4'			=>	array('post' => null,             'val' => null,  'db'=>true),
463 462
 			'ip6'			=>	array('post' => null,             'val' => null,  'db'=>true),
464
-		    'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
463
+			'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
465 464
 		);
466 465
 		
467 466
 		if (isset($postData[$params['action_form']['post']]) 
@@ -469,7 +468,7 @@  discard block
 block discarded – undo
469 468
 		{
470 469
 			try
471 470
 			{
472
-			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
471
+				$this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
473 472
 			}
474 473
 			catch (Exception $e)
475 474
 			{
@@ -479,7 +478,7 @@  discard block
 block discarded – undo
479 478
 			//$this->Module()->
480 479
 			$this->_helper->json(array(
481 480
 				'status'=>'OK',
482
-			    'redirect'=>'trapdirector/handler'
481
+				'redirect'=>'trapdirector/handler'
483 482
 			      
484 483
 			));
485 484
 		}		
@@ -506,7 +505,7 @@  discard block
 block discarded – undo
506 505
 			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
507 506
 			if (! $isHostGroup ) 
508 507
 			{  // checks if selection by host 
509
-			    $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
508
+				$hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
510 509
 				$params['ip4']['val']=$hostAddr->ip4;
511 510
 				$params['ip6']['val']=$hostAddr->ip6;
512 511
 				$checkHostName=$hostAddr->name;
@@ -517,8 +516,8 @@  discard block
 block discarded – undo
517 516
 				}
518 517
 				if (!is_numeric($params['serviceid']['val']))
519 518
 				{
520
-				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
521
-				    return;
519
+					$this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
520
+					return;
522 521
 				}
523 522
 				$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
524 523
 				if ($params['service_name']['val'] != $serviceName->name2)
@@ -529,7 +528,7 @@  discard block
 block discarded – undo
529 528
 			}
530 529
 			else
531 530
 			{
532
-			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
531
+				$object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
533 532
 				if ($params['host_name']['val'] != $object->name1)
534 533
 				{
535 534
 					$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
@@ -551,11 +550,11 @@  discard block
 block discarded – undo
551 550
 			
552 551
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
553 552
 			{  // If no rule number or action is clone, add the handler
554
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
553
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
555 554
 			}
556 555
 			else
557 556
 			{
558
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
557
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
559 558
 				$ruleID=$params['db_rule']['val'];
560 559
 			}
561 560
 		}
@@ -569,9 +568,9 @@  discard block
 block discarded – undo
569 568
 	}
570 569
 
571 570
 	/** Get trap detail by trapid. 
572
-	*	@param integer $trapid : id of trap in received table
573
-	*	@return array (objects)
574
-	*/
571
+	 *	@param integer $trapid : id of trap in received table
572
+	 *	@return array (objects)
573
+	 */
575 574
 	protected function getTrapDetail($trapid) 
576 575
 	{
577 576
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -587,14 +586,14 @@  discard block
 block discarded – undo
587 586
 		}
588 587
 		try
589 588
 		{		
590
-		    $query = $dbConn->select()
589
+			$query = $dbConn->select()
591 590
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
592 591
 				->where('id=?',$trapid);
593 592
 				$trapDetail=$dbConn->fetchRow($query);
594 593
 			if ( $trapDetail == null ) 
595 594
 			{
596
-			    $trapDetail = 'NULL';
597
-			    throw new Exception('No traps was found with id = '.$trapid);
595
+				$trapDetail = 'NULL';
596
+				throw new Exception('No traps was found with id = '.$trapid);
598 597
 			}
599 598
 		}
600 599
 		catch (Exception $e)
@@ -608,9 +607,9 @@  discard block
 block discarded – undo
608 607
 	}
609 608
 
610 609
 	/** Get trap objects
611
-	*	@param integer $trapid : trap id
612
-	* 	@return array : full column in db of trap id
613
-	*/
610
+	 *	@param integer $trapid : trap id
611
+	 * 	@return array : full column in db of trap id
612
+	 */
614 613
 	protected function getTrapobjects($trapid)
615 614
 	{	
616 615
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -626,7 +625,7 @@  discard block
 block discarded – undo
626 625
 		}
627 626
 		try
628 627
 		{		
629
-		    $query = $dbConn->select()
628
+			$query = $dbConn->select()
630 629
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
631 630
 				->where('trap_id=?',$trapid);
632 631
 				$trapDetail=$dbConn->fetchAll($query);
@@ -642,10 +641,10 @@  discard block
 block discarded – undo
642 641
 	}
643 642
 
644 643
 	/** Get rule detail by ruleid.
645
-	*	@param integer $ruleid int id of rule in rule table
646
-	*	@return object|array : column objects in db 
647
-	*
648
-	*/
644
+	 *	@param integer $ruleid int id of rule in rule table
645
+	 *	@return object|array : column objects in db 
646
+	 *
647
+	 */
649 648
 	protected function getRuleDetail($ruleid) 
650 649
 	{
651 650
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -656,7 +655,7 @@  discard block
 block discarded – undo
656 655
 		// ***************  Get main data
657 656
 		try
658 657
 		{		
659
-		    $query = $dbConn->select()
658
+			$query = $dbConn->select()
660 659
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
661 660
 				->where('id=?',$ruleid);
662 661
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -673,7 +672,7 @@  discard block
 block discarded – undo
673 672
 	}
674 673
 
675 674
 	/** Setup tabs for rules 
676
-	*/
675
+	 */
677 676
 	protected function prepareTabs()
678 677
 	{
679 678
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 		$this->checkReadPermission();
25 25
 		$this->prepareTabs()->activate('status');
26 26
 
27
-		$dbConn = $this->getUIDatabase()->getDb();
27
+		$dbConn=$this->getUIDatabase()->getDb();
28 28
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
29 29
 		
30
-		$handlerTable = new HandlerTable(
30
+		$handlerTable=new HandlerTable(
31 31
 		      $this->moduleConfig->getTrapRuleName(),
32 32
 		      $this->moduleConfig->getHandlerListTitles(),
33 33
 		      $this->moduleConfig->getHandlerListDisplayColumns(),
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		
41 41
 		$handlerTable->setMibloader($this->getMIB());
42 42
 		
43
-		$getVars = $this->getRequest()->getParams();
43
+		$getVars=$this->getRequest()->getParams();
44 44
 		$handlerTable->getParams($getVars);
45 45
 		
46 46
 		if ($handlerTable->isOrderSet() == FALSE)
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		
52 52
 		}
53 53
 		
54
-		$this->view->handlerTable = $handlerTable;
54
+		$this->view->handlerTable=$handlerTable;
55 55
 		
56 56
 		
57 57
 		// TODO : Obsolete remove after new table validation.
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	public function testruleAction()
75 75
 	{
76 76
 	    $this->checkReadPermission();
77
-	    $this->getTabs()->add('get',array(
77
+	    $this->getTabs()->add('get', array(
78 78
 	        'active'	=> true,
79 79
 	        'label'		=> $this->translate('Test Rule'),
80 80
 	        'url'		=> Url::fromRequest()
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
 	    if ($this->params->get('rule') !== null) 
85 85
 	    {
86
-	        $this->view->rule= $this->params->get('rule');
86
+	        $this->view->rule=$this->params->get('rule');
87 87
 	    }
88 88
 	    else
89 89
 	    {
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
 	    }
143 143
 	    catch (Exception $e)
144 144
 	    {
145
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
145
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
146 146
 	    }
147 147
 	    
148 148
 	    
149 149
 	    // if one unique host found -> put id text input
150
-	    if (count($hosts)==1) {
150
+	    if (count($hosts) == 1) {
151 151
 	        $this->view->hostname=$hosts[0]->name;
152 152
 	        //$hostid=$hosts[0]->id;
153 153
 	        // Tell JS to get services when page is loaded
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 	    }
157 157
 	    else
158 158
 	    {
159
-	        foreach($hosts as $key=>$val)
159
+	        foreach ($hosts as $key=>$val)
160 160
 	        {
161
-	            array_push($this->view->hostlist,$hosts[$key]->name);
161
+	            array_push($this->view->hostlist, $hosts[$key]->name);
162 162
 	        }
163 163
 	    }
164 164
 	    
@@ -197,18 +197,18 @@  discard block
 block discarded – undo
197 197
 	            $currentObjectTypeEnum
198 198
 	        );
199 199
 	        $oid_index++;
200
-	        array_push($this->view->objectList,$currentObject);
200
+	        array_push($this->view->objectList, $currentObject);
201 201
 	        // set currrent object to null in allObjects
202 202
 	        if (isset($allObjects[$val->oid]))
203 203
 	        {
204 204
 	            $allObjects[$val->oid]=null;
205 205
 	        }
206 206
 	    }
207
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
207
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
208 208
 	    {
209 209
 	        foreach ($allObjects as $key => $val)
210 210
 	        {
211
-	            if ($val==null) { continue; }
211
+	            if ($val == null) { continue; }
212 212
 	            array_push($this->view->objectList, array(
213 213
 	                $oid_index,
214 214
 	                $key,
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	    // Check if hostname still exists
237 237
 	    $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
238 238
 	    
239
-	    if (count($host_get)==0)
239
+	    if (count($host_get) == 0)
240 240
 	    {
241
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
241
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
242 242
 	        $this->view->serviceGet=false;
243 243
 	    }
244 244
 	    else
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 	        // Tell JS to get services when page is loaded
247 247
 	        $this->view->serviceGet=true;
248 248
 	        // get service id for form to set :
249
-	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
250
-	        if (count($serviceID) ==0)
249
+	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
250
+	        if (count($serviceID) == 0)
251 251
 	        {
252
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
252
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
253 253
 	        }
254 254
 	        else
255 255
 	        {
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 	{
267 267
 	    // Check if groupe exists
268 268
 	    $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
269
-	    if (count($group_get)==0)
269
+	    if (count($group_get) == 0)
270 270
 	    {
271
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
271
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
272 272
 	        $this->view->serviceGroupGet=false;
273 273
 	    }
274 274
 	    else
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
 	        
287 287
 	        // Tell JS to get services when page is loaded
288 288
 	        $this->view->serviceGroupGet=true;
289
-	        if ($foundGrpService==0)
289
+	        if ($foundGrpService == 0)
290 290
 	        {
291
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
291
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
292 292
 	        }
293 293
 	    }
294 294
 	}
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 	    $index=1;
307 307
 	    // check in display & rule for : OID(<oid>)
308 308
 	    $matches=array();
309
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
310
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
309
+	    while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) ||
310
+	        preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches))
311 311
 	    {
312 312
 	        $curOid=$matches[1];
313 313
 	        
314
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
314
+	        if ((preg_match('/\*/', $curOid) == 0) 
315 315
 	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
316 316
 	        {
317 317
 	            array_push($curObjectList, array(
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	                'not found'
337 337
 	            ));
338 338
 	        }
339
-	        $curOid = preg_replace('/\*/','\*',$curOid);
340
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
341
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
339
+	        $curOid=preg_replace('/\*/', '\*', $curOid);
340
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
341
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
342 342
 	        $index++;
343 343
 	    }
344 344
 	    return $curObjectList;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		$this->checkConfigPermission();
354 354
 		// set up tab
355 355
 		$this->prepareTabs();
356
-		$this->getTabs()->add('get',array(
356
+		$this->getTabs()->add('get', array(
357 357
 			'active'	=> true,
358 358
 			'label'		=> $this->translate('Add handler'),
359 359
 			'url'		=> Url::fromRequest()
@@ -365,11 +365,11 @@  discard block
 block discarded – undo
365 365
 		$this->view->mibList=$this->getMIB()->getMIBList();
366 366
 		
367 367
 		// Get categories
368
-		$this->view->categoryList = $this->getHandlersCategory();
368
+		$this->view->categoryList=$this->getHandlersCategory();
369 369
 		
370 370
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
371 371
 		
372
-		if (($trapid = $this->params->get('fromid')) !== null) {
372
+		if (($trapid=$this->params->get('fromid')) !== null) {
373 373
 		    /********** Setup from existing trap ***************/
374 374
             $this->add_from_existing($trapid);
375 375
 			return;
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 			$this->view->setRuleMatch=$ruleDetail->action_match;
390 390
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
391 391
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
392
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
392
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
393 393
 			$this->view->modifier=$ruleDetail->modifier;
394 394
 			
395
-			$this->view->comment = $ruleDetail->comment;
396
-			$this->view->category = $ruleDetail->category;
395
+			$this->view->comment=$ruleDetail->comment;
396
+			$this->view->category=$ruleDetail->category;
397 397
 			
398 398
 			// Warning message if host/service don't exists anymore
399 399
 			$this->view->warning_message='';
@@ -444,28 +444,28 @@  discard block
 block discarded – undo
444 444
 	
445 445
 		$params=array(
446 446
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
447
-			'hostgroup'		=>	array('post' => 'hostgroup',                    'db'=>false),
448
-			'db_rule'		=>	array('post' => 'db_rule',                      'db'=>false),
449
-			'hostid'		=>	array('post' => 'hostid',                       'db'=>false),
450
-			'host_name'		=>	array('post' => 'hostname',      'val' => null,  'db'=>true),
451
-			'host_group_name'=>	array('post' => null,            'val' => null,  'db'=>true),
452
-			'serviceid'		=>	array('post' => 'serviceid',                     'db'=>false),
453
-			'service_name'	=>	array('post' => 'serviceName',                    'db'=>true),
454
-		    'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
455
-		    'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
456
-			'trap_oid'		=>	array('post' => 'oid',                            'db'=>true),
457
-			'revert_ok'		=>	array('post' => 'revertOK',      'val' => 0,      'db'=>true),
458
-			'display'		=>	array('post' => 'display',        'val' => '',     'db'=>true),
459
-			'rule'			=>	array('post' => 'rule',          'val' => '',        'db'=>true),			
460
-			'action_match'	=>	array('post' => 'ruleMatch',       'val' => -1,    'db'=>true),
461
-			'action_nomatch'=>	array('post' => 'ruleNoMatch',    'val' => -1,    'db'=>true),					
462
-			'ip4'			=>	array('post' => null,             'val' => null,  'db'=>true),
463
-			'ip6'			=>	array('post' => null,             'val' => null,  'db'=>true),
464
-		    'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
447
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
448
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
449
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
450
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
451
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
452
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
453
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
454
+		    'comment'       =>  array('post' => 'comment', 'val' => '', 'db'=>true),
455
+		    'rule_type'     =>  array('post' => 'category', 'val' => 0, 'db'=>true),
456
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
457
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
458
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
459
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
460
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
461
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
462
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
463
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
464
+		    'action_form'	=>	array('post' => 'action_form', 'val' => null, 'db'=>false)
465 465
 		);
466 466
 		
467 467
 		if (isset($postData[$params['action_form']['post']]) 
468
-			&& $postData[$params['action_form']['post']] == 'delete' )
468
+			&& $postData[$params['action_form']['post']] == 'delete')
469 469
 		{
470 470
 			try
471 471
 			{
@@ -485,16 +485,16 @@  discard block
 block discarded – undo
485 485
 		}		
486 486
 		foreach (array_keys($params) as $key)
487 487
 		{
488
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
489
-			if (! isset($postData[$params[$key]['post']]))
488
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
489
+			if (!isset($postData[$params[$key]['post']]))
490 490
 			{
491 491
 				// should not happen as the js checks data
492
-				$this->_helper->json(array('status'=>'No ' . $key));
492
+				$this->_helper->json(array('status'=>'No '.$key));
493 493
 			}
494 494
 			else
495 495
 			{
496 496
 				$data=$postData[$params[$key]['post']];
497
-				if ($data!=null && $data !="")
497
+				if ($data != null && $data != "")
498 498
 				{
499 499
 					$params[$key]['val']=$postData[$params[$key]['post']];
500 500
 				}
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
 
504 504
 		try 
505 505
 		{
506
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
507
-			if (! $isHostGroup ) 
506
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
507
+			if (!$isHostGroup) 
508 508
 			{  // checks if selection by host 
509 509
 			    $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
510 510
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 				}
518 518
 				if (!is_numeric($params['serviceid']['val']))
519 519
 				{
520
-				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
520
+				    $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val']));
521 521
 				    return;
522 522
 				}
523 523
 				$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
@@ -536,15 +536,15 @@  discard block
 block discarded – undo
536 536
 					return;					
537 537
 				}
538 538
 				// Put param in correct column (group_name)
539
-				$params['host_group_name']['val'] = $params['host_name']['val'];
539
+				$params['host_group_name']['val']=$params['host_name']['val'];
540 540
 				$params['host_name']['val']=null;
541 541
 			}
542 542
 			$dbparams=array();
543 543
 			foreach ($params as $key=>$val)
544 544
 			{
545
-				if ($val['db']==true )
545
+				if ($val['db'] == true)
546 546
 				{
547
-					$dbparams[$key] = $val['val'];
547
+					$dbparams[$key]=$val['val'];
548 548
 				}
549 549
 			}
550 550
 			// echo '<br>';	print_r($dbparams);echo '<br>';
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 			}
556 556
 			else
557 557
 			{
558
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
558
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
559 559
 				$ruleID=$params['db_rule']['val'];
560 560
 			}
561 561
 		}
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
 	*/
575 575
 	protected function getTrapDetail($trapid) 
576 576
 	{
577
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
577
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
578 578
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
579 579
 		
580
-		$dbConn = $this->getUIDatabase()->getDbConn();
580
+		$dbConn=$this->getUIDatabase()->getDbConn();
581 581
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
582 582
 		// ***************  Get main data
583 583
 		// extract columns and titles;
@@ -587,19 +587,19 @@  discard block
 block discarded – undo
587 587
 		}
588 588
 		try
589 589
 		{		
590
-		    $query = $dbConn->select()
591
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
592
-				->where('id=?',$trapid);
590
+		    $query=$dbConn->select()
591
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
592
+				->where('id=?', $trapid);
593 593
 				$trapDetail=$dbConn->fetchRow($query);
594
-			if ( $trapDetail == null ) 
594
+			if ($trapDetail == null) 
595 595
 			{
596
-			    $trapDetail = 'NULL';
596
+			    $trapDetail='NULL';
597 597
 			    throw new Exception('No traps was found with id = '.$trapid);
598 598
 			}
599 599
 		}
600 600
 		catch (Exception $e)
601 601
 		{
602
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
602
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
603 603
 			return;
604 604
 		}
605 605
 
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
 	*/
614 614
 	protected function getTrapobjects($trapid)
615 615
 	{	
616
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
616
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
617 617
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
618 618
 		
619
-		$dbConn = $this->getUIDatabase()->getDbConn();
619
+		$dbConn=$this->getUIDatabase()->getDbConn();
620 620
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
621 621
 		// ***************  Get object data
622 622
 		// extract columns and titles;
@@ -626,15 +626,15 @@  discard block
 block discarded – undo
626 626
 		}
627 627
 		try
628 628
 		{		
629
-		    $query = $dbConn->select()
630
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
631
-				->where('trap_id=?',$trapid);
629
+		    $query=$dbConn->select()
630
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
631
+				->where('trap_id=?', $trapid);
632 632
 				$trapDetail=$dbConn->fetchAll($query);
633 633
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
634 634
 		}
635 635
 		catch (Exception $e)
636 636
 		{
637
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
637
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
638 638
 			return array();
639 639
 		}
640 640
 
@@ -648,24 +648,24 @@  discard block
 block discarded – undo
648 648
 	*/
649 649
 	protected function getRuleDetail($ruleid) 
650 650
 	{
651
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
651
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
652 652
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
653 653
 		
654
-		$dbConn = $this->getUIDatabase()->getDbConn();
654
+		$dbConn=$this->getUIDatabase()->getDbConn();
655 655
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
656 656
 		// ***************  Get main data
657 657
 		try
658 658
 		{		
659
-		    $query = $dbConn->select()
660
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
661
-				->where('id=?',$ruleid);
659
+		    $query=$dbConn->select()
660
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
661
+				->where('id=?', $ruleid);
662 662
 			$ruleDetail=$dbConn->fetchRow($query);
663
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
663
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
664 664
 		}
665 665
 		catch (Exception $e)
666 666
 		{
667
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
668
-			throw new Exception('Error : ' . $e->getMessage());
667
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
668
+			throw new Exception('Error : '.$e->getMessage());
669 669
 		}
670 670
 
671 671
 		return $ruleDetail;
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 	{
679 679
 		return $this->getTabs()->add('status', array(
680 680
 			'label' => $this->translate('Trap handlers'),
681
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
681
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
682 682
 		);
683 683
 	} 
684 684
 	
Please login to merge, or discard this patch.
Braces   +44 added lines, -42 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 		$this->prepareTabs()->activate('status');
26 26
 
27 27
 		$dbConn = $this->getUIDatabase()->getDb();
28
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28
+		if ($dbConn === null) {
29
+			throw new \ErrorException('uncatched db error');
30
+		}
29 31
 		
30 32
 		$handlerTable = new HandlerTable(
31 33
 		      $this->moduleConfig->getTrapRuleName(),
@@ -84,8 +86,7 @@  discard block
 block discarded – undo
84 86
 	    if ($this->params->get('rule') !== null) 
85 87
 	    {
86 88
 	        $this->view->rule= $this->params->get('rule');
87
-	    }
88
-	    else
89
+	    } else
89 90
 	    {
90 91
 	        $this->view->rule='';
91 92
 	    }
@@ -139,8 +140,7 @@  discard block
 block discarded – undo
139 140
 	    try
140 141
 	    {
141 142
 	        $hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
142
-	    }
143
-	    catch (Exception $e)
143
+	    } catch (Exception $e)
144 144
 	    {
145 145
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
146 146
 	    }
@@ -153,8 +153,7 @@  discard block
 block discarded – undo
153 153
 	        // Tell JS to get services when page is loaded
154 154
 	        $this->view->serviceGet=true;
155 155
 	        
156
-	    }
157
-	    else
156
+	    } else
158 157
 	    {
159 158
 	        foreach($hosts as $key=>$val)
160 159
 	        {
@@ -204,11 +203,14 @@  discard block
 block discarded – undo
204 203
 	            $allObjects[$val->oid]=null;
205 204
 	        }
206 205
 	    }
207
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
206
+	    if ($allObjects!=null) {
207
+	    	// in case trap doesn't have objects or is not resolved
208 208
 	    {
209 209
 	        foreach ($allObjects as $key => $val)
210 210
 	        {
211
-	            if ($val==null) { continue; }
211
+	            if ($val==null) { continue;
212
+	    }
213
+	    }
212 214
 	            array_push($this->view->objectList, array(
213 215
 	                $oid_index,
214 216
 	                $key,
@@ -240,8 +242,7 @@  discard block
 block discarded – undo
240 242
 	    {
241 243
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
242 244
 	        $this->view->serviceGet=false;
243
-	    }
244
-	    else
245
+	    } else
245 246
 	    {
246 247
 	        // Tell JS to get services when page is loaded
247 248
 	        $this->view->serviceGet=true;
@@ -250,8 +251,7 @@  discard block
 block discarded – undo
250 251
 	        if (count($serviceID) ==0)
251 252
 	        {
252 253
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
253
-	        }
254
-	        else
254
+	        } else
255 255
 	        {
256 256
 	            $this->view->serviceSet=$serviceID[0]->id;
257 257
 	        }
@@ -270,8 +270,7 @@  discard block
 block discarded – undo
270 270
 	    {
271 271
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
272 272
 	        $this->view->serviceGroupGet=false;
273
-	    }
274
-	    else
273
+	    } else
275 274
 	    {
276 275
 	        $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
277 276
 	        $foundGrpService=0;
@@ -323,8 +322,7 @@  discard block
 block discarded – undo
323 322
 	                $object['type'],
324 323
 	                $object['type_enum']
325 324
 	            ));
326
-	        }
327
-	        else
325
+	        } else
328 326
 	        {
329 327
 	            array_push($curObjectList, array(
330 328
 	                $index,
@@ -402,8 +400,7 @@  discard block
 block discarded – undo
402 400
 			    $this->view->selectGroup=false;
403 401
 			    // Check if hostname still exists
404 402
 			    $this->add_check_host_exists($ruleDetail);
405
-			}
406
-			else
403
+			} else
407 404
 			{
408 405
 			    $this->view->selectGroup=true;
409 406
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -411,9 +408,11 @@  discard block
 block discarded – undo
411 408
 			
412 409
 			$this->view->mainoid=$ruleDetail->trap_oid;
413 410
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
414
-			if ($oidName != null)  // oid is found in mibs
411
+			if ($oidName != null) {
412
+				// oid is found in mibs
415 413
 			{
416
-				$this->view->mib=$oidName['mib']; 
414
+				$this->view->mib=$oidName['mib'];
415
+			}
417 416
 				$this->view->name=$oidName['name'];
418 417
 				$this->view->trapListForMIB=$this->getMIB()
419 418
 					->getTrapList($oidName['mib']);				
@@ -470,8 +469,7 @@  discard block
 block discarded – undo
470 469
 			try
471 470
 			{
472 471
 			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
473
-			}
474
-			catch (Exception $e)
472
+			} catch (Exception $e)
475 473
 			{
476 474
 				$this->_helper->json(array('status'=>$e->getMessage()));
477 475
 				return;
@@ -485,13 +483,15 @@  discard block
 block discarded – undo
485 483
 		}		
486 484
 		foreach (array_keys($params) as $key)
487 485
 		{
488
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
486
+			if ($params[$key]['post']==null) {
487
+				continue;
488
+			}
489
+			// data not sent in post vars
489 490
 			if (! isset($postData[$params[$key]['post']]))
490 491
 			{
491 492
 				// should not happen as the js checks data
492 493
 				$this->_helper->json(array('status'=>'No ' . $key));
493
-			}
494
-			else
494
+			} else
495 495
 			{
496 496
 				$data=$postData[$params[$key]['post']];
497 497
 				if ($data!=null && $data !="")
@@ -526,8 +526,7 @@  discard block
 block discarded – undo
526 526
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
527 527
 					return;
528 528
 				}
529
-			}
530
-			else
529
+			} else
531 530
 			{
532 531
 			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
533 532
 				if ($params['host_name']['val'] != $object->name1)
@@ -552,14 +551,12 @@  discard block
 block discarded – undo
552 551
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
553 552
 			{  // If no rule number or action is clone, add the handler
554 553
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
555
-			}
556
-			else
554
+			} else
557 555
 			{
558 556
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
559 557
 				$ruleID=$params['db_rule']['val'];
560 558
 			}
561
-		}
562
-		catch (Exception $e)
559
+		} catch (Exception $e)
563 560
 		{
564 561
 			$this->_helper->json(array('status'=>$e->getMessage()));
565 562
 			return;
@@ -578,7 +575,9 @@  discard block
 block discarded – undo
578 575
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
579 576
 		
580 577
 		$dbConn = $this->getUIDatabase()->getDbConn();
581
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
578
+		if ($dbConn === null) {
579
+			throw new \ErrorException('uncatched db error');
580
+		}
582 581
 		// ***************  Get main data
583 582
 		// extract columns and titles;
584 583
 		$elmts=NULL;
@@ -596,8 +595,7 @@  discard block
 block discarded – undo
596 595
 			    $trapDetail = 'NULL';
597 596
 			    throw new Exception('No traps was found with id = '.$trapid);
598 597
 			}
599
-		}
600
-		catch (Exception $e)
598
+		} catch (Exception $e)
601 599
 		{
602 600
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
603 601
 			return;
@@ -617,7 +615,9 @@  discard block
 block discarded – undo
617 615
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
618 616
 		
619 617
 		$dbConn = $this->getUIDatabase()->getDbConn();
620
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
618
+		if ($dbConn === null) {
619
+			throw new \ErrorException('uncatched db error');
620
+		}
621 621
 		// ***************  Get object data
622 622
 		// extract columns and titles;
623 623
 		$data_elmts=NULL;
@@ -631,8 +631,7 @@  discard block
 block discarded – undo
631 631
 				->where('trap_id=?',$trapid);
632 632
 				$trapDetail=$dbConn->fetchAll($query);
633 633
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
634
-		}
635
-		catch (Exception $e)
634
+		} catch (Exception $e)
636 635
 		{
637 636
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
638 637
 			return array();
@@ -652,7 +651,9 @@  discard block
 block discarded – undo
652 651
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
653 652
 		
654 653
 		$dbConn = $this->getUIDatabase()->getDbConn();
655
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
654
+		if ($dbConn === null) {
655
+			throw new \ErrorException('uncatched db error');
656
+		}
656 657
 		// ***************  Get main data
657 658
 		try
658 659
 		{		
@@ -660,9 +661,10 @@  discard block
 block discarded – undo
660 661
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
661 662
 				->where('id=?',$ruleid);
662 663
 			$ruleDetail=$dbConn->fetchRow($query);
663
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
664
-		}
665
-		catch (Exception $e)
664
+			if ( $ruleDetail == null ) {
665
+				throw new Exception('No rule was found with id = '.$ruleid);
666
+			}
667
+		} catch (Exception $e)
666 668
 		{
667 669
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
668 670
 			throw new Exception('Error : ' . $e->getMessage());
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTableFilter.php 3 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@  discard block
 block discarded – undo
8 8
     
9 9
     /********* Filter ********/
10 10
     /** @var string $filterString : string filter for db columns */
11
-    protected $filterString = '';
11
+    protected $filterString='';
12 12
     
13 13
     /** @var array $filterColumn : columns to apply filter to */
14
-    protected $filterColumn = array();
14
+    protected $filterColumn=array();
15 15
     
16 16
     protected $filterQuery='';
17 17
     
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         {
30 30
             if ($filter != "") $filter.=' OR ';
31 31
             //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
32
-            $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
32
+            $filter.=$column." LIKE '%".$this->filterString."%'";
33 33
         }
34 34
         //echo $filter;
35 35
         
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 
41 41
     public function setFilter(string $filter, array $filterCol)
42 42
     {
43
-        $this->filterString = $filter;
44
-        $this->filterColumn = $filterCol;
43
+        $this->filterString=$filter;
44
+        $this->filterColumn=$filterCol;
45 45
         return $this;
46 46
     }
47 47
    
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         if (isset($getVars['f']))
65 65
         {
66
-            $this->filterQuery = $getVars['f'];
66
+            $this->filterQuery=$getVars['f'];
67 67
             $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
68 68
         }
69 69
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
         $filter='';
28 28
         foreach ($this->filterColumn as $column)
29 29
         {
30
-            if ($filter != "") $filter.=' OR ';
30
+            if ($filter != "") {
31
+            	$filter.=' OR ';
32
+            }
31 33
             //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
32 34
             $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
33 35
         }
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
     
71 73
     protected function curFilterQuery()
72 74
     {
73
-        if ($this->filterQuery == '') return '';
75
+        if ($this->filterQuery == '') {
76
+        	return '';
77
+        }
74 78
         return 'f='.$this->filterQuery;
75 79
     }
76 80
     
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,75 +6,75 @@
 block discarded – undo
6 6
 trait TrapDirectorTableFilter
7 7
 {
8 8
     
9
-    /********* Filter ********/
10
-    /** @var string $filterString : string filter for db columns */
11
-    protected $filterString = '';
9
+	/********* Filter ********/
10
+	/** @var string $filterString : string filter for db columns */
11
+	protected $filterString = '';
12 12
     
13
-    /** @var array $filterColumn : columns to apply filter to */
14
-    protected $filterColumn = array();
13
+	/** @var array $filterColumn : columns to apply filter to */
14
+	protected $filterColumn = array();
15 15
     
16
-    protected $filterQuery='';
16
+	protected $filterQuery='';
17 17
     
18
-    /**** var & func of TrapDirectorTable used ***/
19
-    protected $query;
20
-    abstract protected function getCurrentURLAndQS(string $caller);
18
+	/**** var & func of TrapDirectorTable used ***/
19
+	protected $query;
20
+	abstract protected function getCurrentURLAndQS(string $caller);
21 21
     
22
-    /**************** Filtering ******************/
22
+	/**************** Filtering ******************/
23 23
     
24
-    public function applyFilter()
25
-    {
26
-        if ($this->filterString == '' || count($this->filterColumn) == 0)
27
-        {
28
-            return $this;
29
-        }
30
-        $filter='';
31
-        foreach ($this->filterColumn as $column)
32
-        {
33
-            if ($filter != "") $filter.=' OR ';
34
-            //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
35
-            $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
36
-        }
37
-        //echo $filter;
24
+	public function applyFilter()
25
+	{
26
+		if ($this->filterString == '' || count($this->filterColumn) == 0)
27
+		{
28
+			return $this;
29
+		}
30
+		$filter='';
31
+		foreach ($this->filterColumn as $column)
32
+		{
33
+			if ($filter != "") $filter.=' OR ';
34
+			//$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
35
+			$filter .= $column  . " LIKE '%" . $this->filterString. "%'";
36
+		}
37
+		//echo $filter;
38 38
         
39
-        $this->query=$this->query->where($filter);
39
+		$this->query=$this->query->where($filter);
40 40
 
41
-        return $this;
42
-    }
41
+		return $this;
42
+	}
43 43
 
44
-    public function setFilter(string $filter, array $filterCol)
45
-    {
46
-        $this->filterString = $filter;
47
-        $this->filterColumn = $filterCol;
48
-        return $this;
49
-    }
44
+	public function setFilter(string $filter, array $filterCol)
45
+	{
46
+		$this->filterString = $filter;
47
+		$this->filterColumn = $filterCol;
48
+		return $this;
49
+	}
50 50
    
51
-    public function renderFilter()
52
-    {
51
+	public function renderFilter()
52
+	{
53 53
         
54
-        $html=' <form id="genfilter" name="mainFilterGen"
54
+		$html=' <form id="genfilter" name="mainFilterGen"
55 55
 			enctype="application/x-www-form-urlencoded"
56 56
 			action="'.$this->getCurrentURLAndQS('filter').'"
57 57
 			method="get">';
58
-        $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words"
58
+		$html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words"
59 59
 	placeholder="Search..."  value="'.$this->filterQuery.'">';
60 60
 
61
-        $html.='</form>';
62
-        return $html;
63
-    }
61
+		$html.='</form>';
62
+		return $html;
63
+	}
64 64
  
65
-    public function getFilterQuery(array $getVars)
66
-    {
67
-        if (isset($getVars['f']))
68
-        {
69
-            $this->filterQuery = $getVars['f'];
70
-            $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
71
-        }
72
-    }
65
+	public function getFilterQuery(array $getVars)
66
+	{
67
+		if (isset($getVars['f']))
68
+		{
69
+			$this->filterQuery = $getVars['f'];
70
+			$this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
71
+		}
72
+	}
73 73
     
74
-    protected function curFilterQuery()
75
-    {
76
-        if ($this->filterQuery == '') return '';
77
-        return 'f='.$this->filterQuery;
78
-    }
74
+	protected function curFilterQuery()
75
+	{
76
+		if ($this->filterQuery == '') return '';
77
+		return 'f='.$this->filterQuery;
78
+	}
79 79
     
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTable.php 3 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -6,195 +6,195 @@
 block discarded – undo
6 6
 abstract class TrapDirectorTable
7 7
 {
8 8
     
9
-    use TrapDirectorTableFilter;
10
-    use TrapDirectorTablePaging;
11
-    use TrapDirectorTableOrder;
12
-    use TrapDirectorTableGrouping;
9
+	use TrapDirectorTableFilter;
10
+	use TrapDirectorTablePaging;
11
+	use TrapDirectorTableOrder;
12
+	use TrapDirectorTableGrouping;
13 13
     
14
-    /** @var array $titles table titles (name, display value) */
15
-    protected $titles = null;
14
+	/** @var array $titles table titles (name, display value) */
15
+	protected $titles = null;
16 16
 
17
-    /** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
18
-    protected $content = null;
17
+	/** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
18
+	protected $content = null;
19 19
     
20
-    /** @var array $columnNames names of columns for filtering */
21
-    protected $columnNames = array();
20
+	/** @var array $columnNames names of columns for filtering */
21
+	protected $columnNames = array();
22 22
     
23
-    /** @var mixed $dbConn connection to database  */
24
-    protected $dbConn = null;
23
+	/** @var mixed $dbConn connection to database  */
24
+	protected $dbConn = null;
25 25
     
26
-    /** Current view **/
27
-    protected $view;
26
+	/** Current view **/
27
+	protected $view;
28 28
     
29
-    protected $urlPath;
29
+	protected $urlPath;
30 30
     
31
-    // Database stuff
31
+	// Database stuff
32 32
    /** @var array $table (db ref, name) */
33
-    protected $table = array();
34
-    
35
-    /** @var mixed  $query Query in database; */
36
-    protected $query = null;
37
-    
38
-    function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
39
-    {
40
-        $this->table = $table;
41
-        $this->titles = $titles;
42
-        $this->content = $columns;
43
-        $this->columnNames = $columnNames;
44
-        $this->dbConn = $dbConn;
33
+	protected $table = array();
34
+    
35
+	/** @var mixed  $query Query in database; */
36
+	protected $query = null;
37
+    
38
+	function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
39
+	{
40
+		$this->table = $table;
41
+		$this->titles = $titles;
42
+		$this->content = $columns;
43
+		$this->columnNames = $columnNames;
44
+		$this->dbConn = $dbConn;
45 45
         
46
-        $this->view = $view;
47
-        $this->urlPath = $urlPath;
46
+		$this->view = $view;
47
+		$this->urlPath = $urlPath;
48 48
         
49
-        return $this;
50
-    }
49
+		return $this;
50
+	}
51 51
 
52 52
     
53
-    /************** GET variables and URLs *************/
54
-    public function getParams(array $getVars)
55
-    {
56
-        $this->getFilterQuery($getVars);
57
-        $this->getPagingQuery($getVars);
58
-        $this->getOrderQuery($getVars);
59
-    }
60
-    
61
-    public function getCurrentURL()
62
-    {
63
-        return '?';
64
-    }
65
-    
66
-    protected function getCurrentURLAndQS(string $caller)
67
-    {
68
-        $actionURL = $this->getCurrentURL() . '?' ;
69
-        $QSList=array();
70
-        if ($caller != 'filter' && $this->curFilterQuery() != '')
71
-            array_push($QSList , $this->curFilterQuery());
53
+	/************** GET variables and URLs *************/
54
+	public function getParams(array $getVars)
55
+	{
56
+		$this->getFilterQuery($getVars);
57
+		$this->getPagingQuery($getVars);
58
+		$this->getOrderQuery($getVars);
59
+	}
60
+    
61
+	public function getCurrentURL()
62
+	{
63
+		return '?';
64
+	}
65
+    
66
+	protected function getCurrentURLAndQS(string $caller)
67
+	{
68
+		$actionURL = $this->getCurrentURL() . '?' ;
69
+		$QSList=array();
70
+		if ($caller != 'filter' && $this->curFilterQuery() != '')
71
+			array_push($QSList , $this->curFilterQuery());
72 72
         
73
-        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
74
-            array_push($QSList , $this->curPagingQuery());
73
+		if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
74
+			array_push($QSList , $this->curPagingQuery());
75 75
  
76
-        if ($caller != 'order' && $this->curOrderQuery() != '')
77
-            array_push($QSList , $this->curOrderQuery());
76
+		if ($caller != 'order' && $this->curOrderQuery() != '')
77
+			array_push($QSList , $this->curOrderQuery());
78 78
         
79
-        if (count($QSList) != 0)
80
-            $actionURL .=  implode('&', $QSList) . '&';
79
+		if (count($QSList) != 0)
80
+			$actionURL .=  implode('&', $QSList) . '&';
81 81
         
82
-        return $actionURL;
83
-    }
84
-    
85
-    /************* DB queries ******************/
86
-    /**
87
-     * Get base query in $this->query
88
-     * @return  TrapDirectorTable
89
-     */
90
-    public function getBaseQuery()
91
-    {
92
-        $this->query = $this->dbConn->select();
93
-        $this->query = $this->query->from(
94
-            $this->table,
95
-            $this->content
96
-            );
82
+		return $actionURL;
83
+	}
84
+    
85
+	/************* DB queries ******************/
86
+	/**
87
+	 * Get base query in $this->query
88
+	 * @return  TrapDirectorTable
89
+	 */
90
+	public function getBaseQuery()
91
+	{
92
+		$this->query = $this->dbConn->select();
93
+		$this->query = $this->query->from(
94
+			$this->table,
95
+			$this->content
96
+			);
97 97
         
98
-        return $this;
99
-    }
100
-    
101
-    public function fullQuery()
102
-    {
103
-        $this->getBaseQuery()
104
-        ->applyFilter()
105
-        ->applyPaging()
106
-        ->applyOrder();
98
+		return $this;
99
+	}
100
+    
101
+	public function fullQuery()
102
+	{
103
+		$this->getBaseQuery()
104
+		->applyFilter()
105
+		->applyPaging()
106
+		->applyOrder();
107 107
         
108
-        return $this->dbConn->fetchAll($this->query);
109
-        //return $this->query->fetchAll();
110
-    }
108
+		return $this->dbConn->fetchAll($this->query);
109
+		//return $this->query->fetchAll();
110
+	}
111 111
      
112
-    /*************** Rendering *************************/
113
-    
114
-    public function titleOrder($name)
115
-    {
116
-        return $this->content[$name];
117
-    }
118
-    
119
-    public function renderTitles()
120
-    {
121
-        $html = "<thead>\n<tr>\n";
122
-        foreach ($this->titles as $name => $values)
123
-        {
124
-            $titleOrder = $this->titleOrder($name);  // TODO : put this as function of order trait
125
-            if ($titleOrder != NULL)
126
-            {
127
-                if (isset($this->order[$titleOrder]))
128
-                {
129
-                    if ($this->order[$titleOrder] == 'ASC')
130
-                    {
131
-                        $titleOrder.='DESC';
132
-                    }
133
-                    else
134
-                    {
135
-                        $titleOrder.='ASC';
136
-                    }
137
-                }
138
-                else 
139
-                {
140
-                    $titleOrder.='ASC';
141
-                }
142
-                $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
143
-                $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
144
-            }
145
-            else 
146
-            {
147
-                $html .= '<th>' . $values . '</th>';
148
-            }          
149
-        }
150
-        $html .= "</tr>\n</thead>\n";
151
-        return $html;
152
-    }
153
-    
154
-    public function renderLine( $value)
155
-    {
156
-        $html = '';
157
-        $titleNames = array_keys($this->titles);
158
-        foreach ($titleNames as $name )
159
-        {
160
-            $html .= '<td>';
161
-            $html .= $value->$name;
162
-            $html .= "</td>\n";
163
-        }
164
-        return $html;
165
-    }
166
-    
167
-    public function renderTable(array $values)
168
-    {
169
-       $html = '<tbody id="obj_table_body">';
170
-       foreach($values as $value)
171
-       {
172
-           $html .= $this->groupingNextLine($value);
112
+	/*************** Rendering *************************/
113
+    
114
+	public function titleOrder($name)
115
+	{
116
+		return $this->content[$name];
117
+	}
118
+    
119
+	public function renderTitles()
120
+	{
121
+		$html = "<thead>\n<tr>\n";
122
+		foreach ($this->titles as $name => $values)
123
+		{
124
+			$titleOrder = $this->titleOrder($name);  // TODO : put this as function of order trait
125
+			if ($titleOrder != NULL)
126
+			{
127
+				if (isset($this->order[$titleOrder]))
128
+				{
129
+					if ($this->order[$titleOrder] == 'ASC')
130
+					{
131
+						$titleOrder.='DESC';
132
+					}
133
+					else
134
+					{
135
+						$titleOrder.='ASC';
136
+					}
137
+				}
138
+				else 
139
+				{
140
+					$titleOrder.='ASC';
141
+				}
142
+				$actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
143
+				$html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
144
+			}
145
+			else 
146
+			{
147
+				$html .= '<th>' . $values . '</th>';
148
+			}          
149
+		}
150
+		$html .= "</tr>\n</thead>\n";
151
+		return $html;
152
+	}
153
+    
154
+	public function renderLine( $value)
155
+	{
156
+		$html = '';
157
+		$titleNames = array_keys($this->titles);
158
+		foreach ($titleNames as $name )
159
+		{
160
+			$html .= '<td>';
161
+			$html .= $value->$name;
162
+			$html .= "</td>\n";
163
+		}
164
+		return $html;
165
+	}
166
+    
167
+	public function renderTable(array $values)
168
+	{
169
+	   $html = '<tbody id="obj_table_body">';
170
+	   foreach($values as $value)
171
+	   {
172
+		   $html .= $this->groupingNextLine($value);
173 173
            
174
-           $html .= "<tr>\n";
175
-           $html .= $this->renderLine($value);
176
-           $html .= "</tr>\n";
177
-       }
178
-       $html .= '</tbody>';
179
-       return $html;
180
-    }
181
-    
182
-    public function render()
183
-    {
184
-        $html = '';
174
+		   $html .= "<tr>\n";
175
+		   $html .= $this->renderLine($value);
176
+		   $html .= "</tr>\n";
177
+	   }
178
+	   $html .= '</tbody>';
179
+	   return $html;
180
+	}
181
+    
182
+	public function render()
183
+	{
184
+		$html = '';
185 185
         
186 186
         
187
-        $values = $this->fullQuery();
188
-        $this->initGrouping();
187
+		$values = $this->fullQuery();
188
+		$this->initGrouping();
189 189
         
190
-        $html.="<table class='simple common-table table-row-selectable'>\n";
190
+		$html.="<table class='simple common-table table-row-selectable'>\n";
191 191
         
192
-        $html .= $this->renderTitles();
193
-        $html .= $this->renderTable($values);
194
-        $html .= '</table>'; 
192
+		$html .= $this->renderTitles();
193
+		$html .= $this->renderTable($values);
194
+		$html .= '</table>'; 
195 195
         
196 196
 
197
-        return $html;
198
-    }
197
+		return $html;
198
+	}
199 199
     
200 200
 }
201 201
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,16 +12,16 @@  discard block
 block discarded – undo
12 12
     use TrapDirectorTableGrouping;
13 13
     
14 14
     /** @var array $titles table titles (name, display value) */
15
-    protected $titles = null;
15
+    protected $titles=null;
16 16
 
17 17
     /** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
18
-    protected $content = null;
18
+    protected $content=null;
19 19
     
20 20
     /** @var array $columnNames names of columns for filtering */
21
-    protected $columnNames = array();
21
+    protected $columnNames=array();
22 22
     
23 23
     /** @var mixed $dbConn connection to database  */
24
-    protected $dbConn = null;
24
+    protected $dbConn=null;
25 25
     
26 26
     /** Current view **/
27 27
     protected $view;
@@ -30,21 +30,21 @@  discard block
 block discarded – undo
30 30
     
31 31
     // Database stuff
32 32
    /** @var array $table (db ref, name) */
33
-    protected $table = array();
33
+    protected $table=array();
34 34
     
35 35
     /** @var mixed  $query Query in database; */
36
-    protected $query = null;
36
+    protected $query=null;
37 37
     
38
-    function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
38
+    function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath)
39 39
     {
40
-        $this->table = $table;
41
-        $this->titles = $titles;
42
-        $this->content = $columns;
43
-        $this->columnNames = $columnNames;
44
-        $this->dbConn = $dbConn;
40
+        $this->table=$table;
41
+        $this->titles=$titles;
42
+        $this->content=$columns;
43
+        $this->columnNames=$columnNames;
44
+        $this->dbConn=$dbConn;
45 45
         
46
-        $this->view = $view;
47
-        $this->urlPath = $urlPath;
46
+        $this->view=$view;
47
+        $this->urlPath=$urlPath;
48 48
         
49 49
         return $this;
50 50
     }
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
     
66 66
     protected function getCurrentURLAndQS(string $caller)
67 67
     {
68
-        $actionURL = $this->getCurrentURL() . '?' ;
68
+        $actionURL=$this->getCurrentURL().'?';
69 69
         $QSList=array();
70 70
         if ($caller != 'filter' && $this->curFilterQuery() != '')
71
-            array_push($QSList , $this->curFilterQuery());
71
+            array_push($QSList, $this->curFilterQuery());
72 72
         
73 73
         if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
74
-            array_push($QSList , $this->curPagingQuery());
74
+            array_push($QSList, $this->curPagingQuery());
75 75
  
76 76
         if ($caller != 'order' && $this->curOrderQuery() != '')
77
-            array_push($QSList , $this->curOrderQuery());
77
+            array_push($QSList, $this->curOrderQuery());
78 78
         
79 79
         if (count($QSList) != 0)
80
-            $actionURL .=  implode('&', $QSList) . '&';
80
+            $actionURL.=implode('&', $QSList).'&';
81 81
         
82 82
         return $actionURL;
83 83
     }
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function getBaseQuery()
91 91
     {
92
-        $this->query = $this->dbConn->select();
93
-        $this->query = $this->query->from(
92
+        $this->query=$this->dbConn->select();
93
+        $this->query=$this->query->from(
94 94
             $this->table,
95 95
             $this->content
96 96
             );
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
     
119 119
     public function renderTitles()
120 120
     {
121
-        $html = "<thead>\n<tr>\n";
121
+        $html="<thead>\n<tr>\n";
122 122
         foreach ($this->titles as $name => $values)
123 123
         {
124
-            $titleOrder = $this->titleOrder($name);  // TODO : put this as function of order trait
124
+            $titleOrder=$this->titleOrder($name); // TODO : put this as function of order trait
125 125
             if ($titleOrder != NULL)
126 126
             {
127 127
                 if (isset($this->order[$titleOrder]))
@@ -139,59 +139,59 @@  discard block
 block discarded – undo
139 139
                 {
140 140
                     $titleOrder.='ASC';
141 141
                 }
142
-                $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
143
-                $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
142
+                $actionURL=$this->getCurrentURLAndQS('order').'o='.$titleOrder;
143
+                $html.='<th><a href="'.$actionURL.'">'.$values.'</a></th>';
144 144
             }
145 145
             else 
146 146
             {
147
-                $html .= '<th>' . $values . '</th>';
147
+                $html.='<th>'.$values.'</th>';
148 148
             }          
149 149
         }
150
-        $html .= "</tr>\n</thead>\n";
150
+        $html.="</tr>\n</thead>\n";
151 151
         return $html;
152 152
     }
153 153
     
154
-    public function renderLine( $value)
154
+    public function renderLine($value)
155 155
     {
156
-        $html = '';
157
-        $titleNames = array_keys($this->titles);
158
-        foreach ($titleNames as $name )
156
+        $html='';
157
+        $titleNames=array_keys($this->titles);
158
+        foreach ($titleNames as $name)
159 159
         {
160
-            $html .= '<td>';
161
-            $html .= $value->$name;
162
-            $html .= "</td>\n";
160
+            $html.='<td>';
161
+            $html.=$value->$name;
162
+            $html.="</td>\n";
163 163
         }
164 164
         return $html;
165 165
     }
166 166
     
167 167
     public function renderTable(array $values)
168 168
     {
169
-       $html = '<tbody id="obj_table_body">';
170
-       foreach($values as $value)
169
+       $html='<tbody id="obj_table_body">';
170
+       foreach ($values as $value)
171 171
        {
172
-           $html .= $this->groupingNextLine($value);
172
+           $html.=$this->groupingNextLine($value);
173 173
            
174
-           $html .= "<tr>\n";
175
-           $html .= $this->renderLine($value);
176
-           $html .= "</tr>\n";
174
+           $html.="<tr>\n";
175
+           $html.=$this->renderLine($value);
176
+           $html.="</tr>\n";
177 177
        }
178
-       $html .= '</tbody>';
178
+       $html.='</tbody>';
179 179
        return $html;
180 180
     }
181 181
     
182 182
     public function render()
183 183
     {
184
-        $html = '';
184
+        $html='';
185 185
         
186 186
         
187
-        $values = $this->fullQuery();
187
+        $values=$this->fullQuery();
188 188
         $this->initGrouping();
189 189
         
190 190
         $html.="<table class='simple common-table table-row-selectable'>\n";
191 191
         
192
-        $html .= $this->renderTitles();
193
-        $html .= $this->renderTable($values);
194
-        $html .= '</table>'; 
192
+        $html.=$this->renderTitles();
193
+        $html.=$this->renderTable($values);
194
+        $html.='</table>'; 
195 195
         
196 196
 
197 197
         return $html;
Please login to merge, or discard this patch.
Braces   +15 added lines, -14 removed lines patch added patch discarded remove patch
@@ -67,17 +67,21 @@  discard block
 block discarded – undo
67 67
     {
68 68
         $actionURL = $this->getCurrentURL() . '?' ;
69 69
         $QSList=array();
70
-        if ($caller != 'filter' && $this->curFilterQuery() != '')
71
-            array_push($QSList , $this->curFilterQuery());
70
+        if ($caller != 'filter' && $this->curFilterQuery() != '') {
71
+                    array_push($QSList , $this->curFilterQuery());
72
+        }
72 73
         
73
-        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
74
-            array_push($QSList , $this->curPagingQuery());
74
+        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') {
75
+                    array_push($QSList , $this->curPagingQuery());
76
+        }
75 77
  
76
-        if ($caller != 'order' && $this->curOrderQuery() != '')
77
-            array_push($QSList , $this->curOrderQuery());
78
+        if ($caller != 'order' && $this->curOrderQuery() != '') {
79
+                    array_push($QSList , $this->curOrderQuery());
80
+        }
78 81
         
79
-        if (count($QSList) != 0)
80
-            $actionURL .=  implode('&', $QSList) . '&';
82
+        if (count($QSList) != 0) {
83
+                    $actionURL .=  implode('&', $QSList) . '&';
84
+        }
81 85
         
82 86
         return $actionURL;
83 87
     }
@@ -129,20 +133,17 @@  discard block
 block discarded – undo
129 133
                     if ($this->order[$titleOrder] == 'ASC')
130 134
                     {
131 135
                         $titleOrder.='DESC';
132
-                    }
133
-                    else
136
+                    } else
134 137
                     {
135 138
                         $titleOrder.='ASC';
136 139
                     }
137
-                }
138
-                else 
140
+                } else 
139 141
                 {
140 142
                     $titleOrder.='ASC';
141 143
                 }
142 144
                 $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
143 145
                 $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
144
-            }
145
-            else 
146
+            } else 
146 147
             {
147 148
                 $html .= '<th>' . $values . '</th>';
148 149
             }          
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTablePaging.php 3 patches
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
     protected function curPagingQuery()
48 48
     {
49
-        if ($this->currentPage == '') return '';
49
+        if ($this->currentPage == '') {
50
+        	return '';
51
+        }
50 52
         return 'page='.$this->currentPage;
51 53
     }
52 54
     
@@ -58,10 +60,14 @@  discard block
 block discarded – undo
58 60
             return  'count : ' . $this->count() . '<br>';
59 61
         }
60 62
         
61
-        if ($this->currentPage == 0) $this->currentPage = 1;
63
+        if ($this->currentPage == 0) {
64
+        	$this->currentPage = 1;
65
+        }
62 66
         
63 67
         $numPages = intdiv($count , $this->maxPerPage);
64
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
68
+        if ($count % $this->maxPerPage != 0 ) {
69
+        	$numPages++;
70
+        }
65 71
         
66 72
         $html = '<div class="pagination-control" role="navigation">';
67 73
         $html .= '<ul class="nav tab-nav">';
@@ -75,8 +81,7 @@  discard block
 block discarded – undo
75 81
                      </span>
76 82
                 </li>
77 83
                ';
78
-        }
79
-        else 
84
+        } else 
80 85
         {
81 86
             $html .= '
82 87
                 <li class="nav-item">
@@ -92,7 +97,9 @@  discard block
 block discarded – undo
92 97
             $active = ($this->currentPage == $i) ? 'active' : '';
93 98
             $first = ($i-1)*$this->maxPerPage+1;
94 99
             $last = $i * $this->maxPerPage;
95
-            if ($last > $count) $last = $count;
100
+            if ($last > $count) {
101
+            	$last = $count;
102
+            }
96 103
             $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
97 104
             $html .= '<li class="' . $active . ' nav-item">
98 105
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
@@ -111,8 +118,7 @@  discard block
 block discarded – undo
111 118
                      </span>
112 119
                 </li>
113 120
                ';
114
-        }
115
-        else
121
+        } else
116 122
         {
117 123
             $html .= '
118 124
                 <li class="nav-item">
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -6,72 +6,72 @@  discard block
 block discarded – undo
6 6
 trait TrapDirectorTablePaging
7 7
 {
8 8
    
9
-    /*************** Paging *************/
10
-    protected $maxPerPage = 25;
9
+	/*************** Paging *************/
10
+	protected $maxPerPage = 25;
11 11
     
12
-    protected $currentPage = 0;
12
+	protected $currentPage = 0;
13 13
         
14
-    /**** var & func of TrapDirectorTable used ***/
15
-    protected $query;
16
-    abstract protected function getCurrentURLAndQS(string $caller);
17
-    abstract public function applyFilter();
14
+	/**** var & func of TrapDirectorTable used ***/
15
+	protected $query;
16
+	abstract protected function getCurrentURLAndQS(string $caller);
17
+	abstract public function applyFilter();
18 18
     
19
-    /*****************  Paging and counting *********/
19
+	/*****************  Paging and counting *********/
20 20
     
21
-    public function countQuery()
22
-    {
23
-        $this->query = $this->dbConn->select();
24
-        $this->query = $this->query
25
-            ->from(
26
-                $this->table,
27
-                array('COUNT(*)')
28
-                );
29
-        $this->applyFilter();                   
30
-    }
21
+	public function countQuery()
22
+	{
23
+		$this->query = $this->dbConn->select();
24
+		$this->query = $this->query
25
+			->from(
26
+				$this->table,
27
+				array('COUNT(*)')
28
+				);
29
+		$this->applyFilter();                   
30
+	}
31 31
     
32
-    public function count()
33
-    {
34
-        $this->countQuery();
35
-        return $this->dbConn->fetchOne($this->query);
36
-    }
32
+	public function count()
33
+	{
34
+		$this->countQuery();
35
+		return $this->dbConn->fetchOne($this->query);
36
+	}
37 37
     
38
-    public function setMaxPerPage(int $max)
39
-    {
40
-        $this->maxPerPage = $max;
41
-    }
38
+	public function setMaxPerPage(int $max)
39
+	{
40
+		$this->maxPerPage = $max;
41
+	}
42 42
     
43
-    protected function getPagingQuery(array $getVars)
44
-    {
45
-        if (isset($getVars['page']))
46
-        {
47
-            $this->currentPage = $getVars['page'];
48
-        }
49
-    }
43
+	protected function getPagingQuery(array $getVars)
44
+	{
45
+		if (isset($getVars['page']))
46
+		{
47
+			$this->currentPage = $getVars['page'];
48
+		}
49
+	}
50 50
 
51
-    protected function curPagingQuery()
52
-    {
53
-        if ($this->currentPage == '') return '';
54
-        return 'page='.$this->currentPage;
55
-    }
51
+	protected function curPagingQuery()
52
+	{
53
+		if ($this->currentPage == '') return '';
54
+		return 'page='.$this->currentPage;
55
+	}
56 56
     
57
-    public function renderPagingHeader()
58
-    {
59
-        $count = $this->count();
60
-        if ($count <= $this->maxPerPage )
61
-        {
62
-            return  'count : ' . $this->count() . '<br>';
63
-        }
57
+	public function renderPagingHeader()
58
+	{
59
+		$count = $this->count();
60
+		if ($count <= $this->maxPerPage )
61
+		{
62
+			return  'count : ' . $this->count() . '<br>';
63
+		}
64 64
         
65
-        if ($this->currentPage == 0) $this->currentPage = 1;
65
+		if ($this->currentPage == 0) $this->currentPage = 1;
66 66
         
67
-        $numPages = intdiv($count , $this->maxPerPage);
68
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
67
+		$numPages = intdiv($count , $this->maxPerPage);
68
+		if ($count % $this->maxPerPage != 0 ) $numPages++;
69 69
         
70
-        $html = '<div class="pagination-control" role="navigation">';
71
-        $html .= '<ul class="nav tab-nav">';
72
-        if ($this->currentPage <=1)
73
-        {
74
-            $html .= '
70
+		$html = '<div class="pagination-control" role="navigation">';
71
+		$html .= '<ul class="nav tab-nav">';
72
+		if ($this->currentPage <=1)
73
+		{
74
+			$html .= '
75 75
                 <li class="nav-item disabled" aria-hidden="true">
76 76
                     <span class="previous-page">
77 77
                             <span class="sr-only">Previous page</span>
@@ -79,35 +79,35 @@  discard block
 block discarded – undo
79 79
                      </span>
80 80
                 </li>
81 81
                ';
82
-        }
83
-        else 
84
-        {
85
-            $html .= '
82
+		}
83
+		else 
84
+		{
85
+			$html .= '
86 86
                 <li class="nav-item">
87 87
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
88 88
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
89 89
                      </a>
90 90
                 </li>
91 91
             ';
92
-        }
92
+		}
93 93
         
94
-        for ($i=1; $i <= $numPages ; $i++)
95
-        {
96
-            $active = ($this->currentPage == $i) ? 'active' : '';
97
-            $first = ($i-1)*$this->maxPerPage+1;
98
-            $last = $i * $this->maxPerPage;
99
-            if ($last > $count) $last = $count;
100
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
-            $html .= '<li class="' . $active . ' nav-item">
94
+		for ($i=1; $i <= $numPages ; $i++)
95
+		{
96
+			$active = ($this->currentPage == $i) ? 'active' : '';
97
+			$first = ($i-1)*$this->maxPerPage+1;
98
+			$last = $i * $this->maxPerPage;
99
+			if ($last > $count) $last = $count;
100
+			$display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
+			$html .= '<li class="' . $active . ' nav-item">
102 102
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
103 103
                     '.$i.'                
104 104
                     </a>
105 105
                 </li>';
106
-        }
106
+		}
107 107
         
108
-        if ($this->currentPage == $numPages)
109
-        {
110
-            $html .= '
108
+		if ($this->currentPage == $numPages)
109
+		{
110
+			$html .= '
111 111
                 <li class="nav-item disabled" aria-hidden="true">
112 112
                     <span class="previous-page">
113 113
                             <span class="sr-only">Previous page</span>
@@ -115,28 +115,28 @@  discard block
 block discarded – undo
115 115
                      </span>
116 116
                 </li>
117 117
                ';
118
-        }
119
-        else
120
-        {
121
-            $html .= '
118
+		}
119
+		else
120
+		{
121
+			$html .= '
122 122
                 <li class="nav-item">
123 123
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
124 124
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
125 125
                      </a>
126 126
                 </li>
127 127
             ';
128
-        }
128
+		}
129 129
         
130
-        $html .= '</ul> </div>';
130
+		$html .= '</ul> </div>';
131 131
         
132
-        return $html;
133
-    }
132
+		return $html;
133
+	}
134 134
     
135
-    public function applyPaging()
136
-    {
137
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
138
-        return $this;
139
-    }
135
+	public function applyPaging()
136
+	{
137
+		$this->query->limitPage($this->currentPage,$this->maxPerPage);
138
+		return $this;
139
+	}
140 140
     
141 141
     
142 142
 }
143 143
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
 {
8 8
    
9 9
     /*************** Paging *************/
10
-    protected $maxPerPage = 25;
10
+    protected $maxPerPage=25;
11 11
     
12
-    protected $currentPage = 0;
12
+    protected $currentPage=0;
13 13
         
14 14
     /**** var & func of TrapDirectorTable used ***/
15 15
     protected $query;
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
     
21 21
     public function countQuery()
22 22
     {
23
-        $this->query = $this->dbConn->select();
24
-        $this->query = $this->query
23
+        $this->query=$this->dbConn->select();
24
+        $this->query=$this->query
25 25
             ->from(
26 26
                 $this->table,
27 27
                 array('COUNT(*)')
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
     
38 38
     public function setMaxPerPage(int $max)
39 39
     {
40
-        $this->maxPerPage = $max;
40
+        $this->maxPerPage=$max;
41 41
     }
42 42
     
43 43
     protected function getPagingQuery(array $getVars)
44 44
     {
45 45
         if (isset($getVars['page']))
46 46
         {
47
-            $this->currentPage = $getVars['page'];
47
+            $this->currentPage=$getVars['page'];
48 48
         }
49 49
     }
50 50
 
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
     
57 57
     public function renderPagingHeader()
58 58
     {
59
-        $count = $this->count();
60
-        if ($count <= $this->maxPerPage )
59
+        $count=$this->count();
60
+        if ($count <= $this->maxPerPage)
61 61
         {
62
-            return  'count : ' . $this->count() . '<br>';
62
+            return  'count : '.$this->count().'<br>';
63 63
         }
64 64
         
65
-        if ($this->currentPage == 0) $this->currentPage = 1;
65
+        if ($this->currentPage == 0) $this->currentPage=1;
66 66
         
67
-        $numPages = intdiv($count , $this->maxPerPage);
68
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
67
+        $numPages=intdiv($count, $this->maxPerPage);
68
+        if ($count % $this->maxPerPage != 0) $numPages++;
69 69
         
70
-        $html = '<div class="pagination-control" role="navigation">';
71
-        $html .= '<ul class="nav tab-nav">';
72
-        if ($this->currentPage <=1)
70
+        $html='<div class="pagination-control" role="navigation">';
71
+        $html.='<ul class="nav tab-nav">';
72
+        if ($this->currentPage <= 1)
73 73
         {
74
-            $html .= '
74
+            $html.='
75 75
                 <li class="nav-item disabled" aria-hidden="true">
76 76
                     <span class="previous-page">
77 77
                             <span class="sr-only">Previous page</span>
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
         }
83 83
         else 
84 84
         {
85
-            $html .= '
85
+            $html.='
86 86
                 <li class="nav-item">
87
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
87
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" >
88 88
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
89 89
                      </a>
90 90
                 </li>
91 91
             ';
92 92
         }
93 93
         
94
-        for ($i=1; $i <= $numPages ; $i++)
94
+        for ($i=1; $i <= $numPages; $i++)
95 95
         {
96
-            $active = ($this->currentPage == $i) ? 'active' : '';
97
-            $first = ($i-1)*$this->maxPerPage+1;
98
-            $last = $i * $this->maxPerPage;
99
-            if ($last > $count) $last = $count;
100
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
-            $html .= '<li class="' . $active . ' nav-item">
102
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
96
+            $active=($this->currentPage == $i) ? 'active' : '';
97
+            $first=($i - 1) * $this->maxPerPage + 1;
98
+            $last=$i * $this->maxPerPage;
99
+            if ($last > $count) $last=$count;
100
+            $display='Show rows '.$first.' to '.$last.' of '.$count;
101
+            $html.='<li class="'.$active.' nav-item">
102
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'">
103 103
                     '.$i.'                
104 104
                     </a>
105 105
                 </li>';
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         
108 108
         if ($this->currentPage == $numPages)
109 109
         {
110
-            $html .= '
110
+            $html.='
111 111
                 <li class="nav-item disabled" aria-hidden="true">
112 112
                     <span class="previous-page">
113 113
                             <span class="sr-only">Previous page</span>
@@ -118,23 +118,23 @@  discard block
 block discarded – undo
118 118
         }
119 119
         else
120 120
         {
121
-            $html .= '
121
+            $html.='
122 122
                 <li class="nav-item">
123
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
123
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page">
124 124
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
125 125
                      </a>
126 126
                 </li>
127 127
             ';
128 128
         }
129 129
         
130
-        $html .= '</ul> </div>';
130
+        $html.='</ul> </div>';
131 131
         
132 132
         return $html;
133 133
     }
134 134
     
135 135
     public function applyPaging()
136 136
     {
137
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
137
+        $this->query->limitPage($this->currentPage, $this->maxPerPage);
138 138
         return $this;
139 139
     }
140 140
     
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTableOrder.php 3 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
20 20
         $orderSQL='';
21 21
         foreach ($this->order as $column => $direction)
22 22
         {
23
-            if ($orderSQL != "") $orderSQL.=',';
23
+            if ($orderSQL != "") {
24
+            	$orderSQL.=',';
25
+            }
24 26
             
25 27
             $orderSQL .= $column . ' ' . $direction;
26 28
         }
@@ -37,7 +39,9 @@  discard block
 block discarded – undo
37 39
 
38 40
     public function isOrderSet()
39 41
     {
40
-        if (count($this->order) == 0) return FALSE;
42
+        if (count($this->order) == 0) {
43
+        	return FALSE;
44
+        }
41 45
         return TRUE;
42 46
     }
43 47
     
@@ -58,7 +62,9 @@  discard block
 block discarded – undo
58 62
     
59 63
     protected function curOrderQuery()
60 64
     {
61
-        if ($this->orderQuery == '') return '';
65
+        if ($this->orderQuery == '') {
66
+        	return '';
67
+        }
62 68
         return 'o='.$this->orderQuery;
63 69
     }
64 70
         
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,65 +5,65 @@
 block discarded – undo
5 5
 
6 6
 trait TrapDirectorTableOrder
7 7
 { 
8
-    /** @var array $order : (db column, 'ASC' | 'DESC') */
9
-    protected $order = array();
10
-    /** @var string $orderQuery passed by GET */
11
-    protected $orderQuery = '';   
8
+	/** @var array $order : (db column, 'ASC' | 'DESC') */
9
+	protected $order = array();
10
+	/** @var string $orderQuery passed by GET */
11
+	protected $orderQuery = '';   
12 12
     
13
-    /** used var & functions of trapDirectorTable **/
14
-    protected $query;
13
+	/** used var & functions of trapDirectorTable **/
14
+	protected $query;
15 15
     
16 16
    /***************** Ordering ********************/
17 17
     
18
-    public function applyOrder()
19
-    {
20
-        if (count($this->order) == 0)
21
-        {
22
-            return $this;
23
-        }
24
-        $orderSQL='';
25
-        foreach ($this->order as $column => $direction)
26
-        {
27
-            if ($orderSQL != "") $orderSQL.=',';
18
+	public function applyOrder()
19
+	{
20
+		if (count($this->order) == 0)
21
+		{
22
+			return $this;
23
+		}
24
+		$orderSQL='';
25
+		foreach ($this->order as $column => $direction)
26
+		{
27
+			if ($orderSQL != "") $orderSQL.=',';
28 28
             
29
-            $orderSQL .= $column . ' ' . $direction;
30
-        }
31
-        $this->query = $this->query->order($orderSQL);
29
+			$orderSQL .= $column . ' ' . $direction;
30
+		}
31
+		$this->query = $this->query->order($orderSQL);
32 32
         
33
-        return $this;
34
-    }
33
+		return $this;
34
+	}
35 35
     
36
-    public function setOrder(array $order)
37
-    {
38
-        $this->order = $order;
39
-        return $this;
40
-    }
36
+	public function setOrder(array $order)
37
+	{
38
+		$this->order = $order;
39
+		return $this;
40
+	}
41 41
 
42
-    public function isOrderSet()
43
-    {
44
-        if (count($this->order) == 0) return FALSE;
45
-        return TRUE;
46
-    }
42
+	public function isOrderSet()
43
+	{
44
+		if (count($this->order) == 0) return FALSE;
45
+		return TRUE;
46
+	}
47 47
     
48
-    public function getOrderQuery(array $getVars)
49
-    {
50
-        if (isset($getVars['o']))
51
-        {
52
-            $this->orderQuery = $getVars['o'];
53
-            $match = array();
54
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
55
-            {
56
-                $orderArray=array($match[1] => $match[2]);
57
-                echo "$match[1] => $match[2]";
58
-                $this->setOrder($orderArray);
59
-            }
60
-        }
61
-    }
48
+	public function getOrderQuery(array $getVars)
49
+	{
50
+		if (isset($getVars['o']))
51
+		{
52
+			$this->orderQuery = $getVars['o'];
53
+			$match = array();
54
+			if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
55
+			{
56
+				$orderArray=array($match[1] => $match[2]);
57
+				echo "$match[1] => $match[2]";
58
+				$this->setOrder($orderArray);
59
+			}
60
+		}
61
+	}
62 62
     
63
-    protected function curOrderQuery()
64
-    {
65
-        if ($this->orderQuery == '') return '';
66
-        return 'o='.$this->orderQuery;
67
-    }
63
+	protected function curOrderQuery()
64
+	{
65
+		if ($this->orderQuery == '') return '';
66
+		return 'o='.$this->orderQuery;
67
+	}
68 68
         
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
 trait TrapDirectorTableOrder
7 7
 { 
8 8
     /** @var array $order : (db column, 'ASC' | 'DESC') */
9
-    protected $order = array();
9
+    protected $order=array();
10 10
     /** @var string $orderQuery passed by GET */
11
-    protected $orderQuery = '';   
11
+    protected $orderQuery='';   
12 12
     
13 13
     /** used var & functions of trapDirectorTable **/
14 14
     protected $query;
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
         {
27 27
             if ($orderSQL != "") $orderSQL.=',';
28 28
             
29
-            $orderSQL .= $column . ' ' . $direction;
29
+            $orderSQL.=$column.' '.$direction;
30 30
         }
31
-        $this->query = $this->query->order($orderSQL);
31
+        $this->query=$this->query->order($orderSQL);
32 32
         
33 33
         return $this;
34 34
     }
35 35
     
36 36
     public function setOrder(array $order)
37 37
     {
38
-        $this->order = $order;
38
+        $this->order=$order;
39 39
         return $this;
40 40
     }
41 41
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
     {
50 50
         if (isset($getVars['o']))
51 51
         {
52
-            $this->orderQuery = $getVars['o'];
53
-            $match = array();
54
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
52
+            $this->orderQuery=$getVars['o'];
53
+            $match=array();
54
+            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match))
55 55
             {
56 56
                 $orderArray=array($match[1] => $match[2]);
57 57
                 echo "$match[1] => $match[2]";
Please login to merge, or discard this patch.