function _get_select_attributes($atts = []) { if (empty($atts)) { return []; } // Group by attribute name $_atts_by_name = []; foreach ((array) $atts as $_info) { $_atts_products_ids[$_info["name"]] = $_info["product_id"]; $_price_text = " (" . ($_info["price"] < 0 ? "-" : "+") . module("shop")->_format_price(abs($_info["price"])) . ")"; $_atts_by_name[$_info["name"]][$_info["value"]] = $_info["value"] . ($_info["price"] ? $_price_text : ""); } $result = []; foreach ((array) $_atts_by_name as $_name => $_info) { $_product_id = $_atts_products_ids[$_name]; $_box = ""; $_box_name = "atts[" . intval($_product_id) . "][" . $_name . "]"; if (count($_info) > 1) { $_box = common()->select_box($_box_name, $_info, $selected, false, 2, "", false); } else { $_box = current($_info) . "\n<input type=\"hidden\" name=\"" . $_box_name . "\" value=\"" . _prepare_html(current($_info)) . "\" />"; } $result[$_name] = ["name" => _prepare_html($_name), "box" => $_box]; } return $result; }
/** * Display preview method * * NOTE : parent_object & parent_action are used to determine */ function _display_preview($params = [], $template = "") { $replace = $params['replace']; $PARENT_OBJECT = $_REQUEST["parent_object"]; $PARENT_ACTION = $_REQUEST["parent_action"]; // If no custom replace given, try to make own if (empty($replace)) { foreach ((array) $_POST as $k => $v) { if (in_array($v, $this->skip_fields)) { continue; } if ($k != 'category_id') { $replace[$k] = $this->_format_text($v); } else { // Try to get category_id based on parent object $categories = cache_get($PARENT_OBJECT . "_categories"); $replace['category_id'] = $categories[$v]; } } } // Try to get template if (false !== strpos($_POST['preview_form_action'], "add_comment")) { $body = tpl()->parse("comments/preview", $replace); } else { $stpl_name = $PARENT_OBJECT . "/" . $PARENT_ACTION . "_preview"; $body = tpl()->_stpl_exists($stpl_name) ? tpl()->parse($stpl_name, $replace) : ""; } // Default body if (empty($body)) { $body = tpl()->parse(__CLASS__ . "/default", $replace); } // Process template $replace2 = ["template" => $body]; return common()->show_empty_page(tpl()->parse("preview/main", $replace2), ["title" => t("Preview")]); }
function pics_browser() { if (isset($_GET['active']) && $_GET['active'] == 1) { $active = ' AND p.active = \'1\' '; } elseif (isset($_GET['active']) && $_GET['active'] == 0) { $active = ' AND p.active = \'\' '; } else { $active = ''; } if (main()->is_post()) { foreach ($_POST['delete'] as $k => $v) { list($id, $product_id) = explode("_", $k); module('manage_shop')->_product_image_delete($id, $product_id); } } $cats_list = _class('_shop_categories', 'modules/shop/')->recursive_get_child_ids(62521); $sql = "SELECT `i`.`product_id`,`i`.`id` FROM `" . db('shop_products') . "` AS `p`, `" . db('shop_product_images') . "` AS `i` WHERE `p`.`id`=`i`.`product_id` AND `p`.`cat_id` IN ('" . implode("','", $cats_list) . "')" . $active; list($add_sql, $pages, $total_records, $page_current, $pages_total, $pages_limited) = common()->divide_pages($sql); $R = db()->query($sql . $add_sql); $items = []; while ($A = db()->fetch_assoc($R)) { $_cls_products = _class('_shop_products', 'modules/shop/'); $image = $_cls_products->_product_image($A['product_id'], true); $items[] = ['id' => $A['product_id'], 'image_id' => $A['id'], 'image' => $image['big']]; } $replace = ['items' => $items, 'total' => $total_records, 'pages' => $pages]; $tpl_name = 'manage_shop/pics_browser'; return tpl()->parse($tpl_name, $replace); }
function _manufacturer_show() { // Prepare manufacturer $replace = ["brand" => module("shop")->_manufacturer, "manufacturer_box" => common()->select_box("manufacturer", module("shop")->_man_for_select, $_SESSION['man_id'], false, 2), "url_manufacturer" => process_url("./?object=shop&action=products_show")]; unset($_SESSION["man_id"]); return tpl()->parse("shop/manufacturer", $replace); }
/** * Track user error message * * @param string * @return void */ function _track_error($error_message = "") { if (empty($error_message)) { return false; } // Try to get user error message source $backtrace = debug_backtrace(); $cur_trace = $backtrace[1]; $next_trace = $backtrace[2]; // Prepare log text $text = "## LOG STARTS AT " . date("Y-m-d H:i:s") . "; QUERY_STRING: " . $_SERVER["QUERY_STRING"] . "; REFERER: " . $_SERVER["HTTP_REFERER"] . "; USER_ID: " . main()->USER_ID . "; USER_GROUP: " . main()->USER_GROUP . "; SITE_ID: " . SITE_ID . "; USER_AGENT: " . $_SERVER["HTTP_USER_AGENT"] . " ##\r\n"; $text .= "URL: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\r\n"; $text .= "SOURCE FILE: \"" . $cur_trace["file"] . "\" at LINE " . $cur_trace["line"] . "; " . (!empty($next_trace["class"]) ? "METHOD: " . $next_trace["class"] . "->" . $next_trace["function"] : "FUNCTION: " . $next_trace["function"]) . ";\r\n"; $text .= "MESSAGE: " . $error_message . "\r\n"; $text .= "## LOG ENDS ##\r\n"; // Do add current error info to the log file $h = fopen(INCLUDE_PATH . $this->LOG_USER_ERRORS_FILE_NAME, "a"); fwrite($h, $text); fclose($h); // Do store message into database (also check if that possible) if ($this->LOG_INTO_DB && is_object(db())) { $error_type = 0; db()->insert_safe('log_user_errors', ['error_level' => intval($error_type), 'error_text' => $error_message, 'source_file' => $cur_trace['file'], 'source_line' => intval($cur_trace['line']), 'date' => time(), 'site_id' => (int) conf('SITE_ID'), 'user_id' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_id' : 'user_id']), 'user_group' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_group' : 'user_group']), 'is_admin' => MAIN_TYPE_ADMIN ? 1 : 0, 'ip' => common()->get_ip(), 'query_string' => WEB_PATH . '?' . $_SERVER['QUERY_STRING'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'request_uri' => $_SERVER['REQUEST_URI'], 'env_data' => $this->DB_LOG_ENV ? $this->_prepare_env() : '', 'object' => $_GET['object'], 'action' => $_GET['action']]); } }
/** */ function add() { return form($a)->validate(['name' => 'trim|required'])->db_insert_if_ok(self::table, ['name', 'web_path', 'real_path'], [])->on_after_update(function () { cache_del([self::table]); common()->admin_wall_add(['site added: ' . $_POST['name'] . '', db()->insert_id()]); })->text('name')->text('web_path')->text('real_path')->active_box()->save_and_back(); }
/** */ function get_user_info() { $access_token = $this->_storage_get('access_token'); if (!$access_token) { $access_token = $this->get_access_token(); if (!$access_token) { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } } if (!$this->_storage_get('user')) { $url = $this->url_user . '?' . http_build_query(['access_token' => $access_token]); $result = common()->get_remote_page($url, $cache = false, $opts, $response); $result = $this->_decode_result($result, $response, __FUNCTION__); if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } else { $this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]); $user = $result; // Emails $url_emails = $this->url_user_emails . '?' . http_build_query(['access_token' => $access_token]); $result = common()->get_remote_page($url_emails, $cache = false, $opts = [], $response); $result = $this->_decode_result($result, $response, __FUNCTION__); $user['emails'] = $result; $this->_storage_set('user', $user); } } return $this->_storage_get('user'); }
/** */ function get_user_info() { $access_token = $this->_storage_get('access_token'); if (!$access_token) { $access_token = $this->get_access_token(); if (!$access_token) { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } } if (!$this->_storage_get('user')) { $url = $this->url_user . '?' . http_build_query(['oauth2_access_token' => $access_token]); $opts['custom_header'][] = 'x-li-format: json'; $result = common()->get_remote_page($url, $cache = false, $opts, $response); $result = $this->_decode_result($result, $response, __FUNCTION__); if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } else { $this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]); $this->_storage_set('user', $result); } } return $this->_storage_get('user'); }
function test() { $time_start = microtime(true); require_once YF_PATH . 'libs/phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = module('test')->SMTP_OPTIONS['smtp_host']; $mail->SMTPAuth = true; $mail->Username = module('test')->SMTP_OPTIONS['smtp_user_name']; $mail->Password = module('test')->SMTP_OPTIONS['smtp_password']; if (module('test')->SMTP_OPTIONS['smtp_secure']) { $mail->SMTPSecure = module('test')->SMTP_OPTIONS['smtp_secure']; } $mail->From = module('test')->TEST_MAIL['email_from']; if (module('test')->TEST_MAIL['name_from']) { $mail->FromName = module('test')->TEST_MAIL['name_from']; } $mail->AddAddress(module('test')->TEST_MAIL['email_to'], module('test')->TEST_MAIL['name_to']); $mail->IsHTML(true); $mail->Subject = module('test')->TEST_MAIL['subject']; $mail->Body = module('test')->TEST_MAIL['html']; $mail->AltBody = module('test')->TEST_MAIL['text']; $result = $mail->Send(); $error_message .= $mail->ErrorInfo; $body .= $result ? '<b style="color:green;">Send successful</b>' : '<b style="color:red;">Send failed</b>'; $body .= !$result ? '<br /><b>Reason:</b><br /> ' . $error_message . implode('<br />\\n', (array) main()->_all_core_error_msgs) . '<br />' : ''; $body .= '<br />Spent time: ' . common()->_format_time_value(microtime(true) - $time_start) . ' sec.<br />'; return $body; }
/** */ function get_user_info() { $access_token = $this->_storage_get('access_token'); if (!$access_token) { $access_token = $this->get_access_token(); if (!$access_token) { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } } if (!$this->_storage_get('user')) { $method = 'users.getInfo'; $sign = md5('app_id=' . $this->client_id . 'method=' . $method . 'secure=1' . 'session_key=' . $access_token . $this->client_public); $url = $this->url_user . '?' . http_build_query(['session_key' => $access_token, 'secure' => 1, 'app_id' => $this->client_id, 'method' => $method, 'sig' => $sign]); $result = common()->get_remote_page($url, $cache = false, $opts, $response); $result = $this->_decode_result($result, $response, __FUNCTION__); if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } else { $this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]); $this->_storage_set('user', $result); } } return $this->_storage_get('user'); }
/** * Order validation */ function _order_validate_delivery() { $_POST['exp_date'] = $_POST['exp_date_mm'] . $_POST['exp_date_yy']; $force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP]; if ($force_ship_type) { $_POST["ship_type"] = $force_ship_type; } if (!strlen($_POST["ship_type"]) || !isset(module('shop')->_ship_types[$_POST["ship_type"]])) { _re("Shipping type required"); } foreach ((array) module('shop')->_b_fields as $_field) { if (!strlen($_POST[$_field]) && in_array($_field, module('shop')->_required_fields)) { _re(t(str_replace("b_", "Billing ", $_field)) . " " . t("is required")); } } if ($_POST["email"] != "" && !common()->email_verify($_POST["email"])) { _re("email not valid."); } /* foreach ((array)module('shop')->_s_fields as $_field) { if (!strlen($_POST[$_field]) && in_array($_field, module('shop')->_required_fields)) { _re(t(str_replace("s_", "Shipping ", $_field))." ".t("is required")); } } if (!common()->email_verify($_POST["s_email"])) { _re("Shipping email not valid."); } */ }
/** * Order step */ function _order_step_do_payment($FORCE_DISPLAY_FORM = false) { $basket_contents = module('shop')->_basket_api()->get_all(); if (module('shop')->FORCE_PAY_METHOD) { $_POST["pay_type"] = module('shop')->FORCE_PAY_METHOD; } // Show previous form if needed if (common()->_error_exists() || empty($_POST)) { return module('shop')->_order_step_select_payment(); } $ORDER_ID = intval($_POST["order_id"] ? $_POST["order_id"] : module('shop')->_CUR_ORDER_ID); if (empty($ORDER_ID)) { _re("Missing order ID"); } // Get order info $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($ORDER_ID) . " AND user_id=" . intval(main()->USER_ID) . " AND status='pending'"); if (empty($order_info["id"])) { _re("Missing order record"); } // Payment by courier, skip next step if (!common()->_error_exists() && $_POST["pay_type"] == 1 or $_POST["pay_type"] == 3 or $_POST["pay_type"] == 4) { module('shop')->_basket_api()->clean(); return js_redirect("./?object=shop&action=" . $_GET["action"] . "&id=finish&page=" . intval($ORDER_ID)); } // Authorize.net payment type if ($_POST["pay_type"] == 2) { module('shop')->_basket_api()->clean(); return module('shop')->_order_pay_authorize_net($order_info); } }
/** * Order step */ function _order_step_delivery($FORCE_DISPLAY_FORM = false) { // Validate previous form if (main()->is_post() && !$FORCE_DISPLAY_FORM) { module('shop')->_order_validate_delivery(); // Display next form if we have no errors if (!common()->_error_exists()) { return module('shop')->_order_step_select_payment(true); } } if (main()->USER_ID) { $order_info = module('shop')->_user_info; } // Fill fields foreach ((array) module('shop')->_b_fields as $_field) { $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[substr($_field, 2)]); } // Fill shipping from billing foreach ((array) module('shop')->_s_fields as $_field) { if (module('shop')->_user_info["shipping_same"] && !isset($_POST[$_field])) { $s_field = "b_" . substr($_field, 2); $replace[$_field] = _prepare_html(isset($_POST[$s_field]) ? $_POST[$s_field] : module('shop')->_user_info[$s_field]); } else { $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[$_field]); } } $force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP]; $SELF_METHOD_ID = substr(__FUNCTION__, strlen("_order_step_")); $replace = my_array_merge((array) $replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $SELF_METHOD_ID, "error_message" => _e(), "ship_type_box" => module('shop')->_box("ship_type", $force_ship_type ? $force_ship_type : $_POST["ship_type"]), "back_link" => "./?object=shop&action=order", "cats_block" => module('shop')->_categories_show()]); return tpl()->parse("shop/order_delivery", $replace); }
/** */ function coupon_edit() { $_GET['id'] = intval($_GET['id']); if (empty($_GET['id'])) { return _e('Empty ID!'); } $coupon_info = db()->query_fetch('SELECT * FROM ' . db('shop_coupons') . ' WHERE id=' . $_GET['id']); if (main()->is_post()) { if (!$_POST['code']) { _re('Code must be entered'); } else { $_POST['code'] = $this->_cleanup_code($_POST['code']); $cnt = db()->get_one("SELECT COUNT(`id`) AS `cnt` FROM `" . db('shop_coupons') . "` WHERE `code`='" . $_POST['code'] . "' AND `id`!=" . $_GET['id']); if ($cnt != 0) { _re('Code already exists'); } } if (!common()->_error_exists()) { $sql_array = ['code' => $this->_cleanup_code($_POST['code']), 'user_id' => intval($_POST['user_id']), 'sum' => intval($_POST['sum']), 'status' => intval($_POST['status']), 'cat_id' => intval($_POST['cat_id']), 'order_id' => intval($_POST['order_id']), 'time_start' => strtotime($_POST['time_start']), 'time_end' => strtotime($_POST['time_end'])]; db()->update('shop_coupons', db()->es($sql_array), 'id=' . $_GET['id']); common()->admin_wall_add(['shop coupon updated: ' . $this->_cleanup_code($_POST['code']), $_GET['id']]); return js_redirect('./?object=' . main()->_get('object') . '&action=coupons'); } } $replace = ['code' => $coupon_info['code'], 'user_id' => $coupon_info['user_id'], 'sum' => $coupon_info['sum'], 'status' => $coupon_info['status'], 'cat_id' => $coupon_info['cat_id'], 'order_id' => $coupon_info['order_id'], 'time_start' => date('d.m.Y I:s', $coupon_info['time_start']), 'time_end' => date('d.m.Y I:s', $coupon_info['time_end']), 'form_action' => './?object=' . main()->_get('object') . '&action=coupon_edit&id=' . $coupon_info['id'], 'back_url' => './?object=' . main()->_get('object') . '&action=coupons']; return form($replace)->text('code')->integer('user_id')->integer('sum')->select_box('status', $this->_statuses)->select_box('cat_id', module('manage_shop')->_cats_for_select, ['desc' => 'Main category', 'edit_link' => './?object=category_editor&action=show_items&id=shop_cats', 'translate' => 0])->integer('order_id')->datetime_select('time_start', null, ['with_time' => 1])->datetime_select('time_end', null, ['with_time' => 1])->save_and_back(); }
/** */ function get_user_info() { $access_token = $this->_storage_get('access_token'); if (!$access_token) { $access_token = $this->get_access_token(); if (!$access_token) { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } } if (!$this->_storage_get('user')) { $access_token_request = $this->_storage_get('access_token_request'); $user_id = $access_token_request['result']['user_id']; $url = $this->url_user . '?' . http_build_query($this->url_params + ['access_token' => $access_token, 'user_id' => $user_id]); $result = common()->get_remote_page($url, $cache = false, $opts, $response); $result = $this->_decode_result($result, $response); if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') { $this->_storage_clean(); js_redirect($this->redirect_uri, $url_rewrite = false); return false; } else { $this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]); $this->_storage_set('user', $result); } } return $this->_storage_get('user'); }
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 add() { $a = $_POST; return form($a)->validate(['name' => 'trim|required|alpha-dash'])->db_insert_if_ok(self::table, ['name', 'code', 'native', 'active'], [])->on_after_update(function () { cache_del([self::table]); common()->admin_wall_add(['language added: ' . $_POST['name'] . '', db()->insert_id()]); })->text('code')->text('name')->text('native')->active_box()->save_and_back(); }
/** */ function add() { $a = $_POST; return form($a)->validate(['name' => 'trim|required'])->db_insert_if_ok('regions', ['name', 'active'], [])->on_after_update(function () { cache_del(['regions']); common()->admin_wall_add(['region added: ' . $_POST['name'] . '', db()->insert_id()]); })->text('name')->text('country')->info('code')->info('code3')->info('num')->info('cont')->active_box()->save_and_back(); }
/** */ function show() { $a = db()->get('SELECT * FROM ' . db('admin') . ' WHERE id=' . (int) main()->ADMIN_ID); $a['password'] = ''; return form($a + (array) $_POST, ['autocomplete' => 'off'])->validate(['__before__' => 'trim', 'email' => 'required|valid_email|is_unique_without[admin.email.' . main()->ADMIN_ID . ']', 'first_name' => 'required|alpha_numeric_spaces', 'last_name' => 'required|alpha_numeric_spaces', 'password' => 'password_update'])->db_update_if_ok('admin', ['email', 'first_name', 'last_name', 'go_after_login', 'password'], 'id=' . (int) main()->ADMIN_ID, ['on_after_update' => function () { common()->admin_wall_add(['admin account details updated', main()->ADMIN_ID]); }])->info('login')->info('group', ['data' => main()->get_data('admin_groups')])->password(['value' => ''])->email()->text('first_name')->text('last_name')->text('go_after_login', 'Url after login')->save(); }
/** */ function add() { $a = $_POST; return form($a)->validate(['name' => 'trim|required|alpha-dash'])->db_insert_if_ok('currencies', ['name', 'id', 'sign', 'active'], [])->on_after_update(function () { cache_del(['currencies']); common()->admin_wall_add(['icon added: ' . $_POST['name'] . '', db()->insert_id()]); })->text('id')->text('name')->text('sign')->active_box()->save_and_back(); }
/** */ function add() { $a = $_POST; return form($a)->validate(['ip' => 'trim|required|valid_ip|is_unique[core_servers.ip]'])->db_insert_if_ok(self::table, ['ip', 'role', 'name', 'hostname', 'comment'], [])->on_after_update(function () { cache_del(['servers', 'server_roles']); common()->admin_wall_add(['server added: ' . $_POST['ip'] . '', db()->insert_id()]); })->text('ip')->text('role')->text('name')->text('hostname')->textarea('comment')->active_box()->save_and_back(); }
/** * Order step */ function _order_step_finish($FORCE_DISPLAY_FORM = false) { module('shop')->_basket_api()->clean(); if (isset($_GET["page"])) { $_GET["id"] = intval($_GET["page"]); unset($_GET["page"]); } $_GET["id"] = intval($_GET["id"]); if ($_GET["id"]) { $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($_GET["id"]) . " AND user_id=" . intval(main()->USER_ID)); } if (empty($order_info)) { return _e("No such order"); } $products_ids = []; $Q = db()->query("SELECT * FROM " . db('shop_order_items') . " WHERE `order_id`=" . intval($order_info["id"])); while ($_info = db()->fetch_assoc($Q)) { if ($_info["product_id"]) { $products_ids[$_info["product_id"]] = $_info["product_id"]; } $order_items[$_info["product_id"]] = $_info; } if (!empty($products_ids)) { $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'"); $products_atts = module('shop')->_products_get_attributes($products_ids); } foreach ((array) $order_items as $_info) { $_product_id = $_info["product_id"]; $_product = $products_infos[$_product_id]; $price = $_info["sum"]; $dynamic_atts = []; if (strlen($_info["attributes"]) > 3) { foreach ((array) unserialize($_info["attributes"]) as $_attr_id) { $_attr_info = $products_atts[$_info["product_id"]][$_attr_id]; $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"]; $price += $_attr_info["price"]; } } $URL_PRODUCT_ID = module('shop')->_product_id_url($_product); $products[$_info["product_id"]] = ["name" => _prepare_html($_product["name"]), "price" => module('shop')->_format_price($price), "sum" => module('shop')->_format_price($_info["sum"]), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($_info["quantity"]), "details_link" => process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : "", "cat_name" => _prepare_html(module('shop')->_shop_cats[$_product["cat_id"]]), "cat_url" => process_url("./?object=shop&action=products_show&id=" . module('shop')->_shop_cats_all[$_product["cat_id"]]['url'])]; $total_price += $price * $quantity; } $total_price = $order_info["total_sum"]; if (main()->USER_ID) { $order_info = my_array_merge(module('shop')->_user_info, $order_info); } else { $order_info["email"] = $order_info["email"]; $order_info["phone"] = $order_info["phone"]; } $order_info = my_array_merge(module('shop')->COMPANY_INFO, $order_info); $replace2 = my_array_merge($order_info, ["id" => $_GET["id"], "products" => $products, "ship_cost" => module('shop')->_format_price(0), "total_cost" => module('shop')->_format_price($total_price), "password" => ""]); // Prepare email template $message = tpl()->parse("shop/invoice_email", $replace2); common()->quick_send_mail($order_info["email"], "invoice #" . $_GET["id"], $message); $replace = my_array_merge($replace2, ["error_message" => _e(), "products" => $products, "ship_price" => module('shop')->_format_price(module('shop')->_ship_types_names[$order_info["ship_type"]]), "total_price" => module('shop')->_format_price($total_price), "order_no" => str_pad($order_info["id"], 8, "0", STR_PAD_LEFT), "hash" => _prepare_html($order_info["hash"]), "back_link" => "./?object=shop&action=show", "cats_block" => module('shop')->_categories_show()]); return tpl()->parse("shop/order_finish", $replace); }
function run($aArgs) { $dDeleted = common()->modelExec()->deleteContentsBySeq($aArgs['seq']); if ($dDeleted !== false) { return true; } else { return false; } }
/** * 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); }
public function test_complex() { $per_page = 10; conf('per_page', $per_page); $this->assertEquals($per_page, conf('per_page')); $this->assertEquals(0, conf('user_per_page')); $this->assertEquals(0, conf('admin_per_page')); $_GET = []; $_GET['object'] = __CLASS__; $_GET['action'] = __FUNCTION__; $_GET['id'] = 12345678; $href = './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&id=' . $_GET['id']; $num_pages = 5; $data = range(1, $per_page * $num_pages); $sql = 'SELECT * FROM user'; $expect_for_sql = array_values(['limit_sql' => ' LIMIT 0, ' . $per_page, 'pages_html' => $this->_get_expected_html($href . '&page=', $num_pages), 'total_records' => count($data), 'first_record' => 0, 'total_pages' => (int) ceil(count($data) / $per_page), 'limited_pages' => 0, 'per_page' => $per_page, 'requested_page' => 0]); $result = common()->divide_pages($sql, $href, '', '', $num_records = count($data)); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals($expect_for_sql, $result); /* $expect_for_sql = array_values(array( 'limit_sql' => ' LIMIT 0, 1', 'pages_html' => $this->_get_expected_html($href.'&page=', 1), 'total_records' => 1, 'first_record' => 0, 'total_pages' => 1, 'limited_pages' => 0, 'per_page' => 1, 'requested_page'=> 0, )); $result = common()->divide_pages($sql, $href, '', '', $num_records = 1); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals( $expect_for_sql, $result ); */ $expect_for_array = array_values(['items' => array_slice($data, 0, $per_page, true), 'pages_html' => $this->_get_expected_html($href . '&page=', $num_pages), 'total_records' => count($data), 'first_record' => 0, 'total_pages' => (int) ceil(count($data) / $per_page), 'limited_pages' => 0, 'per_page' => $per_page, 'requested_page' => 0]); $result = common()->divide_pages($data, $href); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals($expect_for_array, $result); $result = common()->divide_pages($data, $href, 'slide'); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals($expect_for_array, $result); conf('per_page', 100500); $result = common()->divide_pages($data, $href); $result[1] = $this->_cleanup_html($result[1]); $this->assertNotEquals($expect_for_array, $result); $result = common()->divide_pages($data, $href, '', $per_page); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals($expect_for_array, $result); conf('per_page', $per_page); $data = range(1, $per_page * $num_pages - 1); $result = common()->divide_pages($data, $href, '', '', $per_page * $num_pages); $result[1] = $this->_cleanup_html($result[1]); $this->assertEquals($expect_for_array, $result); $data = range(1, $per_page * $num_pages); }
function go() { if (!db()->QUERY_LOG) { return false; } $logs_dir = INCLUDE_PATH . 'logs/'; if (!file_exists($logs_dir)) { _mkdir_m($logs_dir); } $IP = is_object(common()) ? common()->get_ip() : false; if (!$IP) { $IP = $_SERVER['REMOTE_ADDR']; } $log_header = '## ' . date('Y-m-d H:i:s') . '; ' . 'SITE_ID: ' . conf('SITE_ID') . '; ' . 'IP = ' . $IP . '; ' . 'QUERY_STRING = ' . WEB_PATH . '?' . $_SERVER['QUERY_STRING'] . '; ' . (!empty($_SERVER['REQUEST_URI']) ? 'URL: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '; ' : '') . (!empty($_SERVER['HTTP_REFERER']) ? 'REFERER = ' . $_SERVER['HTTP_REFERER'] . '; ' : '') . "##\r\n"; if (db()->LOG_ALL_QUERIES && !empty(db()->FILE_NAME_LOG_ALL)) { $c = 0; $h = fopen($logs_dir . db()->FILE_NAME_LOG_ALL, 'a'); fwrite($h, $log_header); foreach ((array) db()->QUERY_LOG as $id => $text) { if (substr($text, 0, strlen('EXPLAIN')) == 'EXPLAIN' || substr($text, 0, strlen('SHOW SESSION STATUS')) == 'SHOW SESSION STATUS') { continue; } $log_entry = ++$c . ') ' . common()->_format_time_value(db()->QUERY_EXEC_TIME[$id]) . ";\t" . $text . '; ' . (isset(db()->QUERY_AFFECTED_ROWS[$text]) ? ' # affected_rows: ' . intval(db()->QUERY_AFFECTED_ROWS[$text]) . ';' : '') . "\r\n"; fwrite($h, $log_entry); } fwrite($h, "####\r\n"); fclose($h); } // Slow queries if (db()->LOG_SLOW_QUERIES && !empty(db()->FILE_NAME_LOG_SLOW)) { $c = 0; foreach ((array) db()->QUERY_LOG as $id => $text) { if (db()->QUERY_EXEC_TIME[$id] < (double) db()->SLOW_QUERIES_TIME_LIMIT) { continue; } // Get explain info about queries $_explain_result = []; if (substr(db()->DB_TYPE, 0, 5) == 'mysql' && preg_match('/^[\\(]*select/ims', $text)) { $_explain_result = db()->query_fetch_all('EXPLAIN ' . $text); } $_cur_trace = db()->QUERY_BACKTRACE_LOG[$id]; $add_text = '' . (isset(db()->QUERY_AFFECTED_ROWS[$text]) ? ' # affected_rows: ' . intval(db()->QUERY_AFFECTED_ROWS[$text]) . '; ' : '') . (!empty($_cur_trace) ? '# ' . $_cur_trace['file'] . ' on line ' . $_cur_trace['line'] . ' (db->' . $_cur_trace['function'] . (!empty($_cur_trace['inside_method']) ? ' inside ' . $_cur_trace['inside_method'] : '') . '; ' : '') . (!empty($_explain_result) ? $this->_format_db_explain_result($_explain_result) : ''); $slow_queries[] = ++$c . ') ' . common()->_format_time_value(db()->QUERY_EXEC_TIME[$id]) . ";\t" . $text . '; ' . ($add_text ? "\r\n" . $add_text : '') . "\r\n"; } if (!empty($slow_queries)) { $h = fopen($logs_dir . db()->FILE_NAME_LOG_SLOW, 'a'); fwrite($h, $log_header); foreach ((array) $slow_queries as $text) { fwrite($h, $text); } fwrite($h, "####\r\n"); fclose($h); } } }
/** * Display the reassignfiles list on the item form. * This simply adds a heading to the output */ public function hookAdminItemsFormFiles() { $localReassign = (int) (bool) get_option('reassign_files_local_reassign'); if ($localReassign) { echo '<h3>' . __('Add Files from Other Items') . '</h3>'; $itemId = metadata('item', 'id'); $fileNames = SELF::reassignFiles_getFileNames($itemId); // from helpers/ReassignFilesFunctions.php echo common('reassignfileslist', array("fileNames" => $fileNames), 'index'); } }
function _send_info_to_user($user = []) { if (empty($user)) { return false; } $html = tpl()->parse('@object/email', ['user_name' => _display_name($user), 'password' => $user['password'], 'login' => $user['login'], 'advert_name' => SITE_ADVERT_NAME, 'home_url' => url('/'), 'login_url' => url('/login_form'), 'faq_url' => url('/faq')]); return common()->send_mail(['from_mail' => SITE_ADMIN_EMAIL, 'from_name' => SITE_ADVERT_NAME, 'to_mail' => $user['email'], 'to_name' => _display_name($user), 'subj' => t('Password Found'), 'html' => $html, 'text' => nl2br(strip_tags($html)), 'on_error' => function ($params) { common()->message_error('Server cannot send email to you, please contact support'); }, 'on_success' => function ($params) { common()->message_success('Email was sent successfully'); }]); }
function console() { $GLOBALS['no_graphics'] = true; session_write_close(); if (!main()->CONSOLE_MODE) { exit('No direct access to method allowed'); } sleep(3); $params = common()->get_console_params(); echo $params['id']; exit; }
/** */ function write($ses_id, $data) { $session = db()->get('SELECT * FROM ' . db('sessions') . ' WHERE id = "' . _es($ses_id) . '"'); if (is_array($session) && !empty($session)) { db()->update_safe('sessions', ['user_id' => (int) $session['user_id'], 'user_group' => (int) $session['user_group'], 'host_name' => common()->get_ip(), 'data' => $data, 'type' => MAIN_TYPE, 'last_time' => time()], 'id="' . db()->es($ses_id) . '"'); } elseif ($data || count($_COOKIE)) { // Only save session data when when the browser sends a cookie. This keeps // crawlers out of session table. This improves speed up queries, reduces // memory, and gives more useful statistics. db()->insert_safe('sessions', ['id' => $ses_id, 'user_id' => 0, 'user_group' => 0, 'start_time' => time(), 'last_time' => time(), 'host_name' => common()->get_ip(), 'data' => $data, 'type' => MAIN_TYPE]); } return true; }