<?php /** * $Id$ * * @category ImportTools * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkAdmin(); $databases = CImportTools::getAllDatabaseInfo(); foreach ($databases as $_dsn => &$_info) { $_info = CImportTools::getDatabaseStructure($_dsn, true); } $smarty = new CSmartyDP(); $smarty->assign("databases", $databases); $smarty->display("vw_database_explorer.tpl");
<?php /** * $Id: ajax_select_primary_key.php 27769 2015-03-30 08:45:03Z phenxdesign $ * * @category ImportTools * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: 27769 $ * @link http://www.mediboard.org */ CCanDo::checkAdmin(); $dsn = CValue::get("dsn"); $table = CValue::get("table"); $column = CValue::get("column"); $db_info = CImportTools::getDatabaseStructure($dsn); $smarty = new CSmartyDP(); $smarty->assign("dsn", $dsn); $smarty->assign("table", $table); $smarty->assign("column", $column); $smarty->assign("db_info", $db_info); $smarty->display("inc_select_primary_key.tpl");
* @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkAdmin(); $dsn = CValue::get("dsn"); $table = CValue::get("table"); $tooltip = CValue::get("tooltip"); $start = (int) CValue::get("start"); $count = (int) CValue::getOrSession("count", 50); $order_column = CValue::getOrSession("order_column"); $order_way = CValue::getOrSession("order_way", "ASC"); $where_column = CValue::get("where_column"); $where_value = CValue::get("where_value"); $ds = CSQLDataSource::get($dsn); $columns = CImportTools::getColumnsInfo($ds, $table); $orderby = ""; if ($order_column) { $order_column = preg_replace('/[^-_\\w]/', "", $order_column); if (in_array($order_column, array_keys($columns))) { if (!in_array($order_way, array("ASC", "DESC"))) { $order_way = "ASC"; } $orderby = "{$order_column} {$order_way}"; } } $request = new CRequest(); $request->addTable($table); $request->addSelect("*"); $request->setLimit("{$start},{$count}"); if ($orderby) {
/** * Get full database structure * * @param string $dsn Datasource name * @param bool $count Count each table entries * * @return mixed * @throws Exception */ static function getDatabaseStructure($dsn, $count = false) { $databases = CImportTools::getAllDatabaseInfo(); if (!isset($databases[$dsn])) { throw new Exception("DSN not found : {$dsn}"); } $db_info = $databases[$dsn]; $ds = CSQLDataSource::get($dsn); // Description file $description = new DOMDocument(); $description->load($db_info["description_file"]); $description->_xpath = new DOMXPath($description); $db_info["description"] = $description; // Tables $table_names = $ds->loadTables(); $tables = array(); foreach ($table_names as $_table_name) { $_table_info = CImportTools::getTableInfo($ds, $_table_name); if ($count) { $_table_info["count"] = $ds->loadResult("SELECT COUNT(*) FROM {$_table_name}"); } $tables[$_table_name] = $_table_info; } $db_info["tables"] = $tables; return $db_info; }