Ejemplo n.º 1
0
function reportMail($smarty, $module_name, $local_templates_dir, &$arrConf, &$pImap)
{
    $jsonObject = new PaloSantoJSON();
    $arrFilter = array();
    //obtenemos el mailbox que deseamos leer
    $mailbox = getParameter('folder');
    $action = getParameter('action');
    //creamos la connección al mailbox
    $pImap->setMailbox($mailbox);
    $smarty->assign("CURRENT_MAILBOX", $pImap->getMailbox());
    $result = $pImap->login($_SESSION['elastix_user'], $_SESSION['elastix_pass2']);
    if ($result === false) {
        if ($action == 'show_messages_folder') {
            $jsonObject->set_error($pImap->errMsg);
            return $jsonObject->createJSON();
        } else {
            $smarty->assign("ERROR_FIELD", $pImap->errMsg);
            return '';
        }
    }
    $listMailbox = $pImap->getMailboxList();
    if ($result === false) {
        $jsonObject->set_error($pImap->errMsg);
        $smarty->assign("ERROR_FIELD", $pImap->errMsg);
        return '';
    } else {
        $smarty->assign('MAILBOX_FOLDER_LIST', $listMailbox);
        $smarty->assign('NEW_FOLDER', _tr('New Folder'));
    }
    $view_filter_opt['all'] = _tr("All");
    $view_filter_opt['seen'] = _tr("Seen");
    $view_filter_opt['unseen'] = _tr("Unseen");
    $view_filter_opt['flagged'] = _tr("Important");
    $view_filter_opt['unflagged'] = _tr("No Important");
    $smarty->assign("ELX_MAIL_FILTER_OPT", $view_filter_opt);
    $filter_view = 'all';
    $tmp_filter_view = getParameter('email_filter1');
    if (array_key_exists($tmp_filter_view, $view_filter_opt)) {
        $filter_view = $tmp_filter_view;
    }
    $arrFilter = array("filter_view" => $filter_view);
    //obtenemos el numero de correos que ahi en el buzon
    //filtrando por los parámetros dados
    $listUID = array();
    $total = $pImap->getNumMails($arrFilter, $listUID);
    if ($total === false) {
        $total = 0;
        $jsonObject->set_error($pImap->errMsg);
        $smarty->assign("ERROR_FIELD", $pImap->errMsg);
    }
    $limit = 50;
    //sacamos calculamos el offset
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    $currentPage = $oGrid->calculateCurrentPage();
    $numPage = $oGrid->calculateNumPage();
    $url['menu'] = $module_name;
    $url['email_filter1'] = $filter_view;
    $oGrid->setTitle(_tr('Contacts List'));
    $oGrid->setURL($url);
    $oGrid->setStart($total == 0 ? 0 : $offset + 1);
    $oGrid->setEnd($end);
    $oGrid->setTotal($total);
    $smarty->assign("TOTAL_MAILS", $total);
    $smarty->assign("CURRENT_PAGMAIL", $currentPage);
    $smarty->assign("NUM_PAGMAIL", $numPage);
    $smarty->assign("PAGINA", _tr("Page"));
    $smarty->assign("MESSAGES_LABEL", _tr("Messages"));
    $arrData = array();
    if ($total != 0) {
        $pImap->setMessageByPage($limit);
        $pImap->setOffset($offset);
        $emails = $pImap->readMails($listUID);
        if ($emails !== false) {
            foreach ($emails as $email) {
                $tmp = array();
                $class = 'elx_unseen_email';
                if ($email['SEEN'] == 1) {
                    $class = 'elx_seen_email';
                }
                $tmp[] = "<div class='elx_row {$class}' id={$email['UID']}>";
                $tmp[] = "<div class='ic'>";
                $tmp[] = "<div class='sel'><input type='checkbox' value='{$email['UID']}' class='inp1 checkmail'/></div>";
                //$tmp[]="<div class='icon'><img border='0' src='web/apps/home/images/mail2.png' class='icn_buz'></div>";
                $class = 'elx_unflagged_email';
                if ($email['FLAGGED'] == 1) {
                    $class = 'elx_flagged_email';
                }
                $tmp[] = "<div class='star'><span class='{$class} glyphicon glyphicon-star'></span></div>";
                $tmp[] = "</div>";
                //$tmp[]="<div class='email_msg_attr'>";
                $tmp[] = "<div class='from  elx_row_email_msg'> <span>" . htmlentities($email['from'], ENT_COMPAT, 'UTF-8') . "</span></div>";
                $tmp[] = "<div class='subject elx_row_email_msg'> <span>" . htmlentities($email['subject'], ENT_COMPAT, 'UTF-8') . "</span></div>";
                $tmp[] = "<div class='date elx_row_email_msg'><span>" . $email['date'] . "</span></div>";
                //$tmp[]="</div>";
                $tmp[] = "</div>";
                $arrData[] = $tmp;
            }
            $smarty->assign("MAILS", $arrData);
        } else {
            $jsonObject->set_error($pImap->errMsg);
            $smarty->assign("ERROR_FIELD", $pImap->errMsg);
        }
    }
    $pImap->close_mail_connection();
    $imapAlertErros = cleanAlertsImap();
    $listMailbox = array_diff($listMailbox, array($pImap->getMailbox()));
    $move_folder = array();
    foreach ($listMailbox as $value) {
        $move_folder[$value] = $value;
    }
    $smarty->assign("MOVE_FOLDERS", $move_folder);
    if ($action == 'show_messages_folder') {
        $message['email_content'] = $arrData;
        $message['email_filter1'] = $filter_view;
        $message['move_folders'] = $move_folder;
        $message['imap_alerts'] = $imapAlertErros;
        $message['paging']['total'] = $total;
        $message['paging']['currentPage'] = $currentPage;
        $message['paging']['numPages'] = $numPage;
        $jsonObject->set_message($message);
        return $jsonObject->createJSON();
    }
    $smarty->assign("IMAP_ALERTS", $imapAlertErros);
    $smarty->assign("ICON_TYPE", "web/apps/{$module_name}/images/mail2.png");
    $smarty->assign("FOLDER_LIST_TITLE", _tr("Folders"));
    $mark_opt['seen'] = _tr("Seen");
    $mark_opt['unseen'] = _tr("Unseen");
    $mark_opt['flagged'] = _tr("Important");
    $mark_opt['unflagged'] = _tr("No Important");
    $smarty->assign("ELX_MAIL_MARK_OPT", $mark_opt);
    $smarty->assign("MOVE_TO", _tr("Move to"));
    $smarty->assign("MARK_AS", _tr("Mark message as"));
    $smarty->assign("NO_EMAIL_MSG", _tr("Not messages"));
    $smarty->assign("VIEW", _tr("View"));
    $smarty->assign("SELECTED_VIEW_FILTER", $filter_view);
    $smarty->assign("SEND_MAIL_LABEL", _tr("Send"));
    $smarty->assign("ATTACH_LABEL", _tr("Attach"));
    $smarty->assign("ACTION_MSG", _tr('Actions'));
    $arrActionsMsg['reply'] = _tr('Reply');
    $arrActionsMsg['reply_all'] = _tr('Reply All');
    $arrActionsMsg['forward'] = _tr('Forward');
    $arrActionsMsg['delete'] = _tr('Delete');
    $arrActionsMsg['flag_important'] = _tr('Flag as Important');
    $arrActionsMsg['flag_unimportant'] = _tr('Flag as Unimportant');
    $smarty->assign("ELX_EMAIL_MSG_ACT", $arrActionsMsg);
    $html = $smarty->fetch("file:{$local_templates_dir}/form.tpl");
    $contenidoModulo = "<div>" . $html . "</div>";
    return $contenidoModulo;
}
Ejemplo n.º 2
0
function reportContact($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf)
{
    global $arrCredentials;
    $coreContact = new coreContact($pDB);
    $jsonObject = new PaloSantoJSON();
    //obtener los parametros del filtro
    $filters['ftype_contacto'] = getParameter('ftype_contacto');
    $filters['filter'] = getParameter('filter');
    $filters['filter_value'] = getParameter('filter_value');
    $validatedfilters = $coreContact->validatedFilters($filters);
    $total = $coreContact->getTotalContactsByFilter($validatedfilters);
    if ($total === false) {
        $total = 0;
        $smarty->assign("MSG_ERROR_FIELD", _tr("Error en database"));
        $jsonObject->set_error($coreContact->sqlContact->getErrorMsg());
        return $jsonObject->createJSON();
    }
    $limit = 7;
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    $oGrid->setStart($total == 0 ? 0 : $offset + 1);
    $oGrid->setEnd($end);
    $currentPage = $oGrid->calculateCurrentPage();
    $numPage = $oGrid->calculateNumPage();
    $url['menu'] = $module_name;
    $url['ftype_contacto'] = $filters['ftype_contacto'];
    $url['filter'] = $filters['filter'];
    $url['filter_value'] = $filters['filter_value'];
    $oGrid->setTitle(_tr('Contacts List'));
    $oGrid->setURL($url);
    $oGrid->enableExport();
    // enable export.
    $oGrid->setNameFile_Export(_tr("ContactsExport"));
    $arrColumn = array();
    if ($oGrid->isExportAction()) {
        // arreglo de columnas para mostrar en los archivos de exportacion
        $arrColumn[] = 'Name';
        //if($validatedfilters['table']=="internal"){
        if ($validatedfilters['table'] == "internal") {
            $arrColumn[] = 'Ext';
        } else {
            $arrColumn[] = 'Phone';
        }
        $arrColumn[] = 'Email';
        $arrColumn[] = 'Type Contact';
    } else {
        //arreglo de columnas para mostrar en la grilla
        $arrColumn[] = "<span class='glyphicon glyphicon-check'></span>";
        $arrColumn[] = _tr('Picture');
        $arrColumn[] = _tr('Name');
        //if($validatedfilters['table']=="internal"){
        $arrColumn[] = _tr('Ext / Phone');
        $arrColumn[] = _tr('Email');
        $arrColumn[] = _tr('Call');
        $arrColumn[] = _tr('Transfer');
        $arrColumn[] = _tr('Type Contact');
    }
    $oGrid->setColumns($arrColumn);
    $validatedfilters = $coreContact->validatedFilters($filters);
    //enviamos como parametros limit, offset y los filtros validados
    $contacts = $coreContact->getContacts($limit, $offset, $validatedfilters);
    $arrDatosGrid = array();
    if ($contacts === false) {
        $smarty->assign("MSG_ERROR_FIELD", $coreContact->getErrorMsg());
        $jsonObject->set_error($coreContact->getErrorMsg());
        return $jsonObject->createJSON();
    } else {
        if ($oGrid->isExportAction()) {
            // data para exportar en los archivos
            foreach ($contacts as $value) {
                $tmp = array();
                $tmp[] = $value['name'];
                if (empty($value['work_phone'])) {
                    $tmp[] = "N/A";
                } else {
                    $tmp[] = $value['work_phone'];
                }
                if (!empty($value['username'])) {
                    $tmp[] = $value['username'];
                } else {
                    $tmp[] = "N/A";
                }
                if ($validatedfilters['table'] != "internal") {
                    if ($value['status'] == "isPrivate") {
                        $tmp[] = _tr('Private');
                    } else {
                        $tmp[] = _tr('Public');
                    }
                } else {
                    $tmp[] = _tr('Public');
                }
                $arrDatosGrid[] = $tmp;
            }
        } else {
            //data para mostrar en las grillas
            foreach ($contacts as $value) {
                $tmp = array();
                if ($validatedfilters['table'] == "internal") {
                    $tmp[] = "<input type='checkbox' name='checkContacts' id='{$value['id']}' disabled >";
                } else {
                    if ($arrCredentials['idUser'] == $value['iduser']) {
                        $tmp[] = "<input type='checkbox' name='checkContacts' id='{$value['id']}'>";
                    } else {
                        $tmp[] = "<input type='checkbox' name='checkContacts' id='{$value['id']}' disabled >";
                    }
                }
                if ($validatedfilters['table'] == "internal") {
                    $tmp[] = "<img id='img-users' width='16' height='16' alt='image' src='index.php?menu=_elastixutils&action=getImage&ID={$value['id']}&rawmode=yes'/>";
                } else {
                    $tmp[] = "<img id='img-users' width='16' height='16' alt='image' src='index.php?menu={$module_name}&action=getImageExtContact&image={$value['picture']}&rawmode=yes'/>";
                }
                if ($validatedfilters['table'] == "internal") {
                    $tmp[] = htmlentities($value['name'], ENT_QUOTES, "UTF-8");
                } else {
                    if ($arrCredentials['idUser'] == $value['iduser']) {
                        $tmp[] = "<a href='#' onclick='editContact({$value['id']})'>" . htmlentities($value['name'], ENT_QUOTES, "UTF-8") . "</a>";
                    } else {
                        $tmp[] = htmlentities($value['name'], ENT_QUOTES, "UTF-8");
                    }
                }
                if ($validatedfilters['table'] == "internal") {
                    $tmp[] = htmlentities($value['extension'], ENT_QUOTES, "UTF-8");
                } else {
                    if (empty($value['work_phone'])) {
                        $tmp[] = "N/A";
                    } else {
                        $tmp[] = htmlentities($value['work_phone'], ENT_QUOTES, "UTF-8");
                    }
                }
                if (!empty($value['username'])) {
                    $tmp[] = htmlentities($value['username'], ENT_QUOTES, "UTF-8");
                } else {
                    $tmp[] = "N/A";
                }
                //$tmp[]="<span class='glyphicon glyphicon-earphone'></span>";
                $tmp[] = "<a href='#' onclick='callContact({$value['id']})'><span class='glyphicon glyphicon-earphone'></span></a>";
                if ($validatedfilters['table'] == "internal") {
                    //$tmp[]=_tr('Transfer');
                    $tmp[] = "<a href='#' onclick='transferCall({$value['id']})'>" . _tr('Transfer') . "</a>";
                } else {
                    $tmp[] = "N/A";
                }
                if ($validatedfilters['table'] != "internal") {
                    if ($value['status'] == "isPrivate") {
                        $tmp[] = _tr('Private');
                    } else {
                        $tmp[] = _tr('Public');
                    }
                } else {
                    $tmp[] = _tr('Public');
                }
                $arrDatosGrid[] = $tmp;
            }
        }
    }
    $action = getParameter('action');
    if ($action == 'search') {
        $arrData['url'] = $oGrid->getURL();
        $arrData['url'] = str_replace('&amp;', '&', $arrData['url']);
        $arrData['numPage'] = $numPage;
        $arrData['currentPage'] = $currentPage;
        $arrData['content'] = $arrDatosGrid;
        $jsonObject->set_message($arrData);
        return $jsonObject->createJSON();
    }
    $oGrid->addButtonAction("new_contact", "<span class='glyphicon glyphicon-user'></span> New Contact", "", "newContact()");
    $oGrid->addButtonAction("remove_contact", "<span class='glyphicon glyphicon-remove'></span> Delete Contacts", "", "deleteContacts('" . _tr("Are you sure you wish to delete the contact.") . "')");
    $oGrid->addButtonAction("elx_upload_file", "<span class='glyphicon glyphicon-upload'></span> Upload from CSV", "", "");
    $oGrid->addButtonAction("elx_export_data", "<span class='glyphicon glyphicon-download'></span>", "", "");
    $oGrid->addButtonAction("elx_show_filter", "<span class='glyphicon glyphicon-filter'></span> Show filter", "", "");
    $arrayData = array();
    $arrFormFilter = createFilterForm();
    $oFilterForm = new paloForm($smarty, $arrFormFilter);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", _tr('extension'), $arrayData);
    $oGrid->showFilter(trim($htmlFilter));
    $contenidoModulo = actionsReport($arrDatosGrid, $oGrid);
    return $contenidoModulo;
}