diff --git a/include/action.common.inc.php b/include/action.common.inc.php
index 2bb742526..ea1f14b7d 100644
--- a/include/action.common.inc.php
+++ b/include/action.common.inc.php
@@ -322,33 +322,32 @@ if ($sub_action == "save_action_st2")
{
$act = new Follow_Up($cn);
$act->fromArray($_POST);
- try {
- $act->d_id = 0;
- $act->ag_id=$http->request("ag_id","number");
- $act->md_id = $http->post('gen_doc','number',0);
+ try {
+ $act->d_id = 0;
+ $act->ag_id = $http->request("ag_id", "number");
+ $act->md_id = $http->post('gen_doc', 'number', 0);
- $act->verify();
- $sup_parameter=HtmlInput::array_to_string(["sc","sb","f_id","qcode"], $_REQUEST,"&");
- // insert into action_gestion
- $act->update();
-
- $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get()."&ac=".$http->request("ac").
- $sup_parameter;
- echo '
' . hb(_('Action Sauvée').' : ' . $act->ag_ref) . '
';
+ $act->verify();
+ $sup_parameter = HtmlInput::array_to_string(["sc", "sb", "f_id", "qcode"], $_REQUEST, "&");
+ // insert into action_gestion
+ $act->update();
- Follow_Up::show_action_list($cn,$base);
- $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get()."&ac=".$http->request("ac").
- $sup_parameter;
- echo '' . hb(_('Action Sauvée').' : ' . $act->ag_ref) . '
';
- } catch (Exception $e)
- {
- echo '';
- echo _("Erreur")." ".$e->getMessage();
- echo '';
- $sub_action="add_action";
- $error_id=$e->getCode();
- record_log($e);
- }
+ $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get() . "&ac=" . $http->request("ac") .
+ $sup_parameter;
+ echo '' . hb(_('Action Sauvée') . ' : ' . $act->ag_ref) . '
';
+
+ Follow_Up::show_action_list($cn, $base);
+ $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get() . "&ac=" . $http->request("ac") .
+ $sup_parameter;
+ echo '' . hb(_('Action Sauvée') . ' : ' . $act->ag_ref) . '
';
+ } catch (Exception $e) {
+ echo '';
+ echo _("Erreur") . " " . $e->getMessage();
+ echo '';
+ $sub_action = "add_action";
+ $error_id = $e->getCode();
+ record_log($e);
+ }
}
//--------------------------------------------------------------------------------
// Add an action
diff --git a/include/class/document.class.php b/include/class/document.class.php
index bee321778..d3b916760 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -449,7 +449,10 @@ class Document
/**
* @brief upload a file into document
* all the needed data are in $_FILES we don't increment the seq
- * @param $p_file : array containing by default $_FILES
+ * $_FILES : array containing by default $_FILES
+ * @param int $p_ag_id ACTION_GESTION.AG_ID
+ * @param int $agc_id ACTION_GESTION_COMMENT.AGC_ID
+ * @returns array of int DOCUMENT.D_ID (id of saved documents )
*
*/
function upload($p_ag_id)
@@ -463,6 +466,7 @@ class Document
// Start Transaction
$this->db->start();
$name=$_FILES['file_upload']['name'];
+ $document_saved=array();
for ($i=0; $id_description=strip_tags($_POST['input_desc'][$i]);
// 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)";
- $this->db->exec_sql($sql,
+ . " values ($1,$2,$3,$4,$5,$6) returning d_id";
+ $document_saved[]=$this->db->get_value($sql,
array($p_ag_id, $this->d_lob, $this->d_filename, $this->d_mimetype, 1, $this->d_description));
}
} /* end for */
$this->db->commit();
+ return $document_saved;
}
/**
diff --git a/include/class/follow_up.class.php b/include/class/follow_up.class.php
index e03750c6d..ea0ab2594 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -948,7 +948,7 @@ class Follow_Up
}
// upload documents
$doc=new Document($this->db);
- $doc->upload($this->ag_id);
+ $document_saved=$doc->upload($this->ag_id);
/* save action details */
$http=new HttpInput();
@@ -966,8 +966,15 @@ class Follow_Up
if (trim(strip_tags($this->ag_comment??"")) !='')
{
$notag_comment=strip_tags($this->ag_comment);
- $this->db->exec_sql("insert into action_gestion_comment (ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3,$4)"
+ $action_comment_id=$this->db->get_value("insert into action_gestion_comment (ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3,$4) returning agc_id"
, array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], $notag_comment,$this->ag_comment));
+ // saved also documents for this comment
+ if ( ! empty ($document_saved)) {
+ foreach ($document_saved as $document_id) {
+ $this->db->exec_sql("insert into action_comment_document(document_id,action_gestion_comment_id) values ($1,$2)",
+ [$document_id,$action_comment_id]);
+ }
+ }
}
if (trim(strip_tags($this->ag_description??""))!='' )
{
diff --git a/include/template/follow_up-display.php b/include/template/follow_up-display.php
index 5d098abca..bc2cb14dd 100644
--- a/include/template/follow_up-display.php
+++ b/include/template/follow_up-display.php
@@ -377,6 +377,7 @@ function small(p_id_textarea){
echo '';
}
}
+ $dossier_id=Dossier::id();
if ( count($acomment) > 0
&& Document_Option::can_add_comment($ag_id)
&& Document_Option::option_comment($this->dt_id) == "SOME_FIXED")
@@ -395,7 +396,7 @@ function small(p_id_textarea){
$js=Icon_Action::trash("accom".$acomment[$c]['agc_id'], $rmComment);
$comment= h($m_desc.' '.$acomment[$c]['agc_id'].'('.$acomment[$c]['tech_user']." ".
$acomment[$c]['str_agc_date'].')').$js.
- ' '.
+ '
'.
" ".$acomment[$c]['agc_comment_raw'].'
'
;
@@ -414,10 +415,30 @@ function small(p_id_textarea){
Dossier::id().',0)" >\1',$comment);
echo '
';
echo $comment;
+ // link to files to download
+ $aFile=$this->db->get_array('select d_id,d_filename,d_description,d_mimetype
+ from action_comment_document
+ join document on (d_id=document_id) where action_gestion_comment_id=$1'
+ , array( $acomment[$c]['agc_id']));
+ if ( ! empty ($aFile)) {
+ echo '
';
+ echo _("Fichiers :");
+ foreach ($aFile as $file)
+ {
+ $url="export.php?".http_build_query(array("act"=>'RAW:document'
+ ,"gDossier"=>$dossier_id
+ ,"d_id"=>$file["d_id"]));
+ printf('
%s',
+ $url,h($file['d_filename']));
+
+ }
+ echo '
';
+ }
+
} // end for
if ( $has_description && $p_view == 'UPD' && Document_Option::can_add_comment($ag_id)) {
echo '
';
- echo '';
+ echo '
';
echo $desc->input();
echo '
';
}
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index e69de29bb..189a5a644 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -0,0 +1,7 @@
+create table action_comment_document (acd_id bigint generated by default as identity primary key
+ , document_id bigint references document(d_id) on delete cascade on update cascade,
+ action_gestion_comment_id bigint references action_gestion_comment(agc_id) on delete cascade on update cascade);
+
+alter table action_comment_document
+ add constraint action_comment_document_un
+ unique (document_id, action_gestion_comment_id);