dolibarr  16.0.5
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 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('admin', 'fckeditor'));
34 
35 $action = GETPOST('action', 'aZ09');
36 // Possible modes are:
37 // dolibarr_details
38 // dolibarr_notes
39 // dolibarr_readonly
40 // dolibarr_mailings
41 // Full (not sure this one is used)
42 $mode = GETPOST('mode') ?GETPOST('mode', 'alpha') : 'dolibarr_notes';
43 
44 if (!$user->admin) {
46 }
47 
48 // Constant and translation of the module description
49 $modules = array(
50  'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
51  'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
52  'SOCIETE' => 'FCKeditorForCompany',
53  'PRODUCTDESC' => 'FCKeditorForProduct',
54  'DETAILS' => 'FCKeditorForProductDetails',
55  'USERSIGN' => 'FCKeditorForUserSignature',
56  'MAILING' => 'FCKeditorForMailing',
57  'MAIL' => 'FCKeditorForMail',
58  'TICKET' => 'FCKeditorForTicket',
59 );
60 // Conditions for the option to be offered
61 $conditions = array(
62  'NOTE_PUBLIC' => 1,
63  'NOTE_PRIVATE' => 1,
64  'SOCIETE' => 1,
65  'PRODUCTDESC' => (!empty($conf->product->enabled) || !empty($conf->service->enabled)),
66  'DETAILS' => (isModEnabled('facture') || !empty($conf->propal->enabled) || !empty($conf->commande->enabled) || !empty($conf->supplier_proposal->enabled) || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)),
67  'USERSIGN' => 1,
68  'MAILING' => !empty($conf->mailing->enabled),
69  'MAIL' => (isModEnabled('facture') || !empty($conf->propal->enabled) || !empty($conf->commande->enabled)),
70  'TICKET' => !empty($conf->ticket->enabled),
71 );
72 // Picto
73 $picto = array(
74  'NOTE_PUBLIC' => 'generic',
75  'NOTE_PRIVATE' => 'generic',
76  'SOCIETE' => 'generic',
77  'PRODUCTDESC' => 'product',
78  'DETAILS' => 'product',
79  'USERSIGN' => 'user',
80  'MAILING' => 'email',
81  'MAIL' => 'email',
82  'TICKET' => 'ticket',
83 );
84 
85 
86 
87 /*
88  * Actions
89  */
90 
91 foreach ($modules as $const => $desc) {
92  if ($action == 'enable_'.strtolower($const)) {
93  dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
94  // If fckeditor is active in the product/service description, it is activated in the forms
95  if ($const == 'PRODUCTDESC' && !empty($conf->global->PRODUIT_DESC_IN_FORM)) {
96  dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
97  }
98  header("Location: ".$_SERVER["PHP_SELF"]);
99  exit;
100  }
101  if ($action == 'disable_'.strtolower($const)) {
102  dolibarr_del_const($db, "FCKEDITOR_ENABLE_".$const, $conf->entity);
103  header("Location: ".$_SERVER["PHP_SELF"]);
104  exit;
105  }
106 }
107 
108 if (GETPOST('save', 'alpha')) {
109  $error = 0;
110 
111  $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
112  if (!empty($fckeditor_skin)) {
113  $result = dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity);
114  if ($result <= 0) {
115  $error++;
116  }
117  } else {
118  $error++;
119  }
120 
121  $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
122  if (!empty($fckeditor_test)) {
123  $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
124  if ($result <= 0) {
125  $error++;
126  }
127  } else {
128  $error++;
129  }
130 
131  if (!$error) {
132  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
133  } else {
134  setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
135  }
136 }
137 
138 /*
139  * View
140  */
141 
142 llxHeader();
143 
144 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
145 print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
146 print '<br>';
147 
148 if (empty($conf->use_javascript_ajax)) {
149  setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
150 } else {
151  print '<table class="noborder centpercent">';
152  print '<tr class="liste_titre">';
153  print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
154  print '<td class="center" width="100">'.$langs->trans("Action").'</td>';
155  print "</tr>\n";
156 
157  // Modules
158  foreach ($modules as $const => $desc) {
159  // If this condition is not met, the option is not offered
160  if (!$conditions[$const]) {
161  continue;
162  }
163 
164  $constante = 'FCKEDITOR_ENABLE_'.$const;
165  print '<!-- constant = '.$constante.' -->'."\n";
166  print '<tr class="oddeven">';
167  print '<td width="16">'.img_object("", $picto[$const]).'</td>';
168  print '<td>'.$langs->trans($desc).'</td>';
169  print '<td class="center" width="100">';
170  $value = (isset($conf->global->$constante) ? $conf->global->$constante : 0);
171  if ($value == 0) {
172  print '<a href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
173  } elseif ($value == 1) {
174  print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
175  }
176 
177  print "</td>";
178  print '</tr>';
179  }
180 
181  print '</table>'."\n";
182 
183  print '<br>'."\n";
184 
185  print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
186  print '<input type="hidden" name="token" value="'.newToken().'">';
187 
188  // Skins
189  show_skin(null, 1);
190  print '<br>'."\n";
191 
192  $listofmodes = array('dolibarr_mailings', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_readonly', 'Full', 'Full_inline');
193  $linkstomode = '';
194  foreach ($listofmodes as $newmode) {
195  if ($linkstomode) {
196  $linkstomode .= ' - ';
197  }
198  $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
199  if ($mode == $newmode) {
200  $linkstomode .= '<strong>';
201  }
202  $linkstomode .= $newmode;
203  if ($mode == $newmode) {
204  $linkstomode .= '</strong>';
205  }
206  $linkstomode .= '</a>';
207  }
208  $linkstomode .= '';
209  print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
210  print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
211  if ($mode != 'Full_inline') {
212  $uselocalbrowser = true;
213  $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
214  $editor = new DolEditor('formtestfield', isset($conf->global->FCKEDITOR_TEST) ? $conf->global->FCKEDITOR_TEST : 'Test', '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
215  $editor->Create();
216  } else {
217  print '<div style="border: 1px solid #888;" contenteditable="true">';
218  print $conf->global->FCKEDITOR_TEST;
219  print '</div>';
220  }
221  print $form->buttonsSaveCancel("Save", '');
222  print '<div id="divforlog"></div>';
223  print '</form>'."\n";
224 
225  // Add env of ckeditor
226  // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
227  /*
228  print '<br><script type="text/javascript">
229  function jsdump(obj, id) {
230  var out = \'\';
231  for (var i in obj) {
232  out += i + ": " + obj[i] + "<br>\n";
233  }
234 
235  jQuery("#"+id).html(out);
236  }
237 
238  jsdump(CKEDITOR.env, "divforlog");
239  </script>';
240  }
241  */
242 }
243 
244 // End of page
245 llxFooter();
246 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
show_skin
show_skin($fuser, $edit=0)
Show list of ckeditor's themes.
Definition: doleditor.lib.php:34
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolibarr_set_const
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:627
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30