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:
66: public $objTable;
67:
68: 69: 70: 71:
72: public ;
73:
74: 75: 76: 77:
78: public ;
79:
80: 81: 82: 83:
84: public $objRow;
85:
86: 87: 88: 89:
90: public $objItem;
91:
92:
93:
94: 95: 96: 97: 98:
99: public function __construct($defaultstyle = true, $action = "") {
100: global $cfg, $area, $frame;
101:
102: $this->resultsPerPage = 0;
103: $this->listStart = 1;
104: $this->sortable = false;
105:
106: $this->objTable = new cHTMLTable;
107: if ($defaultstyle == true) {
108: $this->objTable->setClass("generic");
109: $this->objTable->updateAttributes(array("cellpadding" => "2"));
110: }
111:
112: $this->objHeaderRow = new cHTMLTableRow;
113:
114: $this->objHeaderItem = new cHTMLTableHead;
115:
116: $this->objRow = new cHTMLTableRow;
117:
118: $this->objItem = new cHTMLTableData;
119:
120: $this->sortlink = new cHTMLLink;
121: $this->sortlink->setStyle("color: #666666;");
122: $this->sortlink->setCLink($area, $frame, $action);
123: }
124:
125: 126: 127: 128: 129: 130: 131:
132: public function setSortable($key, $sortable) {
133: $this->sortable[$key] = $sortable;
134: }
135:
136: 137: 138: 139: 140: 141: 142: 143:
144: public function setCustom($key, $custom) {
145: $this->sortlink->setCustom($key, $custom);
146: }
147:
148: 149: 150: 151: 152:
153: public function onRenderRow($row) {
154: $this->objRow->setStyle("white-space:nowrap;");
155: }
156:
157: 158: 159: 160: 161:
162: public function onRenderColumn($column) {
163:
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: $items = "";
370:
371: $this->onRenderRow($i);
372:
373: foreach ($this->data[$i - 1] as $key => $value) {
374: $this->onRenderColumn($key);
375:
376: if ($key != "hiddendata") {
377: $hiddendata = $this->data[$i - 1]["hiddendata"];
378:
379: $this->objItem->setContent($this->convert($key, $value, $hiddendata));
380: $items .= $this->objItem->render();
381: }
382: $this->objItem->advanceID();
383: }
384:
385: $this->objRow->setContent($items);
386: $items = "";
387:
388: $output .= $this->objRow->render();
389: $this->objRow->advanceID();
390: }
391:
392: $this->objTable->setContent($headeroutput . $output);
393:
394: $output = stripslashes($this->objTable->render());
395:
396: if ($return == true) {
397: return $output;
398: } else {
399: echo $output;
400: }
401: }
402:
403: }
404: