예제 #1
0
파일: core.class.php 프로젝트: hardikk/HNH
 /**
  * Functional point that consults the address book of the authenticated user. The address book has an intern part that is the list * of available extensions, and an extern part that resides in a SQLITE database managed by Elastix
  *
  * @param   string    $addressBookType    Can be 'internal' or 'external'
  * @param   integer   $offset             (Optional) start of records or 0 if omitted
  * @param   integer   $limit              (Optional) limit records or all if omitted
  * @return  array     Array with the information of the contact list (address book).
  */
 function listAddressBook($addressBookType, $offset, $limit, $id_contact = NULL)
 {
     global $arrConf;
     if (!$this->_checkUserAuthorized('address_book')) {
         return false;
     }
     if (!$this->_checkOffsetLimit($offset, $limit)) {
         return false;
     }
     // Elegir entre la agenda interna y externa
     if (!isset($addressBookType) || !in_array($addressBookType, array('internal', 'external'))) {
         $this->errMsg["fc"] = 'PARAMERROR';
         $this->errMsg["fm"] = 'Invalid format';
         $this->errMsg["fd"] = 'Unrecognized address book type, must be internal or external';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     $extension = array();
     $iNumTotal = NULL;
     $dbAddressBook = $this->_getDB($arrConf['dsn_conn_database']);
     $addressBook = new paloAdressBook($dbAddressBook);
     switch ($addressBookType) {
         case 'internal':
             // Contar número de elementos de la agenda interna
             if (isset($id_contact)) {
                 $field_name = "telefono";
                 $field_pattern = $id_contact;
             } else {
                 $field_name = NULL;
                 $field_pattern = NULL;
             }
             $iNumTotal = $addressBook->getDeviceFreePBX_Completed($this->_astDSN, NULL, NULL, $field_name, $field_pattern, TRUE);
             if ($iNumTotal === false) {
                 $this->errMsg["fc"] = 'DBERROR';
                 $this->errMsg["fm"] = 'Database operation failed';
                 $this->errMsg["fd"] = 'Unable to count data from internal phonebook';
                 $this->errMsg["cn"] = get_class($addressBook);
                 return false;
             }
             if (!isset($limit)) {
                 $limit = $iNumTotal;
             }
             // Recuperar la agenda interna
             $extension = $addressBook->getDeviceFreePBX_Completed($this->_astDSN, $limit, $offset, $field_name, $field_pattern);
             if ($extension === false) {
                 $this->errMsg["fc"] = 'DBERROR';
                 $this->errMsg["fm"] = 'Database operation failed';
                 $this->errMsg["fd"] = 'Unable to read data from internal phonebook';
                 $this->errMsg["cn"] = get_class($addressBook);
                 return false;
             }
             break;
         case 'external':
             // Obtener el ID del usuario logoneado
             $id_user = $this->_leerIdUser();
             if (is_null($id_user)) {
                 return false;
             }
             /* Contar número de elementos de la agenda externa. Debido a un mal 
              * diseño de la función getAddressBook, se requiere poner un filtro 
              * de mentira, porque de lo contrario, la función ignora id_user, y
              * devuelve los contactos de todos los usuarios. */
             if (isset($id_contact)) {
                 $field_name = "id";
                 $field_pattern = $id_contact;
             } else {
                 $field_name = "name";
                 $field_pattern = "%%";
             }
             $rs = $addressBook->getAddressBook(NULL, NULL, $field_name, $field_pattern, TRUE, $id_user);
             if (!is_array($rs)) {
                 $this->errMsg["fc"] = 'DBERROR';
                 $this->errMsg["fm"] = 'Database operation failed';
                 $this->errMsg["fd"] = 'Unable to count data from external phonebook - ' . $addressBook->_DB->errMsg;
                 $this->errMsg["cn"] = get_class($addressBook);
                 return false;
             }
             $iNumTotal = $rs[0]['total'];
             if (!isset($limit)) {
                 $limit = $iNumTotal;
             }
             /* Recuperar la agenda externa. Debido a un mal diseño de la función
              * getAddressBook, se requiere poner un filtro de mentira, porque
              * de lo contrario, la función ignora id_user, y devuelve los 
              * contactos de todos los usuarios. */
             $extension = $addressBook->getAddressBook($limit, $offset, $field_name, $field_pattern, FALSE, $id_user);
             if (!is_array($extension)) {
                 $this->errMsg["fc"] = 'DBERROR';
                 $this->errMsg["fm"] = 'Database operation failed';
                 $this->errMsg["fd"] = 'Unable to read data from external phonebook - ' . $addressBook->_DB->errMsg;
                 $this->errMsg["cn"] = get_class($addressBook);
                 return false;
             }
             break;
     }
     return array('totalCount' => $iNumTotal, 'extension' => $extension);
 }