<?php 

defined('BASEPATH') or exit ('Direct script access not allowed');

require_once APPPATH . "core/My_Admin.php";

class Services extends My_Admin{

    public function __construct()
    {
        parent::__construct();
    }

    public $table = 'services';

    // * list of services
    public function index(){

        $data['details'] = $this->cm->search_multiple_where([], 'ASC','id', 'services');

        // echo "<pre>";
        // print_r($data);
        // exit;

        $this->load->view('admin/includes/header', $data);
        $this->load->view('admin/service/view');
        $this->load->view('admin/includes/footer');

    }


    // * update service entry
    public function update_service(){
        request_method('POST');

        $request = check_parameter([
            'service_id' => true,
        ]);

        $request['service_desc'] = $this->input->post('service_desc');
        $request['min'] = $this->input->post('min');
        $request['coins'] = $this->input->post('coins');
        $request['reward_coins'] = $this->input->post('reward_coins');

        $service_id = $this->input->get('service_id');

        $upd = $this->cm->update_where($request, ['id' => $service_id], 'services');

        if($upd){
            echo json_encode([
                'status' => '1',
                'message' => 'details updated'
            ]);exit;
        }

        echo json_encode([
            'status' => '0',
            'message' => 'details not updated'
        ]);exit;
    }


    
    // public function create(){

    //     if($this->input->post()){

    //         // upload_media($_FILES[''])

    //         // redirect();
            
    //     }

    //     $this->load->view('admin/includes/header');
    //     $this->load->view('admin/ads/create');
    //     $this->load->view('admin/includes/footer');

    // }

    // public function edit(){

    //     if (isset($_GET['id'])) {

    //         $data['details'] = $this->cm->search_single_where(['id' => $_GET['id']]);

    //         if (empty($data['details'])) {



    //         } else {

    //             if ($this->input->post()) {

    //                 $id = $_GET['id'];
    //                 $data = $_POST;


    //                 // $this->cm->update_where($data, ['id' => $id]);

    //                 $this->session->set_flashdata('success', 'Data updated successfuly.');
    //                 redirect();
    //             }
                
    //             $this->load->view('admin/includes/header', $data);
    //             $this->load->view('admin/ads/edit');
    //             $this->load->view('admin/includes/footer');
    //         }
    //     } else {
            
    //         redirect();
    //     }
        
    // }

    // public function delete(){

    //     if (isset($_GET['id'])) {

    //         $data['details'] = $this->cm->search_single_where(['id' => $_GET['id']]);
            
    //         if (empty($data['details'])) {
                
    //             redirect();
                
    //         }else{
                
    //             $this->cm->remove_where(['id' => $_GET['id']]);

    //             $this->session->set_flashdata('success', 'Data deleted successfuly.');
    //             redirect();
                
    //         }

    //     }else{

    //         redirect();
            
    //     }
        
    // }


    

    
}
