From 675a17a74c3268aba45b5b1cc8e5a293ccdd603d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 26 Feb 2019 00:34:43 +0100 Subject: [PATCH] wip --- htdocs/core/modules/DolibarrModules.class.php | 69 +++++++++++-------- htdocs/core/modules/modNotification.class.php | 2 +- htdocs/core/modules/modPrelevement.class.php | 49 ++++++------- htdocs/core/modules/modProduct.class.php | 30 ++++---- htdocs/core/modules/modSalaries.class.php | 10 +-- .../core/modules/modMyModule.class.php | 2 +- 6 files changed, 89 insertions(+), 73 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 4aa74e22d5f..e5c3c2c63da 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -382,7 +382,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it * * @return int 1 if OK, 0 if KO */ - private function _init($array_sql, $options = '') + protected function _init($array_sql, $options = '') { global $conf; $err=0; @@ -484,7 +484,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it * * @return int 1 if OK, 0 if KO */ - private function _remove($array_sql, $options = '') + protected function _remove($array_sql, $options = '') { $err=0; @@ -658,11 +658,12 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it @include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php'; $content = dolMd2Html( - $content, 'parsedown', + $content, + 'parsedown', array( - 'doc/'=>dol_buildpath(strtolower($this->name).'/doc/', 1), - 'img/'=>dol_buildpath(strtolower($this->name).'/img/', 1), - 'images/'=>dol_buildpath(strtolower($this->name).'/imgages/', 1), + 'doc/' => dol_buildpath(strtolower($this->name).'/doc/', 1), + 'img/' => dol_buildpath(strtolower($this->name).'/img/', 1), + 'images/' => dol_buildpath(strtolower($this->name).'/imgages/', 1), ) ); } @@ -671,8 +672,9 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $content = nl2br($content); } } - else // Mostly for internal modules + else { + // Mostly for internal modules if (! empty($this->descriptionlong)) { if (is_array($this->langfiles)) { foreach($this->langfiles as $val) @@ -805,14 +807,20 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $ret=''; $newversion=preg_replace('/_deprecated/', '', $this->version); - if ($newversion == 'experimental') { $ret=($translated?$langs->transnoentitiesnoconv("VersionExperimental"):$newversion); - } elseif ($newversion == 'development') { $ret=($translated?$langs->transnoentitiesnoconv("VersionDevelopment"):$newversion); - } elseif ($newversion == 'dolibarr') { $ret=DOL_VERSION; - } elseif ($newversion) { $ret=$newversion; - } else { $ret=($translated?$langs->transnoentitiesnoconv("VersionUnknown"):'unknown'); + if ($newversion == 'experimental') { + $ret=($translated?$langs->transnoentitiesnoconv("VersionExperimental"):$newversion); + } elseif ($newversion == 'development') { + $ret=($translated?$langs->transnoentitiesnoconv("VersionDevelopment"):$newversion); + } elseif ($newversion == 'dolibarr') { + $ret=DOL_VERSION; + } elseif ($newversion) { + $ret=$newversion; + } else { + $ret=($translated?$langs->transnoentitiesnoconv("VersionUnknown"):'unknown'); } - if (preg_match('/_deprecated/', $this->version)) { $ret.=($translated?' ('.$langs->transnoentitiesnoconv("Deprecated").')':$this->version); + if (preg_match('/_deprecated/', $this->version)) { + $ret.=($translated?' ('.$langs->transnoentitiesnoconv("Deprecated").')':$this->version); } return $ret; } @@ -825,13 +833,17 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it */ public function isCoreOrExternalModule() { - if ($this->version == 'dolibarr' || $this->version == 'dolibarr_deprecated') { return 'core'; + if ($this->version == 'dolibarr' || $this->version == 'dolibarr_deprecated') { + return 'core'; } - if (! empty($this->version) && ! in_array($this->version, array('experimental','development'))) { return 'external'; + if (! empty($this->version) && ! in_array($this->version, array('experimental','development'))) { + return 'external'; } - if (! empty($this->editor_name) || ! empty($this->editor_url)) { return 'external'; + if (! empty($this->editor_name) || ! empty($this->editor_url)) { + return 'external'; } - if ($this->numero >= 100000) { return 'external'; + if ($this->numero >= 100000) { + return 'external'; } return 'unknown'; } @@ -911,11 +923,12 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql=$this->db->query($sql); - if (! $resql) { $err++; - } else - { + if (! $resql) { + $err++; + } else { $obj=$this->db->fetch_object($resql); - if ($obj) { return $this->db->jdate($obj->tms); + if ($obj) { + return $this->db->jdate($obj->tms); } } @@ -938,15 +951,16 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql=$this->db->query($sql); - if (! $resql) { $err++; - } else - { + if (! $resql) { + $err++; + } else { $obj=$this->db->fetch_object($resql); $tmp=array(); if ($obj->note) { $tmp=json_decode($obj->note, true); } - if ($obj) { return array('authorid'=>$tmp['authorid'], 'ip'=>$tmp['ip'], 'lastactivationdate'=>$this->db->jdate($obj->tms)); + if ($obj) { + return array('authorid'=>$tmp['authorid'], 'ip'=>$tmp['ip'], 'lastactivationdate'=>$this->db->jdate($obj->tms)); } } @@ -974,7 +988,8 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it dol_syslog(get_class($this)."::_active delete activation constant", LOG_DEBUG); $resql=$this->db->query($sql); - if (! $resql) { $err++; + if (! $resql) { + $err++; } $note=json_encode(array('authorid'=>(is_object($user)?$user->id:0), 'ip'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))); @@ -1029,7 +1044,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it * @param string $reldir Relative directory where to scan files * @return int <=0 if KO, >0 if OK */ - private function _load_tables($reldir) + protected function _load_tables($reldir) { // phpcs:enable global $conf; diff --git a/htdocs/core/modules/modNotification.class.php b/htdocs/core/modules/modNotification.class.php index c3ccca4ef46..c73c8210072 100644 --- a/htdocs/core/modules/modNotification.class.php +++ b/htdocs/core/modules/modNotification.class.php @@ -89,7 +89,7 @@ class modNotification extends DolibarrModules * @param string $options Options when enabling module ('', 'noboxes') * @return int 1 if OK, 0 if KO */ - function init($options = '') + public function init($options = '') { // Permissions $this->remove($options); diff --git a/htdocs/core/modules/modPrelevement.class.php b/htdocs/core/modules/modPrelevement.class.php index 17443b18197..ec4c4ca3a46 100644 --- a/htdocs/core/modules/modPrelevement.class.php +++ b/htdocs/core/modules/modPrelevement.class.php @@ -124,40 +124,41 @@ class modPrelevement extends DolibarrModules $this->rights[$r][4] = 'bons'; $this->rights[$r][5] = 'credit'; -/* $this->rights[2][0] = 154; + /* + $this->rights[2][0] = 154; $this->rights[2][1] = 'Setup withdraw account'; $this->rights[2][2] = 'w'; $this->rights[2][3] = 0; $this->rights[2][4] = 'bons'; $this->rights[2][5] = 'configurer'; -*/ + */ - // Menus - //------- - $this->menu = 1; // This module add menu entries. They are coded into menu manager. - } + // Menus + //------- + $this->menu = 1; // This module add menu entries. They are coded into menu manager. + } - /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ public function init($options = '') - { - global $conf; + { + global $conf; - // Permissions - $this->remove($options); + // Permissions + $this->remove($options); - $sql = array( - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'bankaccount' AND entity = ".$conf->entity, - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','bankaccount',".$conf->entity.")", - ); + $sql = array( + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'bankaccount' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','bankaccount',".$conf->entity.")", + ); - return $this->_init($sql, $options); - } + return $this->_init($sql, $options); + } } diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index 4a0af38dc34..368a41a6fac 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -521,7 +521,7 @@ class modProduct extends DolibarrModules if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR')); if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); -$this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array( + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array( 'sp.price'=>"PriceQtyMinHT*", 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty 'sp.remise_percent'=>'DiscountQtyMin' @@ -625,20 +625,20 @@ $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array } - /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories - * - * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - function init($options = '') - { - $this->remove($options); + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + public function init($options = '') + { + $this->remove($options); - $sql = array(); + $sql = array(); - return $this->_init($sql, $options); - } + return $this->_init($sql, $options); + } } diff --git a/htdocs/core/modules/modSalaries.class.php b/htdocs/core/modules/modSalaries.class.php index 390104f18b8..e111e81ef6b 100644 --- a/htdocs/core/modules/modSalaries.class.php +++ b/htdocs/core/modules/modSalaries.class.php @@ -159,12 +159,12 @@ class modSalaries extends DolibarrModules /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO */ public function init($options = '') { diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 029213f6804..d8bd86e36b2 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -360,7 +360,7 @@ class modMyModule extends DolibarrModules * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. * It also creates data directories * - * @param string $options Options when enabling module ('', 'noboxes') + * @param string $options Options when enabling module ('', 'noboxes') * @return int 1 if OK, 0 if KO */ public function init($options = '')