'opt_pass');
foreach($bools as $bool) {
if(format_bool($GLOBALS[$bool])) {
- $tem->set($bool, 1);
- } else {
- $tem->set($bool . '_else', 1);
+ $tem->set($bool);
}
}
-
}
function metaform() {
# pass false if you want to exclude the <head> and <body> tag etc.
function make_html($whole_file = true) {
- $uploads_output_already = false;
$has_html_editors = false;
$tem = new tem();
$tem->load('code/wfpl/metaform/template.html');
tem_set_globals($tem);
$fields = get_fields();
$tem->set('always_field', find_always_field($fields));
+ $hidden_fields = array();
+ $visible_fields = array();
+ $display_fields = array();
+ $listing_headers = array();
+ $listing_fields = array();
foreach($fields as $field) {
list($name, $type, $input, $format, $sql) = $field;
- $tem->set('name', $name);
- $tem->set('caption', format_caption($name));
- $tem->show($input);
- if($input != 'hidden') {
- $tem->show('row');
+ if($input == 'hidden') {
+ $hidden_fields[] = array('name' => $name);
+ } else {
+ $visible_fields[] = array($input => array(
+ 'name' => $name,
+ 'caption' => format_caption($name)));
}
- if(($input == 'image' || $input == 'file') && !$uploads_output_already) {
- $tem->show('uploads');
+ if($input == 'image' || $input == 'file') {
+ $tem->set('uploads');
$tem->set('enctype_attr', '" enctype="multipart/form-data');
- $uploads_output_already = true;
} elseif($input == 'html') {
$has_html_editors = true;
$tem->set('html_field_name', $name);
- $tem->show('replace_textarea');
+ $tem->set('replace_textarea');
}
- if($GLOBALS['opt_display'] == 'Yes') {
- switch($input) {
- case 'image':
- $tem->show('display_image');
- break;
- case 'checkbox':
- $tem->show('display_yesno');
- break;
- case 'date':
- $tem->show('display_date');
- break;
- case 'textarea':
- $tem->show('display_multiline');
- break;
- case 'html':
- $tem->show('display_html');
- break;
- default:
- $tem->show('display_short');
- }
- $tem->show('display_row');
+ switch($input) {
+ case 'image':
+ case 'checkbox':
+ case 'date':
+ case 'textarea':
+ case 'html':
+ $display_type = $input;
+ break;
+ default:
+ $display_type = 'short';
}
-
- if($GLOBALS['opt_listing'] == 'Yes') {
- if(show_in_listing($type, $input, $format, $sql)) {
- if($format == 'bool' || $format == 'yesno') {
- $tem->set('listing_enc', 'yesno');
- $tem->show('listing_value_enc');
- } elseif($input == 'date') {
- $tem->set('listing_enc', 'mmddyyyy');
- $tem->show('listing_value_enc');
- } elseif($type == 'thumb') {
- $tem->show('listing_value_thumb');
- } else {
- $tem->set('listing_enc', 'html');
- $tem->show('listing_value_enc');
- }
-
- $tem->show('listing_head_col');
- $tem->show('listing_row_col');
+ $display_fields[] = array($display_type => array(
+ 'name' => $name, 'caption' => format_caption($name)));
+
+ if(show_in_listing($type, $input, $format, $sql)) {
+ $listing_headers[] = array('caption' => format_caption($name));
+ $listing_field = array('name' => $name);
+ if($format == 'bool' || $format == 'yesno') {
+ $listing_field['enc'] = 'yesno';
+ } elseif($input == 'date') {
+ $listing_field['enc'] = 'mmddyyyy';
+ } elseif($type == 'thumb') {
+ $listing_field['thumb'] = true;
+ } else {
+ $listing_field['enc'] = 'html';
}
+ $listing_fields[] = $listing_field;
}
}
+ # Submit/Send button
if($GLOBALS['opt_email'] == 'Yes' && $GLOBALS['opt_db'] != 'Yes') {
- $tem->set('name', 'send');
- $tem->set('caption', 'Send');
+ $visible_fields[] = array('submit' => array(
+ 'name' => 'send',
+ 'caption' => 'Send'));
} else {
- $tem->set('name', 'save');
- $tem->set('caption', 'Save');
+ $visible_fields[] = array('submit' => array(
+ 'name' => 'save',
+ 'caption' => 'Save'));
}
- $tem->show('submit');
- $tem->show('row');
- $tem->show('form');
+ $tem->set('form', array(
+ 'visible_fields' => $visible_fields,
+ 'hidden_fields' => $hidden_fields));
+
+ # opt_display and opt_listing control whether these are actually displayed
+ $tem->set('display_fields', $display_fields);
+ $tem->set('listing_headers', $listing_headers);
+ $tem->set('listing_fields', $listing_fields);
+
if($has_html_editors) {
- $tem->show('html_editor_headers');
+ $tem->set('html_editor_headers');
}
if($whole_file) {
return $tem->run();
} else {
- return $tem->get('form');
+ $tem2 = new tem();
+ $tem2->load_str('<!--~form~-->');
+ $tem2->merge($tem);
+ return $tem2->run();
}
}