function do_toggleinstructions() { global $client; $page = mqrequest('page'); hideinstructions(hideinstructions() ? '' : 'hide'); if ($page == 'history') { draw_history(); } else { draw_balance(); } }
function process_tinyadm() { global $db; @session_start(); remove_magic_quotes(); if (!isset($_SESSION['user'])) { $_SESSION['user'] = ''; } if (!isset($_SESSION['password'])) { $_SESSION['password'] = ''; } if (!isset($_SESSION['database'])) { $_SESSION['database'] = ''; } if (!isset($_SESSION['table'])) { $_SESSION['table'] = ''; } if (!isset($_SESSION['last_sql'])) { $_SESSION['last_sql'] = ''; } if (!isset($_SESSION['sql_history'])) { $_SESSION['sql_history'] = array(); } $act = get_var('act'); if ($act == 'login') { setcookie('tinymy_user', get_var('user'), time() + 5184000); // 2 months $_SESSION['user'] = addslashes(get_var('user')); $_SESSION['password'] = addslashes(get_var('password')); } $db = new sqldb($_SESSION['user'], $_SESSION['password'], $_SESSION['database']); if (!$db->is_connected()) { return draw_login_form(); } if ($act == 'login') { // switch to default databas if (get_cookie('tinymy_database')) { $_SESSION['database'] = get_cookie('tinymy_database'); } } switch ($act) { case 'sel_db': $_SESSION['database'] = get_var('d'); $_SESSION['table'] = ''; setcookie('tinymy_database', get_var('d'), time() + 5184000); // 2 months redirect_self(); exit; case 'use_history': $idx = (int) get_var('idx'); if (isset($_SESSION['sql_history'][$idx])) { $_SESSION['database'] = $_SESSION['sql_history'][$idx]['db']; $_SESSION['last_sql'] = $_SESSION['sql_history'][$idx]['sql']; } redirect_self(); exit; case 'sel_table': $_SESSION['table'] = get_var('table'); break; case 'do_export': ob_end_clean(); // we need to pass through the following output from export immediately, without caching do_export(); break; case 'logout': session_unset(); session_destroy(); redirect_self(); exit; case 'exec_sql': history_add(get_var('sql')); } ob_start(); // menu needs to be created after the possible sql has executed echo '<div id="content">'; if ($act != 'export' && $act != 'do_export') { draw_sqlarea(); } switch ($act) { case 'history': draw_history(); break; case 'export': draw_export(); break; case 'sel_db': break; case 'sel_table': case 'show_structure': h('<p style="margin-bottom: 8px;"><a href="?act=show_contents">Show contents of %s</a></p>', $_SESSION['table']); exec_sql_internal(sprintf('desc `%s`', mysqli_escape_string($db->conn_id, $_SESSION['table']))); exec_sql_singlerow(sprintf('show create table `%s`', mysqli_escape_string($db->conn_id, $_SESSION['table']))); break; case 'show_contents': h('<p style="margin-bottom: 8px;"><a href="?act=show_structure">Show structure of %s</a></p>', $_SESSION['table']); $res = mysqli_query($db->conn_id, sprintf("select count(*) from `%s`", mysqli_escape_string($db->conn_id, $_SESSION['table']))); if (!$res) { $db->error(); // } else { list($reccount) = mysqli_fetch_row($res); pager($reccount); exec_sql_internal(sprintf('select * from `%s` %s', mysqli_escape_string($db->conn_id, $_SESSION['table']), pager_limits())); } case 'exec_sql': exec_sql(); // in case the query changed the database, switch to it $cur_database = $db->get_current_database(); if ($cur_database != $_SESSION['database']) { $_SESSION['database'] = $cur_database; setcookie('tinymy_database', $cur_database, time() + 5184000); // 2 months } break; } echo '</div>'; // content $content = ob_get_contents(); ob_end_clean(); // menu needs to be created after all the sql has executed draw_db_menu(); echo $content; }