dolibarr 21.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 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
35// Load translation files required by the page
36$langs->loadLangs(array('admin', 'fckeditor', 'errors'));
37
38$action = GETPOST('action', 'aZ09');
39// Possible modes are:
40// dolibarr_details
41// dolibarr_notes
42// dolibarr_readonly
43// dolibarr_mailings
44// Full (not sure this one is used)
45$mode = GETPOST('mode') ? GETPOST('mode', 'alpha') : 'dolibarr_notes';
46
47if (!$user->admin) {
49}
50
51// Constant and translation of the module description
52$modules = array(
53 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
54 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
55 'SOCIETE' => 'FCKeditorForCompany',
56 'DETAILS' => 'FCKeditorForProductDetails',
57 'USERSIGN' => 'FCKeditorForUserSignature',
58 'MAILING' => 'FCKeditorForMailing',
59 'MAIL' => 'FCKeditorForMail',
60 'TICKET' => 'FCKeditorForTicket',
61 //'SPECIALCHAR' => 'SpecialCharActivation',
62);
63// Conditions for the option to be offered
64$conditions = array(
65 'NOTE_PUBLIC' => 1,
66 'NOTE_PRIVATE' => 1,
67 'SOCIETE' => 1,
68 'PRODUCTDESC' => (isModEnabled("product") || isModEnabled("service")),
69 'DETAILS' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
70 'USERSIGN' => 1,
71 'MAILING' => isModEnabled('mailing'),
72 'MAIL' => (isModEnabled('invoice') || isModEnabled("propal") || isModEnabled('order')),
73 'TICKET' => isModEnabled('ticket'),
74 //'SPECIALCHAR' => 1,
75);
76// Picto
77$picto = array(
78 'NOTE_PUBLIC' => 'generic',
79 'NOTE_PRIVATE' => 'generic',
80 'SOCIETE' => 'generic',
81 'PRODUCTDESC' => 'product',
82 'DETAILS' => 'product',
83 'USERSIGN' => 'user',
84 'MAILING' => 'email',
85 'MAIL' => 'email',
86 'TICKET' => 'ticket',
87 //'SPECIALCHAR' => 'generic'
88);
89
90
91
92/*
93 * Actions
94 */
95
96foreach ($modules as $const => $desc) {
97 if ($action == 'enable_'.strtolower($const)) {
98 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
99
100 // If fckeditor is active in the product/service description, it is activated in the forms
101 if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
102 dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
103 }
104 }
105 if ($action == 'disable_'.strtolower($const)) {
106 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
107 }
108}
109
110if (GETPOST('save', 'alpha')) {
111 $error = 0;
112
113 $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
114 if (!empty($fckeditor_skin)) {
115 $result = dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity);
116 if ($result <= 0) {
117 $error++;
118 }
119 } else {
120 $error++;
121 }
122
123 $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
124 if (!empty($fckeditor_test)) {
125 $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
126 if ($result <= 0) {
127 $error++;
128 }
129 } else {
130 $error = -1; // -1 means a warning message
131 }
132
133 if ($error == 0) {
134 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
135 } elseif ($error == -1) {
136 setEventMessages($langs->trans("EmptyMessageNotAllowedError"), null, 'warnings');
137 } else {
138 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
139 }
140}
141
142
143/*
144 * View
145 */
146
147llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-fckeditor');
148
149$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
150print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
151print '<br>';
152
153if (empty($conf->use_javascript_ajax)) {
154 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
155} else {
156 print '<table class="noborder centpercent">';
157 print '<tr class="liste_titre">';
158 print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
159 print '<td class="center width100"></td>';
160 print "</tr>\n";
161
162 // Modules
163 foreach ($modules as $const => $desc) {
164 // If this condition is not met, the option is not offered
165 if (!$conditions[$const]) {
166 continue;
167 }
168
169 $constante = 'FCKEDITOR_ENABLE_'.$const;
170 print '<!-- constant = '.$constante.' -->'."\n";
171 print '<tr class="oddeven">';
172 print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
173 print '<td>';
174 print $langs->trans($desc);
175 if ($const == 'DETAILS') {
176 print $form->textwithpicto('', '<span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>');
177 }
178 print '</td>';
179 print '<td class="center centpercent width100">';
180 $value = getDolGlobalInt($constante, 0);
181 if ($value == 0) {
182 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
183 } elseif ($value == 1) {
184 if ($const == 'DETAILS') {
185 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>';
186 } else {
187 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
188 }
189 }
190
191 print "</td>";
192 print '</tr>';
193 }
194
195 print '</table>'."\n";
196
197 print '<br>'."\n";
198
199
200 // Other options
201 print '<table class="noborder centpercent">';
202 print '<tr class="liste_titre">';
203 print '<td>'.$langs->trans("Other").'</td>';
204 print '<td class="center"></td>';
205 print "</tr>\n";
206
207 $constante = 'FCKEDITOR_ENANLE_SPECIALCHAR';
208 print '<!-- constant = '.$constante.' -->'."\n";
209 print '<tr class="oddeven">';
210 print '<td>';
211 print $langs->trans('SpecialCharActivation');
212 print '</td>';
213 print '<td class="center width100">';
214 $value = getDolGlobalInt($constante, 0);
215 if ($value == 0) {
216 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
217 } elseif ($value == 1) {
218 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
219 }
220
221 print "</td>";
222 print '</tr>';
223
224 print '</table>'."\n";
225
226 print '<br>'."\n";
227
228
229 print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
230 print '<input type="hidden" name="token" value="'.newToken().'">';
231 print '<input type="hidden" name="page_y" value="">';
232
233 // Skins
234 //show_skin(null, 1);
235 //print '<br>'."\n";
236
237 $listofmodes = array('dolibarr_readonly', 'dolibarr_details', 'dolibarr_notes', 'dolibarr_mailings', 'Full', 'Full_inline');
238 $linkstomode = '';
239 foreach ($listofmodes as $newmode) {
240 if ($linkstomode) {
241 $linkstomode .= ' - ';
242 }
243 $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
244 if ($mode == $newmode) {
245 $linkstomode .= '<strong>';
246 }
247 $linkstomode .= $newmode;
248 if ($mode == $newmode) {
249 $linkstomode .= '</strong>';
250 }
251 $linkstomode .= '</a>';
252 }
253 $linkstomode .= '';
254 print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
255 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
256 if ($mode != 'Full_inline') {
257 $uselocalbrowser = true;
258 $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
259 $editor = new DolEditor('formtestfield', getDolGlobalString('FCKEDITOR_TEST', 'Test'), '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, '8', $readonly);
260 $editor->Create();
261 } else {
262 // CKEditor inline enabled with the contenteditable="true"
263 print '<div style="border: 1px solid #888;" contenteditable="true">';
264 print getDolGlobalString('FCKEDITOR_TEST');
265 print '</div>';
266 }
267 print $form->buttonsSaveCancel("Save", '', array(), 0, 'reposition');
268 print '<div id="divforlog"></div>';
269 print '</form>'."\n";
270
271 // Add env of ckeditor
272 // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
273 /*
274 print '<br><script type="text/javascript">
275 function jsdump(obj, id) {
276 var out = \'\';
277 for (var i in obj) {
278 out += i + ": " + obj[i] + "<br>\n";
279 }
280
281 jQuery("#"+id).html(out);
282 }
283
284 jsdump(CKEDITOR.env, "divforlog");
285 </script>';
286 }
287 */
288}
289
290// End of page
291llxFooter();
292$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).
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:70
Class to manage a WYSIWYG editor.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.