Completed
Pull Request — master (#532)
06:37
created
app/admin/import-export/export-ipaddr.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -27,22 +27,22 @@  discard block
 block discarded – undo
27 27
 
28 28
 # Lets do some reordering to show slaves!
29 29
 if($all_sections !== false) {
30
-	foreach($all_sections as $s) {
31
-		if($s->masterSection=="0") {
32
-			# it is master
33
-			$s->class = "master";
34
-			$sectionssorted[] = $s;
35
-			# check for slaves
36
-			foreach($all_sections as $ss) {
37
-				if($ss->masterSection==$s->id) {
38
-					$ss->class = "slave";
39
-					$sectionssorted[] = $ss;
40
-				}
41
-			}
42
-		}
43
-	}
44
-	# set new array
45
-	$sections_sorted = @$sectionssorted;
30
+    foreach($all_sections as $s) {
31
+        if($s->masterSection=="0") {
32
+            # it is master
33
+            $s->class = "master";
34
+            $sectionssorted[] = $s;
35
+            # check for slaves
36
+            foreach($all_sections as $ss) {
37
+                if($ss->masterSection==$s->id) {
38
+                    $ss->class = "slave";
39
+                    $sectionssorted[] = $ss;
40
+                }
41
+            }
42
+        }
43
+    }
44
+    # set new array
45
+    $sections_sorted = @$sectionssorted;
46 46
 }
47 47
 
48 48
 
@@ -73,81 +73,81 @@  discard block
 block discarded – undo
73 73
 
74 74
 //write headers
75 75
 if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) {
76
-	$worksheet->write($lineCount, $rowCount, _('Section') ,$format_header);
77
-	$rowCount++;
76
+    $worksheet->write($lineCount, $rowCount, _('Section') ,$format_header);
77
+    $rowCount++;
78 78
 }
79 79
 if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) {
80
-	$worksheet->write($lineCount, $rowCount, _('IP Address') ,$format_header);
81
-	$rowCount++;
80
+    $worksheet->write($lineCount, $rowCount, _('IP Address') ,$format_header);
81
+    $rowCount++;
82 82
 }
83 83
 if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) {
84
-	$worksheet->write($lineCount, $rowCount, _('Hostname') ,$format_header);
85
-	$rowCount++;
84
+    $worksheet->write($lineCount, $rowCount, _('Hostname') ,$format_header);
85
+    $rowCount++;
86 86
 }
87 87
 if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
88
-	$worksheet->write($lineCount, $rowCount, _('Description') ,$format_header);
89
-	$rowCount++;
88
+    $worksheet->write($lineCount, $rowCount, _('Description') ,$format_header);
89
+    $rowCount++;
90 90
 }
91 91
 if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) {
92
-	$worksheet->write($lineCount, $rowCount, _('VRF') ,$format_header);
93
-	$rowCount++;
94
-	# fetch all VRFs
95
-	$all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
96
-	if (!$all_vrfs) { $all_vrfs = array(); }
97
-	# prepare list for easy processing
98
-	$vrfs = array(); $vrfs[0] = "default";
99
-	foreach ($all_vrfs as $vrf) { $vrf = (array) $vrf; $vrfs[$vrf['vrfId']] = $vrf['name']; }
92
+    $worksheet->write($lineCount, $rowCount, _('VRF') ,$format_header);
93
+    $rowCount++;
94
+    # fetch all VRFs
95
+    $all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
96
+    if (!$all_vrfs) { $all_vrfs = array(); }
97
+    # prepare list for easy processing
98
+    $vrfs = array(); $vrfs[0] = "default";
99
+    foreach ($all_vrfs as $vrf) { $vrf = (array) $vrf; $vrfs[$vrf['vrfId']] = $vrf['name']; }
100 100
 }
101 101
 if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) {
102
-	$worksheet->write($lineCount, $rowCount, _('Subnet') ,$format_header);
103
-	$rowCount++;
102
+    $worksheet->write($lineCount, $rowCount, _('Subnet') ,$format_header);
103
+    $rowCount++;
104 104
 }
105 105
 if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) {
106
-	$worksheet->write($lineCount, $rowCount, _('MAC') ,$format_header);
107
-	$rowCount++;
106
+    $worksheet->write($lineCount, $rowCount, _('MAC') ,$format_header);
107
+    $rowCount++;
108 108
 }
109 109
 if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) {
110
-	$worksheet->write($lineCount, $rowCount, _('Owner') ,$format_header);
111
-	$rowCount++;
110
+    $worksheet->write($lineCount, $rowCount, _('Owner') ,$format_header);
111
+    $rowCount++;
112 112
 }
113 113
 if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) {
114
-	$worksheet->write($lineCount, $rowCount, _('Device') ,$format_header);
115
-	$rowCount++;
116
-	# get Devices and reorder
117
-	$devices = $Tools->fetch_all_objects ("devices", "hostname");
118
-	$devices_indexed = array();
119
-	if ($devices!==false) {
120
-	foreach($devices as $d) {
121
-    		$devices_indexed[$d->id] = $d;
122
-    	}
123
-	}
114
+    $worksheet->write($lineCount, $rowCount, _('Device') ,$format_header);
115
+    $rowCount++;
116
+    # get Devices and reorder
117
+    $devices = $Tools->fetch_all_objects ("devices", "hostname");
118
+    $devices_indexed = array();
119
+    if ($devices!==false) {
120
+    foreach($devices as $d) {
121
+            $devices_indexed[$d->id] = $d;
122
+        }
123
+    }
124 124
 }
125 125
 if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) {
126
-	$worksheet->write($lineCount, $rowCount, _('Note') ,$format_header);
127
-	$rowCount++;
126
+    $worksheet->write($lineCount, $rowCount, _('Note') ,$format_header);
127
+    $rowCount++;
128 128
 }
129 129
 if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) {
130
-	$worksheet->write($lineCount, $rowCount, _('Tag') ,$format_header);
131
-	$rowCount++;
132
-	# get IP address types
133
-	$ip_types = $Addresses->addresses_types_fetch();
130
+    $worksheet->write($lineCount, $rowCount, _('Tag') ,$format_header);
131
+    $rowCount++;
132
+    # get IP address types
133
+    $ip_types = $Addresses->addresses_types_fetch();
134 134
 }
135 135
 if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) {
136
-	$worksheet->write($lineCount, $rowCount, _('Gateway') ,$format_header);
137
-	$rowCount++;
136
+    $worksheet->write($lineCount, $rowCount, _('Gateway') ,$format_header);
137
+    $rowCount++;
138 138
 }
139 139
 
140 140
 //custom fields
141 141
 if(sizeof($custom_fields) > 0) {
142
-	foreach($custom_fields as $myField) {
143
-		//set temp name - replace space with three ___
144
-		$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
145
-
146
-		if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
147
-			$worksheet->write($lineCount, $rowCount, $myField['name'] ,$format_header);
148
-			$rowCount++;
149
-		}
150
-	}
142
+    foreach($custom_fields as $myField) {
143
+        //set temp name - replace space with three ___
144
+        $myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
145
+
146
+        if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
147
+            $worksheet->write($lineCount, $rowCount, $myField['name'] ,$format_header);
148
+            $rowCount++;
149
+        }
150
+    }
151 151
 }
152 152
 
153 153
 $rowCount = 0;
@@ -155,171 +155,171 @@  discard block
 block discarded – undo
155 155
 
156 156
 //write Subnet entries for the selected sections
157 157
 if($all_sections!==false) {
158
-	foreach ($all_sections as $section) {
159
-		//cast
160
-		$section = (array) $section;
161
-
162
-		if( (isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on") ) {
163
-			// get all subnets in section
164
-			$section_subnets = $Subnets->fetch_section_subnets($section['id']);
165
-
166
-			if (sizeof($section_subnets)==0) { continue; }
167
-
168
-			foreach ($section_subnets as $subnet) {
169
-
170
-				$subnet = (array) $subnet;
171
-
172
-				// ignore folders
173
-				if($subnet['isFolder']) { continue; }
174
-
175
-				// grab IP addresses
176
-				$ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
177
-
178
-				if (sizeof($ipaddresses)==0) { continue; }
179
-
180
-				foreach ($ipaddresses as $ip) {
181
-
182
-					//cast
183
-					$ip = (array) $ip;
184
-
185
-
186
-					if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) {
187
-						$worksheet->write($lineCount, $rowCount, $section['name'], $format_text);
188
-						$rowCount++;
189
-					}
190
-
191
-					if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) {
192
-						$worksheet->write($lineCount, $rowCount, $Subnets->transform_to_dotted($ip['ip_addr']), $format_text);
193
-						$rowCount++;
194
-					}
195
-
196
-					if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) {
197
-						$worksheet->write($lineCount, $rowCount, $ip['dns_name'], $format_text);
198
-						$rowCount++;
199
-					}
200
-
201
-					if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
202
-						$worksheet->write($lineCount, $rowCount, $ip['description'], $format_text);
203
-						$rowCount++;
204
-					}
205
-
206
-					if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) {
207
-						$worksheet->write($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text);
208
-						$rowCount++;
209
-					}
210
-
211
-					if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) {
212
-						$worksheet->write($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text);
213
-						$rowCount++;
214
-					}
215
-
216
-					if( (isset($_GET['state'])) && ($_GET['state'] == "on") ) {
217
-						$worksheet->write($lineCount, $rowCount, $ip['state'], $format_text);
218
-						$rowCount++;
219
-					}
220
-
221
-					if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) {
222
-						$worksheet->write($lineCount, $rowCount, $ip['mac'], $format_text);
223
-						$rowCount++;
224
-					}
225
-
226
-					if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) {
227
-						$worksheet->write($lineCount, $rowCount, $ip['owner'], $format_text);
228
-						$rowCount++;
229
-					}
230
-
231
-					if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) {
232
-						//change device to name
233
-						$ip['device'] = is_null($ip['switch'])||strlen($ip['switch'])==0||$ip['switch']==0 ? "" : $devices_indexed[$ip['switch']]->hostname;
234
-						$worksheet->write($lineCount, $rowCount, $ip['device'], $format_text);
235
-						$rowCount++;
236
-					}
237
-
238
-					if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) {
239
-						$worksheet->write($lineCount, $rowCount, $ip['note'], $format_text);
240
-						$rowCount++;
241
-					}
242
-
243
-					if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) {
244
-						//reformat tag
245
-						$ip['tag'] = (@$ip_types[$ip['state']]['showtag']) ? $ip_types[$ip['state']]['type'] : "";
246
-						$worksheet->write($lineCount, $rowCount, $ip['tag'], $format_text);
247
-						$rowCount++;
248
-					}
249
-
250
-					if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) {
251
-						$ip['gateway'] = ($ip['is_gateway']) ? _("Yes") : _("No");
252
-						$worksheet->write($lineCount, $rowCount, $ip['gateway'], $format_text);
253
-						$rowCount++;
254
-					}
255
-
256
-					//custom fields, per subnet
257
-					if(sizeof($custom_fields) > 0) {
258
-						foreach($custom_fields as $myField) {
259
-							//set temp name - replace space with three ___
260
-							$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
261
-
262
-							if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
263
-								$worksheet->write($lineCount, $rowCount, $ip[$myField['name']], $format_text);
264
-								$rowCount++;
265
-							}
266
-						}
267
-					}
268
-
269
-				//reset row count
270
-				$rowCount = 0;
271
-				$lineCount++;
272
-				}
273
-			}
274
-		}
275
-	}
158
+    foreach ($all_sections as $section) {
159
+        //cast
160
+        $section = (array) $section;
161
+
162
+        if( (isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on") ) {
163
+            // get all subnets in section
164
+            $section_subnets = $Subnets->fetch_section_subnets($section['id']);
165
+
166
+            if (sizeof($section_subnets)==0) { continue; }
167
+
168
+            foreach ($section_subnets as $subnet) {
169
+
170
+                $subnet = (array) $subnet;
171
+
172
+                // ignore folders
173
+                if($subnet['isFolder']) { continue; }
174
+
175
+                // grab IP addresses
176
+                $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
177
+
178
+                if (sizeof($ipaddresses)==0) { continue; }
179
+
180
+                foreach ($ipaddresses as $ip) {
181
+
182
+                    //cast
183
+                    $ip = (array) $ip;
184
+
185
+
186
+                    if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) {
187
+                        $worksheet->write($lineCount, $rowCount, $section['name'], $format_text);
188
+                        $rowCount++;
189
+                    }
190
+
191
+                    if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) {
192
+                        $worksheet->write($lineCount, $rowCount, $Subnets->transform_to_dotted($ip['ip_addr']), $format_text);
193
+                        $rowCount++;
194
+                    }
195
+
196
+                    if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) {
197
+                        $worksheet->write($lineCount, $rowCount, $ip['dns_name'], $format_text);
198
+                        $rowCount++;
199
+                    }
200
+
201
+                    if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
202
+                        $worksheet->write($lineCount, $rowCount, $ip['description'], $format_text);
203
+                        $rowCount++;
204
+                    }
205
+
206
+                    if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) {
207
+                        $worksheet->write($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text);
208
+                        $rowCount++;
209
+                    }
210
+
211
+                    if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) {
212
+                        $worksheet->write($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text);
213
+                        $rowCount++;
214
+                    }
215
+
216
+                    if( (isset($_GET['state'])) && ($_GET['state'] == "on") ) {
217
+                        $worksheet->write($lineCount, $rowCount, $ip['state'], $format_text);
218
+                        $rowCount++;
219
+                    }
220
+
221
+                    if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) {
222
+                        $worksheet->write($lineCount, $rowCount, $ip['mac'], $format_text);
223
+                        $rowCount++;
224
+                    }
225
+
226
+                    if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) {
227
+                        $worksheet->write($lineCount, $rowCount, $ip['owner'], $format_text);
228
+                        $rowCount++;
229
+                    }
230
+
231
+                    if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) {
232
+                        //change device to name
233
+                        $ip['device'] = is_null($ip['switch'])||strlen($ip['switch'])==0||$ip['switch']==0 ? "" : $devices_indexed[$ip['switch']]->hostname;
234
+                        $worksheet->write($lineCount, $rowCount, $ip['device'], $format_text);
235
+                        $rowCount++;
236
+                    }
237
+
238
+                    if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) {
239
+                        $worksheet->write($lineCount, $rowCount, $ip['note'], $format_text);
240
+                        $rowCount++;
241
+                    }
242
+
243
+                    if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) {
244
+                        //reformat tag
245
+                        $ip['tag'] = (@$ip_types[$ip['state']]['showtag']) ? $ip_types[$ip['state']]['type'] : "";
246
+                        $worksheet->write($lineCount, $rowCount, $ip['tag'], $format_text);
247
+                        $rowCount++;
248
+                    }
249
+
250
+                    if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) {
251
+                        $ip['gateway'] = ($ip['is_gateway']) ? _("Yes") : _("No");
252
+                        $worksheet->write($lineCount, $rowCount, $ip['gateway'], $format_text);
253
+                        $rowCount++;
254
+                    }
255
+
256
+                    //custom fields, per subnet
257
+                    if(sizeof($custom_fields) > 0) {
258
+                        foreach($custom_fields as $myField) {
259
+                            //set temp name - replace space with three ___
260
+                            $myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
261
+
262
+                            if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
263
+                                $worksheet->write($lineCount, $rowCount, $ip[$myField['name']], $format_text);
264
+                                $rowCount++;
265
+                            }
266
+                        }
267
+                    }
268
+
269
+                //reset row count
270
+                $rowCount = 0;
271
+                $lineCount++;
272
+                }
273
+            }
274
+        }
275
+    }
276 276
 }
277 277
 //new line
278 278
 $lineCount++;
279 279
 
280 280
 //write section sheet
281 281
 if( (isset($_GET['exportSections'])) && ($_GET['exportSections'] == "on") ) {
282
-	// Create a worksheet
283
-	$worksheet_sections =& $workbook->addWorksheet('Sections');
284
-
285
-	$lineCount = 0;
286
-	$rowCount = 0;
287
-
288
-	//write headers
289
-	$worksheet_sections->write($lineCount, $rowCount, _('Name') ,$format_header);
290
-	$rowCount++;
291
-	$worksheet_sections->write($lineCount, $rowCount, _('Description') ,$format_header);
292
-	$rowCount++;
293
-	$worksheet_sections->write($lineCount, $rowCount, _('Parent') ,$format_header);
294
-	$rowCount++;
295
-
296
-	$lineCount++;
297
-	$rowCount = 0;
298
-
299
-	foreach ($sections_sorted as $section) {
300
-		//cast
301
-		$section = (array) $section;
302
-
303
-		if( (isset($_GET['exportSection__'.str_replace(" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace(" ", "_", $section['name'])] == "on") ) {
304
-			$worksheet_sections->write($lineCount, $rowCount, $section['name'], $format_text);
305
-			$rowCount++;
306
-			$worksheet_sections->write($lineCount, $rowCount, $section['description'], $format_text);
307
-			$rowCount++;
308
-			//master Section
309
-			if($section['masterSection']!=0) {
310
-				# get section details
311
-				$ssec = $Admin->fetch_object("sections", "id", $section['masterSection']);
312
-				$worksheet_sections->write($lineCount, $rowCount, $ssec->name, $format_text);
313
-				$rowCount++;
314
-			} else {
315
-				$worksheet_sections->write($lineCount, $rowCount, "/", $format_text);
316
-				$rowCount++;
317
-			}
318
-		}
319
-
320
-		$lineCount++;
321
-		$rowCount = 0;
322
-	}
282
+    // Create a worksheet
283
+    $worksheet_sections =& $workbook->addWorksheet('Sections');
284
+
285
+    $lineCount = 0;
286
+    $rowCount = 0;
287
+
288
+    //write headers
289
+    $worksheet_sections->write($lineCount, $rowCount, _('Name') ,$format_header);
290
+    $rowCount++;
291
+    $worksheet_sections->write($lineCount, $rowCount, _('Description') ,$format_header);
292
+    $rowCount++;
293
+    $worksheet_sections->write($lineCount, $rowCount, _('Parent') ,$format_header);
294
+    $rowCount++;
295
+
296
+    $lineCount++;
297
+    $rowCount = 0;
298
+
299
+    foreach ($sections_sorted as $section) {
300
+        //cast
301
+        $section = (array) $section;
302
+
303
+        if( (isset($_GET['exportSection__'.str_replace(" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace(" ", "_", $section['name'])] == "on") ) {
304
+            $worksheet_sections->write($lineCount, $rowCount, $section['name'], $format_text);
305
+            $rowCount++;
306
+            $worksheet_sections->write($lineCount, $rowCount, $section['description'], $format_text);
307
+            $rowCount++;
308
+            //master Section
309
+            if($section['masterSection']!=0) {
310
+                # get section details
311
+                $ssec = $Admin->fetch_object("sections", "id", $section['masterSection']);
312
+                $worksheet_sections->write($lineCount, $rowCount, $ssec->name, $format_text);
313
+                $rowCount++;
314
+            } else {
315
+                $worksheet_sections->write($lineCount, $rowCount, "/", $format_text);
316
+                $rowCount++;
317
+            }
318
+        }
319
+
320
+        $lineCount++;
321
+        $rowCount = 0;
322
+    }
323 323
 }
324 324
 
325 325
 // sending HTTP headers
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -5,36 +5,36 @@  discard block
 block discarded – undo
5 5
  ************************************/
6 6
 
7 7
 # include required scripts
8
-require( dirname(__FILE__) . '/../../../functions/functions.php' );
9
-require( dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php');
8
+require(dirname (__FILE__).'/../../../functions/functions.php');
9
+require(dirname (__FILE__).'/../../../functions/PEAR/Spreadsheet/Excel/Writer.php');
10 10
 
11 11
 # initialize user object
12 12
 $Database 	= new Database_PDO;
13
-$User 		= new User ($Database);
13
+$User = new User ($Database);
14 14
 $Admin 		= new Admin ($Database);
15 15
 $Tools	    = new Tools ($Database);
16 16
 $Subnets	= new Subnets ($Database);
17 17
 $Addresses	= new Addresses ($Database);
18
-$Sections	= new Sections ($Database);
18
+$Sections = new Sections ($Database);
19 19
 
20 20
 # verify that user is logged in
21
-$User->check_user_session();
21
+$User->check_user_session ();
22 22
 
23 23
 # Won't check per subnet/section rights since this is an admin section, where the admin user has full access
24 24
 
25 25
 # fetch all sections
26
-$all_sections = $Sections->fetch_all_sections();
26
+$all_sections = $Sections->fetch_all_sections ();
27 27
 
28 28
 # Lets do some reordering to show slaves!
29
-if($all_sections !== false) {
30
-	foreach($all_sections as $s) {
31
-		if($s->masterSection=="0") {
29
+if ($all_sections !== false) {
30
+	foreach ($all_sections as $s) {
31
+		if ($s->masterSection == "0") {
32 32
 			# it is master
33 33
 			$s->class = "master";
34 34
 			$sectionssorted[] = $s;
35 35
 			# check for slaves
36
-			foreach($all_sections as $ss) {
37
-				if($ss->masterSection==$s->id) {
36
+			foreach ($all_sections as $ss) {
37
+				if ($ss->masterSection == $s->id) {
38 38
 					$ss->class = "slave";
39 39
 					$sectionssorted[] = $ss;
40 40
 				}
@@ -47,104 +47,104 @@  discard block
 block discarded – undo
47 47
 
48 48
 
49 49
 # get all custom fields
50
-$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
50
+$custom_fields = $Tools->fetch_custom_fields ('ipaddresses');
51 51
 
52 52
 # Create a workbook
53
-$today = date("Ymd");
53
+$today = date ("Ymd");
54 54
 $filename = $today."_phpipam_ip_address_export.xls";
55
-$workbook = new Spreadsheet_Excel_Writer();
55
+$workbook = new Spreadsheet_Excel_Writer ();
56 56
 
57 57
 //formatting headers
58
-$format_header =& $workbook->addFormat();
59
-$format_header->setBold();
60
-$format_header->setColor('black');
61
-$format_header->setSize(12);
62
-$format_header->setAlign('left');
58
+$format_header = & $workbook->addFormat ();
59
+$format_header->setBold ();
60
+$format_header->setColor ('black');
61
+$format_header->setSize (12);
62
+$format_header->setAlign ('left');
63 63
 
64 64
 //formatting content
65
-$format_text =& $workbook->addFormat();
65
+$format_text = & $workbook->addFormat ();
66 66
 
67 67
 // Create a worksheet
68 68
 $worksheet_name = "IP Addresses";
69
-$worksheet =& $workbook->addWorksheet($worksheet_name);
69
+$worksheet = & $workbook->addWorksheet ($worksheet_name);
70 70
 
71 71
 $lineCount = 0;
72 72
 $rowCount = 0;
73 73
 
74 74
 //write headers
75
-if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) {
76
-	$worksheet->write($lineCount, $rowCount, _('Section') ,$format_header);
75
+if ((isset($_GET['section'])) && ($_GET['section'] == "on")) {
76
+	$worksheet->write ($lineCount, $rowCount, _ ('Section'), $format_header);
77 77
 	$rowCount++;
78 78
 }
79
-if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) {
80
-	$worksheet->write($lineCount, $rowCount, _('IP Address') ,$format_header);
79
+if ((isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on")) {
80
+	$worksheet->write ($lineCount, $rowCount, _ ('IP Address'), $format_header);
81 81
 	$rowCount++;
82 82
 }
83
-if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) {
84
-	$worksheet->write($lineCount, $rowCount, _('Hostname') ,$format_header);
83
+if ((isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on")) {
84
+	$worksheet->write ($lineCount, $rowCount, _ ('Hostname'), $format_header);
85 85
 	$rowCount++;
86 86
 }
87
-if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
88
-	$worksheet->write($lineCount, $rowCount, _('Description') ,$format_header);
87
+if ((isset($_GET['description'])) && ($_GET['description'] == "on")) {
88
+	$worksheet->write ($lineCount, $rowCount, _ ('Description'), $format_header);
89 89
 	$rowCount++;
90 90
 }
91
-if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) {
92
-	$worksheet->write($lineCount, $rowCount, _('VRF') ,$format_header);
91
+if ((isset($_GET['vrf'])) && ($_GET['vrf'] == "on")) {
92
+	$worksheet->write ($lineCount, $rowCount, _ ('VRF'), $format_header);
93 93
 	$rowCount++;
94 94
 	# fetch all VRFs
95
-	$all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
96
-	if (!$all_vrfs) { $all_vrfs = array(); }
95
+	$all_vrfs = $Admin->fetch_all_objects ("vrf", "vrfId");
96
+	if (!$all_vrfs) { $all_vrfs = array (); }
97 97
 	# prepare list for easy processing
98
-	$vrfs = array(); $vrfs[0] = "default";
98
+	$vrfs = array (); $vrfs[0] = "default";
99 99
 	foreach ($all_vrfs as $vrf) { $vrf = (array) $vrf; $vrfs[$vrf['vrfId']] = $vrf['name']; }
100 100
 }
101
-if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) {
102
-	$worksheet->write($lineCount, $rowCount, _('Subnet') ,$format_header);
101
+if ((isset($_GET['subnet'])) && ($_GET['subnet'] == "on")) {
102
+	$worksheet->write ($lineCount, $rowCount, _ ('Subnet'), $format_header);
103 103
 	$rowCount++;
104 104
 }
105
-if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) {
106
-	$worksheet->write($lineCount, $rowCount, _('MAC') ,$format_header);
105
+if ((isset($_GET['mac'])) && ($_GET['mac'] == "on")) {
106
+	$worksheet->write ($lineCount, $rowCount, _ ('MAC'), $format_header);
107 107
 	$rowCount++;
108 108
 }
109
-if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) {
110
-	$worksheet->write($lineCount, $rowCount, _('Owner') ,$format_header);
109
+if ((isset($_GET['owner'])) && ($_GET['owner'] == "on")) {
110
+	$worksheet->write ($lineCount, $rowCount, _ ('Owner'), $format_header);
111 111
 	$rowCount++;
112 112
 }
113
-if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) {
114
-	$worksheet->write($lineCount, $rowCount, _('Device') ,$format_header);
113
+if ((isset($_GET['device'])) && ($_GET['device'] == "on")) {
114
+	$worksheet->write ($lineCount, $rowCount, _ ('Device'), $format_header);
115 115
 	$rowCount++;
116 116
 	# get Devices and reorder
117 117
 	$devices = $Tools->fetch_all_objects ("devices", "hostname");
118
-	$devices_indexed = array();
119
-	if ($devices!==false) {
120
-	foreach($devices as $d) {
118
+	$devices_indexed = array ();
119
+	if ($devices !== false) {
120
+	foreach ($devices as $d) {
121 121
     		$devices_indexed[$d->id] = $d;
122 122
     	}
123 123
 	}
124 124
 }
125
-if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) {
126
-	$worksheet->write($lineCount, $rowCount, _('Note') ,$format_header);
125
+if ((isset($_GET['note'])) && ($_GET['note'] == "on")) {
126
+	$worksheet->write ($lineCount, $rowCount, _ ('Note'), $format_header);
127 127
 	$rowCount++;
128 128
 }
129
-if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) {
130
-	$worksheet->write($lineCount, $rowCount, _('Tag') ,$format_header);
129
+if ((isset($_GET['tag'])) && ($_GET['tag'] == "on")) {
130
+	$worksheet->write ($lineCount, $rowCount, _ ('Tag'), $format_header);
131 131
 	$rowCount++;
132 132
 	# get IP address types
133
-	$ip_types = $Addresses->addresses_types_fetch();
133
+	$ip_types = $Addresses->addresses_types_fetch ();
134 134
 }
135
-if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) {
136
-	$worksheet->write($lineCount, $rowCount, _('Gateway') ,$format_header);
135
+if ((isset($_GET['gateway'])) && ($_GET['gateway'] == "on")) {
136
+	$worksheet->write ($lineCount, $rowCount, _ ('Gateway'), $format_header);
137 137
 	$rowCount++;
138 138
 }
139 139
 
140 140
 //custom fields
141
-if(sizeof($custom_fields) > 0) {
142
-	foreach($custom_fields as $myField) {
141
+if (sizeof ($custom_fields) > 0) {
142
+	foreach ($custom_fields as $myField) {
143 143
 		//set temp name - replace space with three ___
144
-		$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
144
+		$myField['nameTemp'] = str_replace (" ", "___", $myField['name']);
145 145
 
146
-		if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
147
-			$worksheet->write($lineCount, $rowCount, $myField['name'] ,$format_header);
146
+		if ((isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on")) {
147
+			$worksheet->write ($lineCount, $rowCount, $myField['name'], $format_header);
148 148
 			$rowCount++;
149 149
 		}
150 150
 	}
@@ -154,28 +154,28 @@  discard block
 block discarded – undo
154 154
 $lineCount++;
155 155
 
156 156
 //write Subnet entries for the selected sections
157
-if($all_sections!==false) {
157
+if ($all_sections !== false) {
158 158
 	foreach ($all_sections as $section) {
159 159
 		//cast
160 160
 		$section = (array) $section;
161 161
 
162
-		if( (isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on") ) {
162
+		if ((isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on")) {
163 163
 			// get all subnets in section
164
-			$section_subnets = $Subnets->fetch_section_subnets($section['id']);
164
+			$section_subnets = $Subnets->fetch_section_subnets ($section['id']);
165 165
 
166
-			if (sizeof($section_subnets)==0) { continue; }
166
+			if (sizeof ($section_subnets) == 0) { continue; }
167 167
 
168 168
 			foreach ($section_subnets as $subnet) {
169 169
 
170 170
 				$subnet = (array) $subnet;
171 171
 
172 172
 				// ignore folders
173
-				if($subnet['isFolder']) { continue; }
173
+				if ($subnet['isFolder']) { continue; }
174 174
 
175 175
 				// grab IP addresses
176 176
 				$ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
177 177
 
178
-				if (sizeof($ipaddresses)==0) { continue; }
178
+				if (sizeof ($ipaddresses) == 0) { continue; }
179 179
 
180 180
 				foreach ($ipaddresses as $ip) {
181 181
 
@@ -183,84 +183,84 @@  discard block
 block discarded – undo
183 183
 					$ip = (array) $ip;
184 184
 
185 185
 
186
-					if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) {
187
-						$worksheet->write($lineCount, $rowCount, $section['name'], $format_text);
186
+					if ((isset($_GET['section'])) && ($_GET['section'] == "on")) {
187
+						$worksheet->write ($lineCount, $rowCount, $section['name'], $format_text);
188 188
 						$rowCount++;
189 189
 					}
190 190
 
191
-					if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) {
192
-						$worksheet->write($lineCount, $rowCount, $Subnets->transform_to_dotted($ip['ip_addr']), $format_text);
191
+					if ((isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on")) {
192
+						$worksheet->write ($lineCount, $rowCount, $Subnets->transform_to_dotted ($ip['ip_addr']), $format_text);
193 193
 						$rowCount++;
194 194
 					}
195 195
 
196
-					if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) {
197
-						$worksheet->write($lineCount, $rowCount, $ip['dns_name'], $format_text);
196
+					if ((isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on")) {
197
+						$worksheet->write ($lineCount, $rowCount, $ip['dns_name'], $format_text);
198 198
 						$rowCount++;
199 199
 					}
200 200
 
201
-					if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
202
-						$worksheet->write($lineCount, $rowCount, $ip['description'], $format_text);
201
+					if ((isset($_GET['description'])) && ($_GET['description'] == "on")) {
202
+						$worksheet->write ($lineCount, $rowCount, $ip['description'], $format_text);
203 203
 						$rowCount++;
204 204
 					}
205 205
 
206
-					if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) {
207
-						$worksheet->write($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text);
206
+					if ((isset($_GET['vrf'])) && ($_GET['vrf'] == "on")) {
207
+						$worksheet->write ($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text);
208 208
 						$rowCount++;
209 209
 					}
210 210
 
211
-					if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) {
212
-						$worksheet->write($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text);
211
+					if ((isset($_GET['subnet'])) && ($_GET['subnet'] == "on")) {
212
+						$worksheet->write ($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text);
213 213
 						$rowCount++;
214 214
 					}
215 215
 
216
-					if( (isset($_GET['state'])) && ($_GET['state'] == "on") ) {
217
-						$worksheet->write($lineCount, $rowCount, $ip['state'], $format_text);
216
+					if ((isset($_GET['state'])) && ($_GET['state'] == "on")) {
217
+						$worksheet->write ($lineCount, $rowCount, $ip['state'], $format_text);
218 218
 						$rowCount++;
219 219
 					}
220 220
 
221
-					if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) {
222
-						$worksheet->write($lineCount, $rowCount, $ip['mac'], $format_text);
221
+					if ((isset($_GET['mac'])) && ($_GET['mac'] == "on")) {
222
+						$worksheet->write ($lineCount, $rowCount, $ip['mac'], $format_text);
223 223
 						$rowCount++;
224 224
 					}
225 225
 
226
-					if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) {
227
-						$worksheet->write($lineCount, $rowCount, $ip['owner'], $format_text);
226
+					if ((isset($_GET['owner'])) && ($_GET['owner'] == "on")) {
227
+						$worksheet->write ($lineCount, $rowCount, $ip['owner'], $format_text);
228 228
 						$rowCount++;
229 229
 					}
230 230
 
231
-					if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) {
231
+					if ((isset($_GET['device'])) && ($_GET['device'] == "on")) {
232 232
 						//change device to name
233
-						$ip['device'] = is_null($ip['switch'])||strlen($ip['switch'])==0||$ip['switch']==0 ? "" : $devices_indexed[$ip['switch']]->hostname;
234
-						$worksheet->write($lineCount, $rowCount, $ip['device'], $format_text);
233
+						$ip['device'] = is_null ($ip['switch']) || strlen ($ip['switch']) == 0 || $ip['switch'] == 0 ? "" : $devices_indexed[$ip['switch']]->hostname;
234
+						$worksheet->write ($lineCount, $rowCount, $ip['device'], $format_text);
235 235
 						$rowCount++;
236 236
 					}
237 237
 
238
-					if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) {
239
-						$worksheet->write($lineCount, $rowCount, $ip['note'], $format_text);
238
+					if ((isset($_GET['note'])) && ($_GET['note'] == "on")) {
239
+						$worksheet->write ($lineCount, $rowCount, $ip['note'], $format_text);
240 240
 						$rowCount++;
241 241
 					}
242 242
 
243
-					if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) {
243
+					if ((isset($_GET['tag'])) && ($_GET['tag'] == "on")) {
244 244
 						//reformat tag
245 245
 						$ip['tag'] = (@$ip_types[$ip['state']]['showtag']) ? $ip_types[$ip['state']]['type'] : "";
246
-						$worksheet->write($lineCount, $rowCount, $ip['tag'], $format_text);
246
+						$worksheet->write ($lineCount, $rowCount, $ip['tag'], $format_text);
247 247
 						$rowCount++;
248 248
 					}
249 249
 
250
-					if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) {
251
-						$ip['gateway'] = ($ip['is_gateway']) ? _("Yes") : _("No");
252
-						$worksheet->write($lineCount, $rowCount, $ip['gateway'], $format_text);
250
+					if ((isset($_GET['gateway'])) && ($_GET['gateway'] == "on")) {
251
+						$ip['gateway'] = ($ip['is_gateway']) ? _ ("Yes") : _ ("No");
252
+						$worksheet->write ($lineCount, $rowCount, $ip['gateway'], $format_text);
253 253
 						$rowCount++;
254 254
 					}
255 255
 
256 256
 					//custom fields, per subnet
257
-					if(sizeof($custom_fields) > 0) {
258
-						foreach($custom_fields as $myField) {
257
+					if (sizeof ($custom_fields) > 0) {
258
+						foreach ($custom_fields as $myField) {
259 259
 							//set temp name - replace space with three ___
260
-							$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
260
+							$myField['nameTemp'] = str_replace (" ", "___", $myField['name']);
261 261
 
262
-							if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
263
-								$worksheet->write($lineCount, $rowCount, $ip[$myField['name']], $format_text);
262
+							if ((isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on")) {
263
+								$worksheet->write ($lineCount, $rowCount, $ip[$myField['name']], $format_text);
264 264
 								$rowCount++;
265 265
 							}
266 266
 						}
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
 $lineCount++;
279 279
 
280 280
 //write section sheet
281
-if( (isset($_GET['exportSections'])) && ($_GET['exportSections'] == "on") ) {
281
+if ((isset($_GET['exportSections'])) && ($_GET['exportSections'] == "on")) {
282 282
 	// Create a worksheet
283
-	$worksheet_sections =& $workbook->addWorksheet('Sections');
283
+	$worksheet_sections = & $workbook->addWorksheet ('Sections');
284 284
 
285 285
 	$lineCount = 0;
286 286
 	$rowCount = 0;
287 287
 
288 288
 	//write headers
289
-	$worksheet_sections->write($lineCount, $rowCount, _('Name') ,$format_header);
289
+	$worksheet_sections->write ($lineCount, $rowCount, _ ('Name'), $format_header);
290 290
 	$rowCount++;
291
-	$worksheet_sections->write($lineCount, $rowCount, _('Description') ,$format_header);
291
+	$worksheet_sections->write ($lineCount, $rowCount, _ ('Description'), $format_header);
292 292
 	$rowCount++;
293
-	$worksheet_sections->write($lineCount, $rowCount, _('Parent') ,$format_header);
293
+	$worksheet_sections->write ($lineCount, $rowCount, _ ('Parent'), $format_header);
294 294
 	$rowCount++;
295 295
 
296 296
 	$lineCount++;
@@ -300,19 +300,19 @@  discard block
 block discarded – undo
300 300
 		//cast
301 301
 		$section = (array) $section;
302 302
 
303
-		if( (isset($_GET['exportSection__'.str_replace(" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace(" ", "_", $section['name'])] == "on") ) {
304
-			$worksheet_sections->write($lineCount, $rowCount, $section['name'], $format_text);
303
+		if ((isset($_GET['exportSection__'.str_replace (" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace (" ", "_", $section['name'])] == "on")) {
304
+			$worksheet_sections->write ($lineCount, $rowCount, $section['name'], $format_text);
305 305
 			$rowCount++;
306
-			$worksheet_sections->write($lineCount, $rowCount, $section['description'], $format_text);
306
+			$worksheet_sections->write ($lineCount, $rowCount, $section['description'], $format_text);
307 307
 			$rowCount++;
308 308
 			//master Section
309
-			if($section['masterSection']!=0) {
309
+			if ($section['masterSection'] != 0) {
310 310
 				# get section details
311
-				$ssec = $Admin->fetch_object("sections", "id", $section['masterSection']);
312
-				$worksheet_sections->write($lineCount, $rowCount, $ssec->name, $format_text);
311
+				$ssec = $Admin->fetch_object ("sections", "id", $section['masterSection']);
312
+				$worksheet_sections->write ($lineCount, $rowCount, $ssec->name, $format_text);
313 313
 				$rowCount++;
314 314
 			} else {
315
-				$worksheet_sections->write($lineCount, $rowCount, "/", $format_text);
315
+				$worksheet_sections->write ($lineCount, $rowCount, "/", $format_text);
316 316
 				$rowCount++;
317 317
 			}
318 318
 		}
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
 }
324 324
 
325 325
 // sending HTTP headers
326
-$workbook->send($filename);
326
+$workbook->send ($filename);
327 327
 
328 328
 // Let's send the file
329
-$workbook->close();
329
+$workbook->close ();
330 330
 
331 331
 ?>
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr-select.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -60,44 +60,44 @@
 block discarded – undo
60 60
 
61 61
 # manually adjust the standard fields
62 62
 foreach($expfields as $std_field) {
63
-	# extra table and field
64
-	if (isset($extfields[$std_field])) {
65
-		$cfield = $extfields[$std_field]["field"];
66
-		$ctable = $extfields[$std_field]["table"];
67
-		$pname  = $extfields[$std_field]["pname"]." ";
68
-	} else {
69
-		# default table and field
70
-		$cfield = $std_field;
71
-		$ctable = $mtable;
72
-		$pname = "";
73
-	}
74
-
75
-	# read field attributes
76
-	$field = $Tools->fetch_full_field_definition($ctable,$cfield);
77
-	$field = (array) $field;
78
-
79
-	# mark required fields with *
80
-	$msgr = in_array($std_field,$reqfields) ? "*" : "";
81
-
82
-	#prebuild template table rows to avoid useless foreach loops
83
-	$tpl_field_names.= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>";
84
-	$tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>";
63
+    # extra table and field
64
+    if (isset($extfields[$std_field])) {
65
+        $cfield = $extfields[$std_field]["field"];
66
+        $ctable = $extfields[$std_field]["table"];
67
+        $pname  = $extfields[$std_field]["pname"]." ";
68
+    } else {
69
+        # default table and field
70
+        $cfield = $std_field;
71
+        $ctable = $mtable;
72
+        $pname = "";
73
+    }
74
+
75
+    # read field attributes
76
+    $field = $Tools->fetch_full_field_definition($ctable,$cfield);
77
+    $field = (array) $field;
78
+
79
+    # mark required fields with *
80
+    $msgr = in_array($std_field,$reqfields) ? "*" : "";
81
+
82
+    #prebuild template table rows to avoid useless foreach loops
83
+    $tpl_field_names.= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>";
84
+    $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>";
85 85
 }
86 86
 
87 87
 # append the custom fields, if any
88 88
 $custom_fields = $Tools->fetch_custom_fields($mtable);
89 89
 if(sizeof($custom_fields) > 0) {
90
-	foreach($custom_fields as $myField) {
91
-		# add field to required fields if needed
92
-		if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
93
-		# mark required fields with *
94
-		$msgr = in_array($myField['name'],$reqfields) ? "*" : "";
95
-
96
-		$tpl_field_names.= "<th>".$myField['name'].$msgr."</th>";
97
-		$tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>";
98
-		$expfields[] = $myField['name'];
90
+    foreach($custom_fields as $myField) {
91
+        # add field to required fields if needed
92
+        if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
93
+        # mark required fields with *
94
+        $msgr = in_array($myField['name'],$reqfields) ? "*" : "";
95
+
96
+        $tpl_field_names.= "<th>".$myField['name'].$msgr."</th>";
97
+        $tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>";
98
+        $expfields[] = $myField['name'];
99 99
 //		$disfields[] = $myField['name'];
100
-	}
100
+    }
101 101
 }
102 102
 
103 103
 ?>
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -5,22 +5,22 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 # include required scripts
8
-require( dirname(__FILE__) . '/../../../functions/functions.php' );
8
+require(dirname (__FILE__).'/../../../functions/functions.php');
9 9
 
10 10
 # initialize user object
11 11
 $Database 	= new Database_PDO;
12
-$User 		= new User ($Database);
12
+$User = new User ($Database);
13 13
 $Tools	    = new Tools ($Database);
14
-$Admin 		= new Admin ($Database);
14
+$Admin = new Admin ($Database);
15 15
 
16 16
 # verify that user is logged in
17
-$User->check_user_session();
17
+$User->check_user_session ();
18 18
 
19 19
 $tpl_field_names = "";
20 20
 $tpl_field_types = "";
21 21
 
22 22
 # predefine field list
23
-$expfields = array ("section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway");
23
+$expfields = array ("section", "ip_addr", "dns_name", "description", "vrf", "subnet", "mac", "owner", "device", "note", "tag", "gateway");
24 24
 //$disfields = array ("Section","IP Address","Hostname","Description","VRF","Subnet","MAC","owner","device","note","TAG");
25 25
 $mtable = "ipaddresses"; # main table where to check the fields
26 26
 
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 $extfields["gateway"]["pname"] = "Gateway";
57 57
 
58 58
 # required fields without which we will not continue
59
-$reqfields = array("section","ip_addr","subnet");
59
+$reqfields = array ("section", "ip_addr", "subnet");
60 60
 
61 61
 # manually adjust the standard fields
62
-foreach($expfields as $std_field) {
62
+foreach ($expfields as $std_field) {
63 63
 	# extra table and field
64 64
 	if (isset($extfields[$std_field])) {
65 65
 		$cfield = $extfields[$std_field]["field"];
@@ -73,28 +73,28 @@  discard block
 block discarded – undo
73 73
 	}
74 74
 
75 75
 	# read field attributes
76
-	$field = $Tools->fetch_full_field_definition($ctable,$cfield);
76
+	$field = $Tools->fetch_full_field_definition ($ctable, $cfield);
77 77
 	$field = (array) $field;
78 78
 
79 79
 	# mark required fields with *
80
-	$msgr = in_array($std_field,$reqfields) ? "*" : "";
80
+	$msgr = in_array ($std_field, $reqfields) ? "*" : "";
81 81
 
82 82
 	#prebuild template table rows to avoid useless foreach loops
83
-	$tpl_field_names.= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>";
84
-	$tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>";
83
+	$tpl_field_names .= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>";
84
+	$tpl_field_types .= "<td><small>".wordwrap ($field['Type'], 18, "<br>\n", true)."</small></td>";
85 85
 }
86 86
 
87 87
 # append the custom fields, if any
88
-$custom_fields = $Tools->fetch_custom_fields($mtable);
89
-if(sizeof($custom_fields) > 0) {
90
-	foreach($custom_fields as $myField) {
88
+$custom_fields = $Tools->fetch_custom_fields ($mtable);
89
+if (sizeof ($custom_fields) > 0) {
90
+	foreach ($custom_fields as $myField) {
91 91
 		# add field to required fields if needed
92 92
 		if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
93 93
 		# mark required fields with *
94
-		$msgr = in_array($myField['name'],$reqfields) ? "*" : "";
94
+		$msgr = in_array ($myField['name'], $reqfields) ? "*" : "";
95 95
 
96
-		$tpl_field_names.= "<th>".$myField['name'].$msgr."</th>";
97
-		$tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>";
96
+		$tpl_field_names .= "<th>".$myField['name'].$msgr."</th>";
97
+		$tpl_field_types .= "<td><small>".wordwrap ($myField['type'], 18, "<br>\n", true)."</small></td>";
98 98
 		$expfields[] = $myField['name'];
99 99
 //		$disfields[] = $myField['name'];
100 100
 	}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 ?>
104 104
 
105 105
 <!-- header -->
106
-<div class="pHeader"><?php print _("Select IP Addresses file and fields to import"); ?></div>
106
+<div class="pHeader"><?php print _ ("Select IP Addresses file and fields to import"); ?></div>
107 107
 
108 108
 <!-- content -->
109 109
 <div class="pContent">
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
 
113 113
 # print template form
114 114
 print "<form id='selectImportFields'><div id='topmsg'>";
115
-print '<h4>'._("Template").'</h4><hr>';
116
-print _("The import XLS/CSV should have the following fields and a <b>header row</b> for a succesful import:");
115
+print '<h4>'._ ("Template").'</h4><hr>';
116
+print _ ("The import XLS/CSV should have the following fields and a <b>header row</b> for a succesful import:");
117 117
 print "</div>";
118
-print "<input name='expfields' type='hidden' value='".implode('|',$expfields)."' style='display:none;'>";
119
-print "<input name='reqfields' type='hidden' value='".implode('|',$reqfields)."' style='display:none;'>";
118
+print "<input name='expfields' type='hidden' value='".implode ('|', $expfields)."' style='display:none;'>";
119
+print "<input name='reqfields' type='hidden' value='".implode ('|', $reqfields)."' style='display:none;'>";
120 120
 print "<input name='filetype' id='filetype' type='hidden' value='' style='display:none;'>";
121 121
 print "<table class='table table-striped table-condensed' id='fieldstable'><tbody>";
122
-print "<tr>" . $tpl_field_names . "</tr>";
123
-print "<tr>" . $tpl_field_types . "</tr>";
122
+print "<tr>".$tpl_field_names."</tr>";
123
+print "<tr>".$tpl_field_types."</tr>";
124 124
 print "</tbody></table>";
125
-print "<div id='bottommsg'>"._("The fields marked with * are mandatory.")."
126
-	<br>"._("Providing a subnet is optional, the system will add the IP to the longest match if no subnet is provided.")."
127
-	<br>"._("The mask can be provided either as a separate field or with the subnet, sparated by \"/\"")."
125
+print "<div id='bottommsg'>"._ ("The fields marked with * are mandatory.")."
126
+	<br>"._ ("Providing a subnet is optional, the system will add the IP to the longest match if no subnet is provided.")."
127
+	<br>"._ ("The mask can be provided either as a separate field or with the subnet, sparated by \"/\"")."
128 128
 	</div>";
129
-print "<div class='checkbox'><label><input name='searchallvrfs' id='searchallvrfs' type='checkbox' unchecked>"._("Search for matching subnet in all VRFs (ignore provided VRF).")."</label></div>";
129
+print "<div class='checkbox'><label><input name='searchallvrfs' id='searchallvrfs' type='checkbox' unchecked>"._ ("Search for matching subnet in all VRFs (ignore provided VRF).")."</label></div>";
130 130
 #TODO# add option to hide php fields
131 131
 #print "<div class='checkbox'><label><input name='showspecific' id='showspecific' type='checkbox' unchecked>"._("Show PHPIPAM specific columns.")."</label></div>";
132 132
 print "</form>";
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 $templatetype = 'ipaddr';
135 135
 # print upload section
136 136
 print "<div id='uplmsg'>";
137
-print '<h4>'._("Upload file").'</h4><hr>';
137
+print '<h4>'._ ("Upload file").'</h4><hr>';
138 138
 include 'import-button.php';
139 139
 print "</div>";
140 140
 ?>
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 <!-- footer -->
144 144
 <div class="pFooter">
145 145
 	<div class="btn-group">
146
-		<button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button>
147
-		<button class="btn btn-sm btn-default" id="dataImportPreview" data-type="ipaddr" disabled><i class="fa fa-eye"></i> <?php print _('Preview'); ?></button>
146
+		<button class="btn btn-sm btn-default hidePopups"><?php print _ ('Cancel'); ?></button>
147
+		<button class="btn btn-sm btn-default" id="dataImportPreview" data-type="ipaddr" disabled><i class="fa fa-eye"></i> <?php print _ ('Preview'); ?></button>
148 148
 	</div>
149 149
 </div>
Please login to merge, or discard this patch.
app/admin/import-export/import-template.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -25,77 +25,77 @@
 block discarded – undo
25 25
 
26 26
 
27 27
 if ($type == 'subnets'){
28
-	//get all custom fields!
29
-	$custom_address_fields = $Tools->fetch_custom_fields('subnets');
30
-	// set headers
31
-	$worksheet->write($lineCount, 0, _('Section'));
32
-	$worksheet->write($lineCount, 1, _('Subnet'));
33
-	$worksheet->write($lineCount, 2, _('Mask'));
34
-	$worksheet->write($lineCount, 3, _('Description'));
35
-	$worksheet->write($lineCount, 4, _('VLAN'));
36
-	$worksheet->write($lineCount, 5, _('VLAN Domain'));
37
-	$worksheet->write($lineCount, 6, _('VRF'));
38
-	$fc =7 ;
39
-	foreach($custom_address_fields as $k=>$f) {
40
-		$worksheet->write($lineCount, $fc, $k);
41
-		$fc++;
42
-	}
28
+    //get all custom fields!
29
+    $custom_address_fields = $Tools->fetch_custom_fields('subnets');
30
+    // set headers
31
+    $worksheet->write($lineCount, 0, _('Section'));
32
+    $worksheet->write($lineCount, 1, _('Subnet'));
33
+    $worksheet->write($lineCount, 2, _('Mask'));
34
+    $worksheet->write($lineCount, 3, _('Description'));
35
+    $worksheet->write($lineCount, 4, _('VLAN'));
36
+    $worksheet->write($lineCount, 5, _('VLAN Domain'));
37
+    $worksheet->write($lineCount, 6, _('VRF'));
38
+    $fc =7 ;
39
+    foreach($custom_address_fields as $k=>$f) {
40
+        $worksheet->write($lineCount, $fc, $k);
41
+        $fc++;
42
+    }
43 43
 }
44 44
 elseif ($type == 'ipaddr'){
45
-	//get all custom fields!
46
-	$custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
47
-	// set headers
48
-	// "section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway"
49
-	$worksheet->write($lineCount, 0, _('Section'));
50
-	$worksheet->write($lineCount, 1, _('IP address'));
51
-	$worksheet->write($lineCount, 2, _('DNS Hostname'));
52
-	$worksheet->write($lineCount, 3, _('Description'));
53
-	$worksheet->write($lineCount, 4, _('VRF'));
54
-	$worksheet->write($lineCount, 4, _('Subnet'));
55
-	$worksheet->write($lineCount, 5, _('MAC'));
56
-	$worksheet->write($lineCount, 6, _('Owner'));
57
-	$worksheet->write($lineCount, 7, _('Device'));
58
-	$worksheet->write($lineCount, 8, _('Note'));
59
-	$worksheet->write($lineCount, 9, _('Tag'));
60
-	$worksheet->write($lineCount, 10, _('Gateway'));
61
-	$fc =7 ;
62
-	foreach($custom_address_fields as $k=>$f) {
63
-		$worksheet->write($lineCount, $fc, $k);
64
-		$fc++;
65
-	}
45
+    //get all custom fields!
46
+    $custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
47
+    // set headers
48
+    // "section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway"
49
+    $worksheet->write($lineCount, 0, _('Section'));
50
+    $worksheet->write($lineCount, 1, _('IP address'));
51
+    $worksheet->write($lineCount, 2, _('DNS Hostname'));
52
+    $worksheet->write($lineCount, 3, _('Description'));
53
+    $worksheet->write($lineCount, 4, _('VRF'));
54
+    $worksheet->write($lineCount, 4, _('Subnet'));
55
+    $worksheet->write($lineCount, 5, _('MAC'));
56
+    $worksheet->write($lineCount, 6, _('Owner'));
57
+    $worksheet->write($lineCount, 7, _('Device'));
58
+    $worksheet->write($lineCount, 8, _('Note'));
59
+    $worksheet->write($lineCount, 9, _('Tag'));
60
+    $worksheet->write($lineCount, 10, _('Gateway'));
61
+    $fc =7 ;
62
+    foreach($custom_address_fields as $k=>$f) {
63
+        $worksheet->write($lineCount, $fc, $k);
64
+        $fc++;
65
+    }
66 66
 }
67 67
 elseif ($type == 'vrf'){
68
-	//get all custom fields!
69
-	$custom_address_fields = $Tools->fetch_custom_fields('vrf');
70
-	// set headers
71
-	$worksheet->write($lineCount, 0, _('Name'));
72
-	$worksheet->write($lineCount, 1, _('RD'));
73
-	$worksheet->write($lineCount, 2, _('Description'));
74
-	$fc =3 ;
75
-	foreach($custom_address_fields as $k=>$f) {
76
-		$worksheet->write($lineCount, $fc, $k);
77
-		$fc++;
78
-	}
68
+    //get all custom fields!
69
+    $custom_address_fields = $Tools->fetch_custom_fields('vrf');
70
+    // set headers
71
+    $worksheet->write($lineCount, 0, _('Name'));
72
+    $worksheet->write($lineCount, 1, _('RD'));
73
+    $worksheet->write($lineCount, 2, _('Description'));
74
+    $fc =3 ;
75
+    foreach($custom_address_fields as $k=>$f) {
76
+        $worksheet->write($lineCount, $fc, $k);
77
+        $fc++;
78
+    }
79 79
 }
80 80
 elseif ($type == 'vlans'){
81
-	//get all custom fields!
82
-	$custom_address_fields = $Tools->fetch_custom_fields('vlans');
83
-	// set headers
84
-	$worksheet->write($lineCount, 0, _('Name'));
85
-	$worksheet->write($lineCount, 1, _('Number'));
86
-	$worksheet->write($lineCount, 2, _('Description'));
87
-	$worksheet->write($lineCount, 3, _('Domain name'));
88
-	$fc =4 ;
89
-	foreach($custom_address_fields as $k=>$f) {
90
-		$worksheet->write($lineCount, $fc, $k);
91
-		$fc++;
92
-	}
81
+    //get all custom fields!
82
+    $custom_address_fields = $Tools->fetch_custom_fields('vlans');
83
+    // set headers
84
+    $worksheet->write($lineCount, 0, _('Name'));
85
+    $worksheet->write($lineCount, 1, _('Number'));
86
+    $worksheet->write($lineCount, 2, _('Description'));
87
+    $worksheet->write($lineCount, 3, _('Domain name'));
88
+    $fc =4 ;
89
+    foreach($custom_address_fields as $k=>$f) {
90
+        $worksheet->write($lineCount, $fc, $k);
91
+        $fc++;
92
+    }
93 93
 }
94 94
 elseif ($type == 'l2dom'){
95
-	// set headers
96
-	$worksheet->write($lineCount, 0, _('Name'));
97
-	$worksheet->write($lineCount, 1, _('Description'));
98
-	$fc =2 ;
95
+    // set headers
96
+    $worksheet->write($lineCount, 0, _('Name'));
97
+    $worksheet->write($lineCount, 1, _('Description'));
98
+    $fc =2 ;
99 99
 }
100 100
 // sending HTTP headers
101 101
 $workbook->send($filename);
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -3,102 +3,102 @@
 block discarded – undo
3 3
  *	Generate XLS template
4 4
  *********************************/
5 5
 /* functions */
6
-require( dirname(__FILE__) . '/../../../functions/functions.php');
7
-require( dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php');
6
+require(dirname (__FILE__).'/../../../functions/functions.php');
7
+require(dirname (__FILE__).'/../../../functions/PEAR/Spreadsheet/Excel/Writer.php');
8 8
 # classes
9 9
 $Database 	= new Database_PDO;
10
-$User 		= new User ($Database);
10
+$User = new User ($Database);
11 11
 $Tools	 	= new Tools ($Database);
12 12
 $Addresses	= new Addresses ($Database);
13 13
 $Result 	= new Result;
14 14
 $type = $_GET['type'];
15 15
 
16 16
 # verify that user is logged in
17
-$User->check_user_session();
17
+$User->check_user_session ();
18 18
 // Create a workbook
19
-$filename = "phpipam_template_" . $type . ".xls";
20
-$workbook = new Spreadsheet_Excel_Writer();
19
+$filename = "phpipam_template_".$type.".xls";
20
+$workbook = new Spreadsheet_Excel_Writer ();
21 21
 $lineCount = 0;
22 22
 
23 23
 // Create a worksheet
24
-$worksheet = $workbook->addWorksheet("template");
24
+$worksheet = $workbook->addWorksheet ("template");
25 25
 
26 26
 
27
-if ($type == 'subnets'){
27
+if ($type == 'subnets') {
28 28
 	//get all custom fields!
29
-	$custom_address_fields = $Tools->fetch_custom_fields('subnets');
29
+	$custom_address_fields = $Tools->fetch_custom_fields ('subnets');
30 30
 	// set headers
31
-	$worksheet->write($lineCount, 0, _('Section'));
32
-	$worksheet->write($lineCount, 1, _('Subnet'));
33
-	$worksheet->write($lineCount, 2, _('Mask'));
34
-	$worksheet->write($lineCount, 3, _('Description'));
35
-	$worksheet->write($lineCount, 4, _('VLAN'));
36
-	$worksheet->write($lineCount, 5, _('VLAN Domain'));
37
-	$worksheet->write($lineCount, 6, _('VRF'));
38
-	$fc =7 ;
39
-	foreach($custom_address_fields as $k=>$f) {
40
-		$worksheet->write($lineCount, $fc, $k);
31
+	$worksheet->write ($lineCount, 0, _ ('Section'));
32
+	$worksheet->write ($lineCount, 1, _ ('Subnet'));
33
+	$worksheet->write ($lineCount, 2, _ ('Mask'));
34
+	$worksheet->write ($lineCount, 3, _ ('Description'));
35
+	$worksheet->write ($lineCount, 4, _ ('VLAN'));
36
+	$worksheet->write ($lineCount, 5, _ ('VLAN Domain'));
37
+	$worksheet->write ($lineCount, 6, _ ('VRF'));
38
+	$fc = 7;
39
+	foreach ($custom_address_fields as $k=>$f) {
40
+		$worksheet->write ($lineCount, $fc, $k);
41 41
 		$fc++;
42 42
 	}
43 43
 }
44
-elseif ($type == 'ipaddr'){
44
+elseif ($type == 'ipaddr') {
45 45
 	//get all custom fields!
46
-	$custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
46
+	$custom_address_fields = $Tools->fetch_custom_fields ('ipaddresses');
47 47
 	// set headers
48 48
 	// "section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway"
49
-	$worksheet->write($lineCount, 0, _('Section'));
50
-	$worksheet->write($lineCount, 1, _('IP address'));
51
-	$worksheet->write($lineCount, 2, _('DNS Hostname'));
52
-	$worksheet->write($lineCount, 3, _('Description'));
53
-	$worksheet->write($lineCount, 4, _('VRF'));
54
-	$worksheet->write($lineCount, 4, _('Subnet'));
55
-	$worksheet->write($lineCount, 5, _('MAC'));
56
-	$worksheet->write($lineCount, 6, _('Owner'));
57
-	$worksheet->write($lineCount, 7, _('Device'));
58
-	$worksheet->write($lineCount, 8, _('Note'));
59
-	$worksheet->write($lineCount, 9, _('Tag'));
60
-	$worksheet->write($lineCount, 10, _('Gateway'));
61
-	$fc =7 ;
62
-	foreach($custom_address_fields as $k=>$f) {
63
-		$worksheet->write($lineCount, $fc, $k);
49
+	$worksheet->write ($lineCount, 0, _ ('Section'));
50
+	$worksheet->write ($lineCount, 1, _ ('IP address'));
51
+	$worksheet->write ($lineCount, 2, _ ('DNS Hostname'));
52
+	$worksheet->write ($lineCount, 3, _ ('Description'));
53
+	$worksheet->write ($lineCount, 4, _ ('VRF'));
54
+	$worksheet->write ($lineCount, 4, _ ('Subnet'));
55
+	$worksheet->write ($lineCount, 5, _ ('MAC'));
56
+	$worksheet->write ($lineCount, 6, _ ('Owner'));
57
+	$worksheet->write ($lineCount, 7, _ ('Device'));
58
+	$worksheet->write ($lineCount, 8, _ ('Note'));
59
+	$worksheet->write ($lineCount, 9, _ ('Tag'));
60
+	$worksheet->write ($lineCount, 10, _ ('Gateway'));
61
+	$fc = 7;
62
+	foreach ($custom_address_fields as $k=>$f) {
63
+		$worksheet->write ($lineCount, $fc, $k);
64 64
 		$fc++;
65 65
 	}
66 66
 }
67
-elseif ($type == 'vrf'){
67
+elseif ($type == 'vrf') {
68 68
 	//get all custom fields!
69
-	$custom_address_fields = $Tools->fetch_custom_fields('vrf');
69
+	$custom_address_fields = $Tools->fetch_custom_fields ('vrf');
70 70
 	// set headers
71
-	$worksheet->write($lineCount, 0, _('Name'));
72
-	$worksheet->write($lineCount, 1, _('RD'));
73
-	$worksheet->write($lineCount, 2, _('Description'));
74
-	$fc =3 ;
75
-	foreach($custom_address_fields as $k=>$f) {
76
-		$worksheet->write($lineCount, $fc, $k);
71
+	$worksheet->write ($lineCount, 0, _ ('Name'));
72
+	$worksheet->write ($lineCount, 1, _ ('RD'));
73
+	$worksheet->write ($lineCount, 2, _ ('Description'));
74
+	$fc = 3;
75
+	foreach ($custom_address_fields as $k=>$f) {
76
+		$worksheet->write ($lineCount, $fc, $k);
77 77
 		$fc++;
78 78
 	}
79 79
 }
80
-elseif ($type == 'vlans'){
80
+elseif ($type == 'vlans') {
81 81
 	//get all custom fields!
82
-	$custom_address_fields = $Tools->fetch_custom_fields('vlans');
82
+	$custom_address_fields = $Tools->fetch_custom_fields ('vlans');
83 83
 	// set headers
84
-	$worksheet->write($lineCount, 0, _('Name'));
85
-	$worksheet->write($lineCount, 1, _('Number'));
86
-	$worksheet->write($lineCount, 2, _('Description'));
87
-	$worksheet->write($lineCount, 3, _('Domain name'));
88
-	$fc =4 ;
89
-	foreach($custom_address_fields as $k=>$f) {
90
-		$worksheet->write($lineCount, $fc, $k);
84
+	$worksheet->write ($lineCount, 0, _ ('Name'));
85
+	$worksheet->write ($lineCount, 1, _ ('Number'));
86
+	$worksheet->write ($lineCount, 2, _ ('Description'));
87
+	$worksheet->write ($lineCount, 3, _ ('Domain name'));
88
+	$fc = 4;
89
+	foreach ($custom_address_fields as $k=>$f) {
90
+		$worksheet->write ($lineCount, $fc, $k);
91 91
 		$fc++;
92 92
 	}
93 93
 }
94
-elseif ($type == 'l2dom'){
94
+elseif ($type == 'l2dom') {
95 95
 	// set headers
96
-	$worksheet->write($lineCount, 0, _('Name'));
97
-	$worksheet->write($lineCount, 1, _('Description'));
98
-	$fc =2 ;
96
+	$worksheet->write ($lineCount, 0, _ ('Name'));
97
+	$worksheet->write ($lineCount, 1, _ ('Description'));
98
+	$fc = 2;
99 99
 }
100 100
 // sending HTTP headers
101
-$workbook->send($filename);
101
+$workbook->send ($filename);
102 102
 // Let's send the file
103
-$workbook->close();
103
+$workbook->close ();
104 104
 ?>
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr-preview.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -5,15 +5,15 @@  discard block
 block discarded – undo
5 5
  ************************************/
6 6
 
7 7
 # include required scripts
8
-require( dirname(__FILE__) . '/../../../functions/functions.php' );
8
+require(dirname (__FILE__).'/../../../functions/functions.php');
9 9
 
10 10
 # initialize required objects
11
-$Database 	= new Database_PDO;
12
-$Result		= new Result;
13
-$User		= new User ($Database);
11
+$Database = new Database_PDO;
12
+$Result = new Result;
13
+$User = new User ($Database);
14 14
 
15 15
 # verify that user is logged in
16
-$User->check_user_session();
16
+$User->check_user_session ();
17 17
 
18 18
 # load data from uploaded file
19 19
 include 'import-load-data.php';
@@ -23,26 +23,26 @@  discard block
 block discarded – undo
23 23
 ?>
24 24
 
25 25
 <!-- header -->
26
-<div class="pHeader"><?php print _("IP Addresses import data preview"); ?></div>
26
+<div class="pHeader"><?php print _ ("IP Addresses import data preview"); ?></div>
27 27
 
28 28
 <!-- content -->
29 29
 <div class="pContent">
30 30
 <?php
31 31
 
32
-print '<h4>'._("Uploaded data").'</h4><hr>';
33
-print _("The entries marked with ")."<i class='fa ".$icons['add']."'></i>, "._("will be added,
34
-	the ones marked with ")."<i class='fa ".$icons['edit']."'></i>, "._("will be updated
35
-	and the ones marked with ")."<i class='fa ".$icons['skip']."'></i> "._("will be skipped.");
32
+print '<h4>'._ ("Uploaded data").'</h4><hr>';
33
+print _ ("The entries marked with ")."<i class='fa ".$icons['add']."'></i>, "._ ("will be added,
34
+	the ones marked with ")."<i class='fa ".$icons['edit']."'></i>, "._ ("will be updated
35
+	and the ones marked with ")."<i class='fa ".$icons['skip']."'></i> "._ ("will be skipped.");
36 36
 	
37
-print "<b>"._("Summary: ")."</b>".($counters['add'] > 0 ? $counters['add'] : "no")._(" new entries.
38
-		").($counters['edit'] > 0 ? $counters['edit'] : "no")._(" updated entries.
39
-		").($counters['error'] > 0 ? $counters['error'] : "no")._(" entries skipped due to errors.
40
-		").($counters['skip'] > 0 ? $counters['skip'] : "no")._(" duplicate entries.
41
-		")._("Scroll down for details.");
37
+print "<b>"._ ("Summary: ")."</b>".($counters['add'] > 0 ? $counters['add'] : "no")._ (" new entries.
38
+		").($counters['edit'] > 0 ? $counters['edit'] : "no")._ (" updated entries.
39
+		").($counters['error'] > 0 ? $counters['error'] : "no")._ (" entries skipped due to errors.
40
+		").($counters['skip'] > 0 ? $counters['skip'] : "no")._ (" duplicate entries.
41
+		")._ ("Scroll down for details.");
42 42
 
43 43
 print "<form id='selectImportFields'>";
44
-print "<input name='expfields' type='hidden' value='".implode('|',$expfields)."' style='display:none;'>";
45
-print "<input name='reqfields' type='hidden' value='".implode('|',$reqfields)."' style='display:none;'>";
44
+print "<input name='expfields' type='hidden' value='".implode ('|', $expfields)."' style='display:none;'>";
45
+print "<input name='reqfields' type='hidden' value='".implode ('|', $reqfields)."' style='display:none;'>";
46 46
 print $hiddenfields;
47 47
 print "<input name='filetype' id='filetype' type='hidden' value='".$filetype."' style='display:none;'>";
48 48
 print "</form>";
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 <!-- footer -->
60 60
 <div class="pFooter">
61 61
 	<div class="btn-group">
62
-		<button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button>
63
-		<button class="btn btn-sm btn-default" id="dataImportSubmit" data-type="ipaddr" disabled><i class="fa fa-upload"></i> <?php print _('Import'); ?></button>
62
+		<button class="btn btn-sm btn-default hidePopups"><?php print _ ('Cancel'); ?></button>
63
+		<button class="btn btn-sm btn-default" id="dataImportSubmit" data-type="ipaddr" disabled><i class="fa fa-upload"></i> <?php print _ ('Import'); ?></button>
64 64
 	</div>
65 65
 </div>
66 66
 
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr-check.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 # process for easier later check
35 35
 $vrf_data = array();
36 36
 foreach ($all_vrfs as $vrf) {
37
-	//cast
38
-	$vrf = (array) $vrf;
39
-	$vrf_data[$vrf['name']] = $vrf;
40
-	$vrf_data[$vrf['rd']] = $vrf;	# add also RD as VRF name, will allow matches against both name and RD
37
+    //cast
38
+    $vrf = (array) $vrf;
39
+    $vrf_data[$vrf['name']] = $vrf;
40
+    $vrf_data[$vrf['rd']] = $vrf;	# add also RD as VRF name, will allow matches against both name and RD
41 41
 }
42 42
 
43 43
 # fetch all sections and load all subnets
@@ -49,41 +49,41 @@  discard block
 block discarded – undo
49 49
 $subnet_data = array();
50 50
 
51 51
 foreach ($all_sections as $section) {
52
-	$section = (array) $section;
53
-	$section_names[strtolower($section['name'])] = $section;
52
+    $section = (array) $section;
53
+    $section_names[strtolower($section['name'])] = $section;
54 54
 
55
-	# skip sections we're not importing for, so we save cpu time and memory
56
-	if (!isset($used_section[strtolower($section['name'])])) { continue; }
55
+    # skip sections we're not importing for, so we save cpu time and memory
56
+    if (!isset($used_section[strtolower($section['name'])])) { continue; }
57 57
 
58
-	$section_subnets = $Subnets->fetch_section_subnets($section['id']);
58
+    $section_subnets = $Subnets->fetch_section_subnets($section['id']);
59 59
 
60
-	# skip empty sections
61
-	if (sizeof($section_subnets)==0) { continue; }
60
+    # skip empty sections
61
+    if (sizeof($section_subnets)==0) { continue; }
62 62
 	
63
-	foreach ($section_subnets as $subnet) {
64
-		$subnet = (array) $subnet;
63
+    foreach ($section_subnets as $subnet) {
64
+        $subnet = (array) $subnet;
65 65
 
66
-		# ignore folders
67
-		if($subnet['isFolder']) { continue; }
66
+        # ignore folders
67
+        if($subnet['isFolder']) { continue; }
68 68
 
69
-		# store needed subnet information
70
-		$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet;
71
-		$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']);
69
+        # store needed subnet information
70
+        $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet;
71
+        $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']);
72 72
 		
73
-		# grab IP addresses
74
-		$ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
73
+        # grab IP addresses
74
+        $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
75 75
 
76
-		if (sizeof($ipaddresses)==0) { continue; }
76
+        if (sizeof($ipaddresses)==0) { continue; }
77 77
 
78
-		foreach ($ipaddresses as $ip) {
78
+        foreach ($ipaddresses as $ip) {
79 79
 
80
-			//cast
81
-			$ip = (array) $ip;
80
+            //cast
81
+            $ip = (array) $ip;
82 82
 
83
-			$edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip;
83
+            $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip;
84 84
 
85
-		}
86
-	}
85
+        }
86
+    }
87 87
 }
88 88
 
89 89
 # Load available tags
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
 $device_data = array();
95 95
 $devices = $Tools->fetch_all_objects("devices", "hostname");
96 96
 if ($devices!==false) {
97
-	foreach($devices as $c_dev) {
98
-		$c_dev = (array) $c_dev;
99
-		$c_dev_sections=explode(";", $c_dev['sections']);
100
-		# Populate each section with the devices it has
101
-		foreach($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev;}
102
-	}
97
+    foreach($devices as $c_dev) {
98
+        $c_dev = (array) $c_dev;
99
+        $c_dev_sections=explode(";", $c_dev['sections']);
100
+        # Populate each section with the devices it has
101
+        foreach($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev;}
102
+    }
103 103
 }
104 104
 
105 105
 $rows = "";
@@ -108,156 +108,156 @@  discard block
 block discarded – undo
108 108
 
109 109
 # check the fields
110 110
 foreach ($data as &$cdata) {
111
-	$msg = ""; $action = ""; $cfieldtds = "";
112
-
113
-	# check if required fields are present and not empty
114
-	foreach($reqfields as $creq) {
115
-		if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; }
116
-	}
117
-
118
-	# if the subnet contains "/", split it in network and mask
119
-	if ($action != "error") {
120
-		if (preg_match("/\//", $cdata['subnet'])) {
121
-			list($caddr,$cmask) = explode("/",$cdata['subnet'],2);
122
-			$cdata['mask'] = $cmask;
123
-			$cdata['subnet'] = $caddr;
124
-		} 
125
-		else { $msg.= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; }
126
-		if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) {
127
-			$msg.="Invalid network mask format."; $action = "error";
128
-		} else {
129
-			$cdata['type'] = $Subnets->identify_address($cdata['subnet']);
130
-			if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; }
131
-		}
132
-	}
133
-
134
-	# Check if section is provided and valid and link it if it is
135
-	if (!isset($section_names[strtolower($cdata['section'])])) {
136
-		$msg.= "Invalid section."; $action = "error";
137
-	} else {
138
-		$cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id'];
139
-	}
140
-
141
-	# Check if VRF is provided and valid and link it if it is
142
-	if (!empty($cdata['vrf'])) {
143
-		if (!isset($vrf_data[$cdata['vrf']])) {
144
-			$msg.= "Invalid VRF."; $action = "error";
145
-		} else {
146
-			$cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId'];
147
-		}
148
-	} else {
149
-		# no VRF provided, using default
150
-		$cdata['vrfId'] = 0;
151
-	}
152
-
153
-	# Check if Subnet is provided and valid and link it if it is
154
-	if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) {
155
-		if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) {
156
-			$msg.= "Invalid Subnet."; $action = "error";
157
-		} else {
158
-			$cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id'];
159
-		}
160
-	} else {
161
-		# no subnet provided, search not implemented yet, giving out error.
162
-		$msg.= "Subnet/Mask not provided."; $action = "error";
163
-	}
164
-
165
-	# Match device name against device IDs
166
-	if (!empty($cdata['device'])) {
167
-		if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) {
168
-			$msg.= "Invalid device hostname."; $action = "error";
169
-		} else {
170
-			$cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id'];
171
-		}
172
-	} else {
173
-		$cdata['switch'] = 0;
174
-	}
175
-
176
-	# Check if a tag is provided and valid and link it if it is
177
-	if (!empty($cdata['tag'])) {
178
-		if (!isset($tag_data[$cdata['tag']])) {
179
-			$msg.= "Invalid tag."; $action = "error";
180
-		} else {
181
-			$cdata['state'] = $tag_data[$cdata['tag']]['id'];
182
-		}
183
-	} else {
184
-		# no tag provided, using default
185
-		$cdata['state'] = 2;
186
-	}
111
+    $msg = ""; $action = ""; $cfieldtds = "";
112
+
113
+    # check if required fields are present and not empty
114
+    foreach($reqfields as $creq) {
115
+        if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; }
116
+    }
117
+
118
+    # if the subnet contains "/", split it in network and mask
119
+    if ($action != "error") {
120
+        if (preg_match("/\//", $cdata['subnet'])) {
121
+            list($caddr,$cmask) = explode("/",$cdata['subnet'],2);
122
+            $cdata['mask'] = $cmask;
123
+            $cdata['subnet'] = $caddr;
124
+        } 
125
+        else { $msg.= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; }
126
+        if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) {
127
+            $msg.="Invalid network mask format."; $action = "error";
128
+        } else {
129
+            $cdata['type'] = $Subnets->identify_address($cdata['subnet']);
130
+            if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; }
131
+        }
132
+    }
133
+
134
+    # Check if section is provided and valid and link it if it is
135
+    if (!isset($section_names[strtolower($cdata['section'])])) {
136
+        $msg.= "Invalid section."; $action = "error";
137
+    } else {
138
+        $cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id'];
139
+    }
140
+
141
+    # Check if VRF is provided and valid and link it if it is
142
+    if (!empty($cdata['vrf'])) {
143
+        if (!isset($vrf_data[$cdata['vrf']])) {
144
+            $msg.= "Invalid VRF."; $action = "error";
145
+        } else {
146
+            $cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId'];
147
+        }
148
+    } else {
149
+        # no VRF provided, using default
150
+        $cdata['vrfId'] = 0;
151
+    }
152
+
153
+    # Check if Subnet is provided and valid and link it if it is
154
+    if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) {
155
+        if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) {
156
+            $msg.= "Invalid Subnet."; $action = "error";
157
+        } else {
158
+            $cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id'];
159
+        }
160
+    } else {
161
+        # no subnet provided, search not implemented yet, giving out error.
162
+        $msg.= "Subnet/Mask not provided."; $action = "error";
163
+    }
164
+
165
+    # Match device name against device IDs
166
+    if (!empty($cdata['device'])) {
167
+        if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) {
168
+            $msg.= "Invalid device hostname."; $action = "error";
169
+        } else {
170
+            $cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id'];
171
+        }
172
+    } else {
173
+        $cdata['switch'] = 0;
174
+    }
175
+
176
+    # Check if a tag is provided and valid and link it if it is
177
+    if (!empty($cdata['tag'])) {
178
+        if (!isset($tag_data[$cdata['tag']])) {
179
+            $msg.= "Invalid tag."; $action = "error";
180
+        } else {
181
+            $cdata['state'] = $tag_data[$cdata['tag']]['id'];
182
+        }
183
+    } else {
184
+        # no tag provided, using default
185
+        $cdata['state'] = 2;
186
+    }
187 187
 
188 188
 	
189
-	# Verify gateway
190
-	if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; }
189
+    # Verify gateway
190
+    if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; }
191 191
 	
192
-	if ($action != "error") {
193
-    	if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; }
194
-		if ((!empty($cdata['dns_name'])) and (!preg_match("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg.="Invalid DNS name."; $action = "error"; }
195
-		if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; }
196
-		if ($cdata['mac']) {
197
-			if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; }
198
-		}
199
-		if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; }
200
-		if (preg_match("/[;'\"]/", $cdata['note'])) { $msg.="Invalid characters in note."; $action = "error"; }
201
-	}
202
-
203
-	# check if duplicate in the import data
204
-	if ($action != "error") {
205
-		if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; }
206
-	}
207
-
208
-	# check if existing in database
209
-	if ($action != "error") {
210
-		if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) {
211
-			# copy content to a variable for easier checks
212
-			$cedata = $edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']];
213
-
214
-			# Check if we need to change any fields
215
-			$action = "skip"; # skip duplicate fields if identical, update if different
216
-			if ($cdata['dns_name'] != $cedata['dns_name']) { $msg.= "Address DNS name will be updated."; $action = "edit"; }
217
-			if ($cdata['description'] != $cedata['description']) { $msg.= "Address description will be updated."; $action = "edit"; }
218
-			if ($cdata['mac'] != $cedata['mac']) { $msg.= "Address MAC address will be updated."; $action = "edit"; }
219
-			if ($cdata['owner'] != $cedata['owner']) { $msg.= "Address owner will be updated."; $action = "edit"; }
220
-			if ($cdata['switch'] != $cedata['switch']) { $msg.= "Device will be updated."; $action = "edit"; }
221
-			if ($cdata['note'] != $cedata['note']) { $msg.= "Address note will be updated."; $action = "edit"; }
222
-			if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; }
223
-
224
-			# Check if the values of the custom fields have changed
225
-			if(sizeof($custom_fields) > 0) {
226
-				foreach($custom_fields as $myField) {
227
-					if ($cdata[$myField['name']] != $cedata[$myField['name']]) {
228
-						$msg.= $myField['name']." will be updated."; $action = "edit";
229
-					}
230
-				}
231
-			}
232
-
233
-			if ($action == "skip") {
234
-				$msg.= "Duplicate, will skip.";
235
-			} else {
236
-				# set id of matched subnet
237
-				$cdata['id'] = $cedata['id'];
238
-				# copy some fields which we don't import, but need to set
192
+    if ($action != "error") {
193
+        if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; }
194
+        if ((!empty($cdata['dns_name'])) and (!preg_match("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg.="Invalid DNS name."; $action = "error"; }
195
+        if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; }
196
+        if ($cdata['mac']) {
197
+            if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; }
198
+        }
199
+        if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; }
200
+        if (preg_match("/[;'\"]/", $cdata['note'])) { $msg.="Invalid characters in note."; $action = "error"; }
201
+    }
202
+
203
+    # check if duplicate in the import data
204
+    if ($action != "error") {
205
+        if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; }
206
+    }
207
+
208
+    # check if existing in database
209
+    if ($action != "error") {
210
+        if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) {
211
+            # copy content to a variable for easier checks
212
+            $cedata = $edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']];
213
+
214
+            # Check if we need to change any fields
215
+            $action = "skip"; # skip duplicate fields if identical, update if different
216
+            if ($cdata['dns_name'] != $cedata['dns_name']) { $msg.= "Address DNS name will be updated."; $action = "edit"; }
217
+            if ($cdata['description'] != $cedata['description']) { $msg.= "Address description will be updated."; $action = "edit"; }
218
+            if ($cdata['mac'] != $cedata['mac']) { $msg.= "Address MAC address will be updated."; $action = "edit"; }
219
+            if ($cdata['owner'] != $cedata['owner']) { $msg.= "Address owner will be updated."; $action = "edit"; }
220
+            if ($cdata['switch'] != $cedata['switch']) { $msg.= "Device will be updated."; $action = "edit"; }
221
+            if ($cdata['note'] != $cedata['note']) { $msg.= "Address note will be updated."; $action = "edit"; }
222
+            if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; }
223
+
224
+            # Check if the values of the custom fields have changed
225
+            if(sizeof($custom_fields) > 0) {
226
+                foreach($custom_fields as $myField) {
227
+                    if ($cdata[$myField['name']] != $cedata[$myField['name']]) {
228
+                        $msg.= $myField['name']." will be updated."; $action = "edit";
229
+                    }
230
+                }
231
+            }
232
+
233
+            if ($action == "skip") {
234
+                $msg.= "Duplicate, will skip.";
235
+            } else {
236
+                # set id of matched subnet
237
+                $cdata['id'] = $cedata['id'];
238
+                # copy some fields which we don't import, but need to set
239 239
 // 				$cdata['port'] = $cedata['port'];		$cdata['lastseen'] = $cedata['lastseen'];
240 240
 // 				$cdata['excludePing'] = $cedata['excludePing'];
241 241
 // 				$cdata['PTRignore'] = $cedata['PTRignore']; $cdata['PTR'] = $cedata['PTR']; $cdata['NAT'] = $cedata['NAT'];
242 242
 // 				$cdata['firewallAddressObject'] = $cedata['firewallAddressObject'];
243
-			}
244
-		} else {
245
-			$msg.="New entry, will be added."; $action = "add";
243
+            }
244
+        } else {
245
+            $msg.="New entry, will be added."; $action = "add";
246 246
 
247
-			# Add it to ndata for duplicate check
248
-			$ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']] = $cdata;
249
-		}
250
-	}
247
+            # Add it to ndata for duplicate check
248
+            $ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']] = $cdata;
249
+        }
250
+    }
251 251
 
252
-	$cdata['msg'].= $msg;
253
-	$cdata['action'] = $action;
254
-	$counters[$action]++;
252
+    $cdata['msg'].= $msg;
253
+    $cdata['action'] = $action;
254
+    $counters[$action]++;
255 255
 
256
-	$cdata['subnet'] = $cdata['subnet']."/".$cdata['mask'];
256
+    $cdata['subnet'] = $cdata['subnet']."/".$cdata['mask'];
257 257
 
258
-	$rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
259
-	foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
260
-	$rows.= "<td>"._($cdata['msg'])."</td></tr>";
258
+    $rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
259
+    foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
260
+    $rows.= "<td>"._($cdata['msg'])."</td></tr>";
261 261
 
262 262
 }
263 263
 
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -5,143 +5,143 @@  discard block
 block discarded – undo
5 5
  *************************************************/
6 6
 
7 7
 # include required scripts
8
-require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
8
+require_once(dirname (__FILE__).'/../../../functions/functions.php');
9 9
 
10 10
 # initialize user object, if not already set
11
-if (!isset($Database)) { $Database 	= new Database_PDO; }
11
+if (!isset($Database)) { $Database = new Database_PDO; }
12 12
 if (!isset($User)) { $User = new User ($Database); }
13 13
 if (!isset($Admin)) { $Admin = new Admin ($Database); }
14 14
 if (!isset($Tools)) { $Tools = new Tools ($Database); }
15
-if (!isset($Sections)) { $Sections	= new Sections ($Database); }
15
+if (!isset($Sections)) { $Sections = new Sections ($Database); }
16 16
 if (!isset($Addresses)) { $Addresses = new Addresses ($Database); }
17 17
 if (!isset($Subnets)) { $Subnets = new Subnets ($Database); }
18 18
 
19 19
 # verify that user is logged in, to guard against direct access of page and possible exploits
20
-$User->check_user_session();
20
+$User->check_user_session ();
21 21
 
22 22
 # read again the custom fields, if any
23
-if (!isset($custom_fields)) { $custom_fields = $Tools->fetch_custom_fields("ipaddresses"); }
23
+if (!isset($custom_fields)) { $custom_fields = $Tools->fetch_custom_fields ("ipaddresses"); }
24 24
 
25 25
 # check which sections we need to care about
26
-$used_section = array();
27
-foreach ($data as &$cdata) { $used_section[strtolower($cdata['section'])]=$cdata['section']; }
26
+$used_section = array ();
27
+foreach ($data as &$cdata) { $used_section[strtolower ($cdata['section'])] = $cdata['section']; }
28 28
 
29 29
 # fetch all VRFs
30
-$all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
31
-if (!$all_vrfs) { $all_vrfs = array(); }
30
+$all_vrfs = $Admin->fetch_all_objects ("vrf", "vrfId");
31
+if (!$all_vrfs) { $all_vrfs = array (); }
32 32
 # insert default VRF in the list
33
-array_splice($all_vrfs,0,0,(object) array(array('vrfId' => '0', 'name' => 'default', 'rd' => '0:0')));
33
+array_splice ($all_vrfs, 0, 0, (object) array (array ('vrfId' => '0', 'name' => 'default', 'rd' => '0:0')));
34 34
 # process for easier later check
35
-$vrf_data = array();
35
+$vrf_data = array ();
36 36
 foreach ($all_vrfs as $vrf) {
37 37
 	//cast
38 38
 	$vrf = (array) $vrf;
39 39
 	$vrf_data[$vrf['name']] = $vrf;
40
-	$vrf_data[$vrf['rd']] = $vrf;	# add also RD as VRF name, will allow matches against both name and RD
40
+	$vrf_data[$vrf['rd']] = $vrf; # add also RD as VRF name, will allow matches against both name and RD
41 41
 }
42 42
 
43 43
 # fetch all sections and load all subnets
44
-$all_sections = $Sections->fetch_all_sections();
44
+$all_sections = $Sections->fetch_all_sections ();
45 45
 
46 46
 # get all addresses in all subnets in all sections 
47
-$edata = array(); 
48
-$section_names = array(); 
49
-$subnet_data = array();
47
+$edata = array (); 
48
+$section_names = array (); 
49
+$subnet_data = array ();
50 50
 
51 51
 foreach ($all_sections as $section) {
52 52
 	$section = (array) $section;
53
-	$section_names[strtolower($section['name'])] = $section;
53
+	$section_names[strtolower ($section['name'])] = $section;
54 54
 
55 55
 	# skip sections we're not importing for, so we save cpu time and memory
56
-	if (!isset($used_section[strtolower($section['name'])])) { continue; }
56
+	if (!isset($used_section[strtolower ($section['name'])])) { continue; }
57 57
 
58
-	$section_subnets = $Subnets->fetch_section_subnets($section['id']);
58
+	$section_subnets = $Subnets->fetch_section_subnets ($section['id']);
59 59
 
60 60
 	# skip empty sections
61
-	if (sizeof($section_subnets)==0) { continue; }
61
+	if (sizeof ($section_subnets) == 0) { continue; }
62 62
 	
63 63
 	foreach ($section_subnets as $subnet) {
64 64
 		$subnet = (array) $subnet;
65 65
 
66 66
 		# ignore folders
67
-		if($subnet['isFolder']) { continue; }
67
+		if ($subnet['isFolder']) { continue; }
68 68
 
69 69
 		# store needed subnet information
70 70
 		$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet;
71
-		$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']);
71
+		$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address ($subnet['ip']);
72 72
 		
73 73
 		# grab IP addresses
74 74
 		$ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']);
75 75
 
76
-		if (sizeof($ipaddresses)==0) { continue; }
76
+		if (sizeof ($ipaddresses) == 0) { continue; }
77 77
 
78 78
 		foreach ($ipaddresses as $ip) {
79 79
 
80 80
 			//cast
81 81
 			$ip = (array) $ip;
82 82
 
83
-			$edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip;
83
+			$edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address ($ip['ip_addr'], "dotted")] = $ip;
84 84
 
85 85
 		}
86 86
 	}
87 87
 }
88 88
 
89 89
 # Load available tags
90
-$tag_data = array(); $ip_tags = (array) $Addresses->addresses_types_fetch();
90
+$tag_data = array (); $ip_tags = (array) $Addresses->addresses_types_fetch ();
91 91
 foreach ($ip_tags as $c_tag) { $tag_data[$c_tag['type']] = $c_tag; }
92 92
 
93 93
 # Load available devices
94
-$device_data = array();
95
-$devices = $Tools->fetch_all_objects("devices", "hostname");
96
-if ($devices!==false) {
97
-	foreach($devices as $c_dev) {
94
+$device_data = array ();
95
+$devices = $Tools->fetch_all_objects ("devices", "hostname");
96
+if ($devices !== false) {
97
+	foreach ($devices as $c_dev) {
98 98
 		$c_dev = (array) $c_dev;
99
-		$c_dev_sections=explode(";", $c_dev['sections']);
99
+		$c_dev_sections = explode (";", $c_dev['sections']);
100 100
 		# Populate each section with the devices it has
101
-		foreach($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev;}
101
+		foreach ($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev; }
102 102
 	}
103 103
 }
104 104
 
105 105
 $rows = "";
106
-$counters = array();
107
-$ndata = array(); # store new addresses in a similar format with edata for easier processing
106
+$counters = array ();
107
+$ndata = array (); # store new addresses in a similar format with edata for easier processing
108 108
 
109 109
 # check the fields
110 110
 foreach ($data as &$cdata) {
111 111
 	$msg = ""; $action = ""; $cfieldtds = "";
112 112
 
113 113
 	# check if required fields are present and not empty
114
-	foreach($reqfields as $creq) {
115
-		if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; }
114
+	foreach ($reqfields as $creq) {
115
+		if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg .= "Required field ".$creq." missing or empty."; $action = "error"; }
116 116
 	}
117 117
 
118 118
 	# if the subnet contains "/", split it in network and mask
119 119
 	if ($action != "error") {
120
-		if (preg_match("/\//", $cdata['subnet'])) {
121
-			list($caddr,$cmask) = explode("/",$cdata['subnet'],2);
120
+		if (preg_match ("/\//", $cdata['subnet'])) {
121
+			list($caddr, $cmask) = explode ("/", $cdata['subnet'], 2);
122 122
 			$cdata['mask'] = $cmask;
123 123
 			$cdata['subnet'] = $caddr;
124 124
 		} 
125
-		else { $msg.= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; }
126
-		if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) {
127
-			$msg.="Invalid network mask format."; $action = "error";
125
+		else { $msg .= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; }
126
+		if ((!empty($cdata['mask'])) && (!preg_match ("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) {
127
+			$msg .= "Invalid network mask format."; $action = "error";
128 128
 		} else {
129
-			$cdata['type'] = $Subnets->identify_address($cdata['subnet']);
130
-			if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; }
129
+			$cdata['type'] = $Subnets->identify_address ($cdata['subnet']);
130
+			if (($cdata['type'] == "IPv6") && (($cdata['mask'] < 0) || ($cdata['mask'] > 128))) { $msg .= "Invalid IPv6 network mask."; $action = "error"; }
131 131
 		}
132 132
 	}
133 133
 
134 134
 	# Check if section is provided and valid and link it if it is
135
-	if (!isset($section_names[strtolower($cdata['section'])])) {
136
-		$msg.= "Invalid section."; $action = "error";
135
+	if (!isset($section_names[strtolower ($cdata['section'])])) {
136
+		$msg .= "Invalid section."; $action = "error";
137 137
 	} else {
138
-		$cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id'];
138
+		$cdata['sectionId'] = $section_names[strtolower ($cdata['section'])]['id'];
139 139
 	}
140 140
 
141 141
 	# Check if VRF is provided and valid and link it if it is
142 142
 	if (!empty($cdata['vrf'])) {
143 143
 		if (!isset($vrf_data[$cdata['vrf']])) {
144
-			$msg.= "Invalid VRF."; $action = "error";
144
+			$msg .= "Invalid VRF."; $action = "error";
145 145
 		} else {
146 146
 			$cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId'];
147 147
 		}
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
 	# Check if Subnet is provided and valid and link it if it is
154 154
 	if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) {
155 155
 		if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) {
156
-			$msg.= "Invalid Subnet."; $action = "error";
156
+			$msg .= "Invalid Subnet."; $action = "error";
157 157
 		} else {
158 158
 			$cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id'];
159 159
 		}
160 160
 	} else {
161 161
 		# no subnet provided, search not implemented yet, giving out error.
162
-		$msg.= "Subnet/Mask not provided."; $action = "error";
162
+		$msg .= "Subnet/Mask not provided."; $action = "error";
163 163
 	}
164 164
 
165 165
 	# Match device name against device IDs
166 166
 	if (!empty($cdata['device'])) {
167 167
 		if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) {
168
-			$msg.= "Invalid device hostname."; $action = "error";
168
+			$msg .= "Invalid device hostname."; $action = "error";
169 169
 		} else {
170 170
 			$cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id'];
171 171
 		}
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	# Check if a tag is provided and valid and link it if it is
177 177
 	if (!empty($cdata['tag'])) {
178 178
 		if (!isset($tag_data[$cdata['tag']])) {
179
-			$msg.= "Invalid tag."; $action = "error";
179
+			$msg .= "Invalid tag."; $action = "error";
180 180
 		} else {
181 181
 			$cdata['state'] = $tag_data[$cdata['tag']]['id'];
182 182
 		}
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
 
188 188
 	
189 189
 	# Verify gateway
190
-	if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; }
190
+	if (in_array (strtolower ($cdata['is_gateway']), array ("yes", "true", "1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; }
191 191
 	
192 192
 	if ($action != "error") {
193
-    	if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; }
194
-		if ((!empty($cdata['dns_name'])) and (!preg_match("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg.="Invalid DNS name."; $action = "error"; }
195
-		if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; }
193
+    	if (!$Addresses->validate_ip ($cdata['ip_addr'])) { $msg .= "Invalid IP address."; $action = "error"; }
194
+		if ((!empty($cdata['dns_name'])) and (!preg_match ("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg .= "Invalid DNS name."; $action = "error"; }
195
+		if (preg_match ("/[;'\"]/", $cdata['description'])) { $msg .= "Invalid characters in description."; $action = "error"; }
196 196
 		if ($cdata['mac']) {
197
-			if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; }
197
+			if (!preg_match ("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg .= "Invalid MAC address."; $action = "error"; }
198 198
 		}
199
-		if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; }
200
-		if (preg_match("/[;'\"]/", $cdata['note'])) { $msg.="Invalid characters in note."; $action = "error"; }
199
+		if (preg_match ("/[;'\"]/", $cdata['owner'])) { $msg .= "Invalid characters in owner name."; $action = "error"; }
200
+		if (preg_match ("/[;'\"]/", $cdata['note'])) { $msg .= "Invalid characters in note."; $action = "error"; }
201 201
 	}
202 202
 
203 203
 	# check if duplicate in the import data
204 204
 	if ($action != "error") {
205
-		if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; }
205
+		if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg .= "Duplicate entry in imported data."; $action = "error"; }
206 206
 	}
207 207
 
208 208
 	# check if existing in database
@@ -213,25 +213,25 @@  discard block
 block discarded – undo
213 213
 
214 214
 			# Check if we need to change any fields
215 215
 			$action = "skip"; # skip duplicate fields if identical, update if different
216
-			if ($cdata['dns_name'] != $cedata['dns_name']) { $msg.= "Address DNS name will be updated."; $action = "edit"; }
217
-			if ($cdata['description'] != $cedata['description']) { $msg.= "Address description will be updated."; $action = "edit"; }
218
-			if ($cdata['mac'] != $cedata['mac']) { $msg.= "Address MAC address will be updated."; $action = "edit"; }
219
-			if ($cdata['owner'] != $cedata['owner']) { $msg.= "Address owner will be updated."; $action = "edit"; }
220
-			if ($cdata['switch'] != $cedata['switch']) { $msg.= "Device will be updated."; $action = "edit"; }
221
-			if ($cdata['note'] != $cedata['note']) { $msg.= "Address note will be updated."; $action = "edit"; }
222
-			if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; }
216
+			if ($cdata['dns_name'] != $cedata['dns_name']) { $msg .= "Address DNS name will be updated."; $action = "edit"; }
217
+			if ($cdata['description'] != $cedata['description']) { $msg .= "Address description will be updated."; $action = "edit"; }
218
+			if ($cdata['mac'] != $cedata['mac']) { $msg .= "Address MAC address will be updated."; $action = "edit"; }
219
+			if ($cdata['owner'] != $cedata['owner']) { $msg .= "Address owner will be updated."; $action = "edit"; }
220
+			if ($cdata['switch'] != $cedata['switch']) { $msg .= "Device will be updated."; $action = "edit"; }
221
+			if ($cdata['note'] != $cedata['note']) { $msg .= "Address note will be updated."; $action = "edit"; }
222
+			if ($cdata['state'] != $cedata['state']) { $msg .= "Address tag (state) will be updated."; $action = "edit"; }
223 223
 
224 224
 			# Check if the values of the custom fields have changed
225
-			if(sizeof($custom_fields) > 0) {
226
-				foreach($custom_fields as $myField) {
225
+			if (sizeof ($custom_fields) > 0) {
226
+				foreach ($custom_fields as $myField) {
227 227
 					if ($cdata[$myField['name']] != $cedata[$myField['name']]) {
228
-						$msg.= $myField['name']." will be updated."; $action = "edit";
228
+						$msg .= $myField['name']." will be updated."; $action = "edit";
229 229
 					}
230 230
 				}
231 231
 			}
232 232
 
233 233
 			if ($action == "skip") {
234
-				$msg.= "Duplicate, will skip.";
234
+				$msg .= "Duplicate, will skip.";
235 235
 			} else {
236 236
 				# set id of matched subnet
237 237
 				$cdata['id'] = $cedata['id'];
@@ -242,22 +242,22 @@  discard block
 block discarded – undo
242 242
 // 				$cdata['firewallAddressObject'] = $cedata['firewallAddressObject'];
243 243
 			}
244 244
 		} else {
245
-			$msg.="New entry, will be added."; $action = "add";
245
+			$msg .= "New entry, will be added."; $action = "add";
246 246
 
247 247
 			# Add it to ndata for duplicate check
248 248
 			$ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']] = $cdata;
249 249
 		}
250 250
 	}
251 251
 
252
-	$cdata['msg'].= $msg;
252
+	$cdata['msg'] .= $msg;
253 253
 	$cdata['action'] = $action;
254 254
 	$counters[$action]++;
255 255
 
256 256
 	$cdata['subnet'] = $cdata['subnet']."/".$cdata['mask'];
257 257
 
258
-	$rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
259
-	foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
260
-	$rows.= "<td>"._($cdata['msg'])."</td></tr>";
258
+	$rows .= "<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._ ($msg)."'></i></td>";
259
+	foreach ($expfields as $cfield) { $rows .= "<td>".$cdata[$cfield]."</td>"; }
260
+	$rows .= "<td>"._ ($cdata['msg'])."</td></tr>";
261 261
 
262 262
 }
263 263
 
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -33,45 +33,45 @@
 block discarded – undo
33 33
 
34 34
 # import IP Addresses
35 35
 foreach ($data as &$cdata) {
36
-	if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) {
37
-		// # set update array
38
-
39
-		$values = array("id"=>$cdata['id'],
40
-						"ip_addr"=>$Addresses->transform_address($cdata['ip_addr'],"decimal"),
41
-						"subnetId"=>$cdata['subnetId'],
42
-						"dns_name"=>$cdata['dns_name'],
43
-						"description"=>$cdata['description'],
44
-						"mac"=>$cdata['mac'],
45
-						"owner"=>$cdata['owner'],
46
-						"switch"=>$cdata['switch'],
47
-						"state"=>$cdata['state'],
48
-						"note"=>$cdata['note'],
49
-						"is_gateway"=>$cdata['is_gateway']
50
-						);
51
-
52
-		# add custom fields
53
-		if(sizeof($custom_fields) > 0) {
54
-			foreach($custom_fields as $myField) {
55
-				if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; }
56
-			}
57
-		}
58
-
59
-		# update
60
-		$cdata['result'] = $Admin->object_modify("ipaddresses", $cdata['action'], "id", $values);
61
-
62
-		if ($cdata['result']) {
63
-			$trc = $colors[$cdata['action']];
64
-			$msg = "IP Address ".$cdata['action']." successful.";
65
-		} else {
66
-			$trc = "danger";
67
-			$msg = "IP Address ".$cdata['action']." failed.";
68
-		}
69
-
70
-		$rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
71
-		foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
72
-		$rows.= "<td>"._($msg)."</td></tr>";
73
-
74
-	}
36
+    if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) {
37
+        // # set update array
38
+
39
+        $values = array("id"=>$cdata['id'],
40
+                        "ip_addr"=>$Addresses->transform_address($cdata['ip_addr'],"decimal"),
41
+                        "subnetId"=>$cdata['subnetId'],
42
+                        "dns_name"=>$cdata['dns_name'],
43
+                        "description"=>$cdata['description'],
44
+                        "mac"=>$cdata['mac'],
45
+                        "owner"=>$cdata['owner'],
46
+                        "switch"=>$cdata['switch'],
47
+                        "state"=>$cdata['state'],
48
+                        "note"=>$cdata['note'],
49
+                        "is_gateway"=>$cdata['is_gateway']
50
+                        );
51
+
52
+        # add custom fields
53
+        if(sizeof($custom_fields) > 0) {
54
+            foreach($custom_fields as $myField) {
55
+                if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; }
56
+            }
57
+        }
58
+
59
+        # update
60
+        $cdata['result'] = $Admin->object_modify("ipaddresses", $cdata['action'], "id", $values);
61
+
62
+        if ($cdata['result']) {
63
+            $trc = $colors[$cdata['action']];
64
+            $msg = "IP Address ".$cdata['action']." successful.";
65
+        } else {
66
+            $trc = "danger";
67
+            $msg = "IP Address ".$cdata['action']." failed.";
68
+        }
69
+
70
+        $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
71
+        foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
72
+        $rows.= "<td>"._($msg)."</td></tr>";
73
+
74
+    }
75 75
 }
76 76
 print "<table class='table table-condensed table-hover' id='resultstable'><tbody>";
77 77
 print "<tr class='active'>".$hrow."<th>Result</th></tr>";
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@  discard block
 block discarded – undo
4 4
  ************************************************/
5 5
 
6 6
 # include required scripts
7
-require( dirname(__FILE__) . '/../../../functions/functions.php' );
7
+require(dirname (__FILE__).'/../../../functions/functions.php');
8 8
 
9 9
 # initialize user object
10
-$Database 	= new Database_PDO;
10
+$Database = new Database_PDO;
11 11
 $User = new User ($Database);
12 12
 
13 13
 # verify that user is logged in, to guard against direct access of page and possible exploits
14
-$User->check_user_session();
14
+$User->check_user_session ();
15 15
 
16 16
 # load data from uploaded file
17 17
 include 'import-load-data.php';
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 ?>
22 22
 
23 23
 <!-- header -->
24
-<div class="pHeader"><?php print _("IP Addresses import"); ?></div>
24
+<div class="pHeader"><?php print _ ("IP Addresses import"); ?></div>
25 25
 
26 26
 <!-- content -->
27 27
 <div class="pContent">
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) {
37 37
 		// # set update array
38 38
 
39
-		$values = array("id"=>$cdata['id'],
40
-						"ip_addr"=>$Addresses->transform_address($cdata['ip_addr'],"decimal"),
39
+		$values = array ("id"=>$cdata['id'],
40
+						"ip_addr"=>$Addresses->transform_address ($cdata['ip_addr'], "decimal"),
41 41
 						"subnetId"=>$cdata['subnetId'],
42 42
 						"dns_name"=>$cdata['dns_name'],
43 43
 						"description"=>$cdata['description'],
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
 						);
51 51
 
52 52
 		# add custom fields
53
-		if(sizeof($custom_fields) > 0) {
54
-			foreach($custom_fields as $myField) {
55
-				if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; }
53
+		if (sizeof ($custom_fields) > 0) {
54
+			foreach ($custom_fields as $myField) {
55
+				if (isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; }
56 56
 			}
57 57
 		}
58 58
 
59 59
 		# update
60
-		$cdata['result'] = $Admin->object_modify("ipaddresses", $cdata['action'], "id", $values);
60
+		$cdata['result'] = $Admin->object_modify ("ipaddresses", $cdata['action'], "id", $values);
61 61
 
62 62
 		if ($cdata['result']) {
63 63
 			$trc = $colors[$cdata['action']];
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 			$msg = "IP Address ".$cdata['action']." failed.";
68 68
 		}
69 69
 
70
-		$rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
71
-		foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
72
-		$rows.= "<td>"._($msg)."</td></tr>";
70
+		$rows .= "<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._ ($msg)."'></i></td>";
71
+		foreach ($expfields as $cfield) { $rows .= "<td>".$cdata[$cfield]."</td>"; }
72
+		$rows .= "<td>"._ ($msg)."</td></tr>";
73 73
 
74 74
 	}
75 75
 }
@@ -83,5 +83,5 @@  discard block
 block discarded – undo
83 83
 
84 84
 <!-- footer -->
85 85
 <div class="pFooter">
86
-	<button class="btn btn-sm btn-default hidePopups"><?php print _('Close'); ?></button>
86
+	<button class="btn btn-sm btn-default hidePopups"><?php print _ ('Close'); ?></button>
87 87
 </div>
Please login to merge, or discard this patch.
app/admin/import-export/export-ipaddr-field-select.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -5,33 +5,33 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 # include required scripts
8
-require( dirname(__FILE__) . '/../../../functions/functions.php' );
8
+require(dirname (__FILE__).'/../../../functions/functions.php');
9 9
 
10 10
 # initialize user object
11
-$Database	= new Database_PDO;
12
-$User		= new User ($Database);
11
+$Database = new Database_PDO;
12
+$User = new User ($Database);
13 13
 $Admin		= new Admin ($Database);
14 14
 $Tools		= new Tools ($Database);
15
-$Sections	= new Sections ($Database);
15
+$Sections = new Sections ($Database);
16 16
 
17 17
 # verify that user is logged in
18
-$User->check_user_session();
18
+$User->check_user_session ();
19 19
 
20 20
 # Won't check per subnet/section rights since this is an admin section, where the admin user has full access
21 21
 
22 22
 # fetch all sections
23
-$all_sections = $Sections->fetch_all_sections();
23
+$all_sections = $Sections->fetch_all_sections ();
24 24
 
25 25
 # Lets do some reordering to show slaves!
26
-if($all_sections!==false) {
27
-	foreach($all_sections as $s) {
28
-		if($s->masterSection=="0") {
26
+if ($all_sections !== false) {
27
+	foreach ($all_sections as $s) {
28
+		if ($s->masterSection == "0") {
29 29
 			# it is master
30 30
 			$s->class = "master";
31 31
 			$sectionssorted[] = $s;
32 32
 			# check for slaves
33
-			foreach($all_sections as $ss) {
34
-				if($ss->masterSection==$s->id) {
33
+			foreach ($all_sections as $ss) {
34
+				if ($ss->masterSection == $s->id) {
35 35
 					$ss->class = "slave";
36 36
 					$sectionssorted[] = $ss;
37 37
 				}
@@ -43,24 +43,24 @@  discard block
 block discarded – undo
43 43
 }
44 44
 
45 45
 # get all custom fields
46
-$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
46
+$custom_fields = $Tools->fetch_custom_fields ('ipaddresses');
47 47
 # prepare HTML variables
48 48
 $custom_fields_names = "";
49 49
 $custom_fields_boxes = "";
50 50
 
51
-if(sizeof($custom_fields) > 0) {
52
-	foreach($custom_fields as $myField) {
51
+if (sizeof ($custom_fields) > 0) {
52
+	foreach ($custom_fields as $myField) {
53 53
 		//change spaces to "___" so it can be used as element id
54
-		$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
55
-		$custom_fields_names.= "	<th>$myField[name]</th>";
56
-		$custom_fields_boxes.= "	<td><input type='checkbox' name='$myField[nameTemp]' checked> </td>";
54
+		$myField['nameTemp'] = str_replace (" ", "___", $myField['name']);
55
+		$custom_fields_names .= "	<th>$myField[name]</th>";
56
+		$custom_fields_boxes .= "	<td><input type='checkbox' name='$myField[nameTemp]' checked> </td>";
57 57
 	}
58 58
 }
59 59
 
60 60
 ?>
61 61
 
62 62
 <!-- header -->
63
-<div class="pHeader"><?php print _("Select sections and IP address fields to export"); ?></div>
63
+<div class="pHeader"><?php print _ ("Select sections and IP address fields to export"); ?></div>
64 64
 
65 65
 <!-- content -->
66 66
 <div class="pContent">
@@ -74,25 +74,25 @@  discard block
 block discarded – undo
74 74
 print "	<table class='table table-striped table-condensed'>";
75 75
 
76 76
 print "	<tr>";
77
-print "	<th>"._('Section')."</th>";
78
-print "	<th>"._('IP Address')."</th>";
79
-print "	<th>"._('Hostname')."</th>";
80
-print "	<th>"._('Description')."</th>";
81
-print "	<th>"._('VRF')."</th>";
82
-print "	<th>"._('Subnet')."</th>";
83
-print "	<th>"._('MAC')."</th>";
84
-print "	<th>"._('Owner')."</th>";
85
-print "	<th>"._('Device')."</th>";
86
-print "	<th>"._('Note')."</th>";
87
-print "	<th>"._('Tag')."</th>";
88
-print "	<th>"._('Gateway')."</th>";
77
+print "	<th>"._ ('Section')."</th>";
78
+print "	<th>"._ ('IP Address')."</th>";
79
+print "	<th>"._ ('Hostname')."</th>";
80
+print "	<th>"._ ('Description')."</th>";
81
+print "	<th>"._ ('VRF')."</th>";
82
+print "	<th>"._ ('Subnet')."</th>";
83
+print "	<th>"._ ('MAC')."</th>";
84
+print "	<th>"._ ('Owner')."</th>";
85
+print "	<th>"._ ('Device')."</th>";
86
+print "	<th>"._ ('Note')."</th>";
87
+print "	<th>"._ ('Tag')."</th>";
88
+print "	<th>"._ ('Gateway')."</th>";
89 89
 print $custom_fields_names;
90 90
 print "	</tr>";
91 91
 
92 92
 print "	<tr>";
93 93
 print "	<td><input type='checkbox' name='section' checked></td>";
94
-print "	<td><input type='checkbox' name='ip_addr' checked title='"._('Mandatory')."'> </td>";
95
-print "	<td><input type='checkbox' name='dns_name' checked title='"._('Mandatory')."'></td>";
94
+print "	<td><input type='checkbox' name='ip_addr' checked title='"._ ('Mandatory')."'> </td>";
95
+print "	<td><input type='checkbox' name='dns_name' checked title='"._ ('Mandatory')."'></td>";
96 96
 print "	<td><input type='checkbox' name='description' checked> </td>";
97 97
 print "	<td><input type='checkbox' name='vrf' checked></td>";
98 98
 print "	<td><input type='checkbox' name='subnet' checked></td>";
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
 print '<form id="selectExportSections">';
113 113
 
114 114
 # show sections
115
-if($all_sections!==false) {
115
+if ($all_sections !== false) {
116 116
 	print '<h4>Sections</h4>';
117 117
 	print "	<table class='table table-striped table-condensed'>";
118 118
 	print "	<tr>";
119
-    print '	<th><input type="checkbox" id="exportSelectAll" checked> '._('Name').'</th>';
120
-    print "	<th>"._('Description')."</th>";
121
-    print "	<th>"._('Parent')."</th>";
119
+    print '	<th><input type="checkbox" id="exportSelectAll" checked> '._ ('Name').'</th>';
120
+    print "	<th>"._ ('Description')."</th>";
121
+    print "	<th>"._ ('Parent')."</th>";
122 122
     print "	</tr>\n";
123 123
 
124 124
 	# existing sections
@@ -127,22 +127,22 @@  discard block
 block discarded – undo
127 127
 		$section = (array) $section;
128 128
 
129 129
 		print '<tr>';
130
-		print '	<td><div class="checkbox"><label><input type="checkbox" id="exportCheck" name="exportSection__'.str_replace(" ", "_", $section['name']).'" checked>'.str_replace("_", " ", $section['name']).'</label></div></td>';
131
-		print '	<td>'. $section['description'] .'</td>'. "\n";
130
+		print '	<td><div class="checkbox"><label><input type="checkbox" id="exportCheck" name="exportSection__'.str_replace (" ", "_", $section['name']).'" checked>'.str_replace ("_", " ", $section['name']).'</label></div></td>';
131
+		print '	<td>'.$section['description'].'</td>'."\n";
132 132
 		//master Section
133
-		if($section['masterSection']!=0) {
133
+		if ($section['masterSection'] != 0) {
134 134
 			# get section details
135
-			$ssec = $Admin->fetch_object("sections", "id", $section['masterSection']);
135
+			$ssec = $Admin->fetch_object ("sections", "id", $section['masterSection']);
136 136
 			print "	<td>$ssec->name</td>";
137 137
 		} else {
138 138
 			print "	<td>/</td>";
139 139
 		}
140
-		print '</tr>'. "\n";
140
+		print '</tr>'."\n";
141 141
 	}
142 142
 
143 143
 	print '</table>';
144 144
 
145
-	print '<div class="checkbox"><label><input type="checkbox" name="exportSections" checked>'._("Include the sections in a separate sheet.").'</label></div>';
145
+	print '<div class="checkbox"><label><input type="checkbox" name="exportSections" checked>'._ ("Include the sections in a separate sheet.").'</label></div>';
146 146
 //	print '<div class="checkbox"><label><input type="checkbox" name="separateSheets">'._("Export each section in a separate sheet.").'</label></div>';
147 147
 
148 148
 }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 <!-- footer -->
155 155
 <div class="pFooter">
156 156
 	<div class="btn-group">
157
-		<button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button>
158
-		<button class="btn btn-sm btn-success" id="dataExportSubmit" data-type="ipaddr"><i class="fa fa-upload"></i> <?php print _('Export'); ?></button>
157
+		<button class="btn btn-sm btn-default hidePopups"><?php print _ ('Cancel'); ?></button>
158
+		<button class="btn btn-sm btn-success" id="dataExportSubmit" data-type="ipaddr"><i class="fa fa-upload"></i> <?php print _ ('Export'); ?></button>
159 159
 	</div>
160 160
 </div>
Please login to merge, or discard this patch.