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: protected $_tplCellCode = '';
312:
313: 314: 315:
316: protected $_tplTableFile = '';
317:
318: 319: 320:
321: protected $_width = '';
322:
323: 324: 325:
326: protected $_border = 0;
327:
328: 329: 330:
331: protected $_borderColor = '';
332:
333: 334: 335:
336: protected $_solidBorder = '';
337:
338: 339: 340:
341: protected $_padding = 0;
342:
343: 344: 345:
346: protected $_cells = [];
347:
348: 349: 350:
351: protected $_cellAlignment = [];
352:
353: 354: 355:
356: protected $_cellVAlignment = [];
357:
358: 359: 360:
361: protected $_cellColSpan;
362:
363: 364: 365:
366: protected $_cellClass = [];
367:
368: 369: 370:
371: protected $_rowBgColor;
372:
373: 374: 375:
376: protected ;
377:
378: 379: 380:
381: protected $_addMultiSelJS = false;
382:
383: 384: 385:
386: protected $_colorLight = '';
387:
388: 389: 390:
391: protected $_colorDark = '';
392:
393: 394: 395:
396: public function __construct()
397: {
398: $cfg = cRegistry::getConfig();
399: $backendPath = cRegistry::getBackendPath();
400:
401: $this->_padding = 2;
402: $this->_border = 0;
403: $this->_tplTableFile = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper'];
404: $this->_tplCellCode = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper_row'];
405: }
406:
407: 408: 409:
410: public function setCellTemplate($code)
411: {
412: $this->_tplCellCode = $code;
413: }
414:
415: 416: 417:
418: public function setTableTemplateFile($path)
419: {
420: $this->_tplTableFile = $path;
421: }
422:
423: 424: 425: 426: 427: 428: 429:
430: public function setCell($row, $cell, $content)
431: {
432: $this->_cells[$row][$cell] = $content;
433: $this->_cellAlignment[$row][$cell] = "";
434: }
435:
436: 437: 438: 439: 440: 441: 442:
443: protected function setCellAlignment($row, $cell, $alignment)
444: {
445: $this->_cellAlignment[$row][$cell] = $alignment;
446: }
447:
448: 449: 450: 451: 452: 453: 454:
455: public function setCellVAlignment($row, $cell, $alignment)
456: {
457: $this->_cellVAlignment[$row][$cell] = $alignment;
458: }
459:
460: 461: 462: 463: 464: 465: 466:
467: public function setCellClass($row, $cell, $class)
468: {
469: $this->_cellClass[$row][$cell] = $class;
470: }
471:
472: 473:
474: public function addMultiSelJS()
475: {
476: $this->_addMultiSelJS = true;
477: }
478:
479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489:
490: protected function _getMultiSelJS()
491: {
492: $script = '
493: <script type="text/javascript"><!--
494: try {
495: function fncUpdateSel(selectBox, storage) {
496: var sSelection = "";
497: var oSelectBox = document.getElementsByName(selectBox)[0];
498: var oStorage = document.getElementsByName(storage)[0];
499: if (oSelectBox && oStorage) {
500: for (var i = 0; i < oSelectBox.length; i++) {
501: if (oSelectBox.options[i].selected === true) {
502: if (sSelection !== "") {
503: sSelection = sSelection + ",";
504: }
505: sSelection = sSelection + oSelectBox.options[i].value;
506: }
507: }
508: oStorage.value = sSelection;
509: }
510: }
511: } catch (e) { }
512: //--></script>
513: ';
514:
515: return $script;
516: }
517:
518: 519: 520: 521: 522: 523: 524: 525: 526: 527:
528: public function render($print = false)
529: {
530: $template = new cTemplate();
531: $template->reset();
532:
533: $ColCount = 0;
534: if (is_array($this->_cells)) {
535: foreach ($this->_cells as $row => $cells) {
536: $ColCount++;
537:
538: $line = '';
539: $count = 0;
540:
541: foreach ($cells as $cell => $data) {
542: $count++;
543: $tplCell = new cTemplate();
544: $tplCell->reset();
545:
546: if ($this->_cellClass[$row][$cell] != '') {
547: $tplCell->set('s', 'CLASS', $this->_cellClass[$row][$cell]);
548: } else {
549: $tplCell->set('s', 'CLASS', '');
550: }
551:
552: if ($this->_cellAlignment[$row][$cell] != '') {
553: $tplCell->set('s', 'ALIGN', $this->_cellAlignment[$row][$cell]);
554: } else {
555: $tplCell->set('s', 'ALIGN', 'left');
556: }
557:
558: if ($this->_cellVAlignment[$row][$cell] != '') {
559: $tplCell->set('s', 'VALIGN', $this->_cellAlignment[$row][$cell]);
560: } else {
561: $tplCell->set('s', 'VALIGN', 'top');
562: }
563:
564:
565: if ($this->_addMultiSelJS) {
566: $data = $this->_getMultiSelJS() . $data;
567: }
568:
569: $tplCell->set('s', 'CONTENT', $data);
570: $line .= $tplCell->generate($this->_tplCellCode, true, false);
571:
572: error_log($line);
573: }
574:
575:
576: $template->set('d', 'ROWS', $line);
577: $template->next();
578: }
579: }
580: $rendered = $template->generate($this->_tplTableFile, true, false);
581:
582: if ($print == true) {
583: echo $rendered;
584:
585: return null;
586: } else {
587: return $rendered;
588: }
589: }
590: }