Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: add css editor to admin ihm #23944

Merged
merged 3 commits into from Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 32 additions & 2 deletions htdocs/admin/ihm.php
Expand Up @@ -6,6 +6,7 @@
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2021 Anthony Berton <bertonanthony@gmail.com>
* Copyright (C) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -298,6 +299,11 @@
}
}

if ($mode == 'css') {
$data = GETPOST('CUSTOM_CSS', 'none');
file_put_contents(DOL_DATA_ROOT.'/admin/customcss.css', $data);
}

$_SESSION["mainmenu"] = ""; // The menu manager may have changed

if (GETPOST('dol_resetcache')) {
Expand All @@ -314,7 +320,13 @@
*/

$wikihelp = 'EN:First_setup|FR:Premiers_param&eacute;trages|ES:Primeras_configuraciones';
llxHeader('', $langs->trans("Setup"), $wikihelp);

llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0,
array(
'/includes/ace/src/ace.js',
'/includes/ace/src/ext-statusbar.js',
'/includes/ace/src/ext-language_tools.js',
), array());

$form = new Form($db);
$formother = new FormOther($db);
Expand Down Expand Up @@ -679,8 +691,26 @@
print '</div>';
}

if ($mode == 'css') {
print '<div class="div-table-responsive-no-min">';
print '<table summary="edit" class="noborder centpercent editmode tableforfield">';

print '<tr class="liste_titre">';
print '<td colspan="2">';

$customcssValue = file_get_contents(DOL_DATA_ROOT.'/admin/customcss.css');

$doleditor = new DolEditor('CUSTOM_CSS', $customcssValue, '', 400, 'Basic', 'In', false, true, 'ace', 80, 80, 0);
$doleditor->Create(0, '', true, 'css', 'css');
print '</td></tr>'."\n";

print '</table>'."\n";
print '</div>';
}


print '<div class="center">';
print '<input class="button button-save reposition" type="submit" name="submit" value="' . $langs->trans("Save") . '">';
print '<input class="button button-save reposition buttonforacesave" type="submit" name="submit" value="' . $langs->trans("Save") . '">';
print '<input class="button button-cancel reposition" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
print '</div>';

Expand Down
6 changes: 6 additions & 0 deletions htdocs/core/lib/admin.lib.php
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -772,6 +773,11 @@ function ihm_prepare_head()
$head[$h][2] = 'login';
$h++;

$head[$h][0] = DOL_URL_ROOT."/admin/ihm.php?mode=css";
$head[$h][1] = $langs->trans("CSSPage");
$head[$h][2] = 'css';
$h++;

complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin');

complete_head_from_modules($conf, $langs, null, $head, $h, 'ihm_admin', 'remove');
Expand Down
4 changes: 3 additions & 1 deletion htdocs/langs/en_US/admin.lang
Expand Up @@ -2372,4 +2372,6 @@ WarningModuleHasChangedLastVersionCheckParameter=Warning: the module %s has set
WarningModuleHasChangedSecurityCsrfParameter=Warning: the module %s has disabled the CSRF security of your instance. This action is suspect and your installation may no more be secured. Please contact the author of the module for explanation.
EMailsInGoingDesc=Incoming emails are managed by the module %s. You must enable and configure it if you need to support ingoing emails.
MAIN_IMAP_USE_PHPIMAP=Use the PHP-IMAP library for IMAP instead of native PHP IMAP. This also allows the use of an OAuth2 connection for IMAP (module OAuth must also be activated).
MAIN_CHECKBOX_LEFT_COLUMN=Show the column for field and line selection on the left (on the right by default)
MAIN_CHECKBOX_LEFT_COLUMN=Show the column for field and line selection on the left (on the right by default)

CSSPage=CSS Style
5 changes: 5 additions & 0 deletions htdocs/main.inc.php
Expand Up @@ -16,6 +16,7 @@
* Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2023 Joachim Küter <git-jk@bloxera.com>
* Copyright (C) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1785,6 +1786,10 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr
}
}

//customcss
print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/custom.css.php">'."\n";


// Output standard javascript links
if (!defined('DISABLE_JQUERY') && !$disablejs && !empty($conf->use_javascript_ajax)) {
// JQuery. Must be before other includes
Expand Down
35 changes: 35 additions & 0 deletions htdocs/theme/custom.css.php
@@ -0,0 +1,35 @@
<?php
/**
* custom.css.php
*
* Copyright (c) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

require_once __DIR__.'/../main.inc.php'; // __DIR__ allow this script to be included in custom themes
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

// Define css type
top_httphead('text/css');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
if (empty($dolibarr_nocache)) {
header('Cache-Control: max-age=10800, public, must-revalidate');
} else {
header('Cache-Control: no-cache');
}

if (file_exists(DOL_DATA_ROOT.'/admin/customcss.css')) {
readfile(DOL_DATA_ROOT.'/admin/customcss.css');
}