dolibarr 21.0.0-beta
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 * Coryright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
31require_once '../lib/ai.lib.php';
32
41$langs->loadLangs(array("admin"));
42
43// Parameters
44$action = GETPOST('action', 'aZ09');
45$backtopage = GETPOST('backtopage', 'alpha');
46$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
47
48if (empty($action)) {
49 $action = 'edit';
50}
51
52$value = GETPOST('value', 'alpha');
53$label = GETPOST('label', 'alpha');
54$scandir = GETPOST('scan_dir', 'alpha');
55$type = 'myobject';
56
57$error = 0;
58$setupnotempty = 0;
59
60
61// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
62$useFormSetup = 1;
63
64if (!class_exists('FormSetup')) {
65 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
66}
67
68$formSetup = new FormSetup($db);
69
70// List all available IA
71$arrayofia = array(
72 'chatgpt' => 'ChatGPT',
73 'groq' => 'Groq',
74 'custom' => 'Custom'
75 //'gemini' => 'Gemini'
76);
77
78$item = $formSetup->newItem('AI_API_SERVICE'); // Name of constant must end with _KEY so it is encrypted when saved into database.
79$item->setAsSelect($arrayofia);
80$item->cssClass = 'minwidth150';
81
82foreach ($arrayofia as $ia => $ialabel) {
83 // Setup conf AI_PUBLIC_INTERFACE_TOPIC
84 /*$item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_ENDPOINT'); // Name of constant must end with _KEY so it is encrypted when saved into database.
85 $item->defaultFieldValue = '';
86 $item->cssClass = 'minwidth500';*/
87
88 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_KEY')->setAsSecureKey(); // Name of constant must end with _KEY so it is encrypted when saved into database.
89 $item->nameText = $langs->trans("AI_API_KEY").' ('.$ialabel.')';
90 $item->defaultFieldValue = '';
91 $item->fieldParams['hideGenerateButton'] = 1;
92 $item->fieldParams['trClass'] = $ia;
93 $item->cssClass = 'minwidth500 text-security';
94
95 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_URL'); // Name of constant must end with _KEY so it is encrypted when saved into database.
96 $item->nameText = $langs->trans("AI_API_URL").' ('.$ialabel.')';
97 $item->defaultFieldValue = '';
98 $item->fieldParams['trClass'] = $ia;
99 $item->cssClass = 'minwidth500';
100}
101
102$setupnotempty = + count($formSetup->items);
103
104
105$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
106
107// Access control
108if (!$user->admin) {
110}
111if (!isModEnabled('ai')) {
112 accessforbidden('Module AI not activated.');
113}
114
115
116/*
117 * Actions
118 */
119
120include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
121
122$action = 'edit';
123
124
125/*
126 * View
127 */
128
129$form = new Form($db);
130
131$help_url = '';
132$title = "AiSetup";
133
134llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-ai page-admin');
135
136// Subheader
137$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
138
139print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
140
141// Configuration header
142$head = aiAdminPrepareHead();
143print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "fa-microchip");
144
145
146if ($action == 'edit') {
147 print $formSetup->generateOutput(true);
148 print '<br>';
149} elseif (!empty($formSetup->items)) {
150 print $formSetup->generateOutput();
151 print '<div class="tabsAction">';
152 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
153 print '</div>';
154} else {
155 print '<br>'.$langs->trans("NothingToSetup");
156}
157
158
159if (empty($setupnotempty)) {
160 print '<br>'.$langs->trans("NothingToSetup");
161}
162
163// Page end
164print dol_get_fiche_end();
165
166llxFooter();
167$db->close();
aiAdminPrepareHead()
Prepare admin pages header.
Definition ai.lib.php:31
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
This class help you create setup render.
llxFooter()
Footer empty.
Definition document.php:107
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.