From 7e650b5e61a4629a8b0361bb633d26b27ac1a136 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 6 Jun 2017 10:18:31 -0500 Subject: [PATCH] Improving templates for process sale - refs BT#8470 --- plugin/buycourses/src/process.php | 222 +++++++++++----------- plugin/buycourses/src/service_process.php | 4 +- plugin/buycourses/view/process.tpl | 115 ++++++----- 3 files changed, 166 insertions(+), 175 deletions(-) diff --git a/plugin/buycourses/src/process.php b/plugin/buycourses/src/process.php index 00a0404ad6..f85d55ec30 100644 --- a/plugin/buycourses/src/process.php +++ b/plugin/buycourses/src/process.php @@ -1,112 +1,110 @@ -get('include_sessions') === 'true'; -$paypalEnabled = $plugin->get('paypal_enable') === 'true'; -$transferEnabled = $plugin->get('transfer_enable') === 'true'; -$culqiEnabled = $plugin->get('culqi_enable') === 'true'; - -if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled) { - api_not_allowed(true); -} - -if (!isset($_REQUEST['t'], $_REQUEST['i'])) { - api_not_allowed(true); -} - -$buyingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE; -$buyingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION; -$queryString = 'i='.intval($_REQUEST['i']).'&t='.intval($_REQUEST['t']); - -if ($buyingCourse) { - $courseInfo = $plugin->getCourseInfo($_REQUEST['i']); - $item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE); -} elseif ($buyingSession) { - $sessionInfo = $plugin->getSessionInfo($_REQUEST['i']); - $item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION); -} - -$userInfo = api_get_user_info(); - -$form = new FormValidator('confirm_sale'); - -if ($form->validate()) { - $formValues = $form->getSubmitValues(); - - if (!$formValues['payment_type']) { - Display::addFlash( - Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false) - ); - header('Location:'.api_get_self().'?'.$queryString); - exit; - } - - $saleId = $plugin->registerSale($item['id'], $formValues['payment_type']); - - if ($saleId !== false) { - $_SESSION['bc_sale_id'] = $saleId; - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process_confirm.php'); - } - - exit; -} - -$paymentTypesOptions = $plugin->getPaymentTypes(); - -if (!$paypalEnabled) { - unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL]); -} - -if (!$transferEnabled) { - unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER]); -} - -if (!$culqiEnabled) { - unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_CULQI]); -} - -$form->addRadio('payment_type', null, $paymentTypesOptions); -$form->addHtml('

'.$plugin->get_lang('AdditionalInfo').'

'); -$form->addHeader(''); -$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'), 'info')); -$form->addHidden('t', intval($_GET['t'])); -$form->addHidden('i', intval($_GET['i'])); -$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success'); - -// View -$templateName = $plugin->get_lang('PaymentMethods'); -$interbreadcrumb[] = array("url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale')); - -$tpl = new Template($templateName); -$tpl->assign('buying_course', $buyingCourse); -$tpl->assign('buying_session', $buyingSession); -$tpl->assign('user', api_get_user_info()); -$tpl->assign('form', $form->returnForm()); - -if ($buyingCourse) { - $tpl->assign('course', $courseInfo); -} elseif ($buyingSession) { - $tpl->assign('session', $sessionInfo); -} - -$content = $tpl->fetch('buycourses/view/process.tpl'); - -$tpl->assign('content', $content); -$tpl->display_one_col_template(); +get('include_sessions') === 'true'; +$paypalEnabled = $plugin->get('paypal_enable') === 'true'; +$transferEnabled = $plugin->get('transfer_enable') === 'true'; +$culqiEnabled = $plugin->get('culqi_enable') === 'true'; + +if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled) { + api_not_allowed(true); +} + +if (!isset($_REQUEST['t'], $_REQUEST['i'])) { + api_not_allowed(true); +} + +$buyingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE; +$buyingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION; +$queryString = 'i='.intval($_REQUEST['i']).'&t='.intval($_REQUEST['t']); + +if ($buyingCourse) { + $courseInfo = $plugin->getCourseInfo($_REQUEST['i']); + $item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE); +} elseif ($buyingSession) { + $sessionInfo = $plugin->getSessionInfo($_REQUEST['i']); + $item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION); +} + +$userInfo = api_get_user_info(); + +$form = new FormValidator('confirm_sale'); + +if ($form->validate()) { + $formValues = $form->getSubmitValues(); + + if (!$formValues['payment_type']) { + Display::addFlash( + Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false) + ); + header('Location:'.api_get_self().'?'.$queryString); + exit; + } + + $saleId = $plugin->registerSale($item['id'], $formValues['payment_type']); + + if ($saleId !== false) { + $_SESSION['bc_sale_id'] = $saleId; + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process_confirm.php'); + } + + exit; +} + +$paymentTypesOptions = $plugin->getPaymentTypes(); + +if (!$paypalEnabled) { + unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL]); +} + +if (!$transferEnabled) { + unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER]); +} + +if (!$culqiEnabled) { + unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_CULQI]); +} + +$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'), 'info')); +$form->addRadio('payment_type', null, $paymentTypesOptions); +$form->addHidden('t', intval($_GET['t'])); +$form->addHidden('i', intval($_GET['i'])); +$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success'); + +// View +$templateName = $plugin->get_lang('PaymentMethods'); +$interbreadcrumb[] = array("url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale')); + +$tpl = new Template($templateName); +$tpl->assign('buying_course', $buyingCourse); +$tpl->assign('buying_session', $buyingSession); +$tpl->assign('user', api_get_user_info()); +$tpl->assign('form', $form->returnForm()); + +if ($buyingCourse) { + $tpl->assign('course', $courseInfo); +} elseif ($buyingSession) { + $tpl->assign('session', $sessionInfo); +} + +$content = $tpl->fetch('buycourses/view/process.tpl'); + +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/plugin/buycourses/src/service_process.php b/plugin/buycourses/src/service_process.php index 59ea1f9f19..bde104f372 100644 --- a/plugin/buycourses/src/service_process.php +++ b/plugin/buycourses/src/service_process.php @@ -96,10 +96,8 @@ if (!$culqiEnabled) { unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_CULQI]); } -$form->addHeader(''); +$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'), 'info')); $form->addRadio('payment_type', null, $paymentTypesOptions); -$form->addHtml('

'.$plugin->get_lang('AdditionalInfo').'

'); -$form->addHeader(''); $form->addHtml( Display::return_message( $plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'), diff --git a/plugin/buycourses/view/process.tpl b/plugin/buycourses/view/process.tpl index 59361c5d07..f1e577aa18 100644 --- a/plugin/buycourses/view/process.tpl +++ b/plugin/buycourses/view/process.tpl @@ -1,24 +1,21 @@ +
-
-

{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}

- -
+
+
{% if buying_course %} -
- - {{ course.title }} - -
-
+ + {{ course.title }} + +

{{ course.title }}

-
    +
      {% for teacher in course.teachers %} -
    • {{ teacher }}
    • +
    • {{ teacher }}
    • {% endfor %}

    @@ -27,23 +24,24 @@

{% elseif buying_session %} -
-

- {{ session.name }} -

-
-
+ {{ session.name }} +

{{ session.name }}

-

{{ session.dates.display }}

-
    +
      +
    • + {{ session.dates.display }} +
    • +
    +
      {% for course in session.courses %}
    • - {{ course.title }} + + {{ course.title }} {% if course.coaches|length %} -
        +
          {% for coach in course.coaches %} -
        • {{ coach }}
        • +
        • {{ coach }}
        • {% endfor %}
        {% endif %} @@ -56,46 +54,39 @@

{% elseif buying_service %} -
- - {{ service.name }} - -
-
+ + {{ service.name }} + +

{{ service.name }}

-
    - {% if service.applies_to == 0 %} -
  • - {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'None'|get_lang }} -
  • - {% elseif service.applies_to == 1 %} +
      + {% if service.applies_to %}
    • - {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'User'|get_lang }} -
    • - {% elseif service.applies_to == 2 %} -
    • - {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Course'|get_lang }} -
    • - {% elseif service.applies_to == 3 %} -
    • - {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Session'|get_lang }} -
    • - {% elseif service.applies_to == 4 %} -
    • - {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'TemplateTitleCertificate'|get_lang }} + + {% if service.applies_to == 0 %} + {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') ~ ' ' ~ 'None'|get_lang }} + {% elseif service.applies_to == 1 %} + {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') ~ ' ' ~ 'User'|get_lang }} + {% elseif service.applies_to == 2 %} + {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') ~ ' ' ~ 'Course'|get_lang }} + {% elseif service.applies_to == 3 %} + {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') ~ ' ' ~ 'Session'|get_lang }} + {% elseif service.applies_to == 4 %} + {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') ~ ' ' ~ 'TemplateTitleCertificate'|get_lang }} + {% endif %}
    • {% endif %}
    • - + {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} : {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} / {{ service.duration_days == 0 ? 'NoLimit'|get_lang : service.duration_days ~ ' ' ~ 'Days'|get_lang }}
    • -
    • {{ service.owner_name }}
    • -
    • {{ service.description }}
    • +
    • {{ service.owner_name }}
    • +
    • {{ service.description }}

    {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} @@ -105,11 +96,15 @@ {% endif %}

-
-
-
-

{{ 'PaymentMethods'|get_plugin_lang('BuyCoursesPlugin') }}

- {{ form }} +
+
+
+

{{ 'PaymentMethods'|get_plugin_lang('BuyCoursesPlugin') }}

+
+
+ {{ form }} +
+