dolibarr 19.0.4
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array('admin', 'fckeditor'));
35
36$action = GETPOST('action', 'aZ09');
37// Possible modes are:
38// dolibarr_details
39// dolibarr_notes
40// dolibarr_readonly
41// dolibarr_mailings
42// Full (not sure this one is used)
43$mode = GETPOST('mode') ? GETPOST('mode', 'alpha') : 'dolibarr_notes';
44
45if (!$user->admin) {
47}
48
49// Constant and translation of the module description
50$modules = array(
51 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
52 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
53 'SOCIETE' => 'FCKeditorForCompany',
54 //'PRODUCTDESC' => 'FCKeditorForProduct',
55 'DETAILS' => 'FCKeditorForProductDetails',
56 'USERSIGN' => 'FCKeditorForUserSignature',
57 'MAILING' => 'FCKeditorForMailing',
58 'MAIL' => 'FCKeditorForMail',
59 'TICKET' => 'FCKeditorForTicket',
60 'SPECIALCHAR' => 'SpecialCharActivation',
61);
62// Conditions for the option to be offered
63$conditions = array(
64 'NOTE_PUBLIC' => 1,
65 'NOTE_PRIVATE' => 1,
66 'SOCIETE' => 1,
67 'PRODUCTDESC' => (isModEnabled("product") || isModEnabled("service")),
68 'DETAILS' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
69 'USERSIGN' => 1,
70 'MAILING' => isModEnabled('mailing'),
71 'MAIL' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande')),
72 'TICKET' => isModEnabled('ticket'),
73 'SPECIALCHAR' => 1,
74);
75// Picto
76$picto = array(
77 'NOTE_PUBLIC' => 'generic',
78 'NOTE_PRIVATE' => 'generic',
79 'SOCIETE' => 'generic',
80 'PRODUCTDESC' => 'product',
81 'DETAILS' => 'product',
82 'USERSIGN' => 'user',
83 'MAILING' => 'email',
84 'MAIL' => 'email',
85 'TICKET' => 'ticket',
86 'SPECIALCHAR' => 'generic'
87);
88
89
90
91/*
92 * Actions
93 */
94
95foreach ($modules as $const => $desc) {
96 if ($action == 'enable_'.strtolower($const)) {
97 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
98
99 // If fckeditor is active in the product/service description, it is activated in the forms
100 if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
101 dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
102 }
103 }
104 if ($action == 'disable_'.strtolower($const)) {
105 dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
106 }
107}
108
109if (GETPOST('save', 'alpha')) {
110 $error = 0;
111
112 $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
113 if (!empty($fckeditor_skin)) {
114 $result = dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity);
115 if ($result <= 0) {
116 $error++;
117 }
118 } else {
119 $error++;
120 }
121
122 $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
123 if (!empty($fckeditor_test)) {
124 $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
125 if ($result <= 0) {
126 $error++;
127 }
128 } else {
129 $error++;
130 }
131
132 if (!$error) {
133 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
134 } else {
135 setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
136 }
137}
138
139/*
140 * View
141 */
142
143llxHeader();
144
145$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
146print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
147print '<br>';
148
149if (empty($conf->use_javascript_ajax)) {
150 setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
151} else {
152 print '<table class="noborder centpercent">';
153 print '<tr class="liste_titre">';
154 print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
155 print '<td class="center" width="100">'.$langs->trans("Action").'</td>';
156 print "</tr>\n";
157
158 // Modules
159 foreach ($modules as $const => $desc) {
160 // If this condition is not met, the option is not offered
161 if (!$conditions[$const]) {
162 continue;
163 }
164
165 $constante = 'FCKEDITOR_ENABLE_'.$const;
166 print '<!-- constant = '.$constante.' -->'."\n";
167 print '<tr class="oddeven">';
168 print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
169 print '<td>';
170 print $langs->trans($desc);
171 if ($const == 'DETAILS') {
172 print '<br><span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>';
173 }
174 print '</td>';
175 print '<td class="center centpercent width100">';
176 $value = getDolGlobalInt($constante, 0);
177 if ($value == 0) {
178 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
179 } elseif ($value == 1) {
180 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
181 }
182
183 print "</td>";
184 print '</tr>';
185 }
186
187 print '</table>'."\n";
188
189 print '<br>'."\n";
190
191 print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
192 print '<input type="hidden" name="token" value="'.newToken().'">';
193 print '<input type="hidden" name="page_y" value="">';
194
195 // Skins
196 show_skin(null, 1);
197 print '<br>'."\n";
198
199 $listofmodes = array('dolibarr_mailings', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_readonly', 'Full', 'Full_inline');
200 $linkstomode = '';
201 foreach ($listofmodes as $newmode) {
202 if ($linkstomode) {
203 $linkstomode .= ' - ';
204 }
205 $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
206 if ($mode == $newmode) {
207 $linkstomode .= '<strong>';
208 }
209 $linkstomode .= $newmode;
210 if ($mode == $newmode) {
211 $linkstomode .= '</strong>';
212 }
213 $linkstomode .= '</a>';
214 }
215 $linkstomode .= '';
216 print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
217 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
218 if ($mode != 'Full_inline') {
219 $uselocalbrowser = true;
220 $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
221 $editor = new DolEditor('formtestfield', isset($conf->global->FCKEDITOR_TEST) ? $conf->global->FCKEDITOR_TEST : 'Test', '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
222 $editor->Create();
223 } else {
224 // CKEditor inline enabled with the contenteditable="true"
225 print '<div style="border: 1px solid #888;" contenteditable="true">';
226 print $conf->global->FCKEDITOR_TEST;
227 print '</div>';
228 }
229 print $form->buttonsSaveCancel("Save", '', null, 0, 'reposition');
230 print '<div id="divforlog"></div>';
231 print '</form>'."\n";
232
233 // Add env of ckeditor
234 // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
235 /*
236 print '<br><script type="text/javascript">
237 function jsdump(obj, id) {
238 var out = \'\';
239 for (var i in obj) {
240 out += i + ": " + obj[i] + "<br>\n";
241 }
242
243 jQuery("#"+id).html(out);
244 }
245
246 jsdump(CKEDITOR.env, "divforlog");
247 </script>';
248 }
249 */
250}
251
252// End of page
253llxFooter();
254$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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage a WYSIWYG editor.
Create($noprint=0, $morejs='', $disallowAnyContent=true, $titlecontent='', $option='', $moreparam='', $morecss='')
Output edit area inside the HTML stream.
show_skin($fuser, $edit=0)
Show list of ckeditor's themes.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.