Example #1
0
function open_zip_archive($id)
{
    /*
     * No longer necessary since files are already on the filesystem
    $req = "SELECT contenu FROM fichierDonne WHERE idFichierDonne=?";
    $row = DB::request_one_row($req, array($id));
    
    $result = array();
    
    $tmpname = tempnam(sys_get_temp_dir(), "phprendu");
    
    $tmp = fopen($tmpname, "w+");
    
    fwrite($tmp, $row->contenu);
    fclose($tmp);
    */
    fileIdToPath($id, $fspath, $fsname);
    if (is_numeric($zip = zip_open($fspath . $fsname))) {
        return false;
    }
    return array("handle" => $zip);
}
Example #2
0
         DB::request($req, array($idRenduDonne, $nom, $prenom, $email));
     }
 }
 // traitement fichiers
 //print_r($_FILES);
 foreach ($_FILES as $formFileId => $file) {
     if ($file['size'] > 0) {
         $fileName = $file['name'];
         $tmpName = $file['tmp_name'];
         $fileSize = $file['size'];
         $fileType = $file['type'];
         $idFichier = substr($formFileId, 7);
         $req = "INSERT INTO fichierDonne (idRenduDonne, nom, type, idFichier) " . "VALUES (?, ?, ?, ?)";
         //echo "<!-- $req -->";
         $idFichierDonne = DB::insert_autoinc($req, array($idRenduDonne, $fileName, $fileType, $idFichier));
         fileIdToPath($idFichierDonne, $fspath, $fsname);
         createFilePath($fspath);
         // déplace à son emplacement final dans le data store
         move_uploaded_file($tmpName, $fspath . $fsname);
         /*
                                 $fp      = fopen($tmpName, 'r');
                                 $content = fread($fp, filesize($tmpName));
                                 #$content = addslashes($content);  No longer needed with PDO
                                 fclose($fp);
                                  * */
         // Ajout à l'e-mail
         $mail->AddAttachment($fspath . $fsname, $fileName);
         if (true) {
             echo "<p>Fichier {$fileName} téléchargé</p>";
         }
     } else {
Example #3
0
/*
   This file is part of Envoi.

   Envoi is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Envoi is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Envoi.  If not, see <http://www.gnu.org/licenses/>.

   (c) Christophe Jacquet, 2009-2011.
*/
require "tools.php";
$res = DB::request("SELECT idFichierDonne, contenu FROM fichierDonne");
while ($row = $res->fetch()) {
    fileIdToPath($row->idFichierDonne, $path, $name);
    createFilePath($path);
    echo "{$path} {$name}: ";
    if (file_put_contents($path . $name, $row->contenu) === FALSE) {
        echo "FAILED!\n";
        break;
    } else {
        echo "OK\n";
    }
}
Example #4
0
   This file is part of Envoi.

   Envoi is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Envoi is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Envoi.  If not, see <http://www.gnu.org/licenses/>.

   (c) Christophe Jacquet, 2009-2011.
*/
session_start();
if (!isset($_SESSION["role"]) || $_SESSION["role"] != "PROF") {
    die("Vous devez être connecté.");
}
if (!isset($_GET["id"])) {
    die("Vous devez donner un identifiant.");
}
$id = $_GET["id"];
$req = "SELECT type, nom FROM fichierDonne WHERE idFichierDonne=" . $id;
$row = DB::request_one_row($req);
header("Content-type: " . $row->type);
header("Content-Disposition: inline; filename=\"" . $row->nom . "\"");
fileIdToPath($id, $fspath, $fsname);
readfile($fspath . $fsname);
Example #5
0
function supprimeLivraison($idRendu, $code = FALSE)
{
    echo "<p>Suppression de la livraison #" . $idRendu . "</p>";
    if ($code) {
        $res = DB::request("DELETE FROM rendu WHERE idRendu=? AND idEnseignant=? AND code=?", array($idRendu, $_SESSION["login"], $_POST['code']));
    } else {
        $res = DB::request("DELETE FROM rendu WHERE idRendu=? AND idEnseignant=?", array($idRendu, $_SESSION["login"]));
    }
    if ($res->rowCount() < 1) {
        die(<<<END
<p>{$idRendu} : livraison inexistante, ou n'appartenant pas à l'utilisateur {$_SESSION["login"]}, ou mauvais code.</p>
<p><a href="voirrendu.php?id={$idRendu}">Retour au rendu</a></p>
END
);
    } else {
        echo "<p>Supprimé la spécification de livraison.</p>";
    }
    # fichiers sur le disque
    $res = DB::request("SELECT idFichierDonne FROM fichierDonne NATURAL JOIN renduDonne WHERE renduDonne.idRendu = ?", array($idRendu));
    $supprCount = 0;
    $supprCountDB = 0;
    while ($row = $res->fetch()) {
        fileIdToPath($row->idFichierDonne, $p, $n);
        $fn = $p . $n;
        $r = unlink($fn);
        #echo "<p>DEBUG: deleted $fn</p>";
        if ($r) {
            $supprCount++;
        } else {
            echo "<p>ATTENTION : échec de la suppression du fichier {$fn}. Veuillez contacter le mainteneur.</p>";
        }
        # fichierDonne
        $r = DB::request("DELETE FROM fichierDonne WHERE idFichierDonne = ?", array($row->idFichierDonne));
        if ($r->rowCount() === 1) {
            $supprCountDB++;
        } else {
            echo "<p>ATTENTION : échec de la suppression du fichier {$row->idFichierDonne} dans la base. Veuillez contacter le mainteneur.</p>";
        }
    }
    echo "<p>Supprimé {$supprCount} sur disque et {$supprCountDB} dans la base</p>";
    # participant
    $res = DB::request("DELETE FROM participant WHERE idRenduDonne IN (SELECT idRenduDonne FROM renduDonne WHERE idRendu=?)", array($idRendu));
    echo "<p>Supprimé " . $res->rowCount() . " participants</p>";
    # renduDonne
    $res = DB::request("DELETE FROM renduDonne WHERE idRendu=?", array($idRendu));
    echo "<p>Supprimé " . $res->rowCount() . " livraisons</p>";
    # fichier
    $res = DB::request("DELETE FROM fichier WHERE idRendu=?", array($idRendu));
    echo "<p>Supprimé " . $res->rowCount() . " spécifications de fichiers";
}
Example #6
0
/*
   This file is part of Envoi.

   Envoi is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Envoi is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Envoi.  If not, see <http://www.gnu.org/licenses/>.

   (c) Christophe Jacquet, 2009-2014.
*/
include "tools.php";
echo "*** fileIdToPath ***\n";
$ids = array(0x12, 0x1212, 0x12345, 0x78654312);
foreach ($ids as $i) {
    fileIdToPath($i, $p, $d);
    echo sprintf("%8x: ", $i);
    echo "{$p} {$d}\n";
}
echo "*** create dirs ***\n";
//Local::$basedir
echo mkdir("/tmp/a/b", 0777, true);
echo mkdir("/tmp/a/c", 0777, true);
echo mkdir("/tmp/a/c/d", 0777, true);
Example #7
0
        }
    }
}
buildfilelist("");
echo "Checking whether the filesystem is consistent with the database...\n";
$delete = isset($argv[1]) && $argv[1] === "delete_orphans";
if ($delete) {
    echo "Will be deleting orphans.\n";
}
$res = DB::request("SELECT idFichierDonne, idFichier, idRenduDonne, idRendu FROM fichierDonne NATURAL JOIN renduDonne");
#var_dump($filelist);
$countOk = 0;
$countMissing = 0;
$countOrphaned = 0;
while ($row = $res->fetch()) {
    fileIdToPath($row->idFichierDonne, $p, $n);
    $fn = $p . $n;
    if (isset($filelist[$fn])) {
        unset($filelist[$fn]);
        $countOk++;
    } else {
        echo "Missing file: " . $fn . "   idRendu=" . $row->idRendu . ", idFichier=" . $row->idFichier . ", idRenduDonne=" . $row->idRenduDonne . " \n";
        $countMissing++;
    }
}
# At this point, the only remaining files are orphans
foreach ($filelist as $k => $v) {
    echo "Orphaned file: " . $k . "\n";
    if ($delete) {
        if (unlink($k)) {
            echo "Deleted {$k}\n";