#!/usr/local/bin/php -q * Copyright 2001-2010 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * form_template.cli.php */ include_once dirname(__FILE__) . '/_config.inc.php'; // Test arguments. if (isset($_SERVER['argv'][2])) { // Second arg is db table. $db_tbl = $_SERVER['argv'][2]; } else { die(sprintf("Usage: %s site_directory db_table\n", basename($_SERVER['argv'][0]))); } // Get DB tables. $qid = $db->query("SHOW TABLES"); while (list($row) = mysql_fetch_row($qid)) { $tables[] = $row; } // Make sure requested table is in database. if (!in_array($db_tbl, $tables)) { die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables))); } // Get DB table column info. $qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl)); while ($row = mysql_fetch_row($qid)) { $cols[] = $row; } $exclude = array('added_by_user_id', 'added_datetime', 'hit_count', 'modified_datetime', 'modified_by_user_id'); $primary_key = '__///__'; $output = array(); // Loop through columns if (is_array($cols) && !empty($cols)) { foreach ($cols as $col) { // Human readable. $field = $col[0]; $title = ucfirst(str_replace('_', ' ', $field)); $type = preg_replace('/^(\w+).*$/', '\\1', $col[1]); if ('PRI' == $col[3]) { $primary_key = $field; } // Column types like this are usually single toggle checkboxes. if (preg_match("/enum\('true'\)/", $col[1])) { $type = 'toggle'; } if (in_array($field, $exclude) || $primary_key == $field) { // Don't add a field for this column. continue; } // Select menu from the column of a related database table. if (preg_match('/.*_id$/i', $field)) { $output[$field] = << [+] Edit E_O_F; continue; } // File upload. if (preg_match('/file|image/i', $field)) { $output[$field] = << <\x3fphp if ('' != \$upload->getFilenameGlob(getFormData('$primary_key') . '_*') && getFormData('op') == 'edit' || getFormData('op') == 'update') { \x3f>
<\x3fphp printf(_("The current file %2\\\$s will be deleted if a new file is selected for upload."), '/_db_files/__///__', \$upload->getFilenameGlob(getFormData('$primary_key') . '_*')) \x3f>
<\x3fphp } \x3f>
<\x3fphp printf(_("Allowed file types: %s."), join(', ', \$upload->getParam('valid_file_extensions'))) \x3f>
E_O_F; continue; } // Password field. if (preg_match('/pass/i', $field)) { $output[$field] = << E_O_F; continue; } switch ($type) { // Select menu (or radio buttons) case 'enum' : $output[$field] = << E_O_F; break; // Set checkboxes case 'set' : $output[$field] = << <\x3fphp printSetCheckboxes('$db_tbl', '$field', \$frm['$field'], 1) \x3f> E_O_F; break; // Single checkbox case 'toggle' : $output[$field] = << E_O_F; break; // Textarea small case 'text' : case 'tinyblob' : case 'blob' : $output[$field] = << E_O_F; break; // Textarea big case 'mediumtext' : case 'longtext' : case 'mediumblob' : case 'longblob' : $output[$field] = << E_O_F; break; // Number case 'tinyint' : case 'bit' : case 'bool' : case 'smallint' : case 'mediumint' : case 'int' : case 'integer' : case 'bigint' : case 'float' : case 'float' : case 'double' : case 'double' : case 'real' : case 'decimal' : case 'dec' : case 'numeric' : default : $output[$field] = << E_O_F; break; // Date case 'date' : case 'datetime' : case 'timestamp' : case 'time' : case 'year' : default : $output[$field] = << E_O_F; break; // Text case 'char' : case 'varchar' : case 'tinytext' : case 'tinyblob' : default : $output[$field] = << E_O_F; break; } } } else { die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not have any columns.\n"); } echo join("\n", $output); ?>