-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
265 lines (238 loc) · 10.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
include("lib/Scaffold.php");
include("lib/stringParse.php");
include("scaffolds/codeigniter/ci_controller.php");
include("scaffolds/codeigniter/ci_css.php");
include("scaffolds/codeigniter/ci_footer.php");
include("scaffolds/codeigniter/ci_header.php");
include("scaffolds/codeigniter/ci_model.php");
include("scaffolds/codeigniter/ci_view.php");
include("scaffolds/codeigniter/ci_view_actions.php");
include("scaffolds/codeigniter/ci_view_browse.php");
include("scaffolds/codeigniter/ci_view_form.php");
$show_form = 0;
$message = '';
$new_layout_css = ''; // yes or ''
if( isset( $_POST['scaffold_info'])) {
$data = trim($_POST['sql']);
$data_lines = explode("\n", $data);
#echo $data."<br/>";
// strip all comments and get the first line
$first = true;
$firstline = '';
foreach ($data_lines AS $key => $value) {
$value = trim($value);
if ($value[0] == '-' && $value[1] == '-') unset($data_lines[$key]);
elseif (stripos($value, 'insert into')) unset($data_lines[$key]);
// find the first occurrence of "TABLE"
if($first && strpos($value, "TABLE")) {
$firstline = $value;
$first = false;
}
}
#echo "\$firstline = ".$firstline;
$table = array();
// store into cookie
foreach($_POST AS $key => $value) {
$date = time() + 999999;
if ($key == 'sql') $date = time() + 600;
setcookie($key, $value, $date, '/');
}
$table['include'] = stripslashes($_POST['include']);
#$table['id_key'] = trim($_POST['id_key']);
$table['scaffold_info'] = trim($_POST['scaffold_info']);
$table['website_name'] = trim($_POST['website_name']);
$table['project_name'] = trim($_POST['website_name']);
$table['table_prefix'] = trim($_POST['table_prefix']);
$table['author'] = trim($_POST['author']);
$table['company_name'] = trim($_POST['company_name']);
$table['company_url'] = trim($_POST['company_url']);
$new_layout_css = trim($_POST['new_layout_css']);
#echo '<h1>\$new_layout_css = '.$new_layout_css.'</h1>';
$_COOKIE = $_POST;
$tablename_regex = "CREATE\ +TABLE\ +(IF NOT EXISTS)?\ *(`.+`\.)?`([a-zA-Z0-9_]+)`\ \(";
// get first table name
if ( preg_match('/'.$tablename_regex.'/isU', $firstline, $matches) ) {
$table['name'] = str_replace($table['table_prefix'],'', $matches[3]);
echo $table['name'];
$max = count($data_lines);
for ($i = 1; $i < $max; $i++ ) {
if ( strpos( trim($data_lines[$i]), '`') === 0) { // this line has a column
$col = find_text(trim($data_lines[$i]));
$blob = ( stripos($data_lines[$i], 'TEXT') || stripos($data_lines[$i], 'BLOB') ) ? 1 : 0;
$datetime = ( stripos($data_lines[$i], 'DATETIME') ) ? 1 : 0;
$table[$col] =
array(
'blob' => $blob
, 'datetime' => $datetime
, 'attrib' => $data_lines[$i]
);
}
}
$table['table_clean'] = cleanText($table['name']);
$table['table_clean'] = cleanText($table['name']);
$table['className'] = str_replace(' ','_',cleanText($table['name']));
$table['tablePlural'] = $table['table_clean'];
// to get the table name's plural form
$lastchar = substr($table['table_clean'],strlen($table['table_clean'])-1,1);
if( $lastchar!='s') {
if( $lastchar=='x')
$table['tablePlural'] = substr($table['table_clean'],0,strlen($table['table_clean'])-1)."es";
elseif( $lastchar=='y')
$table['tablePlural'] = substr($table['table_clean'],0,strlen($table['table_clean'])-1)."ies";
else
$table['tablePlural'] = cleanText($table['name']).'s';
}
$show_form = 1;
//print_r($table);
} else
$message .= "Cannot find '".$tablename_regex."'";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js"></script>
<script type="text/javascript" src="js/s.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP MySQL CRUD CI Scaffold</title>
<meta name="Keywords" content="php, mysql, crud, scaffold" />
<meta name="Description" content="Fast PHP CRUD Scaffold Maker" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 href="javascript:void()" onclick="" style="cursor:hand;cursor:pointer;">php CI<span class="color">Scaffold</span></h1>
<div class="submenu">
<?php if ($show_form) { ?>
<a href="javascript:showNew();">Enter New Table</a> | <a href="javascript:showAll()">Show All</a> | <a href="javascript:hideAll()">Hide All</a>
<?php } else {?>
<?php } ?>
</div>
<div class="container">
<?php if ($message != '') echo "<div class=message>$message</div>"; ?>
<div <?php if ($show_form) echo 'style=display:none'; ?> id="new_table">
<form action="" method="post">
Welcome to <span class="style1">phpscaffold.com</span>, where you can quickly generate your CRUD scaffold pages for PHP and MySQL.
<br />
<br />
Enter your phpMyAdmin Table Export SQL Below to generate your pages. <a href="javascript:showHint('sql_hint');">[Hint]</a>
<br />
<br />
<div id="sql_hint" style="display:none; ">
<div style="background: #FFFFDD;padding: 5px; margin: 10px 0;">
Paste your phpMyAdmin export SQL queries for the table your which to generate list, edit, new, and delete
pages in the box below. A sample text maybe:
<pre style="color: #888; ">
--
-- Table structure for table `book`
--
CREATE TABLE IF NOT EXISTS `book`.`book` (
`id` INT NOT NULL AUTO_INCREMENT ,
`title_index` VARCHAR(127) NOT NULL COMMENT 'SEF title, to appear on URL (i.e. \'osashizu\', \'ofudesaki\', \'mikagura-uta\', \'kyosoden\')' ,
`title_jpn` VARCHAR(255) NOT NULL ,
`title_jpn_ro` VARCHAR(255) NOT NULL ,
`section_type` SET('chapter','volume','song','section','entry') NOT NULL ,
`status` VARCHAR(45) NULL COMMENT 'draft, published' ,
`description` TEXT NULL COMMENT 'should have descriptions in every language and describe the translated title.' ,
`created` DATETIME NOT NULL ,
`revised` DATETIME NOT NULL ,
`is_active` TINYINT(1) NOT NULL DEFAULT 1 ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `title_index_UNIQUE` (`title_index` ASC) )
ENGINE = InnoDB;
</pre>
</div>
</div>
<textarea name="sql" id="sql" cols="80" rows="10"
><?=((isset($_REQUEST['sql']))?stripslashes($_REQUEST['sql']):'')?></textarea>
<p>
Include File Name. You create this file. <a href="javascript:showHint('include_hint');">[Example]</a><br />
<input name="include" type="text" id="include" value="<?=((isset($_REQUEST['include']))?stripslashes($_REQUEST['include']):'config.php') ?>" />
</p>
<div id="include_hint" style="display:none; ">
<pre style="background:#FFFFDD;padding: 5px; margin: 10px 0; ">
// connect to db
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
if (! mysql_select_db('foo') ) {
die ('Can\'t use foo : ' . mysql_error());
}
</pre>
</div>
<a href="javascript:showHint('customization');">[Customization]</a>
<div id="customization" style="display:none; ">
<p>Website Name<br />
<input name="website_name" type="text" id="website_name"
value="<?=((isset($_REQUEST['website_name']))?stripslashes($_REQUEST['website_name']):'Website Name');?>"/>
</p>
<p>Table Prefix<br />
<input name="table_prefix" type="text" id="table_prefix"
value="<?=((isset($_REQUEST['table_prefix']))?stripslashes($_REQUEST['table_prefix']):"trmd_");?>"/>
</p>
<p>Author<br />
<input name="author" type="text" id="author"
value="<?=((isset($_REQUEST['author']))?stripslashes($_REQUEST['author']):"Author's Name");?>"/>
</p>
<p>Company Name<br />
<input name="company_name" type="text" id="company_name"
value="<?=((isset($_REQUEST['company_name']))?stripslashes($_REQUEST['company_name']):'');?>" />
</p>
<p>Company URL<br />
<input name="company_url" type="text" id="company_url"
value="<?=((isset($_REQUEST['company_url']))?stripslashes($_REQUEST['company_url']):'');?>" />
</p>
<p>
<input name="new_layout_css" type="checkbox" id="new_layout"
value="yes" <?=((isset($_REQUEST['new_layout_css']) && $new_layout_css=='yes')?'checked':'')?> />
Generate New Layout & CSS files <br/>
(views/layout_header.php, views/layout_footer.php & css/style.css)<br />
</p>
<input name="scaffold_info" type="hidden" value="1" />
</div>
<input type="submit" value="Make My Pages" />
</form>
</div>
<?php
function printSection($section='', $text) {
$secTitle = strtoupper(substr($section,0,1)).substr($section,1);
$str = '
<div class="options"><a href="javascript:toggle(\''.$section.'\');">Show/Hide</a>
| <a href="javascript:selectAll(\''.$section.'\');">Select All';
if (stripos($_SERVER["HTTP_USER_AGENT"], "msie") !== false)
$str .= " & Copy";
$str .= '</a> | <a href="download.php">Download All Files</a></div>
<h2>'.$secTitle.'</h2>
<textarea rows="30" cols="80" wrap="off" class="textarea" id="'.$section.'">'.
htmlspecialchars($text)
.'</textarea>';
return $str;
}
if ($show_form) {
$s = new Scaffold($table);
echo printSection('controller', ci_controller($table));
echo printSection('model', ci_model($table));
echo printSection('view', ci_view($table));
echo printSection('actions', ci_view_actions($table));
echo printSection('actionsnav', ci_view_browse($table));
echo printSection('form', ci_view_form($table));
#echo printSection('model', $s->ci_model());
#echo printSection('browse', $s->ci_view_browse());
#echo printSection('view', $s->ci_view());
#echo printSection('form', $s->ci_view_form());
#echo printSection('actionsnav', $s->ci_view_actions());
if($new_layout_css=='yes') {
echo printSection('footer', ci_footer($table));
echo printSection('header', ci_header($table));
echo printSection('css', ci_css($table));
}
}
?>
<br>
<br>
If you have any questions, contact me uprz23 < the at sign > gmail.com. Thanks for visiting.
</div>
</body>
</html>