Skip to content

Commit

Permalink
fix install problem
Browse files Browse the repository at this point in the history
fix space problem in type Creation
fix setup problem when plugin is not installed
change menu
  • Loading branch information
ales-infotel committed Jun 11, 2020
1 parent ea4c7fa commit 7e2d656
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 24 deletions.
9 changes: 9 additions & 0 deletions inc/citype.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function prepareInputForAdd($input) {
$input['fields'] = '';
}
} else {
$input["name"] = str_replace(" ","",$input["name"]);
$input['name'] = "PluginCmdb" . ucfirst($input['name']);
$input['is_imported'] = 0;
if (!empty($input['_fields'])) {
Expand Down Expand Up @@ -434,6 +435,14 @@ function post_addItem($history = 1) {
$classname = self::getClassname($this->fields['name']);
$classname::install();
}
$core_config = Config::getConfigurationValues("core");
$db_values = importArrayFromDB($core_config[Impact::CONF_ENABLED]);
$db_values[] = $classname;
$input[Impact::CONF_ENABLED] = $db_values;
$input["id"] = 1;

$config = new Config();
$config->update($input);
}


Expand Down
90 changes: 68 additions & 22 deletions inc/cmdb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,10 @@ function displayMenu() {
echo "<div class='center'>";
echo "<table class='tab_cadre'>";
echo "<tr>";
echo "<th>" . 'CMDB' . "</th>";
echo "<th colspan='6'>" . __("Display Item Configuration", 'cmdb') . "</th>";
echo "</tr>";
echo "<tr>";
echo "<td class='center b' >";
echo "<a href='citype.php'>";
echo "<i class='fas fa-wrench fa-3x'></i>";
echo "<br/><br/>";
echo __("Configure Type of Item Configuration", 'cmdb');
echo "</a>";
echo "</tr>";
echo "<tr>";
echo "</td>";

$this->displayCIMenuCMDB(__("Display Item Configuration", 'cmdb'), "ci.php", "iconCI.png");
echo "</tr>";
// echo "<tr class='tab_bg_1'>";
Expand All @@ -80,7 +72,7 @@ function displayMenu() {
* @param $url
* @param $nameIcon
*/
function displayCIMenuCMDB($title, $url, $nameIcon) {
function displayCIMenuCMDB($title, $url, $nameIcon) {
global $DB, $CFG_GLPI;

Html::requireJs('cmdb');
Expand Down Expand Up @@ -109,9 +101,9 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
$ci_type = new PluginCmdbCIType();
$ciTypes = $ci_type->find($where);

echo "<td class='center b' >";
echo "<i class='fas fa-cog fa-3x'></i>";
echo "<br/><br/>";
// echo "<td class='center b' >";
// echo "<i class='fas fa-cog fa-3x'></i>";
// echo "<br/><br/>";

if (count($ciTypes) > 0) {
$tabCIType = [];
Expand All @@ -134,14 +126,68 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
// }
}
if (count($tabCIType) > 0) {
echo "<a id='linkDisplay' href='$url'>";
echo $title;
echo "</a><br/>";
Dropdown::showFromArray("citypes", $tabCIType, ["on_change" => "changeLink(this.value)",
"width" => '150']);

$script = "changeLink($(\"select[name='citypes']\").val());";
echo Html::scriptBlock('$(document).ready(function() {'.$script.'});');
// $boucle = intval(count($tabCIType) / 3);
$reste = count($tabCIType) % 3;
$i = 0;
foreach ($tabCIType as $id => $val){
if ($i % 3 == 0) {

echo "<tr class='tab_bg_1'>";
}
$citype = new PluginCmdbCIType();
$citype->getFromDB($id);
if (isset($citype->fields["is_imported"])
&& $citype->fields["is_imported"]) {
$link = Toolbox::getItemTypeSearchURL($citype->fields["name"]);
} else {
$link = $citype->fields["name"]::getSearchURL();
}
$citype_doc = new PluginCmdbCIType_Document();
echo "<td class='center b' colspan='2' >";
echo "<a href='$link'>";
if ($citype_doc->getFromDBByCrit(['plugin_cmdb_citypes_id' => $id,
'types_id' => 0])) {

echo "<img width='32' height='32' src='" . $CFG_GLPI['root_doc'] .
"/front/document.send.php?docid=" . $citype_doc->fields['documents_id'] . "'/>";

}else{
echo "<i class='fas fa-cog fa-3x'></i>";
}


echo "<br/>";
echo $val;
echo "</a>";
echo "</td>";

$i++;
if ($i % 3 == 0) {
echo "</tr>";

}
}

if ($i % 3 != 0) {
$j = 0;
$rest = $i % 3;
for ($j = 0; $j < 3 - $rest; $j++) {
echo "<td colspan='2'></td>";
}
echo "</tr>";

}
// for ($i=0;$i<$boucle;$i++){
//
// }
// echo "<a id='linkDisplay' href='$url'>";
// echo $title;
// echo "</a><br/>";
// Dropdown::showFromArray("citypes", $tabCIType, ["on_change" => "changeLink(this.value)",
// "width" => '150']);
//
// $script = "changeLink($(\"select[name='citypes']\").val());";
// echo Html::scriptBlock('$(document).ready(function() {'.$script.'});');
} else {
echo "<i>" . __("No Types of CI found. Please create Types of CI before display CIs", 'cmdb') . "</i>";
}
Expand Down
2 changes: 2 additions & 0 deletions inc/menu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ static function getMenuContent() {
$menu['title'] = self::getTypeName();
$menu['page'] = "/plugins/cmdb/front/menu.php";

$menu['page'] = "/plugins/cmdb/front/menu.php";
$menu['links']["<i class='fas fa-wrench fa-2x' title='" . __('Configure Type of Item Configuration', 'cmdb') . "'></i>"] = '/plugins/cmdb/front/citype.php';
//ItemConfiguration
$menu['options']['ci']['title'] = __s("Item Configuration", 'cmdb');
$menu['options']['ci']['page'] = '/plugins/cmdb/front/ci.php';
Expand Down
2 changes: 1 addition & 1 deletion install/sql/empty-2.2.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_cmdb_civalues` (
`items_id` int(11) NOT NULL,
`plugin_cmdb_cifields_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `plugin_cmdb_cis_id` (`plugin_cmdb_cis_id`),
KEY `items_id` (`items_id`),
KEY `plugin_cmdb_cifields_id` (`plugin_cmdb_cifields_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Expand Down
6 changes: 5 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ function plugin_init_cmdb() {
//Define impact_asset_types for ci types
include_once(GLPI_ROOT . "/plugins/cmdb/inc/citype.class.php");
$citype = new PluginCmdbCIType();
$citype->showInAssetTypes();
$plugin = new Plugin();
if($plugin->isActivated('cmdb')){
$citype->showInAssetTypes();
}


//Change link from menu.php
$PLUGIN_HOOKS["javascript"]['cmdb'] = ["/plugins/cmdb/js/changeCIMenu.js",
Expand Down

0 comments on commit 7e2d656

Please sign in to comment.