Skip to content

Commit

Permalink
Merge branch 'develop' into fix/phpdoc1
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy authored Mar 12, 2024
2 parents eefe123 + 0b936be commit 949c885
Show file tree
Hide file tree
Showing 108 changed files with 393 additions and 588 deletions.
3 changes: 1 addition & 2 deletions dev/tools/github_commits_byversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# shellcheck disable=1113,2002,2006,2086,2164,2219

Releases=("3.9" "4.0" "5.0" "6.0" "7.0" "8.0" "9.0" "10.0" "11.0" "12.0" "13.0" "14.0" "15.0" "16.0" "17.0" "18.0" "develop")
Releases=("3.9" "4.0" "5.0" "6.0" "7.0" "8.0" "9.0" "10.0" "11.0" "12.0" "13.0" "14.0" "15.0" "16.0" "17.0" "18.0" "19.0" "develop")
let "counter = 0"

echo "Copy script into /tmp/github_commits_byversion.sh"
Expand Down Expand Up @@ -49,4 +49,3 @@ do
echo
let "counter +=1"
done

5 changes: 3 additions & 2 deletions dev/tools/phan/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*/
define('DOL_PROJECT_ROOT', __DIR__.'/../../..');
define('DOL_DOCUMENT_ROOT', DOL_PROJECT_ROOT.'/htdocs');
Expand Down Expand Up @@ -535,7 +536,8 @@
// 'PhanTypeInvalidThrowsIsInterface',
// 'PhanPluginRedundantAssignmentInLoop',
// 'PhanInvalidCommentForDeclarationType',
//'PhanParamSignatureMismatchInternal',
// 'PhanParamSignatureMismatchInternal',
// 'PhanParamSignatureMismatch',
// 'PhanPluginEmptyStatementForeachLoop',
// 'PhanCompatibleDimAlternativeSyntax',
'PhanInvalidFQSENInClasslike',
Expand Down Expand Up @@ -656,5 +658,4 @@
'sockets' => PHAN_DIR . '/stubs/sockets.phan_php',
'zip' => PHAN_DIR . '/stubs/zip.phan_php',
],

];
5 changes: 3 additions & 2 deletions dev/tools/phan/config_fixer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
/* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*/

// Uncomment require_once to enable corresponding fixer

Expand All @@ -7,8 +10,6 @@
//require_once __DIR__.'/plugins/UrlEncodeStringifyFixer.php';
require_once __DIR__.'/plugins/SelectDateFixer.php';

/* Copyright (C) 2024 MDW <[email protected]>
*/
define('DOL_PROJECT_ROOT', __DIR__.'/../../..');
define('DOL_DOCUMENT_ROOT', DOL_PROJECT_ROOT.'/htdocs');
define('PHAN_DIR', __DIR__);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/adherents/class/adherent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public function sendEmail($text, $subject, $filename_list = array(), $mimetype_l
*/
public function makeSubstitution($text)
{
global $conf, $langs;
global $langs;

$birthday = dol_print_date($this->birth, 'day');

Expand Down
10 changes: 5 additions & 5 deletions htdocs/admin/mails.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ function initfields()
jQuery("#MAIN_MAIL_SMTP_SERVER").show();
jQuery("#MAIN_MAIL_SMTP_PORT").show();
jQuery("#smtp_server_mess").hide();
jQuery("#smtp_port_mess").hide();
jQuery("#smtp_port_mess").hide();
jQuery(".smtp_method").show();
jQuery(".dkim").hide();
jQuery(".dkim").hide();
jQuery(".smtp_auth_method").show();
}
if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
Expand All @@ -302,9 +302,9 @@ function initfields()
jQuery("#MAIN_MAIL_SMTP_PORT").show();
jQuery("#smtp_server_mess").hide();
jQuery("#smtp_port_mess").hide();
jQuery(".smtp_method").show();
jQuery(".smtp_method").show();
jQuery(".dkim").show();
jQuery(".smtp_auth_method").show();
jQuery(".smtp_auth_method").show();
}
}
function change_smtp_auth_method() {
Expand Down Expand Up @@ -1109,7 +1109,7 @@ function change_smtp_auth_method() {
$formmail->withtopicreadonly = 0;
$formmail->withfile = 2;
$formmail->withlayout = 1;
$formmail->withaiprompt = 1;
$formmail->withaiprompt = ($action == 'testhtml' ? 'html' : 'text');
$formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
$formmail->withbodyreadonly = 0;
$formmail->withcancel = 1;
Expand Down
7 changes: 4 additions & 3 deletions htdocs/ai/ajax/generate_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
}
$ai = new Ai($db);

$instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8');
$function = 'textgeneration';
$instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8');
$format = empty($jsonData['instructions']) ? '' : $jsonData['instructions'];

$generatedContent = $ai->generateContent($instructions, 'auto', $function);
$generatedContent = $ai->generateContent($instructions, 'auto', $function, $format);

if (is_array($generatedContent) && $generatedContent['error']) {
print "Error : " . $generatedContent['message'];
print "Error returned by API call: " . $generatedContent['message'];
} else {
print $generatedContent;
}
27 changes: 17 additions & 10 deletions htdocs/ai/class/ai.class.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php
/* Copyright (C) 2008-2011 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2016 Regis Houssin <[email protected]>
* Copyright (C) 2012 J. Fernando Lagrange <[email protected]>
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]>
* Copyright (C) 2023 Eric Seigne <[email protected]>
/* Copyright (C) 2024 Laurent Destailleur <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,7 +22,6 @@
*/
class Ai
{

/**
* @var DoliDB $db Database object
*/
Expand Down Expand Up @@ -57,13 +52,18 @@ public function __construct($db)
/**
* Generate response of instructions
*
* @param string $instructions instruction for generate content
* @param string $model model name ('gpt-3.5-turbo')
* @param string $function code of the feature we want to use ('emailing', 'transcription', 'audiotext', 'imagegeneration', 'translation')
* @param string $instructions Instruction to generate content
* @param string $model Model name ('gpt-3.5-turbo', 'gpt-4-turbo', 'dall-e-3', ...)
* @param string $function Code of the feature we want to use ('textgeneration', 'transcription', 'audiotext', 'imagegeneration', 'translation')
* @param string $format Format for output ('', 'html', ...)
* @return mixed $response
*/
public function generateContent($instructions, $model = 'auto', $function = 'textgeneration')
public function generateContent($instructions, $model = 'auto', $function = 'textgeneration', $format = '')
{
if (empty($this->apiKey)) {
return array('error' => true, 'message' => 'API key is no defined');
}

if (empty($this->apiEndpoint)) {
if ($function == 'textgeneration') {
$this->apiEndpoint = 'https://api.openai.com/v1/chat/completions';
Expand Down Expand Up @@ -97,6 +97,8 @@ public function generateContent($instructions, $model = 'auto', $function = 'tex
}
}

dol_syslog("Call API for apiEndpoint=".$this->apiEndpoint." apiKey=".substr($this->apiKey, 0, 3).'***********, model='.$model);

try {
$configurationsJson = getDolGlobalString('AI_CONFIGURATIONS_PROMPT');
$configurations = json_decode($configurationsJson, true);
Expand Down Expand Up @@ -144,6 +146,11 @@ public function generateContent($instructions, $model = 'auto', $function = 'tex
// Extraction content
$generatedEmailContent = $decodedResponse['choices'][0]['message']['content'];

// If content is not HTML, we convert it into HTML
if (!dol_textishtml($generatedEmailContent)) {
$generatedEmailContent = dol_nl2br($generatedEmailContent);
}

return $generatedEmailContent;
} catch (Exception $e) {
return array('error' => true, 'message' => $e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions htdocs/comm/mailing/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@

$formmail = new FormMail($db);
$formmail->withfckeditor = 1;
$formmail->withaiprompt = 1;
$formmail->withaiprompt = 'html';
$formmail->withlayout = 1;

print '<tr class="fieldsforemail"><td></td><td>';
Expand Down Expand Up @@ -1252,7 +1252,7 @@
$formmail->withtopicreadonly = 1;
$formmail->withfile = 0;
$formmail->withlayout = 0;
$formmail->withaiprompt = 0;
$formmail->withaiprompt = '';
$formmail->withbody = 0;
$formmail->withbodyreadonly = 1;
$formmail->withcancel = 1;
Expand Down
5 changes: 3 additions & 2 deletions htdocs/comm/remx.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2019 Laurent Destailleur <[email protected]>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <[email protected]>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,6 +45,7 @@

// Security check
$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
/** @var User $user */
if ($user->socid > 0) {
$socid = $user->socid;
}
Expand All @@ -55,7 +56,7 @@
}
$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);

$permissiontocreate = ($user->rights->societe->creer || $user->rights->facture->creer);
$permissiontocreate = ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer'));



Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/commonnumrefgenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function info($langs)
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @param CommonObject $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
Expand Down
6 changes: 5 additions & 1 deletion htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8006,7 +8006,11 @@ public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix
if (!empty($value)) {
$checked = ' checked ';
}
$value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>';
if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
$value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>';
} else {
$value = yn($value ? 1 : 0);
}
} elseif ($type == 'mail' || $type == 'email') {
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
} elseif ($type == 'url') {
Expand Down
9 changes: 7 additions & 2 deletions htdocs/core/class/conf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ class Conf extends stdClass
*/
public $db;

//! To store properties found into database
/**
* @var Object To store global setup found into database
*/
public $global;
//! To store browser info (->name, ->os, ->version, ->ua, ->layout, ...)

/**
* @var Object To store browser info (->name, ->os, ->version, ->ua, ->layout, ...)
*/
public $browser;

//! To store some setup of generic modules
Expand Down
7 changes: 5 additions & 2 deletions htdocs/core/class/extrafields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,6 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $
} else {
$checked = ' value="1" ';
}

$out = '<input type="checkbox" class="flat valignmiddle'.($morecss ? ' '.$morecss : '').' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>';
} else {
$out = $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1, false, 1);
Expand Down Expand Up @@ -1691,7 +1690,11 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec
if (!empty($value)) {
$checked = ' checked ';
}
$value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>';
if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
$value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>';
} else {
$value = yn($value ? 1 : 0);
}
} elseif ($type == 'mail') {
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
} elseif ($type == 'ip') {
Expand Down
8 changes: 4 additions & 4 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9681,8 +9681,8 @@ public function showrefnav($object, $paramid, $morehtml = '', $shownav = 1, $fie
$stringforfirstkey .= ' CTL +';
}

$previous_ref = $object->ref_previous ? '<a accesskey="p" title="' . $stringforfirstkey . ' p" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_previous) . $moreparam . '"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
$next_ref = $object->ref_next ? '<a accesskey="n" title="' . $stringforfirstkey . ' n" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_next) . $moreparam . '"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
$previous_ref = $object->ref_previous ? '<a accesskey="p" alt="'.dol_escape_htmltag($langs->trans("Previous")).'" title="' . $stringforfirstkey . ' p" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_previous) . $moreparam . '"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
$next_ref = $object->ref_next ? '<a accesskey="n" alt="'.dol_escape_htmltag($langs->trans("Next")).'" title="' . $stringforfirstkey . ' n" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_next) . $moreparam . '"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';
}

//print "xx".$previous_ref."x".$next_ref;
Expand All @@ -9696,8 +9696,8 @@ public function showrefnav($object, $paramid, $morehtml = '', $shownav = 1, $fie
if ($previous_ref || $next_ref || $morehtml) {
$ret .= '<div class="pagination paginationref"><ul class="right">';
}
if ($morehtml) {
$ret .= '<li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ? ' clearbothonsmartphone' : '') . '">' . $morehtml . '</li>';
if ($morehtml && getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') < 2) {
$ret .= '<!-- morehtml --><li class="noborder litext' . (($shownav && $previous_ref && $next_ref) ? ' clearbothonsmartphone' : '') . '">' . $morehtml . '</li>';
}
if ($shownav && ($previous_ref || $next_ref)) {
$ret .= '<li class="pagination">' . $previous_ref . '</li>';
Expand Down
24 changes: 13 additions & 11 deletions htdocs/core/class/html.formmail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ class FormMail extends Form
public $withfile;

/**
* @var int 1=Add a button "Fill with layout"
* @var int 1=Add a button "Fill with layout"
*/
public $withlayout;

/**
* @var int 1=Add a button "Fill with AI generation"
* @var string 'text' or 'html' to add a button "Fill with AI generation"
*/
public $withaiprompt;

Expand Down Expand Up @@ -1051,7 +1051,7 @@ public function get_form($addfileaction = 'addfile', $removefileaction = 'remove
$out .= $this->getModelEmailTemplate();
}
if ($this->withaiprompt && isModEnabled('ai')) {
$out .= $this->getSectionForAIPrompt();
$out .= $this->getSectionForAIPrompt($this->withaiprompt);
}
$out .= '</td>';
$out .= '</tr>';
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public function getHtmlForDeliveryreceipt()
}

/**
* get Html For Topic of message
* Return Html section for the Topic of message
*
* @param array $arraydefaultmessage Array with message template content
* @param string $helpforsubstitution Help string for substitution
Expand Down Expand Up @@ -1437,11 +1437,12 @@ public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
}

/**
* Return Html code for AI instruction of message
* Return Html code for AI instruction of message and autofill result
*
* @return string Text for instructions
* @param string $format Format for output ('', 'html', ...)
* @return string HTML code to ask AI instruction and autofill result
*/
public function getSectionForAIPrompt()
public function getSectionForAIPrompt($format = '')
{
global $langs;

Expand All @@ -1455,7 +1456,6 @@ public function getSectionForAIPrompt()
$out .= '<input id="generate_button" type="button" class="button smallpaddingimp" value="'.$langs->trans('Generate').'"/>';
$out .= "</td></tr>\n";


$out .= "<script type='text/javascript'>
$(document).ready(function() {
// for keydown
Expand All @@ -1468,16 +1468,18 @@ public function getSectionForAIPrompt()
$('#generate_button').click(function() {
var instructions = $('#ai_instructions').val();
//editor on readonly
if (CKEDITOR.instances.message) {
CKEDITOR.instances.message.setReadOnly(1);
}
$.ajax({
url: '". DOL_URL_ROOT."/ai/ajax/generate_content.php?token=".newToken()."',
url: '". DOL_URL_ROOT."/ai/ajax/generate_content.php?token=".currentToken()."',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'format': '".dol_escape_js($format)."',
'instructions': instructions,
}),
success: function(response) {
Expand Down Expand Up @@ -1810,7 +1812,7 @@ public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $acti
*/
public function setSubstitFromObject($object, $outputlangs)
{
global $conf, $user, $extrafields;
global $extrafields;

$parameters = array();
$tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
Expand Down Expand Up @@ -1867,7 +1869,7 @@ public function setSubstitFromObject($object, $outputlangs)
*/
public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
{
global $conf, $langs;
global $langs;

$tmparray = array();
if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
Expand Down
Loading

0 comments on commit 949c885

Please sign in to comment.