@@ -425,62 +425,68 @@ function plugin_formcreator_redirect() {
425425 return ;
426426 }
427427
428+ if (!plugin_formcreator_replaceHelpdesk ()) {
429+ return ;
430+ }
431+
428432 if (strpos ($ _SERVER ['REQUEST_URI ' ], "front/ticket.form.php " ) !== false ) {
429- if (!isset ($ _POST ['update ' ]) && plugin_formcreator_replaceHelpdesk ()) {
430- $ decodedUrl = [];
431- $ openItilFollowup = '' ;
432- if (isset ($ _GET ['_openfollowup ' ])) {
433- $ openItilFollowup = '&_openfollowup=1 ' ;
434- }
435- if (isset ($ _SERVER ['QUERY_STRING ' ])) {
436- parse_str ($ _SERVER ['QUERY_STRING ' ], $ decodedUrl );
437- if (isset ($ decodedUrl ['forcetab ' ])) {
438- Session::setActiveTab (Ticket::class, $ decodedUrl ['forcetab ' ]);
439- }
440- }
441- if (!isset ($ _GET ['id ' ])) {
442- // invalid url
443- Html::redirect ($ CFG_GLPI ["root_doc " ]);
444- }
433+ if (isset ($ _POST ['update ' ]) || isset ($ _POST ['delete ' ])) {
434+ return ;
435+ }
445436
446- // When an ticket has a matching issue (it means that the ticket is the only generated ticket)
447- $ issue = new PluginFormcreatorIssue ();
448- $ issues = $ issue ->find ([
449- 'itemtype ' => Ticket::class,
450- 'items_id ' => (int ) $ _GET ['id ' ]
451- ]);
452- if (count ($ issues ) == 1 ) {
453- $ issueId = array_pop ($ issues )['id ' ];
454- $ issue ->getFromDB ($ issueId );
455- Html::redirect ($ issue ->getFormURLWithID ($ issue ->getID ()) . $ openItilFollowup );
437+ $ decodedUrl = [];
438+ $ openItilFollowup = '' ;
439+ if (isset ($ _GET ['_openfollowup ' ])) {
440+ $ openItilFollowup = '&_openfollowup=1 ' ;
441+ }
442+ if (isset ($ _SERVER ['QUERY_STRING ' ])) {
443+ parse_str ($ _SERVER ['QUERY_STRING ' ], $ decodedUrl );
444+ if (isset ($ decodedUrl ['forcetab ' ])) {
445+ Session::setActiveTab (Ticket::class, $ decodedUrl ['forcetab ' ]);
456446 }
447+ }
448+ if (!isset ($ _GET ['id ' ])) {
449+ // invalid url
450+ Html::redirect ($ CFG_GLPI ["root_doc " ]);
451+ }
457452
458- // When no or several tickets matches an issue, rely use the Form Answer
459- $ itemTicket = new Item_Ticket ();
460- $ itemTicket ->getFromDBByCrit ([
461- 'itemtype ' => PluginFormcreatorFormAnswer::class,
462- 'tickets_id ' => (int ) $ _GET ['id ' ]
463- ]);
464- if ($ itemTicket ->isNewItem ()) {
465- // No formanswer found
466- Html::displayNotFoundError ();
467- }
453+ // When an ticket has a matching issue (it means that the ticket is the only generated ticket)
454+ $ issue = new PluginFormcreatorIssue ();
455+ $ issues = $ issue ->find ([
456+ 'itemtype ' => Ticket::class,
457+ 'items_id ' => (int ) $ _GET ['id ' ]
458+ ]);
459+ if (count ($ issues ) == 1 ) {
460+ $ issueId = array_pop ($ issues )['id ' ];
461+ $ issue ->getFromDB ($ issueId );
462+ Html::redirect ($ issue ->getFormURLWithID ($ issue ->getID ()) . $ openItilFollowup );
463+ }
468464
469- $ issue ->getFromDBByCrit ([
470- 'itemtype ' => PluginFormcreatorFormAnswer::class,
471- 'items_id ' => $ itemTicket ->fields ['items_id ' ]
472- ]);
473- if ($ issue ->isNewItem ()) {
474- // No formanswer found
475- Html::displayNotFoundError ();
476- }
477- $ ticket = Ticket::getById ($ itemTicket ->fields ['tickets_id ' ]);
478- if ($ ticket === false ) {
479- Html::redirect ($ issue ->getFormURLWithID ($ itemTicket ->fields ['items_id ' ]) . $ openItilFollowup );
480- }
465+ // When no or several tickets matches an issue, rely use the Form Answer
466+ $ itemTicket = new Item_Ticket ();
467+ $ itemTicket ->getFromDBByCrit ([
468+ 'itemtype ' => PluginFormcreatorFormAnswer::class,
469+ 'tickets_id ' => (int ) $ _GET ['id ' ]
470+ ]);
471+ if ($ itemTicket ->isNewItem ()) {
472+ // No formanswer found
473+ Html::displayNotFoundError ();
474+ }
481475
482- Html::redirect ($ issue ->getFormURLWithID ($ issue ->getID ()) . '&tickets_id= ' . $ itemTicket ->fields ['tickets_id ' ]);
476+ $ issue ->getFromDBByCrit ([
477+ 'itemtype ' => PluginFormcreatorFormAnswer::class,
478+ 'items_id ' => $ itemTicket ->fields ['items_id ' ]
479+ ]);
480+ if ($ issue ->isNewItem ()) {
481+ // No formanswer found
482+ Html::displayNotFoundError ();
483483 }
484+ $ ticket = Ticket::getById ($ itemTicket ->fields ['tickets_id ' ]);
485+ if ($ ticket === false ) {
486+ Html::redirect ($ issue ->getFormURLWithID ($ itemTicket ->fields ['items_id ' ]) . $ openItilFollowup );
487+ }
488+
489+ Html::redirect ($ issue ->getFormURLWithID ($ issue ->getID ()) . '&tickets_id= ' . $ itemTicket ->fields ['tickets_id ' ]);
484490 }
485491}
486492
0 commit comments