From e4f7f2a0b2e7ac05d6917781eb8e0e14ffeee444 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 26 May 2017 12:39:49 +0200 Subject: [PATCH 01/66] $resaction need in 5.0.x too --- htdocs/core/class/hookmanager.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 24ba86c7115..89a9b834482 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -233,7 +233,7 @@ class HookManager if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue; //dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG); - $result = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) + $resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; From 18799c3a7f1bddfbe7a2f3c27994e290a2de4d0e Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 29 May 2017 11:00:08 +0200 Subject: [PATCH 02/66] Changes Done question need to change $actionclassinstance->results in $actionclassinstance->resactionss ??? --- htdocs/core/class/hookmanager.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 89a9b834482..0c78e89fa9e 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -238,10 +238,10 @@ class HookManager if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string. we must use $actionclassinstance->resprints to return a string - if (! is_array($result) && ! is_numeric($result)) + if (! is_array($resaction) && ! is_numeric($resaction)) { dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR); - if (empty($actionclassinstance->resprints)) { $this->resPrint.=$result; $result=0; } + if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; } } } From 19b8918caf5ec68a00fe94af99d6bebeb3748570 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 13:35:51 +0200 Subject: [PATCH 03/66] FIX #6881 --- htdocs/install/upgrade2.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 09aa85d48c3..42c8f50632e 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -453,11 +453,11 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) $db->close(); - // Actions for all version (not in database) + // Actions for all versions (not in database) migrate_delete_old_files($db, $langs, $conf); - migrate_delete_old_dir($db, $langs, $conf); + dol_mkdir(DOL_DATA_ROOT.'/bank'); migrate_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits'); } @@ -3926,7 +3926,11 @@ function migrate_delete_old_files($db,$langs,$conf) DOL_DOCUMENT_ROOT.'/core/modules/mailings/poire.modules.php', DOL_DOCUMENT_ROOT.'/core/modules/mailings/kiwi.modules.php', DOL_DOCUMENT_ROOT.'/core/modules/facture/pdf_crabe.modules.php', - DOL_DOCUMENT_ROOT.'/core/modules/facture/pdf_oursin.modules.php' + DOL_DOCUMENT_ROOT.'/core/modules/facture/pdf_oursin.modules.php', + + DOL_DOCUMENT_ROOT.'/compta/facture/class/api_invoice.class.php', + DOL_DOCUMENT_ROOT.'/commande/class/api_commande.class.php', + DOL_DOCUMENT_ROOT.'/user/class/api_user.class.php' ); foreach ($filetodeletearray as $filetodelete) From d2813eabbcad08127c92d07534b7554b33c43d77 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 13:39:07 +0200 Subject: [PATCH 04/66] FIX #6877 Conflicts: htdocs/install/mysql/migration/5.0.0-6.0.0.sql --- htdocs/install/mysql/migration/4.0.0-5.0.0.sql | 1 + htdocs/install/mysql/tables/llx_projet.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index fa185f2864b..b5978efac99 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -45,6 +45,7 @@ ALTER TABLE llx_facture_fourn_det ADD INDEX idx_facture_fourn_det_fk_product (fk ALTER TABLE llx_facture_rec ADD COLUMN fk_user_modif integer; ALTER TABLE llx_expedition ADD COLUMN fk_user_modif integer; +ALTER TABLE llx_projet ADD COLUMN fk_user_modif integer; ALTER TABLE llx_adherent ADD COLUMN model_pdf varchar(255); diff --git a/htdocs/install/mysql/tables/llx_projet.sql b/htdocs/install/mysql/tables/llx_projet.sql index d50547b711b..8ca404d3a0e 100644 --- a/htdocs/install/mysql/tables/llx_projet.sql +++ b/htdocs/install/mysql/tables/llx_projet.sql @@ -30,6 +30,7 @@ create table llx_projet title varchar(255) NOT NULL, description text, fk_user_creat integer NOT NULL, -- createur du projet + fk_user_modif integer, public integer, -- project is public or not fk_statut integer DEFAULT 0 NOT NULL, -- open or close fk_opp_status integer DEFAULT NULL, -- if project is used to manage opportunities From 96b8339d21eab4bc275d365b9ba51c24108feda7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 26 May 2017 17:38:57 +0200 Subject: [PATCH 05/66] Fix: [Restler] Delete the cache file otherwise it does not update --- htdocs/api/admin/index.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php index 8142b564c1e..8ea22cee1d3 100644 --- a/htdocs/api/admin/index.php +++ b/htdocs/api/admin/index.php @@ -43,12 +43,29 @@ if ($action == 'setproductionmode') if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', $conf->entity) > 0) { - $result = dol_mkdir($conf->api->dir_temp); - if ($result < 0) - { - setEventMessages($langs->trans("ErrorFaildToCreateDir", $conf->api->dir_temp), null, 'errors'); - } - else + $error=0; + + if ($status == 1) + { + $result = dol_mkdir($conf->api->dir_temp); + if ($result < 0) + { + setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors'); + $error++; + } + } + else + { + // Delete the cache file otherwise it does not update + $result = dol_delete_file($conf->api->dir_temp.'/routes.php'); + if ($result < 0) + { + setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors'); + $error++; + } + } + + if (!$error) { header("Location: ".$_SERVER["PHP_SELF"]); exit; From d8c5ec2aefb9d6e1abf4a313b287c0167a535e54 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 23 May 2017 18:27:41 +0200 Subject: [PATCH 06/66] FIX: REST API not possible to add agendaevents --- htdocs/comm/action/class/api_agendaevents.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 5eeca63a4aa..b1014b9171a 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -289,7 +289,7 @@ class AgendaEvents extends DolibarrApi function _validate($data) { $event = array(); - foreach (Events::$FIELDS as $field) { + foreach (AgendaEvents::$FIELDS as $field) { if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $event[$field] = $data[$field]; From f5637463105ecc51c0c7b4dbf1de1d1e80c0ed43 Mon Sep 17 00:00:00 2001 From: Quentin Vial-Gouteyron Date: Mon, 29 May 2017 15:38:40 +0200 Subject: [PATCH 07/66] NEW_extrafield_in_project_mask --- htdocs/core/lib/functions2.lib.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) mode change 100644 => 100755 htdocs/core/lib/functions2.lib.php diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php old mode 100644 new mode 100755 index 8934447fdfe..69ee228504d --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -711,7 +711,7 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti */ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$mode='next', $bentityon=true) { - global $conf; + global $conf,$user; if (! is_object($objsoc)) $valueforccc=$objsoc; else if($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur; @@ -790,7 +790,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); }*/ - + + if(strstr($mask,'extra_')){ + + $start = "{extra_"; + $end = "\}"; + $extra= get_string_between($mask, "extra_", "}"); + if(!empty($user->array_options['options_'.$extra])){ + $mask = preg_replace('#('.($start).')(.*?)('.($end).')#si', $user->array_options['options_'.$extra], $mask); + } + } $maskwithonlyymcode=$mask; $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); @@ -1110,7 +1119,14 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m dol_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG); return $numFinal; } - +function get_string_between($string, $start, $end){ + $string = " ".$string; + $ini = strpos($string,$start); + if ($ini == 0) return ""; + $ini += strlen($start); + $len = strpos($string,$end,$ini) - $ini; + return substr($string,$ini,$len); +} /** * Check value * From f21ec76bc040638768dcd572e388ac020d2274ba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 21:16:37 +0200 Subject: [PATCH 08/66] Exclude dir --- build/makepack-dolibarr.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index c06d8f0730f..1dbd6f6fd5e 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -518,6 +518,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/dolimed*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/dolimod*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/factory*`; + $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/forceproject*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/lead*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/management*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/multicompany*`; From eea6461369088e27ab0208d7c3313865ed6e2cac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 21:27:22 +0200 Subject: [PATCH 09/66] Update ChangeLog for 4.0.6 --- ChangeLog | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5fe3c741499..e69b2a9d203 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,29 @@ Upgrading to any other version or any other database system is abolutely require make a Dolibarr upgrade. +***** ChangeLog for 4.0.6 to 4.0.5 ***** +FIX: #6613 Default subject for Supplier proposal emails is filled with a non-existing key +FIX: #6623 User card shows "Return to list" link even if the user has no rights to list users +FIX: #6636 Complete fix +FIX: #6669 User with no permission to edit customer invoices can see a edit button in project entry +FIX: #6671 Cannot remove thirdparty type with "#" in its name +FIX: #6673 Missing "nature" table header in thirdparty list +FIX: #6675 Restricted user with no agenda permissions can see a button to create appointment in thirdparty contact list +FIX: #6677 Expired contracts dashboard box does not show the name of the thirdparty +FIX: #6679 User with restricted supplier invoice permissions can edit project, payment conditions, payment mode +FIX: #6680 User with restricted supplier invoice permissions sees "reopen" button even if he has no permission to do it +FIX: #6813 +FIX: Correction with author and validator user on orders +FIX: doactions hook missing in invoice model page +FIX: dont get empty "Incoterms : - " string if no incoterm +FIX: dont lose supplier ref if no supplier price in database +FIX: forgotten parameter for right multicompany use +FIX: global $dateSelector isn't the good one, then date selector on objectline_create tpl was hidden +FIX: limit+1 dosn't show Total line +FIX: supplier order line were always created with rang = 0 +FIX: All known CVE at the date 31th of may. + + ***** ChangeLog for 4.0.5 to 4.0.4 ***** FIX: #6234 FIX: #6259 From 8edce66c08679e79634d7a22c510317aeb3c2d68 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 21:27:22 +0200 Subject: [PATCH 10/66] Update ChangeLog for 4.0.6 --- ChangeLog | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5fe3c741499..e4c07380aae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,28 @@ Upgrading to any other version or any other database system is abolutely require make a Dolibarr upgrade. +***** ChangeLog for 4.0.6 to 4.0.5 ***** +FIX: #6613 Default subject for Supplier proposal emails is filled with a non-existing key +FIX: #6623 User card shows "Return to list" link even if the user has no rights to list users +FIX: #6636 Complete fix +FIX: #6669 User with no permission to edit customer invoices can see a edit button in project entry +FIX: #6671 Cannot remove thirdparty type with "#" in its name +FIX: #6673 Missing "nature" table header in thirdparty list +FIX: #6675 Restricted user with no agenda permissions can see a button to create appointment in thirdparty contact list +FIX: #6677 Expired contracts dashboard box does not show the name of the thirdparty +FIX: #6679 User with restricted supplier invoice permissions can edit project, payment conditions, payment mode +FIX: #6680 User with restricted supplier invoice permissions sees "reopen" button even if he has no permission to do it +FIX: #6813 +FIX: Correction with author and validator user on orders +FIX: doactions hook missing in invoice model page +FIX: dont get empty "Incoterms : - " string if no incoterm +FIX: dont lose supplier ref if no supplier price in database +FIX: forgotten parameter for right multicompany use +FIX: global $dateSelector isn't the good one, then date selector on objectline_create tpl was hidden +FIX: limit+1 dosn't show Total line +FIX: supplier order line were always created with rang = 0 + + ***** ChangeLog for 4.0.5 to 4.0.4 ***** FIX: #6234 FIX: #6259 From bd891ea56ab2de44ce7fc3f5ffe538d51ba7e9bc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 May 2017 00:26:02 +0200 Subject: [PATCH 11/66] Deploy to server works even when cloudflare is active. --- build/makepack-dolibarr.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index 1dbd6f6fd5e..20dfc2579aa 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -19,7 +19,7 @@ use Cwd; # Change this to defined target for option 98 and 99 $PROJECT="dolibarr"; $PUBLISHSTABLE="eldy,dolibarr\@frs.sourceforge.net:/home/frs/project/dolibarr"; -$PUBLISHBETARC="ldestailleur\@asso.dolibarr.org:/home/dolibarr/dolibarr.org/httpdocs/files"; +$PUBLISHBETARC="ldestailleur\@vmprod.dolibarr.org:/home/dolibarr/dolibarr.org/httpdocs/files"; #@LISTETARGET=("TGZ","ZIP","RPM_GENERIC","RPM_FEDORA","RPM_MANDRIVA","RPM_OPENSUSE","DEB","APS","EXEDOLIWAMP","SNAPSHOT"); # Possible packages From fa6bc037656281e5293ee26bcce82f9f8a96c73f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 May 2017 01:32:36 +0200 Subject: [PATCH 12/66] Fix typo --- htdocs/admin/modules.php | 17 ++++++++++------- htdocs/core/lib/files.lib.php | 2 +- htdocs/langs/en_US/modulebuilder.lang | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 5c4291ff3f3..fe735cb2499 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -430,7 +430,6 @@ print "
\n"; if ($mode == 'common') { - print '
'; if ($optioncss != '') print ''; print ''; @@ -763,13 +762,20 @@ if ($mode == 'common') } print "\n"; - } - print "\n"; - print ''; + if ($oldfamily) + { + print "\n"; + print ''; + } dol_fiche_end(); + + // Show warning about external users + print info_admin(showModulesExludedForExternal($modules))."\n"; + + print '
'; } if ($mode == 'marketplace') @@ -909,9 +915,6 @@ if ($mode == 'deploy') } -// Show warning about external users -if ($mode == 'common') print info_admin(showModulesExludedForExternal($modules))."\n"; - llxFooter(); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index ad800708522..e52f8bf98ec 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -588,7 +588,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep if (empty($srcfile) || empty($destfile)) return -1; $destexists=dol_is_dir($destfile); - //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propaated to dol_copy only. + //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. if (! $destexists) { diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 7336a020fa6..b717bafc57c 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -7,9 +7,9 @@ NewModule=New module ModuleKey=Key for new module ModuleInitialized=Module initialized ModuleBuilderDescdescription=Enter here all general information that describe your module -ModuleBuilderDescobjects=Define here the new objects you want to manage with our module. A page to list them and a page to create/edit/view a card will be generated. +ModuleBuilderDescobjects=Define here the new objects you want to manage with your module. A page to list them and a page to create/edit/view a card will be generated. ModuleBuilderDescmenus=This tab is dedicated to define menu entries provided by your module. -ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions you want to provide with our module. +ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions you want to provide with your module. ModuleBuilderDesctriggers=This is the view of triggers provided by your module. To include code executed when a triggered business event is launched, just edit this file with your IDE. ModuleBuilderDescbuildpackage=You can generate here a "ready to distribute" package file (a normalized .zip file) of your module. Just click on button to get your module package file. BuildPackage=Build package From a0de94ae0963d672145d3273e2552dc99c77d169 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 30 May 2017 06:28:19 +0200 Subject: [PATCH 13/66] Fix : Correct donation when we write operation in general ledger --- htdocs/accountancy/journal/bankjournal.php | 37 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index ea98d678671..6aa900f3a89 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php'; @@ -222,7 +223,7 @@ if ($result) { // Now loop on each link of record in bank. foreach ( $links as $key => $val ) { - if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert'))) // So we excluded 'company' here + if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation'))) // So we excluded 'company' here { // We save tabtype for a future use, to remember what kind of payment it is $tabtype[$obj->rowid] = $links[$key]['type']; @@ -278,7 +279,8 @@ if ($result) { } else if ($links[$key]['type'] == 'payment_donation') { $paymentdonstatic->id = $links[$key]['url_id']; $paymentdonstatic->fk_donation = $links[$key]['url_id']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentDonation"); + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentdonstatic->getNomUrl(2); + $tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id; $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount; } else if ($links[$key]['type'] == 'payment_vat') { $paymentvatstatic->id = $links[$key]['url_id']; @@ -415,6 +417,9 @@ if (! $error && $action == 'writebookkeeping') { $objmid = $db->fetch_object($resultmid); $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport } + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->code_tiers = ''; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation } $result = $bookkeeping->create($user); @@ -435,7 +440,7 @@ if (! $error && $action == 'writebookkeeping') { } } } - + // Third party if (! $errorforline) { @@ -475,7 +480,6 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; $bookkeeping->numero_compte = $k; } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice - $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; @@ -489,6 +493,10 @@ if (! $error && $action == 'writebookkeeping') { } $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; $bookkeeping->numero_compte = $k; + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->code_tiers = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation } else if ($tabtype[$key] == 'banktransfert') { $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; @@ -724,6 +732,7 @@ if (empty($action) || $action == 'view') { $invoicestatic = new Facture($db); $invoicesupplierstatic = new FactureFournisseur($db); $expensereportstatic = new ExpenseReport($db); + $donationstatic = new Don($db); llxHeader('', $langs->trans("FinanceJournal")); @@ -793,7 +802,7 @@ if (empty($action) || $action == 'view') { } if ($reflabel == '(CustomerInvoicePayment)') { $reflabel = $langs->trans('Customer'); - } + } if ($reflabel == '(SocialContributionPayment)') { $reflabel = $langs->trans('SocialContribution'); } @@ -806,7 +815,7 @@ if (empty($action) || $action == 'view') { if ($reflabel == '(ExpenseReportPayment)') { $reflabel = $langs->trans('Employee'); } - + $ref=$reflabel; if ($tabtype[$key] == 'payment') { @@ -850,6 +859,20 @@ if (empty($action) || $action == 'view') { } else dol_print_error($db); } + elseif ($tabtype[$key] == 'payment_donation') + { + $sqlmid = 'SELECT payd.fk_donation as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_donation as payd"; + $sqlmid .= " WHERE payd.fk_donation=" . $val["paymentdonationid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $donationstatic->fetch($objmid->id); + $ref=$langs->trans("Donation").' '.$donationstatic->getNomUrl(1); + } + else dol_print_error($db); + } /*$invoicestatic->id = $key; @@ -871,7 +894,7 @@ if (empty($action) || $action == 'view') { else print $accountoshow; print ""; if ($val['soclib'] == '') { - print "" . $bankstatic->label . " - " . $val["ref"] . ""; + print "" . $bankstatic->label . " - " . $reflabel . ""; } else { print "" . $bankstatic->label . " - " . $val['soclib'] . ""; } From c66695bd56e86f506fa78de2e18cd1f9021e4daf Mon Sep 17 00:00:00 2001 From: gauthier Date: Tue, 30 May 2017 15:35:51 +0200 Subject: [PATCH 14/66] FIX : origin & originid on supplierproposal --- .../class/supplier_proposal.class.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 572735384e4..aa845169475 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -356,11 +356,13 @@ class SupplierProposal extends CommonObject * @param array $array_option extrafields array * @param string $ref_fourn Supplier price reference * @param int $fk_unit Id of the unit to use. + * @param string $origin 'order', 'supplier_proposal', ... + * @param int $origin_id Id of origin line * @return int >0 if OK, <0 if KO * * @see add_product */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='') + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin, $origin_id) { global $mysoc; @@ -462,7 +464,8 @@ class SupplierProposal extends CommonObject $this->line->special_code=$special_code; $this->line->fk_parent_line=$fk_parent_line; $this->line->fk_unit=$fk_unit; - + $this->line->origin=$origin; + $this->line->origin_id=$origin_id; $this->line->ref_fourn = $this->db->escape($ref_fourn); // infos marge @@ -880,7 +883,10 @@ class SupplierProposal extends CommonObject $this->lines[$i]->pa_ht, $this->lines[$i]->label, $this->lines[$i]->array_options, - $this->lines[$i]->ref_fourn + $this->lines[$i]->ref_fourn, + $this->lines[$i]->fk_unit, + 'supplier_proposal', + $this->lines[$i]->rowid ); if ($result < 0) From 6b7c4cbbe198063ee403792e542cbeb6182da0a5 Mon Sep 17 00:00:00 2001 From: gauthier Date: Tue, 30 May 2017 16:00:21 +0200 Subject: [PATCH 15/66] FIX : default param --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index aa845169475..23c8257a4f5 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -362,7 +362,7 @@ class SupplierProposal extends CommonObject * * @see add_product */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin, $origin_id) + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0) { global $mysoc; From 200f4010d89deb5487364b5ff74c2e396d6e1a55 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 30 May 2017 16:00:39 +0200 Subject: [PATCH 16/66] Fix special char and size limit in SEPA XML --- htdocs/compta/prelevement/class/bonprelevement.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index f007fa41d21..814bece5bd1 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1574,10 +1574,10 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.strtoupper(dol_string_unaccent($row_nom)).''.$CrLf; + $XML_DEBITOR .=' '.strtoupper(dol_string_unaccent(dolEscapeXML($row_nom))).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$row_country_code.''.$CrLf; - $XML_DEBITOR .=' '.dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))).''.$CrLf; + $XML_DEBITOR .=' '.dol_trunc(dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))),70,'right','UTF-8',true).''.$CrLf; $XML_DEBITOR .=' '.dol_string_unaccent($row_zip.' '.$row_town).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; From 510b1aedcf12d2ce16780bb0fd185bbdbb9cdd68 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 30 May 2017 16:13:49 +0200 Subject: [PATCH 17/66] Fix xml SEPA $ListOfFactures not used and was listing all invoices in each XML line --- .../prelevement/class/bonprelevement.class.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 814bece5bd1..2bfed9b0696 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1265,18 +1265,6 @@ class BonPrelevement extends CommonObject * section Debiteur (sepa Debiteurs bloc lines) */ - $tmp_invoices = array(); - - $sql = "SELECT f.facnumber as fac FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."prelevement_facture as pf, ".MAIN_DB_PREFIX."societe as soc, ".MAIN_DB_PREFIX."c_country as p, ".MAIN_DB_PREFIX."societe_rib as rib WHERE pl.fk_prelevement_bons = ".$this->id." AND pl.rowid = pf.fk_prelevement_lignes AND pf.fk_facture = f.rowid AND soc.fk_pays = p.rowid AND soc.rowid = f.fk_soc AND rib.fk_soc = f.fk_soc AND rib.default_rib = 1"; - $resql=$this->db->query($sql); - if ($resql) { - while ($objfac = $this->db->fetch_object($resql)) { - $tmp_invoices[] = $objfac->fac; - } - } - - $ListOfFactures = implode($tmp_invoices); - $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql.= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum"; @@ -1303,7 +1291,7 @@ class BonPrelevement extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $ListOfFactures, $obj->idfac, $obj->iban, $obj->bic, $this->db->jdate($obj->datec), $obj->drum); + $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $this->db->jdate($obj->datec), $obj->drum); $this->total = $this->total + $obj->somme; $i++; } From 5d115bcf6919d8796ef2abcd0e2291e5de0855ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 May 2017 20:58:32 +0200 Subject: [PATCH 18/66] Fix deadlock feature, can't process a leave request when validator has left company. --- htdocs/holiday/card.php | 60 +++++++++++++++++++++++++++++---- htdocs/langs/en_US/holiday.lang | 2 +- htdocs/langs/en_US/main.lang | 2 ++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index c875caab271..78e2940942f 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -570,14 +570,43 @@ if ($action == 'confirm_refuse') } } + +// Si Validation de la demande +if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') +{ + $object = new Holiday($db); + $object->fetch($id); + + $oldstatus = $object->statut; + $object->statut = 1; + + $result = $object->update($user); + if ($result < 0) + { + $error = $langs->trans('ErrorBackToDraft'); + } + + if (! $error) + { + $db->commit(); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $db->rollback(); + } +} + // Si Validation de la demande if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { $object = new Holiday($db); $object->fetch($id); - // Si statut en attente de validation et valideur = utilisateur - if (($object->statut == 2 || $object->statut == 3) && ($user->id == $object->fk_validator || $user->id == $object->fk_user)) + // Si statut en attente de validation et valideur = valideur ou utilisateur, ou droits de faire pour les autres + if (($object->statut == 2 || $object->statut == 3) && ($user->id == $object->fk_validator || $user->id == $object->fk_user || ! empty($user->rights->holiday->write_all))) { $db->begin(); @@ -989,6 +1018,12 @@ else print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1); } + // Si back to draft + if ($action == 'backtodraft') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1); + } + $head=holiday_prepare_head($object); @@ -1208,18 +1243,31 @@ else print ''.$langs->trans("DeleteCP").''; } - if ($user->id == $object->fk_validator && $object->statut == 2) + if ($object->statut == 2) { - print ''.$langs->trans("Approve").''; - print ''.$langs->trans("ActionRefuseCP").''; + if ($user->id == $object->fk_validator) + { + print ''.$langs->trans("Approve").''; + print ''.$langs->trans("ActionRefuseCP").''; + } + else + { + print ''.$langs->trans("Approve").''; + print ''.$langs->trans("ActionRefuseCP").''; + } } - if (($user->id == $object->fk_validator || $user->id == $object->fk_user) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved + if (($user->id == $object->fk_validator || $user->id == $object->fk_user || ! empty($user->rights->holiday->write_all)) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved { if (($object->date_debut > dol_now()) || $user->admin) print ''.$langs->trans("ActionCancelCP").''; else print ''.$langs->trans("ActionCancelCP").''; } + if ($canedit && $object->statut == 4) + { + print ''.$langs->trans("SetToDraft").''; + } + print ''; } diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 441701c098d..e8d225d5af6 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -16,7 +16,7 @@ CancelCP=Canceled RefuseCP=Refused ValidatorCP=Approbator ListeCP=List of leaves -ReviewedByCP=Will be reviewed by +ReviewedByCP=Will be approved by DescCP=Description SendRequestCP=Create leave request DelayToRequestCP=Leave requests must be made at least %s day(s) before them. diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index ec4e218a11e..ba95ce233f8 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -757,6 +757,8 @@ SomeTranslationAreUncomplete=Some languages may be partially translated or may c DirectDownloadLink=Direct download link Download=Download ActualizeCurrency=Update currency rate +TitleSetToDraft=Go back to draft +ConfirmSetToDraft=Are you sure you want to go back to Draft status ? # Week day Monday=Monday Tuesday=Tuesday From 48a6e9e03808cbc2a8c9b43f69392aede20c0e92 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 May 2017 22:31:57 +0200 Subject: [PATCH 19/66] Removed not used files --- htdocs/modulebuilder/index.html | 0 htdocs/modulebuilder/oldskeletons/.gitignore | 2 - htdocs/modulebuilder/oldskeletons/README | 34 - .../oldskeletons/build_api_class.php | 123 ---- .../oldskeletons/build_class_from_table.php | 677 ------------------ .../build_webservice_from_class.php | 179 ----- .../oldskeletons/modMyModule.class.php | 291 -------- .../oldskeletons/skeleton_api_class.class.php | 289 -------- .../oldskeletons/skeleton_card.php | 604 ---------------- .../oldskeletons/skeleton_class.class.php | 606 ---------------- .../oldskeletons/skeleton_list.php | 570 --------------- .../oldskeletons/skeleton_script.php | 166 ----- .../skeleton_webservice_server.php | 272 ------- .../stock/class/api_stockmovements.class.php | 1 + 14 files changed, 1 insertion(+), 3813 deletions(-) create mode 100644 htdocs/modulebuilder/index.html delete mode 100644 htdocs/modulebuilder/oldskeletons/.gitignore delete mode 100644 htdocs/modulebuilder/oldskeletons/README delete mode 100755 htdocs/modulebuilder/oldskeletons/build_api_class.php delete mode 100755 htdocs/modulebuilder/oldskeletons/build_class_from_table.php delete mode 100755 htdocs/modulebuilder/oldskeletons/build_webservice_from_class.php delete mode 100644 htdocs/modulebuilder/oldskeletons/modMyModule.class.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_api_class.class.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_card.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_class.class.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_list.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_script.php delete mode 100644 htdocs/modulebuilder/oldskeletons/skeleton_webservice_server.php diff --git a/htdocs/modulebuilder/index.html b/htdocs/modulebuilder/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/modulebuilder/oldskeletons/.gitignore b/htdocs/modulebuilder/oldskeletons/.gitignore deleted file mode 100644 index 2dda6229d24..00000000000 --- a/htdocs/modulebuilder/oldskeletons/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out.* -socpeople* diff --git a/htdocs/modulebuilder/oldskeletons/README b/htdocs/modulebuilder/oldskeletons/README deleted file mode 100644 index 5b5b992d91e..00000000000 --- a/htdocs/modulebuilder/oldskeletons/README +++ /dev/null @@ -1,34 +0,0 @@ -README (English) --------------------------------- -This directory contains PHP script samples that can be used to start a development on Dolibarr. - - -*** build_class_from_table.php: - -This is the script to use to generate PHP code of a PHP POJO class -object, a PHP script that use this POJO. This script use the files -skeleton_*.php to build its generated code. - - -*** modMyModule.class.php: - -Is a sample of module descriptor that you can use if you want to build a new module/plugin for -Dolibarr. - - -*** skeleton_script.php: - -Is a sample you can use as an example if you need to build a script to run on command line - - -*** skeleton_page.php: - -Is a sample you can use as an example if you need to build an HTML page to include in Dolibarr GUI. - - -*** skeleton_class.class.php: - -Is a sample you can use as an example if you need to build a class file to access a new table required by a Dolibarr development. -However it is better to run the build_class_from_table.php script that accepts a table name as a parameter and will uses the description table within database and the skeleton_class.class.php file to generate full code for your class file. -After running this script, the class to access your table (insert a record, update, delete and select) is directly finished and can be used by your module's code. -No more coding is needed to get access to table with this script because the file is completely generated once. diff --git a/htdocs/modulebuilder/oldskeletons/build_api_class.php b/htdocs/modulebuilder/oldskeletons/build_api_class.php deleted file mode 100755 index 6263eabcd6e..00000000000 --- a/htdocs/modulebuilder/oldskeletons/build_api_class.php +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env php - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/build_api_class.php - * \ingroup core - * \brief Create a complete API class file from existant class file - */ - -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; -} - -// Include Dolibarr environment -require_once($path."../../htdocs/master.inc.php"); -// After this $db is a defined handler to database. - -// Main -$version='1'; -@set_time_limit(0); -$error=0; - -$langs->load("main"); - - -print "***** $script_file ($version) *****\n"; - - -// -------------------- START OF BUILD_API_FROM_CLASS -------------------- - -// Check parameters -if (! isset($argv[1]) && ! isset($argv[2])) -{ - print "Usage: $script_file phpClassFile phpClassName\n"; - exit; -} -// Show parameters -print 'Classfile='.$argv[1]."\n"; -print 'Classname='.$argv[2]."\n"; - -$classfile=$argv[1]; -$classname=$argv[2]; -$classmin=strtolower($classname); -$classnameApi = $classname.'Api'; -$property=array(); -$targetcontent=''; - -// Load the class and read properties -require_once($classfile); - -$property=array(); -$class = new $classname($db); -$values=get_class_vars($classname); - -unset($values['db']); -unset($values['error']); -unset($values['errors']); -unset($values['element']); -unset($values['table_element']); -unset($values['table_element_line']); -unset($values['fk_element']); -unset($values['ismultientitymanaged']); - -// Read skeleton_api_class.class.php file -$skeletonfile=$path.'skeleton_api_class.class.php'; -$sourcecontent=file_get_contents($skeletonfile); -if (! $sourcecontent) -{ - print "\n"; - print "Error: Failed to read skeleton sample '".$skeletonfile."'\n"; - print "Try to run script from skeletons directory.\n"; - exit; -} - -// Define output variables -$outfile='out.api_'.$classmin.'.class.php'; -$targetcontent=$sourcecontent; - -// Substitute class name -$targetcontent=preg_replace('/skeleton_api_class\.class\.php/', 'api_'.$classmin.'.class.php', $targetcontent); -$targetcontent=preg_replace('/skeleton/', $classmin, $targetcontent); -//$targetcontent=preg_replace('/\$table_element=\'skeleton\'/', '\$table_element=\''.$tablenoprefix.'\'', $targetcontent); -$targetcontent=preg_replace('/SkeletonApi/', $classnameApi, $targetcontent); -$targetcontent=preg_replace('/Skeleton/', $classname, $targetcontent); - -// Build file -$fp=fopen($outfile,"w"); -if ($fp) -{ - fputs($fp, $targetcontent); - fclose($fp); - print "\n"; - print "File '".$outfile."' has been built in current directory.\n"; -} -else $error++; - - - -// -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- - -print "You can now rename generated files by removing the 'out.' prefix in their name and store them into directory /module/class.\n"; -return $error; diff --git a/htdocs/modulebuilder/oldskeletons/build_class_from_table.php b/htdocs/modulebuilder/oldskeletons/build_class_from_table.php deleted file mode 100755 index 0e5a6d82a82..00000000000 --- a/htdocs/modulebuilder/oldskeletons/build_class_from_table.php +++ /dev/null @@ -1,677 +0,0 @@ -#!/usr/bin/env php - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/build_class_from_table.php - * \ingroup core - * \brief Create a complete class file from a table in database - */ - -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; -} - -// Include Dolibarr environment -require_once($path."../../htdocs/master.inc.php"); -// After this $db is a defined handler to database. - -// Main -$version='3.2'; -@set_time_limit(0); -$error=0; - -$langs->load("main"); - - -print "***** $script_file ($version) *****\n"; - - -// -------------------- START OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- - -// Check parameters -if (! isset($argv[1]) || ! isset($argv[2]) || (isset($argv[3]) && ! isset($argv[7]))) -{ - print "Usage: $script_file tablename modulename [server port databasename user pass]\n"; - exit; -} - -if (isset($argv[3]) && isset($argv[4]) && isset($argv[5]) && isset($argv[6]) && isset($argv[7])) -{ - print 'Use specific database ids'."\n"; - $db=getDoliDBInstance('mysqli',$argv[3],$argv[6],$argv[7],$argv[5],$argv[4]); -} - -if ($db->type != 'mysql' && $db->type != 'mysqli') -{ - print "Error: This script works with mysql or mysqli driver only\n"; - exit; -} - -$table=$argv[1]; -$module=$argv[2]; - -// Show parameters -print 'Tablename: '.$table."\n"; -print 'Modulename: '.$module."\n"; -print "Current dir: ".getcwd()."\n"; -print "Database name: ".$db->database_name."\n"; - - -// Define array with list of properties -$property=array(); -$foundprimary=0; -$resql=$db->DDLDescTable($table); -if ($resql) -{ - $i=0; - while($obj=$db->fetch_object($resql)) - { - //var_dump($obj); - $i++; - $property[$i]['field']=$obj->Field; - if ($obj->Key == 'PRI') - { - $property[$i]['primary']=1; - $foundprimary=1; - } - else - { - $property[$i]['primary']=1; - } - $property[$i]['type'] =$obj->Type; - $property[$i]['null'] =$obj->Null; - $property[$i]['extra']=$obj->Extra; - if ($property[$i]['type'] == 'date' - || $property[$i]['type'] == 'datetime' - || $property[$i]['type'] == 'timestamp') - { - $property[$i]['istime']=true; - } - else - { - $property[$i]['istime']=false; - } - if (preg_match('/varchar/i',$property[$i]['type']) - || preg_match('/text/i',$property[$i]['type'])) - { - $property[$i]['ischar']=true; - } - else - { - $property[$i]['ischar']=false; - } - if (preg_match('/int/i',$property[$i]['type'])) - { - $property[$i]['isint']=true; - } - else - { - $property[$i]['isint']=false; - } - } -} -else -{ - print "Error: Failed to get description for table '".$table."'.\n"; - return false; -} -//var_dump($property); - -// Define substitute fetch/select parameters -$varpropselect="\n"; -$cleanparam=''; -$i=0; -foreach($property as $key => $prop) -{ - $i++; - if ($prop['field'] != 'rowid') - { - $varpropselect.="\t\t\$sql .= \" "; - $varpropselect.="t.".$prop['field']; - if ($i < count($property)) $varpropselect.=","; - $varpropselect.="\";"; - $varpropselect.="\n"; - } -} - - - -//-------------------------------- -// Build skeleton_class.class.php -//-------------------------------- - -// Define working variables -$table=strtolower($table); -$tablenoprefix=preg_replace('/'.preg_quote(MAIN_DB_PREFIX,'/').'/i','',$table); -$classname=preg_replace('/_/','',ucfirst($tablenoprefix)); -$classmin=preg_replace('/_/','',strtolower($classname)); - - -// Read skeleton_class.class.php file -$skeletonfile=$path.'skeleton_class.class.php'; -$sourcecontent=file_get_contents($skeletonfile); -if (! $sourcecontent) -{ - print "\n"; - print "Error: Failed to read skeleton sample '".$skeletonfile."'\n"; - print "Try to run script from skeletons directory.\n"; - exit; -} - -// Define output variables -$outfile=$classmin.'.class.php'; -$targetcontent=$sourcecontent; - -// Substitute module name -$targetcontent=preg_replace('/dev\/skeletons/', $module, $targetcontent); -$targetcontent=preg_replace('/mymodule othermodule1 othermodule2/', $module, $targetcontent); -$targetcontent=preg_replace('/mymodule/', $module, $targetcontent); - -// Substitute class name -$targetcontent=preg_replace('/skeleton_class\.class\.php/', $classmin.'.class.php', $targetcontent); -$targetcontent=preg_replace('/\$element = \'skeleton\'/', '\$element = \''.$classmin.'\'', $targetcontent); -$targetcontent=preg_replace('/\$table_element = \'skeleton\'/', '\$table_element = \''.$tablenoprefix.'\'', $targetcontent); -$targetcontent=preg_replace('/Skeleton_Class/', $classname, $targetcontent); -$targetcontent=preg_replace('/skeletons/', $classmin, $targetcontent); -$targetcontent=preg_replace('/skeleton/', $classmin, $targetcontent); - -// Substitute comments -$targetcontent=preg_replace('/This file is an example to create a new class file/', 'Put here description of this class', $targetcontent); -$targetcontent=preg_replace('/\s*\/\/\.\.\./', '', $targetcontent); -$targetcontent=preg_replace('/Put here some comments/','Initialy built by build_class_from_table on '.strftime('%Y-%m-%d %H:%M',mktime()), $targetcontent); - -// Substitute table name -$targetcontent=preg_replace('/MAIN_DB_PREFIX."mytable/', 'MAIN_DB_PREFIX."'.$tablenoprefix, $targetcontent); - -// Substitute declaration parameters -$varprop="\n"; -$cleanparam=''; -foreach($property as $key => $prop) -{ - if ($prop['field'] != 'rowid' && $prop['field'] != 'id') - { - $varprop.="\tpublic \$".$prop['field']; - if ($prop['istime']) $varprop.=" = ''"; - $varprop.=";"; - if ($prop['comment']) $varprop.="\t// ".$prop['extra']; - $varprop.="\n"; - } -} -$targetcontent=preg_replace('/'.preg_quote('public $prop1;','/').'/', $varprop, $targetcontent); -$targetcontent=preg_replace('/'.preg_quote('public $prop2;','/').'/', '', $targetcontent); - -$targetcontent=preg_replace('/\*((\s|\n|\r|\t)*)\@var mixed Sample property 1((\s|\n|\r|\t)*)/', '', $targetcontent); -$targetcontent=preg_replace('/\*((\s|\n|\r|\t)*)\@var mixed Sample property 2((\s|\n|\r|\t)*)/', '', $targetcontent); - -// Substitute clean parameters -$varprop="\n"; -$cleanparam=''; -foreach($property as $key => $prop) -{ - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="\t\tif (isset(\$this->".$prop['field'].")) {\n\t\t\t \$this->".$prop['field']." = trim(\$this->".$prop['field'].");\n\t\t}"; - $varprop.="\n"; - } -} -$targetcontent=preg_replace('/if \(isset\(\$this->prop1\)\) {((\n|\r|\t)*)\$this->prop1 = trim\(\$this->prop1\);((\n|\r|\t)*)}/', $varprop, $targetcontent); -$targetcontent=preg_replace('/if \(isset\(\$this->prop2\)\) {((\n|\r|\t)*)\$this->prop2 = trim\(\$this->prop2\);((\n|\r|\t)*)}/', '', $targetcontent); - - -$no_output_field=0; -foreach($property as $key => $prop) -{ - if ($prop['field'] == 'tms') $no_output_field++; // This is a field of type timestamp edited automatically - if ($prop['extra'] == 'auto_increment') $no_output_field++; -} -// Substitute insert into parameters -$varprop="\n"; -$cleanparam=''; -$i=0; -foreach($property as $key => $prop) -{ - $i++; - $addfield=1; - if ($prop['field'] == 'tms') $addfield=0; // This is a field of type timestamp edited automatically - if ($prop['extra'] == 'auto_increment') $addfield=0; - - if ($addfield) - { - $varprop.="\t\t\$sql.= '".$prop['field']; - if ($i < (count($property)-$no_output_field)) $varprop.=","; - $varprop.="';"; - $varprop.="\n"; - } -} -$targetcontent=preg_replace('/\$sql \.= \' field1,\';/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\$sql \.= \' field2\';/', '', $targetcontent); - -// Substitute insert values parameters -$varprop="\n"; -$cleanparam=''; -$i=0; - -//Count nb field to output to manage commat at end SQL instruction - - -foreach($property as $key => $prop) -{ - - $addfield=1; - if ($prop['field'] == 'tms') $addfield=0; // This is a field of type timestamp edited automatically - if ($prop['extra'] == 'auto_increment') $addfield=0; - - if ($addfield) - { - $i++; - - $varprop.="\t\t\$sql .= ' "; - if ($prop['field']=='datec') - { - $varprop.='\'."\'".$this->db->idate(dol_now())."\'"'; - } - elseif ($prop['istime']) - { - $varprop.='\'.(! isset($this->'.$prop['field'].') || dol_strlen($this->'.$prop['field'].')==0?\'NULL\':"\'".$this->db->idate('; - $varprop.="\$this->".$prop['field']; - $varprop.=").\"'\")"; - } - elseif ($prop['ischar']) - { - $varprop.="'.(! isset(\$this->".$prop['field'].")?'NULL':\"'\"."; - $varprop.="\$this->db->escape(\$this->".$prop['field'].")"; - $varprop.=".\"'\")"; - } - elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_m' || $prop['field']=='fk_user_author') - { - $varprop.="'.\$user->id"; - } - elseif ($prop['isint']) - { - $varprop.='\'.(! isset($this->'.$prop['field'].')?\'NULL\':'; - $varprop.="\$this->".$prop['field']; - $varprop.=')'; - } - else - { - $varprop.='\'.(! isset($this->'.$prop['field'].')?\'NULL\':"\'".'; - $varprop.="\$this->".$prop['field']; - $varprop.='."\'")'; - } - - if ($i < (count($property)-$no_output_field)) $varprop.=".','"; - $varprop.=';'; - $varprop.="\n"; - } -} - -$patern1='/\$sql \.= \' (.*)\' \. \$this->prop1 \. \'(.*),\';/'; -$patern2='/\$sql \.= \' (.*)\' \. \$this->prop2 \. \'(.*)\';/'; -$targetcontent=preg_replace($patern1, $varprop, $targetcontent); -$targetcontent=preg_replace($patern2, '', $targetcontent); - -// Substitute update values parameters - -//Count nb field to output to manage commat at end SQL instruction -$no_output_field=0; -foreach($property as $key => $prop) -{ - if ($prop['extra'] == 'auto_increment') $no_output_field++; -} - -$varprop="\n"; -$cleanparam=''; -$i=0; -foreach($property as $key => $prop) -{ - - $addfield=1; - if ($prop['extra'] == 'auto_increment') $addfield=0; - - if ($addfield) - { - $i++; - - $varprop.="\t\t\$sql .= ' "; - $varprop.=$prop['field'].' = '; - if ($prop['field']=='tms') { - $varprop.='\'.(dol_strlen($this->'.$prop['field'].') != 0 ? "\'".$this->db->idate('; - $varprop.='$this->'.$prop['field']; - $varprop.=')."\'" : "\'".$this->db->idate(dol_now())."\'")'; - } - elseif ($prop['istime']) - { - $varprop.='\'.(! isset($this->'.$prop['field'].') || dol_strlen($this->'.$prop['field'].') != 0 ? "\'".$this->db->idate('; - $varprop.='$this->'.$prop['field']; - $varprop.=')."\'" : \'null\')'; - } - - elseif ($prop['field']=='fk_user_mod' || $prop['field']=='fk_user_m') { - $varprop.="'.\$user->id"; - } - else - { - $varprop.="'."; - if ($prop['ischar']) $varprop.='(isset($this->'.$prop['field'].')?"\'".$this->db->escape($this->'.$prop['field'].')."\'":"null")'; - elseif ($prop['isint']) $varprop.='(isset($this->'.$prop['field'].')?$this->'.$prop['field'].':"null")'; - else $varprop.='(isset($this->'.$prop['field'].')?$this->'.$prop['field'].':"null")'; - } - - if ($i < (count($property)-$no_output_field)) $varprop.=".','"; - $varprop.=';'; - $varprop.="\n"; - } -} -$targetcontent=preg_replace('/\$sql \.= " field1=".\(isset\(\$this->field1\)\?"\'".\$this->db->escape\(\$this->field1\)."\'":"null"\).",";/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\$sql \.= " field2=".\(isset\(\$this->field2\)\?"\'".\$this->db->escape\(\$this->field2\)."\'":"null"\)."";/', '', $targetcontent); - -// Substitute fetch/select parameters -$targetcontent=preg_replace('/\$sql \.= \' t\.field1,\';/', $varpropselect, $targetcontent); -$targetcontent=preg_replace('/\$sql \.= \' t\.field2\';/', '', $targetcontent); - -// Substitute select set parameters -$varprop="\n"; -$varpropline="\n"; -$cleanparam=''; -$i=0; -foreach($property as $key => $prop) -{ - $i++; - if ($prop['field'] != 'rowid' && $prop['field'] != 'id') - { - $varprop.="\t\t\t\t\$this->".$prop['field']." = "; - if ($prop['istime']) $varprop.='$this->db->jdate('; - $varprop.='$obj->'.$prop['field']; - if ($prop['istime']) $varprop.=')'; - $varprop.=";"; - $varprop.="\n"; - - $varpropline.="\t\t\t\t\$line->".$prop['field']." = "; - if ($prop['istime']) $varpropline.='$this->db->jdate('; - $varpropline.='$obj->'.$prop['field']; - if ($prop['istime']) $varpropline.=')'; - $varpropline.=";"; - $varpropline.="\n"; - } -} -$targetcontent=preg_replace('/\$this->prop1 = \$obj->field1;/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\$this->prop2 = \$obj->field2;/', '', $targetcontent); - -//Substirute fetchAll -$targetcontent=preg_replace('/\$line->prop1 = \$obj->field1;/', $varpropline, $targetcontent); -$targetcontent=preg_replace('/\$line->prop2 = \$obj->field2;/', '', $targetcontent); - - -// Substitute initasspecimen parameters -$varprop="\n"; -$cleanparam=''; -foreach($property as $key => $prop) -{ - if ($prop['field'] != 'rowid' && $prop['field'] != 'id') - { - $varprop.="\t\t\$this->".$prop['field']." = '';"; - $varprop.="\n"; - } -} -$targetcontent=preg_replace('/\$this->prop1 = \'prop1\';/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\$this->prop2 = \'prop2\';/', '', $targetcontent); - -// Build file -$fp=fopen($outfile,"w"); -if ($fp) -{ - fputs($fp, $targetcontent); - fclose($fp); - print "\n"; - print "File '".$outfile."' has been built in current directory.\n"; -} -else $error++; - - - -//-------------------------------------------------------------------- -// Build skeleton_script.php, skeleton_list.php and skeleton_card.php -//-------------------------------------------------------------------- - -$skeletonfiles=array( - $path.'skeleton_script.php' => $classmin.'_script.php', - $path.'skeleton_list.php' => $classmin.'_list.php', - $path.'skeleton_card.php' => $classmin.'_card.php' - ); - -foreach ($skeletonfiles as $skeletonfile => $outfile) -{ - $sourcecontent=file_get_contents($skeletonfile); - if (! $sourcecontent) - { - print "\n"; - print "Error: Failed to read skeleton sample '".$skeletonfile."'\n"; - print "Try to run script from skeletons directory.\n"; - exit; - } - - // Define output variables - $targetcontent=$sourcecontent; - - // Substitute module name - $targetcontent=preg_replace('/dev\/skeletons/', $module, $targetcontent); - $targetcontent=preg_replace('/mymodule othermodule1 othermodule2/', $module, $targetcontent); - $targetcontent=preg_replace('/mymodule/', $module, $targetcontent); - - // Substitute class name - $targetcontent=preg_replace('/skeleton_class\.class\.php/', $classmin.'.class.php', $targetcontent); - $targetcontent=preg_replace('/skeleton_script\.php/', $classmin.'_script.php', $targetcontent); - $targetcontent=preg_replace('/\$element = \'skeleton\'/', '\$element=\''.$classmin.'\'', $targetcontent); - $targetcontent=preg_replace('/\$table_element = \'skeleton\'/', '\$table_element=\''.$classmin.'\'', $targetcontent); - $targetcontent=preg_replace('/Skeleton_Class/', $classname, $targetcontent); - $targetcontent=preg_replace('/skeletons/', $classmin, $targetcontent); - $targetcontent=preg_replace('/skeleton/', $classmin, $targetcontent); - - // Substitute comments - $targetcontent=preg_replace('/This file is an example to create a new class file/', 'Put here description of this class', $targetcontent); - $targetcontent=preg_replace('/\s*\/\/\.\.\./', '', $targetcontent); - $targetcontent=preg_replace('/Put here some comments/','Initialy built by build_class_from_table on '.strftime('%Y-%m-%d %H:%M',mktime()), $targetcontent); - - // Substitute table name - $targetcontent=preg_replace('/MAIN_DB_PREFIX."mytable/', 'MAIN_DB_PREFIX."'.$tablenoprefix, $targetcontent); - - // Substitute GETPOST search_fieldx - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - if ($prop['isint']) $varprop.='$search_'.$prop['field']."=GETPOST('search_".$prop['field']."','int');\n"; - else $varprop.='$search_'.$prop['field']."=GETPOST('search_".$prop['field']."','alpha');\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote('$search_field1=GETPOST("search_field1");','/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote('$search_field2=GETPOST("search_field2");','/').'/', '', $targetcontent); - - // Substitute GETPOST fieldx - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - if ($prop['isint']) $varprop.="\t\$object->".$prop['field']."=GETPOST('".$prop['field']."','int');\n"; - else $varprop.="\t\$object->".$prop['field']."=GETPOST('".$prop['field']."','alpha');\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote('$object->prop1=GETPOST("field1");','/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote('$object->prop2=GETPOST("field2");','/').'/', '', $targetcontent); - - // Substitute reset search_field = ''; - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.='$search_'.$prop['field']."='';\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote('$search_field1=\'\';','/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote('$search_field2=\'\';','/').'/', '', $targetcontent); - - // Substitute fetch/select parameters - $targetcontent=preg_replace('/\$sql\s*\.= " t\.field1,";/', $varpropselect, $targetcontent); - $targetcontent=preg_replace('/\$sql\s*\.= " t\.field2";/', '', $targetcontent); - - // Substitute where for search - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.='if ($search_'.$prop['field'].') $sql.= natural_search("'.$prop['field'].'",$search_'.$prop['field'].');'."\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote('if ($search_field1) $sql.= natural_search("field1",$search_field1);','/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote('if ($search_field2) $sql.= natural_search("field2",$search_field2);','/').'/', '', $targetcontent); - - // substitute $params.= - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="if (\$search_".$prop['field']." != '') \$params.= '&search_".$prop['field']."='.urlencode(\$search_".$prop['field'].");\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote("if (\$search_field1 != '') \$params.= '&search_field1='.urlencode(\$search_field1);",'/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote("if (\$search_field2 != '') \$params.= '&search_field2='.urlencode(\$search_field2);",'/').'/', '', $targetcontent); - - // Substitute arrayfields - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="'t.".$prop['field']."'=>array('label'=>\$langs->trans(\"Field".$prop['field']."\"), 'checked'=>1),\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote("'t.field1'=>array('label'=>\$langs->trans(\"Field1\"), 'checked'=>1),",'/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote("'t.field2'=>array('label'=>\$langs->trans(\"Field2\"), 'checked'=>1),",'/').'/', '', $targetcontent); - - // Substitute print_liste_field_titre - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="if (! empty(\$arrayfields['t.".$prop['field']."']['checked'])) print_liste_field_titre(\$arrayfields['t.".$prop['field']."']['label'],\$_SERVER['PHP_SELF'],'t.".$prop['field']."','',\$params,'',\$sortfield,\$sortorder);\n"; - } - } - $targetcontent=preg_replace('/LIST_OF_TD_TITLE_FIELDS/', $varprop, $targetcontent); - - // Substitute fields title search - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="if (! empty(\$arrayfields['t.".$prop['field']."']['checked'])) print '';\n"; - } - } - $targetcontent=preg_replace('/LIST_OF_TD_TITLE_SEARCH/', $varprop, $targetcontent); - - // Substitute where for .fieldx. - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="if (! empty(\$arrayfields['t.".$prop['field']."']['checked'])) print ''.\$obj->".$prop['field'].".'';\n"; - } - } - $targetcontent=preg_replace('/'.preg_quote("if (! empty(\$arrayfields['t.field1']['checked'])) print ''.\$obj->field1.'';",'/').'/', $varprop, $targetcontent); - $targetcontent=preg_replace('/'.preg_quote("if (! empty(\$arrayfields['t.field2']['checked'])) print ''.\$obj->field2.'';",'/').'/', '', $targetcontent); - - // LIST_OF_TD_LABEL_FIELDS_CREATE - List of td for card view - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.="print ''.\$langs->trans(\"Field".$prop['field']."\").'';\n"; - } - } - $targetcontent=preg_replace('/LIST_OF_TD_LABEL_FIELDS_CREATE/', $varprop, $targetcontent); - - // LIST_OF_TD_LABEL_FIELDS_EDIT - List of td for card view - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $baseString = 'print "".\$langs->trans("Field%s")."%s."\">";'; - $varprop.= sprintf("\t ".$baseString." \n", $prop['field'], $prop['field'], $prop['field']); - } - } - $targetcontent=preg_replace('/LIST_OF_TD_LABEL_FIELDS_EDIT/', $varprop, $targetcontent); - - // LIST_OF_TD_LABEL_FIELDS_VIEW - List of td for card view - $varprop="\n"; - $cleanparam=''; - foreach($property as $key => $prop) - { - if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) - { - $varprop.=sprintf("\t print ''.\$langs->trans(\"Field%s\").''.\$object->%s.'';\n",$prop['field'],$prop['field']); - } - } - $targetcontent=preg_replace('/LIST_OF_TD_LABEL_FIELDS_VIEW/', $varprop, $targetcontent); - - - // LIST_OF_TD_FIELDS_LIST - - - - // Build file - $fp=fopen($outfile,"w"); - if ($fp) - { - fputs($fp, $targetcontent); - fclose($fp); - print "File '".$outfile."' has been built in current directory.\n"; - } - else $error++; -} - - -// -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- - -print "You can now move generated files to store them into directory /yourmodule/class (for .class.php file) or /yourmodule.\n"; -return $error; diff --git a/htdocs/modulebuilder/oldskeletons/build_webservice_from_class.php b/htdocs/modulebuilder/oldskeletons/build_webservice_from_class.php deleted file mode 100755 index c91347a424d..00000000000 --- a/htdocs/modulebuilder/oldskeletons/build_webservice_from_class.php +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env php - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/build_webservice_from_class.php - * \ingroup core - * \brief Create a complete webservice file from CRUD functions of a PHP class - */ - -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; -} - -// Include Dolibarr environment -require_once($path."../../htdocs/master.inc.php"); -// After this $db is a defined handler to database. - -// Main -$version='1.8'; -@set_time_limit(0); -$error=0; - -$langs->load("main"); - - -print "***** $script_file ($version) *****\n"; - - -// -------------------- START OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- - -// Check parameters -if (! isset($argv[1]) && ! isset($argv[2])) -{ - print "Usage: $script_file phpClassFile phpClassName\n"; - exit; -} - -// Show parameters -print 'Classfile='.$argv[1]."\n"; -print 'Classname='.$argv[2]."\n"; - -$classfile=$argv[1]; -$classname=$argv[2]; -$classmin=strtolower($classname); -$property=array(); -$targetcontent=''; - -// Load the class and read properties -require_once($classfile); - -$property=array(); -$class = new $classname($db); -$values=get_class_vars($classname); - -unset($values['db']); -unset($values['error']); -unset($values['errors']); -unset($values['element']); -unset($values['table_element']); -unset($values['table_element_line']); -unset($values['fk_element']); -unset($values['ismultientitymanaged']); - -$properties=array_keys($values); - -// Read skeleton_class.class.php file -$skeletonfile='skeleton_webservice_server.php'; -$sourcecontent=file_get_contents($skeletonfile); -if (! $sourcecontent) -{ - print "\n"; - print "Error: Failed to read skeleton sample '".$skeletonfile."'\n"; - print "Try to run script from skeletons directory.\n"; - exit; -} - -// Define output variables -$outfile='out.server_'.$classmin.'.php'; -$targetcontent=$sourcecontent; - - - -// Substitute class name -$targetcontent=preg_replace('/Skeleton/', $classname, $targetcontent); -$targetcontent=preg_replace('/skeleton/', $classmin, $targetcontent); - -// Substitute declaration parameters -$varprop="\n"; -$cleanparam=''; -$i=0; - -while($i array('name'=>'".$properties[$i]."','type'=>'xsd:string')"; - $i++; - - if ($i == count($properties)) - $varprop.="\n"; - else - $varprop.=",\n"; -} - -$targetcontent=preg_replace('/\'prop1\'=>\'xxx\',/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\'prop2\'=>\'xxx\',/', '', $targetcontent); -// Substitute get method parameters -$varprop="\n"; -$cleanparam=''; -$i=0; - -while($i $".$classmin."->".$properties[$i]; - - $i++; - if ($i == count($properties)) - $varprop.="\n"; - else - $varprop.=",\n"; -} - -$targetcontent=preg_replace('/\'prop1\'=>\$'.$classmin.'->prop1,/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\'prop2\'=>\$'.$classmin.'->prop2,/', '', $targetcontent); - -// Substitute get method parameters -$varprop="\n\t\t"; -$cleanparam=''; -$i=0; - -while($i'.$properties[$i].';'; - - $i++; - if ($i == count($properties)) - $varprop.="\n"; - else - $varprop.="\n\t\t"; -} -$targetcontent=preg_replace('/\$newobject->prop1=\$'.$classmin.'->prop1;/', $varprop, $targetcontent); -$targetcontent=preg_replace('/\$newobject->prop2=\$'.$classmin.'->prop2;/', '', $targetcontent); - - - -// Build file -$fp=fopen($outfile,"w"); -if ($fp) -{ - fputs($fp, $targetcontent); - fclose($fp); - print "File '".$outfile."' has been built in current directory.\n"; -} -else $error++; - -// -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- - -print "You must rename files by removing the 'out.' prefix in their name.\n"; -return $error; diff --git a/htdocs/modulebuilder/oldskeletons/modMyModule.class.php b/htdocs/modulebuilder/oldskeletons/modMyModule.class.php deleted file mode 100644 index 4f994c7c654..00000000000 --- a/htdocs/modulebuilder/oldskeletons/modMyModule.class.php +++ /dev/null @@ -1,291 +0,0 @@ - - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2005-2016 Regis Houssin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \defgroup mymodule Module MyModule - * \brief Example of a module descriptor. - * Such a file must be copied into htdocs/mymodule/core/modules directory. - * \file htdocs/mymodule/core/modules/modMyModule.class.php - * \ingroup mymodule - * \brief Description and activation file for module MyModule - */ -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; - - -/** - * Description and activation class for module MyModule - */ -class modMyModule extends DolibarrModules -{ - /** - * Constructor. Define names, constants, directories, boxes, permissions - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - global $langs,$conf; - - $this->db = $db; - - // Id for module (must be unique). - // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). - $this->numero = 500000; // TODO Go on page http://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module - // Key text used to identify module (for permissions, menus, etc...) - $this->rights_class = 'mymodule'; - - // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other' - // It is used to group modules by family in module setup page - $this->family = "other"; - // Module position in the family - $this->module_position = 500; - // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) - //$this->familyinfo = array('myownfamily' => array('position' => '001', 'label' => $langs->trans("MyOwnFamily"))); - - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) - $this->name = preg_replace('/^mod/i','',get_class($this)); - // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) - $this->description = "Description of module MyModule"; - $this->descriptionlong = "A very long description. Can be a full HTML content"; - $this->editor_name = 'Editor name'; - $this->editor_url = 'https://www.dolibarr.org'; - - // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' - $this->version = '1.0'; - // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); - // Name of image file used for this module. - // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' - // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' - $this->picto='generic'; - - // Defined all module parts (triggers, login, substitutions, menus, css, etc...) - // for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable) - // for specific path of parts (eg: /mymodule/core/modules/barcode) - // for specific css file (eg: /mymodule/css/mymodule.css.php) - //$this->module_parts = array( - // 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers) - // 'login' => 0, // Set this to 1 if module has its own login method directory (core/login) - // 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions) - // 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus) - // 'theme' => 0, // Set this to 1 if module has its own theme directory (theme) - // 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl) - // 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode) - // 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx) - // 'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file - // 'js' => array('/mymodule/js/mymodule.js'), // Set this to relative path of js file if module must load a js on all pages - // 'hooks' => array('hookcontext1','hookcontext2',...) // Set here all hooks context managed by module. You can also set hook context 'all' - // 'dir' => array('output' => 'othermodulename'), // To force the default directories names - // 'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@mymodule')) // Set here all workflow context managed by module - // ); - $this->module_parts = array(); - - // Data directories to create when module is enabled. - // Example: this->dirs = array("/mymodule/temp"); - $this->dirs = array(); - - // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module. - $this->config_page_url = array("mysetuppage.php@mymodule"); - - // Dependencies - $this->hidden = false; // A condition to hide module - $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled - $this->requiredby = array(); // List of module ids to disable if this one is disabled - $this->conflictwith = array(); // List of module class names as string this module is in conflict with - $this->phpmin = array(5,0); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(3,0); // Minimum version of Dolibarr required by module - $this->langfiles = array("mylangfile@mymodule"); - - // Constants - // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) - // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), - // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) - // ); - $this->const = array(); - - // Array to add new pages in new tabs - // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1 - // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key. - // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname - // where objecttype can be - // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) - // 'contact' to add a tab in contact view - // 'contract' to add a tab in contract view - // 'group' to add a tab in group view - // 'intervention' to add a tab in intervention view - // 'invoice' to add a tab in customer invoice view - // 'invoice_supplier' to add a tab in supplier invoice view - // 'member' to add a tab in fundation member view - // 'opensurveypoll' to add a tab in opensurvey poll view - // 'order' to add a tab in customer order view - // 'order_supplier' to add a tab in supplier order view - // 'payment' to add a tab in payment view - // 'payment_supplier' to add a tab in supplier payment view - // 'product' to add a tab in product view - // 'propal' to add a tab in propal view - // 'project' to add a tab in project view - // 'stock' to add a tab in stock view - // 'thirdparty' to add a tab in third party view - // 'user' to add a tab in user view - $this->tabs = array(); - - if (! isset($conf->mymodule) || ! isset($conf->mymodule->enabled)) - { - $conf->mymodule=new stdClass(); - $conf->mymodule->enabled=0; - } - - // Dictionaries - $this->dictionaries=array(); - /* Example: - $this->dictionaries=array( - 'langs'=>'mylangfile@mymodule', - 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor - 'tablib'=>array("Table1","Table2","Table3"), // Label of tables - 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields - 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order - 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary) - 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record) - 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert) - 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid') - 'tabcond'=>array($conf->mymodule->enabled,$conf->mymodule->enabled,$conf->mymodule->enabled) // Condition to show each dictionary - ); - */ - - // Boxes - // Add here list of php file(s) stored in core/boxes that contains class to show a box. - $this->boxes = array(); // List of boxes - // Example: - //$this->boxes=array( - // 0=>array('file'=>'myboxa.php@mymodule','note'=>'','enabledbydefaulton'=>'Home'), - // 1=>array('file'=>'myboxb.php@mymodule','note'=>''), - // 2=>array('file'=>'myboxc.php@mymodule','note'=>'') - //); - - // Cronjobs - $this->cronjobs = array(); // List of cron jobs entries to add - // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'test'=>true), - // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'test'=>true) - // ); - - // Permissions - $this->rights = array(); // Permission array used by this module - $r=0; - - // Add here list of permission defined by an id, a label, a boolean and two constant strings. - // Example: - // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) - // $this->rights[$r][1] = 'Permision label'; // Permission label - // $this->rights[$r][3] = 1; // Permission by default for new user (0/1) - // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $r++; - - // Main menu entries - $this->menu = array(); // List of menus to add - $r=0; - - // Add here entries to declare new menus - // - // Example to declare a new Top Menu entry and its Left menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - // 'type'=>'top', // This is a Top menu entry - // 'titre'=>'MyModule top menu', - // 'mainmenu'=>'mymodule', - // 'leftmenu'=>'mymodule', - // 'url'=>'/mymodule/pagetop.php', - // 'langs'=>'mylangfile@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'enabled'=>'$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - // - // Example to declare a Left Menu entry into an existing Top menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu', - // 'mainmenu'=>'xxx', - // 'leftmenu'=>'mymodule', - // 'url'=>'/mymodule/pagelevel2.php', - // 'langs'=>'mylangfile@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'enabled'=>'$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - - - // Exports - $r=1; - - // Example: - // $this->export_code[$r]=$this->rights_class.'_'.$r; - // $this->export_label[$r]='MyModule'; // Translation key (used only if key ExportDataset_xxx_z not found) - // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled. - // $this->export_icon[$r]='generic:MyModule'; // Put here code of icon then string for translation key of module name - // $this->export_permission[$r]=array(array("mymodule","level1","level2")); - // $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'); - // $this->export_TypeFields_array[$r]=array('t.date'=>'Date', 't.qte'=>'Numeric', 't.poids'=>'Numeric', 't.fad'=>'Numeric', 't.paq'=>'Numeric', 't.stockage'=>'Numeric', 't.fadparliv'=>'Numeric', 't.livau100'=>'Numeric', 't.forfait'=>'Numeric', 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.facnumber'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'fd.description'=>"Text",'fd.subprice'=>"Numeric",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.date_start'=>"Date",'fd.date_end'=>"Date",'fd.special_code'=>'Numeric','fd.product_type'=>"Numeric",'fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','p.accountancy_code_sell'=>'Text'); - // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'); - // $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them - // $this->export_sql_start[$r]='SELECT DISTINCT '; - // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)'; - // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; - // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; - // $this->export_sql_order[$r] .=' ORDER BY s.nom'; - // $r++; - } - - /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - public function init($options='') - { - $sql = array(); - - //$this->_load_tables('/mymodule/sql/'); - - return $this->_init($sql, $options); - } - - /** - * Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - public function remove($options = '') - { - $sql = array(); - - return $this->_remove($sql, $options); - } - -} - diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_api_class.class.php b/htdocs/modulebuilder/oldskeletons/skeleton_api_class.class.php deleted file mode 100644 index a40b00af72c..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_api_class.class.php +++ /dev/null @@ -1,289 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - use Luracast\Restler\RestException; - - -/** - * API class for skeleton object - * - * @smart-auto-routing false - * @access protected - * @class DolibarrApiAccess {@requires user,external} - * - * - */ -class SkeletonApi extends DolibarrApi -{ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - static $FIELDS = array( - 'name' - ); - - /** - * @var Skeleton $skeleton {@type Skeleton} - */ - public $skeleton; - - /** - * Constructor - * - * @url GET skeleton/ - * - */ - function __construct() - { - global $db, $conf; - $this->db = $db; - $this->skeleton = new Skeleton($this->db); - } - - /** - * Get properties of a skeleton object - * - * Return an array with skeleton informations - * - * @param int $id ID of skeleton - * @return array|mixed data without useless information - * - * @url GET skeleton/{id} - * @throws RestException - */ - function get($id) - { - if(! DolibarrApiAccess::$user->rights->skeleton->read) { - throw new RestException(401); - } - - $result = $this->skeleton->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Skeleton not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('skeleton',$this->skeleton->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($this->skeleton); - } - - /** - * List skeletons - * - * Get a list of skeletons - * - * @param int $mode Use this param to filter list - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101') or (t.import_key:=:'20160101')" - * @return array Array of skeleton objects - * - * @url GET /skeletons/ - */ - function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') { - global $db, $conf; - - $obj_ret = array(); - - $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; - - // If the internal user must only see his customers, force searching by him - if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; - - $sql = "SELECT s.rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) - $sql.= " FROM ".MAIN_DB_PREFIX."skeleton as s"; - - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; - $sql.= " WHERE s.fk_stcomm = st.id"; - - // Example of use $mode - //if ($mode == 1) $sql.= " AND s.client IN (1, 3)"; - //if ($mode == 2) $sql.= " AND s.client IN (2, 3)"; - - $sql.= ' AND s.entity IN ('.getEntity('skeleton', 1).')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc"; - if ($socid) $sql.= " AND s.fk_soc = ".$socid; - if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale - // Insert sale filter - if ($search_sale > 0) - { - $sql .= " AND sc.fk_user = ".$search_sale; - } - if ($sqlfilters) - { - if (! DolibarrApi::_checkFilters($sqlfilters)) - { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql.= $db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) - { - $page = 0; - } - $offset = $limit * $page; - - $sql.= $db->plimit($limit + 1, $offset); - } - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - while ($i < $num) - { - $obj = $db->fetch_object($result); - $skeleton_static = new Skeleton($db); - if($skeleton_static->fetch($obj->rowid)) { - $obj_ret[] = parent::_cleanObjectDatas($skeleton_static); - } - $i++; - } - } - else { - throw new RestException(503, 'Error when retrieve skeleton list'); - } - if( ! count($obj_ret)) { - throw new RestException(404, 'No skeleton found'); - } - return $obj_ret; - } - - /** - * Create skeleton object - * - * @param array $request_data Request datas - * @return int ID of skeleton - * - * @url POST skeleton/ - */ - function post($request_data = NULL) - { - if(! DolibarrApiAccess::$user->rights->skeleton->create) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach($request_data as $field => $value) { - $this->skeleton->$field = $value; - } - if( ! $this->skeleton->create(DolibarrApiAccess::$user)) { - throw new RestException(500); - } - return $this->skeleton->id; - } - - /** - * Update skeleton - * - * @param int $id Id of skeleton to update - * @param array $request_data Datas - * @return int - * - * @url PUT skeleton/{id} - */ - function put($id, $request_data = NULL) - { - if(! DolibarrApiAccess::$user->rights->skeleton->create) { - throw new RestException(401); - } - - $result = $this->skeleton->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Skeleton not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('skeleton',$this->skeleton->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - foreach($request_data as $field => $value) { - $this->skeleton->$field = $value; - } - - if($this->skeleton->update($id, DolibarrApiAccess::$user)) - return $this->get ($id); - - return false; - } - - /** - * Delete skeleton - * - * @param int $id Skeleton ID - * @return array - * - * @url DELETE skeleton/{id} - */ - function delete($id) - { - if(! DolibarrApiAccess::$user->rights->skeleton->supprimer) { - throw new RestException(401); - } - $result = $this->skeleton->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Skeleton not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('skeleton',$this->skeleton->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if( !$this->skeleton->delete($id)) - { - throw new RestException(500); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Skeleton deleted' - ) - ); - - } - - /** - * Validate fields before create or update object - * - * @param array $data Data to validate - * @return array - * - * @throws RestException - */ - function _validate($data) - { - $skeleton = array(); - foreach (SkeletonApi::$FIELDS as $field) { - if (!isset($data[$field])) - throw new RestException(400, "$field field missing"); - $skeleton[$field] = $data[$field]; - } - return $skeleton; - } -} diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_card.php b/htdocs/modulebuilder/oldskeletons/skeleton_card.php deleted file mode 100644 index 49683af79c8..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_card.php +++ /dev/null @@ -1,604 +0,0 @@ - - * Copyright (C) ---Put here your own copyright and developer email--- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/skeleton_card.php - * \ingroup mymodule othermodule1 othermodule2 - * \brief This file is an example of a php page - * Put here some comments - */ - -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); -//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); -//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test -//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data -//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test -//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu -//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php -//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); -//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) - -// Change this following line to use the correct relative path (../, ../../, etc) -$res=0; -if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory -if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory -if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only -if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only -if (! $res) die("Include of main fails"); -// Change this following line to use the correct relative path from htdocs -include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); -dol_include_once('/mymodule/class/skeleton_class.class.php'); - -// Load traductions files requiredby by page -$langs->load("mymodule"); -$langs->load("other"); - -// Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$cancel = GETPOST('cancel'); -$backtopage = GETPOST('backtopage'); -$myparam = GETPOST('myparam','alpha'); - -$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); - -if (empty($action) && empty($id) && empty($ref)) $action='view'; - -// Protection if external user -if ($user->societe_id > 0) -{ - //accessforbidden(); -} -//$result = restrictedArea($user, 'mymodule', $id); - - -$object = new Skeleton_Class($db); -$extrafields = new ExtraFields($db); - -// fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - -// Load object -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals - -// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('skeleton')); - - - -/* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - */ - -$parameters=array(); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -if (empty($reshook)) -{ - if ($cancel) - { - if ($action != 'addlink') - { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); - header("Location: ".$urltogo); - exit; - } - if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref); - $action=''; - } - - // Action to add record - if ($action == 'add' && ! empty($user->rights->mymodule->create)) - { - if ($cancel) - { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); - header("Location: ".$urltogo); - exit; - } - - $error=0; - - /* object_prop_getpost_prop */ - $object->prop1=GETPOST("field1"); - $object->prop2=GETPOST("field2"); - - if (empty($object->ref)) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); - } - - if (! $error) - { - $result=$object->create($user); - if ($result > 0) - { - // Creation OK - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); - header("Location: ".$urltogo); - exit; - } - { - // Creation KO - if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - $action='create'; - } - } - else - { - $action='create'; - } - } - - // Action to update record - if ($action == 'update' && ! empty($user->rights->mymodule->create)) - { - $error=0; - - $object->prop1=GETPOST("field1"); - $object->prop2=GETPOST("field2"); - - if (empty($object->ref)) - { - $error++; - setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); - } - - if (! $error) - { - $result=$object->update($user); - if ($result > 0) - { - $action='view'; - } - else - { - // Creation KO - if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - $action='edit'; - } - } - else - { - $action='edit'; - } - } - - // Action to delete - if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete)) - { - $result=$object->delete($user); - if ($result > 0) - { - // Delete OK - setEventMessages("RecordDeleted", null, 'mesgs'); - header("Location: ".dol_buildpath('/mymodule/list.php',1)); - exit; - } - else - { - if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - } - } -} - - - - -/* - * VIEW - * - * Put here all code to build page - */ - -$form=new Form($db); - -llxHeader('','MyPageName',''); - - -// Put here content of your page - -// Example : Adding jquery code -print ''; - - -// Part to create -if ($action == 'create') -{ - print load_fiche_titre($langs->trans("NewMyModule")); - - print '
'; - print ''; - print ''; - - dol_fiche_head(); - - print ''."\n"; - // print ''; - // LIST_OF_TD_LABEL_FIELDS_CREATE - print '
'.$langs->trans("Label").'
'."\n"; - - dol_fiche_end(); - - print '
 
'; - - print '
'; -} - - - -// Part to edit record -if (($id || $ref) && $action == 'edit') -{ - print load_fiche_titre($langs->trans("MyModule")); - - print '
'; - print ''; - print ''; - print ''; - - dol_fiche_head(); - - print ''."\n"; - // print ''; - // LIST_OF_TD_LABEL_FIELDS_EDIT - print '
'.$langs->trans("Label").'
'; - - dol_fiche_end(); - - print '
'; - print '   '; - print '
'; - - print '
'; -} - - - -// Part to show record -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) -{ - $res = $object->fetch_optionals($object->id, $extralabels); - - $head = mymodule_prepare_head($object); - dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order'); - - $formconfirm = ''; - - // Confirmation to delete - if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); - } - - // Confirmation of action xxxx - if ($action == 'xxx') - { - $formquestion=array(); - /* - $formquestion = array( - // 'text' => $langs->trans("ConfirmClone"), - // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), - // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), - // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1))); - }*/ - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220); - } - - if (! $formconfirm) { - $parameters = array('lineid' => $lineid); - $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm.=$hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint; - } - - // Print form confirm - print $formconfirm; - - - - // Object card - // ------------------------------------------------------------ - - $linkback = '' . $langs->trans("BackToList") . ''; - - - $morehtmlref='
'; - /* - // Ref bis - $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->mymodule->creer) - { - if ($action != 'classify') - { - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.='
'; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } - */ - $morehtmlref.='
'; - - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - - print '
'; - print '
'; - print '
'; - print ''."\n"; - // print ''; - // LIST_OF_TD_LABEL_FIELDS_VIEW - - - // Other attributes - $cols = 2; - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - - print '
'.$langs->trans("Label").''.$object->label.'
'; - print '
'; - print '
'; - print '
'; - print '
'; - print ''; - - - - print '
'; - print '
'; - print '
'; - print '
'; - - print '

'; - - dol_fiche_end(); - - - // Buttons for actions - if ($action != 'presend' && $action != 'editline') { - print '
'."\n"; - $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - if (empty($reshook)) - { - if ($user->rights->mymodule->write) - { - print ''."\n"; - } - - if ($user->rights->mymodule->delete) - { - print ''."\n"; - } - } - print '
'."\n"; - } - - - // Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - if ($action != 'presend') - { - print '
'; - print ''; // ancre - // Documents - $comref = dol_sanitizeFileName($object->ref); - $relativepath = $comref . '/' . $comref . '.pdf'; - $filedir = $conf->mymodule->dir_output . '/' . $comref; - $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; - $genallowed = $user->rights->mymodule->creer; - $delallowed = $user->rights->mymodule->supprimer; - print $formfile->showdocuments('mymodule', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); - - - // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); - $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - - - print '
'; - - // List of actions on element - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; - $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'order', $socid); - - print '
'; - } - - - /* - * Action presend - */ - /* - if ($action == 'presend') - { - $object->fetch_projet(); - - $ref = dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); - $file = $fileparams['fullname']; - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) - $newlang = $_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - $newlang = $object->thirdparty->default_lang; - - if (!empty($newlang)) - { - $outputlangs = new Translate('', $conf); - $outputlangs->setDefaultLang($newlang); - $outputlangs->load('commercial'); - } - - // Build document if it not exists - if (! $file || ! is_readable($file)) { - $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) { - dol_print_error($db, $object->error, $object->errors); - exit(); - } - $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); - $file = $fileparams['fullname']; - } - - print '
'; - print '
'; - print '
'; - print load_fiche_titre($langs->trans('SendOrderByMail')); - - dol_fiche_head(''); - - // Cree l'objet formulaire mail - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); - $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user')); - - if($formmail->fromtype === 'user'){ - $formmail->fromid = $user->id; - - } - $formmail->trackid='ord'.$object->id; - if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set - { - include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id); - } - $formmail->withfrom = 1; - $liste = array(); - foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) - $liste [$key] = $value; - $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste; - $formmail->withtocc = $liste; - $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC; - if (empty($object->ref_client)) { - $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__'); - } else if (! empty($object->ref_client)) { - $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)'); - } - $formmail->withfile = 2; - $formmail->withbody = 1; - $formmail->withdeliveryreceipt = 1; - $formmail->withcancel = 1; - // Tableau des substitutions - $formmail->setSubstitFromObject($object); - $formmail->substit ['__ORDERREF__'] = $object->ref; - - $custcontact = ''; - $contactarr = array(); - $contactarr = $object->liste_contact(- 1, 'external'); - - if (is_array($contactarr) && count($contactarr) > 0) - { - foreach ($contactarr as $contact) - { - if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label - $contactstatic = new Contact($db); - $contactstatic->fetch($contact ['id']); - $custcontact = $contactstatic->getFullName($langs, 1); - } - } - - if (! empty($custcontact)) { - $formmail->substit['__CONTACTCIVNAME__'] = $custcontact; - } - } - - // Tableau des parametres complementaires - $formmail->param['action'] = 'send'; - $formmail->param['models'] = 'order_send'; - $formmail->param['models_id']=GETPOST('modelmailselected','int'); - $formmail->param['orderid'] = $object->id; - $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id; - - // Init list of files - if (GETPOST("mode") == 'init') { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file, basename($file), dol_mimetype($file)); - } - - // Show form - print $formmail->get_form(); - - dol_fiche_end(); - }*/ -} - - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_class.class.php b/htdocs/modulebuilder/oldskeletons/skeleton_class.class.php deleted file mode 100644 index 6805a697043..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_class.class.php +++ /dev/null @@ -1,606 +0,0 @@ - - * Copyright (C) 2014-2016 Juanjo Menent - * Copyright (C) 2015 Florian Henry - * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) ---Put here your own copyright and developer email--- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file modulebuilder/skeletons/skeleton_class.class.php - * \ingroup mymodule othermodule1 othermodule2 - * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) - */ - -// Put here all includes required by your class file -require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; - -/** - * Class Skeleton_Class - * - * Put here description of your class. - */ -class Skeleton_Class extends CommonObject -{ - /** - * @var string Id to identify managed object - */ - public $element = 'skeleton'; - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element = 'skeleton'; - /** - * @var array Array with all fields and their property - */ - public $picto = 'generic'; - /** - * @var array Array with all fields and their property - */ - public $fields; - - /** - * @var mixed Sample property 1 - */ - public $prop1; - /** - * @var mixed Sample property 2 - */ - public $prop2; - - //... - - protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - - public $table_element_line = 'skeletondet'; - public $class_element_line = 'SkeletonLine'; - public $fk_element = 'fk_skeleton'; - /** - * @var Skeleton_ClassLine[] Lines - */ - public $lines = array(); - - - - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - public function __construct(DoliDB $db) - { - $this->db = $db; - } - - /** - * Create object into database - * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK - */ - public function create(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - // Clean parameters - if (isset($this->prop1)) { - $this->prop1 = trim($this->prop1); - } - if (isset($this->prop2)) { - $this->prop2 = trim($this->prop2); - } - //... - - // Check parameters - // Put here code to add control on parameters values - - // Insert request - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - $sql .= ' field1,'; - $sql .= ' field2'; - //... - $sql .= ') VALUES ('; - $sql .= ' \'' . $this->prop1 . '\','; - $sql .= ' \'' . $this->prop2 . '\''; - //... - $sql .= ')'; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action to call a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); - //if ($result < 0) $error++; - //// End call triggers - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return $this->id; - } - } - - /** - * Load object in memory from the database - * - * @param int $id Id object - * @param string $ref Ref - * - * @return int <0 if KO, 0 if not found, >0 if OK - */ - public function fetch($id, $ref = null) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $sql = 'SELECT'; - $sql .= ' t.rowid,'; - $sql .= ' t.field1,'; - $sql .= ' t.field2'; - //... - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - $sql.= ' WHERE 1 = 1'; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND entity IN (" . getEntity("skeleton", 1) . ")"; - } - if (null !== $ref) { - $sql .= ' AND t.ref = ' . '\'' . $ref . '\''; - } else { - $sql .= ' AND t.rowid = ' . $id; - } - - $resql = $this->db->query($sql); - if ($resql) { - $numrows = $this->db->num_rows($resql); - if ($numrows) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->prop1 = $obj->field1; - $this->prop2 = $obj->field2; - //... - } - - // Retrieve all extrafields for invoice - // fetch optionals attributes and labels - /* - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields=new ExtraFields($this->db); - $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); - $this->fetch_optionals($this->id,$extralabels); - */ - - // $this->fetch_lines(); - - $this->db->free($resql); - - if ($numrows) { - return 1; - } else { - return 0; - } - } else { - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - - return - 1; - } - } - - /** - * Load object in memory from the database - * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit offset limit - * @param int $offset offset limit - * @param array $filter filter array - * @param string $filtermode filter mode (AND or OR) - * - * @return int <0 if KO, >0 if OK - */ - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $sql = 'SELECT'; - $sql .= ' t.rowid,'; - $sql .= ' t.field1,'; - $sql .= ' t.field2'; - //... - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; - - // Manage filter - $sqlwhere = array(); - if (count($filter) > 0) { - foreach ($filter as $key => $value) { - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; - } - } - $sql.= ' WHERE 1 = 1'; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND entity IN (" . getEntity("skeleton", 1) . ")"; - } - if (count($sqlwhere) > 0) { - $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); - } - if (!empty($sortfield)) { - $sql .= $this->db->order($sortfield,$sortorder); - } - if (!empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit, $offset); - } - - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - - while ($obj = $this->db->fetch_object($resql)) { - $line = new self($this->db); - - $line->id = $obj->rowid; - $line->prop1 = $obj->field1; - $line->prop2 = $obj->field2; - //... - } - $this->db->free($resql); - - return $num; - } else { - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - - return - 1; - } - } - - /** - * Update object into database - * - * @param User $user User that modifies - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - // Clean parameters - if (isset($this->prop1)) { - $this->prop1 = trim($this->prop1); - } - if (isset($this->prop2)) { - $this->prop2 = trim($this->prop2); - } - //... - - // Check parameters - // Put here code to add a control on parameters values - - // Update request - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= " field1=".(isset($this->field1)?"'".$this->db->escape($this->field1)."'":"null").","; - $sql .= " field2=".(isset($this->field2)?"'".$this->db->escape($this->field2)."'":"null").""; - //... - $sql .= ' WHERE rowid=' . $this->id; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - if (!$error && !$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return 1; - } - } - - /** - * Delete object in database - * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK - */ - public function delete(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - $this->db->begin(); - - if (!$error) { - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } - } - - // If you need to delete child tables to, you can insert them here - - if (!$error) { - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; - $sql .= ' WHERE rowid=' . $this->id; - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return 1; - } - } - - /** - * Load an object from its id and create a new one in database - * - * @param int $fromid Id of object to clone - * - * @return int New id of clone - */ - public function createFromClone($fromid) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - global $user; - $error = 0; - $object = new Skeleton_Class($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - // Reset object - $object->id = 0; - - // Clear fields - // ... - - // Create clone - $result = $object->create($user); - - // Other options - if ($result < 0) { - $error ++; - $this->errors = $object->errors; - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - // End - if (!$error) { - $this->db->commit(); - - return $object->id; - } else { - $this->db->rollback(); - - return - 1; - } - } - - /** - * Return a link to the object card (with optionaly the picto) - * - * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) - * @param string $option On what the link point to - * @param int $notooltip 1=Disable tooltip - * @param int $maxlen Max length of visible user name - * @param string $morecss Add more css on link - * @return string String with URL - */ - function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='') - { - global $db, $conf, $langs; - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - - $result = ''; - $companylink = ''; - - $label = '' . $langs->trans("MyModule") . ''; - $label.= '
'; - $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; - - $url = DOL_URL_ROOT.'/mymodule/'.$this->table_name.'_card.php?id='.$this->id; - - $linkclose=''; - if (empty($notooltip)) - { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label=$langs->trans("ShowProject"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; - } - else $linkclose = ($morecss?' class="'.$morecss.'"':''); - - $linkstart = ''; - $linkend=''; - - if ($withpicto) - { - $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend); - if ($withpicto != 2) $result.=' '; - } - $result.= $linkstart . $this->ref . $linkend; - return $result; - } - - /** - * Retourne le libelle du status d'un user (actif, inactif) - * - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @return string Label of status - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->status,$mode); - } - - /** - * Return the status - * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto - * @return string Label of status - */ - static function LibStatut($status,$mode=0) - { - global $langs; - - if ($mode == 0) - { - $prefix=''; - if ($status == 1) return $langs->trans('Enabled'); - if ($status == 0) return $langs->trans('Disabled'); - } - if ($mode == 1) - { - if ($status == 1) return $langs->trans('Enabled'); - if ($status == 0) return $langs->trans('Disabled'); - } - if ($mode == 2) - { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); - if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); - } - if ($mode == 3) - { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); - if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); - } - if ($mode == 4) - { - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); - if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); - } - if ($mode == 5) - { - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); - if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); - } - if ($mode == 6) - { - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); - if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); - } - } - - - /** - * Initialise object with example values - * Id must be 0 if object instance is a specimen - * - * @return void - */ - public function initAsSpecimen() - { - $this->id = 0; - $this->prop1 = 'prop1'; - $this->prop2 = 'prop2'; - } - -} - -/** - * Class Skeleton_ClassLine - */ -class Skeleton_ClassLine -{ - /** - * @var int ID - */ - public $id; - /** - * @var mixed Sample line property 1 - */ - public $prop1; - /** - * @var mixed Sample line property 2 - */ - public $prop2; -} diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_list.php b/htdocs/modulebuilder/oldskeletons/skeleton_list.php deleted file mode 100644 index 47aeda79fdc..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_list.php +++ /dev/null @@ -1,570 +0,0 @@ - - * Copyright (C) 2014-2016 Juanjo Menent - * Copyright (C) 2016 Jean-François Ferry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/skeleton_list.php - * \ingroup mymodule othermodule1 othermodule2 - * \brief This file is an example of a php page - * Put here some comments - */ - -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); -//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); -//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test -//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data -//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test -//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu -//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php -//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); -//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) - -// Change this following line to use the correct relative path (../, ../../, etc) -$res=0; -if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory -if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory -if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only -if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only -if (! $res) die("Include of main fails"); -// Change this following line to use the correct relative path from htdocs -require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -dol_include_once('/mymodule/class/skeleton_class.class.php'); - -// Load traductions files requiredby by page -$langs->load("mymodule"); -$langs->load("other"); - -$action=GETPOST('action','alpha'); -$massaction=GETPOST('massaction','alpha'); -$show_files=GETPOST('show_files','int'); -$confirm=GETPOST('confirm','alpha'); -$toselect = GETPOST('toselect', 'array'); - -$id = GETPOST('id','int'); -$backtopage = GETPOST('backtopage'); -$myparam = GETPOST('myparam','alpha'); - -$search_all=trim(GETPOST("sall")); -$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); -$search_myfield=GETPOST('search_myfield'); -$optioncss = GETPOST('optioncss','alpha'); - -// Load variable for pagination -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; -$sortfield = GETPOST('sortfield','alpha'); -$sortorder = GETPOST('sortorder','alpha'); -$page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } -$offset = $limit * $page; -$pageprev = $page - 1; -$pagenext = $page + 1; -if (! $sortfield) $sortfield="t.rowid"; // Set here default search field -if (! $sortorder) $sortorder="ASC"; - -// Protection if external user -$socid=0; -if ($user->societe_id > 0) -{ - $socid = $user->societe_id; - //accessforbidden(); -} - -// Initialize technical object to manage context to save list fields -$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'mymodulelist'; - -// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array -$hookmanager->initHooks(array('mymodulelist')); -$extrafields = new ExtraFields($db); - -// fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('mymodule'); -$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); - -// List of fields to search into when doing a "search in all" -$fieldstosearchall = array( - 't.ref'=>'Ref', - 't.note_public'=>'NotePublic', -); -if (empty($user->socid)) $fieldstosearchall["t.note_private"]="NotePrivate"; - -// Definition of fields for list -$arrayfields=array( - 't.field1'=>array('label'=>"Field1", 'checked'=>1), - 't.field2'=>array('label'=>"Field2", 'checked'=>1), - //'t.entity'=>array('label'=>"Entity", 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))), - 't.datec'=>array('label'=>"DateCreationShort", 'checked'=>0, 'position'=>500), - 't.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), - //'t.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), -); -// Extra fields -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) -{ - foreach($extrafields->attribute_label as $key => $val) - { - $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); - } -} - - -$object=new Skeleton_Class($db); - - - - -/* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - */ - -if (GETPOST('cancel')) { $action='list'; $massaction=''; } -if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } - -$parameters=array(); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -if (empty($reshook)) -{ - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - - // Purge search criteria - if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers - { - $search_field1=''; - $search_field2=''; - $search_date_creation=''; - $search_date_update=''; - $toselect=''; - $search_array_options=array(); - } - - // Mass actions - $objectclass='Skeleton'; - $objectlabel='Skeleton'; - $permtoread = $user->rights->skeleton->read; - $permtodelete = $user->rights->skeleton->delete; - $uploaddir = $conf->skeleton->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; -} - - - -/* - * VIEW - * - * Put here all code to build page - */ - -$now=dol_now(); - -$form=new Form($db); - -//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; -$help_url=''; -$title = $langs->trans('MyModuleListTitle'); - -// Put here content of your page - -// Example : Adding jquery code -print ''; - - -$sql = "SELECT"; -$sql.= " t.rowid,"; -$sql.= " t.field1,"; -$sql.= " t.field2"; -// Add fields from extrafields -foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); -// Add fields from hooks -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; -$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t"; -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mytable_extrafields as ef on (t.rowid = ef.fk_object)"; -$sql.= " WHERE 1 = 1"; -//$sql.= " WHERE u.entity IN (".getEntity('mytable',1).")"; -if ($search_field1) $sql.= natural_search("field1",$search_field1); -if ($search_field2) $sql.= natural_search("field2",$search_field2); -if ($sall) $sql.= natural_search(array_keys($fieldstosearchall), $sall); -// Add where from extra fields -foreach ($search_array_options as $key => $val) -{ - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - $typ=$extrafields->attribute_type[$tmpkey]; - $mode=0; - if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric - if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) - { - $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); - } -} -// Add where from hooks -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListWhere',$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 -$nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); -} - -$sql.= $db->plimit($limit+1, $offset); - -dol_syslog($script_file, LOG_DEBUG); -$resql=$db->query($sql); -if (! $resql) -{ - dol_print_error($db); - exit; -} - -$num = $db->num_rows($resql); - -// Direct jump if only one record found -if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) -{ - $obj = $db->fetch_object($resql); - $id = $obj->rowid; - header("Location: ".DOL_URL_ROOT.'/skeleton/card.php?id='.$id); - exit; -} - -llxHeader('', $title, $help_url); - -$arrayofselected=is_array($toselect)?$toselect:array(); - -$param=''; -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; -if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; -if ($search_field1 != '') $param.= '&search_field1='.urlencode($search_field1); -if ($search_field2 != '') $param.= '&search_field2='.urlencode($search_field2); -if ($optioncss != '') $param.='&optioncss='.$optioncss; -// Add $param from extra fields -foreach ($search_array_options as $key => $val) -{ - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); -} - -$arrayofmassactions = array( - 'presend'=>$langs->trans("SendByMail"), - 'builddoc'=>$langs->trans("PDFMerge"), -); -if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); -if ($massaction == 'presend') $arrayofmassactions=array(); -$massactionbutton=$form->selectMassAction('', $arrayofmassactions); - -print '
'; -if ($optioncss != '') print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; - -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit); - -if ($sall) -{ - foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); -} - -$moreforfilter = ''; -$moreforfilter.='
'; -$moreforfilter.= $langs->trans('MyFilter') . ': '; -$moreforfilter.= '
'; - -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; - -if (! empty($moreforfilter)) -{ - print '
'; - print $moreforfilter; - print '
'; -} - -$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; -$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - -print '
'; -print ''."\n"; - -// Fields title -print ''; -// LIST_OF_TD_TITLE_FIELDS -//if (! empty($arrayfields['t.field1']['checked'])) print_liste_field_titre($arrayfields['t.field1']['label'],$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder); -//if (! empty($arrayfields['t.field2']['checked'])) print_liste_field_titre($arrayfields['t.field2']['label'],$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder); -// Extra fields -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) -{ - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) - { - $align=$extrafields->getAlignFlag($key); - $sortonfield = "ef.".$key; - if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); - } - } -} -// Hook fields -$parameters=array('arrayfields'=>$arrayfields); -$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -//if (! empty($arrayfields['t.status']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder); -print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); -print ''."\n"; - -// Fields title search -print ''; -// LIST_OF_TD_TITLE_SEARCH -//if (! empty($arrayfields['t.field1']['checked'])) print ''; -//if (! empty($arrayfields['t.field2']['checked'])) print ''; -// Extra fields -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) -{ - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) - { - $align=$extrafields->getAlignFlag($key); - $typeofextrafield=$extrafields->attribute_type[$key]; - print ''; - } - } -} -// Fields from hook -$parameters=array('arrayfields'=>$arrayfields); -$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) -{ - // Date creation - print ''; -} -if (! empty($arrayfields['t.tms']['checked'])) -{ - // Date modification - print ''; -} -/*if (! empty($arrayfields['u.statut']['checked'])) -{ - // Status - print ''; -}*/ -// Action column -print ''; -print ''."\n"; - - -// Detect if we need a fetch on each output line -$needToFetchEachLine=0; -foreach ($extrafields->attribute_computed as $key => $val) -{ - if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object -} - - -$i=0; -$totalarray=array(); -while ($i < min($num, $limit)) -{ - $obj = $db->fetch_object($resql); - if ($obj) - { - // Show here line of result - print ''; - // LIST_OF_TD_FIELDS_LIST - /* - if (! empty($arrayfields['t.field1']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['t.field2']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - }*/ - // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) - { - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) - { - print 'getAlignFlag($key); - if ($align) print ' align="'.$align.'"'; - print '>'; - $tmpkey='options_'.$key; - print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); - print ''; - if (! $i) $totalarray['nbfield']++; - } - } - } - // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); - $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - // Date creation - if (! empty($arrayfields['t.datec']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - // Date modification - if (! empty($arrayfields['t.tms']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - // Status - /* - if (! empty($arrayfields['u.statut']['checked'])) - { - $userstatic->statut=$obj->statut; - print ''; - }*/ - - // Action column - print ''; - if (! $i) $totalarray['nbfield']++; - - print ''; - } - $i++; -} - -// Show total line -if (isset($totalarray['totalhtfield'])) -{ - print ''; - $i=0; - while ($i < $totalarray['nbfield']) - { - $i++; - if ($i == 1) - { - if ($num < $limit) print ''; - else print ''; - } - elseif ($totalarray['totalhtfield'] == $i) print ''; - elseif ($totalarray['totalvatfield'] == $i) print ''; - elseif ($totalarray['totalttcfield'] == $i) print ''; - else print ''; - } - print ''; -} - -$db->free($resql); - -$parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); -$reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; - -print '
'; - if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key])) - { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - $searchclass=''; - if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; - if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; - print ''; - } - print ''; - print ''; - print ''; - print $form->selectarray('search_statut', array('-1'=>'','0'=>$langs->trans('Disabled'),'1'=>$langs->trans('Enabled')),$search_statut); - print ''; -$searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); -print $searchpicto; -print '
'.$obj->field1.''.$obj->field2.''; - print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); - print ''; - print dol_print_date($db->jdate($obj->date_update), 'dayhour'); - print ''.$userstatic->getLibStatut(3).''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { - $selected=0; - if (in_array($obj->rowid, $arrayofselected)) $selected=1; - print ''; - } - print '
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.price($totalarray['totalht']).''.price($totalarray['totalvat']).''.price($totalarray['totalttc']).'
'."\n"; -print '
'."\n"; - -print '
'."\n"; - - -if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) -{ - // Show list of available documents - $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource.=str_replace('&','&',$param); - - $filedir=$diroutputmassaction; - $genallowed=$user->rights->facture->lire; - $delallowed=$user->rights->facture->lire; - - print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); -} -else -{ - print '
'.$langs->trans("ShowTempMassFilesArea").''; -} - - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_script.php b/htdocs/modulebuilder/oldskeletons/skeleton_script.php deleted file mode 100644 index 5eb1565d4a3..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_script.php +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env php - - * Copyright (C) ---Put here your own copyright and developer email--- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file dev/skeletons/skeleton_script.php - * \ingroup mymodule - * \brief This file is an example for a command line script - * Put here some comments - */ - -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit(-1); -} - -// Global variables -$version='1.0'; -$error=0; - - -// -------------------- START OF YOUR CODE HERE -------------------- -@set_time_limit(0); // No timeout for this script -define('EVEN_IF_ONLY_LOGIN_ALLOWED',1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". - -// Include and load Dolibarr environment variables -require_once($path."../../htdocs/master.inc.php"); -// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file). -// $user is created but empty. - -//$langs->setDefaultLang('en_US'); // To change default language of $langs -$langs->load("main"); // To load language file for default language - -// Load user and its permissions -$result=$user->fetch('','admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('',$user->error); exit; } -$user->getrights(); - - -print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; -if (! isset($argv[1])) { // Check parameters - print "Usage: ".$script_file." param1 param2 ...\n"; - exit(-1); -} -print '--- start'."\n"; -print 'Argument 1='.$argv[1]."\n"; -print 'Argument 2='.$argv[2]."\n"; - - -// Start of transaction -$db->begin(); - - -// Examples for manipulating class skeleton_class -require_once(DOL_DOCUMENT_ROOT."/../dev/skeletons/skeleton_class.class.php"); -$myobject=new Skeleton_Class($db); - -// Example for inserting creating object in database -/* -dol_syslog($script_file." CREATE", LOG_DEBUG); -$myobject->prop1='value_prop1'; -$myobject->prop2='value_prop2'; -$id=$myobject->create($user); -if ($id < 0) { $error++; dol_print_error($db,$myobject->error); } -else print "Object created with id=".$id."\n"; -*/ - -// Example for reading object from database -/* -dol_syslog($script_file." FETCH", LOG_DEBUG); -$result=$myobject->fetch($id); -if ($result < 0) { $error; dol_print_error($db,$myobject->error); } -else print "Object with id=".$id." loaded\n"; -*/ - -// Example for updating object in database ($myobject must have been loaded by a fetch before) -/* -dol_syslog($script_file." UPDATE", LOG_DEBUG); -$myobject->prop1='newvalue_prop1'; -$myobject->prop2='newvalue_prop2'; -$result=$myobject->update($user); -if ($result < 0) { $error++; dol_print_error($db,$myobject->error); } -else print "Object with id ".$myobject->id." updated\n"; -*/ - -// Example for deleting object in database ($myobject must have been loaded by a fetch before) -/* -dol_syslog($script_file." DELETE", LOG_DEBUG); -$result=$myobject->delete($user); -if ($result < 0) { $error++; dol_print_error($db,$myobject->error); } -else print "Object with id ".$myobject->id." deleted\n"; -*/ - - -// An example of a direct SQL read without using the fetch method -/* -$sql = "SELECT field1, field2"; -$sql.= " FROM ".MAIN_DB_PREFIX."skeleton"; -$sql.= " WHERE field3 = 'xxx'"; -$sql.= " ORDER BY field1 ASC"; - -dol_syslog($script_file, LOG_DEBUG); -$resql=$db->query($sql); -if ($resql) -{ - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj) - { - // You can use here results - print $obj->field1; - print $obj->field2; - } - $i++; - } - } -} -else -{ - $error++; - dol_print_error($db); -} -*/ - - -// -------------------- END OF YOUR CODE -------------------- - -if (! $error) -{ - $db->commit(); - print '--- end ok'."\n"; -} -else -{ - print '--- end error code='.$error."\n"; - $db->rollback(); -} - -$db->close(); // Close $db database opened handler - -exit($error); diff --git a/htdocs/modulebuilder/oldskeletons/skeleton_webservice_server.php b/htdocs/modulebuilder/oldskeletons/skeleton_webservice_server.php deleted file mode 100644 index 54a050ff9da..00000000000 --- a/htdocs/modulebuilder/oldskeletons/skeleton_webservice_server.php +++ /dev/null @@ -1,272 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/webservices/server_skeleton.php - * \brief File that is entry point to call Dolibarr WebServices - * \version $Id: server_skeleton.php,v 1.7 2010/12/19 11:49:37 eldy Exp $ - */ - -// This is to make Dolibarr working with Plesk -set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); - -require_once("../master.inc.php"); -require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP -require_once(DOL_DOCUMENT_ROOT."/core/lib/ws.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/skeleton/class/skeleton.class.php"); - - -dol_syslog("Call Skeleton webservices interfaces"); - -// Enable and test if module web services is enabled -if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) -{ - $langs->load("admin"); - dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled"); - print $langs->trans("WarningModuleNotActive",'WebServices').'.

'; - print $langs->trans("ToActivateModule"); - exit; -} - -// Create the soap Object -$server = new nusoap_server(); -$server->soap_defencoding='UTF-8'; -$server->decode_utf8=false; -$ns='http://www.dolibarr.org/ns/'; -$server->configureWSDL('WebServicesDolibarrSkeleton',$ns); -$server->wsdl->schemaTargetNamespace=$ns; - - -// Define WSDL Authentication object -$server->wsdl->addComplexType( - 'authentication', - 'complexType', - 'struct', - 'all', - '', - array( - 'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'), - 'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'), - 'login' => array('name'=>'login','type'=>'xsd:string'), - 'password' => array('name'=>'password','type'=>'xsd:string'), - 'entity' => array('name'=>'entity','type'=>'xsd:string'), - ) -); - -// Define WSDL Return object -$server->wsdl->addComplexType( - 'result', - 'complexType', - 'struct', - 'all', - '', - array( - 'result_code' => array('name'=>'result_code','type'=>'xsd:string'), - 'result_label' => array('name'=>'result_label','type'=>'xsd:string'), - ) -); - -// Define other specific objects -$server->wsdl->addComplexType( - 'skeleton', - 'complexType', - 'struct', - 'all', - '', - array( - 'prop1'=>'xxx', - 'prop2'=>'xxx', - //... - ) -); - - - -// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped -// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model. -// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ -$styledoc='rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages) -$styleuse='encoded'; // encoded/literal/literal wrapped -// Better choice is document/literal wrapped but literal wrapped not supported by nusoap. - - -// Register WSDL -$server->register( - 'getSkeleton', - // Entry values - array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), - // Exit values - array('result'=>'tns:result','skeleton'=>'tns:skeleton'), - $ns, - $ns.'#getSkeleton', - $styledoc, - $styleuse, - 'WS to get skeleton' -); - -// Register WSDL -$server->register( - 'createSkeleton', - // Entry values - array('authentication'=>'tns:authentication','skeleton'=>'tns:skeleton'), - // Exit values - array('result'=>'tns:result','id'=>'xsd:string'), - $ns, - $ns.'#createSkeleton', - $styledoc, - $styleuse, - 'WS to create a skeleton' -); - - - - -/** - * Get Skeleton - * - * @param array $authentication Array of authentication information - * @param int $id Id of object - * @param string $ref Ref of object - * @param string $ref_ext Ref external of object - * @return mixed - */ -function getSkeleton($authentication,$id,$ref='',$ref_ext='') -{ - global $db,$conf,$langs; - - dol_syslog("Function: getSkeleton login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); - - if ($authentication['entity']) $conf->entity=$authentication['entity']; - - // Init and check authentication - $objectresp=array(); - $errorcode='';$errorlabel=''; - $error=0; - $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); - // Check parameters - if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) - { - $error++; - $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; - } - - if (! $error) - { - $fuser->getrights(); - - if ($fuser->rights->skeleton->read) - { - $skeleton=new Skeleton($db); - $result=$skeleton->fetch($id,$ref,$ref_ext); - if ($result > 0) - { - // Create - $objectresp = array( - 'result'=>array('result_code'=>'OK', 'result_label'=>''), - 'skeleton'=>array( - 'prop1'=>$skeleton->prop1, - 'prop2'=>$skeleton->prop2, - //... - ) - ); - } - else - { - $error++; - $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; - } - } - else - { - $error++; - $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; - } - } - - if ($error) - { - $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); - } - - return $objectresp; -} - - -/** - * Create Skeleton - * - * @param array $authentication Array of authentication information - * @param Skeleton $skeleton $skeleton - * @return array Array result - */ -function createSkeleton($authentication,$skeleton) -{ - global $db,$conf,$langs; - - $now=dol_now(); - - dol_syslog("Function: createSkeleton login=".$authentication['login']); - - if ($authentication['entity']) $conf->entity=$authentication['entity']; - - // Init and check authentication - $objectresp=array(); - $errorcode='';$errorlabel=''; - $error=0; - $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); - // Check parameters - - - if (! $error) - { - $newobject=new Skeleton($db); - $newobject->prop1=$skeleton->prop1; - $newobject->prop2=$skeleton->prop2; - //... - - $db->begin(); - - $result=$newobject->create($fuser); - if ($result <= 0) - { - $error++; - } - - if (! $error) - { - $db->commit(); - $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref); - } - else - { - $db->rollback(); - $error++; - $errorcode='KO'; - $errorlabel=$newobject->error; - } - } - - if ($error) - { - $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); - } - - return $objectresp; -} - -// Return the results. -$server->service(file_get_contents("php://input")); diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 79e17749991..3cc9147a001 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -320,6 +320,7 @@ class StockMovements extends DolibarrApi unset($object->user); unset($object->fk_project); unset($object->project); + unset($object->canvas); //unset($object->eatby); Filled correctly in read mode //unset($object->sellby); Filled correctly in read mode From c39ca4cff8824a7181b9354a40f5ff3c02135c6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 00:20:35 +0200 Subject: [PATCH 20/66] NEW Introduce function dol_compress_dir --- htdocs/core/lib/files.lib.php | 85 ++++++++++++++++++++++++++++++++++ htdocs/langs/en_US/errors.lang | 3 +- htdocs/langs/en_US/other.lang | 1 + htdocs/modulebuilder/index.php | 59 ++++++++++++++++++++++- 4 files changed, 146 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index e52f8bf98ec..95fca68aa5d 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1685,6 +1685,91 @@ function dol_uncompress($inputfile,$outputdir) } +/** + * Compress a directory and subdirectories into a package file. + * + * @param string $inputdir Source dir name + * @param string $outputfile Target file name + * @param string $mode 'zip' + * @return int <0 if KO, >0 if OK + */ +function dol_compress_dir($inputdir, $outputfile, $mode="zip") +{ + $foundhandler=0; + + dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode); + try + { + if ($mode == 'gz') { $foundhandler=0; } + elseif ($mode == 'bz') { $foundhandler=0; } + elseif ($mode == 'zip') + { + /*if (defined('ODTPHP_PATHTOPCLZIP')) + { + $foundhandler=0; // TODO implement this + + include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; + $archive = new PclZip($outputfile); + $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile)); + //$archive->add($inputfile); + return 1; + } + else*/ + if (class_exists('ZipArchive')) + { + $foundhandler=1; + + // Initialize archive object + $zip = new ZipArchive(); + $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE); + + // Create recursive directory iterator + /** @var SplFileInfo[] $files */ + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($inputdir), + RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($files as $name => $file) + { + // Skip directories (they would be added automatically) + if (!$file->isDir()) + { + // Get real and relative path for current file + $filePath = $file->getRealPath(); + $relativePath = substr($filePath, strlen($inputdir) + 1); + + // Add current file to archive + $zip->addFile($filePath, $relativePath); + } + } + + // Zip archive will be created only after closing object + $zip->close(); + + return 1; + } + } + + if (! $foundhandler) + { + dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); + return -2; + } + } + catch (Exception $e) + { + global $langs, $errormsg; + $langs->load("errors"); + dol_syslog("Failed to open file ".$outputfile, LOG_ERR); + dol_syslog($e->getMessage(), LOG_ERR); + $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); + return -1; + } +} + + + /** * Return file(s) into a directory (by default most recent) * diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index aea5ad68113..740397a5044 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -19,6 +19,7 @@ ErrorFailToRenameDir=Failed to rename directory '%s' into '%s'. ErrorFailToCreateDir=Failed to create directory '%s'. ErrorFailToDeleteDir=Failed to delete directory '%s'. ErrorFailToMakeReplacementInto=Failed to make replacement into file '%s'. +ErrorFailToGenerateFile=Failed to generate file '%s'. ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type. ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only. ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different. @@ -115,7 +116,7 @@ ErrorQtyForCustomerInvoiceCantBeNegative=Quantity for line into customer invoice ErrorWebServerUserHasNotPermission=User account %s used to execute web server has no permission for that ErrorNoActivatedBarcode=No barcode type activated ErrUnzipFails=Failed to unzip %s with ZipArchive -ErrNoZipEngine=No engine to unzip %s file in this PHP +ErrNoZipEngine=No engine to zip/unzip %s file in this PHP ErrorFileMustBeADolibarrPackage=The file %s must be a Dolibarr zip package ErrorModuleFileRequired=You must select a Dolibarr module package file ErrorPhpCurlNotInstalled=The PHP CURL is not installed, this is essential to talk with Paypal diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 280a1666b02..a14bfffffb6 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -16,6 +16,7 @@ PreviousMonthOfInvoice=Previous month (number 1-12) of invoice date TextPreviousMonthOfInvoice=Previous month (text) of invoice date NextMonthOfInvoice=Following month (number 1-12) of invoice date TextNextMonthOfInvoice=Following month (text) of invoice date +ZipFileGeneratedInto=Zip file generated into %s. YearOfInvoice=Year of invoice date PreviousYearOfInvoice=Previous year of invoice date diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index e11ff31a303..b3b2c8dac77 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -115,9 +115,60 @@ if ($dircustom && $action == 'initmodule' && $modulename) if ($dircustom && $action == 'generatepackage') { - $dir = $dircustom.'/'.$modulename; + $modulelowercase=strtolower($module); + // Dir for module + $dir = $dircustom.'/'.$modulelowercase; + // Zip file to build + $FILENAMEZIP=''; + + // Load module + dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); + $class='mod'.$module; + if (class_exists($class)) + { + try { + $moduleobj = new $class($db); + } + catch(Exception $e) + { + $error++; + dol_print_error($e->getMessage()); + } + } + else + { + $error++; + $langs->load("errors"); + dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); + exit; + } + + $arrayversion=explode('.',$moduleobj->version,3); + if (count($arrayversion)) + { + $FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip"; + $outputfile = $conf->admin->dir_temp.'/'.$FILENAMEZIP; + + $result = dol_compress_dir($dir, $outputfile, 'zip'); + if ($result > 0) + { + setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfile), null); + } + else + { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfile), null, 'errors'); + } + } + else + { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors'); + } } @@ -434,6 +485,12 @@ elseif (! empty($module)) if ($tab == 'buildpackage') { + if (! class_exists('ZipArchive') && ! defined('ODTPHP_PATHTOPCLZIP')) + { + print img_warning().' '.$langs->trans("ErrNoZipEngine"); + print '
'; + } + print '
'; print ''; print ''; From 21183f91a3f0c9eb2613ad74a3b5e1e6929e2a8e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 31 May 2017 05:27:39 +0200 Subject: [PATCH 21/66] FIX : Vat payment - Sql error / Add information in tooltip / Correct writting in general ledger --- htdocs/accountancy/journal/bankjournal.php | 30 +++++++++++++++--- htdocs/compta/tva/reglement.php | 36 ++++++++++++---------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index ea98d678671..7bb1ef20923 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -284,7 +284,8 @@ if ($result) { $paymentvatstatic->id = $links[$key]['url_id']; $paymentvatstatic->ref = $links[$key]['url_id']; $paymentvatstatic->label = $links[$key]['label']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentVat"); + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2); + $tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id; $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount; } else if ($links[$key]['type'] == 'payment_salary') { $paymentsalstatic->id = $links[$key]['url_id']; @@ -415,8 +416,11 @@ if (! $error && $action == 'writebookkeeping') { $objmid = $db->fetch_object($resultmid); $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport } - } - + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->code_tiers = ''; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat payment + } + $result = $bookkeeping->create($user); if ($result < 0) { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists @@ -489,6 +493,10 @@ if (! $error && $action == 'writebookkeeping') { } $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; $bookkeeping->numero_compte = $k; + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->code_tiers = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat } else if ($tabtype[$key] == 'banktransfert') { $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; @@ -724,6 +732,7 @@ if (empty($action) || $action == 'view') { $invoicestatic = new Facture($db); $invoicesupplierstatic = new FactureFournisseur($db); $expensereportstatic = new ExpenseReport($db); + $vatstatic = new Tva($db); llxHeader('', $langs->trans("FinanceJournal")); @@ -850,7 +859,20 @@ if (empty($action) || $action == 'view') { } else dol_print_error($db); } - + elseif ($tabtype[$key] == 'payment_vat') + { + $sqlmid = 'SELECT v.rowid as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "tva as v"; + $sqlmid .= " WHERE v.rowid=" . $val["paymentvatid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $vatstatic->fetch($objmid->id); + $ref=$langs->trans("PaymentVat").' '.$vatstatic->getNomUrl(1); + } + else dol_print_error($db); + } /*$invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 076978a86fb..8b4d3299f9c 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; 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.'/accountancy/class/accountingjournal.class.php'; $langs->load("compta"); $langs->load("bills"); @@ -94,10 +95,10 @@ llxHeader('', $langs->trans("VATPayments")); $form = new Form($db); $formother=new FormOther($db); $tva_static = new Tva($db); -$accountstatic = new Account($db); +$bankstatic = new Account($db); $sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,"; -$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.accountancy_journal, ba.label as blabel"; +$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; @@ -227,19 +228,22 @@ if ($result) { print ''; if ($obj->fk_bank > 0) - { - //$accountstatic->fetch($obj->fk_bank); - $accountstatic->id=$obj->bid; - $accountstatic->ref=$obj->bref; - $accountstatic->number=$obj->bnumber; - $accountstatic->accountancy_number=$obj->account_number; - $accountstatic->accountancy_journal=$obj->accountancy_journal; - $accountstatic->label=$obj->blabel; - print $accountstatic->getNomUrl(1); - } - else print ' '; - print ''; - } + { + $bankstatic->id=$obj->bid; + $bankstatic->ref=$obj->bref; + $bankstatic->number=$obj->bnumber; + $bankstatic->account_number=$obj->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($obj->fk_accountancy_journal); + $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1); + + $bankstatic->label=$obj->blabel; + print $bankstatic->getNomUrl(1); + } + else print ' '; + print ''; + } // Amount $total = $total + $obj->amount; print "".price($obj->amount).""; From 292571688b54b4d327dc7ad7bac9e1e3fae0b445 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 10:43:01 +0200 Subject: [PATCH 22/66] Fix error message not reported --- htdocs/core/class/dolgraph.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 4fb973160d4..691cb8b986d 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -24,7 +24,12 @@ /** - * Parent class of graph classes + * Class to build graphs. + * Usage is: + * $dolgraph=new DolGraph(); + * $dolgraph->SetData($data); + * $dolgraph->draw('idofgraph'); + * print $dolgraph->show(); */ class DolGraph { @@ -780,9 +785,9 @@ class DolGraph /** * Build a graph using JFlot library. Input when calling this method should be: - * $this->data = array(array( 0=>'labelxA', 1=>yA), array('labelxB',yB)); or + * $this->data = array(array(0=>'labelxA',1=>yA), array('labelxB',yB)); + * $this->data = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn)); // or when there is n series to show for each x * $this->data = array(array('label'=>'labelxA','data'=>yA), array('labelxB',yB)); // TODO Syntax not supported. Removed when dol_print_graph_removed - * $this->data = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn)); // when there is n series to show for each x * $this->legend= array("Val1",...,"Valn"); // list of n series name * $this->type = array('bars',...'lines'); or array('pie') * $this->mode = 'depth' ??? @@ -808,7 +813,7 @@ class DolGraph $legends=array(); $nblot=count($this->data[0])-1; // -1 to remove legend - if ($nblot < 0) dol_print_error('Bad value for property ->data. Must be set by mydolgraph->SetData before callinf mydolgrapgh->draw'); + if ($nblot < 0) dol_print_error('', 'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw'); $firstlot=0; // Works with line but not with bars //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x From 145cb628cd12d51d6b98e8e88a05d11ce408249f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 11:11:25 +0200 Subject: [PATCH 23/66] FIX dol_string_nohtmltag make 2 passes to clean html into html attributes. --- htdocs/core/lib/functions.lib.php | 7 ++++++- test/phpunit/FunctionsLibTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 041235f40f6..4a9d25aefde 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4704,8 +4704,13 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8') $pattern = "/<[^<>]+>/"; $StringHtml = preg_replace('/]*>/', "\n", $StringHtml); $temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto); - $temp = preg_replace($pattern,"",$temp); + // Exemple of $temp: 0000-021 + $temp = preg_replace($pattern,"",$temp); // pass 1 + // $temp after pass 1: 0000-021 + $temp = preg_replace($pattern,"",$temp); // pass 2 + // $temp after pass 2: 0000-021 + // Supprime aussi les retours if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp); diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 8c57e8a178a..4e98ce0b3bc 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -377,6 +377,14 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $after=dol_string_nohtmltag($text,1); $this->assertEquals("A string Another string",$after,"test5"); + $text='ABC'; + $after=dol_string_nohtmltag($text,1); + $this->assertEquals("ABC",$after,"test6"); + + $text='DEF'; + $after=dol_string_nohtmltag($text,1); + $this->assertEquals("DEF",$after,"test7"); + return true; } From 10ac53077e24241e9919d21c2e98650a6eb343ba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 11:51:38 +0200 Subject: [PATCH 24/66] Code comment --- htdocs/core/class/dolgraph.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 691cb8b986d..4fad0149a5b 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -27,7 +27,13 @@ * Class to build graphs. * Usage is: * $dolgraph=new DolGraph(); + * $dolgraph->SetTitle($langs->transnoentities('Tracking_Projects_Pourcent').'
'.$langs->transnoentities('Tracking_IndicatorDefGraph').'%'); + * $dolgraph->SetMaxValue(50); * $dolgraph->SetData($data); + * $dolgraph->setShowLegend(1); + * $dolgraph->setShowPercent(1); + * $dolgraph->SetType(array('pie')); + * $dolgraph->setWidth('100%'); * $dolgraph->draw('idofgraph'); * print $dolgraph->show(); */ @@ -803,7 +809,7 @@ class DolGraph { global $artichow_defaultfont; - dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)); + dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)." this->MaxValue=".$this->MaxValue); if (empty($this->width) && empty($this->height)) { From b2779e2c08e176e639aab478c92e1a2a84016634 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 12:05:53 +0200 Subject: [PATCH 25/66] Typo --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c297c5d8bce..57824562787 100644 --- a/ChangeLog +++ b/ChangeLog @@ -215,7 +215,7 @@ Dolibarr better: - Method commande->set_availability(user, availability_id) removed from commande class, use method commande->availability(availability_id, notrigger). Dolibarr 5.0 was frozen before PHP 7.1 was released. Unit tests are successful on PHP 7.1 but we don't have enough -feedback to confirm all application is compatible. Current officiel supported PHP versions are PHP 5.3 to 7.0. +feedback to confirm whole application is compatible. Current officiel supported PHP versions are PHP 5.3 to 7.0. ***** ChangeLog for 4.0.6 to 4.0.5 ***** From e41541ab79150449ba1db6f52497beb7ac13db88 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 12:47:21 +0200 Subject: [PATCH 26/66] Enhance detection of changelog not updated --- build/makepack-dolibarr.pl | 74 +++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index 9c8f8ea601e..fdd14fcf5a2 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -14,7 +14,7 @@ #---------------------------------------------------------------------------- use Cwd; - +use Term::ANSIColor; # Change this to defined target for option 98 and 99 $PROJECT="dolibarr"; @@ -313,20 +313,6 @@ foreach my $target (sort keys %CHOOSEDTARGET) { print "\n"; -# Build xml check file -#----------------------- -if ($CHOOSEDTARGET{'-CHKSUM'}) -{ - print 'Create xml check file with md5 checksum with command php '.$SOURCE.'/build/generate_filecheck_xml.php release='.$MAJOR.'.'.$MINOR.'.'.$BUILD."\n"; - $ret=`php $SOURCE/build/generate_filelist_xml.php release=$MAJOR.$MINOR.$BUILD`; - print $ret."\n"; - # Copy to final dir - $NEWDESTI=$DESTI; - print "Copy \"$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml\" to $NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml\n"; - use File::Copy qw(copy); - copy "$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml", "$NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"; -} - #print join(',',sort keys %CHOOSEDTARGET)."\n"; @@ -335,7 +321,10 @@ if ($CHOOSEDTARGET{'-CHKSUM'}) $nboftargetok=0; $nboftargetneedbuildroot=0; $nbofpublishneedtag=0; +$nbofpublishneedchangelog=0; + foreach my $target (sort keys %CHOOSEDTARGET) { + if ($target eq '-CHKSUM') { $nbofpublishneedchangelog++; } if ($CHOOSEDTARGET{$target} < 0) { next; } if ($target ne 'EXE' && $target ne 'EXEDOLIWAMP' && $target ne '-CHKSUM') { @@ -345,34 +334,31 @@ foreach my $target (sort keys %CHOOSEDTARGET) { } foreach my $target (sort keys %CHOOSEDPUBLISH) { if ($CHOOSEDPUBLISH{$target} < 0) { next; } - if ($target eq 'ASSO') { $nbofpublishneedtag++; } - if ($target eq 'SF') { $nbofpublishneedtag++; } + if ($target eq 'ASSO') { $nbofpublishneedchangelog++; $nbofpublishneedtag++; } + if ($target eq 'SF') { $nbofpublishneedchangelog++; $nbofpublishneedtag++; } $nboftargetok++; } + if ($nboftargetok) { - # Update GIT tag if required - #--------------------------- - if ($nbofpublishneedtag) + # Check Changelog + #---------------- + if ($nbofpublishneedchangelog) { - print "Go to directory $SOURCE\n"; - $olddir=getcwd(); - chdir("$SOURCE"); - # Test that the ChangeLog is ok $TMPBUILDTOCHECKCHANGELOG=$BUILD; $TMPBUILDTOCHECKCHANGELOG =~ s/\-rc\d*//; $TMPBUILDTOCHECKCHANGELOG =~ s/\-beta\d*//; - print "Check if ChangeLog is ok for version $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG\n"; + print "\nCheck if ChangeLog is ok for version $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG\n"; $ret=`grep "ChangeLog for $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG" "$SOURCE/ChangeLog" 2>&1`; if (! $ret) { - print "Error: The ChangeLogFile was not updated. Run the following command before building package for $MAJOR.$MINOR.$BUILD:\n"; + print color("yellow"), "Error: The ChangeLogFile was not updated. Run the following command before building package for $MAJOR.$MINOR.$BUILD:\n", color('reset'); } else { - print "ChangeLog for $MAJOR.$MINOR\.$BUILD was found into '$SOURCE/ChangeLog. But you can regenerate it with commande:'\n"; + print "ChangeLog for $MAJOR.$MINOR\.$BUILD was found into '$SOURCE/ChangeLog. But you can regenerate it with command:'\n"; } if (! $BUILD || $BUILD eq '0-rc') # For a major version { @@ -385,9 +371,39 @@ if ($nboftargetok) { print "\n"; if (! $ret) { - exit; + print "\nPress F to force and continue anyway (or other key to stop)... "; + my $WAITKEY=; + chomp($WAITKEY); + if ($WAITKEY ne 'F') + { + print "Canceled.\n"; + exit; + } } - + } + + # Build xml check file + #----------------------- + if ($CHOOSEDTARGET{'-CHKSUM'}) + { + print 'Create xml check file with md5 checksum with command php '.$SOURCE.'/build/generate_filecheck_xml.php release='.$MAJOR.'.'.$MINOR.'.'.$BUILD."\n"; + $ret=`php $SOURCE/build/generate_filelist_xml.php release=$MAJOR.$MINOR.$BUILD`; + print $ret."\n"; + # Copy to final dir + $NEWDESTI=$DESTI; + print "Copy \"$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml\" to $NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml\n"; + use File::Copy qw(copy); + copy "$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml", "$NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"; + } + + # Update GIT tag if required + #--------------------------- + if ($nbofpublishneedtag) + { + print "Go to directory $SOURCE\n"; + $olddir=getcwd(); + chdir("$SOURCE"); + print 'Run git tag -a -m "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'" "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'"'."\n"; $ret=`git tag -a -m "$MAJOR.$MINOR.$BUILD" "$MAJOR.$MINOR.$BUILD" 2>&1`; if ($ret =~ /(already exists|existe déjà)/) From 7139a2dd9d420c9f4dec6179edd40e045f190276 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 13:09:25 +0200 Subject: [PATCH 27/66] Update debian package --- build/debian/source/lintian-overrides | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build/debian/source/lintian-overrides b/build/debian/source/lintian-overrides index b4c0956e90f..c878035b482 100644 --- a/build/debian/source/lintian-overrides +++ b/build/debian/source/lintian-overrides @@ -4,7 +4,12 @@ dolibarr: source-contains-prebuilt-javascript-object htdocs/includes/jsgantt/* dolibarr: source-contains-prebuilt-javascript-object htdocs/includes/jstz/* # Those are false positives, the files are their own sources since # they are not minified -source-is-missing htdocs/includes/jsgantt/jsgantt.js * -source-is-missing htdocs/includes/jquery/plugins/colorpicker/jquery.colorpicker.js * -source-is-missing htdocs/includes/jquery/plugins/select2/select2.js * -source-is-missing htdocs/includes/jquery/plugins/select2/select2_locale_ar.js * +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/a11yhelp/dialogs/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/specialchar/dialogs/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/*/dialogs/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/*/filter/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/templates/templates/default.js +source-is-missing htdocs/includes/mobiledetect/mobiledetectlib/Mobile_Detect.json +source-is-missing htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/*.js + From 82ddf293b622c543e4e9740b775a23358008ab93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 13:29:31 +0200 Subject: [PATCH 28/66] Prepare 5.0.3 --- ChangeLog | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 57824562787..78793b9d419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,26 @@ English Dolibarr ChangeLog -------------------------------------------------------------- +***** ChangeLog for 5.0.3 compared to 5.0.2 ***** +FIX: #6677 Expired contracts dashboard box does not show the name of the thirdparty +FIX: #6813 +FIX: 6863 +FIX: #6877 +FIX: #6881 +FIX: Better sanitizing of search all parameter. +FIX: Correction with author and validator user on orders +FIX: dialog window with md theme must not be hidden by left menu part. +FIX: doactions hook missing in invoice model page +FIX: Fullname when member is a moral entity with no name. +FIX: Link to files on bank account tab broken with multicompany FIX: Link to preview on thirdparty broken with multicompany +FIX: New vat code not correctly implemented if "1 price per customer". +FIX: Pagination of invoices +FIX: pagination on resources +FIX: REST API not possible to add agendaevents +FIX: situation invoice broken due to the all percent application form inside addline form +FIX: SQL injection on user/index.php parameter search_statut. +FIX: XSS + ***** ChangeLog for 5.0.2 compared to 5.0.1 ***** FIX: #6468 + Fix missing translation FIX: #6517 #6525 Autocompletion of thirdparty after n chars not implemented From 7c29e286f82f2ca3d3a77a6b67d0534067bad6b0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 13:31:17 +0200 Subject: [PATCH 29/66] Prepare 4.0.7 --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index d2ca04278ff..13349d3c1da 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','4.0.6'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','4.0.7'); if (! defined('EURO')) define('EURO',chr(128)); From d70c14a411f520714656f2d5ca8c0a64d300742c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 19:07:39 +0200 Subject: [PATCH 30/66] Update bonprelevement.class.php --- htdocs/compta/prelevement/class/bonprelevement.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 2bfed9b0696..dd6b773af9f 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1562,11 +1562,11 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.strtoupper(dol_string_unaccent(dolEscapeXML($row_nom))).''.$CrLf; + $XML_DEBITOR .=' '.strtoupper(dolEscapeXML(dol_string_unaccent($row_nom))).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$row_country_code.''.$CrLf; $XML_DEBITOR .=' '.dol_trunc(dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))),70,'right','UTF-8',true).''.$CrLf; - $XML_DEBITOR .=' '.dol_string_unaccent($row_zip.' '.$row_town).''.$CrLf; + $XML_DEBITOR .=' '.dolEscapeXML(dol_string_unaccent($row_zip.' '.$row_town)).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; From d5f83d6bbe9159347192a9dc95bf6285c47a1b4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 19:13:06 +0200 Subject: [PATCH 31/66] NEW #6915 Simplest change. --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4a9d25aefde..f1a7b5b57a9 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -110,10 +110,10 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', * 'email_template', 'event', - * @param int $shared 0=Return id of entity, 1=Return id entity + shared entities + * @param int $shared 1=Return id of current entity + shared entities (default), 0=Return id of current entity only * @return mixed Entity id(s) to use */ -function getEntity($element=false, $shared=0) +function getEntity($element=false, $shared=1) { global $conf, $mc; From 6c7179d28190a0490aee936f74fb670986dd453c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 19:20:33 +0200 Subject: [PATCH 32/66] Test of commit with autoremove trail space --- htdocs/core/lib/functions.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f1a7b5b57a9..bd2944fa2f4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -100,7 +100,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) } /** - * Get list of entity id to use + * Get list of entity id to use. * * @param string $element Current element * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', @@ -110,7 +110,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', * 'email_template', 'event', - * @param int $shared 1=Return id of current entity + shared entities (default), 0=Return id of current entity only + * @param int $shared 1=Return id of current entity + shared entities (default), 0=Return id of current entity only * @return mixed Entity id(s) to use */ function getEntity($element=false, $shared=1) @@ -4710,7 +4710,7 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8') // $temp after pass 1: 0000-021 $temp = preg_replace($pattern,"",$temp); // pass 2 // $temp after pass 2: 0000-021 - + // Supprime aussi les retours if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp); From a49174313f6bf6c6fa05b812c5a78258a65a1f66 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 May 2017 19:45:54 +0200 Subject: [PATCH 33/66] Replace {extra_ with {user_extra_ --- htdocs/core/lib/functions2.lib.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 69ee228504d..c3d8714ab89 100755 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -790,16 +790,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); }*/ - - if(strstr($mask,'extra_')){ - $start = "{extra_"; + if (strstr($mask,'user_extra_')) + { + $start = "{user_extra_"; $end = "\}"; - $extra= get_string_between($mask, "extra_", "}"); + $extra= get_string_between($mask, "user_extra_", "}"); if(!empty($user->array_options['options_'.$extra])){ - $mask = preg_replace('#('.($start).')(.*?)('.($end).')#si', $user->array_options['options_'.$extra], $mask); + $mask = preg_replace('#('.$start.')(.*?)('.$end.')#si', $user->array_options['options_'.$extra], $mask); } - } + } $maskwithonlyymcode=$mask; $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); From c70beaa56b3afce61c4e0f1def585eeffe566487 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 01:53:55 +0200 Subject: [PATCH 34/66] Complete work for mutualizing generic substitution system. --- htdocs/admin/commande.php | 14 +-- htdocs/admin/contract.php | 2 +- htdocs/admin/defaultvalues.php | 44 ++++----- htdocs/admin/expedition.php | 2 +- htdocs/admin/expensereport.php | 12 +-- htdocs/admin/facture.php | 2 +- htdocs/admin/fichinter.php | 4 +- htdocs/admin/ihm.php | 88 +++++++++++------- htdocs/admin/livraison.php | 4 +- htdocs/admin/mails_templates.php | 68 +++++++------- htdocs/admin/propal.php | 6 +- htdocs/admin/supplier_invoice.php | 6 +- htdocs/admin/supplier_order.php | 10 +-- htdocs/admin/supplier_proposal.php | 6 +- htdocs/core/class/html.formmail.class.php | 75 ++++++++-------- htdocs/core/lib/functions.lib.php | 103 +++++++++++++++++++++- htdocs/core/lib/pdf.lib.php | 50 ++++------- htdocs/core/lib/security2.lib.php | 16 ++-- htdocs/index.php | 31 +++---- 19 files changed, 315 insertions(+), 228 deletions(-) diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index d60144a3492..6d92ad21999 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -182,7 +182,7 @@ else if ($action == 'setdoc') else if ($action == 'setmod') { - // TODO Check if numbering module chosen can be activated + // TODO Check if numbering module chosen can be activated // by calling method canBeActivated dolibarr_set_const($db, "COMMANDE_ADDON",$value,'chaine',0,'',$conf->entity); @@ -331,7 +331,7 @@ foreach ($dirmodels as $reldir) if ($module->isEnabled()) { - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -609,7 +609,7 @@ print "\n"; print ''; // Shippable Icon in List -/* Kept as hidden feature for the moment, result seems bugged. +/* Kept as hidden feature for the moment, result seems bugged. Whet is definition of "shippable" according to all different STOCK_CALCULATE_... options ? print ''; @@ -631,7 +631,7 @@ print ''; // Ask for payment bank during order if ($conf->banque->enabled) { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_ORDER").' '; if (! empty($conf->use_javascript_ajax)) @@ -653,7 +653,7 @@ if ($conf->banque->enabled) } else { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_ORDER").' '.$langs->trans('NotAvailable').''; } @@ -661,7 +661,7 @@ else // Ask for warehouse during order if ($conf->stock->enabled) { - + print ''; print $langs->trans("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER").' '; if (! empty($conf->use_javascript_ajax)) @@ -683,7 +683,7 @@ if ($conf->stock->enabled) } else { - + print ''; print $langs->trans("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER").' '.$langs->trans('NotAvailable').''; } diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 4c0a9572761..47e53a05048 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -265,7 +265,7 @@ foreach ($dirmodels as $reldir) if ($module->isEnabled()) { - + print ''.$module->nom."\n"; print $module->info(); print ''; diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index 40e63de8aea..10d9ec5c282 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -120,11 +120,11 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac $error++; } } - + if (! $error) { $db->begin(); - + if ($action == 'add' || (GETPOST('add') && $action != 'update')) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."default_values(type, user_id, page, param, value, entity) VALUES ('".$db->escape($mode)."', 0, '".$db->escape($defaulturl)."','".$db->escape($defaultkey)."','".$db->escape($defaultvalue)."', ".$db->escape($conf->entity).")"; @@ -134,7 +134,7 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac $sql = "UPDATE ".MAIN_DB_PREFIX."default_values SET page = '".$db->escape($urlpage)."', param = '".$db->escape($key)."', value = '".$db->escape($value)."'"; $sql.= " WHERE rowid = ".$id; } - + $result = $db->query($sql); if ($result > 0) { @@ -223,7 +223,7 @@ print ''; print ''; $head=defaultvalues_prepare_head(); - + dol_fiche_head($head, $mode, '', -1, ''); if ($mode == 'sortorder') @@ -249,11 +249,11 @@ $texturl=$form->textwithpicto($langs->trans("Url"), $texthelp); print_liste_field_titre($texturl,$_SERVER["PHP_SELF"],'page,param','',$param,'',$sortfield,$sortorder); // Field $texthelp=$langs->trans("TheKeyIsTheNameOfHtmlField"); -if ($mode != 'sortorder') +if ($mode != 'sortorder') { $textkey=$form->textwithpicto($langs->trans("Field"), $texthelp); } -else +else { $texthelp='field or alias.field'; $textkey=$form->textwithpicto($langs->trans("Field"), $texthelp); @@ -264,22 +264,14 @@ if ($mode != 'focus') { if ($mode != 'sortorder') { + $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object')); // Must match list into GETPOST + $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation"); $texthelp=$langs->trans("FollowingConstantsWillBeSubstituted").'
'; - // See list into GETPOST - $texthelp.='__USERID__
'; - $texthelp.='__SUPERVISORID__
'; - $texthelp.='__MYCOUNTRYID__
'; - $texthelp.='__DAY__
'; - $texthelp.='__MONTH__
'; - $texthelp.='__YEAR__
'; - $texthelp.='__PREVIOUS_DAY__
'; - $texthelp.='__PREVIOUS_MONTH__
'; - $texthelp.='__PREVIOUS_YEAR__
'; - $texthelp.='__NEXT_DAY__
'; - $texthelp.='__NEXT_MONTH__
'; - $texthelp.='__NEXT_YEAR__
'; - if (! empty($conf->multicompany->enabled)) $texthelp.='__ENTITYID__
'; - $textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, ''); + foreach($substitutionarray as $key => $val) + { + $texthelp.=$key.'
'; + } + $textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, ''); // No tooltip on click, this also triggers the sort click } else { @@ -351,18 +343,18 @@ if ($result) while ($i < $num) { $obj = $db->fetch_object($result); - + print "\n"; print ''; - + // Page print ''; if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) print $obj->page; else print ''; print ''."\n"; - + // Field print ''; if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) print $obj->param; @@ -382,7 +374,7 @@ if ($result) else print ''; print ''; } - + // Actions print ''; if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) @@ -400,7 +392,7 @@ if ($result) print ''; } print ''; - + print "\n"; print "\n"; $i++; diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php index 3c89960ede6..e9a9aaedb18 100644 --- a/htdocs/admin/expedition.php +++ b/htdocs/admin/expedition.php @@ -82,7 +82,7 @@ else if ($action == 'set_param') $error++; setEventMessages($langs->trans("Error"), null, 'errors'); } - + $draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha'); $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity); if ($res <= 0) diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php index eefe5747abd..92ba9375927 100644 --- a/htdocs/admin/expensereport.php +++ b/htdocs/admin/expensereport.php @@ -77,7 +77,7 @@ else if ($action == 'specimen') // For fiche inter $inter->initAsSpecimen(); $inter->status = 0; // Force statut draft to show watermark $inter->fk_statut = 0; // Force statut draft to show watermark - + // Search template files $file=''; $classname=''; $filefound=0; $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); @@ -193,13 +193,13 @@ else if ($action == 'setmod') else if ($action == 'setoptions') { $db->begin(); - + $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT'); // No alpha here, we want exact string $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); - + $draft= GETPOST('EXPENSEREPORT_DRAFT_WATERMARK','alpha'); $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity); - + if (! $res1 > 0 || ! $res2 > 0) $error++; if (! $error) @@ -276,7 +276,7 @@ foreach ($dirmodels as $reldir) if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -399,7 +399,7 @@ foreach ($dirmodels as $reldir) if (file_exists($dir.'/'.$file)) { - + $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 77230dc3f68..64ae1abdde6 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -693,7 +693,7 @@ if ($resql) $i = 0; while ($i < $num) { - + $row = $db->fetch_row($resql); print '
'; print ''; @@ -421,7 +443,7 @@ else // Show if ($user->admin && $conf->global->MAIN_LANG_DEFAULT!='auto') print info_admin($langs->trans("SubmitTranslation".($conf->global->MAIN_LANG_DEFAULT=='en_US'?'ENUS':''),$conf->global->MAIN_LANG_DEFAULT),1); print ''; print ""; - + print ''.$langs->trans("EnableMultilangInterface").'' . yn($conf->global->MAIN_MULTILANGS) . ''; print ' '; print ""; @@ -441,7 +463,7 @@ else // Show print ''.$langs->trans("DefaultMaxSizeList").'' . $conf->global->MAIN_SIZE_LISTE_LIMIT . ''; print ' '; print ""; - + print ''.$langs->trans("DefaultMaxSizeShortList").'' . $conf->global->MAIN_SIZE_SHORTLIST_LIMIT . ''; print ' '; print ""; @@ -452,7 +474,7 @@ else // Show print ' '; print ""; */ - + // Disable javascript/ajax print ''.$langs->trans("DisableJavascript").''; print yn($conf->global->MAIN_DISABLE_JAVASCRIPT).""; @@ -506,7 +528,7 @@ else // Show print ' '; print ''; */ - + // Show bugtrack link print ''.$langs->trans("ShowBugTrackLink", $langs->transnoentitiesnoconv("FindBug")).''; print yn($conf->global->MAIN_BUGTRACK_ENABLELINK).""; @@ -527,7 +549,7 @@ else // Show print ''."\n"; print '
'; - + // Login page print ''; print ''; @@ -537,7 +559,7 @@ else // Show if (isset($conf->global->MAIN_HOME)) print dol_htmlcleanlastbr($conf->global->MAIN_HOME); else print ' '; print ''."\n"; - + // Link to help center print ''; - + print '
'.$langs->trans("LoginPage").' 
'.$langs->trans("DisableLinkToHelpCenter").''; print yn((isset($conf->global->MAIN_HELPCENTER_DISABLELINK)?$conf->global->MAIN_HELPCENTER_DISABLELINK:0),1); @@ -557,9 +579,9 @@ else // Show } print ''; print '
'."\n"; - + print '
'; diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index 74081266f43..cf97b397e44 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -259,7 +259,7 @@ foreach ($dirmodels as $reldir) if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -386,7 +386,7 @@ foreach ($dirmodels as $reldir) { if (file_exists($dir.'/'.$file)) { - + $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index caea3bef9f7..3711b346585 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -59,8 +59,8 @@ $acts[1] = "disable"; $actl[0] = img_picto($langs->trans("Disabled"),'switch_off'); $actl[1] = img_picto($langs->trans("Activated"),'switch_on'); -$listoffset=GETPOST('listoffset'); -$listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000; +$listoffset=GETPOST('listoffset','alpha'); +$listlimit=GETPOST('listlimit','alpha')>0?GETPOST('listlimit','alpha'):1000; $active = 1; $sortfield = GETPOST("sortfield",'alpha'); @@ -119,14 +119,14 @@ $formmail=new FormMail($db); if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { $tmp=FormMail::getAvailableSubstitKey('formemail'); - $tmp['__(AnyTransKey)__']='__(AnyTransKey)__'; + $tmp['__(AnyTranslationKey)__']='__(AnyTranslationKey)__'; $helpsubstit = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); $helpsubstitforlines = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); } else { $tmp=FormMail::getAvailableSubstitKey('formemailwithlines'); - $tmp['__(AnyTransKey)__']='__(AnyTransKey)__'; + $tmp['__(AnyTranslationKey)__']='__(AnyTranslationKey)__'; $helpsubstit = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); $tmp=FormMail::getAvailableSubstitKey('formemailforlines'); $helpsubstitforlines = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); @@ -175,7 +175,7 @@ $id = 25; if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x')) { - //$search_country_id = ''; + //$search_country_id = ''; } // Actions add or modify an entry into a dictionary @@ -479,12 +479,12 @@ if ($action != 'edit') if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); } if ($fieldlist[$field]=='content') { $valuetoshow=''; } if ($fieldlist[$field]=='content_lines') { $valuetoshow=''; } - + if ($valuetoshow != '') { print ''; if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print ''.$valuetoshow.' '.img_help(1,$valuetoshow).''; - else if (! empty($tabhelp[$id][$value])) + else if (! empty($tabhelp[$id][$value])) { if (in_array($value, array('topic'))) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click else print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover @@ -494,15 +494,15 @@ if ($action != 'edit') } if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1; } - + print ''; print ''; print ''; print ''; - + // Line to enter new values print ""; - + $obj = new stdClass(); // If data was already input, we define them in obj to populate input fields. if (GETPOST('actionadd')) @@ -513,12 +513,12 @@ if ($action != 'edit') $obj->$val=GETPOST($val); } } - + $tmpaction = 'create'; $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]); $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; - + if (empty($reshook)) { if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit') @@ -530,11 +530,11 @@ if ($action != 'edit') fieldList($fieldlist,$obj,$tabname[$id],'add'); } } - + print ''; print ''; print ""; - + $fieldsforcontent = array('content'); if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { @@ -545,7 +545,7 @@ if ($action != 'edit') print ''; if ($tmpfieldlist == 'content') print ''.$form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'
'; if ($tmpfieldlist == 'content_lines') print ''.$form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'
'; - + if ($context != 'hide') { //print ''; @@ -556,7 +556,7 @@ if ($action != 'edit') } else print ' '; print ''; - if ($tmpfieldlist == 'content') + if ($tmpfieldlist == 'content') { print ''; if ($action != 'edit') @@ -568,12 +568,12 @@ if ($action != 'edit') //else print ''; print ''; } - - - + + + $colspan=count($fieldlist)+1; print ' '; // Keep   to have a line with enough height -} +} // List of available record in database @@ -590,7 +590,7 @@ if ($resql) if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha'); - + // There is several pages if ($num > $listlimit) { @@ -628,7 +628,7 @@ if ($resql) // Affiche nom du champ if ($showfield) { - if (! empty($tabhelp[$id][$value])) + if (! empty($tabhelp[$id][$value])) { if (in_array($value, array('topic'))) $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover else $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover @@ -653,7 +653,7 @@ if ($resql) print ''; print ''; print ''; - + if ($num) { // Lines with values @@ -680,7 +680,7 @@ if ($resql) print '
'; print ''; print ''; - + $fieldsforcontent = array('content'); if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { @@ -691,11 +691,11 @@ if ($resql) $showfield = 1; $align = "left"; $valuetoshow = $obj->{$tmpfieldlist}; - + $class = 'tddict'; // Show value for field if ($showfield) { - + print ''; // To create an artificial CR for the current tr we are on $okforextended = true; if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) @@ -704,9 +704,9 @@ if ($resql) print $doleditor->Create(1); print ''; print ''; - + } - } + } } else { @@ -778,16 +778,16 @@ if ($resql) { $fieldsforcontent = array('content', 'content_lines'); } - foreach ($fieldsforcontent as $tmpfieldlist) + foreach ($fieldsforcontent as $tmpfieldlist) { $showfield = 1; $align = "left"; $valuetoshow = $obj->{$tmpfieldlist}; - + $class = 'tddict'; // Show value for field if ($showfield) { - + print ''; // To create an artificial CR for the current tr we are on $okforextended = true; if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) @@ -796,13 +796,13 @@ if ($resql) print $doleditor->Create(1); print ''; print ''; - + } }*/ } print "\n"; - - + + $i++; } } diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 7c8413a28a6..e0dc1d3b5b4 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -310,7 +310,7 @@ foreach ($dirmodels as $reldir) if ($module->isEnabled()) { - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -614,7 +614,7 @@ print ''; /* Seems to be not so used. So kept hidden for the moment to avoid dangerous options inflation. if ($conf->banque->enabled) { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL").' '; if (! empty($conf->use_javascript_ajax)) @@ -636,7 +636,7 @@ if ($conf->banque->enabled) } else { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL").' '.$langs->trans('NotAvailable').''; } diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index d408657ac8c..549bb93809b 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -251,7 +251,7 @@ foreach ($dirmodels as $reldir) if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -370,7 +370,7 @@ foreach ($dirmodels as $reldir) { while (($file = readdir($handle))!==false) { - if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) { $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); @@ -378,7 +378,7 @@ foreach ($dirmodels as $reldir) require_once $dir.'/'.$file; $module = new $classname($db, new FactureFournisseur($db)); - + print "\n"; print ""; print (empty($module->name)?$name:$module->name); diff --git a/htdocs/admin/supplier_order.php b/htdocs/admin/supplier_order.php index acce3a38c7c..55e4e4b3d07 100644 --- a/htdocs/admin/supplier_order.php +++ b/htdocs/admin/supplier_order.php @@ -280,7 +280,7 @@ foreach ($dirmodels as $reldir) if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -402,7 +402,7 @@ foreach ($dirmodels as $reldir) require_once $dir.'/'.$file; $module = new $classname($db, new CommandeFournisseur($db)); - + print "\n"; print ""; print (empty($module->name)?$name:$module->name); @@ -502,14 +502,14 @@ $var=false; print ''; print ''; print "\n"; - + //} // Ask for payment bank during supplier order /* Kept as hidden for the moment if ($conf->banque->enabled) { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER").' '; if (! empty($conf->use_javascript_ajax)) @@ -531,7 +531,7 @@ if ($conf->banque->enabled) } else { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER").' '.$langs->trans('NotAvailable').''; } diff --git a/htdocs/admin/supplier_proposal.php b/htdocs/admin/supplier_proposal.php index 8a8d2a181a4..82eeddd594c 100644 --- a/htdocs/admin/supplier_proposal.php +++ b/htdocs/admin/supplier_proposal.php @@ -289,7 +289,7 @@ foreach ($dirmodels as $reldir) if ($module->isEnabled()) { - + print ''.$module->nom."\n"; print $module->info(); print ''; @@ -567,7 +567,7 @@ print ''; if ($conf->banque->enabled) { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_PROPOSAL").' '; if (! empty($conf->use_javascript_ajax)) @@ -589,7 +589,7 @@ if ($conf->banque->enabled) } else { - + print ''; print $langs->trans("BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_PROPOSAL").' '.$langs->trans('NotAvailable').''; } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 3641ac87cef..a8d6d64c45c 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -155,7 +155,7 @@ class FormMail extends Form $listofpaths=array(); $listofnames=array(); $listofmimes=array(); - + $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); @@ -182,7 +182,7 @@ class FormMail extends Form $listofpaths=array(); $listofnames=array(); $listofmimes=array(); - + $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); @@ -209,7 +209,7 @@ class FormMail extends Form $listofpaths=array(); $listofnames=array(); $listofmimes=array(); - + $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); @@ -266,13 +266,13 @@ class FormMail extends Form $out=''; $disablebademails=1; - + // Define list of attached files $listofpaths=array(); $listofnames=array(); $listofmimes=array(); $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined - + if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); @@ -415,7 +415,7 @@ class FormMail extends Form { $posalias++; $listaliasval=trim($listaliasval); - if ($listaliasval) + if ($listaliasval) { $listaliasval=preg_replace('//', '>', $listaliasval); @@ -720,7 +720,7 @@ class FormMail extends Form $this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); } } - + //Add lines substitution key from each line $lines = ''; $defaultlines = $arraydefaultmessage['content_lines']; @@ -979,14 +979,14 @@ class FormMail extends Form return -1; } } - - - + + + /** * Set substit array from object - * + * * @param CommonObject $object Object to use - * @param Translate $outputlangs Object lang + * @param Translate $outputlangs Object lang * @return void */ function setSubstitFromObject($object, $outputlangs=null) @@ -1001,14 +1001,14 @@ class FormMail extends Form $this->substit['__AMOUNT__'] = price($object->total_ttc); $this->substit['__AMOUNT_WO_TAX__'] = price($object->total_ht); $this->substit['__AMOUNT_VAT__'] = price($object->total_tva); - + $this->substit['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:''); $this->substit['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:''); - + $this->substit['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:''); $this->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); $this->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:''); - + $this->substit['__SIGNATURE__'] = $user->signature; $this->substit['__PERSONALIZED__'] = ''; $this->substit['__CONTACTCIVNAME__'] = ''; // Will be replace just before sending @@ -1020,7 +1020,7 @@ class FormMail extends Form foreach ($extrafields->attribute_label as $key => $label) { $this->substit['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; } - + //Fill substit_lines with each object lines content if (is_array($object->lines)) { @@ -1057,36 +1057,37 @@ class FormMail extends Form } } } - + /** - * Get list of substition keys available. - * + * Get list of substition keys available for emails. + * This include the complete_substitutions_array. TODO Include the getCommonSubstitutionArray(). + * * @param string $mode 'formemail', 'formemailwithlines', 'formemailforlines', 'emailing', ... - * @return void + * @return array Array of substitution values for emails. */ static function getAvailableSubstitKey($mode='formemail') { global $conf, $langs; - + $vars=array(); - + if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') { $vars=array( - '__REF__', - '__REFCLIENT__', - '__REFSUPPLIER__', - '__THIRDPARTY_ID__', - '__THIRDPARTY_NAME__', - '__PROJECT_ID__', - '__PROJECT_REF__', + '__REF__', + '__REFCLIENT__', + '__REFSUPPLIER__', + '__THIRDPARTY_ID__', + '__THIRDPARTY_NAME__', + '__PROJECT_ID__', + '__PROJECT_REF__', '__PROJECT_NAME__', '__CONTACTCIVNAME__', - '__AMOUNT__', - '__AMOUNT_WO_TAX__', - '__AMOUNT_VAT__', + '__AMOUNT__', + '__AMOUNT_WO_TAX__', + '__AMOUNT_VAT__', '__PERSONALIZED__', // Paypal link will be added here in form mode - '__SIGNATURE__', + '__SIGNATURE__', ); if ($mode == 'formwithlines') { @@ -1127,21 +1128,21 @@ class FormMail extends Form if ($conf->contrat->enabled) $vars['__SECUREKEYPAYPAL_CONTRACTLINE__']='SecureKeyPaypalUniquePerContractLine'; } } - else + else { $vars['__SECUREKEYPAYPAL__']=''; $vars['__SECUREKEYPAYPAL_MEMBER__']=''; } } - - $tmparray=array(); + $parameters=array('mode'=>$mode); + $tmparray=getCommonSubstitutionArray($langs); complete_substitutions_array($tmparray, $langs, null, $parameters); foreach($tmparray as $key => $val) { $vars[$key]=$key; } - + return $vars; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bd2944fa2f4..a18b9e14110 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5014,8 +5014,100 @@ function dol_concatdesc($text1,$text2,$forxml=false) return $ret; } + /** - * Make substition into a string replacing key with vals from $substitutionarray (oldval=>newval) + * Return array of possible common substitutions. + * + * @param Translate $outputlangs Output language + * @param int $onlykey Do not calculate heavy values of keys (performance enhancement when we need only the keys) + * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...) + * @param Object $object Object for keys on object + * @return array Array of substitutions + */ +function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null) +{ + global $conf, $mysoc, $user; + + $substitutionarray=array(); + + if (empty($exclude) || ! in_array('mycompany', $exclude)) + { + $substitutionarray=array_merge($substitutionarray, array( + '__MYCOMPANY_NAME__' => $mysoc->name, + '__MYCOMPANY_EMAIL__' => $mysoc->email, + '__MYCOMPANY_PROFID1__' => $mysoc->idprof1, + '__MYCOMPANY_PROFID2__' => $mysoc->idprof2, + '__MYCOMPANY_PROFID3__' => $mysoc->idprof3, + '__MYCOMPANY_PROFID4__' => $mysoc->idprof4, + '__MYCOMPANY_PROFID5__' => $mysoc->idprof5, + '__MYCOMPANY_PROFID6__' => $mysoc->idprof6, + '__MYCOMPANY_CAPITAL__' => $mysoc->capital, + '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id + )); + } + if (empty($exclude) || ! in_array('object', $exclude)) + { + if (is_object($object)) // For backward compatibility + { + $substitutionarray['__TOTAL_TTC__'] =is_object($object)?$object->total_ttc:''; + $substitutionarray['__TOTAL_HT__'] =is_object($object)?$object->total_ht:''; + $substitutionarray['__TOTAL_VAT__'] =is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):''; + } + $substitutionarray['__AMOUNT__'] =is_object($object)?$object->total_ttc:''; + $substitutionarray['__AMOUNT_WO_TAX__']=is_object($object)?$object->total_ht:''; + $substitutionarray['__AMOUNT_VAT__'] =is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):''; + } + + if (empty($exclude) || ! in_array('date', $exclude)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + + if (! empty($onlykey)) + { + $tmp=$tmp2=$tmp3=$tmp4=$tmp5=array(); + } + else + { + $tmp=dol_getdate(dol_now(), true); + $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); + $tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); + $tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); + $tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); + } + $substitutionarray=array_merge($substitutionarray, array( + '__DAY__' => $tmp['mday'], + '__MONTH__' => $tmp['mon'], + '__YEAR__' => $tmp['year'], + '__PREVIOUS_DAY__' => $tmp2['day'], + '__PREVIOUS_MONTH__' => $tmp3['month'], + '__PREVIOUS_YEAR__' => ($tmp['year'] - 1), + '__NEXT_DAY__' => $tmp4['day'], + '__NEXT_MONTH__' => $tmp5['month'], + '__NEXT_YEAR__' => ($tmp['year'] + 1), + )); + } + + if (empty($exclude) || ! in_array('user', $exclude)) + { + $substitutionarray=array_merge($substitutionarray, array( + '__USER_ID__' => $user->id, + '__USER_LOGIN__' => $user->login, + '__USER_LASTNAME__' => $user->lastname, + '__USER_FIRSTNAME__' => $user->firstname, + '__USER_FULLNAME__' => $user->getFullName($outputlangs), + '__USER_SUPERVISOR_ID__' => $user->fk_user + )); + } + if (! empty($conf->multicompany->enabled)) + { + $substitutionarray=array_merge($substitutionarray, array('__ENTITY_ID__' => $conf->entity)); + } + + return $substitutionarray; +} + +/** + * Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval). * * @param string $text Source string in which we must do substitution * @param array $substitutionarray Array with key->val to substitute @@ -5034,11 +5126,16 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null) // Make substitution for language keys if (is_object($outputlangs)) { - while (preg_match('/__\((.*)\)__/', $text, $reg)) + while (preg_match('/__\(([^\)]*)\)__/', $text, $reg)) { + // If key is __(TranslationKey|langfile)__, then force load of langfile.lang + $tmp=explode('|',$reg[1]); + if (! empty($tmp[1])) $outputlangs->load($tmp[1]); + $msgishtml = 0; if (dol_textishtml($text,1)) $msgishtml = 1; - $text = preg_replace('/__\('.preg_quote($reg[1]).'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text); + + $text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text); } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index e83faee6c8d..8c48e2301e3 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -588,38 +588,25 @@ function pdf_pagehead(&$pdf,$outputlangs,$page_height) /** - * Return array of possible substitutions + * Return array of possible substitutions for PDF content (without external module substitutions). * * @param Translate $outputlangs Output language + * @param Object $object Object * @return array Array of substitutions */ -function pdf_getSubstitutionArray($outputlangs) +function pdf_getSubstitutionArray($outputlangs, $object=null) { - global $conf, $mysoc, $user; - $substitutionarray=array( - '__MYCOMPANY_NAME__' => $mysoc->name, - '__MYCOMPANY_EMAIL__' => $mysoc->email, - '__MYCOMPANY_PROFID1__' => $mysoc->idprof1, - '__MYCOMPANY_PROFID2__' => $mysoc->idprof2, - '__MYCOMPANY_PROFID3__' => $mysoc->idprof3, - '__MYCOMPANY_PROFID4__' => $mysoc->idprof4, - '__MYCOMPANY_PROFID5__' => $mysoc->idprof5, - '__MYCOMPANY_PROFID6__' => $mysoc->idprof6, - '__MYCOMPANY_CAPITAL__' => $mysoc->capital, - '__USER_ID__' => $user->id, - '__USER_LOGIN__' => $user->login, - '__USER_LASTNAME__' => $user->lastname, - '__USER_FIRSTNAME__' => $user->firstname, - '__USER_FULLNAME__' => $user->getFullName($outputlangs) - ); - return $substitutionarray; + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $substitutionarray['__FROM_NAME__']='__FROM_NAME__'; + $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__'; + return $substitutionarray; } /** * Add a draft watermark on PDF files * - * @param TCPDF $pdf Object PDF + * @param TCPDF $pdf Object PDF * @param Translate $outputlangs Object lang * @param int $h Height of PDF * @param int $w Width of PDF @@ -630,7 +617,7 @@ function pdf_getSubstitutionArray($outputlangs) function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) { global $langs, $mysoc, $user; - + // Print Draft Watermark if ($unit=='pt') $k=1; elseif ($unit=='mm') $k=72/25.4; @@ -638,11 +625,11 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) elseif ($unit=='in') $k=72; // Make substitution - $substitutionarray=pdf_getSubstitutionArray($outputlangs); - complete_substitutions_array($substitutionarray,$outputlangs,$object); + $substitutionarray=pdf_getSubstitutionArray($outputlangs,null); + complete_substitutions_array($substitutionarray,$outputlangs,null); $text=make_substitutions($text,$substitutionarray,$outputlangs); $text=$outputlangs->convToOutputCharset($text); - + $savx=$pdf->getX(); $savy=$pdf->getY(); $watermark_angle=atan($h/$w)/2; @@ -867,13 +854,10 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass // Line of free text if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext)) { - $substitutionarray=pdf_getSubstitutionArray($outputlangs); + $substitutionarray=pdf_getSubstitutionArray($outputlangs, $object); // More substitution keys $substitutionarray['__FROM_NAME__']=$fromcompany->name; $substitutionarray['__FROM_EMAIL__']=$fromcompany->email; - $substitutionarray['__TOTAL_TTC__']=$object->total_ttc; - $substitutionarray['__TOTAL_HT__']=$object->total_ht; - $substitutionarray['__TOTAL_VAT__']=$object->total_vat; complete_substitutions_array($substitutionarray,$outputlangs,$object); $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs); $line.=$outputlangs->convToOutputCharset($newfreetext); @@ -1289,16 +1273,16 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if (empty($hideref)) { - if ($issupplierline) + if ($issupplierline) { if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1) $ref_prodserv = $ref_supplier; elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2) - $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')'; - else + $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')'; + else $ref_prodserv = $prodser->ref.' ('.$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.')'; } - else + else $ref_prodserv = $prodser->ref; // Show local ref only if (! empty($libelleproduitservice)) $ref_prodserv .= " - "; diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index 3f41e74b7f6..d20b9612b5f 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -265,15 +265,11 @@ function dol_loginfunction($langs,$conf,$mysoc) $main_home=''; if (! empty($conf->global->MAIN_HOME)) { - $i=0; - while (preg_match('/__\(([a-zA-Z|@]+)\)__/i',$conf->global->MAIN_HOME,$reg) && $i < 100) - { - $tmp=explode('|',$reg[1]); - if (! empty($tmp[1])) $langs->load($tmp[1]); - $conf->global->MAIN_HOME=preg_replace('/__\('.preg_quote($reg[1]).'\)__/i',$langs->trans($tmp[0]),$conf->global->MAIN_HOME); - $i++; - } - $main_home=dol_htmlcleanlastbr($conf->global->MAIN_HOME); + $substitutionarray=getCommonSubstitutionArray($langs); + complete_substitutions_array($substitutionarray, $langs); + $texttoshow = make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs); + + $main_home=dol_htmlcleanlastbr($texttoshow); } // Google AD @@ -415,7 +411,7 @@ function encodedecode_dbpassconf($level=0) fflush($fp); fclose($fp); clearstatcache(); - + // It's config file, so we set read permission for creator only. // Should set permission to web user and groups for users used by batch //@chmod($file, octdec('0600')); diff --git a/htdocs/index.php b/htdocs/index.php index d2da24471d8..5303587150e 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -77,7 +77,7 @@ if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$langs->trans("HomeAr llxHeader('',$title); - + $resultboxes=FormOther::getBoxesArea($user,"0"); // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb) @@ -88,18 +88,13 @@ if (! empty($conf->global->MAIN_MOTD)) $conf->global->MAIN_MOTD=preg_replace('//i','
',$conf->global->MAIN_MOTD); if (! empty($conf->global->MAIN_MOTD)) { - $i=0; - while (preg_match('/__\(([a-zA-Z|@]+)\)__/i',$conf->global->MAIN_MOTD,$reg) && $i < 100) - { - $tmp=explode('|',$reg[1]); - if (! empty($tmp[1])) $langs->load($tmp[1]); - $conf->global->MAIN_MOTD=preg_replace('/__\('.preg_quote($reg[1]).'\)__/i',$langs->trans($tmp[0]),$conf->global->MAIN_MOTD); - $i++; - } + $substitutionarray=getCommonSubstitutionArray($langs); + complete_substitutions_array($substitutionarray, $langs); + $texttoshow = make_substitutions($conf->global->MAIN_MOTD, $substitutionarray, $langs); print "\n\n"; print '
'; - print dol_htmlentitiesbr($conf->global->MAIN_MOTD); + print dol_htmlentitiesbr($texttoshow); print '

'; print "\n\n"; } @@ -136,7 +131,7 @@ if (empty($user->societe_id)) $action=''; $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $boxstat.=$hookmanager->resPrint; - + if (empty($reshook)) { // Condition to be checked for each display line dashboard @@ -179,7 +174,7 @@ if (empty($user->societe_id)) DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.commande.class.php", DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php", DOL_DOCUMENT_ROOT."/supplier_proposal/class/supplier_proposal.class.php", - DOL_DOCUMENT_ROOT."/projet/class/project.class.php", + DOL_DOCUMENT_ROOT."/projet/class/project.class.php", DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php", DOL_DOCUMENT_ROOT."/don/class/don.class.php" ); @@ -327,12 +322,12 @@ if (empty($user->societe_id)) $board->load_state_board($user); $boardloaded[$classe]=$board; } - else + else { $board=$boardloaded[$classe]; } - + if (!empty($langfile[$key])) $langs->load($langfile[$key]); $text=$langs->trans($titres[$key]); $boxstat.=''; @@ -353,7 +348,7 @@ if (empty($user->societe_id)) $boxstat.=''; $boxstat.=''; $boxstat.=''; - + $boxstat.=''; $boxstat.=''; $boxstat.='
'; @@ -558,7 +553,7 @@ if (! empty($valid_dashboardlines)) $textlate = $langs->trans("NActionsLate",$board->nbtodolate); $textlate.= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')'; - + $boxwork .='
'; $boxwork .= '
'; $boxwork .= ''.$board->img.' '.$board->label.'
'; @@ -579,7 +574,7 @@ if (! empty($valid_dashboardlines)) $boxwork.='
'; $boxwork .="\n"; } - + $boxwork .='
'; $boxwork .='
'; $boxwork .='
'; @@ -693,7 +688,7 @@ function showWeather($totallate,$text,$options) $out=''; $offset=0; $factor=10; // By default - + $level0=$offset; if (! empty($conf->global->MAIN_METEO_LEVEL0)) $level0=$conf->global->MAIN_METEO_LEVEL0; $level1=$offset+1*$factor; if (! empty($conf->global->MAIN_METEO_LEVEL1)) $level1=$conf->global->MAIN_METEO_LEVEL1; $level2=$offset+2*$factor; if (! empty($conf->global->MAIN_METEO_LEVEL2)) $level2=$conf->global->MAIN_METEO_LEVEL2; From fa3cd267f48f98cd4312e90c5779849fd1bbe60a Mon Sep 17 00:00:00 2001 From: Inovea Conseil Date: Thu, 1 Jun 2017 10:51:30 +0200 Subject: [PATCH 35/66] Fix bug of prepare_head of card Delete the call of commande_prepare_head function because do not use in skeleton --- dev/skeletons/skeleton_card.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dev/skeletons/skeleton_card.php b/dev/skeletons/skeleton_card.php index f0a9dd23c26..8c487dee776 100644 --- a/dev/skeletons/skeleton_card.php +++ b/dev/skeletons/skeleton_card.php @@ -297,9 +297,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { $res = $object->fetch_optionals($object->id, $extralabels); - $head = commande_prepare_head($object); - dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order'); - + print load_fiche_titre($langs->trans("MyModule")); dol_fiche_head(); From 40dd6fc61c0a08118d2d5b1914a2a17c8a44a0d5 Mon Sep 17 00:00:00 2001 From: Inovea Conseil Date: Thu, 1 Jun 2017 11:22:08 +0200 Subject: [PATCH 36/66] Fix bug to display value Fix bug to display the values in the future card.php --- dev/skeletons/build_class_from_table.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index 537975365ef..532da3131a6 100755 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -1,6 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2017 Nicolas ZABOURI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -649,7 +650,7 @@ foreach ($skeletonfiles as $skeletonfile => $outfile) { if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime']) { - $varprop.="print ''.\$langs->trans(\"Field".$prop['field']."\").'\$object->".$prop['field']."';\n"; + $varprop.="print ''.\$langs->trans(\"Field".$prop['field']."\").''.\$object->".$prop['field'].".'';\n"; } } $targetcontent=preg_replace('/LIST_OF_TD_LABEL_FIELDS_VIEW/', $varprop, $targetcontent); From 77df19009db350893462e42caaad9bad2c50924e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 12:11:45 +0200 Subject: [PATCH 37/66] Removed duplicated code --- htdocs/admin/agenda_other.php | 57 +++---- htdocs/admin/barcode.php | 36 +--- htdocs/admin/commande.php | 31 +--- htdocs/admin/contract.php | 31 +--- htdocs/admin/expedition.php | 32 +--- htdocs/admin/expensereport.php | 32 +--- htdocs/admin/facture.php | 27 +-- htdocs/admin/fichinter.php | 32 +--- htdocs/admin/livraison.php | 32 +--- htdocs/admin/propal.php | 32 +--- htdocs/admin/supplier_payment.php | 35 +--- htdocs/admin/supplier_proposal.php | 36 +--- htdocs/admin/user.php | 32 +--- htdocs/admin/usergroup.php | 32 +--- htdocs/core/actions_setmoduleoptions.inc.php | 86 ++++++++++ htdocs/core/lib/files.lib.php | 160 +++++++++--------- .../doc/doc_generic_contract_odt.modules.php | 41 +---- htdocs/langs/en_US/admin.lang | 2 + htdocs/modulebuilder/template/admin/setup.php | 9 +- htdocs/product/admin/product.php | 45 +---- htdocs/projet/admin/project.php | 39 +---- htdocs/societe/admin/societe.php | 32 +--- 22 files changed, 265 insertions(+), 626 deletions(-) create mode 100644 htdocs/core/actions_setmoduleoptions.inc.php diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index bd9587a4440..44ec3ade889 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -49,6 +49,8 @@ $type = 'action'; * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if (preg_match('/set_(.*)/',$action,$reg)) { $code=$reg[1]; @@ -77,21 +79,6 @@ if (preg_match('/del_(.*)/',$action,$reg)) dol_print_error($db); } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} if ($action == 'set') { dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity); @@ -233,7 +220,7 @@ else if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { print load_fiche_titre($langs->trans("AgendaModelModule"),'',''); - + print ''."\n"; print ''."\n"; print ''."\n"; @@ -243,13 +230,13 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print ''; print ''; print ''."\n"; - + clearstatcache(); - + foreach ($dirmodels as $reldir) { $dir = dol_buildpath($reldir."core/modules/action/doc/"); - + if (is_dir($dir)) { $handle=opendir($dir); @@ -261,10 +248,10 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); - + require_once $dir.'/'.$file; - $module = new $classname($db, new ActionComm($db)); - + $module = new $classname($db, new ActionComm($db)); + print ''."\n"; print "\n"; - + // Active if (in_array($name, $def)) { - + print '"; } - + // Default print ''; - + // Info $htmltooltip = ''.$langs->trans("Name").': '.$module->name; $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); @@ -326,7 +313,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print ''; - + print "\n"; } } @@ -366,7 +353,7 @@ print ''."\n"; if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) { - + print ''; print ''."\n"; print ''."\n"; @@ -404,30 +391,30 @@ print ''."\n"; // AGENDA NOTIFICATION if ($conf->global->MAIN_FEATURES_LEVEL > 0) { - + print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; } else { print ''.img_picto($langs->trans('Enabled'),'switch_on').''; print ''."\n"; - + print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; } } diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php index db81c9a325f..ba649fe9223 100644 --- a/htdocs/admin/barcode.php +++ b/htdocs/admin/barcode.php @@ -39,6 +39,8 @@ $action = GETPOST('action','alpha'); * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'setbarcodeproducton') { $res=dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity); @@ -72,33 +74,7 @@ else if ($action == 'update') else if ($action == 'updateengine') { // TODO Update engines. - -} -// define constants for models generator that need parameters -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - } - } - if (! $res > 0) $error++; - - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } } if ($action && $action != 'setcoder' && $action != 'setModuleOptions') @@ -276,7 +252,7 @@ if ($resql) print '\n"; - + $i++; } } @@ -312,7 +288,7 @@ print ''; // Chemin du binaire genbarcode sous linux if (! isset($_SERVER['WINDIR'])) { - + print ''; print ''; print ''; print ''; print ''; print ''; print '\n"; print "'; $texte.= '
'.$langs->trans("Name").''.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
"; print (empty($module->name)?$name:$module->name); @@ -272,16 +259,16 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print "\n"; require_once $dir.$file; $module = new $classname($db,$specimenthirdparty); - if (method_exists($module,'info')) + if (method_exists($module,'info')) print $module->info($langs); - else + else print $module->description; print "'."\n"; if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name") { @@ -301,7 +288,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print 'scandir.'&label='.urlencode($module->name).'&type=action">'.img_picto($langs->trans("Disabled"),'switch_off').''; print "'; if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name") @@ -313,7 +300,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print 'scandir.'&label='.urlencode($module->name).'&type=action"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; } print ''; print ''.img_object($langs->trans("Preview"),'order').''; print '
'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'
'.$langs->trans('AGENDA_NOTIFICATION').' '."\n"; - + if (empty($conf->global->AGENDA_NOTIFICATION)) { print ''.img_picto($langs->trans('Disabled'),'switch_off').''; print '
'.$langs->trans('AGENDA_NOTIFICATION_SOUND').' '."\n"; - + if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) { print ''.img_picto($langs->trans('Disabled'),'switch_off').''; } else { print ''.img_picto($langs->trans('Enabled'),'switch_on').''; } - + print '
'; print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i); print "
'.$langs->trans("GenbarcodeLocation").''; @@ -328,7 +304,7 @@ if (! isset($_SERVER['WINDIR'])) // Module products if (! empty($conf->product->enabled)) { - + print '
'.$langs->trans("SetDefaultBarcodeTypeProducts").''; @@ -339,7 +315,7 @@ if (! empty($conf->product->enabled)) // Module thirdparty if (! empty($conf->societe->enabled)) { - + print '
'.$langs->trans("SetDefaultBarcodeTypeThirdParties").''; diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 6d92ad21999..3f3c997b0d8 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -54,6 +54,8 @@ $type = 'order'; * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconstorder=GETPOST('maskconstorder','alpha'); @@ -118,35 +120,6 @@ else if ($action == 'specimen') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 47e53a05048..206d9020022 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -50,6 +50,8 @@ if (empty($conf->global->CONTRACT_ADDON)) * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconst = GETPOST('maskconstcontract','alpha'); @@ -113,35 +115,6 @@ else if ($action == 'specimen') // For contract } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php index e9a9aaedb18..6182538f820 100644 --- a/htdocs/admin/expedition.php +++ b/htdocs/admin/expedition.php @@ -57,6 +57,9 @@ if (empty($conf->global->EXPEDITION_ADDON_NUMBER)) /* * Actions */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconst=GETPOST('maskconstexpedition','alpha'); @@ -142,35 +145,6 @@ else if ($action == 'specimen') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -else if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php index 92ba9375927..6c659181c4c 100644 --- a/htdocs/admin/expensereport.php +++ b/htdocs/admin/expensereport.php @@ -51,6 +51,9 @@ $type='expensereport'; /* * Actions */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconst=GETPOST('maskconst','alpha'); @@ -116,35 +119,6 @@ else if ($action == 'specimen') // For fiche inter } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 64ae1abdde6..115a685a3f2 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -51,6 +51,8 @@ $type='invoice'; * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconstinvoice=GETPOST('maskconstinvoice','alpha'); @@ -123,31 +125,6 @@ if ($action == 'specimen') } } -// define constants for models generator that need parameters -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - } - } - if (! $res > 0) $error++; - - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/fichinter.php b/htdocs/admin/fichinter.php index e3000231c38..25c46164783 100644 --- a/htdocs/admin/fichinter.php +++ b/htdocs/admin/fichinter.php @@ -51,6 +51,9 @@ $type='ficheinter'; /* * Actions */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconst=GETPOST('maskconst','alpha'); @@ -114,35 +117,6 @@ else if ($action == 'specimen') // For fiche inter } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index cf97b397e44..ef73ec7a757 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -47,10 +47,13 @@ $label = GETPOST('label','alpha'); $scandir = GETPOST('scandir','alpha'); $type='delivery'; + /* * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconstdelivery=GETPOST('maskconstdelivery','alpha'); @@ -131,35 +134,6 @@ if ($action == 'specimen') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - if ($action == 'set') { $ret = addDocumentModel($value, $type, $label, $scandir); diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index e0dc1d3b5b4..9fa8dad0c0c 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -49,6 +49,9 @@ $type='propal'; /* * Actions */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + $error=0; if ($action == 'updateMask') { @@ -180,35 +183,6 @@ if ($action == 'set_BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model if ($action == 'set') { diff --git a/htdocs/admin/supplier_payment.php b/htdocs/admin/supplier_payment.php index adaa114b1ca..4227f4d4221 100644 --- a/htdocs/admin/supplier_payment.php +++ b/htdocs/admin/supplier_payment.php @@ -47,6 +47,8 @@ $type='supplier_payment'; * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconstsupplierpayment=GETPOST('maskconstsupplierpayment','alpha'); @@ -68,31 +70,6 @@ if ($action == 'updateMask') dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity); } -// define constants for models generator that need parameters -else if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - } - } - if (! $res > 0) $error++; - - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { @@ -195,7 +172,7 @@ dol_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'compan */ if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan'; - + print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', ''); // Load array def with activated templates @@ -265,7 +242,7 @@ foreach ($dirmodels as $reldir) require_once $dir.$filebis; $module = new $classname($db); - + // Show modules according to features level if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; @@ -375,7 +352,7 @@ foreach ($dirmodels as $reldir) { while (($file = readdir($handle))!==false) { - if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) { $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); @@ -383,7 +360,7 @@ foreach ($dirmodels as $reldir) require_once $dir.'/'.$file; $module = new $classname($db, new PaiementFourn($db)); - + print "
"; print (empty($module->name)?$name:$module->name); diff --git a/htdocs/admin/supplier_proposal.php b/htdocs/admin/supplier_proposal.php index 82eeddd594c..210d601c33c 100644 --- a/htdocs/admin/supplier_proposal.php +++ b/htdocs/admin/supplier_proposal.php @@ -41,10 +41,15 @@ $label = GETPOST('label','alpha'); $scandir = GETPOST('scandir','alpha'); $type='supplier_proposal'; +$error=0; + + /* * Actions */ -$error=0; + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'updateMask') { $maskconstsupplier_proposal=GETPOST('maskconstsupplier_proposal','alpha'); @@ -159,35 +164,6 @@ if ($action == 'set_BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_PROPOSAL') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model if ($action == 'set') { diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index 0c7574b7ec4..31efcb22474 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -47,37 +47,9 @@ $type='user'; * Action */ -// Activate a model +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} -elseif ($action == 'set_default') +if ($action == 'set_default') { $ret = addDocumentModel($value, $type, $label, $scandir); $res = true; diff --git a/htdocs/admin/usergroup.php b/htdocs/admin/usergroup.php index 4642e6d3183..8d098ee6923 100644 --- a/htdocs/admin/usergroup.php +++ b/htdocs/admin/usergroup.php @@ -47,37 +47,9 @@ $type='group'; * Action */ -// Activate a model +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} -elseif ($action == 'set_default') +if ($action == 'set_default') { $ret = addDocumentModel($value, $type, $label, $scandir); $res = true; diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php new file mode 100644 index 00000000000..03b33b19eb1 --- /dev/null +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -0,0 +1,86 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/actions_setnotes.inc.php + * \brief Code for actions on setting notes of object page + */ + + +// $action must be defined +// $_FILES may be defined +// $nomessageinsetmoduleoptions can be set to 1 + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $db->begin(); + + // Process common param fields + foreach($_POST as $key => $val) + { + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + { + $param=GETPOST("param".$reg[1],'alpha'); + $value=GETPOST("value".$reg[1],'alpha'); + if ($param) + { + $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + } + + // Process upload fields + if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09')) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $keyforuploaddir=GETPOST('keyforuploaddir','aZ09'); + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir))); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); + else + { + $upload_dir=$tmpdir; + } + } + if ($upload_dir) + { + $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); + if ($result <= 0) $error++; + } + } + + if (! $error) + { + $db->commit(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); + } +} + diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 95fca68aa5d..85aace9db0b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -44,7 +44,7 @@ function dol_basename($pathfile) * @param string $path Starting path from which to search. This is a full path. * @param string $types Can be "directories", "files", or "all" * @param int $recursive Determines whether subdirectories are searched - * @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function, + * @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function, * but must not contains the start and end '/'. Filter is checked into basename only. * @param array $excludefilter Array of Regex for exclude filter (example: array('(\.meta|_preview.*\.png)$','^\.')). Exclude is checked into fullpath. * @param string $sortcriteria Sort criteria ("","fullname","name","date","size") @@ -71,9 +71,9 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil $reshook = 0; $file_list = array(); - + $hookmanager->resArray=array(); - + if (! $nohook) { $hookmanager->initHooks(array('fileslib')); @@ -196,9 +196,9 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil } } } - + $file_list = array_merge($file_list, $hookmanager->resArray); - + return $file_list; } @@ -219,7 +219,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0) { global $conf, $db; - + $sql=" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m, acl, position"; if ($mode) $sql.=", description"; $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files"; @@ -234,7 +234,7 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc $i = 0; while ($i < $num) { - $obj = $db->fetch_object($resql); + $obj = $db->fetch_object($resql); if ($obj) { preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg); @@ -258,7 +258,7 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc } $i++; } - + // Obtain a list of columns if (! empty($sortcriteria)) { @@ -270,7 +270,7 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc // Sort the data if ($sortorder) array_multisort($myarray, $sortorder, $file_list); } - + return $file_list; } else @@ -279,7 +279,7 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc return array(); } } - + /** * Fast compare of 2 files identified by their properties ->name, ->date and ->size @@ -460,10 +460,10 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, if (empty($srcfile)) return -1; if (empty($destfile)) $destfile=$srcfile; - + $destexists=dol_is_file($destfile); if (($destfile != $srcfile) && $destexists) return 0; - + $tmpdestfile=$destfile.'.tmp'; $newpathofsrcfile=dol_osencode($srcfile); @@ -481,17 +481,17 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); return -2; } - + dol_delete_file($tmpdestfile); - + // Create $newpathoftmpdestfile from $newpathofsrcfile $content=file_get_contents($newpathofsrcfile, 'r'); - + $content = make_substitutions($content, $arrayreplacement, null); - + file_put_contents($newpathoftmpdestfile, $content); @chmod($newpathoftmpdestfile, octdec($newmask)); - + // Rename $result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase); if (! $result) @@ -589,7 +589,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep $destexists=dol_is_dir($destfile); //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. - + if (! $destexists) { // We must set mask just before creating dir, becaause it can be set differently by dol_copy @@ -599,7 +599,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files dol_mkdir($destfile, '', decoct($dirmaskdec)); } - + $ossrcfile=dol_osencode($srcfile); $osdestfile=dol_osencode($destfile); @@ -639,7 +639,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep $result=$tmpresult; } if ($result < 0) break; - + } } closedir($dir_handle); @@ -656,10 +656,10 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep /** * Move a file into another name. - * Note: + * Note: * - This function differs from dol_move_uploaded_file, because it can be called in any context. * - Database of files is updated. - * - Test on antivirus is done only if param testvirus is provided and an antivirus was set. + * - Test on antivirus is done only if param testvirus is provided and an antivirus was set. * * @param string $srcfile Source file (can't be a directory. use native php @rename() to move a directory) * @param string $destfile Destination file (can't be a directory. use native php @rename() to move a directory) @@ -679,12 +679,12 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi $srcexists=dol_is_file($srcfile); $destexists=dol_is_file($destfile); - if (! $srcexists) + if (! $srcexists) { dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request."); return false; } - + if ($overwriteifexists || ! $destexists) { $newpathofsrcfile=dol_osencode($srcfile); @@ -695,7 +695,7 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi if ($testvirus) { $testvirusarray=dolCheckVirus($newpathofsrcfile); - if (count($testvirusarray)) + if (count($testvirusarray)) { dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING); return false; @@ -729,14 +729,14 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; - + $ecmfiletarget=new EcmFiles($db); $resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter); if ($resultecmtarget > 0) // An entry for target name already exists for target, we delete it, a new one will be created. { $ecmfiletarget->delete($user); } - + $ecmfile=new EcmFiles($db); $resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore); if ($resultecm > 0) // If an entry was found for src file, we use it to move entry @@ -745,7 +745,7 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi $rel_dir = dirname($rel_filetorenameafter); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; $resultecm = $ecmfile->update($user); @@ -756,7 +756,7 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi $rel_dir = dirname($rel_filetorenameafter); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file @@ -774,12 +774,12 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi { setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); } - + if ($resultecm > 0) $result=true; else $result = false; - } + } } - + if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; $newmaskdec=octdec($newmask); // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) @@ -809,14 +809,14 @@ function dol_unescapefile($filename) /** * Check virus into a file - * + * * @param string $src_file Source file to check * @return array Array of errors or empty array if not virus found */ function dolCheckVirus($src_file) { global $conf; - + if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) { if (! class_exists('AntiVir')) { @@ -837,10 +837,10 @@ function dolCheckVirus($src_file) /** * Make control on an uploaded file from an GUI page and move it to final destination. * If there is errors (virus found, antivir in error, bad filename), file is not moved. - * Note: + * Note: * - This function can be used only into a HTML page context. Use dol_move if you are outside. - * - Database of files is not updated. * - Test on antivirus is always done (if antivirus set). + * - Database of files is NOT updated. * * @param string $src_file Source full path filename ($_FILES['field']['tmp_name']) * @param string $dest_file Target full path filename ($_FILES['field']['name']) @@ -867,7 +867,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable $parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); $reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object); } - + if (empty($reshook)) { // If an upload error has been reported @@ -897,7 +897,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable break; } } - + // If we need to make a virus scan if (empty($disablevirusscan) && file_exists($src_file)) { @@ -908,7 +908,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray); } } - + // Security: // Disallow file with some extensions. We renamed them. // Car si on a mis le rep documents dans un rep de la racine web (pas bien), cela permet d'executer du code a la demande. @@ -916,7 +916,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable { $file_name.= '.noexe'; } - + // Security: // We refuse cache files/dirs, upload using .. and pipes into filenames. if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file)) @@ -924,7 +924,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING); return -1; } - + // Security: // On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers. if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file)) @@ -933,7 +933,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable return -2; } } - + if ($reshook < 0) // At least one blocking error returned by one hook { $errmsg = join(',', $hookmanager->errors); @@ -1005,7 +1005,7 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n dol_syslog("Refused to delete file ".$file, LOG_WARNING); return False; } - + if (empty($nohook)) { $hookmanager->initHooks(array('fileslib')); @@ -1042,16 +1042,16 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n { if ($nophperrors) $ok=@unlink($filename); else $ok=unlink($filename); - if ($ok) + if ($ok) { dol_syslog("Removed file ".$filename, LOG_DEBUG); - + // Delete entry into ecm database $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename); if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file { $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); - + dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); @@ -1079,7 +1079,7 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n if ($nophperrors) $ok=@unlink($file_osencoded); else $ok=unlink($file_osencoded); if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); - else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); + else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); } return $ok; @@ -1104,7 +1104,7 @@ function dol_delete_dir($dir,$nophperrors=0) dol_syslog("Refused to delete dir ".$dir, LOG_WARNING); return False; } - + $dir_osencoded=dol_osencode($dir); return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded)); } @@ -1340,7 +1340,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio global $db,$user,$conf,$langs; $res = 0; - + if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] { dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); @@ -1354,17 +1354,17 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $val = array($val); } } - + $nbfile = count($TFile['name']); - + for ($i = 0; $i < $nbfile; $i++) { // Define $destfull (path to file including filename) and $destfile (only filename) $destfull=$upload_dir . "/" . $TFile['name'][$i]; $destfile=$TFile['name'][$i]; - + $savingdocmask = dol_sanitizeFileName($savingdocmask); - + if ($savingdocmask) { $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); @@ -1378,26 +1378,26 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $destfile = $info['filename'].'.'.strtolower($info['extension']); $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); - + if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' { global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; - + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; - + // Generate thumbs. if (image_format_supported($destfull) == 1) { // Create thumbs // We can't use $object->addThumbs here because there is no $object known - + // Used on logon for example $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); // Create mini thumbs for image (Ratio is near 16/9) // Used on menu or for setup page for example $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); } - + // Update session if (empty($donotupdatesession)) { @@ -1406,18 +1406,18 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $formmail->trackid = $trackid; $formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]); } - + // Update table of files - if ($donotupdatesession) + if ($donotupdatesession) { $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); - + if (! preg_match('/[\\/]temp[\\/]/', $rel_dir)) // If not a tmp dir { $filename = basename($destfile); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $ecmfile->filepath = $rel_dir; @@ -1455,7 +1455,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } } - + } } elseif ($link) { require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; @@ -1478,7 +1478,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors'); } - + return $res; } @@ -1718,11 +1718,11 @@ function dol_compress_dir($inputdir, $outputfile, $mode="zip") if (class_exists('ZipArchive')) { $foundhandler=1; - + // Initialize archive object $zip = new ZipArchive(); $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE); - + // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator( @@ -1738,15 +1738,15 @@ function dol_compress_dir($inputdir, $outputfile, $mode="zip") // Get real and relative path for current file $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($inputdir) + 1); - + // Add current file to archive $zip->addFile($filePath, $relativePath); } } - + // Zip archive will be created only after closing object - $zip->close(); - + $zip->close(); + return 1; } } @@ -1793,7 +1793,7 @@ function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta * @param string $entity Restrict onto entity (0=no restriction) * @param User $fuser User object (forced) * @param string $refname Ref of object to check permission for external users (autodetect if not provided) - * @param string $mode Check permission for 'read' or 'write' + * @param string $mode Check permission for 'read' or 'write' * @return mixed Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name) * @see restrictedArea */ @@ -1801,7 +1801,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, { global $user, $conf, $db; global $dolibarr_main_data_root; - + if (! is_object($fuser)) $fuser=$user; if (empty($modulepart)) return 'ErrorBadParameter'; @@ -1823,7 +1823,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, { $lire='creer'; $read='write'; $download='upload'; } - + // Wrapping for some images if (($modulepart == 'mycompany' || $modulepart == 'companylogo') && !empty($conf->mycompany->dir_output)) { @@ -2022,7 +2022,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } $original_file=$conf->user->dir_output.'/'.$original_file; } - + // Wrapping for third parties else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) { @@ -2119,7 +2119,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } $original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; } - + // Wrapping for interventions else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output)) { @@ -2185,7 +2185,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } // Wrapping pour les commandes fournisseurs - else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) + else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) { if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) { @@ -2317,7 +2317,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } $original_file=$conf->resource->dir_output.'/'.$original_file; } - + // Wrapping pour les remises de cheques else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output)) { @@ -2361,14 +2361,14 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed=1; $original_file=$conf->fckeditor->dir_output.'/'.$original_file; } - + // Wrapping for miscellaneous medias files elseif ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) { $accessallowed=1; $original_file=$dolibarr_main_data_root.'/medias/'.$original_file; } - + // Wrapping for backups else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) { @@ -2416,7 +2416,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, // If modulepart=module Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart else { - if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. + if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. if ($fuser->admin) $accessallowed=1; // If user is admin // Define $accessallowed diff --git a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php index a58d00455e8..64d0da9b5fd 100644 --- a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php +++ b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php @@ -102,16 +102,10 @@ class doc_generic_contract_odt extends ModelePDFContract $form = new Form($this->db); $texte = $this->description.".
\n"; - $texte.= '
'; + $texte.= ''; $texte.= ''; $texte.= ''; $texte.= ''; - if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) - { - $texte.= ''; - $texte.= ''; - $texte.= ''; - } $texte.= ''; // List of directories area @@ -144,40 +138,21 @@ class doc_generic_contract_odt extends ModelePDFContract $texte.=$conf->global->CONTRACT_ADDON_PDF_ODT_PATH; $texte.= ''; $texte.= '
'; - $texte.= ''; + $texte.= ''; $texte.= '
'; // Scan directories if (count($listofdir)) { $texte.=$langs->trans("NumberOfModelFilesFound").': '.count($listoffiles).''; - - if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) - { - // Model for creation - $liste=ModelePDFContract::liste_modeles($this->db); - $texte.= '
'; - $texte.= ''; - $texte.= ''; - $texte.= '"; - - $texte.= ''; - $texte.= ''; - $texte.= '"; - $texte.= ''; - - $texte.= ''; - $texte.= '"; - $texte.= '
'.$langs->trans("DefaultModelPropalCreate").''; - $texte.= $form->selectarray('value2',$liste,$conf->global->CONTRACT_ADDON_PDF_ODT_DEFAULT); - $texte.= "
'.$langs->trans("DefaultModelPropalToBill").''; - $texte.= $form->selectarray('value3',$liste,$conf->global->CONTRACT_ADDON_PDF_ODT_TOBILL); - $texte.= "
'.$langs->trans("DefaultModelPropalClosed").''; - $texte.= $form->selectarray('value4',$liste,$conf->global->CONTRACT_ADDON_PDF_ODT_CLOSED); - $texte.= "
'; - } } + // Add select to upload a new template file. TODO Copy this feature on other admin pages. + $texte.= '
'.$langs->trans("UploadNewTemplate").' '; + $texte.= ''; + $texte.= ''; + $texte.= '
'; + $texte.= '
'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index fe547931908..5b213135878 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -48,6 +48,7 @@ InternalUsers=Internal users ExternalUsers=External users GUISetup=Display SetupArea=Setup area +UploadNewTemplate=Upload new template(s) FormToTestFileUploadForm=Form to test file upload (according to setup) IfModuleEnabled=Note: yes is effective only if module %s is enabled RemoveLock=Remove file %s if it exists to allow usage of the update tool. @@ -873,6 +874,7 @@ DictionaryProspectStatus=Prospection status DictionaryHolidayTypes=Types of leaves DictionaryOpportunityStatus=Opportunity status for project/lead SetupSaved=Setup saved +SetupNotSaved=Setup not saved BackToModuleList=Back to modules list BackToDictionaryList=Back to dictionaries list VATManagement=VAT Management diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 63b92bc6468..b3f2cc87d73 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -39,20 +39,23 @@ require_once '../lib/mymodule.lib.php'; $langs->load("mymodule@mymodule"); // Access control -if (! $user->admin) { - accessforbidden(); -} +if (! $user->admin) accessforbidden(); // Parameters $action = GETPOST('action', 'alpha'); + /* * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + + /* * View */ + $page_name = "MyModuleSetup"; llxHeader('', $langs->trans($page_name)); diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 5183eeb3382..172bdd9354c 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -74,6 +74,9 @@ $error = 0; * Actions */ +$nomessageinsetmoduleoptions=1; +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'setcodeproduct') { if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON",$value,'chaine',0,'',$conf->entity) > 0) @@ -87,36 +90,6 @@ if ($action == 'setcodeproduct') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - //setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - // message yet present at the bottom if($action) - //setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - if ($action == 'other' && GETPOST('value_PRODUIT_LIMIT_SIZE') >= 0) { $res = dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", GETPOST('value_PRODUIT_LIMIT_SIZE'),'chaine',0,'',$conf->entity); @@ -278,7 +251,7 @@ if ($action) } else { - setEventMessages($langs->trans("Error"), null, 'errors'); + setEventMessages($langs->trans("SetupNotError"), null, 'errors'); } } @@ -543,7 +516,7 @@ foreach ($dirmodels as $reldir) print '
'; print "
"; - + /* * Other conf */ @@ -598,7 +571,7 @@ print ''; // multiprix nombre de prix a proposer if (! empty($conf->global->PRODUIT_MULTIPRICES)) { - + print ''; print ''.$langs->trans("MultiPricesNumPrices").''; print ''; @@ -640,7 +613,7 @@ print ''; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { - + print ''; print ''.$langs->trans("NumberOfProductShowInSelect").''; print ''; @@ -681,7 +654,7 @@ print ''; // View product description in thirdparty language if (! empty($conf->global->MAIN_MULTILANGS)) { - + print ''; print ''.$langs->trans("ViewProductDescInThirdpartyLanguageAbility").''; print ''; @@ -723,7 +696,7 @@ if (! empty($conf->global->PRODUCT_CANVAS_ABILITY)) if ($conf->$module->enabled) { - + print ""; print $object->description; diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index fbcecf032cf..9e35ea77e0b 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -51,6 +51,8 @@ $type='project'; * Actions */ +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'setmainoptions') { if (GETPOST('PROJECT_USE_OPPORTUNITIES')) dolibarr_set_const($db, "PROJECT_USE_OPPORTUNITIES",GETPOST('PROJECT_USE_OPPORTUNITIES'),'chaine',0,'',$conf->entity); @@ -104,7 +106,7 @@ else if ($action == 'specimen') $project = new Project($db); $project->initAsSpecimen(); - + // Search template files $file=''; $classname=''; $filefound=0; $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); @@ -188,35 +190,6 @@ else if ($action == 'specimentask') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a model else if ($action == 'set') { @@ -414,7 +387,7 @@ foreach ($dirmodels as $reldir) if ($module->isEnabled()) { - + print ''.$module->name."\n"; print $module->info(); print ''; @@ -518,7 +491,7 @@ if (empty($conf->global->PROJECT_HIDE_TASKS)) if ($module->isEnabled()) { - + print ''.$module->name."\n"; print $module->info(); print ''; @@ -660,7 +633,7 @@ foreach ($dirmodels as $reldir) if ($modulequalified) { - + print ''; print (empty($module->name)?$name:$module->name); print "\n"; diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php index 63ba12197fd..5c84be25521 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -42,6 +42,9 @@ if (!$user->admin) accessforbidden(); /* * Actions */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + if ($action == 'setcodeclient') { if (dolibarr_set_const($db, "SOCIETE_CODECLIENT_ADDON",$value,'chaine',0,'',$conf->entity) > 0) @@ -101,35 +104,6 @@ if ($action == 'updateoptions') } } -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $post_size=count($_POST); - - $db->begin(); - - for($i=0;$i < $post_size;$i++) - { - if (array_key_exists('param'.$i,$_POST)) - { - $param=GETPOST("param".$i,'alpha'); - $value=GETPOST("value".$i,'alpha'); - if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - // Activate a document generator module if ($action == 'set') { From 07a6bb56642f06d32840e2bb2681a84e8b828296 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 12:26:17 +0200 Subject: [PATCH 38/66] More files to delete in migration --- htdocs/install/upgrade2.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 42c8f50632e..33cfd088ebe 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -413,10 +413,10 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) { // Migrate to add entity value into llx_societe_remise migrate_remise_entity($db,$langs,$conf); - + // Migrate to add entity value into llx_societe_remise_except migrate_remise_except_entity($db,$langs,$conf); - + // Reload modules (this must be always and only into last targeted version) $listofmodule=array( 'MAIN_MODULE_ACCOUNTING'=>'newboxdefonly', @@ -426,11 +426,11 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) 'MAIN_MODULE_PRINTING'=>'newboxdefonly', ); migrate_reload_modules($db,$langs,$conf,$listofmodule); - + // Reload menus (this must be always and only into last targeted version) migrate_reload_menu($db,$langs,$conf,$versionto); } - + // Can force activation of some module during migration with third paramater = MAIN_MODULE_XXX,MAIN_MODULE_YYY,... if ($enablemodules) { @@ -456,8 +456,8 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) // Actions for all versions (not in database) migrate_delete_old_files($db, $langs, $conf); migrate_delete_old_dir($db, $langs, $conf); - - + + dol_mkdir(DOL_DATA_ROOT.'/bank'); migrate_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits'); } @@ -3927,10 +3927,13 @@ function migrate_delete_old_files($db,$langs,$conf) DOL_DOCUMENT_ROOT.'/core/modules/mailings/kiwi.modules.php', DOL_DOCUMENT_ROOT.'/core/modules/facture/pdf_crabe.modules.php', DOL_DOCUMENT_ROOT.'/core/modules/facture/pdf_oursin.modules.php', - + DOL_DOCUMENT_ROOT.'/compta/facture/class/api_invoice.class.php', DOL_DOCUMENT_ROOT.'/commande/class/api_commande.class.php', - DOL_DOCUMENT_ROOT.'/user/class/api_user.class.php' + DOL_DOCUMENT_ROOT.'/user/class/api_user.class.php', + DOL_DOCUMENT_ROOT.'/product/class/api_product.class.php', + DOL_DOCUMENT_ROOT.'/societe/class/api_contact.class.php', + DOL_DOCUMENT_ROOT.'/societe/class/api_thirdparty.class.php' ); foreach ($filetodeletearray as $filetodelete) From 733d1caac6578da19a998b7a206e799c3ebdea9e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 12:37:16 +0200 Subject: [PATCH 39/66] Correct usage of parameter 'none' in GETPOST --- htdocs/admin/chequereceipts.php | 2 +- htdocs/admin/commande.php | 2 +- htdocs/admin/contract.php | 2 +- htdocs/admin/expedition.php | 2 +- htdocs/admin/expensereport.php | 2 +- htdocs/admin/facture.php | 2 +- htdocs/admin/fichinter.php | 2 +- htdocs/admin/livraison.php | 2 +- htdocs/admin/payment.php | 17 ++--------------- htdocs/admin/propal.php | 2 +- htdocs/admin/supplier_invoice.php | 2 +- htdocs/admin/supplier_order.php | 2 +- htdocs/admin/supplier_proposal.php | 2 +- htdocs/don/admin/donation.php | 4 ++-- htdocs/install/mysql/migration/repair.sql | 2 +- 15 files changed, 17 insertions(+), 30 deletions(-) diff --git a/htdocs/admin/chequereceipts.php b/htdocs/admin/chequereceipts.php index bc55eb4b9f6..f88dfc6f5a6 100644 --- a/htdocs/admin/chequereceipts.php +++ b/htdocs/admin/chequereceipts.php @@ -77,7 +77,7 @@ if ($action == 'setmod') if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT') { - $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 3f3c997b0d8..f4104e2007f 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -180,7 +180,7 @@ else if ($action == 'set_COMMANDE_DRAFT_WATERMARK') else if ($action == 'set_ORDER_FREE_TEXT') { - $freetext = GETPOST("ORDER_FREE_TEXT"); // No alpha here, we want exact string + $freetext = GETPOST("ORDER_FREE_TEXT",'none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "ORDER_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 206d9020022..7f9465b6f65 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -158,7 +158,7 @@ else if ($action == 'setmod') else if ($action == 'set_other') { - $freetext= GETPOST('CONTRACT_FREE_TEXT'); // No alpha here, we want exact string + $freetext= GETPOST('CONTRACT_FREE_TEXT','none'); // No alpha here, we want exact string $res1 = dolibarr_set_const($db, "CONTRACT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); $draft= GETPOST('CONTRACT_DRAFT_WATERMARK','alpha'); diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php index 6182538f820..12d0b7951d5 100644 --- a/htdocs/admin/expedition.php +++ b/htdocs/admin/expedition.php @@ -78,7 +78,7 @@ if ($action == 'updateMask') else if ($action == 'set_param') { - $freetext=GETPOST('SHIPPING_FREE_TEXT'); // No alpha here, we want exact string + $freetext=GETPOST('SHIPPING_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); if ($res <= 0) { diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php index 6c659181c4c..24aaeede5b4 100644 --- a/htdocs/admin/expensereport.php +++ b/htdocs/admin/expensereport.php @@ -168,7 +168,7 @@ else if ($action == 'setoptions') { $db->begin(); - $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT'); // No alpha here, we want exact string + $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT','none'); // No alpha here, we want exact string $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); $draft= GETPOST('EXPENSEREPORT_DRAFT_WATERMARK','alpha'); diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 115a685a3f2..df371639cde 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -206,7 +206,7 @@ if ($action == 'set_FACTURE_DRAFT_WATERMARK') if ($action == 'set_INVOICE_FREE_TEXT') { - $freetext = GETPOST('INVOICE_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('INVOICE_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "INVOICE_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/fichinter.php b/htdocs/admin/fichinter.php index 25c46164783..43ad7ad8178 100644 --- a/htdocs/admin/fichinter.php +++ b/htdocs/admin/fichinter.php @@ -160,7 +160,7 @@ else if ($action == 'setmod') else if ($action == 'set_FICHINTER_FREE_TEXT') { - $freetext= GETPOST('FICHINTER_FREE_TEXT'); // No alpha here, we want exact string + $freetext= GETPOST('FICHINTER_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "FICHINTER_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index ef73ec7a757..0136f6cc9d9 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -74,7 +74,7 @@ if ($action == 'updateMask') if ($action == 'set_DELIVERY_FREE_TEXT') { - $free=GETPOST('DELIVERY_FREE_TEXT'); // No alpha here, we want exact string + $free=GETPOST('DELIVERY_FREE_TEXT','none'); // No alpha here, we want exact string $res=dolibarr_set_const($db, "DELIVERY_FREE_TEXT",$free,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; diff --git a/htdocs/admin/payment.php b/htdocs/admin/payment.php index 88f2d8cd1c1..061b9d50f6a 100644 --- a/htdocs/admin/payment.php +++ b/htdocs/admin/payment.php @@ -71,7 +71,7 @@ if ($action == 'setmod') if ($action == 'setparams') { - $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string + $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); @@ -81,24 +81,11 @@ if ($action == 'setparams') { setEventMessages($langs->trans("Error"), null, 'errors'); } - - /* - $freetext = GETPOST('INVOICE_AUTO_FILLJS'); // No alpha here, we want exact string - - $res = dolibarr_set_const($db, "INVOICE_AUTO_FILLJS",$freetext,'chaine',0,'',$conf->entity); - - if (! $res > 0) $error++; - - if ($error) - { - setEventMessages($langs->trans("Error"), null, 'errors'); - }*/ - if (! $error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } - + } diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 9fa8dad0c0c..8acbf19f939 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -135,7 +135,7 @@ if ($action == 'set_PROPALE_DRAFT_WATERMARK') if ($action == 'set_PROPOSAL_FREE_TEXT') { - $freetext = GETPOST('PROPOSAL_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('PROPOSAL_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "PROPOSAL_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index 549bb93809b..17501cdb4f9 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -172,7 +172,7 @@ if ($action == 'addcat') if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') { - $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/supplier_order.php b/htdocs/admin/supplier_order.php index 55e4e4b3d07..13499af551a 100644 --- a/htdocs/admin/supplier_order.php +++ b/htdocs/admin/supplier_order.php @@ -169,7 +169,7 @@ else if ($action == 'addcat') else if ($action == 'set_SUPPLIER_ORDER_OTHER') { - $freetext = GETPOST('SUPPLIER_ORDER_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('SUPPLIER_ORDER_FREE_TEXT','none'); // No alpha here, we want exact string $doubleapproval = GETPOST('SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED','alpha'); $doubleapproval = price2num($doubleapproval ); diff --git a/htdocs/admin/supplier_proposal.php b/htdocs/admin/supplier_proposal.php index 210d601c33c..8c52ee83dda 100644 --- a/htdocs/admin/supplier_proposal.php +++ b/htdocs/admin/supplier_proposal.php @@ -132,7 +132,7 @@ if ($action == 'set_SUPPLIER_PROPOSAL_DRAFT_WATERMARK') if ($action == 'set_SUPPLIER_PROPOSAL_FREE_TEXT') { - $freetext = GETPOST('SUPPLIER_PROPOSAL_FREE_TEXT'); // No alpha here, we want exact string + $freetext = GETPOST('SUPPLIER_PROPOSAL_FREE_TEXT','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "SUPPLIER_PROPOSAL_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); diff --git a/htdocs/don/admin/donation.php b/htdocs/don/admin/donation.php index c8d8be2461d..2ca1cba1083 100644 --- a/htdocs/don/admin/donation.php +++ b/htdocs/don/admin/donation.php @@ -121,7 +121,7 @@ else if ($action == 'del') // Options if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') { - $account = GETPOST('DONATION_ACCOUNTINGACCOUNT'); // No alpha here, we want exact string + $account = GETPOST('DONATION_ACCOUNTINGACCOUNT','alpha'); $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT",$account,'chaine',0,'',$conf->entity); @@ -139,7 +139,7 @@ if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') if ($action == 'set_DONATION_MESSAGE') { - $freemessage = GETPOST('DONATION_MESSAGE'); // No alpha here, we want exact string + $freemessage = GETPOST('DONATION_MESSAGE','none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "DONATION_MESSAGE",$freemessage,'chaine',0,'',$conf->entity); diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 6ff7356847f..0277f7e996b 100755 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -28,7 +28,7 @@ --- Requests to clean corrupted database +-- Requests to clean corrupted data UPDATE llx_user set api_key = null where api_key = ''; From 7ad92c3a4d52c7dc0f456d92bed4756ba0efb079 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 13:32:20 +0200 Subject: [PATCH 40/66] Fix new generic substitution system --- htdocs/admin/contract.php | 2 +- htdocs/contrat/class/contrat.class.php | 23 +++++++------- htdocs/core/lib/functions.lib.php | 30 ++++++++++--------- htdocs/core/lib/pdf.lib.php | 17 ++++++----- .../contract/doc/pdf_strato.modules.php | 17 ++++++----- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 7f9465b6f65..e2f865f61f6 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -474,7 +474,7 @@ print ''.$langs->trans("Value").''; print "\n"; $var=true; -$substitutionarray=pdf_getSubstitutionArray($langs); +$substitutionarray=pdf_getSubstitutionArray($langs, array('objectamount')); $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation"); $htmltext = ''.$langs->trans("AvailableVariables").':
'; foreach($substitutionarray as $key => $val) $htmltext.=$key.'
'; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index db6464edb6a..b11e19d114b 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -46,7 +46,7 @@ class Contrat extends CommonObject public $fk_element='fk_contrat'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='contract'; - + /** * {@inheritdoc} */ @@ -530,7 +530,7 @@ class Contrat extends CommonObject $this->fin_validite = $this->db->jdate($result["fin_validite"]); $this->date_cloture = $this->db->jdate($result["date_cloture"]); - + $this->user_author_id = $result["fk_user_author"]; $this->commercial_signature_id = $result["fk_commercial_signature"]; @@ -613,7 +613,7 @@ class Contrat extends CommonObject $this->lines=array(); $pos = 0; - + // Selectionne les lignes contrats liees a un produit $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; $sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; @@ -1858,7 +1858,7 @@ class Contrat extends CommonObject $url = DOL_URL_ROOT.'/contrat/card.php?id='.$this->id; $picto = 'contract'; $label = ''; - + if ($user->rights->contrat->lire) { $label = ''.$langs->trans("ShowContract").''; $label .= '
'.$langs->trans('Ref').': '.$this->ref; @@ -1874,7 +1874,7 @@ class Contrat extends CommonObject $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); } } - + $linkclose=''; if (empty($notooltip) && $user->rights->contrat->lire) { @@ -1890,7 +1890,7 @@ class Contrat extends CommonObject $linkstart = ''; $linkend=''; - + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; $result.=$linkstart.$this->ref.$linkend; @@ -2225,7 +2225,11 @@ class Contrat extends CommonObject $line->total_ht=90; $line->total_ttc=107.64; // 90 * 1.196 $line->total_tva=17.64; - if ($num_prods > 0) + $line->date_ouverture = dol_now() - 200000; + $line->date_ouverture_prevue = dol_now() - 500000; + $line->date_fin_validite = dol_now() + 500000; + $line->date_cloture = dol_now() - 100000; + if ($num_prods > 0) { $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; @@ -2233,11 +2237,6 @@ class Contrat extends CommonObject $this->lines[$xnbp]=$line; $xnbp++; } - - $this->amount_ht = $xnbp*100; - $this->total_ht = $xnbp*100; - $this->total_tva = $xnbp*19.6; - $this->total_ttc = $xnbp*119.6; } /** diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a18b9e14110..dd4f720b378 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -239,7 +239,7 @@ function dol_shutdown() /** * Return value of a param into GET or POST supervariable. * Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder'] - * Note: The property $user->default_values is loaded by the main when loading the user. + * Note: The property $user->default_values is loaded by main.php when loading the user. * * @param string $paramname Name of parameter to found * @param string $check Type of check @@ -359,32 +359,34 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL) if (! empty($check)) { - // Replace vars like __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ... - if (! is_array($out)) + // Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters) + // Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ... + // We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text. + if (! is_array($out) && empty($_POST[$paramname])) { $maxloop=20; $loopnb=0; // Protection against infinite loop while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side. { $loopnb++; $newout = ''; - if ($reg[1] == 'DAY') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; } - elseif ($reg[1] == 'MONTH') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon']; } - elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; } + if ($reg[1] == 'DAY') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; } + elseif ($reg[1] == 'MONTH') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon']; } + elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; } elseif ($reg[1] == 'PREVIOUS_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'PREVIOUS_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); } - elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } - elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } - elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); } - elseif ($reg[1] == 'MYCOUNTRYID') + elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } + elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } + elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); } + elseif ($reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID') { $newout = $mysoc->country_id; } - elseif ($reg[1] == 'USERID') + elseif ($reg[1] == 'USER_ID' || $reg[1] == 'USERID') { $newout = $user->id; } - elseif ($reg[1] == 'SUPERVISORID') + elseif ($reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID') { $newout = $user->fk_user; } @@ -5020,7 +5022,7 @@ function dol_concatdesc($text1,$text2,$forxml=false) * * @param Translate $outputlangs Output language * @param int $onlykey Do not calculate heavy values of keys (performance enhancement when we need only the keys) - * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...) + * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'objectamount', 'date', 'user', ...) * @param Object $object Object for keys on object * @return array Array of substitutions */ @@ -5045,7 +5047,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id )); } - if (empty($exclude) || ! in_array('object', $exclude)) + if (empty($exclude) || ! in_array('objectamount', $exclude)) { if (is_object($object)) // For backward compatibility { diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8c48e2301e3..9220725dc8e 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -591,12 +591,13 @@ function pdf_pagehead(&$pdf,$outputlangs,$page_height) * Return array of possible substitutions for PDF content (without external module substitutions). * * @param Translate $outputlangs Output language + * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...) * @param Object $object Object * @return array Array of substitutions */ -function pdf_getSubstitutionArray($outputlangs, $object=null) +function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null) { - $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $exclude, $object); $substitutionarray['__FROM_NAME__']='__FROM_NAME__'; $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__'; return $substitutionarray; @@ -625,9 +626,9 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) elseif ($unit=='in') $k=72; // Make substitution - $substitutionarray=pdf_getSubstitutionArray($outputlangs,null); - complete_substitutions_array($substitutionarray,$outputlangs,null); - $text=make_substitutions($text,$substitutionarray,$outputlangs); + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null); + complete_substitutions_array($substitutionarray, $outputlangs, null); + $text=make_substitutions($text, $substitutionarray, $outputlangs); $text=$outputlangs->convToOutputCharset($text); $savx=$pdf->getX(); $savy=$pdf->getY(); @@ -854,12 +855,12 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass // Line of free text if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext)) { - $substitutionarray=pdf_getSubstitutionArray($outputlangs, $object); + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object); // More substitution keys $substitutionarray['__FROM_NAME__']=$fromcompany->name; $substitutionarray['__FROM_EMAIL__']=$fromcompany->email; - complete_substitutions_array($substitutionarray,$outputlangs,$object); - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs); $line.=$outputlangs->convToOutputCharset($newfreetext); } diff --git a/htdocs/core/modules/contract/doc/pdf_strato.modules.php b/htdocs/core/modules/contract/doc/pdf_strato.modules.php index 411b3deadf3..c06882fa121 100644 --- a/htdocs/core/modules/contract/doc/pdf_strato.modules.php +++ b/htdocs/core/modules/contract/doc/pdf_strato.modules.php @@ -294,22 +294,25 @@ class pdf_strato extends ModelePDFContract } else { $datere = $langs->trans("Unknown"); } - + $txtpredefinedservice=''; - $txtpredefinedservice = $objectligne->product_ref; + $txtpredefinedservice = $objectligne->product_label; if ($objectligne->product_label) { $txtpredefinedservice .= ' - '; $txtpredefinedservice .= $objectligne->product_label; } - $txt=''.dol_htmlentitiesbr($outputlangs->transnoentities("DateStartPlannedShort")." : ".$datei." - ".$outputlangs->transnoentities("DateEndPlanned")." : ".$datee,1,$outputlangs->charset_output).''; + $desc=dol_htmlentitiesbr($objectligne->desc,1); // Desc (not empty for free lines) + $txt=''; + $txt.=$outputlangs->transnoentities("Quantity").' : '.$objectligne->qty.' - '.$outputlangs->transnoentities("UnitPrice").' : '.price($objectligne->subprice).''; // Desc (not empty for free lines) $txt.='
'; - $txt.=''.dol_htmlentitiesbr($outputlangs->transnoentities("DateStartRealShort")." : ".$daters,1,$outputlangs->charset_output); - if ($objectligne->date_cloture) $txt.=dol_htmlentitiesbr(" - ".$outputlangs->transnoentities("DateEndRealShort")." : ".$datere,1,$outputlangs->charset_output).''; - $desc=dol_htmlentitiesbr($objectligne->desc,1); + $txt.=$outputlangs->transnoentities("DateStartPlannedShort")." : ".$datei." - ".$outputlangs->transnoentities("DateEndPlanned")." : ".$datee.''; + $txt.='
'; + $txt.=$outputlangs->transnoentities("DateStartRealShort")." : ".$daters.''; + if ($objectligne->date_cloture) $txt.=" - ".$outputlangs->transnoentities("DateEndRealShort")." : ''".$datere.''; - $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt,dol_concatdesc($txtpredefinedservice,$desc)), 0, 1, 0); + $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0); $nexY = $pdf->GetY() + 2; $pageposafter=$pdf->getPage(); From f4cdb6b25475ece60ec0bcf8bfcc82bc739d3e5e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Jun 2017 15:33:23 +0200 Subject: [PATCH 41/66] Fix month on 2 chars. Some setup return on 1 char only. More phpunit assert. --- htdocs/core/lib/functions.lib.php | 173 +++++++++++++++--------------- test/phpunit/DateLibTest.php | 39 ++++--- 2 files changed, 109 insertions(+), 103 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c678e0bc7df..0943bc1a7af 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -102,14 +102,14 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) /** * Get list of entity id to use * - * @param string $element Current element - * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', + * @param string $element Current element + * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', * 'product', 'productprice', 'stock', * 'propal', 'facture', 'facture_fourn', - * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', + * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', - * 'email_template', 'event', + * 'email_template', 'event', * @param int $shared 0=Return id of entity, 1=Return id entity + shared entities * @return mixed Entity id(s) to use */ @@ -121,7 +121,7 @@ function getEntity($element=false, $shared=0) if ($element == 'actioncomm') $element='agenda'; if ($element == 'fichinter') $element='intervention'; if ($element == 'categorie') $element='category'; - + if (is_object($mc)) { return $mc->getEntity($element, $shared); @@ -203,7 +203,7 @@ function getBrowserInfo($user_agent) elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name='opera'; $version=$reg[2]; } elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];\srv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) { $name='ie'; $version=end($reg); } // MS products at end elseif (preg_match('/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { $name='lynxlinks'; $version=$reg[4]; } - + if ($tablet) { $layout = 'tablet'; } elseif ($phone) { @@ -268,7 +268,7 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) { $tmp=dol_getdate(dol_now(), true); $out = $tmp['mon']; - } + } elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); @@ -280,7 +280,7 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) $out = $mysoc->country_id; } } - + switch ($check) { case 'int': @@ -337,13 +337,13 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) * This prefix is unique for instance and avoid conflict between multi-instances, * even when having two instances with one root dir or two instances in virtual servers * - * @param string $mode '' or 'email' + * @param string $mode '' or 'email' * @return string A calculated prefix */ function dol_getprefix($mode='') { global $conf; - + // If MAIL_PREFIX_FOR_EMAIL_ID is set and prefix is for email if ($mode == 'email' && ! empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) { @@ -425,15 +425,15 @@ function dol_buildpath($path, $type=0) if ($type == 1) $res = DOL_URL_ROOT.'/'.$path; // Standard value if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path; // Standard value if ($type == 3) $res = DOL_URL_ROOT.'/'.$path; - + foreach ($conf->file->dol_document_root as $key => $dirroot) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...) { - if ($key == 'main') + if ($key == 'main') { if ($type == 3) { global $dolibarr_main_url_root; - + // 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 @@ -460,12 +460,12 @@ function dol_buildpath($path, $type=0) if ($type == 3) { global $dolibarr_main_url_root; - + // 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 - + $res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).$conf->file->dol_url_root[$key].'/'.$path; // Test on start with http is for old conf syntax } break; @@ -732,13 +732,13 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' throw new Exception('Incorrect log level'); } if ($level > $conf->global->SYSLOG_LEVEL) return; - + // If adding log inside HTML page is required if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) // MAIN_LOGTOHTML kept for backward compatibility { $conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message; } - + //TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output // If enable html log tag enabled and url parameter log defined, we show output log on HTML comments if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"])) @@ -747,7 +747,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' print $message."\n"; print "Log end -->\n"; } - + $data = array( 'message' => $message, 'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false), @@ -755,7 +755,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' 'user' => ((is_object($user) && $user->id) ? $user->login : false), 'ip' => false ); - + if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR']; // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR']; @@ -814,7 +814,7 @@ function dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $pi global $conf, $langs, $hookmanager; if ($notab == -1) $notab = 0; // For better compatiblity with modules for 6.0 - + $out="\n".'
'."\n"; // Show title @@ -944,7 +944,7 @@ function dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $pi { $out = $hookmanager->resPrint; } - + return $out; } @@ -1003,7 +1003,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if ($object->element == 'member') $modulepart='memberphoto'; if ($object->element == 'user') $modulepart='userphoto'; if ($object->element == 'product') $modulepart='product'; - + if ($object->element == 'product') { $width=80; $cssclass='photoref'; @@ -1011,7 +1011,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r $maxvisiblephotos=(isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO)?$conf->global->PRODUCT_MAX_VISIBLE_PHOTO:5); if ($conf->browser->phone) $maxvisiblephotos=1; if ($showimage) $morehtmlleft.='
'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',$maxvisiblephotos,0,0,0,$width,0).'
'; - else + else { if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) { $nophoto=''; @@ -1023,11 +1023,11 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r } } } - else + else { - if ($showimage) + if ($showimage) { - if ($modulepart != 'unknown') + if ($modulepart != 'unknown') { $phototoshow = $form->showphoto($modulepart,$object,0,0,0,'photoref','small',1,0,$maxvisiblephotos); if ($phototoshow) @@ -1040,7 +1040,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r elseif ($conf->browser->layout != 'phone') // Show No photo link (picto of pbject) { $morehtmlleft.='
'; - if ($object->element == 'action') + if ($object->element == 'action') { $cssclass='photorefcenter'; $nophoto=img_picto('', 'title_agenda', '', false, 1); @@ -1061,7 +1061,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if ($showbarcode) $morehtmlleft.='
'.$form->showbarcode($object).'
'; if ($object->element == 'societe' && ! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { $morehtmlstatus.=ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased'); - } + } elseif ($object->element == 'product') { //$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') '; @@ -1081,39 +1081,39 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r elseif ($object->element == 'facture' || $object->element == 'invoice' || $object->element == 'invoice_supplier') { $tmptxt=$object->getLibStatut(6, $object->totalpaye); - if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); + if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); $morehtmlstatus.=$tmptxt; } elseif ($object->element == 'chargesociales') { $tmptxt=$object->getLibStatut(6, $object->totalpaye); - if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); + if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); $morehtmlstatus.=$tmptxt; } elseif ($object->element == 'loan') { $tmptxt=$object->getLibStatut(6, $object->totalpaye); - if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); + if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye); $morehtmlstatus.=$tmptxt; } - elseif ($object->element == 'contrat') + elseif ($object->element == 'contrat') { if ($object->statut==0) $morehtmlstatus.=$object->getLibStatut(2); else $morehtmlstatus.=$object->getLibStatut(4); } else { // Generic case $tmptxt=$object->getLibStatut(6); - if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5); + if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5); $morehtmlstatus.=$tmptxt; } if (! empty($object->name_alias)) $morehtmlref.='
'.$object->name_alias.'
'; // For thirdparty - + if ($object->element == 'product' || $object->element == 'bank_account') { if(! empty($object->label)) $morehtmlref.='
'.$object->label.'
'; } - if ($object->element != 'product' && $object->element != 'bookmark') + if ($object->element != 'product' && $object->element != 'bookmark') { $morehtmlref.='
'; $morehtmlref.=$object->getBannerAddress('refaddress',$object); @@ -1125,7 +1125,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r $morehtmlref.=$langs->trans("TechnicalID").': '.$object->id; $morehtmlref.='
'; } - + print '
'; print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright); print '
'; @@ -1301,9 +1301,9 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e $reduceformat=(! empty($conf->dol_optimize_smallscreen) && in_array($format,array('day','dayhour')))?1:0; $formatwithoutreduce = preg_replace('/reduceformat/','',$format); if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat=1; } // so format 'dayreduceformat' is processed like day - + // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default. - // TODO Add format daysmallyear and dayhoursmallyear + // TODO Add format daysmallyear and dayhoursmallyear if ($format == 'day') $format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short); else if ($format == 'hour') $format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short); else if ($format == 'hourduration') $format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration); @@ -1375,7 +1375,8 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e if (preg_match('/__b__/i',$format)) { // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. - $month=adodb_strftime('%m',$time+$offsettz+$offsetdst); // TODO Remove this + $month=adodb_strftime('%m',$time+$offsettz+$offsetdst); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring. + $month=sprintf("%02d", $month); // $month may be return with format '06' on some installation and '6' on other, so we force it to '06'. if ($encodetooutput) { $monthtext=$outputlangs->transnoentities('Month'.$month); @@ -1805,7 +1806,7 @@ function dol_print_phone($phone,$countrycode='',$cid=0,$socid=0,$addlink='',$sep $newphone=($separ!=''?'(':'').substr($newphone,0,3).($separ!=''?')':'').$separ.substr($newphone,3,3).($separ!=''?'-':'').substr($newphone,6,4); } } - + if (! empty($addlink)) // Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set) { if (! empty($conf->browser->phone) || (! empty($conf->clicktodial->enabled) && ! empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) // If phone or option for, we use link of phone @@ -1935,7 +1936,7 @@ function dol_user_country() * @param int $mode thirdparty|contact|member|other * @param int $id Id of object * @param int $noprint No output. Result is the function return - * @param string $charfornl Char to use instead of nl2br. '' means we use a standad nl2br. + * @param string $charfornl Char to use instead of nl2br. '' means we use a standad nl2br. * @return string|void Nothing if noprint is 0, formatted address if noprint is 1 * @see dol_format_address */ @@ -1956,7 +1957,7 @@ function dol_print_address($address, $htmlid, $mode, $id, $noprint=0, $charfornl { if (empty($charfornl)) $out.=nl2br($address); else $out.=preg_replace('/[\r\n]+/', $charfornl, $address); - + $showgmap=$showomap=0; // TODO Add a hook here @@ -2084,7 +2085,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie', print '
'.$langs->trans("NotEnoughDataYet").'
'; return; } - + if (empty($conf->use_javascript_ajax)) return; $jsgraphlib='flot'; $datacolor=array(); @@ -2253,7 +2254,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo global $conf; if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string; - + if (empty($stringencoding)) $stringencoding='UTF-8'; // reduce for small screen if ($conf->dol_optimize_smallscreen==1 && $display==1) $size = round($size/3); @@ -3206,7 +3207,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', * @param string $options More parameters for links ('' by default, does not include sortfield neither sortorder) * @param string $sortfield Field to sort on ('' by default) * @param string $sortorder Order to sort ('' by default) - * @param string $center String in the middle ('' by default). We often find here string $massaction comming from $form->selectMassAction() + * @param string $center String in the middle ('' by default). We often find here string $massaction comming from $form->selectMassAction() * @param int $num Number of records found by select with limit+1 * @param int|string $totalnboflines Total number of records/lines for all pages (if known). Use a negative value of number to not show number. Use '' if unknown. * @param string $picto Icon to use before title (should be a 32x32 transparent png file) @@ -3220,11 +3221,11 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=-1, $hideselectlimit=0) { global $conf,$langs; - + $savlimit = $limit; $savtotalnboflines = $totalnboflines; $totalnboflines=abs($totalnboflines); - + if ($picto == 'setup') $picto='title_setup.png'; if (($conf->browser->name == 'ie') && $picto=='title_generic.png') $picto='title.gif'; if ($limit < 0) $limit = $conf->liste_limit; @@ -3237,7 +3238,7 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so $nextpage = 0; } //print 'totalnboflines='.$totalnboflines.'-savlimit='.$savlimit.'-limit='.$limit.'-num='.$num.'-nextpage='.$nextpage; - + print "\n"; print "\n"; print ''; @@ -3338,7 +3339,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee //$pagesizechoices.=',0:'.$langs->trans("All"); // Not yet supported //$pagesizechoices.=',2:2'; if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES; - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // EMail - + print ''."\n"; @@ -331,19 +340,19 @@ if (GETPOST("source") == 'order' && $valid) $fulltag=dol_string_unaccent($fulltag); // Creditor - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // EMail - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // EMail - + print ''."\n"; // Debitor - + print ''."\n"; // Quantity - + $label=$langs->trans("Quantity"); $qty=1; $duration=''; @@ -616,7 +625,7 @@ if (GETPOST("source") == 'contractline' && $valid) print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // EMail - + print ''."\n"; // Debitor - + print ''."\n"; // Last subscription amount - + print ''."\n"; @@ -725,7 +734,7 @@ if (GETPOST("source") == 'membersubscription' && $valid) } // Amount - + print ''."\n"; // Tag - + print ''."\n"; // EMail - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Quantity - + $label=$langs->trans("Quantity"); $qty=1; $duration=''; @@ -843,7 +852,7 @@ if (GETPOST("source") == 'contractline') print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Last subscription amount - + print ''."\n"; @@ -972,7 +981,7 @@ if (GETPOST("source") == 'membersubscription') } // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Quantity - + $label=$langs->trans("Quantity"); $qty=1; $duration=''; @@ -760,7 +770,7 @@ if (GETPOST("source") == 'contractline') print ''."\n"; // Amount - + print ''."\n"; // Tag - + print ''."\n"; // Debitor - + print ''."\n"; // Last subscription amount - + print ''."\n"; @@ -889,7 +900,7 @@ if (GETPOST("source") == 'membersubscription') } // Amount - + print ''."\n"; // Tag - + print ''; print ''; print '\n"; @@ -713,31 +725,33 @@ if ($id > 0) if (empty($reshook)) { print '
'; - + // Edit if ($user->rights->loan->write) { + print ''.$langs->trans('CreateCalcSchedule').''; + print ''.$langs->trans("Modify").''; } - + // Emit payment if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) { print ''.$langs->trans("DoPayment").''; } - + // Classify 'paid' if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) { print ''.$langs->trans("ClassifyPaid").''; } - + // Delete if ($user->rights->loan->delete) { print ''.$langs->trans("Delete").''; } - + print "
"; } } diff --git a/htdocs/loan/class/loanschedule.class.php b/htdocs/loan/class/loanschedule.class.php new file mode 100644 index 00000000000..1e519e6a2af --- /dev/null +++ b/htdocs/loan/class/loanschedule.class.php @@ -0,0 +1,526 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/loan/class/loanschedule.class.php + * \ingroup facture + * \brief File of class to manage schedule of loans + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** \class LoanSchedule + * \brief Class to manage Schedule of loans + */ +class LoanSchedule extends CommonObject +{ + public $element='loan_schedule'; //!< Id that identify managed objects + public $table_element='loan_schedule'; //!< Name of table without prefix where object is stored + + var $fk_loan; + var $datec=''; + var $tms=''; + var $datep=''; + var $amounts=array(); // Array of amounts + var $amount_capital; // Total amount of payment + var $amount_insurance; + var $amount_interest; + var $fk_typepayment; + var $num_payment; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + var $lines=array(); + + /** + * @deprecated + * @see amount, amounts + */ + var $total; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Create payment of loan into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @return int <0 if KO, id of payment if OK + */ + function create($user) + { + global $conf, $langs; + + $error=0; + + $now=dol_now(); + + // Validate parameters + if (! $this->datepaid) + { + $this->error='ErrorBadValueForParameter'; + return -1; + } + + // Clean parameters + if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital?$this->amount_capital:0); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance?$this->amount_insurance:0); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest?$this->amount_interest:0); + if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); + if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); + + $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) { + $this->errors[]='step1'; + return -1; // Negative amounts are accepted for reject prelevement but not null + } + + + $this->db->begin(); + + if ($totalamount != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; + $sql.= " fk_typepayment, fk_user_creat, fk_bank)"; + $sql.= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',"; + $sql.= " '".$this->db->idate($this->datepaid)."',"; + $sql.= " ".$this->amount_capital.","; + $sql.= " ".$this->amount_insurance.","; + $sql.= " ".$this->amount_interest.","; + $sql.= " ".$this->fk_typepayment.", "; + $sql.= " ".$user->id.","; + $sql.= " ".$this->fk_bank . ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan"); + } + else + { + $this->error=$this->db->lasterror(); + $error++; + } + + } + + if ($totalamount != 0 && ! $error) + { + $this->amount_capital=$totalamount; + $this->total=$totalamount; // deprecated + $this->db->commit(); + return $this->id; + } + else + { + $this->errors[]=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_loan,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount_capital,"; + $sql.= " t.amount_insurance,"; + $sql.= " t.amount_interest,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; + $sql.= " t.note_private,"; + $sql.= " t.note_public,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; + $sql.= ' b.fk_account'; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX.$this->table_element." as t)"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_loan = $obj->fk_loan; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount_capital = $obj->amount_capital; + $this->amount_insurance = $obj->amount_insurance; + $this->amount_interest = $obj->amount_interest; + $this->fk_typepayment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_libelle = $obj->type_libelle; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); + if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); + if (isset($this->note_private)) $this->note_private=trim($this->note_private); + if (isset($this->note_public)) $this->note_public=trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + + $sql.= " fk_loan=".(isset($this->fk_loan)?$this->fk_loan:"null").","; + $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").","; + $sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").","; + $sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").","; + $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; + $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; + $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").","; + $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").","; + $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $this->db->begin(); + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + function calc_mens($capital,$rate,$nbterm) + { + $result=''; + + if (!empty($capital)&&!empty($rate)&&!empty($nbterm)) + { + $result=($capital*($rate/12))/(1-pow((1+($rate/12)),($nbterm*-1))); + } + + return $result; + } + + + /** + * Load all object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetchall($loan) + { + global $langs; + + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_loan,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount_capital,"; + $sql.= " t.amount_insurance,"; + $sql.= " t.amount_interest,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; + $sql.= " t.note_private,"; + $sql.= " t.note_public,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql.= " WHERE t.fk_loan = ".$loan; + + dol_syslog(get_class($this)."::fetchall", LOG_DEBUG); + $resql=$this->db->query($sql); + + if ($resql) + { + while($obj = $this->db->fetch_object($resql)) + { + $line = New LoanSchedule($this->db); + $line->id = $obj->rowid; + $line->ref = $obj->rowid; + + $line->fk_loan = $obj->fk_loan; + $line->datec = $this->db->jdate($obj->datec); + $line->tms = $this->db->jdate($obj->tms); + $line->datep = $this->db->jdate($obj->datep); + $line->amount_capital = $obj->amount_capital; + $line->amount_insurance = $obj->amount_insurance; + $line->amount_interest = $obj->amount_interest; + $line->fk_typepayment = $obj->fk_typepayment; + $line->num_payment = $obj->num_payment; + $line->note_private = $obj->note_private; + $line->note_public = $obj->note_public; + $line->fk_bank = $obj->fk_bank; + $line->fk_user_creat = $obj->fk_user_creat; + $line->fk_user_modif = $obj->fk_user_modif; + + $this->lines[] = $line; + } + $this->db->free($resql); + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + + function trans_paiment() + { + require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + + $toinsert = array(); + + $sql = "SELECT l.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."loan as l "; + $sql.= " WHERE l.paid = 0"; + $resql=$this->db->query($sql); + + if($resql){ + while($obj = $this->db->fetch_object($resql)){ + $lastrecorded = $this->lastpaiment($obj->rowid); + $toinsert = $this->paimenttorecord($obj->rowid, $lastrecorded); + if(count($toinsert)>0){ + foreach ($toinsert as $echid){ + $this->db->begin(); + $sql = "INSERT INTO " .MAIN_DB_PREFIX . "payment_loan "; + $sql.= "(fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif) "; + $sql.= "SELECT fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif FROM " . MAIN_DB_PREFIX . "loan_schedule WHERE rowid =" .$echid; + $res=$this->db->query($sql); + if($res){ + $this->db->commit(); + }else { + $this->db->rollback(); + } + } + } + } + } + } + + + function lastpaiment($loan) + { + $sql = "SELECT p.datep"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p "; + $sql.= " WHERE p.fk_loan = " . $loan; + $sql.= " ORDER BY p.datep DESC "; + $sql.= " LIMIT 1 "; + + $resql=$this->db->query($sql); + + if($resql){ + $obj = $this->db->fetch_object($resql); + return $this->db->jdate($obj->datep); + }else{ + return -1; + } + } + + function paimenttorecord($loan,$datemax) + { + $sql = "SELECT p.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p "; + $sql.= " WHERE p.fk_loan = " . $loan; + if(!empty($datemax)){ $sql.= " AND p.datep > '" . $this->db->idate($datemax) ."'";} + $sql.= " AND p.datep <= '" . $this->db->idate(dol_now()). "'"; + + + $resql=$this->db->query($sql); + + if($resql){ + while($obj = $this->db->fetch_object($resql)) + { + $result[] = $obj->rowid; + + } + + } + + return $result; + } +} + diff --git a/htdocs/loan/createschedule.php b/htdocs/loan/createschedule.php new file mode 100644 index 00000000000..0d15d1b2de6 --- /dev/null +++ b/htdocs/loan/createschedule.php @@ -0,0 +1,208 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/loan/createecheancier.php + * \ingroup loan + * \brief Schedule card + */ + +require '../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php'; + +global $user; + +$loanid = GETPOST('loanid', 'int'); +$action = GETPOST('action'); + +$object = new Loan($db); +$object->fetch($loanid); + +$langs->load('loan'); + +if ($action == 'createecheancier') { + + $i=1; + while($i <$object->nbterm+1){ + + $date = GETPOST('hi_date'.$i,'int'); + $mens = GETPOST('mens'.$i); + $int = GETPOST('hi_interets'.$i); + + $echeance = new LoanSchedule($db); + + $echeance->fk_loan = $object->id; + $echeance->datec = dol_now(); + $echeance->tms = dol_now(); + $echeance->datepaid = $date; + $echeance->amount_capital = $mens-$int; + $echeance->amount_insurance = 0; + $echeance->amount_interest = $int; + $echeance->fk_typepayment = 3; + $echeance->fk_bank = 1; + $echeance->fk_user_creat = $user->id; + $echeance->fk_user_modif = $user->id; + $result=$echeance->create($user); + if ($result<0) { + setEventMessages(null, $echeance->errors,'errors'); + } + $i++; + } +} + +if ($action == 'updateecheancier') { + + $i=1; + while($i <$object->nbterm+1){ + + $mens = GETPOST('mens'.$i); + $int = GETPOST('hi_interets'.$i); + $id = GETPOST('hi_rowid'.$i); + $echeance = new LoanSchedule($db); + $echeance->fetch($id); + $echeance->tms = dol_now(); + $echeance->amount_capital = $mens-$int; + $echeance->amount_insurance = 0; + $echeance->amount_interest = $int; + $echeance->fk_user_modif = $user->id; + $result= $echeance->update($user,0); + if ($result<0) { + setEventMessages(null, $echeance->errors,'errors'); + } + $i++; + } +} + +$echeance = new LoanSchedule($db); +$echeance->fetchall($object->id); + +top_htmlhead('', ''); +$var = ! $var; + + +?> + +'; +print ''; +print ''; +if(count($echeance->lines)>0){ + print ''; +}else{ + print ''; +} +print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -286,7 +295,7 @@ if (! GETPOST("source") && $valid) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -294,7 +303,7 @@ if (! GETPOST("source") && $valid) print '
'.$langs->trans("YourEMail"); print ' ('.$langs->trans("ToComplete").')'; print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$order->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -352,7 +361,7 @@ if (GETPOST("source") == 'order' && $valid) print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -372,7 +381,7 @@ if (GETPOST("source") == 'order' && $valid) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -380,7 +389,7 @@ if (GETPOST("source") == 'order' && $valid) print '
'.$langs->trans("YourEMail"); print ' ('.$langs->trans("ToComplete").')'; $email=$order->thirdparty->email; @@ -419,19 +428,19 @@ if (GETPOST("source") == 'invoice' && $valid) $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$invoice->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -440,7 +449,7 @@ if (GETPOST("source") == 'invoice' && $valid) print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -460,7 +469,7 @@ if (GETPOST("source") == 'invoice' && $valid) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -468,7 +477,7 @@ if (GETPOST("source") == 'invoice' && $valid) print '
'.$langs->trans("YourEMail"); print ' ('.$langs->trans("ToComplete").')'; $email=$invoice->thirdparty->email; @@ -553,19 +562,19 @@ if (GETPOST("source") == 'contractline' && $valid) if (GETPOST('qty')) $qty=GETPOST('qty'); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$contract->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; if ($contractline->fk_product) { @@ -588,7 +597,7 @@ if (GETPOST("source") == 'contractline' && $valid) print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -636,7 +645,7 @@ if (GETPOST("source") == 'contractline' && $valid) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -644,7 +653,7 @@ if (GETPOST("source") == 'contractline' && $valid) print '
'.$langs->trans("YourEMail"); print ' ('.$langs->trans("ToComplete").')'; $email=$contract->thirdparty->email; @@ -684,14 +693,14 @@ if (GETPOST("source") == 'membersubscription' && $valid) $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Member"); print ''; if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; @@ -699,7 +708,7 @@ if (GETPOST("source") == 'membersubscription' && $valid) print ''; // Object - + $text=''.$langs->trans("PaymentSubscription").''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -710,13 +719,13 @@ if (GETPOST("source") == 'membersubscription' && $valid) if ($member->last_subscription_date || $member->last_subscription_amount) { // Last subscription date - + print '
'.$langs->trans("LastSubscriptionDate"); print ''.dol_print_date($member->last_subscription_date,'day'); print '
'.$langs->trans("LastSubscriptionAmount"); print ''.price($member->last_subscription_amount); print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -749,7 +758,7 @@ if (GETPOST("source") == 'membersubscription' && $valid) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -757,7 +766,7 @@ if (GETPOST("source") == 'membersubscription' && $valid) print '
'.$langs->trans("YourEMail"); $email=$member->email; $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:'')); diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 788321b6212..cdfaaa2afc6 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -156,10 +156,10 @@ $urlko=preg_replace('/&$/','',$urlko); // Remove last & if (! empty($conf->paypal->enabled)) { $langs->load("paypal"); - + require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php'; require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php'; - + $PAYPAL_API_OK=""; if ($urlok) $PAYPAL_API_OK=$urlok; $PAYPAL_API_KO=""; @@ -194,7 +194,7 @@ if (! empty($conf->paypal->enabled)) $token = $conf->global->PAYPAL_SECURITY_TOKEN; } if ($SECUREKEY != $token) $valid=false; - + if (! $valid) { print '
Bad value for key.
'; @@ -202,16 +202,16 @@ if (! empty($conf->paypal->enabled)) exit; } } - + $validpaymentmethod['paypal']='valid'; } if (! empty($conf->paybox->enabled)) { $langs->load("paybox"); - + // TODO - + $validpaymentmethod['paybox']='valid'; } @@ -256,10 +256,10 @@ if (empty($validpaymentmethod)) accessforbidden('', 0, 0, 1); if ($action == 'dopayment') { if ($paymentmethod == 'paypal') - { + { $PAYPAL_API_PRICE=price2num(GETPOST("newamount"),'MT'); $PAYPAL_PAYMENT_TYPE='Sale'; - + $origfulltag=GETPOST("fulltag",'alpha'); $shipToName=GETPOST("shipToName"); $shipToStreet=GETPOST("shipToStreet"); @@ -271,24 +271,24 @@ if ($action == 'dopayment') $phoneNum=GETPOST("phoneNum"); $email=GETPOST("email"); $desc=GETPOST("desc"); - + $mesg=''; if (empty($PAYPAL_API_PRICE) || ! is_numeric($PAYPAL_API_PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); //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")); - + //var_dump($_POST); if (empty($mesg)) { dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG); - + // Other $PAYPAL_API_DEVISE="USD"; //if ($currency == 'EUR') $PAYPAL_API_DEVISE="EUR"; //if ($currency == 'USD') $PAYPAL_API_DEVISE="USD"; if (! empty($currency)) $PAYPAL_API_DEVISE=$currency; - + dol_syslog("Submit Paypal form", LOG_DEBUG); dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG); //dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG); // No password into log files @@ -308,15 +308,15 @@ if ($action == 'dopayment') dol_syslog("phoneNum: $phoneNum", LOG_DEBUG); dol_syslog("email: $email", LOG_DEBUG); dol_syslog("desc: $desc", LOG_DEBUG); - + dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO //$_SESSION["PaymentType"]=$PAYPAL_PAYMENT_TYPE; //$_SESSION["currencyCodeType"]=$PAYPAL_API_DEVISE; //$_SESSION["Payment_Amount"]=$PAYPAL_API_PRICE; - + // A redirect is added if API call successfull print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG); - + exit; } } @@ -335,19 +335,28 @@ $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', ''))) +{ + $langs->load("errors"); + dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); + llxFooter(); + $db->close(); + exit; +} if (! empty($conf->paypal->enabled)) { - if (! empty($PAYPAL_API_SANDBOX)) - { - dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); - } - // Common variables $creditor=$mysoc->name; $paramcreditor='PAYPAL_CREDITOR_'.$suffix; if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; else if (! empty($conf->global->PAYPAL_CREDITOR)) $creditor=$conf->global->PAYPAL_CREDITOR; + + if (! empty($PAYPAL_API_SANDBOX)) + { + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); + } } print ''."\n"; @@ -442,14 +451,14 @@ if (! GETPOST("source")) $fulltag=$tag; // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -469,7 +478,7 @@ if (! GETPOST("source")) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -507,26 +516,26 @@ if (GETPOST("source") == 'order') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$order->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -535,7 +544,7 @@ if (GETPOST("source") == 'order') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -555,7 +564,7 @@ if (GETPOST("source") == 'order') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -617,26 +626,26 @@ if (GETPOST("source") == 'invoice') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$invoice->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -645,7 +654,7 @@ if (GETPOST("source") == 'invoice') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -665,7 +674,7 @@ if (GETPOST("source") == 'invoice') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -745,7 +754,7 @@ if (GETPOST("source") == 'contractline') { $product=new Product($db); $result=$product->fetch($contractline->fk_product); - + // We define price for product (TODO Put this in a method in product class) if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -759,7 +768,7 @@ if (GETPOST("source") == 'contractline') $pu_ttc = $product->price_ttc; $price_base_type = $product->price_base_type; } - + $amount=$pu_ttc; if (empty($amount)) { @@ -780,19 +789,19 @@ if (GETPOST("source") == 'contractline') if (GETPOST('qty')) $qty=GETPOST('qty'); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$contract->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; if ($contractline->fk_product) { @@ -815,7 +824,7 @@ if (GETPOST("source") == 'contractline') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -863,7 +872,7 @@ if (GETPOST("source") == 'contractline') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -925,20 +934,20 @@ if (GETPOST("source") == 'membersubscription') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Member"); print ''; if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; @@ -946,7 +955,7 @@ if (GETPOST("source") == 'membersubscription') print ''; // Object - + $text=''.$langs->trans("PaymentSubscription").''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -957,13 +966,13 @@ if (GETPOST("source") == 'membersubscription') if ($member->last_subscription_date || $member->last_subscription_amount) { // Last subscription date - + print '
'.$langs->trans("LastSubscriptionDate"); print ''.dol_print_date($member->last_subscription_date,'day'); print '
'.$langs->trans("LastSubscriptionAmount"); print ''.price($member->last_subscription_amount); print '
'.$langs->trans("Amount"); if (empty($amount)) { @@ -1001,7 +1010,7 @@ if (GETPOST("source") == 'membersubscription') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -1051,11 +1060,11 @@ if ($action != 'dopayment') if ($found && ! $error) // We are in a management option and no error { // Buttons for all payments registration methods - + if (! empty($conf->paypal->enabled)) { if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral'; - + if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') { print '
'; @@ -1065,13 +1074,13 @@ if ($action != 'dopayment') print '
'; } } - + if (! empty($conf->paybox->enabled)) { - - + + } - + // TODO Other methods } else diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index 6de2cb8a441..65fbfbd38a7 100644 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -265,17 +265,27 @@ $conf->dol_hide_leftmenu=1; llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); -if (! empty($conf->global->PAYPAL_API_SANDBOX)) -{ - dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); -} - // Common variables $creditor=$mysoc->name; $paramcreditor='PAYPAL_CREDITOR_'.$suffix; if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; else if (! empty($conf->global->PAYPAL_CREDITOR)) $creditor=$conf->global->PAYPAL_CREDITOR; +// Check link validity +if (! empty($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)); + llxFooter(); + $db->close(); + exit; +} + +if (! empty($conf->global->PAYPAL_API_SANDBOX)) +{ + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); +} + print ''."\n"; print '
'."\n"; print ''."\n"; @@ -359,14 +369,14 @@ if (! GETPOST("source")) $fulltag=$tag; // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -386,7 +396,7 @@ if (! GETPOST("source")) print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -424,26 +434,26 @@ if (GETPOST("source") == 'order') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$order->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -452,7 +462,7 @@ if (GETPOST("source") == 'order') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -472,7 +482,7 @@ if (GETPOST("source") == 'order') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -534,26 +544,26 @@ if (GETPOST("source") == 'invoice') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$invoice->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -562,7 +572,7 @@ if (GETPOST("source") == 'invoice') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -582,7 +592,7 @@ if (GETPOST("source") == 'invoice') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -662,7 +672,7 @@ if (GETPOST("source") == 'contractline') { $product=new Product($db); $result=$product->fetch($contractline->fk_product); - + // We define price for product (TODO Put this in a method in product class) if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -676,7 +686,7 @@ if (GETPOST("source") == 'contractline') $pu_ttc = $product->price_ttc; $price_base_type = $product->price_base_type; } - + $amount=$pu_ttc; if (empty($amount)) { @@ -697,19 +707,19 @@ if (GETPOST("source") == 'contractline') if (GETPOST('qty')) $qty=GETPOST('qty'); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("ThirdParty"); print ''.$contract->thirdparty->name.''; // Object - + $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; if ($contractline->fk_product) { @@ -732,7 +742,7 @@ if (GETPOST("source") == 'contractline') print '
'.$langs->trans("Amount"); if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; print ''; @@ -780,7 +790,7 @@ if (GETPOST("source") == 'contractline') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; @@ -824,6 +834,7 @@ if (GETPOST("source") == 'membersubscription') require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; + $member=new Adherent($db); $result=$member->fetch('',$ref); if ($result < 0) @@ -842,20 +853,20 @@ if (GETPOST("source") == 'membersubscription') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); // Creditor - + print '
'.$langs->trans("Creditor"); print ''.$creditor.''; print ''; print '
'.$langs->trans("Member"); print ''; if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; @@ -863,7 +874,7 @@ if (GETPOST("source") == 'membersubscription') print ''; // Object - + $text=''.$langs->trans("PaymentSubscription").''; print '
'.$langs->trans("Designation"); print ''.$text; @@ -874,13 +885,13 @@ if (GETPOST("source") == 'membersubscription') if ($member->last_subscription_date || $member->last_subscription_amount) { // Last subscription date - + print '
'.$langs->trans("LastSubscriptionDate"); print ''.dol_print_date($member->last_subscription_date,'day'); print '
'.$langs->trans("LastSubscriptionAmount"); print ''.price($member->last_subscription_amount); print '
'.$langs->trans("Amount"); if (empty($amount)) { @@ -918,7 +929,7 @@ if (GETPOST("source") == 'membersubscription') print '
'.$langs->trans("PaymentCode"); print ''.$fulltag.''; print ''; diff --git a/htdocs/public/stripe/newpayment.php b/htdocs/public/stripe/newpayment.php index 01ae19c7032..af0c880d3c8 100644 --- a/htdocs/public/stripe/newpayment.php +++ b/htdocs/public/stripe/newpayment.php @@ -196,7 +196,7 @@ else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIP if ($action == 'dopayment') // We click on button Create payment { if (GETPOST('newamount')) $amount = GETPOST('newamount'); - else + else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); $action = ''; @@ -209,18 +209,18 @@ if ($action == 'charge') // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support $arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); if (! in_array($currency, $arrayzerounitcurrency)) $amount=$amount * 100; - + dol_syslog("POST keys : ".join(',', array_keys($_POST)), LOG_DEBUG, 0, '_stripe'); dol_syslog("POST values: ".join(',', $_POST), LOG_DEBUG, 0, '_stripe'); - + $stripeToken = GETPOST("stripeToken",'alpha'); $email = GETPOST("stripeEmail",'alpha'); dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); dol_syslog("stripeEmail = ".$stripeEmail, LOG_DEBUG, 0, '_stripe'); - + $error = 0; - + try { dol_syslog("Create customer", LOG_DEBUG, 0, '_stripe'); $customer = \Stripe\Customer::create(array( @@ -230,7 +230,7 @@ if ($action == 'charge') 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?) )); // TODO Add 'business_vat_id' ? - + dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, @@ -244,14 +244,14 @@ if ($action == 'charge') // Since it's a decline, \Stripe\Error\Card will be caught $body = $e->getJsonBody(); $err = $body['error']; - + print('Status is:' . $e->getHttpStatus() . "\n"); print('Type is:' . $err['type'] . "\n"); print('Code is:' . $err['code'] . "\n"); // param is '' in this case print('Param is:' . $err['param'] . "\n"); print('Message is:' . $err['message'] . "\n"); - + $error++; setEventMessages($e->getMessage(), null, 'errors'); dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); @@ -295,7 +295,7 @@ if ($action == 'charge') setEventMessages($e->getMessage(), null, 'errors'); $action=''; } - + $_SESSION["onlinetoken"] = $stripeToken; $_SESSION["FinalPaymentAmt"] = $amount; $_SESSION["currencyCodeType"] = $currency; @@ -303,12 +303,12 @@ if ($action == 'charge') $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip $_SESSION['payerID'] = is_object($customer)?$customer->id:''; $_SESSION['TRANSACTIONID'] = is_object($charge)?$charge->id:''; - + dol_syslog("Action charge stripe result=".$error." ip=".$_SESSION['ipaddress'], LOG_DEBUG, 0, '_stripe'); dol_syslog("onlinetoken=".$_SESSION["onlinetoken"]." FinalPaymentAmt=".$_SESSION["FinalPaymentAmt"]." currencyCodeType=".$_SESSION["currencyCodeType"]." payerID=".$_SESSION['payerID']." TRANSACTIONID=".$_SESSION['TRANSACTIONID'], LOG_DEBUG, 0, '_stripe'); dol_syslog("FULLTAG=".$FULLTAG, LOG_DEBUG, 0, '_stripe'); dol_syslog("Now call the redirect to paymentok or paymentko", LOG_DEBUG, 0, '_stripe'); - + if ($error) { header("Location: ".$urlko); @@ -319,7 +319,7 @@ if ($action == 'charge') header("Location: ".$urlok); exit; } - + } @@ -335,6 +335,16 @@ $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', ''))) +{ + $langs->load("errors"); + dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); + llxFooter(); + $db->close(); + exit; +} + if (empty($conf->global->STRIPE_LIVE)) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); @@ -420,7 +430,7 @@ if (! GETPOST("source")) $found=true; $tag=GETPOST("tag"); $fulltag=$tag; - + // Creditor print '
'.$langs->trans("Creditor"); print ''.$creditor.''; @@ -485,7 +495,7 @@ if (GETPOST("source") == 'order') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } @@ -600,7 +610,7 @@ if (GETPOST("source") == 'invoice') //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); - + // Creditor print '
'.$langs->trans("Creditor"); @@ -723,7 +733,7 @@ if (GETPOST("source") == 'contractline') { $product=new Product($db); $result=$product->fetch($contractline->fk_product); - + // We define price for product (TODO Put this in a method in product class) if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -737,7 +747,7 @@ if (GETPOST("source") == 'contractline') $pu_ttc = $product->price_ttc; $price_base_type = $product->price_base_type; } - + $amount=$pu_ttc; if (empty($amount)) { @@ -749,7 +759,7 @@ if (GETPOST("source") == 'contractline') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); //$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," "); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } @@ -904,7 +914,7 @@ if (GETPOST("source") == 'membersubscription') if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); $amount=price2num($amount); } - + $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } $fulltag=dol_string_unaccent($fulltag); @@ -1059,7 +1069,7 @@ if (preg_match('/^dopayment/',$action)) data-description="'.$ref.'"> '; */ - + // Personalized checkout print ''; - + print ' - +
'; @@ -1106,11 +1116,11 @@ if (preg_match('/^dopayment/',$action)) print ''; print ''."\n"; print ''."\n"; - + print '
- +
@@ -1126,22 +1136,22 @@ if (preg_match('/^dopayment/',$action))
- + - + - + '; + print ''; } From bebf2b33eaa3f4439543d012d7f9e97cb7f457cd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 09:25:35 +0200 Subject: [PATCH 50/66] CSS enhancement for mobile --- htdocs/theme/eldy/style.css.php | 9 ++++++++ htdocs/theme/md/style.css.php | 41 ++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index c66fa33dfaa..4227b86ca51 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -712,6 +712,7 @@ div.fiche>form>div.div-table-responsive { align-self: flex-start; } + /* ============================================================================== */ /* Styles to hide objects */ /* ============================================================================== */ @@ -2795,6 +2796,9 @@ div.tabBar .noborder { @media only screen and (max-width: 767px) { + .thumbstat { + flex: 1 1 110px; + } .thumbstat150 { flex: 1 1 110px; } @@ -4594,6 +4598,11 @@ div.tabsElem a.tab { background: #FFF; } + .login_vertical_align { + padding-left: 20px; + padding-right: 20px; + } + /* Reduce login top right info */ .help { diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index a1851dc4a76..6e31fc3ed11 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -317,7 +317,7 @@ textarea { border-left:solid 1px rgba(0,0,0,.1); border-right:solid 1px rgba(0,0,0,.1); border-bottom:solid 1px rgba(0,0,0,.2); - + background-color: #FFF; padding:4px; margin-left:1px; @@ -867,10 +867,10 @@ div.fiche>form>div.div-table-responsive { width: 20px; object-fit: contain; } - + div.statusref { padding-right: 10px; - } + } } .linkobject { cursor: pointer; } @@ -1557,12 +1557,12 @@ foreach($mainmenuusedarray as $val) display: table; position: absolute; height: 100%; - width: 100%; + width: 100%; } .login_center { display: table-cell; vertical-align: middle; -} +} .login_vertical_align { padding: 10px; padding-bottom: 80px; @@ -1992,14 +1992,14 @@ div.tabBar { border-top: 1px solid #CCC; width: auto; background: rgb(); - border-bottom: 1px solid #aaa; + border-bottom: 1px solid #aaa; } div.tabBar div.titre { - padding-top: 10px; + padding-top: 10px; } div.tabBarWithBottom { padding-bottom: 18px; - border-bottom: 1px solid #aaa; + border-bottom: 1px solid #aaa; } div.tabBar table.tableforservicepart2:last-child { border-bottom: 1px solid #aaa; @@ -2720,7 +2720,7 @@ tr.liste_titre th, tr.liste_titre td, th.liste_titre, form.liste_titre div, div. { border-bottom: 1px solid #; } -/* TODO Once title line is moved under title search, make border bottom of all th black and force to whit when it's first tr */ +/* TODO Once title line is moved under title search, make border bottom of all th black and force to whit when it's first tr */ tr:first-child th.liste_titre { border-bottom: 1px solid #FFF ! important; } @@ -2826,7 +2826,7 @@ div .tdtop { /* Prepare to remove class pair - impair */ -.noborder > tbody > tr:nth-child(even):not(.liste_titre), .liste > tbody > tr:nth-child(even):not(.liste_titre) { +.noborder > tbody > tr:nth-child(even):not(.liste_titre), .liste > tbody > tr:nth-child(even):not(.liste_titre) { background: linear-gradient(bottom, rgb() 85%, rgb() 100%); background: -o-linear-gradient(bottom, rgb() 85%, rgb() 100%); background: -moz-linear-gradient(bottom, rgb() 85%, rgb() 100%); @@ -2852,7 +2852,7 @@ div .tdtop { /* * Boxes */ - + .ficheaddleft div.boxstats { border: none; } @@ -2866,29 +2866,32 @@ div .tdtop { text-align: center; border-radius: 2px; } -.boxstats, .boxstats130, .boxstatscontent { +.boxstats, .boxstats130, .boxstatscontent { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .boxstats { padding: 3px; - width: 105px; + width: 105px; } .boxstats130 { - width: 135px; + width: 135px; height: 48px; - padding: 3px + padding: 3px } @media only screen and (max-width: 767px) { + .thumbstat { + flex: 1 1 110px; + } .thumbstat150 { flex: 1 1 110px; } .boxstats, .boxstats130 { - width: 90px; + width: 90px; } - .dashboardlineindicator { + .dashboardlineindicator { float: left; padding-left: 5px; } @@ -2927,7 +2930,7 @@ span.dashboardlineko { padding: 1px 6px 1px 6px; background-color: #8c4446; color: #FFFFFF ! important; - border-radius: .25em; + border-radius: .25em; } .boxtable { margin-bottom: 8px !important; @@ -4047,7 +4050,7 @@ div.dataTables_length select { border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; } -.select2-container-active .select2-choice, .select2-container-active .select2-choices +.select2-container-active .select2-choice, .select2-container-active .select2-choices { outline: none; border-top: none; From df883a601b53ead931a2d6187d2e1576a44d09ef Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 2 Jun 2017 12:28:50 +0200 Subject: [PATCH 51/66] FIX contratligne update --- htdocs/contrat/class/contrat.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index a97391de170..9878e08d447 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2743,6 +2743,8 @@ class ContratLigne extends CommonObjectLine if (empty($this->total_ht)) $this->total_ht = 0; if (empty($this->total_tva)) $this->total_tva = 0; 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; // Check parameters // Put here code to add control on parameters values From 64cd1e0923755d4fddcf2c8788e2fe323f953d8d Mon Sep 17 00:00:00 2001 From: phf Date: Fri, 2 Jun 2017 12:31:03 +0200 Subject: [PATCH 52/66] Fix get extrafields value from getOptionalsFromPost give an error with chkbxlst type on propaldet for exemple --- htdocs/core/class/extrafields.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index c89fc593745..bd1daca8886 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1681,7 +1681,7 @@ class ExtraFields // Clean parameters $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); } - else if (in_array($key_type,array('checkbox'))) + else if (in_array($key_type,array('checkbox', 'chkbxlst'))) { $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); // Make sure we get an array even if there's only one checkbox From c59d216cf5f82572f7b3a24de978dda8037845ae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 12:27:46 +0200 Subject: [PATCH 53/66] NEW Can read time spent of others (hierarchy only or all if granted) --- htdocs/core/actions_setmoduleoptions.inc.php | 86 ------------ htdocs/core/class/html.form.class.php | 8 +- htdocs/core/class/html.formcompany.class.php | 19 +-- htdocs/core/class/html.formprojet.class.php | 52 ++++---- htdocs/core/js/timesheet.js | 4 +- htdocs/core/lib/project.lib.php | 130 +++++++++++-------- htdocs/langs/en_US/admin.lang | 2 +- htdocs/langs/en_US/projects.lang | 9 +- htdocs/projet/activity/perday.php | 100 +++++++------- htdocs/projet/activity/perweek.php | 114 ++++++++-------- htdocs/projet/card.php | 60 +++++---- htdocs/theme/eldy/style.css.php | 14 +- htdocs/theme/md/style.css.php | 9 +- 13 files changed, 269 insertions(+), 338 deletions(-) delete mode 100644 htdocs/core/actions_setmoduleoptions.inc.php diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php deleted file mode 100644 index 03b33b19eb1..00000000000 --- a/htdocs/core/actions_setmoduleoptions.inc.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * or see http://www.gnu.org/ - */ - -/** - * \file htdocs/core/actions_setnotes.inc.php - * \brief Code for actions on setting notes of object page - */ - - -// $action must be defined -// $_FILES may be defined -// $nomessageinsetmoduleoptions can be set to 1 - -// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') -{ - $db->begin(); - - // Process common param fields - foreach($_POST as $key => $val) - { - if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... - { - $param=GETPOST("param".$reg[1],'alpha'); - $value=GETPOST("value".$reg[1],'alpha'); - if ($param) - { - $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; - } - } - } - - // Process upload fields - if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09')) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $keyforuploaddir=GETPOST('keyforuploaddir','aZ09'); - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir))); - foreach($listofdir as $key=>$tmpdir) - { - $tmpdir=trim($tmpdir); - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); - if (! $tmpdir) { - unset($listofdir[$key]); continue; - } - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); - else - { - $upload_dir=$tmpdir; - } - } - if ($upload_dir) - { - $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); - if ($result <= 0) $error++; - } - } - - if (! $error) - { - $db->commit(); - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - $db->rollback(); - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); - } -} - diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index cf6ae18f568..34693cba67a 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1391,7 +1391,7 @@ class Form * @deprecated * @see select_dolusers() */ - function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) + function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude=null,$disabled=0,$include='',$enableonly='',$force_entity=0) { print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity); } @@ -1411,13 +1411,13 @@ class Form * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request * @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list - * @param string $enableonlytext If option $enableonly is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. + * @param string $enableonlytext If option $enableonlytext is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. * @param string $morecss More css * @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). * @return string HTML select string * @see select_dolgroups */ - function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0) + function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude=null, $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0) { global $conf,$user,$langs; @@ -1613,7 +1613,7 @@ class Form * @return string HTML select string * @see select_dolgroups */ - function select_dolusers_forevent($action='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='') + function select_dolusers_forevent($action='', $htmlname='userid', $show_empty=0, $exclude=null, $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='') { global $conf,$user,$langs; diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index bcff0981a70..88ebb816a31 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -358,7 +358,7 @@ class FormCompany * * @param string $selected Title preselected * @param string $htmlname Name of HTML select combo field - * @param string $morecss Add more css on SELECT element + * @param string $morecss Add more css on SELECT element * @return string String with HTML select */ function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100') @@ -563,11 +563,11 @@ class FormCompany $events=array(); // Add an entry 'method' to say 'yes, we must execute url with param action = method'; // Add an entry 'url' to say which url to execute - // Add an entry htmlname to say which element we must change once url is called - // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines + // Add an entry htmlname to say which element we must change once url is called + // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines // To refresh contacts list on thirdparty list change $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); - + if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events { print ''; } -elseif ($object->id > 0) +elseif ($object->id > 0) { /* * Show or edit */ - + $res=$object->fetch_optionals($object->id,$extralabels); // To verify role of users @@ -711,10 +711,11 @@ elseif ($object->id > 0) print ''; $head=project_prepare_head($object); - dol_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public?'projectpub':'project')); if ($action == 'edit' && $userWrite > 0) { + dol_fiche_head($head, 'project', $langs->trans("Project"), 0, ($object->public?'projectpub':'project')); + print ''; // Ref @@ -835,27 +836,30 @@ elseif ($object->id > 0) } else { + dol_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public?'projectpub':'project')); + // Project card - + $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref='
'; // Title $morehtmlref.=$object->title; // Thirdparty - if ($object->thirdparty->id > 0) + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : '; + if ($object->thirdparty->id > 0) { - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project'); + $morehtmlref .= $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); @@ -889,7 +893,7 @@ elseif ($object->id > 0) if (strcmp($object->opp_amount,'')) print price($object->opp_amount,0,$langs,1,0,0,$conf->currency); print ''; } - + // Date start - end print ''; - + // Budget print '
'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").''; $start = dol_print_date($object->date_start,'dayhour'); @@ -899,7 +903,7 @@ elseif ($object->id > 0) print ($end?$end:'?'); if ($object->hasDelay()) print img_warning("Late"); print '
'.$langs->trans("Budget").''; if (strcmp($object->budget_amount, '')) print price($object->budget_amount,0,$langs,1,0,0,$conf->currency); @@ -908,16 +912,16 @@ elseif ($object->id > 0) // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + print '
'; - + print ''; print '
'; print '
'; print '
'; - + print ''; - + // Description print '"; } - + print '
'.$langs->trans("Description").''; print nl2br($object->description); @@ -929,13 +933,13 @@ elseif ($object->id > 0) print $form->showCategories($object->id,'project',1); print "
'; - + print '
'; print '
'; print ''; - + print '
'; } @@ -956,7 +960,7 @@ elseif ($object->id > 0) { $defaultcheckedwhenoppclose=1; if (empty($conf->global->PROJECT_HIDE_TASKS)) $defaultcheckedwhenoppclose=0; - + print ''; print ''; + + // Loan card - + $linkback = '' . $langs->trans("BackToList") . ''; - + $morehtmlref='
'; // Ref loan $morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1); @@ -458,7 +470,7 @@ if ($id > 0) } } $morehtmlref.='
'; - + $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); @@ -652,7 +664,7 @@ if ($id > 0) while ($i < $num) { $objp = $db->fetch_object($resql); - + print '
'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."
'; +print ''; +print '"; +print ''; + +print ''; +Print ''; +Print ''; +Print ''; +Print ''; +Print ''; +print ''; + +if ($object->nbterm > 0 && count($echeance->lines)==0) +{ + $i=1; + $capital = $object->capital; + while($i <$object->nbterm+1){ + $mens = round($echeance->calc_mens($capital, $object->rate/100, $object->nbterm-$i+1),2,PHP_ROUND_HALF_UP); + $int = ($capital*($object->rate/12))/100; + $int = round($int ,2,PHP_ROUND_HALF_UP); + $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + $capital = $cap_rest; + } +}elseif(count($echeance->lines)>0){ + $i=1; + $capital = $object->capital; + foreach ($echeance->lines as $line){ + $mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest; + $int = $line->amount_interest; + $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + print ''; + print ''; + print ''; + if($line->datep > dol_now()){ + print ''; + }else{ + print ''; + } + print ''; + print ''; + print ''; + $i++; + $capital = $cap_rest; + } +} + +print '
' . "Création d'échéancier
Echéance Date Montant Intérêts Capital restant du
' . $i .'' . dol_print_date(dol_time_plus_duree($object->datestart, $i-1, 'm'),'day') . ''.price($int,0,'',1).' €'.price($cap_rest).' €
' . $i .'' . dol_print_date($line->datep,'day') . '' . price($mens) . ' €'.price($int,0,'',1).' €'.price($cap_rest).' €
'; +print '
'; +print '
'; +print '
'; +print ''; + +llxFooter(); +$db->close(); + + + From 1761df2bc243ec9f333f38195ece72c533f83553 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 19:28:22 +0200 Subject: [PATCH 56/66] NEW Add page statistics for project tasks --- htdocs/core/menus/init_menu_auguria.sql | 1 + htdocs/core/menus/standard/eldy.lib.php | 45 +-- htdocs/langs/en_US/projects.lang | 3 + htdocs/projet/class/taskstats.class.php | 471 ++++++++++++++++++++++++ htdocs/projet/tasks/stats/index.php | 218 +++++++++++ 5 files changed, 716 insertions(+), 22 deletions(-) create mode 100644 htdocs/projet/class/taskstats.class.php create mode 100644 htdocs/projet/tasks/stats/index.php diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index 9106c345fda..7a60f330727 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -288,6 +288,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3701__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&action=create', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3702__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks/list.php?leftmenu=projects', 'List', 1, 'projects', '$user->rights->projet->lire', '', 2, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3703__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3704__+MAX_llx_menu__, 'project', '', 3600__+MAX_llx_menu__, '/projet/tasks/stats/index.php?leftmenu=projects', 'Statistics', 1, 'projects', '$user->rights->projet->lire', '', 2, 4, __ENTITY__); -- Project - Categories insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3804__+MAX_llx_menu__, 'project', 'cat', 3__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&type=6', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 6248f294476..38a9a66a137 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -52,7 +52,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode if (empty($noout)) print_start_menu_array(); $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); - + // Show/Hide vertical menu if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -437,7 +437,7 @@ function print_end_menu_array() /** * Core function to output left menu eldy * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home) - * + * * @param DoliDB $db Database handler * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add) * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add) @@ -445,7 +445,7 @@ function print_end_menu_array() * @param Menu $menu Object Menu to return back list of menu entries * @param int $noout Disable output (Initialise &$menu only). * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x' - * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not efined in session. + * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not efined in session. * @param array $moredata An array with more data to output * @return int nb of menu entries */ @@ -459,7 +459,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $leftmenu=($forceleftmenu?'':(empty($_SESSION["leftmenu"])?'none':$_SESSION["leftmenu"])); $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); - + // Show logo company if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && ! empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -503,7 +503,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu print '
'."\n"; print "\n"; } - + /** * We update newmenu with entries found into database * -------------------------------------------------- @@ -605,7 +605,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/user/group/index.php?leftmenu=users", $langs->trans("ListOfGroups"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->read:$user->rights->user->user->lire) || $user->admin); } } - + } @@ -839,7 +839,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"),1,$user->rights->fournisseur->facture->lire); - + $newmenu->add("/fourn/facture/rapport.php",$langs->trans("Reportings"),2,$user->rights->fournisseur->facture->lire); $newmenu->add("/compta/facture/stats/index.php?mode=supplier", $langs->trans("Statistics"),1,$user->rights->fournisseur->facture->lire); @@ -957,29 +957,29 @@ 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/account.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("Chartofaccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 30); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/categories_list.php?id=32&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("AccountingCategory"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 31); 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', 40); - if (! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled)) + if (! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=10&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuVatAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } - if (! empty($conf->tax->enabled)) + if (! empty($conf->tax->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=7&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuTaxAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } - if (! empty($conf->expensereport->enabled)) + if (! empty($conf->expensereport->enabled)) { if (preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=17&from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuExpenseReportAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } /* not required yet, already supported by default account - if (! empty($conf->loan->enabled)) + if (! empty($conf->loan->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/loan.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuLoanAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_loan', 45); } - if (! empty($conf->don->enabled)) + if (! empty($conf->don->enabled)) { if (preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/don/admin/donation.php?from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuDonationAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_donation', 47); }*/ if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/productaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuProductsAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_product', 60); - + // Binding if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/customer/index.php?leftmenu=accountancy_dispatch_customer&mainmenu=accountancy",$langs->trans("CustomersVentilation"),1,$user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_customer'); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_customer/',$leftmenu)) $newmenu->add("/accountancy/customer/list.php?mainmenu=accountancy&leftmenu=accountancy_dispatch_customer",$langs->trans("ToBind"),2,$user->rights->accounting->bind->write); @@ -1023,19 +1023,19 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $objp = $db->fetch_object($resql); $nature=''; - // Must match array $sourceList defined into journals_list.php + // Must match array $sourceList defined into journals_list.php if ($objp->nature == 2) $nature="sells"; if ($objp->nature == 3) $nature="purchases"; if ($objp->nature == 4) $nature="bank"; if ($objp->nature == 1) $nature="various"; if ($objp->nature == 9) $nature="hasnew"; - + // To enable when page exists if (empty($conf->global->MAIN_FEATURES_LEVEL)) { - if ($nature == 'various' || $nature == 'hasnew') $nature=''; + if ($nature == 'various' || $nature == 'hasnew') $nature=''; } - + if ($nature) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&code_journal='.$objp->code,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire); @@ -1275,7 +1275,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/product/inventory/list.php", $langs->trans("List"), 1, $user->rights->stock->lire); } } - + // Expeditions if (! empty($conf->expedition->enabled)) { @@ -1299,9 +1299,9 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (! empty($conf->projet->enabled)) { $langs->load("projects"); - + $search_project_user = GETPOST('search_project_user','int'); - + // Project affected to user $newmenu->add("/projet/index.php?leftmenu=projects".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("Projects"), 0, $user->rights->projet->lire, '', $mainmenu, 'projects'); $newmenu->add("/projet/card.php?leftmenu=projects&action=create".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewProject"), 1, $user->rights->projet->creer); @@ -1314,7 +1314,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/projet/list.php?leftmenu=projects&search_status=99", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire); */ $newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire); - + if (empty($conf->global->PROJECT_HIDE_TASKS)) { // Project affected to user @@ -1322,6 +1322,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/projet/tasks.php?leftmenu=tasks&action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer); $newmenu->add("/projet/tasks/list.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("List"), 1, $user->rights->projet->lire); $newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewTimeSpent"), 1, $user->rights->projet->lire); + $newmenu->add("/projet/tasks/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire); // All project i have permission on /*$newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire); @@ -1445,7 +1446,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/adherents/stats/index.php?leftmenu=members",$langs->trans("MenuMembersStats"),1,$user->rights->adherent->lire); if (! empty($conf->global->MEMBER_LINK_TO_HTPASSWDFILE) && ($usemenuhider || empty($leftmenu) || $leftmenu=="export")) $newmenu->add("/adherents/htpasswd.php?leftmenu=export",$langs->trans("Filehtpasswd"),1,$user->rights->adherent->export); if ($usemenuhider || empty($leftmenu) || $leftmenu=="export") $newmenu->add("/adherents/cartes/carte.php?leftmenu=export",$langs->trans("MembersCards"),1,$user->rights->adherent->export); - + $newmenu->add("/adherents/index.php?leftmenu=members&mainmenu=members",$langs->trans("Subscriptions"),0,$user->rights->adherent->cotisation->lire); $newmenu->add("/adherents/list.php?leftmenu=members&statut=-1,1&mainmenu=members",$langs->trans("NewSubscription"),1,$user->rights->adherent->cotisation->creer); $newmenu->add("/adherents/subscription/list.php?leftmenu=members",$langs->trans("List"),1,$user->rights->adherent->cotisation->lire); diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 3b4e4f4d14f..b3317df9c8e 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -41,6 +41,7 @@ ShowProject=Show project SetProject=Set project NoProject=No project defined or owned NbOfProjects=Nb of projects +NbOfTasks=Nb of tasks TimeSpent=Time spent TimeSpentByYou=Time spent by you TimeSpentByUser=Time spent by user @@ -181,10 +182,12 @@ ProjectOverview=Overview ManageTasks=Use projects to follow tasks and time ManageOpportunitiesStatus=Use projects to follow leads/opportinuties ProjectNbProjectByMonth=Nb of created projects by month +ProjectNbTaskByMonth=Nb of created tasks by month ProjectOppAmountOfProjectsByMonth=Amount of opportunities by month ProjectWeightedOppAmountOfProjectsByMonth=Weighted amount of opportunities by month ProjectOpenedProjectByOppStatus=Open project/lead by opportunity status ProjectsStatistics=Statistics on projects/leads +TasksStatistics=Statistics on project/lead tasks TaskAssignedToEnterTime=Task assigned. Entering time on this task should be possible. IdTaskTime=Id task time YouCanCompleteRef=If you want to complete the ref with some information (to use it as search filters), it is recommanded to add a - character to separate it, so the automatic numbering will still work correctly for next projects. For example %s-ABC. You may also prefer to add search keys into label. But best practice may be to add a dedicated field, also called complementary attributes. diff --git a/htdocs/projet/class/taskstats.class.php b/htdocs/projet/class/taskstats.class.php new file mode 100644 index 00000000000..c0a0530bc75 --- /dev/null +++ b/htdocs/projet/class/taskstats.class.php @@ -0,0 +1,471 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; +include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; + + +/** + * Class to manage statistics on project tasks + */ +class TaskStats extends Stats +{ + private $project; + public $userid; + public $socid; + public $year; + + function __construct($db) + { + global $conf, $user; + + $this->db = $db; + + require_once 'task.class.php'; + $this->task = new Task($this->db); + } + + + /** + * Return all tasks grouped by status. + * + * @param int $limit Limit results + * @return array|int Array with value or -1 if error + * @throws Exception + */ + function getAllTaskByStatus($limit = 5) + { + global $conf, $user, $langs; + + $datay = array (); + + $sql = "SELECT"; + $sql .= " COUNT(t.rowid), t.priority"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + $sql .= $this->buildWhere(); + //$sql .= " AND t.fk_statut <> 0"; // We want historic also, so all task not draft + $sql .= " GROUP BY t.priority"; + + $result = array (); + $res = array (); + + dol_syslog(get_class($this) . '::' . __METHOD__ . "", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + $other = 0; + while ( $i < $num ) { + $row = $this->db->fetch_row($resql); + if ($i < $limit || $num == $limit) + { + $result[$i] = array( + $row[1], + $row[0] + ); + } + else + $other += $row[1]; + $i++; + } + if ($num > $limit) + $result[$i] = array ( + $langs->transnoentitiesnoconv("Other"), + $other + ); + $this->db->free($resql); + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . '::' . __METHOD__ . ' ' . $this->error, LOG_ERR); + return -1; + } + + return $result; + } + + /** + * Return count, and sum of products + * + * @return array of values + */ + function getAllByYear() + { + global $conf, $user, $langs; + + $datay = array (); + + $wonlostfilter=0; // No filter on status WON/LOST + + $sql = "SELECT date_format(t.datec,'%Y') as year, COUNT(t.rowid) as nb"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql.= $this->buildWhere(); + $sql.= " GROUP BY year"; + $sql.= $this->db->order('year', 'DESC'); + + return $this->_getAllByYear($sql); + } + + + /** + * Build the where part + * + * @return string + */ + public function buildWhere() + { + $sqlwhere_str = ''; + $sqlwhere = array(); + + $sqlwhere[] = ' t.entity IN (' . getEntity('project') . ')'; + + if (! empty($this->userid)) + $sqlwhere[] = ' t.fk_user_resp=' . $this->userid; + if (! empty($this->socid)) + $sqlwhere[] = ' t.fk_soc=' . $this->socid; + if (! empty($this->year) && empty($this->yearmonth)) + $sqlwhere[] = " date_format(t.datec,'%Y')='" . $this->db->escape($this->year) . "'"; + if (! empty($this->yearmonth)) + $sqlwhere[] = " t.datec BETWEEN '" . $this->db->idate(dol_get_first_day($this->yearmonth)) . "' AND '" . $this->db->idate(dol_get_last_day($this->yearmonth)) . "'"; + + if (! empty($this->status)) + $sqlwhere[] = " t.priority IN (" . $this->priority . ")"; + + if (count($sqlwhere) > 0) { + $sqlwhere_str = ' WHERE ' . implode(' AND ', $sqlwhere); + } + + return $sqlwhere_str; + } + + /** + * Return Task number by month for a year + * + * @param int $year scan + * @return array of values + */ + function getNbByMonth($year) + { + global $user; + + $this->yearmonth = $year; + + $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(t.rowid) as nb"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= $this->buildWhere(); + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + + $this->yearmonth=0; + + $res = $this->_getNbByMonth($year, $sql); + // var_dump($res);print '
'; + return $res; + } + + /** + * Return the Task amount by month for a year + * + * @param int $year scan + * @return array with amount by month + */ + /* + function getAmountByMonth($year) + { + global $user; + + $this->yearmonth = $year; + + $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(t.rowid)"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= $this->buildWhere(); + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + $this->yearmonth=0; + + $res = $this->_getAmountByMonth($year, $sql); + // var_dump($res);print '
'; + return $res; + }*/ + + + /** + * Return amount of elements by month for several years + * + * @param int $endyear Start year + * @param int $startyear End year + * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) + * @param int $wonlostfilter Add a filter on status won/lost + * @return array Array of values + */ + /* + function getWeightedAmountByMonthWithPrevYear($endyear,$startyear,$cachedelay=0,$wonlostfilter=1) + { + global $conf,$user,$langs; + + if ($startyear > $endyear) return -1; + + $datay=array(); + + // Search into cache + if (! empty($cachedelay)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; + } + + $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_user'.$user->id.'.cache'; + $newmask='0644'; + + $nowgmt = dol_now(); + + $foundintocache=0; + if ($cachedelay > 0) + { + $filedate=dol_filemtime($newpathofdestfile); + if ($filedate >= ($nowgmt - $cachedelay)) + { + $foundintocache=1; + + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; + } + else + { + dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); + } + } + + // Load file into $data + if ($foundintocache) // Cache file found and is not too old + { + dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); + $data = json_decode(file_get_contents($newpathofdestfile), true); + } + else + { + $year=$startyear; + while($year <= $endyear) + { + $datay[$year] = $this->getWeightedAmountByMonth($year,$wonlostfilter); + $year++; + } + + $data = array(); + // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) + for ($i = 0 ; $i < 12 ; $i++) + { + $data[$i][]=$datay[$endyear][$i][0]; // set label + $year=$startyear; + while($year <= $endyear) + { + $data[$i][]=$datay[$year][$i][1]; // set yval for x=i + $year++; + } + } + } + + // Save cache file + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) + { + dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); + if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); + $fp = fopen($newpathofdestfile, 'w'); + if ($fp) + { + fwrite($fp, json_encode($data)); + fclose($fp); + if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; + @chmod($newpathofdestfile, octdec($newmask)); + } + else dol_syslog("Failed to write cache file", LOG_ERR); + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; + } + + return $data; + } + */ + + + /** + * Return the Task weighted opp amount by month for a year. + * + * @param int $year Year to scan + * @param int $wonlostfilter Add a filter on status won/lost + * @return array Array with amount by month + */ + /* + function getWeightedAmountByMonth($year, $wonlostfilter=1) + { + global $user; + + $this->yearmonth = $year; + + $sql = "SELECT date_format(t.datec,'%m') as dm"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= $this->buildWhere(); + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + $this->yearmonth=0; + + $res = $this->_getAmountByMonth($year, $sql); + // var_dump($res);print '
'; + return $res; + }*/ + + /** + * Return amount of elements by month for several years + * + * @param int $endyear End year + * @param int $startyear Start year + * @param int $cachedelay accept for cache file (0=No read, no save of cache, -1=No read but save) + * @return array of values + */ + /* + function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0) + { + global $conf, $user, $langs; + + if ($startyear > $endyear) return - 1; + + $datay = array(); + + // Search into cache + if (! empty($cachedelay)) + { + include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT . '/core/lib/json.lib.php'; + } + + $newpathofdestfile = $conf->user->dir_temp . '/' . get_class($this) . '_' . __FUNCTION__ . '_' . (empty($this->cachefilesuffix) ? '' : $this->cachefilesuffix . '_') . $langs->defaultlang . '_user' . $user->id . '.cache'; + $newmask = '0644'; + + $nowgmt = dol_now(); + + $foundintocache = 0; + if ($cachedelay > 0) { + $filedate = dol_filemtime($newpathofdestfile); + if ($filedate >= ($nowgmt - $cachedelay)) { + $foundintocache = 1; + + $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $filedate; + } else { + dol_syslog(get_class($this) . '::' . __FUNCTION__ . " cache file " . $newpathofdestfile . " is not found or older than now - cachedelay (" . $nowgmt . " - " . $cachedelay . ") so we can't use it."); + } + } + + // Load file into $data + if ($foundintocache) // Cache file found and is not too old + { + dol_syslog(get_class($this) . '::' . __FUNCTION__ . " read data from cache file " . $newpathofdestfile . " " . $filedate . "."); + $data = json_decode(file_get_contents($newpathofdestfile), true); + } else { + $year = $startyear; + while ( $year <= $endyear ) { + $datay[$year] = $this->getTransformRateByMonth($year); + $year ++; + } + + $data = array (); + // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) + for($i = 0; $i < 12; $i ++) { + $data[$i][] = $datay[$endyear][$i][0]; // set label + $year = $startyear; + while ( $year <= $endyear ) { + $data[$i][] = $datay[$year][$i][1]; // set yval for x=i + $year ++; + } + } + } + + // Save cache file + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == - 1)) { + dol_syslog(get_class($this) . '::' . __FUNCTION__ . " save cache file " . $newpathofdestfile . " onto disk."); + if (! dol_is_dir($conf->user->dir_temp)) + dol_mkdir($conf->user->dir_temp); + $fp = fopen($newpathofdestfile, 'w'); + fwrite($fp, json_encode($data)); + fclose($fp); + if (! empty($conf->global->MAIN_UMASK)) + $newmask = $conf->global->MAIN_UMASK; + @chmod($newpathofdestfile, octdec($newmask)); + + $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $nowgmt; + } + + return $data; + }*/ + + /** + * Return the Task transformation rate by month for a year + * + * @param int $year scan + * @return array with amount by month + */ + /* + function getTransformRateByMonth($year) + { + global $user; + + $this->yearmonth = $year; + + $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.rowid)"; + $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= $this->buildWhere(); + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + + $res_total = $this->_getNbByMonth($year, $sql); + + $this->status=6; + + $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.rowid)"; + $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task as t"; + if (! $user->rights->societe->client->voir && ! $user->societe_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= $this->buildWhere(); + $sql .= " GROUP BY dm"; + $sql .= $this->db->order('dm', 'DESC'); + + $this->status=0; + $this->yearmonth=0; + + $res_only_wined = $this->_getNbByMonth($year, $sql); + + $res=array(); + + foreach($res_total as $key=>$total_row) { + //var_dump($total_row); + if (!empty($total_row[1])) { + $res[$key]=array($total_row[0],(100*$res_only_wined[$key][1])/$total_row[1]); + } else { + $res[$key]=array($total_row[0],0); + } + + } + // var_dump($res);print '
'; + return $res; + }*/ +} diff --git a/htdocs/projet/tasks/stats/index.php b/htdocs/projet/tasks/stats/index.php new file mode 100644 index 00000000000..b03d01a8006 --- /dev/null +++ b/htdocs/projet/tasks/stats/index.php @@ -0,0 +1,218 @@ + + * Copyright (C) 2015 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/projet/tasks/stats/index.php + * \ingroup project + * \brief Page for tasks statistics + */ + +require '../../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/taskstats.class.php'; + +// Security check +if (! $user->rights->projet->lire) + accessforbidden(); + + +$WIDTH=DolGraph::getDefaultGraphSizeForStats('width'); +$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height'); + +$userid=GETPOST('userid','int'); +$socid=GETPOST('socid','int'); +// Security check +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} +$nowyear=strftime("%Y", dol_now()); +$year = GETPOST('year')>0?GETPOST('year'):$nowyear; +//$startyear=$year-2; +$startyear=$year-1; +$endyear=$year; + +$langs->load('companies'); +$langs->load('projects'); + + +/* + * View + */ + +$form=new Form($db); + +$includeuserlist=array(); + + +llxHeader('', $langs->trans('Tasks')); + +$title=$langs->trans("TasksStatistics"); +$dir=$conf->projet->dir_output.'/temp'; + +print load_fiche_titre($title,'','title_project.png'); + +dol_mkdir($dir); + + +$stats_tasks= new TaskStats($db); +if (!empty($userid) && $userid!=-1) $stats_tasks->userid=$userid; +if (!empty($socid) && $socid!=-1) $stats_tasks->socid=$socid; +if (!empty($year)) $stats_tasks->year=$year; + + + +// Build graphic number of object +// $data = array(array('Lib',val1,val2,val3),...) +$data = $stats_tasks->getNbByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); + +$filenamenb = $conf->project->dir_output . "/stats/tasknbprevyear-".$year.".png"; +$fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=taskstats&file=tasknbprevyear-'.$year.'.png'; + +$px1 = new DolGraph(); +$mesg = $px1->isGraphKo(); +if (! $mesg) +{ + $px1->SetData($data); + $px1->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + $px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("ProjectNbTask")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->SetPrecisionY(0); + $px1->mode='depth'; + $px1->SetTitle($langs->trans("ProjectNbTaskByMonth")); + + $px1->draw($filenamenb,$fileurlnb); +} + + +// Show array +$stats_tasks->year=0; +$data_all_year = $stats_tasks->getAllByYear(); + +if (!empty($year)) $stats_tasks->year=$year; +$arrayyears=array(); +foreach($data_all_year as $val) { + $arrayyears[$val['year']]=$val['year']; +} +if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear; + + +$h=0; +$head = array(); +$head[$h][0] = DOL_URL_ROOT . '/projet/tasks/stats/index.php?mode='.$mode; +$head[$h][1] = $langs->trans("ByMonthYear"); +$head[$h][2] = 'byyear'; +$h++; + +complete_head_from_modules($conf,$langs,null,$head,$h,$type); + +dol_fiche_head($head,'byyear',$langs->trans("Statistics"), -1, ''); + + +print '
'; + +print '
'; + +print ''; +print ''; +// Company +/*print ''; +*/ +// User +/*print '';*/ +// Year +print ''; +print ''; +print '
'.$langs->trans("Filter").'
'.$langs->trans("ThirdParty").''; +if ($mode == 'customer') $filter='s.client in (1,2,3)'; +if ($mode == 'supplier') $filter='s.fournisseur = 1'; +print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"'); +print '
'.$langs->trans("ProjectCommercial").''; +print $form->select_dolusers($userid, 'userid', 1, array(),0,$includeuserlist); +print '
'.$langs->trans("Year").''; +if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year; +if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear; +arsort($arrayyears); +print $form->selectarray('year',$arrayyears,$year,0); +print '
'; +print '
'; +print '

'; + +print ''; +print ''; +print ''; +print ''; +print ''; + +$oldyear=0; +$var=true; +foreach ($data_all_year as $val) +{ + $year = $val['year']; + while ($year && $oldyear > $year+1) + { // If we have empty year + $oldyear--; + + print ''; + print ''; + print ''; + print ''; + } + + print ''; + print ''; + print ''; + print ''; + $oldyear=$year; +} + +print '
'.$langs->trans("Year").''.$langs->trans("NbOfTasks").'
0?'&userid='.$userid:'').'">'.$oldyear.'0
0?'&userid='.$userid:'').'">'.$year.''.$val['nb'].'
'; + +print '
'; + +$stringtoshow.= '
'; +if ($mesg) { print $mesg; } +else { + $stringtoshow.= $px1->show(); + $stringtoshow.= "
\n"; +} +$stringtoshow.= '
'; + +print $stringtoshow; + + +print '
'; +print '
'; + + +llxFooter(); +$db->close(); From bfa50b8d1d8574151d9bdac304d487f84f39da0e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 19:36:03 +0200 Subject: [PATCH 57/66] Fix some security issues --- htdocs/projet/class/projectstats.class.php | 41 +-- htdocs/projet/class/taskstats.class.php | 297 +-------------------- 2 files changed, 27 insertions(+), 311 deletions(-) diff --git a/htdocs/projet/class/projectstats.class.php b/htdocs/projet/class/projectstats.class.php index 4485117fb0f..a47d28d1b43 100644 --- a/htdocs/projet/class/projectstats.class.php +++ b/htdocs/projet/class/projectstats.class.php @@ -28,8 +28,8 @@ class ProjectStats extends Stats public $userid; public $socid; public $year; - - function __construct($db) + + function __construct($db) { global $conf, $user; @@ -41,7 +41,7 @@ class ProjectStats extends Stats /** - * Return all leads grouped by status. + * Return all leads grouped by opportunity status. * Warning: There is no filter on WON/LOST because we want this for statistics. * * @param int $limit Limit results @@ -56,7 +56,10 @@ class ProjectStats extends Stats $sql = "SELECT"; $sql .= " SUM(t.opp_amount), t.fk_opp_status, cls.code, cls.label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t, ".MAIN_DB_PREFIX."c_lead_status as cls"; + $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t"; + if (! $user->rights->societe->client->voir && ! $user->socid) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; + $sql .= ", ".MAIN_DB_PREFIX."c_lead_status as cls"; $sql .= $this->buildWhere(); $sql .= " AND t.fk_opp_status = cls.rowid"; $sql .= " AND t.fk_statut <> 0"; // We want historic also, so all projects not draft @@ -112,11 +115,11 @@ class ProjectStats extends Stats $datay = array (); $wonlostfilter=0; // No filter on status WON/LOST - + $sql = "SELECT date_format(t.datec,'%Y') as year, COUNT(t.rowid) as nb, SUM(t.opp_amount) as total, AVG(t.opp_amount) as avg,"; $sql.= " SUM(t.opp_amount * ".$this->db->ifsql("t.opp_percent IS NULL".($wonlostfilter?" OR cls.code IN ('WON','LOST')":""), '0', 't.opp_percent')." / 100) as weighted"; $sql.= " FROM " . MAIN_DB_PREFIX . "projet as t LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls ON cls.rowid = t.fk_opp_status"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql.= $this->buildWhere(); $sql.= " GROUP BY year"; @@ -124,14 +127,14 @@ class ProjectStats extends Stats return $this->_getAllByYear($sql); } - - + + /** * Build the where part - * + * * @return string */ - public function buildWhere() + public function buildWhere() { $sqlwhere_str = ''; $sqlwhere = array(); @@ -163,7 +166,7 @@ class ProjectStats extends Stats * @param int $year scan * @return array of values */ - function getNbByMonth($year) + function getNbByMonth($year) { global $user; @@ -171,7 +174,7 @@ class ProjectStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; @@ -190,7 +193,7 @@ class ProjectStats extends Stats * @param int $year scan * @return array with amount by month */ - function getAmountByMonth($year) + function getAmountByMonth($year) { global $user; @@ -198,7 +201,7 @@ class ProjectStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount)"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; @@ -313,7 +316,7 @@ class ProjectStats extends Stats * @param int $wonlostfilter Add a filter on status won/lost * @return array Array with amount by month */ - function getWeightedAmountByMonth($year, $wonlostfilter=1) + function getWeightedAmountByMonth($year, $wonlostfilter=1) { global $user; @@ -321,7 +324,7 @@ class ProjectStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount * ".$this->db->ifsql("t.opp_percent IS NULL".($wonlostfilter?" OR cls.code IN ('WON','LOST')":""), '0', 't.opp_percent')." / 100)"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t LEFT JOIN ".MAIN_DB_PREFIX.'c_lead_status as cls ON t.fk_opp_status = cls.rowid'; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; @@ -421,7 +424,7 @@ class ProjectStats extends Stats * @param int $year scan * @return array with amount by month */ - function getTransformRateByMonth($year) + function getTransformRateByMonth($year) { global $user; @@ -429,7 +432,7 @@ class ProjectStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; @@ -441,7 +444,7 @@ class ProjectStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.opp_amount)"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as t"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; diff --git a/htdocs/projet/class/taskstats.class.php b/htdocs/projet/class/taskstats.class.php index c0a0530bc75..b71c88f3d6b 100644 --- a/htdocs/projet/class/taskstats.class.php +++ b/htdocs/projet/class/taskstats.class.php @@ -51,11 +51,13 @@ class TaskStats extends Stats { global $conf, $user, $langs; - $datay = array (); + $datay = array(); $sql = "SELECT"; $sql .= " COUNT(t.rowid), t.priority"; $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; + if (! $user->rights->societe->client->voir && ! $user->soc_id) + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); //$sql .= " AND t.fk_statut <> 0"; // We want historic also, so all task not draft $sql .= " GROUP BY t.priority"; @@ -112,7 +114,7 @@ class TaskStats extends Stats $sql = "SELECT date_format(t.datec,'%Y') as year, COUNT(t.rowid) as nb"; $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql.= $this->buildWhere(); $sql.= " GROUP BY year"; @@ -167,7 +169,7 @@ class TaskStats extends Stats $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(t.rowid) as nb"; $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) + if (! $user->rights->societe->client->voir && ! $user->soc_id) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; $sql .= $this->buildWhere(); $sql .= " GROUP BY dm"; @@ -179,293 +181,4 @@ class TaskStats extends Stats // var_dump($res);print '
'; return $res; } - - /** - * Return the Task amount by month for a year - * - * @param int $year scan - * @return array with amount by month - */ - /* - function getAmountByMonth($year) - { - global $user; - - $this->yearmonth = $year; - - $sql = "SELECT date_format(t.datec,'%m') as dm, COUNT(t.rowid)"; - $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; - $sql .= $this->buildWhere(); - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - $this->yearmonth=0; - - $res = $this->_getAmountByMonth($year, $sql); - // var_dump($res);print '
'; - return $res; - }*/ - - - /** - * Return amount of elements by month for several years - * - * @param int $endyear Start year - * @param int $startyear End year - * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) - * @param int $wonlostfilter Add a filter on status won/lost - * @return array Array of values - */ - /* - function getWeightedAmountByMonthWithPrevYear($endyear,$startyear,$cachedelay=0,$wonlostfilter=1) - { - global $conf,$user,$langs; - - if ($startyear > $endyear) return -1; - - $datay=array(); - - // Search into cache - if (! empty($cachedelay)) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; - } - - $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_user'.$user->id.'.cache'; - $newmask='0644'; - - $nowgmt = dol_now(); - - $foundintocache=0; - if ($cachedelay > 0) - { - $filedate=dol_filemtime($newpathofdestfile); - if ($filedate >= ($nowgmt - $cachedelay)) - { - $foundintocache=1; - - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; - } - else - { - dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); - } - } - - // Load file into $data - if ($foundintocache) // Cache file found and is not too old - { - dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); - $data = json_decode(file_get_contents($newpathofdestfile), true); - } - else - { - $year=$startyear; - while($year <= $endyear) - { - $datay[$year] = $this->getWeightedAmountByMonth($year,$wonlostfilter); - $year++; - } - - $data = array(); - // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) - for ($i = 0 ; $i < 12 ; $i++) - { - $data[$i][]=$datay[$endyear][$i][0]; // set label - $year=$startyear; - while($year <= $endyear) - { - $data[$i][]=$datay[$year][$i][1]; // set yval for x=i - $year++; - } - } - } - - // Save cache file - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) - { - dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); - if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); - $fp = fopen($newpathofdestfile, 'w'); - if ($fp) - { - fwrite($fp, json_encode($data)); - fclose($fp); - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; - @chmod($newpathofdestfile, octdec($newmask)); - } - else dol_syslog("Failed to write cache file", LOG_ERR); - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; - } - - return $data; - } - */ - - - /** - * Return the Task weighted opp amount by month for a year. - * - * @param int $year Year to scan - * @param int $wonlostfilter Add a filter on status won/lost - * @return array Array with amount by month - */ - /* - function getWeightedAmountByMonth($year, $wonlostfilter=1) - { - global $user; - - $this->yearmonth = $year; - - $sql = "SELECT date_format(t.datec,'%m') as dm"; - $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; - $sql .= $this->buildWhere(); - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - $this->yearmonth=0; - - $res = $this->_getAmountByMonth($year, $sql); - // var_dump($res);print '
'; - return $res; - }*/ - - /** - * Return amount of elements by month for several years - * - * @param int $endyear End year - * @param int $startyear Start year - * @param int $cachedelay accept for cache file (0=No read, no save of cache, -1=No read but save) - * @return array of values - */ - /* - function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0) - { - global $conf, $user, $langs; - - if ($startyear > $endyear) return - 1; - - $datay = array(); - - // Search into cache - if (! empty($cachedelay)) - { - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - include_once DOL_DOCUMENT_ROOT . '/core/lib/json.lib.php'; - } - - $newpathofdestfile = $conf->user->dir_temp . '/' . get_class($this) . '_' . __FUNCTION__ . '_' . (empty($this->cachefilesuffix) ? '' : $this->cachefilesuffix . '_') . $langs->defaultlang . '_user' . $user->id . '.cache'; - $newmask = '0644'; - - $nowgmt = dol_now(); - - $foundintocache = 0; - if ($cachedelay > 0) { - $filedate = dol_filemtime($newpathofdestfile); - if ($filedate >= ($nowgmt - $cachedelay)) { - $foundintocache = 1; - - $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $filedate; - } else { - dol_syslog(get_class($this) . '::' . __FUNCTION__ . " cache file " . $newpathofdestfile . " is not found or older than now - cachedelay (" . $nowgmt . " - " . $cachedelay . ") so we can't use it."); - } - } - - // Load file into $data - if ($foundintocache) // Cache file found and is not too old - { - dol_syslog(get_class($this) . '::' . __FUNCTION__ . " read data from cache file " . $newpathofdestfile . " " . $filedate . "."); - $data = json_decode(file_get_contents($newpathofdestfile), true); - } else { - $year = $startyear; - while ( $year <= $endyear ) { - $datay[$year] = $this->getTransformRateByMonth($year); - $year ++; - } - - $data = array (); - // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) - for($i = 0; $i < 12; $i ++) { - $data[$i][] = $datay[$endyear][$i][0]; // set label - $year = $startyear; - while ( $year <= $endyear ) { - $data[$i][] = $datay[$year][$i][1]; // set yval for x=i - $year ++; - } - } - } - - // Save cache file - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == - 1)) { - dol_syslog(get_class($this) . '::' . __FUNCTION__ . " save cache file " . $newpathofdestfile . " onto disk."); - if (! dol_is_dir($conf->user->dir_temp)) - dol_mkdir($conf->user->dir_temp); - $fp = fopen($newpathofdestfile, 'w'); - fwrite($fp, json_encode($data)); - fclose($fp); - if (! empty($conf->global->MAIN_UMASK)) - $newmask = $conf->global->MAIN_UMASK; - @chmod($newpathofdestfile, octdec($newmask)); - - $this->_lastfetchdate[get_class($this) . '_' . __FUNCTION__] = $nowgmt; - } - - return $data; - }*/ - - /** - * Return the Task transformation rate by month for a year - * - * @param int $year scan - * @return array with amount by month - */ - /* - function getTransformRateByMonth($year) - { - global $user; - - $this->yearmonth = $year; - - $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.rowid)"; - $sql.= " FROM ". MAIN_DB_PREFIX . "projet_task as t INNER JOIN " . MAIN_DB_PREFIX . "projet as p ON p.rowid = t.fk_projet"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; - $sql .= $this->buildWhere(); - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - $res_total = $this->_getNbByMonth($year, $sql); - - $this->status=6; - - $sql = "SELECT date_format(t.datec,'%m') as dm, count(t.rowid)"; - $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task as t"; - if (! $user->rights->societe->client->voir && ! $user->societe_id) - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id; - $sql .= $this->buildWhere(); - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - $this->status=0; - $this->yearmonth=0; - - $res_only_wined = $this->_getNbByMonth($year, $sql); - - $res=array(); - - foreach($res_total as $key=>$total_row) { - //var_dump($total_row); - if (!empty($total_row[1])) { - $res[$key]=array($total_row[0],(100*$res_only_wined[$key][1])/$total_row[1]); - } else { - $res[$key]=array($total_row[0],0); - } - - } - // var_dump($res);print '
'; - return $res; - }*/ } From 9e629bdb0290561813a1ebe22d40828132301c6a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 20:01:25 +0200 Subject: [PATCH 58/66] Work on modulebuilder --- htdocs/core/class/interfaces.class.php | 14 +++++++------- htdocs/core/lib/functions.lib.php | 1 + .../modulebuilder/template/img/object_mytest.png | Bin 0 -> 360 bytes htdocs/theme/eldy/style.css.php | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 htdocs/modulebuilder/template/img/object_mytest.png diff --git a/htdocs/core/class/interfaces.class.php b/htdocs/core/class/interfaces.class.php index cd4a56f4174..625b30e3ac2 100644 --- a/htdocs/core/class/interfaces.class.php +++ b/htdocs/core/class/interfaces.class.php @@ -76,14 +76,14 @@ class Interfaces global $db; $user = new User($db); } - + $nbfile = $nbtotal = $nbok = $nbko = 0; $files = array(); $modules = array(); $orders = array(); $i=0; - + $dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']); foreach($dirtriggers as $reldir) { @@ -106,7 +106,7 @@ class Interfaces $part3=$reg[3]; $nbfile++; - + // Check if trigger file is disabled by name if (preg_match('/NORUN$/i',$file)) continue; // Check if trigger file is for a particular module @@ -132,7 +132,7 @@ class Interfaces dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger", $newdir."/".$file, $fullpathfiles[$modName]), LOG_WARNING); continue; } - + try { //print 'Todo for '.$modName." : ".$newdir.'/'.$file."\n"; include_once $newdir.'/'.$file; @@ -142,7 +142,7 @@ class Interfaces { dol_syslog('ko for '.$modName." ".$e->getMessage()."\n", LOG_ERR); } - + $modules[$i] = $modName; $files[$i] = $file; $fullpathfiles[$modName] = $newdir.'/'.$file; @@ -155,7 +155,7 @@ class Interfaces } asort($orders); - + // Loop on each trigger foreach ($orders as $key => $value) { @@ -246,7 +246,7 @@ class Interfaces { $dirtriggers=$forcedirtriggers; } - + foreach($dirtriggers as $reldir) { $dir=dol_buildpath($reldir,0); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ef03b0c00cc..3569cdd006d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2556,6 +2556,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ $picto = $regs[1]; $path = $regs[2]; // $path is $mymodule } + // Clean parameters if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto .= '.png'; // If alt path are defined, define url where img file is, according to physical path diff --git a/htdocs/modulebuilder/template/img/object_mytest.png b/htdocs/modulebuilder/template/img/object_mytest.png new file mode 100644 index 0000000000000000000000000000000000000000..5a307bfc62f85df909a3cf024f27ee87d44be275 GIT binary patch literal 360 zcmeAS@N?(olHy`uVBq!ia0vp^d?3uh1|;P@bT0xamSQK*5Dp-y;YjHK@;M7UB8!3Q zuY)k7lg8`{prB-lYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&Kt)eIT^vI+ zChono-m4{0gyqBiz=Ju)w^;&N<{#X1a0!1>bC%GsW3bBL=<%|p84;9-@5SwA|2OIEL% zb=QtBT0T9C&(LA{syqXqqW_DHn`b;(x5}@uA-g2{Ncy)Mhpp~Sy0eY()*3IP6|4C4 z(mDEHWvtPCEP7WZe7{4e?P9&>AE%^j|Mz!&9rL?{G_w^d>;^y&GkCiCxvX Date: Fri, 2 Jun 2017 20:17:08 +0200 Subject: [PATCH 59/66] Init of the onlinesign --- htdocs/public/onlinesign/newonlinesign.php | 640 +++++++++++++++++++++ 1 file changed, 640 insertions(+) create mode 100644 htdocs/public/onlinesign/newonlinesign.php diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php new file mode 100644 index 00000000000..73d9f41eab0 --- /dev/null +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -0,0 +1,640 @@ + + * Copyright (C) 2006-2017 Laurent Destailleur + * Copyright (C) 2009-2012 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * For paypal test: https://developer.paypal.com/ + * For paybox test: ??? + */ + +/** + * \file htdocs/public/onlinesign/newsign.php + * \ingroup core + * \brief File to offer a way to make an online signature for a particular Dolibarr entity + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +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)); +if (is_numeric($entity)) define("DOLENTITY", $entity); + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + +// Security check +// No check on module enabled. Done later according to $validpaymentmethod + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("errors"); +$langs->load("paybox"); // File with generic data + +$action=GETPOST('action','alpha'); + +// Input are: +// type ('invoice','order','contractline'), +// id (object id), +// amount (required if id is empty), +// tag (a free text, required if type is empty) +// currency (iso code) + +$suffix=GETPOST("suffix",'alpha'); +$SOURCE=GETPOST("source",'alpha'); +$ref=$REF=GETPOST("ref",'alpha'); + +if (! $action) +{ + if ($source && ! $ref) + { + dol_print_error('',$langs->trans('ErrorBadParameters')." - ref"); + exit; + } +} + + +$paymentmethod=''; +$validpaymentmethod=array(); + + + + +// 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. For Paypal payment, we can use internal URL like localhost. + + +// Complete urls for post treatment +$SECUREKEY=GETPOST("securekey"); // Secure key + +if (! empty($SOURCE)) +{ + $urlok.='source='.urlencode($SOURCE).'&'; + $urlko.='source='.urlencode($SOURCE).'&'; +} +if (! empty($REF)) +{ + $urlok.='ref='.urlencode($REF).'&'; + $urlko.='ref='.urlencode($REF).'&'; +} +if (! empty($SECUREKEY)) +{ + $urlok.='securekey='.urlencode($SECUREKEY).'&'; + $urlko.='securekey='.urlencode($SECUREKEY).'&'; +} +if (! empty($entity)) +{ + $urlok.='entity='.urlencode($entity).'&'; + $urlko.='entity='.urlencode($entity).'&'; +} +$urlok=preg_replace('/&$/','',$urlok); // Remove last & +$urlko=preg_replace('/&$/','',$urlko); // Remove last & + + + + +/* + * Actions + */ + + +if ($action == 'dosign') +{ + // TODO + +} + + +/* + * View + */ + +$head=''; +if (! empty($conf->global->MAIN_SIGN_CSS_URL)) $head=''."\n"; + +$conf->dol_hide_topmenu=1; +$conf->dol_hide_leftmenu=1; + +llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); + +// Check link validity +if (! empty($SOURCE) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) +{ + $langs->load("errors"); + dol_print_error_email('BADREFINONLINESIGNFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); + llxFooter(); + $db->close(); + exit; +} + +print ''."\n"; +print '
'."\n"; +print '
'."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''; +print "\n"; +print ''."\n"; + +print ''."\n"; + +// Show logo (search order: logo defined by PAYBOX_LOGO_suffix, then PAYBOX_LOGO, then small company logo, large company logo, theme logo, common logo) +$width=0; +// Define logo and logosmall +$logosmall=$mysoc->logo_small; +$logo=$mysoc->logo; +$paramlogo='ONLINE_SIGN_LOGO_'.$suffix; +if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo; +else if (! empty($conf->global->ONLINE_SIGN_LOGO)) $logosmall=$conf->global->ONLINE_SIGN_LOGO; +//print ''."\n"; +// Define urllogo +$urllogo=''; +if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) +{ + $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode('thumbs/'.$logosmall); +} +elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) +{ + $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode($logo); + $width=96; +} +// Output html code for logo +if ($urllogo) +{ + print ''; + print ''; + print ''."\n"; +} + +// Output introduction text +$text=''; +if (! empty($conf->global->ONLINE_SIGN_NEWFORM_TEXT)) +{ + $langs->load("members"); + if (preg_match('/^\((.*)\)$/',$conf->global->ONLINE_SIGN_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."
\n"; + else $text.=$conf->global->ONLINE_SIGN_NEWFORM_TEXT."
\n"; + $text=''."\n"; +} +if (empty($text)) +{ + $text.=''."\n"; + $text.=''."\n"; +} +print $text; + +// Output payment summary form +print ''."\n"; + +print '

'.$text.'

'.$langs->trans("WelcomeOnOnlineSignaturePage").'

'.$langs->trans("ThisScreenAllowsYouToSignDocFrom",$creditor).'

'; +print ''; +print ''."\n"; + +$found=false; +$error=0; +$var=false; + +// Free payment +if (! GETPOST("source")) +{ + $found=true; + $tag=GETPOST("tag"); + $fulltag=$tag; + + // Creditor + + print ''."\n"; + + + + // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum + // as they don't exists (buyer is unknown, tag is free). +} + + +// Payment on customer order +if (GETPOST("source") == 'order') +{ + $found=true; + $langs->load("orders"); + + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + + $order=new Commande($db); + $result=$order->fetch('',$ref); + if ($result < 0) + { + $mesg=$order->error; + $error++; + } + else + { + $result=$order->fetch_thirdparty($order->socid); + } + + // Creditor + + print ''."\n"; + + // Debitor + + print ''."\n"; + + +} + + +// Payment on customer invoice +if (GETPOST("source") == 'invoice') +{ + $found=true; + $langs->load("bills"); + + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + + $invoice=new Facture($db); + $result=$invoice->fetch('',$ref); + if ($result < 0) + { + $mesg=$invoice->error; + $error++; + } + else + { + $result=$invoice->fetch_thirdparty($invoice->socid); + } + + if ($action != 'dosign') // Do not change amount if we just click on first dosign + { + $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); + if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); + $amount=price2num($amount); + } + + // Creditor + + print ''."\n"; + + // Debitor + + print ''."\n"; + +} + +// Payment on contract line +if (GETPOST("source") == 'contractline') +{ + $found=true; + $langs->load("contracts"); + + require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; + + $contractline=new ContratLigne($db); + $result=$contractline->fetch('',$ref); + if ($result < 0) + { + $mesg=$contractline->error; + $error++; + } + else + { + if ($contractline->fk_contrat > 0) + { + $contract=new Contrat($db); + $result=$contract->fetch($contractline->fk_contrat); + if ($result > 0) + { + $result=$contract->fetch_thirdparty($contract->socid); + } + else + { + $mesg=$contract->error; + $error++; + } + } + else + { + $mesg='ErrorRecordNotFound'; + $error++; + } + } + + if ($action != 'dosign') // Do not change amount if we just click on first dosign + { + $amount=$contractline->total_ttc; + if ($contractline->fk_product) + { + $product=new Product($db); + $result=$product->fetch($contractline->fk_product); + + // We define price for product (TODO Put this in a method in product class) + if (! empty($conf->global->PRODUIT_MULTIPRICES)) + { + $pu_ht = $product->multiprices[$contract->thirdparty->price_level]; + $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level]; + $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level]; + } + else + { + $pu_ht = $product->price; + $pu_ttc = $product->price_ttc; + $price_base_type = $product->price_base_type; + } + + $amount=$pu_ttc; + if (empty($amount)) + { + dol_print_error('','ErrorNoPriceDefinedForThisProduct'); + exit; + } + } + if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); + $amount=price2num($amount); + } + + $qty=1; + if (GETPOST('qty')) $qty=GETPOST('qty'); + + // Creditor + + print ''."\n"; + + // Debitor + + print ''."\n"; + + // Quantity + + $label=$langs->trans("Quantity"); + $qty=1; + $duration=''; + if ($contractline->fk_product) + { + if ($product->isService() && $product->duration_value > 0) + { + $label=$langs->trans("Duration"); + + // TODO Put this in a global method + if ($product->duration_value > 1) + { + $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears")); + } + else + { + $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear")); + } + $duration=$product->duration_value.' '.$dur[$product->duration_unit]; + } + } + print ''; + print ''."\n"; + + // Amount + + print ''."\n"; + +} + +// Payment on member subscription +if (GETPOST("source") == 'membersubscription') +{ + $found=true; + $langs->load("members"); + + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; + + $member=new Adherent($db); + $result=$member->fetch('',$ref); + if ($result < 0) + { + $mesg=$member->error; + $error++; + } + else + { + $subscription=new Subscription($db); + } + + if ($action != 'dosign') // Do not change amount if we just click on first dosign + { + $amount=$subscription->total_ttc; + if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); + $amount=price2num($amount); + } + + $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); + if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } + $fulltag=dol_string_unaccent($fulltag); + + // Creditor + + print ''."\n"; + + // Debitor + + print ''."\n"; + + if ($member->last_subscription_date || $member->last_subscription_amount) + { + // Last subscription date + + print ''."\n"; + + // Last subscription amount + + print ''."\n"; + + if (empty($amount) && ! GETPOST('newamount')) $_GET['newamount']=$member->last_subscription_amount; + } + + // Amount + + print ''."\n"; + +} + + + + +if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters"); + +if ($mesg) print ''."\n"; + +print '
'.$langs->trans("ThisIsInformationOnDocumentToSign").' :
'.$langs->trans("Creditor"); + print ''.$creditor.''; + print ''; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.''; + print ''; + print '
'.$langs->trans("ThirdParty"); + print ''.$order->thirdparty->name.''; + + // Object + + $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print ''; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.''; + print ''; + print '
'.$langs->trans("ThirdParty"); + print ''.$invoice->thirdparty->name.''; + + // Object + + $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print ''; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.''; + print ''; + print '
'.$langs->trans("ThirdParty"); + print ''.$contract->thirdparty->name.''; + + // Object + + $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; + if ($contractline->fk_product) + { + $text.='
'.$product->ref.($product->label?' - '.$product->label:''); + } + if ($contractline->description) $text.='
'.dol_htmlentitiesbr($contractline->description); + //if ($contractline->date_fin_validite) { + // $text.='
'.$langs->trans("DateEndPlanned").': '; + // $text.=dol_print_date($contractline->date_fin_validite); + //} + if ($contractline->date_fin_validite) + { + $text.='
'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite); + } + + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print ''; + print '
'.$label.''.($duration?$duration:$qty).''; + print ''; + print '
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) + { + print ''; + print ''; + } + else { + print ''.price($amount).''; + print ''; + print ''; + } + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.''; + print ''; + print '
'.$langs->trans("Member"); + print ''; + if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; + else print $member->getFullName($langs); + print ''; + + // Object + + $text=''.$langs->trans("PaymentSubscription").''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print ''; + print '
'.$langs->trans("LastSubscriptionDate"); + print ''.dol_print_date($member->last_subscription_date,'day'); + print '
'.$langs->trans("LastSubscriptionAmount"); + print ''.price($member->last_subscription_amount); + print '
'.$langs->trans("Amount"); + if (empty($amount)) + { + print ' ('.$langs->trans("ToComplete"); + if (! empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) print ' - '.$langs->trans("SeeHere").''; + print ')'; + } + print ''; + if (empty($amount) || ! is_numeric($amount)) + { + $valtoshow=GETPOST("newamount",'int'); + if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); + print ''; + print ''; + } + else { + $valtoshow=$amount; + if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); + print ''.price($valtoshow).''; + print ''; + print ''; + } + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; + print '

'.$mesg.'
'."\n"; +print "\n"; + +if ($action != 'dosign') +{ + if ($found && ! $error) // We are in a management option and no error + { + + + } + else + { + dol_print_error_email('ERRORNEWONLINESIGNPAYPAL'); + } +} +else +{ + // Print +} + +print '
'."\n"; +print '
'."\n"; +print '
'."\n"; +print '
'; + + +htmlPrintOnlinePaymentFooter($mysoc,$langs); + +llxFooter('', 'public'); + +$db->close(); From 70a188c0421045c87a07d6df39f15e5fc9727c1b Mon Sep 17 00:00:00 2001 From: atm-ph Date: Fri, 2 Jun 2017 21:45:02 +0200 Subject: [PATCH 60/66] Fix missing column entity on llx_accounting_journal after init demo with the bash --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 11a86724cf0..4680d451e39 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 @@ -159,6 +159,9 @@ CREATE TABLE llx_product_attribute_combination ALTER TABLE llx_bank_account drop foreign key bank_fk_accountancy_journal; +-- Fix missing entity column after init demo +ALTER TABLE llx_accounting_journal ADD COLUMN entity integer DEFAULT 1; + -- Add journal entries INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (1,'VT', 'Sale journal', 2, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (2,'AC', 'Purchase journal', 3, 1); @@ -355,4 +358,4 @@ delete from llx_categorie_member where fk_categorie not in (select rowid from ll delete from llx_categorie_contact where fk_categorie not in (select rowid from llx_categorie where type = 4); delete from llx_categorie_project where fk_categorie not in (select rowid from llx_categorie where type = 5); -ALTER TABLE llx_inventory ADD COLUMN ref varchar(48); \ No newline at end of file +ALTER TABLE llx_inventory ADD COLUMN ref varchar(48); From 66420d0e80d8fb3e43ffa4c96373154d2f7c779c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 23:02:48 +0200 Subject: [PATCH 61/66] Restore lost file and better generation of modules --- htdocs/core/actions_setmoduleoptions.inc.php | 86 +++++++++++++++ htdocs/core/class/hookmanager.class.php | 17 +-- htdocs/core/class/html.form.class.php | 19 +++- htdocs/core/modules/DolibarrModules.class.php | 102 ++++++++++-------- .../template/langs/en_US/mymodule.lang | 10 +- .../template/langs/fr_FR/mymodule.lang | 10 +- 6 files changed, 173 insertions(+), 71 deletions(-) create mode 100644 htdocs/core/actions_setmoduleoptions.inc.php diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php new file mode 100644 index 00000000000..03b33b19eb1 --- /dev/null +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -0,0 +1,86 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/actions_setnotes.inc.php + * \brief Code for actions on setting notes of object page + */ + + +// $action must be defined +// $_FILES may be defined +// $nomessageinsetmoduleoptions can be set to 1 + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $db->begin(); + + // Process common param fields + foreach($_POST as $key => $val) + { + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + { + $param=GETPOST("param".$reg[1],'alpha'); + $value=GETPOST("value".$reg[1],'alpha'); + if ($param) + { + $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + } + + // Process upload fields + if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09')) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $keyforuploaddir=GETPOST('keyforuploaddir','aZ09'); + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir))); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); + else + { + $upload_dir=$tmpdir; + } + } + if ($upload_dir) + { + $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); + if ($result <= 0) $error++; + } + } + + if (! $error) + { + $db->commit(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); + } +} + diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 590f8060296..1e20ee6ce31 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -133,10 +133,12 @@ class HookManager if (in_array( $method, array( - 'addMoreActionsButtons', + 'addCalendarChoice', + 'addMoreActionsButtons', + 'addMoreMassActions', 'addSearchEntry', 'addStatisticLine', - 'deleteFile', + 'deleteFile', 'doActions', 'formCreateThirdpartyOptions', 'formObjectOptions', @@ -169,7 +171,6 @@ class HookManager 'printSearchForm', 'printTabsHead', 'formatEvent', - 'addCalendarChoice', 'printObjectLine', 'printObjectSubLine', 'createDictionaryFieldList', @@ -181,14 +182,16 @@ class HookManager if ($method == 'insertExtraFields') { - $hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. + $hooktype='returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING); } + // Init return properties + $this->resPrint=''; $this->resArray=array(); + // Loop on each hook to qualify modules that have declared context $modulealreadyexecuted=array(); $resaction=0; $error=0; $result=''; - $this->resPrint=''; $this->resArray=array(); foreach($this->hooks as $context => $modules) // $this->hooks is an array with context as key and value is an array of modules that handle this context { if (! empty($modules)) @@ -202,9 +205,9 @@ class HookManager // test to avoid running twice a hook, when a module implements several active contexts if (in_array($module,$modulealreadyexecuted)) continue; - + dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context); - + $modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice // Clean class (an error may have been set from a previous call of another method for same module/hook) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 34693cba67a..997bc94cc42 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -545,11 +545,20 @@ class Form $disabled=0; $ret='
'; $ret.=''; // Warning: if you set submit button to disabled, post using 'Enter' will no more work. $ret.=''; diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 71de341a769..a79f17b1fdc 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -50,13 +50,13 @@ class DolibarrModules // Can not be abstract, because we need to insta * @since 4.0.0 */ public $editor_name; - + /** * @var string URL of module at publisher site * @since 4.0.0 */ public $editor_url; - + /** * @var string Family * @see familyinfo @@ -80,13 +80,13 @@ class DolibarrModules // Can not be abstract, because we need to insta * */ public $familyinfo; - + /** * @var int Module position * @since 3.9.0 */ public $module_position=500; - + /** * @var string Module name * @@ -214,7 +214,7 @@ class DolibarrModules // Can not be abstract, because we need to insta * HTML content supported. */ public $descriptionlong; - + /** * @var string Module export code */ @@ -249,7 +249,7 @@ class DolibarrModules // Can not be abstract, because we need to insta * @var bool Module is enabled globally (Multicompany support) */ public $core_enabled; - + /** * @var string Relative path to module style sheet * @deprecated @@ -286,7 +286,7 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $config_page_url; - + /** * @var string[] List of module class names that must be enabled if this module is enabled. * @@ -309,22 +309,22 @@ class DolibarrModules // Can not be abstract, because we need to insta * @var string[] Module language files */ public $langfiles; - + /** * @var string[] Array of warnings to show when we activate the module - * + * * array('always'='text') or array('FR'='text') */ public $warnings_activation; - + /** * @var string[] Array of warnings to show when we activate an external module - * + * * array('always'='text') or array('FR'='text') */ public $warnings_activation_ext; - - + + /** * @var array() Minimum version of PHP required by module. * e.g.: PHP ≥ 5.3 = array(5, 3) @@ -342,7 +342,7 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $hidden = false; - + /** * Constructor. Define names, constants, directories, boxes, permissions * @@ -538,8 +538,8 @@ class DolibarrModules // Can not be abstract, because we need to insta return $langs->trans("Module".$this->numero."Name"); } else - { - // If module name translation using it's unique id does not exists, we take use its name to find translation + { + // If module name translation using it's unique id does not exists, we try to use its name to find translation if (is_array($this->langfiles)) { foreach($this->langfiles as $val) @@ -547,6 +547,14 @@ class DolibarrModules // Can not be abstract, because we need to insta if ($val) $langs->load($val); } } + + if ($langs->trans("Module".$this->name."Name") != ("Module".$this->name."Name")) + { + // If module name translation exists + return $langs->trans("Module".$this->name."Name"); + } + + // Last change with simple product label return $langs->trans($this->name); } } @@ -591,13 +599,13 @@ class DolibarrModules // Can not be abstract, because we need to insta { global $langs; $langs->load("admin"); - + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; $filefound= false; - - // Define path to file README.md. + + // Define path to file README.md. // First check README-la_LA.md then README.md $pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0); if (dol_is_file($pathoffile)) @@ -612,11 +620,11 @@ class DolibarrModules // Can not be abstract, because we need to insta $filefound = true; } } - + if ($filefound) // Mostly for external modules { $content = file_get_contents($pathoffile); - + if ((float) DOL_VERSION >= 6.0) { @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php'; @@ -638,14 +646,14 @@ class DolibarrModules // Can not be abstract, because we need to insta if ($val) $langs->load($val); } } - + $content = $langs->trans($this->descriptionlong); } } - + return $content; } - + /** * Gives the publisher name * @@ -655,7 +663,7 @@ class DolibarrModules // Can not be abstract, because we need to insta { return $this->editor_name; } - + /** * Gives the publisher url * @@ -665,7 +673,7 @@ class DolibarrModules // Can not be abstract, because we need to insta { return $this->editor_url; } - + /** * Gives module version (translated if param $translated is on) * For 'experimental' modules, gives 'experimental' translation @@ -768,7 +776,7 @@ class DolibarrModules // Can not be abstract, because we need to insta } } - + /** * Gives the last date of activation * @@ -777,11 +785,11 @@ class DolibarrModules // Can not be abstract, because we need to insta function getLastActivationDate() { global $conf; - + $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'"; $sql.= " AND entity IN (0, ".$conf->entity.")"; - + dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) $err++; @@ -790,11 +798,11 @@ class DolibarrModules // Can not be abstract, because we need to insta $obj=$this->db->fetch_object($resql); if ($obj) return $this->db->jdate($obj->tms); } - + return ''; } - - + + /** * Gives the last author of activation * @@ -803,11 +811,11 @@ class DolibarrModules // Can not be abstract, because we need to insta function getLastActivationInfo() { global $conf; - + $sql = "SELECT tms, note FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'"; $sql.= " AND entity IN (0, ".$conf->entity.")"; - + dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) $err++; @@ -821,11 +829,11 @@ class DolibarrModules // Can not be abstract, because we need to insta } if ($obj) return array('authorid'=>$tmp['authorid'], 'ip'=>$tmp['ip'], 'lastactivationdate'=>$this->db->jdate($obj->tms)); } - + return array(); } - - + + /** * Insert constants for module activation * @@ -929,7 +937,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') { @@ -947,7 +955,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') { @@ -965,7 +973,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data') { @@ -983,7 +991,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update') { @@ -1123,19 +1131,19 @@ class DolibarrModules // Can not be abstract, because we need to insta //$titre = $this->boxes[$key][0]; $file = $this->boxes[$key]['file']; //$note = $this->boxes[$key][2]; - + // TODO If the box is also included by another module and the other module is still on, we should not remove it. // For the moment, we manage this with hard coded exception //print "Remove box ".$file.'
'; if ($file == 'box_graph_product_distribution.php') { - if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) + if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) { dol_syslog("We discard disabling of module ".$file." because another module still active require it."); continue; } } - + if (empty($file)) $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:''; // For backward compatibility if ($this->db->type == 'sqlite3') { @@ -1210,7 +1218,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:''; $priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:''; $test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:''; // Line must be visible - + // Search if boxes def already present $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob"; $sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'"; @@ -1645,7 +1653,7 @@ class DolibarrModules // Can not be abstract, because we need to insta /** * Removes access rights - * + * * @return int Error count (0 if OK) */ function delete_permissions() @@ -1678,7 +1686,7 @@ class DolibarrModules // Can not be abstract, because we need to insta global $user; if (! is_array($this->menu) || empty($this->menu)) return 0; - + require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php'; $err=0; diff --git a/htdocs/modulebuilder/template/langs/en_US/mymodule.lang b/htdocs/modulebuilder/template/langs/en_US/mymodule.lang index 53c6205386c..c33f2453fc4 100644 --- a/htdocs/modulebuilder/template/langs/en_US/mymodule.lang +++ b/htdocs/modulebuilder/template/langs/en_US/mymodule.lang @@ -18,12 +18,10 @@ # Generic # -# Module label 'ModuleXXXName' -# (where XXX is value of numeric property 'numero' of module) -Module500000Name = My module -# Module description 'ModuleXXXDesc' -# (where XXX is value of numeric property 'numero' of module) -Module500000Desc = My module description +# Module label 'ModuleMyModuleName' +ModuleMyModuleName = My module +# Module description 'ModuleMyModuleDesc' +ModuleMyModuleDesc = My module description # # Admin page diff --git a/htdocs/modulebuilder/template/langs/fr_FR/mymodule.lang b/htdocs/modulebuilder/template/langs/fr_FR/mymodule.lang index d15d37f0ebf..06e7ba33885 100644 --- a/htdocs/modulebuilder/template/langs/fr_FR/mymodule.lang +++ b/htdocs/modulebuilder/template/langs/fr_FR/mymodule.lang @@ -18,12 +18,10 @@ # Générique # -# Module label 'ModuleXXXName' -# (where XXX is value of numeric property 'numero' of module) -Module500000Name = Mon module -# Module description 'ModuleXXXDesc' -# (where XXX is value of numeric property 'numero' of module) -Module500000Desc = Description de mon module +# Module label 'ModuleMyModuleName' +ModuleMyModuleName = Mon module +# Module description 'ModuleMyModuleDesc' +ModuleMyModuleDesc = Description de mon module # # Page d'administration From 111087dfdc5b32330ab6b3d45fe1b5ca2586abf7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jun 2017 23:41:18 +0200 Subject: [PATCH 62/66] Work on module template --- htdocs/core/actions_massactions.inc.php | 49 +++++----- htdocs/core/class/hookmanager.class.php | 1 + htdocs/core/class/html.form.class.php | 2 +- .../template/class/actions_mymodule.class.php | 89 +++++++++++++++++-- 4 files changed, 113 insertions(+), 28 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 92d1011b923..fde828fd6d4 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -24,20 +24,22 @@ // $massaction must be defined // $objectclass and $$objectlabel must be defined -// $uploaddir (example $conf->projet->dir_output . "/";) +// $parameters, $object, $action must be defined for the hook. + +// $uploaddir may be defined (example to $conf->projet->dir_output."/";) // $toselect may be defined // Protection -if (empty($objectclass) || empty($uploaddir)) +if (empty($objectclass) || empty($uploaddir)) { dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined'); exit; } -// Mass actions. Controls on number of lines checked -$maxformassaction=1000; +// Mass actions. Controls on number of lines checked. +$maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS); if (! empty($massaction) && count($toselect) < 1) { $error++; @@ -87,7 +89,7 @@ if (! $error && $massaction == 'confirm_presend') } } //var_dump($listofobjectthirdparties);exit; - + foreach ($listofobjectthirdparties as $thirdpartyid) { $result = $thirdparty->fetch($thirdpartyid); @@ -144,7 +146,7 @@ if (! $error && $massaction == 'confirm_presend') { //var_dump($object); //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut); - + if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED) { $nbignored++; @@ -157,7 +159,7 @@ if (! $error && $massaction == 'confirm_presend') $resaction.='
'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'

'; continue; } - + // Read document // TODO Use future field $object->fullpathdoc to know where is stored default file // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. @@ -202,7 +204,7 @@ if (! $error && $massaction == 'confirm_presend') dol_syslog('Failed to read file: '.$file, LOG_WARNING); continue; } - + //var_dump($listofqualifiedref); } @@ -252,9 +254,9 @@ if (! $error && $massaction == 'confirm_presend') $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - + //var_dump($filepath); - + // Send mail require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1); @@ -280,7 +282,7 @@ if (! $error && $massaction == 'confirm_presend') if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO'; if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD'; if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/ - + $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; if ($message) { @@ -290,7 +292,7 @@ if (! $error && $massaction == 'confirm_presend') $actionmsg = dol_concatdesc($actionmsg, $message); } $actionmsg2=''; - + // Initialisation donnees $object->sendtoid = 0; $object->actionmsg = $actionmsg; // Long text @@ -335,7 +337,7 @@ if (! $error && $massaction == 'confirm_presend') $resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n
"; $resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n
"; $resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n
"; - + if ($nbsent) { $action=''; // Do not show form post if there was at least one successfull sent @@ -359,7 +361,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - + $objecttmp=new $objectclass($db); $listofobjectid=array(); $listofobjectthirdparties=array(); @@ -425,21 +427,21 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se if (count($files)>0) { - + $now=dol_now(); $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf'; - + $input_files = ''; foreach($files as $f) { $input_files.=' '.escapeshellarg($f); } - + $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file); exec($cmd); - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - + $langs->load("exports"); setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs'); } @@ -447,7 +449,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se { setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); } - + } else { // Create empty PDF @@ -481,7 +483,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se // Defined name of merged file $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel))); $filename=preg_replace('/\s/','_',$filename); - + // Save merged file if ($filter=='paye:0') { @@ -565,6 +567,11 @@ if (! $error && $massaction == 'delete' && $permtodelete) //var_dump($listofobjectthirdparties);exit; } +$parameters['toselect']=$toselect; +$parameters['uploaddir']=$uploaddir; + +$reshook=$hookmanager->executeHooks('doMassActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 1e20ee6ce31..40ed4153060 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -140,6 +140,7 @@ class HookManager 'addStatisticLine', 'deleteFile', 'doActions', + 'doMassActions', 'formCreateThirdpartyOptions', 'formObjectOptions', 'formattachOptions', diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 997bc94cc42..b14f72a1b7b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -546,7 +546,7 @@ class Form $ret='
'; $ret.=''; - // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['context'] completed by executeHooks. + // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks. $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreMassActions',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) diff --git a/htdocs/modulebuilder/template/class/actions_mymodule.class.php b/htdocs/modulebuilder/template/class/actions_mymodule.class.php index f3ce5963aa6..7f1897c80ae 100644 --- a/htdocs/modulebuilder/template/class/actions_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/actions_mymodule.class.php @@ -62,24 +62,101 @@ class ActionsMyModule */ public function doActions($parameters, &$object, &$action, $hookmanager) { + global $conf, $user, $langs; + $error = 0; // Error counter - $myvalue = 'test'; // A result value + /* print_r($parameters); - echo "action: " . $action; print_r($object); + echo "action: " . $action; + */ + + if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' + - if (in_array('somecontext', explode(':', $parameters['context']))) { - // do something only for the context 'somecontext' } if (! $error) { - $this->results = array('myreturn' => $myvalue); + $this->results = array('myreturn' => 999); $this->resprints = 'A text to show'; - return 0; // or return 1 to replace standard code + return 0; // or return 1 to replace standard code } else { $this->errors[] = 'Error message'; return -1; } } + + + /** + * Overloading the doActions function : replacing the parent's function with the one below + * + * @param array() $parameters Hook metadatas (context, etc...) + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int < 0 on error, 0 on success, 1 to replace standard code + */ + public function doMassActions($parameters, &$object, &$action, $hookmanager) + { + global $conf, $user, $langs; + + $error = 0; // Error counter + + /* + print_r($parameters); + print_r($object); + echo "action: " . $action; + */ + + if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' + + foreach($parameters['toselect'] as $objectid) + { + // Do action on each object id + + } + } + + if (! $error) { + $this->results = array('myreturn' => 999); + $this->resprints = 'A text to show'; + return 0; // or return 1 to replace standard code + } else { + $this->errors[] = 'Error message'; + return -1; + } + } + + + /** + * Overloading the addMoreMassActions function : replacing the parent's function with the one below + * + * @param array() $parameters Hook metadatas (context, etc...) + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int < 0 on error, 0 on success, 1 to replace standard code + */ + public function addMoreMassActions($parameters, &$object, &$action, $hookmanager) + { + global $conf, $user, $langs; + + $error = 0; // Error counter + + if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext' + { + $this->resprints = ''; + } + + if (! $error) { + return 0; // or return 1 to replace standard code + } else { + $this->errors[] = 'Error message'; + return -1; + } + } + + + } From af584bc9c01950efb993182bc5dab705645d5908 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Jun 2017 00:58:51 +0200 Subject: [PATCH 64/66] FIX #6880 #6925 --- htdocs/projet/card.php | 67 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index f69b54cffdc..727ef1d7fdd 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -134,7 +134,7 @@ if (empty($reshook)) $error++; setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors'); } - + if (! $error) { $error=0; @@ -308,8 +308,8 @@ if (empty($reshook)) setEventMessages($langs->trans("FailedToCloseProject").':'.$object->error, $object->errors, 'errors'); } } - - + + if ($error) { $db->rollback(); @@ -322,7 +322,7 @@ if (empty($reshook)) if (GETPOST('socid','int') > 0) $object->fetch_thirdparty(GETPOST('socid','int')); else unset($object->thirdparty); } - + } // Build doc @@ -619,7 +619,7 @@ if ($action == 'create' && $user->rights->projet->creer) { print '     '; print ''; - } + } print '
'; print ''; @@ -641,12 +641,12 @@ if ($action == 'create' && $user->rights->projet->creer) }); '; } -elseif ($object->id > 0) +elseif ($object->id > 0) { /* * Show or edit */ - + $res=$object->fetch_optionals($object->id,$extralabels); // To verify role of users @@ -828,26 +828,26 @@ elseif ($object->id > 0) else { // Project card - + $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref='
'; // Title $morehtmlref.=$object->title; // Thirdparty - if ($object->thirdparty->id > 0) + if ($object->thirdparty->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); @@ -881,18 +881,18 @@ elseif ($object->id > 0) if (strcmp($object->opp_amount,'')) print price($object->opp_amount,0,$langs,1,0,0,$conf->currency); print ''; } - + // Date start - end print ''.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").''; print dol_print_date($object->date_start,'day'); $end=dol_print_date($object->date_end,'day'); - if ($end) + if ($end) { print ' - '.$end; if ($object->hasDelay()) print img_warning($langs->trans('Late')); } print ''; - + // Budget print ''.$langs->trans("Budget").''; if (strcmp($object->budget_amount, '')) print price($object->budget_amount,0,$langs,1,0,0,$conf->currency); @@ -901,16 +901,16 @@ elseif ($object->id > 0) // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + print ''; - + print '
'; print '
'; print '
'; print '
'; - + print ''; - + // Description print '"; } - + print '
'.$langs->trans("Description").''; print nl2br($object->description); @@ -922,13 +922,13 @@ elseif ($object->id > 0) print $form->showCategories($object->id,'project',1); print "
'; - + print '
'; print '
'; print '
'; - + print '
'; } @@ -947,9 +947,10 @@ elseif ($object->id > 0) // Change probability from status if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + // Default value to close or not when we set opp to 'WON'. $defaultcheckedwhenoppclose=1; if (empty($conf->global->PROJECT_HIDE_TASKS)) $defaultcheckedwhenoppclose=0; - + print ''; print '