<?php
defined('BASEPATH') OR exit('No direct script access allowed');
defined('DIR_SEPARATOR') || define('DIR_SEPARATOR', '/');

class Registrationmain extends CI_Model {
	
	public function __construct() {
		parent::__construct();
	}
	
	public function saveRegistration($fullname, $phone, $email, $password) {
		$sql = "INSERT INTO tbl_usermaster (
							username, phone_mobile, email, userid, password, create_dt, position, role, status
						) VALUES (
							'".($fullname)."',
							'".($phone)."',
							'".($email)."',
							'".($email)."',
							'".($password)."', 
							NOW(),
							'Manager',
							'Manager',
							'NEW'
						)";
		return ($this->db->query($sql)) ? $this->db->insert_id() : 0;
	}
	
	public function saveProject($title, $user) {
		$sql = "INSERT INTO project (
							title, startDT, endDT, venue,
							user, createdTS, updatedTS, createdBy, updatedBy
						) VALUES (
							'".(addslashes(trim($title)))."',
							DATE_ADD(NOW(), INTERVAL 14 DAY),
							DATE_ADD(NOW(), INTERVAL 21 DAY),
							NULL,
							".$user.",
							NOW(),
							NOW(),
							".$user.",
							".$user."
						)";
						
		return ($this->db->query($sql)) ? $this->db->insert_id() : 0;
	}
	
	public function isEmailExists($email) {
		$sql = "SELECT COUNT(1) CT FROM tbl_usermaster WHERE LOWER(email) = '".(strtolower(trim($email)))."'";
		$q = $this->db->query($sql);
		return ($q && ($r = $q->result()) && $r[0] && $r[0]->CT) ? TRUE : FALSE;
	}
	
	public function ObjToArray($item) { return json_decode(json_encode($item),true); }
	
}































