dolibarr 23.0.3
fckeditor.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2019 Christophe Battarel <christophe@altairis.fr>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
34
44// Load translation files required by the page
45$langs->loadLangs(array('admin', 'fckeditor', 'errors'));
46
47$action = GETPOST('action', 'aZ09');
48// Possible modes are:
49// dolibarr_details
50// dolibarr_notes
51// dolibarr_readonly
52// dolibarr_mailings
53// Full (not sure this one is used)
54$mode = GETPOST('mode') ? GETPOST('mode', 'alpha') : 'dolibarr_notes';
55
56if (!$user->admin) {
58}
59
60// Constant and translation of the module description
61$modules = array(
62 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
63 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
64 'SOCIETE' => 'FCKeditorForCompany',
65 'DETAILS' => 'FCKeditorForProductDetails',
66 'USERSIGN' => 'FCKeditorForUserSignature',
67 'MAILING' => 'FCKeditorForMailing',
68 'MAIL' => 'FCKeditorForMail',
69 'TICKET' => 'FCKeditorForTicket',
70 //'SPECIALCHAR' => 'SpecialCharActivation',
71);
72// Conditions for the option to be offered
73$conditions = array(
74 'NOTE_PUBLIC' => 1,
75 'NOTE_PRIVATE' => 1,
76 'SOCIETE' => 1,
77 'PRODUCTDESC' => (isModEnabled("product") || isModEnabled("service")),
78 'DETAILS' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
79 'USERSIGN' => 1,
80 'MAILING' => isModEnabled('mailing'),
81 'MAIL' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order')),
82 'TICKET' => isModEnabled('ticket'),
83 //'SPECIALCHAR' => 1,
84);
85// Picto
86$picto = array(
87 'NOTE_PUBLIC' => 'generic',
88 'NOTE_PRIVATE' => 'generic',
89 'SOCIETE' => 'generic',
90 'PRODUCTDESC' => 'product',
91 'DETAILS' => 'product',
92 'USERSIGN' => 'user',
93 'MAILING' => 'email',
94 'MAIL' => 'email',
95 'TICKET' => 'ticket',
96 //'SPECIALCHAR' => 'generic'
97);
98
99
100
101/*
102 * Actions
103 */
104
105foreach ($modules as $const => $desc) {
106 if ($action == 'enable_'.strtolower($const)) {
107 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
108
109 // If fckeditor is active in the product/service description, it is activated in the forms
110 if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
111 dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
112 }
113 }
114 if ($action == 'disable_'.strtolower($const)) {
115 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
116 }
117}
118
119if (GETPOST('action') == 'enable_specialchar') {
120 dolibarr_set_const($db, "FCKEDITOR_ENABLE_SPECIALCHAR", "1", 'chaine', 0, '', $conf->entity);
121}
122if (GETPOST('action') == 'disable_specialchar') {
123 dolibarr_del_const($db, "FCKEDITOR_ENABLE_SPECIALCHAR", $conf->entity);
124}
125
126if (GETPOST('save', 'alpha')) {
127 $error = 0;
128
129 $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
130 if (!empty($fckeditor_test)) {
131 $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
132 if ($result <= 0) {
133 $error++;
134 }
135 } else {
136 $error = -1; // -1 means a warning message
137 }
138
139 if ($error == 0) {
140 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
141 } elseif ($error == -1) {
142 setEventMessages($langs->trans("EmptyMessageNotAllowedError"), null, 'warnings');
143 } else {
144 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
145 }
146}
147
148
149/*
150 * View
151 */
152
153llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-fckeditor');
154
155$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
156
157print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
158print '<br>';
159
160if (empty($conf->use_javascript_ajax)) {
161 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
162} else {
163 print '<table class="noborder centpercent">';
164 print '<tr class="liste_titre">';
165 print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
166 print '<td class="center width100"></td>';
167 print "</tr>\n";
168
169 // Modules
170 foreach ($modules as $const => $desc) {
171 // If this condition is not met, the option is not offered
172 if (!$conditions[$const]) {
173 continue;
174 }
175
176 $constante = 'FCKEDITOR_ENABLE_'.$const;
177 print '<!-- constant = '.$constante.' -->'."\n";
178 print '<tr class="oddeven">';
179 print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
180 print '<td>';
181 print $langs->trans($desc);
182 if ($const == 'DETAILS') {
183 print $form->textwithpicto('', '<span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>');
184 }
185 print '</td>';
186 print '<td class="center centpercent width100">';
187 $value = getDolGlobalInt($constante, 0);
188 if ($value == 0) {
189 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
190 } elseif ($value == 1) {
191 if ($const == 'DETAILS') {
192 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled").' - '.$langs->trans("FCKeditorForProductDetails2"), 'switch_on', '', 0, 0, 0, '', 'warning').'</a>';
193 } else {
194 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
195 }
196 }
197
198 print "</td>";
199 print '</tr>';
200 }
201
202 print '</table>'."\n";
203
204 print '<br>'."\n";
205
206
207 // Other options
208 print '<table class="noborder centpercent">';
209 print '<tr class="liste_titre">';
210 print '<td>'.$langs->trans("Other").'</td>';
211 print '<td class="center"></td>';
212 print "</tr>\n";
213
214 $constante = 'FCKEDITOR_ENABLE_SPECIALCHAR';
215 print '<!-- constant = '.$constante.' -->'."\n";
216 print '<tr class="oddeven">';
217 print '<td>';
218 print $langs->trans('SpecialCharActivation');
219 print '</td>';
220 print '<td class="center width100">';
221 $value = getDolGlobalInt($constante, 0);
222 if ($value == 0) {
223 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
224 } elseif ($value == 1) {
225 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
226 }
227
228 print "</td>";
229 print '</tr>';
230
231 print '</table>'."\n";
232
233 print '<br>'."\n";
234
235
236 print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
237 print '<input type="hidden" name="token" value="'.newToken().'">';
238 print '<input type="hidden" name="page_y" value="">';
239
240 // Skins
241 //show_skin(null, 1);
242 //print '<br>'."\n";
243
244 $listofmodes = array('dolibarr_readonly', 'dolibarr_details', 'dolibarr_notes', 'dolibarr_mailings', 'Full', 'Full_inline');
245 $linkstomode = '';
246 foreach ($listofmodes as $newmode) {
247 if ($linkstomode) {
248 $linkstomode .= ' - ';
249 }
250 $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
251 if ($mode == $newmode) {
252 $linkstomode .= '<strong>';
253 }
254 $linkstomode .= $newmode;
255 if ($mode == $newmode) {
256 $linkstomode .= '</strong>';
257 }
258 $linkstomode .= '</a>';
259 }
260 $linkstomode .= '';
261 print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
262 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
263 if ($mode != 'Full_inline') {
264 $uselocalbrowser = true;
265 $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
266 $editor = new DolEditor('formtestfield', getDolGlobalString('FCKEDITOR_TEST', 'Test'), '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, '8', $readonly);
267 $editor->Create();
268 } else {
269 // CKEditor inline enabled with the contenteditable="true"
270 print '<div style="border: 1px solid #888;" contenteditable="true">';
271 print getDolGlobalString('FCKEDITOR_TEST');
272 print '</div>';
273 }
274 print $form->buttonsSaveCancel("Save", '', array(), 0, 'reposition');
275 print '<div id="divforlog"></div>';
276 print '</form>'."\n";
277
278 // Add env of ckeditor
279 // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
280 /*
281 print '<br><script type="text/javascript">
282 function jsdump(obj, id) {
283 var out = \'\';
284 for (var i in obj) {
285 out += i + ": " + obj[i] + "<br>\n";
286 }
287
288 jQuery("#"+id).html(out);
289 }
290
291 jsdump(CKEDITOR.env, "divforlog");
292 </script>';
293 }
294 */
295}
296
297// End of page
298llxFooter();
299$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage a WYSIWYG editor.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.