1 | #!/usr/local/bin/php -q |
---|
2 | <?php |
---|
3 | /** |
---|
4 | * form_template.cli.php |
---|
5 | * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information |
---|
6 | */ |
---|
7 | |
---|
8 | $CFG->enable_session = false; |
---|
9 | $CFG->log_screen_priority = LOG_DEBUG; |
---|
10 | error_reporting(E_ALL); |
---|
11 | require_once dirname(__FILE__) . '/../../config/boot.inc.php'; |
---|
12 | |
---|
13 | // Test arguments. |
---|
14 | if ($_SERVER['argc'] == 2) { |
---|
15 | $db_tbl = $_SERVER['argv'][1]; |
---|
16 | } else { |
---|
17 | die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n"); |
---|
18 | } |
---|
19 | |
---|
20 | // Get DB tables. |
---|
21 | $qid = dbQuery("SHOW TABLES"); |
---|
22 | while (list($row) = mysql_fetch_row($qid)) { |
---|
23 | $tables[] = $row; |
---|
24 | } |
---|
25 | |
---|
26 | // Make sure requested table is in database. |
---|
27 | if (!in_array($db_tbl, $tables)) { |
---|
28 | die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not exist in database $CFG->database. Please select one of: \n\n" . join("\n", $tables) . "\n\n"); |
---|
29 | } |
---|
30 | |
---|
31 | // Get DB table column info. |
---|
32 | $qid = dbQuery("DESCRIBE " . addslashes($db_tbl)); |
---|
33 | while ($row = mysql_fetch_row($qid)) { |
---|
34 | $cols[] = $row; |
---|
35 | } |
---|
36 | |
---|
37 | $exclude = array('added_by_admin_id', 'added_datetime', 'hit_count', 'modified_datetime', 'modified_by_admin_id'); |
---|
38 | $primary_key_field = ''; |
---|
39 | $output = array(); |
---|
40 | |
---|
41 | // Loop through columns |
---|
42 | if (is_array($cols) && !empty($cols)) { |
---|
43 | foreach ($cols as $col) { |
---|
44 | |
---|
45 | // Human readable. |
---|
46 | $field = $col[0]; |
---|
47 | $title = ucfirst(str_replace('_', ' ', $field)); |
---|
48 | $type = preg_replace('/^(\w+).*$/', '\\1', $col[1]); |
---|
49 | if ('PRI' == $col[3]) { |
---|
50 | $primary_key_field = $field; |
---|
51 | } |
---|
52 | |
---|
53 | // Column types like this are usually single toggle checkboxes. |
---|
54 | if (preg_match("/enum\('true'\)/", $col[1])) { |
---|
55 | $type = 'toggle'; |
---|
56 | } |
---|
57 | |
---|
58 | if (in_array($field, $exclude) || $primary_key_field == $field) { |
---|
59 | // Don't add a field for this column. |
---|
60 | continue; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | if (preg_match('/file/i', $field)) { |
---|
65 | $output[$field] = <<<E_O_F |
---|
66 | <tr> |
---|
67 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
68 | <td valign="top"> |
---|
69 | <input type="file" name="$field" value="<\x3fphp echo \$_FILES['$field']['name']; \x3f>" /> |
---|
70 | <\x3fphp if (getFormData('op') == 'edit') { \x3f> |
---|
71 | <div class="help"><\x3fphp printf(_("The current file <strong>%s</strong> will be overwritten if a new file is selected for upload."), \$frm['$field']) \x3f></div> |
---|
72 | <\x3fphp } \x3f> |
---|
73 | <div class="help"><\x3fphp printf(_("File to upload must have one of the following file-name extensions: %s."), join(', ', \$upload->valid_file_extensions)) \x3f></div> |
---|
74 | </td> |
---|
75 | </tr> |
---|
76 | E_O_F; |
---|
77 | continue; |
---|
78 | } |
---|
79 | |
---|
80 | if (preg_match('/pass/i', $field)) { |
---|
81 | $output[$field] = <<<E_O_F |
---|
82 | <tr> |
---|
83 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
84 | <td valign="top"> |
---|
85 | <input type="password" class="forminputtext" size="50" name="$field" value="<\x3fphp echo oTxt(\$frm['$field']); \x3f>"> |
---|
86 | </td> |
---|
87 | </tr> |
---|
88 | E_O_F; |
---|
89 | continue; |
---|
90 | } |
---|
91 | |
---|
92 | switch ($type) { |
---|
93 | |
---|
94 | // Select menu (or radio buttons) |
---|
95 | case 'enum' : |
---|
96 | $output[$field] = <<<E_O_F |
---|
97 | <tr> |
---|
98 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
99 | <td valign="top"> |
---|
100 | <select name="$field"> |
---|
101 | <\x3fphp printSetSelectForm('$db_tbl', '$field', \$frm['$field'], true); \x3f> |
---|
102 | </select> |
---|
103 | </td> |
---|
104 | </tr> |
---|
105 | E_O_F; |
---|
106 | break; |
---|
107 | |
---|
108 | // Set checkboxes |
---|
109 | case 'set' : |
---|
110 | $output[$field] = <<<E_O_F |
---|
111 | <tr> |
---|
112 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
113 | <td valign="top"> |
---|
114 | <\x3fphp printSetCheckboxes('$db_tbl', '$field', \$frm['$field'], 1) \x3f> |
---|
115 | </td> |
---|
116 | </tr> |
---|
117 | E_O_F; |
---|
118 | break; |
---|
119 | |
---|
120 | // Single checkbox |
---|
121 | case 'toggle' : |
---|
122 | $output[$field] = <<<E_O_F |
---|
123 | <tr> |
---|
124 | <td> </td> |
---|
125 | <td> |
---|
126 | <input type="checkbox" name="$field" <\x3fphp frmChecked(!empty(\$frm['$field'])) \x3f>><label><\x3fphp echo _("$title"); \x3f></label> |
---|
127 | </td> |
---|
128 | </tr> |
---|
129 | E_O_F; |
---|
130 | break; |
---|
131 | |
---|
132 | // Textarea |
---|
133 | case 'tinytext' : |
---|
134 | case 'text' : |
---|
135 | case 'mediumtext' : |
---|
136 | case 'longtext' : |
---|
137 | case 'tinyblob' : |
---|
138 | case 'blob' : |
---|
139 | case 'mediumblob' : |
---|
140 | case 'longblob' : |
---|
141 | $output[$field] = <<<E_O_F |
---|
142 | <tr> |
---|
143 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
144 | <td valign="top"> |
---|
145 | <textarea class="text" cols="75" rows="4" name="$field"><\x3fphp echo oTxt(\$frm['$field']); \x3f></textarea> |
---|
146 | </td> |
---|
147 | </tr> |
---|
148 | E_O_F; |
---|
149 | break; |
---|
150 | |
---|
151 | |
---|
152 | // Text |
---|
153 | case 'tinyint' : |
---|
154 | case 'bit' : |
---|
155 | case 'bool' : |
---|
156 | case 'smallint' : |
---|
157 | case 'mediumint' : |
---|
158 | case 'int' : |
---|
159 | case 'integer' : |
---|
160 | case 'bigint' : |
---|
161 | |
---|
162 | case 'float' : |
---|
163 | case 'float' : |
---|
164 | case 'double' : |
---|
165 | case 'double' : |
---|
166 | case 'real' : |
---|
167 | case 'decimal' : |
---|
168 | case 'dec' : |
---|
169 | case 'numeric' : |
---|
170 | |
---|
171 | case 'date' : |
---|
172 | case 'datetime' : |
---|
173 | case 'timestamp' : |
---|
174 | case 'time' : |
---|
175 | case 'year' : |
---|
176 | |
---|
177 | case 'char' : |
---|
178 | case 'varchar' : |
---|
179 | default : |
---|
180 | $output[$field] = <<<E_O_F |
---|
181 | <tr> |
---|
182 | <td class="right"><label for="$field"<\x3fphp \$fv->err('$field', ' class="error"') \x3f>><\x3fphp echo _("$title"); \x3f></label></td> |
---|
183 | <td valign="top"> |
---|
184 | <input type="text" class="text" size="50" name="$field" value="<\x3fphp echo oTxt(\$frm['$field']); \x3f>"> |
---|
185 | </td> |
---|
186 | </tr> |
---|
187 | E_O_F; |
---|
188 | break; |
---|
189 | } |
---|
190 | } |
---|
191 | } else { |
---|
192 | die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not have any columns.\n"); |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | echo join("\n", $output); |
---|
197 | |
---|
198 | ?> |
---|