@@ -258,26 +258,22 @@ public static function rawSearchOptionsToAdd()
258
258
**/
259
259
public function showForm ($ ID , array $ options = [])
260
260
{
261
- $ itemtype = $ this ->fields ['itemtype ' ];
262
-
263
- if (!Session::haveRight ($ itemtype ::$ rightname , READ )) {
264
- return false ;
265
- }
266
-
267
- if (!is_a ($ itemtype , CommonDBTM::class, true )) {
268
- return false ;
261
+ if (isset ($ options ['parent ' ])) {
262
+ $ options ['itemtype ' ] = $ options ['parent ' ]::class;
263
+ $ options ['items_id ' ] = $ options ['parent ' ]->getID ();
269
264
}
270
265
271
- $ asset = new $ itemtype ();
272
266
if ($ ID > 0 ) {
267
+ $ asset = getItemForItemtype ($ this ->fields ['itemtype ' ]);
273
268
$ this ->check ($ ID , READ );
274
269
$ asset ->getFromDB ($ this ->fields ['items_id ' ]);
275
270
} else {
271
+ $ asset = getItemForItemtype ($ options ['itemtype ' ]);
276
272
$ this ->check (-1 , CREATE , $ options );
277
273
$ asset ->getFromDB ($ options ['items_id ' ]);
278
274
}
279
275
280
- $ options ['canedit ' ] = Session:: haveRight ( $ itemtype :: $ rightname , UPDATE );
276
+ $ options ['canedit ' ] = $ asset -> can ( $ asset -> getID () , UPDATE );
281
277
$ this ->initForm ($ ID , $ options );
282
278
TemplateRenderer::getInstance ()->display ('components/form/item_antivirus.html.twig ' , [
283
279
'item ' => $ this ,
@@ -323,11 +319,15 @@ private static function showForItem(CommonDBTM $asset, $withtemplate = 0)
323
319
]
324
320
);
325
321
326
- TemplateRenderer::getInstance ()->display ('components/form/item_antivirus_item.html.twig ' , [
327
- 'canedit ' => ($ canedit && !(!empty ($ withtemplate ) && ($ withtemplate == 2 ))),
328
- 'has_antivirus ' => ($ result ->numrows () != 0 ),
329
- 'antivirus_form_url ' => ItemAntivirus::getFormURL () .
330
- "?itemtype= $ itemtype&items_id= $ ID &withtemplate= " . $ withtemplate ,
322
+ TemplateRenderer::getInstance ()->display ('components/form/viewsubitem.html.twig ' , [
323
+ 'type ' => self ::class,
324
+ 'parenttype ' => $ itemtype ,
325
+ 'items_id ' => $ asset ::getForeignKeyField (),
326
+ 'id ' => $ ID ,
327
+ 'cancreate ' => ($ canedit && !(!empty ($ withtemplate ) && ($ withtemplate == 2 ))),
328
+ 'add_new_label ' => __ ('Add an antivirus ' ),
329
+ 'ajax_form_submit ' => true ,
330
+ 'reload_tab ' => true ,
331
331
]);
332
332
333
333
$ antivirus = new self ();
0 commit comments