function getNewListElastixAccounts($searchFilter, &$errmsg)
{
    global $arrConf;
    $error = '';
    $pDB = new paloDB($arrConf['elastix_dsn']["elastix"]);
    $pACL = new paloACL($pDB);
    $astMang = AsteriskManagerConnect($error);
    if ($astMang == false) {
        $this->errMsg = $error;
        return false;
    }
    $arrCredentials = getUserCredentials($_SESSION['elastix_user']);
    //obtenemos el codigo pbx de la organizacion
    $query = "SELECT code from organization where id=?";
    $result = $pDB->getFirstRowQuery($query, false, array($arrCredentials["id_organization"]));
    if ($result == false) {
        $errmsg = "An error has ocurred to retrieved organization data. ";
        return false;
    } else {
        $pbxCode = $result[0];
    }
    //1) obtenemos los parametros generales de configuracion para asterisk websocket y el cliente de chat de elastix
    $chatConfig = getChatClientConfig($pDB, $error);
    if ($chatConfig == false) {
        $errmsg = "An error has ocurred to retrieved server configuration params. " . $error;
        return false;
    }
    //2) TODO:obtener el dominio sip de la organizacion si no se encuentra configurado utilizar
    //   el ws_server
    $dominio = $chatConfig['elastix_chat_server'];
    //3) obtenemos la informacion de las cuentas de los usuarios
    $name = null;
    if (!empty($searchFilter)) {
        $name = $searchFilter;
    }
    $result = $pACL->getUsersAccountsInfoByDomain($arrCredentials["id_organization"], $name);
    if ($result === false) {
        //hubo un error de la base de datos ahi que desactivar la columna lateral
        $errmsg = "An error has ocurred to retrieved Contacts Info. " . $pACL->errMsg;
        return false;
    } else {
        $arrContacts = array();
        foreach ($result as $key => $value) {
            //TODO: por el momento se obtine la presencia del usuario al
            // travès de AMI con la función que extension_state
            // en el futuro esto debe ser manejado con la libreria jssip
            // actualmente este libreria no tiene esa funcion implementada
            /*
            -1 = Extension not found
            0 = Idle
            1 = In Use
            2 = Busy
            4 = Unavailable
            8 = Ringing
            16 = On Hold
            */
            if ($value['extension'] != '' && isset($value['extension'])) {
                $result = $astMang->send_request('ExtensionState', array('Exten' => "{$value['extension']}", 'Context' => "{$pbxCode}-ext-local"));
                if ($result['Response'] == 'Success') {
                    $status = getStatusContactFromCode($result['Status']);
                    $st_code = $result['Status'];
                    if ($result['Status'] == '-1') {
                        $index_st = 'not_found';
                    } elseif ($result['Status'] == '4') {
                        $index_st = 'unava';
                    } else {
                        $index_st = 'ava';
                    }
                } else {
                    //TODO:ahi un error con el manager y nopuede determinar le estado de los
                    //contactos por lo tanto dejo a todas como disponibles
                    $index_st = 'ava';
                    $st_code = 0;
                    $status = _tr('Idle');
                }
                if ($value['id'] != $arrCredentials['idUser']) {
                    $arrContacts[$index_st][$key]['idUser'] = $value['id'];
                    $arrContacts[$index_st][$key]['display_name'] = $value['name'];
                    $arrContacts[$index_st][$key]['username'] = $value['username'];
                    $arrContacts[$index_st][$key]['presence'] = $status;
                    $arrContacts[$index_st][$key]['st_code'] = $st_code;
                    $arrContacts[$index_st][$key]['uri'] = "{$value['elxweb_device']}@{$dominio}";
                    $arrContacts[$index_st][$key]['alias'] = "{$value['alias']}@{$dominio}";
                } else {
                    $arrContacts['my_info']['uri'] = "{$value['elxweb_device']}@{$dominio}";
                    $arrContacts['my_info']['ws_servers'] = $chatConfig['ws_servers'];
                    $arrContacts['my_info']['password'] = $_SESSION['elastix_pass2'];
                    $arrContacts['my_info']['display_name'] = $value['name'];
                    $arrContacts['my_info']['elxuser_username'] = $value['username'];
                    $arrContacts['my_info']['elxuser_exten'] = $value['extension'];
                    $arrContacts['my_info']['elxuser_faxexten'] = $value['fax_extension'];
                    $arrContacts['my_info']['st_code'] = $st_code;
                    foreach ($chatConfig as $key => $value) {
                        $arrContacts['my_info'][$key] = $value;
                    }
                }
            }
        }
        $resultado = $arrContacts;
    }
    $astMang->disconnect();
    return $resultado;
}
Example #2
0
function handleJSON_getVideoPoster($smarty, $module_name)
{
    global $arrConf;
    $dialstring = isset($_GET['dialstring']) ? trim($_GET['dialstring']) : '';
    //$w = 150; $h = 120;
    $w = 200;
    $h = 150;
    Header('Content-Type: image/png');
    $im = imagecreatetruecolor($w, $h) or die('Failed to create image');
    $textcolor = imagecolorallocate($im, 192, 0, 0);
    $bgcolor = imagecolorallocate($im, 0, 0, 0);
    // Fondo negro
    imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
    // Mostrar texto
    $domainfont = 2;
    $dialstringfont = 5;
    $otherfont = 4;
    $domain = '';
    if (strpos($dialstring, '@') !== FALSE) {
        $t = explode('@', $dialstring);
        $dialstring = $t[0];
        $domain = $t[1];
    }
    if ($domain == '') {
        $error = NULL;
        $pDB = new paloDB($arrConf['elastix_dsn']["elastix"]);
        $paramSIP = getChatClientConfig($pDB, $error);
        $domain = $paramSIP['elastix_chat_server'];
    }
    $textlayout = array(array($domainfont, NULL, NULL, $domain), array($domainfont, NULL, NULL, ''), array($dialstringfont, NULL, NULL, $dialstring), array($domainfont, NULL, NULL, ''), array($otherfont, NULL, NULL, 'SOUND'), array($otherfont, NULL, NULL, 'ONLY'));
    $totalheight = 0;
    for ($i = 0; $i < count($textlayout); $i++) {
        $textlayout[$i][2] = imagefontheight($textlayout[$i][0]);
        $textlayout[$i][1] = imagefontwidth($textlayout[$i][0]) * strlen($textlayout[$i][3]);
        $totalheight += $textlayout[$i][2];
    }
    // Línea central, inicio
    $centery = ($h - $totalheight) / 2;
    for ($i = 0; $i < count($textlayout); $i++) {
        $leftx = ($w - $textlayout[$i][1]) / 2;
        imagestring($im, $textlayout[$i][0], $leftx, $centery, $textlayout[$i][3], $textcolor);
        $centery += $textlayout[$i][2];
    }
    // Mostrar imagen;
    imagepng($im);
    imagedestroy($im);
}