alecpl
2011-06-16 cc90ed1f84174a89039feb6906775778e0c4eb18
- Add addressbook name in contact info frame (#1487958)


7 files modified
260 ■■■■■ changed files
program/include/rcube_addressbook.php 17 ●●●●● patch | view | raw | blame | history
program/include/rcube_contacts.php 12 ●●●●● patch | view | raw | blame | history
program/include/rcube_ldap.php 210 ●●●● patch | view | raw | blame | history
program/steps/addressbook/func.inc 1 ●●●● patch | view | raw | blame | history
program/steps/addressbook/show.inc 9 ●●●●● patch | view | raw | blame | history
skins/default/addressbook.css 7 ●●●●● patch | view | raw | blame | history
skins/default/templates/contact.html 4 ●●●● patch | view | raw | blame | history
program/include/rcube_addressbook.php
@@ -33,7 +33,7 @@
    const ERROR_INCOMPLETE = 3;
    const ERROR_SAVING = 4;
    const ERROR_SEARCH = 5;
    /** public properties (mandatory) */
    public $primary_key;
    public $groups = false;
@@ -43,8 +43,13 @@
    public $list_page = 1;
    public $page_size = 10;
    public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1));
    protected $error;
    /**
     * Returns addressbook name (e.g. for addressbooks listing)
     */
    abstract function get_name();
    /**
     * Save a search string for future listings
@@ -129,7 +134,7 @@
    {
      return $this->error;
    }
    /**
     * Setter for errors for internal use
     *
@@ -378,7 +383,7 @@
                }
            }
        }
        return $out;
    }
@@ -397,7 +402,7 @@
            array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'),
            array(' ', '\\1\\2', ' '),
            $str));
        foreach ($arr as $i => $part) {
            if (utf8_encode(utf8_decode($part)) == $part) {  // is latin-1 ?
                $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part),
@@ -408,7 +413,7 @@
            else
                $arr[$i] = mb_strtolower($part);
        }
        return join(" ", $arr);
    }
program/include/rcube_contacts.php
@@ -41,6 +41,7 @@
    private $user_id = 0;
    private $filter = null;
    private $result = null;
    private $name;
    private $cache;
    private $table_cols = array('name', 'email', 'firstname', 'surname');
    private $fulltext_cols = array('name', 'firstname', 'surname', 'middlename', 'nickname',
@@ -76,9 +77,18 @@
    /**
     * Returns addressbook name
     */
     function get_name()
     {
        return $this->name;
     }
    /**
     * Save a search string for future listings
     *
     * @param  string SQL params to use in listing method
     * @param string SQL params to use in listing method
     */
    function set_search_set($filter)
    {
program/include/rcube_ldap.php
@@ -292,12 +292,13 @@
    /**
    * Bind connection with DN and password
    *
    * @param string Bind DN
    * @param string Bind password
    * @return boolean True on success, False on error
    */
     * Bind connection with DN and password
     *
     * @param string Bind DN
     * @param string Bind password
     *
     * @return boolean True on success, False on error
     */
    private function _bind($dn, $pass)
    {
        if (!$this->conn) {
@@ -324,8 +325,8 @@
    /**
    * Close connection to LDAP server
    */
     * Close connection to LDAP server
     */
    function close()
    {
        if ($this->conn)
@@ -338,11 +339,21 @@
    /**
    * Set internal list page
    *
    * @param  number  Page number to list
    * @access public
    */
     * Returns address book name
     *
     * @return string Address book name
     */
    function get_name()
    {
        return $this->prop['name'];
    }
    /**
     * Set internal list page
     *
     * @param number $page Page number to list
     */
    function set_page($page)
    {
        $this->list_page = (int)$page;
@@ -350,11 +361,10 @@
    /**
    * Set internal page size
    *
    * @param  number  Number of messages to display on one page
    * @access public
    */
     * Set internal page size
     *
     * @param number $size Number of messages to display on one page
     */
    function set_pagesize($size)
    {
        $this->page_size = (int)$size;
@@ -362,10 +372,10 @@
    /**
    * Save a search string for future listings
    *
    * @param string Filter string
    */
     * Save a search string for future listings
     *
     * @param string $filter Filter string
     */
    function set_search_set($filter)
    {
        $this->filter = $filter;
@@ -373,10 +383,10 @@
    /**
    * Getter for saved search properties
    *
    * @return mixed Search properties used by this class
    */
     * Getter for saved search properties
     *
     * @return mixed Search properties used by this class
     */
    function get_search_set()
    {
        return $this->filter;
@@ -384,8 +394,8 @@
    /**
    * Reset all saved results and search parameters
    */
     * Reset all saved results and search parameters
     */
    function reset()
    {
        $this->result = null;
@@ -395,12 +405,13 @@
    /**
    * List the current set of contact records
    *
    * @param  array  List of cols to show
    * @param  int    Only return this number of records
    * @return array  Indexed list of contact records, each a hash array
    */
     * List the current set of contact records
     *
     * @param  array  List of cols to show
     * @param  int    Only return this number of records
     *
     * @return array  Indexed list of contact records, each a hash array
     */
    function list_records($cols=null, $subset=0)
    {
        // add general filter to query
@@ -453,17 +464,17 @@
    /**
    * Search contacts
    *
    * @param mixed   $fields   The field name of array of field names to search in
    * @param mixed   $value    Search value (or array of values when $fields is array)
    * @param boolean $strict   True for strict, False for partial (fuzzy) matching
    * @param boolean $select   True if results are requested, False if count only
    * @param boolean $nocount  (Not used)
    * @param array   $required List of fields that cannot be empty
    *
    * @return array  Indexed list of contact records and 'count' value
    */
     * Search contacts
     *
     * @param mixed   $fields   The field name of array of field names to search in
     * @param mixed   $value    Search value (or array of values when $fields is array)
     * @param boolean $strict   True for strict, False for partial (fuzzy) matching
     * @param boolean $select   True if results are requested, False if count only
     * @param boolean $nocount  (Not used)
     * @param array   $required List of fields that cannot be empty
     *
     * @return array  Indexed list of contact records and 'count' value
     */
    function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
    {
        // special treatment for ID-based search
@@ -543,10 +554,10 @@
    /**
    * Count number of available contacts in database
    *
    * @return object rcube_result_set Resultset with values for 'count' and 'first'
    */
     * Count number of available contacts in database
     *
     * @return object rcube_result_set Resultset with values for 'count' and 'first'
     */
    function count()
    {
        $count = 0;
@@ -570,10 +581,10 @@
    /**
    * Return the last result set
    *
    * @return object rcube_result_set Current resultset or NULL if nothing selected yet
    */
     * Return the last result set
     *
     * @return object rcube_result_set Current resultset or NULL if nothing selected yet
     */
    function get_result()
    {
        return $this->result;
@@ -581,12 +592,13 @@
    /**
    * Get a specific contact record
    *
    * @param mixed   Record identifier
    * @param boolean Return as associative array
    * @return mixed  Hash array or rcube_result_set with all record fields
    */
     * Get a specific contact record
     *
     * @param mixed   Record identifier
     * @param boolean Return as associative array
     *
     * @return mixed  Hash array or rcube_result_set with all record fields
     */
    function get_record($dn, $assoc=false)
    {
        $res = null;
@@ -624,6 +636,7 @@
     * If input not valid, the message to display can be fetched using get_error()
     *
     * @param array Assoziative array with data to save
     *
     * @return boolean True if input is valid, False if not.
     */
    public function validate($save_data)
@@ -633,18 +646,19 @@
            $this->set_error('warning', 'nonamewarning');
            return false;
        }
        // validate e-mail addresses
        return parent::validate($save_data);
    }
    /**
    * Create a new contact record
    *
    * @param array    Hash array with save data
    * @return encoded record ID on success, False on error
    */
     * Create a new contact record
     *
     * @param array    Hash array with save data
     *
     * @return encoded record ID on success, False on error
     */
    function insert($save_cols)
    {
        // Map out the column names to their LDAP ones to build the new entry.
@@ -698,12 +712,13 @@
    /**
    * Update a specific contact record
    *
    * @param mixed Record identifier
    * @param array Hash array with save data
    * @return boolean True on success, False on error
    */
     * Update a specific contact record
     *
     * @param mixed Record identifier
     * @param array Hash array with save data
     *
     * @return boolean True on success, False on error
     */
    function update($id, $save_cols)
    {
        $record = $this->get_record($id, true);
@@ -713,6 +728,7 @@
        $newdata = array();
        $replacedata = array();
        $deletedata = array();
        foreach ($this->fieldmap as $col => $fld) {
            $val = $save_cols[$col];
            if ($fld) {
@@ -816,11 +832,12 @@
    /**
    * Mark one or more contact records as deleted
    *
    * @param array  Record identifiers
    * @return boolean True on success, False on error
    */
     * Mark one or more contact records as deleted
     *
     * @param array  Record identifiers
     *
     * @return boolean True on success, False on error
     */
    function delete($ids)
    {
        if (!is_array($ids)) {
@@ -856,10 +873,8 @@
    /**
    * Execute the LDAP search based on the stored credentials
    *
    * @access private
    */
     * Execute the LDAP search based on the stored credentials
     */
    private function _exec_search($count = false)
    {
        if ($this->ready)
@@ -894,7 +909,7 @@
        return false;
    }
    /**
     * Set server controls for Virtual List View (paginated listing)
     */
@@ -917,8 +932,8 @@
    /**
    * @access private
    */
     * Converts LDAP entry into an array
     */
    private function _ldap2result($rec)
    {
        $out = array();
@@ -947,8 +962,8 @@
    /**
    * @access private
    */
     * Return real field name (from fields map)
     */
    private function _map_field($field)
    {
        return $this->fieldmap[$field];
@@ -956,9 +971,9 @@
    /**
    * @access private
    */
    private function _attr_name($name)
     * Returns unified attribute name (resolving aliases)
     */
    private static function _attr_name($name)
    {
        // list of known attribute aliases
        $aliases = array(
@@ -973,8 +988,8 @@
    /**
    * @access private
    */
     * Prints debug info to the log
     */
    private function _debug($str)
    {
        if ($this->debug)
@@ -983,9 +998,14 @@
    /**
    * @static
    */
    private function _quote_string($str, $dn=false)
     * Quotes attribute value string
     *
     * @param string $str Attribute value
     * @param bool   $dn  True if the attribute is a DN
     *
     * @return string Quoted string
     */
    private static function _quote_string($str, $dn=false)
    {
        // take firt entry if array given
        if (is_array($str))
@@ -1295,7 +1315,7 @@
        # construct the string from right to left
        $str = "020100"; # contentCount
        $ber_val = self::_ber_encode_int($offset);  // returns encoded integer value in hex format
        // calculate octet length of $ber_val
@@ -1357,7 +1377,7 @@
    {
        $val = dechex($offset);
        $prefix = '';
        // check if bit 8 of high byte is 1
        if (preg_match('/^[89abcdef]/', $val))
            $prefix = '00';
program/steps/addressbook/func.inc
@@ -81,6 +81,7 @@
    $OUTPUT->set_env('address_sources', $js_list);
    $OUTPUT->set_pagetitle(rcube_label('addressbook'));
    $_SESSION['addressbooks_count'] = count($js_list);
    $CONTACTS = rcmail_contact_source($source, true);
}
program/steps/addressbook/show.inc
@@ -32,6 +32,15 @@
    $OUTPUT->set_env('cid', $record['ID']);
}
// get address book name (for display)
if ($_SESSION['addressbooks_count'] > 1) {
    $name = $CONTACTS->get_name();
    if (!$name && $source == 0) {
        $name = rcube_label('personaladrbook');
    }
    $OUTPUT->set_env('sourcename', $name);
}
// return raw photo of the given contact
if ($RCMAIL->action == 'photo') {
    if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
skins/default/addressbook.css
@@ -384,3 +384,10 @@
{
    padding: 2px;
}
#sourcename
{
  color: #666;
  font-size: 10px;
  margin-left: 2px;
}
skins/default/templates/contact.html
@@ -9,6 +9,10 @@
<div id="contact-title" class="boxtitle"><roundcube:label name="contactproperties" /></div>
<div id="contact-details" class="boxcontent">
  <roundcube:if condition="strlen(env:sourcename)" />
    <div id="sourcename"><roundcube:label name="addressbook" />: <roundcube:var name="env:sourcename" /></div>
  <roundcube:endif />
  <div id="contactphoto"><roundcube:object name="contactphoto" id="contactpic" placeholder="/images/contactpic.png" /></div>
  <roundcube:object name="contacthead" id="contacthead" />
  <div style="clear:both"></div>