diff --git a/htdocs/ai/admin/setup.php b/htdocs/ai/admin/setup.php index 6a6e15db8ed..af410762a88 100644 --- a/htdocs/ai/admin/setup.php +++ b/htdocs/ai/admin/setup.php @@ -31,11 +31,6 @@ global $langs, $user; require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once '../lib/ai.lib.php'; -// Access control -if (!$user->admin) { - accessforbidden(); -} - // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); @@ -46,10 +41,15 @@ $label = GETPOST('label', 'alpha'); $scandir = GETPOST('scan_dir', 'alpha'); $type = 'myobject'; - $error = 0; $setupnotempty = 0; +// Access control +if (!$user->admin) { + accessforbidden(); +} + + // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only $useFormSetup = 1; @@ -59,20 +59,16 @@ if (!class_exists('FormSetup')) { $formSetup = new FormSetup($db); -// Setup conf AI_PUBLIC_INTERFACE_TOPIC -$item = $formSetup->newItem('AI_KEY_API_CHATGPT'); -$item->defaultFieldValue = ''; +$arrayofia = array('chatgpt'); - -// Save API Key -if ($_SERVER["REQUEST_METHOD"] == "POST") { - $apiKey = GETPOST('api_key', 'alpha'); - // Validate and clean $apiKey here - dolibarr_set_const($db, 'MAIN_AI_CHATGPT_API_KEY', $apiKey, 'chaine', 0, '', $conf->entity); +foreach($arrayofia as $ia) { + // Setup conf AI_PUBLIC_INTERFACE_TOPIC + $item = $formSetup->newItem('AI_KEY_API_'.strtoupper($ia)); + $item->defaultFieldValue = ''; } // Retrieve existing API Key -$apiKey = dolibarr_get_const($db, 'MAIN_AI_CHATGPT_API_KEY'); +//$apiKey = dolibarr_get_const($db, 'MAIN_AI_CHATGPT_API_KEY'); $setupnotempty =+ count($formSetup->items); @@ -84,11 +80,6 @@ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); * Actions */ -// For retrocompatibility Dolibarr < 15.0 -if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) { - $formSetup->saveConfFromPost(); -} - include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if ($action == 'updateMask') { diff --git a/htdocs/langs/en_US/ai.lang b/htdocs/langs/en_US/ai.lang index 287e652b7ec..0f595c2d022 100644 --- a/htdocs/langs/en_US/ai.lang +++ b/htdocs/langs/en_US/ai.lang @@ -1,3 +1,4 @@ AiDescription=AI (Artificial Intelligence) features AiDescriptionLong=Provides AI (Artificial Intelligence) features in different part of the application. Need external AI API. -AI_KEY_API_CHATGPT= Key for IA api \ No newline at end of file +AI_KEY_API_CHATGPT= Key for IA api +AiSetup=AI module setup \ No newline at end of file diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index d23368dbfc2..0129689133b 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -64,11 +64,6 @@ $langs->loadLangs(array("admin", "mymodule@mymodule")); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('mymodulesetup', 'globalsetup')); -// Access control -if (!$user->admin) { - accessforbidden(); -} - // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); @@ -79,10 +74,15 @@ $label = GETPOST('label', 'alpha'); $scandir = GETPOST('scan_dir', 'alpha'); $type = 'myobject'; - $error = 0; $setupnotempty = 0; +// Access control +if (!$user->admin) { + accessforbidden(); +} + + // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only $useFormSetup = 1; @@ -91,6 +91,11 @@ if (!class_exists('FormSetup')) { } $formSetup = new FormSetup($db); +// Access control +if (!$user->admin) { + accessforbidden(); +} + // Enter here all parameters in your setup page