Clean code

This commit is contained in:
Laurent Destailleur 2023-02-21 13:19:57 +01:00
parent 44da230012
commit b0cf8cd72d
9 changed files with 46 additions and 32 deletions

View File

@ -51,6 +51,12 @@ class Conf
public $mycompany;
public $admin;
public $medias;
//! To store properties of multi-company
public $multicompany;
//! To store module status of special module names
public $expedition_bon;
public $delivery_note;
//! To store if javascript/ajax is enabked
@ -84,8 +90,6 @@ class Conf
*/
public $loghandlers = array();
//! To store properties of multi-company
public $multicompany;
//! Used to store running instance for multi-company (default 1)
public $entity = 1;
//! Used to store list of entities to use for each element
@ -148,8 +152,6 @@ class Conf
// First level object that are modules.
// TODO Remove this part.
$this->multicompany = new stdClass();
$this->expedition_bon = new stdClass();
$this->delivery_note = new stdClass();
$this->fournisseur = new stdClass();
$this->product = new stdClass();
$this->service = new stdClass();
@ -164,7 +166,6 @@ class Conf
$this->adherent = new stdClass();
$this->bank = new stdClass();
$this->notification = new stdClass();
$this->mailing = new stdClass();
$this->expensereport = new stdClass();
$this->productbatch = new stdClass();
}
@ -217,8 +218,6 @@ class Conf
// First level object
// TODO Remove this part.
$this->expedition_bon = new stdClass();
$this->delivery_note = new stdClass();
$this->fournisseur = new stdClass();
$this->product = new stdClass();
$this->service = new stdClass();
@ -233,7 +232,6 @@ class Conf
$this->adherent = new stdClass();
$this->bank = new stdClass();
$this->notification = new stdClass();
$this->mailing = new stdClass();
$this->expensereport = new stdClass();
$this->productbatch = new stdClass();
@ -503,8 +501,10 @@ class Conf
// Exception: Some dir are not the name of module. So we keep exception here for backward compatibility.
// Sous module bons d'expedition
$this->expedition_bon = new stdClass();
$this->expedition_bon->enabled = (empty($this->global->MAIN_SUBMODULE_EXPEDITION) ? 0 : $this->global->MAIN_SUBMODULE_EXPEDITION);
// Sub module delivery note Sous module bons de livraison
$this->delivery_note = new stdClass();
$this->delivery_note->enabled = (empty($this->global->MAIN_SUBMODULE_DELIVERY) ? 0 : $this->global->MAIN_SUBMODULE_DELIVERY);
// Module fournisseur
@ -705,22 +705,26 @@ class Conf
$this->theme = $this->global->MAIN_THEME;
$this->css = "/theme/".$this->theme."/style.css.php";
// conf->email_from = email pour envoi par dolibarr des mails automatiques
// conf->email_from = email by default to send Dolibarr automatic emails
$this->email_from = "robot@example.com";
if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) {
$this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM;
}
// conf->notification->email_from = email pour envoi par Dolibarr des notifications
$this->notification->email_from = $this->email_from;
if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) {
$this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
// conf->notification->email_from = email by default to send Dolibarr notifications
if (isModEnabled('notification')) {
$this->notification->email_from = $this->email_from;
if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) {
$this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
}
}
// conf->mailing->email_from = email pour envoi par Dolibarr des mailings
$this->mailing->email_from = $this->email_from;
if (!empty($this->global->MAILING_EMAIL_FROM)) {
$this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
// conf->mailing->email_from = email by default to send Dolibarr emailings
if (isModEnabled('mailing')) {
$this->mailing->email_from = $this->email_from;
if (!empty($this->global->MAILING_EMAIL_FROM)) {
$this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
}
}
if (!isset($this->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {

View File

@ -47,10 +47,10 @@ function propal_prepare_head($object)
$langs->load("sendings");
$text = '';
$head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$object->id;
if ($conf->expedition_bon->enabled) {
if (isModEnabled('expedition_bon')) {
$text = $langs->trans("Shipment");
}
if ($conf->delivery_note->enabled) {
if (isModEnabled('delivery_note')) {
$text .= '/'.$langs->trans("Receivings");
}
$head[$h][1] = $text;

View File

@ -133,7 +133,7 @@ function delivery_prepare_head($object)
$h = 0;
$head = array();
if ($conf->expedition_bon->enabled && $user->rights->expedition->lire) {
if (isModEnabled('expedition_bon') && $user->rights->expedition->lire) {
$head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->origin_id;
$head[$h][1] = $langs->trans("SendingCard");
$head[$h][2] = 'shipping';

View File

@ -437,9 +437,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
-- Tools
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'empty($user->socid)', __HANDLER__, 'left', 3900__+MAX_llx_menu__, 'tools', 'email_templates', 8__+MAX_llx_menu__, '/admin/mails_templates.php?mainmenu=tools&leftmenu=email_templates', 'EMailTemplates', 0, '', '', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3910__+MAX_llx_menu__, 'tools', 'mailing', 8__+MAX_llx_menu__, '/comm/mailing/index.php?mainmenu=tools&leftmenu=mailing', 'EMailings', 0, 'mails', '$user->rights->mailing->lire', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3911__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/card.php?mainmenu=tools&leftmenu=mailing&action=create', 'NewMailing', 1, 'mails', '$user->rights->mailing->creer', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3912__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/list.php?mainmenu=tools&leftmenu=mailing', 'List', 1, 'mails', '$user->rights->mailing->lire', '', 0, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("mailing")', __HANDLER__, 'left', 3910__+MAX_llx_menu__, 'tools', 'mailing', 8__+MAX_llx_menu__, '/comm/mailing/index.php?mainmenu=tools&leftmenu=mailing', 'EMailings', 0, 'mails', '$user->rights->mailing->lire', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("mailing")', __HANDLER__, 'left', 3911__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/card.php?mainmenu=tools&leftmenu=mailing&action=create', 'NewMailing', 1, 'mails', '$user->rights->mailing->creer', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("mailing")', __HANDLER__, 'left', 3912__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/list.php?mainmenu=tools&leftmenu=mailing', 'List', 1, 'mails', '$user->rights->mailing->lire', '', 0, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->export->enabled', __HANDLER__, 'left', 4100__+MAX_llx_menu__, 'tools', 'export', 8__+MAX_llx_menu__, '/exports/index.php?mainmenu=tools&leftmenu=export', 'FormatedExport', 0, 'exports', '$user->rights->export->lire', '', 2, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->export->enabled', __HANDLER__, 'left', 4101__+MAX_llx_menu__, 'tools', '', 4100__+MAX_llx_menu__, '/exports/export.php?mainmenu=tools&leftmenu=export', 'NewExport', 1, 'exports', '$user->rights->export->creer', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->import->enabled', __HANDLER__, 'left', 4130__+MAX_llx_menu__, 'tools', 'import', 8__+MAX_llx_menu__, '/imports/index.php?mainmenu=tools&leftmenu=import', 'FormatedImport', 0, 'exports', '$user->rights->import->run', '', 2, 2, __ENTITY__);

View File

@ -104,7 +104,7 @@ if ($action == 'add') {
$object->commande_id = GETPOST("commande_id", 'int');
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
if (!$conf->expedition_bon->enabled && isModEnabled('stock')) {
if (!isModEnabled('expedition_bon') && isModEnabled('stock')) {
$expedition->entrepot_id = GETPOST('entrepot_id', 'int');
}
@ -479,7 +479,7 @@ if ($action == 'create') {
print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
print '</tr>';*/
if (!$conf->expedition_bon->enabled && isModEnabled('stock')) {
if (!isModEnabled('expedition_bon') && isModEnabled('stock')) {
// Entrepot
$entrepot = new Entrepot($db);
$entrepot->fetch($object->entrepot_id);
@ -647,7 +647,7 @@ if ($action == 'create') {
}
if ($user->rights->expedition->delivery->supprimer) {
if ($conf->expedition_bon->enabled) {
if (isModEnabled('expedition_bon')) {
print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;expid='.$object->origin_id.'&amp;action=delete&amp;token='.newToken().'&amp;backtopage='.urlencode(DOL_URL_ROOT.'/expedition/card.php?id='.$object->origin_id), '');
} else {
print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&amp;token='.newToken().'&amp;id='.$object->id, '');

View File

@ -201,7 +201,7 @@ class Delivery extends CommonObject
dol_syslog("Delivery::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if (!$conf->expedition_bon->enabled) {
if (!isModEnabled('expedition_bon')) {
$commande = new Commande($this->db);
$commande->id = $this->commande_id;
$commande->fetch_lines();
@ -229,7 +229,7 @@ class Delivery extends CommonObject
$error++;
}
if (!$conf->expedition_bon->enabled) {
if (!isModEnabled('expedition_bon')) {
// TODO standardize status uniformiser les statuts
$ret = $this->setStatut(2, $this->origin_id, $this->origin);
if (!$ret) {

View File

@ -617,7 +617,7 @@ if (empty($reshook)) {
$result = $object->create($user);
if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email) && $object->no_email == 1) {
if (empty($error) && isModEnabled('mailing') && !empty($object->email) && $object->no_email == 1) {
// Add mass emailing flag into table mailing_unsubscribe
$result = $object->setNoEmail($object->no_email);
if ($result < 0) {
@ -1633,7 +1633,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
// Unsubscribe
if (!empty($conf->mailing->enabled)) {
if (isModEnabled('mailing')) {
if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
print "\n".'<script type="text/javascript">'."\n";
print '$(document).ready(function () {
@ -2344,7 +2344,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '</td></tr>';
// Unsubscribe
if (!empty($conf->mailing->enabled)) {
if (isModEnabled('mailing')) {
if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
print "\n".'<script type="text/javascript">'."\n";
@ -3031,7 +3031,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '</td></tr>';
// Unsubscribe opt-out
if (!empty($conf->mailing->enabled)) {
if (isModEnabled('mailing')) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');

View File

@ -73,6 +73,11 @@ if (empty($conf->global->MAILING_LIMIT_SENDBYCLI)) {
$langs->loadLangs(array("main", "mails"));
if (!isModEnabled('mailing')) {
print 'Module Emailing not enabled';
exit(-1);
}
/*
* Main

View File

@ -57,6 +57,11 @@ require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";
$version = DOL_VERSION;
$error = 0;
if (!isModEnabled('mailing')) {
print 'Module Emailing not enabled';
exit(-1);
}
/*
* Main