Skip to content

Commit

Permalink
Push 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Théodore committed Jul 18, 2022
1 parent c2fd7a1 commit 8b1d233
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 126 deletions.
6 changes: 0 additions & 6 deletions .gitignore

This file was deleted.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ 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.
a release and place it within itsm's `plugins` folder.

## Features

* Set UI's color
* Change logo in header
* Change favicon
* Change logo in login page
1 change: 1 addition & 0 deletions bak/whatisthis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains backups of original ITSM-NG files modified by the plugin
8 changes: 4 additions & 4 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

if (isset($_POST["update"])) {
Session::checkRight("config", UPDATE);
$config->handleWhitelabel($_POST, $_FILES);
$config->refreshScss();
$config->handleWhitelabel();
$config->refreshCss();
}

Html::header("White Label", $_SERVER["PHP_SELF"], "config", "plugins");
$config->showConfigForm($_POST);
$config->showConfigForm();
} else {
Html::header("settings", '', "config", "plugins");
echo "<div class='center'><br><br>".
Expand All @@ -23,4 +23,4 @@
Html::footer();
}

Html::footer();
Html::footer();
4 changes: 1 addition & 3 deletions front/profile.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

include ('../../../inc/includes.php');

// Gestion des données du formulaire

Session::haveRight('plugin_whitelabel_whitelabel', UPDATE);

$prof = new PluginWhitelabelProfile();

if (isset($_POST['update'])) {
$prof->update($_POST);
Html::back();
}
}
61 changes: 50 additions & 11 deletions hook.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

function plugin_whitelabel_install() {
global $DB;

$migration = new Migration(100);
$migration = new Migration(101);

if (!$DB->tableExists("itsm_plugin_whitelabel_brand")) {
$query = "CREATE TABLE `itsm_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,
`brand_color_secondary` varchar(7) COLLATE utf8_unicode_ci NOT NULL,
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`, `brand_color_secondary`)
VALUES (1, '', '', '#7b081d', '#ae0c2a')",
(`id`, `favicon`, `logo_central`, `brand_color`)
VALUES (1, '', '', '#7b081d')",
$DB->error());
}

Expand All @@ -37,32 +37,50 @@ function plugin_whitelabel_install() {
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);
}

$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 \"<link rel='stylesheet' type='text/css' href='/css/whitelabel_login.css' media='all'>\";\n",
"login_logo_itsm.png" => "login_logo_whitelabel.png"
];

$patchedLogin = strtr($loginPage, $patchMap);

file_put_contents(GLPI_ROOT . "/index.php", $patchedLogin);

$migration->executeMigration();
return true;
}

function plugin_whitelabel_uninstall() {
global $DB;

$tablename = 'itsm_plugin_whitelabel_brand';
if($DB->tableExists($tablename)) {
// Drop tables
if($DB->tableExists('itsm_plugin_whitelabel_brand')) {
$DB->queryOrDie(
"DROP TABLE `$tablename`",
"DROP TABLE `itsm_plugin_whitelabel_brand`",
$DB->error()
);
}

$tablename = 'itsm_plugin_whitelabel_profiles';
if($DB->tableExists($tablename)) {
if($DB->tableExists('itsm_plugin_whitelabel_profiles')) {
$DB->queryOrDie(
"DROP TABLE `$tablename`",
"DROP TABLE `itsm_plugin_whitelabel_profiles`",
$DB->error()
);
}

// Clear profiles
foreach (PluginWhitelabelProfile::getRightsGeneral() as $right) {
$query = "DELETE FROM `glpi_profilerights`
WHERE `name` = '".$right['field']."'";
Expand All @@ -73,5 +91,26 @@ function plugin_whitelabel_uninstall() {
}
}

// Clear 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
}
}

// 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");
}

// Clear bakups
$files = glob(Plugin::getPhpDir("whitelabel") . "/bak/*");
foreach($files as $file){
if(is_file($file)) {
unlink($file);
}
}
return true;
}
}
Loading

0 comments on commit 8b1d233

Please sign in to comment.