assign_vars(array(
'SKEYWORD_VALUE' => stripslashes($filter['keyword']),
'SCATID_VALUE' => $filter['cat_id'],
));
}
function list_cats(){
global $db, $template, $template_body_page, $base_url, $image_cat_path, $cid;
$sql = "SELECT * FROM shop_pro_cat ORDER BY cat_order ASC";
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
}
$cat_count = $db->sql_numrows($result);
$cat_data = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$cols = 2;
$i = 0;
while ($i < $cat_count){
$template->assign_block_vars("catrow", array());
for ( $j=0; $j<$cols; $j++ ){
if ( $i < $cat_count ){
$template->assign_block_vars("catrow.catcol", array(
'CAT_TITLE' => $cat_data[$i]['cat_title'],
'PIC_THUMB' => !empty($cat_data[$i]['pic_thumb']) ? '' : '',
'U_VIEW' => $base_url .'?cid='. $cat_data[$i]['cat_id'],
'TDMIDDLE' => ($j < $cols - 1) ? '
| ' : '',
));
}
else{
$template->assign_block_vars("catrow.catcol", array(
'TDMIDDLE' => ($j < $cols - 1) ? ' | ' : '',
));
}
$i++;
}
}
$template->assign_vars(array(
'TDWIDTH' => round(100/$cols - 2) .'%',
'TDCOLS' => 2*$cols - 1,
));
$template->set_filenames(array(
'body' => $template_body_page
));
$template->pparse('body');
}
function list_products(){
global $db, $template, $template_list_page, $base_url, $base_cart_url, $image_path, $start, $site_option, $filter;
$start = isset($_GET['start']) ? intval($_GET['start']) : 0;
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
$itemperpage = 5;
$currency = $site_option['product_currency'];
$where_sql = " WHERE enabled=1";
//Filter --------------------------
if ( !empty($filter['keyword']) ){
$keyword = str_replace("*", "%", $filter['keyword']);
$where_sql .= " AND (code LIKE '%". $keyword ."%' OR title LIKE '%". $keyword ."%' OR preview LIKE '%". $keyword ."%' OR detail LIKE '%". $keyword ."%')";
}
if ( $filter['cat_id'] ){
$where_sql .= " AND cat_id=". $filter['cat_id'];
}
//---------------------------------
if ( $cid ){
//Get cat info -----------------
$sql = 'SELECT * FROM shop_pro_cat WHERE cat_id='. $cid;
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
}
if ( $db->sql_numrows($result) ){
$cat_info = $db->sql_fetchrow($result);
$template->assign_vars(array(
'CAT_TITLE' => '\ '. $cat_info['cat_title'] .''
));
$where_sql .= " AND cat_id=$cid";
}
//------------------------------
}
//Get products
$sql = "SELECT * FROM shop_pro $where_sql ORDER BY product_order DESC LIMIT $start, $itemperpage";
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
$product_count = $db->sql_numrows($result);
$product_data = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
//Generate Pagination
$sql = 'SELECT count(product_id) AS total FROM shop_pro '. $where_sql;
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
}
else{
$total = $db->sql_fetchrow($result);
$url_append = empty($filter['url_append']) ? "cid=$cid" : $filter['url_append'];
$pagination = g3_pagination($base_url . "?". $url_append, $total['total'], $itemperpage, $start, 'start', 'Page: ////');
}
//list products in one column --------
for ($i=0; $i<$product_count; $i++){
$template->assign_block_vars("productrow", array(
'PIC_THUMB' => !empty($product_data[$i]['pic_thumb']) ? '' : '',
'PIC_THUMB2' => !empty($product_data[$i]['pic_thumb2']) ? '' : '',
'CODE' => !empty($product_data[$i]['code']) ? '- '. $product_data[$i]['code'] : '',
'PRICE' => $product_data[$i]['price'] ? 'Price: '.number_format($product_data[$i]['price'],DECIMALS,DEC_POINT,THOUSANDS_SEP).' '.$currency : '',
'TITLE' => $product_data[$i]['title'],
'PREVIEW' => restore_htmltags(nl2br($product_data[$i]['preview'])),
'U_VIEW' => $base_url .'?id='. $product_data[$i]['product_id'],
'U_ADD_CART' => $base_cart_url .'?mode=add&id='. $product_data[$i]['product_id'],
));
}
//------------------------------------
$template->assign_vars(array(
'NAVIGATOR' => $pagination,
));
$template->set_filenames(array(
'body' => $template_list_page
));
$template->pparse('body');
}
function view_product(){
global $db, $template, $base_url, $base_cart_url, $template_view_page, $image_path, $id, $site_option;
$currency = $site_option['product_currency'];
//Get products info
$sql = 'SELECT * FROM shop_pro WHERE enabled=1 AND product_id='. $id;
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
if ( !$db->sql_numrows($result) ){
list_products();
return false;
}
$product_info = $db->sql_fetchrow($result);
//Update hits
$sql = "UPDATE shop_pro SET hits=hits+1 WHERE product_id=$id";
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
//get cat title ---------------------
$sql = 'SELECT cat_id, cat_parent_id, cat_title FROM shop_pro_cat WHERE cat_id='. $product_info['cat_id'];
if ( !$result = $db->sql_query($sql) ) {
message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
}
if ( !$db->sql_numrows($result) ){
list_products();
return false;
}
$cat_info = $db->sql_fetchrow($result);
$template->assign_vars(array(
'CAT_TITLE' => '\ '. $cat_info['cat_title'] .'',
'PIC_FULL' => !empty($product_info['pic_full']) ? '' : '',
'PIC_FULL2' => !empty($product_info['pic_full2']) ? '' : '',
'TITLE' => $product_info['title'],
'DETAIL' => restore_htmltags(nl2br($product_info['detail'])),
'CODE' => !empty($product_info['code']) ? '
Code: '. $product_info['code'] : '',
'PRICE' => $product_info['price'] ? 'Price: '. number_format($product_info['price'],DECIMALS,DEC_POINT,THOUSANDS_SEP).' '.$currency : '',
'U_ADD_CART' => $base_cart_url .'?mode=add&id='. $product_info['product_id'],
));
$template->set_filenames(array(
'body' => $template_view_page
));
$template->pparse('body');
}
?>