Index: trunk/core/admin_templates/tools/system_tools.tpl =================================================================== diff -u -N -r7855 -r7887 --- trunk/core/admin_templates/tools/system_tools.tpl (.../system_tools.tpl) (revision 7855) +++ trunk/core/admin_templates/tools/system_tools.tpl (.../system_tools.tpl) (revision 7887) @@ -4,14 +4,24 @@ + + "> : - ]" value="Go"> + ');" value="Go"> @@ -31,7 +41,7 @@ - + Index: trunk/core/kernel/globals.php =================================================================== diff -u -N -r7635 -r7887 --- trunk/core/kernel/globals.php (.../globals.php) (revision 7635) +++ trunk/core/kernel/globals.php (.../globals.php) (revision 7887) @@ -44,10 +44,10 @@ * @param Array $data * @param string $label */ - function print_pre($data, $label='') + function print_pre($data, $label='', $on_screen = false) { $is_debug = false; - if (class_exists('kApplication')) { + if (class_exists('kApplication') && !$on_screen) { $application =& kApplication::Instance(); $is_debug = $application->isDebugMode(); } Index: trunk/core/units/admin/admin_events_handler.php =================================================================== diff -u -N -r7855 -r7887 --- trunk/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 7855) +++ trunk/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 7887) @@ -33,6 +33,93 @@ } /** + * Generates sturcture for specified table + * + * @param kEvent $event + * @author Alex + */ + function OnGenerateTableStructure(&$event) + { + $types_hash = Array( + 'string' => 'varchar|text|mediumtext|longtext|date|datetime|time|timestamp|char|year|enum|set', + 'int' => 'smallint|mediumint|int|bigint|tinyint', + 'float' => 'float', + 'double' => 'double', + 'numeric' => 'decimal', + ); + + $table_name = $this->Application->GetVar('table_name'); + if (!$table_name) { + echo 'error: no table name specified'; + return ; + } + + if (!preg_match('/^'.preg_quote(TABLE_PREFIX, '/').'(.*)/', $table_name)) { + $table_name = TABLE_PREFIX.$table_name; + } + + $table_info = $this->Conn->Query('DESCRIBE '.$table_name); + + // 1. prepare config keys + $fields = Array(); + $float_types = Array ('float', 'double', 'numeric'); + foreach ($table_info as $field_info) { + $field_options = Array (); + + // 1. get php field type by mysql field type + foreach ($types_hash as $php_type => $db_types) { + if (preg_match('/'.$db_types.'/', $field_info['Type'])) { + $field_options['type'] = $php_type; + break; + } + } + + $default_value = $field_info['Default']; + if (in_array($php_type, $float_types)) { + // this is float number, add formatter + if (preg_match('/'.$db_types.'\([\d]+,([\d]+)\)/i', $field_info['Type'], $regs)) { + $field_options['formatter'] = 'kFormatter'; + $field_options['format'] = '%01.'.$regs[1].'f'; + $default_value = 0; + } + } + + if ($field_info['Null'] != 'YES') { + $field_options['not_null'] = 1; + } + + if ($field_info['Key'] == 'PRI') { + $default_value = 0; + $config['IDField'] = "'".$field_info['Field']."'"; + } + + $field_options['default'] = $default_value; + + // format config keys + $ret = ''; + foreach ($field_options as $key_name => $key_value) { + if (!preg_match('/^[-\d]+$/', $key_value)) { + // if not only digits are present, then treat as string + $key_value = "'".$key_value."'"; + } + + $ret .= "'".$key_name."' => ".$key_value.', '; + } + + $fields[ $field_info['Field'] ] = 'Array('.rtrim($ret,',').')'; + } + + $config['Fields'] = $fields; + + echo 'Close Window
'; + $ret = print_r($config, true); + $ret = preg_replace( Array('/\[(.*)\]/',"/(.*)\)/"), Array("'\\1'",'\\1),'), $ret); + print_pre($ret, '', true); + + $event->status = erSTOP; + } + + /** * Refreshes ThemeFiles & Theme tables by actual content on HDD * * @param kEvent $event