2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions related to designer
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/relation.lib.php';
13 require_once 'libraries/Template.class.php';
16 * Function to get html to display a page selector
18 * @param array $cfgRelation information about the configuration storage
19 * @param string $db database name
21 * @return string html content
23 function PMA_getHtmlForPageSelector($cfgRelation, $db)
25 return PMA\Template
::get('designer/page_selector')
29 'cfgRelation' => $cfgRelation
35 * Function to get html for displaying the page edit/delete form
37 * @param string $db database name
38 * @param string $operation 'edit' or 'delete' depending on the operation
40 * @return string html content
42 function PMA_getHtmlForEditOrDeletePages($db, $operation)
44 return PMA\Template
::get('designer/edit_delete_pages')
48 'operation' => $operation
54 * Function to get html for displaying the page save as form
56 * @param string $db database name
58 * @return string html content
60 function PMA_getHtmlForPageSaveAs($db)
62 return PMA\Template
::get('designer/page_save_as')
71 * Retrieve IDs and names of schema pages
73 * @param string $db database name
75 * @return array array of schema page id and names
77 function PMA_getPageIdsAndNames($db)
79 $cfgRelation = PMA_getRelationsParam();
80 $page_query = "SELECT `page_nr`, `page_descr` FROM "
81 . PMA_Util
::backquote($cfgRelation['db']) . "."
82 . PMA_Util
::backquote($cfgRelation['pdf_pages'])
83 . " WHERE db_name = '" . PMA_Util
::sqlAddSlashes($db) . "'"
84 . " ORDER BY `page_descr`";
85 $page_rs = PMA_queryAsControlUser(
86 $page_query, false, PMA_DatabaseInterface
::QUERY_STORE
90 while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) {
91 $result[$curr_page['page_nr']] = $curr_page['page_descr'];
97 * Function to get html for displaying the schema export
99 * @param string $db database name
100 * @param int $page the page to be exported
104 function PMA_getHtmlForSchemaExport($db, $page)
106 /* Scan for schema plugins */
107 /* @var $export_list SchemaPlugin[] */
108 $export_list = PMA_getPlugins(
110 'libraries/plugins/schema/',
114 /* Fail if we didn't find any schema plugin */
115 if (empty($export_list)) {
116 return PMA_Message
::error(
117 __('Could not load schema plugins, please check your installation!')
121 return PMA\Template
::get('designer/schema_export')
126 'export_list' => $export_list
132 * Returns HTML for including some variable to be accessed by JavaScript
134 * @param array $script_tables array on foreign key support for each table
135 * @param array $script_contr initialization data array
136 * @param array $script_display_field display fields of each table
137 * @param int $display_page page number of the selected page
139 * @return string html
141 function PMA_getHtmlForJSFields(
142 $script_tables, $script_contr, $script_display_field, $display_page
144 return PMA\Template
::get('designer/js_fields')
147 'script_tables' => $script_tables,
148 'script_contr' => $script_contr,
149 'script_display_field' => $script_display_field,
150 'display_page' => $display_page
156 * Returns HTML for the menu bar of the designer page
158 * @param boolean $visualBuilder whether this is visual query builder
159 * @param string $selected_page name of the selected page
160 * @param array $params_array array with class name for various buttons on side menu
162 * @return string html
164 function PMA_getDesignerPageMenu($visualBuilder, $selected_page, $params_array)
166 return PMA\Template
::get('designer/side_menu')
169 'visualBuilder' => $visualBuilder,
170 'selected_page' => $selected_page,
171 'params_array' => $params_array
177 * Returns array of stored values of Designer Settings
179 * @return array stored values
181 function PMA_getSideMenuParamsArray()
185 $cfgRelation = PMA_getRelationsParam();
187 if ($GLOBALS['cfgRelation']['designersettingswork']) {
189 $query = 'SELECT `settings_data` FROM ' . PMA_Util
::backquote($cfgRelation['db']) . '.'
190 . PMA_Util
::backquote($cfgRelation['designer_settings'])
191 . ' WHERE ' . PMA_Util
::backquote('username') . ' = "'
192 . $GLOBALS['cfg']['Server']['user'] . '";';
194 $result = $GLOBALS['dbi']->fetchSingleRow($query);
196 $params = json_decode($result['settings_data'], true);
203 * Returns class names for various buttons on Designer Side Menu
205 * @return array class names of various buttons
207 function PMA_returnClassNamesFromMenuButtons()
209 $classes_array = array();
210 $params_array = PMA_getSideMenuParamsArray();
212 if (isset($params_array['angular_direct'])
213 && $params_array['angular_direct'] == 'angular'
215 $classes_array['angular_direct'] = 'M_butt_Selected_down';
217 $classes_array['angular_direct'] = 'M_butt';
220 if (isset($params_array['snap_to_grid'])
221 && $params_array['snap_to_grid'] == 'on'
223 $classes_array['snap_to_grid'] = 'M_butt_Selected_down';
225 $classes_array['snap_to_grid'] = 'M_butt';
228 if (isset($params_array['pin_text'])
229 && $params_array['pin_text'] == 'true'
231 $classes_array['pin_text'] = 'M_butt_Selected_down';
233 $classes_array['pin_text'] = 'M_butt';
236 if (isset($params_array['relation_lines'])
237 && $params_array['relation_lines'] == 'false'
239 $classes_array['relation_lines'] = 'M_butt_Selected_down';
241 $classes_array['relation_lines'] = 'M_butt';
244 if (isset($params_array['small_big_all'])
245 && $params_array['small_big_all'] == 'v'
247 $classes_array['small_big_all'] = 'M_butt_Selected_down';
249 $classes_array['small_big_all'] = 'M_butt';
252 if (isset($params_array['side_menu'])
253 && $params_array['side_menu'] == 'true'
255 $classes_array['side_menu'] = 'M_butt_Selected_down';
257 $classes_array['side_menu'] = 'M_butt';
260 return $classes_array;
264 * Returns HTML for the canvas element
266 * @return string html
268 function PMA_getHTMLCanvas()
270 return PMA\Template
::get('designer/canvas')->render();
274 * Return HTML for the table list
276 * @param array $tab_pos table positions
277 * @param int $display_page page number of the selected page
279 * @return string html
281 function PMA_getHTMLTableList($tab_pos, $display_page)
283 return PMA\Template
::get('designer/table_list')
286 'tab_pos' => $tab_pos,
287 'display_page' => $display_page
293 * Get HTML to display tables on designer page
295 * @param array $tab_pos tables positions
296 * @param int $display_page page number of the selected page
297 * @param array $tab_column table column info
298 * @param array $tables_all_keys all indices
299 * @param array $tables_pk_or_unique_keys unique or primary indices
301 * @return string html
303 function PMA_getDatabaseTables(
304 $tab_pos, $display_page, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys
306 return PMA\Template
::get('designer/database_tables')
309 'tab_pos' => $tab_pos,
310 'display_page' => $display_page,
311 'tab_column' => $tab_column,
312 'tables_all_keys' => $tables_all_keys,
313 'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys
319 * Returns HTML for the new relations panel.
321 * @return string html
323 function PMA_getNewRelationPanel()
325 return PMA\Template
::get('designer/new_relation_panel')->render();
329 * Returns HTML for the relations delete panel
331 * @return string html
333 function PMA_getDeleteRelationPanel()
335 return PMA\Template
::get('designer/delete_relation_panel')->render();
339 * Returns HTML for the options panel
341 * @return string html
343 function PMA_getOptionsPanel()
345 return PMA\Template
::get('designer/options_panel')->render();
349 * Get HTML for the 'rename to' panel
351 * @return string html
353 function PMA_getRenameToPanel()
355 return PMA\Template
::get('designer/rename_to_panel')->render();
359 * Returns HTML for the 'having' panel
361 * @return string html
363 function PMA_getHavingQueryPanel()
365 return PMA\Template
::get('designer/having_query_panel')->render();
369 * Returns HTML for the 'aggregate' panel
371 * @return string html
373 function PMA_getAggregateQueryPanel()
375 return PMA\Template
::get('designer/aggregate_query_panel')->render();
379 * Returns HTML for the 'where' panel
381 * @return string html
383 function PMA_getWhereQueryPanel()
385 return PMA\Template
::get('designer/where_query_panel')->render();
389 * Returns HTML for the query details panel
391 * @return string html
393 function PMA_getQueryDetails()
395 return PMA\Template
::get('designer/query_details')->render();