function show_eshop($params) { global $tpl, $template, $twig, $mysql, $SYSTEM_FLAGS, $config, $userROW, $CurrentHandler, $lang; //var_dump($SYSTEM_FLAGS["eshop"]["catz"]); $id = isset($params['id']) ? abs(intval($params['id'])) : abs(intval($_REQUEST['id'])); $alt = preg_match('#^[A-Za-z0-9\\.\\_\\-]+$#s', $params['alt']) ? input_filter_com(convert($params['alt'])) : ''; $url = pluginGetVariable('eshop', 'url'); switch ($CurrentHandler['handlerParams']['value']['pluginName']) { case 'core': if (isset($url) && !empty($url)) { return redirect_eshop(generateLink('eshop', 'show', array('alt' => $alt))); } break; case 'eshop': if (empty($url)) { return redirect_eshop(generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $alt))); } break; } $conditions = array(); if (isset($alt) && !empty($alt)) { array_push($conditions, "p.url = " . db_squote($alt) . " "); } else { redirect_eshop(link_eshop()); } array_push($conditions, "p.active = 1 "); $tpath = locatePluginTemplates(array('show_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin')); $xt = $twig->loadTemplate($tpath['show_eshop'] . 'show_eshop.tpl'); $fSort = " GROUP BY p.id ORDER BY p.id DESC LIMIT 1"; $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort; $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart; $row = $mysql->record($sqlQ); if (isset($row) && !empty($row)) { $qid = $row['id']; $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url'])); $cat_ids = $row['cid']; $i = 0; $location_tmp = array(); $location = array(); $location_tmp[] = array('text' => $row['name'], 'link' => $fulllink); if ($cat_ids != "") { do { $result_cat = array(); getCatFromTreeByID($SYSTEM_FLAGS["eshop"]["catz"]["tree"], $cat_ids, $result_cat); $bcat_row = $result_cat; $cat_ids = $bcat_row['parent_id']; $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $bcat_row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $bcat_row['url'])); $location_tmp[] = array('text' => $bcat_row['name'], 'link' => $catlink); $i += 1; } while ($cat_ids != 0); /* do { $bcat_row = $mysql->record("SELECT * FROM ".prefix."_eshop_categories c WHERE c.id IN (".$cat_ids.")"); $cat_ids = $bcat_row['parent_id']; $catlink = checkLinkAvailable('eshop', '')? generateLink('eshop', '', array('alt' => $bcat_row['url'])): generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $bcat_row['url'])); $location_tmp[] = array('text' => $bcat_row['name'], 'link' => $catlink, ); $i += 1; } while($cat_ids != 0); */ } $location = array_merge($location, array_reverse($location_tmp)); foreach ($location as $loc_k => $loc) { $SYSTEM_FLAGS['info']['breadcrumbs'][$loc_k]['text'] = $loc['text']; $SYSTEM_FLAGS['info']['breadcrumbs'][$loc_k]['link'] = $loc['link']; } $entriesImg = array(); foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images WHERE product_id = ' . $row['id'] . ' ORDER BY position, id ') as $row2) { $entriesImg[] = $row2; } $entriesVariants = array(); foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants WHERE product_id = ' . $row['id'] . ' ORDER BY position, id ') as $vrow) { $entriesVariants[] = $vrow; } $features_array = array(); foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_options LEFT JOIN ' . prefix . '_eshop_features ON ' . prefix . '_eshop_features.id=' . prefix . '_eshop_options.feature_id WHERE ' . prefix . '_eshop_options.product_id = ' . $row['id'] . ' ORDER BY position, id') as $orow) { if ($orow['ftype'] == 2) { $foptions = json_decode($orow['foptions'], true); $orow['value'] = iconv("utf-8", "windows-1251", $foptions[$orow['value']]); } $features_array[] = $orow; } foreach ($mysql->select('SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views FROM ' . prefix . '_eshop_related_products rp LEFT JOIN ' . prefix . '_eshop_products p ON p.id=rp.related_id WHERE rp.product_id = ' . $row['id'] . ' AND p.active = 1 ORDER BY rp.position') as $rrow) { $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rrow['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rrow['url'])); $rrow['fulllink'] = $fulllink; $related_array[$rrow['id']] = $rrow; } $related_array_ids = array_keys($related_array); if (isset($related_array_ids) && !empty($related_array_ids)) { $related_string_ids = implode(',', $related_array_ids); foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $related_string_ids . ') ORDER BY i.position, i.id') as $irow) { $related_array[$irow['product_id']]['images'][] = $irow; } foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $related_string_ids . ') ORDER BY v.position, v.id') as $vrow) { $related_array[$vrow['product_id']]['variants'][] = $vrow; } } $SYSTEM_FLAGS['info']['title']['others'] = $row['meta_title']; $SYSTEM_FLAGS['info']['title']['group'] = $lang['eshop']['name_plugin']; $SYSTEM_FLAGS['meta']['description'] = $row['meta_description'] ? $row['meta_description'] : ''; $SYSTEM_FLAGS['meta']['keywords'] = $row['meta_keywords'] ? $row['meta_keywords'] : ''; $cmode = intval(pluginGetVariable('eshop', 'views_count')); if ($cmode > 1) { // Delayed update of counters $mysql->query("insert into " . prefix . "_eshop_products_view (id, cnt) values (" . db_squote($row['id']) . ", 1) on duplicate key update cnt = cnt + 1"); } else { if ($cmode > 0) { $mysql->query("update " . prefix . "_eshop_products set views=views+1 where id = " . db_squote($row['id'])); } } $cmp_array = array(); foreach ($SYSTEM_FLAGS["eshop"]["compare"]["entries"] as $cmp_row) { $cmp_array[] = $cmp_row['linked_fld']; } $cmp_flag = in_array($qid, $cmp_array); $likes_tpath = locatePluginTemplates(array('likes_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin')); $likes_xt = $twig->loadTemplate($likes_tpath['likes_eshop'] . 'likes_eshop.tpl'); $likes = $mysql->record("SELECT COUNT(*) as count FROM " . prefix . "_eshop_products_likes l WHERE l.product_id='" . $qid . "'"); $likes_tVars = array('count' => $likes['count'], 'id' => $qid); $comments_tpath = locatePluginTemplates(array('comments.form_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin')); $comments_xt = $twig->loadTemplate($comments_tpath['comments.form_eshop'] . 'comments.form_eshop.tpl'); $comments_tVars = array('id' => $qid); $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url'])); $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $row['curl'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $row['curl'])); $tVars = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'full_link' => $fulllink, 'edit_link' => admin_url . "/admin.php?mod=extra-config&plugin=eshop&action=edit_product&id=" . $row['id'] . "", 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'views' => $row['views'] + 1, 'cat_name' => $row['category'], 'cid' => $row['cid'], 'catlink' => $catlink, 'home' => home, 'tpl_url' => home . '/templates/' . $config['theme'], 'entriesImg' => isset($entriesImg) ? $entriesImg : '', 'entriesVariants' => isset($entriesVariants) ? $entriesVariants : '', 'entriesFeatures' => isset($features_array) ? $features_array : '', 'entriesRelated' => isset($related_array) ? $related_array : '', 'compare' => $cmp_flag, 'likes_form' => $likes_xt->render($likes_tVars), 'comments_form' => $comments_xt->render($comments_tVars)); $template['vars']['mainblock'] .= $xt->render($tVars); } else { error404(); } }
function payment_action($payment_name, $payment_options, $rData) { global $tpl, $template, $config, $mysql, $lang, $twig, $SUPRESS_TEMPLATE_SHOW, $SYSTEM_FLAGS; $SUPRESS_TEMPLATE_SHOW = 1; $SUPRESS_MAINBLOCK_SHOW = 1; $current_time = time() + $config['date_adjust'] * 60; $result = intval($rData['result']); if (!empty($result)) { switch ($result) { case '1': // fail_url redirect_eshop(link_eshop()); break; case '2': // result_url $method = $rData['method']; $params = $rData['params']; $secretKey = $payment_options['secretKey']; if ($method == 'check') { $message = 'CHECK is successful'; return json_encode(array("jsonrpc" => "2.0", "result" => array("message" => $message))); } elseif ($method == 'pay') { if ($params['sign'] == getMd5Sign($params, $secretKey)) { $merchant_purse = $params; $amount = $rData['OutSum']; $order_id = intval($rData['InvId']); $info = array('payment_name' => $payment_name, 'merchant_purse' => $merchant_purse, 'amount' => $amount, 'order_id' => $order_id); $mysql->query('INSERT INTO ' . prefix . '_eshop_purchases (dt, order_id, info) VALUES (' . db_squote($current_time) . ', ' . db_squote($order_id) . ', ' . db_squote(json_encode($info)) . ' ) '); $mysql->query('UPDATE ' . prefix . '_eshop_orders SET paid = 1 WHERE id = ' . $order_id . ' '); $message = 'PAY is successful'; return json_encode(array("jsonrpc" => "2.0", "result" => array("message" => $message))); } else { $message = 'Incorrect digital signature'; return json_encode(array("jsonrpc" => "2.0", "error" => array("code" => -32000, "message" => $message))); } } else { $message = $method . ' not supported'; return json_encode(array("jsonrpc" => "2.0", "error" => array("code" => -32000, "message" => $message))); } break; case '3': // success_url redirect_eshop(link_eshop()); break; default: break; } } else { $filter = array(); $SQL = array(); $order_id = filter_var($rData['order_id'], FILTER_SANITIZE_STRING); $uniqid = filter_var($rData['order_uniqid'], FILTER_SANITIZE_STRING); if (empty($order_id) || empty($uniqid)) { redirect_eshop(link_eshop()); } else { $filter[] = '(id = ' . db_squote($order_id) . ')'; $filter[] = '(uniqid = ' . db_squote($uniqid) . ')'; $sqlQ = "SELECT * FROM " . prefix . "_eshop_orders " . (count($filter) ? "WHERE " . implode(" AND ", $filter) : '') . " LIMIT 1"; $row = $mysql->record($sqlQ); if ($row['paid'] == 1) { redirect_eshop(link_eshop()); } elseif (!empty($row)) { if (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } $paymentType = "card"; $sum = $row['total_price']; $account = $order_id; $projectId = $payment_options['projectId']; $secretKey = $payment_options['secretKey']; $desc = 'Оплата по заказу ID: ' . $order_id; $account = $order_id; $fail_url = home . '/eshop/payment/?result=1&payment_id=unitpay'; $result_url = home . '/eshop/payment/?result=2&payment_id=unitpay'; $success_url = home . '/eshop/payment/?result=3&payment_id=unitpay'; $currency = $SYSTEM_FLAGS['eshop']['currency'][0]['code']; // build URL $url = "https://unitpay.ru/api?method=initPayment&" . "params[paymentType]={$paymentType}¶ms[sum]={$sum}¶ms[account]={$account}¶ms[projectId]={$projectId}¶ms[secretKey]={$secretKey}¶ms[ip]={$ip}¶ms[resultUrl]={$success_url}¶ms[currency]={$currency}"; header('Location: ' . $url . ''); exit; } else { redirect_eshop(link_eshop()); } } } }
function payment_action($payment_name, $payment_options, $rData) { global $tpl, $template, $config, $mysql, $lang, $twig, $SUPRESS_TEMPLATE_SHOW, $SYSTEM_FLAGS; $SUPRESS_TEMPLATE_SHOW = 1; $SUPRESS_MAINBLOCK_SHOW = 1; $current_time = time() + $config['date_adjust'] * 60; $result = intval($rData['result']); if (!empty($result)) { switch ($result) { case '1': // fail_url redirect_eshop(link_eshop()); break; case '2': $rData['sign'] = str_replace(' ', '+', $rData['sign']); $rData['xml'] = str_replace(' ', '+', $rData['xml']); // result_url if (!empty($rData['xml']) and !empty($rData['sign'])) { // Инициализация переменной для хранения сообщения об ошибке $error = ''; // Декодируем входные параметры $xml_encoded = str_replace(' ', '+', $rData['xml']); $xml = base64_decode($xml_encoded); // преобразуем входной xml в удобный для использования формат $xml_vars = simplexml_load_string($xml); //$file = '/home/s/stdex/air.tw1.ru/public_html/engine/plugins/eshop/eeeeee.txt'; //file_put_contents($file, strval($xml_vars), FILE_APPEND | LOCK_EX); if ($xml_vars->order_id) { $hidden_key = $payment_options['hidden_key']; $sign = md5($hidden_key . $xml . $hidden_key); $sign_encode = base64_encode($sign); $a_or_id = explode("_", $xml_vars->order_id); $zid = $a_or_id[1]; $merchant_id = (string) $xml_vars->merchant_id; $order_id = (string) $xml_vars->order_id; $amount = (string) $xml_vars->amount; $currency = (string) $xml_vars->currency; $description = (string) $xml_vars->description; $description = iconv("utf-8", "windows-1251", $description); $paymode = (string) $xml_vars->paymode; $trans_id = (string) $xml_vars->trans_id; $status = (string) $xml_vars->status; $error_msg = (string) $xml_vars->error_msg; $test_mode = (string) $xml_vars->test_mode; $info = array('payment_name' => $payment_name, 'merchant_id' => $merchant_id, 'amount' => $amount, 'currency' => $currency, 'description' => $description, 'paymode' => $paymode, 'trans_id' => $trans_id, 'status' => $status, 'error_msg' => $error_msg, 'test_mode' => $test_mode); if ($sign_encode == $rData['sign']) { if ($status == 'success') { $mysql->query('INSERT INTO ' . prefix . '_eshop_purchases (dt, order_id, info) VALUES (' . db_squote($current_time) . ', ' . db_squote($zid) . ', ' . db_squote(json_encode($info)) . ' ) '); $mysql->query('UPDATE ' . prefix . '_eshop_orders SET paid = 1 WHERE id = ' . $zid . ' '); } } else { $error = 'Incorrect sign'; //redirect_eshop(link_eshop()); } } else { $error = 'Unknown order_id'; //redirect_eshop(link_eshop()); } // Отвечаем серверу Pay2Pay if ($error == '') { $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <result>\n <status>yes</status>\n <err_msg></err_msg>\n </result>"; } else { $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <result>\n <status>no</status>\n <err_msg>{$error}</err_msg>\n </result>"; } die($ret); } break; case '3': // success_url redirect_eshop(link_eshop()); break; default: break; } } else { $filter = array(); $SQL = array(); $order_id = filter_var($rData['order_id'], FILTER_SANITIZE_STRING); $uniqid = filter_var($rData['order_uniqid'], FILTER_SANITIZE_STRING); if (empty($order_id) || empty($uniqid)) { redirect_eshop(link_eshop()); } else { $filter[] = '(id = ' . db_squote($order_id) . ')'; $filter[] = '(uniqid = ' . db_squote($uniqid) . ')'; $sqlQ = "SELECT * FROM " . prefix . "_eshop_orders " . (count($filter) ? "WHERE " . implode(" AND ", $filter) : '') . " LIMIT 1"; $row = $mysql->record($sqlQ); if ($row['paid'] == 1) { redirect_eshop(link_eshop()); } elseif (!empty($row)) { $merchant_id = $payment_options['merchant_id']; // Идентификатор магазина в Pay2Pay $secret_key = $payment_options['secret_key']; // Секретный ключ $hash_order_id = $current_time . "_" . $order_id; // Номер заказа $amount = $row['total_price']; // Сумма заказа $currency = $SYSTEM_FLAGS['eshop']['currency'][0]['code']; // Валюта заказа $desc = 'Оплата по заказу ID: ' . $order_id; // Описание заказа $desc = iconv("windows-1251", "utf-8", $desc); $test_mode = $payment_options['test_mode']; // Тестовый режим // Формируем xml $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <request>\n <version>1.2</version>\n <merchant_id>{$merchant_id}</merchant_id>\n <language>ru</language>\n <order_id>{$hash_order_id}</order_id>\n <amount>{$amount}</amount>\n <currency>{$currency}</currency>\n <description>{$desc}</description>\n <test_mode>{$test_mode}</test_mode>\n <other><![CDATA[{$order_id}]]></other>\n </request>"; // Вычисляем подпись $sign = md5($secret_key . $xml . $secret_key); // Кодируем данные в BASE64 $xml_encode = base64_encode($xml); $sign_encode = base64_encode($sign); echo ' <!DOCTYPE html><html><body> <form id="b-site" action="https://merchant.pay2pay.com/?page=init" method="post"> <input type="hidden" name="xml" value="' . $xml_encode . '"> <input type="hidden" name="sign" value="' . $sign_encode . '"> </form> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script>$("document").ready(function() {$("#b-site").submit();});</script> </body></html>'; exit; } else { redirect_eshop(link_eshop()); } } } }
function payment_action($payment_name, $payment_options, $rData) { global $tpl, $template, $config, $mysql, $lang, $twig, $SUPRESS_TEMPLATE_SHOW, $SYSTEM_FLAGS; $SUPRESS_TEMPLATE_SHOW = 1; $SUPRESS_MAINBLOCK_SHOW = 1; $current_time = time() + $config['date_adjust'] * 60; $result = intval($rData['result']); if (!empty($result)) { switch ($result) { case '1': // fail_url redirect_eshop(link_eshop()); break; case '2': // result_url // Кошелек продавца, на который покупатель совершил платеж. Формат - буква и 12 цифр. $merchant_purse = $rData['LMI_PAYEE_PURSE']; // Сумма, которую заплатил покупатель. Дробная часть отделяется точкой. $amount = $rData['OutSum']; // Внутренний номер покупки продавца // В этом поле передается id заказа в нашем магазине. $order_id = intval($rData['InvId']); // Контрольная подпись $crc = strtoupper($rData['SignatureValue']); $mrh_pass2 = $payment_options['mrh_pass2']; // Проверяем контрольную подпись $my_crc = strtoupper(md5("{$amount}:{$order_id}:{$mrh_pass2}")); if ($my_crc !== $crc) { die("bad sign\n"); } $info = array('payment_name' => $payment_name, 'merchant_purse' => $merchant_purse, 'amount' => $amount, 'order_id' => $order_id); $mysql->query('INSERT INTO ' . prefix . '_eshop_purchases (dt, order_id, info) VALUES (' . db_squote($current_time) . ', ' . db_squote($order_id) . ', ' . db_squote(json_encode($info)) . ' ) '); $mysql->query('UPDATE ' . prefix . '_eshop_orders SET paid = 1 WHERE id = ' . $order_id . ' '); die("OK" . $order_id . "\n"); break; case '3': // success_url redirect_eshop(link_eshop()); break; default: break; } } else { $filter = array(); $SQL = array(); $order_id = filter_var($rData['order_id'], FILTER_SANITIZE_STRING); $uniqid = filter_var($rData['order_uniqid'], FILTER_SANITIZE_STRING); if (empty($order_id) || empty($uniqid)) { redirect_eshop(link_eshop()); } else { $filter[] = '(id = ' . db_squote($order_id) . ')'; $filter[] = '(uniqid = ' . db_squote($uniqid) . ')'; $sqlQ = "SELECT * FROM " . prefix . "_eshop_orders " . (count($filter) ? "WHERE " . implode(" AND ", $filter) : '') . " LIMIT 1"; $row = $mysql->record($sqlQ); if ($row['paid'] == 1) { redirect_eshop(link_eshop()); } elseif (!empty($row)) { $mrh_login = $payment_options['mrh_login']; $mrh_pass1 = $payment_options['mrh_pass1']; $test_mode = $payment_options['test_mode']; $inv_id = $order_id; $inv_desc = 'Оплата по заказу ID: ' . $order_id; $out_summ = $row['total_price']; $OutSumCurrency = $SYSTEM_FLAGS['eshop']['currency'][0]['code']; $shp_item = 1; $in_curr = ""; $culture = "ru"; $IsTest = $test_mode; $crc = md5("{$mrh_login}:{$out_summ}:{$inv_id}:{$OutSumCurrency}:{$mrh_pass1}:Shp_item={$shp_item}"); // build URL $url = "https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin={$mrh_login}&" . "OutSum={$out_summ}&InvId={$inv_id}&Desc={$inv_desc}&OutSumCurrency={$OutSumCurrency}&SignatureValue={$crc}&IsTest={$IsTest}"; header('Location: ' . $url . ''); exit; } else { redirect_eshop(link_eshop()); } } } }