<?php 

defined('BASEPATH') OR exit('No direct script access allowed');

class Deleteaccount extends CI_Controller{
    
    public function __construct(){

        parent::__construct();


    }

    public function index(){
        
        if($this->input->post()){
            
            $data = $_POST;
            
            $email = $this->cm->search_single_where(["email" => $data["email"], "register" => "1"], 'users');
            if(empty($email)){
                
                redirect(site_url('account-not-found'));
                
            }
            
            
            if(md5($data["password"]) == $email['password']){
                
                $id = $email["id"];
                
                $email = array_map(fn($value) => '', $email);
                
                $email['id'] = $id;
                $email['register'] = "0";
                $email['deleted'] = '1';
                $email['deleted_at'] = date('Y-m-d H:i:s');
                $email['deleted_by'] = 'user';
                
                $this->cm->update_where($email, ["id" => $email["id"]], 'users');
                
               redirect(site_url('account-deleted'));
                
            }else{
                
                 redirect(site_url('account-not-found'));
                
            }
            
        }

        $this->load->view('deleteaccount');

    }
    
    
    public function invalid(){
        
        $this->load->view('invalid');

    }
    
    
        
    public function success(){
        
        $this->load->view('deletesuccess');

    }
    
    
}