dolibarr  13.0.2
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) accessforbidden();
45 
46 // Constante et traduction de la description du module
47 $modules = array(
48 'SOCIETE' => 'FCKeditorForCompany',
49 'PRODUCTDESC' => 'FCKeditorForProduct',
50 'DETAILS' => 'FCKeditorForProductDetails',
51 'USERSIGN' => 'FCKeditorForUserSignature',
52 'MAILING' => 'FCKeditorForMailing',
53 'MAIL' => 'FCKeditorForMail',
54 'TICKET' => 'FCKeditorForTicket'
55 );
56 // Conditions pour que l'option soit proposee
57 $conditions = array(
58 'SOCIETE' => 1,
59 'PRODUCTDESC' => (!empty($conf->product->enabled) || !empty($conf->service->enabled)),
60 'DETAILS' => (!empty($conf->facture->enabled) || !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)),
61 'USERSIGN' => 1,
62 'MAILING' => !empty($conf->mailing->enabled),
63 'MAIL' => (!empty($conf->facture->enabled) || !empty($conf->propal->enabled) || !empty($conf->commande->enabled)),
64 'TICKET' => !empty($conf->ticket->enabled)
65 );
66 // Picto
67 $picto = array(
68 'SOCIETE' => 'generic',
69 'PRODUCTDESC' => 'product',
70 'DETAILS' => 'product',
71 'USERSIGN' => 'user',
72 'MAILING' => 'email',
73 'MAIL' => 'email',
74 'TICKET' => 'ticket'
75 );
76 
77 
78 
79 /*
80  * Actions
81  */
82 
83 foreach ($modules as $const => $desc)
84 {
85  if ($action == 'activate_'.strtolower($const))
86  {
87  dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
88  // Si fckeditor est active dans la description produit/service, on l'active dans les formulaires
89  if ($const == 'PRODUCTDESC' && !empty($conf->global->PRODUIT_DESC_IN_FORM))
90  {
91  dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
92  }
93  header("Location: ".$_SERVER["PHP_SELF"]);
94  exit;
95  }
96  if ($action == 'disable_'.strtolower($const))
97  {
98  dolibarr_del_const($db, "FCKEDITOR_ENABLE_".$const, $conf->entity);
99  header("Location: ".$_SERVER["PHP_SELF"]);
100  exit;
101  }
102 }
103 
104 if (GETPOST('save', 'alpha'))
105 {
106  $error = 0;
107 
108  $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
109  if (!empty($fckeditor_skin)) {
110  if (!dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity)) {
111  $error++;
112  }
113  } else {
114  $error++;
115  }
116 
117  $fckeditor_test = GETPOST('formtestfield');
118  if (!empty($fckeditor_test)) {
119  if (!dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity)) {
120  $error++;
121  }
122  } else {
123  $error++;
124  }
125 
126  if (!$error)
127  {
128  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
129  } else {
130  setEventMessages($langs->trans("Error"), null, 'errors');
131  }
132 }
133 
134 /*
135  * View
136  */
137 
138 llxHeader();
139 
140 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
141 print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
142 print '<br>';
143 
144 if (empty($conf->use_javascript_ajax))
145 {
146  setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
147 } else {
148  print '<table class="noborder centpercent">';
149  print '<tr class="liste_titre">';
150  print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
151  print '<td class="center" width="100">'.$langs->trans("Action").'</td>';
152  print "</tr>\n";
153 
154  // Modules
155  foreach ($modules as $const => $desc)
156  {
157  // Si condition non remplie, on ne propose pas l'option
158  if (!$conditions[$const]) continue;
159 
160  print '<tr class="oddeven">';
161  print '<td width="16">'.img_object("", $picto[$const]).'</td>';
162  print '<td>'.$langs->trans($desc).'</td>';
163  print '<td class="center" width="100">';
164  $constante = 'FCKEDITOR_ENABLE_'.$const;
165  $value = (isset($conf->global->$constante) ? $conf->global->$constante : 0);
166  if ($value == 0)
167  {
168  print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate_'.strtolower($const).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
169  } elseif ($value == 1)
170  {
171  print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
172  }
173 
174  print "</td>";
175  print '</tr>';
176  }
177 
178  print '</table>'."\n";
179 
180  print '<br>'."\n";
181 
182  print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
183  print '<input type="hidden" name="token" value="'.newToken().'">';
184 
185  // Skins
186  show_skin(null, 1);
187  print '<br>'."\n";
188 
189  $listofmodes = array('dolibarr_mailings', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_readonly', 'Full', 'Full_inline');
190  $linkstomode = '';
191  foreach ($listofmodes as $newmode)
192  {
193  if ($linkstomode) $linkstomode .= ' - ';
194  $linkstomode .= '<a href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
195  if ($mode == $newmode) $linkstomode .= '<strong>';
196  $linkstomode .= $newmode;
197  if ($mode == $newmode) $linkstomode .= '</strong>';
198  $linkstomode .= '</a>';
199  }
200  $linkstomode .= '';
201  print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
202  print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
203  if ($mode != 'Full_inline')
204  {
205  $uselocalbrowser = true;
206  $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
207  $editor = new DolEditor('formtestfield', isset($conf->global->FCKEDITOR_TEST) ? $conf->global->FCKEDITOR_TEST : 'Test', '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
208  $editor->Create();
209  } else {
210  print '<div style="border: 1px solid #888;" contenteditable="true">';
211  print $conf->global->FCKEDITOR_TEST;
212  print '</div>';
213  }
214  print '<br><div class="center"><input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'"></div>'."\n";
215  print '<div id="divforlog"></div>';
216  print '</form>'."\n";
217 
218  // Add env of ckeditor
219  // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
220  /*
221  print '<br><script language="javascript">
222  function jsdump(obj, id) {
223  var out = \'\';
224  for (var i in obj) {
225  out += i + ": " + obj[i] + "<br>\n";
226  }
227 
228  jQuery("#"+id).html(out);
229  }
230 
231  jsdump(CKEDITOR.env, "divforlog");
232  </script>';
233  }
234  */
235 }
236 
237 // End of page
238 llxFooter();
239 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
show_skin($fuser, $edit=0)
Show list of ckeditor&#39;s themes.
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:575
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:499
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59