@@ -471,23 +471,39 @@ function AMP_AdminServicesTabFields(array $params)
471471 }
472472 return [
473473 'State ' => $ instance ['Running ' ] ? 'Running ' : 'Stopped ' ,
474- 'Instance ID ' => $ service ->instanceId ,
475- 'Target ID ' => $ service ->targetId ,
474+ 'Instance ID ' => '<input type="hidden" name="amp_original_instanceId" value=" ' . htmlspecialchars ($ service ->instanceId ) . '" /> '
475+ . '<input type="text" name="amp_instance_id" value=" ' . htmlspecialchars ($ service ->instanceId ) . '" /> ' ,
476+ 'Target ID ' => '<input type="hidden" name="amp_original_targetId" value=" ' . htmlspecialchars ($ service ->targetId ) . '" /> '
477+ . '<input type="text" name="amp_target_id" value=" ' . htmlspecialchars ($ service ->targetId ) . '" /> ' ,
476478 ] + $ vars ;
477479
478480 } catch (\Exception $ e ) {
479481 return ['Error ' => $ e ->getMessage ()];
480- }
481-
482-
483-
484-
485-
486-
482+ }
487483 }
488484 return [];
489485}
490486
487+ function AMP_AdminServicesTabFieldsSave (array $ params )
488+ {
489+ if (isset ($ _POST ['amp_original_instanceId ' ]) && isset ($ _POST ['amp_original_targetId ' ])) {
490+ $ existingInstanceId = $ _POST ['amp_original_instanceId ' ];
491+ $ existingTargetId = $ _POST ['amp_original_targetId ' ];
492+ $ newInstanceId = isset ($ _POST ['amp_instance_id ' ]) ? trim ($ _POST ['amp_instance_id ' ]) : '' ;
493+ $ newTargetId = isset ($ _POST ['amp_target_id ' ]) ? trim ($ _POST ['amp_target_id ' ]) : '' ;
494+ if ($ newInstanceId != $ existingInstanceId || $ newTargetId != $ existingTargetId ) {
495+ $ updateFields = [];
496+ if ($ newInstanceId != $ existingInstanceId ) {
497+ $ updateFields ['instanceId ' ] = $ newInstanceId ;
498+ }
499+ if ($ newTargetId != $ existingTargetId ) {
500+ $ updateFields ['targetId ' ] = $ newTargetId ;
501+ }
502+ Capsule::table ('ampServices ' )->where ('serviceId ' , $ params ['serviceid ' ])->update ($ updateFields );
503+ }
504+ }
505+ }
506+
491507function AMP_ClientArea (array $ params )
492508{
493509
@@ -522,6 +538,12 @@ function AMP_ClientArea(array $params)
522538 $ m = ($ result == 'success ' ) ? 'Application password has ben reseted successfully ' : $ result ;
523539 echo json_encode (['result ' => $ r , 'message ' => $ m ]);
524540 break ;
541+ case 'ClearInstanceFromWHMCS ' :
542+ $ result = AMP_ClearInstanceFromWHMCS ($ params );
543+ $ r = ($ result == 'success ' ) ? 'success ' : 'failure ' ;
544+ $ m = ($ result == 'success ' ) ? 'Dismissed tasks ' : $ result ;
545+ echo json_encode (['result ' => $ r , 'message ' => $ m ]);
546+ break ;
525547 }
526548 die;
527549 }
@@ -565,6 +587,7 @@ function AMP_AdminCustomButtonArray()
565587 "Stop Instance " => "stopInstance " ,
566588 "Restart Instance " => "restartInstance " ,
567589 "Reset Password " => "resetPassword " ,
590+ "Clear Instance " => "ClearInstanceFromWHMCS " ,
568591 );
569592}
570593
@@ -687,3 +710,17 @@ function AMP_commercialCheck(array $params)
687710 }
688711}
689712
713+ function AMP_ClearInstanceFromWHMCS (array $ params )
714+ {
715+ try {
716+ $ service = Capsule::table ('ampServices ' )->where ('serviceId ' , $ params ['serviceid ' ])->first ();
717+ Capsule::table ('ampServices ' )->where ('serviceId ' , $ params ['serviceid ' ])->delete ();
718+
719+ //removeOldTasks($client);
720+
721+ return 'success ' ;
722+
723+ } catch (\Exception $ e ) {
724+ return $ e ->getMessage ();
725+ }
726+ }
0 commit comments