tbl_chart.lib.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * functions for displaying chart
  5. *
  6. * @usedby tbl_chart.php
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. if (! defined('PHPMYADMIN')) {
  11. exit;
  12. }
  13. /**
  14. * Function to get html for pma_token and url_query
  15. *
  16. * @param string $url_query url query
  17. *
  18. * @return string
  19. */
  20. function PMA_getHtmlForPmaTokenAndUrlQuery($url_query)
  21. {
  22. $htmlString = '<script type="text/javascript">'
  23. . "pma_token = '" . $_SESSION[' PMA_token '] . "';"
  24. . "url_query = '" . $url_query . "';"
  25. . '</script>';
  26. return $htmlString;
  27. }
  28. /**
  29. * Function to get html for the chart type options
  30. *
  31. * @return string
  32. */
  33. function PMA_getHtmlForChartTypeOptions()
  34. {
  35. $html = '<input type="radio" name="chartType" value="bar" id="radio_bar" />'
  36. . '<label for ="radio_bar">' . _pgettext('Chart type', 'Bar') . '</label>'
  37. . '<input type="radio" name="chartType" value="column" id="radio_column" />'
  38. . '<label for ="radio_column">' . _pgettext('Chart type', 'Column')
  39. . '</label>'
  40. . '<input type="radio" name="chartType" value="line" id="radio_line"'
  41. . ' checked="checked" />'
  42. . '<label for ="radio_line">' . _pgettext('Chart type', 'Line') . '</label>'
  43. . '<input type="radio" name="chartType" value="spline" id="radio_spline" />'
  44. . '<label for ="radio_spline">' . _pgettext('Chart type', 'Spline')
  45. . '</label>'
  46. . '<input type="radio" name="chartType" value="area" id="radio_area" />'
  47. . '<label for ="radio_area">' . _pgettext('Chart type', 'Area') . '</label>'
  48. . '<span class="span_pie" style="display:none;">'
  49. . '<input type="radio" name="chartType" value="pie" id="radio_pie" />'
  50. . '<label for ="radio_pie">' . _pgettext('Chart type', 'Pie') . '</label>'
  51. . '</span>'
  52. . '<span class="span_timeline" style="display:none;">'
  53. . '<input type="radio" name="chartType" '
  54. . 'value="timeline" id="radio_timeline" />'
  55. . '<label for ="radio_timeline">' . _pgettext('Chart type', 'Timeline')
  56. . '</label>'
  57. . '</span>'
  58. . '<span class="span_scatter" style="display:none;">'
  59. . '<input type="radio" name="chartType" '
  60. . 'value="scatter" id="radio_scatter" />'
  61. . '<label for ="radio_scatter">' . _pgettext('Chart type', 'Scatter')
  62. . '</label>'
  63. . '</span>'
  64. . '<br /><br />';
  65. return $html;
  66. }
  67. /**
  68. * Function to get html for the bar stacked option
  69. *
  70. * @return string
  71. */
  72. function PMA_getHtmlForStackedOption()
  73. {
  74. $html = '<span class="barStacked" style="display:none;">'
  75. . '<input type="checkbox" name="barStacked" value="1"'
  76. . ' id="checkbox_barStacked" />'
  77. . '<label for ="checkbox_barStacked">' . __('Stacked') . '</label>'
  78. . '</span>'
  79. . '<br /><br />';
  80. return $html;
  81. }
  82. /**
  83. * Function to get html for the chart x axis options
  84. *
  85. * @param array $keys keys
  86. * @param int &$yaxis y axis
  87. *
  88. * @return string
  89. */
  90. function PMA_getHtmlForChartXAxisOptions($keys, &$yaxis)
  91. {
  92. $htmlString = '<div style="float:left; padding-left:40px;">'
  93. . '<label for="select_chartXAxis">' . __('X-Axis:') . '</label>'
  94. . '<select name="chartXAxis" id="select_chartXAxis">';
  95. foreach ($keys as $idx => $key) {
  96. if ($yaxis === null) {
  97. $htmlString .= '<option value="' . htmlspecialchars($idx)
  98. . '" selected="selected">' . htmlspecialchars($key) . '</option>';
  99. $yaxis = $idx;
  100. } else {
  101. $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
  102. . htmlspecialchars($key) . '</option>';
  103. }
  104. }
  105. $htmlString .= '</select>';
  106. return $htmlString;
  107. }
  108. /**
  109. * Function to get html for chart series options
  110. *
  111. * @param array $keys keys
  112. * @param array $fields_meta fields meta
  113. * @param array $numeric_types numeric types
  114. * @param int $yaxis y axis
  115. * @param int $numeric_column_count numeric column count
  116. *
  117. * @return string
  118. */
  119. function PMA_getHtmlForChartSeriesOptions($keys, $fields_meta, $numeric_types,
  120. $yaxis, $numeric_column_count
  121. ) {
  122. $htmlString = '<br />'
  123. . '<label for="select_chartSeries">' . __('Series:') . '</label>'
  124. . '<select name="chartSeries" id="select_chartSeries" multiple="multiple">';
  125. foreach ($keys as $idx => $key) {
  126. if (in_array($fields_meta[$idx]->type, $numeric_types)) {
  127. if ($idx == $yaxis && $numeric_column_count > 1) {
  128. $htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
  129. . htmlspecialchars($key) . '</option>';
  130. } else {
  131. $htmlString .= '<option value="' . htmlspecialchars($idx)
  132. . '" selected="selected">' . htmlspecialchars($key)
  133. . '</option>';
  134. }
  135. }
  136. }
  137. $htmlString .= '</select>';
  138. return $htmlString;
  139. }
  140. /**
  141. * Function to get html for date time columns
  142. *
  143. * @param array $keys keys
  144. * @param array $fields_meta fields meta
  145. *
  146. * @return string
  147. */
  148. function PMA_getHtmlForDateTimeCols($keys, $fields_meta)
  149. {
  150. $htmlString = '<input type="hidden" name="dateTimeCols" value="';
  151. $date_time_types = array('date', 'datetime', 'timestamp');
  152. foreach ($keys as $idx => $key) {
  153. if (in_array($fields_meta[$idx]->type, $date_time_types)) {
  154. $htmlString .= $idx . " ";
  155. }
  156. }
  157. $htmlString .= '" />';
  158. return $htmlString;
  159. }
  160. /**
  161. * Function to get html for date time columns
  162. *
  163. * @param array $keys keys
  164. * @param array $fields_meta fields meta
  165. * @param array $numeric_types numeric types
  166. *
  167. * @return string
  168. */
  169. function PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types)
  170. {
  171. $htmlString = '<input type="hidden" name="numericCols" value="';
  172. foreach ($keys as $idx => $key) {
  173. if (in_array($fields_meta[$idx]->type, $numeric_types)) {
  174. $htmlString .= $idx . " ";
  175. }
  176. }
  177. $htmlString .= '" />';
  178. return $htmlString;
  179. }
  180. /**
  181. * Function to get html for the table axis label options
  182. *
  183. * @param int $yaxis y axis
  184. * @param array $keys keys
  185. *
  186. * @return string
  187. */
  188. function PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys)
  189. {
  190. $htmlString = '<div style="float:left; padding-left:40px;">'
  191. . '<label for="xaxis_label">' . __('X-Axis label:') . '</label>'
  192. . '<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"'
  193. . ' value="'
  194. . (($yaxis == -1) ? __('X Values') : htmlspecialchars($keys[$yaxis]))
  195. . '" /><br />'
  196. . '<label for="yaxis_label">' . __('Y-Axis label:') . '</label>'
  197. . '<input type="text" name="yaxis_label" id="yaxis_label" value="'
  198. . __('Y Values') . '" /><br />'
  199. . '</div>';
  200. return $htmlString;
  201. }
  202. /**
  203. * Function to get html for the start row and number of rows options
  204. *
  205. * @param string $sql_query sql query
  206. *
  207. * @return string
  208. */
  209. function PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query)
  210. {
  211. $htmlString = '<p style="clear:both;">&nbsp;</p>'
  212. . '<fieldset>'
  213. . '<div>'
  214. . '<label for="pos">' . __('Start row:') . '</label>'
  215. . '<input type="text" name="pos" size="3" value="'
  216. . $_SESSION['tmpval']['pos'] . '" />'
  217. . '<label for="session_max_rows">'
  218. . __('Number of rows:') . '</label>'
  219. . '<input type="text" name="session_max_rows" size="3" value="'
  220. . (($_SESSION['tmpval']['max_rows'] != 'all')
  221. ? $_SESSION['tmpval']['max_rows']
  222. : $GLOBALS['cfg']['MaxRows'])
  223. . '" />'
  224. . '<input type="submit" name="submit" class="Go" value="' . __('Go')
  225. . '" />'
  226. . '<input type="hidden" name="sql_query" value="'
  227. . htmlspecialchars($sql_query) . '" />'
  228. . '</div>'
  229. . '</fieldset>';
  230. return $htmlString;
  231. }
  232. /**
  233. * Function to get html for the chart area div
  234. *
  235. * @return string
  236. */
  237. function PMA_getHtmlForChartAreaDiv()
  238. {
  239. $htmlString = '<p style="clear:both;">&nbsp;</p>'
  240. . '<div id="resizer" style="width:600px; height:400px;">'
  241. . '<div id="querychart">'
  242. . '</div>'
  243. . '</div>';
  244. return $htmlString;
  245. }
  246. /**
  247. * Function to get html for displaying table chart
  248. *
  249. * @param string $url_query url query
  250. * @param array $url_params url parameters
  251. * @param array $keys keys
  252. * @param array $fields_meta fields meta
  253. * @param array $numeric_types numeric types
  254. * @param int $numeric_column_count numeric column count
  255. * @param string $sql_query sql query
  256. *
  257. * @return string
  258. */
  259. function PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys,
  260. $fields_meta, $numeric_types, $numeric_column_count, $sql_query
  261. ) {
  262. // pma_token/url_query needed for chart export
  263. $htmlString = PMA_getHtmlForPmaTokenAndUrlQuery($url_query);
  264. $htmlString .= '<!-- Display Chart options -->'
  265. . '<div id="div_view_options">'
  266. . '<form method="post" id="tblchartform" action="tbl_chart.php" '
  267. . 'class="ajax">'
  268. . PMA_URL_getHiddenInputs($url_params)
  269. . '<fieldset>'
  270. . '<legend>' . __('Display chart') . '</legend>'
  271. . '<div style="float:left; width:420px;">';
  272. $htmlString .= PMA_getHtmlForChartTypeOptions();
  273. $htmlString .= PMA_getHtmlForStackedOption();
  274. $htmlString .= '<input type="text" name="chartTitle" value="'
  275. . __('Chart title')
  276. . '">'
  277. . '</div>';
  278. $yaxis = null;
  279. $htmlString .= PMA_getHtmlForChartXAxisOptions($keys, $yaxis);
  280. $htmlString .= PMA_getHtmlForChartSeriesOptions(
  281. $keys, $fields_meta, $numeric_types, $yaxis, $numeric_column_count
  282. );
  283. $htmlString .= PMA_getHtmlForDateTimeCols($keys, $fields_meta);
  284. $htmlString .= PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types);
  285. $htmlString .= '</div>';
  286. $htmlString .= PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys);
  287. $htmlString .= PMA_getHtmlForStartAndNumberOfRowsOptions($sql_query);
  288. $htmlString .= PMA_getHtmlForChartAreaDiv();
  289. $htmlString .= '</fieldset>'
  290. . '</form>'
  291. . '</div>';
  292. return $htmlString;
  293. }
  294. ?>