#!/usr/bin/env php database. Please select one of: \n\n" . join("\n", $tables) . "\n\n"); } // Get DB table column info. $qid = dbQuery("DESCRIBE " . mysql_real_escape_string($db_tbl)); while ($row = mysql_fetch_row($qid)) { $cols[] = $row; } $exclude = array('added_by_admin_id', 'added_datetime', 'hit_count', 'modified_datetime', 'modified_by_admin_id'); $primary_key_field = ''; $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 = $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 == $field) { // Don't add a field for this column. continue; } if (preg_match('/file/i', $field)) { $output[$field] = << <\x3fphp if (getFormData('op') == 'edit') { \x3f>
<\x3fphp printf(_("The current file %s will be overwritten if a new file is selected for upload."), \$frm['$field']) \x3f>
<\x3fphp } \x3f>
<\x3fphp printf(_("File to upload must have one of the following file-name extensions: %s."), join(', ', \$upload->valid_file_extensions)) \x3f>
E_O_F; continue; } 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 case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : $output[$field] = << E_O_F; break; // Text 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' : case 'date' : case 'datetime' : case 'timestamp' : case 'time' : case 'year' : case 'char' : case 'varchar' : 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); ?>