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:  * @version    SVN Revision $Rev:$
 13:  *
 14:  * @author     Bjoern Behrens
 15:  * @copyright  four for business AG <www.4fb.de>
 16:  * @license    http://www.contenido.org/license/LIZENZ.txt
 17:  * @link       http://www.4fb.de
 18:  * @link       http://www.contenido.org
 19:  */
 20: 
 21: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 22: 
 23: /**
 24:  * Select box with additional functions for category and article selection
 25:  *
 26:  * @package Core
 27:  * @subpackage Util
 28:  */
 29: class cHTMLInputSelectElement extends cHTMLSelectElement {
 30: 
 31:     /**
 32:      * Constructor.
 33:      * Creates an HTML select field (aka 'DropDown').
 34:      *
 35:      * @param string $sName
 36:      *         Name of the element
 37:      * @param int $iWidth [optional]
 38:      *         Width of the select element
 39:      * @param string $sID [optional]
 40:      *         ID of the element
 41:      * @param string $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:      * Function addArticles.
 54:      * Adds articles to select box values.
 55:      *
 56:      * @param int $iIDCat
 57:      *         idcat of the category to be listed
 58:      * @param bool $bColored
 59:      *         Add color information to option elements
 60:      * @param bool $bArtOnline
 61:      *         If true, only online articles will be added
 62:      * @param string $sSpaces
 63:      *         Just some '&nbsp;' to show data hierarchically
 64:      *         (used in conjunction with addCategories)
 65:      * @return int
 66:      *         Number of items added
 67:      */
 68:     public function addArticles($iIDCat, $bColored = false, $bArtOnline = true, $sSpaces = '') {
 69:         global $cfg, $lang;
 70: 
 71:         $oDB = cRegistry::getDb();
 72: 
 73:         if (is_numeric($iIDCat) && $iIDCat > 0) {
 74:             $sql = "SELECT al.title AS title, al.idartlang AS idartlang, ca.idcat AS idcat,
 75:                         ca.idcatart AS idcatart, ca.is_start AS isstart, al.online AS online,
 76:                         cl.startidartlang AS idstartartlang
 77:                     FROM " . $cfg["tab"]["art_lang"] . " AS al, " . $cfg["tab"]["cat_art"] . " AS ca,
 78:                         " . $cfg["tab"]["cat_lang"] . " AS cl
 79:                     WHERE ca.idcat = '" . cSecurity::toInteger($iIDCat) . "' AND cl.idcat = ca.idcat
 80:                         AND cl.idlang = al.idlang AND ";
 81: 
 82:             if ($bArtOnline) {
 83:                 $sql .= "al.online = 1 AND ";
 84:             }
 85: 
 86:             $sql .= "al.idart = ca.idart AND al.idlang = " . (int) $lang . " ORDER BY al.title";
 87: 
 88:             $oDB->query($sql);
 89: 
 90:             $iCount = $oDB->numRows();
 91:             if ($iCount == 0) {
 92:                 return 0;
 93:             } else {
 94:                 $iCounter = count($this->_options);
 95:                 while ($oDB->nextRecord()) {
 96:                     // Generate new option element
 97:                     $oOption = new cHTMLOptionElement($sSpaces . '&nbsp;&nbsp;&nbsp;' . substr($oDB->f('title'), 0, 32), $oDB->f('idcatart'));
 98: 
 99:                     if ($bColored) {
100:                         if ($oDB->f('idstartartlang') == $oDB->f('idartlang')) {
101:                             if ($oDB->f('online') == 0) {
102:                                 // Start article, but offline -> red
103:                                 $oOption->setStyle('color: #ff0000;');
104:                             } else {
105:                                 // Start article -> blue
106:                                 $oOption->setStyle('color: #0000ff;');
107:                             }
108:                         } else if ($oDB->f('online') == 0) {
109:                             // Offline article -> grey
110:                             $oOption->setStyle('color: #666666;');
111:                         }
112:                     }
113: 
114:                     // Add option element to the list
115:                     $this->addOptionElement($iCounter, $oOption);
116:                     $iCounter++;
117:                 }
118:                 return $iCount;
119:             }
120:         } else {
121:             return 0;
122:         }
123:     }
124: 
125:     /**
126:      * Function addCategories.
127:      * Adds category elements (optionally including articles) to select box
128:      * values.
129:      * Note: Using 'with articles' adds the articles also - but the categories
130:      * will get a negative value!
131:      * There is no way to distinguish between a category id and an article id...
132:      *
133:      * @param int $iMaxLevel
134:      *         Max. level shown (to be exact: except this level)
135:      * @param bool $bColored
136:      *         Add color information to option elements
137:      * @param bool $bCatVisible
138:      *         If true, only add idcat as value, if cat is visible
139:      * @param bool $bCatPublic
140:      *         If true, only add idcat as value, if cat is public
141:      * @param bool $bWithArt
142:      *         Add also articles per category
143:      * @param bool $bArtOnline
144:      *         If true, show only online articles
145:      * @return int
146:      *         Number of items added
147:      */
148:     public function addCategories($iMaxLevel = 0, $bColored = false, $bCatVisible = true, $bCatPublic = true, $bWithArt = false, $bArtOnline = true) {
149:         global $cfg, $client, $lang;
150: 
151:         $oDB = cRegistry::getDb();
152: 
153:         $sql = "SELECT c.idcat AS idcat, cl.name AS name, cl.visible AS visible, cl.public AS public, ct.level AS level
154:                 FROM " . $cfg["tab"]["cat"] . " AS c, " . $cfg["tab"]["cat_lang"] . " AS cl, " . $cfg["tab"]["cat_tree"] . " AS ct
155:                 WHERE c.idclient = " . (int) $client . " AND cl.idlang = " . (int) $lang . " AND cl.idcat = c.idcat AND ct.idcat = c.idcat ";
156:         if ($iMaxLevel > 0) {
157:             $sql .= "AND ct.level < " . (int) $iMaxLevel . " ";
158:         }
159:         $sql .= "ORDER BY ct.idtree";
160: 
161:         $oDB->query($sql);
162: 
163:         $iCount = $oDB->numRows();
164:         if ($iCount == 0) {
165:             return false;
166:         } else {
167:             $iCounter = count($this->_options);
168:             while ($oDB->nextRecord()) {
169:                 $sSpaces = '';
170:                 $sStyle = '';
171:                 $iID = $oDB->f('idcat');
172: 
173:                 for ($i = 0; $i < $oDB->f('level'); $i++) {
174:                     $sSpaces .= '&nbsp;&nbsp;&nbsp;';
175:                 }
176: 
177:                 // Generate new option element
178:                 if (($bCatVisible && $oDB->f('visible') == 0) || ($bCatPublic && $oDB->f('public') == 0)) {
179:                     // If category has to be visible or public and it isn't,
180:                     // don't add value
181:                     $sValue = '';
182:                 } else if ($bWithArt) {
183:                     // If article will be added, set negative idcat as value
184:                     $sValue = '-' . $iID;
185:                 } else {
186:                     // Show only categories - and everything is fine...
187:                     $sValue = $iID;
188:                 }
189:                 $oOption = new cHTMLOptionElement($sSpaces . '>&nbsp;' . $oDB->f('name'), $sValue);
190: 
191:                 // Coloring option element, restricted shows grey color
192:                 $oOption->setStyle('background-color: #EFEFEF');
193:                 if ($bColored && ($oDB->f('visible') == 0 || $oDB->f('public') == 0)) {
194:                     $oOption->setStyle('color: #666666;');
195:                 }
196: 
197:                 // Add option element to the list
198:                 $this->addOptionElement($iCounter, $oOption);
199: 
200:                 if ($bWithArt) {
201:                     $iArticles = $this->addArticles($iID, $bColored, $bArtOnline, $sSpaces);
202:                     $iCount += $iArticles;
203:                 }
204:                 $iCounter = count($this->_options);
205:             }
206:         }
207:         return $iCount;
208:     }
209: 
210:     /**
211:      * Function addTypesFromArt.
212:      * Adds types and type ids which are available for the specified article
213:      *
214:      * @param int $iIDCatArt
215:      *         Article id
216:      * @param string $sTypeRange
217:      *         Comma separated list of CONTENIDO type ids
218:      *         which may be in the resulting list (e.g. '1', '17', '28')
219:      * @return int
220:      *         Number of items added
221:      */
222:     public function addTypesFromArt($iIDCatArt, $sTypeRange = '') {
223:         global $cfg, $lang;
224: 
225:         $oDB = cRegistry::getDb();
226: 
227:         if (is_numeric($iIDCatArt) && $iIDCatArt > 0) {
228:             $sql = "SELECT t.typeid AS typeid, t.idtype AS idtype, t.type AS type, t.description AS description, t.value AS value
229:                     FROM " . $cfg["tab"]["content"] . " AS t, " . $cfg["tab"]["art_lang"] . " AS al,
230:                          " . $cfg["tab"]["cat_art"] . " AS ca, " . $cfg["tab"]["type"] . " AS t
231:                     WHERE t.idtype = t.idtype AND t.idartlang = al.idartlang AND al.idart = ca.idart
232:                         AND al.idlang = " . (int) $lang . " AND ca.idcatart = " . (int) $iIDCatArt . " ";
233: 
234:             if ($sTypeRange != "") {
235:                 $sql .= "AND t.idtype IN (" . $oDB->escape($sTypeRange) . ") ";
236:             }
237: 
238:             $sql .= "ORDER BY t.idtype, t.typeid";
239: 
240:             $oDB->query($sql);
241: 
242:             $iCount = $oDB->numRows();
243:             if ($iCount == 0) {
244:                 return false;
245:             } else {
246:                 while ($oDB->nextRecord()) {
247:                     $sTypeIdentifier = "tblData.idtype = '" . $oDB->f('idtype') . "' AND tblData.typeid = '" . $oDB->f('typeid') . "'";
248: 
249:                     // Generate new option element
250:                     $oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . substr(strip_tags($oDB->f("value")), 0, 50), $sTypeIdentifier);
251: 
252:                     // Add option element to the list
253:                     $this->addOptionElement($sTypeIdentifier, $oOption);
254:                 }
255:                 return $iCount;
256:             }
257:         } else {
258:             return false;
259:         }
260:     }
261: 
262:     /**
263:      * Selects specified elements as selected
264:      *
265:      * @param array $aElements
266:      *         Array with "values" of the cHTMLOptionElement to set
267:      * @return cHTMLSelectElement
268:      *         $this for chaining
269:      */
270:     public function setSelected($aElements) {
271:         if (is_array($this->_options) && is_array($aElements)) {
272:             foreach ($this->_options as $sKey => $oOption) {
273:                 if (in_array($oOption->getAttribute("value"), $aElements)) {
274:                     $oOption->setSelected(true);
275:                     $this->_options[$sKey] = $oOption;
276:                 } else {
277:                     $oOption->setSelected(false);
278:                     $this->_options[$sKey] = $oOption;
279:                 }
280:             }
281:         }
282:         return $this;
283:     }
284: 
285: }
286: 
287: /**
288:  * Config table class.
289:  *
290:  * @package Core
291:  * @subpackage Util
292:  */
293: class UI_Config_Table {
294: 
295:     /**
296:      *
297:      * @var string
298:      */
299:     var $_sTplCellCode;
300: 
301:     /**
302:      *
303:      * @var string
304:      */
305:     var $_sTplTableFile;
306: 
307:     /**
308:      *
309:      * @var string
310:      */
311:     var $_sWidth;
312: 
313:     /**
314:      *
315:      * @var int
316:      */
317:     var $_sBorder;
318: 
319:     /**
320:      *
321:      * @var string
322:      */
323:     var $_sBorderColor;
324: 
325:     /**
326:      *
327:      * @var string
328:      */
329:     var $_bSolidBorder;
330: 
331:     /**
332:      *
333:      * @var int
334:      */
335:     var $_sPadding;
336: 
337:     /**
338:      *
339:      * @var array
340:      */
341:     var $_aCells;
342: 
343:     /**
344:      *
345:      * @var array
346:      */
347:     var $_aCellAlignment;
348: 
349:     /**
350:      *
351:      * @var array
352:      */
353:     var $_aCellVAlignment;
354: 
355:     /**
356:      *
357:      * @var unknown_type
358:      */
359:     var $_aCellColSpan;
360: 
361:     /**
362:      *
363:      * @var array
364:      */
365:     var $_aCellClass;
366: 
367:     /**
368:      *
369:      * @var unknown_type
370:      */
371:     var $_aRowBgColor;
372: 
373:     /**
374:      *
375:      * @var unknown_type
376:      */
377:     var $_aRowExtra;
378: 
379:     /**
380:      *
381:      * @var bool
382:      */
383:     var $_bAddMultiSelJS;
384: 
385:     /**
386:      *
387:      * @var unknown_type
388:      */
389:     var $_sColorLight;
390: 
391:     /**
392:      *
393:      * @var unknown_type
394:      */
395:     var $_sColorDark;
396: 
397:     /**
398:      * Create a config table instance.
399:      */
400:     function UI_Config_Table() {
401:         global $cfg;
402:         $backendPath = cRegistry::getBackendPath();
403: 
404:         $this->_sPadding = 2;
405:         $this->_sBorder = 0;
406:         $this->_sTplCellCode = '        <td align="{ALIGN}" valign="{VALIGN}" class="{CLASS}" colspan="{COLSPAN}" style="{EXTRA}white-space:nowrap;" nowrap="nowrap">{CONTENT}</td>' . "\n";
407:         $this->_sTplTableFile = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper'];
408:         $this->_sTplCellCode =  $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper_row'];
409:     }
410: 
411:     /**
412:      *
413:      * @param string $sCode
414:      */
415:     function setCellTemplate($sCode) {
416:         $this->_sTplCellCode = $sCode;
417:     }
418: 
419:     /**
420:      *
421:      * @param string $sPath
422:      */
423:     function setTableTemplateFile($sPath) {
424:         $this->_sTplTableFile = $sPath;
425:     }
426: 
427:     /**
428:      *
429:      * @param unknown_type $sRow
430:      * @param unknown_type $sCell
431:      * @param unknown_type $sContent
432:      */
433:     function setCell($sRow, $sCell, $sContent) {
434:         $this->_aCells[$sRow][$sCell] = $sContent;
435:         $this->_aCellAlignment[$sRow][$sCell] = "";
436:     }
437: 
438:     /**
439:      *
440:      * @param unknown_type $sRow
441:      * @param unknown_type $sCell
442:      * @param unknown_type $sAlignment
443:      */
444:     function setCellAlignment($sRow, $sCell, $sAlignment) {
445:         $this->_aCellAlignment[$sRow][$sCell] = $sAlignment;
446:     }
447: 
448:     /**
449:      *
450:      * @param unknown_type $sRow
451:      * @param unknown_type $sCell
452:      * @param unknown_type $sAlignment
453:      */
454:     function setCellVAlignment($sRow, $sCell, $sAlignment) {
455:         $this->_aCellVAlignment[$sRow][$sCell] = $sAlignment;
456:     }
457: 
458:     /**
459:      *
460:      * @param unknown_type $sRow
461:      * @param unknown_type $sCell
462:      * @param unknown_type $sClass
463:      */
464:     function setCellClass($sRow, $sCell, $sClass) {
465:         $this->_aCellClass[$sRow][$sCell] = $sClass;
466:     }
467: 
468:     /**
469:      *
470:      * @return string
471:      */
472:     function _addMultiSelJS() {
473:         // Trick: To save multiple selections in <select>-Element, add some JS
474:         // which saves the
475:         // selection, comma separated in a hidden input field on change.
476:         // Try ... catch prevents error messages, if function is added more than
477:         // once
478:         // if (!fncUpdateSel) in JS has not worked...
479:         $sSkript = '
480: <script type="text/javascript"><!--
481: try {
482:     function fncUpdateSel(sSelectBox, sStorage) {
483:         var sSelection = "";
484:         var oSelectBox = document.getElementsByName(sSelectBox)[0];
485:         var oStorage   = document.getElementsByName(sStorage)[0];
486:         if (oSelectBox && oStorage) {
487:             for (i = 0; i < oSelectBox.length; i++) {
488:                 if (oSelectBox.options[i].selected == true) {
489:                     if (sSelection != "") {
490:                         sSelection = sSelection + ",";
491:                     }
492:                     sSelection = sSelection + oSelectBox.options[i].value;
493:                 }
494:             }
495:             oStorage.value = sSelection;
496:         }
497:     }
498: } catch (e) { }
499: //--></script>
500: ';
501: 
502:         return $sSkript;
503:     }
504: 
505:     /**
506:      *
507:      * @param unknown_type $bPrint [optional]
508:      * @return string|void
509:      *         Complete template string or nothing
510:      */
511:     function render($bPrint = false) {
512:         $oTable = new cTemplate();
513:         $oTable->reset();
514: 
515:         $iColCount = 0;
516:         $bDark = false;
517:         $sBgColor = "";
518:         $bMultiSelJSAdded = false;
519:         if (is_array($this->_aCells)) {
520:             foreach ($this->_aCells as $sRow => $aCells) {
521:                 $iColCount++;
522:                 // $bDark = !$bDark;
523:                 $sLine = '';
524:                 $iCount = 0;
525: 
526:                 foreach ($aCells as $sCell => $sData) {
527:                     $iCount++;
528:                     $tplCell = new cTemplate();
529:                     $tplCell->reset();
530: 
531:                     if ($this->_aCellClass[$sRow][$sCell] != '') {
532:                         $tplCell->set('s', 'CLASS', $this->_aCellClass[$sRow][$sCell]);
533:                     } else {
534:                         $tplCell->set('s', 'CLASS', '');
535:                     }
536: 
537:                     if ($this->_aCellAlignment[$sRow][$sCell] != '') {
538:                         $tplCell->set('s', 'ALIGN', $this->_aCellAlignment[$sRow][$sCell]);
539:                     } else {
540:                         $tplCell->set('s', 'ALIGN', 'left');
541:                     }
542: 
543:                     if ($this->_aCellVAlignment[$sRow][$sCell] != '') {
544:                         $tplCell->set('s', 'VALIGN', $this->_aCellAlignment[$sRow][$sCell]);
545:                     } else {
546:                         $tplCell->set('s', 'VALIGN', 'top');
547:                     }
548: 
549:                     // Multi selection javascript
550:                     if ($this->_bAddMultiSelJS) {
551:                         $sData = $this->_addMultiSelJS() . $sData;
552:                         $this->_bAddMultiSelJS = false;
553:                     }
554: 
555:                     $tplCell->set('s', 'CONTENT', $sData);
556:                     $sLine .= $tplCell->generate($this->_sTplCellCode, true, false);
557:                 }
558: 
559:                 // Row
560:                 $oTable->set('d', 'ROWS', $sLine);
561: 
562:                 $oTable->next();
563:             }
564:         }
565:         $sRendered = $oTable->generate($this->_sTplTableFile, true, false);
566: 
567:         if ($bPrint == true) {
568:             echo $sRendered;
569:         } else {
570:             return $sRendered;
571:         }
572:     }
573: 
574: }
575: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0