示例#1
0
function sql()
{
    global $sqlaction, $sv_s, $sv_d, $drp_tbl, $g_fp, $file_type, $dbbase, $f_nm;
    $secu_config = "xtdump_conf.inc.php";
    $dbhost = $_POST['dbhost'];
    $dbuser = $_POST['dbuser'];
    $dbpass = $_POST['dbpass'];
    $dbbase = $_POST['dbbase'];
    $tbls = $_POST['tbls'];
    $sqlaction = $_POST['sqlaction'];
    $secu = $_POST['secu'];
    $f_cut = $_POST['f_cut'];
    $max_sql = $_POST['max_sql'];
    $opt = $_POST['opt'];
    $savmode = $_POST['savmode'];
    $file_type = $_POST['file_type'];
    $ecraz = $_POST['ecraz'];
    $f_tbl = $_POST['f_tbl'];
    $drp_tbl = $_POST['drp_tbl'];
    $header = "<center><table width=620 cellpadding=0 cellspacing=0 align=center><col width=1><col width=600><col width=1><tr><td></td><td align=left class=texte><br>";
    $footer = "<center><a href='javascript:history.go(-1)' target='_self' class=link>-назад-</a><br></center><br></td><td></td></tr><tr><td height=1 colspan=3></td></tr></table></center>" . nfm_copyright();
    // SQL actions STARTS
    if ($sqlaction == 'save') {
        if ($secu == 1) {
            $fp = fopen($secu_config, "w");
            fputs($fp, "<?php\n");
            fputs($fp, "\$dbhost='{$dbhost}';\n");
            fputs($fp, "\$dbbase='{$dbbase}';\n");
            fputs($fp, "\$dbuser='******';\n");
            fputs($fp, "\$dbpass='******';\n");
            fputs($fp, "?>");
            fclose($fp);
        }
        if (!is_array($tbls)) {
            echo $header . "\r\n<br><center><font color=red>ТЫ ЗАБЫЛ выделить нужные тебе таблицы для дампинга =)</b></font></center>\n{$footer}";
            exit;
        }
        if ($f_cut == 1) {
            if (!is_numeric($max_sql)) {
                echo $header . "<br><center><font color=red><b>Ошибка.</b></font></center>\n{$footer}";
                exit;
            }
            if ($max_sql < 200000) {
                echo $header . "<br><center><font color=red><b>база sql больше 200 000 мб</b></font></center>\n{$footer}";
                exit;
            }
        }
        $tbl = array();
        $tbl[] = reset($tbls);
        if (count($tbls) > 1) {
            $a = true;
            while ($a != false) {
                $a = next($tbls);
                if ($a != false) {
                    $tbl[] = $a;
                }
            }
        }
        if ($opt == 1) {
            $sv_s = true;
            $sv_d = true;
        } else {
            if ($opt == 2) {
                $sv_s = true;
                $sv_d = false;
                $fc = "_struct";
            } else {
                if ($opt == 3) {
                    $sv_s = false;
                    $sv_d = true;
                    $fc = "_data";
                } else {
                    exit;
                }
            }
        }
        $fext = "." . $savmode;
        $fich = $dbbase . $fc . $fext;
        $dte = "";
        if ($ecraz != 1) {
            $dte = date("dMy_Hi") . "_";
        }
        $gz = "";
        if ($file_type == '1') {
            $gz .= ".gz";
        }
        $fcut = false;
        $ftbl = false;
        $f_nm = array();
        if ($f_cut == 1) {
            $fcut = true;
            $max_sql = $max_sql;
            $nbf = 1;
            $f_size = 170;
        }
        if ($f_tbl == 1) {
            $ftbl = true;
        } else {
            if (!$fcut) {
                open_file("dump_" . $dte . $dbbase . $fc . $fext . $gz);
            } else {
                open_file("dump_" . $dte . $dbbase . $fc . "_1" . $fext . $gz);
            }
        }
        $nbf = 1;
        mysql_connect($dbhost, $dbuser, $dbpass);
        mysql_select_db($dbbase);
        if ($fext == ".sql") {
            if ($ftbl) {
                while (list($i) = each($tbl)) {
                    $temp = sqldumptable($tbl[$i]);
                    $sz_t = strlen($temp);
                    if ($fcut) {
                        open_file("dump_" . $dte . $tbl[$i] . $fc . ".sql" . $gz);
                        $nbf = 0;
                        $p_sql = split_sql_file($temp);
                        while (list($j, $val) = each($p_sql)) {
                            if (file_pos() + 6 + strlen($val) < $max_sql) {
                                write_file($val . ";");
                            } else {
                                close_file();
                                $nbf++;
                                open_file("dump_" . $dte . $tbl[$i] . $fc . "_" . $nbf . ".sql" . $gz);
                                write_file($val . ";");
                            }
                        }
                        close_file();
                    } else {
                        open_file("dump_" . $dte . $tbl[$i] . $fc . ".sql" . $gz);
                        write_file($temp . "\n\n");
                        close_file();
                        $nbf = 1;
                    }
                    $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                }
            } else {
                $tblsv = "";
                while (list($i) = each($tbl)) {
                    $temp = sqldumptable($tbl[$i]);
                    $sz_t = strlen($temp);
                    if ($fcut && file_pos() + $sz_t > $max_sql) {
                        $p_sql = split_sql_file($temp);
                        while (list($j, $val) = each($p_sql)) {
                            if (file_pos() + 6 + strlen($val) < $max_sql) {
                                write_file($val . ";");
                            } else {
                                close_file();
                                $nbf++;
                                open_file("dump_" . $dte . $dbbase . $fc . "_" . $nbf . ".sql" . $gz);
                                write_file($val . ";");
                            }
                        }
                    } else {
                        write_file($temp);
                    }
                    $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                }
            }
        } else {
            if ($fext == ".csv") {
                if ($ftbl) {
                    while (list($i) = each($tbl)) {
                        $temp = csvdumptable($tbl[$i]);
                        $sz_t = strlen($temp);
                        if ($fcut) {
                            open_file("dump_" . $dte . $tbl[$i] . $fc . ".csv" . $gz);
                            $nbf = 0;
                            $p_csv = split_csv_file($temp);
                            while (list($j, $val) = each($p_csv)) {
                                if (file_pos() + 6 + strlen($val) < $max_sql) {
                                    write_file($val . "\n");
                                } else {
                                    close_file();
                                    $nbf++;
                                    open_file("dump_" . $dte . $tbl[$i] . $fc . "_" . $nbf . ".csv" . $gz);
                                    write_file($val . "\n");
                                }
                            }
                            close_file();
                        } else {
                            open_file("dump_" . $dte . $tbl[$i] . $fc . ".csv" . $gz);
                            write_file($temp . "\n\n");
                            close_file();
                            $nbf = 1;
                        }
                        $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                    }
                } else {
                    while (list($i) = each($tbl)) {
                        $temp = csvdumptable($tbl[$i]);
                        $sz_t = strlen($temp);
                        if ($fcut && file_pos() + $sz_t > $max_sql) {
                            $p_csv = split_sql_file($temp);
                            while (list($j, $val) = each($p_csv)) {
                                if (file_pos() + 6 + strlen($val) < $max_sql) {
                                    write_file($val . "\n");
                                } else {
                                    close_file();
                                    $nbf++;
                                    open_file("dump_" . $dte . $dbbase . $fc . "_" . $nbf . ".csv" . $gz);
                                    write_file($val . "\n");
                                }
                            }
                        } else {
                            write_file($temp);
                        }
                        $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                    }
                }
            }
        }
        mysql_close();
        if (!$ftbl) {
            close_file();
        }
        echo $header;
        echo "<br><center>Все данные в этих таблицах:<br> " . $tblsv . " помещены в файл указанный ниже:<br><br></center><table border='0' align='center' cellpadding='0' cellspacing='0'><col width=1 bgcolor='#2D7DA7'><col valign=center><col width=1 bgcolor='#2D7DA7'><col valign=center align=right><col width=1 bgcolor='#2D7DA7'><tr><td bgcolor='#2D7DA7' colspan=5></td></tr><tr><td></td><td bgcolor='#338CBD' align=center class=texte><font size=1><b>Файл</b></font></td><td></td><td bgcolor='#338CBD' align=center class=texte><font size=1><b>Размер</b></font></td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        reset($f_nm);
        while (list($i, $val) = each($f_nm)) {
            $coul = '#99CCCC';
            if ($i % 2) {
                $coul = '#CFE3E3';
            }
            echo "<tr><td></td><td bgcolor=" . $coul . " class=texte>&nbsp;<a href='" . $val . "' class=link target='_blank'>" . $val . "&nbsp;</a></td><td></td>";
            $fz_tmp = filesize($val);
            if ($fcut && $fz_tmp > $max_sql) {
                echo "<td bgcolor=" . $coul . " class=texte>&nbsp;<font size=1 color=red>" . $fz_tmp . " Octets</font>&nbsp;</td><td></td></tr>";
            } else {
                echo "<td bgcolor=" . $coul . " class=texte>&nbsp;<font size=1>" . $fz_tmp . " байт</font>&nbsp;</td><td></td></tr>";
            }
            echo "<tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        }
        echo "</table><br>";
        echo $footer;
        exit;
    }
    if ($sqlaction == 'connect') {
        if (!@mysql_connect($dbhost, $dbuser, $dbpass)) {
            echo $header . "<br><center><font color=red><b>Подключение не возможно! Проверьте правильно ли введены данные!</b></font></center>\n{$footer}";
            exit;
        }
        if (!@mysql_select_db($dbbase)) {
            echo $header . "<br><center><font color=red><<b>Подключение не возможно! Проверьте правельно ли введины данные!</b></font></center>\n{$footer}";
            exit;
        }
        if ($secu == 1) {
            if (!file_exists($secu_config)) {
                $fp = fopen($secu_config, "w");
                fputs($fp, "<?php\n");
                fputs($fp, "\$dbhost='{$dbhost}';\n");
                fputs($fp, "\$dbbase='{$dbbase}';\n");
                fputs($fp, "\$dbuser='******';\n");
                fputs($fp, "\$dbpass='******';\n");
                fputs($fp, "?>");
                fclose($fp);
            }
            include $secu_config;
        } else {
            if (file_exists($secu_config)) {
                unlink($secu_config);
            }
        }
        mysql_connect($dbhost, $dbuser, $dbpass);
        $tables = mysql_list_tables($dbbase);
        $nb_tbl = mysql_num_rows($tables);
        echo $header . "<script language='javascript'> function checkall() { var i=0;while (i < {$nb_tbl}) { a='tbls['+i+']';document.formu.elements[a].checked=true;i=i+1;} } function decheckall() { var i=0;while (i < {$nb_tbl}) { a='tbls['+i+']';document.formu.elements[a].checked=false;i=i+1;} } </script><center><br><b>Выбирите нужные вам таблицы для дампинга!</b><form action='' method='post' name=formu><input type='hidden' name='sqlaction' value='save'><input type='hidden' name='dbhost' value='{$dbhost}'><input type='hidden' name='dbbase' value='{$dbbase}'><input type='hidden' name='dbuser' value='{$dbuser}'><input type='hidden' name='dbpass' value='{$dbpass}'><DIV ID='infobull'></DIV><table border='0' width='400' align='center' cellpadding='0' cellspacing='0' class=texte><col width=1 bgcolor='#2D7DA7'><col width=30 align=center valign=center><col width=1 bgcolor='#2D7DA7'><col width=350> <col width=1 bgcolor='#2D7DA7'><tr><td bgcolor='#2D7DA7' colspan=5></td></tr><tr><td></td><td bgcolor='#336699'><input type='checkbox' name='selc' alt='Выделить всё' onclick='if (document.formu.selc.checked==true){checkall();}else{decheckall();}')\"></td><td></td><td bgcolor='#338CBD' align=center><B>Названия таблиц</b></td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        $i = 0;
        while ($i < mysql_num_rows($tables)) {
            $coul = '#99CCCC';
            if ($i % 2) {
                $coul = '#CFE3E3';
            }
            $tb_nom = mysql_tablename($tables, $i);
            echo "<tr><td></td><td bgcolor='" . $coul . "'><input type='checkbox' name='tbls[" . $i . "]' value='" . $tb_nom . "'></td><td></td><td bgcolor='" . $coul . "'>&nbsp;&nbsp;&nbsp;" . $tb_nom . "</td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
            $i++;
        }
        mysql_close();
        echo "</table><br><br><table align=center border=0><tr><td align=left class=texte> <hr> <input type='radio' name='savmode' value='csv'> \r\n  Сохранить в формате csv (*.<i>csv</i>)<br> <input type='radio' name='savmode' value='sql' checked> \r\n  Сохранить в формате Sql (*.<i>sql</i>)<br> <hr> <input type='radio' name='opt' value='1' checked>\r\n  Сохранить структуру и данные<br> <input type='radio' name='opt' value='2'>\r\n  Сохранить только структуру<br> <input type='radio' name='opt' value='3'>\r\n  Сохранить только данные<br> <hr> <input type='Checkbox' name='drp_tbl' value='1' checked>\r\n  Перезаписывать файл, если существует<br>  <input type='Checkbox' name='ecraz' value='1' checked>\r\n  Очистить базу после создания дампа<br> <input type='Checkbox' name='f_tbl' value='1'> \r\n  Помещать каждую таблицу в отдельный файл<br> <input type='Checkbox' name='f_cut' value='1'>\r\n  Максимальный размер одного дамп-файла: <input type='text' name='max_sql' value='200000' class=form>\r\n  Octets<br> <input type='Checkbox' name='file_type' value='1'>\r\n  Gzip.<br> \r\n  </td></tr></table><br><br><input type='submit' value=' Задампить:) ' class=form></form></center>{$footer}";
        exit;
    }
    // SQL actions END
    if (file_exists($secu_config)) {
        include $secu_config;
        $ck = "checked";
    } else {
        $dbhost = "localhost";
        $dbbase = "";
        $dbuser = "******";
        $dbpass = "";
        $ck = "";
    }
    echo $header . "\r\n<table width=620 cellpadding=0 cellspacing=0 align=center> \r\n <col width=1> \r\n <col width=600> \r\n <col width=1> \r\n <tr>\r\n  <td></td>\r\n  <td align=left class=texte>\r\n   <br>\r\n   <form action='' method='post'>\r\n   <input type='hidden' name='sqlaction' value='connect'> \r\n   <table border=0 align=center> \r\n    <col> \r\n    <col align=left> \r\n    <tr>\r\n     <td colspan=2 align=center style='font:bold 9pt;font-family:verdana;'>Введите данные для подключению к mySQL серверу!<br><br></td> \r\n    </tr> \r\n    <tr>\r\n     <td class=texte>Адрес сервера:</td> \r\n     <td><INPUT TYPE='TEXT' NAME='dbhost' SIZE='30' VALUE='localhost' class=form></td>\r\n    </tr> \r\n    <tr>\r\n     <td class=texte>Название базы:</td> \r\n     <td><INPUT TYPE='TEXT' NAME='dbbase' SIZE='30' VALUE='' class=form></td> \r\n    </tr> \r\n    <tr>\r\n     <td class=texte>Логин:</td> \r\n     <td><INPUT TYPE='TEXT' NAME='dbuser' SIZE='30' VALUE='root' class=form></td> \r\n    </tr> \r\n    <tr>\r\n     <td class=texte>Пароль</td> \r\n     <td><INPUT TYPE='Password' NAME='dbpass' SIZE='30' VALUE='' class=form></td> \r\n    </tr> \r\n   </table> \r\n   <br> <center> <br><br> \r\n   <input type='submit' value=' Подключится ' class=form></center> </form> <br><br> \r\n  </td> \r\n  <td></td> \r\n </tr> \r\n <tr> \r\n  <td height=1 colspan=3></td> \r\n </tr> \r\n</table>\r\n</center>";
}
function sql()
{
    global $sqlaction, $sv_s, $sv_d, $drp_tbl, $g_fp, $file_type, $dbbase, $f_nm;
    $secu_config = "xtdump_conf.inc.php";
    $dbhost = $_POST['dbhost'];
    $dbuser = $_POST['dbuser'];
    $dbpass = $_POST['dbpass'];
    $dbbase = $_POST['dbbase'];
    $tbls = $_POST['tbls'];
    $sqlaction = $_POST['sqlaction'];
    $secu = $_POST['secu'];
    $f_cut = $_POST['f_cut'];
    $fz_max = $_POST['fz_max'];
    $opt = $_POST['opt'];
    $savmode = $_POST['savmode'];
    $file_type = $_POST['file_type'];
    $ecraz = $_POST['ecraz'];
    $f_tbl = $_POST['f_tbl'];
    $drp_tbl = $_POST['drp_tbl'];
    $header = "<center><table width=620 cellpadding=0 cellspacing=0 align=center><col width=1><col width=600><col width=1><tr><td></td><td align=left class=texte><br>";
    $footer = "<center><a href='javascript:history.go(-1)' target='_self' class=link>-go back-</a><br></center><br></td><td></td></tr><tr><td height=1 colspan=3></td></tr></table></center>" . nfm_copyright();
    // SQL actions STARTS
    if ($sqlaction == 'save') {
        if ($secu == 1) {
            $fp = fopen($secu_config, "w");
            fputs($fp, "<?php\n");
            fputs($fp, "\$dbhost='{$dbhost}';\n");
            fputs($fp, "\$dbbase='{$dbbase}';\n");
            fputs($fp, "\$dbuser='******';\n");
            fputs($fp, "\$dbpass='******';\n");
            fputs($fp, "?>");
            fclose($fp);
        }
        if (!is_array($tbls)) {
            echo $header . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">\n\n<br><center><font color=red>You forgot to check tables, which you need to dump =)</b></font></center>\n{$footer}";
            exit;
        }
        if ($f_cut == 1) {
            if (!is_numeric($fz_max)) {
                echo $header . "<br><center><font color=red><b>Veuillez choisir une valeur num?rique ? la taille du fichier ? scinder.</b></font></center>\n{$footer}";
                exit;
            }
            if ($fz_max < 200000) {
                echo $header . "<br><center><font color=red><b>Veuillez choisir une taille de fichier a scinder sup\n\n    rieure ? 200 000 Octets.</b></font></center>\n{$footer}";
                exit;
            }
        }
        $tbl = array();
        $tbl[] = reset($tbls);
        if (count($tbls) > 1) {
            $a = true;
            while ($a != false) {
                $a = next($tbls);
                if ($a != false) {
                    $tbl[] = $a;
                }
            }
        }
        if ($opt == 1) {
            $sv_s = true;
            $sv_d = true;
        } else {
            if ($opt == 2) {
                $sv_s = true;
                $sv_d = false;
                $fc = "_struct";
            } else {
                if ($opt == 3) {
                    $sv_s = false;
                    $sv_d = true;
                    $fc = "_data";
                } else {
                    exit;
                }
            }
        }
        $fext = "." . $savmode;
        $fich = $dbbase . $fc . $fext;
        $dte = "";
        if ($ecraz != 1) {
            $dte = date("dMy_Hi") . "_";
        }
        $gz = "";
        if ($file_type == '1') {
            $gz .= ".gz";
        }
        $fcut = false;
        $ftbl = false;
        $f_nm = array();
        if ($f_cut == 1) {
            $fcut = true;
            $fz_max = $fz_max;
            $nbf = 1;
            $f_size = 170;
        }
        if ($f_tbl == 1) {
            $ftbl = true;
        } else {
            if (!$fcut) {
                open_file("dump_" . $dte . $dbbase . $fc . $fext . $gz);
            } else {
                open_file("dump_" . $dte . $dbbase . $fc . "_1" . $fext . $gz);
            }
        }
        $nbf = 1;
        mysql_connect($dbhost, $dbuser, $dbpass);
        mysql_select_db($dbbase);
        if ($fext == ".sql") {
            if ($ftbl) {
                while (list($i) = each($tbl)) {
                    $temp = sqldumptable($tbl[$i]);
                    $sz_t = strlen($temp);
                    if ($fcut) {
                        open_file("dump_" . $dte . $tbl[$i] . $fc . ".sql" . $gz);
                        $nbf = 0;
                        $p_sql = split_sql_file($temp);
                        while (list($j, $val) = each($p_sql)) {
                            if (file_pos() + 6 + strlen($val) < $fz_max) {
                                write_file($val . ";");
                            } else {
                                close_file();
                                $nbf++;
                                open_file("dump_" . $dte . $tbl[$i] . $fc . "_" . $nbf . ".sql" . $gz);
                                write_file($val . ";");
                            }
                        }
                        close_file();
                    } else {
                        open_file("dump_" . $dte . $tbl[$i] . $fc . ".sql" . $gz);
                        write_file($temp . "\n\n");
                        close_file();
                        $nbf = 1;
                    }
                    $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                }
            } else {
                $tblsv = "";
                while (list($i) = each($tbl)) {
                    $temp = sqldumptable($tbl[$i]);
                    $sz_t = strlen($temp);
                    if ($fcut && file_pos() + $sz_t > $fz_max) {
                        $p_sql = split_sql_file($temp);
                        while (list($j, $val) = each($p_sql)) {
                            if (file_pos() + 6 + strlen($val) < $fz_max) {
                                write_file($val . ";");
                            } else {
                                close_file();
                                $nbf++;
                                open_file("dump_" . $dte . $dbbase . $fc . "_" . $nbf . ".sql" . $gz);
                                write_file($val . ";");
                            }
                        }
                    } else {
                        write_file($temp);
                    }
                    $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                }
            }
        } else {
            if ($fext == ".csv") {
                if ($ftbl) {
                    while (list($i) = each($tbl)) {
                        $temp = csvdumptable($tbl[$i]);
                        $sz_t = strlen($temp);
                        if ($fcut) {
                            open_file("dump_" . $dte . $tbl[$i] . $fc . ".csv" . $gz);
                            $nbf = 0;
                            $p_csv = split_csv_file($temp);
                            while (list($j, $val) = each($p_csv)) {
                                if (file_pos() + 6 + strlen($val) < $fz_max) {
                                    write_file($val . "\n");
                                } else {
                                    close_file();
                                    $nbf++;
                                    open_file("dump_" . $dte . $tbl[$i] . $fc . "_" . $nbf . ".csv" . $gz);
                                    write_file($val . "\n");
                                }
                            }
                            close_file();
                        } else {
                            open_file("dump_" . $dte . $tbl[$i] . $fc . ".csv" . $gz);
                            write_file($temp . "\n\n");
                            close_file();
                            $nbf = 1;
                        }
                        $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                    }
                } else {
                    while (list($i) = each($tbl)) {
                        $temp = csvdumptable($tbl[$i]);
                        $sz_t = strlen($temp);
                        if ($fcut && file_pos() + $sz_t > $fz_max) {
                            $p_csv = split_sql_file($temp);
                            while (list($j, $val) = each($p_csv)) {
                                if (file_pos() + 6 + strlen($val) < $fz_max) {
                                    write_file($val . "\n");
                                } else {
                                    close_file();
                                    $nbf++;
                                    open_file("dump_" . $dte . $dbbase . $fc . "_" . $nbf . ".csv" . $gz);
                                    write_file($val . "\n");
                                }
                            }
                        } else {
                            write_file($temp);
                        }
                        $tblsv = $tblsv . "<b>" . $tbl[$i] . "</b>,<br>";
                    }
                }
            }
        }
        mysql_close();
        if (!$ftbl) {
            close_file();
        }
        echo $header;
        echo "<br><center>All the data in these tables:<br> " . $tblsv . " were putted to this file:<br><br></center><table border='0' align='center' cellpadding='0' cellspacing='0'><col width=1 bgcolor='#2D7DA7'><col valign=center><col width=1 bgcolor='#2D7DA7'><col valign=center align=right><col width=1 bgcolor='#2D7DA7'><tr><td bgcolor='#2D7DA7' colspan=5></td></tr><tr><td></td><td bgcolor='#338CBD' align=center class=texte><font size=1><b>File</b></font></td><td></td><td bgcolor='#338CBD' align=center class=texte><font size=1><b>Size</b></font></td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        reset($f_nm);
        while (list($i, $val) = each($f_nm)) {
            $coul = '#99CCCC';
            if ($i % 2) {
                $coul = '#CFE3E3';
            }
            echo "<tr><td></td><td bgcolor=" . $coul . " class=texte>&nbsp;<a href='" . $val . "' class=link target='_blank'>" . $val . "&nbsp;</a></td><td></td>";
            $fz_tmp = filesize($val);
            if ($fcut && $fz_tmp > $fz_max) {
                echo "<td bgcolor=" . $coul . " class=texte>&nbsp;<font size=1 color=red>" . $fz_tmp . " Octets</font>&nbsp;</td><td></td></tr>";
            } else {
                echo "<td bgcolor=" . $coul . " class=texte>&nbsp;<font size=1>" . $fz_tmp . " bites</font>&nbsp;</td><td></td></tr>";
            }
            echo "<tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        }
        echo "</table><br>";
        echo $footer;
        exit;
    }
    if ($sqlaction == 'connect') {
        if (!@mysql_connect($dbhost, $dbuser, $dbpass)) {
            echo $header . "<br><center><font color=red><b>Unable to connect! Check your data input!</b></font></center>\n{$footer}";
            exit;
        }
        if (!@mysql_select_db($dbbase)) {
            echo $header . "<br><center><font color=red><<b>Unable to connect! Check your data input!</b></font></center>\n{$footer}";
            exit;
        }
        if ($secu == 1) {
            if (!file_exists($secu_config)) {
                $fp = fopen($secu_config, "w");
                fputs($fp, "<?php\n");
                fputs($fp, "\$dbhost='{$dbhost}';\n");
                fputs($fp, "\$dbbase='{$dbbase}';\n");
                fputs($fp, "\$dbuser='******';\n");
                fputs($fp, "\$dbpass='******';\n");
                fputs($fp, "?>");
                fclose($fp);
            }
            include $secu_config;
        } else {
            if (file_exists($secu_config)) {
                unlink($secu_config);
            }
        }
        mysql_connect($dbhost, $dbuser, $dbpass);
        $tables = mysql_list_tables($dbbase);
        $nb_tbl = mysql_num_rows($tables);
        echo $header . "<script language='javascript'> function checkall() { var i=0;while (i < {$nb_tbl}) { a='tbls['+i+']';document.formu.elements[a].checked=true;i=i+1;} } function decheckall() { var i=0;while (i < {$nb_tbl}) { a='tbls['+i+']';document.formu.elements[a].checked=false;i=i+1;} } </script><center><br><b>Choose tables you need to dump!</b><form action='' method='post' name=formu><input type='hidden' name='sqlaction' value='save'><input type='hidden' name='dbhost' value='{$dbhost}'><input type='hidden' name='dbbase' value='{$dbbase}'><input type='hidden' name='dbuser' value='{$dbuser}'><input type='hidden' name='dbpass' value='{$dbpass}'><DIV ID='infobull'></DIV><table border='0' width='400' align='center' cellpadding='0' cellspacing='0' class=texte><col width=1 bgcolor='#2D7DA7'><col width=30 align=center valign=center><col width=1 bgcolor='#2D7DA7'><col width=350> <col width=1 bgcolor='#2D7DA7'><tr><td bgcolor='#2D7DA7' colspan=5></td></tr><tr><td></td><td bgcolor='#336699'><input type='checkbox' name='selc' alt='Check all' onclick='if (document.formu.selc.checked==true){checkall();}else{decheckall();}')\"></td><td></td><td bgcolor='#338CBD' align=center><B>Table names</b></td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
        $i = 0;
        while ($i < mysql_num_rows($tables)) {
            $coul = '#99CCCC';
            if ($i % 2) {
                $coul = '#CFE3E3';
            }
            $tb_nom = mysql_tablename($tables, $i);
            echo "<tr><td></td><td bgcolor='" . $coul . "'><input type='checkbox' name='tbls[" . $i . "]' value='" . $tb_nom . "'></td><td></td><td bgcolor='" . $coul . "'>&nbsp;&nbsp;&nbsp;" . $tb_nom . "</td><td></td></tr><tr><td bgcolor='#2D7DA7' colspan=5></td></tr>";
            $i++;
        }
        mysql_close();
        echo "</table><br><br><table align=center border=0><tr><td align=left class=texte> <hr> <input type='radio' name='savmode' value='csv'>\n\n  Save to csv (*.<i>csv</i>)<br> <input type='radio' name='savmode' value='sql' checked>\n\n  Save to Sql (*.<i>sql</i>)<br> <hr> <input type='radio' name='opt' value='1' checked>\n\n  Save structure and data<br> <input type='radio' name='opt' value='2'>\n\n  Save structure only<br> <input type='radio' name='opt' value='3'>\n\n  Save data only<br> <hr> <input type='Checkbox' name='drp_tbl' value='1' checked>\n\n  Rewrite file if exists<br>  <input type='Checkbox' name='ecraz' value='1' checked>\n\n  Clear database after dump<br> <input type='Checkbox' name='f_tbl' value='1'>\n\n  Put each table to a separate file<br> <input type='Checkbox' name='f_cut' value='1'>\n\n  Maximum dump-file size: <input type='text' name='fz_max' value='200000' class=form>\n\n  Octets<br> <input type='Checkbox' name='file_type' value='1'>\n\n  Gzip.<br>\n\n  </td></tr></table><br><br><input type='submit' value=' Dump:) ' class=form></form></center>{$footer}";
        exit;
    }
    // SQL actions END
    if (file_exists($secu_config)) {
        include $secu_config;
        $ck = "checked";
    } else {
        $dbhost = "localhost";
        $dbbase = "";
        $dbuser = "******";
        $dbpass = "";
        $ck = "";
    }
    echo $header . "\n\n<center><br><br>\n\n<table width=620 cellpadding=0 cellspacing=0 align=center>\n\n <col width=1>\n\n <col width=600>\n\n <col width=1>\n\n <tr>\n\n  <td></td>\n\n  <td align=left class=texte>\n\n   <br>\n\n   <form action='' method='post'>\n\n   <input type='hidden' name='sqlaction' value='connect'>\n\n   <table border=0 align=center>\n\n    <col>\n\n    <col align=left>\n\n    <tr>\n\n     <td colspan=2 align=center style='font:bold 9pt;font-family:verdana;'>Enter data to connect to MySQL server!<br><br></td>\n\n    </tr>\n\n    <tr>\n\n     <td class=texte>Server address:</td>\n\n     <td><INPUT TYPE='TEXT' NAME='dbhost' SIZE='30' VALUE='localhost' class=form></td>\n\n    </tr>\n\n    <tr>\n\n     <td class=texte>Base name:</td>\n\n     <td><INPUT TYPE='TEXT' NAME='dbbase' SIZE='30' VALUE='' class=form></td>\n\n    </tr>\n\n    <tr>\n\n     <td class=texte>Login:</td>\n\n     <td><INPUT TYPE='TEXT' NAME='dbuser' SIZE='30' VALUE='root' class=form></td>\n\n    </tr>\n\n    <tr>\n\n     <td class=texte>Password</td>\n\n     <td><INPUT TYPE='Password' NAME='dbpass' SIZE='30' VALUE='' class=form></td>\n\n    </tr>\n\n   </table>\n\n   <br> <center> <br><br>\n\n   <input type='submit' value=' Connect ' class=form></center> </form> <br><br>\n\n  </td>\n\n  <td></td>\n\n </tr>\n\n <tr>\n\n  <td height=1 colspan=3></td>\n\n </tr>\n\n</table>\n\n</center>";
}