Overview

Packages

  • Horde
    • Form
    • MIME
      • Viewer
    • Scheduler
  • None
  • Whups
    • UnitTests

Classes

  • Horde_Core_Ui_VarRenderer_whups
  • Whups
  • Whups_Ajax_Imple_ContactAutoCompleter
  • Whups_Api
  • Whups_Driver
  • Whups_Driver_Sql
  • Whups_Form_AddComment
  • Whups_Form_Admin_AddAttribute
  • Whups_Form_Admin_AddPriority
  • Whups_Form_Admin_AddQueue
  • Whups_Form_Admin_AddReply
  • Whups_Form_Admin_AddState
  • Whups_Form_Admin_AddType
  • Whups_Form_Admin_AddUser
  • Whups_Form_Admin_AddVersion
  • Whups_Form_Admin_CloneType
  • Whups_Form_Admin_DefaultPriority
  • Whups_Form_Admin_DefaultState
  • Whups_Form_Admin_DeleteAttribute
  • Whups_Form_Admin_DeletePriority
  • Whups_Form_Admin_DeleteQueue
  • Whups_Form_Admin_DeleteReply
  • Whups_Form_Admin_DeleteState
  • Whups_Form_Admin_DeleteType
  • Whups_Form_Admin_DeleteVersion
  • Whups_Form_Admin_EditAttributeStepOne
  • Whups_Form_Admin_EditAttributeStepTwo
  • Whups_Form_Admin_EditPriorityStepOne
  • Whups_Form_Admin_EditPriorityStepTwo
  • Whups_Form_Admin_EditQueueStepOne
  • Whups_Form_Admin_EditQueueStepTwo
  • Whups_Form_Admin_EditReplyStepOne
  • Whups_Form_Admin_EditReplyStepTwo
  • Whups_Form_Admin_EditStateStepOne
  • Whups_Form_Admin_EditStateStepTwo
  • Whups_Form_Admin_EditTypeStepOne
  • Whups_Form_Admin_EditTypeStepTwo
  • Whups_Form_Admin_EditUser
  • Whups_Form_Admin_EditVersionStepOne
  • Whups_Form_Admin_EditVersionStepTwo
  • Whups_Form_InsertBranch
  • Whups_Form_Query_AttributeCriterion
  • Whups_Form_Query_ChooseNameForLoad
  • Whups_Form_Query_ChooseNameForSave
  • Whups_Form_Query_DateCriterion
  • Whups_Form_Query_Delete
  • Whups_Form_Query_GroupCriterion
  • Whups_Form_Query_Parameter
  • Whups_Form_Query_PropertyCriterion
  • Whups_Form_Query_TextCriterion
  • Whups_Form_Query_UserCriterion
  • Whups_Form_Renderer_Comment
  • Whups_Form_Search
  • Whups_Form_SendReminder
  • Whups_Form_Ticket_CreateStepFour
  • Whups_Form_Ticket_CreateStepOne
  • Whups_Form_Ticket_CreateStepThree
  • Whups_Form_Ticket_CreateStepTwo
  • Whups_Form_Ticket_Edit
  • Whups_Form_TicketDetails
  • Whups_LoginTasks_SystemTask_Upgrade
  • Whups_Mail
  • Whups_Query
  • Whups_Query_Manager
  • Whups_Reports
  • Whups_Ticket
  • Whups_View_Base
  • Whups_View_Results
  • Whups_View_SavedQueries
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Attach the contact auto completer to a javascript element.
  4:  *
  5:  * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file LICENSE for license information (BSD). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
  9:  *
 10:  * @author  Michael Slusarz <slusarz@horde.org>
 11:  * @package Whups
 12:  */
 13: class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Core_Ajax_Imple_AutoCompleter
 14: {
 15:     /**
 16:      * Attach the Imple object to a javascript event.
 17:      *
 18:      * @param array $js_params  See
 19:      *                          Horde_Core_Ajax_Imple_AutoCompleter::_attach().
 20:      *
 21:      * @return array  See Horde_Core_Ajax_Imple_AutoCompleter::_attach().
 22:      */
 23:     protected function _attach($js_params)
 24:     {
 25:         $js_params['indicator'] = $this->_params['triggerId'] . '_loading_img';
 26: 
 27:         $ret = array(
 28:             'params' => $js_params,
 29:             'raw_params' => array(
 30:                 'onSelect' => 'function (v) { if (!v.endsWith(";")) { v += ","; } return v + " "; }',
 31:                 'onType' => 'function (e) { return e.include("<") ? "" : e; }'
 32:             )
 33:         );
 34: 
 35:         $ret['ajax'] = 'ContactAutoCompleter';
 36: 
 37:         return $ret;
 38:     }
 39: 
 40:     /**
 41:      * TODO
 42:      *
 43:      * @param array $args  TODO
 44:      *
 45:      * @return string  TODO
 46:      */
 47:     public function handle($args, $post)
 48:     {
 49:         // Avoid errors if 'input' isn't set and short-circuit empty searches.
 50:         if (empty($args['input']) ||
 51:             !($input = Horde_Util::getFormData($args['input']))) {
 52:             return array();
 53:         }
 54: 
 55:         return $this->_getAddressList($input);
 56:     }
 57: 
 58:     /**
 59:      * Uses the Registry to expand names and return error information for
 60:      * any address that is either not valid or fails to expand.
 61:      *
 62:      * This function will not search if the address string is empty.
 63:      *
 64:      * @param string $addrString  The name(s) or address(es) to expand.
 65:      *
 66:      * @return array  All matching addresses.
 67:      */
 68:     protected function _getAddressList($addrString = '')
 69:     {
 70:         if (!preg_match('|[^\s]|', $addrString)) {
 71:             return array();
 72:         }
 73: 
 74:         $search = reset(array_filter(array_map('trim', Horde_Mime_Address::explode($addrString, ',;'))));
 75:         $searchpref = Whups::getAddressbookSearchParams();
 76: 
 77:         try {
 78:             $res = $GLOBALS['registry']->call('contacts/search', array($search, $searchpref['sources'], $searchpref['fields']));
 79:         } catch (Horde_Exception $e) {
 80:             Horde::logMessage($e, 'ERR');
 81:             return array();
 82:         }
 83: 
 84:         if (!count($res)) {
 85:             return array();
 86:         }
 87: 
 88:         /* The first key of the result will be the search term. The matching
 89:          * entries are stored underneath this key. */
 90:         $search = array();
 91:         foreach (reset($res) as $val) {
 92:             if (!empty($val['email'])) {
 93:                 if (strpos($val['email'], ',') !== false) {
 94:                     $search[] = Horde_Mime_Address::encode($val['name'], 'personal') . ': ' . $val['email'] . ';';
 95:                 } else {
 96:                     $mbox_host = explode('@', $val['email']);
 97:                     if (isset($mbox_host[1])) {
 98:                         $search[] = Horde_Mime_Address::writeAddress($mbox_host[0], $mbox_host[1], $val['name']);
 99:                     }
100:                 }
101:             }
102:         }
103: 
104:         $sort_list = array();
105:         foreach ($search as $val) {
106:             $sort_list[$val] = levenshtein($addrString, $val);
107:         }
108:         asort($sort_list, SORT_NUMERIC);
109: 
110:         return array_keys($sort_list);
111:     }
112: }
113: 
API documentation generated by ApiGen