Project

General

Profile

Download (20.7 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f908db Scott Ullrich
<?php
2
/*
3 aaec5634 Renato Botelho
 * pkg.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 f5dbca0d Stephen Beaver
 */
53 a7f908db Scott Ullrich
54 6b07c15a Matthew Grooms
##|+PRIV
55
##|*IDENT=page-package-settings
56 5230f468 jim-p
##|*NAME=Package: Settings
57 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Package: Settings' page.
58
##|*MATCH=pkg.php*
59
##|-PRIV
60
61 e4bf1c19 Colin Smith
require_once("guiconfig.inc");
62
require_once("pkg-utils.inc");
63 a7f908db Scott Ullrich
64 2c2fed92 Stephen Beaver
function domTT_title($title_msg) {
65
	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');\"";
66
}
67
68 98bcf1f8 Scott Ullrich
$xml = $_REQUEST['xml'];
69 a7f908db Scott Ullrich
70 f8ac4407 Phil Davis
if ($xml == "") {
71 84320769 k-paulius
	$pgtitle = array(gettext("Package"), gettext("Editor"));
72 de02dc29 Phil Davis
	$pglinks = array("", "@self");
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 de02dc29 Phil Davis
			$pglinks[] = "@self";
200 8cfdeb2e BBcan177
		}
201
	} else {
202
		$pgtitle = array(gettext("Package"), gettext($pkg['title']));
203 de02dc29 Phil Davis
		$pglinks = array("", "@self");
204 8cfdeb2e BBcan177
	}
205
} else {
206
	$pgtitle = array(gettext("Package"), gettext("Editor"));
207 de02dc29 Phil Davis
	$pglinks = array("", "@self");
208 8cfdeb2e BBcan177
}
209
210 3ad27058 heper
if ($pkg['tabs'] != "") {
211
	$tab_array = array();
212
	foreach ($pkg['tabs']['tab'] as $tab) {
213
		if ($tab['tab_level']) {
214
			$tab_level = $tab['tab_level'];
215
		} else {
216
			$tab_level = 1;
217
		}
218
		if (isset($tab['active'])) {
219
			$active = true;
220
			$pgtitle[] = $tab['text'];
221 de02dc29 Phil Davis
			$pglinks[] = "@self";
222 3ad27058 heper
		} else {
223
			$active = false;
224
		}
225
		if (isset($tab['no_drop_down'])) {
226
			$no_drop_down = true;
227
		}
228
		$urltmp = "";
229
		if ($tab['url'] != "") {
230
			$urltmp = $tab['url'];
231
		}
232
		if ($tab['xml'] != "") {
233
			$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
234
		}
235
236
		$addresswithport = getenv("HTTP_HOST");
237
		$colonpos = strpos($addresswithport, ":");
238
		if ($colonpos !== False) {
239
			//my url is actually just the IP address of the pfsense box
240
			$myurl = substr($addresswithport, 0, $colonpos);
241
		} else {
242
			$myurl = $addresswithport;
243
		}
244
		// eval url so that above $myurl item can be processed if need be.
245
		$url = str_replace('$myurl', $myurl, $urltmp);
246
247
		$tab_array[$tab_level][] = array(
248
			$tab['text'],
249
			$active,
250
			$url
251
		);
252
	}
253
254
	ksort($tab_array);
255
}
256
257 83ddedcd Scott Ullrich
include("head.inc");
258 3ad27058 heper
if (isset($tab_array)) {
259
	foreach ($tab_array as $tabid => $tab) {
260
		display_top_tabs($tab); //, $no_drop_down, $tabid);
261
	}
262
}
263 83ddedcd Scott Ullrich
264 a7f908db Scott Ullrich
?>
265
266 44507df4 Colin Fleming
<script type="text/javascript">
267
//<![CDATA[
268 0f649c97 Phil Davis
events.push(function() {
269 2ef13b6c Stephen Beaver
270 44507df4 Colin Fleming
	function setFilter(filtertext) {
271 3f98044a Francisco Cavalcante
		$('#pkg_filter').val(filtertext);
272 44507df4 Colin Fleming
		document.pkgform.submit();
273 f8ac4407 Phil Davis
	}
274 44507df4 Colin Fleming
275 2ef13b6c Stephen Beaver
<?php
276
	if ($pkg['adddeleteeditpagefields']['movable']) {
277
?>
278
		$('#mainarea table tbody').sortable({
279
		items: 'tr.sortable',
280
			cursor: 'move',
281
			distance: 10,
282
			opacity: 0.8,
283
			helper: function(e, ui) {
284
				ui.children().each(function() {
285 3f98044a Francisco Cavalcante
					$(this).width($(this).width());
286 44507df4 Colin Fleming
				});
287 2ef13b6c Stephen Beaver
			return ui;
288
			},
289
		});
290
<?php
291
	}
292
?>
293
});
294 b51d272c Stephen Beaver
295 15281e44 Stephen Beaver
function save_changes_to_xml(xml) {
296
	var ids = $('#mainarea table tbody').sortable('serialize', {key:"ids[]"});
297
	var strloading="<?=gettext('Saving changes...')?>";
298 a16d923f NOYB
	if (confirm("<?=gettext("Confirmation Required to save changes.")?>")) {
299 15281e44 Stephen Beaver
		$.ajax({
300
			type: 'get',
301
			cache: false,
302
			url: "<?=$_SERVER['SCRIPT_NAME']?>",
303
			data: {xml:'<?=$xml?>', act:'update', ids: ids},
304
			beforeSend: function() {
305
				$('#savemsg').empty().html(strloading);
306
			},
307
			error: function(data) {
308
				$('#savemsg').empty().html('Error:' + data);
309
			},
310
			success: function(data) {
311
				$('#savemsg').empty().html(data);
312
			}
313
		});
314 2ef13b6c Stephen Beaver
	}
315
}
316
317 44507df4 Colin Fleming
//]]>
318
</script>
319 f5dbca0d Stephen Beaver
320
<?php
321 0f649c97 Phil Davis
if ($_GET['savemsg'] != "") {
322 f5dbca0d Stephen Beaver
	$savemsg = htmlspecialchars($_GET['savemsg']);
323 0f649c97 Phil Davis
}
324 f5dbca0d Stephen Beaver
325 0f649c97 Phil Davis
if ($savemsg) {
326 f5dbca0d Stephen Beaver
	print_info_box($savemsg, 'success');
327 0f649c97 Phil Davis
}
328 f5dbca0d Stephen Beaver
?>
329
330 5aa9a4f2 Scott Ullrich
<form action="pkg.php" name="pkgform" method="get">
331 f5dbca0d Stephen Beaver
	<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>' />
332 c24bb3fc Stephen Beaver
		<div id="mainarea" class="panel panel-default">
333 b51d272c Stephen Beaver
			<table id="mainarea" class="table table-striped table-hover table-condensed">
334 c24bb3fc Stephen Beaver
				<thead>
335 32c477c5 Scott Ullrich
<?php
336 f8ac4407 Phil Davis
	/* Handle filtering bar A-Z */
337
	$include_filtering_inputbox = false;
338
	$colspan = 0;
339 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
340 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
341
			$colspan++;
342
		}
343
	}
344
	if ($pkg['fields']['field']) {
345
		// First find the sorting type field if it exists
346
		foreach ($pkg['fields']['field'] as $field) {
347
			if ($field['type'] == "sorting") {
348
				if (isset($field['include_filtering_inputbox'])) {
349
					$include_filtering_inputbox = true;
350
				}
351
				if ($display_maximum_rows < 1) {
352
					if ($field['display_maximum_rows']) {
353
						$display_maximum_rows = $field['display_maximum_rows'];
354
					}
355
				}
356 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
357 cadeb9fd Phil Davis
				echo gettext("Filter by: ");
358 f8ac4407 Phil Davis
				$isfirst = true;
359
				for ($char = 65; $char < 91; $char++) {
360
					if (!$isfirst) {
361
						echo " | ";
362
					}
363
					echo "<a href=\"#\" onclick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
364
					$isfirst = false;
365
				}
366
				echo "</td></tr>";
367 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
368 f8ac4407 Phil Davis
				if ($field['sortablefields']) {
369 cadeb9fd Phil Davis
					echo gettext("Filter field: ") . "<select name='pkg_filter_type'>";
370 f8ac4407 Phil Davis
					foreach ($field['sortablefields']['item'] as $si) {
371
						if ($si['name'] == $_REQUEST['pkg_filter_type']) {
372 c4b60a9a Colin Fleming
							$SELECTED = "selected";
373 f8ac4407 Phil Davis
						} else {
374
							$SELECTED = "";
375 32c477c5 Scott Ullrich
						}
376 f8ac4407 Phil Davis
						echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
377 32c477c5 Scott Ullrich
					}
378 f8ac4407 Phil Davis
					echo "</select>";
379 32c477c5 Scott Ullrich
				}
380 f8ac4407 Phil Davis
				if ($include_filtering_inputbox) {
381 7100f041 jim-p
					echo '&nbsp;&nbsp;' . gettext("Filter text: ") . '<input id="pkg_filter" name="pkg_filter" value="' . htmlspecialchars($_REQUEST['pkg_filter']) . '" />';
382 27d6a45b jim-p
					echo '&nbsp;<button type="submit" value="Filter" class="btn btn-primary btn-xs">';
383
					echo '<i class="fa fa-filter icon-embed-btn"></i>';
384
					echo gettext("Filter");
385
					echo "</button>";
386 f8ac4407 Phil Davis
				}
387
				echo "</td></tr><tr><td><font size='-3'>&nbsp;</font></td></tr>";
388
			}
389
		}
390
	}
391 32c477c5 Scott Ullrich
?>
392
				<tr>
393 c24bb3fc Stephen Beaver
394 32c477c5 Scott Ullrich
<?php
395 f8ac4407 Phil Davis
	if ($display_maximum_rows) {
396 6c07db48 Phil Davis
		$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows), 9));
397 f8ac4407 Phil Davis
		$page = 1;
398
		$tmpcount = 0;
399
		$tmppp = 0;
400
		if (is_array($evaledvar)) {
401
			foreach ($evaledvar as $ipa) {
402
				if ($tmpcount == $display_maximum_rows) {
403
					$page++;
404 37da0c50 Scott Ullrich
					$tmpcount = 0;
405
				}
406 f8ac4407 Phil Davis
				if ($tmppp == $startdisplayingat) {
407
					break;
408 32c477c5 Scott Ullrich
				}
409 f8ac4407 Phil Davis
				$tmpcount++;
410
				$tmppp++;
411
			}
412
		}
413 c24bb3fc Stephen Beaver
		echo "<tr><th colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
414 f8ac4407 Phil Davis
		echo "<table width='100%' summary=''>";
415
		echo "<tr>";
416 cadeb9fd Phil Davis
		echo "<td class='text-left'>" . sprintf(gettext('Displaying page %1$s of %2$s'), $page, $totalpages) . "</b></td>";
417
		echo "<td class='text-right'>" . gettext("Rows per page: ") . "<select onchange='document.pkgform.submit();' name='display_maximum_rows'>";
418 6c07db48 Phil Davis
		for ($x = 0; $x < 250; $x++) {
419 f8ac4407 Phil Davis
			if ($x == $display_maximum_rows) {
420 c4b60a9a Colin Fleming
				$SELECTED = "selected";
421 f8ac4407 Phil Davis
			} else {
422
				$SELECTED = "";
423
			}
424
			echo "<option value='$x' $SELECTED>$x</option>\n";
425
			$x = $x + 4;
426
		}
427
		echo "</select></td></tr>";
428
		echo "</table>";
429 c24bb3fc Stephen Beaver
		echo "</th></tr>";
430 f8ac4407 Phil Davis
	}
431 2ef13b6c Stephen Beaver
432 f8ac4407 Phil Davis
	$cols = 0;
433 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
434 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
435 c24bb3fc Stephen Beaver
			echo "<th class=\"listhdrr\">" . $column['fielddescr'] . "</th>";
436 f8ac4407 Phil Davis
			$cols++;
437
		}
438
	}
439
?>
440
				</tr>
441 c24bb3fc Stephen Beaver
				</thead>
442
				<tbody>
443 f8ac4407 Phil Davis
<?php
444
	$i = 0;
445 6c07db48 Phil Davis
	$pagination_counter = 0;
446 f8ac4407 Phil Davis
	if ($evaledvar) {
447
		foreach ($evaledvar as $ip) {
448
			if ($startdisplayingat) {
449
				if ($i < $startdisplayingat) {
450
					$i++;
451
					continue;
452 32c477c5 Scott Ullrich
				}
453 f8ac4407 Phil Davis
			}
454
			if ($_REQUEST['pkg_filter']) {
455
				// Handle filtered items
456
				if ($pkg['fields']['field'] && !$filter_regex) {
457
					// First find the sorting type field if it exists
458
					foreach ($pkg['fields']['field'] as $field) {
459
						if ($field['type'] == "sorting") {
460
							if ($field['sortablefields']['item']) {
461
								foreach ($field['sortablefields']['item'] as $sf) {
462
									if ($sf['name'] == $_REQUEST['pkg_filter_type']) {
463
										$filter_fieldname = $sf['fieldname'];
464
										#Use a default regex on sortable fields when none is declared
465
										if ($sf['regex']) {
466
											$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
467
										} else {
468
											$filter_regex = "/{$_REQUEST['pkg_filter']}/i";
469 32c477c5 Scott Ullrich
										}
470
									}
471
								}
472
							}
473
						}
474
					}
475 f8ac4407 Phil Davis
				}
476
				// Do we have something to filter on?
477
				unset($filter_matches);
478 f5dbca0d Stephen Beaver
				if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
479 f8ac4407 Phil Davis
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
480
						$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
481
						if ($column['fieldname'] == $filter_fieldname) {
482
							if ($filter_regex) {
483
								//echo "$filter_regex - $fieldname<p/>";
484
								preg_match($filter_regex, $fieldname, $filter_matches);
485
								break;
486 32c477c5 Scott Ullrich
							}
487
						}
488
					}
489
				}
490 f8ac4407 Phil Davis
				if (!$filter_matches) {
491
					$i++;
492
					continue;
493
				}
494
			}
495
			if ($pkg['adddeleteeditpagefields']['movable']) {
496 8d659bf1 NOYB
				echo "<tr style=\"vertical-align: top\" class=\"sortable\" id=\"id_{$i}\">\n";
497 f8ac4407 Phil Davis
			} else {
498 8d659bf1 NOYB
				echo "<tr style=\"vertical-align: top\">\n";
499 f8ac4407 Phil Davis
			}
500 f5dbca0d Stephen Beaver
			if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
501 f8ac4407 Phil Davis
				foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
502
					if ($column['fieldname'] == "description") {
503
						$class = "listbg";
504
					} else {
505
						$class = "listlr";
506
					}
507 32c477c5 Scott Ullrich
?>
508 f5dbca0d Stephen Beaver
					<td class="<?=$class?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i?>';">
509 32c477c5 Scott Ullrich
<?php
510 f8ac4407 Phil Davis
					$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
511
					#Check if columnitem has a type field declared
512
					if ($column['type'] == "checkbox") {
513
						if ($fieldname == "") {
514
							echo gettext("No");
515
						} else {
516
							echo gettext("Yes");
517
						}
518
					} else if ($column['type'] == "interface") {
519 6c07db48 Phil Davis
						echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
520 f8ac4407 Phil Davis
					} else {
521 45c50e6f jim-p
						$display_text = "";
522 f8ac4407 Phil Davis
						#Check if columnitem has an encoding field declared
523
						if ($column['encoding'] == "base64") {
524 45c50e6f jim-p
							$display_text = $column['prefix'] . base64_decode($fieldname) . $column['suffix'];
525 f8ac4407 Phil Davis
						#Check if there is a custom info to show when $fieldname is not empty
526
						} else if ($column['listmodeon'] && $fieldname != "") {
527 45c50e6f jim-p
							$display_text = $column['prefix'] . gettext($column['listmodeon']). $column['suffix'];
528 f8ac4407 Phil Davis
						#Check if there is a custom info to show when $fieldname is empty
529
						} else if ($column['listmodeoff'] && $fieldname == "") {
530 45c50e6f jim-p
							$display_text = $column['prefix'] .gettext($column['listmodeoff']). $column['suffix'];
531 f8ac4407 Phil Davis
						} else {
532 45c50e6f jim-p
							$display_text = $column['prefix'] . $fieldname ." ". $column['suffix'];
533 f8ac4407 Phil Davis
						}
534 45c50e6f jim-p
						if (!isset($column['allow_html'])) {
535
							$display_text = htmlspecialchars($display_text);
536
						}
537
						echo $display_text;
538 32c477c5 Scott Ullrich
					}
539
?>
540 f8ac4407 Phil Davis
					</td>
541 32c477c5 Scott Ullrich
<?php
542 f8ac4407 Phil Davis
				} // foreach columnitem
543
			} // if columnitem
544
?>
545 8d659bf1 NOYB
					<td style="vertical-align: middle" class="list text-nowrap">
546 f8ac4407 Phil Davis
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
547
							<tr>
548
<?php
549
			#Show custom description to edit button if defined
550 cadeb9fd Phil Davis
			$edit_msg=($pkg['adddeleteeditpagefields']['edittext']?$pkg['adddeleteeditpagefields']['edittext']:gettext("Edit this item"));
551 f8ac4407 Phil Davis
?>
552 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>
553 f8ac4407 Phil Davis
<?php
554
			#Show custom description to delete button if defined
555 cadeb9fd Phil Davis
			$delete_msg=($pkg['adddeleteeditpagefields']['deletetext']?$pkg['adddeleteeditpagefields']['deletetext']:gettext("Delete this item"));
556 f8ac4407 Phil Davis
?>
557 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>
558 f8ac4407 Phil Davis
							</tr>
559 c24bb3fc Stephen Beaver
						</tbody>
560
					</table>
561 b51d272c Stephen Beaver
				</td>
562 f8ac4407 Phil Davis
<?php
563 f5dbca0d Stephen Beaver
			echo "</tr>\n"; // Pairs with an echo tr some way above
564 f8ac4407 Phil Davis
			// Handle pagination and display_maximum_rows
565
			if ($display_maximum_rows) {
566
				if ($pagination_counter == ($display_maximum_rows-1) or
567 f5dbca0d Stephen Beaver
					$i == (count($evaledvar)-1)) {
568 f8ac4407 Phil Davis
					$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
569
					$final_footer = "";
570
					$final_footer .= "<tr><td colspan='$colcount'>";
571 6c07db48 Phil Davis
					$final_footer .= "<table width='100%' summary=''><tr>";
572 79563cb6 Colin Fleming
					$final_footer .= "<td class='text-left'>";
573 f8ac4407 Phil Davis
					$startingat = $startdisplayingat - $display_maximum_rows;
574
					if ($startingat > -1) {
575 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat={$startingat}&amp;display_maximum_rows={$display_maximum_rows}'>";
576 f8ac4407 Phil Davis
					} else if ($startdisplayingat > 1) {
577 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=0&amp;display_maximum_rows={$display_maximum_rows}'>";
578 32c477c5 Scott Ullrich
					}
579 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'><< " . gettext("Previous page") . "</font></a>";
580 f8ac4407 Phil Davis
					if ($tmppp + $display_maximum_rows > count($evaledvar)) {
581
						$endingrecord = count($evaledvar);
582
					} else {
583
						$endingrecord = $tmppp + $display_maximum_rows;
584
					}
585 79563cb6 Colin Fleming
					$final_footer .= "</td><td class='text-center'>";
586 f8ac4407 Phil Davis
					$tmppp++;
587 6c07db48 Phil Davis
					$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
588 79563cb6 Colin Fleming
					$final_footer .= "</font></td><td class='text-right'>&nbsp;";
589 f8ac4407 Phil Davis
					if (($i+1) < count($evaledvar)) {
590 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}'>";
591 f8ac4407 Phil Davis
					}
592 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'>" . gettext("Next page") . " >></font></a>";
593 6c07db48 Phil Davis
					$final_footer .= "</td></tr></table></td></tr>";
594 f8ac4407 Phil Davis
					$i = count($evaledvar);
595
					break;
596 549912e3 Scott Ullrich
				}
597 f8ac4407 Phil Davis
			}
598
			$i++;
599
			$pagination_counter++;
600
		} // foreach evaledvar
601
	} // if evaledvar
602 32c477c5 Scott Ullrich
?>
603
				<tr>
604
					<td colspan="<?=$cols?>"></td>
605
					<td>
606 44507df4 Colin Fleming
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
607 32c477c5 Scott Ullrich
							<tr>
608 f8ac4407 Phil Davis
<?php
609
	#Show custom description to add button if defined
610 cadeb9fd Phil Davis
	$add_msg=($pkg['adddeleteeditpagefields']['addtext']?$pkg['adddeleteeditpagefields']['addtext']:gettext("Add a new item"));
611 f8ac4407 Phil Davis
?>
612 c0367cb8 jim-p
								<td><a href="pkg_edit.php?xml=<?=$xml?>&amp;id=<?=$i?>" class="btn btn-sm btn-success" title="<?=$add_msg?>"><i class="fa fa-plus icon-embed-btn"></i><?=gettext('Add')?></a></td>
613 f8ac4407 Phil Davis
<?php
614
	#Show description button and info if defined
615
	if ($pkg['adddeleteeditpagefields']['description']) {
616
?>
617 995df6c3 Stephen Beaver
								<td>
618 7ea65674 Jared Dillard
									<i class="fa fa-info-circle"><?=$pkg['adddeleteeditpagefields']['description']?></i>
619 995df6c3 Stephen Beaver
								</td>
620 f8ac4407 Phil Davis
<?php
621
	}
622
?>
623 32c477c5 Scott Ullrich
							</tr>
624
						</table>
625
					</td>
626
				</tr>
627 37da0c50 Scott Ullrich
				<?=$final_footer?>
628 f8ac4407 Phil Davis
			</table>
629 c24bb3fc Stephen Beaver
			</div>
630 e731dae0 jim-p
		<button class="btn btn-primary" type="button" value="Save" name="Submit" onclick="save_changes_to_xml('<?=$xml?>')"><i class="fa fa-save icon-embed-btn"></i><?=gettext("Save")?></button>
631 3d335c4d Scott Ullrich
632 a7f908db Scott Ullrich
</form>
633 b000f96f Scott Ullrich
<?php
634 f5dbca0d Stephen Beaver
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
635
echo "<!-- filter_regex: {$filter_regex} -->";
636 b000f96f Scott Ullrich
637 f5dbca0d Stephen Beaver
include("foot.inc"); ?>