noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 09/13: Task #2326: Suivi : possibilité de cha


From: dwm
Subject: [Noalyss-commit] [noalyss] 09/13: Task #2326: Suivi : possibilité de charger plusieurs documents
Date: Sun, 28 Jan 2024 09:05:27 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit 4a5298f4e47618ff1c87d07762757084b6c41278
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Jan 27 21:17:15 2024 +0100

    Task #2326: Suivi : possibilité de charger plusieurs documents
---
 include/class/document.class.php       | 23 ++++++++++++++----
 include/class/follow_up.class.php      |  1 +
 include/lib/ifile.class.php            | 19 ++++++++++++++-
 include/template/follow_up-display.php | 43 +++++++++++++++++-----------------
 4 files changed, 59 insertions(+), 27 deletions(-)

diff --git a/include/class/document.class.php b/include/class/document.class.php
index d3b916760..b55d58e7d 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -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();
     }
 
diff --git a/include/class/follow_up.class.php 
b/include/class/follow_up.class.php
index ea0ab2594..6c8c16c1c 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -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="";
diff --git a/include/lib/ifile.class.php b/include/lib/ifile.class.php
index a0ee85fc0..60a3f38ba 100644
--- a/include/lib/ifile.class.php
+++ b/include/lib/ifile.class.php
@@ -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);
diff --git a/include/template/follow_up-display.php 
b/include/template/follow_up-display.php
index bc2cb14dd..d541393a2 100644
--- a/include/template/follow_up-display.php
+++ b/include/template/follow_up-display.php
@@ -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">&#xe80f;</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?>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]