Project

General

Profile

Download (20.5 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    pkg_edit.php
5
    Copyright (C) 2004 Scott Ullrich
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
 <tabs>
30
 	<tab>
31
 		<text>Testing Tab</text>
32
 		<url>url to go to</url>
33
 	</tab>
34
 	<tab>
35
 		<text>Testing Tab 2</text>
36
 		<xml>filename of xml</xml>
37
 	</tab>
38
 </tabs>
39

    
40
*/
41

    
42
require("guiconfig.inc");
43
require("xmlparse_pkg.inc");
44

    
45
$pfSense_config = $config; // copy this since we will be parsing
46
                           // another xml file which will be clobbered.
47

    
48
function gentitle_pkg($pgname) {
49
	global $pfSense_config;
50
	return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
51
}
52

    
53
// XXX: Make this input safe.
54
$xml = $_GET['xml'];
55
if($_POST['xml']) $xml = $_POST['xml'];
56

    
57
if($xml == "") {
58
            $xml = "not_defined";
59
            print_info_box_np("ERROR:  Could not open " . $xml . ".");
60
            die;
61
} else {
62
            $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
63
}
64

    
65
$package_name = $pkg['menu'][0]['name'];
66
$section      = $pkg['menu'][0]['section'];
67
$config_path  = $pkg['configpath'];
68
$name         = $pkg['name'];
69
$title        = $section . ": " . $package_name;
70

    
71
$id = $_GET['id'];
72
if (isset($_POST['id']))
73
	$id = $_POST['id'];
74

    
75
// grab the installedpackages->package_name section.
76
$toeval = "\$a_pkg = &\$config['installedpackages']['" . $name . "']['config'];";
77
eval($toeval);
78

    
79
$toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();";
80
eval($toeval);
81

    
82
$toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];";
83
eval($toeval);
84

    
85
if($pkg['custom_php_command_before_form'] <> "")
86
  eval($pkg['custom_php_command_before_form']);
87

    
88

    
89
if ($_POST) {
90
	if($_POST['act'] == "del") {
91
		if($pkg['custom_delete_php_command']) {
92
		    eval($pkg['custom_delete_php_command']);
93
		}
94
		write_config();
95
		// resync the configuration file code if defined.
96
		if($pkg['custom_php_resync_config_command'] <> "") {
97
		    eval($pkg['custom_php_resync_config_command']);
98
		}
99
	} else {
100
		if($pkg['custom_add_php_command']) {
101
			if($pkg['donotsave'] <> "") {
102
				?>
103
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
104
<html>
105
<head>
106
<title><?=gentitle_pkg($title);?></title>
107
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
108
<link href="gui.css" rel="stylesheet" type="text/css">
109
</head>
110

    
111
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
112
<?php
113
include("fbegin.inc");
114

    
115
?>
116
<p class="pgtitle"><?=$title?></p>
117
				<?php
118
			}
119
			if($pkg['preoutput']) echo "<pre>";
120
			eval($pkg['custom_add_php_command']);
121
			if($pkg['preoutput']) echo "</pre>";
122
		}
123
	}
124

    
125
	// donotsave is enabled.  lets simply exit.
126
	if($pkg['donotsave'] <> "") exit;
127

    
128
	$firstfield = "";
129
	$rows = 0;
130

    
131
	// store values in xml configration file.
132
	if (!$input_errors) {
133
		$pkgarr = array();
134
		foreach ($pkg['fields']['field'] as $fields) {
135
			if($fields['type'] == "rowhelper") {
136
				// save rowhelper items.
137
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
138
				                         // XXX: this really is not helping embedded platforms.
139
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
140
						if($firstfield == "")  {
141
						  $firstfield = $rowhelperfield['fieldname'];
142
						} else {
143
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
144
						}
145
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
146
						//echo($comd . "<br>");
147
						eval($comd);
148
						if($value <> "") {
149
							$comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";";
150
							//echo($comd . "<br>");
151
							eval($comd);
152
						}
153
					}
154
				}
155
			} else {
156
				// simply loop through all field names looking for posted
157
				// values matching the fieldnames.  if found, save to package
158
				// configuration area.
159

    
160
				$fieldname  = $fields['fieldname'];
161
				$fieldvalue = $_POST[$fieldname];
162
				$toeval = "\$pkgarr['" . $fieldname . "'] 	= \"" . $fieldvalue . "\";";
163
				eval($toeval);
164
			}
165
		}
166

    
167
		if (isset($id) && $a_pkg[$id])
168
			$a_pkg[$id] = $pkgarr;
169
		else
170
			$a_pkg[] = $pkgarr;
171

    
172
		write_config();
173

    
174
		// late running code
175
		if($pkg['custom_add_php_command_late'] <> "") {
176
		    eval($pkg['custom_add_php_command_late']);
177
		}
178

    
179
		// resync the configuration file code if defined.
180
		if($pkg['custom_php_resync_config_command'] <> "") {
181
		    eval($pkg['custom_php_resync_config_command']);
182
		}
183

    
184
		parse_package_templates();
185

    
186
		/* if start_command is defined, restart w/ this */
187
		if($pkg['start_command'] <> "")
188
		    exec($pkg['start_command'] . ">/dev/null 2&>1");
189

    
190
		/* if restart_command is defined, restart w/ this */
191
		if($pkg['restart_command'] <> "")
192
		    exec($pkg['restart_command'] . ">/dev/null 2&>1");
193

    
194
		if($pkg['aftersaveredirect'] <> "") {
195
		    header("Location:  " . $pkg['aftersaveredirect']);
196
		} else {
197
		    header("Location:  pkg.php?xml=" . $xml);
198
		}
199
		exit;
200
	}
201
}
202

    
203
?>
204
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
205
<html>
206
<head>
207
<title><?=gentitle_pkg($title);?></title>
208
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
209
<link href="gui.css" rel="stylesheet" type="text/css">
210
</head>
211

    
212
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
213

    
214
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
215
</script>
216

    
217
<?php
218
$config_tmp = $config;
219
$config = $pfSense_config;
220
include("fbegin.inc");
221
$config = $config_tmp;
222
?>
223
<p class="pgtitle"><?=$title?></p>
224
<form action="pkg_edit.php" method="post">
225
<input type="hidden" name="xml" value="<?= $xml ?>">
226
<?php if ($savemsg) print_info_box($savemsg); ?>
227

    
228
&nbsp;<br>
229

    
230
<?php
231
if ($pkg['tabs'] <> "") {
232
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
233
    echo "<tr><td>";
234
    echo "  <ul id=\"tabnav\">";
235
    foreach($pkg['tabs']['tab'] as $tab) {
236
	$active = "tabinact";
237
	if(isset($tab['active'])) $active = "tabact";
238
	$url = "";
239
	$title = $tab['text'];
240
	if($tab['url'] <> "") $url = $tab['url'];
241
	if($tab['xml'] <> "") $url = "pkg_edit.php?xml=" . $tab['xml'];
242
	if($active == "tabinact") {
243
	    echo "<li class=\"{$active}\">";
244
	    echo "<a href=\"";
245
	    echo $url;
246
	    echo "\">";
247
	    echo $title;
248
	    echo "</a>";
249
	    echo "</li>";
250
	} else {
251
	    echo "<li class=\"{$active}\">";
252
	    echo $title;
253
	    echo "</li>";
254
	}
255
    }
256
    echo "  </ul>";
257
    echo "</td></tr>";
258
    echo "<tr>";
259
    echo "<td class=\"tabcont\">";
260
}
261
?>
262

    
263
<table width="100%" border="0" cellpadding="6" cellspacing="0">
264
  <?php
265
  $cols = 0;
266
  $savevalue = "Save";
267
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
268
  foreach ($pkg['fields']['field'] as $pkga) { ?>
269

    
270
	  <?php if(!$pkga['combinefieldsend']) echo "<tr valign=\"top\">"; ?>
271

    
272
	  <?php
273
	  if(!$pkga['dontdisplayname']) {
274
		echo "<td width=\"22%\" class=\"vncellreq\">";
275
		echo fixup_string($pkga['fielddescr']);
276
		echo "</td>";
277
	  }
278

    
279
	  if(!$pkga['dontcombinecells'])
280
		echo "<td class=\"vtable\">";
281

    
282
		// if user is editing a record, load in the data.
283
		if (isset($id) && $a_pkg[$id]) {
284
			$fieldname = $pkga['fieldname'];
285
			$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
286
			echo "<!-- eval: " . $toeval . "-->\n";
287
			eval($toeval);
288
		}
289

    
290
	      if($pkga['type'] == "input") {
291
			if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
292
			echo "<input " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
293
			echo "<br>" . fixup_string($pkga['description']) . "\n";
294
	      } else if($pkga['type'] == "password") {
295
			echo "<input type='password' " . $size . " name='" . $pkga['fieldname'] . "' value='" . $value . "'>\n";
296
			echo "<br>" . fixup_string($pkga['description']) . "\n";
297
	      } else if($pkga['type'] == "select") {
298
		  // XXX: TODO: set $selected
299
                  if($pkga['size']) $size = " size='" . $pkga['size'] . "' ";
300
		  if($pkga['multiple'] == "yes") $multiple = "MULTIPLE ";
301
		    echo "<select " . $multiple . $size . "id='" . $pkga['fieldname'] . "' name='" . $pkga['fieldname'] . "'>\n";
302
		    foreach ($pkga['options']['option'] as $opt) {
303
			  $selected = "";
304
			  if($opt['value'] == $value) $selected = " SELECTED";
305
			  echo "\t<option name='" . $opt['name'] . "' value='" . $opt['value'] . "'" . $selected . ">" . $opt['name'] . "</option>\n";
306
		    }
307
		    echo "</select>\n";
308
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
309
	      } else if($pkga['type'] == "vpn_selection") {
310
		    echo "<select name='" . $vpn['name'] . "'>\n";
311
		    foreach ($config['ipsec']['tunnel'] as $vpn) {
312
			echo "\t<option value=\"" . $vpn['descr'] . "\">" . $vpn['descr'] . "</option>\n";
313
		    }
314
		    echo "</select>\n";
315
		    echo "<br>" . fixup_string($pkga['description']) . "\n";
316
	      } else if($pkga['type'] == "checkbox") {
317
			$checkboxchecked = "";
318
			if($value == "on") $checkboxchecked = " CHECKED";
319
			echo "<input type='checkbox' name='" . $pkga['fieldname'] . "'" . $checkboxchecked . ">\n";
320
			echo "<br>" . fixup_string($pkga['description']) . "\n";
321
	      } else if($pkga['type'] == "textarea") {
322
		  if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' ";
323
		  if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' ";
324
			echo "<textarea " . $rows . $cols . " name='" . $pkga['fieldname'] . "'>" . $value . "</textarea>\n";
325
			echo "<br>" . fixup_string($pkga['description']) . "\n";
326
		  } else if($pkga['type'] == "interfaces_selection") {
327
			$size = "";
328
			$multiple = "";
329
			$fieldname = $pkga['fieldname'];
330
			if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\"";
331
			if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") {
332
			  $multiple = " multiple=\"multiple\"";
333
			  $fieldname .= "[]";
334
			}
335
			echo "<select name='" . $fieldname . "'" . $size . $multiple . ">\n";
336
			foreach ($config['interfaces'] as $ifname => $iface) {
337
			  if ($iface['descr'])
338
				  $ifdescr = $iface['descr'];
339
			  else
340
				  $ifdescr = strtoupper($ifname);
341
			  $ifname = $iface['if'];
342
			  $SELECTED = "";
343
			  if($value == $ifname) $SELECTED = " SELECTED";
344
			  echo "<option value='" . $ifname . "'" . $SELECTED . ">" . $ifdescr . "</option>\n";
345
			}
346
			echo "</select>\n";
347
			echo "<br>" . fixup_string($pkga['description']) . "\n";
348
	      } else if($pkga['type'] == "radio") {
349
			echo "<input type='radio' name='" . $pkga['fieldname'] . "' value='" . $value . "'>";
350
	      } else if($pkga['type'] == "rowhelper") {
351
		?>
352
			<script type="text/javascript" language='javascript'>
353
			<!--
354

    
355
			<?php
356
				$rowcounter = 0;
357
				$fieldcounter = 0;
358
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
359
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
360
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
361
					$fieldcounter++;
362
				}
363
			?>
364

    
365
			-->
366
			</script>
367

    
368
			<table name="maintable" id="maintable">
369
			<tr>
370
			<?php
371
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
372
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
373
				}
374
				echo "</tr>";
375
				echo "<tbody>";
376

    
377
				echo "<tr>";
378
				  // XXX: traverse saved fields, add back needed rows.
379
				echo "</tr>";
380

    
381
				echo "<tr>\n";
382
				$rowcounter = 0;
383
				$trc = 0;
384
				if(isset($a_pkg[$id]['row'])) {
385
					foreach($a_pkg[$id]['row'] as $row) {
386
					/*
387
					 * loop through saved data for record if it exists, populating rowhelper
388
					 */
389
						foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
390
							if($rowhelper['value'] <> "") $value = $rowhelper['value'];
391
							$fieldname = $rowhelper['fieldname'];
392
							// if user is editing a record, load in the data.
393
							if (isset($id) && $a_pkg[$id]) {
394
								$toeval = "\$value = \$row['" . $fieldname . "'];";
395
								echo "<!-- eval: " . $toeval . "-->\n";
396
								eval($toeval);
397
								echo "<!-- value: " . $value . "-->\n";
398
							}
399
							$options = "";
400
							$type = $rowhelper['type'];
401
							$fieldname = $rowhelper['fieldname'];
402
							if($type == "option") $options = &$rowhelper['options']['option'];
403
							$size = "8";
404
							if($rowhelper['size'] <> "") $size = $rowhelper['size'];
405
							display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
406
							// javascript helpers for row_helper_dynamic.js
407
							echo "</td>\n";
408
							echo "<script language=\"JavaScript\">\n";
409
							echo "<!--\n";
410
							echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
411
							echo "-->\n";
412
							echo "</script>\n";
413
							$text = "";
414
							$trc++;
415
						}
416

    
417
						$rowcounter++;
418
						echo "<td>";
419
						echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
420
						echo "</td>\n";
421
						echo "</tr>\n";
422
					}
423
				}
424
				if($trc == 0) {
425
					/*
426
					 *  no records loaded.
427
                                         *  just show a generic line non-populated with saved data
428
                                         */
429
                                        foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
430
						if($rowhelper['value'] <> "") $value = $rowhelper['value'];
431
						$fieldname = $rowhelper['fieldname'];
432
						$options = "";
433
						$type = $rowhelper['type'];
434
						$fieldname = $rowhelper['fieldname'];
435
						if($type == "option") $options = &$rowhelper['options']['option'];
436
						$size = "8";
437
						if($rowhelper['size'] <> "") $size = $rowhelper['size'];
438
						display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
439
						// javascript helpers for row_helper_dynamic.js
440
						echo "</td>\n";
441
						echo "<script language=\"JavaScript\">\n";
442
						echo "<!--\n";
443
						echo "newrow[" . $trc . "] = \"" . $text . "\";\n";
444
						echo "-->\n";
445
						echo "</script>\n";
446
						$text = "";
447
						$trc++;
448
					}
449

    
450
					$rowcounter++;
451
				}
452
			?>
453

    
454
			  </tbody>
455
			</table>
456

    
457
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
458
		<script language="JavaScript">
459
		<!--
460
		field_counter_js = <?= $fieldcounter ?>;
461
		rows = <?= $rowcounter ?>;
462
		totalrows = <?php echo $rowcounter; ?>;
463
		loaded = <?php echo $rowcounter; ?>;
464
		//typesel_change();
465
		//-->
466
		</script>
467

    
468
		<?php
469
	      }
470
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
471
	     ?>
472

    
473
      <?php
474
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
475
      $i++;
476
  }
477
 ?>
478
  <tr>
479
	<td>&nbsp;</td>
480
  </tr>
481
  <tr>
482
    <td width="22%" valign="top">&nbsp;</td>
483
    <td width="78%">
484
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
485
      <?php if (isset($id) && $a_pkg[$id]): ?>
486
      <input name="id" type="hidden" value="<?=$id;?>">
487
      <?php endif; ?>
488
    </td>
489
  </tr>
490
</table>
491

    
492
<?php
493
if ($pkg['tabs'] <> "") {
494
    echo "</td></tr></table>";
495
}
496
?>
497

    
498
</form>
499
<?php include("fend.inc"); ?>
500
</body>
501
</html>
502

    
503
<?php
504

    
505
/*
506
 * ROW Helpers function
507
 */
508
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
509
	global $text;
510
	echo "<td>\n";
511
	if($type == "input") {
512
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
513
	} else if($type == "password") {
514
		echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
515
	} else if($type == "textarea") {
516
		echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
517
	} else if($type == "select") {
518
		echo "<select name='" . $fieldname . $trc . "'>\n";
519
		foreach($rowhelper['options']['option'] as $rowopt) {
520
			$selected = "";
521
			if($rowopt['value'] == $value) $selected = " SELECTED";
522
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
523
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
524
		}
525
		echo "</select>\n";
526
	}
527
}
528

    
529
function fixup_string($string) {
530
	global $config;
531
	// fixup #1: $myurl -> http[s]://ip_address:port/
532
	$https = "";
533
	$port = "";
534
	$urlport = "";
535
	$port = $config['system']['webguiport'];
536
	if($port <> "443" and $port <> "80") $urlport = ":" . $port;
537
	if($config['system']['webguiproto'] == "https") $https = "s";
538
	$myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport;
539
	$newstring = str_replace("\$myurl", $myurl, $string);
540
	$string = $newstring;
541
	// fixup #2: $wanip
542
	$curwanip = get_current_wan_address();
543
	$newstring = str_replace("\$wanip", $curwanip, $string);
544
	$string = $newstring;
545
	// fixup #3: $lanip
546
	$lancfg = $config['interfaces']['lan'];
547
	$lanip = $lancfg['ipaddr'];
548
	$newstring = str_replace("\$lanip", $lanip, $string);
549
	$string = $newstring;
550
	// fixup #4: fix'r'up here.
551
	return $newstring;
552
}
553

    
554
/*
555
 *  Parse templates if they are defined
556
 */
557
function parse_package_templates() {
558
	global $pkg, $config;
559
	if($pkg['templates']['template'] <> "")
560
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
561
		$filename = $pkg_template_row['filename'];
562
		$template_text = $pkg_template_row['templatecontents'];
563

    
564
		/* calculate total row helpers count */
565
		foreach ($pkg['fields']['field'] as $fields) {
566
			if($fields['type'] == "rowhelper") {
567
				// save rowhelper items.
568
                                $row_helper_total_rows = 0;
569
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
570
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
571
						if($firstfield == "")  {
572
						  $firstfield = $rowhelperfield['fieldname'];
573
						} else {
574
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
575
						}
576
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
577
						eval($comd);
578
						if($value <> "") {
579
						    //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
580
						} else {
581
						    $row_helper_total_rows = $rows;
582
						    break;
583
						}
584
					}
585
				}
586
			}
587
		}
588

    
589
		/* replace $domain_total_rows with total rows */
590
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
591

    
592
		/* change fields defined as fieldname_fieldvalue to their value */
593
		foreach ($pkg['fields']['field'] as $fields) {
594
			if($fields['type'] == "rowhelper") {
595
				// save rowhelper items.
596
				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
597
					$row_helper_data = "";
598
					$isfirst = 0;
599
					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
600
						if($firstfield == "")  {
601
						  $firstfield = $rowhelperfield['fieldname'];
602
						} else {
603
						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
604
						}
605
						$comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];";
606
						eval($comd);
607
						if($value <> "") {
608
						    if($isfirst == 1) $row_helper_data .= "  " ;
609
						    $row_helper_data .= $value;
610
						    $isfirst = 1;
611
						}
612
						ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
613
						foreach ($sep as $se) $seperator = $se;
614
						if($seperator <> "") {
615
						    $row_helper_data = ereg_replace("  ", $seperator, $row_helper_data);
616
						    $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text);
617
						}
618
						$template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
619
					}
620
				}
621
			} else {
622
				$fieldname  = $fields['fieldname'];
623
				$fieldvalue = $_POST[$fieldname];
624
				$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
625
			}
626
		}
627

    
628
		/* replace cr's */
629
		$template_text = str_replace("\\n", "\n", $template_text);
630

    
631
		/* write out new template file */
632
		$fout = fopen($filename,"w");
633
		fwrite($fout, $template_text);
634
		fclose($fout);
635
	    }
636
}
637

    
638
?>
(54-54/100)