예제 #1
0
파일: index.php 프로젝트: hardikk/HNH
function report_adress_book($smarty, $module_name, $local_templates_dir, $pDB, $pDB_2, $arrLang, $arrConf, $dsn_agi_manager, $dsnAsterisk)
{
    $padress_book = new paloAdressBook($pDB);
    $arrBooker = $padress_book->getBookerList();
    $arrPayment_type = array(0 => 'Khách lẻ không thường xuyên', 1 => 'Khách lẻ thường xuyên', 2 => 'Khách hàng công ty', 3 => 'Khách hàng đại lý');
    $arrComboElements = array("customer_code" => "Mã khách hàng", "firstname" => "Tên khách hàng", "phone" => "Số điện thoại", "email" => "Email", "agent_id" => "Booker", "sale" => "Kinh Doanh", "booker" => "Kế Toán", "type" => "Loại khách hàng");
    $arrFormElements = array("field" => array("LABEL" => "Tìm theo", "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrComboElements, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "pattern" => array("LABEL" => "", "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "INPUT_EXTRA_PARAM" => array('id' => 'filter_value')), "booker" => array("LABEL" => "", "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrBooker, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "payment" => array("LABEL" => "", "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrPayment_type, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""));
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    $smarty->assign("SHOW", "Tìm");
    $smarty->assign("module_name", $module_name);
    $field = NULL;
    $pattern = NULL;
    $namePattern = NULL;
    if (isset($_POST['field']) and isset($_POST['pattern']) and $_POST['pattern'] != "") {
        $field = $_POST['field'];
        $pattern = "%" . trim($_POST['pattern']) . "%";
        $namePattern = trim($_POST['pattern']);
        //$nameField=$arrComboElements[$field];
        //$agent_id = $_POST['booker'];
        //$payment_type = $_POST['booker'];
    }
    $arrFilter = array("field" => $field, "pattern" => $namePattern);
    $startDate = $endDate = date("Y-m-d H:i:s");
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->enableExport();
    // enable export.
    $oGrid->setNameFile_Export("HNH_KhachHang");
    $oGrid->addFilterControl(_tr("Filter applied ") . $field . " = {$namePattern}", $arrFilter, array("field" => "name", "pattern" => ""));
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter_adress_book.tpl", "", $arrFilter);
    $total = $padress_book->getAddressBook(NULL, NULL, $field, $pattern, TRUE);
    $total_datos = $total[0]["total"];
    //Paginacion
    if ($oGrid->isExportAction()) {
        $total = $total_datos;
        $limit = $total;
        $arr_cols = array(0 => array("name" => "Mã KH", "property1" => ""), 1 => array("name" => "Tên khách hàng", "property1" => ""), 2 => array("name" => "Họ/Hình thức", "property1" => ""), 3 => array("name" => "Điện thoại/Liên hệ", "property1" => ""), 4 => array("name" => "Email/Liên hệ", "property1" => ""), 5 => array("name" => "Booker", "property1" => ""), 6 => array("name" => "Kinh doanh", "property1" => ""), 7 => array("name" => "Kế toán", "property1" => ""), 8 => array("name" => "Phân loại", "property1" => ""), 9 => array("name" => "Thẻ thành viên", "property1" => ""), 10 => array("name" => "Cách thanh toán", "property1" => ""));
    } else {
        $limit = 20;
        $total = $total_datos;
        $arr_cols = array(0 => array("name" => "", "property1" => ""), 1 => array("name" => "Mã KH", "property1" => ""), 2 => array("name" => "Tên khách hàng", "property1" => ""), 3 => array("name" => "Họ/Hình thức", "property1" => ""), 4 => array("name" => "Điện thoại/Liên hệ", "property1" => ""), 5 => array("name" => "Email/Liên hệ", "property1" => ""), 6 => array("name" => "Booker", "property1" => ""), 7 => array("name" => "Kinh doanh", "property1" => ""), 8 => array("name" => "Kế toán", "property1" => ""), 9 => array("name" => "Phân loại", "property1" => ""), 10 => array("name" => "Thẻ thành viên", "property1" => ""), 11 => array("name" => "Cách thanh toán", "property1" => ""), 12 => array("name" => "Lựa chọn", "property1" => ""));
    }
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $inicio = $total == 0 ? 0 : $offset + 1;
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    //Fin Paginacion
    $arrResult = $padress_book->getAddressBook($limit, $offset, $field, $pattern, FALSE);
    //var_dump($arrResult);die;
    $arrData = null;
    //echo print_r($arrResult,true);
    if (is_array($arrResult) && $total > 0) {
        if ($oGrid->isExportAction()) {
            foreach ($arrResult as $key => $adress_book) {
                $typeContact = "";
                switch ($adress_book['type']) {
                    case '0':
                        $typeContact = "Khách hàng lẽ";
                        break;
                    case '1':
                        $typeContact = "Khách lẽ thường xuyên";
                        break;
                    case '2':
                        $typeContact = 'Khách hàng công ty';
                        break;
                    case '3':
                        $typeContact = "Khách hàng đại lý";
                        break;
                    default:
                        break;
                }
                $phone_list = '';
                if (isset($adress_book['number']) && count($adress_book['number']) > 0) {
                    foreach ($adress_book['number'] as $phone) {
                        $phone_list .= is_null($phone) || trim($phone) == '' ? '' : $phone . '\\n';
                    }
                }
                //SDT column
                $email_list = '';
                if (count($adress_book['email']) > 0) {
                    foreach ($adress_book['email'] as $email) {
                        $email_list .= is_null($email) || trim($email) == '' ? '' : $email . '\\n';
                    }
                }
                $arrTmp[] = $adress_book['customer_code'];
                //Ten column
                $arrTmp[] = $adress_book['firstname'];
                //Ten column
                $arrTmp[] = $adress_book['lastname'];
                //Ten column
                $arrTmp[] = $phone_list;
                $arrTmp[] = $email_list;
                $arrTmp[] = $adress_book['booker'];
                $arrTmp[] = $adress_book['sale'];
                $arrTmp[] = $adress_book['accountant'];
                $arrTmp[] = $typeContact;
                $arrTmp[] = $adress_book['membership'];
                $arrTmp[] = $adress_book['payment'];
                $arrData[] = $arrTmp;
            }
        } else {
            foreach ($arrResult as $key => $adress_book) {
                switch ($adress_book['type']) {
                    case '0':
                        $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/nor-customer.png" title="Khách hàng lẽ"/>KLE';
                        break;
                    case '1':
                        $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/fre-customer.png" title="Khách hàng lẽ thường xuyên"/>KLE-TX';
                        break;
                    case '2':
                        $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/company.png" title="Khách hàng công ty"/>CTY';
                        break;
                    case '3':
                        $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/agency.png" title="Khách hàng đại lý"/>DLY';
                        break;
                    default:
                        break;
                }
                $phone_list = '';
                if (isset($adress_book['number']) && count($adress_book['number']) > 0) {
                    foreach ($adress_book['number'] as $phone) {
                        $phone1 = explode('-', $phone);
                        $call = trim($phone1[0]);
                        $phone_list .= is_null($call) || trim($call) == '' ? '' : "<a href='?menu={$module_name}&action=call2phone&id=" . $call . "'><img border=0 src='/modules/{$module_name}/images/call.png' title='Gọi số " . $call . "'/></a> " . $phone . '<br/>';
                        //SDT column
                    }
                }
                $email_list = '';
                if (count($adress_book['email']) > 0) {
                    foreach ($adress_book['email'] as $email) {
                        $phone1 = explode('-', $email);
                        $addr = trim($phone1[0]);
                        $email_list .= is_null($addr) || trim($addr) == '' ? '' : '<a title="Gửi mail đến hộp mail này" href="mailto:' . $addr . '?Subject=[CallCenter]:" target="_top">' . $email . '</a><br/>';
                    }
                }
                $arrTmp[0] = "<input type='checkbox' name='contact_{$adress_book['id']}'  />";
                $arrTmp[1] = $adress_book['customer_code'];
                //Ten column
                $arrTmp[2] = $adress_book['firstname'];
                //Ten column
                $arrTmp[3] = $adress_book['lastname'];
                //Ten column
                $arrTmp[4] = $phone_list;
                $arrTmp[5] = $email_list;
                $arrTmp[6] = $adress_book['booker'];
                $arrTmp[7] = $adress_book['sale'];
                $arrTmp[8] = $adress_book['accountant'];
                $arrTmp[9] = $typeContact;
                $arrTmp[10] = $adress_book['membership'];
                $arrTmp[11] = $adress_book['payment'];
                $arrTmp[12] = "<a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img src='modules/{$module_name}/images/extra.png' title='Xem'></a>&nbsp;\n                <a href='?menu={$module_name}&action=edit&id=" . $adress_book['id'] . "'><img src='modules/{$module_name}/images/edit.png' title='Sửa'></a> ";
                $arrData[] = $arrTmp;
            }
        }
    }
    $oGrid->deleteList("Bạn có muốn xóa khách hàng này không?", "delete", "Xóa");
    $arrGrid = array("title" => "Thông tin khách hàng", "url" => array('menu' => $module_name, 'filter' => $pattern), "icon" => "modules/{$module_name}/images/address_book.png", "width" => "99%", "start" => $inicio, "end" => $end, "total" => $total, "columns" => $arr_cols);
    $oGrid->addNew("new", "Thêm khách hàng");
    $oGrid->showFilter(trim($htmlFilter));
    $contenidoModulo = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
    return $contenidoModulo;
}
예제 #2
0
파일: index.php 프로젝트: hardikk/HNH
function report_adress_book($smarty, $module_name, $local_templates_dir, $pDB, $pDB_2, $arrLang, $arrConf, $dsn_agi_manager, $dsnAsterisk)
{
    $padress_book = new paloAdressBook($pDB);
    $pACL = new paloACL($pDB_2);
    $user = $_SESSION["elastix_user"];
    $id_user = $pACL->getIdUser($user);
    $extension = $pACL->getUserExtension($user);
    if (is_null($extension) || $extension == "") {
        if ($pACL->isUserAdministratorGroup($user)) {
            $smarty->assign("mb_title", _tr("MESSAGE"));
            $smarty->assign("mb_message", "<b>" . $arrLang["You don't have extension number associated with user"] . "</b>");
        } else {
            $smarty->assign("mb_message", "<b>" . $arrLang["contact_admin"] . "</b>");
        }
    }
    if (getParameter('select_directory_type') != null && getParameter('select_directory_type') == 'external') {
        $smarty->assign("external_sel", 'selected=selected');
        $directory_type = 'external';
    } else {
        $smarty->assign("internal_sel", 'selected=selected');
        $directory_type = 'internal';
    }
    $_POST['select_directory_type'] = $directory_type;
    $arrComboElements = array("name" => $arrLang["Name"], "telefono" => $arrLang["Phone Number"]);
    if ($directory_type == 'external') {
        $arrComboElements["last_name"] = $arrLang["Last Name"];
    }
    $arrFormElements = array("field" => array("LABEL" => $arrLang["Filter"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrComboElements, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "pattern" => array("LABEL" => "", "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "INPUT_EXTRA_PARAM" => array('id' => 'filter_value')));
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    $smarty->assign("SHOW", $arrLang["Show"]);
    $smarty->assign("NEW_adress_book", $arrLang["New Contact"]);
    $smarty->assign("CSV", $arrLang["CSV"]);
    $smarty->assign("module_name", $module_name);
    $smarty->assign("Phone_Directory", $arrLang["Phone Directory"]);
    $smarty->assign("Internal", $arrLang["Internal"]);
    $smarty->assign("External", $arrLang["External"]);
    $field = NULL;
    $pattern = NULL;
    $namePattern = NULL;
    $allowSelection = array("name", "telefono", "last_name");
    if (isset($_POST['field']) and isset($_POST['pattern']) and $_POST['pattern'] != "") {
        $field = $_POST['field'];
        if (!in_array($field, $allowSelection)) {
            $field = "name";
        }
        $pattern = "%{$_POST['pattern']}%";
        $namePattern = $_POST['pattern'];
        $nameField = $arrComboElements[$field];
    }
    $arrFilter = array("select_directory_type" => $directory_type, "field" => $field, "pattern" => $namePattern);
    $startDate = $endDate = date("Y-m-d H:i:s");
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Phone Directory") . " =  {$directory_type} ", $arrFilter, array("select_directory_type" => "internal"), true);
    $oGrid->addFilterControl(_tr("Filter applied ") . $field . " = {$namePattern}", $arrFilter, array("field" => "name", "pattern" => ""));
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter_adress_book.tpl", "", $arrFilter);
    if ($directory_type == 'external') {
        $total = $padress_book->getAddressBook(NULL, NULL, $field, $pattern, TRUE, $id_user);
    } else {
        $total = $padress_book->getDeviceFreePBX($dsnAsterisk, NULL, NULL, $field, $pattern, TRUE);
    }
    $total_datos = $total[0]["total"];
    //Paginacion
    $limit = 20;
    $total = $total_datos;
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $inicio = $total == 0 ? 0 : $offset + 1;
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    //Fin Paginacion
    if ($directory_type == 'external') {
        $arrResult = $padress_book->getAddressBook($limit, $offset, $field, $pattern, FALSE, $id_user);
    } else {
        $arrResult = $padress_book->getDeviceFreePBX($dsnAsterisk, $limit, $offset, $field, $pattern);
    }
    $arrData = null;
    //echo print_r($arrResult,true);
    if (is_array($arrResult) && $total > 0) {
        $arrMails = array();
        $typeContact = "";
        if ($directory_type == 'internal') {
            $arrMails = $padress_book->getMailsFromVoicemail();
        }
        foreach ($arrResult as $key => $adress_book) {
            if ($directory_type == 'external') {
                $exten = explode(".", $adress_book["picture"]);
                if (isset($exten[count($exten) - 1])) {
                    $exten = $exten[count($exten) - 1];
                }
                $picture = "/var/www/address_book_images/{$adress_book['id']}_Thumbnail.{$exten}";
                if (file_exists($picture)) {
                    $arrTmp[1] = "<a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img alt='image' border='0' src='index.php?menu={$module_name}&action=getImage&idPhoto={$adress_book['id']}&thumbnail=yes&rawmode=yes'/></a>";
                } else {
                    $defaultPicture = "modules/{$module_name}/images/Icon-user_Thumbnail.png";
                    $arrTmp[1] = "<a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img border='0' alt='image' src='{$defaultPicture}'/></a>";
                }
            }
            $arrTmp[0] = $directory_type == 'external' ? "<input type='checkbox' name='contact_{$adress_book['id']}'  />" : '';
            if ($directory_type == 'external') {
                $email = $adress_book['email'];
                if ($adress_book['status'] == 'isPublic') {
                    if ($id_user == $adress_book['iduser']) {
                        $typeContact = "<div><div style='float: left;'><a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img alt='public' style='padding: 5px;' title='" . $arrLang['Public Contact'] . "' border='0' src='modules/{$module_name}/images/public_edit.png' /></a></div><div style='padding: 16px 0px 0px 5px; text-align:center;'><span style='visibility: hidden;'>" . $arrLang['Public editable'] . "</span></div></div>";
                        $arrTmp[0] = "<input type='checkbox' name='contact_{$adress_book['id']}'  />";
                    } else {
                        $typeContact = "<div><div style='float: left;'><a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img alt='public' style='padding: 5px;' title='" . $arrLang['Public Contact'] . "' border='0' src='modules/{$module_name}/images/public.png' /></a></div><div style='padding: 16px 0px 0px 5px; text-align:center;'><span style='visibility: hidden;'>" . $arrLang['Public not editable'] . "</span></div></div>";
                        $arrTmp[0] = "";
                    }
                } else {
                    $typeContact = "<div><div style='float: left;'><a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'><img alt='private' style='padding: 5px;' title='" . $arrLang['Private Contact'] . "' border='0' src='modules/{$module_name}/images/contact.png' /></a></div><div style='padding: 16px 0px 0px 5px; text-align:center;'><span style='visibility: hidden;'>" . $arrLang['Private'] . "</span></div></div>";
                }
            } else {
                if (isset($arrMails[$adress_book['id']])) {
                    $email = $arrMails[$adress_book['id']];
                    $typeContact = "<div><div style='float: left;'><img alt='public' title='" . $arrLang['Public Contact'] . "' src='modules/{$module_name}/images/public.png' /></div><div style='padding: 16px 0px 0px 5px; text-align:center;'><span style='visibility: hidden;'>" . $arrLang['Public not editable'] . "</span></div></div>";
                } else {
                    $email = '';
                    $typeContact = "<div><div style='float: left;'><img alt='public' title='" . $arrLang['Public Contact'] . "' src='modules/{$module_name}/images/public.png' /></div><div style='padding: 16px 0px 0px 5px; text-align:center;'><span style='visibility: hidden;'>" . $arrLang['Public not editable'] . "</span></div></div>";
                }
            }
            $arrTmp[2] = $directory_type == 'external' ? "<a href='?menu={$module_name}&action=show&id=" . $adress_book['id'] . "'>" . htmlspecialchars($adress_book['last_name'], ENT_QUOTES, "UTF-8") . " " . htmlspecialchars($adress_book['name'], ENT_QUOTES, "UTF-8") . "</a>" : $adress_book['description'];
            $arrTmp[3] = $directory_type == 'external' ? $adress_book['telefono'] : $adress_book['id'];
            $arrTmp[4] = $email;
            $arrTmp[5] = "<a href='?menu={$module_name}&action=call2phone&id=" . $adress_book['id'] . "&type=" . $directory_type . "'><img border=0 src='/modules/{$module_name}/images/call.png' /></a>";
            $arrTmp[6] = "<a href='?menu={$module_name}&action=transfer_call&id=" . $adress_book['id'] . "&type=" . $directory_type . "'>{$arrLang["Transfer"]}</a>";
            $arrTmp[7] = $typeContact;
            $arrData[] = $arrTmp;
        }
    }
    if ($directory_type == 'external') {
        $name = "";
        $picture = $arrLang["picture"];
        $oGrid->deleteList(_tr("Are you sure you wish to delete the contact."), "delete", _tr("Delete"));
    } else {
        $name = "";
        $picture = "";
    }
    $arrGrid = array("title" => $arrLang["Address Book"], "url" => array('menu' => $module_name, 'filter' => $pattern, 'select_directory_type' => $directory_type), "icon" => "modules/{$module_name}/images/address_book.png", "width" => "99%", "start" => $inicio, "end" => $end, "total" => $total, "columns" => array(0 => array("name" => $name, "property1" => ""), 1 => array("name" => $picture, "property1" => ""), 2 => array("name" => $arrLang["Name"], "property1" => ""), 3 => array("name" => $arrLang["Phone Number"], "property1" => ""), 4 => array("name" => $arrLang["Email"], "property1" => ""), 5 => array("name" => $arrLang["Call"], "property1" => ""), 6 => array("name" => $arrLang["Transfer"], "property1" => ""), 7 => array("name" => $arrLang["Type Contact"], "property1" => "")));
    $oGrid->addNew("new", _tr("New Contact"));
    $oGrid->showFilter(trim($htmlFilter));
    $contenidoModulo = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
    return $contenidoModulo;
}
예제 #3
0
}
// limit search
if ($query == '' || is_null($query) || strlen($query) <= 4) {
    $total = 0;
    $entry = array('id' => 0, 'cell' => array('customer_code' => 'ERROR', 'firstname' => 'Nhập mục cần tìm!', 'lastname' => '>= 3 ký tự', 'phone' => $query, 'email' => '', 'agent_id' => '', 'sale' => '', 'accountant' => '', 'type' => '', 'membership' => '', 'payment_type' => '', 'view' => ''));
    $jsonData['rows'][] = $entry;
} elseif ($qtype == 'phone' && strlen($query) <= 7) {
    $total = 0;
    $entry = array('id' => 0, 'cell' => array('customer_code' => 'ERROR', 'firstname' => 'Số điện thoại >= 6 số', 'lastname' => '', 'phone' => $query, 'email' => '', 'agent_id' => '', 'sale' => '', 'accountant' => '', 'type' => '', 'membership' => '', 'payment_type' => '', 'view' => ''));
    $jsonData['rows'][] = $entry;
} else {
    /* new code using customer class */
    $pDB = new paloDB($arrConf['cadena_dsn']);
    // address_book
    $padress_book = new paloAdressBook($pDB);
    $total = $padress_book->getAddressBook(NULL, NULL, $qtype, $query, TRUE, $sort, $letter);
    $total = $total[0]["total"];
    $arrResult = $padress_book->getAddressBook($rp, $page - 1, $qtype, $query, FALSE, $sort, $letter);
}
$arrPayment_type = array(0 => 'Khách lẻ không thường xuyên', 1 => 'Khách lẻ thường xuyên', 2 => 'Khách hàng công ty', 3 => 'Khách hàng đại lý');
if (is_array($arrResult) && $total > 0) {
    $typeContact = "";
    foreach ($arrResult as $key => $adress_book) {
        switch ($adress_book['type']) {
            case '0':
                $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/nor-customer.png" title="Khách hàng lẽ"/>KLE';
                break;
            case '1':
                $typeContact = '<img border=0 src="/modules/' . $module_name . '/images/fre-customer.png" title="Khách hàng lẽ thường xuyên"/>KLE-TX';
                break;
            case '2':
예제 #4
0
function report_adress_book($smarty, $module_name, $local_templates_dir, $pDB, $pDB_2, $arrLang, $dsnAsterisk)
{
    include_once "modules/address_book/libs/paloSantoAdressBook.class.php";
    $padress_book = new paloAdressBook($pDB);
    $pACL = new paloACL($pDB_2);
    $id_user = $pACL->getIdUser($_SESSION["elastix_user"]);
    if (isset($_POST['select_directory_type']) && $_POST['select_directory_type'] == 'External') {
        $smarty->assign("external_sel", 'selected=selected');
        $directory_type = 'external';
    } else {
        $smarty->assign("internal_sel", 'selected=selected');
        $directory_type = 'internal';
    }
    $_POST['select_directory_type'] = $directory_type;
    $arrComboElements = array("name" => $arrLang["Name"], "telefono" => $arrLang["Phone Number"]);
    if ($directory_type == 'external') {
        $arrComboElements["last_name"] = $arrLang["Last Name"];
    }
    $arrFormElements = array("field" => array("LABEL" => $arrLang["Filter"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrComboElements, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "pattern" => array("LABEL" => "", "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "INPUT_EXTRA_PARAM" => ""));
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    $smarty->assign("SHOW", $arrLang["Show"]);
    $smarty->assign("CSV", $arrLang["CSV"]);
    $smarty->assign("module_name", $module_name);
    $smarty->assign("Phone_Directory", $arrLang["Phone Directory"]);
    $smarty->assign("Internal", $arrLang["Internal"]);
    $smarty->assign("External", $arrLang["External"]);
    $field = NULL;
    $pattern = NULL;
    $namePattern = NULL;
    $allowSelection = array("name", "telefono", "last_name");
    if (isset($_POST['field']) and isset($_POST['pattern']) and $_POST['pattern'] != "") {
        $field = $_POST['field'];
        if (!in_array($field, $allowSelection)) {
            $field = "name";
        }
        $pattern = '%' . $_POST['pattern'] . '%';
        $namePattern = $_POST['pattern'];
        $nameField = $arrComboElements[$field];
    }
    $startDate = $endDate = date("Y-m-d H:i:s");
    $arrFilter = array("select_directory_type" => $directory_type, "field" => $field, "pattern" => $namePattern);
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Phone Directory") . " =  {$directory_type} ", $arrFilter, array("select_directory_type" => "internal"), true);
    $oGrid->addFilterControl(_tr("Filter applied ") . $field . " = {$namePattern}", $arrFilter, array("field" => "name", "pattern" => ""));
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter_adress_book.tpl", "", $arrFilter);
    if ($directory_type == 'external') {
        $total = $padress_book->getAddressBook(NULL, NULL, $field, $pattern, TRUE, $id_user);
    } else {
        $total = $padress_book->getDeviceFreePBX($dsnAsterisk, NULL, NULL, $field, $pattern, TRUE);
    }
    $total_datos = $total[0]["total"];
    //Paginacion
    $limit = 20;
    $total = $total_datos;
    $oGrid->setLimit($limit);
    $offset = $oGrid->getOffSet($limit, $total, isset($_GET['nav']) ? $_GET['nav'] : NULL, isset($_GET['start']) ? $_GET['start'] : NULL);
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    //Fin Paginacion
    if ($directory_type == 'external') {
        $arrResult = $padress_book->getAddressBook($limit, $offset, $field, $pattern, FALSE, $id_user);
    } else {
        $arrResult = $padress_book->getDeviceFreePBX($dsnAsterisk, $limit, $offset, $field, $pattern);
    }
    $arrData = null;
    if (is_array($arrResult) && $total > 0) {
        $arrMails = array();
        if ($directory_type == 'internal') {
            $arrMails = $padress_book->getMailsFromVoicemail();
        }
        foreach ($arrResult as $key => $adress_book) {
            if ($directory_type == 'external') {
                $email = $adress_book['email'];
            } else {
                if (isset($arrMails[$adress_book['id']])) {
                    $email = $arrMails[$adress_book['id']];
                } else {
                    $email = '';
                }
            }
            $arrTmp[0] = $directory_type == 'external' ? htmlspecialchars($adress_book['last_name'], ENT_QUOTES, "UTF-8") . " " . htmlspecialchars($adress_book['name'], ENT_QUOTES, "UTF-8") : $adress_book['description'];
            $number = $directory_type == 'external' ? htmlspecialchars($adress_book['telefono'], ENT_QUOTES, "UTF-8") : $adress_book['id'];
            $arrTmp[1] = "<a href='javascript:return_phone_number(\"{$number}\", \"{$directory_type}\", \"{$adress_book['id']}\")'>{$number}</a>";
            $arrTmp[2] = htmlspecialchars($email, ENT_QUOTES, "UTF-8");
            $arrData[] = $arrTmp;
        }
    }
    if ($directory_type == 'external') {
        $name = "<input type='submit' name='delete' value='{$arrLang["Delete"]}' class='button' onclick=\" return confirmSubmit('{$arrLang["Are you sure you wish to delete the contact."]}');\" />";
    } else {
        $name = "";
    }
    $arrGrid = array("title" => $arrLang["Address Book"], "url" => array('menu' => $module_name, 'action' => 'phone_numbers', 'rawmode' => 'yes', 'filter' => $pattern), "icon" => "images/list.png", "width" => "99%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $end, "total" => $total, "columns" => array(0 => array("name" => $arrLang["Name"], "property1" => ""), 1 => array("name" => $arrLang["Phone Number"], "property1" => ""), 2 => array("name" => $arrLang["Email"], "property1" => "")));
    $oGrid->showFilter(trim($htmlFilter));
    $contenidoModulo = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
    return $contenidoModulo;
}