<?php 
$page_name="chairman_msg"; 
include ('../common/library.php');  
include ('../template/header.php'); 
include ('../template/sidebar.php');
 


if(isset($_POST['save'])){
  $heading    = $_POST['heading'];
  $title = $_POST['title'];
  $p1 = $_POST['p1'];
  $p2 = $_POST['p2'];
  $p3 = $_POST['p3'];
  $p4 = $_POST['p4'];
  $p5 = $_POST['p5'];
  $endline     = $_POST['endline'];
  $entry_by   = $_SESSION['user_id'];


  $file = $_FILES['pic'];    //image upload
  $file_name = $file['name'];
  $file_path = $file['tmp_name'];  //image upload
	 $location= '../files/chariman_pic/'.$file_name;
	 move_uploaded_file($file_path, $location);

  
 $insert =$conn->query("insert into chairman_msg (`heading`,`title`,`p1`,`p2`,`p3`,`p4`,`p5`,`endline`,`pic`,`entry_by`) Values('".$heading."','".$title."','".$p1."','".$p2."','".$p3."','".$p4."','".$p5."','".$endline."','".$file_name."','".$entry_by."')");
  if($insert==true)
  {
  $insert_id = mysqli_insert_id($conn);
 /* echo '<script>window.location.href = "customer_setup.php";</script>';*/
 

 
  $msg =  '<span style="color:green; font-weight:bold; font-size:18px;">Successfully Inserted.</span>';
  
  }
  else
  {
  $msg =  '<span style="color:red; font-weight:bold; font-size:18px;">Plesae Try Again!</span>';
 }

}


if(isset($_POST['update'])){

  $update_id      = $_POST['update_id'];
  $heading    = $_POST['heading'];
  $title = $_POST['title'];
  $p1 = $_POST['p1'];
  $p2 = $_POST['p2'];
  $p3 = $_POST['p3'];
  $p4 = $_POST['p4'];
  $p5 = $_POST['p5'];
  $endline     = $_POST['endline'];
  $timeNow        = date("Y-m-d H:i:s");
  $entry_by       = $_SESSION['user_id'];

  $file = $_FILES['pic'];    //image upload
  $file_name = $file['name'];
  $file_path = $file['tmp_name'];  //image upload
	 $location= '../files/chairman_pic/'.$file_name;
	 move_uploaded_file($file_path, $location);


  
  if($file_name){
  $update = $conn->query("update chairman_msg set heading='".$heading."',title='".$title."',p1='".$p1."',p2='".$p2."',p3='".$p3."',p4='".$p4."',p5='".$p5."',endline='".$endline."',pic='".$file_name."',updated_by='".$entry_by."',updated_at='".$timeNow."' where id='".$update_id."'");
  }else{
	$update = $conn->query("update chairman_msg set heading='".$heading."',title='".$title."',p1='".$p1."',p2='".$p2."',p3='".$p3."',p4='".$p4."',p5='".$p5."',endline='".$endline."',updated_by='".$entry_by."',updated_at='".$timeNow."' where id='".$update_id."'");

  }
  
  if($update==true)
  {

 /* echo '<script>window.location.href = "customer_setup.php";</script>';*/
  $msg =  '<span style="color:green; font-weight:bold; font-size:18px;"> Successfully Updated.</span>';
  
  }
  else
  {
  $msg =  '<span style="color:red; font-weight:bold; font-size:18px;">Plesae Try Again!</span>';
 }
}



if(isset($_POST['delete'])){

  $delete_id  = $_POST['delete_id'];

  
  if($delete_id>0){
  $update = $conn->query("update company_info set status='Inactive' where id='".$delete_id."'");
  }
  
  if($update==true)
  {
 /* echo '<script>window.location.href = "customer_setup.php";</script>';*/
  $msg =  '<span style="color:green; font-weight:bold; font-size:18px;">About Successfully Deleted.</span>';
  
  }
  else
  {
  $msg =  '<span style="color:red; font-weight:bold; font-size:18px;">Plesae Try Again!</span>';
 }
}
/*while($c_data = $select->fetch_assoc()){
 $p++;
 $code[$p] = $c_data['id'];
 $business_name[$p] = $c_data['business_name'];
 $propritor_name[$p] = $c_data['propritor_name'];
 $mobile_no[$p] = $c_data['mobile_no'];
 $credit_limit[$p] = $c_data['credit_limit'];
 $entry_by[$p] = $c_data['entry_by'];
} 
*/ ?>

		
		<div class="main-panel">
			<div class="content">
				

                     <div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-header">
									<div class="d-flex align-items-center">
										<h4 class="card-title"><?=$msg?></h4>
										<button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal">
											<i class="fa fa-plus"></i>
										 Massage
										</button>
									</div>
								</div>
								<div class="card-body">
									<!-- Modal -->
									<form action="<?=$_POST['PHP_SELF']?>" method="post" enctype="multipart/form-data">
									<div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
										<div class="modal-dialog" role="document">
											<div class="modal-content">
												<div class="modal-header no-bd">
													<h5 class="modal-title">
														<span class="fw-mediumbold">
														Massage</span> 
														<span class="fw-light">
															
														</span>
													</h5>
													<button type="button" class="close" data-dismiss="modal" aria-label="Close">
														<span aria-hidden="true">&times;</span>
													</button>
												</div>
												<div class="modal-body">													
														<div class="row">
															
															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Heading <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="heading"  id="heading"  class="form-control" placeholder="Heading" >
																</div>
															</div>

															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Massage</label>
																	<textarea name="title" id="title" class="form-control" placeholder="Massage"></textarea>
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 1 <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="Paragraph 1" >
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 2 <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="Paragraph 2" >
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 3 <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="Paragraph 3" >
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 4 <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="Paragraph 4" >
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 5 <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="Paragraph 5" >
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>EndLine <span style="color:#FF0000; font-size:15px;"></span></label>
																	<input type="text" name="footer"  id="footer"  class="form-control" placeholder="EndLine" >
																</div>
															</div>
															
															
															<div class="col-md-6">
																<div class="form-group form-group-default">
																	<label>Pic <span style="color:#FF0000; font-size:15px;"> * (1920*994)</span></label>
																	<input name="pic" id="pic" type="file" required class="form-control">
																</div>
															</div>
														</div>
													
												</div>
												<div class="modal-footer no-bd">
													<!--<button type="button" id="addRowButton" class="btn btn-primary">Add</button>-->
													<input type="submit" name="save" id="" value="Add" class="btn btn-primary" />
													<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
												</div>
											</div>
										</div>
									</div>
								  </form>

									<div class="table-responsive">
										<table id="add-row" class="display table table-striped table-hover" >
											<thead>
												<tr>
													<th>Id</th>
													<th> Pic</th>
													<th>Heading</th>
													<th>Paragraph 1</th>
													<th>Endline</th>
													<th style="width: 10%">Action</th>
												</tr>
											</thead>
											<tfoot>																							
													<th></th>
													<th></th>
													<th></th>
													<th></th>
													<th></th>
													<th></th>
												</tr>
											</tfoot>
											<tbody>
											<?php
											 $select =$conn->query("select * from chairman_msg where 1 and status = 'Active'");
											 while($c_data = $select->fetch_assoc()){ ?>

												<tr>
												    <td><?=$c_data['id']?></td>
													<td><img src="../files/chairman_pic/<?=$c_data['pic']?>" style="height:30px;"></td>
													<td><?=$c_data['heading']?></td>
													<td><?=$c_data['p1']?></td>
													<td><?=$c_data['endline']?></td>
													<td>
														<div class="form-button-action">
															<button type="button"  data-toggle="modal" data-target="#editRowModal<?=$c_data['id']?>" title="" class="btn btn-link btn-primary btn-lg" data-original-title="Edit Task">
																<i class="fa fa-edit"></i>
															</button>
											 
											 


															
												
								 <form action="<?=$_POST['PHP_SELF']?>" method="post" enctype="multipart/form-data">			<!--- edit modal -->
									<div class="modal fade" id="editRowModal<?=$c_data['id']?>" tabindex="-1" role="dialog" aria-hidden="true">
										<div class="modal-dialog" role="document">
											<div class="modal-content">
												<div class="modal-header no-bd">
													<h5 class="modal-title">
														<span class="fw-mediumbold">
														Message </span> 
														<span class="fw-light">
															
														</span>
													</h5>
													<button type="button" class="close" data-dismiss="modal" aria-label="Close">
														<span aria-hidden="true">&times;</span>
													</button>
												</div>
												<div class="modal-body">													
														<div class="row">
															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Heading <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="hidden" name="update_id" id="update_id" value="<?=$c_data['id']?>" />
																	<input type="text" name="heading"  id="heading" value="<?=$c_data['heading']?>"  class="form-control" placeholder="Heading" >
																</div>
															</div>
															
															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Massage <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="title"  id="title" value="<?=$c_data['title']?>"  class="form-control" placeholder="Massage" >
																</div>
															</div>
															
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 1</label>
																	<input name="p1" id="p1" value="<?=$c_data['p1']?>" type="text" class="form-control" placeholder="Paragraph 1">
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 2</label>
																	<input name="p2" id="p2" value="<?=$c_data['p2']?>" type="text" class="form-control" placeholder="Paragraph 2">
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 3</label>
																	<input name="p3" id="p3" value="<?=$c_data['p3']?>" type="text" class="form-control" placeholder="Paragraph 3">
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 4</label>
																	<input name="p4" id="p4" value="<?=$c_data['p4']?>" type="text" class="form-control" placeholder="Paragraph 4">
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>Paragraph 5</label>
																	<input name="p5" id="p5" value="<?=$c_data['p5']?>" type="text" class="form-control" placeholder="Paragraph 5">
																</div>
															</div>
															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<label>EndLine</label>
																	<input name="endline" id="endline" value="<?=$c_data['endline']?>" type="text" class="form-control" placeholder="EndLine">
																</div>
															</div>															

															<div class="col-md-6">
																<div class="form-group form-group-default">
																	<label>Pic <span style="color:#FF0000; font-size:15px;"> </span></label>
																	<input name="pic" id="pic" type="file"  class="form-control">
																</div>
															</div>																														
															
															
														</div>
													
												</div>
												<div class="modal-footer no-bd">
													<!--<button type="button" id="addRowButton" class="btn btn-primary">Add</button>-->
													<input type="submit" name="update" id="" value="Update" class="btn btn-primary" />
													<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
												</div>
											</div>
										</div>
									</div>
								</form>
															
															<!--edit modal end-->
															
															
															
															<button type="button" data-toggle="modal" data-target="#viewModal<?=$c_data['id']?>" title="" class="btn btn-link btn-danger" data-original-title="Remove">
																<i class="fa fa-times"></i>
															</button>
															
<!--delete modal -->	
  <form action="" method="post">				
	<div class="modal fade show" id="viewModal<?=$c_data['id']?>" tabindex="-1" role="dialog" aria-labelledby=""aria-modal="true">
        <div class="modal-dialog modal-dialog-centered">
		 
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle">Chairman Message</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">x</span>
                    </button>
                </div>
                <div class="modal-body">

                   Do you want to delete this?
                        
                    
                </div>
                <div class="modal-footer">
				    <input type="hidden" name="delete_id" value="<?=$c_data['id']?>"  />
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" name="delete" class="btn btn-danger">Delete</button>
                </div>
            </div>
		 	
        </div>
    </div>
</form>	
	<!--delete modal End-->
															
														</div>
													</td>
												</tr>
												<?php } ?>
												
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>


			</div>


<?php include('../template/footer.php');?>