#!/usr/local/bin/php -q '; $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] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> ')"><\x3fphp echo _("Add <##>") \x3f> <\x3fphp if ('' != \$frm['<##>_id']) { \x3f> ')"><\x3fphp echo sprintf(_("Edit <##> %s"), \$frm['<##>']) \x3f> <\x3fphp } \x3f> E_O_F; continue; } // File upload. if (preg_match('/file|image/i', $field)) { $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> <\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(_("File to upload must have one of the following file-name extensions: %s."), join(', ', \$upload->getParam('valid_file_extensions'))) \x3f>
E_O_F; continue; } // Password field. if (preg_match('/pass/i', $field)) { $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; continue; } switch ($type) { // Select menu (or radio buttons) case 'enum' : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; break; // Set checkboxes case 'set' : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> <\x3fphp printSetCheckboxes('$db_tbl', '$field', \$frm['$field'], 1) \x3f> E_O_F; break; // Single checkbox case 'toggle' : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> /> E_O_F; break; // Textarea small case 'text' : case 'tinyblob' : case 'blob' : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; break; // Textarea big case 'mediumtext' : case 'longtext' : case 'mediumblob' : case 'longblob' : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> 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] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; break; // Date case 'date' : case 'datetime' : case 'timestamp' : case 'time' : case 'year' : default : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; break; // Text case 'char' : case 'varchar' : case 'tinytext' : case 'tinyblob' : default : $output[$field] = <<err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f> E_O_F; break; } } } else { die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not have any columns.\n"); } echo join("\n", $output); ?>