<div  style="color:red;font-size: 15px " ><?php echo  $this->message; ?></div>
<div class="comm_div">
    <div class="comm_content_block">
        <h3>Manage Plans</h3>
        <div>
            <table  width="99%">
                <tr>
                    
                    <td width="50%">
                        <div class="comm_content_block_items">
                            <form name="frmsearch" method="post" action="<?php echo ConfigUrl::base(); ?>index/listPlans">
                                <label class="labelstyle">Search                                                 </label>
                                <input type="text" value="<?php echo ($_POST['txtSearch']) ? $_POST['txtSearch'] : $this->txtSearch ?>" class="txt_area_2" name="txtSearch" >&nbsp;&nbsp;&nbsp;<input class="btn_styles" type="submit" name="btnSearch" value="Search">
                            </form>
                        </div>
                    </td><td>
                    </td>
                    <td align="right" width="57%">
                        <div>
                            <a href="<?php echo ConfigUrl::base() ?>index/plans/" class="btn_styles" style="text-decoration: none;">Add New Plan</a>
                        </div>
                    </td></tr>
            </table>
            <div class="comm_content_block_items">
                <div id="msgBox" style="color: red"></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="25%" valign="top" align="left"><a href="<?php echo ConfigUrl::base() ?>index/listPlans/0/vPlanName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC' ?>">Plan Title</a></th>
                            <th width="8%" valign="top" align="left"><a href="<?php echo ConfigUrl::base() ?>index/listPlans/0/vPlanAmount/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC' ?>">Amount(<?php echo CURRENCY ?>)</a></th>
                            <th width="10%" valign="top" align="center"><a href="<?php echo ConfigUrl::base() ?>index/listPlans/0/vPlanStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC' ?>">Status</a></th>
                            <th width="10%" 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->nPlanId; ?>" style="color: red"></div>
                            <div>
                                <tr class="row_color1" id="rate<?php echo $row->nPlanId; ?>">
                                    <td valign="top" align="center"><?php echo ($this->page - 1) * $this->pageMaxCount + $i; ?></td>
                                    <td valign="top" align="left"><a href="<?php echo ConfigUrl::base() . 'index/editPlanslist/' . stripslashes($row->nPlanId) . '/'; ?>"><?php echo stripslashes($row->vPlanName); ?></a></td>
                                    <td valign="top" align="left"><?php echo number_format(stripslashes($row->vPlanAmount), 2); ?></td>
                                    <td valign="top" align="center"><span id="status<?php echo $row->nPlanId ?>"><a href="javascript:void(0)" id="jqPlanStatus<?php echo $row->nPlanId ?>" onclick="changeStatus('<?php echo $row->nPlanId ?>','<?php echo $row->vPlanStatus ?>')"><?php echo ($row->vPlanStatus == E) ? "Active" : "Inactive"; ?></a></span></td>
                                    <td valign="top" align="center"><a href="<?php echo ConfigUrl::base() ?>index/editPlanslist/<?php echo $row->nPlanId ?>" id="<?php echo $row->nPlanId ?>">Edit</a> / <a href="javascript:void(0);" id="<?php echo $row->nPlanId ?>" 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>
</div>

           <!--  start paging..................................................... -->
         <?php //if($this->pageCount > 1){  ?>
           <div class="pagination">
               <ul>
                   <li><a href="<?php echo ConfigUrl::base() ?>index/listPlans/1/<?php echo $this->sortfield . '/' . $this->order . '/' . $this->txtSearch ?>" class="page_first" >First</a></li>
                   <li><a class="page_prev" href="<?php echo ConfigUrl::base() ?>index/listPlans/<?php if ($this->page != 1) echo $this->page - 1; else echo $this->page; ?>/<?php echo $this->sortfield . '/' . $this->order . '/' . $this->txtSearch ?>" >Previous</a></li>
                   <li class="pageinfo"><div id="page-info">Page <strong><?php echo $this->page; ?></strong> / <?php echo $this->pageCount; ?></div></li>
                   <li><a class="page_next" href="<?php echo ConfigUrl::base() ?>index/listPlans/<?php if ($this->pageCount != $this->page) echo $this->page + 1; else echo $this->pageCount; ?>/<?php echo $this->sortfield . '/' . $this->order . '/' . $this->txtSearch ?>" >Next</a></li>
                   <li><a class="page_last" href="<?php echo ConfigUrl::base() ?>index/listPlans/<?php echo $this->pageCount; ?>/<?php echo $this->sortfield . '/' . $this->order . '/' . $this->txtSearch ?>" >Last</a></li>
               </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/deletePlanlisting/",
                    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;
	});
        
    });
    
    
    function changeStatus(id,status)
    {
        if(status=='E'){
            if(!confirm("Are you sure you want to deactivate the plan?")){
                return false;
            }
        }
        else if(status=='D'){
            if(!confirm("Are you sure you want to activate the plan?")){
                return false;
            }
        }
        
        var data 	= 'id='  + id+'&status='+status;
        $.ajax({
            url: "<?php echo ConfigUrl::base(); ?>index/updatePlanStatus/",
            type: "POST",
            data: data,
            cache: false,
            success: function (html) {
                
                if (html==1) {
                    //$('#status'+id).load('<?php echo ConfigUrl::base(); ?>index/ajaxPlantatus?id='+id, function() {
                        //alert('Load was performed.');
                   // });

                     $.ajax({
                        url: "<?php echo ConfigUrl::base(); ?>index/ajaxplantatus/",
                        type: "POST",
                        data: {id:id},
                        cache: false,
                        success: function (html) {
                            if (html) {                              
                               $('#status'+id).html(html);
                               return false;
                            }
                            else alert('Sorry, unexpected error. Please try again later.');
                        }
                    });
                    
                    return false;
                }
                else alert('Sorry, unexpected error. Please try again later.');
            }
        });
    }
</script>
