Projet

Général

Profil

Télécharger (39 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / pkg_edit.php @ 0fab7eb1

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
				return false;
301
			}
302
	    });
303
	    
304
		//add new line jQuery function
305
		jQuery('#mainarea table .add').click(function() {
306
			//get table size and assign as new id
307
			var c_id=jQuery("#maintable tr").length;
308
			var new_row=jQuery("table#maintable tr:last").html().replace(/(name|id)="(\w+)(\d+)"/g,"$1='$2"+c_id+"'");
309
			//apply new id to created line rowhelperid
310
			jQuery("table#maintable tr:last").after("<tr>"+new_row+"<\/tr>");
311
			return false;
312
	    });
313
		// Call enablechange function
314
		enablechange();
315
	});
316

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

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

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

    
339
			echo "\t}\n\telse {\n";
340

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

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

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

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

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

    
406
		$tab_array[$tab_level][] = array(
407
						$tab['text'],
408
						$active,
409
						$url
410
					);
411
    	}
412

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
715
				echo $input;
716
				echo $script;
717
                                break;
718

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

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

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

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

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

    
827
					$rowcounter = 0;
828
					$trc = 0;
829

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

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

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

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

    
939
</table>
940
</div></td></tr>
941
</table>
942
</form>
943

    
944
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
945

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

    
962
<?php include("fend.inc"); ?>
963
</body>
964
</html>
965

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

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

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

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

    
1106
		/* replace cr's */
1107
		$template_text = str_replace("\\n", "\n", $template_text);
1108

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

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

    
1124
?>
(129-129/254)