1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class FrontendNavigation {
25:
26: 27: 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: 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: 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: 117: 118: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 470: 471: 472: 473: 474: 475: 476: 477: 478:
479: function getFrontContentUrl($iIdcat, $iIdart, $bAbsolute = true) {
480: if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
481: return '';
482: }
483:
484: if ($bAbsolute === true) {
485:
486: if (is_int((int) $iIdart) AND $iIdart > 0) {
487: $sURL = $this->cfgClient[$this->client]['path']['htmlpath'] . 'front_content.php?idcat=' . $iIdcat . '&idart=' . $iIdart;
488: } else {
489: $sURL = $this->cfgClient[$this->client]['path']['htmlpath'] . 'front_content.php?idcat=' . $iIdcat;
490: }
491: } else {
492: if (is_int((int) $iIdart) AND $iIdart > 0) {
493: $sURL = 'front_content.php?idcat=' . $iIdcat . '&idart=' . $iIdart;
494: } else {
495: $sURL = 'front_content.php?idcat=' . $iIdcat;
496: }
497: }
498:
499: return $sURL;
500: }
501:
502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515:
516: function getUrlPath($iIdcat, $iIdart, $bAbsolute = true, $iLevel = 0, $sURL_SUFFIX = 'index.html') {
517: if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
518: return '';
519: }
520:
521: $cat_str = '';
522: prCreateURLNameLocationString($iIdcat, "/", $cat_str, false, "", $iLevel, $this->lang, true, false);
523:
524: if (strlen($cat_str) <= 1) {
525:
526: return '';
527: }
528:
529: if ($bAbsolute === true) {
530:
531: if (is_int((int) $iIdart) AND $iIdart > 0) {
532: return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/index-d-' . $iIdart . '.html';
533: } else {
534: return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/' . $sURL_SUFFIX;
535: }
536: } else {
537: if (is_int((int) $iIdart) AND $iIdart > 0) {
538: return $cat_str . '/index-d-' . $iIdart . '.html';
539: } else {
540: return $cat_str . '/' . $sURL_SUFFIX;
541: }
542: }
543: }
544:
545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557:
558: function getUrlPathGenParam($iIdcat, $iSelectedNumber, $bAbsolute = true, $iLevel = 0) {
559: if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
560: return '';
561: }
562:
563: $cat_str = '';
564: prCreateURLNameLocationString($iIdcat, "/", $cat_str, false, "", $iLevel, $this->lang, true, false);
565:
566: if (strlen($cat_str) <= 1) {
567:
568: return '';
569: }
570:
571: if ($bAbsolute === true) {
572:
573: if (is_int((int) $iSelectedNumber)) {
574: return $this->cfgClient[$this->client]['path']['htmlpath'] . $cat_str . '/index-g-' . $iSelectedNumber . '.html';
575: }
576: } else {
577: if (is_int((int) $iSelectedNumber)) {
578: return $cat_str . '/index-g-' . $iSelectedNumber . '.html';
579: }
580: }
581: }
582:
583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593:
594: function getURL($iIdcat, $iIdart, $sType = '', $bAbsolute = true, $iLevel = 0) {
595: if (!is_int((int) $iIdcat) AND $iIdcat < 0) {
596: return '';
597: }
598:
599:
600:
601: switch ($sType) {
602: case 'urlpath':
603: $sURL = $this->getUrlPath($iIdcat, $iIdart, $bAbsolute, $iLevel);
604: break;
605: case 'frontcontent':
606: $sURL = $this->getFrontContentUrl($iIdcat, $iIdart, $bAbsolute);
607: break;
608: case 'index-a':
609:
610: $sURL = '';
611: break;
612: default:
613: $sURL = $this->getFrontContentUrl($iIdcat, $iIdart, $bAbsolute);
614: }
615:
616: return $sURL;
617: }
618:
619: 620: 621: 622: 623: 624: 625: 626: 627:
628: function getCategoryOfArticle($iArticleId) {
629:
630:
631: if (!is_int((int) $iArticleId) OR $iArticleId <= 0) {
632: return -1;
633: }
634:
635: $sqlString = '
636: SELECT
637: c.idcat
638: FROM
639: ' . $this->cfg['tab']['art_lang'] . ' AS a,
640: ' . $this->cfg['tab']['art'] . ' AS b,
641: ' . $this->cfg['tab']['cat_art'] . ' AS c
642: WHERE
643: a.idart = ' . $iArticleId . ' AND
644: b.idclient = ' . $this->client . ' AND
645: a.idlang = ' . $this->lang . ' AND
646: b.idart = c.idart AND
647: a.idart = b.idart ';
648:
649: if ($this->_bDebug) {
650: echo "<pre>" . $sqlString . "</pre>";
651: }
652:
653: $this->db->query($sqlString);
654:
655:
656: if ($this->db->getErrorNumber() == 0) {
657: if ($this->db->nextRecord()) {
658: return $this->db->f('idcat');
659: } else {
660: return -1;
661: }
662: } else {
663: if ($this->_bDebug) {
664: echo "<pre>Mysql Error:" . $this->db->getErrorMessage() . "(" . $this->db->getErrorNumber() . ")</pre>";
665: }
666: return -1;
667: }
668: }
669:
670: 671: 672:
673: function getCategoryPath($cat_id, $level = 0, $reverse = true) {
674: if (!is_int((int) $cat_id) AND $cat_id < 0) {
675: return array();
676: }
677:
678: $root_path = array();
679: array_push($root_path, $cat_id);
680: $parent_id = $cat_id;
681:
682: while ($this->getLevel($parent_id) >= 0 AND $this->getLevel($parent_id) > $level) {
683: $parent_id = $this->getParent($parent_id);
684: if ($parent_id >= 0) {
685: array_push($root_path, $parent_id);
686: }
687: }
688:
689: if ($reverse == true) {
690: $root_path = array_reverse($root_path);
691: }
692:
693: return $root_path;
694: }
695:
696: 697: 698:
699: function getRoot($cat_id) {
700: if (!is_int((int) $cat_id) AND $cat_id < 0) {
701: return array();
702: }
703:
704: $parent_id = $cat_id;
705:
706: while ($this->getLevel($parent_id) >= 0) {
707: $iRootCategory = $parent_id;
708: $parent_id = $this->getParent($parent_id);
709: }
710:
711: return $iRootCategory;
712: }
713:
714: 715: 716: 717: 718: 719: 720: 721:
722: function getSubTree($idcat_start) {
723:
724: 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) {
725: return array();
726: }
727:
728: $sql = "SELECT
729: B.idcat, A.level
730: FROM
731: " . $this->cfg["tab"]["cat_tree"] . " AS A,
732: " . $this->cfg["tab"]["cat"] . " AS B
733: WHERE
734: A.idcat = B.idcat AND
735: idclient = " . $this->client . "
736: ORDER BY
737: idtree";
738:
739: if ($this->_bDebug) {
740: echo "<pre>";
741: print_r($sql);
742: echo "</pre>";
743: }
744:
745: $this->db->query($sql);
746:
747: $i = false;
748:
749: while ($this->db->nextRecord()) {
750: if ($this->db->f("idcat") == $idcat_start) {
751: $curLevel = $this->db->f("level");
752: $i = true;
753: } else {
754: if ($curLevel == $this->db->f("level")) {
755:
756: $i = false;
757: }
758: }
759:
760: if ($i == true) {
761: $deeper_cats[] = $this->db->f("idcat");
762: }
763: }
764: return $deeper_cats;
765: }
766:
767: }
768:
769: ?>