<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 Ratings</h3>
        <div class="comm_content_block_items">
            <div style="color: red" id="rateMsg7"></div><div>
			
			<div class="row">
				<div class="top_button_outer">
				<form name="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>index/ratings">
				<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>
			
			<div class="table-responsive">
			<table width="100%" cellspacing="1" cellpadding="0" border="0" class="table table-bordered table-striped">

                <tbody><tr>
                        <th width="4%" valign="top" align="left">#</th>
                        <th width="40%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/ratings/1/Title/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Ad Title</a></th>
                        <th width="7%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/ratings/1/nRate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Rating</a></th>
                        <th width="8%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/ratings/1/dDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Date</a></th>
                        <th width="7%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/ratings/1/nStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Status</a></th>
                        <th width="5%" valign="top" align="left">Action</th>
                    </tr>


                    <?php
                    if(sizeof($this->resRatings)>0) {
                        $i=0;
                        foreach($this->resRatings as $row) {
                            $i++;
                            ?>
                <div id="rateMsg<?php echo $row->nId;?>" style="color: red"></div>
                <div>

                    <tr id="rate<?php echo $row->nId;?>" class="row_color1">
                        <td valign="top" align="left"><?php echo ($this->page-1)*$this->pageMaxCount +$i; ?></td>
                        <td valign="top" align="left"><a href="<?php echo ConfigUrl::base();?>index/viewlisting/<?php echo $row->alias; ?>/ " style="color:#666;"><?php echo stripslashes($row->Title)?></a></td>
                        <td valign="top" align="left" id="divCommVal"><div id="rating_1" class="rating_<?php echo stripslashes($row->nRate)?>"></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==0)?"<span id=\"status$row->nId\"><a href='javascript:void(0)' id=\"$row->nId\"  class='approveratings'>Approve</a></span>":"Approved"; ?></td>
                        <td valign="top" align="left"><a href="javascript:void(0);" id="<?php echo $row->nId?>" class="delratings" >Delete</a>
                        </td>
                    </tr>
                </div>
                        <?php
                    }
                }
                else
                    echo '<tr class="row_color1">
        <td colspan="6">No Record Found</td></tr>';
                ?>

                </tbody>
				</table>
			<div class="clear"></div>
			</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/ratings/1/" class="page_first" >First</a></li>
        <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/ratings/<?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/ratings/<?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/ratings/<?php echo $this->pageCount; ?>/" >Last</a></li>
                <?php
            }?>
    </ul>
    <div class="clear"></div>
</div>
    <?php
}
?>
<div id="divComm" style="top: 100px;left: 300px;position: absolute;background-color: gray"></div>
<script type="text/javascript">
    $(document).ready(function() {
        $('.delratings').click(function () {
            id =  $(this).attr("id");
            var answer = confirm("Are you sure want to delete the Rating?")
            if (answer){
                if (id=='') {
                    return false;
                }
                var data = 'id='+ id;
                $.ajax({
                    url: "<?php echo ConfigUrl::base(); ?>index/deleteRating/",
                    type: "POST",
                    data: data,
                    cache: false,
                    success: function (html) {
                        if (html==1) {
                            $("#rateMsg"+id).html('<font color="green">Ratings deleted Successfully</font>');
                            $("#rateMsg"+id).fadeIn("Slow");
                            setTimeout(function() {$("#rateMsg"+id).fadeOut("slow");$("#rateMsg"+id).html('')},2000);
                            $('#rate'+id).fadeOut(1000);
                        }
                        else alert('Sorry, unexpected error. Please try again later.');
                    }
                });
            }
            return false;
        });
        $('.approveratings').click(function () {
            id =  $(this).attr("id");
            if (id=='') {
                return false;
            }
            var data = 'id='+ id;
            $.ajax({
                url: "<?php echo ConfigUrl::base(); ?>index/approveRating/",
                type: "POST",
                data: data,
                cache: false,
                success: function (html) {
                    if (html==1) {
                        $("#rateMsg"+id).html('<font color="green">Ratings Approved Successfully</font>');
                        $("#rateMsg"+id).fadeIn("Slow");
                        $("#status"+id).html("Approved");
                        setTimeout(function() {$("#rateMsg"+id).fadeOut("slow");$("#rateMsg"+id).html('')},2000);
                    }
                    else alert('Sorry, unexpected error. Please try again later.');
                }
            });

        });
    });
</script>
