fckeditor.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 Activation page for the FCKeditor module in the other modules
  24. */
  25. // Load Dolibarr environment
  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. // Load translation files required by the page
  31. $langs->loadLangs(array('admin', 'fckeditor'));
  32. $action = GETPOST('action', 'aZ09');
  33. // Possible modes are:
  34. // dolibarr_details
  35. // dolibarr_notes
  36. // dolibarr_readonly
  37. // dolibarr_mailings
  38. // Full (not sure this one is used)
  39. $mode = GETPOST('mode') ? GETPOST('mode', 'alpha') : 'dolibarr_notes';
  40. if (!$user->admin) {
  41. accessforbidden();
  42. }
  43. // Constant and translation of the module description
  44. $modules = array(
  45. 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
  46. 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
  47. 'SOCIETE' => 'FCKeditorForCompany',
  48. //'PRODUCTDESC' => 'FCKeditorForProduct',
  49. 'DETAILS' => 'FCKeditorForProductDetails',
  50. 'USERSIGN' => 'FCKeditorForUserSignature',
  51. 'MAILING' => 'FCKeditorForMailing',
  52. 'MAIL' => 'FCKeditorForMail',
  53. 'TICKET' => 'FCKeditorForTicket',
  54. 'SPECIALCHAR' => 'SpecialCharActivation',
  55. );
  56. // Conditions for the option to be offered
  57. $conditions = array(
  58. 'NOTE_PUBLIC' => 1,
  59. 'NOTE_PRIVATE' => 1,
  60. 'SOCIETE' => 1,
  61. 'PRODUCTDESC' => (isModEnabled("product") || isModEnabled("service")),
  62. 'DETAILS' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande') || isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
  63. 'USERSIGN' => 1,
  64. 'MAILING' => isModEnabled('mailing'),
  65. 'MAIL' => (isModEnabled('facture') || isModEnabled("propal") || isModEnabled('commande')),
  66. 'TICKET' => isModEnabled('ticket'),
  67. 'SPECIALCHAR' => 1,
  68. );
  69. // Picto
  70. $picto = array(
  71. 'NOTE_PUBLIC' => 'generic',
  72. 'NOTE_PRIVATE' => 'generic',
  73. 'SOCIETE' => 'generic',
  74. 'PRODUCTDESC' => 'product',
  75. 'DETAILS' => 'product',
  76. 'USERSIGN' => 'user',
  77. 'MAILING' => 'email',
  78. 'MAIL' => 'email',
  79. 'TICKET' => 'ticket',
  80. 'SPECIALCHAR' => 'generic'
  81. );
  82. /*
  83. * Actions
  84. */
  85. foreach ($modules as $const => $desc) {
  86. if ($action == 'enable_'.strtolower($const)) {
  87. dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
  88. // If fckeditor is active in the product/service description, it is activated in the forms
  89. if ($const == 'PRODUCTDESC' && getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
  90. dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
  91. }
  92. }
  93. if ($action == 'disable_'.strtolower($const)) {
  94. dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "0", 'chaine', 0, '', $conf->entity);
  95. }
  96. }
  97. if (GETPOST('save', 'alpha')) {
  98. $error = 0;
  99. $fckeditor_skin = GETPOST('fckeditor_skin', 'alpha');
  100. if (!empty($fckeditor_skin)) {
  101. $result = dolibarr_set_const($db, 'FCKEDITOR_SKIN', $fckeditor_skin, 'chaine', 0, '', $conf->entity);
  102. if ($result <= 0) {
  103. $error++;
  104. }
  105. } else {
  106. $error++;
  107. }
  108. $fckeditor_test = GETPOST('formtestfield', 'restricthtml');
  109. if (!empty($fckeditor_test)) {
  110. $result = dolibarr_set_const($db, 'FCKEDITOR_TEST', $fckeditor_test, 'chaine', 0, '', $conf->entity);
  111. if ($result <= 0) {
  112. $error++;
  113. }
  114. } else {
  115. $error++;
  116. }
  117. if (!$error) {
  118. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  119. } else {
  120. setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
  121. }
  122. }
  123. /*
  124. * View
  125. */
  126. llxHeader();
  127. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  128. print load_fiche_titre($langs->trans("AdvancedEditor"), $linkback, 'title_setup');
  129. print '<br>';
  130. if (empty($conf->use_javascript_ajax)) {
  131. setEventMessages(array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), null, 'errors');
  132. } else {
  133. print '<table class="noborder centpercent">';
  134. print '<tr class="liste_titre">';
  135. print '<td colspan="2">'.$langs->trans("ActivateFCKeditor").'</td>';
  136. print '<td class="center" width="100">'.$langs->trans("Action").'</td>';
  137. print "</tr>\n";
  138. // Modules
  139. foreach ($modules as $const => $desc) {
  140. // If this condition is not met, the option is not offered
  141. if (!$conditions[$const]) {
  142. continue;
  143. }
  144. $constante = 'FCKEDITOR_ENABLE_'.$const;
  145. print '<!-- constant = '.$constante.' -->'."\n";
  146. print '<tr class="oddeven">';
  147. print '<td class="width20">'.img_object("", $picto[$const]).'</td>';
  148. print '<td>';
  149. print $langs->trans($desc);
  150. if ($const == 'DETAILS') {
  151. print '<br><span class="warning">'.$langs->trans("FCKeditorForProductDetails2").'</span>';
  152. }
  153. print '</td>';
  154. print '<td class="center centpercent width100">';
  155. $value = getDolGlobalInt($constante, 0);
  156. if ($value == 0) {
  157. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  158. } elseif ($value == 1) {
  159. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  160. }
  161. print "</td>";
  162. print '</tr>';
  163. }
  164. print '</table>'."\n";
  165. print '<br>'."\n";
  166. print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  167. print '<input type="hidden" name="token" value="'.newToken().'">';
  168. print '<input type="hidden" name="page_y" value="">';
  169. // Skins
  170. show_skin(null, 1);
  171. print '<br>'."\n";
  172. $listofmodes = array('dolibarr_mailings', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_readonly', 'Full', 'Full_inline');
  173. $linkstomode = '';
  174. foreach ($listofmodes as $newmode) {
  175. if ($linkstomode) {
  176. $linkstomode .= ' - ';
  177. }
  178. $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
  179. if ($mode == $newmode) {
  180. $linkstomode .= '<strong>';
  181. }
  182. $linkstomode .= $newmode;
  183. if ($mode == $newmode) {
  184. $linkstomode .= '</strong>';
  185. }
  186. $linkstomode .= '</a>';
  187. }
  188. $linkstomode .= '';
  189. print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
  190. print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
  191. if ($mode != 'Full_inline') {
  192. $uselocalbrowser = true;
  193. $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
  194. $editor = new DolEditor('formtestfield', isset($conf->global->FCKEDITOR_TEST) ? $conf->global->FCKEDITOR_TEST : 'Test', '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
  195. $editor->Create();
  196. } else {
  197. // CKEditor inline enabled with the contenteditable="true"
  198. print '<div style="border: 1px solid #888;" contenteditable="true">';
  199. print $conf->global->FCKEDITOR_TEST;
  200. print '</div>';
  201. }
  202. print $form->buttonsSaveCancel("Save", '', null, 0, 'reposition');
  203. print '<div id="divforlog"></div>';
  204. print '</form>'."\n";
  205. // Add env of ckeditor
  206. // This is to show how CKEditor detect browser to understand why editor is disabled or not. To help debug.
  207. /*
  208. print '<br><script type="text/javascript">
  209. function jsdump(obj, id) {
  210. var out = \'\';
  211. for (var i in obj) {
  212. out += i + ": " + obj[i] + "<br>\n";
  213. }
  214. jQuery("#"+id).html(out);
  215. }
  216. jsdump(CKEDITOR.env, "divforlog");
  217. </script>';
  218. }
  219. */
  220. }
  221. // End of page
  222. llxFooter();
  223. $db->close();