dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("admin");
32 $langs->load("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">'.$langs->trans("BackToModuleList").'</a>';
139 print load_fiche_titre($langs->trans("AdvancedEditor"),$linkback,'title_setup');
140 print '<br>';
141 
142 $var=true;
143 
144 if (empty($conf->use_javascript_ajax))
145 {
146  setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
147 }
148 else
149 {
150  print '<table class="noborder" width="100%">';
151  print '<tr class="liste_titre">';
152  print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
153  print '<td align="center" width="100">'.$langs->trans("Action").'</td>';
154  print "</tr>\n";
155 
156  // Modules
157  foreach($modules as $const => $desc)
158  {
159  // Si condition non remplie, on ne propose pas l'option
160  if (! $conditions[$const]) continue;
161 
162 
163  print '<tr class="oddeven">';
164  print '<td width="16">'.img_object("",$picto[$const]).'</td>';
165  print '<td>'.$langs->trans($desc).'</td>';
166  print '<td align="center" width="100">';
167  $constante = 'FCKEDITOR_ENABLE_'.$const;
168  $value = (isset($conf->global->$constante)?$conf->global->$constante:0);
169  if ($value == 0)
170  {
171  print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate_'.strtolower($const).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
172  }
173  else if ($value == 1)
174  {
175  print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
176  }
177 
178  print "</td>";
179  print '</tr>';
180  }
181 
182  print '</table>'."\n";
183 
184  print '<br>'."\n";
185 
186  print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
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');
193  $linkstomode='';
194  foreach($listofmodes as $newmode)
195  {
196  if ($linkstomode) $linkstomode.=' - ';
197  $linkstomode.='<a href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
198  if ($mode == $newmode) $linkstomode.='<strong>';
199  $linkstomode.=$newmode;
200  if ($mode == $newmode) $linkstomode.='</strong>';
201  $linkstomode.='</a>';
202  }
203  $linkstomode.='';
204  print load_fiche_titre($langs->trans("TestSubmitForm"),$linkstomode,'');
205  print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
206  $uselocalbrowser=true;
207  $readonly=($mode=='dolibarr_readonly'?1:0);
208  $editor=new DolEditor('formtestfield',isset($conf->global->FCKEDITOR_TEST)?$conf->global->FCKEDITOR_TEST:'Test','',200,$mode,'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
209  $editor->Create();
210  print '<br><div class="center"><input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"></div>'."\n";
211  print '<div id="divforlog"></div>';
212  print '</form>'."\n";
213 
214  // Add env of ckeditor
215  // This is to show how CKEditor detect browser to understand why editor is disabled or not
216  if (1 == 2) // Change this to enable output
217  {
218  print '<br><script language="javascript">
219  function jsdump(obj, id) {
220  var out = \'\';
221  for (var i in obj) {
222  out += i + ": " + obj[i] + "<br>\n";
223  }
224 
225  jQuery("#"+id).html(out);
226  }
227 
228  jsdump(CKEDITOR.env, "divforlog");
229  </script>';
230  }
231 
232  /*
233  print '<!-- Result -->';
234  print $_POST["formtestfield"];
235  print '<!-- Result -->';
236  print $conf->global->FCKEDITOR_TEST;
237  */
238 }
239 
240 
241 llxFooter();
242 $db->close();
show_skin($fuser, $edit=0)
Show list of ckeditor's themes.
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
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:485
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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'une constante dans la base de donnees.
Definition: admin.lib.php:410
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
Class to manage a WYSIWYG editor.