diff --git a/www/domain-plan.php b/www/domain-plan.php index 447a9f2..6fece31 100644 --- a/www/domain-plan.php +++ b/www/domain-plan.php @@ -1,105 +1,117 @@ . /* * This is the single e-mail forwarding edit page */ // load framework require '../load.php'; // wanted informations from the templates $domain = null; $plan = null; // URL paramenters (just domain) list( $domain_name ) = url_parts( 1 ); // eventually retrieve domain from database $domain = ( new DomainAPI() ) ->select( [ 'domain.domain_ID', 'domain_name', 'plan.plan_ID', 'plan_name', 'plan_mailboxes', 'plan_mailforwards', 'plan_databases', 'plan_ftpusers', 'plan_mailboxquota', 'plan_yearlyprice', ] ) ->whereDomainName( $domain_name ) ->whereDomainIsVisible() ->joinPlan( 'LEFT' ) ->queryRow(); // no domain no party if( !$domain ) { PageNotFound::spawn(); } // save destination action if( is_action( 'domain-plan-save' ) ) { // check privileges require_permission( 'edit-domain-all' ); // check if the submitted request has sense $new_plan_uid = $_POST['plan_uid'] ?? null; if( !$new_plan_uid || !is_string( $new_plan_uid ) ) { BadRequest::spawn(); } // check if the new Plan exists $new_plan = ( new PlanAPI() ) ->wherePlanUID( $new_plan_uid ) ->queryRow(); // no Plan no party if( !$new_plan ) { BadRequest::spawn( __( "Missing Plan" ) ); } + query( 'START TRANSACTION' ); + // finally update the Plan ( new DomainAPI() ) ->whereDomain( $domain ) ->update( [ 'plan_ID' => $new_plan->getPlanID(), ] ); + // register this event + APILog::insert( [ + 'family' => 'domain', + 'action' => 'plan.change', + 'domain' => $domain, + 'plan' => $new_plan, + ] ); + + query( 'COMMIT' ); + // POST -> REDIRECT -> GET http_redirect( $domain->getDomainPlanPermalink() ); } // spawn header Header::spawn( [ 'uid' => false, 'title' => __( "Domain Plan" ), 'breadcrumb' => [ new MenuEntry( null, $domain->getDomainPermalink(), $domain->getDomainName() ), ], ] ); // spawn the page content template( 'domain-plan-page', [ 'domain' => $domain, 'plan' => $domain, ] ); // spawn the footer Footer::spawn();