Project

General

Profile

Download (38.5 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(!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 ((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
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
271
<script type="text/javascript" src="/javascript/suggestions.js"></script>
272

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

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

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

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

    
333
			echo "\t}\n\telse {\n";
334

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
702
				$script = "<script type='text/javascript'>\n";
703
				$script .= "var aliasarray = new Array({$aliasesaddr})\n";
704
				$script .= "var oTextbox1 = new AutoSuggestControl(document.getElementById('{$fieldname}'), new StateSuggestions(aliasarray))\n";
705
				$script .= "</script>";
706

    
707
				echo $input;
708
				echo $script;
709
                                break;
710

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

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

    
776
			case "radio":
777
				$input = "<input type='radio' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' value='{$value}'>";
778
				if(isset($pkga['advancedfield']) && isset($adv_filed_count))
779
					$advanced .= $input;
780
				else
781
					echo $input;
782
					break;
783

    
784
			case "button":
785
				$input = "<input type='submit' id='{$pkga['fieldname']}' name='{$pkga['fieldname']}' class='formbtn' value='{$pkga['fieldname']}'>\n";
786
				if(isset($pkga['placeonbottom']))
787
					$pkg_buttons .= $input;
788
				else
789
					echo $input ."\n<br>" . fixup_string($pkga['description']) . "\n";;
790
				break;
791

    
792
			case "rowhelper":
793
				#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
794
				$rowhelpername="row";
795
				?>
796
				<script type="text/javascript" language='javascript'>
797
				<!--
798
				<?php
799
					$rowcounter = 0;
800
					$fieldcounter = 0;
801
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
802
						echo "rowname[{$fieldcounter}] = \"{$rowhelper['fieldname']}\";\n";
803
						echo "rowtype[{$fieldcounter}] = \"{$rowhelper['type']}\";\n";
804
						echo "rowsize[{$fieldcounter}] = \"{$rowhelper['size']}\";\n";
805
						$fieldcounter++;
806
					}
807
				?>
808
				-->
809
				</script>
810
				<table name="maintable" id="maintable">
811
				<tr id='<?="tr_{$pkga['fieldname']}";?>'>
812
				<?php
813
					foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
814
					  echo "<td ".domTT_title($rowhelper['description'])."><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
815
					}
816

    
817
					$rowcounter = 0;
818
					$trc = 0;
819

    
820
					//Use assigned $a_pkg or create an empty array to enter loop
821
					if(isset($a_pkg[$id][$rowhelpername]))
822
						$saved_rows=$a_pkg[$id][$rowhelpername];
823
					else
824
						$saved_rows[]=array();
825

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

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

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

    
929
</table>
930
</div></td></tr>
931
</table>
932
</form>
933

    
934
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
935

    
936
<?php
937
	/* JavaScript to handle the advanced fields. */
938
	if ($pkg['advanced_options'] == "enabled") {
939
		echo "<script type=\"text/javascript\">\n";
940
		foreach($js_array as $advfieldname) {
941
			echo "function show_" . $advfieldname . "() {\n";
942
			echo "\tjQuery('#showadv_{$advfieldname}').empty();\n";
943
			echo "\tjQuery('#show_{$advfieldname}').css('display', 'block');\n";
944
			echo "}\n\n";
945
		}
946
		echo "</script>\n";
947
	}
948
?>
949

    
950
<?php include("fend.inc"); ?>
951
</body>
952
</html>
953

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

    
1022
function fixup_string($string) {
1023
	global $config;
1024
	// fixup #1: $myurl -> http[s]://ip_address:port/
1025
	$https = "";
1026
	$port = $config['system']['webguiport'];
1027
	if($port <> "443" and $port <> "80")
1028
		$urlport = ":" . $port;
1029
	else
1030
		$urlport = "";
1031

    
1032
	if($config['system']['webgui']['protocol'] == "https") $https = "s";
1033
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
1034
	$newstring = str_replace("\$myurl", $myurl, $string);
1035
	$string = $newstring;
1036
	// fixup #2: $wanip
1037
	$curwanip = get_interface_ip();
1038
	$newstring = str_replace("\$wanip", $curwanip, $string);
1039
	$string = $newstring;
1040
	// fixup #3: $lanip
1041
	$lancfg = $config['interfaces']['lan'];
1042
	$lanip = $lancfg['ipaddr'];
1043
	$newstring = str_replace("\$lanip", $lanip, $string);
1044
	$string = $newstring;
1045
	// fixup #4: fix'r'up here.
1046
	return $newstring;
1047
}
1048

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

    
1093
		/* replace cr's */
1094
		$template_text = str_replace("\\n", "\n", $template_text);
1095

    
1096
		/* write out new template file */
1097
		$fout = fopen($filename,"w");
1098
		fwrite($fout, $template_text);
1099
		fclose($fout);
1100
	    }
1101
}
1102

    
1103
/* Return html div fields */
1104
function display_advanced_field($fieldname) {
1105
	$div = "<div id='showadv_{$fieldname}'>\n";
1106
	$div .= "<input type='button' onClick='show_{$fieldname}()' value='" . gettext("Advanced") . "'></input> - " . gettext("Show advanced option") ."</div>\n";
1107
	$div .= "<div id='show_{$fieldname}' style='display:none'>\n";
1108
	return $div;
1109
}
1110

    
1111
?>
(128-128/249)