thomascube
2008-02-20 103d6b697ce53eb8e954b4a4c9eac659ef942b24
program/include/rcube_contacts.inc
@@ -19,6 +19,12 @@
*/
/**
 * Model class for the local address book database
 *
 * @package Addressbook
 */
class rcube_contacts
{
  var $db = null;
@@ -55,7 +61,7 @@
  /**
   * PHP 4 object constructor
   *
   * @see  rcube_contacts::__construct
   * @see rcube_contacts::__construct()
   */
  function rcube_contacts($dbconn, $user)
  {
@@ -122,9 +128,17 @@
  
  
  /**
   * Close connection to source
   * Called on script shutdown
   */
  function close(){}
  /**
   * List the current set of contact records
   *
   * @param  array  List of cols to show
   * @param  int    Only return this number of records, use negative values for tail
   * @return array  Indexed list of contact records, each a hash array
   */
  function list_records($cols=null, $subset=0)
@@ -171,7 +185,7 @@
   * @param boolean True if results are requested, False if count only
   * @return Indexed list of contact records and 'count' value
   */
  function search($fields, $value, $select=true)
  function search($fields, $value, $strict=false, $select=true)
  {
    if (!is_array($fields))
      $fields = array($fields);
@@ -184,6 +198,8 @@
        $ids = !is_array($value) ? split(',', $value) : $value;
        $add_where[] = $this->primary_key." IN (".join(',', $ids).")";
      }
      else if ($strict)
        $add_where[] = $this->db->quoteIdentifier($col)."=".$this->db->quote($value);
      else
        $add_where[] = $this->db->quoteIdentifier($col)." LIKE ".$this->db->quote(strlen($value)>2 ? "%$value%" : "$value%");
    }
@@ -278,7 +294,7 @@
    $insert_id = $existing = false;
    if ($check)
      $existing = $this->search('email', $save_data['email'], false);
      $existing = $this->search('email', $save_data['email'], true, false);
    $a_insert_cols = $a_insert_values = array();
    foreach ($this->table_cols as $col)
@@ -370,6 +386,19 @@
    return $this->db->affected_rows();
  }
  /**
   * Remove all records from the database
   */
  function delete_all()
  {
    if (is_array($ids))
      $ids = join(',', $ids);
    $this->db->query("DELETE FROM {$this->db_name} WHERE  user_id=?", $this->user_id);
    return $this->db->affected_rows();
  }
}