From 22de8c3b298601951b213b3d6612e33f8fdf968a Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 18 May 2004 03:39:38 +0000 Subject: [PATCH] Add form making script. Header updates. --- www/data/make-form.php | 547 +++++++++++++++++++++++++++++++++++++++++ www/phplib/html.php | 3 +- 2 files changed, 549 insertions(+), 1 deletion(-) create mode 100755 www/data/make-form.php diff --git a/www/data/make-form.php b/www/data/make-form.php new file mode 100755 index 0000000..8f2fd42 --- /dev/null +++ b/www/data/make-form.php @@ -0,0 +1,547 @@ +#!/usr/bin/php +Bad command '\$op'!\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" if ((\$op == 'D' || \$op == 'M') && !\$id)\n"); +print(" {\n"); +print(" html_header(\"$tname Error\");\n"); +print(" print(\"

Command '\$op' requires an ID!\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" if (\$op == 'N' && \$id)\n"); +print(" {\n"); +print(" html_header(\"$tname Error\");\n"); +print(" print(\"

Command '\$op' may not have an ID!\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("}\n"); +print("else\n"); +print("{\n"); +print(" \$op = 'L';\n"); +print(" \$id = 0;\n"); +print("}\n"); +print("\n"); +print("switch (\$op)\n"); +print("{\n"); +print(" case 'D' : // Delete $tname\n"); +print(" if (\$REQUEST_METHOD == \"POST\")\n"); +print(" {\n"); +print(" db_query(\"DELETE FROM $table WHERE id = \$id\");\n"); +print("\n"); +print(" header(\"Location: \$PHP_SELF?L\");\n"); +print(" }\n"); +print(" else\n"); +print(" {\n"); +print(" \$result = db_query(\"SELECT * FROM $table WHERE id = \$id\");\n"); +print(" if (db_count(\$result) != 1)\n"); +print(" {\n"); +print(" print(\"

Error: $tname #\$id was not found!

\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" \$row = db_next(\$result);\n"); +print("\n"); +print(" html_header(\"Delete $tname #\$id\");\n"); +print("\n"); +print(" html_startlinks(1);\n"); +print(" html_link(\"Return to $tname List\", \"\$PHP_SELF?L\");\n"); +print(" html_link(\"View $tname #\$id\", \"\$PHP_SELF?L\$id\");\n"); +print(" html_link(\"Modify $tname #\$id\", \"\$PHP_SELF?M\$id\");\n"); +print(" html_endlinks();\n"); +print("\n"); +print(" print(\"
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); + +print(" if (!\$row['is_published'])\n"); +print(" print(\"\\n\");\n"); +print("\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) +{ + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + $name = ucwords(str_replace('_', ' ', $row['name'])); + + print(" \$temp = htmlspecialchars(\$row[\"$row[name]\"]);\n"); + print(" print(\"" + ."\\n\");\n"); + print("\n"); + break; + } +} + +print(" print(\"\\n\");\n"); +print(" print(\"
This $tname is \"\n"); +print(" .\"currently hidden from public view.
$name:\$temp
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); +print(" html_footer();\n"); +print(" }\n"); +print(" break;\n"); +print("\n"); +print(" case 'L' : // List (all) $tname(s)\n"); +print(" if (\$id)\n"); +print(" {\n"); +print(" html_header(\"$tname #\$id\");\n"); +print("\n"); +print(" \$result = db_query(\"SELECT * FROM $table WHERE id = \$id\");\n"); +print(" if (db_count(\$result) != 1)\n"); +print(" {\n"); +print(" print(\"

Error: $tname #\$id was not found!

\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" \$row = db_next(\$result);\n"); +print("\n"); +print(" html_startlinks(1);\n"); +print(" html_link(\"Return to $tname List\", \"\$PHP_SELF?L\");\n"); +print(" html_link(\"Modify $tname\", \"\$PHP_SELF?M\$id\");\n"); +print(" html_link(\"Delete $tname #\$id\", \"\$PHP_SELF?D\$id\");\n"); +print(" html_endlinks();\n"); +print("\n"); +print(" print(\"

\\n\");\n"); +print("\n"); +print(" if (!\$row['is_published'])\n"); +print(" print(\"\\n\");\n"); +print("\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) +{ + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + $name = ucwords(str_replace('_', ' ', $row['name'])); + + print(" \$temp = htmlspecialchars(\$row['$row[name]']);\n"); + print(" print(\"" + ."\\n\");\n"); + print("\n"); + break; + } +} + +print(" print(\"
This $tname is \"\n"); +print(" .\"currently hidden from public view.
$name:\$temp

\\n\");\n"); +print(" mysql_free_result(\$result);\n"); +print(" }\n"); +print(" else\n"); +print(" {\n"); +print(" html_header(\"$tname List\");\n"); +print("\n"); +print(" html_startlinks(1);\n"); +print(" html_link(\"New $tname\", \"\$PHP_SELF?N\");\n"); +print(" html_endlinks();\n"); +print("\n"); +print(" \$result = db_query(\"SELECT * FROM $table\");\n"); +print(" \$count = db_count(\$result);\n"); +print("\n"); +print(" if (\$count == 0)\n"); +print(" {\n"); +print(" print(\"

No ${tname}s found.

\\n\");\n"); +print("\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" html_start_table(array("); + +sqlite_seek($result, 0); +$firsttime = 1; +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + $name = ucwords(str_replace('_', ' ', $row['name'])); + if ($firsttime) + { + print(",\"$name\""); + $firsttime = 0; + } + else + print(",\"$name\""); + break; + } + +print("));\n"); +print("\n"); +print(" while (\$row = db_next(\$result))\n"); +print(" {\n"); +print(" html_start_row();\n"); +print("\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + print(" \$temp = htmlspecialchars(\$row['$row[name]']);\n"); + print(" print(\"\"\n"); + print(" .\"\$temp\");\n"); + print("\n"); + break; + } + +print(" html_end_row();\n"); +print(" }\n"); +print("\n"); +print(" html_end_table();\n"); +print(" }\n"); +print("\n"); +print(" html_footer();\n"); +print(" break;\n"); +print("\n"); + +print(" case 'M' : // Modify $tname\n"); +print(" if (\$REQUEST_METHOD == \"POST\")\n"); +print(" {\n"); +print(" \$date = time();\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + break; + + default : + $form = strtoupper($row['name']); + + print(" \$$row[name] = db_escape(\$_POST[\"$form\"]);\n"); + break; + } + +print("\n"); +print(" db_query(\"UPDATE $table SET \"\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + break; + + default : + if ($row['type'] == "INTEGER") + print(" .\"$row[name] = \$$row[name], \"\n"); + else + print(" .\"$row[name] = '\$$row[name]', \"\n"); + break; + } + +print(" .\"modify_date = \$date, \"\n"); +print(" .\"modify_user = '\$LOGIN_USER' \"\n"); +print(" .\"WHERE id = \$id\");\n"); +print("\n"); +print(" header(\"Location: \$PHP_SELF?L\$id\");\n"); +print(" }\n"); +print(" else\n"); +print(" {\n"); +print(" html_header(\"$tname #\$id\");\n"); +print("\n"); +print(" html_startlinks(1);\n"); +print(" html_link(\"Return to $tname List\", \"\$PHP_SELF?L\");\n"); +print(" html_link(\"$tname #\$id\", \"\$PHP_SELF?L\$id\");\n"); +print(" html_endlinks();\n"); +print("\n"); +print(" \$result = db_query(\"SELECT * FROM $table WHERE id = \$id\");\n"); +print(" if (db_count(\$result) != 1)\n"); +print(" {\n"); +print(" print(\"

Error: $tname #\$id was not found!

\\n\");\n"); +print(" html_footer();\n"); +print(" exit();\n"); +print(" }\n"); +print("\n"); +print(" \$row = db_next(\$result);\n"); +print("\n"); +print(" print(\"
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); +print(" print(\"\\n\");\n"); +print("\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + $form = strtoupper($row['name']); + $name = ucwords(str_replace('_', ' ', $row['name'])); + print(" \$temp = htmlspecialchars(\$row['$row[name]'], ENT_QUOTES);\n"); + print(" print(\"\"\n"); + + if ($row['type'] == "TEXT") + { + print(" .\"\\n\");\n"); + } + else + { + print(" .\"\\n\");\n"); + } + + print("\n"); + break; + } + +print(" print(\"\\n\");\n"); +print(" print(\"
Published:\");\n"); +print(" select_is_published(\$row['is_published']);\n"); +print(" print(\"
$name:
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); +print(" html_footer();\n"); +print(" }\n"); +print(" break;\n"); +print("\n"); +print(" case 'N' : // Post new $tname\n"); +print(" if (\$REQUEST_METHOD == \"POST\")\n"); +print(" {\n"); +print(" \$date = time();\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + break; + + default : + $form = strtoupper($row['name']); + if ($row['type'] == "INTEGER") + print(" \$$row[name] = db_escape(\$_POST[\"$form\"]);\n"); + else + print(" \$$row[name] = db_escape(\$_POST[\"$form\"]);\n"); + break; + } + +print("\n"); +print(" db_query(\"INSERT INTO $table VALUES(0,\"\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + break; + + default : + if ($row['type'] == "INTEGER") + print(" .\"\$$row[name],\"\n"); + else + print(" .\"'\$$row[name]',\"\n"); + break; + } + +print(" .\"\$date,'\$LOGIN_USER',\$date,'\$LOGIN_USER')\");\n"); +print("\n"); +print(" \$id = db_insert_id();\n"); +print("\n"); +print(" header(\"Location: \$PHP_SELF?L\$id\");\n"); +print(" break;\n"); +print(" }\n"); +print("\n"); +print(" html_header(\"New $tname\");\n"); +print("\n"); +print(" html_startlinks(1);\n"); +print(" html_link(\"Return to $tname List\", \"\$PHP_SELF?L\");\n"); +print(" html_endlinks();\n"); +print("\n"); +print(" print(\"
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); +print(" print(\"\\n\");\n"); +print("\n"); + +sqlite_seek($result, 0); +while ($row = sqlite_fetch_array($result)) + switch ($row['name']) + { + case "id" : + case "create_date" : + case "create_user" : + case "modify_date" : + case "modify_user" : + case "is_published" : + break; + + default : + $form = strtoupper($row['name']); + $name = ucwords(str_replace('_', ' ', $row['name'])); + + print(" print(\"\"\n"); + + if ($row['type'] == "TEXT") + { + print(" .\"\\n\");\n"); + } + else + { + print(" .\"\\n\");\n"); + } + + print("\n"); + break; + } + +print(" print(\"\\n\");\n"); +print(" print(\"
Published:\");\n"); +print(" select_is_published();\n"); +print(" print(\"
$name:
\"\n"); +print(" .\"

\\n\");\n"); +print("\n"); +print(" html_footer();\n"); +print(" break;\n"); +print("}\n"); +print("\n"); +print("\n"); +print("//\n"); +print("// End of \"\$Id\$\".\n"); +print("//\n"); +print("?>\n"); + +?> diff --git a/www/phplib/html.php b/www/phplib/html.php index d235ea7..eb4371c 100644 --- a/www/phplib/html.php +++ b/www/phplib/html.php @@ -1,6 +1,6 @@    " ."[ Home | " + ."Articles | " ."Documentation | " ."Download | " ."FAQ | "