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