<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
require_once "check_admin.php";
require_once 'database.php';
class emails extends database
{
   public function index($data)
    {
        return $this->update('email', $data);
    }
    
    public function getEmail()
    {
        return $this->fetchRow('email');
    }
}
$cat = new emails();
$successMsg="";
$msg = "";
if(isset($_GET['message']))
{
    $successMsg=$_GET['message'];
}
if(isset($_POST['data']))
{
    $data=$_POST['data'];
    if(trim($data['email']) == '')
    {
        $msg.= "Email is required<br/>";
    }
    
    if($msg=="")
    {
         $res = $cat->index($data);
            if($res)
            {
                    header('Location:emails.php?message=Emails Updated Successfully');
            }
            else {
                $msg = 'Something Went Wrong';
            }
    }
}

$email = $cat->getEmail();


 include 'header.php';
 ?>
 
 
     <div class="content-wrapper">
            <!-- Content -->

            <div class="container-xxl flex-grow-1 container-p-y">
              <h4 class="fw-bold py-3 mb-4">Update Email</h4>
                <?php if($msg !=''){echo '<span class="alert alert-danger pull-left">'.$msg.'</span>';}?>
                <?php if($successMsg !=''){echo '<span class="alert alert-success pull-left">'.$successMsg.'</span>';}?>
              <!-- Basic Layout -->
              <div class="row">

                                <div class="col-sm-12">
                                    <div class="row">
                                     <div class="card-body">
                                    <form method="post">
                                        <div class="col-md-12">
                                            <label class="form-label" for="basic-default-fullname">Emails</label>
                                            <input type="text" name="data[email]" class="form-control" value="<?php echo $email['email'] ?>" />
                                        </div>
                                       
                                        <div class="col-md-12 botm-cont mt-2">
                                            <button type="submit" class="track-btn btn btn-primary">UPDATE EMAIL</button>
                                        </div>
                                    </form>
                                    </div>
                                    </div>
                                </div>
                            </div>                            
                        </div>
                    </div>
                

    <script>
    $(document).ready(function(){
        $('.activ-cat').removeClass('activ-cat');
        $('#email-menu').addClass('activ-cat');
    }); 
</script>
<?php include 'footer.php';?>