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