<?php

namespace App\Controllers\Welcome;

use App\Controllers\BaseController;
use App\Models\Common_M;

class WelcomeController extends BaseController
{
    
    public function __construct(){
        
        helper(['url', 'form']);
        
        
    }

    public function welcome_message(){
        
        $session = session();
        
        $data['page_title'] = "Dashboard || " . COMPANY_SHORT_NAME;
        $data['meta_tag'] = '<meta content='. COMPANY_FULL_NAME . ', Sketch Me Global" name="keywords"><meta content=School Management System,'.COMPANY_FULL_NAME.'", Sketch Me Global" name="description">';
        $cond_arr = array('row_status' => 1);
        $data['welcome'] = $this->common->data_last_row('page_content', $cond_arr, 'id ASC');
        return view('welcome/welcome_message', $data);
        
    }
 


    public function ajax_welcome_message_update_form() {
        $session = session();
        $final_flag = array();
        
        if ($this->request->getPost()) {
            $welcome_header_rule = [
                'content' => 'required',
               
            ];
    
            if ($this->validate($welcome_header_rule)) {
                
                $id = $this->request->getPost('id');
                $insertArray = array(
                    'content' => $this->request->getPost('content'),
                    'updated_by' => $session->get('id')
                );
                $cond=array(
                    "id"=>$id
                );
                if ($insert_id = $this->common->data_update('page_content', $cond,$insertArray)) {
                    $final_flag = array('status' => true, 'code' => '023', 'msg' => EM023, 'redirect_id' => $id);
                } else {
                    $final_flag = array('status' => false, 'code' => '022', 'msg' => EM022, 'redirect_id' => NULL);
                }
            } else {
                $final_flag = array('status' => false, 'code' => '041', 'msg' => EM041 . ' <hr style="border:2px solid #fff;margin-bottom:5px">' . $this->validator->listErrors());
            }
    
            echo json_encode($final_flag);
        }
    }
    
}
