fckeditor.php 8.1 KB

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