[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 06/13: Task #2332: Suivi : ajout fichier lié
From: |
dwm |
Subject: |
[Noalyss-commit] [noalyss] 06/13: Task #2332: Suivi : ajout fichier lié aux commentaires |
Date: |
Sun, 28 Jan 2024 09:05:26 -0500 (EST) |
sparkyx pushed a commit to branch devel
in repository noalyss.
commit 6e627baa457c34d02da8f9fc0e2962d4cecfc8b9
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Jan 27 18:35:47 2024 +0100
Task #2332: Suivi : ajout fichier lié aux commentaires
---
include/action.common.inc.php | 49 +++++++++++++++++-----------------
include/class/document.class.php | 11 +++++---
include/class/follow_up.class.php | 11 ++++++--
include/template/follow_up-display.php | 25 +++++++++++++++--
sql/upgrade.sql | 7 +++++
5 files changed, 71 insertions(+), 32 deletions(-)
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 '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action
Sauvée').' : ' . $act->ag_ref) . '</a></p>';
+ $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 '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action
Sauvée').' : ' . $act->ag_ref) . '</a></p>';
- } catch (Exception $e)
- {
- echo '<span class="notice">';
- echo _("Erreur")." ".$e->getMessage();
- echo '</span>';
- $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 '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action
Sauvée') . ' : ' . $act->ag_ref) . '</a></p>';
+
+ Follow_Up::show_action_list($cn, $base);
+ $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get()
. "&ac=" . $http->request("ac") .
+ $sup_parameter;
+ echo '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action
Sauvée') . ' : ' . $act->ag_ref) . '</a></p>';
+ } catch (Exception $e) {
+ echo '<span class="notice">';
+ echo _("Erreur") . " " . $e->getMessage();
+ echo '</span>';
+ $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; $i<sizeof($name); $i++)
{
$new_name=tempnam($_ENV['TMP'], 'doc_');
@@ -487,12 +491,13 @@ class Document
$this->d_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 '</span>';
}
}
+ $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.
- '<div class="nicEdit-main field_follow_up"
style="margin-left:5%;margin-bottom:2rem;width:90%"
id="com'.$acomment[$c]['agc_id'].'"> '.
+ '<div class="nicEdit-main field_follow_up"
style="margin-left:5%;margin-bottom:auto;width:90%"
id="com'.$acomment[$c]['agc_id'].'"> '.
" ".$acomment[$c]['agc_comment_raw'].'</div>'
;
@@ -414,10 +415,30 @@ function small(p_id_textarea){
Dossier::id().',0)" >\1</a>',$comment);
echo '<p></p>';
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 '<div style="left:10%">';
+ 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('<a class="print_line" href="%s">%s</a>',
+ $url,h($file['d_filename']));
+
+ }
+ echo '</div>';
+ }
+
} // end for
if ( $has_description && $p_view == 'UPD' &&
Document_Option::can_add_comment($ag_id)) {
echo '<span class="noprint">';
- echo '<div style="margin-left:5%">';
+ echo '<div style="margin-left:5%;margin-top:2.5rem">';
echo $desc->input();
echo '</div>';
}
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);
- [Noalyss-commit] [noalyss] 09/13: Task #2326: Suivi : possibilité de charger plusieurs documents, (continued)
- [Noalyss-commit] [noalyss] 09/13: Task #2326: Suivi : possibilité de charger plusieurs documents, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 10/13: Correct merge, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 05/13: Task #0002327 Warning if saldo incorrect, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 01/13: Cosmetic : follow-up comment, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 02/13: Reconnect if session expired, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 03/13: Bug : MY_REPORT was not respected, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 11/13: Task #2332 : cosmetique cache liste fichiers, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 12/13: Upgrade.sql devenu upgrade192.sql, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 07/13: Correct CSS, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 13/13: Task #2332 : cosmetique cache liste fichiers, dwm, 2024/01/28
- [Noalyss-commit] [noalyss] 06/13: Task #2332: Suivi : ajout fichier lié aux commentaires,
dwm <=
- [Noalyss-commit] [noalyss] 08/13: Improve tools debug, dwm, 2024/01/28