diff --git a/plugin/buycourses/lang/spanish.php b/plugin/buycourses/lang/spanish.php index 6d746176ea..d6118cf5b8 100644 --- a/plugin/buycourses/lang/spanish.php +++ b/plugin/buycourses/lang/spanish.php @@ -145,3 +145,5 @@ $strings['ServiceAdded'] = "Servicio agregado"; $strings['ServiceEdited'] = "Servicio editado"; $strings['ServiceSaleInfo'] = "Información del servicio"; $strings['ListOfServicesOnSale'] = "Lista de servicios a la venta"; +$strings['AdditionalInfo'] = "Información adicional"; +$strings['PleaseSelectTheCorrectInfoToApplyTheService'] = "Porfavor Seleccione la información correcta para aplicar el servicio"; diff --git a/plugin/buycourses/resources/css/style.css b/plugin/buycourses/resources/css/style.css index 406740fa29..e3e4a80f79 100644 --- a/plugin/buycourses/resources/css/style.css +++ b/plugin/buycourses/resources/css/style.css @@ -1,5 +1,34 @@ .buy-courses-tabs { - margin-bottom: 15px; + margin-bottom: 15px; +} + +.buy-courses-page-header { + padding-bottom: 9px; + margin: 40px 0 20px; + border-bottom: 1px solid #eee; +} + +.buy-courses-block-button { + display: block; + width: 100%; + height: 50px; + line-height: 35px; + font-size: 16px; +} + +.buy-courses-cross-out { + text-decoration:line-through; +} + +.buy-courses-title-color { + color: #5DC3E1; + padding-bottom: 10px; +} + +.buy-courses-description-service { + text-align: justify; + font-size: 18px; + line-height: 1.42857; } @-moz-keyframes wobblebar-loader { diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index da3d54e7d8..bc9ae545ff 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -2010,7 +2010,7 @@ class BuyCoursesPlugin extends Plugin * @param string $name Optional. The name filter * @param int $min Optional. The minimum price filter * @param int $max Optional. The maximum price filter - * @param int $appliesTo Optional. + * @param mixed $appliesTo Optional. * @return array */ public function getCatalogServiceList($name = null, $min = 0, $max = 0, $appliesTo = '') @@ -2069,4 +2069,21 @@ class BuyCoursesPlugin extends Plugin } + /** + * Update the service sale status + * @param int $serviceSaleId The service sale ID + * @param int $newStatus The new status + * @return boolean + */ + private function updateServiceSaleStatus($serviceSaleId, $newStatus = self::SERVICE_STATUS_PENDING) + { + $serviceSaleTable = Database::get_main_table(self::TABLE_SERVICES_SALE); + + return Database::update( + $serviceSaleTable, + ['status' => intval($newStatus)], + ['id = ?' => intval($serviceSaleId)] + ); + } + } diff --git a/plugin/buycourses/src/service_process.php b/plugin/buycourses/src/service_process.php new file mode 100644 index 0000000000..1cbf4b009a --- /dev/null +++ b/plugin/buycourses/src/service_process.php @@ -0,0 +1,234 @@ +get('include_services'); +$paypalEnabled = $plugin->get('paypal_enable') === 'true'; +$transferEnabled = $plugin->get('transfer_enable') === 'true'; +$wizard = true; +$additionalQueryString = ''; +if ($includeServices !== 'true') { + api_not_allowed(true); +} + +$typeUser = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_USER; +$typeCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_COURSE; +$typeSession = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_SESSION; +$queryString = 'i=' . intval($_REQUEST['i']) . '&t=' . intval($_REQUEST['t']).$additionalQueryString; + +$serviceInfo = $plugin->getServices(intval($_REQUEST['i'])); +$userInfo = api_get_user_info($currentUserId); + +$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; + } + + if (!$formValues['info_select']) { + Display::addFlash( + Display::return_message($plugin->get_lang('AdditionalInfoRequired'), 'error', false) + ); + header('Location:' . api_get_self() . '?' . $queryString); + exit; + } + + $userGroup = $em->getRepository('ChamiloCoreBundle:Usergroup')->findBy(['name' => $formValues['info_select']]); + + if ($userGroup) { + Display::addFlash( + Display::return_message($plugin->get_lang('StoreNameAlreadyExist'), 'error', false) + ); + header('Location:' . api_get_self() . '?' . $queryString); + exit; + } + + $serviceSaleId = $plugin->registerServiceSale($serviceId, $formValues['payment_type'], $formValues['info_select'], $formValues['enable_trial']); + + if (!empty($formValues['store_code'])) { + $data = [ + 'store_code' => Security::remove_XSS($formValues['store_code']), + 'store_name' => Security::remove_XSS($formValues['info_select']), + 'parent_id' => 0, + 'description' => 'Registered by User in buying process', + 'type' => 1, + 'discount' => 0 + ]; + + $verification = $plugin->getDiscountByCode($data['store_code']); + + if (!$verification) { + $plugin->addDiscountCode($data); + } + } + + if ($serviceSaleId !== false) { + $_SESSION['bc_service_sale_id'] = $serviceSaleId; + + if ($verification['discount'] == 100) { + + $serviceSale = $plugin->getServiceSale($serviceSaleId); + + $serviceSaleIsCompleted = $plugin->completeServiceSale($serviceSale['id']); + if ($serviceSaleIsCompleted) { + Display::addFlash(Display::return_message(sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']), 'success')); + + $plugin->SendSubscriptionMail(intval($serviceSale['id'])); + + unset($_SESSION['bc_service_sale_id']); + + header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/package_panel.php?id='.$serviceSale['id']); + exit; + } + } + + if ($wizard) { + header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/service_process_confirm.php?from=register'); + } else { + header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/service_process_confirm.php'); + } + } + + exit; +} + +// Reset discount code +unset($_SESSION['s_discount']); + +$paymentTypesOptions = $plugin->getPaymentTypes(true); + +$form->addHeader(''); +$form->addRadio('payment_type', null, $paymentTypesOptions); +$form->addHtml('

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

'); +$form->addHeader(''); +$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'), 'info')); +$selectOptions = []; + +if ($typeUser) { + $users = $em->getRepository('ChamiloUserBundle:User')->findAll(); + $selectOptions[$userInfo['user_id']] = api_get_person_name($userInfo['firstname'], $userInfo['lastname']) . ' (' . get_lang('Myself') . ')'; + if (!empty($users)) { + foreach ($users as $user) { + if (intval($userInfo['user_id']) !== intval($user->getId())) { + $selectOptions[$user->getId()] = $user->getCompleteNameWithUsername(); + } + } + } + $form->addSelect('info_select', get_lang('User'), $selectOptions); +} elseif ($typeCourse) { + $user = $em->getRepository('ChamiloUserBundle:User')->find($currentUserId); + $courses = $user->getCourses(); + if (!empty($courses)) { + foreach ($courses as $course) { + $selectOptions[$course->getCourse()->getId()] = $course->getCourse()->getTitle(); + } + } + $form->addSelect('info_select', get_lang('Course'), $selectOptions); +} elseif ($typeSession) { + $user = $em->getRepository('ChamiloUserBundle:User')->find($currentUserId); + $sessions = $user->getSessionCourseSubscriptions(); + if (!empty($sessions)) { + foreach ($sessions as $session) { + $selectOptions[$session->getSession()->getId()] = $session->getSession()->getName(); + } + } + $form->addSelect('info_select', get_lang('Session'), $selectOptions); +} elseif ($typeSubscriptionPackage) { + $trial = intval($serviceInfo['allow_trial']); + + if ($trial) { + $trialTime = $serviceInfo['trial_period'] == 'Month' ? get_lang($serviceInfo['trial_period']) . '(es)' : get_lang($serviceInfo['trial_period']) . '(s)'; + $form->addHtml(' +
+ +
+
+
+
+
+
+

' . sprintf($plugin->get_lang('EnableTrialSubscriptionHelpText'), $serviceInfo['trial_frequency'] . ' ' . $trialTime) . '

+
+
+ '); + } + $form->addText('store_code', $plugin->get_lang('DiscountCodeProcess'), true, ['cols-size' => [6, 6, 0], 'id' => 'store_code']); + $form->addText('info_select_trick', $plugin->get_lang('StoreName'), true, ['cols-size' => [6, 6, 0], 'id' => 'info_select_trick']); + $form->addHidden('info_select', ''); + $form->addHtml(' +
+
+ ' . $plugin->get_lang('Check') . ' +
+
+
+
+
+ +
+
+
+

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

+
+
+ '); +} + + +$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" => "service_catalog.php", "name" => $plugin->get_lang('ListOfServicesOnSale')); + +$tpl = new Template($templateName); +if (isset($_GET['from'])) { + if($_GET['from'] == 'register') { + $tpl->assign('wizard', true); + } +} +$tpl->assign('buying_service', true); +$tpl->assign('service', $serviceInfo); +$tpl->assign('user', api_get_user_info()); +$tpl->assign('form', $form->returnForm()); + + +$content = $tpl->fetch('buycourses/view/process.tpl'); + +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/plugin/buycourses/src/services_add.php b/plugin/buycourses/src/services_add.php index 9bba2722e2..0804d51592 100644 --- a/plugin/buycourses/src/services_add.php +++ b/plugin/buycourses/src/services_add.php @@ -95,7 +95,7 @@ $form->addFile( (get_lang( 'AddImage' )), - array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '4 / 3') + array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9') ); $form->addText('video_url', get_lang('VideoUrl'), false); $form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false); diff --git a/plugin/buycourses/src/services_edit.php b/plugin/buycourses/src/services_edit.php index a811ba5876..d5a6ea27db 100644 --- a/plugin/buycourses/src/services_edit.php +++ b/plugin/buycourses/src/services_edit.php @@ -113,7 +113,7 @@ $form->addFile( ($formDefaultValues['image'] != '' ? get_lang('UpdateImage') : get_lang( 'AddImage' )), - array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '4 / 3') + array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9') ); $form->addText('video_url', get_lang('VideoUrl'), false); $form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false); diff --git a/plugin/buycourses/view/catalog.tpl b/plugin/buycourses/view/catalog.tpl index b4104a0457..7a48e39d8f 100644 --- a/plugin/buycourses/view/catalog.tpl +++ b/plugin/buycourses/view/catalog.tpl @@ -148,11 +148,7 @@ {{ 'ServiceInformation'|get_plugin_lang('BuyCoursesPlugin') }} - {% if service.allow_trial %} - {{ 'TryItNowFree'|get_plugin_lang('BuyCoursesPlugin') }} - {% else %} - {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }} - {% endif %} + {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }} diff --git a/plugin/buycourses/view/process.tpl b/plugin/buycourses/view/process.tpl index fc38e02acd..4af0c88912 100644 --- a/plugin/buycourses/view/process.tpl +++ b/plugin/buycourses/view/process.tpl @@ -1,8 +1,9 @@
-
- +
+

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

+
{% if buying_course %}
@@ -43,10 +44,97 @@ {% endfor %}
+ {% elseif buying_service %} +
+ + {{ service.name }} + +
+
+

+ {{ service.name }} +

+
    + {% 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 }}
  • + {% 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.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}

+

+
+ {% endif %}
-
+
+
+
+

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

{{ form }}