Completed
Pull Request — master (#532)
06:37
created
install/index.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 <!-- page header -->
40 40
 <div id="header">
41 41
 <div class="hero-unit">
42
-	<a href="<?php print create_link(null); ?>">phpIPAM installation error</a>
42
+	<a href="<?php print create_link (null); ?>">phpIPAM installation error</a>
43 43
 </div>
44 44
 </div>
45 45
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		Make sure BASE directive is set for your installation. This is used to properly detect phpIPAM directory. It must be set in config.php and in .htaccess
56 56
 
57 57
 		<div class="well" style="padding:5px;margin-top:5px;">
58
-		Detected BASE: <?php print str_replace("install/", "", $_SERVER['REQUEST_URI']);  ?>
58
+		Detected BASE: <?php print str_replace ("install/", "", $_SERVER['REQUEST_URI']); ?>
59 59
 		</div>
60 60
 
61 61
 		<h4>2.) Enable mod_rewrite</h4>
Please login to merge, or discard this patch.
functions/checks/check_db_install.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 # initialize install class
6 6
 $Install = new Install ($Database);
7 7
 # try to connect, if it fails redirect to install
8
-$Install->check_db_connection(true);
8
+$Install->check_db_connection (true);
9 9
 # connection is ok, check that table exists
10
-$Install->check_table("vrf", true);
10
+$Install->check_table ("vrf", true);
11 11
 
12 12
 ?>
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
functions/classes/class.PDO.php 4 patches
Braces   +76 added lines, -33 removed lines patch added patch discarded remove patch
@@ -312,9 +312,15 @@  discard block
 block discarded – undo
312 312
 	 * @return void
313 313
 	 */
314 314
 	public function __construct($username = null, $password = null, $charset = null, $ssl = null) {
315
-		if (isset($username)) $this->username = $username;
316
-		if (isset($password)) $this->password = $password;
317
-		if (isset($charset))  $this->charset = $charset;
315
+		if (isset($username)) {
316
+		    $this->username = $username;
317
+		}
318
+		if (isset($password)) {
319
+		    $this->password = $password;
320
+		}
321
+		if (isset($charset)) {
322
+		    $this->charset = $charset;
323
+		}
318 324
 		# ssl
319 325
 		if ($ssl) {
320 326
 			$this->ssl = $ssl;
@@ -332,9 +338,11 @@  discard block
 block discarded – undo
332 338
 	public static function toDate($date = null) {
333 339
 		if (is_int($date)) {
334 340
 			return date('Y-m-d H:i:s', $date);
335
-		} else if (is_string($date)) {
341
+		}
342
+		else if (is_string($date)) {
336 343
 			return date('Y-m-d H:i:s', strtotime($date));
337
-		} else {
344
+		}
345
+		else {
338 346
 			return date('Y-m-d H:i:s');
339 347
 		}
340 348
 	}
@@ -419,12 +427,15 @@  discard block
 block discarded – undo
419 427
 		if ($len>1) {
420 428
 			if ($str[0] == "'" && $str[$len-1] == "'") {
421 429
 				return substr($str, 1, -1);
422
-			} else if ($str[0] == "'") {
430
+			}
431
+			else if ($str[0] == "'") {
423 432
 				return substr($str, 1);
424
-			} else if ($str[$len-1] == "'") {
433
+			}
434
+			else if ($str[$len-1] == "'") {
425 435
 				return substr($str, 0, -1);
426 436
 			}
427
-		} else if ($len>0) {
437
+		}
438
+		else if ($len>0) {
428 439
 			if ($str[0] == "'") {
429 440
 				return '';
430 441
 			}
@@ -463,7 +474,9 @@  discard block
 block discarded – undo
463 474
 	 * @return void
464 475
 	 */
465 476
 	public function runQuery($query, $values = array()) {
466
-		if (!$this->isConnected()) $this->connect();
477
+		if (!$this->isConnected()) {
478
+		    $this->connect();
479
+		}
467 480
 
468 481
 		$statement = $this->pdo->prepare($query);
469 482
 		//debuq
@@ -480,7 +493,9 @@  discard block
 block discarded – undo
480 493
 	 * @return void
481 494
 	 */
482 495
 	public function escape($str) {
483
-		if (!$this->isConnected()) $this->connect();
496
+		if (!$this->isConnected()) {
497
+		    $this->connect();
498
+		}
484 499
 
485 500
 		return $this->unquote_outer($this->pdo->quote((string)$str));
486 501
 	}
@@ -493,7 +508,9 @@  discard block
 block discarded – undo
493 508
 	 * @return void
494 509
 	 */
495 510
 	public function numObjects($tableName) {
496
-		if (!$this->isConnected()) $this->connect();
511
+		if (!$this->isConnected()) {
512
+		    $this->connect();
513
+		}
497 514
 
498 515
 		$tableName = $this->escape($tableName);
499 516
 		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;');
@@ -515,7 +532,9 @@  discard block
 block discarded – undo
515 532
 	 * @return void
516 533
 	 */
517 534
 	public function numObjectsFilter($tableName, $method, $value) {
518
-		if (!$this->isConnected()) $this->connect();
535
+		if (!$this->isConnected()) {
536
+		    $this->connect();
537
+		}
519 538
 
520 539
 		$tableName = $this->escape($tableName);
521 540
 		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'`=?;');
@@ -540,7 +559,9 @@  discard block
 block discarded – undo
540 559
 	 * @return void
541 560
 	 */
542 561
 	public function updateObject($tableName, $obj, $primarykey = 'id', $primarykey2 = null) {
543
-		if (!$this->isConnected()) $this->connect();
562
+		if (!$this->isConnected()) {
563
+		    $this->connect();
564
+		}
544 565
 
545 566
 		$obj = (array)$obj;
546 567
 
@@ -575,10 +596,12 @@  discard block
 block discarded – undo
575 596
 		$preparedParamStr = implode(',', $preparedParamArr);
576 597
 
577 598
 		//primary key 2?
578
-		if(!is_null($primarykey2))
579
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;');
580
-		else
581
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;');
599
+		if(!is_null($primarykey2)) {
600
+				$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;');
601
+		}
602
+		else {
603
+				$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;');
604
+		}
582 605
 
583 606
 		//merge the parameters and values
584 607
 		$paramValues = array_merge(array_values($obj), $objId);
@@ -627,7 +650,9 @@  discard block
 block discarded – undo
627 650
 	 * @return void
628 651
 	 */
629 652
 	public function insertObject($tableName, $obj, $raw = false, $replace = false) {
630
-		if (!$this->isConnected()) $this->connect();
653
+		if (!$this->isConnected()) {
654
+		    $this->connect();
655
+		}
631 656
 
632 657
 		$obj = (array)$obj;
633 658
 
@@ -654,7 +679,8 @@  discard block
 block discarded – undo
654 679
 
655 680
 		if ($replace) {
656 681
 			$statement = $this->pdo->prepare('REPLACE INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
657
-		} else {
682
+		}
683
+		else {
658 684
 			$statement = $this->pdo->prepare('INSERT INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
659 685
 		}
660 686
 
@@ -697,7 +723,9 @@  discard block
 block discarded – undo
697 723
 	 * @return void
698 724
 	 */
699 725
 	public function getObjects($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') {
700
-		if (!$this->isConnected()) $this->connect();
726
+		if (!$this->isConnected()) {
727
+		    $this->connect();
728
+		}
701 729
 
702 730
 		$sortStr = '';
703 731
 		if (!$sortAsc) {
@@ -711,7 +739,8 @@  discard block
 block discarded – undo
711 739
 		if ($numRecords === null) {
712 740
 			//get all (no limit)
713 741
 			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';');
714
-		} else {
742
+		}
743
+		else {
715 744
 			//get a limited range of objects
716 745
 			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';');
717 746
 		}
@@ -738,7 +767,9 @@  discard block
 block discarded – undo
738 767
 	 * @return void
739 768
 	 */
740 769
 	public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) {
741
-		if (!$this->isConnected()) $this->connect();
770
+		if (!$this->isConnected()) {
771
+		    $this->connect();
772
+		}
742 773
 
743 774
 		$statement = $this->pdo->prepare($query);
744 775
 
@@ -770,7 +801,9 @@  discard block
 block discarded – undo
770 801
 	 * @return void
771 802
 	 */
772 803
 	public function getObjectsQuery($query = null, $values = array(), $class = 'stdClass') {
773
-		if (!$this->isConnected()) $this->connect();
804
+		if (!$this->isConnected()) {
805
+		    $this->connect();
806
+		}
774 807
 
775 808
 		$statement = $this->pdo->prepare($query);
776 809
 
@@ -799,7 +832,9 @@  discard block
 block discarded – undo
799 832
 	 * @return void
800 833
 	 */
801 834
 	public function getObject($tableName, $id = null, $class = 'stdClass') {
802
-		if (!$this->isConnected()) $this->connect();
835
+		if (!$this->isConnected()) {
836
+		    $this->connect();
837
+		}
803 838
 		$id = intval($id);
804 839
 
805 840
 		//has a custom query been provided?
@@ -809,7 +844,8 @@  discard block
 block discarded – undo
809 844
 		if ($id !== null) {
810 845
 			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;');
811 846
 			$statement->bindParam(1, $id, \PDO::PARAM_INT);
812
-		} else {
847
+		}
848
+		else {
813 849
 			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` LIMIT 1;');
814 850
 		}
815 851
 
@@ -822,7 +858,8 @@  discard block
 block discarded – undo
822 858
 
823 859
 		if ($resultObj === false) {
824 860
 			return null;
825
-		} else {
861
+		}
862
+		else {
826 863
 			return $resultObj;
827 864
 		}
828 865
 	}
@@ -837,7 +874,9 @@  discard block
 block discarded – undo
837 874
 	 * @return void
838 875
 	 */
839 876
 	public function getObjectQuery($query = null, $values = array(), $class = 'stdClass') {
840
-		if (!$this->isConnected()) $this->connect();
877
+		if (!$this->isConnected()) {
878
+		    $this->connect();
879
+		}
841 880
 
842 881
 		$statement = $this->pdo->prepare($query);
843 882
 		//debuq
@@ -848,7 +887,8 @@  discard block
 block discarded – undo
848 887
 
849 888
 		if ($resultObj === false) {
850 889
 			return null;
851
-		} else {
890
+		}
891
+		else {
852 892
 			return $resultObj;
853 893
 		}
854 894
 	}
@@ -868,7 +908,8 @@  discard block
 block discarded – undo
868 908
 		if (is_object($obj)) {
869 909
 			$obj = (array)$obj;
870 910
 			return reset($obj);
871
-		} else {
911
+		}
912
+		else {
872 913
 			return null;
873 914
 		}
874 915
 	}
@@ -975,10 +1016,12 @@  discard block
 block discarded – undo
975 1016
 		$field = $this->escape($field);
976 1017
 
977 1018
 		//multiple
978
-		if(!is_null($field2))
979
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2));
980
-		else
981
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value));
1019
+		if(!is_null($field2)) {
1020
+				return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2));
1021
+		}
1022
+		else {
1023
+				return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value));
1024
+		}
982 1025
 	}
983 1026
 
984 1027
 	/**
Please login to merge, or discard this patch.
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @access public
89 89
 	 * @param mixed $username (default: null)
90 90
 	 * @param mixed $password (default: null)
91
-	 * @param mixed $charset (default: null)
91
+	 * @param string $charset (default: null)
92 92
 	 * @param mixed $ssl (default: null)
93 93
 	 * @return void
94 94
 	 */
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @access public
109 109
 	 * @static
110 110
 	 * @param mixed $date (default: null)
111
-	 * @return void
111
+	 * @return string
112 112
 	 */
113 113
 	public static function toDate($date = null) {
114 114
 		if (is_int($date)) {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * makeDsn function.
153 153
 	 *
154 154
 	 * @access protected
155
-	 * @return void
155
+	 * @return string
156 156
 	 */
157 157
 	protected function makeDsn() {
158 158
 		return ':charset=' . $this->charset;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * Are we currently connected to the database
219 219
 	 *
220 220
 	 * @access public
221
-	 * @return void
221
+	 * @return boolean
222 222
 	 */
223 223
 	public function isConnected() {
224 224
 		return ($this->pdo !== null);
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * Note: no objects are fetched
240 240
 	 *
241 241
 	 * @access public
242
-	 * @param mixed $query
242
+	 * @param string $query
243 243
 	 * @param array $values (default: array())
244 244
 	 * @return void
245 245
 	 */
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 	 * @param string $query (default: null)
464 464
 	 * @param array $values (default: array())
465 465
 	 * @param mixed $id (default: null)
466
-	 * @return void
466
+	 * @return boolean
467 467
 	 */
468 468
 	public function objectExists($tableName, $query = null, $values = array(), $id = null) {
469 469
 		return is_object($this->getObject($tableName, $id));
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 	 * @param mixed $query (default: null)
521 521
 	 * @param array $values (default: array())
522 522
 	 * @param mixed $callback (default: null)
523
-	 * @return void
523
+	 * @return boolean
524 524
 	 */
525 525
 	public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) {
526 526
 		if (!$this->isConnected()) $this->connect();
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 	 * Get a single object from the database
579 579
 	 *
580 580
 	 * @access public
581
-	 * @param mixed $tableName
581
+	 * @param string $tableName
582 582
 	 * @param mixed $id (default: null)
583 583
 	 * @param string $class (default: 'stdClass')
584 584
 	 * @return void
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 	 * makeDsn function
907 907
 	 *
908 908
 	 * @access protected
909
-	 * @return void
909
+	 * @return string
910 910
 	 */
911 911
 	protected function makeDsn() {
912 912
 		# for installation
Please login to merge, or discard this patch.
Indentation   +936 added lines, -936 removed lines patch added patch discarded remove patch
@@ -8,777 +8,777 @@  discard block
 block discarded – undo
8 8
 abstract class DB {
9 9
 
10 10
 
11
-	/**
12
-	 * Default db username
13
-	 *
14
-	 * (default value: null)
15
-	 *
16
-	 * @var mixed
17
-	 * @access protected
18
-	 */
19
-	protected $username = null;
20
-
21
-	/**
22
-	 * Default db password
23
-	 *
24
-	 * (default value: null)
25
-	 *
26
-	 * @var mixed
27
-	 * @access protected
28
-	 */
29
-	protected $password = null;
30
-
31
-	/**
32
-	 * charset
33
-	 *
34
-	 * (default value: 'utf8')
35
-	 *
36
-	 * @var string
37
-	 * @access protected
38
-	 */
39
-	protected $charset = 'utf8';
40
-
41
-	/**
42
-	 * pdo
43
-	 *
44
-	 * (default value: null)
45
-	 *
46
-	 * @var mixed
47
-	 * @access protected
48
-	 */
49
-	protected $pdo = null;
50
-
51
-	/**
52
-	 * Database name - needed for check
53
-	 *
54
-	 * (default value: '')
55
-	 *
56
-	 * @var string
57
-	 * @access public
58
-	 */
59
-	public $dbname 	= '';		// needed for DB check
60
-
61
-	/**
62
-	 * hosnamr
63
-	 *
64
-	 * (default value: 'localhost')
65
-	 *
66
-	 * @var string
67
-	 * @access protected
68
-	 */
69
-	protected $host 	= 'localhost';
70
-
71
-	/**
72
-	 * Default port number
73
-	 *
74
-	 * (default value: '3306')
75
-	 *
76
-	 * @var string
77
-	 * @access protected
78
-	 */
79
-	protected $port 	= '3306';
80
-
81
-
82
-
83
-
84
-
85
-	/**
86
-	 * __construct function.
87
-	 *
88
-	 * @access public
89
-	 * @param mixed $username (default: null)
90
-	 * @param mixed $password (default: null)
91
-	 * @param mixed $charset (default: null)
92
-	 * @param mixed $ssl (default: null)
93
-	 * @return void
94
-	 */
95
-	public function __construct($username = null, $password = null, $charset = null, $ssl = null) {
96
-		if (isset($username)) $this->username = $username;
97
-		if (isset($password)) $this->password = $password;
98
-		if (isset($charset))  $this->charset = $charset;
99
-		# ssl
100
-		if ($ssl) {
101
-			$this->ssl = $ssl;
102
-		}
103
-	}
104
-
105
-	/**
106
-	 * convert a date object/string ready for use in sql
107
-	 *
108
-	 * @access public
109
-	 * @static
110
-	 * @param mixed $date (default: null)
111
-	 * @return void
112
-	 */
113
-	public static function toDate($date = null) {
114
-		if (is_int($date)) {
115
-			return date('Y-m-d H:i:s', $date);
116
-		} else if (is_string($date)) {
117
-			return date('Y-m-d H:i:s', strtotime($date));
118
-		} else {
119
-			return date('Y-m-d H:i:s');
120
-		}
121
-	}
122
-
123
-	/**
124
-	 * Connect to the database
125
-	 * Call whenever a connection is needed to be made
126
-	 *
127
-	 * @access public
128
-	 * @return void
129
-	 */
130
-	public function connect() {
131
-		$dsn = $this->makeDsn();
132
-
133
-		try {
134
-			# ssl?
135
-			if ($this->ssl) {
136
-				$this->pdo = new \PDO($dsn, $this->username, $this->password, $this->ssl);
137
-			}
138
-			else {
139
-				$this->pdo = new \PDO($dsn, $this->username, $this->password);
140
-			}
141
-
142
-			$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
143
-
144
-		} catch (\PDOException $e) {
145
-			throw new Exception ("Could not connect to database! ".$e->getMessage());
146
-		}
147
-
148
-		@$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
149
-	}
150
-
151
-	/**
152
-	 * makeDsn function.
153
-	 *
154
-	 * @access protected
155
-	 * @return void
156
-	 */
157
-	protected function makeDsn() {
158
-		return ':charset=' . $this->charset;
159
-	}
160
-
161
-	/**
162
-	 * resets conection.
163
-	 *
164
-	 * @access public
165
-	 * @return void
166
-	 */
167
-	public function resetConn() {
168
-		unset($this->pdo);
169
-		$this->install = false;
170
-	}
171
-
172
-	/**
173
-	 * logs queries to file
174
-	 *
175
-	 * @access private
176
-	 * @param mixed $query
177
-	 * @return void
178
-	 */
179
-	private function log_query ($query) {
180
-		if($this->debug) {
181
-
182
-			$myFile = "/tmp/queries.txt";
183
-			$fh = fopen($myFile, 'a') or die("can't open file");
184
-			fwrite($fh, $query->queryString."\n");
185
-			fclose($fh);
186
-		}
187
-	}
188
-
189
-	/**
190
-	 * Remove outer quotes from a string
191
-	 *
192
-	 * @access public
193
-	 * @static
194
-	 * @param mixed $str
195
-	 * @return void
196
-	 */
197
-	public static function unquote_outer($str) {
198
-		$len = strlen($str);
199
-
200
-		if ($len>1) {
201
-			if ($str[0] == "'" && $str[$len-1] == "'") {
202
-				return substr($str, 1, -1);
203
-			} else if ($str[0] == "'") {
204
-				return substr($str, 1);
205
-			} else if ($str[$len-1] == "'") {
206
-				return substr($str, 0, -1);
207
-			}
208
-		} else if ($len>0) {
209
-			if ($str[0] == "'") {
210
-				return '';
211
-			}
212
-		}
213
-
214
-		return $str;
215
-	}
216
-
217
-	/**
218
-	 * Are we currently connected to the database
219
-	 *
220
-	 * @access public
221
-	 * @return void
222
-	 */
223
-	public function isConnected() {
224
-		return ($this->pdo !== null);
225
-	}
226
-
227
-	/**
228
-	 * Returns last insert ID
229
-	 *
230
-	 * @access public
231
-	 * @return void
232
-	 */
233
-	public function lastInsertId() {
234
-		return $this->pdo->lastInsertId();
235
-	}
236
-
237
-	/**
238
-	 * Run a statement on the database
239
-	 * Note: no objects are fetched
240
-	 *
241
-	 * @access public
242
-	 * @param mixed $query
243
-	 * @param array $values (default: array())
244
-	 * @return void
245
-	 */
246
-	public function runQuery($query, $values = array()) {
247
-		if (!$this->isConnected()) $this->connect();
248
-
249
-		$statement = $this->pdo->prepare($query);
250
-		//debuq
251
-		$this->log_query ($statement);
252
-		return $statement->execute((array)$values); //this array cast allows single values to be used as the parameter
253
-	}
254
-
255
-	/**
256
-	 * Allow a value to be escaped, ready for insertion as a mysql parameter
257
-	 * Note: for usage as a value (rather than prepared statements), you MUST manually quote around.
258
-	 *
259
-	 * @access public
260
-	 * @param mixed $str
261
-	 * @return void
262
-	 */
263
-	public function escape($str) {
264
-		if (!$this->isConnected()) $this->connect();
265
-
266
-		return $this->unquote_outer($this->pdo->quote((string)$str));
267
-	}
268
-
269
-	/**
270
-	 * Get a quick number of objects in a table
271
-	 *
272
-	 * @access public
273
-	 * @param mixed $tableName
274
-	 * @return void
275
-	 */
276
-	public function numObjects($tableName) {
277
-		if (!$this->isConnected()) $this->connect();
278
-
279
-		$tableName = $this->escape($tableName);
280
-		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;');
281
-
282
-		//debuq
283
-		$this->log_query ($statement);
284
-		$statement->execute();
285
-
286
-		return $statement->fetchColumn();
287
-    }
288
-
289
-	/**
290
-	 * Get a quick number of objects in a table for filtered field
291
-	 *
292
-	 * @access public
293
-	 * @param mixed $tableName
294
-	 * @param mixed $method
295
-	 * @param boolean $like (default: false)
296
-	 * @param mixed $value
297
-	 * @return void
298
-	 */
299
-	public function numObjectsFilter($tableName, $method, $value, $like = false) {
300
-		if (!$this->isConnected()) $this->connect();
301
-
302
-		$like === true ? $operator = "LIKE" : $operator = "=";
303
-
304
-		$tableName = $this->escape($tableName);
305
-		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'` '.$operator.' ?;');
306
-
307
-		//debuq
308
-		$this->log_query ($statement);
309
-		$statement->execute(array($value));
310
-
311
-		return $statement->fetchColumn();
312
-	}
313
-
314
-	/**
315
-	 * Update an object in a table with values given
316
-	 *
317
-	 * Note: the id of the object is assumed to be in.
318
-	 *
319
-	 * @access public
320
-	 * @param mixed $tableName
321
-	 * @param mixed $obj
322
-	 * @param string $primarykey (default: 'id')
323
-	 * @param mixed $primarykey2 (default: null)
324
-	 * @return void
325
-	 */
326
-	public function updateObject($tableName, $obj, $primarykey = 'id', $primarykey2 = null) {
327
-		if (!$this->isConnected()) $this->connect();
328
-
329
-		$obj = (array)$obj;
330
-
331
-		//we cannot update an object without an id specified so quit
332
-		if (!isset($obj[$primarykey])) {
333
-			throw new Exception('Missing primary key');
334
-			return false;
335
-		}
336
-
337
-		$tableName = $this->escape($tableName);
338
-
339
-		//get the objects id from the provided object and knock it off from the object so we dont try to update it
340
-		$objId[] = $obj[$primarykey];
341
-		unset($obj[$primarykey]);
342
-
343
-		//secondary primary key?
344
-		if(!is_null($primarykey2)) {
345
-		$objId[] = $obj[$primarykey2];
346
-		unset($obj[$primarykey2]);
347
-		}
348
-
349
-		//TODO: validate given object parameters with that of the table (this validates parameters names)
350
-
351
-		//formulate an update statement based on the object parameters
352
-		$objParams = array_keys($obj);
353
-
354
-		$preparedParamArr = array();
355
-		foreach ($objParams as $objParam) {
356
-			$preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
357
-		}
358
-
359
-		$preparedParamStr = implode(',', $preparedParamArr);
360
-
361
-		//primary key 2?
362
-		if(!is_null($primarykey2))
363
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;');
364
-		else
365
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;');
366
-
367
-		//merge the parameters and values
368
-		$paramValues = array_merge(array_values($obj), $objId);
369
-
370
-		//debuq
371
-		$this->log_query ($statement);
372
-		//run the update on the object
373
-		return $statement->execute($paramValues);
374
-	}
375
-
376
-	/**
377
-	 * Update multiple objects at once.
378
-	 *
379
-	 * @access public
380
-	 * @param string $tableName
381
-	 * @param array $ids
382
-	 * @param array $values
383
-	 * @return void
384
-	 */
385
-	public function updateMultipleObjects($tableName, $ids, $values) {
386
-		$tableName = $this->escape($tableName);
387
-		//set ids
388
-		$num = count($ids);
389
-		$idParts = array_fill(0, $num, '`id`=?');
390
-		//set values
391
-		$objParams = array_keys($values);
392
-		$preparedParamArr = array();
393
-		foreach ($objParams as $objParam) {
394
-			$preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
395
-		}
396
-		//set values
397
-		$all_values = array_merge(array_values($values),$ids);
398
-		//execute
399
-		return $this->runQuery('UPDATE `'.$tableName.'` SET '.implode(',', $preparedParamArr).'  WHERE '.implode(' OR ', $idParts), $all_values);
400
-	}
401
-
402
-	/**
403
-	 * Insert an object into a table
404
-	 * Note: an id field is ignored if specified.
405
-	 *
406
-	 * @access public
407
-	 * @param string $tableName
408
-	 * @param object|array $obj
409
-	 * @param bool $raw (default: false)
410
-	 * @param bool $replace (default: false)
411
-	 * @param bool $ignoreId (default: true)
412
-	 * @return void
413
-	 */
414
-	public function insertObject($tableName, $obj, $raw = false, $replace = false, $ignoreId = true) {
415
-		if (!$this->isConnected()) $this->connect();
416
-
417
-		$obj = (array)$obj;
418
-
419
-		$tableName = $this->escape($tableName);
420
-
421
-		if (!$raw && array_key_exists('id', $obj) && $ignoreId) {
422
-			unset($obj['id']);
423
-		}
424
-
425
-		if (count($obj)<1) {
426
-			return true;
427
-		}
428
-
429
-		//formulate an update statement based on the object parameters
430
-		$objValues = array_values($obj);
431
-
432
-		$preparedParamsArr = array();
433
-		foreach ($obj as $key => $value) {
434
-			$preparedParamsArr[] = '`' . $this->escape($key) . '`';
435
-		}
436
-
437
-		$preparedParamsStr = implode(', ', $preparedParamsArr);
438
-		$preparedValuesStr = implode(', ', array_fill(0, count($objValues), '?'));
439
-
440
-		if ($replace) {
441
-			$statement = $this->pdo->prepare('REPLACE INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
442
-		} else {
443
-			$statement = $this->pdo->prepare('INSERT INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
444
-		}
445
-
446
-		//run the update on the object
447
-		if (!$statement->execute($objValues)) {
448
-			$errObj = $statement->errorInfo();
449
-
450
-			//return false;
451
-			throw new Exception($errObj[2]);
452
-		}
453
-
454
-		return $this->pdo->lastInsertId();
455
-	}
456
-
457
-
458
-	/**
459
-	 * Check if an object exists.
460
-	 *
461
-	 * @access public
462
-	 * @param string $tableName
463
-	 * @param string $query (default: null)
464
-	 * @param array $values (default: array())
465
-	 * @param mixed $id (default: null)
466
-	 * @return void
467
-	 */
468
-	public function objectExists($tableName, $query = null, $values = array(), $id = null) {
469
-		return is_object($this->getObject($tableName, $id));
470
-	}
471
-
472
-	/**
473
-	 * Get a filtered list of objects from the database.
474
-	 *
475
-	 * @access public
476
-	 * @param string $tableName
477
-	 * @param string $sortField (default: 'id')
478
-	 * @param bool $sortAsc (default: true)
479
-	 * @param mixed $numRecords (default: null)
480
-	 * @param int $offset (default: 0)
481
-	 * @param string $class (default: 'stdClass')
482
-	 * @return void
483
-	 */
484
-	public function getObjects($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') {
485
-		if (!$this->isConnected()) $this->connect();
486
-
487
-		$sortStr = '';
488
-		if (!$sortAsc) {
489
-			$sortStr = 'DESC';
490
-		}
491
-
492
-		//we should escape all of the params that we need to
493
-		$tableName = $this->escape($tableName);
494
-		$sortField = $this->escape($sortField);
495
-
496
-		if ($numRecords === null) {
497
-			//get all (no limit)
498
-			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';');
499
-		} else {
500
-			//get a limited range of objects
501
-			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';');
502
-		}
503
-
504
-		$results = array();
505
-
506
-		if (is_object($statement)) {
507
-			while ($newObj = $statement->fetchObject($class)) {
508
-				$results[] = $newObj;
509
-			}
510
-		}
511
-
512
-		return $results;
513
-	}
514
-
515
-
516
-	/**
517
-	 * use this function to conserve memory and read rows one by one rather than reading all of them
518
-	 *
519
-	 * @access public
520
-	 * @param mixed $query (default: null)
521
-	 * @param array $values (default: array())
522
-	 * @param mixed $callback (default: null)
523
-	 * @return void
524
-	 */
525
-	public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) {
526
-		if (!$this->isConnected()) $this->connect();
527
-
528
-		$statement = $this->pdo->prepare($query);
529
-
530
-		//debuq
531
-		$this->log_query ($statement);
532
-		$statement->execute((array)$values);
533
-
534
-		if (is_object($statement)) {
535
-			if ($callback) {
536
-				while ($newObj = $statement->fetchObject('stdClass')) {
537
-					if ($callback($newObj)===false) {
538
-						return false;
539
-					}
540
-				}
541
-			}
542
-		}
543
-
544
-		return true;
545
-	}
546
-
547
-
548
-	/**
549
-	 * Get all objects matching values
550
-	 *
551
-	 * @access public
552
-	 * @param mixed $query (default: null)
553
-	 * @param array $values (default: array())
554
-	 * @param string $class (default: 'stdClass')
555
-	 * @return void
556
-	 */
557
-	public function getObjectsQuery($query = null, $values = array(), $class = 'stdClass') {
558
-		if (!$this->isConnected()) $this->connect();
559
-
560
-		$statement = $this->pdo->prepare($query);
561
-
562
-		//debug
563
-		$this->log_query ($statement);
564
-		$statement->execute((array)$values);
565
-
566
-		$results = array();
567
-
568
-		if (is_object($statement)) {
569
-			while ($newObj = $statement->fetchObject($class)) {
570
-				$results[] = $newObj;
571
-			}
572
-		}
573
-
574
-		return $results;
575
-	}
576
-
577
-	/**
578
-	 * Get a single object from the database
579
-	 *
580
-	 * @access public
581
-	 * @param mixed $tableName
582
-	 * @param mixed $id (default: null)
583
-	 * @param string $class (default: 'stdClass')
584
-	 * @return void
585
-	 */
586
-	public function getObject($tableName, $id = null, $class = 'stdClass') {
587
-		if (!$this->isConnected()) $this->connect();
588
-		$id = intval($id);
589
-
590
-		//has a custom query been provided?
591
-		$tableName = $this->escape($tableName);
592
-
593
-		//prepare a statement to get a single object from the database
594
-		if ($id !== null) {
595
-			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;');
596
-			$statement->bindParam(1, $id, \PDO::PARAM_INT);
597
-		} else {
598
-			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` LIMIT 1;');
599
-		}
600
-
601
-		//debuq
602
-		$this->log_query ($statement);
603
-		$statement->execute();
604
-
605
-		//we can then extract the single object (if we have a result)
606
-		$resultObj = $statement->fetchObject($class);
607
-
608
-		if ($resultObj === false) {
609
-			return null;
610
-		} else {
611
-			return $resultObj;
612
-		}
613
-	}
614
-
615
-	/**
616
-	 * Fetches single object from provided query
617
-	 *
618
-	 * @access public
619
-	 * @param mixed $query (default: null)
620
-	 * @param array $values (default: array())
621
-	 * @param string $class (default: 'stdClass')
622
-	 * @return void
623
-	 */
624
-	public function getObjectQuery($query = null, $values = array(), $class = 'stdClass') {
625
-		if (!$this->isConnected()) $this->connect();
626
-
627
-		$statement = $this->pdo->prepare($query);
628
-		//debuq
629
-		$this->log_query ($statement);
630
-		$statement->execute((array)$values);
631
-
632
-		$resultObj = $statement->fetchObject($class);
633
-
634
-		if ($resultObj === false) {
635
-			return null;
636
-		} else {
637
-			return $resultObj;
638
-		}
639
-	}
640
-
641
-	/**
642
-	 * Get single value
643
-	 *
644
-	 * @access public
645
-	 * @param mixed $query (default: null)
646
-	 * @param array $values (default: array())
647
-	 * @param string $class (default: 'stdClass')
648
-	 * @return void
649
-	 */
650
-	public function getValueQuery($query = null, $values = array(), $class = 'stdClass') {
651
-		$obj = $this->getObjectQuery($query, $values, $class);
652
-
653
-		if (is_object($obj)) {
654
-			$obj = (array)$obj;
655
-			return reset($obj);
656
-		} else {
657
-			return null;
658
-		}
659
-	}
660
-
661
-	/**
662
-	 * Searches for object in database
663
-	 *
664
-	 * @access public
665
-	 * @param mixed $table
666
-	 * @param mixed $field
667
-	 * @param mixed $value
668
-	 * @param string $sortField (default: 'id')
669
-	 * @param bool $sortAsc (default: true)
670
-	 * @param bool $like (default: false)
671
-	 * @param bool $negate (default: false)
672
-	 * @return void
673
-	 */
674
-	public function findObjects($table, $field, $value, $sortField = 'id', $sortAsc = true, $like = false, $negate = false) {
675
-		$table = $this->escape($table);
676
-		$field = $this->escape($field);
677
-		$sortField = $this->escape($sortField);
678
-		$like === true ? $operator = "LIKE" : $operator = "=";
679
-		$negate === true ? $negate_operator = "NOT " : $negate_operator = "";
680
-
681
-		return $this->getObjectsQuery('SELECT * FROM `' . $table . '` WHERE `'. $field .'`'.$negate_operator. $operator .'? ORDER BY `'.$sortField.'` ' . ($sortAsc ? '' : 'DESC') . ';', array($value));
682
-	}
683
-
684
-	/**
685
-	 * Searches for single object.
686
-	 *
687
-	 * @access public
688
-	 * @param mixed $table
689
-	 * @param mixed $field
690
-	 * @param mixed $value
691
-	 * @return void
692
-	 */
693
-	public function findObject($table, $field, $value) {
694
-		$table = $this->escape($table);
695
-		$field = $this->escape($field);
696
-
697
-		return $this->getObjectQuery('SELECT * FROM `' . $table . '` WHERE `' . $field . '` = ? LIMIT 1;', array($value));
698
-	}
699
-
700
-	/**
701
-	 * Get list of items.
702
-	 *
703
-	 * @access public
704
-	 * @param mixed $query (default: null)
705
-	 * @param array $values (default: array())
706
-	 * @param string $class (default: 'stdClass')
707
-	 * @return void
708
-	 */
709
-	public function getList($query = null, $values = array(), $class = 'stdClass') {
710
-		$objs = $this->getObjectsQuery($query, $values, $class);
711
-
712
-		$list = array();
713
-		foreach ($objs as $obj) {
714
-			$columns = array_values((array)$obj);
715
-			$list[] = $columns[0];
716
-		}
717
-
718
-		return $list;
719
-	}
720
-
721
-	/**
722
-	* Delete an object from the database
723
-	*
724
-	* @param {string} table name
725
-	* @param {int} object id
726
-	* @return {boolean} success
727
-	*/
728
-	public function deleteObject($tableName, $id) {
729
-		$tableName = $this->escape($tableName);
730
-
731
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `id`=?;', array($id));
732
-	}
733
-
734
-	/**
735
-	* Delete a list of objects from the database
736
-	*
737
-	* @param {string} table name
738
-	* @param {array} list of ids
739
-	* @return {boolean} success
740
-	*/
741
-	public function deleteObjects($tableName, $ids) {
742
-		$tableName = $this->escape($tableName);
743
-		$num = count($ids);
744
-		$idParts = array_fill(0, $num, '`id`=?');
745
-
746
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE ' . implode(' OR ', $idParts), $ids);
747
-	}
748
-
749
-	/**
750
-	 * Delete specified row
751
-	 *
752
-	 * @access public
753
-	 * @param {string} $tableName
754
-	 * @param {string $field
755
-	 * @param {string $value
756
-	 * @return void
757
-	 */
758
-	public function deleteRow($tableName, $field, $value, $field2=null, $value2 = null) {
759
-		$tableName = $this->escape($tableName);
760
-		$field = $this->escape($field);
761
-
762
-		//multiple
763
-		if(!is_null($field2))
764
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2));
765
-		else
766
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value));
767
-	}
768
-
769
-	/**
770
-	 * truncate specified table
771
-	 *
772
-	 * @access public
773
-	 * @param {string} $tableName
774
-	 * @return void
775
-	 */
776
-	public function emptyTable($tableName) {
777
-		//escape talbe name
778
-		$tableName = $this->escape($tableName);
779
-		//execute
780
-		return $this->runQuery('TRUNCATE TABLE `'.$tableName.'`;');
781
-	}
11
+    /**
12
+     * Default db username
13
+     *
14
+     * (default value: null)
15
+     *
16
+     * @var mixed
17
+     * @access protected
18
+     */
19
+    protected $username = null;
20
+
21
+    /**
22
+     * Default db password
23
+     *
24
+     * (default value: null)
25
+     *
26
+     * @var mixed
27
+     * @access protected
28
+     */
29
+    protected $password = null;
30
+
31
+    /**
32
+     * charset
33
+     *
34
+     * (default value: 'utf8')
35
+     *
36
+     * @var string
37
+     * @access protected
38
+     */
39
+    protected $charset = 'utf8';
40
+
41
+    /**
42
+     * pdo
43
+     *
44
+     * (default value: null)
45
+     *
46
+     * @var mixed
47
+     * @access protected
48
+     */
49
+    protected $pdo = null;
50
+
51
+    /**
52
+     * Database name - needed for check
53
+     *
54
+     * (default value: '')
55
+     *
56
+     * @var string
57
+     * @access public
58
+     */
59
+    public $dbname 	= '';		// needed for DB check
60
+
61
+    /**
62
+     * hosnamr
63
+     *
64
+     * (default value: 'localhost')
65
+     *
66
+     * @var string
67
+     * @access protected
68
+     */
69
+    protected $host 	= 'localhost';
70
+
71
+    /**
72
+     * Default port number
73
+     *
74
+     * (default value: '3306')
75
+     *
76
+     * @var string
77
+     * @access protected
78
+     */
79
+    protected $port 	= '3306';
80
+
81
+
82
+
83
+
84
+
85
+    /**
86
+     * __construct function.
87
+     *
88
+     * @access public
89
+     * @param mixed $username (default: null)
90
+     * @param mixed $password (default: null)
91
+     * @param mixed $charset (default: null)
92
+     * @param mixed $ssl (default: null)
93
+     * @return void
94
+     */
95
+    public function __construct($username = null, $password = null, $charset = null, $ssl = null) {
96
+        if (isset($username)) $this->username = $username;
97
+        if (isset($password)) $this->password = $password;
98
+        if (isset($charset))  $this->charset = $charset;
99
+        # ssl
100
+        if ($ssl) {
101
+            $this->ssl = $ssl;
102
+        }
103
+    }
104
+
105
+    /**
106
+     * convert a date object/string ready for use in sql
107
+     *
108
+     * @access public
109
+     * @static
110
+     * @param mixed $date (default: null)
111
+     * @return void
112
+     */
113
+    public static function toDate($date = null) {
114
+        if (is_int($date)) {
115
+            return date('Y-m-d H:i:s', $date);
116
+        } else if (is_string($date)) {
117
+            return date('Y-m-d H:i:s', strtotime($date));
118
+        } else {
119
+            return date('Y-m-d H:i:s');
120
+        }
121
+    }
122
+
123
+    /**
124
+     * Connect to the database
125
+     * Call whenever a connection is needed to be made
126
+     *
127
+     * @access public
128
+     * @return void
129
+     */
130
+    public function connect() {
131
+        $dsn = $this->makeDsn();
132
+
133
+        try {
134
+            # ssl?
135
+            if ($this->ssl) {
136
+                $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->ssl);
137
+            }
138
+            else {
139
+                $this->pdo = new \PDO($dsn, $this->username, $this->password);
140
+            }
141
+
142
+            $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
143
+
144
+        } catch (\PDOException $e) {
145
+            throw new Exception ("Could not connect to database! ".$e->getMessage());
146
+        }
147
+
148
+        @$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
149
+    }
150
+
151
+    /**
152
+     * makeDsn function.
153
+     *
154
+     * @access protected
155
+     * @return void
156
+     */
157
+    protected function makeDsn() {
158
+        return ':charset=' . $this->charset;
159
+    }
160
+
161
+    /**
162
+     * resets conection.
163
+     *
164
+     * @access public
165
+     * @return void
166
+     */
167
+    public function resetConn() {
168
+        unset($this->pdo);
169
+        $this->install = false;
170
+    }
171
+
172
+    /**
173
+     * logs queries to file
174
+     *
175
+     * @access private
176
+     * @param mixed $query
177
+     * @return void
178
+     */
179
+    private function log_query ($query) {
180
+        if($this->debug) {
181
+
182
+            $myFile = "/tmp/queries.txt";
183
+            $fh = fopen($myFile, 'a') or die("can't open file");
184
+            fwrite($fh, $query->queryString."\n");
185
+            fclose($fh);
186
+        }
187
+    }
188
+
189
+    /**
190
+     * Remove outer quotes from a string
191
+     *
192
+     * @access public
193
+     * @static
194
+     * @param mixed $str
195
+     * @return void
196
+     */
197
+    public static function unquote_outer($str) {
198
+        $len = strlen($str);
199
+
200
+        if ($len>1) {
201
+            if ($str[0] == "'" && $str[$len-1] == "'") {
202
+                return substr($str, 1, -1);
203
+            } else if ($str[0] == "'") {
204
+                return substr($str, 1);
205
+            } else if ($str[$len-1] == "'") {
206
+                return substr($str, 0, -1);
207
+            }
208
+        } else if ($len>0) {
209
+            if ($str[0] == "'") {
210
+                return '';
211
+            }
212
+        }
213
+
214
+        return $str;
215
+    }
216
+
217
+    /**
218
+     * Are we currently connected to the database
219
+     *
220
+     * @access public
221
+     * @return void
222
+     */
223
+    public function isConnected() {
224
+        return ($this->pdo !== null);
225
+    }
226
+
227
+    /**
228
+     * Returns last insert ID
229
+     *
230
+     * @access public
231
+     * @return void
232
+     */
233
+    public function lastInsertId() {
234
+        return $this->pdo->lastInsertId();
235
+    }
236
+
237
+    /**
238
+     * Run a statement on the database
239
+     * Note: no objects are fetched
240
+     *
241
+     * @access public
242
+     * @param mixed $query
243
+     * @param array $values (default: array())
244
+     * @return void
245
+     */
246
+    public function runQuery($query, $values = array()) {
247
+        if (!$this->isConnected()) $this->connect();
248
+
249
+        $statement = $this->pdo->prepare($query);
250
+        //debuq
251
+        $this->log_query ($statement);
252
+        return $statement->execute((array)$values); //this array cast allows single values to be used as the parameter
253
+    }
254
+
255
+    /**
256
+     * Allow a value to be escaped, ready for insertion as a mysql parameter
257
+     * Note: for usage as a value (rather than prepared statements), you MUST manually quote around.
258
+     *
259
+     * @access public
260
+     * @param mixed $str
261
+     * @return void
262
+     */
263
+    public function escape($str) {
264
+        if (!$this->isConnected()) $this->connect();
265
+
266
+        return $this->unquote_outer($this->pdo->quote((string)$str));
267
+    }
268
+
269
+    /**
270
+     * Get a quick number of objects in a table
271
+     *
272
+     * @access public
273
+     * @param mixed $tableName
274
+     * @return void
275
+     */
276
+    public function numObjects($tableName) {
277
+        if (!$this->isConnected()) $this->connect();
278
+
279
+        $tableName = $this->escape($tableName);
280
+        $statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;');
281
+
282
+        //debuq
283
+        $this->log_query ($statement);
284
+        $statement->execute();
285
+
286
+        return $statement->fetchColumn();
287
+    }
288
+
289
+    /**
290
+     * Get a quick number of objects in a table for filtered field
291
+     *
292
+     * @access public
293
+     * @param mixed $tableName
294
+     * @param mixed $method
295
+     * @param boolean $like (default: false)
296
+     * @param mixed $value
297
+     * @return void
298
+     */
299
+    public function numObjectsFilter($tableName, $method, $value, $like = false) {
300
+        if (!$this->isConnected()) $this->connect();
301
+
302
+        $like === true ? $operator = "LIKE" : $operator = "=";
303
+
304
+        $tableName = $this->escape($tableName);
305
+        $statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'` '.$operator.' ?;');
306
+
307
+        //debuq
308
+        $this->log_query ($statement);
309
+        $statement->execute(array($value));
310
+
311
+        return $statement->fetchColumn();
312
+    }
313
+
314
+    /**
315
+     * Update an object in a table with values given
316
+     *
317
+     * Note: the id of the object is assumed to be in.
318
+     *
319
+     * @access public
320
+     * @param mixed $tableName
321
+     * @param mixed $obj
322
+     * @param string $primarykey (default: 'id')
323
+     * @param mixed $primarykey2 (default: null)
324
+     * @return void
325
+     */
326
+    public function updateObject($tableName, $obj, $primarykey = 'id', $primarykey2 = null) {
327
+        if (!$this->isConnected()) $this->connect();
328
+
329
+        $obj = (array)$obj;
330
+
331
+        //we cannot update an object without an id specified so quit
332
+        if (!isset($obj[$primarykey])) {
333
+            throw new Exception('Missing primary key');
334
+            return false;
335
+        }
336
+
337
+        $tableName = $this->escape($tableName);
338
+
339
+        //get the objects id from the provided object and knock it off from the object so we dont try to update it
340
+        $objId[] = $obj[$primarykey];
341
+        unset($obj[$primarykey]);
342
+
343
+        //secondary primary key?
344
+        if(!is_null($primarykey2)) {
345
+        $objId[] = $obj[$primarykey2];
346
+        unset($obj[$primarykey2]);
347
+        }
348
+
349
+        //TODO: validate given object parameters with that of the table (this validates parameters names)
350
+
351
+        //formulate an update statement based on the object parameters
352
+        $objParams = array_keys($obj);
353
+
354
+        $preparedParamArr = array();
355
+        foreach ($objParams as $objParam) {
356
+            $preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
357
+        }
358
+
359
+        $preparedParamStr = implode(',', $preparedParamArr);
360
+
361
+        //primary key 2?
362
+        if(!is_null($primarykey2))
363
+        $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;');
364
+        else
365
+        $statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;');
366
+
367
+        //merge the parameters and values
368
+        $paramValues = array_merge(array_values($obj), $objId);
369
+
370
+        //debuq
371
+        $this->log_query ($statement);
372
+        //run the update on the object
373
+        return $statement->execute($paramValues);
374
+    }
375
+
376
+    /**
377
+     * Update multiple objects at once.
378
+     *
379
+     * @access public
380
+     * @param string $tableName
381
+     * @param array $ids
382
+     * @param array $values
383
+     * @return void
384
+     */
385
+    public function updateMultipleObjects($tableName, $ids, $values) {
386
+        $tableName = $this->escape($tableName);
387
+        //set ids
388
+        $num = count($ids);
389
+        $idParts = array_fill(0, $num, '`id`=?');
390
+        //set values
391
+        $objParams = array_keys($values);
392
+        $preparedParamArr = array();
393
+        foreach ($objParams as $objParam) {
394
+            $preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
395
+        }
396
+        //set values
397
+        $all_values = array_merge(array_values($values),$ids);
398
+        //execute
399
+        return $this->runQuery('UPDATE `'.$tableName.'` SET '.implode(',', $preparedParamArr).'  WHERE '.implode(' OR ', $idParts), $all_values);
400
+    }
401
+
402
+    /**
403
+     * Insert an object into a table
404
+     * Note: an id field is ignored if specified.
405
+     *
406
+     * @access public
407
+     * @param string $tableName
408
+     * @param object|array $obj
409
+     * @param bool $raw (default: false)
410
+     * @param bool $replace (default: false)
411
+     * @param bool $ignoreId (default: true)
412
+     * @return void
413
+     */
414
+    public function insertObject($tableName, $obj, $raw = false, $replace = false, $ignoreId = true) {
415
+        if (!$this->isConnected()) $this->connect();
416
+
417
+        $obj = (array)$obj;
418
+
419
+        $tableName = $this->escape($tableName);
420
+
421
+        if (!$raw && array_key_exists('id', $obj) && $ignoreId) {
422
+            unset($obj['id']);
423
+        }
424
+
425
+        if (count($obj)<1) {
426
+            return true;
427
+        }
428
+
429
+        //formulate an update statement based on the object parameters
430
+        $objValues = array_values($obj);
431
+
432
+        $preparedParamsArr = array();
433
+        foreach ($obj as $key => $value) {
434
+            $preparedParamsArr[] = '`' . $this->escape($key) . '`';
435
+        }
436
+
437
+        $preparedParamsStr = implode(', ', $preparedParamsArr);
438
+        $preparedValuesStr = implode(', ', array_fill(0, count($objValues), '?'));
439
+
440
+        if ($replace) {
441
+            $statement = $this->pdo->prepare('REPLACE INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
442
+        } else {
443
+            $statement = $this->pdo->prepare('INSERT INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
444
+        }
445
+
446
+        //run the update on the object
447
+        if (!$statement->execute($objValues)) {
448
+            $errObj = $statement->errorInfo();
449
+
450
+            //return false;
451
+            throw new Exception($errObj[2]);
452
+        }
453
+
454
+        return $this->pdo->lastInsertId();
455
+    }
456
+
457
+
458
+    /**
459
+     * Check if an object exists.
460
+     *
461
+     * @access public
462
+     * @param string $tableName
463
+     * @param string $query (default: null)
464
+     * @param array $values (default: array())
465
+     * @param mixed $id (default: null)
466
+     * @return void
467
+     */
468
+    public function objectExists($tableName, $query = null, $values = array(), $id = null) {
469
+        return is_object($this->getObject($tableName, $id));
470
+    }
471
+
472
+    /**
473
+     * Get a filtered list of objects from the database.
474
+     *
475
+     * @access public
476
+     * @param string $tableName
477
+     * @param string $sortField (default: 'id')
478
+     * @param bool $sortAsc (default: true)
479
+     * @param mixed $numRecords (default: null)
480
+     * @param int $offset (default: 0)
481
+     * @param string $class (default: 'stdClass')
482
+     * @return void
483
+     */
484
+    public function getObjects($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') {
485
+        if (!$this->isConnected()) $this->connect();
486
+
487
+        $sortStr = '';
488
+        if (!$sortAsc) {
489
+            $sortStr = 'DESC';
490
+        }
491
+
492
+        //we should escape all of the params that we need to
493
+        $tableName = $this->escape($tableName);
494
+        $sortField = $this->escape($sortField);
495
+
496
+        if ($numRecords === null) {
497
+            //get all (no limit)
498
+            $statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';');
499
+        } else {
500
+            //get a limited range of objects
501
+            $statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';');
502
+        }
503
+
504
+        $results = array();
505
+
506
+        if (is_object($statement)) {
507
+            while ($newObj = $statement->fetchObject($class)) {
508
+                $results[] = $newObj;
509
+            }
510
+        }
511
+
512
+        return $results;
513
+    }
514
+
515
+
516
+    /**
517
+     * use this function to conserve memory and read rows one by one rather than reading all of them
518
+     *
519
+     * @access public
520
+     * @param mixed $query (default: null)
521
+     * @param array $values (default: array())
522
+     * @param mixed $callback (default: null)
523
+     * @return void
524
+     */
525
+    public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) {
526
+        if (!$this->isConnected()) $this->connect();
527
+
528
+        $statement = $this->pdo->prepare($query);
529
+
530
+        //debuq
531
+        $this->log_query ($statement);
532
+        $statement->execute((array)$values);
533
+
534
+        if (is_object($statement)) {
535
+            if ($callback) {
536
+                while ($newObj = $statement->fetchObject('stdClass')) {
537
+                    if ($callback($newObj)===false) {
538
+                        return false;
539
+                    }
540
+                }
541
+            }
542
+        }
543
+
544
+        return true;
545
+    }
546
+
547
+
548
+    /**
549
+     * Get all objects matching values
550
+     *
551
+     * @access public
552
+     * @param mixed $query (default: null)
553
+     * @param array $values (default: array())
554
+     * @param string $class (default: 'stdClass')
555
+     * @return void
556
+     */
557
+    public function getObjectsQuery($query = null, $values = array(), $class = 'stdClass') {
558
+        if (!$this->isConnected()) $this->connect();
559
+
560
+        $statement = $this->pdo->prepare($query);
561
+
562
+        //debug
563
+        $this->log_query ($statement);
564
+        $statement->execute((array)$values);
565
+
566
+        $results = array();
567
+
568
+        if (is_object($statement)) {
569
+            while ($newObj = $statement->fetchObject($class)) {
570
+                $results[] = $newObj;
571
+            }
572
+        }
573
+
574
+        return $results;
575
+    }
576
+
577
+    /**
578
+     * Get a single object from the database
579
+     *
580
+     * @access public
581
+     * @param mixed $tableName
582
+     * @param mixed $id (default: null)
583
+     * @param string $class (default: 'stdClass')
584
+     * @return void
585
+     */
586
+    public function getObject($tableName, $id = null, $class = 'stdClass') {
587
+        if (!$this->isConnected()) $this->connect();
588
+        $id = intval($id);
589
+
590
+        //has a custom query been provided?
591
+        $tableName = $this->escape($tableName);
592
+
593
+        //prepare a statement to get a single object from the database
594
+        if ($id !== null) {
595
+            $statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;');
596
+            $statement->bindParam(1, $id, \PDO::PARAM_INT);
597
+        } else {
598
+            $statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` LIMIT 1;');
599
+        }
600
+
601
+        //debuq
602
+        $this->log_query ($statement);
603
+        $statement->execute();
604
+
605
+        //we can then extract the single object (if we have a result)
606
+        $resultObj = $statement->fetchObject($class);
607
+
608
+        if ($resultObj === false) {
609
+            return null;
610
+        } else {
611
+            return $resultObj;
612
+        }
613
+    }
614
+
615
+    /**
616
+     * Fetches single object from provided query
617
+     *
618
+     * @access public
619
+     * @param mixed $query (default: null)
620
+     * @param array $values (default: array())
621
+     * @param string $class (default: 'stdClass')
622
+     * @return void
623
+     */
624
+    public function getObjectQuery($query = null, $values = array(), $class = 'stdClass') {
625
+        if (!$this->isConnected()) $this->connect();
626
+
627
+        $statement = $this->pdo->prepare($query);
628
+        //debuq
629
+        $this->log_query ($statement);
630
+        $statement->execute((array)$values);
631
+
632
+        $resultObj = $statement->fetchObject($class);
633
+
634
+        if ($resultObj === false) {
635
+            return null;
636
+        } else {
637
+            return $resultObj;
638
+        }
639
+    }
640
+
641
+    /**
642
+     * Get single value
643
+     *
644
+     * @access public
645
+     * @param mixed $query (default: null)
646
+     * @param array $values (default: array())
647
+     * @param string $class (default: 'stdClass')
648
+     * @return void
649
+     */
650
+    public function getValueQuery($query = null, $values = array(), $class = 'stdClass') {
651
+        $obj = $this->getObjectQuery($query, $values, $class);
652
+
653
+        if (is_object($obj)) {
654
+            $obj = (array)$obj;
655
+            return reset($obj);
656
+        } else {
657
+            return null;
658
+        }
659
+    }
660
+
661
+    /**
662
+     * Searches for object in database
663
+     *
664
+     * @access public
665
+     * @param mixed $table
666
+     * @param mixed $field
667
+     * @param mixed $value
668
+     * @param string $sortField (default: 'id')
669
+     * @param bool $sortAsc (default: true)
670
+     * @param bool $like (default: false)
671
+     * @param bool $negate (default: false)
672
+     * @return void
673
+     */
674
+    public function findObjects($table, $field, $value, $sortField = 'id', $sortAsc = true, $like = false, $negate = false) {
675
+        $table = $this->escape($table);
676
+        $field = $this->escape($field);
677
+        $sortField = $this->escape($sortField);
678
+        $like === true ? $operator = "LIKE" : $operator = "=";
679
+        $negate === true ? $negate_operator = "NOT " : $negate_operator = "";
680
+
681
+        return $this->getObjectsQuery('SELECT * FROM `' . $table . '` WHERE `'. $field .'`'.$negate_operator. $operator .'? ORDER BY `'.$sortField.'` ' . ($sortAsc ? '' : 'DESC') . ';', array($value));
682
+    }
683
+
684
+    /**
685
+     * Searches for single object.
686
+     *
687
+     * @access public
688
+     * @param mixed $table
689
+     * @param mixed $field
690
+     * @param mixed $value
691
+     * @return void
692
+     */
693
+    public function findObject($table, $field, $value) {
694
+        $table = $this->escape($table);
695
+        $field = $this->escape($field);
696
+
697
+        return $this->getObjectQuery('SELECT * FROM `' . $table . '` WHERE `' . $field . '` = ? LIMIT 1;', array($value));
698
+    }
699
+
700
+    /**
701
+     * Get list of items.
702
+     *
703
+     * @access public
704
+     * @param mixed $query (default: null)
705
+     * @param array $values (default: array())
706
+     * @param string $class (default: 'stdClass')
707
+     * @return void
708
+     */
709
+    public function getList($query = null, $values = array(), $class = 'stdClass') {
710
+        $objs = $this->getObjectsQuery($query, $values, $class);
711
+
712
+        $list = array();
713
+        foreach ($objs as $obj) {
714
+            $columns = array_values((array)$obj);
715
+            $list[] = $columns[0];
716
+        }
717
+
718
+        return $list;
719
+    }
720
+
721
+    /**
722
+     * Delete an object from the database
723
+     *
724
+     * @param {string} table name
725
+     * @param {int} object id
726
+     * @return {boolean} success
727
+     */
728
+    public function deleteObject($tableName, $id) {
729
+        $tableName = $this->escape($tableName);
730
+
731
+        return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `id`=?;', array($id));
732
+    }
733
+
734
+    /**
735
+     * Delete a list of objects from the database
736
+     *
737
+     * @param {string} table name
738
+     * @param {array} list of ids
739
+     * @return {boolean} success
740
+     */
741
+    public function deleteObjects($tableName, $ids) {
742
+        $tableName = $this->escape($tableName);
743
+        $num = count($ids);
744
+        $idParts = array_fill(0, $num, '`id`=?');
745
+
746
+        return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE ' . implode(' OR ', $idParts), $ids);
747
+    }
748
+
749
+    /**
750
+     * Delete specified row
751
+     *
752
+     * @access public
753
+     * @param {string} $tableName
754
+     * @param {string $field
755
+     * @param {string $value
756
+     * @return void
757
+     */
758
+    public function deleteRow($tableName, $field, $value, $field2=null, $value2 = null) {
759
+        $tableName = $this->escape($tableName);
760
+        $field = $this->escape($field);
761
+
762
+        //multiple
763
+        if(!is_null($field2))
764
+        return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2));
765
+        else
766
+        return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value));
767
+    }
768
+
769
+    /**
770
+     * truncate specified table
771
+     *
772
+     * @access public
773
+     * @param {string} $tableName
774
+     * @return void
775
+     */
776
+    public function emptyTable($tableName) {
777
+        //escape talbe name
778
+        $tableName = $this->escape($tableName);
779
+        //execute
780
+        return $this->runQuery('TRUNCATE TABLE `'.$tableName.'`;');
781
+    }
782 782
 }
783 783
 
784 784
 
@@ -791,185 +791,185 @@  discard block
 block discarded – undo
791 791
 class Database_PDO extends DB {
792 792
 
793 793
 
794
-	/**
795
-	 * SSL options for db connection
796
-	 *
797
-	 * (default value: array ())
798
-	 *
799
-	 * @var array
800
-	 * @access protected
801
-	 */
802
-	protected $pdo_ssl_opts = array ();
803
-
804
-	/**
805
-	 * flag if installation is happenig!
806
-	 *
807
-	 * (default value: false)
808
-	 *
809
-	 * @var bool
810
-	 * @access public
811
-	 */
812
-	public $install = false;
813
-
814
-	/**
815
-	 * Debugging flag
816
-	 *
817
-	 * (default value: false)
818
-	 *
819
-	 * @var bool
820
-	 * @access protected
821
-	 */
822
-	protected $debug = false;
823
-
824
-
825
-
826
-
827
-
828
-
829
-	/**
830
-	 * __construct function.
831
-	 *
832
-	 * @access public
833
-	 * @param mixed $host (default: null)
834
-	 * @param mixed $port (default: null)
835
-	 * @param mixed $dbname (default: null)
836
-	 * @param mixed $username (default: null)
837
-	 * @param mixed $password (default: null)
838
-	 * @param mixed $charset (default: null)
839
-	 */
840
-	public function __construct($username=null, $password=null, $host=null, $port=null, $dbname=null, $charset=null) {
841
-		# set parameters
842
-		$this->set_db_params ();
843
-		# rewrite user/pass if requested - for installation
844
-		$username==null ? : $this->username = $username;
845
-		$password==null ? : $this->password = $password;
846
-		$host==null 	? : $this->host = $host;
847
-		$port==null 	? : $this->port = $port;
848
-		$dbname==null 	? : $this->dbname = $dbname;
849
-
850
-		# construct
851
-		parent::__construct($this->username, $this->password, $this->charset, $this->ssl);
852
-	}
853
-
854
-
855
-	/**
856
-	 * get database parameters from config.php
857
-	 *
858
-	 * @access private
859
-	 * @return void
860
-	 */
861
-	private function set_db_params () {
862
-		# use config file
863
-		require( dirname(__FILE__) . '/../../config.php' );
864
-		# set
865
-		$this->host 	= $db['host'];
866
-		$this->port 	= $db['port'];
867
-		$this->username = $db['user'];
868
-		$this->password = $db['pass'];
869
-		$this->dbname 	= $db['name'];
870
-
871
-		$this->ssl = false;
872
-		if ($db['ssl']===true) {
873
-
874
-			$this->pdo_ssl_opts = array (
875
-				'ssl_key'    => PDO::MYSQL_ATTR_SSL_KEY,
876
-				'ssl_cert'   => PDO::MYSQL_ATTR_SSL_CERT,
877
-				'ssl_ca'     => PDO::MYSQL_ATTR_SSL_CA,
878
-				'ssl_cipher' => PDO::MYSQL_ATTR_SSL_CIPHER,
879
-				'ssl_capath' => PDO::MYSQL_ATTR_SSL_CAPATH
880
-			);
881
-
882
-			$this->ssl = array();
883
-
884
-			foreach ($this->pdo_ssl_opts as $key => $pdoopt) {
885
-				if ($db[$key]) {
886
-					$this->ssl[$pdoopt] = $db[$key];
887
-				}
888
-			}
889
-
890
-		}
891
-
892
-	}
893
-
894
-	/**
895
-	 * connect function.
896
-	 *
897
-	 * @access public
898
-	 * @return void
899
-	 */
900
-	public function connect() {
901
-		parent::connect();
902
-		//@$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
903
-	}
904
-
905
-	/**
906
-	 * makeDsn function
907
-	 *
908
-	 * @access protected
909
-	 * @return void
910
-	 */
911
-	protected function makeDsn() {
912
-		# for installation
913
-		if($this->install)	{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';charset=' . $this->charset; }
914
-		else				{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';charset=' . $this->charset; }
915
-	}
916
-
917
-	/**
918
-	 * more generic static useful methods
919
-	 *
920
-	 * @access public
921
-	 * @return void
922
-	 */
923
-	public function getColumnInfo() {
924
-		$columns = $this->getObjectsQuery("
794
+    /**
795
+     * SSL options for db connection
796
+     *
797
+     * (default value: array ())
798
+     *
799
+     * @var array
800
+     * @access protected
801
+     */
802
+    protected $pdo_ssl_opts = array ();
803
+
804
+    /**
805
+     * flag if installation is happenig!
806
+     *
807
+     * (default value: false)
808
+     *
809
+     * @var bool
810
+     * @access public
811
+     */
812
+    public $install = false;
813
+
814
+    /**
815
+     * Debugging flag
816
+     *
817
+     * (default value: false)
818
+     *
819
+     * @var bool
820
+     * @access protected
821
+     */
822
+    protected $debug = false;
823
+
824
+
825
+
826
+
827
+
828
+
829
+    /**
830
+     * __construct function.
831
+     *
832
+     * @access public
833
+     * @param mixed $host (default: null)
834
+     * @param mixed $port (default: null)
835
+     * @param mixed $dbname (default: null)
836
+     * @param mixed $username (default: null)
837
+     * @param mixed $password (default: null)
838
+     * @param mixed $charset (default: null)
839
+     */
840
+    public function __construct($username=null, $password=null, $host=null, $port=null, $dbname=null, $charset=null) {
841
+        # set parameters
842
+        $this->set_db_params ();
843
+        # rewrite user/pass if requested - for installation
844
+        $username==null ? : $this->username = $username;
845
+        $password==null ? : $this->password = $password;
846
+        $host==null 	? : $this->host = $host;
847
+        $port==null 	? : $this->port = $port;
848
+        $dbname==null 	? : $this->dbname = $dbname;
849
+
850
+        # construct
851
+        parent::__construct($this->username, $this->password, $this->charset, $this->ssl);
852
+    }
853
+
854
+
855
+    /**
856
+     * get database parameters from config.php
857
+     *
858
+     * @access private
859
+     * @return void
860
+     */
861
+    private function set_db_params () {
862
+        # use config file
863
+        require( dirname(__FILE__) . '/../../config.php' );
864
+        # set
865
+        $this->host 	= $db['host'];
866
+        $this->port 	= $db['port'];
867
+        $this->username = $db['user'];
868
+        $this->password = $db['pass'];
869
+        $this->dbname 	= $db['name'];
870
+
871
+        $this->ssl = false;
872
+        if ($db['ssl']===true) {
873
+
874
+            $this->pdo_ssl_opts = array (
875
+                'ssl_key'    => PDO::MYSQL_ATTR_SSL_KEY,
876
+                'ssl_cert'   => PDO::MYSQL_ATTR_SSL_CERT,
877
+                'ssl_ca'     => PDO::MYSQL_ATTR_SSL_CA,
878
+                'ssl_cipher' => PDO::MYSQL_ATTR_SSL_CIPHER,
879
+                'ssl_capath' => PDO::MYSQL_ATTR_SSL_CAPATH
880
+            );
881
+
882
+            $this->ssl = array();
883
+
884
+            foreach ($this->pdo_ssl_opts as $key => $pdoopt) {
885
+                if ($db[$key]) {
886
+                    $this->ssl[$pdoopt] = $db[$key];
887
+                }
888
+            }
889
+
890
+        }
891
+
892
+    }
893
+
894
+    /**
895
+     * connect function.
896
+     *
897
+     * @access public
898
+     * @return void
899
+     */
900
+    public function connect() {
901
+        parent::connect();
902
+        //@$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
903
+    }
904
+
905
+    /**
906
+     * makeDsn function
907
+     *
908
+     * @access protected
909
+     * @return void
910
+     */
911
+    protected function makeDsn() {
912
+        # for installation
913
+        if($this->install)	{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';charset=' . $this->charset; }
914
+        else				{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';charset=' . $this->charset; }
915
+    }
916
+
917
+    /**
918
+     * more generic static useful methods
919
+     *
920
+     * @access public
921
+     * @return void
922
+     */
923
+    public function getColumnInfo() {
924
+        $columns = $this->getObjectsQuery("
925 925
 			SELECT `table_name`, `column_name`, `column_default`, `is_nullable`, `data_type`,`column_key`, `extra`
926 926
 			FROM `columns`
927 927
 			WHERE `table_schema`='" . $this->dbname . "';
928 928
 		");
929 929
 
930
-		$columnsByTable = array();
931
-		foreach ($columns as $column) {
932
-			if (!isset($columnsByTable[$column->table_name])) {
933
-				$columnsByTable[$column->table_name] = array();
934
-			}
935
-
936
-			$columnsByTable[$column->table_name][$column->column_name] = $column;
937
-		}
938
-
939
-		return $columnsByTable;
940
-	}
941
-
942
-	/**
943
-	 * getForeignKeyInfo function.
944
-	 *
945
-	 * @access public
946
-	 * @return void
947
-	 */
948
-	public function getForeignKeyInfo() {
949
-		$foreignLinks = $this->getObjectsQuery("
930
+        $columnsByTable = array();
931
+        foreach ($columns as $column) {
932
+            if (!isset($columnsByTable[$column->table_name])) {
933
+                $columnsByTable[$column->table_name] = array();
934
+            }
935
+
936
+            $columnsByTable[$column->table_name][$column->column_name] = $column;
937
+        }
938
+
939
+        return $columnsByTable;
940
+    }
941
+
942
+    /**
943
+     * getForeignKeyInfo function.
944
+     *
945
+     * @access public
946
+     * @return void
947
+     */
948
+    public function getForeignKeyInfo() {
949
+        $foreignLinks = $this->getObjectsQuery("
950 950
 			SELECT i.`table_name`, k.`column_name`, i.`constraint_type`, i.`constraint_name`, k.`referenced_table_name`, k.`referenced_column_name`
951 951
 			FROM `table_constraints` i
952 952
 			LEFT JOIN `key_column_usage` k ON i.`constraint_name` = k.`constraint_name`
953 953
 			WHERE i.`constraint_type` = 'FOREIGN KEY' AND i.`table_schema`='" . $this->dbname . "';
954 954
 		");
955 955
 
956
-		$foreignLinksByTable = array();
957
-		$foreignLinksByRefTable = array();
958
-		foreach ($foreignLinks as $foreignLink) {
959
-			if (!isset($foreignLinksByTable[$foreignLink->table_name])) {
960
-				$foreignLinksByTable[$foreignLink->table_name] = array();
961
-			}
956
+        $foreignLinksByTable = array();
957
+        $foreignLinksByRefTable = array();
958
+        foreach ($foreignLinks as $foreignLink) {
959
+            if (!isset($foreignLinksByTable[$foreignLink->table_name])) {
960
+                $foreignLinksByTable[$foreignLink->table_name] = array();
961
+            }
962 962
 
963
-			if (!isset($foreignLinksByRefTable[$foreignLink->referenced_table_name])) {
964
-				$foreignLinksByRefTable[$foreignLink->referenced_table_name] = array();
965
-			}
963
+            if (!isset($foreignLinksByRefTable[$foreignLink->referenced_table_name])) {
964
+                $foreignLinksByRefTable[$foreignLink->referenced_table_name] = array();
965
+            }
966 966
 
967
-			$foreignLinksByTable[$foreignLink->table_name][$foreignLink->column_name] = $foreignLink;
968
-			$foreignLinksByRefTable[$foreignLink->referenced_table_name][$foreignLink->table_name] = $foreignLink;
969
-		}
967
+            $foreignLinksByTable[$foreignLink->table_name][$foreignLink->column_name] = $foreignLink;
968
+            $foreignLinksByRefTable[$foreignLink->referenced_table_name][$foreignLink->table_name] = $foreignLink;
969
+        }
970 970
 
971
-		return array($foreignLinksByTable, $foreignLinksByRefTable);
972
-	}
971
+        return array($foreignLinksByTable, $foreignLinksByRefTable);
972
+    }
973 973
 }
974 974
 
975 975
 
Please login to merge, or discard this patch.
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @var string
57 57
 	 * @access public
58 58
 	 */
59
-	public $dbname 	= '';		// needed for DB check
59
+	public $dbname = ''; // needed for DB check
60 60
 
61 61
 	/**
62 62
 	 * hosnamr
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @var string
67 67
 	 * @access protected
68 68
 	 */
69
-	protected $host 	= 'localhost';
69
+	protected $host = 'localhost';
70 70
 
71 71
 	/**
72 72
 	 * Default port number
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @var string
77 77
 	 * @access protected
78 78
 	 */
79
-	protected $port 	= '3306';
79
+	protected $port = '3306';
80 80
 
81 81
 
82 82
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param mixed $ssl (default: null)
93 93
 	 * @return void
94 94
 	 */
95
-	public function __construct($username = null, $password = null, $charset = null, $ssl = null) {
95
+	public function __construct ($username = null, $password = null, $charset = null, $ssl = null) {
96 96
 		if (isset($username)) $this->username = $username;
97 97
 		if (isset($password)) $this->password = $password;
98 98
 		if (isset($charset))  $this->charset = $charset;
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 * @param mixed $date (default: null)
111 111
 	 * @return void
112 112
 	 */
113
-	public static function toDate($date = null) {
114
-		if (is_int($date)) {
115
-			return date('Y-m-d H:i:s', $date);
116
-		} else if (is_string($date)) {
117
-			return date('Y-m-d H:i:s', strtotime($date));
113
+	public static function toDate ($date = null) {
114
+		if (is_int ($date)) {
115
+			return date ('Y-m-d H:i:s', $date);
116
+		} else if (is_string ($date)) {
117
+			return date ('Y-m-d H:i:s', strtotime ($date));
118 118
 		} else {
119
-			return date('Y-m-d H:i:s');
119
+			return date ('Y-m-d H:i:s');
120 120
 		}
121 121
 	}
122 122
 
@@ -127,25 +127,25 @@  discard block
 block discarded – undo
127 127
 	 * @access public
128 128
 	 * @return void
129 129
 	 */
130
-	public function connect() {
131
-		$dsn = $this->makeDsn();
130
+	public function connect () {
131
+		$dsn = $this->makeDsn ();
132 132
 
133 133
 		try {
134 134
 			# ssl?
135 135
 			if ($this->ssl) {
136
-				$this->pdo = new \PDO($dsn, $this->username, $this->password, $this->ssl);
136
+				$this->pdo = new \PDO ($dsn, $this->username, $this->password, $this->ssl);
137 137
 			}
138 138
 			else {
139
-				$this->pdo = new \PDO($dsn, $this->username, $this->password);
139
+				$this->pdo = new \PDO ($dsn, $this->username, $this->password);
140 140
 			}
141 141
 
142
-			$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
142
+			$this->pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
143 143
 
144 144
 		} catch (\PDOException $e) {
145
-			throw new Exception ("Could not connect to database! ".$e->getMessage());
145
+			throw new Exception ("Could not connect to database! ".$e->getMessage ());
146 146
 		}
147 147
 
148
-		@$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
148
+		@$this->pdo->query ('SET NAMES \''.$this->charset.'\';');
149 149
 	}
150 150
 
151 151
 	/**
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 	 * @access protected
155 155
 	 * @return void
156 156
 	 */
157
-	protected function makeDsn() {
158
-		return ':charset=' . $this->charset;
157
+	protected function makeDsn () {
158
+		return ':charset='.$this->charset;
159 159
 	}
160 160
 
161 161
 	/**
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @access public
165 165
 	 * @return void
166 166
 	 */
167
-	public function resetConn() {
167
+	public function resetConn () {
168 168
 		unset($this->pdo);
169 169
 		$this->install = false;
170 170
 	}
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
 	 * @return void
178 178
 	 */
179 179
 	private function log_query ($query) {
180
-		if($this->debug) {
180
+		if ($this->debug) {
181 181
 
182 182
 			$myFile = "/tmp/queries.txt";
183
-			$fh = fopen($myFile, 'a') or die("can't open file");
184
-			fwrite($fh, $query->queryString."\n");
185
-			fclose($fh);
183
+			$fh = fopen ($myFile, 'a') or die("can't open file");
184
+			fwrite ($fh, $query->queryString."\n");
185
+			fclose ($fh);
186 186
 		}
187 187
 	}
188 188
 
@@ -194,18 +194,18 @@  discard block
 block discarded – undo
194 194
 	 * @param mixed $str
195 195
 	 * @return void
196 196
 	 */
197
-	public static function unquote_outer($str) {
198
-		$len = strlen($str);
197
+	public static function unquote_outer ($str) {
198
+		$len = strlen ($str);
199 199
 
200
-		if ($len>1) {
201
-			if ($str[0] == "'" && $str[$len-1] == "'") {
202
-				return substr($str, 1, -1);
200
+		if ($len > 1) {
201
+			if ($str[0] == "'" && $str[$len - 1] == "'") {
202
+				return substr ($str, 1, -1);
203 203
 			} else if ($str[0] == "'") {
204
-				return substr($str, 1);
205
-			} else if ($str[$len-1] == "'") {
206
-				return substr($str, 0, -1);
204
+				return substr ($str, 1);
205
+			} else if ($str[$len - 1] == "'") {
206
+				return substr ($str, 0, -1);
207 207
 			}
208
-		} else if ($len>0) {
208
+		} else if ($len > 0) {
209 209
 			if ($str[0] == "'") {
210 210
 				return '';
211 211
 			}
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @access public
221 221
 	 * @return void
222 222
 	 */
223
-	public function isConnected() {
223
+	public function isConnected () {
224 224
 		return ($this->pdo !== null);
225 225
 	}
226 226
 
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * @access public
231 231
 	 * @return void
232 232
 	 */
233
-	public function lastInsertId() {
234
-		return $this->pdo->lastInsertId();
233
+	public function lastInsertId () {
234
+		return $this->pdo->lastInsertId ();
235 235
 	}
236 236
 
237 237
 	/**
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
 	 * @param array $values (default: array())
244 244
 	 * @return void
245 245
 	 */
246
-	public function runQuery($query, $values = array()) {
247
-		if (!$this->isConnected()) $this->connect();
246
+	public function runQuery ($query, $values = array ()) {
247
+		if (!$this->isConnected ()) $this->connect ();
248 248
 
249
-		$statement = $this->pdo->prepare($query);
249
+		$statement = $this->pdo->prepare ($query);
250 250
 		//debuq
251 251
 		$this->log_query ($statement);
252
-		return $statement->execute((array)$values); //this array cast allows single values to be used as the parameter
252
+		return $statement->execute ((array) $values); //this array cast allows single values to be used as the parameter
253 253
 	}
254 254
 
255 255
 	/**
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 	 * @param mixed $str
261 261
 	 * @return void
262 262
 	 */
263
-	public function escape($str) {
264
-		if (!$this->isConnected()) $this->connect();
263
+	public function escape ($str) {
264
+		if (!$this->isConnected ()) $this->connect ();
265 265
 
266
-		return $this->unquote_outer($this->pdo->quote((string)$str));
266
+		return $this->unquote_outer ($this->pdo->quote ((string) $str));
267 267
 	}
268 268
 
269 269
 	/**
@@ -273,17 +273,17 @@  discard block
 block discarded – undo
273 273
 	 * @param mixed $tableName
274 274
 	 * @return void
275 275
 	 */
276
-	public function numObjects($tableName) {
277
-		if (!$this->isConnected()) $this->connect();
276
+	public function numObjects ($tableName) {
277
+		if (!$this->isConnected ()) $this->connect ();
278 278
 
279
-		$tableName = $this->escape($tableName);
280
-		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;');
279
+		$tableName = $this->escape ($tableName);
280
+		$statement = $this->pdo->prepare ('SELECT COUNT(*) as `num` FROM `'.$tableName.'`;');
281 281
 
282 282
 		//debuq
283 283
 		$this->log_query ($statement);
284
-		$statement->execute();
284
+		$statement->execute ();
285 285
 
286
-		return $statement->fetchColumn();
286
+		return $statement->fetchColumn ();
287 287
     }
288 288
 
289 289
 	/**
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 	 * @param mixed $value
297 297
 	 * @return void
298 298
 	 */
299
-	public function numObjectsFilter($tableName, $method, $value, $like = false) {
300
-		if (!$this->isConnected()) $this->connect();
299
+	public function numObjectsFilter ($tableName, $method, $value, $like = false) {
300
+		if (!$this->isConnected ()) $this->connect ();
301 301
 
302 302
 		$like === true ? $operator = "LIKE" : $operator = "=";
303 303
 
304
-		$tableName = $this->escape($tableName);
305
-		$statement = $this->pdo->prepare('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'` '.$operator.' ?;');
304
+		$tableName = $this->escape ($tableName);
305
+		$statement = $this->pdo->prepare ('SELECT COUNT(*) as `num` FROM `'.$tableName.'` where `'.$method.'` '.$operator.' ?;');
306 306
 
307 307
 		//debuq
308 308
 		$this->log_query ($statement);
309
-		$statement->execute(array($value));
309
+		$statement->execute (array ($value));
310 310
 
311
-		return $statement->fetchColumn();
311
+		return $statement->fetchColumn ();
312 312
 	}
313 313
 
314 314
 	/**
@@ -323,25 +323,25 @@  discard block
 block discarded – undo
323 323
 	 * @param mixed $primarykey2 (default: null)
324 324
 	 * @return void
325 325
 	 */
326
-	public function updateObject($tableName, $obj, $primarykey = 'id', $primarykey2 = null) {
327
-		if (!$this->isConnected()) $this->connect();
326
+	public function updateObject ($tableName, $obj, $primarykey = 'id', $primarykey2 = null) {
327
+		if (!$this->isConnected ()) $this->connect ();
328 328
 
329
-		$obj = (array)$obj;
329
+		$obj = (array) $obj;
330 330
 
331 331
 		//we cannot update an object without an id specified so quit
332 332
 		if (!isset($obj[$primarykey])) {
333
-			throw new Exception('Missing primary key');
333
+			throw new Exception ('Missing primary key');
334 334
 			return false;
335 335
 		}
336 336
 
337
-		$tableName = $this->escape($tableName);
337
+		$tableName = $this->escape ($tableName);
338 338
 
339 339
 		//get the objects id from the provided object and knock it off from the object so we dont try to update it
340 340
 		$objId[] = $obj[$primarykey];
341 341
 		unset($obj[$primarykey]);
342 342
 
343 343
 		//secondary primary key?
344
-		if(!is_null($primarykey2)) {
344
+		if (!is_null ($primarykey2)) {
345 345
 		$objId[] = $obj[$primarykey2];
346 346
 		unset($obj[$primarykey2]);
347 347
 		}
@@ -349,28 +349,28 @@  discard block
 block discarded – undo
349 349
 		//TODO: validate given object parameters with that of the table (this validates parameters names)
350 350
 
351 351
 		//formulate an update statement based on the object parameters
352
-		$objParams = array_keys($obj);
352
+		$objParams = array_keys ($obj);
353 353
 
354
-		$preparedParamArr = array();
354
+		$preparedParamArr = array ();
355 355
 		foreach ($objParams as $objParam) {
356
-			$preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
356
+			$preparedParamArr[] = '`'.$this->escape ($objParam).'`=?';
357 357
 		}
358 358
 
359
-		$preparedParamStr = implode(',', $preparedParamArr);
359
+		$preparedParamStr = implode (',', $preparedParamArr);
360 360
 
361 361
 		//primary key 2?
362
-		if(!is_null($primarykey2))
363
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=? AND `' . $primarykey2 . '`=?;');
362
+		if (!is_null ($primarykey2))
363
+		$statement = $this->pdo->prepare ('UPDATE `'.$tableName.'` SET '.$preparedParamStr.' WHERE `'.$primarykey.'`=? AND `'.$primarykey2.'`=?;');
364 364
 		else
365
-		$statement = $this->pdo->prepare('UPDATE `' . $tableName . '` SET ' . $preparedParamStr . ' WHERE `' . $primarykey . '`=?;');
365
+		$statement = $this->pdo->prepare ('UPDATE `'.$tableName.'` SET '.$preparedParamStr.' WHERE `'.$primarykey.'`=?;');
366 366
 
367 367
 		//merge the parameters and values
368
-		$paramValues = array_merge(array_values($obj), $objId);
368
+		$paramValues = array_merge (array_values ($obj), $objId);
369 369
 
370 370
 		//debuq
371 371
 		$this->log_query ($statement);
372 372
 		//run the update on the object
373
-		return $statement->execute($paramValues);
373
+		return $statement->execute ($paramValues);
374 374
 	}
375 375
 
376 376
 	/**
@@ -382,21 +382,21 @@  discard block
 block discarded – undo
382 382
 	 * @param array $values
383 383
 	 * @return void
384 384
 	 */
385
-	public function updateMultipleObjects($tableName, $ids, $values) {
386
-		$tableName = $this->escape($tableName);
385
+	public function updateMultipleObjects ($tableName, $ids, $values) {
386
+		$tableName = $this->escape ($tableName);
387 387
 		//set ids
388
-		$num = count($ids);
389
-		$idParts = array_fill(0, $num, '`id`=?');
388
+		$num = count ($ids);
389
+		$idParts = array_fill (0, $num, '`id`=?');
390 390
 		//set values
391
-		$objParams = array_keys($values);
392
-		$preparedParamArr = array();
391
+		$objParams = array_keys ($values);
392
+		$preparedParamArr = array ();
393 393
 		foreach ($objParams as $objParam) {
394
-			$preparedParamArr[] = '`' . $this->escape($objParam) . '`=?';
394
+			$preparedParamArr[] = '`'.$this->escape ($objParam).'`=?';
395 395
 		}
396 396
 		//set values
397
-		$all_values = array_merge(array_values($values),$ids);
397
+		$all_values = array_merge (array_values ($values), $ids);
398 398
 		//execute
399
-		return $this->runQuery('UPDATE `'.$tableName.'` SET '.implode(',', $preparedParamArr).'  WHERE '.implode(' OR ', $idParts), $all_values);
399
+		return $this->runQuery ('UPDATE `'.$tableName.'` SET '.implode (',', $preparedParamArr).'  WHERE '.implode (' OR ', $idParts), $all_values);
400 400
 	}
401 401
 
402 402
 	/**
@@ -411,47 +411,47 @@  discard block
 block discarded – undo
411 411
 	 * @param bool $ignoreId (default: true)
412 412
 	 * @return void
413 413
 	 */
414
-	public function insertObject($tableName, $obj, $raw = false, $replace = false, $ignoreId = true) {
415
-		if (!$this->isConnected()) $this->connect();
414
+	public function insertObject ($tableName, $obj, $raw = false, $replace = false, $ignoreId = true) {
415
+		if (!$this->isConnected ()) $this->connect ();
416 416
 
417
-		$obj = (array)$obj;
417
+		$obj = (array) $obj;
418 418
 
419
-		$tableName = $this->escape($tableName);
419
+		$tableName = $this->escape ($tableName);
420 420
 
421
-		if (!$raw && array_key_exists('id', $obj) && $ignoreId) {
421
+		if (!$raw && array_key_exists ('id', $obj) && $ignoreId) {
422 422
 			unset($obj['id']);
423 423
 		}
424 424
 
425
-		if (count($obj)<1) {
425
+		if (count ($obj) < 1) {
426 426
 			return true;
427 427
 		}
428 428
 
429 429
 		//formulate an update statement based on the object parameters
430
-		$objValues = array_values($obj);
430
+		$objValues = array_values ($obj);
431 431
 
432
-		$preparedParamsArr = array();
432
+		$preparedParamsArr = array ();
433 433
 		foreach ($obj as $key => $value) {
434
-			$preparedParamsArr[] = '`' . $this->escape($key) . '`';
434
+			$preparedParamsArr[] = '`'.$this->escape ($key).'`';
435 435
 		}
436 436
 
437
-		$preparedParamsStr = implode(', ', $preparedParamsArr);
438
-		$preparedValuesStr = implode(', ', array_fill(0, count($objValues), '?'));
437
+		$preparedParamsStr = implode (', ', $preparedParamsArr);
438
+		$preparedValuesStr = implode (', ', array_fill (0, count ($objValues), '?'));
439 439
 
440 440
 		if ($replace) {
441
-			$statement = $this->pdo->prepare('REPLACE INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
441
+			$statement = $this->pdo->prepare ('REPLACE INTO `'.$tableName.'` ('.$preparedParamsStr.') VALUES ('.$preparedValuesStr.');');
442 442
 		} else {
443
-			$statement = $this->pdo->prepare('INSERT INTO `' . $tableName . '` (' . $preparedParamsStr . ') VALUES (' . $preparedValuesStr . ');');
443
+			$statement = $this->pdo->prepare ('INSERT INTO `'.$tableName.'` ('.$preparedParamsStr.') VALUES ('.$preparedValuesStr.');');
444 444
 		}
445 445
 
446 446
 		//run the update on the object
447
-		if (!$statement->execute($objValues)) {
448
-			$errObj = $statement->errorInfo();
447
+		if (!$statement->execute ($objValues)) {
448
+			$errObj = $statement->errorInfo ();
449 449
 
450 450
 			//return false;
451
-			throw new Exception($errObj[2]);
451
+			throw new Exception ($errObj[2]);
452 452
 		}
453 453
 
454
-		return $this->pdo->lastInsertId();
454
+		return $this->pdo->lastInsertId ();
455 455
 	}
456 456
 
457 457
 
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 * @param mixed $id (default: null)
466 466
 	 * @return void
467 467
 	 */
468
-	public function objectExists($tableName, $query = null, $values = array(), $id = null) {
469
-		return is_object($this->getObject($tableName, $id));
468
+	public function objectExists ($tableName, $query = null, $values = array (), $id = null) {
469
+		return is_object ($this->getObject ($tableName, $id));
470 470
 	}
471 471
 
472 472
 	/**
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
 	 * @param string $class (default: 'stdClass')
482 482
 	 * @return void
483 483
 	 */
484
-	public function getObjects($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') {
485
-		if (!$this->isConnected()) $this->connect();
484
+	public function getObjects ($tableName, $sortField = 'id', $sortAsc = true, $numRecords = null, $offset = 0, $class = 'stdClass') {
485
+		if (!$this->isConnected ()) $this->connect ();
486 486
 
487 487
 		$sortStr = '';
488 488
 		if (!$sortAsc) {
@@ -490,21 +490,21 @@  discard block
 block discarded – undo
490 490
 		}
491 491
 
492 492
 		//we should escape all of the params that we need to
493
-		$tableName = $this->escape($tableName);
494
-		$sortField = $this->escape($sortField);
493
+		$tableName = $this->escape ($tableName);
494
+		$sortField = $this->escape ($sortField);
495 495
 
496 496
 		if ($numRecords === null) {
497 497
 			//get all (no limit)
498
-			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';');
498
+			$statement = $this->pdo->query ('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.';');
499 499
 		} else {
500 500
 			//get a limited range of objects
501
-			$statement = $this->pdo->query('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';');
501
+			$statement = $this->pdo->query ('SELECT * FROM `'.$tableName.'` ORDER BY `'.$sortField.'` '.$sortStr.' LIMIT '.$numRecords.' OFFSET '.$offset.';');
502 502
 		}
503 503
 
504
-		$results = array();
504
+		$results = array ();
505 505
 
506
-		if (is_object($statement)) {
507
-			while ($newObj = $statement->fetchObject($class)) {
506
+		if (is_object ($statement)) {
507
+			while ($newObj = $statement->fetchObject ($class)) {
508 508
 				$results[] = $newObj;
509 509
 			}
510 510
 		}
@@ -522,19 +522,19 @@  discard block
 block discarded – undo
522 522
 	 * @param mixed $callback (default: null)
523 523
 	 * @return void
524 524
 	 */
525
-	public function getObjectsQueryIncremental($query = null, $values = array(), $callback = null) {
526
-		if (!$this->isConnected()) $this->connect();
525
+	public function getObjectsQueryIncremental ($query = null, $values = array (), $callback = null) {
526
+		if (!$this->isConnected ()) $this->connect ();
527 527
 
528
-		$statement = $this->pdo->prepare($query);
528
+		$statement = $this->pdo->prepare ($query);
529 529
 
530 530
 		//debuq
531 531
 		$this->log_query ($statement);
532
-		$statement->execute((array)$values);
532
+		$statement->execute ((array) $values);
533 533
 
534
-		if (is_object($statement)) {
534
+		if (is_object ($statement)) {
535 535
 			if ($callback) {
536
-				while ($newObj = $statement->fetchObject('stdClass')) {
537
-					if ($callback($newObj)===false) {
536
+				while ($newObj = $statement->fetchObject ('stdClass')) {
537
+					if ($callback ($newObj) === false) {
538 538
 						return false;
539 539
 					}
540 540
 				}
@@ -554,19 +554,19 @@  discard block
 block discarded – undo
554 554
 	 * @param string $class (default: 'stdClass')
555 555
 	 * @return void
556 556
 	 */
557
-	public function getObjectsQuery($query = null, $values = array(), $class = 'stdClass') {
558
-		if (!$this->isConnected()) $this->connect();
557
+	public function getObjectsQuery ($query = null, $values = array (), $class = 'stdClass') {
558
+		if (!$this->isConnected ()) $this->connect ();
559 559
 
560
-		$statement = $this->pdo->prepare($query);
560
+		$statement = $this->pdo->prepare ($query);
561 561
 
562 562
 		//debug
563 563
 		$this->log_query ($statement);
564
-		$statement->execute((array)$values);
564
+		$statement->execute ((array) $values);
565 565
 
566
-		$results = array();
566
+		$results = array ();
567 567
 
568
-		if (is_object($statement)) {
569
-			while ($newObj = $statement->fetchObject($class)) {
568
+		if (is_object ($statement)) {
569
+			while ($newObj = $statement->fetchObject ($class)) {
570 570
 				$results[] = $newObj;
571 571
 			}
572 572
 		}
@@ -583,27 +583,27 @@  discard block
 block discarded – undo
583 583
 	 * @param string $class (default: 'stdClass')
584 584
 	 * @return void
585 585
 	 */
586
-	public function getObject($tableName, $id = null, $class = 'stdClass') {
587
-		if (!$this->isConnected()) $this->connect();
588
-		$id = intval($id);
586
+	public function getObject ($tableName, $id = null, $class = 'stdClass') {
587
+		if (!$this->isConnected ()) $this->connect ();
588
+		$id = intval ($id);
589 589
 
590 590
 		//has a custom query been provided?
591
-		$tableName = $this->escape($tableName);
591
+		$tableName = $this->escape ($tableName);
592 592
 
593 593
 		//prepare a statement to get a single object from the database
594 594
 		if ($id !== null) {
595
-			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;');
596
-			$statement->bindParam(1, $id, \PDO::PARAM_INT);
595
+			$statement = $this->pdo->prepare ('SELECT * FROM `'.$tableName.'` WHERE `id`=? LIMIT 1;');
596
+			$statement->bindParam (1, $id, \PDO::PARAM_INT);
597 597
 		} else {
598
-			$statement = $this->pdo->prepare('SELECT * FROM `'.$tableName.'` LIMIT 1;');
598
+			$statement = $this->pdo->prepare ('SELECT * FROM `'.$tableName.'` LIMIT 1;');
599 599
 		}
600 600
 
601 601
 		//debuq
602 602
 		$this->log_query ($statement);
603
-		$statement->execute();
603
+		$statement->execute ();
604 604
 
605 605
 		//we can then extract the single object (if we have a result)
606
-		$resultObj = $statement->fetchObject($class);
606
+		$resultObj = $statement->fetchObject ($class);
607 607
 
608 608
 		if ($resultObj === false) {
609 609
 			return null;
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
 	 * @param string $class (default: 'stdClass')
622 622
 	 * @return void
623 623
 	 */
624
-	public function getObjectQuery($query = null, $values = array(), $class = 'stdClass') {
625
-		if (!$this->isConnected()) $this->connect();
624
+	public function getObjectQuery ($query = null, $values = array (), $class = 'stdClass') {
625
+		if (!$this->isConnected ()) $this->connect ();
626 626
 
627
-		$statement = $this->pdo->prepare($query);
627
+		$statement = $this->pdo->prepare ($query);
628 628
 		//debuq
629 629
 		$this->log_query ($statement);
630
-		$statement->execute((array)$values);
630
+		$statement->execute ((array) $values);
631 631
 
632
-		$resultObj = $statement->fetchObject($class);
632
+		$resultObj = $statement->fetchObject ($class);
633 633
 
634 634
 		if ($resultObj === false) {
635 635
 			return null;
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
 	 * @param string $class (default: 'stdClass')
648 648
 	 * @return void
649 649
 	 */
650
-	public function getValueQuery($query = null, $values = array(), $class = 'stdClass') {
651
-		$obj = $this->getObjectQuery($query, $values, $class);
650
+	public function getValueQuery ($query = null, $values = array (), $class = 'stdClass') {
651
+		$obj = $this->getObjectQuery ($query, $values, $class);
652 652
 
653
-		if (is_object($obj)) {
654
-			$obj = (array)$obj;
655
-			return reset($obj);
653
+		if (is_object ($obj)) {
654
+			$obj = (array) $obj;
655
+			return reset ($obj);
656 656
 		} else {
657 657
 			return null;
658 658
 		}
@@ -671,14 +671,14 @@  discard block
 block discarded – undo
671 671
 	 * @param bool $negate (default: false)
672 672
 	 * @return void
673 673
 	 */
674
-	public function findObjects($table, $field, $value, $sortField = 'id', $sortAsc = true, $like = false, $negate = false) {
675
-		$table = $this->escape($table);
676
-		$field = $this->escape($field);
677
-		$sortField = $this->escape($sortField);
674
+	public function findObjects ($table, $field, $value, $sortField = 'id', $sortAsc = true, $like = false, $negate = false) {
675
+		$table = $this->escape ($table);
676
+		$field = $this->escape ($field);
677
+		$sortField = $this->escape ($sortField);
678 678
 		$like === true ? $operator = "LIKE" : $operator = "=";
679 679
 		$negate === true ? $negate_operator = "NOT " : $negate_operator = "";
680 680
 
681
-		return $this->getObjectsQuery('SELECT * FROM `' . $table . '` WHERE `'. $field .'`'.$negate_operator. $operator .'? ORDER BY `'.$sortField.'` ' . ($sortAsc ? '' : 'DESC') . ';', array($value));
681
+		return $this->getObjectsQuery ('SELECT * FROM `'.$table.'` WHERE `'.$field.'`'.$negate_operator.$operator.'? ORDER BY `'.$sortField.'` '.($sortAsc ? '' : 'DESC').';', array ($value));
682 682
 	}
683 683
 
684 684
 	/**
@@ -690,11 +690,11 @@  discard block
 block discarded – undo
690 690
 	 * @param mixed $value
691 691
 	 * @return void
692 692
 	 */
693
-	public function findObject($table, $field, $value) {
694
-		$table = $this->escape($table);
695
-		$field = $this->escape($field);
693
+	public function findObject ($table, $field, $value) {
694
+		$table = $this->escape ($table);
695
+		$field = $this->escape ($field);
696 696
 
697
-		return $this->getObjectQuery('SELECT * FROM `' . $table . '` WHERE `' . $field . '` = ? LIMIT 1;', array($value));
697
+		return $this->getObjectQuery ('SELECT * FROM `'.$table.'` WHERE `'.$field.'` = ? LIMIT 1;', array ($value));
698 698
 	}
699 699
 
700 700
 	/**
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
 	 * @param string $class (default: 'stdClass')
707 707
 	 * @return void
708 708
 	 */
709
-	public function getList($query = null, $values = array(), $class = 'stdClass') {
710
-		$objs = $this->getObjectsQuery($query, $values, $class);
709
+	public function getList ($query = null, $values = array (), $class = 'stdClass') {
710
+		$objs = $this->getObjectsQuery ($query, $values, $class);
711 711
 
712
-		$list = array();
712
+		$list = array ();
713 713
 		foreach ($objs as $obj) {
714
-			$columns = array_values((array)$obj);
714
+			$columns = array_values ((array) $obj);
715 715
 			$list[] = $columns[0];
716 716
 		}
717 717
 
@@ -725,10 +725,10 @@  discard block
 block discarded – undo
725 725
 	* @param {int} object id
726 726
 	* @return {boolean} success
727 727
 	*/
728
-	public function deleteObject($tableName, $id) {
729
-		$tableName = $this->escape($tableName);
728
+	public function deleteObject ($tableName, $id) {
729
+		$tableName = $this->escape ($tableName);
730 730
 
731
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `id`=?;', array($id));
731
+		return $this->runQuery ('DELETE FROM `'.$tableName.'` WHERE `id`=?;', array ($id));
732 732
 	}
733 733
 
734 734
 	/**
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 	* @param {array} list of ids
739 739
 	* @return {boolean} success
740 740
 	*/
741
-	public function deleteObjects($tableName, $ids) {
742
-		$tableName = $this->escape($tableName);
743
-		$num = count($ids);
744
-		$idParts = array_fill(0, $num, '`id`=?');
741
+	public function deleteObjects ($tableName, $ids) {
742
+		$tableName = $this->escape ($tableName);
743
+		$num = count ($ids);
744
+		$idParts = array_fill (0, $num, '`id`=?');
745 745
 
746
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE ' . implode(' OR ', $idParts), $ids);
746
+		return $this->runQuery ('DELETE FROM `'.$tableName.'` WHERE '.implode (' OR ', $idParts), $ids);
747 747
 	}
748 748
 
749 749
 	/**
@@ -755,15 +755,15 @@  discard block
 block discarded – undo
755 755
 	 * @param {string $value
756 756
 	 * @return void
757 757
 	 */
758
-	public function deleteRow($tableName, $field, $value, $field2=null, $value2 = null) {
759
-		$tableName = $this->escape($tableName);
760
-		$field = $this->escape($field);
758
+	public function deleteRow ($tableName, $field, $value, $field2 = null, $value2 = null) {
759
+		$tableName = $this->escape ($tableName);
760
+		$field = $this->escape ($field);
761 761
 
762 762
 		//multiple
763
-		if(!is_null($field2))
764
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array($value, $value2));
763
+		if (!is_null ($field2))
764
+		return $this->runQuery ('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=? and `'.$field2.'`=?;', array ($value, $value2));
765 765
 		else
766
-		return $this->runQuery('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array($value));
766
+		return $this->runQuery ('DELETE FROM `'.$tableName.'` WHERE `'.$field.'`=?;', array ($value));
767 767
 	}
768 768
 
769 769
 	/**
@@ -773,11 +773,11 @@  discard block
 block discarded – undo
773 773
 	 * @param {string} $tableName
774 774
 	 * @return void
775 775
 	 */
776
-	public function emptyTable($tableName) {
776
+	public function emptyTable ($tableName) {
777 777
 		//escape talbe name
778
-		$tableName = $this->escape($tableName);
778
+		$tableName = $this->escape ($tableName);
779 779
 		//execute
780
-		return $this->runQuery('TRUNCATE TABLE `'.$tableName.'`;');
780
+		return $this->runQuery ('TRUNCATE TABLE `'.$tableName.'`;');
781 781
 	}
782 782
 }
783 783
 
@@ -837,18 +837,18 @@  discard block
 block discarded – undo
837 837
 	 * @param mixed $password (default: null)
838 838
 	 * @param mixed $charset (default: null)
839 839
 	 */
840
-	public function __construct($username=null, $password=null, $host=null, $port=null, $dbname=null, $charset=null) {
840
+	public function __construct ($username = null, $password = null, $host = null, $port = null, $dbname = null, $charset = null) {
841 841
 		# set parameters
842 842
 		$this->set_db_params ();
843 843
 		# rewrite user/pass if requested - for installation
844
-		$username==null ? : $this->username = $username;
845
-		$password==null ? : $this->password = $password;
846
-		$host==null 	? : $this->host = $host;
847
-		$port==null 	? : $this->port = $port;
848
-		$dbname==null 	? : $this->dbname = $dbname;
844
+		$username == null ? : $this->username = $username;
845
+		$password == null ? : $this->password = $password;
846
+		$host == null ? : $this->host = $host;
847
+		$port == null ? : $this->port = $port;
848
+		$dbname == null ? : $this->dbname = $dbname;
849 849
 
850 850
 		# construct
851
-		parent::__construct($this->username, $this->password, $this->charset, $this->ssl);
851
+		parent::__construct ($this->username, $this->password, $this->charset, $this->ssl);
852 852
 	}
853 853
 
854 854
 
@@ -860,16 +860,16 @@  discard block
 block discarded – undo
860 860
 	 */
861 861
 	private function set_db_params () {
862 862
 		# use config file
863
-		require( dirname(__FILE__) . '/../../config.php' );
863
+		require(dirname (__FILE__).'/../../config.php');
864 864
 		# set
865 865
 		$this->host 	= $db['host'];
866 866
 		$this->port 	= $db['port'];
867 867
 		$this->username = $db['user'];
868 868
 		$this->password = $db['pass'];
869
-		$this->dbname 	= $db['name'];
869
+		$this->dbname = $db['name'];
870 870
 
871 871
 		$this->ssl = false;
872
-		if ($db['ssl']===true) {
872
+		if ($db['ssl'] === true) {
873 873
 
874 874
 			$this->pdo_ssl_opts = array (
875 875
 				'ssl_key'    => PDO::MYSQL_ATTR_SSL_KEY,
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 				'ssl_capath' => PDO::MYSQL_ATTR_SSL_CAPATH
880 880
 			);
881 881
 
882
-			$this->ssl = array();
882
+			$this->ssl = array ();
883 883
 
884 884
 			foreach ($this->pdo_ssl_opts as $key => $pdoopt) {
885 885
 				if ($db[$key]) {
@@ -897,8 +897,8 @@  discard block
 block discarded – undo
897 897
 	 * @access public
898 898
 	 * @return void
899 899
 	 */
900
-	public function connect() {
901
-		parent::connect();
900
+	public function connect () {
901
+		parent::connect ();
902 902
 		//@$this->pdo->query('SET NAMES \'' . $this->charset . '\';');
903 903
 	}
904 904
 
@@ -908,10 +908,10 @@  discard block
 block discarded – undo
908 908
 	 * @access protected
909 909
 	 * @return void
910 910
 	 */
911
-	protected function makeDsn() {
911
+	protected function makeDsn () {
912 912
 		# for installation
913
-		if($this->install)	{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';charset=' . $this->charset; }
914
-		else				{ return 'mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';charset=' . $this->charset; }
913
+		if ($this->install) { return 'mysql:host='.$this->host.';port='.$this->port.';charset='.$this->charset; }
914
+		else { return 'mysql:host='.$this->host.';port='.$this->port.';dbname='.$this->dbname.';charset='.$this->charset; }
915 915
 	}
916 916
 
917 917
 	/**
@@ -920,17 +920,17 @@  discard block
 block discarded – undo
920 920
 	 * @access public
921 921
 	 * @return void
922 922
 	 */
923
-	public function getColumnInfo() {
924
-		$columns = $this->getObjectsQuery("
923
+	public function getColumnInfo () {
924
+		$columns = $this->getObjectsQuery ("
925 925
 			SELECT `table_name`, `column_name`, `column_default`, `is_nullable`, `data_type`,`column_key`, `extra`
926 926
 			FROM `columns`
927
-			WHERE `table_schema`='" . $this->dbname . "';
927
+			WHERE `table_schema`='" . $this->dbname."';
928 928
 		");
929 929
 
930
-		$columnsByTable = array();
930
+		$columnsByTable = array ();
931 931
 		foreach ($columns as $column) {
932 932
 			if (!isset($columnsByTable[$column->table_name])) {
933
-				$columnsByTable[$column->table_name] = array();
933
+				$columnsByTable[$column->table_name] = array ();
934 934
 			}
935 935
 
936 936
 			$columnsByTable[$column->table_name][$column->column_name] = $column;
@@ -945,30 +945,30 @@  discard block
 block discarded – undo
945 945
 	 * @access public
946 946
 	 * @return void
947 947
 	 */
948
-	public function getForeignKeyInfo() {
949
-		$foreignLinks = $this->getObjectsQuery("
948
+	public function getForeignKeyInfo () {
949
+		$foreignLinks = $this->getObjectsQuery ("
950 950
 			SELECT i.`table_name`, k.`column_name`, i.`constraint_type`, i.`constraint_name`, k.`referenced_table_name`, k.`referenced_column_name`
951 951
 			FROM `table_constraints` i
952 952
 			LEFT JOIN `key_column_usage` k ON i.`constraint_name` = k.`constraint_name`
953
-			WHERE i.`constraint_type` = 'FOREIGN KEY' AND i.`table_schema`='" . $this->dbname . "';
953
+			WHERE i.`constraint_type` = 'FOREIGN KEY' AND i.`table_schema`='" . $this->dbname."';
954 954
 		");
955 955
 
956
-		$foreignLinksByTable = array();
957
-		$foreignLinksByRefTable = array();
956
+		$foreignLinksByTable = array ();
957
+		$foreignLinksByRefTable = array ();
958 958
 		foreach ($foreignLinks as $foreignLink) {
959 959
 			if (!isset($foreignLinksByTable[$foreignLink->table_name])) {
960
-				$foreignLinksByTable[$foreignLink->table_name] = array();
960
+				$foreignLinksByTable[$foreignLink->table_name] = array ();
961 961
 			}
962 962
 
963 963
 			if (!isset($foreignLinksByRefTable[$foreignLink->referenced_table_name])) {
964
-				$foreignLinksByRefTable[$foreignLink->referenced_table_name] = array();
964
+				$foreignLinksByRefTable[$foreignLink->referenced_table_name] = array ();
965 965
 			}
966 966
 
967 967
 			$foreignLinksByTable[$foreignLink->table_name][$foreignLink->column_name] = $foreignLink;
968 968
 			$foreignLinksByRefTable[$foreignLink->referenced_table_name][$foreignLink->table_name] = $foreignLink;
969 969
 		}
970 970
 
971
-		return array($foreignLinksByTable, $foreignLinksByRefTable);
971
+		return array ($foreignLinksByTable, $foreignLinksByRefTable);
972 972
 	}
973 973
 }
974 974
 
Please login to merge, or discard this patch.
functions/version.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /* set latest version */
3
-define("VERSION", "1.21");									//version changes if database structure changes
3
+define ("VERSION", "1.21"); //version changes if database structure changes
4 4
 /* set latest revision */
5
-define("REVISION", "001");									//revision always changes, verision only if database structure changes
5
+define ("REVISION", "001"); //revision always changes, verision only if database structure changes
6 6
 /* set last possible upgrade */
7
-define("LAST_POSSIBLE", "1.1");								//minimum required version to be able to upgrade
7
+define ("LAST_POSSIBLE", "1.1"); //minimum required version to be able to upgrade
8 8
 ?>
Please login to merge, or discard this patch.
index.php 3 patches
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	# make upgrade and php build checks
46 46
 	include('functions/checks/check_db_upgrade.php'); 	# check if database needs upgrade
47 47
 	include('functions/checks/check_php_build.php');	# check for support for PHP modules and database connection
48
-	if($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back"){
48
+	if($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back") {
49 49
 		$_SESSION['ipamusername'] = $_SESSION['realipamusername'];
50 50
 		unset($_SESSION['realipamusername']);
51 51
 		print	'<script>window.location.href = "'.create_link(null).'";</script>';
@@ -158,7 +158,10 @@  discard block
 block discarded – undo
158 158
 <!-- page sections / menu -->
159 159
 <div class="content">
160 160
 <div id="sections_overlay">
161
-    <?php if($_GET['page']!="login" && $_GET['page']!="request_ip" && $_GET['page']!="upgrade" && $_GET['page']!="install" && $User->user->passChange!="Yes")  include('app/sections/index.php');?>
161
+    <?php if($_GET['page']!="login" && $_GET['page']!="request_ip" && $_GET['page']!="upgrade" && $_GET['page']!="install" && $User->user->passChange!="Yes") {
162
+    include('app/sections/index.php');
163
+}
164
+?>
162 165
 </div>
163 166
 </div>
164 167
 
@@ -210,7 +213,7 @@  discard block
 block discarded – undo
210 213
 				print "<div id='leftMenu' class='menu-$_GET[page]'>";
211 214
 					if($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
212 215
 					   $_GET['page'] == "vrf" 	  || $_GET['page'] == "folder")			{ include("app/subnets/subnets-menu.php"); }
213
-					else if ($_GET['page'] == "tools")									{ include("app/tools/tools-menu.php"); }
216
+					   else if ($_GET['page'] == "tools")									{ include("app/tools/tools-menu.php"); }
214 217
 					else if ($_GET['page'] == "administration")							{ include("app/admin/admin-menu.php"); }
215 218
 				print "</div>";
216 219
 				print "</td>";
Please login to merge, or discard this patch.
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -13,23 +13,23 @@  discard block
 block discarded – undo
13 13
 
14 14
 # if not install fetch settings etc
15 15
 if($_GET['page']!="install" ) {
16
-	# database object
17
-	$Database 	= new Database_PDO;
18
-
19
-	# check if this is a new installation
20
-	require('functions/checks/check_db_install.php');
21
-
22
-	# initialize objects
23
-	$Result		= new Result;
24
-	$User		= new User ($Database);
25
-	$Sections	= new Sections ($Database);
26
-	$Subnets	= new Subnets ($Database);
27
-	$Tools	    = new Tools ($Database);
28
-	$Addresses	= new Addresses ($Database);
29
-	$Log 		= new Logging ($Database);
30
-
31
-	# reset url for base
32
-	$url = $User->createURL ();
16
+    # database object
17
+    $Database 	= new Database_PDO;
18
+
19
+    # check if this is a new installation
20
+    require('functions/checks/check_db_install.php');
21
+
22
+    # initialize objects
23
+    $Result		= new Result;
24
+    $User		= new User ($Database);
25
+    $Sections	= new Sections ($Database);
26
+    $Subnets	= new Subnets ($Database);
27
+    $Tools	    = new Tools ($Database);
28
+    $Addresses	= new Addresses ($Database);
29
+    $Log 		= new Logging ($Database);
30
+
31
+    # reset url for base
32
+    $url = $User->createURL ();
33 33
 }
34 34
 
35 35
 /** include proper subpage **/
@@ -39,17 +39,17 @@  discard block
 block discarded – undo
39 39
 elseif($_GET['page']=="temp_share")	{ require("app/temp_share/index.php"); }
40 40
 elseif($_GET['page']=="request_ip")	{ require("app/login/index.php"); }
41 41
 else {
42
-	# verify that user is logged in
43
-	$User->check_user_session();
44
-
45
-	# make upgrade and php build checks
46
-	include('functions/checks/check_db_upgrade.php'); 	# check if database needs upgrade
47
-	include('functions/checks/check_php_build.php');	# check for support for PHP modules and database connection
48
-	if($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back"){
49
-		$_SESSION['ipamusername'] = $_SESSION['realipamusername'];
50
-		unset($_SESSION['realipamusername']);
51
-		print	'<script>window.location.href = "'.create_link(null).'";</script>';
52
-	}
42
+    # verify that user is logged in
43
+    $User->check_user_session();
44
+
45
+    # make upgrade and php build checks
46
+    include('functions/checks/check_db_upgrade.php'); 	# check if database needs upgrade
47
+    include('functions/checks/check_php_build.php');	# check for support for PHP modules and database connection
48
+    if($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back"){
49
+        $_SESSION['ipamusername'] = $_SESSION['realipamusername'];
50
+        unset($_SESSION['realipamusername']);
51
+        print	'<script>window.location.href = "'.create_link(null).'";</script>';
52
+    }
53 53
 ?>
54 54
 <!DOCTYPE HTML>
55 55
 <html lang="en">
@@ -168,102 +168,102 @@  discard block
 block discarded – undo
168 168
 <div class="container-fluid" id="mainContainer">
169 169
 		<?php
170 170
 
171
-		/* error */
172
-		if($_GET['page'] == "error") {
173
-			print "<div id='error' class='container'>";
174
-			include_once('app/error.php');
175
-			print "</div>";
176
-		}
177
-		/* password reset required */
178
-		elseif($User->user->passChange=="Yes") {
179
-			print "<div id='dashboard' class='container'>";
180
-			include_once("app/tools/pass-change/form.php");
181
-			print "</div>";
182
-		}
183
-		/* dashboard */
184
-		elseif(!isset($_GET['page']) || $_GET['page'] == "dashboard") {
185
-			print "<div id='dashboard'>";
186
-			include_once("app/dashboard/index.php");
187
-			print "</div>";
188
-		}
189
-		/* widgets */
190
-		elseif($_GET['page']=="widgets") {
191
-			print "<div id='dashboard' class='container'>";
192
-			include_once("app/dashboard/widgets/index.php");
193
-			print "</div>";
194
-		}
195
-		/* content */
196
-		else {
197
-			print "<table id='subnetsMenu'>";
198
-			print "<tr>";
199
-
200
-			# fix for empty section
201
-			if( isset($_GET['section']) && (strlen($_GET['section']) == 0) )			{ unset($_GET['section']); }
202
-
203
-			# hide left menu
204
-			if( ($_GET['page']=="tools"||$_GET['page']=="administration") && !isset($_GET['section'])) {
205
-				//we dont display left menu on empty tools and administration
206
-			}
207
-			else {
208
-				# left menu
209
-				print "<td id='subnetsLeft'>";
210
-				print "<div id='leftMenu' class='menu-$_GET[page]'>";
211
-					if($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
212
-					   $_GET['page'] == "vrf" 	  || $_GET['page'] == "folder")			{ include("app/subnets/subnets-menu.php"); }
213
-					else if ($_GET['page'] == "tools")									{ include("app/tools/tools-menu.php"); }
214
-					else if ($_GET['page'] == "administration")							{ include("app/admin/admin-menu.php"); }
215
-				print "</div>";
216
-				print "</td>";
217
-
218
-			}
219
-
220
-			# content
221
-			print "<td id='subnetsContent'>";
222
-			print "<div class='row menu-$_GET[page]' id='content'>";
223
-				# subnets
224
-				if ($_GET['page']=="subnets") {
225
-					if(@$_GET['sPage'] == "address-details")							{ include("app/subnets/addresses/address-details.php"); }
226
-					elseif(@$_GET['sPage'] == "changelog")								{ include("app/subnets/subnet-changelog.php"); }
227
-					elseif(!isset($_GET['subnetId']))									{ include("app/sections/section-subnets.php"); }
228
-					else																{ include("app/subnets/index.php"); }
229
-				}
230
-				# vrf
231
-				elseif ($_GET['page']=="vrf") 											{ include("app/vrf/index.php"); }
232
-				# vlan
233
-				elseif ($_GET['page']=="vlan") 											{ include("app/vlan/index.php"); }
234
-				# folder
235
-				elseif ($_GET['page']=="folder") 										{ include("app/folder/index.php"); }
236
-				# tools
237
-				elseif ($_GET['page']=="tools") {
238
-					if (!isset($_GET['section']))										{ include("app/tools/index.php"); }
239
-					else {
240
-						if(!file_exists("app/tools/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
241
-						else 															{ include("app/tools/$_GET[section]/index.php"); }
242
-					}
243
-				}
244
-				# admin
245
-				elseif ($_GET['page']=="administration") {
246
-					# Admin object
247
-					$Admin = new Admin ($Database);
248
-
249
-					if (!isset($_GET['section']))										{ include("app/admin/index.php"); }
250
-					elseif (@$_GET['subnetId']=="section-changelog")					{ include("app/sections/section-changelog.php"); }
251
-					else {
252
-						if(!file_exists("app/admin/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
253
-						else 															{ include("app/admin/$_GET[section]/index.php"); }
254
-					}
255
-				}
256
-				# default - error
257
-				else {
258
-																						{ header("Location: ".create_link("error","404")); }
259
-				}
260
-			print "</div>";
261
-			print "</td>";
262
-
263
-			print "</tr>";
264
-			print "</table>";
265
-    	}
266
-    	?>
171
+        /* error */
172
+        if($_GET['page'] == "error") {
173
+            print "<div id='error' class='container'>";
174
+            include_once('app/error.php');
175
+            print "</div>";
176
+        }
177
+        /* password reset required */
178
+        elseif($User->user->passChange=="Yes") {
179
+            print "<div id='dashboard' class='container'>";
180
+            include_once("app/tools/pass-change/form.php");
181
+            print "</div>";
182
+        }
183
+        /* dashboard */
184
+        elseif(!isset($_GET['page']) || $_GET['page'] == "dashboard") {
185
+            print "<div id='dashboard'>";
186
+            include_once("app/dashboard/index.php");
187
+            print "</div>";
188
+        }
189
+        /* widgets */
190
+        elseif($_GET['page']=="widgets") {
191
+            print "<div id='dashboard' class='container'>";
192
+            include_once("app/dashboard/widgets/index.php");
193
+            print "</div>";
194
+        }
195
+        /* content */
196
+        else {
197
+            print "<table id='subnetsMenu'>";
198
+            print "<tr>";
199
+
200
+            # fix for empty section
201
+            if( isset($_GET['section']) && (strlen($_GET['section']) == 0) )			{ unset($_GET['section']); }
202
+
203
+            # hide left menu
204
+            if( ($_GET['page']=="tools"||$_GET['page']=="administration") && !isset($_GET['section'])) {
205
+                //we dont display left menu on empty tools and administration
206
+            }
207
+            else {
208
+                # left menu
209
+                print "<td id='subnetsLeft'>";
210
+                print "<div id='leftMenu' class='menu-$_GET[page]'>";
211
+                    if($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
212
+                       $_GET['page'] == "vrf" 	  || $_GET['page'] == "folder")			{ include("app/subnets/subnets-menu.php"); }
213
+                    else if ($_GET['page'] == "tools")									{ include("app/tools/tools-menu.php"); }
214
+                    else if ($_GET['page'] == "administration")							{ include("app/admin/admin-menu.php"); }
215
+                print "</div>";
216
+                print "</td>";
217
+
218
+            }
219
+
220
+            # content
221
+            print "<td id='subnetsContent'>";
222
+            print "<div class='row menu-$_GET[page]' id='content'>";
223
+                # subnets
224
+                if ($_GET['page']=="subnets") {
225
+                    if(@$_GET['sPage'] == "address-details")							{ include("app/subnets/addresses/address-details.php"); }
226
+                    elseif(@$_GET['sPage'] == "changelog")								{ include("app/subnets/subnet-changelog.php"); }
227
+                    elseif(!isset($_GET['subnetId']))									{ include("app/sections/section-subnets.php"); }
228
+                    else																{ include("app/subnets/index.php"); }
229
+                }
230
+                # vrf
231
+                elseif ($_GET['page']=="vrf") 											{ include("app/vrf/index.php"); }
232
+                # vlan
233
+                elseif ($_GET['page']=="vlan") 											{ include("app/vlan/index.php"); }
234
+                # folder
235
+                elseif ($_GET['page']=="folder") 										{ include("app/folder/index.php"); }
236
+                # tools
237
+                elseif ($_GET['page']=="tools") {
238
+                    if (!isset($_GET['section']))										{ include("app/tools/index.php"); }
239
+                    else {
240
+                        if(!file_exists("app/tools/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
241
+                        else 															{ include("app/tools/$_GET[section]/index.php"); }
242
+                    }
243
+                }
244
+                # admin
245
+                elseif ($_GET['page']=="administration") {
246
+                    # Admin object
247
+                    $Admin = new Admin ($Database);
248
+
249
+                    if (!isset($_GET['section']))										{ include("app/admin/index.php"); }
250
+                    elseif (@$_GET['subnetId']=="section-changelog")					{ include("app/sections/section-changelog.php"); }
251
+                    else {
252
+                        if(!file_exists("app/admin/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
253
+                        else 															{ include("app/admin/$_GET[section]/index.php"); }
254
+                    }
255
+                }
256
+                # default - error
257
+                else {
258
+                                                                                        { header("Location: ".create_link("error","404")); }
259
+                }
260
+            print "</div>";
261
+            print "</td>";
262
+
263
+            print "</tr>";
264
+            print "</table>";
265
+        }
266
+        ?>
267 267
 
268 268
 </div>
269 269
 </div>
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,55 +1,55 @@  discard block
 block discarded – undo
1 1
 <?php
2
-ob_start();
2
+ob_start ();
3 3
 
4 4
 /* config */
5
-if (!file_exists("config.php"))	{ die("<br><hr>-- config.php file missing! Please copy default config file `config.dist.php` to `config.php` and set configuration! --<hr><br>phpipam installation documentation: <a href='http://phpipam.net/documents/installation/'>http://phpipam.net/documents/installation/</a>"); }
6
-else 							{ require('config.php'); }
5
+if (!file_exists ("config.php")) { die("<br><hr>-- config.php file missing! Please copy default config file `config.dist.php` to `config.php` and set configuration! --<hr><br>phpipam installation documentation: <a href='http://phpipam.net/documents/installation/'>http://phpipam.net/documents/installation/</a>"); }
6
+else { require('config.php'); }
7 7
 
8 8
 /* site functions */
9 9
 require('functions/functions.php');
10 10
 
11 11
 # set default page
12
-if(!isset($_GET['page'])) { $_GET['page'] = "dashboard"; }
12
+if (!isset($_GET['page'])) { $_GET['page'] = "dashboard"; }
13 13
 
14 14
 # if not install fetch settings etc
15
-if($_GET['page']!="install" ) {
15
+if ($_GET['page'] != "install") {
16 16
 	# database object
17
-	$Database 	= new Database_PDO;
17
+	$Database = new Database_PDO;
18 18
 
19 19
 	# check if this is a new installation
20 20
 	require('functions/checks/check_db_install.php');
21 21
 
22 22
 	# initialize objects
23 23
 	$Result		= new Result;
24
-	$User		= new User ($Database);
25
-	$Sections	= new Sections ($Database);
24
+	$User = new User ($Database);
25
+	$Sections = new Sections ($Database);
26 26
 	$Subnets	= new Subnets ($Database);
27 27
 	$Tools	    = new Tools ($Database);
28 28
 	$Addresses	= new Addresses ($Database);
29
-	$Log 		= new Logging ($Database);
29
+	$Log = new Logging ($Database);
30 30
 
31 31
 	# reset url for base
32 32
 	$url = $User->createURL ();
33 33
 }
34 34
 
35 35
 /** include proper subpage **/
36
-if($_GET['page']=="install")		{ require("app/install/index.php"); }
37
-elseif($_GET['page']=="upgrade")	{ require("app/upgrade/index.php"); }
38
-elseif($_GET['page']=="login")		{ require("app/login/index.php"); }
39
-elseif($_GET['page']=="temp_share")	{ require("app/temp_share/index.php"); }
40
-elseif($_GET['page']=="request_ip")	{ require("app/login/index.php"); }
41
-elseif($_GET['page']=="opensearch")	{ require("app/tools/search/opensearch.php"); }
36
+if ($_GET['page'] == "install") { require("app/install/index.php"); }
37
+elseif ($_GET['page'] == "upgrade") { require("app/upgrade/index.php"); }
38
+elseif ($_GET['page'] == "login") { require("app/login/index.php"); }
39
+elseif ($_GET['page'] == "temp_share") { require("app/temp_share/index.php"); }
40
+elseif ($_GET['page'] == "request_ip") { require("app/login/index.php"); }
41
+elseif ($_GET['page'] == "opensearch") { require("app/tools/search/opensearch.php"); }
42 42
 else {
43 43
 	# verify that user is logged in
44
-	$User->check_user_session();
44
+	$User->check_user_session ();
45 45
 
46 46
 	# make upgrade and php build checks
47
-	include('functions/checks/check_db_upgrade.php'); 	# check if database needs upgrade
48
-	include('functions/checks/check_php_build.php');	# check for support for PHP modules and database connection
49
-	if($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back"){
47
+	include('functions/checks/check_db_upgrade.php'); # check if database needs upgrade
48
+	include('functions/checks/check_php_build.php'); # check for support for PHP modules and database connection
49
+	if ($_GET['switch'] && $_SESSION['realipamusername'] && $_GET['switch'] == "back") {
50 50
 		$_SESSION['ipamusername'] = $_SESSION['realipamusername'];
51 51
 		unset($_SESSION['realipamusername']);
52
-		print	'<script>window.location.href = "'.create_link(null).'";</script>';
52
+		print	'<script>window.location.href = "'.create_link (null).'";</script>';
53 53
 	}
54 54
 ?>
55 55
 <!DOCTYPE HTML>
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	<!-- js -->
88 88
 	<script type="text/javascript" src="js/1.2/jquery-2.1.3.min.js"></script>
89 89
 	<script type="text/javascript" src="js/1.2/jclock.jquery.js"></script>
90
-	<?php if($_GET['page']=="login" || $_GET['page']=="request_ip") { ?>
90
+	<?php if ($_GET['page'] == "login" || $_GET['page'] == "request_ip") { ?>
91 91
 	<script type="text/javascript" src="js/1.2/login.js"></script>
92 92
 	<?php } ?>
93 93
 	<script type="text/javascript" src="js/1.2/magic.js"></script>
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	     if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); }
103 103
 	});
104 104
 	</script>
105
-	<?php if ($User->settings->enableThreshold=="1") { ?>
105
+	<?php if ($User->settings->enableThreshold == "1") { ?>
106 106
 	<link rel="stylesheet" type="text/css" href="css/1.2/slider.css">
107 107
 	<script type="text/javascript" src="js/1.2/bootstrap-slider.js"></script>
108 108
     <?php }	?>
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 <div class="jqueryError">
122 122
 	<div class='alert alert-danger' style="width:400px;margin:auto">jQuery error!</div>
123 123
 	<div class="jqueryErrorText"></div><br>
124
-	<a href="<?php print create_link(null); ?>" class="btn btn-sm btn-default" id="hideError" style="margin-top:0px;">Hide</a>
124
+	<a href="<?php print create_link (null); ?>" class="btn btn-sm btn-default" id="hideError" style="margin-top:0px;">Hide</a>
125 125
 </div>
126 126
 
127 127
 <!-- Popups -->
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 </div>
142 142
 
143 143
 <!-- loader -->
144
-<div class="loading"><?php print _('Loading');?>...<br><i class="fa fa-spinner fa-spin"></i></div>
144
+<div class="loading"><?php print _ ('Loading'); ?>...<br><i class="fa fa-spinner fa-spin"></i></div>
145 145
 
146 146
 <!-- header -->
147 147
 <div class="row" id="header">
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	<div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-sm-12 col-xs-12">
154 154
 		<div class="hero-pusher hidden-xs hidden-sm"></div>
155 155
 		<div class="hero-unit">
156
-			<a href="<?php print create_link(null); ?>"><?php print $User->settings->siteTitle; ?></a>
156
+			<a href="<?php print create_link (null); ?>"><?php print $User->settings->siteTitle; ?></a>
157 157
 		</div>
158 158
 	</div>
159 159
 </div>
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 <!-- page sections / menu -->
163 163
 <div class="content">
164 164
 <div id="sections_overlay">
165
-    <?php if($_GET['page']!="login" && $_GET['page']!="request_ip" && $_GET['page']!="upgrade" && $_GET['page']!="install" && $User->user->passChange!="Yes")  include('app/sections/index.php');?>
165
+    <?php if ($_GET['page'] != "login" && $_GET['page'] != "request_ip" && $_GET['page'] != "upgrade" && $_GET['page'] != "install" && $User->user->passChange != "Yes")  include('app/sections/index.php'); ?>
166 166
 </div>
167 167
 </div>
168 168
 
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 		<?php
174 174
 
175 175
 		/* error */
176
-		if($_GET['page'] == "error") {
176
+		if ($_GET['page'] == "error") {
177 177
 			print "<div id='error' class='container'>";
178 178
 			include_once('app/error.php');
179 179
 			print "</div>";
180 180
 		}
181 181
 		/* password reset required */
182
-		elseif($User->user->passChange=="Yes") {
182
+		elseif ($User->user->passChange == "Yes") {
183 183
 			print "<div id='dashboard' class='container'>";
184 184
 			include_once("app/tools/pass-change/form.php");
185 185
 			print "</div>";
186 186
 		}
187 187
 		/* dashboard */
188
-		elseif(!isset($_GET['page']) || $_GET['page'] == "dashboard") {
188
+		elseif (!isset($_GET['page']) || $_GET['page'] == "dashboard") {
189 189
 			print "<div id='dashboard'>";
190 190
 			include_once("app/dashboard/index.php");
191 191
 			print "</div>";
192 192
 		}
193 193
 		/* widgets */
194
-		elseif($_GET['page']=="widgets") {
194
+		elseif ($_GET['page'] == "widgets") {
195 195
 			print "<div id='dashboard' class='container'>";
196 196
 			include_once("app/dashboard/widgets/index.php");
197 197
 			print "</div>";
@@ -202,20 +202,20 @@  discard block
 block discarded – undo
202 202
 			print "<tr>";
203 203
 
204 204
 			# fix for empty section
205
-			if( isset($_GET['section']) && (strlen($_GET['section']) == 0) )			{ unset($_GET['section']); }
205
+			if (isset($_GET['section']) && (strlen ($_GET['section']) == 0)) { unset($_GET['section']); }
206 206
 
207 207
 			# hide left menu
208
-			if( ($_GET['page']=="tools"||$_GET['page']=="administration") && !isset($_GET['section'])) {
208
+			if (($_GET['page'] == "tools" || $_GET['page'] == "administration") && !isset($_GET['section'])) {
209 209
 				//we dont display left menu on empty tools and administration
210 210
 			}
211 211
 			else {
212 212
 				# left menu
213 213
 				print "<td id='subnetsLeft'>";
214 214
 				print "<div id='leftMenu' class='menu-$_GET[page]'>";
215
-					if($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
216
-					   $_GET['page'] == "vrf" 	  || $_GET['page'] == "folder")			{ include("app/subnets/subnets-menu.php"); }
217
-					else if ($_GET['page'] == "tools")									{ include("app/tools/tools-menu.php"); }
218
-					else if ($_GET['page'] == "administration")							{ include("app/admin/admin-menu.php"); }
215
+					if ($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
216
+					   $_GET['page'] == "vrf" || $_GET['page'] == "folder") { include("app/subnets/subnets-menu.php"); }
217
+					else if ($_GET['page'] == "tools") { include("app/tools/tools-menu.php"); }
218
+					else if ($_GET['page'] == "administration") { include("app/admin/admin-menu.php"); }
219 219
 				print "</div>";
220 220
 				print "</td>";
221 221
 
@@ -225,41 +225,41 @@  discard block
 block discarded – undo
225 225
 			print "<td id='subnetsContent'>";
226 226
 			print "<div class='row menu-$_GET[page]' id='content'>";
227 227
 				# subnets
228
-				if ($_GET['page']=="subnets") {
229
-					if(@$_GET['sPage'] == "address-details")							{ include("app/subnets/addresses/address-details.php"); }
230
-					elseif(@$_GET['sPage'] == "changelog")								{ include("app/subnets/subnet-changelog.php"); }
231
-					elseif(!isset($_GET['subnetId']))									{ include("app/sections/section-subnets.php"); }
232
-					else																{ include("app/subnets/index.php"); }
228
+				if ($_GET['page'] == "subnets") {
229
+					if (@$_GET['sPage'] == "address-details") { include("app/subnets/addresses/address-details.php"); }
230
+					elseif (@$_GET['sPage'] == "changelog") { include("app/subnets/subnet-changelog.php"); }
231
+					elseif (!isset($_GET['subnetId'])) { include("app/sections/section-subnets.php"); }
232
+					else { include("app/subnets/index.php"); }
233 233
 				}
234 234
 				# vrf
235
-				elseif ($_GET['page']=="vrf") 											{ include("app/vrf/index.php"); }
235
+				elseif ($_GET['page'] == "vrf") { include("app/vrf/index.php"); }
236 236
 				# vlan
237
-				elseif ($_GET['page']=="vlan") 											{ include("app/vlan/index.php"); }
237
+				elseif ($_GET['page'] == "vlan") { include("app/vlan/index.php"); }
238 238
 				# folder
239
-				elseif ($_GET['page']=="folder") 										{ include("app/folder/index.php"); }
239
+				elseif ($_GET['page'] == "folder") { include("app/folder/index.php"); }
240 240
 				# tools
241
-				elseif ($_GET['page']=="tools") {
242
-					if (!isset($_GET['section']))										{ include("app/tools/index.php"); }
241
+				elseif ($_GET['page'] == "tools") {
242
+					if (!isset($_GET['section'])) { include("app/tools/index.php"); }
243 243
 					else {
244
-						if(!file_exists("app/tools/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
245
-						else 															{ include("app/tools/$_GET[section]/index.php"); }
244
+						if (!file_exists ("app/tools/$_GET[section]/index.php")) { header ("Location: ".create_link ("error", "404")); }
245
+						else { include("app/tools/$_GET[section]/index.php"); }
246 246
 					}
247 247
 				}
248 248
 				# admin
249
-				elseif ($_GET['page']=="administration") {
249
+				elseif ($_GET['page'] == "administration") {
250 250
 					# Admin object
251 251
 					$Admin = new Admin ($Database);
252 252
 
253
-					if (!isset($_GET['section']))										{ include("app/admin/index.php"); }
254
-					elseif (@$_GET['subnetId']=="section-changelog")					{ include("app/sections/section-changelog.php"); }
253
+					if (!isset($_GET['section'])) { include("app/admin/index.php"); }
254
+					elseif (@$_GET['subnetId'] == "section-changelog") { include("app/sections/section-changelog.php"); }
255 255
 					else {
256
-						if(!file_exists("app/admin/$_GET[section]/index.php")) 			{ header("Location: ".create_link("error","404")); }
257
-						else 															{ include("app/admin/$_GET[section]/index.php"); }
256
+						if (!file_exists ("app/admin/$_GET[section]/index.php")) { header ("Location: ".create_link ("error", "404")); }
257
+						else { include("app/admin/$_GET[section]/index.php"); }
258 258
 					}
259 259
 				}
260 260
 				# default - error
261 261
 				else {
262
-																						{ header("Location: ".create_link("error","404")); }
262
+																						{ header ("Location: ".create_link ("error", "404")); }
263 263
 				}
264 264
 			print "</div>";
265 265
 			print "</td>";
@@ -293,5 +293,5 @@  discard block
 block discarded – undo
293 293
 <!-- end body -->
294 294
 </body>
295 295
 </html>
296
-<?php ob_end_flush(); ?>
296
+<?php ob_end_flush (); ?>
297 297
 <?php } ?>
298 298
\ No newline at end of file
Please login to merge, or discard this patch.
api/controllers/Folders.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -8,88 +8,88 @@
 block discarded – undo
8 8
  */
9 9
 class Folders_controller extends Common_api_functions {
10 10
 
11
-	/**
12
-	 * __construct function
13
-	 *
14
-	 * @access public
15
-	 * @param class $Database
16
-	 * @param class $Tools
17
-	 * @param mixed $params		// post/get values
18
-	 * @param mixed $Response
19
-	 */
20
-	public function __construct($Database, $Tools, $params, $Response) {
21
-		// include
22
-		require("Subnets.php");
23
-		// subnets
24
-		$this->Subnets_controller = new Subnets_controller ($Database, $Tools, $params, $Response);
25
-	}
26
-
27
-
28
-
29
-
30
-	/**
31
-	 * Options
32
-	 *
33
-	 * @access public
34
-	 * @return void
35
-	 */
36
-	public function OPTIONS () {
37
-		return $this->Subnets_controller->OPTIONS ();
38
-	}
39
-
40
-	/**
41
-	 * HEAD, no response
42
-	 *
43
-	 * @access public
44
-	 * @return void
45
-	 */
46
-	public function HEAD () {
47
-		return $this->Subnets_controller->GET ();
48
-	}
49
-
50
-
51
-	/**
52
-	 * Creates new folder
53
-	 *
54
-	 * @access public
55
-	 * @return void
56
-	 */
57
-	public function POST () {
58
-		return $this->Subnets_controller->POST ();
59
-	}
60
-
61
-
62
-	/**
63
-	 * Read folder functions
64
-	 *
65
-	 * @access public
66
-	 * @return void
67
-	 */
68
-	public function GET () {
69
-		return $this->Subnets_controller->GET ();
70
-	}
71
-
72
-
73
-	/**
74
-	 * Updates existing subnet
75
-	 *
76
-	 * @access public
77
-	 * @return void
78
-	 */
79
-	public function PATCH () {
80
-		return $this->Subnets_controller->PATCH ();
81
-	}
82
-
83
-
84
-	/**
85
-	 * Deletes existing subnet along with and addresses
86
-	 *
87
-	 * @access public
88
-	 * @return void
89
-	 */
90
-	public function DELETE () {
91
-		return $this->Subnets_controller->DELETE ();
92
-	}
11
+    /**
12
+     * __construct function
13
+     *
14
+     * @access public
15
+     * @param class $Database
16
+     * @param class $Tools
17
+     * @param mixed $params		// post/get values
18
+     * @param mixed $Response
19
+     */
20
+    public function __construct($Database, $Tools, $params, $Response) {
21
+        // include
22
+        require("Subnets.php");
23
+        // subnets
24
+        $this->Subnets_controller = new Subnets_controller ($Database, $Tools, $params, $Response);
25
+    }
26
+
27
+
28
+
29
+
30
+    /**
31
+     * Options
32
+     *
33
+     * @access public
34
+     * @return void
35
+     */
36
+    public function OPTIONS () {
37
+        return $this->Subnets_controller->OPTIONS ();
38
+    }
39
+
40
+    /**
41
+     * HEAD, no response
42
+     *
43
+     * @access public
44
+     * @return void
45
+     */
46
+    public function HEAD () {
47
+        return $this->Subnets_controller->GET ();
48
+    }
49
+
50
+
51
+    /**
52
+     * Creates new folder
53
+     *
54
+     * @access public
55
+     * @return void
56
+     */
57
+    public function POST () {
58
+        return $this->Subnets_controller->POST ();
59
+    }
60
+
61
+
62
+    /**
63
+     * Read folder functions
64
+     *
65
+     * @access public
66
+     * @return void
67
+     */
68
+    public function GET () {
69
+        return $this->Subnets_controller->GET ();
70
+    }
71
+
72
+
73
+    /**
74
+     * Updates existing subnet
75
+     *
76
+     * @access public
77
+     * @return void
78
+     */
79
+    public function PATCH () {
80
+        return $this->Subnets_controller->PATCH ();
81
+    }
82
+
83
+
84
+    /**
85
+     * Deletes existing subnet along with and addresses
86
+     *
87
+     * @access public
88
+     * @return void
89
+     */
90
+    public function DELETE () {
91
+        return $this->Subnets_controller->DELETE ();
92
+    }
93 93
 }
94 94
 
95 95
 ?>
96 96
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 	 * @param mixed $params		// post/get values
18 18
 	 * @param mixed $Response
19 19
 	 */
20
-	public function __construct($Database, $Tools, $params, $Response) {
20
+	public function __construct ($Database, $Tools, $params, $Response) {
21 21
 		// include
22 22
 		require("Subnets.php");
23 23
 		// subnets
Please login to merge, or discard this patch.
api/controllers/_template.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,164 +17,164 @@
 block discarded – undo
17 17
 class Tools_controller extends Common_api_functions {
18 18
 
19 19
 
20
-	/**
21
-	 * sets output - JSON or XML
22
-	 *
23
-	 * @var mixed
24
-	 * @access public
25
-	 */
26
-	public $result_type;
27
-
28
-	/**
29
-	 * result
30
-	 *
31
-	 * @var mixed
32
-	 * @access public
33
-	 */
34
-	public $result;
35
-
36
-	/**
37
-	 * Database object
38
-	 *
39
-	 * @var mixed
40
-	 * @access protected
41
-	 */
42
-	protected $Database;
43
-
44
-	/**
45
-	 * Response object
46
-	 *
47
-	 * @var mixed
48
-	 * @access protected
49
-	 */
50
-	protected $Response;
20
+    /**
21
+     * sets output - JSON or XML
22
+     *
23
+     * @var mixed
24
+     * @access public
25
+     */
26
+    public $result_type;
27
+
28
+    /**
29
+     * result
30
+     *
31
+     * @var mixed
32
+     * @access public
33
+     */
34
+    public $result;
35
+
36
+    /**
37
+     * Database object
38
+     *
39
+     * @var mixed
40
+     * @access protected
41
+     */
42
+    protected $Database;
43
+
44
+    /**
45
+     * Response object
46
+     *
47
+     * @var mixed
48
+     * @access protected
49
+     */
50
+    protected $Response;
51 51
 
52
-	/**
53
-	 * Tools object
54
-	 *
55
-	 * @var mixed
56
-	 * @access protected
57
-	 */
58
-	protected $Tools;
52
+    /**
53
+     * Tools object
54
+     *
55
+     * @var mixed
56
+     * @access protected
57
+     */
58
+    protected $Tools;
59 59
 
60
-	/**
61
-	 * Parameters
62
-	 *
63
-	 * @var mixed
64
-	 * @access public
65
-	 */
66
-	public $_params;
60
+    /**
61
+     * Parameters
62
+     *
63
+     * @var mixed
64
+     * @access public
65
+     */
66
+    public $_params;
67 67
 
68 68
 
69
-	/**
70
-	 * __construct function
71
-	 *
72
-	 * @access public
73
-	 * @param class $Database
74
-	 * @param class $Tools
75
-	 * @param mixed $params		// post/get values
76
-	 */
77
-	public function __construct($Database, $Tools, $params, $Response) {
78
-		$this->Database = $Database;
79
-		$this->Response = $Response;
80
-		$this->Tools 	= $Tools;
81
-		$this->_params 	= $params;
82
-		// init required objects
83
-		$this->init_object ("Subnets", $Database);
84
-		// set valid keys
85
-		$this->set_valid_keys ("mydatabase");
86
-	}
69
+    /**
70
+     * __construct function
71
+     *
72
+     * @access public
73
+     * @param class $Database
74
+     * @param class $Tools
75
+     * @param mixed $params		// post/get values
76
+     */
77
+    public function __construct($Database, $Tools, $params, $Response) {
78
+        $this->Database = $Database;
79
+        $this->Response = $Response;
80
+        $this->Tools 	= $Tools;
81
+        $this->_params 	= $params;
82
+        // init required objects
83
+        $this->init_object ("Subnets", $Database);
84
+        // set valid keys
85
+        $this->set_valid_keys ("mydatabase");
86
+    }
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-	/**
93
-	 * returns general options
94
-	 *
95
-	 * @access public
96
-	 * @return void
97
-	 */
98
-	public function OPTIONS () {
92
+    /**
93
+     * returns general options
94
+     *
95
+     * @access public
96
+     * @return void
97
+     */
98
+    public function OPTIONS () {
99 99
 
100
-	}
100
+    }
101 101
 
102 102
 
103 103
 
104 104
 
105 105
 
106 106
 
107
-	/**
108
-	 * Creates new object
109
-	 *
110
-	 * @access public
111
-	 * @return void
112
-	 */
113
-	public function POST () {
114
-		// remap keys if needed
115
-		$this->remap_keys ();
116
-		// check for valid keys
117
-		$this->validate_keys ();
118
-	}
107
+    /**
108
+     * Creates new object
109
+     *
110
+     * @access public
111
+     * @return void
112
+     */
113
+    public function POST () {
114
+        // remap keys if needed
115
+        $this->remap_keys ();
116
+        // check for valid keys
117
+        $this->validate_keys ();
118
+    }
119 119
 
120 120
 
121 121
 
122 122
 
123 123
 
124
-	/**
125
-	 * Reads object
126
-	 *
127
-	 * @access public
128
-	 * @return void
129
-	 */
130
-	public function GET () {
124
+    /**
125
+     * Reads object
126
+     *
127
+     * @access public
128
+     * @return void
129
+     */
130
+    public function GET () {
131 131
 
132
-	}
132
+    }
133 133
 
134 134
 
135 135
 
136 136
 
137 137
 
138
-	/**
139
-	 * HEAD, no response
140
-	 *
141
-	 * @access public
142
-	 * @return void
143
-	 */
144
-	public function HEAD () {
145
-		return $this->GET ();
146
-	}
138
+    /**
139
+     * HEAD, no response
140
+     *
141
+     * @access public
142
+     * @return void
143
+     */
144
+    public function HEAD () {
145
+        return $this->GET ();
146
+    }
147 147
 
148 148
 
149 149
 
150 150
 
151 151
 
152
-	/**
153
-	 * Update object
154
-	 *
155
-	 * @access public
156
-	 * @return void
157
-	 */
158
-	public function PATCH () {
159
-		// remap keys if needed
160
-		$this->remap_keys ();
161
-		// check for valid keys
162
-		$this->validate_keys ();
163
-	}
152
+    /**
153
+     * Update object
154
+     *
155
+     * @access public
156
+     * @return void
157
+     */
158
+    public function PATCH () {
159
+        // remap keys if needed
160
+        $this->remap_keys ();
161
+        // check for valid keys
162
+        $this->validate_keys ();
163
+    }
164 164
 
165 165
 
166 166
 
167 167
 
168 168
 
169
-	/**
170
-	 * Deletes existing object
171
-	 *
172
-	 * @access public
173
-	 * @return void
174
-	 */
175
-	public function DELETE () {
169
+    /**
170
+     * Deletes existing object
171
+     *
172
+     * @access public
173
+     * @return void
174
+     */
175
+    public function DELETE () {
176 176
 
177
-	}
177
+    }
178 178
 }
179 179
 
180 180
 ?>
181 181
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
17 17
 	 * @param mixed $params		// post/get values
18 18
 	 * @param mixed $Response
19 19
 	 */
20
-	public function __construct($Database, $Tools, $params, $Response) {
20
+	public function __construct ($Database, $Tools, $params, $Response) {
21 21
 		$this->Database = $Database;
22
-		$this->Tools 	= $Tools;
22
+		$this->Tools = $Tools;
23 23
 		$this->_params 	= $params;
24 24
 		$this->Response = $Response;
25 25
 		// include
Please login to merge, or discard this patch.
api/controllers/L2domains.php 3 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		# execute update
164 164
 		if(!$this->Admin->object_modify ("vrf", "add", "vrfId", $values))
165 165
 													{ $this->Response->throw_exception(500, "VRF creation failed"); }
166
-		else {
166
+													else {
167 167
 			//set result
168 168
 			return array("code"=>201, "data"=>"VRF created", "location"=>"/api/".$this->_params->app_id."/vrfs/".$this->Admin->lastId."/");
169 169
 		}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		# execute update
196 196
 		if(!$this->Admin->object_modify ("vrf", "edit", "vrfId", $values))
197 197
 													{ $this->Response->throw_exception(500, "Vrf edit failed"); }
198
-		else {
198
+													else {
199 199
 			//set result
200 200
 			return array("code"=>200, "data"=>"VRF updated");
201 201
 		}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		# execute delete
223 223
 		if(!$this->Admin->object_modify ("vrf", "delete", "vrfId", $values))
224 224
 													{ $this->Response->throw_exception(500, "Vrf delete failed"); }
225
-		else {
225
+													else {
226 226
 			// delete all references
227 227
 			$this->Admin->remove_object_references ("subnets", "vrfId", $this->_params->id);
228 228
 
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 * @param class $Tools
67 67
 	 * @param mixed $params		// post/get values
68 68
 	 */
69
-	public function __construct($Database, $Tools, $params, $Response) {
69
+	public function __construct ($Database, $Tools, $params, $Response) {
70 70
 		$this->Database = $Database;
71
-		$this->Tools 	= $Tools;
71
+		$this->Tools = $Tools;
72 72
 		$this->_params 	= $params;
73 73
 		$this->Response = $Response;
74 74
 		// init required objects
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
 		$this->validate_options_request ();
95 95
 
96 96
 		// methods
97
-		$result = array();
98
-		$result['methods'] = array(
99
-								array("href"=>"/api/l2domains/".$this->_params->app_id."/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
100
-								array("href"=>"/api/l2domains/".$this->_params->app_id."/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
101
-																												 	array("rel"=>"create", "method"=>"POST"),
102
-																												 	array("rel"=>"update", "method"=>"PATCH"),
103
-																												 	array("rel"=>"delete", "method"=>"DELETE"))),
97
+		$result = array ();
98
+		$result['methods'] = array (
99
+								array ("href"=>"/api/l2domains/".$this->_params->app_id."/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))),
100
+								array ("href"=>"/api/l2domains/".$this->_params->app_id."/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"),
101
+																												 	array ("rel"=>"create", "method"=>"POST"),
102
+																												 	array ("rel"=>"update", "method"=>"PATCH"),
103
+																												 	array ("rel"=>"delete", "method"=>"DELETE"))),
104 104
 							);
105 105
 		# result
106
-		return array("code"=>200, "data"=>$result);
106
+		return array ("code"=>200, "data"=>$result);
107 107
 	}
108 108
 
109 109
 
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public function GET () {
126 126
 		// all domains
127
-		if(!isset($this->_params->id)) {
127
+		if (!isset($this->_params->id)) {
128 128
 			$result = $this->Tools->fetch_all_objects ("vlanDomains", 'id', true);
129 129
 			// check result
130
-			if($result===false)						{ $this->Response->throw_exception(404, 'No domains configured'); }
131
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
130
+			if ($result === false) { $this->Response->throw_exception (404, 'No domains configured'); }
131
+			else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
132 132
 		}
133 133
 		// set
134 134
 		else {
135 135
 			// custom fields
136
-			if($this->_params->id=="custom_fields") {
137
-				if(sizeof($this->custom_fields)==0)	{ $this->Response->throw_exception(404, 'No custom fields defined'); }
138
-				else								{ return array("code"=>200, "data"=>$this->custom_fields); }
136
+			if ($this->_params->id == "custom_fields") {
137
+				if (sizeof ($this->custom_fields) == 0) { $this->Response->throw_exception (404, 'No custom fields defined'); }
138
+				else { return array ("code"=>200, "data"=>$this->custom_fields); }
139 139
 			}
140 140
 			// vlans
141
-			elseif (@$this->_params->id2=="vlans") {
141
+			elseif (@$this->_params->id2 == "vlans") {
142 142
 				// validate domain
143 143
 				$this->validate_domain ();
144 144
 				// save result
145 145
 				$result = $this->Tools->fetch_multiple_objects ("vlans", "domainId", $this->_params->id, 'vlanId', true);
146 146
 				// check result
147
-				if($result==NULL)					{ $this->Response->throw_exception(404, "No vlans belonging to this domain"); }
148
-				else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
147
+				if ($result == NULL) { $this->Response->throw_exception (404, "No vlans belonging to this domain"); }
148
+				else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
149 149
 			}
150 150
 			// id
151 151
 			else {
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 				// result
155 155
 				$result = $this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id);
156 156
 				// check result
157
-				if($result==NULL)					{ $this->Response->throw_exception(404, "Invalid domain id"); }
158
-				else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
157
+				if ($result == NULL) { $this->Response->throw_exception (404, "Invalid domain id"); }
158
+				else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
159 159
 			}
160 160
 
161 161
 		}
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 		$this->validate_domain_edit ();
194 194
 
195 195
 		# execute update
196
-		if(!$this->Admin->object_modify ("vlanDomains", "add", "id", $values))
197
-													{ $this->Response->throw_exception(500, "Domain creation failed"); }
196
+		if (!$this->Admin->object_modify ("vlanDomains", "add", "id", $values))
197
+													{ $this->Response->throw_exception (500, "Domain creation failed"); }
198 198
 		else {
199 199
 			//set result
200
-			return array("code"=>201, "data"=>"L2 domain created", "location"=>"/api/".$this->_params->app_id."/l2domains/".$this->Admin->lastId."/");
200
+			return array ("code"=>201, "data"=>"L2 domain created", "location"=>"/api/".$this->_params->app_id."/l2domains/".$this->Admin->lastId."/");
201 201
 		}
202 202
 	}
203 203
 
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
 		$values = $this->validate_keys ();
222 222
 
223 223
 		# execute update
224
-		if(!$this->Admin->object_modify ("vlanDomains", "edit", "id", $values))
225
-													{ $this->Response->throw_exception(500, "Domain edit failed"); }
224
+		if (!$this->Admin->object_modify ("vlanDomains", "edit", "id", $values))
225
+													{ $this->Response->throw_exception (500, "Domain edit failed"); }
226 226
 		else {
227 227
 			//set result
228
-			return array("code"=>200, "data"=>"L2 domain updated");
228
+			return array ("code"=>200, "data"=>"L2 domain updated");
229 229
 		}
230 230
 	}
231 231
 
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 		$this->validate_domain ();
247 247
 
248 248
 		# set variables for update
249
-		$values = array();
249
+		$values = array ();
250 250
 		$values["id"] = $this->_params->id;
251 251
 
252 252
 		# execute delete
253
-		if(!$this->Admin->object_modify ("vlanDomains", "delete", "id", $values))
254
-													{ $this->Response->throw_exception(500, "L2 domain delete failed"); }
253
+		if (!$this->Admin->object_modify ("vlanDomains", "delete", "id", $values))
254
+													{ $this->Response->throw_exception (500, "L2 domain delete failed"); }
255 255
 		else {
256 256
 			// delete references, reset to default
257 257
 			$this->Admin->update_object_references ("vlans", "domainId", $this->_params->id, 1);
258 258
 
259 259
 			// set result
260
-			return array("code"=>200, "data"=>"L2 domain deleted and vlans migrated to default domain");
260
+			return array ("code"=>200, "data"=>"L2 domain deleted and vlans migrated to default domain");
261 261
 		}
262 262
 	}
263 263
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 */
280 280
 	private function validate_domain () {
281 281
 		// validate id
282
-		if(!isset($this->_params->id))														{ $this->_params->id = 1; }
282
+		if (!isset($this->_params->id)) { $this->_params->id = 1; }
283 283
 		// validate number
284
-		if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
284
+		if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Domain id must be numeric"); }
285 285
 		// check that it exists
286
-		if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id) === false )
287
-																							{ $this->Response->throw_exception(400, "Invalid domain id"); }
286
+		if ($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id) === false)
287
+																							{ $this->Response->throw_exception (400, "Invalid domain id"); }
288 288
 	}
289 289
 
290 290
 
@@ -296,23 +296,23 @@  discard block
 block discarded – undo
296 296
 	 */
297 297
 	private function validate_domain_edit () {
298 298
 		// delete checks
299
-		if($_SERVER['REQUEST_METHOD']=="DELETE") {
299
+		if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
300 300
 			// we cannot delete default domain
301
-			if(@$this->_params->id==1 && $_SERVER['REQUEST_METHOD']=="DELETE")				{ $this->Response->throw_exception(400, "Default domain cannot be deleted"); }
301
+			if (@$this->_params->id == 1 && $_SERVER['REQUEST_METHOD'] == "DELETE") { $this->Response->throw_exception (400, "Default domain cannot be deleted"); }
302 302
 			// ID must be numeric
303
-			if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
303
+			if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Invalid domain id"); }
304 304
 		}
305 305
 		// create checks
306
-		elseif ($_SERVER['REQUEST_METHOD']=="POST") {
306
+		elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
307 307
 			// name must be present
308
-			if(@$this->_params->name == "" || !isset($this->_params->name)) 				{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
308
+			if (@$this->_params->name == "" || !isset($this->_params->name)) { $this->Response->throw_exception (400, "Domain name is mandatory"); }
309 309
 		}
310 310
 		// update checks
311
-		elseif ($_SERVER['REQUEST_METHOD']=="PATCH") {
311
+		elseif ($_SERVER['REQUEST_METHOD'] == "PATCH") {
312 312
 			// ID must be numeric
313
-			if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
313
+			if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Invalid domain id"); }
314 314
 			// name must be present
315
-			if(@$this->_params->name == "" && isset($this->_params->name)) 					{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
315
+			if (@$this->_params->name == "" && isset($this->_params->name)) { $this->Response->throw_exception (400, "Domain name is mandatory"); }
316 316
 		}
317 317
 
318 318
 	}
Please login to merge, or discard this patch.
Indentation   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -9,257 +9,257 @@  discard block
 block discarded – undo
9 9
 class L2domains_controller extends Common_api_functions {
10 10
 
11 11
 
12
-	/**
13
-	 * _params provided
14
-	 *
15
-	 * @var mixed
16
-	 * @access public
17
-	 */
18
-	public $_params;
19
-
20
-	/**
21
-	 * custom_fields
22
-	 *
23
-	 * @var mixed
24
-	 * @access protected
25
-	 */
26
-	public $custom_fields;
27
-
28
-	/**
29
-	 * Database object
30
-	 *
31
-	 * @var mixed
32
-	 * @access protected
33
-	 */
34
-	protected $Database;
35
-
36
-	/**
37
-	 * master Sections object
38
-	 *
39
-	 * @var mixed
40
-	 * @access protected
41
-	 */
42
-	protected $Sections;
43
-
44
-	/**
45
-	 * Master Tools object
46
-	 *
47
-	 * @var mixed
48
-	 * @access protected
49
-	 */
50
-	protected $Tools;
51
-
52
-	/**
53
-	 * Master Admin object
54
-	 *
55
-	 * @var mixed
56
-	 * @access protected
57
-	 */
58
-	protected $Admin;
59
-
60
-
61
-	/**
62
-	 * __construct function
63
-	 *
64
-	 * @access public
65
-	 * @param class $Database
66
-	 * @param class $Tools
67
-	 * @param mixed $params		// post/get values
68
-	 */
69
-	public function __construct($Database, $Tools, $params, $Response) {
70
-		$this->Database = $Database;
71
-		$this->Tools 	= $Tools;
72
-		$this->_params 	= $params;
73
-		$this->Response = $Response;
74
-		// init required objects
75
-		$this->init_object ("Admin", $Database);
76
-		$this->init_object ("Subnets", $Database);
77
-		// set valid keys
78
-		$this->set_valid_keys ("vlanDomains");
79
-	}
80
-
81
-
82
-
83
-
84
-
85
-
86
-	/**
87
-	 * Returns json encoded options
88
-	 *
89
-	 * @access public
90
-	 * @return void
91
-	 */
92
-	public function OPTIONS () {
93
-		// validate
94
-		$this->validate_options_request ();
95
-
96
-		// methods
97
-		$result = array();
98
-		$result['methods'] = array(
99
-								array("href"=>"/api/l2domains/".$this->_params->app_id."/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
100
-								array("href"=>"/api/l2domains/".$this->_params->app_id."/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
101
-																												 	array("rel"=>"create", "method"=>"POST"),
102
-																												 	array("rel"=>"update", "method"=>"PATCH"),
103
-																												 	array("rel"=>"delete", "method"=>"DELETE"))),
104
-							);
105
-		# result
106
-		return array("code"=>200, "data"=>$result);
107
-	}
108
-
109
-
110
-
111
-
112
-
113
-	/**
114
-	 * Read domain functions
115
-	 *
116
-	 *	identifier can be:
117
-	 *		- NONE 				// will return all domains
118
-	 *		- {id}
119
-	 *		- {id}/vlans/
120
-	 *		- custom_fields
121
-	 *
122
-	 * @access public
123
-	 * @return void
124
-	 */
125
-	public function GET () {
126
-		// all domains
127
-		if(!isset($this->_params->id)) {
128
-			$result = $this->Tools->fetch_all_objects ("vlanDomains", 'id', true);
129
-			// check result
130
-			if($result===false)						{ $this->Response->throw_exception(404, 'No domains configured'); }
131
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
132
-		}
133
-		// set
134
-		else {
135
-			// custom fields
136
-			if($this->_params->id=="custom_fields") {
137
-				if(sizeof($this->custom_fields)==0)	{ $this->Response->throw_exception(404, 'No custom fields defined'); }
138
-				else								{ return array("code"=>200, "data"=>$this->custom_fields); }
139
-			}
140
-			// vlans
141
-			elseif (@$this->_params->id2=="vlans") {
142
-				// validate domain
143
-				$this->validate_domain ();
144
-				// save result
145
-				$result = $this->Tools->fetch_multiple_objects ("vlans", "domainId", $this->_params->id, 'vlanId', true);
146
-				// check result
147
-				if($result==NULL)					{ $this->Response->throw_exception(404, "No vlans belonging to this domain"); }
148
-				else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
149
-			}
150
-			// id
151
-			else {
152
-				// validate domain
153
-				$this->validate_domain ();
154
-				// result
155
-				$result = $this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id);
156
-				// check result
157
-				if($result==NULL)					{ $this->Response->throw_exception(404, "Invalid domain id"); }
158
-				else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
159
-			}
160
-
161
-		}
162
-	}
163
-
164
-
165
-
166
-
167
-	/**
168
-	 * HEAD, no response
169
-	 *
170
-	 * @access public
171
-	 * @return void
172
-	 */
173
-	public function HEAD () {
174
-		return $this->GET ();
175
-	}
12
+    /**
13
+     * _params provided
14
+     *
15
+     * @var mixed
16
+     * @access public
17
+     */
18
+    public $_params;
19
+
20
+    /**
21
+     * custom_fields
22
+     *
23
+     * @var mixed
24
+     * @access protected
25
+     */
26
+    public $custom_fields;
27
+
28
+    /**
29
+     * Database object
30
+     *
31
+     * @var mixed
32
+     * @access protected
33
+     */
34
+    protected $Database;
35
+
36
+    /**
37
+     * master Sections object
38
+     *
39
+     * @var mixed
40
+     * @access protected
41
+     */
42
+    protected $Sections;
43
+
44
+    /**
45
+     * Master Tools object
46
+     *
47
+     * @var mixed
48
+     * @access protected
49
+     */
50
+    protected $Tools;
51
+
52
+    /**
53
+     * Master Admin object
54
+     *
55
+     * @var mixed
56
+     * @access protected
57
+     */
58
+    protected $Admin;
59
+
60
+
61
+    /**
62
+     * __construct function
63
+     *
64
+     * @access public
65
+     * @param class $Database
66
+     * @param class $Tools
67
+     * @param mixed $params		// post/get values
68
+     */
69
+    public function __construct($Database, $Tools, $params, $Response) {
70
+        $this->Database = $Database;
71
+        $this->Tools 	= $Tools;
72
+        $this->_params 	= $params;
73
+        $this->Response = $Response;
74
+        // init required objects
75
+        $this->init_object ("Admin", $Database);
76
+        $this->init_object ("Subnets", $Database);
77
+        // set valid keys
78
+        $this->set_valid_keys ("vlanDomains");
79
+    }
80
+
81
+
82
+
83
+
84
+
85
+
86
+    /**
87
+     * Returns json encoded options
88
+     *
89
+     * @access public
90
+     * @return void
91
+     */
92
+    public function OPTIONS () {
93
+        // validate
94
+        $this->validate_options_request ();
95
+
96
+        // methods
97
+        $result = array();
98
+        $result['methods'] = array(
99
+                                array("href"=>"/api/l2domains/".$this->_params->app_id."/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
100
+                                array("href"=>"/api/l2domains/".$this->_params->app_id."/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
101
+                                                                                                                        array("rel"=>"create", "method"=>"POST"),
102
+                                                                                                                        array("rel"=>"update", "method"=>"PATCH"),
103
+                                                                                                                        array("rel"=>"delete", "method"=>"DELETE"))),
104
+                            );
105
+        # result
106
+        return array("code"=>200, "data"=>$result);
107
+    }
108
+
109
+
110
+
111
+
112
+
113
+    /**
114
+     * Read domain functions
115
+     *
116
+     *	identifier can be:
117
+     *		- NONE 				// will return all domains
118
+     *		- {id}
119
+     *		- {id}/vlans/
120
+     *		- custom_fields
121
+     *
122
+     * @access public
123
+     * @return void
124
+     */
125
+    public function GET () {
126
+        // all domains
127
+        if(!isset($this->_params->id)) {
128
+            $result = $this->Tools->fetch_all_objects ("vlanDomains", 'id', true);
129
+            // check result
130
+            if($result===false)						{ $this->Response->throw_exception(404, 'No domains configured'); }
131
+            else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
132
+        }
133
+        // set
134
+        else {
135
+            // custom fields
136
+            if($this->_params->id=="custom_fields") {
137
+                if(sizeof($this->custom_fields)==0)	{ $this->Response->throw_exception(404, 'No custom fields defined'); }
138
+                else								{ return array("code"=>200, "data"=>$this->custom_fields); }
139
+            }
140
+            // vlans
141
+            elseif (@$this->_params->id2=="vlans") {
142
+                // validate domain
143
+                $this->validate_domain ();
144
+                // save result
145
+                $result = $this->Tools->fetch_multiple_objects ("vlans", "domainId", $this->_params->id, 'vlanId', true);
146
+                // check result
147
+                if($result==NULL)					{ $this->Response->throw_exception(404, "No vlans belonging to this domain"); }
148
+                else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
149
+            }
150
+            // id
151
+            else {
152
+                // validate domain
153
+                $this->validate_domain ();
154
+                // result
155
+                $result = $this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id);
156
+                // check result
157
+                if($result==NULL)					{ $this->Response->throw_exception(404, "Invalid domain id"); }
158
+                else								{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
159
+            }
160
+
161
+        }
162
+    }
163
+
164
+
165
+
166
+
167
+    /**
168
+     * HEAD, no response
169
+     *
170
+     * @access public
171
+     * @return void
172
+     */
173
+    public function HEAD () {
174
+        return $this->GET ();
175
+    }
176 176
 
177 177
 
178 178
 
179 179
 
180 180
 
181 181
 
182
-	/**
183
-	 * Creates new domain
184
-	 *
185
-	 * @access public
186
-	 * @return void
187
-	 */
188
-	public function POST () {
189
-		# check for valid keys
190
-		$values = $this->validate_keys ();
191
-
192
-		# validate input
193
-		$this->validate_domain_edit ();
194
-
195
-		# execute update
196
-		if(!$this->Admin->object_modify ("vlanDomains", "add", "id", $values))
197
-													{ $this->Response->throw_exception(500, "Domain creation failed"); }
198
-		else {
199
-			//set result
200
-			return array("code"=>201, "data"=>"L2 domain created", "location"=>"/api/".$this->_params->app_id."/l2domains/".$this->Admin->lastId."/");
201
-		}
202
-	}
203
-
204
-
205
-
206
-
207
-
208
-	/**
209
-	 * Updates existing domain
210
-	 *
211
-	 * @access public
212
-	 * @return void
213
-	 */
214
-	public function PATCH () {
215
-		# verify
216
-		$this->validate_domain_edit ();
217
-		# check that it exists
218
-		$this->validate_domain ();
219
-
220
-		# validate and prepare keys
221
-		$values = $this->validate_keys ();
222
-
223
-		# execute update
224
-		if(!$this->Admin->object_modify ("vlanDomains", "edit", "id", $values))
225
-													{ $this->Response->throw_exception(500, "Domain edit failed"); }
226
-		else {
227
-			//set result
228
-			return array("code"=>200, "data"=>"L2 domain updated");
229
-		}
230
-	}
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-	/**
239
-	 * Deletes existing domain
240
-	 *
241
-	 * @access public
242
-	 * @return void
243
-	 */
244
-	public function DELETE () {
245
-		# check that domain exists
246
-		$this->validate_domain ();
182
+    /**
183
+     * Creates new domain
184
+     *
185
+     * @access public
186
+     * @return void
187
+     */
188
+    public function POST () {
189
+        # check for valid keys
190
+        $values = $this->validate_keys ();
191
+
192
+        # validate input
193
+        $this->validate_domain_edit ();
194
+
195
+        # execute update
196
+        if(!$this->Admin->object_modify ("vlanDomains", "add", "id", $values))
197
+                                                    { $this->Response->throw_exception(500, "Domain creation failed"); }
198
+        else {
199
+            //set result
200
+            return array("code"=>201, "data"=>"L2 domain created", "location"=>"/api/".$this->_params->app_id."/l2domains/".$this->Admin->lastId."/");
201
+        }
202
+    }
203
+
204
+
205
+
206
+
207
+
208
+    /**
209
+     * Updates existing domain
210
+     *
211
+     * @access public
212
+     * @return void
213
+     */
214
+    public function PATCH () {
215
+        # verify
216
+        $this->validate_domain_edit ();
217
+        # check that it exists
218
+        $this->validate_domain ();
219
+
220
+        # validate and prepare keys
221
+        $values = $this->validate_keys ();
222
+
223
+        # execute update
224
+        if(!$this->Admin->object_modify ("vlanDomains", "edit", "id", $values))
225
+                                                    { $this->Response->throw_exception(500, "Domain edit failed"); }
226
+        else {
227
+            //set result
228
+            return array("code"=>200, "data"=>"L2 domain updated");
229
+        }
230
+    }
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+    /**
239
+     * Deletes existing domain
240
+     *
241
+     * @access public
242
+     * @return void
243
+     */
244
+    public function DELETE () {
245
+        # check that domain exists
246
+        $this->validate_domain ();
247 247
 
248
-		# set variables for update
249
-		$values = array();
250
-		$values["id"] = $this->_params->id;
248
+        # set variables for update
249
+        $values = array();
250
+        $values["id"] = $this->_params->id;
251 251
 
252
-		# execute delete
253
-		if(!$this->Admin->object_modify ("vlanDomains", "delete", "id", $values))
254
-													{ $this->Response->throw_exception(500, "L2 domain delete failed"); }
255
-		else {
256
-			// delete references, reset to default
257
-			$this->Admin->update_object_references ("vlans", "domainId", $this->_params->id, 1);
252
+        # execute delete
253
+        if(!$this->Admin->object_modify ("vlanDomains", "delete", "id", $values))
254
+                                                    { $this->Response->throw_exception(500, "L2 domain delete failed"); }
255
+        else {
256
+            // delete references, reset to default
257
+            $this->Admin->update_object_references ("vlans", "domainId", $this->_params->id, 1);
258 258
 
259
-			// set result
260
-			return array("code"=>200, "data"=>"L2 domain deleted and vlans migrated to default domain");
261
-		}
262
-	}
259
+            // set result
260
+            return array("code"=>200, "data"=>"L2 domain deleted and vlans migrated to default domain");
261
+        }
262
+    }
263 263
 
264 264
 
265 265
 
@@ -269,53 +269,53 @@  discard block
 block discarded – undo
269 269
 
270 270
 
271 271
 
272
-	/* @validations ---------- */
272
+    /* @validations ---------- */
273 273
 
274
-	/**
275
-	 * Validates domains
276
-	 *
277
-	 * @access private
278
-	 * @return void
279
-	 */
280
-	private function validate_domain () {
281
-		// validate id
282
-		if(!isset($this->_params->id))														{ $this->_params->id = 1; }
283
-		// validate number
284
-		if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
285
-		// check that it exists
286
-		if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id) === false )
287
-																							{ $this->Response->throw_exception(400, "Invalid domain id"); }
288
-	}
274
+    /**
275
+     * Validates domains
276
+     *
277
+     * @access private
278
+     * @return void
279
+     */
280
+    private function validate_domain () {
281
+        // validate id
282
+        if(!isset($this->_params->id))														{ $this->_params->id = 1; }
283
+        // validate number
284
+        if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
285
+        // check that it exists
286
+        if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->id) === false )
287
+                                                                                            { $this->Response->throw_exception(400, "Invalid domain id"); }
288
+    }
289 289
 
290 290
 
291
-	/**
292
-	 * Validates domain on edit
293
-	 *
294
-	 * @access private
295
-	 * @return void
296
-	 */
297
-	private function validate_domain_edit () {
298
-		// delete checks
299
-		if($_SERVER['REQUEST_METHOD']=="DELETE") {
300
-			// we cannot delete default domain
301
-			if(@$this->_params->id==1 && $_SERVER['REQUEST_METHOD']=="DELETE")				{ $this->Response->throw_exception(400, "Default domain cannot be deleted"); }
302
-			// ID must be numeric
303
-			if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
304
-		}
305
-		// create checks
306
-		elseif ($_SERVER['REQUEST_METHOD']=="POST") {
307
-			// name must be present
308
-			if(@$this->_params->name == "" || !isset($this->_params->name)) 				{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
309
-		}
310
-		// update checks
311
-		elseif ($_SERVER['REQUEST_METHOD']=="PATCH") {
312
-			// ID must be numeric
313
-			if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
314
-			// name must be present
315
-			if(@$this->_params->name == "" && isset($this->_params->name)) 					{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
316
-		}
291
+    /**
292
+     * Validates domain on edit
293
+     *
294
+     * @access private
295
+     * @return void
296
+     */
297
+    private function validate_domain_edit () {
298
+        // delete checks
299
+        if($_SERVER['REQUEST_METHOD']=="DELETE") {
300
+            // we cannot delete default domain
301
+            if(@$this->_params->id==1 && $_SERVER['REQUEST_METHOD']=="DELETE")				{ $this->Response->throw_exception(400, "Default domain cannot be deleted"); }
302
+            // ID must be numeric
303
+            if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
304
+        }
305
+        // create checks
306
+        elseif ($_SERVER['REQUEST_METHOD']=="POST") {
307
+            // name must be present
308
+            if(@$this->_params->name == "" || !isset($this->_params->name)) 				{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
309
+        }
310
+        // update checks
311
+        elseif ($_SERVER['REQUEST_METHOD']=="PATCH") {
312
+            // ID must be numeric
313
+            if(!is_numeric($this->_params->id))												{ $this->Response->throw_exception(400, "Invalid domain id"); }
314
+            // name must be present
315
+            if(@$this->_params->name == "" && isset($this->_params->name)) 					{ $this->Response->throw_exception(400, "Domain name is mandatory"); }
316
+        }
317 317
 
318
-	}
318
+    }
319 319
 }
320 320
 
321 321
 ?>
322 322
\ No newline at end of file
Please login to merge, or discard this patch.
api/controllers/Vlans.php 3 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		# execute update
164 164
 		if(!$this->Admin->object_modify ("vrf", "add", "vrfId", $values))
165 165
 													{ $this->Response->throw_exception(500, "VRF creation failed"); }
166
-		else {
166
+													else {
167 167
 			//set result
168 168
 			return array("code"=>201, "data"=>"VRF created", "location"=>"/api/".$this->_params->app_id."/vrfs/".$this->Admin->lastId."/");
169 169
 		}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		# execute update
196 196
 		if(!$this->Admin->object_modify ("vrf", "edit", "vrfId", $values))
197 197
 													{ $this->Response->throw_exception(500, "Vrf edit failed"); }
198
-		else {
198
+													else {
199 199
 			//set result
200 200
 			return array("code"=>200, "data"=>"VRF updated");
201 201
 		}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		# execute delete
223 223
 		if(!$this->Admin->object_modify ("vrf", "delete", "vrfId", $values))
224 224
 													{ $this->Response->throw_exception(500, "Vrf delete failed"); }
225
-		else {
225
+													else {
226 226
 			// delete all references
227 227
 			$this->Admin->remove_object_references ("subnets", "vrfId", $this->_params->id);
228 228
 
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 	 * @param mixed $params		// post/get values
76 76
 	 * @param class $Response
77 77
 	 */
78
-	public function __construct($Database, $Tools, $params, $Response) {
78
+	public function __construct ($Database, $Tools, $params, $Response) {
79 79
 		$this->Database = $Database;
80
-		$this->Tools 	= $Tools;
80
+		$this->Tools = $Tools;
81 81
 		$this->_params 	= $params;
82 82
 		$this->Response = $Response;
83 83
 		// init required objects
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 		$this->validate_options_request ();
104 104
 
105 105
 		// methods
106
-		$result['methods'] = array(
107
-								array("href"=>"/api/".$this->_params->app_id."/vlans/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
108
-								array("href"=>"/api/".$this->_params->app_id."/vlans/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
109
-																												 array("rel"=>"create", "method"=>"POST"),
110
-																												 array("rel"=>"update", "method"=>"PATCH"),
111
-																												 array("rel"=>"delete", "method"=>"DELETE"))),
106
+		$result['methods'] = array (
107
+								array ("href"=>"/api/".$this->_params->app_id."/vlans/", "methods"=>array (array ("rel"=>"options", "method"=>"OPTIONS"))),
108
+								array ("href"=>"/api/".$this->_params->app_id."/vlans/{id}/", "methods"=>array (array ("rel"=>"read", "method"=>"GET"),
109
+																												 array ("rel"=>"create", "method"=>"POST"),
110
+																												 array ("rel"=>"update", "method"=>"PATCH"),
111
+																												 array ("rel"=>"delete", "method"=>"DELETE"))),
112 112
 							);
113 113
 		# result
114
-		return array("code"=>200, "data"=>$result);
114
+		return array ("code"=>200, "data"=>$result);
115 115
 	}
116 116
 
117 117
 
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function GET () {
135 135
 		// check weather to read belonging subnets
136
-		if(@$this->_params->id2=="subnets") {
136
+		if (@$this->_params->id2 == "subnets") {
137 137
 			// first validate
138 138
 			$this->validate_vlan ();
139 139
 			// save result
140 140
 			$result = $this->Tools->fetch_multiple_objects ("subnets", "vlanId", $this->_params->id, 'id', true);
141 141
 
142 142
 			// only 1 section ?
143
-			if(isset($this->_params->id3)) {
144
-				if($result!=NULL) {
143
+			if (isset($this->_params->id3)) {
144
+				if ($result != NULL) {
145 145
 					foreach ($result as $k=>$r) {
146
-						if($r->sectionId!=$this->_params->id3) {
146
+						if ($r->sectionId != $this->_params->id3) {
147 147
 							unset($result[$k]);
148 148
 						}
149 149
 					}
@@ -151,38 +151,38 @@  discard block
 block discarded – undo
151 151
 			}
152 152
 
153 153
 			// add gateway
154
-			if($result!=NULL) {
154
+			if ($result != NULL) {
155 155
 				foreach ($result as $k=>$r) {
156 156
             		$gateway = $this->read_subnet_gateway ($r->id);
157
-            		if ( $gateway!== false) {
157
+            		if ($gateway !== false) {
158 158
                 		$result[$k]->gatewayId = $gateway->id;
159 159
             		}
160 160
 				}
161 161
 			}
162 162
 
163 163
 			// check result
164
-			if($result==NULL)						{ $this->Response->throw_exception(404, "No subnets found"); }
165
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); }
164
+			if ($result == NULL) { $this->Response->throw_exception (404, "No subnets found"); }
165
+			else { return array ("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); }
166 166
 		}
167 167
 		// custom fields
168
-		elseif (@$this->_params->id=="custom_fields") {
168
+		elseif (@$this->_params->id == "custom_fields") {
169 169
 			// check result
170
-			if(sizeof($this->custom_fields)==0)		{ $this->Response->throw_exception(404, 'No custom fields defined'); }
171
-			else									{ return array("code"=>200, "data"=>$this->custom_fields); }
170
+			if (sizeof ($this->custom_fields) == 0) { $this->Response->throw_exception (404, 'No custom fields defined'); }
171
+			else { return array ("code"=>200, "data"=>$this->custom_fields); }
172 172
 		}
173 173
 		// search
174
-		elseif (@$this->_params->id=="search") {
174
+		elseif (@$this->_params->id == "search") {
175 175
 			$result = $this->Tools->fetch_multiple_objects ("vlans", "number", $this->_params->id2, "vlanId");
176 176
 			// check result
177
-			if($result==NULL)						{ $this->Response->throw_exception(404, "Vlans not found"); }
178
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
177
+			if ($result == NULL) { $this->Response->throw_exception (404, "Vlans not found"); }
178
+			else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
179 179
 		}
180 180
 		// read vlan details
181 181
 		else {
182 182
 			$result = $this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id);
183 183
 			// check result
184
-			if($result==NULL)						{ $this->Response->throw_exception(404, "Vlan not found"); }
185
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
184
+			if ($result == NULL) { $this->Response->throw_exception (404, "Vlan not found"); }
185
+			else { return array ("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
186 186
 		}
187 187
 	}
188 188
 
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
 		$this->validate_vlan_edit ();
221 221
 
222 222
 		# execute update
223
-		if(!$this->Admin->object_modify ("vlans", "add", "vlanId", $values))
224
-													{ $this->Response->throw_exception(500, "Vlan creation failed"); }
223
+		if (!$this->Admin->object_modify ("vlans", "add", "vlanId", $values))
224
+													{ $this->Response->throw_exception (500, "Vlan creation failed"); }
225 225
 		else {
226 226
 			//set result
227
-			return array("code"=>201, "data"=>"Vlan created", "location"=>"/api/".$this->_params->app_id."/vlans/".$this->Admin->lastId."/");
227
+			return array ("code"=>201, "data"=>"Vlan created", "location"=>"/api/".$this->_params->app_id."/vlans/".$this->Admin->lastId."/");
228 228
 		}
229 229
 	}
230 230
 
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 		$values = $this->validate_keys ();
253 253
 
254 254
 		# execute update
255
-		if(!$this->Admin->object_modify ("vlans", "edit", "vlanId", $values))
256
-													{ $this->Response->throw_exception(500, "Vlan edit failed"); }
255
+		if (!$this->Admin->object_modify ("vlans", "edit", "vlanId", $values))
256
+													{ $this->Response->throw_exception (500, "Vlan edit failed"); }
257 257
 		else {
258 258
 			//set result
259
-			return array("code"=>200, "data"=>"Vlan updated");
259
+			return array ("code"=>200, "data"=>"Vlan updated");
260 260
 		}
261 261
 	}
262 262
 
@@ -277,18 +277,18 @@  discard block
 block discarded – undo
277 277
 		$this->validate_vlan ();
278 278
 
279 279
 		# set variables for update
280
-		$values = array();
280
+		$values = array ();
281 281
 		$values["vlanId"] = $this->_params->id;
282 282
 
283 283
 		# execute delete
284
-		if(!$this->Admin->object_modify ("vlans", "delete", "vlanId", $values))
285
-													{ $this->Response->throw_exception(500, "Vlan delete failed"); }
284
+		if (!$this->Admin->object_modify ("vlans", "delete", "vlanId", $values))
285
+													{ $this->Response->throw_exception (500, "Vlan delete failed"); }
286 286
 		else {
287 287
 			// delete all references
288 288
 			$this->Admin->remove_object_references ("subnets", "vlanId", $this->_params->id);
289 289
 
290 290
 			// set result
291
-			return array("code"=>200, "data"=>"Vlan deleted");
291
+			return array ("code"=>200, "data"=>"Vlan deleted");
292 292
 		}
293 293
 	}
294 294
 
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	private function validate_vlan () {
313 313
 		// validate id
314
-		if(!isset($this->_params->id))														{ $this->Response->throw_exception(400, "Vlan Id is required");  }
314
+		if (!isset($this->_params->id)) { $this->Response->throw_exception (400, "Vlan Id is required"); }
315 315
 		// validate number
316
-		if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Vlan Id must be numeric"); }
316
+		if (!is_numeric ($this->_params->id)) { $this->Response->throw_exception (400, "Vlan Id must be numeric"); }
317 317
 		// check that it exists
318
-		if($this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id) === false )	{ $this->Response->throw_exception(400, "Invalid Vlan id"); }
318
+		if ($this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id) === false) { $this->Response->throw_exception (400, "Invalid Vlan id"); }
319 319
 	}
320 320
 
321 321
 
@@ -330,25 +330,25 @@  discard block
 block discarded – undo
330 330
 		$this->settings = $this->Admin->fetch_object ("settings", "id", 1);
331 331
 
332 332
 		//if it already exist die
333
-		if($this->settings->vlanDuplicate==0 && $_SERVER['REQUEST_METHOD']=="POST") {
333
+		if ($this->settings->vlanDuplicate == 0 && $_SERVER['REQUEST_METHOD'] == "POST") {
334 334
 			$check_vlan = $this->Admin->fetch_multiple_objects ("vlans", "domainId", $this->_params->domainId, "vlanId");
335
-			if($check_vlan!==false) {
336
-				foreach($check_vlan as $v) {
337
-					if($v->number == $this->_params->number) {
338
-																							{ $this->Response->throw_exception(400, "Vlan already exists"); }
335
+			if ($check_vlan !== false) {
336
+				foreach ($check_vlan as $v) {
337
+					if ($v->number == $this->_params->number) {
338
+																							{ $this->Response->throw_exception (400, "Vlan already exists"); }
339 339
 					}
340 340
 				}
341 341
 			}
342 342
 		}
343 343
 
344 344
 		//if number too high
345
-		if($this->_params->number>$this->settings->vlanMax && $_SERVER['REQUEST_METHOD']!="DELETE")
346
-																							{ $this->Response->throw_exception(400, 'Highest possible VLAN number is '.$this->settings->vlanMax.'!'); }
347
-		if($_SERVER['REQUEST_METHOD']=="POST") {
348
-			if($this->_params->number<0)													{ $this->Response->throw_exception(400, "Vlan number cannot be negative"); }
349
-			elseif(!is_numeric($this->_params->number))										{ $this->Response->throw_exception(400, "Vlan number must be number"); }
345
+		if ($this->_params->number > $this->settings->vlanMax && $_SERVER['REQUEST_METHOD'] != "DELETE")
346
+																							{ $this->Response->throw_exception (400, 'Highest possible VLAN number is '.$this->settings->vlanMax.'!'); }
347
+		if ($_SERVER['REQUEST_METHOD'] == "POST") {
348
+			if ($this->_params->number < 0) { $this->Response->throw_exception (400, "Vlan number cannot be negative"); }
349
+			elseif (!is_numeric ($this->_params->number)) { $this->Response->throw_exception (400, "Vlan number must be number"); }
350 350
 		}
351
-		if(strlen($this->_params->name)==0)													{ $this->Response->throw_exception(400, "Vlan name is required"); }
351
+		if (strlen ($this->_params->name) == 0) { $this->Response->throw_exception (400, "Vlan name is required"); }
352 352
 	}
353 353
 
354 354
 	/**
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	private function validate_domain () {
361 361
 		// validate id
362
-		if(!isset($this->_params->domainId))												{ $this->_params->domainId = 1; }
362
+		if (!isset($this->_params->domainId)) { $this->_params->domainId = 1; }
363 363
 		// validate number
364
-		if(!is_numeric($this->_params->domainId))											{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
364
+		if (!is_numeric ($this->_params->domainId)) { $this->Response->throw_exception (400, "Domain id must be numeric"); }
365 365
 		// check that it exists
366
-		if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->domainId) === false )
367
-																							{ $this->Response->throw_exception(400, "Invalid domain id"); }
366
+		if ($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->domainId) === false)
367
+																							{ $this->Response->throw_exception (400, "Invalid domain id"); }
368 368
 	}
369 369
 
370 370
 	/**
Please login to merge, or discard this patch.
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -9,374 +9,374 @@
 block discarded – undo
9 9
 class Vlans_controller extends Common_api_functions {
10 10
 
11 11
 
12
-	/**
13
-	 * _params provided
14
-	 *
15
-	 * @var mixed
16
-	 * @access public
17
-	 */
18
-	public $_params;
19
-
20
-	/**
21
-	 * custom_fields
22
-	 *
23
-	 * @var mixed
24
-	 * @access protected
25
-	 */
26
-	public $custom_fields;
27
-
28
-	/**
29
-	 * settings
30
-	 *
31
-	 * @var mixed
32
-	 * @access protected
33
-	 */
34
-	protected $settings;
35
-
36
-	/**
37
-	 * Database object
38
-	 *
39
-	 * @var mixed
40
-	 * @access protected
41
-	 */
42
-	protected $Database;
43
-
44
-	/**
45
-	 * Master Sections object
46
-	 *
47
-	 * @var mixed
48
-	 * @access protected
49
-	 */
50
-	protected $Sections;
51
-
52
-	/**
53
-	 * Master Tools object
54
-	 *
55
-	 * @var mixed
56
-	 * @access protected
57
-	 */
58
-	protected $Tools;
59
-
60
-	/**
61
-	 * Master Admin object
62
-	 *
63
-	 * @var mixed
64
-	 * @access protected
65
-	 */
66
-	protected $Admin;
67
-
68
-
69
-	/**
70
-	 * __construct function
71
-	 *
72
-	 * @access public
73
-	 * @param class $Database
74
-	 * @param class $Tools
75
-	 * @param mixed $params		// post/get values
76
-	 * @param class $Response
77
-	 */
78
-	public function __construct($Database, $Tools, $params, $Response) {
79
-		$this->Database = $Database;
80
-		$this->Tools 	= $Tools;
81
-		$this->_params 	= $params;
82
-		$this->Response = $Response;
83
-		// init required objects
84
-		$this->init_object ("Admin", $Database);
85
-		$this->init_object ("Subnets", $Database);
86
-		// set valid keys
87
-		$this->set_valid_keys ("vlans");
88
-	}
89
-
90
-
91
-
92
-
93
-
94
-
95
-	/**
96
-	 * Returns json encoded options
97
-	 *
98
-	 * @access public
99
-	 * @return void
100
-	 */
101
-	public function OPTIONS () {
102
-		// validate
103
-		$this->validate_options_request ();
104
-
105
-		// methods
106
-		$result['methods'] = array(
107
-								array("href"=>"/api/".$this->_params->app_id."/vlans/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
108
-								array("href"=>"/api/".$this->_params->app_id."/vlans/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
109
-																												 array("rel"=>"create", "method"=>"POST"),
110
-																												 array("rel"=>"update", "method"=>"PATCH"),
111
-																												 array("rel"=>"delete", "method"=>"DELETE"))),
112
-							);
113
-		# result
114
-		return array("code"=>200, "data"=>$result);
115
-	}
116
-
117
-
118
-
119
-
120
-
121
-	/**
122
-	 * Read vlan/domain functions
123
-	 *
124
-	 * parameters:
125
-	 *		- {id}
126
-	 *		- {id}/subnets/				returns subnets belonging to this VLAN
127
-	 *		- {id}/subnets/{sectionId}/	returns subnets belonging to this VLAN inside one section
128
-	 *		- custom_fields				returns custom fields
129
-	 *		- search/{number}/			returns all vlans with specified number
130
-	 *
131
-	 * @access public
132
-	 * @return void
133
-	 */
134
-	public function GET () {
135
-		// check weather to read belonging subnets
136
-		if(@$this->_params->id2=="subnets") {
137
-			// first validate
138
-			$this->validate_vlan ();
139
-			// save result
140
-			$result = $this->Tools->fetch_multiple_objects ("subnets", "vlanId", $this->_params->id, 'id', true);
141
-
142
-			// only 1 section ?
143
-			if(isset($this->_params->id3)) {
144
-				if($result!=NULL) {
145
-					foreach ($result as $k=>$r) {
146
-						if($r->sectionId!=$this->_params->id3) {
147
-							unset($result[$k]);
148
-						}
149
-					}
150
-				}
151
-			}
152
-
153
-			// add gateway
154
-			if($result!=NULL) {
155
-				foreach ($result as $k=>$r) {
156
-            		$gateway = $this->read_subnet_gateway ($r->id);
157
-            		if ( $gateway!== false) {
158
-                		$result[$k]->gatewayId = $gateway->id;
159
-            		}
160
-				}
161
-			}
162
-
163
-			// check result
164
-			if($result==NULL)						{ $this->Response->throw_exception(404, "No subnets found"); }
165
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); }
166
-		}
167
-		// custom fields
168
-		elseif (@$this->_params->id=="custom_fields") {
169
-			// check result
170
-			if(sizeof($this->custom_fields)==0)		{ $this->Response->throw_exception(404, 'No custom fields defined'); }
171
-			else									{ return array("code"=>200, "data"=>$this->custom_fields); }
172
-		}
173
-		// search
174
-		elseif (@$this->_params->id=="search") {
175
-			$result = $this->Tools->fetch_multiple_objects ("vlans", "number", $this->_params->id2, "vlanId");
176
-			// check result
177
-			if($result==NULL)						{ $this->Response->throw_exception(404, "Vlans not found"); }
178
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
179
-		}
180
-		// read vlan details
181
-		else {
182
-			$result = $this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id);
183
-			// check result
184
-			if($result==NULL)						{ $this->Response->throw_exception(404, "Vlan not found"); }
185
-			else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
186
-		}
187
-	}
188
-
189
-
190
-
191
-
192
-	/**
193
-	 * HEAD, no response
194
-	 *
195
-	 * @access public
196
-	 * @return void
197
-	 */
198
-	public function HEAD () {
199
-		return $this->GET ();
200
-	}
201
-
202
-
203
-
204
-
205
-
206
-	/**
207
-	 * Creates new vlan
208
-	 *
209
-	 * @access public
210
-	 * @return void
211
-	 */
212
-	public function POST () {
213
-		# check for valid keys
214
-		$values = $this->validate_keys ();
215
-
216
-		# verify or set domain
217
-		$this->validate_domain ($this->_params->domainId);
218
-
219
-		# validate input
220
-		$this->validate_vlan_edit ();
221
-
222
-		# execute update
223
-		if(!$this->Admin->object_modify ("vlans", "add", "vlanId", $values))
224
-													{ $this->Response->throw_exception(500, "Vlan creation failed"); }
225
-		else {
226
-			//set result
227
-			return array("code"=>201, "data"=>"Vlan created", "location"=>"/api/".$this->_params->app_id."/vlans/".$this->Admin->lastId."/");
228
-		}
229
-	}
230
-
231
-
232
-
233
-
234
-
235
-	/**
236
-	 * Updates existing vlan/domain
237
-	 *
238
-	 * @access public
239
-	 * @return void
240
-	 */
241
-	public function PATCH () {
242
-		# verify
243
-		$this->validate_vlan_edit ();
244
-		# check that it exists
245
-		$this->validate_vlan ();
246
-
247
-		# rewrite id
248
-		$this->_params->vlanId = $this->_params->id;
249
-		unset($this->_params->id);
250
-
251
-		# validate and prepare keys
252
-		$values = $this->validate_keys ();
253
-
254
-		# execute update
255
-		if(!$this->Admin->object_modify ("vlans", "edit", "vlanId", $values))
256
-													{ $this->Response->throw_exception(500, "Vlan edit failed"); }
257
-		else {
258
-			//set result
259
-			return array("code"=>200, "data"=>"Vlan updated");
260
-		}
261
-	}
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-	/**
270
-	 * Deletes existing vlan
271
-	 *
272
-	 * @access public
273
-	 * @return void
274
-	 */
275
-	public function DELETE () {
276
-		# verify
277
-		$this->validate_vlan ();
278
-
279
-		# set variables for update
280
-		$values = array();
281
-		$values["vlanId"] = $this->_params->id;
282
-
283
-		# execute delete
284
-		if(!$this->Admin->object_modify ("vlans", "delete", "vlanId", $values))
285
-													{ $this->Response->throw_exception(500, "Vlan delete failed"); }
286
-		else {
287
-			// delete all references
288
-			$this->Admin->remove_object_references ("subnets", "vlanId", $this->_params->id);
289
-
290
-			// set result
291
-			return array("code"=>200, "data"=>"Vlan deleted");
292
-		}
293
-	}
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-	/* @validations ---------- */
304
-
305
-
306
-	/**
307
-	 * Validates Vlan - checks if it exists
308
-	 *
309
-	 * @access private
310
-	 * @return void
311
-	 */
312
-	private function validate_vlan () {
313
-		// validate id
314
-		if(!isset($this->_params->id))														{ $this->Response->throw_exception(400, "Vlan Id is required");  }
315
-		// validate number
316
-		if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Vlan Id must be numeric"); }
317
-		// check that it exists
318
-		if($this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id) === false )	{ $this->Response->throw_exception(400, "Invalid Vlan id"); }
319
-	}
320
-
321
-
322
-	/**
323
-	 * Validates VLAN on add and edit
324
-	 *
325
-	 * @access private
326
-	 * @return void
327
-	 */
328
-	private function validate_vlan_edit () {
329
-		# get settings
330
-		$this->settings = $this->Admin->fetch_object ("settings", "id", 1);
331
-
332
-		//if it already exist die
333
-		if($this->settings->vlanDuplicate==0 && $_SERVER['REQUEST_METHOD']=="POST") {
334
-			$check_vlan = $this->Admin->fetch_multiple_objects ("vlans", "domainId", $this->_params->domainId, "vlanId");
335
-			if($check_vlan!==false) {
336
-				foreach($check_vlan as $v) {
337
-					if($v->number == $this->_params->number) {
338
-																							{ $this->Response->throw_exception(400, "Vlan already exists"); }
339
-					}
340
-				}
341
-			}
342
-		}
343
-
344
-		//if number too high
345
-		if($this->_params->number>$this->settings->vlanMax && $_SERVER['REQUEST_METHOD']!="DELETE")
346
-																							{ $this->Response->throw_exception(400, 'Highest possible VLAN number is '.$this->settings->vlanMax.'!'); }
347
-		if($_SERVER['REQUEST_METHOD']=="POST") {
348
-			if($this->_params->number<0)													{ $this->Response->throw_exception(400, "Vlan number cannot be negative"); }
349
-			elseif(!is_numeric($this->_params->number))										{ $this->Response->throw_exception(400, "Vlan number must be number"); }
350
-		}
351
-		if(strlen($this->_params->name)==0)													{ $this->Response->throw_exception(400, "Vlan name is required"); }
352
-	}
353
-
354
-	/**
355
-	 * Validates domains
356
-	 *
357
-	 * @access private
358
-	 * @return void
359
-	 */
360
-	private function validate_domain () {
361
-		// validate id
362
-		if(!isset($this->_params->domainId))												{ $this->_params->domainId = 1; }
363
-		// validate number
364
-		if(!is_numeric($this->_params->domainId))											{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
365
-		// check that it exists
366
-		if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->domainId) === false )
367
-																							{ $this->Response->throw_exception(400, "Invalid domain id"); }
368
-	}
369
-
370
-	/**
371
-	 * Returns id of subnet gateay
372
-	 *
373
-	 * @access private
374
-	 * @params mixed $subnetId
375
-	 * @return void
376
-	 */
377
-	private function read_subnet_gateway ($subnetId) {
378
-    	return $this->Subnets->find_gateway ($subnetId);
379
-	}
12
+    /**
13
+     * _params provided
14
+     *
15
+     * @var mixed
16
+     * @access public
17
+     */
18
+    public $_params;
19
+
20
+    /**
21
+     * custom_fields
22
+     *
23
+     * @var mixed
24
+     * @access protected
25
+     */
26
+    public $custom_fields;
27
+
28
+    /**
29
+     * settings
30
+     *
31
+     * @var mixed
32
+     * @access protected
33
+     */
34
+    protected $settings;
35
+
36
+    /**
37
+     * Database object
38
+     *
39
+     * @var mixed
40
+     * @access protected
41
+     */
42
+    protected $Database;
43
+
44
+    /**
45
+     * Master Sections object
46
+     *
47
+     * @var mixed
48
+     * @access protected
49
+     */
50
+    protected $Sections;
51
+
52
+    /**
53
+     * Master Tools object
54
+     *
55
+     * @var mixed
56
+     * @access protected
57
+     */
58
+    protected $Tools;
59
+
60
+    /**
61
+     * Master Admin object
62
+     *
63
+     * @var mixed
64
+     * @access protected
65
+     */
66
+    protected $Admin;
67
+
68
+
69
+    /**
70
+     * __construct function
71
+     *
72
+     * @access public
73
+     * @param class $Database
74
+     * @param class $Tools
75
+     * @param mixed $params		// post/get values
76
+     * @param class $Response
77
+     */
78
+    public function __construct($Database, $Tools, $params, $Response) {
79
+        $this->Database = $Database;
80
+        $this->Tools 	= $Tools;
81
+        $this->_params 	= $params;
82
+        $this->Response = $Response;
83
+        // init required objects
84
+        $this->init_object ("Admin", $Database);
85
+        $this->init_object ("Subnets", $Database);
86
+        // set valid keys
87
+        $this->set_valid_keys ("vlans");
88
+    }
89
+
90
+
91
+
92
+
93
+
94
+
95
+    /**
96
+     * Returns json encoded options
97
+     *
98
+     * @access public
99
+     * @return void
100
+     */
101
+    public function OPTIONS () {
102
+        // validate
103
+        $this->validate_options_request ();
104
+
105
+        // methods
106
+        $result['methods'] = array(
107
+                                array("href"=>"/api/".$this->_params->app_id."/vlans/", 		"methods"=>array(array("rel"=>"options", "method"=>"OPTIONS"))),
108
+                                array("href"=>"/api/".$this->_params->app_id."/vlans/{id}/", 	"methods"=>array(array("rel"=>"read", 	"method"=>"GET"),
109
+                                                                                                                    array("rel"=>"create", "method"=>"POST"),
110
+                                                                                                                    array("rel"=>"update", "method"=>"PATCH"),
111
+                                                                                                                    array("rel"=>"delete", "method"=>"DELETE"))),
112
+                            );
113
+        # result
114
+        return array("code"=>200, "data"=>$result);
115
+    }
116
+
117
+
118
+
119
+
120
+
121
+    /**
122
+     * Read vlan/domain functions
123
+     *
124
+     * parameters:
125
+     *		- {id}
126
+     *		- {id}/subnets/				returns subnets belonging to this VLAN
127
+     *		- {id}/subnets/{sectionId}/	returns subnets belonging to this VLAN inside one section
128
+     *		- custom_fields				returns custom fields
129
+     *		- search/{number}/			returns all vlans with specified number
130
+     *
131
+     * @access public
132
+     * @return void
133
+     */
134
+    public function GET () {
135
+        // check weather to read belonging subnets
136
+        if(@$this->_params->id2=="subnets") {
137
+            // first validate
138
+            $this->validate_vlan ();
139
+            // save result
140
+            $result = $this->Tools->fetch_multiple_objects ("subnets", "vlanId", $this->_params->id, 'id', true);
141
+
142
+            // only 1 section ?
143
+            if(isset($this->_params->id3)) {
144
+                if($result!=NULL) {
145
+                    foreach ($result as $k=>$r) {
146
+                        if($r->sectionId!=$this->_params->id3) {
147
+                            unset($result[$k]);
148
+                        }
149
+                    }
150
+                }
151
+            }
152
+
153
+            // add gateway
154
+            if($result!=NULL) {
155
+                foreach ($result as $k=>$r) {
156
+                    $gateway = $this->read_subnet_gateway ($r->id);
157
+                    if ( $gateway!== false) {
158
+                        $result[$k]->gatewayId = $gateway->id;
159
+                    }
160
+                }
161
+            }
162
+
163
+            // check result
164
+            if($result==NULL)						{ $this->Response->throw_exception(404, "No subnets found"); }
165
+            else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, "subnets", true, true)); }
166
+        }
167
+        // custom fields
168
+        elseif (@$this->_params->id=="custom_fields") {
169
+            // check result
170
+            if(sizeof($this->custom_fields)==0)		{ $this->Response->throw_exception(404, 'No custom fields defined'); }
171
+            else									{ return array("code"=>200, "data"=>$this->custom_fields); }
172
+        }
173
+        // search
174
+        elseif (@$this->_params->id=="search") {
175
+            $result = $this->Tools->fetch_multiple_objects ("vlans", "number", $this->_params->id2, "vlanId");
176
+            // check result
177
+            if($result==NULL)						{ $this->Response->throw_exception(404, "Vlans not found"); }
178
+            else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
179
+        }
180
+        // read vlan details
181
+        else {
182
+            $result = $this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id);
183
+            // check result
184
+            if($result==NULL)						{ $this->Response->throw_exception(404, "Vlan not found"); }
185
+            else									{ return array("code"=>200, "data"=>$this->prepare_result ($result, null, true, true)); }
186
+        }
187
+    }
188
+
189
+
190
+
191
+
192
+    /**
193
+     * HEAD, no response
194
+     *
195
+     * @access public
196
+     * @return void
197
+     */
198
+    public function HEAD () {
199
+        return $this->GET ();
200
+    }
201
+
202
+
203
+
204
+
205
+
206
+    /**
207
+     * Creates new vlan
208
+     *
209
+     * @access public
210
+     * @return void
211
+     */
212
+    public function POST () {
213
+        # check for valid keys
214
+        $values = $this->validate_keys ();
215
+
216
+        # verify or set domain
217
+        $this->validate_domain ($this->_params->domainId);
218
+
219
+        # validate input
220
+        $this->validate_vlan_edit ();
221
+
222
+        # execute update
223
+        if(!$this->Admin->object_modify ("vlans", "add", "vlanId", $values))
224
+                                                    { $this->Response->throw_exception(500, "Vlan creation failed"); }
225
+        else {
226
+            //set result
227
+            return array("code"=>201, "data"=>"Vlan created", "location"=>"/api/".$this->_params->app_id."/vlans/".$this->Admin->lastId."/");
228
+        }
229
+    }
230
+
231
+
232
+
233
+
234
+
235
+    /**
236
+     * Updates existing vlan/domain
237
+     *
238
+     * @access public
239
+     * @return void
240
+     */
241
+    public function PATCH () {
242
+        # verify
243
+        $this->validate_vlan_edit ();
244
+        # check that it exists
245
+        $this->validate_vlan ();
246
+
247
+        # rewrite id
248
+        $this->_params->vlanId = $this->_params->id;
249
+        unset($this->_params->id);
250
+
251
+        # validate and prepare keys
252
+        $values = $this->validate_keys ();
253
+
254
+        # execute update
255
+        if(!$this->Admin->object_modify ("vlans", "edit", "vlanId", $values))
256
+                                                    { $this->Response->throw_exception(500, "Vlan edit failed"); }
257
+        else {
258
+            //set result
259
+            return array("code"=>200, "data"=>"Vlan updated");
260
+        }
261
+    }
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+    /**
270
+     * Deletes existing vlan
271
+     *
272
+     * @access public
273
+     * @return void
274
+     */
275
+    public function DELETE () {
276
+        # verify
277
+        $this->validate_vlan ();
278
+
279
+        # set variables for update
280
+        $values = array();
281
+        $values["vlanId"] = $this->_params->id;
282
+
283
+        # execute delete
284
+        if(!$this->Admin->object_modify ("vlans", "delete", "vlanId", $values))
285
+                                                    { $this->Response->throw_exception(500, "Vlan delete failed"); }
286
+        else {
287
+            // delete all references
288
+            $this->Admin->remove_object_references ("subnets", "vlanId", $this->_params->id);
289
+
290
+            // set result
291
+            return array("code"=>200, "data"=>"Vlan deleted");
292
+        }
293
+    }
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+    /* @validations ---------- */
304
+
305
+
306
+    /**
307
+     * Validates Vlan - checks if it exists
308
+     *
309
+     * @access private
310
+     * @return void
311
+     */
312
+    private function validate_vlan () {
313
+        // validate id
314
+        if(!isset($this->_params->id))														{ $this->Response->throw_exception(400, "Vlan Id is required");  }
315
+        // validate number
316
+        if(!is_numeric($this->_params->id))													{ $this->Response->throw_exception(400, "Vlan Id must be numeric"); }
317
+        // check that it exists
318
+        if($this->Tools->fetch_object ("vlans", "vlanId", $this->_params->id) === false )	{ $this->Response->throw_exception(400, "Invalid Vlan id"); }
319
+    }
320
+
321
+
322
+    /**
323
+     * Validates VLAN on add and edit
324
+     *
325
+     * @access private
326
+     * @return void
327
+     */
328
+    private function validate_vlan_edit () {
329
+        # get settings
330
+        $this->settings = $this->Admin->fetch_object ("settings", "id", 1);
331
+
332
+        //if it already exist die
333
+        if($this->settings->vlanDuplicate==0 && $_SERVER['REQUEST_METHOD']=="POST") {
334
+            $check_vlan = $this->Admin->fetch_multiple_objects ("vlans", "domainId", $this->_params->domainId, "vlanId");
335
+            if($check_vlan!==false) {
336
+                foreach($check_vlan as $v) {
337
+                    if($v->number == $this->_params->number) {
338
+                                                                                            { $this->Response->throw_exception(400, "Vlan already exists"); }
339
+                    }
340
+                }
341
+            }
342
+        }
343
+
344
+        //if number too high
345
+        if($this->_params->number>$this->settings->vlanMax && $_SERVER['REQUEST_METHOD']!="DELETE")
346
+                                                                                            { $this->Response->throw_exception(400, 'Highest possible VLAN number is '.$this->settings->vlanMax.'!'); }
347
+        if($_SERVER['REQUEST_METHOD']=="POST") {
348
+            if($this->_params->number<0)													{ $this->Response->throw_exception(400, "Vlan number cannot be negative"); }
349
+            elseif(!is_numeric($this->_params->number))										{ $this->Response->throw_exception(400, "Vlan number must be number"); }
350
+        }
351
+        if(strlen($this->_params->name)==0)													{ $this->Response->throw_exception(400, "Vlan name is required"); }
352
+    }
353
+
354
+    /**
355
+     * Validates domains
356
+     *
357
+     * @access private
358
+     * @return void
359
+     */
360
+    private function validate_domain () {
361
+        // validate id
362
+        if(!isset($this->_params->domainId))												{ $this->_params->domainId = 1; }
363
+        // validate number
364
+        if(!is_numeric($this->_params->domainId))											{ $this->Response->throw_exception(400, "Domain id must be numeric"); }
365
+        // check that it exists
366
+        if($this->Tools->fetch_object ("vlanDomains", "id", $this->_params->domainId) === false )
367
+                                                                                            { $this->Response->throw_exception(400, "Invalid domain id"); }
368
+    }
369
+
370
+    /**
371
+     * Returns id of subnet gateay
372
+     *
373
+     * @access private
374
+     * @params mixed $subnetId
375
+     * @return void
376
+     */
377
+    private function read_subnet_gateway ($subnetId) {
378
+        return $this->Subnets->find_gateway ($subnetId);
379
+    }
380 380
 }
381 381
 
382 382
 ?>
383 383
\ No newline at end of file
Please login to merge, or discard this patch.