31require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
40require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
41require_once DOL_DOCUMENT_ROOT.
"/ai/lib/ai.lib.php";
43$langs->loadLangs(array(
"admin",
"website",
"other"));
47$action =
GETPOST(
'action',
'aZ09');
48$backtopage =
GETPOST(
'backtopage',
'alpha');
49$modulepart =
GETPOST(
'modulepart',
'aZ09');
64if (!class_exists(
'FormSetup')) {
65 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
77$item = $formSetup->newItem(
'AI_API_SERVICE');
78$item->setAsSelect($arrayofai);
79$item->cssClass =
'minwidth150';
82foreach ($arrayofai as $ia => $iarecord) {
86 $ialabel = $iarecord[
'label'];
93 $item = $formSetup->newItem(
'AI_API_'.strtoupper($ia).
'_KEY')->setAsSecureKey();
94 $item->nameText = $langs->trans(
"AI_API_KEY").
' ('.$ialabel.
')';
95 $item->defaultFieldValue =
'';
96 $item->fieldParams[
'hideGenerateButton'] = 1;
97 $item->fieldParams[
'trClass'] =
'iaservice '.$ia;
98 $item->cssClass =
'minwidth500 text-security input'.$ia;
99 $item->helpText =
'<span class="helptoshow">HelpToShow</span>';
102 $item = $formSetup->newItem(
'AI_API_'.strtoupper($ia).
'_URL');
103 $item->nameText = $langs->trans(
"AI_API_URL").
' ('.$ialabel.
')';
104 $item->defaultFieldValue = $iarecord[
'url'];
105 $item->fieldParams[
'trClass'] =
'iaservice iaurl '.$ia;
106 $item->cssClass =
'minwidth500 input'.$ia;
107 if ($ia ==
'custom') {
108 $item->fieldAttr[
'placeholder'] =
'https://domainofapi.com/v1/';
112$setupnotempty = + count($formSetup->items);
115$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
134include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
146llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-ai page-admin');
149$linkback =
'<a href="'.($backtopage ? $backtopage :
dolBuildUrl(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>';
158if ($action ==
'edit') {
159 print $formSetup->generateOutput(
true);
160} elseif (!empty($formSetup->items)) {
161 print $formSetup->generateOutput();
162 print
'<div class="tabsAction">';
163 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'">'.$langs->trans(
"Modify").
'</a>';
166 print
'<br>'.$langs->trans(
"NothingToSetup");
170if (empty($setupnotempty)) {
171 print
'<br>'.$langs->trans(
"NothingToSetup");
174print
'<script type="text/javascript">
175 jQuery(document).ready(function() {
176 function showHideAIService(aiservice) {
177 console.log("showHideAIService: We select the AI service "+aiservice);
178 jQuery(".iaservice").hide();
180 if (aiservice != "-1") {
181 jQuery(".iaservice."+aiservice).show();
182 const arrayofia = {';
184foreach ($arrayofai as $key => $airecord) {
195 const arrayofextlink = {';
197foreach ($arrayofai as $key => $airecord) {
208 console.log("Check URL for .iaurl."+aiservice+" .input"+aiservice);
209 if (jQuery(".iaurl."+aiservice+" .input"+aiservice).val() == \'\') {
210 console.log("URL is empty, we fill with default value of IA selected");
211 jQuery(".iaurl."+aiservice+" .input"+aiservice).val(arrayofia[aiservice]);
213 jQuery(".helptoshow").text(arrayofextlink[aiservice]);
217 jQuery("#AI_API_SERVICE").change(function() {
218 var aiservice = $(this).val();
220 showHideAIService(aiservice);
222 jQuery(".sectiontest").hide(); /* Hide test section, will appear after the save */
225 showHideAIService("'.getDolGlobalString(
"AI_API_SERVICE").
'");
236 print
'<br><div class="sectiontest">';
239 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
240 print
'<input type="hidden" name="token" value="'.newToken().
'">';
241 print
'<input type="hidden" name="action" value="add">';
242 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
245 $key =
'textgenerationother';
252 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
253 include_once DOL_DOCUMENT_ROOT.
"/core/class/html.formai.class.php";
257 $showlinktoai = $key;
258 $showlinktoailabel = $langs->trans(
"AITestText");
259 $showlinktolayout = 0;
261 $formmail->withaiprompt =
'';
265 $out = $langs->trans(
"Test").
': ';
266 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
271 print
' <span class="small opacitymedium">'.$langs->trans(
"DebugOnInFile",
'dolibarr_ai.log').
'</span>';
273 print
' <span class="small opacitymedium">'.$langs->trans(
"DebugOff",
'dolibarr_ai.log').
'</span>';
276 print
'<br><textarea id="'.$htmlname.
'" placeholder="Click on picto to enter a prompt or enter a message and click picto to make text transformation..." class="quatrevingtpercent" rows="4"></textarea>';
281 $showlinktoai .=
'html';
283 $formmail->withaiprompt =
'html';
286 $out = $langs->trans(
"Test").
': ';
287 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
292 print
' <span class="small opacitymedium">'.$langs->trans(
"DebugOnInFile",
'dolibarr_ai.log').
'</span>';
294 print
' <span class="small opacitymedium">'.$langs->trans(
"DebugOff",
'dolibarr_ai.log').
'</span>';
298 $doleditor =
new DolEditor($htmlname,
'',
'', 150,
'dolibarr_details');
299 print $doleditor->Create(1);
getListOfAIFeatures()
Prepare admin pages header.
aiAdminPrepareHead()
Prepare admin pages header.
getListOfAIServices()
Get list of available ai services.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
Class to manage a WYSIWYG editor.
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.