source: branches/1.1dev/bin/module_maker/form_template.cli.php @ 648

Last change on this file since 648 was 648, checked in by anonymous, 6 years ago

Update hash-bang references. Minor.

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