diff --git a/README.md b/README.md
index 1ec0754..2daebec 100644
--- a/README.md
+++ b/README.md
@@ -2,17 +2,21 @@
## Purpose
-This plugins aims to allow its users to modify the look of their [itsm](https://github.com/itsmng/itsm-ng)
-deployment, unifying their internal software's appearance.
+This plugins aims to allow its users to modify the look of their [itsm](https://github.com/itsmng/itsm-ng) deployment, unifying their internal software's appearance.
## Installation
-Installing this plugin is done following the standard process for itsm plugins, simply clone the git or download
-a release and place it within itsm's `plugins` folder.
+Installing this plugin is done following the standard process for itsm plugins, simply clone the git or download a release and place it within itsm's `plugins` folder.
+
+Don't forget to set Apache rights, and enjoy !
## Features
- * Set UI's color
- * Change logo in header
+ * Set UI's color :
+ * Primary color
+ * Menu color
+ * Active menu color
+ * On hover menu color
+ * Button color
+ * Change logo in header and login page
* Change favicon
- * Change logo in login page
diff --git a/front/config.form.php b/front/config.form.php
index f5c9c69..78c7afe 100644
--- a/front/config.form.php
+++ b/front/config.form.php
@@ -1,24 +1,59 @@
.
+ * ---------------------------------------------------------------------
+ */
include("../../../inc/includes.php");
require_once("../inc/config.class.php");
$plugin = new Plugin();
-if ($plugin->isActivated("whitelabel")) {
+
+if($plugin->isActivated("whitelabel")) {
$config = new PluginWhitelabelConfig();
- if (isset($_POST["update"])) {
+ if(isset($_POST["update"])) {
Session::checkRight("config", UPDATE);
$config->handleWhitelabel();
$config->refreshCss();
}
+ if(isset($_POST["reset"])) {
+ Session::checkRight("config", UPDATE);
+ $config->handleWhitelabel(true);
+ $config->refreshCss(true);
+ }
+
Html::header("White Label", $_SERVER["PHP_SELF"], "config", "plugins");
$config->showConfigForm();
} else {
Html::header("settings", '', "config", "plugins");
- echo "
".
- "
";
+ echo "
";
echo "
Please enable the plugin before configuring it ";
Html::footer();
}
diff --git a/hook.php b/hook.php
index eb068e7..850ca96 100644
--- a/hook.php
+++ b/hook.php
@@ -1,62 +1,129 @@
.
+ * ---------------------------------------------------------------------
+ */
function plugin_whitelabel_install() {
global $DB;
$migration = new Migration(101);
- if (!$DB->tableExists("itsm_plugin_whitelabel_brand")) {
- $query = "CREATE TABLE `itsm_plugin_whitelabel_brand` (
+ if (!$DB->tableExists("glpi_plugin_whitelabel_brand")) {
+ $query = "CREATE TABLE `glpi_plugin_whitelabel_brand` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`favicon` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`logo_central` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `brand_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL,
+ `primary_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#7b081d',
+ `menu_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#ae0c2a',
+ `menu_active_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#c70c2f',
+ `menu_onhover_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#d40e33',
+ `button_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#f5b7b1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
- $DB->queryOrDie("INSERT INTO `itsm_plugin_whitelabel_brand`
- (`id`, `favicon`, `logo_central`, `brand_color`)
- VALUES (1, '', '', '#7b081d')",
- $DB->error());
+
+ // Insert first entry with default itsmng colors
+ $query = "INSERT INTO `glpi_plugin_whitelabel_brand`
+ (`id`,`favicon`,`logo_central`,`primary_color`,`menu_color`,`menu_active_color`,`menu_onhover_color`,`button_color`)
+ VALUES (1,'','','#7b081d','#ae0c2a','#c70c2f','#d40e33','#f5b7b1')";
+ $DB->queryOrDie($query, $DB->error());
}
- if (!$DB->tableExists("itsm_plugin_whitelabel_profiles")) {
+ if (!$DB->tableExists("glpi_plugin_whitelabel_profiles")) {
+ $query = "CREATE TABLE `glpi_plugin_whitelabel_profiles` (
+ `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',
+ `right` char(1) collate utf8_unicode_ci default NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
- $query2 = "CREATE TABLE `itsm_plugin_whitelabel_profiles` (
- `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',
- `right` char(1) collate utf8_unicode_ci default NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
- $DB->queryOrDie($query2, $DB->error());
+ $DB->queryOrDie($query, $DB->error());
include_once(GLPI_ROOT."/plugins/whitelabel/inc/profile.class.php");
PluginWhitelabelProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']);
foreach (PluginWhitelabelProfile::getRightsGeneral() as $right) {
- PluginWhitelabelProfile::addDefaultProfileInfos($_SESSION['glpiactiveprofile']['id'],
- [$right['field'] => $right['default']]);
+ PluginWhitelabelProfile::addDefaultProfileInfos($_SESSION['glpiactiveprofile']['id'],[$right['field'] => $right['default']]);
}
}
// Create backup of resources that will be altered
- if (!file_exists(Plugin::getPhpDir("whitelabel") . "/bak/index.php.bak")) {
- copy(GLPI_ROOT . "/index.php", Plugin::getPhpDir("whitelabel") . "/bak/index.php.bak");
- copy(GLPI_ROOT . "/pics/favicon.ico", Plugin::getPhpDir("whitelabel") . "/bak/favicon.ico.bak");
- chown(Plugin::getPhpDir("whitelabel") . "/bak/index.php.bak", 0664);
- chown(Plugin::getPhpDir("whitelabel") . "/bak/favicon.ico.bak", 0664);
+ if (!file_exists(Plugin::getPhpDir("whitelabel")."/bak/index.php.bak")) {
+ copy(GLPI_ROOT."/index.php", Plugin::getPhpDir("whitelabel")."/bak/index.php.bak");
+ copy(GLPI_ROOT."/pics/favicon.ico", Plugin::getPhpDir("whitelabel")."/bak/favicon.ico.bak");
}
$loginPage = file_get_contents(GLPI_ROOT."/index.php");
// Patch login page (only patched on install, we update the styles through the linked CSS)
$patchMap = [
- "echo Html::css('public/lib/base.css');" => "echo Html::css('public/lib/base.css');\n\techo \"
\";\n",
+ "echo Html::css('public/lib/base.css');" => "echo Html::css('public/lib/base.css');\n\techo \"
\";\n",
"login_logo_itsm.png" => "login_logo_whitelabel.png"
];
$patchedLogin = strtr($loginPage, $patchMap);
- file_put_contents(GLPI_ROOT . "/index.php", $patchedLogin);
+ file_put_contents(GLPI_ROOT."/index.php", $patchedLogin);
+
+ // Update 2.0
+ if($DB->tableExists("glpi_plugin_whitelabel_brand")) {
+ // Rename brand_color column to primary_color
+ if(!$DB->fieldExists('glpi_plugin_whitelabel_brand', 'primary_color')) {
+ $query = "ALTER TABLE `glpi_plugin_whitelabel_brand` CHANGE COLUMN `brand_color` `primary_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#7b081d'";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ // Add column menu_color
+ if(!$DB->fieldExists('glpi_plugin_whitelabel_brand', 'menu_color')) {
+ $query = "ALTER TABLE `glpi_plugin_whitelabel_brand` ADD COLUMN `menu_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#ae0c2a'";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ // Add column menu_active_color
+ if(!$DB->fieldExists('glpi_plugin_whitelabel_brand', 'menu_active_color')) {
+ $query = "ALTER TABLE `glpi_plugin_whitelabel_brand` ADD COLUMN `menu_active_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#c70c2f'";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ // Add column menu_onhover_color
+ if(!$DB->fieldExists('glpi_plugin_whitelabel_brand', 'menu_onhover_color')) {
+ $query = "ALTER TABLE `glpi_plugin_whitelabel_brand` ADD COLUMN `menu_onhover_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#d40e33'";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ // Add column button_color
+ if(!$DB->fieldExists('glpi_plugin_whitelabel_brand', 'button_color')) {
+ $query = "ALTER TABLE `glpi_plugin_whitelabel_brand` ADD COLUMN `button_color` varchar(7) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#f5b7b1'";
+ $DB->queryOrDie($query, $DB->error());
+ }
+
+ }
$migration->executeMigration();
return true;
@@ -66,24 +133,17 @@ function plugin_whitelabel_uninstall() {
global $DB;
// Drop tables
- if($DB->tableExists('itsm_plugin_whitelabel_brand')) {
- $DB->queryOrDie(
- "DROP TABLE `itsm_plugin_whitelabel_brand`",
- $DB->error()
- );
+ if($DB->tableExists('glpi_plugin_whitelabel_brand')) {
+ $DB->queryOrDie("DROP TABLE `glpi_plugin_whitelabel_brand`",$DB->error());
}
- if($DB->tableExists('itsm_plugin_whitelabel_profiles')) {
- $DB->queryOrDie(
- "DROP TABLE `itsm_plugin_whitelabel_profiles`",
- $DB->error()
- );
+ if($DB->tableExists('glpi_plugin_whitelabel_profiles')) {
+ $DB->queryOrDie("DROP TABLE `glpi_plugin_whitelabel_profiles`",$DB->error());
}
// Clear profiles
foreach (PluginWhitelabelProfile::getRightsGeneral() as $right) {
- $query = "DELETE FROM `glpi_profilerights`
- WHERE `name` = '".$right['field']."'";
+ $query = "DELETE FROM `glpi_profilerights` WHERE `name` = '".$right['field']."'";
$DB->query($query);
if (isset($_SESSION['glpiactiveprofile'][$right['field']])) {
@@ -92,25 +152,24 @@ function plugin_whitelabel_uninstall() {
}
// Clear uploads
- $files = glob(Plugin::getPhpDir("whitelabel") . "/uploads/*"); // Get all file names in `uploads`
+ $files = glob(Plugin::getPhpDir("whitelabel")."/uploads/*"); // Get all file names in `uploads`
+
foreach($files as $file){ // Iterate files
- if(is_file($file)) {
- unlink($file); // Delete file
- }
+ if(is_file($file)) unlink($file); // Delete file
}
// Clear patches
- if (is_file(Plugin::getPhpDir("whitelabel") . "/bak/index.php.bak")) {
- copy(Plugin::getPhpDir("whitelabel") . "/bak/index.php.bak", GLPI_ROOT . "/index.php");
- copy(Plugin::getPhpDir("whitelabel") . "/bak/favicon.ico.bak", GLPI_ROOT . "/pics/favicon.ico");
+ if (is_file(Plugin::getPhpDir("whitelabel")."/bak/index.php.bak")) {
+ copy(Plugin::getPhpDir("whitelabel")."/bak/index.php.bak", GLPI_ROOT."/index.php");
+ copy(Plugin::getPhpDir("whitelabel")."/bak/favicon.ico.bak", GLPI_ROOT."/pics/favicon.ico");
}
// Clear bakups
- $files = glob(Plugin::getPhpDir("whitelabel") . "/bak/*");
+ $files = glob(Plugin::getPhpDir("whitelabel")."/bak/*");
+
foreach($files as $file){
- if(is_file($file)) {
- unlink($file);
- }
+ if(is_file($file)) unlink($file);
}
+
return true;
}
diff --git a/inc/config.class.php b/inc/config.class.php
index 7689326..2ba14f5 100644
--- a/inc/config.class.php
+++ b/inc/config.class.php
@@ -1,4 +1,34 @@
.
+ * ---------------------------------------------------------------------
+ */
use ScssPhp\ScssPhp\Compiler;
class PluginWhitelabelConfig extends CommonDBTM {
@@ -7,7 +37,7 @@ class PluginWhitelabelConfig extends CommonDBTM {
*
* @return void
*/
- function showConfigForm() {
+ public function showConfigForm() {
global $DB;
if (!Session::haveRight("plugin_whitelabel_whitelabel",UPDATE)) {
@@ -16,12 +46,28 @@ function showConfigForm() {
echo "