[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

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

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


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1