From f8c0ec48d5c3406a9a1d099b5137f8afea71b703 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Sep 2018 10:50:34 -0500 Subject: [PATCH 1/5] Remove e_notice in advanced course search - refs BT#14835 --- main/admin/course_list.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main/admin/course_list.php b/main/admin/course_list.php index 80b926df35..9ba9a80a71 100755 --- a/main/admin/course_list.php +++ b/main/admin/course_list.php @@ -46,7 +46,9 @@ function get_number_of_courses() } elseif (isset($_GET['keyword_code'])) { $keyword_code = Database::escape_string("%".$_GET['keyword_code']."%"); $keyword_title = Database::escape_string("%".$_GET['keyword_title']."%"); - $keyword_category = Database::escape_string("%".$_GET['keyword_category']."%"); + $keyword_category = isset($_GET['keyword_category']) + ? Database::escape_string("%".$_GET['keyword_category']."%") + : null; $keyword_language = Database::escape_string("%".$_GET['keyword_language']."%"); $keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%"); $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']); @@ -55,12 +57,15 @@ function get_number_of_courses() $sql .= " WHERE (c.code LIKE '".$keyword_code."' OR c.visual_code LIKE '".$keyword_code."') AND c.title LIKE '".$keyword_title."' AND - c.category_code LIKE '".$keyword_category."' AND c.course_language LIKE '".$keyword_language."' AND c.visibility LIKE '".$keyword_visibility."' AND c.subscribe LIKE '".$keyword_subscribe."' AND c.unsubscribe LIKE '".$keyword_unsubscribe."' "; + + if (!empty($keyword_category)) { + $sql .= " AND c.category_code LIKE '".$keyword_category."' "; + } } // adding the filter to see the user's only of the current access_url @@ -127,7 +132,9 @@ function get_course_data($from, $number_of_items, $column, $direction) } elseif (isset($_GET['keyword_code'])) { $keyword_code = Database::escape_string("%".$_GET['keyword_code']."%"); $keyword_title = Database::escape_string("%".$_GET['keyword_title']."%"); - $keyword_category = Database::escape_string("%".$_GET['keyword_category']."%"); + $keyword_category = isset($_GET['keyword_category']) + ? Database::escape_string("%".$_GET['keyword_category']."%") + : null; $keyword_language = Database::escape_string("%".$_GET['keyword_language']."%"); $keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%"); $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']); @@ -136,11 +143,14 @@ function get_course_data($from, $number_of_items, $column, $direction) $sql .= " WHERE (code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND title LIKE '".$keyword_title."' AND - category_code LIKE '".$keyword_category."' AND course_language LIKE '".$keyword_language."' AND visibility LIKE '".$keyword_visibility."' AND subscribe LIKE '".$keyword_subscribe."' AND unsubscribe LIKE '".$keyword_unsubscribe."'"; + + if (!empty($keyword_category)) { + $sql .= " AND category_code LIKE '".$keyword_category."' "; + } } // Adding the filter to see the user's only of the current access_url. @@ -531,7 +541,9 @@ if (isset($_GET['search']) && $_GET['search'] === 'advanced') { } elseif (isset($_GET['keyword_code'])) { $parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']); $parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']); - $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']); + if (isset($_GET['keyword_category'])) { + $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']); + } $parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']); $parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']); $parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']); From 479bf78d87b9e11a846fe545b04a021729029444 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Sep 2018 12:31:22 -0500 Subject: [PATCH 2/5] Fix get_lang's $returnEmptyIfNotFound param - refs BT#14835 See 47685b169b99f560e591fb0283e36d50bf0436fa --- main/inc/lib/internationalization.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 15c1dc9da4..13f7ed2e45 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -160,7 +160,11 @@ function get_lang($variable) } elseif (isset($GLOBALS["lang$variable"])) { $langvar = $GLOBALS["lang$variable"]; } else { - $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable; + if (!$returnEmptyIfNotFound) { + $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable; + } else { + return ''; + } } } if (empty($langvar) || !is_string($langvar)) { From 5dd524f6ac52408646cd77df7c26984c45b7060e Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Sep 2018 14:21:05 -0500 Subject: [PATCH 3/5] Fix buycourses when showing teachers - refs BT#14835 --- plugin/buycourses/src/buy_course_plugin.class.php | 2 +- plugin/buycourses/view/success.tpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index a7ecae20a7..8f0d48226f 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -593,7 +593,7 @@ class BuyCoursesPlugin extends Plugin $courseInfo = [ 'id' => $course->getId(), 'title' => $course->getTitle(), - 'description' => $courseDescription->getContent(), + 'description' => $courseDescription ? $courseDescription->getContent() : null, 'code' => $course->getCode(), 'visual_code' => $course->getVisualCode(), 'teachers' => [], diff --git a/plugin/buycourses/view/success.tpl b/plugin/buycourses/view/success.tpl index 50af52b7de..cc25e8ece3 100644 --- a/plugin/buycourses/view/success.tpl +++ b/plugin/buycourses/view/success.tpl @@ -30,7 +30,7 @@
    {% for teacher in course.teachers %} -
  • {{ teacher }}
  • +
  • {{ teacher.name }}
  • {% endfor %}

@@ -57,7 +57,7 @@ {% for course in session.courses %}

{{ course.title }}
{% for coach in course.coaches %} -
{{ coach }}
+
{{ coach.name }}
{% endfor %} {% endfor %} From 274eb20eb247f4363e535549da629bab71433458 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Sep 2018 15:03:04 -0500 Subject: [PATCH 4/5] BuyCourses: Show link when subscription is done - refs BT#14835 --- plugin/buycourses/lang/brazilian.php | 2 +- plugin/buycourses/lang/dutch.php | 2 +- plugin/buycourses/lang/english.php | 2 +- plugin/buycourses/lang/french.php | 2 +- plugin/buycourses/lang/spanish.php | 2 +- .../src/buy_course_plugin.class.php | 31 +++++++++++++++++++ plugin/buycourses/src/buycourses.ajax.php | 5 +-- plugin/buycourses/src/sales_report.php | 5 +-- plugin/buycourses/src/success.php | 18 ++--------- 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/plugin/buycourses/lang/brazilian.php b/plugin/buycourses/lang/brazilian.php index 46daeebf72..2dc9fb66d7 100644 --- a/plugin/buycourses/lang/brazilian.php +++ b/plugin/buycourses/lang/brazilian.php @@ -47,7 +47,7 @@ $strings['CancelOrder'] = "Anular ordem"; $strings['BankAccountInformation'] = "Detalhes da conta bancária"; $strings['BankAccount'] = "Contas bancárias"; $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrderReference'] = "Uma vez confirmada, você receberá um e-mail com os dados bancários e uma referência de ordem."; -$strings['SubscriptionToCourseXSuccessful'] = "Sua inscrição para \"%s\ foi concluída com sucesso."; +$strings['SubscriptionToCourseXSuccessful'] = "Sua inscrição para \"%s\" foi concluída com sucesso."; $strings['OrderCanceled'] = "Ordem cancelada"; $strings['OrderStatus'] = "Status do pedido"; $strings['SearchByStatus'] = "Pesquisar por estado"; diff --git a/plugin/buycourses/lang/dutch.php b/plugin/buycourses/lang/dutch.php index 9c5dbc0c9b..d265f6c109 100644 --- a/plugin/buycourses/lang/dutch.php +++ b/plugin/buycourses/lang/dutch.php @@ -82,7 +82,7 @@ $strings['CancelOrder'] = "Annuleer order"; $strings['BankAccountInformation'] = "Bankgegevens"; $strings['BankAccount'] = "Bankrekening"; $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrderReference'] = "Eenmaal bevestigd, ontvangt u een e-mail met de bankgegevens en een orderreferentie."; -$strings['SubscriptionToCourseXSuccessful'] = "Uw aankoop op \"%s \" werd met succes afgerond."; +$strings['SubscriptionToCourseXSuccessful'] = "Uw aankoop op \"%s\" werd met succes afgerond."; $strings['OrderCanceled'] = "Order geannuleerd"; $strings['OrderStatus'] = "Bestelstatus"; $strings['PayoutStatus'] = "Betalingsstatus"; diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php index a32c3807bb..1a5ca76432 100644 --- a/plugin/buycourses/lang/english.php +++ b/plugin/buycourses/lang/english.php @@ -82,7 +82,7 @@ $strings['CancelOrder'] = "Cancel order"; $strings['BankAccountInformation'] = "Bank account details"; $strings['BankAccount'] = "Bank account"; $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrderReference'] = "Once confirmed, you will receive an e-mail with the bank details and an order reference."; -$strings['SubscriptionToCourseXSuccessful'] = "Your subscription to \"%s\" was completed successfully."; +$strings['SubscriptionToCourseXSuccessful'] = "Your subscription to \"%s\" was completed successfully."; $strings['OrderCanceled'] = "Order canceled"; $strings['OrderStatus'] = "Order status"; $strings['PayoutStatus'] = "Payment status"; diff --git a/plugin/buycourses/lang/french.php b/plugin/buycourses/lang/french.php index 08e1aa3040..5931920271 100644 --- a/plugin/buycourses/lang/french.php +++ b/plugin/buycourses/lang/french.php @@ -82,7 +82,7 @@ $strings['CancelOrder'] = "Annuler la commande"; $strings['BankAccountInformation'] = "Détails du compte bancaire"; $strings['BankAccount'] = "Compte bancaire"; $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrderReference'] = "Une fois confirmée, vous recevrez un e-mail avec les données bancaires et la référence de la commande"; -$strings['SubscriptionToCourseXSuccessful'] = "Votre inscription au \"%s\" est terminée."; +$strings['SubscriptionToCourseXSuccessful'] = "Votre inscription au \"%s\" est terminée."; $strings['OrderCanceled'] = "Commande annulée"; $strings['OrderStatus'] = "Statut de commande"; $strings['PayoutStatus'] = "État du paiement"; diff --git a/plugin/buycourses/lang/spanish.php b/plugin/buycourses/lang/spanish.php index 54ba33d367..dddc5644bc 100644 --- a/plugin/buycourses/lang/spanish.php +++ b/plugin/buycourses/lang/spanish.php @@ -83,7 +83,7 @@ $strings['CancelOrder'] = "Cancelar Orden"; $strings['BankAccountInformation'] = "Información de la Cuenta Bancaria"; $strings['BankAccount'] = "Cuenta Bancaria"; $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrderReference'] = "Una vez confirmado, recibira un e-mail con los datos bancarios y una referencia del pedido."; -$strings['SubscriptionToCourseXSuccessful'] = "Tu subscripción a \"%s\" se realizó correctamente."; +$strings['SubscriptionToCourseXSuccessful'] = "

Tu subscripción a \"%s\" se realizó correctamente.

"; $strings['OrderCanceled'] = "Pedido cancelado"; $strings['OrderStatus'] = "Estado del pedido"; $strings['PayoutStatus'] = "Estado del pago"; diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 8f0d48226f..c5fa42565d 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -2542,4 +2542,35 @@ class BuyCoursesPlugin extends Plugin ['id = ?' => (int) $serviceSaleId] ); } + + /** + * @param array $saleInfo + * + * @return string + */ + public function getSubscriptionSuccessMessage(array $saleInfo) + { + switch ($saleInfo['product_type']) { + case self::PRODUCT_TYPE_COURSE: + $courseInfo = api_get_course_info_by_id($saleInfo['product_id']); + $url = api_get_course_url($courseInfo['code']); + break; + case self::PRODUCT_TYPE_SESSION: + $sessionId = (int) $saleInfo['product_id']; + $url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionId; + break; + default: + $url = '#'; + } + + return Display::return_message( + sprintf( + $this->get_lang('SubscriptionToCourseXSuccessful'), + $url, + $saleInfo['product_name'] + ), + 'success', + false + ); + } } diff --git a/plugin/buycourses/src/buycourses.ajax.php b/plugin/buycourses/src/buycourses.ajax.php index a10bca6b3d..9366fa2fef 100644 --- a/plugin/buycourses/src/buycourses.ajax.php +++ b/plugin/buycourses/src/buycourses.ajax.php @@ -328,10 +328,7 @@ switch ($action) { if ($saleIsCompleted) { Display::addFlash( - Display::return_message( - sprintf($plugin->get_lang('SubscriptionToCourseXSuccessful'), $sale['product_name']), - 'success' - ) + $plugin->getSubscriptionSuccessMessage($sale) ); } } diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index 08043769a2..1184497620 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -33,10 +33,7 @@ if (isset($_GET['order'])) { $plugin->completeSale($sale['id']); $plugin->storePayouts($sale['id']); Display::addFlash( - Display::return_message( - sprintf($plugin->get_lang('SubscriptionToCourseXSuccessful'), $sale['product_name']), - 'success' - ) + $plugin->getSubscriptionSuccessMessage($sale) ); $urlToRedirect .= http_build_query([ diff --git a/plugin/buycourses/src/success.php b/plugin/buycourses/src/success.php index 9784284271..2b2caffa4f 100644 --- a/plugin/buycourses/src/success.php +++ b/plugin/buycourses/src/success.php @@ -83,23 +83,9 @@ if ($form->validate()) { switch ($confirmPayments['PAYMENTINFO_0_PAYMENTSTATUS']) { case 'Completed': $saleIsCompleted = $plugin->completeSale($sale['id']); - if ($saleIsCompleted && $buyingSession) { + if ($saleIsCompleted) { Display::addFlash( - Display::return_message( - sprintf($plugin->get_lang('SubscriptionToCourseXSuccessful'), $session['name']), - 'success' - ) - ); - $plugin->storePayouts($sale['id']); - break; - } - - if ($saleIsCompleted && $buyingCourse) { - Display::addFlash( - Display::return_message( - sprintf($plugin->get_lang('SubscriptionToCourseXSuccessful'), $course['title']), - 'success' - ) + $plugin->getSubscriptionSuccessMessage($sale) ); $plugin->storePayouts($sale['id']); break; From cc40f065d7c4565c649b40383ee7b644eac03dc6 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Sep 2018 15:42:27 -0500 Subject: [PATCH 5/5] BuyCourses: Fix redirection after self-registration - refs BT#14835 --- main/auth/inscription.php | 6 +++++- plugin/buycourses/src/process.php | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/main/auth/inscription.php b/main/auth/inscription.php index 32d3d7c2e9..bb1291ab15 100755 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -1056,7 +1056,11 @@ if ($form->validate()) { if ($usersCanCreateCourse) { $form_register->addElement('html', $form_data['button']); } else { - $form_register->addElement('html', $form_data['go_button']); + if (!empty($redirectBuyCourse)) { + $form_register->addButtonNext(get_lang('Next')); + } else { + $form_register->addElement('html', $form_data['go_button']); + } } $text_after_registration .= $form_register->returnForm(); diff --git a/plugin/buycourses/src/process.php b/plugin/buycourses/src/process.php index c8f53b0188..415f4977c3 100644 --- a/plugin/buycourses/src/process.php +++ b/plugin/buycourses/src/process.php @@ -11,11 +11,7 @@ use ChamiloSession as Session; 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; -} + $htmlHeadXtra[] = ''; @@ -37,6 +33,12 @@ $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 (empty($currentUserId)) { + Session::write('buy_course_redirect', api_get_self().'?'.$queryString); + header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php'); + exit; +} + if ($buyingCourse) { $courseInfo = $plugin->getCourseInfo($_REQUEST['i']); $item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);