From 23008c3b318df9eeea6514be29c5427259173f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 25 Jul 2013 18:35:48 +0200 Subject: [PATCH 01/31] factorized document actions Conflicts: htdocs/societe/document.php --- htdocs/adherents/document.php | 37 +++++++--------------- htdocs/comm/action/document.php | 22 ++----------- htdocs/comm/propal/document.php | 29 ++---------------- htdocs/commande/document.php | 39 ++++++------------------ htdocs/compta/deplacement/document.php | 25 ++------------- htdocs/compta/facture/document.php | 36 +++++----------------- htdocs/compta/sociales/document.php | 14 ++------- htdocs/contrat/document.php | 23 ++------------ htdocs/core/tpl/document_actions.tpl.php | 35 +++++++++++++++++++++ htdocs/fichinter/document.php | 24 +-------------- htdocs/fourn/commande/document.php | 22 ++----------- htdocs/fourn/facture/document.php | 26 ++-------------- htdocs/product/document.php | 18 ++--------- htdocs/projet/document.php | 22 ++----------- htdocs/projet/tasks/document.php | 23 +++----------- htdocs/societe/document.php | 27 ++-------------- 16 files changed, 90 insertions(+), 332 deletions(-) create mode 100644 htdocs/core/tpl/document_actions.tpl.php diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php index f1a5894a78e..f084164efe3 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.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) { diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index 7f50eaabd7e..e73fddb7574 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 @@ -79,26 +80,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.tpl.php'; /* diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php index 3d6bc97319b..266ee77b7d9 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.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; - } -} /* diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index 0f2925cf455..32e666d1a7b 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.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,7 +119,7 @@ if ($id > 0 || ! empty($ref)) print "\n"; print "\n"; - /* + /* * Confirmation suppression fichier */ if ($action == 'delete') diff --git a/htdocs/compta/deplacement/document.php b/htdocs/compta/deplacement/document.php index 26cdf746f46..93258ab2297 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.tpl.php'; /* diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 8aae07746e9..92292375ac4 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.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 diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php index 452de21285a..dcef5eb1561 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 @@ -71,18 +72,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.tpl.php'; /* diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 1dba64f57d7..2c9e4b42166 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -74,28 +74,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.tpl.php'; /* diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php new file mode 100644 index 00000000000..576e6139639 --- /dev/null +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -0,0 +1,35 @@ +global->MAIN_UPLOAD_DOC)) +{ + if ($object->id) + { + dol_add_file_process($upload_dir,0,1,'userfile'); + } +} +//test code for the link feature, need to mutualize it to avoid copy/paste on every document page +elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { + if ($object->id) { + $link = GETPOST('link', 'alpha'); + if (!strpos(substr($link, 0, 7), 'http://') && !strpos(substr($link, 0, 8), 'https://')) { + $link = 'http://' . $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'); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } +} +?> diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 30349e5bc09..6638d031651 100644 --- a/htdocs/fichinter/document.php +++ b/htdocs/fichinter/document.php @@ -71,29 +71,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.tpl.php'; /* diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php index 63c5a43f912..581fac2df66 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.tpl.php'; /* diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index d75b81f402a..3e288899d1d 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -71,29 +71,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.tpl.php'; /* @@ -218,4 +196,4 @@ else llxFooter(); $db->close(); -?> \ No newline at end of file +?> diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 22de2273820..9aefbe18dad 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.tpl.php'; /* diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php index 66ffc0443b0..84c9f1e109c 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.tpl.php'; /* diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index 90adc2925c2..1a01958b230 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.tpl.php'; /* * View diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 4a14c58dd9b..27e01eec7bc 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.tpl.php'; /* From 3f774adbd01ffab8dae8000908d02e671df75dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 14:22:19 +0200 Subject: [PATCH 02/31] form to link a file --- htdocs/core/class/html.formfile.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 92120f1f8bb..c74e35d31f6 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -155,6 +155,24 @@ class FormFile if (empty($sectionid)) $out .= '
'; $out .= "\n\n\n"; + $title = $langs->trans("LinkANewFile"); + $out .= load_fiche_titre($title, null, null); + $out .= '
'; + $out .= ''; + $out .= ''; + $out .= ''; + + $out .= ''; + $out .= ''; + $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)) From 26aa0c1d7ac94db995ba9cafb8cb80f9c7bb319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 14:32:48 +0200 Subject: [PATCH 03/31] links sql table --- .../install/mysql/migration/3.4.0-3.5.0.sql | 9 ++++++ htdocs/install/mysql/tables/llx_links.sql | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 htdocs/install/mysql/tables/llx_links.sql 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..bd8bd66cca1 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,15 @@ create table llx_categorie_contact import_key varchar(14) )ENGINE=innodb; +create table llx_links +( + id 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 +)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..8dd77d18784 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_links.sql @@ -0,0 +1,28 @@ +-- ======================================================================== +-- 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 +( + id 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 +)ENGINE=innodb; From 06af0733e92d30ab2b079c6dd2a9bfcf21f7baba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 16:17:43 +0200 Subject: [PATCH 04/31] rename parameter to rowid --- htdocs/install/mysql/tables/llx_links.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_links.sql b/htdocs/install/mysql/tables/llx_links.sql index 8dd77d18784..f25f7117f17 100644 --- a/htdocs/install/mysql/tables/llx_links.sql +++ b/htdocs/install/mysql/tables/llx_links.sql @@ -20,7 +20,7 @@ create table llx_links ( - id INTEGER AUTO_INCREMENT PRIMARY KEY, + 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 From d47bb95b5611161acc21bb2c38da58d95bdc377c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 16:37:49 +0200 Subject: [PATCH 05/31] bugfix --- htdocs/core/tpl/document_actions.tpl.php | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index 576e6139639..d41df448333 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -2,34 +2,35 @@ // Envoi fichier if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($object->id) - { - dol_add_file_process($upload_dir,0,1,'userfile'); - } -} -//test code for the link feature, need to mutualize it to avoid copy/paste on every document page -elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($object->id) { + 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 (!strpos(substr($link, 0, 7), 'http://') && !strpos(substr($link, 0, 8), 'https://')) { + 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). + 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; - } + $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; + } } -?> + From 84d0ab47f8e9cf6cdf8038ef36588c234acc3a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 16:44:21 +0200 Subject: [PATCH 06/31] Link class with CRUD methods --- htdocs/link/class/link.class.php | 339 +++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 htdocs/link/class/link.class.php diff --git a/htdocs/link/class/link.class.php b/htdocs/link/class/link.class.php new file mode 100644 index 00000000000..5d7ce2dcf91 --- /dev/null +++ b/htdocs/link/class/link.class.php @@ -0,0 +1,339 @@ + + * + * 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; + + /** + * 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)"; + $sql .= " VALUES ('".$conf->entity."', '".$this->db->idate($this->datea)."'"; + $sql .= ", '" . $this->db->escape($this->url) . "'"; + $sql .= ", '" . $this->db->escape($this->label) . "')"; + + 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 .= " 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 + * @return array of Link objects + * + * */ + public function fetchAll() + { + $sql = "SELECT rowid, entity, datea, url, label FROM " . MAIN_DB_PREFIX . "links"; + $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) { + $links = array(); + 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; + $links[] = $link; + } + return $links; + } 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) + { + if (empty($rowid)) { + $rowid = $this->id; + } + $sql = "SELECT rowid, entity, datea, url, label FROM " . MAIN_DB_PREFIX . "links"; + $sql .= " WHERE rowid = " . $rowid; + $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; + 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; + } + + } + +} From e8e37526269666321d8fde5fe05f8ff4138e8799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 16:47:47 +0200 Subject: [PATCH 07/31] link creation in dol_add_file_process --- htdocs/core/lib/files.lib.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b2a19b2dfeb..616bd3f60d5 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -997,7 +997,7 @@ function dol_init_file_process($pathtoscan='') * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' * @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,7 +1054,20 @@ 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; + $res = $linkObject->create($user); + if ($res) { + setEventMessage($langs->trans("LinkComplete")); + } else { + setEventMessage($langs->trans("ErrorFileNotLinked"), 'errors'); + } + } + } else { $langs->load("errors"); From ae8fea2615b5e4f8111e797fef050cc5c939d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 18:34:21 +0200 Subject: [PATCH 08/31] new attributes --- htdocs/install/mysql/tables/llx_links.sql | 4 ++- htdocs/link/class/link.class.php | 39 +++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_links.sql b/htdocs/install/mysql/tables/llx_links.sql index f25f7117f17..4d4ab401ba4 100644 --- a/htdocs/install/mysql/tables/llx_links.sql +++ b/htdocs/install/mysql/tables/llx_links.sql @@ -24,5 +24,7 @@ create table llx_links 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 + 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/link/class/link.class.php b/htdocs/link/class/link.class.php index 5d7ce2dcf91..cd2e714e57a 100644 --- a/htdocs/link/class/link.class.php +++ b/htdocs/link/class/link.class.php @@ -36,6 +36,8 @@ class Link extends CommonObject public $datea; public $url; public $label; + public $objecttype; + public $objectid; /** * Constructor @@ -83,10 +85,12 @@ class Link extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."links (entity, datea, url, label)"; + $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->db->escape($this->label) . "'"; + $sql .= ", '" . $this->objecttype . "'"; + $sql .= ", " . $this->objectid . ")"; dol_syslog(get_class($this)."::create sql=".$sql); $result = $this->db->query($sql); @@ -174,8 +178,10 @@ class Link extends CommonObject $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 .= ", 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 ."'"; @@ -220,19 +226,30 @@ class Link extends CommonObject /** * Loads all links from database - * @return array of Link objects + * @param $links array of Link objects to fill + * @param $objecttype type of the associated object in dolibarr + * @param $objectid id of the associated object in dolibarr + * @return 1 if ok, 0 if no records, -1 if error * * */ - public function fetchAll() + public function fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null) { - $sql = "SELECT rowid, entity, datea, url, label FROM " . MAIN_DB_PREFIX . "links"; + 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) { - $links = array(); while ($obj = $this->db->fetch_object($resql)) { $link = new Link($db); $link->id = $obj->rowid; @@ -242,7 +259,7 @@ class Link extends CommonObject $link->label = $obj->label; $links[] = $link; } - return $links; + return 1; } else { return 0; } @@ -260,11 +277,13 @@ class Link extends CommonObject * */ public function fetch($rowid=null) { + global $conf; if (empty($rowid)) { $rowid = $this->id; } - $sql = "SELECT rowid, entity, datea, url, label FROM " . MAIN_DB_PREFIX . "links"; + $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) { From 3529f5238b94eb24745c40c3bf0e42ca65f2205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 29 Jul 2013 18:34:43 +0200 Subject: [PATCH 09/31] display links --- htdocs/core/class/html.formfile.class.php | 81 +++++++++++++++++++++++ htdocs/core/lib/files.lib.php | 5 +- htdocs/societe/document.php | 5 +- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index c74e35d31f6..ea4f0b29d76 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -166,6 +166,8 @@ class FormFile $out .= ''; $out .= ''; $out .= ''; + $out .= ''; + $out .= ''; $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':''); $out .= '>'; @@ -1011,6 +1013,85 @@ class FormFile include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php'; } + + public function list_of_links($object, $permtodelete=1) + { + + global $user, $conf, $langs, $hookmanager, $user; + global $bc; + global $sortfield, $sortorder, $maxheightmini; + + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $link = new Link($this->db); + $links = array(); + //HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXX + 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:'').$param; + + // Show list of associated links + 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="center"'); + print_liste_field_titre($langs->trans("Date"),$_SERVER['PHP_SELF'],"date","",$param,'align="center"',$sortfield,$sortorder); + if (empty($useinecm)) 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 ''; + print '\n"; + print ''; + print ''; + // Preview + /*if (empty($useinecm)) + { + print ''; + }*/ + print ''; + // Delete or view link + // ($param must start with &) + print '"; + print "\n"; + } + if ($nboflinks == 0) + { + print ''; + } + print "
'; + //print "XX".$file['name']; //$file['name'] must be utf8 + print ''; + print $link->label; + print ''; + print " '.dol_print_date($link->datea, "dayhour", "tzuser").''; + $tmp=explode('.',$file['name']); + $minifile=$tmp[0].'_mini.'.$tmp[1]; + if (image_format_supported($file['name']) > 0) print ''; + else print ' '; + print ' '; + if ($permtodelete) print ''.img_delete().''; + else print ' '; + print "
'; + if (empty($textifempty)) print $langs->trans("NoLinkFound"); + else print $textifempty; + print '
"; + + return $nboflinks; + } } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 616bd3f60d5..fdcb65bc859 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1055,13 +1055,16 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } } elseif ($link) { + var_dump($_POST); 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'); $res = $linkObject->create($user); - if ($res) { + if ($res > 0) { setEventMessage($langs->trans("LinkComplete")); } else { setEventMessage($langs->trans("ErrorFileNotLinked"), 'errors'); diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 27e01eec7bc..6ddf67c2133 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -162,10 +162,13 @@ if ($object->id) // Show upload form $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,'',0,0,$user->rights->societe->creer,50,$object); + //TODO FACTORIZE THIS // List of document $formfile->list_of_documents($filearray,$object,'societe'); - print "

"; + print "
"; + $formfile->list_of_links($object); + print "
"; } else { From c96b2d3b87bfff0c3741d2151b8536deff3e88e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 16:44:47 +0200 Subject: [PATCH 10/31] factorized form attach, documents list and links list for the document pages --- htdocs/comm/action/document.php | 18 +++++-------- htdocs/compta/sociales/document.php | 15 ++++------- htdocs/contrat/document.php | 1 + htdocs/core/tpl/doc2.tpl.php | 42 +++++++++++++++++++++++++++++ htdocs/fichinter/document.php | 1 + htdocs/fourn/facture/document.php | 1 + htdocs/product/document.php | 13 +++------ htdocs/projet/tasks/document.php | 9 ++++--- 8 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 htdocs/core/tpl/doc2.tpl.php diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index e73fddb7574..741db311e20 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -41,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'); @@ -252,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/doc2.tpl.php'; } else { diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php index dcef5eb1561..c13618691fd 100644 --- a/htdocs/compta/sociales/document.php +++ b/htdocs/compta/sociales/document.php @@ -41,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; @@ -159,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/doc2.tpl.php'; } else { diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 2c9e4b42166..b63679cc1de 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 diff --git a/htdocs/core/tpl/doc2.tpl.php b/htdocs/core/tpl/doc2.tpl.php new file mode 100644 index 00000000000..c2ac769b500 --- /dev/null +++ b/htdocs/core/tpl/doc2.tpl.php @@ -0,0 +1,42 @@ +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->list_of_links($object, $permission); +print "
"; diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 6638d031651..2dc8f7aedea 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 diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index 3e288899d1d..287708da211 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 diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 9aefbe18dad..34d12669617 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -140,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/doc2.tpl.php'; } else { diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index 1a01958b230..c5702aa54c9 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -229,15 +229,18 @@ if ($object->id > 0) print '
'; - - // Affiche formulaire upload + $modulepart = 'projet'; + $permission = $user->rights->projet->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + /*// 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).'/'); + $formfile->list_of_documents($filearray,$object,'projet',$param,0,dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/');*/ } else { From 28bfb10dbde5e5ec86f8d1253a18b153f8e07b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 16:46:18 +0200 Subject: [PATCH 11/31] UI --- htdocs/core/class/html.formfile.class.php | 12 +++++++----- htdocs/core/lib/files.lib.php | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index ea4f0b29d76..03fcd480d27 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1036,10 +1036,11 @@ class FormFile $param = (isset($object->id)?'&id='.$object->id:'').$param; // Show list of associated links + if (empty($useinecm)) 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="center"'); + 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); if (empty($useinecm)) print_liste_field_titre('',$_SERVER['PHP_SELF'],"","",$param,'align="center"'); print_liste_field_titre('','',''); @@ -1060,7 +1061,7 @@ class FormFile print $link->label; print ''; print "\n"; - print ''; + print ''; print ''; // Preview /*if (empty($useinecm)) @@ -1072,11 +1073,12 @@ class FormFile else print ' '; print ''; }*/ - print ''; + print ''; // Delete or view link // ($param must start with &) - print '"; print "\n"; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index fdcb65bc859..05da680aea2 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1055,7 +1055,6 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } } elseif ($link) { - var_dump($_POST); if (dol_mkdir($upload_dir) >= 0) { require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; $linkObject = new Link($db); From dcf051605abcddd2924b85c265d7ca2cb586cf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 16:46:41 +0200 Subject: [PATCH 12/31] delete function for links --- htdocs/core/tpl/document_actions.tpl.php | 50 +++++++++++++++--------- htdocs/link/class/link.class.php | 4 ++ 2 files changed, 35 insertions(+), 19 deletions(-) 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; From ce19b6da5ccea97330425a655e724a441040d73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 16:48:14 +0200 Subject: [PATCH 13/31] typo --- htdocs/core/tpl/document_actions.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index 706b2f4409e..bd26e13672d 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -36,7 +36,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') { $link->fetch(); $res = $link->delete($user); if ($res) { - setEventMessage($langs->trans("LinkWasRemoved", $link->label) + setEventMessage($langs->trans("LinkWasRemoved", $link->label)); } else { setEventMessage($langs->trans("ErrorFailToDeleteLink", $link->label), 'errors'); } From f19e5e86f4c4221359dd70d346220969ea438e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 17:07:02 +0200 Subject: [PATCH 14/31] don't try to create a link when the link input field is empty --- htdocs/core/tpl/document_actions.tpl.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index bd26e13672d..8ae243e47d3 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -7,10 +7,12 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { } elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { if ($object->id) { $link = GETPOST('link', 'alpha'); - if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') { - $link = 'http://' . $link; + 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', $link); } - dol_add_file_process($upload_dir, 0, 1, 'userfile', $link); } } From b625b1843e4ae0c8085867591252a7809acee0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 17:07:19 +0200 Subject: [PATCH 15/31] add a field for label input --- htdocs/core/class/html.formfile.class.php | 3 +++ htdocs/core/lib/files.lib.php | 1 + 2 files changed, 4 insertions(+) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 03fcd480d27..d866601cbcb 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -165,7 +165,10 @@ class FormFile $out .= '
 '.dol_print_date($link->datea, "dayhour", "tzuser").' '; - if ($permtodelete) print ''.img_delete().''; + print ''; + print ''.img_edit().''; + if ($permtodelete) print ''.img_delete().''; else print ' '; print "
'; $out .= ''; $out .= ''; - print '\n"; - print ''; - print ''; - // Preview - /*if (empty($useinecm)) - { - print ''; - }*/ - print ''; - // Delete or view link - // ($param must start with &) - print '"; + print ''; + print ''; + print ''; + print ''; + print ''; + } + else { + print '\n"; + print ''; + print ''; + // Preview + /*if (empty($useinecm)) + { + print ''; + }*/ + print ''; + // Delete or view link + // ($param must start with &) + print '"; + } print "\n"; } if ($nboflinks == 0) diff --git a/htdocs/core/tpl/doc2.tpl.php b/htdocs/core/tpl/doc2.tpl.php index c2ac769b500..37ec4fc1760 100644 --- a/htdocs/core/tpl/doc2.tpl.php +++ b/htdocs/core/tpl/doc2.tpl.php @@ -38,5 +38,5 @@ $formfile->list_of_documents($filearray, print "
"; //List of links -$formfile->list_of_links($object, $permission); +$formfile->list_of_links($object, $permission, $action, GETPOST('linkid', 'int')); print "
"; diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index bd8e2fde1e3..434c9e9f4ed 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -47,5 +47,24 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') { 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 + } } From 6cafe83588ad61ed751c88904e1357e5f731073f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 31 Jul 2013 16:21:38 +0200 Subject: [PATCH 18/31] translation --- htdocs/langs/en_US/link.lang | 1 + htdocs/langs/fr_FR/link.lang | 1 + 2 files changed, 2 insertions(+) diff --git a/htdocs/langs/en_US/link.lang b/htdocs/langs/en_US/link.lang index fd9589607de..8b1efb75ef3 100644 --- a/htdocs/langs/en_US/link.lang +++ b/htdocs/langs/en_US/link.lang @@ -5,3 +5,4 @@ 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 index f5a78d83f56..fb474eb7a59 100644 --- a/htdocs/langs/fr_FR/link.lang +++ b/htdocs/langs/fr_FR/link.lang @@ -6,3 +6,4 @@ 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' From b34a613504a99aece94f3f2942875330689e202f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 1 Aug 2013 10:52:21 +0200 Subject: [PATCH 19/31] code formating --- htdocs/core/class/html.formfile.class.php | 90 +++++++++++++---------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 3beb2eec1ad..97606b19379 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1021,14 +1021,13 @@ class FormFile public function list_of_links($object, $permtodelete=1, $action=null, $selected=null) { - global $user, $conf, $langs, $hookmanager, $user; + global $user, $conf, $langs, $user; global $bc; - global $sortfield, $sortorder, $maxheightmini; + global $sortfield, $sortorder; require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; $link = new Link($this->db); $links = array(); - //HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXX if ($sortfield == "name") { $sortfield = "label"; } elseif ($sortfield == "date") { @@ -1037,28 +1036,55 @@ class FormFile $sortfield = null; } $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder); - $param = (isset($object->id)?'&id='.$object->id:'').$param; + $param = (isset($object->id)?'&id=' . $object->id : ''); // Show list of associated links - if (empty($useinecm)) print_titre($langs->trans("LinkedFiles")); + print_titre($langs->trans("LinkedFiles")); print '
'; + $out .= $langs->trans("Link") . ': '; $out .= ''; + $out .= '   ' . $langs->trans("Label") . ': '; + $out .= ''; $out .= ''; $out .= ''; $out .= 'url = $link; $linkObject->objecttype = GETPOST('objecttype', 'alpha'); $linkObject->objectid = GETPOST('objectid', 'int'); + $linkObject->label = GETPOST('label', 'alpha'); $res = $linkObject->create($user); if ($res > 0) { setEventMessage($langs->trans("LinkComplete")); From b158e8bb74ebdee7233115b93bc787651ad8ee5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 30 Jul 2013 17:47:24 +0200 Subject: [PATCH 16/31] translations --- htdocs/core/class/html.formfile.class.php | 1 + htdocs/core/lib/files.lib.php | 7 ++++--- htdocs/core/tpl/document_actions.tpl.php | 5 +++-- htdocs/langs/en_US/link.lang | 7 +++++++ htdocs/langs/fr_FR/link.lang | 8 ++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 htdocs/langs/en_US/link.lang create mode 100644 htdocs/langs/fr_FR/link.lang diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index d866601cbcb..984a492aa4d 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -155,6 +155,7 @@ 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 .= '
'; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index f3e64028808..9da243dff4f 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1060,10 +1060,11 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $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'); + $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 { diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index 8ae243e47d3..bd8e2fde1e3 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -37,10 +37,11 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') { $link->id = $linkid; $link->fetch(); $res = $link->delete($user); + $langs->load('link'); if ($res) { - setEventMessage($langs->trans("LinkWasRemoved", $link->label)); + setEventMessage($langs->trans("LinkRemoved", $link->label)); } else { - setEventMessage($langs->trans("ErrorFailToDeleteLink", $link->label), 'errors'); + setEventMessage($langs->trans("ErrorFailedToDeleteLink", $link->label), 'errors'); } } header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); diff --git a/htdocs/langs/en_US/link.lang b/htdocs/langs/en_US/link.lang new file mode 100644 index 00000000000..fd9589607de --- /dev/null +++ b/htdocs/langs/en_US/link.lang @@ -0,0 +1,7 @@ +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' diff --git a/htdocs/langs/fr_FR/link.lang b/htdocs/langs/fr_FR/link.lang new file mode 100644 index 00000000000..f5a78d83f56 --- /dev/null +++ b/htdocs/langs/fr_FR/link.lang @@ -0,0 +1,8 @@ +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' From f2535d74ea5f3260077aa26be08a7dd406987b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 31 Jul 2013 16:21:24 +0200 Subject: [PATCH 17/31] edit link lines function --- htdocs/core/class/html.formfile.class.php | 73 ++++++++++++++--------- htdocs/core/tpl/doc2.tpl.php | 2 +- htdocs/core/tpl/document_actions.tpl.php | 19 ++++++ 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 984a492aa4d..3beb2eec1ad 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1018,7 +1018,7 @@ class FormFile } - public function list_of_links($object, $permtodelete=1) + public function list_of_links($object, $permtodelete=1, $action=null, $selected=null) { global $user, $conf, $langs, $hookmanager, $user; @@ -1057,34 +1057,53 @@ class FormFile $var = true; foreach($links as $link) { - $var=!$var; + $var =! $var; print '
'; - //print "XX".$file['name']; //$file['name'] must be utf8 - print ''; - print $link->label; - print ''; - print "'.dol_print_date($link->datea, "dayhour", "tzuser").''; - $tmp=explode('.',$file['name']); - $minifile=$tmp[0].'_mini.'.$tmp[1]; - if (image_format_supported($file['name']) > 0) print ''; - else print ' '; + //edit mode + if ($action == 'update' && $selected === $link->id) { + print ''; + print ''; + print ''; + print ''; + print $langs->trans('Link') . ': '; print ''; - print ''.img_edit().''; - if ($permtodelete) print ''.img_delete().''; - else print ' '; - print "'; + print $langs->trans('Label') . ': '; + print '' . dol_print_date(dol_now(), "dayhour", "tzuser") . ''; + print ''; + //print "XX".$file['name']; //$file['name'] must be utf8 + print ''; + print $link->label; + print ''; + print "'.dol_print_date($link->datea, "dayhour", "tzuser").''; + $tmp=explode('.',$file['name']); + $minifile=$tmp[0].'_mini.'.$tmp[1]; + if (image_format_supported($file['name']) > 0) print ''; + else print ' '; + print ''; + print ''.img_edit().''; + if ($permtodelete) print ''.img_delete().''; + else print ' '; + 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); - if (empty($useinecm)) print_liste_field_titre('',$_SERVER['PHP_SELF'],"","",$param,'align="center"'); + 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'; + if ($nboflinks > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; + } $var = true; - foreach($links as $link) { + foreach ($links as $link) { $var =! $var; - print ''; + print ''; //edit mode if ($action == 'update' && $selected === $link->id) { print ''; @@ -1078,39 +1104,29 @@ class FormFile } else { print '\n"; print ''; - print ''; - // Preview - /*if (empty($useinecm)) - { - print ''; - }*/ + print ''; print ''; - // Delete or view link - // ($param must start with &) print '"; } print "\n"; } - if ($nboflinks == 0) - { - print ''; } print "
'; - //print "XX".$file['name']; //$file['name'] must be utf8 print ''; print $link->label; print ''; print "'.dol_print_date($link->datea, "dayhour", "tzuser").''; - $tmp=explode('.',$file['name']); - $minifile=$tmp[0].'_mini.'.$tmp[1]; - if (image_format_supported($file['name']) > 0) print ''; - else print ' '; - print '' . dol_print_date($link->datea, "dayhour", "tzuser") . ''; - print ''.img_edit().''; - if ($permtodelete) print ''.img_delete().''; - else print ' '; + print '' . img_edit().''; + if ($permtodelete) { + print '' . img_delete() . ''; + } else { + print ' '; + } print "
'; - if (empty($textifempty)) print $langs->trans("NoLinkFound"); - else print $textifempty; + if ($nboflinks == 0) { + print '
'; + print $langs->trans("NoLinkFound"); print '
"; From 4d490ea02b7d00b49f1c6d8bcfd6d9e456d05852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 29 Aug 2013 17:18:37 +0200 Subject: [PATCH 20/31] open link in new tab --- htdocs/core/class/html.formfile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 97606b19379..275ada1ef28 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1104,7 +1104,7 @@ class FormFile } else { print ''; - print ''; + print ''; print $link->label; print ''; print "\n"; From 89f9a871d0ff1353cd37a072cb2a8a124c2937ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 9 Sep 2013 10:16:24 +0200 Subject: [PATCH 21/31] updated migration script --- htdocs/install/mysql/migration/3.4.0-3.5.0.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 bd8bd66cca1..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 @@ -92,11 +92,13 @@ create table llx_categorie_contact create table llx_links ( - id INTEGER AUTO_INCREMENT PRIMARY KEY, + 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 + label VARCHAR(255) NOT NULL, -- link label + objecttype VARCHAR(255) NOT NULL, -- object type in Dolibarr + objectid INTEGER NOT NULL )ENGINE=innodb; From b74cfaf7921d95cba593f6e8ccf871c914931871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 12:02:47 +0200 Subject: [PATCH 22/31] factorization --- htdocs/societe/document.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 6ddf67c2133..0605592e4d7 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -149,26 +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); - - //TODO FACTORIZE THIS - // List of document - $formfile->list_of_documents($filearray,$object,'societe'); - - print "
"; - $formfile->list_of_links($object); - print "
"; + $modulepart = 'societe'; + $permission = $user->rights->societe->creer; + $param = '&id=' . $object->id; + include DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; } else { From b9c36e6e0af7b7a14729c8b9e386219690f2d4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 12:13:50 +0200 Subject: [PATCH 23/31] checkstyle --- htdocs/core/class/html.formfile.class.php | 70 ++++++++++++----------- htdocs/core/lib/files.lib.php | 1 + htdocs/core/tpl/doc2.tpl.php | 53 +++++++++-------- htdocs/link/class/link.class.php | 8 ++- 4 files changed, 71 insertions(+), 61 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 275ada1ef28..36afd101159 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1018,7 +1018,7 @@ class FormFile } - public function list_of_links($object, $permtodelete=1, $action=null, $selected=null) + public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null) { global $user, $conf, $langs, $user; @@ -1042,38 +1042,42 @@ class FormFile 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( + $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); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 9da243dff4f..2296454dc73 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -995,6 +995,7 @@ 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='', $link=null) diff --git a/htdocs/core/tpl/doc2.tpl.php b/htdocs/core/tpl/doc2.tpl.php index 37ec4fc1760..e4551eecae0 100644 --- a/htdocs/core/tpl/doc2.tpl.php +++ b/htdocs/core/tpl/doc2.tpl.php @@ -3,40 +3,43 @@ * 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 - ); + $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 - ); +$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 - ); +$formfile->list_of_documents( + $filearray, + $object, + $modulepart, + $param, + 0, + '', + $permission +); print "
"; //List of links -$formfile->list_of_links($object, $permission, $action, GETPOST('linkid', 'int')); +$formfile->listOfLinks($object, $permission, $action, GETPOST('linkid', 'int')); print "
"; diff --git a/htdocs/link/class/link.class.php b/htdocs/link/class/link.class.php index 982799a57cc..5f1054ef968 100644 --- a/htdocs/link/class/link.class.php +++ b/htdocs/link/class/link.class.php @@ -226,9 +226,11 @@ class Link extends CommonObject /** * Loads all links from database - * @param $links array of Link objects to fill - * @param $objecttype type of the associated object in dolibarr - * @param $objectid id of the associated object in dolibarr + * @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 * @return 1 if ok, 0 if no records, -1 if error * * */ From aea668f68be45f2a52a27fe92f8c9bea1a0cc4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 12:24:56 +0200 Subject: [PATCH 24/31] checkstyle --- htdocs/link/class/link.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/link/class/link.class.php b/htdocs/link/class/link.class.php index 5f1054ef968..fb924eeec9d 100644 --- a/htdocs/link/class/link.class.php +++ b/htdocs/link/class/link.class.php @@ -226,11 +226,12 @@ class Link extends CommonObject /** * Loads all links from database - * @param array $links array of Link objects to fill + * + * @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 + * @param string $sortorder sort order * @return 1 if ok, 0 if no records, -1 if error * * */ From 70ae7b6686562650e6fe1ac5b173b4e840f87a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 14:55:25 +0200 Subject: [PATCH 25/31] facto --- htdocs/adherents/document.php | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php index f084164efe3..3eb7ac331a8 100644 --- a/htdocs/adherents/document.php +++ b/htdocs/adherents/document.php @@ -165,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/doc2.tpl.php'; print "

"; } else From 039bd5b4c85ffb5b047eed55c478dfa00d69753d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 14:56:08 +0200 Subject: [PATCH 26/31] checkstyle --- htdocs/core/lib/files.lib.php | 2 +- htdocs/projet/tasks/document.php | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 2296454dc73..b64f403b758 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1072,7 +1072,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio setEventMessage($langs->trans("ErrorFileNotLinked"), 'errors'); } } - } + } else { $langs->load("errors"); diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index c5702aa54c9..763136d3481 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -229,18 +229,10 @@ if ($object->id > 0) print '
'; - $modulepart = 'projet'; + $modulepart = 'projet'; $permission = $user->rights->projet->creer; $param = '&id=' . $object->id; include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; - /*// 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).'/');*/ } else { From c3108f452ced761be044bbf9e742e62140c3f527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 14:58:26 +0200 Subject: [PATCH 27/31] copyrights --- htdocs/core/tpl/doc2.tpl.php | 18 ++++++++++++++++++ htdocs/core/tpl/document_actions.tpl.php | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/htdocs/core/tpl/doc2.tpl.php b/htdocs/core/tpl/doc2.tpl.php index e4551eecae0..201355e60fe 100644 --- a/htdocs/core/tpl/doc2.tpl.php +++ b/htdocs/core/tpl/doc2.tpl.php @@ -1,4 +1,22 @@ + * + * 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 */ diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions.tpl.php index 434c9e9f4ed..56567de96f1 100644 --- a/htdocs/core/tpl/document_actions.tpl.php +++ b/htdocs/core/tpl/document_actions.tpl.php @@ -1,4 +1,22 @@ + * + * 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) { From 6c22af00e1696d52b747725f0ae3a4cc1c2b3baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 15:55:44 +0200 Subject: [PATCH 28/31] factorization --- htdocs/comm/propal/document.php | 19 ++++--------------- htdocs/commande/document.php | 21 ++++----------------- htdocs/compta/deplacement/document.php | 21 ++++----------------- htdocs/compta/facture/document.php | 22 ++++------------------ htdocs/contrat/document.php | 22 ++++------------------ htdocs/fichinter/document.php | 21 ++++----------------- htdocs/fourn/commande/document.php | 20 ++++---------------- htdocs/fourn/facture/document.php | 15 ++++----------- htdocs/projet/document.php | 17 ++++------------- htdocs/societe/document.php | 2 +- 10 files changed, 37 insertions(+), 143 deletions(-) diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php index 266ee77b7d9..04704ba2ff4 100644 --- a/htdocs/comm/propal/document.php +++ b/htdocs/comm/propal/document.php @@ -130,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/doc2.tpl.php'; } else { diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index 32e666d1a7b..9ba0827e7e1 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -119,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/doc2.tpl.php'; } else { diff --git a/htdocs/compta/deplacement/document.php b/htdocs/compta/deplacement/document.php index 93258ab2297..0177891491d 100644 --- a/htdocs/compta/deplacement/document.php +++ b/htdocs/compta/deplacement/document.php @@ -120,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/doc2.tpl.php'; } else diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 92292375ac4..5bce75e363c 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -147,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/doc2.tpl.php'; } else diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index b63679cc1de..83d9870b0db 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -122,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/doc2.tpl.php'; } else diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 2dc8f7aedea..1505facbab5 100644 --- a/htdocs/fichinter/document.php +++ b/htdocs/fichinter/document.php @@ -120,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/doc2.tpl.php'; } else diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php index 581fac2df66..303e505c18b 100644 --- a/htdocs/fourn/commande/document.php +++ b/htdocs/fourn/commande/document.php @@ -158,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/doc2.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 287708da211..7779b58d220 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -177,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/doc2.tpl.php'; } else { diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php index 84c9f1e109c..7644ef5486c 100644 --- a/htdocs/projet/document.php +++ b/htdocs/projet/document.php @@ -104,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").''; @@ -149,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/doc2.tpl.php'; } else diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 0605592e4d7..e9b172cbc0a 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -152,7 +152,7 @@ if ($object->id) $modulepart = 'societe'; $permission = $user->rights->societe->creer; $param = '&id=' . $object->id; - include DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; } else { From 00c9df670c988bafd07624d8310dd0da682b2501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 18 Sep 2013 16:11:36 +0200 Subject: [PATCH 29/31] renamed templates --- htdocs/adherents/document.php | 4 ++-- htdocs/comm/action/document.php | 4 ++-- htdocs/comm/propal/document.php | 4 ++-- htdocs/commande/document.php | 4 ++-- htdocs/compta/deplacement/document.php | 4 ++-- htdocs/compta/facture/document.php | 4 ++-- htdocs/compta/sociales/document.php | 4 ++-- htdocs/contrat/document.php | 4 ++-- .../{doc2.tpl.php => document_actions_post_headers.tpl.php} | 0 ...t_actions.tpl.php => document_actions_pre_headers.tpl.php} | 0 htdocs/fichinter/document.php | 4 ++-- htdocs/fourn/commande/document.php | 4 ++-- htdocs/fourn/facture/document.php | 4 ++-- htdocs/product/document.php | 4 ++-- htdocs/projet/document.php | 4 ++-- htdocs/projet/tasks/document.php | 4 ++-- htdocs/societe/document.php | 4 ++-- 17 files changed, 30 insertions(+), 30 deletions(-) rename htdocs/core/tpl/{doc2.tpl.php => document_actions_post_headers.tpl.php} (100%) rename htdocs/core/tpl/{document_actions.tpl.php => document_actions_pre_headers.tpl.php} (100%) diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php index 3eb7ac331a8..a95063e9d64 100644 --- a/htdocs/adherents/document.php +++ b/htdocs/adherents/document.php @@ -74,7 +74,7 @@ if ($result < 0) * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -168,7 +168,7 @@ if ($id > 0) $modulepart = 'member'; $permission = $user->rights->adherent->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 741db311e20..848c8057b6d 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -83,7 +83,7 @@ if (! $sortfield) $sortfield="name"; /* * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -256,7 +256,7 @@ if ($act->id > 0) $modulepart = 'actions'; $permission = $user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create; $param = '&id=' . $act->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 04704ba2ff4..6e05813f7f3 100644 --- a/htdocs/comm/propal/document.php +++ b/htdocs/comm/propal/document.php @@ -66,7 +66,7 @@ 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.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; } /* @@ -133,7 +133,7 @@ if ($object->id > 0) $modulepart = 'propal'; $permission = $user->rights->propal->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 9ba0827e7e1..596759d44af 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -72,7 +72,7 @@ if ($object->fetch($id)) $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); } -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -122,7 +122,7 @@ if ($id > 0 || ! empty($ref)) $modulepart = 'commande'; $permission = $user->rights->commande->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 0177891491d..4c44fffa6e5 100644 --- a/htdocs/compta/deplacement/document.php +++ b/htdocs/compta/deplacement/document.php @@ -72,7 +72,7 @@ $modulepart='trip'; * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -123,7 +123,7 @@ if ($object->id) $modulepart = 'deplacement'; $permission = $user->rights->deplacement->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 5bce75e363c..cc16e5dcf77 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -74,7 +74,7 @@ if ($object->fetch($id)) /* * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -150,7 +150,7 @@ if ($id > 0 || ! empty($ref)) $modulepart = 'facture'; $permission = $user->rights->facture->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 c13618691fd..2e86a7a6986 100644 --- a/htdocs/compta/sociales/document.php +++ b/htdocs/compta/sociales/document.php @@ -73,7 +73,7 @@ $modulepart='tax'; * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -163,7 +163,7 @@ if ($object->id) $modulepart = 'tax'; $permission = $user->rights->tax->charges->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 83d9870b0db..c29d3b3186c 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -77,7 +77,7 @@ $modulepart='contract'; /* * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -125,7 +125,7 @@ if ($object->id) $modulepart = 'contract'; $permission = $user->rights->contrat->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/core/tpl/doc2.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php similarity index 100% rename from htdocs/core/tpl/doc2.tpl.php rename to htdocs/core/tpl/document_actions_post_headers.tpl.php diff --git a/htdocs/core/tpl/document_actions.tpl.php b/htdocs/core/tpl/document_actions_pre_headers.tpl.php similarity index 100% rename from htdocs/core/tpl/document_actions.tpl.php rename to htdocs/core/tpl/document_actions_pre_headers.tpl.php diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 1505facbab5..76fff7b9834 100644 --- a/htdocs/fichinter/document.php +++ b/htdocs/fichinter/document.php @@ -72,7 +72,7 @@ $modulepart='fichinter'; * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -123,7 +123,7 @@ if ($object->id) $modulepart = 'ficheinter'; $permission = $user->rights->ficheinter->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 303e505c18b..6816696ba36 100644 --- a/htdocs/fourn/commande/document.php +++ b/htdocs/fourn/commande/document.php @@ -78,7 +78,7 @@ $object->fetch_thirdparty(); * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -161,7 +161,7 @@ if ($object->id > 0) $modulepart = 'commande_fournisseur'; $permission = $user->rights->fournisseur->commande->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index 7779b58d220..f170b29330a 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -72,7 +72,7 @@ if ($object->fetch($id, $ref)) * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -180,7 +180,7 @@ if ($object->id > 0) $modulepart = 'facture_fournisseur'; $permission = $user->rights->fournisseur->facture->creer; $param = '&facid=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 34d12669617..4a5d1691613 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -81,7 +81,7 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); * Action envoie fichier */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -143,7 +143,7 @@ if ($object->id) $modulepart = 'produit'; $permission = $user->rights->produit->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 7644ef5486c..89fc9549156 100644 --- a/htdocs/projet/document.php +++ b/htdocs/projet/document.php @@ -70,7 +70,7 @@ if (! $sortfield) $sortfield="name"; * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -147,7 +147,7 @@ if ($object->id > 0) $modulepart = 'projet'; $permission = ($userWrite > 0); $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 763136d3481..8dd80223e6c 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -108,7 +108,7 @@ if ($id > 0 || ! empty($ref)) } } -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* * View @@ -232,7 +232,7 @@ if ($object->id > 0) $modulepart = 'projet'; $permission = $user->rights->projet->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + 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 e9b172cbc0a..1da45c36c8f 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -73,7 +73,7 @@ if ($id > 0 || ! empty($ref)) * Actions */ -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions.tpl.php'; +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; /* @@ -152,7 +152,7 @@ if ($object->id) $modulepart = 'societe'; $permission = $user->rights->societe->creer; $param = '&id=' . $object->id; - include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php'; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else { From 81ecb4b4a535059ed151b24b21b7193d885114f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 6 Nov 2013 10:26:09 +0100 Subject: [PATCH 30/31] Updated method call to new prototype --- htdocs/core/tpl/document_actions_pre_headers.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/document_actions_pre_headers.tpl.php b/htdocs/core/tpl/document_actions_pre_headers.tpl.php index 56567de96f1..18b7c18c4a5 100644 --- a/htdocs/core/tpl/document_actions_pre_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_pre_headers.tpl.php @@ -29,7 +29,7 @@ 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', null, $link); } } } From f11f9b0a69374997d614b1b718e0cce6d213d777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 6 Nov 2013 10:33:29 +0100 Subject: [PATCH 31/31] Added missing copyright --- htdocs/core/class/html.formfile.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 36afd101159..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