mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 01:28:19 +01:00
NEW ticket : display files linked to actioncomm (#32325)
* modify ecmfiles to link ecmfile to actioncomm * ticket : link files to actioncomm * display linked files in actioncomm cards * Various fix (pre-commit, phpstan, usw.)
This commit is contained in:
committed by
GitHub
parent
783807af14
commit
3c37f28d50
@@ -14857,10 +14857,11 @@ function getActionCommEcmList($object)
|
||||
|
||||
$documents = array();
|
||||
|
||||
$sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename';
|
||||
$sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
|
||||
$sql .= " WHERE ecm.filepath = 'agenda/".((int) $object->id)."'";
|
||||
//$sql.= " ecm.src_object_type = '".$db->escape($object->element)."' AND ecm.src_object_id = ".((int) $object->id); // Old version didn't add object_type during upload
|
||||
$sql.= ' OR ecm.agenda_id = '.(int) $object->id;
|
||||
$sql .= ' ORDER BY ecm.position ASC';
|
||||
|
||||
$resql = $db->query($sql);
|
||||
@@ -15580,10 +15581,21 @@ function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon = null,
|
||||
|
||||
$filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
|
||||
$mime = dol_mimetype($filePath);
|
||||
$file = $actionstatic->id.'/'.$doc->filename;
|
||||
$thumb = $actionstatic->id.'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename, '.')).'_mini'.substr($doc->filename, strrpos($doc->filename, '.'));
|
||||
$doclink = dol_buildpath('document.php', 1).'?modulepart=actions&attachment=0&file='.urlencode($file).'&entity='.$conf->entity;
|
||||
$viewlink = dol_buildpath('viewimage.php', 1).'?modulepart=actions&file='.urlencode($thumb).'&entity='.$conf->entity;
|
||||
if (empty($doc->agenda_id)) {
|
||||
$dir_ref = $actionstatic->id;
|
||||
$modulepart = 'actions';
|
||||
} else {
|
||||
$split_dir = explode('/', $doc->filepath);
|
||||
$modulepart = array_shift($split_dir);
|
||||
$dir_ref = implode('/', $split_dir);
|
||||
}
|
||||
|
||||
$file = $dir_ref.'/'.$doc->filename;
|
||||
$thumb = $dir_ref.'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename, '.')).'_mini'.substr($doc->filename, strrpos($doc->filename, '.'));
|
||||
$doclink = dol_buildpath('document.php', 1).'?modulepart='.$modulepart.'&attachment=0&file='.urlencode($file).'&entity='.$conf->entity;
|
||||
$viewlink = dol_buildpath('viewimage.php', 1).'?modulepart='.$modulepart.'&file='.urlencode($thumb).'&entity='.$conf->entity;
|
||||
|
||||
|
||||
|
||||
$mimeAttr = ' mime="'.$mime.'" ';
|
||||
$class = '';
|
||||
|
||||
@@ -157,6 +157,11 @@ class EcmFiles extends CommonObject
|
||||
*/
|
||||
public $src_object_id;
|
||||
|
||||
/**
|
||||
* @var int ID of linked agenda event
|
||||
*/
|
||||
public $agenda_id;
|
||||
|
||||
/**
|
||||
* @var int section_id ID of section = ID of EcmDirectory, directory of manual ECM (not stored into database)
|
||||
*/
|
||||
@@ -187,6 +192,7 @@ class EcmFiles extends CommonObject
|
||||
'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
|
||||
'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
|
||||
'acl' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160, 'comment' => "for future permission 'per file'"),
|
||||
'agenda_id' => array('type' => 'integer', 'label' => 'IdAgenda', 'enabled' => 1, 'visible' => 0, 'position' => 180, 'comment' => "Link to an actioncomm"),
|
||||
);
|
||||
|
||||
|
||||
@@ -307,6 +313,9 @@ class EcmFiles extends CommonObject
|
||||
$extraparams = dol_trunc($extraparams, 250);
|
||||
|
||||
// Put here code to add control on parameters values
|
||||
if (!empty($this->agenda_id)) {
|
||||
$this->agenda_id = (int) $this->agenda_id;
|
||||
}
|
||||
|
||||
// Insert request
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
|
||||
@@ -332,7 +341,8 @@ class EcmFiles extends CommonObject
|
||||
$sql .= 'fk_user_m,';
|
||||
$sql .= 'acl,';
|
||||
$sql .= 'src_object_type,';
|
||||
$sql .= 'src_object_id';
|
||||
$sql .= 'src_object_id,';
|
||||
$sql .= 'agenda_id';
|
||||
$sql .= ') VALUES (';
|
||||
$sql .= " '".$this->db->escape($this->ref)."', ";
|
||||
$sql .= ' '.(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").',';
|
||||
@@ -356,7 +366,8 @@ class EcmFiles extends CommonObject
|
||||
$sql .= ' '.(!isset($this->fk_user_m) ? 'NULL' : $this->fk_user_m).',';
|
||||
$sql .= ' '.(!isset($this->acl) ? 'NULL' : "'".$this->db->escape($this->acl)."'").',';
|
||||
$sql .= ' '.(!isset($this->src_object_type) ? 'NULL' : "'".$this->db->escape($this->src_object_type)."'").',';
|
||||
$sql .= ' '.(!isset($this->src_object_id) ? 'NULL' : $this->src_object_id);
|
||||
$sql .= ' '.(!isset($this->src_object_id) ? 'NULL' : $this->src_object_id).',';
|
||||
$sql .= ' '.(empty($this->agenda_id) ? 'NULL' : (int) $this->agenda_id);
|
||||
$sql .= ')';
|
||||
|
||||
$this->db->begin();
|
||||
@@ -443,7 +454,8 @@ class EcmFiles extends CommonObject
|
||||
$sql .= ' t.note_public,';
|
||||
$sql .= " t.acl,";
|
||||
$sql .= " t.src_object_type,";
|
||||
$sql .= " t.src_object_id";
|
||||
$sql .= " t.src_object_id,";
|
||||
$sql .= " t.agenda_id";
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||
$sql .= ' WHERE 1 = 1';
|
||||
/* Fetching this table depends on filepath+filename, it must not depends on entity because filesystem on disk does not know what is Dolibarr entities
|
||||
@@ -524,7 +536,7 @@ class EcmFiles extends CommonObject
|
||||
$this->acl = $obj->acl;
|
||||
$this->src_object_type = $obj->src_object_type;
|
||||
$this->src_object_id = $obj->src_object_id;
|
||||
|
||||
$this->agenda_id = $obj->agenda_id;
|
||||
$this->extraparams = (isset($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : null);
|
||||
}
|
||||
|
||||
@@ -587,7 +599,8 @@ class EcmFiles extends CommonObject
|
||||
$sql .= " t.fk_user_m,";
|
||||
$sql .= " t.acl,";
|
||||
$sql .= " t.src_object_type,";
|
||||
$sql .= " t.src_object_id";
|
||||
$sql .= " t.src_object_id,";
|
||||
$sql .= " t.agenda_id";
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||
$sql .= ' WHERE 1 = 1';
|
||||
|
||||
@@ -663,6 +676,7 @@ class EcmFiles extends CommonObject
|
||||
$line->acl = $obj->acl;
|
||||
$line->src_object_type = $obj->src_object_type;
|
||||
$line->src_object_id = $obj->src_object_id;
|
||||
$line->agenda_id = $obj->agenda_id;
|
||||
$this->lines[] = $line;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
@@ -736,8 +750,9 @@ class EcmFiles extends CommonObject
|
||||
if (isset($this->src_object_type)) {
|
||||
$this->src_object_type = trim($this->src_object_type);
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (!empty($this->agenda_id)) {
|
||||
$this->agenda_id = (int) $this->agenda_id;
|
||||
}
|
||||
$extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null);
|
||||
$extraparams = dol_trunc($extraparams, 250);
|
||||
|
||||
@@ -764,7 +779,8 @@ class EcmFiles extends CommonObject
|
||||
$sql .= ' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).',';
|
||||
$sql .= ' acl = '.(isset($this->acl) ? "'".$this->db->escape($this->acl)."'" : "null").',';
|
||||
$sql .= ' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id : "null").',';
|
||||
$sql .= ' src_object_type = '.(isset($this->src_object_type) ? "'".$this->db->escape($this->src_object_type)."'" : "null");
|
||||
$sql .= ' src_object_type = '.(isset($this->src_object_type) ? "'".$this->db->escape($this->src_object_type)."'" : "null").',';
|
||||
$sql .= ' agenda_id = '.($this->agenda_id > 0 ? (int) $this->agenda_id : null);
|
||||
$sql .= ' WHERE rowid='.((int) $this->id);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@@ -346,7 +346,8 @@ class ActionsTicket extends CommonHookActions
|
||||
$sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id';
|
||||
$sql .= ', ecm.filepath, ecm.filename, ecm.share';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
|
||||
$sql .= " WHERE ecm.filepath = 'agenda/".$arraymsgs['id']."'";
|
||||
$sql .= " WHERE ecm.filepath = 'agenda/".(int) $arraymsgs['id']."'";
|
||||
$sql .= " OR (ecm.agenda_id = ".(int) $arraymsgs['id']." AND ecm.src_object_type = 'ticket' AND ecm.src_object_id = ".(int) $this->dao->id.")";
|
||||
$sql .= ' ORDER BY ecm.position ASC';
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
@@ -1900,7 +1900,7 @@ class Ticket extends CommonObject
|
||||
//if (dol_mkdir($destdir) >= 0) {
|
||||
//require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
//dol_move($filespath, $destfile); // Disabled, a file for a ticket should be stored into ticket directory. It generates big trouble.
|
||||
if (in_array($actioncomm->code, array('TICKET_MSG', 'TICKET_MSG_SENTBYMAIL'))) {
|
||||
if (in_array($actioncomm->code, array('TICKET_MSG', 'TICKET_MSG_SENTBYMAIL', 'TICKET_MSG_PRIVATE'))) {
|
||||
$ecmfile = new EcmFiles($this->db);
|
||||
$destdir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $destdir);
|
||||
$destdir = preg_replace('/[\\/]$/', '', $destdir);
|
||||
@@ -1909,11 +1909,7 @@ class Ticket extends CommonObject
|
||||
$result = $ecmfile->fetch(0, '', $destdir.'/'.$attachedfiles['names'][$key]);
|
||||
|
||||
// TODO We must add a column into ecm_files table agenda_id to store the ID of event.
|
||||
// $ecmfile->agenda_id = $actionid;
|
||||
|
||||
// Disabled, serious security hole. A file published into the ERP should not become public for everybody.
|
||||
//require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||
//$ecmfile->share = getRandomPassword(true);
|
||||
$ecmfile->agenda_id = $actionid;
|
||||
|
||||
if ($result > 0) {
|
||||
$result = $ecmfile->update($user);
|
||||
|
||||
Reference in New Issue
Block a user