<?php

class Profile extends MY_Controller {

    function __construct() {
        parent::__construct();
        $s_imeeting['activemenu'] = '008';
        $this->session->set_userdata('s_imeeting', $s_imeeting);
    }

    function index($success = '0') {
        $s_login = $this->session->userdata("s_login");
        $member_id = $s_login['login_id'];

        $this->db->where('id', $member_id);
        $row = $this->db->get('tbmember')->row_array();
        $data['row'] = $row;
        if ($success == '1') {
            $data['msg_text'] = 'บันทึกข้อมูเสร็จเรียบร้อย';
        }

        $this->db->order_by('name', 'asc');
        $data['depart'] = $this->db->get('tbdepart')->result_array();

        $data['page_title'] = "ข้อมูลส่วนตัว";
        $data['content'] = 'profile/profile_frm_v';
        $this->load->view('template_v', $data);
    }

    function save() {
        $id = $this->input->post('id');
        $password = $this->input->post('password1');

        $data = array(
            'name' => $this->input->post('name'),
            'position' => $this->input->post('position'),
            'mobile' => $this->input->post('mobile'),
            'tel' => $this->input->post('tel'),
            'depart_id' => $this->input->post('depart_id'),
            'email' => $this->input->post('email')
        );

        if ($password != '') {
            $this->load->library('encrypt');
            $data['password'] = $this->encrypt->encode($password);
        }

        if ($id == '') {
            $this->db->insert('tbmember', $data);
            $id = $this->db->insert_id();
        } else {
            $this->db->where('id', $id);
            $this->db->update('tbmember', $data);
        }
        redirect("profile/index/1");
    }

}

?>
