+ 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') {
+ $tem->set('uploads');
+ $tem->set('enctype_attr', '" enctype="multipart/form-data');
+ } elseif($input == 'html') {
+ $has_html_editors = true;
+ $tem->set('html_field_name', $name);
+ $tem->set('replace_textarea');
+ }
+
+ switch($input) {
+ case 'image':
+ case 'checkbox':
+ case 'date':
+ case 'textarea':
+ case 'html':
+ $display_type = $input;
+ break;
+ default:
+ $display_type = 'short';
+ }
+ if($format != 'n/a') {
+ $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']) {
+ $visible_fields[] = array('submit' => array(
+ 'name' => 'send',
+ 'caption' => 'Send'));
+ } else {
+ $visible_fields[] = array('submit' => array(
+ 'name' => 'save',
+ 'caption' => 'Save'));
+ }
+
+ $form_fields = array();
+ $form_fields['visible_fields'] = $visible_fields;
+ if($hidden_fields) {
+ $form_fields['hidden_fields'] = $hidden_fields;
+ }
+ $tem->set('form', $form_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->set('html_editor_headers');
+ }
+
+ if($whole_file) {
+ return $tem->run();
+ } else {
+ $tem2 = new tem();
+ $tem2->load_str('<!--~form~-->');
+ $tem2->merge($tem);
+ return $tem2->run();
+ }
+}
+
+function view_html() {
+ view_headers();
+ echo make_html();
+}
+
+function show_in_listing($type, $input, $format, $sql) {
+ switch($input) {
+ case 'submit':
+ case 'hidden':
+ case 'password':
+ case 'textarea':
+ case 'html':
+ case 'fieldset':
+ case 'end_fieldset':
+ return false;
+ }
+ if($type == 'image') {
+ return false;
+ }
+
+ return true;