fckeditor.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. /**
  20. * \file htdocs/admin/fckeditor.php
  21. * \ingroup fckeditor
  22. * \brief Page d'activation du module FCKeditor dans les autres modules
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/doleditor.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  28. $langs->load("admin");
  29. $langs->load("fckeditor");
  30. $action = GETPOST('action','alpha');
  31. // Possible modes are:
  32. // dolibarr_details
  33. // dolibarr_notes
  34. // dolibarr_readonly
  35. // dolibarr_mailings
  36. // Full (not sure this one is used)
  37. $mode=GETPOST('mode')?GETPOST('mode','alpha'):'dolibarr_notes';
  38. if (!$user->admin) accessforbidden();
  39. // Constante et traduction de la description du module
  40. $modules = array(
  41. 'SOCIETE' => 'FCKeditorForCompany',
  42. 'PRODUCTDESC' => 'FCKeditorForProduct',
  43. 'DETAILS' => 'FCKeditorForProductDetails',
  44. 'USERSIGN' => 'FCKeditorForUserSignature',
  45. 'MAILING' => 'FCKeditorForMailing',
  46. 'MAIL' => 'FCKeditorForMail'
  47. );
  48. // Conditions pour que l'option soit proposee
  49. $conditions = array(
  50. 'SOCIETE' => 1,
  51. 'PRODUCTDESC' => (! empty($conf->product->enabled) || ! empty($conf->service->enabled)),
  52. 'DETAILS' => (! empty($conf->facture->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled) || ! empty($conf->supplier_proposal->enabled) || ! empty($conf->fournisseur->enabled)),
  53. 'USERSIGN' => 1,
  54. 'MAILING' => ! empty($conf->mailing->enabled),
  55. 'MAIL' => (! empty($conf->facture->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled))
  56. );
  57. // Picto
  58. $picto = array(
  59. 'SOCIETE' => 'generic',
  60. 'PRODUCTDESC' => 'product',
  61. 'DETAILS' => 'product',
  62. 'USERSIGN' => 'user',
  63. 'MAILING' => 'email',
  64. 'MAIL' => 'email'
  65. );
  66. /*
  67. * Actions
  68. */
  69. foreach($modules as $const => $desc)
  70. {
  71. if ($action == 'activate_'.strtolower($const))
  72. {
  73. dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1",'chaine',0,'',$conf->entity);
  74. // Si fckeditor est active dans la description produit/service, on l'active dans les formulaires
  75. if ($const == 'PRODUCTDESC' && ! empty($conf->global->PRODUIT_DESC_IN_FORM))
  76. {
  77. dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1",'chaine',0,'',$conf->entity);
  78. }
  79. header("Location: ".$_SERVER["PHP_SELF"]);
  80. exit;
  81. }
  82. if ($action == 'disable_'.strtolower($const))
  83. {
  84. dolibarr_del_const($db, "FCKEDITOR_ENABLE_".$const,$conf->entity);
  85. header("Location: ".$_SERVER["PHP_SELF"]);
  86. exit;
  87. }
  88. }
  89. if (GETPOST('save','alpha'))
  90. {
  91. $error = 0;
  92. $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
  93. if (! empty($fckeditor_skin)) {
  94. if (! dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity)) {
  95. $error ++;
  96. }
  97. } else {
  98. $error ++;
  99. }
  100. $fckeditor_test = GETPOST('formtestfield');
  101. if (! empty($fckeditor_test)) {
  102. if (! dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity)) {
  103. $error ++;
  104. }
  105. } else {
  106. $error ++;
  107. }
  108. if (! $error)
  109. {
  110. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  111. }
  112. else
  113. {
  114. setEventMessages($langs->trans("Error"), null, 'errors');
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. llxHeader();
  121. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  122. print load_fiche_titre($langs->trans("AdvancedEditor"),$linkback,'title_setup');
  123. print '<br>';
  124. $var=true;
  125. if (empty($conf->use_javascript_ajax))
  126. {
  127. setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
  128. }
  129. else
  130. {
  131. print '<table class="noborder" width="100%">';
  132. print '<tr class="liste_titre">';
  133. print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
  134. print '<td align="center" width="100">'.$langs->trans("Action").'</td>';
  135. print "</tr>\n";
  136. // Modules
  137. foreach($modules as $const => $desc)
  138. {
  139. // Si condition non remplie, on ne propose pas l'option
  140. if (! $conditions[$const]) continue;
  141. print '<tr class="oddeven">';
  142. print '<td width="16">'.img_object("",$picto[$const]).'</td>';
  143. print '<td>'.$langs->trans($desc).'</td>';
  144. print '<td align="center" width="100">';
  145. $constante = 'FCKEDITOR_ENABLE_'.$const;
  146. $value = (isset($conf->global->$constante)?$conf->global->$constante:0);
  147. if ($value == 0)
  148. {
  149. print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate_'.strtolower($const).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  150. }
  151. else if ($value == 1)
  152. {
  153. print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  154. }
  155. print "</td>";
  156. print '</tr>';
  157. }
  158. print '</table>'."\n";
  159. print '<br>'."\n";
  160. print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  161. // Skins
  162. show_skin(null,1);
  163. print '<br>'."\n";
  164. $listofmodes=array('dolibarr_mailings','dolibarr_notes','dolibarr_details','dolibarr_readonly','Full');
  165. $linkstomode='';
  166. foreach($listofmodes as $newmode)
  167. {
  168. if ($linkstomode) $linkstomode.=' - ';
  169. $linkstomode.='<a href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
  170. if ($mode == $newmode) $linkstomode.='<strong>';
  171. $linkstomode.=$newmode;
  172. if ($mode == $newmode) $linkstomode.='</strong>';
  173. $linkstomode.='</a>';
  174. }
  175. $linkstomode.='';
  176. print load_fiche_titre($langs->trans("TestSubmitForm"),$linkstomode,'');
  177. print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
  178. $uselocalbrowser=true;
  179. $readonly=($mode=='dolibarr_readonly'?1:0);
  180. $editor=new DolEditor('formtestfield',isset($conf->global->FCKEDITOR_TEST)?$conf->global->FCKEDITOR_TEST:'Test','',200,$mode,'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
  181. $editor->Create();
  182. print '<br><div class="center"><input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"></div>'."\n";
  183. print '<div id="divforlog"></div>';
  184. print '</form>'."\n";
  185. // Add env of ckeditor
  186. // This is to show how CKEditor detect browser to understand why editor is disabled or not
  187. if (1 == 2) // Change this to enable output
  188. {
  189. print '<br><script language="javascript">
  190. function jsdump(obj, id) {
  191. var out = \'\';
  192. for (var i in obj) {
  193. out += i + ": " + obj[i] + "<br>\n";
  194. }
  195. jQuery("#"+id).html(out);
  196. }
  197. jsdump(CKEDITOR.env, "divforlog");
  198. </script>';
  199. }
  200. /*
  201. print '<!-- Result -->';
  202. print $_POST["formtestfield"];
  203. print '<!-- Result -->';
  204. print $conf->global->FCKEDITOR_TEST;
  205. */
  206. }
  207. llxFooter();
  208. $db->close();