Project

General

Profile

Download (39 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    pkg_edit.php
5
    Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
6
    All rights reserved.
7

    
8
    Redistribution and use in source and binary forms, with or without
9
    modification, 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 the
16
       documentation and/or other materials provided with the distribution.
17

    
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29
/*
30
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
31
	pfSense_MODULE:	pkgs
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-package-edit
36
##|*NAME=Package: Edit page
37
##|*DESCR=Allow access to the 'Package: Edit' page.
38
##|*MATCH=pkg_edit.php*
39
##|-PRIV
40

    
41
ini_set('max_execution_time', '0');
42

    
43
require("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47
require_once("pkg-utils.inc");
48

    
49
/* dummy stubs needed by some code that was MFC'd */
50
function pfSenseHeader($location) { header("Location: " . $location); }
51

    
52
function gentitle_pkg($pgname) {
53
	global $pfSense_config;
54
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
55
}
56

    
57
function domTT_title($title_msg){
58
	if (!empty($title_msg)){
59
		$title_msg=preg_replace("/\s+/"," ",$title_msg);
60
        $title_msg=preg_replace("/'/","\'",$title_msg);
61
		return "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '{$title_msg}', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'delay',300,'styleClass', 'niceTitle');\"";
62
	}
63
}
64

    
65
$xml = htmlspecialchars($_GET['xml']);
66
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
67

    
68
if($xml == "") {
69
            print_info_box_np(gettext("ERROR: No package defined."));
70
            die;
71
} else {
72
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
73
}
74

    
75
if($pkg['include_file'] <> "") {
76
	require_once($pkg['include_file']);
77
}
78

    
79
if (!isset($pkg['adddeleteeditpagefields']))
80
	$only_edit = true;
81
else
82
	$only_edit = false;
83

    
84
$package_name = $pkg['menu'][0]['name'];
85
$section      = $pkg['menu'][0]['section'];
86
$config_path  = $pkg['configpath'];
87
$name         = $pkg['name'];
88
$title        = $pkg['title'];
89
$pgtitle      = $title;
90

    
91
$id = $_GET['id'];
92
if (isset($_POST['id']))
93
	$id = htmlspecialchars($_POST['id']);
94

    
95
// Not posting?  Then user is editing a record. There must be a valid id
96
// when editing a record.
97
if(!$id && !$_POST)
98
	$id = "0";
99

    
100
if(!is_numeric($id)) {
101
	Header("Location: /");
102
	exit;
103
}
104

    
105
if($pkg['custom_php_global_functions'] <> "")
106
        eval($pkg['custom_php_global_functions']);
107

    
108
// grab the installedpackages->package_name section.
109
if($config['installedpackages'] && !is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
110
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
111

    
112
// If the first entry in the array is an empty <config/> tag, kill it.
113
if ($config['installedpackages'] && (count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0) 
114
	&& ($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == ""))
115
	array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
116

    
117
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
118

    
119
if($_GET['savemsg'] <> "")
120
	$savemsg = htmlspecialchars($_GET['savemsg']);
121

    
122
if($pkg['custom_php_command_before_form'] <> "")
123
	eval($pkg['custom_php_command_before_form']);
124

    
125
if ($_POST) {
126
	$firstfield = "";
127
	$rows = 0;
128

    
129
	$input_errors = array();
130
	$reqfields = array();
131
	$reqfieldsn = array();
132
	foreach ($pkg['fields']['field'] as $field) {
133
		if (($field['type'] == 'input') && isset($field['required'])) {
134
			if($field['fieldname'])
135
				$reqfields[] = $field['fieldname'];
136
			if($field['fielddescr'])
137
				$reqfieldsn[] = $field['fielddescr'];
138
		}
139
	}
140
	do_input_validation($_POST, $reqfields, $reqfieldsn, $input_errors);
141

    
142
	if ($pkg['custom_php_validation_command'])
143
		eval($pkg['custom_php_validation_command']);
144

    
145
	if($_POST['act'] == "del") {
146
		if($pkg['custom_delete_php_command']) {
147
		    if($pkg['custom_php_command_before_form'] <> "")
148
			    eval($pkg['custom_php_command_before_form']);
149
		    eval($pkg['custom_delete_php_command']);
150
		}
151
		write_config($pkg['delete_string']);
152
		// resync the configuration file code if defined.
153
		if($pkg['custom_php_resync_config_command'] <> "") {
154
			if($pkg['custom_php_command_before_form'] <> "")
155
				eval($pkg['custom_php_command_before_form']);
156
			eval($pkg['custom_php_resync_config_command']);
157
		}
158
	} else {
159
		if(!$input_errors && $pkg['custom_add_php_command']) {
160
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
161
			?>
162

    
163
<?php include("head.inc"); ?>
164
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
165
<?php include("fbegin.inc"); ?>
166
<?php
167
			}
168
			if($pkg['preoutput']) echo "<pre>";
169
			eval($pkg['custom_add_php_command']);
170
			if($pkg['preoutput']) echo "</pre>";
171
		}
172
	}
173

    
174
	// donotsave is enabled.  lets simply exit.
175
	if(empty($pkg['donotsave'])) {
176

    
177
		// store values in xml configration file.
178
		if (!$input_errors) {
179
			$pkgarr = array();
180
			foreach ($pkg['fields']['field'] as $fields) {
181
				switch($fields['type']){
182
					case "rowhelper":
183
						// save rowhelper items.
184
						#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
185
						$rowhelpername="row";
186
						foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield)
187
							foreach($_POST as $key => $value){
188
								if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/",$key,$matches))
189
									$pkgarr[$rowhelpername][$matches[1]][$rowhelperfield['fieldname']]=$value;
190
							}
191
						break;
192
					default:
193
						$fieldname  = $fields['fieldname'];
194
						if ($fieldname == "interface_array") {
195
							$fieldvalue = $_POST[$fieldname];
196
						} elseif (is_array($_POST[$fieldname])) {
197
							$fieldvalue = implode(',', $_POST[$fieldname]);
198
						} else {
199
							$fieldvalue = trim($_POST[$fieldname]);
200
							if ($fields['encoding'] == 'base64')
201
								$fieldvalue = base64_encode($fieldvalue);
202
						}
203
						if($fieldname)
204
							$pkgarr[$fieldname] = $fieldvalue;
205
					}
206
			}
207

    
208
			if (isset($id) && $a_pkg[$id])
209
				$a_pkg[$id] = $pkgarr;
210
			else
211
				$a_pkg[] = $pkgarr;
212

    
213
			write_config($pkg['addedit_string']);
214
			// late running code
215
			if($pkg['custom_add_php_command_late'] <> "") {
216
			    eval($pkg['custom_add_php_command_late']);
217
			}
218

    
219
			if (isset($pkg['filter_rules_needed']))
220
				filter_configure();
221

    
222
			// resync the configuration file code if defined.
223
			if($pkg['custom_php_resync_config_command'] <> "") {
224
			    eval($pkg['custom_php_resync_config_command']);
225
			}
226

    
227
			parse_package_templates();
228

    
229
			/* if start_command is defined, restart w/ this */
230
			if($pkg['start_command'] <> "")
231
			    exec($pkg['start_command'] . ">/dev/null 2&>1");
232

    
233
			/* if restart_command is defined, restart w/ this */
234
			if($pkg['restart_command'] <> "")
235
			    exec($pkg['restart_command'] . ">/dev/null 2&>1");
236

    
237
			if($pkg['aftersaveredirect'] <> "") {
238
			    pfSenseHeader($pkg['aftersaveredirect']);
239
			} elseif(!$pkg['adddeleteeditpagefields']) {
240
			    pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
241
			} elseif(!$pkg['preoutput']) {
242
			    pfSenseHeader("pkg.php?xml=" . $xml);
243
			}
244
			exit;
245
		} else {
246
			$get_from_post = true;
247
		}
248
	} elseif (!$input_errors) {
249
		exit;
250
	}
251
}
252

    
253
if($pkg['title'] <> "") {
254
	$edit = ($only_edit ? '' : ": " .  gettext("Edit"));
255
	$title = $pkg['title'] . $edit;
256
}
257
else
258
	$title = gettext("Package Editor");
259

    
260
$pgtitle = $title;
261
include("head.inc");
262

    
263
if ($pkg['custom_php_after_head_command'])
264
	eval($pkg['custom_php_after_head_command']);
265

    
266
?>
267

    
268
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
269

    
270
<?php include("fbegin.inc"); ?>
271

    
272
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
273
<script type="text/javascript" src="/javascript/suggestions.js"></script>
274

    
275
<?php if($pkg['fields']['field'] <> "") { ?>
276
<script type="text/javascript">
277
//<![CDATA[
278
	//Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded
279
	jQuery(document).ready(function() {
280
		
281
		//Sortable function
282
		jQuery('#mainarea table tbody').sortable({
283
			items: 'tr.sortable',
284
			cursor: 'move',
285
			distance: 10,
286
			opacity: 0.8,
287
			helper: function(e,ui){  
288
				ui.children().each(function(){  
289
					jQuery(this).width(jQuery(this).width());  
290
				});
291
			return ui;  
292
			},
293
		});
294
		
295
		//delete current line jQuery function
296
		jQuery('#maintable td .delete').live('click', function() {
297
			//do not remove first line
298
			if (jQuery("#maintable tr").length > 2)
299
				jQuery(this).parent().parent().remove();
300
	    });
301
	    
302
		//add new line jQuery function
303
		jQuery('#mainarea table .add').click(function() {
304
			//get table size and assign as new id
305
			var c_id=jQuery("#maintable tr").length;
306
			var new_row=jQuery("table#maintable tr:last").html().replace(/(name|id)="(\w+)(\d+)"/g,"$1='$2"+c_id+"'");
307
			//apply new id to created line rowhelperid
308
			jQuery("table#maintable tr:last").after("<tr>"+new_row+"<\/tr>");
309
	    });
310
		// Call enablechange function
311
		enablechange();
312
	});
313

    
314
	function enablechange() {
315
	<?php
316
	foreach ($pkg['fields']['field'] as $field) {
317
		if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
318
			echo "\tif (jQuery('form[name=\"iform\"] input[name=\"{$field['fieldname']}\"]').prop('checked') == false) {\n";
319

    
320
			if (isset($field['enablefields'])) {
321
				foreach (explode(',', $field['enablefields']) as $enablefield) {
322
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').length > 0) {\n";
323
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').prop('disabled',true);\n";
324
					echo "\t\t}\n";
325
				}
326
			}
327

    
328
			if (isset($field['checkenablefields'])) {
329
				foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
330
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').length > 0) {\n";
331
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').prop('checked',true);\n";
332
					echo "\t\t}\n";
333
				}
334
			}
335

    
336
			echo "\t}\n\telse {\n";
337

    
338
			if (isset($field['enablefields'])) {
339
				foreach (explode(',', $field['enablefields']) as $enablefield) {
340
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').length > 0) {\n";
341
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$enablefield}\"]').prop('disabled',false);\n";
342
					echo "\t\t}\n";
343
				}
344
			}
345

    
346
			if (isset($field['checkenablefields'])) {
347
				foreach(explode(',', $field['checkenablefields']) as $checkenablefield) {
348
					echo "\t\tif (jQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').length > 0) {\n";
349
					echo "\t\t\tjQuery('form[name=\"iform\"] input[name=\"{$checkenablefield}\"]').prop('checked',false);\n";
350
					echo "\t\t}\n";
351
				}
352
			}
353

    
354
			echo "\t}\n";
355
		}
356
	}
357
	?>
358
}
359
//]]>
360
</script>
361
<?php } ?>
362
<script type="text/javascript" src="javascript/domTT/domLib.js"></script>
363
<script type="text/javascript" src="javascript/domTT/domTT.js"></script>
364
<script type="text/javascript" src="javascript/domTT/behaviour.js"></script>
365
<script type="text/javascript" src="javascript/domTT/fadomatic.js"></script>
366
<script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script>
367

    
368
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
369
<form name="iform" action="pkg_edit.php" method="post">
370
<input type="hidden" name="xml" value="<?= htmlspecialchars($xml) ?>" />
371
<?php if ($savemsg) print_info_box($savemsg); ?>
372
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="package edit">
373
<?php
374
if ($pkg['tabs'] <> "") {
375
	$tab_array = array();
376
	foreach($pkg['tabs']['tab'] as $tab) {
377
		if($tab['tab_level'])
378
			$tab_level = $tab['tab_level'];
379
		else
380
			$tab_level = 1;
381
		if(isset($tab['active'])) {
382
			$active = true;
383
		} else {
384
			$active = false;
385
		}
386
		if(isset($tab['no_drop_down']))
387
			$no_drop_down = true;
388
		$urltmp = "";
389
		if($tab['url'] <> "") $urltmp = $tab['url'];
390
		if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
391

    
392
 		$addresswithport = getenv("HTTP_HOST");
393
		$colonpos = strpos($addresswithport, ":");
394
		if ($colonpos !== False) {
395
			//my url is actually just the IP address of the pfsense box
396
			$myurl = substr($addresswithport, 0, $colonpos);
397
		} else {
398
			$myurl = $addresswithport;
399
		}
400
		// eval url so that above $myurl item can be processed if need be.
401
		$url = str_replace('$myurl', $myurl, $urltmp);
402

    
403
		$tab_array[$tab_level][] = array(
404
						$tab['text'],
405
						$active,
406
						$url
407
					);
408
    	}
409

    
410
	ksort($tab_array);
411
	foreach($tab_array as $tabid => $tab) {
412
		echo '<tr><td>';
413
		display_top_tabs($tab, $no_drop_down, $tabid);
414
		echo '</td></tr>';
415
	}
416
}
417

    
418
?>
419
<tr><td><div id="mainarea"><table id="t" class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
420
<?php
421
	$cols = 0;
422
	$savevalue = gettext("Save");
423
	if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
424
	/* If a package's XML has <advanced_options/> configured, then setup 
425
	 * the table rows for the fields that have <advancedfield/> set.
426
	 * These fields will be placed below other fields in a seprate area titled 'Advanced Features'.
427
	 * These advanced fields are not normally configured and generally left to default to 'default settings'.
428
	 */
429

    
430
	if ($pkg['advanced_options'] == "enabled") {
431
		$adv_filed_count = 0;
432
		$advanced = "<td>&nbsp;</td>";
433
		$advanced .= "<tr><td colspan=\"2\" class=\"listtopic\">". gettext("Advanced features") . "<br/></td></tr>\n";
434
		}		
435
	foreach ($pkg['fields']['field'] as $pkga) {
436
		if ($pkga['type'] == "sorting") 
437
			continue;
438

    
439
		if ($pkga['type'] == "listtopic") {
440
			$input = "<tr id='td_{$pkga['fieldname']}'><td>&nbsp;</td></tr>";
441
			$input .= "<tr id='tr_{$pkga['fieldname']}'><td colspan=\"2\" class=\"listtopic\">{$pkga['name']}<br/></td></tr>\n";
442
			if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
443
				$advanced .= $input;
444
				$adv_filed_count++;
445
				}
446
			else
447
				echo $input;
448
			continue;
449
		}
450

    
451
		if($pkga['combinefields']=="begin"){
452
			$input="<tr valign='top' id='tr_{$pkga['fieldname']}'>";
453
			if(isset($pkga['advancedfield']) && isset($adv_filed_count))
454
				$advanced .= $input;
455
			else
456
			  	echo $input;
457
			}
458

    
459
		$size = "";
460
		if (isset($pkga['dontdisplayname'])){
461
			$input="";
462
			if(!isset($pkga['combinefields']))
463
				$input .= "<tr valign='top' id='tr_{$pkga['fieldname']}'>";
464
			if(isset($pkga['usecolspan2']))
465
				$colspan="colspan='2'";
466
			else
467
				$input .= "<td width='22%' class='vncell{$req}'>&nbsp;</td>";
468
			if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
469
				$advanced .= $input;
470
				$adv_filed_count++;
471
				}
472
			else
473
				echo $input;
474
			}
475
		else if (!isset($pkga['placeonbottom'])){
476
			unset($req);
477
			if (isset($pkga['required']))
478
				$req = 'req';
479
			$input= "<tr><td valign='top' width=\"22%\" class=\"vncell{$req}\">";
480
			$input .= fixup_string($pkga['fielddescr']);
481
			$input .= "</td>";
482
			if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
483
				$advanced .= $input;
484
				$adv_filed_count++;
485
				}
486
			else 
487
				echo $input;
488
		}
489
		if($pkga['combinefields']=="begin"){
490
			$input="<td class=\"vncell\"><table summary=\"advanced\">";
491
			if(isset($pkga['advancedfield']) && isset($adv_filed_count))
492
				$advanced .= $input;
493
			else
494
			  	echo $input;
495
			}
496

    
497
		$class=(isset($pkga['combinefields']) ? '' : 'class="vtable"');
498
		if (!isset($pkga['placeonbottom'])){
499
			$input="<td valign='top' {$colspan} {$class}>";
500
			if(isset($pkga['advancedfield']) && isset($adv_filed_count)){
501
				$advanced .= $input;
502
				$adv_filed_count++;
503
				}
504
			else
505
				echo $input;
506
		}
507

    
508
		// if user is editing a record, load in the data.
509
		$fieldname = $pkga['fieldname'];
510
		if ($get_from_post) {
511
			$value = $_POST[$fieldname];
512
			if (is_array($value)) $value = implode(',', $value);
513
		} else {
514
			if (isset($id) && $a_pkg[$id])
515
				$value = $a_pkg[$id][$fieldname];
516
			else
517
				$value = $pkga['default_value'];
518
		}
519
		switch($pkga['type']){
520
			case "input":
521
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
522
				$input = "<input {$size} id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formfld unknown' value=\"" . htmlspecialchars($value) ."\" />\n";
523
				$input .= "<br/>" . fixup_string($pkga['description']) . "\n";
524
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
525
					$js_array[] = $pkga['fieldname'];
526
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
527
					}
528
				else
529
					echo $input;
530
				break;
531

    
532
			case "password":
533
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
534
				$input = "<input " . $size . " id='" . $pkga['fieldname'] . "' type='password' name='" . $pkga['fieldname'] . "' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
535
				$input .= "<br/>" . fixup_string($pkga['description']) . "\n";
536
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
537
					$js_array[] = $pkga['fieldname'];
538
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
539
					}
540
				else
541
					echo $input;
542
				break;
543

    
544
			case "info":
545
				$input = fixup_string($pkga['description']) . "\n";
546
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
547
					$js_array[] = $pkga['fieldname'];
548
					$advanced .= display_advanced_field($pkga['fieldname']).$input ."</div>\n";
549
					}
550
				else
551
					echo $input;
552
				break;
553

    
554
			case "select":
555
				$fieldname = $pkga['fieldname'];
556
				if (isset($pkga['multiple'])) {
557
					$multiple = 'multiple="multiple"';
558
					$items = explode(',', $value);
559
					$fieldname .= "[]";
560
				} else {
561
					$multiple = '';
562
					$items = array($value);
563
				}
564
				$size = ($pkga['size'] ? " size='{$pkga['size']}' " : "");
565
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
566
				$input = "<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange name=\"$fieldname\">\n";
567
				foreach ($pkga['options']['option'] as $opt) {
568
					$selected = (in_array($opt['value'], $items) ? 'selected="selected"' : '');
569
					$input .= "\t<option value=\"{$opt['value']}\" {$selected}>{$opt['name']}</option>\n";
570
					}
571
				$input .= "</select>\n<br />\n" . fixup_string($pkga['description']) . "\n";
572
                if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
573
					$js_array[] = $pkga['fieldname'];
574
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
575
					$advanced .= "</div>\n";
576
					}
577
				else
578
					echo $input;
579
				break;
580

    
581
			case "select_source":
582
				$fieldname = $pkga['fieldname'];
583
				if (isset($pkga['multiple'])) {
584
					$multiple = 'multiple="multiple"';
585
					$items = explode(',', $value);
586
					$fieldname .= "[]";
587
				} else {
588
					$multiple = '';
589
					$items = array($value);
590
				}
591
				$size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
592
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
593
				$input = "<select id='{$pkga['fieldname']}' {$multiple} {$size} {$onchange} name=\"{$fieldname}\">\n";
594

    
595
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
596
					$js_array[] = $pkga['fieldname'];
597
					$advanced .= display_advanced_field($pkga['fieldname']) .$input;
598
					$advanced .= "</div>\n";
599
				} else {
600
					echo $input;
601
				}
602
				$source_url = $pkga['source'];
603
				eval("\$pkg_source_txt = &$source_url;");
604
				$input="";
605
				#check if show disable option is present on xml
606
				if(isset($pkga['show_disable_value'])){
607
					array_push($pkg_source_txt, array(($pkga['source_name']? $pkga['source_name'] : $pkga['name'])=> $pkga['show_disable_value'],
608
													  ($pkga['source_value']? $pkga['source_value'] : $pkga['value'])=> $pkga['show_disable_value']));
609
					}
610
				foreach ($pkg_source_txt as $opt) {
611
					$source_name =($pkga['source_name']? $opt[$pkga['source_name']] : $opt[$pkga['name']]);
612
					$source_value =($pkga['source_value'] ? $opt[$pkga['source_value']] : $opt[$pkga['value']]);
613
					$selected = (in_array($source_value, $items)? 'selected="selected"' : '' );
614
					$input  .= "\t<option value=\"{$source_value}\" $selected>{$source_name}</option>\n";
615
					}
616
				$input .= "</select>\n<br />\n" . fixup_string($pkga['description']) . "\n";
617
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
618
					$advanced .= $input;
619
				else
620
					echo $input;
621
				break;
622

    
623
			case "vpn_selection" :
624
				$input = "<select id='{$pkga['fieldname']}' name='{$vpn['name']}'>\n";
625
				foreach ($config['ipsec']['phase1'] as $vpn) {
626
					$input .= "\t<option value=\"{$vpn['descr']}\">{$vpn['descr']}</option>\n";
627
					}
628
				$input .= "</select>\n";
629
				$input .= "<br/>" . fixup_string($pkga['description']) . "\n";
630

    
631
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
632
					$js_array[] = $pkga['fieldname'];
633
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
634
					$advanced .= "</div>\n";
635
					}
636
				else
637
					echo $input;
638
				break;
639

    
640
			case "checkbox":
641
				$checkboxchecked =($value == "on" ? " checked=\"checked\"" : "");
642
				$onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
643
				if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
644
					$onclick = ' onclick="javascript:enablechange();"';
645
				$input = "<input id='{$pkga['fieldname']}' type='checkbox' name='{$pkga['fieldname']}' {$checkboxchecked} {$onclick} {$onchange} />\n";
646
				$input .= "<br/>" . fixup_string($pkga['description']) . "\n";
647

    
648
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
649
					$js_array[] = $pkga['fieldname'];
650
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
651
					$advanced .= "</div>\n";
652
					}
653
				else
654
					echo $input;
655
				break;
656

    
657
			case "textarea":
658
				if($pkga['rows'])
659
					$rows = " rows='{$pkga['rows']}' ";
660
				if($pkga['cols'])
661
					$cols = " cols='{$pkga['cols']}' ";
662
				if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value))
663
					$value = base64_decode($value);
664
				$wrap =($pkga['wrap'] == "off" ? 'wrap="off" style="white-space:nowrap;"' : '');		  
665
				$input = "<textarea {$rows} {$cols} name='{$pkga['fieldname']}'{$wrap}>{$value}</textarea>\n";
666
				$input .= "<br/>" . fixup_string($pkga['description']) . "\n";
667
				if(isset($pkga['advancedfield']) && isset($adv_filed_count)) {
668
					$js_array[] = $pkga['fieldname'];
669
					$advanced .= display_advanced_field($pkga['fieldname']).$input;
670
					$advanced .= "</div>\n";
671
					}
672
				else
673
					echo $input;
674
				break;
675

    
676
			case "aliases":
677
				// Use xml tag <typealiases> to filter type aliases
678
				$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
679
				$fieldname = $pkga['fieldname'];
680
				$a_aliases = &$config['aliases']['alias'];
681
				$addrisfirst = 0;
682
				$aliasesaddr = "";
683
				$value = "value='{$value}'";
684

    
685
				if(isset($a_aliases)) {
686
					if(!empty($pkga['typealiases'])) {
687
						foreach($a_aliases as $alias)
688
							if($alias['type'] == $pkga['typealiases']) {
689
								if($addrisfirst == 1) $aliasesaddr .= ",";
690
								$aliasesaddr .= "'" . $alias['name'] . "'";
691
								$addrisfirst = 1;
692
							}
693
					} else {
694
						foreach($a_aliases as $alias) {
695
							if($addrisfirst == 1) $aliasesaddr .= ",";
696
							$aliasesaddr .= "'" . $alias['name'] . "'";
697
							$addrisfirst = 1;
698
						}
699
					}
700
				}
701

    
702
				$input = "<input name='{$fieldname}' type='text' class='formfldalias' id='{$fieldname}' {$size} {$value} />\n<br />";
703
				$input .= fixup_string($pkga['description']) . "\n";
704

    
705
				$script = "<script type='text/javascript'>\n";
706
				$script .= "//<![CDATA[\n";
707
				$script .= "var aliasarray = new Array({$aliasesaddr})\n";
708
				$script .= "var oTextbox1 = new AutoSuggestControl(document.getElementById('{$fieldname}'), new StateSuggestions(aliasarray))\n";
709
				$script .= "//]]>\n";
710
				$script .= "</script>";
711

    
712
				echo $input;
713
				echo $script;
714
                                break;
715

    
716
			case "interfaces_selection":
717
				$ips=array();
718
				$interface_regex=(isset($pkga['hideinterfaceregex']) ? $pkga['hideinterfaceregex'] : "nointerfacestohide");
719
				if (is_array($config['interfaces']))
720
					foreach ($config['interfaces'] as $iface_key=>$iface_value){
721
						if (isset($iface_value['enable']) && ! preg_match("/$interface_regex/",$iface_key)){
722
							$iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
723
							if (isset($pkga['showips']))
724
								$iface_description .= " address";
725
							$ips[]=array('ip'=> $iface_key, 'description'=> $iface_description);
726
							}
727
					}
728
				if (is_array($config['virtualip']) && isset($pkga['showvirtualips']))
729
					foreach ($config['virtualip']['vip'] as $vip){
730
						if (! preg_match("/$interface_regex/",$vip['interface']))
731
						$vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
732
						  switch ($vip['mode']){
733
							case "ipalias":
734
							case "carp":
735
									$ips[]=array(   'ip'=> $vip['subnet'],'description' => "{$vip['subnet']} $vip_description");
736
								break;
737
							case "proxyarp":
738
								if ($vip['type']=="network"){
739
									$start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
740
									$end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
741
									$len = $end - $start;
742
									for ($i = 0; $i <= $len; $i++)
743
										$ips[]= array('ip'=>long2ip32($start+$i),'description'=> long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
744
									}
745
								else{
746
									$ips[]= array('ip'=>$vip['subnet'],'description'=> "{$vip['subnet']} $vip_description");
747
									}
748
								break;
749
							}
750
					}
751
				sort($ips);
752
				if (isset($pkga['showlistenall']))
753
					array_unshift($ips,array('ip'=> 'All', 'description'=> 'Listen on All interfaces/ip addresses '));
754
				if (! preg_match("/$interface_regex/","loopback")){
755
					$iface_description=(isset($pkga['showips']) ? "127.0.0.1 (loopback)" : "loopback");
756
					array_push($ips,array('ip'=> 'lo0', 'description'=> $iface_description));
757
					}
758

    
759
				#show interfaces array on gui
760
				$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
761
				$multiple = '';
762
				$fieldname = $pkga['fieldname'];
763
				if (isset($pkga['multiple'])) {
764
					$fieldname .= '[]';
765
					$multiple = 'multiple="multiple"';
766
					}
767
				$input = "<select id='{$pkga['fieldname']}' name=\"{$fieldname}\" {$size} {$multiple}>\n";
768
				if(is_array($value))
769
					$values = $value;
770
				else
771
					$values  =  explode(',',  $value);
772
				foreach($ips as $iface){
773
					$selected = (in_array($iface['ip'], $values) ? 'selected="selected"' : '');
774
					$input .= "<option value=\"{$iface['ip']}\" {$selected}>{$iface['description']}</option>\n";
775
					}
776
				$input .= "</select>\n<br />" . fixup_string($pkga['description']) . "\n";
777
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
778
					$advanced .= $input;
779
				else
780
					echo $input;
781
				break;
782

    
783
			case "radio":
784
				$input = "<input type='radio' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' value='{$value}' />";
785
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
786
					$advanced .= $input;
787
				else
788
					echo $input;
789
					break;
790

    
791
			case "button":
792
				$input = "<input type='submit' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formbtn' value='{$pkga['fieldname']}' />\n";
793
				if(isset($pkga['placeonbottom']))
794
					$pkg_buttons .= $input;
795
				else
796
					echo $input ."\n<br/>" . fixup_string($pkga['description']) . "\n";;
797
				break;
798

    
799
			case "rowhelper":
800
				#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
801
				$rowhelpername="row";
802
				?>
803
				<script type="text/javascript">
804
				//<![CDATA[
805
				<?php
806
					$rowcounter = 0;
807
					$fieldcounter = 0;
808
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
809
						echo "rowname[{$fieldcounter}] = \"{$rowhelper['fieldname']}\";\n";
810
						echo "rowtype[{$fieldcounter}] = \"{$rowhelper['type']}\";\n";
811
						echo "rowsize[{$fieldcounter}] = \"{$rowhelper['size']}\";\n";
812
						$fieldcounter++;
813
					}
814
				?>
815
				//]]>
816
				</script>
817
				<table id="maintable" summary="main table">
818
				<tr id='<?="tr_{$pkga['fieldname']}";?>'>
819
				<?php
820
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
821
					  echo "<td ".domTT_title($rowhelper['description'])."><b>" . fixup_string($rowhelper['fielddescr']) . "</b></td>\n";
822
					}
823

    
824
					$rowcounter = 0;
825
					$trc = 0;
826

    
827
					//Use assigned $a_pkg or create an empty array to enter loop
828
					if(isset($a_pkg[$id][$rowhelpername]))
829
						$saved_rows=$a_pkg[$id][$rowhelpername];
830
					else
831
						$saved_rows[]=array();
832

    
833
					foreach($saved_rows as $row) {
834
						echo "</tr>\n<tr class=\"sortable\" id=\"id_{$rowcounter}\">\n";
835
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
836
							unset($value);
837
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
838
							$fieldname = $rowhelper['fieldname'];
839
							// if user is editing a record, load in the data.
840
							if (isset($id) && $a_pkg[$id]) {
841
								$value = $row[$fieldname];
842
							}
843
							$options = "";
844
							$type = $rowhelper['type'];
845
							$description = $rowhelper['description'];
846
							$fieldname = $rowhelper['fieldname'];
847
							if($type == "option")
848
								$options = &$rowhelper['options']['option'];
849
							if($rowhelper['size']) 
850
								$size = $rowhelper['size'];
851
							else if ($pkga['size'])
852
								$size = $pkga['size'];
853
							else
854
								$size = "8";
855
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
856

    
857
							$text = "";
858
							$trc++;
859
							}
860
						$rowcounter++;
861
						echo "<td>";
862
						#echo "<a onclick=\"removeRow(this); return false;\" href=\"#\"><img border=\"0\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" alt=\"remove\" /></a>";
863
						echo "<a class='delete' href=\"#\"><img border='0' src='./themes/{$g['theme']}/images/icons/icon_x.gif' alt='delete' /></a>";
864
						echo "</td>\n";
865
						}
866
				?>
867
				</tr>
868
				<tbody></tbody>
869
				</table>
870
	
871
				<!-- <br/><a onclick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?#= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>-->
872
				<br/><a class="add" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>
873
				<br/><?php if($pkga['description'] != "") echo $pkga['description']; ?>
874
				<script type="text/javascript">
875
				//<![CDATA[
876
				field_counter_js = <?= $fieldcounter ?>;
877
				rows = <?= $rowcounter ?>;
878
				totalrows = <?php echo $rowcounter; ?>;
879
				loaded = <?php echo $rowcounter; ?>;
880
				//typesel_change();
881
				//]]>
882
				</script>
883
		
884
				<?php
885
				break;
886
		    }
887
		#check typehint value
888
	   	if($pkga['typehint'])
889
	   		echo " " . $pkga['typehint'];
890
	   	#check combinefields options
891
     	if (isset($pkga['combinefields'])){
892
     		$input="</td>";
893
			if ($pkga['combinefields']=="end")
894
           		$input.="</table></td></tr>";
895
      		}
896
     	else{
897
			$input= "</td></tr>";
898
			if($pkga['usecolspan2'])
899
				$input.= "</tr><br/>";
900
	     	}
901
   	 	if(isset($pkga['advancedfield']) && isset($adv_filed_count))
902
			$advanced .= "{$input}\n";
903
		else
904
			echo "{$input}\n";
905
		#increment counter
906
		$i++;
907
  		}
908

    
909
  	#print advanced settings if any after reading all fields
910
	if (isset($advanced) && $adv_filed_count > 0)
911
		echo $advanced;
912
  
913
	?>
914
  <tr>
915
	<td>&nbsp;</td>
916
  </tr>
917
  <tr>
918
    <td width="22%" valign="top">&nbsp;</td>
919
    <td width="78%">
920
    <div id="buttons">
921
		<?php
922
		if($pkg['note'] != ""){
923
			echo "<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>";
924
			}
925
		//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
926
		echo "<input name='id' type='hidden' value=\"" . htmlspecialchars($id) . "\" />";
927
		echo "<input name='Submit' type='submit' class='formbtn' value=\"" . htmlspecialchars($savevalue) . "\" />\n{$pkg_buttons}\n";
928
		if (!$only_edit){
929
			echo "<input class='formbtn' type='button' value='".gettext("Cancel")."' onclick='history.back()' />";
930
			}
931
		?>
932
	</div>
933
    </td>
934
  </tr>
935

    
936
</table>
937
</div></td></tr>
938
</table>
939
</form>
940

    
941
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
942

    
943
<?php
944
	/* JavaScript to handle the advanced fields. */
945
	if ($pkg['advanced_options'] == "enabled") {
946
		echo "<script type=\"text/javascript\">\n";
947
		echo "//<![CDATA[\n";
948
		foreach($js_array as $advfieldname) {
949
			echo "function show_" . $advfieldname . "() {\n";
950
			echo "\tjQuery('#showadv_{$advfieldname}').empty();\n";
951
			echo "\tjQuery('#show_{$advfieldname}').css('display', 'block');\n";
952
			echo "}\n\n";
953
		}
954
		echo "//]]>\n";
955
		echo "</script>\n";
956
	}
957
?>
958

    
959
<?php include("fend.inc"); ?>
960
</body>
961
</html>
962

    
963
<?php
964
/*
965
 * ROW Helpers function
966
 */
967
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
968
	global $text, $config;
969
	echo "<td>\n";
970
	switch($type){
971
		case "input":
972
			echo "<input size='{$size}' name='{$fieldname}{$trc}' id='{$fieldname}{$trc}' class='formfld unknown' value=\"" . htmlspecialchars($value) . "\" />\n";
973
			break;
974
		case "checkbox":
975
			echo "<input size='{$size}' type='checkbox' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' value='ON' ".($value?"CHECKED":"")." />\n";
976
			break;
977
		case "password":
978
			echo "<input size='{$size}' type='password' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
979
			break;
980
		case "textarea":
981
			echo "<textarea rows='2' cols='12' id='{$fieldname}{$trc}' class='formfld unknown' name='{$fieldname}{$trc}'>{$value}</textarea>\n";
982
		case "select":
983
			echo "<select style='height:22px;'  id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$title}>\n";
984
			foreach($rowhelper['options']['option'] as $rowopt) {
985
				$text .= "<option value='{$rowopt['value']}'>{$rowopt['name']}</option>";
986
				echo "<option value='{$rowopt['value']}'".($rowopt['value'] == $value?" selected=\"selected\"":"").">{$rowopt['name']}</option>\n";
987
				}
988
			echo "</select>\n";
989
			break;
990
		case "interfaces_selection":
991
			$size = ($size ? "size=\"{$size}\"" : '');
992
			$multiple = '';
993
			if (isset($rowhelper['multiple'])) {
994
				$fieldname .= '[]';
995
				$multiple = "multiple=\"multiple\"";
996
			}
997
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
998
			$ifaces = get_configured_interface_with_descr();
999
			$additional_ifaces = $rowhelper['add_to_interfaces_selection'];
1000
			if (!empty($additional_ifaces))
1001
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
1002
			if(is_array($value))
1003
				$values = $value;
1004
			else
1005
				$values  =  explode(',',  $value);
1006
			$ifaces["lo0"] = "loopback";
1007
			echo "<option><name></name><value></value></option>/n";
1008
			foreach($ifaces as $ifname => $iface) {
1009
				$text .="<option value=\"{$ifname}\">$iface</option>";
1010
				echo "<option value=\"{$ifname}\" ".(in_array($ifname, $values) ? 'selected="selected"' : '').">{$iface}</option>\n";
1011
				}
1012
			echo "</select>\n";
1013
			break;
1014
		case "select_source":
1015
			echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}'>\n";
1016
			if(isset($rowhelper['show_disable_value']))
1017
				echo "<option value='{$rowhelper['show_disable_value']}'>{$rowhelper['show_disable_value']}</option>\n";
1018
			$source_url = $rowhelper['source'];
1019
			eval("\$pkg_source_txt = &$source_url;");
1020
			foreach($pkg_source_txt as $opt) {
1021
				$source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
1022
				$source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
1023
				$text .= "<option value='{$source_value}'>{$source_name}</option>";
1024
				echo "<option value='{$source_value}'".($source_value == $value?" selected=\"selected\"":"").">{$source_name}</option>\n";
1025
				}
1026
			echo "</select>\n";
1027
			break;		
1028
		}
1029
	echo "</td>\n";
1030
}
1031

    
1032
function fixup_string($string) {
1033
	global $config;
1034
	// fixup #1: $myurl -> http[s]://ip_address:port/
1035
	$https = "";
1036
	$port = $config['system']['webguiport'];
1037
	if($port <> "443" and $port <> "80")
1038
		$urlport = ":" . $port;
1039
	else
1040
		$urlport = "";
1041

    
1042
	if($config['system']['webgui']['protocol'] == "https") $https = "s";
1043
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
1044
	$newstring = str_replace("\$myurl", $myurl, $string);
1045
	$string = $newstring;
1046
	// fixup #2: $wanip
1047
	$curwanip = get_interface_ip();
1048
	$newstring = str_replace("\$wanip", $curwanip, $string);
1049
	$string = $newstring;
1050
	// fixup #3: $lanip
1051
	$lancfg = $config['interfaces']['lan'];
1052
	$lanip = $lancfg['ipaddr'];
1053
	$newstring = str_replace("\$lanip", $lanip, $string);
1054
	$string = $newstring;
1055
	// fixup #4: fix'r'up here.
1056
	return $newstring;
1057
}
1058

    
1059
/*
1060
 *  Parse templates if they are defined
1061
 */
1062
function parse_package_templates() {
1063
	global $pkg, $config;
1064
	$rows = 0;
1065
	if($pkg['templates']['template'] <> "")
1066
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
1067
			$filename = $pkg_template_row['filename'];
1068
			$template_text = $pkg_template_row['templatecontents'];
1069
			$firstfield = "";
1070
			/* calculate total row helpers count and */
1071
			/* change fields defined as fieldname_fieldvalue to their value */
1072
			foreach ($pkg['fields']['field'] as $fields) {
1073
				switch($fields['type']){
1074
					case "rowhelper":
1075
					// save rowhelper items.
1076
					$row_helper_total_rows = 0;
1077
					$row_helper_data = "";
1078
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield)
1079
						foreach($_POST as $key => $value){
1080
							if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/",$key,$matches)){
1081
								$row_helper_total_rows++;
1082
								$row_helper_data .= $value;
1083
								$sep = "";
1084
								ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
1085
								foreach ($sep as $se) $separator = $se;
1086
								if($separator <> "") {
1087
							    	$row_helper_data = ereg_replace("  ", $separator, $row_helper_data);
1088
							    	$template_text = ereg_replace("\[{$separator}\]", "", $template_text);
1089
									}
1090
								$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
1091
								}
1092
							}
1093
					break;
1094
				default:
1095
					$fieldname  = $fields['fieldname'];
1096
					$fieldvalue = $_POST[$fieldname];
1097
					$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
1098
				}
1099
			}
1100
		/* replace $domain_total_rows with total rows */
1101
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
1102

    
1103
		/* replace cr's */
1104
		$template_text = str_replace("\\n", "\n", $template_text);
1105

    
1106
		/* write out new template file */
1107
		$fout = fopen($filename,"w");
1108
		fwrite($fout, $template_text);
1109
		fclose($fout);
1110
	    }
1111
}
1112

    
1113
/* Return html div fields */
1114
function display_advanced_field($fieldname) {
1115
	$div = "<div id='showadv_{$fieldname}'>\n";
1116
	$div .= "<input type='button' onclick='show_{$fieldname}()' value='" . gettext("Advanced") . "' /> - " . gettext("Show advanced option") ."</div>\n";
1117
	$div .= "<div id='show_{$fieldname}' style='display:none'>\n";
1118
	return $div;
1119
}
1120

    
1121
?>
(129-129/249)