Exemplo n.º 1
0
 /**
  * Functional point that list the sent and received faxes by the system
  *
  * @param   date      $date        (optional) date for which is desired the report, or all if omitted
  * @param   string    $direction   (optional) 'in' for faxes received 'out' for sent faxes, or all if omitted
  * @param   integer   $offset      (optional) start of records or 0 if omitted
  * @param   integer   $limit       (optional) limit records or all if omitted
  * @return  array     Array of records with the following information
  *                          totalfaxcount (positiveInteger) Total number of records
  *                          Faxes: (array) Array of records fax with the following info:
  *                              id (positiveInteger) fax registration ID
  *                              modemdev (string) TTY device on the ingress / egress fax
  *                              errormsg (string, optional) Error message (if any) for failed fax
  *                              company_name (string) Label descriptive fax company
  *                              company_fax (string) descriptive label company number
  *                              date (datetime) date and time sent / received fax
  *                              type (string) 'in ' Fax received 'out' for fax sent
  *                              destiny_name (string) Name of device used fax
  *                              destiny_fax (string) fax telephone number used
  *                   or false if an error exists
  */
 function listFaxDocs($date, $direction, $offset, $limit)
 {
     if (!$this->_checkUserAuthorized('faxviewer')) {
         return false;
     }
     if (!$this->_checkOffsetLimit($offset, $limit)) {
         return false;
     }
     // Validación de la fecha opcional del reporte
     $sFecha = isset($date) ? $this->_checkDateFormat($date) : NULL;
     // Validación de dirección para faxes
     if (isset($direction) && !in_array($direction, array('in', 'out'))) {
         $this->errMsg["fc"] = 'PARAMERROR';
         $this->errMsg["fm"] = 'Invalid direction';
         $this->errMsg["fd"] = 'Fax direction must be one of: in out';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     //obtenemos las credenciales del usuario
     $arrCredentials = getUserCredentials();
     // Cuenta de registros que cumplen con las condiciones
     $oFax = new paloFaxVisor();
     $iNumFaxes = $oFax->obtener_cantidad_faxes($arrCredentials["id_organization"], '', '', is_null($sFecha) ? '' : $sFecha, isset($direction) ? $direction : '');
     // El método obtener_cantidad_faxes devuelve un arreglo vacío en caso de error
     if (is_array($iNumFaxes)) {
         $this->errMsg["fc"] = 'DBERROR';
         $this->errMsg["fm"] = 'Database operation failed';
         $this->errMsg["fd"] = 'Unable to count faxes - ' . $oFax->errMsg;
         $this->errMsg["cn"] = get_class($oFax);
         return false;
     }
     $infoFax = array('totalfaxcount' => $iNumFaxes, 'faxes' => array());
     if ($infoFax['totalfaxcount'] > 0) {
         if (isset($offset) && !isset($limit)) {
             $limit = $infoFax['totalfaxcount'];
         }
         $listaTmpFax = $oFax->obtener_faxes($arrCredentials["id_organization"], '', '', is_null($sFecha) ? '' : $sFecha, $offset, $limit, isset($direction) ? $direction : '');
         /* obtener_faxes devuelve arreglo vacío en caso de error, lo que es
          * difícil de distinguir de una petición exitosa fuera de rango. */
         if (count($listaTmpFax) == 0 && $oFax->errMsg != '') {
             $this->errMsg["fc"] = 'DBERROR';
             $this->errMsg["fm"] = 'Database operation failed';
             $this->errMsg["fd"] = 'Unable to read faxes - ' . $oFax->errMsg;
             $this->errMsg["cn"] = get_class($oFax);
             return false;
         }
         function _transformarFaxDoc($tupla)
         {
             return array('id' => $tupla['id'], 'modemdev' => $tupla['modemdev'], 'errormsg' => trim($tupla['errormsg']) == '' ? NULL : trim($tupla['errormsg']), 'company_name' => $tupla['company_name'], 'company_fax' => $tupla['company_fax'], 'date' => date(SOAP_DATETIME_FORMAT, strtotime($tupla['date'])), 'type' => $tupla['type'], 'destiny_name' => $tupla['destiny_name'], 'destiny_fax' => $tupla['destiny_fax']);
         }
         $infoFax['faxes'] = array_map('_transformarFaxDoc', $listaTmpFax);
     }
     return $infoFax;
 }
Exemplo n.º 2
0
function listarFaxes(&$smarty, $module_name, $local_templates_dir)
{
    $smarty->assign(array('SEARCH' => _tr('Search')));
    $oFax = new paloFaxVisor();
    // Generación del filtro
    $oFilterForm = new paloForm($smarty, getFormElements());
    // Parámetros base y validación de parámetros
    $url = array('menu' => $module_name);
    $paramFiltroBase = $paramFiltro = array('name_company' => '', 'fax_company' => '', 'date_fax' => NULL, 'filter' => 'All');
    foreach (array_keys($paramFiltro) as $k) {
        if (!is_null(getParameter($k))) {
            $paramFiltro[$k] = getParameter($k);
        }
    }
    $oGrid = new paloSantoGrid($smarty);
    $arrType = array("All" => _tr('All'), "In" => _tr('in'), "Out" => _tr('out'));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Company Name") . " = " . $paramFiltro['name_company'], $paramFiltro, array("name_company" => ""));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Company Fax") . " = " . $paramFiltro['fax_company'], $paramFiltro, array("fax_company" => ""));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Fax Date") . " = " . $paramFiltro['date_fax'], $paramFiltro, array("date_fax" => NULL));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Type Fax") . " = " . $arrType[$paramFiltro['filter']], $paramFiltro, array("filter" => "All"), true);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $paramFiltro);
    if (!$oFilterForm->validateForm($paramFiltro)) {
        $smarty->assign(array('mb_title' => _tr('Validation Error'), 'mb_message' => '<b>' . _tr('The following fields contain errors') . ':</b><br/>' . implode(', ', array_keys($oFilterForm->arrErroresValidacion))));
        $paramFiltro = $paramFiltroBase;
        unset($_POST['faxes_delete']);
        // Se aborta el intento de borrar faxes, si había uno.
    }
    $url = array_merge($url, $paramFiltro);
    // Ejecutar el borrado, si se ha validado.
    if (isset($_POST['faxes_delete']) && isset($_POST['faxes']) && is_array($_POST['faxes']) && count($_POST['faxes']) > 0) {
        $msgError = NULL;
        foreach ($_POST['faxes'] as $idFax) {
            if (!$oFax->deleteInfoFax($idFax)) {
                if ($oFax->errMsg = '') {
                    $msgError = _tr('Unable to eliminate pdf file from the path.');
                } else {
                    $msgError = _tr('Unable to eliminate pdf file from the database.') . ' - ' . $oFax->errMsg;
                }
            }
        }
        if (!is_null($msgError)) {
            $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oFax->errMsg));
        }
    }
    $oGrid->setTitle(_tr("Fax Viewer"));
    $oGrid->setIcon("modules/{$module_name}/images/kfaxview.png");
    $oGrid->pagingShow(true);
    // show paging section.
    $oGrid->setURL($url);
    $arrData = NULL;
    $total = $oFax->obtener_cantidad_faxes($paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $paramFiltro['filter']);
    $limit = 20;
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $arrResult = $oFax->obtener_faxes($paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $offset, $limit, $paramFiltro['filter']);
    $oGrid->setColumns(array("", _tr('Type'), _tr('File'), _tr('Company Name'), _tr('Company Fax'), _tr('Fax Destiny'), _tr('Fax Date'), _tr('Status'), _tr('Options')));
    if (is_array($arrResult) && $total > 0) {
        foreach ($arrResult as $fax) {
            foreach (array('pdf_file', 'company_name', 'company_fax', 'destiny_name', 'destiny_fax', 'errormsg') as $k) {
                $fax[$k] = htmlentities($fax[$k], ENT_COMPAT, 'UTF-8');
            }
            if (empty($fax['status']) && !empty($fax['errormsg'])) {
                $fax['status'] = 'failed';
            }
            $arrData[] = array('<input type="checkbox" name="faxes[]" value="' . $fax['id'] . '" />', _tr($fax['type']), strtolower($fax['type']) == 'in' || strpos($fax['pdf_file'], '.pdf') !== FALSE ? "<a href='?menu={$module_name}&action=download&id=" . $fax['id'] . "&rawmode=yes'>" . $fax['pdf_file'] . "</a>" : $fax['pdf_file'], $fax['company_name'], $fax['company_fax'], $fax['destiny_name'] . " - " . $fax['destiny_fax'], $fax['date'], _tr($fax['status']) . (empty($fax['errormsg']) ? '' : ': ' . $fax['errormsg']), "<a href='?menu={$module_name}&action=edit&id=" . $fax['id'] . "'>" . _tr('Edit') . "</a>");
        }
    }
    if (!is_array($arrResult)) {
        $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oFax->errMsg));
    }
    $oGrid->setData($arrData);
    $oGrid->deleteList(_tr('Are you sure you wish to delete fax (es)?'), "faxes_delete", _tr("Delete"));
    $oGrid->showFilter($htmlFilter);
    return $oGrid->fetchGrid();
}
Exemplo n.º 3
0
function listarFaxes(&$smarty, $module_name, $local_templates_dir, $pDB, $credentials)
{
    global $arrPermission;
    $pORGZ = new paloSantoOrganization($pDB);
    $smarty->assign(array('SEARCH' => _tr('Search')));
    $smarty->assign('USERLEVEL', $credentials['userlevel']);
    $arrOrgz = array(0 => "all");
    $organization = getParameter('organization');
    if ($credentials['userlevel'] == 'superadmin') {
        if (empty($organization)) {
            $organization = 0;
        }
        if ($pORGZ->getNumOrganization(array()) > 0) {
            foreach ($pORGZ->getOrganization(array()) as $value) {
                $arrOrgz[$value["id"]] = $value["name"];
            }
        }
    } else {
        $tmpOrg = $pORGZ->getOrganizationById($credentials['id_organization']);
        $arrOrgz[$tmpOrg["id"]] = $tmpOrg['name'];
        $organization = $credentials['id_organization'];
    }
    $oFax = new paloFaxVisor($pDB);
    // Generación del filtro
    $oFilterForm = new paloForm($smarty, getFormElements($arrOrgz));
    // Parámetros base y validación de parámetros
    $url = array('menu' => $module_name);
    $paramFiltroBase = $paramFiltro = array('name_company' => '', 'fax_company' => '', 'date_fax' => NULL, 'filter' => 'All');
    foreach (array_keys($paramFiltro) as $k) {
        if (!is_null(getParameter($k))) {
            $paramFiltro[$k] = getParameter($k);
        }
    }
    $oGrid = new paloSantoGrid($smarty);
    $arrType = array("All" => _tr('All'), "In" => _tr('in'), "Out" => _tr('out'));
    if ($credentials['userlevel'] == 'superadmin') {
        $_POST["organization"] = $organization;
        $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$organization], $_POST, array("organization" => 0), true);
        //organization
    }
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Company Name") . " = " . $paramFiltro['name_company'], $paramFiltro, array("name_company" => ""));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Company Fax") . " = " . $paramFiltro['fax_company'], $paramFiltro, array("fax_company" => ""));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Fax Date") . " = " . $paramFiltro['date_fax'], $paramFiltro, array("date_fax" => NULL));
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Type Fax") . " = " . $arrType[$paramFiltro['filter']], $paramFiltro, array("filter" => "All"), true);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $paramFiltro);
    if (!$oFilterForm->validateForm($paramFiltro)) {
        $smarty->assign(array('mb_title' => _tr('Validation Error'), 'mb_message' => '<b>' . _tr('The following fields contain errors') . ':</b><br/>' . implode(', ', array_keys($oFilterForm->arrErroresValidacion))));
        $paramFiltro = $paramFiltroBase;
    }
    $url = array_merge($url, $paramFiltro);
    $oGrid->setTitle(_tr("Fax Viewer"));
    $oGrid->setIcon("web/apps/{$module_name}/images/kfaxview.png");
    $oGrid->pagingShow(true);
    // show paging section.
    $oGrid->setURL($url);
    $arrData = NULL;
    if ($organization == 0) {
        $total = $oFax->obtener_cantidad_faxes(null, $paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $paramFiltro['filter']);
    } else {
        $total = $oFax->obtener_cantidad_faxes($organization, $paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $paramFiltro['filter']);
    }
    if ($total === false) {
        $total = 0;
        $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oFax->errMsg));
    }
    $delete = in_array('delete_fax', $arrPermission);
    $edit = in_array('edit_fax', $arrPermission);
    $limit = 20;
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    if ($delete) {
        $columns[] = "<input type='checkbox' class='checkall'/>";
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $columns[] = _tr('Organization');
    }
    $columns[] = _tr('Type');
    $columns[] = _tr('File');
    $columns[] = _tr('Fax Cid Name');
    $columns[] = _tr('Fax Cid Number');
    $columns[] = _tr('Fax Destiny');
    $columns[] = _tr('Fax Date');
    $columns[] = _tr('Status');
    if ($edit) {
        $columns[] = _tr('Options');
    }
    $oGrid->setColumns($columns);
    if ($total > 0) {
        if ($organization == 0) {
            $arrResult = $oFax->obtener_faxes(null, $paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $offset, $limit, $paramFiltro['filter']);
        } else {
            $arrResult = $oFax->obtener_faxes($organization, $paramFiltro['name_company'], $paramFiltro['fax_company'], $paramFiltro['date_fax'], $offset, $limit, $paramFiltro['filter']);
        }
        if (!is_array($arrResult)) {
            $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oFax->errMsg));
        } else {
            foreach ($arrResult as $fax) {
                foreach (array('pdf_file', 'company_name', 'company_fax', 'destiny_name', 'destiny_fax') as $k) {
                    $fax[$k] = htmlentities($fax[$k], ENT_COMPAT, 'UTF-8');
                }
                $doc = explode(".", $fax['pdf_file']);
                $iddoc = $doc[0];
                $arrTmp = array();
                if ($delete) {
                    $arrTmp[] = '<input type="checkbox" name="faxes[]" value="' . $fax['id'] . '" />';
                }
                if ($credentials['userlevel'] == 'superadmin') {
                    $arrTmp[] = 'ttt';
                }
                //$arrOrg[$fax['id_organization']];
                $arrTmp[] = _tr($fax['type']);
                $arrTmp[] = strtolower($fax['type']) == 'in' || strpos($fax['pdf_file'], '.pdf') !== FALSE ? "<a href='?menu={$module_name}&action=download&id=" . $fax['id'] . "&rawmode=yes'>" . $fax['pdf_file'] . "</a>" : $fax['pdf_file'];
                $arrTmp[] = $fax['company_name'];
                $arrTmp[] = $fax['company_fax'];
                $arrTmp[] = $fax['destiny_name'] . " - " . $fax['destiny_fax'];
                $arrTmp[] = $fax['date'];
                $arrTmp[] = _tr($fax['status']) . (empty($fax['errormsg']) ? '' : ': ' . $fax['errormsg']);
                if ($edit) {
                    $arrTmp[] = "<a href='?menu={$module_name}&action=edit&id=" . $fax['id'] . "'>" . _tr('Edit') . "</a>";
                }
                $arrData[] = $arrTmp;
            }
        }
    }
    $oGrid->setData($arrData);
    if ($delete) {
        $oGrid->deleteList(_tr('Are you sure you wish to delete fax (es)?'), "faxes_delete", _tr("Delete"));
    }
    $oGrid->showFilter($htmlFilter);
    return $oGrid->fetchGrid();
}