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 <?php
// Envoi fichier // Send file/link
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
{ if ($object->id) {
if ($object->id) dol_add_file_process($upload_dir, 0, 1, 'userfile');
{
dol_add_file_process($upload_dir,0,1,'userfile');
} }
} elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { } elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
if ($object->id) { 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://') { if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') {
$link = 'http://' . $link; $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); // Delete file/link
if ($ret) { if ($action == 'confirm_deletefile' && $confirm == 'yes') {
setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); if ($object->id) {
} else { $urlfile = GETPOST('urlfile', 'alpha');
setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); $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; exit;
} }
} }

View File

@ -257,6 +257,8 @@ class Link extends CommonObject
$link->datea = $this->db->jdate($obj->datea); $link->datea = $this->db->jdate($obj->datea);
$link->url = $obj->url; $link->url = $obj->url;
$link->label = $obj->label; $link->label = $obj->label;
$link->objecttype = $obj->objecttype;
$link->objectid = $obj->objectid;
$links[] = $link; $links[] = $link;
} }
return 1; return 1;
@ -293,6 +295,8 @@ class Link extends CommonObject
$this->datea = $this->db->jdate($obj->datea); $this->datea = $this->db->jdate($obj->datea);
$this->url = $obj->url; $this->url = $obj->url;
$this->label = $obj->label; $this->label = $obj->label;
$this->objecttype = $obj->objecttype;
$this->objectid = $obj->objectid;
return 1; return 1;
} else { } else {
$this->error = 'Fetch no link found for id = ' . $rowid; $this->error = 'Fetch no link found for id = ' . $rowid;