<?php
session_start();
require_once 'includes/header.php';
require_once 'includes/config.php';
$error=false;
$errors=array();
// avoid user arriving to this page without logging in
if(!isset($_SESSION['user_logged_in']) && $_SESSION['user_logged_in']!=TRUE )
{
	header('Location:login.php');

}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
	
	
	$group_name=$_POST['group_name'];
	
	
	
	
	if($error==false)
	{
		$createCustomer=mysqli_query($con,"UPDATE smsgroups SET group_name='".$group_name."', qr_no=''  WHERE id=".$_GET['id']);
		
		if($createCustomer){
			$errors['success']='smsgroups updated successfully.';
		}else{
			$error=true;
			$errors['error']='Something went wrong!!!, Please try again.';
		}
	}
	
	
}
$customer=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM smsgroups WHERE id=".$_GET['id']));

?>
 <div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12">
              <div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title">Edit smsgroup</h4>
                  <p class="card-category"></p>
                </div>
                <div class="card-body">

<?php

if (isset($error) && $error==false && isset($errors['success'])) {
	echo '<div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> '.$errors['success'].'</div>';
} 

if (isset($error) && $error==true && isset($errors['error'])) {
	echo '<div class="alert alert-danger" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> '.$errors['error'].'</div>';
} 

?>

  <form role="form" method="post" enctype="multipart/form-data">
   <div class="box-body">
   

   
   <div class="row">
   
   <div class="col-md-6">
   
   <div class="form-group">
	<input type="text" name="group_name" required class="form-control" placeholder="Group Name" value="<?php echo $customer['group_name'];  ?>" >
	<?php if($error==true && isset($errors['group_name'])){?>
		<p class="error"><?php echo $errors['group_name'];?></p>
	<?php } ?>
   </div>
   </div>
   
  <div class="col-md-6">
   
   
   </div>
   
   </div>
   
   
   
   <div class="box-footer">
		<button type="submit" class="btn btn-primary">Save</button>
   </div>
			  
   </form>
  </div>
  </div>
  </div>
  </div>
  </div>
  </div>

<?php include_once 'includes/footer.php'; ?>