cookie_name = 'contact_id'; $this->dbTableName = Config::$db_tables['contacts']; } function get_cookie() { // returns the contact id stored in the cookie or FALSE return (isset($_COOKIE[$this->cookie_name])) ? $_COOKIE[$this->cookie_name] : FALSE; } function _search($search_by, $search_for) { // searches by any 1 field in contacts record (usually name or email) // returns id or FALSE $sel = "SELECT id FROM $this->dbTableName WHERE $search_by='".trim(addslashes($search_for))."'"; //echo $sel; $RS = Database::ado_execute_query($sel, "Contacts::_search"); switch($RS->RecordCount()) { case 0: return(FALSE); case 1: $row = $RS->FetchRow(); return($row); default: // multiples $body = "contacts::_search"; Utilities::notify(Config::$tech_email, "Multiple Contacts Exist for $search_by: $search_for", $body); return(FALSE); } } function search_name_email($name, $email) { // if both name and email match return id. if either 1 matches alert tech and return false. otherwise return false $RS = Database::ado_execute_query("SELECT id FROM $this->dbTableName WHERE name='".trim(addslashes($name))."' AND email='".trim(addslashes($email))."'", "Contacts::search_name_email"); switch($RS->RecordCount()) { case 0: // see if either / or matches if($otherContact = $this->_search('name', $name)) { // if the email is blank ok to use the other contact if($otherContact['email'] == '') { return($otherContact['id']); } // otherwise the email is different Utilities::notify(Config::$tech_email, "Contact name found with different email", "$name\n$email"); } if($otherContact = $this->_search('email', $email)) { // if the name is blank ok to use the other contact if($otherContact['name'] == '') { return($otherContact['id']); } // otherwise the name is different Utilities::notify(Config::$tech_email, "Contact email found with different name", "$name\n$email"); } return(FALSE); break; case 1: $row = $RS->FetchRow(); return($row['id']); break; default: // multiples $body = "contacts::search_name_email"; Utilities::notify(Config::$tech_email, "Multiple Contacts Exist for name: $name, email: $email", $body); return(FALSE); } } function generate_select($Forms, $onchange='') { $contact_select = ''; $c = array(); // stored as dbname => display if(isset($_SESSION['contacts'])) { $c = $_SESSION['contacts']; } else { $cRS = Database::ado_execute_query("SELECT name FROM contacts WHERE name != '' ORDER BY name"); while($cRow = $cRS->FetchRow()) { $cname = strtoupper($cRow['name']); $cp = explode(' ', $cname); $cfirst = ''; // will hold everything before last name (ie middle initial) $clast = ''; $pc = 0; foreach($cp as $p) { ++$pc; if($pc == count($cp)) { $clast = $p; } else { $cfirst .= ($pc == 1) ? $p : ' '.$p; } } // fix PHD $funky_ln = array('phd', 'jd', 'j.d.', 'md', 'm.d.', 'md.'); if(in_array(strtolower($clast), $funky_ln)) { $clast = $cp[count($cp) - 2] . ' ' . $clast; $cfirst = $cp[0]; } $c[$cRow['name']] = $clast . ', ' . $cfirst; } asort($c); $_SESSION['contacts'] = $c; } $top_option = array('' => '-- select customer --'); $options = array(); foreach($c as $cvalue=>$contact) { $options[$cvalue] = $contact; } $options['0'] = '--> customer selected <--'; return($Forms->generate_select_formfield('contact', $options, $top_option, '', $onchange)); } function _insert($fields) { return(Database::_insert($this->dbTableName, $fields, 'Contacts::_insert')); } } ?>