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('
' . sprintf($plugin->get_lang('EnableTrialSubscriptionHelpText'), $serviceInfo['trial_frequency'] . ' ' . $trialTime) . '
+' . $plugin->get_lang('DiscountCodeInfoText') . '
+{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}
+ +