Passed
Push — master ( 2ea6c2...c1d2b2 )
by Patrick
02:01
created
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.
library/Trapdirector/Tables/TrapDirectorTableGrouping.php 3 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -7,85 +7,85 @@
 block discarded – undo
7 7
 {
8 8
     
9 9
   
10
-    /*************** Grouping ************/
10
+	/*************** Grouping ************/
11 11
     
12
-    /** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
-    protected $grouppingActive=false;
12
+	/** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
+	protected $grouppingActive=false;
14 14
     
15
-    /** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
-    protected $groupingColumn='';
15
+	/** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
+	protected $groupingColumn='';
17 17
     
18
-    /**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
-    protected $groupingVal='';
18
+	/**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
+	protected $groupingVal='';
20 20
     
21
-    /** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
-    protected $groupingColSpan=1;
21
+	/** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
+	protected $groupingColSpan=1;
23 23
       
24
-    /*****************  Grouping ****************/
24
+	/*****************  Grouping ****************/
25 25
     
26
-    /**
27
-     * Set grouping. column must be DB name
28
-     * @param string $columnDBName
29
-     */
30
-    public function setGrouping(string $columnDBName)
31
-    {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
34
-    }
26
+	/**
27
+	 * Set grouping. column must be DB name
28
+	 * @param string $columnDBName
29
+	 */
30
+	public function setGrouping(string $columnDBName)
31
+	{
32
+		$this->groupingColumn = $columnDBName;
33
+		$this->grouppingActive = TRUE;
34
+	}
35 35
     
36
-    /**
37
-     * Init of grouping before rendering
38
-     */
39
-    public function initGrouping()
40
-    {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
43
-    }
36
+	/**
37
+	 * Init of grouping before rendering
38
+	 */
39
+	public function initGrouping()
40
+	{
41
+		$this->groupingVal = '';
42
+		$this->groupingColSpan = count($this->titles);
43
+	}
44 44
     
45
-    /**
46
-     * Function to print grouping value (for ovveride in specific tables)
47
-     * @param string $value
48
-     * @return string
49
-     */
50
-    public function groupingPrintData( string $value )
51
-    {
52
-        $html = "$value";
53
-        return $html;
54
-    }
45
+	/**
46
+	 * Function to print grouping value (for ovveride in specific tables)
47
+	 * @param string $value
48
+	 * @return string
49
+	 */
50
+	public function groupingPrintData( string $value )
51
+	{
52
+		$html = "$value";
53
+		return $html;
54
+	}
55 55
     
56
-    /**
57
-     * When to display new grouping line  (for ovveride in specific tables)
58
-     * @param string $val1 Current value in grouping
59
-     * @param string $val2 Value of current line
60
-     * @return boolean TRUE if a new grouping line is needed.
61
-     */
62
-    public function groupingEvalNext(string $val1, string $val2)
63
-    {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
68
-    }
56
+	/**
57
+	 * When to display new grouping line  (for ovveride in specific tables)
58
+	 * @param string $val1 Current value in grouping
59
+	 * @param string $val2 Value of current line
60
+	 * @return boolean TRUE if a new grouping line is needed.
61
+	 */
62
+	public function groupingEvalNext(string $val1, string $val2)
63
+	{
64
+		if ($val1 != $val2)
65
+			return TRUE;
66
+		else
67
+			return FALSE;
68
+	}
69 69
     
70
-    /**
71
-     * Called before each line to check if grouping line is needed.
72
-     * @param mixed $values
73
-     * @return string with line or empty.
74
-     */
75
-    public function groupingNextLine( $values)
76
-    {
77
-        if ($this->grouppingActive === FALSE) return '';
70
+	/**
71
+	 * Called before each line to check if grouping line is needed.
72
+	 * @param mixed $values
73
+	 * @return string with line or empty.
74
+	 */
75
+	public function groupingNextLine( $values)
76
+	{
77
+		if ($this->grouppingActive === FALSE) return '';
78 78
         
79
-        $dbcol = $this->groupingColumn;
80
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$values->$dbcol) === TRUE )
81
-        {
82
-            $this->groupingVal = $values->$dbcol;
83
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
84
-            return $html;
85
-        }
86
-        return '';
79
+		$dbcol = $this->groupingColumn;
80
+		if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$values->$dbcol) === TRUE )
81
+		{
82
+			$this->groupingVal = $values->$dbcol;
83
+			$html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
84
+			return $html;
85
+		}
86
+		return '';
87 87
         
88
-    }
88
+	}
89 89
     
90 90
   
91 91
 }
92 92
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function setGrouping(string $columnDBName)
31 31
     {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
32
+        $this->groupingColumn=$columnDBName;
33
+        $this->grouppingActive=TRUE;
34 34
     }
35 35
     
36 36
     /**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function initGrouping()
40 40
     {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
41
+        $this->groupingVal='';
42
+        $this->groupingColSpan=count($this->titles);
43 43
     }
44 44
     
45 45
     /**
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @param string $value
48 48
      * @return string
49 49
      */
50
-    public function groupingPrintData( string $value )
50
+    public function groupingPrintData(string $value)
51 51
     {
52
-        $html = "$value";
52
+        $html="$value";
53 53
         return $html;
54 54
     }
55 55
     
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
      * @param mixed $values
73 73
      * @return string with line or empty.
74 74
      */
75
-    public function groupingNextLine( $values)
75
+    public function groupingNextLine($values)
76 76
     {
77 77
         if ($this->grouppingActive === FALSE) return '';
78 78
         
79
-        $dbcol = $this->groupingColumn;
80
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$values->$dbcol) === TRUE )
79
+        $dbcol=$this->groupingColumn;
80
+        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal, $values->$dbcol) === TRUE)
81 81
         {
82
-            $this->groupingVal = $values->$dbcol;
83
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
82
+            $this->groupingVal=$values->$dbcol;
83
+            $html='<tr><th colspan="'.$this->groupingColSpan.'">'.$this->groupingPrintData($this->groupingVal).'</th></tr>';
84 84
             return $html;
85 85
         }
86 86
         return '';
Please login to merge, or discard this patch.
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -61,10 +61,11 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function groupingEvalNext(string $val1, string $val2)
63 63
     {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
64
+        if ($val1 != $val2) {
65
+                    return TRUE;
66
+        } else {
67
+                    return FALSE;
68
+        }
68 69
     }
69 70
     
70 71
     /**
@@ -74,7 +75,9 @@  discard block
 block discarded – undo
74 75
      */
75 76
     public function groupingNextLine( $values)
76 77
     {
77
-        if ($this->grouppingActive === FALSE) return '';
78
+        if ($this->grouppingActive === FALSE) {
79
+        	return '';
80
+        }
78 81
         
79 82
         $dbcol = $this->groupingColumn;
80 83
         if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$values->$dbcol) === TRUE )
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 3 patches
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -8,367 +8,367 @@
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $curl;
22
-    // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
24
-        JSON_ERROR_NONE => 'No error has occurred.',
25
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
-        JSON_ERROR_SYNTAX => 'Syntax error.',
29
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
-    ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
21
+	protected $curl;
22
+	// http://php.net/manual/de/function.json-last-error.php#119985
23
+	protected $errorReference = [
24
+		JSON_ERROR_NONE => 'No error has occurred.',
25
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
+		JSON_ERROR_SYNTAX => 'Syntax error.',
29
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
+	];
34
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
35 35
     
36
-    /**
37
-     * Creates Icinga2API object
38
-     * 
39
-     * @param string $host host name or IP
40
-     * @param number $port API port
41
-     */
42
-    public function __construct($host, $port = 5665)
43
-    {
44
-        $this->host=$host;
45
-        $this->port=$port;
46
-    }
47
-    /**
48
-     * Set user & pass
49
-     * @param string $user
50
-     * @param string $pass
51
-     */
52
-    public function setCredentials($user,$pass)
53
-    {
54
-        $this->user=$user;
55
-        $this->pass=$pass;
56
-        $this->authmethod='pass';
57
-    }
36
+	/**
37
+	 * Creates Icinga2API object
38
+	 * 
39
+	 * @param string $host host name or IP
40
+	 * @param number $port API port
41
+	 */
42
+	public function __construct($host, $port = 5665)
43
+	{
44
+		$this->host=$host;
45
+		$this->port=$port;
46
+	}
47
+	/**
48
+	 * Set user & pass
49
+	 * @param string $user
50
+	 * @param string $pass
51
+	 */
52
+	public function setCredentials($user,$pass)
53
+	{
54
+		$this->user=$user;
55
+		$this->pass=$pass;
56
+		$this->authmethod='pass';
57
+	}
58 58
     
59
-    /**
60
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
-     * @param string $user
62
-     * @param string $usercert
63
-     */
64
-    public function setCredentialskey($user,$usercert)
65
-    {
66
-        $this->user=$user;
67
-        $this->usercert=$usercert;
68
-        $this->authmethod='cert';
69
-        throw new RuntimeException('Certificate auth not implemented');
70
-    }
59
+	/**
60
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
+	 * @param string $user
62
+	 * @param string $usercert
63
+	 */
64
+	public function setCredentialskey($user,$usercert)
65
+	{
66
+		$this->user=$user;
67
+		$this->usercert=$usercert;
68
+		$this->authmethod='cert';
69
+		throw new RuntimeException('Certificate auth not implemented');
70
+	}
71 71
 
72
-    public function test(array $permissions)
73
-    {
74
-       try
75
-        {
76
-            $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
79
-        {
80
-            return array(true, 'Error with API : '.$e->getMessage());
81
-        }
82
-        //var_dump($result);
83
-        $permOk=1;
84
-        $permMissing='';
85
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
86
-        {
87
-            return array(false,'OK');
88
-        }
89
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90
-        {
72
+	public function test(array $permissions)
73
+	{
74
+	   try
75
+		{
76
+			$result=$this->request('GET', "", NULL, NULL);
77
+		} 
78
+		catch (Exception $e)
79
+		{
80
+			return array(true, 'Error with API : '.$e->getMessage());
81
+		}
82
+		//var_dump($result);
83
+		$permOk=1;
84
+		$permMissing='';
85
+		if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
86
+		{
87
+			return array(false,'OK');
88
+		}
89
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90
+		{
91 91
             
92
-            foreach ( $permissions as $mustPermission)
93
-            {
94
-                $curPermOK=0;
95
-                foreach ( $result->results[0]->permissions as $curPermission)
96
-                {
97
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
99
-                    {
100
-                        $curPermOK=1;
101
-                        break;
102
-                    }
103
-                }
104
-                if ($curPermOK == 0)
105
-                {
106
-                    $permOk=0;
107
-                    $permMissing=$mustPermission;
108
-                    break;
109
-                }
110
-            }
111
-            if ($permOk == 0)
112
-            {
113
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
114
-            }
115
-            return array(false,'API connection OK');
92
+			foreach ( $permissions as $mustPermission)
93
+			{
94
+				$curPermOK=0;
95
+				foreach ( $result->results[0]->permissions as $curPermission)
96
+				{
97
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
99
+					{
100
+						$curPermOK=1;
101
+						break;
102
+					}
103
+				}
104
+				if ($curPermOK == 0)
105
+				{
106
+					$permOk=0;
107
+					$permMissing=$mustPermission;
108
+					break;
109
+				}
110
+			}
111
+			if ($permOk == 0)
112
+			{
113
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
114
+			}
115
+			return array(false,'API connection OK');
116 116
             
117
-        }
118
-        return array(true,'API connection OK, but cannot get permissions');
119
-    }
117
+		}
118
+		return array(true,'API connection OK, but cannot get permissions');
119
+	}
120 120
     
121 121
     
122
-    protected function url($url) {
123
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
124
-    }
122
+	protected function url($url) {
123
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
124
+	}
125 125
     
126
-    /**
127
-     * Create or return curl ressource
128
-     * @throws Exception
129
-     * @return resource
130
-     */
131
-    protected function curl() {
132
-        if ($this->curl === null) {
133
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134
-            if ($this->curl === false) {
135
-                throw new Exception('CURL INIT ERROR');
136
-            }
137
-        }
138
-        return $this->curl;
139
-    }
126
+	/**
127
+	 * Create or return curl ressource
128
+	 * @throws Exception
129
+	 * @return resource
130
+	 */
131
+	protected function curl() {
132
+		if ($this->curl === null) {
133
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134
+			if ($this->curl === false) {
135
+				throw new Exception('CURL INIT ERROR');
136
+			}
137
+		}
138
+		return $this->curl;
139
+	}
140 140
 
141
-    /**
142
-     * Send a passive service check
143
-     * @param string $host : host name 
144
-     * @param string $service : service name
145
-     * @param int $state : state of service
146
-     * @param string $display : service passive check output
147
-     * @param string $perfdata : performance data as string
148
-     * @return array (status = true (oK) or false (nok), string message)
149
-     */
150
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
151
-    {
152
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
153
-        //actions/process-check-result?service=example.localdomain!passive-ping6
154
-        $url='actions/process-check-result';
155
-        $body=array(
156
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
157
-            'type'          => 'Service',
158
-            "exit_status"   => $state,
159
-            "plugin_output" => $display,
160
-            "performance_data" => $perfdata
161
-        );
162
-        try 
163
-        {
164
-            $result=$this->request('POST', $url, null, $body);
165
-        } catch (Exception $e) 
166
-        {
167
-            return array(false, $e->getMessage());
168
-        }
169
-        if (property_exists($result,'error') )
170
-        {
171
-            if (property_exists($result,'status'))
172
-            {
173
-                $message=$result->status;
174
-            }
175
-            else 
176
-            {
177
-                $message="Unkown status";
178
-            }
179
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
180
-        }
181
-        if (property_exists($result, 'results'))
182
-        {
183
-            if (isset($result->results[0]))
184
-            {
185
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
-            }
187
-            else
188
-            {
189
-                return array(false,'Service not found');
190
-            }
141
+	/**
142
+	 * Send a passive service check
143
+	 * @param string $host : host name 
144
+	 * @param string $service : service name
145
+	 * @param int $state : state of service
146
+	 * @param string $display : service passive check output
147
+	 * @param string $perfdata : performance data as string
148
+	 * @return array (status = true (oK) or false (nok), string message)
149
+	 */
150
+	public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
151
+	{
152
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
153
+		//actions/process-check-result?service=example.localdomain!passive-ping6
154
+		$url='actions/process-check-result';
155
+		$body=array(
156
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
157
+			'type'          => 'Service',
158
+			"exit_status"   => $state,
159
+			"plugin_output" => $display,
160
+			"performance_data" => $perfdata
161
+		);
162
+		try 
163
+		{
164
+			$result=$this->request('POST', $url, null, $body);
165
+		} catch (Exception $e) 
166
+		{
167
+			return array(false, $e->getMessage());
168
+		}
169
+		if (property_exists($result,'error') )
170
+		{
171
+			if (property_exists($result,'status'))
172
+			{
173
+				$message=$result->status;
174
+			}
175
+			else 
176
+			{
177
+				$message="Unkown status";
178
+			}
179
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
180
+		}
181
+		if (property_exists($result, 'results'))
182
+		{
183
+			if (isset($result->results[0]))
184
+			{
185
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
+			}
187
+			else
188
+			{
189
+				return array(false,'Service not found');
190
+			}
191 191
             
192
-        }
193
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
194
-    }
192
+		}
193
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
194
+	}
195 195
  
196
-    /**
197
-     * return array of host by IP (4 or 6)
198
-     * @param string $ip
199
-     * @throws Exception
200
-     * @return array objects : array('__name','name','display_name')
201
-     */
202
-    public function getHostByIP($ip) 
203
-    {
204
-        /*
196
+	/**
197
+	 * return array of host by IP (4 or 6)
198
+	 * @param string $ip
199
+	 * @throws Exception
200
+	 * @return array objects : array('__name','name','display_name')
201
+	 */
202
+	public function getHostByIP($ip) 
203
+	{
204
+		/*
205 205
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
206 206
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
207 207
             
208 208
             {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
209 209
          */
210 210
         
211
-        $url='objects/hosts';
212
-        $body=array(
213
-            "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
-            "attrs"         => array('__name','name','display_name','groups')
215
-        );
216
-        try
217
-        {
218
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
219
-        } catch (Exception $e)
220
-        {
221
-            throw new Exception($e->getMessage());
222
-        }
211
+		$url='objects/hosts';
212
+		$body=array(
213
+			"filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
+			"attrs"         => array('__name','name','display_name','groups')
215
+		);
216
+		try
217
+		{
218
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
219
+		} catch (Exception $e)
220
+		{
221
+			throw new Exception($e->getMessage());
222
+		}
223 223
         
224
-        if (property_exists($result,'error') )
225
-        {
226
-            if (property_exists($result,'status'))
227
-            {
228
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
-            }
230
-            else
231
-            {
232
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
233
-            }
234
-        }
235
-        if (property_exists($result, 'results'))
236
-        {
237
-            $numHost=0;
238
-            $hostArray=array();
239
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
240
-            {
241
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
242
-                $numHost++;
243
-            }
244
-            return $hostArray;            
245
-        }
246
-        throw new Exception('Unkown result');
247
-    }
224
+		if (property_exists($result,'error') )
225
+		{
226
+			if (property_exists($result,'status'))
227
+			{
228
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
+			}
230
+			else
231
+			{
232
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
233
+			}
234
+		}
235
+		if (property_exists($result, 'results'))
236
+		{
237
+			$numHost=0;
238
+			$hostArray=array();
239
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
240
+			{
241
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
242
+				$numHost++;
243
+			}
244
+			return $hostArray;            
245
+		}
246
+		throw new Exception('Unkown result');
247
+	}
248 248
 
249
-    /**
250
-     * Get all host and IP from hostgroup
251
-     * @param string $hostGroup
252
-     * @throws Exception
253
-     * @return array : attributes : address, address6, name
254
-     */
255
-    public function getHostsIPByHostGroup($hostGroup)
256
-    {        
257
-        $url='objects/hosts';
258
-        $body=array(
259
-            "filter"        => '\"'.$hostGroup.'\" in groups',
260
-            "attrs"         => array('address','address','name')
261
-        );
262
-        try
263
-        {
264
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
265
-        } catch (Exception $e)
266
-        {
267
-            throw new Exception($e->getMessage());
268
-        }
249
+	/**
250
+	 * Get all host and IP from hostgroup
251
+	 * @param string $hostGroup
252
+	 * @throws Exception
253
+	 * @return array : attributes : address, address6, name
254
+	 */
255
+	public function getHostsIPByHostGroup($hostGroup)
256
+	{        
257
+		$url='objects/hosts';
258
+		$body=array(
259
+			"filter"        => '\"'.$hostGroup.'\" in groups',
260
+			"attrs"         => array('address','address','name')
261
+		);
262
+		try
263
+		{
264
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
265
+		} catch (Exception $e)
266
+		{
267
+			throw new Exception($e->getMessage());
268
+		}
269 269
         
270
-        if (property_exists($result,'error') )
271
-        {
272
-            if (property_exists($result,'status'))
273
-            {
274
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
-            }
276
-            else
277
-            {
278
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
279
-            }
280
-        }
281
-        if (property_exists($result, 'results'))
282
-        {
283
-            $numHost=0;
284
-            $hostArray=array();
285
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
286
-            {
287
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
288
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
289
-                $numHost++;
290
-            }
291
-            return $hostArray;
292
-        }
293
-        throw new Exception('Unkown result');
294
-    }
270
+		if (property_exists($result,'error') )
271
+		{
272
+			if (property_exists($result,'status'))
273
+			{
274
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
+			}
276
+			else
277
+			{
278
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
279
+			}
280
+		}
281
+		if (property_exists($result, 'results'))
282
+		{
283
+			$numHost=0;
284
+			$hostArray=array();
285
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
286
+			{
287
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
288
+				$hostArray[$numHost]->name = $result->results[$numHost]->name;
289
+				$numHost++;
290
+			}
291
+			return $hostArray;
292
+		}
293
+		throw new Exception('Unkown result');
294
+	}
295 295
     
296
-    /**
297
-     * Send request to API
298
-     * @param string $method get/post/...
299
-     * @param string $url (after /v1/ )
300
-     * @param array $headers
301
-     * @param array $body 
302
-     * @throws Exception
303
-     * @return array
304
-     */
305
-    public function request($method, $url, $headers, $body) {
306
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
307
-        $curlHeaders = array("Accept: application/json");
308
-        if ($body !== null) {
309
-            $body = json_encode($body);
310
-            array_push($curlHeaders, 'Content-Type: application/json');
311
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312
-        }
313
-        //var_dump($body);
314
-        //var_dump($this->url($url));
315
-        if ($headers !== null) {
316
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
317
-        } else 
318
-        {
319
-            $curlFinalHeaders=$curlHeaders;
320
-        }
321
-        $curl = $this->curl();
322
-        $opts = array(
323
-            CURLOPT_URL		=> $this->url($url),
324
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325
-            CURLOPT_USERPWD		=> $auth,
326
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
327
-            CURLOPT_RETURNTRANSFER 	=> true,
328
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
329
-            CURLOPT_SSL_VERIFYHOST 	=> false,
330
-            CURLOPT_SSL_VERIFYPEER 	=> false,
331
-        );
332
-        if ($body !== null) {
333
-            $opts[CURLOPT_POSTFIELDS] = $body;
334
-        }
335
-        curl_setopt_array($curl, $opts);
336
-        $res = curl_exec($curl);
337
-        if ($res === false) {
338
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
339
-        }
340
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
341
-        if ($statusCode === 401) {
342
-            throw new Exception('Unable to authenticate, please check your API credentials');
343
-        }
344
-        return $this->fromJsonResult($res);
345
-    }
296
+	/**
297
+	 * Send request to API
298
+	 * @param string $method get/post/...
299
+	 * @param string $url (after /v1/ )
300
+	 * @param array $headers
301
+	 * @param array $body 
302
+	 * @throws Exception
303
+	 * @return array
304
+	 */
305
+	public function request($method, $url, $headers, $body) {
306
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
307
+		$curlHeaders = array("Accept: application/json");
308
+		if ($body !== null) {
309
+			$body = json_encode($body);
310
+			array_push($curlHeaders, 'Content-Type: application/json');
311
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312
+		}
313
+		//var_dump($body);
314
+		//var_dump($this->url($url));
315
+		if ($headers !== null) {
316
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
317
+		} else 
318
+		{
319
+			$curlFinalHeaders=$curlHeaders;
320
+		}
321
+		$curl = $this->curl();
322
+		$opts = array(
323
+			CURLOPT_URL		=> $this->url($url),
324
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325
+			CURLOPT_USERPWD		=> $auth,
326
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
327
+			CURLOPT_RETURNTRANSFER 	=> true,
328
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
329
+			CURLOPT_SSL_VERIFYHOST 	=> false,
330
+			CURLOPT_SSL_VERIFYPEER 	=> false,
331
+		);
332
+		if ($body !== null) {
333
+			$opts[CURLOPT_POSTFIELDS] = $body;
334
+		}
335
+		curl_setopt_array($curl, $opts);
336
+		$res = curl_exec($curl);
337
+		if ($res === false) {
338
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
339
+		}
340
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
341
+		if ($statusCode === 401) {
342
+			throw new Exception('Unable to authenticate, please check your API credentials');
343
+		}
344
+		return $this->fromJsonResult($res);
345
+	}
346 346
     
347
-    /**
348
-     * 
349
-     * @param string $json json encoded 
350
-     * @throws Exception
351
-     * @return array json decoded
352
-     */
353
-    protected function fromJsonResult($json) {
354
-        $result = @json_decode($json);
355
-        //var_dump($json);
356
-        if ($result === null) {
357
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
358
-        }
359
-        return $result;
360
-    }
347
+	/**
348
+	 * 
349
+	 * @param string $json json encoded 
350
+	 * @throws Exception
351
+	 * @return array json decoded
352
+	 */
353
+	protected function fromJsonResult($json) {
354
+		$result = @json_decode($json);
355
+		//var_dump($json);
356
+		if ($result === null) {
357
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
358
+		}
359
+		return $result;
360
+	}
361 361
     
362
-    /**
363
-     * Return text error no json error
364
-     * @param string $errorCode
365
-     * @return string
366
-     */
367
-    protected function getLastJsonErrorMessage($errorCode) {
368
-        if (!array_key_exists($errorCode, $this->errorReference)) {
369
-            return self::JSON_UNKNOWN_ERROR;
370
-        }
371
-        return $this->errorReference[$errorCode];
372
-    }
362
+	/**
363
+	 * Return text error no json error
364
+	 * @param string $errorCode
365
+	 * @return string
366
+	 */
367
+	protected function getLastJsonErrorMessage($errorCode) {
368
+		if (!array_key_exists($errorCode, $this->errorReference)) {
369
+			return self::JSON_UNKNOWN_ERROR;
370
+		}
371
+		return $this->errorReference[$errorCode];
372
+	}
373 373
 }
374 374
 
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $curl;
22 22
     // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
23
+    protected $errorReference=[
24 24
         JSON_ERROR_NONE => 'No error has occurred.',
25 25
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26 26
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32 32
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33 33
     ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
34
+    const JSON_UNKNOWN_ERROR='Unknown error.';
35 35
     
36 36
     /**
37 37
      * Creates Icinga2API object
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param string $host host name or IP
40 40
      * @param number $port API port
41 41
      */
42
-    public function __construct($host, $port = 5665)
42
+    public function __construct($host, $port=5665)
43 43
     {
44 44
         $this->host=$host;
45 45
         $this->port=$port;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * @param string $user
50 50
      * @param string $pass
51 51
      */
52
-    public function setCredentials($user,$pass)
52
+    public function setCredentials($user, $pass)
53 53
     {
54 54
         $this->user=$user;
55 55
         $this->pass=$pass;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param string $user
62 62
      * @param string $usercert
63 63
      */
64
-    public function setCredentialskey($user,$usercert)
64
+    public function setCredentialskey($user, $usercert)
65 65
     {
66 66
         $this->user=$user;
67 67
         $this->usercert=$usercert;
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
         $permMissing='';
85 85
         if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
86 86
         {
87
-            return array(false,'OK');
87
+            return array(false, 'OK');
88 88
         }
89 89
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90 90
         {
91 91
             
92
-            foreach ( $permissions as $mustPermission)
92
+            foreach ($permissions as $mustPermission)
93 93
             {
94 94
                 $curPermOK=0;
95
-                foreach ( $result->results[0]->permissions as $curPermission)
95
+                foreach ($result->results[0]->permissions as $curPermission)
96 96
                 {
97
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
97
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
98
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
99 99
                     {
100 100
                         $curPermOK=1;
101 101
                         break;
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
             }
111 111
             if ($permOk == 0)
112 112
             {
113
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
113
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
114 114
             }
115
-            return array(false,'API connection OK');
115
+            return array(false, 'API connection OK');
116 116
             
117 117
         }
118
-        return array(true,'API connection OK, but cannot get permissions');
118
+        return array(true, 'API connection OK, but cannot get permissions');
119 119
     }
120 120
     
121 121
     
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     protected function curl() {
132 132
         if ($this->curl === null) {
133
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
133
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134 134
             if ($this->curl === false) {
135 135
                 throw new Exception('CURL INIT ERROR');
136 136
             }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      * @param string $perfdata : performance data as string
148 148
      * @return array (status = true (oK) or false (nok), string message)
149 149
      */
150
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
150
+    public function serviceCheckResult($host, $service, $state, $display, $perfdata='')
151 151
     {
152 152
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
153 153
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
         {
167 167
             return array(false, $e->getMessage());
168 168
         }
169
-        if (property_exists($result,'error') )
169
+        if (property_exists($result, 'error'))
170 170
         {
171
-            if (property_exists($result,'status'))
171
+            if (property_exists($result, 'status'))
172 172
             {
173 173
                 $message=$result->status;
174 174
             }
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
             {
177 177
                 $message="Unkown status";
178 178
             }
179
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
179
+            return array(false, 'Ret code '.$result->error.' : '.$message);
180 180
         }
181 181
         if (property_exists($result, 'results'))
182 182
         {
183 183
             if (isset($result->results[0]))
184 184
             {
185
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
185
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186 186
             }
187 187
             else
188 188
             {
189
-                return array(false,'Service not found');
189
+                return array(false, 'Service not found');
190 190
             }
191 191
             
192 192
         }
193
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
193
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
194 194
     }
195 195
  
196 196
     /**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
         $url='objects/hosts';
212 212
         $body=array(
213 213
             "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
-            "attrs"         => array('__name','name','display_name','groups')
214
+            "attrs"         => array('__name', 'name', 'display_name', 'groups')
215 215
         );
216 216
         try
217 217
         {
@@ -221,24 +221,24 @@  discard block
 block discarded – undo
221 221
             throw new Exception($e->getMessage());
222 222
         }
223 223
         
224
-        if (property_exists($result,'error') )
224
+        if (property_exists($result, 'error'))
225 225
         {
226
-            if (property_exists($result,'status'))
226
+            if (property_exists($result, 'status'))
227 227
             {
228
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
228
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
229 229
             }
230 230
             else
231 231
             {
232
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
232
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
233 233
             }
234 234
         }
235 235
         if (property_exists($result, 'results'))
236 236
         {
237 237
             $numHost=0;
238 238
             $hostArray=array();
239
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
239
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
240 240
             {
241
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
241
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
242 242
                 $numHost++;
243 243
             }
244 244
             return $hostArray;            
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         $url='objects/hosts';
258 258
         $body=array(
259 259
             "filter"        => '\"'.$hostGroup.'\" in groups',
260
-            "attrs"         => array('address','address','name')
260
+            "attrs"         => array('address', 'address', 'name')
261 261
         );
262 262
         try
263 263
         {
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
             throw new Exception($e->getMessage());
268 268
         }
269 269
         
270
-        if (property_exists($result,'error') )
270
+        if (property_exists($result, 'error'))
271 271
         {
272
-            if (property_exists($result,'status'))
272
+            if (property_exists($result, 'status'))
273 273
             {
274
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
274
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
275 275
             }
276 276
             else
277 277
             {
278
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
278
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
279 279
             }
280 280
         }
281 281
         if (property_exists($result, 'results'))
282 282
         {
283 283
             $numHost=0;
284 284
             $hostArray=array();
285
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
285
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
286 286
             {
287
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
288
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
287
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
288
+                $hostArray[$numHost]->name=$result->results[$numHost]->name;
289 289
                 $numHost++;
290 290
             }
291 291
             return $hostArray;
@@ -303,23 +303,23 @@  discard block
 block discarded – undo
303 303
      * @return array
304 304
      */
305 305
     public function request($method, $url, $headers, $body) {
306
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
307
-        $curlHeaders = array("Accept: application/json");
306
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
307
+        $curlHeaders=array("Accept: application/json");
308 308
         if ($body !== null) {
309
-            $body = json_encode($body);
309
+            $body=json_encode($body);
310 310
             array_push($curlHeaders, 'Content-Type: application/json');
311 311
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312 312
         }
313 313
         //var_dump($body);
314 314
         //var_dump($this->url($url));
315 315
         if ($headers !== null) {
316
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
316
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
317 317
         } else 
318 318
         {
319 319
             $curlFinalHeaders=$curlHeaders;
320 320
         }
321
-        $curl = $this->curl();
322
-        $opts = array(
321
+        $curl=$this->curl();
322
+        $opts=array(
323 323
             CURLOPT_URL		=> $this->url($url),
324 324
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325 325
             CURLOPT_USERPWD		=> $auth,
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
             CURLOPT_SSL_VERIFYPEER 	=> false,
331 331
         );
332 332
         if ($body !== null) {
333
-            $opts[CURLOPT_POSTFIELDS] = $body;
333
+            $opts[CURLOPT_POSTFIELDS]=$body;
334 334
         }
335 335
         curl_setopt_array($curl, $opts);
336
-        $res = curl_exec($curl);
336
+        $res=curl_exec($curl);
337 337
         if ($res === false) {
338
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
338
+            throw new Exception('CURL ERROR: '.curl_error($curl));
339 339
         }
340
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
340
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
341 341
         if ($statusCode === 401) {
342 342
             throw new Exception('Unable to authenticate, please check your API credentials');
343 343
         }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @return array json decoded
352 352
      */
353 353
     protected function fromJsonResult($json) {
354
-        $result = @json_decode($json);
354
+        $result=@json_decode($json);
355 355
         //var_dump($json);
356 356
         if ($result === null) {
357 357
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
Please login to merge, or discard this patch.
Braces   +8 added lines, -11 removed lines patch added patch discarded remove patch
@@ -74,18 +74,19 @@  discard block
 block discarded – undo
74 74
        try
75 75
         {
76 76
             $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
77
+        } catch (Exception $e)
79 78
         {
80 79
             return array(true, 'Error with API : '.$e->getMessage());
81 80
         }
82 81
         //var_dump($result);
83 82
         $permOk=1;
84 83
         $permMissing='';
85
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
84
+        if ($permissions === NULL || count($permissions) == 0) {
85
+        	// If no permission check return OK after connexion
86 86
         {
87 87
             return array(false,'OK');
88 88
         }
89
+        }
89 90
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90 91
         {
91 92
             
@@ -171,8 +172,7 @@  discard block
 block discarded – undo
171 172
             if (property_exists($result,'status'))
172 173
             {
173 174
                 $message=$result->status;
174
-            }
175
-            else 
175
+            } else 
176 176
             {
177 177
                 $message="Unkown status";
178 178
             }
@@ -183,8 +183,7 @@  discard block
 block discarded – undo
183 183
             if (isset($result->results[0]))
184 184
             {
185 185
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
-            }
187
-            else
186
+            } else
188 187
             {
189 188
                 return array(false,'Service not found');
190 189
             }
@@ -226,8 +225,7 @@  discard block
 block discarded – undo
226 225
             if (property_exists($result,'status'))
227 226
             {
228 227
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
-            }
230
-            else
228
+            } else
231 229
             {
232 230
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
233 231
             }
@@ -272,8 +270,7 @@  discard block
 block discarded – undo
272 270
             if (property_exists($result,'status'))
273 271
             {
274 272
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
-            }
276
-            else
273
+            } else
277 274
             {
278 275
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
279 276
             }
Please login to merge, or discard this patch.