function rcl_orders($author_lk) { global $wpdb, $user_ID, $rmag_options, $rcl_options, $order; if ($user_ID != $author_lk) { return false; } $block = apply_filters('content_order_tab', ''); if (isset($_GET['order-id'])) { $order = rcl_get_order($_GET['order-id']); if ($order->order_author != $user_ID) { return false; } $status = $order->order_status; $order_id = $order->order_id; $price = $order->order_price; $block .= '<a class="recall-button view-orders" href="' . rcl_format_url(get_author_posts_url($author_lk), 'orders') . '">Смотреть все заказы</a>'; $block .= '<h3>Заказ №' . $order_id . '</h3>'; $block .= '<div id="manage-order">'; if ($status == 1 || $status == 5) { $block .= '<input class="remove_order recall-button" onclick="rcl_trash_order(this);return false;" type="button" name="remove_order" data-order="' . $order_id . '" value="Удалить">'; } if ($status == 1 && function_exists('rcl_payform')) { $type_pay = $rmag_options['type_order_payment']; if ($type_pay == 1 || $type_pay == 2) { $block .= rcl_payform(array('id_pay' => $order_id, 'summ' => $price, 'type' => 2)); } else { $block .= '<input class="pay_order recall-button" onclick="rcl_pay_order_private_account(this);return false;" type="button" name="pay_order" data-order="' . $order_id . '" value="Оплатить">'; } } $block .= '</div>'; $block .= '<div class="redirectform"></div>'; $block .= rcl_get_include_template('order.php', __FILE__); } else { global $orders; $orders = rcl_get_orders(array('user_id' => $user_ID, 'status_not_in' => 6)); if (!$orders) { $block .= '<p>У вас пока не оформлено ни одного заказа.</p>'; } else { $block .= rcl_get_include_template('orders-history.php', __FILE__); } } return $block; }
function rmag_manage_orders() { global $wpdb; echo '<h2>Управление заказами</h2> <div style="width:1050px">'; //начало блока настроек профиля $n = 0; $s = 0; if ($_GET['remove-trash'] == 101 && wp_verify_nonce($_GET['_wpnonce'], 'delete-trash-rmag')) { $wpdb->query($wpdb->prepare("DELETE FROM " . RMAG_PREF . "orders_history WHERE order_status = '%d'", 6)); } if ($_GET['order-id']) { global $order, $product; $order = rcl_get_order($_GET['order-id']); if ($_POST['submit_message']) { if ($_POST['email_author']) { $email_author = sanitize_email($_POST['email_author']); } else { $email_author = 'noreply@' . $_SERVER['HTTP_HOST']; } $user_email = get_the_author_meta('user_email', intval($_POST['address_message'])); $result_mess = rcl_mail($user_email, sanitize_text_field($_POST['title_message']), force_balance_tags($_POST['text_message'])); } $header_tb = array('№ п/п', 'Наименование товара', 'Цена', 'Количество', 'Сумма', 'Статус'); echo '<h3>ID заказа: ' . $_GET['order_id'] . '</h3>' . '<table class="widefat">' . '<tr>'; foreach ($header_tb as $h) { echo '<th>' . $h . '</th>'; } echo '</tr>'; foreach ($order->products as $product) { $n++; $user_login = get_the_author_meta('user_login', $product->user_id); echo '<tr>' . '<td>' . $n . '</td>' . '<td>' . get_the_title($product->product_id) . '</td>' . '<td>' . $product->product_price . '</td>' . '<td>' . $product->numberproduct . '</td>' . '<td>' . $product->product_price . '</td>' . '<td>' . rcl_get_status_name_order($product->order_status) . '</td>' . '</tr>'; } echo '<tr> <td colspan="4">Сумма заказа</td> <td colspan="2">' . $order->order_price . '</td> </tr> </table>'; $get_fields = get_option('custom_profile_field'); $cf = new Rcl_Custom_Fields(); foreach ((array) $get_fields as $custom_field) { $meta = get_the_author_meta($custom_field['slug'], $order->order_author); $show_custom_field .= $cf->get_field_value($custom_field, $meta); } $details_order = rcl_get_order_details($order->order_id); echo '<form><input type="button" value="Назад" onClick="history.back()"></form><div style="text-align:right;"><a href="' . admin_url('admin.php?page=manage-rmag') . '">Показать все заказы</a></div> <h3>Все заказы пользователя: <a href="' . admin_url('admin.php?page=manage-rmag&user='******'">' . $user_login . '</a></h3> <h3>Информация о пользователе:</h3><p><b>Имя</b>: ' . get_the_author_meta('display_name', $order->order_author) . '</p><p><b>Email</b>: ' . get_the_author_meta('user_email', $order->order_author) . '</p>' . $show_custom_field; if ($details_order) { echo '<h3>Детали заказа:</h3>' . $details_order; } if ($result_mess) { echo '<h3 style="color:green;">Сообщение было отправлено!</h3>'; } echo '<style>.form_message input[type="text"], .form_message textarea{width:450px;padding:5px;}</style> <h3>Написать пользователю сообщение на почту ' . get_the_author_meta('user_email', $order->order_author) . '</h3> <form method="post" action="" class="form_message" > <p><b>Почта отправителя</b> (по-умолчанию "noreply@' . $_SERVER['HTTP_HOST'] . '")</p> <input type="text" name="email_author" value="' . sanitize_email($_POST['email_author']) . '"> <p><b>Тема письма</b></p> <input type="text" name="title_message" value="' . sanitize_text_field($_POST['title_message']) . '"> <p><b>Текст сообщения</b></p>'; $textmail = "<p>Добрый день!</p>\n\t<p>Вы или кто то другой оформил заказ на сайте " . get_bloginfo('name') . "</p>\n\t<h3>Детали заказа:</h3>\n\t" . rcl_get_include_template('order.php', __FILE__) . "\n\t<p>Ваш заказ ожидает оплаты. Вы можете произвести оплату своего заказа любым из предложенных способ из своего личного кабинета или просто пополнив свой личный счет на сайте <a href='" . get_bloginfo('wpurl') . "'>" . get_bloginfo('wpurl') . "<p>\n\t____________________________________________________________________________\n\tЭто письмо было сформировано автоматически не надо отвечать на него"; if ($_POST['text_message']) { $textmail = force_balance_tags($_POST['text_message']); } $args = array('wpautop' => 1, 'media_buttons' => 1, 'textarea_name' => 'text_message', 'textarea_rows' => 15, 'tabindex' => null, 'editor_css' => '', 'editor_class' => 'contentarea', 'teeny' => 0, 'dfw' => 0, 'tinymce' => 1, 'quicktags' => 1); wp_editor($textmail, 'textmessage', $args); echo '<input type="hidden" name="address_message" value="' . $order->order_author . '"> <p><input type="submit" name="submit_message" value="Отправить"></p> </form>'; echo $table; } else { global $order, $product; $all_pr = 0; list($year, $month, $day, $hour, $minute, $second) = preg_split('([^0-9])', current_time('mysql')); $args = array(); if ($_POST['filter-date']) { if ($_POST['year']) { $args['year'] = $_POST['year']; if ($_POST['month']) { $args['month'] = sanitize_text_field($_POST['month']); } } if ($_POST['status']) { $args['order_status'] = intval($_POST['status']); } $orders = rcl_get_orders($args); } else { if ($_GET['status']) { $args['order_status'] = intval($_GET['status']); } elseif ($_GET['user']) { $args['user_id'] = intval($_GET['user']); } elseif ($_GET['search_order']) { $args['order_id'] = intval($_GET['search_order']); $args['user_id'] = intval($_GET['search_order']); $args['search'] = true; } else { $args['status_not_in'] = 6; $args['year'] = $year; $args['month'] = $month; $_POST['year'] = $year; $_POST['month'] = $month; } //$where = apply_filters('string_where_get_orders',$where); } $orders = rcl_get_orders($args); if ($orders) { foreach ($orders as $rdr) { $n++; foreach ($rdr as $prods) { $all_pr += $prods->product_price * $prods->numberproduct; } } } //if(!isset($_GET['status'])||$_GET['status']!=6) $table .= rcl_get_chart_orders($orders); $table .= '<h3>Всего заказов: ' . $n . ' на ' . $all_pr . ' рублей</h3>'; $table .= '<form method="get" action="' . admin_url('admin.php?page=manage-rmag') . '"><p class="search-box"> <label class="screen-reader-text" for="order-search-input">Поиск заказов:</label> <input type="search" id="order-search-input" name="search_order" placeholder="ID заказа или покупателя" value=""> <input type="submit" id="search-submit" class="button" value="Поиск заказов"> <input type="hidden" name="page" value="manage-rmag"> </p></form>'; $table .= '<form action="" method="post">'; $table .= '<select name="status">'; $table .= '<option value="">Все заказы</option>'; for ($a = 1; $a <= 6; $a++) { $table .= '<option value="' . $a . '" ' . selected($a, $_POST['status'], false) . '>' . rcl_get_status_name_order($a) . '</option>'; } $table .= '</select>'; $table .= '<select name="month">'; $months = array('За все месяцы', 'январь', 'февраль', 'март', 'апрель', 'май', 'июнь', 'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь'); foreach ($months as $k => $month) { if ($k) { $k = zeroise($k, 2); } $table .= '<option value="' . $k . '" ' . selected($k, $_POST['month'], false) . '>' . $month . '</option>'; } $table .= '</select>'; $table .= '<select name="year">'; for ($a = 2013; $a <= $year + 1; $a++) { $table .= '<option value="' . $a . '" ' . selected($a, $_POST['year'], false) . '>' . $a . '</option>'; } $table .= '</select>'; $table .= '<input type="submit" value="Фильтровать" name="filter-date" class="button-secondary">'; if ($_GET['status'] == 6) { $table .= '<a href="' . wp_nonce_url(admin_url('admin.php?page=manage-rmag&remove-trash=101'), 'delete-trash-rmag') . '">Очистить корзину</a>'; } $table .= '</form>'; if (!$orders) { echo $table; exit; } $cols = array('Заказ ID', 'Пользователь', 'Сумма заказа', 'Дата и время', 'Статус', 'Смена статуса', 'Действие'); $cols = apply_filters('header_table_orders_rcl', $cols); $table .= '<table class="widefat"><tr>'; foreach ($cols as $col) { $table .= '<th>' . $col . '</th>'; } $table .= '</tr>'; foreach ($orders as $order_id => $order) { rcl_setup_orderdata($order); $radioform .= '<select id="status-' . $order_id . '" name="status-' . $order_id . '">'; for ($a = 1; $a < 7; $a++) { $radioform .= '<option ' . selected($a, $order->order_status, false) . ' value="' . $a . '">' . rcl_get_status_name_order($a) . '</option>'; } $radioform .= '</select>'; if ($order->order_status == 6) { $delete = '<input type="button" class="button-primary delete-order" id="' . $order_id . '" value="Удалить">'; } $button = '<input type="button" class="button-secondary select_status" id="' . $order_id . '" value="Изменить статус"> ' . $delete; $user_id = $order->order_author; $pagelink = admin_url('admin.php?page=manage-rmag'); $cols_content = array('<a href="' . $pagelink . '&order-id=' . $order_id . '">Заказ ' . $order_id . '</a>', '<a href="' . $pagelink . '&user='******'">' . get_the_author_meta('user_login', $user_id) . '</a>', $order->order_price, $order->order_date, '<a href="' . $pagelink . '&status=' . $order->order_status . '"><span class="change-' . $order_id . '">' . rcl_get_status_name_order($order->order_status) . '</span></a>', $radioform, $button); $cols_content = apply_filters('content_table_orders_rcl', $cols_content, $user_id); $table .= '<tr id="row-' . $order_id . '">'; foreach ($cols_content as $content) { $table .= '<td>' . $content . '</td>'; } $table .= '</tr>'; $radioform = ''; $delete = ''; } $cnt_cols = count($cols); if ($_GET['status'] != 6) { $table .= '<tr><td align="right" colspan="' . $cnt_cols . '"><a href="' . admin_url('admin.php?page=manage-rmag&status=6') . '">Перейти в корзину</a></td></tr>'; } $table .= '</table>'; echo $table; if ($_GET['user'] || $_GET['status'] || $_GET['date']) { echo '<form><input type="button" value="Назад" onClick="history.back()"></form><div style="text-align:right;"><a href="' . admin_url('admin.php?page=manage-rmag') . '">Показать текущие заказы</a></div>'; } } echo '</div>'; //конец блока заказов }
function rcl_remove_reserve($order_id, $st = 0) { global $rmag_options, $wpdb; if ($rmag_options['products_warehouse_recall'] != 1) { return false; } $orders = rcl_get_order($order_id); foreach ((array) $orders as $sumproduct) { $reserve = get_post_meta($sumproduct->product, 'reserve_product', 1); if ($reserve) { //если резев имеется $reserve = $reserve - "{$sumproduct->count}"; //уменьшаем резерв update_post_meta($sumproduct->product, 'reserve_product', $reserve); if ($st) { $amount = get_post_meta($sumproduct->product, 'amount_product', 1); $amount = $amount + "{$sumproduct->count}"; //увеличиваем наличие update_post_meta($sumproduct->product, 'amount_product', $amount); } } } }
function rcl_pay_order_private_account() { global $user_ID, $wpdb, $rmag_options, $order; $order_id = intval($_POST['idorder']); if (!$order_id || !$user_ID) { $log['otvet'] = 1; echo json_encode($log); exit; } $order = rcl_get_order($order_id); //rcl_setup_orderdata($order); $oldusercount = rcl_get_user_money(); if (!$oldusercount) { $log['otvet'] = 1; $log['recall'] = $order->order_price; echo json_encode($log); exit; } //print_r($order); $newusercount = $oldusercount - $order->order_price; if ($newusercount < 0) { $log['otvet'] = 1; $log['recall'] = $order->order_price; echo json_encode($log); exit; } rcl_update_user_money($newusercount); $result = rcl_update_status_order($order_id, 2); if (!$result) { $log['otvet'] = 1; $log['recall'] = 'Ошибка запроса!'; echo json_encode($log); exit; } rcl_payment_order($order_id, $user_ID); do_action('payment_rcl', $user_ID, $order->order_price, $order_id, 2); $text = "<p>Ваш заказ успешно оплачен! Соответствующее уведомление было выслано администрации сервиса.</p>"; $text = apply_filters('payment_order_text', $text); $log['recall'] = "<div style='clear: both;color:green;font-weight:bold;padding:10px; border:2px solid green;'>" . $text . "</div>"; $log['count'] = $newusercount; $log['idorder'] = $order_id; $log['otvet'] = 100; echo json_encode($log); exit; }