/oscommerce2-mypgsql/catalog/admin/includes/functions/html_graphs.php

https://github.com/shooray/oscommerce2-mypgsql · PHP · 568 lines · 400 code · 104 blank · 64 comment · 81 complexity · 3881520d9aff25deb37021e979d42ccf MD5 · raw file

  1. <?php
  2. /*
  3. $Id$
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2002 osCommerce
  7. Released under the GNU General Public License
  8. HTML_Graphs (v1.5 1998/11/05 06:15:52) by Phil Davis, http://www.pobox.com/~pdavis/
  9. */
  10. ////
  11. // calls routines to initialize defaults, set up table
  12. // print data, and close table.
  13. function html_graph($names, $values, $bars, $vals, $dvalues = 0, $dbars = 0) {
  14. // set the error level on entry and exit so as not to interfear with anyone elses error checking.
  15. $er = error_reporting(1);
  16. // set the values that the user didn't
  17. $vals = hv_graph_defaults($vals);
  18. $html_graph_string = start_graph($vals, $names);
  19. if ($vals['type'] == 0) {
  20. $html_graph_string .= horizontal_graph($names, $values, $bars, $vals);
  21. } elseif ($vals['type'] == 1) {
  22. $html_graph_string .= vertical_graph($names, $values, $bars, $vals);
  23. } elseif ($vals['type'] == 2) {
  24. $html_graph_string .= double_horizontal_graph($names, $values, $bars, $vals, $dvalues, $dbars);
  25. } elseif ($vals['type'] == 3) {
  26. $html_graph_string .= double_vertical_graph($names, $values, $bars, $vals, $dvalues, $dbars);
  27. }
  28. $html_graph_string .= end_graph();
  29. // Set the error level back to where it was.
  30. error_reporting($er);
  31. return $html_graph_string;
  32. }
  33. ////
  34. // sets up the $vals array by initializing all values to null. Used to avoid
  35. // warnings from error_reporting being set high. This routine only needs to be
  36. // called if you are worried about using uninitialized variables.
  37. function html_graph_init() {
  38. $vals = array('vlabel'=>'',
  39. 'hlabel'=>'',
  40. 'type'=>'',
  41. 'cellpadding'=>'',
  42. 'cellspacing'=>'',
  43. 'border'=>'',
  44. 'width'=>'',
  45. 'background'=>'',
  46. 'vfcolor'=>'',
  47. 'hfcolor'=>'',
  48. 'vbgcolor'=>'',
  49. 'hbgcolor'=>'',
  50. 'vfstyle'=>'',
  51. 'hfstyle'=>'',
  52. 'noshowvals'=>'',
  53. 'scale'=>'',
  54. 'namebgcolor'=>'',
  55. 'valuebgcolor'=>'',
  56. 'namefcolor'=>'',
  57. 'valuefcolor'=>'',
  58. 'namefstyle'=>'',
  59. 'valuefstyle'=>'',
  60. 'doublefcolor'=>'');
  61. return($vals);
  62. }
  63. ////
  64. // prints out the table header and graph labels
  65. function start_graph($vals, $names) {
  66. $start_graph_string = '<table cellpadding="' . $vals['cellpadding'] . '" cellspacing="' . $vals['cellspacing'] . '" border="' . $vals['border'] . '"';
  67. if ($vals['width'] != 0) $start_graph_string .= ' width="' . $vals['width'] . '"';
  68. if ($vals['background']) $start_graph_string .= ' background="' . $vals['background'] . '"';
  69. $start_graph_string .= '>' . "\n";
  70. if ( ($vals['vlabel']) || ($vals['hlabel']) ) {
  71. if ( ($vals['type'] == 0) || ($vals['type'] == 2) ) {
  72. // horizontal chart
  73. $rowspan = sizeof($names) + 1;
  74. $colspan = 3;
  75. } elseif ( ($vals['type'] == 1) || ($vals['type'] == 3) ) {
  76. // vertical chart
  77. $rowspan = 3;
  78. $colspan = sizeof($names) + 1;
  79. }
  80. $start_graph_string .= ' <tr>' . "\n" .
  81. ' <td align="center" valign="center"';
  82. // if a background was choosen don't print cell BGCOLOR
  83. if (!$vals['background']) $start_graph_string .= ' bgcolor="' . $vals['hbgcolor'] . '"';
  84. $start_graph_string .= ' colspan="' . $colspan . '"><font color="' . $vals['hfcolor'] . '" style="' . $vals['hfstyle'] . '"><strong>' . $vals['hlabel'] . '</strong></font></td>' . "\n" .
  85. ' </tr>' . "\n" .
  86. ' <tr>' . "\n" .
  87. ' <td align="center" valign="center"';
  88. // if a background was choosen don't print cell BGCOLOR
  89. if (!$vals['background']) $start_graph_string .= ' bgcolor="' . $vals['vbgcolor'] . '"';
  90. $start_graph_string .= ' rowspan="' . $rowspan . '"><font color="' . $vals['vfcolor'] . '" style="' . $vals['vfstyle'] . '"><strong>' . $vals['vlabel'] . '</strong></font></td>' . "\n" .
  91. ' </tr>' . "\n";
  92. }
  93. return $start_graph_string;
  94. }
  95. ////
  96. // prints out the table footer
  97. function end_graph() {
  98. return '</table>' . "\n";
  99. }
  100. ////
  101. // sets the default values for the $vals array
  102. function hv_graph_defaults($vals) {
  103. if (!$vals['vfcolor']) $vals['vfcolor'] = '#000000';
  104. if (!$vals['hfcolor']) $vals['hfcolor'] = '#000000';
  105. if (!$vals['vbgcolor']) $vals['vbgcolor'] = '#FFFFFF';
  106. if (!$vals['hbgcolor']) $vals['hbgcolor'] = '#FFFFFF';
  107. if (!$vals['cellpadding']) $vals['cellpadding'] = '0';
  108. if (!$vals['cellspacing']) $vals['cellspacing'] = '0';
  109. if (!$vals['border']) $vals['border'] = '0';
  110. if (!$vals['scale']) $vals['scale'] = '1';
  111. if (!$vals['namebgcolor']) $vals['namebgcolor'] = '#FFFFFF';
  112. if (!$vals['valuebgcolor']) $vals['valuebgcolor'] = '#FFFFFF';
  113. if (!$vals['namefcolor']) $vals['namefcolor'] = '#000000';
  114. if (!$vals['valuefcolor']) $vals['valuefcolor'] = '#000000';
  115. if (!$vals['doublefcolor']) $vals['doublefcolor'] = '#886666';
  116. return $vals;
  117. }
  118. ////
  119. // prints out the actual data for the horizontal chart
  120. function horizontal_graph($names, $values, $bars, $vals) {
  121. $horizontal_graph_string = '';
  122. for($i = 0, $n = sizeof($values); $i < $n; $i++) {
  123. $horizontal_graph_string .= ' <tr>' . "\n" .
  124. ' <td align="right"';
  125. // if a background was choosen don't print cell BGCOLOR
  126. if (!$vals['background']) $horizontal_graph_string .= ' bgcolor="' . $vals['namebgcolor'] . '"';
  127. $horizontal_graph_string .= '><font size="-1" color="' . $vals['namefcolor'] . '" style="' . $vals['namefstyle'] . '">' . $names[$i] . '</font></td>' . "\n" .
  128. ' <td';
  129. // if a background was choosen don't print cell BGCOLOR
  130. if (!$vals['background']) $horizontal_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  131. $horizontal_graph_string .= '>';
  132. // decide if the value in bar is a color code or image.
  133. if (preg_match('/^#/', $bars[$i])) {
  134. $horizontal_graph_string .= '<table cellpadding="0" cellspacing="0" bgcolor="' . $bars[$i] . '" width="' . ($values[$i] * $vals['scale']) . '">' . "\n" .
  135. ' <tr>' . "\n" .
  136. ' <td>&nbsp;</td>' . "\n" .
  137. ' </tr>' . "\n" .
  138. '</table>';
  139. } else {
  140. $horizontal_graph_string .= '<img src="' . $bars[$i] . '" height="10" width="' . ($values[$i] * $vals['scale']) . '">';
  141. }
  142. if (!$vals['noshowvals']) {
  143. $horizontal_graph_string .= '<i><font size="-2" color="' . $vals['valuefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $values[$i] . ')</font></i>';
  144. }
  145. $horizontal_graph_string .= '</td>' . "\n" .
  146. ' </tr>' . "\n";
  147. } // endfor
  148. return $horizontal_graph_string;
  149. }
  150. ////
  151. // prints out the actual data for the vertical chart
  152. function vertical_graph($names, $values, $bars, $vals) {
  153. $vertical_graph_string = ' <tr>' . "\n";
  154. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  155. $vertical_graph_string .= ' <td align="center" valign="bottom"';
  156. // if a background was choosen don't print cell BGCOLOR
  157. if (!$vals['background']) $vertical_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  158. $vertical_graph_string .= '>';
  159. if (!$vals['noshowvals']) {
  160. $vertical_graph_string .= '<i><font size="-2" color="' . $vals['valuefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $values[$i] . ')</font></i><br />';
  161. }
  162. $vertical_graph_string .= '<img src="' . $bars[$i] . '" width="5" height="';
  163. // values of zero are displayed wrong because a image height of zero
  164. // gives a strange behavior in Netscape. For this reason the height
  165. // is set at 1 pixel if the value is zero. - Jan Diepens
  166. if ($values[$i] != 0) {
  167. $vertical_graph_string .= $values[$i] * $vals['scale'];
  168. } else {
  169. $vertical_graph_string .= '1';
  170. }
  171. $vertical_graph_string .= '"></td>' . "\n";
  172. } // endfor
  173. $vertical_graph_string .= ' </tr>' . "\n" .
  174. ' <tr>' . "\n";
  175. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  176. $vertical_graph_string .= ' <td align="center" valign="top"';
  177. // if a background was choosen don't print cell BGCOLOR
  178. if (!$vals['background']) $vertical_graph_string .= ' bgcolor="' . $vals['namebgcolor'] . '"';
  179. $vertical_graph_string .= '><font size="-1" color="' . $vals['namefcolor'] . '" style="' . $vals['namefstyle'] . '">' . $names[$i] . '</font></td>' . "\n";
  180. } // endfor
  181. $vertical_graph_string .= ' </tr>' . "\n";
  182. return $vertical_graph_string;
  183. }
  184. ////
  185. // prints out the actual data for the double horizontal chart
  186. function double_horizontal_graph($names, $values, $bars, $vals, $dvalues, $dbars) {
  187. $double_horizontal_graph_string = '';
  188. for($i = 0, $n = sizeof($values); $i < $n; $i++) {
  189. $double_horizontal_graph_string .= ' <tr>' . "\n" .
  190. ' <td align="right"';
  191. // if a background was choosen don't print cell BGCOLOR
  192. if (!$vals['background']) $double_horizontal_graph_string .= ' bgcolor="' . $vals['namebgcolor'] . '"';
  193. $double_horizontal_graph_string .= '><font size="-1" color="' . $vals['namefcolor'] . '" style="' . $vals['namefstyle'] . '">' . $names[$i] . '</font></td>' . "\n" .
  194. ' <td';
  195. // if a background was choosen don't print cell BGCOLOR
  196. if (!$vals['background']) $double_horizontal_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  197. $double_horizontal_graph_string .= '><table align="left" cellpadding="0" cellspacing="0" width="' . ($dvalues[$i] * $vals['scale']) . '">' . "\n" .
  198. ' <tr>' . "\n" .
  199. ' <td';
  200. // set background to a color if it starts with # or an image otherwise.
  201. if (preg_match('/^#/', $dbars[$i])) {
  202. $double_horizontal_graph_string .= ' bgcolor="' . $dbars[$i] . '">';
  203. } else {
  204. $double_horizontal_graph_string .= ' background="' . $dbars[$i] . '">';
  205. }
  206. $double_horizontal_graph_string .= '<nowrap>';
  207. // decide if the value in bar is a color code or image.
  208. if (preg_match('/^#/', $bars[$i])) {
  209. $double_horizontal_graph_string .= '<table align="left" cellpadding="0" cellspacing="0" bgcolor="' . $bars[$i] . '" width="' . ($values[$i] * $vals['scale']) . '">' . "\n" .
  210. ' <tr>' . "\n" .
  211. ' <td>&nbsp;</td>' . "\n" .
  212. ' </tr>' . "\n" .
  213. '</table>';
  214. } else {
  215. $double_horizontal_graph_string .= '<img src="' . $bars[$i] . '" height="10" width="' . ($values[$i] * $vals['scale']) . '">';
  216. }
  217. if (!$vals['noshowvals']) {
  218. $double_horizontal_graph_string .= '<i><font size="-3" color="' . $vals['valuefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $values[$i] . ')</font></i>';
  219. }
  220. $double_horizontal_graph_string .= '</nowrap></td>' . "\n" .
  221. ' </tr>' . "\n" .
  222. ' </table>';
  223. if (!$vals['noshowvals']) {
  224. $double_horizontal_graph_string .= '<i><font size="-3" color="' . $vals['doublefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $dvalues[$i] . ')</font></i>';
  225. }
  226. $double_horizontal_graph_string .= '</td>' . "\n" .
  227. ' </tr>' . "\n";
  228. } // endfor
  229. return $double_horizontal_graph_string;
  230. }
  231. ////
  232. // prints out the actual data for the double vertical chart
  233. function double_vertical_graph($names, $values, $bars, $vals, $dvalues, $dbars) {
  234. $double_vertical_graph_string = ' <tr>' . "\n";
  235. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  236. $double_vertical_graph_string .= ' <td align="center" valign="bottom"';
  237. // if a background was choosen don't print cell BGCOLOR
  238. if (!$vals['background']) $double_vertical_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  239. $double_vertical_graph_string .= '><table>' . "\n" .
  240. ' <tr>' . "\n" .
  241. ' <td align="center" valign="bottom"';
  242. // if a background was choosen don't print cell BGCOLOR
  243. if (!$vals['background']) $double_vertical_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  244. $double_vertical_graph_string .= '>';
  245. if (!$vals['noshowvals'] && $values[$i]) {
  246. $double_vertical_graph_string .= '<i><font size="-2" color="' . $vals['valuefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $values[$i] . ')</font></i><br />';
  247. }
  248. $double_vertical_graph_string .= '<img src="' . $bars[$i] . '" width="10" height="';
  249. if ($values[$i] != 0) {
  250. $double_vertical_graph_string .= $values[$i] * $vals['scale'];
  251. } else {
  252. $double_vertical_graph_string .= '1';
  253. }
  254. $double_vertical_graph_string .= '"></td>' . "\n" .
  255. ' <td align="center" valign="bottom"';
  256. // if a background was choosen don't print cell BGCOLOR
  257. if (!$vals['background']) $double_vertical_graph_string .= ' bgcolor="' . $vals['valuebgcolor'] . '"';
  258. $double_vertical_graph_string .= '>';
  259. if (!$vals['noshowvals'] && $dvalues[$i]) {
  260. $double_vertical_graph_string .= '<i><font size="-2" color="' . $vals['doublefcolor'] . '" style="' . $vals['valuefstyle'] . '">(' . $dvalues[$i] . ')</font></i><br />';
  261. }
  262. $double_vertical_graph_string .= '<img src="' . $dbars[$i] . '" width="10" height="';
  263. if ($dvalues[$i] != 0) {
  264. $double_vertical_graph_string .= $dvalues[$i] * $vals['scale'];
  265. } else {
  266. $double_vertical_graph_string .= '1';
  267. }
  268. $double_vertical_graph_string .= '"></td>' . "\n" .
  269. ' </tr>' . "\n" .
  270. ' </table></td>' . "\n";
  271. } // endfor
  272. $double_vertical_graph_string .= ' </tr>' . "\n" .
  273. ' <tr>' . "\n";
  274. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  275. $double_vertical_graph_string .= ' <td align="center" valign="top"';
  276. // if a background was choosen don't print cell BGCOLOR
  277. if (!$vals['background']) $double_vertical_graph_string .= ' bgcolor="' . $vals['namebgcolor'] . '"';
  278. $double_vertical_graph_string .= '><font size="-1" color="' . $vals['namefcolor'] . '" style="' . $vals['namefstyle'] . '">' . $names[$i] . '</font></td>' . "\n";
  279. } // endfor
  280. $double_vertical_graph_string .= ' </tr>' . "\n";
  281. return $double_vertical_graph_string;
  282. }
  283. ////
  284. // draws a double vertical bar graph for the banner views vs clicks statistics
  285. function tep_banner_graph_infoBox($banner_id, $days) {
  286. $names = array();
  287. $values = array();
  288. $dvalues = array();
  289. $banner_stats_query = tep_db_query("select dayofmonth(banners_history_date) as name, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and to_days(now()) - to_days(banners_history_date) < " . $days . " order by banners_history_date");
  290. while ($banner_stats = tep_db_fetch_array($banner_stats_query)) {
  291. $names[] = $banner_stats['name'];
  292. $values[] = $banner_stats['value'];
  293. $dvalues[] = $banner_stats['dvalue'];
  294. }
  295. $largest = @max($values);
  296. $bars = array();
  297. $dbars = array();
  298. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  299. $bars[$i] = DIR_WS_IMAGES . 'graph_hbar_blue.gif';
  300. $dbars[$i] = DIR_WS_IMAGES . 'graph_hbar_red.gif';
  301. }
  302. $graph_vals = @array('vlabel'=>TEXT_BANNERS_DATA,
  303. 'hlabel'=>TEXT_BANNERS_LAST_3_DAYS,
  304. 'type'=>'3',
  305. 'cellpadding'=>'',
  306. 'cellspacing'=>'1',
  307. 'border'=>'',
  308. 'width'=>'',
  309. 'vfcolor'=>'#ffffff',
  310. 'hfcolor'=>'#ffffff',
  311. 'vbgcolor'=>'#81a2b6',
  312. 'hbgcolor'=>'#81a2b6',
  313. 'vfstyle'=>'Verdana, Arial, Helvetica',
  314. 'hfstyle'=>'Verdana, Arial, Helvetica',
  315. 'scale'=>100/$largest,
  316. 'namebgcolor'=>'#f3f5fe',
  317. 'valuebgcolor'=>'#f3f5fe',
  318. 'namefcolor'=>'',
  319. 'valuefcolor'=>'#0000d0',
  320. 'namefstyle'=>'Verdana, Arial, Helvetica',
  321. 'valuefstyle'=>'',
  322. 'doublefcolor'=>'#ff7339');
  323. return html_graph($names, $values, $bars, $graph_vals, $dvalues, $dbars);
  324. }
  325. ////
  326. // draws a double vertical bar graph for the banner views vs clicks statistics
  327. function tep_banner_graph_yearly($banner_id) {
  328. global $banner, $HTTP_GET_VARS;
  329. $banner_stats_query = tep_db_query("select year(banners_history_date) as year, sum(banners_shown) as value, sum(banners_clicked) as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' group by year(banners_history_date)");
  330. while ($banner_stats = tep_db_fetch_array($banner_stats_query)) {
  331. $names[] = $banner_stats['year'];
  332. $values[] = (($banner_stats['value']) ? $banner_stats['value'] : '0');
  333. $dvalues[] = (($banner_stats['dvalue']) ? $banner_stats['dvalue'] : '0');
  334. }
  335. $largest = @max($values);
  336. $bars = array();
  337. $dbars = array();
  338. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  339. $bars[$i] = DIR_WS_IMAGES . 'graph_hbar_blue.gif';
  340. $dbars[$i] = DIR_WS_IMAGES . 'graph_hbar_red.gif';
  341. }
  342. $graph_vals = @array('vlabel'=>TEXT_BANNERS_DATA,
  343. 'hlabel'=>sprintf(TEXT_BANNERS_YEARLY_STATISTICS, $banner['banners_title']),
  344. 'type'=>'3',
  345. 'cellpadding'=>'',
  346. 'cellspacing'=>'1',
  347. 'border'=>'',
  348. 'width'=>'',
  349. 'vfcolor'=>'#ffffff',
  350. 'hfcolor'=>'#ffffff',
  351. 'vbgcolor'=>'#81a2b6',
  352. 'hbgcolor'=>'#81a2b6',
  353. 'vfstyle'=>'Verdana, Arial, Helvetica',
  354. 'hfstyle'=>'Verdana, Arial, Helvetica',
  355. 'scale'=>100/$largest,
  356. 'namebgcolor'=>'#f3f5fe',
  357. 'valuebgcolor'=>'#f3f5fe',
  358. 'namefcolor'=>'',
  359. 'valuefcolor'=>'#0000d0',
  360. 'namefstyle'=>'Verdana, Arial, Helvetica',
  361. 'valuefstyle'=>'',
  362. 'doublefcolor'=>'#ff7339');
  363. return html_graph($names, $values, $bars, $graph_vals, $dvalues, $dbars);
  364. }
  365. ////
  366. // draws a double vertical bar graph for the banner views vs clicks statistics
  367. function tep_banner_graph_monthly($banner_id) {
  368. global $banner, $HTTP_GET_VARS;
  369. $year = (($HTTP_GET_VARS['year']) ? $HTTP_GET_VARS['year'] : date('Y'));
  370. for ($i=1; $i<13; $i++) {
  371. $names[] = strftime('%b', mktime(0,0,0,$i));
  372. $values[] = '0';
  373. $dvalues[] = '0';
  374. }
  375. $banner_stats_query = tep_db_query("select month(banners_history_date) as banner_month, sum(banners_shown) as value, sum(banners_clicked) as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and year(banners_history_date) = '" . $year . "' group by month(banners_history_date)");
  376. while ($banner_stats = tep_db_fetch_array($banner_stats_query)) {
  377. $names[($banner_stats['banner_month']-1)] = strftime('%b', mktime(0,0,0,$banner_stats['banner_month']));
  378. $values[($banner_stats['banner_month']-1)] = (($banner_stats['value']) ? $banner_stats['value'] : '0');
  379. $dvalues[($banner_stats['banner_month']-1)] = (($banner_stats['dvalue']) ? $banner_stats['dvalue'] : '0');
  380. }
  381. $largest = @max($values);
  382. $bars = array();
  383. $dbars = array();
  384. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  385. $bars[$i] = DIR_WS_IMAGES . 'graph_hbar_blue.gif';
  386. $dbars[$i] = DIR_WS_IMAGES . 'graph_hbar_red.gif';
  387. }
  388. $graph_vals = @array('vlabel'=>TEXT_BANNERS_DATA,
  389. 'hlabel'=>sprintf(TEXT_BANNERS_MONTHLY_STATISTICS, $banner['banners_title'], date('Y')),
  390. 'type'=>'3',
  391. 'cellpadding'=>'',
  392. 'cellspacing'=>'1',
  393. 'border'=>'',
  394. 'width'=>'',
  395. 'vfcolor'=>'#ffffff',
  396. 'hfcolor'=>'#ffffff',
  397. 'vbgcolor'=>'#81a2b6',
  398. 'hbgcolor'=>'#81a2b6',
  399. 'vfstyle'=>'Verdana, Arial, Helvetica',
  400. 'hfstyle'=>'Verdana, Arial, Helvetica',
  401. 'scale'=>100/$largest,
  402. 'namebgcolor'=>'#f3f5fe',
  403. 'valuebgcolor'=>'#f3f5fe',
  404. 'namefcolor'=>'',
  405. 'valuefcolor'=>'#0000d0',
  406. 'namefstyle'=>'Verdana, Arial, Helvetica',
  407. 'valuefstyle'=>'',
  408. 'doublefcolor'=>'#ff7339');
  409. return html_graph($names, $values, $bars, $graph_vals, $dvalues, $dbars);
  410. }
  411. ////
  412. // draws a double vertical bar graph for the banner views vs clicks statistics
  413. function tep_banner_graph_daily($banner_id) {
  414. global $banner, $HTTP_GET_VARS;
  415. $year = (isset($HTTP_GET_VARS['year']) ? $HTTP_GET_VARS['year'] : date('Y'));
  416. $month = (isset($HTTP_GET_VARS['month']) ? $HTTP_GET_VARS['month'] : date('n'));
  417. $days = (date('t', mktime(0,0,0,$month))+1);
  418. $stats = array();
  419. for ($i=1; $i<$days; $i++) {
  420. $names[] = $i;
  421. $values[] = '0';
  422. $dvalues[] = '0';
  423. }
  424. $banner_stats_query = tep_db_query("select dayofmonth(banners_history_date) as banner_day, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and month(banners_history_date) = '" . $month . "' and year(banners_history_date) = '" . $year . "'");
  425. while ($banner_stats = tep_db_fetch_array($banner_stats_query)) {
  426. $names[($banner_stats['banner_day']-1)] = $banner_stats['banner_day'];
  427. $values[($banner_stats['banner_day']-1)] = (($banner_stats['value']) ? $banner_stats['value'] : '0');
  428. $dvalues[($banner_stats['banner_day']-1)] = (($banner_stats['dvalue']) ? $banner_stats['dvalue'] : '0');
  429. }
  430. $largest = @max($values);
  431. $bars = array();
  432. $dbars = array();
  433. for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
  434. $bars[$i] = DIR_WS_IMAGES . 'graph_hbar_blue.gif';
  435. $dbars[$i] = DIR_WS_IMAGES . 'graph_hbar_red.gif';
  436. }
  437. $graph_vals = @array('vlabel'=>TEXT_BANNERS_DATA,
  438. 'hlabel'=>sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0,0,0,$month)), $year),
  439. 'type'=>'3',
  440. 'cellpadding'=>'',
  441. 'cellspacing'=>'1',
  442. 'border'=>'',
  443. 'width'=>'',
  444. 'vfcolor'=>'#ffffff',
  445. 'hfcolor'=>'#ffffff',
  446. 'vbgcolor'=>'#81a2b6',
  447. 'hbgcolor'=>'#81a2b6',
  448. 'vfstyle'=>'Verdana, Arial, Helvetica',
  449. 'hfstyle'=>'Verdana, Arial, Helvetica',
  450. 'scale'=>100/$largest,
  451. 'namebgcolor'=>'#f3f5fe',
  452. 'valuebgcolor'=>'#f3f5fe',
  453. 'namefcolor'=>'',
  454. 'valuefcolor'=>'#0000d0',
  455. 'namefstyle'=>'Verdana, Arial, Helvetica',
  456. 'valuefstyle'=>'',
  457. 'doublefcolor'=>'#ff7339');
  458. return html_graph($names, $values, $bars, $graph_vals, $dvalues, $dbars);
  459. }
  460. ?>