예제 #1
0
function outputCSV($filename, $data, $column_titles = true)
{
    $fileHandle = fopen('php://output', 'w');
    ob_start();
    generateCSV($fileHandle, $data, $column_titles);
    $csv_data = ob_get_clean();
    ob_end_clean();
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    echo $csv_data;
    die;
}
예제 #2
0
/**
 * generateAllCSV - Génère un fichier CSV à partir d'une liste de services (plusieurs services en même temps)
 *
 * @category : eval_ccpc_functions
 * @param array $list Array contenant la liste des identifiants des services
 * @param string $dateMin Borne inférieure de l'intervalle temporel sur lequel on extrait les données
 * @param string $dateMax Borne supérieure de l'intervalle temporel sur lequel on extrait les données
 * @param int|boolean $promotion Promotion pour laquelle on extrait les données, FALSE si on extrait indifféremment de la promotion
 * @param boolean $moderate TRUE si on affiche les messages modérés, FALSE sinon
 * @return array Array contenant les informations du fichier généré
 *
 * @Author Ali Bellamine
 *
 * Contenu de l'array retourné :<br>
 * 	['csvPath'] => (string) Chemin local vers le fichier généré<br>
 * 	['csvURI'] => (string) URI pointant vers le fichier généré
 *
 */
function generateAllCSV($list, $dateMin, $dateMax, $promotion = FALSE, $moderate = FALSE)
{
    // Array contenant les résultats
    $output = array();
    // On vérifie l'existence des données
    if (isset($list) && count($list) > 0 && isset($dateMin) && isset($dateMax) && $dateMin <= $dateMax) {
        // Calcul du md5
        $hash = md5(json_encode($list));
        $csvPath = PLUGIN_PATH . 'cache/' . $hash . '.csv';
        $csvPathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.csv';
        if ($csv = fopen($csvPath, 'w')) {
            $firstLoop = TRUE;
            foreach ($list as $service) {
                // Si le service existe
                if (count(checkService($service, array())) == 0) {
                    // On affiche la liste des catégorie uniquement au premier tour de boucle
                    if ($firstLoop) {
                        $serviceCSV = generateCSV(getEvaluationCCPCFullData($service, $promotion, $dateMin, $dateMax, $moderate), TRUE);
                    } else {
                        $serviceCSV = generateCSV(getEvaluationCCPCFullData($service, $promotion, $dateMin, $dateMax, $moderate), FALSE);
                    }
                    // On lit le fichier CSV généré
                    if ($tempCSV = fopen($serviceCSV['csvPath'], 'r')) {
                        $tempCSVContent = fread($tempCSV, filesize($serviceCSV['csvPath']));
                    }
                    // On copie son contenue à la fin du fichier CSV final
                    fwrite($csv, $tempCSVContent);
                    unset($tempCSVContent);
                    $firstLoop = FALSE;
                }
            }
            fclose($csv);
            $output['csvPath'] = $csvPath;
            $output['csvURI'] = $csvPathURI;
            return $output;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}
예제 #3
0
파일: admin.php 프로젝트: Galinijay/PAS
 $allowedJoin['none'] = FALSE;
 // Pour le PDF
 if (isset($_POST['pdfJoin']) && isset($allowedJoin[$_POST['pdfJoin']]) && ($_POST['pdfJoin'] == 'none' || $allowedJoin[$_POST['pdfJoin']]['type'] == 'PDF')) {
     if ($_POST['pdfJoin'] != 'none') {
         foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
             $_SESSION['sendMail']['settings']['pdf'] = generatePDF(getEvaluationCCPCFullData($serviceDetected['service']['id'], $serviceDetected['promotion'], $_GET['dateDebut'], $_GET['dateFin'], $allowedJoin[$_POST['pdfJoin']]['moderation']), $allowedJoin[$_POST['pdfJoin']]['comment'], TRUE)['pdfPath'];
         }
     }
 } else {
     $erreur['LANG_ERROR_CCPC_UNKNOWN'] = TRUE;
 }
 // Pour le CSV
 if (isset($_POST['csvJoin']) && isset($allowedJoin[$_POST['csvJoin']]) && ($_POST['csvJoin'] == 'none' || $allowedJoin[$_POST['csvJoin']]['type'] == 'CSV')) {
     if ($_POST['csvJoin'] != 'none') {
         foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
             $_SESSION['sendMail']['settings']['csv'] = generateCSV(getEvaluationCCPCFullData($serviceDetected['service']['id'], $serviceDetected['promotion'], $_GET['dateDebut'], $_GET['dateFin'], $allowedJoin[$_POST['csvJoin']]['moderation']), TRUE)['csvPath'];
         }
     }
 } else {
     $erreur['LANG_ERROR_CCPC_UNKNOWN'] = TRUE;
 }
 /**
 				Liste des messages à envoyer
 			**/
 if (count($erreur) == 0) {
     foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
         $serviceData = getServiceInfo($serviceDetected['service']['id']);
         $chefData = getUserData($serviceData['chef']['id']);
         $_SESSION['sendMail']['current'][$chefData['id']] = $chefData;
         // On ajoute les envoie à faire dans current
     }
예제 #4
0
                        }
                        break;
                    }
                }
            }
        }
        ?>
					</div>
					
					<?php 
        /**
        						Bouton de téléchargement
        					**/
        if (isset($_GET['download'])) {
            if ($_GET['download'] == 'csv') {
                downloadFILE(generateCSV($evaluationData, TRUE)['csvPath'], $evaluationData['service']['FullName'] . '.csv');
            } else {
                if ($_GET['download'] == 'pdf') {
                    downloadFILE(generatePDF($evaluationData, TRUE, TRUE)['pdfPath'], $evaluationData['service']['FullName'] . '.pdf');
                }
            }
        }
        /**
        						Masquage du service
        					**/
        if (isset($_GET['hideService']) && $_SESSION['rang'] >= 3) {
            unset($_GET['hideService']);
            if ($evaluationData['service']['hide'] == 1) {
                $setHideValue = 0;
            } else {
                $setHideValue = 1;
예제 #5
0
        // Save merged file
        $filename = strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
        if ($option == 'late') {
            $filename .= '_' . strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
        }
        if ($pagecount) {
            $now = dol_now();
            $file = $diroutputpdf . '/' . $filename . '_' . dol_print_date($now, 'dayhourlog') . '.pdf';
            $pdf->Output($file, 'F');
            if (!empty($conf->global->MAIN_UMASK)) {
                @chmod($file, octdec($conf->global->MAIN_UMASK));
            }
        }
    }
} elseif (is_array($_POST['toGenerate']) && isset($_REQUEST['generateCSV'])) {
    generateCSV();
}
// Remove file
if ($action == 'remove_file') {
    require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
    $langs->load("other");
    $upload_dir = $diroutputpdf;
    $file = $upload_dir . '/' . GETPOST('file');
    $ret = dol_delete_file($file, 0, 0, 0, '');
    if ($ret) {
        setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
    } else {
        setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
    }
    $action = '';
}