:?php /** * @author Philip Morris * @copyright 2008 */ if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User_model extends Model { var $id=FALSE; var $name; var $email; var $site_id; var $data; var $user_db; var $first_name; var $last_name; var $phone; function __construct() { parent::Model(); $this->user_db = $this->load->database('listmgr',TRUE); //check for logged in user if($id = $this->session->userdata('user_id')) $this->id = $this->verify_user_session($id) ? $id : FALSE; } /** * querys the database for a user w/ the given credentials */ function check_login_credentials( $email, $password ) { $this->user_db->select('*'); $this->user_db->from('contacts'); $this->user_db->where( array('email'=>$email, 'password'=>$password) ); $this->user_db->where('site_id',$this->config->item('site_id')); $this->user_db->limit(1); $query = $this->user_db->get(); if( $query->num_rows() > 0 ) { $this->data = $query->row(); $this->id = $this->data->id; $this->name = $this->data->first_name . ' ' . $this->data->last_name; $this->first_name = $this->data->first_name; $this->last_name = $this->data->last_name; $this->email = $this->data->email; $this->phone = $this->data->home_phone; $this->site_id = $this->data->site_id; return true; } else { return false; } } /** * retrieves a user record based on an email lookup * @param string user's email address * @return array limited user information */ function lookup_user_by_email() { $email = $this->input->post('email'); if( empty($email) ) return false; $this->user_db->select('first_name,last_name,email,password'); $this->user_db->from('contacts'); $this->user_db->where("(`email`='$email' OR `email2`='$email')"); $this->user_db->where('site_id',$this->config->item('site_id')); $this->user_db->limit(1); $query = $this->user_db->get(); if($query->num_rows()>0) { $this->data = $query->row(); return true; } else return false; } /** * fetch user data from the database by the id * @param int user_id * @return object user data object */ function get_user_by_id($user_id=null,$type='object') { if($user_id && is_numeric($user_id)) { $id=$user_id; } elseif($this->id && is_numeric($this->id)) { $id=$this->id; } else { log_message('error',"user_model.get_user_by_id receive an id. \$user_id=$user_id. \$this=".print_r($this)); return false; } $this->user_db->select('*'); $this->user_db->from('v_contacts'); $this->user_db->where('id',$id); $this->user_db->where('site_id',$this->config->item('site_id')); $this->user_db->limit(1); $query = $this->user_db->get(); if($query->num_rows()>0) return $query->row(0,$type); else { log_message('error',"user_model.get_user_by_id could not locate the user, id=$id with query: ".$this->user_db->last_query()); return false; } } /** * logs user activity * @param string register|login|property search|property detail * @param string * @param integer * @return boolean */ function log_user_activity($type,$description='',$item_id=null) { if(!is_numeric($this->id)) return false; $data = array( 'contact_id' => $this->id, 'type' => $type, 'description' => $description, 'item_id' => $item_id ); $this->user_db->insert('contact_activity_log',$data); return true; } /** * checkec to see if the users is currently logged in */ function logged_in() { return is_numeric($this->id) ? TRUE : FALSE; } /** * logs in the user */ function login_user($data=FALSE) { if(is_object($data)) $o = $data; else $o =& $this; if(!is_numeric($o->id)) return false; $this->id = $o->id; log_message('info','user.login_user this->id = '.$this->id); $sess_id = $this->session->userdata('session_id'); $data = array( 'site_id' => $this->config->item('site_id'), 'user_id' => $o->id, 'name' => trim($o->first_name . ' ' . $o->last_name), 'first_name' => $o->first_name, 'last_name' => $o->last_name, 'email' => $o->email, 'phone' => property_exists($o,'phone') ? $o->phone : $o->home_phone ); $this->session->set_userdata($data); // add user_id to session db table $data = array( 'user_id' => $o->id ); $this->user_db->where('session_id',$sess_id); $this->user_db->update('ci_sessions',$data); //verify session updated $query = $this->user_db->select('user_id')->from('ci_sessions')->where('user_id',$o->id)->where('session_id',$sess_id)->limit(1)->get(); if($query->num_rows()>0) { //echo 'returning true'; return true;} else return false; } /** * log the user out */ function logout_user() { $this->session->unset_userdata('data'); $this->session->sess_destroy(); } /** * DEPRICATED - an alias of get_user_by_id() * @param int user_id * @return object user data object */ function profile($user_id=null) { return $this->get_user_by_id($user_id); /*if($user_id && is_numeric($user_id)) { $id=$user_id; } elseif($this->id && is_numeric($this->id)) { $id=$this->id; } else { return false; } $this->user_db->select('*'); $this->user_db->from('v_contacts'); $this->user_db->where('id',$id); $this->user_db->where('site_id',$this->config->item('site_id')); $this->user_db->limit(1); $query = $this->user_db->get(); if($query->num_rows()>0) return $query->row();*/ } function register_user() { $this->load->database('listmgr'); $towns = is_array($this->input->post('towns')) ? implode(',',$this->input->post('towns')) : ''; $areas = is_array($this->input->post('areas')) ? implode(',',$this->input->post('areas')) : ''; $data = array( 'site_id' => $this->config->item('site_id'), 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'email' => $this->input->post('email'), 'password' => url_title($this->input->post('first_name')), 'home_phone' => $this->input->post('phone'), 'price_min' => $this->input->post('price_min'), 'price_max' => $this->input->post('price_max'), 'beds_min' => $this->input->post('beds_min'), 'beds_max' => $this->input->post('beds_max'), 'baths_min' => $this->input->post('baths_min'), 'baths_max' => $this->input->post('baths_max'), 'property_types'=> implode(',',$this->input->post('property_types')), 'timeframe_id' => $this->input->post('timeframe'), 'status_id' => 217, 'lead_from_id' => 7, 'lead_source_id'=> $this->input->post('source'), 'towns' => $towns, 'areas' => $areas ); $this->user_db->insert('contacts',$data); if( $user_id = $this->user_db->insert_id() ) { $this->user_db->insert('contact_assignments',array('contact_id'=>$user_id,'notes'=>'New Registration')); $this->id = $data['user_id'] = $user_id; $this->email = $this->input->post('email'); $this->name = $this->input->post('first_name') . ' ' . $this->input->post('last_name'); $this->send_registration_email($data); //if(!strstr($this->email,'pmorris96@')) $this->send_registration_email_to_admin($user_id); #$this->login_user(); #we no loner want to log the user in automaticlaly. return true; } } /** * sends registration email to the current user (for registration) or to the specified user (for lost_password) */ function send_registration_email($data) { //uses get_instance rather than $this because $this->email is the user's email address within this object $recipient = is_array($data) ? $data['email'] : $data->email; $CI =& get_instance(); $CI->load->library('email'); $CI->email->clear(); $CI->email->from('info@bostonrealestate.net','Group Boston Real Estate LLC'); $CI->email->to($recipient); $CI->email->subject('Thank you for visiting Group Boston Real Estate LLC!'); $CI->email->message($CI->load->view('email/registration',$data,true)); $CI->email->bcc('pmorris@firstseoconsultants.com'); /*if($CI->email->send()) { echo $CI->email->print_debugger(); die(); return true; } else return false;*/ return $CI->email->send(); } /** * send a registration newsletter (no longer in use) */ function send_registration_newsletter() { //uses get_instance rather than $this because $this->email is the user's email address within this object $CI =& get_instance(); $CI->load->library('email'); $CI->email->clear(); $CI->email->from('info@bostonrealestate.net','Group Boston Real Estate LLC'); $CI->email->to($this->email); $CI->email->subject('Welcome to Group Boston Real Estate LLC'); $CI->email->message($CI->load->view('email/registration_newsletter',array(),true)); /*if($CI->email->send()) { echo $CI->email->print_debugger(); return true; } else return false;*/ return $CI->email->send(); } function send_registration_email_to_admin($data) { if(is_numeric($data)) $data = $this->get_user_by_id($data,'array'); // conver towns and areas from csv of ids to text $CI =& get_instance(); $CI->load->model('mlslistings_model'); $towns = element('towns',$data,"''"); if(!empty($data['areas'])) { $areas = explode(',',$data['areas']); foreach($areas as $k=>$v) $areas[$k] = "'$v'"; $areas = implode(',',$areas); } else $areas = "''"; $data['towns_areas'] = $CI->mlslistings_model->get_towns("`type` = 'town' and `id` in ($towns) OR `type` = 'area' and `id` in ($areas)"); // convert property types string from codes to actual text values $property_type_lookup = $this->config->item('options:property_type','mls'); $property_types = array(); foreach( explode(',',$data['property_types']) as $k=>$type) { $property_types[$k] = element($type,$property_type_lookup,$type.' not found'); } $data['property_types'] = $property_types; // bedrooms if( $data['beds_min'] == 0 && $data['beds_max'] == 99 ) $bedrooms = 'Any'; elseif( $data['beds_min'] == 0 ) $bedrooms = $data['beds_max'] . ' or less'; elseif( $data['beds_max'] == 99 ) $bedrooms = $data['beds_min'] . ' or more'; else $bedrooms = $data['beds_min'] . ' - ' . $data['beds_max']; $data['bedrooms'] = $bedrooms; // bathrooms if( $data['baths_min'] == 0 && $data['baths_max'] == 99 ) $bathrooms = 'Any'; elseif( $data['baths_min'] == 0 ) $bathrooms = $data['baths_max'] . ' or less'; elseif( $data['baths_max'] == 99 ) $bathrooms = $data['baths_min'] . ' or more'; else $bathrooms = $data['baths_min'] . ' - ' . $data['baths_max']; $data['bathrooms'] = $bathrooms; //uses get_instance rather than $this because $this->email is the user's email address within this object $CI =& get_instance(); $CI->load->library('email'); $CI->email->clear(); $CI->email->from('info@bostonrealestate.net','Group Boston Real Estate LLC'); if($this->uri->segment(1)=='test' || $this->uri->segment(3)=='test' ) $CI->email->to('pmorris@firstseoconsultants.com'); else { $CI->email->to('pmcintyre@bostonrealestate.net'); $CI->email->cc('mcarucci@bostonrealestate.net'); #$CI->email->bcc('pmorris@firstseoconsultants.com'); } $CI->email->subject('New user registration'); $CI->email->message($CI->load->view('email/registration_to_admin',$data,true)); if($CI->email->send()) { if($this->uri->segment(1)=='test') echo $CI->email->print_debugger(); return true; } else return false; #return $CI->email->send(); } public function unsubscribe_dailyalert($user_id=null) { if($user_id && is_numeric($user_id)) { $id=$user_id; } elseif($this->id && is_numeric($this->id)) { $id=$this->id; } else { return false; } $data = array( 'send_dailyalert' => 0 ); $this->user_db->where('id',$id); $this->user_db->update('contacts',$data); // confirm the user is unsubscribed $r = $this->user_db->select('send_dailyalert')->from('contacts')->where('id',$id)->limit(1)->get(); return ( $r->num_rows() && $r->row()->send_dailyalert == 0); } function update($user_id=null) { if($user_id && is_numeric($user_id)) { $id=$user_id; } elseif($this->id && is_numeric($this->id)) { $id=$this->id; } else { return false; } $towns = is_array($this->input->post('towns')) ? implode(',',$this->input->post('towns')) : ''; $areas = is_array($this->input->post('areas')) ? implode(',',$this->input->post('areas')) : ''; $data = array( 'site_id' => $this->config->item('site_id'), 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'email' => $this->input->post('email'), 'home_phone' => $this->input->post('home_phone'), 'work_phone' => $this->input->post('work_phone'), 'mobile_phone' => $this->input->post('mobile_phone'), 'towns' => $towns, 'areas' => $areas, 'price_min' => $this->input->post('price_min'), 'price_max' => $this->input->post('price_max'), 'beds_min' => $this->input->post('beds_min'), 'beds_max' => $this->input->post('beds_max'), 'baths_min' => $this->input->post('baths_min'), 'baths_max' => $this->input->post('baths_max'), 'property_types'=> implode(',',$this->input->post('property_types')), 'living_area_min' => $this->input->post('living_area_min'), 'living_area_max' => $this->input->post('living_area_max') ); if( isset($_POST['send_dailyalert'])) $data['send_dailyalert'] = $this->input->post('send_dailyalert'); $this->user_db->where('id',$id); $this->user_db->update('contacts',$data); } function validate_forgotten_password() { $this->validation->set_rules(array( 'email' => "required|callback_lookup_user_by_email" )); return $this->validation->run(); } function validate_login() { $this->validation->set_rules(array( 'username' => "required", 'password' => "required|callback_check_login_credentials" )); return $this->validation->run(); } function validate_profile() { $this->validation->set_rules(array( 'email' => 'required|valid_email', 'first_name' => 'required', 'last_name' => 'required' )); $this->validation->set_fields(array( 'email' => 'Email Address', 'first_name' => 'First Name', 'last_name' => 'Last Name' )); return $this->validation->run(); } function validate_registration() { $this->validation->set_rules(array( 'email' => 'required|valid_email|callback_check_unique_email', 'first_name' => 'required', 'last_name' => 'required', 'phone' => 'required|min_length[10]|max_length[20]', 'timeframe' => 'required', 'sbmt_register_x' => 'callback_verify_property_type_section|callback_verify_location_selection' )); $this->validation->set_fields(array( 'email' => 'Email Address', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'phone' => 'Phone Number', 'property_type' => 'Property Type', 'timeframe' => 'Time Frame' )); return $this->validation->run(); } /** * */ function verify_user_session($user_id) { $query = $this->user_db->select('user_id')->from('ci_sessions')->where('user_id',$user_id)->where('session_id',$this->session->userdata('session_id'))->limit(1)->get(); if($query->num_rows()>0) return true; else return false; } } /* End of file user_model.php */ /* Location: ./system/application/controllers/user_model.php */
Fatal error: Class 'User_model' not found in /usr/local/codeigniter/1.7.3/system/libraries/Loader.php on line 184