<div  style="color:red;font-size: 15px " ><?php echo  $this->message; ?></div>
<div class="comm_div">
    <div class="comm_content_block">
        <h3>Manage Listing</h3>
        <div class="comm_content_block_items">
            <div id="msgBox" style="color: red"></div>
            <div class="btm-padding">
                    <form name="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>index/listing">
                        <span class="label-stl">Search</span>
                        <input type="text" value="<?php echo ($_POST['txtSearch'])?$_POST['txtSearch']:$this->txtSearch?>" class="txt_area_2 txt_bx" name="txtSearch" >&nbsp;
                        <input class="btn_styles butnstl" type="submit" name="btnSearch" value="Search">
                        <input type="hidden" value="<?php echo $this->sortfield?>" class="txt_area_2 txt_bx" name="txtSortField" >
                        <input type="hidden" value="<?php echo $this->order?>" class="txt_area_2 txt_bx" name="txtOrder" >
                        <input class="btn_styles butnstl" type="submit" name="btnExportExcel" value="Export to excel">
                        <!--<a class="btn_styles butnstl" href="<?php echo ConfigUrl::base();?>index/add">Post Ad</a>-->
                    </form>
                    <div class="clear"></div>
            </div>

            <table width="100%" cellspacing="1" cellpadding="0" border="0" class="list_table">
                <tbody>
                    <tr>
                        <th width="3%" valign="top" align="center">#</th>
                        <th width="31%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/listing/1/Title/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Ad Title</a></th>
                        <th width="31%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/listing/1/vFirstName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Posted By</a></th>
                        <th width="8%" valign="top" align="center"><a href="<?php echo ConfigUrl::base()?>index/listing/1/dPostDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Posted Date</a></th>
                        <th width="7%" valign="top" align="center"><a href="<?php echo ConfigUrl::base()?>index/listing/1/nStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Status</a></th>
                        <th width="5%" valign="top" align="center">Action</th>
                    </tr>
                    <?php
                    if(sizeof($this->resProducts)>0) {
                        $i=0;
                        foreach($this->resProducts as $row) {
                            $i++;
                            ?>
                <div id="listMsg<?php echo $row->nBusId;?>" style="color: red"></div>
                <div>
                    <tr class="row_color1" id="rate<?php echo $row->nBusId;?>">
                        <td valign="top" align="center"><?php echo ($this->page-1)*$this->pageMaxCount +$i//$i; ?></td>
                        <td valign="top" align="left"><a href="<?php echo ConfigUrl::base().'index/viewlisting/'.stripslashes($row->nBusId).'/'; ?> " target='_blank'><?php echo stripslashes($row->Title); ?></a></td>
                        <td valign="top" align="left"><?php echo stripslashes($row->vFirstName).' '.stripslashes($row->vLastName)?></td>
                        <td valign="top" align="center"><?php echo stripslashes($row->PostDate)?></td>
                        <td valign="top" align="center"><?php echo ($row->nStatus==0) ? "Pending" : "Approved"; ?></td>
                        <td valign="top" align="center"><a href="<?php echo ConfigUrl::base() ?>index/edit/<?php echo $row->nBusId?>" id="<?php echo $row->nBusId?>">Edit</a> / <a href="javascript:void(0);" id="<?php echo $row->nBusId?>" class="dellisting">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>
</div>

<!--  start paging..................................................... -->
<?php if($this->pageCount > 1) {  
    $sortParams = '';
    if(!empty($this->sortfield)) {
    $sortParams = '/'.$this->sortfield.'/'.$this->order;
    }
    $sortParams.= '/'. $this->txtSearch;
    ?>

<div class="pagination">
    <ul>

            <?php
            if($this->page != 1) {?>
        <li><a href="<?php echo ConfigUrl::base()?>index/listing/1<?php echo $sortParams;?>" class="page_first" >First</a></li>
        <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/listing/<?php if($this->page != 1) {echo ($this->page - 1).$sortParams; }else {echo $this->page; ?><?php $sortParams;}?>" >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/listing/<?php if($this->pageCount != $this->page) echo  $this->page + 1; else echo $this->pageCount; ?><?php echo $sortParams?>" >Next</a></li>
        <li><a class="page_last" href="<?php echo ConfigUrl::base()?>index/listing/<?php echo $this->pageCount; ?><?php echo $sortParams?>" >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() {
        $('.dellisting').click(function () {
            id =  $(this).attr("id");
            var answer = confirm("Are you sure want to delete the listing?")
            if (answer){
                if (id=='') {
                    return false;
                }
                var data = 'id='+ id;
                $.ajax({
                    url: "<?php echo ConfigUrl::base(); ?>index/deleteListing/",
                    type: "POST",
                    data: data,
                    cache: false,
                    success: function (html) {
                        if (html==1) {
                            $("#listMsg"+id).html('<font color="green">Listing deleted successfully</font>');
                            $("#listMsg"+id).fadeIn("Slow");
                            setTimeout(function() {$("#listMsg"+id).fadeOut("slow");$("#listMsg"+id).html('')},2000);
                            $('#rate'+id).fadeOut(1000);
                        }
                        else alert('Sorry, unexpected error. Please try again later.');
                    }
                });
            }
            return false;
        });

    });
</script>
