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
    • NavigationMain
    • 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
  • 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:             $sSQL = "SELECT tblArtLang.title AS title, tblArtLang.idartlang AS idartlang, tblCatArt.idcat AS idcat, ";
 66:             $sSQL .= "tblCatArt.idcatart AS idcatart, tblCatArt.is_start AS isstart, tblArtLang.online AS online, ";
 67:             $sSQL .= "tblCatLang.startidartlang as idstartartlang ";
 68:             $sSQL .= "FROM " . $cfg["tab"]["art_lang"] . " AS tblArtLang, " . $cfg["tab"]["cat_art"] . " AS tblCatArt, ";
 69:             $sSQL .= $cfg["tab"]["cat_lang"] . " AS tblCatLang ";
 70:             $sSQL .= "WHERE tblCatArt.idcat = '" . cSecurity::toInteger($iIDCat) . "' AND tblCatLang.idcat = tblCatArt.idcat AND tblCatLang.idlang = tblArtLang.idlang AND ";
 71: 
 72:             if ($bArtOnline) {
 73:                 $sSQL .= "tblArtLang.online = '1' AND ";
 74:             }
 75: 
 76:             $sSQL .= "tblArtLang.idart = tblCatArt.idart AND tblArtLang.idlang = '" . cSecurity::escapeDB($lang, $oDB) . "' ORDER BY tblArtLang.title";
 77: 
 78:             $oDB->query($sSQL);
 79: 
 80:             $iCount = $oDB->numRows();
 81:             if ($iCount == 0) {
 82:                 return 0;
 83:             } else {
 84:                 $iCounter = count($this->_options);
 85:                 while ($oDB->nextRecord()) {
 86:                     // Generate new option element
 87:                     $oOption = new cHTMLOptionElement($sSpaces . "&nbsp;&nbsp;&nbsp;" . substr($oDB->f("title"), 0, 32), $oDB->f("idcatart"));
 88: 
 89:                     if ($bColored) {
 90:                         if ($oDB->f("idstartartlang") == $oDB->f("idartlang")) {
 91:                             if ($oDB->f("online") == 0) {
 92:                                 // Start article, but offline -> red
 93:                                 $oOption->setStyle("color: #ff0000;");
 94:                             } else {
 95:                                 // Start article -> blue
 96:                                 $oOption->setStyle("color: #0000ff;");
 97:                             }
 98:                         } else if ($oDB->f("online") == 0) {
 99:                             // Offline article -> grey
100:                             $oOption->setStyle("color: #666666;");
101:                         }
102:                     }
103: 
104:                     // Add option element to the list
105:                     $this->addOptionElement($iCounter, $oOption);
106:                     $iCounter++;
107:                 }
108:                 return $iCount;
109:             }
110:         } else {
111:             return 0;
112:         }
113:     }
114: 
115:     /**
116:      * Function addCategories.
117:      * Adds category elements (optionally including articles) to select box
118:      * values.
119:      * Note: Using "with articles" adds the articles also - but the categories
120:      * will get a negative value!
121:      * There is no way to distinguish between a category id and an article id...
122:      *
123:      * @param int $iMaxLevel Max. level shown (to be exact: except this level)
124:      * @param bool $bColored Add color information to option elements
125:      * @param bool $bCatVisible If true, only add idcat as value, if cat is
126:      *        visible
127:      * @param bool $bCatPublic If true, only add idcat as value, if cat is
128:      *        public
129:      * @param bool $bWithArt Add also articles per category
130:      * @param bool $bArtOnline If true, show only online articles
131:      *
132:      * @return int Number of items added
133:      *
134:      */
135:     public function addCategories($iMaxLevel = 0, $bColored = false, $bCatVisible = true, $bCatPublic = true, $bWithArt = false, $bArtOnline = true) {
136:         global $cfg, $client, $lang;
137: 
138:         $oDB = cRegistry::getDb();
139: 
140:         $sSQL = "SELECT tblCat.idcat AS idcat, tblCatLang.name AS name, ";
141:         $sSQL .= "tblCatLang.visible AS visible, tblCatLang.public AS public, tblCatTree.level AS level ";
142:         $sSQL .= "FROM " . $cfg["tab"]["cat"] . " AS tblCat, " . $cfg["tab"]["cat_lang"] . " AS tblCatLang, ";
143:         $sSQL .= $cfg["tab"]["cat_tree"] . " AS tblCatTree ";
144:         $sSQL .= "WHERE tblCat.idclient = '" . cSecurity::escapeDB($client, $oDB) . "' AND tblCatLang.idlang = '" . cSecurity::escapeDB($lang, $oDB) . "' AND ";
145:         $sSQL .= "tblCatLang.idcat = tblCat.idcat AND tblCatTree.idcat = tblCat.idcat ";
146: 
147:         if ($iMaxLevel > 0) {
148:             $sSQL .= "AND tblCatTree.level < '" . cSecurity::escapeDB($iMaxLevel, $oDB) . "' ";
149:         }
150:         $sSQL .= "ORDER BY tblCatTree.idtree";
151: 
152:         $oDB->query($sSQL);
153: 
154:         $iCount = $oDB->numRows();
155:         if ($iCount == 0) {
156:             return false;
157:         } else {
158:             $iCounter = count($this->_options);
159:             while ($oDB->nextRecord()) {
160:                 $sSpaces = "";
161:                 $sStyle = "";
162:                 $iID = $oDB->f("idcat");
163: 
164:                 for ($i = 0; $i < $oDB->f("level"); $i++) {
165:                     $sSpaces .= "&nbsp;&nbsp;&nbsp;";
166:                 }
167: 
168:                 // Generate new option element
169:                 if (($bCatVisible && $oDB->f("visible") == 0) || ($bCatPublic && $oDB->f("public") == 0)) {
170:                     // If category has to be visible or public and it isn't,
171:                     // don't add value
172:                     $sValue = "";
173:                 } else if ($bWithArt) {
174:                     // If article will be added, set negative idcat as value
175:                     $sValue = "-" . $iID;
176:                 } else {
177:                     // Show only categories - and everything is fine...
178:                     $sValue = $iID;
179:                 }
180:                 $oOption = new cHTMLOptionElement($sSpaces . ">&nbsp;" . $oDB->f("name"), $sValue);
181: 
182:                 // Coloring option element, restricted shows grey color
183:                 $oOption->setStyle("background-color: #EFEFEF");
184:                 if ($bColored && ($oDB->f("visible") == 0 || $oDB->f("public") == 0)) {
185:                     $oOption->setStyle("color: #666666;");
186:                 }
187: 
188:                 // Add option element to the list
189:                 $this->addOptionElement($iCounter, $oOption);
190: 
191:                 if ($bWithArt) {
192:                     $iArticles = $this->addArticles($iID, $bColored, $bArtOnline, $sSpaces);
193:                     $iCount += $iArticles;
194:                 }
195:                 $iCounter = count($this->_options);
196:             }
197:         }
198:         return $iCount;
199:     }
200: 
201:     /**
202:      * Function addTypesFromArt.
203:      * Adds types and type ids which are available for the specified article
204:      *
205:      * @param int $iIDCatArt Article id
206:      * @param string $sTypeRange Komma separated list of CONTENIDO type ids
207:      *        which may be in the resulting list (e.g. '1','17','28')
208:      *
209:      * @return int Number of items added
210:      *
211:      */
212:     public function addTypesFromArt($iIDCatArt, $sTypeRange = "") {
213:         global $cfg, $lang;
214: 
215:         $oDB = cRegistry::getDb();
216: 
217:         if (is_numeric($iIDCatArt) && $iIDCatArt > 0) {
218:             $sSQL = "SELECT tblContent.typeid AS typeid, tblContent.idtype AS idtype, tblType.type AS type, tblType.description AS description, ";
219:             $sSQL .= "tblContent.value AS value ";
220:             $sSQL .= "FROM " . $cfg["tab"]["content"] . " AS tblContent, " . $cfg["tab"]["art_lang"] . " AS tblArtLang, ";
221:             $sSQL .= $cfg["tab"]["cat_art"] . " AS tblCatArt, " . $cfg["tab"]["type"] . " AS tblType ";
222:             $sSQL .= "WHERE tblContent.idtype = tblType.idtype AND tblContent.idartlang = tblArtLang.idartlang AND ";
223:             $sSQL .= "tblArtLang.idart = tblCatArt.idart AND tblArtLang.idlang = '" . cSecurity::escapeDB($lang, $oDB) . "' AND tblCatArt.idcatart = '" . cSecurity::toInteger($iIDCatArt) . "' ";
224: 
225:             if ($sTypeRange != "") {
226:                 $sSQL .= "AND tblContent.idtype IN (" . cSecurity::escapeDB($sTypeRange, $oDB) . ") ";
227:             }
228: 
229:             $sSQL .= "ORDER BY tblContent.idtype, tblContent.typeid";
230: 
231:             $oDB->query($sSQL);
232: 
233:             $iCount = $oDB->numRows();
234:             if ($iCount == 0) {
235:                 return false;
236:             } else {
237:                 while ($oDB->nextRecord()) {
238:                     $sTypeIdentifier = "tblData.idtype = '" . $oDB->f('idtype') . "' AND tblData.typeid = '" . $oDB->f('typeid') . "'";
239: 
240:                     // Generate new option element
241:                     $oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . substr(strip_tags($oDB->f("value")), 0, 50), $sTypeIdentifier);
242: 
243:                     // Add option element to the list
244:                     $this->addOptionElement($sTypeIdentifier, $oOption);
245:                 }
246:                 return $iCount;
247:             }
248:         } else {
249:             return false;
250:         }
251:     }
252: 
253:     /**
254:      * Selects specified elements as selected
255:      *
256:      * @param array $aElements Array with "values" of the cHTMLOptionElement to
257:      *        set
258:      *
259:      * @return none
260:      */
261:     public function setSelected($aElements) {
262:         if (is_array($this->_options) && is_array($aElements)) {
263:             foreach ($this->_options as $sKey => $oOption) {
264:                 if (in_array($oOption->getAttribute("value"), $aElements)) {
265:                     $oOption->setSelected(true);
266:                     $this->_options[$sKey] = $oOption;
267:                 } else {
268:                     $oOption->setSelected(false);
269:                     $this->_options[$sKey] = $oOption;
270:                 }
271:             }
272:         }
273:     }
274: 
275: }
276: 
277: /**
278:  * Config table class.
279:  *
280:  * @package Core
281:  * @subpackage Util
282:  */
283: class UI_Config_Table {
284: 
285:     var $_sTplCellCode;
286: 
287:     var $_sTplTableFile;
288: 
289:     var $_sWidth;
290: 
291:     var $_sBorder;
292: 
293:     var $_sBorderColor;
294: 
295:     var $_bSolidBorder;
296: 
297:     var $_sPadding;
298: 
299:     var $_aCells;
300: 
301:     var $_aCellAlignment;
302: 
303:     var $_aCellVAlignment;
304: 
305:     var $_aCellColSpan;
306: 
307:     var $_aCellClass;
308: 
309:     var $_aRowBgColor;
310: 
311:     var $_aRowExtra;
312: 
313:     var $_bAddMultiSelJS;
314: 
315:     var $_sColorLight;
316: 
317:     var $_sColorDark;
318: 
319:     function UI_Config_Table() {
320:         global $cfg;
321:         $backendPath = cRegistry::getBackendPath();
322: 
323:         $this->_sPadding = 2;
324:         $this->_sBorder = 0;
325:         $this->_sTplCellCode = '        <td align="{ALIGN}" valign="{VALIGN}" class="{CLASS}" colspan="{COLSPAN}" style="{EXTRA}white-space:nowrap;" nowrap="nowrap">{CONTENT}</td>' . "\n";
326:         $this->_sTplTableFile = $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper'];
327:         $this->_sTplCellCode =  $backendPath . $cfg['path']['templates'] . $cfg['templates']['input_helper_row'];
328:     }
329: 
330:     function setCellTemplate($sCode) {
331:         $this->_sTplCellCode = $sCode;
332:     }
333: 
334:     function setTableTemplateFile($sPath) {
335:         $this->_sTplTableFile = $sPath;
336:     }
337: 
338:     function setCell($sRow, $sCell, $sContent) {
339:         $this->_aCells[$sRow][$sCell] = $sContent;
340:         $this->_aCellAlignment[$sRow][$sCell] = "";
341:     }
342: 
343:     function setCellAlignment($sRow, $sCell, $sAlignment) {
344:         $this->_aCellAlignment[$sRow][$sCell] = $sAlignment;
345:     }
346: 
347:     function setCellVAlignment($sRow, $sCell, $sAlignment) {
348:         $this->_aCellVAlignment[$sRow][$sCell] = $sAlignment;
349:     }
350: 
351:     function setCellClass($sRow, $sCell, $sClass) {
352:         $this->_aCellClass[$sRow][$sCell] = $sClass;
353:     }
354: 
355:     function _addMultiSelJS() {
356:         // Trick: To save multiple selections in <select>-Element, add some JS
357:         // which saves the
358:         // selection, comma separated in a hidden input field on change.
359:         // Try ... catch prevents error messages, if function is added more than
360:         // once
361:         // if (!fncUpdateSel) in JS has not worked...
362:         $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";
363: 
364:         return $sSkript;
365:     }
366: 
367:     function render($bPrint = false) {
368:         $oTable = new cTemplate();
369:         $oTable->reset();
370: 
371:         $iColCount = 0;
372:         $bDark = false;
373:         $sBgColor = "";
374:         $bMultiSelJSAdded = false;
375:         if (is_array($this->_aCells)) {
376:             foreach ($this->_aCells as $sRow => $aCells) {
377:                 $iColCount++;
378:                 // $bDark = !$bDark;
379:                 $sLine = "";
380:                 $iCount = 0;
381: 
382:                 foreach ($aCells as $sCell => $sData) {
383:                     $iCount++;
384:                     $tplCell = new cTemplate();
385:                     $tplCell->reset();
386: 
387:                     if ($this->_aCellClass[$sRow][$sCell] != "") {
388:                         $tplCell->set("s", "CLASS", $this->_aCellClass[$sRow][$sCell]);
389:                     } else {
390:                         $tplCell->set("s", "CLASS", "");
391:                     }
392: 
393:                     if ($this->_aCellAlignment[$sRow][$sCell] != "") {
394:                         $tplCell->set("s", "ALIGN", $this->_aCellAlignment[$sRow][$sCell]);
395:                     } else {
396:                         $tplCell->set("s", "ALIGN", "left");
397:                     }
398: 
399:                     if ($this->_aCellVAlignment[$sRow][$sCell] != "") {
400:                         $tplCell->set("s", "VALIGN", $this->_aCellAlignment[$sRow][$sCell]);
401:                     } else {
402:                         $tplCell->set("s", "VALIGN", "top");
403:                     }
404: 
405:                     // Multi selection javascript
406:                     if ($this->_bAddMultiSelJS) {
407:                         $sData = $this->_addMultiSelJS() . $sData;
408:                         $this->_bAddMultiSelJS = false;
409:                     }
410: 
411:                     $tplCell->set("s", "CONTENT", $sData);
412:                     $sLine .= $tplCell->generate($this->_sTplCellCode, true, false);
413:                 }
414: 
415:                 // Row
416:                 $oTable->set('d', 'ROWS', $sLine);
417: 
418:                 $oTable->next();
419:             }
420:         }
421:         $sRendered = $oTable->generate($this->_sTplTableFile, true, false);
422: 
423:         if ($bPrint == true) {
424:             echo $sRendered;
425:         } else {
426:             return $sRendered;
427:         }
428:     }
429: 
430: }
431: 
432: ?>
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0