Overview

Packages

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