PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Helios Engine/helios/renderers/xtable.php

https://code.google.com/p/prjtest00/
PHP | 281 lines | 252 code | 15 blank | 14 comment | 26 complexity | 72a9276b26919edeb86d2a15af6bbe54 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. <?php
  2. class XTable {
  3. // Variable Table
  4. public $conf = NULL; // Configuration variable
  5. public $result = NULL; // Result storage.
  6. public function __construct($id,$IO,$params) {
  7. // Pass required variables:
  8. $this->conf["id"] = $id;
  9. if ($IO === SQL) {
  10. // Validate Pool
  11. $config = $GLOBALS["SQL"]->config;
  12. foreach ($config["databases"] as $database) {
  13. if ($params === $database[0])
  14. {
  15. $valid = TRUE;
  16. $params = $database[1];
  17. }
  18. }
  19. if (!$valid) {
  20. echo "<p>Invalid Pool selected.</p>";
  21. return -1;
  22. } else {
  23. }
  24. $this->conf["pool"] = $params;
  25. }
  26. require_once "functions/xhmlentities.php";
  27. }
  28. // Load a query:
  29. public function query($query) {
  30. $qid = $GLOBALS["SQL"]->query($this->conf["pool"],FE,$query);
  31. if ($qid < 0) {
  32. echo "<p> Xtable: An error occured. Check the logs! </p>";
  33. return -1;
  34. } else {
  35. $this->conf["query"] = $qid;
  36. }}
  37. // Set Table CSS information
  38. public function SetProperties($class,$style,$labels) {
  39. $this->conf["class"] = $class;
  40. $this->conf["style"] = $style;
  41. $this->conf["labels"] = $labels;
  42. $this->conf["counter"] = 0;
  43. $this->conf["ncounter"] = 0;
  44. }
  45. // Add a Behaviour:
  46. public function AddBehaviour($behaviour) {
  47. $this->conf["behaviour"] = $behaviour;
  48. }
  49. // Add Extra row:
  50. public function AddExtra($behaviour) {
  51. $this->conf["extrafunc"][] = $behaviour;
  52. }
  53. // Add form entries (optional)
  54. public function AddEntry($entry) {
  55. $this->conf["entries"][] = $entry;
  56. }
  57. // Add a table-wide form:
  58. public function AddTableForm($form) {
  59. $this->conf["formbehaviour"] = $form;
  60. }
  61. // Set counter values:
  62. public function InitCounter($counter,$ncounter) {
  63. $this->conf["counter"] = $counter;
  64. $this->conf["ncounter"] = $ncounter;
  65. }
  66. // Set a custom value:
  67. public function SetCProperty($property,$value) {
  68. $this->conf["$property"] = $value;
  69. }
  70. // Generate the Table:
  71. public function Render($query) {
  72. $qid = $GLOBALS["SQL"]->query($this->conf["pool"],FE,$query);
  73. $this->result = $GLOBALS["SQL"]->execute($qid,ASSOC);
  74. array_shift($this->result);
  75. $counter = $this->conf["counter"];
  76. if (isset($this->conf["formbehaviour"])) {
  77. ?>
  78. <form id="<?php echo $this->conf["id"];?>FORM" onsubmit="<?php echo $this->conf["formbehaviour"];?> return 0;" method="post" action="">
  79. <?
  80. }
  81. ?>
  82. <table id="<?php echo $this->conf["id"];?>" class="<?php echo $this->conf["class"] ?>" style="<?php echo $this->conf["style"];?>">
  83. <thead>
  84. <tr class="tableinxbdr">
  85. <?
  86. $ncounter = $this->conf["ncounter"];
  87. foreach($this->conf["labels"] as $labels) {
  88. ?>
  89. <td><?php echo $labels;?></td>
  90. <?
  91. }
  92. ?>
  93. </tr>
  94. </thead>
  95. <tbody>
  96. <?
  97. foreach ($this->result as $result) {
  98. $rand = rand(0,1000);
  99. ?>
  100. <tr id="<?php echo $this->conf["id"];?>TR<?php echo $counter+$rand;?>" class="<?php if ($counter %2) {echo "tableeven";} else {echo "tableodd";} ?>">
  101. <?
  102. $ncounter++;
  103. $keys = array_keys($result);
  104. foreach ($keys as $keys) {
  105. if ($keys != "id") {
  106. $data = $result["$keys"];
  107. ?>
  108. <td id="<?php echo $this->conf["id"];?>TD<?php echo $ncounter;?>">
  109. <?php if (empty($this->conf["behaviour"])) { echo xhtmlentities($data); } else {
  110. { require $this->conf["behaviour"]; }
  111. } ?>
  112. </td>
  113. <?
  114. }}
  115. $ncounter++;
  116. if (isset($this->conf["extrafunc"])) {
  117. foreach ($this->conf["extrafunc"] as $extra) {
  118. $ncounter++;
  119. ?>
  120. <td id="<?php echo $this->conf["id"];?>TD<?php echo $ncounter;?>">
  121. <?
  122. require $extra;
  123. ?>
  124. </td>
  125. <?
  126. }}
  127. ?>
  128. </tr>
  129. <?
  130. $counter++;
  131. }
  132. ?>
  133. </tbody>
  134. </table>
  135. <?
  136. if (isset($this->conf["formbehaviour"])) {
  137. ?>
  138. <input type="hidden" id="TableREF" value="<?php echo $this->conf["id"];?>"/>
  139. <input type="hidden" id="<?php echo $this->conf["id"];?>TR" value="<?php echo $counter; ?>"/>
  140. <input type="hidden" id="<?php echo $this->conf["id"];?>TD" value="<?php echo $ncounter; ?>"/>
  141. </form>
  142. <?
  143. }
  144. $this->conf["counter"] = $counter;
  145. $this->conf["ncounter"] = $ncounter;
  146. }
  147. // Just give me one TR, will you?
  148. public function RenderTR($query) {
  149. $qid = $GLOBALS["SQL"]->query($this->conf["pool"],FE,$query);
  150. $this->result = $GLOBALS["SQL"]->execute($qid,ASSOC);
  151. array_shift($this->result);
  152. $ncounter = $this->conf["ncounter"];
  153. $counter = $this->conf["counter"];
  154. ?>
  155. <?
  156. $ncounter++;
  157. $keys = array_keys($this->result[0]);
  158. foreach ($keys as $keys) {
  159. if ($keys != "id") {
  160. $data = $this->result[0]["$keys"]
  161. ?>
  162. <td id="<?php echo $this->conf["id"];?>TD<?php echo $ncounter;?>">
  163. <?php if (empty($this->conf["behaviour"])) { echo xhtmlentities($data); } else {
  164. {require $this->conf["behaviour"]; }
  165. } ?>
  166. </td>
  167. <?
  168. $ncounter++;
  169. }}
  170. if (isset($this->conf["extrafunc"])) {
  171. foreach ($this->conf["extrafunc"] as $extra) {
  172. $ncounter++;
  173. ?>
  174. <td id="<?php echo $this->conf["id"];?>TD<?php echo $ncounter;?>">
  175. <?
  176. require $extra;
  177. ?>
  178. </td>
  179. <?
  180. }}
  181. ?>
  182. <?
  183. $this->conf["ncounter"] = $ncounter;
  184. }
  185. # Overloaded for convenience:
  186. public function MultiVertTable($query) {
  187. $this->QuickVertTable($query);
  188. }
  189. public function QuickVertTable($query) {
  190. $qid = $GLOBALS["SQL"]->query($this->conf["pool"],FE,$query);
  191. $this->result = $GLOBALS["SQL"]->execute($qid,ASSOC);
  192. array_shift($this->result);
  193. $counter = 0;
  194. if (is_array($this->result[0])) {
  195. $labels = array_keys($this->result[0]);
  196. ?>
  197. <table id="<?php echo $this->conf["id"];?>" class="<?php echo $this->conf["class"] ?>" style="<?php echo $this->conf["style"]; ?>">
  198. <tbody>
  199. <?
  200. foreach ($this->result[0] as $data) {
  201. echo "<tr>\n";
  202. echo "<td class=\"tableinxbdr\">".htmlentities(ucfirst($labels[$counter]),UTF-8)."</td>\n";
  203. echo "<td class=\"";
  204. if ($counter %2) {
  205. echo "tableeven";
  206. } else {
  207. echo "tableodd";
  208. }
  209. echo "\">";
  210. if (empty($this->conf["behaviour"])) {
  211. echo xhtmlentities($data);
  212. } else {
  213. require $this->conf["behaviour"]; }
  214. echo "</td>\n";
  215. echo "</tr>\n";
  216. $counter++;
  217. }
  218. ?>
  219. </tbody>
  220. </table>
  221. <?
  222. }}
  223. public function MultiHorizTable($query) {
  224. $qid = $GLOBALS["SQL"]->query($this->conf["pool"],FE,$query);
  225. $this->result = $GLOBALS["SQL"]->execute($qid,ASSOC);
  226. array_shift($this->result);
  227. $counter = 0;
  228. if (is_array($this->result[0])) {
  229. $labels = array_keys($this->result[0]);
  230. ?>
  231. <table id="<?php echo $this->conf["id"];?>" class="<?php echo $this->conf["class"] ?>" style="<?php echo $this->conf["style"]; ?>">
  232. <tbody>
  233. <?
  234. echo "<tr class=\"tableinxbdr\">";
  235. foreach ($labels as $label) {
  236. echo "<td>";
  237. echo htmlentities(ucfirst($label),UTF-8);
  238. echo "</td>\n";
  239. }
  240. echo "</tr>\n";
  241. foreach ($this->result as $result){
  242. echo "<tr class=\"";
  243. if ($counter %2) {
  244. echo "tableeven";
  245. } else {
  246. echo "tableodd";
  247. }
  248. echo "\">";
  249. foreach ($result as $data) {
  250. echo "<td>\n";
  251. if (empty($this->conf["behaviour"])) {
  252. echo xhtmlentities($data);
  253. } else {
  254. require $this->conf["behaviour"]; }
  255. echo "</td>\n";
  256. }
  257. echo "</tr>\n";
  258. $counter++;
  259. }
  260. ?>
  261. </tbody>
  262. </table>
  263. <?
  264. }}
  265. }
  266. ?>