* Copyright (c) 2001-2002 Jim Kraai * Versions 5.0 and higher developed by Ondrej Jombik * Copyright (c) 2002-2003 Platon SDG, http://www.platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://www.platon.sk/projects/phpMyEdit/ */ /* $Platon: phpMyEdit/phpMyEditSetup.php,v 1.16 2002/12/03 21:13:08 nepto Exp $ */ // setup.php version 3.5 27-Apr-01 // Heavily updated by Ondrej Jombik in 9-Aug-2002. ?> phpMyEdit Setup Please log in to your MySQL database'; if (!empty($submit)) {echo '

Sorry - login failed - please try again

'."\n";} echo '
Hostname:
Username:
Password:

'."\n"; } else { if (!isset($db)) { $dbs = mysql_list_dbs($dbl); $num_dbs = mysql_numrows($dbs); echo '

Please choose a database

'."\n"; for ($i=0; $i<$num_dbs; $i++) { $db = mysql_dbname($dbs, $i); if ($i==0) { echo ' '."\n"; } else { echo ' '."\n"; } } echo '
'.$db.'
'.$db.'

'."\n"; } else { if (!isset($tb)) { echo '

Please choose a table from database: '.$db.'

'."\n"; $tbs = mysql_list_tables($db,$dbl); $num_tbs = @mysql_num_rows($tbs); for ($j=0; $j<$num_tbs; $j++) { $tb = mysql_tablename($tbs, $j); if ($j == 0) { echo ' '."\n"; } else { echo ' '."\n"; } } echo '
'.$tb.'
'.$tb.'

'."\n"; } else { if (!isset($id)) { echo '

Please choose an identifier from table: '.$tb.'

This field will be used in Changes or Deletes.

It must be numeric and must uniquely identify a record.
If you haven\'t got a suitable field select None.

'."\n"; echo "describe $tb
\n"; mysql_select_db($db); $tb_desc = mysql_query("describe $tb"); $fds = mysql_list_fields($db,$tb,$dbl); $j = 0; while (1) { $fd = @mysql_field_name($fds, $j); if ($fd == "") { break; } $ff = mysql_field_flags($fds, $j); echo ' '; $r = mysql_fetch_array($tb_desc,$j); /* echo "\n"; echo "\n"; */ ++$j; } echo '
NoneNo id field required
'.$fd.''.$ff.'
";
print_r($r);
echo "

Page Title:
Base Filename:
'."\n"; } else { echo '

Here is your phpMyEdit calling program

'."\n"; echo '

You may now copy and paste it into your PHP editor

'."\n"; //echo '
'."\n";
        echo_buffer('

'.$pageTitle.'

true, 'sort' => true, 'time' => true ); // URLs - You can redefine URL for images to store images on different location // that phpMyEdit class file. \$opts['url'] = array( 'images' => 'images/' ); /* Field definitions. Fields will be displayed left to right on the screen in the order in which they appear in this list. ['name'] is the title used for column headings, etc.; ['sort'] = true means the users may sort the display on this column; ['type'] is generated by SETUP.php and indicates the mysql field type best not edited ['maxlen'] maximum length to display add/edit/search input boxes ['trimlen'] maximum length of string content to display in row listing if strlen(value) > trimlen, display substr($value,0,trimlen-3).'...' ['strip_tags'] true or false. whether to strip tags from content ['width'] is an optional display width specification for the column, e.g. ['width'] = '100px'; or \$fdd['colname']['width'] = (\$fdd['colname']['trimlen'] * 8).'px'; ['nowrap'] true or false. whether this field should get a NOWRAP ['mask'] a string that is used by sprintf() to format field output ['datemask'] a string that is used by date() to format date fields see PHP's date() for valid formatting characters ['daterange'] a of numbers ['daterange']['start'] = 1996; ['daterange']['end'] = \$fdd['colname']['daterange']['start']+20; ['URL'] is used to make a field 'clickable' in the display, e.g.: ['URL'] = 'mailto:\$value' or ['URL'] = 'http://\$value'; ['URL'] = '\$page?stuff'; Note that the following are available as variables: \$key key field for record \$name name of the field \$value value of the field \$page this HTML page \$urlstr all page variables \$row mysql_fetch_assoc() for this row ['URLtarget'] HTML target link specification (for example: _blank) ['URLdisp'] what to display as hypertext link (by default \$value) ['URLprefix'] old 3.5 ['URL'] behaviour, will prepend string before ['URLpostfix'] similary to ['URLprefix'] will append string after ['required'] = true will generate javascript to prevent null entries by users ['options'] is an optional parameter to control whether a field is displayed L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view Another flags can be: R - indicates that a field is read only W - indicates that a field is a password field H - indicates that a field is to be hidden and marked as hidden ['textarea']['rows'] and/or ['textarea']['cols'] specifies a textarea is to be used to give multi-line input, e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10 ['values'] restricts user input to the specified constants, e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99); ['values']['table'] and ['values']['column'] restricts user input to the values found in the specified column of another table. The optional ['values']['description'] field allows the value(s) displayed to the user to be different to those in the ['values']['column'] field. This is useful for giving more meaning to column values. There are two main options when using the ['values']['description'] field. These are whether you want to use a single, or multiple field in your description. To apply single, you need to use: ['values']['description'] = 'desc_column' This may be used, with no other options, and will simply display the description for the corresponding value. For Multiple, use: ['values']['description']['columns']['1'] = 'desc_column_1' ['values']['description']['divs']['1'] = ' ' ['values']['description']['columns']['2'] = 'desc_column_2' The 'div' component is what will be used as a divider between the columns in the display. You don't need to define the last 'div' field if it isn't required. So, for example...if you have a series of people in a table, with a separate column for id, first name, and last name, you could use: ['values']['db']='mydb' *optional if table is in another database* ['values']['table']='mytable' ['values']['column']='id' ['values']['description']['columns']['1']='name_last' ['values']['description']['divs']['1'] =', ' ['values']['description']['columns']['2']='name_first' ['values']['filters']='idcolumn in (1,2,3)' *optional WHERE clause* ['values']['orderby']='last_name' *optional ORDER BY clause* if a column is either SET or ENUM type, then the values are put in by PME Setup. ['select'] = 'T/D/M' (text, drop-down, or multiple selection for filters) if a column is a SET type, then this is automatically 'M' Calculated Expressions example: \$fdd['other']['name']='Col Header'; \$fdd['other']['expression']='onHand-ordered'; \$fdd['other']['sort']='T:!'; \$fdd['other']['select']='T'; \$fdd['other']['type']='int'; 'other' can be anything, but needs to be unique within the list of \$fdd keys 'expression' can be any valid MySQL expression 'type' should reflect the results of the expression, e.g. 'int' or 'string' all other options work as with other, normal columns this kind of column is always read-only Special note: Note, that you can create special options for particular \$fdd array elements, that depends on performed action. In example if you can change name of column in list and filter action, you can define \$fdd['column']['name|FL']. Others options works of course also well. */"); mysql_select_db($db); $tb_desc = mysql_query("describe $tb"); $fds = mysql_list_fields($db, $tb, $dbl); $num_fds = mysql_num_fields($fds); for ($k = 0; $k < $num_fds; $k++) { $fd = mysql_field_name($fds,$k); $fm = mysql_fetch_field($fds,$k); $fn = strtr($fd, "_-.", " "); $fn = preg_replace('/(^| +)id( +|$)/', '\\1ID\\2', $fn); // uppercase IDs $fn = ucfirst($fn); $row = mysql_fetch_array($tb_desc); echo_buffer('$opts[\'fdd\'][\''.$fd.'\'] = array('); echo_buffer(" 'name'=>'".str_replace('\'','\\\'',$fn)."',"); if (substr($row[1],0,3) == 'set') { echo_buffer(" 'select'=>'M',"); echo_buffer(" 'type'=>'set',"); } else { echo_buffer(" 'select'=>'T',"); echo_buffer(" 'type'=>'".mysql_field_type($fds,$k)."',"); } echo_buffer(" 'maxlen'=>".mysql_field_len($fds,$k).','); echo_buffer(" 'nowrap'=>false,"); if (stristr(mysql_field_flags($fds,$k),'not_null')) { echo_buffer(" 'required'=>true,"); } // blobs -> textarea if (mysql_field_type($fds,$k)=='blob') { echo_buffer(" 'textarea'=>array("); echo_buffer(" 'rows'=>5,"); echo_buffer(" 'cols'=>50,"); echo_buffer(" 'wrap'=>'virtual'"); echo_buffer(" ),"); } // timestamps are read-only if (mysql_field_type($fds,$k)=='timestamp') { echo_buffer(" 'options'=>'R',"); } // SETs and ENUMs get special treatment if (substr($row[1],0,3) == 'set') { echo_buffer(" 'values'=>array".substr($row[1],3).','); } if (substr($row[1],0,4) == 'enum') { echo_buffer(" 'values'=>array".substr($row[1],4).','); } // automatic support for Default values if ($row[4] != '' && $row[4] != 'NULL') { echo_buffer(" 'default'=>'".$row[4]."',"); } echo_buffer(" 'sort'=>true"); echo_buffer(');'); echo_buffer(''); } echo_buffer(" /* Table-level filter capability (if set, is included in the WHERE clause of any generated SELECT statement; this gives you ability to wirk only with subset of data from table) Some valid examples: \$opts['filters'] = \"column1 like '%11%' AND column2<17\"; \$opts['filters'] = \"section_id = 9\"; \$opts['filters'] = \"Table0.sessions_count > 200\"; */ /* CGI variables. You can optionally append or overwrite particular variables returned from CGI environment (GET/POST HTTP protocol data). Use these two arrays for this purpose, where array key mean CGI variable name and value means CGI variable value. Examples: // This will cause descending sorting according first field if other // type of sort was not specified/selected by user. \$opts['cgi']['append'] = array('sfn' => '-0'); // This will cause the same sort allways in all cases. \$opts['cgi']['overwrite'] = array('sfn' => '-0'); */ /* Triggers are files that are included (via require) that perform actions (before or after) X (inserts, updates, or deletes). 'before' triggers are usually used to verify conditions prior to executing the main operation. 'after' triggers are usually used to perform follow-on operations after the main operation. For example, to update secondary tables to enforce referential integrity or to update aggregate tables. The operation sequence is this: before, main, after. If any operation fails, not only should the next operation(s) not be executed, but the previous ones are 'rolled back' as if they never happened. If a database is not able to do this, it is not 'transaction-safe'. Triggers are risky in basic MySQL as there is no native transaction support--it is not transaction-safe by default. There are transaction-safe table types in MySQL that can be conditionally built (see MySQL-Max), but phpMyEdit is currently not set up to support real transactions. What that means is that if an operation fails, the database may be left in an intermediate and invalid state. The programmer must understand and accept these risks prior to using the phpMyEdit triggers mechanism. If the triggers are used, they execute within the namespace or scope of the phpMyEdit class. They _must_ return true or false to indicate success or failure. */ /* \$opts['triggers']['insert']['before']='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TIB.inc'; \$opts['triggers']['insert']['after'] ='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TIA.inc'; \$opts['triggers']['update']['before']='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TUB.inc'; \$opts['triggers']['update']['after'] ='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TUA.inc'; \$opts['triggers']['delete']['before']='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TDB.inc'; \$opts['triggers']['delete']['after'] ='".substr($contentFile,0,strrpos($contentFile,'.inc')).".TDA.inc'; */ /* Logtable schema CREATE TABLE changelog ( updated timestamp(14) NOT NULL, user varchar(50) default NULL, host varchar(255) NOT NULL default '', operation varchar(50) default NULL, tab varchar(50) default NULL, rowkey varchar(255) default NULL, col varchar(255) default NULL, oldval blob, newval blob ); \$opts['logtable']= 'changelog'; */ "); echo_buffer(" /* Get the user's default language and use it if possible or you can specify language particular one you want to use. Available languages are: DE EN-US EN FR IT NL PG SK SP */ \$opts['language'] = \$HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']; /* Code execution. Since version 4.0 phpMyEdit will automatically starts its execution. You can turn this feature off by setting \$opts['execute'] to 0. Default value is 1. */ // and now the all-important call to phpMyEdit // warning - beware of case-sensitive operating systems! require_once 'phpMyEdit.class.php'; \$MyForm = new phpMyEdit(\$opts); ?>
"); /* * Writting of two files makes only much more confusion on whole stuff. * Only real phpMyEdit content file is now written. Everybody can include * it from its own files to get the job (headers, footes, etc.). * * Nepto [29/7/2002] */ if (0) { // write the php file $phpFileContents = ''; echo 'Writing PHP file to: '.$destDir.'/'.$phpFile."
\n"; $filehandle = @fopen($destDir.'/'.$phpFile,'w+'); if ($filehandle) { fwrite($filehandle,$phpFileContents); flush($filehandle); fclose($filehandle); echo 'file written successfully
'; } echo '
PHP file:
';
	echo_html($phpFileContents);
	echo "

\n"; } // if (0) // write the content include file echo 'Trying to write content file to: '.$inclDir.'/'.$contentFile.'
'."\n"; $filehandle = @fopen($inclDir.'/'.$contentFile,'w+'); if ($filehandle) { fwrite($filehandle,$buffer); flush($filehandle); fclose($filehandle); echo 'phpMyEdit content file written successfully
'; } else { echo 'phpMyEdit content file was NOT written due to inssufficient privileges.
'; echo 'Please copy and paste content listed below to '.$inclDir.'/'.$contentFile.' file.'; } echo '

'; echo '

phpMyEdit content file follows

'."\n"; echo '
';
echo_html($buffer);
echo '

'."\n"; } } } } ?>