dolibarr 20.0.2
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
30require_once '../lib/ai.lib.php';
31
32$langs->loadLangs(array("admin"));
33
34// Parameters
35$action = GETPOST('action', 'aZ09');
36$backtopage = GETPOST('backtopage', 'alpha');
37$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
38
39if (empty($action)) {
40 $action = 'edit';
41}
42
43$value = GETPOST('value', 'alpha');
44$label = GETPOST('label', 'alpha');
45$scandir = GETPOST('scan_dir', 'alpha');
46$type = 'myobject';
47
48$error = 0;
49$setupnotempty = 0;
50
51// Access control
52if (!$user->admin) {
54}
55
56
57// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
58$useFormSetup = 1;
59
60if (!class_exists('FormSetup')) {
61 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
62}
63
64$formSetup = new FormSetup($db);
65
66// List all available IA
67$arrayofia = array(
68 'chatgpt' => 'ChatGPT',
69 'groq' => 'Groq',
70 //'gemini' => 'Gemini'
71);
72
73$item = $formSetup->newItem('AI_API_SERVICE'); // Name of constant must end with _KEY so it is encrypted when saved into database.
74$item->setAsSelect($arrayofia);
75$item->cssClass = 'minwidth150';
76
77foreach ($arrayofia as $ia => $ialabel) {
78 // Setup conf AI_PUBLIC_INTERFACE_TOPIC
79 /*$item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_ENDPOINT'); // Name of constant must end with _KEY so it is encrypted when saved into database.
80 $item->defaultFieldValue = '';
81 $item->cssClass = 'minwidth500';*/
82
83 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_KEY')->setAsSecureKey(); // Name of constant must end with _KEY so it is encrypted when saved into database.
84 $item->nameText = $langs->trans("AI_API_KEY").' ('.$ialabel.')';
85 $item->defaultFieldValue = '';
86 $item->fieldParams['hideGenerateButton'] = 1;
87 $item->cssClass = 'minwidth500 text-security';
88}
89
90$setupnotempty = + count($formSetup->items);
91
92
93$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
94
95
96/*
97 * Actions
98 */
99
100include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
101
102$action = 'edit';
103
104
105/*
106 * View
107 */
108
109$form = new Form($db);
110
111$help_url = '';
112$title = "AiSetup";
113
114llxHeader('', $langs->trans($title), $help_url);
115
116// Subheader
117$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
118
119print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
120
121// Configuration header
122$head = aiAdminPrepareHead();
123print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "fa-microchip");
124
125
126if ($action == 'edit') {
127 print $formSetup->generateOutput(true);
128 print '<br>';
129} elseif (!empty($formSetup->items)) {
130 print $formSetup->generateOutput();
131 print '<div class="tabsAction">';
132 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
133 print '</div>';
134} else {
135 print '<br>'.$langs->trans("NothingToSetup");
136}
137
138
139if (empty($setupnotempty)) {
140 print '<br>'.$langs->trans("NothingToSetup");
141}
142
143// Page end
144print dol_get_fiche_end();
145
146llxFooter();
147$db->close();
aiAdminPrepareHead()
Prepare admin pages header.
Definition ai.lib.php:30
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
This class help you create setup render.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.