2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions related to designer
8 use PMA\libraries\Message
;
9 use PMA\libraries\plugins\SchemaPlugin
;
11 if (! defined('PHPMYADMIN')) {
15 require_once 'libraries/relation.lib.php';
18 * Function to get html to display a page selector
20 * @param array $cfgRelation information about the configuration storage
21 * @param string $db database name
23 * @return string html content
25 function PMA_getHtmlForPageSelector($cfgRelation, $db)
27 return PMA\libraries\Template
::get('database/designer/page_selector')
31 'cfgRelation' => $cfgRelation
37 * Function to get html for displaying the page edit/delete form
39 * @param string $db database name
40 * @param string $operation 'edit' or 'delete' depending on the operation
42 * @return string html content
44 function PMA_getHtmlForEditOrDeletePages($db, $operation)
46 return PMA\libraries\Template
::get('database/designer/edit_delete_pages')
50 'operation' => $operation
56 * Function to get html for displaying the page save as form
58 * @param string $db database name
60 * @return string html content
62 function PMA_getHtmlForPageSaveAs($db)
64 return PMA\libraries\Template
::get('database/designer/page_save_as')
73 * Retrieve IDs and names of schema pages
75 * @param string $db database name
77 * @return array array of schema page id and names
79 function PMA_getPageIdsAndNames($db)
81 $cfgRelation = PMA_getRelationsParam();
82 $page_query = "SELECT `page_nr`, `page_descr` FROM "
83 . PMA\libraries\Util
::backquote($cfgRelation['db']) . "."
84 . PMA\libraries\Util
::backquote($cfgRelation['pdf_pages'])
85 . " WHERE db_name = '" . PMA\libraries\Util
::sqlAddSlashes($db) . "'"
86 . " ORDER BY `page_descr`";
87 $page_rs = PMA_queryAsControlUser(
88 $page_query, false, PMA\libraries\DatabaseInterface
::QUERY_STORE
92 while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) {
93 $result[$curr_page['page_nr']] = $curr_page['page_descr'];
99 * Function to get html for displaying the schema export
101 * @param string $db database name
102 * @param int $page the page to be exported
106 function PMA_getHtmlForSchemaExport($db, $page)
108 /* Scan for schema plugins */
109 /* @var $export_list SchemaPlugin[] */
110 $export_list = PMA_getPlugins(
112 'libraries/plugins/schema/',
116 /* Fail if we didn't find any schema plugin */
117 if (empty($export_list)) {
118 return Message
::error(
119 __('Could not load schema plugins, please check your installation!')
123 return PMA\libraries\Template
::get('database/designer/schema_export')
128 'export_list' => $export_list
134 * Returns HTML for including some variable to be accessed by JavaScript
136 * @param array $script_tables array on foreign key support for each table
137 * @param array $script_contr initialization data array
138 * @param array $script_display_field display fields of each table
139 * @param int $display_page page number of the selected page
141 * @return string html
143 function PMA_getHtmlForJSFields(
144 $script_tables, $script_contr, $script_display_field, $display_page
146 return PMA\libraries\Template
::get('database/designer/js_fields')
149 'script_tables' => $script_tables,
150 'script_contr' => $script_contr,
151 'script_display_field' => $script_display_field,
152 'display_page' => $display_page
158 * Returns HTML for the menu bar of the designer page
160 * @param boolean $visualBuilder whether this is visual query builder
161 * @param string $selected_page name of the selected page
162 * @param array $params_array array with class name for various buttons on side
165 * @return string html
167 function PMA_getDesignerPageMenu($visualBuilder, $selected_page, $params_array)
169 return PMA\libraries\Template
::get('database/designer/side_menu')
172 'visualBuilder' => $visualBuilder,
173 'selected_page' => $selected_page,
174 'params_array' => $params_array
180 * Returns array of stored values of Designer Settings
182 * @return array stored values
184 function PMA_getSideMenuParamsArray()
188 $cfgRelation = PMA_getRelationsParam();
190 if ($GLOBALS['cfgRelation']['designersettingswork']) {
192 $query = 'SELECT `settings_data` FROM '
193 . PMA\libraries\Util
::backquote($cfgRelation['db']) . '.'
194 . PMA\libraries\Util
::backquote($cfgRelation['designer_settings'])
195 . ' WHERE ' . PMA\libraries\Util
::backquote('username') . ' = "'
196 . $GLOBALS['cfg']['Server']['user'] . '";';
198 $result = $GLOBALS['dbi']->fetchSingleRow($query);
200 $params = json_decode($result['settings_data'], true);
207 * Returns class names for various buttons on Designer Side Menu
209 * @return array class names of various buttons
211 function PMA_returnClassNamesFromMenuButtons()
213 $classes_array = array();
214 $params_array = PMA_getSideMenuParamsArray();
216 if (isset($params_array['angular_direct'])
217 && $params_array['angular_direct'] == 'angular'
219 $classes_array['angular_direct'] = 'M_butt_Selected_down';
221 $classes_array['angular_direct'] = 'M_butt';
224 if (isset($params_array['snap_to_grid'])
225 && $params_array['snap_to_grid'] == 'on'
227 $classes_array['snap_to_grid'] = 'M_butt_Selected_down';
229 $classes_array['snap_to_grid'] = 'M_butt';
232 if (isset($params_array['pin_text'])
233 && $params_array['pin_text'] == 'true'
235 $classes_array['pin_text'] = 'M_butt_Selected_down';
237 $classes_array['pin_text'] = 'M_butt';
240 if (isset($params_array['relation_lines'])
241 && $params_array['relation_lines'] == 'false'
243 $classes_array['relation_lines'] = 'M_butt_Selected_down';
245 $classes_array['relation_lines'] = 'M_butt';
248 if (isset($params_array['small_big_all'])
249 && $params_array['small_big_all'] == 'v'
251 $classes_array['small_big_all'] = 'M_butt_Selected_down';
253 $classes_array['small_big_all'] = 'M_butt';
256 if (isset($params_array['side_menu'])
257 && $params_array['side_menu'] == 'true'
259 $classes_array['side_menu'] = 'M_butt_Selected_down';
261 $classes_array['side_menu'] = 'M_butt';
264 return $classes_array;
268 * Returns HTML for the canvas element
270 * @return string html
272 function PMA_getHTMLCanvas()
274 return PMA\libraries\Template
::get('database/designer/canvas')->render();
278 * Return HTML for the table list
280 * @param array $tab_pos table positions
281 * @param int $display_page page number of the selected page
283 * @return string html
285 function PMA_getHTMLTableList($tab_pos, $display_page)
287 return PMA\libraries\Template
::get('database/designer/table_list')
290 'tab_pos' => $tab_pos,
291 'display_page' => $display_page
297 * Get HTML to display tables on designer page
299 * @param array $tab_pos tables positions
300 * @param int $display_page page number of the selected page
301 * @param array $tab_column table column info
302 * @param array $tables_all_keys all indices
303 * @param array $tables_pk_or_unique_keys unique or primary indices
305 * @return string html
307 function PMA_getDatabaseTables(
308 $tab_pos, $display_page, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys
310 return PMA\libraries\Template
::get('database/designer/database_tables')
313 'tab_pos' => $tab_pos,
314 'display_page' => $display_page,
315 'tab_column' => $tab_column,
316 'tables_all_keys' => $tables_all_keys,
317 'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys
323 * Returns HTML for the new relations panel.
325 * @return string html
327 function PMA_getNewRelationPanel()
329 return PMA\libraries\Template
::get('database/designer/new_relation_panel')
334 * Returns HTML for the relations delete panel
336 * @return string html
338 function PMA_getDeleteRelationPanel()
340 return PMA\libraries\Template
::get('database/designer/delete_relation_panel')
345 * Returns HTML for the options panel
347 * @return string html
349 function PMA_getOptionsPanel()
351 return PMA\libraries\Template
::get('database/designer/options_panel')->render();
355 * Get HTML for the 'rename to' panel
357 * @return string html
359 function PMA_getRenameToPanel()
361 return PMA\libraries\Template
::get('database/designer/rename_to_panel')
366 * Returns HTML for the 'having' panel
368 * @return string html
370 function PMA_getHavingQueryPanel()
372 return PMA\libraries\Template
::get('database/designer/having_query_panel')
377 * Returns HTML for the 'aggregate' panel
379 * @return string html
381 function PMA_getAggregateQueryPanel()
383 return PMA\libraries\Template
::get('database/designer/aggregate_query_panel')
388 * Returns HTML for the 'where' panel
390 * @return string html
392 function PMA_getWhereQueryPanel()
394 return PMA\libraries\Template
::get('database/designer/where_query_panel')
399 * Returns HTML for the query details panel
401 * @return string html
403 function PMA_getQueryDetails()
405 return PMA\libraries\Template
::get('database/designer/query_details')->render();