1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cGuiScrollList {
25:
26: 27: 28: 29:
30: public $data = Array();
31:
32: 33: 34: 35:
36: public = Array();
37:
38: 39: 40: 41:
42: public $resultsPerPage;
43:
44: 45: 46: 47:
48: public $listStart;
49:
50: 51: 52: 53:
54: public $sortable;
55:
56: 57: 58: 59:
60: public $sortlink;
61:
62: 63: 64:
65: public $objTable;
66:
67: 68: 69:
70: public ;
71:
72: 73: 74:
75: public ;
76:
77: 78: 79:
80: public $objRow;
81:
82: 83: 84:
85: public $objItem;
86:
87: 88: 89: 90:
91:
92: 93: 94: 95: 96: 97:
98: public function __construct($defaultstyle = true, $action = "") {
99: global $cfg, $area, $frame;
100:
101: $this->resultsPerPage = 0;
102: $this->listStart = 1;
103: $this->sortable = false;
104:
105: $this->objTable = new cHTMLTable();
106: if ($defaultstyle == true) {
107: $this->objTable->setClass("generic");
108: $this->objTable->updateAttributes(array(
109: "cellpadding" => "2"
110: ));
111: }
112:
113: $this->objHeaderRow = new cHTMLTableRow();
114:
115: $this->objHeaderItem = new cHTMLTableHead();
116:
117: $this->objRow = new cHTMLTableRow();
118:
119: $this->objItem = new cHTMLTableData();
120:
121: $this->sortlink = new cHTMLLink();
122: $this->sortlink->setStyle("color: #666666;");
123: $this->sortlink->setCLink($area, $frame, $action);
124: }
125:
126: 127: 128: 129: 130: 131: 132:
133: public function setSortable($key, $sortable) {
134: $this->sortable[$key] = $sortable;
135: }
136:
137: 138: 139: 140: 141: 142: 143: 144:
145: public function setCustom($key, $custom) {
146: $this->sortlink->setCustom($key, $custom);
147: }
148:
149: 150: 151: 152: 153:
154: public function onRenderRow($row) {
155: $this->objRow->setStyle("white-space:nowrap;");
156: }
157:
158: 159: 160: 161: 162:
163: public function onRenderColumn($column) {
164: }
165:
166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179:
180: public function () {
181: $numargs = func_num_args();
182:
183: for ($i = 0; $i < $numargs; $i++) {
184: $this->header[$i] = func_get_arg($i);
185: }
186: }
187:
188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202:
203: public function setData($index) {
204: $numargs = func_num_args();
205:
206: for ($i = 1; $i < $numargs; $i++) {
207: $this->data[$index][$i] = func_get_arg($i);
208: }
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225:
226: public function setHiddenData($index) {
227: $numargs = func_num_args();
228:
229: for ($i = 1; $i < $numargs; $i++) {
230: $this->data[$index]["hiddendata"][$i] = func_get_arg($i);
231: }
232: }
233:
234: 235: 236: 237: 238:
239: public function setResultsPerPage($numresults) {
240: $this->resultsPerPage = $numresults;
241: }
242:
243: 244: 245: 246: 247:
248: public function setListStart($startpage) {
249: $this->listStart = $startpage;
250: }
251:
252: 253: 254: 255: 256: 257:
258: public function getCurrentPage() {
259: if ($this->resultsPerPage == 0) {
260: return 1;
261: }
262:
263: return ($this->listStart);
264: }
265:
266: 267: 268: 269: 270: 271:
272: public function getNumPages() {
273: return (ceil(count($this->data) / $this->resultsPerPage));
274: }
275:
276: 277: 278: 279: 280: 281:
282: public function sort($field, $order) {
283: if ($order == "") {
284: $order = SORT_ASC;
285: }
286:
287: if ($order == "ASC") {
288: $order = SORT_ASC;
289: }
290:
291: if ($order == "DESC") {
292: $order = SORT_DESC;
293: }
294:
295: $this->sortkey = $field;
296: $this->sortmode = $order;
297:
298: $field = $field + 1;
299: $this->data = cArray::csort($this->data, "$field", $order);
300: }
301:
302: 303: 304: 305: 306: 307: 308:
309: public function convert($field, $value, $hiddendata) {
310: return $value;
311: }
312:
313: 314: 315: 316: 317:
318: public function render($return = true) {
319: global $cfg;
320:
321: $currentpage = $this->getCurrentPage();
322:
323: $itemstart = (($currentpage - 1) * $this->resultsPerPage) + 1;
324:
325: $headeroutput = "";
326: $output = "";
327:
328:
329: foreach ($this->header as $key => $value) {
330: if (is_array($this->sortable)) {
331: if (array_key_exists($key, $this->sortable) && $this->sortable[$key] == true) {
332: $this->sortlink->setContent($value);
333: $this->sortlink->setCustom("sortby", $key);
334:
335: if ($this->sortkey == $key && $this->sortmode == SORT_ASC) {
336: $this->sortlink->setCustom("sortmode", "DESC");
337: } else {
338: $this->sortlink->setCustom("sortmode", "ASC");
339: }
340:
341: $this->objHeaderItem->setContent($this->sortlink->render());
342: $headeroutput .= $this->objHeaderItem->render();
343: } else {
344: $this->objHeaderItem->setContent($value);
345: $headeroutput .= $this->objHeaderItem->render();
346: }
347: } else {
348: $this->objHeaderItem->setContent($value);
349: $headeroutput .= $this->objHeaderItem->render();
350: }
351: $this->objHeaderItem->advanceID();
352: }
353:
354: $this->objHeaderRow->setContent($headeroutput);
355:
356: $headeroutput = $this->objHeaderRow->render();
357:
358: if ($this->resultsPerPage == 0) {
359: $itemend = count($this->data) - ($itemstart - 1);
360: } else {
361: $itemend = $currentpage * $this->resultsPerPage;
362: }
363:
364: if ($itemend > count($this->data)) {
365: $itemend = count($this->data);
366: }
367:
368: for ($i = $itemstart; $i < $itemend + 1; $i++) {
369:
370:
371:
372: if ($this->data[$i - 1] == NULL) {
373: continue;
374: }
375:
376: $items = "";
377:
378: $this->onRenderRow($i);
379:
380: foreach ($this->data[$i - 1] as $key => $value) {
381: $this->onRenderColumn($key);
382:
383: if ($key != "hiddendata") {
384: $hiddendata = $this->data[$i - 1]["hiddendata"];
385:
386: $this->objItem->setContent($this->convert($key, $value, $hiddendata));
387: $items .= $this->objItem->render();
388: }
389: $this->objItem->advanceID();
390: }
391:
392: $this->objRow->setContent($items);
393: $items = "";
394:
395: $output .= $this->objRow->render();
396: $this->objRow->advanceID();
397: }
398:
399: $this->objTable->setContent($headeroutput . $output);
400:
401: $output = stripslashes($this->objTable->render());
402:
403: if ($return == true) {
404: return $output;
405: } else {
406: echo $output;
407: }
408: }
409:
410: }
411: