Project

General

Profile

Download (29.9 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
    $tab_array = array();
336 7c061036 Scott Ullrich
    foreach($pkg['tabs']['tab'] as $tab) {
337 90551807 Warren Baker
		if($tab['tab_level'])
338
			$tab_level = $tab['tab_level'];
339
		else
340
			$tab_level = 1;
341
		if(isset($tab['active'])) {
342
			$active = true;
343
		} else {
344
			$active = false;
345
		}
346
		$urltmp = "";
347
		if($tab['url'] <> "") $urltmp = $tab['url'];
348
		if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
349
350
 		$addresswithport = getenv("HTTP_HOST");
351
		$colonpos = strpos($addresswithport, ":");
352
		if ($colonpos !== False) {
353
			//my url is actually just the IP address of the pfsense box
354
			$myurl = substr($addresswithport, 0, $colonpos);
355
		} else {
356
			$myurl = $addresswithport;
357
		}
358
		// eval url so that above $myurl item can be processed if need be.
359
		$url = str_replace('$myurl', $myurl, $urltmp);
360
361
		$tab_array[$tab_level][] = array(
362
						$tab['text'],
363
						$active,
364
						$url
365
					);
366 7c061036 Scott Ullrich
    }
367 90551807 Warren Baker
368
	ksort($tab_array);
369
	foreach($tab_array as $tab) {
370
   		echo '<tr><td>';
371
    	display_top_tabs($tab);
372
   		echo '</td></tr>';
373
	}
374 7c061036 Scott Ullrich
}
375
?>
376 f4cb26b7 Colin Smith
<tr><td><div id="mainarea"><table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
377 d47013e1 Scott Ullrich
  <?php
378
  $cols = 0;
379 457106da Renato Botelho
  $savevalue = gettext("Save");
380 3eaeb703 Scott Ullrich
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
381 32487e42 Scott Ullrich
  foreach ($pkg['fields']['field'] as $pkga) { 
382 969a36ce Scott Ullrich
		if ($pkga['type'] == "sorting") 
383
			continue;
384 32487e42 Scott Ullrich
385
		if ($pkga['type'] == "listtopic") {
386
			echo "<td>&nbsp;</td>";
387
			echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $pkga['name'] . "<br></td></tr>\n";
388
			continue;
389
	    }	
390
	
391
?>
392 3c616886 Scott Ullrich
393 facd08f9 Scott Ullrich
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
394
395 d47013e1 Scott Ullrich
	  <?php
396 3c616886 Scott Ullrich
397 5c74f339 Scott Ullrich
	  $size = "";
398 3c616886 Scott Ullrich
399 facd08f9 Scott Ullrich
	  if(!$pkga['dontdisplayname']) {
400 7c172009 Scott Ullrich
		unset($req);
401 b91540da Scott Ullrich
		if (isset($pkga['required']))
402 7c172009 Scott Ullrich
			$req = 'req';
403
		echo "<td width=\"22%\" class=\"vncell{$req}\">";
404 d51f86e0 Scott Ullrich
		echo fixup_string($pkga['fielddescr']);
405 31d27c6c Scott Ullrich
		echo "</td>";
406 facd08f9 Scott Ullrich
	  }
407
408
	  if(!$pkga['dontcombinecells'])
409
		echo "<td class=\"vtable\">";
410 31d27c6c Scott Ullrich
		// if user is editing a record, load in the data.
411 7c172009 Scott Ullrich
		$fieldname = $pkga['fieldname'];
412 fbd14b13 Scott Ullrich
		if ($get_from_post) {
413 7c172009 Scott Ullrich
			$value = $_POST[$fieldname];
414 fbd14b13 Scott Ullrich
			if (is_array($value)) $value = implode(',', $value);
415
		}
416 7c172009 Scott Ullrich
		else {
417
			if (isset($id) && $a_pkg[$id])
418
				$value = $a_pkg[$id][$fieldname];
419 b91540da Scott Ullrich
			else
420
				$value = $pkga['default_value'];
421 31d27c6c Scott Ullrich
		}
422
423 3eaeb703 Scott Ullrich
	      if($pkga['type'] == "input") {
424 b6e87566 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
425 e4f8f7d2 Bill Marquette
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' class='formfld unknown' value='" . $value . "'>\n";
426 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
427 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "password") {
428 f1412ed6 Scott Ullrich
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";		
429 e4f8f7d2 Bill Marquette
			echo "<input " . $size . " id='" . $pkga['fieldname'] . "' type='password' " . $size . " name='" . $pkga['fieldname'] . "' class='formfld pwd' value='" . $value . "'>\n";
430 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
431 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "select") {
432 fbd14b13 Scott Ullrich
                  $fieldname = $pkga['fieldname'];
433
                  if (isset($pkga['multiple'])) {
434 67fa245a Scott Ullrich
                    $multiple = 'multiple="multiple"';
435 fbd14b13 Scott Ullrich
                    $items = explode(',', $value);
436 67fa245a Scott Ullrich
                    $fieldname .= "[]";
437 fbd14b13 Scott Ullrich
                  }
438
                  else {
439
                    $multiple = '';
440
                    $items = array($value);
441
                  }
442
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
443
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
444
445 ae2ea68c Scott Ullrich
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
446 fbd14b13 Scott Ullrich
                  foreach ($pkga['options']['option'] as $opt) {
447
                      $selected = '';
448 67fa245a Scott Ullrich
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
449 fbd14b13 Scott Ullrich
                      print("\t<option name=\"{$opt['name']}\" value=\"{$opt['value']}\" $selected>{$opt['name']}</option>\n");
450
                  }
451
452
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");
453 9f65abbf Scott Ullrich
		  } else if($pkga['type'] == "select_source") {
454
                  $fieldname = $pkga['fieldname'];
455
                  if (isset($pkga['multiple'])) {
456
                    $multiple = 'multiple="multiple"';
457
                    $items = explode(',', $value);
458
                    $fieldname .= "[]";
459
                  }
460
                  else {
461
                    $multiple = '';
462
                    $items = array($value);
463
                  }
464
                  $size = (isset($pkga['size']) ? "size=\"{$pkga['size']}\"" : '');
465
                  $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
466
467
                  print("<select id='" . $pkga['fieldname'] . "' $multiple $size $onchange id=\"$fieldname\" name=\"$fieldname\">\n");
468
				  $source_url = $pkga['source'];
469
				  eval("\$pkg_source_txt = &$source_url;");
470
                  foreach ($pkg_source_txt as $opt) {
471
                      $selected = '';
472
					  if($pkga['source_name']) {
473
						$source_name = $opt[$pkga['source_name']];
474
					  } else {
475
						$source_name = $opt[$pkga['name']];
476
					  }
477
					  if($pkga['source_value']) {
478
						$source_value = $opt[$pkga['source_value']];
479
					  } else {
480
						$source_value = $opt[$pkga['value']];
481
					  }
482
                      if (in_array($opt['value'], $items)) $selected = 'selected="selected"';
483
                      	print("\t<option name=\"{$source_name}\" value=\"{$source_value}\" $selected>{$source_name}</option>\n");
484
                  }
485
486
                  print("</select>\n<br />\n" . fixup_string($pkga['description']) . "\n");		
487 2c634bdd Scott Ullrich
	      } else if($pkga['type'] == "vpn_selection") {
488 ae2ea68c Scott Ullrich
		    echo "<select id='" . $pkga['fieldname'] . "' name='" . $vpn['name'] . "'>\n";
489 a93e56c5 Matthew Grooms
		    foreach ($config['ipsec']['phase1'] as $vpn) {
490 2c634bdd Scott Ullrich
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
491
		    }
492
		    echo "</select>\n";
493 03f0bfe7 Scott Ullrich
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
494 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "checkbox") {
495 64c1ebbb Scott Ullrich
			$checkboxchecked = "";
496 34865da0 Scott Ullrich
			if($value == "on") $checkboxchecked = " CHECKED";
497 b91540da Scott Ullrich
			if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
498
				$onclick = ' onclick="javascript:enablechange();"';
499 ae2ea68c Scott Ullrich
			echo "<input id='" . $pkga['fieldname'] . "' type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . $onclick . ">\n";
500 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
501 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "textarea") {
502
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
503
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
504 82458abb Mark Crane
		  if($pkga['wrap'] == "off") { $wrap = 'wrap="off" style="white-space:nowrap;"'; } else { $wrap = ''; }		  
505 5d65350b Ermal Lu?i
		  if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) $value = base64_decode($value);
506 82458abb Mark Crane
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "' ".$wrap.">" . $value . "</textarea>\n";
507 d51f86e0 Scott Ullrich
			echo "<br>" . fixup_string($pkga['description']) . "\n";
508 ab73789e Scott Ullrich
		  } else if($pkga['type'] == "interfaces_selection") {
509 fbd14b13 Scott Ullrich
			$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
510
			$multiple = '';
511 7502342a Scott Ullrich
			$fieldname = $pkga['fieldname'];
512 fbd14b13 Scott Ullrich
			if (isset($pkga['multiple'])) {
513
				$fieldname .= '[]';
514
				$multiple = 'multiple';
515 e4a72146 Scott Ullrich
			}
516 ae2ea68c Scott Ullrich
			print("<select id='" . $pkga['fieldname'] . "' name=\"$fieldname\" $size $multiple>\n");
517 5d65350b Ermal Lu?i
			$ifaces = get_configured_interface_with_descr();
518 fbd14b13 Scott Ullrich
			$additional_ifaces = $pkga['add_to_interfaces_selection'];
519
			if (!empty($additional_ifaces))
520
				$ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
521 9996eff6 Scott Ullrich
			if(is_array($value))
522
				$values = $value;
523
			else
524
				$values  =  explode(',',  $value);
525 fbd14b13 Scott Ullrich
			foreach($ifaces as $ifname => $iface) {
526
				$selected = (in_array($ifname, $values) ? 'selected' : '');
527 5d65350b Ermal Lu?i
				print("<option value=\"$ifname\" $selected>$iface</option>\n");
528 ab73789e Scott Ullrich
			}
529 fbd14b13 Scott Ullrich
			print("</select>\n<br />" . fixup_string($pkga['description']) . "\n");
530 3eaeb703 Scott Ullrich
	      } else if($pkga['type'] == "radio") {
531 ae2ea68c Scott Ullrich
			echo "<input type='radio' id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
532 eec70f21 Scott Ullrich
	      } else if($pkga['type'] == "rowhelper") {
533
		?>
534
			<script type="text/javascript" language='javascript'>
535
			<!--
536
			<?php
537
				$rowcounter = 0;
538
				$fieldcounter = 0;
539
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
540
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
541
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
542
					$fieldcounter++;
543
				}
544
			?>
545
			-->
546
			</script>
547
			<table name="maintable" id="maintable">
548 b6e87566 Scott Ullrich
			<tr>
549 eec70f21 Scott Ullrich
			<?php
550 31d27c6c Scott Ullrich
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
551 d51f86e0 Scott Ullrich
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
552 31d27c6c Scott Ullrich
				}
553 b6e87566 Scott Ullrich
				echo "</tr>";
554
555 eec70f21 Scott Ullrich
				echo "<tr>";
556
				  // XXX: traverse saved fields, add back needed rows.
557
				echo "</tr>";
558 0e730fee Scott Ullrich
559 31d27c6c Scott Ullrich
				echo "<tr>\n";
560
				$rowcounter = 0;
561
				$trc = 0;
562
				if(isset($a_pkg[$id]['row'])) {
563
					foreach($a_pkg[$id]['row'] as $row) {
564
					/*
565
					 * loop through saved data for record if it exists, populating rowhelper
566 bb940538 Scott Ullrich
					 */
567 31d27c6c Scott Ullrich
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
568
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
569
							$fieldname = $rowhelper['fieldname'];
570
							// if user is editing a record, load in the data.
571 bb940538 Scott Ullrich
							if (isset($id) && $a_pkg[$id]) {
572 7db8ff99 Colin Smith
								$value = $row[$fieldname];
573 bb940538 Scott Ullrich
							}
574 31d27c6c Scott Ullrich
							$options = "";
575
							$type = $rowhelper['type'];
576
							$fieldname = $rowhelper['fieldname'];
577 e54626e2 Ermal Lu?i
							if($type == "option")
578
								$options = &$rowhelper['options']['option'];
579 7e542bd1 Scott Ullrich
							if($rowhelper['size']) 
580 4c09b655 Scott Ullrich
								$size = $rowhelper['size'];
581 e54626e2 Ermal Lu?i
							else if ($pkga['size'])
582
								$size = $pkga['size'];
583 4c09b655 Scott Ullrich
							else
584
								$size = "8";
585 e70e0b76 Scott Ullrich
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
586 bb940538 Scott Ullrich
							// javascript helpers for row_helper_dynamic.js
587
							echo "</td>\n";
588
							echo "<script language=\"JavaScript\">\n";
589
							echo "<!--\n";
590
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
591
							echo "-->\n";
592
							echo "</script>\n";
593
							$text = "";
594
							$trc++;
595 eec70f21 Scott Ullrich
						}
596 bb940538 Scott Ullrich
597 31d27c6c Scott Ullrich
						$rowcounter++;
598
						echo "<td>";
599 b91540da Scott Ullrich
						echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
600 eec70f21 Scott Ullrich
						echo "</td>\n";
601 31d27c6c Scott Ullrich
						echo "</tr>\n";
602
					}
603
				}
604
				if($trc == 0) {
605
					/*
606
					 *  no records loaded.
607
                                         *  just show a generic line non-populated with saved data
608
                                         */
609
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
610
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
611 bb940538 Scott Ullrich
						$fieldname = $rowhelper['fieldname'];
612 31d27c6c Scott Ullrich
						$options = "";
613
						$type = $rowhelper['type'];
614
						$fieldname = $rowhelper['fieldname'];
615
						if($type == "option") $options = &$rowhelper['options']['option'];
616 e54626e2 Ermal Lu?i
						if($rowhelper['size'] <> "")
617
							$size = $rowhelper['size'];
618
						else if ($pkga['size'])
619
							$size = $pkga['size'];
620
						else
621
							$size = 8;
622 e70e0b76 Scott Ullrich
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
623 bb940538 Scott Ullrich
						// javascript helpers for row_helper_dynamic.js
624
						echo "</td>\n";
625
						echo "<script language=\"JavaScript\">\n";
626
						echo "<!--\n";
627
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
628
						echo "-->\n";
629
						echo "</script>\n";
630
						$text = "";
631 eec70f21 Scott Ullrich
						$trc++;
632
					}
633 bb940538 Scott Ullrich
634
					$rowcounter++;
635 e54626e2 Ermal Lu?i
					echo "<td>";
636
					echo "<input type=\"image\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"" . gettext("Delete") . "\">";
637
					echo "</td>\n";
638
					echo "</tr>\n";
639 eec70f21 Scott Ullrich
				}
640
			?>
641 0e730fee Scott Ullrich
642 03664f64 Scott Ullrich
			  <tbody></tbody>
643 eec70f21 Scott Ullrich
			</table>
644 0e730fee Scott Ullrich
645 e54626e2 Ermal Lu?i
		<?php if ($pkga['size']): ?>
646
			<br><a onClick="javascript:addRowTo('maintable', <?=$pkga['size'];?>); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
647
		<?php else: ?>
648
			<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif"></a>
649
		<?php endif; ?>
650 eec70f21 Scott Ullrich
		<script language="JavaScript">
651
		<!--
652
		field_counter_js = <?= $fieldcounter ?>;
653
		rows = <?= $rowcounter ?>;
654
		totalrows = <?php echo $rowcounter; ?>;
655
		loaded = <?php echo $rowcounter; ?>;
656 e02a6839 Scott Ullrich
		//typesel_change();
657 eec70f21 Scott Ullrich
		//-->
658
		</script>
659
660
		<?php
661 d47013e1 Scott Ullrich
	      }
662 3eaeb703 Scott Ullrich
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
663 facd08f9 Scott Ullrich
	     ?>
664
665 d47013e1 Scott Ullrich
      <?php
666 facd08f9 Scott Ullrich
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
667 d47013e1 Scott Ullrich
      $i++;
668
  }
669
 ?>
670 b6e87566 Scott Ullrich
  <tr>
671
	<td>&nbsp;</td>
672
  </tr>
673 d47013e1 Scott Ullrich
  <tr>
674
    <td width="22%" valign="top">&nbsp;</td>
675
    <td width="78%">
676 7c172009 Scott Ullrich
<?php
677
if($pkg['note'] != "")
678 b91540da Scott Ullrich
	print("<p><span class=\"red\"><strong>" . gettext("Note") . ":</strong></span> {$pkg['note']}</p>");
679
//if (isset($id) && $a_pkg[$id]) // We'll always have a valid ID in our hands
680 7c172009 Scott Ullrich
      print("<input name=\"id\" type=\"hidden\" value=\"$id\">");
681
?>
682
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
683 b91540da Scott Ullrich
<?php if (!$only_edit): ?>
684 457106da Renato Botelho
      <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
685 b91540da Scott Ullrich
<?php endif; ?>
686 d47013e1 Scott Ullrich
    </td>
687
  </tr>
688
</table>
689 f4cb26b7 Colin Smith
</div></tr></td></table>
690 7c172009 Scott Ullrich
</form>
691 7c061036 Scott Ullrich
692 7c172009 Scott Ullrich
<?php if ($pkg['custom_php_after_form_command']) eval($pkg['custom_php_after_form_command']); ?>
693 95736b54 Scott Ullrich
694 d47013e1 Scott Ullrich
<?php include("fend.inc"); ?>
695
</body>
696
</html>
697
698 31d27c6c Scott Ullrich
<?php
699
/*
700
 * ROW Helpers function
701
 */
702 e70e0b76 Scott Ullrich
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
703 db3829e1 Scott Ullrich
	global $text, $config;
704 31d27c6c Scott Ullrich
	echo "<td>\n";
705
	if($type == "input") {
706 ae2ea68c Scott Ullrich
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' id='" . $fieldname . $trc . "' value='" . $value . "'>\n";
707 855cab21 Scott Ullrich
	} else if($type == "checkbox") {
708
		if($value)
709 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON' CHECKED>\n";
710 855cab21 Scott Ullrich
		else
711 ae2ea68c Scott Ullrich
			echo "<input size='" . $size . "' type='checkbox' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' value='ON'>\n";
712 31d27c6c Scott Ullrich
	} else if($type == "password") {
713 e4f8f7d2 Bill Marquette
		echo "<input size='" . $size . "' type='password' id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "' class='formfld pwd' value='" . $value . "'>\n";
714 31d27c6c Scott Ullrich
	} else if($type == "textarea") {
715 e4f8f7d2 Bill Marquette
		echo "<textarea rows='2' cols='12' id='" . $fieldname . $trc . "' class='formfld unknown' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
716 31d27c6c Scott Ullrich
	} else if($type == "select") {
717 ae2ea68c Scott Ullrich
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
718 31d27c6c Scott Ullrich
		foreach($rowhelper['options']['option'] as $rowopt) {
719
			$selected = "";
720
			if($rowopt['value'] == $value) $selected = " SELECTED";
721
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
722
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
723
		}
724
		echo "</select>\n";
725 db3829e1 Scott Ullrich
	} else if($type == "select_source") {
726
		echo "<select id='" . $fieldname . $trc . "' name='" . $fieldname . $trc . "'>\n";
727
	    $source_url = $rowhelper['source'];
728
	    eval("\$pkg_source_txt = &$source_url;");
729
		foreach($pkg_source_txt as $opt) {
730
			$selected = "";
731
		    if($rowhelper['source_name']) {
732
				$source_name = $opt[$rowhelper['source_name']];
733
		    } else {
734
				$source_name = $opt[$rowhelper['name']];
735
		    }
736
		  	if($rowhelper['source_value']) {
737
				$source_value = $opt[$rowhelper['source_value']];
738
		  	} else {
739
				$source_value = $opt[$rowhelper['value']];
740
		  	}
741 9605d06f Scott Ullrich
			if($source_value == $value) 
742 db3829e1 Scott Ullrich
				$selected = " SELECTED";
743
			$text .= "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>";
744
			echo "<option value='" . $source_value . "'" . $selected . ">" . $source_name . "</option>\n";
745
		}
746
		echo "</select>\n";		
747 31d27c6c Scott Ullrich
	}
748
}
749
750 d51f86e0 Scott Ullrich
function fixup_string($string) {
751 d2133701 Scott Ullrich
	global $config;
752 d51f86e0 Scott Ullrich
	// fixup #1: $myurl -> http[s]://ip_address:port/
753
	$https = "";
754
	$port = $config['system']['webguiport'];
755 63637de9 Bill Marquette
	if($port <> "443" and $port <> "80")
756
		$urlport = ":" . $port;
757
	else
758
		$urlport = "";
759 3c616886 Scott Ullrich
760 58362f9d jim-p
	if($config['system']['webgui']['protocol'] == "https") $https = "s";
761 63637de9 Bill Marquette
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
762 d51f86e0 Scott Ullrich
	$newstring = str_replace("\$myurl", $myurl, $string);
763 d2133701 Scott Ullrich
	$string = $newstring;
764
	// fixup #2: $wanip
765 85a5da13 Ermal Luçi
	$curwanip = get_interface_ip();
766 d2133701 Scott Ullrich
	$newstring = str_replace("\$wanip", $curwanip, $string);
767
	$string = $newstring;
768
	// fixup #3: $lanip
769
	$lancfg = $config['interfaces']['lan'];
770
	$lanip = $lancfg['ipaddr'];
771
	$newstring = str_replace("\$lanip", $lanip, $string);
772
	$string = $newstring;
773
	// fixup #4: fix'r'up here.
774 d51f86e0 Scott Ullrich
	return $newstring;
775
}
776
777 dcbe6f52 Scott Ullrich
/*
778
 *  Parse templates if they are defined
779
 */
780
function parse_package_templates() {
781
	global $pkg, $config;
782 767a716e Scott Ullrich
	$rows = 0;
783 dcbe6f52 Scott Ullrich
	if($pkg['templates']['template'] <> "")
784
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
785
		$filename = $pkg_template_row['filename'];
786
		$template_text = $pkg_template_row['templatecontents'];
787 767a716e Scott Ullrich
		$firstfield = "";
788 dcbe6f52 Scott Ullrich
		/* calculate total row helpers count */
789
		foreach ($pkg['fields']['field'] as $fields) {
790
			if($fields['type'] == "rowhelper") {
791
				// save rowhelper items.
792
                                $row_helper_total_rows = 0;
793
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
794
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
795
						if($firstfield == "")  {
796
						  $firstfield = $rowhelperfield['fieldname'];
797
						} else {
798
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
799
						}
800
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
801 767a716e Scott Ullrich
						$value = "";
802 dcbe6f52 Scott Ullrich
						eval($comd);
803
						if($value <> "") {
804
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
805
						} else {
806
						    $row_helper_total_rows = $rows;
807
						    break;
808
						}
809
					}
810
				}
811
			}
812
		}
813
814
		/* replace $domain_total_rows with total rows */
815
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
816
817
		/* change fields defined as fieldname_fieldvalue to their value */
818
		foreach ($pkg['fields']['field'] as $fields) {
819
			if($fields['type'] == "rowhelper") {
820
				// save rowhelper items.
821
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
822
					$row_helper_data = "";
823 1be00369 Scott Ullrich
					$isfirst = 0;
824 dcbe6f52 Scott Ullrich
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
825
						if($firstfield == "")  {
826
						  $firstfield = $rowhelperfield['fieldname'];
827
						} else {
828
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
829
						}
830
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
831
						eval($comd);
832
						if($value <> "") {
833 1be00369 Scott Ullrich
						    if($isfirst == 1) $row_helper_data .= "  " ;
834
						    $row_helper_data .= $value;
835
						    $isfirst = 1;
836 dcbe6f52 Scott Ullrich
						}
837 767a716e Scott Ullrich
						$sep = "";
838 dcbe6f52 Scott Ullrich
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
839
						foreach ($sep as $se) $seperator = $se;
840
						if($seperator <> "") {
841
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
842
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
843
						}
844
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
845
					}
846
				}
847
			} else {
848
				$fieldname  = $fields['fieldname'];
849
				$fieldvalue = $_POST[$fieldname];
850
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
851
			}
852
		}
853
854
		/* replace cr's */
855
		$template_text = str_replace("\\n", "\n", $template_text);
856
857
		/* write out new template file */
858
		$fout = fopen($filename,"w");
859
		fwrite($fout, $template_text);
860
		fclose($fout);
861
	    }
862
}
863
864 c8536f7d Carlos Eduardo Ramos
?>