From 81f1a341120a85e97c718571ca5bf447a74c08c8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Jun 2017 13:06:35 +0200 Subject: [PATCH 01/13] Revert "Fix SPEC #7013 : use database type "numeric" to store monetary values" --- .../install/mysql/migration/6.0.0-7.0.0.sql | 64 ------------------- .../tables/llx_accounting_bookkeeping.sql | 10 +-- .../install/mysql/tables/llx_blockedlog.sql | 2 +- .../mysql/tables/llx_chargesociales.sql | 2 +- htdocs/install/mysql/tables/llx_commande.sql | 2 +- .../mysql/tables/llx_commande_fournisseur.sql | 2 +- htdocs/install/mysql/tables/llx_don.sql | 2 +- .../mysql/tables/llx_loan_schedule.sql | 6 +- .../mysql/tables/llx_paiementcharge.sql | 2 +- .../mysql/tables/llx_paiementfourn.sql | 2 +- .../mysql/tables/llx_payment_donation.sql | 2 +- .../tables/llx_payment_expensereport.sql | 2 +- .../install/mysql/tables/llx_payment_loan.sql | 6 +- .../mysql/tables/llx_payment_salary.sql | 4 +- .../mysql/tables/llx_prelevement_bons.sql | 2 +- .../llx_prelevement_facture_demande.sql | 2 +- .../mysql/tables/llx_prelevement_lignes.sql | 2 +- htdocs/install/mysql/tables/llx_societe.sql | 2 +- htdocs/install/mysql/tables/llx_tva.sql | 4 +- 19 files changed, 28 insertions(+), 92 deletions(-) delete mode 100644 htdocs/install/mysql/migration/6.0.0-7.0.0.sql diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql deleted file mode 100644 index 545b52ea4a7..00000000000 --- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql +++ /dev/null @@ -1,64 +0,0 @@ --- --- Be carefull to requests order. --- This file must be loaded by calling /install/index.php page --- when current version is 6.0.0 or higher. --- --- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; --- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; --- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); --- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; --- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); --- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; --- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table --- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex --- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y --- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y --- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; --- To make pk to be auto increment (postgres): -- VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE --- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL; --- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; --- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL; --- To set a field as NOT NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET NOT NULL; --- To set a field as default NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; --- Note: fields with type BLOB/TEXT can't have default value. --- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); --- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); - - --- Clean corrupted values for tms --- VMYSQL4.1 SET sql_mode = 'ALLOW_INVALID_DATES'; --- VMYSQL4.1 update llx_opensurvey_sondage set tms = date_fin where DATE(STR_TO_DATE(tms, '%Y-%m-%d')) IS NULL; --- VMYSQL4.1 SET sql_mode = 'NO_ZERO_DATE'; --- VMYSQL4.1 update llx_opensurvey_sondage set tms = date_fin where DATE(STR_TO_DATE(tms, '%Y-%m-%d')) IS NULL; --- Remove default not null on date_fin --- VMYSQL4.3 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN date_fin DATETIME NULL DEFAULT NULL; --- VPGSQL8.2 ALTER TABLE llx_opensurvey_sondage ALTER COLUMN date_fin DROP NOT NULL; - --- Move real to numeric for more precision for storing monetary amounts (no rouding) --- https://wiki.dolibarr.org/index.php/Langages_et_normes#Structure_des_tables_et_champs -ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN debit numeric(24,8); -ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN credit numeric(24,8); -ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN montant numeric(24,8); -ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN multicurrency_amount numeric(24,8); -ALTER TABLE llx_blockedlog MODIFY COLUMN amounts numeric(24,8); -ALTER TABLE llx_chargessociales MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_commande MODIFY COLUMN amount_ht numeric(24,8); -ALTER TABLE llx_commande_fournisseur MODIFY COLUMN amount_ht numeric(24,8); -ALTER TABLE llx_don MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_loan_schedule MODIFY COLUMN amount_capital numeric(24,8); -ALTER TABLE llx_loan_schedule MODIFY COLUMN amount_insurance numeric(24,8); -ALTER TABLE llx_loan_schedule MODIFY COLUMN amount_interest numeric(24,8); -ALTER TABLE llx_paiementcharge MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_paiementfourn MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_payment_donation MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_payment_expensereport MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_payment_loan MODIFY COLUMN amount_capital numeric(24,8); -ALTER TABLE llx_payment_loan MODIFY COLUMN amount_insurance numeric(24,8); -ALTER TABLE llx_payment_loan MODIFY COLUMN amount_interest numeric(24,8); -ALTER TABLE llx_payment_salary MODIFY COLUMN salary numeric(24,8); -ALTER TABLE llx_payment_salary MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_prelevement_bons MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_prelevement_facture_demande MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_prelevement_lignes MODIFY COLUMN amount numeric(24,8); -ALTER TABLE llx_societe MODIFY COLUMN capital numeric(24,8); -ALTER TABLE llx_tva MODIFY COLUMN amount numeric(24,8); diff --git a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql index 01ced5b07f4..ad1160c356d 100644 --- a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql +++ b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql @@ -26,17 +26,17 @@ CREATE TABLE llx_accounting_bookkeeping doc_ref varchar(300) NOT NULL, -- | facture_client/reglement_client/... reference number fk_doc integer NOT NULL, -- | facture_client/reglement_client/... rowid fk_docdet integer NOT NULL, -- | facture_client/reglement_client/... line rowid - thirdparty_code varchar(32), -- Third party code (customer or supplier) when record is saved (may help debug) + thirdparty_code varchar(32), -- Third party code (customer or supplier) when record is saved (may help debug) subledger_account varchar(32), -- FEC:CompAuxNum | account number of subledger account subledger_label varchar(255), -- FEC:CompAuxLib | label of subledger account numero_compte varchar(32) NOT NULL, -- FEC:CompteNum | account number label_compte varchar(255) NOT NULL, -- FEC:CompteLib | label of account label_operation varchar(255), -- FEC:EcritureLib | label of the operation - debit numeric(24,8) NOT NULL, -- FEC:Debit - credit numeric(24,8) NOT NULL, -- FEC:Credit - montant numeric(24,8) NOT NULL, -- FEC:Montant (Not necessary) + debit double NOT NULL, -- FEC:Debit + credit double NOT NULL, -- FEC:Credit + montant double NOT NULL, -- FEC:Montant (Not necessary) sens varchar(1) DEFAULT NULL, -- FEC:Sens (Not necessary) - multicurrency_amount numeric(24,8), -- FEC:Montantdevise + multicurrency_amount double, -- FEC:Montantdevise multicurrency_code varchar(255), -- FEC:Idevise lettering_code varchar(255), -- FEC:EcritureLet date_lettering datetime, -- FEC:DateLet diff --git a/htdocs/install/mysql/tables/llx_blockedlog.sql b/htdocs/install/mysql/tables/llx_blockedlog.sql index 59c8e262817..ae696a0d6d1 100644 --- a/htdocs/install/mysql/tables/llx_blockedlog.sql +++ b/htdocs/install/mysql/tables/llx_blockedlog.sql @@ -4,7 +4,7 @@ CREATE TABLE llx_blockedlog rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, action varchar(50), - amounts numeric(24,8) NOT NULL, + amounts real NOT NULL, signature varchar(100) NOT NULL, signature_line varchar(100) NOT NULL, element varchar(50), diff --git a/htdocs/install/mysql/tables/llx_chargesociales.sql b/htdocs/install/mysql/tables/llx_chargesociales.sql index 093b635a964..519ceacc9e5 100644 --- a/htdocs/install/mysql/tables/llx_chargesociales.sql +++ b/htdocs/install/mysql/tables/llx_chargesociales.sql @@ -34,7 +34,7 @@ create table llx_chargesociales fk_type integer NOT NULL, fk_account integer, -- bank account fk_mode_reglement integer, -- mode de reglement - amount numeric(24,8) default 0 NOT NULL, + amount real default 0 NOT NULL, paye smallint default 0 NOT NULL, periode date, fk_projet integer DEFAULT NULL, diff --git a/htdocs/install/mysql/tables/llx_commande.sql b/htdocs/install/mysql/tables/llx_commande.sql index 6964abdcd57..98740c232ac 100644 --- a/htdocs/install/mysql/tables/llx_commande.sql +++ b/htdocs/install/mysql/tables/llx_commande.sql @@ -42,7 +42,7 @@ create table llx_commande fk_user_cloture integer, -- user closing source smallint, -- not used, except by setting this to 42 for orders coming for replenishment and 0 in other case ? fk_statut smallint default 0, - amount_ht numeric(24,8) default 0, + amount_ht real default 0, remise_percent real default 0, remise_absolue real default 0, remise real default 0, diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql index 24158903eb1..6d291dcfa00 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql @@ -46,7 +46,7 @@ create table llx_commande_fournisseur source smallint NOT NULL, -- not used, except by setting this to 42 for orders coming for replenishment and 0 in other case ? fk_statut smallint default 0, billed smallint default 0, - amount_ht numeric(24,8) default 0, + amount_ht real default 0, remise_percent real default 0, remise real default 0, tva double(24,8) default 0, diff --git a/htdocs/install/mysql/tables/llx_don.sql b/htdocs/install/mysql/tables/llx_don.sql index 63b2cd111ea..b7b7c89f9cd 100644 --- a/htdocs/install/mysql/tables/llx_don.sql +++ b/htdocs/install/mysql/tables/llx_don.sql @@ -28,7 +28,7 @@ create table llx_don tms timestamp, fk_statut smallint NOT NULL DEFAULT 0, -- Status of donation promise or validate datedon datetime, -- Date of the donation/promise - amount numeric(24,8) DEFAULT 0, + amount real DEFAULT 0, fk_payment integer, paid smallint default 0 NOT NULL, firstname varchar(50), diff --git a/htdocs/install/mysql/tables/llx_loan_schedule.sql b/htdocs/install/mysql/tables/llx_loan_schedule.sql index eb43238255a..c682b22f276 100644 --- a/htdocs/install/mysql/tables/llx_loan_schedule.sql +++ b/htdocs/install/mysql/tables/llx_loan_schedule.sql @@ -24,9 +24,9 @@ create table llx_loan_schedule datec datetime, -- creation date tms timestamp, datep datetime, -- payment date - amount_capital numeric(24,8) DEFAULT 0, - amount_insurance numeric(24,8) DEFAULT 0, - amount_interest numeric(24,8) DEFAULT 0, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note_private text, diff --git a/htdocs/install/mysql/tables/llx_paiementcharge.sql b/htdocs/install/mysql/tables/llx_paiementcharge.sql index 086bafae0fa..2efca933dba 100644 --- a/htdocs/install/mysql/tables/llx_paiementcharge.sql +++ b/htdocs/install/mysql/tables/llx_paiementcharge.sql @@ -23,7 +23,7 @@ create table llx_paiementcharge datec datetime, -- date de creation tms timestamp, datep datetime, -- payment date - amount numeric(24,8) DEFAULT 0, + amount real DEFAULT 0, fk_typepaiement integer NOT NULL, num_paiement varchar(50), note text, diff --git a/htdocs/install/mysql/tables/llx_paiementfourn.sql b/htdocs/install/mysql/tables/llx_paiementfourn.sql index 16d63a32076..0e9b1885c97 100644 --- a/htdocs/install/mysql/tables/llx_paiementfourn.sql +++ b/htdocs/install/mysql/tables/llx_paiementfourn.sql @@ -25,7 +25,7 @@ create table llx_paiementfourn tms timestamp, datec datetime, -- date de creation de l'enregistrement datep datetime, -- date de paiement - amount numeric(24,8) DEFAULT 0, -- montant + amount real DEFAULT 0, -- montant multicurrency_amount double(24,8) DEFAULT 0, -- multicurrency amount fk_user_author integer, -- auteur fk_paiement integer NOT NULL, -- moyen de paiement diff --git a/htdocs/install/mysql/tables/llx_payment_donation.sql b/htdocs/install/mysql/tables/llx_payment_donation.sql index 1859c7aa796..afa5075cd4e 100644 --- a/htdocs/install/mysql/tables/llx_payment_donation.sql +++ b/htdocs/install/mysql/tables/llx_payment_donation.sql @@ -23,7 +23,7 @@ create table llx_payment_donation datec datetime, -- date de creation tms timestamp, datep datetime, -- payment date - amount numeric(24,8) DEFAULT 0, + amount real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note text, diff --git a/htdocs/install/mysql/tables/llx_payment_expensereport.sql b/htdocs/install/mysql/tables/llx_payment_expensereport.sql index 1857246e22e..40e39771978 100644 --- a/htdocs/install/mysql/tables/llx_payment_expensereport.sql +++ b/htdocs/install/mysql/tables/llx_payment_expensereport.sql @@ -23,7 +23,7 @@ create table llx_payment_expensereport datec datetime, -- date de creation tms timestamp, datep datetime, -- payment date - amount numeric(24,8) DEFAULT 0, + amount real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note text, diff --git a/htdocs/install/mysql/tables/llx_payment_loan.sql b/htdocs/install/mysql/tables/llx_payment_loan.sql index 3b6111a7b2f..d023c039391 100644 --- a/htdocs/install/mysql/tables/llx_payment_loan.sql +++ b/htdocs/install/mysql/tables/llx_payment_loan.sql @@ -24,9 +24,9 @@ create table llx_payment_loan datec datetime, -- creation date tms timestamp, datep datetime, -- payment date - amount_capital numeric(24,8) DEFAULT 0, - amount_insurance numeric(24,8) DEFAULT 0, - amount_interest numeric(24,8) DEFAULT 0, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note_private text, diff --git a/htdocs/install/mysql/tables/llx_payment_salary.sql b/htdocs/install/mysql/tables/llx_payment_salary.sql index 3b6da16b9cb..38364c6812e 100644 --- a/htdocs/install/mysql/tables/llx_payment_salary.sql +++ b/htdocs/install/mysql/tables/llx_payment_salary.sql @@ -24,8 +24,8 @@ create table llx_payment_salary fk_user integer NOT NULL, datep date, -- date de paiement datev date, -- date de valeur (this field should not be here, only into bank tables) - salary numeric(24,8), -- salary of user when payment was done - amount numeric(24,8) NOT NULL DEFAULT 0, + salary real, -- salary of user when payment was done + amount real NOT NULL DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), -- ref label varchar(255), diff --git a/htdocs/install/mysql/tables/llx_prelevement_bons.sql b/htdocs/install/mysql/tables/llx_prelevement_bons.sql index 40fff2e842d..e92342eb001 100644 --- a/htdocs/install/mysql/tables/llx_prelevement_bons.sql +++ b/htdocs/install/mysql/tables/llx_prelevement_bons.sql @@ -29,7 +29,7 @@ create table llx_prelevement_bons ref varchar(12), -- reference entity integer DEFAULT 1 NOT NULL, -- multi company id datec datetime, -- date de creation - amount numeric(24,8) DEFAULT 0, -- montant total du prelevement + amount real DEFAULT 0, -- montant total du prelevement statut smallint DEFAULT 0, -- statut credite smallint DEFAULT 0, -- indique si le prelevement a ete credite note text, diff --git a/htdocs/install/mysql/tables/llx_prelevement_facture_demande.sql b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.sql index 1d1b59bf3f5..3bdc0e2ed81 100644 --- a/htdocs/install/mysql/tables/llx_prelevement_facture_demande.sql +++ b/htdocs/install/mysql/tables/llx_prelevement_facture_demande.sql @@ -21,7 +21,7 @@ create table llx_prelevement_facture_demande ( rowid integer AUTO_INCREMENT PRIMARY KEY, fk_facture integer NOT NULL, - amount numeric(24,8) NOT NULL, + amount real NOT NULL, date_demande datetime NOT NULL, traite smallint DEFAULT 0, date_traite datetime, diff --git a/htdocs/install/mysql/tables/llx_prelevement_lignes.sql b/htdocs/install/mysql/tables/llx_prelevement_lignes.sql index 448b3846d71..04b6e1ebf5e 100644 --- a/htdocs/install/mysql/tables/llx_prelevement_lignes.sql +++ b/htdocs/install/mysql/tables/llx_prelevement_lignes.sql @@ -24,7 +24,7 @@ create table llx_prelevement_lignes statut smallint DEFAULT 0, client_nom varchar(255), - amount numeric(24,8) DEFAULT 0, + amount real DEFAULT 0, code_banque varchar(128), code_guichet varchar(6), number varchar(255), diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index 7c88a74de07..20440b692d7 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -64,7 +64,7 @@ create table llx_societe idprof5 varchar(128), -- IDProf5: nu for france idprof6 varchar(128), -- IDProf6: nu for france tva_intra varchar(20), -- tva - capital numeric(24,8), -- capital de la societe + capital real, -- capital de la societe fk_stcomm integer DEFAULT 0 NOT NULL, -- commercial statut note_private text, -- note_public text, -- diff --git a/htdocs/install/mysql/tables/llx_tva.sql b/htdocs/install/mysql/tables/llx_tva.sql index d2a7b67c835..9abf63d6ad9 100644 --- a/htdocs/install/mysql/tables/llx_tva.sql +++ b/htdocs/install/mysql/tables/llx_tva.sql @@ -24,11 +24,11 @@ create table llx_tva datec datetime, -- Create date datep date, -- date de paiement datev date, -- date de valeur - amount numeric(24,8) NOT NULL DEFAULT 0, + amount real NOT NULL DEFAULT 0, fk_typepayment integer NULL, num_payment varchar(50), label varchar(255), - entity integer DEFAULT 1 NOT NULL, -- multi company id + entity integer DEFAULT 1 NOT NULL, -- multi company id note text, fk_bank integer, fk_user_creat integer, -- utilisateur who create record From f0e234eef2e2fbc9c2425bdc7311d64f0768a1f0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 16 Jun 2017 17:01:43 +0200 Subject: [PATCH 02/13] Fix: missing hookmanager init --- htdocs/admin/defaultvalues.php | 6 +++++- htdocs/admin/modules.php | 36 ++++++++++++++++++++++------------ htdocs/admin/translation.php | 7 +++++-- htdocs/user/group/index.php | 2 +- htdocs/user/perms.php | 12 ++++++------ 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index 94682cd502f..53c22353b92 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2017 Laurent Destailleur + * Copyright (C) 2017 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 @@ -60,6 +61,9 @@ $urlpage = GETPOST('urlpage'); $key = GETPOST('key'); $value = GETPOST('value'); +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('admindefaultvalues','globaladmin')); + /* * Actions diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 8bea1c6dcb7..1aebae10947 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -1,12 +1,12 @@ - * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2017 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry - * Copyright (C) 2015 Raphaël Doursenaud +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Raphaël Doursenaud * * 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 @@ -75,11 +75,18 @@ if ($search_version) $param.='&search_version='.urlencode($search_version); $dirins=DOL_DOCUMENT_ROOT.'/custom'; $urldolibarrmodules='https://www.dolistore.com/'; +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('adminmodules','globaladmin')); + /* * Actions */ +$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 (GETPOST('buttonreset')) { $search_keyword=''; @@ -204,7 +211,7 @@ if ($action == 'set' && $user->admin) setEventMessages($msg, null, 'warnings'); } } - header("Location: modules.php?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); + header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); exit; } @@ -212,7 +219,7 @@ if ($action == 'reset' && $user->admin) { $result=unActivateModule($value); if ($result) setEventMessages($result, null, 'errors'); - header("Location: modules.php?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); + header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); exit; } @@ -474,10 +481,13 @@ if ($mode == 'common') print $hookmanager->resPrint; } + $moreforfilter=''; print '

'; - $moreforfilter=''; + $parameters=array(); + $reshook=$hookmanager->executeHooks('insertExtraHeader',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Show list of modules @@ -657,7 +667,7 @@ if ($mode == 'common') } else { - print ''; + print ''; print img_picto($langs->trans("Activated"),'switch_on'); print ''; } @@ -749,7 +759,7 @@ if ($mode == 'common') } } print ''."\n"; - print ''; print img_picto($langs->trans("Disabled"),'switch_off'); diff --git a/htdocs/admin/translation.php b/htdocs/admin/translation.php index 8a6c38ffe46..be48bd0c8f4 100644 --- a/htdocs/admin/translation.php +++ b/htdocs/admin/translation.php @@ -1,6 +1,6 @@ - * Copyright (C) 2009 Regis Houssin +/* Copyright (C) 2007-2016 Laurent Destailleur + * Copyright (C) 2009-2017 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 @@ -56,6 +56,9 @@ $pagenext = $page + 1; if (! $sortfield) $sortfield='lang,transkey'; if (! $sortorder) $sortorder='ASC'; +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('admintranslation','globaladmin')); + /* * Actions diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index 06e11caced9..e8d37801998 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -203,7 +203,7 @@ if ($resql) print ''; print "\n"; - $db->free(); + $db->free($resql); } else { diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index 5d87232c928..6f89e49af5e 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -1,10 +1,10 @@ - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2012 Juanjo Menent +/* Copyright (C) 2002-2005 Rodolphe Quiedeville + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2012 Juanjo Menent * * 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 From 5320ebc0515e865553004f2febe718b3a46b9620 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 10:16:52 +0200 Subject: [PATCH 03/13] getTotalWeightVolume : add conversion Lb & oz to KG New conversion value : Oz once Little az a wizzard... --- htdocs/core/class/commonobject.class.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3ac7cb6ffb3..bd5d8a6b831 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3097,9 +3097,18 @@ abstract class CommonObject $trueWeightUnit=pow(10, $weightUnit); $totalWeight += $weight * $qty * $trueWeightUnit; } - else - { - $totalWeight += $weight * $qty; // This may be wrong if we mix different units + else { + if ($weight_units == 99) { + // conversion 1 Livre = 0.45359237 KG + $trueWeightUnit = 0.45359237; + $totalWeight += $weight * $qty * $trueWeightUnit; + } elseif ($weight_units == 98) { + // conversion 1 once = 0.0283495 KG + $trueWeightUnit = 0.0283495; + $totalWeight += $weight * $qty * $trueWeightUnit; + } + else + $totalWeight += $weight * $qty; // This may be wrong if we mix different units } if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) { From e98bc90489b8c9085904ffc7762cd0b63e48ada8 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 10:18:59 +0200 Subject: [PATCH 04/13] introduce OZ : once weight --- htdocs/product/class/html.formproduct.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index 01064c8ffa3..1dbfbc7662f 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -307,7 +307,7 @@ class FormProduct $return=''; $measuring_units=array(); - if ($measuring_style == 'weight') $measuring_units=array(-6=>1,-3=>1,0=>1,3=>1,99=>1); + if ($measuring_style == 'weight') $measuring_units=array(-6=>1,-3=>1,0=>1,3=>1,98=>1,99=>1); else if ($measuring_style == 'size') $measuring_units=array(-3=>1,-2=>1,-1=>1,0=>1,98=>1,99=>1); else if ($measuring_style == 'surface') $measuring_units=array(-6=>1,-4=>1,-2=>1,0=>1,98=>1,99=>1); else if ($measuring_style == 'volume') $measuring_units=array(-9=>1,-6=>1,-3=>1,0=>1,88=>1,89=>1,97=>1,99=>1,/* 98=>1 */); // Liter is not used as already available with dm3 From 17247c64f0fbe50c0720e5c13c70965892ae18e9 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 10:26:01 +0200 Subject: [PATCH 05/13] add WeightUnitonce --- htdocs/core/lib/product.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 5aec64f3ce0..16bedc4d346 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -441,7 +441,8 @@ function measuring_units_string($unit,$measuring_style='') $measuring_units[0] = $langs->transnoentitiesnoconv("WeightUnitkg"); $measuring_units[-3] = $langs->transnoentitiesnoconv("WeightUnitg"); $measuring_units[-6] = $langs->transnoentitiesnoconv("WeightUnitmg"); - $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); + $measuring_units[98] = $langs->transnoentitiesnoconv("WeightUnitonce"); + $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); } else if ($measuring_style == 'size') { From f0bc72cda4aa3864dcfaba252537a3005027bad8 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 10:27:00 +0200 Subject: [PATCH 06/13] WeightUnitonce translation --- htdocs/langs/en_US/other.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index a14bfffffb6..120b1dcd790 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -123,6 +123,7 @@ WeightUnitkg=kg WeightUnitg=g WeightUnitmg=mg WeightUnitpound=pound +WeightUnitonce=once Length=Length LengthUnitm=m LengthUnitdm=dm From 12cab2dfe08695f75199afb84779c84b897101e9 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 16:30:03 +0200 Subject: [PATCH 07/13] Once to Ounce --- htdocs/core/lib/product.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 16bedc4d346..7048b8570c6 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -441,7 +441,7 @@ function measuring_units_string($unit,$measuring_style='') $measuring_units[0] = $langs->transnoentitiesnoconv("WeightUnitkg"); $measuring_units[-3] = $langs->transnoentitiesnoconv("WeightUnitg"); $measuring_units[-6] = $langs->transnoentitiesnoconv("WeightUnitmg"); - $measuring_units[98] = $langs->transnoentitiesnoconv("WeightUnitonce"); + $measuring_units[98] = $langs->transnoentitiesnoconv("WeightUnitounce"); $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); } else if ($measuring_style == 'size') From db173632674e7fd6ae22c0965ae8e9361b607502 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 16:30:37 +0200 Subject: [PATCH 08/13] Update other.lang --- htdocs/langs/en_US/other.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 120b1dcd790..bf01ba734f3 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -123,7 +123,7 @@ WeightUnitkg=kg WeightUnitg=g WeightUnitmg=mg WeightUnitpound=pound -WeightUnitonce=once +WeightUnitounce=ounce Length=Length LengthUnitm=m LengthUnitdm=dm From fcdf68db6a1175f2faa5e9a95afef05398c29fb5 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 17 Jun 2017 16:31:54 +0200 Subject: [PATCH 09/13] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index bd5d8a6b831..b87b3d28ea8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3099,11 +3099,11 @@ abstract class CommonObject } else { if ($weight_units == 99) { - // conversion 1 Livre = 0.45359237 KG + // conversion 1 Pound = 0.45359237 KG $trueWeightUnit = 0.45359237; $totalWeight += $weight * $qty * $trueWeightUnit; } elseif ($weight_units == 98) { - // conversion 1 once = 0.0283495 KG + // conversion 1 Ounce = 0.0283495 KG $trueWeightUnit = 0.0283495; $totalWeight += $weight * $qty * $trueWeightUnit; } From 04821376200381ef232947147b8063bf189c2f9b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2017 18:03:53 +0200 Subject: [PATCH 10/13] Fix warning --- htdocs/install/inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index dc7e29b19f5..b9efc4eb8a4 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -385,12 +385,12 @@ function pHeader($subtitle,$next,$action='set',$param='',$forcejqueryurl='',$css // We force the content charset header("Content-type: text/html; charset=".$conf->file->character_set_client); header("X-Content-Type-Options: nosniff"); - + print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; print ''."\n"; print ''."\n"; @@ -453,7 +453,7 @@ function pFooter($nonext=0,$setuplang='',$jscheckfunction='', $withpleasewait=0) print '
'; if ($nonext == '2') { - print $langs->trans("ErrorFoundDuringMigration", $_SERVER["REQUEST_URI"].'&ignoreerrors=1').'

'; + print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"])?$_SERVER["REQUEST_URI"].'&ignoreerrors=1':'').'

'; } print '"'; From a6b4b15e07a29934b483c93b8487eb6b7dee0218 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2017 19:40:48 +0200 Subject: [PATCH 11/13] Work on modulebuilder --- htdocs/langs/en_US/modulebuilder.lang | 6 +- htdocs/modulebuilder/index.php | 142 +++++++++++++++++- .../modulebuilder/template/class/MyObject.txt | 1 + ...class.class.php => api_myobject.class.php} | 0 .../template/class/myobject.class.php | 4 +- ...bject_mymodule.png => object_myobject.png} | Bin 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 htdocs/modulebuilder/template/class/MyObject.txt rename htdocs/modulebuilder/template/class/{myobject_api_class.class.php => api_myobject.class.php} (100%) rename htdocs/modulebuilder/template/img/{myobject_mymodule.png => object_myobject.png} (100%) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index adce0950b88..b8300182b05 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -1,11 +1,15 @@ # Dolibarr language file - Source file is en_US - loan ModuleBuilderDesc=This tools give you utilites to build or edit your own module. -EnterNameOfModuleDesc=Enter name of the module to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...) +EnterNameOfModuleDesc=Enter name of the module/application to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...) +EnterNameOfObjectDesc=Enter name of the object to create with no spaces. Use uppercase to separate words (For example: MyObject, Student, Teacher...) ModuleBuilderDesc2=Path were modules are generated/edited (first alternative directory defined into %s): %s ModuleBuilderDesc3=Generated/editable modules found: %s (they are detected as editable when the file %s exists in root of module directory). NewModule=New module +NewObject=New object ModuleKey=Key for new module +ObjectKey=Key for new object ModuleInitialized=Module initialized +FilesForObjectInitialized=Files for new object initialized ModuleBuilderDescdescription=Enter here all general information that describe your module 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. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 8cabec1bdfb..0f60d76ca4f 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -33,11 +33,13 @@ $action=GETPOST('action','aZ09'); $confirm=GETPOST('confirm','alpha'); $module=GETPOST('module','alpha'); $tab=GETPOST('tab','aZ09'); +$tabobj=GETPOST('tabobj','alpha'); if (empty($module)) $module='initmodule'; if (empty($tab)) $tab='description'; +if (empty($tabobj)) $tabobj='newobject'; $modulename=dol_sanitizeFileName(GETPOST('modulename','alpha')); - +$objectname=dol_sanitizeFileName(GETPOST('objectname','alpha')); // Security check if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed'); @@ -80,6 +82,18 @@ if ($dirins && $action == 'initmodule' && $modulename) } } + // Delete some files + dol_delete_file($destdir.'/myobject_card.php'); + dol_delete_file($destdir.'/myobject_list.php'); + dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php'); + dol_delete_file($destdir.'/sql/llx_myobject.key.sql'); + dol_delete_file($destdir.'/sql/llx_myobject.sql'); + dol_delete_file($destdir.'/scripts/myobject.php'); + dol_delete_file($destdir.'/img/object_myobject.png'); + dol_delete_file($destdir.'/class/myobject.class.php'); + dol_delete_file($destdir.'/class/api_myobject.class.php'); + dol_delete_file($destdir.'/class/MyObject.txt'); + // Edit PHP files if (! $error) { @@ -113,6 +127,86 @@ if ($dirins && $action == 'initmodule' && $modulename) } } +if ($dirins && $action == 'initobject' && $module && $objectname) +{ + $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; + $destdir = $dirins.'/'.strtolower($module); + + $arrayreplacement=array( + 'mymodule'=>strtolower($module), + 'MyModule'=>$module, + 'myobject'=>strtolower($objectname), + 'MyObject'=>$objectname + ); + + + // Delete some files + $filetogenerate = array( + 'myobject_card.php'=>strtolower($objectname).'_card.php', + 'myobject_list.php'=>strtolower($objectname).'_list.php', + 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php', + 'sql/llx_myobject.key.sql'=>'sql/llx_'.strtolower($objectname).'.key.sql', + 'sql/llx_myobject.sql'=>'sql/llx_'.strtolower($objectname).'.sql', + 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php', + 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png', + 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php', + 'class/api_myobject.class.php'=>'class/api_'.strtolower($objectname).'.class.php', + 'class/MyObject.txt'=>'class/'.$objectname.'.txt' + ); + + foreach($filetogenerate as $srcfile => $destfile) + { + $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile); + if ($result <= 0) + { + if ($result < 0) + { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors'); + } + else // $result == 0 + { + setEventMessages($langs->trans("FileAlreadyExists", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'warnings'); + } + } + else + { + // Copy is ok + } + } + + // Edit PHP files + foreach($filetogenerate as $destfile) + { + $phpfileval['fullname'] = $destdir.'/'.$destfile; + + //var_dump($phpfileval['fullname']); + $arrayreplacement=array( + 'mymodule'=>strtolower($modulename), + 'MyModule'=>$modulename, + 'MYMODULE'=>strtoupper($modulename), + 'My module'=>$modulename, + 'htdocs/modulebuilder/template/'=>'', + 'myobject'=>strtolower($objectname), + 'MyObject'=>$objectname + ); + + $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); + //var_dump($result); + if ($result < 0) + { + setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors'); + } + } + + if (! $error) + { + setEventMessages('FilesForObjectInitialized', null); + } +} + + if ($dirins && $action == 'confirm_delete') { $modulelowercase=strtolower($module); @@ -485,9 +579,53 @@ elseif (! empty($module)) if ($tab == 'objects') { - print $langs->trans("FeatureNotYetAvailable"); + $head3 = array(); + $h=0; + $modulelowercase=strtolower($module); + + // Dir for module + $dir = $dirins.'/'.$modulelowercase.'/class'; + + $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj=newobject'; + $head3[$h][1] = $langs->trans("NewObject"); + $head3[$h][2] = 'newobject'; + $h++; + + $listofobject = dol_dir_list($dir , 'files', 0, '\.txt$'); + foreach($listofobject as $fileobj) + { + $objectname = preg_replace('/\.txt$/', '', $fileobj['name']); + + $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj='.$objectname; + $head3[$h][1] = $objectname; + $head3[$h][2] = $objectname; + $h++; + } + + dol_fiche_head($head3, $tabobj, '', -1, ''); + + if ($tabobj == 'newobject') + { + // New module + print '
'; + print ''; + print ''; + print ''; + print ''; + + print $langs->trans("EnterNameOfObjectDesc").'

'; + + print ''; + print ''; + print '
'; + } + + if ($tabobj == 'fields') + { + print $langs->trans("FeatureNotYetAvailable").'

'; + } } if ($tab == 'menus') diff --git a/htdocs/modulebuilder/template/class/MyObject.txt b/htdocs/modulebuilder/template/class/MyObject.txt new file mode 100644 index 00000000000..37ccaca81ed --- /dev/null +++ b/htdocs/modulebuilder/template/class/MyObject.txt @@ -0,0 +1 @@ +# If this file exists, it means the class and file for object MyOjbect was generated by ModuleBuilder. \ No newline at end of file diff --git a/htdocs/modulebuilder/template/class/myobject_api_class.class.php b/htdocs/modulebuilder/template/class/api_myobject.class.php similarity index 100% rename from htdocs/modulebuilder/template/class/myobject_api_class.class.php rename to htdocs/modulebuilder/template/class/api_myobject.class.php diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index f2d4daee8d4..9e66b9410f6 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -31,11 +31,11 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** - * Class MyModuleObject + * Class MyObject * * Put here description of your class. */ -class MyModuleObject extends CommonObject +class MyObject extends CommonObject { /** * @var string Id to identify managed object diff --git a/htdocs/modulebuilder/template/img/myobject_mymodule.png b/htdocs/modulebuilder/template/img/object_myobject.png similarity index 100% rename from htdocs/modulebuilder/template/img/myobject_mymodule.png rename to htdocs/modulebuilder/template/img/object_myobject.png From 69b26dcb4ebea5a36cd6dcfb9fbf4ced48a910de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2017 21:23:52 +0200 Subject: [PATCH 12/13] Work on modulebuilder --- htdocs/langs/en_US/modulebuilder.lang | 10 +- htdocs/modulebuilder/index.php | 152 ++++++++++++++++-- .../template/class/myobject.class.php | 22 ++- 3 files changed, 159 insertions(+), 25 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index b8300182b05..8d9a31cfdf7 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -17,7 +17,7 @@ ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions 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. ModuleBuilderDeschooks=This tab is dedicated to hooks. ModuleBuilderDescwidgets=This tab is dedicated to manage/build widgets. -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. +ModuleBuilderDescbuildpackage=You can generate here a "ready to distribute" package file (a normalized .zip file) of your module. Just click on button to build the module package file. ModuleBuilderDescdangerzone=You can delete your module. WARNING: All files of module will be definetly lost ! DangerZone=Danger zone BuildPackage=Build package @@ -25,4 +25,10 @@ ModuleIsNotActive=This module was not activated yet (go into Home-Setup-Module t ModuleIsLive=This module has been activated. Any change on it may break a current active feature. DescriptionLong=Long description EditorName=Name of editor -EditorUrl=URL of editor \ No newline at end of file +EditorUrl=URL of editor +DescriptorFile=Descriptor file of module +ClassFile=File for PHP class +ApiClassFile=File for PHP API class +PageForList=PHP page for list of record +PageForCreateEditView=PHP page to create/edit/view a record +PathToModulePackage=Path to zip of module/application package \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0f60d76ca4f..d9ae491b654 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -454,7 +454,9 @@ elseif (! empty($module)) $head2 = array(); $h=0; - $modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive"); + $modulelowercase=strtolower($module); + + $modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive"); if (! empty($conf->$module->enabled)) { $modulestatusinfo=img_warning().' '.$langs->trans("ModuleIsLive"); @@ -513,7 +515,12 @@ elseif (! empty($module)) if ($tab == 'description') { - print '
'; + $pathtofile = $modulelowercase.'/core/modules/mod'.$module.'.class.php'; + + print ' '.$langs->trans("DescriptorFile").' : '.$pathtofile.'
'; + print '
'; + + print '
'; print '
'; print ''; @@ -579,12 +586,9 @@ elseif (! empty($module)) if ($tab == 'objects') { - $head3 = array(); $h=0; - $modulelowercase=strtolower($module); - // Dir for module $dir = $dirins.'/'.$modulelowercase.'/class'; @@ -621,10 +625,92 @@ elseif (! empty($module)) print ''; print ''; } - - if ($tabobj == 'fields') + else { - print $langs->trans("FeatureNotYetAvailable").'

'; + try { + $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php'; + $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; + $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.class.php'; + $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.class.php'; + print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.'
'; + print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.'
'; + print ' '.$langs->trans("PageForList").' : '.$pathtolist.'
'; + print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.'
'; + + $result = dol_include_once($pathtoclass); + $tmpobjet = new $tabobj($db); + + $reflector = new ReflectionClass($tabobj); + $properties = $reflector->getProperties(); + $propdefault = $reflector->getDefaultProperties(); + + print load_fiche_titre($langs->trans("Properties"), '', ''); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + foreach($properties as $propkey => $propval) + { + if ($propval->class == $tabobj) + { + $propname=$propval->getName(); + + // Discard generic properties + if (in_array($propname, array('element', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue; + + // Keep or not lines + if (in_array($propname, array('fk_element', 'lines'))) continue; + + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + } + } + print '
'.$langs->trans("Property").''.$langs->trans("Description").''.$langs->trans("Type").''.$langs->trans("DefaultValue").'
'; + print ''; + print '
'; + print $propname; + print ''; + + print ''; + + print ''; + print $propdefault[$propname]; + print ''; + + print '
'; + + print ''; + } + catch(Exception $e) + { + print $e->getMessage(); + } } } @@ -666,10 +752,9 @@ elseif (! empty($module)) $var=True; foreach ($triggers as $trigger) { - print ''; print ''.$trigger['picto'].''; - print ''.$trigger['file'].''; + print ''.$trigger['relpath'].''; print ''.$trigger['status'].''; print ''; $text=$trigger['info']; @@ -698,11 +783,56 @@ elseif (! empty($module)) print '
'; } + $modulelowercase=strtolower($module); + + // 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; + } + + print ' '. $langs->trans("PathToModulePackage") . ' : '; + if (! dol_is_file($outputfile)) print ''.$langs->trans("PackageFileNotYetGenerated").''; + else { + print ''.$outputfile.''; + print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfile), 'dayhour').')'; + } + print '
'; + + print '

'; + print '
'; print ''; print ''; print ''; - print ''; + print ''; print '
'; } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 9e66b9410f6..4993f60f83c 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -21,8 +21,8 @@ /** * \file htdocs/modulebuilder/template/class/myobject.class.php - * \ingroup mymodule othermodule1 othermodule2 - * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) + * \ingroup mymodule + * \brief This file is a CRUD class file for MyObject (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -31,24 +31,22 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** - * Class MyObject - * - * Put here description of your class. + * Class for MyObject */ class MyObject extends CommonObject { /** * @var string Id to identify managed object */ - public $element = 'mymoduleobject'; + public $element = 'myobject'; /** * @var string Name of table without prefix where object is stored */ - public $table_element = 'mymoduleobject'; + public $table_element = 'myobject'; /** * @var array Array with all fields and their property */ - public $picto = 'generic'; + public $picto = 'myobject'; /** * @var array Array with all fields and their property */ @@ -67,12 +65,12 @@ class MyObject extends CommonObject protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - public $table_element_line = 'mymoduleobjectdet'; - public $class_element_line = 'MyModuleObjectline'; - public $fk_element = 'fk_mymoduleobject'; + public $table_element_line = 'myobjectdet'; + public $class_element_line = 'MyObjectline'; + public $fk_element = 'fk_myobject'; /** - * @var MyModuleObjectLine[] Lines + * @var MyObjectLine[] Lines */ public $lines = array(); From 862b12abfd4bef2915abf492dd6fb7790657d234 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2017 21:28:29 +0200 Subject: [PATCH 13/13] Fix responsive --- htdocs/opensurvey/card.php | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index 18326321a4b..c634ca1ceaa 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -67,48 +67,48 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { if ($cancel) $action=''; - + // Delete if ($action == 'delete_confirm') { // Security check if (!$user->rights->opensurvey->write) accessforbidden(); - + $result=$object->delete($user,'',$numsondage); - + header('Location: '.dol_buildpath('/opensurvey/list.php',1)); exit(); } - + // Close if ($action == 'close') { $object->status = Opensurveysondage::STATUS_CLOSED; $object->update($user); } - + // Reopend if ($action == 'reopen') { $object->status = Opensurveysondage::STATUS_VALIDATED; $object->update($user); } - + // Update if ($action == 'update') { // Security check if (!$user->rights->opensurvey->write) accessforbidden(); - + $error=0; - + if (! GETPOST('nouveautitre')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); $error++; $action = 'edit'; } - + if (! $error) { $object->titre = GETPOST('nouveautitre'); @@ -118,7 +118,7 @@ if (empty($reshook)) $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false; $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false; $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false; - + $res=$object->update($user); if ($res < 0) { @@ -132,7 +132,7 @@ if (empty($reshook)) if (GETPOST('ajoutcomment')) { $error=0; - + if (! GETPOST('comment')) { $error++; @@ -143,33 +143,33 @@ if (empty($reshook)) $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors'); } - + if (! $error) { $comment = GETPOST("comment"); $comment_user = GETPOST('commentuser'); - + $resql = $object->addComment($comment, $comment_user); - + if (! $resql) { setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors'); } } } - + // Delete comment $idcomment=GETPOST('deletecomment','int'); if ($idcomment) { // Security check if (!$user->rights->opensurvey->write) accessforbidden(); - + $resql = $object->deleteComment($idcomment); } - + if ($action == 'edit') { - + // Security check if (!$user->rights->opensurvey->write) accessforbidden(); } @@ -307,7 +307,7 @@ print ''; // Expire date print ''.$langs->trans('ExpireDate').''; if ($action == 'edit') print $form->select_date($expiredate?$expiredate:$object->date_fin,'expire',0,0,0,'',1,0,1); -else +else { print dol_print_date($object->date_fin,'day'); if ($object->date_fin && $object->date_fin < dol_now()) print img_warning($langs->trans("Expired")); @@ -377,7 +377,7 @@ if ($action != 'edit' && $user->rights->opensurvey->write) { //Opened button print '
'.$langs->trans("ReOpen") . ''; } - + //Delete button print ''.$langs->trans('Delete').''; } @@ -420,7 +420,7 @@ print '
'; // Add comment if ($object->allow_comments) { print $langs->trans("AddACommentForPoll") . '
'; - print '
'."\n"; + print '
'."\n"; print $langs->trans("Name") .':
'."\n"; print '
'."\n"; if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") {