dolibarr 21.0.0-alpha
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
33$langs->loadLangs(array("admin"));
34
35// Parameters
36$action = GETPOST('action', 'aZ09');
37$backtopage = GETPOST('backtopage', 'alpha');
38$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
39
40if (empty($action)) {
41 $action = 'edit';
42}
43
44$value = GETPOST('value', 'alpha');
45$label = GETPOST('label', 'alpha');
46$scandir = GETPOST('scan_dir', 'alpha');
47$type = 'myobject';
48
49$error = 0;
50$setupnotempty = 0;
51
52
53// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
54$useFormSetup = 1;
55
56if (!class_exists('FormSetup')) {
57 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
58}
59
60$formSetup = new FormSetup($db);
61
62// List all available IA
63$arrayofia = array(
64 'chatgpt' => 'ChatGPT',
65 'groq' => 'Groq',
66 'custom' => 'Custom'
67 //'gemini' => 'Gemini'
68);
69
70$item = $formSetup->newItem('AI_API_SERVICE'); // Name of constant must end with _KEY so it is encrypted when saved into database.
71$item->setAsSelect($arrayofia);
72$item->cssClass = 'minwidth150';
73
74foreach ($arrayofia as $ia => $ialabel) {
75 // Setup conf AI_PUBLIC_INTERFACE_TOPIC
76 /*$item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_ENDPOINT'); // Name of constant must end with _KEY so it is encrypted when saved into database.
77 $item->defaultFieldValue = '';
78 $item->cssClass = 'minwidth500';*/
79
80 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_KEY')->setAsSecureKey(); // Name of constant must end with _KEY so it is encrypted when saved into database.
81 $item->nameText = $langs->trans("AI_API_KEY").' ('.$ialabel.')';
82 $item->defaultFieldValue = '';
83 $item->fieldParams['hideGenerateButton'] = 1;
84 $item->fieldParams['trClass'] = $ia;
85 $item->cssClass = 'minwidth500 text-security';
86
87 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_URL'); // Name of constant must end with _KEY so it is encrypted when saved into database.
88 $item->nameText = $langs->trans("AI_API_URL").' ('.$ialabel.')';
89 $item->defaultFieldValue = '';
90 $item->fieldParams['trClass'] = $ia;
91 $item->cssClass = 'minwidth500';
92}
93
94$setupnotempty = + count($formSetup->items);
95
96
97$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
98
99// Access control
100if (!$user->admin) {
102}
103if (!isModEnabled('ai')) {
104 accessforbidden('Module AI not activated.');
105}
106
107
108/*
109 * Actions
110 */
111
112include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
113
114$action = 'edit';
115
116
117/*
118 * View
119 */
120
121$form = new Form($db);
122
123$help_url = '';
124$title = "AiSetup";
125
126llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-ai page-admin');
127
128// Subheader
129$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
130
131print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
132
133// Configuration header
134$head = aiAdminPrepareHead();
135print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "fa-microchip");
136
137
138if ($action == 'edit') {
139 print $formSetup->generateOutput(true);
140 print '<br>';
141} elseif (!empty($formSetup->items)) {
142 print $formSetup->generateOutput();
143 print '<div class="tabsAction">';
144 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
145 print '</div>';
146} else {
147 print '<br>'.$langs->trans("NothingToSetup");
148}
149
150
151if (empty($setupnotempty)) {
152 print '<br>'.$langs->trans("NothingToSetup");
153}
154
155// Page end
156print dol_get_fiche_end();
157
158llxFooter();
159$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:70
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.