Improving templates for process sale - refs BT#8470

remotes/angel/1.11.x
Angel Fernando Quiroz Campos 8 years ago
parent cd4b25c86c
commit 7e650b5e61
  1. 222
      plugin/buycourses/src/process.php
  2. 4
      plugin/buycourses/src/service_process.php
  3. 115
      plugin/buycourses/view/process.tpl

@ -1,112 +1,110 @@
<?php
/* For license terms, see /license.txt */
use ChamiloSession as Session;
/**
* Process payments for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
require_once '../config.php';
$currentUserId = api_get_user_id();
if (empty($currentUserId)) {
Session::write('buy_course_redirect', Security::remove_XSS($_SERVER['REQUEST_URI']));
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
exit;
}
$plugin = BuyCoursesPlugin::create();
$includeSession = $plugin->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('<h3 class="panel-heading">'.$plugin->get_lang('AdditionalInfo').'</h3>');
$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();
<?php
/* For license terms, see /license.txt */
use ChamiloSession as Session;
/**
* Process payments for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
require_once '../config.php';
$currentUserId = api_get_user_id();
if (empty($currentUserId)) {
Session::write('buy_course_redirect', Security::remove_XSS($_SERVER['REQUEST_URI']));
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
exit;
}
$plugin = BuyCoursesPlugin::create();
$includeSession = $plugin->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();

@ -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('<h3 class="panel-heading">'.$plugin->get_lang('AdditionalInfo').'</h3>');
$form->addHeader('');
$form->addHtml(
Display::return_message(
$plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'),

@ -1,24 +1,21 @@
<h2 class="page-header">{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}</h2>
<div class="row">
<div class="col-md-5 panel panel-default buycourse-panel-default">
<h3 class="panel-heading">{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
<legend></legend>
<div class="row">
<div class="col-md-5">
<div class="thumbnail">
{% if buying_course %}
<div class="col-sm-12 col-md-12 col-xs-12">
<a class="ajax" data-title="{{ course.title }}"
href="{{ _p.web_ajax ~ 'course_home.ajax.php?' ~ {'a': 'show_course_information', 'code': course.code}|url_encode() }}">
<img alt="{{ course.title }}" class="img-responsive" style="width: 100%;"
src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}">
</a>
</div>
<div class="col-sm-12 col-md-12 col-xs-12">
<a class="ajax" data-title="{{ course.title }}"
href="{{ _p.web_ajax ~ 'course_home.ajax.php?' ~ {'a': 'show_course_information', 'code': course.code}|url_encode() }}">
<img alt="{{ course.title }}" class="img-responsive" style="width: 100%;"
src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}">
</a>
<div class="caption">
<h3>
<a class="ajax" data-title="{{ course.title }}"
href="{{ _p.web_ajax ~ 'course_home.ajax.php?' ~ {'a': 'show_course_information', 'code': course.code}|url_encode() }}">{{ course.title }}</a>
</h3>
<ul class="list-unstyled">
<ul class="fa-ul">
{% for teacher in course.teachers %}
<li><em class="fa fa-user"></em> {{ teacher }}</li>
<li><em class="fa-li fa fa-user" aria-hidden="true"></em>{{ teacher }}</li>
{% endfor %}
</ul>
<p id="n-price" class="lead text-right" style="color: white;">
@ -27,23 +24,24 @@
<p id="s-price" class="lead text-right"></p>
</div>
{% elseif buying_session %}
<div class="col-sm-12 col-md-12 col-xs-12">
<p>
<img alt="{{ session.name }}" class="img-responsive" style="width: 100%;"
src="{{ session.image ? session.image : 'session_default.png'|icon() }}">
</p>
</div>
<div class="col-sm-12 col-md-12 col-xs-12">
<img alt="{{ session.name }}" class="img-ressponsive" style="width: 100%;"
src="{{ session.image ? session.image : 'session_default.png'|icon() }}">
<div class="caption">
<h3>{{ session.name }}</h3>
<p><em class="fa fa-calendar fa-fw"></em> {{ session.dates.display }}</p>
<ul class="list-unstyled">
<ul class="fa-ul">
<li>
<em class="fa-li fa fa-calendar" aria-hidden="true"></em>{{ session.dates.display }}
</li>
</ul>
<ul class="fa-ul">
{% for course in session.courses %}
<li>
<em class="fa fa-book fa-fw"></em> {{ course.title }}
<em class="fa-li fa fa-book" aria-hidden="true"></em>
{{ course.title }}
{% if course.coaches|length %}
<ul>
<ul class="fa-ul">
{% for coach in course.coaches %}
<li><em class="fa fa-user fa-fw"></em>{{ coach }}</li>
<li><em class="fa-li fa fa-user" aria-hidden="true"></em>{{ coach }}</li>
{% endfor %}
</ul>
{% endif %}
@ -56,46 +54,39 @@
<p id="s-price" class="lead text-right"></p>
</div>
{% elseif buying_service %}
<div class="col-sm-12 col-md-12 col-xs-12">
<a href='{{ _p.web }}service/{{ service.id }}'>
<img alt="{{ service.name }}" class="img-responsive"
src="{{ service.image ? _p.web ~ 'plugin/buycourses/uploads/services/images/' ~ service.image : 'session_default.png'|icon() }}">
</a>
</div>
<div class="col-sm-12 col-md-12 col-xs-12">
<a href='{{ _p.web }}service/{{ service.id }}'>
<img alt="{{ service.name }}" class="img-responsive"
src="{{ service.image ? _p.web ~ 'plugin/buycourses/uploads/services/images/' ~ service.image : 'session_default.png'|icon() }}">
</a>
<div class="caption">
<h3>
<a href='{{ _p.web }}service/{{ service.id }}'>{{ service.name }}</a>
</h3>
<ul class="list-unstyled">
{% if service.applies_to == 0 %}
<li>
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'None'|get_lang }}
</li>
{% elseif service.applies_to == 1 %}
<ul class="fa-ul">
{% if service.applies_to %}
<li>
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'User'|get_lang }}
</li>
{% elseif service.applies_to == 2 %}
<li>
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Course'|get_lang }}
</li>
{% elseif service.applies_to == 3 %}
<li>
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Session'|get_lang }}
</li>
{% elseif service.applies_to == 4 %}
<li>
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'TemplateTitleCertificate'|get_lang }}
<em class="fa-li fa fa-hand-o-right" aria-hidden="true"></em>
{% 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 %}
</li>
{% endif %}
<li>
<em class="fa fa-money"></em>
<em class="fa-li fa fa-money" aria-hidden="true"></em>
{{ '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 }}
</li>
<li><em class="fa fa-user"></em> {{ service.owner_name }}</li>
<li><em class="fa fa-align-justify"></em> {{ service.description }}</li>
<li><em class="fa-li fa fa-user" aria-hidden="true"></em> {{ service.owner_name }}</li>
<li><em class="fa-li fa fa-align-justify" aria-hidden="true"></em> {{ service.description }}</li>
</ul>
<p id="n-price" class="lead text-right" style="color: white;">
<span class="label label-primary">{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}</span>
@ -105,11 +96,15 @@
{% endif %}
</div>
</div>
<div class="col-md-1">
</div>
<div class="col-md-6 panel panel-default buycourse-panel-default">
<h3 class="panel-heading">{{ 'PaymentMethods'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
{{ form }}
<div class="col-md-6 col-md-offset-1">
<div class="panel panel-default buycourse-panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{ 'PaymentMethods'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
</div>
<div class="panel-body">
{{ form }}
</div>
</div>
</div>
</div>
<script>

Loading…
Cancel
Save