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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiPathresolveCacheHelper
  • cArray
  • cArticleCollector
  • cDirHandler
  • cFileHandler
  • cHTMLInputSelectElement
  • cIterator
  • cString
  • cZipArchive
  • UI_Config_Table
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the the input helper classes.
  4:  * Various derived HTML class elements especially useful
  5:  * in the input area of modules
  6:  * Simple table generation class especially useful to generate
  7:  * backend configuration table. May be used also in Frontend,
  8:  * but note the globally used variables ($cfg)
  9:  *
 10:  * @package    Core
 11:  * @subpackage Util
 12:  * @author     Bjoern Behrens
 13:  * @copyright  four for business AG <www.4fb.de>
 14:  * @license    http://www.contenido.org/license/LIZENZ.txt
 15:  * @link       http://www.4fb.de
 16:  * @link       http://www.contenido.org
 17:  */
 18: 
 19: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 20: 
 21: /**
 22:  * Select box with additional functions for category and article selection
 23:  *
 24:  * @package Core
 25:  * @subpackage Util
 26:  */
 27: class cHTMLInputSelectElement extends cHTMLSelectElement {
 28: 
 29:     /**
 30:      * Constructor to create an instance of this class.
 31:      *
 32:      * Creates an HTML select field (aka 'DropDown').
 33:      *
 34:      * @param string $sName
 35:      *         Name of the element
 36:      * @param int $iWidth [optional]
 37:      *         Width of the select element
 38:      * @param string $sID [optional]
 39:      *         ID of the element
 40:      * @param string $bDisabled [optional]
 41:      *         Item disabled flag (non-empty to set disabled)
 42:      * @param int $iTabIndex [optional]
 43:      *         Tab index for form elements
 44:      * @param string $sAccessKey [optional]
 45:      *         Key to access the field
 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:      * Function addArticles.
 53:      * Adds articles to select box values.
 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:      * @return int
 65:      *         Number of items added
 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:                     // Generate new option element
 96:                     $oOption = new cHTMLOptionElement($sSpaces . '&nbsp;&nbsp;&nbsp;' . 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:                                 // Start article, but offline -> red
102:                                 $oOption->setStyle('color: #ff0000;');
103:                             } else {
104:                                 // Start article -> blue
105:                                 $oOption->setStyle('color: #0000ff;');
106:                             }
107:                         } else if ($oDB->f('online') == 0) {
108:                             // Offline article -> grey
109:                             $oOption->setStyle('color: #666666;');
110:                         }
111:                     }
112: 
113:                     // Add option element to the list
114:                     $this->addOptionElement($iCounter, $oOption);
115:                     $iCounter++;
116:                 }
117:                 return $iCount;
118:             }
119:         } else {
120:             return 0;
121:         }
122:     }
123: 
124:     /**
125:      * Function addCategories.
126:      * Adds category elements (optionally including articles) to select box
127:      * values.
128:      * Note: Using 'with articles' adds the articles also - but the categories
129:      * will get a negative value!
130:      * There is no way to distinguish between a category id and an article id...
131:      *
132:      * @param int $iMaxLevel
133:      *         Max. level shown (to be exact: except this level)
134:      * @param bool $bColored
135:      *         Add color information to option elements
136:      * @param bool $bCatVisible
137:      *         If true, only add idcat as value, if cat is visible
138:      * @param bool $bCatPublic
139:      *         If true, only add idcat as value, if cat is public
140:      * @param bool $bWithArt
141:      *         Add also articles per category
142:      * @param bool $bArtOnline
143:      *         If true, show only online articles
144:      * @return int
145:      *         Number of items added
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 .= '&nbsp;&nbsp;&nbsp;';
174:                 }
175: 
176:                 // Generate new option element
177:                 if (($bCatVisible && $oDB->f('visible') == 0) || ($bCatPublic && $oDB->f('public') == 0)) {
178:                     // If category has to be visible or public and it isn't,
179:                     // don't add value
180:                     $sValue = '';
181:                 } else if ($bWithArt) {
182:                     // If article will be added, set negative idcat as value
183:                     $sValue = '-' . $iID;
184:                 } else {
185:                     // Show only categories - and everything is fine...
186:                     $sValue = $iID;
187:                 }
188:                 $oOption = new cHTMLOptionElement($sSpaces . '>&nbsp;' . $oDB->f('name'), $sValue);
189: 
190:                 // Coloring option element, restricted shows grey color
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:                 // Add option element to the list
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:      * Function addTypesFromArt.
211:      * Adds types and type ids which are available for the specified article
212:      *
213:      * @param int $iIDCatArt
214:      *         Article id
215:      * @param string $sTypeRange
216:      *         Comma separated list of CONTENIDO type ids
217:      *         which may be in the resulting list (e.g. '1', '17', '28')
218:      * @return int
219:      *         Number of items added
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:                     // Generate new option element
249:                     $oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . substr(strip_tags($oDB->f("value")), 0, 50), $sTypeIdentifier);
250: 
251:                     // Add option element to the list
252:                     $this->addOptionElement($sTypeIdentifier, $oOption);
253:                 }
254:                 return $iCount;
255:             }
256:         } else {
257:             return false;
258:         }
259:     }
260: 
261:     /**
262:      * Selects specified elements as selected
263:      *
264:      * @param array $aElements
265:      *         Array with "values" of the cHTMLOptionElement to set
266:      * @return cHTMLSelectElement
267:      *         $this for chaining
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:  * Config table class.
288:  *
289:  * @package Core
290:  * @subpackage Util
291:  */
292: class UI_Config_Table {
293: 
294:     /**
295:      *
296:      * @var string
297:      */
298:     protected $_TplCellCode = '';
299: 
300:     /**
301:      *
302:      * @var string
303:      */
304:     protected $_TplTableFile = '';
305: 
306:     /**
307:      *
308:      * @var string
309:      */
310:     protected $_Width = '';
311: 
312:     /**
313:      *
314:      * @var int
315:      */
316:     protected $_Border = 0;
317: 
318:     /**
319:      *
320:      * @var string
321:      */
322:     protected $_BorderColor = '';
323: 
324:     /**
325:      *
326:      * @var string
327:      */
328:     protected $_SolidBorder = '';
329: 
330:     /**
331:      *
332:      * @var int
333:      */
334:     protected $_Padding = 0;
335: 
336:     /**
337:      *
338:      * @var array
339:      */
340:     protected $_Cells = array();
341: 
342:     /**
343:      *
344:      * @var array
345:      */
346:     protected $_CellAlignment = array();
347: 
348:     /**
349:      *
350:      * @var array
351:      */
352:     protected $_CellVAlignment = array();
353: 
354:     /**
355:      *
356:      * @var unknown_type
357:      */
358:     protected $_CellColSpan;
359: 
360:     /**
361:      *
362:      * @var array
363:      */
364:     protected $_CellClass = array();
365: 
366:     /**
367:      *
368:      * @var unknown_type
369:      */
370:     protected $_RowBgColor;
371: 
372:     /**
373:      *
374:      * @var unknown_type
375:      */
376:     protected $_RowExtra;
377: 
378:     /**
379:      *
380:      * @var bool
381:      */
382:     protected $_AddMultiSelJS = null;
383: 
384:     /**
385:      *
386:      * @var string
387:      */
388:     protected $_ColorLight = '';
389: 
390:     /**
391:      *
392:      * @var string
393:      */
394:     protected $_ColorDark = '';
395: 
396:     /**
397:      * Constructor to create an instance of this class.
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:      * Create a config table instance.
412:      * Old constructor
413:      *
414:      * @deprecated [2016-02-11]
415:      *              This method is deprecated and is not needed any longer.
416:      *              Please use __construct() as constructor function.
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:      * @param string $code
426:      */
427:     public function setCellTemplate($code) {
428:         $this->_TplCellCode = $code;
429:     }
430: 
431:     /**
432:      *
433:      * @param string $path
434:      */
435:     public function setTableTemplateFile($path) {
436:         $this->_TplTableFile = $path;
437:     }
438: 
439:     /**
440:      * Set method for cells
441:      *
442:      * @param string $row
443:      * @param string $cell
444:      * @param string $content
445:      */
446:     public function setCell($row, $cell, $content) {
447:         $this->_Cells[$row][$cell] = $content;
448:         $this->_CellAlignment[$row][$cell] = "";
449:     }
450: 
451:     /**
452:      * Set method for cell alignment
453:      *
454:      * @param string $row
455:      * @param string $cell
456:      * @param unknown_type $alignment
457:      */
458:     protected function setCellAlignment($row, $cell, $alignment) {
459:         $this->_CellAlignment[$row][$cell] = $alignment;
460:     }
461: 
462:     /**
463:      * Set method for cell vertical alignment
464:      *
465:      * @param string $row
466:      * @param string $cell
467:      * @param unknown_type $alignment
468:      */
469:     public function setCellVAlignment($row, $cell, $alignment) {
470:         $this->_CellVAlignment[$row][$cell] = $alignment;
471:     }
472: 
473:     /**
474:      * Set method for cell class
475:      *
476:      * @param string $row
477:      * @param string $cell
478:      * @param unknown_type $class
479:      */
480:     public function setCellClass($row, $cell, $class) {
481:         $this->_CellClass[$row][$cell] = $class;
482:     }
483: 
484:     /**
485:      * Add inline javascript
486:      *
487:      * @return string
488:      */
489:     protected function _addMultiSelJS() {
490:         // Trick: To save multiple selections in <select>-Element,
491:         // add some JS which saves the selection, comma separated
492:         // in a hidden input field on change.
493:         // Try ... catch prevents error messages, if function is added
494:         // more than once if (!fncUpdateSel) in JS has not worked ...
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:      * Rendering function
523:      *
524:      * @param bool $print [optional]
525:      * @return string|void
526:      *         Complete template string or nothing
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:                 // $dark = !$dark;
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:                     // Multi selection javascript
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:                 // Row
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: }
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0