<div  style="color:red;font-size: 15px " ><?php if(isset($this->message)){ echo  $this->message; } ?></div>
<div class="comm_div">
    <div class="comm_content_block">
        <h3>Manage Comments</h3>
        <div class="comm_content_block_items">
		<div class="row">
				<div class="top_button_outer">
				<form name="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>index/comments">
				<div class="col-xs-12 col-sm-1"><span class="label-stl">Search</span></div>
				<div class="col-xs-12 col-sm-4">
					<div class="small_search_outer">
                                        <input type="text" value="<?php if(isset($_POST['txtSearch'])){ echo $_POST['txtSearch']; }else{ if(isset($this->txtSearch)){ echo $this->txtSearch; } } ?>" class="form-control" name="txtSearch" >
					<button type="submit" name="btnSearch" value="Search" class="small_search">
						<i class="fa fa-search" aria-hidden="true"></i>
					</button>
					</div>
				</div>
			  
				<div class="clearfix"></div>
				</form>
				</div>
			</div>
			
		
		<div class="table-responsive">
            <table width="100%" cellspacing="1" cellpadding="0" border="0" class="table table-bordered table-striped">

                <tbody><tr>
                        <th width="3%" valign="top" align="left">#</th>
                        <th width="16%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/comments/1/vName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Name</a></th>
                        <th width="20%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/comments/1/vEmail/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Email</a></th>
                        <th width="25%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/comments/1/Title/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Ad Title</a></th>
                        <th width="25%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/comments/1/vComment/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Comment</a></th>
                        <th width="20%" valign="top" align="left"><a href ="<?php echo ConfigUrl::base()?>index/comments/1/dDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Added Date</a></th>
                        <th width="12%" valign="top" align="left"><a href ="<?php echo ConfigUrl::base()?>index/comments/1/nStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Status</a></th>
                        <th width="12%" valign="top" align="left">Action</th>
                    </tr>


                    <tr  class="row_color1" id="jq_messagerow" style="display:none;"><td colspan="6"><div id="commMsg" style="color: red;"> </div></td></tr>
                    <?php
                    if(sizeof($this->resComments)>0) {
                        $i=0;
                        foreach($this->resComments as $row) {
                            $i++;
                            ?>

                    <tr class="row_color1">
                        <td valign="top" align="left"><?php echo ($this->page-1)*$this->pageMaxCount +$i; ?></td>
                        <td valign="top" align="left"><?php echo stripslashes($row->vName)?></td>
                        <td valign="top" align="left"><?php echo stripslashes($row->vEmail)?></td>
                        <td valign="top" align="left"><a href="<?php echo ConfigUrl::base();?>index/viewlisting/<?php echo $row->alias; ?>/ " target='_blank' style="color:#666;"><?php echo stripslashes($row->Title)?></a></td>
                        <td  valign="top" align="left" id="divCommVal">
							<?php echo substr(stripslashes($row->vComment),0,50)."...";?>
						<!--<div class="table_tooltip_outer">-->
							<!--<div onmouseover="showComment(event,'<?php //echo $row->nId?>')" onmouseout="hideComment('<?php //echo $row->nId?>')" ><?php //echo substr(stripslashes($row->vComment),0,50)."...";?>
							</div>
							<div style="display:none;" class="table_tooltip_inner" id="divCommText<?php echo $row->nId?>"><?php echo stripslashes($row->vComment);?></div>
						</div>-->
						</td>
                        <td  valign="top" align="left"><?php echo date("m/d/Y",strtotime(stripslashes($row->dDate)))?></td>
                        <td  valign="top" align="left" id="divStatusVal"><?php echo ($row->nStatus==1)?"Approved":"Not Approved";?></td>
                        <td   valign="top" align="left">
							<a href="" onclick="loadComment(event,'<?php echo $row->nId?>')" data-comid="<?php echo $row->nId?>" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Edit</a> 
							


						</td>
                    </tr>
                            <?php
                        }
                    } else { ?>
                        <tr>
                            <td colspan="8">No Record Found</td>
                        </tr>
                    <?php } ?>
                </tbody>
				</table>
			</div>
            <div class="clear"></div>
        </div>
    </div>
</div>

<!--  start paging..................................................... -->
<?php if($this->pageCount > 1) {  ?>

<div class="pagination">
    <ul>
            <?php if($this->page != 1) {?>
        <li><a href="<?php echo ConfigUrl::base()?>index/comments/1/" class="page_first" >First</a></li>
        <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/comments/<?php if($this->page != 1) echo $this->page - 1; else echo $this->page; ?>/" >Previous</a></li>
                <?php
            }?>
        <li class="pageinfo"><div id="page-info">Page <strong><?php echo $this->page; ?></strong> / <?php echo $this->pageCount; ?></div></li>
            <?php if($this->pageCount != $this->page) {?>
        <li><a class="page_next" href="<?php echo ConfigUrl::base()?>index/comments/<?php if($this->pageCount != $this->page) echo  $this->page + 1; else echo $this->pageCount; ?>/" >Next</a></li>
        <li><a class="page_last" href="<?php echo ConfigUrl::base()?>index/comments/<?php echo $this->pageCount; ?>/" >Last</a></li>
                <?php
            }?>
    </ul>
    <div class="clear"></div>
</div>

    <?php
}
?>
<div id="divComm" style="top: 0px;left:0px;position: absolute;background-color: gray"></div>
<script>
    function showComment(e,id)
    {
        var posx =0;var posy=0;
        if (!e){var e = window.event;}
        if (e.pageX || e.pageY){
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY){
            posx = e.clientX;
            posy = e.clientY;
        }
        $('#divCommText'+id).css("top",posy+15);
        $('#divCommText'+id).css("left",posx);
        $('#divCommText'+id).fadeIn();
    }
    function hideComment(id)
    {
        $('#divCommText'+id).fadeOut("slow");
    }




    function loadComment(e,id)
    {
        var posx =0;var posy=0;
        if (!e){var e = window.event;}
        if (e.pageX || e.pageY){
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY){
            posx = e.clientX;
            posy = e.clientY;
        }
        $('#divComm').fadeIn("slow");
        $('#divComm').css("top",posy+20);
        $('#divComm').css("left",posx-480);
        if(!$('#divComm .modal').length)
            $('#divComm').load('<?php echo ConfigUrl::base()?>index/loadComments?id='+id, function() {
                $('body').addClass('modal-open').append('<div class="modal-backdrop fade in"></div>');
                $('#divComm .modal').addClass('in').show();
            });
    }
    function load(){

        var comm      =    $("#txtComment").val();
        var status    =    $("#cmbStatus").val();
        var id        =    $("#id").val();
        if(comm=="" || id=="")
        {
            $("#divCommReq").html("Please Enter Comment");
        }
        else
        {
            var data 	= 'id='  + id+'&comm='+comm+'&status='+status;
            $.ajax({
                url: "<?php echo ConfigUrl::base(); ?>index/updateComments/",
                type: "POST",
                data: data,
                cache: false,
                success: function (html) {
                    if (html==1) {
                        $("#divComm").html("");
                        $('.modal-backdrop').remove();
                        $('body').removeClass('modal-open');
                        $("#divCommVal").html(comm);
                        if(status==1)$("#divStatusVal").html("Approved");
                        else $("#divStatusVal").html("Not Approved");

                        /*$("#cat"+id).hide("slow");
                              $("#catVal"+id).html(cat);
                              $("#catVal"+id).show("slow");*/
                        $("#jq_messagerow").show();
                        $("#commMsg").html('<font color="green">Comment updated Successfully</font>');
                        $("#commMsg").fadeIn("Slow");
                        //                                    setTimeout(function() {$("#commMsg").fadeOut("slow");$("#commMsg").html('')},2000);
                        $("#jq_messagerow").hide(2005);
                        return false;
                    }
                    if (html==2)
                        $("#divCommReq").html("Please Enter Comment");

                    else alert('Sorry, unexpected error. Please try again later.');
                }
            });
        }

    }
	
if(typeof $(document).on === 'function') {
    $('#myModal').on('shown.bs.modal', function () {
      $('#myInput').focus()
    })

    $('.modal .close').on('click', function(){ 
        $("#divComm").html("");
        $('.modal-backdrop').remove();
        $('body').removeClass('modal-open');
    })
} else {
    $('#myModal').live('shown.bs.modal', function () {
      $('#myInput').focus()
    })

    $('.modal .close').live('click', function(){ console.log('12');
        $("#divComm").html("");
        $('.modal-backdrop').remove();
        $('body').removeClass('modal-open');
    })
}

$(document).ready(function(){
    $('html').click(function(e) {
      if (e.target.id != 'divComm' && $(e.target).parents('.modal-dialog').length == 0) {
        $("#divComm").html("");
        $('.modal-backdrop').remove();
        $('body').removeClass('modal-open');
      }
    });
})

</script>
