From 637e1a8d211a65c0c0cee59868df80e40d44ddb0 Mon Sep 17 00:00:00 2001 From: mikee2 Date: Sat, 6 May 2017 10:49:37 +0200 Subject: [PATCH 01/47] Update Segment.php Add additional needed fields so that you can invoice yearly items. Have number and text descriptions to avoid future changes that may break existing invoices. --- htdocs/includes/odtphp/Segment.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 81e9dad9f97..4310c716ee7 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -170,8 +170,16 @@ class Segment implements IteratorAggregate, Countable { global $langs; - $patterns=array( '__CURRENTDAY__','__CURRENTDAYTEXT__','__CURRENTMONTHSHORT__','__CURRENTMONTH__','__CURRENTYEAR__' ); - $values=array( date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y') ); + $nextMonth = strtotime('+1 month'); + + $patterns=array( '/__CURRENTDAY__/u','/__CURRENTDAYTEXT__/u', + '/__CURRENTMONTH__/u','/__CURRENTMONTHSHORT__/u','/__CURRENTMONTHLONG__/u', + '/__NEXTMONTH__/u','/__NEXTMONTHSHORT__/u','/__NEXTMONTHLONG__/u', + '/__CURRENTYEAR__/u','/__NEXTYEAR__/u' ); + $values=array( date('j'), $langs->trans(date('l')), + $langs->trans(date('n')), $langs->trans(date('M')), $langs->trans(date('F')), + $langs->trans(date('n', $nextMonth)), $langs->trans(date('M', $nextMonth)), $langs->trans(date('F', $nextMonth)), + date('Y'), date('Y', strtotime('+1 year')) ); $text=preg_replace($patterns, $values, $text); From 6a350470200b224261d20817d3a5159095e2f104 Mon Sep 17 00:00:00 2001 From: mikee2 Date: Wed, 14 Jun 2017 12:53:29 +0200 Subject: [PATCH 02/47] Updated to use dolibarr timme functions Redefined macro strings to adapt to dolibarr date functions return values. Keep same macro names when possible to avoid breaking existing code. Some macro holders (not commonly used) have been dropped because non existing values in dolibarr date functions. Per eldy request changed php date functions with dolibarr's internal date functions to match users time zone. Now dates are those of the user's timezone so check that is is correctly defined in user's profile. --- htdocs/includes/odtphp/Segment.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 4310c716ee7..d015d6ad263 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -170,16 +170,17 @@ class Segment implements IteratorAggregate, Countable { global $langs; - $nextMonth = strtotime('+1 month'); - - $patterns=array( '/__CURRENTDAY__/u','/__CURRENTDAYTEXT__/u', - '/__CURRENTMONTH__/u','/__CURRENTMONTHSHORT__/u','/__CURRENTMONTHLONG__/u', - '/__NEXTMONTH__/u','/__NEXTMONTHSHORT__/u','/__NEXTMONTHLONG__/u', + $hoy = dol_getdate(dol_now('tzuser')); + $nextMonth = dol_get_next_month($hoy['mon'], $hoy['year'])['month']; + + $patterns=array( '/__CURRENTDAY__/u','/__CURENTWEEKDAY__/u', + '/__CURRENTMONTH__/u','/__CURRENTMONTHLONG__/u', + '/__NEXTMONTH__/u','/__NEXTMONTHLONG__/u', '/__CURRENTYEAR__/u','/__NEXTYEAR__/u' ); - $values=array( date('j'), $langs->trans(date('l')), - $langs->trans(date('n')), $langs->trans(date('M')), $langs->trans(date('F')), - $langs->trans(date('n', $nextMonth)), $langs->trans(date('M', $nextMonth)), $langs->trans(date('F', $nextMonth)), - date('Y'), date('Y', strtotime('+1 year')) ); + $values=array( $hoy['mday'], $langs->trans($hoy['weekday']), + $hoy['mon'], $langs->trans($hoy['month']), + $nextMonth, monthArray($langs)[$nextMonth], + $hoy['year'], $hoy['year']+1 ); $text=preg_replace($patterns, $values, $text); From ff7b542bfad145d7485d920c34b77594d358b556 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 15 Sep 2017 13:25:54 +0200 Subject: [PATCH 03/47] fix : Avoid warning --- .../class/expensereport.class.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index f999a93c57f..0ac2ce64062 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -187,20 +187,22 @@ class ExpenseReport extends CommonObject $resql=$this->db->query($sql); if (!$resql) $error++; - foreach ($this->lines as $i => $val) - { - $newndfline=new ExpenseReportLine($this->db); - $newndfline=$this->lines[$i]; - $newndfline->fk_expensereport=$this->id; - if ($result >= 0) - { - $result=$newndfline->insert(); - } - if ($result < 0) - { - $error++; - break; - } + if (is_array($this->lines) && count($this->lines)>0) { + foreach ($this->lines as $i => $val) + { + $newndfline=new ExpenseReportLine($this->db); + $newndfline=$this->lines[$i]; + $newndfline->fk_expensereport=$this->id; + if ($result >= 0) + { + $result=$newndfline->insert(); + } + if ($result < 0) + { + $error++; + break; + } + } } if (! $error) From 99149b5cfeada8c2062ae969841ef9629c01335c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 17 Sep 2017 21:21:12 +0200 Subject: [PATCH 04/47] Fix box activity again --- htdocs/core/boxes/box_activity.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index a05fcf761b6..7aa5974efbd 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -438,11 +438,6 @@ class box_activity extends ModeleBoxes 'td' => 'align="center"', 'text'=>$langs->trans("NoRecordedInvoices"), ); - } else { - $this->info_box_contents[0][0] = array( - 'td' => '', - 'maxlength'=>500, 'text' => ($db->error().' sql='.$sql), - ); } } From f76b675e092ba5053ac3dbffe8f4b1ab5d977bea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 17 Sep 2017 21:24:30 +0200 Subject: [PATCH 05/47] Fix box activity again --- htdocs/core/boxes/box_activity.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 7aa5974efbd..2f923855dbb 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -147,7 +147,7 @@ class box_activity extends ModeleBoxes if (! empty($data)) { $j=0; - while ($line < count($data)) + while ($j < count($data)) { $this->info_box_contents[$line][0] = array( 'td' => 'align="left" width="16"', @@ -230,7 +230,7 @@ class box_activity extends ModeleBoxes if (! empty($data)) { $j=0; - while ($line < count($data)) { + while ($j < count($data)) { $this->info_box_contents[$line][0] = array( 'td' => 'align="left" width="16"', 'url' => DOL_URL_ROOT."/commande/list.php?mainmenu=commercial&leftmenu=orders&viewstatut=".$data[$j]->fk_statut, @@ -315,7 +315,7 @@ class box_activity extends ModeleBoxes if (! empty($data)) { $j=0; - while ($line < count($data)) { + while ($j < count($data)) { $billurl="search_status=2&paye=1&year=".$data[$j]->annee; $this->info_box_contents[$line][0] = array( 'td' => 'align="left" width="16"', @@ -400,7 +400,7 @@ class box_activity extends ModeleBoxes $alreadypaid=-1; - while ($line < count($data)) { + while ($j < count($data)) { $billurl="search_status=".$data[$j]->fk_statut."&paye=0"; $this->info_box_contents[$line][0] = array( 'td' => 'align="left" width="16"', From eaee8ee5864c0e2b1481adc6530d2a166f885186 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 17 Sep 2017 21:29:25 +0200 Subject: [PATCH 06/47] Fix box activity again --- htdocs/core/boxes/box_activity.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 2f923855dbb..71a9a4e3125 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -77,7 +77,6 @@ class box_activity extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $totalMnt = 0; $totalnb = 0; $line = 0; $cachetime = 3600; @@ -173,7 +172,6 @@ class box_activity extends ModeleBoxes 'td' => 'class="right"', 'text' => price($data[$j]->Mnttot,1,$langs,0,0,-1,$conf->currency), ); - $totalMnt += $data[$j]->Mnttot; $this->info_box_contents[$line][4] = array( 'td' => 'align="right" width="18"', 'text' => $propalstatic->LibStatut($data[$j]->fk_statut,3), @@ -255,7 +253,6 @@ class box_activity extends ModeleBoxes 'td' => 'class="right"', 'text' => price($data[$j]->Mnttot,1,$langs,0,0,-1,$conf->currency), ); - $totalMnt += $data[$j]->Mnttot; $this->info_box_contents[$line][4] = array( 'td' => 'align="right" width="18"', 'text' => $commandestatic->LibStatut($data[$j]->fk_statut,0,3), @@ -342,10 +339,8 @@ class box_activity extends ModeleBoxes ); // We add only for the current year - if ($data[$j]->annee == date("Y")) { - $totalnb += $data[$j]->nb; - $totalMnt += $data[$j]->Mnttot; - } + $totalnb += $data[$j]->nb; + $this->info_box_contents[$line][4] = array( 'td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut(1,$data[$j]->fk_statut,3), @@ -396,10 +391,9 @@ class box_activity extends ModeleBoxes } if (! empty($data)) { - $j=0; - $alreadypaid=-1; + $j=0; while ($j < count($data)) { $billurl="search_status=".$data[$j]->fk_statut."&paye=0"; $this->info_box_contents[$line][0] = array( @@ -425,7 +419,6 @@ class box_activity extends ModeleBoxes 'td' => 'class="right"', 'text' => price($data[$j]->Mnttot,1,$langs,0,0,-1,$conf->currency), ); - $totalMnt += $objp->Mnttot; $this->info_box_contents[$line][4] = array( 'td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut(0,$data[$j]->fk_statut,3, $alreadypaid), From 0536d6cbed522893ddbfd3ce7c69847a8eac8fee Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 15:46:17 +0200 Subject: [PATCH 07/47] FIX #7330 --- htdocs/contrat/list.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 17246751600..221a4233f5a 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2014 Juanjo Menent @@ -271,11 +271,8 @@ $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.re $sql.= ' s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql.= " typent.code,"; $sql.= " state.code_departement, state.nom"; -// Add where from extra fields -foreach ($extrafields->attribute_label as $key => $val) -{ - $sql .= ', ef.'.$key; -} +// Add fields from extrafields +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : ''); // Add where from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook From 6ac1b6e82eed373a7a0d061a3961268f6dd2689d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 15:48:04 +0200 Subject: [PATCH 08/47] Fix template --- htdocs/modulebuilder/template/myobject_list.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 96b7d7ca733..c4e7875e89a 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -237,6 +237,21 @@ foreach ($search_array_options as $key => $val) $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; + +/* If a group by is required +$sql.= " GROUP BY " +foreach($object->fields as $key => $val) +{ + $sql.='t.'.$key.', '; +} +// Add fields from extrafields +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : ''); +// Add where from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +*/ + $sql.=$db->order($sortfield,$sortorder); // Count total nb of records From aba907d1a8805e1133f8fe337593674d177a7b93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 15:49:21 +0200 Subject: [PATCH 09/47] FIX #7420 --- htdocs/includes/odtphp/Segment.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 40668215647..525cd5b4f3f 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -24,7 +24,7 @@ class Segment implements IteratorAggregate, Countable protected $images = array(); protected $odf; protected $file; - + /** * Constructor * @@ -86,15 +86,15 @@ class Segment implements IteratorAggregate, Countable */ public function merge() { - // To provide debug information on line number processed + // To provide debug information on line number processed global $count; if (empty($count)) $count=1; else $count++; - + if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps $this->xml = $this->savxml; $tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values - + // Search all tags fou into condition to complete $tmpvars, so we will proceed all tests even if not defined $reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); @@ -106,7 +106,7 @@ class Segment implements IteratorAggregate, Countable $tmpvars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop } } - + // Conditionals substitution // Note: must be done before static substitution, else the variable will be replaced by its value and the conditional won't work anymore foreach($tmpvars as $key => $value) @@ -133,7 +133,7 @@ class Segment implements IteratorAggregate, Countable $this->xml = preg_replace($reg, '', $this->xml); } } - + $this->xmlParsed .= str_replace(array_keys($tmpvars), array_values($tmpvars), $this->xml); if ($this->hasChildren()) { foreach ($this->children as $child) { @@ -143,7 +143,7 @@ class Segment implements IteratorAggregate, Countable } $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/sm"; $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed); - // Miguel Erill 09704/2017 - Add macro replacement to invoice lines + // Miguel Erill 09704/2017 - Add macro replacement to invoice lines $this->xmlParsed = $this->macroReplace($this->xmlParsed); $this->file->open($this->odf->getTmpfile()); foreach ($this->images as $imageKey => $imageValue) { @@ -155,28 +155,28 @@ class Segment implements IteratorAggregate, Countable } } $this->file->close(); - + return $this->xmlParsed; } /** * Function to replace macros for invoice short and long month, invoice year - * + * * Substitution occur when the invoice is generated, not considering the invoice date * so do not (re)generate in a diferent date than the one that the invoice belongs to * Perhaps it would be better to use the invoice issued date but I still do not know * how to get it here * * Miguel Erill 09/04/2017 - * + * * @param string $value String to convert */ public function macroReplace($text) { global $langs; - $patterns=array( '__CURRENTDAY__','__CURRENTDAYTEXT__','__CURRENTMONTHSHORT__','__CURRENTMONTH__','__CURRENTYEAR__' ); - $values=array( date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y') ); + $patterns=array('/__CURRENTDAY__/','/__CURRENTDAYTEXT__/','/__CURRENTMONTHSHORT__/','/__CURRENTMONTH__/','/__CURRENTYEAR__/'); + $values=array(date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y')); $text=preg_replace($patterns, $values, $text); @@ -203,7 +203,7 @@ class Segment implements IteratorAggregate, Countable } return $this; } - + /** * Assign a template variable to replace * From c11ff4a18c7f488b3588793451165370f28beb4b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 15:55:25 +0200 Subject: [PATCH 10/47] FIX #7368 --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 1 + htdocs/install/mysql/migration/repair.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 14990f1bfdc..3a5810d19e4 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -510,6 +510,7 @@ ALTER TABLE llx_user_rights DROP FOREIGN KEY fk_user_rights_fk_user_user; ALTER TABLE llx_user_rights DROP INDEX uk_user_rights; ALTER TABLE llx_user_rights DROP INDEX fk_user; ALTER TABLE llx_user_rights ADD UNIQUE INDEX uk_user_rights (entity, fk_user, fk_id); +DELETE FROM llx_user_rights WHERE fk_user NOT IN (select rowid from llx_user); ALTER TABLE llx_user_rights ADD CONSTRAINT fk_user_rights_fk_user_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); ALTER TABLE llx_usergroup_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 59be09bcb8b..3a61ef4b216 100755 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -89,6 +89,7 @@ delete from llx_livraison where ref = ''; delete from llx_expeditiondet where fk_expedition in (select rowid from llx_expedition where ref = ''); delete from llx_expedition where ref = ''; delete from llx_holiday_logs where fk_user_update not IN (select rowid from llx_user); +delete from llx_user_rights where fk_user not IN (select rowid from llx_user); update llx_deplacement set dated='2010-01-01' where dated < '2000-01-01'; From 70b11f18b51fac1f679080f832c3931e825468f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 16:06:58 +0200 Subject: [PATCH 11/47] FIX #7367 --- htdocs/core/lib/files.lib.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 9ff9ec0df63..b1031153507 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1559,7 +1559,7 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile= } /** - * Convert an image file into anoher format. + * Convert an image file into another format. * This need Imagick php extension. * * @param string $fileinput Input file name @@ -1567,14 +1567,19 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile= * @param string $fileoutput Output filename * @return int <0 if KO, 0=Nothing done, >0 if OK */ -function dol_convert_file($fileinput,$ext='png',$fileoutput='') +function dol_convert_file($fileinput, $ext='png', $fileoutput='') { global $langs; if (class_exists('Imagick')) { $image=new Imagick(); - $ret = $image->readImage($fileinput); + try { + $ret = $image->readImage($fileinput); + } catch(Exception $e) { + dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING); + return 0; + } if ($ret) { $ret = $image->setImageFormat($ext); From cdd1473cfa00a7bc7bed8b767defe36a40fa1436 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 18 Sep 2017 16:30:01 +0200 Subject: [PATCH 12/47] Fix: avoid Warning: A non-numeric value encountered --- htdocs/product/price.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index b03a8763770..7c58069585e 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1,9 +1,9 @@ +/* Copyright (C) 2001-2007 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2005-2015 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2014 Florian Henry * Copyright (C) 2014-2016 Juanjo Menent * Copyright (C) 2014-2015 Philippe Grand @@ -1171,7 +1171,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) } print ''; print ''; - + $parameters=array('colspan' => 2); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -1493,10 +1493,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); - $page = GETPOST("page", 'int'); - if ($page == - 1) { - $page = 0; - } + $page = (GETPOST("page",'int')?GETPOST("page", 'int'):0); + if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; From ee99483b0def49e496f7abcf233b8127a51e9385 Mon Sep 17 00:00:00 2001 From: Kjeld Borch Egevang Date: Mon, 18 Sep 2017 22:30:08 +0200 Subject: [PATCH 13/47] Changed "Solde" to "Balance". --- htdocs/accountancy/bookkeeping/balance.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index c6d0d5cf40e..382d0697b6a 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -210,7 +210,7 @@ else { print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $options, "", $sortfield, $sortorder); print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); - print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); + print_liste_field_titre("Balance", $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; @@ -280,4 +280,4 @@ else { llxFooter(); } -$db->close(); \ No newline at end of file +$db->close(); From 9838199de148579753f5602dadf6c5924c6827ab Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Sep 2017 23:31:07 +0200 Subject: [PATCH 14/47] FIX Sign of amount in origin currency on credit note created from lines --- htdocs/compta/facture/card.php | 17 +++++++++++------ htdocs/compta/facture/class/facture.class.php | 7 ++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 82eeb3d49c0..c66285ae0c8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -841,13 +841,18 @@ if (empty($reshook)) $line->fk_facture = $object->id; $line->fk_parent_line = $fk_parent_line; - $line->subprice =-$line->subprice; // invert price for object + $line->subprice = -$line->subprice; // invert price for object $line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here - $line->total_ht=-$line->total_ht; - $line->total_tva=-$line->total_tva; - $line->total_ttc=-$line->total_ttc; - $line->total_localtax1=-$line->total_localtax1; - $line->total_localtax2=-$line->total_localtax2; + $line->total_ht = -$line->total_ht; + $line->total_tva = -$line->total_tva; + $line->total_ttc = -$line->total_ttc; + $line->total_localtax1 = -$line->total_localtax1; + $line->total_localtax2 = -$line->total_localtax2; + + $line->multicurrency_subprice = -$line->multicurrency_subprice; + $line->multicurrency_total_ht = -$line->multicurrency_total_ht; + $line->multicurrency_total_tva = -$line->multicurrency_total_tva; + $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc; $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9cc9a63f313..c3b58117dd7 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1568,7 +1568,7 @@ class Facture extends CommonInvoice $facligne->desc=$remise->description; // Description ligne $facligne->vat_src_code=$remise->vat_src_code; $facligne->tva_tx=$remise->tva_tx; - $facligne->subprice=-$remise->amount_ht; + $facligne->subprice = -$remise->amount_ht; $facligne->fk_product=0; // Id produit predefini $facligne->qty=1; $facligne->remise_percent=0; @@ -1591,6 +1591,11 @@ class Facture extends CommonInvoice $facligne->total_tva = -$remise->amount_tva; $facligne->total_ttc = -$remise->amount_ttc; + $facligne->multicurrency_subprice = -$remise->multicurrency_subprice; + $facligne->multicurrency_total_ht = -$remise->multicurrency_total_ht; + $facligne->multicurrency_total_tva = -$remise->multicurrency_total_tva; + $facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc; + $lineid=$facligne->insert(); if ($lineid > 0) { From f936b17d68928caf7c8af9131a2276e837f1faa4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 00:24:52 +0200 Subject: [PATCH 15/47] FIX Protection to avoid to apply credit note discount > remain to pay --- htdocs/comm/remx.php | 24 +++++++++--------- htdocs/compta/facture/card.php | 37 ++++++++++++++++++++-------- htdocs/core/class/discount.class.php | 7 ++++++ htdocs/langs/en_US/bills.lang | 1 + htdocs/langs/en_US/errors.lang | 2 +- 5 files changed, 48 insertions(+), 23 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 9964db9ecde..94142b6ec54 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -125,7 +125,7 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') if ($res > 0 && $newid1 > 0 && $newid2 > 0) { $db->commit(); - header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); // To avoid pb whith back + header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id.($backtopage?'&backtopage='.urlencode($backtopage):'')); // To avoid pb whith back exit; } else @@ -275,13 +275,13 @@ if ($socid > 0) print ''; print ''; - + if ($user->rights->societe->creer) { print '
'; - + print load_fiche_titre($langs->trans("NewGlobalDiscount"),'',''); - + print '
'; print ''; print ''; @@ -293,7 +293,7 @@ if ($socid > 0) print ''; print ''; print ''; - + print "
'.$langs->trans("AmountHT").'
'.$langs->trans("NoteReason").'
"; } @@ -362,7 +362,7 @@ if ($socid > 0) while ($i < $num) { $obj = $db->fetch_object($resql); - + print ''; print ''.dol_print_date($db->jdate($obj->dc),'dayhour').''; if (preg_match('/\(CREDIT_NOTE\)/',$obj->description)) @@ -408,14 +408,14 @@ if ($socid > 0) if ($user->rights->societe->creer || $user->rights->facture->creer) { print ''; - print 'rowid.'">'.img_split($langs->trans("SplitDiscount")).''; + print 'rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).''; print '   '; - print 'rowid.'">'.img_delete($langs->trans("RemoveDiscount")).''; + print 'rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).''; print ''; } else print ' '; print ''; - + if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid) { $showconfirminfo['rowid']=$obj->rowid; @@ -427,7 +427,7 @@ if ($socid > 0) else { print ''.$langs->trans("None").''; - } + } $db->free($resql); print ""; @@ -441,7 +441,7 @@ if ($socid > 0) array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5') ); $langs->load("dict"); - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'], $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0); + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0); } } else @@ -590,7 +590,7 @@ if ($socid > 0) { print ''.$langs->trans("None").''; } - + print ""; } else diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index c66285ae0c8..6cfed39a02f 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -378,7 +378,9 @@ if (empty($reshook)) else if ($action == "setabsolutediscount" && $user->rights->facture->creer) { - // POST[remise_id] ou POST[remise_id_for_payment] + // POST[remise_id] or POST[remise_id_for_payment] + + // We use the credit to reduce amount of invoice if (! empty($_POST["remise_id"])) { $ret = $object->fetch($id); if ($ret > 0) { @@ -390,14 +392,28 @@ if (empty($reshook)) dol_print_error($db, $object->error); } } - if (! empty($_POST["remise_id_for_payment"])) { + // We use the credit to reduce remain to pay + if (! empty($_POST["remise_id_for_payment"])) + { require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; $discount = new DiscountAbsolute($db); $discount->fetch($_POST["remise_id_for_payment"]); - $result = $discount->link_to_invoice(0, $id); - if ($result < 0) { - setEventMessages($discount->error, $discount->errors, 'errors'); + //var_dump($object->getRemainToPay(0)); + //var_dump($discount->amount_ttc);exit; + if ($discount->amount_ttc > $object->getRemainToPay(0)) + { + // TODO Split the discount in 2 automatically + $error++; + setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors'); + } + + if (! $error) + { + $result = $discount->link_to_invoice(0, $id); + if ($result < 0) { + setEventMessages($discount->error, $discount->errors, 'errors'); + } } } } @@ -3175,6 +3191,7 @@ else if ($id > 0 || ! empty($ref)) $addrelativediscount = '' . $langs->trans("EditRelativeDiscounts") . ''; $addabsolutediscount = '' . $langs->trans("EditGlobalDiscounts") . ''; $addcreditnote = '' . $langs->trans("AddCreditNote") . ''; + $viewabsolutediscount = '' . $langs->trans("ViewAvailableGlobalDiscounts") . ''; print '' . $langs->trans('Discounts'); print ''; @@ -3184,7 +3201,7 @@ else if ($id > 0 || ! empty($ref)) print $langs->trans("CompanyHasNoRelativeDiscount"); // print ' ('.$addrelativediscount.')'; - // Is there commercial discount or down payment available ? + // Is there is commercial discount or down payment available ? if ($absolute_discount > 0) { print '. '; if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { @@ -3209,7 +3226,7 @@ else if ($id > 0 || ! empty($ref)) } else { if ($absolute_creditnote > 0) // If not, link will be added later { - if ($object->statut == 0 && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) + if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' (' . $addabsolutediscount . ')
'; else print '. '; @@ -3220,7 +3237,7 @@ else if ($id > 0 || ! empty($ref)) if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" - if ($object->statut != 1 || $object->type == Facture::TYPE_CREDIT_NOTE) { + if ($object->statut != Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE) { if ($object->statut == 0 && $object->type != Facture::TYPE_DEPOSIT) { $text = $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)); print $form->textwithpicto($text, $langs->trans("CreditNoteDepositUse")); @@ -3231,13 +3248,13 @@ else if ($id > 0 || ! empty($ref)) // There is credit notes discounts available if (! $absolute_discount) print '
'; // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer); - $more=' ('.$addcreditnote.')'; + $more=' ('.$addcreditnote. (($addcreditnote && $viewabsolutediscount) ? ' - ' : '') . $viewabsolutediscount . ')'; $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0, $more); // We allow credit note even if amount is higher } } if (! $absolute_discount && ! $absolute_creditnote) { print $langs->trans("CompanyHasNoAbsoluteDiscount"); - if ($object->statut == 0 && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) + if ($object->statut == Facture::STATUS_DRAFT && $object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT) print ' (' . $addabsolutediscount . ')
'; else print '. '; diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 443534eb1b3..89bb230d34f 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -78,6 +78,7 @@ class DiscountAbsolute $sql = "SELECT sr.rowid, sr.fk_soc,"; $sql.= " sr.fk_user,"; $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; + $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,"; $sql.= " sr.datec,"; $sql.= " f.facnumber as ref_facture_source"; @@ -97,9 +98,15 @@ class DiscountAbsolute $this->id = $obj->rowid; $this->fk_soc = $obj->fk_soc; + $this->amount_ht = $obj->amount_ht; $this->amount_tva = $obj->amount_tva; $this->amount_ttc = $obj->amount_ttc; + + $this->multicurrency_amount_ht = $obj->multicurrency_amount_ht; + $this->multicurrency_amount_tva = $obj->multicurrency_amount_tva; + $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc; + $this->tva_tx = $obj->tva_tx; $this->fk_user = $obj->fk_user; $this->fk_facture_line = $obj->fk_facture_line; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 189ef5c1fe2..df00aec79fe 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -338,6 +338,7 @@ DateIsNotEnough=Date not reached yet InvoiceGeneratedFromTemplate=Invoice %s generated from recurring template invoice %s WarningInvoiceDateInFuture=Warning, the invoice date is higher than current date WarningInvoiceDateTooFarInFuture=Warning, the invoice date is too far from current date +ViewAvailableGlobalDiscounts=View available discounts # PaymentConditions Statut=Status PaymentConditionShortRECEP=Due Upon Receipt diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 8dfc02c49f1..e42e701bb3a 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -196,7 +196,7 @@ ErrorBadLinkSourceSetButBadValueForRef=The link you use is not valid. A 'source' ErrorTooManyErrorsProcessStopped=Too many errors. Process was stopped. ErrorOnlyInvoiceValidatedCanBeSentInMassAction=Only validated invoices can be sent using the "Send by email" mass action. ErrorChooseBetweenFreeEntryOrPredefinedProduct=You must choose if article is a predefined product or not - +ErrorDiscountLargerThanRemainToPaySplitItBefore=The discount you try to apply is larger than remain to pay. Split the discount in 2 smaller discounts before. # Warnings WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined From 1e33495f429fb6b346b85a235aa23ecc856ae84a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 00:31:51 +0200 Subject: [PATCH 16/47] Fix remove warnings --- htdocs/accountancy/admin/account.php | 10 ++++------ htdocs/comm/mailing/advtargetemailing.php | 14 +++++++------- htdocs/product/stats/commande_fournisseur.php | 14 +++++++------- htdocs/product/stats/propal.php | 12 +++++++----- htdocs/product/stats/supplier_proposal.php | 12 +++++++----- htdocs/societe/price.php | 4 +--- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 5c4e836986e..fb48bc8094f 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -53,12 +53,10 @@ if (! $user->rights->accounting->chartofaccount) accessforbidden(); // Load variable for pagination $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'sortorder'); -$page = GETPOST("page", 'int'); -if ($page == - 1) { - $page = 0; -} +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index 39d1b7c8d8d..cfafdaa725b 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -45,13 +45,13 @@ if (! empty($conf->categorie->enabled)) { if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden(); -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if ($page == - 1) { - $page = 0; -} -$offset = $conf->liste_limit * $page; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php index 4b9aa67236e..17d4bb5f962 100644 --- a/htdocs/product/stats/commande_fournisseur.php +++ b/htdocs/product/stats/commande_fournisseur.php @@ -51,13 +51,13 @@ $hookmanager->initHooks(array ( $mesg = ''; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if ($page == - 1) { - $page = 0; -} -$offset = $conf->liste_limit * $page; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 3f6eae0bfce..aa2c9a8e603 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -48,11 +48,13 @@ $hookmanager->initHooks(array ('productstatspropal')); $mesg = ''; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if ($page == - 1) { $page = 0;} -$offset = $conf->liste_limit * $page; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder = "DESC"; diff --git a/htdocs/product/stats/supplier_proposal.php b/htdocs/product/stats/supplier_proposal.php index 1e0cefc3150..9406ade286f 100644 --- a/htdocs/product/stats/supplier_proposal.php +++ b/htdocs/product/stats/supplier_proposal.php @@ -48,11 +48,13 @@ $hookmanager->initHooks(array ('productstatspropal')); $mesg = ''; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if ($page == - 1) { $page = 0;} -$offset = $conf->liste_limit * $page; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder = "DESC"; diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index 515aef60a6a..fc864bd5e01 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -237,9 +237,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { $sortorder = GETPOST("sortorder", 'alpha'); $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $page = GETPOST("page", 'int'); - if ($page == - 1) { - $page = 0; - } + if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; From 89bfb81cc75a196c8af67576d156747fc3d99fec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 01:05:13 +0200 Subject: [PATCH 17/47] Fix repair --- htdocs/install/repair.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 7fc3744e334..a93081cd5b2 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -211,7 +211,8 @@ if ($ok) $extrafields=new ExtraFields($db); $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', - 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', + 'supplier_proposal'=>'supplier_proposal', 'commande_fournisseur'=>'commande_fournisseur', 'facture_fourn'=>'facture_fourn', + 'actioncomm'=>'actioncomm', 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); print '
*** Check fields into extra table structure match table of definition. If not add column into table'; foreach($listofmodulesextra as $tablename => $elementtype) @@ -303,6 +304,10 @@ if ($ok) print " \n"; } + else + { + dol_print_error($db); + } } } From b723d2c2d2604cfd513de68ea8a958f37bbf406d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 01:39:22 +0200 Subject: [PATCH 18/47] Fix scrutinizer bugs --- htdocs/core/actions_massactions.inc.php | 4 ++-- htdocs/core/lib/agenda.lib.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index b17c047860a..2ac0b3a5885 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -147,11 +147,11 @@ if (! $error && $massaction == 'confirm_presend') foreach($receiver as $key=>$val) { // Recipient was provided from combo list - if ($val == 'thirdparty') // Id of third party + if ($val == 'thirdparty') // Id of third party or user { $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; } - elseif ($val) // Id du contact + elseif ($val && method_exists($thirdparty, 'contact_get_property')) // Id of contact { $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); $sendtoid[] = $val; diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index a1571f7ac08..526e6386f0f 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -54,6 +54,9 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh $langs->load("companies"); + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions=new FormActions($db); + // Filters print '
'; print ''; @@ -95,9 +98,6 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print ''; } - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - // Type print ''; print ''; From 978702d04b3ded8ea709f41b45726d65eaa2d046 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 01:41:57 +0200 Subject: [PATCH 19/47] Fix false deprecated warning --- htdocs/core/lib/json.lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 55bfcf96061..425b5713565 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -46,7 +46,7 @@ if (! function_exists('json_encode')) */ function dol_json_encode($elements) { - dol_syslog("For better permorfance, enable the native json in your PHP", LOG_WARNING); + dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); $num=0; if (is_object($elements)) // Count number of properties for an object @@ -225,12 +225,11 @@ if (! function_exists('json_decode')) * @param string $json Json encoded to PHP Object or Array * @param bool $assoc False return an object, true return an array. Try to always use it with true ! * @return mixed Object or Array or false on error - * @deprecated PHP >= 5.3 supports native json_decode * @see json_decode() */ function dol_json_decode($json, $assoc=false) { - dol_syslog('dol_json_decode() is deprecated. Please update your code to use native json_decode().', LOG_WARNING); + dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); $comment = false; From 0b67ac36f144ed3ac6320cc2d2ebf2f2cf1316f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 02:01:05 +0200 Subject: [PATCH 20/47] Show image on tool page --- htdocs/core/tools.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tools.php b/htdocs/core/tools.php index 51378c9246a..8010f726c4f 100644 --- a/htdocs/core/tools.php +++ b/htdocs/core/tools.php @@ -49,7 +49,8 @@ print load_fiche_titre($text); print $langs->trans("ToolsDesc").'

'; - +// Show logo +print '
'; llxFooter(); From 7375afca3ecd6e0916b2905fdd02da84f0b18c91 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 19 Sep 2017 09:03:25 +0200 Subject: [PATCH 21/47] fix : rest API URL --- htdocs/api/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php index 218ab58467e..f2c5160db38 100644 --- a/htdocs/api/admin/index.php +++ b/htdocs/api/admin/index.php @@ -128,7 +128,7 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain // Show message $message=''; -$url=$urlwithroot.'/api/index.php/login?login=auserlogin&userpassword=thepassword[&reset=1]'; +$url=$urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]'; $message.=$langs->trans("UrlToGetKeyToUseAPIs").':
'; $message.=img_picto('','object_globe.png').' '.$url; print $message; From 77d1a150160ac9a1e13cb2b14a314e08d4bac8a9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 12:03:48 +0200 Subject: [PATCH 22/47] Activate warning for french "Loi Finance 2016" --- htdocs/core/modules/modCashDesk.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modCashDesk.class.php b/htdocs/core/modules/modCashDesk.class.php index f153631dc20..33b44297628 100644 --- a/htdocs/core/modules/modCashDesk.class.php +++ b/htdocs/core/modules/modCashDesk.class.php @@ -70,7 +70,7 @@ class modCashDesk extends DolibarrModules $this->phpmin = array(4,1); // Minimum version of PHP required by module $this->need_dolibarr_version = array(2,4); // Minimum version of Dolibarr required by module $this->langfiles = array("cashdesk"); - //$this->warnings_activation = array('FR'=>'WarningNoteModulePOSForFrenchLaw'); // Warning to show when we activate module. array('always'='text') or array('FR'='text') + $this->warnings_activation = array('FR'=>'WarningNoteModulePOSForFrenchLaw'); // Warning to show when we activate module. array('always'='text') or array('FR'='text') //$this->warnings_activation_ext = array('FR'=>'WarningInstallationMayBecomeNotCompliantWithLaw'); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text') // Constants From 2a04d497da0a477d56e4e5d94d804ac34d8cbb2e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 16:40:55 +0200 Subject: [PATCH 23/47] Use a different css into timespent entry page when user is on holiday --- htdocs/core/lib/project.lib.php | 32 ++++--- htdocs/holiday/class/holiday.class.php | 113 ++++++++++++++++++++++--- htdocs/projet/activity/perday.php | 10 ++- htdocs/projet/activity/perweek.php | 23 ++++- 4 files changed, 151 insertions(+), 27 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 8233251d815..2e5799f970c 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -576,10 +576,10 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t * @param string $mine Show only task lines I am assigned to * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to * @param int $preselectedday Preselected day - * @param boolean $var Var for css of lines + * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @return $inc */ -function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='', $var=false) +function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable) { global $conf, $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; @@ -732,8 +732,12 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr print $tableCell; print ''; + $cssonholiday=''; + if (! $isavailable[$preselectedday]['morning']) $cssonholiday.='onholidaymorning '; + if (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon '; + // Duration - print ''; + print ''; $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]; $alreadyspent=''; @@ -783,8 +787,8 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $level++; if ($lines[$i]->id > 0) { - if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); - else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); + if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable); + else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable); } $level--; } @@ -798,7 +802,6 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr } - /** * Output a task line into a perday intput mode * @@ -812,10 +815,10 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr * @param string $tasksrole Array of roles user has on task * @param string $mine Show only task lines I am assigned to * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to - * @param boolean $var Var for css of lines + * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @return $inc */ -function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $var=false) +function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable) { global $conf, $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; @@ -851,7 +854,6 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ // Break on a new project if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) { - //$var = ! $var; $lastprojectid=$lines[$i]->fk_project; $projectstatic->id = $lines[$i]->fk_project; } @@ -966,13 +968,18 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ for ($idw = 0; $idw < 7; $idw++) { $tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd'); + + $cssonholiday=''; + if (! $isavailable[$tmpday]['morning']) $cssonholiday.='onholidaymorning '; + if (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon '; + $tmparray=dol_getdate($tmpday); $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]; $alreadyspent=''; if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin'); $alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']); - $tableCell =''; + $tableCell =''; if ($alreadyspent) { $tableCell.=''; @@ -1008,8 +1015,8 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $level++; if ($lines[$i]->id > 0) { - if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var); - else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var); + if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable); + else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable); } $level--; } @@ -1163,7 +1170,6 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= $sql2.= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee"; $sql2.= " ORDER BY p.title, p.ref"; - $var=true; $resql = $db->query($sql2); if ($resql) { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index ad9ead401dd..10589c9d0b4 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -284,7 +284,7 @@ class Holiday extends CommonObject * @param string $filter SQL Filter * @return int -1 if KO, 1 if OK, 2 if no result */ - function fetchByUser($user_id,$order='',$filter='') + function fetchByUser($user_id, $order='', $filter='') { global $langs, $conf; @@ -692,13 +692,17 @@ class Holiday extends CommonObject } /** - * verifDateHolidayCP + * Check if a user is on holiday (partially or completely) into a period. + * This function can be used to avoid to have 2 leave requests on same period for example. + * Warning: It consumes a lot of memory because it load in ->holiday all holiday of a dedicated user at each call. * * @param int $fk_user Id user - * @param date $dateDebut Start date - * @param date $dateFin End date - * @param int $halfday Tag to define half day when holiday start and end - * @return boolean + * @param date $dateDebut Start date of period to check + * @param date $dateFin End date of period to check + * @param int $halfday Tag to define how start and end the period to check: + * 0:Full days, 2:Sart afternoon end monring, -1:Start afternoon, 1:End morning + * @return boolean False is on holiday at least partially into the period, True is never on holiday during chcked period. + * @see verifDateHolidayForTimestamp */ function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday=0) { @@ -710,14 +714,103 @@ class Holiday extends CommonObject if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays // TODO Also use halfday for the check - if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) - { - return false; - } + if ($halfday == 0) + { + if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) + { + return false; + } + } + elseif ($halfday == -1) + { + if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) + { + return false; + } + } + elseif ($halfday == 1) + { + if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) + { + return false; + } + } + elseif ($halfday == 2) + { + if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) + { + return false; + } + } + else + { + dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP'); + } } return true; + } + + /** + * Check a user is not on holiday for a particular timestamp + * + * @param int $fk_user Id user + * @param timestamp $timestamp Time stamp date for a day (YYYY-MM-DD) without hours (= 12:00AM in english and not 12:00PM that is 12:00) + * @return array array('morning'=> ,'afternoon'=> ), Boolean is true if user is available for day timestamp. + * @see verifDateHolidayCP + */ + function verifDateHolidayForTimestamp($fk_user, $timestamp) + { + global $langs, $conf; + + $isavailablemorning=true; + $isavailableafternoon=true; + + $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday"; + $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; + $sql.= " WHERE cp.entity IN (".getEntity('holiday').")"; + $sql.= " AND cp.fk_user = ".(int) $fk_user; + $sql.= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'"; + + $resql = $this->db->query($sql); + if ($resql) + { + $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon + if ($num_rows > 0) + { + $i=0; + while ($i < $num_rows) + { + $obj = $this->db->fetch_object($resql); + + // Note: $obj->halday is 0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning + $arrayofrecord[$obj->rowid]=array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday); + $i++; + } + + // We found a record, user is on holiday by default, so is not available is true. + $isavailablemorning = true; + foreach($arrayofrecord as $record) + { + if ($timestamp == $record['date_start'] && $record['halfday'] == 2) continue; + if ($timestamp == $record['date_start'] && $record['halfday'] == -1) continue; + $isavailablemorning = false; + break; + } + $isavailableafternoon = true; + foreach($arrayofrecord as $record) + { + if ($timestamp == $record['date_end'] && $record['halfday'] == 2) continue; + if ($timestamp == $record['date_end'] && $record['halfday'] == 1) continue; + $isavailableafternoon = false; + break; + } + } + } + else dol_print_error($this->db); + + return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); } diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index da789675cb8..ad1815c5efc 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; $langs->load('projects'); $langs->load('users'); @@ -484,10 +485,17 @@ print "\n"; // By default, we can edit only tasks we are assigned to $restrictviewformytask=(empty($conf->global->PROJECT_TIME_SHOW_TASK_NOT_ASSIGNED)?1:0); +// Get if user is available or not for each day +$holiday = new Holiday($db); +$isavailable=array(); + +$isavailablefordayanduser = $holiday->verifDateHolidayForTimestamp($usertoprocess->id, $daytoparse); // $daytoparse is a date with hours = 0 +$isavailable[$daytoparse]=$isavailablefordayanduser; // in projectLinesPerWeek later, we are using $firstdaytoshow and dol_time_plus_duree to loop on each day + if (count($tasksarray) > 0) { $j=0; - projectLinesPerDay($j, 0, $usertoprocess, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse); + projectLinesPerDay($j, 0, $usertoprocess, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse, $isavailable); $colspan = 8; if (! empty($conf->global->PROJECT_LINES_PERDAY_SHOW_THIRDPARTY)) $colspan++; diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index c0482967c9e..caf2a3e4e84 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; $langs->load('projects'); $langs->load('users'); @@ -474,9 +475,25 @@ print ''.$langs->trans("TimeSpent").'' $startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']); -for($i=0;$i<7;$i++) +// Get if user is available or not for each day +$holiday = new Holiday($db); +$isavailable=array(); + +for ($i=0;$i<7;$i++) { - print ''.dol_print_date($startday + ($i * 3600 * 24), '%a').'
'.dol_print_date($startday + ($i * 3600 * 24), 'dayreduceformat').''; + $dayinloopfromfirstdaytoshow = dol_time_plus_duree($firstdaytoshow, $i, 'd'); // $firstdaytoshow is a date with hours = 0 + $dayinloop = dol_time_plus_duree($startday, $i, 'd'); + + // Useless because $dayinloopwithouthours should be same than $dayinloopfromfirstdaytoshow + //$tmparray = dol_getdate($dayinloop); + //$dayinloopwithouthours=dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); + //print dol_print_date($dayinloop, 'dayhour').' '; + //print dol_print_date($dayinloopwithouthours, 'dayhour').' '; + //print dol_print_date($dayinloopfromfirstdaytoshow, 'dayhour').'
'; + + $isavailablefordayanduser = $holiday->verifDateHolidayForTimestamp($usertoprocess->id, $dayinloopfromfirstdaytoshow); + $isavailable[$dayinloopfromfirstdaytoshow]=$isavailablefordayanduser; // in projectLinesPerWeek later, we are using $firstdaytoshow and dol_time_plus_duree to loop on each day + print ''.dol_print_date($dayinloopfromfirstdaytoshow, '%a').'
'.dol_print_date($dayinloopfromfirstdaytoshow, 'dayreduceformat').''; } print ''; print "\n"; @@ -491,7 +508,7 @@ if (count($tasksarray) > 0) $j=0; $level=0; - projectLinesPerWeek($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask); + projectLinesPerWeek($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $isavailable); $colspan=7; if (! empty($conf->global->PROJECT_LINES_PERWEEK_SHOW_THIRDPARTY)) $colspan++; From f4ddce727421d81f85a68111536c1f14bddd6024 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 17:05:50 +0200 Subject: [PATCH 24/47] FIX View of timespent for another user --- htdocs/projet/activity/perday.php | 2 +- htdocs/projet/activity/perweek.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 4dff34ad30b..3dbf7e32650 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -84,7 +84,7 @@ if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) $usertoprocess=$user; $search_usertoprocessid=$usertoprocess->id; } -elseif (search_usertoprocessid > 0) +elseif ($search_usertoprocessid > 0) { $usertoprocess=new User($db); $usertoprocess->fetch($search_usertoprocessid); diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index 6ea60f3d76f..3b6ce8efd91 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -97,7 +97,7 @@ if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) $usertoprocess=$user; $search_usertoprocessid=$usertoprocess->id; } -elseif (search_usertoprocessid > 0) +elseif ($search_usertoprocessid > 0) { $usertoprocess=new User($db); $usertoprocess->fetch($search_usertoprocessid); From 5f7631a95d83fe0fc26c8750f22ba50b06ef845a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 17:07:39 +0200 Subject: [PATCH 25/47] NEW Days where user is on vacation use different colors in timesheet. --- htdocs/core/lib/project.lib.php | 10 ++++++---- htdocs/projet/activity/perday.php | 2 +- htdocs/projet/activity/perweek.php | 2 +- htdocs/theme/eldy/style.css.php | 8 +++++++- htdocs/theme/md/style.css.php | 7 +++++++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 2e5799f970c..0de84d581f1 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -733,8 +733,9 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr print ''; $cssonholiday=''; - if (! $isavailable[$preselectedday]['morning']) $cssonholiday.='onholidaymorning '; - if (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon '; + if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayallday '; + elseif (! $isavailable[$preselectedday]['morning']) $cssonholiday.='onholidaymorning '; + elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon '; // Duration print ''; @@ -970,8 +971,9 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd'); $cssonholiday=''; - if (! $isavailable[$tmpday]['morning']) $cssonholiday.='onholidaymorning '; - if (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon '; + if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayallday '; + elseif (! $isavailable[$tmpday]['morning']) $cssonholiday.='onholidaymorning '; + elseif (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon '; $tmparray=dol_getdate($tmpday); $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]; diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index ad1815c5efc..c9c577742e6 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -85,7 +85,7 @@ if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) $usertoprocess=$user; $search_usertoprocessid=$usertoprocess->id; } -elseif (search_usertoprocessid > 0) +elseif ($search_usertoprocessid > 0) { $usertoprocess=new User($db); $usertoprocess->fetch($search_usertoprocessid); diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index caf2a3e4e84..b808017123d 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -98,7 +98,7 @@ if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) $usertoprocess=$user; $search_usertoprocessid=$usertoprocess->id; } -elseif (search_usertoprocessid > 0) +elseif ($search_usertoprocessid > 0) { $usertoprocess=new User($db); $usertoprocess->fetch($search_usertoprocessid); diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 3d58211fbde..a83d2ed9dd8 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -387,12 +387,18 @@ input.buttonpaymentstripe { background-repeat: no-repeat; background-position: 8px 7px; } +/* Used by timesheets */ span.timesheetalreadyrecorded input { border: none; border-bottom: solid 1px rgba(0,0,0,0.4); margin-right: 1px !important; } - +td.onholidaymorning, td.onholidayafternoon { + background-color: #fdf6f2; +} +td.onholidayallday { + background-color: #f4eede; +} select.flat, form.flat select { font-weight: normal; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 36fbd2bdd20..0f3711bf45b 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -384,11 +384,18 @@ input.buttonpaymentstripe { background-repeat: no-repeat; background-position: 8px 7px; } +/* Used for timesheets */ span.timesheetalreadyrecorded input { border: none; border-bottom: solid 1px rgba(0,0,0,0.1); margin-right: 1px !important; } +td.onholidaymorning, td.onholidayafternoon { + background-color: #fdf6f2; +} +td.onholidayallday { + background-color: #f4eede; +} select.flat, form.flat select { font-weight: normal; From 5643d4e867557f134daf56f64564f91203496107 Mon Sep 17 00:00:00 2001 From: tysauron Date: Tue, 19 Sep 2017 17:26:18 +0200 Subject: [PATCH 26/47] Rename "->fk_action" in "->type_id" (is old name) --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index cb6da443404..ec1c84dd652 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -754,7 +754,7 @@ class ActionComm extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; $sql.= " SET percent = '".$this->db->escape($this->percentage)."'"; - if ($this->fk_action > 0) $sql.= ", fk_action = '".$this->db->escape($this->fk_action)."'"; + if ($this->type_id > 0) $sql.= ", fk_action = '".$this->db->escape($this->type_id)."'"; $sql.= ", label = ".($this->label ? "'".$this->db->escape($this->label)."'":"null"); $sql.= ", datep = ".(strval($this->datep)!='' ? "'".$this->db->idate($this->datep)."'" : 'null'); $sql.= ", datep2 = ".(strval($this->datef)!='' ? "'".$this->db->idate($this->datef)."'" : 'null'); From c38ed5499054c0f80fc18231ba649abdf1b501d2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 17:31:37 +0200 Subject: [PATCH 27/47] Disable old datepicker --- htdocs/admin/system/perf.php | 2 +- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/core/lib/project.lib.php | 4 ++-- htdocs/main.inc.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/system/perf.php b/htdocs/admin/system/perf.php index 25079d8f185..3a8e1e42bf4 100644 --- a/htdocs/admin/system/perf.php +++ b/htdocs/admin/system/perf.php @@ -336,7 +336,7 @@ jQuery(document).ready(function() { var compjsphpstring; getjsphpurl = $.ajax({ type: "GET", - url: \''.DOL_URL_ROOT.'/core/js/datepicker.js.php\', + url: \''.DOL_URL_ROOT.'/core/js/lib_head.js.php\', cache: false, /* async: false, */ /* crossDomain: true,*/ diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bca87c7a65f..628be5660df 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5046,11 +5046,11 @@ class Form else return 'BadValueForParameterTypeHour'; if ($typehour!='text') $retstring.=' '.$langs->trans('HourShort'); - else $retstring.=':'; + else $retstring.=':'; // Minutes if ($minunderhours) $retstring.='
'; - else $retstring.=" "; + else $retstring.=' '; if ($typehour=='select' || $typehour=='textselect') { diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 0de84d581f1..af49fa6b27d 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -738,7 +738,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon '; // Duration - print ''; + print ''; $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]; $alreadyspent=''; @@ -748,7 +748,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $tableCell=''; $tableCell.=''; - $tableCell.=' + '; + $tableCell.=' + '; //$tableCell.='   '; $tableCell.=$form->select_duration($lines[$i]->id.'duration','',$disabledtask,'text',0,1); //$tableCell.=' '; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 06a6b4658ae..675c82aa499 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1322,10 +1322,10 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs print ''."\n"; // Add datepicker default options - if (! defined('DISABLE_DATE_PICKER')) + /*if (! defined('DISABLE_DATE_PICKER')) { print ''."\n"; - } + }*/ // JS forced by modules (relative url starting with /) if (! empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) From ffe2ee82324cc266bacd093edcf88cd0e3ca6691 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 19:00:28 +0200 Subject: [PATCH 28/47] Standardize code --- htdocs/compta/bank/index.php | 17 ++++++++--------- htdocs/core/menus/standard/eldy.lib.php | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/bank/index.php b/htdocs/compta/bank/index.php index 80bf9d6f50c..5a0ab062b29 100644 --- a/htdocs/compta/bank/index.php +++ b/htdocs/compta/bank/index.php @@ -46,7 +46,7 @@ $toselect = GETPOST('toselect', 'array'); $search_ref=GETPOST('search_ref','alpha'); $search_label=GETPOST('search_label','alpha'); $search_number=GETPOST('search_number','alpha'); -$statut=GETPOST('statut')?GETPOST('statut', 'alpha'):'opened'; // 'all' or ''='opened' +$search_status=GETPOST('search_status')?GETPOST('search_status', 'alpha'):'opened'; // 'all' or ''='opened' $optioncss = GETPOST('optioncss','alpha'); // Security check @@ -123,11 +123,10 @@ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers { - $statut = 'all'; $search_ref=''; $search_label=''; $search_number=''; - $search_statut=''; + $search_status=''; } @@ -153,8 +152,8 @@ $sql.=$hookmanager->resPrint; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as b"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bankcacount_extrafields as ef on (c.rowid = ef.fk_object)"; $sql.= " WHERE entity IN (".getEntity('bank_account').")"; -if ($statut == 'opened') $sql.= " AND clos = 0"; -if ($statut == 'closed') $sql.= " AND clos = 1"; +if ($search_status == 'opened') $sql.= " AND clos = 0"; +if ($search_status == 'closed') $sql.= " AND clos = 1"; if ($search_ref != '') $sql.=natural_search('b.ref', $search_ref); if ($search_label != '') $sql.=natural_search('b.label', $search_label); if ($search_number != '') $sql.=natural_search('b.number', $search_number); @@ -222,7 +221,7 @@ if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($search_ref != '') $param.='&search_ref='.$search_ref; if ($search_label != '') $param.='&search_label='.$search_label; if ($search_number != '') $param.='&search_number='.$search_number; -if ($statut != '') $param.='&statut='.$statut; +if ($search_status != '') $param.='&search_status='.$search_status; if ($show_files) $param.='&show_files=' .$show_files; if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields @@ -377,7 +376,7 @@ if (! empty($arrayfields['b.tms']['checked'])) print ''; print ''; } -// Statut +// Status if (! empty($arrayfields['b.clos']['checked'])) { print ''; @@ -385,7 +384,7 @@ if (! empty($arrayfields['b.clos']['checked'])) 'opened'=>$langs->trans("Opened"), 'closed'=>$langs->trans("Closed") ); - print $form->selectarray("statut", $array, $statut, 1); + print $form->selectarray("search_status", $array, $search_status, 1); print ''; } // Balance @@ -584,7 +583,7 @@ foreach ($accounts as $key=>$type) if (! $i) $totalarray['nbfield']++; } - // Statut + // Status if (! empty($arrayfields['b.clos']['checked'])) { print ''.$acc->getLibStatut(5).''; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index fb503cfea9d..55d3b75fe13 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -977,7 +977,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/defaultaccounts.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuDefaultAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); if (! empty($conf->banque->enabled)) { - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/compta/bank/index.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuBankAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_bank', 51); + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/compta/bank/index.php?mainmenu=accountancy&leftmenu=accountancy_admin&search_status=-1", $langs->trans("MenuBankAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_bank', 51); } if (! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled)) { From f87614e2d396cdd4044afdfdb16e3074291ad15d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 19:12:54 +0200 Subject: [PATCH 29/47] Fix missing translation --- htdocs/compta/prelevement/class/bonprelevement.class.php | 1 + htdocs/compta/prelevement/create.php | 2 +- htdocs/langs/en_US/withdrawals.lang | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 0278d97d724..a3d50d58143 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -953,6 +953,7 @@ class BonPrelevement extends CommonObject { $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $this->id = $prev_id; + $this->ref = $ref; } else { diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 6743ea3098b..09102ec1309 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -80,7 +80,7 @@ if ($action == 'create') } else { - setEventMessages($langs->trans("DirectDebitOrderCreated"), null); + setEventMessages($langs->trans("DirectDebitOrderCreated", $bprev->getNomUrl(1)), null); } } diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index 8e80a111516..29b5766215b 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -12,7 +12,7 @@ WithdrawalsLines=Direct debit order lines RequestStandingOrderToTreat=Request for direct debit payment order to process RequestStandingOrderTreated=Request for direct debit payment order processed NotPossibleForThisStatusOfWithdrawReceiptORLine=Not yet possible. Withdraw status must be set to 'credited' before declaring reject on specific lines. -NbOfInvoiceToWithdraw=Nb. of invoice with direct debit order +NbOfInvoiceToWithdraw=Nb. of qualified invoice with waiting direct debit order NbOfInvoiceToWithdrawWithInfo=Nb. of customer invoice with direct debit payment orders having defined bank account information InvoiceWaitingWithdraw=Invoice waiting for direct debit AmountToWithdraw=Amount to withdraw @@ -94,6 +94,7 @@ SEPAFrstOrRecur=Type of payment ModeRECUR=Reccurent payment ModeFRST=One-off payment PleaseCheckOne=Please check one only +DirectDebitOrderCreated=Direct debit order %s created ### Notifications InfoCreditSubject=Payment of direct debit payment order %s by the bank From 6a0ef4b561ab32717f53d1d4528c96fa12a57f10 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 19:29:00 +0200 Subject: [PATCH 30/47] Fix info ot total in direct debit page --- htdocs/compta/prelevement/factures.php | 29 ++++++++++++++++---------- htdocs/langs/en_US/withdrawals.lang | 3 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/htdocs/compta/prelevement/factures.php b/htdocs/compta/prelevement/factures.php index f7e41bdc997..60215005446 100644 --- a/htdocs/compta/prelevement/factures.php +++ b/htdocs/compta/prelevement/factures.php @@ -145,9 +145,9 @@ if ($prev_id > 0 || $ref) // List of invoices -$sql = "SELECT pf.rowid"; -$sql.= ",f.rowid as facid, f.facnumber as ref, f.total_ttc"; -$sql.= ", s.rowid as socid, s.nom as name, pl.statut"; +$sql = "SELECT pf.rowid,"; +$sql.= " f.rowid as facid, f.facnumber as ref, f.total_ttc,"; +$sql.= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql.= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture as pf"; @@ -202,14 +202,14 @@ if ($result) print ''; print_liste_field_titre("Bill",$_SERVER["PHP_SELF"],"p.ref",'',$param,'',$sortfield,$sortorder); print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",'',$param,'',$sortfield,$sortorder); - print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre("AmountInvoice",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre("AmountRequested",$_SERVER["PHP_SELF"],"pl.amount_requested","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre("StatusDebitCredit",$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre(''); print "\n"; - $var=false; - - $total = 0; + $totalinvoices = 0; + $totalamount_requested = 0; while ($i < min($num, $limit)) { @@ -231,9 +231,12 @@ if ($result) print $thirdpartytmp->getNomUrl(1); print "\n"; - // Amount + // Amount of invoice print ''.price($obj->total_ttc)."\n"; + // Amount requested + print ''.price($obj->amount_requested)."\n"; + // Status of requests print ''; @@ -256,7 +259,8 @@ if ($result) print "\n"; - $total += $obj->total_ttc; + $totalinvoices += $obj->total_ttc; + $totalamount_requested += $obj->amount_requested; $i++; } @@ -267,8 +271,11 @@ if ($result) print ''.$langs->trans("Total").''; print ' '; print ''; - if ($total != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices"); - print price($total); + //if ($totalinvoices != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices"); // It is normal to have total that differs. For an amount of invoice of 100, request to pay may be 50 only. + if ($totalamount_requested != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices"); + print "\n"; + print ''; + print price($totalamount_requested); print "\n"; print ' '; print ' '; diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index 29b5766215b..308987575f5 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -72,7 +72,7 @@ IfInvoiceNeedOnWithdrawPaymentWontBeClosed=However, if invoice has at least one DoStandingOrdersBeforePayments=This tab allows you to request a direct debit payment order. Once done, go into menu Bank->Direct Debit orders to manage the direct debit payment order. When payment order is closed, payment on invoice will be automatically recorded, and invoice closed if remainder to pay is null. WithdrawalFile=Withdrawal file SetToStatusSent=Set to status "File Sent" -ThisWillAlsoAddPaymentOnInvoice=This will also apply payments to invoices and will classify them as "Paid" +ThisWillAlsoAddPaymentOnInvoice=This will also record payments to invoices and will classify them as "Paid" if remain to pay is null StatisticsByLineStatus=Statistics by status of lines RUM=UMR RUMLong=Unique Mandate Reference @@ -95,6 +95,7 @@ ModeRECUR=Reccurent payment ModeFRST=One-off payment PleaseCheckOne=Please check one only DirectDebitOrderCreated=Direct debit order %s created +AmountRequested=Amount requested ### Notifications InfoCreditSubject=Payment of direct debit payment order %s by the bank From 04e1458a3f1e47f7f42831cc4b57af68acbc7dff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 22:03:44 +0200 Subject: [PATCH 31/47] Fix clean parameters --- .../facture/class/facture-rec.class.php | 3 +++ htdocs/contrat/class/contrat.class.php | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index b12f848323d..b3a8a68611d 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -715,6 +715,9 @@ class FactureRec extends CommonInvoice dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; + // Clean parameters + if (empty($remise_percent)) $remise_percent = 0; + // Check parameters if ($type < 0) return -1; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 6e9fc443e03..69bda6f2b1c 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -538,11 +538,13 @@ class Contrat extends CommonObject /** * Load a contract from database * - * @param int $id Id of contract to load - * @param string $ref Ref - * @return int <0 if KO, id of contract if OK + * @param int $id Id of contract to load + * @param string $ref Ref + * @param string $ref_customer Customer ref + * @param string $ref_supplier Supplier ref + * @return int <0 if KO, 0 if not found, Id of contract if OK */ - function fetch($id,$ref='') + function fetch($id, $ref='', $ref_customer='', $ref_supplier='') { $sql = "SELECT rowid, statut, ref, fk_soc, mise_en_service as datemise,"; $sql.= " ref_supplier, ref_customer,"; @@ -553,12 +555,20 @@ class Contrat extends CommonObject $sql.= " fk_commercial_signature, fk_commercial_suivi,"; $sql.= " note_private, note_public, model_pdf, extraparams"; $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; + if (! $id) $sql.=" WHERE entity IN (".getEntity('contract', 0).")"; + else $sql.= " WHERE rowid=".$id; + if ($ref_customer) + { + $sql.= " AND ref_customer = '".$this->db->escape($ref_customer)."'"; + } + if ($ref_supplier) + { + $sql.= " AND ref_supplier = '".$this->db->escape($ref_supplier)."'"; + } if ($ref) { - $sql.= " WHERE ref='".$this->db->escape($ref)."'"; - $sql.= " AND entity IN (".getEntity('contract', 0).")"; + $sql.= " AND ref='".$this->db->escape($ref)."'"; } - else $sql.= " WHERE rowid=".$id; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -628,7 +638,7 @@ class Contrat extends CommonObject { dol_syslog(get_class($this)."::Fetch Erreur contrat non trouve"); $this->error="Contract not found"; - return -2; + return 0; } } else @@ -2834,6 +2844,7 @@ class ContratLigne extends CommonObjectLine if (empty($this->total_ttc)) $this->total_ttc = 0; if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->remise_percent)) $this->remise_percent = 0; // Check parameters // Put here code to add control on parameters values From cfd29841e10117b8c0fda4f9c295d44d2de99436 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Sep 2017 23:42:20 +0200 Subject: [PATCH 32/47] NEW Option STOCK_SUPPORTS_SERVICES become visible. --- htdocs/admin/stock.php | 172 ++++++++++++++++++--------------- htdocs/langs/en_US/stocks.lang | 4 +- 2 files changed, 97 insertions(+), 79 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index f7e18851306..a2f0a4b5346 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -45,6 +45,10 @@ if($action) { $db->begin(); + if ($action == 'STOCK_SUPPORTS_SERVICES') + { + $res = dolibarr_set_const($db, "STOCK_SUPPORTS_SERVICES", GETPOST('STOCK_SUPPORTS_SERVICES','alpha'),'chaine',0,'',$conf->entity); + } if ($action == 'STOCK_USERSTOCK_AUTOCREATE') { $res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity); @@ -164,8 +168,8 @@ $found=0; print ''; -print ''.$langs->trans("DeStockOnBill").''; -print ''; +print ''.$langs->trans("DeStockOnBill").''; +print ''; if (! empty($conf->facture->enabled)) { print ""; @@ -184,8 +188,8 @@ $found++; print ''; -print ''.$langs->trans("DeStockOnValidateOrder").''; -print ''; +print ''.$langs->trans("DeStockOnValidateOrder").''; +print ''; if (! empty($conf->commande->enabled)) { print ""; @@ -206,8 +210,8 @@ $found++; //{ print ''; -print ''.$langs->trans("DeStockOnShipment").''; -print ''; +print ''.$langs->trans("DeStockOnShipment").''; +print ''; if (! empty($conf->expedition->enabled)) { print ""; @@ -226,8 +230,8 @@ $found++; print ''; -print ''.$langs->trans("DeStockOnShipmentOnClosing").''; -print ''; +print ''.$langs->trans("DeStockOnShipmentOnClosing").''; +print ''; if (! empty($conf->expedition->enabled)) { print ""; @@ -268,8 +272,8 @@ $found=0; print ''; -print ''.$langs->trans("ReStockOnBill").''; -print ''; +print ''.$langs->trans("ReStockOnBill").''; +print ''; if (! empty($conf->fournisseur->enabled)) { print ""; @@ -289,8 +293,8 @@ $found++; print ''; -print ''.$langs->trans("ReStockOnValidateOrder").''; -print ''; +print ''.$langs->trans("ReStockOnValidateOrder").''; +print ''; if (! empty($conf->fournisseur->enabled)) { print ""; @@ -309,8 +313,8 @@ $found++; print ''; -print ''.$langs->trans("ReStockOnDispatchOrder").''; -print ''; +print ''.$langs->trans("ReStockOnDispatchOrder").''; +print ''; if (! empty($conf->fournisseur->enabled)) { print ""; @@ -346,8 +350,8 @@ print ''."\n"; print ''; -print ''.$langs->trans("WarehouseAllowNegativeTransfer").''; -print ''; +print ''.$langs->trans("WarehouseAllowNegativeTransfer").''; +print ''; print ""; print ''; print ""; @@ -361,8 +365,8 @@ print "\n"; if($conf->invoice->enabled) { $var = !$var; print ''; - print ''.$langs->trans("StockMustBeEnoughForInvoice").''; - print ''; + print ''.$langs->trans("StockMustBeEnoughForInvoice").''; + print ''; print ""; print ''; print ""; @@ -376,8 +380,8 @@ if($conf->invoice->enabled) { if($conf->order->enabled) { $var = !$var; print ''; - print ''.$langs->trans("StockMustBeEnoughForOrder").''; - print ''; + print ''.$langs->trans("StockMustBeEnoughForOrder").''; + print ''; print ""; print ''; print ""; @@ -391,8 +395,8 @@ if($conf->order->enabled) { if($conf->expedition->enabled) { $var = !$var; print ''; - print ''.$langs->trans("StockMustBeEnoughForShipment").''; - print ''; + print ''.$langs->trans("StockMustBeEnoughForShipment").''; + print ''; print ""; print ''; print ""; @@ -404,6 +408,9 @@ if($conf->expedition->enabled) { } print ''; + +print '
'; + $virtualdiffersfromphysical=0; if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) @@ -411,7 +418,6 @@ if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) if ($virtualdiffersfromphysical) { - print '
'; print ''; print ''; print " \n"; @@ -419,8 +425,8 @@ if ($virtualdiffersfromphysical) print ''."\n"; $var = !$var; print ''; - print ''; - print ''; + print '\n"; print "\n"; print '
".$langs->trans("RuleForStockReplenishment")." ".img_help('help',$langs->trans("VirtualDiffersFromPhysical"))."
'.$langs->trans("UseVirtualStockByDefault").''; + print ''.$langs->trans("UseVirtualStockByDefault").''; print ""; print ''; print ""; @@ -430,9 +436,70 @@ if ($virtualdiffersfromphysical) print "
'; + print '
'; } +print ''; + +print ''; +print " \n"; +print " \n"; +print ''."\n"; + +print ''; +print ''; +print '\n"; +print "\n"; + +print ''; +print ''; +print '\n"; +print "\n"; + +print ''; +print ''; +print '\n"; +print "\n"; + +if (! empty($conf->fournisseur->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) { + + print ''; + print ''; + print '\n\n"; +} + +print '
".$langs->trans("Other")." 
'.$langs->trans("UserWarehouseAutoCreate").''; +print ""; +print ''; +print ""; +print $form->selectyesno("STOCK_USERSTOCK_AUTOCREATE",$conf->global->STOCK_USERSTOCK_AUTOCREATE,1); +print ''; +print ''; +print "
'; +print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc")).''; +print "
"; +print ''; +print ""; +print $form->selectyesno("STOCK_SUPPORTS_SERVICES",$conf->global->STOCK_SUPPORTS_SERVICES,1); +print ''; +print '
'; +print "
'.$langs->trans("AllowAddLimitStockByWarehouse").''; +print "
"; +print ''; +print ""; +print $form->selectyesno("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE",$conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE,1); +print ''; +print '
'; +print "
'.$langs->trans("UseDispatchStatus").''; + print "
"; + print ''; + print ""; + print $form->selectyesno("SUPPLIER_ORDER_USE_DISPATCH_STATUS",$conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS,1); + print ''; + print "
\n"; + print "
'; + print '
'; if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { @@ -484,54 +551,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print ''; } -print ''; - -print ''; -print " \n"; -print " \n"; -print ''."\n"; - -if (! empty($conf->fournisseur->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) { - - print ''; - print ''; - print '\n\n"; -} - -print ''; -print ''; -print '\n"; -print "\n"; - -print ''; -print ''; - -print '\n"; -print "\n"; - -print '
'; - /* I keep the option/feature, but hidden to end users for the moment. If feature is used by module, no need to have users see it. If not used by a module, I still need to understand in which case user may need this now we can set rule on product page. if ($conf->global->PRODUIT_SOUSPRODUITS) @@ -539,9 +558,8 @@ if ($conf->global->PRODUIT_SOUSPRODUITS) print ''; - print ''; - - print ''; + print '
".$langs->trans("Other")." 
'.$langs->trans("UseDispatchStatus").''; - print "
"; - print ''; - print ""; - print $form->selectyesno("SUPPLIER_ORDER_USE_DISPATCH_STATUS",$conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS,1); - print ''; - print "
\n"; - print "
'.$langs->trans("UserWarehouseAutoCreate").''; -print "
"; -print ''; -print ""; -print $form->selectyesno("STOCK_USERSTOCK_AUTOCREATE",$conf->global->STOCK_USERSTOCK_AUTOCREATE,1); -print ''; -print '
'; -print "
'.$langs->trans("AllowAddLimitStockByWarehouse").''; -print "
"; -print ''; -print ""; -print $form->selectyesno("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE",$conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE,1); -print ''; -print '
'; -print "
'.$langs->trans("IndependantSubProductStock").''; + print ''.$langs->trans("IndependantSubProductStock").''; print "
"; print ''; print ""; @@ -553,8 +571,6 @@ if ($conf->global->PRODUIT_SOUSPRODUITS) } */ -print '
'; - llxFooter(); diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index cda14147ece..6019977120e 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -195,4 +195,6 @@ InventoryFlushed=Inventory flushed ExitEditMode=Exit edition inventoryDeleteLine=Delete line RegulateStock=Regulate Stock -ListInventory=List \ No newline at end of file +ListInventory=List +StockSupportServices=Stock management support services +StockSupportServicesDesc=By default, you can stock only product with type "product". If on, and if module service is on, you can also stock a product with type "service" \ No newline at end of file From 8bb3130aab8ba7d0ae6600c2efdec472bf8796b4 Mon Sep 17 00:00:00 2001 From: tysauron Date: Wed, 20 Sep 2017 00:35:52 +0200 Subject: [PATCH 33/47] For use ajax select company --- htdocs/projet/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 97f9ff41d54..1146ba49b80 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -528,7 +528,7 @@ if ($action == 'create' && $user->rights->projet->creer) print ''; $filteronlist=''; if (! empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) $filteronlist=$conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST; - $text=$form->select_thirdparty_list(GETPOST('socid','int'), 'socid', $filteronlist, 'SelectThirdParty', 1, 0, array(), '', 0, 0, 'minwidth300'); + $text=$form->select_company(GETPOST('socid','int'), 'socid', $filteronlist, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth300'); if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) { $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); @@ -747,7 +747,7 @@ elseif ($object->id > 0) print ''; $filteronlist=''; if (! empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) $filteronlist=$conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST; - $text=$form->select_thirdparty_list($object->thirdparty->id, 'socid', $filteronlist, 'None', 1, 0, array(), '', 0, 0, 'minwidth300'); + $text=$form->select_company($object->thirdparty->id, 'socid', $filteronlist, 'None', 1, 0, array(), 0, 'minwidth300'); if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) { $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); From 3220225af3377ec32ecabcce2da9852cedfffdd0 Mon Sep 17 00:00:00 2001 From: tysauron Date: Wed, 20 Sep 2017 00:53:48 +0200 Subject: [PATCH 34/47] Bug get socid with old object sosciete --- htdocs/projet/tasks/contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 3d834fe28b6..6cdbc204749 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -397,7 +397,7 @@ if ($id > 0 || ! empty($ref)) print ''; $thirdpartyofproject=$projectstatic->getListContactId('thirdparty'); - $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id; + $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->socid; $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', $thirdpartyofproject, 0, '&withproject='.$withproject); print ''; From 1314e00bc642b3085755865b621c7310b0c297d2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 20 Sep 2017 14:46:51 +0200 Subject: [PATCH 35/47] Fix: check if array and check empty value if required --- htdocs/core/class/extrafields.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 12d958b6ebb..53327f67a15 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1708,7 +1708,7 @@ class ExtraFields if (! empty($onlykey) && $key != $onlykey) continue; $key_type = $this->attribute_type[$key]; - if($this->attribute_required[$key] && !GETPOST("options_$key",2)) + if ($this->attribute_required[$key] && empty($_POST["options_".$key])) // Check if empty without GETPOST, value can be alpha, int, array, etc... { $nofillrequired++; $error_field_required[] = $value; @@ -1721,7 +1721,7 @@ class ExtraFields } else if (in_array($key_type,array('checkbox','chkbxlst'))) { - $value_arr=GETPOST("options_".$key); + $value_arr=GETPOST("options_".$key, 'array'); // check if an array if (!empty($value_arr)) { $value_key=implode($value_arr,','); }else { @@ -1740,7 +1740,7 @@ class ExtraFields $object->array_options["options_".$key]=$value_key; } - if($nofillrequired) { + if ($nofillrequired) { $langs->load('errors'); setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors'); return -1; From 1d6213ea7d829767834ebe5486e7ef8422c65546 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Sep 2017 15:29:47 +0200 Subject: [PATCH 36/47] Add picto for cheque payment --- htdocs/public/payment/newpayment.php | 2 +- htdocs/theme/common/cheque.png | Bin 0 -> 2483 bytes htdocs/theme/eldy/style.css.php | 26 +++++++++----------------- htdocs/theme/md/style.css.php | 6 ++++-- 4 files changed, 14 insertions(+), 20 deletions(-) create mode 100644 htdocs/theme/common/cheque.png diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 72ad0390cce..62f82bc33d1 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -602,7 +602,7 @@ print $text; // Output payment summary form print ''; print ''; -print ''."\n"; +print ''."\n"; $found=false; $error=0; diff --git a/htdocs/theme/common/cheque.png b/htdocs/theme/common/cheque.png new file mode 100644 index 0000000000000000000000000000000000000000..34b89a1e1d010a5fc6246970393cecced8228904 GIT binary patch literal 2483 zcmV;k2~75hP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00|pOL_t(|+U=ct>>O1U$3L^b z<=2*4i@ZcAEttw1g_v0^yyI z5RkXLA%zeWLjkomk%uk){r0!lKkl9U&febHojW_TGdp{~$!2HnJa*=M@44sPbI-jC z0RbtoB@hKM3^zUv`~>(AQ0DVAaBvXK@Zox3y&$q}J_?usE(#(V4$J_au}E}%CV?*o zaaA8@q#!fa)ZYhjRUdCS2vxuaV4ZcW1nLipCn%fv{ z;2pF5u4i{d883K`KtZ{L{!VOv46HTVE#Q35d(8rl4iuD+2ZgiqBT+uj1QXgGpAUjK z%f}*ND>qrq@x2~)G`6MR4I(WUvw_zIA?Jx>hi4%4-5}EPaj76~Eif*Qz2!;j1h6!S zv|P*-q)pN}fPHiZE&X#4Y5Dk-aE|^Y%I5SZskOp>5zJV4EP;a&dwnZauJ_IChsOsZ&gc5(7%aI$=vs73I5R(9)-Z zILpV0g3vcb`8Ya-)7LpVAc(YFY;A%AF(I-~xh#Wo^l}hs`M5=BscbeQbP(T%)J?$W zgGkH8d_mg(fc?a=3o~fxWkICn<1V44zqSGm>j|SULx(R2P26A|Tb02%S{6iFE@lC* z2ts}=j(weMqc9;HSTfEN#I3UkdEJxL7I173Y58aw;#$C0MfsQLoe5}X*{=%XEFYH$ za_$r5TLP~+NNgD==p5iG2dT4yNXx}ert1*TQa0&_0T1Dx z%#`#ZOT_g{@gJJ23!#g6GbKVf;oD-*gc-Eg+po8I0AV-X_ zOwND_waML;=|r-4wG>|sJI90(LC;UUJ7{S+gvKOZD)yfTp73;z<^V@o4p)FdGlQ$F zfWI3Xh83EkOPLI5?ST%|1AGtot7j!V!vrn>{spW+kLDCn0iy)-5hav$>#il4q$r_W z89(GxUC!;>%Uw(I3Mg6ouPRIX0KQyfLY0rXYvir+Ilwpa6VaK^RClx3 z_jsrp@C)3Dj{f-IH1x8rqhLb^Ho%={py5`}mSG(D>4-GB?K}uo1J>FV8D9G5HP+I? zHMD5E`XYKdzt8WC0pA<}4IL^kSK{0ZmF$>Nj}-nw?qbto;Yf{(pcS60UcRFS-a$GoI;E0Q-8? zLw57>Xo91ZLV5;0zXWt9-<~D_;Cirr>}$NpMvU3$6~>gu^*0M!8V!-7G?C!JE;9Z^ zT-go<9`EOeeNfg43m?apsBT==@tB>{Vl@C>nM`H=r}^BM$)_ zSR+E)J~p&UH*?$K;2!2DC`_FYW z!CT{w3Mn>^?AY7gu1k_v2{VDSm>yQU(R|;KveGQ4 z+N+Yy0KR43rX*>80@#S2Dp-_Vj?nQ=iL=mC3s140(@tUe1)b{x4a$l0v40bJbX%G! z1)282S|vCPrvm>3ejrGD((zn_ezwY@=-Fp^5jzhZB7CG~UalRSUpy!qT6Q0GEqWo2 zy1~mSY7kI$c-j6y=S$=+frYwi=<(?I zt`b22nR1%6qDj(zQoPn)WLaJ#_a8y8F4LEWHb=PTuddkh{08`03S}Y>LhEQVuOc~T z7fXYZ%6pC2bX&Vgo;!wK5v}iTOWIg&9c|{hL-L%tr=SFnwpxUSNYN;Hxmmj{0Ylv6 z+BdDMO|2>>ite_|Ku=csK>UE57MP^rip{4FMkG(`vtK}^Xg%ycp=+vNWc59ho|T0A z+POfzDz`10ZYy>wM;~Upszk$7{RUI6J>KX{By? xUmUhJ>D^s_#^>@kVw<{}9P)Pq0s_jw{{h9JxNccM6oLQ%002ovPDHLkV1ffXjZy#r literal 0 HcmV?d00001 diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index a83d2ed9dd8..1c991f9ccd7 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -344,48 +344,40 @@ input.buttongen { vertical-align: middle; } input.buttonpayment { - width: 300px; + min-width: 280px; margin-bottom: 15px; background-image: none; line-height: 24px; padding: 8px; + background: none; + border: 2px solid #666666; } input.buttonpaymentcb { background-image: url(); background-size: 26px; background-repeat: no-repeat; - background-position: 5px 5px; + background-position: 2px 11px; } input.buttonpaymentcheque { background-image: url(); - background-repeat: no-repeat; - background-position: 8px 7px; -} -input.buttonpaymentcb { - background-image: url(); background-size: 24px; background-repeat: no-repeat; - background-position: 5px 4px; -} -input.buttonpaymentcheque { - background-image: url(); - background-repeat: no-repeat; - background-position: 5px 4px; + background-position: 2px 8px; } input.buttonpaymentpaypal { background-image: url(); background-repeat: no-repeat; - background-position: 8px 7px; + background-position: 8px 11px; } input.buttonpaymentpaybox { background-image: url(); background-repeat: no-repeat; - background-position: 8px 7px; + background-position: 8px 11px; } input.buttonpaymentstripe { background-image: url(); background-repeat: no-repeat; - background-position: 8px 7px; + background-position: 8px 11px; } /* Used by timesheets */ span.timesheetalreadyrecorded input { @@ -3147,7 +3139,7 @@ div.titre { /* text-shadow: 1px 1px 2px #FFFFFF; */ } -#dolpaymenttable { width: 600px; font-size: 13px; } +#dolpaymenttable { max-width: 600px; font-size: 16px; } #tablepublicpayment { border: 1px solid #CCCCCC !important; width: 100%; padding: 20px; } #tablepublicpayment .CTableRow1 { background-color: #F0F0F0 !important; } #tablepublicpayment tr.liste_total { border-bottom: 1px solid #CCCCCC !important; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 0f3711bf45b..1ed9b433be7 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -341,11 +341,13 @@ input.buttongen { vertical-align: middle; } input.buttonpayment { - width: 300px; + min-width: 280px; margin-bottom: 15px; background-image: none; line-height: 24px; padding: 8px; + background: none; + border: 2px solid #666666; } input.buttonpaymentcb { background-image: url(); @@ -3237,7 +3239,7 @@ div.titre { dol_optimize_smallscreen)?'':'margin-top: 4px;'); ?> } -#dolpaymenttable { width: 600px; font-size: 13px; } +#dolpaymenttable { max-width: 600px; font-size: 16px; } #tablepublicpayment { border: 1px solid #CCCCCC !important; width: 100%; padding: 20px; } #tablepublicpayment .CTableRow1 { background-color: #F0F0F0 !important; } #tablepublicpayment tr.liste_total { border-bottom: 1px solid #CCCCCC !important; } From 577c64cc3735d6db8f75ee7efbe1767b606b7dfa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Sep 2017 17:23:36 +0200 Subject: [PATCH 37/47] WIP work on param download on payment page --- htdocs/compta/facture/class/facture.class.php | 17 +++++++++++++++++ htdocs/public/payment/newpayment.php | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 76b41f3ce86..41cc8042144 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1051,6 +1051,23 @@ class Facture extends CommonInvoice else return -1; } + /** + * Return link to download file from a direct external access + * + * @param int $withpicto Add download picto into link + * @return string HTML link to file + */ + function getDirectExternalLink($withpicto=0) + { + // Define $urlwithroot + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + $url='eee'; + return ''.$this->ref.''; + } + /** * Return clicable link of object (with eventually picto) * diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 62f82bc33d1..0c8fbbc733d 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -808,7 +808,7 @@ if ($source == 'invoice') print ''."\n"; // Debitor @@ -821,8 +821,8 @@ if ($source == 'invoice') $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; print ''."\n"; // Amount @@ -846,13 +846,21 @@ if ($source == 'invoice') print ''."\n"; // Tag - print ''."\n"; + // Add download link + if (GETPOST('download','int') > 0) + { + print ''."\n"; + } + // Shipping address $shipToName=$invoice->thirdparty->name; $shipToStreet=$invoice->thirdparty->address; From 2f317c583400dfeb326364acd530ba9d1a98b117 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Sep 2017 19:34:14 +0200 Subject: [PATCH 38/47] Debug online payment using unique form --- htdocs/public/payment/newpayment.php | 55 ++++++++++++++-------------- htdocs/public/payment/paymentko.php | 2 +- htdocs/public/payment/paymentok.php | 5 +-- htdocs/theme/eldy/style.css.php | 4 +- htdocs/theme/md/style.css.php | 5 ++- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 0c8fbbc733d..faf40e17067 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -66,21 +66,21 @@ $suffix=GETPOST("suffix",'aZ09'); $amount=price2num(GETPOST("amount",'alpha')); if (! GETPOST("currency",'alpha')) $currency=$conf->currency; else $currency=GETPOST("currency",'alpha'); -$source = GETPOST("source",'alpha'); +$source = GETPOST("s",'alpha')?GETPOST("s",'alpha'):GETPOST("source",'alpha'); if (! $action) { - if (! GETPOST("amount",'alpha') && ! GETPOST("source",'alpha')) + if (! GETPOST("amount",'alpha') && ! $source) { print $langs->trans('ErrorBadParameters')." - amount or source"; exit; } - if (is_numeric($amount) && ! GETPOST("tag",'alpha') && ! GETPOST("source",'alpha')) + if (is_numeric($amount) && ! GETPOST("tag",'alpha') && ! $source) { print $langs->trans('ErrorBadParameters')." - tag or source"; exit; } - if (GETPOST("source",'alpha') && ! GETPOST("ref",'alpha')) + if ($source && ! GETPOST("ref",'alpha')) { print $langs->trans('ErrorBadParameters')." - ref"; exit; @@ -111,7 +111,6 @@ $urlok=$urlwithroot.'/public/payment/paymentok.php?'; $urlko=$urlwithroot.'/public/payment/paymentko.php?'; // Complete urls for post treatment -$SOURCE=GETPOST("source",'alpha'); $ref=$REF=GETPOST('ref','alpha'); $TAG=GETPOST("tag",'alpha'); $FULLTAG=GETPOST("fulltag",'alpha'); // fulltag is tag with more informations @@ -123,10 +122,10 @@ if (! empty($suffix)) $urlok.='suffix='.urlencode($suffix).'&'; $urlko.='suffix='.urlencode($suffix).'&'; } -if (! empty($SOURCE)) +if ($source) { - $urlok.='source='.urlencode($SOURCE).'&'; - $urlko.='source='.urlencode($SOURCE).'&'; + $urlok.='s='.urlencode($source).'&'; + $urlko.='s='.urlencode($source).'&'; } if (! empty($REF)) { @@ -143,15 +142,16 @@ if (! empty($FULLTAG)) $urlok.='fulltag='.urlencode($FULLTAG).'&'; $urlko.='fulltag='.urlencode($FULLTAG).'&'; } +/* This make url too long. Seems not required into the back url if (! empty($SECUREKEY)) { $urlok.='securekey='.urlencode($SECUREKEY).'&'; $urlko.='securekey='.urlencode($SECUREKEY).'&'; -} +}*/ if (! empty($entity)) { - $urlok.='entity='.urlencode($entity).'&'; - $urlko.='entity='.urlencode($entity).'&'; + $urlok.='e='.urlencode($entity).'&'; + $urlko.='e='.urlencode($entity).'&'; } $urlok=preg_replace('/&$/','',$urlok); // Remove last & $urlko=preg_replace('/&$/','',$urlko); // Remove last & @@ -223,7 +223,7 @@ if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) { if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { - if ($SOURCE && $REF) $token = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $SOURCE . $REF, 2); // Use the source in the hash to avoid duplicates if the references are identical + if ($source && $REF) $token = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $source . $REF, 2); // Use the source in the hash to avoid duplicates if the references are identical else $token = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); } else @@ -340,13 +340,14 @@ if ($action == 'dopayment') elseif (empty($email)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail")); elseif (! isValidEMail($email)) $mesg=$langs->trans("ErrorBadEMail",$email); elseif (! $origfulltag) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode")); - elseif (dol_strlen($urlok) > 150) $mesg='Error urlok too long '.$urlok; - elseif (dol_strlen($urlko) > 150) $mesg='Error urlko too long '.$urlko; + elseif (dol_strlen($urlok) > 150) $mesg='Error urlok too long '.$urlok.'( Paybox requires 150, found '.strlen($urlok).')'; + elseif (dol_strlen($urlko) > 150) $mesg='Error urlko too long '.$urlko.'( Paybox requires 150, found '.strlen($urlok).')'; if (empty($mesg)) { dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG); + include_once DOL_DOCUMENT_ROOT.'/paybox/lib/paybox.lib.php'; print_paybox_redirect($PRICE, $conf->currency, $email, $urlok, $urlko, $FULLTAG); session_destroy(); @@ -499,10 +500,10 @@ $conf->dol_hide_leftmenu=1; llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); // Check link validity -if (! empty($SOURCE) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) +if ($source && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) { $langs->load("errors"); - dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); + dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref)); llxFooter(); $db->close(); exit; @@ -528,7 +529,7 @@ print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; -print ''; +print ''; print "\n"; print ''."\n"; print ''."\n"; @@ -709,8 +710,8 @@ if ($source == 'order') $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; print ''."\n"; // Amount @@ -821,7 +822,7 @@ if ($source == 'invoice') $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; print ''."\n"; @@ -1004,8 +1005,8 @@ if ($source == 'contractline') print ''."\n"; // Quantity @@ -1146,8 +1147,8 @@ if ($source == 'membersubscription') $text=''.$langs->trans("PaymentSubscription").''; print ''."\n"; if ($member->last_subscription_date || $member->last_subscription_amount) @@ -1272,7 +1273,7 @@ if ($action != 'dopayment') if (! empty($conf->stripe->enabled)) { // If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of stripe - print '
'; + print '
'; } if (! empty($conf->paypal->enabled)) @@ -1365,12 +1366,12 @@ if (preg_match('/^dopayment/',$action)) print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; - print ''; + print ''; print ''."\n"; print ''."\n"; diff --git a/htdocs/public/payment/paymentko.php b/htdocs/public/payment/paymentko.php index cbea7db650f..bdc301a0dce 100644 --- a/htdocs/public/payment/paymentko.php +++ b/htdocs/public/payment/paymentko.php @@ -31,7 +31,7 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. // For MultiCompany module. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php // TODO This should be useless. Because entity must be retreive from object ref and not from url. -$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +$entity=(! empty($_GET['e']) ? (int) $_GET['e'] : (! empty($_POST['e']) ? (int) $_POST['e'] : 1)); if (is_numeric($entity)) define("DOLENTITY", $entity); require '../../main.inc.php'; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 29d2b78d142..7ccd95abcdf 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -31,7 +31,7 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. // For MultiCompany module. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php // TODO This should be useless. Because entity must be retreive from object ref and not from url. -$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +$entity=(! empty($_GET['e']) ? (int) $_GET['e'] : (! empty($_POST['e']) ? (int) $_POST['e'] : 1)); if (is_numeric($entity)) define("DOLENTITY", $entity); require '../../main.inc.php'; @@ -76,7 +76,7 @@ if (! empty($conf->paypal->enabled)) $FULLTAG=GETPOST('FULLTAG'); if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); -$source=GETPOST('source'); +$source=GETPOST('s','alpha')?GETPOST('s','alpha'):GETPOST('source','alpha'); $ref=GETPOST('ref'); $suffix=GETPOST("suffix",'aZ09'); @@ -145,7 +145,6 @@ $conf->dol_hide_leftmenu=1; llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); - // Show message print ''."\n"; print '
'."\n"; diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 1c991f9ccd7..e6bf4d8233a 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1084,7 +1084,7 @@ div.fiche { dol_hide_leftmenu)) print 'margin-bottom: 12px;'."\n"; ?> } body.onlinepaymentbody div.fiche { /* For online payment page */ - margin: 40px !important; + margin: 20px !important; } div.fiche>table:first-child { margin-bottom: 15px !important; @@ -3139,7 +3139,7 @@ div.titre { /* text-shadow: 1px 1px 2px #FFFFFF; */ } -#dolpaymenttable { max-width: 600px; font-size: 16px; } +#dolpaymenttable { min-width: 310px; font-size: 16px; } /* Width must have min to make stripe input area visible */ #tablepublicpayment { border: 1px solid #CCCCCC !important; width: 100%; padding: 20px; } #tablepublicpayment .CTableRow1 { background-color: #F0F0F0 !important; } #tablepublicpayment tr.liste_total { border-bottom: 1px solid #CCCCCC !important; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 1ed9b433be7..64210218799 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -1120,6 +1120,9 @@ div.fiche { dol_hide_leftmenu) && ! empty($conf->dol_hide_topmenu)) print 'margin-top: 4px;'; ?> margin-bottom: 15px; } +body.onlinepaymentbody div.fiche { /* For online payment page */ + margin: 20px !important; +} div.fichecenter { width: 100%; clear: both; /* This is to have div fichecenter that are true rectangles */ @@ -3239,7 +3242,7 @@ div.titre { dol_optimize_smallscreen)?'':'margin-top: 4px;'); ?> } -#dolpaymenttable { max-width: 600px; font-size: 16px; } +#dolpaymenttable { min-width: 320px; font-size: 16px; } /* Width must have min to make stripe input area visible */ #tablepublicpayment { border: 1px solid #CCCCCC !important; width: 100%; padding: 20px; } #tablepublicpayment .CTableRow1 { background-color: #F0F0F0 !important; } #tablepublicpayment tr.liste_total { border-bottom: 1px solid #CCCCCC !important; } From 0eb416d4afd3a4aeee16bfae41dea2223e3e5dd1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Sep 2017 20:41:40 +0200 Subject: [PATCH 39/47] Fix removal of a file --- htdocs/ecm/docfile.php | 26 +++++++++++---------- htdocs/ecm/index.php | 34 +++++++++++++--------------- htdocs/langs/en_US/ecm.lang | 3 ++- htdocs/public/payment/newpayment.php | 3 ++- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php index 192240b4943..29f1b21a321 100644 --- a/htdocs/ecm/docfile.php +++ b/htdocs/ecm/docfile.php @@ -19,12 +19,12 @@ * \file htdocs/ecm/docfile.php * \ingroup ecm * \brief Card of a file for ECM module - * \author Laurent Destailleur */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php'; @@ -103,11 +103,9 @@ if (! empty($_GET["fileid"])) -/******************************************************************* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ +/* + * Actions + */ if ($action == 'cancel') { @@ -166,11 +164,9 @@ if ($action == 'update') -/******************************************************************* - * PAGE - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ +/* + * View + */ llxHeader(); @@ -253,6 +249,13 @@ print dol_print_size($totalsize); print ''; */ +$filepath=$relativepath.$file->label; + +print '
'; + // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file @@ -264,7 +267,6 @@ $forcedownload=1; $rellink='/document.php?modulepart='.$modulepart; if ($forcedownload) $rellink.='&attachment=1'; if (! empty($object->entity)) $rellink.='&entity='.$object->entity; -$filepath=$relativepath.$file->label; $rellink.='&file='.urlencode($filepath); $fulllink=$urlwithroot.$rellink; print img_picto('','object_globe.png').' '; diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 94b1781ab81..77fb16f5afd 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -143,26 +143,24 @@ if ($action == 'confirm_deletefile') { if (GETPOST('confirm') == 'yes') { + // GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections. + //var_dump(GETPOST('urlfile'));exit; $langs->load("other"); - if ($section) - { - $result=$ecmdir->fetch($section); - if (! ($result > 0)) - { - dol_print_error($db,$ecmdir->error); - exit; - } - $relativepath=$ecmdir->getRelativePath(); - } - else $relativepath=''; + $upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:''); - $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP). + $file = $upload_dir . "/" . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP). + //var_dump($file);exit; - $ret=dol_delete_file($file); - if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); - else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); - - $result=$ecmdir->changeNbOfFiles('-'); + $ret=dol_delete_file($file); // This include also the delete from file index in database. + if ($ret) + { + setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile','alpha')), null, 'mesgs'); + $result=$ecmdir->changeNbOfFiles('-'); + } + else + { + setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile','alpha')), null, 'errors'); + } clearstatcache(); } @@ -375,7 +373,7 @@ else print ''; } $url=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&module='.$module:'').($section?'&section='.$section:''))); -print ''; +print ''; print ''; print ''; diff --git a/htdocs/langs/en_US/ecm.lang b/htdocs/langs/en_US/ecm.lang index 5f651413301..a238a8cd384 100644 --- a/htdocs/langs/en_US/ecm.lang +++ b/htdocs/langs/en_US/ecm.lang @@ -41,4 +41,5 @@ ECMDirectoryForFiles=Relative directory for files CannotRemoveDirectoryContainsFiles=Removed not possible because it contains some files ECMFileManager=File manager ECMSelectASection=Select a directory on left tree... -DirNotSynchronizedSyncFirst=This directory seems to be created or modified outside ECM module. You must click on "Refresh" button first to synchronize disk and database to get content of this directory. +DirNotSynchronizedSyncFirst=This directory seems to be created or modified outside ECM module. You must click on "Resync" button first to synchronize disk and database to get content of this directory. +ReSyncListOfDir=Resync list of directories \ No newline at end of file diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index faf40e17067..52aa5950a92 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -67,6 +67,7 @@ $amount=price2num(GETPOST("amount",'alpha')); if (! GETPOST("currency",'alpha')) $currency=$conf->currency; else $currency=GETPOST("currency",'alpha'); $source = GETPOST("s",'alpha')?GETPOST("s",'alpha'):GETPOST("source",'alpha'); +$download = GETPOST('d','int')?GETPOST('d','int'):GETPOST('download','int'); if (! $action) { @@ -854,7 +855,7 @@ if ($source == 'invoice') print ''."\n"; // Add download link - if (GETPOST('download','int') > 0) + if ($download > 0) { print ''; */ +$relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document $filepath=$relativepath.$file->label; +$filepathtodocument=$relativetodocument.$file->label; print ''; // Define $urlwithroot @@ -261,6 +273,19 @@ $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current +print ''; + print ''; + print '
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("Creditor"); print ''.$creditor.''; - print ''; + print ''; print '
'.$langs->trans("Designation"); print ''.$text; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; print ''; print '
'.$langs->trans("Document"); + print ''; + print $invoice->getDirectExternalLink(1); + print '
'.$langs->trans("Designation"); print ''.$text; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("Designation"); print ''.$text; - print ''; + print ''; print ''; print '
'.$langs->trans("Designation"); print ''.$text; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("Designation"); print ''.$text; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("HashSaved").''; +$ecmfile = new EcmFiles($db); +print $filepath; +print '
'.$langs->trans("Document"); print ''; From beac7a7439e9aa638c568b658550de4a55063ece Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Sep 2017 21:29:27 +0200 Subject: [PATCH 40/47] Work on direct download links --- htdocs/core/lib/files.lib.php | 2 +- htdocs/ecm/class/ecmfiles.class.php | 2 +- htdocs/ecm/docfile.php | 36 +++++++++++++++++++++++++---- htdocs/langs/en_US/ecm.lang | 4 +++- htdocs/langs/en_US/main.lang | 3 ++- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 238728068c9..83259aa41d2 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1537,7 +1537,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $ecmfile=new EcmFiles($db); $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($destfull)); + $ecmfile->label = md5_file(dol_osencode($destfull)); // MD5 of file content $ecmfile->fullpath_orig = $TFile['name'][$i]; $ecmfile->gen_or_uploaded = 'uploaded'; $ecmfile->description = ''; // indexed content diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index f1090757dad..abe5c403462 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -46,7 +46,7 @@ class EcmFiles //extends CommonObject /** */ - public $label; + public $label; // hash of file md5_file(dol_osencode($destfull)), so MD5 of file content public $entity; public $filename; public $filepath; diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php index 29f1b21a321..045c3ebda8b 100644 --- a/htdocs/ecm/docfile.php +++ b/htdocs/ecm/docfile.php @@ -249,11 +249,23 @@ print dol_print_size($totalsize); print '
'.$langs->trans("HashSaved").''; $ecmfile = new EcmFiles($db); -print $filepath; +//$filenametosearch=basename($filepath); +//$filedirtosearch=basedir($filepath); +$ecmfile->fetch(0, '', $filepathtodocument); +if (! empty($ecmfile->label)) +{ + print $ecmfile->label; +} +else +{ + print img_warning().' '.$langs->trans("FileNotYetIndexedInDatabase"); +} print '
'.$langs->trans("DirectDownloadInternalLink").''; +$modulepart='ecm'; +$forcedownload=1; +$rellink='/document.php?modulepart='.$modulepart; +if ($forcedownload) $rellink.='&attachment=1'; +if (! empty($object->entity)) $rellink.='&entity='.$object->entity; +$rellink.='&file='.urlencode($filepath); +$fulllink=$urlwithroot.$rellink; +print img_picto('','object_globe.png').' '; +print ''; +print ' '.$langs->trans("Download").''; +print '
'.$langs->trans("DirectDownloadLink").''; $modulepart='ecm'; $forcedownload=1; @@ -269,12 +294,15 @@ if ($forcedownload) $rellink.='&attachment=1'; if (! empty($object->entity)) $rellink.='&entity='.$object->entity; $rellink.='&file='.urlencode($filepath); $fulllink=$urlwithroot.$rellink; -print img_picto('','object_globe.png').' '; -print ''; -print ' '.$langs->trans("Download").''; +// TODO +//print img_picto('','object_globe.png').' '; +//print ''; +//print ' '.$langs->trans("Download").''; print '
'; +print ajax_autoselect('downloadinternallink'); print ajax_autoselect('downloadlink'); dol_fiche_end(); diff --git a/htdocs/langs/en_US/ecm.lang b/htdocs/langs/en_US/ecm.lang index a238a8cd384..f7c0f0ab737 100644 --- a/htdocs/langs/en_US/ecm.lang +++ b/htdocs/langs/en_US/ecm.lang @@ -42,4 +42,6 @@ CannotRemoveDirectoryContainsFiles=Removed not possible because it contains some ECMFileManager=File manager ECMSelectASection=Select a directory on left tree... DirNotSynchronizedSyncFirst=This directory seems to be created or modified outside ECM module. You must click on "Resync" button first to synchronize disk and database to get content of this directory. -ReSyncListOfDir=Resync list of directories \ No newline at end of file +ReSyncListOfDir=Resync list of directories +HashSaved=Hash of file +FileNotYetIndexedInDatabase=File not yet indexed into database (try to re-upload it) \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 1b92d87e9ba..dfe38b7fe65 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -792,7 +792,8 @@ GroupBy=Group by... ViewFlatList=View flat list RemoveString=Remove string '%s' SomeTranslationAreUncomplete=Some languages may be partially translated or may contains errors. If you detect some, you can fix language files registering to https://transifex.com/projects/p/dolibarr/. -DirectDownloadLink=Direct download link +DirectDownloadLink=Direct download link (public/external) +DirectDownloadInternalLink=Direct download link (need to be logged and permissions) Download=Download ActualizeCurrency=Update currency rate Fiscalyear=Fiscal year From e56840b9ec668e95647b707c186b2cc1f073de82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 11:35:18 +0200 Subject: [PATCH 41/47] Clean deprecated code --- htdocs/comm/action/card.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 7b1c81af59c..b491c9007cb 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -397,7 +397,7 @@ if ($action == 'update') $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); - $object->fk_action = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm'); + $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm'); $object->label = GETPOST("label"); $object->datep = $datep; $object->datef = $datef; @@ -407,8 +407,6 @@ if ($action == 'update') $object->location = GETPOST('location'); $object->socid = GETPOST("socid"); $object->contactid = GETPOST("contactid",'int'); - //$object->societe->id = $_POST["socid"]; // deprecated - //$object->contact->id = $_POST["contactid"]; // deprecated $object->fk_project = GETPOST("projectid",'int'); $object->note = GETPOST("note"); $object->pnote = GETPOST("note"); @@ -869,7 +867,7 @@ if ($id > 0) $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); - $object->fk_action = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm'); + $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm'); $object->label = GETPOST("label"); $object->datep = $datep; $object->datef = $datef; @@ -879,8 +877,6 @@ if ($id > 0) $object->location = GETPOST('location'); $object->socid = GETPOST("socid"); $object->contactid = GETPOST("contactid",'int'); - //$object->societe->id = $_POST["socid"]; // deprecated - //$object->contact->id = $_POST["contactid"]; // deprecated $object->fk_project = GETPOST("projectid",'int'); $object->note = GETPOST("note"); From 8a06a1f43372a925e18d6c854395f84212b85254 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 11:50:36 +0200 Subject: [PATCH 42/47] Code comment --- htdocs/projet/document.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php index 8777d83e419..fbf9574bd75 100644 --- a/htdocs/projet/document.php +++ b/htdocs/projet/document.php @@ -20,7 +20,7 @@ /** * \file htdocs/projet/document.php * \ingroup project - * \brief Page de gestion des documents attachees a un projet + * \brief Page to managed related documents linked to a project */ require '../main.inc.php'; @@ -106,11 +106,11 @@ if ($object->id > 0) $totalsize+=$file['size']; } - + // Project card - + $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref='
'; // Title $morehtmlref.=$object->title; @@ -120,19 +120,19 @@ if ($object->id > 0) $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project'); } $morehtmlref.='
'; - + // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0); $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")"; } - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '
'; - print '
'; + print '
'; print ''; @@ -141,10 +141,10 @@ if ($object->id > 0) print ''; print "
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; - + print '
'; - + dol_fiche_end(); $modulepart = 'project'; From 23604a2b54dd2905885e35099252239d022488dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 11:54:37 +0200 Subject: [PATCH 43/47] NEW Add hidden option PROJECT_DISABLE_UNLINK_FROM_OVERVIEW --- htdocs/projet/element.php | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 1e4d4132944..f76b6f9f0cc 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -643,33 +643,6 @@ foreach ($listofreferent as $key => $value) $total_ttc = -$total_ttc; } - /*switch ($classname) { - case 'FactureFournisseur': - $newclassname = 'SupplierInvoice'; - break; - case 'Facture': - $newclassname = 'Bill'; - break; - case 'Propal': - $newclassname = 'CommercialProposal'; - break; - case 'Commande': - $newclassname = 'Order'; - break; - case 'Expedition': - $newclassname = 'Sending'; - break; - case 'Contrat': - $newclassname = 'Contract'; - break; - case 'MouvementStock': - $newclassname = 'StockMovement'; - break; - default: - $newclassname = $classname; - }*/ - - $var = ! $var; print ''; // Module print ''.$name.''; @@ -693,7 +666,6 @@ print ''; print ""; - print '

'; print '
'; @@ -771,7 +743,7 @@ foreach ($listofreferent as $key => $value) print ''; print ''; - // Remove link + // Remove link column print ''; // Ref print ''.$langs->trans("Ref").''; @@ -862,11 +834,15 @@ foreach ($listofreferent as $key => $value) } print ''; + // Remove link print '\n"; From 296e678c1be26500c87a56bc46fbe0db84573b7b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 12:02:46 +0200 Subject: [PATCH 44/47] Solve url too long with paybox --- htdocs/public/payment/newpayment.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 52aa5950a92..1862a5b8a47 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -143,12 +143,11 @@ if (! empty($FULLTAG)) $urlok.='fulltag='.urlencode($FULLTAG).'&'; $urlko.='fulltag='.urlencode($FULLTAG).'&'; } -/* This make url too long. Seems not required into the back url if (! empty($SECUREKEY)) { $urlok.='securekey='.urlencode($SECUREKEY).'&'; $urlko.='securekey='.urlencode($SECUREKEY).'&'; -}*/ +} if (! empty($entity)) { $urlok.='e='.urlencode($entity).'&'; @@ -336,6 +335,10 @@ if ($action == 'dopayment') $origfulltag=GETPOST("fulltag",'alpha'); + // Securekey into back url useless for back url and we need an url lower than 150. + $urlok = preg_replace('/securekey=[^&]+/', '', $urlok); + $urlko = preg_replace('/securekey=[^&]+/', '', $urlko); + $mesg=''; if (empty($PRICE) || ! is_numeric($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); elseif (empty($email)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail")); From 96efe43e3cbcc8c8f7a94b5187be927cbc679068 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 12:48:07 +0200 Subject: [PATCH 45/47] NEW Provide a way to download a file from a public URL. --- htdocs/document.php | 37 ++++++++++++++++++++++++++--- htdocs/ecm/class/ecmfiles.class.php | 15 +++++++++--- htdocs/ecm/docfile.php | 30 ++++++++++++++--------- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/htdocs/document.php b/htdocs/document.php index d35021005e6..c09441ea0ed 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -59,24 +59,28 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $encoding = ''; $action=GETPOST('action','alpha'); -$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). +$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). +$hashn=GETPOST('hashn','aZ09'); +$hashc=GETPOST('hashc','aZ09'); $modulepart=GETPOST('modulepart','alpha'); $urlsource=GETPOST('urlsource','alpha'); $entity=GETPOST('entity','int')?GETPOST('entity','int'):$conf->entity; // Security check -if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); +if (empty($modulepart)) accessforbidden('Bad link. Bad value for parameter modulepart',0,0,1); +if (empty($original_file) && empty($hashn) && empty($hashc)) accessforbidden('Bad link. Missing identification to find file (original_file, hasn or hashc)',0,0,1); if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; // For some module part, dir may be privates -if (in_array($modulepart,array('facture_paiement','unpaid'))) +if (in_array($modulepart, array('facture_paiement','unpaid'))) { if (! $user->rights->societe->client->voir || $socid) $original_file='private/'.$user->id.'/'.$original_file; // If user has no permission to see all, output dir is specific to user } + /* * Action */ @@ -99,6 +103,33 @@ if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false; if (isset($_GET["attachment"])) $attachment = GETPOST("attachment",'alpha')?true:false; if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; +// If we have a hash (hashc or hashn), we guess the original_file. Note: using hashn is not reliable. +if (! empty($hashn) || ! empty($hashc)) +{ + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + $ecmfile=new EcmFiles($db); + $result = $ecmfile->fetch(0, $hashn, '', $hashc); + if ($result > 0) + { + $tmp = explode('/', $ecmfile->filepath, 2); // $ecmfile->filepatch is relative to document directory + $moduleparttocheck = $tmp[0]; + if ($moduleparttocheck == $modulepart) + { + $original_file = (($tmp[1]?$tmp[1].'/':'').$ecmfile->filename); // this is relative to module dir + //var_dump($original_file); exit; + } + else + { + accessforbidden('Bad link. File owns to another module part.',0,0,1); + } + } + else + { + accessforbidden('Bad link. File was not found or removed recently.',0,0,1); + } +} + + // Security: Delete string ../ into $original_file $original_file = str_replace("../","/", $original_file); diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index abe5c403462..77fa294aeed 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -157,6 +157,7 @@ class EcmFiles //extends CommonObject // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + $sql.= 'ref,'; $sql.= 'label,'; $sql.= 'entity,'; $sql.= 'filename,'; @@ -174,6 +175,7 @@ class EcmFiles //extends CommonObject $sql.= 'fk_user_m,'; $sql.= 'acl'; $sql .= ') VALUES ('; + $sql .= " '".dol_hash($this->filepath.'/'.$this->filename, 3)."', "; $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; $sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).','; $sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").','; @@ -232,11 +234,12 @@ class EcmFiles //extends CommonObject * Load object in memory from the database * * @param int $id Id object - * @param string $ref Not used yet. Will contains a hash id from filename+filepath + * @param string $ref Hash of file name (filename+filepath). Not always defined on some version. * @param string $relativepath Relative path of file from document directory. Example: path/path2/file + * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed. * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null, $relativepath = '') + public function fetch($id, $ref = '', $relativepath = '', $hashoffile='') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -268,11 +271,16 @@ class EcmFiles //extends CommonObject if ($relativepath) { $sql .= " AND t.filepath = '" . $this->db->escape(dirname($relativepath)) . "' AND t.filename = '".$this->db->escape(basename($relativepath))."'"; } - elseif (null !== $ref) { + elseif (! empty($ref)) { $sql .= " AND t.ref = '".$this->db->escape($ref)."'"; + } + elseif (! empty($hashoffile)) { + $sql .= " AND t.label = '".$this->db->escape($hashoffile)."'"; } else { $sql .= ' AND t.rowid = ' . $id; } + $this->db->plimit(1); + $this->db->order('t.rowid', 'ASC'); // When we search on hash of content, we take the first one. $resql = $this->db->query($sql); if ($resql) { @@ -484,6 +492,7 @@ class EcmFiles //extends CommonObject // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + $sql .= ' ref = '.dol_hash($this->filepath.'/'.$this->filename, 3); $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; $sql .= ' entity = '.(isset($this->entity)?$this->entity:$conf->entity).','; $sql .= ' filename = '.(isset($this->filename)?"'".$this->db->escape($this->filename)."'":"null").','; diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php index 045c3ebda8b..aa708a85f24 100644 --- a/htdocs/ecm/docfile.php +++ b/htdocs/ecm/docfile.php @@ -287,17 +287,25 @@ print ' '.$langs->trans("Download").''; print ''; print ''; print '
'; if ($tablename != 'projet_task' && $tablename != 'stock_mouvement') { - print '' . img_picto($langs->trans('Unlink'), 'editdelete') . ''; + if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true + { + print '' . img_picto($langs->trans('Unlink'), 'editdelete') . ''; + } } print "
'.$langs->trans("DirectDownloadLink").''; -$modulepart='ecm'; -$forcedownload=1; -$rellink='/document.php?modulepart='.$modulepart; -if ($forcedownload) $rellink.='&attachment=1'; -if (! empty($object->entity)) $rellink.='&entity='.$object->entity; -$rellink.='&file='.urlencode($filepath); -$fulllink=$urlwithroot.$rellink; -// TODO -//print img_picto('','object_globe.png').' '; -//print ''; -//print ' '.$langs->trans("Download").''; +if (! empty($ecmfile->ref) || ! empty($ecmfile->label)) +{ + $modulepart='ecm'; + $forcedownload=1; + $rellink='/document.php?modulepart='.$modulepart; + if ($forcedownload) $rellink.='&attachment=1'; + if (! empty($object->entity)) $rellink.='&entity='.$object->entity; + //$rellink.='&file='.urlencode($filepath); // No need of name of file for public link, we will use the hash + $fulllink=$urlwithroot.$rellink; + if (! empty($ecmfile->ref)) $fulllink.='&hashn='.$ecmfile->ref; // Hash of file path + elseif (! empty($ecmfile->label)) $fulllink.='&hashc='.$ecmfile->label; // Hash of file content + print img_picto('','object_globe.png').' '; + print ''; + print ' '.$langs->trans("Download").''; +} +else +{ + print img_warning().' '.$langs->trans("FileNotYetIndexedInDatabase"); +} print '
'; From 57358f0ce5d5a626f38ae87385c493b5fde641fe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Sep 2017 14:02:42 +0200 Subject: [PATCH 46/47] NEW Provide a way to download a file from a public URL for files in ECM --- htdocs/document.php | 11 +- htdocs/ecm/class/ecmfiles.class.php | 43 ++++- htdocs/ecm/docfile.php | 162 +++++++++++------- .../install/mysql/migration/6.0.0-7.0.0.sql | 5 + htdocs/install/mysql/tables/llx_ecm_files.sql | 5 +- htdocs/langs/en_US/ecm.lang | 5 +- htdocs/langs/en_US/main.lang | 3 +- htdocs/langs/en_US/website.lang | 2 +- 8 files changed, 158 insertions(+), 78 deletions(-) diff --git a/htdocs/document.php b/htdocs/document.php index c09441ea0ed..590d47d2c13 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -60,15 +60,14 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $encoding = ''; $action=GETPOST('action','alpha'); $original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). -$hashn=GETPOST('hashn','aZ09'); -$hashc=GETPOST('hashc','aZ09'); +$hashp=GETPOST('hashp','aZ09'); $modulepart=GETPOST('modulepart','alpha'); $urlsource=GETPOST('urlsource','alpha'); $entity=GETPOST('entity','int')?GETPOST('entity','int'):$conf->entity; // Security check if (empty($modulepart)) accessforbidden('Bad link. Bad value for parameter modulepart',0,0,1); -if (empty($original_file) && empty($hashn) && empty($hashc)) accessforbidden('Bad link. Missing identification to find file (original_file, hasn or hashc)',0,0,1); +if (empty($original_file) && empty($hashp)) accessforbidden('Bad link. Missing identification to find file (original_file or hashp)',0,0,1); if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility $socid=0; @@ -103,12 +102,12 @@ if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false; if (isset($_GET["attachment"])) $attachment = GETPOST("attachment",'alpha')?true:false; if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; -// If we have a hash (hashc or hashn), we guess the original_file. Note: using hashn is not reliable. -if (! empty($hashn) || ! empty($hashc)) +// If we have a hash public (hashp), we guess the original_file. +if (! empty($hashp)) { include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); - $result = $ecmfile->fetch(0, $hashn, '', $hashc); + $result = $ecmfile->fetch(0, '', '', '', $hashp); if ($result > 0) { $tmp = explode('/', $ecmfile->filepath, 2); // $ecmfile->filepatch is relative to document directory diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 77fa294aeed..0035b18d3c7 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -46,7 +46,9 @@ class EcmFiles //extends CommonObject /** */ - public $label; // hash of file md5_file(dol_osencode($destfull)), so MD5 of file content + public $ref; // hash of file path + public $label; // hash of file content (md5_file(dol_osencode($destfull)) + public $share; // hash for file sharing. empty by default public $entity; public $filename; public $filepath; @@ -94,10 +96,15 @@ class EcmFiles //extends CommonObject $error = 0; // Clean parameters - + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } if (isset($this->label)) { $this->label = trim($this->label); } + if (isset($this->share)) { + $this->share = trim($this->share); + } if (isset($this->entity)) { $this->entity = trim($this->entity); } @@ -136,6 +143,10 @@ class EcmFiles //extends CommonObject } if (empty($this->date_c)) $this->date_c = dol_now(); + // If ref not defined + if (empty($ref)) $ref = dol_hash($this->filepath.'/'.$this->filename, 3); + + $maxposition=0; if (empty($this->position)) // Get max used { @@ -159,6 +170,7 @@ class EcmFiles //extends CommonObject $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; $sql.= 'ref,'; $sql.= 'label,'; + $sql.= 'share,'; $sql.= 'entity,'; $sql.= 'filename,'; $sql.= 'filepath,'; @@ -175,8 +187,9 @@ class EcmFiles //extends CommonObject $sql.= 'fk_user_m,'; $sql.= 'acl'; $sql .= ') VALUES ('; - $sql .= " '".dol_hash($this->filepath.'/'.$this->filename, 3)."', "; + $sql .= " '".$ref."', "; $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; + $sql .= ' '.(! isset($this->share)?'NULL':"'".$this->db->escape($this->share)."'").','; $sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).','; $sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").','; $sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").','; @@ -237,9 +250,10 @@ class EcmFiles //extends CommonObject * @param string $ref Hash of file name (filename+filepath). Not always defined on some version. * @param string $relativepath Relative path of file from document directory. Example: path/path2/file * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed. + * @param string $hashforshare Hash of file sharing. * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = '', $relativepath = '', $hashoffile='') + public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -247,6 +261,7 @@ class EcmFiles //extends CommonObject $sql .= ' t.rowid,'; $sql .= " t.ref,"; $sql .= " t.label,"; + $sql .= " t.share,"; $sql .= " t.entity,"; $sql .= " t.filename,"; $sql .= " t.filepath,"; @@ -276,11 +291,15 @@ class EcmFiles //extends CommonObject } elseif (! empty($hashoffile)) { $sql .= " AND t.label = '".$this->db->escape($hashoffile)."'"; + } + elseif (! empty($hashforshare)) { + $sql .= " AND t.share = '".$this->db->escape($hashforshare)."'"; } else { $sql .= ' AND t.rowid = ' . $id; } + // When we search on hash of content, we take the first one. Solve also hash conflict. $this->db->plimit(1); - $this->db->order('t.rowid', 'ASC'); // When we search on hash of content, we take the first one. + $this->db->order('t.rowid', 'ASC'); $resql = $this->db->query($sql); if ($resql) { @@ -291,6 +310,7 @@ class EcmFiles //extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->ref; $this->label = $obj->label; + $this->share = $obj->share; $this->entity = $obj->entity; $this->filename = $obj->filename; $this->filepath = $obj->filepath; @@ -352,6 +372,7 @@ class EcmFiles //extends CommonObject $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.label,"; + $sql .= " t.share,"; $sql .= " t.entity,"; $sql .= " t.filename,"; $sql .= " t.filepath,"; @@ -401,8 +422,9 @@ class EcmFiles //extends CommonObject $line = new EcmfilesLine(); $line->id = $obj->rowid; - + $line->ref = $obj->ref; $line->label = $obj->label; + $line->share = $obj->share; $line->entity = $obj->entity; $line->filename = $obj->filename; $line->filepath = $obj->filepath; @@ -446,9 +468,15 @@ class EcmFiles //extends CommonObject // Clean parameters + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } if (isset($this->label)) { $this->label = trim($this->label); } + if (isset($this->share)) { + $this->share = trim($this->share); + } if (isset($this->entity)) { $this->entity = trim($this->entity); } @@ -492,8 +520,9 @@ class EcmFiles //extends CommonObject // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= ' ref = '.dol_hash($this->filepath.'/'.$this->filename, 3); + $sql .= " ref = '".dol_hash($this->filepath.'/'.$this->filename, 3)."',"; $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; + $sql .= ' share = '.(! empty($this->share)?"'".$this->db->escape($this->share)."'":"null").','; $sql .= ' entity = '.(isset($this->entity)?$this->entity:$conf->entity).','; $sql .= ' filename = '.(isset($this->filename)?"'".$this->db->escape($this->filename)."'":"null").','; $sql .= ' filepath = '.(isset($this->filepath)?"'".$this->db->escape($this->filepath)."'":"null").','; diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php index aa708a85f24..a856ab22c36 100644 --- a/htdocs/ecm/docfile.php +++ b/htdocs/ecm/docfile.php @@ -39,6 +39,9 @@ $langs->load("bills"); $langs->load("contracts"); $langs->load("categories"); +$action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'alpha'); + if (!$user->rights->ecm->setup) accessforbidden(); // Get parameters @@ -61,8 +64,6 @@ $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; -$cancel=GETPOST('cancel','alpha'); -$action=GETPOST('action','aZ09'); $section=GETPOST("section"); if (! $section) { @@ -87,19 +88,25 @@ if (! $result > 0) $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; +$fullpath=$conf->ecm->dir_output.'/'.$relativepath.$urlfile; -/* -$ecmfile = new ECMFile($db); -if (! empty($_GET["fileid"])) +$file = new stdClass(); +$file->section_id=$ecmdir->id; +$file->label=$urlfile; + +$relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document +$filepath=$relativepath.$file->label; +$filepathtodocument=$relativetodocument.$file->label; + +// Try to load object from index +$object = new ECMFiles($db); +$result=$object->fetch(0, '', $filepathtodocument); +if (! ($result >= 0)) { - $result=$ecmfile->fetch($_GET["fileid"]); - if (! $result > 0) - { - dol_print_error($db,$ecmfile->error); - exit; - } + dol_print_error($db, $object->error, $object->errors); + exit; } -*/ + @@ -107,7 +114,7 @@ if (! empty($_GET["fileid"])) * Actions */ -if ($action == 'cancel') +if ($cancel) { $action =''; if ($backtourl) @@ -117,7 +124,7 @@ if ($action == 'cancel') } else { - header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager§ion='.$section); + header("Location: ".DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.$urlfile.'§ion='.$section); exit; } } @@ -127,8 +134,9 @@ if ($action == 'update') { $error=0; - $oldlabel=GETPOST('urlfile'); - $newlabel=GETPOST('label'); + $oldlabel=GETPOST('urlfile', 'alpha'); + $newlabel=GETPOST('label', 'alpha'); + $shareenabled = GETPOST('shareenabled', 'alpha'); //$db->begin(); @@ -142,7 +150,7 @@ if ($action == 'update') //print $oldfile.' - '.$newfile; if ($newlabel != $oldlabel) { - $result=dol_move($oldfile, $newfile); + $result=dol_move($oldfile, $newfile); // This include update of database if (! $result) { $langs->load('errors'); @@ -151,14 +159,39 @@ if ($action == 'update') } } + // Now we update index of file + $db->begin(); + if (! $error) { - //$db->commit(); + if (is_object($object)) + { + if ($shareenabled) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + $object->share = getRandomPassword(true); + } + else + { + $object->share = ''; + } + $result = $object->update($user); + if ($result < 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + if (!$error) + { + $db->commit(); $urlfile=$newlabel; } else { - //$db->rollback(); + $db->rollback(); } } @@ -168,25 +201,20 @@ if ($action == 'update') * View */ -llxHeader(); - $form=new Form($db); -$fullpath=$conf->ecm->dir_output.'/'.$relativepath.$urlfile; - -$file = new stdClass(); -$file->section_id=$ecmdir->id; -$file->label=$urlfile; +llxHeader(); $head = ecm_file_prepare_head($file); -if ($_GET["action"] == 'edit') +if ($action == 'edit') { print ''; print ''; print ''; print ''; print ''; + print ''; } dol_fiche_head($head, 'card', $langs->trans("File"), 0, 'generic'); @@ -217,11 +245,11 @@ while ($tmpecmdir && $result > 0) print img_picto('','object_dir').' '.$langs->trans("ECMRoot").' -> '; print $s; print ' -> '; -if (GETPOST('action','aZ09') == 'edit') print ''; +if ($action == 'edit') print ''; else print $urlfile; print ''; /*print ''.$langs->trans("Description").''; -if ($_GET["action"] == 'edit') +if ($action == 'edit') { print '