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
    • SIWECOS
    • 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:      * @var string
310:      */
311:     protected $_tplCellCode = '';
312: 
313:     /**
314:      * @var string
315:      */
316:     protected $_tplTableFile = '';
317: 
318:     /**
319:      * @var string
320:      */
321:     protected $_width = '';
322: 
323:     /**
324:      * @var int
325:      */
326:     protected $_border = 0;
327: 
328:     /**
329:      * @var string
330:      */
331:     protected $_borderColor = '';
332: 
333:     /**
334:      * @var string
335:      */
336:     protected $_solidBorder = '';
337: 
338:     /**
339:      * @var int
340:      */
341:     protected $_padding = 0;
342: 
343:     /**
344:      * @var array
345:      */
346:     protected $_cells = [];
347: 
348:     /**
349:      * @var array
350:      */
351:     protected $_cellAlignment = [];
352: 
353:     /**
354:      * @var array
355:      */
356:     protected $_cellVAlignment = [];
357: 
358:     /**
359:      * @var string
360:      */
361:     protected $_cellColSpan;
362: 
363:     /**
364:      * @var array
365:      */
366:     protected $_cellClass = [];
367: 
368:     /**
369:      * @var string
370:      */
371:     protected $_rowBgColor;
372: 
373:     /**
374:      * @var string
375:      */
376:     protected $_rowExtra;
377: 
378:     /**
379:      * @var bool
380:      */
381:     protected $_addMultiSelJS = false;
382: 
383:     /**
384:      * @var string
385:      */
386:     protected $_colorLight = '';
387: 
388:     /**
389:      * @var string
390:      */
391:     protected $_colorDark = '';
392: 
393:     /**
394:      * Constructor to create an instance of this class.
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:      * @param string $code
409:      */
410:     public function setCellTemplate($code)
411:     {
412:         $this->_tplCellCode = $code;
413:     }
414: 
415:     /**
416:      * @param string $path
417:      */
418:     public function setTableTemplateFile($path)
419:     {
420:         $this->_tplTableFile = $path;
421:     }
422: 
423:     /**
424:      * Set method for cells
425:      *
426:      * @param string $row
427:      * @param string $cell
428:      * @param string $content
429:      */
430:     public function setCell($row, $cell, $content)
431:     {
432:         $this->_cells[$row][$cell]         = $content;
433:         $this->_cellAlignment[$row][$cell] = "";
434:     }
435: 
436:     /**
437:      * Set method for cell alignment
438:      *
439:      * @param string       $row
440:      * @param string       $cell
441:      * @param string $alignment
442:      */
443:     protected function setCellAlignment($row, $cell, $alignment)
444:     {
445:         $this->_cellAlignment[$row][$cell] = $alignment;
446:     }
447: 
448:     /**
449:      * Set method for cell vertical alignment
450:      *
451:      * @param string       $row
452:      * @param string       $cell
453:      * @param string $alignment
454:      */
455:     public function setCellVAlignment($row, $cell, $alignment)
456:     {
457:         $this->_cellVAlignment[$row][$cell] = $alignment;
458:     }
459: 
460:     /**
461:      * Set method for cell class
462:      *
463:      * @param string       $row
464:      * @param string       $cell
465:      * @param string $class
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:      * Add inline javascript
481:      *
482:      * @internal Trick: To save multiple selections in <select>-Element,
483:      * add some JS which saves the selection, comma separated
484:      * in a hidden input field on change.
485:      * Try ... catch prevents error messages, if function is added
486:      * more than once if (!fncUpdateSel) in JS has not worked ...
487:      *
488:      * @return string
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:      * Rendering function
520:      *
521:      * @param bool $print [optional]
522:      *
523:      * @return string|null
524:      *         Complete template string or nothing
525:      *
526:      * @throws cInvalidArgumentException
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:                 // $dark = !$dark;
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:                     // add multi selection javascript
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:                 // Row
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: }
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0