Minor improvement to prior commit.
[openemr.git] / phpmyadmin / libraries / db_designer.lib.php
blob4ca11c017e68ed228404b831d11e2bb1b73d9611
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions related to designer
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/relation.lib.php';
13 require_once 'libraries/Template.class.php';
15 /**
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('database/designer/page_selector')
26 ->render(
27 array(
28 'db' => $db,
29 'cfgRelation' => $cfgRelation
34 /**
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('database/designer/edit_delete_pages')
45 ->render(
46 array(
47 'db' => $db,
48 'operation' => $operation
53 /**
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('database/designer/page_save_as')
63 ->render(
64 array(
65 'db' => $db
70 /**
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
89 $result = array();
90 while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) {
91 $result[$curr_page['page_nr']] = $curr_page['page_descr'];
93 return $result;
96 /**
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
102 * @return string
104 function PMA_getHtmlForSchemaExport($db, $page)
106 /* Scan for schema plugins */
107 /* @var $export_list SchemaPlugin[] */
108 $export_list = PMA_getPlugins(
109 "schema",
110 'libraries/plugins/schema/',
111 null
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!')
118 )->getDisplay();
121 return PMA\Template::get('database/designer/schema_export')
122 ->render(
123 array(
124 'db' => $db,
125 'page' => $page,
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('database/designer/js_fields')
145 ->render(
146 array(
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
161 * menu
163 * @return string html
165 function PMA_getDesignerPageMenu($visualBuilder, $selected_page, $params_array)
167 return PMA\Template::get('database/designer/side_menu')
168 ->render(
169 array(
170 'visualBuilder' => $visualBuilder,
171 'selected_page' => $selected_page,
172 'params_array' => $params_array
178 * Returns array of stored values of Designer Settings
180 * @return array stored values
182 function PMA_getSideMenuParamsArray()
184 $params = array();
186 $cfgRelation = PMA_getRelationsParam();
188 if ($GLOBALS['cfgRelation']['designersettingswork']) {
190 $query = 'SELECT `settings_data` FROM '
191 . PMA_Util::backquote($cfgRelation['db']) . '.'
192 . PMA_Util::backquote($cfgRelation['designer_settings'])
193 . ' WHERE ' . PMA_Util::backquote('username') . ' = "'
194 . $GLOBALS['cfg']['Server']['user'] . '";';
196 $result = $GLOBALS['dbi']->fetchSingleRow($query);
198 $params = json_decode($result['settings_data'], true);
201 return $params;
205 * Returns class names for various buttons on Designer Side Menu
207 * @return array class names of various buttons
209 function PMA_returnClassNamesFromMenuButtons()
211 $classes_array = array();
212 $params_array = PMA_getSideMenuParamsArray();
214 if (isset($params_array['angular_direct'])
215 && $params_array['angular_direct'] == 'angular'
217 $classes_array['angular_direct'] = 'M_butt_Selected_down';
218 } else {
219 $classes_array['angular_direct'] = 'M_butt';
222 if (isset($params_array['snap_to_grid'])
223 && $params_array['snap_to_grid'] == 'on'
225 $classes_array['snap_to_grid'] = 'M_butt_Selected_down';
226 } else {
227 $classes_array['snap_to_grid'] = 'M_butt';
230 if (isset($params_array['pin_text'])
231 && $params_array['pin_text'] == 'true'
233 $classes_array['pin_text'] = 'M_butt_Selected_down';
234 } else {
235 $classes_array['pin_text'] = 'M_butt';
238 if (isset($params_array['relation_lines'])
239 && $params_array['relation_lines'] == 'false'
241 $classes_array['relation_lines'] = 'M_butt_Selected_down';
242 } else {
243 $classes_array['relation_lines'] = 'M_butt';
246 if (isset($params_array['small_big_all'])
247 && $params_array['small_big_all'] == 'v'
249 $classes_array['small_big_all'] = 'M_butt_Selected_down';
250 } else {
251 $classes_array['small_big_all'] = 'M_butt';
254 if (isset($params_array['side_menu'])
255 && $params_array['side_menu'] == 'true'
257 $classes_array['side_menu'] = 'M_butt_Selected_down';
258 } else {
259 $classes_array['side_menu'] = 'M_butt';
262 return $classes_array;
266 * Returns HTML for the canvas element
268 * @return string html
270 function PMA_getHTMLCanvas()
272 return PMA\Template::get('database/designer/canvas')->render();
276 * Return HTML for the table list
278 * @param array $tab_pos table positions
279 * @param int $display_page page number of the selected page
281 * @return string html
283 function PMA_getHTMLTableList($tab_pos, $display_page)
285 return PMA\Template::get('database/designer/table_list')
286 ->render(
287 array(
288 'tab_pos' => $tab_pos,
289 'display_page' => $display_page
295 * Get HTML to display tables on designer page
297 * @param array $tab_pos tables positions
298 * @param int $display_page page number of the selected page
299 * @param array $tab_column table column info
300 * @param array $tables_all_keys all indices
301 * @param array $tables_pk_or_unique_keys unique or primary indices
303 * @return string html
305 function PMA_getDatabaseTables(
306 $tab_pos, $display_page, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys
308 return PMA\Template::get('database/designer/database_tables')
309 ->render(
310 array(
311 'tab_pos' => $tab_pos,
312 'display_page' => $display_page,
313 'tab_column' => $tab_column,
314 'tables_all_keys' => $tables_all_keys,
315 'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys
321 * Returns HTML for the new relations panel.
323 * @return string html
325 function PMA_getNewRelationPanel()
327 return PMA\Template::get('database/designer/new_relation_panel')->render();
331 * Returns HTML for the relations delete panel
333 * @return string html
335 function PMA_getDeleteRelationPanel()
337 return PMA\Template::get('database/designer/delete_relation_panel')->render();
341 * Returns HTML for the options panel
343 * @return string html
345 function PMA_getOptionsPanel()
347 return PMA\Template::get('database/designer/options_panel')->render();
351 * Get HTML for the 'rename to' panel
353 * @return string html
355 function PMA_getRenameToPanel()
357 return PMA\Template::get('database/designer/rename_to_panel')->render();
361 * Returns HTML for the 'having' panel
363 * @return string html
365 function PMA_getHavingQueryPanel()
367 return PMA\Template::get('database/designer/having_query_panel')->render();
371 * Returns HTML for the 'aggregate' panel
373 * @return string html
375 function PMA_getAggregateQueryPanel()
377 return PMA\Template::get('database/designer/aggregate_query_panel')->render();
381 * Returns HTML for the 'where' panel
383 * @return string html
385 function PMA_getWhereQueryPanel()
387 return PMA\Template::get('database/designer/where_query_panel')->render();
391 * Returns HTML for the query details panel
393 * @return string html
395 function PMA_getQueryDetails()
397 return PMA\Template::get('database/designer/query_details')->render();