root / src / phpMyEditSetup.php @ master
Historique | Voir | Annoter | Télécharger (20,3 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
/*
|
4 |
* phpMyEdit - instant MySQL table editor and code generator
|
5 |
*
|
6 |
* phpMyEditSetup.php - interactive table configuration utility (setup)
|
7 |
* ____________________________________________________________
|
8 |
*
|
9 |
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net>
|
10 |
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net>
|
11 |
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net>
|
12 |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/
|
13 |
* All rights reserved.
|
14 |
*
|
15 |
* See README file for more information about this software.
|
16 |
* See COPYING file for license information.
|
17 |
*
|
18 |
* Download the latest version from
|
19 |
* http://platon.sk/projects/phpMyEdit/
|
20 |
*/
|
21 |
|
22 |
/* $Platon: phpMyEdit/phpMyEditSetup.php,v 1.50 2007-09-16 12:57:07 nepto Exp $ */
|
23 |
|
24 |
?>
|
25 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
26 |
"http://www.w3.org/TR/html4/loose.dtd">
|
27 |
<html>
|
28 |
<head>
|
29 |
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
30 |
<title>phpMyEdit Setup</title> |
31 |
<style type="text/css"> |
32 |
<!--
|
33 |
body { font-family: "Verdana", "Arial", "Sans-Serif"; text-align: left }
|
34 |
h1 { color: #004d9c; font-size: 13pt; font-weight: bold }
|
35 |
h2 { color: #004d9c; font-size: 11pt; font-weight: bold }
|
36 |
h3 { color: #004d9c; font-size: 11pt; }
|
37 |
p { color: #004d9c; font-size: 9pt; }
|
38 |
table { border: 1px solid #004d9c; border-collapse: collapse; border-spacing: 0px; }
|
39 |
td { border: 1px solid; padding: 3px; color: #004d9c; font-size: 9pt; }
|
40 |
hr
|
41 |
{
|
42 |
height: 1px;
|
43 |
background-color: #000000;
|
44 |
color: #000000;
|
45 |
border: solid #000000 0;
|
46 |
padding: 0;
|
47 |
margin: 0;
|
48 |
border-top-width: 1px;
|
49 |
}
|
50 |
-->
|
51 |
</style>
|
52 |
</head>
|
53 |
<body bgcolor="white"> |
54 |
|
55 |
<?php
|
56 |
|
57 |
if (! defined('PHP_EOL')) { |
58 |
define('PHP_EOL', strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? "\r\n" |
59 |
: strtoupper(substr(PHP_OS, 0, 3) == 'MAC') ? "\r" : "\n"); |
60 |
} |
61 |
|
62 |
$hn = @$_POST['hn']; |
63 |
$un = @$_POST['un']; |
64 |
$pw = @$_POST['pw']; |
65 |
if(strlen($_POST['db'])>0) $db = @$_POST['db']; |
66 |
if(strlen($_POST['tb'])>0) $tb = @$_POST['tb']; |
67 |
$id = @$_POST['id']; |
68 |
$submit = @$_POST['submit']; |
69 |
$options = @$_POST['options']; |
70 |
$baseFilename = @$_POST['baseFilename']; |
71 |
$pageTitle = @$_POST['pageTitle']; |
72 |
$pageHeader = @$_POST['pageHeader']; |
73 |
$HTMLissues = @$_POST['HTMLissues']; |
74 |
$CSSstylesheet = @$_POST['CSSstylesheet']; |
75 |
|
76 |
$phpExtension = '.php'; |
77 |
if (isset($baseFilename) && $baseFilename != '') { |
78 |
$phpFile = $baseFilename.$phpExtension; |
79 |
//$contentFile = $baseFilename.'Content.inc';
|
80 |
$contentFile = $baseFilename.'.php'; |
81 |
} elseif (isset($tb)) { |
82 |
$phpFile = $tb.$phpExtension; |
83 |
//$contentFile = $tb.'Content.inc';
|
84 |
$contentFile = $tb.'.php'; |
85 |
} else {
|
86 |
$phpFile = 'index'.$phpExtension; |
87 |
//$contentFile = 'Content.inc';
|
88 |
$contentFile = 'phpMyEdit-content.php'; |
89 |
} |
90 |
|
91 |
$buffer = ''; |
92 |
|
93 |
function echo_html($x) |
94 |
{ |
95 |
echo htmlspecialchars($x),PHP_EOL; |
96 |
} |
97 |
|
98 |
function echo_buffer($x) |
99 |
{ |
100 |
global $buffer; |
101 |
$buffer .= $x.PHP_EOL; |
102 |
} |
103 |
|
104 |
#:#####################################:#
|
105 |
#:# Function: check_constraints #:#
|
106 |
#:# Parameters: tb=table name #:#
|
107 |
#:# fd=field name #:#
|
108 |
#:# return: lookup default for #:#
|
109 |
#:# said constraint #:#
|
110 |
#:# or null if no #:#
|
111 |
#:# constraint is found. #:#
|
112 |
#:# Contributed by Wade Ryan, #:#
|
113 |
#:# 20060906 #:#
|
114 |
#:#####################################:#
|
115 |
function check_constraints($tb,$fd) |
116 |
{ |
117 |
$query = "show create table $tb"; |
118 |
$result = mysql_query($query); |
119 |
$tableDef = preg_split('/\n/',mysql_result($result,0,1)); |
120 |
|
121 |
$constraint_arg=""; |
122 |
while (list($key,$val) = each($tableDef)) { |
123 |
$words=preg_split("/[\s'`()]+/", $val); |
124 |
if ($words[1] == "CONSTRAINT" && $words[6]=="REFERENCES") { |
125 |
if ($words[5]==$fd) { |
126 |
$constraint_arg=" 'values' => array(\n". |
127 |
" 'table' => '$words[7]',\n".
|
128 |
" 'column' => '$words[8]'\n".
|
129 |
" ),\n";
|
130 |
} |
131 |
|
132 |
} |
133 |
} |
134 |
return $constraint_arg; |
135 |
} |
136 |
|
137 |
function get_versions() |
138 |
{ |
139 |
$ret_ar = array(); |
140 |
$dirname = dirname(__FILE__); |
141 |
foreach (array( |
142 |
'current' => __FILE__, |
143 |
'setup' => "$dirname/phpMyEditSetup.php", |
144 |
'core' => "$dirname/phpMyEdit.class.php", |
145 |
'version' => "$dirname/doc/VERSION") |
146 |
as $type => $file) { |
147 |
if (@file_exists($file) && @is_readable($file)) { |
148 |
if (($f = fopen($file, 'r')) == false) { |
149 |
continue;
|
150 |
} |
151 |
$str = trim(fread($f, 4096)); |
152 |
if (strpos($str, ' ') === false && strlen($str) < 10) { |
153 |
$ret_ar[$type] = $str; |
154 |
} else if (preg_match('|\$'.'Platon:\s+\S+,v\s+(\d+.\d+)\s+|', $str, $matches)) { |
155 |
$ret_ar[$type] = $matches[1]; |
156 |
} |
157 |
fclose($f); |
158 |
} |
159 |
} |
160 |
return $ret_ar; |
161 |
} |
162 |
|
163 |
|
164 |
$self = basename($_SERVER['PHP_SELF']); |
165 |
$dbl = @mysql_pconnect($hn, $un, $pw); |
166 |
|
167 |
if ((!$dbl) or empty($submit)) { |
168 |
echo '<h1>Please log in to your MySQL database</h1>'; |
169 |
if (!empty($submit)) { |
170 |
echo '<h2>Sorry - login failed - please try again</h2>'.PHP_EOL; |
171 |
} |
172 |
if (! isset($hn)) { |
173 |
$hn = 'localhost'; |
174 |
} |
175 |
echo ' |
176 |
<form action="'.htmlspecialchars($self).'" method="POST"> |
177 |
<table border="1" cellpadding="1" cellspacing="0" summary="Login form">
|
178 |
<tr>
|
179 |
<td>Hostname:</td>
|
180 |
<td><input type="text" name="hn" value="'.htmlspecialchars($hn).'"></td> |
181 |
</tr><tr>
|
182 |
<td>Username:</td>
|
183 |
<td><input type="text" name="un" value="'.htmlspecialchars($un).'"></td> |
184 |
</tr><tr>
|
185 |
<td>Password:</td>
|
186 |
<td><input type="password" name="pw" value="'.htmlspecialchars($pw).'"></td> |
187 |
</tr><tr>
|
188 |
<td>Database:</td>
|
189 |
<td><input type="text" name="db" value="'.htmlspecialchars($db).'"></td> |
190 |
</tr><tr>
|
191 |
<td>Table:</td>
|
192 |
<td><input type="text" name="tb" value="'.htmlspecialchars($tb).'"></td> |
193 |
</tr>
|
194 |
</table><br>
|
195 |
<input type="submit" name="submit" value="Submit">
|
196 |
</form>'.PHP_EOL; |
197 |
} else if (! isset($db)) { |
198 |
$dbs = @mysql_list_dbs($dbl); |
199 |
$num_dbs = @mysql_num_rows($dbs); |
200 |
echo '<h1>Please select a database</h1> |
201 |
<form action="'.htmlspecialchars($self).'" method="POST"> |
202 |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
203 |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
204 |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
205 |
<table border="1" cellpadding="1" cellspacing="1" summary="Database selection">'.PHP_EOL; |
206 |
for ($i = 0; $i < $num_dbs; $i++) { |
207 |
$db = @mysql_db_name($dbs, $i); |
208 |
$checked = ! strcasecmp($un, $db) ? ' checked' : ''; |
209 |
$db = htmlspecialchars($db); |
210 |
echo '<tr><td><input'.$checked.' type="radio" name="db" value="'.$db.'"></td><td>'.$db.'</td></tr>'.PHP_EOL; |
211 |
} |
212 |
echo '</table><br> |
213 |
<input type="submit" name="submit" value="Submit">
|
214 |
<input type="submit" name="cancel" value="Cancel">
|
215 |
</form>'.PHP_EOL; |
216 |
} else if (!isset($tb)) { |
217 |
echo '<h1>Please select a table from database: '.htmlspecialchars($db).'</h1> |
218 |
<form action="'.htmlspecialchars($self).'" method="POST"> |
219 |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
220 |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
221 |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
222 |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
223 |
<table border="1" cellpadding="1" cellspacing="1" summary="Table selection">'.PHP_EOL; |
224 |
$tbs = @mysql_list_tables($db, $dbl); |
225 |
$num_tbs = @mysql_num_rows($tbs); |
226 |
for ($j = 0; $j < $num_tbs; $j++) { |
227 |
$tb = @mysql_tablename($tbs, $j); |
228 |
$tb = htmlspecialchars($tb); |
229 |
$checked = $j == 0 ? ' checked' : ''; |
230 |
echo '<tr><td><input'.$checked.' type="radio" name="tb" value="'.$tb.'"></td><td>'.$tb.'</td></tr>'.PHP_EOL; |
231 |
} |
232 |
echo '</table><br> |
233 |
<input type="submit" name="submit" value="Submit">
|
234 |
<input type="submit" name="cancel" value="Cancel">
|
235 |
</form>'.PHP_EOL; |
236 |
} else if (!isset($id)) { |
237 |
echo ' <h1>Please select an identifier from table: '.htmlspecialchars($tb).'</h1> |
238 |
<p>
|
239 |
This field will be used in change, view, copy and delete operations.<br>
|
240 |
The field should be numeric and must uniquely identify a record.
|
241 |
</p>
|
242 |
<p>
|
243 |
Please note, that there were problems reported by phpMyEdit users
|
244 |
regarding using MySQL reserved word as unique key name (the example for
|
245 |
this is "key" name). Thus we recommend you to use another name
|
246 |
of unique key. Usage of "id" or "ID" should be safe and good idea.
|
247 |
</p>
|
248 |
<form action="'.htmlspecialchars($self).'" method="POST"> |
249 |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
250 |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
251 |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
252 |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
253 |
<input type="hidden" name="tb" value="'.htmlspecialchars($tb).'"> |
254 |
<table border="1" cellpadding="1" cellspacing="1" summary="Key selection">'.PHP_EOL; |
255 |
// <tr><td><input type="radio" name="id" value="">
|
256 |
// <td><i>None</i></td><td><i>No id field required</i></td></tr>
|
257 |
@mysql_select_db($db); |
258 |
$tb_desc = @mysql_query("DESCRIBE $tb"); |
259 |
$fds = @mysql_list_fields($db,$tb,$dbl); |
260 |
for ($j = 0; ($fd = @mysql_field_name($fds, $j)) != false; $j++) { |
261 |
$ff = @mysql_field_flags($fds, $j); |
262 |
strlen($ff) <= 0 && $ff = '---'; |
263 |
$checked = stristr($ff, 'primary_key') ? ' checked' : ''; |
264 |
echo '<tr><td><input',$checked,' type="radio" name="id" value="',htmlspecialchars($fd),'"></td>'; |
265 |
echo '<td>',htmlspecialchars($fd),'</td>'; |
266 |
echo '<td>',htmlspecialchars($ff),'</td>'; |
267 |
$r = @mysql_fetch_array($tb_desc, $j); |
268 |
} |
269 |
echo '</table><br> |
270 |
<input type="submit" name="submit" value="Submit">
|
271 |
<input type="submit" name="cancel" value="Cancel">
|
272 |
</form>'.PHP_EOL; |
273 |
|
274 |
} else if (!isset($options)) { |
275 |
echo '<h1>Please select additional options</h1> |
276 |
<form action="'.htmlspecialchars($self).'" method="POST"> |
277 |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
278 |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
279 |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
280 |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
281 |
<input type="hidden" name="tb" value="'.htmlspecialchars($tb).'"> |
282 |
<input type="hidden" name="id" value="'.htmlspecialchars($id).'"> |
283 |
<table border="1" cellpadding="1" cellspacing="1" summary="Additional options">
|
284 |
<tr><td>Base filename</td><td><input type="text" name=baseFilename value ="'.htmlspecialchars($tb).'"></td></tr> |
285 |
<tr><td>Page title</td><td><input type="text" name=pageTitle value ="'.htmlspecialchars($tb).'"></td></tr> |
286 |
<tr><td>Page header</td><td><input type="checkbox" name=pageHeader></td></tr>
|
287 |
<tr><td>HTML header & footer</td><td><input type="checkbox" name=HTMLissues></td></tr>
|
288 |
<tr><td>CSS basic stylesheet</td><td><input checked type="checkbox" name=CSSstylesheet></td></tr>
|
289 |
</table><br>
|
290 |
<input type="submit" name="submit" value="Submit">
|
291 |
<input type="submit" name="cancel" value="Cancel">
|
292 |
<input type="hidden" name="options" value="1">
|
293 |
</form>'.PHP_EOL; |
294 |
} else {
|
295 |
echo '<h1>Here is your phpMyEdit calling program</h1>'.PHP_EOL; |
296 |
echo '<h2>You may now copy and paste it into your PHP editor</h2>'.PHP_EOL; |
297 |
if ($pageHeader) { |
298 |
echo_buffer('<h3>'.$pageTitle.'</h3>'); |
299 |
} |
300 |
$versions = ''; |
301 |
$versions_ar = get_versions();
|
302 |
foreach (array( |
303 |
'version' => 'phpMyEdit version:', |
304 |
'core' => 'phpMyEdit.class.php core class:', |
305 |
'setup' => 'phpMyEditSetup.php script:', |
306 |
'current' => 'generating setup script:') |
307 |
as $type => $desc) { |
308 |
$version = isset($versions_ar[$type]) ? $versions_ar[$type] : 'unknown'; |
309 |
$versions .= sprintf("\n * %36s %s", $desc, $version); |
310 |
} |
311 |
echo_buffer("<?php
|
312 |
|
313 |
/*
|
314 |
* IMPORTANT NOTE: This generated file contains only a subset of huge amount
|
315 |
* of options that can be used with phpMyEdit. To get information about all
|
316 |
* features offered by phpMyEdit, check official documentation. It is available
|
317 |
* online and also for download on phpMyEdit project management page:
|
318 |
*
|
319 |
* http://platon.sk/projects/main_page.php?project_id=5
|
320 |
*
|
321 |
* This file was generated by:
|
322 |
*$versions
|
323 |
*/
|
324 |
|
325 |
// MySQL host name, user name, password, database, and table
|
326 |
\$opts['hn'] = '$hn';
|
327 |
\$opts['un'] = '$un';
|
328 |
\$opts['pw'] = '$pw';
|
329 |
\$opts['db'] = '$db';
|
330 |
\$opts['tb'] = '$tb';
|
331 |
|
332 |
// Name of field which is the unique key
|
333 |
\$opts['key'] = '$id';
|
334 |
|
335 |
// Type of key field (int/real/string/date etc.)");
|
336 |
|
337 |
if ($id == '') { |
338 |
echo_buffer("\$opts['key_type'] = '';");
|
339 |
} else {
|
340 |
$fds = @mysql_list_fields($db,$tb,$dbl); |
341 |
for ($j = 0; ($fd = @mysql_field_name($fds, $j)) != ''; $j++) { |
342 |
if ($fd == $id) { |
343 |
echo_buffer("\$opts['key_type'] = '".@mysql_field_type($fds, $j)."';"); |
344 |
break;
|
345 |
} |
346 |
} |
347 |
} |
348 |
echo_buffer("
|
349 |
// Sorting field(s)
|
350 |
\$opts['sort_field'] = array('$id');
|
351 |
|
352 |
// Number of records to display on the screen
|
353 |
// Value of -1 lists all records in a table
|
354 |
\$opts['inc'] = 15;
|
355 |
|
356 |
// Options you wish to give the users
|
357 |
// A - add, C - change, P - copy, V - view, D - delete,
|
358 |
// F - filter, I - initial sort suppressed
|
359 |
\$opts['options'] = 'ACPVDF';
|
360 |
|
361 |
// Number of lines to display on multiple selection filters
|
362 |
\$opts['multiple'] = '4';
|
363 |
|
364 |
// Navigation style: B - buttons (default), T - text links, G - graphic links
|
365 |
// Buttons position: U - up, D - down (default)
|
366 |
\$opts['navigation'] = 'DB';
|
367 |
|
368 |
// Display special page elements
|
369 |
\$opts['display'] = array(
|
370 |
'form' => true,
|
371 |
'query' => true,
|
372 |
'sort' => true,
|
373 |
'time' => true,
|
374 |
'tabs' => true
|
375 |
);
|
376 |
|
377 |
// Set default prefixes for variables
|
378 |
\$opts['js']['prefix'] = 'PME_js_';
|
379 |
\$opts['dhtml']['prefix'] = 'PME_dhtml_';
|
380 |
\$opts['cgi']['prefix']['operation'] = 'PME_op_';
|
381 |
\$opts['cgi']['prefix']['sys'] = 'PME_sys_';
|
382 |
\$opts['cgi']['prefix']['data'] = 'PME_data_';
|
383 |
|
384 |
/* Get the user's default language and use it if possible or you can
|
385 |
specify particular one you want to use. Refer to official documentation
|
386 |
for list of available languages. */
|
387 |
\$opts['language'] = \$_SERVER['HTTP_ACCEPT_LANGUAGE'] . '-UTF8';
|
388 |
|
389 |
/* Table-level filter capability. If set, it is included in the WHERE clause
|
390 |
of any generated SELECT statement in SQL query. This gives you ability to
|
391 |
work only with subset of data from table.
|
392 |
|
393 |
\$opts['filters'] = \"column1 like '%11%' AND column2<17\";
|
394 |
\$opts['filters'] = \"section_id = 9\";
|
395 |
\$opts['filters'] = \"PMEtable0.sessions_count > 200\";
|
396 |
*/
|
397 |
|
398 |
/* Field definitions
|
399 |
|
400 |
Fields will be displayed left to right on the screen in the order in which they
|
401 |
appear in generated list. Here are some most used field options documented.
|
402 |
|
403 |
['name'] is the title used for column headings, etc.;
|
404 |
['maxlen'] maximum length to display add/edit/search input boxes
|
405 |
['trimlen'] maximum length of string content to display in row listing
|
406 |
['width'] is an optional display width specification for the column
|
407 |
e.g. ['width'] = '100px';
|
408 |
['mask'] a string that is used by sprintf() to format field output
|
409 |
['sort'] true or false; means the users may sort the display on this column
|
410 |
['strip_tags'] true or false; whether to strip tags from content
|
411 |
['nowrap'] true or false; whether this field should get a NOWRAP
|
412 |
['select'] T - text, N - numeric, D - drop-down, M - multiple selection
|
413 |
['options'] optional parameter to control whether a field is displayed
|
414 |
L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view
|
415 |
Another flags are:
|
416 |
R - indicates that a field is read only
|
417 |
W - indicates that a field is a password field
|
418 |
H - indicates that a field is to be hidden and marked as hidden
|
419 |
['URL'] is used to make a field 'clickable' in the display
|
420 |
e.g.: 'mailto:\$value', 'http://\$value' or '\$page?stuff';
|
421 |
['URLtarget'] HTML target link specification (for example: _blank)
|
422 |
['textarea']['rows'] and/or ['textarea']['cols']
|
423 |
specifies a textarea is to be used to give multi-line input
|
424 |
e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10
|
425 |
['values'] restricts user input to the specified constants,
|
426 |
e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99)
|
427 |
['values']['table'] and ['values']['column'] restricts user input
|
428 |
to the values found in the specified column of another table
|
429 |
['values']['description'] = 'desc_column'
|
430 |
The optional ['values']['description'] field allows the value(s) displayed
|
431 |
to the user to be different to those in the ['values']['column'] field.
|
432 |
This is useful for giving more meaning to column values. Multiple
|
433 |
descriptions fields are also possible. Check documentation for this.
|
434 |
*/
|
435 |
");
|
436 |
|
437 |
@mysql_select_db($db); |
438 |
$tb_desc = @mysql_query("DESCRIBE $tb"); |
439 |
$fds = @mysql_list_fields($db, $tb, $dbl); |
440 |
$num_fds = @mysql_num_fields($fds); |
441 |
$ts_cnt = 0; |
442 |
for ($k = 0; $k < $num_fds; $k++) { |
443 |
$fd = mysql_field_name($fds,$k); |
444 |
$fm = mysql_fetch_field($fds,$k); |
445 |
$fn = strtr($fd, '_-.', ' '); |
446 |
$fn = preg_replace('/(^| +)id( +|$)/', '\\1ID\\2', $fn); // uppercase IDs |
447 |
$fn = ucfirst($fn); |
448 |
$row = @mysql_fetch_array($tb_desc); |
449 |
echo_buffer('$opts[\'fdd\'][\''.$fd.'\'] = array('); // ) |
450 |
echo_buffer(" 'name' => '".str_replace('\'','\\\'',$fn)."',"); |
451 |
$auto_increment = strstr($row[5], 'auto_increment') ? 1 : 0; |
452 |
if (substr($row[1],0,3) == 'set') { |
453 |
echo_buffer(" 'select' => 'M',");
|
454 |
} else {
|
455 |
echo_buffer(" 'select' => 'T',");
|
456 |
} |
457 |
if ($auto_increment) { |
458 |
echo_buffer(" 'options' => 'AVCPDR', // auto increment");
|
459 |
} |
460 |
// timestamps are read-only
|
461 |
else if (@mysql_field_type($fds, $k) == 'timestamp') { |
462 |
if ($ts_cnt > 0) { |
463 |
echo_buffer(" 'options' => 'AVCPD',");
|
464 |
} else { // first timestamp |
465 |
echo_buffer(" 'options' => 'AVCPDR', // updated automatically (MySQL feature)");
|
466 |
} |
467 |
$ts_cnt++;
|
468 |
} |
469 |
echo_buffer(" 'maxlen' => ".@mysql_field_len($fds,$k).','); |
470 |
// blobs -> textarea
|
471 |
if (@mysql_field_type($fds,$k) == 'blob') { |
472 |
echo_buffer(" 'textarea' => array(");
|
473 |
echo_buffer(" 'rows' => 5,");
|
474 |
echo_buffer(" 'cols' => 50),");
|
475 |
} |
476 |
// SETs and ENUMs get special treatment
|
477 |
if ((substr($row[1],0,3) == 'set' || substr($row[1],0,4) == 'enum') |
478 |
&& ! (($pos = strpos($row[1], '(')) === false)) { |
479 |
$indent = str_repeat(' ', 18); |
480 |
$outstr = substr($row[1], $pos + 2, -2); |
481 |
$outstr = explode("','", $outstr); |
482 |
$outstr = str_replace("''", "'", $outstr); |
483 |
$outstr = str_replace('"', '\\"', $outstr); |
484 |
$outstr = implode('",'.PHP_EOL.$indent.'"', $outstr); |
485 |
echo_buffer(" 'values' => array(".PHP_EOL.$indent.'"'.$outstr.'"),'); |
486 |
} |
487 |
// automatic support for Default values
|
488 |
if ($row[4] != '' && $row[4] != 'NULL') { |
489 |
echo_buffer(" 'default' => '".$row[4]."',"); |
490 |
} else if ($auto_increment) { |
491 |
echo_buffer(" 'default' => '0',");
|
492 |
} |
493 |
// check for table constraints
|
494 |
$outstr = check_constraints($tb, $fd); |
495 |
if ($outstr != '') { |
496 |
echo_buffer($outstr);
|
497 |
} |
498 |
echo_buffer(" 'sort' => true");
|
499 |
//echo_buffer(" 'nowrap' => false,");
|
500 |
echo_buffer(');');
|
501 |
} |
502 |
|
503 |
echo_buffer("
|
504 |
// Now important call to phpMyEdit
|
505 |
require_once 'phpMyEdit.class.php';
|
506 |
new phpMyEdit(\$opts);
|
507 |
|
508 |
?>
|
509 |
");
|
510 |
|
511 |
$css_directive = <<<END |
512 |
<style type="text/css">
|
513 |
hr.pme-hr { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; }
|
514 |
table.pme-main { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
|
515 |
table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
|
516 |
td.pme-navigation-0, td.pme-navigation-1 { white-space: nowrap; }
|
517 |
th.pme-header { border: #004d9c 1px solid; padding: 4px; background: #add8e6; }
|
518 |
td.pme-key-0, td.pme-value-0, td.pme-help-0, td.pme-navigation-0, td.pme-cell-0,
|
519 |
td.pme-key-1, td.pme-value-1, td.pme-help-0, td.pme-navigation-1, td.pme-cell-1,
|
520 |
td.pme-sortinfo, td.pme-filter { border: #004d9c 1px solid; padding: 3px; }
|
521 |
td.pme-buttons { text-align: left; }
|
522 |
td.pme-message { text-align: center; }
|
523 |
td.pme-stats { text-align: right; }
|
524 |
</style>
|
525 |
END;
|
526 |
if (! $CSSstylesheet) { |
527 |
$css_directive = ''; |
528 |
} |
529 |
|
530 |
if ($HTMLissues) { |
531 |
$buffer = <<<END |
532 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
533 |
"http://www.w3.org/TR/html4/loose.dtd">
|
534 |
<html>
|
535 |
<head>
|
536 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
537 |
<title>$pageTitle</title>
|
538 |
$css_directive
|
539 |
</head>
|
540 |
<body>
|
541 |
$buffer
|
542 |
</body>
|
543 |
</html>
|
544 |
END;
|
545 |
} else if ($CSSstylesheet) { |
546 |
$buffer = $css_directive . $buffer; |
547 |
} |
548 |
// write the content include file
|
549 |
echo 'Trying to write content file to: <b>'.'./'.$contentFile.'</b><br>'.PHP_EOL; |
550 |
$filehandle = @fopen('./'.$contentFile, 'w+'); |
551 |
if ($filehandle) { |
552 |
fwrite($filehandle, $buffer); |
553 |
flush($filehandle); |
554 |
fclose($filehandle); |
555 |
echo 'phpMyEdit content file written successfully<br>'; |
556 |
} else {
|
557 |
echo 'phpMyEdit content file was NOT written due to inssufficient privileges.<br>'; |
558 |
echo 'Please copy and paste content listed below to <i>'.'./'.$contentFile.'</i> file.'; |
559 |
} |
560 |
echo '<br><hr>'; |
561 |
echo '<pre>'; |
562 |
echo_html($buffer);
|
563 |
echo '</pre><hr>'.PHP_EOL; |
564 |
} |
565 |
|
566 |
?>
|
567 |
|
568 |
</body>
|
569 |
</html>
|
570 |
|