dolibarr 23.0.3
server_mcp.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 DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
32require_once DOL_DOCUMENT_ROOT."/ai/lib/ai.lib.php";
33
42$langs->loadLangs(array("admin", "website", "other"));
43
44
45// Parameters
46$action = GETPOST('action', 'aZ09');
47$backtopage = GETPOST('backtopage', 'alpha');
48$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
49
50if (empty($action)) {
51 $action = 'edit';
52}
53
54$content = GETPOST('content');
55
56$error = 0;
57$setupnotempty = 0;
58
59
60// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
61$useFormSetup = 1;
62
63if (!class_exists('FormSetup')) {
64 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
65}
66
67$formSetup = new FormSetup($db);
68
69// List all available IA
70$arrayofai = getListOfAIServices();
71
72// List all available features
73$arrayofaifeatures = getListOfAIFeatures();
74
75$item = $formSetup->newItem('AI_API_SERVICE'); // Name of constant must end with _KEY so it is encrypted when saved into database.
76$item->setAsSelect($arrayofai);
77$item->cssClass = 'minwidth150';
78
79foreach ($arrayofai as $ia => $iarecord) {
80 $ialabel = $iarecord['label'];
81 // Setup conf AI_PUBLIC_INTERFACE_TOPIC
82 /*$item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_ENDPOINT'); // Name of constant must end with _KEY so it is encrypted when saved into database.
83 $item->defaultFieldValue = '';
84 $item->cssClass = 'minwidth500';*/
85
86 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_KEY')->setAsSecureKey(); // Name of constant must end with _KEY so it is encrypted when saved into database.
87 $item->nameText = $langs->trans("AI_API_KEY").' ('.$ialabel.')';
88 $item->defaultFieldValue = '';
89 $item->fieldParams['hideGenerateButton'] = 1;
90 $item->fieldParams['trClass'] = 'iaservice '.$ia;
91 $item->cssClass = 'minwidth500 text-security input'.$ia;
92
93 $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_URL'); // Name of constant must end with _KEY so it is encrypted when saved into database.
94 $item->nameText = $langs->trans("AI_API_URL").' ('.$ialabel.')';
95 $item->defaultFieldValue = '';
96 $item->fieldParams['trClass'] = 'iaservice iaurl '.$ia;
97 $item->cssClass = 'minwidth500 input'.$ia;
98 if ($ia == 'custom') {
99 $item->fieldAttr['placeholder'] = 'https://domainofapi.com/v1/';
100 }
101}
102
103$setupnotempty = + count($formSetup->items);
104
105
106$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
107
108// Access control
109if (!$user->admin) {
111}
112if (!isModEnabled('ai')) {
113 accessforbidden('Module AI not activated.');
114}
115
116
117/*
118 * Actions
119 */
120
121include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
122
123$action = 'edit';
124
125
126/*
127 * View
128 */
129
130$help_url = '';
131$title = "AiSetup";
132
133llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-ai page-admin');
134
135// Subheader
136$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
137
138print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
139
140// Configuration header
141$head = aiAdminPrepareHead();
142print dol_get_fiche_head($head, 'servermcp', $langs->trans($title), -1, "ai");
143
144print 'There is no MCP server available yet.';
145
146llxFooter();
147$db->close();
getListOfAIFeatures()
Prepare admin pages header.
Definition ai.lib.php:34
aiAdminPrepareHead()
Prepare admin pages header.
Definition ai.lib.php:167
getListOfAIServices()
Get list of available ai services.
Definition ai.lib.php:64
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
This class help you create setup render.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.