dolibarr  9.0.0
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-20113 Juanjo Menent <jmenent@2byte.es>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('admin', 'fckeditor'));
33 
34 $action = GETPOST('action','alpha');
35 // Possible modes are:
36 // dolibarr_details
37 // dolibarr_notes
38 // dolibarr_readonly
39 // dolibarr_mailings
40 // Full (not sure this one is used)
41 $mode=GETPOST('mode')?GETPOST('mode','alpha'):'dolibarr_notes';
42 
43 if (!$user->admin) accessforbidden();
44 
45 // Constante et traduction de la description du module
46 $modules = array(
47 'SOCIETE' => 'FCKeditorForCompany',
48 'PRODUCTDESC' => 'FCKeditorForProduct',
49 'DETAILS' => 'FCKeditorForProductDetails',
50 'USERSIGN' => 'FCKeditorForUserSignature',
51 'MAILING' => 'FCKeditorForMailing',
52 'MAIL' => 'FCKeditorForMail'
53 );
54 // Conditions pour que l'option soit proposee
55 $conditions = array(
56 'SOCIETE' => 1,
57 'PRODUCTDESC' => (! empty($conf->product->enabled) || ! empty($conf->service->enabled)),
58 'DETAILS' => (! empty($conf->facture->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled) || ! empty($conf->supplier_proposal->enabled) || ! empty($conf->fournisseur->enabled)),
59 'USERSIGN' => 1,
60 'MAILING' => ! empty($conf->mailing->enabled),
61 'MAIL' => (! empty($conf->facture->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled))
62 );
63 // Picto
64 $picto = array(
65 'SOCIETE' => 'generic',
66 'PRODUCTDESC' => 'product',
67 'DETAILS' => 'product',
68 'USERSIGN' => 'user',
69 'MAILING' => 'email',
70 'MAIL' => 'email'
71 );
72 
73 
74 
75 /*
76  * Actions
77  */
78 
79 foreach($modules as $const => $desc)
80 {
81  if ($action == 'activate_'.strtolower($const))
82  {
83  dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1",'chaine',0,'',$conf->entity);
84  // Si fckeditor est active dans la description produit/service, on l'active dans les formulaires
85  if ($const == 'PRODUCTDESC' && ! empty($conf->global->PRODUIT_DESC_IN_FORM))
86  {
87  dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1",'chaine',0,'',$conf->entity);
88  }
89  header("Location: ".$_SERVER["PHP_SELF"]);
90  exit;
91  }
92  if ($action == 'disable_'.strtolower($const))
93  {
94  dolibarr_del_const($db, "FCKEDITOR_ENABLE_".$const,$conf->entity);
95  header("Location: ".$_SERVER["PHP_SELF"]);
96  exit;
97  }
98 }
99 
100 if (GETPOST('save','alpha'))
101 {
102  $error = 0;
103 
104  $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
105  if (! empty($fckeditor_skin)) {
106  if (! dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity)) {
107  $error ++;
108  }
109  } else {
110  $error ++;
111  }
112 
113  $fckeditor_test = GETPOST('formtestfield');
114  if (! empty($fckeditor_test)) {
115  if (! dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity)) {
116  $error ++;
117  }
118  } else {
119  $error ++;
120  }
121 
122  if (! $error)
123  {
124  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
125  }
126  else
127  {
128  setEventMessages($langs->trans("Error"), null, 'errors');
129  }
130 }
131 
132 /*
133  * View
134  */
135 
136 llxHeader();
137 
138 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
139 print load_fiche_titre($langs->trans("AdvancedEditor"),$linkback,'title_setup');
140 print '<br>';
141 
142 if (empty($conf->use_javascript_ajax))
143 {
144  setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
145 }
146 else
147 {
148  print '<table class="noborder" width="100%">';
149  print '<tr class="liste_titre">';
150  print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
151  print '<td align="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 align="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  }
170  else if ($value == 1)
171  {
172  print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
173  }
174 
175  print "</td>";
176  print '</tr>';
177  }
178 
179  print '</table>'."\n";
180 
181  print '<br>'."\n";
182 
183  print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
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');
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  $uselocalbrowser=true;
204  $readonly=($mode=='dolibarr_readonly'?1:0);
205  $editor=new DolEditor('formtestfield',isset($conf->global->FCKEDITOR_TEST)?$conf->global->FCKEDITOR_TEST:'Test','',200,$mode,'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
206  $editor->Create();
207  print '<br><div class="center"><input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"></div>'."\n";
208  print '<div id="divforlog"></div>';
209  print '</form>'."\n";
210 
211  // Add env of ckeditor
212  // This is to show how CKEditor detect browser to understand why editor is disabled or not
213  if (1 == 2) // Change this to enable output
214  {
215  print '<br><script language="javascript">
216  function jsdump(obj, id) {
217  var out = \'\';
218  for (var i in obj) {
219  out += i + ": " + obj[i] + "<br>\n";
220  }
221 
222  jQuery("#"+id).html(out);
223  }
224 
225  jsdump(CKEDITOR.env, "divforlog");
226  </script>';
227  }
228 
229  /*
230  print '<!-- Result -->';
231  print $_POST["formtestfield"];
232  print '<!-- Result -->';
233  print $conf->global->FCKEDITOR_TEST;
234  */
235 }
236 
237 // End of page
238 llxFooter();
239 $db->close();
show_skin($fuser, $edit=0)
Show list of ckeditor&#39;s themes.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:510
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage a WYSIWYG editor.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)