CHTMLTable.class


SUBMITTED BY: Guest

DATE: July 23, 2014, 12:24 p.m.

FORMAT: Text only

SIZE: 10.2 kB

HITS: 1070

  1. <?php
  2. class CHTMLTable {
  3. var $version = '1.1a';
  4. var $author_info = 'Sergey Ovchinnikov <sergeyvo@ngs.ru>, ICQ UIN 91792005';
  5. var $range_rows;
  6. var $range_cols;
  7. var $Table;
  8. var $table_properties = array(
  9. 'border' => 'border',
  10. 'bordercolor' => 'bordercolor',
  11. 'width' => 'width',
  12. 'height' => 'height',
  13. 'cellspacing' => 'cellspacing',
  14. 'cellpadding' => 'cellpadding',
  15. 'style' => 'style',
  16. 'align' => 'align',
  17. 'class' => 'class',
  18. 'id' => 'id',
  19. );
  20. var $tr_properties = array(
  21. 'width' => 'width',
  22. 'height' => 'height',
  23. 'bgcolor' => 'bgcolor',
  24. 'align' => 'align',
  25. 'valign' => 'valign',
  26. 'style' => 'style',
  27. 'class' => 'class',
  28. 'id' => 'id',
  29. );
  30. var $td_properties = array(
  31. 'width' => 'width',
  32. 'height' => 'height',
  33. 'bgcolor' => 'bgcolor',
  34. 'align' => 'align',
  35. 'valign' => 'valign',
  36. 'colspan' => 'colspan',
  37. 'rowspan' => 'rowspan',
  38. 'style' => 'style',
  39. 'class' => 'class',
  40. 'id' => 'id',
  41. 'content' => 'content'
  42. );
  43. #===============================================================================================
  44. # CHTMLTable
  45. #===============================================================================================
  46. function CHTMLTable() {
  47. $this->Table = array();
  48. }
  49. #===============================================================================================
  50. # SET RANGE ROWS
  51. #===============================================================================================
  52. function setRangeRows($range_rows) {
  53. $this->range_rows = $range_rows;
  54. }
  55. #===============================================================================================
  56. # SET RANGE COLS
  57. #===============================================================================================
  58. function setRangeCols($range_cols) {
  59. $this->range_cols = $range_cols;
  60. }
  61. #===============================================================================================
  62. # SET TD PROPERTIES
  63. #===============================================================================================
  64. function setTDProperties($array) {
  65. foreach($array as $key=>$property) {
  66. $this->td_properties[$key] = $property;
  67. }
  68. }
  69. #===============================================================================================
  70. # SET TR PROPERTIES
  71. #===============================================================================================
  72. function setTRProperties($array) {
  73. foreach($array as $key=>$property) {
  74. $this->tr_properties[$key] = $property;
  75. }
  76. }
  77. #===============================================================================================
  78. # GET MAX KEY OF ARRAY
  79. #===============================================================================================
  80. function getMaxKey($array) {
  81. $keys = array_keys($array);
  82. rsort($keys);
  83. return $keys[0];
  84. }
  85. #===============================================================================================
  86. # GET MAX ROWS
  87. #===============================================================================================
  88. function calculateRangeRows() {
  89. $this->range_rows = $this->getMaxKey($this->Table['Rows']);
  90. return $this->range_rows++;
  91. }
  92. #===============================================================================================
  93. # GET MAX COLS
  94. #===============================================================================================
  95. function calculateRangeCells() {
  96. $this->range_cols = 0;
  97. foreach ($this->Table['Rows'] as $table) {
  98. $max_key = $this->getMaxKey($table['Cols']);
  99. if ($max_key > $this->range_cols) $this->range_cols = $max_key;
  100. }
  101. return $this->range_cols++;
  102. }
  103. #===============================================================================================
  104. # SHOW TABLE INIT
  105. #===============================================================================================
  106. function calculateRanges() {
  107. $this->calculateRangeRows();
  108. $this->calculateRangeCells();
  109. }
  110. #===============================================================================================
  111. # SHOW TABLE
  112. #===============================================================================================
  113. function showTable() {
  114. if (!$this->Table['Rows']) return false;
  115. $this->printOpenTable();
  116. for ($i=0; $i<$this->range_rows; $i++) {
  117. if ($this->Table['Rows'][$i]['Cols']) {
  118. $tr = $this->Table['Rows'][$i];
  119. $this->printOpenTR($tr);
  120. for ($j=0; $j<$this->range_cols; $j++) {
  121. $td = $this->Table['Rows'][$i]['Cols'][$j];
  122. if ($td[$this->td_properties['colspan']]!='') $colspan[$i] = intval($td[$this->td_properties['colspan']]);
  123. if ($td[$this->td_properties['rowspan']]!='') $rowspan[$j] = intval($td[$this->td_properties['rowspan']]);
  124. if ($colspan[$i] && $td[$this->td_properties['rowspan']]!='') {
  125. $cols_rowspan[$i] = intval($td[$this->td_properties['rowspan']]);
  126. }
  127. // if (!$colspan[$i]) $cols_rowspan[$i]=0;
  128. if ($cols_rowspan[$i]>0) $rowspan[$j] = $cols_rowspan[$i];
  129. if (
  130. (!$rowspan[$j] || ($rowspan[$j] && $td[$this->td_properties['rowspan']]!=''))
  131. &&
  132. (!$colspan[$i] || ($colspan[$i] && $td[$this->td_properties['colspan']]!=''))
  133. ) {
  134. $this->printTD($td);
  135. }
  136. if ($rowspan[$j]>0) $rowspan[$j]--;
  137. if ($colspan[$i]>0) $colspan[$i]--;
  138. if (!$colspan[$i]) $cols_rowspan[$i]=0;
  139. }
  140. echo "</TR>\n\r";
  141. }
  142. }
  143. $this->printCloseTable();
  144. }
  145. #===============================================================================================
  146. # PRINT OPEN TABLE
  147. #===============================================================================================
  148. function printOpenTable() {
  149. echo "\n\r<TABLE";
  150. foreach($this->table_properties as $key=>$property) {
  151. if (strval($this->Table[$this->table_properties[$key]])!='') {
  152. echo " ".$key."=\"".strval($this->Table[$this->table_properties[$key]])."\"";
  153. }
  154. }
  155. echo ">\n\r";
  156. }
  157. #===============================================================================================
  158. # PRINT OPEN TABLE
  159. #===============================================================================================
  160. function printCloseTable() {
  161. echo "</TABLE>\n\r\n\r";
  162. }
  163. #===============================================================================================
  164. # PRINT OPEN TD
  165. #===============================================================================================
  166. function printTD($td) {
  167. echo " <TD";
  168. foreach($this->td_properties as $key=>$property) {
  169. if (strval($td[$this->td_properties[$key]])!='') {
  170. echo " ".$key."=\"".strval($td[$this->td_properties[$key]])."\"";
  171. }
  172. }
  173. echo ">";
  174. if ($td[$this->td_properties['content']]) echo $td[$this->td_properties['content']];
  175. else echo '&nbsp;';
  176. echo "</TD>\n\r";
  177. }
  178. #===============================================================================================
  179. # PRINT OPEN TR
  180. #===============================================================================================
  181. function printOpenTR($tr) {
  182. echo "<TR";
  183. foreach($this->tr_properties as $key=>$property) {
  184. if (strval($tr[$this->tr_properties[$key]])!='') {
  185. echo " ".$key."=\"".strval($tr[$this->tr_properties[$key]])."\"";
  186. }
  187. }
  188. echo ">\n\r";
  189. }
  190. #===============================================================================================
  191. # / class
  192. #===============================================================================================
  193. }
  194. ?>

comments powered by Disqus