Exemplo n.º 1
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;
}