"Fossies" - the Fresh Open Source Software Archive

Member "mysqlwdb-1.5.4/mysqlwdb.pl" (21 Dec 2005, 240142 Bytes) of package /linux/www/old/mysqlwdb-1.5.4.tar.gz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 #!/usr/bin/perl
    2 ####################################################################################
    3 #                               mysqlwdb Version 1.5.4
    4 #
    5 #    This is a CGI script written in Perl5, easy to configure and to install,
    6 #    intended to manage MySQL database tables through a web interface.
    7 #    Just edit and configure THIS UNIQUE file.
    8 #
    9 ####################################################################################
   10 ####################################################################################
   11 #
   12 #    Copyright (C) 2000,2005 Andrea Maestrutti aka Dree Mistrut in friulian language
   13 #    http://www.igsuite.org/cgi-bin/igwiki/mysqlwdb --- dree@igsuite.org
   14 #
   15 #    This program is free software; you can redistribute it and/or modify
   16 #    it under the terms of the GNU General Public License version 2 as
   17 #    published by the Free Software Foundation.
   18 #
   19 #    This program is distributed in the hope that it will be useful,
   20 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22 #    GNU General Public License for more details.
   23 #
   24 #    You should have received a copy of the GNU General Public License
   25 #    along with this program; if not, write to the Free Software
   26 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   27 #
   28 #    You may also find the license at http://www.gnu.org/copyleft/gpl.html
   29 #
   30 ####################################################################################
   31 
   32 #use strict;    # to avoid scope variables errors: useful for developers
   33 
   34 $|=1;       # to avoid output buffering
   35 close STDERR;   # to avoid DBI error output on html with some web servers
   36 
   37 #==================================================================================
   38 #
   39 #                       VARIABLE CONFIGURATION SECTION
   40 #
   41 #       PLEASE READ THE INSTALLATION DOCUMENT AND CHANGE UNDER THIS COMMENT THE
   42 #       VARIABLES YOU NEED, TO REFLECT TO YOUR PURPOSES
   43 #
   44 #==================================================================================
   45 
   46 #=========================================================
   47 #       Name of this CGI script
   48 #=========================================================
   49 my $thiscgi=               'mysqlwdb.pl';
   50 
   51 #=========================================================
   52 #       Database(s) & user(s) variables
   53 #=========================================================
   54 
   55 #
   56 #       It is possible to manage more than 1 database.
   57 #       If you put data for only 1 database, you will not prompt for databases choice.
   58 #       If you put data for more than 1 database, a menu of choice will appear.
   59 #
   60 
   61 my $custom_configuration=0; # 1 means YES, 0 means NO
   62 
   63 my %DATABASES=     (
   64 
   65         1 => {
   66 
   67             host        =>  " ! PUT HOST            HERE ! ",
   68                 port        =>  " ! PUT PORT            HERE ! ", # 3306 is the standard MySQL port
   69                 database    =>  " ! PUT DATABASE NAME   HERE ! ",
   70                 user        =>  " ! PUT USER            HERE ! ",
   71                 password    =>  " ! PUT PASSWORD        HERE ! ",
   72                 db_description  =>  " ! PUT DB_DESCRIPTION  HERE ! "
   73 
   74              },
   75 #
   76 #       Example for Database2.
   77 #
   78 #       If you need to manage a second database, please remove all # from 2 to },
   79 #       If you need to manage others databases, please copy & paste the example and change the order number
   80 #
   81 #
   82 #       2 => {
   83 #
   84 #              host            =>      "host for Database2",
   85 #              port            =>      "port for Database2, usually 3306",
   86 #              database        =>      "Database2",
   87 #              user            =>      "User for Database2",
   88 #              password        =>      "Password for Database2",
   89 #              db_description  =>      "Description for Database 2"
   90 #
   91 #            },
   92 
   93 );
   94 
   95 #=========================================================
   96 #       Login variables
   97 #=========================================================
   98 
   99 #       It is possible to prompt user for login.
  100 #
  101 #       If you WANT to manage user(s), please:
  102 #               a) remove the # before user(s) id and password that you need
  103 #               b) change the user(s) id and password according to your needs
  104 #               c) set $login_prompt variable to 1
  105 
  106 my %LOGIN=(
  107 
  108 #        "user1"         =>      "pwd1",
  109 #        "user2"         =>      "pwd2",
  110 
  111 );
  112 
  113 my $login_prompt=  0;              # 1 means YES, 0 means NO
  114 
  115 #=========================================================
  116 #       DBI driver variable
  117 #=========================================================
  118 my $DBI_driver=            'mysql';
  119 
  120 #=========================================================
  121 #       DBD::mysql version variables
  122 #=========================================================
  123 #
  124 # 1 means YES, 0 means NO
  125 
  126 my $recent_DBD_is_pri_key=  1;      # 'recent' means Msql-Mysql-modules version 1.21_07 or greater (1998-11-08)
  127                     # the default value is 1
  128 
  129 my $recent_DBD_dsn_syntax=      1;      # 'recent' means Msql-Mysql-modules version 1.19_03 or greater (1998-02-06)
  130                     # the default value is 1
  131 
  132 my $obsolete_DBD_ListTables=    1;      # 'obsolete' means Msql-Mysql-modules version prior to 1.21_07 (1998-11-08)
  133                     # (it is set to 1 as a precaution due to a problem of $dbh->tables() 
  134                     # with empty databases in old drivers).
  135                     # Set to 0 if you report problems (i.e. warnings) on your web server log
  136                     # the default value is 1
  137 
  138 my $ListDBs_data_sources=   1;      # the way to obtain the databases list via the initial login form
  139                     # 0 means that is used _ListDBs, 1 means that is used DBI->data_sources
  140                     # change to 0 and try again if you encounter problems
  141                     # the default value is 1
  142 
  143 #=========================================================
  144 #       MySQL specific variable
  145 #=========================================================
  146 my $mysql_specific=        1;      # 1 means YES, 0 means NO
  147 
  148 #=========================================================
  149 #       Delimiters
  150 #=========================================================
  151 my $delimiter=      '@@';
  152 my $pri_key_delimiter=  '##';
  153 
  154 #=========================================================
  155 #       backup filename
  156 #=========================================================
  157 my $backup_filename=        "backup.sql";
  158 
  159 #=========================================================
  160 #       backup filename
  161 #=========================================================
  162 my $csv_exp_filename=       "export.csv";
  163 
  164 
  165 #=========================================================
  166 #       Configurable actions
  167 #=========================================================
  168 
  169 #=======DBMS actions
  170 #
  171 # 1 means YES, 0 means NO
  172 
  173 my $drop_enabled=          1;      # to be able to drop table(s)
  174 my $drop_check=            1;      # to be prompted before drop table(s)
  175 my $erase_enabled=         1;      # to be able to erase table(s) data
  176 my $erase_check=           1;      # to be prompted before erase table(s) data
  177 my $delete_enabled=        1;      # to be able to delete field(s)
  178 my $db_backup_enabled=     1;      # to be able to backup a whole database
  179 my $db_csv_exp_enabled=    1;      # to be able to export to csv from a whole database
  180 my $table_backup_enabled=  1;      # to be able to backup table(s)
  181 my $table_csv_exp_enabled= 1;      # to be able to export to csv from table(s)
  182 my $prepare_create_enabled=1;      # to be able to define a new table
  183 my $create_enabled=        1;      # to be able to definitevely create a table
  184 my $create_check=          1;      # to be prompted before definitevely create a table
  185 my $delete_check=          1;      # to be prompted before delete field(s)
  186 my $select_enabled=        1;      # to be able to select field(s)
  187 my $edititem_enabled=      1;      # to be able to edit field(s) for update
  188 my $new_enabled=           1;      # to be able to edit fields for create new record(s)
  189 my $prepare_enabled=       1;      # to be able to prepare select on checked field(s)
  190 my $describe_enabled=      1;      # to be able to describe table(s)
  191 my $showindex_enabled=     1;      # to be able to show index from table(s)
  192 my $selectfields_enabled=  1;      # to be able to select checked field(s)
  193 my $insertrecord_enabled=  1;      # to be able to insert records(s)
  194 my $insertrecord_check=    1;      # to be prompted before insert record(s)
  195 my $updaterecord_enabled=  1;      # to be able to update field(s)
  196 my $updaterecord_check=    1;      # to be prompted before update table(s)
  197 my $fquery_enabled=    1;      # to be able to make free query
  198 my $fquery_check=      1;      # to be prompted before make free query
  199 my $refresh_enabled=       1;      # to be able to refresh table(s) list
  200 my $max_selected_rows=     500;    # to provide an overall limit to the number of ALL selected records
  201 
  202 #=======Warnings '0 rows affected' happened
  203 #
  204 # 1 means YES, 0 means NO
  205 
  206 my $wrng_enabled_4_crate=  0;      # to be warned if '0 rows affected' happened for create table action
  207 my $wrng_enabled_4_drop=   0;      # to be warned if '0 rows affected' happened for drop table action
  208 my $wrng_enabled_4_erase=  0;      # to be warned if '0 rows affected' happened for erase data table action
  209 my $wrng_enabled_4_delete= 1;      # to be warned if '0 rows affected' happened for delete action
  210 my $wrng_enabled_4_update= 1;      # to be warned if '0 rows affected' happened for update action
  211 my $wrng_enabled_4_insert= 1;      # to be warned if '0 rows affected' happened for insert action
  212 
  213 #======Upper box
  214 #
  215 # 1 means YES, 0 means NO
  216 
  217 my $upper_box_enabled=     1;      # 1 means that the upper box will appear
  218 
  219 #=======javascript check
  220 #
  221 # 1 means YES, 0 means NO
  222 
  223 my $javascript_enabled=    1;      # 1 means that javascript code will (0 means NOT) appear to check whether
  224                                    # tables/records/fields have been correctly checked or not
  225 
  226 #=======mysqlwdb link
  227 #
  228 # 1 means YES, 0 means NO
  229 
  230 my $display_mysqlwdb_link= 1;      # display mysqlwdb link at the bottom of the page
  231 
  232 
  233 #=======CSV separator
  234 #
  235 my $csv_separator_default= ',';    # the default character used to divide fields
  236 
  237 
  238 #=========================================================
  239 #       Create table specific
  240 #=========================================================
  241 
  242 #
  243 # NOTE: For configure types & specifiers please go to the end of this file
  244 #
  245 
  246 #=======create table specifiers order
  247 #
  248 # Specifiers order from left to right. Numbers are the positions.
  249 # It is possible to remove some specifiers (i.e. a line) but 'field_name' and 'field_type' are required.
  250 # Please do not change names, but only the numbers. See "create table specifiers messages" section to change names.
  251 
  252 my %SPECIFIERS_ORDER=      (
  253 
  254         "field_name"    =>      "1",
  255         "field_type"    =>      "2",
  256 
  257         "length"        =>      "3",
  258         "decimals"      =>      "4",
  259         "unsigned"      =>      "5",
  260         "zerofill"      =>      "6",
  261         "binary"        =>      "7",
  262         "not_null"      =>      "8",
  263         "default"       =>      "9",
  264         "auto_increment"=>      "10",
  265         "fulltext"  =>      "11",
  266         "index"     =>      "12",
  267         "unique"    =>      "13",
  268         "primary_key"   =>      "14"
  269 );
  270 
  271 #=======characters not allowed for create table names
  272 #
  273 # _SOME_ characters not allowed for table and fields names
  274 # This is for names check purpose. Space is already included.
  275 
  276 my @characters_not_allowed=qw(
  277 
  278         "
  279         '
  280         @
  281         .
  282         &
  283         %
  284         !
  285         ?
  286         /
  287         \
  288 );
  289 
  290 #=========================================================
  291 #       Messages
  292 #=========================================================
  293 #
  294 # NOTE: if you want to add a " in a message, please write it as \"
  295 
  296 #=======buttons & interface_messages
  297 
  298 my $button_discard=        "Discard";
  299 my $button_proceed=        "Proceed";
  300 my $button_drop=           "Drop table(s)";
  301 my $button_erase=          "Erase table(s) data";
  302 my $button_prepare_create= "Create table";
  303 my $button_create=         "Create";
  304 my $button_describe=       "Describe table(s)";
  305 my $button_showindex=      "Show index";
  306 my $button_refresh=        "Refresh table(s) list";
  307 my $button_db_backup=      "Database backup";
  308 my $button_db_csv_exp=     "Database CSV export";
  309 my $button_table_backup=   "Table(s) backup";
  310 my $button_table_csv_exp=  "Table(s) CSV export";
  311 my $lock_table_backup=     "With Lock table(s) instructions";
  312 my $drop_table_backup=     "With Drop table(s) instructions";
  313 my $button_edit=           "Edit record(s)";
  314 my $button_delete=         "Delete record(s)";
  315 my $button_update=         "Update record(s)";
  316 my $button_insert=         "Insert record(s)";
  317 my $button_new=            "New record(s)";
  318 my $button_prepare=        "Prepare select";
  319 my $button_select_all=     "Select all fields";
  320 my $button_select_chk=     "Select checked field(s)";
  321 my $button_js_check_tab=   "Check all table(s)";
  322 my $button_js_unchk_tab=   "Uncheck all table(s)";
  323 my $button_js_rvrse_tab=   "Reverse checked table(s)";
  324 my $button_js_check_fld=   "Check all field(s)";
  325 my $button_js_unchk_fld=   "Uncheck all field(s)";
  326 my $button_js_check_rec=   "Check all record(s)";
  327 my $button_js_unchk_rec=   "Uncheck all record(s)";
  328 my $button_db_choice=      "Go to";
  329 my $button_go_to_db_choice="Databases choice";
  330 my $button_fquery=     "Submit";
  331 my $databases_choice=      "Databases choice";
  332 my $user_login=            "User login";
  333 my $user_login_failed=     "User login failed";
  334 my $user_login_fail_prompt="Please check your id or password";
  335 my $button_user_login=     "Submit";
  336 my $button_user_logout=    "Logout";
  337 my $user_id=               "Id:";
  338 my $user_pwd=              "Pwd:";
  339 my $current_user_msg=      "";
  340 my $general_error=     "Error";
  341 
  342 my $server_login=             "Server login";
  343 my $button_server_login=      "Submit";
  344 my $server_login_fail_prompt= "Please check your login informations";
  345 my $server_login_host=        "Host:";
  346 my $server_login_port=        "Port:";
  347 my $server_login_port_default="3306";
  348 my $server_login_database=    "Database:";
  349 my $server_login_user=        "User:";
  350 my $server_login_pwd=         "Pwd:";
  351 
  352 my $number_of_fields=      "number of field(s)";
  353 my $query_limit=           "limit";
  354 my $query_offset=          "offset";
  355 my $query_where=           "where";
  356 my $query_and=             "and";
  357 my $query_from=        "from";
  358 my $query_order_by=        "order by";
  359 
  360 my $fquery_no_output=      "No output from free query";
  361 
  362 my $radio_db_backup_witht= "With table(s) structure";
  363 my $radio_db_backup_withot="Without table(s) structure";
  364 my $radio_db_backup_struct="Only table(s) structure";
  365 
  366 #=======operations
  367 
  368 my $operation_on_user=     "Current user";
  369 my $operation_on_dbs=      "Operation(s) on database(s)";
  370 my $operation_on_tables=   "Operation(s) on table(s)";
  371 my $operation_on_fields=   "Operation(s) on field(s)";
  372 my $operation_on_records=  "Operation(s) on record(s)";
  373 my $operations_on_query=   "Query(ies)";
  374 my $fquery=        "Free query";
  375 
  376 #=======questions
  377 
  378 my $ask_drop_tables=       "Do you really want to drop";
  379 my $ask_erase_tables=      "Do you really want to erase";
  380 my $ask_create_table=      "Do you really want to create table?";
  381 my $ask_delete_records=    "Do you really want to delete selected record(s)?";
  382 my $ask_insert_records=    "Do you really want to insert record(s)?";
  383 my $ask_update_records=    "Do you really want to update record(s)?";
  384 my $ask_fquery=        "Do you really want to submit the free query?";
  385 my $ask_backup_type=       "Choose backup type";
  386 my $ask_table_backup=      "Table(s)";
  387 my $ask_csv_separator=     "Choose CSV separator";
  388 
  389 #=======javascript alerts
  390 
  391 my $js_no_checked_tables=  "No checked table(s)";
  392 my $js_no_checked_fields=  "No checked field(s)";
  393 my $js_tab_check_wo_exist= "Table(s) checked without existing record(s) or field(s)";
  394 my $js_tab_check_wo_check= "Table(s) checked without checked record(s) or field(s)";
  395 my $js_tab_no_check_with=  "Table(s) no checked with checked record(s) or field(s)";
  396 my $js_no_field_name=      "No field name";
  397 my $js_no_table_name=      "No table name";
  398 my $js_in_table_name=      "in table name";
  399 my $js_in_field_name=      "in field name";
  400 my $js_ai_must_be_pkey=    "field must be a";
  401 my $js_pk_must_be_nn=      "must be";
  402 my $js_space_character=    "'space'";
  403 my $js_for_type=           "for type";
  404 my $js_field=              "field";
  405 my $js_not_allowed=        "is not allowed";
  406 my $js_required=           "is required";
  407 my $js_with=               "with";
  408 my $js_same_name_fields=   "Same name for fields";
  409 my $js_name_not_number=    "Name can not consist only of numbers";
  410 
  411 #=======DBMS operations messages
  412 
  413 my $ok_insert=             "Insert operation successfully completed";
  414 my $ko_insert=             "insert operation NOT completed";
  415 my $ok_create=             "Create operation successfully completed";
  416 my $ko_create=             "create operation NOT completed";
  417 my $ok_update=             "Update operation successfully completed";
  418 my $ko_update=             "update operation NOT completed";
  419 my $ok_delete=             "Delete record(s) operation successfully completed";
  420 my $ko_delete=             "delete record(s) operation NOT completed";
  421 my $ok_drop=               "Drop operation successfully completed";
  422 my $ko_drop=               "drop operation NOT completed";
  423 my $ok_erase=              "Erase operation successfully completed";
  424 my $ko_erase=              "erase operation NOT completed";
  425 my $ok_fquery=             "Free query successfully completed";
  426 my $ko_fquery=             "free query operation NOT completed";
  427 
  428 #=======create table specifiers messages
  429 #
  430 # It is possible to remove some specifiers (i.e. a line) but 'field_name' and 'field_type' are required.
  431 # Please do not change names on the left, but only messages on the right.
  432 # See "create table specifiers messages" section to change names on the left.
  433 
  434 my %SPECIFIERS_MESSAGES=        (
  435 
  436         "table_name"    =>      "Table name",
  437         "field_name"    =>      "Field name",
  438         "field_type"    =>      "Field type",
  439         "length"        =>      "Length",
  440         "decimals"      =>      "Decimals",
  441         "unsigned"      =>      "Unsigned",
  442         "zerofill"      =>      "Zerofill",
  443         "binary"        =>      "Binary",
  444         "not_null"      =>      "Not null",
  445         "default"       =>      "Default",
  446         "auto_increment"=>      "Auto increment",
  447         "fulltext"  =>      "Fulltext",
  448         "index"         =>      "Index",
  449         "unique"        =>      "Unique",
  450         "primary_key"   =>      "Primary key"
  451 );
  452 
  453 #=======interface errors and warnings
  454 
  455 my $err_error_word=        "ERROR";
  456 my $err_warning_word=      "WARNING";
  457 my $err_details_word=      "details";
  458 my $err_connect_db=        "Can not connect to the database";
  459 my $err_db_empty=          "Database empty";
  460 my $err_no_dbs=        "No database(s)";
  461 my $err_not_present=       "NOT PRESENT";
  462 my $err_no_prikey=         "PRIMARY KEY IS NOT PRESENT";
  463 my $err_0_rows_happened=   "'0 rows affected' happened";
  464 my $err_0_new_records=     "0 new records";
  465 my $err_0_fields=          "0 fields";
  466 my $err_no_checked_tables= "No checked table(s)";
  467 my $err_no_check_rec_tab=  "No checked record(s) or table(s)";
  468 my $err_tab_no_check_with= "table(s) no checked with checked record(s) or field(s)";
  469 my $err_tab_check_wo_exist="table(s) checked without existing record(s) or field(s)";
  470 my $err_tab_check_wo_check="table(s) checked without checked record(s) or field(s)";
  471 my $err_no_table_name=     "No table name";
  472 my $err_no_field_name=     "No field name";
  473 my $err_name_not_number=   "Name can not consist only of numbers";
  474 my $err_no_checked_fields= "No checked field(s)";
  475 my $err_same_name_fields=  "Same name for fields";
  476 my $err_in_table_name=     "in table name";
  477 my $err_in_field_name=     "in field name";
  478 my $err_required=          "is required";
  479 my $err_not_allowed=       "is not allowed";
  480 my $err_with=              "with";
  481 my $err_field=         "field";
  482 my $err_for_type=          "for type";
  483 my $err_space_character=   "'space'";
  484 
  485 #=========================================================
  486 #       HTML layout
  487 #=========================================================
  488 
  489 #=======box % width
  490 
  491 my $upper_box_perc=        "40%";
  492 my $fquery_box_perc=       "40%";
  493 
  494 #=======font face
  495 
  496 my $font_face=             'Verdana, Arial, Helvetica, sans-serif';        # font for general text
  497 my $button_font_face=      'Verdana, Arial, Helvetica, sans-serif';        # font for buttons
  498 my $numb_table_checkb_ff=  'Verdana, Arial, Helvetica, sans-serif';        # font for numbers before the checkbox of tables
  499 my $numb_rec_checkb_ff=    'Verdana, Arial, Helvetica, sans-serif';        # font for numbers before the checkbox of records
  500 my $tablename_font_face=   'Verdana, Arial, Helvetica, sans-serif';        # font for tables names
  501 my $box_font_face=         'Verdana, Arial, Helvetica, sans-serif';        # font for text in upper box
  502 my $null_face=             'Verdana, Arial, Helvetica, sans-serif';        # font for NULL
  503 
  504 #=======font size
  505 
  506 my $font_size=             '2';    # font size for general text
  507 my $button_font_size=      '2';    # font size for buttons
  508 my $numb_table_checkb_fs=  '2';    # font size for numbers before the checkbox of tables
  509 my $numb_rec_checkb_fs=    '2';    # font size for numbers before the checkbox of records
  510 my $tablename_font_size=   '2';    # font size for tables names
  511 my $box_font_size=         '3';    # font size for text in upper box
  512 my $null_size=             '2';    # font size for NULL
  513 
  514 #=======colors
  515 
  516 my $body_bgcolor=          '#ffffff';      # color for page background
  517 my $font_color=            '#000000';      # color font for general text
  518 my $font_color_log_fail=   'red';          # color font for user login fail text
  519 my $button_font_color=     '#000000';      # color for buttons
  520 my $table_color=           '#f0f0f0';      # color for tables background
  521 my $table_td_color=        '#a0b8c8';      # color for tables columns
  522 my $tablename_font_color=  '#000000';      # color font for tables names
  523 my $table_checkb_td_color= '#a0b8c8';      # color for columns with the checkbox of tables
  524 my $numb_table_checkb_col= '#000000';      # color font for numbers before the checkbox of tables
  525 my $numb_rec_checkb_col=   '#000000';      # color font for numbers before the checkbox of records
  526 my $rec_checkb_td_color=   '#a0b8c8';      # color for columns with the checkbox of records
  527 my $pri_key_color=         '#ea6467';      # color for columns with primary key field
  528 my $field_color=           '#00b8c8';      # color for columns with records fields
  529 my $label_color=           '#ea6467';      # color for labels
  530 my $box_bg_color=          '#f0f0f0';      # color for upper box background
  531 my $box_font_color=        '#000000';      # color font for text in upper box
  532 my $null_color=            '#00647f';      # color font for NULL
  533 
  534 #=======form
  535 
  536 my $input_text_size=       15;     # text size of the input control for insert & update fields
  537 my $text_size_4_create=    15;     # text size of the input control for table and field names
  538 my $maxlength_4_create=    64;     # maxlength of the input control for table and field names (would be 64 characters in MySQL)
  539 my $text_size_4_specif=    5;      # text size of the input control for type specifiers
  540 my $edit_textarea_auto=    1;      # enabled: 1 means YES, 0 means NO
  541                    # a textarea appears instead of the text input control
  542                    # if the type of the field is text or blob (edit operation)
  543 my $edit_textarea_enabled= 0;      # enabled: 1 means YES, 0 means NO
  544                                    # a textarea appears instead of the text input control (edit operation) [continue below]
  545 my $max_length4text=       40;     # if the number of characters of the field is higher than $max_length4text
  546 my $cols_textarea=         35;     # number of columns of the textarea
  547 my $rows_textarea=         4;      # number of rows of the textarea
  548 
  549 my $cols_fquery_textarea=  45;     # number of columns of the textarea for the free query
  550 my $rows_fquery_textarea=  4;      # number of rows of the textarea for the free query
  551 
  552 my $cols_fquery_texta_out= 55;     # number of columns of the textarea for the free query output
  553 my $rows_fquery_texta_out= 7;      # number of rows of the textarea for the free query output
  554 
  555 my $new_textarea_auto=     1;      # enabled: 1 means YES, 0 means NO
  556                    # a textarea appears instead of the text input control
  557                    # if the type of the field is text or blob (new operation)
  558 my $new_textarea_enabled=  0;      # 1 means YES, 0 means NO
  559                                    # if 1 a textarea appears instead of the text input control (new operation)
  560 
  561 my $cols_new_textarea=     25;     # number of columns of the textarea
  562 my $rows_new_textarea=     3;      # number of rows of the textarea
  563 my $where_text_size=       10;     # text size of input control for the SQL where
  564 my $and_text_size=         10;     # text size of input control for the SQL and
  565 
  566 my $limit_values=          q{
  567                         <option>5</option>
  568                         <option>10</option>
  569                         <option>25</option>
  570                         <option>50</option>
  571                         <option>100</option>
  572                         };
  573 
  574 my $limit_offset_values=   q{
  575                         <option>5</option>
  576                         <option>10</option>
  577                         <option>15</option>
  578                         <option>20</option>
  579                         };
  580 
  581 my $select_params=         q{
  582                         <option>=</option>
  583                         <option>like</option>
  584                         <option>&gt;</option>
  585                         <option>&gt;=</option>
  586                         <option>&lt;</option>
  587                         <option>&lt;=</option>
  588                         };
  589 
  590 my $orderby_params=        q{
  591                         <option>ASC</option>
  592                         <option>DESC</option>
  593                         };
  594 
  595 my $new_values=            q{
  596                         <option>1</option>
  597                         <option>2</option>
  598                         <option>3</option>
  599                         <option>4</option>
  600                         <option>5</option>
  601                         <option>10</option>
  602                         <option>20</option>
  603                         };
  604 
  605 my $new_fields=            q{
  606                         <option>1</option>
  607                         <option>2</option>
  608                         <option>3</option>
  609                         <option>4</option>
  610                         <option>5</option>
  611                         <option>10</option>
  612                         <option>20</option>
  613                         };
  614 
  615 #================================================================================
  616 #                       VARIABLE CONFIGURATION SECTION END
  617 #================================================================================
  618 
  619 #================================================================================
  620 #
  621 #                               PAY ATTENTION!
  622 #
  623 #               PLEASE DO NOT EDIT ANYTHING UNDER THIS COMMENT
  624 #                   IF YOU ARE NOT SURE WHAT ARE YOU DOING
  625 #
  626 #================================================================================
  627 
  628 use vars qw/    %CGI_INPUT %CHECKED_ITEMS %FIELD_VALUES %HASH_pri_keys @ARRAY_pri_keys
  629         %FIELD_NAMES %internal_SPECIFIERS_ORDER %SPECIFIERS_PROPERTIES $dbh
  630         %FIELDS_TYPES %NO_SYNC_INPUT_HASH1 %CHECKED_TABLES %NO_SYNC_INPUT_HASH2
  631         %DUP_HASH %SELECT_PARAMS %PREPARE_NAMES @tables_names $global_err $server_state
  632         @javascript_objects $flag_ok $database_prompt $empty_db $descarray
  633         $fquery_output $relevant_js_obj $warning_flag $current_db $current_user
  634                 $current_pwd $descarray_describe $elem_describe $elem_select $selected_rows/;
  635 
  636 my $VERSION='1.5.4';
  637 my $mysqlwdb_link='http://www.igsuite.org/cgi-bin/igwiki/mysqlwdb';
  638 
  639 #===============================================#
  640 #                                               #
  641 #                    main                       #
  642 #                                               #
  643 #===============================================#
  644 
  645 input_from_CGI();
  646 
  647 if (($db_backup_enabled and $CGI_INPUT{db_backupok}) or 
  648     ($table_backup_enabled and $CGI_INPUT{table_backupok}) or 
  649     ($db_csv_exp_enabled and $CGI_INPUT{db_csv_expok}) or 
  650     ($table_csv_exp_enabled and $CGI_INPUT{table_csv_expok}) ) {
  651 
  652     if (get_current_db()) {
  653 
  654                 if (!DBI_initialization()) {
  655 
  656             put_HTTP_header();
  657             if ($custom_configuration) {
  658 
  659                     put_HTML_header('server_login_failed');
  660                 DBI_error();
  661 
  662             } else {
  663 
  664                         put_HTML_header('server_login_failed');
  665                 prompt_server_login();
  666             }
  667 
  668         } elsif (($db_backup_enabled and $CGI_INPUT{db_backupok}) or 
  669                  ($table_backup_enabled and $CGI_INPUT{table_backupok}) ) {
  670 
  671             put_HTTP_header_nohtml($backup_filename);
  672 
  673             my ($database,$host,$port);
  674             if ($custom_configuration) {
  675 
  676                     $host=$DATABASES{$current_db}{'host'};
  677                     $port=$DATABASES{$current_db}{'port'};
  678                     $database=$DATABASES{$current_db}{'database'};
  679 
  680             } else {
  681 
  682                     $host=$CGI_INPUT{'server_login_host'};
  683                     $port=$CGI_INPUT{'server_login_port'};
  684                     $database=$CGI_INPUT{'server_login_database'};
  685             }
  686 
  687             qselect("SELECT version()");
  688 
  689             print "-- dump by mysqlwdb $VERSION ($mysqlwdb_link)\n";
  690             print "--\n";
  691             print "-- Host: $host    Database: $database\n";
  692             print "---------------------------------------------------------\n";
  693             print "-- Server version    ".$elem_select->[0]->[0]."\n\n";
  694 
  695             if ($CGI_INPUT{table_backupok}) {
  696 
  697                 table_backup($CGI_INPUT{backup_type});
  698 
  699             } elsif ($CGI_INPUT{db_backupok}) {
  700 
  701                 db_backup($CGI_INPUT{backup_type});
  702             }
  703             exit;
  704 
  705         } elsif (($db_csv_exp_enabled and $CGI_INPUT{db_csv_expok}) or 
  706                  ($table_csv_exp_enabled and $CGI_INPUT{table_csv_expok}) ) {
  707 
  708             put_HTTP_header_nohtml($csv_exp_filename);
  709 
  710             if ($CGI_INPUT{table_csv_expok}) {
  711 
  712                 table_csv_exp($CGI_INPUT{csv_exp_separator});
  713 
  714             } elsif ($CGI_INPUT{db_csv_expok}) {
  715 
  716                 db_csv_exp($CGI_INPUT{csv_exp_separator});
  717             }
  718 
  719             exit;
  720         }
  721 
  722     } else {
  723 
  724         put_HTTP_header();
  725             put_HTML_header('general_error');
  726     }
  727 
  728     put_HTML_footer();
  729     exit;
  730 
  731 } else {
  732     
  733     put_HTTP_header();
  734 }
  735 
  736 my $verify_state=verify_user();
  737 
  738 if (!$custom_configuration) {
  739 
  740     %DATABASES=();
  741     $server_state=0;
  742 }
  743 
  744 if ($verify_state == -1) {
  745 
  746         put_HTML_header('user_login_failed');
  747         prompt_user_login('failed');
  748 
  749 } elsif ($verify_state == 0) {
  750 
  751         put_HTML_header('user_login');
  752         prompt_user_login('normal');
  753 
  754 } else {
  755 
  756         if ($CGI_INPUT{'go_to_db_choice'}) {
  757 
  758                 $database_prompt=1;
  759         if ($custom_configuration) {
  760 
  761                     put_HTML_header('db_prompt');
  762                     prompt_db_choice();
  763 
  764         } else {
  765 
  766             $server_state=1;
  767                     put_HTML_header('server_login');
  768             prompt_server_login();
  769         }
  770 
  771         } elsif ($CGI_INPUT{'server_login'}) {
  772 
  773         if (db_list()) {
  774 
  775                     put_HTML_header('db_prompt');
  776             prompt_db_choice();
  777 
  778         } else {
  779 
  780                 put_HTML_header('server_login_failed');
  781             DBI_error();
  782         }
  783 
  784         } elsif (get_current_db()) {
  785 
  786                 if (!DBI_initialization()) {
  787 
  788             if ($custom_configuration) {
  789 
  790                     put_HTML_header('server_login_failed');
  791                 DBI_error();
  792 
  793             } else {
  794 
  795                         put_HTML_header('server_login_failed');
  796                 prompt_server_login();
  797             }
  798 
  799         } else {
  800 
  801                     put_HTML_header('normal');
  802                     get_action_info();
  803                     perform_action();
  804         }
  805 
  806         } else {
  807 
  808         if ($custom_configuration) {
  809 
  810                     put_HTML_header('db_prompt');
  811                     prompt_db_choice();
  812 
  813         } else {
  814 
  815             $server_state=1;
  816                     put_HTML_header('server_login');
  817             prompt_server_login();
  818         }
  819         }
  820 }
  821 
  822 put_HTML_footer();
  823 
  824 exit;
  825 
  826 #===============================================#
  827 #                                               #
  828 #               subroutines                     #
  829 #                                               #
  830 #===============================================#
  831 
  832 #===============================================
  833 #       HTTP , CGI , DBI , USER subroutines
  834 #===============================================
  835 
  836 sub put_HTTP_header {
  837 
  838         print "Content-Type: text/html\n\n";
  839 }
  840 
  841 sub put_HTTP_header_nohtml {
  842 
  843         print "Content-Type: octet-stream\n";
  844     print "Content-Disposition: attachment; filename=\"$_[0]\"\n\n";
  845 }
  846 
  847 sub put_HTML_footer {
  848 
  849     print qq{<br><div align="center"><a href="$mysqlwdb_link"><font face="$font_face" size="$font_size">mysqlwdb $VERSION</font></a></div>} if ($display_mysqlwdb_link);
  850     print q{</body></html>};
  851 }
  852 
  853 sub put_HTML_header {
  854 
  855         my $state=$_[0];
  856         my $message;
  857 
  858         if ($state eq 'normal') {
  859 
  860         if ($custom_configuration) {
  861 
  862             $message=$DATABASES{$current_db}{'db_description'};
  863 
  864         } else {
  865 
  866             $message=$DATABASES{'1'}{'db_description'};
  867         }
  868 
  869         } elsif ($state eq 'server_login') {
  870 
  871                 $message=$server_login;
  872 
  873         } elsif ($state eq 'server_login_failed') {
  874 
  875                 $message=$server_login_fail_prompt;
  876 
  877         } elsif ($state eq 'db_prompt') {
  878 
  879                 $message=$databases_choice;
  880 
  881         } elsif ($state eq 'user_login_failed') {
  882 
  883                 $message=$user_login_failed;
  884 
  885         } elsif ($state eq 'general_error') {
  886 
  887                 $message=$general_error;
  888 
  889         } else {
  890 
  891                 $message=$user_login;
  892         }
  893 
  894         print qq{<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
  895         <html>
  896                 <head>
  897                 <title>$message</title>
  898                 </head>
  899                 <body bgcolor="$body_bgcolor">
  900                 };
  901 
  902         if ($upper_box_enabled) {
  903 
  904                 print qq{
  905                         <br>
  906                         <div align="center">
  907                         <table border="0" cellpadding="1" cellspacing="0" width="$upper_box_perc">
  908                         <tr><td bgcolor="#000000">
  909                         <table border="0" cellpadding="5" cellspacing="0" width = "100%">
  910                         <tr><td bgcolor="$box_bg_color" width="100%" align="center">
  911                         <font face="$box_font_face" size="$box_font_size" color="$box_font_color">
  912                         <b>$message</b>
  913                         </font>
  914                         </td>
  915                         </tr>
  916                         </table>
  917                         </td>
  918                         </tr>
  919                         </table>
  920                         </div>
  921                         <br>
  922                         };
  923         }
  924 }
  925 
  926 sub input_from_CGI {
  927 
  928         my ($name,
  929             $value,
  930             $elem,
  931             @pair,
  932         $request
  933             );
  934 
  935         if ($ENV{REQUEST_METHOD} eq "GET") {
  936 
  937                 $request=$ENV{QUERY_STRING};
  938 
  939         } else {
  940 
  941                 read(STDIN, $request, $ENV{CONTENT_LENGTH});
  942         }
  943 
  944         @pair = split('&', $request);
  945 
  946         foreach $elem (@pair) {
  947 
  948                 ($name, $value) = split('=',$elem);
  949 
  950                 $value =~ tr/+/ /;
  951 
  952                 $name  =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack('c',hex($1))/ge;
  953                 $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack('c',hex($1))/ge;
  954 
  955                 $CGI_INPUT{$name} = $value;
  956         }
  957 }
  958 
  959 sub DBI_error {
  960 
  961         print qq{
  962                 <br>
  963                 <table align="center" border="0" cellpadding="1" cellspacing="0">
  964                 <tr>
  965                 <td bgcolor="#000000">
  966                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
  967                 <tr>
  968                 <td>
  969                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
  970                 <tr>
  971                 <td>
  972                 };
  973 
  974                 my $err="<b>$err_error_word:</b> $err_connect_db<br><b>$err_details_word:</b> $DBI::errstr";
  975                 write_labeled_message($err);
  976 
  977         print q{
  978                 </td>
  979                 </tr>
  980                 };
  981 
  982         if ($login_prompt) {
  983 
  984             print q{
  985                         <tr>
  986                     <td colspan="2"><table border="0">
  987                     };
  988 
  989                     put_user_related_buttons();
  990 
  991                 print q{</table>
  992                     </td>
  993                     </tr>
  994                     };
  995         }
  996 
  997         if ($custom_configuration && $database_prompt) {
  998 
  999                 $refresh_enabled=0;
 1000 
 1001                 print qq{<tr><td>
 1002                         <form name="the_script" method="POST" action="$thiscgi">
 1003                         <input type="hidden" name="current_db" value="$current_db">
 1004                         <input type="hidden" name="current_user" value="$current_user">
 1005                         <input type="hidden" name="current_pwd" value="$current_pwd">
 1006             <table>
 1007                         };
 1008 
 1009                 put_database_related_buttons();
 1010 
 1011                 print q{
 1012             </table>
 1013                         </form>
 1014             </td></tr>
 1015                         };
 1016         }
 1017 
 1018         print q{
 1019                 </table>
 1020                 </td>
 1021                 </tr>
 1022                 </table>
 1023                 </td>
 1024                 </tr>
 1025                 </table>
 1026                 };
 1027 }
 1028 
 1029 sub DBI_initialization {
 1030 
 1031         my ($host,$port,$database,$user,$password,$dsn);
 1032 
 1033     if ($custom_configuration) {
 1034 
 1035             $host=$DATABASES{$current_db}{'host'};
 1036             $port=$DATABASES{$current_db}{'port'};
 1037             $database=$DATABASES{$current_db}{'database'};
 1038             $user=$DATABASES{$current_db}{'user'};
 1039             $password=$DATABASES{$current_db}{'password'};
 1040 
 1041     } else {
 1042 
 1043             $host=$CGI_INPUT{'server_login_host'};
 1044             $port=$CGI_INPUT{'server_login_port'};
 1045             $database=$CGI_INPUT{'server_login_database'};
 1046             $user=$CGI_INPUT{'server_login_user'};
 1047             $password=$CGI_INPUT{'server_login_pwd'};
 1048     }
 1049 
 1050         use DBI;
 1051 
 1052         if ($recent_DBD_dsn_syntax) {
 1053 
 1054                 $dsn="DBI:$DBI_driver:database=$database;host=$host;port=$port";
 1055 
 1056         } else {
 1057 
 1058                 $dsn="DBI:$DBI_driver:$database:$host:$port";
 1059         }
 1060 
 1061         if (!($dbh=DBI->connect($dsn,$user,$password))) {
 1062 
 1063         return 0;
 1064 
 1065     } else {
 1066 
 1067         return 1;
 1068     }
 1069 }
 1070 
 1071 sub db_list {
 1072 
 1073     %DATABASES=();
 1074 
 1075     return 0 if (!DBI_initialization());
 1076 
 1077     my $drh=DBI->install_driver('mysql');
 1078     my @databases;
 1079 
 1080     if (!$ListDBs_data_sources) {
 1081 
 1082         @databases= $drh->func($CGI_INPUT{'server_login_host'},'_ListDBs');
 1083 
 1084     } else {
 1085 
 1086         @databases = DBI->data_sources('mysql',{
 1087                             host     => $CGI_INPUT{'server_login_host'},
 1088                                 port     => $CGI_INPUT{'server_login_port'},
 1089                                                     user     => $CGI_INPUT{'server_login_user'},
 1090                                                     password => $CGI_INPUT{'server_login_pwd'}
 1091                             }
 1092                         );
 1093     }
 1094 
 1095     my $db_count;
 1096     foreach my $database (@databases) {
 1097 
 1098         if ($database=~/:/) {
 1099 
 1100             $database=~/:([^:]+?)$/;
 1101             $database=$1;
 1102         }
 1103 
 1104         $db_count++;
 1105         $DATABASES{"$db_count"}={
 1106             host=>$CGI_INPUT{'server_login_host'},
 1107             port=>$CGI_INPUT{'server_login_port'},
 1108             database=>$database,
 1109             user=>$CGI_INPUT{'server_login_user'},
 1110             password=>$CGI_INPUT{'server_login_pwd'},
 1111             db_description=>$database
 1112         }
 1113     }
 1114 
 1115     return 1;
 1116 }
 1117 
 1118 sub get_current_db {
 1119 
 1120         my ($db_position,$dbs,$last_db);
 1121 
 1122         $current_db=$CGI_INPUT{'current_db'};
 1123 
 1124     if (!$custom_configuration) {
 1125 
 1126         if ($current_db eq '#') {
 1127 
 1128             $DATABASES{"1"}={
 1129                 host=>$CGI_INPUT{'server_login_host'},
 1130                 port=>$CGI_INPUT{'server_login_port'},
 1131                 database=>$CGI_INPUT{'server_login_database'},
 1132                 user=>$CGI_INPUT{'server_login_user'},
 1133                 password=>$CGI_INPUT{'server_login_pwd'},
 1134                 db_description=>$CGI_INPUT{'server_login_database'}
 1135             };
 1136 
 1137             $database_prompt=1;
 1138             return 1;
 1139 
 1140         } else {
 1141 
 1142             return 0;
 1143         }
 1144     }
 1145 
 1146         foreach $db_position (sort numerically keys %DATABASES) {
 1147 
 1148                 $last_db=$db_position;
 1149                 $dbs++;
 1150         }
 1151 
 1152         if ($dbs > 1) {
 1153 
 1154                 $database_prompt=1;
 1155 
 1156                 if (!$current_db) {
 1157 
 1158                         return 0;
 1159 
 1160                 } else {
 1161 
 1162                         return 1;
 1163                 }
 1164 
 1165         } else {
 1166 
 1167                 $database_prompt=0;
 1168 
 1169                 if (!$current_db) {
 1170 
 1171                         $current_db=$last_db;
 1172                 }
 1173 
 1174                 return 1;
 1175         }
 1176 }
 1177 
 1178 sub table_backup {
 1179 
 1180     my $type=$_[0];
 1181     get_checked_tables();
 1182 
 1183         foreach my $table_name (sort keys %CHECKED_TABLES) {
 1184 
 1185         if ($type eq 'with') {
 1186 
 1187             backup_table_desc($table_name,$CGI_INPUT{'with_drop'});
 1188                 print "\n";
 1189             backup_table_data($table_name,$CGI_INPUT{'with_drop'});
 1190 
 1191         } elsif ($type eq 'without') {
 1192 
 1193             backup_table_data($table_name,$CGI_INPUT{'without_lock'});
 1194 
 1195         } elsif ($type eq 'struct') {
 1196 
 1197             backup_table_desc($table_name,$CGI_INPUT{'struct_drop'});
 1198         }
 1199 
 1200         print "\n";
 1201     }
 1202 }
 1203 
 1204 sub table_csv_exp {
 1205 
 1206     my $csv_separator=$_[0];
 1207     get_checked_tables();
 1208 
 1209         foreach my $table_name (sort keys %CHECKED_TABLES) {
 1210 
 1211         csv_exp($table_name,$csv_separator);
 1212     }
 1213 }
 1214 
 1215 sub db_backup {
 1216 
 1217     my $type=$_[0];
 1218     list_tables();
 1219 
 1220     foreach my $table_name (sort @tables_names) {
 1221 
 1222         if ($type eq 'with') {
 1223 
 1224             backup_table_desc($table_name,$CGI_INPUT{'with_drop'});
 1225                 print "\n";
 1226             backup_table_data($table_name,$CGI_INPUT{'with_lock'});
 1227 
 1228         } elsif ($type eq 'without') {
 1229 
 1230             backup_table_data($table_name,$CGI_INPUT{'without_lock'});
 1231 
 1232         } elsif ($type eq 'struct') {
 1233 
 1234             backup_table_desc($table_name,$CGI_INPUT{'struct_drop'});
 1235         }
 1236 
 1237         print "\n";
 1238     }
 1239 }
 1240 
 1241 sub db_csv_exp {
 1242 
 1243     my $csv_separator=$_[0];
 1244     list_tables();
 1245 
 1246     foreach my $current_table (sort @tables_names) {
 1247 
 1248         csv_exp($current_table,$csv_separator);
 1249     }
 1250 }
 1251 
 1252 sub csv_exp {
 1253 
 1254     my $current_table=$_[0];
 1255     my $csv_separator=$_[1];
 1256     my $csv_separator_quote=quotemeta($csv_separator);
 1257 
 1258     qselect("SHOW COLUMNS FROM $current_table");
 1259 
 1260         my $pri_key_string=get_pri_key($current_table);
 1261 
 1262     my $qstring="SELECT * FROM $current_table";
 1263     $qstring.=" ORDER BY $pri_key_string" if ($pri_key_string);
 1264 
 1265         qselect($qstring);
 1266 
 1267         foreach my $elem (@{$elem_select}) {
 1268 
 1269         my $type_array_index;
 1270         my $data;
 1271                 foreach my $row_elem (@{$elem}) {
 1272 
 1273             $row_elem=~s/\r//g;
 1274             $row_elem=~s/"/""/g;
 1275 
 1276             if ($row_elem=~/$csv_separator_quote/ or $row_elem=~/\n/ or $row_elem=~/"/) {
 1277 
 1278                 $data.="\"$row_elem\"$csv_separator";
 1279 
 1280             } else {
 1281 
 1282                 $data.="$row_elem$csv_separator";
 1283             }
 1284         }
 1285 
 1286         chop($data);
 1287         print "$data\n";
 1288     }
 1289 }
 1290 
 1291 sub backup_table_desc {
 1292 
 1293     my $current_table=$_[0];
 1294     my $drop_action=$_[1];
 1295 
 1296     qselect("SHOW CREATE TABLE $current_table");
 1297     $elem_select->[0]->[1] =~ tr/`//d;
 1298 
 1299     print "--\n";
 1300     print "-- Table structure for table `$current_table`\n";
 1301     print "--\n";
 1302 
 1303     print "\nDROP TABLE IF EXISTS $current_table;" if ($drop_action);
 1304     print "\n".$elem_select->[0]->[1].";\n" if ($elem_select->[0]->[1] ne '');
 1305 
 1306     return;
 1307 }
 1308 
 1309 sub backup_table_data {
 1310 
 1311     my $current_table=$_[0];
 1312     my $lock_action=$_[1];
 1313 
 1314     qselect("SHOW COLUMNS FROM $current_table");
 1315 
 1316     my @type_array;
 1317     foreach my $elem (@{$elem_select}) {
 1318     
 1319         push @type_array,$$elem[1];
 1320     }
 1321 
 1322         my $pri_key_string=get_pri_key($current_table);
 1323 
 1324     my $qstring="SELECT * FROM $current_table";
 1325     $qstring.=" ORDER BY $pri_key_string" if ($pri_key_string);
 1326 
 1327         qselect($qstring);
 1328 
 1329     print "--\n";
 1330     print "-- Dumping data for table `$current_table`\n";
 1331     print "--\n\n";
 1332 
 1333     print "LOCK TABLES $current_table WRITE;\n" if ($lock_action);
 1334 
 1335         foreach my $elem (@{$elem_select}) {
 1336 
 1337         my $type_array_index;
 1338         my $data="INSERT INTO $current_table VALUES (";
 1339                 foreach my $row_elem (@{$elem}) {
 1340 
 1341             my $quoted_value=$row_elem;
 1342             $quoted_value=$dbh->quote($row_elem,$type_array[$type_array_index++]);
 1343             $quoted_value='NULL' if (!defined $row_elem);
 1344             $data.="$quoted_value,";
 1345         }
 1346     
 1347         chop($data);
 1348         print $data.");\n";
 1349     }
 1350     print "UNLOCK TABLES;\n" if ($lock_action);
 1351 }
 1352 
 1353 sub verify_user {
 1354 
 1355         if ($login_prompt) {
 1356 
 1357                 if ((exists $CGI_INPUT{'current_user'}) and (exists $CGI_INPUT{'current_pwd'})) {
 1358 
 1359                         my $salt=substr $CGI_INPUT{'current_pwd'},0,2;
 1360                         my $encrypted_pwd=crypt($LOGIN{$CGI_INPUT{'current_user'}},$salt);
 1361 
 1362                         if ($encrypted_pwd eq $CGI_INPUT{'current_pwd'}) {
 1363 
 1364                                 $current_user=$CGI_INPUT{'current_user'};
 1365                                 $current_pwd=$CGI_INPUT{'current_pwd'};
 1366                                 return 1
 1367 
 1368                         } else {
 1369 
 1370                                 return -1
 1371                         }
 1372 
 1373                 } elsif ((exists $CGI_INPUT{'user_id'}) or (exists $CGI_INPUT{'user_pwd'})) {
 1374 
 1375                         if (scalar(keys %LOGIN) and (exists $LOGIN{$CGI_INPUT{'user_id'}}) and ($LOGIN{$CGI_INPUT{'user_id'}} eq $CGI_INPUT{'user_pwd'})) {
 1376 
 1377                                 my @list_of_chars=(0..9,'a'..'z','A'..'Z');
 1378                                 my $first_salt=rand 64;
 1379                                 srand;
 1380                                 my $secont_salt=rand 64;
 1381                                 my $salt=$list_of_chars[$first_salt].$list_of_chars[$secont_salt];
 1382                                 my $encrypted_pwd=crypt($LOGIN{$CGI_INPUT{'user_id'}},$salt);
 1383 
 1384                                 $current_user=$CGI_INPUT{'user_id'};
 1385                                 $current_pwd=$encrypted_pwd;
 1386                                 return 1
 1387 
 1388                         } else {
 1389 
 1390                                 return -1
 1391                         }
 1392 
 1393                 } else {
 1394 
 1395                         return 0
 1396                 }
 1397 
 1398         } else {
 1399 
 1400                 return 1;
 1401         }
 1402 }
 1403 
 1404 #===============================================
 1405 #       Misc. subroutines
 1406 #===============================================
 1407 
 1408 sub write_labeled_message {
 1409 
 1410         print qq{
 1411                 <br>
 1412                 <div align="center">
 1413                 <table border="0" cellspacing="1" cellpadding="3" width="300">
 1414                 <tr bgcolor="$label_color" align="center">
 1415                 <td>
 1416                 <font face="$font_face" size="$font_size">
 1417                 $_[0]
 1418                 </font>
 1419                 </td>
 1420                 </tr>
 1421                 </table>
 1422                 </div>
 1423                 <br>
 1424                 };
 1425 }
 1426 
 1427 sub numerically { $a <=> $b; }
 1428 
 1429 sub html2txt {
 1430 
 1431         my $html_input=$_[0];
 1432         my $param=$_[1];
 1433 
 1434         $html_input =~ s/&/&amp;/g;
 1435         $html_input =~ s/</&lt;/g;
 1436         $html_input =~ s/>/&gt;/g;
 1437         $html_input =~ s/"/&quot;/g;
 1438 
 1439         if ($param eq 'br') {
 1440                 $html_input =~ s/\n/<br>/g;
 1441             $html_input =~ s/\x20/&nbsp;/g;
 1442         }
 1443 
 1444         return $html_input;
 1445 }
 1446 
 1447 sub txt2html {
 1448 
 1449         my $html_input=$_[0];
 1450         my $param=$_[1];
 1451 
 1452         if ($param eq 'br') {
 1453                 $html_input =~ s/<br>/\n/g;
 1454             $html_input =~ s/&(nbsp|#160);/chr(32)/ge;
 1455         }
 1456 
 1457         $html_input =~ s/&quot;/"/g;
 1458         $html_input =~ s/&gt;/>/g;
 1459         $html_input =~ s/&lt;/</g;
 1460         $html_input =~ s/&amp;/&/g;
 1461 
 1462         return $html_input;
 1463 }
 1464 
 1465 #===============================================
 1466 #       DBMS actions subroutines
 1467 #===============================================
 1468 
 1469 sub create {
 1470 
 1471         my ($type,
 1472             $checked_type,
 1473             $create_string,
 1474             $err_message,
 1475             $appear,
 1476             $order,
 1477             $pair_done,
 1478             $property,
 1479             $required_specifier,
 1480         $pri_key_create_string,
 1481         $index_create_string,
 1482         $fulltext_create_string,
 1483         $unique_create_string,
 1484         $output_specifier
 1485             );
 1486 
 1487         $create_string="CREATE TABLE $CGI_INPUT{'table_name'}(";
 1488 
 1489         foreach my $checked (sort numerically keys %{$FIELD_NAMES{'checked_item'}}) {
 1490 
 1491                 $pair_done=0;
 1492                 $create_string.="$FIELD_NAMES{'field_name'}{$checked} $FIELD_NAMES{'field_type'}{$checked}";
 1493 
 1494                 foreach my $specifier (sort { $internal_SPECIFIERS_ORDER{$a} <=> $internal_SPECIFIERS_ORDER{$b} } keys %internal_SPECIFIERS_ORDER) {
 1495 
 1496                         if (!$FIELD_NAMES{$specifier}{$checked}) {next;}
 1497 
 1498                         ($appear,$order)=split /\+/ , $SPECIFIERS_PROPERTIES{$specifier}{'appear'};
 1499 
 1500                         if ($appear) {
 1501 
 1502                 if ($specifier eq 'primary_key') {
 1503 
 1504                     $pri_key_create_string.="$FIELD_NAMES{'field_name'}{$checked}";
 1505                     $pri_key_create_string.="($FIELD_NAMES{'index'}{$checked})" if $FIELD_NAMES{'index'}{$checked};
 1506                     $pri_key_create_string.=',';
 1507                     next;
 1508 
 1509                 } elsif ($specifier eq 'index') {
 1510 
 1511                     next if($FIELD_NAMES{'primary_key'}{$checked});
 1512                     $FIELD_NAMES{$specifier}{$checked}=~/([^\(]+)\(([^\)]+)\)/;
 1513                     my $index_name=$1;
 1514                     my $index_length=$2;
 1515                     if ($index_length) {
 1516 
 1517                         $index_create_string.="KEY $index_name ($FIELD_NAMES{'field_name'}{$checked}($index_length)),";
 1518 
 1519                     } else {
 1520 
 1521                         $index_create_string.="KEY $FIELD_NAMES{$specifier}{$checked} ($FIELD_NAMES{'field_name'}{$checked}),";
 1522                     }
 1523 
 1524                     next;
 1525 
 1526                 } elsif ($specifier eq 'unique') {
 1527 
 1528                     $unique_create_string.="UNIQUE $FIELD_NAMES{$specifier}{$checked} ($FIELD_NAMES{'field_name'}{$checked}),";
 1529 
 1530                     next;
 1531 
 1532                 } elsif ($specifier eq 'fulltext') {
 1533 
 1534                     $fulltext_create_string.="$FIELD_NAMES{'field_name'}{$checked},";
 1535 
 1536                     next;
 1537                 }
 1538 
 1539                                 ($output_specifier=$specifier) =~ s/_/ /;
 1540 
 1541                                 if ($SPECIFIERS_PROPERTIES{$specifier}{'html'} eq 'text') {
 1542 
 1543                                         $create_string.=" $output_specifier $FIELD_NAMES{$specifier}{$checked} ";
 1544 
 1545                                 } else {
 1546 
 1547                                         $create_string.=" $output_specifier ";
 1548                                 }
 1549 
 1550                         } else {
 1551 
 1552                                 $checked_type=$FIELD_NAMES{'field_type'}{$checked};
 1553                                 ($property,$required_specifier)=split /\+/ , $FIELDS_TYPES{$checked_type}{$specifier};
 1554 
 1555                                 if ($required_specifier) {
 1556 
 1557                                         if (!$pair_done) {
 1558 
 1559                                                 if ($order eq '1') {
 1560 
 1561                                                         $create_string.="($FIELD_NAMES{$specifier}{$checked},$FIELD_NAMES{$required_specifier}{$checked}) ";
 1562 
 1563                                                 } else {
 1564 
 1565                                                         $create_string.="($FIELD_NAMES{$required_specifier}{$checked},$FIELD_NAMES{$specifier}{$checked}) ";
 1566                                                 }
 1567 
 1568                                                 $pair_done=1;
 1569                                         }
 1570 
 1571                                 } else {
 1572 
 1573                                         $create_string.="($FIELD_NAMES{$specifier}{$checked}) ";
 1574                                 }
 1575                         }
 1576                 }
 1577 
 1578                 if (exists $FIELD_NAMES{'auto_increment'}{0}) {
 1579 
 1580                         if ($FIELD_NAMES{'auto_increment'}{0} == $checked) {
 1581 
 1582                                 $create_string.=" auto_increment ";
 1583                         }
 1584                 }
 1585 
 1586                 $create_string.=",";
 1587         }
 1588 
 1589     chop $create_string;
 1590 
 1591     if ($pri_key_create_string) {
 1592 
 1593         chop $pri_key_create_string;
 1594         $pri_key_create_string=',PRIMARY KEY ('.$pri_key_create_string.')';
 1595         $create_string.=$pri_key_create_string;
 1596     }
 1597 
 1598     if ($index_create_string) {
 1599 
 1600         chop $index_create_string;
 1601         $create_string.=','.$index_create_string;
 1602     }
 1603 
 1604     if ($fulltext_create_string) {
 1605 
 1606         chop $fulltext_create_string;
 1607         $create_string.=', FULLTEXT('.$fulltext_create_string.')';
 1608     }
 1609 
 1610     if ($unique_create_string) {
 1611 
 1612         chop $unique_create_string;
 1613         $create_string.=','.$unique_create_string;
 1614     }
 1615 
 1616     $create_string.=')';
 1617 
 1618         my $sth = $dbh->do($create_string);
 1619 
 1620         if ( !defined $sth ) {
 1621 
 1622                 $global_err="$DBI::errstr";
 1623                 return 0;
 1624 
 1625         } elsif ($sth eq "0E0") {
 1626 
 1627                 $warning_flag=1;
 1628         }
 1629 
 1630         if ($wrng_enabled_4_crate and $warning_flag) {
 1631 
 1632                 $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 1633                 write_labeled_message($err_message);
 1634         }
 1635 
 1636         return 1;
 1637 }
 1638 
 1639 sub drop {
 1640 
 1641         my ($table_name,
 1642             $warning_flag,
 1643             $err_message
 1644             );
 1645 
 1646         foreach $table_name (keys %CHECKED_TABLES) {
 1647 
 1648                 my $sth = $dbh->do("drop table $table_name");
 1649 
 1650                 if ( !defined $sth ) {
 1651 
 1652                         $global_err="$DBI::errstr";
 1653                         return 0;
 1654 
 1655                 } elsif ($sth eq "0E0") {
 1656 
 1657                         $warning_flag=1;
 1658                 }
 1659         }
 1660 
 1661         if ($wrng_enabled_4_drop and $warning_flag) {
 1662 
 1663                 $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 1664                 write_labeled_message($err_message);
 1665         }
 1666 
 1667         return 1;
 1668 }
 1669 
 1670 sub erase {
 1671 
 1672         my ($table_name,
 1673             $warning_flag,
 1674             $err_message
 1675             );
 1676 
 1677         foreach $table_name (keys %CHECKED_TABLES) {
 1678 
 1679                 my $sth = $dbh->do("delete from $table_name");
 1680 
 1681                 if ( !defined $sth ) {
 1682 
 1683                         $global_err="$DBI::errstr";
 1684                         return 0;
 1685 
 1686                 } elsif ($sth eq "0E0") {
 1687 
 1688                         $warning_flag=1;
 1689                 }
 1690         }
 1691 
 1692         if ($wrng_enabled_4_erase and $warning_flag) {
 1693 
 1694                 $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 1695                 write_labeled_message($err_message);
 1696         }
 1697 
 1698         return 1;
 1699 }
 1700 
 1701 sub deleterec {
 1702 
 1703         my ($where_string,
 1704             $table_name,
 1705             $key_name,
 1706             $delete_string,
 1707             $number,
 1708             $warning_flag,
 1709             $err_message
 1710             );
 1711 
 1712         if (!lock_tables()) {return 0;}
 1713 
 1714         foreach $table_name (keys %CHECKED_ITEMS) {
 1715 
 1716                 foreach $key_name (keys %{$CHECKED_ITEMS{$table_name}}) {
 1717 
 1718                         foreach $number (keys %{$CHECKED_ITEMS{$table_name}{$key_name}}) {
 1719 
 1720                 $where_string='';
 1721                 my $tmp_pri_key_delimiter=quotemeta($pri_key_delimiter);
 1722                 my @pri_keys=split /$tmp_pri_key_delimiter/,$key_name;
 1723                 my @pri_keys_values=split /$tmp_pri_key_delimiter/,$CHECKED_ITEMS{$table_name}{$key_name}{$number};
 1724                 foreach (0..$#pri_keys) {
 1725 
 1726                             my $quoted_value=$pri_keys_values[$_];
 1727 
 1728                                         if ($quoted_value eq '') {
 1729 
 1730                                                 $quoted_value="''";
 1731 
 1732                                         } else {
 1733 
 1734                                     $quoted_value=$dbh->quote($quoted_value);
 1735                                         }
 1736 
 1737                         $where_string.="($pri_keys[$_] = $quoted_value) and ";
 1738                 }
 1739 
 1740                 substr($where_string,-5)='';
 1741 
 1742                 $where_string=' where ('.$where_string.')';
 1743 
 1744                                 $delete_string=qq{delete from $table_name $where_string};
 1745 
 1746                                 my $sth = $dbh->do("$delete_string");
 1747 
 1748                                 if ( !defined $sth ) {
 1749 
 1750                                         $global_err="$DBI::errstr";
 1751                                         return 0;
 1752 
 1753                                 } elsif ($sth eq "0E0") {
 1754 
 1755                                         $warning_flag=1;
 1756                                 }
 1757                         }
 1758                 }
 1759         }
 1760 
 1761         if (!unlock_tables()) {
 1762 
 1763                 return 0;
 1764 
 1765         } else {
 1766 
 1767                 if ($wrng_enabled_4_delete and $warning_flag) {
 1768 
 1769                         $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 1770                         write_labeled_message($err_message);
 1771                 }
 1772 
 1773                 return 1;
 1774         }
 1775 }
 1776 
 1777 sub describe {
 1778 
 1779         my $table_name=$_[0];
 1780     my $command=$_[1];
 1781 
 1782         my $sth = $dbh->prepare("$command $table_name");
 1783 
 1784         if ( !defined $sth ) {
 1785 
 1786                 $global_err="$DBI::errstr";
 1787                 return 0;
 1788         }
 1789 
 1790         $sth->execute;
 1791 
 1792         $descarray_describe=$sth->{NAME};
 1793 
 1794         $elem_describe=$sth->fetchall_arrayref;
 1795 
 1796         $sth->finish;
 1797 
 1798         return 1;
 1799 }
 1800 
 1801 sub qselect {
 1802 
 1803         my $select_string;
 1804 
 1805         $select_string=$_[0];
 1806 
 1807         my $sth = $dbh->prepare( "$select_string");
 1808 
 1809         if ( !defined $sth ) {
 1810 
 1811                 $global_err="$DBI::errstr";
 1812                 return 0;
 1813         }
 1814 
 1815         $sth->execute;
 1816 
 1817         $descarray=$sth->{NAME};
 1818 
 1819         $elem_select=$sth->fetchall_arrayref;
 1820 
 1821         $sth->finish;
 1822 
 1823         return 1;
 1824 }
 1825 
 1826 sub get_pri_key {
 1827 
 1828         my ($table_name,
 1829             $key_index,
 1830             $refbool,
 1831         $pri_key_string
 1832             );
 1833 
 1834     %HASH_pri_keys=();
 1835     @ARRAY_pri_keys=();
 1836         $table_name=$_[0];
 1837 
 1838         if ($mysql_specific) {
 1839 
 1840                 my $sth = $dbh->prepare("LISTFIELDS $table_name");
 1841 
 1842                 if ( !defined $sth ) {
 1843 
 1844                         $global_err="$DBI::errstr";
 1845                         return 0;
 1846                 }
 1847 
 1848                 $sth->execute;
 1849 
 1850                 $descarray=$sth->{'NAME'};
 1851 
 1852                 if ($recent_DBD_is_pri_key) {
 1853 
 1854                         $refbool=$sth->{'mysql_is_pri_key'};
 1855 
 1856                 } else {
 1857 
 1858                         $refbool=$sth->{'is_pri_key'};
 1859                 }
 1860 
 1861                 $sth->finish;
 1862 
 1863                 foreach $key_index (0..$#{$refbool}) {
 1864 
 1865                         if ($refbool->[$key_index] eq 1) {
 1866 
 1867                                 $HASH_pri_keys{$descarray->[$key_index]}=$key_index;
 1868                 $ARRAY_pri_keys[++$#ARRAY_pri_keys]=$descarray->[$key_index];
 1869                 $pri_key_string.=$descarray->[$key_index].$pri_key_delimiter;
 1870                         }
 1871                 }
 1872 
 1873         } else {
 1874 
 1875                 #I don't know how to implement this feature
 1876         }
 1877 
 1878     substr($pri_key_string,-length($pri_key_delimiter))='' if ($pri_key_string);
 1879         return $pri_key_string;
 1880 }
 1881 
 1882 sub prepare {
 1883 
 1884         my $table_name;
 1885 
 1886         $table_name=$_[0];
 1887 
 1888         if ($mysql_specific) {
 1889 
 1890                 my $sth = $dbh->prepare("LISTFIELDS $table_name");
 1891 
 1892                 if ( !defined $sth ) {
 1893 
 1894                         $global_err="$DBI::errstr";
 1895                         return 0;
 1896                 }
 1897 
 1898                 $sth->execute;
 1899 
 1900                 $descarray=$sth->{'NAME'};
 1901 
 1902                 $sth->finish;
 1903 
 1904         } else {
 1905 
 1906                 my $sth = $dbh->prepare("select * from $table_name");
 1907 
 1908                 if ( !defined $sth ) {
 1909 
 1910                         $global_err="$DBI::errstr";
 1911                         return 0;
 1912                 }
 1913 
 1914                 $sth->execute;
 1915 
 1916                 $descarray=$sth->{NAME};
 1917 
 1918                 $sth->finish;
 1919         }
 1920 
 1921         @{$PREPARE_NAMES{$table_name}}=@{$descarray};
 1922 
 1923         return 1;
 1924 }
 1925 
 1926 sub update_records {
 1927 
 1928         my ($set_string,
 1929             $where_string,
 1930             $update_string,
 1931             $table_name,
 1932             $key_name,
 1933             $number,
 1934             $field_name,
 1935             $field_value,
 1936             $warning_flag
 1937             );
 1938 
 1939         if (!lock_tables()) {return 0;}
 1940 
 1941         foreach $table_name (keys %CHECKED_ITEMS) {
 1942 
 1943                 foreach $key_name (keys %{$CHECKED_ITEMS{$table_name}}) {
 1944 
 1945                         foreach $number (keys %{$CHECKED_ITEMS{$table_name}{$key_name}}) {
 1946 
 1947                 $where_string='';
 1948                 my $tmp_pri_key_delimiter=quotemeta($pri_key_delimiter);
 1949                 my @pri_keys=split /$tmp_pri_key_delimiter/,$key_name;
 1950                 my @pri_keys_values=split /$tmp_pri_key_delimiter/,$CHECKED_ITEMS{$table_name}{$key_name}{$number};
 1951                 foreach (0..$#pri_keys) {
 1952 
 1953                             my $quoted_value=$pri_keys_values[$_];
 1954 
 1955                                         if ($quoted_value eq '') {
 1956 
 1957                                                 $quoted_value="''";
 1958 
 1959                                         } else {
 1960 
 1961                                     $quoted_value=$dbh->quote($quoted_value);
 1962                                         }
 1963 
 1964                     $where_string.="($pri_keys[$_] = $quoted_value) and ";
 1965                 }
 1966 
 1967                 substr($where_string,-5)='';
 1968 
 1969                 $where_string=' where ('.$where_string.')';
 1970 
 1971                                 $set_string='';
 1972 
 1973                                 foreach $field_name (keys %{$FIELD_VALUES{$table_name}{$number}}) {
 1974 
 1975                                         $field_value=$FIELD_VALUES{$table_name}{$number}{$field_name};
 1976 
 1977                                         if ($updaterecord_check) {
 1978 
 1979                                                 txt2html($field_value,'nobr');
 1980                                         }
 1981 
 1982                                         $field_value=$dbh->quote($field_value);
 1983 
 1984                                         $set_string.=$field_name.'='.$field_value.',';
 1985                                 }
 1986 
 1987                                 chop($set_string);
 1988 
 1989                                 $update_string='update '.$table_name.' set '.$set_string.' '.$where_string;
 1990 
 1991                                 my $sth = $dbh->do("$update_string");
 1992 
 1993                                 if ( !defined $sth ) {
 1994 
 1995                                         $global_err="$DBI::errstr";
 1996                                         return 0;
 1997 
 1998                                 } elsif ($sth eq "0E0") {
 1999 
 2000                                         $warning_flag=1;
 2001                                 }
 2002                         }
 2003                 }
 2004         }
 2005 
 2006         if (!unlock_tables()) {
 2007 
 2008                 return 0;
 2009 
 2010         } else {
 2011 
 2012                 if ($wrng_enabled_4_update and $warning_flag) {
 2013 
 2014                         my $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 2015                         write_labeled_message($err_message);
 2016                 }
 2017 
 2018                 return 1;
 2019         }
 2020 }
 2021 
 2022 sub insert_records {
 2023 
 2024         my ($table_name,
 2025             $field_name,
 2026             $field_value,
 2027             $number,
 2028             $names_string,
 2029             $values_string,
 2030             $insert_string,
 2031             $warning_flag,
 2032             $err_message
 2033             );
 2034 
 2035         if (!lock_tables()) {return 0;}
 2036 
 2037         foreach $table_name (keys %FIELD_VALUES) {
 2038 
 2039                 foreach $number (sort numerically keys %{$FIELD_VALUES{$table_name}}) {
 2040 
 2041                         $names_string='';
 2042                         $values_string='';
 2043 
 2044                         foreach $field_name (keys %{$FIELD_VALUES{$table_name}{$number}}) {
 2045 
 2046                                 $field_value=$FIELD_VALUES{$table_name}{$number}{$field_name};
 2047 
 2048                                 if ($insertrecord_check) {
 2049 
 2050                                         txt2html($field_value,'nobr');
 2051                                 }
 2052 
 2053                                 $field_value=$dbh->quote($field_value);
 2054 
 2055                                 $names_string.=$field_name.',';
 2056                                 $values_string.=$field_value.',';
 2057                         }
 2058 
 2059                         chop($names_string);
 2060                         chop($values_string);
 2061 
 2062                         $insert_string='insert into '.$table_name.' ('.$names_string.') VALUES ('.$values_string.')';
 2063 
 2064                         my $sth = $dbh->do("$insert_string");
 2065 
 2066                         if ( !defined $sth ) {
 2067 
 2068                                 $global_err="$DBI::errstr";
 2069                                 return 0;
 2070 
 2071                         } elsif ($sth eq "0E0") {
 2072 
 2073                                 $warning_flag=1;
 2074                         }
 2075                 }
 2076         }
 2077 
 2078         if (!unlock_tables()) {
 2079 
 2080                 return 0;
 2081 
 2082         } else {
 2083 
 2084                 if ($wrng_enabled_4_insert and $warning_flag) {
 2085 
 2086                         $err_message=qq{<b>$err_warning_word</b>: $err_0_rows_happened};
 2087                         write_labeled_message($err_message);
 2088                 }
 2089 
 2090                 return 1;
 2091         }
 2092 }
 2093 
 2094 sub lock_tables {
 2095 
 2096         my ($table_name_list,
 2097             $table_name,
 2098             $lock_string
 2099            );
 2100 
 2101         $table_name_list='';
 2102 
 2103         foreach $table_name (keys %CHECKED_TABLES) {
 2104 
 2105                 $table_name_list.=$table_name.' WRITE ,';
 2106         }
 2107 
 2108         chop ($table_name_list);
 2109 
 2110         $lock_string='LOCK TABLES '.$table_name_list;
 2111 
 2112         if (!defined $dbh->do("$lock_string")) {
 2113 
 2114                 $global_err="$DBI::errstr";
 2115                 return 0;
 2116 
 2117         } else {
 2118 
 2119                 return 1;
 2120         }
 2121 }
 2122 
 2123 sub unlock_tables {
 2124 
 2125         if (!defined $dbh->do("UNLOCK TABLES")) {
 2126 
 2127                 $global_err="$DBI::errstr";
 2128                 return 0;
 2129 
 2130         } else {
 2131 
 2132                 return 1;
 2133         }
 2134 }
 2135 
 2136 sub list_tables {
 2137 
 2138         if ($mysql_specific) {
 2139 
 2140         if (!$obsolete_DBD_ListTables) {
 2141 
 2142                     @tables_names = $dbh->tables();
 2143 
 2144         } else {
 2145 
 2146                     @tables_names = $dbh->func("_ListTables");
 2147         }
 2148 
 2149         #DBD::mysql 2.9x workaround
 2150         tr/`//d foreach @tables_names;
 2151 
 2152         } else {
 2153 
 2154                 @tables_names = $dbh->tables();
 2155         }
 2156 
 2157         return @tables_names+0;
 2158 }
 2159 
 2160 sub perform_fquery {
 2161 
 2162     $CGI_INPUT{'fquery_textarea'}=~s/\n//g;
 2163     $CGI_INPUT{'fquery_textarea'}=~s/\r//g;
 2164     $CGI_INPUT{'fquery_textarea'}=txt2html($CGI_INPUT{'fquery_textarea'},'nobr');
 2165 
 2166         my $sth = $dbh->prepare("$CGI_INPUT{'fquery_textarea'}");
 2167 
 2168         if ( !defined $sth ) {
 2169 
 2170                 $global_err="$DBI::errstr";
 2171                 return 0;
 2172         }
 2173 
 2174         my $rv=$sth->execute;
 2175 
 2176         if ( !defined $rv ) {
 2177 
 2178             $global_err="$DBI::errstr";
 2179                 return 0;
 2180 
 2181     } else { #also with $rv eq "0E0"
 2182 
 2183         $fquery_output='';
 2184 
 2185             $descarray_describe=$sth->{NAME};
 2186             $elem_describe=$sth->fetchall_arrayref;
 2187     }
 2188 
 2189     $sth->finish;
 2190 
 2191     return 1;
 2192 }
 2193 
 2194 #===============================================
 2195 #       get_action_info subroutines
 2196 #===============================================
 2197 
 2198 sub get_action_info {
 2199 
 2200         $flag_ok=1;
 2201 
 2202         if ($create_enabled and $CGI_INPUT{create} and !$CGI_INPUT{'new_fields'}) {
 2203 
 2204                 write_labeled_message("<b>$err_error_word:</b> $err_0_fields");
 2205                 $CGI_INPUT{create}=0;
 2206                 $flag_ok=0;
 2207         }
 2208 
 2209         if ($create_enabled and $CGI_INPUT{createok}) {
 2210 
 2211                 if (verify_create_checks()) {
 2212 
 2213                         if ($create_check) {
 2214 
 2215                                 print qq{
 2216                                         <div align="center"><form action="$thiscgi" method="post">
 2217                                         <input type="hidden" name="current_user" value="$current_user">
 2218                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2219                                         };
 2220 
 2221                 if (!$custom_configuration) {
 2222 
 2223                     print qq{
 2224                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2225                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2226                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2227                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2228                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2229                         <input type="hidden" name="current_db" value="#">
 2230                         };
 2231 
 2232                 } else {
 2233 
 2234                     print qq{
 2235                         <input type="hidden" name="current_db" value="$current_db">
 2236                         };
 2237                 }
 2238 
 2239                                 write_labeled_message("$ask_create_table");
 2240 
 2241                                 put_hidden_values_4_create();
 2242 
 2243                                 print qq{
 2244                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2245                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="createcheck" value="$button_proceed">
 2246                                         </font>
 2247                                         </form></div>
 2248                                         };
 2249 
 2250                                 $flag_ok=0;
 2251 
 2252                         } else {
 2253 
 2254                                 $CGI_INPUT{createcheck}=1;
 2255                                 $flag_ok=1;
 2256                         }
 2257                 }
 2258         }
 2259 
 2260         if ($table_csv_exp_enabled and $CGI_INPUT{table_csv_exp}) {
 2261 
 2262                 if (get_checked_tables()) {
 2263 
 2264                         if (!$CGI_INPUT{table_csv_expok}) {
 2265 
 2266                                 print qq{
 2267                                         <div align="center"><form action="$thiscgi" method="post">
 2268                                         <input type="hidden" name="current_user" value="$current_user">
 2269                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2270                                         };
 2271 
 2272                 if (!$custom_configuration) {
 2273 
 2274                     print qq{
 2275                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2276                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2277                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2278                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2279                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2280                         <input type="hidden" name="current_db" value="#">
 2281                         };
 2282 
 2283                 } else {
 2284 
 2285                     print qq{
 2286                         <input type="hidden" name="current_db" value="$current_db">
 2287                         };
 2288                 }
 2289 
 2290                                 my $message="$ask_table_backup:";
 2291 
 2292                                 foreach my $table_name (keys %CHECKED_TABLES) {
 2293 
 2294                                         $message.="<LI>$table_name</LI>";
 2295 
 2296                                         my $tmp_name='checked_table'.$delimiter.$table_name;
 2297                                         my $tmp_value=$table_name;
 2298                                         print qq{<input type="hidden" name="$tmp_name" value="$tmp_value">\n};
 2299                                 }
 2300 
 2301                                 write_labeled_message($message);
 2302 
 2303                     write_labeled_message($ask_csv_separator);
 2304 
 2305                         print qq{
 2306                                 <table align="center" border="0" cellpadding="1" cellspacing="0">
 2307                                 <tr>
 2308                                 <td bgcolor="#000000">
 2309                                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 2310                                 <tr>
 2311                                 <td>
 2312                                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 2313                                 <tr>
 2314                                 <td>
 2315                                 };
 2316 
 2317                     print qq{
 2318                     <table cellspacing="2" cellpadding="2">
 2319                             <tr><td>
 2320                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2321                         <input type="text" name="csv_exp_separator" value="$csv_separator_default" size="1" maxlength="1">
 2322                         </font>
 2323                     </td></tr>
 2324                             </table>
 2325                             };
 2326 
 2327                         print q{
 2328                                 </table>
 2329                                 </td>
 2330                                 </tr>
 2331                                 </table>
 2332                                 </td>
 2333                                 </tr>
 2334                                 </table>
 2335                                 <br>
 2336                                 };
 2337 
 2338                                 print qq{
 2339                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2340                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="table_csv_expok" value="$button_proceed">
 2341                                         </font>
 2342                                         </form></div>
 2343                                         };
 2344 
 2345                         } else {
 2346 
 2347                                 $flag_ok=1;
 2348                         }
 2349 
 2350                 } else {
 2351 
 2352                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2353                         $flag_ok=0;
 2354                 }
 2355         }
 2356 
 2357         if ($table_backup_enabled and $CGI_INPUT{table_backup}) {
 2358 
 2359                 if (get_checked_tables()) {
 2360 
 2361                         if (!$CGI_INPUT{table_backupok}) {
 2362 
 2363                                 print qq{
 2364                                         <div align="center"><form action="$thiscgi" method="post">
 2365                                         <input type="hidden" name="current_user" value="$current_user">
 2366                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2367                                         };
 2368 
 2369                 if (!$custom_configuration) {
 2370 
 2371                     print qq{
 2372                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2373                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2374                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2375                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2376                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2377                         <input type="hidden" name="current_db" value="#">
 2378                         };
 2379 
 2380                 } else {
 2381 
 2382                     print qq{
 2383                         <input type="hidden" name="current_db" value="$current_db">
 2384                         };
 2385                 }
 2386 
 2387                                 my $message="$ask_table_backup:";
 2388 
 2389                                 foreach my $table_name (keys %CHECKED_TABLES) {
 2390 
 2391                                         $message.="<LI>$table_name</LI>";
 2392 
 2393                                         my $tmp_name='checked_table'.$delimiter.$table_name;
 2394                                         my $tmp_value=$table_name;
 2395                                         print qq{<input type="hidden" name="$tmp_name" value="$tmp_value">\n};
 2396                                 }
 2397 
 2398                                 write_labeled_message($message);
 2399 
 2400                     write_labeled_message($ask_backup_type);
 2401 
 2402                         print qq{
 2403                                 <table align="center" border="0" cellpadding="1" cellspacing="0">
 2404                                 <tr>
 2405                                 <td bgcolor="#000000">
 2406                                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 2407                                 <tr>
 2408                                 <td>
 2409                                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 2410                                 <tr>
 2411                                 <td>
 2412                                 };
 2413 
 2414                     print qq{
 2415                     <table cellspacing="2" cellpadding="2">
 2416                             <tr><td>
 2417                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2418                         <input type="radio" name="backup_type" value="with" checked>$radio_db_backup_witht
 2419                         <table>
 2420                             <tr>
 2421                             <td>&nbsp;</td>
 2422                             <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2423                             <input type="checkbox" name="with_lock" value="1">$lock_table_backup</font></td>
 2424                             </tr>
 2425                             <tr>
 2426                             <td>&nbsp;</td>
 2427                             <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2428                             <input type="checkbox" name="with_drop" value="1">$drop_table_backup</font></td>
 2429                             </tr>
 2430                         </table>
 2431                         </font>
 2432                     </td></tr>
 2433                     <tr><td>
 2434                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2435                         <input type="radio" name="backup_type" value="without">$radio_db_backup_withot
 2436                         <table>
 2437                             <tr>
 2438                             <td>&nbsp;</td>
 2439                             <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2440                             <input type="checkbox" name="without_lock" value="1">$lock_table_backup</font></td>
 2441                             </tr>
 2442                         </table>
 2443                         </font>
 2444                     </td></tr>
 2445                     <tr><td>
 2446                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2447                         <input type="radio" name="backup_type" value="struct">$radio_db_backup_struct
 2448                         <table>
 2449                             <tr>
 2450                             <td>&nbsp;</td>
 2451                             <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2452                             <input type="checkbox" name="struct_drop" value="1">$drop_table_backup</font></td>
 2453                             </tr>
 2454                         </table>
 2455                         </font>
 2456                     </td></tr>
 2457                             </table>
 2458                             };
 2459 
 2460                         print q{
 2461                                 </table>
 2462                                 </td>
 2463                                 </tr>
 2464                                 </table>
 2465                                 </td>
 2466                                 </tr>
 2467                                 </table>
 2468                                 <br>
 2469                                 };
 2470 
 2471                                 print qq{
 2472                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2473                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="table_backupok" value="$button_proceed">
 2474                                         </font>
 2475                                         </form></div>
 2476                                         };
 2477 
 2478                         } else {
 2479 
 2480                                 $flag_ok=1;
 2481                         }
 2482 
 2483                 } else {
 2484 
 2485                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2486                         $flag_ok=0;
 2487                 }
 2488         }
 2489 
 2490         if ($drop_enabled and $CGI_INPUT{drop}) {
 2491 
 2492                 if (get_checked_tables()) {
 2493 
 2494                         if ($drop_check) {
 2495 
 2496                                 print qq{
 2497                                         <div align="center"><form action="$thiscgi" method="post">
 2498                                         <input type="hidden" name="current_user" value="$current_user">
 2499                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2500                                         };
 2501 
 2502                 if (!$custom_configuration) {
 2503 
 2504                     print qq{
 2505                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2506                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2507                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2508                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2509                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2510                         <input type="hidden" name="current_db" value="#">
 2511                         };
 2512 
 2513                 } else {
 2514 
 2515                     print qq{
 2516                         <input type="hidden" name="current_db" value="$current_db">
 2517                         };
 2518                 }
 2519 
 2520                                 my $message="$ask_drop_tables:";
 2521 
 2522                                 foreach my $table_name (keys %CHECKED_TABLES) {
 2523 
 2524                                         $message.="<LI>$table_name</LI>";
 2525 
 2526                                         my $tmp_name='checked_table'.$delimiter.$table_name;
 2527                                         my $tmp_value=$table_name;
 2528                                         print qq{<input type="hidden" name="$tmp_name" value="$tmp_value">\n};
 2529                                 }
 2530 
 2531                                 write_labeled_message($message);
 2532 
 2533                                 print qq{
 2534                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2535                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="dropok" value="$button_proceed">
 2536                                         </font>
 2537                                         </form></div>
 2538                                         };
 2539 
 2540                         } else {
 2541 
 2542                                 $CGI_INPUT{dropok}=1;
 2543                                 $flag_ok=1;
 2544                         }
 2545 
 2546                 } else {
 2547 
 2548                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2549                         $flag_ok=0;
 2550                 }
 2551         }
 2552 
 2553         if ($erase_enabled and $CGI_INPUT{erase}) {
 2554 
 2555                 if (get_checked_tables()) {
 2556 
 2557                         if ($erase_check) {
 2558 
 2559                                 print qq{
 2560                                         <div align="center"><form action="$thiscgi" method="post">
 2561                                         <input type="hidden" name="current_user" value="$current_user">
 2562                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2563                                         };
 2564 
 2565                 if (!$custom_configuration) {
 2566 
 2567                     print qq{
 2568                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2569                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2570                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2571                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2572                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2573                         <input type="hidden" name="current_db" value="#">
 2574                         };
 2575 
 2576                 } else {
 2577 
 2578                     print qq{
 2579                         <input type="hidden" name="current_db" value="$current_db">
 2580                         };
 2581                 }
 2582 
 2583                                 my $message="$ask_erase_tables:";
 2584 
 2585                                 foreach my $table_name (keys %CHECKED_TABLES) {
 2586 
 2587                                         $message.="<LI>$table_name</LI>";
 2588 
 2589                                         my $tmp_name='checked_table'.$delimiter.$table_name;
 2590                                         my $tmp_value=$table_name;
 2591                                         print qq{<input type="hidden" name="$tmp_name" value="$tmp_value">\n};
 2592                                 }
 2593 
 2594                                 write_labeled_message($message);
 2595 
 2596                                 print qq{
 2597                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2598                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="eraseok" value="$button_proceed">
 2599                                         </font>
 2600                                         </form></div>
 2601                                         };
 2602 
 2603                         } else {
 2604 
 2605                                 $CGI_INPUT{eraseok}=1;
 2606                                 $flag_ok=1;
 2607                         }
 2608 
 2609                 } else {
 2610 
 2611                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2612                         $flag_ok=0;
 2613                 }
 2614         }
 2615 
 2616         if ($delete_enabled and $CGI_INPUT{delete}) {
 2617 
 2618                 if (verify_checks()) {
 2619 
 2620                         if ($delete_check) {
 2621 
 2622                                 print qq{
 2623                                         <div align="center"><form action="$thiscgi" method="post">
 2624                                         <input type="hidden" name="current_user" value="$current_user">
 2625                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2626                                         };
 2627 
 2628                 if (!$custom_configuration) {
 2629 
 2630                     print qq{
 2631                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2632                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2633                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2634                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2635                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2636                         <input type="hidden" name="current_db" value="#">
 2637                         };
 2638 
 2639                 } else {
 2640 
 2641                     print qq{
 2642                         <input type="hidden" name="current_db" value="$current_db">
 2643                         };
 2644                 }
 2645 
 2646                                 write_labeled_message("$ask_delete_records");
 2647                                 put_hidden_values();
 2648 
 2649                                 print qq{
 2650                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2651                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="deleteok" value="$button_proceed">
 2652                                         </font>
 2653                                         </form></div>
 2654                                         };
 2655 
 2656                                 $flag_ok=0;
 2657 
 2658                         } else {
 2659 
 2660                                 $CGI_INPUT{deleteok}=1;
 2661                                 $flag_ok=1;
 2662                         }
 2663                 }
 2664         }
 2665 
 2666         if (($describe_enabled and $CGI_INPUT{describe}) or ($showindex_enabled and $CGI_INPUT{showindex})) {
 2667 
 2668                 if (!(get_checked_tables())) {
 2669 
 2670                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2671                         $flag_ok=0;
 2672                 }
 2673         }
 2674 
 2675         if ($select_enabled and $CGI_INPUT{select}) {
 2676 
 2677                 get_field_names();
 2678                 get_select_params();
 2679 
 2680                 if (!(get_checked_tables())) {
 2681 
 2682                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2683                         $flag_ok=0;
 2684                 }
 2685 
 2686                 if ($selectfields_enabled and $CGI_INPUT{withselectfields}) {
 2687 
 2688                         if (!verify_checks_lite()) {
 2689 
 2690                                 $flag_ok=0;
 2691                         }
 2692                 }
 2693         }
 2694 
 2695         if ($new_enabled and $CGI_INPUT{new}) {
 2696 
 2697                 if (!$CGI_INPUT{'new_elem'}) {
 2698 
 2699                         write_labeled_message("<b>$err_error_word:</b> $err_0_new_records");
 2700                         $flag_ok=0;
 2701                 }
 2702 
 2703                 if (!(get_checked_tables())) {
 2704 
 2705                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2706                         $flag_ok=0;
 2707                 }
 2708         }
 2709 
 2710         if ($prepare_enabled and $CGI_INPUT{prepare}) {
 2711 
 2712                 if (!(get_checked_tables())) {
 2713 
 2714                         write_labeled_message("<b>$err_error_word:</b> $err_no_checked_tables");
 2715                         $flag_ok=0;
 2716                 }
 2717         }
 2718 
 2719         if ($selectfields_enabled and $CGI_INPUT{selectfields}) {
 2720 
 2721                 if (verify_checks()) {
 2722 
 2723                         get_select_params();
 2724 
 2725                 } else {
 2726 
 2727                         $flag_ok=0;
 2728                 }
 2729         }
 2730 
 2731         if ($edititem_enabled and $CGI_INPUT{edititem}) {
 2732 
 2733                 if (!verify_checks()) {
 2734 
 2735                         $flag_ok=0;
 2736                 }
 2737         }
 2738 
 2739         if ($insertrecord_enabled and $CGI_INPUT{insertrecord}) {
 2740 
 2741                 if (verify_checks()) {
 2742 
 2743                         get_field_values();
 2744                         if ($insertrecord_check) {
 2745 
 2746                                 print qq{
 2747                                         <div align="center"><form action="$thiscgi" method="post">
 2748                                         <input type="hidden" name="current_user" value="$current_user">
 2749                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2750                                         };
 2751 
 2752                 if (!$custom_configuration) {
 2753 
 2754                     print qq{
 2755                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2756                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2757                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2758                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2759                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2760                         <input type="hidden" name="current_db" value="#">
 2761                         };
 2762 
 2763                 } else {
 2764 
 2765                     print qq{
 2766                         <input type="hidden" name="current_db" value="$current_db">
 2767                         };
 2768                 }
 2769 
 2770                                 write_labeled_message("$ask_insert_records");
 2771 
 2772                                 put_hidden_values();
 2773 
 2774                                 print qq{
 2775                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2776                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="insertok" value="$button_proceed">
 2777                                         </font>
 2778                                         </form></div>
 2779                                         };
 2780 
 2781                                 $flag_ok=0;
 2782 
 2783                         } else {
 2784 
 2785                                 $CGI_INPUT{insertok}=1;
 2786                                 $flag_ok=1;
 2787                         }
 2788                 }
 2789         }
 2790 
 2791         if ($fquery_enabled and $CGI_INPUT{fquery}) {
 2792 
 2793                 if ($fquery_check) {
 2794 
 2795                         print qq{
 2796                                 <div align="center"><form action="$thiscgi" method="post">
 2797                                 <input type="hidden" name="current_user" value="$current_user">
 2798                                 <input type="hidden" name="current_pwd" value="$current_pwd">
 2799                                 };
 2800 
 2801             if (!$custom_configuration) {
 2802 
 2803                 print qq{
 2804                                 <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2805                             <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2806                                 <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2807                             <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2808                             <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2809                     <input type="hidden" name="current_db" value="#">
 2810                     };
 2811 
 2812             } else {
 2813 
 2814                 print qq{
 2815                     <input type="hidden" name="current_db" value="$current_db">
 2816                     };
 2817             }
 2818 
 2819             $CGI_INPUT{'fquery_textarea'}=html2txt($CGI_INPUT{'fquery_textarea'},'nobr');
 2820 
 2821                         print qq{
 2822                                 <input type="hidden" name="fquery_textarea" value="$CGI_INPUT{'fquery_textarea'}">
 2823                                 };
 2824 
 2825                         write_labeled_message("$ask_fquery");
 2826 
 2827                         print qq{
 2828                                 <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2829                                 <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="fqueryok" value="$button_proceed">
 2830                                 </font>
 2831                                 </form></div>
 2832                                 };
 2833 
 2834                         $flag_ok=0;
 2835 
 2836                 } else {
 2837 
 2838                         $CGI_INPUT{fqueryok}=1;
 2839                         $flag_ok=1;
 2840                 }
 2841 
 2842     }
 2843 
 2844         if ($updaterecord_enabled and $CGI_INPUT{updaterecord}) {
 2845 
 2846                 if (verify_checks()) {
 2847 
 2848                         get_field_values();
 2849 
 2850                         if ($updaterecord_check) {
 2851 
 2852                                 print qq{
 2853                                         <div align="center"><form action="$thiscgi" method="post">
 2854                                         <input type="hidden" name="current_user" value="$current_user">
 2855                                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2856                                         };
 2857 
 2858                 if (!$custom_configuration) {
 2859 
 2860                     print qq{
 2861                                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2862                                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2863                                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2864                                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2865                                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2866                         <input type="hidden" name="current_db" value="#">
 2867                         };
 2868 
 2869                 } else {
 2870 
 2871                     print qq{
 2872                         <input type="hidden" name="current_db" value="$current_db">
 2873                         };
 2874                 }
 2875 
 2876                                 write_labeled_message("$ask_update_records");
 2877 
 2878                                 put_hidden_values();
 2879 
 2880                                 print qq{
 2881                                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2882                                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="updateok" value="$button_proceed">
 2883                                         </font>
 2884                                         </form></div>
 2885                                         };
 2886 
 2887                                 $flag_ok=0;
 2888 
 2889                         } else {
 2890 
 2891                                 $CGI_INPUT{updateok}=1;
 2892                                 $flag_ok=1;
 2893                         }
 2894                 }
 2895         }
 2896 
 2897         if ($db_csv_exp_enabled and $CGI_INPUT{db_csv_exp}) {
 2898 
 2899                 print qq{
 2900                         <div align="center"><form action="$thiscgi" method="post">
 2901                         <input type="hidden" name="current_user" value="$current_user">
 2902                         <input type="hidden" name="current_pwd" value="$current_pwd">
 2903                         };
 2904 
 2905         if (!$custom_configuration) {
 2906 
 2907             print qq{
 2908                         <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2909                         <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2910                         <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2911                         <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2912                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2913                 <input type="hidden" name="current_db" value="#">
 2914                 };
 2915 
 2916         } else {
 2917 
 2918             print qq{
 2919                 <input type="hidden" name="current_db" value="$current_db">
 2920                 };
 2921         }
 2922 
 2923             write_labeled_message($ask_csv_separator);
 2924 
 2925                 print qq{
 2926                         <table align="center" border="0" cellpadding="1" cellspacing="0">
 2927                         <tr>
 2928                         <td bgcolor="#000000">
 2929                         <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 2930                         <tr>
 2931                         <td>
 2932                         <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 2933                         <tr>
 2934                         <td>
 2935                         };
 2936 
 2937             print qq{
 2938             <table cellspacing="2" cellpadding="2">
 2939                     <tr><td>
 2940                 <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2941                 <input type="text" name="csv_exp_separator" value="$csv_separator_default" size="1" maxlength="1">
 2942                 </font>
 2943             </td></tr>
 2944                     </table>
 2945                     };
 2946 
 2947                 print q{
 2948                         </table>
 2949                         </td>
 2950                         </tr>
 2951                         </table>
 2952                         </td>
 2953                         </tr>
 2954                         </table>
 2955                         <br>
 2956                 };
 2957 
 2958                 print qq{
 2959                         <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 2960                         <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="db_csv_expok" value="$button_proceed">
 2961                         </font>
 2962                         </form></div>
 2963                         };
 2964 
 2965                 $flag_ok=1;
 2966         }
 2967 
 2968     if ($db_backup_enabled and $CGI_INPUT{db_backup}) {
 2969 
 2970             print qq{
 2971                     <div align="center"><form action="$thiscgi" method="post">
 2972                     <input type="hidden" name="current_user" value="$current_user">
 2973                     <input type="hidden" name="current_pwd" value="$current_pwd">
 2974                     };
 2975 
 2976         if (!$custom_configuration) {
 2977 
 2978             print qq{
 2979                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 2980                     <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 2981                         <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 2982                     <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 2983                     <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 2984                 <input type="hidden" name="current_db" value="#">
 2985                 };
 2986 
 2987         } else {
 2988 
 2989             print qq{
 2990                 <input type="hidden" name="current_db" value="$current_db">
 2991                 };
 2992         }
 2993 
 2994             write_labeled_message("$ask_backup_type");
 2995 
 2996                 print qq{
 2997                         <table align="center" border="0" cellpadding="1" cellspacing="0">
 2998                         <tr>
 2999                         <td bgcolor="#000000">
 3000                         <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 3001                         <tr>
 3002                         <td>
 3003                         <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 3004                         <tr>
 3005                         <td>
 3006                         };
 3007 
 3008             print qq{
 3009             <table cellspacing="2" cellpadding="2">
 3010                     <tr><td>
 3011                 <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3012                 <input type="radio" name="backup_type" value="with" checked>$radio_db_backup_witht
 3013                 <table>
 3014                     <tr>
 3015                     <td>&nbsp;</td>
 3016                     <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3017                     <input type="checkbox" name="with_lock" value="1">$lock_table_backup</font></td>
 3018                     </tr>
 3019                     <tr>
 3020                     <td>&nbsp;</td>
 3021                     <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3022                     <input type="checkbox" name="with_drop" value="1">$drop_table_backup</font></td>
 3023                     </tr>
 3024                 </table>
 3025                 </font>
 3026             </td></tr>
 3027             <tr><td>
 3028                 <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3029                 <input type="radio" name="backup_type" value="without">$radio_db_backup_withot
 3030                 <table>
 3031                     <tr>
 3032                     <td>&nbsp;</td>
 3033                     <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3034                     <input type="checkbox" name="without_lock" value="1">$lock_table_backup</font></td>
 3035                     </tr>
 3036                 </table>
 3037                 </font>
 3038             </td></tr>
 3039             <tr><td>
 3040                 <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3041                 <input type="radio" name="backup_type" value="struct">$radio_db_backup_struct
 3042                 <table>
 3043                     <tr>
 3044                     <td>&nbsp;</td>
 3045                     <td><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3046                     <input type="checkbox" name="struct_drop" value="1">$drop_table_backup</font></td>
 3047                     </tr>
 3048                 </table>
 3049                 </font>
 3050             </td></tr>
 3051                     </table>
 3052                     };
 3053 
 3054                 print q{
 3055             </td></tr>
 3056                         </table>
 3057                         </td>
 3058                         </tr>
 3059                         </table>
 3060                         </td>
 3061                         </tr>
 3062                         </table>
 3063                         <br>
 3064                         };
 3065 
 3066             put_hidden_values();
 3067 
 3068             print qq{
 3069                     <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 3070                     <input type="submit" name="refresh" value="$button_discard"><input type="submit" name="db_backupok" value="$button_proceed">
 3071                     </font>
 3072                     </form></div>
 3073                     };
 3074 
 3075             $flag_ok=0;
 3076     }
 3077 }
 3078 
 3079 sub put_hidden_values {
 3080 
 3081         my ($table_name,
 3082             $num,
 3083             $prim_key,
 3084             $tmp_name,
 3085             $tmp_value,
 3086             $field_name
 3087             );
 3088 
 3089         foreach $table_name (keys %CHECKED_ITEMS) {
 3090 
 3091                 $tmp_name='checked_table'.$delimiter.$table_name;
 3092                 $tmp_value=$table_name;
 3093                 print qq{
 3094                         <input type="hidden" name="$tmp_name" value="$tmp_value">
 3095                         };
 3096 
 3097                 foreach $prim_key (keys %{$CHECKED_ITEMS{$table_name}}) {
 3098 
 3099                         foreach $num (sort numerically keys %{$CHECKED_ITEMS{$table_name}{$prim_key}}) {
 3100 
 3101                                 $tmp_value=$CHECKED_ITEMS{$table_name}{$prim_key}{$num};
 3102                                 $tmp_name='checked_item'.$delimiter.$table_name.$delimiter.$prim_key.$delimiter.$num;
 3103 
 3104                                 print qq{
 3105                                         <input type="hidden" name="$tmp_name" value="$tmp_value">
 3106                                         };
 3107 
 3108                                 foreach $field_name (keys %{$FIELD_VALUES{$table_name}{$num}}) {
 3109 
 3110                                         $tmp_value=$FIELD_VALUES{$table_name}{$num}{$field_name};
 3111                                         $tmp_value=html2txt($tmp_value,'nobr');
 3112                     $tmp_value=~s/\r//g;
 3113                                         $tmp_name='field_value'.$delimiter.$num.$delimiter.$table_name.$delimiter.$field_name;
 3114                                         print qq{
 3115                                                 <input type="hidden" name="$tmp_name" value="$tmp_value">
 3116                                                 };
 3117                                 }
 3118                         }
 3119                 }
 3120         }
 3121 }
 3122 
 3123 sub put_hidden_values_4_create {
 3124 
 3125         my ($tmp_name,
 3126             $tmp_value,
 3127             $type,
 3128             $checked
 3129             );
 3130 
 3131         $tmp_name='table_name';
 3132         $tmp_value=$CGI_INPUT{'table_name'};
 3133 
 3134         print qq{
 3135                 <input type="hidden" name="$tmp_name" value="$tmp_value">
 3136                 };
 3137 
 3138         foreach $type (keys %FIELD_NAMES) {
 3139 
 3140                 foreach $checked (keys %{$FIELD_NAMES{$type}}) {
 3141 
 3142                         $tmp_name='field_name'.$delimiter.$type.$delimiter.$checked;
 3143                         $tmp_value=$FIELD_NAMES{$type}{$checked};
 3144 
 3145                         print qq{
 3146                                 <input type="hidden" name="$tmp_name" value="$tmp_value">
 3147                                 };
 3148                 }
 3149         }
 3150 }
 3151 
 3152 sub verify_create_names {
 3153 
 3154         my $name=$_[0];
 3155         my ($err_string,
 3156             $character,
 3157             $metacharacter
 3158             );
 3159 
 3160         if ($name =~ / /) {
 3161 
 3162                 $err_string="$err_space_character $err_not_allowed";
 3163                 return $err_string;
 3164         }
 3165 
 3166         foreach $character (@characters_not_allowed) {
 3167 
 3168                 $metacharacter=quotemeta($character);
 3169 
 3170                 if ($name =~ /$metacharacter/) {
 3171 
 3172                         $err_string="$character $err_not_allowed";
 3173                         return $err_string;
 3174                 }
 3175         }
 3176 
 3177         if ($name !~ /[^\d]/) {
 3178 
 3179                 $err_string="$err_name_not_number";
 3180                 return $err_string;
 3181         }
 3182 
 3183         return '';
 3184 }
 3185 
 3186 sub verify_create_checks {
 3187 
 3188         my ($flag_err,
 3189             $err_string,
 3190             $err_string_name,
 3191             $extrn,
 3192             $intrn,
 3193             $message,
 3194             $message_required_specifier,
 3195             @create_checked_items,
 3196             $checked,
 3197             $property,
 3198             $required_specifier
 3199             );
 3200 
 3201         $flag_err=0;
 3202 
 3203         get_field_names();
 3204 
 3205         if (!$CGI_INPUT{'table_name'}) {
 3206 
 3207                 $err_string.='<br>'.$err_no_table_name;
 3208                 $flag_err=1;
 3209         }
 3210 
 3211         if (!$flag_err) {
 3212 
 3213                 $err_string_name=verify_create_names($CGI_INPUT{'table_name'});
 3214 
 3215                 if ($err_string_name) {
 3216 
 3217                         $err_string.='<br>'."$err_string_name $err_in_table_name";
 3218                         $flag_err=1;
 3219                 }
 3220         }
 3221 
 3222         get_fields_types();
 3223 
 3224         foreach $checked (sort numerically keys %{$FIELD_NAMES{'checked_item'}}) {
 3225 
 3226                 $create_checked_items[++$#create_checked_items]=$checked;
 3227 
 3228                 if ($FIELD_NAMES{'field_name'}{$checked} eq '') {
 3229 
 3230                         $err_string.='<br>'."$err_no_field_name : $err_field $checked";
 3231                         $flag_err=1;
 3232 
 3233                 } else {
 3234 
 3235                         $err_string_name=verify_create_names($FIELD_NAMES{'field_name'}{$checked});
 3236 
 3237                         if ($err_string_name) {
 3238 
 3239                                 $err_string.='<br>'."$err_string_name $err_in_field_name : $err_field $checked";
 3240                                 $flag_err=1;
 3241                         }
 3242                 }
 3243 
 3244                 my $type=$FIELD_NAMES{'field_type'}{$checked};
 3245 
 3246                 foreach my $specifier (keys %SPECIFIERS_ORDER) {
 3247 
 3248                         if ($FIELD_NAMES{$specifier}{$checked} ne '') {
 3249 
 3250                                 ($property,$required_specifier)=split /\+/ , $FIELDS_TYPES{$type}{$specifier};
 3251 
 3252                                 if ($required_specifier) {
 3253 
 3254                                         $message_required_specifier=$SPECIFIERS_MESSAGES{$required_specifier};
 3255                                         $message=$SPECIFIERS_MESSAGES{$specifier};
 3256 
 3257                                         if ($FIELD_NAMES{$required_specifier}{$checked} eq '') {
 3258                                                 $err_string.='<br>'."$message_required_specifier $err_required $err_with $message $err_for_type $type : $err_field $checked";
 3259                                                 $flag_err=1;
 3260                                         }
 3261                                 }
 3262 
 3263                                 if ($FIELDS_TYPES{$type}{$specifier} eq '-1') {
 3264 
 3265                                         $message=$SPECIFIERS_MESSAGES{$specifier};
 3266 
 3267                                         $err_string.='<br>'."$message $err_not_allowed $err_for_type $type : $err_field $checked";
 3268                                         $flag_err=1;
 3269                                 }
 3270 
 3271                         } else {
 3272 
 3273                                 if ($FIELDS_TYPES{$type}{$specifier} eq '1') {
 3274 
 3275                                         $message=$SPECIFIERS_MESSAGES{$specifier};
 3276 
 3277                                         $err_string.='<br>'."$message $err_required $err_for_type $type : $err_field $checked";
 3278                                         $flag_err=1;
 3279 
 3280                                 } elsif ($FIELD_NAMES{$specifier}{0} eq $checked) {
 3281 
 3282                                         if ($FIELDS_TYPES{$type}{$specifier} eq '-1') {
 3283 
 3284                                                 $message=$SPECIFIERS_MESSAGES{$specifier};
 3285 
 3286                                                 $err_string.='<br>'."$message $err_not_allowed $err_for_type $type : $err_field $checked";
 3287                                                 $flag_err=1;
 3288                                         }
 3289                                 }
 3290                         }
 3291                 }
 3292         }
 3293 
 3294         if ($#create_checked_items == -1) {
 3295 
 3296                 $err_string.='<br>'.$err_no_checked_fields;
 3297                 $flag_err=1;
 3298         }
 3299 
 3300         for ($extrn=1;$extrn<$#create_checked_items+1;$extrn++) {
 3301 
 3302                 for ($intrn=$extrn+1;$intrn<=$#create_checked_items+1;$intrn++) {
 3303 
 3304                         if ($FIELD_NAMES{'field_name'}{$create_checked_items[$extrn-1]} eq $FIELD_NAMES{'field_name'}{$create_checked_items[$intrn-1]}) {
 3305 
 3306                                 $err_string.='<br>'."$err_same_name_fields $extrn , $intrn";
 3307                                 $flag_err=1;
 3308                         }
 3309                 }
 3310         }
 3311 
 3312         if ((exists $FIELD_NAMES{'checked_item'}{$FIELD_NAMES{'auto_increment'}{0}}) and $FIELD_NAMES{'auto_increment'}{0}) {
 3313 
 3314         my $local_err=1;
 3315         foreach my $key (keys %{$FIELD_NAMES{'primary_key'}}) {
 3316 
 3317             if ($key eq $FIELD_NAMES{'auto_increment'}{0}) {
 3318 
 3319                 $local_err=0;
 3320                 last;
 3321             }
 3322         }
 3323 
 3324                 if ($local_err) {
 3325 
 3326                         $err_string.='<br>'."$SPECIFIERS_MESSAGES{'auto_increment'} $js_ai_must_be_pkey $SPECIFIERS_MESSAGES{'primary_key'} : $FIELD_NAMES{'auto_increment'}{0}";
 3327                         $flag_err=1;
 3328                 }
 3329         }
 3330 
 3331     foreach my $key (keys %{$FIELD_NAMES{'primary_key'}}) {
 3332 
 3333             if ((exists $FIELD_NAMES{'checked_item'}{$key}) && (!exists $FIELD_NAMES{'checked_item'}{$FIELD_NAMES{'not_null'}{$key}})) {
 3334 
 3335                 $err_string.='<br>'."$SPECIFIERS_MESSAGES{'primary_key'} $js_pk_must_be_nn $SPECIFIERS_MESSAGES{'not_null'} : $err_field $key";
 3336                     $flag_err=1;
 3337             last;
 3338         }
 3339         }
 3340 
 3341         if ($flag_err) {
 3342 
 3343                 $err_string="<b>$err_error_word:</b> ".$err_string;
 3344                 write_labeled_message($err_string);
 3345                 return 0;
 3346 
 3347         } else {
 3348 
 3349                 return 1;
 3350         }
 3351 }
 3352 
 3353 sub verify_checks_lite {
 3354 
 3355         my ($flag_err,
 3356             $dim_hash_tabs,
 3357             $dim_hash_items,
 3358             $tabcheck_but,
 3359             $tabno_with_checked,
 3360             $dim_hash1,
 3361             $dim_hash2,
 3362             $norec_exist,
 3363             $norec_check,
 3364             @recerr_noex,
 3365             @recerr_nocheck,
 3366             @taberr_no,
 3367             $tab_string,
 3368             $err_string
 3369             );
 3370 
 3371         $flag_err=0;
 3372 
 3373         ($dim_hash_tabs,$dim_hash_items,$norec_exist,$norec_check)=sync_checked_items(\%CHECKED_TABLES,\%FIELD_NAMES);
 3374 
 3375         if ($norec_exist) {
 3376 
 3377                 @recerr_noex=keys %NO_SYNC_INPUT_HASH1;
 3378         }
 3379 
 3380         if (@recerr_noex) {
 3381 
 3382                 $tab_string="@recerr_noex";
 3383                 $tab_string="<li>$tab_string</li>";
 3384                 $tab_string =~ s/\x20/<li>/g;
 3385                 $tab_string =~ s/\x20/<\/li>/g;
 3386                 $err_string.="<br><b>$err_error_word:</b> $err_tab_check_wo_exist:<br>$tab_string<br>";
 3387                 $flag_err=1;
 3388         }
 3389 
 3390         if ($flag_err) {
 3391 
 3392                 write_labeled_message($err_string);
 3393                 return 0;
 3394 
 3395         } else {
 3396 
 3397                 return 1;
 3398         }
 3399 }
 3400 
 3401 sub verify_checks {
 3402 
 3403         my ($flag_err,
 3404             $dim_hash_tabs,
 3405             $dim_hash_items,
 3406             $tabcheck_but,
 3407             $tabno_with_checked,
 3408             $dim_hash1,
 3409             $dim_hash2,
 3410             $norec_exist,
 3411             $norec_check,
 3412             @recerr_noex,
 3413             @recerr_nocheck,
 3414             @taberr_no,
 3415             $tab_string,
 3416             $err_string
 3417             );
 3418 
 3419         $flag_err=0;
 3420 
 3421         get_checked_tables();
 3422         get_checked_items();
 3423 
 3424         ($dim_hash_tabs,$dim_hash_items,$tabcheck_but,$tabno_with_checked)=sync_checked_items(\%CHECKED_TABLES,\%CHECKED_ITEMS);
 3425         get_field_names();
 3426 
 3427         if ($tabno_with_checked) {
 3428 
 3429                 @taberr_no=keys %NO_SYNC_INPUT_HASH2;
 3430                 $flag_err=1;
 3431         }
 3432 
 3433         if ($tabcheck_but) {
 3434 
 3435                 foreach my $key (%NO_SYNC_INPUT_HASH1) {
 3436                         $DUP_HASH{$key}=$NO_SYNC_INPUT_HASH1{$key};
 3437                 }
 3438 
 3439                 ($dim_hash1,$dim_hash2,$norec_exist,$norec_check)=sync_checked_items(\%DUP_HASH,\%FIELD_NAMES);
 3440 
 3441                 if ($norec_exist) {
 3442 
 3443                         @recerr_noex=keys %NO_SYNC_INPUT_HASH1;
 3444                 }
 3445 
 3446                 @recerr_nocheck=keys %FIELD_NAMES;
 3447                 $flag_err=1;
 3448         }
 3449 
 3450         if (@taberr_no) {
 3451 
 3452                 $tab_string="@taberr_no";
 3453                 $tab_string="<li>$tab_string</li>";
 3454                 $tab_string=~ s/\x20/<li>/g;
 3455                 $tab_string=~ s/\x20/<\/li>/g;
 3456                 $err_string="<br><b>$err_error_word:</b> $err_tab_no_check_with:<br>$tab_string<br>";
 3457         }
 3458 
 3459         if (@recerr_noex) {
 3460 
 3461                 $tab_string="@recerr_noex";
 3462                 $tab_string="<li>$tab_string</li>";
 3463                 $tab_string =~ s/\x20/<li>/g;
 3464                 $tab_string =~ s/\x20/<\/li>/g;
 3465                 $err_string.="<br><b>$err_error_word:</b> $err_tab_check_wo_exist:<br>$tab_string<br>";
 3466         }
 3467 
 3468         if (@recerr_nocheck) {
 3469 
 3470                 $tab_string="@recerr_nocheck";
 3471                 $tab_string="<li>$tab_string</li>";
 3472                 $tab_string =~ s/\x20/<li>/g;
 3473                 $tab_string =~ s/\x20/<\/li>/g;
 3474                 $err_string.="<br><b>$err_error_word:</b> $err_tab_check_wo_check:<br>$tab_string<br>";
 3475         }
 3476 
 3477         if (!$flag_err and !$dim_hash_tabs) {
 3478 
 3479                 $err_string.="<b>$err_error_word:</b> $err_no_check_rec_tab";
 3480                 $flag_err=1;
 3481         }
 3482 
 3483         if ($flag_err) {
 3484 
 3485                 write_labeled_message($err_string);
 3486                 return 0;
 3487 
 3488         } else {
 3489 
 3490                 return 1;
 3491         }
 3492 }
 3493 
 3494 sub get_checked_tables {
 3495 
 3496         my ($key,
 3497             $checked_table,
 3498             $table_name
 3499             );
 3500 
 3501     my $tmp_delimiter=quotemeta($delimiter);
 3502         foreach $key (keys %CGI_INPUT) {
 3503 
 3504                 ($checked_table,$table_name)=split /$tmp_delimiter/, $key;
 3505 
 3506                 if ($checked_table eq 'checked_table') {
 3507 
 3508                         $CHECKED_TABLES{$CGI_INPUT{$key}}=$table_name;
 3509                         delete $CGI_INPUT{$key};
 3510                 }
 3511         }
 3512 
 3513         return %CHECKED_TABLES+0;
 3514 }
 3515 
 3516 sub get_checked_items {
 3517 
 3518         my ($num_of_items ,
 3519             $checked_item ,
 3520             $table_name   ,
 3521             $relevant_name,
 3522             $id_number    ,
 3523             $key
 3524             );
 3525 
 3526         $num_of_items=0;
 3527 
 3528     my $tmp_delimiter=quotemeta($delimiter);
 3529         foreach $key (keys %CGI_INPUT) {
 3530 
 3531                 ($checked_item,$table_name,$relevant_name,$id_number)=split /$tmp_delimiter/, $key;
 3532 
 3533                 if ($checked_item eq "checked_item") {
 3534 
 3535                         $CHECKED_ITEMS{$table_name}{$relevant_name}{$id_number}=$CGI_INPUT{$key};
 3536                         delete $CGI_INPUT{$key};
 3537                         $num_of_items++;
 3538                 }
 3539         }
 3540 
 3541         return $num_of_items;
 3542 }
 3543 
 3544 sub get_field_names {
 3545 
 3546         my ($num_of_fields,
 3547             $field_name   ,
 3548             $table_name   ,
 3549             $id_number    ,
 3550             $key
 3551             );
 3552 
 3553         $num_of_fields=0;
 3554 
 3555     my $tmp_delimiter=quotemeta($delimiter);
 3556         foreach $key (keys %CGI_INPUT) {
 3557 
 3558                 ($field_name,$table_name,$id_number)=split /$tmp_delimiter/, $key;
 3559 
 3560                 if ($field_name eq "field_name") {
 3561 
 3562                         $FIELD_NAMES{$table_name}{$id_number}=$CGI_INPUT{$key};
 3563                         delete $CGI_INPUT{$key};
 3564                         $num_of_fields++;
 3565                 }
 3566         }
 3567 
 3568         return $num_of_fields;
 3569 }
 3570 
 3571 sub get_fields_types {
 3572 
 3573         my ($line,
 3574         @properties,
 3575             @specifiers,
 3576             $property_index,
 3577             $specifier,
 3578             $html_form_tag,
 3579             $js_property,
 3580             $appear,
 3581         $option
 3582         );
 3583 
 3584         $line=<DATA>;
 3585 
 3586         @properties=split /,/,$line;
 3587 
 3588         foreach $property_index (1 .. $#properties) {
 3589 
 3590                 ($specifier,$html_form_tag,$js_property,$appear)=split /\*/,$properties[$property_index];
 3591 
 3592                 $internal_SPECIFIERS_ORDER{$specifier}=$property_index;
 3593 
 3594                 $SPECIFIERS_PROPERTIES{$specifier}{'html'}=$html_form_tag;
 3595                 $SPECIFIERS_PROPERTIES{$specifier}{'js'}=$js_property;
 3596                 $SPECIFIERS_PROPERTIES{$specifier}{'appear'}=$appear;
 3597         }
 3598 
 3599         while ($line=<DATA>) {
 3600 
 3601                 @specifiers=split /,/ , $line;
 3602 
 3603                 foreach $specifier (keys %internal_SPECIFIERS_ORDER) {
 3604 
 3605                         $FIELDS_TYPES{$specifiers[0]}{$specifier}=$specifiers[$internal_SPECIFIERS_ORDER{$specifier}];
 3606                 }
 3607 
 3608                 $option.=qq{
 3609                             <option>$specifiers[0]</option>
 3610                             };
 3611         }
 3612 
 3613         return $option;
 3614 }
 3615 
 3616 sub get_select_params {
 3617 
 3618         my ($num_of_fields,
 3619             $select_param ,
 3620             $table_name   ,
 3621             $action_name  ,
 3622             $key
 3623             );
 3624 
 3625         $num_of_fields=0;
 3626 
 3627     my $tmp_delimiter=quotemeta($delimiter);
 3628         foreach $key (keys %CGI_INPUT) {
 3629 
 3630                 ($select_param,$action_name,$table_name)=split /$tmp_delimiter/, $key;
 3631 
 3632                 if ($select_param eq "select_param") {
 3633 
 3634                         if ($table_name) {
 3635 
 3636                                 $SELECT_PARAMS{$action_name}{$table_name}=$CGI_INPUT{$key};
 3637 
 3638                         } else {
 3639 
 3640                                 $SELECT_PARAMS{$action_name}{'all_checked'}=$CGI_INPUT{$key};
 3641                         }
 3642 
 3643                         delete $CGI_INPUT{$key};
 3644                         $num_of_fields++;
 3645                 }
 3646         }
 3647 
 3648         return $num_of_fields;
 3649 }
 3650 
 3651 sub get_field_values {
 3652 
 3653         my ($num_of_value_fields,
 3654             $field_value        ,
 3655             $table_name         ,
 3656             $id_number          ,
 3657             $field_name         ,
 3658             $key_field          ,
 3659             $key
 3660             );
 3661 
 3662         $num_of_value_fields=0;
 3663 
 3664     my $tmp_delimiter=quotemeta($delimiter);
 3665         foreach $key (keys %CGI_INPUT) {
 3666 
 3667                 ($field_value,$id_number,$table_name,$field_name)=split /$tmp_delimiter/, $key;
 3668 
 3669                 if ($field_value eq 'field_value') {
 3670 
 3671                         if (exists $CHECKED_ITEMS{$table_name}) {
 3672 
 3673                                 foreach $key_field (keys %{$CHECKED_ITEMS{$table_name}}) {
 3674 
 3675                                         if (exists $CHECKED_ITEMS{$table_name}{$key_field}{$id_number}) {
 3676 
 3677                                                 $FIELD_VALUES{$table_name}{$id_number}{$field_name}=$CGI_INPUT{$key};
 3678                                                 delete $CGI_INPUT{$key};
 3679                                                 $num_of_value_fields++;
 3680                                         }
 3681                                 }
 3682                         }
 3683                 }
 3684         }
 3685 
 3686         return $num_of_value_fields;
 3687 }
 3688 
 3689 sub sync_checked_items {
 3690 
 3691         my ($input_hash_ref1    ,
 3692             $input_hash_ref2    ,
 3693             $keys_equals        ,
 3694             $index_input_keys1  ,
 3695             $index_input_keys2  ,
 3696             $lower_limit        ,
 3697             $not_synced_end     ,
 3698             $index_synced       ,
 3699             $key                ,
 3700             @input_keys1        ,
 3701             @input_keys2        ,
 3702             @synced_items       ,
 3703             );
 3704 
 3705         $input_hash_ref1=$_[0];
 3706         $input_hash_ref2=$_[1];
 3707         @input_keys1    =sort keys %{$input_hash_ref1};
 3708         @input_keys2    =sort keys %{$input_hash_ref2};
 3709         @synced_items   =();
 3710 
 3711         $lower_limit=0;
 3712         $keys_equals=0;
 3713 
 3714         foreach $index_input_keys1 (0 .. $#input_keys1) {
 3715 
 3716                 if ($keys_equals) {$lower_limit++; $keys_equals=0;}
 3717 
 3718                 foreach $index_input_keys2 ($lower_limit .. $#input_keys2) {
 3719 
 3720                         if ($input_keys1[$index_input_keys1] eq $input_keys2[$index_input_keys2]) {
 3721 
 3722                                 $synced_items[++$#synced_items]=$input_keys1[$index_input_keys1];
 3723                                 $keys_equals=1;
 3724                                 last;
 3725                         }
 3726                 }
 3727         }
 3728 
 3729         undef %NO_SYNC_INPUT_HASH1;
 3730         undef %NO_SYNC_INPUT_HASH2;
 3731 
 3732         $index_synced=0;
 3733         $not_synced_end=1;
 3734 
 3735         foreach $key (sort keys %{$input_hash_ref1}) {
 3736 
 3737                 if ($not_synced_end) {
 3738 
 3739                         if ($synced_items[$index_synced] ne $key) {
 3740 
 3741                                 $NO_SYNC_INPUT_HASH1{$key}=$key;
 3742                                 delete ${$input_hash_ref1}{$key};
 3743 
 3744                         } else {
 3745 
 3746                                 if ($index_synced == $#synced_items) {$not_synced_end=0;} else {$index_synced++;}
 3747                         }
 3748 
 3749                 } else {
 3750 
 3751                         $NO_SYNC_INPUT_HASH1{$key}=$key;
 3752                         delete ${$input_hash_ref1}{$key};
 3753                 }
 3754         }
 3755 
 3756         $index_synced=0;
 3757         $not_synced_end=1;
 3758 
 3759         foreach $key (sort keys %{$input_hash_ref2}) {
 3760 
 3761                 if ($not_synced_end) {
 3762 
 3763                         if ($synced_items[$index_synced] ne $key) {
 3764 
 3765                                 $NO_SYNC_INPUT_HASH2{$key}=1;
 3766                                 delete ${$input_hash_ref2}{$key};
 3767 
 3768                         } else {
 3769 
 3770                                 if ($index_synced == $#synced_items) {$not_synced_end=0;} else {$index_synced++;}
 3771                         }
 3772 
 3773                 } else {
 3774 
 3775                         $NO_SYNC_INPUT_HASH2{$key}=1;
 3776                         delete ${$input_hash_ref2}{$key};
 3777                 }
 3778         }
 3779 
 3780         return %{$input_hash_ref1}+0,%{$input_hash_ref2}+0,%NO_SYNC_INPUT_HASH1+0,%NO_SYNC_INPUT_HASH2+0;
 3781 }
 3782 
 3783 sub get_current_select_params {
 3784 
 3785         my ($table_name,
 3786             $limit,
 3787             $offset_value,
 3788             $where_field,
 3789             $where_value,
 3790             $where_method,
 3791             $and_field,
 3792             $and_value,
 3793             $and_method,
 3794             $orderby_field,
 3795             $orderby_method
 3796             );
 3797 
 3798         $table_name=$_[0];
 3799 
 3800         if (exists $SELECT_PARAMS{'where'}{$table_name}) {
 3801 
 3802                 $where_field=$SELECT_PARAMS{'where_field'}{$table_name};
 3803                 $where_value=$dbh->quote($SELECT_PARAMS{'where_value'}{$table_name});
 3804                 $where_method=$SELECT_PARAMS{'where_method'}{$table_name};
 3805         }
 3806 
 3807         if (exists $SELECT_PARAMS{'and'}{$table_name}) {
 3808 
 3809                 $and_field=$SELECT_PARAMS{'and_field'}{$table_name};
 3810                 $and_value=$dbh->quote($SELECT_PARAMS{'and_value'}{$table_name});
 3811                 $and_method=$SELECT_PARAMS{'and_method'}{$table_name};
 3812         }
 3813 
 3814         if (exists $SELECT_PARAMS{'orderby'}{$table_name}) {
 3815 
 3816                 $orderby_field=$SELECT_PARAMS{'orderby_field'}{$table_name};
 3817                 $orderby_method=$SELECT_PARAMS{'orderby_method'}{$table_name};
 3818         }
 3819 
 3820         if (exists $SELECT_PARAMS{'limit'}{$table_name}) {
 3821 
 3822                 $limit=$SELECT_PARAMS{'limit'}{$table_name};
 3823 
 3824         } else {
 3825 
 3826                 $limit=$SELECT_PARAMS{'limit'}{'all_checked'};
 3827         }
 3828 
 3829         if (exists $SELECT_PARAMS{'offset'}{$table_name}) {
 3830 
 3831                 $offset_value=$SELECT_PARAMS{'offset_value'}{$table_name};
 3832 
 3833         } elsif (exists $SELECT_PARAMS{'offset'}{'all_checked'}) {
 3834 
 3835                 $offset_value=$SELECT_PARAMS{'offset_value'}{'all_checked'};
 3836         }
 3837 
 3838         return $limit,$offset_value,$where_field,$where_value,$where_method,$and_field,$and_value,$and_method,$orderby_field,$orderby_method;
 3839 }
 3840 
 3841 #===============================================
 3842 #       perform_action subroutines
 3843 #===============================================
 3844 
 3845 sub perform_action {
 3846 
 3847         my ($message,$error_message);
 3848 
 3849         if ($create_enabled and $flag_ok and $CGI_INPUT{createcheck}) {
 3850 
 3851                 get_fields_types();
 3852                 get_field_names();
 3853 
 3854                 if (create()) {
 3855 
 3856                         $message=$ok_create;
 3857                         write_labeled_message($message);
 3858 
 3859                 } else {
 3860 
 3861                         $error_message="<b>$err_error_word:</b> $ko_create<br><b>$err_details_word:</b> $global_err";
 3862                         write_labeled_message($error_message);
 3863                 }
 3864 
 3865                 $flag_ok=0;
 3866         }
 3867 
 3868         if ($insertrecord_enabled and $flag_ok and $CGI_INPUT{insertok}) {
 3869 
 3870                 get_checked_tables();
 3871                 get_checked_items();
 3872                 get_field_values();
 3873 
 3874                 if (insert_records()) {
 3875 
 3876                         $message=$ok_insert;
 3877                         write_labeled_message($message);
 3878 
 3879                 } else {
 3880 
 3881                         $error_message="<b>$err_error_word:</b> $ko_insert<br><b>$err_details_word:</b> $global_err";
 3882                         write_labeled_message($error_message);
 3883                 }
 3884 
 3885                 $flag_ok=0;
 3886         }
 3887 
 3888         if ($updaterecord_enabled and $flag_ok and $CGI_INPUT{updateok}) {
 3889 
 3890                 get_checked_tables();
 3891                 get_checked_items();
 3892                 get_field_values();
 3893 
 3894                 if (update_records()) {
 3895 
 3896                         $message=$ok_update;
 3897                         write_labeled_message($message);
 3898 
 3899                 } else {
 3900 
 3901                         $error_message="<b>$err_error_word:</b> $ko_update<br><b>$err_details_word:</b> $global_err";
 3902                         write_labeled_message($error_message);
 3903                 }
 3904 
 3905                 $flag_ok=0;
 3906         }
 3907 
 3908         if ($delete_enabled and $flag_ok and $CGI_INPUT{deleteok}) {
 3909 
 3910                 get_checked_tables();
 3911                 get_checked_items();
 3912 
 3913                 if (deleterec()) {
 3914 
 3915                         $message=$ok_delete;
 3916                         write_labeled_message($message);
 3917 
 3918                 } else {
 3919 
 3920                         $error_message="<b>$err_error_word:</b> $ko_delete<br><b>$err_details_word:</b> $global_err";
 3921                         write_labeled_message($error_message);
 3922                 }
 3923 
 3924                 $flag_ok=0;
 3925         }
 3926 
 3927         if ($drop_enabled and $flag_ok and $CGI_INPUT{dropok}) {
 3928 
 3929                 get_checked_tables();
 3930 
 3931                 if (drop()) {
 3932 
 3933                         $message=$ok_drop;
 3934                         write_labeled_message($message);
 3935 
 3936                 } else {
 3937 
 3938                         $error_message="<b>$err_error_word:</b> $ko_drop<br><b>$err_details_word:</b> $global_err";
 3939                         write_labeled_message($error_message);
 3940                 }
 3941 
 3942                 $flag_ok=0;
 3943         }
 3944 
 3945         if ($erase_enabled and $flag_ok and $CGI_INPUT{eraseok}) {
 3946 
 3947                 get_checked_tables();
 3948 
 3949                 if (erase()) {
 3950 
 3951                         $message=$ok_erase;
 3952                         write_labeled_message($message);
 3953 
 3954                 } else {
 3955 
 3956                         $error_message="<b>$err_error_word:</b> $ko_erase<br><b>$err_details_word:</b> $global_err";
 3957                         write_labeled_message($error_message);
 3958                 }
 3959 
 3960                 $flag_ok=0;
 3961         }
 3962 
 3963         if ($fquery_enabled and $flag_ok and $CGI_INPUT{fqueryok}) {
 3964 
 3965                 #get_fquery();
 3966 
 3967                 if (perform_fquery()) {
 3968 
 3969             main_fquery();
 3970 
 3971                 } else {
 3972 
 3973                         $error_message="<b>$err_error_word:</b> $ko_fquery<br><b>$err_details_word:</b> $global_err";
 3974                         write_labeled_message($error_message);
 3975                 }
 3976 
 3977                 $flag_ok=0;
 3978         }
 3979 
 3980         print qq{
 3981                 <br>
 3982                 <form name="the_script" method="POST" action="$thiscgi">
 3983                 <input type="hidden" name="current_user" value="$current_user">
 3984                 <input type="hidden" name="current_pwd" value="$current_pwd">
 3985         };
 3986 
 3987     if (!$custom_configuration) {
 3988 
 3989         print qq{
 3990                     <input type="hidden" name="server_login_host" value="$DATABASES{'1'}{'host'}">
 3991                         <input type="hidden" name="server_login_port" value="$DATABASES{'1'}{'port'}">
 3992                     <input type="hidden" name="server_login_database" value="$DATABASES{'1'}{'database'}">
 3993                         <input type="hidden" name="server_login_user" value="$DATABASES{'1'}{'user'}">
 3994                         <input type="hidden" name="server_login_pwd" value="$DATABASES{'1'}{'password'}">
 3995             <input type="hidden" name="current_db" value="#">
 3996             };
 3997 
 3998     } else {
 3999 
 4000         print qq{
 4001             <input type="hidden" name="current_db" value="$current_db">
 4002             };
 4003     }
 4004 
 4005     print qq{
 4006                 <div align="center">
 4007                 <table border="0" cellpadding="1" cellspacing="0">
 4008                 <tr>
 4009                 <td bgcolor="#000000" align="center">
 4010                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color" width="100%">
 4011                 <tr>
 4012                 <td>
 4013                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 4014                 };
 4015 
 4016         my $current_table_number=1;
 4017 
 4018     if (!$custom_configuration) {
 4019 
 4020             $relevant_js_obj=8;
 4021 
 4022     } else {
 4023 
 4024             $relevant_js_obj=3;
 4025     }
 4026 
 4027         if (!($prepare_create_enabled and $CGI_INPUT{create})) {
 4028 
 4029                 if (!list_tables()) {
 4030 
 4031                         $empty_db=1;
 4032 
 4033                         print q{
 4034                                 <tr>
 4035                                 <td align="center">
 4036                                 };
 4037 
 4038                         write_labeled_message("$err_db_empty");
 4039 
 4040                         print q{
 4041                                 </td>
 4042                                 </tr>
 4043                                 };
 4044                 }
 4045 
 4046         } else {
 4047 
 4048                 main_create();
 4049         }
 4050 
 4051         foreach my $current_table (@tables_names) {
 4052 
 4053                 print qq{
 4054                         <tr>
 4055                         <td align="center" bgcolor="$table_checkb_td_color">
 4056                         <FONT FACE="$numb_table_checkb_ff" SIZE="$numb_table_checkb_fs" COLOR="$numb_table_checkb_col">
 4057                         $current_table_number
 4058                         </font>
 4059                         };
 4060 
 4061                 if ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled or $new_enabled or $select_enabled or $prepare_enabled) {
 4062 
 4063                         my $tmp_name='checked_table'.$delimiter.$current_table;
 4064 
 4065                         if ($flag_ok and exists $CHECKED_TABLES{$current_table}) {
 4066 
 4067                                 print qq{
 4068                                         <input type="checkbox" checked name="$tmp_name" value="$current_table">
 4069                                         };
 4070 
 4071                         } else {
 4072 
 4073                                 print qq{
 4074                                         <input type="checkbox" name="$tmp_name" value="$current_table">
 4075                                         };
 4076                         }
 4077                 }
 4078 
 4079                 print qq{
 4080                         </td>
 4081                         <td><FONT FACE="$tablename_font_face" SIZE="$tablename_font_size" COLOR="$tablename_font_color">
 4082                         $current_table
 4083                         </font>
 4084                         </td>
 4085                         </tr>
 4086                         };
 4087 
 4088                 $javascript_objects[$current_table_number]->{'object_number'}=$relevant_js_obj;
 4089                 $javascript_objects[$current_table_number]->{'dim_array_obj_num'}=0;
 4090                 $relevant_js_obj++;
 4091 
 4092                 if ($describe_enabled and $flag_ok and $CGI_INPUT{describe}) {
 4093 
 4094                         if (exists $CHECKED_TABLES{$current_table}) {
 4095 
 4096                                 main_describe($current_table,'describe');
 4097                         }
 4098                 }
 4099 
 4100                 if ($showindex_enabled and $flag_ok and $CGI_INPUT{showindex}) {
 4101 
 4102                         if (exists $CHECKED_TABLES{$current_table}) {
 4103 
 4104                                 main_describe($current_table,'show index from');
 4105                         }
 4106                 }
 4107 
 4108                 if ($select_enabled and $flag_ok and $CGI_INPUT{select}) {
 4109 
 4110                         if (exists $CHECKED_TABLES{$current_table}) {
 4111 
 4112                                 main_select($current_table,$current_table_number);
 4113                         }
 4114                 }
 4115 
 4116                 if ($prepare_enabled and $flag_ok and $CGI_INPUT{prepare}) {
 4117 
 4118                         if (exists $CHECKED_TABLES{$current_table}) {
 4119 
 4120                                 main_prepare($current_table,$current_table_number);
 4121                         }
 4122                 }
 4123 
 4124                 if ($new_enabled and $flag_ok and $CGI_INPUT{new}) {
 4125 
 4126                         if (exists $CHECKED_TABLES{$current_table}) {
 4127 
 4128                                 main_new($current_table,$current_table_number);
 4129                         }
 4130                 }
 4131 
 4132                 if ($selectfields_enabled and $flag_ok and $CGI_INPUT{selectfields}) {
 4133 
 4134                         if (exists $CHECKED_TABLES{$current_table}) {
 4135 
 4136                                 main_selectfields($current_table,$current_table_number);
 4137                         }
 4138                 }
 4139 
 4140                 if ($edititem_enabled and $flag_ok and $CGI_INPUT{edititem}) {
 4141 
 4142                         if (exists $CHECKED_TABLES{$current_table}) {
 4143 
 4144                                 main_edititem($current_table,$current_table_number);
 4145                         }
 4146                 }
 4147 
 4148                 $current_table_number++;
 4149         }
 4150 
 4151         print q{
 4152                 </table>
 4153                 </td>
 4154                 </tr>
 4155                 };
 4156 
 4157         if (!$empty_db) {
 4158 
 4159                 if (((
 4160             ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled or ($javascript_enabled and $new_enabled) 
 4161             or ($javascript_enabled and $select_enabled) or ($javascript_enabled and $prepare_enabled))) 
 4162             or ($new_enabled or ($flag_ok and (($select_enabled and $CGI_INPUT{select}) 
 4163             or ($selectfields_enabled and $CGI_INPUT{selectfields})
 4164               ) and ($edititem_enabled or $delete_enabled)
 4165               ) or ($flag_ok and ($edititem_enabled and $CGI_INPUT{edititem} and $updaterecord_enabled)) 
 4166             or ($flag_ok and ($new_enabled and $CGI_INPUT{new} and $insertrecord_enabled))
 4167               ) or ($select_enabled or ($selectfields_enabled and $CGI_INPUT{selectfields}) or $prepare_enabled)
 4168               ) and (!$CGI_INPUT{create})) {
 4169 
 4170                         print q{
 4171                                 <tr>
 4172                                 <td>
 4173                                 };
 4174 
 4175                         put_buttons();
 4176 
 4177                         print q{
 4178                                 </td>
 4179                                 </tr>
 4180                                 };
 4181 
 4182                 } elsif ($CGI_INPUT{create} and $prepare_create_enabled) {
 4183 
 4184                         put_create_related_buttons();
 4185                 }
 4186 
 4187         } else {
 4188 
 4189                 put_database_related_buttons();
 4190 
 4191                 if ($create_enabled) {
 4192 
 4193                         put_create_button();
 4194                 }
 4195 
 4196             if ($fquery_enabled) {
 4197 
 4198                         put_fquery();
 4199         }
 4200         }
 4201 
 4202         print q{
 4203                 </table>
 4204                 </td>
 4205                 </tr>
 4206                 </table>
 4207                 </div>
 4208                 </form>
 4209                 };
 4210 
 4211         if (!$empty_db and $javascript_enabled and !$CGI_INPUT{create}) {put_javascript();}
 4212         if ($CGI_INPUT{create} and $prepare_create_enabled and $javascript_enabled) {put_javascript_for_create();}
 4213 
 4214         $dbh->disconnect;
 4215 }
 4216 
 4217 sub put_create_button {
 4218 
 4219         print qq{
 4220                 <tr>
 4221                 <td>
 4222                 <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4223                 <b>$operation_on_tables</b>
 4224                 </font>
 4225                 <table border="1">
 4226                 <tr>
 4227                 <td>
 4228                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4229                 <input type="submit" name="create" value="$button_prepare_create">&nbsp;
 4230                 $number_of_fields &nbsp;
 4231                 <select name="new_fields">
 4232                 $new_fields
 4233                 </select>
 4234                 </font>
 4235                 </td>
 4236                 </tr>
 4237                 </table>
 4238                 </td>
 4239                 </tr>
 4240                 };
 4241 }
 4242 
 4243 sub put_fquery {
 4244 
 4245         print qq{
 4246                 <tr>
 4247                 <td>
 4248                 <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4249                 <b>$fquery</b>
 4250                 </font>
 4251                 <table border="1">
 4252                 <tr>
 4253                 <td>
 4254                 };
 4255 
 4256     print qq{
 4257         <textarea cols="$cols_fquery_textarea" rows="$rows_fquery_textarea" name="fquery_textarea"></textarea>
 4258         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4259         <input type="submit" name="fquery" value="$button_fquery">
 4260         </font>
 4261         };
 4262 
 4263         print q{
 4264                 </td>
 4265                 </tr>
 4266                 </table>
 4267                 </td>
 4268                 </tr>
 4269                 };
 4270 
 4271 }
 4272 
 4273 sub prompt_db_choice {
 4274 
 4275         my $db_position;
 4276 
 4277         print qq{
 4278                 <br>
 4279                 <div align="center">
 4280                 <table border="0" cellpadding="1" cellspacing="0">
 4281                 <tr>
 4282                 <td bgcolor="#000000">
 4283                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 4284                 <tr>
 4285                 <td>
 4286                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 4287                 };
 4288 
 4289         foreach $db_position (sort numerically keys %DATABASES) {
 4290 
 4291                 print qq{
 4292                         <tr>
 4293                         <td valign="top"><form name="the_script" method="POST" action="$thiscgi">
 4294             <font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 4295                         <input type="submit" name="db_choice" value="$button_db_choice">
 4296             };
 4297 
 4298         if (!$custom_configuration) {
 4299 
 4300             print qq{
 4301                             <input type="hidden" name="server_login_host" value="$DATABASES{$db_position}{'host'}">
 4302                             <input type="hidden" name="server_login_port" value="$DATABASES{$db_position}{'port'}">
 4303                             <input type="hidden" name="server_login_database" value="$DATABASES{$db_position}{'database'}">
 4304                             <input type="hidden" name="server_login_user" value="$DATABASES{$db_position}{'user'}">
 4305                             <input type="hidden" name="server_login_pwd" value="$DATABASES{$db_position}{'password'}">
 4306                 <input type="hidden" name="current_db" value="#">
 4307                 };
 4308 
 4309         } else {
 4310 
 4311             print qq{
 4312                 <input type="hidden" name="current_db" value="$db_position">
 4313                 };
 4314         }
 4315 
 4316         print qq{
 4317                         <input type="hidden" name="current_user" value="$current_user">
 4318                         <input type="hidden" name="current_pwd" value="$current_pwd">
 4319             &nbsp;$DATABASES{$db_position}{'db_description'}
 4320                         </font>
 4321                         </form>
 4322                         </td>
 4323                         </tr>
 4324                        };
 4325         }
 4326 
 4327     write_labeled_message("$err_no_dbs") if (! scalar %DATABASES);
 4328 
 4329         if ($login_prompt or !$custom_configuration) {
 4330 
 4331                 print q{
 4332                         <tr>
 4333                         <td colspan="2"><table border="0">
 4334                         };
 4335 
 4336                         put_user_related_buttons();
 4337 
 4338                 print q{
 4339             </table>
 4340                         </td>
 4341                         </tr>
 4342                         };
 4343         }
 4344 
 4345         print q{
 4346                         </table>
 4347                 </td>
 4348                 </tr>
 4349                 </table>
 4350                 </td>
 4351                 </tr>
 4352                 </table>
 4353                 </div>
 4354                 };
 4355 }
 4356 
 4357 sub prompt_user_login {
 4358 
 4359         my $state=$_[0];
 4360 
 4361         print qq{
 4362                 <br>
 4363                 <form name="the_script" method="POST" action="$thiscgi">
 4364                 <div align="center">
 4365                 <table border="0" cellpadding="1" cellspacing="0">
 4366                 <tr>
 4367                 <td bgcolor="#000000">
 4368                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 4369                 <tr>
 4370                 <td>
 4371                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 4372                 };
 4373 
 4374         if ($state eq 'failed') {
 4375 
 4376                 print qq{<tr><td colspan="2" align="center">
 4377                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color_log_fail">
 4378                         <b>$user_login_fail_prompt</b>
 4379                         </font>
 4380                         </td></tr>
 4381                         };
 4382         }
 4383 
 4384         print qq{
 4385                 <tr>
 4386                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4387                 <b>$user_id</b>
 4388                 </font>
 4389                 </td>
 4390                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4391                 <input type="text" name="user_id" value="">
 4392                 </font>
 4393                 </td>
 4394                 </tr>
 4395                 <tr>
 4396                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4397                 <b>$user_pwd</b>
 4398                 </font>
 4399                 </td>
 4400                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4401                 <input type="password" name="user_pwd" value="">
 4402                 </font>
 4403                 </td>
 4404                 </tr>
 4405                 <tr>
 4406                 <td colspan="2" align="center"><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 4407                 <input type="submit" name="user_login" value="$button_user_login">
 4408                 </font>
 4409                 </td>
 4410                 </tr>
 4411                };
 4412 
 4413         print q{
 4414                         </table>
 4415                 </td>
 4416                 </tr>
 4417                 </table>
 4418                 </td>
 4419                 </tr>
 4420                 </table>
 4421                 </div>
 4422                 </form>
 4423                 };
 4424 }
 4425 
 4426 sub prompt_server_login {
 4427 
 4428         my $state=$_[0];
 4429 
 4430         print qq{
 4431                 <br>
 4432                 <form name="the_script" method="POST" action="$thiscgi">
 4433                 <input type="hidden" name="current_user" value="$current_user">
 4434                 <input type="hidden" name="current_pwd" value="$current_pwd">
 4435                 <div align="center">
 4436                 <table border="0" cellpadding="1" cellspacing="0">
 4437                 <tr>
 4438                 <td bgcolor="#000000">
 4439                 <table border="0" cellspacing="0" cellpadding="5" BGCOLOR="$table_color">
 4440                 <tr>
 4441                 <td>
 4442                 <table border="0" cellspacing="2" cellpadding="2" BGCOLOR="$table_color">
 4443                 };
 4444 
 4445         if ($state eq 'failed') {
 4446 
 4447                 print qq{<tr><td colspan="2" align="center">
 4448                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color_log_fail">
 4449                         <b>$server_login_fail_prompt</b>
 4450                         </font>
 4451                         </td></tr>
 4452                         };
 4453         }
 4454 
 4455         print qq{
 4456                 <tr>
 4457                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4458                 <b>$server_login_host</b>
 4459                 </font>
 4460                 </td>
 4461                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4462                 <input type="text" name="server_login_host" value="">
 4463                 </font>
 4464                 </td>
 4465                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4466                 $server_login_port <input type="text" name="server_login_port" value="$server_login_port_default" size="5">
 4467                 </font>
 4468                 </td>
 4469                 </tr>
 4470 
 4471                 <tr>
 4472                 <td>&nbsp;
 4473                 </td>
 4474                 <td>&nbsp;
 4475                 </td>
 4476                 <td>&nbsp;
 4477                 </td>
 4478                 </tr>
 4479 
 4480                 <tr>
 4481                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4482                 <b>$server_login_user</b>
 4483                 </font>
 4484                 </td>
 4485                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4486                 <input type="text" name="server_login_user" value="">
 4487                 </font>
 4488                 </td>
 4489                 </tr>
 4490 
 4491                 <tr>
 4492                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4493                 <b>$server_login_pwd</b>
 4494                 </font>
 4495                 </td>
 4496                 <td><FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4497                 <input type="password" name="server_login_pwd" value="">
 4498                 </font>
 4499                 </td>
 4500                 </tr>
 4501 
 4502                 <tr>
 4503                 <td colspan="3" align="center"><font face="$button_font_face" size="$button_font_size" color="$button_font_color">
 4504                 <input type="submit" name="server_login" value="$button_server_login">
 4505                 </font>
 4506                 </td>
 4507                 </tr>
 4508                };
 4509 
 4510         if ($login_prompt) {
 4511 
 4512                 print q{
 4513                         <tr>
 4514                         <td colspan="3"><table border="0">
 4515                         };
 4516 
 4517                         put_user_related_buttons();
 4518 
 4519                 print q{</table>
 4520                         </td>
 4521                         </tr>
 4522                         };
 4523         }
 4524 
 4525         print q{
 4526                         </table>
 4527                 </td>
 4528                 </tr>
 4529                 </table>
 4530                 </td>
 4531                 </tr>
 4532                 </table>
 4533                 </div>
 4534                 </form>
 4535                 };
 4536 }
 4537 
 4538 sub put_user_related_buttons {
 4539 
 4540         if ($login_prompt or !$custom_configuration) {
 4541 
 4542                 print q{
 4543                         <tr>
 4544             };
 4545 
 4546         if ($login_prompt) {
 4547 
 4548             print qq{
 4549                             <td>
 4550                             <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4551                             <b>$operation_on_user</b>
 4552                             </font>
 4553                             <table border="1">
 4554                             <tr>
 4555                             <td valign="top" border="1">
 4556                             <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4557                             $current_user_msg <b>$current_user</b>
 4558                             </font>
 4559                             </td>
 4560                             <td valign="top">
 4561                             <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4562                             <a href="$thiscgi">$button_user_logout</a>
 4563                             </font>
 4564                             </td>
 4565                 };
 4566         }
 4567 
 4568         if (!$custom_configuration && !$server_state) {
 4569 
 4570             if (!$login_prompt) {
 4571 
 4572                 print q{
 4573                     <td>
 4574                                 <table border="1">
 4575                                 <tr>
 4576                     };
 4577             }
 4578 
 4579 
 4580             if ($CGI_INPUT{'server_login'}) {
 4581 
 4582                 print qq{
 4583                     <form action="$thiscgi" method="post">
 4584                                         <input type="hidden" name="current_user" value="$current_user">
 4585                                         <input type="hidden" name="current_pwd" value="$current_pwd">};
 4586             }
 4587 
 4588             print qq{
 4589                             <td>
 4590                             <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4591                 };
 4592 
 4593 
 4594             print qq{
 4595                 <input type="submit" name="go_to_db_choice" value="Server logout">};
 4596 
 4597             print q{
 4598                             </font>
 4599                             </td>
 4600                 };
 4601 
 4602             if ($CGI_INPUT{'server_login'}) {
 4603 
 4604                 print q{
 4605                     </form>};
 4606             }
 4607 
 4608             if (!$login_prompt) {
 4609 
 4610                 print q{
 4611                                 </tr>
 4612                                 </table>
 4613                                 </td>
 4614                     };
 4615             }
 4616         }
 4617 
 4618         if ($login_prompt) {
 4619 
 4620             print q{
 4621                             </tr>
 4622                             </table>
 4623                             </td>
 4624                 };
 4625         }
 4626 
 4627         print q{
 4628                         </tr>
 4629                         };
 4630         }
 4631 }
 4632 
 4633 sub put_database_related_buttons {
 4634 
 4635         if ($database_prompt or 
 4636         $refresh_enabled or 
 4637         $db_backup_enabled or
 4638         $db_csv_exp_enabled) {
 4639 
 4640                 print qq{
 4641                         <tr>
 4642                         <td>
 4643                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4644                         <b>$operation_on_dbs</b>
 4645                         </font>
 4646                         <table border="1">
 4647                         <tr>
 4648                         <td>
 4649                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4650                         };
 4651 
 4652                 if ($database_prompt && $custom_configuration) {
 4653 
 4654                         print qq{
 4655                                 <input type="submit" name="go_to_db_choice" value="$button_go_to_db_choice">
 4656                                 };
 4657 
 4658                 } elsif ($database_prompt && !$custom_configuration) {
 4659 
 4660                         print qq{
 4661                                 <input type="submit" name="server_login" value="$button_go_to_db_choice">
 4662                                 };
 4663                 }
 4664 
 4665                 if ($refresh_enabled) {
 4666 
 4667                         print qq{
 4668                                 <input type="submit" name="refresh" value="$button_refresh">
 4669                                 };
 4670                 }
 4671 
 4672                 if ($db_backup_enabled) {
 4673 
 4674                         print qq{
 4675                                 <input type="submit" name="db_backup" value="$button_db_backup">
 4676                                 };
 4677                 }
 4678 
 4679                 if ($db_csv_exp_enabled) {
 4680 
 4681                         print qq{
 4682                                 <input type="submit" name="db_csv_exp" value="$button_db_csv_exp">
 4683                                 };
 4684                 }
 4685 
 4686                 print q{
 4687                         </font>
 4688                         </td>
 4689                         </tr>
 4690                         </table>
 4691                         </td>
 4692                         </tr>
 4693                         };
 4694         }
 4695 }
 4696 
 4697 sub put_create_related_buttons {
 4698 
 4699         put_user_related_buttons();
 4700         put_database_related_buttons();
 4701 
 4702         if ($create_enabled) {
 4703 
 4704                 print qq{
 4705                         <tr>
 4706                         <td>
 4707                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4708                         <b>$operation_on_tables</b>
 4709                         </font>
 4710                         <table border="1">
 4711                         <tr>
 4712                         <td>
 4713                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4714                         };
 4715 
 4716                 print qq{
 4717                         <input type="submit" name="createok" value="$button_create"};
 4718 
 4719                 if ($javascript_enabled) {
 4720 
 4721                         print qq{ onClick="return (verify_table_name() && verify_checked_fields() && verify_fields_names() && verify_equal_fields_names() && verify_create_specifiers());">};
 4722 
 4723                 } else {
 4724 
 4725                         print q{>};
 4726                 }
 4727 
 4728                 if ($prepare_create_enabled) {
 4729 
 4730                         print q{
 4731                                 <br>
 4732                                 };
 4733 
 4734                         print qq{
 4735                                 <input type="submit" name="create" value="$button_prepare_create">&nbsp;
 4736                                 $number_of_fields&nbsp;
 4737                                 <select name="new_fields">
 4738                                 $new_fields
 4739                                 </select>
 4740                                 };
 4741                 }
 4742 
 4743                 print q{
 4744                         </font>
 4745                         </td>
 4746                         </tr>
 4747                         </table></td></tr>
 4748                         };
 4749         }
 4750 
 4751         if ($javascript_enabled) {
 4752 
 4753                 print qq{
 4754                         <tr>
 4755                         <td>
 4756                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4757                         <b>$operation_on_fields</b>
 4758                         </font>
 4759                         <table border="1">
 4760                         <tr>
 4761                         <td>
 4762                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4763                         <input type="button" value="$button_js_check_fld" onClick="check_fields();">&nbsp;
 4764                         <input type="button" value="$button_js_unchk_fld" onClick="uncheck_fields();">
 4765                         </font>
 4766                         </td>
 4767                         </tr>
 4768                         </table>
 4769                         </td>
 4770                         </tr>
 4771                         };
 4772         }
 4773 
 4774         if ($fquery_enabled) {
 4775 
 4776         put_fquery();
 4777     }
 4778 
 4779 }
 4780 
 4781 sub put_buttons {
 4782 
 4783     my (
 4784         $tmp_name1,
 4785         $tmp_name2,
 4786         $tmp_name3
 4787        );
 4788 
 4789         my $br_for_new_enabled=0;
 4790 
 4791         print qq{
 4792                 <table border="0" cellspacing="1" cellpadding="1" BGCOLOR="$table_color">
 4793                 };
 4794 
 4795         put_user_related_buttons();
 4796         put_database_related_buttons();
 4797 
 4798         if ($drop_enabled or 
 4799         $erase_enabled or 
 4800         $describe_enabled or 
 4801         $showindex_enabled or 
 4802         $table_backup_enabled or 
 4803         $table_csv_exp_enabled or 
 4804         $prepare_create_enabled or 
 4805         ($javascript_enabled and $new_enabled) or 
 4806         ($javascript_enabled and $select_enabled) or 
 4807         ($javascript_enabled and $prepare_enabled)) {
 4808 
 4809                 print qq{
 4810                         <tr>
 4811                         <td>
 4812                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4813                         <b>$operation_on_tables</b>
 4814                         </font>
 4815                         <table border="1">
 4816                         <tr>
 4817                         <td>
 4818                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4819                         };
 4820 
 4821                 if ($drop_enabled) {
 4822 
 4823                         print qq{
 4824                                 <input type="submit" name="drop" value="$button_drop"};
 4825 
 4826                         if (!$empty_db and $javascript_enabled) {
 4827 
 4828                                 print q{ onClick="return verify_checked_tables();">};
 4829 
 4830                         } else {
 4831 
 4832                                 print q{>};
 4833                         }
 4834                 }
 4835 
 4836                 if ($erase_enabled) {
 4837 
 4838                         print qq{
 4839                                 <input type="submit" name="erase" value="$button_erase"};
 4840 
 4841                         if (!$empty_db and $javascript_enabled) {
 4842 
 4843                                 print q{ onClick="return verify_checked_tables();">};
 4844 
 4845                         } else {
 4846 
 4847                                 print q{>};
 4848                         }
 4849                 }
 4850 
 4851                 if ($describe_enabled) {
 4852 
 4853                         print qq{
 4854                                 <input type="submit" name="describe" value="$button_describe"};
 4855 
 4856                         if (!$empty_db and $javascript_enabled) {
 4857 
 4858                                 print q{ onClick="return verify_checked_tables();">};
 4859 
 4860                         } else {
 4861 
 4862                                 print q{>};
 4863                         }
 4864                 }
 4865 
 4866                 if ($showindex_enabled) {
 4867 
 4868                         print qq{
 4869                                 <input type="submit" name="showindex" value="$button_showindex"};
 4870 
 4871                         if (!$empty_db and $javascript_enabled) {
 4872 
 4873                                 print q{ onClick="return verify_checked_tables();">};
 4874 
 4875                         } else {
 4876 
 4877                                 print q{>};
 4878                         }
 4879                 }
 4880 
 4881                 if ($table_backup_enabled) {
 4882 
 4883                         if ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled) {
 4884 
 4885                                 print q{
 4886                                         <br>
 4887                                         };
 4888                         }
 4889 
 4890                         print qq{
 4891                                 <input type="submit" name="table_backup" value="$button_table_backup"};
 4892 
 4893                         if (!$empty_db and $javascript_enabled) {
 4894 
 4895                                 print q{ onClick="return verify_checked_tables();">};
 4896 
 4897                         } else {
 4898 
 4899                                 print q{>};
 4900                         }
 4901                 }
 4902 
 4903                 if ($table_csv_exp_enabled) {
 4904 
 4905                         if ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled) {
 4906 
 4907                                 print q{
 4908                                         <br>
 4909                                         };
 4910                         }
 4911 
 4912                         print qq{
 4913                                 <input type="submit" name="table_csv_exp" value="$button_table_csv_exp"};
 4914 
 4915                         if (!$empty_db and $javascript_enabled) {
 4916 
 4917                                 print q{ onClick="return verify_checked_tables();">};
 4918 
 4919                         } else {
 4920 
 4921                                 print q{>};
 4922                         }
 4923                 }
 4924 
 4925                 if ($prepare_create_enabled) {
 4926 
 4927                         if ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled) {
 4928 
 4929                                 print q{
 4930                                         <br>
 4931                                         };
 4932                         }
 4933 
 4934                         print qq{
 4935                                 <input type="submit" name="create" value="$button_prepare_create">&nbsp;
 4936                                 $number_of_fields&nbsp;
 4937                                 <select name="new_fields">
 4938                                 $new_fields
 4939                                 </select>
 4940                                 };
 4941                 }
 4942 
 4943                 if (!$empty_db and $javascript_enabled) {
 4944 
 4945                         if ($drop_enabled or $erase_enabled or $describe_enabled or $showindex_enabled) {
 4946 
 4947                                 print qq{
 4948                                         </font>
 4949                                         </td>
 4950                                         <td>
 4951                                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4952                                         };
 4953                         }
 4954 
 4955                         print qq{
 4956                                 <input type="button" value="$button_js_check_tab" onClick="check_tables();"><br>
 4957                                 <input type="button" value="$button_js_unchk_tab" onClick="uncheck_tables();"><br>
 4958                                 <input type="button" value="$button_js_rvrse_tab" onClick="reverse_tables();">
 4959                                 };
 4960                 }
 4961 
 4962                 print q{
 4963                         </font>
 4964                         </td>
 4965                         </tr>
 4966                         </table>
 4967                         </td>
 4968                         </tr>
 4969                         };
 4970         }
 4971 
 4972         if ($new_enabled or 
 4973         ($flag_ok and (($select_enabled and $CGI_INPUT{select}) or 
 4974         ($selectfields_enabled and $CGI_INPUT{selectfields})) and 
 4975         ($edititem_enabled or $delete_enabled)) 
 4976         or ($flag_ok and ($edititem_enabled and $CGI_INPUT{edititem} and $updaterecord_enabled)) or 
 4977         ($flag_ok and ($new_enabled and $CGI_INPUT{new} and $insertrecord_enabled))) {
 4978 
 4979                 print qq{
 4980                         <tr>
 4981                         <td>
 4982                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 4983                         <b>$operation_on_records</b>
 4984                         </font>
 4985                         <table border="1">
 4986                         <tr>
 4987                         <td>
 4988                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 4989                         };
 4990 
 4991                 if ($flag_ok and (($select_enabled and $CGI_INPUT{select}) or ($selectfields_enabled and $CGI_INPUT{selectfields}))) {
 4992 
 4993                         if ($edititem_enabled) {
 4994 
 4995                                 $br_for_new_enabled=1;
 4996 
 4997                                 print qq{
 4998                                         <input type="submit" name="edititem" value="$button_edit"};
 4999 
 5000                                 if (!$empty_db and $javascript_enabled) {
 5001 
 5002                                         print q{ onClick="return (verify_checked_records() && verify_checked_tables());">};
 5003 
 5004                                 } else {
 5005 
 5006                                         print q{>};
 5007                                 }
 5008                         }
 5009 
 5010                         if ($delete_enabled) {
 5011 
 5012                                 $br_for_new_enabled=1;
 5013 
 5014                                 print qq{
 5015                                         <input type="submit" name="delete" value="$button_delete"};
 5016 
 5017                                 if (!$empty_db and $javascript_enabled) {
 5018 
 5019                                         print q{ onClick="return (verify_checked_records() && verify_checked_tables());">};
 5020 
 5021                                 } else {
 5022 
 5023                                         print q{>};
 5024                                 }
 5025                         }
 5026                 }
 5027 
 5028                 if ($flag_ok and ($edititem_enabled and $CGI_INPUT{edititem} and $updaterecord_enabled)) {
 5029 
 5030                         $br_for_new_enabled=1;
 5031 
 5032                         print qq{
 5033                                 <input type="submit" name="updaterecord" value="$button_update"};
 5034 
 5035                         if (!$empty_db and $javascript_enabled) {
 5036 
 5037                                 print q{ onClick="return (verify_checked_records() && verify_checked_tables());">};
 5038 
 5039                         } else {
 5040 
 5041                                 print q{>};
 5042                         }
 5043                 }
 5044 
 5045                 if ($flag_ok and ($new_enabled and $CGI_INPUT{new} and $insertrecord_enabled)) {
 5046 
 5047                         $br_for_new_enabled=1;
 5048 
 5049                         print qq{
 5050                                 <input type="submit" name="insertrecord" value="$button_insert"};
 5051 
 5052                         if (!$empty_db and $javascript_enabled) {
 5053 
 5054                                 print q{ onClick="return (verify_checked_records() && verify_checked_tables());">};
 5055 
 5056                         } else {
 5057 
 5058                                 print q{>};
 5059                         }
 5060                 }
 5061 
 5062                 if ($new_enabled) {
 5063 
 5064                         if ($br_for_new_enabled) {
 5065 
 5066                                 print q{
 5067                                         <br>
 5068                                         };
 5069                         }
 5070 
 5071                         print qq{
 5072                                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 5073                                 <input type="submit" name="new" value="$button_new"
 5074                                 };
 5075 
 5076                         if (!$empty_db and $javascript_enabled) {
 5077 
 5078                                 print q{ onClick="return verify_checked_tables();">};
 5079 
 5080                         } else {
 5081 
 5082                                 print q{>};
 5083                         }
 5084 
 5085                         print qq{
 5086                                 </font>
 5087                                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 5088                                 <select name="new_elem">
 5089                                 $new_values
 5090                                 </select>
 5091                                 </font>
 5092                                 };
 5093                 }
 5094 
 5095                 print q{
 5096                         </font>
 5097                         </td>
 5098                         </tr>
 5099                         </table>
 5100                         </td>
 5101                         </tr>
 5102                         };
 5103         }
 5104 
 5105         if ($select_enabled or 
 5106         ($selectfields_enabled and $CGI_INPUT{selectfields}) or 
 5107         $prepare_enabled) {
 5108 
 5109                 print qq{
 5110                         <tr>
 5111                         <td>
 5112                         <FONT FACE="$font_face" SIZE="$font_size" COLOR="$font_color">
 5113                         <b>$operations_on_query</b>
 5114                         </font>
 5115                         <table border="1">
 5116                         <tr>
 5117                         <td>
 5118                         <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 5119                         };
 5120 
 5121                 if ($prepare_enabled) {
 5122 
 5123                         print qq{
 5124                                 <input type="submit" name="prepare" value="$button_prepare"};
 5125 
 5126                         if (!$empty_db and $javascript_enabled) {
 5127 
 5128                                 print q{ onClick="return verify_checked_tables();">};
 5129 
 5130                         } else {
 5131 
 5132                                 print q{>};
 5133                         }
 5134 
 5135                         print q{
 5136                                 <br>
 5137                                 };
 5138                 }
 5139 
 5140                 if ($select_enabled) {
 5141 
 5142                         if ($selectfields_enabled and ($prepare_enabled and $CGI_INPUT{prepare})) {
 5143 
 5144                                 print qq{
 5145                                         <input type="hidden" name="withselectfields" value="1">
 5146                                         <input type="submit" name="select" value="$button_select_all"};
 5147 
 5148                                 if (!$empty_db and $javascript_enabled) {
 5149 
 5150                                         print q{ onClick="return (verify_existing_fields() && verify_checked_tables());">};
 5151 
 5152                                 } else {
 5153 
 5154                                         print q{>};
 5155                                 }
 5156 
 5157                         } else {
 5158 
 5159                                 print qq{
 5160                                         <input type="submit" name="select" value="$button_select_all"};
 5161 
 5162                                 if (!$empty_db and $javascript_enabled) {
 5163 
 5164                                         print q{ onClick="return verify_checked_tables();">};
 5165 
 5166                                 } else {
 5167 
 5168                                         print q{>};
 5169                                 }
 5170                         }
 5171                 }
 5172 
 5173                 if ($flag_ok and $selectfields_enabled and ($prepare_enabled and $CGI_INPUT{prepare})) {
 5174 
 5175                         print qq{
 5176                                 <br>
 5177                                 <input type="submit" name="selectfields" value="$button_select_chk"};
 5178 
 5179                         if (!$empty_db and $javascript_enabled) {
 5180 
 5181                                 print q{ onClick="return (verify_checked_records() && verify_checked_tables());">};
 5182 
 5183                         } else {
 5184 
 5185                                 print q{>};
 5186                         }
 5187                 }
 5188 
 5189                 if ($select_enabled or $selectfields_enabled) {
 5190 
 5191                         if ($flag_ok and ($prepare_enabled and $CGI_INPUT{prepare}) and $selectfields_enabled) {
 5192 
 5193                                 print q{
 5194                                         </font>
 5195                                         </td>
 5196                                         <td align="right">
 5197                                         <table border="0">
 5198                                         };
 5199 
 5200                                 foreach my $table_name (sort keys %PREPARE_NAMES) {
 5201 
 5202                                         print qq{
 5203                                                 <tr>
 5204                                                 <td>
 5205                                                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color"> $query_from <b>$table_name</b>
 5206                                                 </font>
 5207                                                 </td>
 5208                                                 };
 5209 
 5210                                         $tmp_name1='select_param'.$delimiter.'where'.$delimiter.$table_name;
 5211 
 5212                                         print qq{
 5213                                                 <td>
 5214                                                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 5215                                                 <input type="checkbox" name="$tmp_name1" value="on">&nbsp;$query_where
 5216                                                 </font>
 5217                                                 </td>
 5218                                                 <td>
 5219                                                 <FONT FACE="$button_font_face" SIZE="$button_font_size" COLOR="$button_font_color">
 5220                                                 };
 5221 
 5222                                         $tmp_name1='select_param'.$delimiter.'where_field'.$delimiter.$table_name;
 5223 
 5224                                         print qq{
 5225                                                 <select name="$tmp_name1">
 5226                                                 };
 5227 
 5228                                         my $tmp_fields_names='';
 5229 
 5230                                         foreach my $field_name (@{$PREPARE_NAMES{$table_name}}) {
 5231 
 5232                                                 $tmp_fields_names.=qq{
 5233