1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19:
20: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
21:
22: 23: 24: 25: 26: 27:
28: class cHTMLInputSelectElement extends cHTMLSelectElement {
29:
30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: public function __construct($sName, $iWidth = '', $sID = '', $bDisabled = false, $iTabIndex = NULL, $sAccessKey = '') {
49: parent::__construct($sName, $iWidth, $sID, $bDisabled, $iTabIndex, $sAccessKey);
50: }
51:
52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
70: public function addArticles($iIDCat, $bColored = false, $bArtOnline = true, $sSpaces = '') {
71: global $cfg, $lang;
72:
73: if (is_numeric($iIDCat) && $iIDCat > 0) {
74:
75: $sql = "SELECT al.title AS title
76: , al.idartlang AS idartlang
77: , ca.idcat AS idcat
78: , ca.idcatart AS idcatart
79: , ca.is_start AS isstart
80: , al.online AS online
81: , cl.startidartlang AS idstartartlang
82: FROM " . $cfg["tab"]["art_lang"] . " AS al
83: , " . $cfg["tab"]["cat_art"] . " AS ca
84: , " . $cfg["tab"]["cat_lang"] . " AS cl
85: WHERE ca.idcat = '" . cSecurity::toInteger($iIDCat) . "'
86: AND cl.idcat = ca.idcat
87: AND cl.idlang = al.idlang
88: ";
89:
90: if ($bArtOnline) {
91: $sql .= " AND al.online = 1";
92: }
93:
94: $sql .= " AND al.idart = ca.idart
95: AND al.idlang = " . (int) $lang . "
96: ORDER BY al.title";
97:
98: $oDB = cRegistry::getDb();
99: $oDB->query($sql);
100:
101: $iCount = $oDB->numRows();
102: if ($iCount == 0) {
103: return 0;
104: } else {
105: $iCounter = count($this->_options);
106: while ($oDB->nextRecord()) {
107:
108: $oOption = new cHTMLOptionElement($sSpaces . ' ' . cString::getPartOfString($oDB->f('title'), 0, 32), $oDB->f('idcatart'));
109:
110: if ($bColored) {
111: if ($oDB->f('idstartartlang') == $oDB->f('idartlang')) {
112: if ($oDB->f('online') == 0) {
113:
114: $oOption->setStyle('color: #ff0000;');
115: } else {
116:
117: $oOption->setStyle('color: #0000ff;');
118: }
119: } else if ($oDB->f('online') == 0) {
120:
121: $oOption->setStyle('color: #666666;');
122: }
123: }
124:
125:
126: $this->addOptionElement($iCounter, $oOption);
127: $iCounter++;
128: }
129: return $iCount;
130: }
131: } else {
132: return 0;
133: }
134: }
135:
136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160:
161: public function addCategories($iMaxLevel = 0, $bColored = false, $bCatVisible = true, $bCatPublic = true, $bWithArt = false, $bArtOnline = true) {
162: global $cfg, $client, $lang;
163:
164: $sql = "SELECT
165: c.idcat
166: , cl.name
167: , cl.visible
168: , cl.public
169: , ct.level
170: FROM
171: " . $cfg["tab"]["cat"] . " AS c
172: , " . $cfg["tab"]["cat_lang"] . " AS cl
173: , " . $cfg["tab"]["cat_tree"] . " AS ct
174: WHERE
175: c.idclient = " . (int) $client . "
176: AND cl.idlang = " . (int) $lang . "
177: AND cl.idcat = c.idcat
178: AND ct.idcat = c.idcat";
179: if ($iMaxLevel > 0) {
180: $sql .= " AND ct.level < " . (int) $iMaxLevel;
181: }
182: $sql .= " ORDER BY ct.idtree";
183:
184: $oDB = cRegistry::getDb();
185: $oDB->query($sql);
186:
187: $iCount = $oDB->numRows();
188: if ($iCount == 0) {
189: return false;
190: } else {
191: $iCounter = count($this->_options);
192: while ($oDB->nextRecord()) {
193: $sSpaces = '';
194: $iID = $oDB->f('idcat');
195:
196: for ($i = 0; $i < $oDB->f('level'); $i++) {
197: $sSpaces .= ' ';
198: }
199:
200:
201: if (($bCatVisible && $oDB->f('visible') == 0) || ($bCatPublic && $oDB->f('public') == 0)) {
202:
203:
204: $sValue = '';
205: } else if ($bWithArt) {
206:
207: $sValue = '-' . $iID;
208: } else {
209:
210: $sValue = $iID;
211: }
212: $oOption = new cHTMLOptionElement($sSpaces . '> ' . $oDB->f('name'), $sValue);
213:
214:
215: $oOption->setStyle('background-color: #EFEFEF');
216: if ($bColored && ($oDB->f('visible') == 0 || $oDB->f('public') == 0)) {
217: $oOption->setStyle('color: #666666;');
218: }
219:
220:
221: $this->addOptionElement($iCounter, $oOption);
222:
223: if ($bWithArt) {
224: $iArticles = $this->addArticles($iID, $bColored, $bArtOnline, $sSpaces);
225: $iCount += $iArticles;
226: }
227: $iCounter = count($this->_options);
228: }
229: }
230:
231: return $iCount;
232: }
233:
234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248:
249: public function addTypesFromArt($iIDCatArt, $sTypeRange = '') {
250: global $cfg, $lang;
251:
252: if (is_numeric($iIDCatArt) && $iIDCatArt > 0) {
253: $oDB = cRegistry::getDb();
254:
255: $sql = "SELECT
256: t.typeid AS typeid
257: , t.idtype AS idtype
258: , t.type AS type
259: , t.description AS description
260: , t.value AS value
261: FROM " . $cfg["tab"]["content"] . " AS t
262: , " . $cfg["tab"]["art_lang"] . " AS al
263: , " . $cfg["tab"]["cat_art"] . " AS ca
264: , " . $cfg["tab"]["type"] . " AS t
265: WHERE
266: t.idtype = t.idtype
267: AND t.idartlang = al.idartlang
268: AND al.idart = ca.idart
269: AND al.idlang = " . (int) $lang . "
270: AND ca.idcatart = " . (int) $iIDCatArt;
271: if ($sTypeRange != "") {
272: $sql .= " AND t.idtype IN (" . $oDB->escape($sTypeRange) . ")";
273: }
274: $sql .= " ORDER BY t.idtype, t.typeid";
275:
276: $oDB = cRegistry::getDb();
277: $oDB->query($sql);
278:
279: $iCount = $oDB->numRows();
280: if ($iCount == 0) {
281: return false;
282: } else {
283: while ($oDB->nextRecord()) {
284: $sTypeIdentifier = "tblData.idtype = '" . $oDB->f('idtype') . "' AND tblData.typeid = '" . $oDB->f('typeid') . "'";
285:
286:
287: $oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . cString::getPartOfString(strip_tags($oDB->f("value")), 0, 50), $sTypeIdentifier);
288:
289:
290: $this->addOptionElement($sTypeIdentifier, $oOption);
291: }
292: return $iCount;
293: }
294: } else {
295: return false;
296: }
297: }
298: }
299:
300: 301: 302: 303: 304: 305:
306: class UI_Config_Table {
307:
308: 309: 310: 311:
312: protected $_TplCellCode = '';
313:
314: 315: 316: 317:
318: protected $_TplTableFile = '';
319:
320: 321: 322: 323:
324: protected $_Width = '';
325:
326: 327: 328: 329:
330: protected $_Border = 0;
331:
332: 333: 334: 335:
336: protected $_BorderColor = '';
337:
338: 339: 340: 341:
342: protected $_SolidBorder = '';
343:
344: 345: 346: 347:
348: protected $_Padding = 0;
349:
350: 351: 352: 353:
354: protected $_Cells = array();
355:
356: 357: 358: 359:
360: protected $_CellAlignment = array();
361:
362: 363: 364: 365:
366: protected $_CellVAlignment = array();
367:
368: 369: 370: 371:
372: protected $_CellColSpan;
373:
374: 375: 376: 377:
378: protected $_CellClass = array();
379:
380: 381: 382: 383:
384: protected $_RowBgColor;
385:
386: 387: 388: 389:
390: protected ;
391:
392: 393: 394: 395:
396: protected $_AddMultiSelJS = null;
397:
398: 399: 400: 401:
402: protected $_ColorLight = '';
403:
404: 405: 406: 407:
408: protected $_ColorDark = '';
409:
410: 411: 412:
413: public function __construct() {
414: $cfg = cRegistry::getConfig();
415: $backendPath = cRegistry::getBackendPath();
416:
417: $this->_Padding = 2;
418: $this->_Border = 0;
419: $this->_TplCellCode = ' <td align="{ALIGN}" valign="{VALIGN}" class="{CLASS}" colspan="{COLSPAN}" style="{EXTRA}white-space:nowrap;" nowrap="nowrap">{CONTENT}</td>' . "\n";
420: $this->_TplTableFile = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper'];
421: $this->_TplCellCode = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper_row'];
422: }
423:
424: 425: 426: 427: 428: 429: 430: 431:
432: public function UI_Config_Table() {
433: cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
434: return $this->__construct();
435: }
436:
437: 438: 439:
440: function setAddMultiSelJS($bEnabled = true) {
441: $this->_bAddMultiSelJS = (bool) $bEnabled;
442: }
443:
444: 445: 446: 447:
448: public function setCellTemplate($code) {
449: $this->_TplCellCode = $code;
450: }
451:
452: 453: 454: 455:
456: public function setTableTemplateFile($path) {
457: $this->_TplTableFile = $path;
458: }
459:
460: 461: 462: 463: 464: 465: 466:
467: public function setCell($row, $cell, $content) {
468: $this->_Cells[$row][$cell] = $content;
469: $this->_CellAlignment[$row][$cell] = "";
470: }
471:
472: 473: 474: 475: 476: 477: 478:
479: protected function setCellAlignment($row, $cell, $alignment) {
480: $this->_CellAlignment[$row][$cell] = $alignment;
481: }
482:
483: 484: 485: 486: 487: 488: 489:
490: public function setCellVAlignment($row, $cell, $alignment) {
491: $this->_CellVAlignment[$row][$cell] = $alignment;
492: }
493:
494: 495: 496: 497: 498: 499: 500:
501: public function setCellClass($row, $cell, $class) {
502: $this->_CellClass[$row][$cell] = $class;
503: }
504:
505: 506: 507: 508: 509:
510: protected function _addMultiSelJS() {
511:
512:
513:
514:
515:
516: $script = '
517: <script type="text/javascript"><!--
518: try {
519: function fncUpdateSel(selectBox, storage) {
520: var sSelection = "";
521: var oSelectBox = document.getElementsByName(selectBox)[0];
522: var oStorage = document.getElementsByName(storage)[0];
523: if (oSelectBox && oStorage) {
524: for (i = 0; i < oSelectBox.length; i++) {
525: if (oSelectBox.options[i].selected == true) {
526: if (sSelection != "") {
527: sSelection = sSelection + ",";
528: }
529: sSelection = sSelection + oSelectBox.options[i].value;
530: }
531: }
532: oStorage.value = sSelection;
533: }
534: }
535: } catch (e) { }
536: //--></script>
537: ';
538:
539: return $script;
540: }
541:
542: 543: 544: 545: 546: 547: 548: 549: 550: 551:
552: public function render($print = false) {
553: $table = new cTemplate();
554: $table->reset();
555:
556: $ColCount = 0;
557: if (is_array($this->_Cells)) {
558: foreach ($this->_Cells as $row => $cells) {
559: $ColCount++;
560:
561: $line = '';
562: $count = 0;
563:
564: foreach ($cells as $cell => $data) {
565: $count++;
566: $tplCell = new cTemplate();
567: $tplCell->reset();
568:
569: if ($this->_CellClass[$row][$cell] != '') {
570: $tplCell->set('s', 'CLASS', $this->_CellClass[$row][$cell]);
571: } else {
572: $tplCell->set('s', 'CLASS', '');
573: }
574:
575: if ($this->_CellAlignment[$row][$cell] != '') {
576: $tplCell->set('s', 'ALIGN', $this->_CellAlignment[$row][$cell]);
577: } else {
578: $tplCell->set('s', 'ALIGN', 'left');
579: }
580:
581: if ($this->_CellVAlignment[$row][$cell] != '') {
582: $tplCell->set('s', 'VALIGN', $this->_CellAlignment[$row][$cell]);
583: } else {
584: $tplCell->set('s', 'VALIGN', 'top');
585: }
586:
587:
588: if ($this->_AddMultiSelJS) {
589: $data = $this->_addMultiSelJS() . $data;
590: $this->_AddMultiSelJS = false;
591: }
592:
593: $tplCell->set('s', 'CONTENT', $data);
594: $line .= $tplCell->generate($this->_TplCellCode, true, false);
595: }
596:
597:
598: $table->set('d', 'ROWS', $line);
599: $table->next();
600: }
601: }
602: $rendered = $table->generate($this->_TplTableFile, true, false);
603:
604: if ($print == true) {
605: echo $rendered;
606: } else {
607: return $rendered;
608: }
609: }
610:
611: }