1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 911: 912: 913: 914: 915: 916: 917: 918: 919: 920: 921: 922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938: 939: 940: 941: 942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990: 991: 992: 993: 994: 995: 996: 997: 998: 999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218:
<?php
class PHPShopShopCore extends PHPShopCore {
var $no_photo = 'images/shop/no_photo.gif';
var $debug = false;
var $cache = true;
var $cache_format = array('content', 'yml_bid_array');
var $grid = true;
var $max_item = 100;
var $memory = true;
var $multi_cat = array();
var $cell_type = 'default';
var $cell_type_class = 'product-block';
var $price_min = 0;
var $price_max = 0;
var $previewSorts;
var $sortCategories;
var $warehouse;
function __construct() {
global $PHPShopValutaArray, $PHPShopPromotions;
$this->objBase = $GLOBALS['SysValue']['base']['products'];
$this->Valuta = $PHPShopValutaArray->getArray();
PHPShopObj::loadClass('product');
parent::__construct();
$this->dengi = $this->PHPShopSystem->getParam('dengi');
$this->currency = $this->currency();
$this->PHPShopPromotions = $PHPShopPromotions;
$this->parent_price_enabled = $this->PHPShopSystem->getSerilizeParam('admoption.parent_price_enabled');
$this->user_price_activate = $this->PHPShopSystem->getSerilizeParam('admoption.user_price_activate');
$this->sklad_enabled = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_enabled');
$this->sklad_status = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_status');
$this->format = intval($this->PHPShopSystem->getSerilizeParam("admoption.price_znak"));
$this->warehouse_sum = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_sum_enabled');
$this->setHtmlOption(__CLASS__);
}
function __call($name, $arguments) {
if ($name == __CLASS__) {
self::__construct();
}
}
function query_filter($where = false) {
if (!empty($where))
$where .= ' and ';
$sort = null;
$this->set('productRriceOT', 0);
$this->set('productRriceDO', 0);
$v = @$_GET['v'];
$s = intval(@$_GET['s']);
$f = intval(@$_GET['f']);
if ($this->PHPShopNav->isPageAll())
$p = PHPShopSecurity::TotalClean($p, 1);
if (is_array($v)) {
$sort .= " and (";
foreach ($v as $key => $val) {
if (PHPShopSecurity::true_num($key) and PHPShopSecurity::true_num($val)) {
$hash = $key . "-" . $val;
$sort .= " vendor REGEXP 'i" . $hash . "i' or";
}
}
$sort = substr($sort, 0, strlen($sort) - 2);
$sort .= ") ";
}
$percent = $this->PHPShopSystem->getValue('percent');
switch ($_GET['gridChange']) {
case 1:
$this->set('gridSetAactive', 'active');
break;
case 2:
$this->set('gridSetBactive', 'active');
break;
default: $this->set('gridSetBactive', 'active');
}
switch ($f) {
case(1): $order_direction = "";
$this->set('productSortNext', 2);
$this->set('productSortImg', 1);
$this->set('productSortT', 1);
$this->set('fSetBactive', 'active');
break;
case(2): $order_direction = " desc";
$this->set('productSortNext', 1);
$this->set('productSortImg', 2);
$this->set('productSortT', 2);
$this->set('fSetAactive', 'active');
break;
default: $order_direction = "";
$this->set('productSortNext', 2);
$this->set('productSortImg', 1);
$this->set('productSortT', 1);
$this->set('fSetBactive', 'active');
break;
}
switch ($s) {
case(1): $order = array('order' => 'name' . $order_direction);
$this->set('productSortA', 'sortActiv');
$this->set('sSetBactive', 'active');
break;
case(2): $order = array('order' => 'price' . $order_direction);
$this->set('productSortB', 'sortActiv');
$this->set('sSetAactive', 'active');
break;
default:
$order = array('order' => 'num' . $order_direction);
$this->set('productSortC', 'sortActiv');
$this->set('sSetCactive', 'active');
break;
}
foreach ($order as $key => $val)
$string = $key . ' by ' . $val;
if ($this->PHPShopNav->isPageAll()) {
$sql = "select * from " . $this->getValue('base.products') . " where (" . $where . " enabled='1' and parent_enabled='0') " . $sort . " " . $string . ' limit ' . $this->max_item;
}
elseif (isset($_POST['priceSearch']) or ! empty($sort)) {
if (!empty($_POST['priceOT']) or ! empty($_POST['priceDO'])) {
$priceOT = intval($_POST['priceOT']);
$priceDO = intval($_POST['priceDO']);
$this->set('productRriceOT', $priceOT);
$this->set('productRriceDO', $priceDO);
if ($priceDO == 0)
$priceDO = 1000000000;
if (empty($priceOT))
$priceOT = 0;
$priceOT /= $this->currency('kurs');
$priceDO /= $this->currency('kurs');
$price_sort = "and price >= " . ($priceOT / (100 + $percent) * 100) . " AND price <= " . ($priceDO / (100 + $percent) * 100);
}
$sql = "select * from " . $this->getValue('base.products') . " where " . $where . " enabled='1' and parent_enabled='0' " . $price_sort . " " . $sort . $string . ' limit 0,' . $this->max_item;
}
else {
return $order;
}
return $sql;
}
function currency($name = 'code') {
if (isset($_SESSION['valuta']))
$currency = $_SESSION['valuta'];
else
$currency = $this->dengi;
$row = $this->select(array('*'), array('id' => '=' . intval($currency)), false, array('limit' => 1), __FUNCTION__, array('base' => $this->getValue('base.currency'), 'cache' => 'true'));
if ($name == 'code' and ( $row['iso'] == 'RUR' or $row['iso'] == "RUB"))
return 'p';
return $row[$name];
}
function select($select, $where, $order = false, $option = array('limit' => 1), $function_name = false, $from = false, $mysql_error = true) {
if (is_array($from)) {
$base = @$from['base'];
$cache = @$from['cache'];
if (!empty($from['cache_format']))
$cache_format = $from['cache_format'];
} else {
$base = $this->objBase;
$cache = $this->cache;
$cache_format = $this->cache_format;
}
$PHPShopOrm = new PHPShopOrm($base);
$PHPShopOrm->objBase = $base;
$PHPShopOrm->debug = $this->debug;
$PHPShopOrm->cache = $cache;
$PHPShopOrm->mysql_error = $mysql_error;
$PHPShopOrm->cache_format = $cache_format;
$result = $PHPShopOrm->select($select, $where, $order, $option, __CLASS__, $function_name);
return $result;
}
function price($row, $newprice = false, $promo = true) {
if ($this->memory_get(__CLASS__ . '.' . __FUNCTION__, true)) {
$hook = $this->setHook(__CLASS__, __FUNCTION__, $row, $newprice);
if ($hook) {
return $hook;
} else
$this->memory_set(__CLASS__ . '.' . __FUNCTION__, 0);
}
if (empty($newprice)) {
$price = $row['price'];
} else {
$price = $row['price_n'];
$row['price2'] = $row['price3'] = $row['price4'] = $row['price5'] = null;
}
if ($promo) {
$promotions = $this->PHPShopPromotions->getPrice($row);
if (is_array($promotions)) {
if (empty($newprice))
$price = $promotions['price'];
else
$price = $promotions['price_n'];
}
}
return PHPShopProductFunction::GetPriceValuta($row['id'], array($price, $row['price2'], $row['price3'], $row['price4'], $row['price5']), $row['baseinputvaluta']);
}
function setPaginator($count = null, $sql = null) {
if ($this->setHook(__CLASS__, __FUNCTION__, array('count' => $count, 'sql' => $sql), 'START'))
return true;
$type = $this->memory_get(__CLASS__ . '.' . __FUNCTION__);
if (!$type) {
if (!PHPShopParser::checkFile("paginator/paginator_one_link.tpl")) {
$type = "lib";
} else {
$type = "templates";
}
$this->memory_set(__CLASS__ . '.' . __FUNCTION__, $type);
}
if ($type == "lib") {
$template_location = "./phpshop/lib/templates/";
$template_location_bool = true;
}
$this->count = $count;
$SQL = null;
$nWhere = 1;
if (is_array($this->where)) {
foreach ($this->where as $pole => $value) {
$SQL .= $pole . $value;
if ($nWhere < count($this->where))
$SQL .= $this->PHPShopOrm->Option['where'];
$nWhere++;
}
} else
$SQL = $sql;
$sort = '?';
if (!empty($_GET['v']) and is_array($_GET['v']))
foreach ($_GET['v'] as $key => $val) {
if (is_array($val)) {
foreach ($val as $v)
$sort .= 'v[' . $key . '][]=' . $v . '&';
} else if (is_numeric($key) and is_numeric($val))
$sort .= 'v[' . $key . ']=' . $val . '&';
}
if (!empty($_GET['s']) and is_numeric($_GET['s']))
$sort .= 's=' . $_GET['s'] . '&';
if (!empty($_GET['f']) and is_numeric($_GET['f']))
$sort .= 'f=' . $_GET['f'] . '&';
$sort = substr($sort, 0, strlen($sort) - 1);
$this->PHPShopOrm->comment = __CLASS__ . '.' . __FUNCTION__;
$result = $this->PHPShopOrm->query("select COUNT('id') as count, (price_n - price) as discount from " . $this->objBase . ' where ' . $SQL);
$row = mysqli_fetch_array($result);
$this->num_page = $row['count'];
$i = 1;
$navigat = $delim;
$num = @ceil($this->num_page / $this->num_row);
$this->max_page = $num;
if (((int) $this->page > 1) && $this->page > $this->num_page and $this->page != 'ALL') {
return $this->setError404();
}
if ($num > 1) {
if ($this->page >= $num) {
$p_to = $i - 1;
$p_do = $this->page - 1;
} else {
$p_to = $this->page + 1;
$p_do = 1;
}
if ($this->page != 'ALL')
$this->set("paginPageCurnet", $this->page);
else
$this->set("paginPageCurnet", '-');
$this->set("paginPageCount", $num);
while ($i <= $num) {
if ($i > 1) {
$p_start = $this->num_row * ($i - 1) + 1;
$p_end = $p_start + $this->num_row - 1;
} else {
$p_start = $i;
$p_end = $this->num_row;
}
$this->set("paginPageRangeStart", $p_start);
$this->set("paginPageRangeEnd", $p_end);
$this->set("paginPageNumber", $i);
if ($i != $this->page) {
if ($i == 1) {
$this->set("paginLink", $GLOBALS['SysValue']['dir']['dir'] . substr($this->objPath, 0, strlen($this->objPath) - 1) . '.html' . $sort);
$navigat .= parseTemplateReturn($template_location . "paginator/paginator_one_link.tpl", $template_location_bool);
} else {
if ($i > ($this->page - $this->nav_len) and $i < ($this->page + $this->nav_len)) {
$this->set("paginLink", $GLOBALS['SysValue']['dir']['dir'] . $this->objPath . $i . '.html' . $sort);
$navigat .= parseTemplateReturn($template_location . "paginator/paginator_one_link.tpl", $template_location_bool);
} else if ($i - ($this->page + $this->nav_len) < 3 and ( ($this->page - $this->nav_len) - $i) < 3) {
$navigat .= parseTemplateReturn($template_location . "paginator/paginator_one_more.tpl", $template_location_bool);
}
}
} else
$navigat .= parseTemplateReturn($template_location . "paginator/paginator_one_selected.tpl", $template_location_bool);
$i++;
}
$this->set("pageNow", $this->getValue('lang.page_now'));
$this->set("navBack", $this->lang('nav_back'));
$this->set("navNext", $this->lang('nav_forw'));
$this->set("navigation", $navigat);
if ($p_do == 1)
$this->set("previousLink", $GLOBALS['SysValue']['dir']['dir'] . substr($this->objPath, 0, strlen($this->objPath) - 1) . '.html' . $sort);
else
$this->set("previousLink", $GLOBALS['SysValue']['dir']['dir'] . $this->objPath . ($p_do) . '.html' . $sort);
if ($p_to == 0 or strtoupper($this->page) == 'ALL')
$this->set("nextLink", $GLOBALS['SysValue']['dir']['dir'] . substr($this->objPath, 0, strlen($this->objPath) - 1) . '.html' . $sort);
else
$this->set("nextLink", $GLOBALS['SysValue']['dir']['dir'] . $this->objPath . ($p_to) . '.html' . $sort);
if (strtoupper($this->page) == 'ALL')
$this->set("allPages", parseTemplateReturn($template_location . "paginator/paginator_all_pages_link_selected.tpl", $template_location_bool));
else {
$this->set("allPagesLink", $this->objPath . 'ALL.html' . $sort);
$this->set("allPages", parseTemplateReturn($template_location . "paginator/paginator_all_pages_link.tpl", $template_location_bool));
}
$nav = parseTemplateReturn($template_location . "paginator/paginator_main.tpl", $template_location_bool);
$this->set('productPageNav', $nav);
}
$this->setHook(__CLASS__, __FUNCTION__, $nav, 'END');
}
function queryMultibase() {
global $queryMultibase;
if (defined("HostID") or defined("HostMain")) {
if (!empty($queryMultibase))
return $queryMultibase;
$multi_cat = array();
$multi_dop_cat = null;
$where['skin_enabled '] = "!='1'";
if (defined("HostID"))
$where['servers'] = " REGEXP 'i" . HostID . "i'";
elseif (defined("HostMain"))
$where['skin_enabled'] .= ' and (servers ="" or servers REGEXP "i1000i")';
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['categories']);
$PHPShopOrm->debug = $this->debug;
$data = $PHPShopOrm->select(array('id'), $where, false, array('limit' => 1000), __CLASS__, __FUNCTION__);
if (is_array($data)) {
foreach ($data as $row) {
$multi_cat[] = $row['id'];
$multi_dop_cat .= " or dop_cat REGEXP '#" . $row['id'] . "#'";
}
}
$queryMultibase = $multi_select = ' and ( category IN (' . @implode(',', $multi_cat) . ')' . $multi_dop_cat . ')';
return $multi_select;
}
}
function errorMultibase($category, $dop_cat = null) {
if (defined("HostID") or defined("HostMain")) {
if (empty($this->multi_cat)) {
if (strstr($dop_cat, "#")) {
$dop_cat_array = explode("#", $dop_cat);
if (is_array($dop_cat_array))
foreach ($dop_cat_array as $v)
if (!empty($v))
$dop_cat_array_true[] = intval($v);
if (is_array($dop_cat_array_true))
$where['id'] = ' IN ("' . $category . '", "' . @implode('","', $dop_cat_array_true) . '")';
}
$where['skin_enabled'] = "!='1'";
if (defined("HostID"))
$where['servers'] = " REGEXP 'i" . HostID . "i'";
elseif (defined("HostMain"))
$where['skin_enabled'] .= ' and (servers ="" or servers REGEXP "i1000i")';
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['categories']);
$PHPShopOrm->debug = $this->debug;
$PHPShopOrm->cache = false;
$data = $PHPShopOrm->select(array('id'), $where, false, array('limit' => 10000));
if (is_array($data)) {
foreach ($data as $row) {
$this->multi_cat[] = $row['id'];
}
}
}
if (in_array($category, $this->multi_cat)) {
return false;
}
if (count($dop_cat_array_true) > 0) {
$this->category = $dop_cat_array_true[0];
$this->PHPShopCategory = new PHPShopCategory($this->category);
$this->category_name = $this->PHPShopCategory->getName();
if (count($this->multi_cat) == 0)
return true;
} else if (!in_array($category, $this->multi_cat))
return true;
}
}
function getStore() {
if(is_array($this->warehouse)) {
return;
}
$this->warehouse = [];
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['warehouses']);
$where['enabled'] = "='1'";
if (defined("HostID") or defined("HostMain")) {
if (defined("HostID"))
$where['servers'] = " REGEXP 'i" . HostID . "i'";
elseif (defined("HostMain"))
$where['enabled'] .= ' and (servers ="" or servers REGEXP "i1000i")';
}
$data = $PHPShopOrm->select(array('*'), $where, array('order' => 'num'), array('limit' => 100));
if (is_array($data))
foreach ($data as $row) {
if (!empty($row['description']))
$this->warehouse[$row['id']] = $row['description'];
else
$this->warehouse[$row['id']] = $row['name'];
}
}
function checkStore($row = array()) {
$this->set('productValutaName', $this->currency);
if (empty($row['ed_izm']))
$row['ed_izm'] = $this->lang('product_on_sklad_i');
$this->set('productEdIzm', $row['ed_izm']);
$promotions = $this->PHPShopPromotions->getPrice($row);
if (is_array($promotions)) {
$priceColumn = $this->PHPShopSystem->getPriceColumn();
$row[$priceColumn] = $promotions['price'];
$row['price_n'] = $promotions['price_n'];
$row['promo_label'] = $promotions['label'];
}
if ($this->sklad_enabled == 1) {
$this->getStore($row);
if (is_array($this->warehouse) and count($this->warehouse) > 0) {
$this->set('productSklad', '');
if ($this->warehouse_sum == 1)
$this->set('productSklad', PHPShopText::div(__('') . ": " . $row['items'] . " " . $row['ed_izm']), true);
foreach ($this->warehouse as $store_id => $store_name) {
if(isset($row['items' . $store_id])) {
$this->set('productSklad', PHPShopText::div($store_name . ": " . $row['items' . $store_id] . " " . $row['ed_izm']), true);
}
}
} else
$this->set('productSklad', $this->lang('product_on_sklad') . " " . $row['items'] . " " . $row['ed_izm']);
} else
$this->set('productSklad', '');
$price = $this->price($row, false, false);
if ($price > $this->price_max)
$this->price_max = $price;
if (empty($this->price_min))
$this->price_min = $price;
if ($price < $this->price_min)
$this->price_min = $price;
$this->set('productSchemaPrice', $price);
$price = number_format($price, $this->format, '.', ' ');
if (empty($row['sklad'])) {
$this->set('Notice', '');
$this->set('ComStartCart', '');
$this->set('ComEndCart', '');
$this->set('ComStartNotice', PHPShopText::comment('<'));
$this->set('ComEndNotice', PHPShopText::comment('>'));
$this->set('elementCartHide', null);
$this->set('elementNoticeHide', 'hide hidden');
$this->set('productOutStock', null);
$this->set('productPriceRub', null);
}
else {
$this->set('productPriceRub', $this->lang('sklad_mesage'));
$this->set('productOutStock', $this->lang('sklad_mesage'));
$this->set('ComStartNotice', '');
$this->set('ComEndNotice', '');
$this->set('elementCartHide', 'hide hidden');
$this->set('ComStartCart', PHPShopText::comment('<'));
$this->set('ComEndCart', PHPShopText::comment('>'));
$this->set('productNotice', $this->lang('product_notice'));
$this->set('elementNoticeHide', null);
$this->set('elementCartOptionHide', 'hide hidden');
$this->set('productSklad', '');
$this->set('productPriceOld', '');
$this->set('productLabelDiscount', '');
}
if (empty($row['price_n'])) {
$this->set('productPrice', $price);
$this->set('productLabelDiscount', null);
$this->set('productPriceOld', null);
}
else {
$productPrice = $price;
$productPriceNew = $this->price($row, true, false);
$this->set('productPrice', $productPrice);
$this->set('productPriceOld', PHPShopText::strike($productPriceNew . " " . $this->currency, $this->format));
$this->set('productLabelDiscount', '-' . ceil(($row['price_n'] - $row['price']) * 100 / $row['price_n']) . '%');
}
if (empty($row['price'])) {
$this->set('ComStartCart', PHPShopText::comment('<'));
$this->set('ComEndCart', PHPShopText::comment('>'));
$this->set('elementCartHide', 'hide hidden');
$this->set('productPrice', null);
$this->set('productPriceRub', null);
$this->set('productValutaName', null);
$this->set('productPriceOld', null);
}
if (!empty($row['parent'])) {
$this->set('parentLangFrom', __(''));
$this->set('elementCartHide', 'hide hidden');
$this->set('ComStartCart', PHPShopText::comment('<'));
$this->set('ComEndCart', PHPShopText::comment('>'));
$this->set('productSale', $this->lang('product_select'));
if (empty($row['sklad']))
$this->set('elementCartOptionHide', null);
}
else {
$this->set('elementCartOptionHide', 'hide hidden');
$this->set('parentLangFrom', null);
$this->set('productSale', $this->lang('product_sale'));
}
if ($this->user_price_activate == 1 and empty($_SESSION['UsersId'])) {
$this->set('ComStartCart', PHPShopText::comment('<'));
$this->set('ComEndCart', PHPShopText::comment('>'));
$this->set('productPrice', null);
$this->set('productPriceRub', null);
$this->set('productValutaName', null);
$this->set('elementCartOptionHide', 'hide hidden');
$this->set('elementCartHide', 'hide hidden');
$this->set('parentLangFrom', null);
$this->set('productPriceOld', null);
}
if (!empty($row['promo_label'])) {
$this->set('promoLabel', $row['promo_label']);
$this->set('promotionsIcon', ParseTemplateReturn('product/promoIcon.tpl'));
} else
$this->set('promotionsIcon', '');
if ($this->memory_get(__CLASS__ . '.' . __FUNCTION__, true)) {
$hook = $this->setHook(__CLASS__, __FUNCTION__, $row);
if ($hook) {
return $hook;
} else
$this->memory_set(__CLASS__ . '.' . __FUNCTION__, 0);
}
}
function setCell($d1, $d2 = null, $d3 = null, $d4 = null, $d5 = null, $d6 = null, $d7 = null) {
if ($this->grid)
$this->grid_style = 'class="setka"';
else
$this->grid_style = '';
$this->separator = null;
$Arg = func_get_args();
$item = 1;
foreach ($Arg as $key => $value)
if ($key < $this->cell)
$args[] = $value;
$num = count($args);
switch ($num) {
case 1:
$panel = array('panel_l panel_1_1');
break;
case 2:
$panel = array('panel_l panel_2_1', 'panel_r panel_2_2');
break;
case 3:
$panel = array('panel_l panel_3_1', 'panel_r panel_3_2', 'panel_l panel_3_2');
break;
case 4:
$panel = array('panel_l panel_4_1', 'panel_r panel_4_2', 'panel_l panel_4_3', 'panel_l panel_4_4');
break;
case 5:
$panel = array('panel_l panel_5_1', 'panel_r panel_5_2', 'panel_l panel_5_3', 'panel_l panel_5_4', 'panel_l panel_5_5');
break;
default: $panel = array('panel_l', 'panel_r', 'panel_l', 'panel_r', 'panel_l', 'panel_r', 'panel_l');
}
switch ($this->cell_type) {
case 'li':
if (is_array($args))
foreach ($args as $key => $val) {
$tr .= '<li class="' . $this->cell_type_class . '">' . $val . '</li>';
$item++;
}
break;
case 'div':
if (is_array($args))
foreach ($args as $key => $val) {
$tr .= '<div class="' . $this->cell_type_class . '">' . $val . '</div>';
$item++;
}
break;
case 'bootstrap':
$tr = '<div class="row">';
if (is_array($args))
foreach ($args as $key => $val) {
$tr .= $val;
$item++;
}
$tr .= '</div>';
break;
default:
$tr = '<tr>';
if (is_array($args))
foreach ($args as $key => $val) {
$tr .= '<td class="' . $panel[$key] . '" valign="top">' . $val . '</td>';
if ($item < $num and $num == $this->cell)
$tr .= '<td ' . $this->grid_style . '><img src="images/spacer.gif" width="1"></td>';
$item++;
}
$tr .= '</tr>';
$this->separator = '<tr><td ' . $this->grid_style . ' colspan="' . ($this->cell * 2) . '" height="1"><img height="1" src="images/spacer.gif"></td></tr>';
if (!empty($this->setka_footer)) {
$tr .= $this->separator;
}
}
return $tr;
}
function calculateCell($category, $num_row) {
if (!empty($_REQUEST['gridChange'])) {
if ($_REQUEST['gridChange'] == 2 AND $num_row > 1) {
$_SESSION['gridChange'][$category] = $num_row;
$this->set("gridChange2", "btn-primary");
return $num_row;
} elseif ($_REQUEST['gridChange'] == 2) {
$_SESSION['gridChange'][$category] = 2;
$this->set("gridChange2", "btn-primary");
return 2;
} else {
$_SESSION['gridChange'][$category] = 1;
$this->set("gridChange", "btn-primary");
return 1;
}
} elseif (isset($_SESSION['gridChange'][$category])) {
if ($_SESSION['gridChange'][$category] > 1)
$this->set("gridChange2", "btn-primary");
else
$this->set("gridChange", "btn-primary");
return $_SESSION['gridChange'][$category];
}
if ($num_row > 1)
$this->set("gridChange2", "btn-primary");
else
$this->set("gridChange", "btn-primary");
return $num_row;
}
function parent($row) {
if($this->setHook(__CLASS__, __FUNCTION__, $row, 'START'))
return true;
$this->select_value = array();
$row['parent'] = PHPShopSecurity::CleanOut($row['parent']);
if (!empty($row['parent'])) {
$parent = explode(",", $row['parent']);
$this->set('ComStartCart', '<!--');
$this->set('ComEndCart', '-->');
if (is_array($parent))
foreach ($parent as $value) {
if (PHPShopProductFunction::true_parent($value))
$Product[$value] = $this->select(array('*'), array('uid' => '="' . $value . '"', 'enabled' => "='1'", 'sklad' => "!='1'"), false, false, __FUNCTION__);
else
$Product[intval($value)] = $this->select(array('*'), array('id' => '=' . intval($value), 'enabled' => "='1'", 'sklad' => "!='1'"), false, false, __FUNCTION__);
}
if (!empty($row['price']) and empty($row['priceSklad']) and ( !empty($row['items']) or ( empty($row['items']) and $this->sklad_status == 1))) {
$this->select_value[] = array($row['name'] . " - (" . $this->price($row) . "
" . $this->currency . ')', $row['id'], false);
} else {
$this->set('ComStartNotice', PHPShopText::comment('<'));
$this->set('ComEndNotice', PHPShopText::comment('>'));
}
if (is_array($Product))
foreach ($Product as $p) {
if (!empty($p)) {
if (empty($p['priceSklad']) and ( !empty($p['items']) or ( empty($p['items']) and $this->sklad_status == 1))) {
$price = $this->price($p);
$this->select_value[] = array($p['name'] . ' - (' . $price . ' ' . $this->currency . ')', $p['id'], false);
}
}
}
if (count($this->select_value) > 0) {
$this->set('parentList', PHPShopText::select('parentId', $this->select_value, "; max-width:300px;"));
$this->set('productParentList', ParseTemplateReturn("product/product_odnotip_product_parent.tpl"));
}
$this->set('productPrice', '');
$this->set('productPriceRub', '');
$this->set('productValutaName', '');
$this->setHook(__CLASS__, __FUNCTION__, $row, 'END');
}
}
function product_grid($dataArray, $cell = 2, $template = false) {
if (empty($cell))
$cell = 2;
$this->cell = $cell;
$this->setka_footer = true;
$table = null;
$j = 1;
$item = 1;
$lastmodified = 0;
$this->set('productSale', $this->lang('product_sale'));
$this->set('productSaleReady', $this->lang('productSaleReady'));
$this->set('productInfo', $this->lang('product_info'));
$this->set('productPriceMoney', $this->dengi);
$this->set('catalog', $this->lang('catalog'));
if ($this->PHPShopNav->getPage() > 0)
$this->set('productPageThis', $this->PHPShopNav->getPage());
elseif ($this->PHPShopNav->getPage() != 'ALL')
$this->set('productPageThis', 1);
$d1 = $d2 = $d3 = $d4 = $d5 = $d6 = $d7 = null;
if (is_array($dataArray)) {
$total = count($dataArray);
if ($total < $cell)
$this->grid = false;
foreach ($dataArray as $row) {
$this->checkStore($row);
$this->set('productName', $row['name']);
$this->set('productArt', $row['uid']);
$this->set('productDes', Parser($row['description']));
$this->set('productWeight', $row['weight']);
if ($row['datas'] > $lastmodified)
$lastmodified = $row['datas'];
$this->set('productImg', $row['pic_small']);
if (empty($row['pic_small']))
$this->set('productImg', $this->no_photo);
$this->set('productImgBigFoto', $row['pic_big']);
$this->set('productUid', $row['id']);
$this->set('previewSorts', $this->getPreviewSorts($dataArray, $row));
$this->doLoadFunction(__CLASS__, 'comment_rate', array("row" => $row, "type" => "CID"), 'shop');
$this->setHook(__CLASS__, __FUNCTION__, $row);
if (empty($template))
$template = $this->getValue('templates.main_product_forma_' . $this->cell);
$dis = ParseTemplateReturn($template);
if ($item == $total)
$this->setka_footer = false;
$cell_name = 'd' . $j;
$$cell_name = $dis;
if ($j == $this->cell) {
$table .= $this->setCell($d1, $d2, $d3, $d4, $d5, $d6, $d7);
$d1 = $d2 = $d3 = $d4 = $d5 = $d6 = $d7 = null;
$j = 0;
} elseif ($item == $total) {
$table .= $this->setCell($d1, $d2, $d3, $d4, $d5, $d6, $d7);
}
$j++;
$item++;
}
}
$this->lastmodified = $lastmodified;
return $table;
}
public function getPreviewSorts($products, $currentProduct) {
if(is_null($this->sortCategories)) {
$sortCategoryOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['sort_categories']);
$this->sortCategories = $sortCategoryOrm->getList(array('id', 'name'), array('show_preview' => '="1"'));
}
if (\count($this->sortCategories) === 0) {
return null;
}
if (\is_null($this->previewSorts)) {
$sortValueIds = array();
foreach ($products as $product) {
$vendorArray = unserialize($product['vendor_array']);
if (is_array($vendorArray)) {
foreach (array_values($vendorArray) as $sortValues) {
foreach ($sortValues as $sortValue) {
$sortValueIds[] = (int) $sortValue;
}
}
}
}
if (\count($sortValueIds) === 0) {
return null;
}
$sortOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['sort']);
$sorts = $sortOrm->getList(array('id', 'name'), array('`id` IN ' => sprintf('(%s)', implode(',', $sortValueIds))));
foreach ($sorts as $sort) {
$this->previewSorts[$sort['id']] = $sort['name'];
}
}
$vendorArray = unserialize($currentProduct['vendor_array']);
$html = '';
foreach ($this->sortCategories as $sortCategory) {
if (isset($vendorArray[$sortCategory['id']])) {
foreach ($vendorArray[$sortCategory['id']] as $value) {
$titles = array();
if (isset($this->previewSorts[(int) $value])) {
$titles[] = $this->previewSorts[(int) $value];
}
}
$this->set('previewSortTitle', $sortCategory['name']);
$this->set('previewSortValue', implode(', ', $titles));
$html .= ParseTemplateReturn("product/preview_sort_one.tpl");
}
}
$this->set('previewSorts', $html);
return ParseTemplateReturn("product/preview_sorts.tpl");
}
}
?>