Project

General

Profile

Download (20.8 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
<?php
208
    if($pkg['title'] <> "") $title = $pkg['title'];
209
?>
210
<title><?=gentitle_pkg($title);?></title>
211
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
212
<link href="gui.css" rel="stylesheet" type="text/css">
213
</head>
214

    
215
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
216

    
217
<script type="text/javascript" language="javascript" src="row_helper_dynamic.js">
218
</script>
219

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

    
231
<?php
232
if ($pkg['tabs'] <> "") {
233
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
234
    echo "<tr><td>";
235
    echo "  <ul id=\"tabnav\">";
236
    foreach($pkg['tabs']['tab'] as $tab) {
237
	$active = "tabinact";
238
	if(isset($tab['active'])) $active = "tabact";
239

    
240
	$urltmp = "";
241
	$title = $tab['text'];
242
	if($tab['url'] <> "") $urltmp = $tab['url'];
243
	if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
244

    
245
	$toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n";
246
	eval($toeval);
247
	// eval url so that above $myurl item can be processed if need be.
248
	$toeval = "\$url = \"" . $urltmp . "\"; \n";
249
	eval($toeval);
250

    
251
	if($active == "tabinact") {
252
	    echo "<li class=\"{$active}\">";
253
	    echo "<a href=\"";
254
	    echo $url;
255
	    echo "\">";
256
	    echo $title;
257
	    echo "</a>";
258
	    echo "</li>";
259
	} else {
260
	    echo "<li class=\"{$active}\">";
261
	    echo $title;
262
	    echo "</li>";
263
	}
264
    }
265
    echo "  </ul>";
266
    echo "</td></tr>";
267
    echo "<tr>";
268
    echo "<td class=\"tabcont\">";
269
}
270
?>
271

    
272
<table width="100%" border="0" cellpadding="6" cellspacing="0">
273
  <?php
274
  $cols = 0;
275
  $savevalue = "Save";
276
  if($pkg['savetext'] <> "") $savevalue = $pkg['savetext'];
277
  foreach ($pkg['fields']['field'] as $pkga) { ?>
278

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

    
281
	  <?php
282
	  if(!$pkga['dontdisplayname']) {
283
		echo "<td width=\"22%\" class=\"vncellreq\">";
284
		echo fixup_string($pkga['fielddescr']);
285
		echo "</td>";
286
	  }
287

    
288
	  if(!$pkga['dontcombinecells'])
289
		echo "<td class=\"vtable\">";
290

    
291
		// if user is editing a record, load in the data.
292
		if (isset($id) && $a_pkg[$id]) {
293
			$fieldname = $pkga['fieldname'];
294
			$toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];";
295
			echo "<!-- eval: " . $toeval . "-->\n";
296
			eval($toeval);
297
		}
298

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

    
364
			<?php
365
				$rowcounter = 0;
366
				$fieldcounter = 0;
367
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
368
					echo "rowname[" . $fieldcounter . "] = \"" . $rowhelper['fieldname'] . "\";\n";
369
					echo "rowtype[" . $fieldcounter . "] = \"" . $rowhelper['type'] . "\";\n";
370
					$fieldcounter++;
371
				}
372
			?>
373

    
374
			-->
375
			</script>
376

    
377
			<table name="maintable" id="maintable">
378
			<tr>
379
			<?php
380
				foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
381
				  echo "<td><b>" . fixup_string($rowhelper['fielddescr']) . "</td>\n";
382
				}
383
				echo "</tr>";
384
				echo "<tbody>";
385

    
386
				echo "<tr>";
387
				  // XXX: traverse saved fields, add back needed rows.
388
				echo "</tr>";
389

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

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

    
459
					$rowcounter++;
460
				}
461
			?>
462

    
463
			  </tbody>
464
			</table>
465

    
466
		<br><a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
467
		<script language="JavaScript">
468
		<!--
469
		field_counter_js = <?= $fieldcounter ?>;
470
		rows = <?= $rowcounter ?>;
471
		totalrows = <?php echo $rowcounter; ?>;
472
		loaded = <?php echo $rowcounter; ?>;
473
		//typesel_change();
474
		//-->
475
		</script>
476

    
477
		<?php
478
	      }
479
	      if($pkga['typehint']) echo " " . $pkga['typehint'];
480
	     ?>
481

    
482
      <?php
483
	  if(!$pkga['combinefieldsbegin']) echo "</td></tr>";
484
      $i++;
485
  }
486
 ?>
487
  <tr>
488
	<td>&nbsp;</td>
489
  </tr>
490
  <tr>
491
    <td width="22%" valign="top">&nbsp;</td>
492
    <td width="78%">
493
      <input name="Submit" type="submit" class="formbtn" value="<?= $savevalue ?>">
494
      <?php if (isset($id) && $a_pkg[$id]): ?>
495
      <input name="id" type="hidden" value="<?=$id;?>">
496
      <?php endif; ?>
497
    </td>
498
  </tr>
499
</table>
500

    
501
<?php
502
if ($pkg['tabs'] <> "") {
503
    echo "</td></tr></table>";
504
}
505
?>
506

    
507
</form>
508
<?php include("fend.inc"); ?>
509
</body>
510
</html>
511

    
512
<?php
513

    
514
/*
515
 * ROW Helpers function
516
 */
517
function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
518
	global $text;
519
	echo "<td>\n";
520
	if($type == "input") {
521
		echo "<input size='" . $size . "' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
522
	} else if($type == "password") {
523
		echo "<input size='" . $size . "' type='password' name='" . $fieldname . $trc . "' value='" . $value . "'>\n";
524
	} else if($type == "textarea") {
525
		echo "<textarea rows='2' cols='12' name='" . $fieldname . $trc . "'>" . $value . "</textarea>\n";
526
	} else if($type == "select") {
527
		echo "<select name='" . $fieldname . $trc . "'>\n";
528
		foreach($rowhelper['options']['option'] as $rowopt) {
529
			$selected = "";
530
			if($rowopt['value'] == $value) $selected = " SELECTED";
531
			$text .= "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>";
532
			echo "<option value='" . $rowopt['value'] . "'" . $selected . ">" . $rowopt['name'] . "</option>\n";
533
		}
534
		echo "</select>\n";
535
	}
536
}
537

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

    
563
/*
564
 *  Parse templates if they are defined
565
 */
566
function parse_package_templates() {
567
	global $pkg, $config;
568
	if($pkg['templates']['template'] <> "")
569
	    foreach($pkg['templates']['template'] as $pkg_template_row) {
570
		$filename = $pkg_template_row['filename'];
571
		$template_text = $pkg_template_row['templatecontents'];
572

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

    
598
		/* replace $domain_total_rows with total rows */
599
		$template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
600

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

    
637
		/* replace cr's */
638
		$template_text = str_replace("\\n", "\n", $template_text);
639

    
640
		/* write out new template file */
641
		$fout = fopen($filename,"w");
642
		fwrite($fout, $template_text);
643
		fclose($fout);
644
	    }
645
}
646

    
647
?>
(54-54/100)