dolibarr 23.0.3
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
39//Protection to avoid direct call of template
40if (empty($conf) || !is_object($conf)) {
41 print "Error, template page can't be called as URL";
42 exit(1);
43}
44
45if (empty($langs)) {
46 print 'Parameter langs not defined.';
47 exit(1);
48}
49if (empty($htmlname)) {
50 print 'Parameter htmlname not defined.';
51 exit(1);
52}
53
54?>
55<!-- BEGIN PHP TEMPLATE htdocs/core/tpl/formlayoutai.tpl.php -->
56<?php
57
58'
59@phan-var-force ?FormWebSite $formwebsite
60@phan-var-force ?FormMail $formmail
61@phan-var-force ?FormAI $formai
62@phan-var-force string $showlinktolayout
63@phan-var-force string $showlinktolayoutlabel
64@phan-var-force string $showlinktoai
65@phan-var-force string $showlinktoailabel
66@phan-var-force ?string $out
67@phan-var-force ?string $morecss
68@phan-var-force string $aiprompt
69';
70
71if (!isset($out)) { // Init to empty string if not defined
72 $out = '';
73}
74if (!isset($morecss)) { // Init to empty string if not defined
75 $morecss = '';
76}
77if (!isset($aiprompt)) { // Init to empty string if not defined
78 $aiprompt = '';
79}
80// Add link to add layout
81if (!empty($showlinktolayout)) { // May be set only if MAIN_EMAIL_USE_LAYOUT is set
82 $out .= '<a href="#" id="linkforlayouttemplates" class="notasortlink inline-block alink marginrightonly">';
83 $out .= img_picto($showlinktolayoutlabel, 'layout', 'class="paddingrightonly"');
84 $out .= '<span class="hideobject hideonsmartphone">'.$showlinktolayoutlabel.'...</span>';
85 $out .= '</a> &nbsp; &nbsp; ';
86
87 $out .= '<script>
88 $(document).ready(function() {
89 $("#linkforlayouttemplates").click(function() {
90 console.log("We click on linkforlayouttemplates, we toggle .template-selector");
91 event.preventDefault();
92 jQuery(".template-selector").toggle();
93 jQuery(".ai_input'.$htmlname.'").hide();
94 jQuery("#pageContent").show(); // May exists for website page only
95 });
96 });
97 </script>
98 ';
99}
100// Add link to add AI content
101if (!empty($showlinktoai)) {
102 // TODO Diff between showlinktoai and htmlname ? Why not using one key only ?
103 $out .= '<a href="#" id="linkforaiprompt'.$showlinktoai.'" class="notasortlink inline-block alink '.$morecss.'">';
104 $out .= img_picto($showlinktoailabel, 'ai', 'class="paddingrightonly"');
105 $out .= '<span class="hideobject hideonsmartphone">'.$showlinktoailabel.'...</span>';
106 $out .= '</a>';
107
108 $out .= '<script>
109 $(document).ready(function() {
110 $("#linkforaiprompt'.$showlinktoai.'").click(function() {
111 console.log("formlayoutai.tpl: We click on linkforaiprompt'.$showlinktoai.', we toggle .ai_input'.$showlinktoai.'");
112 event.preventDefault();
113 jQuery(".ai_dropdown'.$htmlname.'").toggle();
114 jQuery(".template-selector").hide();
115 jQuery(".email-layout-container").hide();
116 if (!jQuery("#ai_dropdown'.$htmlname.'").is(":hidden")) {
117 console.log("Set focus on input field #ai_instructions'.$htmlname.'");
118 jQuery("#ai_instructions'.$htmlname.'").focus();
119 if (!jQuery("pageContent").is(":hidden")) { // May exists for website page only
120 jQuery("#pageContent").show();
121 }
122 }
123 });
124 $(document).on("click", function (event) {
125 aidropdown = $(".ai_dropdown'.$htmlname.'");
126 aidropdownbutton = $("#linkforaiprompt'.$showlinktoai.'");
127 if (!aidropdown.is(event.target) && !aidropdownbutton.is(event.target) && $(event.target).closest(aidropdown).length === 0 && $(event.target).closest(aidropdownbutton).length === 0 && aidropdown.is(":visible")) {
128 console.log("You clicked outside of ai_dropdown - we close it");
129 $(".ai_dropdown'.$htmlname.'").hide();
130 }
131 });
132 });
133 </script>
134 ';
135}
136
137if (!empty($showlinktolayout)) {
138 if (!empty($formwebsite) && is_object($formwebsite)) {
139 $out .= $formwebsite->getContentPageTemplate($htmlname);
140 } else {
141 if (!is_object($formmail)) {
142 // Create form object
143 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
144 $formmail = new FormMail($db);
145 }
146 $out .= $formmail->getEmailLayoutSelector($htmlname, $showlinktolayout);
147 }
148} else {
149 $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 -->';
150}
151
154if (!empty($showlinktoai)) {
155 if (empty($formai) || $formai instanceof FormAI) {
156 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
157 $formai = new FormAI($db);
158 }
159 $out .= $formai->getAjaxAICallFunction();
160
161 if (empty($onlyenhancements)) {
162 $onlyenhancements = '';
163 }
164 if (!empty($aiprompt) && !empty($object)) {
165 $formai->setSubstitFromObject($object, $langs);
166 $aiprompt = make_substitutions($aiprompt, $formai->substit);
167 }
168 $format = '';
169 if (is_object($formmail) && !empty($formmail->withaiprompt)) {
170 $format = $formmail->withaiprompt;
171 }
172 $out .= $formai->getSectionForAIEnhancement($showlinktoai, $format, $htmlname, $onlyenhancements, $aiprompt);
173} else {
174 $out .= '<!-- No link to the AI feature, $formmail->withaiprompt must be set to the ai feature and module ai must be enabled -->';
175}
176
177?>
178<!-- END PHP TEMPLATE htdocs/core/tpl/formlayoutai.tpl.php -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
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)
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...