27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
29require_once
'../lib/ai.lib.php';
31$langs->loadLangs(array(
"admin",
"website",
"other"));
34$action =
GETPOST(
'action',
'aZ09');
35$backtopage =
GETPOST(
'backtopage',
'alpha');
36$modulepart =
GETPOST(
'modulepart',
'aZ09');
54if (!class_exists(
'FormSetup')) {
55 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
61$item = $formSetup->newItem(
'AI_CONFIGURATIONS_PROMPT');
62$item->defaultFieldValue =
'';
64$setupnotempty += count($formSetup->items);
66$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
69$arrayofaifeatures = array(
70 'textgenerationemail' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"EmailContent").
')',
'picto'=>
'',
'status'=>
'development'),
71 'textgenerationwebpage' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"WebsitePage").
')',
'picto'=>
'',
'status'=>
'development'),
72 'textgeneration' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"Other").
')',
'picto'=>
'',
'status'=>
'notused'),
73 'imagegeneration' => array(
'label' =>
'ImageGeneration',
'picto'=>
'',
'status'=>
'notused'),
74 'videogeneration' => array(
'label' =>
'VideoGeneration',
'picto'=>
'',
'status'=>
'notused'),
75 'transcription' => array(
'label' =>
'Transcription',
'picto'=>
'',
'status'=>
'notused'),
76 'translation' => array(
'label' =>
'Translation',
'picto'=>
'',
'status'=>
'notused'),
77 'audiotext' => array(
'label' =>
'AudioText',
'picto'=>
'',
'status'=>
'notused')
85$functioncode =
GETPOST(
'functioncode',
'alpha');
86$pre_prompt =
GETPOST(
'prePrompt');
87$post_prompt =
GETPOST(
'postPrompt');
91$currentConfigurations = json_decode($currentConfigurationsJson,
true);
93if ($action ==
'update' &&
GETPOST(
'cancel')) {
96if ($action ==
'update' && !
GETPOST(
'cancel')) {
98 if (empty($functioncode)) {
102 if (!is_array($currentConfigurations)) {
103 $currentConfigurations = [];
106 if (empty($functioncode) || (empty($pre_prompt) && empty($post_prompt))) {
107 if (isset($currentConfigurations[$functioncode])) {
108 unset($currentConfigurations[$functioncode]);
111 $currentConfigurations[$functioncode] = [
112 'prePrompt' => $pre_prompt,
113 'postPrompt' => $post_prompt,
117 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
118 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
121 header(
"Location: ".$_SERVER[
'PHP_SELF']);
132if ($action ==
'updatePrompts') {
133 $key =
GETPOST(
'key',
'alpha');
135 $currentConfigurations[$key] = [
136 'prePrompt' => $pre_prompt,
137 'postPrompt' => $post_prompt,
140 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
141 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
145 header(
"Location: ".$_SERVER[
'PHP_SELF']);
154if ($action ==
'confirm_deleteproperty' &&
GETPOST(
'confirm') ==
'yes') {
155 $key =
GETPOST(
'key',
'alpha');
157 if (isset($currentConfigurations[$key])) {
158 unset($currentConfigurations[$key]);
160 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
161 $res =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
163 header(
"Location: ".$_SERVER[
'PHP_SELF']);
177$form =
new Form($db);
182llxHeader(
'', $langs->trans($title), $help_url);
185$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
196print
load_fiche_titre($langs->trans(
"AIPromptForFeatures"), $newbutton,
'');
198if ($action ==
'deleteproperty') {
199 $formconfirm = $form->formconfirm(
200 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
201 $langs->trans(
'Delete'),
202 $langs->trans(
'ConfirmDeleteSetup',
GETPOST(
'key',
'alpha')),
203 'confirm_deleteproperty',
211if ($action ==
'edit' || $action ==
'deleteproperty') {
212 $out =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
213 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
214 $out .=
'<input type="hidden" name="action" value="update">';
217 $out .=
'<table class="noborder centpercent">';
219 $out .=
'<tr class="liste_titre">';
220 $out .=
'<td>'.$langs->trans(
'Add').
'</td>';
225 $out .=
'<tr class="oddeven">';
226 $out .=
'<td class="col-setup-title">';
227 $out .=
'<span id="module" class="spanforparamtooltip">'.$langs->trans(
"Feature").
'</span>';
231 $out .=
'<select name="functioncode" id="functioncode" class="flat minwidth500">';
232 $out .=
'<option> </option>';
233 foreach ($arrayofaifeatures as $key => $val) {
234 $labelhtml = $langs->trans($arrayofaifeatures[$key][
'label']).($arrayofaifeatures[$key][
'status'] ==
'notused' ?
' <span class="opacitymedium">('.$langs->trans(
"NotYetAvailable").
')</span>' :
"");
235 $labeltext = $langs->trans($arrayofaifeatures[$key][
'label']);
256 $out .=
'<tr class="oddeven">';
257 $out .=
'<td class="col-setup-title">';
258 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
261 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput" name="prePrompt" rows="3"></textarea>';
264 $out .=
'<tr class="oddeven">';
265 $out .=
'<td class="col-setup-title">';
266 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
269 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput" name="postPrompt" rows="3"></textarea>';
275 $out .= $form->buttonsSaveCancel(
"Add",
"");
277 $out .=
'<br><br><br>';
283if ($action ==
'edit' || $action ==
'create' || $action ==
'deleteproperty') {
286 if (!empty($currentConfigurations)) {
287 $out =
'<table class="noborder centpercent">';
288 foreach ($currentConfigurations as $key => $config) {
289 if (!empty($key) && !preg_match(
'/^[a-z]+$/i', $key)) {
294 $out .=
'<tr class="liste_titre">';
295 $out .=
'<td>'.$arrayofaifeatures[$key][
'picto'].
' '.$langs->trans($arrayofaifeatures[$key][
'label']);
297 $out .=
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deleteproperty&token='.
newToken().
'&key='.urlencode($key).
'">'.
img_delete().
'</a>';
304 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
305 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
306 $out .=
'<input type="hidden" name="key" value="'.$key.
'" />';
307 $out .=
'<input type="hidden" name="action" value="updatePrompts">';
308 $out .=
'<tr class="oddeven">';
309 $out .=
'<td class="col-setup-title">';
310 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
313 $out .=
'<textarea class="flat minwidth500" id="prePromptInput_'.$key.
'" name="prePrompt" rows="2" disabled>'.$config[
'prePrompt'].
'</textarea>';
316 $out .=
'<tr class="oddeven">';
317 $out .=
'<td class="col-setup-title">';
318 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
321 $out .=
'<textarea class="flat minwidth500" id="postPromptInput_'.$key.
'" name="postPrompt" rows="2" disabled>'.$config[
'postPrompt'].
'</textarea>';
322 $out .=
'<br><input type="submit" class="button small submitBtn" name="modify" data-index="'.$key.
'" style="display: none;" value="'.
dol_escape_htmltag($langs->trans(
"Modify")).
'"/>';
334 var configurations = ".$currentConfigurationsJson.
";
335 $(document).ready(function() {
336 $('#module_select').change(function() {
337 var selectedModule = $(this).val();
338 var moduleConfig = configurations[selectedModule];
341 $('#prePromptInput').val(moduleConfig.prePrompt || '');
342 $('#postPromptInput').val(moduleConfig.postPrompt || '');
344 $('#prePromptInput').val('');
345 $('#postPromptInput').val('');
349 $('.showInputBtn').click(function() {
350 event.preventDefault();
351 var index = $(this).data('index');
352 var state = $(this).data('state');
354 if(state === 'edit') {
355 $('#prePromptInput_'+index).removeAttr('disabled').focus();
356 $('#postPromptInput_'+index).removeAttr('disabled');
357 $('.submitBtn[data-index=' + index + ']').show();
358 $(this).html($(this).data('icon-cancel'));
359 $(this).data('state', 'cancel');
363 $('#prePromptInput_'+index).attr('disabled', 'disabled');
364 $('#postPromptInput_'+index).attr('disabled', 'disabled');
365 $('.submitBtn[data-index=' + index + ']').hide();
366 $(this).html($(this).data('icon-edit'));
367 $(this).data('state', 'edit');
380if (empty($setupnotempty)) {
381 print
'<br>'.$langs->trans(
"NothingToSetup");
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
aiAdminPrepareHead()
Prepare admin pages header.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
img_view($titlealt='default', $float=0, $other='class="valignmiddle"')
Show logo view 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.