[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_module/mod_shop/ -> frontend.render.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  
  31  // Module/Plug-in Shop & Products
  32  
  33  $_shop_load_cat          = strpos($content['all'], '{SHOP_CATEGOR');
  34  $_shop_load_list         = strpos($content['all'], '{SHOP_PRODUCTLIST}');
  35  $_shop_load_cart_small    = strpos($content['all'], '{CART_SMALL}');
  36  $_shop_load_order        = strpos($content['all'], '{SHOP_ORDER_PROCESS}');
  37  
  38  
  39  // set CART session value
  40  if(!isset($_SESSION['shopping_cart'])) {
  41      $_SESSION['shopping_cart'] = array();
  42  }
  43  
  44  
  45  if( $_shop_load_cat !== false || $_shop_load_list !== false || $_shop_load_order !== false || $_shop_load_cart_small !== false) {
  46  
  47      // load template
  48      $_tmpl = array( 'config' => array(), 'source' => '' );
  49      $_tmpl['source'] = @file_get_contents($phpwcms['modules']['shop']['path'].'template/default/default.html');
  50      if($_tmpl['source'])
  51      {
  52          $_tmpl['config'] = parse_ini_str(get_tmpl_section('CONFIG', $_tmpl['source']), false);
  53          
  54          $_tmpl['config']['cat_list_products']        = empty($_tmpl['config']['cat_list_products']) ? false : boolval($_tmpl['config']['cat_list_products']);
  55          $_tmpl['config']['image_list_lightbox']        = empty($_tmpl['config']['image_list_lightbox']) ? false : boolval($_tmpl['config']['image_list_lightbox']);
  56          $_tmpl['config']['image_detail_lightbox']    = empty($_tmpl['config']['image_detail_lightbox']) ? false : boolval($_tmpl['config']['image_detail_lightbox']);
  57          $_tmpl['config']['image_detail_crop']        = empty($_tmpl['config']['image_detail_crop']) ? false : boolval($_tmpl['config']['image_detail_crop']);
  58          $_tmpl['config']['image_list_crop']            = empty($_tmpl['config']['image_list_crop']) ? false : boolval($_tmpl['config']['image_list_crop']);
  59          
  60          // handle custom fields
  61          $_tmpl['config']['shop_field'] = array();
  62          $custom_field_number = 1;
  63          while( !empty( $_tmpl['config']['shop_field_' . $custom_field_number] ) ) {
  64          
  65              $custom_field_type = explode('_', trim($_tmpl['config']['shop_field_' . $custom_field_number]) );
  66              if($custom_field_type[0] === 'STRING' || $custom_field_type[0] === 'TEXTAREA') {
  67                  $_tmpl['config']['shop_field'][ $custom_field_number ]['type'] = $custom_field_type[0];
  68                  if(isset($custom_field_type[1]) && $custom_field_type[1] == 'REQ') {
  69                      $_tmpl['config']['shop_field'][ $custom_field_number ]['required'] = true;
  70                      if(empty($custom_field_type[2])) {
  71                          $_tmpl['config']['shop_field'][ $custom_field_number ]['label'] = 'Custom '.$custom_field_number;
  72                      } else {
  73                          $_tmpl['config']['shop_field'][ $custom_field_number ]['label'] = trim($custom_field_type[2]);
  74                      }
  75                  } elseif(empty($custom_field_type[1])) {
  76                      $_tmpl['config']['shop_field'][ $custom_field_number ]['required'] = false;
  77                      $_tmpl['config']['shop_field'][ $custom_field_number ]['label'] = 'Custom '.$custom_field_number;
  78                  } else {
  79                      $_tmpl['config']['shop_field'][ $custom_field_number ]['required'] = false;
  80                      $_tmpl['config']['shop_field'][ $custom_field_number ]['label'] = trim($custom_field_type[1]);
  81                  }
  82              }
  83              $custom_field_number++;
  84          }
  85      
  86          if($_shop_load_list) {
  87              $_tmpl['list_header']    = get_tmpl_section('LIST_HEADER',    $_tmpl['source']);
  88              $_tmpl['list_entry']    = get_tmpl_section('LIST_ENTRY',    $_tmpl['source']);
  89              $_tmpl['list_space']    = get_tmpl_section('LIST_SPACE',    $_tmpl['source']);
  90              $_tmpl['list_none']        = get_tmpl_section('LIST_NONE',        $_tmpl['source']);
  91              $_tmpl['list_footer']    = get_tmpl_section('LIST_FOOTER',    $_tmpl['source']);
  92              $_tmpl['detail']        = get_tmpl_section('DETAIL',        $_tmpl['source']);
  93              $_tmpl['image_space']    = get_tmpl_section('IMAGE_SPACE',    $_tmpl['source']);
  94          }
  95          
  96          if($_shop_load_cart_small) {    
  97              $_tmpl['cart_small']    = get_tmpl_section('CART_SMALL',    $_tmpl['source']);
  98          }
  99          
 100          if($_shop_load_order) {    
 101              $_tmpl['cart_header']    = get_tmpl_section('CART_HEADER',            $_tmpl['source']);
 102              $_tmpl['cart_entry']    = get_tmpl_section('CART_ENTRY',            $_tmpl['source']);
 103              $_tmpl['cart_space']    = get_tmpl_section('CART_SPACE',            $_tmpl['source']);
 104              $_tmpl['cart_footer']    = get_tmpl_section('CART_FOOTER',            $_tmpl['source']);
 105              $_tmpl['cart_none']        = get_tmpl_section('CART_NONE',                $_tmpl['source']);
 106              $_tmpl['inv_address']    = get_tmpl_section('ORDER_INV_ADDRESS',        $_tmpl['source']);
 107              $_tmpl['order_terms']    = get_tmpl_section('ORDER_TERMS',            $_tmpl['source']);
 108              $_tmpl['term_entry']    = get_tmpl_section('ORDER_TERMS_ITEM',        $_tmpl['source']);
 109              $_tmpl['term_space']    = get_tmpl_section('ORDER_TERMS_ITEMSPACE',    $_tmpl['source']);
 110              $_tmpl['mail_customer']    = get_tmpl_section('MAIL_CUSTOMER',            $_tmpl['source']);
 111              $_tmpl['mail_neworder']    = get_tmpl_section('MAIL_NEWORDER',            $_tmpl['source']);
 112              $_tmpl['order_success']    = get_tmpl_section('ORDER_DONE',            $_tmpl['source']);
 113              $_tmpl['order_failed']    = get_tmpl_section('ORDER_NOT_DONE',        $_tmpl['source']);
 114              $_tmpl['mail_item']        = get_tmpl_section('MAIL_ITEM',                $_tmpl['source']);
 115          }
 116      }
 117      
 118      // merge config settings like translations and so on    
 119      $_tmpl['config'] = array_merge(    array(
 120                              'cat_all'                => '@@All products@@',
 121                              'cat_list_products'        => false,
 122                              'price_decimals'        => 2,
 123                              'vat_decimals'            => 0,
 124                              'weight_decimals'        => 0,
 125                              'dec_point'                => ".",
 126                              'thousands_sep'            => ",",
 127                              'image_list_width'        => 200,
 128                              'image_list_height'        => 200,
 129                              'image_detail_width'    => 200,
 130                              'image_detail_height'    => 200,
 131                              'image_zoom_width'        => 750,
 132                              'image_zoom_height'        => 500,
 133                              'image_list_lightbox'    => false,
 134                              'image_detail_lightbox'    => true,
 135                              'image_detail_crop'        => false,
 136                              'image_list_crop'        => false,
 137                              'mail_customer_subject'    => "[#{ORDER}] Your order at MyShop",
 138                              'mail_neworder_subject'    => "[#{ORDER}] New order",
 139                              'label_payby_prepay'    => "@@Cash with order@@",
 140                              'label_payby_pod'        => "@@Cash on delivery@@",
 141                              'label_payby_onbill'    => "@@On account@@",
 142                              'order_number_style'    => 'RANDOM',
 143                              'cat_list_sort_by'        => 'shopprod_name1 ASC'
 144                          ),    $_tmpl['config'] );
 145      
 146      // set preferences
 147      $_shopPref = array();
 148      foreach( array( 'shop_pref_currency', 'shop_pref_unit_weight', 'shop_pref_vat', 'shop_pref_email_to', 
 149                      'shop_pref_email_from', 'shop_pref_email_paypal', 'shop_pref_shipping', 
 150                      'shop_pref_payment' ) as $value ) {
 151          _getConfig( $value, '_shopPref' );
 152      }
 153  
 154      $_tmpl['config']['shop_url'] = _getConfig( 'shop_pref_id_shop', '_shopPref' );
 155      $_tmpl['config']['cart_url'] = _getConfig( 'shop_pref_id_cart', '_shopPref' );
 156      
 157      if(!is_numeric($_tmpl['config']['shop_url']) && is_string($_tmpl['config']['shop_url'])) {
 158          $_tmpl['config']['shop_url']    = trim($_tmpl['config']['shop_url']);
 159      } elseif(is_numeric($_tmpl['config']['shop_url']) && intval($_tmpl['config']['shop_url'])) {
 160          $_tmpl['config']['shop_url']    = 'aid='.intval($_tmpl['config']['shop_url']);
 161      } else {
 162          $_tmpl['config']['shop_url']    = $aktion[1] ? 'aid='.$aktion[1] : 'id='.$aktion[0];
 163      }
 164      
 165      if(!is_numeric($_tmpl['config']['cart_url']) && is_string($_tmpl['config']['cart_url'])) {
 166          $_tmpl['config']['cart_url']    = trim($_tmpl['config']['cart_url']);
 167      } elseif(is_numeric($_tmpl['config']['cart_url']) && intval($_tmpl['config']['cart_url'])) {
 168          $_tmpl['config']['cart_url']    = 'aid='.intval($_tmpl['config']['cart_url']);
 169      } else {
 170          $_tmpl['config']['cart_url']    = $aktion[1] ? 'aid='.$aktion[1] : 'id='.$aktion[0];
 171      }
 172      
 173      $_tmpl['config']['shop_url'] = 'index.php?' . $_tmpl['config']['shop_url'];
 174      $_tmpl['config']['cart_url'] = 'index.php?' . $_tmpl['config']['cart_url'];
 175      
 176      
 177      // OK get cart post data
 178      if( isset($_POST['shop_action']) ) {
 179      
 180          switch($_POST['shop_action']) {
 181          
 182              case 'add':        $shop_prod_id        = intval($_POST['shop_prod_id']);
 183                              $shop_prod_amount    = abs( intval($_POST['shop_prod_amount']) );
 184                              if(empty($shop_prod_id) || empty($shop_prod_amount)) break; // leave
 185                              
 186                              // add product to shopping 
 187                              if(isset($_SESSION['shopping_cart']['products'][$shop_prod_id])) {
 188                                  $_SESSION['shopping_cart']['products'][$shop_prod_id] += $shop_prod_amount;
 189                              } else {
 190                                  $_SESSION['shopping_cart']['products'][$shop_prod_id]  = $shop_prod_amount;
 191                              }
 192                              
 193                              break;
 194          
 195          }
 196      
 197      } elseif( isset($_POST['shop_prod_amount']) && is_array($_POST['shop_prod_amount']) ) {
 198      
 199          foreach($_POST['shop_prod_amount'] as $prod_id => $prod_qty) {
 200          
 201              $prod_id  = intval($prod_id);
 202              $prod_qty = abs( intval($prod_qty) );
 203              if(isset($_SESSION['shopping_cart']['products'][$prod_id])) {
 204                  if($prod_qty) {
 205                      $_SESSION['shopping_cart']['products'][$prod_id] = $prod_qty;
 206                  } else {
 207                      unset($_SESSION['shopping_cart']['products'][$prod_id]);
 208                  }
 209              }        
 210          }
 211      
 212      } elseif( isset($_POST['shop_order_step1']) ) {
 213      
 214          // handle invoice address -> checkout
 215          
 216          $_SESSION['shopping_cart']['step1'] = array(
 217      
 218              'INV_FIRSTNAME'    => isset($_POST['shop_inv_firstname']) ? clean_slweg($_POST['shop_inv_firstname']) : '',
 219              'INV_NAME'        => isset($_POST['shop_inv_name']) ? clean_slweg($_POST['shop_inv_name']) : '',
 220              'INV_ADDRESS'    => isset($_POST['shop_inv_address']) ? clean_slweg($_POST['shop_inv_address']) : '',
 221              'INV_ZIP'        => isset($_POST['shop_inv_zip']) ? clean_slweg($_POST['shop_inv_zip']) : '',
 222              'INV_CITY'        => isset($_POST['shop_inv_city']) ? clean_slweg($_POST['shop_inv_city']) : '',
 223              'INV_REGION'    => isset($_POST['shop_inv_region']) ? clean_slweg($_POST['shop_inv_region']) : '',
 224              'INV_COUNTRY'    => isset($_POST['shop_inv_country']) ? clean_slweg($_POST['shop_inv_country']) : '',
 225              'EMAIL'            => isset($_POST['shop_email']) ? clean_slweg($_POST['shop_email']) : '',
 226              'PHONE'            => isset($_POST['shop_phone']) ? clean_slweg($_POST['shop_phone']) : ''
 227                      
 228                      );
 229          
 230          // retrieve all custom field POST data
 231          foreach($_tmpl['config']['shop_field'] as $key => $row) {
 232              
 233              $_SESSION['shopping_cart']['step1']['shop_field_'.$key] = empty($_POST['shop_field_'.$key]) ? '' : clean_slweg($_POST['shop_field_'.$key]);
 234              if($row['required'] && $_SESSION['shopping_cart']['step1']['shop_field_'.$key] === '') {
 235                  $ERROR['inv_address']['shop_field_'.$key] = $row['required'] . ' must be filled';
 236              }        
 237          }
 238          
 239          $payment_options = get_payment_options();
 240          if(!empty($_POST['shopping_payment']) && isset($payment_options[$_POST['shopping_payment']])) {
 241              $_SESSION['shopping_cart']['payby'] = $_POST['shopping_payment'];
 242          } else {
 243              $ERROR['inv_address']['payment'] = true;
 244          }
 245          
 246          if(empty($_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'])) {
 247              $ERROR['inv_address']['INV_FIRSTNAME'] = '@@First name must be filled@@';
 248          }
 249          if(empty($_SESSION['shopping_cart']['step1']['INV_NAME'])) {
 250              $ERROR['inv_address']['INV_NAME'] = '@@Name must be filled@@';
 251          }
 252          if(empty($_SESSION['shopping_cart']['step1']['INV_ADDRESS'])) {
 253              $ERROR['inv_address']['INV_ADDRESS'] = '@@Address must be filled@@';
 254          }
 255          if(empty($_SESSION['shopping_cart']['step1']['INV_ZIP'])) {
 256              $ERROR['inv_address']['INV_ZIP'] = '@@ZIP must be filled@@';
 257          }
 258          if(empty($_SESSION['shopping_cart']['step1']['INV_CITY'])) {
 259              $ERROR['inv_address']['INV_CITY'] = '@@City must be filled@@';
 260          }
 261          if(empty($_SESSION['shopping_cart']['step1']['EMAIL']) || !is_valid_email($_SESSION['shopping_cart']['step1']['EMAIL'])) {
 262              $ERROR['inv_address']['EMAIL'] = '@@Email must be filled or is invalid@@';
 263          }
 264          if(empty($_SESSION['shopping_cart']['step1']['PHONE'])) {
 265              $ERROR['inv_address']['PHONE'] = '@@Phone must be filled@@';
 266          }
 267          if(isset($ERROR['inv_address']) && count($ERROR['inv_address'])) {
 268              $_SESSION['shopping_cart']['error']['step1'] = true;
 269          } elseif(isset($_SESSION['shopping_cart']['error']['step1'])) {
 270              unset($_SESSION['shopping_cart']['error']['step1']);
 271          }
 272  
 273      
 274      
 275      } elseif( isset($_POST['shop_order_submit']) ) {
 276      
 277          if(empty($_POST['shop_terms_agree'])) {
 278              $_SESSION['shopping_cart']['error']['step2'] = true;
 279          } elseif(isset($_SESSION['shopping_cart']['error']['step2'])) {
 280              unset($_SESSION['shopping_cart']['error']['step2']);
 281          }
 282          
 283      } elseif( isset($_SESSION['shopping_cart']['error']['step2']) && !isset($_POST['shop_order_submit'])) {
 284      
 285          unset($_SESSION['shopping_cart']['error']['step2']);
 286      
 287      }
 288  
 289  }
 290  
 291  
 292  // first we take categories
 293  if( $_shop_load_cat !== false ) {
 294  
 295      preg_match('/\{SHOP_CATEGORY:(\d+)\}/', $content['all'], $catmatch);
 296      if(!empty($catmatch[1])) {
 297          $shop_limited_cat = true;
 298          $shop_limited_catid = intval($catmatch[1]);
 299          if(empty($GLOBALS['_getVar']['shop_cat'])) {
 300              $GLOBALS['_getVar']['shop_cat'] = $shop_limited_catid;
 301          }
 302      } else {
 303          $shop_limited_cat = false;
 304      }
 305      
 306  
 307      $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_categories WHERE ';
 308      $sql .= "cat_type='module_shop' AND cat_status=1 AND cat_pid=0 ";
 309      if($shop_limited_cat) {
 310          $sql .= 'AND cat_id = ' . $shop_limited_catid . ' ';
 311      }
 312      $sql .= 'ORDER BY cat_name ASC';
 313      $data = _dbQuery($sql);
 314      
 315      $shop_cat = array();
 316      
 317      $shop_cat_selected    = isset($GLOBALS['_getVar']['shop_cat']) ? $GLOBALS['_getVar']['shop_cat'] : 'all';
 318      if(strpos($shop_cat_selected, '_')) {
 319          $shop_cat_selected = explode('_', $shop_cat_selected, 2);
 320          if(isset($shop_cat_selected[1])) {
 321              $shop_subcat_selected    = intval($shop_cat_selected[1]);
 322          }
 323          $shop_cat_selected = intval($shop_cat_selected[0]);
 324          if(!$shop_cat_selected) {
 325              $shop_cat_selected        = 'all';
 326              $shop_subcat_selected    = 0;
 327          }
 328      } else {
 329          $shop_subcat_selected = 0;
 330      }
 331      
 332      
 333      $shop_detail_id        = isset($GLOBALS['_getVar']['shop_detail']) ? intval($GLOBALS['_getVar']['shop_detail']) : 0;
 334      unset($GLOBALS['_getVar']['shop_cat'], $GLOBALS['_getVar']['shop_detail']);
 335  
 336      $shop_cat_link  = $_tmpl['config']['shop_url'];
 337      
 338      if($shop_detail_id) {
 339          $GLOBALS['_getVar']['shop_detail'] = $shop_detail_id;
 340      }
 341      
 342      if(is_array($data) && count($data)) {
 343  
 344          $x = 0;
 345      
 346          foreach($data as $row) {
 347          
 348              if($shop_limited_cat && $row['cat_id'] != $shop_limited_catid) {
 349                  continue;
 350              }
 351              
 352              $shop_cat_prods = '';
 353              $shop_cat[$x]   = '<li';
 354              if($row['cat_id'] == $shop_cat_selected) {
 355                  $shop_cat[$x] .= ' class="active"';
 356                  
 357                  // now try to retrieve sub categories for active category
 358                  $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_categories WHERE ';
 359                  $sql .= "cat_type='module_shop' AND cat_status=1 AND cat_pid=" . $shop_cat_selected ;
 360                  $sql .= ' ORDER BY cat_name ASC';
 361                  $sdata = _dbQuery($sql);
 362                  
 363                  $subcat_count = count($sdata);
 364                  
 365                  $selected_product_cat = $subcat_count && $shop_subcat_selected ? $shop_subcat_selected : $shop_cat_selected;
 366                  
 367                  if($subcat_count) {
 368                      
 369                      $shop_subcat = array();
 370                      $z = 0;
 371                      foreach($sdata as $srow) {
 372                      
 373                          $shop_subcat[$z]   = '<li';
 374                          if($srow['cat_id'] == $shop_subcat_selected) {
 375                              $shop_subcat[$z] .= ' class="active"';    
 376                          }
 377                          $shop_subcat[$z]  .= '>';
 378                          $shop_subcat[$z] .= '<a href="' . $shop_cat_link . '&amp;shop_cat=' . $srow['cat_pid'] . '_' . $srow['cat_id'] . '">';
 379                          $shop_subcat[$z] .= html_specialchars($srow['cat_name']);
 380                          $shop_subcat[$z] .= '</a>';
 381                          if($srow['cat_id'] == $shop_subcat_selected && $_tmpl['config']['cat_list_products']) {
 382                              $shop_subcat[$z] .= get_category_products($srow['cat_id'], $shop_detail_id, $shop_cat_selected, $shop_subcat_selected, $shop_cat_link);
 383                          }
 384                          $shop_subcat[$z] .= '</li>';
 385                          
 386                          $z++;
 387                      }
 388                      
 389                      if(count($shop_subcat)) {
 390                          $shop_cat_prods = LF . '        <ul>' . LF.'            ' . implode(LF.'            ', $shop_subcat) . LF .'        </ul>' . LF.'    ';
 391                      }
 392                  
 393                  }
 394                  
 395                  if($_tmpl['config']['cat_list_products']) {
 396                       $shop_cat_prods .= get_category_products($shop_cat_selected, $shop_detail_id, $shop_cat_selected, $shop_subcat_selected, $shop_cat_link);
 397                  }
 398                  
 399              }
 400              $shop_cat[$x] .= '>';
 401              $shop_cat[$x] .= '<a href="' . $shop_cat_link . '&amp;shop_cat=' . $row['cat_id'] . '">';
 402              $shop_cat[$x] .= html_specialchars($row['cat_name']);
 403              $shop_cat[$x] .= '</a>' . $shop_cat_prods;
 404              $shop_cat[$x] .= '</li>';
 405          
 406              $x++;
 407          }    
 408      
 409      }
 410      
 411      if( count($shop_cat) ) {
 412      
 413          if( ! $shop_limited_cat ) {
 414              $shop_cat[$x]  = '<li';
 415              if($shop_cat_selected == 'all') {
 416                  $shop_cat[$x] .= ' class="active"';
 417              }
 418              $shop_cat[$x] .= '>';
 419              $shop_cat[$x] .= '<a href="' . $shop_cat_link . '&amp;shop_cat=all">';
 420              $shop_cat[$x] .= html_specialchars($_tmpl['config']['cat_all']);
 421              $shop_cat[$x] .= '</a>';
 422              $shop_cat[$x] .= '</li>';
 423          }
 424          $shop_cat = '<ul class="shop_cat">' . LF.'    ' . implode(LF.'    ', $shop_cat) . LF . '</ul>';
 425          
 426      
 427      } else {
 428          
 429          $shop_cat = '';
 430          
 431      }
 432      
 433      $content['all'] = str_replace('{SHOP_CATEGORIES}', $shop_cat, $content['all']);
 434      $content['all'] = preg_replace('/\{SHOP_CATEGORY:\d+\}/', $shop_cat, $content["all"]);
 435      
 436      if($shop_cat_selected) {
 437          $GLOBALS['_getVar']['shop_cat'] = $shop_cat_selected;
 438          if($shop_subcat_selected) {
 439              $GLOBALS['_getVar']['shop_cat'] .= '_' . $shop_subcat_selected;
 440          }
 441      }
 442  
 443  }
 444  
 445  
 446  // Ok lets search for product listing
 447  if( $_shop_load_list !== false ) {
 448  
 449      // check selected category
 450      $shop_cat_selected    = isset($GLOBALS['_getVar']['shop_cat']) ? $GLOBALS['_getVar']['shop_cat'] : 0;
 451      if(strpos($shop_cat_selected, '_')) {
 452          $shop_cat_selected = explode('_', $shop_cat_selected, 2);
 453          if(isset($shop_cat_selected[1])) {
 454              $shop_subcat_selected    = intval($shop_cat_selected[1]);
 455          }
 456          $shop_cat_selected = intval($shop_cat_selected[0]);
 457          if(!$shop_cat_selected) {
 458              //$shop_cat_selected        = 'all';
 459              $shop_subcat_selected    = 0;
 460          }
 461      } else {
 462          $shop_cat_selected        = intval($shop_cat_selected);
 463          $shop_subcat_selected    = 0;
 464      }
 465      $selected_product_cat = $shop_subcat_selected ? $shop_subcat_selected : $shop_cat_selected;
 466      
 467      $shop_detail_id        = isset($GLOBALS['_getVar']['shop_detail']) ? intval($GLOBALS['_getVar']['shop_detail']) : 0;
 468      
 469      $shop_cat_name = get_shop_category_name($shop_cat_selected);
 470  
 471      if(empty($shop_cat_name)) {
 472          $shop_cat_name        = $_tmpl['config']['cat_all'];
 473          $shop_cat_selected    = 0;
 474      }
 475      
 476      $sql  = "SELECT * FROM ".DB_PREPEND.'phpwcms_shop_products WHERE ';
 477      $sql .= "shopprod_status=1";
 478  
 479      if($selected_product_cat && !$shop_detail_id) {
 480  
 481          $sql .= ' AND (';
 482          $sql .= "shopprod_category = '" . $selected_product_cat . "' OR ";
 483          $sql .= "shopprod_category LIKE '%," . $selected_product_cat . ",%' OR ";
 484          $sql .= "shopprod_category LIKE '" . $selected_product_cat . ",%' OR ";
 485          $sql .= "shopprod_category LIKE '%," . $selected_product_cat . "'";
 486          $sql .= ')';
 487      
 488      } elseif($shop_detail_id) {
 489  
 490          $sql .= ' AND shopprod_id=' . $shop_detail_id;
 491      
 492      } else {
 493          
 494          $sql .= ' AND shopprod_listall=1';
 495          
 496      }
 497      
 498      $_tmpl['config']['cat_list_sort_by'] = trim($_tmpl['config']['cat_list_sort_by']);
 499      if($_tmpl['config']['cat_list_sort_by'] !== '') {
 500          $sql .= ' ORDER BY '.aporeplace($_tmpl['config']['cat_list_sort_by']);
 501      }
 502      
 503      $data = _dbQuery($sql);
 504      
 505      if( count($shop_cat) ) {
 506      
 507          $x = 0;
 508          $entry = array();
 509  
 510          $shop_prod_detail = rel_url(array(), array('shop_detail'));
 511          
 512          $_tmpl['config']['init_lightbox'] = false;
 513  
 514          foreach($data as $row) {
 515          
 516              $_price['vat'] = $row['shopprod_vat'];
 517              if($row['shopprod_netgross'] == 1) {
 518                  // price given is GROSS price, including VAT
 519                  $_price['net']        = $row['shopprod_price'] / (1 + $_price['vat'] / 100);
 520                  $_price['gross']    = $row['shopprod_price'];
 521              } else {
 522                  // price given is NET price, excluding VAT
 523                  $_price['net']        = $row['shopprod_price'];
 524                  $_price['gross']    = $row['shopprod_price'] * (1 + $_price['vat'] / 100);
 525              }
 526              
 527              $_price['vat']        = number_format($_price['vat'],   $_tmpl['config']['vat_decimals'],   $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep']);
 528              $_price['net']        = number_format($_price['net'],   $_tmpl['config']['price_decimals'], $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep']);
 529              $_price['gross']    = number_format($_price['gross'], $_tmpl['config']['price_decimals'], $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep']);
 530              $_price['weight']    = $row['shopprod_weight'] > 0 ? number_format($row['shopprod_weight'], $_tmpl['config']['weight_decimals'], $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep']) : '';
 531              
 532              $row['shopprod_var'] = @unserialize($row['shopprod_var']);
 533              
 534              // select template based on listing or detail view
 535              $entry[$x] = $shop_detail_id ? $_tmpl['detail'] : $_tmpl['list_entry'];
 536              
 537              $_cart = preg_match("/\[CART_ADD\](.*?)\[\/CART_ADD\]/is", $entry[$x], $g) ? $g[1] : '';
 538              
 539              $_cart_add  = '<form action="' . $shop_prod_detail . '" method="post">';
 540              $_cart_add .= '<input type="hidden" name="shop_prod_id" value="' . $row['shopprod_id'] . '" />';
 541              $_cart_add .= '<input type="hidden" name="shop_action" value="add" />';
 542              $_cart_add .= '<input type="hidden" name="shop_prod_amount" value="1" />';
 543              if(strpos($_cart, 'input ')) {
 544                  // user has set input button
 545                  $_cart_add .= $_cart;
 546              } else {
 547                  $_cart_add .= '<input type="submit" name="shop_cart_add" value="' . html_specialchars($_cart) . '" class="cart_add_button" />';
 548              }
 549              $_cart_add .= '</form>';
 550  
 551              $entry[$x] = preg_replace('/\[CART_ADD\](.*?)\[\/CART_ADD\]/is', $_cart_add , $entry[$x]);
 552              
 553              // product name
 554              $entry[$x] = str_replace('{CURRENCY_SYMBOL}', html_entities($_shopPref['shop_pref_currency']), $entry[$x]);
 555              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_TITLE', html_specialchars($row['shopprod_name1']));
 556              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_ADD', html_specialchars($row['shopprod_name2']));
 557              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_SHORT', $row['shopprod_description0']);
 558              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_LONG', $row['shopprod_description1']);
 559              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_WEIGHT', $_price['weight']);
 560              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_NET_PRICE', $_price['net']);
 561              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_GROSS_PRICE', $_price['gross']);
 562              $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_VAT', $_price['vat']);
 563              $entry[$x] = render_cnt_template($entry[$x], 'ORDER_NUM', html_specialchars($row['shopprod_ordernumber']));
 564              $entry[$x] = render_cnt_template($entry[$x], 'MODEL', html_specialchars($row['shopprod_model']));
 565              $entry[$x] = render_cnt_template($entry[$x], 'VIEWED', number_format($row['shopprod_track_view'], 0, $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep']));
 566              
 567              if($shop_detail_id) {
 568                  
 569                  $_tmpl['config']['mode']        = 'detail';
 570                  $_tmpl['config']['lightbox_id']    = '[product_'.$x.'_'.$shop_detail_id.']';
 571                  
 572                  // product detail
 573                  $entry[$x] = str_replace('{PRODUCT_DETAIL_LINK}', $shop_prod_detail, $entry[$x]);
 574                  
 575                  $_prod_list_img = array();
 576                  
 577                  if(count($row['shopprod_var']['images'])) {
 578  
 579                      foreach($row['shopprod_var']['images'] as $img_key => $img_vars) {
 580                          if($img_vars = shop_image_tag($row['shopprod_var']['images'][$img_key])) {
 581                              $_prod_list_img[] = $img_vars;
 582                          }
 583                      }
 584                  }
 585                  $_prod_list_img = implode($_tmpl['image_space'], $_prod_list_img);
 586                  
 587                  
 588                  // Update product view count
 589                  // ToDo: Maybe use cookie or session to avoid tracking in case showed once
 590                  $sql = 'UPDATE LOW_PRIORITY '.DB_PREPEND.'phpwcms_shop_products SET shopprod_track_view=shopprod_track_view+1 WHERE shopprod_id='.$shop_detail_id;
 591                  _dbQuery($sql, 'UPDATE');
 592                  
 593              } else {
 594                  
 595                  $_tmpl['config']['mode']        = 'list';
 596                  $_tmpl['config']['lightbox_id']    = '';
 597              
 598                  if(count($row['shopprod_var']['images'])) {
 599                      $_prod_list_img = shop_image_tag($row['shopprod_var']['images'][0]);
 600                  } else {
 601                      $_prod_list_img = '';
 602                  }
 603                  
 604                  // product listing
 605                  $entry[$x] = str_replace('{PRODUCT_DETAIL_LINK}', $shop_prod_detail.'&amp;shop_detail='.$row['shopprod_id'], $entry[$x]);
 606                  
 607              }
 608              
 609              if(!$_tmpl['config']['init_lightbox'] && $_tmpl['config']['image_'.$_tmpl['config']['mode'].'_lightbox'] && $_prod_list_img) {
 610                  $_tmpl['config']['init_lightbox'] = true;
 611              }
 612              
 613              $entry[$x] = render_cnt_template($entry[$x], 'IMAGE', $_prod_list_img);
 614  
 615              $x++;
 616          }
 617          
 618          // initialize Lightbox effect
 619          if($_tmpl['config']['init_lightbox']) {
 620              initializeLightbox();
 621          }
 622          
 623          $entries = implode($_tmpl['list_space'], $entry);
 624  
 625      } else {
 626      
 627          $entries = $_tmpl['list_none'];
 628      
 629      }
 630      
 631  
 632      $entries = $_tmpl['list_header'] . LF . $entries . LF . $_tmpl['list_footer'];
 633      
 634      $entries = str_replace('{CATEGORY}', html_specialchars($shop_cat_name), $entries);
 635  
 636      $content['all'] = str_replace('{SHOP_PRODUCTLIST}', $entries, $content['all']);
 637      
 638  }
 639  
 640  if( $_shop_load_order ) {
 641  
 642      $cart_data = get_cart_data();
 643      
 644      if(empty($cart_data)) {
 645          
 646          // cart is empty
 647          $order_process = $_tmpl['cart_none'];
 648  
 649      } elseif(isset($_POST['shop_cart_checkout']) || isset($ERROR['inv_address']) || isset($_SESSION['shopping_cart']['error']['step1']) || isset($_POST['shop_edit_address'])) {
 650      
 651          // order Step 1 -> get address
 652      
 653          $_step1 = array(
 654                      'INV_FIRSTNAME' => '',
 655                      'INV_NAME' => '',
 656                      'INV_ADDRESS' => '',
 657                      'INV_ZIP' => '',
 658                      'INV_CITY' => '',
 659                      'INV_REGION' => '',
 660                      'INV_COUNTRY' => '',
 661                      'EMAIL' => '',
 662                      'PHONE' => ''
 663                          );
 664                          
 665          // handle custom fields
 666          foreach($_tmpl['config']['shop_field'] as $item_key => $row) {
 667              $_step1['shop_field_'.$item_key] = '';
 668          }
 669      
 670          if(isset($_SESSION['shopping_cart']['step1'])) {
 671              $_step1 = array_merge($_step1, $_SESSION['shopping_cart']['step1']);
 672          }
 673  
 674          // checkout step 1 -> insert invoice address
 675          $order_process = $_tmpl['inv_address'];
 676          
 677          foreach($_step1 as $item_key => $row) {
 678              $field_error   = empty($ERROR['inv_address'][$item_key]) ? '' : $ERROR['inv_address'][$item_key];
 679              
 680              $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row));
 681              $order_process = render_cnt_template($order_process, 'ERROR_'.$item_key, $field_error);
 682          }
 683          
 684          $payment_options = get_payment_options();
 685  
 686          if(count($payment_options)) {
 687          
 688              $payment_fields = array();
 689              $payment_selected = isset($_SESSION['shopping_cart']['payby']) && isset($payment_options[ $_SESSION['shopping_cart']['payby'] ]) ? $_SESSION['shopping_cart']['payby'] : '';
 690              foreach($payment_options as $item_key => $row) {
 691                  
 692                  $payment_fields[$item_key]  = '<div><label>';
 693                  $payment_fields[$item_key] .= '<input type="radio" name="shopping_payment" id="shopping_payment_'.$item_key.'" ';
 694                  $payment_fields[$item_key] .= 'value="'.$item_key.'" ';
 695                  if($payment_selected == $item_key) {
 696                      $payment_fields[$item_key] .= ' checked="checked"';
 697                  }
 698                  $payment_fields[$item_key] .= ' />';
 699                  $payment_fields[$item_key] .= '<span>' . html_specialchars($_tmpl['config']['label_payby_'.$item_key]) . '</span>';
 700                  $payment_fields[$item_key] .= '</label></div>';
 701              }
 702              $order_process = render_cnt_template($order_process, 'PAYMENT', implode(LF, $payment_fields));
 703          } else {
 704              $order_process = render_cnt_template($order_process, 'PAYMENT', '');
 705          }
 706          
 707          // some errr handling
 708          $order_process = render_cnt_template($order_process, 'ERROR_PAYMENT', isset($ERROR['inv_address']['payment']) ? ' ' : '');
 709          $order_process = render_cnt_template($order_process, 'IF_ERROR', isset($ERROR['inv_address']) ? ' ' : '');
 710          
 711          $order_process = '<form action="' .$_tmpl['config']['cart_url']. '" method="post">' . LF . trim($order_process) . LF . '</form>';
 712  
 713  
 714      } elseif( isset($_POST['shop_order_step1']) || isset($ERROR['terms']) || isset($_SESSION['shopping_cart']['error']['step2']) ) {
 715      
 716          // Order step 2 -> Proof and [X] terms of business
 717          $order_process = $_tmpl['order_terms'];
 718          
 719          $order_process = str_replace('{SHOP_LINK}', $_tmpl['config']['shop_url'], $order_process);
 720          $order_process = str_replace('{CART_LINK}', $_tmpl['config']['cart_url'], $order_process);
 721          
 722          foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) {
 723              $order_process = render_cnt_template($order_process, $item_key, nl2br(html_specialchars($row)));
 724          }
 725          
 726          $order_process = render_cnt_template($order_process, 'IF_ERROR', isset($_SESSION['shopping_cart']['error']['step2']) ? ' ' : '');
 727          
 728          if(isset($_SESSION['shopping_cart']['payby'])) {
 729              $order_process = render_cnt_template($order_process, 'PAYMENT', html_specialchars($_tmpl['config']['label_payby_'.$_SESSION['shopping_cart']['payby']]));
 730          } else {
 731              $order_process = render_cnt_template($order_process, 'PAYMENT', '');
 732          }
 733          
 734          $cart_mode = 'terms';
 735          include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php');
 736          $order_process = str_replace('{ITEMS}', implode($_tmpl['term_space'], $cart_items), $order_process);
 737          
 738          $terms_text        = _getConfig( 'shop_pref_terms', '_shopPref' );
 739          $terms_format    = _getConfig( 'shop_pref_terms_format', '_shopPref' );
 740          $order_process = str_replace('{TERMS}', $terms_format ? $terms_text : nl2br(html_specialchars($terms_text)), $order_process);
 741          
 742  
 743          include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php');
 744          
 745          // Is Shipping?
 746          //$order_process  = preg_replace('/\[SHIPPING\](.*?)\[\/SHIPPING\]/is', '' , $order_process);
 747          $order_process = render_cnt_template($order_process, 'SHIPPING', $subtotal['float_shipping_net'] > 0 ? 1 : '');
 748          
 749  
 750      } elseif( isset($_POST['shop_order_submit']) && !isset($_SESSION['shopping_cart']['error']['step2']) ) {
 751  
 752          // OK agreed - now send order
 753          
 754          if($_tmpl['config']['order_number_style'] == 'RANDOM') {
 755              $order_num = generic_string(8, 2);
 756          } else {
 757              // count all current orders
 758              $order_num = _dbCount('SELECT COUNT(*) FROM '.DB_PREPEND.'phpwcms_shop_orders') + 1;
 759              if(strpos($_tmpl['config']['order_number_style'], '%') !== FALSE) {
 760                  $order_num = sprintf($_tmpl['config']['order_number_style'], $order_num);
 761              }
 762          }
 763          
 764          // prepare customer mail
 765          $order_process = $_tmpl['mail_customer'];
 766  
 767          foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) {
 768              $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row));
 769          }
 770          
 771          $cart_mode = 'mail1';
 772          include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php');
 773          $order_process = str_replace('{ITEMS}', implode(LF.LF, $cart_items), $order_process);
 774  
 775          include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php');
 776  
 777          $order_process = str_replace('{ORDER}', $order_num, $order_process);
 778          $order_process = render_cnt_date($order_process, time());
 779          
 780          $mail_customer = @html_entity_decode($order_process);
 781          
 782          // prepare new order mail
 783          $order_process = $_tmpl['mail_neworder'];
 784          
 785          foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) {
 786              $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row));
 787          }
 788          
 789          $cart_mode = 'mail1';
 790          include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php');
 791          $order_process = str_replace('{ITEMS}', implode(LF.LF, $cart_items), $order_process);
 792  
 793          include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php');
 794  
 795          $order_process = str_replace('{ORDER}', $order_num, $order_process);
 796          $order_process = render_cnt_date($order_process, time());
 797          
 798          $mail_neworder = @html_entity_decode($order_process);
 799          
 800          if(!empty($_SESSION['shopping_cart']['payby'])) {
 801              $payment = $_SESSION['shopping_cart']['payby'];
 802              $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($payment), $_tmpl['config']['label_payby_'.$payment]);
 803              $mail_neworder = render_cnt_template($mail_neworder, 'PAYMENT', $_tmpl['config']['label_payby_'.$payment]);
 804          } else {
 805              $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($payment), 'n.a.');
 806              $mail_neworder = render_cnt_template($mail_neworder, 'PAYMENT', 'n.a.');
 807              $payment = 'n.a.';
 808          }
 809          
 810          $payment_options = get_payment_options();
 811          foreach($payment_options  as $item_key => $row) {
 812              $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($item_key), '');
 813          }
 814  
 815          // store order in database        
 816          $order_data = array(
 817              'order_number'        => $order_num,
 818              'order_date'        => gmdate('Y-m-d H:i'),
 819              'order_name'        => $_SESSION['shopping_cart']['step1']['INV_NAME'],
 820              'order_firstname'    => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'],
 821              'order_email'        => $_SESSION['shopping_cart']['step1']['EMAIL'],
 822              'order_net'            => $subtotal['float_total_net'],
 823              'order_gross'        => $subtotal['float_total_gross'],
 824              'order_payment'        => $payment,
 825              'order_data'        => @serialize( array(
 826                                                  'cart' => $cart_data, 
 827                                                  'address' => $_SESSION['shopping_cart']['step1'], 
 828                                                  'mail_customer' => $mail_customer,
 829                                                  'mail_self' => $mail_neworder,
 830                                                  'subtotal' => array(
 831                                                          'subtotal_net' => $subtotal['float_net'],
 832                                                          'subtotal_gross' => $subtotal['float_gross']
 833                                                                      ),
 834                                                  'shipping' => array(
 835                                                          'shipping_net' => $subtotal['float_shipping_net'],
 836                                                          'shipping_gross' => $subtotal['float_shipping_gross']
 837                                                                      ),
 838                                                  'weight' => $subtotal['float_weight']
 839                                                  ) ),
 840              'order_status'        => 'NEW-ORDER'        
 841          );
 842          
 843          // receive order db ID
 844          $order_data = _dbInsert('phpwcms_shop_orders', $order_data);
 845          
 846          // send mail to customer
 847          $email_from = _getConfig( 'shop_pref_email_from', '_shopPref' );
 848          if(!is_valid_email($email_from)) $email_from = $phpwcms['SMTP_FROM_EMAIL'];
 849  
 850          $order_mail_customer = array(
 851              'recipient'    => $_SESSION['shopping_cart']['step1']['EMAIL'],
 852              'toName'    => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'] . ' ' . $_SESSION['shopping_cart']['step1']['INV_NAME'],
 853              'subject'    => str_replace('{ORDER}', $order_num, $_tmpl['config']['mail_customer_subject']),
 854              'text'        => $mail_customer,
 855              'from'        => $email_from,
 856              'sender'    => $email_from
 857          );
 858          
 859          $order_data_mail_customer = sendEmail($order_mail_customer);
 860          
 861          // send mail to shop
 862          $send_order_to = convertStringToArray( _getConfig( 'shop_pref_email_to', '_shopPref' ), ';' );
 863          if(empty($send_order_to[0]) || !is_valid_email($send_order_to[0])) {
 864              $email_to = $phpwcms['SMTP_FROM_EMAIL'];
 865          } else {
 866              $email_to = $send_order_to[0];
 867              unset($send_order_to[0]);
 868          }
 869          
 870          $order_mail_self = array(
 871              'from'        => $_SESSION['shopping_cart']['step1']['EMAIL'],
 872              'fromName'    => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'] . ' ' . $_SESSION['shopping_cart']['step1']['INV_NAME'],
 873              'subject'    => str_replace('{ORDER}', $order_num, $_tmpl['config']['mail_neworder_subject']),
 874              'text'        => $mail_neworder,
 875              'recipient'    => $email_to,
 876              'sender'    => $_SESSION['shopping_cart']['step1']['EMAIL']
 877          );
 878          
 879          $order_data_mail_self = sendEmail($order_mail_self);
 880          
 881          // are there additional recipients for orders?
 882          if(count($send_order_to)) {
 883              foreach($send_order_to as $value) {
 884                  $order_mail_self['recipient'] = $value;
 885                  @sendEmail($order_mail_self);
 886              }
 887          }
 888          
 889      
 890          // success
 891          if(!empty($order_data['INSERT_ID']) || !empty($order_data_mail_customer[0])) {
 892      
 893              $order_process = $_tmpl['order_success'];
 894              
 895              foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) {
 896                  $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row));
 897              }
 898              unset($_SESSION['shopping_cart']);
 899  
 900          // NO success
 901          } else {
 902  
 903              $order_process = $_tmpl['order_failed'];
 904              
 905              $order_process = str_replace('{SUBJECT}', rawurlencode($_tmpl['config']['mail_neworder_subject']), $order_process);
 906              $order_process = str_replace('{MSG}', rawurlencode('---- FALLBACK MESSAGE ---' . LF . LF . $mail_customer), $order_process);
 907              
 908              foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) {
 909                  $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row));
 910              }
 911  
 912          }
 913          
 914          $order_process = str_replace('{ORDER}', $order_num, $order_process);
 915  
 916          
 917      } else {
 918      
 919          // show cart
 920          
 921          $cart_mode = 'cart';
 922          include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php');
 923          
 924          $order_process  = $_tmpl['cart_header'];
 925          $order_process .= implode($_tmpl['cart_space'], $cart_items);
 926          $order_process .= $_tmpl['cart_footer'];
 927          
 928          include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php');
 929          
 930          // Update Cart Button
 931          $_cart_button = preg_match("/\[UPDATE\](.*?)\[\/UPDATE\]/is", $order_process, $g) ? $g[1] : '';
 932          if(strpos($_cart_button, 'input ') === false) {
 933              $_cart_button = '<input type="submit" name="shop_cart_update" value="' . html_specialchars($_cart_button) . '" class="cart_update_button" />';
 934          }
 935          $order_process  = preg_replace('/\[UPDATE\](.*?)\[\/UPDATE\]/is', $_cart_button , $order_process);
 936          
 937          // Checkout Button
 938          $_cart_button = preg_match("/\[CHECKOUT\](.*?)\[\/CHECKOUT\]/is", $order_process, $g) ? $g[1] : '';
 939          if(strpos($_cart_button, 'input ') === false) {
 940              $_cart_button = '<input type="submit" name="shop_cart_checkout" value="' . html_specialchars($_cart_button) . '" class="cart_checkout_button" />';
 941          }
 942          $order_process  = preg_replace('/\[CHECKOUT\](.*?)\[\/CHECKOUT\]/is', $_cart_button , $order_process);
 943          
 944          // Is Shipping?
 945          //$order_process  = preg_replace('/\[SHIPPING\](.*?)\[\/SHIPPING\]/is', '' , $order_process);
 946          $order_process = render_cnt_template($order_process, 'SHIPPING', $subtotal['float_shipping_net'] > 0 ? 1 : '');
 947          
 948          $order_process  = '<form action="' .$_tmpl['config']['cart_url']. '" method="post">' . LF . trim($order_process) . LF . '</form>';
 949          
 950      }
 951  
 952      $order_process = str_replace('{SHOP_LINK}', $_tmpl['config']['shop_url'], $order_process);
 953      
 954      $content['all'] = str_replace('{SHOP_ORDER_PROCESS}', $order_process, $content['all']);
 955  }
 956  
 957  // small cart
 958  if($_shop_load_cart_small) {
 959  
 960      $_cart_count = 0;
 961  
 962      if(isset($_SESSION['shopping_cart']['products']) && is_array($_SESSION['shopping_cart']['products']) && count($_SESSION['shopping_cart']['products'])) {
 963          foreach($_SESSION['shopping_cart']['products'] as $cartval) {
 964              $_cart_count += $cartval;
 965          }
 966      }    
 967  
 968      if(!$_cart_count) {
 969          $_cart_count = '';
 970      }
 971  
 972      if(strpos($_tmpl['cart_small'], '{CART_LINK}')) {
 973      
 974          $shop_cat_selected    = isset($GLOBALS['_getVar']['shop_cat']) ? $GLOBALS['_getVar']['shop_cat'] : 0;
 975          $shop_detail_id        = isset($GLOBALS['_getVar']['shop_detail']) ? intval($GLOBALS['_getVar']['shop_detail']) : 0;
 976          unset($GLOBALS['_getVar']['shop_cat'], $GLOBALS['_getVar']['shop_detail']);
 977          $_tmpl['cart_small'] = str_replace('{CART_LINK}', $_tmpl['config']['cart_url'], $_tmpl['cart_small']);
 978          if($shop_cat_selected) $GLOBALS['_getVar']['shop_cat'] = $shop_cat_selected;
 979          if($shop_detail_id) $GLOBALS['_getVar']['shop_detail'] = $shop_detail_id;
 980          
 981      }
 982      
 983      $_tmpl['cart_small'] = render_cnt_template($_tmpl['cart_small'], 'COUNT', $_cart_count);
 984      $content['all'] = str_replace('{CART_SMALL}', $_tmpl['cart_small'], $content['all']);
 985  }
 986  
 987  
 988  
 989  function get_cart_data() {
 990  
 991      // retrieve all cart data
 992      if(empty($_SESSION['shopping_cart']['products']) || ! is_array($_SESSION['shopping_cart']['products']) ||    ! count($_SESSION['shopping_cart']['products'])    ) 
 993      {
 994          return array();
 995      }
 996      
 997      $in = array();
 998      foreach($_SESSION['shopping_cart']['products'] as $key => $value) {
 999          $key = intval($key);
1000          $in[$key] = $key;
1001      }
1002  
1003      $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_shop_products WHERE shopprod_status=1 AND ';
1004      $sql .= 'shopprod_id IN (' . implode(',', $in) . ')';
1005      $data = _dbQuery($sql);
1006      
1007      if(isset($data[0])) {
1008      
1009          foreach($data as $key => $value) {
1010      
1011              $data[$key]['shopprod_quantity'] = $_SESSION['shopping_cart']['products'][ $value['shopprod_id'] ];
1012      
1013          }
1014      
1015      }
1016  
1017      return $data;    
1018  }
1019  
1020  
1021  
1022  function shop_image_tag($img) {
1023      
1024      //['config'][], $_tmpl['config']['']
1025      $config =& $GLOBALS['_tmpl']['config'];
1026      
1027      // set image values
1028      $width        = $config['image_'.$config['mode'].'_width'];
1029      $height        = $config['image_'.$config['mode'].'_height'];
1030      $crop        = $config['image_'.$config['mode'].'_crop'];
1031  
1032      $thumb_image = get_cached_image(
1033              array(    "target_ext"    =>    $img['f_ext'],
1034                      "image_name"    =>    $img['f_hash'] . '.' . $img['f_ext'],
1035                      "max_width"        =>    $width,
1036                      "max_height"    =>    $height,
1037                      "thumb_name"    =>    md5($img['f_hash'].$width.$height.$GLOBALS['phpwcms']["sharpen_level"].$crop),
1038                      'crop_image'    =>    $crop
1039                    )
1040              );
1041      
1042      if($thumb_image) {
1043          
1044          // now try to build caption and if neccessary add alt to image or set external link for image
1045          $caption    = getImageCaption($img['caption']);
1046          // set caption and ALT Image Text for imagelist
1047          $capt_cur    = html_specialchars($caption[0]);
1048          $caption[3] = empty($caption[3]) ? '' : ' title="'.html_specialchars($caption[3]).'"'; //title
1049          $caption[1] = html_specialchars(empty($caption[1]) ? $img['f_name'] : $caption[1]);
1050          
1051          $list_img_temp  = '<img src="'.PHPWCMS_IMAGES.$thumb_image[0].'" ';
1052          $list_img_temp .= $thumb_image[3].' alt="'.$caption[1].'"'.$caption[3].' border="0" />';
1053          
1054          // use lightbox effect
1055          if($config['image_'.$config['mode'].'_lightbox']) {
1056          
1057              $a  = '<a href="img/cmsimage.php/';
1058              $a .= $config['image_zoom_width'] . 'x' . $config['image_zoom_height'] . '/';
1059              $a .= $img['f_hash'] . '.' . $img['f_ext'] . '" ';
1060              $a .= 'target="_blank" rel="lightbox'.$config['lightbox_id'].'"' . $caption[3] .'>';
1061              
1062              $list_img_temp = $a . $list_img_temp . '</a>';
1063          }
1064          
1065          return $list_img_temp;
1066  
1067      }
1068      
1069      return '';
1070  }
1071  
1072  function get_shop_category_name($id) {
1073      if(empty($id)) return '';
1074      $sql  = 'SELECT cat_name FROM '.DB_PREPEND.'phpwcms_categories WHERE ';
1075      $sql .= "cat_type='module_shop' AND cat_status=1 AND cat_id=" . intval($id) . ' LIMIT 1';
1076      $data = _dbQuery($sql);
1077      if(is_array($data)) {
1078          foreach($data as $row) {
1079              return $row['cat_name'];
1080          }
1081      }
1082      return '';
1083  }
1084  
1085  function get_payment_options() {
1086  
1087      $payment_prefs = _getConfig( 'shop_pref_payment', '_shopPref' );
1088      $supported = array('prepay' => 0, 'pod' => 0, 'onbill' => 0);
1089      $available = array();
1090      foreach($supported as $key => $value) {
1091          if($payment_prefs[$key]) $available[$key] = $payment_prefs[$key];
1092      }
1093      return $available;
1094  }
1095  
1096  
1097  function get_category_products($selected_product_cat, $shop_detail_id, $shop_cat_selected, $shop_subcat_selected, $shop_cat_link) {
1098      
1099      $shop_cat_prods = '';
1100      
1101      $sql  = "SELECT * FROM ".DB_PREPEND.'phpwcms_shop_products WHERE ';
1102      $sql .= "shopprod_status=1";
1103      $sql .= ' AND (';
1104      $sql .= "shopprod_category = '" . $selected_product_cat . "' OR ";
1105      $sql .= "shopprod_category LIKE '%," . $selected_product_cat . ",%' OR ";
1106      $sql .= "shopprod_category LIKE '" . $selected_product_cat . ",%' OR ";
1107      $sql .= "shopprod_category LIKE '%," . $selected_product_cat . "'";
1108      $sql .= ')';
1109      $pdata = _dbQuery($sql);
1110      
1111      if(is_array($pdata) && count($pdata)) {
1112      
1113          $z = 0;
1114          $shop_cat_prods = array();
1115          foreach($pdata as $prow) {
1116              
1117              $shop_cat_prods[$z] = '<li';
1118              if($prow['shopprod_id'] == $shop_detail_id) {
1119                  $shop_cat_prods[$z] .= ' class="active"';
1120              }
1121              $shop_cat_prods[$z] .= '>';
1122              $shop_cat_prods[$z] .= '<a href="' . $shop_cat_link . '&amp;shop_cat=' . $shop_cat_selected;
1123              if($shop_subcat_selected) {
1124                  $shop_cat_prods[$z] .= '_' . $shop_subcat_selected;
1125              }
1126              $shop_cat_prods[$z] .= '&amp;shop_detail=' .$prow['shopprod_id']. '">';
1127              $shop_cat_prods[$z] .= html_specialchars($prow['shopprod_name1']);
1128              $shop_cat_prods[$z] .= '</a>';
1129              $shop_cat_prods[$z] .= '</li>';
1130              $z++;
1131          }
1132  
1133          if(count($shop_cat_prods)) {
1134              $shop_cat_prods = LF . '        <ul class="products">' . LF.'            ' . implode(LF.'            ', $shop_cat_prods) . LF .'        </ul>' . LF.'    ';
1135          }
1136      
1137      }
1138      
1139      return $shop_cat_prods;
1140  
1141  }
1142  
1143  
1144  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7