Ejemplo n.º 1
0
 /**
  * Creates tags cloud
  * $cloud_data - array like (key => array(text, num))  OR   $cloud_data - array like (text => num)
  */
 function create($cloud_data = [], $params = [])
 {
     if (empty($cloud_data)) {
         return '';
     }
     if (empty($params['object'])) {
         $params['object'] = 'tags';
     }
     if (empty($params['action'])) {
         $params['action'] = 'search';
     }
     if ($this->CLOUD_ORDER == 'text') {
         ksort($cloud_data);
     } elseif ($this->CLOUD_ORDER == 'num') {
         arsort($cloud_data);
     }
     // Search for the max and min values of 'num' in array
     $max_val = max($cloud_data);
     $min_val = min($cloud_data);
     foreach ((array) $cloud_data as $_text => $_num) {
         // Creating cloud
         if ($max_val !== $min_val) {
             $_cloud_fsize = $this->CLOUD_MIN_FSIZE + ($this->CLOUD_MAX_FSIZE - $this->CLOUD_MIN_FSIZE) * ($_num - $min_val) / ($max_val - $min_val);
             $_cloud_fsize = round($_cloud_fsize, 2);
         } else {
             $_cloud_fsize = 1;
         }
         $replace2 = ['num' => $_num, 'tag_text' => $_text, 'tag_search_url' => './?object=' . $params['object'] . '&action=' . $params['action'] . '&id=' . $params['id_prefix'] . ($params['amp_encode'] ? str_replace(urlencode('&'), urlencode(urlencode('&')), urlencode($_text)) : urlencode($_text)), 'cloud_fsize' => $_cloud_fsize];
         $items .= tpl()->parse('tags/cloud_item', $replace2);
     }
     return $items;
 }
Ejemplo n.º 2
0
function __exception_handler($exception, $message = NULL, $file = NULL, $line = NULL)
{
    $PHP_ERROR = func_num_args() === 5;
    if ($PHP_ERROR and (error_reporting() & $exception) === 0) {
        return;
    }
    if ($PHP_ERROR) {
        $code = $exception;
        $type = 'PHP Error';
        $message = $type . '  ' . $message . '  ' . $file . '  ' . $line;
    } else {
        $code = $exception->getCode();
        $type = get_class($exception);
        $message = $exception->getMessage() . "\n" . $exception->getTraceAsString();
        $file = $exception->getFile();
        $line = $exception->getLine();
    }
    Log::error($type, $code, $message, $file, $line);
    if (!DEBUG) {
        $_file = tpl("error");
        if (file_exists($_file)) {
            ob_end_clean();
            include $_file;
        } else {
            redirect('/', $message);
        }
    } else {
        $str = '<style>body {font-size:12px;}</style>';
        $str .= '<h1>操作失败!</h1><br />';
        $str .= '<strong>错误信息:<strong><font color="red">' . $message . '</font><br />';
        echo $str;
    }
    exit($code);
}
Ejemplo n.º 3
0
 /**
  */
 function show()
 {
     asset('jquery-jstree');
     $slick_view = isset($_GET['CKEditorFuncNum']);
     $body = tpl()->parse(__CLASS__ . '/main', ['ck_funcnum' => (int) $_GET['CKEditorFuncNum']]);
     return $slick_view ? print common()->show_empty_page($body) : $body;
 }
Ejemplo n.º 4
0
 /**
  * basket_main
  */
 function basket_main()
 {
     $products_ids = [];
     $basket_contents = module('shop')->_basket_api()->get_all();
     foreach ((array) $basket_contents as $_item_id => $_info) {
         if ($_info["product_id"]) {
             $products_ids[$_info["product_id"]] = $_info["product_id"];
         }
     }
     if (!empty($products_ids)) {
         $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE active='1' AND id IN(" . implode(",", $products_ids) . ")");
         $products_atts = module('shop')->_products_get_attributes($products_ids);
         $group_prices = module('shop')->_get_group_prices($products_ids);
     }
     $total_price = 0;
     foreach ((array) $products_infos as $_info) {
         $_product_id = $_info["id"];
         $_info["_group_price"] = $group_prices[$_product_id][module('shop')->USER_GROUP];
         $quantity2 = $basket_contents[$_info["id"]]["quantity"];
         $price = module('shop')->_product_get_price($_info);
         $dynamic_atts = [];
         foreach ((array) $products_atts[$_product_id] as $_attr_id => $_attr_info) {
             if ($basket_contents[$_product_id]["atts"][$_attr_info["name"]] == $_attr_info["value"]) {
                 $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"];
                 $price += $_attr_info["price"];
             }
         }
         $total_price += $price * $quantity2;
         $quantity += intval($quantity2);
     }
     $replace = ["total_price" => module('shop')->_format_price($total_price), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => $quantity, "order_link" => "./?object=shop&action=basket", "basket_link" => "./?object=shop&action=basket"];
     return tpl()->parse("shop/basket_main", $replace);
 }
Ejemplo n.º 5
0
 public function _tpl($stpl_text = '', $replace = [], $name = '', $params = [])
 {
     if (!$name) {
         $name = 'auto__' . get_called_class() . '__' . substr(md5($stpl_text), 0, 16);
     }
     return tpl()->parse_string($stpl_text, $replace, $name, $params);
 }
Ejemplo n.º 6
0
 function add_receivers()
 {
     $A = $this->_get_notification($_GET['id']);
     $method_name = "_add_receivers_" . $A['receiver_type'];
     if (!method_exists($this, $method_name) || !method_exists($this, $method_name . "_process")) {
         js_redirect("./?object=" . $_GET['object']);
     }
     if (main()->is_post()) {
         $method_name_process = $method_name . "_process";
         $sql = $this->{$method_name_process}($_GET['id']);
         $receivers = db()->get_2d($sql);
         $sql_arr = [];
         foreach ((array) $receivers as $v) {
             if ($_POST['is_all'] == 1 || $_POST['id'][$v] == 1) {
                 $sql_arr[] = "({$_GET['id']}, '{$A['receiver_type']}', {$v}, 0)";
             }
         }
         if (count($sql_arr) > 0) {
             db()->query("REPLACE INTO `" . db('notifications_receivers') . "` (`notification_id`,`receiver_type`,`receiver_id`,`is_read`) VALUES " . implode(",", $sql_arr));
         }
         js_redirect("./?object=" . $_GET['object'] . "&action=view&id=" . $_GET['id']);
     }
     $replace = ['table' => $this->{$method_name}($_GET['id']), 'show_add_selected' => $A['receiver_type'] != 'user_id_tmp' ? 1 : 0];
     return tpl()->parse($_GET['object'] . "/" . __FUNCTION__, $replace);
 }
Ejemplo n.º 7
0
 public function test_avail_arrays()
 {
     // TODO: deep debug why
     // For some reason it fails under current jenkins
     if (getenv('CI') === 'jenkins') {
         return false;
     }
     $old = tpl()->_avail_arrays;
     $_GET['mytestvar'] = 'mytestvalue';
     tpl()->_avail_arrays = ['get' => '_GET'];
     $this->assertEquals('', self::_tpl('{get.not_exists}'));
     $this->assertEquals('_mytestvalue_', self::_tpl('_{get.mytestvar}_'));
     $this->assertEquals('good', self::_tpl('{if(get.mytestvar eq mytestvalue)}good{else}bad{/if}'));
     $this->assertEquals('good', self::_tpl('{if(get.mytestvar ne "")}good{else}bad{/if}'));
     $this->assertEquals('good', self::_tpl('{if(get.mytestvar ne something_else)}good{else}bad{/if}'));
     $data = ['k1' => 'v1', 'k2' => 'v2', 'k3' => 'v3'];
     $_GET['myarray'] = $data;
     $this->assertEquals(' k1=v1  k2=v2  k3=v3 ', self::_tpl('{foreach(data)} {_key}={_val} {/foreach}', ['data' => $data]));
     $this->assertEquals(' k1=v1  k2=v2  k3=v3 ', self::_tpl('{foreach(data.myarray)} {_key}={_val} {/foreach}', ['data' => ['myarray' => $data]]));
     $this->assertEquals('', self::_tpl('{foreach(data.not_exists)} {_key}={_val} {/foreach}', ['data' => ['myarray' => $data]]));
     $this->assertEquals('k1=v1', self::_tpl('{foreach(data.myarray)}{if(_key eq k1)}{_key}={_val}{/if}{/foreach}', ['data' => ['myarray' => $data]]));
     $this->assertEquals('k2=v2', self::_tpl('{foreach(data.myarray)}{if(_key eq k2)}{_key}={_val}{/if}{/foreach}', ['data' => ['myarray' => $data]]));
     $this->assertEquals('k3=v3', self::_tpl('{foreach(data.myarray)}{if(_key eq k3)}{_key}={_val}{/if}{/foreach}', ['data' => ['myarray' => $data]]));
     $this->assertEquals(' k1=v1  k2=v2  k3=v3 ', self::_tpl('{foreach(get.myarray)} {_key}={_val} {/foreach}'));
     $this->assertEquals('', self::_tpl('{foreach(get.not_exists)} {_key}={_val} {/foreach}'));
     $this->assertEquals('k1=v1', self::_tpl('{foreach(get.myarray)}{if(_key eq k1)}{_key}={_val}{/if}{/foreach}'));
     $this->assertEquals('k2=v2', self::_tpl('{foreach(get.myarray)}{if(_key eq k2)}{_key}={_val}{/if}{/foreach}'));
     $this->assertEquals('k3=v3', self::_tpl('{foreach(get.myarray)}{if(_key eq k3)}{_key}={_val}{/if}{/foreach}'));
     tpl()->_avail_arrays = $old;
 }
Ejemplo n.º 8
0
 function menu()
 {
     global $db;
     //判断是否登陆
     !isset($_SESSION['user']) && exit('Please login!');
     tpl('menu');
 }
 function products_similar_by_basket($id)
 {
     $sql_order_id = "SELECT order_id FROM " . db('shop_order_items') . " WHERE product_id =  " . $id;
     $orders = db()->query($sql_order_id);
     while ($A = db()->fetch_assoc($orders)) {
         $order_id .= $A["order_id"] . ",";
     }
     $order_id = rtrim($order_id, ",");
     if (!empty($order_id)) {
         $sql_product_id = "SELECT product_id FROM " . db('shop_order_items') . " WHERE  order_id IN (  " . $order_id . ") AND product_id != " . $id;
         $products = db()->query($sql_product_id);
         while ($A = db()->fetch_assoc($products)) {
             $product_id .= $A["product_id"] . ",";
         }
         $product_id = rtrim($product_id, ",");
     }
     if (!empty($product_id)) {
         $sql = "SELECT * FROM " . db('shop_products') . " WHERE  id in ( " . $product_id . ")";
         $product = db()->query_fetch_all($sql);
         foreach ((array) $product as $k => $product_info) {
             $thumb_path = $product_info["url"] . "_" . $product_info["id"] . "_1" . module("shop")->THUMB_SUFFIX . ".jpg";
             $URL_PRODUCT_ID = module("shop")->_product_id_url($product_info);
             $items[$product_info["id"]] = ["name" => _prepare_html($product_info["name"]), "price" => module("shop")->_format_price(module("shop")->_product_get_price($product_info)), "currency" => _prepare_html(module("shop")->CURRENCY), "image" => file_exists(module("shop")->products_img_dir . $thumb_path) ? module("shop")->products_img_webdir . $thumb_path : "", "link" => $product_info["external_url"] ? $product_info["external_url"] : process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "special" => ""];
         }
     }
     $replace = ["items" => $items, "title" => "Those who purchased this product also buy"];
     return tpl()->parse("shop/products_similar_by_price", $replace);
 }
Ejemplo n.º 10
0
 /**
  * Order step
  */
 function _order_step_start($FORCE_DISPLAY_FORM = false)
 {
     module('shop')->_basket_save();
     $basket_contents = module('shop')->_basket_api()->get_all();
     $products_ids = [];
     foreach ((array) $basket_contents as $_item_id => $_info) {
         if ($_info["product_id"]) {
             $products_ids[$_info["product_id"]] = $_info["product_id"];
         }
     }
     if (!empty($products_ids)) {
         $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'");
         $products_atts = module('shop')->_products_get_attributes($products_ids);
         $group_prices = module('shop')->_get_group_prices($products_ids);
     }
     $total_price = 0;
     foreach ((array) $products_infos as $_info) {
         $_product_id = $_info["id"];
         $_info["_group_price"] = $group_prices[$_product_id][module('shop')->USER_GROUP];
         $quantity = $basket_contents[$_info["id"]]["quantity"];
         $price = module('shop')->_product_get_price($_info);
         $dynamic_atts = [];
         foreach ((array) $products_atts[$_product_id] as $_attr_id => $_attr_info) {
             if ($basket_contents[$_product_id]["atts"][$_attr_info["name"]] == $_attr_info["value"]) {
                 $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"];
                 $price += $_attr_info["price"];
             }
         }
         $URL_PRODUCT_ID = module('shop')->_product_id_url($_info);
         $products[$_info["id"]] = ["name" => _prepare_html($_info["name"]), "price" => module('shop')->_format_price($price), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($quantity), "details_link" => process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : "", "cat_name" => _prepare_html(module('shop')->_shop_cats[$_info["cat_id"]]), "cat_url" => process_url("./?object=shop&action=products_show&id=" . module('shop')->_shop_cats_all[$_info["cat_id"]]['url'])];
         $total_price += $price * $quantity;
     }
     $replace = ["products" => $products, "total_price" => module('shop')->_format_price($total_price), "currency" => _prepare_html(module('shop')->CURRENCY), "back_link" => "./?object=shop&action=basket", "next_link" => "./?object=shop&action=order&id=delivery", "cats_block" => module('shop')->_categories_show()];
     return tpl()->parse("shop/order_start", $replace);
 }
Ejemplo n.º 11
0
 public function events()
 {
     if (!env('student')) {
         redirect('m=login');
     }
     $updisciplineId = val($_REQUEST, 'updisciplineId');
     $learningMode = val($_REQUEST, 'learningMode');
     if (empty($updisciplineId) || empty($learningMode)) {
         throw new Exception('Missed required param', 404);
     }
     $updiscipline = entry_sql('SELECT * FROM updiscipline WHERE updisciplineId=:updisciplineId', array(':updisciplineId' => $updisciplineId));
     if (empty($updiscipline)) {
         throw new Exception('Updiscipline not found', 404);
     }
     $groupPeriod = entry_sql('SELECT gp.* FROM group_history gh INNER JOIN group_period gp USING(groupPeriodId) WHERE gh.studentId=:studentId AND gp.sersemester=:sersemester', array('studentId' => studentId(), 'sersemester' => $updiscipline['sersemester']));
     if (empty($groupPeriod)) {
         throw new Exception('Cannot detect groupPeriod', 404);
     }
     $events = entries_sql('SELECT * FROM event WHERE updisciplineId=:updisciplineId AND groupPeriodId=:groupPeriodId AND learningMode=:learningMode', array('groupPeriodId' => $groupPeriod['groupPeriodId'], 'updisciplineId' => $updiscipline['updisciplineId'], 'learningMode' => $learningMode));
     array_walk($events, function (&$event, $k, $studentId) {
         $event['c'] = material::i($event['instanceType'])->c();
         $event['grade'] = material::i($event['instanceType'])->get_grade($event['instanceId'], $studentId);
     }, studentId());
     env('breadcrumbs', array(array(lng('up:disciplines'), '/?c=up'), array($updiscipline['disciplineName'], '/?c=up&amp;m=events&amp;updisciplineId=' . $updisciplineId . '&amp;learningMode=' . $learningMode), lng('up:events')));
     tpl('up/events', array('updiscipline' => $updiscipline, 'events' => $events, 'result' => entry_sql('SELECT * FROM result WHERE studentId=:studentId AND updisciplineId=:updisciplineId AND learningMode=:learningMode', array('studentId' => studentId(), 'updisciplineId' => $updiscipline['updisciplineId'], 'learningMode' => $learningMode))));
 }
Ejemplo n.º 12
0
 function pics_browser()
 {
     if (isset($_GET['active']) && $_GET['active'] == 1) {
         $active = ' AND p.active = \'1\' ';
     } elseif (isset($_GET['active']) && $_GET['active'] == 0) {
         $active = ' AND p.active = \'\' ';
     } else {
         $active = '';
     }
     if (main()->is_post()) {
         foreach ($_POST['delete'] as $k => $v) {
             list($id, $product_id) = explode("_", $k);
             module('manage_shop')->_product_image_delete($id, $product_id);
         }
     }
     $cats_list = _class('_shop_categories', 'modules/shop/')->recursive_get_child_ids(62521);
     $sql = "SELECT `i`.`product_id`,`i`.`id` FROM `" . db('shop_products') . "` AS `p`, `" . db('shop_product_images') . "` AS `i` WHERE `p`.`id`=`i`.`product_id` AND `p`.`cat_id` IN ('" . implode("','", $cats_list) . "')" . $active;
     list($add_sql, $pages, $total_records, $page_current, $pages_total, $pages_limited) = common()->divide_pages($sql);
     $R = db()->query($sql . $add_sql);
     $items = [];
     while ($A = db()->fetch_assoc($R)) {
         $_cls_products = _class('_shop_products', 'modules/shop/');
         $image = $_cls_products->_product_image($A['product_id'], true);
         $items[] = ['id' => $A['product_id'], 'image_id' => $A['id'], 'image' => $image['big']];
     }
     $replace = ['items' => $items, 'total' => $total_records, 'pages' => $pages];
     $tpl_name = 'manage_shop/pics_browser';
     return tpl()->parse($tpl_name, $replace);
 }
Ejemplo n.º 13
0
/**
 * Include the page tree navigation
 * @param  int/WP_Post $page Post ID or object
 */
function tpl_nav_page_tree($page)
{
    $tree = get_page_tree($page);
    if (!empty($tree)) {
        tpl('nav', 'page-tree', array('tree' => $tree));
    }
}
Ejemplo n.º 14
0
 function product_details()
 {
     if (!$_GET["id"]) {
         return is_redirect("./?object=shop");
     }
     // Get products from database
     if (is_numeric($_GET["id"])) {
         $add_sql = "id= '" . intval($_GET["id"]);
     } else {
         $add_sql = "url='" . _es($_GET['id']);
     }
     $sql = "SELECT * FROM " . db('shop_products') . " WHERE active='1' AND " . $add_sql . "'";
     $product_info = db()->query_fetch($sql);
     // Required for comments
     module("shop")->_comments_params["object_id"] = $product_info["id"];
     module("shop")->_comments_params["objects_ids"] = $product_info["id"];
     $N = module("shop")->_get_num_comments();
     $N = $N[$product_info["id"]];
     if ($N == "") {
         $N = 0;
     }
     $dirs = sprintf("%06s", $product_info["id"]);
     $dir2 = substr($dirs, -3, 3);
     $dir1 = substr($dirs, -6, 3);
     $mpath = $dir1 . "/" . $dir2 . "/";
     $group_prices = module("shop")->_get_group_prices($product_info["id"]);
     $product_info["_group_price"] = $group_prices[module("shop")->USER_GROUP];
     module("shop")->_product_info = $product_info;
     $atts = module("shop")->_products_get_attributes($product_info["id"]);
     $thumb_path = $product_info["url"] . "_" . $product_info["id"] . "_" . $product_info["image"] . module("shop")->THUMB_SUFFIX . ".jpg";
     $img_path = $product_info["url"] . "_" . $product_info["id"] . "_" . $product_info["image"] . module("shop")->FULL_IMG_SUFFIX . ".jpg";
     if ($product_info["image"] == 0) {
         $image = "";
     } else {
         $image_files = _class('dir')->scan_dir(module("shop")->products_img_dir . $mpath, true, "/" . $product_info["url"] . "_" . $product_info["id"] . ".+?_small\\.jpg" . "/");
         $reg = "/" . $product_info["url"] . "_" . $product_info["id"] . "_(?P<content>[\\d]+)_small\\.jpg/";
         foreach ((array) $image_files as $filepath) {
             preg_match($reg, $filepath, $rezult);
             $i = $rezult["content"];
             if ($i != $product_info["image"]) {
                 $thumb_temp = module("shop")->products_img_webdir . $mpath . $product_info["url"] . "_" . $product_info["id"] . "_" . $i . module("shop")->THUMB_SUFFIX . ".jpg";
                 $img_temp = module("shop")->products_img_webdir . $mpath . $product_info["url"] . "_" . $product_info["id"] . "_" . $i . module("shop")->FULL_IMG_SUFFIX . ".jpg";
                 $replace2 = ["thumb_path" => $thumb_temp, "img_path" => $img_temp, "name" => $product_info["url"]];
                 $image .= tpl()->parse("shop/image_items", $replace2);
             }
         }
     }
     $URL_PRODUCT_ID = module("shop")->_product_id_url($product_info);
     $sql_man = "SELECT * FROM " . db('shop_manufacturers') . " WHERE id = " . $product_info["manufacturer_id"];
     $manufacturer = db()->query_fetch($sql_man);
     if (module("shop")->SHOW_products_similar_by_price == true) {
         $products_similar_by_price = module("shop")->products_similar_by_price($product_info["price"], $product_info["id"]);
     }
     if (module("shop")->products_similar_by_basket == true) {
         $products_similar_by_basket = module("shop")->products_similar_by_basket($product_info["id"]);
     }
     $replace = ["name" => _prepare_html($product_info["name"]), "model" => _prepare_html($product_info["model"]), "desc" => $product_info["description"], "manufacturer" => _prepare_html(module("shop")->_manufacturer[$product_info["manufacturer_id"]]["name"]), "url_manufacturer" => process_url("./?object=shop&action=products_show&id=" . module("shop")->_manufacturer[$product_info["manufacturer_id"]]["url"]), "date" => _format_date($product_info["add_date"], "long"), "price" => module("shop")->_format_price(module("shop")->_product_get_price($product_info)), "currency" => _prepare_html(module("shop")->CURRENCY), "thumb_path" => file_exists(module("shop")->products_img_dir . $mpath . $img_path) ? module("shop")->products_img_webdir . $mpath . $img_path : "", "img_path" => file_exists(module("shop")->products_img_dir . $mpath . $img_path) ? module("shop")->products_img_webdir . $mpath . $img_path : "", "image" => $image, "basket_add_url" => $product_info["external_url"] ? $product_info["external_url"] : process_url("./?object=shop&action=basket_add&id=" . $URL_PRODUCT_ID), "external_url" => intval((bool) $product_info["external_url"]), "back_url" => process_url("./?object=shop"), "show_basket_url" => process_url("./?object=shop&action=basket"), "dynamic_atts" => module("shop")->_get_select_attributes($atts), "cats_block" => module("shop")->_categories_show(), "cat_name" => _prepare_html(module("shop")->_shop_cats[$product_info["cat_id"]]), "cat_url" => process_url("./?object=shop&action=product_details&id=" . module("shop")->_shop_cats_all[$product_info["cat_id"]]['url']), 'comments' => module("shop")->_view_comments(), "N" => $N, "products_similar_by_price" => $products_similar_by_price, "products_similar_by_basket" => $products_similar_by_basket, "product_related" => module("shop")->products_related($product_info["id"])];
     db()->query("UPDATE " . db('shop_products') . " SET viewed = viewed+1 , last_viewed_date = " . time() . "  WHERE " . $add_sql . "'");
     return tpl()->parse("shop/details", $replace);
 }
 function products_similar_by_price($price, $id)
 {
     $price_min = floor($price - $price * 10 / 100);
     $price_max = ceil($price + $price * 10 / 100);
     $sql1 = "SELECT category_id FROM " . db('shop_product_to_category') . " WHERE product_id =  " . $id . "";
     $cat_id = db()->query($sql1);
     while ($A = db()->fetch_assoc($cat_id)) {
         $cats_id .= $A["category_id"] . ",";
     }
     $cats_id = rtrim($cats_id, ",");
     $sql2 = "SELECT product_id FROM " . db('shop_product_to_category') . " WHERE category_id IN ( " . $cats_id . ")";
     $prod = db()->query($sql2);
     while ($A = db()->fetch_assoc($prod)) {
         $prods .= $A["product_id"] . ",";
     }
     $prods = rtrim($prods, ",");
     $sql = "SELECT * FROM " . db('shop_products') . " WHERE price > " . $price_min . " AND price < " . $price_max . " AND id != " . $id . " AND id IN(" . $prods . ")";
     $product = db()->query_fetch_all($sql);
     foreach ((array) $product as $k => $product_info) {
         $thumb_path = $product_info["url"] . "_" . $product_info["id"] . "_1" . module("shop")->THUMB_SUFFIX . ".jpg";
         $URL_PRODUCT_ID = module("shop")->_product_id_url($product_info);
         $items[$product_info["id"]] = ["name" => _prepare_html($product_info["name"]), "price" => module("shop")->_format_price(module("shop")->_product_get_price($product_info)), "currency" => _prepare_html(module("shop")->CURRENCY), "image" => file_exists(module("shop")->products_img_dir . $thumb_path) ? module("shop")->products_img_webdir . $thumb_path : "", "link" => $product_info["external_url"] ? $product_info["external_url"] : process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "special" => ""];
     }
     $replace = ["items" => $items, "title" => "Similar price"];
     return tpl()->parse("shop/products_similar_by_price", $replace);
 }
Ejemplo n.º 16
0
    /**
     */
    public function show()
    {
        css('
			#faq-search { padding-top: 20px; }
			#faq-items { padding-top: 20px; padding-bottom: 20px; }
			#faq-items li.li-header { list-style: none; display:none; }
			#faq-items li.li-level-0 { display: block; font-size: 15px; }
			#faq-items li.li-level-1 { padding-top: 10px; font-size: 13px; }
			span.highlight { background-color: #ff0; }
		');
        asset('jquery-highlight');
        jquery('
			var url_hash = window.location.hash.replace("/", "");
			if (url_hash) {
				$("li.li-level-0" + url_hash + " .li-level-1", "#faq-items").show();
			}
			$(".li-level-0", "#faq-items").click(function(){
				$(".li-level-1", this).toggle()
			})
			$("input#search", "#faq-search").on("change keyup", function(){
				var words = $(this).val();
				$("#faq-items").unhighlight();
				$("#faq-items").highlight(words);
				$(".li-level-1").hide().filter(":has(\'span.highlight\')").show();
			})
		');
        $items = [];
        foreach ((array) db()->from(self::table)->where('active', 1)->where('locale', conf('language'))->get_all() as $a) {
            $items[$a['id']] = ['parent_id' => $a['parent_id'], 'name' => _truncate(trim($a['title']), 60, true, '...'), 'link' => url('/@object/#/faq' . $a['id']), 'id' => 'faq' . $a['id']];
            if ($a['text']) {
                $items['1111' . $a['id']] = ['parent_id' => $a['id'], 'body' => trim($a['text'])];
            }
        }
        return tpl()->parse_string($this->_tpl, ['items' => html()->li_tree($items)]);
    }
Ejemplo n.º 17
0
 function orders()
 {
     if (!main()->USER_ID) {
         if (main()->is_post()) {
             module('shop')->order_validate_data();
             // Display next form if we have no errors
             if (!common()->_error_exists()) {
                 return module('shop')->order_view(true);
             }
         }
         $items[] = ["order_id" => $_POST["order_id"], "email" => $_POST["email"], "form_action" => "./?object=shop&action=orders", "back_link" => "./?object=shop"];
     } else {
         $sql = "SELECT * FROM " . db('shop_orders') . " WHERE user_id=" . intval(main()->USER_ID);
         //$filter_sql = $this->PARENT_OBJ->USE_FILTER ? $this->PARENT_OBJ->_create_filter_sql() : "";
         $sql .= strlen($filter_sql) ? " WHERE 1=1 " . $filter_sql : " ORDER BY date DESC ";
         list($add_sql, $pages, $total) = common()->divide_pages($sql);
         $orders_info = db()->query_fetch_all($sql . $add_sql);
         if (!empty($orders_info)) {
             foreach ((array) $orders_info as $v) {
                 $user_ids[] = $v["user_id"];
             }
             $user_infos = user($user_ids);
         }
         foreach ((array) $orders_info as $v) {
             if ($v["status"] == "pending" or $v["status"] == "pending payment") {
                 $del = "./?object=shop&action=order_delete&id=" . $v["id"];
             } else {
                 $del = "";
             }
             $items[] = ["order_id" => $v["id"], "date" => _format_date($v["date"], "long"), "sum" => module('shop')->_format_price($v["total_sum"]), "user_link" => _profile_link($v["user_id"]), "user_name" => _display_name($user_infos[$v["user_id"]]), "status" => $v["status"], "delete_url" => $del, "view_url" => "./?object=shop&action=order_view&id=" . $v["id"]];
         }
     }
     $replace = ["error_message" => _e(), "items" => (array) $items, "pages" => $pages, "total" => intval($total), "filter" => module('shop')->USE_FILTER ? module('shop')->_show_filter() : ""];
     return tpl()->parse("shop/order_show", $replace);
 }
Ejemplo n.º 18
0
 function resetpwd()
 {
     global $db;
     //判断是否登陆
     !isset($_SESSION['user']) && exit('Please login!');
     //转到登陆页面
     if (!isset($_POST['update'])) {
         tpl('resetpwd');
     }
     //处理修改密码事件
     $post = htmlescape($_POST, 'yes');
     $rs = $db->row_query_one("SELECT * FROM user WHERE user='******'user']}'");
     if (!isset($rs['passwd']) || $rs['passwd'] != md5($post['passwd'])) {
         show('提示', '原密码输入错误', '-1');
         exit;
     }
     $arr = array('user' => $post['user'], 'passwd' => md5($post['newpwd']));
     $rs = $db->row_update('user', $arr, "user='******'user']}'");
     if ($rs) {
         $_SESSION['user'] = $post['user'];
         show('提示', '修改成功,下次登陆请使用新密码', '?module=admin&act=right');
     } else {
         show('提示', '修改密码失败,请稍后再试', '-1');
     }
     exit;
 }
Ejemplo n.º 19
0
 function _manufacturer_show()
 {
     // Prepare manufacturer
     $replace = ["brand" => module("shop")->_manufacturer, "manufacturer_box" => common()->select_box("manufacturer", module("shop")->_man_for_select, $_SESSION['man_id'], false, 2), "url_manufacturer" => process_url("./?object=shop&action=products_show")];
     unset($_SESSION["man_id"]);
     return tpl()->parse("shop/manufacturer", $replace);
 }
Ejemplo n.º 20
0
 /**
  * Order step
  */
 function _order_step_delivery($FORCE_DISPLAY_FORM = false)
 {
     // Validate previous form
     if (main()->is_post() && !$FORCE_DISPLAY_FORM) {
         module('shop')->_order_validate_delivery();
         // Display next form if we have no errors
         if (!common()->_error_exists()) {
             return module('shop')->_order_step_select_payment(true);
         }
     }
     if (main()->USER_ID) {
         $order_info = module('shop')->_user_info;
     }
     // Fill fields
     foreach ((array) module('shop')->_b_fields as $_field) {
         $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[substr($_field, 2)]);
     }
     // Fill shipping from billing
     foreach ((array) module('shop')->_s_fields as $_field) {
         if (module('shop')->_user_info["shipping_same"] && !isset($_POST[$_field])) {
             $s_field = "b_" . substr($_field, 2);
             $replace[$_field] = _prepare_html(isset($_POST[$s_field]) ? $_POST[$s_field] : module('shop')->_user_info[$s_field]);
         } else {
             $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[$_field]);
         }
     }
     $force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP];
     $SELF_METHOD_ID = substr(__FUNCTION__, strlen("_order_step_"));
     $replace = my_array_merge((array) $replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $SELF_METHOD_ID, "error_message" => _e(), "ship_type_box" => module('shop')->_box("ship_type", $force_ship_type ? $force_ship_type : $_POST["ship_type"]), "back_link" => "./?object=shop&action=order", "cats_block" => module('shop')->_categories_show()]);
     return tpl()->parse("shop/order_delivery", $replace);
 }
Ejemplo n.º 21
0
 function show()
 {
     $docs = _class('docs');
     $dir = $docs->docs_dir;
     $dir_len = strlen($dir);
     $ext = '.stpl';
     $ext_len = strlen($ext);
     $name = preg_replace('~[^a-z0-9/_-]+~ims', '', $_GET['id']);
     if (strlen($name)) {
         $dev_path = YF_PATH . '.dev/samples/classes/';
         $dev_class_path = $dev_path . $name . '.class.php';
         if (file_exists($dev_class_path)) {
             return _class($name, $dev_path)->show();
         }
         $f = $dir . $name . '.stpl';
         if (!file_exists($f)) {
             return _404('Not found');
         }
         return '<section class="page-contents">' . tpl()->parse_string(file_get_contents($f), $replace, 'doc_' . $name) . '</section>';
     }
     $url = rtrim(url('/@object/@action/')) . '/';
     $data = [];
     foreach ((array) $this->_get_misc_docs($dir) as $name) {
         $data[$name] = ['name' => $name, 'link' => $url . urlencode($name)];
     }
     ksort($data);
     return html()->li($data);
 }
Ejemplo n.º 22
0
 function clear_patterns()
 {
     $html = table('SELECT * FROM ' . db('shop_patterns'), ['table_attr' => 'id="patterns_list"', 'filter' => $_SESSION[$_GET['object'] . '__patterns'], 'filter_params' => ['search' => 'like', 'repalce' => 'like', 'cat_id' => 'in']])->text('search', ['header_tip' => $this->SEARCH_TIP])->text('replace')->text('description')->func('cat_id', function ($value, $extra, $row_info) {
         $category = conf('all_cats::' . $value);
         $category = !empty($category) ? $category['name'] : t('In all categories');
         return '<span class="badge badge-warning">' . $category . '</span>';
     }, ['desc' => 'Category'])->func('id', function ($value, $extra, $row_info) {
         $where = '';
         if (!empty($row_info['cat_id'])) {
             $cat_ids = _class('cats')->_get_recursive_cat_ids($row_info['cat_id']);
             $where = ' AND (cat_id IN (' . implode(',', $cat_ids) . ') OR id IN (SELECT product_id FROM ' . db('shop_product_to_category') . ' WHERE category_id IN (' . implode(',', $cat_ids) . ')))';
         }
         $sql = 'SELECT COUNT(*) AS `0` FROM ' . db('shop_products') . ' WHERE LOWER(name) REGEXP \'[[:<:]]' . mb_strtolower($row_info['search'], 'UTF-8') . '[[:>:]]\'' . $where;
         list($count) = db()->query_fetch($sql);
         return '<span class="badge badge-info pattern_count">' . $count . '</span>';
     }, ['desc' => 'Products for changing'])->btn_func('Run', function ($row_info, $params, $instance_params, $_this) {
         if ($row_info['process']) {
             return '<button class="btn btn-mini btn-xs run_item btn-warning" data-id="' . $row_info['id'] . '"><i class="icon-refresh fa fa-refresh icon-spin fa-spin"></i> <span>' . t('Process') . '...</span></button>';
         } else {
             return '<button class="btn btn-mini btn-xs btn-info run_item" data-id="' . $row_info['id'] . '"><i class="icon-play fa fa-play"></i> <span>' . t('Run') . '</span></button>';
         }
     })->btn_func('Rollback', function ($row_info, $params, $instance_params, $_this) {
         if ($row_info['process']) {
             return '<button class="btn btn-mini btn-xs btn-warning rollback_item" data-id="' . $row_info['id'] . '"><i class="icon-refresh fa fa-refresh icon-spin fa-spin"></i> <span>' . t('Process') . '...</span></button>';
         } else {
             return '<button class="btn btn-mini btn-xs btn-danger rollback_item" data-id="' . $row_info['id'] . '"><i class="icon-undo fa fa-undo"></i> <span>' . t('Rollback') . '</span></button>';
         }
     })->btn('List of changes', './?object=manage_shop&action=clear_pattern_list&id=%d', ['icon' => 'icon-th-list fa fa-th-list'])->btn_edit('', './?object=manage_shop&action=clear_pattern_edit&id=%d', ['no_ajax' => 1])->btn_delete('', './?object=manage_shop&action=clear_pattern_delete&id=%d')->footer_add('Add pattern', './?object=manage_shop&action=clear_pattern_add', ['no_ajax' => 1]);
     $replace = ['pattern_run_url' => './?object=manage_shop&action=clear_pattern_run', 'pattern_stop_url' => './?object=manage_shop&action=clear_pattern_stop', 'pattern_status_url' => './?object=manage_shop&action=clear_pattern_status', 'pattern_rollback_url' => './?object=manage_shop&action=clear_pattern_rollback'];
     $html .= tpl()->parse('manage_shop/product_clear_patterns', $replace);
     return $html;
 }
Ejemplo n.º 23
0
 function google_maps($name = '', $desc = '', $extra = [], $replace = [], $form)
 {
     if (is_array($desc)) {
         $extra += $desc;
         $desc = '';
     }
     if (!is_array($extra)) {
         $extra = [];
     }
     asset('google-maps-api');
     $extra['name'] = $extra['name'] ?: ($name ?: 'map');
     $extra['markers_limit'] = $extra['markers_limit'] ?: 5;
     $extra['start_zoom'] = $extra['start_zoom'] ?: 5;
     $extra['desc'] = $form->_prepare_desc($extra, $desc);
     $func = function ($extra, $r, $form) {
         $form->_prepare_inline_error($extra);
         // Compatibility with filter
         $start_lat = 49;
         $start_lng = 32;
         $replace = ['start_lat' => $start_lat, 'start_lng' => $start_lng, 'start_zoom' => $extra['start_zoom'], 'markers_limit' => $extra['markers_limit'], 'name' => $extra['name'], 'value' => $r[$extra['name']]];
         if ($extra['disable_edit_mode']) {
             $body = tpl()->parse('form2/google_maps_view', $replace);
         } else {
             $body = tpl()->parse('form2/google_maps', $replace);
         }
         return $form->_row_html($body, $extra, $r);
     };
     if ($form->_chained_mode) {
         $form->_body[] = ['func' => $func, 'extra' => $extra, 'replace' => $replace, 'name' => __FUNCTION__];
         return $form;
     }
     return $func($extra, $replace, $form);
 }
Ejemplo n.º 24
0
 public static function setUpBeforeClass()
 {
     // Replace default style and script templates with empty strings
     tpl()->parse_string('', [], 'style_css');
     tpl()->parse_string('', [], 'script_js');
     _class('assets')->ADD_IS_DIRECT_OUT = false;
     _class('assets')->OUT_ADD_ASSET_NAME = false;
 }
Ejemplo n.º 25
0
 function show()
 {
     foreach (range(1, 10) as $i) {
         $data[$i] = ['id' => $i, 'name' => 'name_' . $i];
     }
     return tpl()->parse_string('{foreach("data")} <li>{if("#.id" mod 4)}_MOD_{/if} {#.name}</li> {/foreach}', ['data' => $data]);
     #	<li>{if("#.id" mod 4)}_MOD_{/if} {if("#.id" mod 3 or "#.id" mod 5)}!!!{/if} {#.name}</li>
 }
Ejemplo n.º 26
0
 /**
  * Order step
  */
 function _order_step_finish($FORCE_DISPLAY_FORM = false)
 {
     module('shop')->_basket_api()->clean();
     if (isset($_GET["page"])) {
         $_GET["id"] = intval($_GET["page"]);
         unset($_GET["page"]);
     }
     $_GET["id"] = intval($_GET["id"]);
     if ($_GET["id"]) {
         $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($_GET["id"]) . " AND user_id=" . intval(main()->USER_ID));
     }
     if (empty($order_info)) {
         return _e("No such order");
     }
     $products_ids = [];
     $Q = db()->query("SELECT * FROM " . db('shop_order_items') . " WHERE `order_id`=" . intval($order_info["id"]));
     while ($_info = db()->fetch_assoc($Q)) {
         if ($_info["product_id"]) {
             $products_ids[$_info["product_id"]] = $_info["product_id"];
         }
         $order_items[$_info["product_id"]] = $_info;
     }
     if (!empty($products_ids)) {
         $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'");
         $products_atts = module('shop')->_products_get_attributes($products_ids);
     }
     foreach ((array) $order_items as $_info) {
         $_product_id = $_info["product_id"];
         $_product = $products_infos[$_product_id];
         $price = $_info["sum"];
         $dynamic_atts = [];
         if (strlen($_info["attributes"]) > 3) {
             foreach ((array) unserialize($_info["attributes"]) as $_attr_id) {
                 $_attr_info = $products_atts[$_info["product_id"]][$_attr_id];
                 $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"];
                 $price += $_attr_info["price"];
             }
         }
         $URL_PRODUCT_ID = module('shop')->_product_id_url($_product);
         $products[$_info["product_id"]] = ["name" => _prepare_html($_product["name"]), "price" => module('shop')->_format_price($price), "sum" => module('shop')->_format_price($_info["sum"]), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($_info["quantity"]), "details_link" => process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : "", "cat_name" => _prepare_html(module('shop')->_shop_cats[$_product["cat_id"]]), "cat_url" => process_url("./?object=shop&action=products_show&id=" . module('shop')->_shop_cats_all[$_product["cat_id"]]['url'])];
         $total_price += $price * $quantity;
     }
     $total_price = $order_info["total_sum"];
     if (main()->USER_ID) {
         $order_info = my_array_merge(module('shop')->_user_info, $order_info);
     } else {
         $order_info["email"] = $order_info["email"];
         $order_info["phone"] = $order_info["phone"];
     }
     $order_info = my_array_merge(module('shop')->COMPANY_INFO, $order_info);
     $replace2 = my_array_merge($order_info, ["id" => $_GET["id"], "products" => $products, "ship_cost" => module('shop')->_format_price(0), "total_cost" => module('shop')->_format_price($total_price), "password" => ""]);
     // Prepare email template
     $message = tpl()->parse("shop/invoice_email", $replace2);
     common()->quick_send_mail($order_info["email"], "invoice #" . $_GET["id"], $message);
     $replace = my_array_merge($replace2, ["error_message" => _e(), "products" => $products, "ship_price" => module('shop')->_format_price(module('shop')->_ship_types_names[$order_info["ship_type"]]), "total_price" => module('shop')->_format_price($total_price), "order_no" => str_pad($order_info["id"], 8, "0", STR_PAD_LEFT), "hash" => _prepare_html($order_info["hash"]), "back_link" => "./?object=shop&action=show", "cats_block" => module('shop')->_categories_show()]);
     return tpl()->parse("shop/order_finish", $replace);
 }
Ejemplo n.º 27
0
 function login()
 {
     !isset($_POST['user']) && exit;
     $arr = escape($_POST, 'yes');
     strtolower($arr['code']) != $_SESSION['authCode'] && show('登陆失败', '验证码错误', '-1');
     $rs = $db->row_query_one("SELECT `passwd` FROM `user` WHERE `user`='{$arr['user']}'");
     (!isset($rs['passwd']) || $rs['passwd'] != md5($arr['passwd'])) && show('登陆失败', '用户名或密码错误', '-1');
     $_SESSION['user'] = $arr['user'];
     tpl('main');
 }
Ejemplo n.º 28
0
 /**
  */
 function _init()
 {
     require_php_lib('smarty');
     $smarty = new Smarty();
     $smarty->setTemplateDir(YF_PATH . tpl()->TPL_PATH);
     $smarty->setCompileDir(STORAGE_PATH . 'templates_c/');
     $smarty->setCacheDir(STORAGE_PATH . 'smarty_cache/');
     #		$smarty->setConfigDir(STORAGE_PATH.'smarty_configs/');
     $this->smarty = $smarty;
 }
Ejemplo n.º 29
0
 public function access()
 {
     //获取当前用户组项目权限信息
     $menu = array();
     $menu = M("Node")->field("id,title,name")->where('level=1')->select();
     foreach ($menu as $k => $v) {
         $menu[$k]['node'] = M("Node")->field("id,title,name")->where("pid={$v['id']}")->select();
     }
     require tpl();
 }
Ejemplo n.º 30
0
 /**
  */
 function _for_user_profile($user_id, $MAX_SHOW_COMMENTS)
 {
     list($comments, $titles, $user_names) = $this->_get_comments($MAX_SHOW_COMMENTS, $user_id);
     if (!empty($comments)) {
         foreach ((array) $comments as $comment) {
             $replace2 = ['num' => ++$i, 'text' => nl2br(_cut_bb_codes(_prepare_html($comment['text']))), 'title' => _prepare_html($titles[$comment['object_name'] . $comment['object_id']]), 'created' => _format_date($comment['add_date'], 'long'), 'view_link' => module('comments')->COMMENT_LINKS[$comment['object_name']] . $comment['object_id'] . '#cid_' . $comment['id'], 'where_comment' => $comment['object_name'], 'user_link' => './?object=user_profile&action=show&id=' . $comment['user_id']];
             $item .= tpl()->parse('comments' . '/for_user_profile_item', $replace2);
         }
     }
     return $item;
 }