Esempio n. 1
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);
 }
 /**
  * Display list of user-specific vars
  */
 function user_vars()
 {
     if (isset($_GET['id']) && !isset($_GET['page'])) {
         $_GET['page'] = $_GET['id'];
         $_GET['id'] = null;
     }
     // Group actions here
     if (main()->is_post()) {
         if (isset($_POST['multi-push'])) {
             foreach ((array) $_POST['items'] as $_id) {
                 $_id = intval($_id);
                 if (!empty($_id)) {
                     $this->user_var_push($_id);
                 }
             }
         }
         return js_redirect('./?object=' . $_GET['object'] . '&action=user_vars' . _add_get());
     }
     $sql = 'SELECT * FROM ' . db('locale_user_tr') . '';
     // TODO: add filter here with sorting selection, user id, etc
     $sql .= strlen($filter_sql) ? ' WHERE 1 ' . $filter_sql : ' ORDER BY user_id DESC, name ASC';
     list($add_sql, $pages, $total) = common()->divide_pages($sql, '', '', 100);
     $Q = db()->query($sql . $add_sql);
     while ($A = db()->fetch_assoc($Q)) {
         $data[$A['id']] = $A;
         if ($A['user_id']) {
             $users_ids[$A['user_id']] = intval($A['user_id']);
         }
         if (strlen($A['name'])) {
             $vars_names[$A['name']] = $A['name'];
         }
     }
     if (!empty($users_ids)) {
         $Q = db()->query('SELECT * FROM ' . db('user') . ' WHERE id IN(' . implode(',', $users_ids) . ')');
         while ($A = db()->fetch_assoc($Q)) {
             $users_names[$A['id']] = $A['email'];
         }
     }
     // Check if var exists in the global table
     $global_vars = [];
     if (!empty($vars_names)) {
         foreach ((array) db()->query_fetch_all('SELECT * FROM ' . db('locale_vars') . " WHERE value IN('" . implode("','", $vars_names) . "')") as $A) {
             $global_vars[$A['value']] = $A['id'];
         }
     }
     $color_exists = '#ff5';
     foreach ((array) $data as $A) {
         $var_bg_color = '';
         $global_var_exists = isset($global_vars[_strtolower(str_replace(' ', '_', $A['name']))]);
         if ($global_var_exists) {
             $var_bg_color = $color_exists;
         }
         $items[] = ['id' => $A['id'], 'bg_class' => $i++ % 2 ? 'bg1' : 'bg2', 'id' => intval($A['id']), 'user_id' => intval($A['user_id']), 'user_name' => _prepare_html($users_names[$A['user_id']]), 'user_link' => _profile_link($A['user_id']), 'name' => _prepare_html(str_replace('_', ' ', $A['name'])), 'translation' => _prepare_html($A['translation']), 'locale' => _prepare_html($A['locale']), 'site_id' => intval($A['site_id']), 'last_update' => _format_date($A['last_update'], 'long'), 'global_exists' => (int) $global_var_exists, 'var_bg_color' => $var_bg_color, 'active' => intval($A['active']), 'edit_url' => './?object=' . $_GET['object'] . '&action=user_var_edit&id=' . $A['id'], 'delete_url' => './?object=' . $_GET['object'] . '&action=user_var_delete&id=' . $A['id'], 'push_url' => './?object=' . $_GET['object'] . '&action=user_var_push&id=' . $A['id']];
     }
     $replace = ['form_action' => './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . ($_GET['id'] ? '&id=' . $_GET['id'] : ''), 'error' => _e(), 'items' => $items, 'pages' => $pages, 'total' => $total, 'show_vars_link' => './?object=' . $_GET['object'] . '&action=show_vars'];
     return tpl()->parse($_GET['object'] . '/user_vars_main', $replace);
 }
Esempio n. 3
0
 /**
  * view orders
  */
 function _order_view()
 {
     if ($_POST["order_id"]) {
         $_GET["id"] = intval($_POST["order_id"]);
     } else {
         $_GET["id"] = intval($_GET["id"]);
     }
     if ($_GET["id"]) {
         $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($_GET["id"]));
     }
     if (empty($order_info)) {
         return _e("No such order");
     }
     if (!empty($_POST["status"])) {
         db()->UPDATE(db('shop_orders'), ["status" => _es($_POST["status"])], "id=" . intval($_GET["id"]));
         return js_redirect("./?object=shop&action=orders");
     }
     $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 = $products_infos[$_info["product_id"]];
         $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"];
             }
         }
         $products[$_info["product_id"]] = ["name" => _prepare_html($_product["name"]), "price" => module('shop')->_format_price($_info["sum"]), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($_info["quantity"]), "details_link" => process_url("./?object=shop&action=view&id=" . $_product["id"]), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : ""];
         $total_price += $_info["price"] * $quantity;
     }
     $total_price = $order_info["total_sum"];
     $replace = my_array_merge($replace, _prepare_html($order_info));
     $replace = my_array_merge($replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $_GET["id"], "order_id" => $order_info["id"], "total_sum" => module('shop')->_format_price($order_info["total_sum"]), "user_link" => _profile_link($order_info["user_id"]), "user_name" => _display_name(user($order_info["user_id"])), "error_message" => _e(), "products" => (array) $products, "total_price" => module('shop')->_format_price($total_price), "ship_type" => module('shop')->_ship_type[$order_info["ship_type"]], "pay_type" => module('shop')->_pay_types[$order_info["pay_type"]], "date" => _format_date($order_info["date"], "long"), "status_box" => module('shop')->_statuses[$order_info["status"]], "back_url" => "./?object=shop&action=orders"]);
     return tpl()->parse("shop/order_view", $replace);
 }
Esempio n. 4
0
    /**
     */
    function view_order()
    {
        $_GET['id'] = intval($_GET['id']);
        if ($_GET['id']) {
            if ($this->SUPPLIER_ID) {
                $sql = 'SELECT o.* FROM ' . db('shop_orders') . ' AS o
						INNER JOIN ' . db('shop_order_items') . ' AS i ON i.order_id = o.id
						INNER JOIN ' . db('shop_products') . ' AS p ON i.product_id = p.id
						INNER JOIN ' . db('shop_admin_to_supplier') . ' AS m ON m.supplier_id = p.supplier_id
						WHERE
							o.id=' . intval($_GET['id']) . '
							AND m.admin_id=' . intval(main()->ADMIN_ID) . '
						GROUP BY o.id';
            } else {
                $sql = 'SELECT * FROM ' . db('shop_orders') . ' WHERE id=' . intval($_GET['id']);
            }
            $order_info = db()->query_fetch($sql);
        }
        if (empty($order_info)) {
            return _e('No such order');
        }
        $recount_price = false;
        $_class_price = _class('_shop_price', 'modules/shop/');
        $_class_units = _class('_shop_product_units', 'modules/shop/');
        $_class_basket = _class('shop_basket', 'modules/shop/');
        if (main()->is_post()) {
            module('manage_shop')->_product_check_first_revision('order', intval($_GET['id']));
            $order_id = (int) $_GET['id'];
            foreach ($_POST as $k => $v) {
                if ($k == 'status_item') {
                    foreach ($v as $k1 => $status) {
                        list($product_id, $param_id) = explode('_', $k1);
                        db()->UPDATE(db('shop_order_items'), ['status' => $status], ' order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id));
                    }
                } elseif ($k == 'delete') {
                    foreach ($v as $k1 => $is_del) {
                        list($product_id, $param_id) = explode('_', $k1);
                        if ($is_del == 1) {
                            db()->query('DELETE FROM ' . db('shop_order_items') . ' WHERE order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id));
                        }
                    }
                    $recount_price = true;
                } elseif ($k == 'qty') {
                    foreach ($v as $k1 => $qty) {
                        list($product_id, $param_id) = explode('_', $k1);
                        if (intval($qty) == 0) {
                            db()->query('DELETE FROM ' . db('shop_order_items') . ' WHERE order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id));
                        } else {
                            db()->UPDATE(db('shop_order_items'), ['quantity' => intval($qty)], ' order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id));
                        }
                        $recount_price = true;
                    }
                } elseif ($k == 'unit') {
                    foreach ($v as $k1 => $unit) {
                        $unit = (int) $unit;
                        list($product_id, $param_id) = explode('_', $k1);
                        $product_id = (int) $product_id;
                        $param_id = (int) $param_id;
                        if ($unit > 0) {
                            $units = $_class_units->get_by_product_ids($product_id);
                            if (isset($units[$product_id][$unit])) {
                                db()->UPDATE(db('shop_order_items'), ['unit' => $unit], ' order_id=' . $order_id . ' AND product_id=' . $product_id . ' AND param_id=' . $param_id);
                                $products = db_get_all('SELECT * FROM ' . db('shop_products') . ' WHERE id = ' . $product_id);
                                $product = $products[$product_id];
                                list($price) = $_class_price->markup_down($product['price'], $product_id);
                                $item = ['price' => $price, 'unit' => $unit, 'units' => $units[$product_id]];
                                $price_one = $_class_basket->_get_price_one($item);
                                $item = ['order_id' => $order_id, 'product_id' => $product_id, 'param_id' => $param_id];
                                $item_price = $item + ['price' => $price_one];
                                $this->_item_update_price_unit($item_price);
                                $recount_price = true;
                            }
                        }
                    }
                } elseif ($k == 'price_unit') {
                    foreach ($v as $k1 => $price) {
                        list($product_id, $param_id) = explode('_', $k1);
                        $this->_item_update_price_unit(['price' => $price, 'order_id' => $order_id, 'product_id' => (int) $product_id, 'param_id' => (int) $param_id]);
                        $recount_price = true;
                    }
                }
            }
            $sql = [];
            foreach (['address', 'phone', 'address', 'house', 'apartment', 'floor', 'porch', 'intercom', 'delivery_price', 'status', 'region', 'discount', 'discount_add', 'delivery_type', 'delivery_id', 'delivery_location'] as $f) {
                if (isset($_POST[$f])) {
                    $sql[$f] = $_POST[$f];
                    if ($f == 'delivery_price' && $_POST['delivery_price'] != $order_info['delivery_price']) {
                        $sql['is_manual_delivery_price'] = 1;
                        $order_info['is_manual_delivery_price'] = 1;
                        $order_info['delivery_price'] = $sql['delivery_price'];
                        $recount_price = true;
                    }
                    if ($f == 'discount') {
                        $discount = $_class_price->_number_mysql($sql['discount']);
                        $order_info['discount'] = $discount;
                        $sql['discount'] = $discount;
                        $recount_price = true;
                    }
                    if ($f == 'discount_add') {
                        $discount = $_class_price->_number_mysql($sql['discount_add']);
                        $order_info['discount_add'] = $discount;
                        $sql['discount_add'] = $discount;
                    }
                    if ($f == 'delivery_id') {
                        $value = (int) $sql[$f];
                        $value = $value > 0 ? $value : $order_info[$f];
                        $sql[$f] = $value;
                    }
                    if ($f == 'delivery_type') {
                        $value = (int) $sql[$f];
                        $order_info['payment'] = $value;
                        $sql['payment'] = $value;
                    }
                }
            }
            if (count($sql) > 0) {
                db()->update_safe(db('shop_orders'), $sql, 'id=' . intval($_GET['id']));
            }
            if ($recount_price) {
                list($order_info['total_sum'], $order_info['delivery_price']) = $this->_order_recount_price($order_info['id'], $order_info);
            }
            module('manage_shop')->_order_add_revision('edit', intval($_GET['id']));
            return js_redirect('./?object=' . main()->_get('object') . '&action=view_order&id=' . $order_info['id']);
        }
        $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['param_id']] = $_info;
        }
        if (!empty($products_ids)) {
            $products_infos = db()->query_fetch_all('SELECT * FROM ' . db('shop_products') . ' WHERE id IN(' . implode(',', $products_ids) . ')');
            $products_atts = module('manage_shop')->_get_products_attributes($products_ids);
        }
        $price_total = 0;
        foreach ((array) $order_items as $_info) {
            $_product = $products_infos[$_info['product_id']];
            $_units = [];
            if (intval($_info['type']) == 1) {
                $images[0]['thumb'] = _class('_shop_products', 'modules/shop/')->_product_set_image($_info["product_id"], $_product['cat_id'], 'thumb', false);
                $link = './?object=' . main()->_get('object') . '&action=product_set_edit&id=' . $_info['product_id'];
            } else {
                $images = _class('_shop_products', 'modules/shop/')->_product_image($_info["product_id"], false, false);
                $link = './?object=' . main()->_get('object') . '&action=product_edit&id=' . $_info['product_id'];
                $_units = $_class_units->get_by_product_ids($_info['product_id']);
            }
            $image = $images[0]['thumb'] ?: _class('_shop_categories', 'modules/shop/')->get_icon_url($_product['cat_id'], 'item');
            $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'];
                }
            }
            $product_id = (int) $_info['product_id'];
            $param_id = (int) $_info['param_id'];
            $price_one = tofloat($_info['price']);
            $quantity = (int) $_info['quantity'];
            $price_item = $price_one * $quantity;
            // product unit
            $unit = (int) $_info['unit'];
            $units = null;
            $unit_name = 'шт.';
            if ($_units[$product_id]) {
                $units = $_units[$product_id];
                $units[$unit] && ($unit_name = $units[$unit]['title']);
            }
            $products[$_info['product_id'] . '_' . $_info['param_id']] = ['product_id' => intval($_info['product_id']), 'param_id' => intval($_info['param_id']), 'param_name' => _class('_shop_product_params', 'modules/shop/')->_get_name_by_option_id($_info['param_id']), 'name' => _prepare_html($_product['name']), 'image' => $image, 'link' => $link, 'unit' => $unit, 'unit_name' => $unit_name, 'units' => $units, 'price_unit' => $price_one, 'price' => $price_item, 'currency' => _prepare_html(module('manage_shop')->CURRENCY), 'quantity' => intval($_info['quantity']), 'details_link' => process_url('./?object=' . main()->_get('object') . '&action=view&id=' . $_product['id']), 'dynamic_atts' => !empty($dynamic_atts) ? implode('<br />' . PHP_EOL, $dynamic_atts) : '', 'status' => module('manage_shop')->_box('status_item', $_info['status']), 'delete' => ''];
            $price_total += $price_item;
        }
        // discount
        $discount = $order_info['discount'];
        $discount_add = $order_info['discount_add'];
        $_discount = $discount;
        $discount_price = $_class_price->apply_price($price_total, $_discount);
        $discount_price -= $price_total;
        $discount_price = $_class_price->_number_round($discount_price);
        $_discount = $discount_add;
        $discount_add_price = $_class_price->apply_price($price_total, $_discount);
        $discount_add_price -= $price_total;
        $total_price = tofloat($order_info['total_sum']);
        $replace = my_array_merge($replace, _prepare_html($order_info));
        $replace = my_array_merge($replace, ['form_action' => './?object=' . main()->_get('object') . '&action=' . $_GET['action'] . '&id=' . $_GET['id'], 'order_id' => $order_info['id'], 'price_total_info' => module('manage_shop')->_format_price($price_total), 'discount' => $_class_price->_number_format($discount), 'discount_add' => $_class_price->_number_format($discount_add), 'discount_price_info' => $_class_price->_price_format($discount_price), 'discount_add_price_info' => $_class_price->_price_format($discount_add_price), 'delivery_info' => module('manage_shop')->_format_price($order_info['delivery_price']), 'total_sum' => module('manage_shop')->_format_price($total_price), 'user_link' => _profile_link($order_info['user_id']), 'user_name' => _display_name(user($order_info['user_id'])), 'error_message' => _e(), 'products' => (array) $products, 'total_price' => module('manage_shop')->_format_price($total_price), 'ship_type' => module('manage_shop')->_ship_types[$order_info['ship_type']], 'pay_type' => module('manage_shop')->_pay_types[$order_info['pay_type']], 'date' => $order_info['date'], 'status_box' => module('manage_shop')->_box('status', $order_info['status']), 'back_url' => './?object=' . main()->_get('object') . '&action=show_orders', 'print_url' => './?object=' . main()->_get('object') . '&action=show_print&id=' . $order_info['id'], 'payment' => common()->get_static_conf('payment_methods', $order_info['payment'])]);
        $link_invoice = './?object=manage_shop&action=invoice&id=' . $replace['id'];
        $link_invoice_add = $link_invoice . '&with_discount_add=y';
        $link_pdf_invoice = $link_invoice . '&pdf=y';
        $link_pdf_invoice_add = $link_invoice_add . '&pdf=y';
        $region = _class('_shop_region', 'modules/shop/')->_get_list();
        array_unshift($region, '- регион не выбран -');
        $out = form2($replace, ['dd_mode' => 1, 'big_labels' => true])->info('id')->info('price_total_info', ['desc' => 'Сумма'])->row_start(['desc' => 'Скидка, %'])->number('discount', ['desc' => 'Скидка, %'])->info('discount_price_info')->link('Invoice', $link_invoice, ['title' => 'Накладная без учета добавочной скидки', 'icon' => 'fa fa-file-o', 'target' => '_blank'])->link('PDF', $link_pdf_invoice, ['title' => 'Накладная PDF без учета добавочной скидки', 'icon' => 'fa fa-file-text-o', 'target' => '_blank'])->row_end()->row_start(['desc' => 'Скидка добавочная, %'])->number('discount_add', ['desc' => 'Скидка добавочная, %'])->info('discount_add_price_info', ['desc' => ' '])->link(t('Invoice') . '+', $link_invoice_add, ['title' => 'Накладная с учетом добавочной скидки', 'icon' => 'fa fa-file-o', 'target' => '_blank'])->link(t('PDF') . '+', $link_pdf_invoice_add, ['title' => 'Накладная PDF с учетом добавочной скидки', 'icon' => 'fa fa-file-text-o', 'target' => '_blank'])->row_end()->info('delivery_info', ['desc' => 'Доставка'])->info('total_sum', '', ['desc' => 'Итоговая сумма', 'tip' => 'Итоговая сумма без учета добавочной скидки', 'no_escape' => 1])->info_date('date', ['format' => 'full'])->info('name')->email('email')->info('phone')->container('<a href="./?object=' . main()->_get('object') . '&action=send_sms&phone=' . urlencode($replace["phone"]) . '" class="btn">Send SMS</a><br /><br />')->select_box('region', $region, ['desc' => 'Регион доставки', 'class_add_wrapper' => 'region_type_wrap'])->select_box('delivery_type', _class('_shop_delivery', 'modules/shop/')->_get_types(), ['desc' => 'Тип доставки', 'class_add_wrapper' => 'delivery_type_wrap'])->select_box('delivery_id', _class('_shop_delivery', 'modules/shop/')->_get_locations_by_type($replace['delivery_type']), ['class' => 'delivery_id', 'class_add_wrapper' => 'delivery_id_wrap', 'desc' => 'Отделение'])->text('delivery_location', 'Отделение доставки', ['class' => 'delivery_location', 'class_add_wrapper' => 'delivery_location_wrap'])->text('address')->text('house')->text('apartment')->text('floor')->text('porch')->text('intercom')->info('comment')->text('delivery_time')->price('delivery_price')->user_info('user_id')->info('payment', 'Payment method')->info('transaction_id', 'Transaction id')->container(table2($products)->image('product_id', ['width' => '50px', 'no_link' => true, 'web_path' => '', 'img_path_check' => false, 'img_path_callback' => function ($_p1, $_p2, $row) {
            return $row['image'];
        }])->func('link', function ($f, $p, $row) {
            $result = "<a class='btn' href='{$row[link]}'>{$row[product_id]}</a>";
            return $result;
        })->func('name', function ($f, $p, $row) {
            $row['name'] = $row['name'] . ($row['param_name'] != '' ? "<br /><small>" . $row['param_name'] . "</small>" : '');
            return $row['name'];
        })->func('unit', function ($f, $p, $row) {
            $values = [];
            if (!empty($row['units'])) {
                $values[0] = ' - ';
                foreach ($row['units'] as $id => $item) {
                    $values[$id] = $item['title'];
                }
            }
            $desc = 'Ед. измерения';
            $width = '7em';
            $result = sprintf('
									<style>
										.unit_current {
											width: %s;
										}
									</style>
									<div class="unit_current">
										%s
										<span class="btn btn-mini unit_change">
											<i class="icon-edit fa fa-edit"></i>
										</span>
									</div>
									', $width, $row['unit_name']) . _class('html')->select2_box(['desc' => $desc, 'name' => 'unit[' . $row['product_id'] . '_' . $row['param_id'] . ']', 'values' => $values, 'js_options' => ['width' => $width, 'containerCssClass' => 'select2_box']]);
            return $result;
        })->func('quantity', function ($f, $p, $row) {
            $row['quantity'] = "<input type='text' name='qty[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='" . intval($row['quantity']) . "' style='width:50px;'>";
            return $row['quantity'];
        })->func('price_unit', function ($f, $p, $row) {
            $row['price_unit'] = "<input type='text' name='price_unit[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='" . $row['price_unit'] . "' style='width:100px;'>";
            return $row['price_unit'];
        })->text('price')->func('status', function ($f, $p, $row) {
            $row['status'] = str_replace("status_item", "status_item[" . $row['product_id'] . "_" . $row['param_id'] . "]", $row['status']);
            return $row['status'];
        })->func('delete', function ($f, $p, $row) {
            $row['delete'] = "<input type='checkbox' name='delete[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='1'>";
            return $row['delete'];
        }), ['wide' => 1])->container(tpl()->parse('manage_shop/product_search_order', ['order_id' => $_GET['id']]), 'Add product')->box('status_box', 'Status order', ['selected' => $order_info['status']])->save_and_back();
        // misc handlers
        css('
			.select2_box {
				display: none;
			}
			.unit_current {
				position : relative;
			}
			.btn.unit_change {
				display  : none;
				position : absolute;
				right    : 0;
			}
		');
        jquery('
			$(".delivery_id").on( "change", function( event ) {
				var location =  $(this).find( "option:selected" ).text();
				$(".delivery_location").val( location );
			});
			var delivery_type__on_change = function( target ) {
				var value = +$(target).find( "option:selected" ).val();
				if( value == 1 ) {
					$(".delivery_id_wrap").hide();
					$(".delivery_location_wrap").hide();
				} else if( value == 2 ) {
					var count = +$(".delivery_id_wrap").find( "option" ).length;
					if( count > 1 ) {
						$(".delivery_id_wrap").show();
						$(".delivery_location_wrap").show();
					}
				}
			}
			delivery_type__on_change( $(".delivery_type_wrap") );

			$(".delivery_type_wrap").on( "change", function( event ) {
				delivery_type__on_change( event.target );
			});
			$( ".unit_change" ).on( "click", function( event ) {
				var $this = $( this );
				var $select2 = $this.parent().next();
				$select2.toggle()
			}).each( function( i ) {
				var $this = $( this );
				if( $this.parent().next().length ) {
					$this.show();
				}
			});
		');
        // get similar orders
        $sql = "SELECT o.*, COUNT(*) AS num_items FROM `" . db('shop_orders') . "` AS `o`\n\t\t\t\tINNER JOIN " . db('shop_order_items') . " AS i ON i.order_id = o.id\n\t\t\t\tWHERE `o`.`id`!='" . $order_info['id'] . "'\n\t\t\t\t\tAND `o`.`phone`='" . $order_info['phone'] . "'\n\t\t\t\t\tAND `o`.`status`='" . $order_info['status'] . "'\n\t\t\t\tGROUP BY o.id ORDER BY o.id DESC";
        $out .= "<br /><br /><h3>" . t('Similar orders') . "</h3>" . table($sql)->text('id')->date('date', ['format' => 'full', 'nowrap' => 1])->user('user_id')->text('name')->text('phone')->text('total_sum', ['nowrap' => 1])->text('num_items')->btn_edit('', './?object=' . main()->_get('object') . '&action=view_order&id=%d', ['no_ajax' => 1])->btn('Merge', './?object=' . main()->_get('object') . '&action=merge_order&id=' . $order_info['id'] . '&merge_id=%d', ['no_ajax' => 1]);
        //		$out .= tpl()->parse('manage_shop/product_search',array());
        return $out;
    }
Esempio n. 5
0
 /**
  * Show friendship statistics
  */
 function show_friend_stats()
 {
     if (empty(main()->USER_ID)) {
         return _error_need_login();
     }
     $_id = intval(main()->USER_ID);
     $sql = "SELECT * FROM " . db('log_user_action') . " WHERE action_name IN('add_friend', 'del_friend') AND owner_id=" . $_id . " ORDER BY add_date DESC";
     list($add_sql, $pages, $total) = common()->divide_pages($sql);
     $stats_array = db()->query_fetch_all($sql . $add_sql);
     foreach ((array) $stats_array as $A) {
         $members_ids[] = $A["member_id"];
     }
     $members_ids = array_unique((array) $members_ids);
     $user_infos = user($members_ids, "short");
     foreach ((array) $stats_array as $A) {
         $replace2 = ["avatar" => _show_avatar($A["member_id"]), "event_date" => _format_date($A["add_date"], "long"), "user_nick" => $user_infos[$A["member_id"]]["nick"], "event" => $A["action_name"], "profile_url" => _profile_link($user_infos[$A["member_id"]])];
         $items .= tpl()->parse($_GET["object"] . "/friend_stats_item", $replace2);
     }
     $replace = ["total" => $total, "pages" => $pages, "items" => $items, "back_url" => "./?object=" . $_GET["object"]];
     return tpl()->parse($_GET["object"] . "/friend_stats_main", $replace);
 }
Esempio n. 6
0
    /**
     * Do edit own comment
     */
    function _edit($params = [])
    {
        if (empty(main()->USER_ID) && MAIN_TYPE_USER) {
            return _error_need_login();
        }
        $_GET['id'] = intval($_GET['id']);
        $comment_info = db()->query_fetch('SELECT * FROM ' . db('comments') . ' WHERE id=' . intval($_GET['id']));
        if (empty($comment_info['id'])) {
            return _e('No such comment!');
        }
        $OBJECT_NAME = !empty($params['object_name']) ? $params['object_name'] : $_GET['object'];
        $OBJECT_ID = !empty($params['object_id']) ? intval($params['object_id']) : intval($_GET['id']);
        $FORM_ACTION = !empty($params['add_form_action']) ? $params['add_form_action'] : './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&id=' . $OBJECT_ID;
        $STPL_NAME_EDIT = !empty($params['stpl_edit']) ? $params['stpl_edit'] : 'comments/edit_form';
        $RETURN_PATH = $_SERVER['HTTP_REFERER'];
        if (!empty($params['return_path'])) {
            $RETURN_PATH = process_url($params['return_path']);
        } elseif (!empty($params['return_action'])) {
            $RETURN_PATH = process_url('./?object=' . $_GET['object'] . '&action=' . $params['return_action'] . '&id=' . $comment_info['object_id']);
        }
        if (empty($OBJECT_NAME) || empty($OBJECT_ID)) {
            return '';
        }
        $edit_allowed = false;
        $edit_allowed_check_method = is_object(module($_GET['object'])) && method_exists(module($_GET['object']), module('comments')->_edit_allowed_method);
        if ($edit_allowed_check_method) {
            $m = module('comments')->_edit_allowed_method;
            $edit_allowed = (bool) module($_GET['object'])->{$m}(['user_id' => $comment_info['user_id'], 'object_id' => $comment_info['object_id']]);
        } else {
            $edit_allowed = main()->USER_ID && $comment_info['user_id'] == main()->USER_ID;
        }
        if (MAIN_TYPE_ADMIN) {
            $edit_allowed = true;
        } else {
            if (!empty(module('comments')->EDIT_LIMIT_TIME)) {
                $elapse_time = time() - $comment_info['add_date'];
                if ($elapse_time > module('comments')->EDIT_LIMIT_TIME) {
                    return _e('allowed time to edit has expired');
                }
            }
        }
        if (!$edit_allowed) {
            return _e('You are not allowed to perform this action');
        }
        $user_info = user($comment_info['user_id'], ['id', 'name', module('comments')->_user_nick_field, 'photo_verified'], ['WHERE' => ['active' => 1]]);
        if (count($_POST) > 0 && !isset($_POST['_not_for_comments'])) {
            $_POST['text'] = substr($_POST['text'], 0, module('comments')->MAX_POST_TEXT_LENGTH);
            if (empty($_POST['text'])) {
                _re('Comment text required');
            }
            if (module($_GET['object'])->USE_CAPTCHA) {
                module($_GET['object'])->_captcha_check();
            }
            if (!common()->_error_exists() && MAIN_TYPE_USER) {
                $info_for_check = ['comment_text' => $_POST['text'], 'user_id' => main()->USER_ID];
                $USER_BANNED = _check_user_ban($info_for_check, module('comments')->_user_info);
                if ($USER_BANNED) {
                    module('comments')->_user_info = user(main()->USER_ID);
                }
                if (module('comments')->_user_info['ban_comments']) {
                    return _e('Sorry, you are not allowed to post comments!' . PHP_EOL . 'Perhaps, you broke some of our rules and moderator has banned you from using this feature. Please, enjoy our site in some other way!' . 'For more details <a href=\'./?object=faq&action=view&id=16\'>click here</a>');
                }
            }
            // Anti-flood check
            if (!common()->_error_exists() && module('comments')->ANTI_FLOOD_TIME && MAIN_TYPE_USER) {
                $FLOOD_DETECTED = db()->query_fetch('SELECT id,add_date FROM ' . db('comments') . ' WHERE ' . (main()->USER_ID ? 'user_id=' . intval(main()->USER_ID) : 'ip="' . _es(common()->get_ip()) . '"') . ' AND add_date > ' . (time() - module('comments')->ANTI_FLOOD_TIME) . ' 
					ORDER BY add_date DESC 
					LIMIT 1');
                if (!empty($FLOOD_DETECTED)) {
                    _re('Please wait %num seconds before post comment.', ['%num' => intval(module('comments')->ANTI_FLOOD_TIME - (time() - $FLOOD_DETECTED['add_date']))]);
                }
            }
            // Anti-spam check
            if (!common()->_error_exists()) {
                if (module('comments')->ANTI_SPAM_DETECT) {
                    $this->_spam_check($_POST['text']);
                }
            }
            if (!common()->_error_exists()) {
                if (module('comments')->AUTO_FILTER_INPUT_TEXT) {
                    $_POST['text'] = _filter_text($_POST['text']);
                }
                if (module('comments')->USE_BB_CODES) {
                    $BB_CODES_OBJ = _class('bb_codes');
                    if (is_object($BB_CODES_OBJ)) {
                        $_POST['text'] = $BB_CODES_OBJ->_force_close_bb_codes($_POST['text']);
                    }
                }
                db()->UPDATE('comments', ['text' => _es($_POST['text'])], 'id=' . intval($comment_info['id']));
                $try_trigger_callback = [module($_GET['object']), module('comments')->_on_update_trigger];
                if (is_callable($try_trigger_callback)) {
                    call_user_func($try_trigger_callback, $params);
                }
                $RETURN_PATH = !empty($params['return_path']) ? process_url($params['return_path']) : (!empty($params['return_action']) ? process_url('./?object=' . $_GET['object'] . '&action=' . $params['return_action'] . '&id=' . $comment_info['object_id']) : $_SERVER['HTTP_REFERER']);
                return js_redirect($RETURN_PATH, false);
            }
        } else {
            $_POST['text'] = $comment_info['text'];
        }
        $error_message = _e();
        if (empty($_POST['go']) || !empty($error_message)) {
            $replace = ['form_action' => $FORM_ACTION, 'error_message' => $error_message, 'user_id' => intval(main()->USER_ID), 'user_name' => _prepare_html(_display_name($user_info)), 'user_avatar' => _show_avatar($comment_info['user_id'], $user_info, 1, 1), 'user_profile_link' => _profile_link($comment_info['user_id']), 'user_email_link' => _email_link($comment_info['user_id']), 'text' => _prepare_html($_POST['text']), 'back_url' => $_SERVER['HTTP_REFERER'], 'object_name' => _prepare_html($OBJECT_NAME), 'object_id' => intval($OBJECT_ID), 'use_captcha' => intval((bool) module($_GET['object'])->USE_CAPTCHA), 'captcha_block' => module($_GET['object'])->_captcha_block(), 'bb_codes_block' => module('comments')->USE_BB_CODES ? _class('bb_codes')->_display_buttons(['unique_id' => 'text']) : '', 'js_check' => intval((bool) module('comments')->JS_TEXT_CHECKING)];
            $body = tpl()->parse($STPL_NAME_EDIT, $replace);
        }
        return $body;
    }
Esempio n. 7
0
 /**
  * Display comments tree
  */
 function _show_for_object_tree($params = [])
 {
     $OBJECT_NAME = !empty($params['object_name']) ? $params['object_name'] : $_GET['object'];
     $OBJECT_ID = !empty($params['object_id']) ? intval($params['object_id']) : intval($_GET['id']);
     $STPL_NAME_MAIN = !empty($params['stpl_main']) ? $params['stpl_main'] : 'comments/main_tree';
     $STPL_NAME_ITEM = !empty($params['stpl_item']) ? $params['stpl_item'] : 'comments/item_tree';
     $PAGER_PATH = !empty($params['pager_path']) ? $params['pager_path'] : '';
     $FORM_ACTION = !empty($params['add_form_action']) ? $params['add_form_action'] : './?object=' . $_GET['object'] . '&action=add_comment&id=' . $OBJECT_ID;
     $USE_TREE_MODE = !empty($params['use_tree_mode']) ? $params['use_tree_mode'] : $this->USE_TREE_MODE;
     if (empty($OBJECT_NAME) || empty($OBJECT_ID)) {
         return '';
     }
     // Get current profile comments from db
     $sql = 'SELECT * FROM ' . db('comments') . ' WHERE object_name="' . _es($OBJECT_NAME) . '" AND object_id=' . intval($OBJECT_ID) . ($this->PROCESS_STATUS_FIELD ? ' AND active=1 ' : '');
     $order_sql = ' ORDER BY add_date ASC';
     $Q = db()->query($sql . $order_sql);
     while ($A = db()->fetch_assoc($Q)) {
         $comments_array[$A['id']] = $A;
         $comments_array_ids[$A['id']] = $A['parent_id'];
         $users_ids[$A['user_id']] = $A['user_id'];
     }
     if (main()->USER_ID && !empty($comments_array)) {
         module('unread')->_set_read('comments', array_keys($comments_array));
     }
     // Try to get users names
     if (!empty($users_ids)) {
         foreach ((array) user($users_ids, ['id', 'name', $this->_user_nick_field, 'photo_verified']) as $A) {
             $users_names[$A['id']] = _display_name($A);
             $GLOBALS['verified_photos'][$A['id']] = $A['photo_verified'];
         }
     }
     $users_reput_info = module('reputation')->_get_reput_info_for_user_ids($users_ids);
     // Try to find more complex checking methods
     $obj = module($_GET['object']);
     $edit_allowed_check_method = is_object($obj) && method_exists($obj, $this->_edit_allowed_method);
     $delete_allowed_check_method = is_object($obj) && method_exists($obj, $this->_delete_allowed_method);
     if ($this->CHECK_ALLOW_TO_VIEW_USER_EMAIL) {
         $view_email_allowed_check_method = is_object($obj) && method_exists($obj, $this->_view_email_allowed_method);
     }
     if ($view_email_allowed_check_method) {
         $m = $this->_view_email_allowed_method;
         $view_email = (bool) module($_GET['object'])->{$m}(['object_id' => $OBJECT_ID]);
     }
     $this->_comment_array = $comments_array_ids;
     $this->_comment_tree_array = [];
     if (!empty($this->_comment_array)) {
         foreach ((array) $this->_comment_array as $key => $value) {
             if ($value == 0) {
                 $temp_array[$key] = $value;
             }
         }
         $this->_sort_to_tree($temp_array);
     }
     foreach ((array) $this->_comment_tree_array as $comment_tree_info) {
         $comment_info = $comments_array[$comment_tree_info['id']];
         $level = $comment_tree_info['level'];
         if ($edit_allowed_check_method) {
             $m = $this->_edit_allowed_method;
             $edit_allowed = (bool) module($_GET['object'])->{$m}(['user_id' => $comment_info['user_id'], 'object_id' => $comment_info['object_id']]);
         } else {
             $edit_allowed = main()->USER_ID && $comment_info['user_id'] == main()->USER_ID;
         }
         if ($delete_allowed_check_method) {
             $m = $this->_delete_allowed_method;
             $delete_allowed = (bool) module($_GET['object'])->{$m}(['user_id' => $comment_info['user_id'], 'object_id' => $comment_info['object_id']]);
         } else {
             $delete_allowed = main()->USER_ID && $comment_info['user_id'] == main()->USER_ID;
         }
         if (MAIN_TYPE_ADMIN) {
             $edit_allowed = true;
             $delete_allowed = true;
         }
         $comment_info['text'] = str_replace(["\\\\", "\\'", "\\\""], ["\\", "'", "\""], $comment_info['text']);
         if ($comment_info['text'] == '__comment was deleted__' and $comment_info['user_id'] == '0') {
             $comment_info['text'] = t(str_replace('__', '', $comment_info['text']));
         }
         $replace2 = ['user_id' => intval($comment_info['user_id']), 'user_name' => _prepare_html(!empty($comment_info['user_id']) ? $users_names[$comment_info['user_id']] : $comment_info['user_name']), 'user_email' => $view_email ? _prepare_html($comment_info['user_email']) : '', 'user_avatar' => $comment_info['user_id'] ? _show_avatar($comment_info['user_id'], $users_names[$comment_info['user_id']], 1, 0, 1) : '', 'user_profile_link' => $comment_info['user_id'] ? _profile_link($comment_info['user_id']) : '', 'user_email_link' => $comment_info['user_id'] ? _email_link($comment_info['user_id']) : '', 'add_date' => _format_date($comment_info['add_date'], 'long'), 'comment_text' => $this->_format_text($comment_info['text']), 'edit_comment_link' => $edit_allowed ? './?object=' . $_GET['object'] . '&action=edit_comment&id=' . $comment_info['id'] . _add_get(['page']) : '', 'delete_comment_link' => $delete_allowed ? './?object=' . $_GET['object'] . '&action=delete_comment&id=' . $comment_info['id'] . _add_get(['page']) : '', 'current_link' => './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&id=' . $_GET['id'] . '#cid_' . $comment_info['id'], 'reput_text' => is_object($REPUT_OBJ) && isset($users_names[$comment_info['user_id']]) ? $REPUT_OBJ->_show_for_user($comment_info['user_id'], $users_reput_info[$comment_info['user_id']], false, ['comments', $comment_info['id']]) : '', 'id' => $comment_info['id'], 'comment_margin_left' => $level * 30];
         $items .= tpl()->parse($STPL_NAME_ITEM, $replace2);
     }
     if (!empty(main()->USER_ID)) {
         $add_comment_form = $this->_add($params);
     } else {
         $add_comment_form = '';
     }
     if ($params['allow_guests_posts']) {
         $add_comment_form = $this->_add($params);
     }
     $replace = ['comments' => $items, 'comments_pages' => $pages, 'num_comments' => intval($total), 'add_comment_form' => $add_comment_form, 'login_link' => empty(main()->USER_ID) && MAIN_TYPE_USER ? './?object=login_form&go_url=' . $OBJECT_NAME . ';' . $_GET['action'] . ';id=' . $OBJECT_ID : '', 'add_comment_action' => $FORM_ACTION];
     return tpl()->parse($STPL_NAME_MAIN, $replace);
 }
Esempio n. 8
0
 /**
  * Get related content
  *
  * @exmaple
  *	$data = common()->related_content(array(
  *		'action'		=> 'fetch', // Action: sql, fetch, stpl
  *		'source_array'	=> $post_info, // array to analyze title and text from
  *		'table_name'	=> db('blog_posts'), // database table name to query
  *		'fields_return'	=> 'id, user_id, add_date, title, text, privacy', // array or string of fields to return in resultset
  *		'field_id'		=> 'id',
  *		'field_date'	=> 'add_date',
  *		'field_title'	=> 'title',
  *		'field_text'	=> 'text',
  *		'where'			=> 'user_id='.intval($post_info['user_id']), // custom WHERE condition will be added to query
  *	));
  *
  */
 function _process($params = [])
 {
     // THESE ARE REQUIRED!
     $SOURCE_ARRAY = $params['source_array'];
     $TABLE_NAME = $params['table_name'];
     // Missing required params
     if (!$SOURCE_ARRAY) {
         trigger_error('RELATED: empty params[source_array]', E_USER_WARNING);
         return false;
     }
     $WHAT_TO_RETURN = $params['action'] && in_array($params['action'], ['sql', 'fetch', 'stpl']) ? $params['action'] : $this->DEF_PARAMS['WHAT_TO_RETURN'];
     $FIELD_ID = $params['field_id'] ? _es($params['field_id']) : $this->DEF_PARAMS['FIELD_ID'];
     $FIELD_DATE = $params['field_date'] ? _es($params['field_date']) : $this->DEF_PARAMS['FIELD_DATE'];
     $FIELD_USER = $params['field_user'] ? _es($params['field_user']) : $this->DEF_PARAMS['FIELD_USER'];
     $FIELD_TITLE = $params['field_title'] ? _es($params['field_title']) : $this->DEF_PARAMS['FIELD_TITLE'];
     $FIELD_TEXT = $params['field_text'] ? _es($params['field_text']) : $this->DEF_PARAMS['FIELD_TEXT'];
     $FIELD_SCORE = $params['field_score'] ? _es($params['field_score']) : $this->DEF_PARAMS['FIELD_SCORE'];
     // Additional fields for fulltext searching
     $FIELD_ADD_1 = $params['field_add_1'] ? _es($params['field_add_1']) : $this->DEF_PARAMS['FIELD_ADD_1'];
     $FIELD_ADD_2 = $params['field_add_2'] ? _es($params['field_add_2']) : $this->DEF_PARAMS['FIELD_ADD_2'];
     // Title or text is required
     if ((!$FIELD_TITLE || $FIELD_TITLE == -1) && (!$FIELD_TEXT || $FIELD_TEXT == -1)) {
         trigger_error('RELATED: no title and text fields specified', E_USER_WARNING);
         return false;
     }
     $FIELDS_RETURN = $params['fields_return'] ? $this->_prepare_fields_param($params['fields_return']) : '';
     if (!$FIELDS_RETURN) {
         $FIELDS_RETURN[] = $FIELD_ID;
         if ($FIELD_DATE && $FIELD_DATE != -1) {
             $FIELDS_RETURN[] = $FIELD_DATE;
         }
         if ($FIELD_USER && $FIELD_USER != -1) {
             $FIELDS_RETURN[] = $FIELD_USER;
         }
         if ($FIELD_TITLE && $FIELD_TITLE != -1) {
             $FIELDS_RETURN[] = $FIELD_TITLE;
         }
         if ($FIELD_TEXT && $FIELD_TEXT != -1) {
             $FIELDS_RETURN[] = $FIELD_TEXT;
         }
         if ($FIELD_ADD_1 && $FIELD_ADD_1 != -1) {
             $FIELDS_RETURN[] = $FIELD_ADD_1;
         }
         if ($FIELD_ADD_2 && $FIELD_ADD_2 != -1) {
             $FIELDS_RETURN[] = $FIELD_ADD_2;
         }
         $FIELDS_RETURN[] = $FIELD_SCORE;
     }
     $WHERE_COND = $params['where'] ? $params['where'] : '';
     // Not checked. Be careful with this!
     $PAST_ONLY = $params['past_only'] ? intval((bool) $params['past_only']) : $this->DEF_PARAMS['PAST_ONLY'];
     if (!$FIELD_DATE || $FIELD_DATE == -1) {
         $PAST_ONLY = false;
     }
     $RECORDS_LIMIT = $params['limit'] ? intval($params['limit']) : $this->DEF_PARAMS['RECORDS_LIMIT'];
     $ORDER_BY = $params['order_by'] ? _es($params['order_by']) : $FIELD_SCORE . ' DESC';
     $STPL_NAME = $params['stpl_name'] ? $params['stpl_name'] : $this->DEF_PARAMS['STPL_NAME'];
     $THRESHOLD = $params['thold'] ? intval($params['thold']) : $this->DEF_PARAMS['THRESHOLD'];
     $WEIGHT_TEXT = $params['weight_body'] ? intval($params['weight_body']) : $this->DEF_PARAMS['WEIGHT_TEXT'];
     $WEIGHT_TITLE = $params['weight_title'] ? intval($params['weight_title']) : $this->DEF_PARAMS['WEIGHT_TITLE'];
     // Additional fields
     $WEIGHT_ADD_1 = $params['weight_add_1'] ? intval($params['weight_add_1']) : $this->DEF_PARAMS['WEIGHT_ADD_1'];
     $WEIGHT_ADD_2 = $params['weight_add_2'] ? intval($params['weight_add_2']) : $this->DEF_PARAMS['WEIGHT_ADD_2'];
     // TODO: complete these
     $WEIGHT_TAG = $params['weight_tag'] ? intval($params['weight_tag']) : $this->DEF_PARAMS['WEIGHT_TAG'];
     $WEIGHT_CAT = $params['weight_cat'] ? intval($params['weight_cat']) : $this->DEF_PARAMS['WEIGHT_CAT'];
     // PARSE PARAMS END
     $WEIGHT_TOTAL = $WEIGHT_TEXT + $WEIGHT_TITLE + $WEIGHT_TAG + $WEIGHT_CAT;
     $WEIGHTED_THOLD = $THRESHOLD / ($WEIGHT_TOTAL + 0.1);
     $keywords_text = '';
     if ($FIELD_TEXT && $FIELD_TEXT != -1) {
         $keywords_text = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_TEXT]);
     }
     $keywords_title = '';
     if ($FIELD_TITLE && $FIELD_TITLE != -1) {
         $keywords_title = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_TITLE]);
     }
     $keywords_add_1 = '';
     if ($FIELD_ADD_1 && $FIELD_ADD_1 != -1) {
         $keywords_add_1 = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_ADD_1]);
     }
     $keywords_add_2 = '';
     if ($FIELD_ADD_2 && $FIELD_ADD_2 != -1) {
         $keywords_add_2 = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_ADD_2]);
     }
     // Keywords required
     if (!strlen($keywords_text) && !strlen($keywords_title) && !strlen($keywords_add_1) && !strlen($keywords_add_2)) {
         return false;
     }
     // Prepare fields to return as string for SQL
     $_tmp = [];
     foreach ((array) $FIELDS_RETURN as $k => $v) {
         $_tmp[$k] = db()->escape_key($v);
     }
     $fields_to_return_sql = implode(', ', $_tmp);
     unset($_tmp);
     $now = time();
     // TODO
     $cats = '';
     $tags = '';
     $sql = "SELECT *, ( \n\t\t\t\tscore_text\t* " . $WEIGHT_TEXT . " \n\t\t\t\t" . (strlen($keywords_title) ? " + score_title\t* " . $WEIGHT_TITLE : "") . "\n\t\t\t\t" . (strlen($keywords_add_1) ? " + score_add_1\t* " . $WEIGHT_ADD_1 : "") . "\n\t\t\t\t" . (strlen($keywords_add_2) ? " + score_add_2\t* " . $WEIGHT_ADD_2 : "") . "\n\t\t\t\t" . ($tags ? " + score_tag\t* " . $WEIGHT_TAG : "") . "\n\t\t\t\t" . ($cats ? " + score_cat\t* " . $WEIGHT_CAT : "") . "\n\t\t\t) AS " . $FIELD_SCORE . " \n\n\t\t\tFROM ( \n\t\t\t\tSELECT " . ($fields_to_return_sql ? $fields_to_return_sql : "1") . "\n\t\t\t\t\t, " . (strlen($keywords_text) ? "(MATCH (" . $FIELD_TEXT . ") AGAINST ('" . _es($keywords_text) . "' IN BOOLEAN MODE))" : "0") . " AS score_text \n\t\t\t\t\t" . (strlen($keywords_title) ? ", (MATCH (" . $FIELD_TITLE . ") AGAINST ('" . _es($keywords_title) . "' IN BOOLEAN MODE)) AS score_title " : "") . "\n\t\t\t\t\t" . (strlen($keywords_add_1) ? ", (MATCH (" . $FIELD_ADD_1 . ") AGAINST ('" . _es($keywords_add_1) . "' IN BOOLEAN MODE)) AS score_add_1 " : "") . "\n\t\t\t\t\t" . (strlen($keywords_add_2) ? ", (MATCH (" . $FIELD_ADD_2 . ") AGAINST ('" . _es($keywords_add_2) . "' IN BOOLEAN MODE)) AS score_add_2 " : "") . "\n\t\t\t\t\t" . ($tags ? ", IFNULL(0/*score_tag*/,0) AS score_tag " : "") . "\n\t\t\t\t\t" . ($cats ? ", IFNULL(0/*score_cat*/,0) as score_cat " : "") . "\n\t\t\t\tFROM " . $TABLE_NAME . " \n\t\t\t\tWHERE " . ($WHERE_COND ? $WHERE_COND : "1") . " \n\t\t\t\t\tAND " . $FIELD_ID . " != " . intval($SOURCE_ARRAY[$FIELD_ID]) . ($PAST_ONLY ? " AND " . $FIELD_DATE . " <= '" . $now . "' " : ' ') . ") AS rawscores \n\n\t\t\tWHERE ( \n\t\t\t\tscore_text\t* " . $WEIGHT_TEXT . "\n\t\t\t\t" . (strlen($keywords_title) ? " + score_title\t* " . $WEIGHT_TITLE : "") . "\n\t\t\t\t" . (strlen($keywords_add_1) ? " + score_add_1 * " . $WEIGHT_ADD_1 : "") . "\n\t\t\t\t" . (strlen($keywords_add_2) ? " + score_add_2 * " . $WEIGHT_ADD_2 : "") . "\n\t\t\t\t" . ($tags ? " + score_tag\t* " . $WEIGHT_TAG : "") . "\n\t\t\t\t" . ($cats ? " + score_cat\t* " . $WEIGHT_CAT : "") . "\n\t\t\t) >= " . $THRESHOLD . "\n\n\t\t\tORDER BY " . $ORDER_BY . " \n\n\t\t\tLIMIT " . $RECORDS_LIMIT;
     // Special for the db_installer (allows to easily restore if not exists FULLTEXT INDEX on used fields)
     $fulltext_needed_for = [];
     if (strlen($keywords_text)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_TEXT;
     }
     if (strlen($keywords_title)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_TITLE;
     }
     if (strlen($keywords_add_1)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_ADD_1;
     }
     if (strlen($keywords_add_2)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_ADD_2;
     }
     conf('fulltext_needed_for', $fulltext_needed_for);
     // Try to pretty format SQL with missing lines
     $sql = str_replace(["\r", "\n\t\t\t\t\t\n", "\n\t\t\t\t\n", "\n\t\t\t\n"], "\n", $sql);
     $sql = str_replace(["\n\n\n", "\n\n"], "\n", $sql);
     // RETURN RESULT HERE
     if ($WHAT_TO_RETURN == 'sql') {
         return $sql;
     }
     if ($WHAT_TO_RETURN == 'fetch') {
         return db()->query_fetch_all($sql, $FIELD_ID);
     }
     if ($WHAT_TO_RETURN == 'stpl') {
         $data = db()->query_fetch_all($sql, $FIELD_ID);
         if (!$data) {
             return '';
         }
         // Get users infos
         if ($FIELD_USER && $FIELD_USER != -1) {
             $users_ids = [];
             foreach ((array) $data as $k => $v) {
                 if ($v[$FIELD_USER]) {
                     $users_ids[$v[$FIELD_USER]] = $v[$FIELD_USER];
                 }
             }
             if (!empty($users_ids)) {
                 $users_infos = user($users_ids);
             }
         }
         foreach ((array) $data as $k => $v) {
             $data2[$k] = ['id' => intval($v[$FIELD_ID]), 'date' => _format_date($v[$FIELD_DATE]), 'title' => _prepare_html($v[$FIELD_TITLE]), 'text' => _prepare_html(_substr($v[$FIELD_TEXT], 0, 200)), 'add_1' => _prepare_html(_substr($v[$FIELD_ADD_1], 0, 200)), 'add_2' => _prepare_html(_substr($v[$FIELD_ADD_2], 0, 200)), 'user_id' => intval($v[$FIELD_USER]), 'user_name' => _prepare_html(_display_name($users_infos[$v[$FIELD_USER]])), 'profile_link' => _profile_link($v[$FIELD_USER]), 'score' => _prepare_html($v[$FIELD_SCORE]), 'href' => process_url('./?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&id=' . intval($v[$FIELD_ID]))];
         }
         $replace = ['data' => $data2, 'source' => _prepare_html($SOURCE_ARRAY)];
         return tpl()->parse($STPL_NAME, $replace);
     }
 }
Esempio n. 9
0
 function _show_avatar($user_id = 0, $user_name = '', $as_link = 0, $is_middle = 0, $only_img_src = 0, $force_link = '')
 {
     if (is_array($user_name)) {
         $user_info = $user_name;
         $user_name = _display_name($user_info);
     }
     $avatar_path = _gen_dir_path($user_id, INCLUDE_PATH . SITE_AVATARS_DIR, 0, 0777) . intval($user_id) . ($is_middle ? '_m' : '') . '.jpg';
     $photo_src = file_exists($avatar_path) && filesize($avatar_path) ? str_replace(INCLUDE_PATH, WEB_PATH, $avatar_path) : '';
     if ($only_img_src) {
         return !empty($photo_src) ? $photo_src : '';
     }
     $use_ajax = conf('no_ajax_here') ? 0 : 1;
     if (conf('HIGH_CPU_LOAD') == 1) {
         $use_ajax = 0;
     }
     $replace = ['user_name' => $user_name, 'custom_title' => _prepare_html(conf('avatar_custom_title')), 'user_id' => $user_id, 'photo_src' => $photo_src, 'user_details_link' => !empty($force_link) ? process_url($force_link) : _profile_link(is_array($user_info) ? $user_info : $user_id, null, MAIN_TYPE_ADMIN ? 1 : 0), 'as_link' => intval((bool) $as_link), 'is_middle' => intval((bool) $is_middle), 'no_photo_small' => !$is_middle && empty($photo_src), 'no_photo_middle' => $is_middle && empty($photo_src), 'use_ajax' => intval($use_ajax)];
     $body = tpl()->parse('avatar_img', $replace);
     return str_replace(["\r", "\n", "\t"], '', trim($body));
 }