dolibarr  19.0.0-dev
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
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
31 require_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 
45 if (!$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 );
61 // Conditions for the option to be offered
62 $conditions = array(
63  'NOTE_PUBLIC' => 1,
64  'NOTE_PRIVATE' => 1,
65  'SOCIETE' => 1,
66  'PRODUCTDESC' => (isModEnabled("product") || isModEnabled("service")),
67  'DETAILS' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
68  'USERSIGN' => 1,
69  'MAILING' => isModEnabled('mailing'),
70  'MAIL' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande')),
71  'TICKET' => isModEnabled('ticket'),
72 );
73 // Picto
74 $picto = array(
75  'NOTE_PUBLIC' => 'generic',
76  'NOTE_PRIVATE' => 'generic',
77  'SOCIETE' => 'generic',
78  'PRODUCTDESC' => 'product',
79  'DETAILS' => 'product',
80  'USERSIGN' => 'user',
81  'MAILING' => 'email',
82  'MAIL' => 'email',
83  'TICKET' => 'ticket',
84 );
85 
86 
87 
88 /*
89  * Actions
90  */
91 
92 foreach ($modules as $const => $desc) {
93  if ($action == 'enable_'.strtolower($const)) {
94  dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
95  // If fckeditor is active in the product/service description, it is activated in the forms
96  if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
97  dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
98  }
99  header("Location: ".$_SERVER["PHP_SELF"]);
100  exit;
101  }
102  if ($action == 'disable_'.strtolower($const)) {
103  dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
104  header("Location: ".$_SERVER["PHP_SELF"]);
105  exit;
106  }
107 }
108 
109 if (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 
143 llxHeader();
144 
145 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
146 print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
147 print '<br>';
148 
149 if (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 = (isset($conf->global->$constante) ? $conf->global->$constante : 0);
177  if ($value == 0) {
178  print '<a 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 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
253 llxFooter();
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).
Definition: admin.lib.php:638
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage a WYSIWYG editor.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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 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)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.