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

  • FrontendNavigation
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file includes the "frontend navigation" sub plugin from the old plugin repository.
  4:  *
  5:  * @package    Plugin
  6:  * @subpackage Repository_FrontendNavigation
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Willi Man
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * file FrontendNavigation.php
 20:  *
 21:  * @package    Plugin
 22:  * @subpackage Repository_FrontendNavigation
 23:  */
 24: class FrontendNavigation {
 25: 
 26:     /**
 27:      * Constructor
 28:      */
 29:     function FrontendNavigation($db, $cfg, $cfgClient, $client, $lang) {
 30:         $this->_bDebug = false;
 31:         $this->db = &$db;
 32:         $this->cfgClient = &$cfgClient;
 33:         $this->cfg = &$cfg;
 34:         $this->client = &$client;
 35:         $this->lang = &$lang;
 36:     }
 37: 
 38:     /**
 39:      * Get child categories by given parent category
 40:      */
 41:     function getSubCategories($iParentCategory) {
 42:         if (!is_int((int) $iParentCategory) AND $iParentCategory < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
 43:             return array();
 44:         }
 45: 
 46:         $sql = "SELECT
 47:                     A.idcat
 48:                 FROM
 49:                     " . $this->cfg["tab"]["cat_tree"] . " AS A,
 50:                     " . $this->cfg["tab"]["cat"] . " AS B,
 51:                     " . $this->cfg["tab"]["cat_lang"] . " AS C
 52:                 WHERE
 53:                     A.idcat    = B.idcat AND
 54:                     B.idcat    = C.idcat AND
 55:                     B.idclient = " . $this->client . " AND
 56:                     C.idlang   = " . $this->lang . " AND
 57:                     C.visible  = 1 AND
 58:                     C.public   = 1 AND
 59:                     B.parentid = " . $iParentCategory . "
 60:                 ORDER BY
 61:                     A.idtree ";
 62: 
 63:         if ($this->_bDebug) {
 64:             echo "<pre>";
 65:             print_r($sql);
 66:             echo "</pre>";
 67:         }
 68: 
 69:         $this->db->query($sql);
 70: 
 71:         $navigation = array();
 72:         while ($this->db->nextRecord()) {
 73:             $navigation[] = $this->db->f("idcat");
 74:         }
 75: 
 76:         return $navigation;
 77:     }
 78: 
 79:     /**
 80:      * Check if child categories of a given parent category exist
 81:      */
 82:     function hasChildren($iParentCategory) {
 83:         if (!is_int((int) $iParentCategory) AND $iParentCategory < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
 84:             return false;
 85:         }
 86: 
 87:         $sql = "SELECT
 88:                     B.idcat
 89:                 FROM
 90:                     " . $this->cfg["tab"]["cat"] . " AS B,
 91:                     " . $this->cfg["tab"]["cat_lang"] . " AS C
 92:                 WHERE
 93:                     B.idcat    = C.idcat AND
 94:                     B.idclient = " . $this->client . " AND
 95:                     C.idlang   = " . $this->lang . " AND
 96:                     C.visible  = 1 AND
 97:                     C.public   = 1 AND
 98:                     B.parentid = " . $iParentCategory . " ";
 99: 
100:         if ($this->_bDebug) {
101:             echo "<pre>";
102:             print_r($sql);
103:             echo "</pre>";
104:         }
105: 
106:         $this->db->query($sql);
107: 
108:         if ($this->db->nextRecord()) {
109:             return true;
110:         } else {
111:             return false;
112:         }
113:     }
114: 
115:     /**
116:      * Get direct successor of a given category
117:      * Note: does not work if direct successor (with preid 0) is not visible
118:      * or not public
119:      */
120:     function getSuccessor($iCategory) {
121:         if (!is_int((int) $iCategory) AND $iCategory < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
122:             return -1;
123:         }
124: 
125:         $sql = "SELECT
126:                     B.idcat
127:                 FROM
128:                     " . $this->cfg["tab"]["cat"] . " AS B,
129:                     " . $this->cfg["tab"]["cat_lang"] . " AS C
130:                 WHERE
131:                     B.idcat    = C.idcat AND
132:                     B.idclient = " . $this->client . " AND
133:                     C.idlang   = " . $this->lang . " AND
134:                     C.visible  = 1 AND
135:                     C.public   = 1 AND
136:                     B.preid    = 0 AND
137:                     B.parentid = " . $iCategory . " ";
138: 
139:         if ($this->_bDebug) {
140:             echo "<pre>";
141:             print_r($sql);
142:             echo "</pre>";
143:         }
144: 
145:         $this->db->query($sql);
146: 
147:         if ($this->db->nextRecord()) {
148:             return $this->db->f("idcat");
149:         } else {
150:             return -1;
151:         }
152:     }
153: 
154:     /**
155:      * Check if a given category has a direct successor
156:      */
157:     function hasSuccessor($iCategory) {
158:         if (!is_int((int) $iCategory) AND $iCategory < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
159:             return false;
160:         }
161: 
162:         $sql = "SELECT
163:                     B.idcat
164:                 FROM
165:                     " . $this->cfg["tab"]["cat"] . " AS B,
166:                     " . $this->cfg["tab"]["cat_lang"] . " AS C
167:                 WHERE
168:                     B.idcat    = C.idcat AND
169:                     B.idclient = " . $this->client . " AND
170:                     C.idlang   = " . $this->lang . " AND
171:                     C.visible  = 1 AND
172:                     C.public   = 1 AND
173:                     B.preid    = 0 AND
174:                     B.parentid = " . $iCategory . " ";
175: 
176:         if ($this->_bDebug) {
177:             echo "<pre>";
178:             print_r($sql);
179:             echo "</pre>";
180:         }
181: 
182:         $this->db->query($sql);
183: 
184:         if ($this->db->nextRecord()) {
185:             return true;
186:         } else {
187:             return false;
188:         }
189:     }
190: 
191:     /**
192:      * Get category name
193:      */
194:     function getCategoryName($cat_id) {
195:         if (!is_int((int) $cat_id) AND $cat_id < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
196:             return '';
197:         }
198: 
199:         $sql = "SELECT
200:                     B.name
201:                 FROM
202:                     " . $this->cfg["tab"]["cat"] . " AS A,
203:                     " . $this->cfg["tab"]["cat_lang"] . " AS B
204:                 WHERE
205:                     A.idcat    = B.idcat AND
206:                     A.idcat    = $cat_id AND
207:                     A.idclient = " . $this->client . " AND
208:                     B.idlang   = " . $this->lang . "
209:                 ";
210: 
211:         if ($this->_bDebug) {
212:             echo "<pre>";
213:             print_r($sql);
214:             echo "</pre>";
215:         }
216: 
217:         $this->db->query($sql);
218: 
219:         if ($this->db->nextRecord()) {
220:             return $this->db->f("name");
221:         } else {
222:             return '';
223:         }
224:     }
225: 
226:     /**
227:      * Get category urlname
228:      */
229:     function getCategoryURLName($cat_id) {
230:         if (!is_int((int) $cat_id) AND $cat_id < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
231:             return '';
232:         }
233: 
234:         $sql = "SELECT
235:                     B.urlname
236:                 FROM
237:                     " . $this->cfg["tab"]["cat"] . " AS A,
238:                     " . $this->cfg["tab"]["cat_lang"] . " AS B
239:                 WHERE
240:                     A.idcat    = B.idcat AND
241:                     A.idcat    = $cat_id AND
242:                     A.idclient = " . $this->client . " AND
243:                     B.idlang   = " . $this->lang . "
244:                 ";
245: 
246:         if ($this->_bDebug) {
247:             echo "<pre>";
248:             print_r($sql);
249:             echo "</pre>";
250:         }
251: 
252:         $this->db->query($sql);
253: 
254:         if ($this->db->nextRecord()) {
255:             return $this->db->f("urlname");
256:         } else {
257:             return '';
258:         }
259:     }
260: 
261:     /**
262:      * Check if category is visible
263:      */
264:     function isVisible($cat_id) {
265:         if (!is_int((int) $cat_id) AND $cat_id < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
266:             return false;
267:         }
268: 
269:         $sql = "SELECT
270:                     B.visible
271:                 FROM
272:                     " . $this->cfg["tab"]["cat"] . " AS A,
273:                     " . $this->cfg["tab"]["cat_lang"] . " AS B
274:                 WHERE
275:                     A.idcat    = B.idcat AND
276:                     A.idcat    = $cat_id AND
277:                     A.idclient = " . $this->client . " AND
278:                     B.idlang   = " . $this->lang . "
279:                 ";
280: 
281:         if ($this->_bDebug) {
282:             echo "<pre>";
283:             print_r($sql);
284:             echo "</pre>";
285:         }
286: 
287:         $this->db->query($sql);
288:         $this->db->nextRecord();
289: 
290:         if ($this->db->f("visible") == 1) {
291:             return true;
292:         } else {
293:             return false;
294:         }
295:     }
296: 
297:     /**
298:      * Check if category is public
299:      */
300:     function isPublic($cat_id) {
301:         if (!is_int((int) $cat_id) AND $cat_id < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
302:             return false;
303:         }
304: 
305:         $sql = "SELECT
306:                     B.public
307:                 FROM
308:                     " . $this->cfg["tab"]["cat"] . " AS A,
309:                     " . $this->cfg["tab"]["cat_lang"] . " AS B
310:                 WHERE
311:                     A.idcat    = B.idcat AND
312:                     A.idcat    = $cat_id AND
313:                     A.idclient = " . $this->client . " AND
314:                     B.idlang   = " . $this->lang . "
315:                 ";
316: 
317:         if ($this->_bDebug) {
318:             echo "<pre>";
319:             print_r($sql);
320:             echo "</pre>";
321:         }
322: 
323:         $this->db->query($sql);
324:         $this->db->nextRecord();
325: 
326:         if ($this->db->f("public") == 1) {
327:             return true;
328:         } else {
329:             return false;
330:         }
331:     }
332: 
333:     /**
334:      * Return true if $parentid is parent of $catid
335:      */
336:     function isParent($parentid, $catid) {
337:         if (!is_int((int) $parentid) AND $parentid < 0 AND !is_int((int) $catid) AND $catid < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
338:             return false;
339:         }
340: 
341:         $sql = "SELECT
342:                 a.parentid
343:                 FROM
344:                     " . $this->cfg["tab"]["cat"] . " AS a,
345:                     " . $this->cfg["tab"]["cat_lang"] . " AS b
346:                 WHERE
347:                     a.idclient = " . $this->client . " AND
348:                     b.idlang   = " . $this->lang . " AND
349:                     a.idcat    = b.idcat AND
350:                     a.idcat    = " . $catid . " ";
351: 
352:         $this->db->query($sql);
353:         $this->db->nextRecord();
354: 
355:         if ($this->_bDebug) {
356:             echo "<pre>";
357:             print_r($sql);
358:             echo "</pre>";
359:         }
360: 
361:         $pre = $this->db->f("parentid");
362: 
363:         if ($parentid == $pre) {
364:             return true;
365:         } else {
366:             return false;
367:         }
368:     }
369: 
370:     /**
371:      * Get parent id of a category
372:      */
373:     function getParent($preid) {
374:         if (!is_int((int) $preid) AND $preid < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
375:             return -1;
376:         }
377: 
378:         $sql = "SELECT
379:                 a.parentid
380:                 FROM
381:                     " . $this->cfg["tab"]["cat"] . " AS a,
382:                     " . $this->cfg["tab"]["cat_lang"] . " AS b
383:                 WHERE
384:                     a.idclient = " . $this->client . " AND
385:                     b.idlang   = " . $this->lang . " AND
386:                     a.idcat    = b.idcat AND
387:                     a.idcat    = " . $preid . " ";
388: 
389:         $this->db->query($sql);
390: 
391:         if ($this->_bDebug) {
392:             echo "<pre>";
393:             print_r($sql);
394:             echo "</pre>";
395:         }
396: 
397:         if ($this->db->nextRecord()) {
398:             return $this->db->f("parentid");
399:         } else {
400:             return -1;
401:         }
402:     }
403: 
404:     /**
405:      * Check if a category has a parent
406:      */
407:     function hasParent($preid) {
408:         if (!is_int((int) $preid) AND $preid < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
409:             return false;
410:         }
411: 
412:         $sql = "SELECT
413:                 a.parentid
414:                 FROM
415:                     " . $this->cfg["tab"]["cat"] . " AS a,
416:                     " . $this->cfg["tab"]["cat_lang"] . " AS b
417:                 WHERE
418:                     a.idclient = " . $this->client . " AND
419:                     b.idlang   = " . $this->lang . " AND
420:                     a.idcat    = b.idcat AND
421:                     a.idcat    = " . $preid . " ";
422: 
423:         $this->db->query($sql);
424: 
425:         if ($this->_bDebug) {
426:             echo "<pre>";
427:             print_r($sql);
428:             echo "</pre>";
429:         }
430: 
431:         if ($this->db->nextRecord()) {
432:             return true;
433:         } else {
434:             return false;
435:         }
436:     }
437: 
438:     /**
439:      * Get level of a category
440:      */
441:     function getLevel($catid) {
442:         if (!is_int((int) $catid) AND $catid < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
443:             return -1;
444:         }
445: 
446:         $sql = "SELECT
447:                     level
448:                 FROM
449:                     " . $this->cfg["tab"]["cat_tree"] . "
450:                 WHERE
451:                     idcat = " . $catid . " ";
452: 
453:         $this->db->query($sql);
454: 
455:         if ($this->_bDebug) {
456:             echo "<pre>";
457:             print_r($sql);
458:             echo "</pre>";
459:         }
460: 
461:         if ($this->db->nextRecord()) {
462:             return $this->db->f("level");
463:         } else {
464:             return -1;
465:         }
466:     }
467: 
468:     /**
469:      * Get URL by given category in front_content.php style
470:      *
471:      * @param int $iIdcat
472:      * @param int $iIdart
473:      * @param bool $bAbsolute return absolute path or not
474:      * @return string URL
475:      * @author Willi Man
476:      */
477:     function getFrontContentUrl($iIdcat, $iIdart, $bAbsolute = true) {
478:         if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
479:             return '';
480:         }
481: 
482:         if ($bAbsolute === true) {
483:             # add absolute web path to urlpath
484:             if (is_int((int) $iIdart) AND $iIdart > 0) {
485:                 $sURL = $this->cfgClient[$this->client]['path']['htmlpath'] . 'front_content.php?idcat=' . $iIdcat . '&idart=' . $iIdart;
486:             } else {
487:                 $sURL = $this->cfgClient[$this->client]['path']['htmlpath'] . 'front_content.php?idcat=' . $iIdcat;
488:             }
489:         } else {
490:             if (is_int((int) $iIdart) AND $iIdart > 0) {
491:                 $sURL = 'front_content.php?idcat=' . $iIdcat . '&idart=' . $iIdart;
492:             } else {
493:                 $sURL = 'front_content.php?idcat=' . $iIdcat;
494:             }
495:         }
496: 
497:         return $sURL;
498:     }
499: 
500:     /**
501:      * Get urlpath by given category and/or idart and level.
502:      * The urlpath looks like /Home/Product/Support/ where the directory-like string equals a category path.
503:      *
504:      * @requires functions.pathresolver.php
505:      * @param int $iIdcat
506:      * @param int $iIdart
507:      * @param bool $bAbsolute return absolute path or not
508:      * @return string path information or empty string
509:      * @author Marco Jahn (Project www.usa.de)
510:      * @modified by Willi Man
511:      */
512:     function getUrlPath($iIdcat, $iIdart, $bAbsolute = true, $iLevel = 0, $sURL_SUFFIX = 'index.html') {
513:         if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
514:             return '';
515:         }
516: 
517:         $cat_str = '';
518:         prCreateURLNameLocationString($iIdcat, "/", $cat_str, false, "", $iLevel, $this->lang, true, false);
519: 
520:         if (strlen($cat_str) <= 1) {
521:             # return empty string if no url location is available
522:             return '';
523:         }
524: 
525:         if ($bAbsolute === true) {
526:             # add absolute web path to urlpath
527:             if (is_int((int) $iIdart) AND $iIdart > 0) {
528:                 return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/index-d-' . $iIdart . '.html';
529:             } else {
530:                 return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/' . $sURL_SUFFIX;
531:             }
532:         } else {
533:             if (is_int((int) $iIdart) AND $iIdart > 0) {
534:                 return $cat_str . '/index-d-' . $iIdart . '.html';
535:             } else {
536:                 return $cat_str . '/' . $sURL_SUFFIX;
537:             }
538:         }
539:     }
540: 
541:     /**
542:      * Get urlpath by given category and/or selected param and level.
543:      *
544:      * @requires functions.pathresolver.php
545:      * @param int $iIdcat
546:      * @param int $iSelectedNumber
547:      * @param bool $bAbsolute return absolute path or not
548:      * @return string path information or empty string
549:      * @author Willi Man
550:      */
551:     function getUrlPathGenParam($iIdcat, $iSelectedNumber, $bAbsolute = true, $iLevel = 0) {
552:         if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
553:             return '';
554:         }
555: 
556:         $cat_str = '';
557:         prCreateURLNameLocationString($iIdcat, "/", $cat_str, false, "", $iLevel, $this->lang, true, false);
558: 
559:         if (strlen($cat_str) <= 1) {
560:             # return empty string if no url location is available
561:             return '';
562:         }
563: 
564:         if ($bAbsolute === true) {
565:             # add absolute web path to urlpath
566:             if (is_int((int) $iSelectedNumber)) {
567:                 return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/index-g-' . $iSelectedNumber . '.html';
568:             }
569:         } else {
570:             if (is_int((int) $iSelectedNumber)) {
571:                 return $cat_str . '/index-g-' . $iSelectedNumber . '.html';
572:             }
573:         }
574:     }
575: 
576:     /**
577:      * Get URL by given categoryid and/or articleid
578:      *
579:      * @param int $iIdcat url name to create for
580:      * @param int $iIdart
581:      * @param bool $bAbsolute return absolute path or not
582:      * @return string URL
583:      * @author Willi Man
584:      */
585:     function getURL($iIdcat, $iIdart, $sType = '', $bAbsolute = true, $iLevel = 0) {
586:         if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
587:             return '';
588:         }
589: 
590:         #print "type ".$sType."<br>";
591: 
592:         switch ($sType) {
593:             case 'urlpath':
594:                 $sURL = $this->getUrlPath($iIdcat, $iIdart, $bAbsolute, $iLevel);
595:                 break;
596:             case 'frontcontent':
597:                 $sURL = $this->getFrontContentUrl($iIdcat, $iIdart, $bAbsolute);
598:                 break;
599:             case 'index-a':
600:                 # not implemented
601:                 $sURL = '';
602:                 break;
603:             default:
604:                 $sURL = $this->getFrontContentUrl($iIdcat, $iIdart, $bAbsolute);
605:         }
606: 
607:         return $sURL;
608:     }
609: 
610:     /**
611:      * Get category of article.
612:      *
613:      * If an article is assigned to more than one category take the first
614:      * category.
615:      *
616:      * @param  int $iArticleId
617:      * @return int category id
618:      */
619:     function getCategoryOfArticle($iArticleId) {
620: 
621:         # validate input
622:         if (!is_int((int) $iArticleId) OR $iArticleId <= 0) {
623:             return -1;
624:         }
625: 
626:         $sqlString = '
627:         SELECT
628:             c.idcat
629:         FROM
630:             ' . $this->cfg['tab']['art_lang'] . ' AS a,
631:             ' . $this->cfg['tab']['art'] . ' AS b,
632:             ' . $this->cfg['tab']['cat_art'] . ' AS c
633:         WHERE
634:             a.idart = ' . $iArticleId . ' AND
635:             b.idclient = ' . $this->client . ' AND
636:             a.idlang = ' . $this->lang . ' AND
637:             b.idart = c.idart AND
638:             a.idart = b.idart ';
639: 
640:         if ($this->_bDebug) {
641:             echo "<pre>" . $sqlString . "</pre>";
642:         }
643: 
644:         $this->db->query($sqlString);
645: 
646:         # $this->db->getErrorNumber() returns 0 (zero) if no error occurred.
647:         if ($this->db->getErrorNumber() == 0) {
648:             if ($this->db->nextRecord()) {
649:                 return $this->db->f('idcat');
650:             } else {
651:                 return -1;
652:             }
653:         } else {
654:             if ($this->_bDebug) {
655:                 echo "<pre>Mysql Error:" . $this->db->getErrorMessage() . "(" . $this->db->getErrorNumber() . ")</pre>";
656:             }
657:             return -1; # error occurred.
658:         }
659:     }
660: 
661:     /**
662:      * Get path  of a given category up to a certain level
663:      */
664:     function getCategoryPath($cat_id, $level = 0, $reverse = true) {
665:         if (!is_int((int) $cat_id) AND $cat_id < 0) {
666:             return array();
667:         }
668: 
669:         $root_path = array();
670:         array_push($root_path, $cat_id);
671:         $parent_id = $cat_id;
672: 
673:         while ($this->getLevel($parent_id) >= 0 AND $this->getLevel($parent_id) > $level) {
674:             $parent_id = $this->getParent($parent_id);
675:             if ($parent_id >= 0) {
676:                 array_push($root_path, $parent_id);
677:             }
678:         }
679: 
680:         if ($reverse == true) {
681:             $root_path = array_reverse($root_path);
682:         }
683: 
684:         return $root_path;
685:     }
686: 
687:     /**
688:      * Get root category of a given category
689:      */
690:     function getRoot($cat_id) {
691:         if (!is_int((int) $cat_id) AND $cat_id < 0) {
692:             return array();
693:         }
694: 
695:         $parent_id = $cat_id;
696: 
697:         while ($this->getLevel($parent_id) >= 0) {
698:             $iRootCategory = $parent_id;
699:             $parent_id = $this->getParent($parent_id);
700:         }
701: 
702:         return $iRootCategory;
703:     }
704: 
705:     /**
706:      * get subtree by a given id
707:      *
708:      * @param int $idcat_start Id of category
709:      * @return array Array with subtree
710:      *
711:      * @copyright four for business AG <www.4fb.de>
712:      */
713:     function getSubTree($idcat_start) {
714: 
715:         if (!is_int((int) $idcat_start) AND $idcat_start < 0 AND !is_array($this->cfg) AND !isset($this->cfg['tab']) AND !is_int((int) $this->client) AND $this->client < 0 AND !is_int((int) $this->lang) AND $this->lang < 0) {
716:             return array();
717:         }
718: 
719:         $sql = "SELECT
720:                     B.idcat, A.level
721:                 FROM
722:                     " . $this->cfg["tab"]["cat_tree"] . " AS A,
723:                     " . $this->cfg["tab"]["cat"] . " AS B
724:                 WHERE
725:                     A.idcat  = B.idcat AND
726:                     idclient = " . $this->client . "
727:                 ORDER BY
728:                     idtree";
729: 
730:         if ($this->_bDebug) {
731:             echo "<pre>";
732:             print_r($sql);
733:             echo "</pre>";
734:         }
735: 
736:         $this->db->query($sql);
737: 
738:         $i = false;
739: 
740:         while ($this->db->nextRecord()) {
741:             if ($this->db->f("idcat") == $idcat_start) {
742:                 $curLevel = $this->db->f("level");
743:                 $i = true;
744:             } else {
745:                 if ($curLevel == $this->db->f("level")) {
746:                     # ending part of tree
747:                     $i = false;
748:                 }
749:             }
750: 
751:             if ($i == true) {
752:                 $deeper_cats[] = $this->db->f("idcat");
753:             }
754:         }
755:         return $deeper_cats;
756:     }
757: 
758: }
759: 
760: ?>
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0