Commit 1ae0fcfd authored by Jerome Mariette's avatar Jerome Mariette
Browse files

download working

parent 5b421e47
......@@ -14,6 +14,7 @@ class tx_nG6_eid {
/* connect to the databse */
tslib_eidtools::connectDB();
$html = '';
$id = trim(t3lib_div::_GP('id'));
$type = trim(t3lib_div::_GP('type'));
......@@ -53,9 +54,6 @@ class tx_nG6_eid {
$dest_directories = Array();
$vals = split(";", $ids);
$temporary_dir = $this->createRandomArchiveName($tmp_folder);
$i = 0;
$tmp = "";
foreach($vals as $val) {
if ($val != "undefined" && $val != "") {
$id = split("_", $val);
......@@ -89,12 +87,11 @@ class tx_nG6_eid {
}
}
} else if ($id[0] == "project") {
$tmp .= "p".$id[1].", ";
//TODO
}
$i++;
}
}
$this->archiveZip($src_directories, $dest_directories);
return $this->archiveZip($src_directories, $dest_directories, $temporary_dir, 'tar.gz');
}
function get_run_analysis($run_id) {
......@@ -337,55 +334,40 @@ class tx_nG6_eid {
return $dir."/";
}
function force_download($name, $path) {
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
readfile($path);
exit();
}
/**
* Archivate data from $directories_src to an archive (structurated as $directories_dest)
*
* @param array $directories_src: list of directories to archivate
* @param array $directories_dest: list of directories to archivate
* @param string $method : tar.gz
* @return string HTML link to the archive
*/
function archiveZip($directories_src , $directories_dest)
{
$dataDir = $this->internal['data'];
$zip = Array() ; //array of files
function archiveZip($directories_src , $directories_dest, $temporary_dir, $method)
{
##Do an exhaustive list of files from the directories list
foreach($directories_src as $index => $dir_src)
{
$dir_src = $dataDir . $dir_src ;
$dir_dest = $directories_dest[$index];
//$zip = Array() ; //array of files
$subzip = $this->copyDirectoryAndList($dir_src, $dir_dest);
$zip = array_merge ( $zip , $subzip );
$this->copyDirectoryAndList($dir_src, $directories_dest[$index]);
}
if( count($zip)==0 ){
return "\n\n".'No file to zip';
}
//TODO: chunk into small buffers (about 100MB)
//change cwd to the $this->internal['archive_root']
$normal_cwd = getcwd();
$this->internal['archive_root'] = $this->dirSlash($this->internal['archive_root']);
chdir(dirname($this->internal['archive_root']));
$normal_cwd = getcwd();
$temporary_dir = $this->dirSlash($temporary_dir);
chdir(dirname($temporary_dir));
//write out zipped file
switch($this->internal["zip_option"])
switch($method)
{
case 'zip': //use zip.lib.php
foreach($zip as $key => $file){ #remove path above the archive
$zip[$key] = substr( $file, strlen("fileadmin/temp/") , strlen($file));
}
$outfile = basename($this->internal['archive_root']).'.zip';
## calls to zip.lib.php library
$ziper = new zipfile();
$ziper->addFiles($zip); //array of files
$ziper->output($outfile);
break;
case 'tar.gz': //system call
$archive_name = basename($this->internal['archive_root']);
$archive_name = basename($temporary_dir);
$outfile = $archive_name.".tar";
system("tar -Pcf ".$outfile." ".$archive_name." --remove-files");
system("gzip ".$outfile);
......@@ -395,8 +377,7 @@ class tx_nG6_eid {
}
//restore cwd
chdir($normal_cwd);
unset($zip); //free memory //target="_blank"
return "\n\n".'<a id="download_link" href="'.$this->internal['temp_directory'].'/'.$outfile.'" > '.basename($outfile).'</a>';
return $outfile;
}
/**
......
......@@ -77,6 +77,9 @@ class tx_nG6_pi5 extends tslib_pibase {
// Sets the page content
// First get the temp url :
$tmp_url = substr($this->conf["temp"], strpos($this->conf["temp"], "fileadmin"));
$content = '<h2>Telechargement de vos donnees</h2>';
$content .= '<p>Selectionner dans l\'arbre les informations que vous souhaitez telecharger puis cliquer sur le bouton de telechargement. </p>';
$content .= '<script type="text/javascript" class="source">
......@@ -114,13 +117,13 @@ class tx_nG6_pi5 extends tslib_pibase {
$(".jstree-checked > ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked").each(function(){
url_val += $(this).attr("id")+";";
});
alert(url_val);
$("#download_dialog").dialog("option", "title", "Telechargement ...");
$("#download_dialog").html(\'<img src="fileadmin/templates/nG6template/images/light_wait.gif"/>\').dialog("open");
$("#download_dialog").dialog("option", "title", "T&eacute;l&eacute;chargement");
$("#download_dialog").html(\'<img src="fileadmin/templates/nG6template/images/light_wait.gif"/> Cr&eacute;ation en cours ...\').dialog("open");
$.ajax({
url: url_val,
success: function(val) {
$("#download_dialog").html(val).dialog("open");
$("#download_dialog").dialog("close");
location.href = "'.$tmp_url.'/"+val;
}
});
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment