Example #1
0
function exporter_test()
{
    global $page;
    global $resultat;
    global $message;
    $page['gabarit'] = "administration";
    if (isset($_SESSION['role_user']) && droit_acces($resultat['exporter_test'], $_SESSION['role_user'])) {
        $page['vue'] = "resultats/exporter_test.vue.php";
        $page['colonne'] = "tests/sidebar_test.vue.php";
        $page['tests'] = liste_test();
        $page['motifs'] = liste_motif();
        $page['lieux'] = liste_lieux();
        if (isset($_GET['id'])) {
            $id = $_GET['id'];
        }
        if (isset($_POST['id_test'])) {
            $id = $_POST['id_test'];
        }
        $page['id_test'] = $id;
        $page['test'] = get_test($id);
        $page['test'] = $page['test'][0];
        if (isset($_POST['exporter'])) {
            if (isset($_POST['type_export'])) {
                $test = get_contenu_test_actif($id);
                $i = 0;
                foreach ($test as $key => $content) {
                    if ($content['type'] == 'item') {
                        $item = get_item($content['id_element']);
                        $test[$i] = $item[0];
                        $i++;
                    } else {
                        $items = get_item_by_section($content['id_element']);
                        foreach ($items as $it) {
                            $test[$i] = $it;
                            $i++;
                        }
                    }
                }
                if ($_POST['type_export'] == 'valeur') {
                    $column = array();
                    foreach ($_POST["critere"] as $c) {
                        if ($c == 'distinct(candidat.nid_candidat)') {
                            $c = 'nid_candidat';
                        }
                        $column[] = $c;
                    }
                    foreach ($test as $item) {
                        $column[] = $item['libelle_item'];
                        $column[] = $item['libelle_item'] . ' position';
                    }
                    // output headers so that the file is downloaded rather than displayed
                    // create a file pointer connected to the output stream
                    $output = fopen('php://output', 'w');
                    // output the column headings
                    fputcsv($output, $column, ';');
                    // fetch the data
                    $candidats = get_candidats_filtre_reponse($_POST['id_test'], $_POST['crea1'], $_POST['crea1'], $_POST['id_motif'], $_POST['id_organisme'], $_POST['critere']);
                    // loop over the rows, outputting them
                    foreach ($candidats as $c) {
                        foreach ($test as $item) {
                            $rep = get_reponse_item_candidat($item['id_item'], $c['nid_candidat'], $id);
                            $reponse = "";
                            $reponsep = "";
                            foreach ($rep as $r) {
                                $reponse .= $r['libelle_reponse'] . '|';
                            }
                            $c[] = $reponse;
                            foreach ($rep as $r) {
                                $reponsep .= $r['position_reponse'] . '|';
                            }
                            $c[] = $reponsep;
                        }
                        fputcsv($output, $c, ';');
                    }
                    fclose($output);
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header('Content-Description: File Transfer');
                    header("Content-type: text/csv");
                    header("Content-Disposition: attachment; filename=data.csv");
                    header("Expires: 0");
                    header("Pragma: public");
                    exit;
                }
                if ($_POST['type_export'] == 'score') {
                    // output headers so that the file is downloaded rather than displayed
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header('Content-Description: File Transfer');
                    header("Content-type: text/csv");
                    header("Content-Disposition: attachment; filename=data.csv");
                    header("Expires: 0");
                    header("Pragma: public");
                    // create a file pointer connected to the output stream
                    $output = fopen('php://output', 'w');
                    $column = array();
                    foreach ($_POST["critere"] as $c) {
                        $column[] = $c;
                    }
                    foreach ($test as $item) {
                        $dims = get_dim_item($item['id_item']);
                        foreach ($dims as $dim) {
                            $column[] = $item['libelle_item'] . "_" . $dim['libelle_court_dimension'];
                        }
                    }
                    // output the column headings
                    fputcsv($output, $column, ';');
                    // fetch the data
                    $candidats = get_candidats_filtre_reponse($_POST['id_test'], $_POST['crea1'], $_POST['crea1'], $_POST['id_motif'], $_POST['id_organisme'], $_POST['critere']);
                    foreach ($candidats as $c) {
                        foreach ($test as $item) {
                            $dims = get_dim_item($item['id_item']);
                            foreach ($dims as $dim) {
                                $rep = get_score_dim_item_candidat($item['id_item'], $c['nid_candidat'], $id, $dim['id_dimension']);
                                $reponse = "";
                                foreach ($rep as $r) {
                                    $reponse .= $r['score_brut'] . ' | ';
                                }
                                $c[] = $reponse;
                            }
                        }
                        fputcsv($output, $c, ';');
                    }
                    fclose($output);
                    exit;
                }
            } else {
                $page['message'] = $message['champs_obligatoire_2'];
            }
        }
    } else {
        $page['vue'] = "erreur_droit.vue.php";
    }
}
Example #2
0
function retirer_partage_test()
{
    global $page;
    global $item;
    global $message;
    $page['gabarit'] = "administration";
    if (isset($_SESSION['role_user']) && droit_acces($item['reponse_item'], $_SESSION['role_user'])) {
        $page['vue'] = "tests/retirer_partage_test.vue.php";
        $page['colonne'] = "tests/sidebar_test.vue.php";
        $page['etat'] = liste_etat();
        $page['etat'] = liste_etat();
        $page['categorie'] = liste_categorie();
        $page['tests'] = liste_test();
        $page['lieu'] = liste_lieux_auteur();
        $page['sphere'] = liste_sphere();
        $page['facteur'] = liste_facteur();
        $page['projet'] = liste_projet();
        if (isset($_POST['rech_test'])) {
            if (!isset($_POST['aleatoire'])) {
                $_POST['aleatoire'] = 'off';
            }
            if (!isset($_POST['retour_arriere'])) {
                $_POST['retour_arriere'] = 'off';
            }
            $test_rech = rechercher_test_partage2_json(1, 0, $_POST['code_test'], $_POST['libelle_long_test'], $_POST['id_etat'], $_SESSION['id_lieu'], $_POST['duree_test'], $_POST['version_test'], date_fr_to_en($_POST['date_mise_en_prod']), date_fr_to_en($_POST['date_retrait']), $_POST['id_facteur'], $_POST['id_sphere'], $_POST['retour_arriere'], $_POST['aleatoire'], $_POST['id_lieu'], $_POST['projet_test']);
            if ($test_rech != null) {
                $page['tests_recherche'] = json_encode($test_rech);
            } else {
                $page['tests_recherche'] = '';
            }
        } elseif (isset($_POST['retirer'])) {
            if (isset($_POST['droits'])) {
                foreach ($_POST['droits'] as $droit) {
                    retirer_droit_test($droit);
                }
                header("Location : index.php?controleur=test&tache=base");
            } else {
                $page['message'] = $message['test_obligatoire'];
            }
        }
    } else {
        $page['vue'] = "erreur_droit.vue.php";
    }
}