Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmdevteam committed Nov 8, 2022
0 parents commit 6b6c324
Show file tree
Hide file tree
Showing 21 changed files with 1,692 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ITSM Splitdropdown

## Purpose

This plugin allows you to split a dropdown into multiple dropdowns based on the level of splitting you want.

## 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.

Don't forget to set Apache rights, and enjoy !

## Usage

Go to `Configuration > Plugins` and click on `Split dropdown` to access the configuration.

![Add splitted dropdown](img/splitdropdown_add.png)

* Dropdown : select the dropdown to split (ITIL Categories / Locations)
* Enable split : Enable or disable splitting
* Level : splitting level

The splitting dropdown list is displayed below.

![Splitted dropdown list](img/splitdropdown_list.png)

When you add a new enabled splitted dropdown, a preview is displayed for you to test the dropdown split.

![Splitted dropdown preview](img/splitdropdown_preview.png)

`Note : a splitted dropdown is updated when you added the same dropdown type.`
44 changes: 44 additions & 0 deletions ajax/children.dropdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
include("../../../inc/includes.php");

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

if (isset($_GET['fk'])) {
$sons = getSonsOf($_GET['table'], $_GET['fk']);
$_GET['itemType']::dropdown([
$sons,
"name" => $_GET['itemType_id'],
"condition" => [$_GET['itemType_id'] . "=" . $_GET['fk']],
]);
}
39 changes: 39 additions & 0 deletions ajax/delete.database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
include("../../../inc/includes.php");

global $DB;

$criteria = "DELETE FROM glpi_plugin_splitdropdown WHERE id='" . $_GET["id"] . "'";
$DB->request($criteria);

header("location: ../front/config.form.php");
72 changes: 72 additions & 0 deletions ajax/getOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
require_once("../../../inc/includes.php");

global $DB;

$criteria = "SELECT category, split, level FROM glpi_plugin_splitdropdown";
$iterators = $DB->request($criteria);

foreach ($iterators as $iterator) {
$list[$iterator["category"]] = array(
"category" => $iterator["category"],
"split" => $iterator["split"],
"level" => $iterator["level"]
);
}

$options = array(
"inNewTicket" => (preg_match("/helpdesk.public.php/", $_SERVER["HTTP_REFERER"]) || preg_match("/tracking.injector.php/", $_SERVER["HTTP_REFERER"]) || preg_match("/ticket.form.php/", $_SERVER["HTTP_REFERER"])) && !preg_match("/[?]id=/", $_SERVER["HTTP_REFERER"]),
);

if(!empty($list)) {
foreach ($list as $element) {
$category = $list[$element["category"]]["category"];
$level = $list[$element["category"]]["level"];
$split = $list[$element["category"]]["split"];

$table = getTableForItemType($category);
$itemType_id = getForeignKeyFieldForTable($table);
$itemType = getSingular(ucfirst($category));

$options[$element["category"]] = array(
"options" => $list[$element["category"]],
"values" => array(
"table" => $table,
"itemType_id" => $itemType_id,
"itemType" => $itemType,
),
);
}
}

echo json_encode($options);
46 changes: 46 additions & 0 deletions ajax/parent.dropdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
include("../../../inc/includes.php");

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

if (isset($_GET["split"]) && $_GET["split"] === "1") {
$_GET['itemType']::dropdown([
"name" => "parent_" . $_GET['itemType_id'],
"condition" => ["level =" . $_GET["level"]],
]);
} else {
$_GET['itemType']::dropdown([
"name" => "parent_" . $_GET['itemType_id'],
]);
}
67 changes: 67 additions & 0 deletions front/config.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
include('../../../inc/includes.php');
include_once('../inc/splitdropdown.class.php');
include_once('../inc/config.class.php');

$plugin = new Plugin();

if ($plugin->isActivated('splitdropdown')) {
$splitdropdown = new SplitDropdown();
$config = new PluginSplitdropdownConfig();

if (isset($_POST["splitOption"]) && $_POST["splitOption"] === "2") $_POST["splitOption"] = "0";
if (isset($_POST["splitOption"], $_POST["levelOption"]) && $_POST["splitOption"] === "1" && $_POST["levelOption"] === "") $_POST["levelOption"] = "1";

Html::header('List Category', $_SERVER["PHP_SELF"], "config", "plugins");

$config->showFormulaire();

echo "<br>";

if (isset($_POST['update'], $_POST["categoryOption"], $_POST["splitOption"], $_POST["levelOption"]) && $_POST["categoryOption"] != "0") {
$splitdropdown->addToDatabase($_POST["categoryOption"], $_POST["splitOption"], $_POST["levelOption"]);
}

$config->showTable();
echo "<br>";

if (isset($_POST['update'], $_POST["categoryOption"], $_POST["splitOption"], $_POST["levelOption"]) && $_POST["splitOption"] != "0") {
$config->showPreview($_POST["categoryOption"]);
}
} else {
global $CFG_GLPI;
echo '<div class=\'center\'><br><br><img src=\'' . $CFG_GLPI['root_doc'] . '/pics/warning.png\' alt=\'warning\'><br><br>';
echo '<b>' . __("Enable your plugin", "splitdropdown") . '</b></div>';
}

Html::footer();
76 changes: 76 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/

/**
* Install hook
*
* @return boolean
*/
function plugin_splitdropdown_install() {
global $DB;

$migration = new Migration(100);

if (!$DB->tableExists("glpi_plugin_splitdropdown")) {
$query = "CREATE TABLE `glpi_plugin_splitdropdown` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(255) NOT NULL,
`split` boolean NOT NULL,
`level` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
}

$migration->executeMigration();

return true;
}

/**
* Uninstall hook
*
* @return boolean
*/
function plugin_splitdropdown_uninstall() {
global $DB;

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

return true;
}
Binary file added img/splitdropdown_add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/splitdropdown_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/splitdropdown_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6b6c324

Please sign in to comment.