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