Skip to content

Instantly share code, notes, and snippets.

@morozVA
Created April 14, 2018 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morozVA/c18871c021067fd1dc979c4cea573e8e to your computer and use it in GitHub Desktop.
Save morozVA/c18871c021067fd1dc979c4cea573e8e to your computer and use it in GitHub Desktop.
evo пример модуля отзывов
?>
<h1>Отзывы</h1>
<ul id="tabs">
<li><a title="tab1" href="#">Опубликованные отзывы</a></li>
<li><a title="tab2" href="#">Неопубликованные отзывы</a></li>
</ul>
<div id="content">
<?php
/*Функция makeTab выводит отзывы из бд в модуль, обеспечивает редактирование записей и вывод отзывов на сайте.
Параметры:
$pub=0 - неопубликованные отзывы
$pub=1 - опубликованные отзывы
*/
function makeTab ($pub){
global $modx;
$pub ==1?$pub_ = 0:$pub_ = 1;
if($pub ==1){
$pub_text='опубликован';
$pub_text_='не опубликован';
}
else{
$pub_text='не опубликован';
$pub_text_='опубликован';
}
$url = $_GET['referer'];
$output = '<table>
<thead>
<tr>
<!--<td>№</td>style="display:none;"-->
<td>Дата отзыва</td>
<td>Название товара</td>
<td>Текст отзыва</td>
<td>Oценка</td>
<td>Имя отправителя</td>
<td>Статус публикации</td>
<td></td>
</tr>
</thead>
<tbody>';
$res = $modx->db->query('SELECT * FROM `reviews`,`modx_site_content` where `publish_review`="'.$pub.'" and `modx_site_content`.`id`=`reviews`.`id_product` ORDER BY `date_review` DESC' );
while($row = $modx->db->getRow($res)) {
$parent_ =$row['parent'];
$id=$row['id_review'];
$result = $modx->db->query('SELECT `alias` FROM `modx_site_content` where `modx_site_content`.`id`="'.$parent_.'"');//3
$row_ = $modx->db->getRow($result);
$category = $row_["alias"];
$page_id = $row['id'];
if($page_id == "1"){
$page ="Отзыв о магазине";
$link='http://iris.qmedia.by';
}
else{
$page = $row['pagetitle'];
$link='http://iris.qmedia.by/katalog/'.$category.'/'.$row['alias'].'.html';
}
$output .= '<tr>
<td>'.$row['date_review'].'</td>
<td><a href="'.$link.'" target="_blank">'.$page.'</a></td>
<td class="textar">'.$row["text_review"].'</td>
<td>'.$row["rating_review"].'</td>
<td>'.$row['name_review'].' ('.$row['email_review'].')</td>
<td>
<select name="publish_review" disabled>
<option value="'.$pub.'" selected>'.$pub_text.'</option>
<option value="'.$pub_.'">'.$pub_text_.'</option>
</select>
</td>
<td>
<input type="button" class="edit" name="edit" title="Редактировать" value="">
<input type="submit" class="save" name="save" value="'.$row['id_review'].'" title="Сохранить">
</td>
</tr>' ;
}
$output .='</tbody></table>';
echo $output;
if(isset($_POST['save'])){
$save = $_POST['save'];
//var_dump($save);
$text=$_POST['text_review'];
$publish=$_POST['publish_review'];
$res_ = $modx->db->query("UPDATE `reviews` SET `text_review`= '$text', `publish_review`='$publish' where `id_review` = '$save'");
if ($res_== 'true') {
?>
<Script language="JavaScript">window.location = '<?=$url; ?>';</Script>
<?php
}
}
}//function
?>
<div id="tab1">
<form action="" method="post" id="pub">
<?php
makeTab(1);
?>
</form>
</div><!--end of tab1-->
<div id="tab2">
<form action="" method="post" id="unpub">
<?php
makeTab(0);
?>
</form>
</div><!--end of tab2-->
</div><!--end of content-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script>
$(document).ready(function() {
$("#content>div").hide(); // Скрытое содержимое
var cookie1 = $.cookie('tabActive');
if(cookie1==null){
$("#content>div").hide(); // Скрытое содержимое
}
else{
var cookie2 = '#' + cookie1;
if(cookie2 =='#tab1' || cookie2 =='#tab2' || cookie2 =='#tab3'){
$("#tabs").css("display", "block");
$("#content").css("display", "block");
$("#content").find(cookie2).fadeIn();
var tabUp = cookie2.slice(-1);
if (tabUp=='1'){
$("#tabs li:first").attr("id","current");
}
else if(tabUp=='2'){
$("#tabs li:eq(1)").attr("id","current");
}
else{
$("#tabs li:last").attr("id","current");
}
}
}//if cookie exists
$('#tabs a').click(function(e) {
e.preventDefault();
$("#content>div").hide(); //Скрыть всё содержимое
$("#tabs li").attr("id",""); //Сброс идентификаторов
$(this).parent().attr("id","current"); // Активация идентификаторов
$('#' + $(this).attr('title')).fadeIn(); // Показать содержимое текущей вкладки
var tab = $(this).attr('title');//for saving id of the active tab in cookie, using for page updating
$.cookie('tabActive', tab);
});
$('td').on('click', '.edit', function(e){
e.preventDefault();
$(this).parent().find('.save').css('visibility','visible');
$(this).parent().parent().siblings("tr").find('.save').css('visibility','hidden');
if(($(this).parent().find('.save').css('visibility'))=='visible'){
$(this).parent().parent().siblings("tr").find('textarea').attr("disabled","disabled");
var textarVal = $(this).parent().siblings(".textar").text();
var text = '<textarea class="textReview" name="text_review">'+textarVal+'</textarea>';
$(this).parent().parent().find(".textar").html(text);
$(this).parent().parent().siblings("tr").find('select').attr("disabled","disabled").removeClass('editable');
$(this).parent().parent().find("select").removeAttr("disabled").addClass('editable');
}
});
});//ready
</script>
<style>
textarea:disabled {
background:transparent !important;
border:none;
min-height: 35px;
}
select{
border: none;
background: transparent;
}
table{
border-collapse: collapse;
border:none;
}
thead{
color: #fff;
}
thead td{
background: #B60064;
}
textarea{
height: 100%;
border: none;
background: #fff !important;
width:100%;
min-height: 80px;
border: 1px solid #d8d8d8;
}
td:first-of-type{
width:12%;
}
td:nth-of-type(2){
width:12%;
}
td:nth-of-type(3){
width:24%;
}
td:nth-of-type(4){
width:5%;
}
td:nth-of-type(5){
width:10%;
}
td:nth-of-type(6){
width:3%;
}
td:last-of-type{
width:18%;
}
#tab1 table, #tab2 table{
margin: 0;
border: none;
font-family: Tahoma, Geneva, sans-serif;
}
tbody tr:nth-of-type(2n){
background: rgba(182, 0, 100,0.04);
}
tbody tr:nth-of-type(2n) textarea{
background:transparent;
}
#tab1 td, #tab2 td{
/*display: inline-block;*/
padding: 5px 5px;
font-size:12px;
border: 1px solid #d8d8d8;
}
#tab1 ul span>input, #tab2 ul span>input{
padding:0;
}
#tab1 ul input[type='submit'], #tab2 ul input[type='submit'], #tab3 ul input[type='submit']{
display: inline-block;
}
ul .delete{
color: transparent;
}
#tab1 ul input[type='text'], #tab2 ul input[type='text'], #tab3 ul input[type='text']{
border: none;
background: transparent;
width:50%;
color: inherit;
margin: 0 8px 0 0;
height: 30px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
.save { /*#tab2 ul input.save1*/
display: inline-block;
width:75px;
height: 30px;
line-height: 30px;
margin:0 0px;
visibility: hidden;
vertical-align: middle;
border: none;
cursor: pointer;
}
.edit{ /*, , .delete, .add.edit1, .add1*/
width: 30px;
height: 30px;
background-color: #dee1e7;
cursor: pointer;
border: 1px solid #a4aab9;
border-radius: 3px;
padding: 10px;
background-repeat: no-repeat;
background-position: 50%;
margin: 0px;
}
.edit{ /*, .edit1*/
background-image: url("../assets/templates/qmedia/images/edit-icon.png");
vertical-align: bottom;
}
ul input.editable[type='text'], textarea.editable, select.editable{
border:1px solid #ccc !important;
background:#fff !important;
}
#tabs{
overflow: auto;
margin: 0;
padding: 0;
}
#tabs li{
margin: 0;
padding: 0;
float: left;
list-style-type:none;
}
#tabs a{
background: #B60064;
text-shadow: 0 1px 0 rgba(0,0,0,.5);
color: #fff;
float: left;
font: bold 15px/32px 'Lucida sans', Arial, Helvetica;
height: 32px;
padding: 0 30px;
text-decoration: none;
border-right: 2px solid white;
}
#tabs a:hover {
background: #333;
}
#tabs a:focus{
outline: 0;
}
#tabs #current a{
background: #333;
text-shadow: none;
color: #fff;
}
#content ul{
padding:0;
}
#tab1, #tab2, #tab3{
border: 1px solid #B60064;
padding: 15px;
width:730px;
position: relative;
}
select {
padding: 0 2px;
-webkit-border-radius: 4px;
border-radius: 4px;
height: 30px;
}
input.save { /* input.save1*/
height: 30px;
background-color: #B60064;
border: none;
cursor: pointer;
margin-left:3px;
}
input[type='submit']:hover, input.save:hover, input[type='button']:hover {
background-color: #B60064;
}
form {
margin-bottom: 0px;
}
h4 {
margin: 30px 0px 10px 0px;
}
.save{
background: url("../assets/images/save.jpg") no-repeat 50% 50%;
background-size: 75px 30px;
color: transparent;
display:inline-block;
}
tr>td:last-of-type{
border: none !important;
background: #fff !important;
padding-right: 0 !important;
}
td>a:hover{
text-decoration:none;
}
.save:hover{
background: url("../assets/images/saveHover.jpg") no-repeat 50% 50%;
background-size: 75px 30px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment