From: Jason Woofenden
Date: Mon, 11 Dec 2006 21:12:35 +0000 (-0500)
Subject: added tar.php. metaform working
X-Git-Url: https://jasonwoof.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=c6b6624fdc65060f3a54d9902b28c8c103da7709;p=wfpl.git
added tar.php. metaform working
---
diff --git a/metaform.php b/metaform.php
index c20515e..74ec74f 100644
--- a/metaform.php
+++ b/metaform.php
@@ -1,6 +1,29 @@
array('textbox', 'url', 'varchar(200)'),
'textarea' => array('textarea', 'unix', 'text'),
'pulldown' => array('pulldown', 'options', 'int'),
- 'checkbox' => array('checkbox', 'yesno', 'int'),
- 'yesno' => array('checkbox', 'yesno', 'int'),
+ 'checkbox' => array('checkbox', 'yesno', 'int'),
+ 'yesno' => array('checkbox', 'yesno', 'int'),
'submit' => array('submit', 'oneline', 'n/a')
);
if(isset($_REQUEST['form_name'])) {
- $GLOBALS['form_name'] = $_REQUEST['form_name'];
+ $GLOBALS['form_name'] = ereg_replace('[^a-z0-9_-]', '', $_REQUEST['form_name']);
} else {
$GLOBALS['form_name'] = 'some_form';
}
if(isset($_REQUEST['fields'])) {
- if(isset($_REQUEST['download_sql'])) {
- download_sql();
+ if(isset($_REQUEST['view_sql'])) {
+ view_sql();
exit();
- } elseif(isset($_REQUEST['download_php'])) {
- download_php();
+ } elseif(isset($_REQUEST['view_php'])) {
+ view_php();
exit();
- } elseif(isset($_REQUEST['download_template'])) {
- download_template();
+ } elseif(isset($_REQUEST['view_template'])) {
+ view_template();
exit();
- } elseif(isset($_REQUEST['download_email'])) {
- download_email();
+ } elseif(isset($_REQUEST['view_email'])) {
+ view_email();
exit();
- } else {
- tem_set('message', "Sorry... couldn't tell which button you pressed");
+ } elseif(isset($_REQUEST['download_tar'])) {
+ download_tar();
+ exit();
+ } elseif(isset($_REQUEST['preview'])) {
+ preview();
+ exit();
+ } elseif(isset($_REQUEST['edit'])) {
+ tem_set('fields', $_REQUEST['fields']);
+ tem_set('form_name', $GLOBALS['form_name']);
# fall through
+ } else {
+ die("Sorry... couldn't tell which button you pressed");
}
-} else {
- tem_output('code/wfpl/metaform/main.html');
}
+set_form_action();
+tem_output('code/wfpl/metaform/main.html');
+exit();
+
+
function field_input($type) { return $GLOBALS['types'][$type][0]; }
function field_format($type) { return $GLOBALS['types'][$type][1]; }
function field_sql($type) { return $GLOBALS['types'][$type][2]; }
@@ -67,97 +102,151 @@ function get_fields() {
return $ret;
}
-function download_headers() {
- header('Content-type: application/octet-stream');
- header('Content-disposition: download'); # is this correct? does it do anything?
+function set_form_action() {
+ $action = ereg_replace('.*/', '', $_SERVER['REQUEST_URI']);
+ if($action == '') $action = './';
+ tem_set('form_action', $action);
+}
+
+# perfect HTTP headers for viewing created files
+function view_headers() {
+ header('Content-type: text/plain');
}
-function download_sql() {
- tem_load('code/wfpl/metaform/template.sql');
- tem_set('form_name', $GLOBALS['form_name']);
+function make_sql() {
+ $tem = new tem();
+ $tem->load('code/wfpl/metaform/template.sql');
+ $tem->set('form_name', $GLOBALS['form_name']);
$fields = get_fields();
foreach($fields as $field) {
list($name, $type, $input, $format, $sql) = $field;
if($sql != 'n/a') {
- tem_set('name', $name);
- tem_set('type', $sql);
+ $tem->set('name', $name);
+ $tem->set('type', $sql);
if($sql == 'int') {
- tem_set('default', '0');
+ $tem->set('default', '0');
} else {
- tem_set('default', '""');
+ $tem->set('default', '""');
}
- tem_sub('column');
+ $tem->sub('column');
}
}
- download_headers();
- tem_output();
+ view_headers();
+ return $tem->run();
+}
+
+function view_sql() {
+ view_headers();
+ echo make_sql();
}
-function download_template() {
- tem_load('code/wfpl/metaform/template.html');
- tem_set('form_name', $GLOBALS['form_name']);
+# pass false if you want to exclude the and tag etc.
+function make_template($whole_file = true) {
+ $tem = new tem();
+ $tem->load('code/wfpl/metaform/template.html');
+ $tem->set('form_name', $GLOBALS['form_name']);
$fields = get_fields();
foreach($fields as $field) {
list($name, $type, $input, $format, $sql) = $field;
- tem_set('name', $name);
- tem_set('caption', $name); # fixme
- tem_sub($input);
+ $tem->set('name', $name);
+ $tem->set('caption', $name); # fixme
+ $tem->sub($input);
}
- tem_set('name', 'save');
- tem_set('caption', 'Save');
- tem_sub('submit');
- download_headers();
- tem_output();
+ $tem->set('name', 'save');
+ $tem->set('caption', 'Save');
+ $tem->sub('submit');
+ $tem->sub('body');
+ if($whole_file) {
+ return $tem->run();
+ } else {
+ return $tem->get('body');
+ }
+}
+
+function view_template() {
+ view_headers();
+ echo make_template();
}
-function download_php() {
- tem_load('code/wfpl/metaform/template.php');
- tem_set('form_name', $GLOBALS['form_name']);
+function make_php() {
+ $tem = new tem();
+ $tem->load('code/wfpl/metaform/template.php');
+ $tem->set('form_name', $GLOBALS['form_name']);
$fields = get_fields();
$db_fields = '';
$always_field = false;
foreach($fields as $field) {
list($name, $type, $input, $format, $sql) = $field;
if($input != 'submit') {
- tem_set('format', $format);
- tem_set('name', $name);
- tem_set('db_field', ''); # we don't want to use the value from last time
+ $tem->set('format', $format);
+ $tem->set('name', $name);
+ $tem->set('db_field', ''); # we don't want to use the value from last time
if($sql != 'n/a') {
- tem_sub('db_field');
+ $tem->sub('db_field');
if($db_fields != '') $db_fields .= ',';
$db_fields .= $name;
}
- tem_sub('formats');
+ $tem->sub('formats');
if(!$always_field and $input != 'checkbox' and $input != 'radio') {
$always_field = $name;
}
}
}
# always_field is a form field that always submits (unlike say, checkboxes). It's used to detect if the form has submitted or not.
- tem_set('always_field', $always_field);
- tem_set('db_fields', $db_fields);
- download_headers();
- tem_output();
+ $tem->set('always_field', $always_field);
+ $tem->set('db_fields', $db_fields);
+ return $tem->run();
+}
+
+function view_php() {
+ view_headers();
+ echo make_php();
}
-function download_email() {
- tem_load('code/wfpl/metaform/template.email.txt');
- tem_set('form_name', $GLOBALS['form_name']);
+function make_email() {
+ $tem = new tem();
+ $tem->load('code/wfpl/metaform/template.email.txt');
+ $tem->set('form_name', $GLOBALS['form_name']);
$fields = get_fields();
foreach($fields as $field) {
list($name, $type, $input, $format, $sql) = $field;
- tem_set('name', $name);
- tem_set('caption', $name); # fixme
- tem_sub('fields');
+ $tem->set('name', $name);
+ $tem->set('caption', $name); # fixme
+ $tem->sub('fields');
}
- download_headers();
- tem_output();
+ return $tem->run();
+}
+
+function view_email() {
+ view_headers();
+ echo make_email();
+}
+
+
+function preview() {
+ $tem = new tem();
+ $tem->load('code/wfpl/metaform/preview.html');
+ $tem->set('form_name', $GLOBALS['form_name']);
+ $tem->set('fields', $_REQUEST['fields']);
+ $tem->set('preview', make_template(false));
+ set_form_action();
+ $tem->output();
+}
+
+function download_tar() {
+ $name = $GLOBALS['form_name'];
+ $data = array(
+ "$name.html" => make_template(),
+ "$name.sql" => make_sql(),
+ "$name.email.txt" => make_email(),
+ "$name.php" => make_php());
+ make_tar($name, $data);
}
?>
diff --git a/metaform/main.html b/metaform/main.html
index 64c09d4..e8ab716 100644
--- a/metaform/main.html
+++ b/metaform/main.html
@@ -6,19 +6,23 @@
-
+ Fields:
+
-
+
diff --git a/metaform/preview.html b/metaform/preview.html
new file mode 100644
index 0000000..041cfd8
--- /dev/null
+++ b/metaform/preview.html
@@ -0,0 +1,28 @@
+
+
+
+
+ Meta Form
+
+
+
+ Preview
+
+~preview~
+
+
+
+
+
+
diff --git a/metaform/template.html b/metaform/template.html
index ca0d271..426be60 100644
--- a/metaform/template.html
+++ b/metaform/template.html
@@ -6,6 +6,7 @@
+
~form_name~ entry form
+