1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21:
22: class FrontendNavigation {
23:
24: 25: 26: 27: 28:
29: protected $_db = null;
30:
31: 32: 33: 34:
35: protected $_debug = false;
36:
37: 38: 39:
40: protected $_client = 0;
41:
42: 43: 44:
45: protected $_cfgClient = array();
46:
47: 48: 49:
50: protected $_cfg = array();
51:
52: 53: 54:
55: protected $_lang = 0;
56:
57: 58: 59:
60: public function __construct() {
61: $this->_db = cRegistry::getDb();
62: $this->_cfgClient = cRegistry::getClientConfig();
63: $this->_cfg = cRegistry::getConfig();
64: $this->_client = cRegistry::getClientId();
65: $this->_lang = cRegistry::getLanguageId();
66: }
67:
68: 69: 70: 71: 72: 73: 74:
75: public function FrontendNavigation() {
76: cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
77: return $this->__construct();
78: }
79:
80: 81: 82: 83: 84: 85: 86: 87:
88: public function getSubCategories($parentCategory) {
89: if (!is_int((int) $parentCategory)) {
90: return array();
91: }
92:
93: $sql = "SELECT
94: A.idcat
95: FROM
96: " . $this->_cfg["tab"]["cat_tree"] . " AS A,
97: " . $this->_cfg["tab"]["cat"] . " AS B,
98: " . $this->_cfg["tab"]["cat_lang"] . " AS C
99: WHERE
100: A.idcat = B.idcat AND
101: B.idcat = C.idcat AND
102: B.idclient = " . $this->_client . " AND
103: C.idlang = " . $this->_lang . " AND
104: C.visible = 1 AND
105: C.public = 1 AND
106: B.parentid = " . $parentCategory . "
107: ORDER BY
108: A.idtree ";
109:
110: if ($this->_debug) {
111: echo "<pre>";
112: print_r($sql);
113: echo "</pre>";
114: }
115:
116: $this->_db->query($sql);
117:
118: $navigation = array();
119: while ($this->_db->nextRecord()) {
120: $navigation[] = $this->_db->f("idcat");
121: }
122:
123: return $navigation;
124: }
125:
126: 127: 128: 129: 130: 131: 132: 133:
134: public function hasChildren($parentCategory) {
135: if (!is_int((int) $parentCategory)) {
136: return false;
137: }
138:
139: $sql = "SELECT
140: B.idcat
141: FROM
142: " . $this->_cfg["tab"]["cat"] . " AS B,
143: " . $this->_cfg["tab"]["cat_lang"] . " AS C
144: WHERE
145: B.idcat = C.idcat AND
146: B.idclient = " . $this->_client . " AND
147: C.idlang = " . $this->_lang . " AND
148: C.visible = 1 AND
149: C.public = 1 AND
150: B.parentid = " . $parentCategory . " ";
151:
152: if ($this->_debug) {
153: echo "<pre>";
154: print_r($sql);
155: echo "</pre>";
156: }
157:
158: $this->_db->query($sql);
159:
160: if ($this->_db->nextRecord()) {
161: return true;
162: } else {
163: return false;
164: }
165: }
166:
167: 168: 169: 170: 171: 172: 173: 174: 175: 176:
177: public function getSuccessor($category) {
178: if (!is_int((int) $category)) {
179: return -1;
180: }
181:
182: $sql = "SELECT
183: B.idcat
184: FROM
185: " . $this->_cfg["tab"]["cat"] . " AS B,
186: " . $this->_cfg["tab"]["cat_lang"] . " AS C
187: WHERE
188: B.idcat = C.idcat AND
189: B.idclient = " . $this->_client . " AND
190: C.idlang = " . $this->_lang . " AND
191: C.visible = 1 AND
192: C.public = 1 AND
193: B.preid = 0 AND
194: B.parentid = " . $category . " ";
195:
196: if ($this->_debug) {
197: echo "<pre>";
198: print_r($sql);
199: echo "</pre>";
200: }
201:
202: $this->_db->query($sql);
203:
204: if ($this->_db->nextRecord()) {
205: return $this->_db->f("idcat");
206: } else {
207: return -1;
208: }
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218:
219: public function hasSuccessor($category) {
220: if (!is_int((int) $category)) {
221: return false;
222: }
223:
224: $sql = "SELECT
225: B.idcat
226: FROM
227: " . $this->_cfg["tab"]["cat"] . " AS B,
228: " . $this->_cfg["tab"]["cat_lang"] . " AS C
229: WHERE
230: B.idcat = C.idcat AND
231: B.idclient = " . $this->_client . " AND
232: C.idlang = " . $this->_lang . " AND
233: C.visible = 1 AND
234: C.public = 1 AND
235: B.preid = 0 AND
236: B.parentid = " . $category . " ";
237:
238: if ($this->_debug) {
239: echo "<pre>";
240: print_r($sql);
241: echo "</pre>";
242: }
243:
244: $this->_db->query($sql);
245:
246: if ($this->_db->nextRecord()) {
247: return true;
248: } else {
249: return false;
250: }
251: }
252:
253: 254: 255: 256: 257: 258: 259: 260:
261: public function getCategoryName($cat_id) {
262: if (!is_int((int) $cat_id)) {
263: return '';
264: }
265:
266: $sql = "SELECT
267: B.name
268: FROM
269: " . $this->_cfg["tab"]["cat"] . " AS A,
270: " . $this->_cfg["tab"]["cat_lang"] . " AS B
271: WHERE
272: A.idcat = B.idcat AND
273: A.idcat = $cat_id AND
274: A.idclient = " . $this->_client . " AND
275: B.idlang = " . $this->_lang . "
276: ";
277:
278: if ($this->_debug) {
279: echo "<pre>";
280: print_r($sql);
281: echo "</pre>";
282: }
283:
284: $this->_db->query($sql);
285:
286: if ($this->_db->nextRecord()) {
287: return $this->_db->f("name");
288: } else {
289: return '';
290: }
291: }
292:
293: 294: 295: 296: 297: 298: 299: 300:
301: public function getCategoryURLName($cat_id) {
302: if (!is_int((int) $cat_id)) {
303: return '';
304: }
305:
306: $sql = "SELECT
307: B.urlname
308: FROM
309: " . $this->_cfg["tab"]["cat"] . " AS A,
310: " . $this->_cfg["tab"]["cat_lang"] . " AS B
311: WHERE
312: A.idcat = B.idcat AND
313: A.idcat = $cat_id AND
314: A.idclient = " . $this->_client . " AND
315: B.idlang = " . $this->_lang . "
316: ";
317:
318: if ($this->_debug) {
319: echo "<pre>";
320: print_r($sql);
321: echo "</pre>";
322: }
323:
324: $this->_db->query($sql);
325:
326: if ($this->_db->nextRecord()) {
327: return $this->_db->f("urlname");
328: } else {
329: return '';
330: }
331: }
332:
333: 334: 335: 336: 337: 338: 339: 340:
341: public function isVisible($cat_id) {
342: if (!is_int((int) $cat_id)) {
343: return false;
344: }
345:
346: $sql = "SELECT
347: B.visible
348: FROM
349: " . $this->_cfg["tab"]["cat"] . " AS A,
350: " . $this->_cfg["tab"]["cat_lang"] . " AS B
351: WHERE
352: A.idcat = B.idcat AND
353: A.idcat = $cat_id AND
354: A.idclient = " . $this->_client . " AND
355: B.idlang = " . $this->_lang . "
356: ";
357:
358: if ($this->_debug) {
359: echo "<pre>";
360: print_r($sql);
361: echo "</pre>";
362: }
363:
364: $this->_db->query($sql);
365: $this->_db->nextRecord();
366:
367: if ($this->_db->f("visible") == 1) {
368: return true;
369: } else {
370: return false;
371: }
372: }
373:
374: 375: 376: 377: 378: 379: 380: 381:
382: public function isPublic($cat_id) {
383: if (!is_int((int) $cat_id)) {
384: return false;
385: }
386:
387: $sql = "SELECT
388: B.public
389: FROM
390: " . $this->_cfg["tab"]["cat"] . " AS A,
391: " . $this->_cfg["tab"]["cat_lang"] . " AS B
392: WHERE
393: A.idcat = B.idcat AND
394: A.idcat = $cat_id AND
395: A.idclient = " . $this->_client . " AND
396: B.idlang = " . $this->_lang . "
397: ";
398:
399: if ($this->_debug) {
400: echo "<pre>";
401: print_r($sql);
402: echo "</pre>";
403: }
404:
405: $this->_db->query($sql);
406: $this->_db->nextRecord();
407:
408: if ($this->_db->f("public") == 1) {
409: return true;
410: } else {
411: return false;
412: }
413: }
414:
415: 416: 417: 418: 419: 420: 421: 422: 423:
424: public function isParent($parentid, $catid) {
425: if (!is_int((int) $parentid)) {
426: return false;
427: }
428:
429: $sql = "SELECT
430: a.parentid
431: FROM
432: " . $this->_cfg["tab"]["cat"] . " AS a,
433: " . $this->_cfg["tab"]["cat_lang"] . " AS b
434: WHERE
435: a.idclient = " . $this->_client . " AND
436: b.idlang = " . $this->_lang . " AND
437: a.idcat = b.idcat AND
438: a.idcat = " . $catid . " ";
439:
440: $this->_db->query($sql);
441: $this->_db->nextRecord();
442:
443: if ($this->_debug) {
444: echo "<pre>";
445: print_r($sql);
446: echo "</pre>";
447: }
448:
449: $pre = $this->_db->f("parentid");
450:
451: if ($parentid == $pre) {
452: return true;
453: } else {
454: return false;
455: }
456: }
457:
458: 459: 460: 461: 462: 463: 464: 465:
466: public function getParent($preid) {
467: if (!is_int((int) $preid)) {
468: return -1;
469: }
470:
471: $sql = "SELECT
472: a.parentid
473: FROM
474: " . $this->_cfg["tab"]["cat"] . " AS a,
475: " . $this->_cfg["tab"]["cat_lang"] . " AS b
476: WHERE
477: a.idclient = " . $this->_client . " AND
478: b.idlang = " . $this->_lang . " AND
479: a.idcat = b.idcat AND
480: a.idcat = " . $preid . " ";
481:
482: $this->_db->query($sql);
483:
484: if ($this->_debug) {
485: echo "<pre>";
486: print_r($sql);
487: echo "</pre>";
488: }
489:
490: if ($this->_db->nextRecord()) {
491: return $this->_db->f("parentid");
492: } else {
493: return -1;
494: }
495: }
496:
497: 498: 499: 500: 501: 502: 503: 504:
505: public function hasParent($preid) {
506: if (!is_int((int) $preid)) {
507: return false;
508: }
509:
510: $sql = "SELECT
511: a.parentid
512: FROM
513: " . $this->_cfg["tab"]["cat"] . " AS a,
514: " . $this->_cfg["tab"]["cat_lang"] . " AS b
515: WHERE
516: a.idclient = " . $this->_client . " AND
517: b.idlang = " . $this->_lang . " AND
518: a.idcat = b.idcat AND
519: a.idcat = " . $preid . " ";
520:
521: $this->_db->query($sql);
522:
523: if ($this->_debug) {
524: echo "<pre>";
525: print_r($sql);
526: echo "</pre>";
527: }
528:
529: if ($this->_db->nextRecord()) {
530: return true;
531: } else {
532: return false;
533: }
534: }
535:
536: 537: 538: 539: 540: 541: 542: 543:
544: public function getLevel($catid) {
545: if (!is_int((int) $catid)) {
546: return -1;
547: }
548:
549: $sql = "SELECT
550: level
551: FROM
552: " . $this->_cfg["tab"]["cat_tree"] . "
553: WHERE
554: idcat = " . $catid . " ";
555:
556: $this->_db->query($sql);
557:
558: if ($this->_debug) {
559: echo "<pre>";
560: print_r($sql);
561: echo "</pre>";
562: }
563:
564: if ($this->_db->nextRecord()) {
565: return $this->_db->f("level");
566: } else {
567: return -1;
568: }
569: }
570:
571: 572: 573: 574: 575: 576: 577: 578:
579: public function getFrontContentUrl($idcat, $idart, $absolute = true) {
580: if (!is_int((int) $idcat) && $idcat < 0) {
581: return '';
582: }
583:
584: if ($absolute === true) {
585:
586: if (is_int((int) $idart) && $idart > 0) {
587: $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'front_content.php?idcat=' . $idcat . '&idart=' . $idart;
588: } else {
589: $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'front_content.php?idcat=' . $idcat;
590: }
591: } else {
592: if (is_int((int) $idart) && $idart > 0) {
593: $url = 'front_content.php?idcat=' . $idcat . '&idart=' . $idart;
594: } else {
595: $url = 'front_content.php?idcat=' . $idcat;
596: }
597: }
598:
599: return $url;
600: }
601:
602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613:
614: public function getUrlPath($idcat, $idart, $absolute = true, $level = 0, $urlSuffix = 'index.html') {
615: if (!is_int((int) $idcat) && $idcat < 0) {
616: return '';
617: }
618:
619: $cat_str = '';
620: prCreateURLNameLocationString($idcat, "/", $cat_str, false, "", $level, $this->_lang, true, false);
621:
622: if (cString::getStringLength($cat_str) <= 1) {
623:
624: return '';
625: }
626:
627: if ($absolute === true) {
628:
629: if (is_int((int) $idart) && $idart > 0) {
630: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/index-d-' . $idart . '.html';
631: } else {
632: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/' . $urlSuffix;
633: }
634: } else {
635: if (is_int((int) $idart) && $idart > 0) {
636: return $cat_str . '/index-d-' . $idart . '.html';
637: } else {
638: return $cat_str . '/' . $urlSuffix;
639: }
640: }
641: }
642:
643: 644: 645: 646: 647: 648: 649: 650: 651: 652:
653: public function getUrlPathGenParam($idcat, $selectedNumber, $absolute = true, $level = 0) {
654: if (!is_int((int) $idcat) && $idcat < 0) {
655: return '';
656: }
657:
658: $cat_str = '';
659: prCreateURLNameLocationString($idcat, "/", $cat_str, false, "", $level, $this->_lang, true, false);
660:
661: if (cString::getStringLength($cat_str) <= 1) {
662:
663: return '';
664: }
665:
666: if ($absolute === true) {
667:
668: if (is_int((int) $selectedNumber)) {
669: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/index-g-' . $selectedNumber . '.html';
670: }
671: } else {
672: if (is_int((int) $selectedNumber)) {
673: return $cat_str . '/index-g-' . $selectedNumber . '.html';
674: }
675: }
676: }
677:
678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688:
689: public function getURL($idcat, $idart, $type = '', $absolute = true, $level = 0) {
690: if (!is_int((int) $idcat) AND $idcat < 0) {
691: return '';
692: }
693:
694: switch ($type) {
695: case 'urlpath':
696: $url = $this->getUrlPath($idcat, $idart, $absolute, $level);
697: break;
698: case 'frontcontent':
699: $url = $this->getFrontContentUrl($idcat, $idart, $absolute);
700: break;
701: case 'index-a':
702:
703: $url = '';
704: break;
705: default:
706: $url = $this->getFrontContentUrl($idcat, $idart, $absolute);
707: }
708:
709: return $url;
710: }
711:
712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722:
723: public function getCategoryOfArticle($idart) {
724:
725:
726: if (!is_int((int) $idart) || $idart <= 0) {
727: return -1;
728: }
729:
730: $sql = '
731: SELECT
732: c.idcat
733: FROM
734: ' . $this->_cfg['tab']['art_lang'] . ' AS a,
735: ' . $this->_cfg['tab']['art'] . ' AS b,
736: ' . $this->_cfg['tab']['cat_art'] . ' AS c
737: WHERE
738: a.idart = ' . $idart . ' AND
739: b.idclient = ' . $this->_client . ' AND
740: a.idlang = ' . $this->_lang . ' AND
741: b.idart = c.idart AND
742: a.idart = b.idart ';
743:
744: if ($this->_debug) {
745: echo "<pre>" . $sql . "</pre>";
746: }
747:
748: $this->_db->query($sql);
749:
750:
751: if ($this->_db->getErrorNumber() == 0) {
752: if ($this->_db->nextRecord()) {
753: return $this->_db->f('idcat');
754: } else {
755: return -1;
756: }
757: } else {
758: if ($this->_debug) {
759: echo "<pre>Mysql Error:" . $this->_db->getErrorMessage() . "(" . $this->_db->getErrorNumber() . ")</pre>";
760: }
761: return -1;
762: }
763: }
764:
765: 766: 767: 768: 769: 770: 771: 772: 773: 774:
775: public function getCategoryPath($cat_id, $level = 0, $reverse = true) {
776: if (!is_int((int) $cat_id) && $cat_id < 0) {
777: return array();
778: }
779:
780: $root_path = array();
781: array_push($root_path, $cat_id);
782: $parent_id = $cat_id;
783:
784: while ($this->getLevel($parent_id) >= 0 && $this->getLevel($parent_id) > $level) {
785: $parent_id = $this->getParent($parent_id);
786: if ($parent_id >= 0) {
787: array_push($root_path, $parent_id);
788: }
789: }
790:
791: if ($reverse == true) {
792: $root_path = array_reverse($root_path);
793: }
794:
795: return $root_path;
796: }
797:
798: 799: 800: 801: 802: 803: 804: 805:
806: function getRoot($cat_id) {
807: if (!is_int((int) $cat_id) && $cat_id < 0) {
808: return array();
809: }
810:
811: $parent_id = $cat_id;
812:
813: while ($this->getLevel($parent_id) >= 0) {
814: $rootCategory = $parent_id;
815: $parent_id = $this->getParent($parent_id);
816: }
817:
818: return $rootCategory;
819: }
820:
821: 822: 823: 824: 825: 826: 827: 828:
829: function getSubTree($idcat_start) {
830:
831: if (!is_int((int) $idcat_start)) {
832: return array();
833: }
834:
835: $sql = "SELECT
836: B.idcat, A.level
837: FROM
838: " . $this->_cfg["tab"]["cat_tree"] . " AS A,
839: " . $this->_cfg["tab"]["cat"] . " AS B
840: WHERE
841: A.idcat = B.idcat AND
842: idclient = " . $this->_client . "
843: ORDER BY
844: idtree";
845:
846: if ($this->_debug) {
847: echo "<pre>";
848: print_r($sql);
849: echo "</pre>";
850: }
851:
852: $this->_db->query($sql);
853:
854: $i = false;
855: $curLevel = 0;
856:
857: while ($this->_db->nextRecord()) {
858: if ($this->_db->f("idcat") == $idcat_start) {
859: $curLevel = $this->_db->f("level");
860: $i = true;
861: } else {
862: if ($curLevel == $this->_db->f("level")) {
863:
864: $i = false;
865: }
866: }
867:
868: if ($i == true) {
869: $deeper_cats[] = $this->_db->f("idcat");
870: }
871: }
872: return $deeper_cats;
873: }
874:
875: }
876: ?>