Project

General

Profile

Download (29.8 KB) Statistics
| Branch: | Tag: | Revision:
1 d47013e1 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 d47013e1 Scott Ullrich
/*
4
    pkg_edit.php
5 4f6a5e6a Scott Ullrich
    Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
6 d47013e1 Scott Ullrich
    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 1d333258 Scott Ullrich
/*
30
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
31
	pfSense_MODULE:	pkgs
32
*/
33 d47013e1 Scott Ullrich
34 6b07c15a Matthew Grooms
##|+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 0089af7c Scott Ullrich
ini_set('max_execution_time', '0');
42
43 7a927e67 Scott Ullrich
require("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47 f8e335a3 Scott Ullrich
require_once("pkg-utils.inc");
48 d47013e1 Scott Ullrich
49 14db714e Scott Ullrich
/* dummy stubs needed by some code that was MFC'd */
50 916b74c6 Scott Ullrich
function pfSenseHeader($location) { header("Location: " . $location); }
51 14db714e Scott Ullrich
52 d47013e1 Scott Ullrich
function gentitle_pkg($pgname) {
53
	global $pfSense_config;
54
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
55
}
56
57 d8c1a6c5 Scott Ullrich
$xml = htmlspecialchars($_GET['xml']);
58
if($_POST['xml']) $xml = htmlspecialchars($_POST['xml']);
59 d47013e1 Scott Ullrich
60
if($xml == "") {
61 b91540da Scott Ullrich
            print_info_box_np(gettext("ERROR: No package defined."));
62 d47013e1 Scott Ullrich
            die;
63
} else {
64 19a11678 Colin Smith
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
65 d47013e1 Scott Ullrich
}
66 7c172009 Scott Ullrich
67
if($pkg['include_file'] <> "") {
68
	require_once($pkg['include_file']);
69
}
70
71 b91540da Scott Ullrich
if (!isset($pkg['adddeleteeditpagefields']))
72
	$only_edit = true;
73
else
74
	$only_edit = false;
75
76 a28c8b59 Scott Ullrich
$package_name = $pkg['menu'][0]['name'];
77
$section      = $pkg['menu'][0]['section'];
78 d47013e1 Scott Ullrich
$config_path  = $pkg['configpath'];
79 bb940538 Scott Ullrich
$name         = $pkg['name'];
80 b91540da Scott Ullrich
$title        = $pkg['title'];
81 96d9f5c9 Bill Marquette
$pgtitle      = $title;
82 d47013e1 Scott Ullrich
83 da7bf505 Scott Ullrich
$id = $_GET['id'];
84
if (isset($_POST['id']))
85 d8c1a6c5 Scott Ullrich
	$id = htmlspecialchars($_POST['id']);
86 916b74c6 Scott Ullrich
	
87
// Not posting?  Then user is editing a record. There must be a valid id
88
// when editing a record.
89
if(!$id && !$_POST)
90
	$id = "0";
91
	
92 529ffadb Bill Marquette
if($pkg['custom_php_global_functions'] <> "")
93
        eval($pkg['custom_php_global_functions']);
94
95 31d27c6c Scott Ullrich
// grab the installedpackages->package_name section.
96 e315cfa1 Colin Smith
if(!is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']))
97 7db8ff99 Colin Smith
	$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
98 da7bf505 Scott Ullrich
99 a2a7f74d jim-p
// If the first entry in the array is an empty <config/> tag, kill it.
100
if ((count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0) 
101
	&& ($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == ""))
102
	array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
103
104 7db8ff99 Colin Smith
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
105 da7bf505 Scott Ullrich
106 19d360bf Scott Ullrich
if($_GET['savemsg'] <> "")
107 d8c1a6c5 Scott Ullrich
	$savemsg = htmlspecialchars($_GET['savemsg']);
108 f9a91638 Scott Ullrich
109 194b4e0a Colin Smith
if($pkg['custom_php_command_before_form'] <> "")
110
	eval($pkg['custom_php_command_before_form']);
111 f9a91638 Scott Ullrich
112 6483da5d Scott Ullrich
if ($_POST) {
113 b3235baa Scott Ullrich
	if($_POST['act'] == "del") {
114
		if($pkg['custom_delete_php_command']) {
115 5cd30ac3 Scott Ullrich
		    if($pkg['custom_php_command_before_form'] <> "")
116
			    eval($pkg['custom_php_command_before_form']);
117 b3235baa Scott Ullrich
		    eval($pkg['custom_delete_php_command']);
118
		}
119 7c172009 Scott Ullrich
		write_config($pkg['delete_string']);
120 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
121
		if($pkg['custom_php_resync_config_command'] <> "") {
122 86f3fc00 Scott Ullrich
			if($pkg['custom_php_command_before_form'] <> "")
123
				eval($pkg['custom_php_command_before_form']);
124
			eval($pkg['custom_php_resync_config_command']);
125 facd08f9 Scott Ullrich
		}
126 b3235baa Scott Ullrich
	} else {
127
		if($pkg['custom_add_php_command']) {
128 90779bf7 Scott Ullrich
			if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
129 12123e25 Colin Smith
			?>
130 afe4a7d3 Erik Kristensen
131 539b4c44 Colin Smith
<?php include("head.inc"); ?>
132 3eaeb703 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
133 2fe6c52b Colin Smith
<?php include("fbegin.inc"); ?>
134 fbd14b13 Scott Ullrich
<?php
135 3eaeb703 Scott Ullrich
			}
136
			if($pkg['preoutput']) echo "<pre>";
137
			eval($pkg['custom_add_php_command']);
138
			if($pkg['preoutput']) echo "</pre>";
139 b3235baa Scott Ullrich
		}
140 6483da5d Scott Ullrich
	}
141 e3c4b6b7 Scott Ullrich
142 eec70f21 Scott Ullrich
	// donotsave is enabled.  lets simply exit.
143 3eaeb703 Scott Ullrich
	if($pkg['donotsave'] <> "") exit;
144
145 b6e87566 Scott Ullrich
	$firstfield = "";
146
	$rows = 0;
147
148 7c172009 Scott Ullrich
	$input_errors = array();
149
	$reqfields = array();
150
	$reqfieldsn = array();
151
	foreach ($pkg['fields']['field'] as $field) {
152 b91540da Scott Ullrich
		if (($field['type'] == 'input') && isset($field['required'])) {
153 349ef5c9 Scott Ullrich
			if($field['fieldname'])
154
				$reqfields[] = $field['fieldname'];
155
			if($field['fielddescr'])	
156
				$reqfieldsn[] = $field['fielddescr'];
157 7c172009 Scott Ullrich
		}
158
	}
159
	do_input_validation($_POST, $reqfields, $reqfieldsn, &$input_errors);
160
161
	if ($pkg['custom_php_validation_command'])
162
		eval($pkg['custom_php_validation_command']);
163
164 b3235baa Scott Ullrich
	// store values in xml configration file.
165
	if (!$input_errors) {
166
		$pkgarr = array();
167
		foreach ($pkg['fields']['field'] as $fields) {
168 969a36ce Scott Ullrich
			if($fields['type'] == "sorting")
169
				continue;
170 41fd0445 Scott Ullrich
			if($fields['type'] == "listtopic")
171
				continue;
172 eec70f21 Scott Ullrich
			if($fields['type'] == "rowhelper") {
173
				// save rowhelper items.
174
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
175 628b33c1 Scott Ullrich
				                         // XXX: this really is not helping embedded platforms.
176 0e730fee Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
177 b6e87566 Scott Ullrich
						if($firstfield == "")  {
178
						  $firstfield = $rowhelperfield['fieldname'];
179
						} else {
180
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
181
						}
182 6e32d276 Scott Ullrich
						$fieldname = str_replace("\\", "", $rowhelperfield['fieldname']);
183 13e92c36 Scott Ullrich
						$comd = "\$value = \$_POST['" . $fieldname . $x . "'];";
184 eec70f21 Scott Ullrich
						eval($comd);
185
						if($value <> "") {
186 6e32d276 Scott Ullrich
							$comd = "\$pkgarr['row'][" . $x . "]['" . $fieldname . "'] = \"" . $value . "\";";
187 b6e87566 Scott Ullrich
							//echo($comd . "<br>");
188 eec70f21 Scott Ullrich
							eval($comd);
189
						}
190
					}
191
				}
192
			} else {
193
				$fieldname  = $fields['fieldname'];
194 fbd14b13 Scott Ullrich
				$fieldvalue = $_POST[$fieldname];
195
				if (is_array($fieldvalue))
196
					$fieldvalue = implode(',', $fieldvalue);
197
				else {
198
					$fieldvalue = trim($fieldvalue);
199
					if ($fields['encoding'] == 'base64')
200
						$fieldvalue = base64_encode($fieldvalue);
201
				}
202 349ef5c9 Scott Ullrich
				if($fieldname)
203
					$pkgarr[$fieldname] = $fieldvalue;
204 eec70f21 Scott Ullrich
			}
205 b3235baa Scott Ullrich
		}
206 0e730fee Scott Ullrich
207 e3c4b6b7 Scott Ullrich
		if (isset($id) && $a_pkg[$id])
208
			$a_pkg[$id] = $pkgarr;
209
		else
210
			$a_pkg[] = $pkgarr;
211 0e730fee Scott Ullrich
212 7c172009 Scott Ullrich
		write_config($pkg['addedit_string']);
213 facd08f9 Scott Ullrich
		// late running code
214 2a520a0a Scott Ullrich
		if($pkg['custom_add_php_command_late'] <> "") {
215
		    eval($pkg['custom_add_php_command_late']);
216
		}
217 0e730fee Scott Ullrich
218 b8d220ab Scott Ullrich
		if (isset($pkg['filter_rules_needed'])) 
219 07bcca25 Ermal Lu?i
			filter_configure();
220 a9b2e638 Ermal Lu?i
221 facd08f9 Scott Ullrich
		// resync the configuration file code if defined.
222
		if($pkg['custom_php_resync_config_command'] <> "") {
223
		    eval($pkg['custom_php_resync_config_command']);
224
		}
225
226 dcbe6f52 Scott Ullrich
		parse_package_templates();
227
228 a485a6f5 Scott Ullrich
		/* if start_command is defined, restart w/ this */
229
		if($pkg['start_command'] <> "")
230
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
231
232
		/* if restart_command is defined, restart w/ this */
233
		if($pkg['restart_command'] <> "")
234
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
235
236 dcbe6f52 Scott Ullrich
		if($pkg['aftersaveredirect'] <> "") {
237 fbd14b13 Scott Ullrich
		    pfSenseHeader($pkg['aftersaveredirect']);
238 3089059e Colin Smith
		} elseif(!$pkg['adddeleteeditpagefields']) {
239 fbd14b13 Scott Ullrich
		    pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
240 3089059e Colin Smith
		} elseif(!$pkg['preoutput']) {
241 fbd14b13 Scott Ullrich
		    pfSenseHeader("pkg.php?xml=" . $xml);
242 dcbe6f52 Scott Ullrich
		}
243 0e730fee Scott Ullrich
		exit;
244 e3c4b6b7 Scott Ullrich
	}
245 7c172009 Scott Ullrich
	else
246
		$get_from_post = true;
247 da7bf505 Scott Ullrich
}
248
249 b91540da Scott Ullrich
if($pkg['title'] <> "") {
250 f0d1af93 Carlos Eduardo Ramos
	$edit = ($only_edit ? '' : ": " .  gettext("Edit"));
251 b91540da Scott Ullrich
	$title = $pkg['title'] . $edit;
252
}
253 83ddedcd Scott Ullrich
else
254 b91540da Scott Ullrich
	$title = gettext("Package Editor");
255 83ddedcd Scott Ullrich
256
$pgtitle = $title;
257
include("head.inc");
258
259 7c172009 Scott Ullrich
if ($pkg['custom_php_after_head_command'])
260
	eval($pkg['custom_php_after_head_command']);
261
262 d47013e1 Scott Ullrich
?>
263
264 2fe6c52b Colin Smith
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onLoad="enablechange();">
265
<?php if($pkg['fields']['field'] <> "") { ?>
266
<script language="JavaScript">
267
<!--
268
function enablechange() {
269 3c616886 Scott Ullrich
<?php
270 fbd14b13 Scott Ullrich
foreach ($pkg['fields']['field'] as $field) {
271
	if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
272
		print("\tif (document.iform.elements[\"{$field['fieldname']}\"].checked == false) {\n");
273
274
		if (isset($field['enablefields'])) {
275 dcf6d563 Manoel Carvalho
			foreach (explode(',', $field['enablefields']) as $enablefield) {
276
				print("\t\tif(document.iform.elements[\"$enablefield\"]){\n");
277
				print("\t\t\tdocument.iform.elements[\"$enablefield\"].disabled = 1;\n");
278
				print("\t\t}else{\n");
279
				print("\t\t\tdocument.iform.elements[\"$enablefield".'[]'."\"].disabled = 1;\n");
280
				print("\t\t}\n");
281
			}
282 fbd14b13 Scott Ullrich
		}
283
284
		if (isset($field['checkenablefields'])) {
285 dcf6d563 Manoel Carvalho
			foreach (explode(',', $field['checkenablefields']) as $checkenablefield) {
286
				print("\t\tif(document.iform.elements[\"$checkenablefield\"]){\n");
287
				print("\t\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 0;\n");
288
				print("\t\t}else{\n");
289
				print("\t\t\tdocument.iform.elements[\"$checkenablefield".'[]'."\"].checked = 0;\n");
290
				print("\t\t}\n");
291
			}
292 fbd14b13 Scott Ullrich
		}
293
294
		print("\t}\n\telse {\n");
295
296
		if (isset($field['enablefields'])) {
297 dcf6d563 Manoel Carvalho
			foreach (explode(',', $field['enablefields']) as $enablefield) {
298
				print("\t\tif(document.iform.elements[\"$enablefield\"]){\n");
299
				print("\t\t\tdocument.iform.elements[\"$enablefield\"].disabled = 0;\n");
300
				print("\t\t}else{\n");
301
				print("\t\t\tdocument.iform.elements[\"$enablefield".'[]'."\"].disabled = 0;\n");
302
				print("\t\t}\n");
303
			}
304 fbd14b13 Scott Ullrich
		}
305
306
		if (isset($field['checkenablefields'])) {
307 dcf6d563 Manoel Carvalho
			foreach(explode(',', $field['checkenablefields']) as $checkenablefield) {
308
				print("\t\tif(document.iform.elements[\"$checkenablefield\"]){\n");
309
				print("\t\t\tdocument.iform.elements[\"$checkenablefield\"].checked = 1;\n");
310
				print("\t\t}else{\n");
311
				print("\t\t\tdocument.iform.elements[\"$checkenablefield".'[]'."\"].checked = 1;\n");
312
				print("\t\t}\n");
313
			}
314 fbd14b13 Scott Ullrich
		}
315
316
		print("\t}\n");
317
	}
318
}
319 2fe6c52b Colin Smith
?>
320
}
321
//-->
322
</script>
323
<?php } ?>
324 625dcc40 Bill Marquette
<script type="text/javascript" language="javascript" src="/javascript/row_helper_dynamic.js">
325 eec70f21 Scott Ullrich
</script>
326
327 96d9f5c9 Bill Marquette
<?php include("fbegin.inc"); ?>
328 7c172009 Scott Ullrich
<?php if (!empty($input_errors)) print_input_errors($input_errors); ?>
329
<form name="iform" action="pkg_edit.php" method="post">
330 19fd2947 Scott Ullrich
<input type="hidden" name="xml" value="<?= $xml ?>">
331 d47013e1 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
332 f4cb26b7 Colin Smith
<table width="100%" border="0" cellpadding="0" cellspacing="0">
333 7c061036 Scott Ullrich
<?php
334
if ($pkg['tabs'] <> "") {
335 f4cb26b7 Colin Smith
    echo '<tr><td>';
336
    $tab_array = array();
337 7c061036 Scott Ullrich
    foreach($pkg['tabs']['tab'] as $tab) {
338 f4cb26b7 Colin Smith
	if(isset($tab['active'])) {
339
		$active = true;
340
	} else {
341
		$active = false;
342
	}
343 e17ce934 Scott Ullrich
	$urltmp = "";
344
	if($tab['url'] <> "") $urltmp = $tab['url'];
345
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
346
347 656a2fea Seth Mos
 	$addresswithport = getenv("HTTP_HOST");
348
	$colonpos = strpos($addresswithport, ":");
349
	if ($colonpos !== False){
350
		//my url is actually just the IP address of the pfsense box
351
		$myurl = substr($addresswithport, 0, $colonpos);
352
	}
353
	else
354
	{
355
		$myurl = $addresswithport;
356
	}
357 e17ce934 Scott Ullrich
	// eval url so that above $myurl item can be processed if need be.
358 f4cb26b7 Colin Smith
	$url = str_replace('$myurl', $myurl, $urltmp);
359 656a2fea Seth Mos
360 f4cb26b7 Colin Smith
	$tab_array[] = array(
361
				$tab['text'],
362
				$active,
363
				$url
364
			);
365 7c061036 Scott Ullrich
    }
366 f4cb26b7 Colin Smith
    display_top_tabs($tab_array);
367
    echo '</td></tr>';
368 7c061036 Scott Ullrich
}
369
?>
370 f4cb26b7 Colin Smith
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
371 d47013e1 Scott Ullrich
  <?php
372
  $cols = 0;
373 457106da Renato Botelho
  $savevalue = gettext("Save");
374 3eaeb703 Scott Ullrich
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
375 32487e42 Scott Ullrich
  foreach ($pkg['fields']['field'] as $pkga) { 
376 969a36ce Scott Ullrich
		if ($pkga['type'] == "sorting") 
377
			continue;
378 32487e42 Scott Ullrich
379
		if ($pkga['type'] == "listtopic") {
380
			echo "<td>&nbsp;</td>";
381
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $pkga['name'] . "<br></td></tr>\n";
382
			continue;
383
	    }	
384
	
385
?>
386 3c616886 Scott Ullrich
387 facd08f9 Scott Ullrich
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
388
389 d47013e1 Scott Ullrich
	  <?php
390 3c616886 Scott Ullrich
391 5c74f339 Scott Ullrich
	  $size = "";
392 3c616886 Scott Ullrich
393 facd08f9 Scott Ullrich
	  if(!$pkga['dontdisplayname']) {
394 7c172009 Scott Ullrich
		unset($req);
395 b91540da Scott Ullrich
		if (isset($pkga['required']))
396 7c172009 Scott Ullrich
			$req = 'req';
397
		echo "<td width=\"22%\" class=\"vncell{$req}\">";
398 d51f86e0 Scott Ullrich
		echo fixup_string($pkga['fielddescr']);
399 31d27c6c Scott Ullrich
		echo "</td>";
400 facd08f9 Scott Ullrich
	  }
401
402
	  if(!$pkga['dontcombinecells'])
403
		echo "<td class=\"vtable\">";
404 31d27c6c Scott Ullrich
		// if user is editing a record, load in the data.
405 7c172009 Scott Ullrich
		$fieldname = $pkga['fieldname'];
406 fbd14b13 Scott Ullrich
		if ($get_from_post) {
407 7c172009 Scott Ullrich
			$value = $_POST[$fieldname];
408 fbd14b13 Scott Ullrich
			if (is_array($value)) $value = implode(',', $value);
409
		}
410 7c172009 Scott Ullrich
		else {
411
			if (isset($id) && $a_pkg[$id])
412
				$value = $a_pkg[$id][$fieldname];
413 b91540da Scott Ullrich
			else
414
				$value = $pkga['default_value'];
415 31d27c6c Scott Ullrich
		}
416
417 3eaeb703 Scott Ullrich
	      if($pkga['type'] == "input") {
418 b6e87566 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
419 e4f8f7d2 Bill Marquette
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' class='formfld unknown' value='" . $value . "'>\n";
420 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
421 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "password") {
422 f1412ed6 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";		
423 e4f8f7d2 Bill Marquette
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' class='formfld pwd' value='" . $value . "'>\n";
424 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
425 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "select") {
426 fbd14b13 Scott Ullrich
                  $fieldname = $pkga['fieldname'];
427
                  if (isset($pkga['multiple'])) {
428 67fa245a Scott Ullrich
                    $multiple = 'multiple="multiple"';
429 fbd14b13 Scott Ullrich
                    $items = explode(',', $value);
430 67fa245a Scott Ullrich
                    $fieldname .= "[]";
431 fbd14b13 Scott Ullrich
                  }
432
                  else {
433
                    $multiple = '';
434
                    $items = array($value);
435
                  }
436
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
437
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
438
439 ae2ea68c Scott Ullrich
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
440 fbd14b13 Scott Ullrich
                  foreach ($pkga['options']['option'] as $opt) {
441
                      $selected = '';
442 67fa245a Scott Ullrich
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
443 fbd14b13 Scott Ullrich
                      print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
444
                  }
445
446
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
447 9f65abbf Scott Ullrich
		  } else if($pkga['type'] == "select_source") {
448
                  $fieldname = $pkga['fieldname'];
449
                  if (isset($pkga['multiple'])) {
450
                    $multiple = 'multiple="multiple"';
451
                    $items = explode(',', $value);
452
                    $fieldname .= "[]";
453
                  }
454
                  else {
455
                    $multiple = '';
456
                    $items = array($value);
457
                  }
458
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
459
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
460
461
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
462
				  $source_url = $pkga['source'];
463
				  eval("\$pkg_source_txt = &$source_url;");
464
                  foreach ($pkg_source_txt as $opt) {
465
                      $selected = '';
466
					  if($pkga['source_name']) {
467
						$source_name = $opt[$pkga['source_name']];
468
					  } else {
469
						$source_name = $opt[$pkga['name']];
470
					  }
471
					  if($pkga['source_value']) {
472
						$source_value = $opt[$pkga['source_value']];
473
					  } else {
474
						$source_value = $opt[$pkga['value']];
475
					  }
476
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
477
                      	print("\t<option name=\"{$source_name}\" value=\"{$source_value}\" $selected>{$source_name}</option>\n");
478
                  }
479
480
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");		
481 2c634bdd Scott Ullrich
	      } else if($pkga['type'] == "vpn_selection") {
482 ae2ea68c Scott Ullrich
		    echo "<select id='" . $pkga['fieldname'] . "' name='" . $vpn['name'] . "'>\n";
483 a93e56c5 Matthew Grooms
		    foreach ($config['ipsec']['phase1'] as $vpn) {
484 2c634bdd Scott Ullrich
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
485
		    }
486
		    echo "</select>\n";
487 03f0bfe7 Scott Ullrich
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
488 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "checkbox") {
489 64c1ebbb Scott Ullrich
			$checkboxchecked = "";
490 34865da0 Scott Ullrich
			if($value == "on") $checkboxchecked = " CHECKED";
491 b91540da Scott Ullrich
			if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
492
				$onclick = ' onclick="javascript:enablechange();"';
493 ae2ea68c Scott Ullrich
			echo "<input id='" . $pkga['fieldname'] . "' type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . $onclick . ">\n";
494 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
495 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "textarea") {
496
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
497
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
498 82458abb Mark Crane
		  if($pkga['wrap'] == "off") { $wrap = 'wrap="off" style="white-space:nowrap;"'; } else { $wrap = ''; }		  
499 5d65350b Ermal Lu?i
		  if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) $value = base64_decode($value);
500 82458abb Mark Crane
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "' ".$wrap.">" . $value . "</textarea>\n";
501 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
502 ab73789e Scott Ullrich
		  } else if($pkga['type'] == "interfaces_selection") {
503 fbd14b13 Scott Ullrich
			$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
504
			$multiple = '';
505 7502342a Scott Ullrich
			$fieldname = $pkga['fieldname'];
506 fbd14b13 Scott Ullrich
			if (isset($pkga['multiple'])) {
507
				$fieldname .= '[]';
508
				$multiple = 'multiple';
509 e4a72146 Scott Ullrich
			}
510 ae2ea68c Scott Ullrich
			print("<select id='" . $pkga['fieldname'] . "' name=\"$fieldname\" $size $multiple>\n");
511 5d65350b Ermal Lu?i
			$ifaces = get_configured_interface_with_descr();
512 fbd14b13 Scott Ullrich
			$additional_ifaces = $pkga['add_to_interfaces_selection'];
513
			if (!empty($additional_ifaces))
514
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
515 9996eff6 Scott Ullrich
			if(is_array($value))
516
				$values = $value;
517
			else
518
				$values  =  explode(',',  $value);
519 fbd14b13 Scott Ullrich
			foreach($ifaces as $ifname => $iface) {
520
				$selected = (in_array($ifname, $values) ? 'selected' : '');
521 5d65350b Ermal Lu?i
				print("<option value=\"$ifname\" $selected>$iface</option>\n");
522 ab73789e Scott Ullrich
			}
523 fbd14b13 Scott Ullrich
			print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
524 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "radio") {
525 ae2ea68c Scott Ullrich
			echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
526 eec70f21 Scott Ullrich
	      } else if($pkga['type'] == "rowhelper") {
527
		?>
528
			<script type="text/javascript" language='javascript'>
529
			<!--
530
			<?php
531
				$rowcounter = 0;
532
				$fieldcounter = 0;
533
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
534
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
535
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
536
					$fieldcounter++;
537
				}
538
			?>
539
			-->
540
			</script>
541
			<table name="maintable" id="maintable">
542 b6e87566 Scott Ullrich
			<tr>
543 eec70f21 Scott Ullrich
			<?php
544 31d27c6c Scott Ullrich
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
545 d51f86e0 Scott Ullrich
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
546 31d27c6c Scott Ullrich
				}
547 b6e87566 Scott Ullrich
				echo "</tr>";
548
549 eec70f21 Scott Ullrich
				echo "<tr>";
550
				  // XXX: traverse saved fields, add back needed rows.
551
				echo "</tr>";
552 0e730fee Scott Ullrich
553 31d27c6c Scott Ullrich
				echo "<tr>\n";
554
				$rowcounter = 0;
555
				$trc = 0;
556
				if(isset($a_pkg[$id]['row'])) {
557
					foreach($a_pkg[$id]['row'] as $row) {
558
					/*
559
					 * loop through saved data for record if it exists, populating rowhelper
560 bb940538 Scott Ullrich
					 */
561 31d27c6c Scott Ullrich
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
562
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
563
							$fieldname = $rowhelper['fieldname'];
564
							// if user is editing a record, load in the data.
565 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
566 7db8ff99 Colin Smith
								$value = $row[$fieldname];
567 bb940538 Scott Ullrich
							}
568 31d27c6c Scott Ullrich
							$options = "";
569
							$type = $rowhelper['type'];
570
							$fieldname = $rowhelper['fieldname'];
571 e54626e2 Ermal Lu?i
							if($type == "option")
572
								$options = &$rowhelper['options']['option'];
573 7e542bd1 Scott Ullrich
							if($rowhelper['size']) 
574 4c09b655 Scott Ullrich
								$size = $rowhelper['size'];
575 e54626e2 Ermal Lu?i
							else if ($pkga['size'])
576
								$size = $pkga['size'];
577 4c09b655 Scott Ullrich
							else
578
								$size = "8";
579 e70e0b76 Scott Ullrich
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
580 bb940538 Scott Ullrich
							// javascript helpers for row_helper_dynamic.js
581
							echo "</td>\n";
582
							echo "<script language=\"JavaScript\">\n";
583
							echo "<!--\n";
584
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
585
							echo "-->\n";
586
							echo "</script>\n";
587
							$text = "";
588
							$trc++;
589 eec70f21 Scott Ullrich
						}
590 bb940538 Scott Ullrich
591 31d27c6c Scott Ullrich
						$rowcounter++;
592
						echo "<td>";
593 b91540da Scott Ullrich
						echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
594 eec70f21 Scott Ullrich
						echo "</td>\n";
595 31d27c6c Scott Ullrich
						echo "</tr>\n";
596
					}
597
				}
598
				if($trc == 0) {
599
					/*
600
					 *  no records loaded.
601
                                         *  just show a generic line non-populated with saved data
602
                                         */
603
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
604
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
605 bb940538 Scott Ullrich
						$fieldname = $rowhelper['fieldname'];
606 31d27c6c Scott Ullrich
						$options = "";
607
						$type = $rowhelper['type'];
608
						$fieldname = $rowhelper['fieldname'];
609
						if($type == "option") $options = &$rowhelper['options']['option'];
610 e54626e2 Ermal Lu?i
						if($rowhelper['size'] <> "")
611
							$size = $rowhelper['size'];
612
						else if ($pkga['size'])
613
							$size = $pkga['size'];
614
						else
615
							$size = 8;
616 e70e0b76 Scott Ullrich
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
617 bb940538 Scott Ullrich
						// javascript helpers for row_helper_dynamic.js
618
						echo "</td>\n";
619
						echo "<script language=\"JavaScript\">\n";
620
						echo "<!--\n";
621
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
622
						echo "-->\n";
623
						echo "</script>\n";
624
						$text = "";
625 eec70f21 Scott Ullrich
						$trc++;
626
					}
627 bb940538 Scott Ullrich
628
					$rowcounter++;
629 e54626e2 Ermal Lu?i
					echo "<td>";
630
					echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
631
					echo "</td>\n";
632
					echo "</tr>\n";
633 eec70f21 Scott Ullrich
				}
634
			?>
635 0e730fee Scott Ullrich
636 03664f64 Scott Ullrich
			  <tbody></tbody>
637 eec70f21 Scott Ullrich
			</table>
638 0e730fee Scott Ullrich
639 e54626e2 Ermal Lu?i
		<?php if ($pkga['size']): ?>
640
			<br><a onClick="javascript:addRowTo('maintable', <?=$pkga['size'];?>); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
641
		<?php else: ?>
642
			<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
643
		<?php endif; ?>
644 eec70f21 Scott Ullrich
		<script language="JavaScript">
645
		<!--
646
		field_counter_js = <?= $fieldcounter ?>;
647
		rows = <?= $rowcounter ?>;
648
		totalrows = <?php echo $rowcounter; ?>;
649
		loaded = <?php echo $rowcounter; ?>;
650 e02a6839 Scott Ullrich
		//typesel_change();
651 eec70f21 Scott Ullrich
		//-->
652
		</script>
653
654
		<?php
655 d47013e1 Scott Ullrich
	      }
656 3eaeb703 Scott Ullrich
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
657 facd08f9 Scott Ullrich
	     ?>
658
659 d47013e1 Scott Ullrich
      <?php
660 facd08f9 Scott Ullrich
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
661 d47013e1 Scott Ullrich
      $i++;
662
  }
663
 ?>
664 b6e87566 Scott Ullrich
  <tr>
665
	<td>&nbsp;</td>
666
  </tr>
667 d47013e1 Scott Ullrich
  <tr>
668
    <td width="22%" valign="top">&nbsp;</td>
669
    <td width="78%">
670 7c172009 Scott Ullrich
<?php
671
if($pkg['note'] != "")
672 b91540da Scott Ullrich
	print("<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>");
673
//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
674 7c172009 Scott Ullrich
      print("<input name=\"id\" type=\"hidden\" value=\"$id\">");
675
?>
676
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
677 b91540da Scott Ullrich
<?php if (!$only_edit): ?>
678 457106da Renato Botelho
      <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
679 b91540da Scott Ullrich
<?php endif; ?>
680 d47013e1 Scott Ullrich
    </td>
681
  </tr>
682
</table>
683 f4cb26b7 Colin Smith
</div></tr></td></table>
684 7c172009 Scott Ullrich
</form>
685 7c061036 Scott Ullrich
686 7c172009 Scott Ullrich
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
687 95736b54 Scott Ullrich
688 d47013e1 Scott Ullrich
<?php include("fend.inc"); ?>
689
</body>
690
</html>
691
692 31d27c6c Scott Ullrich
<?php
693
/*
694
 * ROW Helpers function
695
 */
696 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
697 db3829e1 Scott Ullrich
	global $text, $config;
698 31d27c6c Scott Ullrich
	echo "<td>\n";
699
	if($type == "input") {
700 ae2ea68c Scott Ullrich
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' id='" . $fieldname . $trc . "' value='" . $value . "'>\n";
701 855cab21 Scott Ullrich
	} else if($type == "checkbox") {
702
		if($value)
703 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON' CHECKED>\n";
704 855cab21 Scott Ullrich
		else
705 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON'>\n";
706 31d27c6c Scott Ullrich
	} else if($type == "password") {
707 e4f8f7d2 Bill Marquette
		echo "<input size='" . $size . "' type='password' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' class='formfld pwd' value='" . $value . "'>\n";
708 31d27c6c Scott Ullrich
	} else if($type == "textarea") {
709 e4f8f7d2 Bill Marquette
		echo "<textarea rows='2' cols='12' id='" . $fieldname . $trc . "' class='formfld unknown' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
710 31d27c6c Scott Ullrich
	} else if($type == "select") {
711 ae2ea68c Scott Ullrich
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
712 31d27c6c Scott Ullrich
		foreach($rowhelper['options']['option'] as $rowopt) {
713
			$selected = "";
714
			if($rowopt['value'] == $value) $selected = " SELECTED";
715
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
716
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
717
		}
718
		echo "</select>\n";
719 db3829e1 Scott Ullrich
	} else if($type == "select_source") {
720
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
721
	    $source_url = $rowhelper['source'];
722
	    eval("\$pkg_source_txt = &$source_url;");
723
		foreach($pkg_source_txt as $opt) {
724
			$selected = "";
725
		    if($rowhelper['source_name']) {
726
				$source_name = $opt[$rowhelper['source_name']];
727
		    } else {
728
				$source_name = $opt[$rowhelper['name']];
729
		    }
730
		  	if($rowhelper['source_value']) {
731
				$source_value = $opt[$rowhelper['source_value']];
732
		  	} else {
733
				$source_value = $opt[$rowhelper['value']];
734
		  	}
735 9605d06f Scott Ullrich
			if($source_value == $value) 
736 db3829e1 Scott Ullrich
				$selected = " SELECTED";
737
			$text .= "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>";
738
			echo "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>\n";
739
		}
740
		echo "</select>\n";		
741 31d27c6c Scott Ullrich
	}
742
}
743
744 d51f86e0 Scott Ullrich
function fixup_string($string) {
745 d2133701 Scott Ullrich
	global $config;
746 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
747
	$https = "";
748
	$port = $config['system']['webguiport'];
749 63637de9 Bill Marquette
	if($port <> "443" and $port <> "80")
750
		$urlport = ":" . $port;
751
	else
752
		$urlport = "";
753 3c616886 Scott Ullrich
754 58362f9d jim-p
	if($config['system']['webgui']['protocol'] == "https") $https = "s";
755 63637de9 Bill Marquette
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
756 d51f86e0 Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $string);
757 d2133701 Scott Ullrich
	$string = $newstring;
758
	// fixup #2: $wanip
759 85a5da13 Ermal Luçi
	$curwanip = get_interface_ip();
760 d2133701 Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $string);
761
	$string = $newstring;
762
	// fixup #3: $lanip
763
	$lancfg = $config['interfaces']['lan'];
764
	$lanip = $lancfg['ipaddr'];
765
	$newstring = str_replace("\$lanip", $lanip, $string);
766
	$string = $newstring;
767
	// fixup #4: fix'r'up here.
768 d51f86e0 Scott Ullrich
	return $newstring;
769
}
770
771 dcbe6f52 Scott Ullrich
/*
772
 *  Parse templates if they are defined
773
 */
774
function parse_package_templates() {
775
	global $pkg, $config;
776 767a716e Scott Ullrich
	$rows = 0;
777 dcbe6f52 Scott Ullrich
	if($pkg['templates']['template'] <> "")
778
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
779
		$filename = $pkg_template_row['filename'];
780
		$template_text = $pkg_template_row['templatecontents'];
781 767a716e Scott Ullrich
		$firstfield = "";
782 dcbe6f52 Scott Ullrich
		/* calculate total row helpers count */
783
		foreach ($pkg['fields']['field'] as $fields) {
784
			if($fields['type'] == "rowhelper") {
785
				// save rowhelper items.
786
                                $row_helper_total_rows = 0;
787
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
788
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
789
						if($firstfield == "")  {
790
						  $firstfield = $rowhelperfield['fieldname'];
791
						} else {
792
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
793
						}
794
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
795 767a716e Scott Ullrich
						$value = "";
796 dcbe6f52 Scott Ullrich
						eval($comd);
797
						if($value <> "") {
798
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
799
						} else {
800
						    $row_helper_total_rows = $rows;
801
						    break;
802
						}
803
					}
804
				}
805
			}
806
		}
807
808
		/* replace $domain_total_rows with total rows */
809
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
810
811
		/* change fields defined as fieldname_fieldvalue to their value */
812
		foreach ($pkg['fields']['field'] as $fields) {
813
			if($fields['type'] == "rowhelper") {
814
				// save rowhelper items.
815
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
816
					$row_helper_data = "";
817 1be00369 Scott Ullrich
					$isfirst = 0;
818 dcbe6f52 Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
819
						if($firstfield == "")  {
820
						  $firstfield = $rowhelperfield['fieldname'];
821
						} else {
822
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
823
						}
824
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
825
						eval($comd);
826
						if($value <> "") {
827 1be00369 Scott Ullrich
						    if($isfirst == 1) $row_helper_data .= "  " ;
828
						    $row_helper_data .= $value;
829
						    $isfirst = 1;
830 dcbe6f52 Scott Ullrich
						}
831 767a716e Scott Ullrich
						$sep = "";
832 dcbe6f52 Scott Ullrich
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
833
						foreach ($sep as $se) $seperator = $se;
834
						if($seperator <> "") {
835
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
836
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
837
						}
838
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
839
					}
840
				}
841
			} else {
842
				$fieldname  = $fields['fieldname'];
843
				$fieldvalue = $_POST[$fieldname];
844
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
845
			}
846
		}
847
848
		/* replace cr's */
849
		$template_text = str_replace("\\n", "\n", $template_text);
850
851
		/* write out new template file */
852
		$fout = fopen($filename,"w");
853
		fwrite($fout, $template_text);
854
		fclose($fout);
855
	    }
856
}
857
858 c8536f7d Carlos Eduardo Ramos
?>