Example #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);
 }
 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);
 }
 /**
  * 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);
 }
Example #4
0
 /**
  * Do check if user is banned for some reason
  * 
  * @access	public
  * @param	array	Array of fields to check
  * @param	array	User info (optional)
  * @return
  */
 function _check($input = [], $user_info = [])
 {
     // Default banned status
     $BANNED_STATUS = false;
     // Nothing to check
     if (empty($input) || empty($input["user_id"])) {
         return $BANNED_STATUS;
     }
     // Default user ban fields
     $ban_fields = ["ban_ads" => 0, "ban_reviews" => 0, "ban_images" => 0, "ban_email" => 0, "ban_forum" => 0, "ban_comments" => 0, "ban_blog" => 0, "ban_bad_contact" => 0, "ban_reput" => 0];
     // Start process ban checks
     foreach ((array) $this->BAN_CHECKS as $CUR_CHECKS) {
         // Process input fields
         foreach ((array) $input as $input_name => $input_value) {
             // Switch between active checks
             $WHAT_FOUND = $this->_try_to_find($input_name, $CUR_CHECKS, $input_value);
             if (!$WHAT_FOUND) {
                 continue;
             }
             // Process ban status if found one
             $BANNED_STATUS = true;
             // Try to find ban reasons
             foreach ((array) $ban_fields as $ban_name => $ban_value) {
                 // User already banned for this type
                 if ($ban_value == 1 || empty($CUR_CHECKS[$ban_name])) {
                     continue;
                 }
                 // Else - do ban current type
                 $ban_fields[$ban_name] = 1;
                 $ban_reasons[$input_name] = $WHAT_FOUND;
             }
         }
     }
     // Create SQL query for the user table
     $sql3 = [];
     foreach ((array) $ban_fields as $ban_name => $new_ban_value) {
         // No need to change ban status
         if ($new_ban_value == 0) {
             continue;
         }
         // Check if this ban type is already banned for the current user
         if (!empty($user_info) && $user_info[$ban_name] == $new_ban_value) {
             continue;
         }
         // Do add SQL for the update query
         $sql3[] = " " . _es($ban_name) . "='1' ";
     }
     // Do update user's table (if needed)
     if (!empty($sql3)) {
         $NEW_ADMIN_COMMENTS = "\r\n==============\r\nAuto-banned on " . _format_date(time()) . " (action: " . $_GET["object"] . "->" . $_GET["action"] . "; " . implode(",", $ban_reasons) . ")";
         $sql4 = "UPDATE " . db('user') . " SET \n\t\t\t\t\t" . implode(",", $sql3) . ", \n\t\t\t\t\tadmin_comments = CONCAT(admin_comments, '" . _es($NEW_ADMIN_COMMENTS) . "')\n\t\t\t\tWHERE id=" . intval($input["user_id"]);
         db()->query($sql4);
     }
     return $BANNED_STATUS;
 }
 /**
  */
 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;
 }
Example #6
0
    public function home()
    {
        global $core;
        $v = $this->__(array('a', 'p' => 0));
        if (f($v['a'])) {
            $sql = 'SELECT area_id
				FROM _reference_area
				WHERE area_alias = ?';
            if (!_field(sql_filter($sql, $v['a']), 'area_id', 0)) {
                _fatal();
            }
            $sql = 'SELECT COUNT(r.ref_id) AS total
				FROM _reference r, _reference_area a
				WHERE a.area_alias = ?
					AND r.ref_area = a.area_id
				ORDER BY r.ref_time DESC';
            $ref_total = _field(sql_filter($sql, $v['a']), 'total', 0);
            $sql = 'SELECT *
				FROM _reference r, _reference_area a
				WHERE a.area_alias = ?
					AND r.ref_area = a.area_id
				ORDER BY r.ref_time DESC
				LIMIT ??, ??';
            $ref = _rowset(sql_filter($sql, $v['a'], $v['p'], $core->v('ref_pages')));
        } else {
            $sql = 'SELECT COUNT(ref_id) AS total
				FROM _reference
				ORDER BY ref_time DESC';
            $ref_total = _field($sql, 'total', 0);
            $sql = 'SELECT *
				FROM _reference r, _reference_area a
				WHERE r.ref_area = a.area_id
				ORDER BY r.ref_time DESC
				LIMIT ??, ??';
            $ref = _rowset(sql_filter($sql, $v['p'], $core->v('ref_pages')));
        }
        if ($v['p'] && $ref_total) {
            redirect(_link());
        } else {
            _style('noref');
        }
        foreach ($ref as $i => $row) {
            if (!$i) {
                _style('ref');
            }
            if ($this->has_plugin($row['ref_content'])) {
                $this->parse_plugin($row);
                continue;
            }
            _style('ref.row', _vs(array('id' => $row['ref_id'], 'link' => _link($row['ref_alias']), 'subject' => $row['ref_subject'], 'content' => _message($row['ref_content']), 'time' => _format_date($row['ref_time'])), 'ref'));
        }
        return;
    }
Example #7
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);
 }
Example #8
0
    public function home()
    {
        $now = time();
        $sql = 'SELECT *
			FROM _contest
			WHERE contest_start > ??
				AND contest_end < ??
			ORDER BY contest_start';
        $contest = sql_rowset(sql_filter($sql, $now, $now));
        foreach ($contest as $i => $row) {
            if (!$i) {
                _style('contest');
            }
            _style('contest.row', array('URL' => _link('contest', $row->contest_alias), 'SUBJECT' => $row->contest_subject, 'END' => _format_date($row->contest_end)));
        }
        return;
    }
Example #9
0
    public function home()
    {
        $cols = w('Email Nickname Cumplea&ntilde;os Pa&iacute;s');
        $sql = 'SELECT user_email, user_username, user_birthday, country_name
			FROM _members m, _countries c
			WHERE m.user_type = ?
				AND m.user_country = c.country_id
			ORDER BY m.user_username';
        $members = _rowset(sql_filter($sql, 1));
        foreach ($members as $i => $rowm) {
            if (!$i) {
                _style('table');
                foreach ($cols as $j => $field) {
                    if (!$j) {
                        _style('table.head', array('TITLE' => '#'));
                    }
                    _style('table.head', array('TITLE' => $field));
                }
            }
            _style('table.row');
            $j = 0;
            foreach ($rowm as $f => $row) {
                if (!$j) {
                    _style('table.row.col', array('VALUE' => $i + 1));
                }
                switch ($f) {
                    case 'user_birthday':
                        $row_year = substr($row, 0, 4);
                        $row_month = substr($row, 4, 2);
                        $row_day = substr($row, 6, 2);
                        $row = _format_date(_timestamp($row_month, $row_day, $row_year), 'd F Y');
                        break;
                }
                _style('table.row.col', array('VALUE' => $row));
                $j++;
            }
        }
        return;
    }
Example #10
0
    protected function _view_home()
    {
        global $core, $bio;
        $v = $this->__(array('alias', 't' => 0, 'p' => 0));
        if (!f($v['alias'])) {
            _fatal();
        }
        $v['field'] = !is_numb($v['alias']) ? 'alias' : 'id';
        $sql = 'SELECT *
			FROM _events
			WHERE event_?? = ?';
        if (!($event = _fieldrow(sql_filter($sql, $v['field'], $v['alias'])))) {
            _fatal();
        }
        if ($v['field'] == 'id' && f($event['event_alias'])) {
            redirect(_link($this->m(), $event['event_alias']) . _linkp(array('t' => $v['t'], 'p' => $v['p']), true));
        }
        // Get images
        $sql = 'SELECT *
			FROM _events_images
			WHERE image_event = ?
			ORDER BY image ASC
			LIMIT ??, ??';
        $event_images = _rowset(sql_filter($sql, $event['event_id'], $v['t'], $core->v('thumbs_per_page')));
        foreach ($event_images as $i => $row) {
            if (!$i) {
                _style('thumbnails', _pagination(_link($this->m(), $event['event_alias']), 't:%d', $event['event_images'], $core->v('thumbs_per_page'), $v['t']));
            }
            _style('thumbnails.row', array('U_THUMBNAIL' => _lib(w(LIB_EVENT . ' thumbnail ' . $event['event_id'], $row['image'], 'jpg')), 'U_IMAGE' => _lib(w(LIB_EVENT . ' gallery ' . $event['event_id'], $row['image'], 'jpg')), 'V_FOOTER' => $row['image_footer']));
        }
        if (is_ghost()) {
            return;
        }
        // Statistics
        if (!$v['t'] && !$bio->v('auth_founder')) {
            $this->_stats_store();
        }
        $is_future = $row['event_end'] > time() ? true : false;
        if (!$is_future) {
            // Star for favourites
            if (!($star_type = $core->cache_load('star_type'))) {
                $sql = 'SELECT type_id, type_name
					FROM _events_star_type
					ORDER BY type_order';
                $types = $core->cache_store('star_type', _rowset($sql, 'type_id', 'type_name'));
            }
            $i = 0;
            foreach ($types as $type_id => $type_name) {
                if (!$i) {
                    _style('star_type');
                }
                _style('star_type.row', array('TYPE_ID' => $type_id, 'TYPE_NAME' => $type_name));
                $i++;
            }
        } else {
            $sql = 'SELECT *
				FROM _events_reviews r, _bio b
				WHERE r.review_event = ?
					AND r.review_uid = b.bio_id
				ORDER BY r.review_avg
				LIMIT 0, 5';
            $reviews = _rowset(sql_filter($sql, $event['event_id']), 'review_id');
            $sql = 'SELECT *
				FROM _events_reviews_rate r, _events_reviews_fields f
				WHERE r.rate_review IN (??)
					AND r.rate_field = f.field_id
				ORDER BY f.field_order';
            $reviews_rate = _rowset(sql_filter($sql, _implode(',', array_keys($reviews))), 'rate_review', false, true);
            $i = 0;
            foreach ($reviews as $row) {
                if (!$i) {
                    _style('reviews');
                }
                _style('reviews.row', array('REVIEW_CONTENT' => $row['review_content'], 'REVIEW_' => $row['review_']));
                if (isset($reviews_rate[$row['review_id']])) {
                    foreach ($reviews_rate[$row['review_id']] as $j => $rate) {
                        if (!$j) {
                            _style('reviews.row.rate');
                        }
                        _style('reviews.row.rate.field', array('FIELD' => $rate['field_name'], 'RATE' => $rate['rate_value']));
                    }
                }
                $i++;
            }
        }
        // Who attend
        $sql = 'SELECT at.type_id, at.type_name_next, at.type_name_prev, b.bio_alias, b.bio_name, b.bio_avatar, b.bio_avatar_up
			FROM _events_attend a, _events_attend_type at, _bio b
			WHERE a.attend_event = ?
				AND a.attend_type = at.type_id
				AND a.attend_uid = b.bio_id
			ORDER BY a.attend_time';
        $attend = _rowset(sql_filter($sql, $event['event_id']), 'type_id', false, true);
        $i = 0;
        foreach ($attend as $type_name => $rows) {
            if (!$i) {
                _style('attend');
            }
            $type_name = $is_future ? 'next' : 'prev';
            _style('attend.type', array('TYPE_NAME' => $rows[0]['type_name_' . $type_name]));
            foreach ($rows as $row) {
                _style('attend.type.row', array('BIO_NAME' => $row['bio_name'], 'BIO_AVATAR' => _avatar($row)));
            }
            $i++;
        }
        // Messages
        $ref = _link('events', $event['event_alias']);
        if ($event['event_publish']) {
            if ($event['event_comments']) {
                $sql = 'SELECT c.comment_id, c.comment_time, c.comment_text, b.bio_id, b.bio_alias, b.bio_name, b.bio_avatar, b.bio_avatar_up
					FROM _events_comments c, _bio b
					WHERE c.comment_event = ?
						AND c.comment_active = ?
						AND c.comment_bio = b.bio_id
					ORDER BY c.comment_time DESC
					LIMIT ??, ??';
                $comments = _rowset(sql_filter($sql, $event['event_id'], 1, $v['p'], $core->v('events_comments')));
                foreach ($comments as $i => $row) {
                    if (!$i) {
                        _style('comment_area', _pagination(_link($this->m(), array($event['event_alias'], $v['t'], 's%d')), $topic_data['topic_replies'] + 1, $core->v('posts_per_page'), $start));
                    }
                    _style('comment_area.row', array('BIO_ALIAS' => _link_bio($row['bio_alias']), 'BIO_NAME' => $row['bio_name'], 'BIO_AVATAR' => _avatar($row), 'COMMENT_ID' => $row['comment_id'], 'COMMENT_TIME' => _format_date($row['comment_time']), 'COMMENT_TEXT' => _message($row['comment_text'])));
                }
            }
            _style('comment_publish', array('U_PUBLISH' => _link()));
        }
        //
        if ($event['event_posts']) {
            $reply = array('ref' => $ref, 'start' => $v['p'], 'start_f' => 's', 'rows' => $event['event_posts'], 'rows_page' => $core->v('s_posts'), 'block' => 'posts', 'sql' => 'SELECT p.post_id, p.post_time, p.post_text, b.bio_id, b.bio_alias, b.bio_name, b.bio_avatar, b.bio_avatar_up, b.bio_sig
					FROM _events_posts p, _bio b
					WHERE p.post_event = ?
						AND p.post_active = 1 
						AND p.post_uid = b.bio_id
					ORDER BY p.post_time DESC
					LIMIT {START}, {ROWS_PAGE}');
            $reply['sql'] = sql_filter($reply['sql'], $event['event_id']);
            $this->_replies($reply);
        }
        v_style(_vs(array('SUBJECT' => $event['event_subject'], 'IMAGES' => $event['event_images'], 'START' => _format_date($event['event_start'], 'd F Y'), 'END' => _format_date($event['event_end'], 'd F Y'), 'COMMENTS' => $event['event_posts']), 'event'));
        return;
    }
Example #11
0
 /**
  */
 function date($name, $desc = '', $extra = [])
 {
     if (is_array($desc)) {
         $extra = (array) $extra + $desc;
         $desc = '';
     }
     if (!$desc) {
         $desc = ucfirst(str_replace('_', ' ', $name));
     }
     $this->_fields[] = ['type' => __FUNCTION__, 'name' => $name, 'extra' => $extra, 'desc' => $desc, 'func' => function ($field, $params, $row, $instance_params, $table) {
         $extra = $params['extra'];
         $text = str_replace(' ', '&nbsp;', _format_date($field, $extra['format']));
         return $table->_apply_badges($text, $extra, $field);
     }];
     return $this;
 }
Example #12
0
function industries_ajax_newsgroup2()
{
    if (isset($_GET['p'])) {
        $resultPerPage = 10;
        if (isset($_GET['view']) && $_GET['view'] == 'news') {
            $resultPerPage = 20;
        }
        $page = $_GET['p'];
        $start = $page * $resultPerPage;
        $db = _db();
        $db->prepare('SELECT SQL_CALC_FOUND_ROWS news_id, news_title, news_created FROM _prefix_news WHERE parent_id=3 AND is_category=0 ORDER BY news_created DESC LIMIT :OFFSET,' . $resultPerPage);
        $db->bindValue(':OFFSET', $start, PARAM_INT);
        $db->execute();
        if ($result = $db->fetchAll()) {
            for ($i = 0; $i < count($result); $i++) {
                $result[$i]['news_created'] = _format_date($result[$i]['news_created']);
            }
            return json_encode($result);
        }
    }
    return json_encode(false);
}
Example #13
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);
     }
 }
Example #14
0
 protected final function _replies($f)
 {
     global $bio;
     $rf_k = $rf_v = w();
     foreach ($f as $k => $v) {
         $rf_k[] = '{' . strtoupper($k) . '}';
     }
     $rf_v = array_values($f);
     $f['sql'] = str_replace($rf_k, $rf_v, $f['sql']);
     if (!($rows = _rowset($f['sql']))) {
         return;
     }
     // TODO: Control Panel. Modify & remove comments
     $bio = w();
     foreach ($rows as $i => $row) {
         if (!$i) {
             _style($f['block'], _vs(_pagination($f['ref'], $f['start_f'] . ':%d', $f['rows'], $f['rows_page'], $f['start'])));
         }
         $uid = $row['bio_id'];
         $row['is_member'] = $uid != 1 ? 1 : 0;
         if (!isset($bio[$uid]) || !$row['is_member']) {
             $bio[$uid] = $this->_profile($row);
         }
         $s_row = array('V_MEMBER' => $row['is_member'], 'V_TIME' => _format_date($row['post_time']), 'V_MESSAGE' => _message($row['post_text']));
         _style($f['block'] . '.row', array_merge($s_row, _vs($bio[$uid], 'v')));
     }
     return;
 }
Example #15
0
 /**
  * Welcome message method
  */
 function show_welcome()
 {
     // For authorized admins only
     if (MAIN_TYPE_ADMIN) {
         $login_time = $_SESSION['admin_login_time'];
         $admin_id = (int) main()->ADMIN_ID;
         $admin_group = (int) main()->ADMIN_GROUP;
         if ($admin_id && $admin_group) {
             $admin_info = db()->query_fetch('SELECT * FROM ' . db('admin') . ' WHERE id=' . $admin_id);
             $admin_groups = main()->get_data('admin_groups');
             $body .= tpl()->parse('system/admin_welcome', ['id' => intval($admin_id), 'name' => _prepare_html($admin_info['first_name'] . ' ' . $admin_info['last_name']), 'group' => _prepare_html(t($admin_groups[$admin_group])), 'time' => _format_date($login_time), 'edit_link' => './?object=admin_account']);
             if ($_SESSION['admin_prev_info']) {
                 $body .= '<li><a href="./?task=login&id=prev_info"><i class="icon icon-arrow-up fa fa-arrow-up"></i> ' . t('Login back') . '</a></li>';
             }
         }
         // For authorized users only
     } elseif (MAIN_TYPE_USER) {
         $login_time = $_SESSION['user_login_time'];
         $user_id = (int) main()->USER_ID;
         $user_group = (int) main()->USER_GROUP;
         if ($user_id && $user_group) {
             $user_info = user($user_id);
             $user_groups = main()->get_data('user_groups');
             $body .= tpl()->parse('system/user_welcome', ['id' => intval($user_info['id']), 'name' => _prepare_html(_display_name($user_info)), 'group' => _prepare_html(t($user_groups[$user_group])), 'time' => _format_date($login_time), 'user_info' => $user_info]);
         }
     }
     return $body;
 }
Example #16
0
    /**
     */
    function media_objects($data = [], $extra = [])
    {
        $extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
        if ($data) {
            $data = $this->_recursive_sort_items($data);
        }
        $img_class = ($extra['img_class'] ?: 'media-object') . ($extra['img_class_add'] ? ' ' . $extra['img_class_add'] : '');
        $keys = array_keys($data);
        $keys_counter = array_flip($keys);
        $items = [];
        foreach ((array) $data as $id => $item) {
            $next_id = $keys[$keys_counter[$id] + 1];
            $next_item = $next_id ? $data[$next_id] : [];
            $close_num_levels = 1;
            if ($next_item) {
                $close_num_levels = $item['level'] - $next_item['level'] + 1;
                if ($close_num_levels < 0) {
                    $close_num_levels = 0;
                }
            } elseif ($item['level'] > 0) {
                $close_num_levels = $item['level'] + 1;
            }
            $items[] = '
				<div class="media">
					<a class="pull-left"' . ($item['link'] ? ' href="' . $item['link'] . '"' : '') . '>' . '<img class="' . $img_class . '" alt="' . $item['alt'] . '" src="' . $item['img'] . '"' . ($item['img_width'] ? ' width="' . $item['img_width'] . '"' : '') . ($item['img_height'] ? ' height="' . $item['img_height'] . '"' : '') . '></a>
					<div class="media-body">
						<h4 class="media-heading">' . ($item['link'] ? '<a href="' . $item['link'] . '">' : '') . $item['head'] . ($item['link'] ? '</a>' : '') . ($item['date'] ? '&nbsp;<small class="pull-right">' . _format_date($item['date'], $extra['date_format'] ?: 'full') . '</small>' : '') . '</h4>' . $item['body'] . '
			';
            if ($close_num_levels) {
                $items[] = str_repeat(PHP_EOL . '</div></div>' . PHP_EOL, $close_num_levels);
            }
        }
        return '<div class="media-objects' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" id="' . $extra['id'] . '">' . implode(PHP_EOL, (array) $items) . '</div>';
    }
Example #17
0
 /**
  */
 function _prepare_invoice_body($order_id = false)
 {
     $_class_price = $this->_class_price;
     $_class_units = $this->_class_units;
     $_class_region = $this->_class_region;
     $_class_categories = $this->_class_categories;
     $_class_basket = $this->_class_basket;
     $_class_shop = $this->_class_shop;
     if ($order_id) {
         $order_info = db()->query_fetch('SELECT * FROM ' . db('shop_orders') . ' WHERE id=' . intval($order_id));
     }
     if (empty($order_info)) {
         return _e('No such order');
     }
     $id = (int) $order_info['id'];
     $Q = db_get_all('SELECT * FROM ' . db('shop_order_items') . ' WHERE order_id=' . $id);
     // while ($A = db()->fetch_assoc($Q)) {
     // $order_items[$A['product_id']] = $A;
     // }
     // Get products from db
     $products_ids = [];
     // type: 0 - product; 1 - product set
     foreach ((array) $Q as $_id => $item) {
         $type = (int) $item['type'];
         $product_id = (int) $item['product_id'];
         if ($product_id) {
             $products_ids[$type][$product_id] = $product_id;
         }
     }
     $infos = [];
     if (!empty($products_ids[0])) {
         $ids = array_keys($products_ids[0]);
         $ids_sql = implode(',', $ids);
         $infos[0] = db()->query_fetch_all('SELECT * FROM ' . db('shop_products') . ' WHERE id IN(' . $ids_sql . ')');
         $_class_units = $this->_class_units;
         $products_units = $_class_units->get_by_product_ids($ids);
     }
     if (!empty($products_ids[1])) {
         $ids = array_keys($products_ids[1]);
         $ids_sql = implode(',', $ids);
         $infos[1] = db()->query_fetch_all('SELECT * FROM ' . db('shop_product_sets') . ' WHERE id IN(' . $ids_sql . ')');
     }
     $price_total = 0;
     // foreach ((array)$Q as $_info) {
     foreach ((array) $Q as $item) {
         $param_id = (int) $item['param_id'];
         $product_id = (int) $item['product_id'];
         $type = (int) $item['type'];
         $quantity = (int) $item['quantity'];
         $unit = (int) $item['unit'];
         $info =& $infos[$type][$product_id];
         $units = $unit > 0 ? $products_units[$product_id] : 0;
         // price
         // $price_one  = (float)$info[ 'price' ];
         $price_one = $_class_basket->_get_price_one($item);
         $price_item = $price_one * $quantity;
         $out['products'][] = ["product_name" => _prepare_html($info['name']), "product_units" => $units[$unit]['title'] ?: $this->default_unit, "product_price_one" => $_class_shop->_format_price($price_one), "product_quantity" => $quantity, "product_item_price" => $_class_shop->_format_price($price_item)];
         $price_total += $price_item;
     }
     foreach ((array) $order_info as $k => $v) {
         if (in_array($k, $this->order_address_fields) && !empty($v)) {
             $user_address[] = t($k) . ': ' . $v;
         }
     }
     // discount
     $discount = $order_info['discount'];
     $discount_add = $order_info['discount_add'];
     $_discount = $discount;
     $with_discount_add = isset($_GET['with_discount_add']);
     if ($with_discount_add) {
         $_discount += $discount_add;
     }
     $discount_price = $_class_price->apply_price($price_total, $_discount);
     $discount_price -= $price_total;
     // total string
     $total_sum = (double) $order_info['total_sum'];
     $num_to_str = common()->num2str($total_sum);
     // delivery
     $_class_delivery = _class('_shop_delivery', 'modules/shop/');
     $delivery_id = (int) $order_info['delivery_id'];
     $delivery_type = (int) $order_info['delivery_type'];
     $delivery_name = $_class_delivery->_get_name_by_id($delivery_type);
     $region = $_class_region->_get_user_region();
     $replace = ['id' => $id, 'total_sum' => $_class_shop->_format_price($total_sum), 'user_address' => implode(" / ", $user_address), 'date' => _format_date($order_info['date'], '%d.%m.%Y г.'), 'products' => $out['products'], 'region' => $region, 'delivery' => $_class_shop->_format_price(floatval($order_info['delivery_price'])), 'delivery_id' => $delivery_id, 'delivery_type' => $delivery_type, 'delivery_name' => $delivery_name, 'delivery_location' => $order_info['delivery_location'], 'discount' => $_class_shop->_format_price($discount_price), 'num_to_str' => $num_to_str];
     return [tpl()->parse('shop/invoice_css', $replace), tpl()->parse('shop/invoice_html', $replace)];
 }
Example #18
0
 /**
  */
 function _get_latest_auths()
 {
     asset('bfh-select');
     $user_id = main()->USER_ID;
     return table(db()->from('log_auth')->whereid($user_id, 'user_id')->order_by('date DESC'), ['condensed' => true, 'no_header' => true, 'pager_records_on_page' => 50, 'pager_num_records' => 50, 'no_pages' => 1])->func('date', function ($date) {
         return '<small>' . _format_date($date, 'long') . '</small>';
     }, ['nowrap' => true])->func('ip', function ($ip) {
         return html()->ip($ip);
     })->func('user_agent', function ($ua) {
         return '<small>' . $ua . '</small>';
     });
 }
Example #19
0
 /**
  * Show available backups and backuping form
  */
 function show_backup()
 {
     $backup_folder_path = INCLUDE_PATH . $this->BACKUP_PATH;
     if ($_FILES['import_file']['tmp_name']) {
         $import_data = file_get_contents($_FILES['import_file']['tmp_name']);
         file_put_contents($backup_folder_path . $_FILES['import_file']['name'], $import_data);
     }
     // Find all backups in backup folder
     $backup_files = _class('dir')->scan_dir($backup_folder_path, true, '/\\.(sql|gz)$/i');
     $_files_infos = [];
     if (!empty($backup_files)) {
         foreach ((array) $backup_files as $fpath) {
             $_files_infos[] = ['fpath' => $fpath, 'file_mtime' => filemtime($fpath), 'file_size' => filesize($fpath)];
         }
     }
     usort($_files_infos, [&$this, '_sort_by_date']);
     foreach ((array) $_files_infos as $_info) {
         $fpath = $_info['fpath'];
         $id = urlencode(basename($fpath));
         $replace2 = ['backup_date' => _format_date($_info['file_mtime'], 'long'), 'backup_fsize' => common()->format_file_size($_info['file_size']), 'backup_name' => basename($fpath), 'delete_url' => url('/@object/delete_backup/' . $id), 'restore_url' => url('/@object/restore/' . $id), 'download_url' => url('/@object/export_backup/' . $id)];
         $items .= tpl()->parse('@object/backup_item', $replace2);
     }
     // Show form
     $replace = ['items' => $items, 'form_action' => url('/@object/backup'), 'import_form_action' => url('/@object/show_backup'), 'error_message' => _e(), 'back_link' => url('/@object')];
     return tpl()->parse('@object/backup', $replace);
 }
Example #20
0
 /**
  */
 function show_old()
 {
     // Path to project.conf.php
     $proj_conf_path = INCLUDE_PATH . "project_conf.php";
     if ($this->SHOW_CUR_SETTINGS && $_SESSION["admin_group"] == 1) {
         // Current settings
         $replace2 = ["rewrite_mode" => (int) conf("rewrite_mode"), "output_caching" => (int) conf("output_caching"), "language" => _prepare_html(strtoupper(conf("language"))), "charset" => _prepare_html(strtoupper(conf("charset"))), "admin_email" => _prepare_html(conf("admin_email")), "mail_debug" => (int) conf("mail_debug"), "site_enabled" => (int) conf("site_enabled"), "settings_link" => $this->_url_allowed("./?object=settings")];
         $cur_settings = tpl()->parse($_GET["object"] . "/cur_settings", $replace2);
     } else {
         $this->DISPLAY_STATS = false;
     }
     if ($this->SHOW_GENERAL_INFO && $_SESSION["admin_group"] == 1) {
         $replace3 = ["php_ver" => phpversion(), "mysql_serv_ver" => db()->get_server_version(), "mysql_host_info" => db()->get_host_info(), "db_name" => DB_NAME, "db_size" => $admin_statistics_array["db_size"], "project_dir_size" => $admin_statistics_array["project_dir_size"]];
         $general_info = tpl()->parse($_GET["object"] . "/general_info", $replace3);
     }
     if ($this->DISPLAY_STATS) {
         $admin_statistics_array = cache_get($this->CACHE_NAME, $this->ADMIN_HOME_CACHE_TIME);
     }
     if ($this->DISPLAY_STATS && empty($admin_statistics_array)) {
         // General info
         $db_size = 0;
         $Q = db()->query("SHOW TABLE STATUS FROM " . DB_NAME . "");
         while ($A = db()->fetch_assoc($Q)) {
             $db_size += $A["Data_length"];
         }
         $admin_statistics_array["db_size"] = common()->format_file_size($db_size);
         $admin_statistics_array["project_dir_size"] = common()->format_file_size(_class("dir")->dirsize(INCLUDE_PATH));
         // Statistics
         $A = db()->query_fetch_all("SELECT * FROM " . db('user_groups') . " WHERE active='1'");
         $sql_parts[] = "SELECT 'total_users' AS '0', COUNT(id) AS '1' FROM " . db('user') . " WHERE active='1'";
         foreach ((array) $A as $V1) {
             $sql_parts[] = "SELECT 'total_" . strtolower($V1["name"]) . "' AS '0', COUNT(id) AS '1' FROM " . db('user') . " WHERE `group`='" . $V1["id"] . "' AND active='1'";
         }
         $sql_parts2 = ["SELECT 'forum_topics' AS '0', COUNT(id) AS '1' FROM " . db('forum_topics') . " WHERE 1=1", "SELECT 'forum_posts' AS '0', COUNT(id) AS '1' FROM " . db('forum_posts') . " WHERE 1=1", "SELECT 'gallery_photos' AS '0', COUNT(id) AS '1' FROM " . db('gallery_photos') . " WHERE 1=1", "SELECT 'blog_posts' AS '0', COUNT(id) AS '1' FROM " . db('blog_posts') . " WHERE 1=1", "SELECT 'articles' AS '0', COUNT(id) AS '1' FROM " . db('articles_texts') . " WHERE 1=1"];
         $sql_parts = array_merge($sql_parts, $sql_parts2);
         $sql = "(\r\n" . implode("\r\n) UNION ALL (\r\n", $sql_parts) . "\r\n)";
         $B = db()->query_fetch_all($sql);
         foreach ((array) $B as $V) {
             $admin_statistics_array[$V[0]] = $V[1];
         }
         cache_put($this->CACHE_NAME, $admin_statistics_array);
     }
     if ($this->DISPLAY_STATS) {
         $statistics = tpl()->parse($_GET["object"] . "/statistics", $admin_statistics_array);
     }
     $replace = ["proj_conf_link" => file_exists($proj_conf_path) ? "./?object=file_manager&action=edit_item&f_=" . basename($proj_conf_path) . "&dir_name=" . urlencode(dirname($proj_conf_path)) : "", "current_date" => _format_date(time(), "long"), "my_id" => $_SESSION["admin_id"], "cur_settings" => $cur_settings, "general_info" => $general_info, "statistics" => $statistics, "cache_time" => ceil($this->ADMIN_HOME_CACHE_TIME / 60), "custom_content" => $this->_custom_content(), "custom_content" => $this->_custom_content(), "suggests" => $this->_show_suggesting_messages()];
     return tpl()->parse($_GET["object"] . "/main", $replace);
 }
Example #21
0
    protected function _publish_home()
    {
        global $bio;
        $v = $this->__(w('address key subject content playing f 0 p 0'));
        // TODO: Implement bio authorization
        $this->_bio_publish($v->address, $v->key);
        //
        if (!$v->forum && !$v->post) {
            $warning->now();
        }
        if ($v->forum) {
            if (empty($v->subject)) {
                $this->_error('NO_TOPIC_SUBJECT');
            }
            $sql = 'SELECT *
				FROM _board_forums
				WHERE forum_id = ?';
            if (!($forum = sql_fieldrow(sql_filter($sql, $v->forum)))) {
                $warning->now();
            }
            $v->subject = _subject($v->subject);
        } else {
            $sql = 'SELECT *
				FROM _board_posts
				WHERE post_id = ?';
            if (!($post = sql_fieldrow(sql_filter($sql, $v->post)))) {
                $warning->now();
            }
            $sql = 'SELECT *
				FROM _board_topics
				WHERE topic_id = ?';
            if (!($topic = sql_fieldrow(sql_filter($sql, $post->post_topic)))) {
                $warning->now();
            }
        }
        if ($v->forum) {
            if ($forum->forum_locked && !$this->auth_forum($forum, 'create')) {
                $warning->now();
            }
        }
        if (empty($v->content)) {
            $this->_error('NO_TOPIC_CONTENT');
        }
        $v->content = _prepare($v->content);
        // Start insert transaction
        sql_transaction();
        $sql_commit = false;
        if ($v->forum) {
            // Insert topic
            $sql_insert = array('forum' => $v->forum, 'subject' => $v->subject, 'author' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'));
            $v->topic_next = sql_put('_board_topics', prefix('topic', $sql_insert));
            // Insert post
            $sql_insert = array('forum' => $v->forum, 'topic' => $v->topic_next, 'parent' => 0, 'bio' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'), 'message' => $v->content, 'playing' => $v->playing);
            $v->post_next = sql_put('_board_posts', prefix('post', $sql_insert));
            if ($v->topic_next && $v->post_next) {
                $sql_commit = true;
            }
        } else {
            $sql_insert = array('forum' => $topic->topic_forum, 'topic' => $topic->topic_id, 'parent' => $v->post, 'bio' => $bio->v('bio_id'), 'time' => time(), 'active' => $bio->v('bio_confirmed'), 'message' => $v->content, 'playing' => $v->playing);
            $v->post_next = sql_put('_board_posts', prefix('post', $sql_insert));
            $sql_update = w();
            $sql = 'UPDATE _board_topics SET topic_replies = topic_replies + 1' . sql_build('UPDATE', $sql_update) . sql_filter('
				WHERE topic_id = ?', $topic->topic_id);
            $updated = sql_affected($sql);
            if ($v->post_next && $updated) {
                $sql_commit = true;
            }
        }
        if (!$sql_commit) {
            sql_transaction('rollback');
            $this->_error('ROLLBACK_MESSAGE');
        }
        sql_transaction('commit');
        if (is_ghost() && $v->post) {
            if ($bio->v('bio_confirmed')) {
                $response = array('show' => 1, 'parent' => $v->post, 'post' => $v->post_next, 'content' => _message($v->content), 'time' => _format_date(), 'profile' => array('link' => _link_bio($bio->v('bio_alias')), 'name' => $bio->v('bio_name')));
            } else {
                $response = array('show' => 0, 'legend' => _lang('PUBLISH_TOPIC_GUEST'));
            }
            $this->output(json_encode($response));
        }
        return redirect(_link('board', array('topic', $v->topic)));
    }
Example #22
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);
 }
Example #23
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);
 }
Example #24
0
 /**
  * Default method
  */
 function show()
 {
     //		$this->SERVER_ID = intval($_GET["id"]);
     // Check if <dir_name> is inside <START_FOLDER>
     if ($this->GET_PATH) {
         $dir_name = $this->_urldecode($this->GET_PATH);
     } else {
         $dir_name = $this->START_DIR;
     }
     $dir_name = $this->_prepare_path($dir_name);
     $dir_contents = $this->SSH_OBJ->scan_dir($this->_server_info, $dir_name, "", "/\\.(svn|git)/ims", 0);
     if (is_array($dir_contents)) {
         uasort($dir_contents, [&$this, "_sort_by_type"]);
     }
     // More useful navigation
     $_tmp_path = "";
     $_tmp_array = [];
     $dir_name = rtrim($dir_name, "/");
     if (substr_count($dir_name, "/") < 1) {
         $allow_delete = false;
         $allow_chmod = false;
     } else {
         $allow_delete = true;
         $allow_chmod = true;
     }
     $folders_array = explode("/", $dir_name);
     $num = count($folders_array);
     foreach ((array) $folders_array as $_folder) {
         $i++;
         $_tmp_path .= $_folder . "/";
         if ($i >= $num || !substr_count($_tmp_path, $this->START_DIR)) {
             $_tmp_array[] = _prepare_html($_folder);
         } else {
             $_tmp_array[] = "<a href='./?object=" . $_GET["object"] . "&action=show&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_tmp_path) . "'>" . _prepare_html($_folder) . "</a>";
         }
     }
     if ($_tmp_array) {
         $cur_dir_name = implode("/", $_tmp_array);
     }
     $tmp_path_info = pathinfo($dir_name);
     $up_dir_name = str_replace("\\", "/", $tmp_path_info["dirname"]);
     // Limit navigation within start folder
     if (!substr_count($dir_name, $this->START_DIR) || $dir_name == $this->START_DIR) {
         $up_dir_name = "";
     }
     $num_dirs = 0;
     $num_files = 0;
     foreach ((array) $dir_contents as $_path => $_info) {
         // Gathering of common statistics
         if ($_info["type"] != "d") {
             $total_fsize += intval($_info["size"]);
             $num_files++;
         } else {
             $num_dirs++;
         }
         // Determine which files allowed to view and edit
         $file_path_info = pathinfo($_info["name"]);
         if ($_info["type"] != "d" && in_array($file_path_info["extension"], (array) $this->EDIT_ALLOWED_TYPES)) {
             $allow_edit = true;
         } else {
             $allow_edit = false;
         }
         if ($_info["type"] != "d") {
             $path_parts = pathinfo($_path);
             if (in_array($path_parts["extension"], (array) array_keys($this->ext_images))) {
                 $ext_img = $this->ext_images[$path_parts["extension"]];
             } else {
                 $ext_img = $this->ext_images["default"];
             }
         } else {
             $ext_img = $this->ext_images["folder"];
         }
         $replace2 = ["name" => _prepare_html($_info["name"]), "encoded_name" => $this->_urlencode($_path), "ext_img" => $ext_img ? $ext_img : "", "type" => $_info["type"], "size" => common()->format_file_size($_info["size"]), "date" => _format_date($_info["date"], "long"), "perms" => $_info["perms"], "user" => $_info["user"], "view_url" => $allow_edit ? "./?object=" . $_GET["object"] . "&action=view_file&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : "", "edit_url" => $allow_edit ? "./?object=" . $_GET["object"] . "&action=edit_file&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : "", "delete_url" => $allow_delete && $_info["type"] == "d" || $_info["type"] != "d" ? "./?object=" . $_GET["object"] . "&action=" . ($_info["type"] == "d" ? "delete_folder" : "delete_file") . "&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : "", "dir_url" => $_info["type"] == "d" && $this->_check_blacklist($_path) ? "./?object=" . $_GET["object"] . "&action=show&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : "", "download_url" => $_info["type"] != "d" ? "./?object=" . $_GET["object"] . "&action=download_file&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : "", "chmod_url" => $allow_chmod ? "./?object=" . $_GET["object"] . "&action=edit_chmod&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($_path) : ""];
         $items .= tpl()->parse($_GET["object"] . "/item", $replace2);
     }
     $replace = ["server_name" => $this->_server_info["name"], "server_ip" => $this->_server_info["base_ip"], "server_url" => $this->SHOW_SERVER_NAME ? $this->SERVER_INFO_URL . "&id=" . $this->SERVER_ID : "", "up_level_url" => $up_dir_name ? "./?object=" . $_GET["object"] . "&action=show&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($up_dir_name) : "", "items" => $items, "form_action" => "./?object=" . $_GET["object"] . "&action=upload_file&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($dir_name), "mkdir_action" => "./?object=" . $_GET["object"] . "&action=create_folder&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($dir_name), "dir_name" => $cur_dir_name, "total_fsize" => common()->format_file_size($total_fsize), "num_files" => $num_files, "num_dirs" => $num_dirs, "group_delete_url" => "./?object=" . $_GET["object"] . "&action=group_delete&id=" . $this->SERVER_ID, "group_chmod_url" => "./?object=" . $_GET["object"] . "&action=edit_chmod&id=" . $this->SERVER_ID, "tar_url" => "./?object=" . $_GET["object"] . "&action=tar&id=" . ($this->SERVER_ID ? $this->SERVER_ID . "&page=" : "") . $this->_urlencode($dir_name)];
     return tpl()->parse($_GET["object"] . "/main", $replace);
 }
Example #25
0
    protected function _analytics_home()
    {
        global $bio;
        $sql = 'SELECT *, SUM(stats_members + stats_guests) AS total
			FROM _bio_stats
			WHERE bio_id = ?
			GROUP BY date
			ORDER BY date DESC';
        $stats = sql_rowset(sql_filter($sql, $bio->v('bio_id')), 'stats_date');
        $years_sum = w();
        $years_temp = w();
        $years = w();
        foreach ($stats as $date => $void) {
            $year = substr($date, 0, 4);
            if (!isset($years_temp[$year])) {
                $years[] = $year;
                $years_temp[$year] = true;
            }
            if (!isset($years_sum[$year])) {
                $years_sum[$year] = 0;
            }
            $years_sum[$year] += $void['total'];
        }
        unset($years_temp);
        if (sizeof($years)) {
            rsort($years);
        } else {
            $years[] = date('Y');
        }
        $total_graph = 0;
        foreach ($years as $year) {
            _style('year', array('YEAR' => $year));
            if (!isset($years_sum[$year])) {
                $years_sum[$year] = 0;
            }
            for ($i = 1; $i < 13; $i++) {
                $month = ($i < 10 ? '0' : '') . $i;
                $monthdata = isset($stats[$year . $month]) ? $stats[$year . $month] : (object) w();
                $monthdata->total = isset($monthdata->total) ? $monthdata->total : 0;
                $monthdata->percent = $years_sum[$year] > 0 ? $monthdata->total / $years_sum[$year] : 0;
                $monthdata->members = isset($monthdata->members) ? $monthdata->members : 0;
                $monthdata->guests = isset($monthdata->guests) ? $monthdata->guests : 0;
                $monthdata->unix = _timestamp($i, 1, $year, 0, 0, 0);
                $total_graph += $monthdata->total;
                _style('year.month', array('NAME' => _format_date($monthdata->unix, 'F'), 'TOTAL' => $monthdata->total, 'MEMBERS' => $monthdata->members, 'GUESTS' => $monthdata->guests, 'PERCENT' => sprintf("%.1d", $monthdata->percent * 100)));
            }
        }
        v_style(array('BEFORE_VIEWS' => number_format($bio->v('bio_views')), 'SHOW_VIEWS_LEGEND' => $this->data['views'] > $total_graph));
        return;
    }
Example #26
0
 /**
  */
 function _view()
 {
     $a = $this->_get_info();
     if (!$a || !$a['active']) {
         return _404('Not found');
     }
     $this->_current = $a;
     $url = url('/@object/@action/' . ($a['url'] ?: $a['id']));
     $comments = module('comments')->_show_comments((array) $this->_comments_params + ['add_form_action' => url('/@object/add_comment/' . $a['id']), 'return_path' => $url, 'object_id' => $a['id']]);
     $comments_form = main()->USER_ID ? module('comments')->add((array) $this->_comments_params + ['add_form_action' => url('/@object/add_comment/' . $a['id']), 'return_path' => $url, 'object_id' => $a['id']]) : '';
     return tpl()->parse('news/full_news', ['title' => $a['title'], 'head_text' => $a['head_text'], 'full_text' => $a['full_text'], 'add_date' => _format_date($a['add_date'], 'long'), 'full_link' => $url, 'comments_url' => url('/@object/add_comment/' . $a['id']), 'comments_form' => $comments_form, 'comments_block' => $comments['comments'], 'num_comments' => intval($comments['num_comments']), 'social' => html()->social_simple_share(['horizontal' => true, 'url' => $url, 'title' => $a['title'] . ' | ' . t('Новости') . (defined('SITE_ADVERT_NAME') ? ' | ' . SITE_ADVERT_NAME : '')])]);
 }
Example #27
0
    protected function _comments_home()
    {
        global $user;
        $tree = $this->valid_tree();
        if (!$tree['tree_allow_comments']) {
            _fatal();
        }
        $sql = 'SELECT *
			FROM _comments c, _members m
			WHERE c.comment_tree = ?
				AND c.comment_uid = m.user_id
			ORDER BY comment_time DESC';
        $comments = _rowset(sql_filter($sql, $tree['tree_id']));
        foreach ($comments as $i => $row) {
            if (!$i) {
                _style('comments');
            }
            _style('comments.row', array('ID' => $row['comment_id'], 'USERNAME' => $row['comment_username'], 'EMAIL' => $row['comment_email'], 'WEBSITE' => $row['comment_website'], 'IP' => $row['comment_ip'], 'STATUS' => $row['comment_status'], 'TIME' => _format_date($row['comment_time']), 'MESSAGE' => $row['comment_message'], 'U_VALIDATION' => _link(_rewrite($tree), array('x1' => 'comments', 'x2' => 'validation'))));
        }
        if (!count($comments)) {
            _style('no_comments');
        }
        return $this->_template('tree_comments');
    }
Example #28
0
 protected function to_calendar($field, &$value)
 {
     switch ($field) {
         case 'calendar':
             $value = _format_date($value, 'd/m/Y');
             break;
     }
     return $value;
 }
Example #29
0
    protected function _view_home()
    {
        global $core, $user;
        $v = $this->__(array('code', 'a' => 0, 'print' => 0, 'offset' => 0));
        if (f($v['code'])) {
            $sql = 'SELECT ticket_id
				FROM _tickets
				WHERE ticket_code = ?';
            $v['a'] = _field(sql_filter($sql, $v['code']), 'ticket_id');
        }
        $d = $this->init_ticket($v['a']);
        $d['ticket_owner'] = $d['ticket_contact'] == $user->v('user_id') ? true : false;
        $d['ticket_access'] = false;
        if ($user->v('is_founder') || $d['ticket_owner']) {
            $d['ticket_access'] = true;
        } else {
            $sql = 'SELECT g.group_id
				FROM _groups g, _groups_members m
				WHERE g.group_id = m.member_group
					AND m.member_uid = ?';
            if ($s_group_id = _rowset(sql_filter($sql, $user->v('user_id')), false, 'group_id')) {
                $sql = 'SELECT *
					FROM _groups g, _groups_members m, _tickets t
					WHERE t.ticket_id = ?
						AND g.group_id = m.member_group
						AND g.group_id = t.ticket_group
						AND t.ticket_group IN (??)';
                if (_fieldrow(sql_filter($sql, $d['ticket_id'], _implode(',', $s_group_id)))) {
                    $d['ticket_access'] = true;
                }
            }
        }
        if (!$d['ticket_access']) {
            $sql = 'SELECT *
				FROM _tickets t, _tickets_assign a
				WHERE t.ticket_id = ?
					AND t.ticket_id = a.assign_ticket
					AND a.user_id = ?';
            if (_fieldrow(sql_filter($sql, $d['ticket_id'], $user->v('user_id')))) {
                $d['ticket_access'] = true;
            }
        }
        if (!$d['ticket_access']) {
            _fatal();
        }
        $d['ticket_control'] = !$d['ticket_owner'] || $user->v('is_founder') ? true : false;
        $this->navigation('TICKET_VIEW', array('x1' => 'view', 'a' => $v['a'], 'offset' => $v['offset']));
        //
        $sql = 'SELECT cat_name
			FROM _tickets_cat
			WHERE cat_id = ?';
        $cat_name = _field(sql_filter($sql, $d['ticket_cat']), 'cat_name');
        $sql = 'SELECT user_firstname, user_lastname, user_username
			FROM _members
			WHERE user_id = ?';
        $ticket_author = _fieldrow(sql_filter($sql, $d['ticket_contact']));
        //
        $status_list = $this->init_status_list();
        $sql_show_public = $d['ticket_owner'] || $d['ticket_owner'] && $user->v('is_founder') ? true : false;
        //
        $sql = 'SELECT a.assign_id, a.assign_status, a.assign_end, m.user_id, m.user_username, m.user_firstname, m.user_lastname
			FROM _members m, _tickets_assign a
			WHERE m.user_id = a.user_id
				AND a.assign_ticket = ?
			ORDER BY m.user_firstname, m.user_lastname';
        $ticket_assign = _rowset(sql_filter($sql, $v['a']));
        foreach ($ticket_assign as $i => $row) {
            if (!$i) {
                _style('assigned');
            }
            if (!isset($status_list[$row['assign_status']])) {
                $row['assign_status'] = $d['ticket_status'];
            }
            _style('assigned.row', array('V_AID' => $row['assign_id'], 'V_ALIAS' => $row['user_username'], 'V_UID' => $row['user_id'], 'V_FULLNAME' => _fullname($row), 'U_PROFILE' => _link('contacts', array('m' => $row['user_username'])), 'V_STATUS' => $status_list[$row['assign_status']]['status_alias'], 'V_END' => $row['assign_end'] ? _format_date($row['assign_end']) : ''));
        }
        $sql = 'SELECT *
			FROM _groups
			ORDER BY group_name';
        $groups = _rowset($sql, 'group_id', 'group_name');
        _rowset_foreach(string_to_array_assoc($groups, w('group_id group_name')), 'groups');
        //
        if (!($category = $core->cache_load('tickets_cat'))) {
            $sql = 'SELECT *
				FROM _tickets_cat
				ORDER BY cat_name';
            $category = $core->cache_store(_rowset($sql));
        }
        $ticket_groups = explode(',', $user->auth_groups());
        foreach ($category as $i2 => $catrow) {
            if (!$catrow['cat_group'] || in_array($catrow['cat_group'], $ticket_groups)) {
                continue;
            }
            unset($category[$i2]);
        }
        _rowset_foreach($category, 'category');
        // Ticket notes
        $sql = 'SELECT n.*, m.user_id, m.user_username, m.user_firstname, m.user_lastname
			FROM _tickets_notes n, _members m
			WHERE n.ticket_id = ?
				??
				AND n.user_id = m.user_id
			ORDER BY n.note_time';
        $notes = _rowset(sql_filter($sql, $d['ticket_id'], $sql_show_public ? 'AND n.note_cc = 1 ' : ''));
        foreach ($notes as $i => $row) {
            if (!$i) {
                _style('notes');
            }
            $access = $row['note_cc'] ? 'public' : 'private';
            _style('notes.row', array('U_NOTE_EDIT' => _link($this->m(), array('x1' => 'note', 'x2' => 'modify', 'note' => $row['note_id'])), 'U_NOTE_REMOVE' => _link($this->m(), array('x1' => 'note', 'x2' => 'remove', 'note' => $row['note_id'])), 'V_NOTE_ID' => $row['note_id'], 'V_USERNAME' => _fullname($row), 'V_USERLINK' => _link('contacts', array('m' => $row['user_username'])), 'V_TIME' => _format_date($row['note_time']), 'V_TEXT' => _message($row['note_text']), 'V_ACCESS' => _lang($access), 'V_ACCESS_CLASS' => $row['note_cc'] ? 'green' : 'red'));
        }
        $sql = 'SELECT attach_id, attach_name, attach_extension, attach_size, attach_time
			FROM _tickets_attach
			WHERE attach_ticket = ?
			ORDER BY attach_name';
        $attachments = _rowset(sql_filter($sql, $d['ticket_id']));
        foreach ($attachments as $i => $row) {
            if (!$i) {
                _style('attachments');
            }
            switch ($row['attach_extension']) {
                case 'jpeg':
                case 'jpg':
                case 'gif':
                case 'png':
                    _style('attachments.image', array('ATTACH_LINK' => _link('space/f/' . $row['attach_name'], false, false), 'ATTACH_NAME' => $row['attach_name'], 'ATTACH_SIZE' => _filesize($row['attach_size'])));
                    break;
                default:
                    _style('attachments.normal', array('ATTACH_LINK' => _link('space/f/' . $row['attach_name'], false, false), 'ATTACH_NAME' => $row['attach_name'], 'ATTACH_SIZE' => _filesize($row['attach_size'])));
                    break;
            }
        }
        $author_fullname = _fullname($ticket_author);
        $sql = 'SELECT assign_status
			FROM _tickets_assign
			WHERE assign_ticket = ?
				AND user_id = ?';
        if ($assign_status = _field(sql_filter($sql, $d['ticket_id'], $user->v('user_id')), 'assign_status', 0)) {
            $d['ticket_status'] = $assign_status;
        }
        v_style(array('U_STATUS' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'status', 'ticket' => $v['a'])), 'U_GROUP' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'groups', 'a' => $v['a'])), 'U_ADD_NOTE' => _link($this->m(), array('x1' => 'note', 'x2' => 'create', 'ticket' => $v['a'])), 'U_CATEGORY' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'cat', 'ticket' => $v['a'])), 'U_TECH_ADD' => _link($this->m(), array('x1' => 'tech', 'x2' => 'add', 'ticket' => $v['a'])), 'U_TECH_QUERY' => _link($this->m(), array('x1' => 'tech', 'x2' => 'query', 'ticket' => $v['a'])), 'U_TECH_REMOVE' => _link($this->m(), array('x1' => 'tech', 'x2' => 'remove', 'ticket' => $v['a'])), 'U_REMOVE' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'remove', 'ticket' => $v['a'])), 'U_PRINT' => _link($this->m(), array('x1' => 'view', 'a' => $v['a'], 'print' => 1)), 'V_ID' => $v['a'], 'V_DELETED' => $d['ticket_deleted'], 'V_STATUS' => $this->init_status($d['ticket_status']), 'V_STATUS_ID' => $d['ticket_status'], 'V_STATUS_NAME' => $status_list[$d['ticket_status']]['status_name'], 'V_GROUP_NAME' => $groups[$d['ticket_group']], 'V_CATEGORY' => $cat_name, 'V_TITLE' => $d['ticket_title'] != '' ? $d['ticket_title'] : _lang('TICKET_NO_SUBJECT'), 'V_TEXT' => _message($d['ticket_text']), 'V_START' => $d['ticket_start'] ? _format_date($d['ticket_start']) : '', 'V_END' => $d['ticket_end'] ? _format_date($d['ticket_end']) : '', 'V_IP' => $d['ticket_ip'], 'V_AUTHOR_NAME' => $author_fullname ? $author_fullname : _lang('USER_UNKNOWN'), 'V_AUTHOR_URL' => _link('contacts', array('m' => $ticket_author['user_username'])), 'V_SHOW_PUBLIC' => !$sql_show_public));
        $this->__home_common($v['offset']);
        if ($v['print']) {
            $this->_template('ticket.print');
        }
        return;
    }
Example #30
0
    public function home()
    {
        global $user;
        $v = $this->__(array('username', 'start', 'end'));
        if (_button()) {
            if (!f($v['username'])) {
                $this->e('Debe ingresar un nombre de usuario.');
            }
            $sql = 'SELECT *
				FROM _members
				WHERE user_username = ?';
            if (!($userdata = _fieldrow(sql_filter($sql, $v['username'])))) {
                $this->_error('#TICKET_NOT_MEMBER');
            }
            $sql = "SELECT assign_ticket\n\t\t\t\tFROM _tickets_assign a, _members m\n\t\t\t\tWHERE m.user_username = ?\n\t\t\t\t\tAND m.user_id = a.user_id\n\t\t\t\tORDER BY assign_ticket";
            $as = _rowset(sql_filter($sql, $v['username']), false, 'assign_ticket');
            if (!count($as)) {
                $this->e('No hay solicitudes asignadas al usuario.');
            }
            //
            $e_start = explode('-', $v['start']);
            $v_start = mktime(0, 0, 0, $e_start[1], $e_start[0], $e_start[2]);
            //
            $sql = 'SELECT *
				FROM _tickets_status
				ORDER BY status_alias';
            $status = _rowset($sql, 'status_id', 'status_name');
            $sql = 'SELECT *
				FROM _tickets_cat
				ORDER BY cat_id';
            $cat = _rowset($sql, 'cat_id', 'cat_name');
            //
            $sql = 'SELECT *
				FROM _tickets t, _members m
				WHERE t.ticket_contact = m.user_id
					AND t.ticket_id IN (' . implode(',', $as) . ')
					/*AND t.ticket_status = 3*/
					AND t.ticket_start > ??
					AND t.ticket_deleted = 0
				ORDER BY t.ticket_start';
            $tickets = _rowset(sql_filter($sql, $v_start));
            if (!count($tickets)) {
                _style('no_tickets');
            }
            foreach ($tickets as $i => $row) {
                if (!$i) {
                    _style('tickets');
                }
                $sql = 'SELECT *
					FROM _tickets_assign a, _members m
					WHERE a.user_id = m.user_id
						AND assign_ticket = ?
					ORDER BY user_firstname';
                $names = w();
                foreach (_rowset(sql_filter($sql, $row['ticket_id']), 'assign_id') as $assigned_row) {
                    $names[] = _fullname($assigned_row);
                }
                _style('tickets.row', array('SOLICITANTE' => _fullname($row), 'ASIGNADOS' => implode(', ', $names), 'CATEGORIA' => $cat[$row['ticket_cat']], 'FECHAHORA' => _format_date($row['ticket_start']), 'TITULO' => $row['ticket_title'], 'TEXTO' => $row['ticket_text'], 'ESTADO' => $status[$row['ticket_status']]));
                //
                $sql = 'SELECT *
					FROM _tickets_notes n, _members m
					WHERE n.ticket_id = ??
						AND n.user_id = m.user_id
					ORDER BY n.note_time DESC';
                $notes = _rowset(sql_filter($sql, $row['ticket_id']));
                foreach ($notes as $note_row) {
                    _style('tickets.row.notes', array('AUTOR' => _fullname($note_row), 'TEXTO' => $note_row['note_text'], 'FECHAHORA' => _format_date($note_row['note_time'])));
                }
            }
        }
        $now = getdate();
        v_style(array('U_FILTER' => _link('export'), 'V_USERNAME' => $v['username'], 'V_NOW' => f($v['start']) ? $v['start'] : $now['mday'] . '-' . $now['mon'] . '-' . $now['year']));
        return $this->_template('ticket_export');
    }