/**
 * get transaction page html
 *
 * @param bool $return
 * @return string
 * @since 1.5
 */
function mgm_get_transaction_page_html($return = false, $method = NULL)
{
    // get method
    if (!$method) {
        $method = mgm_request_var('method', '', true);
    }
    // switch $method
    switch ($method) {
        case 'payment_return':
            // after payment return with get/post values and process
        // after payment return with get/post values and process
        case 'payment_notify':
            // silent post back, IPN, just after first payment
        // silent post back, IPN, just after first payment
        case 'payment_status_notify':
            // INS, post back, at each payment cycle,i.e, 2CO INS, PayPal IPN
        // INS, post back, at each payment cycle,i.e, 2CO INS, PayPal IPN
        case 'payment_cancel':
            // cancelled
        // cancelled
        case 'payment_unsubscribe':
            // unsubscribe tracking
        // unsubscribe tracking
        case 'payment_html_redirect':
            // proxy for html redirect
        // proxy for html redirect
        case 'payment_credit_card':
            // proxy for credit_card processing
            // get module
            $module = mgm_request_var('module', '', true);
            // validate module
            if ($module_obj = mgm_is_valid_module($module, 'payment', 'object')) {
                // process, invoke process_return,process_notify,process_cancel,process_unsubscribe
                $output = $module_obj->invoke(str_replace(array('payment_'), 'process_', $method));
                // html redirect
                if ($method == 'payment_html_redirect') {
                    // set in globals
                    $GLOBALS['mgm_html_outout'] = $output;
                    // if template exists
                    if ($return) {
                        $template_file = MGM_CORE_DIR . 'html/payment_processing_return.php';
                    } else {
                        if (file_exists(TEMPLATEPATH . '/payment_processing.php')) {
                            $template_file = TEMPLATEPATH . '/payment_processing.php';
                        } else {
                            $template_file = MGM_CORE_DIR . 'html/payment_processing.php';
                        }
                    }
                    // apply template filter
                    $template_file = apply_filters('mgm_page_template', $template_file, $method);
                    // return template
                    if ($return) {
                        return mgm_get_include($template_file);
                    }
                    // @todo check payment
                    // include template
                    @(include $template_file);
                }
            } else {
                // not a valiud module, call default for unsubscribe
                if ($method == 'payment_unsubscribe') {
                    // default unsubscribe
                    return mgm_member_unsubscribe();
                } else {
                    // error
                    return __('Invalid module supplied', 'mgm');
                }
            }
            break;
        case 'payment_processed':
            // processed
            // get module
            $module = mgm_request_var('module', '', true);
            // validate module
            if ($module_obj = mgm_is_valid_module($module, 'payment', 'object')) {
                // redirect logic moved, in all cases same page is loaded
                // if template exists
                if ($return) {
                    $template_file = MGM_CORE_DIR . 'html/payment_processed_return.php';
                } else {
                    if (file_exists(TEMPLATEPATH . '/payment_processed.php')) {
                        $template_file = TEMPLATEPATH . '/payment_processed.php';
                    } else {
                        $template_file = MGM_CORE_DIR . 'html/payment_processed.php';
                    }
                }
                // apply template filter
                $template_file = apply_filters('mgm_page_template', $template_file, $method);
                // return template
                if ($return) {
                    return mgm_get_include($template_file);
                }
                // include template
                @(include $template_file);
            } else {
                return __('Invalid module supplied', 'mgm');
            }
            break;
        case 'payment_purchase':
            // post purchase
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/payment_post_purchase_return.php';
            } else {
                if (file_exists(TEMPLATEPATH . '/payment_post_purchase.php')) {
                    $template_file = TEMPLATEPATH . '/payment_post_purchase.php';
                } else {
                    $template_file = MGM_CORE_DIR . 'html/payment_post_purchase.php';
                }
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
        case 'guest_purchase':
            // form
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/guest_purchase_return.php';
            } else {
                if (file_exists(TEMPLATEPATH . '/guest_purchase.php')) {
                    $template_file = TEMPLATEPATH . '/guest_purchase.php';
                } else {
                    $template_file = MGM_CORE_DIR . 'html/guest_purchase.php';
                }
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
        case 'register':
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'profile':
            //user profile page
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'lost_password':
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'user_login':
        case 'login':
            // if template exists
            $template = mgm_get_page_template('login', $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'payment_subscribe':
            // form
        // form
        case 'payment':
            // form
        // form
        default:
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/payment_subscribe_return.php';
            } elseif (file_exists(TEMPLATEPATH . '/payment_subscribe.php')) {
                $template_file = TEMPLATEPATH . '/payment_subscribe.php';
            } else {
                $template_file = MGM_CORE_DIR . 'html/payment_subscribe.php';
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
    }
}
/**
 * override default template
 *
 * @param array $column
 * @param init $post_id
 * @return void
 */
function mgm_template_include($template)
{
    // check override
    if (bool_from_yn(mgm_get_setting('override_theme_for_custom_pages'))) {
        // name
        $name = mgm_get_query_var('name');
        // switch
        switch ($name) {
            case 'register':
            case 'profile':
            case 'lost_password':
            case 'login':
                $content = mgm_get_query_post_content();
                // @todo check #BUG_PENDING
                // check
                if (mgm_is_custom_page_published($name, $content)) {
                    // if template exists in theme only
                    if ($c_template = mgm_get_page_template($name, false, true)) {
                        $template = $c_template;
                    }
                }
                break;
        }
    }
    // return
    return $template;
}