dolibarr 25.0.0-alpha
formlayoutai.tpl.php
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
41//Protection to avoid direct call of template
42if (empty($conf) || !is_object($conf)) {
43 print "Error, template page can't be called as URL";
44 exit(1);
45}
46
47if (empty($langs)) {
48 print 'Parameter langs not defined.';
49 exit(1);
50}
51if (empty($htmlname)) {
52 print 'Parameter htmlname not defined.';
53 exit(1);
54}
55
56'
57@phan-var-force ?FormWebSite $formwebsite
58@phan-var-force ?FormMail $formmail
59@phan-var-force ?FormAI $formai
60@phan-var-force string $showlinktolayout
61@phan-var-force string $showlinktolayoutlabel
62@phan-var-force string $showlinktoai
63@phan-var-force string $showlinktoailabel
64@phan-var-force ?string $out
65@phan-var-force ?string $morecss
66@phan-var-force string $aiprompt
67';
68
69if (!isset($out)) { // Init to empty string if not defined
70 $out = '';
71}
72if (!isset($morecss)) { // Init to empty string if not defined
73 $morecss = '';
74}
75if (!isset($aiprompt)) { // Init to empty string if not defined
76 $aiprompt = '';
77}
78
79$out .= '<!-- BEGIN PHP TEMPLATE htdocs/core/tpl/formlayoutai.tpl.php -->'."\n";
80
81// Add link to add layout
82if (!empty($showlinktolayout)) { // May be set only if MAIN_EMAIL_USE_LAYOUT is set
83 $out .= '<a href="#" id="linkforlayouttemplates" class="notasortlink inline-block alink marginrightonly">';
84 $out .= img_picto($showlinktolayoutlabel, 'layout', 'class="paddingrightonly"');
85 $out .= '<span class="hideobject hideonsmartphone">'.$showlinktolayoutlabel.'...</span>';
86 $out .= '</a> &nbsp; &nbsp; ';
87
88 $out .= '<script>
89 $(document).ready(function() {
90 $("#linkforlayouttemplates").click(function() {
91 console.log("We click on linkforlayouttemplates, we toggle .template-selector");
92 event.preventDefault();
93 jQuery(".template-selector").toggle();
94 jQuery(".ai_input'.$htmlname.'").hide();
95 jQuery("#pageContent").show(); // May exists for website page only
96 });
97 jQuery(document).on("click", function (event) {
98 templateselector = jQuery(".template-selector");
99 templateselectorbutton = jQuery("#linkforlayouttemplates");
100 if (!templateselector.is(event.target) && !templateselectorbutton.is(event.target) && jQuery(event.target).closest(templateselector).length === 0 && jQuery(event.target).closest(templateselectorbutton).length === 0 && templateselector.is(":visible")) {
101 console.log("You clicked outside of template-selector - we close it");
102 jQuery(".template-selector").hide();
103 }
104 });
105 });
106 </script>
107 ';
108}
109// Add link to add AI content
110if (!empty($showlinktoai)) {
111 // TODO Diff between showlinktoai and htmlname ? Why not using one key only ?
112 $out .= '<a href="#" id="linkforaiprompt'.$showlinktoai.'" class="notasortlink inline-block alink '.$morecss.'">';
113 $out .= img_picto($showlinktoailabel, 'ai', 'class="paddingrightonly"');
114 $out .= '<span class="hideobject hideonsmartphone">'.$showlinktoailabel.'...</span>';
115 $out .= '</a>';
116
117 $out .= '<script>
118 $(document).ready(function() {
119 $("#linkforaiprompt'.$showlinktoai.'").click(function() {
120 console.log("formlayoutai.tpl: We click on linkforaiprompt'.$showlinktoai.', we toggle .ai_input'.$showlinktoai.'");
121 event.preventDefault();
122 jQuery(".ai_dropdown'.$htmlname.'").toggle();
123 jQuery(".template-selector").hide();
124 jQuery(".email-layout-container").hide();
125 if (!jQuery("#ai_dropdown'.$htmlname.'").is(":hidden")) {
126 console.log("Set focus on input field #ai_instructions'.$htmlname.'");
127 jQuery("#ai_instructions'.$htmlname.'").focus();
128 if (!jQuery("pageContent").is(":hidden")) { // May exists for website page only
129 jQuery("#pageContent").show();
130 }
131 }
132 });
133 $(document).on("click", function (event) {
134 aidropdown = $(".ai_dropdown'.$htmlname.'");
135 aidropdownbutton = $("#linkforaiprompt'.$showlinktoai.'");
136 if (!aidropdown.is(event.target) && !aidropdownbutton.is(event.target) && $(event.target).closest(aidropdown).length === 0 && $(event.target).closest(aidropdownbutton).length === 0 && aidropdown.is(":visible")) {
137 console.log("You clicked outside of ai_dropdown - we close it");
138 $(".ai_dropdown'.$htmlname.'").hide();
139 }
140 });
141 });
142 </script>
143 ';
144}
145
146if (!empty($showlinktolayout)) {
147 if (!empty($formwebsite) && is_object($formwebsite)) {
148 $out .= $formwebsite->getContentPageTemplate($htmlname);
149 } else {
150 if (!is_object($formmail)) {
151 // Create form object
152 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
153 $formmail = new FormMail($db);
154 }
155 $out .= $formmail->getEmailLayoutSelector($htmlname, $showlinktolayout);
156 }
157} else {
158 $out .= '<!-- No link to the layout feature, $formmail->withlayout must be set to a string use case, module WYSIWYG must be enabled and MAIN_EMAIL_USE_LAYOUT must be set -->';
159}
160
163if (!empty($showlinktoai)) {
164 if (empty($formai) || $formai instanceof FormAI) {
165 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
166 $formai = new FormAI($db);
167 }
168 $out .= $formai->getAjaxAICallFunction();
169
170 if (empty($onlyenhancements)) {
171 $onlyenhancements = '';
172 }
173 if (!empty($aiprompt) && !empty($object)) {
174 $formai->setSubstitFromObject($object, $langs);
175 $aiprompt = make_substitutions($aiprompt, $formai->substit);
176 }
177 $format = '';
178 if (is_object($formmail) && !empty($formmail->withaiprompt)) { // $formmail->withaiprompt is set to 'text' or 'html'
179 $format = $formmail->withaiprompt;
180 }
181 $out .= $formai->getSectionForAIEnhancement($showlinktoai, $format, $htmlname, $onlyenhancements, $aiprompt);
182} else {
183 $out .= '<!-- No link to the AI feature, $formmail->withaiprompt must be set to the ai feature and module ai must be enabled -->';
184}
185
186$out .= '<!-- END PHP TEMPLATE htdocs/core/tpl/formlayoutai.tpl.php -->'."\n";
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to generate HTML forms for single email Usage: $formai = new FormAI($db) $formai->proprietes=1 ...
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...