Rename variables to use camel case format
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
40cc4a0dee
commit
437215cab2
@ -19,12 +19,12 @@ if (false === @include_once 'OpenID/RelyingParty.php') {
|
||||
}
|
||||
|
||||
/* Change this to true if using phpMyAdmin over https */
|
||||
$secure_cookie = false;
|
||||
$secureCookie = false;
|
||||
|
||||
/**
|
||||
* Map of authenticated users to MySQL user/password pairs.
|
||||
*/
|
||||
$AUTH_MAP = [
|
||||
$authMap = [
|
||||
'https://launchpad.net/~username' => [
|
||||
'user' => 'root',
|
||||
'password' => '',
|
||||
@ -79,10 +79,10 @@ function Die_error($e): void
|
||||
// phpcs:enable
|
||||
|
||||
/* Need to have cookie visible from parent directory */
|
||||
session_set_cookie_params(0, '/', '', $secure_cookie, true);
|
||||
session_set_cookie_params(0, '/', '', $secureCookie, true);
|
||||
/* Create signon session */
|
||||
$session_name = 'SignonSession';
|
||||
session_name($session_name);
|
||||
$sessionName = 'SignonSession';
|
||||
session_name($sessionName);
|
||||
@session_start();
|
||||
|
||||
// Determine realm and return_to
|
||||
@ -158,13 +158,13 @@ try {
|
||||
|
||||
$id = $message->get('openid.claimed_id');
|
||||
|
||||
if (empty($id) || ! isset($AUTH_MAP[$id])) {
|
||||
if (empty($id) || ! isset($authMap[$id])) {
|
||||
Show_page('<p>User not allowed!</p>');
|
||||
exit;
|
||||
}
|
||||
|
||||
$_SESSION['PMA_single_signon_user'] = $AUTH_MAP[$id]['user'];
|
||||
$_SESSION['PMA_single_signon_password'] = $AUTH_MAP[$id]['password'];
|
||||
$_SESSION['PMA_single_signon_user'] = $authMap[$id]['user'];
|
||||
$_SESSION['PMA_single_signon_password'] = $authMap[$id]['password'];
|
||||
$_SESSION['PMA_single_signon_HMAC_secret'] = hash('sha1', uniqid(strval(random_int(0, mt_getrandmax())), true));
|
||||
session_write_close();
|
||||
/* Redirect to phpMyAdmin (should use absolute URL here!) */
|
||||
|
||||
@ -12,12 +12,12 @@ declare(strict_types=1);
|
||||
/* Use cookies for session */
|
||||
ini_set('session.use_cookies', 'true');
|
||||
/* Change this to true if using phpMyAdmin over https */
|
||||
$secure_cookie = false;
|
||||
$secureCookie = false;
|
||||
/* Need to have cookie visible from parent directory */
|
||||
session_set_cookie_params(0, '/', '', $secure_cookie, true);
|
||||
session_set_cookie_params(0, '/', '', $secureCookie, true);
|
||||
/* Create signon session */
|
||||
$session_name = 'SignonSession';
|
||||
session_name($session_name);
|
||||
$sessionName = 'SignonSession';
|
||||
session_name($sessionName);
|
||||
// Uncomment and change the following line to match your $cfg['SessionSavePath']
|
||||
//session_save_path('/foobar');
|
||||
@session_start();
|
||||
|
||||
@ -153,8 +153,8 @@ class Bookmark
|
||||
// remove comments that encloses a variable placeholder
|
||||
$query = (string) preg_replace('|/\*(.*\[VARIABLE[0-9]*\].*)\*/|imsU', '${1}', $this->query);
|
||||
// replace variable placeholders with values
|
||||
$number_of_variables = $this->getVariableCount();
|
||||
for ($i = 1; $i <= $number_of_variables; $i++) {
|
||||
$numberOfVariables = $this->getVariableCount();
|
||||
for ($i = 1; $i <= $numberOfVariables; $i++) {
|
||||
$var = '';
|
||||
if (! empty($variables[$i])) {
|
||||
$var = $this->dbi->escapeString($variables[$i]);
|
||||
@ -175,27 +175,27 @@ class Bookmark
|
||||
/**
|
||||
* Creates a Bookmark object from the parameters
|
||||
*
|
||||
* @param array $bkm_fields the properties of the bookmark to add; here, $bkm_fields['bkm_sql_query'] is urlencoded
|
||||
* @param bool $all_users whether to make the bookmark available for all users
|
||||
* @param array $bkmFields the properties of the bookmark to add; here, $bkm_fields['bkm_sql_query'] is urlencoded
|
||||
* @param bool $allUsers whether to make the bookmark available for all users
|
||||
*/
|
||||
public static function createBookmark(
|
||||
DatabaseInterface $dbi,
|
||||
array $bkm_fields,
|
||||
bool $all_users = false,
|
||||
array $bkmFields,
|
||||
bool $allUsers = false,
|
||||
): Bookmark|false {
|
||||
if (
|
||||
! (isset($bkm_fields['bkm_sql_query'], $bkm_fields['bkm_label'])
|
||||
&& strlen($bkm_fields['bkm_sql_query']) > 0
|
||||
&& strlen($bkm_fields['bkm_label']) > 0)
|
||||
! (isset($bkmFields['bkm_sql_query'], $bkmFields['bkm_label'])
|
||||
&& strlen($bkmFields['bkm_sql_query']) > 0
|
||||
&& strlen($bkmFields['bkm_label']) > 0)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bookmark = new Bookmark($dbi, new Relation($dbi));
|
||||
$bookmark->database = $bkm_fields['bkm_database'];
|
||||
$bookmark->label = $bkm_fields['bkm_label'];
|
||||
$bookmark->query = $bkm_fields['bkm_sql_query'];
|
||||
$bookmark->currentUser = $all_users ? '' : $bkm_fields['bkm_user'];
|
||||
$bookmark->database = $bkmFields['bkm_database'];
|
||||
$bookmark->label = $bkmFields['bkm_label'];
|
||||
$bookmark->query = $bkmFields['bkm_sql_query'];
|
||||
$bookmark->currentUser = $allUsers ? '' : $bkmFields['bkm_user'];
|
||||
|
||||
return $bookmark;
|
||||
}
|
||||
@ -255,13 +255,13 @@ class Bookmark
|
||||
/**
|
||||
* Retrieve a specific bookmark
|
||||
*
|
||||
* @param string $user Current user
|
||||
* @param DatabaseName $db the current database name
|
||||
* @param int|string $id an identifier of the bookmark to get
|
||||
* @param string $id_field which field to look up the identifier
|
||||
* @param bool $action_bookmark_all true: get all bookmarks regardless
|
||||
* @param string $user Current user
|
||||
* @param DatabaseName $db the current database name
|
||||
* @param int|string $id an identifier of the bookmark to get
|
||||
* @param string $idField which field to look up the identifier
|
||||
* @param bool $actionBookmarkAll true: get all bookmarks regardless
|
||||
* of the owning user
|
||||
* @param bool $exact_user_match whether to ignore bookmarks with no user
|
||||
* @param bool $exactUserMatch whether to ignore bookmarks with no user
|
||||
*
|
||||
* @return Bookmark|null the bookmark
|
||||
*/
|
||||
@ -270,9 +270,9 @@ class Bookmark
|
||||
string $user,
|
||||
DatabaseName $db,
|
||||
int|string $id,
|
||||
string $id_field = 'id',
|
||||
bool $action_bookmark_all = false,
|
||||
bool $exact_user_match = false,
|
||||
string $idField = 'id',
|
||||
bool $actionBookmarkAll = false,
|
||||
bool $exactUserMatch = false,
|
||||
): self|null {
|
||||
$relation = new Relation($dbi);
|
||||
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
|
||||
@ -283,16 +283,16 @@ class Bookmark
|
||||
$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
|
||||
. '.' . Util::backquote($bookmarkFeature->bookmark)
|
||||
. ' WHERE dbase = ' . $dbi->quoteString($db->getName());
|
||||
if (! $action_bookmark_all) {
|
||||
if (! $actionBookmarkAll) {
|
||||
$query .= ' AND (user = ' . $dbi->quoteString($user);
|
||||
if (! $exact_user_match) {
|
||||
if (! $exactUserMatch) {
|
||||
$query .= " OR user = ''";
|
||||
}
|
||||
|
||||
$query .= ')';
|
||||
}
|
||||
|
||||
$query .= ' AND ' . Util::backquote($id_field)
|
||||
$query .= ' AND ' . Util::backquote($idField)
|
||||
. ' = ' . $dbi->quoteString((string) $id) . ' LIMIT 1';
|
||||
|
||||
$result = $dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, Connection::TYPE_CONTROL);
|
||||
|
||||
@ -168,10 +168,10 @@ final class CacheWarmupCommand extends Command
|
||||
// Generate line map
|
||||
/** @psalm-suppress InternalMethod */
|
||||
$cacheFilename = $twigCache->generateKey($name, $twig->getTemplateClass($name));
|
||||
$template_file = 'templates/' . $name;
|
||||
$cache_file = str_replace($tmpDir, 'twig-templates', $cacheFilename);
|
||||
$templateFile = 'templates/' . $name;
|
||||
$cacheFile = str_replace($tmpDir, 'twig-templates', $cacheFilename);
|
||||
/** @psalm-suppress InternalMethod */
|
||||
$replacements[$cache_file] = [$template_file, $template->getDebugInfo()];
|
||||
$replacements[$cacheFile] = [$templateFile, $template->getDebugInfo()];
|
||||
}
|
||||
|
||||
if (! $writeReplacements) {
|
||||
|
||||
@ -156,19 +156,19 @@ class Config
|
||||
/**
|
||||
* Sets the client platform based on user agent
|
||||
*
|
||||
* @param string $user_agent the user agent
|
||||
* @param string $userAgent the user agent
|
||||
*/
|
||||
private function setClientPlatform(string $user_agent): void
|
||||
private function setClientPlatform(string $userAgent): void
|
||||
{
|
||||
if (mb_strstr($user_agent, 'Win')) {
|
||||
if (mb_strstr($userAgent, 'Win')) {
|
||||
$this->set('PMA_USR_OS', 'Win');
|
||||
} elseif (mb_strstr($user_agent, 'Mac')) {
|
||||
} elseif (mb_strstr($userAgent, 'Mac')) {
|
||||
$this->set('PMA_USR_OS', 'Mac');
|
||||
} elseif (mb_strstr($user_agent, 'Linux')) {
|
||||
} elseif (mb_strstr($userAgent, 'Linux')) {
|
||||
$this->set('PMA_USR_OS', 'Linux');
|
||||
} elseif (mb_strstr($user_agent, 'Unix')) {
|
||||
} elseif (mb_strstr($userAgent, 'Unix')) {
|
||||
$this->set('PMA_USR_OS', 'Unix');
|
||||
} elseif (mb_strstr($user_agent, 'OS/2')) {
|
||||
} elseif (mb_strstr($userAgent, 'OS/2')) {
|
||||
$this->set('PMA_USR_OS', 'OS/2');
|
||||
} else {
|
||||
$this->set('PMA_USR_OS', 'Other');
|
||||
@ -183,60 +183,60 @@ class Config
|
||||
*/
|
||||
public function checkClient(): void
|
||||
{
|
||||
$HTTP_USER_AGENT = '';
|
||||
$httpUserAgent = '';
|
||||
if (Core::getenv('HTTP_USER_AGENT')) {
|
||||
$HTTP_USER_AGENT = Core::getenv('HTTP_USER_AGENT');
|
||||
$httpUserAgent = Core::getenv('HTTP_USER_AGENT');
|
||||
}
|
||||
|
||||
// 1. Platform
|
||||
$this->setClientPlatform($HTTP_USER_AGENT);
|
||||
$this->setClientPlatform($httpUserAgent);
|
||||
|
||||
// 2. browser and version
|
||||
// (must check everything else before Mozilla)
|
||||
|
||||
$is_mozilla = preg_match('@Mozilla/([0-9]\.[0-9]{1,2})@', $HTTP_USER_AGENT, $mozilla_version);
|
||||
$isMozilla = preg_match('@Mozilla/([0-9]\.[0-9]{1,2})@', $httpUserAgent, $mozillaVersion);
|
||||
|
||||
if (preg_match('@Opera(/| )([0-9]\.[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[2]);
|
||||
if (preg_match('@Opera(/| )([0-9]\.[0-9]{1,2})@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[2]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
|
||||
} elseif (preg_match('@(MS)?IE ([0-9]{1,2}\.[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[2]);
|
||||
} elseif (preg_match('@(MS)?IE ([0-9]{1,2}\.[0-9]{1,2})@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[2]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'IE');
|
||||
} elseif (preg_match('@Trident/(7)\.0@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', intval($log_version[1]) + 4);
|
||||
} elseif (preg_match('@Trident/(7)\.0@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', intval($logVersion[1]) + 4);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'IE');
|
||||
} elseif (preg_match('@OmniWeb/([0-9]{1,3})@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[1]);
|
||||
} elseif (preg_match('@OmniWeb/([0-9]{1,3})@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
|
||||
// Konqueror 2.2.2 says Konqueror/2.2.2
|
||||
// Konqueror 3.0.3 says Konqueror/3
|
||||
} elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[2]);
|
||||
} elseif (preg_match('@(Konqueror/)(.*)(;)@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[2]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
|
||||
// must check Chrome before Safari
|
||||
} elseif ($is_mozilla && preg_match('@Chrome/([0-9.]*)@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[1]);
|
||||
} elseif ($isMozilla && preg_match('@Chrome/([0-9.]*)@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'CHROME');
|
||||
// newer Safari
|
||||
} elseif ($is_mozilla && preg_match('@Version/(.*) Safari@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[1]);
|
||||
} elseif ($isMozilla && preg_match('@Version/(.*) Safari@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
|
||||
// older Safari
|
||||
} elseif ($is_mozilla && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $mozilla_version[1] . '.' . $log_version[1]);
|
||||
} elseif ($isMozilla && preg_match('@Safari/([0-9]*)@', $httpUserAgent, $logVersion)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $mozillaVersion[1] . '.' . $logVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
|
||||
// Firefox
|
||||
} elseif (
|
||||
! mb_strstr($HTTP_USER_AGENT, 'compatible')
|
||||
&& preg_match('@Firefox/([\w.]+)@', $HTTP_USER_AGENT, $log_version)
|
||||
! mb_strstr($httpUserAgent, 'compatible')
|
||||
&& preg_match('@Firefox/([\w.]+)@', $httpUserAgent, $logVersion)
|
||||
) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $log_version[1]);
|
||||
$this->set('PMA_USR_BROWSER_VER', $logVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'FIREFOX');
|
||||
} elseif (preg_match('@rv:1\.9(.*)Gecko@', $HTTP_USER_AGENT)) {
|
||||
} elseif (preg_match('@rv:1\.9(.*)Gecko@', $httpUserAgent)) {
|
||||
$this->set('PMA_USR_BROWSER_VER', '1.9');
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
|
||||
} elseif ($is_mozilla) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $mozilla_version[1]);
|
||||
} elseif ($isMozilla) {
|
||||
$this->set('PMA_USR_BROWSER_VER', $mozillaVersion[1]);
|
||||
$this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
|
||||
} else {
|
||||
$this->set('PMA_USR_BROWSER_VER', 0);
|
||||
@ -268,8 +268,8 @@ class Config
|
||||
}
|
||||
|
||||
if (function_exists('gd_info')) {
|
||||
$gd_nfo = gd_info();
|
||||
if (mb_strstr($gd_nfo['GD Version'], '2.')) {
|
||||
$gdInfo = gd_info();
|
||||
if (mb_strstr($gdInfo['GD Version'], '2.')) {
|
||||
$this->set('PMA_IS_GD2', 1);
|
||||
|
||||
return;
|
||||
@ -371,7 +371,7 @@ class Config
|
||||
ob_start();
|
||||
try {
|
||||
/** @psalm-suppress UnresolvableInclude */
|
||||
$eval_result = include $this->getSource();
|
||||
$evalResult = include $this->getSource();
|
||||
} catch (Throwable) {
|
||||
throw new ConfigException('Failed to load phpMyAdmin configuration.');
|
||||
}
|
||||
@ -382,7 +382,7 @@ class Config
|
||||
error_reporting($oldErrorReporting);
|
||||
}
|
||||
|
||||
if ($eval_result === false) {
|
||||
if ($evalResult === false) {
|
||||
$this->errorConfigFile = true;
|
||||
} else {
|
||||
$this->errorConfigFile = false;
|
||||
@ -416,12 +416,12 @@ class Config
|
||||
*/
|
||||
private function setConnectionCollation(): void
|
||||
{
|
||||
$collation_connection = $this->get('DefaultConnectionCollation');
|
||||
if (empty($collation_connection) || $collation_connection == $GLOBALS['collation_connection']) {
|
||||
$collationConnection = $this->get('DefaultConnectionCollation');
|
||||
if (empty($collationConnection) || $collationConnection == $GLOBALS['collationConnection']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['dbi']->setCollation($collation_connection);
|
||||
$GLOBALS['dbi']->setCollation($collationConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -435,34 +435,34 @@ class Config
|
||||
$server = $GLOBALS['server'] ?? (! empty($GLOBALS['cfg']['ServerDefault'])
|
||||
? $GLOBALS['cfg']['ServerDefault']
|
||||
: 0);
|
||||
$cache_key = 'server_' . $server;
|
||||
$cacheKey = 'server_' . $server;
|
||||
if ($server > 0 && ! $isMinimumCommon) {
|
||||
// cache user preferences, use database only when needed
|
||||
if (
|
||||
! isset($_SESSION['cache'][$cache_key]['userprefs'])
|
||||
|| $_SESSION['cache'][$cache_key]['config_mtime'] < $this->sourceMtime
|
||||
! isset($_SESSION['cache'][$cacheKey]['userprefs'])
|
||||
|| $_SESSION['cache'][$cacheKey]['config_mtime'] < $this->sourceMtime
|
||||
) {
|
||||
$userPreferences = new UserPreferences($GLOBALS['dbi']);
|
||||
$prefs = $userPreferences->load();
|
||||
$_SESSION['cache'][$cache_key]['userprefs'] = $userPreferences->apply($prefs['config_data']);
|
||||
$_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
|
||||
$_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
|
||||
$_SESSION['cache'][$cache_key]['config_mtime'] = $this->sourceMtime;
|
||||
$_SESSION['cache'][$cacheKey]['userprefs'] = $userPreferences->apply($prefs['config_data']);
|
||||
$_SESSION['cache'][$cacheKey]['userprefs_mtime'] = $prefs['mtime'];
|
||||
$_SESSION['cache'][$cacheKey]['userprefs_type'] = $prefs['type'];
|
||||
$_SESSION['cache'][$cacheKey]['config_mtime'] = $this->sourceMtime;
|
||||
}
|
||||
} elseif ($server == 0 || ! isset($_SESSION['cache'][$cache_key]['userprefs'])) {
|
||||
} elseif ($server == 0 || ! isset($_SESSION['cache'][$cacheKey]['userprefs'])) {
|
||||
$this->set('user_preferences', false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$config_data = $_SESSION['cache'][$cache_key]['userprefs'];
|
||||
$configData = $_SESSION['cache'][$cacheKey]['userprefs'];
|
||||
// type is 'db' or 'session'
|
||||
$this->set('user_preferences', $_SESSION['cache'][$cache_key]['userprefs_type']);
|
||||
$this->set('user_preferences_mtime', $_SESSION['cache'][$cache_key]['userprefs_mtime']);
|
||||
$this->set('user_preferences', $_SESSION['cache'][$cacheKey]['userprefs_type']);
|
||||
$this->set('user_preferences_mtime', $_SESSION['cache'][$cacheKey]['userprefs_mtime']);
|
||||
|
||||
// load config array
|
||||
$this->settings = array_replace_recursive($this->settings, $config_data);
|
||||
$GLOBALS['cfg'] = array_replace_recursive($GLOBALS['cfg'], $config_data);
|
||||
$this->settings = array_replace_recursive($this->settings, $configData);
|
||||
$GLOBALS['cfg'] = array_replace_recursive($GLOBALS['cfg'], $configData);
|
||||
|
||||
if ($isMinimumCommon) {
|
||||
return;
|
||||
@ -476,10 +476,10 @@ class Config
|
||||
$tmanager = ThemeManager::getInstance();
|
||||
if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) {
|
||||
if (
|
||||
(! isset($config_data['ThemeDefault'])
|
||||
(! isset($configData['ThemeDefault'])
|
||||
&& $tmanager->theme->getId() !== 'original')
|
||||
|| isset($config_data['ThemeDefault'])
|
||||
&& $config_data['ThemeDefault'] != $tmanager->theme->getId()
|
||||
|| isset($configData['ThemeDefault'])
|
||||
&& $configData['ThemeDefault'] != $tmanager->theme->getId()
|
||||
) {
|
||||
$this->setUserValue(
|
||||
null,
|
||||
@ -502,17 +502,17 @@ class Config
|
||||
// save language
|
||||
if ($this->issetCookie('pma_lang') || isset($_POST['lang'])) {
|
||||
if (
|
||||
(! isset($config_data['lang'])
|
||||
(! isset($configData['lang'])
|
||||
&& $GLOBALS['lang'] !== 'en')
|
||||
|| isset($config_data['lang'])
|
||||
&& $GLOBALS['lang'] != $config_data['lang']
|
||||
|| isset($configData['lang'])
|
||||
&& $GLOBALS['lang'] != $configData['lang']
|
||||
) {
|
||||
$this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
|
||||
}
|
||||
} else {
|
||||
// read language from settings
|
||||
if (isset($config_data['lang'])) {
|
||||
$language = LanguageManager::getInstance()->getLanguage($config_data['lang']);
|
||||
if (isset($configData['lang'])) {
|
||||
$language = LanguageManager::getInstance()->getLanguage($configData['lang']);
|
||||
if ($language !== false) {
|
||||
$language->activate();
|
||||
$this->setCookie('pma_lang', $language->getCode());
|
||||
@ -532,42 +532,42 @@ class Config
|
||||
* global config and added to a update queue, which is processed
|
||||
* by {@link loadUserPreferences()}
|
||||
*
|
||||
* @param string|null $cookie_name can be null
|
||||
* @param string $cfg_path configuration path
|
||||
* @param mixed $new_cfg_value new value
|
||||
* @param string|null $default_value default value
|
||||
* @param string|null $cookieName can be null
|
||||
* @param string $cfgPath configuration path
|
||||
* @param mixed $newCfgValue new value
|
||||
* @param string|null $defaultValue default value
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function setUserValue(
|
||||
string|null $cookie_name,
|
||||
string $cfg_path,
|
||||
mixed $new_cfg_value,
|
||||
string|null $default_value = null,
|
||||
string|null $cookieName,
|
||||
string $cfgPath,
|
||||
mixed $newCfgValue,
|
||||
string|null $defaultValue = null,
|
||||
): bool|Message {
|
||||
$userPreferences = new UserPreferences($GLOBALS['dbi']);
|
||||
$result = true;
|
||||
// use permanent user preferences if possible
|
||||
$prefs_type = $this->get('user_preferences');
|
||||
if ($prefs_type) {
|
||||
if ($default_value === null) {
|
||||
$default_value = Core::arrayRead($cfg_path, $this->default);
|
||||
$prefsType = $this->get('user_preferences');
|
||||
if ($prefsType) {
|
||||
if ($defaultValue === null) {
|
||||
$defaultValue = Core::arrayRead($cfgPath, $this->default);
|
||||
}
|
||||
|
||||
$result = $userPreferences->persistOption($cfg_path, $new_cfg_value, $default_value);
|
||||
$result = $userPreferences->persistOption($cfgPath, $newCfgValue, $defaultValue);
|
||||
}
|
||||
|
||||
if ($prefs_type !== 'db' && $cookie_name) {
|
||||
if ($prefsType !== 'db' && $cookieName) {
|
||||
// fall back to cookies
|
||||
if ($default_value === null) {
|
||||
$default_value = Core::arrayRead($cfg_path, $this->settings);
|
||||
if ($defaultValue === null) {
|
||||
$defaultValue = Core::arrayRead($cfgPath, $this->settings);
|
||||
}
|
||||
|
||||
$this->setCookie($cookie_name, (string) $new_cfg_value, $default_value);
|
||||
$this->setCookie($cookieName, (string) $newCfgValue, $defaultValue);
|
||||
}
|
||||
|
||||
Core::arrayWrite($cfg_path, $GLOBALS['cfg'], $new_cfg_value);
|
||||
Core::arrayWrite($cfg_path, $this->settings, $new_cfg_value);
|
||||
Core::arrayWrite($cfgPath, $GLOBALS['cfg'], $newCfgValue);
|
||||
Core::arrayWrite($cfgPath, $this->settings, $newCfgValue);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -575,24 +575,24 @@ class Config
|
||||
/**
|
||||
* Reads value stored by {@link setUserValue()}
|
||||
*
|
||||
* @param string $cookie_name cookie name
|
||||
* @param mixed $cfg_value config value
|
||||
* @param string $cookieName cookie name
|
||||
* @param mixed $cfgValue config value
|
||||
*/
|
||||
public function getUserValue(string $cookie_name, mixed $cfg_value): mixed
|
||||
public function getUserValue(string $cookieName, mixed $cfgValue): mixed
|
||||
{
|
||||
$cookie_exists = ! empty($this->getCookie($cookie_name));
|
||||
$prefs_type = $this->get('user_preferences');
|
||||
if ($prefs_type === 'db') {
|
||||
$cookieExists = ! empty($this->getCookie($cookieName));
|
||||
$prefsType = $this->get('user_preferences');
|
||||
if ($prefsType === 'db') {
|
||||
// permanent user preferences value exists, remove cookie
|
||||
if ($cookie_exists) {
|
||||
$this->removeCookie($cookie_name);
|
||||
if ($cookieExists) {
|
||||
$this->removeCookie($cookieName);
|
||||
}
|
||||
} elseif ($cookie_exists) {
|
||||
return $this->getCookie($cookie_name);
|
||||
} elseif ($cookieExists) {
|
||||
return $this->getCookie($cookieName);
|
||||
}
|
||||
|
||||
// return value from $cfg array
|
||||
return $cfg_value;
|
||||
return $cfgValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -783,42 +783,42 @@ class Config
|
||||
*/
|
||||
public function isHttps(): bool
|
||||
{
|
||||
$is_https = $this->get('is_https');
|
||||
if ($is_https !== null) {
|
||||
return (bool) $is_https;
|
||||
$isHttps = $this->get('is_https');
|
||||
if ($isHttps !== null) {
|
||||
return (bool) $isHttps;
|
||||
}
|
||||
|
||||
$url = $this->get('PmaAbsoluteUri');
|
||||
|
||||
$is_https = false;
|
||||
$isHttps = false;
|
||||
if (! empty($url) && parse_url($url, PHP_URL_SCHEME) === 'https') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTP_SCHEME')) === 'https') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTPS')) === 'on') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(substr(Core::getenv('REQUEST_URI'), 0, 6)) === 'https:') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTP_HTTPS_FROM_LB')) === 'on') {
|
||||
// A10 Networks load balancer
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTP_FRONT_END_HTTPS')) === 'on') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTP_X_FORWARDED_PROTO')) === 'https') {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (strtolower(Core::getenv('HTTP_CLOUDFRONT_FORWARDED_PROTO')) === 'https') {
|
||||
// Amazon CloudFront, issue #15621
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (Util::getProtoFromForwardedHeader(Core::getenv('HTTP_FORWARDED')) === 'https') {
|
||||
// RFC 7239 Forwarded header
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
} elseif (Core::getenv('SERVER_PORT') == 443) {
|
||||
$is_https = true;
|
||||
$isHttps = true;
|
||||
}
|
||||
|
||||
$this->set('is_https', $is_https);
|
||||
$this->set('is_https', $isHttps);
|
||||
|
||||
return $is_https;
|
||||
return $isHttps;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -828,10 +828,10 @@ class Config
|
||||
*/
|
||||
public function getRootPath(): string
|
||||
{
|
||||
static $cookie_path = null;
|
||||
static $cookiePath = null;
|
||||
|
||||
if ($cookie_path !== null && ! defined('TESTSUITE')) {
|
||||
return $cookie_path;
|
||||
if ($cookiePath !== null && ! defined('TESTSUITE')) {
|
||||
return $cookiePath;
|
||||
}
|
||||
|
||||
$url = $this->get('PmaAbsoluteUri');
|
||||
@ -1048,10 +1048,10 @@ class Config
|
||||
*/
|
||||
public function getTempDir(string $name): string|null
|
||||
{
|
||||
static $temp_dir = [];
|
||||
static $tempDir = [];
|
||||
|
||||
if (isset($temp_dir[$name]) && ! defined('TESTSUITE')) {
|
||||
return $temp_dir[$name];
|
||||
if (isset($tempDir[$name]) && ! defined('TESTSUITE')) {
|
||||
return $tempDir[$name];
|
||||
}
|
||||
|
||||
$path = $this->get('TempDir');
|
||||
@ -1068,7 +1068,7 @@ class Config
|
||||
}
|
||||
}
|
||||
|
||||
$temp_dir[$name] = $path;
|
||||
$tempDir[$name] = $path;
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
@ -347,14 +347,14 @@ class Relation
|
||||
{
|
||||
// From 4.3, new input oriented transformation feature was introduced.
|
||||
// Check whether column_info table has input transformation columns
|
||||
$new_cols = [
|
||||
$newCols = [
|
||||
'input_transformation',
|
||||
'input_transformation_options',
|
||||
];
|
||||
$query = 'SHOW COLUMNS FROM '
|
||||
. Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
|
||||
. '.' . Util::backquote($GLOBALS['cfg']['Server']['column_info'])
|
||||
. ' WHERE Field IN (\'' . implode('\', \'', $new_cols) . '\')';
|
||||
. ' WHERE Field IN (\'' . implode('\', \'', $newCols) . '\')';
|
||||
$result = $this->dbi->tryQueryAsControlUser($query);
|
||||
if ($result) {
|
||||
$rows = $result->numRows();
|
||||
@ -420,24 +420,24 @@ class Relation
|
||||
$foreign = [];
|
||||
|
||||
if ($relationFeature !== null && ($source === 'both' || $source === 'internal')) {
|
||||
$rel_query = 'SELECT `master_field`, `foreign_db`, '
|
||||
$relQuery = 'SELECT `master_field`, `foreign_db`, '
|
||||
. '`foreign_table`, `foreign_field`'
|
||||
. ' FROM ' . Util::backquote($relationFeature->database)
|
||||
. '.' . Util::backquote($relationFeature->relation)
|
||||
. ' WHERE `master_db` = ' . $this->dbi->quoteString($db)
|
||||
. ' AND `master_table` = ' . $this->dbi->quoteString($table);
|
||||
if (strlen($column) > 0) {
|
||||
$rel_query .= ' AND `master_field` = ' . $this->dbi->quoteString($column);
|
||||
$relQuery .= ' AND `master_field` = ' . $this->dbi->quoteString($column);
|
||||
}
|
||||
|
||||
$foreign = $this->dbi->fetchResult($rel_query, 'master_field', null, Connection::TYPE_CONTROL);
|
||||
$foreign = $this->dbi->fetchResult($relQuery, 'master_field', null, Connection::TYPE_CONTROL);
|
||||
}
|
||||
|
||||
if (($source === 'both' || $source === 'foreign') && strlen($table) > 0) {
|
||||
$tableObj = new Table($table, $db, $this->dbi);
|
||||
$show_create_table = $tableObj->showCreate();
|
||||
if ($show_create_table) {
|
||||
$parser = new Parser($show_create_table);
|
||||
$showCreateTable = $tableObj->showCreate();
|
||||
if ($showCreateTable) {
|
||||
$parser = new Parser($showCreateTable);
|
||||
$stmt = $parser->statements[0];
|
||||
$foreign['foreign_keys_data'] = [];
|
||||
if ($stmt instanceof CreateStatement) {
|
||||
@ -492,14 +492,14 @@ class Relation
|
||||
* Try to fetch the display field from DB.
|
||||
*/
|
||||
if ($displayFeature !== null) {
|
||||
$disp_query = 'SELECT `display_field`'
|
||||
$dispQuery = 'SELECT `display_field`'
|
||||
. ' FROM ' . Util::backquote($displayFeature->database)
|
||||
. '.' . Util::backquote($displayFeature->tableInfo)
|
||||
. ' WHERE `db_name` = ' . $this->dbi->quoteString($db)
|
||||
. ' AND `table_name` = ' . $this->dbi->quoteString($table);
|
||||
|
||||
$row = $this->dbi->fetchSingleRow(
|
||||
$disp_query,
|
||||
$dispQuery,
|
||||
DatabaseInterface::FETCH_ASSOC,
|
||||
Connection::TYPE_CONTROL,
|
||||
);
|
||||
@ -573,16 +573,16 @@ class Relation
|
||||
$columnCommentsFeature = $this->getRelationParameters()->columnCommentsFeature;
|
||||
if ($columnCommentsFeature !== null) {
|
||||
// pmadb internal db comment
|
||||
$com_qry = 'SELECT `comment`'
|
||||
$comQry = 'SELECT `comment`'
|
||||
. ' FROM ' . Util::backquote($columnCommentsFeature->database)
|
||||
. '.' . Util::backquote($columnCommentsFeature->columnInfo)
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($db, Connection::TYPE_CONTROL)
|
||||
. ' AND table_name = \'\''
|
||||
. ' AND column_name = \'(db_comment)\'';
|
||||
$com_rs = $this->dbi->tryQueryAsControlUser($com_qry);
|
||||
$comRs = $this->dbi->tryQueryAsControlUser($comQry);
|
||||
|
||||
if ($com_rs && $com_rs->numRows() > 0) {
|
||||
$row = $com_rs->fetchAssoc();
|
||||
if ($comRs && $comRs->numRows() > 0) {
|
||||
$row = $comRs->fetchAssoc();
|
||||
|
||||
return (string) $row['comment'];
|
||||
}
|
||||
@ -602,14 +602,14 @@ class Relation
|
||||
|
||||
if ($columnCommentsFeature !== null) {
|
||||
// pmadb internal db comment
|
||||
$com_qry = 'SELECT `db_name`, `comment`'
|
||||
$comQry = 'SELECT `db_name`, `comment`'
|
||||
. ' FROM ' . Util::backquote($columnCommentsFeature->database)
|
||||
. '.' . Util::backquote($columnCommentsFeature->columnInfo)
|
||||
. ' WHERE `column_name` = \'(db_comment)\'';
|
||||
$com_rs = $this->dbi->tryQueryAsControlUser($com_qry);
|
||||
$comRs = $this->dbi->tryQueryAsControlUser($comQry);
|
||||
|
||||
if ($com_rs && $com_rs->numRows() > 0) {
|
||||
return $com_rs->fetchAllKeyPair();
|
||||
if ($comRs && $comRs->numRows() > 0) {
|
||||
return $comRs->fetchAllKeyPair();
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,7 +630,7 @@ class Relation
|
||||
}
|
||||
|
||||
if (strlen($comment) > 0) {
|
||||
$upd_query = 'INSERT INTO '
|
||||
$updQuery = 'INSERT INTO '
|
||||
. Util::backquote($columnCommentsFeature->database) . '.'
|
||||
. Util::backquote($columnCommentsFeature->columnInfo)
|
||||
. ' (`db_name`, `table_name`, `column_name`, `comment`)'
|
||||
@ -642,7 +642,7 @@ class Relation
|
||||
. ' ON DUPLICATE KEY UPDATE '
|
||||
. '`comment` = ' . $this->dbi->quoteString($comment, Connection::TYPE_CONTROL);
|
||||
} else {
|
||||
$upd_query = 'DELETE FROM '
|
||||
$updQuery = 'DELETE FROM '
|
||||
. Util::backquote($columnCommentsFeature->database) . '.'
|
||||
. Util::backquote($columnCommentsFeature->columnInfo)
|
||||
. ' WHERE `db_name` = ' . $this->dbi->quoteString($db, Connection::TYPE_CONTROL)
|
||||
@ -651,7 +651,7 @@ class Relation
|
||||
AND `column_name` = \'(db_comment)\'';
|
||||
}
|
||||
|
||||
return (bool) $this->dbi->queryAsControlUser($upd_query);
|
||||
return (bool) $this->dbi->queryAsControlUser($updQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -737,7 +737,7 @@ class Relation
|
||||
return false;
|
||||
}
|
||||
|
||||
$hist_query = '
|
||||
$histQuery = '
|
||||
SELECT `db`,
|
||||
`table`,
|
||||
`sqlquery`,
|
||||
@ -747,7 +747,7 @@ class Relation
|
||||
WHERE `username` = ' . $this->dbi->quoteString($username) . '
|
||||
ORDER BY `id` DESC';
|
||||
|
||||
return $this->dbi->fetchResult($hist_query, null, null, Connection::TYPE_CONTROL);
|
||||
return $this->dbi->fetchResult($histQuery, null, null, Connection::TYPE_CONTROL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -765,7 +765,7 @@ class Relation
|
||||
return;
|
||||
}
|
||||
|
||||
$search_query = '
|
||||
$searchQuery = '
|
||||
SELECT `timevalue`
|
||||
FROM ' . Util::backquote($sqlHistoryFeature->database)
|
||||
. '.' . Util::backquote($sqlHistoryFeature->history) . '
|
||||
@ -773,9 +773,9 @@ class Relation
|
||||
ORDER BY `timevalue` DESC
|
||||
LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1';
|
||||
|
||||
$max_time = $this->dbi->fetchValue($search_query, 0, Connection::TYPE_CONTROL);
|
||||
$maxTime = $this->dbi->fetchValue($searchQuery, 0, Connection::TYPE_CONTROL);
|
||||
|
||||
if (! $max_time) {
|
||||
if (! $maxTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -785,7 +785,7 @@ class Relation
|
||||
. Util::backquote($sqlHistoryFeature->history) . '
|
||||
WHERE `username` = ' . $this->dbi->quoteString($username, Connection::TYPE_CONTROL)
|
||||
. '
|
||||
AND `timevalue` <= \'' . $max_time . '\'',
|
||||
AND `timevalue` <= \'' . $maxTime . '\'',
|
||||
);
|
||||
}
|
||||
|
||||
@ -882,18 +882,18 @@ class Relation
|
||||
/**
|
||||
* Outputs dropdown with values of foreign fields
|
||||
*
|
||||
* @param array[] $disp_row array of the displayed row
|
||||
* @param string $foreign_field the foreign field
|
||||
* @param string $foreign_display the foreign field to display
|
||||
* @param string $data the current data of the dropdown (field in row)
|
||||
* @param int|null $max maximum number of items in the dropdown
|
||||
* @param array[] $dispRow array of the displayed row
|
||||
* @param string $foreignField the foreign field
|
||||
* @param string $foreignDisplay the foreign field to display
|
||||
* @param string $data the current data of the dropdown (field in row)
|
||||
* @param int|null $max maximum number of items in the dropdown
|
||||
*
|
||||
* @return string the <option value=""><option>s
|
||||
*/
|
||||
public function foreignDropdown(
|
||||
array $disp_row,
|
||||
string $foreign_field,
|
||||
string $foreign_display,
|
||||
array $dispRow,
|
||||
string $foreignField,
|
||||
string $foreignDisplay,
|
||||
string $data,
|
||||
int|null $max = null,
|
||||
): string {
|
||||
@ -904,12 +904,12 @@ class Relation
|
||||
$foreign = [];
|
||||
|
||||
// collect the data
|
||||
foreach ($disp_row as $relrow) {
|
||||
$key = $relrow[$foreign_field];
|
||||
foreach ($dispRow as $relrow) {
|
||||
$key = $relrow[$foreignField];
|
||||
|
||||
// if the display field has been defined for this foreign table
|
||||
if ($foreign_display) {
|
||||
$value = $relrow[$foreign_display];
|
||||
if ($foreignDisplay) {
|
||||
$value = $relrow[$foreignDisplay];
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
@ -920,7 +920,7 @@ class Relation
|
||||
// put the dropdown sections in correct order
|
||||
$top = [];
|
||||
$bottom = [];
|
||||
if ($foreign_display) {
|
||||
if ($foreignDisplay) {
|
||||
if (
|
||||
isset($GLOBALS['cfg']['ForeignKeyDropdownOrder'])
|
||||
&& is_array($GLOBALS['cfg']['ForeignKeyDropdownOrder'])
|
||||
@ -958,17 +958,17 @@ class Relation
|
||||
|
||||
// beginning of dropdown
|
||||
$ret = '<option value=""> </option>';
|
||||
$top_count = count($top);
|
||||
if ($max == -1 || $top_count < $max) {
|
||||
$topCount = count($top);
|
||||
if ($max == -1 || $topCount < $max) {
|
||||
$ret .= implode('', $top);
|
||||
if ($foreign_display && $top_count > 0) {
|
||||
if ($foreignDisplay && $topCount > 0) {
|
||||
// this empty option is to visually mark the beginning of the
|
||||
// second series of values (bottom)
|
||||
$ret .= '<option value=""> </option>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($foreign_display) {
|
||||
if ($foreignDisplay) {
|
||||
$ret .= implode('', $bottom);
|
||||
}
|
||||
|
||||
@ -978,12 +978,12 @@ class Relation
|
||||
/**
|
||||
* Gets foreign keys in preparation for a drop-down selector
|
||||
*
|
||||
* @param array|bool $foreigners array of the foreign keys
|
||||
* @param string $field the foreign field name
|
||||
* @param bool $override_total whether to override the total
|
||||
* @param string $foreign_filter a possible filter
|
||||
* @param string $foreign_limit a possible LIMIT clause
|
||||
* @param bool $get_total optional, whether to get total num of rows
|
||||
* @param array|bool $foreigners array of the foreign keys
|
||||
* @param string $field the foreign field name
|
||||
* @param bool $overrideTotal whether to override the total
|
||||
* @param string $foreignFilter a possible filter
|
||||
* @param string $foreignLimit a possible LIMIT clause
|
||||
* @param bool $getTotal optional, whether to get total num of rows
|
||||
* in $foreignData['the_total;]
|
||||
* (has an effect of performance)
|
||||
*
|
||||
@ -999,15 +999,15 @@ class Relation
|
||||
public function getForeignData(
|
||||
array|bool $foreigners,
|
||||
string $field,
|
||||
bool $override_total,
|
||||
string $foreign_filter,
|
||||
string $foreign_limit,
|
||||
bool $get_total = false,
|
||||
bool $overrideTotal,
|
||||
string $foreignFilter,
|
||||
string $foreignLimit,
|
||||
bool $getTotal = false,
|
||||
): array {
|
||||
// we always show the foreign field in the drop-down; if a display
|
||||
// field is defined, we show it besides the foreign field
|
||||
$foreign_link = false;
|
||||
$disp_row = $foreign_display = $the_total = $foreign_field = null;
|
||||
$foreignLink = false;
|
||||
$dispRow = $foreignDisplay = $theTotal = $foreignField = null;
|
||||
do {
|
||||
if (! $foreigners) {
|
||||
break;
|
||||
@ -1018,9 +1018,9 @@ class Relation
|
||||
break;
|
||||
}
|
||||
|
||||
$foreign_db = $foreigner['foreign_db'];
|
||||
$foreign_table = $foreigner['foreign_table'];
|
||||
$foreign_field = $foreigner['foreign_field'];
|
||||
$foreignDb = $foreigner['foreign_db'];
|
||||
$foreignTable = $foreigner['foreign_table'];
|
||||
$foreignField = $foreigner['foreign_field'];
|
||||
|
||||
// Count number of rows in the foreign table. Currently we do
|
||||
// not use a drop-down if more than ForeignKeyMaxLimit rows in the
|
||||
@ -1032,81 +1032,81 @@ class Relation
|
||||
|
||||
// Check if table has more rows than specified by
|
||||
// $GLOBALS['cfg']['ForeignKeyMaxLimit']
|
||||
$moreThanLimit = $this->dbi->getTable($foreign_db, $foreign_table)
|
||||
$moreThanLimit = $this->dbi->getTable($foreignDb, $foreignTable)
|
||||
->checkIfMinRecordsExist($GLOBALS['cfg']['ForeignKeyMaxLimit']);
|
||||
|
||||
if ($override_total === true || ! $moreThanLimit) {
|
||||
if ($overrideTotal === true || ! $moreThanLimit) {
|
||||
// foreign_display can be false if no display field defined:
|
||||
$foreign_display = $this->getDisplayField($foreign_db, $foreign_table);
|
||||
$foreignDisplay = $this->getDisplayField($foreignDb, $foreignTable);
|
||||
|
||||
$f_query_main = 'SELECT ' . Util::backquote($foreign_field)
|
||||
$fQueryMain = 'SELECT ' . Util::backquote($foreignField)
|
||||
. (
|
||||
$foreign_display === false
|
||||
$foreignDisplay === false
|
||||
? ''
|
||||
: ', ' . Util::backquote($foreign_display)
|
||||
: ', ' . Util::backquote($foreignDisplay)
|
||||
);
|
||||
$f_query_from = ' FROM ' . Util::backquote($foreign_db)
|
||||
. '.' . Util::backquote($foreign_table);
|
||||
$f_query_filter = $foreign_filter === '' ? '' : ' WHERE '
|
||||
. Util::backquote($foreign_field)
|
||||
$fQueryFrom = ' FROM ' . Util::backquote($foreignDb)
|
||||
. '.' . Util::backquote($foreignTable);
|
||||
$fQueryFilter = $foreignFilter === '' ? '' : ' WHERE '
|
||||
. Util::backquote($foreignField)
|
||||
. ' LIKE ' . $this->dbi->quoteString(
|
||||
'%' . $this->dbi->escapeMysqlWildcards($foreign_filter) . '%',
|
||||
'%' . $this->dbi->escapeMysqlWildcards($foreignFilter) . '%',
|
||||
)
|
||||
. (
|
||||
$foreign_display === false
|
||||
$foreignDisplay === false
|
||||
? ''
|
||||
: ' OR ' . Util::backquote($foreign_display)
|
||||
: ' OR ' . Util::backquote($foreignDisplay)
|
||||
. ' LIKE ' . $this->dbi->quoteString(
|
||||
'%' . $this->dbi->escapeMysqlWildcards($foreign_filter) . '%',
|
||||
'%' . $this->dbi->escapeMysqlWildcards($foreignFilter) . '%',
|
||||
)
|
||||
);
|
||||
$f_query_order = $foreign_display === false ? '' : ' ORDER BY '
|
||||
. Util::backquote($foreign_table) . '.'
|
||||
. Util::backquote($foreign_display);
|
||||
$fQueryOrder = $foreignDisplay === false ? '' : ' ORDER BY '
|
||||
. Util::backquote($foreignTable) . '.'
|
||||
. Util::backquote($foreignDisplay);
|
||||
|
||||
$f_query_limit = $foreign_limit !== '' ? $foreign_limit : '';
|
||||
$fQueryLimit = $foreignLimit !== '' ? $foreignLimit : '';
|
||||
|
||||
if ($foreign_filter !== '') {
|
||||
$the_total = $this->dbi->fetchValue('SELECT COUNT(*)' . $f_query_from . $f_query_filter);
|
||||
if ($the_total === false) {
|
||||
$the_total = 0;
|
||||
if ($foreignFilter !== '') {
|
||||
$theTotal = $this->dbi->fetchValue('SELECT COUNT(*)' . $fQueryFrom . $fQueryFilter);
|
||||
if ($theTotal === false) {
|
||||
$theTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$disp = $this->dbi->tryQuery(
|
||||
$f_query_main . $f_query_from . $f_query_filter
|
||||
. $f_query_order . $f_query_limit,
|
||||
$fQueryMain . $fQueryFrom . $fQueryFilter
|
||||
. $fQueryOrder . $fQueryLimit,
|
||||
);
|
||||
if ($disp && $disp->numRows() > 0) {
|
||||
// If a resultset has been created, pre-cache it in the $disp_row
|
||||
// array. This helps us from not needing to use mysql_data_seek by
|
||||
// accessing a pre-cached PHP array. Usually those resultsets are
|
||||
// not that big, so a performance hit should not be expected.
|
||||
$disp_row = $disp->fetchAllAssoc();
|
||||
$dispRow = $disp->fetchAllAssoc();
|
||||
} else {
|
||||
// Either no data in the foreign table or
|
||||
// user does not have select permission to foreign table/field
|
||||
// Show an input field with a 'Browse foreign values' link
|
||||
$disp_row = null;
|
||||
$foreign_link = true;
|
||||
$dispRow = null;
|
||||
$foreignLink = true;
|
||||
}
|
||||
} else {
|
||||
$disp_row = null;
|
||||
$foreign_link = true;
|
||||
$dispRow = null;
|
||||
$foreignLink = true;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
if ($get_total && isset($foreign_db, $foreign_table)) {
|
||||
$the_total = $this->dbi->getTable($foreign_db, $foreign_table)
|
||||
if ($getTotal && isset($foreignDb, $foreignTable)) {
|
||||
$theTotal = $this->dbi->getTable($foreignDb, $foreignTable)
|
||||
->countRecords(true);
|
||||
}
|
||||
|
||||
return [
|
||||
'foreign_link' => $foreign_link,
|
||||
'the_total' => $the_total,
|
||||
'foreign_display' => is_string($foreign_display) ? $foreign_display : '',
|
||||
'disp_row' => $disp_row,
|
||||
'foreign_field' => $foreign_field,
|
||||
'foreign_link' => $foreignLink,
|
||||
'the_total' => $theTotal,
|
||||
'foreign_display' => is_string($foreignDisplay) ? $foreignDisplay : '',
|
||||
'disp_row' => $dispRow,
|
||||
'foreign_field' => $foreignField,
|
||||
];
|
||||
}
|
||||
|
||||
@ -1115,80 +1115,80 @@ class Relation
|
||||
*
|
||||
* usually called after a column in a table was renamed
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $field old field name
|
||||
* @param string $new_name new field name
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $field old field name
|
||||
* @param string $newName new field name
|
||||
*/
|
||||
public function renameField(string $db, string $table, string $field, string $new_name): void
|
||||
public function renameField(string $db, string $table, string $field, string $newName): void
|
||||
{
|
||||
$relationParameters = $this->getRelationParameters();
|
||||
|
||||
if ($relationParameters->displayFeature !== null) {
|
||||
$table_query = 'UPDATE '
|
||||
$tableQuery = 'UPDATE '
|
||||
. Util::backquote($relationParameters->displayFeature->database) . '.'
|
||||
. Util::backquote($relationParameters->displayFeature->tableInfo)
|
||||
. ' SET display_field = ' . $this->dbi->quoteString($new_name, Connection::TYPE_CONTROL)
|
||||
. ' SET display_field = ' . $this->dbi->quoteString($newName, Connection::TYPE_CONTROL)
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($db, Connection::TYPE_CONTROL)
|
||||
. ' AND table_name = ' . $this->dbi->quoteString($table, Connection::TYPE_CONTROL)
|
||||
. ' AND display_field = ' . $this->dbi->quoteString($field, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($table_query);
|
||||
$this->dbi->queryAsControlUser($tableQuery);
|
||||
}
|
||||
|
||||
if ($relationParameters->relationFeature === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table_query = 'UPDATE '
|
||||
$tableQuery = 'UPDATE '
|
||||
. Util::backquote($relationParameters->relationFeature->database) . '.'
|
||||
. Util::backquote($relationParameters->relationFeature->relation)
|
||||
. ' SET master_field = ' . $this->dbi->quoteString($new_name, Connection::TYPE_CONTROL)
|
||||
. ' SET master_field = ' . $this->dbi->quoteString($newName, Connection::TYPE_CONTROL)
|
||||
. ' WHERE master_db = ' . $this->dbi->quoteString($db, Connection::TYPE_CONTROL)
|
||||
. ' AND master_table = ' . $this->dbi->quoteString($table, Connection::TYPE_CONTROL)
|
||||
. ' AND master_field = ' . $this->dbi->quoteString($field, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($table_query);
|
||||
$this->dbi->queryAsControlUser($tableQuery);
|
||||
|
||||
$table_query = 'UPDATE '
|
||||
$tableQuery = 'UPDATE '
|
||||
. Util::backquote($relationParameters->relationFeature->database) . '.'
|
||||
. Util::backquote($relationParameters->relationFeature->relation)
|
||||
. ' SET foreign_field = ' . $this->dbi->quoteString($new_name, Connection::TYPE_CONTROL)
|
||||
. ' SET foreign_field = ' . $this->dbi->quoteString($newName, Connection::TYPE_CONTROL)
|
||||
. ' WHERE foreign_db = ' . $this->dbi->quoteString($db, Connection::TYPE_CONTROL)
|
||||
. ' AND foreign_table = ' . $this->dbi->quoteString($table, Connection::TYPE_CONTROL)
|
||||
. ' AND foreign_field = ' . $this->dbi->quoteString($field, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($table_query);
|
||||
$this->dbi->queryAsControlUser($tableQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs SQL query used for renaming table.
|
||||
*
|
||||
* @param string $source_db Source database name
|
||||
* @param string $target_db Target database name
|
||||
* @param string $source_table Source table name
|
||||
* @param string $target_table Target table name
|
||||
* @param string $db_field Name of database field
|
||||
* @param string $table_field Name of table field
|
||||
* @param string $sourceDb Source database name
|
||||
* @param string $targetDb Target database name
|
||||
* @param string $sourceTable Source table name
|
||||
* @param string $targetTable Target table name
|
||||
* @param string $dbField Name of database field
|
||||
* @param string $tableField Name of table field
|
||||
*/
|
||||
public function renameSingleTable(
|
||||
DatabaseName $configStorageDatabase,
|
||||
TableName $configStorageTable,
|
||||
string $source_db,
|
||||
string $target_db,
|
||||
string $source_table,
|
||||
string $target_table,
|
||||
string $db_field,
|
||||
string $table_field,
|
||||
string $sourceDb,
|
||||
string $targetDb,
|
||||
string $sourceTable,
|
||||
string $targetTable,
|
||||
string $dbField,
|
||||
string $tableField,
|
||||
): void {
|
||||
$query = 'UPDATE '
|
||||
. Util::backquote($configStorageDatabase) . '.'
|
||||
. Util::backquote($configStorageTable)
|
||||
. ' SET '
|
||||
. $db_field . ' = ' . $this->dbi->quoteString($target_db, Connection::TYPE_CONTROL)
|
||||
. $dbField . ' = ' . $this->dbi->quoteString($targetDb, Connection::TYPE_CONTROL)
|
||||
. ', '
|
||||
. $table_field . ' = ' . $this->dbi->quoteString($target_table, Connection::TYPE_CONTROL)
|
||||
. $tableField . ' = ' . $this->dbi->quoteString($targetTable, Connection::TYPE_CONTROL)
|
||||
. ' WHERE '
|
||||
. $db_field . ' = ' . $this->dbi->quoteString($source_db, Connection::TYPE_CONTROL)
|
||||
. $dbField . ' = ' . $this->dbi->quoteString($sourceDb, Connection::TYPE_CONTROL)
|
||||
. ' AND '
|
||||
. $table_field . ' = ' . $this->dbi->quoteString($source_table, Connection::TYPE_CONTROL);
|
||||
. $tableField . ' = ' . $this->dbi->quoteString($sourceTable, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($query);
|
||||
}
|
||||
|
||||
@ -1197,12 +1197,12 @@ class Relation
|
||||
*
|
||||
* usually called after table has been moved
|
||||
*
|
||||
* @param string $source_db Source database name
|
||||
* @param string $target_db Target database name
|
||||
* @param string $source_table Source table name
|
||||
* @param string $target_table Target table name
|
||||
* @param string $sourceDb Source database name
|
||||
* @param string $targetDb Target database name
|
||||
* @param string $sourceTable Source table name
|
||||
* @param string $targetTable Target table name
|
||||
*/
|
||||
public function renameTable(string $source_db, string $target_db, string $source_table, string $target_table): void
|
||||
public function renameTable(string $sourceDb, string $targetDb, string $sourceTable, string $targetTable): void
|
||||
{
|
||||
$relationParameters = $this->getRelationParameters();
|
||||
|
||||
@ -1211,10 +1211,10 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->columnCommentsFeature->database,
|
||||
$relationParameters->columnCommentsFeature->columnInfo,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'db_name',
|
||||
'table_name',
|
||||
);
|
||||
@ -1227,10 +1227,10 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->displayFeature->database,
|
||||
$relationParameters->displayFeature->tableInfo,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'db_name',
|
||||
'table_name',
|
||||
);
|
||||
@ -1240,10 +1240,10 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->relationFeature->database,
|
||||
$relationParameters->relationFeature->relation,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'foreign_db',
|
||||
'foreign_table',
|
||||
);
|
||||
@ -1251,37 +1251,37 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->relationFeature->database,
|
||||
$relationParameters->relationFeature->relation,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'master_db',
|
||||
'master_table',
|
||||
);
|
||||
}
|
||||
|
||||
if ($relationParameters->pdfFeature !== null) {
|
||||
if ($source_db == $target_db) {
|
||||
if ($sourceDb == $targetDb) {
|
||||
// rename within the database can be handled
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->pdfFeature->database,
|
||||
$relationParameters->pdfFeature->tableCoords,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'db_name',
|
||||
'table_name',
|
||||
);
|
||||
} else {
|
||||
// if the table is moved out of the database we can no longer keep the
|
||||
// record for table coordinate
|
||||
$remove_query = 'DELETE FROM '
|
||||
$removeQuery = 'DELETE FROM '
|
||||
. Util::backquote($relationParameters->pdfFeature->database) . '.'
|
||||
. Util::backquote($relationParameters->pdfFeature->tableCoords)
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($source_db, Connection::TYPE_CONTROL)
|
||||
. ' AND table_name = ' . $this->dbi->quoteString($source_table, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($remove_query);
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($sourceDb, Connection::TYPE_CONTROL)
|
||||
. ' AND table_name = ' . $this->dbi->quoteString($sourceTable, Connection::TYPE_CONTROL);
|
||||
$this->dbi->queryAsControlUser($removeQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1289,10 +1289,10 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->uiPreferencesFeature->database,
|
||||
$relationParameters->uiPreferencesFeature->tableUiPrefs,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'db_name',
|
||||
'table_name',
|
||||
);
|
||||
@ -1306,10 +1306,10 @@ class Relation
|
||||
$this->renameSingleTable(
|
||||
$relationParameters->navigationItemsHidingFeature->database,
|
||||
$relationParameters->navigationItemsHidingFeature->navigationHiding,
|
||||
$source_db,
|
||||
$target_db,
|
||||
$source_table,
|
||||
$target_table,
|
||||
$sourceDb,
|
||||
$targetDb,
|
||||
$sourceTable,
|
||||
$targetTable,
|
||||
'db_name',
|
||||
'table_name',
|
||||
);
|
||||
@ -1318,11 +1318,11 @@ class Relation
|
||||
$query = 'UPDATE '
|
||||
. Util::backquote($relationParameters->navigationItemsHidingFeature->database) . '.'
|
||||
. Util::backquote($relationParameters->navigationItemsHidingFeature->navigationHiding)
|
||||
. ' SET db_name = ' . $this->dbi->quoteString($target_db, Connection::TYPE_CONTROL)
|
||||
. ' SET db_name = ' . $this->dbi->quoteString($targetDb, Connection::TYPE_CONTROL)
|
||||
. ','
|
||||
. ' item_name = ' . $this->dbi->quoteString($target_table, Connection::TYPE_CONTROL)
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($source_db, Connection::TYPE_CONTROL)
|
||||
. ' AND item_name = ' . $this->dbi->quoteString($source_table, Connection::TYPE_CONTROL)
|
||||
. ' item_name = ' . $this->dbi->quoteString($targetTable, Connection::TYPE_CONTROL)
|
||||
. ' WHERE db_name = ' . $this->dbi->quoteString($sourceDb, Connection::TYPE_CONTROL)
|
||||
. ' AND item_name = ' . $this->dbi->quoteString($sourceTable, Connection::TYPE_CONTROL)
|
||||
. " AND item_type = 'table'";
|
||||
$this->dbi->queryAsControlUser($query);
|
||||
}
|
||||
@ -1335,14 +1335,14 @@ class Relation
|
||||
*/
|
||||
public function createPage(string|null $newpage, PdfFeature $pdfFeature, string $db): int
|
||||
{
|
||||
$ins_query = 'INSERT INTO '
|
||||
$insQuery = 'INSERT INTO '
|
||||
. Util::backquote($pdfFeature->database) . '.'
|
||||
. Util::backquote($pdfFeature->pdfPages)
|
||||
. ' (db_name, page_descr)'
|
||||
. ' VALUES ('
|
||||
. $this->dbi->quoteString($db, Connection::TYPE_CONTROL) . ', '
|
||||
. $this->dbi->quoteString($newpage ?: __('no description'), Connection::TYPE_CONTROL) . ')';
|
||||
$this->dbi->tryQueryAsControlUser($ins_query);
|
||||
$this->dbi->tryQueryAsControlUser($insQuery);
|
||||
|
||||
return $this->dbi->insertId(Connection::TYPE_CONTROL);
|
||||
}
|
||||
@ -1358,7 +1358,7 @@ class Relation
|
||||
public function getChildReferences(string $db, string $table, string $column = ''): array
|
||||
{
|
||||
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
|
||||
$rel_query = 'SELECT `column_name`, `table_name`,'
|
||||
$relQuery = 'SELECT `column_name`, `table_name`,'
|
||||
. ' `table_schema`, `referenced_column_name`'
|
||||
. ' FROM `information_schema`.`key_column_usage`'
|
||||
. ' WHERE `referenced_table_name` = '
|
||||
@ -1366,12 +1366,12 @@ class Relation
|
||||
. ' AND `referenced_table_schema` = '
|
||||
. $this->dbi->quoteString($db);
|
||||
if ($column) {
|
||||
$rel_query .= ' AND `referenced_column_name` = '
|
||||
$relQuery .= ' AND `referenced_column_name` = '
|
||||
. $this->dbi->quoteString($column);
|
||||
}
|
||||
|
||||
return $this->dbi->fetchResult(
|
||||
$rel_query,
|
||||
$relQuery,
|
||||
[
|
||||
'referenced_column_name',
|
||||
null,
|
||||
@ -1385,11 +1385,11 @@ class Relation
|
||||
/**
|
||||
* Check child table references and foreign key for a table column.
|
||||
*
|
||||
* @param string $db name of master table db.
|
||||
* @param string $table name of master table.
|
||||
* @param string $column name of master table column.
|
||||
* @param array|null $foreigners_full foreigners array for the whole table.
|
||||
* @param array|null $child_references_full child references for the whole table.
|
||||
* @param string $db name of master table db.
|
||||
* @param string $table name of master table.
|
||||
* @param string $column name of master table column.
|
||||
* @param array|null $foreignersFull foreigners array for the whole table.
|
||||
* @param array|null $childReferencesFull child references for the whole table.
|
||||
*
|
||||
* @return array<string, mixed> telling about references if foreign key.
|
||||
* @psalm-return array{isEditable: bool, isForeignKey: bool, isReferenced: bool, references: string[]}
|
||||
@ -1398,10 +1398,10 @@ class Relation
|
||||
string $db,
|
||||
string $table,
|
||||
string $column,
|
||||
array|null $foreigners_full = null,
|
||||
array|null $child_references_full = null,
|
||||
array|null $foreignersFull = null,
|
||||
array|null $childReferencesFull = null,
|
||||
): array {
|
||||
$column_status = [
|
||||
$columnStatus = [
|
||||
'isEditable' => true,
|
||||
'isReferenced' => false,
|
||||
'isForeignKey' => false,
|
||||
@ -1409,13 +1409,13 @@ class Relation
|
||||
];
|
||||
|
||||
$foreigners = [];
|
||||
if ($foreigners_full !== null) {
|
||||
if (isset($foreigners_full[$column])) {
|
||||
$foreigners[$column] = $foreigners_full[$column];
|
||||
if ($foreignersFull !== null) {
|
||||
if (isset($foreignersFull[$column])) {
|
||||
$foreigners[$column] = $foreignersFull[$column];
|
||||
}
|
||||
|
||||
if (isset($foreigners_full['foreign_keys_data'])) {
|
||||
$foreigners['foreign_keys_data'] = $foreigners_full['foreign_keys_data'];
|
||||
if (isset($foreignersFull['foreign_keys_data'])) {
|
||||
$foreigners['foreign_keys_data'] = $foreignersFull['foreign_keys_data'];
|
||||
}
|
||||
} else {
|
||||
$foreigners = $this->getForeigners($db, $table, $column, 'foreign');
|
||||
@ -1423,31 +1423,31 @@ class Relation
|
||||
|
||||
$foreigner = $this->searchColumnInForeigners($foreigners, $column);
|
||||
|
||||
$child_references = [];
|
||||
if ($child_references_full !== null) {
|
||||
if (isset($child_references_full[$column])) {
|
||||
$child_references = $child_references_full[$column];
|
||||
$childReferences = [];
|
||||
if ($childReferencesFull !== null) {
|
||||
if (isset($childReferencesFull[$column])) {
|
||||
$childReferences = $childReferencesFull[$column];
|
||||
}
|
||||
} else {
|
||||
$child_references = $this->getChildReferences($db, $table, $column);
|
||||
$childReferences = $this->getChildReferences($db, $table, $column);
|
||||
}
|
||||
|
||||
if (count($child_references) > 0 || $foreigner) {
|
||||
$column_status['isEditable'] = false;
|
||||
if (count($child_references) > 0) {
|
||||
$column_status['isReferenced'] = true;
|
||||
foreach ($child_references as $columns) {
|
||||
$column_status['references'][] = Util::backquote($columns['table_schema'])
|
||||
if (count($childReferences) > 0 || $foreigner) {
|
||||
$columnStatus['isEditable'] = false;
|
||||
if (count($childReferences) > 0) {
|
||||
$columnStatus['isReferenced'] = true;
|
||||
foreach ($childReferences as $columns) {
|
||||
$columnStatus['references'][] = Util::backquote($columns['table_schema'])
|
||||
. '.' . Util::backquote($columns['table_name']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($foreigner) {
|
||||
$column_status['isForeignKey'] = true;
|
||||
$columnStatus['isForeignKey'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $column_status;
|
||||
return $columnStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1467,15 +1467,15 @@ class Relation
|
||||
}
|
||||
|
||||
$foreigner = [];
|
||||
foreach ($foreigners['foreign_keys_data'] as $one_key) {
|
||||
$column_index = array_search($column, $one_key['index_list']);
|
||||
if ($column_index !== false) {
|
||||
$foreigner['foreign_field'] = $one_key['ref_index_list'][$column_index];
|
||||
$foreigner['foreign_db'] = $one_key['ref_db_name'] ?? $GLOBALS['db'];
|
||||
$foreigner['foreign_table'] = $one_key['ref_table_name'];
|
||||
$foreigner['constraint'] = $one_key['constraint'];
|
||||
$foreigner['on_update'] = $one_key['on_update'] ?? 'RESTRICT';
|
||||
$foreigner['on_delete'] = $one_key['on_delete'] ?? 'RESTRICT';
|
||||
foreach ($foreigners['foreign_keys_data'] as $oneKey) {
|
||||
$columnIndex = array_search($column, $oneKey['index_list']);
|
||||
if ($columnIndex !== false) {
|
||||
$foreigner['foreign_field'] = $oneKey['ref_index_list'][$columnIndex];
|
||||
$foreigner['foreign_db'] = $oneKey['ref_db_name'] ?? $GLOBALS['db'];
|
||||
$foreigner['foreign_table'] = $oneKey['ref_table_name'];
|
||||
$foreigner['constraint'] = $oneKey['constraint'];
|
||||
$foreigner['on_update'] = $oneKey['on_update'] ?? 'RESTRICT';
|
||||
$foreigner['on_delete'] = $oneKey['on_delete'] ?? 'RESTRICT';
|
||||
|
||||
return $foreigner;
|
||||
}
|
||||
@ -1491,10 +1491,10 @@ class Relation
|
||||
*/
|
||||
public function getDefaultPmaTableNames(array $tableNameReplacements): array
|
||||
{
|
||||
$pma_tables = [];
|
||||
$create_tables_file = (string) file_get_contents(SQL_DIR . 'create_tables.sql');
|
||||
$pmaTables = [];
|
||||
$createTablesFile = (string) file_get_contents(SQL_DIR . 'create_tables.sql');
|
||||
|
||||
$queries = explode(';', $create_tables_file);
|
||||
$queries = explode(';', $createTablesFile);
|
||||
|
||||
foreach ($queries as $query) {
|
||||
if (! preg_match('/CREATE TABLE IF NOT EXISTS `(.*)` \(/', $query, $table)) {
|
||||
@ -1509,10 +1509,10 @@ class Relation
|
||||
$query = str_replace($tableName, $tableNameReplacements[$tableName], $query);
|
||||
}
|
||||
|
||||
$pma_tables[$tableName] = $query . ';';
|
||||
$pmaTables[$tableName] = $query . ';';
|
||||
}
|
||||
|
||||
return $pma_tables;
|
||||
return $pmaTables;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1663,13 +1663,13 @@ class Relation
|
||||
// re-initialize the favorite and recent tables stored in the
|
||||
// session from the current configuration storage.
|
||||
if ($relationParameters->favoriteTablesFeature !== null) {
|
||||
$fav_tables = RecentFavoriteTable::getInstance('favorite');
|
||||
$_SESSION['tmpval']['favoriteTables'][$GLOBALS['server']] = $fav_tables->getFromDb();
|
||||
$favTables = RecentFavoriteTable::getInstance('favorite');
|
||||
$_SESSION['tmpval']['favoriteTables'][$GLOBALS['server']] = $favTables->getFromDb();
|
||||
}
|
||||
|
||||
if ($relationParameters->recentlyUsedTablesFeature !== null) {
|
||||
$recent_tables = RecentFavoriteTable::getInstance('recent');
|
||||
$_SESSION['tmpval']['recentTables'][$GLOBALS['server']] = $recent_tables->getFromDb();
|
||||
$recentTables = RecentFavoriteTable::getInstance('recent');
|
||||
$_SESSION['tmpval']['recentTables'][$GLOBALS['server']] = $recentTables->getFromDb();
|
||||
}
|
||||
|
||||
// Reload navi panel to update the recent/favorite lists.
|
||||
@ -1688,19 +1688,19 @@ class Relation
|
||||
*/
|
||||
public function getRelationsAndStatus(bool $condition, string $db, string $table): array
|
||||
{
|
||||
$have_rel = false;
|
||||
$res_rel = [];
|
||||
$haveRel = false;
|
||||
$resRel = [];
|
||||
if ($condition) {
|
||||
// Find which tables are related with the current one and write it in
|
||||
// an array
|
||||
$res_rel = $this->getForeigners($db, $table);
|
||||
$resRel = $this->getForeigners($db, $table);
|
||||
|
||||
$have_rel = count($res_rel) > 0;
|
||||
$haveRel = count($resRel) > 0;
|
||||
}
|
||||
|
||||
return [
|
||||
$res_rel,
|
||||
$have_rel,
|
||||
$resRel,
|
||||
$haveRel,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -46,9 +46,9 @@ class UserGroups
|
||||
$userGroupSpecialChars = htmlspecialchars($userGroup);
|
||||
$usersTable = Util::backquote($configurableMenusFeature->database)
|
||||
. '.' . Util::backquote($configurableMenusFeature->users);
|
||||
$sql_query = 'SELECT `username` FROM ' . $usersTable
|
||||
$sqlQuery = 'SELECT `username` FROM ' . $usersTable
|
||||
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL);
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sqlQuery);
|
||||
if ($result) {
|
||||
$i = 0;
|
||||
while ($row = $result->fetchRow()) {
|
||||
@ -77,14 +77,14 @@ class UserGroups
|
||||
{
|
||||
$groupTable = Util::backquote($configurableMenusFeature->database)
|
||||
. '.' . Util::backquote($configurableMenusFeature->userGroups);
|
||||
$sql_query = 'SELECT * FROM ' . $groupTable . ' ORDER BY `usergroup` ASC';
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
|
||||
$sqlQuery = 'SELECT * FROM ' . $groupTable . ' ORDER BY `usergroup` ASC';
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sqlQuery);
|
||||
$userGroups = [];
|
||||
$userGroupsValues = [];
|
||||
$action = Url::getFromRoute('/server/privileges');
|
||||
$hidden_inputs = null;
|
||||
$hiddenInputs = null;
|
||||
if ($result && $result->numRows()) {
|
||||
$hidden_inputs = Url::getHiddenInputs();
|
||||
$hiddenInputs = Url::getHiddenInputs();
|
||||
foreach ($result as $row) {
|
||||
$groupName = $row['usergroup'];
|
||||
if (! isset($userGroups[$groupName])) {
|
||||
@ -130,7 +130,7 @@ class UserGroups
|
||||
|
||||
return $template->render('server/user_groups/user_groups', [
|
||||
'action' => $action,
|
||||
'hidden_inputs' => $hidden_inputs ?? '',
|
||||
'hidden_inputs' => $hiddenInputs ?? '',
|
||||
'has_rows' => $userGroups !== [],
|
||||
'user_groups_values' => $userGroupsValues,
|
||||
'add_user_url' => $addUserUrl,
|
||||
@ -218,9 +218,9 @@ class UserGroups
|
||||
if ($userGroup !== null) {
|
||||
$groupTable = Util::backquote($configurableMenusFeature->database)
|
||||
. '.' . Util::backquote($configurableMenusFeature->userGroups);
|
||||
$sql_query = 'SELECT * FROM ' . $groupTable
|
||||
$sqlQuery = 'SELECT * FROM ' . $groupTable
|
||||
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL);
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
|
||||
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sqlQuery);
|
||||
if ($result) {
|
||||
foreach ($result as $row) {
|
||||
$key = $row['tab'];
|
||||
@ -312,12 +312,12 @@ class UserGroups
|
||||
. '.' . Util::backquote($configurableMenusFeature->userGroups);
|
||||
|
||||
if (! $new) {
|
||||
$sql_query = 'DELETE FROM ' . $groupTable
|
||||
$sqlQuery = 'DELETE FROM ' . $groupTable
|
||||
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL) . ';';
|
||||
$GLOBALS['dbi']->queryAsControlUser($sql_query);
|
||||
$GLOBALS['dbi']->queryAsControlUser($sqlQuery);
|
||||
}
|
||||
|
||||
$sql_query = 'INSERT INTO ' . $groupTable
|
||||
$sqlQuery = 'INSERT INTO ' . $groupTable
|
||||
. '(`usergroup`, `tab`, `allowed`)'
|
||||
. ' VALUES ';
|
||||
$first = true;
|
||||
@ -325,19 +325,19 @@ class UserGroups
|
||||
foreach ($tabs as $tabGroupName => $tabGroup) {
|
||||
foreach (array_keys($tabGroup) as $tab) {
|
||||
if (! $first) {
|
||||
$sql_query .= ', ';
|
||||
$sqlQuery .= ', ';
|
||||
}
|
||||
|
||||
$tabName = $tabGroupName . '_' . $tab;
|
||||
$allowed = isset($_POST[$tabName]) && $_POST[$tabName] === 'Y';
|
||||
$sql_query .= '(' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL)
|
||||
$sqlQuery .= '(' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL)
|
||||
. ', ' . $GLOBALS['dbi']->quoteString($tabName, Connection::TYPE_CONTROL) . ", '"
|
||||
. ($allowed ? 'Y' : 'N') . "')";
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
|
||||
$sql_query .= ';';
|
||||
$GLOBALS['dbi']->queryAsControlUser($sql_query);
|
||||
$sqlQuery .= ';';
|
||||
$GLOBALS['dbi']->queryAsControlUser($sqlQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,15 +65,15 @@ class Console
|
||||
}
|
||||
|
||||
$bookmarks = Bookmark::getList($bookmarkFeature, $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user']);
|
||||
$count_bookmarks = count($bookmarks);
|
||||
if ($count_bookmarks > 0) {
|
||||
$countBookmarks = count($bookmarks);
|
||||
if ($countBookmarks > 0) {
|
||||
$welcomeMessage = sprintf(
|
||||
_ngettext(
|
||||
'Showing %1$d bookmark (both private and shared)',
|
||||
'Showing %1$d bookmarks (both private and shared)',
|
||||
$count_bookmarks,
|
||||
$countBookmarks,
|
||||
),
|
||||
$count_bookmarks,
|
||||
$countBookmarks,
|
||||
);
|
||||
} else {
|
||||
$welcomeMessage = __('No bookmarks');
|
||||
@ -105,12 +105,12 @@ class Console
|
||||
}
|
||||
|
||||
$bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
|
||||
$_sql_history = $this->relation->getHistory($GLOBALS['cfg']['Server']['user']);
|
||||
$sqlHistory = $this->relation->getHistory($GLOBALS['cfg']['Server']['user']);
|
||||
$bookmarkContent = static::getBookmarkContent();
|
||||
|
||||
return $this->template->render('console/display', [
|
||||
'has_bookmark_feature' => $bookmarkFeature !== null,
|
||||
'sql_history' => $_sql_history,
|
||||
'sql_history' => $sqlHistory,
|
||||
'bookmark_content' => $bookmarkContent,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -61,8 +61,8 @@ class ChangeLogController extends AbstractController
|
||||
*/
|
||||
$changelog = htmlspecialchars((string) $changelog);
|
||||
|
||||
$github_url = 'https://github.com/phpmyadmin/phpmyadmin/';
|
||||
$faq_url = 'https://docs.phpmyadmin.net/en/latest/faq.html';
|
||||
$githubUrl = 'https://github.com/phpmyadmin/phpmyadmin/';
|
||||
$faqUrl = 'https://docs.phpmyadmin.net/en/latest/faq.html';
|
||||
|
||||
$replaces = [
|
||||
'@(https?://[./a-zA-Z0-9.-_-]*[/a-zA-Z0-9_])@' => '<a href="'
|
||||
@ -73,11 +73,11 @@ class ChangeLogController extends AbstractController
|
||||
|
||||
// FAQ entries
|
||||
'/FAQ ([0-9]+)\.([0-9a-z]+)/i' => '<a href="'
|
||||
. Url::getFromRoute('/url') . '&url=' . $faq_url . '#faq\\1-\\2">FAQ \\1.\\2</a>',
|
||||
. Url::getFromRoute('/url') . '&url=' . $faqUrl . '#faq\\1-\\2">FAQ \\1.\\2</a>',
|
||||
|
||||
// GitHub issues
|
||||
'/issue\s*#?([0-9]{4,5}) /i' => '<a href="'
|
||||
. Url::getFromRoute('/url') . '&url=' . $github_url . 'issues/\\1">issue #\\1</a> ',
|
||||
. Url::getFromRoute('/url') . '&url=' . $githubUrl . 'issues/\\1">issue #\\1</a> ',
|
||||
|
||||
// CVE/CAN entries
|
||||
'/((CAN|CVE)-[0-9]+-[0-9]+)/' => '<a href="' . Url::getFromRoute('/url') . '&url='
|
||||
@ -89,10 +89,10 @@ class ChangeLogController extends AbstractController
|
||||
|
||||
// Highlight releases (with links)
|
||||
'/([0-9]+)\.([0-9]+)\.([0-9]+)\.0 (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3"></a>'
|
||||
. '<a href="' . Url::getFromRoute('/url') . '&url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3">'
|
||||
. '<a href="' . Url::getFromRoute('/url') . '&url=' . $githubUrl . 'commits/RELEASE_\\1_\\2_\\3">'
|
||||
. '\\1.\\2.\\3.0 \\4</a>',
|
||||
'/([0-9]+)\.([0-9]+)\.([0-9]+)\.([1-9][0-9]*) (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3_\\4"></a>'
|
||||
. '<a href="' . Url::getFromRoute('/url') . '&url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3_\\4">'
|
||||
. '<a href="' . Url::getFromRoute('/url') . '&url=' . $githubUrl . 'commits/RELEASE_\\1_\\2_\\3_\\4">'
|
||||
. '\\1.\\2.\\3.\\4 \\5</a>',
|
||||
|
||||
// Highlight releases (not linkable)
|
||||
|
||||
@ -53,7 +53,7 @@ class CentralColumnsController extends AbstractController
|
||||
}
|
||||
|
||||
if ($request->hasBodyParam('add_new_column')) {
|
||||
$tmp_msg = $this->addNewColumn([
|
||||
$tmpMsg = $this->addNewColumn([
|
||||
'col_name' => $request->getParsedBodyParam('col_name'),
|
||||
'col_default' => $request->getParsedBodyParam('col_default'),
|
||||
'col_default_sel' => $request->getParsedBodyParam('col_default_sel'),
|
||||
@ -75,7 +75,7 @@ class CentralColumnsController extends AbstractController
|
||||
}
|
||||
|
||||
if ($request->hasBodyParam('add_column')) {
|
||||
$tmp_msg = $this->addColumn([
|
||||
$tmpMsg = $this->addColumn([
|
||||
'table-select' => $request->getParsedBodyParam('table-select'),
|
||||
'column-select' => $request->getParsedBodyParam('column-select'),
|
||||
]);
|
||||
@ -117,7 +117,7 @@ class CentralColumnsController extends AbstractController
|
||||
}
|
||||
|
||||
if ($request->hasBodyParam('delete_save')) {
|
||||
$tmp_msg = $this->deleteSave([
|
||||
$tmpMsg = $this->deleteSave([
|
||||
'db' => $request->getParsedBodyParam('db'),
|
||||
'col_name' => $request->getParsedBodyParam('col_name'),
|
||||
]);
|
||||
@ -141,11 +141,11 @@ class CentralColumnsController extends AbstractController
|
||||
$GLOBALS['message'] = Message::success(
|
||||
sprintf(__('Showing rows %1$s - %2$s.'), $pos + 1, $pos + $GLOBALS['num_cols']),
|
||||
);
|
||||
if (! isset($tmp_msg) || $tmp_msg === true) {
|
||||
if (! isset($tmpMsg) || $tmpMsg === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['message'] = $tmp_msg;
|
||||
$GLOBALS['message'] = $tmpMsg;
|
||||
}
|
||||
|
||||
/** @param array $params Request parameters */
|
||||
|
||||
@ -77,35 +77,35 @@ final class ExportController extends AbstractController
|
||||
|
||||
$tablesForMultiValues = [];
|
||||
|
||||
foreach ($GLOBALS['tables'] as $each_table) {
|
||||
foreach ($GLOBALS['tables'] as $eachTable) {
|
||||
$tableSelect = $request->getParsedBodyParam('table_select');
|
||||
if (is_array($tableSelect)) {
|
||||
$is_checked = $this->export->getCheckedClause($each_table['Name'], $tableSelect);
|
||||
$isChecked = $this->export->getCheckedClause($eachTable['Name'], $tableSelect);
|
||||
} elseif (isset($GLOBALS['table_select'])) {
|
||||
$is_checked = $this->export->getCheckedClause($each_table['Name'], $GLOBALS['table_select']);
|
||||
$isChecked = $this->export->getCheckedClause($eachTable['Name'], $GLOBALS['table_select']);
|
||||
} else {
|
||||
$is_checked = true;
|
||||
$isChecked = true;
|
||||
}
|
||||
|
||||
$tableStructure = $request->getParsedBodyParam('table_structure');
|
||||
if (is_array($tableStructure)) {
|
||||
$structure_checked = $this->export->getCheckedClause($each_table['Name'], $tableStructure);
|
||||
$structureChecked = $this->export->getCheckedClause($eachTable['Name'], $tableStructure);
|
||||
} else {
|
||||
$structure_checked = $is_checked;
|
||||
$structureChecked = $isChecked;
|
||||
}
|
||||
|
||||
$tableData = $request->getParsedBodyParam('table_data');
|
||||
if (is_array($tableData)) {
|
||||
$data_checked = $this->export->getCheckedClause($each_table['Name'], $tableData);
|
||||
$dataChecked = $this->export->getCheckedClause($eachTable['Name'], $tableData);
|
||||
} else {
|
||||
$data_checked = $is_checked;
|
||||
$dataChecked = $isChecked;
|
||||
}
|
||||
|
||||
$tablesForMultiValues[] = [
|
||||
'name' => $each_table['Name'],
|
||||
'is_checked_select' => $is_checked,
|
||||
'is_checked_structure' => $structure_checked,
|
||||
'is_checked_data' => $data_checked,
|
||||
'name' => $eachTable['Name'],
|
||||
'is_checked_select' => $isChecked,
|
||||
'is_checked_structure' => $structureChecked,
|
||||
'is_checked_data' => $dataChecked,
|
||||
];
|
||||
}
|
||||
|
||||
@ -119,14 +119,14 @@ final class ExportController extends AbstractController
|
||||
|
||||
$isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw';
|
||||
if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) {
|
||||
$export_type = 'raw';
|
||||
$exportType = 'raw';
|
||||
} else {
|
||||
$export_type = 'database';
|
||||
$exportType = 'database';
|
||||
}
|
||||
|
||||
$GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null;
|
||||
|
||||
$exportList = Plugins::getExport($export_type, isset($GLOBALS['single_table']));
|
||||
$exportList = Plugins::getExport($exportType, isset($GLOBALS['single_table']));
|
||||
|
||||
if (empty($exportList)) {
|
||||
$this->response->addHTML(Message::error(
|
||||
@ -137,7 +137,7 @@ final class ExportController extends AbstractController
|
||||
}
|
||||
|
||||
$options = $this->exportOptions->getOptions(
|
||||
$export_type,
|
||||
$exportType,
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$GLOBALS['sql_query'],
|
||||
|
||||
@ -52,9 +52,9 @@ final class CollationController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_query = 'ALTER DATABASE ' . Util::backquote($GLOBALS['db'])
|
||||
$sqlQuery = 'ALTER DATABASE ' . Util::backquote($GLOBALS['db'])
|
||||
. ' DEFAULT' . Util::getCharsetQueryPart($dbCollation);
|
||||
$this->dbi->query($sql_query);
|
||||
$this->dbi->query($sqlQuery);
|
||||
$message = Message::success();
|
||||
|
||||
/**
|
||||
@ -69,13 +69,13 @@ final class CollationController extends AbstractController
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql_query = 'ALTER TABLE '
|
||||
$sqlQuery = 'ALTER TABLE '
|
||||
. Util::backquote($GLOBALS['db'])
|
||||
. '.'
|
||||
. Util::backquote($tableName)
|
||||
. ' DEFAULT '
|
||||
. Util::getCharsetQueryPart($dbCollation);
|
||||
$this->dbi->query($sql_query);
|
||||
$this->dbi->query($sqlQuery);
|
||||
|
||||
/**
|
||||
* Changes columns charset if requested by the user
|
||||
|
||||
@ -78,12 +78,12 @@ class ErrorReportController extends AbstractController
|
||||
$reportData = $this->errorReport->getData($exceptionType);
|
||||
// report if and only if there were 'actual' errors.
|
||||
if (count($reportData) > 0) {
|
||||
$server_response = $this->errorReport->send($reportData);
|
||||
if (! is_string($server_response)) {
|
||||
$serverResponse = $this->errorReport->send($reportData);
|
||||
if (! is_string($serverResponse)) {
|
||||
$success = false;
|
||||
} else {
|
||||
$decoded_response = json_decode($server_response, true);
|
||||
$success = ! empty($decoded_response) && $decoded_response['success'];
|
||||
$decodedResponse = json_decode($serverResponse, true);
|
||||
$success = ! empty($decodedResponse) && $decodedResponse['success'];
|
||||
}
|
||||
|
||||
/* Message to show to the user */
|
||||
|
||||
@ -252,8 +252,8 @@ class HomeController extends AbstractController
|
||||
/**
|
||||
* Check whether session.gc_maxlifetime limits session validity.
|
||||
*/
|
||||
$gc_time = (int) ini_get('session.gc_maxlifetime');
|
||||
if ($gc_time < $GLOBALS['cfg']['LoginCookieValidity']) {
|
||||
$gcTime = (int) ini_get('session.gc_maxlifetime');
|
||||
if ($gcTime < $GLOBALS['cfg']['LoginCookieValidity']) {
|
||||
$this->errors[] = [
|
||||
'message' => __(
|
||||
'Your PHP parameter [a@https://www.php.net/manual/en/session.' .
|
||||
|
||||
@ -178,11 +178,11 @@ final class ImportController extends AbstractController
|
||||
preg_match(
|
||||
'/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
|
||||
$GLOBALS['sql_query'],
|
||||
$rename_table_names,
|
||||
$renameTableNames,
|
||||
)
|
||||
) {
|
||||
$GLOBALS['ajax_reload']['reload'] = true;
|
||||
$GLOBALS['ajax_reload']['table_name'] = Util::unQuote($rename_table_names[2]);
|
||||
$GLOBALS['ajax_reload']['table_name'] = Util::unQuote($renameTableNames[2]);
|
||||
}
|
||||
|
||||
$GLOBALS['sql_query'] = '';
|
||||
@ -223,9 +223,9 @@ final class ImportController extends AbstractController
|
||||
}
|
||||
|
||||
// Add console message id to response output
|
||||
$console_message_id = $request->getParsedBodyParam('console_message_id');
|
||||
if ($console_message_id !== null) {
|
||||
$this->response->addJSON('console_message_id', $console_message_id);
|
||||
$consoleMessageId = $request->getParsedBodyParam('console_message_id');
|
||||
if ($consoleMessageId !== null) {
|
||||
$this->response->addJSON('console_message_id', $consoleMessageId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,9 +242,9 @@ final class ImportController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$post_patterns = ['/^' . $GLOBALS['format'] . '_/'];
|
||||
$postPatterns = ['/^' . $GLOBALS['format'] . '_/'];
|
||||
|
||||
Core::setPostAsGlobal($post_patterns);
|
||||
Core::setPostAsGlobal($postPatterns);
|
||||
|
||||
$this->checkParameters(['import_type', 'format']);
|
||||
|
||||
@ -317,16 +317,16 @@ final class ImportController extends AbstractController
|
||||
$GLOBALS['result'] = false;
|
||||
|
||||
// Bookmark Support: get a query back from bookmark if required
|
||||
$id_bookmark = (int) $request->getParsedBodyParam('id_bookmark');
|
||||
$action_bookmark = (int) $request->getParsedBodyParam('action_bookmark');
|
||||
if ($id_bookmark !== 0) {
|
||||
switch ($action_bookmark) {
|
||||
$idBookmark = (int) $request->getParsedBodyParam('id_bookmark');
|
||||
$actionBookmark = (int) $request->getParsedBodyParam('action_bookmark');
|
||||
if ($idBookmark !== 0) {
|
||||
switch ($actionBookmark) {
|
||||
case 0: // bookmarked query that have to be run
|
||||
$bookmark = Bookmark::get(
|
||||
$this->dbi,
|
||||
$GLOBALS['cfg']['Server']['user'],
|
||||
DatabaseName::fromValue($GLOBALS['db']),
|
||||
$id_bookmark,
|
||||
$idBookmark,
|
||||
'id',
|
||||
$request->hasBodyParam('action_bookmark_all'),
|
||||
);
|
||||
@ -334,9 +334,9 @@ final class ImportController extends AbstractController
|
||||
break;
|
||||
}
|
||||
|
||||
$bookmark_variables = $request->getParsedBodyParam('bookmark_variable');
|
||||
if (is_array($bookmark_variables)) {
|
||||
$GLOBALS['import_text'] = $bookmark->applyVariables($bookmark_variables);
|
||||
$bookmarkVariables = $request->getParsedBodyParam('bookmark_variable');
|
||||
if (is_array($bookmarkVariables)) {
|
||||
$GLOBALS['import_text'] = $bookmark->applyVariables($bookmarkVariables);
|
||||
} else {
|
||||
$GLOBALS['import_text'] = $bookmark->getQuery();
|
||||
}
|
||||
@ -358,7 +358,7 @@ final class ImportController extends AbstractController
|
||||
$this->dbi,
|
||||
$GLOBALS['cfg']['Server']['user'],
|
||||
DatabaseName::fromValue($GLOBALS['db']),
|
||||
$id_bookmark,
|
||||
$idBookmark,
|
||||
);
|
||||
if (! $bookmark instanceof Bookmark) {
|
||||
break;
|
||||
@ -370,7 +370,7 @@ final class ImportController extends AbstractController
|
||||
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
|
||||
$this->response->addJSON('message', $GLOBALS['message']);
|
||||
$this->response->addJSON('sql_query', $GLOBALS['import_text']);
|
||||
$this->response->addJSON('action_bookmark', $action_bookmark);
|
||||
$this->response->addJSON('action_bookmark', $actionBookmark);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -382,7 +382,7 @@ final class ImportController extends AbstractController
|
||||
$this->dbi,
|
||||
$GLOBALS['cfg']['Server']['user'],
|
||||
DatabaseName::fromValue($GLOBALS['db']),
|
||||
$id_bookmark,
|
||||
$idBookmark,
|
||||
);
|
||||
if (! $bookmark instanceof Bookmark) {
|
||||
break;
|
||||
@ -395,8 +395,8 @@ final class ImportController extends AbstractController
|
||||
);
|
||||
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
|
||||
$this->response->addJSON('message', $GLOBALS['message']);
|
||||
$this->response->addJSON('action_bookmark', $action_bookmark);
|
||||
$this->response->addJSON('id_bookmark', $id_bookmark);
|
||||
$this->response->addJSON('action_bookmark', $actionBookmark);
|
||||
$this->response->addJSON('id_bookmark', $idBookmark);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -542,7 +542,7 @@ final class ImportController extends AbstractController
|
||||
|
||||
// Something to skip? (because timeout has passed)
|
||||
if (! $GLOBALS['error'] && $request->hasBodyParam('skip')) {
|
||||
$original_skip = $skip = intval($request->getParsedBodyParam('skip'));
|
||||
$originalSkip = $skip = intval($request->getParsedBodyParam('skip'));
|
||||
while ($skip > 0 && ! $GLOBALS['finished']) {
|
||||
$this->import->getNextChunk(
|
||||
$importHandle ?? null,
|
||||
@ -561,9 +561,9 @@ final class ImportController extends AbstractController
|
||||
$queriesToBeExecuted = [];
|
||||
|
||||
if (! $GLOBALS['error']) {
|
||||
/** @var ImportPlugin $import_plugin */
|
||||
$import_plugin = Plugins::getPlugin('import', $GLOBALS['format'], $GLOBALS['import_type']);
|
||||
if ($import_plugin == null) {
|
||||
/** @var ImportPlugin $importPlugin */
|
||||
$importPlugin = Plugins::getPlugin('import', $GLOBALS['format'], $GLOBALS['import_type']);
|
||||
if ($importPlugin == null) {
|
||||
$GLOBALS['message'] = Message::error(
|
||||
__('Could not load import plugins, please check your installation!'),
|
||||
);
|
||||
@ -578,12 +578,12 @@ final class ImportController extends AbstractController
|
||||
}
|
||||
|
||||
// Do the real import
|
||||
$default_fk_check = ForeignKey::handleDisableCheckInit();
|
||||
$defaultFkCheck = ForeignKey::handleDisableCheckInit();
|
||||
try {
|
||||
$queriesToBeExecuted = $import_plugin->doImport($importHandle ?? null);
|
||||
ForeignKey::handleDisableCheckCleanup($default_fk_check);
|
||||
$queriesToBeExecuted = $importPlugin->doImport($importHandle ?? null);
|
||||
ForeignKey::handleDisableCheckCleanup($defaultFkCheck);
|
||||
} catch (Throwable $e) {
|
||||
ForeignKey::handleDisableCheckCleanup($default_fk_check);
|
||||
ForeignKey::handleDisableCheckCleanup($defaultFkCheck);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
@ -600,11 +600,11 @@ final class ImportController extends AbstractController
|
||||
}
|
||||
|
||||
// Show correct message
|
||||
if ($id_bookmark !== 0 && $action_bookmark === 2) {
|
||||
if ($idBookmark !== 0 && $actionBookmark === 2) {
|
||||
$GLOBALS['message'] = Message::success(__('The bookmark has been deleted.'));
|
||||
$GLOBALS['display_query'] = $GLOBALS['import_text'];
|
||||
$GLOBALS['error'] = false; // unset error marker, it was used just to skip processing
|
||||
} elseif ($id_bookmark !== 0 && $action_bookmark === 1) {
|
||||
} elseif ($idBookmark !== 0 && $actionBookmark === 1) {
|
||||
$GLOBALS['message'] = Message::notice(__('Showing bookmark'));
|
||||
} elseif ($GLOBALS['finished'] && ! $GLOBALS['error']) {
|
||||
// Do not display the query with message, we do it separately
|
||||
@ -657,7 +657,7 @@ final class ImportController extends AbstractController
|
||||
$GLOBALS['message']->addParamHtml('<a href="' . $importUrl . '">');
|
||||
$GLOBALS['message']->addParamHtml('</a>');
|
||||
|
||||
if ($GLOBALS['offset'] == 0 || (isset($original_skip) && $original_skip == $GLOBALS['offset'])) {
|
||||
if ($GLOBALS['offset'] == 0 || (isset($originalSkip) && $originalSkip == $GLOBALS['offset'])) {
|
||||
$GLOBALS['message']->addText(
|
||||
__(
|
||||
'However on last run no data has been parsed,'
|
||||
@ -680,7 +680,7 @@ final class ImportController extends AbstractController
|
||||
// can choke on it so avoid parsing)
|
||||
$sqlLength = mb_strlen($GLOBALS['sql_query']);
|
||||
if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
|
||||
[$statementInfo, $GLOBALS['db'], $table_from_sql] = ParseAnalyze::sqlQuery(
|
||||
[$statementInfo, $GLOBALS['db'], $tableFromSql] = ParseAnalyze::sqlQuery(
|
||||
$GLOBALS['sql_query'],
|
||||
$GLOBALS['db'],
|
||||
);
|
||||
@ -688,8 +688,8 @@ final class ImportController extends AbstractController
|
||||
$GLOBALS['reload'] = $statementInfo->reload;
|
||||
$GLOBALS['offset'] = $statementInfo->offset;
|
||||
|
||||
if ($GLOBALS['table'] != $table_from_sql && $table_from_sql !== '') {
|
||||
$GLOBALS['table'] = $table_from_sql;
|
||||
if ($GLOBALS['table'] != $tableFromSql && $tableFromSql !== '') {
|
||||
$GLOBALS['table'] = $tableFromSql;
|
||||
}
|
||||
}
|
||||
|
||||
@ -707,11 +707,11 @@ final class ImportController extends AbstractController
|
||||
$queriesToBeExecuted = [$GLOBALS['sql_query']];
|
||||
}
|
||||
|
||||
$html_output = '';
|
||||
$htmlOutput = '';
|
||||
|
||||
foreach ($queriesToBeExecuted as $GLOBALS['sql_query']) {
|
||||
// parse sql query
|
||||
[$statementInfo, $GLOBALS['db'], $table_from_sql] = ParseAnalyze::sqlQuery(
|
||||
[$statementInfo, $GLOBALS['db'], $tableFromSql] = ParseAnalyze::sqlQuery(
|
||||
$GLOBALS['sql_query'],
|
||||
$GLOBALS['db'],
|
||||
);
|
||||
@ -737,11 +737,11 @@ final class ImportController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
if ($GLOBALS['table'] != $table_from_sql && $table_from_sql !== '') {
|
||||
$GLOBALS['table'] = $table_from_sql;
|
||||
if ($GLOBALS['table'] != $tableFromSql && $tableFromSql !== '') {
|
||||
$GLOBALS['table'] = $tableFromSql;
|
||||
}
|
||||
|
||||
$html_output .= $this->sql->executeQueryAndGetQueryResponse(
|
||||
$htmlOutput .= $this->sql->executeQueryAndGetQueryResponse(
|
||||
$statementInfo,
|
||||
false, // is_gotofile
|
||||
$GLOBALS['db'], // db
|
||||
@ -776,7 +776,7 @@ final class ImportController extends AbstractController
|
||||
}
|
||||
|
||||
$this->response->addJSON('ajax_reload', $GLOBALS['ajax_reload']);
|
||||
$this->response->addHTML($html_output);
|
||||
$this->response->addHTML($htmlOutput);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ final class AddNewPrimaryController extends AbstractController
|
||||
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$num_fields = 1;
|
||||
$numFields = 1;
|
||||
|
||||
$db = DatabaseName::tryFromValue($GLOBALS['db']);
|
||||
$table = TableName::tryFromValue($GLOBALS['table']);
|
||||
@ -34,7 +34,7 @@ final class AddNewPrimaryController extends AbstractController
|
||||
'Extra' => 'auto_increment',
|
||||
];
|
||||
$html = $this->normalization->getHtmlForCreateNewColumn(
|
||||
$num_fields,
|
||||
$numFields,
|
||||
$dbName,
|
||||
$tableName,
|
||||
$columnMeta,
|
||||
|
||||
@ -23,8 +23,8 @@ final class CreateNewColumnController extends AbstractController
|
||||
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$num_fields = min(4096, intval($request->getParsedBodyParam('numFields')));
|
||||
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
|
||||
$numFields = min(4096, intval($request->getParsedBodyParam('numFields')));
|
||||
$html = $this->normalization->getHtmlForCreateNewColumn($numFields, $GLOBALS['db'], $GLOBALS['table']);
|
||||
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
|
||||
$this->response->addHTML($html);
|
||||
}
|
||||
|
||||
@ -22,10 +22,10 @@ final class MoveRepeatingGroup extends AbstractController
|
||||
$repeatingColumns = $request->getParsedBodyParam('repeatingColumns');
|
||||
$newTable = $request->getParsedBodyParam('newTable');
|
||||
$newColumn = $request->getParsedBodyParam('newColumn');
|
||||
$primary_columns = $request->getParsedBodyParam('primary_columns');
|
||||
$primaryColumns = $request->getParsedBodyParam('primary_columns');
|
||||
$res = $this->normalization->moveRepeatingGroup(
|
||||
$repeatingColumns,
|
||||
$primary_columns,
|
||||
$primaryColumns,
|
||||
$newTable,
|
||||
$newColumn,
|
||||
$GLOBALS['table'],
|
||||
|
||||
@ -153,7 +153,7 @@ class ManageController extends AbstractController
|
||||
}
|
||||
|
||||
$GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $configuration);
|
||||
$_POST_bak = $_POST;
|
||||
$postParamBackup = $_POST;
|
||||
foreach ($GLOBALS['new_config'] as $k => $v) {
|
||||
$_POST[str_replace('/', '-', (string) $k)] = $v;
|
||||
}
|
||||
@ -161,7 +161,7 @@ class ManageController extends AbstractController
|
||||
$GLOBALS['cf']->resetConfigData();
|
||||
$GLOBALS['all_ok'] = $GLOBALS['form_display']->process(true, false);
|
||||
$GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $GLOBALS['form_display']->hasErrors();
|
||||
$_POST = $_POST_bak;
|
||||
$_POST = $postParamBackup;
|
||||
|
||||
if (! $GLOBALS['all_ok'] && $request->hasBodyParam('fix_errors')) {
|
||||
$GLOBALS['form_display']->fixErrors();
|
||||
|
||||
@ -38,7 +38,7 @@ final class DestroyController extends AbstractController
|
||||
$GLOBALS['errorUrl'] ??= null;
|
||||
$GLOBALS['reload'] ??= null;
|
||||
|
||||
$selected_dbs = $request->getParsedBodyParam('selected_dbs');
|
||||
$selectedDbs = $request->getParsedBodyParam('selected_dbs');
|
||||
|
||||
if (
|
||||
! $this->response->isAjax()
|
||||
@ -53,8 +53,8 @@ final class DestroyController extends AbstractController
|
||||
}
|
||||
|
||||
if (
|
||||
! is_array($selected_dbs)
|
||||
|| $selected_dbs === []
|
||||
! is_array($selectedDbs)
|
||||
|| $selectedDbs === []
|
||||
) {
|
||||
$message = Message::error(__('No databases selected.'));
|
||||
$json = ['message' => $message];
|
||||
@ -65,10 +65,10 @@ final class DestroyController extends AbstractController
|
||||
}
|
||||
|
||||
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/databases');
|
||||
$GLOBALS['selected'] = $selected_dbs;
|
||||
$numberOfDatabases = count($selected_dbs);
|
||||
$GLOBALS['selected'] = $selectedDbs;
|
||||
$numberOfDatabases = count($selectedDbs);
|
||||
|
||||
foreach ($selected_dbs as $database) {
|
||||
foreach ($selectedDbs as $database) {
|
||||
$this->relationCleanup->database($database);
|
||||
$aQuery = 'DROP DATABASE ' . Util::backquote($database);
|
||||
$GLOBALS['reload'] = true;
|
||||
|
||||
@ -204,12 +204,12 @@ class PrivilegesController extends AbstractController
|
||||
*/
|
||||
if ($request->hasBodyParam('update_privs')) {
|
||||
if (is_array($GLOBALS['dbname'])) {
|
||||
foreach ($GLOBALS['dbname'] as $key => $db_name) {
|
||||
foreach ($GLOBALS['dbname'] as $key => $dbName) {
|
||||
[$GLOBALS['sql_query'][$key], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
|
||||
($GLOBALS['username'] ?? ''),
|
||||
($GLOBALS['hostname'] ?? ''),
|
||||
($tablename ?? ($routinename ?? '')),
|
||||
($db_name ?? ''),
|
||||
($dbName ?? ''),
|
||||
$itemType,
|
||||
);
|
||||
}
|
||||
@ -290,10 +290,10 @@ class PrivilegesController extends AbstractController
|
||||
/**
|
||||
* Reloads the privilege tables into memory
|
||||
*/
|
||||
$message_ret = $serverPrivileges->updateMessageForReload();
|
||||
if ($message_ret !== null) {
|
||||
$GLOBALS['message'] = $message_ret;
|
||||
unset($message_ret);
|
||||
$messageRet = $serverPrivileges->updateMessageForReload();
|
||||
if ($messageRet !== null) {
|
||||
$GLOBALS['message'] = $messageRet;
|
||||
unset($messageRet);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,7 +309,7 @@ class PrivilegesController extends AbstractController
|
||||
|| $request->getParsedBodyParam('delete') === __('Go'))
|
||||
&& ! $request->hasQueryParam('showall')
|
||||
) {
|
||||
$extra_data = $serverPrivileges->getExtraDataForAjaxBehavior(
|
||||
$extraData = $serverPrivileges->getExtraDataForAjaxBehavior(
|
||||
($password ?? ''),
|
||||
($GLOBALS['sql_query'] ?? ''),
|
||||
($GLOBALS['hostname'] ?? ''),
|
||||
@ -319,7 +319,7 @@ class PrivilegesController extends AbstractController
|
||||
if (! empty($GLOBALS['message']) && $GLOBALS['message'] instanceof Message) {
|
||||
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
|
||||
$this->response->addJSON('message', $GLOBALS['message']);
|
||||
$this->response->addJSON($extra_data);
|
||||
$this->response->addJSON($extraData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -17,8 +17,8 @@ final class ShowConfigController
|
||||
{
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$form_display = new ConfigForm($GLOBALS['ConfigFile']);
|
||||
$form_display->save(['Config']);
|
||||
$formDisplay = new ConfigForm($GLOBALS['ConfigFile']);
|
||||
$formDisplay->save(['Config']);
|
||||
|
||||
$response = ResponseRenderer::getInstance();
|
||||
$response->disable();
|
||||
|
||||
@ -36,7 +36,7 @@ final class EnumValuesController extends AbstractController
|
||||
$this->checkUserPrivileges->getPrivileges();
|
||||
|
||||
$column = $request->getParsedBodyParam('column');
|
||||
$curr_value = $request->getParsedBodyParam('curr_value');
|
||||
$currValue = $request->getParsedBodyParam('curr_value');
|
||||
$values = $this->sql->getValuesForColumn($GLOBALS['db'], $GLOBALS['table'], strval($column));
|
||||
|
||||
if ($values === null) {
|
||||
@ -47,7 +47,7 @@ final class EnumValuesController extends AbstractController
|
||||
}
|
||||
|
||||
// Converts characters of $curr_value to HTML entities.
|
||||
$convertedCurrentValue = htmlentities(strval($curr_value), ENT_COMPAT, 'UTF-8');
|
||||
$convertedCurrentValue = htmlentities(strval($currValue), ENT_COMPAT, 'UTF-8');
|
||||
|
||||
$dropdown = $this->template->render('sql/enum_column_dropdown', [
|
||||
'values' => $values,
|
||||
|
||||
@ -34,19 +34,19 @@ final class RelationalValuesController extends AbstractController
|
||||
$this->checkUserPrivileges->getPrivileges();
|
||||
|
||||
$column = $request->getParsedBodyParam('column');
|
||||
$relation_key_or_display_column = $request->getParsedBodyParam('relation_key_or_display_column');
|
||||
$relationKeyOrDisplayColumn = $request->getParsedBodyParam('relation_key_or_display_column');
|
||||
|
||||
if ($_SESSION['tmpval']['relational_display'] === 'D' && $relation_key_or_display_column !== null) {
|
||||
$curr_value = $relation_key_or_display_column;
|
||||
if ($_SESSION['tmpval']['relational_display'] === 'D' && $relationKeyOrDisplayColumn !== null) {
|
||||
$currValue = $relationKeyOrDisplayColumn;
|
||||
} else {
|
||||
$curr_value = $request->getParsedBodyParam('curr_value');
|
||||
$currValue = $request->getParsedBodyParam('curr_value');
|
||||
}
|
||||
|
||||
$dropdown = $this->sql->getHtmlForRelationalColumnDropdown(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
strval($column),
|
||||
strval($curr_value),
|
||||
strval($currValue),
|
||||
);
|
||||
$this->response->addJSON('dropdown', $dropdown);
|
||||
}
|
||||
|
||||
@ -103,15 +103,15 @@ class SqlController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/** @var array<string>|null $bkm_fields */
|
||||
$bkm_fields = $request->getParsedBodyParam('bkm_fields');
|
||||
$sql_query = $request->getParsedBodyParam('sql_query');
|
||||
/** @var array<string>|null $bkmFields */
|
||||
$bkmFields = $request->getParsedBodyParam('bkm_fields');
|
||||
$sqlQuery = $request->getParsedBodyParam('sql_query');
|
||||
|
||||
// Coming from a bookmark dialog
|
||||
if ($bkm_fields !== null && $bkm_fields['bkm_sql_query'] != null) {
|
||||
$GLOBALS['sql_query'] = $bkm_fields['bkm_sql_query'];
|
||||
} elseif ($sql_query !== null) {
|
||||
$GLOBALS['sql_query'] = $sql_query;
|
||||
if ($bkmFields !== null && $bkmFields['bkm_sql_query'] != null) {
|
||||
$GLOBALS['sql_query'] = $bkmFields['bkm_sql_query'];
|
||||
} elseif ($sqlQuery !== null) {
|
||||
$GLOBALS['sql_query'] = $sqlQuery;
|
||||
} elseif (isset($_GET['sql_query'], $_GET['sql_signature'])) {
|
||||
if (Core::checkSqlQuerySignature($_GET['sql_query'], $_GET['sql_signature'])) {
|
||||
$GLOBALS['sql_query'] = $_GET['sql_query'];
|
||||
@ -119,8 +119,8 @@ class SqlController extends AbstractController
|
||||
}
|
||||
|
||||
// This one is just to fill $db
|
||||
if ($bkm_fields !== null && $bkm_fields['bkm_database'] != null) {
|
||||
$GLOBALS['db'] = $bkm_fields['bkm_database'];
|
||||
if ($bkmFields !== null && $bkmFields['bkm_database'] != null) {
|
||||
$GLOBALS['db'] = $bkmFields['bkm_database'];
|
||||
}
|
||||
|
||||
// Default to browse if no query set and we have table
|
||||
@ -178,10 +178,10 @@ class SqlController extends AbstractController
|
||||
/**
|
||||
* Bookmark add
|
||||
*/
|
||||
$store_bkm = $request->hasBodyParam('store_bkm');
|
||||
$bkm_all_users = $request->getParsedBodyParam('bkm_all_users'); // Should this be hasBodyParam?
|
||||
if ($store_bkm && $bkm_fields !== null) {
|
||||
$this->addBookmark($GLOBALS['goto'], $bkm_fields, (bool) $bkm_all_users);
|
||||
$storeBkm = $request->hasBodyParam('store_bkm');
|
||||
$bkmAllUsers = $request->getParsedBodyParam('bkm_all_users'); // Should this be hasBodyParam?
|
||||
if ($storeBkm && $bkmFields !== null) {
|
||||
$this->addBookmark($GLOBALS['goto'], $bkmFields, (bool) $bkmAllUsers);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -216,13 +216,13 @@ class SqlController extends AbstractController
|
||||
));
|
||||
}
|
||||
|
||||
/** @param array<string> $bkm_fields */
|
||||
private function addBookmark(string $goto, array $bkm_fields, bool $bkm_all_users): void
|
||||
/** @param array<string> $bkmFields */
|
||||
private function addBookmark(string $goto, array $bkmFields, bool $bkmAllUsers): void
|
||||
{
|
||||
$bookmark = Bookmark::createBookmark(
|
||||
$this->dbi,
|
||||
$bkm_fields,
|
||||
$bkm_all_users,
|
||||
$bkmFields,
|
||||
$bkmAllUsers,
|
||||
);
|
||||
|
||||
$result = null;
|
||||
@ -231,14 +231,14 @@ class SqlController extends AbstractController
|
||||
}
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
Core::sendHeaderLocation('./' . $goto . '&label=' . $bkm_fields['bkm_label']);
|
||||
Core::sendHeaderLocation('./' . $goto . '&label=' . $bkmFields['bkm_label']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$msg = Message::success(__('Bookmark %s has been created.'));
|
||||
$msg->addParam($bkm_fields['bkm_label']);
|
||||
$msg->addParam($bkmFields['bkm_label']);
|
||||
$this->response->addJSON('message', $msg);
|
||||
|
||||
return;
|
||||
|
||||
@ -114,8 +114,8 @@ class AddFieldController extends AbstractController
|
||||
);
|
||||
|
||||
if ($GLOBALS['result'] !== true) {
|
||||
$error_message_html = Generator::mysqlDie('', '', false, $GLOBALS['errorUrl'], false);
|
||||
$this->response->addHTML($error_message_html ?? '');
|
||||
$errorMessageHtml = Generator::mysqlDie('', '', false, $GLOBALS['errorUrl'], false);
|
||||
$this->response->addHTML($errorMessageHtml ?? '');
|
||||
$this->response->setRequestStatus(false);
|
||||
|
||||
return;
|
||||
@ -164,9 +164,9 @@ class AddFieldController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$urlParams = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($urlParams, '&');
|
||||
|
||||
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ class ChangeController extends AbstractController
|
||||
$foreigners = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
// Retrieve form parameters for insert/edit form
|
||||
$_form_params = $this->insertEdit->getFormParametersForInsertForm(
|
||||
$formParams = $this->insertEdit->getFormParametersForInsertForm(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$GLOBALS['where_clauses'],
|
||||
@ -173,7 +173,7 @@ class ChangeController extends AbstractController
|
||||
// Had to put the URI because when hosted on an https server,
|
||||
// some browsers send wrongly this form to the http server.
|
||||
|
||||
$html_output = '';
|
||||
$htmlOutput = '';
|
||||
// Set if we passed the first timestamp field
|
||||
$GLOBALS['timestamp_seen'] = false;
|
||||
$GLOBALS['columns_cnt'] = count($GLOBALS['table_columns']);
|
||||
@ -201,49 +201,49 @@ class ChangeController extends AbstractController
|
||||
//Insert/Edit form
|
||||
//If table has blob fields we have to disable ajax.
|
||||
$isUpload = $GLOBALS['config']->get('enable_upload');
|
||||
$html_output .= $this->insertEdit->getHtmlForInsertEditFormHeader($GLOBALS['has_blob_field'], $isUpload);
|
||||
$htmlOutput .= $this->insertEdit->getHtmlForInsertEditFormHeader($GLOBALS['has_blob_field'], $isUpload);
|
||||
|
||||
$html_output .= Url::getHiddenInputs($_form_params);
|
||||
$htmlOutput .= Url::getHiddenInputs($formParams);
|
||||
|
||||
// user can toggle the display of Function column and column types
|
||||
// (currently does not work for multi-edits)
|
||||
if (! $GLOBALS['cfg']['ShowFunctionFields'] || ! $GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
|
||||
$html_output .= __('Show');
|
||||
$htmlOutput .= __('Show');
|
||||
}
|
||||
|
||||
if (! $GLOBALS['cfg']['ShowFunctionFields']) {
|
||||
$html_output .= $this->insertEdit->showTypeOrFunction('function', $GLOBALS['urlParams'], false);
|
||||
$htmlOutput .= $this->insertEdit->showTypeOrFunction('function', $GLOBALS['urlParams'], false);
|
||||
}
|
||||
|
||||
if (! $GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
|
||||
$html_output .= $this->insertEdit->showTypeOrFunction('type', $GLOBALS['urlParams'], false);
|
||||
$htmlOutput .= $this->insertEdit->showTypeOrFunction('type', $GLOBALS['urlParams'], false);
|
||||
}
|
||||
|
||||
$GLOBALS['plugin_scripts'] = [];
|
||||
foreach ($GLOBALS['rows'] as $row_id => $current_row) {
|
||||
if (empty($current_row)) {
|
||||
$current_row = [];
|
||||
foreach ($GLOBALS['rows'] as $rowId => $currentRow) {
|
||||
if (empty($currentRow)) {
|
||||
$currentRow = [];
|
||||
}
|
||||
|
||||
$GLOBALS['jsvkey'] = (string) $row_id;
|
||||
$GLOBALS['jsvkey'] = (string) $rowId;
|
||||
$GLOBALS['vkey'] = '[multi_edit][' . $GLOBALS['jsvkey'] . ']';
|
||||
|
||||
$GLOBALS['current_result'] = (isset($GLOBALS['result'])
|
||||
&& is_array($GLOBALS['result']) && isset($GLOBALS['result'][$row_id])
|
||||
? $GLOBALS['result'][$row_id]
|
||||
&& is_array($GLOBALS['result']) && isset($GLOBALS['result'][$rowId])
|
||||
? $GLOBALS['result'][$rowId]
|
||||
: $GLOBALS['result']);
|
||||
$GLOBALS['repopulate'] = [];
|
||||
$GLOBALS['checked'] = true;
|
||||
if (isset($GLOBALS['unsaved_values'][$row_id])) {
|
||||
$GLOBALS['repopulate'] = $GLOBALS['unsaved_values'][$row_id];
|
||||
if (isset($GLOBALS['unsaved_values'][$rowId])) {
|
||||
$GLOBALS['repopulate'] = $GLOBALS['unsaved_values'][$rowId];
|
||||
$GLOBALS['checked'] = false;
|
||||
}
|
||||
|
||||
if ($GLOBALS['insert_mode'] && $row_id > 0) {
|
||||
$html_output .= $this->insertEdit->getHtmlForIgnoreOption($row_id, $GLOBALS['checked']);
|
||||
if ($GLOBALS['insert_mode'] && $rowId > 0) {
|
||||
$htmlOutput .= $this->insertEdit->getHtmlForIgnoreOption($rowId, $GLOBALS['checked']);
|
||||
}
|
||||
|
||||
$html_output .= $this->insertEdit->getHtmlForInsertEditRow(
|
||||
$htmlOutput .= $this->insertEdit->getHtmlForInsertEditRow(
|
||||
$GLOBALS['urlParams'],
|
||||
$GLOBALS['table_columns'],
|
||||
$GLOBALS['comments_map'],
|
||||
@ -252,7 +252,7 @@ class ChangeController extends AbstractController
|
||||
$GLOBALS['jsvkey'],
|
||||
$GLOBALS['vkey'],
|
||||
$GLOBALS['insert_mode'],
|
||||
$current_row,
|
||||
$currentRow,
|
||||
$GLOBALS['o_rows'],
|
||||
$GLOBALS['tabindex'],
|
||||
$GLOBALS['columns_cnt'],
|
||||
@ -261,7 +261,7 @@ class ChangeController extends AbstractController
|
||||
$GLOBALS['tabindex_for_value'],
|
||||
$GLOBALS['table'],
|
||||
$GLOBALS['db'],
|
||||
$row_id,
|
||||
$rowId,
|
||||
$GLOBALS['biggest_max_file_size'],
|
||||
$GLOBALS['text_dir'],
|
||||
$GLOBALS['repopulate'],
|
||||
@ -278,7 +278,7 @@ class ChangeController extends AbstractController
|
||||
}
|
||||
|
||||
$isNumeric = InsertEdit::isWhereClauseNumeric($GLOBALS['where_clause']);
|
||||
$html_output .= $this->template->render('table/insert/actions_panel', [
|
||||
$htmlOutput .= $this->template->render('table/insert/actions_panel', [
|
||||
'where_clause' => $GLOBALS['where_clause'],
|
||||
'after_insert' => $GLOBALS['after_insert'],
|
||||
'found_unique_key' => $GLOBALS['found_unique_key'],
|
||||
@ -286,18 +286,18 @@ class ChangeController extends AbstractController
|
||||
]);
|
||||
|
||||
if ($GLOBALS['biggest_max_file_size'] > 0) {
|
||||
$html_output .= '<input type="hidden" name="MAX_FILE_SIZE" value="'
|
||||
$htmlOutput .= '<input type="hidden" name="MAX_FILE_SIZE" value="'
|
||||
. $GLOBALS['biggest_max_file_size'] . '">' . "\n";
|
||||
}
|
||||
|
||||
$html_output .= '</form>';
|
||||
$htmlOutput .= '</form>';
|
||||
|
||||
$html_output .= $this->insertEdit->getHtmlForGisEditor();
|
||||
$htmlOutput .= $this->insertEdit->getHtmlForGisEditor();
|
||||
// end Insert/Edit form
|
||||
|
||||
if ($GLOBALS['insert_mode']) {
|
||||
//Continue insertion form
|
||||
$html_output .= $this->insertEdit->getContinueInsertionForm(
|
||||
$htmlOutput .= $this->insertEdit->getContinueInsertionForm(
|
||||
$GLOBALS['table'],
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['where_clause_array'],
|
||||
@ -305,6 +305,6 @@ class ChangeController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
$this->response->addHTML($html_output);
|
||||
$this->response->addHTML($htmlOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ final class ChangeRowsController extends AbstractController
|
||||
// for the /table/change script.
|
||||
$GLOBALS['where_clause'] = [];
|
||||
if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) {
|
||||
foreach ($_POST['rows_to_delete'] as $i_where_clause) {
|
||||
$GLOBALS['where_clause'][] = $i_where_clause;
|
||||
foreach ($_POST['rows_to_delete'] as $eachWhereClause) {
|
||||
$GLOBALS['where_clause'][] = $eachWhereClause;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ class ChartController extends AbstractController
|
||||
'vendor/jqplot/plugins/jqplot.highlighter.js',
|
||||
]);
|
||||
|
||||
$url_params = [];
|
||||
$urlParams = [];
|
||||
|
||||
/**
|
||||
* Runs common work
|
||||
@ -82,18 +82,18 @@ class ChartController extends AbstractController
|
||||
if (strlen($GLOBALS['table']) > 0) {
|
||||
$this->checkParameters(['db', 'table']);
|
||||
|
||||
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$urlParams = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($urlParams, '&');
|
||||
|
||||
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$url_params['back'] = Url::getFromRoute('/table/sql');
|
||||
$urlParams['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$urlParams['back'] = Url::getFromRoute('/table/sql');
|
||||
$this->dbi->selectDb($GLOBALS['db']);
|
||||
} elseif (strlen($GLOBALS['db']) > 0) {
|
||||
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
|
||||
$url_params['back'] = Url::getFromRoute('/sql');
|
||||
$urlParams['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
|
||||
$urlParams['back'] = Url::getFromRoute('/sql');
|
||||
|
||||
$this->checkParameters(['db']);
|
||||
|
||||
@ -104,8 +104,8 @@ class ChartController extends AbstractController
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
|
||||
$url_params['back'] = Url::getFromRoute('/sql');
|
||||
$urlParams['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
|
||||
$urlParams['back'] = Url::getFromRoute('/sql');
|
||||
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
|
||||
|
||||
if ($this->dbi->isSuperUser()) {
|
||||
@ -114,9 +114,9 @@ class ChartController extends AbstractController
|
||||
}
|
||||
|
||||
$result = $this->dbi->tryQuery($GLOBALS['sql_query']);
|
||||
$fields_meta = $row = [];
|
||||
$fieldsMeta = $row = [];
|
||||
if ($result !== false) {
|
||||
$fields_meta = $this->dbi->getFieldsMeta($result);
|
||||
$fieldsMeta = $this->dbi->getFieldsMeta($result);
|
||||
$row = $result->fetchAssoc();
|
||||
}
|
||||
|
||||
@ -124,9 +124,9 @@ class ChartController extends AbstractController
|
||||
$numericColumnFound = false;
|
||||
foreach (array_keys($keys) as $idx) {
|
||||
if (
|
||||
isset($fields_meta[$idx]) && (
|
||||
$fields_meta[$idx]->isType(FieldMetadata::TYPE_INT)
|
||||
|| $fields_meta[$idx]->isType(FieldMetadata::TYPE_REAL)
|
||||
isset($fieldsMeta[$idx]) && (
|
||||
$fieldsMeta[$idx]->isType(FieldMetadata::TYPE_INT)
|
||||
|| $fieldsMeta[$idx]->isType(FieldMetadata::TYPE_REAL)
|
||||
)
|
||||
) {
|
||||
$numericColumnFound = true;
|
||||
@ -144,8 +144,8 @@ class ChartController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['db'] = $GLOBALS['db'];
|
||||
$url_params['reload'] = 1;
|
||||
$urlParams['db'] = $GLOBALS['db'];
|
||||
$urlParams['reload'] = 1;
|
||||
|
||||
$startAndNumberOfRowsFieldset = Generator::getStartAndNumberOfRowsFieldsetData($GLOBALS['sql_query']);
|
||||
|
||||
@ -153,9 +153,9 @@ class ChartController extends AbstractController
|
||||
* Displays the page
|
||||
*/
|
||||
$this->render('table/chart/tbl_chart', [
|
||||
'url_params' => $url_params,
|
||||
'url_params' => $urlParams,
|
||||
'keys' => $keys,
|
||||
'fields_meta' => $fields_meta,
|
||||
'fields_meta' => $fieldsMeta,
|
||||
'table_has_a_numeric_column' => true,
|
||||
'start_and_number_of_rows_fieldset' => $startAndNumberOfRowsFieldset,
|
||||
]);
|
||||
@ -189,9 +189,9 @@ class ChartController extends AbstractController
|
||||
$statement->limit = new Limit($rows, $start);
|
||||
}
|
||||
|
||||
$sql_with_limit = $statement->build();
|
||||
$sqlWithLimit = $statement->build();
|
||||
|
||||
$result = $this->dbi->tryQuery($sql_with_limit);
|
||||
$result = $this->dbi->tryQuery($sqlWithLimit);
|
||||
$data = [];
|
||||
if ($result !== false) {
|
||||
$data = $result->fetchAllAssoc();
|
||||
@ -204,20 +204,20 @@ class ChartController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$sanitized_data = [];
|
||||
$sanitizedData = [];
|
||||
|
||||
foreach ($data as $data_row) {
|
||||
$tmp_row = [];
|
||||
foreach ($data_row as $data_column => $data_value) {
|
||||
$escaped_value = $data_value === null ? null : htmlspecialchars($data_value);
|
||||
$tmp_row[htmlspecialchars($data_column)] = $escaped_value;
|
||||
foreach ($data as $dataRow) {
|
||||
$tmpRow = [];
|
||||
foreach ($dataRow as $dataColumn => $dataValue) {
|
||||
$escapedValue = $dataValue === null ? null : htmlspecialchars($dataValue);
|
||||
$tmpRow[htmlspecialchars($dataColumn)] = $escapedValue;
|
||||
}
|
||||
|
||||
$sanitized_data[] = $tmp_row;
|
||||
$sanitizedData[] = $tmpRow;
|
||||
}
|
||||
|
||||
$this->response->setRequestStatus(true);
|
||||
$this->response->addJSON('message', null);
|
||||
$this->response->addJSON('chartData', json_encode($sanitized_data));
|
||||
$this->response->addJSON('chartData', json_encode($sanitizedData));
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ final class DeleteRowsController extends AbstractController
|
||||
$GLOBALS['disp_query'] ??= null;
|
||||
$GLOBALS['active_page'] ??= null;
|
||||
|
||||
$mult_btn = $_POST['mult_btn'] ?? '';
|
||||
$multBtn = $_POST['mult_btn'] ?? '';
|
||||
$selected = $_POST['selected'] ?? [];
|
||||
|
||||
$relation = new Relation($this->dbi);
|
||||
@ -51,8 +51,8 @@ final class DeleteRowsController extends AbstractController
|
||||
$this->template,
|
||||
);
|
||||
|
||||
if ($mult_btn === __('Yes')) {
|
||||
$default_fk_check_value = ForeignKey::handleDisableCheckInit();
|
||||
if ($multBtn === __('Yes')) {
|
||||
$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();
|
||||
$GLOBALS['sql_query'] = '';
|
||||
|
||||
foreach ($selected as $row) {
|
||||
@ -70,7 +70,7 @@ final class DeleteRowsController extends AbstractController
|
||||
$_REQUEST['pos'] = $sql->calculatePosForLastPage($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['pos']);
|
||||
}
|
||||
|
||||
ForeignKey::handleDisableCheckCleanup($default_fk_check_value);
|
||||
ForeignKey::handleDisableCheckCleanup($defaultFkCheckValue);
|
||||
|
||||
$GLOBALS['disp_message'] = __('Your SQL query has been executed successfully.');
|
||||
$GLOBALS['disp_query'] = $GLOBALS['sql_query'];
|
||||
|
||||
@ -45,8 +45,8 @@ final class ExportRowsController extends AbstractController
|
||||
// for the /table/change script.
|
||||
$GLOBALS['where_clause'] = [];
|
||||
if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) {
|
||||
foreach ($_POST['rows_to_delete'] as $i_where_clause) {
|
||||
$GLOBALS['where_clause'][] = $i_where_clause;
|
||||
foreach ($_POST['rows_to_delete'] as $eachWhereClause) {
|
||||
$GLOBALS['where_clause'][] = $eachWhereClause;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -195,7 +195,7 @@ class FindReplaceController extends AbstractController
|
||||
if ($useRegex) {
|
||||
$result = $this->getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet);
|
||||
} else {
|
||||
$sql_query = 'SELECT '
|
||||
$sqlQuery = 'SELECT '
|
||||
. Util::backquote($column) . ','
|
||||
. ' REPLACE('
|
||||
. Util::backquote($column) . ", '" . $find . "', '"
|
||||
@ -209,10 +209,10 @@ class FindReplaceController extends AbstractController
|
||||
// change the collation of the 2nd operand to a case sensitive
|
||||
// binary collation to make sure that the comparison
|
||||
// is case sensitive
|
||||
$sql_query .= ' GROUP BY ' . Util::backquote($column)
|
||||
$sqlQuery .= ' GROUP BY ' . Util::backquote($column)
|
||||
. ' ORDER BY ' . Util::backquote($column) . ' ASC';
|
||||
|
||||
$result = $this->dbi->fetchResult($sql_query, 0);
|
||||
$result = $this->dbi->fetchResult($sqlQuery, 0);
|
||||
}
|
||||
|
||||
return $this->template->render('table/find_replace/replace_preview', [
|
||||
@ -243,7 +243,7 @@ class FindReplaceController extends AbstractController
|
||||
string $charSet,
|
||||
): array|bool {
|
||||
$column = $this->columnNames[$columnIndex];
|
||||
$sql_query = 'SELECT '
|
||||
$sqlQuery = 'SELECT '
|
||||
. Util::backquote($column) . ','
|
||||
. ' 1,' // to add an extra column that will have replaced value
|
||||
. ' COUNT(*)'
|
||||
@ -254,10 +254,10 @@ class FindReplaceController extends AbstractController
|
||||
. $charSet . '_bin'; // here we
|
||||
// change the collation of the 2nd operand to a case sensitive
|
||||
// binary collation to make sure that the comparison is case sensitive
|
||||
$sql_query .= ' GROUP BY ' . Util::backquote($column)
|
||||
$sqlQuery .= ' GROUP BY ' . Util::backquote($column)
|
||||
. ' ORDER BY ' . Util::backquote($column) . ' ASC';
|
||||
|
||||
$result = $this->dbi->fetchResult($sql_query, 0);
|
||||
$result = $this->dbi->fetchResult($sqlQuery, 0);
|
||||
|
||||
/* Iterate over possible delimiters to get one */
|
||||
$delimiters = [
|
||||
@ -305,32 +305,32 @@ class FindReplaceController extends AbstractController
|
||||
$column = $this->columnNames[$columnIndex];
|
||||
if ($useRegex) {
|
||||
$toReplace = $this->getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet);
|
||||
$sql_query = 'UPDATE ' . Util::backquote($GLOBALS['table'])
|
||||
$sqlQuery = 'UPDATE ' . Util::backquote($GLOBALS['table'])
|
||||
. ' SET ' . Util::backquote($column);
|
||||
|
||||
if (is_array($toReplace)) {
|
||||
if (count($toReplace) > 0) {
|
||||
$sql_query .= ' = CASE';
|
||||
$sqlQuery .= ' = CASE';
|
||||
foreach ($toReplace as $row) {
|
||||
$sql_query .= "\n WHEN " . Util::backquote($column)
|
||||
$sqlQuery .= "\n WHEN " . Util::backquote($column)
|
||||
. ' = ' . $this->dbi->quoteString($row[0])
|
||||
. ' THEN ' . $this->dbi->quoteString($row[1]);
|
||||
}
|
||||
|
||||
$sql_query .= ' END';
|
||||
$sqlQuery .= ' END';
|
||||
} else {
|
||||
$sql_query .= ' = ' . Util::backquote($column);
|
||||
$sqlQuery .= ' = ' . Util::backquote($column);
|
||||
}
|
||||
}
|
||||
|
||||
$sql_query .= ' WHERE ' . Util::backquote($column)
|
||||
$sqlQuery .= ' WHERE ' . Util::backquote($column)
|
||||
. ' RLIKE ' . $this->dbi->quoteString($find) . ' COLLATE '
|
||||
. $charSet . '_bin'; // here we
|
||||
// change the collation of the 2nd operand to a case sensitive
|
||||
// binary collation to make sure that the comparison
|
||||
// is case sensitive
|
||||
} else {
|
||||
$sql_query = 'UPDATE ' . Util::backquote($GLOBALS['table'])
|
||||
$sqlQuery = 'UPDATE ' . Util::backquote($GLOBALS['table'])
|
||||
. ' SET ' . Util::backquote($column) . ' ='
|
||||
. ' REPLACE('
|
||||
. Util::backquote($column) . ", '" . $find . "', '"
|
||||
@ -343,7 +343,7 @@ class FindReplaceController extends AbstractController
|
||||
// is case sensitive
|
||||
}
|
||||
|
||||
$this->dbi->query($sql_query);
|
||||
$GLOBALS['sql_query'] = $sql_query;
|
||||
$this->dbi->query($sqlQuery);
|
||||
$GLOBALS['sql_query'] = $sqlQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,15 +64,15 @@ final class GisVisualizationController extends AbstractController
|
||||
// Find the candidate fields for label column and spatial column
|
||||
$labelCandidates = [];
|
||||
$spatialCandidates = [];
|
||||
foreach ($meta as $column_meta) {
|
||||
if ($column_meta->name === '') {
|
||||
foreach ($meta as $columnMeta) {
|
||||
if ($columnMeta->name === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($column_meta->isMappedTypeGeometry) {
|
||||
$spatialCandidates[] = $column_meta->name;
|
||||
if ($columnMeta->isMappedTypeGeometry) {
|
||||
$spatialCandidates[] = $columnMeta->name;
|
||||
} else {
|
||||
$labelCandidates[] = $column_meta->name;
|
||||
$labelCandidates[] = $columnMeta->name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -78,16 +78,16 @@ class IndexesController extends AbstractController
|
||||
private function displayForm(Index $index): void
|
||||
{
|
||||
$this->dbi->selectDb($GLOBALS['db']);
|
||||
$add_fields = 0;
|
||||
$addFields = 0;
|
||||
if (isset($_POST['index']) && is_array($_POST['index'])) {
|
||||
// coming already from form
|
||||
if (isset($_POST['index']['columns']['names'])) {
|
||||
$add_fields = count($_POST['index']['columns']['names'])
|
||||
$addFields = count($_POST['index']['columns']['names'])
|
||||
- $index->getColumnCount();
|
||||
}
|
||||
|
||||
if (isset($_POST['add_fields'])) {
|
||||
$add_fields += $_POST['added_fields'];
|
||||
$addFields += $_POST['added_fields'];
|
||||
}
|
||||
} elseif (isset($_POST['create_index'])) {
|
||||
/**
|
||||
@ -98,43 +98,43 @@ class IndexesController extends AbstractController
|
||||
* @see https://mariadb.com/kb/en/innodb-limitations/#limitations-on-schema "maximum of 16 columns"
|
||||
* @see https://mariadb.com/kb/en/myisam-overview/#myisam-features "Maximum of 32 columns per index"
|
||||
*/
|
||||
$add_fields = 1;
|
||||
$addFields = 1;
|
||||
if (is_numeric($_POST['added_fields']) && $_POST['added_fields'] >= 2) {
|
||||
$add_fields = min((int) $_POST['added_fields'], 16);
|
||||
$addFields = min((int) $_POST['added_fields'], 16);
|
||||
}
|
||||
}
|
||||
|
||||
// Get fields and stores their name/type
|
||||
if (isset($_POST['create_edit_table'])) {
|
||||
$fields = json_decode($_POST['columns'], true);
|
||||
$index_params = [
|
||||
$indexParams = [
|
||||
'Non_unique' => $_POST['index']['Index_choice'] !== 'UNIQUE',
|
||||
];
|
||||
$index->set($index_params);
|
||||
$add_fields = count($fields);
|
||||
$index->set($indexParams);
|
||||
$addFields = count($fields);
|
||||
} else {
|
||||
$fields = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table'])
|
||||
->getNameAndTypeOfTheColumns();
|
||||
}
|
||||
|
||||
$form_params = [
|
||||
$formParams = [
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table'],
|
||||
];
|
||||
|
||||
if (isset($_POST['create_index'])) {
|
||||
$form_params['create_index'] = 1;
|
||||
$formParams['create_index'] = 1;
|
||||
} elseif (isset($_POST['old_index'])) {
|
||||
$form_params['old_index'] = $_POST['old_index'];
|
||||
$formParams['old_index'] = $_POST['old_index'];
|
||||
} elseif (isset($_POST['index'])) {
|
||||
$form_params['old_index'] = $_POST['index'];
|
||||
$formParams['old_index'] = $_POST['index'];
|
||||
}
|
||||
|
||||
$this->render('table/index_form', [
|
||||
'fields' => $fields,
|
||||
'index' => $index,
|
||||
'form_params' => $form_params,
|
||||
'add_fields' => $add_fields,
|
||||
'form_params' => $formParams,
|
||||
'add_fields' => $addFields,
|
||||
'create_edit_table' => isset($_POST['create_edit_table']),
|
||||
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
|
||||
'is_from_nav' => isset($_POST['is_from_nav']),
|
||||
|
||||
@ -80,7 +80,7 @@ class OperationsController extends AbstractController
|
||||
$GLOBALS['table'] = mb_strtolower($GLOBALS['table']);
|
||||
}
|
||||
|
||||
$pma_table = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
$pmaTable = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
$this->addScriptFiles(['table/operations.js']);
|
||||
|
||||
@ -102,29 +102,29 @@ class OperationsController extends AbstractController
|
||||
*/
|
||||
$this->dbi->selectDb($GLOBALS['db']);
|
||||
|
||||
$GLOBALS['reread_info'] = $pma_table->getStatusInfo(null, false);
|
||||
$GLOBALS['showtable'] = $pma_table->getStatusInfo(
|
||||
$GLOBALS['reread_info'] = $pmaTable->getStatusInfo(null, false);
|
||||
$GLOBALS['showtable'] = $pmaTable->getStatusInfo(
|
||||
null,
|
||||
(isset($GLOBALS['reread_info']) && $GLOBALS['reread_info']),
|
||||
);
|
||||
if ($pma_table->isView()) {
|
||||
if ($pmaTable->isView()) {
|
||||
$GLOBALS['tbl_is_view'] = true;
|
||||
$GLOBALS['tbl_storage_engine'] = __('View');
|
||||
$GLOBALS['show_comment'] = null;
|
||||
} else {
|
||||
$GLOBALS['tbl_is_view'] = false;
|
||||
$GLOBALS['tbl_storage_engine'] = $pma_table->getStorageEngine();
|
||||
$GLOBALS['show_comment'] = $pma_table->getComment();
|
||||
$GLOBALS['tbl_storage_engine'] = $pmaTable->getStorageEngine();
|
||||
$GLOBALS['show_comment'] = $pmaTable->getComment();
|
||||
}
|
||||
|
||||
$GLOBALS['tbl_collation'] = $pma_table->getCollation();
|
||||
$GLOBALS['table_info_num_rows'] = $pma_table->getNumRows();
|
||||
$GLOBALS['row_format'] = $pma_table->getRowFormat();
|
||||
$GLOBALS['auto_increment'] = $pma_table->getAutoIncrement();
|
||||
$GLOBALS['create_options'] = $pma_table->getCreateOptions();
|
||||
$GLOBALS['tbl_collation'] = $pmaTable->getCollation();
|
||||
$GLOBALS['table_info_num_rows'] = $pmaTable->getNumRows();
|
||||
$GLOBALS['row_format'] = $pmaTable->getRowFormat();
|
||||
$GLOBALS['auto_increment'] = $pmaTable->getAutoIncrement();
|
||||
$GLOBALS['create_options'] = $pmaTable->getCreateOptions();
|
||||
|
||||
// set initial value of these variables, based on the current table engine
|
||||
if ($pma_table->isEngine('ARIA')) {
|
||||
if ($pmaTable->isEngine('ARIA')) {
|
||||
// the value for transactional can be implicit
|
||||
// (no create option found, in this case it means 1)
|
||||
// or explicit (option found with a value of 0 or 1)
|
||||
@ -136,7 +136,7 @@ class OperationsController extends AbstractController
|
||||
$GLOBALS['create_options']['page_checksum'] ??= '';
|
||||
}
|
||||
|
||||
$pma_table = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
$pmaTable = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
$GLOBALS['reread_info'] = false;
|
||||
$GLOBALS['table_alters'] = [];
|
||||
|
||||
@ -173,7 +173,7 @@ class OperationsController extends AbstractController
|
||||
* Updates table comment, type and options if required
|
||||
*/
|
||||
if ($request->hasBodyParam('submitoptions')) {
|
||||
$_message = '';
|
||||
$newMessage = '';
|
||||
$GLOBALS['warning_messages'] = [];
|
||||
|
||||
/** @var mixed $newName */
|
||||
@ -184,10 +184,10 @@ class OperationsController extends AbstractController
|
||||
}
|
||||
|
||||
// Get original names before rename operation
|
||||
$oldTable = $pma_table->getName();
|
||||
$oldDb = $pma_table->getDbName();
|
||||
$oldTable = $pmaTable->getName();
|
||||
$oldDb = $pmaTable->getDbName();
|
||||
|
||||
if ($pma_table->rename($newName)) {
|
||||
if ($pmaTable->rename($newName)) {
|
||||
if ($request->getParsedBodyParam('adjust_privileges')) {
|
||||
/** @var mixed $dbParam */
|
||||
$dbParam = $request->getParsedBodyParam('db');
|
||||
@ -202,13 +202,13 @@ class OperationsController extends AbstractController
|
||||
// Reselect the original DB
|
||||
$GLOBALS['db'] = $oldDb;
|
||||
$this->dbi->selectDb($oldDb);
|
||||
$_message .= $pma_table->getLastMessage();
|
||||
$newMessage .= $pmaTable->getLastMessage();
|
||||
$GLOBALS['result'] = true;
|
||||
$GLOBALS['table'] = $pma_table->getName();
|
||||
$GLOBALS['table'] = $pmaTable->getName();
|
||||
$GLOBALS['reread_info'] = true;
|
||||
$GLOBALS['reload'] = true;
|
||||
} else {
|
||||
$_message .= $pma_table->getLastError();
|
||||
$newMessage .= $pmaTable->getLastError();
|
||||
$GLOBALS['result'] = false;
|
||||
}
|
||||
}
|
||||
@ -221,7 +221,7 @@ class OperationsController extends AbstractController
|
||||
) {
|
||||
$GLOBALS['new_tbl_storage_engine'] = mb_strtoupper($newTableStorageEngine);
|
||||
|
||||
if ($pma_table->isEngine('ARIA')) {
|
||||
if ($pmaTable->isEngine('ARIA')) {
|
||||
$GLOBALS['create_options']['transactional'] = ($GLOBALS['create_options']['transactional'] ?? '')
|
||||
== '0' ? '0' : '1';
|
||||
$GLOBALS['create_options']['page_checksum'] ??= '';
|
||||
@ -230,10 +230,10 @@ class OperationsController extends AbstractController
|
||||
$GLOBALS['new_tbl_storage_engine'] = '';
|
||||
}
|
||||
|
||||
$GLOBALS['row_format'] = $GLOBALS['create_options']['row_format'] ?? $pma_table->getRowFormat();
|
||||
$GLOBALS['row_format'] = $GLOBALS['create_options']['row_format'] ?? $pmaTable->getRowFormat();
|
||||
|
||||
$GLOBALS['table_alters'] = $this->operations->getTableAltersArray(
|
||||
$pma_table,
|
||||
$pmaTable,
|
||||
$GLOBALS['create_options']['pack_keys'],
|
||||
(empty($GLOBALS['create_options']['checksum']) ? '0' : '1'),
|
||||
($GLOBALS['create_options']['page_checksum'] ?? ''),
|
||||
@ -323,39 +323,39 @@ class OperationsController extends AbstractController
|
||||
// a change, clear the cache
|
||||
$this->dbi->getCache()->clearTableCache();
|
||||
$this->dbi->selectDb($GLOBALS['db']);
|
||||
$GLOBALS['showtable'] = $pma_table->getStatusInfo(null, true);
|
||||
if ($pma_table->isView()) {
|
||||
$GLOBALS['showtable'] = $pmaTable->getStatusInfo(null, true);
|
||||
if ($pmaTable->isView()) {
|
||||
$GLOBALS['tbl_is_view'] = true;
|
||||
$GLOBALS['tbl_storage_engine'] = __('View');
|
||||
$GLOBALS['show_comment'] = null;
|
||||
} else {
|
||||
$GLOBALS['tbl_is_view'] = false;
|
||||
$GLOBALS['tbl_storage_engine'] = $pma_table->getStorageEngine();
|
||||
$GLOBALS['show_comment'] = $pma_table->getComment();
|
||||
$GLOBALS['tbl_storage_engine'] = $pmaTable->getStorageEngine();
|
||||
$GLOBALS['show_comment'] = $pmaTable->getComment();
|
||||
}
|
||||
|
||||
$GLOBALS['tbl_collation'] = $pma_table->getCollation();
|
||||
$GLOBALS['table_info_num_rows'] = $pma_table->getNumRows();
|
||||
$GLOBALS['row_format'] = $pma_table->getRowFormat();
|
||||
$GLOBALS['auto_increment'] = $pma_table->getAutoIncrement();
|
||||
$GLOBALS['create_options'] = $pma_table->getCreateOptions();
|
||||
$GLOBALS['tbl_collation'] = $pmaTable->getCollation();
|
||||
$GLOBALS['table_info_num_rows'] = $pmaTable->getNumRows();
|
||||
$GLOBALS['row_format'] = $pmaTable->getRowFormat();
|
||||
$GLOBALS['auto_increment'] = $pmaTable->getAutoIncrement();
|
||||
$GLOBALS['create_options'] = $pmaTable->getCreateOptions();
|
||||
}
|
||||
|
||||
unset($GLOBALS['reread_info']);
|
||||
|
||||
if (isset($GLOBALS['result']) && empty($GLOBALS['message_to_show'])) {
|
||||
if (empty($_message)) {
|
||||
if (empty($newMessage)) {
|
||||
if (empty($GLOBALS['sql_query'])) {
|
||||
$_message = Message::success(__('No change'));
|
||||
$newMessage = Message::success(__('No change'));
|
||||
} else {
|
||||
$_message = $GLOBALS['result']
|
||||
$newMessage = $GLOBALS['result']
|
||||
? Message::success()
|
||||
: Message::error();
|
||||
}
|
||||
|
||||
if ($this->response->isAjax()) {
|
||||
$this->response->setRequestStatus($_message->isSuccess());
|
||||
$this->response->addJSON('message', $_message);
|
||||
$this->response->setRequestStatus($newMessage->isSuccess());
|
||||
$this->response->addJSON('message', $newMessage);
|
||||
if (! empty($GLOBALS['sql_query'])) {
|
||||
$this->response->addJSON(
|
||||
'sql_query',
|
||||
@ -366,18 +366,18 @@ class OperationsController extends AbstractController
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$_message = $GLOBALS['result']
|
||||
? Message::success($_message)
|
||||
: Message::error($_message);
|
||||
$newMessage = $GLOBALS['result']
|
||||
? Message::success($newMessage)
|
||||
: Message::error($newMessage);
|
||||
}
|
||||
|
||||
if (! empty($GLOBALS['warning_messages'])) {
|
||||
$_message = new Message();
|
||||
$_message->addMessagesString($GLOBALS['warning_messages']);
|
||||
$_message->isError(true);
|
||||
$newMessage = new Message();
|
||||
$newMessage->addMessagesString($GLOBALS['warning_messages']);
|
||||
$newMessage->isError(true);
|
||||
if ($this->response->isAjax()) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', $_message);
|
||||
$this->response->addJSON('message', $newMessage);
|
||||
if (! empty($GLOBALS['sql_query'])) {
|
||||
$this->response->addJSON(
|
||||
'sql_query',
|
||||
@ -393,15 +393,15 @@ class OperationsController extends AbstractController
|
||||
|
||||
if (empty($GLOBALS['sql_query'])) {
|
||||
$this->response->addHTML(
|
||||
$_message->getDisplay(),
|
||||
$newMessage->getDisplay(),
|
||||
);
|
||||
} else {
|
||||
$this->response->addHTML(
|
||||
Generator::getMessage($_message, $GLOBALS['sql_query']),
|
||||
Generator::getMessage($newMessage, $GLOBALS['sql_query']),
|
||||
);
|
||||
}
|
||||
|
||||
unset($_message);
|
||||
unset($newMessage);
|
||||
}
|
||||
|
||||
$GLOBALS['urlParams']['goto'] = $GLOBALS['urlParams']['back'] = Url::getFromRoute('/table/operations');
|
||||
@ -459,11 +459,11 @@ class OperationsController extends AbstractController
|
||||
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
|
||||
|
||||
$hasPackKeys = isset($GLOBALS['create_options']['pack_keys'])
|
||||
&& $pma_table->isEngine(['MYISAM', 'ARIA', 'ISAM']);
|
||||
$hasChecksumAndDelayKeyWrite = $pma_table->isEngine(['MYISAM', 'ARIA']);
|
||||
$hasTransactionalAndPageChecksum = $pma_table->isEngine('ARIA');
|
||||
&& $pmaTable->isEngine(['MYISAM', 'ARIA', 'ISAM']);
|
||||
$hasChecksumAndDelayKeyWrite = $pmaTable->isEngine(['MYISAM', 'ARIA']);
|
||||
$hasTransactionalAndPageChecksum = $pmaTable->isEngine('ARIA');
|
||||
$hasAutoIncrement = strlen($GLOBALS['auto_increment']) > 0
|
||||
&& $pma_table->isEngine(['MYISAM', 'ARIA', 'INNODB', 'PBXT', 'ROCKSDB']);
|
||||
&& $pmaTable->isEngine(['MYISAM', 'ARIA', 'INNODB', 'PBXT', 'ROCKSDB']);
|
||||
|
||||
$possibleRowFormats = $this->operations->getPossibleRowFormat();
|
||||
|
||||
|
||||
@ -120,20 +120,20 @@ final class RelationController extends AbstractController
|
||||
// in mysqli
|
||||
$columns = $this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
$column_array = [];
|
||||
$column_hash_array = [];
|
||||
$column_array[''] = '';
|
||||
$columnArray = [];
|
||||
$columnHashArray = [];
|
||||
$columnArray[''] = '';
|
||||
foreach ($columns as $column) {
|
||||
if (strtoupper($storageEngine) !== 'INNODB' && empty($column['Key'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$column_array[$column['Field']] = $column['Field'];
|
||||
$column_hash_array[$column['Field']] = md5($column['Field']);
|
||||
$columnArray[$column['Field']] = $column['Field'];
|
||||
$columnHashArray[$column['Field']] = md5($column['Field']);
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
uksort($column_array, 'strnatcasecmp');
|
||||
uksort($columnArray, 'strnatcasecmp');
|
||||
}
|
||||
|
||||
$foreignKeyRow = '';
|
||||
@ -165,7 +165,7 @@ final class RelationController extends AbstractController
|
||||
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
|
||||
'i' => $i,
|
||||
'one_key' => $oneKey,
|
||||
'column_array' => $column_array,
|
||||
'column_array' => $columnArray,
|
||||
'options_array' => $options,
|
||||
'tbl_storage_engine' => $storageEngine,
|
||||
'db' => $GLOBALS['db'],
|
||||
@ -184,7 +184,7 @@ final class RelationController extends AbstractController
|
||||
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
|
||||
'i' => $i,
|
||||
'one_key' => [],
|
||||
'column_array' => $column_array,
|
||||
'column_array' => $columnArray,
|
||||
'options_array' => $options,
|
||||
'tbl_storage_engine' => $storageEngine,
|
||||
'db' => $GLOBALS['db'],
|
||||
@ -207,8 +207,8 @@ final class RelationController extends AbstractController
|
||||
'existrel' => $relations,
|
||||
'existrel_foreign' => $existrelForeign,
|
||||
'options_array' => $options,
|
||||
'column_array' => $column_array,
|
||||
'column_hash_array' => $column_hash_array,
|
||||
'column_array' => $columnArray,
|
||||
'column_hash_array' => $columnHashArray,
|
||||
'save_row' => array_values($columns),
|
||||
'url_params' => $GLOBALS['urlParams'],
|
||||
'databases' => $this->dbi->getDatabaseList(),
|
||||
@ -245,9 +245,9 @@ final class RelationController extends AbstractController
|
||||
*/
|
||||
private function updateForForeignKeys(Table $table, array $options, array $relationsForeign): void
|
||||
{
|
||||
$multi_edit_columns_name = $_POST['foreign_key_fields_name'] ?? null;
|
||||
$preview_sql_data = '';
|
||||
$seen_error = false;
|
||||
$multiEditColumnsName = $_POST['foreign_key_fields_name'] ?? null;
|
||||
$previewSqlData = '';
|
||||
$seenError = false;
|
||||
|
||||
// (for now, one index name only; we keep the definitions if the
|
||||
// foreign db is not the same)
|
||||
@ -257,12 +257,12 @@ final class RelationController extends AbstractController
|
||||
) {
|
||||
[
|
||||
$html,
|
||||
$preview_sql_data,
|
||||
$display_query,
|
||||
$seen_error,
|
||||
$previewSqlData,
|
||||
$displayQuery,
|
||||
$seenError,
|
||||
] = $table->updateForeignKeys(
|
||||
$_POST['destination_foreign_db'],
|
||||
$multi_edit_columns_name,
|
||||
$multiEditColumnsName,
|
||||
$_POST['destination_foreign_table'],
|
||||
$_POST['destination_foreign_column'],
|
||||
$options,
|
||||
@ -276,16 +276,16 @@ final class RelationController extends AbstractController
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_POST['preview_sql'])) {
|
||||
Core::previewSQL($preview_sql_data);
|
||||
Core::previewSQL($previewSqlData);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($display_query) || $seen_error) {
|
||||
if (empty($displayQuery) || $seenError) {
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['display_query'] = $display_query;
|
||||
$GLOBALS['displayQuery'] = $displayQuery;
|
||||
$this->response->addHTML(
|
||||
Generator::getMessage(
|
||||
__('Your SQL query has been executed successfully.'),
|
||||
@ -305,11 +305,11 @@ final class RelationController extends AbstractController
|
||||
RelationFeature $relationFeature,
|
||||
array $relations,
|
||||
): void {
|
||||
$multi_edit_columns_name = $_POST['fields_name'] ?? null;
|
||||
$multiEditColumnsName = $_POST['fields_name'] ?? null;
|
||||
|
||||
if (
|
||||
! $table->updateInternalRelations(
|
||||
$multi_edit_columns_name,
|
||||
$multiEditColumnsName,
|
||||
$_POST['destination_db'],
|
||||
$_POST['destination_table'],
|
||||
$_POST['destination_column'],
|
||||
@ -335,13 +335,13 @@ final class RelationController extends AbstractController
|
||||
public function getDropdownValueForTable(): void
|
||||
{
|
||||
$foreignTable = $_POST['foreignTable'];
|
||||
$table_obj = $this->dbi->getTable($_POST['foreignDb'], $foreignTable);
|
||||
$tableObj = $this->dbi->getTable($_POST['foreignDb'], $foreignTable);
|
||||
// Since views do not have keys defined on them provide the full list of
|
||||
// columns
|
||||
if ($table_obj->isView()) {
|
||||
$columnList = $table_obj->getColumns(false, false);
|
||||
if ($tableObj->isView()) {
|
||||
$columnList = $tableObj->getColumns(false, false);
|
||||
} else {
|
||||
$columnList = $table_obj->getIndexedColumns(false, false);
|
||||
$columnList = $tableObj->getIndexedColumns(false, false);
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
@ -371,9 +371,9 @@ final class RelationController extends AbstractController
|
||||
if ($foreign) {
|
||||
$query = 'SHOW TABLE STATUS FROM '
|
||||
. Util::backquote($_POST['foreignDb']);
|
||||
$tables_rs = $this->dbi->query($query);
|
||||
$tablesRs = $this->dbi->query($query);
|
||||
|
||||
foreach ($tables_rs as $row) {
|
||||
foreach ($tablesRs as $row) {
|
||||
if (! isset($row['Engine']) || mb_strtoupper($row['Engine']) !== $storageEngine) {
|
||||
continue;
|
||||
}
|
||||
@ -383,8 +383,8 @@ final class RelationController extends AbstractController
|
||||
} else {
|
||||
$query = 'SHOW TABLES FROM '
|
||||
. Util::backquote($_POST['foreignDb']);
|
||||
$tables_rs = $this->dbi->query($query);
|
||||
$tables = $tables_rs->fetchAllColumn();
|
||||
$tablesRs = $this->dbi->query($query);
|
||||
$tables = $tablesRs->fetchAllColumn();
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
|
||||
@ -84,19 +84,19 @@ final class ReplaceController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$after_insert_actions = [
|
||||
$afterInsertActions = [
|
||||
'new_insert',
|
||||
'same_insert',
|
||||
'edit_next',
|
||||
];
|
||||
if (isset($_POST['after_insert']) && in_array($_POST['after_insert'], $after_insert_actions)) {
|
||||
if (isset($_POST['after_insert']) && in_array($_POST['after_insert'], $afterInsertActions)) {
|
||||
$GLOBALS['urlParams']['after_insert'] = $_POST['after_insert'];
|
||||
if (isset($_POST['where_clause'])) {
|
||||
foreach ($_POST['where_clause'] as $one_where_clause) {
|
||||
foreach ($_POST['where_clause'] as $oneWhereClause) {
|
||||
if ($_POST['after_insert'] === 'same_insert') {
|
||||
$GLOBALS['urlParams']['where_clause'][] = $one_where_clause;
|
||||
$GLOBALS['urlParams']['where_clause'][] = $oneWhereClause;
|
||||
} elseif ($_POST['after_insert'] === 'edit_next') {
|
||||
$this->insertEdit->setSessionForEditNext($one_where_clause);
|
||||
$this->insertEdit->setSessionForEditNext($oneWhereClause);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,10 +127,10 @@ final class ReplaceController extends AbstractController
|
||||
$insertErrors = [];
|
||||
$rowSkipped = false;
|
||||
$GLOBALS['unsaved_values'] = [];
|
||||
/** @var string|int $where_clause */
|
||||
foreach ($loopArray as $rownumber => $where_clause) {
|
||||
/** @var string|int $whereClause */
|
||||
foreach ($loopArray as $rowNumber => $whereClause) {
|
||||
// skip fields to be ignored
|
||||
if (! $usingKey && isset($_POST['insert_ignore_' . $where_clause])) {
|
||||
if (! $usingKey && isset($_POST['insert_ignore_' . $whereClause])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -138,108 +138,108 @@ final class ReplaceController extends AbstractController
|
||||
$queryValues = [];
|
||||
|
||||
// Map multi-edit keys to single-level arrays, dependent on how we got the fields
|
||||
$multi_edit_columns = $_POST['fields']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_columns_name = $_POST['fields_name']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_columns_prev = $_POST['fields_prev']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_funcs = $_POST['funcs']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_salt = $_POST['salt']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_columns_type = $_POST['fields_type']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_columns_null = $_POST['fields_null']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_columns_null_prev = $_POST['fields_null_prev']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_auto_increment = $_POST['auto_increment']['multi_edit'][$rownumber] ?? [];
|
||||
$multi_edit_virtual = $_POST['virtual']['multi_edit'][$rownumber] ?? [];
|
||||
$multiEditColumns = $_POST['fields']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditColumnsName = $_POST['fields_name']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditColumnsPrev = $_POST['fields_prev']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditFuncs = $_POST['funcs']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditSalt = $_POST['salt']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditColumnsType = $_POST['fields_type']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditColumnsNull = $_POST['fields_null']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditColumnsNullPrev = $_POST['fields_null_prev']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditAutoIncrement = $_POST['auto_increment']['multi_edit'][$rowNumber] ?? [];
|
||||
$multiEditVirtual = $_POST['virtual']['multi_edit'][$rowNumber] ?? [];
|
||||
|
||||
// Iterate in the order of $multi_edit_columns_name,
|
||||
// not $multi_edit_columns, to avoid problems
|
||||
// when inserting multiple entries
|
||||
$insert_fail = false;
|
||||
$insertFail = false;
|
||||
/** @var int|string $key */
|
||||
foreach ($multi_edit_columns_name as $key => $column_name) {
|
||||
foreach ($multiEditColumnsName as $key => $columnName) {
|
||||
// Note: $key is an md5 of the fieldname. The actual fieldname is
|
||||
// available in $multi_edit_columns_name[$key]
|
||||
|
||||
// When a select field is nullified, it's not present in $_POST so initialize it
|
||||
$multi_edit_columns[$key] ??= '';
|
||||
$multiEditColumns[$key] ??= '';
|
||||
|
||||
/** @var string[]|string $current_value */
|
||||
$current_value = $multi_edit_columns[$key];
|
||||
if (is_array($current_value)) {
|
||||
/** @var string[]|string $currentValue */
|
||||
$currentValue = $multiEditColumns[$key];
|
||||
if (is_array($currentValue)) {
|
||||
// Some column types accept comma-separated values e.g. set
|
||||
$current_value = implode(',', $current_value);
|
||||
$currentValue = implode(',', $currentValue);
|
||||
}
|
||||
|
||||
$file_to_insert = new File();
|
||||
$file_to_insert->checkTblChangeForm((string) $key, (string) $rownumber);
|
||||
$fileToInsert = new File();
|
||||
$fileToInsert->checkTblChangeForm((string) $key, (string) $rowNumber);
|
||||
|
||||
$possibly_uploaded_val = $file_to_insert->getContent();
|
||||
if ($possibly_uploaded_val !== false) {
|
||||
$current_value = $possibly_uploaded_val;
|
||||
$possiblyUploadedVal = $fileToInsert->getContent();
|
||||
if ($possiblyUploadedVal !== false) {
|
||||
$currentValue = $possiblyUploadedVal;
|
||||
}
|
||||
|
||||
// Apply Input Transformation if defined
|
||||
if (
|
||||
! empty($mimeMap[$column_name])
|
||||
&& ! empty($mimeMap[$column_name]['input_transformation'])
|
||||
! empty($mimeMap[$columnName])
|
||||
&& ! empty($mimeMap[$columnName]['input_transformation'])
|
||||
) {
|
||||
$filename = 'libraries/classes/Plugins/Transformations/'
|
||||
. $mimeMap[$column_name]['input_transformation'];
|
||||
. $mimeMap[$columnName]['input_transformation'];
|
||||
if (is_file(ROOT_PATH . $filename)) {
|
||||
$classname = $this->transformations->getClassName($filename);
|
||||
if (class_exists($classname)) {
|
||||
/** @var IOTransformationsPlugin $transformation_plugin */
|
||||
$transformation_plugin = new $classname();
|
||||
$transformation_options = $this->transformations->getOptions(
|
||||
$mimeMap[$column_name]['input_transformation_options'],
|
||||
$className = $this->transformations->getClassName($filename);
|
||||
if (class_exists($className)) {
|
||||
/** @var IOTransformationsPlugin $transformationPlugin */
|
||||
$transformationPlugin = new $className();
|
||||
$transformationOptions = $this->transformations->getOptions(
|
||||
$mimeMap[$columnName]['input_transformation_options'],
|
||||
);
|
||||
$current_value = $transformation_plugin->applyTransformation(
|
||||
$current_value,
|
||||
$transformation_options,
|
||||
$currentValue = $transformationPlugin->applyTransformation(
|
||||
$currentValue,
|
||||
$transformationOptions,
|
||||
);
|
||||
// check if transformation was successful or not
|
||||
// and accordingly set error messages & insert_fail
|
||||
if (
|
||||
method_exists($transformation_plugin, 'isSuccess')
|
||||
&& ! $transformation_plugin->isSuccess()
|
||||
method_exists($transformationPlugin, 'isSuccess')
|
||||
&& ! $transformationPlugin->isSuccess()
|
||||
) {
|
||||
$insert_fail = true;
|
||||
$insertFail = true;
|
||||
$rowSkipped = true;
|
||||
$insertErrors[] = sprintf(
|
||||
__('Row: %1$s, Column: %2$s, Error: %3$s'),
|
||||
$rownumber,
|
||||
$column_name,
|
||||
$transformation_plugin->getError(),
|
||||
$rowNumber,
|
||||
$columnName,
|
||||
$transformationPlugin->getError(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($file_to_insert->isError()) {
|
||||
$insertErrors[] = $file_to_insert->getError();
|
||||
if ($fileToInsert->isError()) {
|
||||
$insertErrors[] = $fileToInsert->getError();
|
||||
}
|
||||
|
||||
// delete $file_to_insert temporary variable
|
||||
$file_to_insert->cleanUp();
|
||||
$fileToInsert->cleanUp();
|
||||
|
||||
$editField = new EditField(
|
||||
$column_name,
|
||||
$current_value,
|
||||
$multi_edit_columns_type[$key] ?? '',
|
||||
isset($multi_edit_auto_increment[$key]),
|
||||
! empty($multi_edit_columns_null[$key]),
|
||||
! empty($multi_edit_columns_null_prev[$key]),
|
||||
$multi_edit_funcs[$key] ?? '',
|
||||
$multi_edit_salt[$key] ?? null,
|
||||
$multi_edit_columns_prev[$key] ?? null,
|
||||
$possibly_uploaded_val !== false,
|
||||
$columnName,
|
||||
$currentValue,
|
||||
$multiEditColumnsType[$key] ?? '',
|
||||
isset($multiEditAutoIncrement[$key]),
|
||||
! empty($multiEditColumnsNull[$key]),
|
||||
! empty($multiEditColumnsNullPrev[$key]),
|
||||
$multiEditFuncs[$key] ?? '',
|
||||
$multiEditSalt[$key] ?? null,
|
||||
$multiEditColumnsPrev[$key] ?? null,
|
||||
$possiblyUploadedVal !== false,
|
||||
);
|
||||
|
||||
if (! isset($multi_edit_virtual[$key])) {
|
||||
if (! isset($multiEditVirtual[$key])) {
|
||||
if ($isInsert) {
|
||||
$queryPart = $this->insertEdit->getQueryValueForInsert(
|
||||
$editField,
|
||||
$usingKey,
|
||||
$where_clause,
|
||||
$whereClause,
|
||||
);
|
||||
if ($queryPart !== '' && $valueSets === []) {
|
||||
// first inserted row so prepare the list of fields
|
||||
@ -256,17 +256,17 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
|
||||
if ($editField->isNull) {
|
||||
$multi_edit_columns[$key] = null;
|
||||
$multiEditColumns[$key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// temporarily store rows not inserted
|
||||
// so that they can be populated again.
|
||||
if ($insert_fail) {
|
||||
$GLOBALS['unsaved_values'][$rownumber] = $multi_edit_columns;
|
||||
if ($insertFail) {
|
||||
$GLOBALS['unsaved_values'][$rowNumber] = $multiEditColumns;
|
||||
}
|
||||
|
||||
if ($insert_fail || $queryValues === []) {
|
||||
if ($insertFail || $queryValues === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -277,24 +277,24 @@ final class ReplaceController extends AbstractController
|
||||
$clauseIsUnique = $_POST['clause_is_unique'] ?? $_GET['clause_is_unique'] ?? '';// Should contain 0 or 1
|
||||
$GLOBALS['query'][] = 'UPDATE ' . Util::backquote($GLOBALS['table'])
|
||||
. ' SET ' . implode(', ', $queryValues)
|
||||
. ' WHERE ' . $where_clause
|
||||
. ' WHERE ' . $whereClause
|
||||
. ($clauseIsUnique ? '' : ' LIMIT 1');
|
||||
}
|
||||
}
|
||||
|
||||
unset(
|
||||
$multi_edit_columns_name,
|
||||
$multi_edit_columns_prev,
|
||||
$multi_edit_funcs,
|
||||
$multi_edit_columns_type,
|
||||
$multi_edit_columns_null,
|
||||
$multi_edit_auto_increment,
|
||||
$multiEditColumnsName,
|
||||
$multiEditColumnsPrev,
|
||||
$multiEditFuncs,
|
||||
$multiEditColumnsType,
|
||||
$multiEditColumnsNull,
|
||||
$multiEditAutoIncrement,
|
||||
$key,
|
||||
$current_value,
|
||||
$where_clause,
|
||||
$multi_edit_columns_null_prev,
|
||||
$insert_fail,
|
||||
$multi_edit_columns,
|
||||
$currentValue,
|
||||
$whereClause,
|
||||
$multiEditColumnsNullPrev,
|
||||
$insertFail,
|
||||
$multiEditColumns,
|
||||
);
|
||||
|
||||
// Builds the sql query
|
||||
@ -404,55 +404,55 @@ final class ReplaceController extends AbstractController
|
||||
if (isset($_POST['rel_fields_list']) && $_POST['rel_fields_list'] != '') {
|
||||
$map = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
/** @var array<int,array> $relation_fields */
|
||||
$relation_fields = [];
|
||||
parse_str($_POST['rel_fields_list'], $relation_fields);
|
||||
/** @var array<int,array> $relationFields */
|
||||
$relationFields = [];
|
||||
parse_str($_POST['rel_fields_list'], $relationFields);
|
||||
|
||||
// loop for each relation cell
|
||||
foreach ($relation_fields as $cell_index => $curr_rel_field) {
|
||||
foreach ($curr_rel_field as $relation_field => $relation_field_value) {
|
||||
$where_comparison = "='" . $relation_field_value . "'";
|
||||
foreach ($relationFields as $cellIndex => $currRelField) {
|
||||
foreach ($currRelField as $relationField => $relationFieldValue) {
|
||||
$whereComparison = "='" . $relationFieldValue . "'";
|
||||
$dispval = $this->insertEdit->getDisplayValueForForeignTableColumn(
|
||||
$where_comparison,
|
||||
$whereComparison,
|
||||
$map,
|
||||
$relation_field,
|
||||
$relationField,
|
||||
);
|
||||
|
||||
$extra_data['relations'][$cell_index] = $this->insertEdit->getLinkForRelationalDisplayField(
|
||||
$extraData['relations'][$cellIndex] = $this->insertEdit->getLinkForRelationalDisplayField(
|
||||
$map,
|
||||
$relation_field,
|
||||
$where_comparison,
|
||||
$relationField,
|
||||
$whereComparison,
|
||||
$dispval,
|
||||
$relation_field_value,
|
||||
$relationFieldValue,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['do_transformations']) && $_POST['do_transformations'] == true) {
|
||||
$edited_values = [];
|
||||
parse_str($_POST['transform_fields_list'], $edited_values);
|
||||
$editedValues = [];
|
||||
parse_str($_POST['transform_fields_list'], $editedValues);
|
||||
|
||||
if (! isset($extra_data)) {
|
||||
$extra_data = [];
|
||||
if (! isset($extraData)) {
|
||||
$extraData = [];
|
||||
}
|
||||
|
||||
$transformation_types = [
|
||||
$transformationTypes = [
|
||||
'input_transformation',
|
||||
'transformation',
|
||||
];
|
||||
foreach ($mimeMap as $transformation) {
|
||||
$column_name = $transformation['column_name'];
|
||||
foreach ($transformation_types as $type) {
|
||||
$columnName = $transformation['column_name'];
|
||||
foreach ($transformationTypes as $type) {
|
||||
$file = Core::securePath($transformation[$type]);
|
||||
$extra_data = $this->insertEdit->transformEditedValues(
|
||||
$extraData = $this->insertEdit->transformEditedValues(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$transformation,
|
||||
$edited_values,
|
||||
$editedValues,
|
||||
$file,
|
||||
$column_name,
|
||||
$extra_data,
|
||||
$columnName,
|
||||
$extraData,
|
||||
$type,
|
||||
);
|
||||
}
|
||||
@ -461,24 +461,24 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
// Need to check the inline edited value can be truncated by MySQL
|
||||
// without informing while saving
|
||||
$column_name = $_POST['fields_name']['multi_edit'][0][0];
|
||||
$columnName = $_POST['fields_name']['multi_edit'][0][0];
|
||||
|
||||
$this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$column_name,
|
||||
$extra_data,
|
||||
$columnName,
|
||||
$extraData,
|
||||
);
|
||||
|
||||
/**Get the total row count of the table*/
|
||||
$_table = new Table($_POST['table'], $_POST['db'], $this->dbi);
|
||||
$extra_data['row_count'] = $_table->countRecords();
|
||||
$tableObj = new Table($_POST['table'], $_POST['db'], $this->dbi);
|
||||
$extraData['row_count'] = $tableObj->countRecords();
|
||||
|
||||
$extra_data['sql_query'] = Generator::getMessage($GLOBALS['message'], $GLOBALS['display_query']);
|
||||
$extraData['sql_query'] = Generator::getMessage($GLOBALS['message'], $GLOBALS['display_query']);
|
||||
|
||||
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
|
||||
$this->response->addJSON('message', $GLOBALS['message']);
|
||||
$this->response->addJSON($extra_data);
|
||||
$this->response->addJSON($extraData);
|
||||
}
|
||||
|
||||
private function moveBackToCallingScript(string $gotoInclude, ServerRequest $request): void
|
||||
|
||||
@ -103,7 +103,7 @@ class SearchController extends AbstractController
|
||||
// Gets the list and number of columns
|
||||
$columns = $this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table'], true);
|
||||
// Get details about the geometry functions
|
||||
$geom_types = Gis::getDataTypes();
|
||||
$geomTypes = Gis::getDataTypes();
|
||||
|
||||
foreach ($columns as $row) {
|
||||
// set column name
|
||||
@ -113,7 +113,7 @@ class SearchController extends AbstractController
|
||||
// before any replacement
|
||||
$this->originalColumnTypes[] = mb_strtolower($type);
|
||||
// check whether table contains geometric columns
|
||||
if (in_array($type, $geom_types)) {
|
||||
if (in_array($type, $geomTypes)) {
|
||||
$this->geomColumnFlag = true;
|
||||
}
|
||||
|
||||
@ -194,26 +194,26 @@ class SearchController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$extra_data = [];
|
||||
$row_info_query = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
|
||||
$extraData = [];
|
||||
$rowInfoQuery = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
|
||||
. Util::backquote($_POST['table']) . ' WHERE ' . $_POST['where_clause'];
|
||||
$result = $this->dbi->query($row_info_query . ';');
|
||||
$fields_meta = $this->dbi->getFieldsMeta($result);
|
||||
$result = $this->dbi->query($rowInfoQuery . ';');
|
||||
$fieldsMeta = $this->dbi->getFieldsMeta($result);
|
||||
while ($row = $result->fetchAssoc()) {
|
||||
// for bit fields we need to convert them to printable form
|
||||
$i = 0;
|
||||
foreach ($row as $col => $val) {
|
||||
if (isset($fields_meta[$i]) && $fields_meta[$i]->isMappedTypeBit) {
|
||||
$row[$col] = Util::printableBitValue((int) $val, $fields_meta[$i]->length);
|
||||
if (isset($fieldsMeta[$i]) && $fieldsMeta[$i]->isMappedTypeBit) {
|
||||
$row[$col] = Util::printableBitValue((int) $val, $fieldsMeta[$i]->length);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$extra_data['row_info'] = $row;
|
||||
$extraData['row_info'] = $row;
|
||||
}
|
||||
|
||||
$this->response->addJSON($extra_data);
|
||||
$this->response->addJSON($extraData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,7 +224,7 @@ class SearchController extends AbstractController
|
||||
/**
|
||||
* Selection criteria have been submitted -> do the work
|
||||
*/
|
||||
$sql_query = $this->search->buildSqlQuery();
|
||||
$sqlQuery = $this->search->buildSqlQuery();
|
||||
|
||||
/**
|
||||
* Add this to ensure following procedures included running correctly.
|
||||
@ -251,7 +251,7 @@ class SearchController extends AbstractController
|
||||
$GLOBALS['goto'], // goto
|
||||
null, // disp_query
|
||||
null, // disp_message
|
||||
$sql_query, // sql_query
|
||||
$sqlQuery, // sql_query
|
||||
null, // complete_query
|
||||
));
|
||||
}
|
||||
@ -284,8 +284,8 @@ class SearchController extends AbstractController
|
||||
*/
|
||||
public function rangeSearchAction(): void
|
||||
{
|
||||
$min_max = $this->getColumnMinMax($_POST['column']);
|
||||
$this->response->addJSON('column_data', $min_max);
|
||||
$minMax = $this->getColumnMinMax($_POST['column']);
|
||||
$this->response->addJSON('column_data', $minMax);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,45 +295,45 @@ class SearchController extends AbstractController
|
||||
*/
|
||||
public function getColumnMinMax(string $column): array|null
|
||||
{
|
||||
$sql_query = 'SELECT MIN(' . Util::backquote($column) . ') AS `min`, '
|
||||
$sqlQuery = 'SELECT MIN(' . Util::backquote($column) . ') AS `min`, '
|
||||
. 'MAX(' . Util::backquote($column) . ') AS `max` '
|
||||
. 'FROM ' . Util::backquote($GLOBALS['db']) . '.'
|
||||
. Util::backquote($GLOBALS['table']);
|
||||
|
||||
return $this->dbi->fetchSingleRow($sql_query);
|
||||
return $this->dbi->fetchSingleRow($sqlQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a column's type, collation, operators list, and criteria value
|
||||
* to display in table search form
|
||||
*
|
||||
* @param int $search_index Row number in table search form
|
||||
* @param int $column_index Column index in ColumnNames array
|
||||
* @param int $searchIndex Row number in table search form
|
||||
* @param int $columnIndex Column index in ColumnNames array
|
||||
*
|
||||
* @return array Array containing column's properties
|
||||
*/
|
||||
public function getColumnProperties(int $search_index, int $column_index): array
|
||||
public function getColumnProperties(int $searchIndex, int $columnIndex): array
|
||||
{
|
||||
$selected_operator = ($_POST['criteriaColumnOperators'][$search_index] ?? '');
|
||||
$entered_value = ($_POST['criteriaValues'] ?? '');
|
||||
$selectedOperator = ($_POST['criteriaColumnOperators'][$searchIndex] ?? '');
|
||||
$enteredValue = ($_POST['criteriaValues'] ?? '');
|
||||
//Gets column's type and collation
|
||||
$type = $this->columnTypes[$column_index];
|
||||
$collation = $this->columnCollations[$column_index];
|
||||
$type = $this->columnTypes[$columnIndex];
|
||||
$collation = $this->columnCollations[$columnIndex];
|
||||
$cleanType = preg_replace('@\(.*@s', '', $type);
|
||||
//Gets column's comparison operators depending on column type
|
||||
$typeOperators = $this->dbi->types->getTypeOperatorsHtml(
|
||||
$cleanType,
|
||||
$this->columnNullFlags[$column_index],
|
||||
$selected_operator,
|
||||
$this->columnNullFlags[$columnIndex],
|
||||
$selectedOperator,
|
||||
);
|
||||
$func = $this->template->render('table/search/column_comparison_operators', [
|
||||
'search_index' => $search_index,
|
||||
'search_index' => $searchIndex,
|
||||
'type_operators' => $typeOperators,
|
||||
]);
|
||||
//Gets link to browse foreign data(if any) and criteria inputbox
|
||||
$foreignData = $this->relation->getForeignData(
|
||||
$this->foreigners,
|
||||
$this->columnNames[$column_index],
|
||||
$this->columnNames[$columnIndex],
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
@ -342,21 +342,21 @@ class SearchController extends AbstractController
|
||||
$isInteger = in_array($cleanType, $this->dbi->types->getIntegerTypes());
|
||||
$isFloat = in_array($cleanType, $this->dbi->types->getFloatTypes());
|
||||
if ($isInteger) {
|
||||
$extractedColumnspec = Util::extractColumnSpec($this->originalColumnTypes[$column_index]);
|
||||
$is_unsigned = $extractedColumnspec['unsigned'];
|
||||
$minMaxValues = $this->dbi->types->getIntegerRange($cleanType, ! $is_unsigned);
|
||||
$extractedColumnspec = Util::extractColumnSpec($this->originalColumnTypes[$columnIndex]);
|
||||
$isUnsigned = $extractedColumnspec['unsigned'];
|
||||
$minMaxValues = $this->dbi->types->getIntegerRange($cleanType, ! $isUnsigned);
|
||||
$htmlAttributes = 'data-min="' . $minMaxValues[0] . '" '
|
||||
. 'data-max="' . $minMaxValues[1] . '"';
|
||||
}
|
||||
|
||||
$htmlAttributes .= ' onfocus="return '
|
||||
. 'verifyAfterSearchFieldChange(' . $search_index . ', \'#tbl_search_form\')"';
|
||||
. 'verifyAfterSearchFieldChange(' . $searchIndex . ', \'#tbl_search_form\')"';
|
||||
|
||||
$foreignDropdown = '';
|
||||
|
||||
$searchColumnInForeigners = $this->relation->searchColumnInForeigners(
|
||||
$this->foreigners,
|
||||
$this->columnNames[$column_index],
|
||||
$this->columnNames[$columnIndex],
|
||||
);
|
||||
|
||||
if (
|
||||
@ -381,12 +381,12 @@ class SearchController extends AbstractController
|
||||
'column_id' => 'fieldID_',
|
||||
'in_zoom_search_edit' => false,
|
||||
'foreigners' => $this->foreigners,
|
||||
'column_name' => $this->columnNames[$column_index],
|
||||
'column_name_hash' => md5($this->columnNames[$column_index]),
|
||||
'column_name' => $this->columnNames[$columnIndex],
|
||||
'column_name_hash' => md5($this->columnNames[$columnIndex]),
|
||||
'foreign_data' => $foreignData,
|
||||
'table' => $GLOBALS['table'],
|
||||
'column_index' => $search_index,
|
||||
'criteria_values' => $entered_value,
|
||||
'column_index' => $searchIndex,
|
||||
'criteria_values' => $enteredValue,
|
||||
'db' => $GLOBALS['db'],
|
||||
'in_fbs' => true,
|
||||
'foreign_dropdown' => $foreignDropdown,
|
||||
|
||||
@ -43,9 +43,9 @@ final class SqlController extends AbstractController
|
||||
|
||||
$this->checkParameters(['db', 'table']);
|
||||
|
||||
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$urlParams = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($urlParams, '&');
|
||||
|
||||
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ final class BrowseController extends AbstractController
|
||||
$fields[] = Util::backquote($sval);
|
||||
}
|
||||
|
||||
$sql_query = sprintf(
|
||||
$sqlQuery = sprintf(
|
||||
'SELECT %s FROM %s.%s',
|
||||
implode(', ', $fields),
|
||||
Util::backquote($GLOBALS['db']),
|
||||
@ -57,7 +57,7 @@ final class BrowseController extends AbstractController
|
||||
);
|
||||
|
||||
// Parse and analyze the query
|
||||
[$statementInfo, $GLOBALS['db']] = ParseAnalyze::sqlQuery($sql_query, $GLOBALS['db']);
|
||||
[$statementInfo, $GLOBALS['db']] = ParseAnalyze::sqlQuery($sqlQuery, $GLOBALS['db']);
|
||||
|
||||
$this->response->addHTML(
|
||||
$this->sql->executeQueryAndGetQueryResponse(
|
||||
@ -73,7 +73,7 @@ final class BrowseController extends AbstractController
|
||||
$goto, // goto
|
||||
null, // disp_query
|
||||
null, // disp_message
|
||||
$sql_query, // sql_query
|
||||
$sqlQuery, // sql_query
|
||||
null, // complete_query
|
||||
),
|
||||
);
|
||||
|
||||
@ -58,7 +58,7 @@ final class ChangeController extends AbstractController
|
||||
$GLOBALS['num_fields'] ??= null;
|
||||
|
||||
/** @todo optimize in case of multiple fields to modify */
|
||||
$fields_meta = [];
|
||||
$fieldsMeta = [];
|
||||
foreach ($selected as $column) {
|
||||
$value = $this->dbi->getColumn($GLOBALS['db'], $GLOBALS['table'], $column, true);
|
||||
if ($value === []) {
|
||||
@ -68,11 +68,11 @@ final class ChangeController extends AbstractController
|
||||
$message->addParam($column);
|
||||
$this->response->addHTML($message->getDisplay());
|
||||
} else {
|
||||
$fields_meta[] = $value;
|
||||
$fieldsMeta[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['num_fields'] = count($fields_meta);
|
||||
$GLOBALS['num_fields'] = count($fieldsMeta);
|
||||
|
||||
/**
|
||||
* Form for changing properties.
|
||||
@ -89,7 +89,7 @@ final class ChangeController extends AbstractController
|
||||
$GLOBALS['num_fields'],
|
||||
null,
|
||||
$selected,
|
||||
$fields_meta,
|
||||
$fieldsMeta,
|
||||
);
|
||||
|
||||
$this->render('columns_definitions/column_definitions_form', $templateData);
|
||||
|
||||
@ -40,8 +40,8 @@ final class MoveColumnsController extends AbstractController
|
||||
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$move_columns = $request->getParsedBodyParam('move_columns');
|
||||
if (! is_array($move_columns) || ! $this->response->isAjax()) {
|
||||
$moveColumns = $request->getParsedBodyParam('move_columns');
|
||||
if (! is_array($moveColumns) || ! $this->response->isAjax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -51,31 +51,31 @@ final class MoveColumnsController extends AbstractController
|
||||
* load the definitions for all columns
|
||||
*/
|
||||
$columns = $this->dbi->getColumnsFull($GLOBALS['db'], $GLOBALS['table']);
|
||||
$column_names = array_column($columns, 'Field');
|
||||
$columnNames = array_column($columns, 'Field');
|
||||
$changes = [];
|
||||
|
||||
// @see https://mariadb.com/kb/en/library/changes-improvements-in-mariadb-102/#information-schema
|
||||
$usesLiteralNull = $this->dbi->isMariaDB() && $this->dbi->getVersion() >= 100200;
|
||||
$defaultNullValue = $usesLiteralNull ? 'NULL' : null;
|
||||
// move columns from first to last
|
||||
for ($i = 0, $l = count($move_columns); $i < $l; $i++) {
|
||||
$column = $move_columns[$i];
|
||||
for ($i = 0, $l = count($moveColumns); $i < $l; $i++) {
|
||||
$column = $moveColumns[$i];
|
||||
// is this column already correctly placed?
|
||||
if ($column_names[$i] == $column) {
|
||||
if ($columnNames[$i] == $column) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// it is not, let's move it to index $i
|
||||
$data = $columns[$column];
|
||||
$extracted_columnspec = Util::extractColumnSpec($data['Type']);
|
||||
$extractedColumnSpec = Util::extractColumnSpec($data['Type']);
|
||||
if (isset($data['Extra']) && $data['Extra'] === 'on update CURRENT_TIMESTAMP') {
|
||||
$extracted_columnspec['attribute'] = $data['Extra'];
|
||||
$extractedColumnSpec['attribute'] = $data['Extra'];
|
||||
unset($data['Extra']);
|
||||
}
|
||||
|
||||
$timeType = $data['Type'] === 'timestamp' || $data['Type'] === 'datetime';
|
||||
$timeDefault = $data['Default'] === 'CURRENT_TIMESTAMP' || $data['Default'] === 'current_timestamp()';
|
||||
$current_timestamp = $timeType && $timeDefault;
|
||||
$currentTimestamp = $timeType && $timeDefault;
|
||||
|
||||
$uuidType = $data['Type'] === 'uuid';
|
||||
$uuidDefault = $data['Default'] === 'UUID' || $data['Default'] === 'uuid()';
|
||||
@ -83,15 +83,15 @@ final class MoveColumnsController extends AbstractController
|
||||
|
||||
// @see https://mariadb.com/kb/en/library/information-schema-columns-table/#examples
|
||||
if ($data['Null'] === 'YES' && in_array($data['Default'], [$defaultNullValue, null])) {
|
||||
$default_type = 'NULL';
|
||||
} elseif ($current_timestamp) {
|
||||
$default_type = 'CURRENT_TIMESTAMP';
|
||||
$defaultType = 'NULL';
|
||||
} elseif ($currentTimestamp) {
|
||||
$defaultType = 'CURRENT_TIMESTAMP';
|
||||
} elseif ($uuid) {
|
||||
$default_type = 'UUID';
|
||||
$defaultType = 'UUID';
|
||||
} elseif ($data['Default'] === null) {
|
||||
$default_type = 'NONE';
|
||||
$defaultType = 'NONE';
|
||||
} else {
|
||||
$default_type = 'USER_DEFINED';
|
||||
$defaultType = 'USER_DEFINED';
|
||||
}
|
||||
|
||||
$virtual = [
|
||||
@ -111,31 +111,31 @@ final class MoveColumnsController extends AbstractController
|
||||
$changes[] = 'CHANGE ' . Table::generateAlter(
|
||||
$column,
|
||||
$column,
|
||||
mb_strtoupper($extracted_columnspec['type']),
|
||||
$extracted_columnspec['spec_in_brackets'],
|
||||
$extracted_columnspec['attribute'],
|
||||
mb_strtoupper($extractedColumnSpec['type']),
|
||||
$extractedColumnSpec['spec_in_brackets'],
|
||||
$extractedColumnSpec['attribute'],
|
||||
$data['Collation'] ?? '',
|
||||
$data['Null'] === 'YES' ? 'YES' : 'NO',
|
||||
$default_type,
|
||||
$current_timestamp ? '' : $data['Default'],
|
||||
$defaultType,
|
||||
$currentTimestamp ? '' : $data['Default'],
|
||||
$data['Extra'] ?? '',
|
||||
isset($data['COLUMN_COMMENT']) && $data['COLUMN_COMMENT'] !== ''
|
||||
? $data['COLUMN_COMMENT'] : false,
|
||||
$data['Virtuality'],
|
||||
$data['Expression'],
|
||||
$i === 0 ? '-first' : $column_names[$i - 1],
|
||||
$i === 0 ? '-first' : $columnNames[$i - 1],
|
||||
);
|
||||
// update current column_names array, first delete old position
|
||||
for ($j = 0, $ll = count($column_names); $j < $ll; $j++) {
|
||||
if ($column_names[$j] != $column) {
|
||||
for ($j = 0, $ll = count($columnNames); $j < $ll; $j++) {
|
||||
if ($columnNames[$j] != $column) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($column_names[$j]);
|
||||
unset($columnNames[$j]);
|
||||
}
|
||||
|
||||
// insert moved column
|
||||
array_splice($column_names, $i, 0, $column);
|
||||
array_splice($columnNames, $i, 0, $column);
|
||||
}
|
||||
|
||||
if (empty($changes) && ! isset($_REQUEST['preview_sql'])) { // should never happen
|
||||
@ -145,7 +145,7 @@ final class MoveColumnsController extends AbstractController
|
||||
}
|
||||
|
||||
// query for moving the columns
|
||||
$sql_query = sprintf(
|
||||
$sqlQuery = sprintf(
|
||||
'ALTER TABLE %s %s',
|
||||
Util::backquote($GLOBALS['table']),
|
||||
implode(', ', $changes),
|
||||
@ -154,17 +154,17 @@ final class MoveColumnsController extends AbstractController
|
||||
if (isset($_REQUEST['preview_sql'])) { // preview sql
|
||||
$this->response->addJSON(
|
||||
'sql_data',
|
||||
$this->template->render('preview_sql', ['query_data' => $sql_query]),
|
||||
$this->template->render('preview_sql', ['query_data' => $sqlQuery]),
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dbi->tryQuery($sql_query);
|
||||
$tmp_error = $this->dbi->getError();
|
||||
if ($tmp_error !== '') {
|
||||
$this->dbi->tryQuery($sqlQuery);
|
||||
$tmpError = $this->dbi->getError();
|
||||
if ($tmpError !== '') {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', Message::error($tmp_error));
|
||||
$this->response->addJSON('message', Message::error($tmpError));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -173,6 +173,6 @@ final class MoveColumnsController extends AbstractController
|
||||
__('The columns have been moved successfully.'),
|
||||
);
|
||||
$this->response->addJSON('message', $message);
|
||||
$this->response->addJSON('columns', $column_names);
|
||||
$this->response->addJSON('columns', $columnNames);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,11 +241,11 @@ final class PartitioningController extends AbstractController
|
||||
|
||||
private function updatePartitioning(): void
|
||||
{
|
||||
$sql_query = 'ALTER TABLE ' . Util::backquote($GLOBALS['table']) . ' '
|
||||
$sqlQuery = 'ALTER TABLE ' . Util::backquote($GLOBALS['table']) . ' '
|
||||
. $this->createAddField->getPartitionsDefinition();
|
||||
|
||||
// Execute alter query
|
||||
$result = $this->dbi->tryQuery($sql_query);
|
||||
$result = $this->dbi->tryQuery($sqlQuery);
|
||||
|
||||
if ($result === false) {
|
||||
$this->response->setRequestStatus(false);
|
||||
@ -264,7 +264,7 @@ final class PartitioningController extends AbstractController
|
||||
);
|
||||
$message->addParam($GLOBALS['table']);
|
||||
$this->response->addHTML(
|
||||
Generator::getMessage($message, $sql_query, 'success'),
|
||||
Generator::getMessage($message, $sqlQuery, 'success'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,21 +24,21 @@ final class ReservedWordCheckController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$columns_names = $request->getParsedBodyParam('field_name');
|
||||
$reserved_keywords_names = [];
|
||||
foreach ($columns_names as $column) {
|
||||
$columnsNames = $request->getParsedBodyParam('field_name');
|
||||
$reservedKeywordsNames = [];
|
||||
foreach ($columnsNames as $column) {
|
||||
if (! Context::isKeyword(trim($column), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$reserved_keywords_names[] = trim($column);
|
||||
$reservedKeywordsNames[] = trim($column);
|
||||
}
|
||||
|
||||
if (Context::isKeyword(trim($GLOBALS['table']), true)) {
|
||||
$reserved_keywords_names[] = trim($GLOBALS['table']);
|
||||
$reservedKeywordsNames[] = trim($GLOBALS['table']);
|
||||
}
|
||||
|
||||
if (count($reserved_keywords_names) === 0) {
|
||||
if (count($reservedKeywordsNames) === 0) {
|
||||
$this->response->setRequestStatus(false);
|
||||
}
|
||||
|
||||
@ -48,9 +48,9 @@ final class ReservedWordCheckController extends AbstractController
|
||||
_ngettext(
|
||||
'The name \'%s\' is a MySQL reserved keyword.',
|
||||
'The names \'%s\' are MySQL reserved keywords.',
|
||||
count($reserved_keywords_names),
|
||||
count($reservedKeywordsNames),
|
||||
),
|
||||
implode(',', $reserved_keywords_names),
|
||||
implode(',', $reservedKeywordsNames),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -64,18 +64,18 @@ final class SaveController extends AbstractController
|
||||
*/
|
||||
private function updateColumns(): bool
|
||||
{
|
||||
$err_url = Url::getFromRoute('/table/structure', [
|
||||
$errUrl = Url::getFromRoute('/table/structure', [
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table'],
|
||||
]);
|
||||
$regenerate = false;
|
||||
$field_cnt = count($_POST['field_name'] ?? []);
|
||||
$fieldCnt = count($_POST['field_name'] ?? []);
|
||||
$changes = [];
|
||||
$adjust_privileges = [];
|
||||
$columns_with_index = $this->dbi
|
||||
$adjustPrivileges = [];
|
||||
$columnsWithIndex = $this->dbi
|
||||
->getTable($GLOBALS['db'], $GLOBALS['table'])
|
||||
->getColumnsWithIndex(Index::PRIMARY | Index::UNIQUE);
|
||||
for ($i = 0; $i < $field_cnt; $i++) {
|
||||
for ($i = 0; $i < $fieldCnt; $i++) {
|
||||
if (! $this->columnNeedsAlterTable($i)) {
|
||||
continue;
|
||||
}
|
||||
@ -95,13 +95,13 @@ final class SaveController extends AbstractController
|
||||
Util::getValueByKey($_POST, 'field_virtuality.' . $i, ''),
|
||||
Util::getValueByKey($_POST, 'field_expression.' . $i, ''),
|
||||
Util::getValueByKey($_POST, 'field_move_to.' . $i, ''),
|
||||
$columns_with_index,
|
||||
$columnsWithIndex,
|
||||
);
|
||||
|
||||
// find the remembered sort expression
|
||||
$sorted_col = $this->tableObj->getUiProp(Table::PROP_SORTED_COLUMN);
|
||||
$sortedCol = $this->tableObj->getUiProp(Table::PROP_SORTED_COLUMN);
|
||||
// if the old column name is part of the remembered sort expression
|
||||
if (mb_strpos((string) $sorted_col, Util::backquote($_POST['field_orig'][$i])) !== false) {
|
||||
if (mb_strpos((string) $sortedCol, Util::backquote($_POST['field_orig'][$i])) !== false) {
|
||||
// delete the whole remembered sort expression
|
||||
$this->tableObj->removeUiProp(Table::PROP_SORTED_COLUMN);
|
||||
}
|
||||
@ -113,12 +113,12 @@ final class SaveController extends AbstractController
|
||||
continue;
|
||||
}
|
||||
|
||||
$adjust_privileges[$_POST['field_orig'][$i]] = $_POST['field_name'][$i];
|
||||
$adjustPrivileges[$_POST['field_orig'][$i]] = $_POST['field_name'][$i];
|
||||
}
|
||||
|
||||
if (count($changes) > 0 || isset($_POST['preview_sql'])) {
|
||||
// Builds the primary keys statements and updates the table
|
||||
$key_query = '';
|
||||
$keyQuery = '';
|
||||
/**
|
||||
* this is a little bit more complex
|
||||
*
|
||||
@ -134,53 +134,53 @@ final class SaveController extends AbstractController
|
||||
$this->dbi->getError(),
|
||||
'USE ' . Util::backquote($GLOBALS['db']) . ';',
|
||||
false,
|
||||
$err_url,
|
||||
$errUrl,
|
||||
);
|
||||
}
|
||||
|
||||
$sql_query = 'ALTER TABLE ' . Util::backquote($GLOBALS['table']) . ' ';
|
||||
$sql_query .= implode(', ', $changes) . $key_query;
|
||||
$sqlQuery = 'ALTER TABLE ' . Util::backquote($GLOBALS['table']) . ' ';
|
||||
$sqlQuery .= implode(', ', $changes) . $keyQuery;
|
||||
if (isset($_POST['online_transaction'])) {
|
||||
$sql_query .= ', ALGORITHM=INPLACE, LOCK=NONE';
|
||||
$sqlQuery .= ', ALGORITHM=INPLACE, LOCK=NONE';
|
||||
}
|
||||
|
||||
$sql_query .= ';';
|
||||
$sqlQuery .= ';';
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_POST['preview_sql'])) {
|
||||
Core::previewSQL(count($changes) > 0 ? $sql_query : '');
|
||||
Core::previewSQL(count($changes) > 0 ? $sqlQuery : '');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$columns_with_index = $this->dbi
|
||||
$columnsWithIndex = $this->dbi
|
||||
->getTable($GLOBALS['db'], $GLOBALS['table'])
|
||||
->getColumnsWithIndex(Index::PRIMARY | Index::UNIQUE | Index::INDEX | Index::SPATIAL | Index::FULLTEXT);
|
||||
|
||||
$changedToBlob = [];
|
||||
// While changing the Column Collation
|
||||
// First change to BLOB
|
||||
for ($i = 0; $i < $field_cnt; $i++) {
|
||||
for ($i = 0; $i < $fieldCnt; $i++) {
|
||||
if (
|
||||
isset($_POST['field_collation'][$i], $_POST['field_collation_orig'][$i])
|
||||
&& $_POST['field_collation'][$i] !== $_POST['field_collation_orig'][$i]
|
||||
&& ! in_array($_POST['field_orig'][$i], $columns_with_index)
|
||||
&& ! in_array($_POST['field_orig'][$i], $columnsWithIndex)
|
||||
) {
|
||||
$secondary_query = 'ALTER TABLE ' . Util::backquote($GLOBALS['table'])
|
||||
$secondaryQuery = 'ALTER TABLE ' . Util::backquote($GLOBALS['table'])
|
||||
. ' CHANGE ' . Util::backquote($_POST['field_orig'][$i])
|
||||
. ' ' . Util::backquote($_POST['field_orig'][$i])
|
||||
. ' BLOB';
|
||||
|
||||
if (isset($_POST['field_virtuality'][$i], $_POST['field_expression'][$i])) {
|
||||
if ($_POST['field_virtuality'][$i]) {
|
||||
$secondary_query .= ' AS (' . $_POST['field_expression'][$i] . ') '
|
||||
$secondaryQuery .= ' AS (' . $_POST['field_expression'][$i] . ') '
|
||||
. $_POST['field_virtuality'][$i];
|
||||
}
|
||||
}
|
||||
|
||||
$secondary_query .= ';';
|
||||
$secondaryQuery .= ';';
|
||||
|
||||
$this->dbi->query($secondary_query);
|
||||
$this->dbi->query($secondaryQuery);
|
||||
$changedToBlob[$i] = true;
|
||||
} else {
|
||||
$changedToBlob[$i] = false;
|
||||
@ -188,12 +188,12 @@ final class SaveController extends AbstractController
|
||||
}
|
||||
|
||||
// Then make the requested changes
|
||||
$result = $this->dbi->tryQuery($sql_query);
|
||||
$result = $this->dbi->tryQuery($sqlQuery);
|
||||
|
||||
if ($result !== false) {
|
||||
$changed_privileges = $this->adjustColumnPrivileges($adjust_privileges);
|
||||
$changedPrivileges = $this->adjustColumnPrivileges($adjustPrivileges);
|
||||
|
||||
if ($changed_privileges) {
|
||||
if ($changedPrivileges) {
|
||||
$message = Message::success(
|
||||
__(
|
||||
'Table %1$s has been altered successfully. Privileges have been adjusted.',
|
||||
@ -208,22 +208,22 @@ final class SaveController extends AbstractController
|
||||
$message->addParam($GLOBALS['table']);
|
||||
|
||||
$this->response->addHTML(
|
||||
Generator::getMessage($message, $sql_query, 'success'),
|
||||
Generator::getMessage($message, $sqlQuery, 'success'),
|
||||
);
|
||||
} else {
|
||||
// An error happened while inserting/updating a table definition
|
||||
|
||||
// Save the Original Error
|
||||
$orig_error = $this->dbi->getError();
|
||||
$changes_revert = [];
|
||||
$origError = $this->dbi->getError();
|
||||
$changesRevert = [];
|
||||
|
||||
// Change back to Original Collation and data type
|
||||
for ($i = 0; $i < $field_cnt; $i++) {
|
||||
for ($i = 0; $i < $fieldCnt; $i++) {
|
||||
if (! $changedToBlob[$i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$changes_revert[] = 'CHANGE ' . Table::generateAlter(
|
||||
$changesRevert[] = 'CHANGE ' . Table::generateAlter(
|
||||
Util::getValueByKey($_POST, 'field_orig.' . $i, ''),
|
||||
$_POST['field_name'][$i],
|
||||
$_POST['field_type_orig'][$i],
|
||||
@ -241,20 +241,20 @@ final class SaveController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
$revert_query = 'ALTER TABLE ' . Util::backquote($GLOBALS['table'])
|
||||
$revertQuery = 'ALTER TABLE ' . Util::backquote($GLOBALS['table'])
|
||||
. ' ';
|
||||
$revert_query .= implode(', ', $changes_revert);
|
||||
$revert_query .= ';';
|
||||
$revertQuery .= implode(', ', $changesRevert);
|
||||
$revertQuery .= ';';
|
||||
|
||||
// Column reverted back to original
|
||||
$this->dbi->query($revert_query);
|
||||
$this->dbi->query($revertQuery);
|
||||
|
||||
$this->response->setRequestStatus(false);
|
||||
$message = Message::rawError(
|
||||
__('Query error') . ':<br>' . $orig_error,
|
||||
__('Query error') . ':<br>' . $origError,
|
||||
);
|
||||
$this->response->addHTML(
|
||||
Generator::getMessage($message, $sql_query, 'error'),
|
||||
Generator::getMessage($message, $sqlQuery, 'error'),
|
||||
);
|
||||
$regenerate = true;
|
||||
}
|
||||
@ -344,10 +344,10 @@ final class SaveController extends AbstractController
|
||||
/**
|
||||
* Adjusts the Privileges for all the columns whose names have changed
|
||||
*
|
||||
* @param array $adjust_privileges assoc array of old col names mapped to new
|
||||
* @param array $adjustPrivileges assoc array of old col names mapped to new
|
||||
* cols
|
||||
*/
|
||||
private function adjustColumnPrivileges(array $adjust_privileges): bool
|
||||
private function adjustColumnPrivileges(array $adjustPrivileges): bool
|
||||
{
|
||||
$changed = false;
|
||||
|
||||
@ -355,7 +355,7 @@ final class SaveController extends AbstractController
|
||||
$this->dbi->selectDb('mysql');
|
||||
|
||||
// For Column specific privileges
|
||||
foreach ($adjust_privileges as $oldCol => $newCol) {
|
||||
foreach ($adjustPrivileges as $oldCol => $newCol) {
|
||||
$this->dbi->query(
|
||||
sprintf(
|
||||
'UPDATE %s SET Column_name = "%s"
|
||||
|
||||
@ -98,17 +98,17 @@ class StructureController extends AbstractController
|
||||
$this->checkParameters(['db', 'table']);
|
||||
|
||||
$isSystemSchema = Utilities::isSystemSchema($GLOBALS['db']);
|
||||
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$urlParams = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
|
||||
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
|
||||
$GLOBALS['errorUrl'] .= Url::getCommon($urlParams, '&');
|
||||
|
||||
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
$primary = Index::getPrimary($this->dbi, $GLOBALS['table'], $GLOBALS['db']);
|
||||
$columns_with_index = $this->dbi
|
||||
$columnsWithIndex = $this->dbi
|
||||
->getTable($GLOBALS['db'], $GLOBALS['table'])
|
||||
->getColumnsWithIndex(Index::UNIQUE | Index::INDEX | Index::SPATIAL | Index::FULLTEXT);
|
||||
$columns_with_unique_index = $this->dbi
|
||||
$columnsWithUniqueIndex = $this->dbi
|
||||
->getTable($GLOBALS['db'], $GLOBALS['table'])
|
||||
->getColumnsWithIndex(Index::UNIQUE);
|
||||
|
||||
@ -116,10 +116,10 @@ class StructureController extends AbstractController
|
||||
|
||||
$this->response->addHTML($this->displayStructure(
|
||||
$relationParameters,
|
||||
$columns_with_unique_index,
|
||||
$columnsWithUniqueIndex,
|
||||
$primary,
|
||||
$fields,
|
||||
$columns_with_index,
|
||||
$columnsWithIndex,
|
||||
$isSystemSchema,
|
||||
$request->getRoute(),
|
||||
));
|
||||
@ -128,17 +128,17 @@ class StructureController extends AbstractController
|
||||
/**
|
||||
* Displays the table structure ('show table' works correct since 3.23.03)
|
||||
*
|
||||
* @param array $columns_with_unique_index Columns with unique index
|
||||
* @param array $fields Fields
|
||||
* @param array $columns_with_index Columns with index
|
||||
* @param array $columnsWithUniqueIndex Columns with unique index
|
||||
* @param array $fields Fields
|
||||
* @param array $columnsWithIndex Columns with index
|
||||
* @psalm-param non-empty-string $route
|
||||
*/
|
||||
protected function displayStructure(
|
||||
RelationParameters $relationParameters,
|
||||
array $columns_with_unique_index,
|
||||
array $columnsWithUniqueIndex,
|
||||
Index|null $primaryIndex,
|
||||
array $fields,
|
||||
array $columns_with_index,
|
||||
array $columnsWithIndex,
|
||||
bool $isSystemSchema,
|
||||
string $route,
|
||||
): string {
|
||||
@ -146,18 +146,18 @@ class StructureController extends AbstractController
|
||||
$GLOBALS['tbl_storage_engine'] ??= null;
|
||||
|
||||
// prepare comments
|
||||
$comments_map = [];
|
||||
$mime_map = [];
|
||||
$commentsMap = [];
|
||||
$mimeMap = [];
|
||||
|
||||
if ($GLOBALS['cfg']['ShowPropertyComments']) {
|
||||
$comments_map = $this->relation->getComments($GLOBALS['db'], $GLOBALS['table']);
|
||||
$commentsMap = $this->relation->getComments($GLOBALS['db'], $GLOBALS['table']);
|
||||
if ($relationParameters->browserTransformationFeature !== null && $GLOBALS['cfg']['BrowseMIME']) {
|
||||
$mime_map = $this->transformations->getMime($GLOBALS['db'], $GLOBALS['table'], true);
|
||||
$mimeMap = $this->transformations->getMime($GLOBALS['db'], $GLOBALS['table'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$centralColumns = new CentralColumns($this->dbi);
|
||||
$central_list = $centralColumns->getFromTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
$centralList = $centralColumns->getFromTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
/**
|
||||
* Displays Space usage and row statistics
|
||||
@ -175,38 +175,38 @@ class StructureController extends AbstractController
|
||||
|
||||
// logic removed from Template
|
||||
$rownum = 0;
|
||||
$columns_list = [];
|
||||
$columnsList = [];
|
||||
$attributes = [];
|
||||
$displayed_fields = [];
|
||||
$row_comments = [];
|
||||
$extracted_columnspecs = [];
|
||||
$displayedFields = [];
|
||||
$rowComments = [];
|
||||
$extractedColumnSpecs = [];
|
||||
$collations = [];
|
||||
foreach ($fields as $field) {
|
||||
++$rownum;
|
||||
$columns_list[] = $field['Field'];
|
||||
$columnsList[] = $field['Field'];
|
||||
|
||||
$extracted_columnspecs[$rownum] = Util::extractColumnSpec($field['Type']);
|
||||
$attributes[$rownum] = $extracted_columnspecs[$rownum]['attribute'];
|
||||
$extractedColumnSpecs[$rownum] = Util::extractColumnSpec($field['Type']);
|
||||
$attributes[$rownum] = $extractedColumnSpecs[$rownum]['attribute'];
|
||||
if (str_contains($field['Extra'], 'on update CURRENT_TIMESTAMP')) {
|
||||
$attributes[$rownum] = 'on update CURRENT_TIMESTAMP';
|
||||
}
|
||||
|
||||
$displayed_fields[$rownum] = new stdClass();
|
||||
$displayed_fields[$rownum]->text = $field['Field'];
|
||||
$displayed_fields[$rownum]->icon = '';
|
||||
$row_comments[$rownum] = '';
|
||||
$displayedFields[$rownum] = new stdClass();
|
||||
$displayedFields[$rownum]->text = $field['Field'];
|
||||
$displayedFields[$rownum]->icon = '';
|
||||
$rowComments[$rownum] = '';
|
||||
|
||||
if (isset($comments_map[$field['Field']])) {
|
||||
$displayed_fields[$rownum]->comment = $comments_map[$field['Field']];
|
||||
$row_comments[$rownum] = $comments_map[$field['Field']];
|
||||
if (isset($commentsMap[$field['Field']])) {
|
||||
$displayedFields[$rownum]->comment = $commentsMap[$field['Field']];
|
||||
$rowComments[$rownum] = $commentsMap[$field['Field']];
|
||||
}
|
||||
|
||||
if ($primaryIndex !== null && $primaryIndex->hasColumn($field['Field'])) {
|
||||
$displayed_fields[$rownum]->icon .= Generator::getImage('b_primary', __('Primary'));
|
||||
$displayedFields[$rownum]->icon .= Generator::getImage('b_primary', __('Primary'));
|
||||
}
|
||||
|
||||
if (in_array($field['Field'], $columns_with_index)) {
|
||||
$displayed_fields[$rownum]->icon .= Generator::getImage('bd_primary', __('Index'));
|
||||
if (in_array($field['Field'], $columnsWithIndex)) {
|
||||
$displayedFields[$rownum]->icon .= Generator::getImage('bd_primary', __('Index'));
|
||||
}
|
||||
|
||||
$collation = Charsets::findCollationByName(
|
||||
@ -237,17 +237,17 @@ class StructureController extends AbstractController
|
||||
'table' => $GLOBALS['table'],
|
||||
'db_is_system_schema' => $isSystemSchema,
|
||||
'tbl_is_view' => $GLOBALS['tbl_is_view'],
|
||||
'mime_map' => $mime_map,
|
||||
'mime_map' => $mimeMap,
|
||||
'tbl_storage_engine' => $GLOBALS['tbl_storage_engine'],
|
||||
'primary' => $primaryIndex,
|
||||
'columns_with_unique_index' => $columns_with_unique_index,
|
||||
'columns_list' => $columns_list,
|
||||
'columns_with_unique_index' => $columnsWithUniqueIndex,
|
||||
'columns_list' => $columnsList,
|
||||
'table_stats' => $tablestats ?? null,
|
||||
'fields' => $fields,
|
||||
'extracted_columnspecs' => $extracted_columnspecs,
|
||||
'columns_with_index' => $columns_with_index,
|
||||
'central_list' => $central_list,
|
||||
'comments_map' => $comments_map,
|
||||
'extracted_columnspecs' => $extractedColumnSpecs,
|
||||
'columns_with_index' => $columnsWithIndex,
|
||||
'central_list' => $centralList,
|
||||
'comments_map' => $commentsMap,
|
||||
'browse_mime' => $GLOBALS['cfg']['BrowseMIME'],
|
||||
'show_column_comments' => $GLOBALS['cfg']['ShowColumnComments'],
|
||||
'show_stats' => $GLOBALS['cfg']['ShowStats'],
|
||||
@ -260,8 +260,8 @@ class StructureController extends AbstractController
|
||||
'partition_names' => Partition::getPartitionNames($GLOBALS['db'], $GLOBALS['table']),
|
||||
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
|
||||
'attributes' => $attributes,
|
||||
'displayed_fields' => $displayed_fields,
|
||||
'row_comments' => $row_comments,
|
||||
'displayed_fields' => $displayedFields,
|
||||
'row_comments' => $rowComments,
|
||||
'route' => $route,
|
||||
]);
|
||||
}
|
||||
@ -292,51 +292,51 @@ class StructureController extends AbstractController
|
||||
$GLOBALS['showtable']['Index_length'] = 0;
|
||||
}
|
||||
|
||||
$is_innodb = (isset($GLOBALS['showtable']['Type'])
|
||||
$isInnoDB = (isset($GLOBALS['showtable']['Type'])
|
||||
&& $GLOBALS['showtable']['Type'] === 'InnoDB');
|
||||
|
||||
$mergetable = $this->tableObj->isMerge();
|
||||
|
||||
// this is to display for example 261.2 MiB instead of 268k KiB
|
||||
$max_digits = 3;
|
||||
$maxDigits = 3;
|
||||
$decimals = 1;
|
||||
[$data_size, $data_unit] = Util::formatByteDown($GLOBALS['showtable']['Data_length'], $max_digits, $decimals);
|
||||
[$dataSize, $dataUnit] = Util::formatByteDown($GLOBALS['showtable']['Data_length'], $maxDigits, $decimals);
|
||||
if ($mergetable === false) {
|
||||
[$index_size, $index_unit] = Util::formatByteDown(
|
||||
[$indexSize, $indexUnit] = Util::formatByteDown(
|
||||
$GLOBALS['showtable']['Index_length'],
|
||||
$max_digits,
|
||||
$maxDigits,
|
||||
$decimals,
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['showtable']['Data_free'])) {
|
||||
[$free_size, $free_unit] = Util::formatByteDown($GLOBALS['showtable']['Data_free'], $max_digits, $decimals);
|
||||
[$effect_size, $effect_unit] = Util::formatByteDown(
|
||||
[$freeSize, $freeUnit] = Util::formatByteDown($GLOBALS['showtable']['Data_free'], $maxDigits, $decimals);
|
||||
[$effectSize, $effectUnit] = Util::formatByteDown(
|
||||
$GLOBALS['showtable']['Data_length']
|
||||
+ $GLOBALS['showtable']['Index_length']
|
||||
- $GLOBALS['showtable']['Data_free'],
|
||||
$max_digits,
|
||||
$maxDigits,
|
||||
$decimals,
|
||||
);
|
||||
} else {
|
||||
[$effect_size, $effect_unit] = Util::formatByteDown(
|
||||
[$effectSize, $effectUnit] = Util::formatByteDown(
|
||||
$GLOBALS['showtable']['Data_length']
|
||||
+ $GLOBALS['showtable']['Index_length'],
|
||||
$max_digits,
|
||||
$maxDigits,
|
||||
$decimals,
|
||||
);
|
||||
}
|
||||
|
||||
[$tot_size, $tot_unit] = Util::formatByteDown(
|
||||
[$totSize, $totUnit] = Util::formatByteDown(
|
||||
$GLOBALS['showtable']['Data_length'] + $GLOBALS['showtable']['Index_length'],
|
||||
$max_digits,
|
||||
$maxDigits,
|
||||
$decimals,
|
||||
);
|
||||
|
||||
$avg_size = '';
|
||||
$avg_unit = '';
|
||||
$avgSize = '';
|
||||
$avgUnit = '';
|
||||
if ($GLOBALS['table_info_num_rows'] > 0) {
|
||||
[$avg_size, $avg_unit] = Util::formatByteDown(
|
||||
[$avgSize, $avgUnit] = Util::formatByteDown(
|
||||
($GLOBALS['showtable']['Data_length']
|
||||
+ $GLOBALS['showtable']['Index_length'])
|
||||
/ $GLOBALS['showtable']['Rows'],
|
||||
@ -347,7 +347,7 @@ class StructureController extends AbstractController
|
||||
|
||||
/** @var Innodb $innodbEnginePlugin */
|
||||
$innodbEnginePlugin = StorageEngine::getEngine('Innodb');
|
||||
$innodb_file_per_table = $innodbEnginePlugin->supportsFilePerTable();
|
||||
$innodbFilePerTable = $innodbEnginePlugin->supportsFilePerTable();
|
||||
|
||||
$tableCollation = [];
|
||||
$collation = Charsets::findCollationByName(
|
||||
@ -383,21 +383,21 @@ class StructureController extends AbstractController
|
||||
'db_is_system_schema' => $isSystemSchema,
|
||||
'tbl_storage_engine' => $GLOBALS['tbl_storage_engine'],
|
||||
'table_collation' => $tableCollation,
|
||||
'is_innodb' => $is_innodb,
|
||||
'is_innodb' => $isInnoDB,
|
||||
'mergetable' => $mergetable,
|
||||
'avg_size' => $avg_size ?? null,
|
||||
'avg_unit' => $avg_unit ?? null,
|
||||
'data_size' => $data_size,
|
||||
'data_unit' => $data_unit,
|
||||
'index_size' => $index_size ?? null,
|
||||
'index_unit' => $index_unit ?? null,
|
||||
'innodb_file_per_table' => $innodb_file_per_table,
|
||||
'free_size' => $free_size ?? null,
|
||||
'free_unit' => $free_unit ?? null,
|
||||
'effect_size' => $effect_size,
|
||||
'effect_unit' => $effect_unit,
|
||||
'tot_size' => $tot_size,
|
||||
'tot_unit' => $tot_unit,
|
||||
'avg_size' => $avgSize ?? null,
|
||||
'avg_unit' => $avgUnit ?? null,
|
||||
'data_size' => $dataSize,
|
||||
'data_unit' => $dataUnit,
|
||||
'index_size' => $indexSize ?? null,
|
||||
'index_unit' => $indexUnit ?? null,
|
||||
'innodb_file_per_table' => $innodbFilePerTable,
|
||||
'free_size' => $freeSize ?? null,
|
||||
'free_unit' => $freeUnit ?? null,
|
||||
'effect_size' => $effectSize,
|
||||
'effect_unit' => $effectUnit,
|
||||
'tot_size' => $totSize,
|
||||
'tot_unit' => $totUnit,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ class ZoomSearchController extends AbstractController
|
||||
// Gets the list and number of columns
|
||||
$columns = $this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table'], true);
|
||||
// Get details about the geometry functions
|
||||
$geom_types = Gis::getDataTypes();
|
||||
$geomTypes = Gis::getDataTypes();
|
||||
|
||||
foreach ($columns as $row) {
|
||||
// set column name
|
||||
@ -169,7 +169,7 @@ class ZoomSearchController extends AbstractController
|
||||
// before any replacement
|
||||
$this->originalColumnTypes[] = mb_strtolower($type);
|
||||
// check whether table contains geometric columns
|
||||
if (in_array($type, $geom_types)) {
|
||||
if (in_array($type, $geomTypes)) {
|
||||
$this->geomColumnFlag = true;
|
||||
}
|
||||
|
||||
@ -212,18 +212,18 @@ class ZoomSearchController extends AbstractController
|
||||
$GLOBALS['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
}
|
||||
|
||||
$criteria_column_names = $_POST['criteriaColumnNames'] ?? null;
|
||||
$criteriaColumnNames = $_POST['criteriaColumnNames'] ?? null;
|
||||
$keys = [];
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
if (! isset($criteria_column_names[$i])) {
|
||||
if (! isset($criteriaColumnNames[$i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($criteria_column_names[$i] === 'pma_null') {
|
||||
if ($criteriaColumnNames[$i] === 'pma_null') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys[$criteria_column_names[$i]] = array_search($criteria_column_names[$i], $this->columnNames);
|
||||
$keys[$criteriaColumnNames[$i]] = array_search($criteriaColumnNames[$i], $this->columnNames);
|
||||
}
|
||||
|
||||
$this->render('table/zoom_search/index', [
|
||||
@ -235,7 +235,7 @@ class ZoomSearchController extends AbstractController
|
||||
'column_names' => $this->columnNames,
|
||||
'data_label' => $dataLabel,
|
||||
'keys' => $keys,
|
||||
'criteria_column_names' => $criteria_column_names,
|
||||
'criteria_column_names' => $criteriaColumnNames,
|
||||
'criteria_column_types' => $_POST['criteriaColumnTypes'] ?? null,
|
||||
'max_plot_limit' => ! empty($_POST['maxPlotLimit'])
|
||||
? intval($_POST['maxPlotLimit'])
|
||||
@ -252,26 +252,26 @@ class ZoomSearchController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
$extra_data = [];
|
||||
$row_info_query = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
|
||||
$extraData = [];
|
||||
$rowInfoQuery = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
|
||||
. Util::backquote($_POST['table']) . ' WHERE ' . $_POST['where_clause'];
|
||||
$result = $this->dbi->query($row_info_query . ';');
|
||||
$fields_meta = $this->dbi->getFieldsMeta($result);
|
||||
$result = $this->dbi->query($rowInfoQuery . ';');
|
||||
$fieldsMeta = $this->dbi->getFieldsMeta($result);
|
||||
while ($row = $result->fetchAssoc()) {
|
||||
// for bit fields we need to convert them to printable form
|
||||
$i = 0;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($fields_meta[$i]->isMappedTypeBit) {
|
||||
$row[$col] = Util::printableBitValue((int) $val, $fields_meta[$i]->length);
|
||||
if ($fieldsMeta[$i]->isMappedTypeBit) {
|
||||
$row[$col] = Util::printableBitValue((int) $val, $fieldsMeta[$i]->length);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$extra_data['row_info'] = $row;
|
||||
$extraData['row_info'] = $row;
|
||||
}
|
||||
|
||||
$this->response->addJSON($extra_data);
|
||||
$this->response->addJSON($extraData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,10 +290,10 @@ class ZoomSearchController extends AbstractController
|
||||
}
|
||||
|
||||
$key = array_search($field, $this->columnNames);
|
||||
$search_index = (isset($_POST['it']) && is_numeric($_POST['it'])
|
||||
$searchIndex = (isset($_POST['it']) && is_numeric($_POST['it'])
|
||||
? intval($_POST['it']) : 0);
|
||||
|
||||
$properties = $this->getColumnProperties($search_index, $key);
|
||||
$properties = $this->getColumnProperties($searchIndex, $key);
|
||||
$this->response->addJSON(
|
||||
'field_type',
|
||||
htmlspecialchars($properties['type']),
|
||||
@ -312,12 +312,12 @@ class ZoomSearchController extends AbstractController
|
||||
public function zoomSubmitAction(string $dataLabel, string $goto): void
|
||||
{
|
||||
//Query generation part
|
||||
$sql_query = $this->search->buildSqlQuery();
|
||||
$sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
|
||||
$sqlQuery = $this->search->buildSqlQuery();
|
||||
$sqlQuery .= ' LIMIT ' . $_POST['maxPlotLimit'];
|
||||
|
||||
//Query execution part
|
||||
$result = $this->dbi->query($sql_query . ';');
|
||||
$fields_meta = $this->dbi->getFieldsMeta($result);
|
||||
$result = $this->dbi->query($sqlQuery . ';');
|
||||
$fieldsMeta = $this->dbi->getFieldsMeta($result);
|
||||
$data = [];
|
||||
while ($row = $result->fetchAssoc()) {
|
||||
//Need a row with indexes as 0,1,2 for the getUniqueCondition
|
||||
@ -327,7 +327,7 @@ class ZoomSearchController extends AbstractController
|
||||
//Get unique condition on each row (will be needed for row update)
|
||||
[$uniqueCondition] = Util::getUniqueCondition(
|
||||
count($this->columnNames),
|
||||
$fields_meta,
|
||||
$fieldsMeta,
|
||||
$tmpRow,
|
||||
true,
|
||||
);
|
||||
@ -347,13 +347,13 @@ class ZoomSearchController extends AbstractController
|
||||
|
||||
unset($tmpData);
|
||||
|
||||
$column_names_hashes = [];
|
||||
$columnNamesHashes = [];
|
||||
$foreignDropdown = [];
|
||||
$searchColumnInForeigners = [];
|
||||
$foreignData = [];
|
||||
|
||||
foreach ($this->columnNames as $columnIndex => $columnName) {
|
||||
$column_names_hashes[$columnName] = md5($columnName);
|
||||
$columnNamesHashes[$columnName] = md5($columnName);
|
||||
$foreignData[$columnIndex] = $this->relation->getForeignData($this->foreigners, $columnName, false, '', '');
|
||||
$searchColumnInForeigners[$columnIndex] = $this->relation->searchColumnInForeigners(
|
||||
$this->foreigners,
|
||||
@ -380,7 +380,7 @@ class ZoomSearchController extends AbstractController
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table'],
|
||||
'column_names' => $this->columnNames,
|
||||
'column_names_hashes' => $column_names_hashes,
|
||||
'column_names_hashes' => $columnNamesHashes,
|
||||
'foreigners' => $this->foreigners,
|
||||
'column_null_flags' => $this->columnNullFlags,
|
||||
'column_types' => $this->columnTypes,
|
||||
@ -398,33 +398,33 @@ class ZoomSearchController extends AbstractController
|
||||
* Provides a column's type, collation, operators list, and criteria value
|
||||
* to display in table search form
|
||||
*
|
||||
* @param int $search_index Row number in table search form
|
||||
* @param int $column_index Column index in ColumnNames array
|
||||
* @param int $searchIndex Row number in table search form
|
||||
* @param int $columnIndex Column index in ColumnNames array
|
||||
*
|
||||
* @return array Array containing column's properties
|
||||
*/
|
||||
public function getColumnProperties(int $search_index, int $column_index): array
|
||||
public function getColumnProperties(int $searchIndex, int $columnIndex): array
|
||||
{
|
||||
$selected_operator = ($_POST['criteriaColumnOperators'][$search_index] ?? '');
|
||||
$entered_value = ($_POST['criteriaValues'] ?? '');
|
||||
$selectedOperator = ($_POST['criteriaColumnOperators'][$searchIndex] ?? '');
|
||||
$enteredValue = ($_POST['criteriaValues'] ?? '');
|
||||
//Gets column's type and collation
|
||||
$type = $this->columnTypes[$column_index];
|
||||
$collation = $this->columnCollations[$column_index];
|
||||
$type = $this->columnTypes[$columnIndex];
|
||||
$collation = $this->columnCollations[$columnIndex];
|
||||
$cleanType = preg_replace('@\(.*@s', '', $type);
|
||||
//Gets column's comparison operators depending on column type
|
||||
$typeOperators = $this->dbi->types->getTypeOperatorsHtml(
|
||||
$cleanType,
|
||||
$this->columnNullFlags[$column_index],
|
||||
$selected_operator,
|
||||
$this->columnNullFlags[$columnIndex],
|
||||
$selectedOperator,
|
||||
);
|
||||
$func = $this->template->render('table/search/column_comparison_operators', [
|
||||
'search_index' => $search_index,
|
||||
'search_index' => $searchIndex,
|
||||
'type_operators' => $typeOperators,
|
||||
]);
|
||||
//Gets link to browse foreign data(if any) and criteria inputbox
|
||||
$foreignData = $this->relation->getForeignData(
|
||||
$this->foreigners,
|
||||
$this->columnNames[$column_index],
|
||||
$this->columnNames[$columnIndex],
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
@ -433,21 +433,21 @@ class ZoomSearchController extends AbstractController
|
||||
$isInteger = in_array($cleanType, $this->dbi->types->getIntegerTypes());
|
||||
$isFloat = in_array($cleanType, $this->dbi->types->getFloatTypes());
|
||||
if ($isInteger) {
|
||||
$extractedColumnspec = Util::extractColumnSpec($this->originalColumnTypes[$column_index]);
|
||||
$is_unsigned = $extractedColumnspec['unsigned'];
|
||||
$minMaxValues = $this->dbi->types->getIntegerRange($cleanType, ! $is_unsigned);
|
||||
$extractedColumnspec = Util::extractColumnSpec($this->originalColumnTypes[$columnIndex]);
|
||||
$isUnsigned = $extractedColumnspec['unsigned'];
|
||||
$minMaxValues = $this->dbi->types->getIntegerRange($cleanType, ! $isUnsigned);
|
||||
$htmlAttributes = 'data-min="' . $minMaxValues[0] . '" '
|
||||
. 'data-max="' . $minMaxValues[1] . '"';
|
||||
}
|
||||
|
||||
$htmlAttributes .= ' onfocus="return '
|
||||
. 'verifyAfterSearchFieldChange(' . $search_index . ', \'#zoom_search_form\')"';
|
||||
. 'verifyAfterSearchFieldChange(' . $searchIndex . ', \'#zoom_search_form\')"';
|
||||
|
||||
$foreignDropdown = '';
|
||||
|
||||
if (
|
||||
$this->foreigners
|
||||
&& $this->relation->searchColumnInForeigners($this->foreigners, $this->columnNames[$column_index])
|
||||
&& $this->relation->searchColumnInForeigners($this->foreigners, $this->columnNames[$columnIndex])
|
||||
&& is_array($foreignData['disp_row'])
|
||||
) {
|
||||
$foreignDropdown = $this->relation->foreignDropdown(
|
||||
@ -467,12 +467,12 @@ class ZoomSearchController extends AbstractController
|
||||
'column_id' => 'fieldID_',
|
||||
'in_zoom_search_edit' => false,
|
||||
'foreigners' => $this->foreigners,
|
||||
'column_name' => $this->columnNames[$column_index],
|
||||
'column_name_hash' => md5($this->columnNames[$column_index]),
|
||||
'column_name' => $this->columnNames[$columnIndex],
|
||||
'column_name_hash' => md5($this->columnNames[$columnIndex]),
|
||||
'foreign_data' => $foreignData,
|
||||
'table' => $GLOBALS['table'],
|
||||
'column_index' => $search_index,
|
||||
'criteria_values' => $entered_value,
|
||||
'column_index' => $searchIndex,
|
||||
'criteria_values' => $enteredValue,
|
||||
'db' => $GLOBALS['db'],
|
||||
'in_fbs' => true,
|
||||
'foreign_dropdown' => $foreignDropdown,
|
||||
|
||||
@ -76,24 +76,24 @@ class UserPasswordController extends AbstractController
|
||||
$GLOBALS['msg'] = $GLOBALS['change_password_message']['msg'];
|
||||
|
||||
if (! $GLOBALS['change_password_message']['error']) {
|
||||
$sql_query = $this->userPassword->changePassword(
|
||||
$sqlQuery = $this->userPassword->changePassword(
|
||||
$password,
|
||||
$request->getParsedBodyParam('authentication_plugin'),
|
||||
);
|
||||
|
||||
if ($this->response->isAjax()) {
|
||||
$sql_query = Generator::getMessage(
|
||||
$sqlQuery = Generator::getMessage(
|
||||
$GLOBALS['change_password_message']['msg'],
|
||||
$sql_query,
|
||||
$sqlQuery,
|
||||
'success',
|
||||
);
|
||||
$this->response->addJSON('message', $sql_query);
|
||||
$this->response->addJSON('message', $sqlQuery);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->addHTML('<h1>' . __('Change password') . '</h1>' . "\n\n");
|
||||
$this->response->addHTML(Generator::getMessage($GLOBALS['msg'], $sql_query, 'success'));
|
||||
$this->response->addHTML(Generator::getMessage($GLOBALS['msg'], $sqlQuery, 'success'));
|
||||
$this->render('user_password');
|
||||
|
||||
return;
|
||||
|
||||
@ -83,7 +83,7 @@ class Core
|
||||
public static function getPHPDocLink(string $target): string
|
||||
{
|
||||
/* List of PHP documentation translations */
|
||||
$php_doc_languages = [
|
||||
$phpDocLanguages = [
|
||||
'pt_BR',
|
||||
'zh_CN',
|
||||
'fr',
|
||||
@ -95,7 +95,7 @@ class Core
|
||||
];
|
||||
|
||||
$lang = 'en';
|
||||
if (isset($GLOBALS['lang']) && in_array($GLOBALS['lang'], $php_doc_languages)) {
|
||||
if (isset($GLOBALS['lang']) && in_array($GLOBALS['lang'], $phpDocLanguages)) {
|
||||
if ($GLOBALS['lang'] === 'zh_CN') {
|
||||
$lang = 'zh';
|
||||
} else {
|
||||
@ -216,23 +216,23 @@ class Core
|
||||
return false;
|
||||
}
|
||||
|
||||
$_page = mb_substr(
|
||||
$newPage = mb_substr(
|
||||
$page,
|
||||
0,
|
||||
(int) mb_strpos($page . '?', '?'),
|
||||
);
|
||||
if (in_array($_page, $allowList)) {
|
||||
if (in_array($newPage, $allowList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$_page = urldecode($page);
|
||||
$_page = mb_substr(
|
||||
$_page,
|
||||
$newPage = urldecode($page);
|
||||
$newPage = mb_substr(
|
||||
$newPage,
|
||||
0,
|
||||
(int) mb_strpos($_page . '?', '?'),
|
||||
(int) mb_strpos($newPage . '?', '?'),
|
||||
);
|
||||
|
||||
return in_array($_page, $allowList);
|
||||
return in_array($newPage, $allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,26 +241,26 @@ class Core
|
||||
* searches in $_SERVER, $_ENV then tries getenv() and apache_getenv()
|
||||
* in this order
|
||||
*
|
||||
* @param string $var_name variable name
|
||||
* @param string $varName variable name
|
||||
*
|
||||
* @return string value of $var or empty string
|
||||
*/
|
||||
public static function getenv(string $var_name): string
|
||||
public static function getenv(string $varName): string
|
||||
{
|
||||
if (isset($_SERVER[$var_name])) {
|
||||
return (string) $_SERVER[$var_name];
|
||||
if (isset($_SERVER[$varName])) {
|
||||
return (string) $_SERVER[$varName];
|
||||
}
|
||||
|
||||
if (isset($_ENV[$var_name])) {
|
||||
return (string) $_ENV[$var_name];
|
||||
if (isset($_ENV[$varName])) {
|
||||
return (string) $_ENV[$varName];
|
||||
}
|
||||
|
||||
if (getenv($var_name)) {
|
||||
return (string) getenv($var_name);
|
||||
if (getenv($varName)) {
|
||||
return (string) getenv($varName);
|
||||
}
|
||||
|
||||
if (function_exists('apache_getenv') && apache_getenv($var_name, true)) {
|
||||
return (string) apache_getenv($var_name, true);
|
||||
if (function_exists('apache_getenv') && apache_getenv($varName, true)) {
|
||||
return (string) apache_getenv($varName, true);
|
||||
}
|
||||
|
||||
return '';
|
||||
@ -269,10 +269,10 @@ class Core
|
||||
/**
|
||||
* Send HTTP header, taking IIS limits into account (600 seems ok)
|
||||
*
|
||||
* @param string $uri the header to send
|
||||
* @param bool $use_refresh whether to use Refresh: header when running on IIS
|
||||
* @param string $uri the header to send
|
||||
* @param bool $useRefresh whether to use Refresh: header when running on IIS
|
||||
*/
|
||||
public static function sendHeaderLocation(string $uri, bool $use_refresh = false): void
|
||||
public static function sendHeaderLocation(string $uri, bool $useRefresh = false): void
|
||||
{
|
||||
if ($GLOBALS['config']->get('PMA_IS_IIS') && mb_strlen($uri) > 600) {
|
||||
ResponseRenderer::getInstance()->disable();
|
||||
@ -301,7 +301,7 @@ class Core
|
||||
// bug #1523784: IE6 does not like 'Refresh: 0', it
|
||||
// results in a blank page
|
||||
// but we need it when coming from the cookie login panel)
|
||||
if ($GLOBALS['config']->get('PMA_IS_IIS') && $use_refresh) {
|
||||
if ($GLOBALS['config']->get('PMA_IS_IIS') && $useRefresh) {
|
||||
$response->header('Refresh: 0; ' . $uri);
|
||||
|
||||
return;
|
||||
@ -362,17 +362,17 @@ class Core
|
||||
* none Content-Disposition header will be sent.
|
||||
* @param string $mimetype MIME type to include in headers.
|
||||
* @param int $length Length of content (optional)
|
||||
* @param bool $no_cache Whether to include no-caching headers.
|
||||
* @param bool $noCache Whether to include no-caching headers.
|
||||
*/
|
||||
public static function downloadHeader(
|
||||
string $filename,
|
||||
string $mimetype,
|
||||
int $length = 0,
|
||||
bool $no_cache = true,
|
||||
bool $noCache = true,
|
||||
): void {
|
||||
$headers = [];
|
||||
|
||||
if ($no_cache) {
|
||||
if ($noCache) {
|
||||
$headers = self::getNoCacheHeaders();
|
||||
}
|
||||
|
||||
@ -437,7 +437,7 @@ class Core
|
||||
public static function arrayWrite(string $path, array &$array, mixed $value): void
|
||||
{
|
||||
$keys = explode('/', $path);
|
||||
$last_key = array_pop($keys);
|
||||
$lastKey = array_pop($keys);
|
||||
$a =& $array;
|
||||
foreach ($keys as $key) {
|
||||
if (! isset($a[$key])) {
|
||||
@ -447,7 +447,7 @@ class Core
|
||||
$a =& $a[$key];
|
||||
}
|
||||
|
||||
$a[$last_key] = $value;
|
||||
$a[$lastKey] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,7 +459,7 @@ class Core
|
||||
public static function arrayRemove(string $path, array &$array): void
|
||||
{
|
||||
$keys = explode('/', $path);
|
||||
$keys_last = array_pop($keys);
|
||||
$keysLast = array_pop($keys);
|
||||
$path = [];
|
||||
$depth = 0;
|
||||
|
||||
@ -478,7 +478,7 @@ class Core
|
||||
|
||||
// if element found, remove it
|
||||
if ($found) {
|
||||
unset($path[$depth][$keys_last]);
|
||||
unset($path[$depth][$keysLast]);
|
||||
$depth--;
|
||||
}
|
||||
|
||||
@ -593,19 +593,19 @@ class Core
|
||||
/**
|
||||
* Displays SQL query before executing.
|
||||
*
|
||||
* @param array|string $query_data Array containing queries or query itself
|
||||
* @param array|string $queryData Array containing queries or query itself
|
||||
*/
|
||||
public static function previewSQL(array|string $query_data): void
|
||||
public static function previewSQL(array|string $queryData): void
|
||||
{
|
||||
$retval = '<div class="preview_sql">';
|
||||
if ($query_data === '' || $query_data === []) {
|
||||
if ($queryData === '' || $queryData === []) {
|
||||
$retval .= __('No change');
|
||||
} elseif (is_array($query_data)) {
|
||||
foreach ($query_data as $query) {
|
||||
} elseif (is_array($queryData)) {
|
||||
foreach ($queryData as $query) {
|
||||
$retval .= Html\Generator::formatSql($query);
|
||||
}
|
||||
} else {
|
||||
$retval .= Html\Generator::formatSql($query_data);
|
||||
$retval .= Html\Generator::formatSql($queryData);
|
||||
}
|
||||
|
||||
$retval .= '</div>';
|
||||
@ -639,19 +639,19 @@ class Core
|
||||
/**
|
||||
* Creates some globals from $_POST variables matching a pattern
|
||||
*
|
||||
* @param array $post_patterns The patterns to search for
|
||||
* @param array $postPatterns The patterns to search for
|
||||
*/
|
||||
public static function setPostAsGlobal(array $post_patterns): void
|
||||
public static function setPostAsGlobal(array $postPatterns): void
|
||||
{
|
||||
$container = self::getContainerBuilder();
|
||||
foreach (array_keys($_POST) as $post_key) {
|
||||
foreach ($post_patterns as $one_post_pattern) {
|
||||
if (! preg_match($one_post_pattern, $post_key)) {
|
||||
foreach (array_keys($_POST) as $postKey) {
|
||||
foreach ($postPatterns as $onePostPattern) {
|
||||
if (! preg_match($onePostPattern, $postKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$GLOBALS[$post_key] = $_POST[$post_key];
|
||||
$container->setParameter($post_key, $GLOBALS[$post_key]);
|
||||
$GLOBALS[$postKey] = $_POST[$postKey];
|
||||
$container->setParameter($postKey, $GLOBALS[$postKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -669,12 +669,12 @@ class Core
|
||||
return false;
|
||||
}
|
||||
|
||||
$direct_ip = $_SERVER['REMOTE_ADDR'];
|
||||
$directIp = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
/* Do we trust this IP as a proxy? If yes we will use it's header. */
|
||||
if (! isset($GLOBALS['cfg']['TrustedProxies'][$direct_ip])) {
|
||||
if (! isset($GLOBALS['cfg']['TrustedProxies'][$directIp])) {
|
||||
/* Return true IP */
|
||||
return $direct_ip;
|
||||
return $directIp;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -682,13 +682,13 @@ class Core
|
||||
* X-Forwarded-For: client, proxy1, proxy2
|
||||
*/
|
||||
// Get header content
|
||||
$value = self::getenv($GLOBALS['cfg']['TrustedProxies'][$direct_ip]);
|
||||
$value = self::getenv($GLOBALS['cfg']['TrustedProxies'][$directIp]);
|
||||
// Grab first element what is client adddress
|
||||
$value = explode(',', $value)[0];
|
||||
// checks that the header contains only one IP address,
|
||||
$is_ip = filter_var($value, FILTER_VALIDATE_IP);
|
||||
$isIp = filter_var($value, FILTER_VALIDATE_IP);
|
||||
|
||||
if ($is_ip !== false) {
|
||||
if ($isIp !== false) {
|
||||
// True IP behind a proxy
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -116,21 +116,21 @@ class CentralColumns
|
||||
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$this->dbi->selectDb($pmadb, Connection::TYPE_CONTROL);
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
//get current values of $db from central column list
|
||||
if ($num == 0) {
|
||||
$query = 'SELECT * FROM ' . Util::backquote($central_list_table) . ' '
|
||||
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\';';
|
||||
} else {
|
||||
$query = 'SELECT * FROM ' . Util::backquote($central_list_table) . ' '
|
||||
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\' '
|
||||
. 'LIMIT ' . $from . ', ' . $num . ';';
|
||||
}
|
||||
|
||||
$has_list = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($has_list);
|
||||
$hasList = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($hasList);
|
||||
|
||||
return $has_list;
|
||||
return $hasList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,9 +149,9 @@ class CentralColumns
|
||||
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$this->dbi->selectDb($pmadb, Connection::TYPE_CONTROL);
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
$query = 'SELECT count(db_name) FROM '
|
||||
. Util::backquote($central_list_table) . ' '
|
||||
. Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\';';
|
||||
$res = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
if (isset($res[0])) {
|
||||
@ -183,30 +183,30 @@ class CentralColumns
|
||||
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$this->dbi->selectDb($pmadb, Connection::TYPE_CONTROL);
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
if ($allFields) {
|
||||
$query = 'SELECT * FROM ' . Util::backquote($central_list_table) . ' '
|
||||
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\' AND col_name IN (' . $cols . ');';
|
||||
$has_list = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($has_list);
|
||||
$hasList = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($hasList);
|
||||
} else {
|
||||
$query = 'SELECT col_name FROM '
|
||||
. Util::backquote($central_list_table) . ' '
|
||||
. Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\' AND col_name IN (' . $cols . ');';
|
||||
$has_list = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$hasList = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
}
|
||||
|
||||
return $has_list;
|
||||
return $hasList;
|
||||
}
|
||||
|
||||
/**
|
||||
* build the insert query for central columns list given PMA storage
|
||||
* db, central_columns table, column name and corresponding definition to be added
|
||||
*
|
||||
* @param string $column column to add into central list
|
||||
* @param array $def list of attributes of the column being added
|
||||
* @param string $db PMA configuration storage database name
|
||||
* @param string $central_list_table central columns configuration storage table name
|
||||
* @param string $column column to add into central list
|
||||
* @param array $def list of attributes of the column being added
|
||||
* @param string $db PMA configuration storage database name
|
||||
* @param string $centralListTable central columns configuration storage table name
|
||||
*
|
||||
* @return string query string to insert the given column
|
||||
* with definition into central list
|
||||
@ -215,16 +215,16 @@ class CentralColumns
|
||||
string $column,
|
||||
array $def,
|
||||
string $db,
|
||||
string $central_list_table,
|
||||
string $centralListTable,
|
||||
): string {
|
||||
$type = '';
|
||||
$length = 0;
|
||||
$attribute = '';
|
||||
if (isset($def['Type'])) {
|
||||
$extracted_columnspec = Util::extractColumnSpec($def['Type']);
|
||||
$attribute = trim($extracted_columnspec['attribute']);
|
||||
$type = $extracted_columnspec['type'];
|
||||
$length = $extracted_columnspec['spec_in_brackets'];
|
||||
$extractedColumnSpec = Util::extractColumnSpec($def['Type']);
|
||||
$attribute = trim($extractedColumnSpec['attribute']);
|
||||
$type = $extractedColumnSpec['type'];
|
||||
$length = $extractedColumnSpec['spec_in_brackets'];
|
||||
}
|
||||
|
||||
if (isset($def['Attribute'])) {
|
||||
@ -237,7 +237,7 @@ class CentralColumns
|
||||
$default = $def['Default'] ?? '';
|
||||
|
||||
return 'INSERT INTO '
|
||||
. Util::backquote($central_list_table) . ' '
|
||||
. Util::backquote($centralListTable) . ' '
|
||||
. 'VALUES ( \'' . $this->dbi->escapeString($db) . '\' ,'
|
||||
. '\'' . $this->dbi->escapeString($column) . '\',\''
|
||||
. $this->dbi->escapeString($type) . '\','
|
||||
@ -253,16 +253,16 @@ class CentralColumns
|
||||
* are added to central list otherwise the $field_select is considered as
|
||||
* list of columns and these columns are added to central list if not already added
|
||||
*
|
||||
* @param array $field_select if $isTable is true selected tables list
|
||||
* @param array $fieldSelect if $isTable is true selected tables list
|
||||
* otherwise selected columns list
|
||||
* @param bool $isTable if passed array is of tables or columns
|
||||
* @param string $table if $isTable is false, then table name to
|
||||
* which columns belong
|
||||
* @param bool $isTable if passed array is of tables or columns
|
||||
* @param string $table if $isTable is false, then table name to
|
||||
* which columns belong
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function syncUniqueColumns(
|
||||
array $field_select,
|
||||
array $fieldSelect,
|
||||
bool $isTable = true,
|
||||
string|null $table = null,
|
||||
): bool|Message {
|
||||
@ -275,7 +275,7 @@ class CentralColumns
|
||||
|
||||
$db = $_POST['db'];
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
$this->dbi->selectDb($db);
|
||||
$existingCols = [];
|
||||
$cols = '';
|
||||
@ -283,20 +283,20 @@ class CentralColumns
|
||||
$fields = [];
|
||||
$message = true;
|
||||
if ($isTable) {
|
||||
foreach ($field_select as $table) {
|
||||
foreach ($fieldSelect as $table) {
|
||||
$fields[$table] = $this->dbi->getColumns($db, $table, true);
|
||||
foreach (array_column($fields[$table], 'Field') as $field) {
|
||||
$cols .= "'" . $this->dbi->escapeString($field) . "',";
|
||||
}
|
||||
}
|
||||
|
||||
$has_list = $this->findExistingColNames($db, trim($cols, ','));
|
||||
foreach ($field_select as $table) {
|
||||
$hasList = $this->findExistingColNames($db, trim($cols, ','));
|
||||
foreach ($fieldSelect as $table) {
|
||||
foreach ($fields[$table] as $def) {
|
||||
$field = (string) $def['Field'];
|
||||
if (! in_array($field, $has_list)) {
|
||||
$has_list[] = $field;
|
||||
$insQuery[] = $this->getInsertQuery($field, $def, $db, $central_list_table);
|
||||
if (! in_array($field, $hasList)) {
|
||||
$hasList[] = $field;
|
||||
$insQuery[] = $this->getInsertQuery($field, $def, $db, $centralListTable);
|
||||
} else {
|
||||
$existingCols[] = "'" . $field . "'";
|
||||
}
|
||||
@ -307,16 +307,16 @@ class CentralColumns
|
||||
$table = $_POST['table'];
|
||||
}
|
||||
|
||||
foreach ($field_select as $column) {
|
||||
foreach ($fieldSelect as $column) {
|
||||
$cols .= "'" . $this->dbi->escapeString($column) . "',";
|
||||
}
|
||||
|
||||
$has_list = $this->findExistingColNames($db, trim($cols, ','));
|
||||
foreach ($field_select as $column) {
|
||||
if (! in_array($column, $has_list)) {
|
||||
$has_list[] = $column;
|
||||
$hasList = $this->findExistingColNames($db, trim($cols, ','));
|
||||
foreach ($fieldSelect as $column) {
|
||||
if (! in_array($column, $hasList)) {
|
||||
$hasList[] = $column;
|
||||
$field = $this->dbi->getColumn($db, $table, $column, true);
|
||||
$insQuery[] = $this->getInsertQuery($column, $field, $db, $central_list_table);
|
||||
$insQuery[] = $this->getInsertQuery($column, $field, $db, $centralListTable);
|
||||
} else {
|
||||
$existingCols[] = "'" . $column . "'";
|
||||
}
|
||||
@ -359,16 +359,16 @@ class CentralColumns
|
||||
* central columns list otherwise $field_select is columns list and it removes
|
||||
* given columns if present in central list
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param array $field_select if $isTable selected list of tables otherwise
|
||||
* @param string $database Database name
|
||||
* @param array $fieldSelect if $isTable selected list of tables otherwise
|
||||
* selected list of columns to remove from central list
|
||||
* @param bool $isTable if passed array is of tables or columns
|
||||
* @param bool $isTable if passed array is of tables or columns
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function deleteColumnsFromList(
|
||||
string $database,
|
||||
array $field_select,
|
||||
array $fieldSelect,
|
||||
bool $isTable = true,
|
||||
): bool|Message {
|
||||
$cfgCentralColumns = $this->getParams();
|
||||
@ -379,25 +379,25 @@ class CentralColumns
|
||||
}
|
||||
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
$this->dbi->selectDb($database);
|
||||
$message = true;
|
||||
$colNotExist = [];
|
||||
$fields = [];
|
||||
if ($isTable) {
|
||||
$cols = '';
|
||||
foreach ($field_select as $table) {
|
||||
foreach ($fieldSelect as $table) {
|
||||
$fields[$table] = $this->dbi->getColumnNames($database, $table);
|
||||
foreach ($fields[$table] as $col_select) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($col_select) . '\',';
|
||||
foreach ($fields[$table] as $colSelect) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($colSelect) . '\',';
|
||||
}
|
||||
}
|
||||
|
||||
$cols = trim($cols, ',');
|
||||
$has_list = $this->findExistingColNames($database, $cols);
|
||||
foreach ($field_select as $table) {
|
||||
$hasList = $this->findExistingColNames($database, $cols);
|
||||
foreach ($fieldSelect as $table) {
|
||||
foreach ($fields[$table] as $column) {
|
||||
if (in_array($column, $has_list)) {
|
||||
if (in_array($column, $hasList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -406,14 +406,14 @@ class CentralColumns
|
||||
}
|
||||
} else {
|
||||
$cols = '';
|
||||
foreach ($field_select as $col_select) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($col_select) . '\',';
|
||||
foreach ($fieldSelect as $colSelect) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($colSelect) . '\',';
|
||||
}
|
||||
|
||||
$cols = trim($cols, ',');
|
||||
$has_list = $this->findExistingColNames($database, $cols);
|
||||
foreach ($field_select as $column) {
|
||||
if (in_array($column, $has_list)) {
|
||||
$hasList = $this->findExistingColNames($database, $cols);
|
||||
foreach ($fieldSelect as $column) {
|
||||
if (in_array($column, $hasList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ class CentralColumns
|
||||
|
||||
$this->dbi->selectDb($pmadb, Connection::TYPE_CONTROL);
|
||||
|
||||
$query = 'DELETE FROM ' . Util::backquote($central_list_table) . ' '
|
||||
$query = 'DELETE FROM ' . Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($database) . '\' AND col_name IN (' . $cols . ');';
|
||||
|
||||
if (! $this->dbi->tryQuery($query, Connection::TYPE_CONTROL)) {
|
||||
@ -453,25 +453,25 @@ class CentralColumns
|
||||
* Make the columns of given tables consistent with central list of columns.
|
||||
* Updates only those columns which are not being referenced.
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string[] $selected_tables list of selected tables.
|
||||
* @param string $db current database
|
||||
* @param string[] $selectedTables list of selected tables.
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function makeConsistentWithList(
|
||||
string $db,
|
||||
array $selected_tables,
|
||||
array $selectedTables,
|
||||
): bool|Message {
|
||||
$message = true;
|
||||
foreach ($selected_tables as $table) {
|
||||
foreach ($selectedTables as $table) {
|
||||
$query = 'ALTER TABLE ' . Util::backquote($table);
|
||||
$has_list = $this->getFromTable($db, $table, true);
|
||||
$hasList = $this->getFromTable($db, $table, true);
|
||||
$this->dbi->selectDb($db);
|
||||
foreach ($has_list as $column) {
|
||||
$column_status = $this->relation->checkChildForeignReferences($db, $table, $column['col_name']);
|
||||
foreach ($hasList as $column) {
|
||||
$columnStatus = $this->relation->checkChildForeignReferences($db, $table, $column['col_name']);
|
||||
//column definition can only be changed if
|
||||
//it is not referenced by another column
|
||||
if (! $column_status['isEditable']) {
|
||||
if (! $columnStatus['isEditable']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -542,8 +542,8 @@ class CentralColumns
|
||||
$this->dbi->selectDb($db);
|
||||
$fields = $this->dbi->getColumnNames($db, $table);
|
||||
$cols = '';
|
||||
foreach ($fields as $col_select) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($col_select) . '\',';
|
||||
foreach ($fields as $colSelect) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($colSelect) . '\',';
|
||||
}
|
||||
|
||||
$cols = trim($cols, ',');
|
||||
@ -554,30 +554,30 @@ class CentralColumns
|
||||
/**
|
||||
* update a column in central columns list if a edit is requested
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $orig_col_name original column name before edit
|
||||
* @param string $col_name new column name
|
||||
* @param string $col_type new column type
|
||||
* @param string $col_attribute new column attribute
|
||||
* @param string $col_length new column length
|
||||
* @param int $col_isNull value 1 if new column isNull is true, 0 otherwise
|
||||
* @param string $collation new column collation
|
||||
* @param string $col_extra new column extra property
|
||||
* @param string $col_default new column default value
|
||||
* @param string $db current database
|
||||
* @param string $origColName original column name before edit
|
||||
* @param string $colName new column name
|
||||
* @param string $colType new column type
|
||||
* @param string $colAttribute new column attribute
|
||||
* @param string $colLength new column length
|
||||
* @param int $colIsNull value 1 if new column isNull is true, 0 otherwise
|
||||
* @param string $collation new column collation
|
||||
* @param string $colExtra new column extra property
|
||||
* @param string $colDefault new column default value
|
||||
*
|
||||
* @return true|Message
|
||||
*/
|
||||
public function updateOneColumn(
|
||||
string $db,
|
||||
string $orig_col_name,
|
||||
string $col_name,
|
||||
string $col_type,
|
||||
string $col_attribute,
|
||||
string $col_length,
|
||||
int $col_isNull,
|
||||
string $origColName,
|
||||
string $colName,
|
||||
string $colType,
|
||||
string $colAttribute,
|
||||
string $colLength,
|
||||
int $colIsNull,
|
||||
string $collation,
|
||||
string $col_extra,
|
||||
string $col_default,
|
||||
string $colExtra,
|
||||
string $colDefault,
|
||||
): bool|Message {
|
||||
$cfgCentralColumns = $this->getParams();
|
||||
if (! is_array($cfgCentralColumns)) {
|
||||
@ -588,31 +588,31 @@ class CentralColumns
|
||||
|
||||
$centralTable = $cfgCentralColumns['table'];
|
||||
$this->dbi->selectDb($cfgCentralColumns['db'], Connection::TYPE_CONTROL);
|
||||
if ($orig_col_name == '') {
|
||||
if ($origColName == '') {
|
||||
$def = [];
|
||||
$def['Type'] = $col_type;
|
||||
if ($col_length) {
|
||||
$def['Type'] .= '(' . $col_length . ')';
|
||||
$def['Type'] = $colType;
|
||||
if ($colLength) {
|
||||
$def['Type'] .= '(' . $colLength . ')';
|
||||
}
|
||||
|
||||
$def['Collation'] = $collation;
|
||||
$def['Null'] = $col_isNull ? __('YES') : __('NO');
|
||||
$def['Extra'] = $col_extra;
|
||||
$def['Attribute'] = $col_attribute;
|
||||
$def['Default'] = $col_default;
|
||||
$query = $this->getInsertQuery($col_name, $def, $db, $centralTable);
|
||||
$def['Null'] = $colIsNull ? __('YES') : __('NO');
|
||||
$def['Extra'] = $colExtra;
|
||||
$def['Attribute'] = $colAttribute;
|
||||
$def['Default'] = $colDefault;
|
||||
$query = $this->getInsertQuery($colName, $def, $db, $centralTable);
|
||||
} else {
|
||||
$query = 'UPDATE ' . Util::backquote($centralTable)
|
||||
. ' SET col_type = \'' . $this->dbi->escapeString($col_type) . '\''
|
||||
. ', col_name = \'' . $this->dbi->escapeString($col_name) . '\''
|
||||
. ', col_length = \'' . $this->dbi->escapeString($col_length) . '\''
|
||||
. ', col_isNull = ' . $col_isNull
|
||||
. ' SET col_type = \'' . $this->dbi->escapeString($colType) . '\''
|
||||
. ', col_name = \'' . $this->dbi->escapeString($colName) . '\''
|
||||
. ', col_length = \'' . $this->dbi->escapeString($colLength) . '\''
|
||||
. ', col_isNull = ' . $colIsNull
|
||||
. ', col_collation = \'' . $this->dbi->escapeString($collation) . '\''
|
||||
. ', col_extra = \''
|
||||
. implode(',', [$col_extra, $col_attribute]) . '\''
|
||||
. ', col_default = \'' . $this->dbi->escapeString($col_default) . '\''
|
||||
. implode(',', [$colExtra, $colAttribute]) . '\''
|
||||
. ', col_default = \'' . $this->dbi->escapeString($colDefault) . '\''
|
||||
. ' WHERE db_name = \'' . $this->dbi->escapeString($db) . '\' '
|
||||
. 'AND col_name = \'' . $this->dbi->escapeString($orig_col_name)
|
||||
. 'AND col_name = \'' . $this->dbi->escapeString($origColName)
|
||||
. '\'';
|
||||
}
|
||||
|
||||
@ -669,13 +669,13 @@ class CentralColumns
|
||||
/**
|
||||
* build html for editing a row in central columns table
|
||||
*
|
||||
* @param array $row array contains complete information of a
|
||||
* particular row of central list table
|
||||
* @param int $row_num position the row in the table
|
||||
* @param array $row array contains complete information of a
|
||||
* particular row of central list table
|
||||
* @param int $rowNum position the row in the table
|
||||
*
|
||||
* @return string html of a particular row in the central columns table.
|
||||
*/
|
||||
private function getHtmlForEditTableRow(array $row, int $row_num): string
|
||||
private function getHtmlForEditTableRow(array $row, int $rowNum): string
|
||||
{
|
||||
$meta = [];
|
||||
if (! isset($row['col_default']) || $row['col_default'] == '') {
|
||||
@ -707,7 +707,7 @@ class CentralColumns
|
||||
$collations = Charsets::getCollations($this->dbi, $this->disableIs);
|
||||
|
||||
return $this->template->render('database/central_columns/edit_table_row', [
|
||||
'row_num' => $row_num,
|
||||
'row_num' => $rowNum,
|
||||
'row' => $row,
|
||||
'max_rows' => $this->maxRows,
|
||||
'meta' => $meta,
|
||||
@ -744,8 +744,8 @@ class CentralColumns
|
||||
$this->dbi->selectDb($db);
|
||||
$columns = $this->dbi->getColumnNames($db, $table);
|
||||
$cols = '';
|
||||
foreach ($columns as $col_select) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($col_select) . '\',';
|
||||
foreach ($columns as $colSelect) {
|
||||
$cols .= '\'' . $this->dbi->escapeString($colSelect) . '\',';
|
||||
}
|
||||
|
||||
$cols = trim($cols, ',');
|
||||
@ -759,21 +759,21 @@ class CentralColumns
|
||||
}
|
||||
|
||||
$this->dbi->selectDb($cfgCentralColumns['db'], Connection::TYPE_CONTROL);
|
||||
$columns_list = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($columns_list);
|
||||
$columnsList = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
$this->handleColumnExtra($columnsList);
|
||||
|
||||
return $columns_list;
|
||||
return $columnsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column `col_extra` is used to store both extra and attributes for a column.
|
||||
* This method separates them.
|
||||
*
|
||||
* @param array $columns_list columns list
|
||||
* @param array $columnsList columns list
|
||||
*/
|
||||
private function handleColumnExtra(array &$columns_list): void
|
||||
private function handleColumnExtra(array &$columnsList): void
|
||||
{
|
||||
foreach ($columns_list as &$row) {
|
||||
foreach ($columnsList as &$row) {
|
||||
$vals = explode(',', $row['col_extra']);
|
||||
|
||||
if (in_array('BINARY', $vals)) {
|
||||
@ -799,27 +799,27 @@ class CentralColumns
|
||||
/**
|
||||
* Get HTML for editing page central columns
|
||||
*
|
||||
* @param array $selected_fld Array containing the selected fields
|
||||
* @param string $selected_db String containing the name of database
|
||||
* @param array $selectedFld Array containing the selected fields
|
||||
* @param string $selectedDb String containing the name of database
|
||||
*
|
||||
* @return string HTML for complete editing page for central columns
|
||||
*/
|
||||
public function getHtmlForEditingPage(array $selected_fld, string $selected_db): string
|
||||
public function getHtmlForEditingPage(array $selectedFld, string $selectedDb): string
|
||||
{
|
||||
$html = '';
|
||||
$selected_fld_safe = [];
|
||||
foreach ($selected_fld as $key) {
|
||||
$selected_fld_safe[] = $this->dbi->escapeString($key);
|
||||
$selectedFldSafe = [];
|
||||
foreach ($selectedFld as $key) {
|
||||
$selectedFldSafe[] = $this->dbi->escapeString($key);
|
||||
}
|
||||
|
||||
$columns_list = implode("','", $selected_fld_safe);
|
||||
$columns_list = "'" . $columns_list . "'";
|
||||
$list_detail_cols = $this->findExistingColNames($selected_db, $columns_list, true);
|
||||
$row_num = 0;
|
||||
foreach ($list_detail_cols as $row) {
|
||||
$tableHtmlRow = $this->getHtmlForEditTableRow($row, $row_num);
|
||||
$columnsList = implode("','", $selectedFldSafe);
|
||||
$columnsList = "'" . $columnsList . "'";
|
||||
$listDetailCols = $this->findExistingColNames($selectedDb, $columnsList, true);
|
||||
$rowNum = 0;
|
||||
foreach ($listDetailCols as $row) {
|
||||
$tableHtmlRow = $this->getHtmlForEditTableRow($row, $rowNum);
|
||||
$html .= $tableHtmlRow;
|
||||
$row_num++;
|
||||
$rowNum++;
|
||||
}
|
||||
|
||||
return $html;
|
||||
@ -845,9 +845,9 @@ class CentralColumns
|
||||
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$this->dbi->selectDb($pmadb, Connection::TYPE_CONTROL);
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$centralListTable = $cfgCentralColumns['table'];
|
||||
//get current values of $db from central column list
|
||||
$query = 'SELECT COUNT(db_name) FROM ' . Util::backquote($central_list_table) . ' '
|
||||
$query = 'SELECT COUNT(db_name) FROM ' . Util::backquote($centralListTable) . ' '
|
||||
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\''
|
||||
. ($num === 0 ? '' : 'LIMIT ' . $from . ', ' . $num) . ';';
|
||||
$result = $this->dbi->fetchResult($query, null, null, Connection::TYPE_CONTROL);
|
||||
@ -873,66 +873,66 @@ class CentralColumns
|
||||
/**
|
||||
* Adding a new user defined column to central list
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param int $total_rows number of rows in central columns
|
||||
* @param int $pos offset of first result with complete result set
|
||||
* @param string $text_dir table footer arrow direction
|
||||
* @param string $db current database
|
||||
* @param int $totalRows number of rows in central columns
|
||||
* @param int $pos offset of first result with complete result set
|
||||
* @param string $textDir table footer arrow direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateVariablesForMain(
|
||||
string $db,
|
||||
int $total_rows,
|
||||
int $totalRows,
|
||||
int $pos,
|
||||
string $text_dir,
|
||||
string $textDir,
|
||||
): array {
|
||||
$max_rows = $this->maxRows;
|
||||
$attribute_types = $this->dbi->types->getAttributes();
|
||||
$maxRows = $this->maxRows;
|
||||
$attributeTypes = $this->dbi->types->getAttributes();
|
||||
|
||||
$tn_pageNow = ($pos / $this->maxRows) + 1;
|
||||
$tn_nbTotalPage = (int) ceil($total_rows / $this->maxRows);
|
||||
$tn_page_selector = $tn_nbTotalPage > 1 ? Util::pageselector(
|
||||
$tnPageNow = ($pos / $this->maxRows) + 1;
|
||||
$tnNbTotalPage = (int) ceil($totalRows / $this->maxRows);
|
||||
$tnPageSelector = $tnNbTotalPage > 1 ? Util::pageselector(
|
||||
'pos',
|
||||
$this->maxRows,
|
||||
$tn_pageNow,
|
||||
$tn_nbTotalPage,
|
||||
$tnPageNow,
|
||||
$tnNbTotalPage,
|
||||
) : '';
|
||||
$this->dbi->selectDb($db);
|
||||
$tables = $this->dbi->getTables($db);
|
||||
$rows_list = $this->getColumnsList($db, $pos, $max_rows);
|
||||
$rowsList = $this->getColumnsList($db, $pos, $maxRows);
|
||||
|
||||
$defaultValues = [];
|
||||
$rows_meta = [];
|
||||
$types_upper = [];
|
||||
$row_num = 0;
|
||||
foreach ($rows_list as $row) {
|
||||
$rows_meta[$row_num] = [];
|
||||
$rowsMeta = [];
|
||||
$typesUpper = [];
|
||||
$rowNum = 0;
|
||||
foreach ($rowsList as $row) {
|
||||
$rowsMeta[$rowNum] = [];
|
||||
if (! isset($row['col_default']) || $row['col_default'] == '') {
|
||||
$rows_meta[$row_num]['DefaultType'] = 'NONE';
|
||||
$rowsMeta[$rowNum]['DefaultType'] = 'NONE';
|
||||
} elseif ($row['col_default'] === 'CURRENT_TIMESTAMP' || $row['col_default'] === 'current_timestamp()') {
|
||||
$rows_meta[$row_num]['DefaultType'] = 'CURRENT_TIMESTAMP';
|
||||
$rowsMeta[$rowNum]['DefaultType'] = 'CURRENT_TIMESTAMP';
|
||||
} elseif ($row['col_default'] == 'NULL') {
|
||||
$rows_meta[$row_num]['DefaultType'] = $row['col_default'];
|
||||
$rowsMeta[$rowNum]['DefaultType'] = $row['col_default'];
|
||||
} else {
|
||||
$rows_meta[$row_num]['DefaultType'] = 'USER_DEFINED';
|
||||
$rows_meta[$row_num]['DefaultValue'] = $row['col_default'];
|
||||
$rowsMeta[$rowNum]['DefaultType'] = 'USER_DEFINED';
|
||||
$rowsMeta[$rowNum]['DefaultValue'] = $row['col_default'];
|
||||
}
|
||||
|
||||
$types_upper[$row_num] = mb_strtoupper((string) $row['col_type']);
|
||||
$typesUpper[$rowNum] = mb_strtoupper((string) $row['col_type']);
|
||||
|
||||
// For a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
|
||||
$defaultValues[$row_num] = '';
|
||||
if (isset($rows_meta[$row_num]['DefaultValue'])) {
|
||||
$defaultValues[$row_num] = $rows_meta[$row_num]['DefaultValue'];
|
||||
$defaultValues[$rowNum] = '';
|
||||
if (isset($rowsMeta[$rowNum]['DefaultValue'])) {
|
||||
$defaultValues[$rowNum] = $rowsMeta[$rowNum]['DefaultValue'];
|
||||
|
||||
if ($types_upper[$row_num] === 'BIT') {
|
||||
$defaultValues[$row_num] = Util::convertBitDefaultValue($rows_meta[$row_num]['DefaultValue']);
|
||||
} elseif ($types_upper[$row_num] === 'BINARY' || $types_upper[$row_num] === 'VARBINARY') {
|
||||
$defaultValues[$row_num] = bin2hex($rows_meta[$row_num]['DefaultValue']);
|
||||
if ($typesUpper[$rowNum] === 'BIT') {
|
||||
$defaultValues[$rowNum] = Util::convertBitDefaultValue($rowsMeta[$rowNum]['DefaultValue']);
|
||||
} elseif ($typesUpper[$rowNum] === 'BINARY' || $typesUpper[$rowNum] === 'VARBINARY') {
|
||||
$defaultValues[$rowNum] = bin2hex($rowsMeta[$rowNum]['DefaultValue']);
|
||||
}
|
||||
}
|
||||
|
||||
$row_num++;
|
||||
$rowNum++;
|
||||
}
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $this->disableIs);
|
||||
@ -956,19 +956,19 @@ class CentralColumns
|
||||
|
||||
return [
|
||||
'db' => $db,
|
||||
'total_rows' => $total_rows,
|
||||
'max_rows' => $max_rows,
|
||||
'total_rows' => $totalRows,
|
||||
'max_rows' => $maxRows,
|
||||
'pos' => $pos,
|
||||
'char_editing' => $this->charEditing,
|
||||
'attribute_types' => $attribute_types,
|
||||
'tn_nbTotalPage' => $tn_nbTotalPage,
|
||||
'tn_page_selector' => $tn_page_selector,
|
||||
'attribute_types' => $attributeTypes,
|
||||
'tn_nbTotalPage' => $tnNbTotalPage,
|
||||
'tn_page_selector' => $tnPageSelector,
|
||||
'tables' => $tables,
|
||||
'rows_list' => $rows_list,
|
||||
'rows_meta' => $rows_meta,
|
||||
'rows_list' => $rowsList,
|
||||
'rows_meta' => $rowsMeta,
|
||||
'default_values' => $defaultValues,
|
||||
'types_upper' => $types_upper,
|
||||
'text_dir' => $text_dir,
|
||||
'types_upper' => $typesUpper,
|
||||
'text_dir' => $textDir,
|
||||
'charsets' => $charsetsList,
|
||||
];
|
||||
}
|
||||
|
||||
@ -82,20 +82,20 @@ class Designer
|
||||
return [];
|
||||
}
|
||||
|
||||
$page_query = 'SELECT `page_nr`, `page_descr` FROM '
|
||||
$pageQuery = 'SELECT `page_nr`, `page_descr` FROM '
|
||||
. Util::backquote($pdfFeature->database) . '.'
|
||||
. Util::backquote($pdfFeature->pdfPages)
|
||||
. " WHERE db_name = '" . $this->dbi->escapeString($db) . "'"
|
||||
. ' ORDER BY `page_descr`';
|
||||
$page_rs = $this->dbi->tryQueryAsControlUser($page_query);
|
||||
$pageRs = $this->dbi->tryQueryAsControlUser($pageQuery);
|
||||
|
||||
if (! $page_rs) {
|
||||
if (! $pageRs) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
while ($curr_page = $page_rs->fetchAssoc()) {
|
||||
$result[intval($curr_page['page_nr'])] = $curr_page['page_descr'];
|
||||
while ($currPage = $pageRs->fetchAssoc()) {
|
||||
$result[intval($currPage['page_nr'])] = $currPage['page_descr'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -109,10 +109,10 @@ class Designer
|
||||
*/
|
||||
public function getHtmlForSchemaExport(string $db, int $page): string
|
||||
{
|
||||
$export_list = Plugins::getSchema();
|
||||
$exportList = Plugins::getSchema();
|
||||
|
||||
/* Fail if we didn't find any schema plugin */
|
||||
if ($export_list === []) {
|
||||
if ($exportList === []) {
|
||||
return Message::error(
|
||||
__('Could not load schema plugins, please check your installation!'),
|
||||
)->getDisplay();
|
||||
@ -121,8 +121,8 @@ class Designer
|
||||
$default = isset($_GET['export_type'])
|
||||
? (string) $_GET['export_type']
|
||||
: Plugins::getDefault('Schema', 'format');
|
||||
$choice = Plugins::getChoice($export_list, $default);
|
||||
$options = Plugins::getOptions('Schema', $export_list);
|
||||
$choice = Plugins::getChoice($exportList, $default);
|
||||
$options = Plugins::getOptions('Schema', $exportList);
|
||||
|
||||
return $this->template->render('database/designer/schema_export', [
|
||||
'db' => $db,
|
||||
@ -166,100 +166,100 @@ class Designer
|
||||
*/
|
||||
public function returnClassNamesFromMenuButtons(): array
|
||||
{
|
||||
$classes_array = [];
|
||||
$params_array = $this->getSideMenuParamsArray();
|
||||
$classesArray = [];
|
||||
$paramsArray = $this->getSideMenuParamsArray();
|
||||
|
||||
if (isset($params_array['angular_direct']) && $params_array['angular_direct'] === 'angular') {
|
||||
$classes_array['angular_direct'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['angular_direct']) && $paramsArray['angular_direct'] === 'angular') {
|
||||
$classesArray['angular_direct'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['angular_direct'] = 'M_butt';
|
||||
$classesArray['angular_direct'] = 'M_butt';
|
||||
}
|
||||
|
||||
if (isset($params_array['snap_to_grid']) && $params_array['snap_to_grid'] === 'on') {
|
||||
$classes_array['snap_to_grid'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['snap_to_grid']) && $paramsArray['snap_to_grid'] === 'on') {
|
||||
$classesArray['snap_to_grid'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['snap_to_grid'] = 'M_butt';
|
||||
$classesArray['snap_to_grid'] = 'M_butt';
|
||||
}
|
||||
|
||||
if (isset($params_array['pin_text']) && $params_array['pin_text'] === 'true') {
|
||||
$classes_array['pin_text'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['pin_text']) && $paramsArray['pin_text'] === 'true') {
|
||||
$classesArray['pin_text'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['pin_text'] = 'M_butt';
|
||||
$classesArray['pin_text'] = 'M_butt';
|
||||
}
|
||||
|
||||
if (isset($params_array['relation_lines']) && $params_array['relation_lines'] === 'false') {
|
||||
$classes_array['relation_lines'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['relation_lines']) && $paramsArray['relation_lines'] === 'false') {
|
||||
$classesArray['relation_lines'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['relation_lines'] = 'M_butt';
|
||||
$classesArray['relation_lines'] = 'M_butt';
|
||||
}
|
||||
|
||||
if (isset($params_array['small_big_all']) && $params_array['small_big_all'] === 'v') {
|
||||
$classes_array['small_big_all'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['small_big_all']) && $paramsArray['small_big_all'] === 'v') {
|
||||
$classesArray['small_big_all'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['small_big_all'] = 'M_butt';
|
||||
$classesArray['small_big_all'] = 'M_butt';
|
||||
}
|
||||
|
||||
if (isset($params_array['side_menu']) && $params_array['side_menu'] === 'true') {
|
||||
$classes_array['side_menu'] = 'M_butt_Selected_down';
|
||||
if (isset($paramsArray['side_menu']) && $paramsArray['side_menu'] === 'true') {
|
||||
$classesArray['side_menu'] = 'M_butt_Selected_down';
|
||||
} else {
|
||||
$classes_array['side_menu'] = 'M_butt';
|
||||
$classesArray['side_menu'] = 'M_butt';
|
||||
}
|
||||
|
||||
return $classes_array;
|
||||
return $classesArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML to display tables on designer page
|
||||
*
|
||||
* @param string $db The database name from the request
|
||||
* @param DesignerTable[] $designerTables The designer tables
|
||||
* @param array $tab_pos tables positions
|
||||
* @param int $display_page page number of the selected page
|
||||
* @param array $tab_column table column info
|
||||
* @param array $tables_all_keys all indices
|
||||
* @param array $tables_pk_or_unique_keys unique or primary indices
|
||||
* @param string $db The database name from the request
|
||||
* @param DesignerTable[] $designerTables The designer tables
|
||||
* @param array $tabPos tables positions
|
||||
* @param int $displayPage page number of the selected page
|
||||
* @param array $tabColumn table column info
|
||||
* @param array $tablesAllKeys all indices
|
||||
* @param array $tablesPkOrUniqueKeys unique or primary indices
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public function getDatabaseTables(
|
||||
string $db,
|
||||
array $designerTables,
|
||||
array $tab_pos,
|
||||
int $display_page,
|
||||
array $tab_column,
|
||||
array $tables_all_keys,
|
||||
array $tables_pk_or_unique_keys,
|
||||
array $tabPos,
|
||||
int $displayPage,
|
||||
array $tabColumn,
|
||||
array $tablesAllKeys,
|
||||
array $tablesPkOrUniqueKeys,
|
||||
): string {
|
||||
$GLOBALS['text_dir'] ??= null;
|
||||
|
||||
$columns_type = [];
|
||||
$columnsType = [];
|
||||
foreach ($designerTables as $designerTable) {
|
||||
$table_name = $designerTable->getDbTableString();
|
||||
$limit = count($tab_column[$table_name]['COLUMN_ID']);
|
||||
$tableName = $designerTable->getDbTableString();
|
||||
$limit = count($tabColumn[$tableName]['COLUMN_ID']);
|
||||
for ($j = 0; $j < $limit; $j++) {
|
||||
$table_column_name = $table_name . '.' . $tab_column[$table_name]['COLUMN_NAME'][$j];
|
||||
if (isset($tables_pk_or_unique_keys[$table_column_name])) {
|
||||
$columns_type[$table_column_name] = 'designer/FieldKey_small';
|
||||
$tableColumnName = $tableName . '.' . $tabColumn[$tableName]['COLUMN_NAME'][$j];
|
||||
if (isset($tablesPkOrUniqueKeys[$tableColumnName])) {
|
||||
$columnsType[$tableColumnName] = 'designer/FieldKey_small';
|
||||
} else {
|
||||
$columns_type[$table_column_name] = 'designer/Field_small';
|
||||
$columnsType[$tableColumnName] = 'designer/Field_small';
|
||||
if (
|
||||
str_contains($tab_column[$table_name]['TYPE'][$j], 'char')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'text')
|
||||
str_contains($tabColumn[$tableName]['TYPE'][$j], 'char')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'text')
|
||||
) {
|
||||
$columns_type[$table_column_name] .= '_char';
|
||||
$columnsType[$tableColumnName] .= '_char';
|
||||
} elseif (
|
||||
str_contains($tab_column[$table_name]['TYPE'][$j], 'int')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'float')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'double')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'decimal')
|
||||
str_contains($tabColumn[$tableName]['TYPE'][$j], 'int')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'float')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'double')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'decimal')
|
||||
) {
|
||||
$columns_type[$table_column_name] .= '_int';
|
||||
$columnsType[$tableColumnName] .= '_int';
|
||||
} elseif (
|
||||
str_contains($tab_column[$table_name]['TYPE'][$j], 'date')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'time')
|
||||
|| str_contains($tab_column[$table_name]['TYPE'][$j], 'year')
|
||||
str_contains($tabColumn[$tableName]['TYPE'][$j], 'date')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'time')
|
||||
|| str_contains($tabColumn[$tableName]['TYPE'][$j], 'year')
|
||||
) {
|
||||
$columns_type[$table_column_name] .= '_date';
|
||||
$columnsType[$tableColumnName] .= '_date';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -270,13 +270,13 @@ class Designer
|
||||
'text_dir' => $GLOBALS['text_dir'],
|
||||
'get_db' => $db,
|
||||
'has_query' => isset($_REQUEST['query']),
|
||||
'tab_pos' => $tab_pos,
|
||||
'display_page' => $display_page,
|
||||
'tab_column' => $tab_column,
|
||||
'tables_all_keys' => $tables_all_keys,
|
||||
'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys,
|
||||
'tab_pos' => $tabPos,
|
||||
'display_page' => $displayPage,
|
||||
'tab_column' => $tabColumn,
|
||||
'tables_all_keys' => $tablesAllKeys,
|
||||
'tables_pk_or_unique_keys' => $tablesPkOrUniqueKeys,
|
||||
'tables' => $designerTables,
|
||||
'columns_type' => $columns_type,
|
||||
'columns_type' => $columnsType,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -56,15 +56,15 @@ class Common
|
||||
$tables = $this->dbi->getTablesFull($db, $table);
|
||||
}
|
||||
|
||||
foreach ($tables as $one_table) {
|
||||
$DF = $this->relation->getDisplayField($db, $one_table['TABLE_NAME']);
|
||||
$DF = is_string($DF) ? $DF : '';
|
||||
$DF = $DF !== '' ? $DF : null;
|
||||
foreach ($tables as $oneTable) {
|
||||
$df = $this->relation->getDisplayField($db, $oneTable['TABLE_NAME']);
|
||||
$df = is_string($df) ? $df : '';
|
||||
$df = $df !== '' ? $df : null;
|
||||
$designerTables[] = new DesignerTable(
|
||||
$db,
|
||||
$one_table['TABLE_NAME'],
|
||||
is_string($one_table['ENGINE']) ? $one_table['ENGINE'] : '',
|
||||
$DF,
|
||||
$oneTable['TABLE_NAME'],
|
||||
is_string($oneTable['ENGINE']) ? $oneTable['ENGINE'] : '',
|
||||
$df,
|
||||
);
|
||||
}
|
||||
|
||||
@ -120,8 +120,8 @@ class Common
|
||||
/** @var array{C_NAME: string[], DTN: string[], DCN: string[], STN: string[], SCN: string[]} $con */
|
||||
$con = ['C_NAME' => [], 'DTN' => [], 'DCN' => [], 'STN' => [], 'SCN' => []];
|
||||
$i = 0;
|
||||
$alltab_rs = $this->dbi->query('SHOW TABLES FROM ' . Util::backquote($GLOBALS['db']));
|
||||
while ($val = $alltab_rs->fetchRow()) {
|
||||
$allTabRs = $this->dbi->query('SHOW TABLES FROM ' . Util::backquote($GLOBALS['db']));
|
||||
while ($val = $allTabRs->fetchRow()) {
|
||||
$val = (string) $val[0];
|
||||
|
||||
$row = $this->relation->getForeigners($GLOBALS['db'], $val, '', 'internal');
|
||||
@ -142,16 +142,16 @@ class Common
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($row['foreign_keys_data'] as $one_key) {
|
||||
foreach ($one_key['index_list'] as $index => $one_field) {
|
||||
$con['C_NAME'][$i] = rawurlencode($one_key['constraint']);
|
||||
foreach ($row['foreign_keys_data'] as $oneKey) {
|
||||
foreach ($oneKey['index_list'] as $index => $oneField) {
|
||||
$con['C_NAME'][$i] = rawurlencode($oneKey['constraint']);
|
||||
$con['DTN'][$i] = rawurlencode($GLOBALS['db'] . '.' . $val);
|
||||
$con['DCN'][$i] = rawurlencode($one_field);
|
||||
$con['DCN'][$i] = rawurlencode($oneField);
|
||||
$con['STN'][$i] = rawurlencode(
|
||||
($one_key['ref_db_name'] ?? $GLOBALS['db'])
|
||||
. '.' . $one_key['ref_table_name'],
|
||||
($oneKey['ref_db_name'] ?? $GLOBALS['db'])
|
||||
. '.' . $oneKey['ref_table_name'],
|
||||
);
|
||||
$con['SCN'][$i] = rawurlencode($one_key['ref_index_list'][$index]);
|
||||
$con['SCN'][$i] = rawurlencode($oneKey['ref_index_list'][$index]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
@ -165,13 +165,13 @@ class Common
|
||||
$ti = 0;
|
||||
$retval = [];
|
||||
for ($i = 0, $cnt = count($con['C_NAME']); $i < $cnt; $i++) {
|
||||
$c_name_i = $con['C_NAME'][$i];
|
||||
$dtn_i = $con['DTN'][$i];
|
||||
$cNameI = $con['C_NAME'][$i];
|
||||
$dtnI = $con['DTN'][$i];
|
||||
$retval[$ti] = [];
|
||||
$retval[$ti][$c_name_i] = [];
|
||||
if (in_array($dtn_i, $tableDbNames) && in_array($con['STN'][$i], $tableDbNames)) {
|
||||
$retval[$ti][$c_name_i][$dtn_i] = [];
|
||||
$retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = [
|
||||
$retval[$ti][$cNameI] = [];
|
||||
if (in_array($dtnI, $tableDbNames) && in_array($con['STN'][$i], $tableDbNames)) {
|
||||
$retval[$ti][$cNameI][$dtnI] = [];
|
||||
$retval[$ti][$cNameI][$dtnI][$con['DCN'][$i]] = [
|
||||
0 => $con['STN'][$i],
|
||||
1 => $con['SCN'][$i],
|
||||
];
|
||||
@ -199,11 +199,11 @@ class Common
|
||||
* Returns all indices
|
||||
*
|
||||
* @param DesignerTable[] $designerTables The designer tables
|
||||
* @param bool $unique_only whether to include only unique ones
|
||||
* @param bool $uniqueOnly whether to include only unique ones
|
||||
*
|
||||
* @return array indices
|
||||
*/
|
||||
public function getAllKeys(array $designerTables, bool $unique_only = false): array
|
||||
public function getAllKeys(array $designerTables, bool $uniqueOnly = false): array
|
||||
{
|
||||
$keys = [];
|
||||
|
||||
@ -211,13 +211,13 @@ class Common
|
||||
$schema = $designerTable->getDatabaseName();
|
||||
// for now, take into account only the first index segment
|
||||
foreach (Index::getFromTable($this->dbi, $designerTable->getTableName(), $schema) as $index) {
|
||||
if ($unique_only && ! $index->isUnique()) {
|
||||
if ($uniqueOnly && ! $index->isUnique()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = $index->getColumns();
|
||||
foreach (array_keys($columns) as $column_name) {
|
||||
$keys[$schema . '.' . $designerTable->getTableName() . '.' . $column_name] = 1;
|
||||
foreach (array_keys($columns) as $columnName) {
|
||||
$keys[$schema . '.' . $designerTable->getTableName() . '.' . $columnName] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -299,13 +299,13 @@ class Common
|
||||
. ' FROM ' . Util::backquote($pdfFeature->database)
|
||||
. '.' . Util::backquote($pdfFeature->pdfPages)
|
||||
. ' WHERE ' . Util::backquote('page_nr') . ' = ' . $pg;
|
||||
$page_name = $this->dbi->fetchValue(
|
||||
$pageName = $this->dbi->fetchValue(
|
||||
$query,
|
||||
0,
|
||||
Connection::TYPE_CONTROL,
|
||||
);
|
||||
|
||||
return $page_name !== false ? $page_name : null;
|
||||
return $pageName !== false ? $pageName : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,13 +354,13 @@ class Common
|
||||
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'"
|
||||
. " AND `page_descr` = '" . $this->dbi->escapeString($db) . "'";
|
||||
|
||||
$default_page_no = $this->dbi->fetchValue(
|
||||
$defaultPageNo = $this->dbi->fetchValue(
|
||||
$query,
|
||||
0,
|
||||
Connection::TYPE_CONTROL,
|
||||
);
|
||||
|
||||
return is_string($default_page_no) ? intval($default_page_no) : -1;
|
||||
return is_string($defaultPageNo) ? intval($defaultPageNo) : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -405,9 +405,9 @@ class Common
|
||||
return -1;
|
||||
}
|
||||
|
||||
$default_page_no = $this->getDefaultPage($db);
|
||||
if ($default_page_no != -1) {
|
||||
return $default_page_no;
|
||||
$defaultPageNo = $this->getDefaultPage($db);
|
||||
if ($defaultPageNo != -1) {
|
||||
return $defaultPageNo;
|
||||
}
|
||||
|
||||
$query = 'SELECT MIN(`page_nr`)'
|
||||
@ -415,13 +415,13 @@ class Common
|
||||
. '.' . Util::backquote($pdfFeature->pdfPages)
|
||||
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'";
|
||||
|
||||
$min_page_no = $this->dbi->fetchValue(
|
||||
$minPageNo = $this->dbi->fetchValue(
|
||||
$query,
|
||||
0,
|
||||
Connection::TYPE_CONTROL,
|
||||
);
|
||||
|
||||
return is_string($min_page_no) ? intval($min_page_no) : -1;
|
||||
return is_string($minPageNo) ? intval($minPageNo) : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,8 +462,8 @@ class Common
|
||||
$this->dbi->queryAsControlUser($query);
|
||||
|
||||
foreach ($_POST['t_h'] as $key => $value) {
|
||||
$DB = $_POST['t_db'][$key];
|
||||
$TAB = $_POST['t_tbl'][$key];
|
||||
$db = $_POST['t_db'][$key];
|
||||
$tab = $_POST['t_tbl'][$key];
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
@ -473,8 +473,8 @@ class Common
|
||||
. Util::backquote($pdfFeature->tableCoords)
|
||||
. ' (`db_name`, `table_name`, `pdf_page_number`, `x`, `y`)'
|
||||
. ' VALUES ('
|
||||
. "'" . $this->dbi->escapeString($DB) . "', "
|
||||
. "'" . $this->dbi->escapeString($TAB) . "', "
|
||||
. "'" . $this->dbi->escapeString($db) . "', "
|
||||
. "'" . $this->dbi->escapeString($tab) . "', "
|
||||
. "'" . $pageId . "', "
|
||||
. "'" . $this->dbi->escapeString($_POST['t_x'][$key]) . "', "
|
||||
. "'" . $this->dbi->escapeString($_POST['t_y'][$key]) . "')";
|
||||
@ -509,8 +509,8 @@ class Common
|
||||
];
|
||||
}
|
||||
|
||||
$upd_query = new Table($table, $db, $this->dbi);
|
||||
$upd_query->updateDisplayField($field, $displayFeature);
|
||||
$updQuery = new Table($table, $db, $this->dbi);
|
||||
$updQuery->updateDisplayField($field, $displayFeature);
|
||||
|
||||
return [
|
||||
true,
|
||||
@ -521,40 +521,40 @@ class Common
|
||||
/**
|
||||
* Adds a new foreign relation
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $T1 foreign table
|
||||
* @param string $F1 foreign field
|
||||
* @param string $T2 master table
|
||||
* @param string $F2 master field
|
||||
* @param string $on_delete on delete action
|
||||
* @param string $on_update on update action
|
||||
* @param string $DB1 database
|
||||
* @param string $DB2 database
|
||||
* @param string $db database name
|
||||
* @param string $t1 foreign table
|
||||
* @param string $f1 foreign field
|
||||
* @param string $t2 master table
|
||||
* @param string $f2 master field
|
||||
* @param string $onDelete on delete action
|
||||
* @param string $onUpdate on update action
|
||||
* @param string $db1 database
|
||||
* @param string $db2 database
|
||||
*
|
||||
* @return array<int,string|bool> array of success/failure and message
|
||||
* @psalm-return array{0: bool, 1: string}
|
||||
*/
|
||||
public function addNewRelation(
|
||||
string $db,
|
||||
string $T1,
|
||||
string $F1,
|
||||
string $T2,
|
||||
string $F2,
|
||||
string $on_delete,
|
||||
string $on_update,
|
||||
string $DB1,
|
||||
string $DB2,
|
||||
string $t1,
|
||||
string $f1,
|
||||
string $t2,
|
||||
string $f2,
|
||||
string $onDelete,
|
||||
string $onUpdate,
|
||||
string $db1,
|
||||
string $db2,
|
||||
): array {
|
||||
$tables = $this->dbi->getTablesFull($DB1, $T1);
|
||||
$type_T1 = mb_strtoupper($tables[$T1]['ENGINE'] ?? '');
|
||||
$tables = $this->dbi->getTablesFull($DB2, $T2);
|
||||
$type_T2 = mb_strtoupper($tables[$T2]['ENGINE'] ?? '');
|
||||
$tables = $this->dbi->getTablesFull($db1, $t1);
|
||||
$typeT1 = mb_strtoupper($tables[$t1]['ENGINE'] ?? '');
|
||||
$tables = $this->dbi->getTablesFull($db2, $t2);
|
||||
$typeT2 = mb_strtoupper($tables[$t2]['ENGINE'] ?? '');
|
||||
|
||||
// native foreign key
|
||||
if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 === $type_T2) {
|
||||
if (ForeignKey::isSupported($typeT1) && ForeignKey::isSupported($typeT2) && $typeT1 === $typeT2) {
|
||||
// relation exists?
|
||||
$existrel_foreign = $this->relation->getForeigners($DB2, $T2, '', 'foreign');
|
||||
$foreigner = $this->relation->searchColumnInForeigners($existrel_foreign, $F2);
|
||||
$existRelForeign = $this->relation->getForeigners($db2, $t2, '', 'foreign');
|
||||
$foreigner = $this->relation->searchColumnInForeigners($existRelForeign, $f2);
|
||||
if ($foreigner && isset($foreigner['constraint'])) {
|
||||
return [
|
||||
false,
|
||||
@ -566,48 +566,48 @@ class Common
|
||||
// or UNIQUE key
|
||||
// improve: check all other requirements for InnoDB relations
|
||||
$result = $this->dbi->query(
|
||||
'SHOW INDEX FROM ' . Util::backquote($DB1)
|
||||
. '.' . Util::backquote($T1) . ';',
|
||||
'SHOW INDEX FROM ' . Util::backquote($db1)
|
||||
. '.' . Util::backquote($t1) . ';',
|
||||
);
|
||||
|
||||
// will be use to emphasis prim. keys in the table view
|
||||
$index_array1 = [];
|
||||
$indexArray1 = [];
|
||||
while ($row = $result->fetchAssoc()) {
|
||||
$index_array1[$row['Column_name']] = 1;
|
||||
$indexArray1[$row['Column_name']] = 1;
|
||||
}
|
||||
|
||||
$result = $this->dbi->query(
|
||||
'SHOW INDEX FROM ' . Util::backquote($DB2)
|
||||
. '.' . Util::backquote($T2) . ';',
|
||||
'SHOW INDEX FROM ' . Util::backquote($db2)
|
||||
. '.' . Util::backquote($t2) . ';',
|
||||
);
|
||||
// will be used to emphasis prim. keys in the table view
|
||||
$index_array2 = [];
|
||||
$indexArray2 = [];
|
||||
while ($row = $result->fetchAssoc()) {
|
||||
$index_array2[$row['Column_name']] = 1;
|
||||
$indexArray2[$row['Column_name']] = 1;
|
||||
}
|
||||
|
||||
unset($result);
|
||||
|
||||
if (! empty($index_array1[$F1]) && ! empty($index_array2[$F2])) {
|
||||
$upd_query = 'ALTER TABLE ' . Util::backquote($DB2)
|
||||
. '.' . Util::backquote($T2)
|
||||
if (! empty($indexArray1[$f1]) && ! empty($indexArray2[$f2])) {
|
||||
$updQuery = 'ALTER TABLE ' . Util::backquote($db2)
|
||||
. '.' . Util::backquote($t2)
|
||||
. ' ADD FOREIGN KEY ('
|
||||
. Util::backquote($F2) . ')'
|
||||
. Util::backquote($f2) . ')'
|
||||
. ' REFERENCES '
|
||||
. Util::backquote($DB1) . '.'
|
||||
. Util::backquote($T1) . '('
|
||||
. Util::backquote($F1) . ')';
|
||||
. Util::backquote($db1) . '.'
|
||||
. Util::backquote($t1) . '('
|
||||
. Util::backquote($f1) . ')';
|
||||
|
||||
if ($on_delete !== 'nix') {
|
||||
$upd_query .= ' ON DELETE ' . $on_delete;
|
||||
if ($onDelete !== 'nix') {
|
||||
$updQuery .= ' ON DELETE ' . $onDelete;
|
||||
}
|
||||
|
||||
if ($on_update !== 'nix') {
|
||||
$upd_query .= ' ON UPDATE ' . $on_update;
|
||||
if ($onUpdate !== 'nix') {
|
||||
$updQuery .= ' ON UPDATE ' . $onUpdate;
|
||||
}
|
||||
|
||||
$upd_query .= ';';
|
||||
if ($this->dbi->tryQuery($upd_query)) {
|
||||
$updQuery .= ';';
|
||||
if ($this->dbi->tryQuery($updQuery)) {
|
||||
return [
|
||||
true,
|
||||
__('FOREIGN KEY relationship has been added.'),
|
||||
@ -647,12 +647,12 @@ class Common
|
||||
. '(master_db, master_table, master_field, '
|
||||
. 'foreign_db, foreign_table, foreign_field)'
|
||||
. ' values('
|
||||
. "'" . $this->dbi->escapeString($DB2) . "', "
|
||||
. "'" . $this->dbi->escapeString($T2) . "', "
|
||||
. "'" . $this->dbi->escapeString($F2) . "', "
|
||||
. "'" . $this->dbi->escapeString($DB1) . "', "
|
||||
. "'" . $this->dbi->escapeString($T1) . "', "
|
||||
. "'" . $this->dbi->escapeString($F1) . "')";
|
||||
. "'" . $this->dbi->escapeString($db2) . "', "
|
||||
. "'" . $this->dbi->escapeString($t2) . "', "
|
||||
. "'" . $this->dbi->escapeString($f2) . "', "
|
||||
. "'" . $this->dbi->escapeString($db1) . "', "
|
||||
. "'" . $this->dbi->escapeString($t1) . "', "
|
||||
. "'" . $this->dbi->escapeString($f1) . "')";
|
||||
|
||||
if ($this->dbi->tryQueryAsControlUser($q)) {
|
||||
return [
|
||||
@ -673,33 +673,33 @@ class Common
|
||||
/**
|
||||
* Removes a foreign relation
|
||||
*
|
||||
* @param string $T1 foreign db.table
|
||||
* @param string $F1 foreign field
|
||||
* @param string $T2 master db.table
|
||||
* @param string $F2 master field
|
||||
* @param string $t1 foreign db.table
|
||||
* @param string $f1 foreign field
|
||||
* @param string $t2 master db.table
|
||||
* @param string $f2 master field
|
||||
*
|
||||
* @return array array of success/failure and message
|
||||
*/
|
||||
public function removeRelation(string $T1, string $F1, string $T2, string $F2): array
|
||||
public function removeRelation(string $t1, string $f1, string $t2, string $f2): array
|
||||
{
|
||||
[$DB1, $T1] = explode('.', $T1);
|
||||
[$DB2, $T2] = explode('.', $T2);
|
||||
[$db1, $t1] = explode('.', $t1);
|
||||
[$db2, $t2] = explode('.', $t2);
|
||||
|
||||
$tables = $this->dbi->getTablesFull($DB1, $T1);
|
||||
$type_T1 = mb_strtoupper($tables[$T1]['ENGINE']);
|
||||
$tables = $this->dbi->getTablesFull($DB2, $T2);
|
||||
$type_T2 = mb_strtoupper($tables[$T2]['ENGINE']);
|
||||
$tables = $this->dbi->getTablesFull($db1, $t1);
|
||||
$typeT1 = mb_strtoupper($tables[$t1]['ENGINE']);
|
||||
$tables = $this->dbi->getTablesFull($db2, $t2);
|
||||
$typeT2 = mb_strtoupper($tables[$t2]['ENGINE']);
|
||||
|
||||
if (ForeignKey::isSupported($type_T1) && ForeignKey::isSupported($type_T2) && $type_T1 === $type_T2) {
|
||||
if (ForeignKey::isSupported($typeT1) && ForeignKey::isSupported($typeT2) && $typeT1 === $typeT2) {
|
||||
// InnoDB
|
||||
$existrel_foreign = $this->relation->getForeigners($DB2, $T2, '', 'foreign');
|
||||
$foreigner = $this->relation->searchColumnInForeigners($existrel_foreign, $F2);
|
||||
$existRelForeign = $this->relation->getForeigners($db2, $t2, '', 'foreign');
|
||||
$foreigner = $this->relation->searchColumnInForeigners($existRelForeign, $f2);
|
||||
|
||||
if (is_array($foreigner) && isset($foreigner['constraint'])) {
|
||||
$upd_query = 'ALTER TABLE ' . Util::backquote($DB2)
|
||||
. '.' . Util::backquote($T2) . ' DROP FOREIGN KEY '
|
||||
$updQuery = 'ALTER TABLE ' . Util::backquote($db2)
|
||||
. '.' . Util::backquote($t2) . ' DROP FOREIGN KEY '
|
||||
. Util::backquote($foreigner['constraint']) . ';';
|
||||
$this->dbi->query($upd_query);
|
||||
$this->dbi->query($updQuery);
|
||||
|
||||
return [
|
||||
true,
|
||||
@ -717,17 +717,17 @@ class Common
|
||||
}
|
||||
|
||||
// internal relations
|
||||
$delete_query = 'DELETE FROM '
|
||||
$deleteQuery = 'DELETE FROM '
|
||||
. Util::backquote($relationFeature->database) . '.'
|
||||
. Util::backquote($relationFeature->relation) . ' WHERE '
|
||||
. "master_db = '" . $this->dbi->escapeString($DB2) . "'"
|
||||
. " AND master_table = '" . $this->dbi->escapeString($T2) . "'"
|
||||
. " AND master_field = '" . $this->dbi->escapeString($F2) . "'"
|
||||
. " AND foreign_db = '" . $this->dbi->escapeString($DB1) . "'"
|
||||
. " AND foreign_table = '" . $this->dbi->escapeString($T1) . "'"
|
||||
. " AND foreign_field = '" . $this->dbi->escapeString($F1) . "'";
|
||||
. "master_db = '" . $this->dbi->escapeString($db2) . "'"
|
||||
. " AND master_table = '" . $this->dbi->escapeString($t2) . "'"
|
||||
. " AND master_field = '" . $this->dbi->escapeString($f2) . "'"
|
||||
. " AND foreign_db = '" . $this->dbi->escapeString($db1) . "'"
|
||||
. " AND foreign_table = '" . $this->dbi->escapeString($t1) . "'"
|
||||
. " AND foreign_field = '" . $this->dbi->escapeString($f1) . "'";
|
||||
|
||||
$result = $this->dbi->tryQueryAsControlUser($delete_query);
|
||||
$result = $this->dbi->tryQueryAsControlUser($deleteQuery);
|
||||
|
||||
if (! $result) {
|
||||
$error = $this->dbi->getError(Connection::TYPE_CONTROL);
|
||||
@ -760,40 +760,40 @@ class Common
|
||||
'table' => $databaseDesignerSettingsFeature->designerSettings->getName(),
|
||||
];
|
||||
|
||||
$orig_data_query = 'SELECT settings_data'
|
||||
$origDataQuery = 'SELECT settings_data'
|
||||
. ' FROM ' . Util::backquote($cfgDesigner['db'])
|
||||
. '.' . Util::backquote($cfgDesigner['table'])
|
||||
. " WHERE username = '"
|
||||
. $this->dbi->escapeString($cfgDesigner['user']) . "';";
|
||||
|
||||
$orig_data = $this->dbi->fetchSingleRow(
|
||||
$orig_data_query,
|
||||
$origData = $this->dbi->fetchSingleRow(
|
||||
$origDataQuery,
|
||||
DatabaseInterface::FETCH_ASSOC,
|
||||
Connection::TYPE_CONTROL,
|
||||
);
|
||||
|
||||
if (! empty($orig_data)) {
|
||||
$orig_data = json_decode($orig_data['settings_data'], true);
|
||||
$orig_data[$index] = $value;
|
||||
$orig_data = json_encode($orig_data);
|
||||
if (! empty($origData)) {
|
||||
$origData = json_decode($origData['settings_data'], true);
|
||||
$origData[$index] = $value;
|
||||
$origData = json_encode($origData);
|
||||
|
||||
$save_query = 'UPDATE '
|
||||
$saveQuery = 'UPDATE '
|
||||
. Util::backquote($cfgDesigner['db'])
|
||||
. '.' . Util::backquote($cfgDesigner['table'])
|
||||
. " SET settings_data = '" . $orig_data . "'"
|
||||
. " SET settings_data = '" . $origData . "'"
|
||||
. " WHERE username = '"
|
||||
. $this->dbi->escapeString($cfgDesigner['user']) . "';";
|
||||
|
||||
$this->dbi->queryAsControlUser($save_query);
|
||||
$this->dbi->queryAsControlUser($saveQuery);
|
||||
} else {
|
||||
$save_data = [$index => $value];
|
||||
$saveData = [$index => $value];
|
||||
|
||||
$query = 'INSERT INTO '
|
||||
. Util::backquote($cfgDesigner['db'])
|
||||
. '.' . Util::backquote($cfgDesigner['table'])
|
||||
. ' (username, settings_data)'
|
||||
. " VALUES('" . $this->dbi->escapeString($cfgDesigner['user'])
|
||||
. "', '" . json_encode($save_data) . "');";
|
||||
. "', '" . json_encode($saveData) . "');";
|
||||
|
||||
$this->dbi->queryAsControlUser($query);
|
||||
}
|
||||
|
||||
@ -78,41 +78,41 @@ class Events
|
||||
$GLOBALS['message'] ??= null;
|
||||
|
||||
if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
|
||||
$sql_query = '';
|
||||
$sqlQuery = '';
|
||||
|
||||
$item_query = $this->getQueryFromRequest();
|
||||
$itemQuery = $this->getQueryFromRequest();
|
||||
|
||||
// set by getQueryFromRequest()
|
||||
if (! count($GLOBALS['errors'])) {
|
||||
// Execute the created query
|
||||
if (! empty($_POST['editor_process_edit'])) {
|
||||
// Backup the old trigger, in case something goes wrong
|
||||
$create_item = self::getDefinition($this->dbi, $GLOBALS['db'], $_POST['item_original_name']);
|
||||
$drop_item = 'DROP EVENT IF EXISTS '
|
||||
$createItem = self::getDefinition($this->dbi, $GLOBALS['db'], $_POST['item_original_name']);
|
||||
$dropItem = 'DROP EVENT IF EXISTS '
|
||||
. Util::backquote($_POST['item_original_name'])
|
||||
. ";\n";
|
||||
$result = $this->dbi->tryQuery($drop_item);
|
||||
$result = $this->dbi->tryQuery($dropItem);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($drop_item),
|
||||
htmlspecialchars($dropItem),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
} else {
|
||||
$result = $this->dbi->tryQuery($item_query);
|
||||
$result = $this->dbi->tryQuery($itemQuery);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query),
|
||||
htmlspecialchars($itemQuery),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
// We dropped the old item, but were unable to create
|
||||
// the new one. Try to restore the backup query
|
||||
$result = $this->dbi->tryQuery($create_item);
|
||||
$result = $this->dbi->tryQuery($createItem);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'] = $this->checkResult($create_item, $GLOBALS['errors']);
|
||||
$GLOBALS['errors'] = $this->checkResult($createItem, $GLOBALS['errors']);
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['message'] = Message::success(
|
||||
@ -121,16 +121,16 @@ class Events
|
||||
$GLOBALS['message']->addParam(
|
||||
Util::backquote($_POST['item_name']),
|
||||
);
|
||||
$sql_query = $drop_item . $item_query;
|
||||
$sqlQuery = $dropItem . $itemQuery;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 'Add a new item' mode
|
||||
$result = $this->dbi->tryQuery($item_query);
|
||||
$result = $this->dbi->tryQuery($itemQuery);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query),
|
||||
htmlspecialchars($itemQuery),
|
||||
)
|
||||
. '<br><br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
@ -141,7 +141,7 @@ class Events
|
||||
$GLOBALS['message']->addParam(
|
||||
Util::backquote($_POST['item_name']),
|
||||
);
|
||||
$sql_query = $item_query;
|
||||
$sqlQuery = $itemQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ class Events
|
||||
$GLOBALS['message']->addHtml('</ul>');
|
||||
}
|
||||
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sql_query);
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sqlQuery);
|
||||
|
||||
if ($this->response->isAjax()) {
|
||||
if ($GLOBALS['message']->isSuccess()) {
|
||||
|
||||
@ -175,8 +175,8 @@ class Routines
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$sql_query = '';
|
||||
$routine_query = $this->getQueryFromRequest();
|
||||
$sqlQuery = '';
|
||||
$routineQuery = $this->getQueryFromRequest();
|
||||
|
||||
// set by getQueryFromRequest()
|
||||
if (! count($errors)) {
|
||||
@ -190,32 +190,32 @@ class Routines
|
||||
} else {
|
||||
// Backup the old routine, in case something goes wrong
|
||||
if ($_POST['item_original_type'] === 'FUNCTION') {
|
||||
$create_routine = self::getFunctionDefinition($this->dbi, $db, $_POST['item_original_name']);
|
||||
$createRoutine = self::getFunctionDefinition($this->dbi, $db, $_POST['item_original_name']);
|
||||
} else {
|
||||
$create_routine = self::getProcedureDefinition($this->dbi, $db, $_POST['item_original_name']);
|
||||
$createRoutine = self::getProcedureDefinition($this->dbi, $db, $_POST['item_original_name']);
|
||||
}
|
||||
|
||||
$privilegesBackup = $this->backupPrivileges();
|
||||
|
||||
$drop_routine = 'DROP ' . $_POST['item_original_type'] . ' '
|
||||
$dropRoutine = 'DROP ' . $_POST['item_original_type'] . ' '
|
||||
. Util::backquote($_POST['item_original_name'])
|
||||
. ";\n";
|
||||
$result = $this->dbi->tryQuery($drop_routine);
|
||||
$result = $this->dbi->tryQuery($dropRoutine);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($drop_routine),
|
||||
htmlspecialchars($dropRoutine),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
} else {
|
||||
[$newErrors, $GLOBALS['message']] = $this->create(
|
||||
$routine_query,
|
||||
$create_routine,
|
||||
$routineQuery,
|
||||
$createRoutine,
|
||||
$privilegesBackup,
|
||||
);
|
||||
if (empty($newErrors)) {
|
||||
$sql_query = $drop_routine . $routine_query;
|
||||
$sqlQuery = $dropRoutine . $routineQuery;
|
||||
} else {
|
||||
$errors = array_merge($errors, $newErrors);
|
||||
}
|
||||
@ -225,11 +225,11 @@ class Routines
|
||||
}
|
||||
} else {
|
||||
// 'Add a new routine' mode
|
||||
$result = $this->dbi->tryQuery($routine_query);
|
||||
$result = $this->dbi->tryQuery($routineQuery);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($routine_query),
|
||||
htmlspecialchars($routineQuery),
|
||||
)
|
||||
. '<br><br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
@ -240,7 +240,7 @@ class Routines
|
||||
$GLOBALS['message']->addParam(
|
||||
Util::backquote($_POST['item_name']),
|
||||
);
|
||||
$sql_query = $routine_query;
|
||||
$sqlQuery = $routineQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ class Routines
|
||||
$GLOBALS['message']->addHtml('</ul>');
|
||||
}
|
||||
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sql_query);
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sqlQuery);
|
||||
|
||||
if (! $this->response->isAjax()) {
|
||||
return $errors;
|
||||
@ -315,32 +315,32 @@ class Routines
|
||||
/**
|
||||
* Create the routine
|
||||
*
|
||||
* @param string $routine_query Query to create routine
|
||||
* @param string $create_routine Query to restore routine
|
||||
* @param string $routineQuery Query to create routine
|
||||
* @param string $createRoutine Query to restore routine
|
||||
* @param array $privilegesBackup Privileges backup
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function create(
|
||||
string $routine_query,
|
||||
string $create_routine,
|
||||
string $routineQuery,
|
||||
string $createRoutine,
|
||||
array $privilegesBackup,
|
||||
): array {
|
||||
$result = $this->dbi->tryQuery($routine_query);
|
||||
$result = $this->dbi->tryQuery($routineQuery);
|
||||
if (! $result) {
|
||||
$errors = [];
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($routine_query),
|
||||
htmlspecialchars($routineQuery),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
// We dropped the old routine,
|
||||
// but were unable to create the new one
|
||||
// Try to restore the backup query
|
||||
$result = $this->dbi->tryQuery($create_routine);
|
||||
$result = $this->dbi->tryQuery($createRoutine);
|
||||
if (! $result) {
|
||||
$errors = $this->checkResult($create_routine, $errors);
|
||||
$errors = $this->checkResult($createRoutine, $errors);
|
||||
}
|
||||
|
||||
return [
|
||||
@ -658,7 +658,7 @@ class Routines
|
||||
// template row for AJAX request
|
||||
$i = 0;
|
||||
$index = '%s';
|
||||
$drop_class = '';
|
||||
$dropClass = '';
|
||||
$routine = [
|
||||
'item_param_dir' => [0 => ''],
|
||||
'item_param_name' => [0 => ''],
|
||||
@ -669,7 +669,7 @@ class Routines
|
||||
];
|
||||
} elseif ($routine !== []) {
|
||||
// regular row for routine editor
|
||||
$drop_class = ' hide';
|
||||
$dropClass = ' hide';
|
||||
$i = $index;
|
||||
} else {
|
||||
// No input data. This shouldn't happen,
|
||||
@ -701,7 +701,7 @@ class Routines
|
||||
$routine['item_param_type'][$i],
|
||||
),
|
||||
'charsets' => $charsets,
|
||||
'drop_class' => $drop_class,
|
||||
'drop_class' => $dropClass,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -953,19 +953,19 @@ class Routines
|
||||
if (str_contains($itemDefiner, '@')) {
|
||||
$arr = explode('@', $itemDefiner);
|
||||
|
||||
$do_backquote = true;
|
||||
$doBackquote = true;
|
||||
if (substr($arr[0], 0, 1) === '`' && substr($arr[0], -1) === '`') {
|
||||
$do_backquote = false;
|
||||
$doBackquote = false;
|
||||
}
|
||||
|
||||
$query .= 'DEFINER=' . Util::backquoteCompat($arr[0], 'NONE', $do_backquote);
|
||||
$query .= 'DEFINER=' . Util::backquoteCompat($arr[0], 'NONE', $doBackquote);
|
||||
|
||||
$do_backquote = true;
|
||||
$doBackquote = true;
|
||||
if (substr($arr[1], 0, 1) === '`' && substr($arr[1], -1) === '`') {
|
||||
$do_backquote = false;
|
||||
$doBackquote = false;
|
||||
}
|
||||
|
||||
$query .= '@' . Util::backquoteCompat($arr[1], 'NONE', $do_backquote) . ' ';
|
||||
$query .= '@' . Util::backquoteCompat($arr[1], 'NONE', $doBackquote) . ' ';
|
||||
} else {
|
||||
$GLOBALS['errors'][] = __('The definer must be in the "username@hostname" format!');
|
||||
}
|
||||
@ -1064,9 +1064,9 @@ class Routines
|
||||
private function getQueriesFromRoutineForm(array $routine): array
|
||||
{
|
||||
$queries = [];
|
||||
$end_query = [];
|
||||
$endQuery = [];
|
||||
$args = [];
|
||||
$all_functions = $this->dbi->types->getAllFunctions();
|
||||
$allFunctions = $this->dbi->types->getAllFunctions();
|
||||
for ($i = 0; $i < $routine['item_num_params']; $i++) {
|
||||
if (isset($_POST['params'][$routine['item_param_name'][$i]])) {
|
||||
$value = $_POST['params'][$routine['item_param_name'][$i]];
|
||||
@ -1077,7 +1077,7 @@ class Routines
|
||||
$value = $this->dbi->escapeString($value);
|
||||
if (
|
||||
! empty($_POST['funcs'][$routine['item_param_name'][$i]])
|
||||
&& in_array($_POST['funcs'][$routine['item_param_name'][$i]], $all_functions)
|
||||
&& in_array($_POST['funcs'][$routine['item_param_name'][$i]], $allFunctions)
|
||||
) {
|
||||
$queries[] = 'SET @p' . $i . '='
|
||||
. $_POST['funcs'][$routine['item_param_name'][$i]]
|
||||
@ -1099,15 +1099,15 @@ class Routines
|
||||
continue;
|
||||
}
|
||||
|
||||
$end_query[] = '@p' . $i . ' AS '
|
||||
$endQuery[] = '@p' . $i . ' AS '
|
||||
. Util::backquote($routine['item_param_name'][$i]);
|
||||
}
|
||||
|
||||
if ($routine['item_type'] === 'PROCEDURE') {
|
||||
$queries[] = 'CALL ' . Util::backquote($routine['item_name'])
|
||||
. '(' . implode(', ', $args) . ");\n";
|
||||
if (count($end_query)) {
|
||||
$queries[] = 'SELECT ' . implode(', ', $end_query) . ";\n";
|
||||
if (count($endQuery)) {
|
||||
$queries[] = 'SELECT ' . implode(', ', $endQuery) . ";\n";
|
||||
}
|
||||
} else {
|
||||
$queries[] = 'SELECT ' . Util::backquote($routine['item_name'])
|
||||
@ -1145,13 +1145,13 @@ class Routines
|
||||
$queries = is_array($routine) ? $this->getQueriesFromRoutineForm($routine) : [];
|
||||
|
||||
// Get all the queries as one SQL statement
|
||||
$multiple_query = implode('', $queries);
|
||||
$multipleQuery = implode('', $queries);
|
||||
|
||||
$outcome = true;
|
||||
$affected = 0;
|
||||
|
||||
// Execute query
|
||||
if (! $this->dbi->tryMultiQuery($multiple_query)) {
|
||||
if (! $this->dbi->tryMultiQuery($multipleQuery)) {
|
||||
$outcome = false;
|
||||
}
|
||||
|
||||
@ -1232,7 +1232,7 @@ class Routines
|
||||
$message = Message::error(
|
||||
sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($multiple_query),
|
||||
htmlspecialchars($multipleQuery),
|
||||
)
|
||||
. '<br><br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError(),
|
||||
@ -1343,10 +1343,10 @@ class Routines
|
||||
$routine['item_param_name'][$i] = htmlentities($routine['item_param_name'][$i], ENT_QUOTES);
|
||||
}
|
||||
|
||||
$no_support_types = Util::unsupportedDatatypes();
|
||||
$noSupportTypes = Util::unsupportedDatatypes();
|
||||
|
||||
$params = [];
|
||||
$params['no_support_types'] = $no_support_types;
|
||||
$params['no_support_types'] = $noSupportTypes;
|
||||
|
||||
for ($i = 0; $i < $routine['item_num_params']; $i++) {
|
||||
if ($routine['item_type'] === 'PROCEDURE' && $routine['item_param_dir'][$i] === 'OUT') {
|
||||
@ -1359,7 +1359,7 @@ class Routines
|
||||
|| stripos($routine['item_param_type'][$i], 'set') !== false
|
||||
|| in_array(
|
||||
mb_strtolower($routine['item_param_type'][$i]),
|
||||
$no_support_types,
|
||||
$noSupportTypes,
|
||||
)
|
||||
) {
|
||||
$params[$i]['generator'] = null;
|
||||
@ -1395,7 +1395,7 @@ class Routines
|
||||
$value = htmlentities(Util::unQuote($value), ENT_QUOTES);
|
||||
$params[$i]['htmlentities'][] = $value;
|
||||
}
|
||||
} elseif (in_array(mb_strtolower($routine['item_param_type'][$i]), $no_support_types)) {
|
||||
} elseif (in_array(mb_strtolower($routine['item_param_type'][$i]), $noSupportTypes)) {
|
||||
$params[$i]['input_type'] = null;
|
||||
} else {
|
||||
$params[$i]['input_type'] = 'text';
|
||||
|
||||
@ -134,19 +134,19 @@ class Search
|
||||
private function getSearchSqls(string $table): array
|
||||
{
|
||||
// Statement types
|
||||
$sqlstr_select = 'SELECT';
|
||||
$sqlstr_delete = 'DELETE';
|
||||
$sqlStrSelect = 'SELECT';
|
||||
$sqlStrDelete = 'DELETE';
|
||||
// Table to use
|
||||
$sqlstr_from = ' FROM ' . Util::backquote($GLOBALS['db']) . '.' . Util::backquote($table);
|
||||
$sqlStrFrom = ' FROM ' . Util::backquote($GLOBALS['db']) . '.' . Util::backquote($table);
|
||||
// Gets where clause for the query
|
||||
$where_clause = $this->getWhereClause($table);
|
||||
$whereClause = $this->getWhereClause($table);
|
||||
// Builds complete queries
|
||||
$sql = [];
|
||||
$sql['select_columns'] = $sqlstr_select . ' *' . $sqlstr_from . $where_clause;
|
||||
$sql['select_columns'] = $sqlStrSelect . ' *' . $sqlStrFrom . $whereClause;
|
||||
// here, I think we need to still use the COUNT clause, even for
|
||||
// VIEWs, anyway we have a WHERE clause that should limit results
|
||||
$sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`' . $sqlstr_from . $where_clause;
|
||||
$sql['delete'] = $sqlstr_delete . $sqlstr_from . $where_clause;
|
||||
$sql['select_count'] = $sqlStrSelect . ' COUNT(*) AS `count`' . $sqlStrFrom . $whereClause;
|
||||
$sql['delete'] = $sqlStrDelete . $sqlStrFrom . $whereClause;
|
||||
|
||||
return $sql;
|
||||
}
|
||||
@ -164,19 +164,19 @@ class Search
|
||||
$allColumns = $this->dbi->getColumns($GLOBALS['db'], $table);
|
||||
$likeClauses = [];
|
||||
// Based on search type, decide like/regex & '%'/''
|
||||
$like_or_regex = ($this->criteriaSearchType == 5 ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = ($this->criteriaSearchType < 4 ? '%' : '');
|
||||
$likeOrRegex = ($this->criteriaSearchType == 5 ? 'REGEXP' : 'LIKE');
|
||||
$automaticWildcard = ($this->criteriaSearchType < 4 ? '%' : '');
|
||||
// For "as regular expression" (search option 5), LIKE won't be used
|
||||
// Usage example: If user is searching for a literal $ in a regexp search,
|
||||
// they should enter \$ as the value.
|
||||
// Extract search words or pattern
|
||||
$search_words = $this->criteriaSearchType > 2
|
||||
$searchWords = $this->criteriaSearchType > 2
|
||||
? [$this->criteriaSearchString]
|
||||
: explode(' ', $this->criteriaSearchString);
|
||||
|
||||
foreach ($search_words as $search_word) {
|
||||
foreach ($searchWords as $searchWord) {
|
||||
// Eliminates empty values
|
||||
if ($search_word === '') {
|
||||
if ($searchWord === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -191,8 +191,8 @@ class Search
|
||||
}
|
||||
|
||||
$column = 'CONVERT(' . Util::backquote($column['Field']) . ' USING utf8)';
|
||||
$likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' '
|
||||
. $this->dbi->quoteString($automatic_wildcard . $search_word . $automatic_wildcard);
|
||||
$likeClausesPerColumn[] = $column . ' ' . $likeOrRegex . ' '
|
||||
. $this->dbi->quoteString($automaticWildcard . $searchWord . $automaticWildcard);
|
||||
}
|
||||
|
||||
if ($likeClausesPerColumn === []) {
|
||||
@ -209,9 +209,9 @@ class Search
|
||||
}
|
||||
|
||||
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
|
||||
$implode_str = ($this->criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
$implodeStr = ($this->criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
|
||||
return ' WHERE (' . implode(') ' . $implode_str . ' (', $likeClauses) . ')';
|
||||
return ' WHERE (' . implode(') ' . $implodeStr . ' (', $likeClauses) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -89,9 +89,9 @@ class Triggers
|
||||
$GLOBALS['message'] ??= null;
|
||||
|
||||
if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
|
||||
$sql_query = '';
|
||||
$sqlQuery = '';
|
||||
|
||||
$item_query = $this->getQueryFromRequest();
|
||||
$itemQuery = $this->getQueryFromRequest();
|
||||
|
||||
// set by getQueryFromRequest()
|
||||
if (! count($GLOBALS['errors'])) {
|
||||
@ -99,31 +99,31 @@ class Triggers
|
||||
if (! empty($_POST['editor_process_edit'])) {
|
||||
// Backup the old trigger, in case something goes wrong
|
||||
$trigger = $this->getDataFromName($_POST['item_original_name']);
|
||||
$create_item = $trigger['create'];
|
||||
$drop_item = $trigger['drop'] . ';';
|
||||
$result = $this->dbi->tryQuery($drop_item);
|
||||
$createItem = $trigger['create'];
|
||||
$dropItem = $trigger['drop'] . ';';
|
||||
$result = $this->dbi->tryQuery($dropItem);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($drop_item),
|
||||
htmlspecialchars($dropItem),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
} else {
|
||||
$result = $this->dbi->tryQuery($item_query);
|
||||
$result = $this->dbi->tryQuery($itemQuery);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query),
|
||||
htmlspecialchars($itemQuery),
|
||||
)
|
||||
. '<br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
// We dropped the old item, but were unable to create the
|
||||
// new one. Try to restore the backup query.
|
||||
$result = $this->dbi->tryQuery($create_item);
|
||||
$result = $this->dbi->tryQuery($createItem);
|
||||
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'] = $this->checkResult($create_item, $GLOBALS['errors']);
|
||||
$GLOBALS['errors'] = $this->checkResult($createItem, $GLOBALS['errors']);
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['message'] = Message::success(
|
||||
@ -132,16 +132,16 @@ class Triggers
|
||||
$GLOBALS['message']->addParam(
|
||||
Util::backquote($_POST['item_name']),
|
||||
);
|
||||
$sql_query = $drop_item . $item_query;
|
||||
$sqlQuery = $dropItem . $itemQuery;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 'Add a new item' mode
|
||||
$result = $this->dbi->tryQuery($item_query);
|
||||
$result = $this->dbi->tryQuery($itemQuery);
|
||||
if (! $result) {
|
||||
$GLOBALS['errors'][] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query),
|
||||
htmlspecialchars($itemQuery),
|
||||
)
|
||||
. '<br><br>'
|
||||
. __('MySQL said: ') . $this->dbi->getError();
|
||||
@ -152,7 +152,7 @@ class Triggers
|
||||
$GLOBALS['message']->addParam(
|
||||
Util::backquote($_POST['item_name']),
|
||||
);
|
||||
$sql_query = $item_query;
|
||||
$sqlQuery = $itemQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,7 +173,7 @@ class Triggers
|
||||
$GLOBALS['message']->addHtml('</ul>');
|
||||
}
|
||||
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sql_query);
|
||||
$output = Generator::getMessage($GLOBALS['message'], $sqlQuery);
|
||||
|
||||
if ($this->response->isAjax()) {
|
||||
if ($GLOBALS['message']->isSuccess()) {
|
||||
|
||||
@ -367,7 +367,7 @@ class DatabaseInterface implements DbalInterface
|
||||
}
|
||||
|
||||
$tables = [];
|
||||
$paging_applied = false;
|
||||
$pagingApplied = false;
|
||||
|
||||
if ($limitCount && is_array($table) && $sortBy === 'Name') {
|
||||
if ($sortOrder === 'DESC') {
|
||||
@ -375,7 +375,7 @@ class DatabaseInterface implements DbalInterface
|
||||
}
|
||||
|
||||
$table = array_slice($table, $limitOffset, $limitCount);
|
||||
$paging_applied = true;
|
||||
$pagingApplied = true;
|
||||
}
|
||||
|
||||
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
|
||||
@ -408,7 +408,7 @@ class DatabaseInterface implements DbalInterface
|
||||
// Sort the tables
|
||||
$sql .= ' ORDER BY ' . $sortBy . ' ' . $sortOrder;
|
||||
|
||||
if ($limitCount && ! $paging_applied) {
|
||||
if ($limitCount && ! $pagingApplied) {
|
||||
$sql .= ' LIMIT ' . $limitCount . ' OFFSET ' . $limitOffset;
|
||||
}
|
||||
|
||||
@ -585,7 +585,7 @@ class DatabaseInterface implements DbalInterface
|
||||
unset($sortValues);
|
||||
}
|
||||
|
||||
if ($limitCount && ! $paging_applied) {
|
||||
if ($limitCount && ! $pagingApplied) {
|
||||
$eachTables = array_slice($eachTables, $limitOffset, $limitCount, true);
|
||||
}
|
||||
|
||||
|
||||
@ -50,17 +50,17 @@ class DbiMysqli implements DbiExtension
|
||||
return null;
|
||||
}
|
||||
|
||||
$client_flags = 0;
|
||||
$clientFlags = 0;
|
||||
|
||||
/* Optionally compress connection */
|
||||
if ($server->compress && defined('MYSQLI_CLIENT_COMPRESS')) {
|
||||
$client_flags |= MYSQLI_CLIENT_COMPRESS;
|
||||
$clientFlags |= MYSQLI_CLIENT_COMPRESS;
|
||||
}
|
||||
|
||||
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
/* Optionally enable SSL */
|
||||
if ($server->ssl) {
|
||||
$client_flags |= MYSQLI_CLIENT_SSL;
|
||||
$clientFlags |= MYSQLI_CLIENT_SSL;
|
||||
if (
|
||||
$server->ssl_key !== null && $server->ssl_key !== '' ||
|
||||
$server->ssl_cert !== null && $server->ssl_cert !== '' ||
|
||||
@ -85,7 +85,7 @@ class DbiMysqli implements DbiExtension
|
||||
*/
|
||||
if (! $server->ssl_verify) {
|
||||
$mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, (int) $server->ssl_verify);
|
||||
$client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
|
||||
$clientFlags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ class DbiMysqli implements DbiExtension
|
||||
'',
|
||||
(int) $server->port,
|
||||
$server->socket,
|
||||
$client_flags,
|
||||
$clientFlags,
|
||||
);
|
||||
} catch (mysqli_sql_exception) {
|
||||
/**
|
||||
@ -114,13 +114,13 @@ class DbiMysqli implements DbiExtension
|
||||
* - #2001 - SSL Connection is required. Please specify SSL options and retry.
|
||||
* - #9002 - SSL connection is required. Please specify SSL options and retry.
|
||||
*/
|
||||
$error_number = $mysqli->connect_errno;
|
||||
$error_message = $mysqli->connect_error;
|
||||
$errorNumber = $mysqli->connect_errno;
|
||||
$errorMessage = $mysqli->connect_error;
|
||||
if (
|
||||
! $server->ssl
|
||||
&& ($error_number == 3159
|
||||
|| (($error_number == 2001 || $error_number == 9002)
|
||||
&& stripos($error_message, 'SSL Connection is required') !== false))
|
||||
&& ($errorNumber == 3159
|
||||
|| (($errorNumber == 2001 || $errorNumber == 9002)
|
||||
&& stripos($errorMessage, 'SSL Connection is required') !== false))
|
||||
) {
|
||||
trigger_error(
|
||||
__('SSL connection enforced by server, automatically enabling it.'),
|
||||
@ -130,7 +130,7 @@ class DbiMysqli implements DbiExtension
|
||||
return self::connect($user, $password, $server->withSSL(true));
|
||||
}
|
||||
|
||||
if ($error_number === 1045 && $server->hide_connection_errors) {
|
||||
if ($errorNumber === 1045 && $server->hide_connection_errors) {
|
||||
trigger_error(
|
||||
sprintf(
|
||||
__(
|
||||
@ -143,7 +143,7 @@ class DbiMysqli implements DbiExtension
|
||||
E_USER_ERROR,
|
||||
);
|
||||
} else {
|
||||
trigger_error($error_number . ': ' . $error_message, E_USER_WARNING);
|
||||
trigger_error($errorNumber . ': ' . $errorMessage, E_USER_WARNING);
|
||||
}
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
@ -295,18 +295,18 @@ class DbiMysqli implements DbiExtension
|
||||
/** @var mysqli $mysqli */
|
||||
$mysqli = $connection->connection;
|
||||
|
||||
$error_number = $mysqli->errno;
|
||||
$error_message = $mysqli->error;
|
||||
$errorNumber = $mysqli->errno;
|
||||
$errorMessage = $mysqli->error;
|
||||
|
||||
if ($error_number === 0 || $error_message === '') {
|
||||
if ($errorNumber === 0 || $errorMessage === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// keep the error number for further check after
|
||||
// the call to getError()
|
||||
$GLOBALS['errno'] = $error_number;
|
||||
$GLOBALS['errno'] = $errorNumber;
|
||||
|
||||
return Utilities::formatError($error_number, $error_message);
|
||||
return Utilities::formatError($errorNumber, $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -2560,12 +2560,12 @@ class Results
|
||||
. Url::getCommonRaw($linkingUrlParams, $divider);
|
||||
}
|
||||
|
||||
foreach ($linkRelations['link_dependancy_params'] as $new_param) {
|
||||
$columnName = mb_strtolower($new_param['column_name']);
|
||||
foreach ($linkRelations['link_dependancy_params'] as $newParam) {
|
||||
$columnName = mb_strtolower($newParam['column_name']);
|
||||
|
||||
// If there is a value for this column name in the rowInfo provided
|
||||
if (isset($rowInfo[$columnName])) {
|
||||
$linkingUrlParams[$new_param['param_info']] = $rowInfo[$columnName];
|
||||
$linkingUrlParams[$newParam['param_info']] = $rowInfo[$columnName];
|
||||
}
|
||||
|
||||
// Special case 1 - when executing routines, according
|
||||
|
||||
@ -163,18 +163,18 @@ class Encoding
|
||||
* Converts encoding of text according to parameters with detected
|
||||
* conversion function.
|
||||
*
|
||||
* @param string $src_charset source charset
|
||||
* @param string $dest_charset target charset
|
||||
* @param string $what what to convert
|
||||
* @param string $srcCharset source charset
|
||||
* @param string $destCharset target charset
|
||||
* @param string $what what to convert
|
||||
*
|
||||
* @return string converted text
|
||||
*/
|
||||
public static function convertString(
|
||||
string $src_charset,
|
||||
string $dest_charset,
|
||||
string $srcCharset,
|
||||
string $destCharset,
|
||||
string $what,
|
||||
): string {
|
||||
if ($src_charset === $dest_charset) {
|
||||
if ($srcCharset === $destCharset) {
|
||||
return $what;
|
||||
}
|
||||
|
||||
@ -183,13 +183,13 @@ class Encoding
|
||||
}
|
||||
|
||||
return match (self::$engine) {
|
||||
self::ENGINE_RECODE => recode_string($src_charset . '..' . $dest_charset, $what),
|
||||
self::ENGINE_RECODE => recode_string($srcCharset . '..' . $destCharset, $what),
|
||||
self::ENGINE_ICONV => iconv(
|
||||
$src_charset,
|
||||
$dest_charset . ($GLOBALS['cfg']['IconvExtraParams'] ?? ''),
|
||||
$srcCharset,
|
||||
$destCharset . ($GLOBALS['cfg']['IconvExtraParams'] ?? ''),
|
||||
$what,
|
||||
),
|
||||
self::ENGINE_MB => mb_convert_encoding($what, $dest_charset, $src_charset),
|
||||
self::ENGINE_MB => mb_convert_encoding($what, $destCharset, $srcCharset),
|
||||
default => $what,
|
||||
};
|
||||
}
|
||||
@ -250,18 +250,18 @@ class Encoding
|
||||
return $str;
|
||||
}
|
||||
|
||||
$string_encoding = mb_detect_encoding($str, self::$kanjiEncodings);
|
||||
if ($string_encoding === false) {
|
||||
$string_encoding = 'utf-8';
|
||||
$stringEncoding = mb_detect_encoding($str, self::$kanjiEncodings);
|
||||
if ($stringEncoding === false) {
|
||||
$stringEncoding = 'utf-8';
|
||||
}
|
||||
|
||||
if ($kana === 'kana') {
|
||||
$dist = mb_convert_kana($str, 'KV', $string_encoding);
|
||||
$dist = mb_convert_kana($str, 'KV', $stringEncoding);
|
||||
$str = $dist;
|
||||
}
|
||||
|
||||
if ($string_encoding !== $enc && $enc != '') {
|
||||
return mb_convert_encoding($str, $enc, $string_encoding);
|
||||
if ($stringEncoding !== $enc && $enc != '') {
|
||||
return mb_convert_encoding($str, $enc, $stringEncoding);
|
||||
}
|
||||
|
||||
return $str;
|
||||
|
||||
@ -141,16 +141,16 @@ class Pbxt extends StorageEngine
|
||||
* returns the pbxt engine specific handling for
|
||||
* DETAILS_TYPE_SIZE variables.
|
||||
*
|
||||
* @param int|string $formatted_size the size expression (for example 8MB)
|
||||
* @param int|string $formattedSize the size expression (for example 8MB)
|
||||
*
|
||||
* @return array|null the formatted value and its unit
|
||||
*/
|
||||
public function resolveTypeSize(int|string $formatted_size): array|null
|
||||
public function resolveTypeSize(int|string $formattedSize): array|null
|
||||
{
|
||||
if (is_string($formatted_size) && preg_match('/^[0-9]+[a-zA-Z]+$/', $formatted_size)) {
|
||||
$value = Util::extractValueFromFormattedSize($formatted_size);
|
||||
if (is_string($formattedSize) && preg_match('/^[0-9]+[a-zA-Z]+$/', $formattedSize)) {
|
||||
$value = Util::extractValueFromFormattedSize($formattedSize);
|
||||
} else {
|
||||
$value = $formatted_size;
|
||||
$value = $formattedSize;
|
||||
}
|
||||
|
||||
return Util::formatByteDown($value);
|
||||
|
||||
@ -128,12 +128,12 @@ class File
|
||||
* checks or sets the temp flag for this file
|
||||
* file objects with temp flags are deleted with object destruction
|
||||
*
|
||||
* @param bool $is_temp sets the temp flag
|
||||
* @param bool $isTemp sets the temp flag
|
||||
*/
|
||||
public function isTemp(bool|null $is_temp = null): bool
|
||||
public function isTemp(bool|null $isTemp = null): bool
|
||||
{
|
||||
if ($is_temp !== null) {
|
||||
$this->isTemp = $is_temp;
|
||||
if ($isTemp !== null) {
|
||||
$this->isTemp = $isTemp;
|
||||
}
|
||||
|
||||
return $this->isTemp;
|
||||
@ -450,8 +450,8 @@ class File
|
||||
return true;
|
||||
}
|
||||
|
||||
$tmp_subdir = $GLOBALS['config']->getUploadTempDir();
|
||||
if ($tmp_subdir === null) {
|
||||
$tmpSubdir = $GLOBALS['config']->getUploadTempDir();
|
||||
if ($tmpSubdir === null) {
|
||||
// cannot create directory or access, point user to FAQ 1.11
|
||||
$this->errorMessage = Message::error(__(
|
||||
'Error moving the uploaded file, see [doc@faq1-11]FAQ 1.11[/doc].',
|
||||
@ -460,26 +460,26 @@ class File
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_file_to_upload = (string) tempnam(
|
||||
$tmp_subdir,
|
||||
$newFileToUpload = (string) tempnam(
|
||||
$tmpSubdir,
|
||||
basename((string) $this->getName()),
|
||||
);
|
||||
|
||||
// suppress warnings from being displayed, but not from being logged
|
||||
// any file access outside of open_basedir will issue a warning
|
||||
ob_start();
|
||||
$move_uploaded_file_result = move_uploaded_file(
|
||||
$moveUploadedFileResult = move_uploaded_file(
|
||||
(string) $this->getName(),
|
||||
$new_file_to_upload,
|
||||
$newFileToUpload,
|
||||
);
|
||||
ob_end_clean();
|
||||
if (! $move_uploaded_file_result) {
|
||||
if (! $moveUploadedFileResult) {
|
||||
$this->errorMessage = Message::error(__('Error while moving uploaded file.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setName($new_file_to_upload);
|
||||
$this->setName($newFileToUpload);
|
||||
$this->isTemp(true);
|
||||
|
||||
if (! $this->isReadable()) {
|
||||
@ -623,11 +623,11 @@ class File
|
||||
/**
|
||||
* Opens file from zip
|
||||
*
|
||||
* @param string|null $specific_entry Entry to open
|
||||
* @param string|null $specificEntry Entry to open
|
||||
*/
|
||||
public function openZip(string|null $specific_entry = null): bool
|
||||
public function openZip(string|null $specificEntry = null): bool
|
||||
{
|
||||
$result = $this->zipExtension->getContents($this->getName(), $specific_entry);
|
||||
$result = $this->zipExtension->getContents($this->getName(), $specificEntry);
|
||||
if (! empty($result['error'])) {
|
||||
$this->errorMessage = Message::rawError($result['error']);
|
||||
|
||||
|
||||
@ -31,38 +31,38 @@ abstract class GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS data object
|
||||
* @param string $label label for the GIS data object
|
||||
* @param int[] $color color for the GIS data object
|
||||
* @param array $scale_data data related to scaling
|
||||
* @param string $spatial GIS data object
|
||||
* @param string $label label for the GIS data object
|
||||
* @param int[] $color color for the GIS data object
|
||||
* @param array $scaleData data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
abstract public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string;
|
||||
abstract public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string;
|
||||
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
abstract public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper;
|
||||
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS data object
|
||||
* @param string $label label for the GIS data object
|
||||
* @param int[] $color color for the GIS data object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $spatial GIS data object
|
||||
* @param string $label label for the GIS data object
|
||||
* @param int[] $color color for the GIS data object
|
||||
* @param array $scaleData array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
@ -70,7 +70,7 @@ abstract class GisGeometry
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
TCPDF $pdf,
|
||||
): TCPDF;
|
||||
|
||||
@ -104,26 +104,26 @@ abstract class GisGeometry
|
||||
/**
|
||||
* Generates the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index index into the parameter object
|
||||
* @param string|null $empty value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index index into the parameter object
|
||||
* @param string|null $empty value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
abstract public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string;
|
||||
abstract public function generateWkt(array $gisData, int $index, string|null $empty = ''): string;
|
||||
|
||||
/**
|
||||
* Updates the min, max values with the given point set.
|
||||
*
|
||||
* @param string $point_set point set
|
||||
* @param string $pointSet point set
|
||||
* @param ScaleData|null $scaleData existing min, max values
|
||||
*
|
||||
* @return ScaleData|null the updated min, max values
|
||||
*/
|
||||
protected function setMinMax(string $point_set, ScaleData|null $scaleData = null): ScaleData|null
|
||||
protected function setMinMax(string $pointSet, ScaleData|null $scaleData = null): ScaleData|null
|
||||
{
|
||||
// Separate each point
|
||||
$points = explode(',', $point_set);
|
||||
$points = explode(',', $pointSet);
|
||||
|
||||
foreach ($points as $point) {
|
||||
// Extract coordinates of the point
|
||||
@ -148,15 +148,15 @@ abstract class GisGeometry
|
||||
*/
|
||||
protected function parseWktAndSrid(string $value): array
|
||||
{
|
||||
$geom_types = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
|
||||
$geomTypes = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
|
||||
$srid = 0;
|
||||
$wkt = '';
|
||||
|
||||
if (preg_match("/^'" . $geom_types . "\(.*\)',[0-9]*$/i", $value)) {
|
||||
$last_comma = mb_strripos($value, ',');
|
||||
$srid = (int) trim(mb_substr($value, $last_comma + 1));
|
||||
$wkt = trim(mb_substr($value, 1, $last_comma - 2));
|
||||
} elseif (preg_match('/^' . $geom_types . '\(.*\)$/i', $value)) {
|
||||
if (preg_match("/^'" . $geomTypes . "\(.*\)',[0-9]*$/i", $value)) {
|
||||
$lastComma = mb_strripos($value, ',');
|
||||
$srid = (int) trim(mb_substr($value, $lastComma + 1));
|
||||
$wkt = trim(mb_substr($value, 1, $lastComma - 2));
|
||||
} elseif (preg_match('/^' . $geomTypes . '\(.*\)$/i', $value)) {
|
||||
$wkt = $value;
|
||||
}
|
||||
|
||||
@ -188,12 +188,12 @@ abstract class GisGeometry
|
||||
$index = 0;
|
||||
$wkt = $data['wkt'];
|
||||
preg_match('/^\w+/', $wkt, $matches);
|
||||
$wkt_type = strtoupper($matches[0]);
|
||||
$wktType = strtoupper($matches[0]);
|
||||
|
||||
return [
|
||||
'srid' => $data['srid'],
|
||||
$index => [
|
||||
$wkt_type => $this->getCoordinateParams($wkt),
|
||||
$wktType => $this->getCoordinateParams($wkt),
|
||||
],
|
||||
];
|
||||
}
|
||||
@ -201,18 +201,18 @@ abstract class GisGeometry
|
||||
/**
|
||||
* Extracts points, scales and returns them as an array.
|
||||
*
|
||||
* @param string $point_set string of comma separated points
|
||||
* @param array|null $scale_data data related to scaling
|
||||
* @param bool $linear if true, as a 1D array, else as a 2D array
|
||||
* @param string $pointSet string of comma separated points
|
||||
* @param array|null $scaleData data related to scaling
|
||||
* @param bool $linear if true, as a 1D array, else as a 2D array
|
||||
*
|
||||
* @return float[]|float[][] scaled points
|
||||
*/
|
||||
private function extractPointsInternal(string $point_set, array|null $scale_data, bool $linear): array
|
||||
private function extractPointsInternal(string $pointSet, array|null $scaleData, bool $linear): array
|
||||
{
|
||||
$points_arr = [];
|
||||
$pointsArr = [];
|
||||
|
||||
// Separate each point
|
||||
$points = explode(',', $point_set);
|
||||
$points = explode(',', $pointSet);
|
||||
|
||||
foreach ($points as $point) {
|
||||
$point = str_replace(['(', ')'], '', $point);
|
||||
@ -220,13 +220,13 @@ abstract class GisGeometry
|
||||
$coordinates = explode(' ', $point);
|
||||
|
||||
if (isset($coordinates[1]) && trim($coordinates[0]) != '' && trim($coordinates[1]) != '') {
|
||||
if ($scale_data === null) {
|
||||
if ($scaleData === null) {
|
||||
$x = (float) $coordinates[0];
|
||||
$y = (float) $coordinates[1];
|
||||
} else {
|
||||
$x = (float) (((float) $coordinates[0] - $scale_data['x']) * $scale_data['scale']);
|
||||
$y = (float) ($scale_data['height']
|
||||
- ((float) $coordinates[1] - $scale_data['y']) * $scale_data['scale']);
|
||||
$x = (float) (((float) $coordinates[0] - $scaleData['x']) * $scaleData['scale']);
|
||||
$y = (float) ($scaleData['height']
|
||||
- ((float) $coordinates[1] - $scaleData['y']) * $scaleData['scale']);
|
||||
}
|
||||
} else {
|
||||
$x = 0.0;
|
||||
@ -234,75 +234,75 @@ abstract class GisGeometry
|
||||
}
|
||||
|
||||
if ($linear) {
|
||||
$points_arr[] = $x;
|
||||
$points_arr[] = $y;
|
||||
$pointsArr[] = $x;
|
||||
$pointsArr[] = $y;
|
||||
} else {
|
||||
$points_arr[] = [$x, $y];
|
||||
$pointsArr[] = [$x, $y];
|
||||
}
|
||||
}
|
||||
|
||||
return $points_arr;
|
||||
return $pointsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts points, scales and returns them as an array.
|
||||
*
|
||||
* @param string $wktCoords string of comma separated points
|
||||
* @param array|null $scale_data data related to scaling
|
||||
* @param string $wktCoords string of comma separated points
|
||||
* @param array|null $scaleData data related to scaling
|
||||
*
|
||||
* @return float[][] scaled points
|
||||
*/
|
||||
protected function extractPoints1d(string $wktCoords, array|null $scale_data): array
|
||||
protected function extractPoints1d(string $wktCoords, array|null $scaleData): array
|
||||
{
|
||||
/** @var float[][] $points_arr */
|
||||
$points_arr = $this->extractPointsInternal($wktCoords, $scale_data, false);
|
||||
/** @var float[][] $pointsArr */
|
||||
$pointsArr = $this->extractPointsInternal($wktCoords, $scaleData, false);
|
||||
|
||||
return $points_arr;
|
||||
return $pointsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts points, scales and returns them as an linear array.
|
||||
*
|
||||
* @param string $wktCoords string of comma separated points
|
||||
* @param array|null $scale_data data related to scaling
|
||||
* @param string $wktCoords string of comma separated points
|
||||
* @param array|null $scaleData data related to scaling
|
||||
*
|
||||
* @return float[] scaled points
|
||||
*/
|
||||
protected function extractPoints1dLinear(string $wktCoords, array|null $scale_data): array
|
||||
protected function extractPoints1dLinear(string $wktCoords, array|null $scaleData): array
|
||||
{
|
||||
/** @var float[] $points_arr */
|
||||
$points_arr = $this->extractPointsInternal($wktCoords, $scale_data, true);
|
||||
/** @var float[] $pointsArr */
|
||||
$pointsArr = $this->extractPointsInternal($wktCoords, $scaleData, true);
|
||||
|
||||
return $points_arr;
|
||||
return $pointsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $wktCoords string of ),( separated points
|
||||
* @param array|null $scale_data data related to scaling
|
||||
* @param string $wktCoords string of ),( separated points
|
||||
* @param array|null $scaleData data related to scaling
|
||||
*
|
||||
* @return float[][][] scaled points
|
||||
*/
|
||||
protected function extractPoints2d(string $wktCoords, array|null $scale_data): array
|
||||
protected function extractPoints2d(string $wktCoords, array|null $scaleData): array
|
||||
{
|
||||
$parts = explode('),(', $wktCoords);
|
||||
|
||||
return array_map(function ($coord) use ($scale_data) {
|
||||
return $this->extractPoints1d($coord, $scale_data);
|
||||
return array_map(function ($coord) use ($scaleData) {
|
||||
return $this->extractPoints1d($coord, $scaleData);
|
||||
}, $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $wktCoords string of )),(( separated points
|
||||
* @param array|null $scale_data data related to scaling
|
||||
* @param string $wktCoords string of )),(( separated points
|
||||
* @param array|null $scaleData data related to scaling
|
||||
*
|
||||
* @return float[][][][] scaled points
|
||||
*/
|
||||
protected function extractPoints3d(string $wktCoords, array|null $scale_data): array
|
||||
protected function extractPoints3d(string $wktCoords, array|null $scaleData): array
|
||||
{
|
||||
$parts = explode(')),((', $wktCoords);
|
||||
|
||||
return array_map(function ($coord) use ($scale_data) {
|
||||
return $this->extractPoints2d($coord, $scale_data);
|
||||
return array_map(function ($coord) use ($scaleData) {
|
||||
return $this->extractPoints2d($coord, $scaleData);
|
||||
}, $parts);
|
||||
}
|
||||
|
||||
|
||||
@ -52,69 +52,69 @@ class GisGeometryCollection extends GisGeometry
|
||||
*/
|
||||
public function scaleRow(string $spatial): ScaleData|null
|
||||
{
|
||||
$min_max = null;
|
||||
$minMax = null;
|
||||
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($spatial, 19, -1);
|
||||
$geomCol = mb_substr($spatial, 19, -1);
|
||||
|
||||
// Split the geometry collection object to get its constituents.
|
||||
$sub_parts = $this->explodeGeomCol($goem_col);
|
||||
$subParts = $this->explodeGeomCol($geomCol);
|
||||
|
||||
foreach ($sub_parts as $sub_part) {
|
||||
$type_pos = mb_strpos($sub_part, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($subParts as $subPart) {
|
||||
$typePos = mb_strpos($subPart, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($sub_part, 0, $type_pos);
|
||||
$type = mb_substr($subPart, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$scale_data = $gis_obj->scaleRow($sub_part);
|
||||
$scaleData = $gisObj->scaleRow($subPart);
|
||||
|
||||
$min_max = $min_max === null ? $scale_data : $scale_data?->merge($min_max);
|
||||
$minMax = $minMax === null ? $scaleData : $scaleData?->merge($minMax);
|
||||
}
|
||||
|
||||
return $min_max;
|
||||
return $minMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($spatial, 19, -1);
|
||||
$geomCol = mb_substr($spatial, 19, -1);
|
||||
// Split the geometry collection object to get its constituents.
|
||||
$sub_parts = $this->explodeGeomCol($goem_col);
|
||||
$subParts = $this->explodeGeomCol($geomCol);
|
||||
|
||||
foreach ($sub_parts as $sub_part) {
|
||||
$type_pos = mb_strpos($sub_part, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($subParts as $subPart) {
|
||||
$typePos = mb_strpos($subPart, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($sub_part, 0, $type_pos);
|
||||
$type = mb_substr($subPart, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image = $gis_obj->prepareRowAsPng($sub_part, $label, $color, $scale_data, $image);
|
||||
$image = $gisObj->prepareRowAsPng($subPart, $label, $color, $scaleData, $image);
|
||||
}
|
||||
|
||||
return $image;
|
||||
@ -123,34 +123,34 @@ class GisGeometryCollection extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS GEOMETRYCOLLECTION object
|
||||
* @param string $label label for the GIS GEOMETRYCOLLECTION object
|
||||
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $spatial GIS GEOMETRYCOLLECTION object
|
||||
* @param string $label label for the GIS GEOMETRYCOLLECTION object
|
||||
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
|
||||
* @param array $scaleData array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scale_data, TCPDF $pdf): TCPDF
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scaleData, TCPDF $pdf): TCPDF
|
||||
{
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($spatial, 19, -1);
|
||||
$geomCol = mb_substr($spatial, 19, -1);
|
||||
// Split the geometry collection object to get its constituents.
|
||||
$sub_parts = $this->explodeGeomCol($goem_col);
|
||||
$subParts = $this->explodeGeomCol($geomCol);
|
||||
|
||||
foreach ($sub_parts as $sub_part) {
|
||||
$type_pos = mb_strpos($sub_part, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($subParts as $subPart) {
|
||||
$typePos = mb_strpos($subPart, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($sub_part, 0, $type_pos);
|
||||
$type = mb_substr($subPart, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pdf = $gis_obj->prepareRowAsPdf($sub_part, $label, $color, $scale_data, $pdf);
|
||||
$pdf = $gisObj->prepareRowAsPdf($subPart, $label, $color, $scaleData, $pdf);
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
@ -159,36 +159,36 @@ class GisGeometryCollection extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS GEOMETRYCOLLECTION object
|
||||
* @param string $label label for the GIS GEOMETRYCOLLECTION object
|
||||
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
|
||||
* @param array $scale_data array containing data related to scaling
|
||||
* @param string $spatial GIS GEOMETRYCOLLECTION object
|
||||
* @param string $label label for the GIS GEOMETRYCOLLECTION object
|
||||
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
|
||||
* @param array $scaleData array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$row = '';
|
||||
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($spatial, 19, -1);
|
||||
$geomCol = mb_substr($spatial, 19, -1);
|
||||
// Split the geometry collection object to get its constituents.
|
||||
$sub_parts = $this->explodeGeomCol($goem_col);
|
||||
$subParts = $this->explodeGeomCol($geomCol);
|
||||
|
||||
foreach ($sub_parts as $sub_part) {
|
||||
$type_pos = mb_strpos($sub_part, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($subParts as $subPart) {
|
||||
$typePos = mb_strpos($subPart, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($sub_part, 0, $type_pos);
|
||||
$type = mb_substr($subPart, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row .= $gis_obj->prepareRowAsSvg($sub_part, $label, $color, $scale_data);
|
||||
$row .= $gisObj->prepareRowAsSvg($subPart, $label, $color, $scaleData);
|
||||
}
|
||||
|
||||
return $row;
|
||||
@ -210,24 +210,24 @@ class GisGeometryCollection extends GisGeometry
|
||||
$row = '';
|
||||
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($spatial, 19, -1);
|
||||
$geomCol = mb_substr($spatial, 19, -1);
|
||||
// Split the geometry collection object to get its constituents.
|
||||
$sub_parts = $this->explodeGeomCol($goem_col);
|
||||
$subParts = $this->explodeGeomCol($geomCol);
|
||||
|
||||
foreach ($sub_parts as $sub_part) {
|
||||
$type_pos = mb_strpos($sub_part, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($subParts as $subPart) {
|
||||
$typePos = mb_strpos($subPart, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($sub_part, 0, $type_pos);
|
||||
$type = mb_substr($subPart, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row .= $gis_obj->prepareRowAsOl($sub_part, $srid, $label, $color);
|
||||
$row .= $gisObj->prepareRowAsOl($subPart, $srid, $label, $color);
|
||||
}
|
||||
|
||||
return $row;
|
||||
@ -236,23 +236,23 @@ class GisGeometryCollection extends GisGeometry
|
||||
/**
|
||||
* Splits the GEOMETRYCOLLECTION object and get its constituents.
|
||||
*
|
||||
* @param string $geom_col geometry collection string
|
||||
* @param string $geomCol geometry collection string
|
||||
*
|
||||
* @return string[] the constituents of the geometry collection object
|
||||
*/
|
||||
private function explodeGeomCol(string $geom_col): array
|
||||
private function explodeGeomCol(string $geomCol): array
|
||||
{
|
||||
$sub_parts = [];
|
||||
$br_count = 0;
|
||||
$subParts = [];
|
||||
$brCount = 0;
|
||||
$start = 0;
|
||||
$count = 0;
|
||||
foreach (str_split($geom_col) as $char) {
|
||||
foreach (str_split($geomCol) as $char) {
|
||||
if ($char === '(') {
|
||||
$br_count++;
|
||||
$brCount++;
|
||||
} elseif ($char === ')') {
|
||||
$br_count--;
|
||||
if ($br_count == 0) {
|
||||
$sub_parts[] = mb_substr($geom_col, $start, $count + 1 - $start);
|
||||
$brCount--;
|
||||
if ($brCount == 0) {
|
||||
$subParts[] = mb_substr($geomCol, $start, $count + 1 - $start);
|
||||
$start = $count + 2;
|
||||
}
|
||||
}
|
||||
@ -260,37 +260,37 @@ class GisGeometryCollection extends GisGeometry
|
||||
$count++;
|
||||
}
|
||||
|
||||
return $sub_parts;
|
||||
return $subParts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index index into the parameter object
|
||||
* @param string|null $empty value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index index into the parameter object
|
||||
* @param string|null $empty value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$geom_count = $gis_data['GEOMETRYCOLLECTION']['geom_count'] ?? 1;
|
||||
$geomCount = $gisData['GEOMETRYCOLLECTION']['geom_count'] ?? 1;
|
||||
$wkt = 'GEOMETRYCOLLECTION(';
|
||||
for ($i = 0; $i < $geom_count; $i++) {
|
||||
if (! isset($gis_data[$i]['gis_type'])) {
|
||||
for ($i = 0; $i < $geomCount; $i++) {
|
||||
if (! isset($gisData[$i]['gis_type'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $gis_data[$i]['gis_type'];
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$type = $gisData[$i]['gis_type'];
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
|
||||
$wkt .= $gisObj->generateWkt($gisData, $i, $empty) . ',';
|
||||
}
|
||||
|
||||
if (isset($gis_data[0]['gis_type'])) {
|
||||
if (isset($gisData[0]['gis_type'])) {
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
}
|
||||
|
||||
@ -320,31 +320,31 @@ class GisGeometryCollection extends GisGeometry
|
||||
$wkt = $data['wkt'];
|
||||
|
||||
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
|
||||
$goem_col = mb_substr($wkt, 19, -1);
|
||||
$wkt_geometries = $this->explodeGeomCol($goem_col);
|
||||
$geomCol = mb_substr($wkt, 19, -1);
|
||||
$wktGeometries = $this->explodeGeomCol($geomCol);
|
||||
$params = [
|
||||
'srid' => $data['srid'],
|
||||
'GEOMETRYCOLLECTION' => [
|
||||
'geom_count' => count($wkt_geometries),
|
||||
'geom_count' => count($wktGeometries),
|
||||
],
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
foreach ($wkt_geometries as $wkt_geometry) {
|
||||
$type_pos = mb_strpos($wkt_geometry, '(');
|
||||
if ($type_pos === false) {
|
||||
foreach ($wktGeometries as $wktGeometry) {
|
||||
$typePos = mb_strpos($wktGeometry, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wkt_type = strtoupper(mb_substr($wkt_geometry, 0, $type_pos));
|
||||
$gis_obj = GisFactory::factory($wkt_type);
|
||||
if (! $gis_obj) {
|
||||
$wktType = strtoupper(mb_substr($wktGeometry, 0, $typePos));
|
||||
$gisObj = GisFactory::factory($wktType);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$params[$i++] = [
|
||||
'gis_type' => $wkt_type,
|
||||
$wkt_type => $gis_obj->getCoordinateParams($wkt_geometry),
|
||||
'gis_type' => $wktType,
|
||||
$wktType => $gisObj->getCoordinateParams($wktGeometry),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -63,47 +63,47 @@ class GisLineString extends GisGeometry
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$line_color = $image->colorAllocate(...$color);
|
||||
$lineColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'LINESTRING(' and trailing ')'
|
||||
$lineString = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($lineString, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($lineString, $scaleData);
|
||||
|
||||
foreach ($points_arr as $point) {
|
||||
if (isset($temp_point)) {
|
||||
foreach ($pointsArr as $point) {
|
||||
if (isset($tempPoint)) {
|
||||
// draw line section
|
||||
$image->line(
|
||||
(int) round($temp_point[0]),
|
||||
(int) round($temp_point[1]),
|
||||
(int) round($tempPoint[0]),
|
||||
(int) round($tempPoint[1]),
|
||||
(int) round($point[0]),
|
||||
(int) round($point[1]),
|
||||
$line_color,
|
||||
$lineColor,
|
||||
);
|
||||
}
|
||||
|
||||
$temp_point = $point;
|
||||
$tempPoint = $point;
|
||||
}
|
||||
|
||||
// print label if applicable
|
||||
if ($label !== '') {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($points_arr[1][0]),
|
||||
(int) round($points_arr[1][1]),
|
||||
(int) round($pointsArr[1][0]),
|
||||
(int) round($pointsArr[1][1]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
@ -115,14 +115,14 @@ class GisLineString extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label Label for the GIS LINESTRING object
|
||||
* @param int[] $color Color for the GIS LINESTRING object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label Label for the GIS LINESTRING object
|
||||
* @param int[] $color Color for the GIS LINESTRING object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scale_data, TCPDF $pdf): TCPDF
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scaleData, TCPDF $pdf): TCPDF
|
||||
{
|
||||
$line = [
|
||||
'width' => 1.5,
|
||||
@ -130,21 +130,21 @@ class GisLineString extends GisGeometry
|
||||
];
|
||||
|
||||
// Trim to remove leading 'LINESTRING(' and trailing ')'
|
||||
$linesrting = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($linesrting, $scale_data);
|
||||
$linestring = mb_substr($spatial, 11, -1);
|
||||
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
|
||||
|
||||
foreach ($points_arr as $point) {
|
||||
if (isset($temp_point)) {
|
||||
foreach ($pointsArr as $point) {
|
||||
if (isset($tempPoint)) {
|
||||
// draw line section
|
||||
$pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line);
|
||||
$pdf->Line($tempPoint[0], $tempPoint[1], $point[0], $point[1], $line);
|
||||
}
|
||||
|
||||
$temp_point = $point;
|
||||
$tempPoint = $point;
|
||||
}
|
||||
|
||||
// print label
|
||||
if ($label !== '') {
|
||||
$pdf->setXY($points_arr[1][0], $points_arr[1][1]);
|
||||
$pdf->setXY($pointsArr[1][0], $pointsArr[1][1]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
@ -155,16 +155,16 @@ class GisLineString extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label Label for the GIS LINESTRING object
|
||||
* @param int[] $color Color for the GIS LINESTRING object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS LINESTRING object
|
||||
* @param string $label Label for the GIS LINESTRING object
|
||||
* @param int[] $color Color for the GIS LINESTRING object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$line_options = [
|
||||
$lineOptions = [
|
||||
'name' => $label,
|
||||
'id' => $label . $this->getRandomId(),
|
||||
'class' => 'linestring vector',
|
||||
@ -174,16 +174,16 @@ class GisLineString extends GisGeometry
|
||||
];
|
||||
|
||||
// Trim to remove leading 'LINESTRING(' and trailing ')'
|
||||
$linesrting = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($linesrting, $scale_data);
|
||||
$linestring = mb_substr($spatial, 11, -1);
|
||||
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
|
||||
|
||||
$row = '<polyline points="';
|
||||
foreach ($points_arr as $point) {
|
||||
foreach ($pointsArr as $point) {
|
||||
$row .= $point[0] . ',' . $point[1] . ' ';
|
||||
}
|
||||
|
||||
$row .= '"';
|
||||
foreach ($line_options as $option => $val) {
|
||||
foreach ($lineOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -205,16 +205,16 @@ class GisLineString extends GisGeometry
|
||||
*/
|
||||
public function prepareRowAsOl(string $spatial, int $srid, string $label, array $color): string
|
||||
{
|
||||
$stroke_style = [
|
||||
$strokeStyle = [
|
||||
'color' => $color,
|
||||
'width' => 2,
|
||||
];
|
||||
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . ')';
|
||||
if ($label !== '') {
|
||||
$text_style = ['text' => $label];
|
||||
$style .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$textStyle = ['text' => $label];
|
||||
$style .= ', text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -233,27 +233,27 @@ class GisLineString extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$no_of_points = $gis_data[$index]['LINESTRING']['no_of_points'] ?? 2;
|
||||
if ($no_of_points < 2) {
|
||||
$no_of_points = 2;
|
||||
$noOfPoints = $gisData[$index]['LINESTRING']['no_of_points'] ?? 2;
|
||||
if ($noOfPoints < 2) {
|
||||
$noOfPoints = 2;
|
||||
}
|
||||
|
||||
$wkt = 'LINESTRING(';
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
$wkt .= (isset($gis_data[$index]['LINESTRING'][$i]['x'])
|
||||
&& trim((string) $gis_data[$index]['LINESTRING'][$i]['x']) != ''
|
||||
? $gis_data[$index]['LINESTRING'][$i]['x'] : $empty)
|
||||
. ' ' . (isset($gis_data[$index]['LINESTRING'][$i]['y'])
|
||||
&& trim((string) $gis_data[$index]['LINESTRING'][$i]['y']) != ''
|
||||
? $gis_data[$index]['LINESTRING'][$i]['y'] : $empty) . ',';
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$wkt .= (isset($gisData[$index]['LINESTRING'][$i]['x'])
|
||||
&& trim((string) $gisData[$index]['LINESTRING'][$i]['x']) != ''
|
||||
? $gisData[$index]['LINESTRING'][$i]['x'] : $empty)
|
||||
. ' ' . (isset($gisData[$index]['LINESTRING'][$i]['y'])
|
||||
&& trim((string) $gisData[$index]['LINESTRING'][$i]['y']) != ''
|
||||
? $gisData[$index]['LINESTRING'][$i]['y'] : $empty) . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -272,14 +272,14 @@ class GisLineString extends GisGeometry
|
||||
{
|
||||
// Trim to remove leading 'LINESTRING(' and trailing ')'
|
||||
$linestring = mb_substr($wkt, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($linestring, null);
|
||||
$pointsArr = $this->extractPoints1d($linestring, null);
|
||||
|
||||
$no_of_points = count($points_arr);
|
||||
$coords = ['no_of_points' => $no_of_points];
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
$noOfPoints = count($pointsArr);
|
||||
$coords = ['no_of_points' => $noOfPoints];
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$coords[$i] = [
|
||||
'x' => $points_arr[$i][0],
|
||||
'y' => $points_arr[$i][1],
|
||||
'x' => $pointsArr[$i][0],
|
||||
'y' => $pointsArr[$i][1],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -55,75 +55,75 @@ class GisMultiLineString extends GisGeometry
|
||||
*/
|
||||
public function scaleRow(string $spatial): ScaleData|null
|
||||
{
|
||||
$min_max = null;
|
||||
$minMax = null;
|
||||
|
||||
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
|
||||
$multilinestirng = mb_substr($spatial, 17, -2);
|
||||
$multilineString = mb_substr($spatial, 17, -2);
|
||||
// Separate each linestring
|
||||
$linestirngs = explode('),(', $multilinestirng);
|
||||
$linestrings = explode('),(', $multilineString);
|
||||
|
||||
foreach ($linestirngs as $linestring) {
|
||||
$min_max = $this->setMinMax($linestring, $min_max);
|
||||
foreach ($linestrings as $linestring) {
|
||||
$minMax = $this->setMinMax($linestring, $minMax);
|
||||
}
|
||||
|
||||
return $min_max;
|
||||
return $minMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$line_color = $image->colorAllocate(...$color);
|
||||
$lineColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
|
||||
$multilinestirng = mb_substr($spatial, 17, -2);
|
||||
$multilineString = mb_substr($spatial, 17, -2);
|
||||
// Separate each linestring
|
||||
$linestirngs = explode('),(', $multilinestirng);
|
||||
$linestrings = explode('),(', $multilineString);
|
||||
|
||||
$first_line = true;
|
||||
foreach ($linestirngs as $linestring) {
|
||||
$points_arr = $this->extractPoints1d($linestring, $scale_data);
|
||||
foreach ($points_arr as $point) {
|
||||
if (isset($temp_point)) {
|
||||
$firstLine = true;
|
||||
foreach ($linestrings as $linestring) {
|
||||
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
|
||||
foreach ($pointsArr as $point) {
|
||||
if (isset($tempPoint)) {
|
||||
// draw line section
|
||||
$image->line(
|
||||
(int) round($temp_point[0]),
|
||||
(int) round($temp_point[1]),
|
||||
(int) round($tempPoint[0]),
|
||||
(int) round($tempPoint[1]),
|
||||
(int) round($point[0]),
|
||||
(int) round($point[1]),
|
||||
$line_color,
|
||||
$lineColor,
|
||||
);
|
||||
}
|
||||
|
||||
$temp_point = $point;
|
||||
$tempPoint = $point;
|
||||
}
|
||||
|
||||
unset($temp_point);
|
||||
unset($tempPoint);
|
||||
// print label if applicable
|
||||
if ($label !== '' && $first_line) {
|
||||
if ($label !== '' && $firstLine) {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($points_arr[1][0]),
|
||||
(int) round($points_arr[1][1]),
|
||||
(int) round($pointsArr[1][0]),
|
||||
(int) round($pointsArr[1][1]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
}
|
||||
|
||||
$first_line = false;
|
||||
$firstLine = false;
|
||||
}
|
||||
|
||||
return $image;
|
||||
@ -132,14 +132,14 @@ class GisMultiLineString extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label Label for the GIS MULTILINESTRING object
|
||||
* @param int[] $color Color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label Label for the GIS MULTILINESTRING object
|
||||
* @param int[] $color Color for the GIS MULTILINESTRING object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scale_data, TCPDF $pdf): TCPDF
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scaleData, TCPDF $pdf): TCPDF
|
||||
{
|
||||
$line = [
|
||||
'width' => 1.5,
|
||||
@ -147,31 +147,31 @@ class GisMultiLineString extends GisGeometry
|
||||
];
|
||||
|
||||
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
|
||||
$multilinestirng = mb_substr($spatial, 17, -2);
|
||||
$multilineString = mb_substr($spatial, 17, -2);
|
||||
// Separate each linestring
|
||||
$linestirngs = explode('),(', $multilinestirng);
|
||||
$linestrings = explode('),(', $multilineString);
|
||||
|
||||
$first_line = true;
|
||||
foreach ($linestirngs as $linestring) {
|
||||
$points_arr = $this->extractPoints1d($linestring, $scale_data);
|
||||
foreach ($points_arr as $point) {
|
||||
if (isset($temp_point)) {
|
||||
$firstLine = true;
|
||||
foreach ($linestrings as $linestring) {
|
||||
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
|
||||
foreach ($pointsArr as $point) {
|
||||
if (isset($tempPoint)) {
|
||||
// draw line section
|
||||
$pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line);
|
||||
$pdf->Line($tempPoint[0], $tempPoint[1], $point[0], $point[1], $line);
|
||||
}
|
||||
|
||||
$temp_point = $point;
|
||||
$tempPoint = $point;
|
||||
}
|
||||
|
||||
unset($temp_point);
|
||||
unset($tempPoint);
|
||||
// print label
|
||||
if ($label !== '' && $first_line) {
|
||||
$pdf->setXY($points_arr[1][0], $points_arr[1][1]);
|
||||
if ($label !== '' && $firstLine) {
|
||||
$pdf->setXY($pointsArr[1][0], $pointsArr[1][1]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
|
||||
$first_line = false;
|
||||
$firstLine = false;
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
@ -180,16 +180,16 @@ class GisMultiLineString extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label Label for the GIS MULTILINESTRING object
|
||||
* @param int[] $color Color for the GIS MULTILINESTRING object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTILINESTRING object
|
||||
* @param string $label Label for the GIS MULTILINESTRING object
|
||||
* @param int[] $color Color for the GIS MULTILINESTRING object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$line_options = [
|
||||
$lineOptions = [
|
||||
'name' => $label,
|
||||
'class' => 'linestring vector',
|
||||
'fill' => 'none',
|
||||
@ -198,22 +198,22 @@ class GisMultiLineString extends GisGeometry
|
||||
];
|
||||
|
||||
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
|
||||
$multilinestirng = mb_substr($spatial, 17, -2);
|
||||
$multilineString = mb_substr($spatial, 17, -2);
|
||||
// Separate each linestring
|
||||
$linestirngs = explode('),(', $multilinestirng);
|
||||
$linestrings = explode('),(', $multilineString);
|
||||
|
||||
$row = '';
|
||||
foreach ($linestirngs as $linestring) {
|
||||
$points_arr = $this->extractPoints1d($linestring, $scale_data);
|
||||
foreach ($linestrings as $linestring) {
|
||||
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
|
||||
|
||||
$row .= '<polyline points="';
|
||||
foreach ($points_arr as $point) {
|
||||
foreach ($pointsArr as $point) {
|
||||
$row .= $point[0] . ',' . $point[1] . ' ';
|
||||
}
|
||||
|
||||
$row .= '"';
|
||||
$line_options['id'] = $label . $this->getRandomId();
|
||||
foreach ($line_options as $option => $val) {
|
||||
$lineOptions['id'] = $label . $this->getRandomId();
|
||||
foreach ($lineOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -236,16 +236,16 @@ class GisMultiLineString extends GisGeometry
|
||||
*/
|
||||
public function prepareRowAsOl(string $spatial, int $srid, string $label, array $color): string
|
||||
{
|
||||
$stroke_style = [
|
||||
$strokeStyle = [
|
||||
'color' => $color,
|
||||
'width' => 2,
|
||||
];
|
||||
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . ')';
|
||||
if ($label !== '') {
|
||||
$text_style = ['text' => $label];
|
||||
$style .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$textStyle = ['text' => $label];
|
||||
$style .= ', text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -264,36 +264,36 @@ class GisMultiLineString extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$data_row = $gis_data[$index]['MULTILINESTRING'];
|
||||
$dataRow = $gisData[$index]['MULTILINESTRING'];
|
||||
|
||||
$no_of_lines = $data_row['no_of_lines'] ?? 1;
|
||||
if ($no_of_lines < 1) {
|
||||
$no_of_lines = 1;
|
||||
$noOfLines = $dataRow['no_of_lines'] ?? 1;
|
||||
if ($noOfLines < 1) {
|
||||
$noOfLines = 1;
|
||||
}
|
||||
|
||||
$wkt = 'MULTILINESTRING(';
|
||||
for ($i = 0; $i < $no_of_lines; $i++) {
|
||||
$no_of_points = $data_row[$i]['no_of_points'] ?? 2;
|
||||
if ($no_of_points < 2) {
|
||||
$no_of_points = 2;
|
||||
for ($i = 0; $i < $noOfLines; $i++) {
|
||||
$noOfPoints = $dataRow[$i]['no_of_points'] ?? 2;
|
||||
if ($noOfPoints < 2) {
|
||||
$noOfPoints = 2;
|
||||
}
|
||||
|
||||
$wkt .= '(';
|
||||
for ($j = 0; $j < $no_of_points; $j++) {
|
||||
$wkt .= (isset($data_row[$i][$j]['x'])
|
||||
&& trim((string) $data_row[$i][$j]['x']) != ''
|
||||
? $data_row[$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($data_row[$i][$j]['y'])
|
||||
&& trim((string) $data_row[$i][$j]['y']) != ''
|
||||
? $data_row[$i][$j]['y'] : $empty) . ',';
|
||||
for ($j = 0; $j < $noOfPoints; $j++) {
|
||||
$wkt .= (isset($dataRow[$i][$j]['x'])
|
||||
&& trim((string) $dataRow[$i][$j]['x']) != ''
|
||||
? $dataRow[$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($dataRow[$i][$j]['y'])
|
||||
&& trim((string) $dataRow[$i][$j]['y']) != ''
|
||||
? $dataRow[$i][$j]['y'] : $empty) . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -308,16 +308,16 @@ class GisMultiLineString extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT for the data from ESRI shape files.
|
||||
*
|
||||
* @param array $row_data GIS data
|
||||
* @param array $rowData GIS data
|
||||
*
|
||||
* @return string the WKT for the data from ESRI shape files
|
||||
*/
|
||||
public function getShape(array $row_data): string
|
||||
public function getShape(array $rowData): string
|
||||
{
|
||||
$wkt = 'MULTILINESTRING(';
|
||||
for ($i = 0; $i < $row_data['numparts']; $i++) {
|
||||
for ($i = 0; $i < $rowData['numparts']; $i++) {
|
||||
$wkt .= '(';
|
||||
foreach ($row_data['parts'][$i]['points'] as $point) {
|
||||
foreach ($rowData['parts'][$i]['points'] as $point) {
|
||||
$wkt .= $point['x'] . ' ' . $point['y'] . ',';
|
||||
}
|
||||
|
||||
@ -340,15 +340,15 @@ class GisMultiLineString extends GisGeometry
|
||||
protected function getCoordinateParams(string $wkt): array
|
||||
{
|
||||
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
|
||||
$wkt_multilinestring = mb_substr($wkt, 17, -2);
|
||||
$wkt_linestrings = explode('),(', $wkt_multilinestring);
|
||||
$coords = ['no_of_lines' => count($wkt_linestrings)];
|
||||
$wktMultilinestring = mb_substr($wkt, 17, -2);
|
||||
$wktLinestrings = explode('),(', $wktMultilinestring);
|
||||
$coords = ['no_of_lines' => count($wktLinestrings)];
|
||||
|
||||
foreach ($wkt_linestrings as $j => $wkt_linestring) {
|
||||
$points = $this->extractPoints1d($wkt_linestring, null);
|
||||
$no_of_points = count($points);
|
||||
$coords[$j] = ['no_of_points' => $no_of_points];
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
foreach ($wktLinestrings as $j => $wktLinestring) {
|
||||
$points = $this->extractPoints1d($wktLinestring, null);
|
||||
$noOfPoints = count($points);
|
||||
$coords[$j] = ['no_of_points' => $noOfPoints];
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$coords[$j][$i] = [
|
||||
'x' => $points[$i][0],
|
||||
'y' => $points[$i][1],
|
||||
|
||||
@ -63,27 +63,27 @@ class GisMultiPoint extends GisGeometry
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$point_color = $image->colorAllocate(...$color);
|
||||
$pointColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
|
||||
$multipoint = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($multipoint, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($multipoint, $scaleData);
|
||||
|
||||
foreach ($points_arr as $point) {
|
||||
foreach ($pointsArr as $point) {
|
||||
// draw a small circle to mark the point
|
||||
if ($point[0] == '' || $point[1] == '') {
|
||||
continue;
|
||||
@ -96,16 +96,16 @@ class GisMultiPoint extends GisGeometry
|
||||
7,
|
||||
0,
|
||||
360,
|
||||
$point_color,
|
||||
$pointColor,
|
||||
);
|
||||
}
|
||||
|
||||
// print label for each point
|
||||
if ($label !== '' && ($points_arr[0][0] != '' && $points_arr[0][1] != '')) {
|
||||
if ($label !== '' && ($pointsArr[0][0] != '' && $pointsArr[0][1] != '')) {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($points_arr[0][0]),
|
||||
(int) round($points_arr[0][1]),
|
||||
(int) round($pointsArr[0][0]),
|
||||
(int) round($pointsArr[0][1]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
@ -117,10 +117,10 @@ class GisMultiPoint extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label Label for the GIS MULTIPOINT object
|
||||
* @param int[] $color Color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label Label for the GIS MULTIPOINT object
|
||||
* @param int[] $color Color for the GIS MULTIPOINT object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
@ -128,7 +128,7 @@ class GisMultiPoint extends GisGeometry
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
TCPDF $pdf,
|
||||
): TCPDF {
|
||||
$line = [
|
||||
@ -138,9 +138,9 @@ class GisMultiPoint extends GisGeometry
|
||||
|
||||
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
|
||||
$multipoint = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($multipoint, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($multipoint, $scaleData);
|
||||
|
||||
foreach ($points_arr as $point) {
|
||||
foreach ($pointsArr as $point) {
|
||||
// draw a small circle to mark the point
|
||||
if ($point[0] == '' || $point[1] == '') {
|
||||
continue;
|
||||
@ -150,8 +150,8 @@ class GisMultiPoint extends GisGeometry
|
||||
}
|
||||
|
||||
// print label for each point
|
||||
if ($label !== '' && ($points_arr[0][0] != '' && $points_arr[0][1] != '')) {
|
||||
$pdf->setXY($points_arr[0][0], $points_arr[0][1]);
|
||||
if ($label !== '' && ($pointsArr[0][0] != '' && $pointsArr[0][1] != '')) {
|
||||
$pdf->setXY($pointsArr[0][0], $pointsArr[0][1]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
@ -162,16 +162,16 @@ class GisMultiPoint extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label Label for the GIS MULTIPOINT object
|
||||
* @param int[] $color Color for the GIS MULTIPOINT object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTIPOINT object
|
||||
* @param string $label Label for the GIS MULTIPOINT object
|
||||
* @param int[] $color Color for the GIS MULTIPOINT object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$point_options = [
|
||||
$pointOptions = [
|
||||
'name' => $label,
|
||||
'class' => 'multipoint vector',
|
||||
'fill' => 'white',
|
||||
@ -181,18 +181,18 @@ class GisMultiPoint extends GisGeometry
|
||||
|
||||
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
|
||||
$multipoint = mb_substr($spatial, 11, -1);
|
||||
$points_arr = $this->extractPoints1d($multipoint, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($multipoint, $scaleData);
|
||||
|
||||
$row = '';
|
||||
foreach ($points_arr as $point) {
|
||||
foreach ($pointsArr as $point) {
|
||||
if ($point[0] === 0.0 || $point[1] === 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row .= '<circle cx="' . $point[0] . '" cy="'
|
||||
. $point[1] . '" r="3"';
|
||||
$point_options['id'] = $label . $this->getRandomId();
|
||||
foreach ($point_options as $option => $val) {
|
||||
$pointOptions['id'] = $label . $this->getRandomId();
|
||||
foreach ($pointOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -219,23 +219,23 @@ class GisMultiPoint extends GisGeometry
|
||||
string $label,
|
||||
array $color,
|
||||
): string {
|
||||
$fill_style = ['color' => 'white'];
|
||||
$stroke_style = [
|
||||
$fillStyle = ['color' => 'white'];
|
||||
$strokeStyle = [
|
||||
'color' => $color,
|
||||
'width' => 2,
|
||||
];
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'image: new ol.style.Circle({'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . '),'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fillStyle) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . '),'
|
||||
. 'radius: 3'
|
||||
. '})';
|
||||
if ($label !== '') {
|
||||
$text_style = [
|
||||
$textStyle = [
|
||||
'text' => $label,
|
||||
'offsetY' => -9,
|
||||
];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -254,27 +254,27 @@ class GisMultiPoint extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Multipoint does not adhere to this
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Multipoint does not adhere to this
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$no_of_points = $gis_data[$index]['MULTIPOINT']['no_of_points'] ?? 1;
|
||||
if ($no_of_points < 1) {
|
||||
$no_of_points = 1;
|
||||
$noOfPoints = $gisData[$index]['MULTIPOINT']['no_of_points'] ?? 1;
|
||||
if ($noOfPoints < 1) {
|
||||
$noOfPoints = 1;
|
||||
}
|
||||
|
||||
$wkt = 'MULTIPOINT(';
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
$wkt .= (isset($gis_data[$index]['MULTIPOINT'][$i]['x'])
|
||||
&& trim((string) $gis_data[$index]['MULTIPOINT'][$i]['x']) != ''
|
||||
? $gis_data[$index]['MULTIPOINT'][$i]['x'] : '')
|
||||
. ' ' . (isset($gis_data[$index]['MULTIPOINT'][$i]['y'])
|
||||
&& trim((string) $gis_data[$index]['MULTIPOINT'][$i]['y']) != ''
|
||||
? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ',';
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$wkt .= (isset($gisData[$index]['MULTIPOINT'][$i]['x'])
|
||||
&& trim((string) $gisData[$index]['MULTIPOINT'][$i]['x']) != ''
|
||||
? $gisData[$index]['MULTIPOINT'][$i]['x'] : '')
|
||||
. ' ' . (isset($gisData[$index]['MULTIPOINT'][$i]['y'])
|
||||
&& trim((string) $gisData[$index]['MULTIPOINT'][$i]['y']) != ''
|
||||
? $gisData[$index]['MULTIPOINT'][$i]['y'] : '') . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -285,16 +285,16 @@ class GisMultiPoint extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT for the data from ESRI shape files.
|
||||
*
|
||||
* @param array $row_data GIS data
|
||||
* @param array $rowData GIS data
|
||||
*
|
||||
* @return string the WKT for the data from ESRI shape files
|
||||
*/
|
||||
public function getShape(array $row_data): string
|
||||
public function getShape(array $rowData): string
|
||||
{
|
||||
$wkt = 'MULTIPOINT(';
|
||||
for ($i = 0; $i < $row_data['numpoints']; $i++) {
|
||||
$wkt .= $row_data['points'][$i]['x'] . ' '
|
||||
. $row_data['points'][$i]['y'] . ',';
|
||||
for ($i = 0; $i < $rowData['numpoints']; $i++) {
|
||||
$wkt .= $rowData['points'][$i]['x'] . ' '
|
||||
. $rowData['points'][$i]['y'] . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -312,12 +312,12 @@ class GisMultiPoint extends GisGeometry
|
||||
protected function getCoordinateParams(string $wkt): array
|
||||
{
|
||||
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
|
||||
$wkt_points = mb_substr($wkt, 11, -1);
|
||||
$points = $this->extractPoints1d($wkt_points, null);
|
||||
$wktPoints = mb_substr($wkt, 11, -1);
|
||||
$points = $this->extractPoints1d($wktPoints, null);
|
||||
|
||||
$no_of_points = count($points);
|
||||
$coords = ['no_of_points' => $no_of_points];
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
$noOfPoints = count($points);
|
||||
$coords = ['no_of_points' => $noOfPoints];
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$coords[$i] = [
|
||||
'x' => $points[$i][0],
|
||||
'y' => $points[$i][1],
|
||||
|
||||
@ -57,38 +57,38 @@ class GisMultiPolygon extends GisGeometry
|
||||
*/
|
||||
public function scaleRow(string $spatial): ScaleData|null
|
||||
{
|
||||
$min_max = null;
|
||||
$minMax = null;
|
||||
|
||||
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
|
||||
$multipolygon = mb_substr($spatial, 15, -3);
|
||||
$wkt_polygons = explode(')),((', $multipolygon);
|
||||
$wktPolygons = explode(')),((', $multipolygon);
|
||||
|
||||
foreach ($wkt_polygons as $wkt_polygon) {
|
||||
$wkt_outer_ring = explode('),(', $wkt_polygon)[0];
|
||||
$min_max = $this->setMinMax($wkt_outer_ring, $min_max);
|
||||
foreach ($wktPolygons as $wktPolygon) {
|
||||
$wktOuterRing = explode('),(', $wktPolygon)[0];
|
||||
$minMax = $this->setMinMax($wktOuterRing, $minMax);
|
||||
}
|
||||
|
||||
return $min_max;
|
||||
return $minMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$fill_color = $image->colorAllocate(...$color);
|
||||
$fillColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
|
||||
$multipolygon = mb_substr($spatial, 15, -3);
|
||||
@ -96,34 +96,34 @@ class GisMultiPolygon extends GisGeometry
|
||||
$polygons = explode(')),((', $multipolygon);
|
||||
|
||||
foreach ($polygons as $polygon) {
|
||||
$wkt_rings = explode('),(', $polygon);
|
||||
$wktRings = explode('),(', $polygon);
|
||||
|
||||
$points_arr = [];
|
||||
$pointsArr = [];
|
||||
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$ring = $this->extractPoints1dLinear($wkt_ring, $scale_data);
|
||||
$points_arr = array_merge($points_arr, $ring);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$ring = $this->extractPoints1dLinear($wktRing, $scaleData);
|
||||
$pointsArr = array_merge($pointsArr, $ring);
|
||||
}
|
||||
|
||||
// draw polygon
|
||||
$image->filledPolygon($points_arr, $fill_color);
|
||||
$image->filledPolygon($pointsArr, $fillColor);
|
||||
// mark label point if applicable
|
||||
if (isset($label_point)) {
|
||||
if (isset($labelPoint)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label_point = [
|
||||
$points_arr[2],
|
||||
$points_arr[3],
|
||||
$labelPoint = [
|
||||
$pointsArr[2],
|
||||
$pointsArr[3],
|
||||
];
|
||||
}
|
||||
|
||||
// print label if applicable
|
||||
if ($label !== '' && isset($label_point)) {
|
||||
if ($label !== '' && isset($labelPoint)) {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($label_point[0]),
|
||||
(int) round($label_point[1]),
|
||||
(int) round($labelPoint[0]),
|
||||
(int) round($labelPoint[1]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
@ -135,45 +135,45 @@ class GisMultiPolygon extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label Label for the GIS MULTIPOLYGON object
|
||||
* @param int[] $color Color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label Label for the GIS MULTIPOLYGON object
|
||||
* @param int[] $color Color for the GIS MULTIPOLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scale_data, TCPDF $pdf): TCPDF
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scaleData, TCPDF $pdf): TCPDF
|
||||
{
|
||||
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
|
||||
$multipolygon = mb_substr($spatial, 15, -3);
|
||||
// Separate each polygon
|
||||
$wkt_polygons = explode(')),((', $multipolygon);
|
||||
$wktPolygons = explode(')),((', $multipolygon);
|
||||
|
||||
foreach ($wkt_polygons as $wkt_polygon) {
|
||||
$wkt_rings = explode('),(', $wkt_polygon);
|
||||
$points_arr = [];
|
||||
foreach ($wktPolygons as $wktPolygon) {
|
||||
$wktRings = explode('),(', $wktPolygon);
|
||||
$pointsArr = [];
|
||||
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$ring = $this->extractPoints1dLinear($wkt_ring, $scale_data);
|
||||
$points_arr = array_merge($points_arr, $ring);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$ring = $this->extractPoints1dLinear($wktRing, $scaleData);
|
||||
$pointsArr = array_merge($pointsArr, $ring);
|
||||
}
|
||||
|
||||
// draw polygon
|
||||
$pdf->Polygon($points_arr, 'F*', [], $color, true);
|
||||
$pdf->Polygon($pointsArr, 'F*', [], $color, true);
|
||||
// mark label point if applicable
|
||||
if (isset($label_point)) {
|
||||
if (isset($labelPoint)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label_point = [
|
||||
$points_arr[2],
|
||||
$points_arr[3],
|
||||
$labelPoint = [
|
||||
$pointsArr[2],
|
||||
$pointsArr[3],
|
||||
];
|
||||
}
|
||||
|
||||
// print label if applicable
|
||||
if ($label !== '' && isset($label_point)) {
|
||||
$pdf->setXY($label_point[0], $label_point[1]);
|
||||
if ($label !== '' && isset($labelPoint)) {
|
||||
$pdf->setXY($labelPoint[0], $labelPoint[1]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
@ -184,16 +184,16 @@ class GisMultiPolygon extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label Label for the GIS MULTIPOLYGON object
|
||||
* @param int[] $color Color for the GIS MULTIPOLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS MULTIPOLYGON object
|
||||
* @param string $label Label for the GIS MULTIPOLYGON object
|
||||
* @param int[] $color Color for the GIS MULTIPOLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$polygon_options = [
|
||||
$polygonOptions = [
|
||||
'name' => $label,
|
||||
'class' => 'multipolygon vector',
|
||||
'stroke' => 'black',
|
||||
@ -208,19 +208,19 @@ class GisMultiPolygon extends GisGeometry
|
||||
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
|
||||
$multipolygon = mb_substr($spatial, 15, -3);
|
||||
// Separate each polygon
|
||||
$wkt_polygons = explode(')),((', $multipolygon);
|
||||
$wktPolygons = explode(')),((', $multipolygon);
|
||||
|
||||
foreach ($wkt_polygons as $wkt_polygon) {
|
||||
foreach ($wktPolygons as $wktPolygon) {
|
||||
$row .= '<path d="';
|
||||
|
||||
$wkt_rings = explode('),(', $wkt_polygon);
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$row .= $this->drawPath($wkt_ring, $scale_data);
|
||||
$wktRings = explode('),(', $wktPolygon);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$row .= $this->drawPath($wktRing, $scaleData);
|
||||
}
|
||||
|
||||
$polygon_options['id'] = $label . $this->getRandomId();
|
||||
$polygonOptions['id'] = $label . $this->getRandomId();
|
||||
$row .= '"';
|
||||
foreach ($polygon_options as $option => $val) {
|
||||
foreach ($polygonOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -244,17 +244,17 @@ class GisMultiPolygon extends GisGeometry
|
||||
public function prepareRowAsOl(string $spatial, int $srid, string $label, array $color): string
|
||||
{
|
||||
$color[] = 0.8;
|
||||
$fill_style = ['color' => $color];
|
||||
$stroke_style = [
|
||||
$fillStyle = ['color' => $color];
|
||||
$strokeStyle = [
|
||||
'color' => [0, 0, 0],
|
||||
'width' => 0.5,
|
||||
];
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fillStyle) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . ')';
|
||||
if ($label !== '') {
|
||||
$text_style = ['text' => $label];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$textStyle = ['text' => $label];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -273,18 +273,18 @@ class GisMultiPolygon extends GisGeometry
|
||||
/**
|
||||
* Draws a ring of the polygon using SVG path element.
|
||||
*
|
||||
* @param string $polygon The ring
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $polygon The ring
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code to draw the ring
|
||||
*/
|
||||
private function drawPath(string $polygon, array $scale_data): string
|
||||
private function drawPath(string $polygon, array $scaleData): string
|
||||
{
|
||||
$points_arr = $this->extractPoints1d($polygon, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($polygon, $scaleData);
|
||||
|
||||
$row = ' M ' . $points_arr[0][0] . ', ' . $points_arr[0][1];
|
||||
$other_points = array_slice($points_arr, 1, count($points_arr) - 2);
|
||||
foreach ($other_points as $point) {
|
||||
$row = ' M ' . $pointsArr[0][0] . ', ' . $pointsArr[0][1];
|
||||
$otherPoints = array_slice($pointsArr, 1, count($pointsArr) - 2);
|
||||
foreach ($otherPoints as $point) {
|
||||
$row .= ' L ' . $point[0] . ', ' . $point[1];
|
||||
}
|
||||
|
||||
@ -296,43 +296,43 @@ class GisMultiPolygon extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$data_row = $gis_data[$index]['MULTIPOLYGON'];
|
||||
$dataRow = $gisData[$index]['MULTIPOLYGON'];
|
||||
|
||||
$no_of_polygons = $data_row['no_of_polygons'] ?? 1;
|
||||
if ($no_of_polygons < 1) {
|
||||
$no_of_polygons = 1;
|
||||
$noOfPolygons = $dataRow['no_of_polygons'] ?? 1;
|
||||
if ($noOfPolygons < 1) {
|
||||
$noOfPolygons = 1;
|
||||
}
|
||||
|
||||
$wkt = 'MULTIPOLYGON(';
|
||||
for ($k = 0; $k < $no_of_polygons; $k++) {
|
||||
$no_of_lines = $data_row[$k]['no_of_lines'] ?? 1;
|
||||
if ($no_of_lines < 1) {
|
||||
$no_of_lines = 1;
|
||||
for ($k = 0; $k < $noOfPolygons; $k++) {
|
||||
$noOfLines = $dataRow[$k]['no_of_lines'] ?? 1;
|
||||
if ($noOfLines < 1) {
|
||||
$noOfLines = 1;
|
||||
}
|
||||
|
||||
$wkt .= '(';
|
||||
for ($i = 0; $i < $no_of_lines; $i++) {
|
||||
$no_of_points = $data_row[$k][$i]['no_of_points'] ?? 4;
|
||||
if ($no_of_points < 4) {
|
||||
$no_of_points = 4;
|
||||
for ($i = 0; $i < $noOfLines; $i++) {
|
||||
$noOfPoints = $dataRow[$k][$i]['no_of_points'] ?? 4;
|
||||
if ($noOfPoints < 4) {
|
||||
$noOfPoints = 4;
|
||||
}
|
||||
|
||||
$wkt .= '(';
|
||||
for ($j = 0; $j < $no_of_points; $j++) {
|
||||
$wkt .= (isset($data_row[$k][$i][$j]['x'])
|
||||
&& trim((string) $data_row[$k][$i][$j]['x']) != ''
|
||||
? $data_row[$k][$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($data_row[$k][$i][$j]['y'])
|
||||
&& trim((string) $data_row[$k][$i][$j]['y']) != ''
|
||||
? $data_row[$k][$i][$j]['y'] : $empty) . ',';
|
||||
for ($j = 0; $j < $noOfPoints; $j++) {
|
||||
$wkt .= (isset($dataRow[$k][$i][$j]['x'])
|
||||
&& trim((string) $dataRow[$k][$i][$j]['x']) != ''
|
||||
? $dataRow[$k][$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($dataRow[$k][$i][$j]['y'])
|
||||
&& trim((string) $dataRow[$k][$i][$j]['y']) != ''
|
||||
? $dataRow[$k][$i][$j]['y'] : $empty) . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -351,35 +351,35 @@ class GisMultiPolygon extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT for the data from ESRI shape files.
|
||||
*
|
||||
* @param array $row_data GIS data
|
||||
* @param array $rowData GIS data
|
||||
*
|
||||
* @return string the WKT for the data from ESRI shape files
|
||||
*/
|
||||
public function getShape(array $row_data): string
|
||||
public function getShape(array $rowData): string
|
||||
{
|
||||
// Determines whether each line ring is an inner ring or an outer ring.
|
||||
// If it's an inner ring get a point on the surface which can be used to
|
||||
// correctly classify inner rings to their respective outer rings.
|
||||
foreach ($row_data['parts'] as $i => $ring) {
|
||||
$row_data['parts'][$i]['isOuter'] = GisPolygon::isOuterRing($ring['points']);
|
||||
foreach ($rowData['parts'] as $i => $ring) {
|
||||
$rowData['parts'][$i]['isOuter'] = GisPolygon::isOuterRing($ring['points']);
|
||||
}
|
||||
|
||||
// Find points on surface for inner rings
|
||||
foreach ($row_data['parts'] as $i => $ring) {
|
||||
foreach ($rowData['parts'] as $i => $ring) {
|
||||
if ($ring['isOuter']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row_data['parts'][$i]['pointOnSurface'] = GisPolygon::getPointOnSurface($ring['points']);
|
||||
$rowData['parts'][$i]['pointOnSurface'] = GisPolygon::getPointOnSurface($ring['points']);
|
||||
}
|
||||
|
||||
// Classify inner rings to their respective outer rings.
|
||||
foreach ($row_data['parts'] as $j => $ring1) {
|
||||
foreach ($rowData['parts'] as $j => $ring1) {
|
||||
if ($ring1['isOuter']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($row_data['parts'] as $k => $ring2) {
|
||||
foreach ($rowData['parts'] as $k => $ring2) {
|
||||
if (! $ring2['isOuter']) {
|
||||
continue;
|
||||
}
|
||||
@ -391,16 +391,16 @@ class GisMultiPolygon extends GisGeometry
|
||||
}
|
||||
|
||||
if (! isset($ring2['inner'])) {
|
||||
$row_data['parts'][$k]['inner'] = [];
|
||||
$rowData['parts'][$k]['inner'] = [];
|
||||
}
|
||||
|
||||
$row_data['parts'][$k]['inner'][] = $j;
|
||||
$rowData['parts'][$k]['inner'][] = $j;
|
||||
}
|
||||
}
|
||||
|
||||
$wkt = 'MULTIPOLYGON(';
|
||||
// for each polygon
|
||||
foreach ($row_data['parts'] as $ring) {
|
||||
foreach ($rowData['parts'] as $ring) {
|
||||
if (! $ring['isOuter']) {
|
||||
continue;
|
||||
}
|
||||
@ -419,7 +419,7 @@ class GisMultiPolygon extends GisGeometry
|
||||
if (isset($ring['inner'])) {
|
||||
foreach ($ring['inner'] as $j) {
|
||||
$wkt .= ',('; // start of inner ring
|
||||
foreach ($row_data['parts'][$j]['points'] as $innerPoint) {
|
||||
foreach ($rowData['parts'][$j]['points'] as $innerPoint) {
|
||||
$wkt .= $innerPoint['x'] . ' ' . $innerPoint['y'] . ',';
|
||||
}
|
||||
|
||||
@ -446,18 +446,18 @@ class GisMultiPolygon extends GisGeometry
|
||||
protected function getCoordinateParams(string $wkt): array
|
||||
{
|
||||
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
|
||||
$wkt_multipolygon = mb_substr($wkt, 15, -3);
|
||||
$wkt_polygons = explode(')),((', $wkt_multipolygon);
|
||||
$coords = ['no_of_polygons' => count($wkt_polygons)];
|
||||
$wktMultiPolygon = mb_substr($wkt, 15, -3);
|
||||
$wktPolygons = explode(')),((', $wktMultiPolygon);
|
||||
$coords = ['no_of_polygons' => count($wktPolygons)];
|
||||
|
||||
foreach ($wkt_polygons as $k => $wkt_polygon) {
|
||||
$wkt_rings = explode('),(', $wkt_polygon);
|
||||
$coords[$k] = ['no_of_lines' => count($wkt_rings)];
|
||||
foreach ($wkt_rings as $j => $wkt_ring) {
|
||||
$points = $this->extractPoints1d($wkt_ring, null);
|
||||
$no_of_points = count($points);
|
||||
$coords[$k][$j] = ['no_of_points' => $no_of_points];
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
foreach ($wktPolygons as $k => $wktPolygon) {
|
||||
$wktRings = explode('),(', $wktPolygon);
|
||||
$coords[$k] = ['no_of_lines' => count($wktRings)];
|
||||
foreach ($wktRings as $j => $wktRing) {
|
||||
$points = $this->extractPoints1d($wktRing, null);
|
||||
$noOfPoints = count($points);
|
||||
$coords[$k][$j] = ['no_of_points' => $noOfPoints];
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$coords[$k][$j][$i] = [
|
||||
'x' => $points[$i][0],
|
||||
'y' => $points[$i][1],
|
||||
|
||||
@ -62,43 +62,43 @@ class GisPoint extends GisGeometry
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$point_color = $image->colorAllocate(...$color);
|
||||
$pointColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'POINT(' and trailing ')'
|
||||
$point = mb_substr($spatial, 6, -1);
|
||||
$points_arr = $this->extractPoints1dLinear($point, $scale_data);
|
||||
$pointsArr = $this->extractPoints1dLinear($point, $scaleData);
|
||||
|
||||
// draw a small circle to mark the point
|
||||
if ($points_arr[0] != '' && $points_arr[0] != '') {
|
||||
if ($pointsArr[0] != '' && $pointsArr[0] != '') {
|
||||
$image->arc(
|
||||
(int) round($points_arr[0]),
|
||||
(int) round($points_arr[1]),
|
||||
(int) round($pointsArr[0]),
|
||||
(int) round($pointsArr[1]),
|
||||
7,
|
||||
7,
|
||||
0,
|
||||
360,
|
||||
$point_color,
|
||||
$pointColor,
|
||||
);
|
||||
// print label if applicable
|
||||
if ($label !== '') {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($points_arr[0]),
|
||||
(int) round($points_arr[1]),
|
||||
(int) round($pointsArr[0]),
|
||||
(int) round($pointsArr[1]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
@ -111,10 +111,10 @@ class GisPoint extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label Label for the GIS POINT object
|
||||
* @param int[] $color Color for the GIS POINT object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label Label for the GIS POINT object
|
||||
* @param int[] $color Color for the GIS POINT object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
@ -122,7 +122,7 @@ class GisPoint extends GisGeometry
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
TCPDF $pdf,
|
||||
): TCPDF {
|
||||
$line = [
|
||||
@ -132,14 +132,14 @@ class GisPoint extends GisGeometry
|
||||
|
||||
// Trim to remove leading 'POINT(' and trailing ')'
|
||||
$point = mb_substr($spatial, 6, -1);
|
||||
$points_arr = $this->extractPoints1dLinear($point, $scale_data);
|
||||
$pointsArr = $this->extractPoints1dLinear($point, $scaleData);
|
||||
|
||||
// draw a small circle to mark the point
|
||||
if ($points_arr[0] != '' && $points_arr[1] != '') {
|
||||
$pdf->Circle($points_arr[0], $points_arr[1], 2, 0, 360, 'D', $line);
|
||||
if ($pointsArr[0] != '' && $pointsArr[1] != '') {
|
||||
$pdf->Circle($pointsArr[0], $pointsArr[1], 2, 0, 360, 'D', $line);
|
||||
// print label if applicable
|
||||
if ($label !== '') {
|
||||
$pdf->setXY($points_arr[0], $points_arr[1]);
|
||||
$pdf->setXY($pointsArr[0], $pointsArr[1]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
@ -151,16 +151,16 @@ class GisPoint extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label Label for the GIS POINT object
|
||||
* @param int[] $color Color for the GIS POINT object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POINT object
|
||||
* @param string $label Label for the GIS POINT object
|
||||
* @param int[] $color Color for the GIS POINT object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$point_options = [
|
||||
$pointOptions = [
|
||||
'name' => $label,
|
||||
'id' => $label . $this->getRandomId(),
|
||||
'class' => 'point vector',
|
||||
@ -171,13 +171,13 @@ class GisPoint extends GisGeometry
|
||||
|
||||
// Trim to remove leading 'POINT(' and trailing ')'
|
||||
$point = mb_substr($spatial, 6, -1);
|
||||
$points_arr = $this->extractPoints1dLinear($point, $scale_data);
|
||||
$pointsArr = $this->extractPoints1dLinear($point, $scaleData);
|
||||
|
||||
$row = '';
|
||||
if ($points_arr[0] !== 0.0 && $points_arr[1] !== 0.0) {
|
||||
$row .= '<circle cx="' . $points_arr[0]
|
||||
. '" cy="' . $points_arr[1] . '" r="3"';
|
||||
foreach ($point_options as $option => $val) {
|
||||
if ($pointsArr[0] !== 0.0 && $pointsArr[1] !== 0.0) {
|
||||
$row .= '<circle cx="' . $pointsArr[0]
|
||||
. '" cy="' . $pointsArr[1] . '" r="3"';
|
||||
foreach ($pointOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -204,23 +204,23 @@ class GisPoint extends GisGeometry
|
||||
string $label,
|
||||
array $color,
|
||||
): string {
|
||||
$fill_style = ['color' => 'white'];
|
||||
$stroke_style = [
|
||||
$fillStyle = ['color' => 'white'];
|
||||
$strokeStyle = [
|
||||
'color' => $color,
|
||||
'width' => 2,
|
||||
];
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'image: new ol.style.Circle({'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . '),'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fillStyle) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . '),'
|
||||
. 'radius: 3'
|
||||
. '})';
|
||||
if ($label !== '') {
|
||||
$text_style = [
|
||||
$textStyle = [
|
||||
'text' => $label,
|
||||
'offsetY' => -9,
|
||||
];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -239,35 +239,35 @@ class GisPoint extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Point does not adhere to this parameter
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Point does not adhere to this parameter
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
return 'POINT('
|
||||
. (isset($gis_data[$index]['POINT']['x'])
|
||||
&& trim((string) $gis_data[$index]['POINT']['x']) != ''
|
||||
? $gis_data[$index]['POINT']['x'] : '')
|
||||
. (isset($gisData[$index]['POINT']['x'])
|
||||
&& trim((string) $gisData[$index]['POINT']['x']) != ''
|
||||
? $gisData[$index]['POINT']['x'] : '')
|
||||
. ' '
|
||||
. (isset($gis_data[$index]['POINT']['y'])
|
||||
&& trim((string) $gis_data[$index]['POINT']['y']) != ''
|
||||
? $gis_data[$index]['POINT']['y'] : '') . ')';
|
||||
. (isset($gisData[$index]['POINT']['y'])
|
||||
&& trim((string) $gisData[$index]['POINT']['y']) != ''
|
||||
? $gisData[$index]['POINT']['y'] : '') . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the WKT for the data from ESRI shape files.
|
||||
*
|
||||
* @param array $row_data GIS data
|
||||
* @param array $rowData GIS data
|
||||
*
|
||||
* @return string the WKT for the data from ESRI shape files
|
||||
*/
|
||||
public function getShape(array $row_data): string
|
||||
public function getShape(array $rowData): string
|
||||
{
|
||||
return 'POINT(' . ($row_data['x'] ?? '')
|
||||
. ' ' . ($row_data['y'] ?? '') . ')';
|
||||
return 'POINT(' . ($rowData['x'] ?? '')
|
||||
. ' ' . ($rowData['y'] ?? '') . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,8 +280,8 @@ class GisPoint extends GisGeometry
|
||||
protected function getCoordinateParams(string $wkt): array
|
||||
{
|
||||
// Trim to remove leading 'POINT(' and trailing ')'
|
||||
$wkt_point = mb_substr($wkt, 6, -1);
|
||||
$points = $this->extractPoints1d($wkt_point, null);
|
||||
$wktPoint = mb_substr($wkt, 6, -1);
|
||||
$points = $this->extractPoints1d($wktPoint, null);
|
||||
|
||||
return [
|
||||
'x' => $points[0][0],
|
||||
|
||||
@ -62,48 +62,48 @@ class GisPolygon extends GisGeometry
|
||||
{
|
||||
// Trim to remove leading 'POLYGON((' and trailing '))'
|
||||
$polygon = mb_substr($spatial, 9, -2);
|
||||
$wkt_outer_ring = explode('),(', $polygon)[0];
|
||||
$wktOuterRing = explode('),(', $polygon)[0];
|
||||
|
||||
return $this->setMinMax($wkt_outer_ring);
|
||||
return $this->setMinMax($wktOuterRing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the PNG image object, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*/
|
||||
public function prepareRowAsPng(
|
||||
string $spatial,
|
||||
string $label,
|
||||
array $color,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
ImageWrapper $image,
|
||||
): ImageWrapper {
|
||||
// allocate colors
|
||||
$black = $image->colorAllocate(0, 0, 0);
|
||||
$fill_color = $image->colorAllocate(...$color);
|
||||
$fillColor = $image->colorAllocate(...$color);
|
||||
|
||||
// Trim to remove leading 'POLYGON((' and trailing '))'
|
||||
$polygon = mb_substr($spatial, 9, -2);
|
||||
|
||||
$points_arr = [];
|
||||
$wkt_rings = explode('),(', $polygon);
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$ring = $this->extractPoints1dLinear($wkt_ring, $scale_data);
|
||||
$points_arr = array_merge($points_arr, $ring);
|
||||
$pointsArr = [];
|
||||
$wktRings = explode('),(', $polygon);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$ring = $this->extractPoints1dLinear($wktRing, $scaleData);
|
||||
$pointsArr = array_merge($pointsArr, $ring);
|
||||
}
|
||||
|
||||
// draw polygon
|
||||
$image->filledPolygon($points_arr, $fill_color);
|
||||
$image->filledPolygon($pointsArr, $fillColor);
|
||||
// print label if applicable
|
||||
if ($label !== '') {
|
||||
$image->string(
|
||||
1,
|
||||
(int) round($points_arr[2]),
|
||||
(int) round($points_arr[3]),
|
||||
(int) round($pointsArr[2]),
|
||||
(int) round($pointsArr[3]),
|
||||
$label,
|
||||
$black,
|
||||
);
|
||||
@ -115,32 +115,32 @@ class GisPolygon extends GisGeometry
|
||||
/**
|
||||
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return TCPDF the modified TCPDF instance
|
||||
*/
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scale_data, TCPDF $pdf): TCPDF
|
||||
public function prepareRowAsPdf(string $spatial, string $label, array $color, array $scaleData, TCPDF $pdf): TCPDF
|
||||
{
|
||||
// Trim to remove leading 'POLYGON((' and trailing '))'
|
||||
$polygon = mb_substr($spatial, 9, -2);
|
||||
|
||||
$wkt_rings = explode('),(', $polygon);
|
||||
$wktRings = explode('),(', $polygon);
|
||||
|
||||
$points_arr = [];
|
||||
$pointsArr = [];
|
||||
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$ring = $this->extractPoints1dLinear($wkt_ring, $scale_data);
|
||||
$points_arr = array_merge($points_arr, $ring);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$ring = $this->extractPoints1dLinear($wktRing, $scaleData);
|
||||
$pointsArr = array_merge($pointsArr, $ring);
|
||||
}
|
||||
|
||||
// draw polygon
|
||||
$pdf->Polygon($points_arr, 'F*', [], $color, true);
|
||||
$pdf->Polygon($pointsArr, 'F*', [], $color, true);
|
||||
// print label if applicable
|
||||
if ($label !== '') {
|
||||
$pdf->setXY($points_arr[2], $points_arr[3]);
|
||||
$pdf->setXY($pointsArr[2], $pointsArr[3]);
|
||||
$pdf->setFontSize(5);
|
||||
$pdf->Cell(0, 0, $label);
|
||||
}
|
||||
@ -151,16 +151,16 @@ class GisPolygon extends GisGeometry
|
||||
/**
|
||||
* Prepares and returns the code related to a row in the GIS dataset as SVG.
|
||||
*
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $spatial GIS POLYGON object
|
||||
* @param string $label Label for the GIS POLYGON object
|
||||
* @param int[] $color Color for the GIS POLYGON object
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code related to a row in the GIS dataset
|
||||
*/
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scale_data): string
|
||||
public function prepareRowAsSvg(string $spatial, string $label, array $color, array $scaleData): string
|
||||
{
|
||||
$polygon_options = [
|
||||
$polygonOptions = [
|
||||
'name' => $label,
|
||||
'id' => $label . $this->getRandomId(),
|
||||
'class' => 'polygon vector',
|
||||
@ -176,13 +176,13 @@ class GisPolygon extends GisGeometry
|
||||
|
||||
$row = '<path d="';
|
||||
|
||||
$wkt_rings = explode('),(', $polygon);
|
||||
foreach ($wkt_rings as $wkt_ring) {
|
||||
$row .= $this->drawPath($wkt_ring, $scale_data);
|
||||
$wktRings = explode('),(', $polygon);
|
||||
foreach ($wktRings as $wktRing) {
|
||||
$row .= $this->drawPath($wktRing, $scaleData);
|
||||
}
|
||||
|
||||
$row .= '"';
|
||||
foreach ($polygon_options as $option => $val) {
|
||||
foreach ($polygonOptions as $option => $val) {
|
||||
$row .= ' ' . $option . '="' . $val . '"';
|
||||
}
|
||||
|
||||
@ -205,17 +205,17 @@ class GisPolygon extends GisGeometry
|
||||
public function prepareRowAsOl(string $spatial, int $srid, string $label, array $color): string
|
||||
{
|
||||
$color[] = 0.8;
|
||||
$fill_style = ['color' => $color];
|
||||
$stroke_style = [
|
||||
$fillStyle = ['color' => $color];
|
||||
$strokeStyle = [
|
||||
'color' => [0, 0, 0],
|
||||
'width' => 0.5,
|
||||
];
|
||||
$style = 'new ol.style.Style({'
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fill_style) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
|
||||
. 'fill: new ol.style.Fill(' . json_encode($fillStyle) . '),'
|
||||
. 'stroke: new ol.style.Stroke(' . json_encode($strokeStyle) . ')';
|
||||
if ($label !== '') {
|
||||
$text_style = ['text' => $label];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($text_style) . ')';
|
||||
$textStyle = ['text' => $label];
|
||||
$style .= ',text: new ol.style.Text(' . json_encode($textStyle) . ')';
|
||||
}
|
||||
|
||||
$style .= '})';
|
||||
@ -234,18 +234,18 @@ class GisPolygon extends GisGeometry
|
||||
/**
|
||||
* Draws a ring of the polygon using SVG path element.
|
||||
*
|
||||
* @param string $polygon The ring
|
||||
* @param array $scale_data Array containing data related to scaling
|
||||
* @param string $polygon The ring
|
||||
* @param array $scaleData Array containing data related to scaling
|
||||
*
|
||||
* @return string the code to draw the ring
|
||||
*/
|
||||
private function drawPath(string $polygon, array $scale_data): string
|
||||
private function drawPath(string $polygon, array $scaleData): string
|
||||
{
|
||||
$points_arr = $this->extractPoints1d($polygon, $scale_data);
|
||||
$pointsArr = $this->extractPoints1d($polygon, $scaleData);
|
||||
|
||||
$row = ' M ' . $points_arr[0][0] . ', ' . $points_arr[0][1];
|
||||
$other_points = array_slice($points_arr, 1, count($points_arr) - 2);
|
||||
foreach ($other_points as $point) {
|
||||
$row = ' M ' . $pointsArr[0][0] . ', ' . $pointsArr[0][1];
|
||||
$otherPoints = array_slice($pointsArr, 1, count($pointsArr) - 2);
|
||||
foreach ($otherPoints as $point) {
|
||||
$row .= ' L ' . $point[0] . ', ' . $point[1];
|
||||
}
|
||||
|
||||
@ -257,34 +257,34 @@ class GisPolygon extends GisGeometry
|
||||
/**
|
||||
* Generate the WKT with the set of parameters passed by the GIS editor.
|
||||
*
|
||||
* @param array $gis_data GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
* @param array $gisData GIS data
|
||||
* @param int $index Index into the parameter object
|
||||
* @param string|null $empty Value for empty points
|
||||
*
|
||||
* @return string WKT with the set of parameters passed by the GIS editor
|
||||
*/
|
||||
public function generateWkt(array $gis_data, int $index, string|null $empty = ''): string
|
||||
public function generateWkt(array $gisData, int $index, string|null $empty = ''): string
|
||||
{
|
||||
$no_of_lines = $gis_data[$index]['POLYGON']['no_of_lines'] ?? 1;
|
||||
if ($no_of_lines < 1) {
|
||||
$no_of_lines = 1;
|
||||
$noOfLines = $gisData[$index]['POLYGON']['no_of_lines'] ?? 1;
|
||||
if ($noOfLines < 1) {
|
||||
$noOfLines = 1;
|
||||
}
|
||||
|
||||
$wkt = 'POLYGON(';
|
||||
for ($i = 0; $i < $no_of_lines; $i++) {
|
||||
$no_of_points = $gis_data[$index]['POLYGON'][$i]['no_of_points'] ?? 4;
|
||||
if ($no_of_points < 4) {
|
||||
$no_of_points = 4;
|
||||
for ($i = 0; $i < $noOfLines; $i++) {
|
||||
$noOfPoints = $gisData[$index]['POLYGON'][$i]['no_of_points'] ?? 4;
|
||||
if ($noOfPoints < 4) {
|
||||
$noOfPoints = 4;
|
||||
}
|
||||
|
||||
$wkt .= '(';
|
||||
for ($j = 0; $j < $no_of_points; $j++) {
|
||||
$wkt .= (isset($gis_data[$index]['POLYGON'][$i][$j]['x'])
|
||||
&& trim((string) $gis_data[$index]['POLYGON'][$i][$j]['x']) != ''
|
||||
? $gis_data[$index]['POLYGON'][$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($gis_data[$index]['POLYGON'][$i][$j]['y'])
|
||||
&& trim((string) $gis_data[$index]['POLYGON'][$i][$j]['y']) != ''
|
||||
? $gis_data[$index]['POLYGON'][$i][$j]['y'] : $empty) . ',';
|
||||
for ($j = 0; $j < $noOfPoints; $j++) {
|
||||
$wkt .= (isset($gisData[$index]['POLYGON'][$i][$j]['x'])
|
||||
&& trim((string) $gisData[$index]['POLYGON'][$i][$j]['x']) != ''
|
||||
? $gisData[$index]['POLYGON'][$i][$j]['x'] : $empty)
|
||||
. ' ' . (isset($gisData[$index]['POLYGON'][$i][$j]['y'])
|
||||
&& trim((string) $gisData[$index]['POLYGON'][$i][$j]['y']) != ''
|
||||
? $gisData[$index]['POLYGON'][$i][$j]['y'] : $empty) . ',';
|
||||
}
|
||||
|
||||
$wkt = mb_substr($wkt, 0, -1);
|
||||
@ -305,12 +305,12 @@ class GisPolygon extends GisGeometry
|
||||
*/
|
||||
public static function area(array $ring): float
|
||||
{
|
||||
$no_of_points = count($ring);
|
||||
$noOfPoints = count($ring);
|
||||
|
||||
// If the last point is same as the first point ignore it
|
||||
$last = count($ring) - 1;
|
||||
if (($ring[0]['x'] == $ring[$last]['x']) && ($ring[0]['y'] == $ring[$last]['y'])) {
|
||||
$no_of_points--;
|
||||
$noOfPoints--;
|
||||
}
|
||||
|
||||
// _n-1
|
||||
@ -318,8 +318,8 @@ class GisPolygon extends GisGeometry
|
||||
// 2 /__
|
||||
// i=0
|
||||
$area = 0;
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
$j = ($i + 1) % $no_of_points;
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$j = ($i + 1) % $noOfPoints;
|
||||
$area += $ring[$i]['x'] * $ring[$j]['y'];
|
||||
$area -= $ring[$i]['y'] * $ring[$j]['x'];
|
||||
}
|
||||
@ -356,13 +356,13 @@ class GisPolygon extends GisGeometry
|
||||
$polygon = array_slice($polygon, 0, $last);
|
||||
}
|
||||
|
||||
$no_of_points = count($polygon);
|
||||
$noOfPoints = count($polygon);
|
||||
$counter = 0;
|
||||
|
||||
// Use ray casting algorithm
|
||||
$p1 = $polygon[0];
|
||||
for ($i = 1; $i <= $no_of_points; $i++) {
|
||||
$p2 = $polygon[$i % $no_of_points];
|
||||
for ($i = 1; $i <= $noOfPoints; $i++) {
|
||||
$p2 = $polygon[$i % $noOfPoints];
|
||||
if ($point['y'] <= min([$p1['y'], $p2['y']])) {
|
||||
$p1 = $p2;
|
||||
continue;
|
||||
@ -470,15 +470,15 @@ class GisPolygon extends GisGeometry
|
||||
protected function getCoordinateParams(string $wkt): array
|
||||
{
|
||||
// Trim to remove leading 'POLYGON((' and trailing '))'
|
||||
$wkt_polygon = mb_substr($wkt, 9, -2);
|
||||
$wkt_rings = explode('),(', $wkt_polygon);
|
||||
$coords = ['no_of_lines' => count($wkt_rings)];
|
||||
$wktPolygon = mb_substr($wkt, 9, -2);
|
||||
$wktRings = explode('),(', $wktPolygon);
|
||||
$coords = ['no_of_lines' => count($wktRings)];
|
||||
|
||||
foreach ($wkt_rings as $j => $wkt_ring) {
|
||||
$points = $this->extractPoints1d($wkt_ring, null);
|
||||
$no_of_points = count($points);
|
||||
$coords[$j] = ['no_of_points' => $no_of_points];
|
||||
for ($i = 0; $i < $no_of_points; $i++) {
|
||||
foreach ($wktRings as $j => $wktRing) {
|
||||
$points = $this->extractPoints1d($wktRing, null);
|
||||
$noOfPoints = count($points);
|
||||
$coords[$j] = ['no_of_points' => $noOfPoints];
|
||||
for ($i = 0; $i < $noOfPoints; $i++) {
|
||||
$coords[$j][$i] = [
|
||||
'x' => $points[$i][0],
|
||||
'y' => $points[$i][1],
|
||||
|
||||
@ -101,10 +101,10 @@ class GisVisualization
|
||||
/**
|
||||
* Factory
|
||||
*
|
||||
* @param string $sql_query SQL to fetch raw data for visualization
|
||||
* @param array<string,string|int|null> $options Users specified options
|
||||
* @param int $rows number of rows
|
||||
* @param int $pos start position
|
||||
* @param string $sqlQuery SQL to fetch raw data for visualization
|
||||
* @param array<string,string|int|null> $options Users specified options
|
||||
* @param int $rows number of rows
|
||||
* @param int $pos start position
|
||||
* @psalm-param array{
|
||||
* spatialColumn: non-empty-string,
|
||||
* labelColumn?: non-empty-string|null,
|
||||
@ -112,9 +112,9 @@ class GisVisualization
|
||||
* height: int,
|
||||
* } $options
|
||||
*/
|
||||
public static function get(string $sql_query, array $options, int $rows, int $pos): GisVisualization
|
||||
public static function get(string $sqlQuery, array $options, int $rows, int $pos): GisVisualization
|
||||
{
|
||||
return new GisVisualization($sql_query, $options, $rows, $pos);
|
||||
return new GisVisualization($sqlQuery, $options, $rows, $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,13 +196,13 @@ class GisVisualization
|
||||
/**
|
||||
* Returns sql for fetching raw data
|
||||
*
|
||||
* @param string $sql_query The SQL to modify.
|
||||
* @param string $sqlQuery The SQL to modify.
|
||||
*
|
||||
* @return string the modified sql query.
|
||||
*/
|
||||
private function modifySqlQuery(string $sql_query): string
|
||||
private function modifySqlQuery(string $sqlQuery): string
|
||||
{
|
||||
$modified_query = 'SELECT ';
|
||||
$modifiedQuery = 'SELECT ';
|
||||
$spatialAsText = 'ASTEXT';
|
||||
$spatialSrid = 'SRID';
|
||||
$axisOrder = '';
|
||||
@ -222,31 +222,31 @@ class GisVisualization
|
||||
|
||||
// If label column is chosen add it to the query
|
||||
if ($this->labelColumn !== null) {
|
||||
$modified_query .= Util::backquote($this->labelColumn)
|
||||
$modifiedQuery .= Util::backquote($this->labelColumn)
|
||||
. ', ';
|
||||
}
|
||||
|
||||
// Wrap the spatial column with 'ST_ASTEXT()' function and add it
|
||||
$modified_query .= $spatialAsText . '('
|
||||
$modifiedQuery .= $spatialAsText . '('
|
||||
. Util::backquote($this->spatialColumn)
|
||||
. $axisOrder . ') AS ' . Util::backquote($this->spatialColumn)
|
||||
. ', ';
|
||||
|
||||
// Get the SRID
|
||||
$modified_query .= $spatialSrid . '('
|
||||
$modifiedQuery .= $spatialSrid . '('
|
||||
. Util::backquote($this->spatialColumn)
|
||||
. ') AS ' . Util::backquote('srid') . ' ';
|
||||
|
||||
// Append the original query as the inner query
|
||||
$modified_query .= 'FROM (' . rtrim($sql_query, ';') . ') AS '
|
||||
$modifiedQuery .= 'FROM (' . rtrim($sqlQuery, ';') . ') AS '
|
||||
. Util::backquote('temp_gis');
|
||||
|
||||
// LIMIT clause
|
||||
if ($this->rows > 0) {
|
||||
$modified_query .= ' LIMIT ' . ($this->pos > 0 ? $this->pos . ', ' : '') . $this->rows;
|
||||
$modifiedQuery .= ' LIMIT ' . ($this->pos > 0 ? $this->pos . ', ' : '') . $this->rows;
|
||||
}
|
||||
|
||||
return $modified_query;
|
||||
return $modifiedQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,50 +256,50 @@ class GisVisualization
|
||||
*/
|
||||
private function fetchRawData(string $modifiedSql): array
|
||||
{
|
||||
$modified_result = $GLOBALS['dbi']->tryQuery($modifiedSql);
|
||||
$modifiedResult = $GLOBALS['dbi']->tryQuery($modifiedSql);
|
||||
|
||||
if ($modified_result === false) {
|
||||
if ($modifiedResult === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $modified_result->fetchAllAssoc();
|
||||
return $modifiedResult->fetchAllAssoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes the file name.
|
||||
*
|
||||
* @param string $file_name file name
|
||||
* @param string $ext extension of the file
|
||||
* @param string $fileName file name
|
||||
* @param string $ext extension of the file
|
||||
*
|
||||
* @return string the sanitized file name
|
||||
*/
|
||||
private function sanitizeName(string $file_name, string $ext): string
|
||||
private function sanitizeName(string $fileName, string $ext): string
|
||||
{
|
||||
$file_name = Sanitize::sanitizeFilename($file_name);
|
||||
$fileName = Sanitize::sanitizeFilename($fileName);
|
||||
|
||||
// Check if the user already added extension;
|
||||
// get the substring where the extension would be if it was included
|
||||
$required_extension = '.' . $ext;
|
||||
$extension_length = mb_strlen($required_extension);
|
||||
$user_extension = mb_substr($file_name, -$extension_length);
|
||||
if (mb_strtolower($user_extension) !== $required_extension) {
|
||||
$file_name .= $required_extension;
|
||||
$requiredExtension = '.' . $ext;
|
||||
$extensionLength = mb_strlen($requiredExtension);
|
||||
$userExtension = mb_substr($fileName, -$extensionLength);
|
||||
if (mb_strtolower($userExtension) !== $requiredExtension) {
|
||||
$fileName .= $requiredExtension;
|
||||
}
|
||||
|
||||
return $file_name;
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles common tasks of writing the visualization to file for various formats.
|
||||
*
|
||||
* @param string $file_name file name
|
||||
* @param string $type mime type
|
||||
* @param string $ext extension of the file
|
||||
* @param string $fileName file name
|
||||
* @param string $type mime type
|
||||
* @param string $ext extension of the file
|
||||
*/
|
||||
private function writeToFile(string $file_name, string $type, string $ext): void
|
||||
private function writeToFile(string $fileName, string $type, string $ext): void
|
||||
{
|
||||
$file_name = $this->sanitizeName($file_name, $ext);
|
||||
Core::downloadHeader($file_name, $type);
|
||||
$fileName = $this->sanitizeName($fileName, $ext);
|
||||
Core::downloadHeader($fileName, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,9 +309,9 @@ class GisVisualization
|
||||
*/
|
||||
private function svg(): string
|
||||
{
|
||||
$scale_data = $this->scaleDataSet($this->data);
|
||||
$scaleData = $this->scaleDataSet($this->data);
|
||||
/** @var string $svg */
|
||||
$svg = $this->prepareDataSet($this->data, $scale_data, 'svg');
|
||||
$svg = $this->prepareDataSet($this->data, $scaleData, 'svg');
|
||||
|
||||
return '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
|
||||
. "\n"
|
||||
@ -336,12 +336,12 @@ class GisVisualization
|
||||
/**
|
||||
* Saves as a SVG image to a file.
|
||||
*
|
||||
* @param string $file_name File name
|
||||
* @param string $fileName File name
|
||||
*/
|
||||
public function toFileAsSvg(string $file_name): void
|
||||
public function toFileAsSvg(string $fileName): void
|
||||
{
|
||||
$img = $this->svg();
|
||||
$this->writeToFile($file_name, 'image/svg+xml', 'svg');
|
||||
$this->writeToFile($fileName, 'image/svg+xml', 'svg');
|
||||
echo $img;
|
||||
}
|
||||
|
||||
@ -361,9 +361,9 @@ class GisVisualization
|
||||
return null;
|
||||
}
|
||||
|
||||
$scale_data = $this->scaleDataSet($this->data);
|
||||
$scaleData = $this->scaleDataSet($this->data);
|
||||
/** @var ImageWrapper $image */
|
||||
$image = $this->prepareDataSet($this->data, $scale_data, 'png', $image);
|
||||
$image = $this->prepareDataSet($this->data, $scaleData, 'png', $image);
|
||||
|
||||
return $image;
|
||||
}
|
||||
@ -371,16 +371,16 @@ class GisVisualization
|
||||
/**
|
||||
* Saves as a PNG image to a file.
|
||||
*
|
||||
* @param string $file_name File name
|
||||
* @param string $fileName File name
|
||||
*/
|
||||
public function toFileAsPng(string $file_name): void
|
||||
public function toFileAsPng(string $fileName): void
|
||||
{
|
||||
$image = $this->png();
|
||||
if ($image === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->writeToFile($file_name, 'image/png', 'png');
|
||||
$this->writeToFile($fileName, 'image/png', 'png');
|
||||
$image->png(null, 9, PNG_ALL_FILTERS);
|
||||
}
|
||||
|
||||
@ -393,9 +393,9 @@ class GisVisualization
|
||||
*/
|
||||
public function asOl(): string
|
||||
{
|
||||
$scale_data = $this->scaleDataSet($this->data);
|
||||
$scaleData = $this->scaleDataSet($this->data);
|
||||
/** @var string $olCode */
|
||||
$olCode = $this->prepareDataSet($this->data, $scale_data, 'ol');
|
||||
$olCode = $this->prepareDataSet($this->data, $scaleData, 'ol');
|
||||
|
||||
return 'function drawOpenLayers() {'
|
||||
. 'if (typeof ol === "undefined") { return undefined; }'
|
||||
@ -434,9 +434,9 @@ class GisVisualization
|
||||
/**
|
||||
* Saves as a PDF to a file.
|
||||
*
|
||||
* @param string $file_name File name
|
||||
* @param string $fileName File name
|
||||
*/
|
||||
public function toFileAsPdf(string $file_name): void
|
||||
public function toFileAsPdf(string $fileName): void
|
||||
{
|
||||
// create pdf
|
||||
$pdf = new TCPDF('', 'pt', $GLOBALS['cfg']['PDFDefaultPageSize'], true, 'UTF-8', false);
|
||||
@ -451,12 +451,12 @@ class GisVisualization
|
||||
// add a page
|
||||
$pdf->AddPage();
|
||||
|
||||
$scale_data = $this->scaleDataSet($this->data);
|
||||
$pdf = $this->prepareDataSet($this->data, $scale_data, 'pdf', $pdf);
|
||||
$scaleData = $this->scaleDataSet($this->data);
|
||||
$pdf = $this->prepareDataSet($this->data, $scaleData, 'pdf', $pdf);
|
||||
|
||||
// sanitize file name
|
||||
$file_name = $this->sanitizeName($file_name, 'pdf');
|
||||
$pdf->Output($file_name, 'D');
|
||||
$fileName = $this->sanitizeName($fileName, 'pdf');
|
||||
$pdf->Output($fileName, 'D');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -485,53 +485,53 @@ class GisVisualization
|
||||
*/
|
||||
private function scaleDataSet(array $data): array
|
||||
{
|
||||
$min_max = null;
|
||||
$minMax = null;
|
||||
$border = 15;
|
||||
// effective width and height of the plot
|
||||
$plot_width = $this->width - 2 * $border;
|
||||
$plot_height = $this->height - 2 * $border;
|
||||
$plotWidth = $this->width - 2 * $border;
|
||||
$plotHeight = $this->height - 2 * $border;
|
||||
|
||||
foreach ($data as $row) {
|
||||
// Figure out the data type
|
||||
$ref_data = $row[$this->spatialColumn];
|
||||
if (! is_string($ref_data)) {
|
||||
$refData = $row[$this->spatialColumn];
|
||||
if (! is_string($refData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type_pos = mb_strpos($ref_data, '(');
|
||||
if ($type_pos === false) {
|
||||
$typePos = mb_strpos($refData, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($ref_data, 0, $type_pos);
|
||||
$type = mb_substr($refData, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$scaleData = $gis_obj->scaleRow($ref_data);
|
||||
$scaleData = $gisObj->scaleRow($refData);
|
||||
|
||||
// Update minimum/maximum values for x and y coordinates.
|
||||
$min_max = $min_max === null ? $scaleData : $scaleData?->merge($min_max);
|
||||
$minMax = $minMax === null ? $scaleData : $scaleData?->merge($minMax);
|
||||
}
|
||||
|
||||
$min_max ??= new ScaleData(0, 0, 0, 0);
|
||||
$minMax ??= new ScaleData(0, 0, 0, 0);
|
||||
|
||||
// scale the visualization
|
||||
$x_ratio = ($min_max->maxX - $min_max->minX) / $plot_width;
|
||||
$y_ratio = ($min_max->maxY - $min_max->minY) / $plot_height;
|
||||
$ratio = $x_ratio > $y_ratio ? $x_ratio : $y_ratio;
|
||||
$xRatio = ($minMax->maxX - $minMax->minX) / $plotWidth;
|
||||
$yRatio = ($minMax->maxY - $minMax->minY) / $plotHeight;
|
||||
$ratio = $xRatio > $yRatio ? $xRatio : $yRatio;
|
||||
|
||||
$scale = $ratio != 0 ? 1 / $ratio : 1;
|
||||
|
||||
// Center plot
|
||||
$x = $ratio == 0 || $x_ratio < $y_ratio
|
||||
? ($min_max->maxX + $min_max->minX - $this->width / $scale) / 2
|
||||
: $min_max->minX - ($border / $scale);
|
||||
$y = $ratio == 0 || $x_ratio >= $y_ratio
|
||||
? ($min_max->maxY + $min_max->minY - $this->height / $scale) / 2
|
||||
: $min_max->minY - ($border / $scale);
|
||||
$x = $ratio == 0 || $xRatio < $yRatio
|
||||
? ($minMax->maxX + $minMax->minX - $this->width / $scale) / 2
|
||||
: $minMax->minX - ($border / $scale);
|
||||
$y = $ratio == 0 || $xRatio >= $yRatio
|
||||
? ($minMax->maxY + $minMax->minY - $this->height / $scale) / 2
|
||||
: $minMax->minY - ($border / $scale);
|
||||
|
||||
return [
|
||||
'scale' => $scale,
|
||||
@ -544,78 +544,78 @@ class GisVisualization
|
||||
/**
|
||||
* Prepares and return the dataset as needed by the visualization.
|
||||
*
|
||||
* @param mixed[][] $data Raw data
|
||||
* @param array $scale_data Data related to scaling
|
||||
* @param string $format Format of the visualization
|
||||
* @param ImageWrapper|TCPDF|string $results Image object in the case of png
|
||||
* TCPDF object in the case of pdf
|
||||
* @param mixed[][] $data Raw data
|
||||
* @param array $scaleData Data related to scaling
|
||||
* @param string $format Format of the visualization
|
||||
* @param ImageWrapper|TCPDF|string $results Image object in the case of png
|
||||
* TCPDF object in the case of pdf
|
||||
*
|
||||
* @return mixed the formatted array of data
|
||||
*/
|
||||
private function prepareDataSet(
|
||||
array $data,
|
||||
array $scale_data,
|
||||
array $scaleData,
|
||||
string $format,
|
||||
ImageWrapper|TCPDF|string $results = '',
|
||||
): mixed {
|
||||
$color_index = 0;
|
||||
$colorIndex = 0;
|
||||
|
||||
// loop through the rows
|
||||
foreach ($data as $row) {
|
||||
// Figure out the data type
|
||||
$ref_data = $row[$this->spatialColumn];
|
||||
if (! is_string($ref_data)) {
|
||||
$refData = $row[$this->spatialColumn];
|
||||
if (! is_string($refData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type_pos = mb_strpos($ref_data, '(');
|
||||
if ($type_pos === false) {
|
||||
$typePos = mb_strpos($refData, '(');
|
||||
if ($typePos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = mb_substr($ref_data, 0, $type_pos);
|
||||
$type = mb_substr($refData, 0, $typePos);
|
||||
|
||||
$gis_obj = GisFactory::factory($type);
|
||||
if (! $gis_obj) {
|
||||
$gisObj = GisFactory::factory($type);
|
||||
if (! $gisObj) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$color = self::COLORS[$color_index];
|
||||
$color = self::COLORS[$colorIndex];
|
||||
$label = trim((string) ($row[$this->labelColumn] ?? ''));
|
||||
|
||||
if ($format === 'svg') {
|
||||
$results .= $gis_obj->prepareRowAsSvg(
|
||||
$ref_data,
|
||||
$results .= $gisObj->prepareRowAsSvg(
|
||||
$refData,
|
||||
$label,
|
||||
$color,
|
||||
$scale_data,
|
||||
$scaleData,
|
||||
);
|
||||
} elseif ($format === 'png') {
|
||||
$results = $gis_obj->prepareRowAsPng(
|
||||
$ref_data,
|
||||
$results = $gisObj->prepareRowAsPng(
|
||||
$refData,
|
||||
$label,
|
||||
$color,
|
||||
$scale_data,
|
||||
$scaleData,
|
||||
$results,
|
||||
);
|
||||
} elseif ($format === 'pdf' && $results instanceof TCPDF) {
|
||||
$results = $gis_obj->prepareRowAsPdf(
|
||||
$ref_data,
|
||||
$results = $gisObj->prepareRowAsPdf(
|
||||
$refData,
|
||||
$label,
|
||||
$color,
|
||||
$scale_data,
|
||||
$scaleData,
|
||||
$results,
|
||||
);
|
||||
} elseif ($format === 'ol') {
|
||||
$results .= $gis_obj->prepareRowAsOl(
|
||||
$ref_data,
|
||||
$results .= $gisObj->prepareRowAsOl(
|
||||
$refData,
|
||||
(int) $row['srid'],
|
||||
$label,
|
||||
$color,
|
||||
);
|
||||
}
|
||||
|
||||
$color_index = ($color_index + 1) % count(self::COLORS);
|
||||
$colorIndex = ($colorIndex + 1) % count(self::COLORS);
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
@ -78,9 +78,9 @@ class Git
|
||||
/**
|
||||
* detects if Git revision
|
||||
*
|
||||
* @param string|null $git_location (optional) verified git directory
|
||||
* @param string|null $gitLocation (optional) verified git directory
|
||||
*/
|
||||
public function isGitRevision(string|null &$git_location = null): bool
|
||||
public function isGitRevision(string|null &$gitLocation = null): bool
|
||||
{
|
||||
if (! $this->showGitRevision) {
|
||||
return false;
|
||||
@ -89,7 +89,7 @@ class Git
|
||||
// caching
|
||||
if (isset($_SESSION['is_git_revision']) && array_key_exists('git_location', $_SESSION)) {
|
||||
// Define location using cached value
|
||||
$git_location = $_SESSION['git_location'];
|
||||
$gitLocation = $_SESSION['git_location'];
|
||||
|
||||
return (bool) $_SESSION['is_git_revision'];
|
||||
}
|
||||
@ -105,7 +105,7 @@ class Git
|
||||
return false;
|
||||
}
|
||||
|
||||
$git_location = $git;
|
||||
$gitLocation = $git;
|
||||
} elseif (is_file($git)) {
|
||||
$contents = (string) file_get_contents($git);
|
||||
$gitmatch = [];
|
||||
@ -125,7 +125,7 @@ class Git
|
||||
}
|
||||
|
||||
//Detected git external folder location
|
||||
$git_location = $gitmatch[1];
|
||||
$gitLocation = $gitmatch[1];
|
||||
} else {
|
||||
$_SESSION['git_location'] = null;
|
||||
$_SESSION['is_git_revision'] = false;
|
||||
@ -134,7 +134,7 @@ class Git
|
||||
}
|
||||
|
||||
// Define session for caching
|
||||
$_SESSION['git_location'] = $git_location;
|
||||
$_SESSION['git_location'] = $gitLocation;
|
||||
$_SESSION['is_git_revision'] = true;
|
||||
|
||||
return true;
|
||||
@ -194,18 +194,18 @@ class Git
|
||||
private function getPackOffset(string $packFile, string $hash): int|null
|
||||
{
|
||||
// load index
|
||||
$index_data = @file_get_contents($packFile);
|
||||
if ($index_data === false) {
|
||||
$indexData = @file_get_contents($packFile);
|
||||
if ($indexData === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// check format
|
||||
if (substr($index_data, 0, 4) != "\377tOc") {
|
||||
if (substr($indexData, 0, 4) != "\377tOc") {
|
||||
return null;
|
||||
}
|
||||
|
||||
// check version
|
||||
$version = unpack('N', substr($index_data, 4, 4));
|
||||
$version = unpack('N', substr($indexData, 4, 4));
|
||||
if ($version[1] != 2) {
|
||||
return null;
|
||||
}
|
||||
@ -213,7 +213,7 @@ class Git
|
||||
// parse fanout table
|
||||
$fanout = unpack(
|
||||
'N*',
|
||||
substr($index_data, 8, 256 * 4),
|
||||
substr($indexData, 8, 256 * 4),
|
||||
);
|
||||
|
||||
// find where we should search
|
||||
@ -234,7 +234,7 @@ class Git
|
||||
for ($position = $start; $position < $end; $position++) {
|
||||
$sha = strtolower(
|
||||
bin2hex(
|
||||
substr($index_data, $offset + ($position * 20), 20),
|
||||
substr($indexData, $offset + ($position * 20), 20),
|
||||
),
|
||||
);
|
||||
if ($sha === $hash) {
|
||||
@ -251,7 +251,7 @@ class Git
|
||||
$offset = 8 + (256 * 4) + (24 * $fanout[256]);
|
||||
$packOffsets = unpack(
|
||||
'N',
|
||||
substr($index_data, $offset + ($position * 4), 4),
|
||||
substr($indexData, $offset + ($position * 4), 4),
|
||||
);
|
||||
|
||||
return $packOffsets[1];
|
||||
@ -287,13 +287,13 @@ class Git
|
||||
$commit = explode("\n", $commit[1]);
|
||||
$_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
|
||||
} else {
|
||||
$pack_names = [];
|
||||
$packNames = [];
|
||||
// work with packed data
|
||||
$packs_file = $gitFolder . '/objects/info/packs';
|
||||
$packsFile = $gitFolder . '/objects/info/packs';
|
||||
$packs = '';
|
||||
|
||||
if (@file_exists($packs_file)) {
|
||||
$packs = @file_get_contents($packs_file);
|
||||
if (@file_exists($packsFile)) {
|
||||
$packs = @file_get_contents($packsFile);
|
||||
}
|
||||
|
||||
if ($packs) {
|
||||
@ -311,7 +311,7 @@ class Git
|
||||
}
|
||||
|
||||
// parse names
|
||||
$pack_names[] = substr($line, 2);
|
||||
$packNames[] = substr($line, 2);
|
||||
}
|
||||
} else {
|
||||
// '.git/objects/info/packs' file can be missing
|
||||
@ -320,27 +320,27 @@ class Git
|
||||
// directory for all the .pack files and use that list of
|
||||
// files instead
|
||||
$dirIterator = new DirectoryIterator($gitFolder . '/objects/pack');
|
||||
foreach ($dirIterator as $file_info) {
|
||||
$file_name = $file_info->getFilename();
|
||||
foreach ($dirIterator as $fileInfo) {
|
||||
$fileName = $fileInfo->getFilename();
|
||||
// if this is a .pack file
|
||||
if (! $file_info->isFile() || substr($file_name, -5) !== '.pack') {
|
||||
if (! $fileInfo->isFile() || substr($fileName, -5) !== '.pack') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pack_names[] = $file_name;
|
||||
$packNames[] = $fileName;
|
||||
}
|
||||
}
|
||||
|
||||
$hash = strtolower($hash);
|
||||
foreach ($pack_names as $pack_name) {
|
||||
$index_name = str_replace('.pack', '.idx', $pack_name);
|
||||
foreach ($packNames as $packName) {
|
||||
$indexName = str_replace('.pack', '.idx', $packName);
|
||||
|
||||
$packOffset = $this->getPackOffset($gitFolder . '/objects/pack/' . $index_name, $hash);
|
||||
$packOffset = $this->getPackOffset($gitFolder . '/objects/pack/' . $indexName, $hash);
|
||||
if ($packOffset === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$commit = $this->readPackFile($gitFolder . '/objects/pack/' . $pack_name, $packOffset);
|
||||
$commit = $this->readPackFile($gitFolder . '/objects/pack/' . $packName, $packOffset);
|
||||
if ($commit !== null) {
|
||||
$commit = gzuncompress($commit);
|
||||
if ($commit !== false) {
|
||||
@ -427,15 +427,15 @@ class Git
|
||||
}
|
||||
|
||||
$link = 'https://www.phpmyadmin.net/api/commit/' . $hash . '/';
|
||||
$is_found = $httpRequest->create($link, 'GET');
|
||||
if ($is_found === false) {
|
||||
$isFound = $httpRequest->create($link, 'GET');
|
||||
if ($isFound === false) {
|
||||
$isRemoteCommit = false;
|
||||
$_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = false;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($is_found === null) {
|
||||
if ($isFound === null) {
|
||||
// no remote link for now, but don't cache this as GitHub is down
|
||||
$isRemoteCommit = false;
|
||||
|
||||
@ -446,7 +446,7 @@ class Git
|
||||
$_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = true;
|
||||
if ($commit === false) {
|
||||
// if no local commit data, try loading from Github
|
||||
return json_decode((string) $is_found);
|
||||
return json_decode((string) $isFound);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -546,9 +546,9 @@ class Git
|
||||
return null;
|
||||
}
|
||||
|
||||
$ref_head = @file_get_contents($gitFolder . '/HEAD');
|
||||
$refHead = @file_get_contents($gitFolder . '/HEAD');
|
||||
|
||||
if (! $ref_head) {
|
||||
if (! $refHead) {
|
||||
$this->hasGit = false;
|
||||
|
||||
return null;
|
||||
@ -559,7 +559,7 @@ class Git
|
||||
$gitFolder .= DIRECTORY_SEPARATOR . $commonDirContents;
|
||||
}
|
||||
|
||||
[$hash, $branch] = $this->getHashFromHeadRef($gitFolder, $ref_head);
|
||||
[$hash, $branch] = $this->getHashFromHeadRef($gitFolder, $refHead);
|
||||
if ($hash === null) {
|
||||
return null;
|
||||
}
|
||||
@ -576,48 +576,48 @@ class Git
|
||||
}
|
||||
}
|
||||
|
||||
$is_remote_commit = false;
|
||||
$commit_json = $this->isRemoteCommit(
|
||||
$isRemoteCommit = false;
|
||||
$commitJson = $this->isRemoteCommit(
|
||||
$commit, // Will be modified if necessary by the function
|
||||
$is_remote_commit, // Will be modified if necessary by the function
|
||||
$isRemoteCommit, // Will be modified if necessary by the function
|
||||
$hash,
|
||||
);
|
||||
|
||||
$is_remote_branch = false;
|
||||
if ($is_remote_commit && $branch !== false) {
|
||||
$isRemoteBranch = false;
|
||||
if ($isRemoteCommit && $branch !== false) {
|
||||
// check if branch exists in Github
|
||||
if (isset($_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash])) {
|
||||
$is_remote_branch = $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash];
|
||||
$isRemoteBranch = $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash];
|
||||
} else {
|
||||
$httpRequest = new HttpRequest();
|
||||
$link = 'https://www.phpmyadmin.net/api/tree/' . $branch . '/';
|
||||
$is_found = $httpRequest->create($link, 'GET', true);
|
||||
if (is_bool($is_found)) {
|
||||
$is_remote_branch = $is_found;
|
||||
$_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = $is_found;
|
||||
$isFound = $httpRequest->create($link, 'GET', true);
|
||||
if (is_bool($isFound)) {
|
||||
$isRemoteBranch = $isFound;
|
||||
$_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = $isFound;
|
||||
}
|
||||
|
||||
if ($is_found === null) {
|
||||
if ($isFound === null) {
|
||||
// no remote link for now, but don't cache this as Github is down
|
||||
$is_remote_branch = false;
|
||||
$isRemoteBranch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($commit !== false) {
|
||||
[$author, $committer, $message] = $this->extractDataFormTextBody($commit);
|
||||
} elseif (isset($commit_json->author, $commit_json->committer, $commit_json->message)) {
|
||||
} elseif (isset($commitJson->author, $commitJson->committer, $commitJson->message)) {
|
||||
$author = [
|
||||
'name' => $commit_json->author->name,
|
||||
'email' => $commit_json->author->email,
|
||||
'date' => $commit_json->author->date,
|
||||
'name' => $commitJson->author->name,
|
||||
'email' => $commitJson->author->email,
|
||||
'date' => $commitJson->author->date,
|
||||
];
|
||||
$committer = [
|
||||
'name' => $commit_json->committer->name,
|
||||
'email' => $commit_json->committer->email,
|
||||
'date' => $commit_json->committer->date,
|
||||
'name' => $commitJson->committer->name,
|
||||
'email' => $commitJson->committer->email,
|
||||
'date' => $commitJson->committer->date,
|
||||
];
|
||||
$message = trim($commit_json->message);
|
||||
$message = trim($commitJson->message);
|
||||
} else {
|
||||
$this->hasGit = false;
|
||||
|
||||
@ -632,8 +632,8 @@ class Git
|
||||
'message' => $message,
|
||||
'author' => $author,
|
||||
'committer' => $committer,
|
||||
'is_remote_commit' => $is_remote_commit,
|
||||
'is_remote_branch' => $is_remote_branch,
|
||||
'is_remote_commit' => $isRemoteCommit,
|
||||
'is_remote_branch' => $isRemoteBranch,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,17 +28,17 @@ final class Ajax
|
||||
/**
|
||||
* constant for differentiating array in $_SESSION variable
|
||||
*/
|
||||
$SESSION_KEY = '__upload_status';
|
||||
$sessionKey = '__upload_status';
|
||||
|
||||
/**
|
||||
* sets default plugin for handling the import process
|
||||
*/
|
||||
$_SESSION[$SESSION_KEY]['handler'] = '';
|
||||
$_SESSION[$sessionKey]['handler'] = '';
|
||||
|
||||
/**
|
||||
* unique ID for each upload
|
||||
*/
|
||||
$upload_id = ! defined('TESTSUITE') ? uniqid('') : 'abc1234567890';
|
||||
$uploadId = ! defined('TESTSUITE') ? uniqid('') : 'abc1234567890';
|
||||
|
||||
/**
|
||||
* list of available plugins
|
||||
@ -55,15 +55,15 @@ final class Ajax
|
||||
$check = $plugin . 'Check';
|
||||
|
||||
if (self::$check()) {
|
||||
$upload_class = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords($plugin);
|
||||
$_SESSION[$SESSION_KEY]['handler'] = $upload_class;
|
||||
$uploadClass = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords($plugin);
|
||||
$_SESSION[$sessionKey]['handler'] = $uploadClass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
$SESSION_KEY,
|
||||
$upload_id,
|
||||
$sessionKey,
|
||||
$uploadId,
|
||||
$plugins,
|
||||
];
|
||||
}
|
||||
|
||||
@ -98,16 +98,16 @@ class Index
|
||||
DatabaseInterface $dbi,
|
||||
string $schema,
|
||||
string $table,
|
||||
string $index_name = '',
|
||||
string $indexName = '',
|
||||
): Index {
|
||||
self::loadIndexes($dbi, $table, $schema);
|
||||
if (isset(self::$registry[$schema][$table][$index_name])) {
|
||||
return self::$registry[$schema][$table][$index_name];
|
||||
if (isset(self::$registry[$schema][$table][$indexName])) {
|
||||
return self::$registry[$schema][$table][$indexName];
|
||||
}
|
||||
|
||||
$index = new Index();
|
||||
if ($index_name !== '') {
|
||||
$index->setName($index_name);
|
||||
if ($indexName !== '') {
|
||||
$index->setName($indexName);
|
||||
self::$registry[$schema][$table][$index->getName()] = $index;
|
||||
}
|
||||
|
||||
@ -185,18 +185,18 @@ class Index
|
||||
return true;
|
||||
}
|
||||
|
||||
$_raw_indexes = $dbi->getTableIndexes($schema, $table);
|
||||
foreach ($_raw_indexes as $_each_index) {
|
||||
$_each_index['Schema'] = $schema;
|
||||
$keyName = $_each_index['Key_name'];
|
||||
$rawIndexes = $dbi->getTableIndexes($schema, $table);
|
||||
foreach ($rawIndexes as $eachIndex) {
|
||||
$eachIndex['Schema'] = $schema;
|
||||
$keyName = $eachIndex['Key_name'];
|
||||
if (! isset(self::$registry[$schema][$table][$keyName])) {
|
||||
$key = new Index($_each_index);
|
||||
$key = new Index($eachIndex);
|
||||
self::$registry[$schema][$table][$keyName] = $key;
|
||||
} else {
|
||||
$key = self::$registry[$schema][$table][$keyName];
|
||||
}
|
||||
|
||||
$key->addColumn($_each_index);
|
||||
$key->addColumn($eachIndex);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -229,17 +229,17 @@ class Index
|
||||
*/
|
||||
public function addColumns(array $columns): void
|
||||
{
|
||||
$_columns = [];
|
||||
$addedColumns = [];
|
||||
|
||||
if (isset($columns['names'])) {
|
||||
// coming from form
|
||||
// $columns[names][]
|
||||
// $columns[sub_parts][]
|
||||
foreach ($columns['names'] as $key => $name) {
|
||||
$sub_part = $columns['sub_parts'][$key] ?? '';
|
||||
$_columns[] = [
|
||||
$subPart = $columns['sub_parts'][$key] ?? '';
|
||||
$addedColumns[] = [
|
||||
'Column_name' => $name,
|
||||
'Sub_part' => $sub_part,
|
||||
'Sub_part' => $subPart,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
@ -247,10 +247,10 @@ class Index
|
||||
// $columns[][name]
|
||||
// $columns[][sub_part]
|
||||
// ...
|
||||
$_columns = $columns;
|
||||
$addedColumns = $columns;
|
||||
}
|
||||
|
||||
foreach ($_columns as $column) {
|
||||
foreach ($addedColumns as $column) {
|
||||
$this->addColumn($column);
|
||||
}
|
||||
}
|
||||
@ -472,13 +472,13 @@ class Index
|
||||
/**
|
||||
* Returns whether the index is a 'Unique' index
|
||||
*
|
||||
* @param bool $as_text whether to output should be in text
|
||||
* @param bool $asText whether to output should be in text
|
||||
*
|
||||
* @return string|bool whether the index is a 'Unique' index
|
||||
*/
|
||||
public function isUnique(bool $as_text = false): string|bool
|
||||
public function isUnique(bool $asText = false): string|bool
|
||||
{
|
||||
if ($as_text) {
|
||||
if ($asText) {
|
||||
return $this->nonUnique ? __('No') : __('Yes');
|
||||
}
|
||||
|
||||
@ -564,10 +564,10 @@ class Index
|
||||
}
|
||||
|
||||
// remove last index from stack and ...
|
||||
while ($while_index = array_pop($indexes)) {
|
||||
while ($whileIndex = array_pop($indexes)) {
|
||||
// ... compare with every remaining index in stack
|
||||
foreach ($indexes as $each_index) {
|
||||
if ($each_index->getCompareData() !== $while_index->getCompareData()) {
|
||||
foreach ($indexes as $eachIndex) {
|
||||
if ($eachIndex->getCompareData() !== $whileIndex->getCompareData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -579,8 +579,8 @@ class Index
|
||||
'The indexes %1$s and %2$s seem to be equal and one of them could possibly be removed.',
|
||||
),
|
||||
);
|
||||
$message->addParam($each_index->getName());
|
||||
$message->addParam($while_index->getName());
|
||||
$message->addParam($eachIndex->getName());
|
||||
$message->addParam($whileIndex->getName());
|
||||
$output .= $message->getDisplay();
|
||||
|
||||
// there is no need to check any further indexes if we have already
|
||||
|
||||
@ -139,14 +139,14 @@ class IndexColumn
|
||||
/**
|
||||
* Returns whether the column is nullable
|
||||
*
|
||||
* @param bool $as_text whether to returned the string representation
|
||||
* @param bool $asText whether to returned the string representation
|
||||
*
|
||||
* @return string nullability of the column. True/false or Yes/No depending
|
||||
* on the value of the $as_text parameter
|
||||
*/
|
||||
public function getNull(bool $as_text = false): string
|
||||
public function getNull(bool $asText = false): string
|
||||
{
|
||||
if ($as_text) {
|
||||
if ($asText) {
|
||||
if (! $this->null || $this->null === 'NO') {
|
||||
return __('No');
|
||||
}
|
||||
|
||||
@ -579,15 +579,15 @@ class InsertEdit
|
||||
/**
|
||||
* Get column values
|
||||
*
|
||||
* @param string[] $enum_set_values
|
||||
* @param string[] $enumSetValues
|
||||
*
|
||||
* @return array column values as an associative array
|
||||
* @psalm-return list<array{html: string, plain: string}>
|
||||
*/
|
||||
private function getColumnEnumValues(array $enum_set_values): array
|
||||
private function getColumnEnumValues(array $enumSetValues): array
|
||||
{
|
||||
$values = [];
|
||||
foreach ($enum_set_values as $val) {
|
||||
foreach ($enumSetValues as $val) {
|
||||
$values[] = [
|
||||
'plain' => $val,
|
||||
'html' => htmlspecialchars($val),
|
||||
@ -600,18 +600,18 @@ class InsertEdit
|
||||
/**
|
||||
* Retrieve column 'set' value and select size
|
||||
*
|
||||
* @param array $column description of column in given table
|
||||
* @param string[] $enum_set_values
|
||||
* @param array $column description of column in given table
|
||||
* @param string[] $enumSetValues
|
||||
*
|
||||
* @return array $column['values'], $column['select_size']
|
||||
*/
|
||||
private function getColumnSetValueAndSelectSize(
|
||||
array $column,
|
||||
array $enum_set_values,
|
||||
array $enumSetValues,
|
||||
): array {
|
||||
if (! isset($column['values'])) {
|
||||
$column['values'] = [];
|
||||
foreach ($enum_set_values as $val) {
|
||||
foreach ($enumSetValues as $val) {
|
||||
$column['values'][] = [
|
||||
'plain' => $val,
|
||||
'html' => htmlspecialchars($val),
|
||||
@ -726,13 +726,13 @@ class InsertEdit
|
||||
/**
|
||||
* Retrieve the maximum upload file size
|
||||
*
|
||||
* @param string $pma_type column type
|
||||
* @param string $pmaType column type
|
||||
* @param int $biggestMaxFileSize biggest max file size for uploading
|
||||
*
|
||||
* @return array an html snippet and $biggest_max_file_size
|
||||
* @psalm-return array{non-empty-string, int}
|
||||
*/
|
||||
private function getMaxUploadSize(string $pma_type, int $biggestMaxFileSize): array
|
||||
private function getMaxUploadSize(string $pmaType, int $biggestMaxFileSize): array
|
||||
{
|
||||
// find maximum upload size, based on field type
|
||||
/**
|
||||
@ -747,8 +747,8 @@ class InsertEdit
|
||||
];
|
||||
|
||||
$thisFieldMaxSize = (int) $GLOBALS['config']->get('max_upload_size'); // from PHP max
|
||||
if ($thisFieldMaxSize > $maxFieldSizes[$pma_type]) {
|
||||
$thisFieldMaxSize = $maxFieldSizes[$pma_type];
|
||||
if ($thisFieldMaxSize > $maxFieldSizes[$pmaType]) {
|
||||
$thisFieldMaxSize = $maxFieldSizes[$pmaType];
|
||||
}
|
||||
|
||||
$htmlOutput = Util::getFormattedMaximumUploadSize($thisFieldMaxSize) . "\n";
|
||||
|
||||
@ -121,67 +121,67 @@ class IpAllowDeny
|
||||
* xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx[yyy-zzz]
|
||||
* (range, partial octets not supported)
|
||||
*
|
||||
* @param string $test_range string of IP range to match
|
||||
* @param string $ip_to_test string of IP to test against range
|
||||
* @param string $testRange string of IP range to match
|
||||
* @param string $ipToTest string of IP to test against range
|
||||
*/
|
||||
public function ipv6MaskTest(string $test_range, string $ip_to_test): bool
|
||||
public function ipv6MaskTest(string $testRange, string $ipToTest): bool
|
||||
{
|
||||
$result = true;
|
||||
|
||||
// convert to lowercase for easier comparison
|
||||
$test_range = mb_strtolower($test_range);
|
||||
$ip_to_test = mb_strtolower($ip_to_test);
|
||||
$testRange = mb_strtolower($testRange);
|
||||
$ipToTest = mb_strtolower($ipToTest);
|
||||
|
||||
$is_cidr = mb_strpos($test_range, '/') > -1;
|
||||
$is_range = mb_strpos($test_range, '[') > -1;
|
||||
$is_single = ! $is_cidr && ! $is_range;
|
||||
$isCidr = mb_strpos($testRange, '/') > -1;
|
||||
$isRange = mb_strpos($testRange, '[') > -1;
|
||||
$isSingle = ! $isCidr && ! $isRange;
|
||||
|
||||
$ip_hex = bin2hex((string) inet_pton($ip_to_test));
|
||||
$ipHex = bin2hex((string) inet_pton($ipToTest));
|
||||
|
||||
if ($is_single) {
|
||||
$range_hex = bin2hex((string) inet_pton($test_range));
|
||||
if ($isSingle) {
|
||||
$rangeHex = bin2hex((string) inet_pton($testRange));
|
||||
|
||||
return hash_equals($ip_hex, $range_hex);
|
||||
return hash_equals($ipHex, $rangeHex);
|
||||
}
|
||||
|
||||
if ($is_range) {
|
||||
if ($isRange) {
|
||||
// what range do we operate on?
|
||||
$range_match = [];
|
||||
$match = preg_match('/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $test_range, $range_match);
|
||||
$rangeMatch = [];
|
||||
$match = preg_match('/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $testRange, $rangeMatch);
|
||||
if ($match) {
|
||||
$range_start = $range_match[1];
|
||||
$range_end = $range_match[2];
|
||||
$rangeStart = $rangeMatch[1];
|
||||
$rangeEnd = $rangeMatch[2];
|
||||
|
||||
// get the first and last allowed IPs
|
||||
$first_ip = str_replace($range_match[0], $range_start, $test_range);
|
||||
$first_hex = bin2hex((string) inet_pton($first_ip));
|
||||
$last_ip = str_replace($range_match[0], $range_end, $test_range);
|
||||
$last_hex = bin2hex((string) inet_pton($last_ip));
|
||||
$firstIp = str_replace($rangeMatch[0], $rangeStart, $testRange);
|
||||
$firstHex = bin2hex((string) inet_pton($firstIp));
|
||||
$lastIp = str_replace($rangeMatch[0], $rangeEnd, $testRange);
|
||||
$lastHex = bin2hex((string) inet_pton($lastIp));
|
||||
|
||||
// check if the IP to test is within the range
|
||||
$result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
|
||||
$result = ($ipHex >= $firstHex && $ipHex <= $lastHex);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($is_cidr) {
|
||||
if ($isCidr) {
|
||||
// Split in address and prefix length
|
||||
[$first_ip, $subnet] = explode('/', $test_range);
|
||||
[$firstIp, $subnet] = explode('/', $testRange);
|
||||
|
||||
// Parse the address into a binary string
|
||||
$first_bin = inet_pton($first_ip);
|
||||
$first_hex = bin2hex((string) $first_bin);
|
||||
$firstBin = inet_pton($firstIp);
|
||||
$firstHex = bin2hex((string) $firstBin);
|
||||
|
||||
$flexbits = 128 - (int) $subnet;
|
||||
|
||||
// Build the hexadecimal string of the last address
|
||||
$last_hex = $first_hex;
|
||||
$lastHex = $firstHex;
|
||||
|
||||
$pos = 31;
|
||||
while ($flexbits > 0) {
|
||||
// Get the character at this position
|
||||
$orig = mb_substr($last_hex, $pos, 1);
|
||||
$orig = mb_substr($lastHex, $pos, 1);
|
||||
|
||||
// Convert it to an integer
|
||||
$origval = hexdec($orig);
|
||||
@ -193,7 +193,7 @@ class IpAllowDeny
|
||||
$new = dechex($newval);
|
||||
|
||||
// And put that character back in the string
|
||||
$last_hex = substr_replace($last_hex, $new, $pos, 1);
|
||||
$lastHex = substr_replace($lastHex, $new, $pos, 1);
|
||||
|
||||
// We processed one nibble, move to previous position
|
||||
$flexbits -= 4;
|
||||
@ -201,7 +201,7 @@ class IpAllowDeny
|
||||
}
|
||||
|
||||
// check if the IP to test is within the range
|
||||
$result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
|
||||
$result = ($ipHex >= $firstHex && $ipHex <= $lastHex);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -237,8 +237,8 @@ class IpAllowDeny
|
||||
private function allowDeny(string $type): bool
|
||||
{
|
||||
// Grabs true IP of the user and returns if it can't be found
|
||||
$remote_ip = Core::getIp();
|
||||
if (empty($remote_ip)) {
|
||||
$remoteIp = Core::getIp();
|
||||
if (empty($remoteIp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -270,37 +270,37 @@ class IpAllowDeny
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
// extract rule data
|
||||
$rule_data = explode(' ', $rule);
|
||||
$ruleData = explode(' ', $rule);
|
||||
|
||||
// check for rule type
|
||||
if ($rule_data[0] != $type) {
|
||||
if ($ruleData[0] != $type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for username
|
||||
if (
|
||||
($rule_data[1] !== '%') //wildcarded first
|
||||
&& (! hash_equals($rule_data[1], $username))
|
||||
($ruleData[1] !== '%') //wildcarded first
|
||||
&& (! hash_equals($ruleData[1], $username))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if the config file has the full string with an extra
|
||||
// 'from' in it and if it does, just discard it
|
||||
if ($rule_data[2] === 'from') {
|
||||
$rule_data[2] = $rule_data[3];
|
||||
if ($ruleData[2] === 'from') {
|
||||
$ruleData[2] = $ruleData[3];
|
||||
}
|
||||
|
||||
// Handle shortcuts with above array
|
||||
if (isset($shortcuts[$rule_data[2]])) {
|
||||
$rule_data[2] = $shortcuts[$rule_data[2]];
|
||||
if (isset($shortcuts[$ruleData[2]])) {
|
||||
$ruleData[2] = $shortcuts[$ruleData[2]];
|
||||
}
|
||||
|
||||
// Add code for host lookups here
|
||||
// Excluded for the moment
|
||||
|
||||
// Do the actual matching now
|
||||
if ($this->ipMaskTest($rule_data[2], $remote_ip)) {
|
||||
if ($this->ipMaskTest($ruleData[2], $remoteIp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -924,9 +924,9 @@ class LanguageManager
|
||||
$langs = $this->availableLanguages();
|
||||
|
||||
// try to find out user's language by checking its HTTP_ACCEPT_LANGUAGE variable;
|
||||
$accepted_languages = Core::getenv('HTTP_ACCEPT_LANGUAGE');
|
||||
if ($accepted_languages) {
|
||||
foreach (explode(',', $accepted_languages) as $header) {
|
||||
$acceptedLanguages = Core::getenv('HTTP_ACCEPT_LANGUAGE');
|
||||
if ($acceptedLanguages) {
|
||||
foreach (explode(',', $acceptedLanguages) as $header) {
|
||||
foreach ($langs as $language) {
|
||||
if ($language->matchesAcceptLanguage($header)) {
|
||||
return $language;
|
||||
@ -936,10 +936,10 @@ class LanguageManager
|
||||
}
|
||||
|
||||
// try to find out user's language by checking its HTTP_USER_AGENT variable
|
||||
$user_agent = Core::getenv('HTTP_USER_AGENT');
|
||||
if ($user_agent !== '') {
|
||||
$userAgent = Core::getenv('HTTP_USER_AGENT');
|
||||
if ($userAgent !== '') {
|
||||
foreach ($langs as $language) {
|
||||
if ($language->matchesUserAgent($user_agent)) {
|
||||
if ($language->matchesUserAgent($userAgent)) {
|
||||
return $language;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,29 +77,29 @@ class ListDatabase extends ListAbstract
|
||||
/**
|
||||
* retrieves database list from server
|
||||
*
|
||||
* @param string|null $like_db_name usually a db_name containing wildcards
|
||||
* @param string|null $likeDbName usually a db_name containing wildcards
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function retrieve(string|null $like_db_name = null): array
|
||||
protected function retrieve(string|null $likeDbName = null): array
|
||||
{
|
||||
$database_list = [];
|
||||
$databaseList = [];
|
||||
$command = '';
|
||||
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
|
||||
$command .= 'SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`';
|
||||
if ($like_db_name !== null) {
|
||||
$command .= " WHERE `SCHEMA_NAME` LIKE '" . $like_db_name . "'";
|
||||
if ($likeDbName !== null) {
|
||||
$command .= " WHERE `SCHEMA_NAME` LIKE '" . $likeDbName . "'";
|
||||
}
|
||||
} else {
|
||||
if ($GLOBALS['dbs_to_test'] === false || $like_db_name !== null) {
|
||||
if ($GLOBALS['dbs_to_test'] === false || $likeDbName !== null) {
|
||||
$command .= 'SHOW DATABASES';
|
||||
if ($like_db_name !== null) {
|
||||
$command .= " LIKE '" . $like_db_name . "'";
|
||||
if ($likeDbName !== null) {
|
||||
$command .= " LIKE '" . $likeDbName . "'";
|
||||
}
|
||||
} else {
|
||||
foreach ($GLOBALS['dbs_to_test'] as $db) {
|
||||
$database_list = array_merge(
|
||||
$database_list,
|
||||
$databaseList = array_merge(
|
||||
$databaseList,
|
||||
$this->retrieve($db),
|
||||
);
|
||||
}
|
||||
@ -107,18 +107,18 @@ class ListDatabase extends ListAbstract
|
||||
}
|
||||
|
||||
if ($command) {
|
||||
$database_list = $GLOBALS['dbi']->fetchResult($command, null, null);
|
||||
$databaseList = $GLOBALS['dbi']->fetchResult($command, null, null);
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
usort($database_list, 'strnatcasecmp');
|
||||
usort($databaseList, 'strnatcasecmp');
|
||||
} else {
|
||||
// need to sort anyway, otherwise information_schema
|
||||
// goes at the top
|
||||
sort($database_list);
|
||||
sort($databaseList);
|
||||
}
|
||||
|
||||
return $database_list;
|
||||
return $databaseList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,16 +151,16 @@ class ListDatabase extends ListAbstract
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) {
|
||||
foreach ($GLOBALS['cfg']['Server']['only_db'] as $eachOnlyDb) {
|
||||
// check if the db name contains wildcard,
|
||||
// thus containing not escaped _ or %
|
||||
if (! preg_match('/(^|[^\\\\])(_|%)/', $each_only_db)) {
|
||||
if (! preg_match('/(^|[^\\\\])(_|%)/', $eachOnlyDb)) {
|
||||
// ... not contains wildcard
|
||||
$items[] = strtr($each_only_db, ['\\\\' => '\\', '\\_' => '_', '\\%' => '%']);
|
||||
$items[] = strtr($eachOnlyDb, ['\\\\' => '\\', '\\_' => '_', '\\%' => '%']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$items = array_merge($items, $this->retrieve($each_only_db));
|
||||
$items = array_merge($items, $this->retrieve($eachOnlyDb));
|
||||
}
|
||||
|
||||
$this->exchangeArray($items);
|
||||
|
||||
@ -31,20 +31,20 @@ class Logging
|
||||
*/
|
||||
public static function getLogDestination(): string
|
||||
{
|
||||
$log_file = $GLOBALS['config']->get('AuthLog');
|
||||
$logFile = $GLOBALS['config']->get('AuthLog');
|
||||
|
||||
/* Autodetect */
|
||||
if ($log_file === 'auto') {
|
||||
if ($logFile === 'auto') {
|
||||
if (function_exists('syslog')) {
|
||||
$log_file = 'syslog';
|
||||
$logFile = 'syslog';
|
||||
} elseif (function_exists('error_log')) {
|
||||
$log_file = 'php';
|
||||
$logFile = 'php';
|
||||
} else {
|
||||
$log_file = '';
|
||||
$logFile = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $log_file;
|
||||
return $logFile;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,27 +80,27 @@ class Logging
|
||||
return;
|
||||
}
|
||||
|
||||
$log_file = self::getLogDestination();
|
||||
if (empty($log_file)) {
|
||||
$logFile = self::getLogDestination();
|
||||
if (empty($logFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = self::getLogMessage($user, $status);
|
||||
if ($log_file === 'syslog') {
|
||||
if ($logFile === 'syslog') {
|
||||
if (function_exists('syslog')) {
|
||||
@openlog('phpMyAdmin', LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
|
||||
@syslog(LOG_WARNING, $message);
|
||||
closelog();
|
||||
}
|
||||
} elseif ($log_file === 'php') {
|
||||
} elseif ($logFile === 'php') {
|
||||
@error_log($message);
|
||||
} elseif ($log_file === 'sapi') {
|
||||
} elseif ($logFile === 'sapi') {
|
||||
@error_log($message, 4);
|
||||
} else {
|
||||
@error_log(
|
||||
date('M d H:i:s') . ' phpmyadmin: ' . $message . "\n",
|
||||
3,
|
||||
$log_file,
|
||||
$logFile,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -625,8 +625,8 @@ class Message implements Stringable
|
||||
$message = self::decodeBB($message);
|
||||
}
|
||||
|
||||
foreach ($this->getAddedMessages() as $add_message) {
|
||||
$message .= $add_message;
|
||||
foreach ($this->getAddedMessages() as $addMessage) {
|
||||
$message .= $addMessage;
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
||||
@ -201,14 +201,14 @@ class Partition extends SubPartition
|
||||
public static function getPartitionMethod(string $db, string $table): string|null
|
||||
{
|
||||
if (self::havePartitioning()) {
|
||||
$partition_method = $GLOBALS['dbi']->fetchResult(
|
||||
$partitionMethod = $GLOBALS['dbi']->fetchResult(
|
||||
'SELECT `PARTITION_METHOD` FROM `information_schema`.`PARTITIONS`'
|
||||
. ' WHERE `TABLE_SCHEMA` = ' . $GLOBALS['dbi']->quoteString($db)
|
||||
. ' AND `TABLE_NAME` = ' . $GLOBALS['dbi']->quoteString($table)
|
||||
. ' LIMIT 1',
|
||||
);
|
||||
if (! empty($partition_method)) {
|
||||
return $partition_method[0];
|
||||
if (! empty($partitionMethod)) {
|
||||
return $partitionMethod[0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,30 +223,30 @@ class Partition extends SubPartition
|
||||
*/
|
||||
public static function havePartitioning(): bool
|
||||
{
|
||||
static $have_partitioning = false;
|
||||
static $already_checked = false;
|
||||
static $havePartitioning = false;
|
||||
static $alreadyChecked = false;
|
||||
|
||||
if (! $already_checked) {
|
||||
if (! $alreadyChecked) {
|
||||
if ($GLOBALS['dbi']->getVersion() < 50600) {
|
||||
if ($GLOBALS['dbi']->fetchValue('SELECT @@have_partitioning;')) {
|
||||
$have_partitioning = true;
|
||||
$havePartitioning = true;
|
||||
}
|
||||
} elseif ($GLOBALS['dbi']->getVersion() >= 80000) {
|
||||
$have_partitioning = true;
|
||||
$havePartitioning = true;
|
||||
} else {
|
||||
// see https://dev.mysql.com/doc/refman/5.6/en/partitioning.html
|
||||
$plugins = $GLOBALS['dbi']->fetchResult('SHOW PLUGINS');
|
||||
foreach ($plugins as $value) {
|
||||
if ($value['Name'] === 'partition') {
|
||||
$have_partitioning = true;
|
||||
$havePartitioning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$already_checked = true;
|
||||
$alreadyChecked = true;
|
||||
}
|
||||
|
||||
return $have_partitioning;
|
||||
return $havePartitioning;
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,13 +127,13 @@ class Pdf extends TCPDF
|
||||
/**
|
||||
* Displays an error message
|
||||
*
|
||||
* @param string $error_message the error message
|
||||
* @param string $errorMessage the error message
|
||||
*/
|
||||
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
public function Error($error_message = ''): void
|
||||
public function Error($errorMessage = ''): void
|
||||
{
|
||||
echo Message::error(
|
||||
__('Error while creating PDF:') . ' ' . $error_message,
|
||||
__('Error while creating PDF:') . ' ' . $errorMessage,
|
||||
)->getDisplay();
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -283,29 +283,29 @@ class Plugins
|
||||
* Returns single option in a list element
|
||||
*
|
||||
* @param string $section name of config section in $GLOBALS['cfg'][$section] for plugin
|
||||
* @param string $plugin_name unique plugin name
|
||||
* @param string $pluginName unique plugin name
|
||||
* @param OptionsPropertyItem $propertyGroup options property main group instance
|
||||
* @param bool $is_subgroup if this group is a subgroup
|
||||
* @param bool $isSubgroup if this group is a subgroup
|
||||
* @psalm-param 'Export'|'Import'|'Schema' $section
|
||||
*
|
||||
* @return string table row with option
|
||||
*/
|
||||
private static function getOneOption(
|
||||
string $section,
|
||||
string $plugin_name,
|
||||
string $pluginName,
|
||||
OptionsPropertyItem $propertyGroup,
|
||||
bool $is_subgroup = false,
|
||||
bool $isSubgroup = false,
|
||||
): string {
|
||||
$ret = "\n";
|
||||
|
||||
$properties = null;
|
||||
if (! $is_subgroup) {
|
||||
if (! $isSubgroup) {
|
||||
// for subgroup headers
|
||||
if (mb_strpos($propertyGroup::class, 'PropertyItem')) {
|
||||
$properties = [$propertyGroup];
|
||||
} else {
|
||||
// for main groups
|
||||
$ret .= '<div id="' . $plugin_name . '_' . $propertyGroup->getName() . '">';
|
||||
$ret .= '<div id="' . $pluginName . '_' . $propertyGroup->getName() . '">';
|
||||
|
||||
$text = null;
|
||||
if (method_exists($propertyGroup, 'getText')) {
|
||||
@ -320,49 +320,49 @@ class Plugins
|
||||
}
|
||||
}
|
||||
|
||||
$not_subgroup_header = false;
|
||||
$notSubgroupHeader = false;
|
||||
if ($properties === null) {
|
||||
$not_subgroup_header = true;
|
||||
$notSubgroupHeader = true;
|
||||
if ($propertyGroup instanceof OptionsPropertyGroup) {
|
||||
$properties = $propertyGroup->getProperties();
|
||||
}
|
||||
}
|
||||
|
||||
$property_class = null;
|
||||
$propertyClass = null;
|
||||
if ($properties !== null) {
|
||||
/** @var OptionsPropertySubgroup $propertyItem */
|
||||
foreach ($properties as $propertyItem) {
|
||||
$property_class = $propertyItem::class;
|
||||
$propertyClass = $propertyItem::class;
|
||||
// if the property is a subgroup, we deal with it recursively
|
||||
if (mb_strpos($property_class, 'Subgroup')) {
|
||||
if (mb_strpos($propertyClass, 'Subgroup')) {
|
||||
// for subgroups
|
||||
// each subgroup can have a header, which may also be a form element
|
||||
/** @var OptionsPropertyItem|null $subgroup_header */
|
||||
$subgroup_header = $propertyItem->getSubgroupHeader();
|
||||
if ($subgroup_header !== null) {
|
||||
$ret .= self::getOneOption($section, $plugin_name, $subgroup_header);
|
||||
/** @var OptionsPropertyItem|null $subgroupHeader */
|
||||
$subgroupHeader = $propertyItem->getSubgroupHeader();
|
||||
if ($subgroupHeader !== null) {
|
||||
$ret .= self::getOneOption($section, $pluginName, $subgroupHeader);
|
||||
}
|
||||
|
||||
$ret .= '<li class="list-group-item"><ul class="list-group"';
|
||||
if ($subgroup_header !== null) {
|
||||
$ret .= ' id="ul_' . $subgroup_header->getName() . '">';
|
||||
if ($subgroupHeader !== null) {
|
||||
$ret .= ' id="ul_' . $subgroupHeader->getName() . '">';
|
||||
} else {
|
||||
$ret .= '>';
|
||||
}
|
||||
|
||||
$ret .= self::getOneOption($section, $plugin_name, $propertyItem, true);
|
||||
$ret .= self::getOneOption($section, $pluginName, $propertyItem, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// single property item
|
||||
$ret .= self::getHtmlForProperty($section, $plugin_name, $propertyItem);
|
||||
$ret .= self::getHtmlForProperty($section, $pluginName, $propertyItem);
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_subgroup) {
|
||||
if ($isSubgroup) {
|
||||
// end subgroup
|
||||
$ret .= '</ul></li>';
|
||||
} elseif ($not_subgroup_header) {
|
||||
} elseif ($notSubgroupHeader) {
|
||||
// end main group
|
||||
$ret .= '</ul></div>';
|
||||
}
|
||||
@ -382,10 +382,10 @@ class Plugins
|
||||
|
||||
// Close the list element after $doc link is displayed
|
||||
if (
|
||||
$property_class === BoolPropertyItem::class
|
||||
|| $property_class === MessageOnlyPropertyItem::class
|
||||
|| $property_class === SelectPropertyItem::class
|
||||
|| $property_class === TextPropertyItem::class
|
||||
$propertyClass === BoolPropertyItem::class
|
||||
|| $propertyClass === MessageOnlyPropertyItem::class
|
||||
|| $propertyClass === SelectPropertyItem::class
|
||||
|| $propertyClass === TextPropertyItem::class
|
||||
) {
|
||||
$ret .= '</li>';
|
||||
}
|
||||
@ -398,44 +398,44 @@ class Plugins
|
||||
*
|
||||
* @param string $section name of config section in
|
||||
* $GLOBALS['cfg'][$section] for plugin
|
||||
* @param string $plugin_name unique plugin name
|
||||
* @param string $pluginName unique plugin name
|
||||
* @param OptionsPropertyItem $propertyItem Property item
|
||||
* @psalm-param 'Export'|'Import'|'Schema' $section
|
||||
*/
|
||||
public static function getHtmlForProperty(
|
||||
string $section,
|
||||
string $plugin_name,
|
||||
string $pluginName,
|
||||
OptionsPropertyItem $propertyItem,
|
||||
): string {
|
||||
$ret = '';
|
||||
$property_class = $propertyItem::class;
|
||||
switch ($property_class) {
|
||||
$propertyClass = $propertyItem::class;
|
||||
switch ($propertyClass) {
|
||||
case BoolPropertyItem::class:
|
||||
$ret .= '<li class="list-group-item">' . "\n";
|
||||
$ret .= '<div class="form-check form-switch">' . "\n";
|
||||
$ret .= '<input class="form-check-input" type="checkbox" role="switch" name="' . $plugin_name . '_'
|
||||
$ret .= '<input class="form-check-input" type="checkbox" role="switch" name="' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '"'
|
||||
. ' value="something" id="checkbox_' . $plugin_name . '_'
|
||||
. ' value="something" id="checkbox_' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '"'
|
||||
. ' '
|
||||
. self::checkboxCheck(
|
||||
$section,
|
||||
$plugin_name . '_' . $propertyItem->getName(),
|
||||
$pluginName . '_' . $propertyItem->getName(),
|
||||
);
|
||||
|
||||
if ($propertyItem->getForce() != null) {
|
||||
// Same code is also few lines lower, update both if needed
|
||||
$ret .= ' onclick="if (!this.checked && '
|
||||
. '(!document.getElementById(\'checkbox_' . $plugin_name
|
||||
. '(!document.getElementById(\'checkbox_' . $pluginName
|
||||
. '_' . $propertyItem->getForce() . '\') '
|
||||
. '|| !document.getElementById(\'checkbox_'
|
||||
. $plugin_name . '_' . $propertyItem->getForce()
|
||||
. $pluginName . '_' . $propertyItem->getForce()
|
||||
. '\').checked)) '
|
||||
. 'return false; else return true;"';
|
||||
}
|
||||
|
||||
$ret .= '>';
|
||||
$ret .= '<label class="form-check-label" for="checkbox_' . $plugin_name . '_'
|
||||
$ret .= '<label class="form-check-label" for="checkbox_' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '">'
|
||||
. self::getString($propertyItem->getText()) . '</label></div>';
|
||||
break;
|
||||
@ -443,11 +443,11 @@ class Plugins
|
||||
echo DocPropertyItem::class;
|
||||
break;
|
||||
case HiddenPropertyItem::class:
|
||||
$ret .= '<li class="list-group-item"><input type="hidden" name="' . $plugin_name . '_'
|
||||
$ret .= '<li class="list-group-item"><input type="hidden" name="' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '"'
|
||||
. ' value="' . self::getDefault(
|
||||
$section,
|
||||
$plugin_name . '_' . $propertyItem->getName(),
|
||||
$pluginName . '_' . $propertyItem->getName(),
|
||||
)
|
||||
. '"></li>';
|
||||
break;
|
||||
@ -461,21 +461,21 @@ class Plugins
|
||||
|
||||
$default = self::getDefault(
|
||||
$section,
|
||||
$plugin_name . '_' . $pitem->getName(),
|
||||
$pluginName . '_' . $pitem->getName(),
|
||||
);
|
||||
|
||||
$ret .= '<li class="list-group-item">';
|
||||
|
||||
foreach ($pitem->getValues() as $key => $val) {
|
||||
$ret .= '<div class="form-check"><input type="radio" name="' . $plugin_name
|
||||
$ret .= '<div class="form-check"><input type="radio" name="' . $pluginName
|
||||
. '_' . $pitem->getName() . '" class="form-check-input" value="' . $key
|
||||
. '" id="radio_' . $plugin_name . '_'
|
||||
. '" id="radio_' . $pluginName . '_'
|
||||
. $pitem->getName() . '_' . $key . '"';
|
||||
if ($key == $default) {
|
||||
$ret .= ' checked';
|
||||
}
|
||||
|
||||
$ret .= '><label class="form-check-label" for="radio_' . $plugin_name . '_'
|
||||
$ret .= '><label class="form-check-label" for="radio_' . $pluginName . '_'
|
||||
. $pitem->getName() . '_' . $key . '">'
|
||||
. self::getString($val) . '</label></div>';
|
||||
}
|
||||
@ -487,16 +487,16 @@ class Plugins
|
||||
/** @var SelectPropertyItem $pitem */
|
||||
$pitem = $propertyItem;
|
||||
$ret .= '<li class="list-group-item">' . "\n";
|
||||
$ret .= '<label for="select_' . $plugin_name . '_'
|
||||
$ret .= '<label for="select_' . $pluginName . '_'
|
||||
. $pitem->getName() . '" class="form-label">'
|
||||
. self::getString($pitem->getText()) . '</label>';
|
||||
$ret .= '<select class="form-select" name="' . $plugin_name . '_'
|
||||
$ret .= '<select class="form-select" name="' . $pluginName . '_'
|
||||
. $pitem->getName() . '"'
|
||||
. ' id="select_' . $plugin_name . '_'
|
||||
. ' id="select_' . $pluginName . '_'
|
||||
. $pitem->getName() . '">';
|
||||
$default = self::getDefault(
|
||||
$section,
|
||||
$plugin_name . '_' . $pitem->getName(),
|
||||
$pluginName . '_' . $pitem->getName(),
|
||||
);
|
||||
foreach ($pitem->getValues() as $key => $val) {
|
||||
$ret .= '<option value="' . $key . '"';
|
||||
@ -513,16 +513,16 @@ class Plugins
|
||||
/** @var TextPropertyItem $pitem */
|
||||
$pitem = $propertyItem;
|
||||
$ret .= '<li class="list-group-item">' . "\n";
|
||||
$ret .= '<label for="text_' . $plugin_name . '_'
|
||||
$ret .= '<label for="text_' . $pluginName . '_'
|
||||
. $pitem->getName() . '" class="form-label">'
|
||||
. self::getString($pitem->getText()) . '</label>';
|
||||
$ret .= '<input class="form-control" type="text" name="' . $plugin_name . '_'
|
||||
$ret .= '<input class="form-control" type="text" name="' . $pluginName . '_'
|
||||
. $pitem->getName() . '"'
|
||||
. ' value="' . self::getDefault(
|
||||
$section,
|
||||
$plugin_name . '_' . $pitem->getName(),
|
||||
$pluginName . '_' . $pitem->getName(),
|
||||
) . '"'
|
||||
. ' id="text_' . $plugin_name . '_'
|
||||
. ' id="text_' . $pluginName . '_'
|
||||
. $pitem->getName() . '"'
|
||||
. ($pitem->getSize() !== 0
|
||||
? ' size="' . $pitem->getSize() . '"'
|
||||
@ -534,16 +534,16 @@ class Plugins
|
||||
break;
|
||||
case NumberPropertyItem::class:
|
||||
$ret .= '<li class="list-group-item">' . "\n";
|
||||
$ret .= '<label for="number_' . $plugin_name . '_'
|
||||
$ret .= '<label for="number_' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '" class="form-label">'
|
||||
. self::getString($propertyItem->getText()) . '</label>';
|
||||
$ret .= '<input class="form-control" type="number" name="' . $plugin_name . '_'
|
||||
$ret .= '<input class="form-control" type="number" name="' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '"'
|
||||
. ' value="' . self::getDefault(
|
||||
$section,
|
||||
$plugin_name . '_' . $propertyItem->getName(),
|
||||
$pluginName . '_' . $propertyItem->getName(),
|
||||
) . '"'
|
||||
. ' id="number_' . $plugin_name . '_'
|
||||
. ' id="number_' . $pluginName . '_'
|
||||
. $propertyItem->getName() . '"'
|
||||
. ' min="0"'
|
||||
. '>';
|
||||
@ -573,29 +573,29 @@ class Plugins
|
||||
$text = $properties->getText();
|
||||
$options = $properties->getOptions();
|
||||
|
||||
$plugin_name = $plugin->getName();
|
||||
$pluginName = $plugin->getName();
|
||||
|
||||
$ret .= '<div id="' . $plugin_name
|
||||
$ret .= '<div id="' . $pluginName
|
||||
. '_options" class="format_specific_options">';
|
||||
$ret .= '<h3>' . self::getString($text) . '</h3>';
|
||||
|
||||
$no_options = true;
|
||||
$noOptions = true;
|
||||
if ($options !== null && count($options) > 0) {
|
||||
foreach ($options->getProperties() as $propertyMainGroup) {
|
||||
// check for hidden properties
|
||||
$no_options = true;
|
||||
$noOptions = true;
|
||||
foreach ($propertyMainGroup->getProperties() as $propertyItem) {
|
||||
if (! ($propertyItem instanceof HiddenPropertyItem)) {
|
||||
$no_options = false;
|
||||
$noOptions = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$ret .= self::getOneOption($section, $plugin_name, $propertyMainGroup);
|
||||
$ret .= self::getOneOption($section, $pluginName, $propertyMainGroup);
|
||||
}
|
||||
}
|
||||
|
||||
if ($no_options) {
|
||||
if ($noOptions) {
|
||||
$ret .= '<p class="card-text">' . __('This format has no options') . '</p>';
|
||||
}
|
||||
|
||||
|
||||
@ -75,9 +75,9 @@ class AuthenticationConfig extends AuthenticationPlugin
|
||||
{
|
||||
parent::showFailure($failure);
|
||||
|
||||
$conn_error = $GLOBALS['dbi']->getError();
|
||||
if (! $conn_error) {
|
||||
$conn_error = __('Cannot connect: invalid settings.');
|
||||
$connError = $GLOBALS['dbi']->getError();
|
||||
if (! $connError) {
|
||||
$connError = __('Cannot connect: invalid settings.');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
@ -135,7 +135,7 @@ class AuthenticationConfig extends AuthenticationPlugin
|
||||
);
|
||||
}
|
||||
|
||||
echo Generator::mysqlDie($conn_error, '', true, '', false);
|
||||
echo Generator::mysqlDie($connError, '', true, '', false);
|
||||
}
|
||||
|
||||
$GLOBALS['errorHandler']->dispUserErrors();
|
||||
|
||||
@ -75,8 +75,8 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
* new token explicitly with the response to update the token
|
||||
* in all the forms having a hidden token.
|
||||
*/
|
||||
$session_expired = isset($_REQUEST['check_timeout']) || isset($_REQUEST['session_timedout']);
|
||||
if (! $session_expired && $response->loginPage()) {
|
||||
$sessionExpired = isset($_REQUEST['check_timeout']) || isset($_REQUEST['session_timedout']);
|
||||
if (! $sessionExpired && $response->loginPage()) {
|
||||
if (defined('TESTSUITE')) {
|
||||
return true;
|
||||
}
|
||||
@ -89,7 +89,7 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
* new token explicitly with the response to update the token
|
||||
* in all the forms having a hidden token.
|
||||
*/
|
||||
if ($session_expired) {
|
||||
if ($sessionExpired) {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('new_token', $_SESSION[' PMA_token ']);
|
||||
}
|
||||
@ -105,17 +105,17 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
// No recall if blowfish secret is not configured as it would produce
|
||||
// garbage
|
||||
if ($GLOBALS['cfg']['LoginCookieRecall'] && ! empty($GLOBALS['cfg']['blowfish_secret'])) {
|
||||
$default_user = $this->user;
|
||||
$default_server = $GLOBALS['pma_auth_server'];
|
||||
$defaultUser = $this->user;
|
||||
$defaultServer = $GLOBALS['pma_auth_server'];
|
||||
$hasAutocomplete = true;
|
||||
} else {
|
||||
$default_user = '';
|
||||
$default_server = '';
|
||||
$defaultUser = '';
|
||||
$defaultServer = '';
|
||||
$hasAutocomplete = false;
|
||||
}
|
||||
|
||||
// wrap the login form in a div which overlays the whole page.
|
||||
if ($session_expired) {
|
||||
if ($sessionExpired) {
|
||||
$loginHeader = $this->template->render('login/header', [
|
||||
'add_class' => ' modal_form',
|
||||
'session_expired' => 1,
|
||||
@ -149,15 +149,15 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
$serversOptions = Select::render(false, false);
|
||||
}
|
||||
|
||||
$_form_params = [];
|
||||
$_form_params['route'] = Common::getRequest()->getRoute();
|
||||
$formParams = [];
|
||||
$formParams['route'] = Common::getRequest()->getRoute();
|
||||
|
||||
if (strlen($GLOBALS['db'])) {
|
||||
$_form_params['db'] = $GLOBALS['db'];
|
||||
$formParams['db'] = $GLOBALS['db'];
|
||||
}
|
||||
|
||||
if (strlen($GLOBALS['table'])) {
|
||||
$_form_params['table'] = $GLOBALS['table'];
|
||||
$formParams['table'] = $GLOBALS['table'];
|
||||
}
|
||||
|
||||
$errors = '';
|
||||
@ -166,7 +166,7 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
}
|
||||
|
||||
// close the wrapping div tag, if the request is after session timeout
|
||||
if ($session_expired) {
|
||||
if ($sessionExpired) {
|
||||
$loginFooter = $this->template->render('login/footer', ['session_expired' => 1]);
|
||||
} else {
|
||||
$loginFooter = $this->template->render('login/footer', ['session_expired' => 0]);
|
||||
@ -179,12 +179,12 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
'is_demo' => $GLOBALS['cfg']['DBG']['demo'],
|
||||
'error_messages' => $errorMessages,
|
||||
'available_languages' => $availableLanguages,
|
||||
'is_session_expired' => $session_expired,
|
||||
'is_session_expired' => $sessionExpired,
|
||||
'has_autocomplete' => $hasAutocomplete,
|
||||
'session_id' => session_id(),
|
||||
'is_arbitrary_server_allowed' => $GLOBALS['cfg']['AllowArbitraryServer'],
|
||||
'default_server' => $default_server,
|
||||
'default_user' => $default_user,
|
||||
'default_server' => $defaultServer,
|
||||
'default_user' => $defaultUser,
|
||||
'has_servers' => $hasServers,
|
||||
'server_options' => $serversOptions,
|
||||
'server' => $GLOBALS['server'],
|
||||
@ -199,7 +199,7 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
'captcha_req' => $GLOBALS['cfg']['CaptchaRequestParam'],
|
||||
'captcha_resp' => $GLOBALS['cfg']['CaptchaResponseParam'],
|
||||
'captcha_key' => $GLOBALS['cfg']['CaptchaLoginPublicKey'],
|
||||
'form_params' => $_form_params,
|
||||
'form_params' => $formParams,
|
||||
'errors' => $errors,
|
||||
'login_footer' => $loginFooter,
|
||||
'config_footer' => $configFooter,
|
||||
@ -313,12 +313,12 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
if ($GLOBALS['cfg']['ArbitraryServerRegexp']) {
|
||||
$parts = explode(' ', $_REQUEST['pma_servername']);
|
||||
if (count($parts) === 2) {
|
||||
$tmp_host = $parts[0];
|
||||
$tmpHost = $parts[0];
|
||||
} else {
|
||||
$tmp_host = $_REQUEST['pma_servername'];
|
||||
$tmpHost = $_REQUEST['pma_servername'];
|
||||
}
|
||||
|
||||
$match = preg_match($GLOBALS['cfg']['ArbitraryServerRegexp'], $tmp_host);
|
||||
$match = preg_match($GLOBALS['cfg']['ArbitraryServerRegexp'], $tmpHost);
|
||||
if (! $match) {
|
||||
$GLOBALS['conn_error'] = __('You are not allowed to log in to this MySQL server!');
|
||||
|
||||
@ -370,9 +370,9 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
}
|
||||
|
||||
// User inactive too long
|
||||
$last_access_time = time() - $GLOBALS['cfg']['LoginCookieValidity'];
|
||||
$lastAccessTime = time() - $GLOBALS['cfg']['LoginCookieValidity'];
|
||||
foreach ($_SESSION['browser_access_time'] as $key => $value) {
|
||||
if ($value >= $last_access_time) {
|
||||
if ($value >= $lastAccessTime) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -414,15 +414,15 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
return false;
|
||||
}
|
||||
|
||||
$auth_data = json_decode($value, true);
|
||||
$authData = json_decode($value, true);
|
||||
|
||||
if (! is_array($auth_data) || ! isset($auth_data['password'])) {
|
||||
if (! is_array($authData) || ! isset($authData['password'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->password = $auth_data['password'];
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer'] && ! empty($auth_data['server'])) {
|
||||
$GLOBALS['pma_auth_server'] = $auth_data['server'];
|
||||
$this->password = $authData['password'];
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer'] && ! empty($authData['server'])) {
|
||||
$GLOBALS['pma_auth_server'] = $authData['server'];
|
||||
}
|
||||
|
||||
$GLOBALS['from_cookie'] = true;
|
||||
@ -441,21 +441,21 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
/* Allow to specify 'host port' */
|
||||
$parts = explode(' ', $GLOBALS['pma_auth_server']);
|
||||
if (count($parts) === 2) {
|
||||
$tmp_host = $parts[0];
|
||||
$tmp_port = $parts[1];
|
||||
$tmpHost = $parts[0];
|
||||
$tmpPort = $parts[1];
|
||||
} else {
|
||||
$tmp_host = $GLOBALS['pma_auth_server'];
|
||||
$tmp_port = '';
|
||||
$tmpHost = $GLOBALS['pma_auth_server'];
|
||||
$tmpPort = '';
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['Server']['host'] != $GLOBALS['pma_auth_server']) {
|
||||
$GLOBALS['cfg']['Server']['host'] = $tmp_host;
|
||||
if (! empty($tmp_port)) {
|
||||
$GLOBALS['cfg']['Server']['port'] = $tmp_port;
|
||||
$GLOBALS['cfg']['Server']['host'] = $tmpHost;
|
||||
if (! empty($tmpPort)) {
|
||||
$GLOBALS['cfg']['Server']['port'] = $tmpPort;
|
||||
}
|
||||
}
|
||||
|
||||
unset($tmp_host, $tmp_port, $parts);
|
||||
unset($tmpHost, $tmpPort, $parts);
|
||||
}
|
||||
|
||||
return parent::storeCredentials();
|
||||
@ -478,15 +478,15 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
}
|
||||
|
||||
// any parameters to pass?
|
||||
$url_params = [];
|
||||
$url_params['route'] = Common::getRequest()->getRoute();
|
||||
$urlParams = [];
|
||||
$urlParams['route'] = Common::getRequest()->getRoute();
|
||||
|
||||
if (strlen($GLOBALS['db']) > 0) {
|
||||
$url_params['db'] = $GLOBALS['db'];
|
||||
$urlParams['db'] = $GLOBALS['db'];
|
||||
}
|
||||
|
||||
if (strlen($GLOBALS['table']) > 0) {
|
||||
$url_params['table'] = $GLOBALS['table'];
|
||||
$urlParams['table'] = $GLOBALS['table'];
|
||||
}
|
||||
|
||||
// user logged in successfully after session expiration
|
||||
@ -517,7 +517,7 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
ResponseRenderer::getInstance()->disable();
|
||||
|
||||
Core::sendHeaderLocation(
|
||||
'./index.php?route=/' . Url::getCommonRaw($url_params, '&'),
|
||||
'./index.php?route=/' . Url::getCommonRaw($urlParams, '&'),
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
@ -58,21 +58,21 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
{
|
||||
if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) {
|
||||
if (empty($GLOBALS['cfg']['Server']['verbose'])) {
|
||||
$server_message = $GLOBALS['cfg']['Server']['host'];
|
||||
$serverMessage = $GLOBALS['cfg']['Server']['host'];
|
||||
} else {
|
||||
$server_message = $GLOBALS['cfg']['Server']['verbose'];
|
||||
$serverMessage = $GLOBALS['cfg']['Server']['verbose'];
|
||||
}
|
||||
|
||||
$realm_message = 'phpMyAdmin ' . $server_message;
|
||||
$realmMessage = 'phpMyAdmin ' . $serverMessage;
|
||||
} else {
|
||||
$realm_message = $GLOBALS['cfg']['Server']['auth_http_realm'];
|
||||
$realmMessage = $GLOBALS['cfg']['Server']['auth_http_realm'];
|
||||
}
|
||||
|
||||
$response = ResponseRenderer::getInstance();
|
||||
|
||||
// remove non US-ASCII to respect RFC2616
|
||||
$realm_message = preg_replace('/[^\x20-\x7e]/i', '', $realm_message);
|
||||
$response->header('WWW-Authenticate: Basic realm="' . $realm_message . '"');
|
||||
$realmMessage = preg_replace('/[^\x20-\x7e]/i', '', $realmMessage);
|
||||
$response->header('WWW-Authenticate: Basic realm="' . $realmMessage . '"');
|
||||
$response->setHttpResponseCode(401);
|
||||
|
||||
/* HTML header */
|
||||
@ -156,26 +156,26 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
// Decode possibly encoded information (used by IIS/CGI/FastCGI)
|
||||
// (do not use explode() because a user might have a colon in their password
|
||||
if (strcmp(substr($this->user, 0, 6), 'Basic ') == 0) {
|
||||
$usr_pass = base64_decode(substr($this->user, 6));
|
||||
if (! empty($usr_pass)) {
|
||||
$colon = strpos($usr_pass, ':');
|
||||
$userPass = base64_decode(substr($this->user, 6));
|
||||
if (! empty($userPass)) {
|
||||
$colon = strpos($userPass, ':');
|
||||
if ($colon) {
|
||||
$this->user = substr($usr_pass, 0, $colon);
|
||||
$this->password = substr($usr_pass, $colon + 1);
|
||||
$this->user = substr($userPass, 0, $colon);
|
||||
$this->password = substr($userPass, $colon + 1);
|
||||
}
|
||||
|
||||
unset($colon);
|
||||
}
|
||||
|
||||
unset($usr_pass);
|
||||
unset($userPass);
|
||||
}
|
||||
|
||||
// sanitize username
|
||||
$this->user = Core::sanitizeMySQLUser($this->user);
|
||||
|
||||
// User logged out -> ensure the new username is not the same
|
||||
$old_usr = $_REQUEST['old_usr'] ?? '';
|
||||
if (! empty($old_usr) && hash_equals($old_usr, $this->user)) {
|
||||
$oldUser = $_REQUEST['old_usr'] ?? '';
|
||||
if (! empty($oldUser) && hash_equals($oldUser, $this->user)) {
|
||||
$this->user = '';
|
||||
}
|
||||
|
||||
|
||||
@ -107,45 +107,45 @@ class AuthenticationSignon extends AuthenticationPlugin
|
||||
public function readCredentials(): bool
|
||||
{
|
||||
/* Check if we're using same signon server */
|
||||
$signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
if (isset($_SESSION['LAST_SIGNON_URL']) && $_SESSION['LAST_SIGNON_URL'] != $signon_url) {
|
||||
$signonUrl = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
if (isset($_SESSION['LAST_SIGNON_URL']) && $_SESSION['LAST_SIGNON_URL'] != $signonUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Script name */
|
||||
$script_name = $GLOBALS['cfg']['Server']['SignonScript'];
|
||||
$scriptName = $GLOBALS['cfg']['Server']['SignonScript'];
|
||||
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
$sessionName = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Current host */
|
||||
$single_signon_host = $GLOBALS['cfg']['Server']['host'];
|
||||
$singleSignonHost = $GLOBALS['cfg']['Server']['host'];
|
||||
|
||||
/* Current port */
|
||||
$single_signon_port = $GLOBALS['cfg']['Server']['port'];
|
||||
$singleSignonPort = $GLOBALS['cfg']['Server']['port'];
|
||||
|
||||
/* No configuration updates */
|
||||
$single_signon_cfgupdate = [];
|
||||
$singleSignonCfgUpdate = [];
|
||||
|
||||
/* Handle script based auth */
|
||||
if ($script_name !== '') {
|
||||
if (! @file_exists($script_name)) {
|
||||
if ($scriptName !== '') {
|
||||
if (! @file_exists($scriptName)) {
|
||||
echo $this->template->render('error/generic', [
|
||||
'lang' => $GLOBALS['lang'] ?? 'en',
|
||||
'dir' => $GLOBALS['text_dir'] ?? 'ltr',
|
||||
'error_message' => __('Can not find signon authentication script:') . ' ' . $script_name,
|
||||
'error_message' => __('Can not find signon authentication script:') . ' ' . $scriptName,
|
||||
]);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
include $script_name;
|
||||
include $scriptName;
|
||||
|
||||
[$this->user, $this->password] = get_login_credentials($GLOBALS['cfg']['Server']['user']);
|
||||
} elseif (isset($_COOKIE[$session_name])) { /* Does session exist? */
|
||||
} elseif (isset($_COOKIE[$sessionName])) { /* Does session exist? */
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
$oldSession = session_name();
|
||||
$oldId = session_id();
|
||||
$oldCookieParams = session_get_cookie_params();
|
||||
if (! defined('TESTSUITE')) {
|
||||
session_write_close();
|
||||
@ -154,8 +154,8 @@ class AuthenticationSignon extends AuthenticationPlugin
|
||||
/* Load single signon session */
|
||||
if (! defined('TESTSUITE')) {
|
||||
$this->setCookieParams();
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_name($sessionName);
|
||||
session_id($_COOKIE[$sessionName]);
|
||||
session_start();
|
||||
}
|
||||
|
||||
@ -172,26 +172,26 @@ class AuthenticationSignon extends AuthenticationPlugin
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_host'])) {
|
||||
$single_signon_host = $_SESSION['PMA_single_signon_host'];
|
||||
$singleSignonHost = $_SESSION['PMA_single_signon_host'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_port'])) {
|
||||
$single_signon_port = $_SESSION['PMA_single_signon_port'];
|
||||
$singleSignonPort = $_SESSION['PMA_single_signon_port'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_cfgupdate'])) {
|
||||
$single_signon_cfgupdate = $_SESSION['PMA_single_signon_cfgupdate'];
|
||||
$singleSignonCfgUpdate = $_SESSION['PMA_single_signon_cfgupdate'];
|
||||
}
|
||||
|
||||
/* Also get token as it is needed to access subpages */
|
||||
if (isset($_SESSION['PMA_single_signon_token'])) {
|
||||
/* No need to care about token on logout */
|
||||
$pma_token = $_SESSION['PMA_single_signon_token'];
|
||||
$pmaToken = $_SESSION['PMA_single_signon_token'];
|
||||
}
|
||||
|
||||
$HMACSecret = Util::generateRandom(16);
|
||||
$hmacSecret = Util::generateRandom(16);
|
||||
if (isset($_SESSION['PMA_single_signon_HMAC_secret'])) {
|
||||
$HMACSecret = $_SESSION['PMA_single_signon_HMAC_secret'];
|
||||
$hmacSecret = $_SESSION['PMA_single_signon_HMAC_secret'];
|
||||
}
|
||||
|
||||
/* End single signon session */
|
||||
@ -202,30 +202,30 @@ class AuthenticationSignon extends AuthenticationPlugin
|
||||
/* Restart phpMyAdmin session */
|
||||
if (! defined('TESTSUITE')) {
|
||||
$this->setCookieParams($oldCookieParams);
|
||||
if ($old_session !== false) {
|
||||
session_name($old_session);
|
||||
if ($oldSession !== false) {
|
||||
session_name($oldSession);
|
||||
}
|
||||
|
||||
if (! empty($old_id)) {
|
||||
session_id($old_id);
|
||||
if (! empty($oldId)) {
|
||||
session_id($oldId);
|
||||
}
|
||||
|
||||
session_start();
|
||||
}
|
||||
|
||||
/* Set the single signon host */
|
||||
$GLOBALS['cfg']['Server']['host'] = $single_signon_host;
|
||||
$GLOBALS['cfg']['Server']['host'] = $singleSignonHost;
|
||||
|
||||
/* Set the single signon port */
|
||||
$GLOBALS['cfg']['Server']['port'] = $single_signon_port;
|
||||
$GLOBALS['cfg']['Server']['port'] = $singleSignonPort;
|
||||
|
||||
/* Configuration update */
|
||||
$GLOBALS['cfg']['Server'] = array_merge($GLOBALS['cfg']['Server'], $single_signon_cfgupdate);
|
||||
$GLOBALS['cfg']['Server'] = array_merge($GLOBALS['cfg']['Server'], $singleSignonCfgUpdate);
|
||||
|
||||
/* Restore our token */
|
||||
if (! empty($pma_token)) {
|
||||
$_SESSION[' PMA_token '] = $pma_token;
|
||||
$_SESSION[' HMAC_secret '] = $HMACSecret;
|
||||
if (! empty($pmaToken)) {
|
||||
$_SESSION[' PMA_token '] = $pmaToken;
|
||||
$_SESSION[' HMAC_secret '] = $hmacSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,18 +256,18 @@ class AuthenticationSignon extends AuthenticationPlugin
|
||||
parent::showFailure($failure);
|
||||
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
$sessionName = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Does session exist? */
|
||||
if (isset($_COOKIE[$session_name])) {
|
||||
if (isset($_COOKIE[$sessionName])) {
|
||||
if (! defined('TESTSUITE')) {
|
||||
/* End current session */
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
$this->setCookieParams();
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_name($sessionName);
|
||||
session_id($_COOKIE[$sessionName]);
|
||||
session_start();
|
||||
}
|
||||
|
||||
|
||||
@ -107,9 +107,9 @@ abstract class AuthenticationPlugin
|
||||
|
||||
/* Obtain redirect URL (before doing logout) */
|
||||
if (! empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
|
||||
$redirect_url = $GLOBALS['cfg']['Server']['LogoutURL'];
|
||||
$redirectUrl = $GLOBALS['cfg']['Server']['LogoutURL'];
|
||||
} else {
|
||||
$redirect_url = $this->getLoginFormURL();
|
||||
$redirectUrl = $this->getLoginFormURL();
|
||||
}
|
||||
|
||||
/* Clear credentials */
|
||||
@ -136,7 +136,7 @@ abstract class AuthenticationPlugin
|
||||
}
|
||||
|
||||
/* Redirect to login form (or configured URL) */
|
||||
Core::sendHeaderLocation($redirect_url);
|
||||
Core::sendHeaderLocation($redirectUrl);
|
||||
} else {
|
||||
/* Redirect to other authenticated server */
|
||||
$_SESSION['partial_logout'] = true;
|
||||
@ -177,9 +177,9 @@ abstract class AuthenticationPlugin
|
||||
);
|
||||
}
|
||||
|
||||
$dbi_error = $GLOBALS['dbi']->getError();
|
||||
if (! empty($dbi_error)) {
|
||||
return htmlspecialchars($dbi_error);
|
||||
$dbiError = $GLOBALS['dbi']->getError();
|
||||
if (! empty($dbiError)) {
|
||||
return htmlspecialchars($dbiError);
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['errno'])) {
|
||||
@ -270,17 +270,17 @@ abstract class AuthenticationPlugin
|
||||
// Check IP-based Allow/Deny rules as soon as possible to reject the
|
||||
// user based on mod_access in Apache
|
||||
if (isset($GLOBALS['cfg']['Server']['AllowDeny']['order'])) {
|
||||
$allowDeny_forbidden = false; // default
|
||||
$allowDenyForbidden = false; // default
|
||||
if ($GLOBALS['cfg']['Server']['AllowDeny']['order'] === 'allow,deny') {
|
||||
$allowDeny_forbidden = ! ($this->ipAllowDeny->allow() && ! $this->ipAllowDeny->deny());
|
||||
$allowDenyForbidden = ! ($this->ipAllowDeny->allow() && ! $this->ipAllowDeny->deny());
|
||||
} elseif ($GLOBALS['cfg']['Server']['AllowDeny']['order'] === 'deny,allow') {
|
||||
$allowDeny_forbidden = $this->ipAllowDeny->deny() && ! $this->ipAllowDeny->allow();
|
||||
$allowDenyForbidden = $this->ipAllowDeny->deny() && ! $this->ipAllowDeny->allow();
|
||||
} elseif ($GLOBALS['cfg']['Server']['AllowDeny']['order'] === 'explicit') {
|
||||
$allowDeny_forbidden = ! ($this->ipAllowDeny->allow() && ! $this->ipAllowDeny->deny());
|
||||
$allowDenyForbidden = ! ($this->ipAllowDeny->allow() && ! $this->ipAllowDeny->deny());
|
||||
}
|
||||
|
||||
// Ejects the user if banished
|
||||
if ($allowDeny_forbidden) {
|
||||
if ($allowDenyForbidden) {
|
||||
$this->showFailure('allow-denied');
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,9 +201,9 @@ class ExportCodegen extends ExportPlugin
|
||||
*/
|
||||
private function handleNHibernateCSBody(string $db, string $table, array $aliases = []): string
|
||||
{
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$result = $GLOBALS['dbi']->query(
|
||||
sprintf(
|
||||
@ -216,9 +216,9 @@ class ExportCodegen extends ExportPlugin
|
||||
/** @var TableProperty[] $tableProperties */
|
||||
$tableProperties = [];
|
||||
while ($row = $result->fetchRow()) {
|
||||
$col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
|
||||
if (! empty($col_as)) {
|
||||
$row[0] = $col_as;
|
||||
$colAs = $this->getAlias($aliases, $row[0], 'col', $db, $table);
|
||||
if (! empty($colAs)) {
|
||||
$row[0] = $colAs;
|
||||
}
|
||||
|
||||
$tableProperties[] = new TableProperty($row);
|
||||
@ -231,12 +231,12 @@ class ExportCodegen extends ExportPlugin
|
||||
$lines[] = 'using System.Collections;';
|
||||
$lines[] = 'using System.Collections.Generic;';
|
||||
$lines[] = 'using System.Text;';
|
||||
$lines[] = 'namespace ' . self::cgMakeIdentifier($db_alias);
|
||||
$lines[] = 'namespace ' . self::cgMakeIdentifier($dbAlias);
|
||||
$lines[] = '{';
|
||||
$lines[] = ' #region '
|
||||
. self::cgMakeIdentifier($table_alias);
|
||||
. self::cgMakeIdentifier($tableAlias);
|
||||
$lines[] = ' public class '
|
||||
. self::cgMakeIdentifier($table_alias);
|
||||
. self::cgMakeIdentifier($tableAlias);
|
||||
$lines[] = ' {';
|
||||
$lines[] = ' #region Member Variables';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
@ -246,7 +246,7 @@ class ExportCodegen extends ExportPlugin
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Constructors';
|
||||
$lines[] = ' public '
|
||||
. self::cgMakeIdentifier($table_alias) . '() { }';
|
||||
. self::cgMakeIdentifier($tableAlias) . '() { }';
|
||||
$temp = [];
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if ($tableProperty->isPK()) {
|
||||
@ -257,7 +257,7 @@ class ExportCodegen extends ExportPlugin
|
||||
}
|
||||
|
||||
$lines[] = ' public '
|
||||
. self::cgMakeIdentifier($table_alias)
|
||||
. self::cgMakeIdentifier($tableAlias)
|
||||
. '('
|
||||
. implode(', ', $temp)
|
||||
. ')';
|
||||
@ -306,17 +306,17 @@ class ExportCodegen extends ExportPlugin
|
||||
string $table,
|
||||
array $aliases = [],
|
||||
): string {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
$lines = [];
|
||||
$lines[] = '<?xml version="1.0" encoding="utf-8" ?>';
|
||||
$lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
|
||||
. 'namespace="' . self::cgMakeIdentifier($db_alias) . '" '
|
||||
. 'assembly="' . self::cgMakeIdentifier($db_alias) . '">';
|
||||
. 'namespace="' . self::cgMakeIdentifier($dbAlias) . '" '
|
||||
. 'assembly="' . self::cgMakeIdentifier($dbAlias) . '">';
|
||||
$lines[] = ' <class '
|
||||
. 'name="' . self::cgMakeIdentifier($table_alias) . '" '
|
||||
. 'table="' . self::cgMakeIdentifier($table_alias) . '">';
|
||||
. 'name="' . self::cgMakeIdentifier($tableAlias) . '" '
|
||||
. 'table="' . self::cgMakeIdentifier($tableAlias) . '">';
|
||||
$result = $GLOBALS['dbi']->query(
|
||||
sprintf(
|
||||
'DESC %s.%s',
|
||||
@ -326,9 +326,9 @@ class ExportCodegen extends ExportPlugin
|
||||
);
|
||||
|
||||
while ($row = $result->fetchRow()) {
|
||||
$col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
|
||||
if (! empty($col_as)) {
|
||||
$row[0] = $col_as;
|
||||
$colAs = $this->getAlias($aliases, $row[0], 'col', $db, $table);
|
||||
if (! empty($colAs)) {
|
||||
$row[0] = $colAs;
|
||||
}
|
||||
|
||||
$tableProperty = new TableProperty($row);
|
||||
@ -372,10 +372,10 @@ class ExportCodegen extends ExportPlugin
|
||||
/**
|
||||
* Setter for CodeGen formats
|
||||
*
|
||||
* @param array $CG_FORMATS contains CodeGen Formats
|
||||
* @param array $cgFormats contains CodeGen Formats
|
||||
*/
|
||||
private function setCgFormats(array $CG_FORMATS): void
|
||||
private function setCgFormats(array $cgFormats): void
|
||||
{
|
||||
$this->cgFormats = $CG_FORMATS;
|
||||
$this->cgFormats = $cgFormats;
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,9 +214,9 @@ class ExportCsv extends ExportPlugin
|
||||
$GLOBALS['csv_enclosed'] ??= null;
|
||||
$GLOBALS['csv_escaped'] ??= null;
|
||||
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
/**
|
||||
* Gets the data from the database
|
||||
@ -233,26 +233,26 @@ class ExportCsv extends ExportPlugin
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS['csv_columns']) && $GLOBALS['csv_columns']) {
|
||||
$insertFields = [];
|
||||
foreach ($result->getFieldNames() as $col_as) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
foreach ($result->getFieldNames() as $colAs) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
if ($GLOBALS['csv_enclosed'] == '') {
|
||||
$insertFields[] = $col_as;
|
||||
$insertFields[] = $colAs;
|
||||
} else {
|
||||
$insertFields[] = $GLOBALS['csv_enclosed']
|
||||
. str_replace(
|
||||
$GLOBALS['csv_enclosed'],
|
||||
$GLOBALS['csv_escaped'] . $GLOBALS['csv_enclosed'],
|
||||
$col_as,
|
||||
$colAs,
|
||||
)
|
||||
. $GLOBALS['csv_enclosed'];
|
||||
}
|
||||
}
|
||||
|
||||
$schema_insert = implode($GLOBALS['csv_separator'], $insertFields);
|
||||
if (! $this->export->outputHandler($schema_insert . $GLOBALS['csv_terminated'])) {
|
||||
$schemaInsert = implode($GLOBALS['csv_separator'], $insertFields);
|
||||
if (! $this->export->outputHandler($schemaInsert . $GLOBALS['csv_terminated'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -315,8 +315,8 @@ class ExportCsv extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
$schema_insert = implode($GLOBALS['csv_separator'], $insertValues);
|
||||
if (! $this->export->outputHandler($schema_insert . $GLOBALS['csv_terminated'])) {
|
||||
$schemaInsert = implode($GLOBALS['csv_separator'], $insertValues);
|
||||
if (! $this->export->outputHandler($schemaInsert . $GLOBALS['csv_terminated'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,14 +182,14 @@ class ExportHtmlword extends ExportPlugin
|
||||
): bool {
|
||||
$GLOBALS['what'] ??= null;
|
||||
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
if (
|
||||
! $this->export->outputHandler(
|
||||
'<h2>'
|
||||
. __('Dumping data for table') . ' ' . htmlspecialchars($table_alias)
|
||||
. __('Dumping data for table') . ' ' . htmlspecialchars($tableAlias)
|
||||
. '</h2>',
|
||||
)
|
||||
) {
|
||||
@ -214,26 +214,26 @@ class ExportHtmlword extends ExportPlugin
|
||||
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS['htmlword_columns'])) {
|
||||
$schema_insert = '<tr class="print-category">';
|
||||
foreach ($result->getFieldNames() as $col_as) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$schemaInsert = '<tr class="print-category">';
|
||||
foreach ($result->getFieldNames() as $colAs) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
. htmlspecialchars($col_as)
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. htmlspecialchars($colAs)
|
||||
. '</strong></td>';
|
||||
}
|
||||
|
||||
$schema_insert .= '</tr>';
|
||||
if (! $this->export->outputHandler($schema_insert)) {
|
||||
$schemaInsert .= '</tr>';
|
||||
if (! $this->export->outputHandler($schemaInsert)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Format the data
|
||||
while ($row = $result->fetchRow()) {
|
||||
$schema_insert = '<tr class="print-category">';
|
||||
$schemaInsert = '<tr class="print-category">';
|
||||
foreach ($row as $field) {
|
||||
if ($field === null) {
|
||||
$value = $GLOBALS[$GLOBALS['what'] . '_null'];
|
||||
@ -241,13 +241,13 @@ class ExportHtmlword extends ExportPlugin
|
||||
$value = $field;
|
||||
}
|
||||
|
||||
$schema_insert .= '<td class="print">'
|
||||
$schemaInsert .= '<td class="print">'
|
||||
. htmlspecialchars((string) $value)
|
||||
. '</td>';
|
||||
}
|
||||
|
||||
$schema_insert .= '</tr>';
|
||||
if (! $this->export->outputHandler($schema_insert)) {
|
||||
$schemaInsert .= '</tr>';
|
||||
if (! $this->export->outputHandler($schemaInsert)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -266,7 +266,7 @@ class ExportHtmlword extends ExportPlugin
|
||||
*/
|
||||
public function getTableDefStandIn(string $db, string $view, array $aliases = []): string
|
||||
{
|
||||
$schema_insert = '<table width="100%" cellspacing="1">'
|
||||
$schemaInsert = '<table width="100%" cellspacing="1">'
|
||||
. '<tr class="print-category">'
|
||||
. '<th class="print">'
|
||||
. __('Column')
|
||||
@ -285,63 +285,63 @@ class ExportHtmlword extends ExportPlugin
|
||||
/**
|
||||
* Get the unique keys in the view
|
||||
*/
|
||||
$unique_keys = [];
|
||||
$uniqueKeys = [];
|
||||
$keys = $GLOBALS['dbi']->getTableIndexes($db, $view);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
$uniqueKeys[] = $key['Column_name'];
|
||||
}
|
||||
|
||||
$columns = $GLOBALS['dbi']->getColumns($db, $view);
|
||||
foreach ($columns as $column) {
|
||||
$col_as = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$view]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$view]['columns'][$col_as];
|
||||
$colAs = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$view]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$view]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$schema_insert .= $this->formatOneColumnDefinition($column, $unique_keys, $col_as);
|
||||
$schema_insert .= '</tr>';
|
||||
$schemaInsert .= $this->formatOneColumnDefinition($column, $uniqueKeys, $colAs);
|
||||
$schemaInsert .= '</tr>';
|
||||
}
|
||||
|
||||
$schema_insert .= '</table>';
|
||||
$schemaInsert .= '</table>';
|
||||
|
||||
return $schema_insert;
|
||||
return $schemaInsert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns $table's CREATE definition
|
||||
*
|
||||
* @param string $db the database name
|
||||
* @param string $table the table name
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db the database name
|
||||
* @param string $table the table name
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* PMA_exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* at the end
|
||||
* @param bool $view whether we're handling a view
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $view whether we're handling a view
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*
|
||||
* @return string resulting schema
|
||||
*/
|
||||
public function getTableDef(
|
||||
string $db,
|
||||
string $table,
|
||||
bool $do_relation,
|
||||
bool $do_comments,
|
||||
bool $do_mime,
|
||||
bool $doRelation,
|
||||
bool $doComments,
|
||||
bool $doMime,
|
||||
bool $view = false,
|
||||
array $aliases = [],
|
||||
): string {
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
|
||||
$schema_insert = '';
|
||||
$schemaInsert = '';
|
||||
|
||||
/**
|
||||
* Gets fields properties
|
||||
@ -349,8 +349,8 @@ class ExportHtmlword extends ExportPlugin
|
||||
$GLOBALS['dbi']->selectDb($db);
|
||||
|
||||
// Check if we can use Relations
|
||||
[$res_rel, $have_rel] = $this->relation->getRelationsAndStatus(
|
||||
$do_relation && $relationParameters->relationFeature !== null,
|
||||
[$resRel, $haveRel] = $this->relation->getRelationsAndStatus(
|
||||
$doRelation && $relationParameters->relationFeature !== null,
|
||||
$db,
|
||||
$table,
|
||||
);
|
||||
@ -358,71 +358,71 @@ class ExportHtmlword extends ExportPlugin
|
||||
/**
|
||||
* Displays the table structure
|
||||
*/
|
||||
$schema_insert .= '<table width="100%" cellspacing="1">';
|
||||
$schemaInsert .= '<table width="100%" cellspacing="1">';
|
||||
|
||||
$schema_insert .= '<tr class="print-category">';
|
||||
$schema_insert .= '<th class="print">'
|
||||
$schemaInsert .= '<tr class="print-category">';
|
||||
$schemaInsert .= '<th class="print">'
|
||||
. __('Column')
|
||||
. '</th>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Type')
|
||||
. '</strong></td>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Null')
|
||||
. '</strong></td>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Default')
|
||||
. '</strong></td>';
|
||||
if ($do_relation && $have_rel) {
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
if ($doRelation && $haveRel) {
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Links to')
|
||||
. '</strong></td>';
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
if ($doComments) {
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Comments')
|
||||
. '</strong></td>';
|
||||
$comments = $this->relation->getComments($db, $table);
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$schemaInsert .= '<td class="print"><strong>'
|
||||
. __('Media type')
|
||||
. '</strong></td>';
|
||||
$mime_map = $this->transformations->getMime($db, $table, true);
|
||||
$mimeMap = $this->transformations->getMime($db, $table, true);
|
||||
}
|
||||
|
||||
$schema_insert .= '</tr>';
|
||||
$schemaInsert .= '</tr>';
|
||||
|
||||
$columns = $GLOBALS['dbi']->getColumns($db, $table);
|
||||
/**
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = [];
|
||||
$uniqueKeys = [];
|
||||
$keys = $GLOBALS['dbi']->getTableIndexes($db, $table);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
$uniqueKeys[] = $key['Column_name'];
|
||||
}
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$col_as = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$colAs = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$schema_insert .= $this->formatOneColumnDefinition($column, $unique_keys, $col_as);
|
||||
$field_name = $column['Field'];
|
||||
if ($do_relation && $have_rel) {
|
||||
$schema_insert .= '<td class="print">'
|
||||
$schemaInsert .= $this->formatOneColumnDefinition($column, $uniqueKeys, $colAs);
|
||||
$fieldName = $column['Field'];
|
||||
if ($doRelation && $haveRel) {
|
||||
$schemaInsert .= '<td class="print">'
|
||||
. htmlspecialchars(
|
||||
$this->getRelationString(
|
||||
$res_rel,
|
||||
$field_name,
|
||||
$resRel,
|
||||
$fieldName,
|
||||
$db,
|
||||
$aliases,
|
||||
),
|
||||
@ -430,28 +430,28 @@ class ExportHtmlword extends ExportPlugin
|
||||
. '</td>';
|
||||
}
|
||||
|
||||
if ($do_comments && $relationParameters->columnCommentsFeature !== null) {
|
||||
$schema_insert .= '<td class="print">'
|
||||
. (isset($comments[$field_name])
|
||||
? htmlspecialchars($comments[$field_name])
|
||||
if ($doComments && $relationParameters->columnCommentsFeature !== null) {
|
||||
$schemaInsert .= '<td class="print">'
|
||||
. (isset($comments[$fieldName])
|
||||
? htmlspecialchars($comments[$fieldName])
|
||||
: '') . '</td>';
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$schema_insert .= '<td class="print">'
|
||||
. (isset($mime_map[$field_name]) ?
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$schemaInsert .= '<td class="print">'
|
||||
. (isset($mimeMap[$fieldName]) ?
|
||||
htmlspecialchars(
|
||||
str_replace('_', '/', $mime_map[$field_name]['mimetype']),
|
||||
str_replace('_', '/', $mimeMap[$fieldName]['mimetype']),
|
||||
)
|
||||
: '') . '</td>';
|
||||
}
|
||||
|
||||
$schema_insert .= '</tr>';
|
||||
$schemaInsert .= '</tr>';
|
||||
}
|
||||
|
||||
$schema_insert .= '</table>';
|
||||
$schemaInsert .= '</table>';
|
||||
|
||||
return $schema_insert;
|
||||
return $schemaInsert;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -499,22 +499,22 @@ class ExportHtmlword extends ExportPlugin
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* PMA_exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*/
|
||||
public function exportStructure(
|
||||
string $db,
|
||||
@ -522,15 +522,15 @@ class ExportHtmlword extends ExportPlugin
|
||||
string $errorUrl,
|
||||
string $exportMode,
|
||||
string $exportType,
|
||||
bool $do_relation = false,
|
||||
bool $do_comments = false,
|
||||
bool $do_mime = false,
|
||||
bool $doRelation = false,
|
||||
bool $doComments = false,
|
||||
bool $doMime = false,
|
||||
bool $dates = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$dump = '';
|
||||
|
||||
@ -538,15 +538,15 @@ class ExportHtmlword extends ExportPlugin
|
||||
case 'create_table':
|
||||
$dump .= '<h2>'
|
||||
. __('Table structure for table') . ' '
|
||||
. htmlspecialchars($table_alias)
|
||||
. htmlspecialchars($tableAlias)
|
||||
. '</h2>';
|
||||
$dump .= $this->getTableDef($db, $table, $do_relation, $do_comments, $do_mime, false, $aliases);
|
||||
$dump .= $this->getTableDef($db, $table, $doRelation, $doComments, $doMime, false, $aliases);
|
||||
break;
|
||||
case 'triggers':
|
||||
$triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
|
||||
if ($triggers) {
|
||||
$dump .= '<h2>'
|
||||
. __('Triggers') . ' ' . htmlspecialchars($table_alias)
|
||||
. __('Triggers') . ' ' . htmlspecialchars($tableAlias)
|
||||
. '</h2>';
|
||||
$dump .= $this->getTriggers($db, $table);
|
||||
}
|
||||
@ -554,14 +554,14 @@ class ExportHtmlword extends ExportPlugin
|
||||
break;
|
||||
case 'create_view':
|
||||
$dump .= '<h2>'
|
||||
. __('Structure for view') . ' ' . htmlspecialchars($table_alias)
|
||||
. __('Structure for view') . ' ' . htmlspecialchars($tableAlias)
|
||||
. '</h2>';
|
||||
$dump .= $this->getTableDef($db, $table, $do_relation, $do_comments, $do_mime, true, $aliases);
|
||||
$dump .= $this->getTableDef($db, $table, $doRelation, $doComments, $doMime, true, $aliases);
|
||||
break;
|
||||
case 'stand_in':
|
||||
$dump .= '<h2>'
|
||||
. __('Stand-in structure for view') . ' '
|
||||
. htmlspecialchars($table_alias)
|
||||
. htmlspecialchars($tableAlias)
|
||||
. '</h2>';
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
$dump .= $this->getTableDefStandIn($db, $table, $aliases);
|
||||
@ -573,26 +573,26 @@ class ExportHtmlword extends ExportPlugin
|
||||
/**
|
||||
* Formats the definition for one column
|
||||
*
|
||||
* @param array $column info about this column
|
||||
* @param array $unique_keys unique keys of the table
|
||||
* @param string $col_alias Column Alias
|
||||
* @param array $column info about this column
|
||||
* @param array $uniqueKeys unique keys of the table
|
||||
* @param string $colAlias Column Alias
|
||||
*
|
||||
* @return string Formatted column definition
|
||||
*/
|
||||
protected function formatOneColumnDefinition(
|
||||
array $column,
|
||||
array $unique_keys,
|
||||
string $col_alias = '',
|
||||
array $uniqueKeys,
|
||||
string $colAlias = '',
|
||||
): string {
|
||||
if ($col_alias === '') {
|
||||
$col_alias = $column['Field'];
|
||||
if ($colAlias === '') {
|
||||
$colAlias = $column['Field'];
|
||||
}
|
||||
|
||||
$definition = '<tr class="print-category">';
|
||||
|
||||
$extracted_columnspec = Util::extractColumnSpec($column['Type']);
|
||||
$extractedColumnSpec = Util::extractColumnSpec($column['Type']);
|
||||
|
||||
$type = htmlspecialchars($extracted_columnspec['print_type']);
|
||||
$type = htmlspecialchars($extractedColumnSpec['print_type']);
|
||||
if ($type === '') {
|
||||
$type = ' ';
|
||||
}
|
||||
@ -603,20 +603,20 @@ class ExportHtmlword extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
$fmt_pre = '';
|
||||
$fmt_post = '';
|
||||
if (in_array($column['Field'], $unique_keys)) {
|
||||
$fmt_pre = '<strong>' . $fmt_pre;
|
||||
$fmt_post .= '</strong>';
|
||||
$fmtPre = '';
|
||||
$fmtPost = '';
|
||||
if (in_array($column['Field'], $uniqueKeys)) {
|
||||
$fmtPre = '<strong>' . $fmtPre;
|
||||
$fmtPost .= '</strong>';
|
||||
}
|
||||
|
||||
if ($column['Key'] === 'PRI') {
|
||||
$fmt_pre = '<em>' . $fmt_pre;
|
||||
$fmt_post .= '</em>';
|
||||
$fmtPre = '<em>' . $fmtPre;
|
||||
$fmtPost .= '</em>';
|
||||
}
|
||||
|
||||
$definition .= '<td class="print">' . $fmt_pre
|
||||
. htmlspecialchars($col_alias) . $fmt_post . '</td>';
|
||||
$definition .= '<td class="print">' . $fmtPre
|
||||
. htmlspecialchars($colAlias) . $fmtPost . '</td>';
|
||||
$definition .= '<td class="print">' . htmlspecialchars($type) . '</td>';
|
||||
$definition .= '<td class="print">'
|
||||
. ($column['Null'] == '' || $column['Null'] === 'NO'
|
||||
|
||||
@ -181,9 +181,9 @@ class ExportJson extends ExportPlugin
|
||||
string $sqlQuery,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
if (! $this->first) {
|
||||
if (! $this->export->outputHandler(',')) {
|
||||
@ -195,8 +195,8 @@ class ExportJson extends ExportPlugin
|
||||
|
||||
$buffer = $this->encode([
|
||||
'type' => 'table',
|
||||
'name' => $table_alias,
|
||||
'database' => $db_alias,
|
||||
'name' => $tableAlias,
|
||||
'database' => $dbAlias,
|
||||
'data' => '@@DATA@@',
|
||||
]);
|
||||
if ($buffer === false) {
|
||||
@ -234,28 +234,28 @@ class ExportJson extends ExportPlugin
|
||||
}
|
||||
|
||||
$result = $dbi->query($sqlQuery, Connection::TYPE_USER, DatabaseInterface::QUERY_UNBUFFERED);
|
||||
$columns_cnt = $result->numFields();
|
||||
$columnsCnt = $result->numFields();
|
||||
$fieldsMeta = $dbi->getFieldsMeta($result);
|
||||
|
||||
$columns = [];
|
||||
foreach ($fieldsMeta as $i => $field) {
|
||||
$col_as = $field->name;
|
||||
$colAs = $field->name;
|
||||
if (
|
||||
$db !== null && $table !== null && $aliases !== null
|
||||
&& ! empty($aliases[$db]['tables'][$table]['columns'][$col_as])
|
||||
&& ! empty($aliases[$db]['tables'][$table]['columns'][$colAs])
|
||||
) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$columns[$i] = $col_as;
|
||||
$columns[$i] = $colAs;
|
||||
}
|
||||
|
||||
$record_cnt = 0;
|
||||
$recordCnt = 0;
|
||||
while ($record = $result->fetchRow()) {
|
||||
$record_cnt++;
|
||||
$recordCnt++;
|
||||
|
||||
// Output table name as comment if this is the first record of the table
|
||||
if ($record_cnt > 1) {
|
||||
if ($recordCnt > 1) {
|
||||
if (! $this->export->outputHandler(',' . "\n")) {
|
||||
return false;
|
||||
}
|
||||
@ -263,7 +263,7 @@ class ExportJson extends ExportPlugin
|
||||
|
||||
$data = [];
|
||||
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
for ($i = 0; $i < $columnsCnt; $i++) {
|
||||
// 63 is the binary charset, see: https://dev.mysql.com/doc/internals/en/charsets.html
|
||||
$isBlobAndIsBinaryCharset = isset($fieldsMeta[$i])
|
||||
&& $fieldsMeta[$i]->isType(FieldMetadata::TYPE_BLOB)
|
||||
|
||||
@ -55,9 +55,9 @@ class ExportLatex extends ExportPlugin
|
||||
{
|
||||
$GLOBALS['plugin_param'] ??= null;
|
||||
|
||||
$hide_structure = false;
|
||||
$hideStructure = false;
|
||||
if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) {
|
||||
$hide_structure = true;
|
||||
$hideStructure = true;
|
||||
}
|
||||
|
||||
$exportPluginProperties = new ExportPluginProperties();
|
||||
@ -101,7 +101,7 @@ class ExportLatex extends ExportPlugin
|
||||
$exportSpecificOptions->addProperty($dumpWhat);
|
||||
|
||||
// structure options main group
|
||||
if (! $hide_structure) {
|
||||
if (! $hideStructure) {
|
||||
$structureOptions = new OptionsPropertyMainGroup(
|
||||
'structure',
|
||||
__('Object creation options'),
|
||||
@ -284,9 +284,9 @@ class ExportLatex extends ExportPlugin
|
||||
string $sqlQuery,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$result = $GLOBALS['dbi']->tryQuery(
|
||||
$sqlQuery,
|
||||
@ -294,22 +294,22 @@ class ExportLatex extends ExportPlugin
|
||||
DatabaseInterface::QUERY_UNBUFFERED,
|
||||
);
|
||||
|
||||
$columns_cnt = $result->numFields();
|
||||
$columnsCnt = $result->numFields();
|
||||
$columns = [];
|
||||
$columns_alias = [];
|
||||
foreach ($result->getFieldNames() as $i => $col_as) {
|
||||
$columns[$i] = $col_as;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$columnsAlias = [];
|
||||
foreach ($result->getFieldNames() as $i => $colAs) {
|
||||
$columns[$i] = $colAs;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$columns_alias[$i] = $col_as;
|
||||
$columnsAlias[$i] = $colAs;
|
||||
}
|
||||
|
||||
$buffer = "\n" . '%' . "\n" . '% ' . __('Data:') . ' ' . $table_alias
|
||||
$buffer = "\n" . '%' . "\n" . '% ' . __('Data:') . ' ' . $tableAlias
|
||||
. "\n" . '%' . "\n" . ' \\begin{longtable}{|';
|
||||
|
||||
$buffer .= str_repeat('l|', $columns_cnt);
|
||||
$buffer .= str_repeat('l|', $columnsCnt);
|
||||
|
||||
$buffer .= '} ' . "\n";
|
||||
|
||||
@ -319,15 +319,15 @@ class ExportLatex extends ExportPlugin
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_data_caption'],
|
||||
[static::class, 'texEscape'],
|
||||
['table' => $table_alias, 'database' => $db_alias],
|
||||
['table' => $tableAlias, 'database' => $dbAlias],
|
||||
)
|
||||
. '} \\label{'
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_data_label'],
|
||||
null,
|
||||
[
|
||||
'table' => $table_alias,
|
||||
'database' => $db_alias,
|
||||
'table' => $tableAlias,
|
||||
'database' => $dbAlias,
|
||||
],
|
||||
)
|
||||
. '} \\\\';
|
||||
@ -340,9 +340,9 @@ class ExportLatex extends ExportPlugin
|
||||
// show column names
|
||||
if (isset($GLOBALS['latex_columns'])) {
|
||||
$buffer = '\\hline ';
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
for ($i = 0; $i < $columnsCnt; $i++) {
|
||||
$buffer .= '\\multicolumn{1}{|c|}{\\textbf{'
|
||||
. self::texEscape($columns_alias[$i]) . '}} & ';
|
||||
. self::texEscape($columnsAlias[$i]) . '}} & ';
|
||||
}
|
||||
|
||||
$buffer = mb_substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
|
||||
@ -357,7 +357,7 @@ class ExportLatex extends ExportPlugin
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_data_continued_caption'],
|
||||
[static::class, 'texEscape'],
|
||||
['table' => $table_alias, 'database' => $db_alias],
|
||||
['table' => $tableAlias, 'database' => $dbAlias],
|
||||
)
|
||||
. '} \\\\ ',
|
||||
)
|
||||
@ -379,18 +379,18 @@ class ExportLatex extends ExportPlugin
|
||||
while ($record = $result->fetchAssoc()) {
|
||||
$buffer = '';
|
||||
// print each row
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
for ($i = 0; $i < $columnsCnt; $i++) {
|
||||
if ($record[$columns[$i]] !== null) {
|
||||
$column_value = self::texEscape($record[$columns[$i]]);
|
||||
$columnValue = self::texEscape($record[$columns[$i]]);
|
||||
} else {
|
||||
$column_value = $GLOBALS['latex_null'];
|
||||
$columnValue = $GLOBALS['latex_null'];
|
||||
}
|
||||
|
||||
// last column ... no need for & character
|
||||
if ($i == $columns_cnt - 1) {
|
||||
$buffer .= $column_value;
|
||||
if ($i == $columnsCnt - 1) {
|
||||
$buffer .= $columnValue;
|
||||
} else {
|
||||
$buffer .= $column_value . ' & ';
|
||||
$buffer .= $columnValue . ' & ';
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,22 +424,22 @@ class ExportLatex extends ExportPlugin
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*/
|
||||
public function exportStructure(
|
||||
string $db,
|
||||
@ -447,15 +447,15 @@ class ExportLatex extends ExportPlugin
|
||||
string $errorUrl,
|
||||
string $exportMode,
|
||||
string $exportType,
|
||||
bool $do_relation = false,
|
||||
bool $do_comments = false,
|
||||
bool $do_mime = false,
|
||||
bool $doRelation = false,
|
||||
bool $doComments = false,
|
||||
bool $doMime = false,
|
||||
bool $dates = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
|
||||
@ -467,14 +467,14 @@ class ExportLatex extends ExportPlugin
|
||||
/**
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = [];
|
||||
$uniqueKeys = [];
|
||||
$keys = $GLOBALS['dbi']->getTableIndexes($db, $table);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
$uniqueKeys[] = $key['Column_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,8 +483,8 @@ class ExportLatex extends ExportPlugin
|
||||
$GLOBALS['dbi']->selectDb($db);
|
||||
|
||||
// Check if we can use Relations
|
||||
[$res_rel, $have_rel] = $this->relation->getRelationsAndStatus(
|
||||
$do_relation && $relationParameters->relationFeature !== null,
|
||||
[$resRel, $haveRel] = $this->relation->getRelationsAndStatus(
|
||||
$doRelation && $relationParameters->relationFeature !== null,
|
||||
$db,
|
||||
$table,
|
||||
);
|
||||
@ -492,21 +492,21 @@ class ExportLatex extends ExportPlugin
|
||||
* Displays the table structure
|
||||
*/
|
||||
$buffer = "\n" . '%' . "\n" . '% ' . __('Structure:') . ' '
|
||||
. $table_alias . "\n" . '%' . "\n" . ' \\begin{longtable}{';
|
||||
. $tableAlias . "\n" . '%' . "\n" . ' \\begin{longtable}{';
|
||||
if (! $this->export->outputHandler($buffer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$alignment = '|l|c|c|c|';
|
||||
if ($do_relation && $have_rel) {
|
||||
if ($doRelation && $haveRel) {
|
||||
$alignment .= 'l|';
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
if ($doComments) {
|
||||
$alignment .= 'l|';
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$alignment .= 'l|';
|
||||
}
|
||||
|
||||
@ -517,18 +517,18 @@ class ExportLatex extends ExportPlugin
|
||||
. '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type')
|
||||
. '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null')
|
||||
. '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}';
|
||||
if ($do_relation && $have_rel) {
|
||||
if ($doRelation && $haveRel) {
|
||||
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}';
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
if ($doComments) {
|
||||
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}';
|
||||
$comments = $this->relation->getComments($db, $table);
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
|
||||
$mime_map = $this->transformations->getMime($db, $table, true);
|
||||
$mimeMap = $this->transformations->getMime($db, $table, true);
|
||||
}
|
||||
|
||||
// Table caption for first page and label
|
||||
@ -537,15 +537,15 @@ class ExportLatex extends ExportPlugin
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_structure_caption'],
|
||||
[static::class, 'texEscape'],
|
||||
['table' => $table_alias, 'database' => $db_alias],
|
||||
['table' => $tableAlias, 'database' => $dbAlias],
|
||||
)
|
||||
. '} \\label{'
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_structure_label'],
|
||||
null,
|
||||
[
|
||||
'table' => $table_alias,
|
||||
'database' => $db_alias,
|
||||
'table' => $tableAlias,
|
||||
'database' => $dbAlias,
|
||||
],
|
||||
)
|
||||
. '} \\\\' . "\n";
|
||||
@ -559,7 +559,7 @@ class ExportLatex extends ExportPlugin
|
||||
. Util::expandUserString(
|
||||
$GLOBALS['latex_structure_continued_caption'],
|
||||
[static::class, 'texEscape'],
|
||||
['table' => $table_alias, 'database' => $db_alias],
|
||||
['table' => $tableAlias, 'database' => $dbAlias],
|
||||
)
|
||||
. '} \\\\ ' . "\n";
|
||||
}
|
||||
@ -572,8 +572,8 @@ class ExportLatex extends ExportPlugin
|
||||
|
||||
$fields = $GLOBALS['dbi']->getColumns($db, $table);
|
||||
foreach ($fields as $row) {
|
||||
$extracted_columnspec = Util::extractColumnSpec($row['Type']);
|
||||
$type = $extracted_columnspec['print_type'];
|
||||
$extractedColumnSpec = Util::extractColumnSpec($row['Type']);
|
||||
$type = $extractedColumnSpec['print_type'];
|
||||
if (empty($type)) {
|
||||
$type = ' ';
|
||||
}
|
||||
@ -584,47 +584,47 @@ class ExportLatex extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
$field_name = $col_as = $row['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$fieldName = $colAs = $row['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$local_buffer = $col_as . "\000" . $type . "\000"
|
||||
$localBuffer = $colAs . "\000" . $type . "\000"
|
||||
. ($row['Null'] == '' || $row['Null'] === 'NO'
|
||||
? __('No') : __('Yes'))
|
||||
. "\000" . ($row['Default'] ?? '');
|
||||
|
||||
if ($do_relation && $have_rel) {
|
||||
$local_buffer .= "\000";
|
||||
$local_buffer .= $this->getRelationString($res_rel, $field_name, $db, $aliases);
|
||||
if ($doRelation && $haveRel) {
|
||||
$localBuffer .= "\000";
|
||||
$localBuffer .= $this->getRelationString($resRel, $fieldName, $db, $aliases);
|
||||
}
|
||||
|
||||
if ($do_comments && $relationParameters->columnCommentsFeature !== null) {
|
||||
$local_buffer .= "\000";
|
||||
if (isset($comments[$field_name])) {
|
||||
$local_buffer .= $comments[$field_name];
|
||||
if ($doComments && $relationParameters->columnCommentsFeature !== null) {
|
||||
$localBuffer .= "\000";
|
||||
if (isset($comments[$fieldName])) {
|
||||
$localBuffer .= $comments[$fieldName];
|
||||
}
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$local_buffer .= "\000";
|
||||
if (isset($mime_map[$field_name])) {
|
||||
$local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$localBuffer .= "\000";
|
||||
if (isset($mimeMap[$fieldName])) {
|
||||
$localBuffer .= str_replace('_', '/', $mimeMap[$fieldName]['mimetype']);
|
||||
}
|
||||
}
|
||||
|
||||
$local_buffer = self::texEscape($local_buffer);
|
||||
$localBuffer = self::texEscape($localBuffer);
|
||||
if ($row['Key'] === 'PRI') {
|
||||
$pos = (int) mb_strpos($local_buffer, "\000");
|
||||
$local_buffer = '\\textit{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos);
|
||||
$pos = (int) mb_strpos($localBuffer, "\000");
|
||||
$localBuffer = '\\textit{' . mb_substr($localBuffer, 0, $pos) . '}' . mb_substr($localBuffer, $pos);
|
||||
}
|
||||
|
||||
if (in_array($field_name, $unique_keys)) {
|
||||
$pos = (int) mb_strpos($local_buffer, "\000");
|
||||
$local_buffer = '\\textbf{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos);
|
||||
if (in_array($fieldName, $uniqueKeys)) {
|
||||
$pos = (int) mb_strpos($localBuffer, "\000");
|
||||
$localBuffer = '\\textbf{' . mb_substr($localBuffer, 0, $pos) . '}' . mb_substr($localBuffer, $pos);
|
||||
}
|
||||
|
||||
$buffer = str_replace("\000", ' & ', $local_buffer);
|
||||
$buffer = str_replace("\000", ' & ', $localBuffer);
|
||||
$buffer .= ' \\\\ \\hline ' . "\n";
|
||||
|
||||
if (! $this->export->outputHandler($buffer)) {
|
||||
@ -656,8 +656,8 @@ class ExportLatex extends ExportPlugin
|
||||
'_',
|
||||
'^',
|
||||
];
|
||||
$cnt_escape = count($escape);
|
||||
for ($k = 0; $k < $cnt_escape; $k++) {
|
||||
$cntEscape = count($escape);
|
||||
for ($k = 0; $k < $cntEscape; $k++) {
|
||||
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
|
||||
}
|
||||
|
||||
|
||||
@ -144,22 +144,22 @@ class ExportMediawiki extends ExportPlugin
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure; this is
|
||||
* deprecated but the parameter is left here
|
||||
* because /export calls exportStructure()
|
||||
* also for other export types which use this
|
||||
* parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*/
|
||||
public function exportStructure(
|
||||
string $db,
|
||||
@ -167,26 +167,26 @@ class ExportMediawiki extends ExportPlugin
|
||||
string $errorUrl,
|
||||
string $exportMode,
|
||||
string $exportType,
|
||||
bool $do_relation = false,
|
||||
bool $do_comments = false,
|
||||
bool $do_mime = false,
|
||||
bool $doRelation = false,
|
||||
bool $doComments = false,
|
||||
bool $doMime = false,
|
||||
bool $dates = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$output = '';
|
||||
if ($exportMode === 'create_table') {
|
||||
$columns = $GLOBALS['dbi']->getColumns($db, $table);
|
||||
$columns = array_values($columns);
|
||||
$row_cnt = count($columns);
|
||||
$rowCnt = count($columns);
|
||||
|
||||
// Print structure comment
|
||||
$output = $this->exportComment(
|
||||
'Table structure for '
|
||||
. Util::backquote($table_alias),
|
||||
. Util::backquote($tableAlias),
|
||||
);
|
||||
|
||||
// Begin the table construction
|
||||
@ -195,7 +195,7 @@ class ExportMediawiki extends ExportPlugin
|
||||
|
||||
// Add the table name
|
||||
if (isset($GLOBALS['mediawiki_caption'])) {
|
||||
$output .= "|+'''" . $table_alias . "'''" . $this->exportCRLF();
|
||||
$output .= "|+'''" . $tableAlias . "'''" . $this->exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
@ -203,38 +203,38 @@ class ExportMediawiki extends ExportPlugin
|
||||
$output .= '|- style="background:#ffdead;"' . $this->exportCRLF();
|
||||
$output .= '! style="background:#ffffff" | '
|
||||
. $this->exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$col_as = $columns[$i]['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
for ($i = 0; $i < $rowCnt; ++$i) {
|
||||
$colAs = $columns[$i]['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$output .= ' | ' . $col_as . $this->exportCRLF();
|
||||
$output .= ' | ' . $colAs . $this->exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the table structure
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
$output .= '! Type' . $this->exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
for ($i = 0; $i < $rowCnt; ++$i) {
|
||||
$output .= ' | ' . $columns[$i]['Type'] . $this->exportCRLF();
|
||||
}
|
||||
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
$output .= '! Null' . $this->exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
for ($i = 0; $i < $rowCnt; ++$i) {
|
||||
$output .= ' | ' . $columns[$i]['Null'] . $this->exportCRLF();
|
||||
}
|
||||
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
$output .= '! Default' . $this->exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
for ($i = 0; $i < $rowCnt; ++$i) {
|
||||
$output .= ' | ' . $columns[$i]['Default'] . $this->exportCRLF();
|
||||
}
|
||||
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
$output .= '! Extra' . $this->exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
for ($i = 0; $i < $rowCnt; ++$i) {
|
||||
$output .= ' | ' . $columns[$i]['Extra'] . $this->exportCRLF();
|
||||
}
|
||||
|
||||
@ -260,14 +260,14 @@ class ExportMediawiki extends ExportPlugin
|
||||
string $sqlQuery,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
// Print data comment
|
||||
$output = $this->exportComment(
|
||||
$table_alias != ''
|
||||
? 'Table data for ' . Util::backquote($table_alias)
|
||||
$tableAlias != ''
|
||||
? 'Table data for ' . Util::backquote($tableAlias)
|
||||
: 'Query results',
|
||||
);
|
||||
|
||||
@ -279,21 +279,21 @@ class ExportMediawiki extends ExportPlugin
|
||||
|
||||
// Add the table name
|
||||
if (isset($GLOBALS['mediawiki_caption'])) {
|
||||
$output .= "|+'''" . $table_alias . "'''" . $this->exportCRLF();
|
||||
$output .= "|+'''" . $tableAlias . "'''" . $this->exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if (isset($GLOBALS['mediawiki_headers'])) {
|
||||
// Get column names
|
||||
$column_names = $GLOBALS['dbi']->getColumnNames($db, $table);
|
||||
$columnNames = $GLOBALS['dbi']->getColumnNames($db, $table);
|
||||
|
||||
// Add column names as table headers
|
||||
if ($column_names !== []) {
|
||||
if ($columnNames !== []) {
|
||||
// Use '|-' for separating rows
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
|
||||
// Use '!' for separating table headers
|
||||
foreach ($column_names as $column) {
|
||||
foreach ($columnNames as $column) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$column])) {
|
||||
$column = $aliases[$db]['tables'][$table]['columns'][$column];
|
||||
}
|
||||
@ -309,13 +309,13 @@ class ExportMediawiki extends ExportPlugin
|
||||
Connection::TYPE_USER,
|
||||
DatabaseInterface::QUERY_UNBUFFERED,
|
||||
);
|
||||
$fields_cnt = $result->numFields();
|
||||
$fieldsCnt = $result->numFields();
|
||||
|
||||
while ($row = $result->fetchRow()) {
|
||||
$output .= '|-' . $this->exportCRLF();
|
||||
|
||||
// Use '|' for separating table columns
|
||||
for ($i = 0; $i < $fields_cnt; ++$i) {
|
||||
for ($i = 0; $i < $fieldsCnt; ++$i) {
|
||||
$output .= ' | ' . $row[$i] . $this->exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,33 +199,33 @@ class ExportOds extends ExportPlugin
|
||||
): bool {
|
||||
$GLOBALS['what'] ??= null;
|
||||
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
// Gets the data from the database
|
||||
$result = $GLOBALS['dbi']->query(
|
||||
$sqlQuery,
|
||||
Connection::TYPE_USER,
|
||||
DatabaseInterface::QUERY_UNBUFFERED,
|
||||
);
|
||||
$fields_cnt = $result->numFields();
|
||||
$fieldsCnt = $result->numFields();
|
||||
/** @var FieldMetadata[] $fieldsMeta */
|
||||
$fieldsMeta = $GLOBALS['dbi']->getFieldsMeta($result);
|
||||
|
||||
$GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table_alias) . '">';
|
||||
$GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($tableAlias) . '">';
|
||||
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS[$GLOBALS['what'] . '_columns'])) {
|
||||
$GLOBALS['ods_buffer'] .= '<table:table-row>';
|
||||
foreach ($fieldsMeta as $field) {
|
||||
$col_as = $field->name;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$colAs = $field->name;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>'
|
||||
. htmlspecialchars($col_as)
|
||||
. htmlspecialchars($colAs)
|
||||
. '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
}
|
||||
@ -236,7 +236,7 @@ class ExportOds extends ExportPlugin
|
||||
// Format the data
|
||||
while ($row = $result->fetchRow()) {
|
||||
$GLOBALS['ods_buffer'] .= '<table:table-row>';
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
for ($j = 0; $j < $fieldsCnt; $j++) {
|
||||
if ($fieldsMeta[$j]->isMappedTypeGeometry) {
|
||||
// export GIS types as hex
|
||||
$row[$j] = '0x' . bin2hex($row[$j]);
|
||||
|
||||
@ -46,9 +46,9 @@ class ExportOdt extends ExportPlugin
|
||||
{
|
||||
$GLOBALS['plugin_param'] ??= null;
|
||||
|
||||
$hide_structure = false;
|
||||
$hideStructure = false;
|
||||
if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) {
|
||||
$hide_structure = true;
|
||||
$hideStructure = true;
|
||||
}
|
||||
|
||||
$exportPluginProperties = new ExportPluginProperties();
|
||||
@ -82,7 +82,7 @@ class ExportOdt extends ExportPlugin
|
||||
$exportSpecificOptions->addProperty($dumpWhat);
|
||||
|
||||
// structure options main group
|
||||
if (! $hide_structure) {
|
||||
if (! $hideStructure) {
|
||||
$structureOptions = new OptionsPropertyMainGroup(
|
||||
'structure',
|
||||
__('Object creation options'),
|
||||
@ -228,42 +228,42 @@ class ExportOdt extends ExportPlugin
|
||||
): bool {
|
||||
$GLOBALS['what'] ??= null;
|
||||
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
// Gets the data from the database
|
||||
$result = $GLOBALS['dbi']->query(
|
||||
$sqlQuery,
|
||||
Connection::TYPE_USER,
|
||||
DatabaseInterface::QUERY_UNBUFFERED,
|
||||
);
|
||||
$fields_cnt = $result->numFields();
|
||||
$fieldsCnt = $result->numFields();
|
||||
/** @var FieldMetadata[] $fieldsMeta */
|
||||
$fieldsMeta = $GLOBALS['dbi']->getFieldsMeta($result);
|
||||
|
||||
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">';
|
||||
$table_alias != ''
|
||||
? $GLOBALS['odt_buffer'] .= __('Dumping data for table') . ' ' . htmlspecialchars($table_alias)
|
||||
$tableAlias != ''
|
||||
? $GLOBALS['odt_buffer'] .= __('Dumping data for table') . ' ' . htmlspecialchars($tableAlias)
|
||||
: $GLOBALS['odt_buffer'] .= __('Dumping data for query result');
|
||||
$GLOBALS['odt_buffer'] .= '</text:h>'
|
||||
. '<table:table'
|
||||
. ' table:name="' . htmlspecialchars($table_alias) . '_structure">'
|
||||
. ' table:name="' . htmlspecialchars($tableAlias) . '_structure">'
|
||||
. '<table:table-column'
|
||||
. ' table:number-columns-repeated="' . $fields_cnt . '"/>';
|
||||
. ' table:number-columns-repeated="' . $fieldsCnt . '"/>';
|
||||
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS[$GLOBALS['what'] . '_columns'])) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-row>';
|
||||
foreach ($fieldsMeta as $field) {
|
||||
$col_as = $field->name;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$colAs = $field->name;
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>'
|
||||
. htmlspecialchars($col_as)
|
||||
. htmlspecialchars($colAs)
|
||||
. '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
}
|
||||
@ -274,7 +274,7 @@ class ExportOdt extends ExportPlugin
|
||||
// Format the data
|
||||
while ($row = $result->fetchRow()) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-row>';
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
for ($j = 0; $j < $fieldsCnt; $j++) {
|
||||
if ($fieldsMeta[$j]->isMappedTypeGeometry) {
|
||||
// export GIS types as hex
|
||||
$row[$j] = '0x' . bin2hex($row[$j]);
|
||||
@ -344,9 +344,9 @@ class ExportOdt extends ExportPlugin
|
||||
*/
|
||||
public function getTableDefStandIn(string $db, string $view, array $aliases = []): string
|
||||
{
|
||||
$db_alias = $db;
|
||||
$view_alias = $view;
|
||||
$this->initAlias($aliases, $db_alias, $view_alias);
|
||||
$dbAlias = $db;
|
||||
$viewAlias = $view;
|
||||
$this->initAlias($aliases, $dbAlias, $viewAlias);
|
||||
/**
|
||||
* Gets fields properties
|
||||
*/
|
||||
@ -356,10 +356,10 @@ class ExportOdt extends ExportPlugin
|
||||
* Displays the table structure
|
||||
*/
|
||||
$GLOBALS['odt_buffer'] .= '<table:table table:name="'
|
||||
. htmlspecialchars($view_alias) . '_data">';
|
||||
$columns_cnt = 4;
|
||||
. htmlspecialchars($viewAlias) . '_data">';
|
||||
$columnsCnt = 4;
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-column'
|
||||
. ' table:number-columns-repeated="' . $columns_cnt . '"/>';
|
||||
. ' table:number-columns-repeated="' . $columnsCnt . '"/>';
|
||||
/* Header */
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-row>'
|
||||
. '<table:table-cell office:value-type="string">'
|
||||
@ -378,12 +378,12 @@ class ExportOdt extends ExportPlugin
|
||||
|
||||
$columns = $GLOBALS['dbi']->getColumns($db, $view);
|
||||
foreach ($columns as $column) {
|
||||
$col_as = $column['Field'] ?? null;
|
||||
if (! empty($aliases[$db]['tables'][$view]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$view]['columns'][$col_as];
|
||||
$colAs = $column['Field'] ?? null;
|
||||
if (! empty($aliases[$db]['tables'][$view]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$view]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column, $col_as);
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column, $colAs);
|
||||
$GLOBALS['odt_buffer'] .= '</table:table-row>';
|
||||
}
|
||||
|
||||
@ -395,37 +395,37 @@ class ExportOdt extends ExportPlugin
|
||||
/**
|
||||
* Returns $table's CREATE definition
|
||||
*
|
||||
* @param string $db the database name
|
||||
* @param string $table the table name
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db the database name
|
||||
* @param string $table the table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* PMA_exportStructure() also for other
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $show_dates whether to include creation/update/check dates
|
||||
* @param bool $add_semicolon whether to add semicolon and end-of-line at
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $showDates whether to include creation/update/check dates
|
||||
* @param bool $addSemicolon whether to add semicolon and end-of-line at
|
||||
* the end
|
||||
* @param bool $view whether we're handling a view
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $view whether we're handling a view
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*/
|
||||
public function getTableDef(
|
||||
string $db,
|
||||
string $table,
|
||||
string $error_url,
|
||||
bool $do_relation,
|
||||
bool $do_comments,
|
||||
bool $do_mime,
|
||||
bool $show_dates = false,
|
||||
bool $add_semicolon = true,
|
||||
string $errorUrl,
|
||||
bool $doRelation,
|
||||
bool $doComments,
|
||||
bool $doMime,
|
||||
bool $showDates = false,
|
||||
bool $addSemicolon = true,
|
||||
bool $view = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
|
||||
@ -435,8 +435,8 @@ class ExportOdt extends ExportPlugin
|
||||
$GLOBALS['dbi']->selectDb($db);
|
||||
|
||||
// Check if we can use Relations
|
||||
[$res_rel, $have_rel] = $this->relation->getRelationsAndStatus(
|
||||
$do_relation && $relationParameters->relationFeature !== null,
|
||||
[$resRel, $haveRel] = $this->relation->getRelationsAndStatus(
|
||||
$doRelation && $relationParameters->relationFeature !== null,
|
||||
$db,
|
||||
$table,
|
||||
);
|
||||
@ -444,22 +444,22 @@ class ExportOdt extends ExportPlugin
|
||||
* Displays the table structure
|
||||
*/
|
||||
$GLOBALS['odt_buffer'] .= '<table:table table:name="'
|
||||
. htmlspecialchars($table_alias) . '_structure">';
|
||||
$columns_cnt = 4;
|
||||
if ($do_relation && $have_rel) {
|
||||
$columns_cnt++;
|
||||
. htmlspecialchars($tableAlias) . '_structure">';
|
||||
$columnsCnt = 4;
|
||||
if ($doRelation && $haveRel) {
|
||||
$columnsCnt++;
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
$columns_cnt++;
|
||||
if ($doComments) {
|
||||
$columnsCnt++;
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$columns_cnt++;
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$columnsCnt++;
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-column'
|
||||
. ' table:number-columns-repeated="' . $columns_cnt . '"/>';
|
||||
. ' table:number-columns-repeated="' . $columnsCnt . '"/>';
|
||||
/* Header */
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-row>'
|
||||
. '<table:table-cell office:value-type="string">'
|
||||
@ -474,38 +474,38 @@ class ExportOdt extends ExportPlugin
|
||||
. '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>' . __('Default') . '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
if ($do_relation && $have_rel) {
|
||||
if ($doRelation && $haveRel) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>' . __('Links to') . '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
if ($doComments) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>' . __('Comments') . '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
$comments = $this->relation->getComments($db, $table);
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>' . __('Media type') . '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
$mime_map = $this->transformations->getMime($db, $table, true);
|
||||
$mimeMap = $this->transformations->getMime($db, $table, true);
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] .= '</table:table-row>';
|
||||
|
||||
$columns = $GLOBALS['dbi']->getColumns($db, $table);
|
||||
foreach ($columns as $column) {
|
||||
$col_as = $field_name = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
$colAs = $fieldName = $column['Field'];
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column, $col_as);
|
||||
if ($do_relation && $have_rel) {
|
||||
$foreigner = $this->relation->searchColumnInForeigners($res_rel, $field_name);
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column, $colAs);
|
||||
if ($doRelation && $haveRel) {
|
||||
$foreigner = $this->relation->searchColumnInForeigners($resRel, $fieldName);
|
||||
if ($foreigner) {
|
||||
$rtable = $foreigner['foreign_table'];
|
||||
$rfield = $foreigner['foreign_field'];
|
||||
@ -526,11 +526,11 @@ class ExportOdt extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
if ($do_comments) {
|
||||
if (isset($comments[$field_name])) {
|
||||
if ($doComments) {
|
||||
if (isset($comments[$fieldName])) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>'
|
||||
. htmlspecialchars($comments[$field_name])
|
||||
. htmlspecialchars($comments[$fieldName])
|
||||
. '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
} else {
|
||||
@ -540,12 +540,12 @@ class ExportOdt extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
if ($do_mime && $relationParameters->browserTransformationFeature !== null) {
|
||||
if (isset($mime_map[$field_name])) {
|
||||
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
|
||||
if (isset($mimeMap[$fieldName])) {
|
||||
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>'
|
||||
. htmlspecialchars(
|
||||
str_replace('_', '/', $mime_map[$field_name]['mimetype']),
|
||||
str_replace('_', '/', $mimeMap[$fieldName]['mimetype']),
|
||||
)
|
||||
. '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
@ -573,11 +573,11 @@ class ExportOdt extends ExportPlugin
|
||||
*/
|
||||
protected function getTriggers(string $db, string $table, array $aliases = []): string
|
||||
{
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
$GLOBALS['odt_buffer'] .= '<table:table'
|
||||
. ' table:name="' . htmlspecialchars($table_alias) . '_triggers">'
|
||||
. ' table:name="' . htmlspecialchars($tableAlias) . '_triggers">'
|
||||
. '<table:table-column'
|
||||
. ' table:number-columns-repeated="4"/>'
|
||||
. '<table:table-row>'
|
||||
@ -630,21 +630,21 @@ class ExportOdt extends ExportPlugin
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* PMA_exportStructure() also for other
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases Aliases of db/table/columns
|
||||
*/
|
||||
public function exportStructure(
|
||||
string $db,
|
||||
@ -652,29 +652,29 @@ class ExportOdt extends ExportPlugin
|
||||
string $errorUrl,
|
||||
string $exportMode,
|
||||
string $exportType,
|
||||
bool $do_relation = false,
|
||||
bool $do_comments = false,
|
||||
bool $do_mime = false,
|
||||
bool $doRelation = false,
|
||||
bool $doComments = false,
|
||||
bool $doMime = false,
|
||||
bool $dates = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
switch ($exportMode) {
|
||||
case 'create_table':
|
||||
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">'
|
||||
. __('Table structure for table') . ' ' .
|
||||
htmlspecialchars($table_alias)
|
||||
htmlspecialchars($tableAlias)
|
||||
. '</text:h>';
|
||||
$this->getTableDef(
|
||||
$db,
|
||||
$table,
|
||||
$errorUrl,
|
||||
$do_relation,
|
||||
$do_comments,
|
||||
$do_mime,
|
||||
$doRelation,
|
||||
$doComments,
|
||||
$doMime,
|
||||
$dates,
|
||||
true,
|
||||
false,
|
||||
@ -687,7 +687,7 @@ class ExportOdt extends ExportPlugin
|
||||
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">'
|
||||
. __('Triggers') . ' '
|
||||
. htmlspecialchars($table_alias)
|
||||
. htmlspecialchars($tableAlias)
|
||||
. '</text:h>';
|
||||
$this->getTriggers($db, $table);
|
||||
}
|
||||
@ -697,15 +697,15 @@ class ExportOdt extends ExportPlugin
|
||||
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">'
|
||||
. __('Structure for view') . ' '
|
||||
. htmlspecialchars($table_alias)
|
||||
. htmlspecialchars($tableAlias)
|
||||
. '</text:h>';
|
||||
$this->getTableDef(
|
||||
$db,
|
||||
$table,
|
||||
$errorUrl,
|
||||
$do_relation,
|
||||
$do_comments,
|
||||
$do_mime,
|
||||
$doRelation,
|
||||
$doComments,
|
||||
$doMime,
|
||||
$dates,
|
||||
true,
|
||||
true,
|
||||
@ -716,7 +716,7 @@ class ExportOdt extends ExportPlugin
|
||||
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">'
|
||||
. __('Stand-in structure for view') . ' '
|
||||
. htmlspecialchars($table_alias)
|
||||
. htmlspecialchars($tableAlias)
|
||||
. '</text:h>';
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
$this->getTableDefStandIn($db, $table, $aliases);
|
||||
@ -729,23 +729,23 @@ class ExportOdt extends ExportPlugin
|
||||
* Formats the definition for one column
|
||||
*
|
||||
* @param array $column info about this column
|
||||
* @param string $col_as column alias
|
||||
* @param string $colAs column alias
|
||||
*
|
||||
* @return string Formatted column definition
|
||||
*/
|
||||
protected function formatOneColumnDefinition(array $column, string $col_as = ''): string
|
||||
protected function formatOneColumnDefinition(array $column, string $colAs = ''): string
|
||||
{
|
||||
if (empty($col_as)) {
|
||||
$col_as = $column['Field'];
|
||||
if (empty($colAs)) {
|
||||
$colAs = $column['Field'];
|
||||
}
|
||||
|
||||
$definition = '<table:table-row>';
|
||||
$definition .= '<table:table-cell office:value-type="string">'
|
||||
. '<text:p>' . htmlspecialchars($col_as) . '</text:p>'
|
||||
. '<text:p>' . htmlspecialchars($colAs) . '</text:p>'
|
||||
. '</table:table-cell>';
|
||||
|
||||
$extracted_columnspec = Util::extractColumnSpec($column['Type']);
|
||||
$type = htmlspecialchars($extracted_columnspec['print_type']);
|
||||
$extractedColumnSpec = Util::extractColumnSpec($column['Type']);
|
||||
$type = htmlspecialchars($extractedColumnSpec['print_type']);
|
||||
if (empty($type)) {
|
||||
$type = ' ';
|
||||
}
|
||||
|
||||
@ -172,14 +172,14 @@ class ExportPdf extends ExportPlugin
|
||||
string $sqlQuery,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
$pdf = $this->getPdf();
|
||||
$pdf->setCurrentDb($db);
|
||||
$pdf->setCurrentTable($table);
|
||||
$pdf->setDbAlias($db_alias);
|
||||
$pdf->setTableAlias($table_alias);
|
||||
$pdf->setDbAlias($dbAlias);
|
||||
$pdf->setTableAlias($tableAlias);
|
||||
$pdf->setAliases($aliases);
|
||||
$pdf->setPurpose(__('Dumping data'));
|
||||
$pdf->mysqlReport($sqlQuery);
|
||||
@ -214,22 +214,22 @@ class ExportPdf extends ExportPlugin
|
||||
/**
|
||||
* Outputs table structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $errorUrl the url to go back in case of error
|
||||
* @param string $exportMode 'create_table', 'triggers', 'create_view',
|
||||
* 'stand_in'
|
||||
* @param string $exportType 'server', 'database', 'table'
|
||||
* @param bool $doRelation whether to include relation comments
|
||||
* @param bool $doComments whether to include the pmadb-style column
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because /export calls
|
||||
* PMA_exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases aliases for db/table/columns
|
||||
* @param bool $doMime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
* @param array $aliases aliases for db/table/columns
|
||||
*/
|
||||
public function exportStructure(
|
||||
string $db,
|
||||
@ -237,16 +237,16 @@ class ExportPdf extends ExportPlugin
|
||||
string $errorUrl,
|
||||
string $exportMode,
|
||||
string $exportType,
|
||||
bool $do_relation = false,
|
||||
bool $do_comments = false,
|
||||
bool $do_mime = false,
|
||||
bool $doRelation = false,
|
||||
bool $doComments = false,
|
||||
bool $doMime = false,
|
||||
bool $dates = false,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$purpose = '';
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
$pdf = $this->getPdf();
|
||||
// getting purpose to show at top
|
||||
switch ($exportMode) {
|
||||
@ -265,8 +265,8 @@ class ExportPdf extends ExportPlugin
|
||||
|
||||
$pdf->setCurrentDb($db);
|
||||
$pdf->setCurrentTable($table);
|
||||
$pdf->setDbAlias($db_alias);
|
||||
$pdf->setTableAlias($table_alias);
|
||||
$pdf->setDbAlias($dbAlias);
|
||||
$pdf->setTableAlias($tableAlias);
|
||||
$pdf->setAliases($aliases);
|
||||
$pdf->setPurpose($purpose);
|
||||
|
||||
@ -276,13 +276,13 @@ class ExportPdf extends ExportPlugin
|
||||
*/
|
||||
switch ($exportMode) {
|
||||
case 'create_table':
|
||||
$pdf->getTableDef($db, $table, $do_relation, true, $do_mime, false, $aliases);
|
||||
$pdf->getTableDef($db, $table, $doRelation, true, $doMime, false, $aliases);
|
||||
break;
|
||||
case 'triggers':
|
||||
$pdf->getTriggers($db, $table);
|
||||
break;
|
||||
case 'create_view':
|
||||
$pdf->getTableDef($db, $table, $do_relation, true, $do_mime, false, $aliases);
|
||||
$pdf->getTableDef($db, $table, $doRelation, true, $doMime, false, $aliases);
|
||||
break;
|
||||
case 'stand_in':
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
|
||||
@ -154,9 +154,9 @@ class ExportPhparray extends ExportPlugin
|
||||
string $sqlQuery,
|
||||
array $aliases = [],
|
||||
): bool {
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
$this->initAlias($aliases, $db_alias, $table_alias);
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
$this->initAlias($aliases, $dbAlias, $tableAlias);
|
||||
|
||||
$result = $GLOBALS['dbi']->query(
|
||||
$sqlQuery,
|
||||
@ -164,38 +164,38 @@ class ExportPhparray extends ExportPlugin
|
||||
DatabaseInterface::QUERY_UNBUFFERED,
|
||||
);
|
||||
|
||||
$columns_cnt = $result->numFields();
|
||||
$columnsCnt = $result->numFields();
|
||||
$columns = [];
|
||||
foreach ($result->getFieldNames() as $i => $col_as) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
$col_as = $aliases[$db]['tables'][$table]['columns'][$col_as];
|
||||
foreach ($result->getFieldNames() as $i => $colAs) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$colAs])) {
|
||||
$colAs = $aliases[$db]['tables'][$table]['columns'][$colAs];
|
||||
}
|
||||
|
||||
$columns[$i] = $col_as;
|
||||
$columns[$i] = $colAs;
|
||||
}
|
||||
|
||||
$tablefixed = $table;
|
||||
$tableFixed = $table;
|
||||
|
||||
// fix variable names (based on
|
||||
// https://www.php.net/manual/en/language.variables.basics.php)
|
||||
if (! preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $table_alias)) {
|
||||
if (! preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $tableAlias)) {
|
||||
// fix invalid characters in variable names by replacing them with
|
||||
// underscores
|
||||
$tablefixed = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $table_alias);
|
||||
$tableFixed = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $tableAlias);
|
||||
|
||||
// variable name must not start with a number or dash...
|
||||
if (preg_match('/^[a-zA-Z_\x7f-\xff]/', $tablefixed) === 0) {
|
||||
$tablefixed = '_' . $tablefixed;
|
||||
if (preg_match('/^[a-zA-Z_\x7f-\xff]/', $tableFixed) === 0) {
|
||||
$tableFixed = '_' . $tableFixed;
|
||||
}
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
$record_cnt = 0;
|
||||
$recordCnt = 0;
|
||||
// Output table name as comment
|
||||
$buffer .= "\n" . '/* '
|
||||
. $this->commentString(Util::backquote($db_alias)) . '.'
|
||||
. $this->commentString(Util::backquote($table_alias)) . ' */' . "\n";
|
||||
$buffer .= '$' . $tablefixed . ' = array(';
|
||||
. $this->commentString(Util::backquote($dbAlias)) . '.'
|
||||
. $this->commentString(Util::backquote($tableAlias)) . ' */' . "\n";
|
||||
$buffer .= '$' . $tableFixed . ' = array(';
|
||||
if (! $this->export->outputHandler($buffer)) {
|
||||
return false;
|
||||
}
|
||||
@ -203,18 +203,18 @@ class ExportPhparray extends ExportPlugin
|
||||
// Reset the buffer
|
||||
$buffer = '';
|
||||
while ($record = $result->fetchRow()) {
|
||||
$record_cnt++;
|
||||
$recordCnt++;
|
||||
|
||||
if ($record_cnt == 1) {
|
||||
if ($recordCnt == 1) {
|
||||
$buffer .= "\n" . ' array(';
|
||||
} else {
|
||||
$buffer .= ',' . "\n" . ' array(';
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
for ($i = 0; $i < $columnsCnt; $i++) {
|
||||
$buffer .= var_export($columns[$i], true)
|
||||
. ' => ' . var_export($record[$i], true)
|
||||
. ($i + 1 >= $columns_cnt ? '' : ',');
|
||||
. ($i + 1 >= $columnsCnt ? '' : ',');
|
||||
}
|
||||
|
||||
$buffer .= ')';
|
||||
|
||||
@ -2172,7 +2172,7 @@ class ExportSql extends ExportPlugin
|
||||
}
|
||||
|
||||
//\x08\\x09, not required
|
||||
$current_row = 0;
|
||||
$currentRow = 0;
|
||||
$querySize = 0;
|
||||
if (
|
||||
($GLOBALS['sql_insert_syntax'] === 'extended'
|
||||
@ -2187,7 +2187,7 @@ class ExportSql extends ExportPlugin
|
||||
}
|
||||
|
||||
while ($row = $result->fetchRow()) {
|
||||
if ($current_row === 0) {
|
||||
if ($currentRow === 0) {
|
||||
$head = $this->possibleCRLF()
|
||||
. $this->exportComment()
|
||||
. $this->exportComment(
|
||||
@ -2203,7 +2203,7 @@ class ExportSql extends ExportPlugin
|
||||
|
||||
// We need to SET IDENTITY_INSERT ON for MSSQL
|
||||
if (
|
||||
$current_row === 0
|
||||
$currentRow === 0
|
||||
&& isset($GLOBALS['sql_compatibility'])
|
||||
&& $GLOBALS['sql_compatibility'] === 'MSSQL'
|
||||
) {
|
||||
@ -2222,7 +2222,7 @@ class ExportSql extends ExportPlugin
|
||||
}
|
||||
}
|
||||
|
||||
$current_row++;
|
||||
$currentRow++;
|
||||
$values = [];
|
||||
foreach ($fieldsMeta as $j => $metaInfo) {
|
||||
// NULL
|
||||
@ -2292,7 +2292,7 @@ class ExportSql extends ExportPlugin
|
||||
unset($tmpUniqueCondition);
|
||||
} elseif ($GLOBALS['sql_insert_syntax'] === 'extended' || $GLOBALS['sql_insert_syntax'] === 'both') {
|
||||
// Extended inserts case
|
||||
if ($current_row === 1) {
|
||||
if ($currentRow === 1) {
|
||||
$insertLine = $schemaInsert . '('
|
||||
. implode(', ', $values) . ')';
|
||||
} else {
|
||||
@ -2305,7 +2305,7 @@ class ExportSql extends ExportPlugin
|
||||
}
|
||||
|
||||
$querySize = 0;
|
||||
$current_row = 1;
|
||||
$currentRow = 1;
|
||||
$insertLine = $schemaInsert . $insertLine;
|
||||
}
|
||||
}
|
||||
@ -2316,12 +2316,12 @@ class ExportSql extends ExportPlugin
|
||||
$insertLine = $schemaInsert . '(' . implode(', ', $values) . ')';
|
||||
}
|
||||
|
||||
if (! $this->export->outputHandler(($current_row === 1 ? '' : $separator . "\n") . $insertLine)) {
|
||||
if (! $this->export->outputHandler(($currentRow === 1 ? '' : $separator . "\n") . $insertLine)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($current_row > 0) {
|
||||
if ($currentRow > 0) {
|
||||
if (! $this->export->outputHandler(';' . "\n")) {
|
||||
return false;
|
||||
}
|
||||
@ -2331,7 +2331,7 @@ class ExportSql extends ExportPlugin
|
||||
if (
|
||||
isset($GLOBALS['sql_compatibility'])
|
||||
&& $GLOBALS['sql_compatibility'] === 'MSSQL'
|
||||
&& $current_row > 0
|
||||
&& $currentRow > 0
|
||||
) {
|
||||
$outputSucceeded = $this->export->outputHandler(
|
||||
"\n" . 'SET IDENTITY_INSERT '
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user