From d834cbf7baeb2fef8698c84ff634726160d3e437 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 21 May 2017 15:24:16 +0200 Subject: [PATCH 01/12] Use getNomUrl for accounting account in product card --- htdocs/product/card.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 71f7cd8e7f6..5885775a1f1 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1,20 +1,20 @@ +/* Copyright (C) 2001-2007 Rodolphe Quiedeville * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005 Eric Seigne + * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2013-2016 Marcos García * Copyright (C) 2012-2013 Cédric Salvador - * Copyright (C) 2011-2016 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * Copyright (C) 2014 Cédric Gross * Copyright (C) 2014-2015 Ferran Marcet * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2016 Charlie Benke - * Copyright (C) 2016 Meziane Sof + * Copyright (C) 2016 Meziane Sof * * 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 @@ -51,8 +51,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; $langs->load("products"); $langs->load("other"); @@ -272,7 +272,7 @@ if (empty($reshook)) $object->volume_units = GETPOST('volume_units'); $object->finished = GETPOST('finished'); $object->fk_unit = GETPOST('units'); - + $accountancy_code_sell = GETPOST('accountancy_code_sell'); $accountancy_code_buy = GETPOST('accountancy_code_buy'); @@ -399,7 +399,7 @@ if (empty($reshook)) $accountancy_code_sell = GETPOST('accountancy_code_sell'); $accountancy_code_buy = GETPOST('accountancy_code_buy'); - + if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } @@ -1107,7 +1107,7 @@ else // Accountancy codes print ''; - + if (! empty($conf->accounting->enabled)) { // Accountancy_code_sell @@ -1121,7 +1121,7 @@ else print ''; - } + } else // For external software { // Accountancy_code_sell @@ -1414,7 +1414,7 @@ else print ''; - } + } else // For external software { // Accountancy_code_sell @@ -1530,8 +1530,12 @@ else print '
'; print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, ''); print '
'; print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1); print '
'; print $langs->trans("ProductAccountancySellCode"); print ''; - if (! empty($conf->accounting->enabled)) { - print length_accountg($object->accountancy_code_sell); + if (! empty($conf->accounting->enabled)) + { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch('',$object->accountancy_code_sell); + + print $accountingaccount->getNomUrl(0,1,1,'',1); } else { print $object->accountancy_code_sell; } @@ -1541,8 +1545,12 @@ else print '
'; print $langs->trans("ProductAccountancyBuyCode"); print ''; - if (! empty($conf->accounting->enabled)) { - print length_accountg($object->accountancy_code_buy); + if (! empty($conf->accounting->enabled)) + { + $accountingaccount2 = new AccountingAccount($db); + $accountingaccount2->fetch('',$object->accountancy_code_buy); + + print $accountingaccount2->getNomUrl(0,1,1,'',1); } else { print $object->accountancy_code_buy; } From 9bc60b8aa5d738d99ebcec0e25ff72d97aba8e20 Mon Sep 17 00:00:00 2001 From: phf Date: Mon, 22 May 2017 09:26:10 +0200 Subject: [PATCH 02/12] Fix missing column ref on migration for inventory --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 1 + 1 file changed, 1 insertion(+) 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 0bd68ddfcfb..67ad5017999 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 @@ -326,3 +326,4 @@ ALTER TABLE llx_facture ADD COLUMN fk_fac_rec_source integer; DELETE from llx_c_actioncomm where code in ('AC_PROP','AC_COM','AC_FAC','AC_SHIP','AC_SUP_ORD','AC_SUP_INV') AND id NOT IN (SELECT DISTINCT fk_action FROM llx_actioncomm); +ALTER TABLE llx_inventory ADD COLUMN ref varchar(48); \ No newline at end of file From 3898cfe02f4acf744595eee9fdd51fac5a562a57 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 23 May 2017 18:27:41 +0200 Subject: [PATCH 03/12] 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 55121c5e05cfee1fcd84e818f46fcb449972c245 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 May 2017 16:35:02 +0200 Subject: [PATCH 04/12] Fix: use encrypt for llx_const data --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 6c71f279867..8ae10636373 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 @@ -210,22 +210,22 @@ ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_invoic ALTER TABLE llx_facture_rec ADD COLUMN vat_src_code varchar(10) DEFAULT ''; -DELETE FROM llx_const where name = 'ADHERENT_BANK_USE_AUTO'; +DELETE FROM llx_const WHERE name = __ENCRYPT('ADHERENT_BANK_USE_AUTO')__; -UPDATE llx_const set value='moono-lisa' where value = 'moono' AND name = 'FCKEDITOR_SKIN'; +UPDATE llx_const SET value = __ENCRYPT('moono-lisa')__ WHERE value = __ENCRYPT('moono')__ AND name = __ENCRYPT('FCKEDITOR_SKIN')__; -ALTER TABLE llx_product_price ADD COLUMN default_vat_code varchar(10) after tva_tx; -ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code varchar(10) after tva_tx; +ALTER TABLE llx_product_price ADD COLUMN default_vat_code varchar(10) AFTER tva_tx; +ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code varchar(10) AFTER tva_tx; ALTER TABLE llx_user ADD COLUMN model_pdf varchar(255); ALTER TABLE llx_usergroup ADD COLUMN model_pdf varchar(255); -INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('PRODUCT_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/products', 'chaine', 0, ''); -INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('CONTRACT_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/contracts', 'chaine', 0, ''); -INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USERGROUP_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/usergroups', 'chaine', 0, ''); -INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USER_ADDON_PDF_ODT_PATH', 1, 'DOL_DATA_ROOT/doctemplates/users', 'chaine', 0, ''); +INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('PRODUCT_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/products')__, 'chaine', 0, ''); +INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('CONTRACT_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/contracts')__, 'chaine', 0, ''); +INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('USERGROUP_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/usergroups')__, 'chaine', 0, ''); +INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('USER_ADDON_PDF_ODT_PATH')__, 1, __ENCRYPT('DOL_DATA_ROOT/doctemplates/users')__, 'chaine', 0, ''); -INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('MAIN_ENABLE_OVERWRITE_TRANSLATION', 1, '1', 'chaine', 0, 'Enable overwrote of translation'); +INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES (__ENCRYPT('MAIN_ENABLE_OVERWRITE_TRANSLATION')__, 1, __ENCRYPT('1')__, 'chaine', 0, 'Enable overwrote of translation'); ALTER TABLE llx_chargesociales ADD COLUMN ref varchar(16); ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL; From 339d9dbfdf6a800b12387ba2226a95d2172d6865 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 May 2017 18:44:03 +0200 Subject: [PATCH 05/12] New: add REST api "dictionaryevents" for to use with "agendaevents" --- .../api/class/api_dictionaryevents.class.php | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 htdocs/api/class/api_dictionaryevents.class.php diff --git a/htdocs/api/class/api_dictionaryevents.class.php b/htdocs/api/class/api_dictionaryevents.class.php new file mode 100644 index 00000000000..23d7e8e5dba --- /dev/null +++ b/htdocs/api/class/api_dictionaryevents.class.php @@ -0,0 +1,100 @@ + + * + * 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; + +require_once DOL_DOCUMENT_ROOT.'/main.inc.php'; + +/** + * API class for events type (content of the actioncomm dictionary) + * + * @access protected + * @class DolibarrApiAccess {@requires user,external} + */ +class DictionaryEvents extends DolibarrApi +{ + /** + * Constructor + */ + function __construct() + { + global $db; + $this->db = $db; + } + + /** + * Get the list of events types. + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Number of items per page + * @param int $page Page number (starting from zero) + * @param string $type To filter on type of event + * @param string $module To filter on module events + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" + * @return List of events types + * + * @throws RestException + */ + function index($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $sqlfilters = '') + { + $list = array(); + + $sql = "SELECT id, code, type, libelle as label, module"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; + $sql.= " WHERE t.active = 1"; + if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; + if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; + // Add sql filters + 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.= $this->db->order($sortfield, $sortorder); + + if ($limit) { + if ($page < 0) { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $this->db->plimit($limit, $offset); + } + + $result = $this->db->query($sql); + + if ($result) { + $num = $this->db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + for ($i = 0; $i < $min; $i++) { + $list[] = $this->db->fetch_object($result); + } + } else { + throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror()); + } + + return $list; + } + +} From 659436f1ed0d62085aa0edfc56299fa3e4965d70 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 May 2017 19:33:44 +0200 Subject: [PATCH 06/12] Fix: wrong min value --- htdocs/adherents/class/api_members.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 9ea36bf579a..3b1bda41250 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -106,7 +106,7 @@ class Members extends DolibarrApi $sql.= ' AND t.fk_adherent_type='.$typeid; } // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -115,7 +115,7 @@ class Members extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -132,9 +132,10 @@ class Members extends DolibarrApi { $i=0; $num = $db->num_rows($result); - while ($i < min($limit, $num)) + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) { - $obj = $db->fetch_object($result); + $obj = $db->fetch_object($result); $member = new Adherent($this->db); if($member->fetch($obj->rowid)) { $obj_ret[] = $this->_cleanObjectDatas($member); From db6d7d9e21c63669241dfdcf3989fbce594460fa Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 25 May 2017 07:15:36 +0200 Subject: [PATCH 07/12] Spaces --- .../accountancy/class/bookkeeping.class.php | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index a59d92eb63a..c885d6228cb 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1053,23 +1053,23 @@ class BookKeeping extends CommonObject */ function deleteByYearAndJournal($delyear='', $journal='') { global $conf; - + if (empty($delyear) && empty($journal)) { return -1; } - + $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql.= " WHERE 1 = 1"; if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'"; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1083,7 +1083,7 @@ class BookKeeping extends CommonObject $this->db->commit(); return 1; } - + /** * Delete bookkepping by piece number * @@ -1092,17 +1092,17 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { global $conf; - + $this->db->begin(); // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1116,7 +1116,7 @@ class BookKeeping extends CommonObject $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * @@ -1130,27 +1130,27 @@ class BookKeeping extends CommonObject global $user; $error = 0; $object = new Accountingbookkeeping($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__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); @@ -1158,11 +1158,11 @@ class BookKeeping extends CommonObject return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1171,9 +1171,9 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { global $user; - + $now=dol_now(); - + $this->id = 0; $this->doc_date = $now; $this->doc_type = ''; @@ -1192,7 +1192,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1201,17 +1201,17 @@ class BookKeeping extends CommonObject */ public function fetchPerMvt($piecenum) { global $conf; - - $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; + + $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1222,10 +1222,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1233,8 +1233,8 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { - global $conf; - + global $conf; + $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; @@ -1243,16 +1243,16 @@ class BookKeeping extends CommonObject if ($result) { $obj = $this->db->fetch_object($result); - if ($obj) $result = $obj->max; - if (empty($result)) $result = 1; - return $result; + if ($obj) $result = $obj->max; + if (empty($result)) $result = 1; + return $result; } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::getNextNumMvt " . $this->error, LOG_ERR); return - 1; } } - + /** * Load all informations of accountancy document * @@ -1260,26 +1260,26 @@ class BookKeeping extends CommonObject * @return int <0 if KO, >0 if OK */ function fetch_all_per_mvt($piecenum) { - global $conf; - + global $conf; + $sql = "SELECT rowid, doc_date, doc_type,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; - + $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1294,7 +1294,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1302,10 +1302,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1313,28 +1313,28 @@ class BookKeeping extends CommonObject * @return int Result */ function export_bookkeping($model = 'ebp') { - global $conf; - + global $conf; + $sql = "SELECT rowid, doc_date, doc_type,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; - + $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1349,11 +1349,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); From ca08f814c1ded69a054fab469c7dc7615f2e71b9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 May 2017 19:38:42 +0200 Subject: [PATCH 08/12] Remove deprecated files --- htdocs/install/fileconf.php | 40 ++++++++++++++-------------- htdocs/theme/common/ical.gif | Bin 460 -> 0 bytes htdocs/theme/common/information.png | Bin 4180 -> 0 bytes htdocs/theme/common/rss.gif | Bin 476 -> 0 bytes htdocs/theme/common/vcal.gif | Bin 1079 -> 0 bytes htdocs/theme/login_background.png | Bin 79 -> 0 bytes 6 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 htdocs/theme/common/ical.gif delete mode 100644 htdocs/theme/common/information.png delete mode 100644 htdocs/theme/common/rss.gif delete mode 100644 htdocs/theme/common/vcal.gif delete mode 100644 htdocs/theme/login_background.png diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index cdd639ad50b..424126b63b6 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -86,7 +86,7 @@ if (! is_writable($conffile)) if (! empty($force_install_message)) { - print '
'.$langs->trans($force_install_message).'
'; + print '

'.$langs->trans($force_install_message).'
'; /*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); -// TODO +// 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"; -// Example 2: Adding links to objects -// The class must extend CommonObject for this method to be available -$somethingshown = $form->showLinkedObjectBlock($myobject); +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/template/scripts/myobject.php b/htdocs/modulebuilder/template/scripts/myobject.php new file mode 100644 index 00000000000..af381b0bfae --- /dev/null +++ b/htdocs/modulebuilder/template/scripts/myobject.php @@ -0,0 +1,165 @@ +#!/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 htdocs/modulebuilder/template/scripts/myobject.php + * \ingroup mymodule + * \brief This file is an example for a command line script to work on MyObject + */ + +$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 MyObject +dol_include_once("/mymodule/class/myobject.class.php"); +$myobject=new MyObject($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."myobject"; +$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/template/scripts/myscript.php b/htdocs/modulebuilder/template/scripts/myscript.php deleted file mode 100644 index 468729c59f3..00000000000 --- a/htdocs/modulebuilder/template/scripts/myscript.php +++ /dev/null @@ -1,203 +0,0 @@ -#!/usr/bin/env php - - * Copyright (C) - * - * 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 scripts/myscript.php - * \ingroup mymodule - * \brief Example command line script. - * - * Put detailed description here. - */ - -$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 "; - echo $script_file; - echo " from command line, you must use PHP for CLI mode.\n"; - exit; -} - -// Global variables -$version = '1.0.0'; -$error = 0; - - -/* - * -------------------- YOUR CODE STARTS HERE -------------------- - */ -/* Set this define to 0 if you want to allow execution of your script - * even if dolibarr setup is "locked to admin user only". */ -define('EVEN_IF_ONLY_LOGIN_ALLOWED', 0); - -/* Include Dolibarr environment - * Customize to your needs - */ -require_once $path . '../../../master.inc.php'; -/* After this $db, $conf, $langs, $mysoc, $user and other Dolibarr utility variables should be defined. - * Warning: this still requires a valid htdocs/conf.php file - */ - -global $conf, $db, $langs, $mysoc, $user; - -// No timeout for this script -@set_time_limit(0); - -// Set the default language -//$langs->setDefaultLang('en_US'); - -// Load translations for the default language -$langs->load("main"); - -/* User and permissions loading - * Loads user for login 'admin'. - * Comment out to run as anonymous user. */ -$result = $user->fetch('', 'admin'); -if (! $result > 0) { - dol_print_error('', $user->error); - exit; -} -$user->getrights(); - -// Display banner and help -echo "***** " . $script_file . " (" . $version . ") pid=" . getmypid() . " *****\n"; -dol_syslog($script_file . " launched with arg " . join(',', $argv)); -if (! isset($argv[1])) { - // Check parameters - echo "Usage: " . $script_file . " param1 param2 ...\n"; - exit; -} -echo '--- start' . "\n"; -echo 'Argument 1=' . $argv[1] . "\n"; -echo 'Argument 2=' . $argv[2] . "\n"; - -// Start database transaction -$db->begin(); - -// Examples for manipulating a class -require_once '../class/myclass.class.php'; -$myobject = new MyClass($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 { - echo "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 { - echo "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 { - echo "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 { - echo "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 . "c_pays"; - $sql.= " WHERE field3 = 'xxx'"; - $sql.= " ORDER BY field1 ASC"; - - dol_syslog($script_file . " sql=" . $sql, 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 - echo $obj->field1; - echo $obj->field2; - } - $i++; - } - } - } else { - $error++; - dol_print_error($db); - } - */ - - -/* - * --------------------- YOUR CODE ENDS HERE ---------------------- - */ - -// Error management -if (! $error) { - $db->commit(); - echo '--- end ok' . "\n"; - $exit_status = 0; // UNIX no errors exit status -} else { - echo '--- end error code=' . $error . "\n"; - $db->rollback(); - $exit_status = 1; // UNIX general error exit status -} - -// Close database handler -$db->close(); - -// Return exit status code -return $exit_status; diff --git a/htdocs/modulebuilder/template/sql/data.sql b/htdocs/modulebuilder/template/sql/data.sql index 90e9e0ced2b..82266dc08b3 100644 --- a/htdocs/modulebuilder/template/sql/data.sql +++ b/htdocs/modulebuilder/template/sql/data.sql @@ -14,6 +14,6 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -INSERT INTO llx_mytable VALUES ( +INSERT INTO llx_myobject VALUES ( 1, 1, 'mydata' ); diff --git a/htdocs/modulebuilder/template/sql/llx_mytable.key.sql b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql similarity index 90% rename from htdocs/modulebuilder/template/sql/llx_mytable.key.sql rename to htdocs/modulebuilder/template/sql/llx_myobject.key.sql index 56975f55a01..6fd4bb4cda6 100644 --- a/htdocs/modulebuilder/template/sql/llx_mytable.key.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql @@ -14,4 +14,4 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -ALTER TABLE llx_mytable ADD UNIQUE INDEX uk_fk_othertable (fk_othertable); +ALTER TABLE llx_myobject ADD UNIQUE INDEX uk_fk_othertable (fk_othertable); diff --git a/htdocs/modulebuilder/template/sql/llx_mytable.sql b/htdocs/modulebuilder/template/sql/llx_myobject.sql similarity index 97% rename from htdocs/modulebuilder/template/sql/llx_mytable.sql rename to htdocs/modulebuilder/template/sql/llx_myobject.sql index 2ef08b7fca1..edcd7a7c26d 100644 --- a/htdocs/modulebuilder/template/sql/llx_mytable.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.sql @@ -14,7 +14,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -CREATE TABLE llx_mytable( +CREATE TABLE llx_myobject( rowid INTEGER AUTO_INCREMENT PRIMARY KEY, entity INTEGER DEFAULT 1 NOT NULL, fk_othertable INTEGER NOT NULL, diff --git a/htdocs/modulebuilder/template/test/functional/MyModuleFunctionalTest.php b/htdocs/modulebuilder/template/test/phpunit/MyModuleFunctionalTest.php similarity index 100% rename from htdocs/modulebuilder/template/test/functional/MyModuleFunctionalTest.php rename to htdocs/modulebuilder/template/test/phpunit/MyModuleFunctionalTest.php diff --git a/htdocs/modulebuilder/template/test/unit/MyClassTest.php b/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php similarity index 91% rename from htdocs/modulebuilder/template/test/unit/MyClassTest.php rename to htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php index 94898e9209b..37a65323fda 100644 --- a/htdocs/modulebuilder/template/test/unit/MyClassTest.php +++ b/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php @@ -17,20 +17,18 @@ */ /** - * \file test/unit/MyClassTest.php + * \file test/unit/MyObjectTest.php * \ingroup mymodule - * \brief Example PHPUnit test. - * - * Put detailed description here. + * \brief PHPUnit test for MyObject class. */ namespace test\unit; /** - * Class MyClassTest + * Class MyObjectTest * @package Testmymodule */ -class MyClassTest extends \PHPUnit_Framework_TestCase +class MyObjectTest extends \PHPUnit_Framework_TestCase { /** * Global test setup From d0f01085d882f497f25ed039a0e93b167b179952 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 May 2017 02:44:14 +0200 Subject: [PATCH 12/12] Add more information on stripe payment --- htdocs/public/stripe/newpayment.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/htdocs/public/stripe/newpayment.php b/htdocs/public/stripe/newpayment.php index a430baafb59..01ae19c7032 100644 --- a/htdocs/public/stripe/newpayment.php +++ b/htdocs/public/stripe/newpayment.php @@ -181,6 +181,13 @@ if (! empty($conf->global->STRIPE_SECURITY_TOKEN)) } } +// Common variables +$creditor=$mysoc->name; +$paramcreditor='STRIPE_CREDITOR_'.$suffix; +if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; +else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIPE_CREDITOR; + + /* * Actions @@ -218,17 +225,20 @@ if ($action == 'charge') dol_syslog("Create customer", LOG_DEBUG, 0, '_stripe'); $customer = \Stripe\Customer::create(array( 'email' => $email, - 'card' => $stripeToken - // TODO + 'description' => ($email?'Customer for '.$email:null), + 'metadata' => array('ipaddress'=>$_SERVER['REMOTE_ADDR']), + '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, 'amount' => price2num($amount, 'MU'), 'currency' => $currency, 'description' => 'Stripe payment: '.$FULLTAG, - 'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars + 'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name), + 'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars that appears on bank receipt )); } catch(\Stripe\Error\Card $e) { // Since it's a decline, \Stripe\Error\Card will be caught @@ -330,12 +340,6 @@ if (empty($conf->global->STRIPE_LIVE)) dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); } -// Common variables -$creditor=$mysoc->name; -$paramcreditor='STRIPE_CREDITOR_'.$suffix; -if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; -else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIPE_CREDITOR; - print ''."\n"; print '
'."\n"; print '
'."\n";