<?php include("links/top.php");
$action=$_GET['action'];
?>
<?php 
if($action=='delete'){
$id=$_GET['id'];
$del="delete from news where id='$id'";
$DB->executeQuery($del);
header('Location:news.php?action=list');
}
?>
	<?php 
	if($action=='addnew' || $action== 'edit'){
	if($action=='edit'){
	$id=$_GET['id'];
	}
	if(isset($_POST['submit']) || isset($_POST['update'])){
	
	extract($_POST);
	
	if($action=='addnew'){
		$arr=array('title' 		=> addslashes($title),'coupon_code' 		=> addslashes($coupon_code),'value' 		=> addslashes($value),'about' 		=> addslashes($about),'description' => addslashes($description)); 
		$DB->insert('news',$arr);
		$id=getRecordId();							
	}
	if($action=='edit'){
		$arr=array( 'title' 		=> addslashes($title),'coupon_code' 		=> addslashes($coupon_code),'value' 		=> addslashes($value),'about' 		=> addslashes($about),'description' => addslashes($description));
		$DB->update('news',$arr,"id='$id'");
	}
	
header('Location: news.php?action=list');
	}
	}
	?>	
		<div id="content">
			<div class="container">
				<div class="page-header">
					<div class="page-title">
						<h3>Coupon Management</h3>
					</div>
				</div>
				<div class="row">
               
					<div class="col-md-12">
                    <?php if($action=='list'){?> <a href="news.php?action=addnew"><button class="btn btn-sm btn-info">Add Coupon</button></a> <?php } ?>                   
						<div class="widget box">
                        <div class="widget-header">
						<?php if($action=='list'){?>
                            <h4>Coupon List</h4>
                            <?php }else if($action=='addnew'){ ?>
                            <h4>Add Coupon</h4>
                            <?php }?>					
							</div>
                        <div class="widget-content">
                             <?php if($action=='list'){
								 $sno=1;
								$sel=executeQuery("select * from news");
								?>							
							
								<table class="table table-striped table-bordered table-hover table-checkable datatable">
									<thead>
										<tr>
											<!-- <th class="checkbox-column"><input type="checkbox" class="uniform"></th> -->
                                 <th>S.No</th>
								 <th>Coupon Title</th>
								  <th>Coupon Code</th>
								  <th>Coupon Value</th>
								 <!--<th>Sorting</th>-->
                                 <th>Status</th>
								 <th>Action</th>
										</tr>
									</thead>
									<tbody>
                                    <?php
								  $sno=1;
								 while($rec=getAssoc($sel)){?>
										<tr>
											<!--<td class="checkbox-column"><input type="checkbox" class="uniform"></td>-->
                                 <td><?php echo $sno;?></td>
											<td><?php echo $rec['title'];?></td>
											<td><?php echo $rec['coupon_code'];?></td>
												<td><?php echo $rec['value'];?></td>
												
                              <?php /* <td class="col-md-1"><input type="number" min="0" value="<?php echo $rec['sorting'];?>" id="sorting<?php echo $rec['id'];?>" onBlur="changesort('<?php echo $rec['id'];?>','news')" onKeyUp="changesort('<?php echo $rec['id'];?>','news')" class="form-control"></td>
                              */ ?>
                                 <td><a href="javascript:void(0)" id="status<?php echo $rec['id'];?>" onclick="return status(<?php echo $rec['id'];?>,'news')"><?php if($rec['status']==1){echo 'Active';}else{echo 'Inactive';}?></a></td>
											<td>
                                             <a href="news.php?action=edit&id=<?php echo $rec['id'];?>" title="Edit"><i class="icol-pencil"></i></a> &nbsp;&nbsp;
										 <a href="news.php?action=delete&id=<?php echo $rec['id'];?>" onClick="return confirm('Are you sure you want to delete ?')" title="Delete"><i class="icol-cross"></i></a>
                                            </td>
										</tr>
                                        <?php $sno++;}?>
									</tbody>
								</table>
							
                            <?php }else if($action=='addnew' || $action=='edit'){?>
					
							<?php if($action=='edit'){
                            $id=$_GET['id'];
                            $e="select * from news where id='$id'";
                            $ed=$DB->executeQuery($e);
                            $edi=$DB->getAssoc($ed);
                            }?>
														
								<form class="form-horizontal" id="validate-1" method="post" novalidate="novalidate" enctype="multipart/form-data">
									<div class="form-group">
										<label class="col-md-2 control-label">Coupon Title <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="title" class="form-control required" value="<?php if($action=='edit'){echo $edi['title'];}?>">
										</div>
									</div>
									<div class="form-group">
										<label class="col-md-2 control-label">Coupon Code <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="coupon_code" class="form-control required" value="<?php if($action=='edit'){echo $edi['coupon_code'];}?>">
										</div>
									</div>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Coupon Value <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="value" class="form-control required" value="<?php if($action=='edit'){echo $edi['value'];}?>">
										</div>
									</div> 
                                    
                                    <?php /* <div class="form-group">
										<label class="col-md-2 control-label">Small Description</label>
										<div class="col-md-4">
											<textarea name="about" class="form-control"><?php if($action=='edit'){echo $edi['about'];}?></textarea>
										</div>
									</div>
                            <div class="form-group">
										<label class="col-md-2 control-label">Description</label>
										<div class="col-md-12 clearfix" style="clear:both; margin-top:40px;">
											<textarea id="description" name="description" class="ckeditor"><?php if($action=='edit'){echo $edi['description'];}?></textarea>
										</div>
									</div>  
									*/ ?>
									
									<div class="form-actions">
                                    <label class="col-md-2">&nbsp;</label>
                                    <?php if($action=='addnew'){?>
									<input class="btn btn-info pull-left" type="submit" name="submit" value="Submit" />
									<?php }else if($action=='edit'){?>
									<input class="btn btn-info pull-left" type="submit" name="update" value="Update" />
									<?php }?>
									</div>
								</form>
						<?php }?>
                        </div>
                    </div>				
                </div>
            </div>
        </div>
	<?php include("links/bottom.php");?>