[ create a new paste ] login | about

Link: http://codepad.org/d2rJi41o    [ raw code | fork ]

PHP, pasted on Aug 8:
<?php
/**
 * Example backend class for a custom address book
 *
 * This one just holds a static list of address records
 *
 * @author Thomas Bruederli
 */
class example_addressbook_backend extends rcube_addressbook
{
  public $primary_key = 'ID';
  public $readonly = true;
  public $groups = false;
  public $lista = array();

  private $filter;
  private $result;
  private $name;
  public $coltypes = array('name', 'firstname', 'surname', 'middlename', 'prefix', 'suffix', 'nickname',
  	'jobtitle', 'organization', 'department', 'assistant', 'manager',
  	'gender', 'maidenname', 'spouse', 'email', 'email:item', 'phone', 'address',
  	'birthday', 'anniversary', 'website', 'im', 'notes', 'photo', 'words');

  public function __construct($name)
  {
    $this->ready = true;
    $this->name = $name;
  }

  public function get_name()
  {
    return $this->name;
  }

  public function set_search_set($filter)
  {
    $this->filter = $filter;
  }

  public function get_search_set()
  {
    return $this->filter;
  }

  public function reset()
  {
    $this->result = null;
    $this->filter = null;
  }

  function list_groups($search = null)
  {
    return array(
    );
  }

  public function list_records($cols=null, $subset=0, $busca="")
  {

  	// this is just for tests purposes
	$con = mysql_connect('localhost', 'login', 'pass') or die('Error');
	mysql_selectdb('roundcube', $con) or die('Error on select');

	$lista = mysql_query("SELECT * FROM custom_contact_table", $con);

	// $lista is the resource from datatabase
	$this->result = $this->count();
	while ($contato = mysql_fetch_assoc($lista))
	{
		$this->result->add(
			array(
				'ID' => $contato['id'], 
				'name' => $contato['nome'], 
				'firstname' => current(explode(" ",$contato['nome'])),
				'surname' => (isset($contato['vinculo']) && $contato['vinculo'] != "")?" (".$contato['vinculo'].")":"",
				'department' => array($contato['lotacao']),
				'email' => $contato['email'], 
                'user_id' => $contato['id'],
			)
		);
	}
	$cnt = count($this->result->records);
 	$this->result->count = $cnt;
 	$this->result->searchonly = true;

    return $this->result;
  }

  public function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
  {
  	$values = is_array($value)? implode("|", $value) : $value;

  	$where = "WHERE nome REGEXP '" . $values ."' OR email REGEXP '" . $values ."' OR descricao REGEXP '" . $values ."' AND email IS NOT NULL";

    return $this->list_records($fields, 0, $where);
    //return $this->result;

  }

  public function count()
  {
    return new rcube_result_set(1, ($this->list_page-1) * $this->page_size);
  }

  public function get_result()
  {
    return $this->result;
  }

  public function get_record($id, $assoc=false)
  {
    $this->list_records();
    while($record = $this->result->iterate()){
    	if($record['ID'] == $id){
    		$contact = $record;
    		break;
    	}else{
    		$contact = null;
    	}
    }
    
    if(isset($contact)){
	    $this->result = $this->count();
    	$this->result->add($contact);
    	$this->result->next();
    }

    return $contact;
  }


  function create_group($name)
  {
    $result = false;

    return $result;
  }

  function delete_group($gid)
  {
    return false;
  }

  function rename_group($gid, $newname)
  {
    return $newname;
  }

  function add_to_group($group_id, $ids)
  {
    return false;
  }

  function remove_from_group($group_id, $ids)
  {
     return false;
  }

}


Create a new paste based on this one


Comments: