Skip to content

Commit

Permalink
Min fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Jun 11, 2020
1 parent 7e2d656 commit d537fc4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 78 deletions.
8 changes: 4 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ function plugin_cmdb_uninstall() {

//remove files
if (is_dir(PLUGINCMDB_DOC_DIR.'/front')) {
rrmdir(PLUGINCMDB_DOC_DIR.'/front');
cmdb_rmdir(PLUGINCMDB_DOC_DIR.'/front');
}
if (is_dir(PLUGINCMDB_DOC_DIR.'/inc')) {
rrmdir(PLUGINCMDB_DOC_DIR.'/inc');
cmdb_rmdir(PLUGINCMDB_DOC_DIR.'/inc');
}
//PluginCmdbMenu::removeRightsFromSession();
PluginCmdbProfile::removeRightsFromSession();
Expand Down Expand Up @@ -333,14 +333,14 @@ function plugin_cmdb_giveItem($type, $ID, $data, $num) {
return "";
}

function rrmdir($dir) {
function cmdb_rmdir($dir) {

if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") {
rrmdir($dir."/".$object);
cmdb_rmdir($dir."/".$object);
} else {
unlink($dir."/".$object);
}
Expand Down
4 changes: 2 additions & 2 deletions inc/ci.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ function showForm($ID, $options = []) {
$this->showFormHeader($options);

echo "<tr class='tab_bg_1'>";

echo "<td>" . __('Name') . "</td>";
echo "<td>";
Html::autocompletionTextField($this, "name");
echo "</td>";
echo "</tr>";

echo "<tr class='tab_bg_1 fieldCI'>";
echo "<td>" . PluginCmdbCIType::getTypeName(1) . "</td>";
echo "<td>";
$idType = $this->setSelectCITypes($ID);
echo "</td>";

echo "</tr>";

$cifields = new PluginCmdbCifields();
if (!isset($this->fields["plugin_cmdb_citypes_id"])
|| $this->fields["plugin_cmdb_citypes_id"] == "") {
Expand Down
1 change: 1 addition & 0 deletions inc/cifields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static function setValue($typefield, $value) {
/**
* @param $idType
* @param $id
* @param $itemtype
*/
function setFieldByType($idType, $id,$itemtype) {

Expand Down
2 changes: 2 additions & 0 deletions inc/citype.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ function showForm($ID, $options = []) {
echo __("Be careful the name cannot be changed after creation", "cmdb");
echo "<br>";
echo __("Do not use a plural classname (like 'myobjects')", "cmdb");
echo "<br>";
echo __("Do not use a classname with spaces (like 'my objects')", "cmdb");
echo "</div>";
echo "</td>";
echo "</tr>";
Expand Down
110 changes: 47 additions & 63 deletions inc/cmdb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ public static function getTypeName($nb = 0) {
function displayMenu() {
global $CFG_GLPI;

echo "<div class='center'>";
echo "<table class='tab_cadre'>";
echo "<tr>";
echo "<th colspan='6'>" . __("Display Item Configuration", 'cmdb') . "</th>";
echo "</tr>";
echo "<tr>";

$this->displayCIMenuCMDB(__("Display Item Configuration", 'cmdb'), "ci.php", "iconCI.png");
echo "</tr>";
// echo "<tr class='tab_bg_1'>";
// $this->displayItemMenuCMDB(__("Configure links", 'cmdb'), "typelink.php", "iconTypelink.png");
// $this->displayItemMenuCMDB(__("Display Baseline", 'cmdb'), "baseline.php", "iconBaseline.png");
// echo "</tr>";
echo "</table>";
echo "</div>";
}

/**
* @param $title
* @param $url
* @param $nameIcon
*/
function displayCIMenuCMDB($title, $url, $nameIcon) {
global $DB, $CFG_GLPI;

Html::requireJs('cmdb');

$dbu = new DbUtils();
Expand All @@ -95,49 +70,57 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
$entities = $entity;
$recursive = false;
}
$where = $dbu->getEntitiesRestrictCriteria("glpi_plugin_cmdb_citypes", '', $entities, $recursive);
$where = $dbu->getEntitiesRestrictCriteria("glpi_plugin_cmdb_citypes", '', $entities, $recursive);
}

$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) {

echo "<div class='center'>";
echo "<table class='tab_cadre' width='30%'>";
echo "<tr>";
echo "<th colspan='6'>" . __("Display Item Configuration", 'cmdb') . "</th>";
echo "</tr>";
echo "<tr>";

$tabCIType = [];
foreach ($ciTypes as $data) {
$id = $data["id"];
$name = $data["name"];

// if ($data["is_imported"]) {
if ($item = $dbu->getItemForItemtype($data["name"])) {
$item = $dbu->getItemForItemtype($data["name"]);
$name = $item::getTypeName(1);
if (!array_search($name, $tabCIType)) {
$tabCIType[$id] = $name;
}
// if ($data["is_imported"]) {
if ($item = $dbu->getItemForItemtype($data["name"])) {
$item = $dbu->getItemForItemtype($data["name"]);
$name = $item::getTypeName(1);
if (!array_search($name, $tabCIType)) {
$tabCIType[$id] = $name;
}
// } else {
// if (!array_search($name, $tabCIType)) {
// $tabCIType[$id] = $name;
// }
// }
}
// } else {
// if (!array_search($name, $tabCIType)) {
// $tabCIType[$id] = $name;
// }
// }
}
if (count($tabCIType) > 0) {
// $boucle = intval(count($tabCIType) / 3);
// $boucle = intval(count($tabCIType) / 3);
$reste = count($tabCIType) % 3;
$i = 0;
foreach ($tabCIType as $id => $val){
$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"]) {
&& $citype->fields["is_imported"]) {
$link = Toolbox::getItemTypeSearchURL($citype->fields["name"]);
} else {
$link = $citype->fields["name"]::getSearchURL();
Expand All @@ -146,16 +129,15 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
echo "<td class='center b' colspan='2' >";
echo "<a href='$link'>";
if ($citype_doc->getFromDBByCrit(['plugin_cmdb_citypes_id' => $id,
'types_id' => 0])) {
'types_id' => 0])) {

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

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


echo "<br/>";
echo $val;
echo "</a>";
Expand All @@ -164,30 +146,29 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
$i++;
if ($i % 3 == 0) {
echo "</tr>";

}
}

if ($i % 3 != 0) {
$j = 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.'});');
// 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 All @@ -196,5 +177,8 @@ function displayCIMenuCMDB($title, $url, $nameIcon) {
}

echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
}
}
2 changes: 1 addition & 1 deletion inc/menu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static function getMenuContent() {
$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';
$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
10 changes: 2 additions & 8 deletions templates/citype.class.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,12 @@ class %%CLASSNAME%% extends CommonDropdown {
Html::autocompletionTextField($this, "name");
echo "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>";
echo "</td>";
echo "</tr>";
$cifields = new PluginCmdbCifields();
$cifields->setFieldByType(%%TYPE%%, $ID, self::getType());
$this->showFormButtons($options);
$this->showFormButtons($options);
return true;
return true;
}

/**
Expand Down

0 comments on commit d537fc4

Please sign in to comment.