Converted referrals_report.php to standard security model, take 2.
[openemr.git] / phpmyadmin / libraries / db_common.inc.php
blob2cfc9c091f6fac228a0978cb0b5593c66c9d3f83
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Common includes for the database level views
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Gets some core libraries
15 require_once './libraries/bookmark.lib.php';
17 PMA_Util::checkParameters(array('db'));
19 global $cfg;
20 global $db;
22 $is_show_stats = $cfg['ShowStats'];
24 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db);
25 if ($db_is_system_schema) {
26 $is_show_stats = false;
29 /**
30 * Defines the urls to return to in case of error in a sql statement
32 $err_url_0 = 'index.php' . PMA_URL_getCommon();
34 $err_url = PMA_Util::getScriptNameForOption(
35 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
37 . PMA_URL_getCommon(array('db' => $db));
39 /** @var PMA_String $pmaString */
40 $pmaString = $GLOBALS['PMA_String'];
42 /**
43 * Ensures the database exists (else move to the "parent" script) and displays
44 * headers
46 if (! isset($is_db) || ! $is_db) {
47 if (/*overload*/mb_strlen($db)) {
48 $is_db = $GLOBALS['dbi']->selectDb($db);
49 // This "Command out of sync" 2014 error may happen, for example
50 // after calling a MySQL procedure; at this point we can't select
51 // the db but it's not necessarily wrong
52 if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
53 $is_db = true;
54 unset($GLOBALS['errno']);
56 } else {
57 $is_db = false;
59 // Not a valid db name -> back to the welcome page
60 $uri = $cfg['PmaAbsoluteUri'] . 'index.php'
61 . PMA_URL_getCommon(array(), 'text')
62 . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1';
63 if (!/*overload*/mb_strlen($db) || ! $is_db) {
64 $response = PMA_Response::getInstance();
65 if ($response->isAjax()) {
66 $response->isSuccess(false);
67 $response->addJSON(
68 'message',
69 PMA_Message::error(__('No databases selected.'))
71 } else {
72 PMA_sendHeaderLocation($uri);
74 exit;
76 } // end if (ensures db exists)
78 /**
79 * Changes database charset if requested by the user
81 if (isset($_REQUEST['submitcollation'])
82 && isset($_REQUEST['db_collation'])
83 && ! empty($_REQUEST['db_collation'])
84 ) {
85 list($db_charset) = explode('_', $_REQUEST['db_collation']);
86 $sql_query = 'ALTER DATABASE '
87 . PMA_Util::backquote($db)
88 . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
89 $result = $GLOBALS['dbi']->query($sql_query);
90 $message = PMA_Message::success();
91 unset($db_charset);
93 /**
94 * If we are in an Ajax request, let us stop the execution here. Necessary for
95 * db charset change action on db_operations.php. If this causes a bug on
96 * other pages, we might have to move this to a different location.
98 if ($GLOBALS['is_ajax_request'] == true) {
99 $response = PMA_Response::getInstance();
100 $response->isSuccess($message->isSuccess());
101 $response->addJSON('message', $message);
102 exit;
107 * Set parameters for links
109 $url_query = PMA_URL_getCommon(array('db' => $db));