Skip to content

Commit

Permalink
Showing 8 changed files with 14 additions and 33 deletions.
10 changes: 4 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
@@ -108,7 +108,6 @@ function plugin_fields_install() {
* @return boolean
*/
function plugin_fields_uninstall() {
global $DB;

if (!class_exists('PluginFieldsProfile')) {
Session::addMessageAfterRedirect(__("The plugin can't be uninstalled when the plugin is disabled", 'fields'),
@@ -219,16 +218,16 @@ function plugin_fields_MassiveActionsFieldsDisplay($options = []) {
*
* Actions for rules
* @since 0.84
* @param $params input data
* @return an array of actions
* @param array $params input data
* @return array an array of actions
*/
function plugin_fields_getRuleActions($params = []) {
$actions = [];

switch ($params['rule_itemtype']) {
case "PluginFusioninventoryTaskpostactionRule":
$options = PluginFieldsContainer::getAddSearchOptions("Computer");
foreach ($options as $num => $option) {
foreach ($options as $option) {
$actions[$option['linkfield']]['name'] = $option['name'];
$actions[$option['linkfield']]['type'] = $option['pfields_type'];
if ($option['pfields_type'] == 'dropdown') {
@@ -288,7 +287,6 @@ function plugin_fields_rule_matched($params = []) {
function plugin_fields_giveItem($itemtype, $ID, $data, $num) {
$searchopt = &Search::getOptions($itemtype);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];

//fix glpi default Search::giveItem who for empty date display "--"
if (strpos($table, "glpi_plugin_fields") !== false
@@ -310,7 +308,7 @@ function plugin_datainjection_populate_fields() {

$container = new PluginFieldsContainer();
$found = $container->find(['is_active' => 1]);
foreach ($found as $id => $values) {
foreach ($found as $values) {
$types = json_decode($values['itemtypes']);

foreach ($types as $type) {
1 change: 1 addition & 0 deletions inc/autoload.php
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ public function setOptions($options) {
}

public function processClassname($classname) {
$matches = [];
preg_match("/Plugin([A-Z][a-z0-9]+)([A-Z]\w+)/", $classname, $matches);

if (count($matches) < 3) {
16 changes: 6 additions & 10 deletions inc/container.class.php
Original file line number Diff line number Diff line change
@@ -253,8 +253,8 @@ static function uninstall() {
//uninstall container table and class
$obj = new self;
$containers = $obj->find();
foreach ($containers as $containers_id => $container) {
$obj->delete(['id' => $containers_id]);
foreach ($containers as $container) {
$obj->delete(['id' => $container['id']]);
}

//drop global container table
@@ -751,8 +751,6 @@ public function showForm($ID, $options = []) {
}

static function showFormItemtype($params = []) {
global $CFG_GLPI;

$is_domtab = isset($params['type']) && $params['type'] == 'domtab';

$rand = $params['rand'];
@@ -800,7 +798,7 @@ static function showFormSubtype($params, $display = false) {
}

// For delete <sup class='tab_nb'>number</sup> :
foreach ($tabs as $key => &$value) {
foreach ($tabs as &$value) {
$results = [];
if (preg_match_all('#<sup.*>(.+)</sup>#', $value, $results)) {
$value = str_replace($results[0][0], "", $value);
@@ -909,7 +907,7 @@ static function getEntries($type = 'tab', $full = false) {

$jsonitemtypes = json_decode($item['itemtypes']);
//show more info or not
foreach ($jsonitemtypes as $k => $v) {
foreach ($jsonitemtypes as $v) {
if ($full) {
//check for translation
$item['itemtype'] = self::getType();
@@ -997,8 +995,6 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
* @return boolean
*/
function updateFieldsValues($data, $itemtype, $massiveaction = false) {
global $DB;

if (self::validateValues($data, $itemtype, $massiveaction) === false) {
return false;
}
@@ -1040,7 +1036,7 @@ function updateFieldsValues($data, $itemtype, $massiveaction = false) {
* @param string $itemtype item type
* @param array $data values send by update form
* @param array $old_values old values, if empty -> values add
* @return nothing
* @return void
*/
static function constructHistory($containers_id, $items_id, $itemtype, $data,
$old_values = []) {
@@ -1165,7 +1161,7 @@ static function validateValues($data, $itemtype, $massiveaction) {
'plugin_fields_containers_id' => $data['plugin_fields_containers_id']
]);

foreach ($fields as $fields_id => $field) {
foreach ($fields as $field) {
if (!$field['is_active']) {
continue;
}
2 changes: 1 addition & 1 deletion inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
@@ -308,7 +308,7 @@ public static function removeBlackListedOption($array, $itemtype_class){
$allowed_table = [getTableForItemType($itemtype_class), getTableForItemType(User::getType()), getTableForItemType(Group::getType())];

//use relation.constant.php to allow some tables (exclude Location which is managed later)
foreach (getDbRelations() as $tablename => $relation) {
foreach (getDbRelations() as $relation) {
foreach ($relation as $main_table => $foreignKey) {
if($main_table == getTableForItemType($itemtype_class)
&& !is_array($foreignKey)
10 changes: 0 additions & 10 deletions inc/field.class.php
Original file line number Diff line number Diff line change
@@ -196,8 +196,6 @@ function prepareInputForAdd($input) {
}

function pre_deleteItem() {
global $DB;

//remove field in container table
if ($this->fields['type'] !== "header"
&& !isset($_SESSION['uninstall_fields'])
@@ -299,7 +297,6 @@ function getNextRanking() {

function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate) {
$nb = 0;
switch ($item->getType()) {
case __CLASS__ :
$ong[1] = $this->getTypeName(1);
@@ -332,9 +329,6 @@ function showSummary($container) {
$cID = $container->fields['id'];

// Display existing Fields
$tmp = ['plugin_fields_containers_id' => $cID];
$canadd = $this->can(-1, CREATE, $tmp);

$query = "SELECT `id`, `label`
FROM `".$this->getTable()."`
WHERE `plugin_fields_containers_id` = '$cID'
@@ -595,8 +589,6 @@ function ($itemtype) {
}

static function showForTabContainer($c_id, $items_id, $itemtype) {
global $CFG_GLPI;

//profile restriction (for reading profile)
$profile = new PluginFieldsProfile;
$found = $profile->find(['profiles_id' => $_SESSION['glpiactiveprofile']['id'],
@@ -667,8 +659,6 @@ static private function showDomContainer($c_id, $itemtype, $items_id, $type = "d
* @return void
*/
static function showForTab($params) {
global $CFG_GLPI;

$item = $params['item'];

$functions = array_column(debug_backtrace(), 'function');
2 changes: 1 addition & 1 deletion inc/inventory.class.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ static function updateInventory($params = []) {
&& isset($params['inventory_data']) && !empty($params['inventory_data'])) {

$availaibleItemType = ["Computer","Printer","NetworkEquipment"];
foreach ($params['inventory_data'] as $itemtype => $inventories) {
foreach (array_keys($params['inventory_data']) as $itemtype) {

if (in_array($itemtype, $availaibleItemType)) {
//retrive items id switch itemtype
4 changes: 0 additions & 4 deletions inc/labeltranslation.class.php
Original file line number Diff line number Diff line change
@@ -134,8 +134,6 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
* @return void
**/
static function showTranslations(CommonDBTM $item) {
global $DB, $CFG_GLPI;

$canedit = $item->can($item->getID(), UPDATE);
$rand = mt_rand();
if ($canedit) {
@@ -238,8 +236,6 @@ static function showTranslations(CommonDBTM $item) {
* @return void
*/
function showFormForItem($itemtype, $items_id, $id = -1) {
global $CFG_GLPI;

if ($id > 0) {
$this->check($id, READ);
} else {
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
@@ -315,7 +315,7 @@ function plugin_fields_exportBlockAsYaml($container_id = null) {
$dropdown_obj = new $dropdown_itemtype();
$dropdown_datas = $dropdown_obj->find();
$datas = [];
foreach ($dropdown_datas as $key => $value) {
foreach ($dropdown_datas as $value) {
$items = [];
$items['id'] = (int)$value['id'];
$items['value'] = $value['name'];

0 comments on commit 5691edd

Please sign in to comment.