<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Welcome_model
 *
 * @author mzq163
 */
class Temp_model extends CI_Model {

    //put your code here
    var $db_temp;
    var $status;
    var $message;
    var $response_data = array();

    public function __construct() {
        parent::__construct();
        $this->db_temp = $this->load->database('db_temp', true);
    }

    public function endUserImageUploadTempModel($_post_data = null) {
        if ($_post_data != null) {
            $image_data = addslashes(file_get_contents($_FILES['image']['tmp_name']));
            if ($_post_data['userType'] == 1) {
                $this->db_temp->where('sessionId', $_post_data['id']);
                $this->db_temp->update('EndUser', array('singleModePicture' => $image_data));
            } else {
                $this->db_temp->where('sessionId', $_post_data['userId']);
                $this->db_temp->update('EndGroupUser', array('groupPicture' => $image_data));
            }
            $this->status = TRUE;
            $this->message = 'Image upload success.';
        } else {
            $this->message = 'Image upload fail.';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * $this->status = false;
     */
    public function endUserRegistrationModel($_post_data = null) {
        if ($_post_data != null) {
            $this->db_temp->insert('EndUser', $_post_data);
           // $this->response_data['s_singleModeId'] = $this->db_temp->insert_id();
           // $this->response_data['m_singleModeId'] = $_post_data['mobileSingleModeId'];
            $this->status = TRUE;
            $this->message = 'End user registration success.';
        } else {
            $this->message = 'End user registration fail.';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function endUserGroupRegistrationModel($_post_data = null) {
        if ($_post_data != null) {
            $this->db_temp->insert('EndGroupUser', $_post_data);
           // $this->response_data['s_groupModeId'] = $this->db_temp->insert_id();
           // $this->response_data['m_groupModeId'] = $_post_data['mobileGroupId'];
            $this->status = TRUE;
            $this->message = 'End user group registration success.';
        } else {
            $this->message = 'End user group registration fail.';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function sessionPlayDataModel($_post_data = null) {
        if ($_post_data != null) {
            $this->db_temp->insert('SessionDetail', $_post_data);
           // $this->response_data['s_moduleId'] = $this->db_temp->insert_id();
           // $this->response_data['m_moduleId'] = $_post_data['mobileModuleId'];
            $this->status = TRUE;
            $this->message = 'Data submit success.';
        } else {
            $this->message = 'Data submit fail.';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function userRegistrationTempModel($_post_data = null) {
        if ($_post_data != null) {
            $this->db_temp->insert('UserRegistration', $_post_data);
          //  $this->response_data['s_userid'] = $this->db_temp->insert_id();
          //  $this->response_data['m_userid'] = $_post_data['mobileUserId'];
            $this->status = TRUE;
            $this->message = 'User registration success.';
        } else {
            $this->message = 'User registration fail.';
        }
       // return array('status'=>$this->status ,'message'=>$this->message,'s_userid'=>$this->response_data['s_userid'],'m_userid'=>$this->response_data['m_userid']);
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }
    /**
     * 
     * 
     * 
     */
    public function recapQuestionTempModel($_post_data = null) {
         if ($_post_data != null) {
            $this->db_temp->insert('RecapQuestion', $_post_data);
            
            $this->status = TRUE;
            $this->message = 'Success.';
        } else {
            $this->message = 'Fail.';
        }
       // return array('status'=>$this->status ,'message'=>$this->message,'s_userid'=>$this->response_data['s_userid'],'m_userid'=>$this->response_data['m_userid']);
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
  
    }
    /**
     * 
     * 
     * 
     */
    public function preQuestionTempModel($_post_data = null) {
         if ($_post_data != null) {
            $this->db_temp->insert('PreQuestion', $_post_data);
            
            $this->status = TRUE;
            $this->message = 'Success.';
        } else {
            $this->message = 'Fail.';
        }
       // return array('status'=>$this->status ,'message'=>$this->message,'s_userid'=>$this->response_data['s_userid'],'m_userid'=>$this->response_data['m_userid']);
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
  
    }

    /**
     * 
     * 
     * 
     */
    public function insertDataModel() {
        $this->db_temp->insert('temp', array('fullName' => 'Abdul Muttalib'));
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function userAuthenticationUserIdPassword_model($_post_data = null) {
        if ($_post_data != null) {
            $query_data = $this->db_sbcc->select('*')
                            ->from('MasterUser')
                            ->where($_post_data)->get();
            if ($query_data->num_rows() > 0) {
                $this->status = true;
                $this->message = 'Login success';
                $this->response_data = $query_data->result_array();
            } else {
                $this->message = 'Login failed';
            }
        } else {
            $this->message = 'Login failed';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * 
     */
    private function getResponseAfterSubmitData($_status, $_message, $_responsedata) {
        return array('status' => $_status, 'message' => $_message, 'response_data' => $_responsedata);
    }

    /**
     * 
     * 
     * 
     */
    private function checkLoginIdAvilability($loginId = null) {
        if ($loginId != null) {
            if (
                            $this->db_sbcc->select('*')
                            ->from('MasterUser')
                            ->where('loginId', $loginId)->get()
                            ->num_rows() > 0) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

}
