Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / libraries / tbl_chart.lib.php
blobe1f8680e9b397ce97d3bcac9eed783de5df4e17b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying chart
7 * @usedby tbl_chart.php
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * Function to get html for pma_token and url_query
18 * @param string $url_query url query
20 * @return string
22 function PMA_getHtmlForPmaTokenAndUrlQuery($url_query)
24 $htmlString = '<script type="text/javascript">'
25 . "pma_token = '" . $_SESSION[' PMA_token '] . "';"
26 . "url_query = '" . $url_query . "';"
27 . '</script>';
28 return $htmlString;
31 /**
32 * Function to get html for the chart type options
34 * @return string
36 function PMA_getHtmlForChartTypeOptions()
38 $html = '<input type="radio" name="chartType" value="bar" id="radio_bar" />'
39 . '<label for ="radio_bar">' . _pgettext('Chart type', 'Bar') . '</label>'
40 . '<input type="radio" name="chartType" value="column" id="radio_column" />'
41 . '<label for ="radio_column">' . _pgettext('Chart type', 'Column')
42 . '</label>'
43 . '<input type="radio" name="chartType" value="line" id="radio_line"'
44 . ' checked="checked" />'
45 . '<label for ="radio_line">' . _pgettext('Chart type', 'Line') . '</label>'
46 . '<input type="radio" name="chartType" value="spline" id="radio_spline" />'
47 . '<label for ="radio_spline">' . _pgettext('Chart type', 'Spline')
48 . '</label>'
49 . '<input type="radio" name="chartType" value="area" id="radio_area" />'
50 . '<label for ="radio_area">' . _pgettext('Chart type', 'Area') . '</label>'
51 . '<span class="span_pie" style="display:none;">'
52 . '<input type="radio" name="chartType" value="pie" id="radio_pie" />'
53 . '<label for ="radio_pie">' . _pgettext('Chart type', 'Pie') . '</label>'
54 . '</span>'
55 . '<span class="span_timeline" style="display:none;">'
56 . '<input type="radio" name="chartType" '
57 . 'value="timeline" id="radio_timeline" />'
58 . '<label for ="radio_timeline">' . _pgettext('Chart type', 'Timeline')
59 . '</label>'
60 . '</span>'
61 . '<br /><br />';
63 return $html;
66 /**
67 * Function to get html for the bar stacked option
69 * @return string
71 function PMA_getHtmlForStackedOption()
73 $html = '<span class="barStacked">'
74 . '<input type="checkbox" name="barStacked" value="1"'
75 . ' id="checkbox_barStacked" />'
76 . '<label for ="checkbox_barStacked">' . __('Stacked') . '</label>'
77 . '</span>'
78 . '<br /><br />';
80 return $html;
83 /**
84 * Function to get html for the chart x axis options
86 * @param array $keys keys
87 * @param int &$yaxis y axis
89 * @return string
91 function PMA_getHtmlForChartXAxisOptions($keys, &$yaxis)
93 $htmlString = '<div style="float:left; padding-left:40px;">'
94 . '<label for="select_chartXAxis">' . __('X-Axis:') . '</label>'
95 . '<select name="chartXAxis" id="select_chartXAxis">';
97 foreach ($keys as $idx => $key) {
98 if ($yaxis === null) {
99 $htmlString .= '<option value="' . htmlspecialchars($idx)
100 . '" selected="selected">' . htmlspecialchars($key) . '</option>';
101 $yaxis = $idx;
102 } else {
103 $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
104 . htmlspecialchars($key) . '</option>';
107 $htmlString .= '</select>';
109 return $htmlString;
114 * Function to get html for chart series options
116 * @param array $keys keys
117 * @param array $fields_meta fields meta
118 * @param array $numeric_types numeric types
119 * @param int $yaxis y axis
120 * @param int $numeric_column_count numeric column count
122 * @return string
124 function PMA_getHtmlForChartSeriesOptions($keys, $fields_meta, $numeric_types,
125 $yaxis, $numeric_column_count
127 $htmlString = '<br />'
128 . '<label for="select_chartSeries">' . __('Series:') . '</label>'
129 . '<select name="chartSeries" id="select_chartSeries" multiple="multiple">';
131 foreach ($keys as $idx => $key) {
132 if (in_array($fields_meta[$idx]->type, $numeric_types)) {
133 if ($idx == $yaxis && $numeric_column_count > 1) {
134 $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
135 . htmlspecialchars($key) . '</option>';
136 } else {
137 $htmlString .= '<option value="' . htmlspecialchars($idx)
138 . '" selected="selected">' . htmlspecialchars($key)
139 . '</option>';
143 $htmlString .= '</select>';
144 return $htmlString;
148 * Function to get html for date time columns
150 * @param array $keys keys
151 * @param array $fields_meta fields meta
153 * @return string
155 function PMA_getHtmlForDateTimeCols($keys, $fields_meta)
157 $htmlString = '<input type="hidden" name="dateTimeCols" value="';
159 $date_time_types = array('date', 'datetime', 'timestamp');
160 foreach ($keys as $idx => $key) {
161 if (in_array($fields_meta[$idx]->type, $date_time_types)) {
162 $htmlString .= $idx . " ";
165 $htmlString .= '" />';
167 return $htmlString;
171 * Function to get html for the table axis label options
173 * @param int $yaxis y axis
174 * @param array $keys keys
176 * @return string
178 function PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys)
180 $htmlString = '<div style="float:left; padding-left:40px;">'
181 . '<label for="xaxis_label">' . __('X-Axis label:') . '</label>'
182 . '<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"'
183 . ' value="'
184 . (($yaxis == -1) ? __('X Values') : htmlspecialchars($keys[$yaxis]))
185 . '" /><br />'
186 . '<label for="yaxis_label">' . __('Y-Axis label:') . '</label>'
187 . '<input type="text" name="yaxis_label" id="yaxis_label" value="'
188 . __('Y Values') . '" /><br />'
189 . '</div>';
191 return $htmlString;
195 * Function to get html for the start row and number of rows options
197 * @param string $sql_query sql query
199 * @return string
201 function PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query)
203 $htmlString = '<p style="clear:both;">&nbsp;</p>'
204 . '<fieldset>'
205 . '<div>'
206 . '<label for="pos">' . __('Start row:') . '</label>'
207 . '<input type="text" name="pos" size="3" value="'
208 . $_SESSION['tmpval']['pos'] . '" />'
209 . '<label for="session_max_rows">'
210 . __('Number of rows:') . '</label>'
211 . '<input type="text" name="session_max_rows" size="3" value="'
212 . (($_SESSION['tmpval']['max_rows'] != 'all')
213 ? $_SESSION['tmpval']['max_rows']
214 : $GLOBALS['cfg']['MaxRows'])
215 . '" />'
216 . '<input type="submit" name="submit" class="Go" value="' . __('Go')
217 . '" />'
218 . '<input type="hidden" name="sql_query" value="'
219 . htmlspecialchars($sql_query) . '" />'
220 . '</div>'
221 . '</fieldset>';
223 return $htmlString;
227 * Function to get html for the chart area div
229 * @return string
231 function PMA_getHtmlForChartAreaDiv()
233 $htmlString = '<p style="clear:both;">&nbsp;</p>'
234 . '<div id="resizer" style="width:600px; height:400px;">'
235 . '<div id="querychart">'
236 . '</div>'
237 . '</div>';
239 return $htmlString;
243 * Function to get html for displaying table chart
245 * @param string $url_query url query
246 * @param array $url_params url parameters
247 * @param array $keys keys
248 * @param array $fields_meta fields meta
249 * @param array $numeric_types numeric types
250 * @param int $numeric_column_count numeric column count
251 * @param string $sql_query sql query
253 * @return string
255 function PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys,
256 $fields_meta, $numeric_types, $numeric_column_count, $sql_query
258 // pma_token/url_query needed for chart export
259 $htmlString = PMA_getHtmlForPmaTokenAndUrlQuery($url_query);
260 $htmlString .= '<!-- Display Chart options -->'
261 . '<div id="div_view_options">'
262 . '<form method="post" id="tblchartform" action="tbl_chart.php" '
263 . 'class="ajax">'
264 . PMA_URL_getHiddenInputs($url_params)
265 . '<fieldset>'
266 . '<legend>' . __('Display chart') . '</legend>'
267 . '<div style="float:left; width:420px;">';
268 $htmlString .= PMA_getHtmlForChartTypeOptions();
269 $htmlString .= PMA_getHtmlForStackedOption();
271 $htmlString .= '<input type="text" name="chartTitle" value="'
272 . __('Chart title')
273 . '">'
274 . '</div>';
275 $yaxis = null;
276 $htmlString .= PMA_getHtmlForChartXAxisOptions($keys, $yaxis);
277 $htmlString .= PMA_getHtmlForChartSeriesOptions(
278 $keys, $fields_meta, $numeric_types, $yaxis, $numeric_column_count
280 $htmlString .= PMA_getHtmlForDateTimeCols($keys, $fields_meta);
281 $htmlString .= '</div>';
283 $htmlString .= PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys);
284 $htmlString .= PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query);
286 $htmlString .= PMA_getHtmlForChartAreaDiv();
288 $htmlString .= '</fieldset>'
289 . '</form>'
290 . '</div>';
292 return $htmlString;