Exemple #1
0
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;
}
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;
}