Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiPathresolveCacheHelper
  • cArray
  • cArticleCollector
  • cDirHandler
  • cFileHandler
  • cHTMLInputSelectElement
  • cIterator
  • cString
  • cStringMultiByteWrapper
  • cZipArchive
  • UI_Config_Table
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the the input helper classes.
  5:  * Various derived HTML class elements especially useful
  6:  * in the input area of modules
  7:  * Simple table generation class especially useful to generate
  8:  * backend configuration table. May be used also in Frontend,
  9:  * but note the globally used variables ($cfg)
 10:  *
 11:  * @package    Core
 12:  * @subpackage Util
 13:  * @author     Bjoern Behrens
 14:  * @copyright  four for business AG <www.4fb.de>
 15:  * @license    http://www.contenido.org/license/LIZENZ.txt
 16:  * @link       http://www.4fb.de
 17:  * @link       http://www.contenido.org
 18:  */
 19: 
 20: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 21: 
 22: /**
 23:  * Select box with additional functionality for category and article selection
 24:  *
 25:  * @package Core
 26:  * @subpackage Util
 27:  */
 28: class cHTMLInputSelectElement extends cHTMLSelectElement {
 29: 
 30:     /**
 31:      * Constructor to create an instance of this class.
 32:      *
 33:      * Creates an HTML select field (aka 'DropDown').
 34:      *
 35:      * @param string $sName
 36:      *         Name of the select element
 37:      * @param string $iWidth [optional]
 38:      *         Width of the select element
 39:      * @param string $sID [optional]
 40:      *         ID of the select element
 41:      * @param bool $bDisabled [optional]
 42:      *         Item disabled flag (non-empty to set disabled)
 43:      * @param int $iTabIndex [optional]
 44:      *         Tab index for form elements
 45:      * @param string $sAccessKey [optional]
 46:      *         Key to access the field
 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:      * Adds articles to select options.
 54:      *
 55:      * @param int    $iIDCat
 56:      *         idcat of the category to be listed
 57:      * @param bool   $bColored
 58:      *         Add color information to option elements
 59:      * @param bool   $bArtOnline
 60:      *         If true, only online articles will be added
 61:      * @param string $sSpaces
 62:      *         Just some '&nbsp;' to show data hierarchically
 63:      *         (used in conjunction with addCategories)
 64:      *
 65:      * @return int
 66:      *         Number of items added
 67:      * 
 68:      * @throws cDbException
 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:                     // Generate new option element
108:                     $oOption = new cHTMLOptionElement($sSpaces . '&nbsp;&nbsp;&nbsp;' . 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:                                 // Start article, but offline -> red
114:                                 $oOption->setStyle('color: #ff0000;');
115:                             } else {
116:                                 // Start article -> blue
117:                                 $oOption->setStyle('color: #0000ff;');
118:                             }
119:                         } else if ($oDB->f('online') == 0) {
120:                             // Offline article -> grey
121:                             $oOption->setStyle('color: #666666;');
122:                         }
123:                     }
124: 
125:                     // Add option element to the list
126:                     $this->addOptionElement($iCounter, $oOption);
127:                     $iCounter++;
128:                 }
129:                 return $iCount;
130:             }
131:         } else {
132:             return 0;
133:         }
134:     }
135: 
136:     /**
137:      * Adds categories (optionally including articles) as options to select box.
138:      *
139:      * Note: Using 'with articles' also adds articles - but the categories
140:      * will get negative values cause otherwise there is no way to distinguish
141:      * between a category id and an article id.
142:      *
143:      * @param int  $iMaxLevel
144:      *         Max. level shown (to be exact: except this level)
145:      * @param bool $bColored
146:      *         Add color information to option elements
147:      * @param bool $bCatVisible
148:      *         If true, only add idcat as value, if cat is visible
149:      * @param bool $bCatPublic
150:      *         If true, only add idcat as value, if cat is public
151:      * @param bool $bWithArt
152:      *         Add also articles per category
153:      * @param bool $bArtOnline
154:      *         If true, show only online articles
155:      * 
156:      * @return int
157:      *         Number of items added
158:      * 
159:      * @throws cDbException
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 .= '&nbsp;&nbsp;&nbsp;';
198:                 }
199: 
200:                 // Generate new option element
201:                 if (($bCatVisible && $oDB->f('visible') == 0) || ($bCatPublic && $oDB->f('public') == 0)) {
202:                     // If category has to be visible or public and it isn't,
203:                     // don't add value
204:                     $sValue = '';
205:                 } else if ($bWithArt) {
206:                     // If article will be added, set negative idcat as value
207:                     $sValue = '-' . $iID;
208:                 } else {
209:                     // Show only categories - and everything is fine...
210:                     $sValue = $iID;
211:                 }
212:                 $oOption = new cHTMLOptionElement($sSpaces . '>&nbsp;' . $oDB->f('name'), $sValue);
213: 
214:                 // Coloring option element, restricted shows grey color
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:                 // Add option element to the list
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:      * Function addTypesFromArt.
236:      * Adds types and type ids which are available for the specified article
237:      *
238:      * @param int    $iIDCatArt
239:      *         Article id
240:      * @param string $sTypeRange
241:      *         Comma separated list of CONTENIDO type ids
242:      *         which may be in the resulting list (e.g. '1', '17', '28')
243:      * 
244:      * @return int
245:      *         Number of items added
246:      * 
247:      * @throws cDbException
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:                     // Generate new option element
287:                     $oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . cString::getPartOfString(strip_tags($oDB->f("value")), 0, 50), $sTypeIdentifier);
288: 
289:                     // Add option element to the list
290:                     $this->addOptionElement($sTypeIdentifier, $oOption);
291:                 }
292:                 return $iCount;
293:             }
294:         } else {
295:             return false;
296:         }
297:     }
298: }
299: 
300: /**
301:  * Config table class.
302:  *
303:  * @package Core
304:  * @subpackage Util
305:  */
306: class UI_Config_Table {
307: 
308:     /**
309:      *
310:      * @var string
311:      */
312:     protected $_TplCellCode = '';
313: 
314:     /**
315:      *
316:      * @var string
317:      */
318:     protected $_TplTableFile = '';
319: 
320:     /**
321:      *
322:      * @var string
323:      */
324:     protected $_Width = '';
325: 
326:     /**
327:      *
328:      * @var int
329:      */
330:     protected $_Border = 0;
331: 
332:     /**
333:      *
334:      * @var string
335:      */
336:     protected $_BorderColor = '';
337: 
338:     /**
339:      *
340:      * @var string
341:      */
342:     protected $_SolidBorder = '';
343: 
344:     /**
345:      *
346:      * @var int
347:      */
348:     protected $_Padding = 0;
349: 
350:     /**
351:      *
352:      * @var array
353:      */
354:     protected $_Cells = array();
355: 
356:     /**
357:      *
358:      * @var array
359:      */
360:     protected $_CellAlignment = array();
361: 
362:     /**
363:      *
364:      * @var array
365:      */
366:     protected $_CellVAlignment = array();
367: 
368:     /**
369:      *
370:      * @var unknown_type
371:      */
372:     protected $_CellColSpan;
373: 
374:     /**
375:      *
376:      * @var array
377:      */
378:     protected $_CellClass = array();
379: 
380:     /**
381:      *
382:      * @var unknown_type
383:      */
384:     protected $_RowBgColor;
385: 
386:     /**
387:      *
388:      * @var unknown_type
389:      */
390:     protected $_RowExtra;
391: 
392:     /**
393:      *
394:      * @var bool
395:      */
396:     protected $_AddMultiSelJS = null;
397: 
398:     /**
399:      *
400:      * @var string
401:      */
402:     protected $_ColorLight = '';
403: 
404:     /**
405:      *
406:      * @var string
407:      */
408:     protected $_ColorDark = '';
409: 
410:     /**
411:      * Constructor to create an instance of this class.
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:      * Create a config table instance.
426:      * Old constructor
427:      *
428:      * @deprecated [2016-02-11]
429:      *              This method is deprecated and is not needed any longer.
430:      *              Please use __construct() as constructor function.
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:      * @param bool $bEnabled
439:      */
440:     function setAddMultiSelJS($bEnabled = true) {
441:         $this->_bAddMultiSelJS = (bool) $bEnabled;
442:     }
443: 
444:     /**
445:      *
446:      * @param string $code
447:      */
448:     public function setCellTemplate($code) {
449:         $this->_TplCellCode = $code;
450:     }
451: 
452:     /**
453:      *
454:      * @param string $path
455:      */
456:     public function setTableTemplateFile($path) {
457:         $this->_TplTableFile = $path;
458:     }
459: 
460:     /**
461:      * Set method for cells
462:      *
463:      * @param string $row
464:      * @param string $cell
465:      * @param string $content
466:      */
467:     public function setCell($row, $cell, $content) {
468:         $this->_Cells[$row][$cell] = $content;
469:         $this->_CellAlignment[$row][$cell] = "";
470:     }
471: 
472:     /**
473:      * Set method for cell alignment
474:      *
475:      * @param string $row
476:      * @param string $cell
477:      * @param unknown_type $alignment
478:      */
479:     protected function setCellAlignment($row, $cell, $alignment) {
480:         $this->_CellAlignment[$row][$cell] = $alignment;
481:     }
482: 
483:     /**
484:      * Set method for cell vertical alignment
485:      *
486:      * @param string $row
487:      * @param string $cell
488:      * @param unknown_type $alignment
489:      */
490:     public function setCellVAlignment($row, $cell, $alignment) {
491:         $this->_CellVAlignment[$row][$cell] = $alignment;
492:     }
493: 
494:     /**
495:      * Set method for cell class
496:      *
497:      * @param string $row
498:      * @param string $cell
499:      * @param unknown_type $class
500:      */
501:     public function setCellClass($row, $cell, $class) {
502:         $this->_CellClass[$row][$cell] = $class;
503:     }
504: 
505:     /**
506:      * Add inline javascript
507:      *
508:      * @return string
509:      */
510:     protected function _addMultiSelJS() {
511:         // Trick: To save multiple selections in <select>-Element,
512:         // add some JS which saves the selection, comma separated
513:         // in a hidden input field on change.
514:         // Try ... catch prevents error messages, if function is added
515:         // more than once if (!fncUpdateSel) in JS has not worked ...
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:      * Rendering function
544:      *
545:      * @param bool $print [optional]
546:      *
547:      * @return string|void
548:      *         Complete template string or nothing
549:      * 
550:      * @throws cInvalidArgumentException
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:                 // $dark = !$dark;
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:                     // Multi selection javascript
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:                 // Row
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: }
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0