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 "


". - "warning

"; + echo "


warning

"; 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 "
"; echo ""; - echo ""; + echo ""; - $this->startField("Brand color"); - Html::showColorField("brand_color", [ - "value" => $this->getBrandColor(), - ]); + $colors = $this->getThemeColors(); + + $this->startField(__("Primary color", 'whitelabel')); + Html::showColorField("primary_color", ["value" => $colors["primary_color"]]); + $this->endField(); + + $this->startField(__("Menu color", 'whitelabel')); + Html::showColorField("menu_color", ["value" => $colors["menu_color"]]); + $this->endField(); + + $this->startField(__("Active menu color", 'whitelabel')); + Html::showColorField("menu_active_color", ["value" => $colors["menu_active_color"]]); + $this->endField(); + + $this->startField(__("On hover menu color", 'whitelabel')); + Html::showColorField("menu_onhover_color", ["value" => $colors["menu_onhover_color"]]); + $this->endField(); + + $this->startField(__("Button color", 'whitelabel')); + Html::showColorField("button_color", ["value" => $colors["button_color"]]); $this->endField(); $this->startField(sprintf(__('Favicon (%s)'), Document::getMaxUploadSize())); @@ -33,14 +79,14 @@ function showConfigForm() { $this->endField(); echo ""; echo "
".__("Whitelabel Settings", 'holidays')."
".__("Whitelabel Settings", 'whitelabel')."
"; - echo ""; + echo "  "; echo "
"; Html::closeForm(); } /** - * Displays an image upload field + * Displays image upload field * * @param string Field name * @@ -49,7 +95,8 @@ function showConfigForm() { private function showImageUploadField(string $fieldName) { global $DB; $path = Plugin::getPhpDir("whitelabel", false)."/uploads/"; - $row = $DB->queryOrDie("SELECT * FROM `itsm_plugin_whitelabel_brand` WHERE id = 1", $DB->error())->fetch_assoc(); + $row = $DB->queryOrDie("SELECT * FROM `glpi_plugin_whitelabel_brand` WHERE `id` = 1", $DB->error())->fetch_assoc(); + if (!empty($row[$fieldName])) { echo Html::image($path.$row[$fieldName], [ 'style' => 'max-width: 100px; max-height: 50px;', @@ -62,15 +109,38 @@ private function showImageUploadField(string $fieldName) { echo ""; } } - - private function getBrandColor() { + + /** + * Get the primary theme color + * + * @return string + */ + private function getThemeColors() { global $DB; - $query = "SELECT brand_color FROM itsm_plugin_whitelabel_brand WHERE id = '1'"; + + // Default colors + $colors = [ + 'primary_color' => '#7b081d', + 'menu_color' => '#ae0c2a', + 'menu_active_color' => '#c70c2f', + 'menu_onhover_color' => '#d40e33', + 'button_color' => '#f5b7b1' + ]; + + $query = "SELECT * FROM `glpi_plugin_whitelabel_brand` WHERE id = '1'"; $result = $DB->query($query); + if ($DB->numrows($result) > 0) { - return $DB->result($result, 0, 'brand_color'); + $colors = [ + 'primary_color' => $DB->result($result, 0, 'primary_color'), + 'menu_color' => $DB->result($result, 0, 'menu_color'), + 'menu_active_color' => $DB->result($result, 0, 'menu_active_color'), + 'menu_onhover_color' => $DB->result($result, 0, 'menu_onhover_color'), + 'button_color' => $DB->result($result, 0, 'button_color') + ]; } - return '#7b081d'; + + return $colors; } /** @@ -98,74 +168,80 @@ private function endField() { echo ""; } - function handleWhitelabel() { + public function handleWhitelabel($reset = false) { global $DB; - $color = $_POST["brand_color"]; - $DB->queryOrDie("UPDATE `itsm_plugin_whitelabel_brand` SET brand_color = '$color' WHERE id = 1", $DB->error()); + // Update theme colors + if($_POST["primary_color"]) { + $color = (!$reset) ? $_POST["primary_color"] : '#7b081d'; + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET `primary_color` = '$color' WHERE `id` = 1", $DB->error()); + } + + if($_POST["menu_color"]) { + $color = (!$reset) ? $_POST["menu_color"] : '#ae0c2a'; + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET `menu_color` = '$color' WHERE `id` = 1", $DB->error()); + } + + if($_POST["menu_active_color"]) { + $color = (!$reset) ? $_POST["menu_active_color"] : '#c70c2f'; + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET `menu_active_color` = '$color' WHERE `id` = 1", $DB->error()); + } + + if($_POST["menu_onhover_color"]) { + $color = (!$reset) ? $_POST["menu_onhover_color"] : '#d40e33'; + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET `menu_onhover_color` = '$color' WHERE `id` = 1", $DB->error()); + } + + if($_POST["button_color"]) { + $color = (!$reset) ? $_POST["button_color"] : '#f5b7b1'; + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET `button_color` = '$color' WHERE `id` = 1", $DB->error()); + } + $this->handleFile("favicon", array("image/x-icon")); - $this->handleFile("logo_central", array("image/jpeg", "image/gif", "image/png")); + $this->handleFile("logo_central", array("image/png")); if ($this->handleClear("favicon")) { copy(Plugin::getPhpDir("whitelabel")."/bak/favicon.ico.bak", GLPI_ROOT."/pics/favicon.ico"); } + $this->handleClear("logo_central"); - copy(Plugin::getPhpDir("whitelabel")."/uploads/favicon.ico", GLPI_ROOT."/pics/favicon.ico"); - chown(GLPI_ROOT."/pics/favicon.ico", 0664); + if(file_exists(Plugin::getPhpDir("whitelabel")."/uploads/favicon.ico")) { + copy(Plugin::getPhpDir("whitelabel")."/uploads/favicon.ico", GLPI_ROOT."/pics/favicon.ico"); + } } /** * Generate and install new CSS sheets w/ styles mapped */ - function refreshCss() { + public function refreshCss($reset = false) { global $DB; - $row = $DB->queryOrDie("SELECT * FROM `itsm_plugin_whitelabel_brand` WHERE id = 1", $DB->error())->fetch_assoc(); - - list($r, $g, $b) = sscanf($row["brand_color"], "#%02x%02x%02x"); // Magic format parse to do #HEX to RGB - // Apply color offsets from the stock theme - $secondary = sprintf("#%02x%02x%02x", - $this->rgbClamp($r + 13), - $this->rgbClamp($g + 4), - $this->rgbClamp($b + 23)); - $ternary = sprintf("#%02x%02x%02x", - $this->rgbClamp($r + 122), - $this->rgbClamp($g + 124), - $this->rgbClamp($b + 148)); - $ternary_hover = sprintf("#%02x%02x%02x", - $this->rgbClamp($r + 71), - $this->rgbClamp($g + 96), - $this->rgbClamp($b + 111)); - $quad = sprintf("#%02x%02x%02x", - $this->rgbClamp($r + 18), - $this->rgbClamp($g + 4), - $this->rgbClamp($b + 45)); - $quad_hover = sprintf("#%02x%02x%02x", - $this->rgbClamp($r + 8), - $this->rgbClamp($g + 2), - $this->rgbClamp($b + 23)); - $low_contrast = sprintf("#%02x%02x%02x", - $this->rgbClamp($r - 19), - $this->rgbClamp($g + 20), - $this->rgbClamp($b + 45)); - $logo = "/pics/fd_logo.png"; - list($logoW, $logoH) = getimagesize(GLPI_ROOT."/pics/fd_logeo.png"); + + $row = $DB->queryOrDie("SELECT * FROM `glpi_plugin_whitelabel_brand` WHERE `id` = 1", $DB->error())->fetch_assoc(); + + $primaryColor = (!$reset) ? $row["primary_color"] : '#7b081d'; + $menuColor = (!$reset) ? $row["menu_color"] : '#ae0c2a'; + $menuActiveColor = (!$reset) ? $row["menu_active_color"] : '#c70c2f'; + $menuOnHoverColor = (!$reset) ? $row["menu_onhover_color"] : '#d40e33'; + $buttonColor = (!$reset) ? $row["button_color"] : '#f5b7b1'; + + list($logoW, $logoH) = getimagesize(GLPI_ROOT."/pics/fd_logo.png"); copy(GLPI_ROOT."/pics/fd_logo.png", GLPI_ROOT."/pics/login_logo_whitelabel.png"); + $logo = "../../../pics/login_logo_whitelabel.png"; + if(!empty($row["logo_central"])) { - list($logoW, $logoH) = getimagesize(Plugin::getPhpDir("whitelabel", true) . "/uploads/logo_central.png"); - $logo = $row["logo_central"]; + list($logoW, $logoH) = getimagesize(Plugin::getPhpDir("whitelabel", true)."/uploads/logo_central.png"); copy(Plugin::getPhpDir("whitelabel")."/uploads/".$row["logo_central"], GLPI_ROOT."/pics/login_logo_whitelabel.png"); } + $map = [ - "%brand_color%" => $row["brand_color"], - "%brand_color_secondary%" => $secondary, - "%brand_color_ternary%" => $ternary, - "%brand_color_hover_ternary%" => $ternary_hover, - "%brand_color_quad%" => $quad, - "%brand_color_hover_quad%" => $quad_hover, - "%low_contrast_text%" => $low_contrast, - "%logo%" => $logo, - "%logo_width%" => ceil(55 * ($logoW / $logoH)) + "%primary_color%" => $primaryColor, + "%menu_color%" => $menuColor, + "%button_color%" => $buttonColor, + "%menu_active_color%" => $menuActiveColor, + "%menu_onhover_color%" => $menuOnHoverColor, + "%logo%" => $logo, + "%logo_width%" => ceil(55 * ($logoW / $logoH)) ]; $template = file_get_contents(Plugin::getPhpDir("whitelabel")."/styles/template.scss"); @@ -180,8 +256,14 @@ function refreshCss() { $css = $scssCompiler->compile($style); $loginCss = $scssCompiler->compile($login_style); - unlink(Plugin::getPhpDir("whitelabel", true)."/uploads/whitelabel.css"); - unlink(GLPI_ROOT."/css/whitelabel_login.css"); + if(file_exists(Plugin::getPhpDir("whitelabel", true)."/uploads/whitelabel.css")) { + unlink(Plugin::getPhpDir("whitelabel", true)."/uploads/whitelabel.css"); + } + + if(file_exists(GLPI_ROOT."/css/whitelabel_login.css")) { + unlink(GLPI_ROOT."/css/whitelabel_login.css"); + } + // Place compiled CSS file_put_contents(Plugin::getPhpDir("whitelabel", true)."/uploads/whitelabel.css", $css); file_put_contents(GLPI_ROOT."/css/whitelabel_login.css", $loginCss); @@ -192,12 +274,15 @@ function refreshCss() { // Clear cache $files = glob(GLPI_ROOT."/files/_cache/*"); + foreach($files as $file){ if(is_file($file)) { unlink($file); } } + $files = glob(GLPI_ROOT."/files/_tmp/*"); + foreach($files as $file){ if(is_file($file)) { unlink($file); @@ -210,9 +295,11 @@ function refreshCss() { */ private function handleFile(string $file, array $formats) { global $DB; + if(empty($_FILES[$file])) { return; } + // Get error code from file upload action switch ($_FILES[$file]["error"]) { case UPLOAD_ERR_OK: @@ -223,9 +310,13 @@ private function handleFile(string $file, array $formats) { $this->createDirectoryIfNotExist(Plugin::getPhpDir("whitelabel", true)."/uploads/"); $ext = pathinfo($_FILES[$file]["name"], PATHINFO_EXTENSION); $uploadfile = Plugin::getPhpDir("whitelabel", true)."/uploads/".$file.".".$ext; - unlink($uploadfile); + + if(file_exists($uploadfile)) { + unlink($uploadfile); + } + if (move_uploaded_file($_FILES[$file]["tmp_name"], $uploadfile)) { - $DB->queryOrDie("UPDATE `itsm_plugin_whitelabel_brand` SET $file = '$file.".$ext."' WHERE id = 1", $DB->error()); + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET $file = '$file.".$ext."' WHERE id = 1", $DB->error()); chmod($uploadfile, 0664); } break; @@ -263,29 +354,26 @@ private function handleFile(string $file, array $formats) { * @param string $path The path to the folder to create * @return bool */ - private function createDirectoryIfNotExist(string $path) - { + private function createDirectoryIfNotExist(string $path) { if (!file_exists($path)) { mkdir($path, 0664); } elseif (!is_dir($path)) { return false; } + return true; } - private function handleClear(string $field) - { + private function handleClear(string $field) { global $DB; + if (isset($_POST["_blank_".$field])) { - $row = $DB->queryOrDie("SELECT * FROM `itsm_plugin_whitelabel_brand` WHERE id = 1", $DB->error())->fetch_assoc(); + $row = $DB->queryOrDie("SELECT * FROM `glpi_plugin_whitelabel_brand` WHERE `id` = 1", $DB->error())->fetch_assoc(); unlink(Plugin::getPhpDir("whitelabel")."/uploads/".$row[$field]); - $DB->queryOrDie("UPDATE `itsm_plugin_whitelabel_brand` SET $field = '' WHERE id = 1", $DB->error()); + $DB->queryOrDie("UPDATE `glpi_plugin_whitelabel_brand` SET $field = '' WHERE `id` = 1", $DB->error()); return true; } - return false; - } - private function rgbClamp($value) { - return max(0, min(255, $value)); + return false; } } diff --git a/locales/en_GB.mo b/locales/en_GB.mo new file mode 100644 index 0000000..41da6fe Binary files /dev/null and b/locales/en_GB.mo differ diff --git a/locales/en_GB.po b/locales/en_GB.po new file mode 100644 index 0000000..554e00c --- /dev/null +++ b/locales/en_GB.po @@ -0,0 +1,46 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" + +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-14 13:29+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" + +#: inc/config.class.php:49 +msgid "Whitelabel Settings" +msgstr "" + +#: inc/config.class.php:53 +msgid "Primary color" +msgstr "" + +#: inc/config.class.php:57 +msgid "Menu color" +msgstr "" + +#: inc/config.class.php:61 +msgid "Active menu color" +msgstr "" + +#: inc/config.class.php:65 +msgid "On hover menu color" +msgstr "" + +#: inc/config.class.php:69 +msgid "Button color" +msgstr "" + +#: inc/config.class.php:82 +msgid "Restore colors" +msgstr "" diff --git a/locales/fr_FR.mo b/locales/fr_FR.mo new file mode 100644 index 0000000..0170db0 Binary files /dev/null and b/locales/fr_FR.mo differ diff --git a/locales/fr_FR.po b/locales/fr_FR.po new file mode 100644 index 0000000..80b7120 --- /dev/null +++ b/locales/fr_FR.po @@ -0,0 +1,46 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" + +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-14 13:29+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" + +#: inc/config.class.php:49 +msgid "Whitelabel Settings" +msgstr "Configuration de Whitelabel" + +#: inc/config.class.php:53 +msgid "Primary color" +msgstr "Couleur principale" + +#: inc/config.class.php:57 +msgid "Menu color" +msgstr "Couleur du menu" + +#: inc/config.class.php:61 +msgid "Active menu color" +msgstr "Couleur du menu actif" + +#: inc/config.class.php:65 +msgid "On hover menu color" +msgstr "Couleur du menu au survol" + +#: inc/config.class.php:69 +msgid "Button color" +msgstr "Couleur des boutons" + +#: inc/config.class.php:82 +msgid "Restore colors" +msgstr "Restaurer les couleurs" diff --git a/locales/glpi_whitelabel.pot b/locales/glpi_whitelabel.pot new file mode 100644 index 0000000..baf85d8 --- /dev/null +++ b/locales/glpi_whitelabel.pot @@ -0,0 +1,35 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" + +#: inc/config.class.php:49 +msgid "Whitelabel Settings" +msgstr "" + +#: inc/config.class.php:53 +msgid "Primary color" +msgstr "" + +#: inc/config.class.php:57 +msgid "Menu color" +msgstr "" + +#: inc/config.class.php:61 +msgid "Active menu color" +msgstr "" + +#: inc/config.class.php:65 +msgid "On hover menu color" +msgstr "" + +#: inc/config.class.php:69 +msgid "Button color" +msgstr "" + +#: inc/config.class.php:82 +msgid "Restore colors" +msgstr "" diff --git a/locales/new.pot b/locales/new.pot new file mode 100644 index 0000000..baf85d8 --- /dev/null +++ b/locales/new.pot @@ -0,0 +1,35 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" + +#: inc/config.class.php:49 +msgid "Whitelabel Settings" +msgstr "" + +#: inc/config.class.php:53 +msgid "Primary color" +msgstr "" + +#: inc/config.class.php:57 +msgid "Menu color" +msgstr "" + +#: inc/config.class.php:61 +msgid "Active menu color" +msgstr "" + +#: inc/config.class.php:65 +msgid "On hover menu color" +msgstr "" + +#: inc/config.class.php:69 +msgid "Button color" +msgstr "" + +#: inc/config.class.php:82 +msgid "Restore colors" +msgstr "" diff --git a/setup.php b/setup.php index 87602be..cf1bf5f 100644 --- a/setup.php +++ b/setup.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + */ function plugin_init_whitelabel() { global $PLUGIN_HOOKS; @@ -16,12 +46,14 @@ function plugin_init_whitelabel() { } function plugin_version_whitelabel() { - return array('name' => "White Label", - 'version' => '1.0.1', - 'author' => 'Théodore Clément', - 'license' => 'GPLv3+', - 'homepage' => 'https://github.com/Soulusions/whitelabel', - 'minGlpiVersion' => '9.5'); + return array( + 'name' => "White Label", + 'version' => '2.0.0', + 'author' => 'ITSM Dev Team, Théodore Clément', + 'license' => 'GPLv3+', + 'homepage' => 'https://github.com/itsmng/whitelabel', + 'minGlpiVersion' => '9.5' + ); } function plugin_whitelabel_check_prerequisites() { diff --git a/styles/login_template.scss b/styles/login_template.scss index 6bed5f9..e89d07b 100644 --- a/styles/login_template.scss +++ b/styles/login_template.scss @@ -1,26 +1,26 @@ #contenulogin { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } #boxlogin legend { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } #boxlogin input { - border: 1px solid %brand_color_secondary% !important; + border: 1px solid %menu_color% !important; } #firstboxlogin { - background-color: %brand_color% !important; + background-color: %primary_color% !important; } #text-login { color: white !important; - background-color: %brand_color_secondary% !important; + background-color: %menu_color% !important; } #logo_login { - background: %brand_color_secondary% !important; + background: %menu_color% !important; } input { @@ -29,12 +29,10 @@ input { } &.submit { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; } } .vsubmit { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; } diff --git a/styles/template.scss b/styles/template.scss index 24947bc..b71af38 100644 --- a/styles/template.scss +++ b/styles/template.scss @@ -5,7 +5,7 @@ $break_menu: 1055px; $break_tablets: 1300px; .radio .outer { - border: 3px solid %brand_color% !important; + border: 3px solid %primary_color% !important; } #header #c_logo { @@ -15,11 +15,11 @@ $break_tablets: 1300px; } #firstboxlogin { - background-color: %brand_color% !important; + background-color: %primary_color% !important; } #header_top { - background-color: %brand_color% !important; + background-color: %primary_color% !important; } #c_preference a, #language_link > span { @@ -36,36 +36,28 @@ $break_tablets: 1300px; } .x-button.x-button-drop.planned:after { - color: %brand_color% !important; + color: %primary_color% !important; } .itilstatus { - color: %brand_color% !important; + color: %primary_color% !important; } #logo_login { - background: %brand_color_secondary% !important; + background: %menu_color% !important; } #text_login { color: white !important; - background-color: %brand_color_secondary% !important; -} - -a, .btn-linkstyled { - color: %brand_color_secondary% !important; - - &:link { - color: %brand_color_secondary% !important; - } + background-color: %menu_color% !important; } #c_menu { - background-color: %brand_color_secondary% !important; + background-color: %menu_color% !important; } .main_form tr.headerRow th { - color: %brand_color_quad% !important; + color: %menu_active_color% !important; } .primary-fg, .primary-fg:link, .primary-fg:hover { @@ -81,22 +73,22 @@ ul { } > li.active { - background-color: %brand_color_quad% !important; + background-color: %menu_active_color% !important; } } &.ssmenu li.active { - background-color: %brand_color_quad% !important; + background-color: %menu_active_color% !important; } &#menu { > li:hover { - background-color: %brand_color_hover_quad% !important; + background-color: %menu_onhover_color% !important; } ul li a { &:hover { - background: %brand_color_secondary% !important; + background: %menu_color% !important; color: #fff !important; } @@ -107,7 +99,7 @@ ul { div.progress { .progress-fg { - background-color: %brand_color_quad% !important; + background-color: %menu_active_color%!important; } } @@ -115,16 +107,12 @@ a.copyright { color: #000 !important; } -a, a:link { - color: %brand_color_secondary% !important; -} - a:hover { color: black !important; } .showplan { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } ul#onglet { @@ -137,7 +125,7 @@ ul#onglet li { } ul#onglet li.actif { - border-bottom: 1px ridge %brand_color_secondary% !important; + border-bottom: 1px ridge %menu_color% !important; } ul#onglet li.invisible { @@ -153,7 +141,7 @@ ul#onglet li.actif a { } #onglet a:hover { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } ul#onglet span.fake { @@ -161,24 +149,24 @@ ul#onglet span.fake { } #contenulogin { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } #boxlogin legend { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } #boxlogin input { - border: 1px solid %brand_color_secondary% !important; + border: 1px solid %menu_color% !important; } #logo-login a:hover { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } #c_preference { .select2-choice { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } } @@ -189,18 +177,18 @@ ul#onglet span.fake { #show_all_menu{ dt { color: white !important; - background-color: %brand_color% !important; + background-color: %primary_color% !important; } a:hover { - background-color: %brand_color_secondary% !important; + background-color: %menu_color% !important; } } .primary-fg-inverse { - color: %brand_color_secondary% !important; + color: %menu_color% !important; &:hover { - color: %brand_color_secondary% !important; + color: %menu_color% !important; } } @@ -209,12 +197,12 @@ ul#onglet span.fake { .kanban-dropdown { li { &:hover { - background-color: %brand_color_secondary% !important; + background-color: %menu_color% !important; } } li.dropdown-trigger { &.active { - background-color: %brand_color_secondary% !important; + background-color: %menu_color% !important; } } } @@ -247,14 +235,12 @@ input { } &.submit { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; } } .vsubmit { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; } .breadcrumb_item { @@ -267,25 +253,23 @@ input { } &:nth-of-type(3) { - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; &:after { - border-left-color: %brand_color_ternary% !important; + border-left-color: %button_color% !important; } } } .x-button { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; &:hover { - background-color: %brand_color_hover_ternary% !important; + background-color: %button_color% !important; } } .warning { - color: %low_contrast_text% !important; - background-color: %brand_color_ternary% !important; + background-color: %button_color% !important; } -// I am sorry this exists. +