fckeditor.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  122. print load_fiche_titre($langs->trans("AdvancedEditor"),$linkback,'title_setup');
  123. print '<br>';
  124. if (empty($conf->use_javascript_ajax))
  125. {
  126. setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
  127. }
  128. else
  129. {
  130. print '<table class="noborder" width="100%">';
  131. print '<tr class="liste_titre">';
  132. print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
  133. print '<td align="center" width="100">'.$langs->trans("Action").'</td>';
  134. print "</tr>\n";
  135. // Modules
  136. foreach($modules as $const => $desc)
  137. {
  138. // Si condition non remplie, on ne propose pas l'option
  139. if (! $conditions[$const]) continue;
  140. print '<tr class="oddeven">';
  141. print '<td width="16">'.img_object("",$picto[$const]).'</td>';
  142. print '<td>'.$langs->trans($desc).'</td>';
  143. print '<td align="center" width="100">';
  144. $constante = 'FCKEDITOR_ENABLE_'.$const;
  145. $value = (isset($conf->global->$constante)?$conf->global->$constante:0);
  146. if ($value == 0)
  147. {
  148. print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate_'.strtolower($const).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  149. }
  150. else if ($value == 1)
  151. {
  152. print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  153. }
  154. print "</td>";
  155. print '</tr>';
  156. }
  157. print '</table>'."\n";
  158. print '<br>'."\n";
  159. print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  160. // Skins
  161. show_skin(null,1);
  162. print '<br>'."\n";
  163. $listofmodes=array('dolibarr_mailings','dolibarr_notes','dolibarr_details','dolibarr_readonly','Full');
  164. $linkstomode='';
  165. foreach($listofmodes as $newmode)
  166. {
  167. if ($linkstomode) $linkstomode.=' - ';
  168. $linkstomode.='<a href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
  169. if ($mode == $newmode) $linkstomode.='<strong>';
  170. $linkstomode.=$newmode;
  171. if ($mode == $newmode) $linkstomode.='</strong>';
  172. $linkstomode.='</a>';
  173. }
  174. $linkstomode.='';
  175. print load_fiche_titre($langs->trans("TestSubmitForm"),$linkstomode,'');
  176. print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
  177. $uselocalbrowser=true;
  178. $readonly=($mode=='dolibarr_readonly'?1:0);
  179. $editor=new DolEditor('formtestfield',isset($conf->global->FCKEDITOR_TEST)?$conf->global->FCKEDITOR_TEST:'Test','',200,$mode,'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
  180. $editor->Create();
  181. print '<br><div class="center"><input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"></div>'."\n";
  182. print '<div id="divforlog"></div>';
  183. print '</form>'."\n";
  184. // Add env of ckeditor
  185. // This is to show how CKEditor detect browser to understand why editor is disabled or not
  186. if (1 == 2) // Change this to enable output
  187. {
  188. print '<br><script language="javascript">
  189. function jsdump(obj, id) {
  190. var out = \'\';
  191. for (var i in obj) {
  192. out += i + ": " + obj[i] + "<br>\n";
  193. }
  194. jQuery("#"+id).html(out);
  195. }
  196. jsdump(CKEDITOR.env, "divforlog");
  197. </script>';
  198. }
  199. /*
  200. print '<!-- Result -->';
  201. print $_POST["formtestfield"];
  202. print '<!-- Result -->';
  203. print $conf->global->FCKEDITOR_TEST;
  204. */
  205. }
  206. llxFooter();
  207. $db->close();