Ejemplo n.º 1
0
function tzs_front_end_view_product_handler($atts)
{
    ob_start();
    global $wpdb;
    $user_id = get_current_user_id();
    $sh_id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
    if ($sh_id <= 0) {
        print_error('Товар/услуга не найден');
    } else {
        $sql = "SELECT * FROM " . TZS_PRODUCTS_TABLE . " WHERE id={$sh_id};";
        $row = $wpdb->get_row($sql);
        if (count($row) == 0 && $wpdb->last_error != null) {
            print_error('Не удалось отобразить информацию о товаре/услуге. Свяжитесь, пожалуйста, с администрацией сайта.');
        } else {
            if ($row == null) {
                print_error('Товар/услуга не найден');
            } else {
                if (isset($_GET['spis'])) {
                    echo "<a id='edit_search' href='/account/my-products/'>Назад к списку</a> <div style='clear: both'></div>";
                } elseif (isset($_GET['link'])) {
                    echo "<a id='edit_search' href='/" . $_GET['link'] . "/'>Назад к списку</a> <div style='clear: both'></div>";
                } else {
                    echo "<button id='edit_search'  onclick='history.back()'>Назад к списку</button> <div style='clear: both'></div>";
                }
                ?>
                <div id="">
                    <table border="0" id="view_ship">
			<tr>
				<td>Номер товара/услуги</td>
				<td><?php 
                echo $row->id;
                ?>
</td>
			</tr>
			<tr>
				<td>Активно</td>
				<td><?php 
                echo $row->active == 1 ? 'Да' : 'Нет';
                ?>
</td>
			</tr>
			<tr>
				<td>Дата размещения</td>
				<td><?php 
                echo convert_date_no_year($row->created);
                ?>
 <?php 
                echo convert_time_only($row->time);
                ?>
</td>
			</tr>
			<?php 
                if ($row->last_edited != null) {
                    ?>
			<tr>
				<td>Дата последнего изменения</td>
				<td><?php 
                    echo convert_date_no_year($row->last_edited);
                    ?>
 <?php 
                    echo convert_time_only($row->last_edited);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->expiration != null) {
                    ?>
			<tr>
				<td>Дата окончания публикации</td>
				<td><?php 
                    echo convert_date_no_year($row->expiration);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->type_id > 0) {
                    ?>
			<tr>
				<td>Категория</td>
				<td><?php 
                    echo $row->type_id;
                    $res = tzs_get_children_pages(TZS_PR_ROOT_CATEGORY_PAGE_ID);
                    $key = array_search(intval($row->type_id), $res);
                    if ($key) {
                        echo $res[$key]['title'];
                    }
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Краткое описание товара/услуги</td>
				<td><?php 
                echo htmlspecialchars($row->title);
                ?>
</td>
			</tr>
			<tr>
				<td>Полное описание товара/услуги</td>
				<td><?php 
                echo htmlspecialchars($row->description);
                ?>
</td>
			</tr>
			<?php 
                if ($row->copies > 0) {
                    ?>
			<tr>
				<td>Количество</td>
				<td><?php 
                    echo $row->copies;
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->price > 0) {
                    ?>
			<tr>
				<td>Стоимость товара</td>
				<td><?php 
                    echo $row->price . " " . $GLOBALS['tzs_pr_curr'][$row->currency];
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->payment > 0) {
                    ?>
			<tr>
				<td>Форма оплаты</td>
				<td><?php 
                    echo $GLOBALS['tzs_pr_payment'][$row->payment];
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Местонахождение</td>
				<td><?php 
                echo tzs_city_to_str($row->from_cid, $row->from_rid, $row->from_sid, $row->city_from);
                ?>
</td>
			</tr>
			<?php 
                if (strlen($row->comment) > 0) {
                    ?>
			<tr>
				<td>Комментарии</td>
				<td><?php 
                    echo htmlspecialchars($row->comment);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if (strlen($row->image_id_lists) > 0) {
                    ?>
			<tr>
				<td>Изображения</td>
				<td><?php 
                    //$img_names = explode(';', $row->pictures);
                    $img_names = explode(';', $row->image_id_lists);
                    $main_image_id = $row->main_image_id;
                    if (count($img_names) > 0) {
                        ?>
                                    <table>
                                        <?php 
                        // Вначале выведем главное изображение
                        $attachment_info = wp_get_attachment_image_src($main_image_id, 'full');
                        if ($attachment_info !== false) {
                            echo '<tr><td><img src="' . $attachment_info[0] . '" alt=""></td></tr>';
                        }
                        // Затем выведем все остальные изображения
                        for ($i = 0; $i < count($img_names); $i++) {
                            if ($img_names[$i] !== $main_image_id) {
                                $attachment_info = wp_get_attachment_image_src($img_names[$i], 'full');
                                //if (file_exists(ABSPATH . $img_names[$i])) {
                                if ($attachment_info !== false) {
                                    echo '<tr><td><img src="' . $attachment_info[0] . '" alt=""></td></tr>';
                                }
                            }
                        }
                        ?>
                                    </table>
                                        <?php 
                    }
                    ?>
</td>
			</tr>
			<?php 
                } else {
                    $img_names = array();
                }
                ?>
			</table>
                    </div>

			<?php 
                if ($user_id == 0 && $GLOBALS['tzs_au_contact_view_all'] == false) {
                    ?>
				<div>Для просмотра контактов необходимо <a href="/account/login/">войти</a> или <a href="/account/registration/">зарегистрироваться</a></div>
			<?php 
                } else {
                    if ($user_id != $row->user_id) {
                        ?>
			
			<br/>
			<h1 class="entry-title">Контактная информация</h1>
			
			<?php 
                        tzs_print_user_table($row->user_id);
                        ?>
			
			<script src="/wp-content/plugins/tzs/assets/js/feedback.js"></script>
			
			<button id="view_feedback" onClick="<?php 
                        echo tzs_feedback_build_url($row->user_id);
                        ?>
">Отзывы <span>|</span> Рейтинг пользователя</button>
			<?php 
                    } else {
                        ?>
				<button id="view_del" onClick="javascript: promptDelete(<?php 
                        echo $row->id;
                        ?>
);">Удалить</button>
				<button id="view_edit" onClick="javascript: window.open('/account/edit-product/?id=<?php 
                        echo $row->id;
                        ?>
', '_self');">Изменить</button>
			<?php 
                    }
                }
                ?>
			<script>
				function promptDelete(id) {
					jQuery('<div></div>').appendTo('body')
						.html('<div><h6>Удалить запись '+id+'?</h6></div>')
						.dialog({
							modal: true,
							title: 'Удаление',
							zIndex: 10000,
							autoOpen: true,
							width: 'auto',
							resizable: false,
							buttons: {
								'Да': function () {
									jQuery(this).dialog("close");
									doDelete(id);
								},
								'Нет': function () {
									jQuery(this).dialog("close");
								}
							},
							close: function (event, ui) {
								jQuery(this).remove();
							}
						});
				}
				function doDelete(id) {
					var data = {
						'action': 'tzs_delete_product',
						'id': id
					};
					
					jQuery.post(ajax_url, data, function(response) {
						if (response == '1') {
							window.open('/account/my-products/', '_self');
						} else {
							alert('Не удалось удалить: '+response);
						}
					});
				}
			</script>
			<?php 
            }
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 2
0
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>&nbsp;</td>
				<?php 
                        }
                        ?>
				
				<?php 
                        if ($row->sh_volume > 0) {
                            ?>
					<td><?php 
                            echo remove_decimal_part($row->sh_volume);
                            ?>
 м³</td>
				<?php 
                        } else {
                            ?>
					<td>&nbsp;</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;
}
Ejemplo n.º 3
0
function tzs_front_end_view_auction_handler($atts)
{
    ob_start();
    global $wpdb;
    $user_id = get_current_user_id();
    $sh_id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
    if ($sh_id <= 0) {
        print_error('Тендер не найден');
    } else {
        $sql = "SELECT * FROM " . TZS_AUCTIONS_TABLE . " WHERE id={$sh_id};";
        $row = $wpdb->get_row($sql);
        if (count($row) == 0 && $wpdb->last_error != null) {
            print_error('Не удалось отобразить информацию о тендер. Свяжитесь, пожалуйста, с администрацией сайта.');
        } else {
            if ($row == null) {
                print_error('Тендер не найден');
            } else {
                if (isset($_GET['spis'])) {
                    echo "<a id='edit_search' href='/account/my-auctions/'>Назад к списку</a> <div style='clear: both'></div>";
                } else {
                    echo "<button id='edit_search'  onclick='history.back()'>Назад к списку</button> <div style='clear: both'></div>";
                }
                ?>
                    <table border="0" id="view_ship">
			<tr>
				<td>Номер тендера</td>
				<td><?php 
                echo $row->id;
                ?>
</td>
			</tr>
			<tr>
				<td>Активен</td>
				<td><?php 
                echo $row->active == 1 ? 'Да' : 'Нет';
                ?>
</td>
			</tr>
			<tr>
				<td>Дата размещения</td>
				<td><?php 
                echo convert_date_no_year($row->created);
                ?>
 <?php 
                echo convert_time_only($row->time);
                ?>
</td>
			</tr>
			<?php 
                if ($row->last_edited != null) {
                    ?>
			<tr>
				<td>Дата последнего изменения</td>
				<td><?php 
                    echo convert_date_no_year($row->last_edited);
                    ?>
 <?php 
                    echo convert_time_only($row->last_edited);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->expiration != null) {
                    ?>
			<tr>
				<td>Дата окончания публикации</td>
				<td><?php 
                    echo convert_date_no_year($row->expiration);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->type_id > 0) {
                    ?>
			<tr>
				<td>Категория</td>
				<td><?php 
                    echo $row->type_id;
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Краткое описание товара/услуги</td>
				<td><?php 
                echo htmlspecialchars($row->title);
                ?>
</td>
			</tr>
			<tr>
				<td>Полное описание товара/услуги</td>
				<td><?php 
                echo htmlspecialchars($row->description);
                ?>
</td>
			</tr>
			<?php 
                if ($row->copies > 0) {
                    ?>
			<tr>
				<td>Количество</td>
				<td><?php 
                    echo $row->copies;
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->price > 0) {
                    ?>
			<tr>
				<td>Стартовая стоимость товара</td>
				<td><?php 
                    echo $row->price . " " . $GLOBALS['tzs_pr_curr'][$row->currency];
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->payment > 0) {
                    ?>
			<tr>
				<td>Форма оплаты</td>
				<td><?php 
                    echo $GLOBALS['tzs_pr_payment'][$row->payment];
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Местонахождение</td>
				<td><?php 
                echo tzs_city_to_str($row->from_cid, $row->from_rid, $row->from_sid, $row->city_from);
                ?>
</td>
			</tr>
			<?php 
                if (strlen($row->comment) > 0) {
                    ?>
			<tr>
				<td>Комментарии</td>
				<td><?php 
                    echo htmlspecialchars($row->comment);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if (strlen($row->image_id_lists) > 0) {
                    ?>
			<tr>
				<td>Изображения</td>
				<td><?php 
                    //$img_names = explode(';', $row->pictures);
                    $img_names = explode(';', $row->image_id_lists);
                    $main_image_id = $row->main_image_id;
                    if (count($img_names) > 0) {
                        ?>
                                    <table>
                                        <?php 
                        // Вначале выведем главное изображение
                        $attachment_info = wp_get_attachment_image_src($main_image_id, 'full');
                        if ($attachment_info !== false) {
                            echo '<tr><td><img src="' . $attachment_info[0] . '" alt=""></td></tr>';
                        }
                        // Затем выведем все остальные изображения
                        for ($i = 0; $i < count($img_names); $i++) {
                            if ($img_names[$i] !== $main_image_id) {
                                $attachment_info = wp_get_attachment_image_src($img_names[$i], 'full');
                                //if (file_exists(ABSPATH . $img_names[$i])) {
                                if ($attachment_info !== false) {
                                    echo '<tr><td><img src="' . $attachment_info[0] . '" alt=""></td></tr>';
                                }
                            }
                        }
                        ?>
                                    </table>
                                        <?php 
                    }
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			</table>

			<br/>
			<h1 class="entry-title">Контактная информация</h1>
			
			<?php 
                if ($user_id == 0 && $GLOBALS['tzs_au_contact_view_all'] == false) {
                    ?>
				<div>Для просмотра контактов необходимо <a href="/account/login/">войти</a> или <a href="/account/registration/">зарегистрироваться</a></div>
			<?php 
                } else {
                    if ($user_id != $row->user_id) {
                        ?>
			<?php 
                        tzs_print_user_table($row->user_id);
                        ?>
			
			<script src="/wp-content/plugins/tzs/assets/js/feedback.js"></script>
			
			<button id="view_feedback" onClick="<?php 
                        echo tzs_feedback_build_url($row->user_id);
                        ?>
">Отзывы <span>|</span> Рейтинг пользователя</button>
			<?php 
                    } else {
                        ?>
				<button id="view_del" onClick="javascript: promptDelete(<?php 
                        echo $row->id;
                        ?>
);">Удалить</button>
				<button id="view_edit" onClick="javascript: window.open('/account/edit-auction/?id=<?php 
                        echo $row->id;
                        ?>
', '_self');">Изменить</button>
			<?php 
                    }
                }
                ?>

			<br/>
                        <hr/>
			<h2 class="entry-title">Информация о ставках</h2>
                        <?php 
                // Отбор ставок по тендеру - active=1 AND
                $sql = "SELECT * FROM " . TZS_AUCTION_RATES_TABLE . " WHERE auction_id={$sh_id} ORDER BY active DESC,created DESC;";
                $res = $wpdb->get_results($sql);
                if (count($res) == 0 && $wpdb->last_error != null) {
                    print_error('Не удалось отобразить информацию о ставках. Свяжитесь, пожалуйста, с администрацией сайта.');
                } else {
                    if (count($res) == 0) {
                        print_error('Ставки не найдены');
                    } else {
                        ?>
                            <table border="0" id="tbl_products">
                                <tr>
                                        <th>Статус</th>
                                        <th id="tbl_products_dtc">Дата и время размещения</th>
                                        <th id="tbl_products_dtc">Дата и время отзыва</th>
                                        <th id="price">Предложенная стоимость</th>
                                        <th id="price">Автор</th>
                                        <?php 
                        if ($user_id !== 0 || $GLOBALS['tzs_au_contact_view_all'] !== false) {
                            ?>
                                        <th id="price">Контактные данные</th>
                                        <?php 
                        }
                        ?>
                                </tr>
                                <?php 
                        foreach ($res as $row) {
                            $user_info = get_userdata($row->user_id);
                            ?>
                                    <tr id="<?php 
                            echo $row->active == 1 ? 'tbl_auction_rate_active' : 'tbl_auction_rate_reviewed';
                            ?>
">
                                        <td><?php 
                            echo $row->active == 1 ? 'Активна' : 'Отозвана';
                            ?>
</td>
                                        <td><?php 
                            echo convert_time($row->created);
                            ?>
</td>
                                        <td><?php 
                            echo $row->reviewed == null ? '&nbsp;' : convert_time($row->reviewed);
                            ?>
</td>
                                        <td><?php 
                            echo $row->rate . " " . $GLOBALS['tzs_pr_curr'][$row->currency];
                            ?>
</td>
                                        <td><?php 
                            $meta = get_user_meta($row->user_id, 'fio');
                            echo $meta[0];
                            ?>
</td>
                                        <?php 
                            if ($user_id !== 0 || $GLOBALS['tzs_au_contact_view_all'] !== false) {
                                ?>
                                        <td>
                                            <?php 
                                $meta = get_user_meta($row->user_id, 'telephone');
                                echo $meta[0] == null ? '' : 'Номера телефонов: ' . htmlspecialchars($meta[0]) . '<br/>';
                                ?>
                                            <?php 
                                echo $user_info->user_email == null ? '' : 'E-mail: ' . htmlspecialchars($user_info->user_email) . '<br/>';
                                ?>
                                            <?php 
                                $meta = get_user_meta($row->user_id, 'skype');
                                echo $meta[0] == null ? '' : 'Skype: ' . htmlspecialchars($meta[0]) . '<br/>';
                                ?>
                                        </td>
                                        <?php 
                            }
                            ?>
                                    </tr>
                                <?php 
                        }
                        ?>
                            </table>
                        <?php 
                    }
                }
                ?>
                                
			<script>
				function promptDelete(id) {
					jQuery('<div></div>').appendTo('body')
						.html('<div><h6>Удалить запись '+id+'?</h6></div>')
						.dialog({
							modal: true,
							title: 'Удаление',
							zIndex: 10000,
							autoOpen: true,
							width: 'auto',
							resizable: false,
							buttons: {
								'Да': function () {
									jQuery(this).dialog("close");
									doDelete(id);
								},
								'Нет': function () {
									jQuery(this).dialog("close");
								}
							},
							close: function (event, ui) {
								jQuery(this).remove();
							}
						});
				}
				function doDelete(id) {
					var data = {
						'action': 'tzs_delete_auction',
						'id': id
					};
					
					jQuery.post(ajax_url, data, function(response) {
						if (response == '1') {
							window.open('/account/my-auctions/', '_self');
						} else {
							alert('Не удалось удалить: '+response);
						}
					});
				}
			</script>
			<?php 
            }
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 4
0
function tzs_front_end_view_shipment_handler($atts)
{
    ob_start();
    global $wpdb;
    $user_id = get_current_user_id();
    $sh_id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
    if ($sh_id <= 0) {
        print_error('Груз не найден');
    } else {
        $sql = "SELECT * FROM " . TZS_SHIPMENT_TABLE . " WHERE id={$sh_id};";
        $row = $wpdb->get_row($sql);
        if (count($row) == 0 && $wpdb->last_error != null) {
            print_error('Не удалось отобразить информацию о грузе. Свяжитесь, пожалуйста, с администрацией сайта');
        } else {
            if ($row == null) {
                print_error('Груз не найден');
            } else {
                $type = isset($GLOBALS['tzs_tr_types'][$row->trans_type]) ? $GLOBALS['tzs_tr_types'][$row->trans_type] : "";
                ?>
			<script src="/wp-content/plugins/tzs/assets/js/distance.js"></script>
			<?php 
                if (isset($_GET['spis'])) {
                    echo "<a id='edit_search' href='/account/my-shipments/'>Назад к списку</a> <div style='clear: both'></div>";
                } elseif (isset($_GET['link'])) {
                    echo "<a id='edit_search' href='/" . $_GET['link'] . "/'>Назад к списку</a> <div style='clear: both'></div>";
                } else {
                    echo "<button id='edit_search'  onclick='history.back()'>Назад к списку</button> <div style='clear: both'></div>";
                }
                ?>
            <table border="0" id="view_ship">
			<tr>
				<td>Номер груза</td>
				<td><?php 
                echo $row->id;
                ?>
</td>
			</tr>
			<tr>
				<td>Активно</td>
				<td><?php 
                echo $row->active == 1 ? 'Да' : 'Нет';
                ?>
</td>
			</tr>
			<tr>
				<td>Дата размещения</td>
				<td><?php 
                echo convert_date_no_year($row->time);
                ?>
 <?php 
                echo convert_time_only($row->time);
                ?>
</td>
			</tr>
			<?php 
                if ($row->last_edited != null) {
                    ?>
			<tr>
				<td>Дата последнего изменения</td>
				<td><?php 
                    echo convert_date_no_year($row->last_edited);
                    ?>
 <?php 
                    echo convert_time_only($row->last_edited);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Дата погрузки</td>
				<td><?php 
                echo convert_date_no_year($row->sh_date_from);
                ?>
</td>
			</tr>
			<tr>
				<td>Дата выгрузки</td>
				<td><?php 
                echo convert_date_no_year($row->sh_date_to);
                ?>
</td>
			</tr>
			<tr>
				<td>Пункт погрузки</td>
				<td><?php 
                echo tzs_city_to_str($row->from_cid, $row->from_rid, $row->from_sid, $row->sh_city_from);
                ?>
</td>
			</tr>
			<tr>
				<td>Пункт выгрузки</td>
				<td><?php 
                echo tzs_city_to_str($row->to_cid, $row->to_rid, $row->to_sid, $row->sh_city_to);
                ?>
</td>
			</tr>
			<tr>
				<td>Описание груза</td>
				<td><?php 
                echo htmlspecialchars($row->sh_descr);
                ?>
</td>
			</tr>
			<?php 
                if ($row->sh_weight > 0) {
                    ?>
			<tr>
				<td>Вес</td>
				<td><?php 
                    echo $row->sh_weight;
                    ?>
 т</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                if ($row->sh_volume > 0) {
                    ?>
			<tr>
				<td>Объем</td>
				<td><?php 
                    echo $row->sh_volume;
                    ?>
 м³</td>
			</tr>
			<?php 
                }
                ?>
			<tr>
				<td>Количество машин</td>
				<td><?php 
                echo $row->trans_count;
                ?>
</td>
			</tr>
			<tr>
				<td>Тип транспорта</td>
				<td><?php 
                echo $type;
                ?>
</td>
			</tr>
			<?php 
                if ($row->sh_length > 0 || $row->sh_height > 0 || $row->sh_width > 0) {
                    ?>
			<tr>
				<td>Габариты</td>
				<td>Длинна=<?php 
                    echo $row->sh_length;
                    ?>
м Ширина=<?php 
                    echo $row->sh_width;
                    ?>
м Высота=<?php 
                    echo $row->sh_height;
                    ?>
м</td>
			</tr>
			<?php 
                }
                ?>
			<?php 
                $cost = tzs_cost_to_str($row->cost);
                if (strlen($cost) > 0) {
                    ?>
			<tr>
				<td>Цена</td>
				<td><?php 
                    echo $cost;
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			
			<?php 
                if ($row->distance > 0) {
                    ?>
			<tr>
				<td>Расстояние</td>
				<td><?php 
                    echo tzs_make_distance_link($row->distance, false, array($row->sh_city_from, $row->sh_city_to));
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			
			<?php 
                if (strlen($row->comment) > 0) {
                    ?>
			<tr>
				<td>Комментарии</td>
				<td><?php 
                    echo htmlspecialchars($row->comment);
                    ?>
</td>
			</tr>
			<?php 
                }
                ?>
			</table>
			
			<?php 
                if ($user_id == 0) {
                    ?>
				<div>Для просмотра контактов необходимо <a href="/account/login/">войти</a> или <a href="/account/registration/">зарегистрироваться</a></div>
			<?php 
                } else {
                    if ($user_id != $row->user_id) {
                        ?>
			
			<br/>
			<h1 class="entry-title">Контактная информация</h1>
			
			<?php 
                        tzs_print_user_table($row->user_id);
                        ?>
			
			<script src="/wp-content/plugins/tzs/assets/js/feedback.js"></script>
			
			<button id="view_feedback" onClick="<?php 
                        echo tzs_feedback_build_url($row->user_id);
                        ?>
">Отзывы <span>|</span> Рейтинг пользователя</button>
			<?php 
                    } else {
                        ?>
				<button id="view_del" onClick="javascript: promptDelete(<?php 
                        echo $row->id;
                        ?>
);">Удалить</button>
				<button id="view_edit" onClick="javascript: window.open('/account/edit-shipment/?id=<?php 
                        echo $row->id;
                        ?>
', '_self');">Изменить</button>
			<?php 
                    }
                }
                ?>
			<script>
				function promptDelete(id) {
					jQuery('<div></div>').appendTo('body')
						.html('<div><h6>Удалить запись '+id+'?</h6></div>')
						.dialog({
							modal: true,
							title: 'Удаление',
							zIndex: 10000,
							autoOpen: true,
							width: 'auto',
							resizable: false,
							buttons: {
								'Да': function () {
									jQuery(this).dialog("close");
									doDelete(id);
								},
								'Нет': function () {
									jQuery(this).dialog("close");
								}
							},
							close: function (event, ui) {
								jQuery(this).remove();
							}
						});
				}
				function doDelete(id) {
					var data = {
						'action': 'tzs_delete_shipment',
						'id': id
					};
					
					jQuery.post(ajax_url, data, function(response) {
						if (response == '1') {
							window.open('/account/my-shipments/', '_self');
						} else {
							alert('Не удалось удалить: '+response);
						}
					});
				}
			</script>
			<?php 
            }
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 5
0
function tzs_front_end_feedback_handler($atts)
{
    ob_start();
    tzs_copy_get_to_post();
    $pp = TZS_FEEDBACKS_PER_PAGE;
    $id = isset($_POST['id']) && is_valid_num($_POST['id']) ? intval($_POST['id']) : 0;
    $page = isset($_POST['pg']) && is_valid_num($_POST['pg']) ? intval($_POST['pg']) : 1;
    $user_id = get_current_user_id();
    $user_info = $id > 0 ? get_userdata($id) : null;
    if ($user_info == null) {
        print_error('Пользователь не найден');
    } else {
        global $wpdb;
        $res_neg = $wpdb->get_row($wpdb->prepare("SELECT COUNT(*) as cnt FROM {$wpdb->comments} WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) AND comment_content like %s", $id, $user_id, '0%'));
        $res_pos = $wpdb->get_row($wpdb->prepare("SELECT COUNT(*) as cnt FROM {$wpdb->comments} WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) AND comment_content like %s", $id, $user_id, '2%'));
        $res_cnt = $wpdb->get_row($wpdb->prepare("SELECT COUNT(*) as cnt FROM {$wpdb->comments} WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )", $id, $user_id));
        $records = $res_cnt->cnt;
        $pages = ceil($records / $pp);
        if ($pages == 0) {
            $pages = 1;
        }
        if ($page > $pages) {
            $page = $pages;
        }
        $from = ($page - 1) * $pp;
        $rate = 0 - $res_neg->cnt + $res_pos->cnt;
        $rate_class = "feedback_neutral";
        if ($rate < 0) {
            $rate_class = "feedback_negative";
        } else {
            if ($rate > 0) {
                $rate_class = "feedback_positive";
            }
        }
        $u_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d AND user_id = %d", $id, $user_id));
        $u_exists = count($u_comment) > 0;
        $u_text = $u_exists ? substr($u_comment->comment_content, 1) : "";
        $u_type = $u_exists ? substr($u_comment->comment_content, 0, 1) : "1";
        $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt DESC LIMIT %d,%d", $id, $user_id, $from, $pp));
        ?>
	<div id="feedback_title">Компания <?php 
        $meta = get_user_meta($id, 'company');
        echo $meta[0];
        ?>
, контактное лицо &quot;<?php 
        $meta = get_user_meta($user_id, 'fio');
        echo $meta[0];
        //echo htmlspecialchars($user_info->display_name);
        ?>
&quot;</div>
	
	<div id="feedback_rating">
		Рейтинг: <span class="<?php 
        echo $rate_class;
        ?>
"><?php 
        echo $rate;
        ?>
</span>
	</div>
	
	<?php 
        if (count($comments) == 0) {
            ?>
			<div id="info">У этого пользователя еще нет отзывов.</div>
		<?php 
        } else {
            ?>
	<div id="feedback_content">
		<table>
			<tr>
				<th id="adds">Дата</th>
				<th id="type">Тип отзыва</th>
				<th id="auth">Автор</th>
				<th id="feedback">Отзыв</th>
			</tr>
			<?php 
            foreach ($comments as $row) {
                $cont = $row->comment_content;
                $type = substr($cont, 0, 1);
                $user_id = $row->user_id;
                $user_info = get_userdata($user_id);
                if (is_valid_num_zero($type)) {
                    $cont = substr($cont, 1);
                    if ($type == '0') {
                        $type = "<span id=\"negative\">Отрицательный<span>";
                    } else {
                        if ($type == '1') {
                            $type = "<span id=\"neutral\">Нейтральный<span>";
                        } else {
                            $type = "<span id=\"positive\">Положительный<span>";
                        }
                    }
                } else {
                    $type = "<span id=\"neutral\">Нейтральный<span>";
                }
                ?>
				<tr>
					<td><b><?php 
                echo convert_date_no_year($row->comment_date);
                ?>
</b><br/><?php 
                echo convert_time_only($row->comment_date);
                ?>
</td>
					<td><?php 
                echo $type;
                ?>
</td>
					<td><?php 
                echo $user_info->display_name;
                ?>
</td>
					<td><?php 
                echo htmlspecialchars($cont);
                ?>
</td>
				</tr>
				<?php 
            }
            ?>
		</table>
		<?php 
            build_pages_footer($page, $pages, "fpage");
            ?>
	</div>
	<?php 
        }
        ?>
	
	<div id="feedback_form">
		<input type="hidden" name="user_id" value="<?php 
        echo $id;
        ?>
"></input>
		<select name="feedback_type">
			<option value="0" <?php 
        if ($u_type == "0") {
            echo "selected";
        }
        ?>
>Отрицательный</option>
			<option value="1" <?php 
        if ($u_type == "1") {
            echo "selected";
        }
        ?>
>Нейтральный</option>
			<option value="2" <?php 
        if ($u_type == "2") {
            echo "selected";
        }
        ?>
>Положительный</option>
		</select>
		<textarea name="feedback_text"><?php 
        echo $u_text;
        ?>
</textarea>
		<?php 
        if ($u_exists) {
            ?>
			<button onClick="javascript:sendFeedback();">Изменить</button>
			<button onClick="javascript:delFeedback();">Удалить</button>
		<?php 
        } else {
            ?>
			<button onClick="javascript:sendFeedback();">Добавить</button>
		<?php 
        }
        ?>
	</div>
	
	<!--<button onClick="javascript:doReloadFeedback();">Обновить</button>-->
	
	<script>
		function sendFeedback() {
			var tp = jQuery("select[name=feedback_type] option:selected").attr('value');
			var cont = jQuery("textarea[name=feedback_text]").val();
			var id = jQuery("input[name=user_id]").val();
			
			var data = {
				'action': 'tzs_add_feedback',
				'cont': cont,
				'type': tp,
				'id': id
			};
			
			jQuery.post(ajax_url, data, function(response) {
				if (response != '1') {
					alert("Ошибка: "+response);
				} else {
					doReloadFeedback();
				}
			}).fail(function() {
				alert("Не удалось добавить/изменить отзыв. Попробуйте, пожалуйста, еще раз.");
			});
		}
		
		function delFeedback() {
			var id = jQuery("input[name=user_id]").val();
			
			var data = {
				'action': 'tzs_del_feedback',
				'id': id
			};
			
			jQuery.post(ajax_url, data, function(response) {
				if (response != '1') {
					alert("Ошибка: "+response);
				} else {
					doReloadFeedback();
				}
			}).fail(function() {
				alert("Не удалось удалить отзыв. Попробуйте, пожалуйста, еще раз.");
			});
		}
		
		function hijackFeedbackLinks() {
			jQuery('a[tag=fpage]').each(function() {
				jQuery(this).click(function(){
					feedback_page = parseInt(jQuery(this).attr('page'));
					doReloadFeedback();
					return false;
				});
			});
		}
		
		jQuery(document).ready(function() {
			hijackFeedbackLinks();
		});
	</script>
	
	<?php 
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}