<?php include("links/top.php");
$action=$_GET['action'];
?>
<?php 
if($action=='delete'){
$id=$_GET['id'];
$del="delete from pages where id='$id'";
$DB->executeQuery($del);
header('Location:pages.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),'about' 	=> addslashes($about),'email' 	=> addslashes($email),'phone' 	=> addslashes($phone),'title2' 	=> addslashes($title2),'about2' 	=> addslashes($about2),'date' 	=> addslashes($date),'location' 	=> addslashes($location),'map' 	=> addslashes($map),'description' => addslashes($description),'description1' => addslashes($description1),'status' => addslashes($status)); 
		$DB->insert('pages',$arr);	
		$id=getRecordId();						
	}
	if($action=='edit'){
		$arr=array( 'title' => addslashes($title),'about' 	=> addslashes($about),'email' 	=> addslashes($email),'phone' 	=> addslashes($phone),'title2' 	=> addslashes($title2),'about2' 	=> addslashes($about2),'date' 	=> addslashes($date),'map' 	=> addslashes($map),'location' 	=> addslashes($location),'description' => addslashes($description),'description1' => addslashes($description1),'status' => addslashes($status));
		$DB->update('pages',$arr,"id='$id'");
	}
	if($_FILES['file']['name']!='')
		{
		//$code=time();
		$filepath="uploads/images/";
		$extension = strtolower(strrchr($_FILES['file']['name'], '.'));
		if($extension=='.jpg' || $extension=='.jpeg' || $extension=='.png' || $extension=='.gif' || $extension=='.JPG' || $extension=='.JPEG' || $extension=='.PNG' || $extension=='.GIF' || $extension=='.bmp' || $extension=='.BMP'){
		$image = $filepath.$_FILES['file']['name'].$extension;
		move_uploaded_file($_FILES['file']['tmp_name'],'../'.$image);
		$arr=array( 'image' 	=> $image);
		$DB->update('pages',$arr,"id='$id'");
		}}
header('Location: pages.php?action=list');
	}
	}
	?>	
		<div id="content">
			<div class="container">
				<div class="page-header">
					<div class="page-title">
						<h3>Pages Management</h3>
					</div>
				</div>
				<div class="row">
               
					<div class="col-md-12">
                   <?php /*?> <?php if($action=='list'){?> <a href="pages.php?action=addnew"><button class="btn btn-sm btn-info">Add Page</button></a> <?php } ?><?php */?>                   
						<div class="widget box">
                        <div class="widget-header">
						<?php if($action=='list'){?>
                            <h4>Pages List</h4>
                            <?php }else if($action=='addnew'){ ?>
                            <h4>Add Page</h4>
                            <?php }?>					
							</div>
                        <div class="widget-content">
                             <?php if($action=='list'){
								 $sno=1;
								$sel=executeQuery("select * from pages");
								?>							
							
								<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>Title</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>
                                             <a href="pages.php?action=edit&id=<?php echo $rec['id'];?>" title="Edit"><i class="icol-pencil"></i></a> &nbsp;&nbsp;
										 <?php /*?><a href="pages.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><?php */?>
                                            </td>
										</tr>
                                        <?php $sno++;}?>
									</tbody>
								</table>
							
                            <?php }else if($action=='addnew' || $action=='edit'){?>
					
							<?php if($action=='edit'){
                            $id=$_GET['id'];
                            $e="select * from pages 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">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>
                                    <?php if($id==1 || $id==13 || $id==15 || $id==20 || $id==21 || $id==22){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">About <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="about" class="form-control required" value="<?php if($action=='edit'){echo $edi['about'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                    <?php if($id==8 || $id==9 || $id==10   || $id==16){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Email <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="email" class="form-control required" value="<?php if($action=='edit'){echo $edi['email'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                    <?php if($id==8 || $id==9 || $id==10 ){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Phone <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="phone" class="form-control required" value="<?php if($action=='edit'){echo $edi['phone'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                    <?php if($id==19 || $id==7){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Title2 </label>
										<div class="col-md-4">
											<input type="text" name="title2" class="form-control" value="<?php if($action=='edit'){echo $edi['title2'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                   <?php /*
                                    <?php if($id==19 ){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Time </label>
										<div class="col-md-4">
											<input type="text" name="about2" class="form-control " value="<?php if($action=='edit'){echo $edi['about2'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                   <?php if($id==19 ){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Location </label>
										<div class="col-md-4">
											<input type="text" name="location" class="form-control " value="<?php if($action=='edit'){echo $edi['location'];}?>">
										</div>
									</div>
                                   <?php } ?> 
                                   
                                   */ ?>
                                   
                                    <?php if($id==17 ){ ?>
                                   <div class="form-group">
										<label class="col-md-2 control-label">Countdown Date </label>
										<div class="col-md-4">
											<input type="text" name="date" class="form-control" value="<?php if($action=='edit'){echo $edi['date'];}?>">
										</div>
									</div>
									<?php } ?> 
									<?php if($id==17 || $id==18){ ?>
									
									 <div class="form-group">
										<label class="col-md-2 control-label">Status <span class="required">*</span></label>
										<div class="col-md-4 clearfix">
                                        <select name="status" class="form-control required">
								  		 <option <?php if($action=='edit'){if($edi['status']=='1'){echo 'selected="selected"';}}?> value="1">Active</option>
                                         <option <?php if($action=='edit'){if($edi['status']=='0'){echo 'selected="selected"';}}?> value="0">Inactive</option>
											</select>											
										</div>
									</div>
                                   <?php } ?> 
                                    <?php if($id==13){ ?>
								<div class="form-group">
                                    <label class="col-md-2 control-label">Image <span class="required">*</span></label>
                                    <div class="col-md-2 fileupload fileupload-new" data-provides="fileupload">
                                            <div class="fileupload-new thumbnail" style="width: 180px;">
                                           <img src="<?php if($action=='edit'){if($edi['image']!=''){ echo '../'.$edi['image'];}else{echo 'assets/img/no-image.gif';}}else{echo 'assets/img/no-image.gif';}?>" style="width:170px;" />
                                            </div>
                                            <div class="fileupload-preview fileupload-exists thumbnail"></div>
                                            <div>
                                                <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists" style="padding:6px;">Change</span><input type="file" name='file' <?php if($action=='edit'){if($edi['image']==''){echo 'class="required"';}}else{echo 'class="required"';}?> accept="image/*"  /></span><br />
                                               <span style="color:#F00;"> Image Size[370X409] px;</span>
                                                <a href="#" class="btn fileupload-exists" style="padding:4px 7px!important;" data-dismiss="fileupload">Remove</a>
                                            </div>
                                        </div>
                                        </div>
                                       <?php } ?> 
                                       <?php if($id==7){ ?>
                                       <div class="form-group">
										<label class="col-md-2 control-label">Map</label>
										
											<textarea  name="map" class=""><?php if($action=='edit'){echo $edi['map'];}?></textarea>
										
									</div>
                                   <?php } ?> 
                                  
                                    <?php 
                                    //if($id!=8 && $id!=9 && $id!=10 && $id!=15 && $id!=16 && $id!=17 && $id!=18  && $id!=24 && $id!=30 && $id!=19 && $id!=20 && $id!=21 && $id!=22){ 
                                      if($page_id!=8 && $page_id!=9 && $page_id!=10 && $page_id!=15 && $page_id!=16 && $page_id!=17 && $page_id!=18  && $page_id!=24 && $page_id!=30 && $page_id!=19 && $page_id!=20 && $page_id!=21 && $page_id!=22){ ?>
                                    <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>
                                    <?php } ?>
                                    <?php if($id==33){?>
                                    <div class="form-group">
										<label class="col-md-2 control-label">Description1</label>
										<div class="col-md-12 clearfix" style="clear:both; margin-top:40px;">
											<textarea id="description1" name="description1" class="ckeditor"><?php if($action=='edit'){echo $edi['description1'];}?></textarea>
										</div>
									</div>
                                   <?php } ?> 
                                 
									<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");?>