Skip to content
Snippets Groups Projects
Commit dcf05160 authored by Cédric Salvador's avatar Cédric Salvador Committed by Raphaël Doursenaud
Browse files

delete function for links

parent 28bfb10d
No related branches found
No related tags found
No related merge requests found
<?php
// Envoi fichier
if (GETPOST('sendit') && ! empty($conf->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;
}
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment