Project

General

Profile

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