dolibarr 25.0.0-alpha
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-2026 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';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42
43// Load translation files required by the page
44$langs->loadLangs(array('admin', 'fckeditor', 'errors', 'website'));
45
46$action = GETPOST('action', 'aZ09');
47// Possible modes are:
48// dolibarr_details
49// dolibarr_notes
50// dolibarr_readonly
51// dolibarr_mailings
52// Full (not sure this one is used)
53$mode = GETPOST('mode') ? GETPOST('mode', 'alpha') : 'dolibarr_notes';
54
55if (!$user->admin) {
57}
58
59// Constant and translation of the module description
60$modules = array(
61 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
62 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
63 'SOCIETE' => 'FCKeditorForCompany',
64 'DETAILS' => 'FCKeditorForProductDetails',
65 'USERSIGN' => 'FCKeditorForUserSignature',
66 'MAILING' => 'FCKeditorForMailing',
67 'MAIL' => 'FCKeditorForMail',
68 'TICKET' => 'FCKeditorForTicket',
69 //'SPECIALCHAR' => 'SpecialCharActivation',
70);
71// Conditions for the option to be offered
72$conditions = array(
73 'NOTE_PUBLIC' => 1,
74 'NOTE_PRIVATE' => 1,
75 'SOCIETE' => 1,
76 'DETAILS' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
77 'USERSIGN' => 1,
78 'MAILING' => isModEnabled('mailing'),
79 'MAIL' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order')),
80 'TICKET' => isModEnabled('ticket'),
81 //'SPECIALCHAR' => 1,
82);
83// Picto
84$picto = array(
85 'NOTE_PUBLIC' => 'generic',
86 'NOTE_PRIVATE' => 'generic',
87 'SOCIETE' => 'generic',
88 'DETAILS' => 'product',
89 'USERSIGN' => 'user',
90 'MAILING' => 'email',
91 'MAIL' => 'email',
92 'TICKET' => 'ticket',
93 //'SPECIALCHAR' => 'generic'
94);
95
96
97
98/*
99 * Actions
100 */
101
102foreach ($modules as $const => $desc) {
103 if ($action == 'enable_'.strtolower($const)) {
104 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
105 }
106 if ($action == 'disable_'.strtolower($const)) {
107 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
108 }
109}
110
111if (GETPOST('action') == 'enable_specialchar') {
112 dolibarr_set_const($db, "FCKEDITOR_ENABLE_SPECIALCHAR", "1", 'chaine', 0, '', $conf->entity);
113}
114if (GETPOST('action') == 'disable_specialchar') {
115 dolibarr_del_const($db, "FCKEDITOR_ENABLE_SPECIALCHAR", $conf->entity);
116}
117
118if (GETPOST('action', 'aZ09') == 'setbackend') {
119 $newbackend = GETPOST('editorbackend', 'aZ09');
120 if (in_array($newbackend, array('ckeditor', 'tinymce'), true)) {
121 $res = dolibarr_set_const($db, 'FCKEDITOR_EDITORNAME', $newbackend, 'chaine', 0, '', $conf->entity);
122 if ($res > 0) {
123 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
124 } else {
125 dol_syslog("admin/fckeditor.php: failed to save FCKEDITOR_EDITORNAME=".$newbackend.": ".$db->lasterror(), LOG_ERR);
126 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
127 }
128 } else {
129 dol_syslog("admin/fckeditor.php: invalid editor backend value: ".$newbackend, LOG_WARNING);
130 setEventMessages($langs->trans("ErrorBadValue"), null, 'errors');
131 }
132}
133
134if (GETPOST('save', 'alpha')) {
135 $error = 0;
136
137 $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
138 if (!empty($fckeditor_test)) {
139 $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
140 if ($result <= 0) {
141 $error++;
142 }
143 } else {
144 $error = -1; // -1 means a warning message
145 }
146
147 if ($error == 0) {
148 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
149 } elseif ($error == -1) {
150 setEventMessages($langs->trans("EmptyMessageNotAllowedError"), null, 'warnings');
151 } else {
152 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
153 }
154}
155
156
157/*
158 * View
159 */
160
161llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-fckeditor');
162
163$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>';
164
165print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
166print '<br>';
167
168if (empty($conf->use_javascript_ajax)) {
169 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
170} else {
171 // Editor backend choice (CKEditor vs TinyMCE)
172 $currentbackend = getDolGlobalString('FCKEDITOR_EDITORNAME', 'ckeditor');
173 if (!in_array($currentbackend, array('ckeditor', 'tinymce'), true)) {
174 $currentbackend = 'ckeditor';
175 }
176
177 print '<table class="noborder centpercent">';
178 print '<tr class="liste_titre">';
179 print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
180 print '<td class="center width100"></td>';
181 print "</tr>\n";
182
183 // Modules
184 foreach ($modules as $const => $desc) {
185 // If this condition is not met, the option is not offered
186 if (!$conditions[$const]) {
187 continue;
188 }
189
190 $constante = 'FCKEDITOR_ENABLE_'.$const;
191 print '<!-- constant = '.$constante.' -->'."\n";
192 print '<tr class="oddeven">';
193 print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
194 print '<td>';
195 print $langs->trans($desc);
196 if ($const == 'DETAILS') {
197 print $form->textwithpicto('', '<span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>');
198 }
199 print '</td>';
200 print '<td class="center centpercent width100">';
201 $value = getDolGlobalInt($constante, 0);
202 if ($value == 0) {
203 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
204 } elseif ($value == 1) {
205 if ($const == 'DETAILS') {
206 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>';
207 } else {
208 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
209 }
210 }
211
212 print "</td>";
213 print '</tr>';
214 }
215
216 print '</table>'."\n";
217
218 print '<br>'."\n";
219
220
221 // Other options
222
223 print '<form name="formeditorbackend" method="POST" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
224 print '<input type="hidden" name="token" value="'.newToken().'">';
225 print '<input type="hidden" name="action" value="setbackend">';
226 print '<input type="hidden" name="mode" value="'.$mode.'">';
227 print '<input type="hidden" name="page_y" value="">';
228
229 print '<table class="noborder centpercent">';
230 print '<tr class="liste_titre">';
231 print '<td>'.$langs->trans("Other").'</td>';
232 print '<td></td>';
233 print '<td></td>';
234 print "</tr>\n";
235
236
237 print '<tr class="oddeven">';
238 print '<td>';
239 print $langs->trans("EditorBackend");
240 print '</td>';
241 print '<td class="right">';
242 $arrayofeditor = array(
243 'ckeditor' => array('label' => 'CKEditor 4'),
244 'tinymce' => array('label' => 'TinyMCE ('.$langs->trans("Experimental").')', 'data-html' => 'TinyMCE <span class="opacitymedium">('.$langs->trans("Experimental").')</span>')
245 );
246 print $form->selectarray("editorbackend", $arrayofeditor, $currentbackend);
247 print ' '.$form->textwithpicto('', $langs->trans("EditorBackendHelp"));
248 print '</td>';
249 print '<td class="center width100"><input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
250 print '</tr>';
251
252
253 $constante = 'FCKEDITOR_ENABLE_SPECIALCHAR';
254 print '<!-- constant = '.$constante.' -->'."\n";
255 print '<tr class="oddeven">';
256 print '<td>';
257 print $langs->trans('SpecialCharActivation');
258 print '</td>';
259 print '<td class="center width100" colspan="2">';
260 $value = getDolGlobalInt($constante, 0);
261 if ($value == 0) {
262 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
263 } elseif ($value == 1) {
264 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
265 }
266
267 print "</td>";
268 print '</tr>';
269
270 print '</table>'."\n";
271
272 print '</form>'."\n";
273
274 print '<br><br><br>'."\n";
275
276
277 print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
278 print '<input type="hidden" name="token" value="'.newToken().'">';
279 print '<input type="hidden" name="page_y" value="">';
280
281 // Skins
282 //show_skin(null, 1);
283 //print '<br>'."\n";
284
285 $listofmodes = array('dolibarr_readonly' => 'ReadOnly', 'dolibarr_details' => 'DetailOfLines', 'dolibarr_notes' => 'Notes', 'dolibarr_mailings' => 'Emails', 'Full' => 'AllFeatures', 'Full_inline' => 'EditInLine');
286 $linkstomode = '';
287 foreach ($listofmodes as $newmode => $newmodelabel) {
288 if (!$linkstomode) {
289 $linkstomode = '<span class="opacitymedium">'.$langs->trans("Mode").': </span>';
290 }
291 $linkstomode .= '<a class="a-selection'.($mode != $newmode ? '-disabled' : '').' marginleftonly marginrightonly reposition nounderline" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
292 $linkstomode .= $langs->trans($newmodelabel);
293 $linkstomode .= '</a>';
294 }
295 print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
296 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
297 if ($mode != 'Full_inline') {
298 $uselocalbrowser = true;
299 $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
300 $editor = new DolEditor('formtestfield', getDolGlobalString('FCKEDITOR_TEST', 'Test'), '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, '8', $readonly);
301 $editor->Create();
302 } else {
303 // CKEditor inline enabled with the contenteditable="true"
304 print '<div style="border: 1px solid #888;" contenteditable="true">';
305 print getDolGlobalString('FCKEDITOR_TEST');
306 print '</div>';
307 }
308 print $form->buttonsSaveCancel("Save", '', array(), 0, 'reposition');
309 print '<div id="divforlog"></div>';
310 print '</form>'."\n";
311
312 // Add env of ckeditor
313 // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
314 /*
315 print '<br><script type="text/javascript">
316 function jsdump(obj, id) {
317 var out = \'\';
318 for (var i in obj) {
319 out += i + ": " + obj[i] + "<br>\n";
320 }
321
322 jQuery("#"+id).html(out);
323 }
324
325 jsdump(CKEDITOR.env, "divforlog");
326 </script>';
327 }
328 */
329}
330
331// End of page
332llxFooter();
333$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.