Project

General

Profile

Download (20.6 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 84320769 k-paulius
	$pgtitle = array(gettext("Package"), gettext("Editor"));
74 f5dbca0d Stephen Beaver
	include("head.inc");
75 8545adde k-paulius
	print_info_box(gettext("No valid package defined."), 'danger', false);
76 f5dbca0d Stephen Beaver
	include("foot.inc");
77 b000f96f Scott Ullrich
	exit;
78 a7f908db Scott Ullrich
} else {
79 44bcf766 jim-p
	$pkg_xml_prefix = "/usr/local/pkg/";
80
	$pkg_full_path = "{$pkg_xml_prefix}/{$xml}";
81 74817ee2 Phil Davis
	$pkg_realpath = realpath($pkg_full_path);
82
	if (empty($pkg_realpath)) {
83 8545adde k-paulius
		$path_error = sprintf(gettext("Package path %s not found."), htmlspecialchars($pkg_full_path));
84 ae2915a4 Phil Davis
	} else if (substr_compare($pkg_realpath, $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) {
85 8545adde k-paulius
		$path_error = sprintf(gettext("Invalid path %s specified."), htmlspecialchars($pkg_full_path));
86 74817ee2 Phil Davis
	}
87
88
	if (!empty($path_error)) {
89
		include("head.inc");
90 8545adde k-paulius
		print_info_box($path_error . "<br />" . gettext("Try reinstalling the package."), 'danger', false);
91 74817ee2 Phil Davis
		include("foot.inc");
92 44bcf766 jim-p
		die;
93
	}
94 74817ee2 Phil Davis
95 44bcf766 jim-p
	if (file_exists($pkg_full_path)) {
96
		$pkg = parse_xml_config_pkg($pkg_full_path, "packagegui");
97 f8ac4407 Phil Davis
	} else {
98 f5dbca0d Stephen Beaver
		include("head.inc");
99 8545adde k-paulius
		print_info_box(sprintf(gettext("File not found %s."), htmlspecialchars($xml)), 'danger', false);
100 f5dbca0d Stephen Beaver
		include("foot.inc");
101 98bcf1f8 Scott Ullrich
		exit;
102
	}
103 a7f908db Scott Ullrich
}
104
105 f5dbca0d Stephen Beaver
if ($pkg['donotsave'] != "") {
106 6f3d2063 Renato Botelho
	header("Location: pkg_edit.php?xml=" . $xml);
107 b000f96f Scott Ullrich
	exit;
108 3eaeb703 Scott Ullrich
}
109
110 7c172009 Scott Ullrich
if ($pkg['include_file'] != "") {
111
	require_once($pkg['include_file']);
112
}
113
114 f8ac4407 Phil Davis
if ($_REQUEST['startdisplayingat']) {
115 32c477c5 Scott Ullrich
	$startdisplayingat = $_REQUEST['startdisplayingat'];
116 f8ac4407 Phil Davis
}
117 32c477c5 Scott Ullrich
118 f8ac4407 Phil Davis
if ($_REQUEST['display_maximum_rows']) {
119
	if ($_REQUEST['display_maximum_rows']) {
120 3ca50a15 Scott Ullrich
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
121 f8ac4407 Phil Davis
	}
122
}
123 3ca50a15 Scott Ullrich
124 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
125 e3c4b6b7 Scott Ullrich
126 05a42cce Marcello Coutinho
if ($_GET['act'] == "update") {
127 f8ac4407 Phil Davis
128
	if (is_array($config['installedpackages'][$pkg['name']]) && $pkg['name'] != "" && $_REQUEST['ids'] !="") {
129
		#get current values
130
		$current_values=$config['installedpackages'][$pkg['name']]['config'];
131
		#get updated ids
132
		parse_str($_REQUEST['ids'], $update_list);
133
		#sort ids to know what to change
134
		#useful to do not lose data when using sorting and paging
135
		$sort_list=$update_list['ids'];
136
		sort($sort_list);
137
		#apply updates
138
		foreach ($update_list['ids'] as $key=> $value) {
139
			$config['installedpackages'][$pkg['name']]['config'][$sort_list[$key]]=$current_values[$update_list['ids'][$key]];
140
		}
141
		#save current config
142
		write_config();
143
		#sync package
144
		eval ("{$pkg['custom_php_resync_config_command']}");
145
	}
146
	#function called via jquery, no need to continue after save changes.
147
	exit;
148 05a42cce Marcello Coutinho
}
149 e3c4b6b7 Scott Ullrich
if ($_GET['act'] == "del") {
150 f8ac4407 Phil Davis
	// loop through our fieldnames and automatically setup the fieldnames
151 f5dbca0d Stephen Beaver
	// in the environment.	ie: a fieldname of username with a value of
152 f8ac4407 Phil Davis
	// testuser would automatically eval $username = "testuser";
153
	foreach ($evaledvar as $ip) {
154
		if ($pkg['adddeleteeditpagefields']['columnitem']) {
155
			foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
156
				${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
157
			}
158 ef2029df Scott Ullrich
		}
159 f8ac4407 Phil Davis
	}
160 e3c4b6b7 Scott Ullrich
161 f8ac4407 Phil Davis
	$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
162 e3c4b6b7 Scott Ullrich
163 f8ac4407 Phil Davis
	if ($a_pkg[$_GET['id']]) {
164
		unset($a_pkg[$_GET['id']]);
165
		write_config();
166 f5dbca0d Stephen Beaver
		if ($pkg['custom_delete_php_command'] != "") {
167
			if ($pkg['custom_php_command_before_form'] != "") {
168 f8ac4407 Phil Davis
				eval($pkg['custom_php_command_before_form']);
169 8060d89a Scott Ullrich
			}
170 f8ac4407 Phil Davis
			eval($pkg['custom_delete_php_command']);
171
		}
172
		header("Location:  pkg.php?xml=" . $xml);
173
		exit;
174
	}
175 e3c4b6b7 Scott Ullrich
}
176
177 4b5976b5 Scott Ullrich
ob_start();
178
179 d3ab36dc Ermal Lu?i
$iflist = get_configured_interface_with_descr(false, true);
180 ce696feb Colin Smith
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
181 a7f908db Scott Ullrich
182 f5dbca0d Stephen Beaver
if ($pkg['custom_php_global_functions'] != "") {
183 ef2029df Scott Ullrich
	eval($pkg['custom_php_global_functions']);
184 f8ac4407 Phil Davis
}
185 194b4e0a Colin Smith
186 f5dbca0d Stephen Beaver
if ($pkg['custom_php_command_before_form'] != "") {
187 194b4e0a Colin Smith
	eval($pkg['custom_php_command_before_form']);
188 f8ac4407 Phil Davis
}
189 f9a91638 Scott Ullrich
190 8cfdeb2e BBcan177
// Breadcrumb
191
if ($pkg['title'] != "") {
192 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
193
 		$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']; 
194
	}*/
195 8cfdeb2e BBcan177
	if (strpos($pkg['title'], '/')) {
196
		$title = explode('/', $pkg['title']);
197
198
		foreach ($title as $subtitle) {
199
			$pgtitle[] = gettext($subtitle);
200
		}
201
	} else {
202
		$pgtitle = array(gettext("Package"), gettext($pkg['title']));
203
	}
204
} else {
205
	$pgtitle = array(gettext("Package"), gettext("Editor"));
206
}
207
208 3ad27058 heper
if ($pkg['tabs'] != "") {
209
	$tab_array = array();
210
	foreach ($pkg['tabs']['tab'] as $tab) {
211
		if ($tab['tab_level']) {
212
			$tab_level = $tab['tab_level'];
213
		} else {
214
			$tab_level = 1;
215
		}
216
		if (isset($tab['active'])) {
217
			$active = true;
218
			$pgtitle[] = $tab['text'];
219
		} else {
220
			$active = false;
221
		}
222
		if (isset($tab['no_drop_down'])) {
223
			$no_drop_down = true;
224
		}
225
		$urltmp = "";
226
		if ($tab['url'] != "") {
227
			$urltmp = $tab['url'];
228
		}
229
		if ($tab['xml'] != "") {
230
			$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
231
		}
232
233
		$addresswithport = getenv("HTTP_HOST");
234
		$colonpos = strpos($addresswithport, ":");
235
		if ($colonpos !== False) {
236
			//my url is actually just the IP address of the pfsense box
237
			$myurl = substr($addresswithport, 0, $colonpos);
238
		} else {
239
			$myurl = $addresswithport;
240
		}
241
		// eval url so that above $myurl item can be processed if need be.
242
		$url = str_replace('$myurl', $myurl, $urltmp);
243
244
		$tab_array[$tab_level][] = array(
245
			$tab['text'],
246
			$active,
247
			$url
248
		);
249
	}
250
251
	ksort($tab_array);
252
}
253
254 83ddedcd Scott Ullrich
include("head.inc");
255 3ad27058 heper
if (isset($tab_array)) {
256
	foreach ($tab_array as $tabid => $tab) {
257
		display_top_tabs($tab); //, $no_drop_down, $tabid);
258
	}
259
}
260 83ddedcd Scott Ullrich
261 a7f908db Scott Ullrich
?>
262
263 44507df4 Colin Fleming
<script type="text/javascript">
264
//<![CDATA[
265 0f649c97 Phil Davis
events.push(function() {
266 2ef13b6c Stephen Beaver
267 44507df4 Colin Fleming
	function setFilter(filtertext) {
268 3f98044a Francisco Cavalcante
		$('#pkg_filter').val(filtertext);
269 44507df4 Colin Fleming
		document.pkgform.submit();
270 f8ac4407 Phil Davis
	}
271 44507df4 Colin Fleming
272 2ef13b6c Stephen Beaver
<?php
273
	if ($pkg['adddeleteeditpagefields']['movable']) {
274
?>
275
		$('#mainarea table tbody').sortable({
276
		items: 'tr.sortable',
277
			cursor: 'move',
278
			distance: 10,
279
			opacity: 0.8,
280
			helper: function(e, ui) {
281
				ui.children().each(function() {
282 3f98044a Francisco Cavalcante
					$(this).width($(this).width());
283 44507df4 Colin Fleming
				});
284 2ef13b6c Stephen Beaver
			return ui;
285
			},
286
		});
287
<?php
288
	}
289
?>
290
});
291 b51d272c Stephen Beaver
292 15281e44 Stephen Beaver
function save_changes_to_xml(xml) {
293
	var ids = $('#mainarea table tbody').sortable('serialize', {key:"ids[]"});
294
	var strloading="<?=gettext('Saving changes...')?>";
295 a16d923f NOYB
	if (confirm("<?=gettext("Confirmation Required to save changes.")?>")) {
296 15281e44 Stephen Beaver
		$.ajax({
297
			type: 'get',
298
			cache: false,
299
			url: "<?=$_SERVER['SCRIPT_NAME']?>",
300
			data: {xml:'<?=$xml?>', act:'update', ids: ids},
301
			beforeSend: function() {
302
				$('#savemsg').empty().html(strloading);
303
			},
304
			error: function(data) {
305
				$('#savemsg').empty().html('Error:' + data);
306
			},
307
			success: function(data) {
308
				$('#savemsg').empty().html(data);
309
			}
310
		});
311 2ef13b6c Stephen Beaver
	}
312
}
313
314 44507df4 Colin Fleming
//]]>
315
</script>
316 f5dbca0d Stephen Beaver
317
<?php
318 0f649c97 Phil Davis
if ($_GET['savemsg'] != "") {
319 f5dbca0d Stephen Beaver
	$savemsg = htmlspecialchars($_GET['savemsg']);
320 0f649c97 Phil Davis
}
321 f5dbca0d Stephen Beaver
322 0f649c97 Phil Davis
if ($savemsg) {
323 f5dbca0d Stephen Beaver
	print_info_box($savemsg, 'success');
324 0f649c97 Phil Davis
}
325 f5dbca0d Stephen Beaver
?>
326
327 5aa9a4f2 Scott Ullrich
<form action="pkg.php" name="pkgform" method="get">
328 f5dbca0d Stephen Beaver
	<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>' />
329 c24bb3fc Stephen Beaver
		<div id="mainarea" class="panel panel-default">
330 b51d272c Stephen Beaver
			<table id="mainarea" class="table table-striped table-hover table-condensed">
331 c24bb3fc Stephen Beaver
				<thead>
332 32c477c5 Scott Ullrich
<?php
333 f8ac4407 Phil Davis
	/* Handle filtering bar A-Z */
334
	$include_filtering_inputbox = false;
335
	$colspan = 0;
336 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
337 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
338
			$colspan++;
339
		}
340
	}
341
	if ($pkg['fields']['field']) {
342
		// First find the sorting type field if it exists
343
		foreach ($pkg['fields']['field'] as $field) {
344
			if ($field['type'] == "sorting") {
345
				if (isset($field['include_filtering_inputbox'])) {
346
					$include_filtering_inputbox = true;
347
				}
348
				if ($display_maximum_rows < 1) {
349
					if ($field['display_maximum_rows']) {
350
						$display_maximum_rows = $field['display_maximum_rows'];
351
					}
352
				}
353 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
354 cadeb9fd Phil Davis
				echo gettext("Filter by: ");
355 f8ac4407 Phil Davis
				$isfirst = true;
356
				for ($char = 65; $char < 91; $char++) {
357
					if (!$isfirst) {
358
						echo " | ";
359
					}
360
					echo "<a href=\"#\" onclick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
361
					$isfirst = false;
362
				}
363
				echo "</td></tr>";
364 79563cb6 Colin Fleming
				echo "<tr><td colspan='$colspan' class='text-center'>";
365 f8ac4407 Phil Davis
				if ($field['sortablefields']) {
366 cadeb9fd Phil Davis
					echo gettext("Filter field: ") . "<select name='pkg_filter_type'>";
367 f8ac4407 Phil Davis
					foreach ($field['sortablefields']['item'] as $si) {
368
						if ($si['name'] == $_REQUEST['pkg_filter_type']) {
369 c4b60a9a Colin Fleming
							$SELECTED = "selected";
370 f8ac4407 Phil Davis
						} else {
371
							$SELECTED = "";
372 32c477c5 Scott Ullrich
						}
373 f8ac4407 Phil Davis
						echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
374 32c477c5 Scott Ullrich
					}
375 f8ac4407 Phil Davis
					echo "</select>";
376 32c477c5 Scott Ullrich
				}
377 f8ac4407 Phil Davis
				if ($include_filtering_inputbox) {
378 27d6a45b jim-p
					echo '&nbsp;&nbsp;' . gettext("Filter text: ") . '<input id="pkg_filter" name="pkg_filter" value="' . $_REQUEST['pkg_filter'] . '" />';
379
					echo '&nbsp;<button type="submit" value="Filter" class="btn btn-primary btn-xs">';
380
					echo '<i class="fa fa-filter icon-embed-btn"></i>';
381
					echo gettext("Filter");
382
					echo "</button>";
383 f8ac4407 Phil Davis
				}
384
				echo "</td></tr><tr><td><font size='-3'>&nbsp;</font></td></tr>";
385
			}
386
		}
387
	}
388 32c477c5 Scott Ullrich
?>
389
				<tr>
390 c24bb3fc Stephen Beaver
391 32c477c5 Scott Ullrich
<?php
392 f8ac4407 Phil Davis
	if ($display_maximum_rows) {
393 6c07db48 Phil Davis
		$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows), 9));
394 f8ac4407 Phil Davis
		$page = 1;
395
		$tmpcount = 0;
396
		$tmppp = 0;
397
		if (is_array($evaledvar)) {
398
			foreach ($evaledvar as $ipa) {
399
				if ($tmpcount == $display_maximum_rows) {
400
					$page++;
401 37da0c50 Scott Ullrich
					$tmpcount = 0;
402
				}
403 f8ac4407 Phil Davis
				if ($tmppp == $startdisplayingat) {
404
					break;
405 32c477c5 Scott Ullrich
				}
406 f8ac4407 Phil Davis
				$tmpcount++;
407
				$tmppp++;
408
			}
409
		}
410 c24bb3fc Stephen Beaver
		echo "<tr><th colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
411 f8ac4407 Phil Davis
		echo "<table width='100%' summary=''>";
412
		echo "<tr>";
413 cadeb9fd Phil Davis
		echo "<td class='text-left'>" . sprintf(gettext('Displaying page %1$s of %2$s'), $page, $totalpages) . "</b></td>";
414
		echo "<td class='text-right'>" . gettext("Rows per page: ") . "<select onchange='document.pkgform.submit();' name='display_maximum_rows'>";
415 6c07db48 Phil Davis
		for ($x = 0; $x < 250; $x++) {
416 f8ac4407 Phil Davis
			if ($x == $display_maximum_rows) {
417 c4b60a9a Colin Fleming
				$SELECTED = "selected";
418 f8ac4407 Phil Davis
			} else {
419
				$SELECTED = "";
420
			}
421
			echo "<option value='$x' $SELECTED>$x</option>\n";
422
			$x = $x + 4;
423
		}
424
		echo "</select></td></tr>";
425
		echo "</table>";
426 c24bb3fc Stephen Beaver
		echo "</th></tr>";
427 f8ac4407 Phil Davis
	}
428 2ef13b6c Stephen Beaver
429 f8ac4407 Phil Davis
	$cols = 0;
430 f5dbca0d Stephen Beaver
	if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
431 f8ac4407 Phil Davis
		foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
432 c24bb3fc Stephen Beaver
			echo "<th class=\"listhdrr\">" . $column['fielddescr'] . "</th>";
433 f8ac4407 Phil Davis
			$cols++;
434
		}
435
	}
436
?>
437
				</tr>
438 c24bb3fc Stephen Beaver
				</thead>
439
				<tbody>
440 f8ac4407 Phil Davis
<?php
441
	$i = 0;
442 6c07db48 Phil Davis
	$pagination_counter = 0;
443 f8ac4407 Phil Davis
	if ($evaledvar) {
444
		foreach ($evaledvar as $ip) {
445
			if ($startdisplayingat) {
446
				if ($i < $startdisplayingat) {
447
					$i++;
448
					continue;
449 32c477c5 Scott Ullrich
				}
450 f8ac4407 Phil Davis
			}
451
			if ($_REQUEST['pkg_filter']) {
452
				// Handle filtered items
453
				if ($pkg['fields']['field'] && !$filter_regex) {
454
					// First find the sorting type field if it exists
455
					foreach ($pkg['fields']['field'] as $field) {
456
						if ($field['type'] == "sorting") {
457
							if ($field['sortablefields']['item']) {
458
								foreach ($field['sortablefields']['item'] as $sf) {
459
									if ($sf['name'] == $_REQUEST['pkg_filter_type']) {
460
										$filter_fieldname = $sf['fieldname'];
461
										#Use a default regex on sortable fields when none is declared
462
										if ($sf['regex']) {
463
											$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
464
										} else {
465
											$filter_regex = "/{$_REQUEST['pkg_filter']}/i";
466 32c477c5 Scott Ullrich
										}
467
									}
468
								}
469
							}
470
						}
471
					}
472 f8ac4407 Phil Davis
				}
473
				// Do we have something to filter on?
474
				unset($filter_matches);
475 f5dbca0d Stephen Beaver
				if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
476 f8ac4407 Phil Davis
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
477
						$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
478
						if ($column['fieldname'] == $filter_fieldname) {
479
							if ($filter_regex) {
480
								//echo "$filter_regex - $fieldname<p/>";
481
								preg_match($filter_regex, $fieldname, $filter_matches);
482
								break;
483 32c477c5 Scott Ullrich
							}
484
						}
485
					}
486
				}
487 f8ac4407 Phil Davis
				if (!$filter_matches) {
488
					$i++;
489
					continue;
490
				}
491
			}
492
			if ($pkg['adddeleteeditpagefields']['movable']) {
493 8d659bf1 NOYB
				echo "<tr style=\"vertical-align: top\" class=\"sortable\" id=\"id_{$i}\">\n";
494 f8ac4407 Phil Davis
			} else {
495 8d659bf1 NOYB
				echo "<tr style=\"vertical-align: top\">\n";
496 f8ac4407 Phil Davis
			}
497 f5dbca0d Stephen Beaver
			if ($pkg['adddeleteeditpagefields']['columnitem'] != "") {
498 f8ac4407 Phil Davis
				foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
499
					if ($column['fieldname'] == "description") {
500
						$class = "listbg";
501
					} else {
502
						$class = "listlr";
503
					}
504 32c477c5 Scott Ullrich
?>
505 f5dbca0d Stephen Beaver
					<td class="<?=$class?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&amp;act=edit&amp;id=<?=$i?>';">
506 32c477c5 Scott Ullrich
<?php
507 f8ac4407 Phil Davis
					$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
508
					#Check if columnitem has a type field declared
509
					if ($column['type'] == "checkbox") {
510
						if ($fieldname == "") {
511
							echo gettext("No");
512
						} else {
513
							echo gettext("Yes");
514
						}
515
					} else if ($column['type'] == "interface") {
516 6c07db48 Phil Davis
						echo $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
517 f8ac4407 Phil Davis
					} else {
518 45c50e6f jim-p
						$display_text = "";
519 f8ac4407 Phil Davis
						#Check if columnitem has an encoding field declared
520
						if ($column['encoding'] == "base64") {
521 45c50e6f jim-p
							$display_text = $column['prefix'] . base64_decode($fieldname) . $column['suffix'];
522 f8ac4407 Phil Davis
						#Check if there is a custom info to show when $fieldname is not empty
523
						} else if ($column['listmodeon'] && $fieldname != "") {
524 45c50e6f jim-p
							$display_text = $column['prefix'] . gettext($column['listmodeon']). $column['suffix'];
525 f8ac4407 Phil Davis
						#Check if there is a custom info to show when $fieldname is empty
526
						} else if ($column['listmodeoff'] && $fieldname == "") {
527 45c50e6f jim-p
							$display_text = $column['prefix'] .gettext($column['listmodeoff']). $column['suffix'];
528 f8ac4407 Phil Davis
						} else {
529 45c50e6f jim-p
							$display_text = $column['prefix'] . $fieldname ." ". $column['suffix'];
530 f8ac4407 Phil Davis
						}
531 45c50e6f jim-p
						if (!isset($column['allow_html'])) {
532
							$display_text = htmlspecialchars($display_text);
533
						}
534
						echo $display_text;
535 32c477c5 Scott Ullrich
					}
536
?>
537 f8ac4407 Phil Davis
					</td>
538 32c477c5 Scott Ullrich
<?php
539 f8ac4407 Phil Davis
				} // foreach columnitem
540
			} // if columnitem
541
?>
542 8d659bf1 NOYB
					<td style="vertical-align: middle" class="list text-nowrap">
543 f8ac4407 Phil Davis
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
544
							<tr>
545
<?php
546
			#Show custom description to edit button if defined
547 cadeb9fd Phil Davis
			$edit_msg=($pkg['adddeleteeditpagefields']['edittext']?$pkg['adddeleteeditpagefields']['edittext']:gettext("Edit this item"));
548 f8ac4407 Phil Davis
?>
549 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>
550 f8ac4407 Phil Davis
<?php
551
			#Show custom description to delete button if defined
552 cadeb9fd Phil Davis
			$delete_msg=($pkg['adddeleteeditpagefields']['deletetext']?$pkg['adddeleteeditpagefields']['deletetext']:gettext("Delete this item"));
553 f8ac4407 Phil Davis
?>
554 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>
555 f8ac4407 Phil Davis
							</tr>
556 c24bb3fc Stephen Beaver
						</tbody>
557
					</table>
558 b51d272c Stephen Beaver
				</td>
559 f8ac4407 Phil Davis
<?php
560 f5dbca0d Stephen Beaver
			echo "</tr>\n"; // Pairs with an echo tr some way above
561 f8ac4407 Phil Davis
			// Handle pagination and display_maximum_rows
562
			if ($display_maximum_rows) {
563
				if ($pagination_counter == ($display_maximum_rows-1) or
564 f5dbca0d Stephen Beaver
					$i == (count($evaledvar)-1)) {
565 f8ac4407 Phil Davis
					$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
566
					$final_footer = "";
567
					$final_footer .= "<tr><td colspan='$colcount'>";
568 6c07db48 Phil Davis
					$final_footer .= "<table width='100%' summary=''><tr>";
569 79563cb6 Colin Fleming
					$final_footer .= "<td class='text-left'>";
570 f8ac4407 Phil Davis
					$startingat = $startdisplayingat - $display_maximum_rows;
571
					if ($startingat > -1) {
572 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat={$startingat}&amp;display_maximum_rows={$display_maximum_rows}'>";
573 f8ac4407 Phil Davis
					} else if ($startdisplayingat > 1) {
574 6c07db48 Phil Davis
						$final_footer .= "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&amp;startdisplayingat=0&amp;display_maximum_rows={$display_maximum_rows}'>";
575 32c477c5 Scott Ullrich
					}
576 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'><< " . gettext("Previous page") . "</font></a>";
577 f8ac4407 Phil Davis
					if ($tmppp + $display_maximum_rows > count($evaledvar)) {
578
						$endingrecord = count($evaledvar);
579
					} else {
580
						$endingrecord = $tmppp + $display_maximum_rows;
581
					}
582 79563cb6 Colin Fleming
					$final_footer .= "</td><td class='text-center'>";
583 f8ac4407 Phil Davis
					$tmppp++;
584 6c07db48 Phil Davis
					$final_footer .= "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
585 79563cb6 Colin Fleming
					$final_footer .= "</font></td><td class='text-right'>&nbsp;";
586 f8ac4407 Phil Davis
					if (($i+1) < count($evaledvar)) {
587 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}'>";
588 f8ac4407 Phil Davis
					}
589 cadeb9fd Phil Davis
					$final_footer .= "<font size='2'>" . gettext("Next page") . " >></font></a>";
590 6c07db48 Phil Davis
					$final_footer .= "</td></tr></table></td></tr>";
591 f8ac4407 Phil Davis
					$i = count($evaledvar);
592
					break;
593 549912e3 Scott Ullrich
				}
594 f8ac4407 Phil Davis
			}
595
			$i++;
596
			$pagination_counter++;
597
		} // foreach evaledvar
598
	} // if evaledvar
599 32c477c5 Scott Ullrich
?>
600
				<tr>
601
					<td colspan="<?=$cols?>"></td>
602
					<td>
603 44507df4 Colin Fleming
						<table border="0" cellspacing="0" cellpadding="1" summary="icons">
604 32c477c5 Scott Ullrich
							<tr>
605 f8ac4407 Phil Davis
<?php
606
	#Show custom description to add button if defined
607 cadeb9fd Phil Davis
	$add_msg=($pkg['adddeleteeditpagefields']['addtext']?$pkg['adddeleteeditpagefields']['addtext']:gettext("Add a new item"));
608 f8ac4407 Phil Davis
?>
609 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>
610 f8ac4407 Phil Davis
<?php
611
	#Show description button and info if defined
612
	if ($pkg['adddeleteeditpagefields']['description']) {
613
?>
614 995df6c3 Stephen Beaver
								<td>
615 7ea65674 Jared Dillard
									<i class="fa fa-info-circle"><?=$pkg['adddeleteeditpagefields']['description']?></i>
616 995df6c3 Stephen Beaver
								</td>
617 f8ac4407 Phil Davis
<?php
618
	}
619
?>
620 32c477c5 Scott Ullrich
							</tr>
621
						</table>
622
					</td>
623
				</tr>
624 37da0c50 Scott Ullrich
				<?=$final_footer?>
625 f8ac4407 Phil Davis
			</table>
626 c24bb3fc Stephen Beaver
			</div>
627 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>
628 3d335c4d Scott Ullrich
629 a7f908db Scott Ullrich
</form>
630 b000f96f Scott Ullrich
<?php
631 f5dbca0d Stephen Beaver
echo "<!-- filter_fieldname: {$filter_fieldname} -->";
632
echo "<!-- filter_regex: {$filter_regex} -->";
633 b000f96f Scott Ullrich
634 f5dbca0d Stephen Beaver
include("foot.inc"); ?>