529
529
if (isset ($ _GET ['get_readable_pass ' ])) {
530
530
echo json_encode (GenerateReadablePassword (4 ));
531
531
}
532
+
533
+ /*
534
+ * ITFlow - POST request handler for client tickets
535
+ */
536
+ if (isset ($ _POST ['update_kanban_status_position ' ])) {
537
+ // Update multiple ticket status kanban orders
538
+ enforceUserPermission ('module_support ' , 2 );
539
+
540
+ $ positions = $ _POST ['positions ' ];
541
+
542
+ foreach ($ positions as $ position ) {
543
+ $ status_id = intval ($ position ['status_id ' ]);
544
+ $ kanban = intval ($ position ['status_kanban ' ]);
545
+
546
+ mysqli_query ($ mysqli , "UPDATE ticket_statuses SET ticket_status_order = $ kanban WHERE ticket_status_id = $ status_id " );
547
+ }
548
+
549
+ // return a response
550
+ echo json_encode (['status ' => 'success ' ]);
551
+ exit ;
552
+ }
553
+
554
+ if (isset ($ _POST ['update_kanban_ticket ' ])) {
555
+ // Update ticket kanban order and status
556
+ enforceUserPermission ('module_support ' , 2 );
557
+
558
+
559
+ // have to do new logic, to update only one dragged ticket
560
+ $ positions = $ _POST ['positions ' ]; //old and new position
561
+
562
+
563
+
564
+
565
+ // old logic that updated all tickets on the column
566
+ $ positions = $ _POST ['positions ' ];
567
+
568
+ foreach ($ positions as $ position ) {
569
+ $ ticket_id = intval ($ position ['ticket_id ' ]);
570
+ $ kanban = intval ($ position ['ticket_kanban ' ]); // ticket kanban position
571
+ $ status = intval ($ position ['ticket_status ' ]); // ticket statuses
572
+ $ oldStatus = intval ($ position ['ticket_oldStatus ' ]); // ticket old status if moved
573
+
574
+ $ statuses ['Closed ' ] = 5 ;
575
+ $ statuses ['Resolved ' ] = 4 ;
576
+
577
+ // Continue if status is null / Closed
578
+ if ($ status === null || $ status === $ statuses ['Closed ' ]) {
579
+ continue ;
580
+ }
581
+
582
+
583
+ if ($ oldStatus === false ) {
584
+ // if ticket was not moved, just uptdate the order on kanban
585
+ mysqli_query ($ mysqli , "UPDATE tickets SET ticket_kanban = $ kanban WHERE ticket_id = $ ticket_id " );
586
+ customAction ('ticket_update ' , $ ticket_id );
587
+ } else {
588
+ // If the ticket was moved from a resolved status to another status, we need to update ticket_resolved_at
589
+ if ($ oldStatus === $ statuses ['Resolved ' ]) {
590
+ mysqli_query ($ mysqli , "UPDATE tickets SET ticket_kanban = $ kanban, ticket_status = $ status, ticket_resolved_at = NULL WHERE ticket_id = $ ticket_id " );
591
+ customAction ('ticket_update ' , $ ticket_id );
592
+ } elseif ($ status === $ statuses ['Resolved ' ]) {
593
+ // If the ticket was moved to a resolved status, we need to update ticket_resolved_at
594
+ mysqli_query ($ mysqli , "UPDATE tickets SET ticket_kanban = $ kanban, ticket_status = $ status, ticket_resolved_at = NOW() WHERE ticket_id = $ ticket_id " );
595
+ customAction ('ticket_update ' , $ ticket_id );
596
+ } else {
597
+ // If the ticket was moved from any status to another status
598
+ mysqli_query ($ mysqli , "UPDATE tickets SET ticket_kanban = $ kanban, ticket_status = $ status WHERE ticket_id = $ ticket_id " );
599
+ customAction ('ticket_update ' , $ ticket_id );
600
+ }
601
+ }
602
+
603
+ }
604
+
605
+ // return a response
606
+ echo json_encode (['status ' => 'success ' ,'payload ' => $ positions ]);
607
+ exit ;
608
+ }
0 commit comments