[ Index ] |
PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2010 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 . '&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 . '&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 . '&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 // check custom product URL 535 if(empty($row['shopprod_var']['url'])) { 536 $row['prod_url'] = array('link'=>'', 'target'=>''); 537 } else { 538 $row['prod_url'] = get_redirect_link($row['shopprod_var']['url'], ' ', ''); 539 $row['prod_url']['link'] = html_specialchars($row['prod_url']['link']); 540 } 541 542 // select template based on listing or detail view 543 $entry[$x] = $shop_detail_id ? $_tmpl['detail'] : $_tmpl['list_entry']; 544 545 $_cart = preg_match("/\[CART_ADD\](.*?)\[\/CART_ADD\]/is", $entry[$x], $g) ? $g[1] : ''; 546 547 $_cart_add = '<form action="' . $shop_prod_detail . '" method="post">'; 548 $_cart_add .= '<input type="hidden" name="shop_prod_id" value="' . $row['shopprod_id'] . '" />'; 549 $_cart_add .= '<input type="hidden" name="shop_action" value="add" />'; 550 $_cart_add .= '<input type="hidden" name="shop_prod_amount" value="1" />'; 551 if(strpos($_cart, 'input ')) { 552 // user has set input button 553 $_cart_add .= $_cart; 554 } else { 555 $_cart_add .= '<input type="submit" name="shop_cart_add" value="' . html_specialchars($_cart) . '" class="cart_add_button" />'; 556 } 557 $_cart_add .= '</form>'; 558 559 $entry[$x] = preg_replace('/\[CART_ADD\](.*?)\[\/CART_ADD\]/is', $_cart_add , $entry[$x]); 560 561 // product name 562 $entry[$x] = str_replace('{CURRENCY_SYMBOL}', html_entities($_shopPref['shop_pref_currency']), $entry[$x]); 563 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_TITLE', html_specialchars($row['shopprod_name1'])); 564 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_ADD', html_specialchars($row['shopprod_name2'])); 565 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_SHORT', $row['shopprod_description0']); 566 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_LONG', $row['shopprod_description1']); 567 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_WEIGHT', $_price['weight']); 568 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_NET_PRICE', $_price['net']); 569 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_GROSS_PRICE', $_price['gross']); 570 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_VAT', $_price['vat']); 571 $entry[$x] = render_cnt_template($entry[$x], 'PRODUCT_URL', $row['prod_url']['link']); 572 $entry[$x] = str_replace('{PRODUCT_URL_TARGET}', $row['prod_url']['target'], $entry[$x]); 573 $entry[$x] = render_cnt_template($entry[$x], 'ORDER_NUM', html_specialchars($row['shopprod_ordernumber'])); 574 $entry[$x] = render_cnt_template($entry[$x], 'MODEL', html_specialchars($row['shopprod_model'])); 575 $entry[$x] = render_cnt_template($entry[$x], 'VIEWED', number_format($row['shopprod_track_view'], 0, $_tmpl['config']['dec_point'], $_tmpl['config']['thousands_sep'])); 576 577 if($shop_detail_id) { 578 579 $_tmpl['config']['mode'] = 'detail'; 580 $_tmpl['config']['lightbox_id'] = '[product_'.$x.'_'.$shop_detail_id.']'; 581 582 // product detail 583 $entry[$x] = str_replace('{PRODUCT_DETAIL_LINK}', $shop_prod_detail, $entry[$x]); 584 585 $_prod_list_img = array(); 586 587 if(count($row['shopprod_var']['images'])) { 588 589 foreach($row['shopprod_var']['images'] as $img_key => $img_vars) { 590 if($img_vars = shop_image_tag($row['shopprod_var']['images'][$img_key])) { 591 $_prod_list_img[] = $img_vars; 592 } 593 } 594 } 595 $_prod_list_img = implode($_tmpl['image_space'], $_prod_list_img); 596 597 598 // Update product view count 599 // ToDo: Maybe use cookie or session to avoid tracking in case showed once 600 $sql = 'UPDATE LOW_PRIORITY '.DB_PREPEND.'phpwcms_shop_products SET shopprod_track_view=shopprod_track_view+1 WHERE shopprod_id='.$shop_detail_id; 601 _dbQuery($sql, 'UPDATE'); 602 603 } else { 604 605 $_tmpl['config']['mode'] = 'list'; 606 $_tmpl['config']['lightbox_id'] = ''; 607 608 if(count($row['shopprod_var']['images'])) { 609 $_prod_list_img = shop_image_tag($row['shopprod_var']['images'][0]); 610 } else { 611 $_prod_list_img = ''; 612 } 613 614 // product listing 615 $entry[$x] = str_replace('{PRODUCT_DETAIL_LINK}', $shop_prod_detail.'&shop_detail='.$row['shopprod_id'], $entry[$x]); 616 617 } 618 619 if(!$_tmpl['config']['init_lightbox'] && $_tmpl['config']['image_'.$_tmpl['config']['mode'].'_lightbox'] && $_prod_list_img) { 620 $_tmpl['config']['init_lightbox'] = true; 621 } 622 623 $entry[$x] = render_cnt_template($entry[$x], 'IMAGE', $_prod_list_img); 624 625 $x++; 626 } 627 628 // initialize Lightbox effect 629 if($_tmpl['config']['init_lightbox']) { 630 initSlimbox(); 631 } 632 633 $entries = implode($_tmpl['list_space'], $entry); 634 635 } else { 636 637 $entries = $_tmpl['list_none']; 638 639 } 640 641 642 $entries = $_tmpl['list_header'] . LF . $entries . LF . $_tmpl['list_footer']; 643 644 $entries = str_replace('{CATEGORY}', html_specialchars($shop_cat_name), $entries); 645 646 $content['all'] = str_replace('{SHOP_PRODUCTLIST}', $entries, $content['all']); 647 648 } 649 650 if( $_shop_load_order ) { 651 652 $cart_data = get_cart_data(); 653 654 if(empty($cart_data)) { 655 656 // cart is empty 657 $order_process = $_tmpl['cart_none']; 658 659 } elseif(isset($_POST['shop_cart_checkout']) || isset($ERROR['inv_address']) || isset($_SESSION['shopping_cart']['error']['step1']) || isset($_POST['shop_edit_address'])) { 660 661 // order Step 1 -> get address 662 663 $_step1 = array( 664 'INV_FIRSTNAME' => '', 665 'INV_NAME' => '', 666 'INV_ADDRESS' => '', 667 'INV_ZIP' => '', 668 'INV_CITY' => '', 669 'INV_REGION' => '', 670 'INV_COUNTRY' => '', 671 'EMAIL' => '', 672 'PHONE' => '' 673 ); 674 675 // handle custom fields 676 foreach($_tmpl['config']['shop_field'] as $item_key => $row) { 677 $_step1['shop_field_'.$item_key] = ''; 678 } 679 680 if(isset($_SESSION['shopping_cart']['step1'])) { 681 $_step1 = array_merge($_step1, $_SESSION['shopping_cart']['step1']); 682 } 683 684 // checkout step 1 -> insert invoice address 685 $order_process = $_tmpl['inv_address']; 686 687 foreach($_step1 as $item_key => $row) { 688 $field_error = empty($ERROR['inv_address'][$item_key]) ? '' : $ERROR['inv_address'][$item_key]; 689 690 $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row)); 691 $order_process = render_cnt_template($order_process, 'ERROR_'.$item_key, $field_error); 692 } 693 694 $payment_options = get_payment_options(); 695 696 if(count($payment_options)) { 697 698 $payment_fields = array(); 699 $payment_selected = isset($_SESSION['shopping_cart']['payby']) && isset($payment_options[ $_SESSION['shopping_cart']['payby'] ]) ? $_SESSION['shopping_cart']['payby'] : ''; 700 foreach($payment_options as $item_key => $row) { 701 702 $payment_fields[$item_key] = '<div><label>'; 703 $payment_fields[$item_key] .= '<input type="radio" name="shopping_payment" id="shopping_payment_'.$item_key.'" '; 704 $payment_fields[$item_key] .= 'value="'.$item_key.'" '; 705 if($payment_selected == $item_key) { 706 $payment_fields[$item_key] .= ' checked="checked"'; 707 } 708 $payment_fields[$item_key] .= ' />'; 709 $payment_fields[$item_key] .= '<span>' . html_specialchars($_tmpl['config']['label_payby_'.$item_key]) . '</span>'; 710 $payment_fields[$item_key] .= '</label></div>'; 711 } 712 $order_process = render_cnt_template($order_process, 'PAYMENT', implode(LF, $payment_fields)); 713 } else { 714 $order_process = render_cnt_template($order_process, 'PAYMENT', ''); 715 } 716 717 // some errr handling 718 $order_process = render_cnt_template($order_process, 'ERROR_PAYMENT', isset($ERROR['inv_address']['payment']) ? ' ' : ''); 719 $order_process = render_cnt_template($order_process, 'IF_ERROR', isset($ERROR['inv_address']) ? ' ' : ''); 720 721 $order_process = '<form action="' .$_tmpl['config']['cart_url']. '" method="post">' . LF . trim($order_process) . LF . '</form>'; 722 723 724 } elseif( isset($_POST['shop_order_step1']) || isset($ERROR['terms']) || isset($_SESSION['shopping_cart']['error']['step2']) ) { 725 726 // Order step 2 -> Proof and [X] terms of business 727 $order_process = $_tmpl['order_terms']; 728 729 $order_process = str_replace('{SHOP_LINK}', $_tmpl['config']['shop_url'], $order_process); 730 $order_process = str_replace('{CART_LINK}', $_tmpl['config']['cart_url'], $order_process); 731 732 foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) { 733 $order_process = render_cnt_template($order_process, $item_key, nl2br(html_specialchars($row))); 734 } 735 736 $order_process = render_cnt_template($order_process, 'IF_ERROR', isset($_SESSION['shopping_cart']['error']['step2']) ? ' ' : ''); 737 738 if(isset($_SESSION['shopping_cart']['payby'])) { 739 $order_process = render_cnt_template($order_process, 'PAYMENT', html_specialchars($_tmpl['config']['label_payby_'.$_SESSION['shopping_cart']['payby']])); 740 } else { 741 $order_process = render_cnt_template($order_process, 'PAYMENT', ''); 742 } 743 744 $cart_mode = 'terms'; 745 include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php'); 746 $order_process = str_replace('{ITEMS}', implode($_tmpl['term_space'], $cart_items), $order_process); 747 748 $terms_text = _getConfig( 'shop_pref_terms', '_shopPref' ); 749 $terms_format = _getConfig( 'shop_pref_terms_format', '_shopPref' ); 750 $order_process = str_replace('{TERMS}', $terms_format ? $terms_text : nl2br(html_specialchars($terms_text)), $order_process); 751 752 753 include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php'); 754 755 // Is Shipping? 756 //$order_process = preg_replace('/\[SHIPPING\](.*?)\[\/SHIPPING\]/is', '' , $order_process); 757 $order_process = render_cnt_template($order_process, 'SHIPPING', $subtotal['float_shipping_net'] > 0 ? 1 : ''); 758 759 760 } elseif( isset($_POST['shop_order_submit']) && !isset($_SESSION['shopping_cart']['error']['step2']) ) { 761 762 // OK agreed - now send order 763 764 if($_tmpl['config']['order_number_style'] == 'RANDOM') { 765 $order_num = generic_string(8, 2); 766 } else { 767 // count all current orders 768 $order_num = _dbCount('SELECT COUNT(*) FROM '.DB_PREPEND.'phpwcms_shop_orders') + 1; 769 if(strpos($_tmpl['config']['order_number_style'], '%') !== FALSE) { 770 $order_num = sprintf($_tmpl['config']['order_number_style'], $order_num); 771 } 772 } 773 774 // prepare customer mail 775 $order_process = $_tmpl['mail_customer']; 776 777 foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) { 778 $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row)); 779 } 780 781 $cart_mode = 'mail1'; 782 include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php'); 783 $order_process = str_replace('{ITEMS}', implode(LF.LF, $cart_items), $order_process); 784 785 include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php'); 786 787 $order_process = str_replace('{ORDER}', $order_num, $order_process); 788 $order_process = render_cnt_date($order_process, time()); 789 790 $mail_customer = @html_entity_decode($order_process); 791 792 // prepare new order mail 793 $order_process = $_tmpl['mail_neworder']; 794 795 foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) { 796 $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row)); 797 } 798 799 $cart_mode = 'mail1'; 800 include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php'); 801 $order_process = str_replace('{ITEMS}', implode(LF.LF, $cart_items), $order_process); 802 803 include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php'); 804 805 $order_process = str_replace('{ORDER}', $order_num, $order_process); 806 $order_process = render_cnt_date($order_process, time()); 807 808 $mail_neworder = @html_entity_decode($order_process); 809 810 if(!empty($_SESSION['shopping_cart']['payby'])) { 811 $payment = $_SESSION['shopping_cart']['payby']; 812 $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($payment), $_tmpl['config']['label_payby_'.$payment]); 813 $mail_neworder = render_cnt_template($mail_neworder, 'PAYMENT', $_tmpl['config']['label_payby_'.$payment]); 814 } else { 815 $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($payment), 'n.a.'); 816 $mail_neworder = render_cnt_template($mail_neworder, 'PAYMENT', 'n.a.'); 817 $payment = 'n.a.'; 818 } 819 820 $payment_options = get_payment_options(); 821 foreach($payment_options as $item_key => $row) { 822 $mail_customer = render_cnt_template($mail_customer, 'PAYBY_'.strtoupper($item_key), ''); 823 } 824 825 // store order in database 826 $order_data = array( 827 'order_number' => $order_num, 828 'order_date' => gmdate('Y-m-d H:i'), 829 'order_name' => $_SESSION['shopping_cart']['step1']['INV_NAME'], 830 'order_firstname' => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'], 831 'order_email' => $_SESSION['shopping_cart']['step1']['EMAIL'], 832 'order_net' => $subtotal['float_total_net'], 833 'order_gross' => $subtotal['float_total_gross'], 834 'order_payment' => $payment, 835 'order_data' => @serialize( array( 836 'cart' => $cart_data, 837 'address' => $_SESSION['shopping_cart']['step1'], 838 'mail_customer' => $mail_customer, 839 'mail_self' => $mail_neworder, 840 'subtotal' => array( 841 'subtotal_net' => $subtotal['float_net'], 842 'subtotal_gross' => $subtotal['float_gross'] 843 ), 844 'shipping' => array( 845 'shipping_net' => $subtotal['float_shipping_net'], 846 'shipping_gross' => $subtotal['float_shipping_gross'] 847 ), 848 'weight' => $subtotal['float_weight'] 849 ) ), 850 'order_status' => 'NEW-ORDER' 851 ); 852 853 // receive order db ID 854 $order_data = _dbInsert('phpwcms_shop_orders', $order_data); 855 856 // send mail to customer 857 $email_from = _getConfig( 'shop_pref_email_from', '_shopPref' ); 858 if(!is_valid_email($email_from)) $email_from = $phpwcms['SMTP_FROM_EMAIL']; 859 860 $order_mail_customer = array( 861 'recipient' => $_SESSION['shopping_cart']['step1']['EMAIL'], 862 'toName' => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'] . ' ' . $_SESSION['shopping_cart']['step1']['INV_NAME'], 863 'subject' => str_replace('{ORDER}', $order_num, $_tmpl['config']['mail_customer_subject']), 864 'text' => $mail_customer, 865 'from' => $email_from, 866 'sender' => $email_from 867 ); 868 869 $order_data_mail_customer = sendEmail($order_mail_customer); 870 871 // send mail to shop 872 $send_order_to = convertStringToArray( _getConfig( 'shop_pref_email_to', '_shopPref' ), ';' ); 873 if(empty($send_order_to[0]) || !is_valid_email($send_order_to[0])) { 874 $email_to = $phpwcms['SMTP_FROM_EMAIL']; 875 } else { 876 $email_to = $send_order_to[0]; 877 unset($send_order_to[0]); 878 } 879 880 $order_mail_self = array( 881 'from' => $_SESSION['shopping_cart']['step1']['EMAIL'], 882 'fromName' => $_SESSION['shopping_cart']['step1']['INV_FIRSTNAME'] . ' ' . $_SESSION['shopping_cart']['step1']['INV_NAME'], 883 'subject' => str_replace('{ORDER}', $order_num, $_tmpl['config']['mail_neworder_subject']), 884 'text' => $mail_neworder, 885 'recipient' => $email_to, 886 'sender' => $_SESSION['shopping_cart']['step1']['EMAIL'] 887 ); 888 889 $order_data_mail_self = sendEmail($order_mail_self); 890 891 // are there additional recipients for orders? 892 if(count($send_order_to)) { 893 foreach($send_order_to as $value) { 894 $order_mail_self['recipient'] = $value; 895 @sendEmail($order_mail_self); 896 } 897 } 898 899 900 // success 901 if(!empty($order_data['INSERT_ID']) || !empty($order_data_mail_customer[0])) { 902 903 $order_process = $_tmpl['order_success']; 904 905 foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) { 906 $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row)); 907 } 908 unset($_SESSION['shopping_cart']); 909 910 // NO success 911 } else { 912 913 $order_process = $_tmpl['order_failed']; 914 915 $order_process = str_replace('{SUBJECT}', rawurlencode($_tmpl['config']['mail_neworder_subject']), $order_process); 916 $order_process = str_replace('{MSG}', rawurlencode('---- FALLBACK MESSAGE ---' . LF . LF . $mail_customer), $order_process); 917 918 foreach($_SESSION['shopping_cart']['step1'] as $item_key => $row) { 919 $order_process = render_cnt_template($order_process, $item_key, html_specialchars($row)); 920 } 921 922 } 923 924 $order_process = str_replace('{ORDER}', $order_num, $order_process); 925 926 927 } else { 928 929 // show cart 930 931 $cart_mode = 'cart'; 932 include($phpwcms['modules']['shop']['path'].'inc/cart.items.inc.php'); 933 934 $order_process = $_tmpl['cart_header']; 935 $order_process .= implode($_tmpl['cart_space'], $cart_items); 936 $order_process .= $_tmpl['cart_footer']; 937 938 include($phpwcms['modules']['shop']['path'].'inc/cart.parse.inc.php'); 939 940 // Update Cart Button 941 $_cart_button = preg_match("/\[UPDATE\](.*?)\[\/UPDATE\]/is", $order_process, $g) ? $g[1] : ''; 942 if(strpos($_cart_button, 'input ') === false) { 943 $_cart_button = '<input type="submit" name="shop_cart_update" value="' . html_specialchars($_cart_button) . '" class="cart_update_button" />'; 944 } 945 $order_process = preg_replace('/\[UPDATE\](.*?)\[\/UPDATE\]/is', $_cart_button , $order_process); 946 947 // Checkout Button 948 $_cart_button = preg_match("/\[CHECKOUT\](.*?)\[\/CHECKOUT\]/is", $order_process, $g) ? $g[1] : ''; 949 if(strpos($_cart_button, 'input ') === false) { 950 $_cart_button = '<input type="submit" name="shop_cart_checkout" value="' . html_specialchars($_cart_button) . '" class="cart_checkout_button" />'; 951 } 952 $order_process = preg_replace('/\[CHECKOUT\](.*?)\[\/CHECKOUT\]/is', $_cart_button , $order_process); 953 954 // Is Shipping? 955 //$order_process = preg_replace('/\[SHIPPING\](.*?)\[\/SHIPPING\]/is', '' , $order_process); 956 $order_process = render_cnt_template($order_process, 'SHIPPING', $subtotal['float_shipping_net'] > 0 ? 1 : ''); 957 958 $order_process = '<form action="' .$_tmpl['config']['cart_url']. '" method="post">' . LF . trim($order_process) . LF . '</form>'; 959 960 } 961 962 $order_process = str_replace('{SHOP_LINK}', $_tmpl['config']['shop_url'], $order_process); 963 964 $content['all'] = str_replace('{SHOP_ORDER_PROCESS}', $order_process, $content['all']); 965 } 966 967 // small cart 968 if($_shop_load_cart_small) { 969 970 $_cart_count = 0; 971 972 if(isset($_SESSION['shopping_cart']['products']) && is_array($_SESSION['shopping_cart']['products']) && count($_SESSION['shopping_cart']['products'])) { 973 foreach($_SESSION['shopping_cart']['products'] as $cartval) { 974 $_cart_count += $cartval; 975 } 976 } 977 978 if(!$_cart_count) { 979 $_cart_count = ''; 980 } 981 982 if(strpos($_tmpl['cart_small'], '{CART_LINK}')) { 983 984 $shop_cat_selected = isset($GLOBALS['_getVar']['shop_cat']) ? $GLOBALS['_getVar']['shop_cat'] : 0; 985 $shop_detail_id = isset($GLOBALS['_getVar']['shop_detail']) ? intval($GLOBALS['_getVar']['shop_detail']) : 0; 986 unset($GLOBALS['_getVar']['shop_cat'], $GLOBALS['_getVar']['shop_detail']); 987 $_tmpl['cart_small'] = str_replace('{CART_LINK}', $_tmpl['config']['cart_url'], $_tmpl['cart_small']); 988 if($shop_cat_selected) $GLOBALS['_getVar']['shop_cat'] = $shop_cat_selected; 989 if($shop_detail_id) $GLOBALS['_getVar']['shop_detail'] = $shop_detail_id; 990 991 } 992 993 $_tmpl['cart_small'] = render_cnt_template($_tmpl['cart_small'], 'COUNT', $_cart_count); 994 $content['all'] = str_replace('{CART_SMALL}', $_tmpl['cart_small'], $content['all']); 995 } 996 997 998 999 function get_cart_data() { 1000 1001 // retrieve all cart data 1002 if(empty($_SESSION['shopping_cart']['products']) || ! is_array($_SESSION['shopping_cart']['products']) || ! count($_SESSION['shopping_cart']['products']) ) 1003 { 1004 return array(); 1005 } 1006 1007 $in = array(); 1008 foreach($_SESSION['shopping_cart']['products'] as $key => $value) { 1009 $key = intval($key); 1010 $in[$key] = $key; 1011 } 1012 1013 $sql = 'SELECT * FROM '.DB_PREPEND.'phpwcms_shop_products WHERE shopprod_status=1 AND '; 1014 $sql .= 'shopprod_id IN (' . implode(',', $in) . ')'; 1015 $data = _dbQuery($sql); 1016 1017 if(isset($data[0])) { 1018 1019 foreach($data as $key => $value) { 1020 1021 $data[$key]['shopprod_quantity'] = $_SESSION['shopping_cart']['products'][ $value['shopprod_id'] ]; 1022 1023 } 1024 1025 } 1026 1027 return $data; 1028 } 1029 1030 1031 1032 function shop_image_tag($img) { 1033 1034 //['config'][], $_tmpl['config'][''] 1035 $config =& $GLOBALS['_tmpl']['config']; 1036 1037 // set image values 1038 $width = $config['image_'.$config['mode'].'_width']; 1039 $height = $config['image_'.$config['mode'].'_height']; 1040 $crop = $config['image_'.$config['mode'].'_crop']; 1041 1042 $thumb_image = get_cached_image( 1043 array( "target_ext" => $img['f_ext'], 1044 "image_name" => $img['f_hash'] . '.' . $img['f_ext'], 1045 "max_width" => $width, 1046 "max_height" => $height, 1047 "thumb_name" => md5($img['f_hash'].$width.$height.$GLOBALS['phpwcms']["sharpen_level"].$crop), 1048 'crop_image' => $crop 1049 ) 1050 ); 1051 1052 if($thumb_image) { 1053 1054 // now try to build caption and if neccessary add alt to image or set external link for image 1055 $caption = getImageCaption($img['caption']); 1056 // set caption and ALT Image Text for imagelist 1057 $capt_cur = html_specialchars($caption[0]); 1058 $caption[3] = empty($caption[3]) ? '' : ' title="'.html_specialchars($caption[3]).'"'; //title 1059 $caption[1] = html_specialchars(empty($caption[1]) ? $img['f_name'] : $caption[1]); 1060 1061 $list_img_temp = '<img src="'.PHPWCMS_IMAGES.$thumb_image[0].'" '; 1062 $list_img_temp .= $thumb_image[3].' alt="'.$caption[1].'"'.$caption[3].' border="0" />'; 1063 1064 // use lightbox effect 1065 if($config['image_'.$config['mode'].'_lightbox']) { 1066 1067 $a = '<a href="img/cmsimage.php/'; 1068 $a .= $config['image_zoom_width'] . 'x' . $config['image_zoom_height'] . '/'; 1069 $a .= $img['f_hash'] . '.' . $img['f_ext'] . '" '; 1070 $a .= 'target="_blank" rel="lightbox'.$config['lightbox_id'].'"' . $caption[3] .'>'; 1071 1072 $list_img_temp = $a . $list_img_temp . '</a>'; 1073 } 1074 1075 return $list_img_temp; 1076 1077 } 1078 1079 return ''; 1080 } 1081 1082 function get_shop_category_name($id) { 1083 if(empty($id)) return ''; 1084 $sql = 'SELECT cat_name FROM '.DB_PREPEND.'phpwcms_categories WHERE '; 1085 $sql .= "cat_type='module_shop' AND cat_status=1 AND cat_id=" . intval($id) . ' LIMIT 1'; 1086 $data = _dbQuery($sql); 1087 if(is_array($data)) { 1088 foreach($data as $row) { 1089 return $row['cat_name']; 1090 } 1091 } 1092 return ''; 1093 } 1094 1095 function get_payment_options() { 1096 1097 $payment_prefs = _getConfig( 'shop_pref_payment', '_shopPref' ); 1098 $supported = array('prepay' => 0, 'pod' => 0, 'onbill' => 0); 1099 $available = array(); 1100 foreach($supported as $key => $value) { 1101 if($payment_prefs[$key]) $available[$key] = $payment_prefs[$key]; 1102 } 1103 return $available; 1104 } 1105 1106 1107 function get_category_products($selected_product_cat, $shop_detail_id, $shop_cat_selected, $shop_subcat_selected, $shop_cat_link) { 1108 1109 $shop_cat_prods = ''; 1110 1111 $sql = "SELECT * FROM ".DB_PREPEND.'phpwcms_shop_products WHERE '; 1112 $sql .= "shopprod_status=1"; 1113 $sql .= ' AND ('; 1114 $sql .= "shopprod_category = '" . $selected_product_cat . "' OR "; 1115 $sql .= "shopprod_category LIKE '%," . $selected_product_cat . ",%' OR "; 1116 $sql .= "shopprod_category LIKE '" . $selected_product_cat . ",%' OR "; 1117 $sql .= "shopprod_category LIKE '%," . $selected_product_cat . "'"; 1118 $sql .= ')'; 1119 $pdata = _dbQuery($sql); 1120 1121 if(is_array($pdata) && count($pdata)) { 1122 1123 $z = 0; 1124 $shop_cat_prods = array(); 1125 foreach($pdata as $prow) { 1126 1127 $shop_cat_prods[$z] = '<li'; 1128 if($prow['shopprod_id'] == $shop_detail_id) { 1129 $shop_cat_prods[$z] .= ' class="active"'; 1130 } 1131 $shop_cat_prods[$z] .= '>'; 1132 $shop_cat_prods[$z] .= '<a href="' . $shop_cat_link . '&shop_cat=' . $shop_cat_selected; 1133 if($shop_subcat_selected) { 1134 $shop_cat_prods[$z] .= '_' . $shop_subcat_selected; 1135 } 1136 $shop_cat_prods[$z] .= '&shop_detail=' .$prow['shopprod_id']. '">'; 1137 $shop_cat_prods[$z] .= html_specialchars($prow['shopprod_name1']); 1138 $shop_cat_prods[$z] .= '</a>'; 1139 $shop_cat_prods[$z] .= '</li>'; 1140 $z++; 1141 } 1142 1143 if(count($shop_cat_prods)) { 1144 $shop_cat_prods = LF . ' <ul class="products">' . LF.' ' . implode(LF.' ', $shop_cat_prods) . LF .' </ul>' . LF.' '; 1145 } 1146 1147 } 1148 1149 return $shop_cat_prods; 1150 1151 } 1152 1153 1154 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 16 22:51:00 2010 | Cross-referenced by PHPXref 0.7 |