diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 7c141daa4b4..8c68f4f7c48 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3641,6 +3641,30 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed = 1; } $original_file = $conf->member->dir_output.'/'.$original_file; + } elseif ($modulepart == 'ticket' && !empty($conf->ticket->multidir_output[$entity])) { + // Wrapping for events + if ($fuser->hasRight('ticket', $read)) { + $accessallowed = 1; + } + if (!isset($_SESSION['email_customer'])) { + $sqlprotectagainstexternals = ''; + } else { + $email_split = explode('@', $_SESSION['email_customer']); + + $sqlprotectagainstexternals = 'SELECT t.rowid, t.fk_soc FROM '.MAIN_DB_PREFIX.'ticket t'; + $sqlprotectagainstexternals.= ' LEFT JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id = t.rowid'; + $sqlprotectagainstexternals.= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople c ON c.rowid = ec.fk_socpeople'; + $sqlprotectagainstexternals.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_contact tc ON tc.element = "ticket" AND tc.rowid = ec.fk_c_type_contact'; + $sqlprotectagainstexternals.= ' WHERE t.ref LIKE "'.$db->sanitize($refname).'"'; + $sqlprotectagainstexternals.= ' AND ('; + $sqlprotectagainstexternals.= ' ('; + $sqlprotectagainstexternals.= ' tc.rowid IS NOT NULL'; + $sqlprotectagainstexternals.= ' AND c.email = "'.$db->sanitize($email_split[0]).'@'.$db->sanitize($email_split[1]).'"'; + $sqlprotectagainstexternals.= ' )'; + $sqlprotectagainstexternals.= ' OR t.origin_email = "'.$db->sanitize($email_split[0]).'@'.$db->sanitize($email_split[1]).'"'; + $sqlprotectagainstexternals.= ' )'; + } + $original_file = $conf->ticket->multidir_output[$entity].'/'.$original_file; // If modulepart=module_user_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp/iduser // If modulepart=module_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp // If modulepart=module_user Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/iduser diff --git a/htdocs/document.php b/htdocs/document.php index f3db61c1737..554a857e837 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -74,6 +74,16 @@ if ((isset($_GET["modulepart"]) && $_GET["modulepart"] == 'medias')) { if (!defined("NOIPCHECK")) { define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip } +} elseif (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'ticket' && strpos($_SERVER['HTTP_REFERER'], 'public/ticket') !== false) { + if (!defined("NOLOGIN")) { + define("NOLOGIN", 1); + } + if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. + } + if (!defined("NOIPCHECK")) { + define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip + } } /** @@ -295,6 +305,16 @@ if (!empty($hashp)) { } } } + } elseif ($modulepart == 'ticket' && !getDolGlobalString('TICKET_EMAIL_MUST_EXISTS')) { + if ($sqlprotectagainstexternals) { + $resql = $db->query($sqlprotectagainstexternals); + if ($resql) { + $num = $db->num_rows($resql); + if ($num > 0) { + $accessallowed = 1; + } + } + } } } diff --git a/htdocs/ticket/class/actions_ticket.class.php b/htdocs/ticket/class/actions_ticket.class.php index bf9d0acbffe..870be32f029 100644 --- a/htdocs/ticket/class/actions_ticket.class.php +++ b/htdocs/ticket/class/actions_ticket.class.php @@ -344,7 +344,7 @@ class ActionsTicket extends CommonHookActions $documents = array(); - $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id'; + $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.agenda_id'; $sql .= ', ecm.filepath, ecm.filename, ecm.share'; $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm'; $sql .= " WHERE ecm.filepath = 'agenda/".(int) $arraymsgs['id']."'"; @@ -363,7 +363,7 @@ class ActionsTicket extends CommonHookActions $isshared = 0; $footer = '