thomascube
2008-02-20 103d6b697ce53eb8e954b4a4c9eac659ef942b24
program/include/rcube_contacts.inc
@@ -19,12 +19,18 @@
*/
/**
 * Model class for the local address book database
 *
 * @package Addressbook
 */
class rcube_contacts
{
  var $db = null;
  var $db_name = '';
  var $user_id = 0;
  var $filter = '1';
  var $filter = null;
  var $result = null;
  var $search_fields;
  var $search_string;
@@ -55,7 +61,7 @@
  /**
   * PHP 4 object constructor
   *
   * @see  rcube_contacts::__construct
   * @see rcube_contacts::__construct()
   */
  function rcube_contacts($dbconn, $user)
  {
@@ -115,16 +121,24 @@
  function reset()
  {
    $this->result = null;
    $this->filter = '1';
    $this->filter = null;
    $this->search_fields = null;
    $this->search_string = null;
  }
  
  
  /**
   * 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)
@@ -142,9 +156,9 @@
      $sql_result = $this->db->limitquery(
        "SELECT * FROM ".$this->db_name."
         WHERE  del<>1
         AND    user_id=?
         AND    (".$this->filter.")
         ORDER BY name",
         AND    user_id=?" .
        ($this->filter ? " AND (".$this->filter.")" : "") .
        " ORDER BY name",
        $start_row,
        $length,
        $this->user_id);
@@ -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%");
    }
@@ -213,8 +229,8 @@
      "SELECT COUNT(contact_id) AS rows
       FROM ".$this->db_name."
       WHERE  del<>1
       AND    user_id=?
       AND    (".$this->filter.")",
       AND    user_id=?".
       ($this->filter ? " AND (".$this->filter.")" : ""),
      $this->user_id);
    $sql_arr = $this->db->fetch_assoc($sql_result);
@@ -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();
  }
}