Exemplo n.º 1
0
function reportReportedeCalltypes($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $argv)
{
    $pReportedeCalltypes = new paloSantoReportedeCalltypes($pDB);
    $filter_field = $argv[3];
    //getParameter("filter_field");
    $filter_value = $argv[4];
    //getParameter("filter_value");
    $id_campania = $argv[1];
    //getParameter("id_campania");
    $tiempo_unix = $argv[2];
    $nombre_archivo = '/modules/hispana_reporte_calltype/reportes/Reporte_de_Calltypes_' . $id_campania . "_{$tiempo_unix}.xls";
    $pReportedeCalltypes->registraReporteOffline($id_campania, $tiempo_unix, $nombre_archivo, "{$filter_field}={$filter_value}");
    //begin grid parameters
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setTitle(_tr("Reporte de Calltypes"));
    $oGrid->pagingShow(true);
    // show paging section.
    $oGrid->enableExport();
    // enable export.
    $oGrid->setNameFile_Export(_tr("Reporte de Calltypes"));
    $url = array("menu" => $module_name, "filter_field" => $filter_field, "filter_value" => $filter_value, "id_campania" => $id_campania);
    $oGrid->setURL($url);
    // Columnas base
    $arrColumns = array(_tr("Fecha"), _tr("Campaña"), _tr("Base"), _tr("Cliente"), _tr("CI"), _tr("Teléfono"), _tr("Agente"), _tr("Contactabilidad"), _tr("Mejor calltype"), _tr("Formulario"));
    // Otras columnas
    if ($id_campania != "") {
        // Columnas adicionales
        $arrColumnasAdicionales = $pReportedeCalltypes->getColumnasAdicionales($id_campania);
        $arrColumns = array_merge($arrColumns, $arrColumnasAdicionales);
        // Columnas de gestión
        $arrTmp = $pReportedeCalltypes->getFormFields($id_campania);
        $i = 0;
        foreach ($arrTmp as $formField) {
            $arrOrden[] = $formField['id'];
            $arrColumnsAdicionales[$i] = $formField['etiqueta'];
            $i++;
        }
        $arrColumns = array_merge($arrColumns, $arrColumnsAdicionales);
    }
    $oGrid->setColumns($arrColumns);
    $total = $pReportedeCalltypes->getNumReportedeCalltypes($filter_field, $filter_value, $id_campania);
    $arrData = null;
    //if($oGrid->isExportAction()){
    $limit = $total;
    // max number of rows.
    $offset = 0;
    // since the start.
    /*}else{
          $limit  = 20; // default 20
          $oGrid->setLimit($limit);
          $oGrid->setTotal($total);
          $offset = $oGrid->calculateOffset();
      }*/
    $arrResult = $pReportedeCalltypes->getReportedeCalltypes($limit, $offset, $filter_field, $filter_value, $id_campania);
    if (is_array($arrResult) && $total > 0) {
        foreach ($arrResult as $key => $value) {
            $arrTmp[0] = $value['fecha'];
            $arrTmp[1] = $value['base'];
            $arrTmp[2] = $value['campania'];
            $arrTmp[3] = $value['cliente'];
            $arrTmp[4] = $value['ci'];
            $arrTmp[5] = $value['telefono'];
            $arrTmp[6] = $value['agente'];
            $arrTmp[7] = $value['contactabilidad'];
            $arrTmp[8] = $value['mejor_calltype'];
            // $arrTmp[8] = $value['formulario'];
            // Así lo requiere RUBENING
            /*$arrTmp[9] = "<a href=modules/$module_name/gestion_info.php?id_gestion=$value[id_gestion_mejor_calltype] target=\"_blank\" onClick=\"window.open(this.href, this.target, 'width=600,height=400'); return false;\">Ver gestión</a>".
               "<br>".
              "<a href=modules/$module_name/gestion_edit.php?id_gestion=$value[id_gestion_mejor_calltype]&user="******"elastix_user"]." target=\"_blank\" onClick=\"window.open(this.href, this.target, 'width=600,height=400'); return false;\">Editar</a>"*/
            //$arrTmp[9] = "<a href=modules/$module_name/gestion_info.php?id_gestion=$value[id_gestion_mejor_calltype] target=\"_blank\" onClick=\"window.open(this.href, this.target, 'width=600,height=400'); return false;\">Ver gestión</a>";
            // Datos adicionales
            $arrDatosAdicionales = $pReportedeCalltypes->getDatosAdicionales($value['ci']);
            $i = 10;
            foreach ($arrColumnasAdicionales as $k => $columnaAdicional) {
                $arrTmp[$i] = $arrDatosAdicionales[$columnaAdicional];
                $i++;
            }
            unset($arrDatosAdicionales);
            $numColumnasFijas = $i;
            // Datos de gestión
            $arrFormValues = $pReportedeCalltypes->getFormValues($value['id_gestion_mejor_calltype']);
            // array_search retorna el key dado el valor a buscar
            foreach ($arrFormValues as $formValue) {
                // echo $formValue['valor'] . " " . array_search($formValue['id_form_field'],$arrOrden) . "<br>";
                $ubicacionReal = array_search($formValue['id_form_field'], $arrOrden) + $numColumnasFijas;
                if (is_array($formValue['valor'])) {
                    $formValue['valor'] = print_r($formValue['valor'], true);
                }
                $arrTmp[$ubicacionReal] = $formValue['valor'];
            }
            $arrData[] = $arrTmp;
            unset($arrTmp);
        }
    }
    $oGrid->setData($arrData);
    /* Para colocar en $arrTmp 
     */
    //begin section filter
    //$oFilterForm = new paloForm($smarty, createFieldFilter());
    //$smarty->assign("SHOW", _tr("Show"));
    //$smarty->assign("filter_campaign", filter_campaign($pDB, $id_campania));
    //$htmlFilter  = $oFilterForm->fetchForm("$local_templates_dir/filter.tpl","",$_POST);
    //end section filter
    //$oGrid->showFilter(trim($htmlFilter));
    $export = $oGrid->exportType();
    $content = $oGrid->fetchGrid();
    //end grid parameters
    //REPORTE OFFLINE
    //exportspreadsheet=yes&rawmode=yes
    if ($export == 'csv' || $export == 'pdf' || ($export = 'xls')) {
        $nombre_archivo = '/var/www/html/modules/hispana_reporte_calltype/reportes/Reporte_de_Calltypes_' . $id_campania . "_{$tiempo_unix}." . $export;
        $fd = fopen($nombre_archivo, "w");
        fwrite($fd, $content);
        fclose($fd);
    }
    $nombre_archivo = '/modules/hispana_reporte_calltype/reportes/Reporte_de_Calltypes_' . $id_campania . "_{$tiempo_unix}." . $export;
    $pReportedeCalltypes->actualizaReporteOffline($id_campania, $tiempo_unix);
    return $content;
}