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', '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 $langs->load('errors');
151 setEventMessages($langs->trans("EmptyMessageNotAllowedError"), null, 'warnings');
152 } else {
153 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
154 }
155}
156
157
158/*
159 * View
160 */
161
162llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-fckeditor');
163
164$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>';
165
166print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
167print '<br>';
168
169if (empty($conf->use_javascript_ajax)) {
170 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
171} else {
172 // Editor backend choice (CKEditor vs TinyMCE)
173 $currentbackend = getDolGlobalString('FCKEDITOR_EDITORNAME', 'ckeditor');
174 if (!in_array($currentbackend, array('ckeditor', 'tinymce'), true)) {
175 $currentbackend = 'ckeditor';
176 }
177
178 print '<table class="noborder centpercent">';
179 print '<tr class="liste_titre">';
180 print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
181 print '<td class="center width100"></td>';
182 print "</tr>\n";
183
184 // Modules
185 foreach ($modules as $const => $desc) {
186 // If this condition is not met, the option is not offered
187 if (!$conditions[$const]) {
188 continue;
189 }
190
191 $constante = 'FCKEDITOR_ENABLE_'.$const;
192 print '<!-- constant = '.$constante.' -->'."\n";
193 print '<tr class="oddeven">';
194 print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
195 print '<td>';
196 print $langs->trans($desc);
197 if ($const == 'DETAILS') {
198 print $form->textwithpicto('', '<span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>');
199 }
200 print '</td>';
201 print '<td class="center centpercent width100">';
202 $value = getDolGlobalInt($constante, 0);
203 if ($value == 0) {
204 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
205 } elseif ($value == 1) {
206 if ($const == 'DETAILS') {
207 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>';
208 } else {
209 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
210 }
211 }
212
213 print "</td>";
214 print '</tr>';
215 }
216
217 print '</table>'."\n";
218
219 print '<br>'."\n";
220
221
222 // Other options
223
224 print '<form name="formeditorbackend" method="POST" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
225 print '<input type="hidden" name="token" value="'.newToken().'">';
226 print '<input type="hidden" name="action" value="setbackend">';
227 print '<input type="hidden" name="mode" value="'.$mode.'">';
228 print '<input type="hidden" name="page_y" value="">';
229
230 print '<table class="noborder centpercent">';
231 print '<tr class="liste_titre">';
232 print '<td>'.$langs->trans("Other").'</td>';
233 print '<td></td>';
234 print '<td></td>';
235 print "</tr>\n";
236
237
238 print '<tr class="oddeven">';
239 print '<td>';
240 print $langs->trans("EditorBackend");
241 print '</td>';
242 print '<td class="right">';
243 $arrayofeditor = array(
244 'ckeditor' => array('label' => 'CKEditor 4'),
245 'tinymce' => array('label' => 'TinyMCE ('.$langs->trans("Experimental").')', 'data-html' => 'TinyMCE <span class="opacitymedium">('.$langs->trans("Experimental").')</span>')
246 );
247 print $form->selectarray("editorbackend", $arrayofeditor, $currentbackend);
248 print ' '.$form->textwithpicto('', $langs->trans("EditorBackendHelp"));
249 print '</td>';
250 print '<td class="center width100"><input type="submit" class="button smallpaddingimp reposition" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
251 print '</tr>';
252
253
254 $constante = 'FCKEDITOR_ENABLE_SPECIALCHAR';
255 print '<!-- constant = '.$constante.' -->'."\n";
256 print '<tr class="oddeven">';
257 print '<td>';
258 print $langs->trans('SpecialCharActivation');
259 print '</td>';
260 print '<td class="center width100" colspan="2">';
261 $value = getDolGlobalInt($constante, 0);
262 if ($value == 0) {
263 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
264 } elseif ($value == 1) {
265 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_specialchar&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
266 }
267
268 print "</td>";
269 print '</tr>';
270
271 print '</table>'."\n";
272
273 print '</form>'."\n";
274
275 print '<br><br><br>'."\n";
276
277
278 print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
279 print '<input type="hidden" name="token" value="'.newToken().'">';
280 print '<input type="hidden" name="page_y" value="">';
281
282 // Skins
283 //show_skin(null, 1);
284 //print '<br>'."\n";
285
286 $listofmodes = array('dolibarr_readonly' => 'ReadOnly', 'dolibarr_details' => 'DetailOfLines', 'dolibarr_notes' => 'Notes', 'dolibarr_mailings' => 'Emails', 'Full' => 'AllFeatures', 'Full_inline' => 'EditInLine');
287 $linkstomode = '';
288 foreach ($listofmodes as $newmode => $newmodelabel) {
289 if (!$linkstomode) {
290 $linkstomode = '<span class="opacitymedium">'.$langs->trans("Mode").': </span>';
291 }
292 $linkstomode .= '<a class="a-selection'.($mode != $newmode ? '-disabled' : '').' marginleftonly marginrightonly reposition nounderline" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
293 $linkstomode .= $langs->trans($newmodelabel);
294 $linkstomode .= '</a>';
295 }
296 print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
297 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
298 if ($mode != 'Full_inline') {
299 $uselocalbrowser = true;
300 $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
301 $editor = new DolEditor('formtestfield', getDolGlobalString('FCKEDITOR_TEST', 'Test'), '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, '8', $readonly);
302 $editor->Create();
303 } else {
304 // CKEditor inline enabled with the contenteditable="true"
305 print '<div style="border: 1px solid #888;" contenteditable="true">';
306 print getDolGlobalString('FCKEDITOR_TEST');
307 print '</div>';
308 }
309 print $form->buttonsSaveCancel("Save", '', array(), 0, 'reposition');
310 print '<div id="divforlog"></div>';
311 print '</form>'."\n";
312
313 // Add env of ckeditor
314 // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
315 /*
316 print '<br><script type="text/javascript">
317 function jsdump(obj, id) {
318 var out = \'\';
319 for (var i in obj) {
320 out += i + ": " + obj[i] + "<br>\n";
321 }
322
323 jQuery("#"+id).html(out);
324 }
325
326 jsdump(CKEDITOR.env, "divforlog");
327 </script>';
328 }
329 */
330}
331
332// End of page
333llxFooter();
334$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
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.