From a2df87ab15ff9186d3702ce16998bacd22965efe Mon Sep 17 00:00:00 2001 From: alexis Algoud Date: Tue, 5 Dec 2017 11:34:07 +0100 Subject: [PATCH 1/3] NEW warning on module blocked log reset if country code is FR fix wrong paste click --- htdocs/admin/modules.php | 38 +++++++++++++-- htdocs/core/modules/modBlockedLog.class.php | 51 ++++++++++++++++++++- htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/blockedlog.lang | 3 +- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 25352372d8d..82f1df1b7d5 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -94,6 +94,8 @@ $hookmanager->initHooks(array('adminmodules','globaladmin')); * Actions */ +$formconfirm = ''; + $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'); @@ -236,8 +238,7 @@ if ($action == 'set' && $user->admin) header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); exit; } - -if ($action == 'reset' && $user->admin) +else if ($action == 'reset' && $user->admin && GETPOST('confirm') == 'yes') { $result=unActivateModule($value); if ($result) setEventMessages($result, null, 'errors'); @@ -423,6 +424,22 @@ foreach ($modulesdir as $dir) } } +if ($action == 'reset_confirm' && $user->admin) +{ + if(!empty($modules[$value])) { + $objMod = $modules[$value]; + + if(!empty($objMod->langfiles)) $langs->loadLangs($objMod->langfiles); + + $form = new Form($db); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmUnactivation'), $langs->trans(GETPOST('confirm_message_code')), 'reset', '', 'no', 1); + + } + +} + +print $formconfirm; + asort($orders); //var_dump($orders); //var_dump($categ); @@ -679,9 +696,20 @@ if ($mode == 'common') } else { - print ''; - print img_picto($langs->trans("Activated"),'switch_on'); - print ''; + if(!empty($objMod->warnings_unactivation[$mysoc->country_code]) && method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) { + print 'warnings_unactivation[$mysoc->country_code].'&value=' . $modName . '&mode=' . $mode . $param . '">'; + print img_picto($langs->trans("Activated"),'switch_on'); + print ''; + + } + else { + + print ''; + print img_picto($langs->trans("Activated"),'switch_on'); + print ''; + + } + } print ''."\n"; diff --git a/htdocs/core/modules/modBlockedLog.class.php b/htdocs/core/modules/modBlockedLog.class.php index 6928c6f6f1c..493c0ad513a 100644 --- a/htdocs/core/modules/modBlockedLog.class.php +++ b/htdocs/core/modules/modBlockedLog.class.php @@ -69,8 +69,10 @@ class modBlockedLog extends DolibarrModules $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with - $this->langfiles = array(); + $this->langfiles = array('blockedlog'); + $this->warnings_unactivation = array('FR'=>'BlockedLogAreRequiredByYourCountryLegislation'); + // Constants //----------- @@ -87,4 +89,51 @@ class modBlockedLog extends DolibarrModules //------------------ $this->menu = array(); } + + /** + * Check if module was already used before unactivation linked to warnings_unactivation property + */ + function alreadyUsed() { + + $res = $this->db->query("SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."blockedlog"); + if($res!==false) { + $obj = $this->db->fetch_object($res); + return ($obj->nb > 0); + } + + return false; + } + + /** + * Function called when module is disabled. + * The remove function removes tabs, constants, boxes, permissions and menus from Dolibarr database. + * Data directories are not deleted + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function remove($options = '') { + + global $user; + + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; + + $object=new stdClass; + $object->id = 1; + $object->element = 'module'; + $object->ref = 'module'; + $object->date = time(); + + $b=new BlockedLog($this->db); + $b->setObjectData($object, 'MODULE_RESET', -1); + + $res = $b->create($user); + if($res<=0) { + $this->error = $b->error; + return $res; + } + + return $this->_remove(array(), $options); + + } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index b8673911f7f..fc3caa74657 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1765,3 +1765,4 @@ ResourceSetup=Configuration du module Resource UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list). DisabledResourceLinkUser=Disabled resource link to user DisabledResourceLinkContact=Disabled resource link to contact +ConfirmUnactivation=Confirm module reset diff --git a/htdocs/langs/en_US/blockedlog.lang b/htdocs/langs/en_US/blockedlog.lang index 9c4edd35a52..5c4c84eb2ab 100644 --- a/htdocs/langs/en_US/blockedlog.lang +++ b/htdocs/langs/en_US/blockedlog.lang @@ -26,4 +26,5 @@ DownloadLogCSV=Download archive logs (CSV) logDOC_PREVIEW=Preview of a validated document in order to print or download logDOC_DOWNLOAD=Download of a validated document in order to print or send DataOfArchivedEvent=Full datas of archived event -ImpossibleToReloadObject=Object (type %s, id %s) removed \ No newline at end of file +ImpossibleToReloadObject=Object (type %s, id %s) removed +BlockedLogAreRequiredByYourCountryLegislation=Unalterable logs are required by the legislation of your country. Disabling this module may render any future transactions invalid with respect to the law and the use of non-legal software as it can not be validated by a tax audit. \ No newline at end of file From ad46bf9a947ca937eef491d3b7bba7f2f573553c Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Tue, 5 Dec 2017 18:30:48 +0100 Subject: [PATCH 2/3] NEW option to avoid countries to disable there blockedlog --- htdocs/blockedlog/admin/blockedlog.php | 34 ++++++++++++++++++++- htdocs/core/modules/modBlockedLog.class.php | 5 ++- htdocs/langs/en_US/blockedlog.lang | 3 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/htdocs/blockedlog/admin/blockedlog.php b/htdocs/blockedlog/admin/blockedlog.php index b3822a9acb7..399ace64ad9 100644 --- a/htdocs/blockedlog/admin/blockedlog.php +++ b/htdocs/blockedlog/admin/blockedlog.php @@ -41,7 +41,10 @@ $action = GETPOST('action','alpha'); if (preg_match('/set_(.*)/',$action,$reg)) { $code=$reg[1]; - if (dolibarr_set_const($db, $code, GETPOST($code), 'chaine', 0, '', $conf->entity) > 0) + $values = GETPOST($code); + if(is_array($values))$values = implode(',', $values); + + if (dolibarr_set_const($db, $code, $values, 'chaine', 0, '', $conf->entity) > 0) { header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -115,6 +118,35 @@ if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) { print ''; } +$var=!$var; +print ''; +print ''.$langs->trans("BlockedLogDisableNotAllowedForCountry").''; +print ''; +print '
'; +print ''; +print ''; + +$sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; +$sql.= " FROM ".MAIN_DB_PREFIX."c_country"; +$sql.= " WHERE active > 0"; + +$countryArray=array(); +$resql=$db->query($sql); +if ($resql) +{ + while ($obj = $db->fetch_object($resql)) + { + $countryArray[$obj->code_iso] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->transnoentitiesnoconv("Country".$obj->code_iso):($obj->label!='-'?$obj->label:'')); + } +} + +$seledted = empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY) ? array() : explode(',',$conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY); + +print $form->multiselectarray('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', $countryArray, $seledted); +print ''; +print '
'; +print ''; + print ''; dol_fiche_end(); diff --git a/htdocs/core/modules/modBlockedLog.class.php b/htdocs/core/modules/modBlockedLog.class.php index 493c0ad513a..5056bdd7a36 100644 --- a/htdocs/core/modules/modBlockedLog.class.php +++ b/htdocs/core/modules/modBlockedLog.class.php @@ -36,7 +36,7 @@ class modBlockedLog extends DolibarrModules */ function __construct($db) { - global $langs,$conf; + global $langs,$conf,$mysoc; $this->db = $db; $this->numero = 3200; @@ -88,6 +88,9 @@ class modBlockedLog extends DolibarrModules // Main menu entries //------------------ $this->menu = array(); + + $this->always_enabled = !empty($conf->blockedlog->enabled) && !empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY) && in_array($mysoc->country_code, explode(',', $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY)); + } /** diff --git a/htdocs/langs/en_US/blockedlog.lang b/htdocs/langs/en_US/blockedlog.lang index 5c4c84eb2ab..46e63f3e6c7 100644 --- a/htdocs/langs/en_US/blockedlog.lang +++ b/htdocs/langs/en_US/blockedlog.lang @@ -27,4 +27,5 @@ logDOC_PREVIEW=Preview of a validated document in order to print or download logDOC_DOWNLOAD=Download of a validated document in order to print or send DataOfArchivedEvent=Full datas of archived event ImpossibleToReloadObject=Object (type %s, id %s) removed -BlockedLogAreRequiredByYourCountryLegislation=Unalterable logs are required by the legislation of your country. Disabling this module may render any future transactions invalid with respect to the law and the use of non-legal software as it can not be validated by a tax audit. \ No newline at end of file +BlockedLogAreRequiredByYourCountryLegislation=Unalterable logs are required by the legislation of your country. Disabling this module may render any future transactions invalid with respect to the law and the use of non-legal software as it can not be validated by a tax audit. +BlockedLogDisableNotAllowedForCountry=Disable not allowed for this countries \ No newline at end of file From 62cd77d999594b5716fbe9b0afb11544ebb0488e Mon Sep 17 00:00:00 2001 From: alexis Algoud Date: Fri, 8 Dec 2017 10:13:03 +0100 Subject: [PATCH 3/3] NEW automatic activation of external module on country set --- htdocs/admin/company.php | 1 + htdocs/core/lib/admin.lib.php | 76 +++++++++++++++++++++ htdocs/core/modules/modBlockedLog.class.php | 2 + htdocs/langs/en_US/blockedlog.lang | 1 + 4 files changed, 80 insertions(+) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 517c57c7d0b..ce830646826 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -69,6 +69,7 @@ if ( ($action == 'update' && ! GETPOST("cancel",'alpha')) $s=$mysoc->country_id.':'.$mysoc->country_code.':'.$mysoc->country_label; dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s,'chaine',0,'',$conf->entity); + module_require_by_country($mysoc->country_code); } dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", GETPOST("nom",'nohtml'),'chaine',0,'',$conf->entity); diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 422e7be984d..47624b2e05d 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1132,6 +1132,82 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql return 1; } +/** + * Activate external modules for country if neccessary + * + * @param string $country_code CountryCode + * @return int 1 + */ +function module_require_by_country($country_code) +{ + global $db, $conf, $langs; + + $modulesdir = dolGetModulesDirs(); + + foreach ($modulesdir as $dir) + { + // Load modules attributes in arrays (name, numero, orders) from dir directory + dol_syslog("Scan directory ".$dir." for modules"); + $handle=@opendir(dol_osencode($dir)); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') + { + $modName = substr($file, 0, dol_strlen($file) - 10); + + if ($modName) + { + include_once $dir.$file; + $objMod = new $modName($db); + + if ($objMod->numero > 0) + { + $j = $objMod->numero; + } + else + { + $j = 1000 + $i; + } + + $modulequalified=1; + + // We discard modules according to features level (PS: if module is activated we always show it) + $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod))); + + if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; + if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + if(!empty($conf->global->$const_name)) $modulequalified=0; // already activated + + if ($modulequalified) + { + // Load languages files of module + if (isset($objMod->automatic_activation) && is_array($objMod->automatic_activation) && isset($objMod->automatic_activation[$country_code])) + { + + activateModule($modName); + + setEventMessage($objMod->automatic_activation[$country_code],'warnings'); + + } + + } + else dol_syslog("Module ".get_class($objMod)." not qualified"); + } + } + } + closedir($handle); + } + else + { + dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING); + } + } + + return 1; +} + /** * Add external modules to list of contact element * diff --git a/htdocs/core/modules/modBlockedLog.class.php b/htdocs/core/modules/modBlockedLog.class.php index 5056bdd7a36..7c1227e14fe 100644 --- a/htdocs/core/modules/modBlockedLog.class.php +++ b/htdocs/core/modules/modBlockedLog.class.php @@ -73,6 +73,8 @@ class modBlockedLog extends DolibarrModules $this->warnings_unactivation = array('FR'=>'BlockedLogAreRequiredByYourCountryLegislation'); + $this->automatic_activation = array('FR'=>'BlockedLogActivatedBecauseRequiredByYourCountryLegislation'); + // Constants //----------- diff --git a/htdocs/langs/en_US/blockedlog.lang b/htdocs/langs/en_US/blockedlog.lang index 46e63f3e6c7..8f3ef9ff22e 100644 --- a/htdocs/langs/en_US/blockedlog.lang +++ b/htdocs/langs/en_US/blockedlog.lang @@ -28,4 +28,5 @@ logDOC_DOWNLOAD=Download of a validated document in order to print or send DataOfArchivedEvent=Full datas of archived event ImpossibleToReloadObject=Object (type %s, id %s) removed BlockedLogAreRequiredByYourCountryLegislation=Unalterable logs are required by the legislation of your country. Disabling this module may render any future transactions invalid with respect to the law and the use of non-legal software as it can not be validated by a tax audit. +BlockedLogActivatedBecauseRequiredByYourCountryLegislation=Unalterable logs module was activated because of the legislation of your country. Disabling this module may render any future transactions invalid with respect to the law and the use of non-legal software as it can not be validated by a tax audit. BlockedLogDisableNotAllowedForCountry=Disable not allowed for this countries \ No newline at end of file