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:
<?php
class PHPShopProductElements extends PHPShopElements {
var $cache = false;
var $template_debug = true;
var $cache_format = array('content');
var $grid = false;
var $num_row = 9;
var $memory = false;
var $no_photo = 'images/shop/no_photo.gif';
var $total = 0;
var $product_grid;
var $cell_type = 'default';
var $cell_type_class = 'product-element-block';
var $warehouse;
function __construct() {
global $PHPShopPromotions;
$this->objBase = $GLOBALS['SysValue']['base']['products'];
PHPShopObj::loadClass('product');
parent::__construct();
$this->dengi = $this->PHPShopSystem->getParam('dengi');
$this->currency = $this->currency();
$this->PHPShopPromotions = $PHPShopPromotions;
$this->user_price_activate = $this->PHPShopSystem->getSerilizeParam('admoption.user_price_activate');
$this->format = intval($this->PHPShopSystem->getSerilizeParam("admoption.price_znak"));
$this->sklad_enabled = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_enabled');
$this->warehouse_sum = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_sum_enabled');
$this->setHtmlOption(__CLASS__);
}
function __call($name, $arguments) {
if ($name == __CLASS__) {
self::__construct();
}
}
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 seamply() {
$cell = 2;
$limit = 4;
$this->dataArray = $this->select(array('*'), array('enabled' => "='1'"), array('order' => 'RAND()'), array('limit' => $limit), __FUNCTION__);
$this->product_grid($this->dataArray, $cell);
$this->compile();
}
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' => 10000), __CLASS__, __FUNCTION__);
if (is_array($data)) {
foreach ($data as $row) {
$multi_cat[] = $row['id'];
$multi_dop_cat.=" or dop_cat REGEXP '#" . $row['id'] . "#'";
}
}
if (count($multi_cat) > 0)
$queryMultibase = $multi_select = ' and ( category IN (' . @implode(',', $multi_cat) . ') ' . $multi_dop_cat . ')';
return $multi_select;
}
}
function setramdom($limit) {
if (empty($_SESSION['max_item'])) {
$PHPShopOrm = new PHPShopOrm();
$PHPShopOrm->debug = $this->debug;
$PHPShopOrm->cache = false;
$PHPShopOrm->sql = 'SELECT MAX(id) as max_item FROM ' . $GLOBALS['SysValue']['base']['products'];
$data = $PHPShopOrm->select();
if (is_array($data[0]))
$this->max_item = $data[0]['max_item'];
else
$this->max_item = 0;
$_SESSION['max_item'] = $this->max_item;
}
else
$this->max_item = $_SESSION['max_item'];
$limit_start = rand(1, $this->max_item / rand(1, 7));
return ' BETWEEN ' . $limit_start . ' and ' . round($limit_start + $limit + $this->max_item / 3);
}
function select($select, $where, $order = false, $option = array('limit' => 1), $function_name = false, $from = false) {
$cache_format = null;
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->cache_format = $cache_format;
$result = $PHPShopOrm->select($select, $where, $order, $option, __CLASS__, $function_name);
return $result;
}
function compile() {
if ($this->cell_type == 'default' or $this->cell_type == 'table')
$table = '<table cellpadding="0" cellspacing="0" border="0">' . $this->product_grid . '</table>';
else
$table = $this->product_grid;
$this->product_grid = null;
return $table;
}
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)) {
$row['price'] = $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 == 0)
$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;
$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('productSklad', '');
$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('elementCartHide', 'hide hidden');
$this->set('elementNoticeHide', null);
$this->set('elementCartOptionHide', 'hide hidden');
$this->set('productPriceOld', null);
}
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('>'));
}
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('productValutaName', null);
$this->set('productPriceRub', null);
$this->set('elementCartHide', 'hide hidden');
$this->set('elementCartOptionHide', '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 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'];
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 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']);
$sklad_status = $this->PHPShopSystem->getSerilizeParam('admoption.sklad_status');
$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'"), false, false, __FUNCTION__);
}
if (!empty($row['price']) and empty($row['priceSklad']) and (!empty($row['items']) or (empty($row['items']) and $sklad_status == 1))) {
$this->select_value[] = array($row['name'] . " - (" . $this->price($row) . "
" . $this->get('productValutaName') . ')', $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 $sklad_status == 1))) {
$price = $this->price($p);
$this->select_value[] = array($p['name'] . ' - (' . $price . ' ' . $this->get('productValutaName') . ')', $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, $template = false, $line = true, $mod = false) {
if (!empty($line))
$this->grid = true;
else
$this->grid = false;
if (empty($cell))
$cell = 2;
$this->cell = $cell;
$this->setka_footer = true;
$table = null;
$j = 1;
$item = 1;
$this->set('productInfo', $this->lang('productInfo'));
$this->set('productSale', $this->lang('productSale'));
$this->set('productSaleReady', $this->lang('productSaleReady'));
$d1 = $d2 = $d3 = $d4 = $d5 = $d6 = $d7 = null;
if (is_array($dataArray)) {
$this->total = count($dataArray);
foreach ($dataArray as $row) {
$this->checkStore($row);
$this->set('productName', $row['name']);
$this->set('productArt', $row['uid']);
$this->set('productDes', $row['description']);
$this->set('productPageThis', $this->PHPShopNav->getPage());
if (empty($row['pic_small']))
$this->set('productImg', $this->no_photo);
else
$this->set('productImg', $row['pic_small']);
$this->set('productImgBigFoto', $row['pic_big']);
$this->set('productPriceMoney', $this->PHPShopSystem->getValue('dengi'));
$this->set('productUid', $row['id']);
$this->set('catalog', $this->lang('catalog'));
$this->doLoadFunction(__CLASS__, 'comment_rate', array("row" => $row, "type" => "CID"), 'shop');
if (empty($template))
$template = 'main_product_forma_' . $this->cell;
$this->setHook(__CLASS__, __FUNCTION__, $row);
$dis = ParseTemplateReturn($this->getValue('templates.' . $template), $mod, $this->template_debug);
if ($item == $this->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 == $this->total) {
$table.=$this->setCell($d1, $d2, $d3, $d4, $d5, $d6, $d7);
}
$j++;
$item++;
}
}
$this->product_grid = $table;
return $table;
}
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 = '';
$Arg = func_get_args();
$item = 1;
foreach ($Arg as $key => $value)
if ($key < $this->cell and $this->total >= $this->cell)
$args[] = $value;
elseif (!empty($value))
$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_r 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>';
if (!empty($this->setka_footer))
$tr.='<tr><td ' . $this->grid_style . ' colspan="' . ($this->cell * 2) . '" height="1"><img height="1" src="images/spacer.gif"></td></tr>';
}
return $tr;
}
}
?>