3 require_once('code/wfpl/template.php');
5 # see code/wfpl/metaform/template.html for the html templates for these elements
6 $GLOBALS['types'] = array(
7 # type input format sql
8 'name' => array('textbox', 'oneline', 'varchar(200)'),
9 'textbox' => array('textbox', 'oneline', 'varchar(200)'),
10 'email' => array('textbox', 'email', 'varchar(100)'),
11 'phone' => array('textbox', 'phone', 'varchar(32)'),
12 'money' => array('textbox', 'money', 'varchar(32)'),
13 'dollars' => array('textbox', 'dollars', 'varchar(32)'),
14 'url' => array('textbox', 'url', 'varchar(200)'),
15 'textarea' => array('textarea', 'unix', 'text'),
16 'pulldown' => array('pulldown', 'options', 'int'),
17 'checkbox' => array('checkbox', 'yesno', 'int'),
18 'yesno' => array('checkbox', 'yesno', 'int'),
19 'submit' => array('submit', 'oneline', 'n/a')
22 if(isset($_REQUEST['form_name'])) {
23 $GLOBALS['form_name'] = $_REQUEST['form_name'];
25 $GLOBALS['form_name'] = 'some_form';
28 if(isset($_REQUEST['fields'])) {
29 if(isset($_REQUEST['download_sql'])) {
32 } elseif(isset($_REQUEST['download_php'])) {
35 } elseif(isset($_REQUEST['download_template'])) {
38 } elseif(isset($_REQUEST['download_email'])) {
42 tem_set('message', "Sorry... couldn't tell which button you pressed");
46 tem_output('code/wfpl/metaform/main.html');
49 function field_input($type) { return $GLOBALS['types'][$type][0]; }
50 function field_format($type) { return $GLOBALS['types'][$type][1]; }
51 function field_sql($type) { return $GLOBALS['types'][$type][2]; }
53 function get_fields() {
54 $fields_str = unix_newlines($_REQUEST['fields']);
56 $fields_str = rtrim($fields_str);
57 $fields = split("\n", $fields_str);
58 foreach($fields as $field) {
59 list($name, $type, $options) = split(' *', $field);
60 if($options) $options = split(',', $options);
61 if(!$type) $type = $name;
62 $input = field_input($type);
63 $format = field_format($type);
64 $sql = field_sql($type);
65 $ret[] = array($name, $type, $input, $format, $sql, $options);
70 function download_headers() {
71 header('Content-type: application/octet-stream');
72 header('Content-disposition: download'); # is this correct? does it do anything?
78 function download_sql() {
79 tem_load('code/wfpl/metaform/template.sql');
80 tem_set('form_name', $GLOBALS['form_name']);
81 $fields = get_fields();
82 foreach($fields as $field) {
83 list($name, $type, $input, $format, $sql) = $field;
85 tem_set('name', $name);
86 tem_set('type', $sql);
88 tem_set('default', '0');
90 tem_set('default', '""');
100 function download_template() {
101 tem_load('code/wfpl/metaform/template.html');
102 tem_set('form_name', $GLOBALS['form_name']);
103 $fields = get_fields();
104 foreach($fields as $field) {
105 list($name, $type, $input, $format, $sql) = $field;
106 tem_set('name', $name);
107 tem_set('caption', $name); # fixme
110 tem_set('name', 'save');
111 tem_set('caption', 'Save');
118 function download_php() {
119 tem_load('code/wfpl/metaform/template.php');
120 tem_set('form_name', $GLOBALS['form_name']);
121 $fields = get_fields();
123 $always_field = false;
124 foreach($fields as $field) {
125 list($name, $type, $input, $format, $sql) = $field;
126 if($input != 'submit') {
127 tem_set('format', $format);
128 tem_set('name', $name);
129 tem_set('db_field', ''); # we don't want to use the value from last time
132 if($db_fields != '') $db_fields .= ',';
136 if(!$always_field and $input != 'checkbox' and $input != 'radio') {
137 $always_field = $name;
141 # always_field is a form field that always submits (unlike say, checkboxes). It's used to detect if the form has submitted or not.
142 tem_set('always_field', $always_field);
143 tem_set('db_fields', $db_fields);
149 function download_email() {
150 tem_load('code/wfpl/metaform/template.email.txt');
151 tem_set('form_name', $GLOBALS['form_name']);
152 $fields = get_fields();
153 foreach($fields as $field) {
154 list($name, $type, $input, $format, $sql) = $field;
155 tem_set('name', $name);
156 tem_set('caption', $name); # fixme