fckeditor.php 8.0 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 Activation page for the FCKeditor module in the other 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', 'aZ09');
  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) {
  40. accessforbidden();
  41. }
  42. // Constant and translation of the module description
  43. $modules = array(
  44. 'NOTE_PUBLIC' => 'FCKeditorForNotePublic',
  45. 'NOTE_PRIVATE' => 'FCKeditorForNotePrivate',
  46. 'SOCIETE' => 'FCKeditorForCompany',
  47. 'PRODUCTDESC' => 'FCKeditorForProduct',
  48. 'DETAILS' => 'FCKeditorForProductDetails',
  49. 'USERSIGN' => 'FCKeditorForUserSignature',
  50. 'MAILING' => 'FCKeditorForMailing',
  51. 'MAIL' => 'FCKeditorForMail',
  52. 'TICKET' => 'FCKeditorForTicket',
  53. );
  54. // Conditions for the option to be offered
  55. $conditions = array(
  56. 'NOTE_PUBLIC' => 1,
  57. 'NOTE_PRIVATE' => 1,
  58. 'SOCIETE' => 1,
  59. 'PRODUCTDESC' => (!empty($conf->product->enabled) || !empty($conf->service->enabled)),
  60. 'DETAILS' => (isModEnabled('facture') || !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)),
  61. 'USERSIGN' => 1,
  62. 'MAILING' => !empty($conf->mailing->enabled),
  63. 'MAIL' => (isModEnabled('facture') || !empty($conf->propal->enabled) || !empty($conf->commande->enabled)),
  64. 'TICKET' => !empty($conf->ticket->enabled),
  65. );
  66. // Picto
  67. $picto = array(
  68. 'NOTE_PUBLIC' => 'generic',
  69. 'NOTE_PRIVATE' => 'generic',
  70. 'SOCIETE' => 'generic',
  71. 'PRODUCTDESC' => 'product',
  72. 'DETAILS' => 'product',
  73. 'USERSIGN' => 'user',
  74. 'MAILING' => 'email',
  75. 'MAIL' => 'email',
  76. 'TICKET' => 'ticket',
  77. );
  78. /*
  79. * Actions
  80. */
  81. foreach ($modules as $const => $desc) {
  82. if ($action == 'enable_'.strtolower($const)) {
  83. dolibarr_set_const($db, "FCKEDITOR_ENABLE_".$const, "1", 'chaine', 0, '', $conf->entity);
  84. // If fckeditor is active in the product/service description, it is activated in the forms
  85. if ($const == 'PRODUCTDESC' && !empty($conf->global->PRODUIT_DESC_IN_FORM)) {
  86. dolibarr_set_const($db, "FCKEDITOR_ENABLE_DETAILS", "1", 'chaine', 0, '', $conf->entity);
  87. }
  88. header("Location: ".$_SERVER["PHP_SELF"]);
  89. exit;
  90. }
  91. if ($action == 'disable_'.strtolower($const)) {
  92. dolibarr_del_const($db, "FCKEDITOR_ENABLE_".$const, $conf->entity);
  93. header("Location: ".$_SERVER["PHP_SELF"]);
  94. exit;
  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 width="16">'.img_object("", $picto[$const]).'</td>';
  148. print '<td>'.$langs->trans($desc).'</td>';
  149. print '<td class="center" width="100">';
  150. $value = (isset($conf->global->$constante) ? $conf->global->$constante : 0);
  151. if ($value == 0) {
  152. print '<a href="'.$_SERVER['PHP_SELF'].'?action=enable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  153. } elseif ($value == 1) {
  154. print '<a href="'.$_SERVER['PHP_SELF'].'?action=disable_'.strtolower($const).'&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  155. }
  156. print "</td>";
  157. print '</tr>';
  158. }
  159. print '</table>'."\n";
  160. print '<br>'."\n";
  161. print '<form name="formtest" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  162. print '<input type="hidden" name="token" value="'.newToken().'">';
  163. // Skins
  164. show_skin(null, 1);
  165. print '<br>'."\n";
  166. $listofmodes = array('dolibarr_mailings', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_readonly', 'Full', 'Full_inline');
  167. $linkstomode = '';
  168. foreach ($listofmodes as $newmode) {
  169. if ($linkstomode) {
  170. $linkstomode .= ' - ';
  171. }
  172. $linkstomode .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode='.$newmode.'">';
  173. if ($mode == $newmode) {
  174. $linkstomode .= '<strong>';
  175. }
  176. $linkstomode .= $newmode;
  177. if ($mode == $newmode) {
  178. $linkstomode .= '</strong>';
  179. }
  180. $linkstomode .= '</a>';
  181. }
  182. $linkstomode .= '';
  183. print load_fiche_titre($langs->trans("TestSubmitForm"), $linkstomode, '');
  184. print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
  185. if ($mode != 'Full_inline') {
  186. $uselocalbrowser = true;
  187. $readonly = ($mode == 'dolibarr_readonly' ? 1 : 0);
  188. $editor = new DolEditor('formtestfield', isset($conf->global->FCKEDITOR_TEST) ? $conf->global->FCKEDITOR_TEST : 'Test', '', 200, $mode, 'In', true, $uselocalbrowser, 1, 120, 8, $readonly);
  189. $editor->Create();
  190. } else {
  191. print '<div style="border: 1px solid #888;" contenteditable="true">';
  192. print $conf->global->FCKEDITOR_TEST;
  193. print '</div>';
  194. }
  195. print $form->buttonsSaveCancel("Save", '');
  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. To help debug.
  200. /*
  201. print '<br><script type="text/javascript">
  202. function jsdump(obj, id) {
  203. var out = \'\';
  204. for (var i in obj) {
  205. out += i + ": " + obj[i] + "<br>\n";
  206. }
  207. jQuery("#"+id).html(out);
  208. }
  209. jsdump(CKEDITOR.env, "divforlog");
  210. </script>';
  211. }
  212. */
  213. }
  214. // End of page
  215. llxFooter();
  216. $db->close();