Task #2326: Suivi : possibilité de charger plusieurs documents
This commit is contained in:
parent
b80c7f9872
commit
4a5298f4e4
4 changed files with 59 additions and 27 deletions
|
|
@ -467,6 +467,9 @@ class Document
|
|||
$this->db->start();
|
||||
$name=$_FILES['file_upload']['name'];
|
||||
$document_saved=array();
|
||||
$http=new HttpInput();
|
||||
$aDescription=$http->post("input_desc","array",array());
|
||||
$description="";
|
||||
for ($i=0; $i<sizeof($name); $i++)
|
||||
{
|
||||
$new_name=tempnam($_ENV['TMP'], 'doc_');
|
||||
|
|
@ -488,7 +491,10 @@ class Document
|
|||
$this->d_lob=$oid;
|
||||
$this->d_filename=$_FILES['file_upload']['name'][$i];
|
||||
$this->d_mimetype=$_FILES['file_upload']['type'][$i];
|
||||
$this->d_description=strip_tags($_POST['input_desc'][$i]);
|
||||
if ( isset($aDescription[$i])) {
|
||||
$description=$aDescription[$i];
|
||||
}
|
||||
$this->d_description=$description;
|
||||
// insert into the table
|
||||
$sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description)"
|
||||
. " values ($1,$2,$3,$4,$5,$6) returning d_id";
|
||||
|
|
@ -545,8 +551,19 @@ class Document
|
|||
$this->db->start();
|
||||
$ret=$this->db->exec_sql(
|
||||
"select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
|
||||
|
||||
if (Database::num_row($ret)==0)
|
||||
{
|
||||
// send it to stdout
|
||||
ini_set('zlib.output_compression', 'Off');
|
||||
header("Pragma: public");
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header('Content-type: text');
|
||||
header('Content-Disposition: attachment;filename="vide.txt"', FALSE);
|
||||
header("Accept-Ranges: bytes");
|
||||
echo "VIDE-EMPTY";
|
||||
return;
|
||||
}
|
||||
$row=Database::fetch_array($ret, 0);
|
||||
|
|
@ -555,7 +572,7 @@ class Document
|
|||
$this->db->lo_export($row['d_lob'], $tmp);
|
||||
$this->d_mimetype=$row['d_mimetype'];
|
||||
$this->d_filename=$row['d_filename'];
|
||||
|
||||
$file=fopen($tmp, 'r');
|
||||
// send it to stdout
|
||||
ini_set('zlib.output_compression', 'Off');
|
||||
header("Pragma: public");
|
||||
|
|
@ -565,7 +582,6 @@ class Document
|
|||
header('Content-type: '.$this->d_mimetype);
|
||||
header('Content-Disposition: attachment;filename="'.$this->d_filename.'"', FALSE);
|
||||
header("Accept-Ranges: bytes");
|
||||
$file=fopen($tmp, 'r');
|
||||
while (!feof($file))
|
||||
{
|
||||
echo fread($file, 8192);
|
||||
|
|
@ -573,7 +589,6 @@ class Document
|
|||
fclose($file);
|
||||
|
||||
unlink($tmp);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -416,6 +416,7 @@ class Follow_Up
|
|||
/* for new files */
|
||||
$upload=new IFile();
|
||||
$upload->name="file_upload[]";
|
||||
$upload->set_multiple(true);
|
||||
$upload->setAlertOnSize(true);
|
||||
$upload->readOnly=$readonly;
|
||||
$upload->value="";
|
||||
|
|
|
|||
|
|
@ -31,10 +31,23 @@ class IFile extends HtmlInput
|
|||
{
|
||||
// if true , the size is tested and a box is displaid
|
||||
private $alert_on_size;
|
||||
private $multiple ; // false by default, if true allow to select several files
|
||||
function __construct($p_name = "", $p_value = "", $p_id = "")
|
||||
{
|
||||
parent::__construct($p_name, $p_value, $p_id);
|
||||
$this->alert_on_size=false;
|
||||
$this->multiple=false;
|
||||
}
|
||||
|
||||
public function get_multiple(): bool
|
||||
{
|
||||
return $this->multiple;
|
||||
}
|
||||
|
||||
public function set_multiple(bool $multiple): IFile
|
||||
{
|
||||
$this->multiple = $multiple;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,7 +74,11 @@ class IFile extends HtmlInput
|
|||
$this->value=($p_value==null)?$this->value:$p_value;
|
||||
if ( $this->readOnly==true) return $this->display();
|
||||
if ($this->id=="") $this->id=uniqid("file_");
|
||||
$r=sprintf('<INPUT class="inp" TYPE="file" name="%s" id="%s" value="%s">',
|
||||
$multiple="";
|
||||
if ( $this->multiple) $multiple=" multiple ";
|
||||
|
||||
$r=sprintf('<INPUT class="inp" %s TYPE="file" name="%s" id="%s" value="%s">',
|
||||
$multiple,
|
||||
$this->name,
|
||||
$this->id,
|
||||
$this->value);
|
||||
|
|
|
|||
|
|
@ -472,8 +472,26 @@ if ( $this->ag_id > 0 && Document_Option::is_enable_operation_detail($this->dt_i
|
|||
**********************************************************************************************************************/
|
||||
?>
|
||||
|
||||
<div style="clear:both"></div>
|
||||
<div style="clear:both"></div>
|
||||
<?php if ($p_view != 'READ') : ?>
|
||||
<div class="noprint">
|
||||
<h3 >Fichiers à ajouter: </h3>
|
||||
<ol id='add_file' >
|
||||
<li>
|
||||
<?php echo $upload->input();
|
||||
?>
|
||||
|
||||
<?php
|
||||
$js="document.getElementById('add_file').removeChild(this.parentNode)";
|
||||
echo Icon_Action::trash(uniqid(),$js);
|
||||
?>
|
||||
</li>
|
||||
</ol>
|
||||
<span >
|
||||
<input type="button" class="smallbutton" onclick="addFiles();" value="<?php echo _("Ajouter un fichier")?>">
|
||||
</span>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
|
||||
<div id="div_action_attached_doc">
|
||||
|
|
@ -563,7 +581,7 @@ function addFiles() {
|
|||
try {
|
||||
docAdded=document.getElementById('add_file');
|
||||
new_element=document.createElement('li');
|
||||
new_element.innerHTML='<input class="inp" type="file" value="" name="file_upload[]"/><label>Description</label> <input type="input" class="input_text" name="input_desc[]" >';
|
||||
new_element.innerHTML='<input class="inp" type="file" value="" multiple name="file_upload[]"/>';
|
||||
|
||||
new_element.innerHTML+='<span id="<?=uniqid("file")?>" onclick="document.getElementById(\'add_file\').removeChild(this.parentNode)" class="icon"></span>';
|
||||
|
||||
|
|
@ -574,26 +592,7 @@ try {
|
|||
catch(exception) { alert('<?php echo j(_('Je ne peux pas ajouter de fichier'))?>'); alert(exception.message);}
|
||||
}
|
||||
</script>
|
||||
<?php if ($p_view != 'READ') : ?>
|
||||
<div class="noprint">
|
||||
<h3 >Fichiers à ajouter: </h3>
|
||||
<ol id='add_file' >
|
||||
<li>
|
||||
<?php echo $upload->input();
|
||||
?>
|
||||
<label><?php echo _('Description')?></label>
|
||||
<input type="input" class="input_text" name="input_desc[]" >
|
||||
<?php
|
||||
$js="document.getElementById('add_file').removeChild(this.parentNode)";
|
||||
echo Icon_Action::trash(uniqid(),$js);
|
||||
?>
|
||||
</li>
|
||||
</ol>
|
||||
<span >
|
||||
<input type="button" class="smallbutton" onclick="addFiles();" value="<?php echo _("Ajouter un fichier")?>">
|
||||
</span>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
</div>
|
||||
<?php if ($p_view != 'NEW') : ?>
|
||||
Document créé le <?php echo $this->ag_timestamp ?> par <?php echo $this->ag_owner?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue