Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type and Model Fields errors when the item is not a computer #7

Open
LordBat opened this issue Mar 15, 2018 · 2 comments
Open

Type and Model Fields errors when the item is not a computer #7

LordBat opened this issue Mar 15, 2018 · 2 comments

Comments

@LordBat
Copy link

LordBat commented Mar 15, 2018

Hi, is posible to get the model and type field based on the type of inventory?

For example i search a peripheral item and i get

on Type:
PHP Notice: Undefined index: computertypes_id in /var/www/html/glpi/plugins/physicalinv/inc/inventory.class.php at line 243

on Model:
PHP Notice: Undefined index: computermodels_id in /var/www/html/glpi/plugins/physicalinv/inc/inventory.class.php at line 271

Regards!

@abohicham
Copy link

solution:

////delete line 243 and add:

echo "";
echo "".__('Type')."";
echo "";
$type = $itemtype.'Type';
if (TableExists(getTableForItemType($type))) {

     if($item->getTypeName()=="Ordinateur")
            $type::dropdown(array('value' => $item->fields["computertypes_id"]));
else if ($item->getTypeName()=="Moniteur")
           $type::dropdown(array('value' => $item->fields["monitortypes_id"]));
else if ($item->getTypeName()=="Imprimante")
             $type::dropdown(array('value' => $item->fields["printertypes_id"]));
else if ($item->getTypeName()=="Périphérique")
             $type::dropdown(array('value' => $item->fields["peripheraltypes_id"]));
else if ($item->getTypeName()=="Téléphone")
             $type::dropdown(array('value' => $item->fields["phonetypes_id"]));
else if ($item->getTypeName()=="Matériel réseau")
             $type::dropdown(array('value' => $item->fields["networkequipmenttypes_id"]));
else if ($item->getTypeName()=="Scannersdocument")
             $type::dropdown(array('value' => $item->fields["plugin_genericobject_scannersdocumenttypes_id"]));
else if ($item->getTypeName()=="Scannerscheque")
             $type::dropdown(array('value' => $item->fields["plugin_genericobject_scannerschequetypes_id"]));
 }

else {
echo "";
echo "";
}
echo "\n";

////delete line 271 and add:

echo "</textarea>";
$model = $itemtype.'Model';
if (TableExists(getTableForItemType($model))) {

     echo "<td>";
     echo __('Model');
     echo "</td>";
     echo "<td>";
     if($item->getTypeName()=="Ordinateur")
             $model::dropdown(array('value' => $item->fields["computermodels_id"]));
     else if ($item->getTypeName()=="Moniteur")
             $model::dropdown(array('value' => $item->fields["monitormodels_id"]));
     else if ($item->getTypeName()=="Imprimante")
             $model::dropdown(array('value' => $item->fields["printermodels_id"]));
     else if ($item->getTypeName()=="Périphérique")
             $model::dropdown(array('value' => $item->fields["peripheralmodels_id"]));
     else if ($item->getTypeName()=="Téléphone")
             $model::dropdown(array('value' => $item->fields["phonemodels_id"]));
     else if ($item->getTypeName()=="Matériel réseau")
             $model::dropdown(array('value' => $item->fields["networkequipmentmodels_id"]));
     else if ($item->getTypeName()=="Scannersdocument")
             $model::dropdown(array('value' => $item->fields["plugin_genericobject_scannersdocumentmodels_id"]));
     else if ($item->getTypeName()=="Scannerscheque")
             $model::dropdown(array('value' => $item->fields["plugin_genericobject_scannerschequemodels_id"]));
     echo "</td>";

  } else {
                                                                  echo "<td colspan='2'></td>";
                                                                        }
  echo "</tr>";

@Rafit77
Copy link

Rafit77 commented Sep 8, 2019

I suggest another solution:

if ($DB->tableExists(getTableForItemType($model))) {
         $fk = getForeignKeyFieldForTable(getTableForItemType($model));
           ...
         $model::dropdown(array('value' => $item->fields["computermodels_id"]));

It is more flexible, it works with General Object plugins and doesn't need any names which depend from system language.

You can check my pull proposal for whole code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants