ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WEBCONDDB/php_CondDB/utils/tableViewer.php
Revision: 1.1
Committed: Fri Jun 29 07:53:08 2007 UTC (17 years, 10 months ago) by kdziedzi
Branch: MAIN
CVS Tags: V01-01-02, V01-01-01, V1_01_00, V01-01-00, V1_00_01, HEAD
Log Message:
Introducing new order in project

File Contents

# Content
1 <?php
2 session_start();
3 class tableViewer
4 {
5 var $data= Array();
6 var $isRecSet = false;
7
8 function tableViewer($data)
9 {
10 if (method_exists($data, 'GetAssoc'))
11 {
12 $this->data = $data->GetAssoc();
13 $this->isRecSet = true;
14 }
15 else
16 {
17 $this->data = $data;
18 }
19 }
20
21 function showData()
22 {
23
24 if ($this->isRecSet)
25 {
26 $this->showHeaders(current($this->data));
27 $is_odd = false;
28 echo '<tbody>';
29 foreach ($this->data as $row)
30 {
31 $this->showRows($row, $is_odd);
32 $is_odd ? $is_odd = false : $is_odd = true;
33 }
34 echo '</tbody>';
35 }
36 else
37 {
38 $this->showHeaders($this->data);
39 echo '<tbody>';
40 $this->showRows($this->data, false);
41 echo '</tbody>';
42 }
43
44 echo '</table></div>';
45 }
46 function showHeaders($name_tab)
47 {
48
49
50 if (is_array($name_tab))
51 {
52 echo '<script> function getHeaders(){
53 return [ ';
54 $i = 1;
55 foreach (array_keys($name_tab) as $cell)
56 {
57 $i= $i+1;
58 if (!stristr($cell, 'file_name') && !is_int($cell))
59 {
60 echo ' {key:"'.$cell.'",sortable:true}';
61 if ($i < count($name_tab))
62 {
63 echo ',';
64 }
65 }
66 }
67 }
68 else
69 {
70 echo '<p>No record</p>';
71 exit();
72 }
73 echo '];};' .
74 ' </script>' .
75 ' <div id="tablediv" class = "results">
76 <table id="dataTable" class = "results"><thead>
77 <TR>';
78 // <TH>Row</TH>';
79 /* if (!is_array($name_tab))
80 {
81 echo '<TD>No record</td>';
82 }
83 else
84 {
85 */ foreach (array_keys($name_tab) as $cell)
86 {
87 if (!stristr($cell, 'file_name') && !is_int($cell))
88 {
89 echo '<TH >'.$cell.'</TH>';
90 }
91 }
92 // }
93 echo '</TR></thead>';
94 }
95 function showRows($dataRow, $is_odd)
96 {
97
98 echo ($is_odd ? '<tr>' : '<tr>');
99 foreach ($dataRow as $key=>$value) //iterating over cells
100 {
101
102 if(is_int($key))
103 {
104 //skip
105 }
106 elseif (!stristr($key, 'file')) // all variables
107 {
108 echo '<td>'.$value.'</td>';
109 }
110 else //files
111 {
112 if (!stristr($key, 'file_name'))
113 {
114 echo '<td>';
115 if ($value != '')
116 {
117 $fileName = ($dataRow[$key.'_NAME'] != null ? $dataRow[$key.'_NAME'] :$dataRow[$key.'_name']);
118 $_SESSION[$fileName] = $value;
119 echo
120 '
121 <form name=file action="utils/saveFileButton.php" method="post" >
122 <input type="submit" name="send" value="Save" />' .
123 // '
124 // <input type="hidden" name="fileData" value="'.$value.'">' .
125 '
126 <input type="hidden" name="fileName" value="'.$fileName.'">
127 </form>';
128 }
129 else
130 {
131 echo 'No file';
132 }
133 echo '</td>';
134 }
135
136 }
137 }
138 echo '</tr>';
139 }
140 }
141
142 ?>