<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="row">
				<div class="top_button_outer">
				<form name="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>ads/index">
				<div class="col-xs-12 col-sm-1"><span class="label-stl">Search</span></div>
				<div class="col-xs-12 col-sm-12 col-md-4 manage_listing_search">
					<div class="small_search_outer">
					<input type="text" value="<?php echo $this->txtSearch?>" class="form-control" name="txtSearch" >
                    <input type="hidden" value="<?php echo $this->sortfield?>" class="form-control" name="txtSortField" >
                    <input type="hidden" value="<?php echo $this->order?>" class="form-control" name="txtOrder" >
					<button type="submit" name="btnSearch" value="Search" class="small_search"><i class="fa fa-search" aria-hidden="true"></i>
</button>
					</div>
				</div>
			 
				<div class="col-xs-12 col-sm-6 col-md-3">
					<button type="submit" name="btnExportExcel" value="Export to Excel" class="small_red_btt">
						<i class="fa fa-upload" aria-hidden="true"></i>Export to Excel
					</button>
				</div>
				<div class="col-xs-12 col-sm-6 col-md-3">
					<a href="<?php echo ConfigUrl::base('default'); ?>postads" class="small_red_btt">
						<i class="fa fa-plus" aria-hidden="true"></i>
 Add Listing
					</a>
				</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="40%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>ads/index/1/Title/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Ad Title</a></th>
                        <th width="8%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>ads/index/1/dPostDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Posted Date</a></th>
                        <?php
                        if(SITE_PAYMENT_MODE =='paid'){?>
                            <th width="7%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>ads/index/1/nPlanExpiryDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Expiry Date</a></th>
                        <?php
                        }?>
                        <th width="7%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>ads/index/1/nStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Status</a></th>
                        <th width="8%" valign="top" align="left">Action</th>
                         <?php
                        if(SITE_PAYMENT_MODE =='paid'){?>
                            <th width="7%" valign="top" align="left">Renew</th>
                        <?php
                       }?>
                    </tr>
                    <?php
                    if(sizeof($this->resProducts)>0) {
                        $i=0;
                        //echopre($this->resProducts);
                        foreach($this->resProducts as $row) {
                            $i++;
                            ?>
                    <tr id="listingBox<?php echo $row->nBusId;?>" 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; ?>/ " target='_blank' style="color:#666;"><?php echo stripslashes($row->Title); ?></a></td>
                        <td valign="top" align="left"><?php echo date("m/d/Y",strtotime(stripslashes($row->dPostDate)));/*<?php echo stripslashes($row->dPostDate)*/?></td>
                         <?php
                        if(SITE_PAYMENT_MODE =='paid' ){?>
                            <td valign="top" align="left">
                                <?php /*echo ($row->vPlantype=='M')?stripslashes($row->nPlanExpiryDate):'-'*/?>
                             <?php echo ($row->vPlantype=='M')? date("m/d/Y",strtotime(stripslashes($row->nPlanExpiryDate))):'-'?>
                            </td>
                        <?php
                        }?>
                        <td valign="top" align="left"><?php echo ($row->nStatus==0) ? "Pending" : "Approved"; //if(strtotime(date('m/d/Y'))>strtotime($row->nPlanExpiryDate)){echo "Expired";}else{echo ($row->nStatus==0) ? "Pending" : "Approved";}//  ?></td>
                        <td valign="top" align="left"><a href="<?php echo ConfigUrl::base() ?>ads/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>
                         <?php
                        if(SITE_PAYMENT_MODE =='paid'){?>
                            <td valign="top" align="left">
                                <?php if($row->vPlantype=='M'){?>
                                    <a href="<?php echo ConfigUrl::base(); ?>index/renew/<?php echo $row->nBusId;?>">Renew</a>
                                <?php
                                }
                                else{
                                    echo"-";
                                }?>
                            </td>
                        <?php
                        }?>
                    </tr>
                            <?php
                        }
                    } else {
                        echo '<tr class="row_color1">
                      <td colspan="7">No Record Found</td></tr>';
                    }
                    ?>
                    <tr>
                        <td colspan="7" align="right"><!--a href="<?php echo ConfigUrl::base('default'); ?>postads">Add listing</a--></td>
                    </tr>
                </tbody></table>
			</div>
            <div class="clear"></div>
        </div>
    </div>
</div>

<!--  start paging..................................................... -->
<?php if($this->pageCount > 1) {
    $sortParams = '';
    if(!empty($this->sortfield)) {
    $sortParams = '/'.$this->sortfield.'/'.$this->order;
    }
    ?>
<div class="pagination">
    <ul>
            <?php if($this->page != 1) {?>
        <li><a href="<?php echo ConfigUrl::base()?>ads/index/1<?php echo $sortParams; ?>" class="page_first" >First</a></li>
        <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>ads/index/<?php if($this->page != 1) echo $this->page - 1; else echo $this->page; ?><?php echo $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()?>ads/index/<?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()?>ads/index/<?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(); ?>ads/drop/",
                    type: "POST",
                    data: data,
                    cache: false,
                    success: function (html) {
                        if (html==1) {
                            $("#listingBox"+id).remove();
                            $("#msgBox").html('<font color="green">Listing deleted Successfully</font>');
                            $("#msgBox").fadeIn("Slow");
                            setTimeout(function() {$("#msgBox").fadeOut("slow");$("#msgBox").html('')},2000);
                            $("#msgBox").fadeOut(10000);
                        } else { alert('Sorry, unexpected error. Please try again later.'); }
                    }
                });
            }
            return false;
        });
    });
</script>
