dolibarr 21.0.0-alpha
formlayoutai.tpl.php
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Need to have the following variables defined:
19 * $conf
20 * $formmail
21 * $formwebsite (optional)
22 * $showlinktolayout=0|1
23 * $showlinktolayoutlabel='...'
24 * $showlinktoai ('' or 'textgeneration', 'textgenerationemail', 'textgenerationwebpage', ...)
25 * $showlinktoailabel='...'
26 * $htmlname
27 */
28
29// Protection to avoid direct call of template
30if (empty($conf) || !is_object($conf)) {
31 print "Error, template page can't be called as URL";
32 exit(1);
33}
34
35if (empty($htmlname)) {
36 print 'Parameter htmlname not defined.';
37 exit(1);
38}
39
40?>
41<!-- BEGIN PHP TEMPLATE formlayoutai.tpl.php -->
42<?php
43
44'
45@phan-var-force ?FormWebSite $formwebsite
46@phan-var-force ?FormMail $formmail
47';
48
49if (!isset($out)) {
50 $out = '';
51}
52// Add link to add layout
53if ($showlinktolayout) {
54 $out .= '<a href="#" id="linkforlayouttemplates" class="reposition notasortlink inline-block alink marginrightonly">';
55 $out .= img_picto($showlinktolayoutlabel, 'layout', 'class="paddingrightonly"');
56 $out .= $showlinktolayoutlabel.'...';
57 $out .= '</a> &nbsp; &nbsp; ';
58
59 $out .= '<script>
60 $(document).ready(function() {
61 $("#linkforlayouttemplates").click(function() {
62 console.log("We click on linkforlayouttemplates");
63 event.preventDefault();
64 jQuery("#template-selector").toggle();
65 jQuery("#ai_input").hide();
66 jQuery("#pageContent").show(); // May exists for website page only
67 });
68 });
69 </script>
70 ';
71}
72// Add link to add AI content
73if ($showlinktoai) {
74 $out .= '<a href="#" id="linkforaiprompt'.$showlinktoai.'" class="reposition notasortlink inline-block alink marginrightonly">';
75 $out .= img_picto($showlinktoailabel, 'ai', 'class="paddingrightonly"');
76 $out .= $showlinktoailabel.'...';
77 $out .= '</a>';
78
79 $out .= '<script>
80 $(document).ready(function() {
81 $("#linkforaiprompt'.$showlinktoai.'").click(function() {
82 console.log("formlayoutai.tpl: We click on linkforaiprompt'.$showlinktoai.', we toggle #ai_input'.$showlinktoai.'");
83 event.preventDefault();
84 jQuery("#ai_input'.$htmlname.'").toggle();
85 jQuery("#template-selector").hide();
86 if (!jQuery("#ai_input'.$htmlname.'").is(":hidden")) {
87 console.log("Set focus on input field");
88 jQuery("#ai_instructions").focus();
89 if (!jQuery("pageContent").is(":hidden")) { // May exists for website page only
90 jQuery("#pageContent").show();
91 }
92 }
93 });
94 });
95 </script>
96 ';
97}
98if ($showlinktolayout) {
99 if (!empty($formwebsite) && is_object($formwebsite)) {
100 $out .= $formwebsite->getContentPageTemplate($htmlname);
101 } else {
102 $out .= $formmail->getModelEmailTemplate($htmlname);
103 }
104} else {
105 $out .= '<!-- No link to the layout feature, $formmail->withlayout must be set to 1, module WYSIWYG must be enabled and MAIN_EMAIL_USE_LAYOUT must be set -->';
106}
107if ($showlinktoai) {
108 $out .= $formmail->getSectionForAIPrompt($showlinktoai, $formmail->withaiprompt, $htmlname);
109} else {
110 $out .= '<!-- No link to the AI feature, $formmail->withaiprompt must be set to the ai feature and module ai must be enabled -->';
111}
112
113?>
114<!-- END PHP TEMPLATE commonfields_edit.tpl.php -->
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)