diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index d41df448333..706b2f4409e 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -1,10 +1,8 @@ global->MAIN_UPLOAD_DOC)) -{ - if ($object->id) - { - dol_add_file_process($upload_dir,0,1,'userfile'); +// Send file/link +if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { + if ($object->id) { + dol_add_file_process($upload_dir, 0, 1, 'userfile'); } } elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { if ($object->id) { @@ -12,24 +10,38 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') { $link = 'http://' . $link; } - dol_add_file_process($upload_dir,0,1,'userfile', $link); + dol_add_file_process($upload_dir, 0, 1, 'userfile', $link); } } -// Delete file -if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id) - { - $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). - $ret = dol_delete_file($file,0,0,0,$object); - if ($ret) { - setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - } else { - setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); +// Delete file/link +if ($action == 'confirm_deletefile' && $confirm == 'yes') { + if ($object->id) { + $urlfile = GETPOST('urlfile', 'alpha'); + $linkid = GETPOST('linkid', 'int'); + if ($urlfile) { + $file = $upload_dir . "/" . $urlfile; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). + + $ret = dol_delete_file($file, 0, 0, 0, $object); + if ($ret) { + setEventMessage($langs->trans("FileWasRemoved", $urlfile)); + } else { + setEventMessage($langs->trans("ErrorFailToDeleteFile", $urlfile), 'errors'); + } + } elseif ($linkid) { + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $link = new Link($db); + $link->id = $linkid; + $link->fetch(); + $res = $link->delete($user); + if ($res) { + setEventMessage($langs->trans("LinkWasRemoved", $link->label) + } else { + setEventMessage($langs->trans("ErrorFailToDeleteLink", $link->label), 'errors'); + } } - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); exit; } } diff --git a/htdocs/link/class/link.class.php b/htdocs/link/class/link.class.php index cd2e714e57a..982799a57cc 100644 --- a/htdocs/link/class/link.class.php +++ b/htdocs/link/class/link.class.php @@ -257,6 +257,8 @@ class Link extends CommonObject $link->datea = $this->db->jdate($obj->datea); $link->url = $obj->url; $link->label = $obj->label; + $link->objecttype = $obj->objecttype; + $link->objectid = $obj->objectid; $links[] = $link; } return 1; @@ -293,6 +295,8 @@ class Link extends CommonObject $this->datea = $this->db->jdate($obj->datea); $this->url = $obj->url; $this->label = $obj->label; + $this->objecttype = $obj->objecttype; + $this->objectid = $obj->objectid; return 1; } else { $this->error = 'Fetch no link found for id = ' . $rowid;