Skip to content

Commit

Permalink
Merge pull request #14376 from williamdes/issue-13032-designer
Browse files Browse the repository at this point in the history
Issue #13032 - fix designer
  • Loading branch information
MauricioFauth committed Jun 16, 2018
2 parents e6bfa47 + 913c28e commit cb2dae5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 62 deletions.
17 changes: 8 additions & 9 deletions js/designer/init.js
Expand Up @@ -23,17 +23,16 @@ AJAX.registerOnload('designer/init.js', function () {
$('#ab').accordion('refresh');
return false;
});
var tables_data = JSON.parse($('#script_tables').html());

j_tabs = tables_data.j_tabs;
h_tabs = tables_data.h_tabs;
contr = JSON.parse($('#script_contr').html());
display_field = JSON.parse($('#script_display_field').html());
j_tabs = designer_config.scriptTables.j_tabs;
h_tabs = designer_config.scriptTables.h_tabs;
contr = designer_config.scriptContr;
display_field = designer_config.scriptDisplayField;

server = $('#script_server').html();
db = $('#script_db').html();
selected_page = $('#script_display_page').html() === '' ? '-1' : $('#script_display_page').html();
designer_tables_enabled = $('#designer_tables_enabled').html() === '1';
server = designer_config.server;
db = designer_config.db;
selected_page = designer_config.displayPage;
designer_tables_enabled = designer_config.tablesEnabled;

Main();

Expand Down
2 changes: 1 addition & 1 deletion js/designer/move.js
Expand Up @@ -1122,7 +1122,7 @@ function Load_page (page) {
if (page !== null) {
param_page = argsep + 'page=' + page;
}
$('<a href="db_designer.php?server=' + server + argsep + 'db=' + db + param_page + '"></a>')
$('<a href="db_designer.php?server=' + server + argsep + 'db=' + encodeURI(db) + param_page + '"></a>')
.appendTo($('#page_content'))
.trigger('click');
} else {
Expand Down
16 changes: 11 additions & 5 deletions libraries/classes/Database/Designer.php
Expand Up @@ -360,15 +360,21 @@ public function getHtmlForMain(
}
}
}

$designerConfig = new \stdClass();
$designerConfig->db = $db;
$designerConfig->scriptTables = $scriptTables;
$designerConfig->scriptContr = $scriptContr;
$designerConfig->server = $GLOBALS['server'];
$designerConfig->scriptDisplayField = $scriptDisplayField;
$designerConfig->displayPage = $displayPage;
$designerConfig->tablesEnabled = $cfgRelation['pdfwork'];

return Template::get('database/designer/main')->render([
'server' => $GLOBALS['server'],
'db' => $db,
'get_db' => $getDb,
'script_tables' => json_encode($scriptTables),
'script_contr' => json_encode($scriptContr),
'script_display_field' => json_encode($scriptDisplayField),
'designer_config'=> json_encode($designerConfig),
'display_page' => $displayPage,
'relation_pdfwork' => $cfgRelation['pdfwork'],
'has_query' => $hasQuery,
'selected_page' => $selectedPage,
'params_array' => $paramsArray,
Expand Down
37 changes: 23 additions & 14 deletions libraries/classes/Database/Designer/Common.php
Expand Up @@ -55,7 +55,15 @@ public function getTablesInfo()
$GLOBALS['designer']['TABLE_NAME'] = [];// that foreach no error
$GLOBALS['designer']['OWNER'] = [];
$GLOBALS['designer']['TABLE_NAME_SMALL'] = [];
$GLOBALS['designer']['TABLE_TYPE'] = [];

$GLOBALS['designer_url']['TABLE_NAME'] = [];
$GLOBALS['designer_url']['OWNER'] = [];
$GLOBALS['designer_url']['TABLE_NAME_SMALL'] = [];

$GLOBALS['designer_out']['TABLE_NAME'] = [];
$GLOBALS['designer_out']['OWNER'] = [];
$GLOBALS['designer_out']['TABLE_NAME_SMALL'] = [];
$tables = $this->dbi->getTablesFull($GLOBALS['db']);
// seems to be needed later
$this->dbi->selectDb($GLOBALS['db']);
Expand Down Expand Up @@ -94,7 +102,8 @@ public function getTablesInfo()

$DF = $this->relation->getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
if ($DF != '') {
$retval[$GLOBALS['designer_url']["TABLE_NAME_SMALL"][$i]] = $DF;
$DF = rawurlencode((string)$DF);
$retval[rawurlencode($GLOBALS['designer_url']["TABLE_NAME_SMALL"][$i])] = $DF;
}

$i++;
Expand Down Expand Up @@ -158,12 +167,12 @@ public function getScriptContr()
if ($row !== false) {
foreach ($row as $field => $value) {
$con['C_NAME'][$i] = '';
$con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
$con['DCN'][$i] = urlencode($field);
$con['STN'][$i] = urlencode(
$con['DTN'][$i] = rawurlencode($GLOBALS['db'] . "." . $val[0]);
$con['DCN'][$i] = rawurlencode($field);
$con['STN'][$i] = rawurlencode(
$value['foreign_db'] . "." . $value['foreign_table']
);
$con['SCN'][$i] = urlencode($value['foreign_field']);
$con['SCN'][$i] = rawurlencode($value['foreign_field']);
$i++;
}
}
Expand All @@ -172,15 +181,15 @@ public function getScriptContr()
if ($row !== false) {
foreach ($row['foreign_keys_data'] as $one_key) {
foreach ($one_key['index_list'] as $index => $one_field) {
$con['C_NAME'][$i] = $one_key['constraint'];
$con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
$con['DCN'][$i] = urlencode($one_field);
$con['STN'][$i] = urlencode(
$con['C_NAME'][$i] = rawurlencode($one_key['constraint']);
$con['DTN'][$i] = rawurlencode($GLOBALS['db'] . "." . $val[0]);
$con['DCN'][$i] = rawurlencode($one_field);
$con['STN'][$i] = rawurlencode(
(isset($one_key['ref_db_name']) ?
$one_key['ref_db_name'] : $GLOBALS['db'])
. "." . $one_key['ref_table_name']
);
$con['SCN'][$i] = urlencode($one_key['ref_index_list'][$index]);
$con['SCN'][$i] = rawurlencode($one_key['ref_index_list'][$index]);
$i++;
}
}
Expand All @@ -194,8 +203,8 @@ public function getScriptContr()
$dtn_i = $con['DTN'][$i];
$retval[$ti] = [];
$retval[$ti][$c_name_i] = [];
if (in_array($dtn_i, $GLOBALS['designer_url']["TABLE_NAME"])
&& in_array($con['STN'][$i], $GLOBALS['designer_url']["TABLE_NAME"])
if (in_array(rawurldecode($dtn_i), $GLOBALS['designer_url']["TABLE_NAME"])
&& in_array(rawurldecode($con['STN'][$i]), $GLOBALS['designer_url']["TABLE_NAME"])
) {
$retval[$ti][$c_name_i][$dtn_i] = [];
$retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = [
Expand Down Expand Up @@ -262,8 +271,8 @@ public function getScriptTabs()
if (Util::isForeignKeySupported($GLOBALS['designer']['TABLE_TYPE'][$i])) {
$j = 1;
}
$retval['j_tabs'][$GLOBALS['designer_url']['TABLE_NAME'][$i]] = $j;
$retval['h_tabs'][$GLOBALS['designer_url']['TABLE_NAME'][$i]] = 1;
$retval['j_tabs'][\rawurlencode($GLOBALS['designer_url']['TABLE_NAME'][$i])] = $j;
$retval['h_tabs'][\rawurlencode($GLOBALS['designer_url']['TABLE_NAME'][$i])] = 1;
}
return $retval;
}
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/ThemeManager.php
Expand Up @@ -105,7 +105,6 @@ public function __construct()
$this->theme_default = $GLOBALS['cfg']['ThemeDefault'];
}


// check if user have a theme cookie
$cookie_theme = $this->getThemeCookie();
if (! $cookie_theme || ! $this->setActiveTheme($cookie_theme)) {
Expand Down
40 changes: 20 additions & 20 deletions templates/database/designer/database_tables.twig
@@ -1,11 +1,11 @@
{% for i in 0..table_names|length - 1 %}
{% set t_n = table_names[i] %}
{% for t_n in table_names %}
{% set i = loop.index0 %}
{% set t_n_url = table_names_url[i] %}
<input name="t_x[{{ t_n_url }}]" type="hidden" id="t_x_{{ t_n_url }}_" />
<input name="t_y[{{ t_n_url }}]" type="hidden" id="t_y_{{ t_n_url }}_" />
<input name="t_v[{{ t_n_url }}]" type="hidden" id="t_v_{{ t_n_url }}_" />
<input name="t_h[{{ t_n_url }}]" type="hidden" id="t_h_{{ t_n_url }}_" />
<table id="{{ t_n_url }}"
<input name="t_x[{{ t_n_url|url_encode }}]" type="hidden" id="t_x_{{ t_n_url|url_encode }}_" />
<input name="t_y[{{ t_n_url|url_encode }}]" type="hidden" id="t_y_{{ t_n_url|url_encode }}_" />
<input name="t_v[{{ t_n_url|url_encode }}]" type="hidden" id="t_v_{{ t_n_url|url_encode }}_" />
<input name="t_h[{{ t_n_url|url_encode }}]" type="hidden" id="t_h_{{ t_n_url|url_encode }}_" />
<table id="{{ t_n_url|url_encode }}"
cellpadding="0"
cellspacing="0"
class="designer_tab"
Expand All @@ -20,27 +20,27 @@
<input class="select_all_1"
type="checkbox"
style="margin: 0;"
value="select_all_{{ t_n_url }}"
id="select_all_{{ t_n_url }}"
value="select_all_{{ t_n_url|url_encode }}"
id="select_all_{{ t_n_url|url_encode }}"
title="select all"
designer_url_table_name="{{ t_n_url }}"
designer_url_table_name="{{ t_n_url|url_encode }}"
designer_out_owner="{{ owner_out[i]|raw }}">
</td>
{% endif %}
<td class="small_tab"
title="{% trans 'Show/hide columns' %}"
id="id_hide_tbody_{{ t_n_url }}"
table_name="{{ t_n_url }}">
id="id_hide_tbody_{{ t_n_url|url_encode }}"
table_name="{{ t_n_url|url_encode }}">
{{ tab_pos[t_n] is not defined or tab_pos[t_n]['V'] is not empty ? 'v' : '&gt;' }}
</td>
<td class="small_tab_pref small_tab_pref_1"
table_name_small="{{ table_names_small_url[i] }}">
<img src="{{ theme.getImgPath('designer/exec_small.png') }}"
title="{% trans 'See table structure' %}" />
</td>
<td id="id_zag_{{ t_n_url }}"
<td id="id_zag_{{ t_n_url|url_encode }}"
class="tab_zag nowrap tab_zag_noquery"
table_name="{{ t_n_url }}"
table_name="{{ t_n_url|url_encode }}"
query_set="{{ has_query ? 1 : 0 }}">
<span class="owner">
{{ owner_out[i]|raw }}
Expand All @@ -49,13 +49,13 @@
</td>
{% if has_query %}
<td class="tab_zag tab_zag_query"
id="id_zag_{{ t_n_url }}_2"
table_name="{{ t_n_url }}">
id="id_zag_{{ t_n_url|url_encode }}_2"
table_name="{{ t_n_url|url_encode }}">
</td>
{% endif %}
</tr>
</thead>
<tbody id="id_tbody_{{ t_n_url }}"
<tbody id="id_tbody_{{ t_n_url|url_encode }}"
{{- tab_pos[t_n] is defined and tab_pos[t_n]['V'] is empty ? ' style="display: none"' }}>
{% set display_field = Relation_getDisplayField(get_db, table_names_small[i]) %}
{% for j in 0..tab_column[t_n]['COLUMN_ID']|length - 1 %}
Expand All @@ -78,17 +78,17 @@
{% if has_query %}
<td class="select_all">
<input class="select_all_store_col"
value="{{ t_n_url }}{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
value="{{ t_n_url|url_encode }}{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
type="checkbox"
id="select_{{ t_n_url }}._{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
id="select_{{ t_n_url|url_encode }}._{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
style="margin: 0;"
title="select_{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
store_column_param="{{ table_names_small_out[i]|url_encode }},
{{- owner_out[i] }},
{{- tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}">
</td>
{% endif %}
<td width="10px" colspan="3" id="{{ t_n_url }}.
<td width="10px" colspan="3" id="{{ t_n_url|url_encode }}.
{{- tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}">
<div class="nowrap">
{% set type = columns_type[t_n ~ '.' ~ tab_column[t_n]['COLUMN_NAME'][j]] %}
Expand Down
18 changes: 7 additions & 11 deletions templates/database/designer/main.twig
@@ -1,12 +1,8 @@
{# Invisible characters will make javascript crash #}
{% spaceless %}
<div id="script_server" class="hide">{{ server }}</div>
<div id="script_db" class="hide">{{ db }}</div>
<div id="script_tables" class="hide">{{ script_tables }}</div>
<div id="script_contr" class="hide">{{ script_contr }}</div>
<div id="script_display_field" class="hide">{{ script_display_field }}</div>
<div id="script_display_page" class="hide">{{ display_page }}</div>
<div id="designer_tables_enabled" class="hide">{{ relation_pdfwork }}</div>
<script type="text/javascript">
var designer_config = {{ designer_config | raw }};
</script>
{% endspaceless %}

{# side menu #}
Expand Down Expand Up @@ -231,25 +227,25 @@
width="1px"
class="L_butt2_1">
<img alt=""
table_name="{{ table_names_small_url[i] }}"
table_name="{{ table_names_small_url[i]|url_encode }}"
class="scroll_tab_struct"
src="{{ theme.getImgPath('designer/exec.png') }}"/>
</td>
<td width="1px">
<input class="scroll_tab_checkbox"
title="{% trans 'Hide' %}"
id="check_vis_{{ table_names_url[i] }}"
id="check_vis_{{ table_names_url[i]|url_encode }}"
style="margin:0;"
type="checkbox"
value="{{ table_names_url[i] }}"
value="{{ table_names_url[i]|url_encode }}"
{% if (tab_pos[table_names[i]] is defined
and tab_pos[table_names[i]]['H'])
or display_page == -1 -%}
checked="checked"
{%- endif %} />
</td>
<td class="designer_Tabs"
designer_url_table_name="{{ table_names_url[i] }}">
designer_url_table_name="{{ table_names_url[i]|url_encode }}">
{{ table_names_out[i]|raw }}
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion test/ci-apidocs
@@ -1,3 +1,3 @@
#!/bin/sh
set -e
./vendor/bin/sami.php --no-interaction update ./test/sami-config.php
./vendor/bin/sami.php --no-interaction --verbose update ./test/sami-config.php

0 comments on commit cb2dae5

Please sign in to comment.