aab36da186b2f8e805b98d1b6f35506071b507a9
1 <?php
3 class listing {
5 var $xmlData;
6 var $entries;
7 var $departmentBrowser= false;
8 var $departmentRootVisible= false;
9 var $multiSelect= false;
10 var $template;
11 var $summary;
12 var $header= array();
13 var $colprops= array();
15 function listing($filename)
16 {
17 if (!$this->load($filename)) {
18 die("Cannot parse $filename!");
19 }
20 }
23 function load($filename)
24 {
25 $contents = file_get_contents($filename);
26 $this->xmlData= xml::xml2array($contents, 1);
28 if (!isset($this->xmlData['list'])) {
29 return false;
30 }
32 $this->xmlData= $this->xmlData["list"];
34 // Load some definition values
35 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect") as $token) {
36 if (isset($this->xmlData['definition'][$token]) &&
37 $this->xmlData['definition'][$token] == "true"){
38 $this->$token= true;
39 }
40 }
42 // Parse layout per column
43 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
45 // Prepare table headers
46 $this->header= array();
47 if (isset($this->xmlData['table']['column'])){
48 foreach ($this->xmlData['table']['column'] as $index => $config) {
49 if (isset($config['header'])) {
50 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">".xml::getLocalizedAttribute($config['header'], $GLOBALS['t_language'])."</td>";
51 } else {
52 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
53 }
54 }
55 }
57 return true;
58 }
61 function render()
62 {
63 #print_a($this->xmlData);
64 #print_a($this->entries);
65 echo "Fill summary, handle empty lists differently, alternating<br>";
66 $summary= "empty";
68 // Initialize list
69 $result= "<table summary='$summary' style='width:600px;height:450px;' cellspacing='0' id='t_scrolltable'>
70 <tr><td class='scrollhead'><table summary='' style='width:100%;' cellspacing='0' id='t_scrollhead'>";
71 $num_cols= count($this->colprops) + ($this->multiSelect?1:0);
73 // Build list header
74 $result.= "<tr>";
75 if ($this->multiSelect) {
76 $result.= "<td class='listheader' style='width:20px;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"item_selected_[0-9]*$\",\"select_all\");' ></td>";
77 }
78 foreach ($this->header as $header) {
79 $result.= $header;
80 }
82 // Add 13px for scroller
83 $result.= "<td class='listheader' style='width:13px;border-right:0px;'> </td></table></td></tr>";
85 // New table for the real list contents
86 $result.= "<tr><td colspan='$num_cols' class='scrollbody'><div style='width:100%;height:430px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
88 // Fill with contents
89 $first= true;
90 foreach ($this->entries as $entry){
91 $result.="<tr class='rowxp1'>";
92 foreach ($this->xmlData['table']['column'] as $config) {
93 if ($first) {
95 } else {
96 }
97 }
98 $first= false;
99 }
100 # for ($i= 0; $i<10; $i++) {
101 # $result.="<tr class='rowxp1'>";
102 # $result.="<td style='text-align:center;width:20px;' class='list1'> </td>";
103 # $result.="<td style='text-align:center;width:20px;' class='list1'><image src='images/lists/folder.png' class='center'></td>";
104 # $result.="<td style='' class='list1'><a href='?plug=19&post_id=12499984306&act=dep_open&dep_id=1'>Administrativa - [Funktionelle Daten]</a></td>";
105 # $result.="<td style='width:100px;' class='list1'> </td>";
106 # $result.="<td style='width:158px;border-right:0px;' class='list1'> </td>";
107 # $result.="</tr>";
108 # }
110 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
111 if (count($this->entries) < 22) {
112 $result.= "<tr>";
113 for ($i= 0; $i<=$num_cols; $i++) {
114 if ($i == 0) {
115 $result.= "<td class='list1nohighlight' style='height:100%;'> </td>";
116 continue;
117 }
118 if ($i != $num_cols-1) {
119 $result.= "<td class='list1nohighlight''> </td>";
120 } else {
121 $result.= "<td class='list1nohighlight' style='border-right:0px'> </td>";
122 }
123 }
124 $result.= "</tr>";
125 }
127 $result.= "</table></div></td></tr></table>";
129 return $result;
130 }
133 function setEntries($entries)
134 {
135 $this->entries= &$entries;
136 }
139 function parseLayout($layout)
140 {
141 $result= array();
142 $layout= preg_replace("/^\|/", "", $layout);
143 $layout= preg_replace("/\|$/", "", $layout);
144 $cols= split("\|", $layout);
145 foreach ($cols as $index => $config) {
146 if ($config != "") {
147 $components= split(';', $config);
148 $config= "";
149 foreach ($components as $part) {
150 if (preg_match("/^r$/", $part)) {
151 $config.= "text-align:right;";
152 continue;
153 }
154 if (preg_match("/^l$/", $part)) {
155 $config.= "text-align:left;";
156 continue;
157 }
158 if (preg_match("/^c$/", $part)) {
159 $config.= "text-align:center;";
160 continue;
161 }
162 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
163 $config.= "width:$part;";
164 continue;
165 }
166 }
168 $result[$index]= " style='$config' ";
169 } else {
170 $result[$index]= null;
171 }
172 }
174 return $result;
175 }
177 }
179 ?>