<?

session_start();

header( 'Content-type: text/html; charset=windows-1251' );

define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest' ) { exit(); }

if ( !isset( $_SESSION['iduser'] ) ) exit();

include_once ROOT_DIR . '/engine/config.php';
include_once ROOT_DIR . '/engine/function.php';

$id = ( int ) $_GET['id'];


?>
  <div class="modal fade bd-example-modal-lg" id="modalf" style="">
	  <div class="modal-dialog " role="document" >
		<div class="modal-content" style="width: 650px;">
		  <div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title">Комментарии к заданию №:<?=$id?></h4>
		  </div>
		  
		  <div class="modal-body modal-body-height-fix" style=""><!--Содержимое модального окна начало-->
		    <?
				$select_comm = mysql_query( "SELECT * FROM tasks_comment WHERE ident = '" . $id . "' ORDER BY date DESC" );
				if ( mysql_num_rows( $select_comm ) > 0 ) {
					while ( $select_comm_row = mysql_fetch_array( $select_comm ) ) {
						$comm_user = mysql_fetch_array( mysql_query( "SELECT id, username, avatar FROM user WHERE id = '" . $select_comm_row['iduser'] . "'" ) );
						if ( $select_comm_row['type'] == 1 ) {
							$comm_type = 'icon_task_bad';
							$comm_type_css = 'task_comm_bad';
							$comm_icon_task = 'comm-icon-task-bad';
							$glyphicon_thumbs = 'glyphicon-thumbs-down';
							$comm_title_task = 'Негативный отзыв';
						} else {
							$comm_type = 'icon_task_good';
							$comm_type_css = 'task_comm_good';
							$comm_icon_task = 'comm-icon-task-good';
							$glyphicon_thumbs = 'glyphicon-thumbs-up';
							$comm_title_task = 'Позитивный отзыв';
						}
						$month = array( 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек' );
						$comm_time = ( int ) date( 'd', $select_comm_row['date'] ) . ' ' . $month[( int ) date( 'm', $select_comm_row['date'] ) - 1] . ' ' . date( 'Y', $select_comm_row['date'] ) . ' в ' . date( 'H:i', $select_comm_row['date'] );
						?>
						<div class="wrap_comm_task <?=$comm_type_css?>">
						  <div class="comm-avatar">
							<a href="/id<?=$comm_user['id']?>" target="_blank"><img class="avatar img-circle" height="30" width="30" src="/temp/avatar/<?=$comm_user['avatar']?>" alt="" /></a>
						  </div>
						  <div class="<?=$comm_icon_task?>">
							<span class="glyphicon <?=$glyphicon_thumbs?>" aria-hidden="true" title="<?=$comm_title_task?>"></span>	
						  </div>
						  <div class="wrap_comm_text <?=$comm_type?>">
							<div class="comm_user_task">
							  <a href="/id<?=$comm_user['id']?>" target="_blank" style="color: #333333"><?=$comm_user['username']?></a>
							</div>
							<div class="comm-time"><?=$comm_time?></div>
							<div class="text-comm-task"><?=$select_comm_row['comm']?></div>
						  </div>
						</div>
						<?
					}
				} else {
					?>
					  <div class="vertical-align-main">
					    <div class="vertical-align-paragraph"><i class="fa fa-meh-o" aria-hidden="true"></i> У этого задания еще нет комментариев.</div>
					  </div>
					<?
				}
			?>
			<div class="error_modal_ultimate" > </div>
			<p style="display: none;" id="success_text"><span class="glyphicon glyphicon-info-sign"></span> Сообщение отправлено!</p>
		  </div><!--Содержимое модального окна конец-->
		  
		  <div class="modal-footer">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
		  </div>
		</div>
	  </div>
  </div>
	
  <script type="text/javascript">
	$(document).ready(function(){
		var options = {
			show : true
		}
		$('#modalf').modal(options);
		
		$('.glyphicon').tipTip({defaultPosition:'right'});
		
	});

	

  </script>