delete function for links

This commit is contained in:
Cédric Salvador 2013-07-30 16:46:41 +02:00 committed by Raphaël Doursenaud
parent 28bfb10dbd
commit dcf051605a
2 changed files with 35 additions and 19 deletions

View File

@ -1,10 +1,8 @@
<?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;
}
}

View File

@ -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;