diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php index f1a5894a78e..a95063e9d64 100644 --- a/htdocs/adherents/document.php +++ b/htdocs/adherents/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,47 +61,31 @@ if (! $sortfield) $sortfield="name"; $upload_dir = $conf->adherent->dir_output . "/" . get_exdir($id,2,0,1) . '/' . $id; - - - +$form = new Form($db); +$object=new Adherent($db); +$membert=new AdherentType($db); +$result=$object->fetch($id); +if ($result < 0) +{ + dol_print_error($db); + exit; +} /* * Actions */ -// Envoie fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Suppression fichier -if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - $langs->load("other"); - $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). - $ret=dol_delete_file($file); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* * View */ -$form = new Form($db); -$object=new Adherent($db); -$membert=new AdherentType($db); llxHeader(); if ($id > 0) { - $result=$object->fetch($id); $result=$membert->fetch($object->typeid); if ($result > 0) { @@ -180,23 +165,10 @@ if ($id > 0) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - } - - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/adherents/document.php?id='.$object->id,'',0,0,$user->rights->adherent->creer,50,$object); - - - // List of document - $formfile->list_of_documents($filearray,$object,'member','', 0, get_exdir($object->id,2,0,1).'/'.$object->id.'/'); - + $modulepart = 'member'; + $permission = $user->rights->adherent->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; print "

"; } else diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index 7f50eaabd7e..848c8057b6d 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -4,6 +4,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,8 +41,9 @@ $langs->load("commercial"); $langs->load("other"); $langs->load("bills"); -$objectid = GETPOST('id','int'); -$action=GETPOST('action','alpha'); +$objectid = GETPOST('id', 'int'); +$action=GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); // Security check $socid = GETPOST('socid','int'); @@ -79,26 +81,9 @@ if (! $sortfield) $sortfield="name"; /* - * Action envoie fichier + * Actions */ -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid); - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -/* - * Efface fichier - */ -if ($action == 'delete') -{ - $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid); - $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,$act); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); - $action=''; -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -268,15 +253,10 @@ if ($act->id > 0) print ''; - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create),50,$act); - - - // List of document - $param='&id='.$act->id; - $formfile->list_of_documents($filearray,$act,'actions',$param,0,'',$user->rights->agenda->myactions->create); + $modulepart = 'actions'; + $permission = $user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create; + $param = '&id=' . $act->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php index 3d6bc97319b..6e05813f7f3 100644 --- a/htdocs/comm/propal/document.php +++ b/htdocs/comm/propal/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,38 +65,14 @@ $object->fetch($id,$ref); if ($object->id > 0) { $object->fetch_thirdparty(); + $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref); + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; } /* * Actions */ -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - if ($object->id > 0) - { - $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); - dol_add_file_process($upload_dir,0,1,'userfile'); - } -} - -// Delete -if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id > 0) - { - $langs->load("other"); - - $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} /* @@ -153,21 +130,10 @@ if ($object->id > 0) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - } - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->propal->creer,50,$object); - - - // List of document - $formfile->list_of_documents($filearray,$object,'propal'); + $modulepart = 'propal'; + $permission = $user->rights->propal->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index 0f2925cf455..596759d44af 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,35 +66,13 @@ $object = new Commande($db); /* * Actions */ - -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) +if ($object->fetch($id)) { - if ($object->fetch($id)) - { - $object->fetch_thirdparty(); - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); - dol_add_file_process($upload_dir,0,1,'userfile'); - } + $object->fetch_thirdparty(); + $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); } -// Delete -else if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->fetch($id)) - { - $langs->load("other"); - $object->fetch_thirdparty(); - - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -107,10 +86,10 @@ $form = new Form($db); if ($id > 0 || ! empty($ref)) { if ($object->fetch($id, $ref)) - { - $object->fetch_thirdparty(); + { + $object->fetch_thirdparty(); - $upload_dir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($object->ref); + $upload_dir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($object->ref); $head = commande_prepare_head($object); dol_fiche_head($head, 'documents', $langs->trans('CustomerOrder'), 0, 'order'); @@ -140,23 +119,10 @@ if ($id > 0 || ! empty($ref)) print "\n"; print "\n"; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/commande/document.php?id='.$object->id,'',0,0,$user->rights->commande->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'commande',$param); + $modulepart = 'commande'; + $permission = $user->rights->commande->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/compta/deplacement/document.php b/htdocs/compta/deplacement/document.php index 26cdf746f46..4c44fffa6e5 100644 --- a/htdocs/compta/deplacement/document.php +++ b/htdocs/compta/deplacement/document.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,29 +72,7 @@ $modulepart='trip'; * Actions */ -if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -else if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id > 0) - { - $langs->load("other"); - $object->fetch_thirdparty(); - - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -141,23 +120,10 @@ if ($object->id) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/deplacement/document.php?id='.$object->id,'',0,0,$user->rights->deplacement->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'deplacement',$param); + $modulepart = 'deplacement'; + $permission = $user->rights->deplacement->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 8aae07746e9..cc16e5dcf77 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,40 +65,17 @@ if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="name"; $object = new Facture($db); - +if ($object->fetch($id)) +{ + $object->fetch_thirdparty(); + $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref); +} /* * Actions */ +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - if ($object->fetch($id)) - { - $object->fetch_thirdparty(); - $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref); - dol_add_file_process($upload_dir,0,1,'userfile'); - } -} - -// Delete -if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->fetch($id)) - { - $langs->load("other"); - $object->fetch_thirdparty(); - - $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} /* * View @@ -169,24 +147,10 @@ if ($id > 0 || ! empty($ref)) print "\n"; print "\n"; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } - - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer,50,$object); - - - // List of document - $param='&facid='.$object->id; - $formfile->list_of_documents($filearray,$object,'facture',$param); + $modulepart = 'facture'; + $permission = $user->rights->facture->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php index 452de21285a..2e86a7a6986 100644 --- a/htdocs/compta/sociales/document.php +++ b/htdocs/compta/sociales/document.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,6 +41,7 @@ $langs->load("bills"); $id = GETPOST('id','int'); $action = GETPOST("action"); +$confirm = GETPOST('confirm', 'alpha'); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -71,18 +73,7 @@ $modulepart='tax'; * Actions */ -if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -if ($action == 'delete') -{ - $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'); -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -169,16 +160,10 @@ if ($object->id) print ''; - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id,'',0,0,$user->rights->tax->charges->creer,50,$object); - - - // List of document - //$param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'tax',$param); - + $modulepart = 'tax'; + $permission = $user->rights->tax->charges->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 1dba64f57d7..c29d3b3186c 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -4,6 +4,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,28 +75,9 @@ $modulepart='contract'; /* - * Action envoie fichier + * Actions */ -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id) - { - $langs->load("other"); - - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -140,24 +122,10 @@ if ($object->id) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } - - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->contrat->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'contract',$param); + $modulepart = 'contract'; + $permission = $user->rights->contrat->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 92120f1f8bb..aea0a5909cb 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2010-2012 Regis Houssin * Copyright (c) 2010 Juanjo Menent * Copyright (c) 2013 Charles-Fr BENKE + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -155,6 +156,30 @@ class FormFile if (empty($sectionid)) $out .= '
'; $out .= "\n\n\n"; + $langs->load('link'); + $title = $langs->trans("LinkANewFile"); + $out .= load_fiche_titre($title, null, null); + $out .= '
'; + $out .= ''; + $out .= ''; + $out .= ''; + + $out .= ''; + $out .= ''; + $out .= ''; + $out .= '
'; + $out .= $langs->trans("Link") . ': '; + $out .= ''; + $out .= '   ' . $langs->trans("Label") . ': '; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':''); + $out .= '>'; + $out .= '
'; + + $out .= '

'; $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm); $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object); if (empty($res)) @@ -993,6 +1018,126 @@ class FormFile include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php'; } + + public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null) + { + + global $user, $conf, $langs, $user; + global $bc; + global $sortfield, $sortorder; + + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $link = new Link($this->db); + $links = array(); + if ($sortfield == "name") { + $sortfield = "label"; + } elseif ($sortfield == "date") { + $sortfield = "datea"; + } else { + $sortfield = null; + } + $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder); + $param = (isset($object->id)?'&id=' . $object->id : ''); + + // Show list of associated links + print_titre($langs->trans("LinkedFiles")); + print ''; + print ''; + print_liste_field_titre( + $langs->trans("Documents2"), + $_SERVER['PHP_SELF'], + "name", + "", + $param, + 'align="left"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("Size"), + "", + "", + "", + "", + 'align="right"' + ); + print_liste_field_titre( + $langs->trans("Date"), + $_SERVER['PHP_SELF'], + "date", + "", + $param, + 'align="center"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + '', + $_SERVER['PHP_SELF'], + "", + "", + $param, + 'align="center"' + ); + print_liste_field_titre('','',''); + print ''; + $nboflinks = count($links); + if ($nboflinks > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; + } + + $var = true; + foreach ($links as $link) { + $var =! $var; + print ''; + //edit mode + if ($action == 'update' && $selected === $link->id) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + else { + print '\n"; + print ''; + print ''; + print ''; + print '"; + } + print "\n"; + } + if ($nboflinks == 0) { + print ''; + } + print "
'; + print $langs->trans('Link') . ': '; + print ''; + print $langs->trans('Label') . ': '; + print '' . dol_print_date(dol_now(), "dayhour", "tzuser") . ''; + print ''; + print ''; + print $link->label; + print ''; + print "' . dol_print_date($link->datea, "dayhour", "tzuser") . ''; + print '' . img_edit().''; + if ($permtodelete) { + print '' . img_delete() . ''; + } else { + print ' '; + } + print "
'; + print $langs->trans("NoLinkFound"); + print '
"; + + return $nboflinks; + } } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b2a19b2dfeb..b64f403b758 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -995,9 +995,10 @@ function dol_init_file_process($pathtoscan='') * @param int $donotupdatesession 1=Do no edit _SESSION variable * @param string $varfiles _FILES var name * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' + * @param string $link Link to add * @return void */ -function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='') +function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null) { global $db,$user,$conf,$langs; @@ -1054,6 +1055,23 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } } + } elseif ($link) { + if (dol_mkdir($upload_dir) >= 0) { + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $linkObject = new Link($db); + $linkObject->entity = $conf->entity; + $linkObject->url = $link; + $linkObject->objecttype = GETPOST('objecttype', 'alpha'); + $linkObject->objectid = GETPOST('objectid', 'int'); + $linkObject->label = GETPOST('label', 'alpha'); + $res = $linkObject->create($user); + $langs->load('link'); + if ($res > 0) { + setEventMessage($langs->trans("LinkComplete")); + } else { + setEventMessage($langs->trans("ErrorFileNotLinked"), 'errors'); + } + } } else { diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php new file mode 100644 index 00000000000..201355e60fe --- /dev/null +++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php @@ -0,0 +1,63 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + + +/* + * Confirm suppression + */ +if ($action == 'delete') { + $ret = $form->form_confirm( + $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&urlfile=' . urlencode(GETPOST("urlfile")) . '&linkid=' . GETPOST('linkid', 'int'), + $langs->trans('DeleteFile'), + $langs->trans('ConfirmDeleteFile'), + 'confirm_deletefile', + '', + 0, + 1 + ); + if ($ret == 'html') print '
'; +} + +$formfile=new FormFile($db); + +// Show upload form +$formfile->form_attach_new_file( + $_SERVER["PHP_SELF"].'?id='.$object->id, + '', + 0, + 0, + $permission, + 50, + $object +); + +// List of document +$formfile->list_of_documents( + $filearray, + $object, + $modulepart, + $param, + 0, + '', + $permission +); + +print "
"; +//List of links +$formfile->listOfLinks($object, $permission, $action, GETPOST('linkid', 'int')); +print "
"; diff --git a/htdocs/core/tpl/document_actions_pre_headers.tpl.php b/htdocs/core/tpl/document_actions_pre_headers.tpl.php new file mode 100644 index 00000000000..18b7c18c4a5 --- /dev/null +++ b/htdocs/core/tpl/document_actions_pre_headers.tpl.php @@ -0,0 +1,88 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + + +// 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) { + $link = GETPOST('link', 'alpha'); + if ($link) { + if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') { + $link = 'http://' . $link; + } + dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link); + } + } +} + + +// 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); + $langs->load('link'); + if ($res) { + setEventMessage($langs->trans("LinkRemoved", $link->label)); + } else { + setEventMessage($langs->trans("ErrorFailedToDeleteLink", $link->label), 'errors'); + } + } + header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha')) { + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $langs->load('link'); + $link = new Link($db); + $link->id = GETPOST('linkid', 'int'); + $f = $link->fetch(); + if ($f) { + $link->url = GETPOST('link', 'alpha'); + if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://') { + $link->url = 'http://' . $link->url; + } + $link->label = GETPOST('label', 'alpha'); + $res = $link->update($user); + if (!$res) { + setEventMessage($langs->trans("ErrorFailedToUpdateLink", $link->label)); + } + } else { + //error fetching + } +} + diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 30349e5bc09..76fff7b9834 100644 --- a/htdocs/fichinter/document.php +++ b/htdocs/fichinter/document.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,29 +72,7 @@ $modulepart='fichinter'; * Actions */ -if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -else if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id > 0) - { - $langs->load("other"); - $object->fetch_thirdparty(); - - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -141,23 +120,10 @@ if ($object->id) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id,'',0,0,$user->rights->ficheinter->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'ficheinter',$param); + $modulepart = 'ficheinter'; + $permission = $user->rights->ficheinter->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php index 63c5a43f912..6816696ba36 100644 --- a/htdocs/fourn/commande/document.php +++ b/htdocs/fourn/commande/document.php @@ -4,6 +4,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos García + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -77,26 +78,7 @@ $object->fetch_thirdparty(); * Actions */ -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -else if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id > 0) - { - $langs->load("other"); - - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -176,23 +158,11 @@ if ($object->id > 0) print "\n"; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - - } + $modulepart = 'commande_fournisseur'; + $permission = $user->rights->fournisseur->commande->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id,'',0,0,$user->rights->fournisseur->commande->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'commande_fournisseur',$param); } else { diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index d75b81f402a..f170b29330a 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,29 +72,7 @@ if ($object->fetch($id, $ref)) * Actions */ -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - if ($object->id > 0) - { - dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask')); - } -} - -// Delete -else if ($action == 'confirm_deletefile' && $confirm == 'yes') -{ - if ($object->id > 0) - { - $langs->load("other"); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -198,17 +177,10 @@ if ($object->id > 0) print ''; print ''; - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id, '', 0, 0, $user->rights->fournisseur->facture->creer, 50, $object, '', 0, dol_sanitizeFileName($object->ref.'_'.$object->ref_supplier.'___file__')); - - - // List of document - $param='&facid='.$object->id; - $ref=dol_sanitizeFileName($object->ref); - $formfile->list_of_documents($filearray,$object,'facture_fournisseur',$param,0,get_exdir($object->id,2,0).$ref.'/'); - + $modulepart = 'facture_fournisseur'; + $permission = $user->rights->fournisseur->facture->creer; + $param = '&facid=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { @@ -218,4 +190,4 @@ else llxFooter(); $db->close(); -?> \ No newline at end of file +?> diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql index 9c317efb6e4..81a61afbd81 100755 --- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql +++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql @@ -90,6 +90,17 @@ create table llx_categorie_contact import_key varchar(14) )ENGINE=innodb; +create table llx_links +( + rowid INTEGER AUTO_INCREMENT PRIMARY KEY, + entity INTEGER DEFAULT 1 NOT NULL, -- multi company id + datea DATETIME NOT NULL, -- date start + url VARCHAR(255) NOT NULL, -- link url + label VARCHAR(255) NOT NULL, -- link label + objecttype VARCHAR(255) NOT NULL, -- object type in Dolibarr + objectid INTEGER NOT NULL +)ENGINE=innodb; + ALTER TABLE llx_categorie_contact ADD PRIMARY KEY pk_categorie_contact (fk_categorie, fk_socpeople); ALTER TABLE llx_categorie_contact ADD INDEX idx_categorie_contact_fk_categorie (fk_categorie); diff --git a/htdocs/install/mysql/tables/llx_links.sql b/htdocs/install/mysql/tables/llx_links.sql new file mode 100644 index 00000000000..4d4ab401ba4 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_links.sql @@ -0,0 +1,30 @@ +-- ======================================================================== +-- Copyright (C) 2013 Cédric Salvador +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- +-- Actions commerciales +-- ======================================================================== + +create table llx_links +( + rowid INTEGER AUTO_INCREMENT PRIMARY KEY, + entity INTEGER DEFAULT 1 NOT NULL, -- multi company id + datea DATETIME NOT NULL, -- date start + url VARCHAR(255) NOT NULL, -- link url + label VARCHAR(255) NOT NULL, -- link label + objecttype VARCHAR(255) NOT NULL, -- object type in Dolibarr + objectid INTEGER NOT NULL +)ENGINE=innodb; diff --git a/htdocs/langs/en_US/link.lang b/htdocs/langs/en_US/link.lang new file mode 100644 index 00000000000..8b1efb75ef3 --- /dev/null +++ b/htdocs/langs/en_US/link.lang @@ -0,0 +1,8 @@ +LinkANewFile=Link a new file/document +LinkedFiles=Linked files and documents +NoLinkFound=No registered links +LinkComplete=The file has been linked successfully +ErrorFileNotLinked=The file could not be linked +LinkRemoved=The link %s has been removed +ErrorFailedToDeleteLink= Failed to remove link '%s' +ErrorFailedToUpdateLink= Failed to update link '%s' diff --git a/htdocs/langs/fr_FR/link.lang b/htdocs/langs/fr_FR/link.lang new file mode 100644 index 00000000000..fb474eb7a59 --- /dev/null +++ b/htdocs/langs/fr_FR/link.lang @@ -0,0 +1,9 @@ +CHARSET=UTF-8 +LinkANewFile=Lier un nouveau fichier/document +LinkedFiles=Fichiers et documents liés +NoLinkFound=Aucun lien associé +LinkComplete=Le fichier a été correctement lié +ErrorFileNotLinked=Le fichier n'a pas pu être lié +LinkRemoved=Le lien %s a été supprimé +ErrorFailedToDeleteLink= Impossible de supprimer le lien '%s' +ErrorFailedToUpdateLink= Impossible de modifier le lien '%s' diff --git a/htdocs/link/class/link.class.php b/htdocs/link/class/link.class.php new file mode 100644 index 00000000000..fb924eeec9d --- /dev/null +++ b/htdocs/link/class/link.class.php @@ -0,0 +1,365 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/link/class/link.class.php + * \ingroup link + * \brief File for link class + */ +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** + * Class to manage links + */ +class Link extends CommonObject +{ + public $element = 'link'; + public $table_element = 'links'; + + public $id; + public $entity; + public $datea; + public $url; + public $label; + public $objecttype; + public $objectid; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + global $conf; + + $this->db = $db; + + return 1; + } + + + /** + * Create link in database + * + * @param User $user Object of user that ask creation + * @return int >= 0 if OK, < 0 if KO + */ + public function create($user='') + { + global $langs,$conf; + + $error=0; + $langs->load("errors"); + // Clean parameters + if (empty($this->label)) { + $this->label = trim(basename($this->url)); + } + if (empty($this->datea)) { + $this->datea = dol_now(); + } + $this->url = trim($this->url); + + dol_syslog(get_class($this)."::create ".$this->url); + + // Check parameters + if (empty($this->url)) { + $this->error = $langs->trans("NoUrl"); + return -1; + } + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."links (entity, datea, url, label, objecttype, objectid)"; + $sql .= " VALUES ('".$conf->entity."', '".$this->db->idate($this->datea)."'"; + $sql .= ", '" . $this->db->escape($this->url) . "'"; + $sql .= ", '" . $this->db->escape($this->label) . "'"; + $sql .= ", '" . $this->objecttype . "'"; + $sql .= ", " . $this->objectid . ")"; + + dol_syslog(get_class($this)."::create sql=".$sql); + $result = $this->db->query($sql); + if ($result) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "links"); + + if ($this->id > 0) { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LINK_CREATE', $this, $user, $langs, $conf); + if ($result < 0) { + $error++; + $this->errors = $interface->errors; + } + // Fin appel triggers + } else { + $error++; + } + + if (! $error) + { + dol_syslog(get_class($this)."::Create success id=" . $this->id); + $this->db->commit(); + return $this->id; + } + else + { + dol_syslog(get_class($this)."::Create echec update " . $this->error, LOG_ERR); + $this->db->rollback(); + return -3; + } + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + + $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); + $result=-1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::Create fails insert sql=".$sql, LOG_ERR); + $result=-2; + } + $this->db->rollback(); + return $result; + } + } + + /** + * Update parameters of third party + * + * @param User $user User executing update + * @param int $call_trigger 0=no, 1=yes + * @return int <0 if KO, >=0 if OK + */ + public function update($user='', $call_trigger=1) + { + global $langs,$conf; + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $langs->load("errors"); + $error=0; + + dol_syslog(get_class($this)."::Update id = " . $this->id . " call_trigger = " . $call_trigger); + + // Check parameters + if (empty($this->url)) { + $this->error = $langs->trans("NoURL"); + return -1; + } + + // Clean parameters + $this->url = clean_url($this->url,0); + if(empty($this->label)) { + $this->label = basename($this->url); + } + $this->label = trim($this->label); + + + $this->db->begin(); + + $sql = "UPDATE " . MAIN_DB_PREFIX . "links SET "; + $sql .= "entity = '" . $conf->entity ."'"; + $sql .= ", datea = '" . $this->db->idate(dol_now()) . "'"; + $sql .= ", url = '" . $this->db->escape($this->url) . "'"; + $sql .= ", label = '" . $this->db->escape($this->label) . "'"; + $sql .= ", objecttype = '" . $this->objecttype . "'"; + $sql .= ", objectid = " . $this->objectid; + $sql .= " WHERE rowid = '" . $this->id ."'"; + + + dol_syslog(get_class($this)."::Update sql = " .$sql); + $resql = $this->db->query($sql); + if ($resql) + { + if ($call_trigger) { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface = new Interfaces($this->db); + $result = $interface->run_triggers('LINK_MODIFY', $this, $user, $langs, $conf); + if ($result < 0) { + $error++; + $this->errors = $interface->errors; + } + // Fin appel triggers + } + + if (! $error) { + dol_syslog(get_class($this) . "::Update success"); + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return -1; + } + } else { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + // Doublon + $this->error = $langs->trans("ErrorDuplicateField"); + $result = -1; + } else { + $this->error = $langs->trans("Error sql = " . $sql); + dol_syslog(get_class($this) . "::Update fails update sql = " . $sql, LOG_ERR); + $result = -2; + } + $this->db->rollback(); + return $result; + } + } + + /** + * Loads all links from database + * + * @param array &$links array of Link objects to fill + * @param string $objecttype type of the associated object in dolibarr + * @param int $objectid id of the associated object in dolibarr + * @param string $sortfield field used to sort + * @param string $sortorder sort order + * @return 1 if ok, 0 if no records, -1 if error + * + * */ + public function fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null) + { + global $conf; + $sql = "SELECT rowid, entity, datea, url, label , objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; + $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid; + if($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; + if ($sortfield) { + if (empty($sortorder)) { + $sortorder = "ASC"; + } + $sql .= " ORDER BY " . $sortfield . " " . $sortorder; + } + $resql = $this->db->query($sql); + dol_syslog(get_class($this)."::fetchAll " . $sql, LOG_DEBUG); + if ($resql) { + $num = $this->db->num_rows($resql); + dol_syslog(get_class($this)."::fetchAll " . $num . "records", LOG_DEBUG); + if ($num > 0) { + while ($obj = $this->db->fetch_object($resql)) { + $link = new Link($db); + $link->id = $obj->rowid; + $link->entity = $obj->entity; + $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; + } else { + return 0; + } + } else { + dol_syslog(get_class($this) . "::FetchAll fails sql=" . $sql, LOG_ERR); + return -1; + } + } + + /* + * Loads a link from database + * @param rowid id of link to load + * @return int 1 if ok, 0 if no record found, -1 if error + * + * */ + public function fetch($rowid=null) + { + global $conf; + if (empty($rowid)) { + $rowid = $this->id; + } + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; + $sql .= " WHERE rowid = " . $rowid; + if($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; + $resql = $this->db->query($sql); + dol_syslog(get_class($this)."::fetch " . $sql, LOG_DEBUG); + if ($resql) { + if($this->db->num_rows($resql) > 0) { + $obj = $this->db->fetch_object($resql); + $this->entity = $obj->entity; + $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; + dol_syslog($this->error, LOG_ERR); + return 0; + } + } else { + dol_syslog($this->db->error(), LOG_ERR); + $this->error=$this->db->error(); + return -1; + } + } + + /** + * Delete a link from database + * + * @return int <0 if KO, 0 if nothing done, >0 if OK + */ + public function delete() + { + global $user, $langs, $conf; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $error = 0; + + $this->db->begin(); + + // Remove link + + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "links"; + $sql.= " WHERE rowid = " . $this->id; + dol_syslog(get_class($this)."::delete sql=" . $sql, LOG_DEBUG); + if (! $this->db->query($sql)) { + $error++; + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this)."::delete error -4 " . $this->error, LOG_ERR); + } + + + if (! $error) { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result = $interface->run_triggers('LINK_DELETE', $this, $user, $langs, $conf); + if ($result < 0) { + $error++; + $this->errors = $interface->errors; + } + // Fin appel triggers + } + + if (! $error) { + $this->db->commit(); + + return 1; + } else { + $this->db->rollback(); + return -1; + } + + } + +} diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 22de2273820..4a5d1691613 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,22 +81,7 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); * Action envoie fichier */ -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -if ($action=='delete') -{ - $langs->load("other"); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -154,15 +140,10 @@ if ($object->id) print ''; - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$object->id,'',0,0,($user->rights->produit->creer||$user->rights->service->creer),50,$object); - - - // List of document - $formfile->list_of_documents($filearray,$object,'produit'); - + $modulepart = 'produit'; + $permission = $user->rights->produit->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php index 66ffc0443b0..89fc9549156 100644 --- a/htdocs/projet/document.php +++ b/htdocs/projet/document.php @@ -1,6 +1,7 @@ * Copyright (C) 2012 Laurent Destailleur + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +50,7 @@ $object->fetch($id,$ref); if ($object->id > 0) { $object->fetch_thirdparty(); + $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); } // Get parameters @@ -68,25 +70,7 @@ if (! $sortfield) $sortfield="name"; * Actions */ -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->projet->supprimer) -{ - $langs->load("other"); - $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -120,11 +104,6 @@ if ($object->id > 0) $totalsize+=$file['size']; } - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&urlfile=".urlencode(GETPOST("urlfile")),$langs->trans("DeleteAFile"),$langs->trans("ConfirmDeleteAFile"),"confirm_delete",'','',1); - } - print ''; $linkback = ''.$langs->trans("BackToList").''; @@ -165,14 +144,10 @@ if ($object->id > 0) print "
\n"; print "\n"; - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/document.php?id='.$object->id,'',0,0,($userWrite>0),50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'projet',$param,0,'',($userWrite>0)); + $modulepart = 'projet'; + $permission = ($userWrite > 0); + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index 90adc2925c2..8dd80223e6c 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -1,7 +1,8 @@ +/* Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2006-2012 Laurent Destailleur - * Copyright (C) 2012 Florian Henry + * Copyright (C) 2012 Florian Henry + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -107,23 +108,7 @@ if ($id > 0 || ! empty($ref)) } } -// Envoi fichier -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - dol_add_file_process($upload_dir,0,1,'userfile'); -} - -// Delete -if ($action=='delete') -{ - $langs->load("other"); - $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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* * View @@ -244,15 +229,10 @@ if ($object->id > 0) print '
'; - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.($withproject?'&withproject=1':''),'',0,0,$user->rights->projet->creer,50,$object); - - - // List of document - $param='&id='.$object->id; - $formfile->list_of_documents($filearray,$object,'projet',$param,0,dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/'); + $modulepart = 'projet'; + $permission = $user->rights->projet->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 4a14c58dd9b..1da45c36c8f 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,31 +73,7 @@ if ($id > 0 || ! empty($ref)) * Actions */ -// TODO Use an include to mutualize this code for action sendit and confirm_deletefile - -// Post file -if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) -{ - if ($object->id) - { - dol_add_file_process($upload_dir,0,1,'userfile'); - } -} - -// 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'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } -} +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -172,23 +149,10 @@ if ($object->id) print ''; - /* - * Confirmation suppression fichier - */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); - } - - $formfile=new FormFile($db); - - // Show upload form - $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,'',0,0,$user->rights->societe->creer,50,$object); - - // List of document - $formfile->list_of_documents($filearray,$object,'societe'); - - print "

"; + $modulepart = 'societe'; + $permission = $user->rights->societe->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else {