home *** CD-ROM | disk | FTP | other *** search
Wrap
<?php /* Copyright Intermesh 2003 Author: Merijn Schering <mschering@intermesh.nl> Version: 1.0 Release date: 08 July 2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ class contacts extends db { function contacts() { $this->db(); } function search($user_id, $query) { $sql = "SELECT * FROM contacts WHERE user_id='$user_id' AND name LIKE '".smart_addslashes($query)."'"; $this->query($sql); return $this->num_rows(); } function get_contacts($user_id, $sort = "name", $direction = "ASC") { $this->query("SELECT * FROM contacts WHERE user_id='$user_id' ORDER BY ".$sort." ".$direction); return $this->num_rows(); } function get_contacts_with_group($user_id) { $this->query("SELECT contacts.*, contact_groups.name AS group_name FROM contacts LEFT JOIN contact_groups ON (contacts.group_id=contact_groups.id) WHERE contacts.user_id='$user_id'"); return $this->num_rows(); } function get_contacts_group($user_id, $group_id, $sort = "name", $direction = "ASC") { $this->query("SELECT * FROM contacts WHERE group_id='$group_id' AND user_id='$user_id' ORDER BY ".$sort." ".$direction); return $this->num_rows(); } function get_contact($contact_id) { $this->query("SELECT * FROM contacts WHERE id='$contact_id'"); if ($this->next_record()) { return $this->Record; } } function add_contact($source_id, $user_id, $name, $email, $work_phone = "", $home_phone = "", $fax = "", $cellular = "", $country = "", $state = "", $city = "", $zip = "", $address = "", $company = "", $work_country = "", $work_state = "", $work_city = "", $work_zip = "", $work_address = "", $work_fax = "", $homepage = "", $department = "", $function = "", $comments="", $group_id = 0, $color='') { $name = htmlentities(smart_addslashes($name)); $work_phone = htmlentities(smart_addslashes($work_phone)); $home_phone = htmlentities(smart_addslashes($home_phone)); $fax = htmlentities(smart_addslashes($fax)); $cellular = htmlentities(smart_addslashes($cellular)); $country = htmlentities(smart_addslashes($country)); $state = htmlentities(smart_addslashes($state)); $city = htmlentities(smart_addslashes($city)); $zip = htmlentities(smart_addslashes($zip)); $address = htmlentities(smart_addslashes($address)); $company = htmlentities(smart_addslashes($company)); $work_country = htmlentities(smart_addslashes($work_country)); $work_state = htmlentities(smart_addslashes($work_state)); $work_city = htmlentities(smart_addslashes($work_city)); $work_zip = htmlentities(smart_addslashes($work_zip)); $work_address = htmlentities(smart_addslashes($work_address)); $work_fax = htmlentities(smart_addslashes($work_fax)); $homepage = htmlentities(smart_addslashes($homepage)); $function = htmlentities(smart_addslashes($function)); if ($group_id == '') { $group_id = 0; } $contact_id = $this->nextid("contacts"); if ($contact_id > 0) { $sql = "INSERT INTO contacts "; $sql .= "(id, source_id, user_id, name, email, work_phone, home_phone, fax, cellular, country, state, city, zip, address, company, work_country, work_state, work_city, work_zip, work_address, work_fax, homepage, department, function, comments, group_id, color) VALUES "; $sql .= "('$contact_id', '$source_id', '$user_id', '$name', '$email', '$work_phone', '$home_phone', '$fax', '$cellular', '$country', '$state', '$city', '$zip', '$address', '$company', '$work_country', '$work_state', '$work_city', '$work_zip', '$work_address', '$work_fax', '$homepage', '$department', '$function','$comments', '$group_id', '$color')"; $query = $this->query($sql); if ($this->affected_rows() > 0) { return true; }else { return false; } }else { return false; } } function update_contact($id, $name, $email, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function, $comments = '', $group_id='0', $color) { $name = htmlentities(smart_addslashes($name)); $work_phone = htmlentities(smart_addslashes($work_phone)); $home_phone = htmlentities(smart_addslashes($home_phone)); $fax = htmlentities(smart_addslashes($fax)); $cellular = htmlentities(smart_addslashes($cellular)); $country = htmlentities(smart_addslashes($country)); $state = htmlentities(smart_addslashes($state)); $city = htmlentities(smart_addslashes($city)); $zip = htmlentities(smart_addslashes($zip)); $address = htmlentities(smart_addslashes($address)); $company = htmlentities(smart_addslashes($company)); $work_country = htmlentities(smart_addslashes($work_country)); $work_state = htmlentities(smart_addslashes($work_state)); $work_city = htmlentities(smart_addslashes($work_city)); $work_zip = htmlentities(smart_addslashes($work_zip)); $work_address = htmlentities(smart_addslashes($work_address)); $work_fax = htmlentities(smart_addslashes($work_fax)); $homepage = htmlentities(smart_addslashes($homepage)); $function = htmlentities(smart_addslashes($function)); $sql = "UPDATE contacts SET "; $sql .= "name='$name', email='$email', work_phone='$work_phone', home_phone='$home_phone', fax='$fax', cellular='$cellular', state='$state'"; $sql .= ", country='$country', city='$city', zip='$zip', address='$address', company='$company', department='$department', function='$function', work_country='$work_country', work_state='$work_state', work_city='$work_city', work_zip='$work_zip', work_address='$work_address', work_fax='$work_fax', homepage='$homepage', comments='$comments', group_id='$group_id', color='$color'"; $sql .= " WHERE id='$id'"; $query = $this->query($sql); if (isset($query)) { return true; }else { return false; } } function delete_contact($id) { $sql = "DELETE FROM contacts WHERE id='$id'"; $this->query($sql); return true; } function synchronise($contact_id, $user_id) { $sql = "SELECT * FROM users WHERE id='$user_id'"; $this->query($sql); if ($this->next_record()) { $sql = "UPDATE contacts SET "; $sql .= "name='".$this->f("name")."', email='".$this->f("email")."', work_phone='".$this->f("work_phone")."', home_phone='".$this->f("home_phone")."', fax='".$this->f("fax")."', cellular='".$this->f("cellular")."', state='".$this->f("state")."'"; $sql .= ", country='".$this->f("country")."', city='".$this->f("city")."', zip='".$this->f("zip")."', address='".$this->f("address")."', company='".$this->f("company")."', department='".$this->f("department")."', function='".$this->f("function")."'"; $sql .= " WHERE id='$contact_id'"; $this->query($sql); } } function user_is_contact($user_id, $id) { $sql = "SELECT * FROM contacts WHERE source_id='$id' AND user_id='$user_id'"; $this->query($sql); if ($this->next_record()) { return $this->Record; }else { return false; } } function get_contact_id_by_email($email, $user_id) { $sql = "SELECT id FROM contacts WHERE email='".smart_addslashes($email)."' AND user_id='$user_id'"; $this->query($sql); if ($this->next_record()) return $this->f("id"); else return false; } function get_contact_profile_by_email($email, $user_id) { $sql = "SELECT * FROM contacts WHERE email='".smart_addslashes($email)."' AND user_id='$user_id'"; $this->query($sql); if ($this->next_record()) return $this->Record; else return false; } function get_groups($user_id) { $sql= "SELECT * FROM contact_groups WHERE user_id='$user_id'"; $this->query($sql); return $this->num_rows(); } function add_group($user_id, $name) { $name = htmlentities(smart_addslashes($name)); $group_id = $this->nextid("contact_groups"); if ($group_id > 0) { $sql = "INSERT INTO contact_groups (id, user_id, name) VALUES ('$group_id', '$user_id', '".smart_addslashes($name)."')"; $this->query($sql); return $group_id; }else { return false; } } function delete_group($group_id) { $sql = "UPDATE contacts SET group_id='0' WHERE group_id='$group_id'"; if ($this->query($sql)) { $sql = "DELETE FROM contact_groups WHERE id='$group_id'"; $this->query($sql); return true; } return false; } function move_contact_to_group($contact_id, $group_id) { $sql = "UPDATE contacts SET group_id='$group_id' WHERE id='$contact_id'"; $this->query($sql); } function clear_group($group_id) { $sql = "UPDATE contacts SET group_id='0' WHERE group_id='$group_id'"; $this->query($sql); } function change_group_name($group_id, $name) { $sql = "UPDATE contact_groups SET name='".smart_addslashes($name)."' WHERE id='$group_id'"; $this->query($sql); } function delete_user($user_id) { $sql = "UPDATE contacts SET source_id='0' WHERE source_id='$user_id'"; $this->query($sql); $sql = "DELETE FROM contacts WHERE user_id ='$user_id'"; $this->query($sql); } } ?>