function tzs_front_end_following_handler($atts) { ob_start(); $sp = tzs_validate_search_parameters(); $s_sql = tzs_search_parameters_to_sql($sp, 'sh'); $s_title = tzs_search_parameters_to_str($sp); $errors = $sp['errors']; $show_table = true; if (strlen($s_title) == 0 && count($errors) == 0) { $show_table = false; //$errors = array("Укажите параметры поиска"); } if (count($errors) > 0) { print_errors($errors); } ?> <a href="javascript:showSearchDialog();" id="edit_search">Изменить параметры поиска</a> <?php if (count($errors) == 0 && $show_table) { if (strlen($s_title) > 0) { ?> <div id="search_info">Попутные грузы <?php echo $s_title; ?> </div> <?php } else { ?> <div id="search_info">Параметры поиска не заданы</div> <?php } $page = current_page_number(); ?> <a tag="page" id="realod_btn" href="<?php echo build_page_url($page); ?> ">Обновить</a> <?php global $wpdb; $url = current_page_url(); $pp = TZS_RECORDS_PER_PAGE; $sql = "SELECT COUNT(*) as cnt FROM " . TZS_SHIPMENT_TABLE . " WHERE active=1 {$s_sql};"; $res = $wpdb->get_row($sql); if (count($res) == 0 && $wpdb->last_error != null) { print_error('Не удалось отобразить список грузов. Свяжитесь, пожалуйста, с администрацией сайта'); } else { $records = $res->cnt; $pages = ceil($records / $pp); if ($pages == 0) { $pages = 1; } if ($page > $pages) { $page = $pages; } $from = ($page - 1) * $pp; $sql = "SELECT * FROM " . TZS_SHIPMENT_TABLE . " WHERE active=1 {$s_sql} ORDER BY time DESC LIMIT {$from},{$pp};"; $res = $wpdb->get_results($sql); if (count($res) == 0 && $wpdb->last_error != null) { print_error('Не удалось отобразить список грузов. Свяжитесь, пожалуйста, с администрацией сайта'); } else { if (count($res) == 0) { ?> <div id="info">По Вашему запросу ничего не найдено.</div> <?php } else { ?> <script src="/wp-content/plugins/tzs/assets/js/distance.js"></script> <table id="tbl_shipments"> <tr> <th id="numb">Номер заявки</th> <th id="adds">Дата размещения</th> <th id="date-load">Дата погрузки<br>Дата выгрузки</th> <th id="numb-unload" nonclickable="true">Пункт погрузки<br>Пункт выгрузки</th> <th id="desc">Описание груза</th> <th id="wight">Вес</th> <th id="vol">Объем</th> <th id="type">Тип транспорта</th> <th id="cost">Цена</th> <th id="comm">Комментарии</th> </tr> <?php foreach ($res as $row) { $type = isset($GLOBALS['tzs_tr_types'][$row->trans_type]) ? $GLOBALS['tzs_tr_types'][$row->trans_type] : ""; ?> <tr rid="<?php echo $row->id; ?> "> <td><?php echo $row->id; ?> </td> <td><b><?php echo convert_date_no_year($row->time); ?> </b><br/><?php echo convert_time_only($row->time); ?> </td> <td><?php echo convert_date_no_year($row->sh_date_from); ?> <br/><?php echo convert_date_no_year($row->sh_date_to); ?> </td> <td> <?php echo tzs_city_to_str($row->from_cid, $row->from_rid, $row->from_sid, $row->sh_city_from); ?> <br/><?php echo tzs_city_to_str($row->to_cid, $row->to_rid, $row->to_sid, $row->sh_city_to); ?> <?php if ($row->distance > 0) { ?> <br/> <?php echo tzs_make_distance_link($row->distance, false, array($row->sh_city_from, $row->sh_city_to)); ?> <?php } ?> </td> <td><?php echo htmlspecialchars($row->sh_descr); ?> </td> <?php if ($row->sh_weight > 0) { ?> <td><?php echo remove_decimal_part($row->sh_weight); ?> т</td> <?php } else { ?> <td> </td> <?php } ?> <?php if ($row->sh_volume > 0) { ?> <td><?php echo remove_decimal_part($row->sh_volume); ?> м³</td> <?php } else { ?> <td> </td> <?php } ?> <td><?php echo $type; ?> </td> <td><?php echo tzs_cost_to_str($row->cost); ?> </td> <td><?php echo htmlspecialchars($row->comment); ?> </td> </tr> <?php } ?> </table> <?php } build_pages_footer($page, $pages); } } } ?> <script src="/wp-content/plugins/tzs/assets/js/search.js"></script> <script> var post = []; <?php echo "// POST dump here\n"; foreach ($_POST as $key => $value) { echo "post[" . tzs_encode2($key) . "] = " . tzs_encode2($value) . ";\n"; } ?> function showSearchDialog() { doSearchDialog('cargo', post, null, true); } jQuery(document).ready(function(){ jQuery('#tbl_shipments').on('click', 'td', function(e) { var nonclickable = 'true' == e.delegateTarget.rows[0].cells[this.cellIndex].getAttribute('nonclickable'); var id = this.parentNode.getAttribute("rid"); if (!nonclickable) document.location = "/account/view-shipment/?id="+id; }); hijackLinks(post); <?php if (strlen($s_title) == 0) { ?> showSearchDialog();<?php } ?> }); </script> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }
function tzs_front_end_tables_reload() { // Возвращаемые переменные $output_info = ''; $output_error = ''; $output_tbody = ''; $output_pnav = ''; $lastrecid = 0; $form_type = get_param_def('form_type', ''); $type_id = get_param_def('type_id', '0'); $rootcategory = get_param_def('rootcategory', '0'); $cur_type_id = get_param_def('cur_type_id', '0'); $cur_post_name = get_param_def('cur_post_name', ''); $p_title = get_param_def('p_title', ''); $page = get_param_def('page', '1'); $records_per_page = get_param_def('records_per_page', '' . TZS_RECORDS_PER_PAGE); $record_pickup_time = get_option('t3s_setting_record_pickup_time', '30'); //$p_id = get_the_ID(); //$p_title = the_title('', '', false); // Если указан параметр rootcategory, то выводим все товары раздела // Иначе - товары категории if ($rootcategory === '1' && $type_id === '0') { $sql1 = ' AND type_id IN (' . tzs_build_product_types_id_str($cur_type_id) . ')'; $p_name = ''; } else { //$sql1 = ' AND type_id='.$type_id; $sql1 = ''; $p_name = get_post_field('post_name', $type_id); } if ($form_type === 'products') { $sp = tzs_validate_pr_search_parameters(); } else { $sp = tzs_validate_search_parameters(); } $errors = $sp['errors']; switch ($form_type) { case 'products': $pr_type_array = tzs_get_children_pages(TZS_PR_ROOT_CATEGORY_PAGE_ID); $table_name = TZS_PRODUCTS_TABLE; $table_error_msg = 'товаров'; $table_order_by = 'created'; $order_table_prefix = 'PR'; break; case 'trucks': $table_name = TZS_TRUCK_TABLE; $table_error_msg = 'транспорта'; $table_order_by = 'time'; $table_prefix = 'tr'; $order_table_prefix = 'TR'; break; case 'shipments': $table_name = TZS_SHIPMENT_TABLE; $table_error_msg = 'грузов'; $table_order_by = 'time'; $table_prefix = 'sh'; $order_table_prefix = 'SH'; break; default: array_push($errors, "Неверно указан тип формы"); } if (count($errors) > 0) { $output_error = print_errors($errors); } if (count($errors) == 0) { if ($form_type === 'products') { $s_sql = tzs_search_pr_parameters_to_sql($sp, ''); $s_title = tzs_search_pr_parameters_to_str($sp); } else { $s_sql = tzs_search_parameters_to_sql($sp, $table_prefix); $s_title = tzs_search_parameters_to_str($sp); } $output_info = $p_title; if (strlen($s_title) > 0) { $output_info .= ' * ' . $s_title; } //$page = current_page_number(); global $wpdb; //$url = current_page_url(); $pp = floatval($records_per_page); $sql = "SELECT COUNT(*) as cnt FROM " . $table_name . " a WHERE active=1 {$sql1} {$s_sql};"; $res = $wpdb->get_row($sql); if (count($res) == 0 && $wpdb->last_error != null) { $output_error .= '<div>Не удалось отобразить список ' . $table_error_msg . '. Свяжитесь, пожалуйста, с администрацией сайта.<br>' . $sql . '<br>' . $wpdb->last_error . '</div>'; } else { $records = $res->cnt; $pages = ceil($records / $pp); if ($pages == 0) { $pages = 1; } if ($page > $pages) { $page = $pages; } $from = ($page - 1) * $pp; //$sql = "SELECT * FROM ".$table_name." WHERE active=1 $sql1 $s_sql ORDER BY ".$table_order_by." DESC LIMIT $from,$pp;"; // Хитрый запрос для отбора ТОП $sql = "SELECT a.*,"; $sql .= " b.number AS order_number,"; $sql .= " b.status AS order_status,"; $sql .= " b.dt_pay AS order_dt_pay,"; $sql .= " b.dt_expired AS order_dt_expired,"; $sql .= " IFNULL(b.dt_pay, a." . $table_order_by . ") AS dt_sort,"; $sql .= " IF(b.status IS NOT NULL, 2, IF(ROUND((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(a.dt_pickup))/60, 0) <= " . $record_pickup_time . ", 1, 0)) AS top_status,"; $sql .= " LOWER(c.code) AS from_code"; if ($form_type != 'products') { $sql .= ", LOWER(d.code) AS to_code"; } $sql .= " FROM " . $table_name . " a"; $sql .= " LEFT OUTER JOIN wp_tzs_orders b ON (b.tbl_type = '" . $order_table_prefix . "' AND a.id = b.tbl_id AND b.status = 1 AND b.dt_expired > NOW())"; $sql .= " LEFT OUTER JOIN wp_tzs_countries c ON (a.from_cid = c.country_id)"; if ($form_type != 'products') { $sql .= " LEFT OUTER JOIN wp_tzs_countries d ON (a.to_cid = d.country_id)"; } $sql .= " WHERE active=1 {$sql1} {$s_sql}"; $sql .= " ORDER BY top_status DESC, order_status DESC, dt_sort DESC"; $sql .= " LIMIT {$from},{$pp};"; $res = $wpdb->get_results($sql); if (count($res) == 0 && $wpdb->last_error != null) { $output_error .= '<div>Не удалось отобразить список ' . $table_error_msg . '. Свяжитесь, пожалуйста, с администрацией сайта.<br>' . $sql . '<br>' . $wpdb->last_error . '</div>'; } else { if (count($res) == 0) { $output_error .= '<div>По Вашему запросу ничего не найдено.</div>'; } else { foreach ($res as $row) { if ($form_type === 'products') { $output_tbody .= tzs_products_table_record_out($row, $form_type, $pr_type_array); } else { $output_tbody .= tzs_tr_sh_table_record_out($row, $form_type); } $lastrecid = $row->id; } } // Пагинация if ($pages > 1) { if ($page > 1) { $page0 = $page - 1; $output_pnav .= '<a tag="page" page="' . $page0 . '" href="javascript:TblTbodyReload(' . $page0 . ')">« Предыдущая</a> '; } $start = 1; $stop = $pages; for ($i = $start; $i <= $stop; $i++) { if ($i == $page) { $output_pnav .= ' <span>' . $i . '</span> '; } else { $output_pnav .= ' <a tag="page" page="' . $i . '" href="javascript:TblTbodyReload(' . $i . ')">' . $i . '</a> '; } } if ($page < $pages) { $page1 = $page + 1; $output_pnav .= ' <a tag="page" page="' . $page1 . '" href="javascript:TblTbodyReload(' . $page1 . ')">Следующая »</a>'; } } } } } $output = array('output_info' => $output_info, 'output_error' => $output_error, 'output_tbody' => $output_tbody, 'output_pnav' => $output_pnav, 'output_tbody_cnt' => count($res), 'lastrecid' => $lastrecid, 'type_id' => $type_id, 'rootcategory' => $rootcategory, 'sql' => $sql, 'sql1' => $sql1, 's_sql' => $s_sql); //echo json_encode($output); // print_r($output_tbody); return $output; }