dolibarr 21.0.0-beta
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 * Copyright (C) 2024 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 * Need to have the following variables defined:
20 * $conf
21 * $formmail
22 * $formwebsite (optional)
23 * $showlinktolayout='emailing', 'email', 'websitepage', ...
24 * $showlinktolayoutlabel='...'
25 * $showlinktoai ('' or 'textgeneration', 'textgenerationemail', 'textgenerationwebpage', ...)
26 * $showlinktoailabel='...'
27 * $htmlname
28 */
37// Protection to avoid direct call of template
38if (empty($conf) || !is_object($conf)) {
39 print "Error, template page can't be called as URL";
40 exit(1);
41}
42
43if (empty($htmlname)) {
44 print 'Parameter htmlname not defined.';
45 exit(1);
46}
47
48?>
49<!-- BEGIN PHP TEMPLATE formlayoutai.tpl.php -->
50<?php
51
52'
53@phan-var-force ?FormWebSite $formwebsite
54@phan-var-force ?FormMail $formmail
55@phan-var-force string $showlinktolayout
56@phan-var-force string $showlinktolayoutlabel
57';
58
59if (!isset($out)) {
60 $out = '';
61}
62// Add link to add layout
63if ($showlinktolayout) {
64 $out .= '<a href="#" id="linkforlayouttemplates" class="notasortlink inline-block alink marginrightonly">';
65 $out .= img_picto($showlinktolayoutlabel, 'layout', 'class="paddingrightonly"');
66 $out .= $showlinktolayoutlabel.'...';
67 $out .= '</a> &nbsp; &nbsp; ';
68
69 $out .= '<script>
70 $(document).ready(function() {
71 $("#linkforlayouttemplates").click(function() {
72 console.log("We click on linkforlayouttemplates");
73 event.preventDefault();
74 jQuery("#template-selector").toggle();
75 jQuery("#ai_input'.$htmlname.'").hide();
76 jQuery("#pageContent").show(); // May exists for website page only
77 });
78 });
79 </script>
80 ';
81}
82// Add link to add AI content
83if ($showlinktoai) {
84 $out .= '<a href="#" id="linkforaiprompt'.$showlinktoai.'" class="notasortlink inline-block alink marginrightonly">';
85 $out .= img_picto($showlinktoailabel, 'ai', 'class="paddingrightonly"');
86 $out .= $showlinktoailabel.'...';
87 $out .= '</a>';
88
89 $out .= '<script>
90 $(document).ready(function() {
91 $("#linkforaiprompt'.$showlinktoai.'").click(function() {
92 console.log("formlayoutai.tpl: We click on linkforaiprompt'.$showlinktoai.', we toggle #ai_input'.$showlinktoai.'");
93 event.preventDefault();
94 jQuery("#ai_input'.$htmlname.'").toggle();
95 jQuery("#template-selector").hide();
96 jQuery(".email-layout-container").hide();
97 if (!jQuery("#ai_input'.$htmlname.'").is(":hidden")) {
98 console.log("Set focus on input field #ai_instructions'.$htmlname.'");
99 jQuery("#ai_instructions'.$htmlname.'").focus();
100 if (!jQuery("pageContent").is(":hidden")) { // May exists for website page only
101 jQuery("#pageContent").show();
102 }
103 }
104 });
105 });
106 </script>
107 ';
108}
109if ($showlinktolayout) {
110 if (!empty($formwebsite) && is_object($formwebsite)) {
111 $out .= $formwebsite->getContentPageTemplate($htmlname);
112 } else {
113 $out .= $formmail->getModelEmailTemplate($htmlname, $showlinktolayout);
114 }
115} else {
116 $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 -->';
117}
118if ($showlinktoai) {
119 $out .= $formmail->getSectionForAIPrompt($showlinktoai, $formmail->withaiprompt, $htmlname);
120} else {
121 $out .= '<!-- No link to the AI feature, $formmail->withaiprompt must be set to the ai feature and module ai must be enabled -->';
122}
123
124?>
125<!-- 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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79