PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/RGrid/example5.php

http://cartonbank.googlecode.com/
PHP | 213 lines | 106 code | 33 blank | 74 comment | 1 complexity | 78ca5bc697438db2bab0a5191ebab8d6 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. /**
  3. * o------------------------------------------------------------------------------o
  4. * | This package is licensed under the Phpguru license. A quick summary is |
  5. * | that for commercial use, there is a small one-time licensing fee to pay. For |
  6. * | registered charities and educational institutes there is a reduced license |
  7. * | fee available. You can read more at: |
  8. * | |
  9. * | http://www.phpguru.org/static/license.html |
  10. * o------------------------------------------------------------------------------o
  11. *
  12. * Š Copyright 2008,2009 Richard Heyes
  13. */
  14. /**
  15. * This an example script that uses the datagrid and shows it off
  16. */
  17. /**
  18. * Include the datagrid code
  19. */
  20. require_once('RGrid.php');
  21. $params['hostname'] = 'localhost';
  22. $params['username'] = 'datagrid';
  23. $params['password'] = 'datagrid';
  24. $params['database'] = 'phpguru';
  25. $sql = "SELECT cm_id,
  26. ne_title,
  27. cm_author,
  28. cm_datetime,
  29. cm_status,
  30. cm_neid
  31. FROM comments,
  32. news
  33. WHERE cm_status = 'ACTIVE'
  34. AND cm_neid = ne_id
  35. ORDER BY cm_id DESC";
  36. /**
  37. * Create the datagrid with the connection parameters and SQL query
  38. * defined above. You MUST specify an ORDER BY
  39. * clause (with ASC/DESC direction indicator) - if not then ordering
  40. * will be fubar. I will eventually fix this so that the headers
  41. * aren't clickable if you don't supply an ORDER BY, for the time
  42. * being just specify an ORDER BY clause (the one you specify will
  43. * be used by default).
  44. */
  45. $grid = RGrid::Create($params, $sql);
  46. /**
  47. * Disable sorting
  48. */
  49. $grid->allowSorting = false;
  50. /**
  51. * Turn the column headers off/on
  52. */
  53. $grid->showHeaders = true;
  54. /**
  55. * Sets nice(r) display names instead of the raw column names
  56. */
  57. $grid->SetDisplayNames(array('cm_id' => 'ID',
  58. 'ne_title' => 'Title',
  59. 'cm_author' => 'Author',
  60. 'cm_email' => 'Email',
  61. 'cm_datetime' => 'Date & time',
  62. 'cm_status' => 'Status'));
  63. /**
  64. * This simply sets the specified columns not to be passed through htmlspecialchars()
  65. * Generally any column that shows HTML
  66. */
  67. $grid->NoSpecialChars('ne_title', 'status', 'actions');
  68. /**
  69. * Hide the cm_neid column as it's only used for linking purposes
  70. */
  71. $grid->HideColumn('cm_neid', 'cm_status');
  72. /**
  73. * Here just for show. This function sets the number of rows to set per page.
  74. * The default is 20.
  75. */
  76. $grid->SetPerPage(15);
  77. /**
  78. * The callback function that adds the extra column
  79. */
  80. $grid->AddCallback('RowCallback');
  81. function RowCallback(&$row)
  82. {
  83. $row['actions'] = sprintf('<a href="http://www.phpguru.org/article.php/%d#comment_%d" target="_blank">View</a>', $row['cm_neid'], $row['cm_id']);
  84. $length = 25;
  85. if (strlen($row['ne_title']) > $length) {
  86. $row['ne_title'] = substr($row['ne_title'],0, 25) . '...';
  87. }
  88. $row['ne_title'] = sprintf('<a href="/article.php/%d" target="_blank" title="%s">%s</a>', $row['cm_neid'], $row['ne_title'], $row['ne_title']);
  89. // Format the datetime field. We do it here so that ordering is OK
  90. $row['cm_datetime'] = date('H:i jS F Y', strtotime($row['cm_datetime']));
  91. }
  92. /**
  93. * The HTML. The appearance can be customised using CSS. Naturally you would (should) put
  94. * all of the datagrid styling in a central CSS file that can be <link>ed to by all of
  95. * your websites' pages. That way:
  96. * o All of your datagrids will look the same
  97. * o Changes to the appearance will affect all of your datagrids across your
  98. * entire website. You might not want this necessarily, but might.
  99. *
  100. * eg. <link rel="stylesheet" type="text/css" media="screen" href="/css/datagrid.css" />
  101. */
  102. ?>
  103. <html>
  104. <head>
  105. <title>Datagrid example</title>
  106. <style type="text/css">
  107. <!--
  108. /* Format the page */
  109. body {
  110. background-color: #eee;
  111. }
  112. /* Format the entire table */
  113. .datagrid {
  114. font-family: Arial;
  115. font-size: smaller;
  116. width: 600px;
  117. }
  118. /* Format the table headers */
  119. .datagrid thead th {
  120. background-color: #003;
  121. color: #fff;
  122. height: 25px;
  123. text-align: left;
  124. }
  125. /* Colour the headers white */
  126. .datagrid thead th a {
  127. color: white;
  128. text-decoration: none;
  129. }
  130. /* Padding on headers and body cells */
  131. .datagrid thead th,
  132. .datagrid tbody td {
  133. padding-left: 5px;
  134. padding-right: 5px;
  135. }
  136. /* Row colours */
  137. .datagrid tbody td.col_0,
  138. .datagrid tbody td.col_2 {
  139. background-color: #fff;
  140. }
  141. /* Alternate row colours */
  142. .datagrid tbody td.col_1,
  143. .datagrid tbody td.col_3 {
  144. background-color: #cff;
  145. }
  146. /* Show the left hand border on all table cells */
  147. .datagrid tbody td {
  148. border-left: 1px solid #6c9;
  149. }
  150. /* Don't show the left border on the last column... */
  151. .datagrid tbody td.col_4 {
  152. border-left: 0;
  153. }
  154. /* ...show the right border on the next to last column */
  155. .datagrid tbody td.col_3 {
  156. border-right: 1px solid #6c9;
  157. }
  158. /* Show the bottom border */
  159. .datagrid tbody td.row_14 {
  160. border-bottom: 1px solid #6c9;
  161. }
  162. /* No underline for the view links */
  163. .datagrid tbody td.row_14 {
  164. border-bottom: 1px solid #6c9;
  165. }
  166. .datagrid tbody td.col_1 a,
  167. .datagrid tbody td.col_4 a {
  168. text-decoration: none;
  169. }
  170. .datagrid tbody td.col_4 {
  171. border-bottom: 0;
  172. }
  173. // -->
  174. </style>
  175. </head>
  176. <body>
  177. <h1>Example 5</h1>
  178. <?php $grid->Display() ?>
  179. </body>
  180. </html>