id = $id;
$this->cookie_ttl = 60*60*24*365; // 365 days
}
function set_data($Contacts)
{
return($this->data = Database::get_record_for_object($Contacts, $this->id));
}
function set_cookie($Contacts)
{
if(!isset($_COOKIE[$Contacts->cookie_name]))
{
setcookie($Contacts->cookie_name, $this->id, time()+$this->cookie_ttl, '/');
}
else
{
if($_COOKIE[$Contacts->cookie_name] != $this->id)
{
// possibly someone else using a computer or a friend signing up a friend
Utilities::notify(Config::$tech_email, "contact_id cookie overwrite", "old: ".$_COOKIE[$Contacts->cookie_name]."\nnew: $this->id");
setcookie($Contacts->cookie_name, $this->id, time()+$this->cookie_ttl, '/');
}
}
}
function _subscribe()
{
$field_arr = array('email_list' => 'yes');
$where_field_arr= array('id' => $this->id);
return(Database::_update(Config::$db_tables['contacts'], $field_arr, $where_field_arr, 1, 'Contact::_subscribe'));
}
function confirm_email()
{
$update_fields = array('email_confirmed' => 'yes');
$where_fields= array('id' => $this->id);
return(Database::_update(Config::$db_tables['contacts'], $update_fields, $where_fields, 1, 'Contact::_update'));
}
function match_email_id($uEmail)
{
// does email match contact id?
$select = "SELECT email FROM ".Config::$db_tables['contacts']." WHERE id='".$this->id."'";
return(Database::ado_get_one($select, $title='Contact::match_email_id'));
}
function _unsubscribe()
{
$date = date("Y-m-d");
$upd = "UPDATE ".Config::$db_tables['contacts']." SET email_list='no', notes=CONCAT(notes, '|unsubscribed $date') WHERE id='".$this->id."' LIMIT 1";
return(Database::ado_execute_query($upd));
//$update_fields = array('email_list' => 'no', 'notes' => );
//$where_fields= array('id' => $this->id);
//return(Database::_update(Config::$db_tables['contacts'], $update_fields, $where_fields, 1, 'Contact::_update'));
}
function _update($Contacts, $fields, $overwrite=TRUE, $append_notes=FALSE, $fatal=TRUE)
{
// if overwrite is false do not send fields that exist in db (not blank) for updating. if the new field is different than the current (not blank) value send email to tech
if(!isset($this->data))
{
$this->set_data($Contacts);
}
$update_fields = array();
$send_tech_email = FALSE;
$tech_msg = "contact id: $this->id";
foreach($fields as $field=>$value)
{
if(!$overwrite && $this->data[$field] != '' && $value != $this->data[$field] && ($field != 'birthday' || ($field == 'birthday' && $this->data[$field] != '0000')))
{
// do not update - trying to overwrite with a different value
$send_tech_email = TRUE;
$tech_msg .= "\n not overwritten ".Config::$db_tables['contacts'].".$field from ".$this->data[$field]." to $value";
}
elseif($field == 'notes_contact' || ($field == 'notes' && $append_notes) && $this->data[$field] != '')
{
// append to, don't overwrite
$value = $this->data[$field] . "
$value";
$update_fields[$field] = $value;
}
else
{
$update_fields[$field] = $value;
}
}
if($send_tech_email)
{
Utilities::notify(Config::$tech_email, 'Contact info overwrite (?)', $tech_msg);
}
$where_fields= array('id' => $this->id);
return(Database::_update(Config::$db_tables['contacts'], $update_fields, $where_fields, 1, '', $fatal));
}
function send_welcome_email()
{
$to_arr = array($this->data['email']);
$subject = "Welcome!";
$body = "Welcome to the ".Config::$site_name." Email List!
You will be receiving announcements about new merchandise and designers added to our showroom, as well as about sales and promotions.
Please feel free to email our Product Advisor, ".Config::$product_advisor_name.", with any questions or requests you may have.
Thanks for joining us and please be sure to check our What's New? page often!
Best Regards,
".Config::$site_name;
Utilities::phpmailer_email($to_arr, $subject, $body, Config::$site_info_email, Config::$site_name, '', '', '', '', TRUE, '', '');
// notification email
$not_arr = array(Config::$product_advisor_email, Config::$site_manager_email);
$not_body = "id."\">View New Contact
A copy of their welcome email is below:
$body";
Utilities::phpmailer_email($not_arr, 'New '.Config::$site_name.' Email Subscription', $not_body, Config::$site_info_email, Config::$site_name, '', '', '', '', TRUE, '', '');
}
function most_recent_order($timeframe_min=0)
{
// returns order id of most recent order within timeframe (0 is unlimited)
$sel = "SELECT id FROM ".Config::$db_tables['orders']." WHERE contact_id='".$this->id."'";
if($timeframe_min > 0)
{
// get tf in mm-dd-yy hh:mm:ss format
$tf = date("m-d-y H:i:s", mktime(date("H"), date("i") - $timeframe_min));
$sel .= " AND order_dt > '$tf'";
}
//$now = date("m-d-y H:i:s", mktime());
//echo $now.'
>'.$tf;
$sel .= " ORDER BY order_dt DESC";
return(Database::ado_get_one($sel, ""));
}
}
?>