Esempio n. 1
0
        /**
         * Handles displaying of the DatabaseBrowser admin page
         * 
         * @since 1.0
         */
        function adminPage()
        {
            echo '
			<div class="wrap" id="databasebrowser">
				<h2>' . __("Database browser", "databasebrowser") . '</h2>
			';
            // if no query is being run
            if ($this->querytype == "") {
                // show the navigation and return
                include_once "views/navigation.php";
                return;
            }
            // if a table has been chosen
            if (wp_verify_nonce(@$_GET["_wpnonce"], "query") && $this->querytype == "table") {
                // get the limit
                if (@$_POST["limit"] != "") {
                    $_SESSION["limit"] = (int) $_POST["limit"];
                    $this->limit = (int) $_POST["limit"];
                }
                // create the new paginator
                $paginator = new Paginator($this->limit);
                // load the table
                $this->loadTable($paginator->findStart(), $this->limit);
                // include the title view
                $title = sprintf(__("Table: %s", "databasebrowser"), $this->table);
                include_once "views/title.php";
                // include the filters view
                include_once "views/filters.php";
                // include the results view
                include_once "views/results.php";
                return;
            }
            // if a custom query is being run
            if (wp_verify_nonce(@$_GET["_wpnonce"], "query") && $this->querytype == "customquery") {
                // see if this query is being saved
                $queryname = trim(@$_POST["queryname"]);
                if ($queryname != "") {
                    $this->saveQuery($queryname, $this->query, true);
                }
                // run the query
                $this->runQuery($this->query);
                // include the title view
                $title = __("Custom query", "databasebrowser");
                include_once "views/title.php";
                // include the query view
                include_once "views/query.php";
                // include the results view
                include_once "views/results.php";
                return;
            }
            // if a stored query is being run
            if (wp_verify_nonce(@$_GET["_wpnonce"], "query") && $this->querytype == "storedquery") {
                // save this query
                $this->saveQuery($this->queryname, $this->query, false);
                // run the query
                $this->runQuery($this->query);
                // include the title view
                $title = sprintf(__("Stored query: %s", "databasebrowser"), $this->queryname);
                include_once "views/title.php";
                // include the query view
                include_once "views/query.php";
                // include the results view
                include_once "views/results.php";
                return;
            }
            // if we get here something has gone wrong, so show the navigation
            include_once "views/navigation.php";
        }
Esempio n. 2
0
        function adminPage()
        {
            echo '
			<div class="wrap" id="databasebrowser">
				<h1>' . __("Database browser", "databasebrowser") . '</h1>
			';
            // if a table has been chosen, load the data
            if (wp_verify_nonce(@$_GET["_wpnonce"], "table") && $this->table != "") {
                $limit = 100;
                $paginator = new Paginator($limit);
                $custom = false;
                // if a query has been given
                if (isset($_POST["query"]) || isset($_SESSION["custom_query"])) {
                    $custom = true;
                    $tablename = "Custom query";
                    $query = @$_POST["query"];
                    if ($query == "") {
                        $query = $_SESSION["custom_query"];
                    }
                    $this->runQuery($query);
                } else {
                    // load the table
                    $this->loadTable($paginator->findStart(), $limit);
                    $tablename = $this->table;
                }
                echo '
				<h2>' . sprintf(__("Table: %s", "databasebrowser"), $tablename) . '</h2>
				';
                if ($this->error != null && $this->error != "") {
                    echo '
					<div id="message" class="updated">
						<p><strong>' . __("Database error", "databasebrowser") . '</strong></p>
						<p>' . $this->error . '</p>
					</div>
					';
                }
                // if a query has not been given
                if (!$custom) {
                    echo '
				<form action="' . $this->formURL . '" method="post">
				<p><label id="wherelabel" for="where">' . __("Where (click to toggle):", "databasebrowser") . '</label>
					<textarea name="where" cols="30" rows="6" style="width:100%;height:4em" class="hider" id="where">' . @stripslashes($_POST["where"]) . '</textarea>
				</p>
				<p><label id="orderbylabel" for="orderby">' . __("Order by (click to toggle):", "databasebrowser") . '</label>
					<textarea name="orderby" cols="30" rows="6" style="width:100%;height:4em" class="hider" id="orderby">' . @stripslashes($_POST["orderby"]) . '</textarea>
				</p>
				<p><button type="submit" class="button">' . __("Run where and order by clauses", "databasebrowser") . '</button>
				' . wp_nonce_field("query") . '</p>
				</form>
				';
                }
                // no data found
                if ($this->rowcount == 0) {
                    echo '
					<div id="message" class="updated">
						<p><strong>' . __("No data was found in this table.", "databasebrowser") . '</strong></p>
					</div>';
                } else {
                    $paginator->findPages($this->rowcount);
                    // write the export links
                    $this->exportLinks();
                    // write the data table with pagination (if not running a custom query)
                    if (!$custom) {
                        echo $paginator->links;
                    }
                    echo '<div class="tablewrapper">';
                    echo $this->toHTML("widefat");
                    echo '</div>';
                    if (!$custom) {
                        echo $paginator->links;
                    }
                    // write the export links
                    $this->exportLinks();
                }
            }
            // load tables
            $this->loadTables();
            // show tables list
            echo '
			<form action="tools.php?page=databasebrowser" method="post">
			<p>
				<label for="tablelist">' . __("Select table", "databasebrowser") . '</label>
				<select name="table" id="tablelist">
				';
            foreach ($this->tables as $table) {
                echo '
					<option value="' . $table . '">' . $table . '</option>
					';
            }
            echo '
				</select>
				<input type="submit" class="button-primary" value="' . __("Select table", "databasebrowser") . '" />
				' . wp_nonce_field("table") . '
			</p>
			</form>
			';
            if ($this->query != null && $this->query != "") {
                echo '
				<form action="tools.php?page=databasebrowser&amp;table=' . $this->table . '&amp;_wpnonce=' . wp_create_nonce("table") . '" method="post">
				<h4 id="queryheader">' . __("Query performed (click to toggle):", "databasebrowser") . '</h4>
				<div class="hider" id="query">
					<p><textarea name="query" cols="30" rows="10" style="width:100%;height:10em">' . $this->query . '</textarea></p>
					<p><input type="submit" class="button" value="' . __("Run query", "databasebrowser") . '" />
					' . wp_nonce_field("query") . '</p>
				</div>
				</form>
				';
            }
            echo '
			</div>
			';
        }