Project

General

Profile

Download (20.1 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f908db Scott Ullrich
<?php
2
/*
3 f8ac4407 Phil Davis
	pkg.php
4 1d333258 Scott Ullrich
/*
5 f5dbca0d Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55 a7f908db Scott Ullrich
56 6b07c15a Matthew Grooms
##|+PRIV
57
##|*IDENT=page-package-settings
58 5230f468 jim-p
##|*NAME=Package: Settings
59 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Package: Settings' page.
60
##|*MATCH=pkg.php*
61
##|-PRIV
62
63 e4bf1c19 Colin Smith
require_once("guiconfig.inc");
64
require_once("pkg-utils.inc");
65 a7f908db Scott Ullrich
66 2c2fed92 Stephen Beaver
function domTT_title($title_msg) {
67
	print "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '".gettext($title_msg)."', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\"";
68
}
69
70 98bcf1f8 Scott Ullrich
$xml = $_REQUEST['xml'];
71 a7f908db Scott Ullrich
72 f8ac4407 Phil Davis
if ($xml == "") {
73 f5dbca0d Stephen Beaver
	include("head.inc");
74 8545adde k-paulius
	print_info_box(gettext("No valid package defined."), 'danger', false);
75 f5dbca0d Stephen Beaver
	include("foot.inc");
76 b000f96f Scott Ullrich
	exit;
77 a7f908db Scott Ullrich
} else {
78 44bcf766 jim-p
	$pkg_xml_prefix = "/usr/local/pkg/";
79
	$pkg_full_path = "{$pkg_xml_prefix}/{$xml}";
80 74817ee2 Phil Davis
	$pkg_realpath = realpath($pkg_full_path);
81
	if (empty($pkg_realpath)) {
82 8545adde k-paulius
		$path_error = sprintf(gettext("Package path %s not found."), htmlspecialchars($pkg_full_path));
83 ae2915a4 Phil Davis
	} else if (substr_compare($pkg_realpath, $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) {
84 8545adde k-paulius
		$path_error = sprintf(gettext("Invalid path %s specified."), htmlspecialchars($pkg_full_path));
85 74817ee2 Phil Davis
	}
86
87
	if (!empty($path_error)) {
88
		include("head.inc");
89 8545adde k-paulius
		print_info_box($path_error . "<br />" . gettext("Try reinstalling the package."), 'danger', false);
90 74817ee2 Phil Davis
		include("foot.inc");
91 44bcf766 jim-p
		die;
92
	}
93 74817ee2 Phil Davis
94 44bcf766 jim-p
	if (file_exists($pkg_full_path)) {
95
		$pkg = parse_xml_config_pkg($pkg_full_path, "packagegui");
96 f8ac4407 Phil Davis
	} else {
97 f5dbca0d Stephen Beaver
		include("head.inc");
98 8545adde k-paulius
		print_info_box(sprintf(gettext("File not found %s."), htmlspecialchars($xml)), 'danger', false);
99 f5dbca0d Stephen Beaver
		include("foot.inc");
100 98bcf1f8 Scott Ullrich
		exit;
101
	}
102 a7f908db Scott Ullrich
}
103
104 f5dbca0d Stephen Beaver
if ($pkg['donotsave'] != "") {
105 6f3d2063 Renato Botelho
	header("Location: pkg_edit.php?xml=" . $xml);
106 b000f96f Scott Ullrich
	exit;
107 3eaeb703 Scott Ullrich
}
108
109 7c172009 Scott Ullrich
if ($pkg['include_file'] != "") {
110
	require_once($pkg['include_file']);
111
}
112
113 f8ac4407 Phil Davis
if ($_REQUEST['startdisplayingat']) {
114 32c477c5 Scott Ullrich
	$startdisplayingat = $_REQUEST['startdisplayingat'];
115 f8ac4407 Phil Davis
}
116 32c477c5 Scott Ullrich
117 f8ac4407 Phil Davis
if ($_REQUEST['display_maximum_rows']) {
118
	if ($_REQUEST['display_maximum_rows']) {
119 3ca50a15 Scott Ullrich
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
120 f8ac4407 Phil Davis
	}
121
}
122 3ca50a15 Scott Ullrich
123 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
124 e3c4b6b7 Scott Ullrich
125 05a42cce Marcello Coutinho
if ($_GET['act'] == "update") {
126 f8ac4407 Phil Davis
127
	if (is_array($config['installedpackages'][$pkg['name']]) && $pkg['name'] != "" && $_REQUEST['ids'] !="") {
128
		#get current values
129
		$current_values=$config['installedpackages'][$pkg['name']]['config'];
130
		#get updated ids
131
		parse_str($_REQUEST['ids'], $update_list);
132
		#sort ids to know what to change
133
		#useful to do not lose data when using sorting and paging
134
		$sort_list=$update_list['ids'];
135
		sort($sort_list);
136
		#apply updates
137
		foreach ($update_list['ids'] as $key=> $value) {
138
			$config['installedpackages'][$pkg['name']]['config'][$sort_list[$key]]=$current_values[$update_list['ids'][$key]];
139
		}
140
		#save current config
141
		write_config();
142
		#sync package
143
		eval ("{$pkg['custom_php_resync_config_command']}");
144
	}
145
	#function called via jquery, no need to continue after save changes.
146
	exit;
147 05a42cce Marcello Coutinho
}
148 e3c4b6b7 Scott Ullrich
if ($_GET['act'] == "del") {
149 f8ac4407 Phil Davis
	// loop through our fieldnames and automatically setup the fieldnames
150 f5dbca0d Stephen Beaver
	// in the environment.	ie: a fieldname of username with a value of
151 f8ac4407 Phil Davis
	// testuser would automatically eval $username = "testuser";
152
	foreach ($evaledvar as $ip) {
153
		if ($pkg['adddeleteeditpagefields']['columnitem']) {
154
			foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
155
				${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
156
			}
157 ef2029df Scott Ullrich
		}
158 f8ac4407 Phil Davis
	}
159 e3c4b6b7 Scott Ullrich
160 f8ac4407 Phil Davis
	$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
161 e3c4b6b7 Scott Ullrich
162 f8ac4407 Phil Davis
	if ($a_pkg[$_GET['id']]) {
163
		unset($a_pkg[$_GET['id']]);
164
		write_config();
165 f5dbca0d Stephen Beaver
		if ($pkg['custom_delete_php_command'] != "") {
166
			if ($pkg['custom_php_command_before_form'] != "") {
167 f8ac4407 Phil Davis
				eval($pkg['custom_php_command_before_form']);
168 8060d89a Scott Ullrich
			}
169 f8ac4407 Phil Davis
			eval($pkg['custom_delete_php_command']);
170
		}
171
		header("Location:  pkg.php?xml=" . $xml);
172
		exit;
173
	}
174 e3c4b6b7 Scott Ullrich
}
175
176 4b5976b5 Scott Ullrich
ob_start();
177
178 d3ab36dc Ermal Lu?i
$iflist = get_configured_interface_with_descr(false, true);
179 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
180 a7f908db Scott Ullrich
181 f5dbca0d Stephen Beaver
if ($pkg['custom_php_global_functions'] != "") {
182 ef2029df Scott Ullrich
	eval($pkg['custom_php_global_functions']);
183 f8ac4407 Phil Davis
}
184 194b4e0a Colin Smith
185 f5dbca0d Stephen Beaver
if ($pkg['custom_php_command_before_form'] != "") {
186 194b4e0a Colin Smith
	eval($pkg['custom_php_command_before_form']);
187 f8ac4407 Phil Davis
}
188 f9a91638 Scott Ullrich
189 8cfdeb2e BBcan177
// Breadcrumb
190
if ($pkg['title'] != "") {
191 3ad27058 heper
	/*if (!$only_edit) {						// Is any package still making use of this?? Is this something that is still wanted, considering the breadcrumb policy https://redmine.pfsense.org/issues/5527
192
 		$pkg['title'] = $pkg['title'] . '/Edit';		// If this needs to live on, then it has to be moved to run AFTER "foreach ($pkg['tabs']['tab'] as $tab)"-loop. This due to $pgtitle[] = $tab['text']; 
193
	}*/
194 8cfdeb2e BBcan177
	if (strpos($pkg['title'], '/')) {
195
		$title = explode('/', $pkg['title']);
196
197
		foreach ($title as $subtitle) {
198
			$pgtitle[] = gettext($subtitle);
199
		}
200
	} else {
201
		$pgtitle = array(gettext("Package"), gettext($pkg['title']));
202
	}
203
} else {
204
	$pgtitle = array(gettext("Package"), gettext("Editor"));
205
}
206
207 3ad27058 heper
if ($pkg['tabs'] != "") {
208
	$tab_array = array();
209
	foreach ($pkg['tabs']['tab'] as $tab) {
210
		if ($tab['tab_level']) {
211
			$tab_level = $tab['tab_level'];
212
		} else {
213
			$tab_level = 1;
214
		}
215
		if (isset($tab['active'])) {
216
			$active = true;
217
			$pgtitle[] = $tab['text'];
218
		} else {
219
			$active = false;
220
		}
221
		if (isset($tab['no_drop_down'])) {
222
			$no_drop_down = true;
223
		}
224
		$urltmp = "";
225
		if ($tab['url'] != "") {
226
			$urltmp = $tab['url'];
227
		}
228
		if ($tab['xml'] != "") {
229
			$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
230
		}
231
232
		$addresswithport = getenv("HTTP_HOST");
233
		$colonpos = strpos($addresswithport, ":");
234
		if ($colonpos !== False) {
235
			//my url is actually just the IP address of the pfsense box
236
			$myurl = substr($addresswithport, 0, $colonpos);
237
		} else {
238
			$myurl = $addresswithport;
239
		}
240
		// eval url so that above $myurl item can be processed if need be.
241
		$url = str_replace('$myurl', $myurl, $urltmp);
242
243
		$tab_array[$tab_level][] = array(
244
			$tab['text'],
245
			$active,
246
			$url
247
		);
248
	}
249
250
	ksort($tab_array);
251
}
252
253 83ddedcd Scott Ullrich
include("head.inc");
254 3ad27058 heper
if (isset($tab_array)) {
255
	foreach ($tab_array as $tabid => $tab) {
256
		display_top_tabs($tab); //, $no_drop_down, $tabid);
257
	}
258
}
259 83ddedcd Scott Ullrich
260 a7f908db Scott Ullrich
?>
261
262 44507df4 Colin Fleming
<script type="text/javascript">
263
//<![CDATA[
264 0f649c97 Phil Davis
events.push(function() {
265 2ef13b6c Stephen Beaver
266 44507df4 Colin Fleming
	function setFilter(filtertext) {
267 3f98044a Francisco Cavalcante
		$('#pkg_filter').val(filtertext);
268 44507df4 Colin Fleming
		document.pkgform.submit();
269 f8ac4407 Phil Davis
	}
270 44507df4 Colin Fleming
271 2ef13b6c Stephen Beaver
<?php
272
	if ($pkg['adddeleteeditpagefields']['movable']) {
273
?>
274
		$('#mainarea table tbody').sortable({
275
		items: 'tr.sortable',
276
			cursor: 'move',
277
			distance: 10,
278
			opacity: 0.8,
279
			helper: function(e, ui) {
280
				ui.children().each(function() {
281 3f98044a Francisco Cavalcante
					$(this).width($(this).width());
282 44507df4 Colin Fleming
				});
283 2ef13b6c Stephen Beaver
			return ui;
284
			},
285
		});
286
<?php
287
	}
288
?>
289
});
290 b51d272c Stephen Beaver
291 15281e44 Stephen Beaver
function save_changes_to_xml(xml) {
292
	var ids = $('#mainarea table tbody').sortable('serialize', {key:"ids[]"});
293
	var strloading="<?=gettext('Saving changes...')?>";
294
	if (confirm("<?=gettext("Do you really want to save changes?")?>")) {
295
		$.ajax({
296
			type: 'get',
297
			cache: false,
298
			url: "<?=$_SERVER['SCRIPT_NAME']?>",
299
			data: {xml:'<?=$xml?>', act:'update', ids: ids},
300
			beforeSend: function() {
301
				$('#savemsg').empty().html(strloading);
302
			},
303
			error: function(data) {
304
				$('#savemsg').empty().html('Error:' + data);
305
			},
306
			success: function(data) {
307
				$('#savemsg').empty().html(data);
308
			}
309
		});
310 2ef13b6c Stephen Beaver
	}
311
}
312
313 44507df4 Colin Fleming
//]]>
314
</script>
315 f5dbca0d Stephen Beaver
316
<?php
317 0f649c97 Phil Davis
if ($_GET['savemsg'] != "") {
318 f5dbca0d Stephen Beaver
	$savemsg = htmlspecialchars($_GET['savemsg']);
319 0f649c97 Phil Davis
}
320 f5dbca0d Stephen Beaver
321 0f649c97 Phil Davis
if ($savemsg) {
322 f5dbca0d Stephen Beaver
	print_info_box($savemsg, 'success');
323 0f649c97 Phil Davis
}
324 f5dbca0d Stephen Beaver
?>
325
326 5aa9a4f2 Scott Ullrich
<form action="pkg.php" name="pkgform" method="get">
327 f5dbca0d Stephen Beaver
	<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>' />
328 c24bb3fc Stephen Beaver
		<div id="mainarea" class="panel panel-default">
329 b51d272c Stephen Beaver
			<table id="mainarea" class="table table-striped table-hover table-condensed">
330 c24bb3fc Stephen Beaver
				<thead>
331 32c477c5 Scott Ullrich
<?php
332 f8ac4407 Phil Davis
	/* Handle filtering bar A-Z */
333
	$include_filtering_inputbox = false;
334
	$colspan = 0;
335 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
336 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
337
			$colspan++;
338
		}
339
	}
340
	if ($pkg['fields']['field']) {
341
		// First find the sorting type field if it exists
342
		foreach ($pkg['fields']['field'] as $field) {
343
			if ($field['type'] == "sorting") {
344
				if (isset($field['include_filtering_inputbox'])) {
345
					$include_filtering_inputbox = true;
346
				}
347
				if ($display_maximum_rows < 1) {
348
					if ($field['display_maximum_rows']) {
349
						$display_maximum_rows = $field['display_maximum_rows'];
350
					}
351
				}
352 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
353 cadeb9fd Phil Davis
				echo gettext("Filter by: ");
354 f8ac4407 Phil Davis
				$isfirst = true;
355
				for ($char = 65; $char < 91; $char++) {
356
					if (!$isfirst) {
357
						echo " | ";
358
					}
359
					echo "<a href=\"#\" onclick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
360
					$isfirst = false;
361
				}
362
				echo "</td></tr>";
363 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
364 f8ac4407 Phil Davis
				if ($field['sortablefields']) {
365 cadeb9fd Phil Davis
					echo gettext("Filter field: ") . "<select name='pkg_filter_type'>";
366 f8ac4407 Phil Davis
					foreach ($field['sortablefields']['item'] as $si) {
367
						if ($si['name'] == $_REQUEST['pkg_filter_type']) {
368 c4b60a9a Colin Fleming
							$SELECTED = "selected";
369 f8ac4407 Phil Davis
						} else {
370
							$SELECTED = "";
371 32c477c5 Scott Ullrich
						}
372 f8ac4407 Phil Davis
						echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
373 32c477c5 Scott Ullrich
					}
374 f8ac4407 Phil Davis
					echo "</select>";
375 32c477c5 Scott Ullrich
				}
376 f8ac4407 Phil Davis
				if ($include_filtering_inputbox) {
377 cadeb9fd Phil Davis
					echo "&nbsp;&nbsp;" . gettext("Filter text: ") . "<input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "' /><input type='submit' value='Filter' />";
378 f8ac4407 Phil Davis
				}
379
				echo "</td></tr><tr><td><font size='-3'>&nbsp;</font></td></tr>";
380
			}
381
		}
382
	}
383 32c477c5 Scott Ullrich
?>
384
				<tr>
385 c24bb3fc Stephen Beaver
386 32c477c5 Scott Ullrich
<?php
387 f8ac4407 Phil Davis
	if ($display_maximum_rows) {
388 6c07db48 Phil Davis
		$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows), 9));
389 f8ac4407 Phil Davis
		$page = 1;
390
		$tmpcount = 0;
391
		$tmppp = 0;
392
		if (is_array($evaledvar)) {
393
			foreach ($evaledvar as $ipa) {
394
				if ($tmpcount == $display_maximum_rows) {
395
					$page++;
396 37da0c50 Scott Ullrich
					$tmpcount = 0;
397
				}
398 f8ac4407 Phil Davis
				if ($tmppp == $startdisplayingat) {
399
					break;
400 32c477c5 Scott Ullrich
				}
401 f8ac4407 Phil Davis
				$tmpcount++;
402
				$tmppp++;
403
			}
404
		}
405 c24bb3fc Stephen Beaver
		echo "<tr><th colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
406 f8ac4407 Phil Davis
		echo "<table width='100%' summary=''>";
407
		echo "<tr>";
408 cadeb9fd Phil Davis
		echo "<td class='text-left'>" . sprintf(gettext('Displaying page %1$s of %2$s'), $page, $totalpages) . "</b></td>";
409
		echo "<td class='text-right'>" . gettext("Rows per page: ") . "<select onchange='document.pkgform.submit();' name='display_maximum_rows'>";
410 6c07db48 Phil Davis
		for ($x = 0; $x < 250; $x++) {
411 f8ac4407 Phil Davis
			if ($x == $display_maximum_rows) {
412 c4b60a9a Colin Fleming
				$SELECTED = "selected";
413 f8ac4407 Phil Davis
			} else {
414
				$SELECTED = "";
415
			}
416
			echo "<option value='$x' $SELECTED>$x</option>\n";
417
			$x = $x + 4;
418
		}
419
		echo "</select></td></tr>";
420
		echo "</table>";
421 c24bb3fc Stephen Beaver
		echo "</th></tr>";
422 f8ac4407 Phil Davis
	}
423 2ef13b6c Stephen Beaver
424 f8ac4407 Phil Davis
	$cols = 0;
425 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
426 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
427 c24bb3fc Stephen Beaver
			echo "<th class=\"listhdrr\">" . $column['fielddescr'] . "</th>";
428 f8ac4407 Phil Davis
			$cols++;
429
		}
430
	}
431
?>
432
				</tr>
433 c24bb3fc Stephen Beaver
				</thead>
434
				<tbody>
435 f8ac4407 Phil Davis
<?php
436
	$i = 0;
437 6c07db48 Phil Davis
	$pagination_counter = 0;
438 f8ac4407 Phil Davis
	if ($evaledvar) {
439
		foreach ($evaledvar as $ip) {
440
			if ($startdisplayingat) {
441
				if ($i < $startdisplayingat) {
442
					$i++;
443
					continue;
444 32c477c5 Scott Ullrich
				}
445 f8ac4407 Phil Davis
			}
446
			if ($_REQUEST['pkg_filter']) {
447
				// Handle filtered items
448
				if ($pkg['fields']['field'] && !$filter_regex) {
449
					// First find the sorting type field if it exists
450
					foreach ($pkg['fields']['field'] as $field) {
451
						if ($field['type'] == "sorting") {
452
							if ($field['sortablefields']['item']) {
453
								foreach ($field['sortablefields']['item'] as $sf) {
454
									if ($sf['name'] == $_REQUEST['pkg_filter_type']) {
455
										$filter_fieldname = $sf['fieldname'];
456
										#Use a default regex on sortable fields when none is declared
457
										if ($sf['regex']) {
458
											$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
459
										} else {
460
											$filter_regex = "/{$_REQUEST['pkg_filter']}/i";
461 32c477c5 Scott Ullrich
										}
462
									}
463
								}
464
							}
465
						}
466
					}
467 f8ac4407 Phil Davis
				}
468
				// Do we have something to filter on?
469
				unset($filter_matches);
470 f5dbca0d Stephen Beaver
				if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
471 f8ac4407 Phil Davis
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
472
						$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
473
						if ($column['fieldname'] == $filter_fieldname) {
474
							if ($filter_regex) {
475
								//echo "$filter_regex - $fieldname<p/>";
476
								preg_match($filter_regex, $fieldname, $filter_matches);
477
								break;
478 32c477c5 Scott Ullrich
							}
479
						}
480
					}
481
				}
482 f8ac4407 Phil Davis
				if (!$filter_matches) {
483
					$i++;
484
					continue;
485
				}
486
			}
487
			if ($pkg['adddeleteeditpagefields']['movable']) {
488
				echo "<tr valign=\"top\" class=\"sortable\" id=\"id_{$i}\">\n";
489
			} else {
490
				echo "<tr valign=\"top\">\n";
491
			}
492 f5dbca0d Stephen Beaver
			if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
493 f8ac4407 Phil Davis
				foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
494
					if ($column['fieldname'] == "description") {
495
						$class = "listbg";
496
					} else {
497
						$class = "listlr";
498
					}
499 32c477c5 Scott Ullrich
?>
500 f5dbca0d Stephen Beaver
					<td class="<?=$class?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i?>';">
501 32c477c5 Scott Ullrich
<?php
502 f8ac4407 Phil Davis
					$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
503
					#Check if columnitem has a type field declared
504
					if ($column['type'] == "checkbox") {
505
						if ($fieldname == "") {
506
							echo gettext("No");
507
						} else {
508
							echo gettext("Yes");
509
						}
510
					} else if ($column['type'] == "interface") {
511 6c07db48 Phil Davis
						echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
512 f8ac4407 Phil Davis
					} else {
513
						#Check if columnitem has an encoding field declared
514
						if ($column['encoding'] == "base64") {
515 6c07db48 Phil Davis
							echo $column['prefix'] . base64_decode($fieldname) . $column['suffix'];
516 f8ac4407 Phil Davis
						#Check if there is a custom info to show when $fieldname is not empty
517
						} else if ($column['listmodeon'] && $fieldname != "") {
518
							echo $column['prefix'] . gettext($column['listmodeon']). $column['suffix'];
519
						#Check if there is a custom info to show when $fieldname is empty
520
						} else if ($column['listmodeoff'] && $fieldname == "") {
521
							echo $column['prefix'] .gettext($column['listmodeoff']). $column['suffix'];
522
						} else {
523
							echo $column['prefix'] . $fieldname ." ". $column['suffix'];
524
						}
525 32c477c5 Scott Ullrich
					}
526
?>
527 f8ac4407 Phil Davis
					</td>
528 32c477c5 Scott Ullrich
<?php
529 f8ac4407 Phil Davis
				} // foreach columnitem
530
			} // if columnitem
531
?>
532 b77cef66 Colin Fleming
					<td valign="middle" class="list text-nowrap">
533 f8ac4407 Phil Davis
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
534
							<tr>
535
<?php
536
			#Show custom description to edit button if defined
537 cadeb9fd Phil Davis
			$edit_msg=($pkg['adddeleteeditpagefields']['edittext']?$pkg['adddeleteeditpagefields']['edittext']:gettext("Edit this item"));
538 f8ac4407 Phil Davis
?>
539 1dfa60c5 Stephen Beaver
								<td><a class="fa fa-pencil" href="pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i?>" title="<?=$edit_msg?>"></a></td>
540 f8ac4407 Phil Davis
<?php
541
			#Show custom description to delete button if defined
542 cadeb9fd Phil Davis
			$delete_msg=($pkg['adddeleteeditpagefields']['deletetext']?$pkg['adddeleteeditpagefields']['deletetext']:gettext("Delete this item"));
543 f8ac4407 Phil Davis
?>
544 408c4a27 Stephen Beaver
								<td>&nbsp;<a class="fa fa-trash" href="pkg.php?xml=<?=$xml?>&amp;act=del&amp;id=<?=$i?>" title="<?=$delete_msg?>"></a></td>
545 f8ac4407 Phil Davis
							</tr>
546 c24bb3fc Stephen Beaver
						</tbody>
547
					</table>
548 b51d272c Stephen Beaver
				</td>
549 f8ac4407 Phil Davis
<?php
550 f5dbca0d Stephen Beaver
			echo "</tr>\n"; // Pairs with an echo tr some way above
551 f8ac4407 Phil Davis
			// Handle pagination and display_maximum_rows
552
			if ($display_maximum_rows) {
553
				if ($pagination_counter == ($display_maximum_rows-1) or
554 f5dbca0d Stephen Beaver
					$i == (count($evaledvar)-1)) {
555 f8ac4407 Phil Davis
					$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
556
					$final_footer = "";
557
					$final_footer .= "<tr><td colspan='$colcount'>";
558 6c07db48 Phil Davis
					$final_footer .= "<table width='100%' summary=''><tr>";
559 79563cb6 Colin Fleming
					$final_footer .= "<td class='text-left'>";
560 f8ac4407 Phil Davis
					$startingat = $startdisplayingat - $display_maximum_rows;
561
					if ($startingat > -1) {
562 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat={$startingat}&amp;display_maximum_rows={$display_maximum_rows}'>";
563 f8ac4407 Phil Davis
					} else if ($startdisplayingat > 1) {
564 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=0&amp;display_maximum_rows={$display_maximum_rows}'>";
565 32c477c5 Scott Ullrich
					}
566 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'><< " . gettext("Previous page") . "</font></a>";
567 f8ac4407 Phil Davis
					if ($tmppp + $display_maximum_rows > count($evaledvar)) {
568
						$endingrecord = count($evaledvar);
569
					} else {
570
						$endingrecord = $tmppp + $display_maximum_rows;
571
					}
572 79563cb6 Colin Fleming
					$final_footer .= "</td><td class='text-center'>";
573 f8ac4407 Phil Davis
					$tmppp++;
574 6c07db48 Phil Davis
					$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
575 79563cb6 Colin Fleming
					$final_footer .= "</font></td><td class='text-right'>&nbsp;";
576 f8ac4407 Phil Davis
					if (($i+1) < count($evaledvar)) {
577 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&amp;display_maximum_rows={$display_maximum_rows}'>";
578 f8ac4407 Phil Davis
					}
579 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'>" . gettext("Next page") . " >></font></a>";
580 6c07db48 Phil Davis
					$final_footer .= "</td></tr></table></td></tr>";
581 f8ac4407 Phil Davis
					$i = count($evaledvar);
582
					break;
583 549912e3 Scott Ullrich
				}
584 f8ac4407 Phil Davis
			}
585
			$i++;
586
			$pagination_counter++;
587
		} // foreach evaledvar
588
	} // if evaledvar
589 32c477c5 Scott Ullrich
?>
590
				<tr>
591
					<td colspan="<?=$cols?>"></td>
592
					<td>
593 44507df4 Colin Fleming
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
594 32c477c5 Scott Ullrich
							<tr>
595 f8ac4407 Phil Davis
<?php
596
	#Show custom description to add button if defined
597 cadeb9fd Phil Davis
	$add_msg=($pkg['adddeleteeditpagefields']['addtext']?$pkg['adddeleteeditpagefields']['addtext']:gettext("Add a new item"));
598 f8ac4407 Phil Davis
?>
599 c405d4f0 Stephen Beaver
								<td><a href="pkg_edit.php?xml=<?=$xml?>&amp;id=<?=$i?>" class="btn btn-sm btn-success" title="<?=$add_msg?>"><?=gettext('Add')?></a></td>
600 f8ac4407 Phil Davis
<?php
601
	#Show description button and info if defined
602
	if ($pkg['adddeleteeditpagefields']['description']) {
603
?>
604 995df6c3 Stephen Beaver
								<td>
605 7ea65674 Jared Dillard
									<i class="fa fa-info-circle"><?=$pkg['adddeleteeditpagefields']['description']?></i>
606 995df6c3 Stephen Beaver
								</td>
607 f8ac4407 Phil Davis
<?php
608
	}
609
?>
610 32c477c5 Scott Ullrich
							</tr>
611
						</table>
612
					</td>
613
				</tr>
614 37da0c50 Scott Ullrich
				<?=$final_footer?>
615 f8ac4407 Phil Davis
			</table>
616 c24bb3fc Stephen Beaver
			</div>
617
		<input class="btn btn-primary" type="button" value="Save" name="Submit" onclick="save_changes_to_xml('<?=$xml?>')" />
618 3d335c4d Scott Ullrich
619 a7f908db Scott Ullrich
</form>
620 b000f96f Scott Ullrich
<?php
621 f5dbca0d Stephen Beaver
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
622
echo "<!-- filter_regex: {$filter_regex} -->";
623 b000f96f Scott Ullrich
624 f5dbca0d Stephen Beaver
include("foot.inc"); ?>