Extend buy_course plugin to include sessions (session mailing not done yet) - refs #7272

1.9.x
Imanol Losada 11 years ago
parent 904fd4e338
commit 4601849aeb
  1. 4
      plugin/buycourses/config.php
  2. 66
      plugin/buycourses/database.php
  3. 24
      plugin/buycourses/js/buycourses.js
  4. 3
      plugin/buycourses/lang/english.php
  5. 2
      plugin/buycourses/lang/french.php
  6. 2
      plugin/buycourses/lang/spanish.php
  7. 329
      plugin/buycourses/src/buy_course.lib.php
  8. 53
      plugin/buycourses/src/buy_course_plugin.class.php
  9. 12
      plugin/buycourses/src/configuration.php
  10. 4
      plugin/buycourses/src/error.php
  11. 34
      plugin/buycourses/src/function.php
  12. 4
      plugin/buycourses/src/index.buycourses.php
  13. 13
      plugin/buycourses/src/list.php
  14. 2
      plugin/buycourses/src/pending_orders.php
  15. 66
      plugin/buycourses/src/process.php
  16. 35
      plugin/buycourses/src/process_confirm.php
  17. 81
      plugin/buycourses/src/success.php
  18. 65
      plugin/buycourses/view/configuration.tpl
  19. 2
      plugin/buycourses/view/index.tpl
  20. 119
      plugin/buycourses/view/list.tpl
  21. 49
      plugin/buycourses/view/process.tpl

@ -1,6 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
define('TABLE_BUY_SESSION', 'plugin_buy_session');
define('TABLE_BUY_SESSION_COURSE', 'plugin_buy_session_course');
define('TABLE_BUY_SESSION_TEMPORAL', 'plugin_buy_session_temporal');
define('TABLE_BUY_SESSION_SALE', 'plugin_buy_session_sale');
define('TABLE_BUY_COURSE', 'plugin_buy_course');
define('TABLE_BUY_COURSE_COUNTRY', 'plugin_buy_course_country');
define('TABLE_BUY_COURSE_PAYPAL', 'plugin_buy_course_paypal');

@ -16,9 +16,31 @@ if (!function_exists('api_get_path')) {
*/
$objPlugin = BuyCoursesPlugin::create();
$table = Database::get_main_table(TABLE_BUY_SESSION);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
session_id INT unsigned NOT NULL DEFAULT '0',
name VARCHAR(250),
date_start VARCHAR(40),
date_end VARCHAR(40),
visible int,
price FLOAT(11,2) NOT NULL DEFAULT '0',
sync int)";
Database::query($sql);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT id, name, date_start, date_end FROM $tableSession";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$presql = "INSERT INTO $table (session_id, name, date_start, date_end, visible)
VALUES ('" . $row['id'] . "','" . $row['name'] . "','" . $row['date_start'] . "','" . $row['date_end'] . "','NO')";
Database::query($presql);
}
$table = Database::get_main_table(TABLE_BUY_COURSE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
session_id INT unsigned NOT NULL DEFAULT '0',
course_id INT unsigned NOT NULL DEFAULT '0',
code VARCHAR(40),
title VARCHAR(250),
@ -26,6 +48,7 @@ $sql = "CREATE TABLE IF NOT EXISTS $table (
price FLOAT(11,2) NOT NULL DEFAULT '0',
sync int)";
Database::query($sql);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT id, code, title FROM $tableCourse";
$res = Database::query($sql);
@ -34,6 +57,24 @@ while ($row = Database::fetch_assoc($res)) {
Database::query($presql);
}
$table = Database::get_main_table(TABLE_BUY_SESSION_COURSE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
id_session SMALLINT(5) unsigned DEFAULT '0',
course_code VARCHAR(40),
nbr_users SMALLINT(5) unsigned DEFAULT '0',
sync int)";
Database::query($sql);
$tableSessionCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$sql = "SELECT * FROM $tableSessionCourse";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$presql = "INSERT INTO $table (id_session, course_code, nbr_users)
VALUES ('" . $row['id_session'] . "','" . $row['course_code'] . "','" . $row['nbr_users'] . "')";
Database::query($presql);
}
$table = Database::get_main_table(TABLE_BUY_COURSE_COUNTRY);
$sql = "CREATE TABLE IF NOT EXISTS $table (
country_id int NOT NULL AUTO_INCREMENT,
@ -321,6 +362,18 @@ $sql = "CREATE TABLE IF NOT EXISTS $table (
swift VARCHAR(100) NOT NULL DEFAULT '')";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
name VARCHAR(255) NOT NULL DEFAULT '',
session_id INT unsigned NOT NULL DEFAULT '0',
title VARCHAR(200) NOT NULL DEFAULT '',
reference VARCHAR(20) NOT NULL DEFAULT '',
price FLOAT(11,2) NOT NULL DEFAULT '0',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
@ -333,6 +386,17 @@ $sql = "CREATE TABLE IF NOT EXISTS $table (
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_SESSION_SALE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
session_id INT unsigned NOT NULL DEFAULT '0',
price FLOAT(11,2) NOT NULL DEFAULT '0',
payment_type VARCHAR(100) NOT NULL DEFAULT '',
status VARCHAR(20) NOT NULL DEFAULT '',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_SALE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
@ -345,7 +409,7 @@ $sql = "CREATE TABLE IF NOT EXISTS $table (
Database::query($sql);
//Menu main tabs
$rsTab = $objPlugin->addTab('Buy Courses', 'plugin/buycourses/index.php');
$rsTab = $objPlugin->addTab($objPlugin->get_lang('BuyCourses'), 'plugin/buycourses/index.php');
if ($rsTab) {
echo "<script>location.href = '" . Security::remove_XSS($_SERVER['REQUEST_URI']) . "';</script>";

@ -35,20 +35,28 @@ $(document).ready(function () {
var visible = $(this).parent().parent().prev().prev().children().attr("checked");
var price = $(this).parent().parent().prev().children().attr("value");
var course_id = $(this).attr('id');
$.post("function.php", {tab: "save_mod", course_id: course_id, visible: visible, price: price},
var courseOrSession = $(this).parent().parent()[0].attributes[0].value;
if (courseOrSession.indexOf("session") > -1) {
courseOrSession = "session_id";
} else {
courseOrSession = "course_id";
}
var courseOrSessionObject = {tab: "save_mod", visible: visible, price: price};
courseOrSessionObject[courseOrSession] = course_id;
$.post("function.php", courseOrSessionObject,
function (data) {
if (data.status == "false") {
alert("Database Error");
} else {
$("#course" + data.course_id).children().attr("style", "display:''");
$("#course" + data.course_id).children().next().attr("style", "display:none");
$("#course" + data.course_id).parent().removeClass("fmod")
$("#course" + data.course_id).parent().children().each(function () {
courseOrSession = courseOrSession.replace("_id", "");
$("#" + courseOrSession + data.course_id).children().attr("style", "display:''");
$("#" + courseOrSession + data.course_id).children().next().attr("style", "display:none");
$("#" + courseOrSession + data.course_id).parent().removeClass("fmod")
$("#" + courseOrSession + data.course_id).parent().children().each(function () {
$(this).removeClass("btop");
});
}
}
}, "json");
});
$('#sync').click(function (e) {
@ -164,7 +172,7 @@ $(document).ready(function () {
e.stopPropagation();
});
$(".confirm_order").click(function (e) {
$(".confirm_order").click(function (e) {console.log('hey');
var vid = $(this).parent().attr("id");
$.post("function.php", {tab: "confirm_order", id: vid},
function (data) {

@ -1,3 +1,4 @@
<?php
$strings['plugin_title'] = "Sell courses";
$strings['plugin_comment'] = "Sell courses directly through your Chamilo portal, using a PayPal account to receive funds. This plugin is in beta version. Neither the Chamilo association nor the developers involved could be considered responsible of any issue you might suffer using this plugin.";
@ -12,6 +13,7 @@ $strings['OpenToTheWorld'] = "Public - access open to anybody";
$strings['Description'] = "Description";
$strings['Buy'] = "Buy";
$strings['Mostrar_disponibles'] = "Show available courses";
$strings['include_sessions'] = "Include sessions";
$strings['paypal_enable'] = "Enable PayPal";
$strings['transfer_enable'] = "Enable bank transfer";
$strings['unregistered_users_enable'] = "Allow anonymous users";
@ -30,6 +32,7 @@ $strings['ProblemToSubscribeTheUser'] = 'Problem subscribing the user';
$strings['TheSubscriptionAndActivationWereDoneSuccessfully'] = 'The subscription and activation were successful';
$strings['TheUserIsAlreadyRegisteredInTheCourse'] = 'The user is already registered in the course.';
$strings['CourseListOnSale'] = 'List of courses on sale';
$strings['BuySessions'] = "Buy sessions";
$strings['BuyCourses'] = 'Buy courses';
$strings['ConfigurationOfCoursesAndPrices'] = 'Courses and prices configuration';
$strings['ConfigurationOfPayments'] = 'Payments configuration';

@ -17,6 +17,7 @@ $strings['Description'] = "Description";
$strings['Buy'] = "Acheter";
$strings['Mostrar_disponibles'] = "Montrer les cours disponibles";
$strings['include_sessions'] = "Inclure les sessions";
$strings['paypal_enable'] = "Activer PayPal";
$strings['transfer_enable'] = "Activer les transferts bancaires";
$strings['unregistered_users_enable'] = "Permettre l'accès aux utilisateurs non enregistrés sur la plateforme";
@ -37,6 +38,7 @@ $strings['ProblemToSubscribeTheUser'] = "Problème d'inscription de l'utilisateu
$strings['TheSubscriptionAndActivationWereDoneSuccessfully'] = "L'inscription et l'activation se sont déroulés sans problème.";
$strings['TheUserIsAlreadyRegisteredInTheCourse'] = "L'utilisateur est déjà inscrit au cours";
$strings['CourseListOnSale'] = "Liste de cours en vente";
$strings['BuySessions'] = "Acheter des sessions";
$strings['BuyCourses'] = "Acheter des cours";
$strings['ConfigurationOfCoursesAndPrices'] = "Configuration des cours et prix";
$strings['ConfigurationOfPayments'] = "Configuration des paiements";

@ -17,6 +17,7 @@ $strings['Description'] = "Descripci&oacute;n";
$strings['Buy'] = "Comprar";
$strings['Mostrar_disponibles'] = "Mostrar cursos disponibles";
$strings['include_sessions'] = "Incluir sesiones";
$strings['paypal_enable'] = "Habilitar PayPal";
$strings['transfer_enable'] = "Habilitar transferencia";
$strings['unregistered_users_enable'] = "Permitir usuarios sin registro en la plataforma";
@ -37,6 +38,7 @@ $strings['ProblemToSubscribeTheUser'] = 'Problema para suscribir el usuario';
$strings['TheSubscriptionAndActivationWereDoneSuccessfully'] = 'La suscripción y la activación se realizaron con éxito.';
$strings['TheUserIsAlreadyRegisteredInTheCourse'] = 'El usuario ya está registrado en el curso.';
$strings['CourseListOnSale'] = 'Lista de cursos a la venta';
$strings['BuySessions'] = "Comprar sesiones";
$strings['BuyCourses'] = 'Comprar cursos';
$strings['ConfigurationOfCoursesAndPrices'] = 'Configuración de cursos y precios';
$strings['ConfigurationOfPayments'] = 'Configuración de pagos';

@ -16,31 +16,110 @@ require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php';
*/
function sync()
{
$tableBuySessionRelCourse = Database::get_main_table(TABLE_BUY_SESSION_COURSE);
$tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$sql = "UPDATE $tableBuySessionRelCourse SET sync = 0";
Database::query($sql);
$sql = "SELECT id_session, course_code, nbr_users FROM $tableSessionRelCourse";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$sql = "SELECT 1 FROM $tableBuySessionRelCourse WHERE id_session='" . $row['id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$sql = "UPDATE $tableBuySessionRelCourse SET sync = 1 WHERE id_session='" . $row['id'] . "';";
Database::query($sql);
} else {
$sql = "INSERT INTO $tableBuySessionRelCourse (id_session, course_code, nbr_users, sync)
VALUES ('" . $row['id_session'] . "', '" . $row['course_code'] . "', '" . $row['nbr_users'] . "', 1);";
Database::query($sql);
}
}
$sql = "DELETE FROM $tableBuySessionRelCourse WHERE sync = 0;";
Database::query($sql);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "UPDATE $tableBuyCourse SET sync = 0";
Database::query($sql);
$sql = "SELECT id FROM $tableCourse";
$sql = "SELECT id, code, title FROM $tableCourse";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$sql = "SELECT id_session FROM $tableBuySessionRelCourse
WHERE course_code = '" . $row['code'] . "' LIMIT 1";
$courseIdSession = Database::fetch_assoc(Database::query($sql))['id_session'];
if (!is_numeric($courseIdSession)) {
$courseIdSession = 0;
}
$sql = "SELECT 1 FROM $tableBuyCourse WHERE course_id='" . $row['id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$sql = "UPDATE $tableBuyCourse SET sync = 1 WHERE course_id='" . $row['id'] . "';";
$sql = "UPDATE $tableBuyCourse SET sync = 1, session_id = $courseIdSession WHERE course_id='" . $row['id'] . "';";
Database::query($sql);
} else {
$sql = "INSERT INTO $tableBuyCourse (course_id, visible, sync) VALUES ('" . $row['id'] . "', 0, 1);";
$sql = "INSERT INTO $tableBuyCourse (session_id, course_id, code, title, visible, sync)
VALUES ('" . $courseIdSession . "', '" . $row['id'] . "', '" .
$row['code'] . "', '" . $row['title'] . "', 0, 1);";
Database::query($sql);
}
}
$sql = "DELETE FROM $tableBuyCourse WHERE sync = 0;";
Database::query($sql);
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "UPDATE $tableBuySession SET sync = 0";
Database::query($sql);
$sql = "SELECT id, name, date_start, date_end FROM $tableSession";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$sql = "SELECT 1 FROM $tableBuySession WHERE session_id='" . $row['id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$sql = "UPDATE $tableBuySession SET sync = 1 WHERE session_id='" . $row['id'] . "';";
Database::query($sql);
} else {
$sql = "INSERT INTO $tableBuySession (session_id, name, date_start, date_end, visible, sync)
VALUES ('" . $row['id'] . "', '" . $row['name'] . "', '" .
$row['date_start'] . "', '" . $row['date_end'] . "', 0, 1);";
Database::query($sql);
}
}
$sql = "DELETE FROM $tableBuySession WHERE sync = 0;";
Database::query($sql);
}
/**
* List courses detils from the buy-course table and the course table
* List sessions details from the buy-session table and the session table
* @return array Results (list of session details)
*/
function listSessions()
{
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT a.session_id, a.visible, a.price, b.*
FROM $tableBuySession a, $tableSession b
WHERE a.session_id = b.id;";
$res = Database::query($sql);
$aux = array();
while ($row = Database::fetch_assoc($res)) {
$aux[] = $row;
}
return $aux;
}
/**
* List courses details from the buy-course table and the course table
* @return array Results (list of courses details)
*/
function listCourses()
@ -60,6 +139,97 @@ function listCourses()
return $aux;
}
/**
*
*/
function userSessionList()
{
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$tableBuySessionRelCourse = Database::get_main_table(TABLE_BUY_SESSION_COURSE);
$tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableSessionRelUser = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tableBuySessionTemporal = Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL);
// get existing sessions
$sql = "SELECT a.session_id, a.visible, a.price, b.*
FROM $tableBuySession a, $tableSession b
WHERE a.session_id = b.id AND a.visible = 1;";
$resSessions = Database::query($sql);
$auxSessions = array();
// loop through all sessions
while ($rowSession = Database::fetch_assoc($resSessions)) {
// get courses of current session
$sqlSessionCourse = "SELECT DISTINCT a.id_session, a.course_code, a.nbr_users
FROM $tableBuySessionRelCourse a, $tableSessionRelCourse b
WHERE a.id_session = b.id_session AND a.id_session = " . $rowSession['session_id'] . ";";
$resSessionCourse = Database::query($sqlSessionCourse);
$aux = array();
// loop through courses of current session
while ($rowSessionCourse = Database::fetch_assoc($resSessionCourse)) {
// get course of current session
$sql = "SELECT a.course_id, a.session_id, a.visible, a.price, b.*
FROM $tableBuyCourse a, $tableCourse b
WHERE a.code = b.code AND a.code = '" . $rowSessionCourse['course_code'] . "' AND a.visible = 1;";
$res = Database::query($sql);
// loop inside a course of current session
while ($row = Database::fetch_assoc($res)) {
//check teacher
$sql = "SELECT lastname, firstname
FROM course_rel_user a, user b
WHERE a.course_code='" . $row['code'] . "'
AND a.role<>'' AND a.role<>'NULL'
AND a.user_id=b.user_id;";
$tmp = Database::query($sql);
$rowTmp = Database::fetch_assoc($tmp);
$row['teacher'] = $rowTmp['firstname'] . ' ' . $rowTmp['lastname'];
//check images
if (file_exists("../../courses/" . $row['code'] . "/course-pic85x85.png")) {
$row['course_img'] = "courses/" . $row['code'] . "/course-pic85x85.png";
} else {
$row['course_img'] = "main/img/without_picture.png";
}
$row['price'] = number_format($row['price'], 2, '.', ' ');
$aux[] = $row;
}
}
//check if the user is enrolled in the current session
if (isset($_SESSION['_user']) || $_SESSION['_user']['user_id'] != '') {
$sql = "SELECT 1 FROM $tableSessionRelUser
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "YES";
} else {
$sql = "SELECT 1 FROM $tableBuySessionTemporal
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "TMP";
} else {
$rowSession['enrolled'] = "NO";
}
}
} else {
$sql = "SELECT 1 FROM $tableBuySessionTemporal
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "TMP";
} else {
$rowSession['enrolled'] = "NO";
}
}
// add courses to current session
$rowSession['courses'] = $aux;
// add the current whole session
$auxSessions[] = $rowSession;
}
return $auxSessions;
}
/**
*
*/
@ -72,7 +242,7 @@ function userCourseList()
$sql = "SELECT a.course_id, a.visible, a.price, b.*
FROM $tableBuyCourse a, $tableCourse b
WHERE a.course_id = b.id AND a.visible = 1;";
WHERE a.course_id = b.id AND a.session_id = 0 AND a.visible = 1;";
$res = Database::query($sql);
$aux = array();
while ($row = Database::fetch_assoc($res)) {
@ -132,7 +302,24 @@ function userCourseList()
/**
*
*/
function checkUserCourse($course, $user)
function checkUserBuy($parameter, $user, $type = 'COURSE')
{
$sql = "SELECT 1 FROM %s WHERE %s ='" . $parameter . "' AND id_user='" . $user . "';";
$sql = $type === 'SESSION' ?
sprintf($sql, Database::get_main_table(TABLE_MAIN_SESSION_USER), 'id_session') :
sprintf($sql, Database::get_main_table(TABLE_MAIN_COURSE_USER), 'course_code');
Database::query($sql);
if (Database::affected_rows() > 0) {
return true;
} else {
return false;
}
}
/**
*
*/
/*function checkUserCourse($course, $user)
{
$tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$sql = "SELECT 1 FROM $tableCourseRelUser
@ -144,12 +331,29 @@ function checkUserCourse($course, $user)
} else {
return false;
}
}*/
/**
*
*/
function checkUserBuyTransfer($parameter, $user, $type = 'COURSE')
{
$sql = "SELECT 1 FROM %s WHERE %s ='" . $parameter . "' AND id_user='" . $user . "';";
$sql = $type === 'SESSION' ?
sprintf($sql, Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL), 'session_id') :
sprintf($sql, Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL), 'course_code');
Database::query($sql);
if (Database::affected_rows() > 0) {
return true;
} else {
return false;
}
}
/**
*
*/
function checkUserCourseTransfer($course, $user)
/*function checkUserCourseTransfer($course, $user)
{
$tableBuyCourseTemporal = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "SELECT 1 FROM $tableBuyCourseTemporal
@ -161,7 +365,7 @@ function checkUserCourseTransfer($course, $user)
} else {
return false;
}
}
}*/
/**
*
@ -279,6 +483,96 @@ function findCurrency()
return $row['currency_code'];
}
/**
* Extended information about the session (from the session table as well as
* the buy_session table)
* @param string $code The session code
* @return array Info about the session
*/
function sessionInfo($code) //TODO
{
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$tableBuySessionRelCourse = Database::get_main_table(TABLE_BUY_SESSION_COURSE);
$tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableSessionRelUser = Database::get_main_table(TABLE_MAIN_SESSION_USER);
//$tableBuyCourseTemporal = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$tableBuySessionTemporal = Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL);
$code = Database::escape_string($code);
$sql = "SELECT a.session_id, a.visible, a.price, b.*
FROM $tableBuySession a, $tableSession b
WHERE a.session_id=b.id
AND a.visible = 1
AND b.id = '" . $code . "';";
$res = Database::query($sql);
$rowSession = Database::fetch_assoc($res);
$sqlSessionCourse = "SELECT DISTINCT a.id_session, a.course_code, a.nbr_users
FROM $tableBuySessionRelCourse a, $tableSessionRelCourse b
WHERE a.id_session = b.id_session AND a.id_session = " . $rowSession['session_id'] . ";";
$resSessionCourse = Database::query($sqlSessionCourse);
$aux = array();
// loop through courses of current session
while ($rowSessionCourse = Database::fetch_assoc($resSessionCourse)) {
// get course of current session
$sql = "SELECT a.course_id, a.session_id, a.visible, a.price, b.*
FROM $tableBuyCourse a, $tableCourse b
WHERE a.code = b.code AND a.code = '" . $rowSessionCourse['course_code'] . "' AND a.visible = 1;";
$res = Database::query($sql);
// loop inside a course of current session
while ($row = Database::fetch_assoc($res)) {
//check teacher
$sql = "SELECT lastname, firstname
FROM course_rel_user a, user b
WHERE a.course_code='" . $row['code'] . "'
AND a.role<>'' AND a.role<>'NULL'
AND a.user_id=b.user_id;";
$tmp = Database::query($sql);
$rowTmp = Database::fetch_assoc($tmp);
$row['teacher'] = $rowTmp['firstname'] . ' ' . $rowTmp['lastname'];
//check images
if (file_exists("../../courses/" . $row['code'] . "/course-pic85x85.png")) {
$row['course_img'] = "courses/" . $row['code'] . "/course-pic85x85.png";
} else {
$row['course_img'] = "main/img/without_picture.png";
}
$row['price'] = number_format($row['price'], 2, '.', ' ');
$aux[] = $row;
}
}
//check if the user is enrolled in the current session
if (isset($_SESSION['_user']) || $_SESSION['_user']['user_id'] != '') {
$sql = "SELECT 1 FROM $tableSessionRelUser
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "YES";
} else {
$sql = "SELECT 1 FROM $tableBuySessionTemporal
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "TMP";
} else {
$rowSession['enrolled'] = "NO";
}
}
} else {
$sql = "SELECT 1 FROM $tableBuySessionTemporal
WHERE user_id='" . $_SESSION['_user']['user_id'] . "';";
Database::query($sql);
if (Database::affected_rows() > 0) {
$rowSession['enrolled'] = "TMP";
} else {
$rowSession['enrolled'] = "NO";
}
}
// add courses to current session
$rowSession['courses'] = $aux;
return $rowSession;
}
/**
* Extended information about the course (from the course table as well as
* the buy_course table)
@ -366,10 +660,12 @@ function randomText($long = 6, $minWords = true, $maxWords = true, $number = tru
* Generates an order reference
* @result string A reference number
*/
function calculateReference()
function calculateReference($bc_codetext)
{
$tableBuyCourseTemporal = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "SELECT MAX(cod) as cod FROM $tableBuyCourseTemporal";
$tableBuyTemporal = $bc_codetext === 'THIS_IS_A_SESSION' ?
Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL) :
Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "SELECT MAX(cod) as cod FROM $tableBuyTemporal";
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
if ($row['cod'] != '') {
@ -379,7 +675,6 @@ function calculateReference()
}
$randomText = randomText();
$reference .= $randomText;
return $reference;
}
/**
@ -387,10 +682,12 @@ function calculateReference()
* @result array List of orders
* @todo Enable pagination
*/
function pendingList()
function pendingList($bc_codetext)
{
$tableBuyCourseTemporal = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "SELECT * FROM $tableBuyCourseTemporal;";
$tableBuyTemporal = $bc_codetext === 'THIS_IS_A_SESSION' ?
Database::get_main_table(TABLE_BUY_SESSION_TEMPORAL) :
Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "SELECT * FROM $tableBuyTemporal;";
$res = Database::query($sql);
$aux = array();
while ($row = Database::fetch_assoc($res)) {

@ -22,7 +22,17 @@ class BuyCoursesPlugin extends Plugin
protected function __construct()
{
parent::__construct('1.0', 'Jose Angel Ruiz - NoSoloRed (original author), Francis Gonzales and Yannick Warnier - BeezNest (integration)', array('paypal_enable' => 'boolean', 'transfer_enable' => 'boolean', 'unregistered_users_enable' => 'boolean'));
parent::__construct(
'1.0',
'Jose Angel Ruiz - NoSoloRed (original author),
Francis Gonzales and Yannick Warnier - BeezNest (integration)',
array(
'include_sessions' => 'boolean',
'paypal_enable' => 'boolean',
'transfer_enable' => 'boolean',
'unregistered_users_enable' => 'boolean'
)
);
}
/**
@ -38,28 +48,25 @@ class BuyCoursesPlugin extends Plugin
*/
function uninstall()
{
$table = Database::get_main_table(TABLE_BUY_COURSE);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_COUNTRY);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$tablesToBeDeleted = array(
TABLE_BUY_SESSION,
TABLE_BUY_SESSION_COURSE,
TABLE_BUY_SESSION_TEMPORAL,
TABLE_BUY_SESSION_SALE,
TABLE_BUY_COURSE,
TABLE_BUY_COURSE_COUNTRY,
TABLE_BUY_COURSE_PAYPAL,
TABLE_BUY_COURSE_TRANSFER,
TABLE_BUY_COURSE_TEMPORAL,
TABLE_BUY_COURSE_SALE
);
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
$table = Database::get_main_table($tableToBeDeleted);
$sql = "DROP TABLE IF EXISTS $tableToBeDeleted";
Database::query($sql);
}
$table = Database::get_main_table(TABLE_BUY_COURSE_PAYPAL);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_TRANSFER);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_SALE);
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$objPlugin = BuyCoursesPlugin::create();
$objPlugin->deleteTab('custom_tab_1');
}
}

@ -44,6 +44,18 @@ if ($teacher) {
$tpl->assign('save_img', $saveImgPath);
$tpl->assign('currency', $currencyType);
$result = array_shift(
Database::select(
'selected_value',
Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT),
array('where'=> array('variable = ?' => array('buycourses_include_sessions')))
)
);
if ($result['selected_value'] === 'true') {
$tpl->assign('sessionsAreIncluded', 'YES');
$tpl->assign('sessions', listSessions());
}
$listing_tpl = 'buycourses/view/configuration.tpl';
$content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content);

@ -13,8 +13,8 @@ require_once 'buy_course_plugin.class.php';
unset($_SESSION['bc_user_id']);
unset($_SESSION['bc_registered']);
unset($_SESSION['bc_course_code']);
unset($_SESSION['bc_course_title']);
unset($_SESSION['bc_code']);
unset($_SESSION['bc_title']);
unset($_SESSION['Payment_Amount']);
unset($_SESSION['currencyCodeType']);
unset($_SESSION['PaymentType']);

@ -12,11 +12,13 @@ require_once 'buy_course.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'course.lib.php';
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$tableBuyCourseCountry = Database::get_main_table(TABLE_BUY_COURSE_COUNTRY);
$tableBuyCoursePaypal = Database::get_main_table(TABLE_BUY_COURSE_PAYPAL);
$tableBuyCourseTransfer = Database::get_main_table(TABLE_BUY_COURSE_TRANSFER);
$tableBuyCourseTemporal = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
@ -25,12 +27,22 @@ $plugin = BuyCoursesPlugin::create();
$buy_name = $plugin->get_lang('Buy');
if ($_REQUEST['tab'] == 'sync') {
$sql = "SELECT code, title FROM $tableCourse;";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$aux_code .= $row['code'];
$aux_title .= $row['title'];
}
$sql = "SELECT name, date_start, date_end FROM $tableSession;";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$aux_name .= $row['name'];
$aux_date_start .= $row['date_start'];
$aux_date_end .= $row['date_end'];
}
echo json_encode(array("status" => "true", "content" => $content));
}
@ -232,29 +244,39 @@ if ($_REQUEST['tab'] == 'delete_account') {
if ($_REQUEST['tab'] == 'save_mod') {
$_REQUEST['id'] = Database::escape_string($_REQUEST['id']);
$idCourse = intval($_REQUEST['course_id']);
$id = intval($_REQUEST['course_id']);
$tableBuy = $tableBuyCourse;
$tableField = 'course_id';
if (isset($_REQUEST['session_id'])) {
$id = intval($_REQUEST['session_id']);
$tableBuy = $tableBuySession;
$tableField = 'session_id';
}
$visible = ($_REQUEST['visible'] == "checked") ? 1 : 0;
$price = Database::escape_string($_REQUEST['price']);
$sql = "UPDATE $tableBuyCourse
$sql = "UPDATE $tableBuy
SET visible = " . $visible . ",
price = '" . $price . "'
WHERE course_id = '" . $idCourse . "';";
WHERE " . $tableField . " = '" . $id . "';";
$res = Database::query($sql);
if (!res) {
$content = $plugin->get_lang('ProblemToSaveTheMessage') . Database::error();
echo json_encode(array("status" => "false", "content" => $content));
} else {
echo json_encode(array("status" => "true", "course_id" => $idCourse));
echo json_encode(array("status" => "true", "course_id" => $id));
}
}
if ($_REQUEST['tab'] == 'unset_variables') {
unset($_SESSION['bc_user_id']);
unset($_SESSION['bc_registered']);
unset($_SESSION['bc_course_code']);
unset($_SESSION['bc_course_title']);
unset($_SESSION['bc_code']);
unset($_SESSION['bc_title']);
unset($_SESSION["Payment_Amount"]);
unset($_SESSION["currencyCodeType"]);
unset($_SESSION["PaymentType"]);

@ -17,13 +17,15 @@ if ($guess_enable == "true" || isset($_SESSION['_user'])) {
$tpl = new Template($templateName);
$tpl->assign('isAdmin', api_is_platform_admin());
$tpl->assign('title', $title);
$tpl->assign('BuySessions', $plugin->get_lang('BuySessions'));
$tpl->assign('BuyCourses', $templateName);
$tpl->assign('ConfigurationOfSessionsAndPrices', $plugin->get_lang('ConfigurationOfSessionsAndPrices'));
$tpl->assign('ConfigurationOfCoursesAndPrices', $plugin->get_lang('ConfigurationOfCoursesAndPrices'));
$tpl->assign('ConfigurationOfPayments', $plugin->get_lang('ConfigurationOfPayments'));
$tpl->assign('OrdersPendingOfPayment', $plugin->get_lang('OrdersPendingOfPayment'));
$listing_tpl = 'buycourses/view/index.tpl';
$content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
}

@ -50,6 +50,19 @@ $tpl->assign('courses', $courseList);
$tpl->assign('category', $categoryList);
$tpl->assign('currency', $currencyType);
$result = array_shift(
Database::select(
'selected_value',
Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT),
array('where'=> array('variable = ?' => array('buycourses_include_sessions')))
)
);
if ($result['selected_value'] === 'true') {
$tpl->assign('sessionsAreIncluded', 'YES');
$tpl->assign('sessions', userSessionList());
}
$listing_tpl = 'buycourses/view/list.tpl';
$content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content);

@ -22,7 +22,7 @@ $teacher = api_is_platform_admin();
api_protect_course_script(true);
if ($teacher) {
$pendingList = pendingList();
$pendingList = pendingList($_SESSION['bc_codetext']);
$confirmationImg = api_get_path(WEB_PLUGIN_PATH) . 'buycourses/resources/message_confirmation.png';
$deleteImg = api_get_path(WEB_PLUGIN_PATH) . 'buycourses/resources/delete.png';
$currencyType = findCurrency();

@ -18,25 +18,51 @@ $interbreadcrumb[] = array("url" => "list.php", "name" => $plugin->get_lang('Cou
$tpl = new Template($templateName);
if (!empty($_GET['code'])) {
$codeType = "COURSE";
$code = (int)$_GET['code'];
} else if (!empty($_GET['scode'])) {
$codeType = "SESSION";
$code = (int)$_GET['scode'];
} else {
$code = $_SESSION['bc_course_code'];
$code = $_SESSION['bc_code'];
}
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$result = array_shift(
Database::select(
'selected_value',
Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT),
array('where'=> array('variable = ?' => array('buycourses_include_sessions')))
)
);
$sql = "SELECT a.price, a.title, b.code
if ($codeType === 'SESSION' && $result['selected_value'] === 'true') {
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$tableBuySession = Database::get_main_table(TABLE_BUY_SESSION);
$sql = "SELECT a.session_id, a.name, a.date_start, a.date_end, a.price
FROM $tableBuySession a, $tableSession b
WHERE a.session_id = " . $code . "
AND a.session_id = b.id;";
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
$_SESSION['bc_title'] = $row['name'];
$_SESSION['bc_codetext'] = 'THIS_IS_A_SESSION';
$tpl->assign('session', sessionInfo($code));
$tpl->assign('isSession', 'YES');
} else {
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tableBuyCourse = Database::get_main_table(TABLE_BUY_COURSE);
$sql = "SELECT a.price, a.title, b.code
FROM $tableBuyCourse a, $tableCourse b
WHERE a.course_id = " . $code . "
AND a.course_id = b.id;";
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
$_SESSION['bc_title'] = $row['title'];
$_SESSION['bc_codetext'] = $row['code'];
$tpl->assign('course', courseInfo($code));
}
$_SESSION['Payment_Amount'] = number_format($row['price'], 2, '.', '');
$_SESSION['bc_course_code'] = $code;
$_SESSION['bc_course_title'] = $row['title'];
$_SESSION['bc_course_codetext'] = $row['code'];
$_SESSION['bc_code'] = $code;
if (!isset($_SESSION['_user'])) {
//Needs to be Registered
@ -57,30 +83,28 @@ if (!isset($_SESSION['_user'])) {
$tpl->assign('user', $_SESSION['bc_user']['username']);
}
if (checkUserCourse($_SESSION['bc_course_codetext'], $_SESSION['bc_user_id'])) {
$currencyType = findCurrency();
$paypalEnable = $plugin->get('paypal_enable');
$transferEnable = $plugin->get('transfer_enable');
if (checkUserBuy($_SESSION['bc_codetext'], $_SESSION['bc_user_id'], $codeType)) {
$_SESSION['bc_success'] = false;
$_SESSION['bc_message'] = 'AlreadyBuy';
header('Location: list.php');
}
if (checkUserCourseTransfer($_SESSION['bc_course_codetext'], $_SESSION['bc_user_id'])) {
if (checkUserBuyTransfer($_SESSION['bc_codetext'], $_SESSION['bc_user_id'], $codeType)) {
$_SESSION['bc_success'] = false;
$_SESSION['bc_message'] = 'bc_tmp_registered';
header('Location: list.php');
}
$currencyType = findCurrency();
$paypalEnable = $plugin->get('paypal_enable');
$transferEnable = $plugin->get('transfer_enable');
$courseInfo = courseInfo($code);
$tpl->assign('course', $courseInfo);
$tpl->assign('server', $_configuration['root_web']);
$tpl->assign('paypal_enable', $paypalEnable);
$tpl->assign('transfer_enable', $transferEnable);
$tpl->assign('title', $_SESSION['bc_course_title']);
$tpl->assign('title', $_SESSION['bc_title']);
$tpl->assign('price', $_SESSION['Payment_Amount']);
$tpl->assign('currency', $currencyType);

@ -21,8 +21,7 @@ $tableBuyCoursePaypal = Database::get_main_table(TABLE_BUY_COURSE_PAYPAL);
if (isset($_POST['Confirm'])) {
// Save the user, course and reference in a tmp table
$user_id = $_SESSION['bc_user_id'];
$course_code = $_SESSION['bc_course_codetext'];
$reference = calculateReference();
$reference = calculateReference($_SESSION['bc_codetext']);
reset($_POST);
while (list ($param, $val) = each($_POST)) {
@ -30,8 +29,11 @@ if (isset($_POST['Confirm'])) {
eval($asignacion);
}
$sql = "INSERT INTO $tableBuyCourseTemporal (user_id, name, course_code, title, reference, price)
VALUES ('" . $user_id . "', '" . $name . "','" . $course_code . "','" . $title . "','" . $reference . "','" . $price . "');";
$sql = $_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION' ?
"INSERT INTO $tableBuySessionTemporal (user_id, name, session_id, title, reference, price)
VALUES ('" . $user_id . "', '" . $name . "','" . $_SESSION['bc_code'] . "','" . $title . "','" . $reference . "','" . $price . "');" :
"INSERT INTO $tableBuyCourseTemporal (user_id, name, course_code, title, reference, price)
VALUES ('" . $user_id . "', '" . $name . "','" . $_SESSION['bc_codetext'] . "','" . $title . "','" . $reference . "','" . $price . "');";
$res = Database::query($sql);
// Notify the user and send the bank info
@ -62,12 +64,12 @@ if (isset($_POST['Confirm'])) {
$email = $_SESSION['bc_user']['email'];
}
$courseInfo = courseInfo($_SESSION['bc_course_code']);
$title_course = $courseInfo['title'];
$message = $plugin->get_lang('bc_message');
$message = str_replace("{{name}}", $name, $message);
$message = str_replace("{{course}}", $title_course, $message);
$_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION' ?
$message = str_replace("{{session}}", sessionInfo($_SESSION['bc_code'])['name'], $message) :
$message = str_replace("{{course}}", courseInfo($_SESSION['bc_code'])['title'], $message);
$message = str_replace("{{".$parameterName."}}", $title, $message);
$message = str_replace("{{reference}}", $reference, $message);
$message .= $text;
@ -97,10 +99,13 @@ if ($_POST['payment_type'] == "PayPal") {
$returnURL = $server . "plugin/buycourses/src/success.php";
$cancelURL = $server . "plugin/buycourses/src/error.php";
$courseInfo = courseInfo($_SESSION['bc_course_code']);
$courseTitle = $courseInfo['title'];
$title = $_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION' ?
sessionInfo($_SESSION['bc_code'])['name'] :
courseInfo($_SESSION['bc_code'])['title'];
$i = 0;
$extra = "&L_PAYMENTREQUEST_0_NAME" . $i . "=" . $courseTitle;
$extra = "&L_PAYMENTREQUEST_0_NAME" . $i . "=" . $title;
$extra .= "&L_PAYMENTREQUEST_0_AMT" . $i . "=" . $paymentAmount;
$extra .= "&L_PAYMENTREQUEST_0_QTY" . $i . "=1";
@ -130,12 +135,12 @@ if ($_POST['payment_type'] == "Transfer") {
$tpl = new Template($templateName);
$code = $_SESSION['bc_course_code'];
$courseInfo = courseInfo($code);
$_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION' ?
$tpl->assign('session', sessionInfo($_SESSION['bc_code'])) :
$tpl->assign('course', courseInfo($_SESSION['bc_code']));
$tpl->assign('course', $courseInfo);
$tpl->assign('server', $_configuration['root_web']);
$tpl->assign('title', $_SESSION['bc_course_title']);
$tpl->assign('title', $_SESSION['bc_title']);
$tpl->assign('price', $_SESSION['Payment_Amount']);
$tpl->assign('currency', $_SESSION['bc_currency_type']);
if (!isset($_SESSION['_user'])) {

@ -106,12 +106,11 @@ if (!isset($_POST['paymentOption'])) {
$tpl = new Template($templateName);
$code = $_SESSION['bc_course_code'];
$courseInfo = courseInfo($code);
$tpl->assign('course', $courseInfo);
$_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION' ?
$tpl->assign('session', sessionInfo($_SESSION['bc_code'])) :
$tpl->assign('course', courseInfo($_SESSION['bc_code']));
$tpl->assign('server', $_configuration['root_web']);
$tpl->assign('title', $_SESSION['bc_course_title']);
$tpl->assign('title', $_SESSION['bc_title']);
$tpl->assign('price', $_SESSION['Payment_Amount']);
$tpl->assign('currency', $_SESSION['bc_currency_type']);
if (!isset($_SESSION['_user'])) {
@ -211,29 +210,49 @@ if (!isset($_POST['paymentOption'])) {
* refund: A reversal has occurred on this transaction because you have given the customer a refund.
* other: A reversal has occurred on this transaction due to a reason not listed above.
*/
//api_get_session_info($session_id)
$reasonCode = $resArray["PAYMENTINFO_0_REASONCODE"];
// Insert the user information to activate the user
if ($paymentStatus == "Completed") {
$user_id = $_SESSION['bc_user_id'];
$course_code = $_SESSION['bc_course_codetext'];
$all_course_information = CourseManager::get_course_information($course_code);
if (CourseManager::subscribe_user($user_id, $course_code)) {
$send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
if ($send == 1) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
} else if ($send == 2) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
if ($_SESSION['bc_codetext'] === 'THIS_IS_A_SESSION') {
$session_id = $_SESSION['bc_code'];
$all_session_information = Session::api_get_session_info($session_id);
if (SessionManager::suscribe_users_to_session($session_id, array($user_id),
api_get_session_visibility($session_id), false)) {
//$send = api_get_session_setting('email_alert_to_teacher_on_new_user_in_session', $session_id);
//if ($send == 1) {
//SessionManager::email_to_tutor($user_id, $session_id, $send_to_tutor_also = false);
/*} else if ($send == 2) {
CourseManager::email_to_tutor($user_id, $session_id, $send_to_tutor_also = true);
}*/
//$url = Display::url($all_session_information['name'], api_get_session_url($session_id));
$_SESSION['bc_message'] = 'EnrollToSessionXSuccessful';
$_SESSION['bc_url'] = '';//$url;
$_SESSION['bc_success'] = true;
} else {
$_SESSION['bc_message'] = 'ErrorContactPlatformAdmin';
$_SESSION['bc_success'] = false;
}
$url = Display::url($all_course_information['title'], api_get_course_url($course_code));
$_SESSION['bc_message'] = 'EnrollToCourseXSuccessful';
$_SESSION['bc_url'] = $url;
$_SESSION['bc_success'] = true;
} else {
$_SESSION['bc_message'] = 'ErrorContactPlatformAdmin';
$_SESSION['bc_success'] = false;
$course_code = $_SESSION['bc_codetext'];
$all_course_information = CourseManager::get_course_information($course_code);
if (CourseManager::subscribe_user($user_id, $course_code)) {
$send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
if ($send == 1) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
} else if ($send == 2) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
}
$url = Display::url($all_course_information['title'], api_get_course_url($course_code));
$_SESSION['bc_message'] = 'EnrollToCourseXSuccessful';
$_SESSION['bc_url'] = $url;
$_SESSION['bc_success'] = true;
} else {
$_SESSION['bc_message'] = 'ErrorContactPlatformAdmin';
$_SESSION['bc_success'] = false;
}
}
// Activate the use
$TABLE_USER = Database::get_main_table(TABLE_MAIN_USER);
@ -263,23 +282,27 @@ if (!isset($_POST['paymentOption'])) {
$_user['lastLogin'] = api_strtotime($uData['login_date'], 'UTC');
$is_platformAdmin = (bool)(!is_null($uData['is_admin']));
$is_allowedCreateCourse = (bool)(($uData ['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $uData['status'] == DRH));
ConditionalLogin::check_conditions($uData);
Session::write('_user', $_user);
UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true');
Session::write('is_platformAdmin', $is_platformAdmin);
Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
} else {
header('location:' . api_get_path(WEB_PATH));
}
// Delete variables
unset($_SESSION['bc_user_id']);
unset($_SESSION['bc_course_code']);
unset($_SESSION['bc_course_codetext']);
unset($_SESSION['bc_course_title']);
unset($_SESSION['bc_code']);
unset($_SESSION['bc_codetext']);
unset($_SESSION['bc_title']);
unset($_SESSION['bc_user']);
unset($_SESSION["Payment_Amount"]);
unset($_SESSION["sec_token"]);
@ -290,8 +313,8 @@ if (!isset($_POST['paymentOption'])) {
header('Location:list.php');
} else {
$_SESSION['bc_message'] = 'CancelOrder';
unset($_SESSION['bc_course_code']);
unset($_SESSION['bc_course_title']);
unset($_SESSION['bc_code']);
unset($_SESSION['bc_title']);
unset($_SESSION["Payment_Amount"]);
unset($_SESSION["currencyCodeType"]);
unset($_SESSION["PaymentType"]);
@ -306,9 +329,9 @@ if (!isset($_POST['paymentOption'])) {
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
$_SESSION['bc_message'] = 'ErrorContactPlatformAdmin';
unset($_SESSION['bc_course_code']);
unset($_SESSION['bc_course_codetext']);
unset($_SESSION['bc_course_title']);
unset($_SESSION['bc_code']);
unset($_SESSION['bc_codetext']);
unset($_SESSION['bc_title']);
unset($_SESSION["Payment_Amount"]);
unset($_SESSION["currencyCodeType"]);
unset($_SESSION["PaymentType"]);

@ -2,7 +2,23 @@
<link rel="stylesheet" type="text/css" href="../resources/plugin.css"/>
<div class="row">
<script>
$(function() {
/* Binds a tab id in the url */
$("#tabs").bind('tabsselect', function(event, ui) {
window.location.href=ui.tab;
});
// Generate tabs with jquery-ui
$('#tabs').tabs();
$( "#sub_tab" ).tabs();
});
</script>
{% if sessionsAreIncluded == "YES" %}
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs"> <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"> <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"> <a href="#tabs-1"> Cursos</a></li><li class="ui-state-default ui-corner-top"> <a href="#tabs-2"> Sesiones</a></li></ul>
{% endif %}
<div id="tabs-1" class="row">
<div class="span12">
<table id="courses_table" class="data_table">
<tr class="row_odd">
@ -43,3 +59,50 @@
</div>
<div class="cleared"></div>
</div>
{% if sessionsAreIncluded == "YES" %}
<div id="tabs-2" class="row">
<div class="span12">
<table id="courses_table" class="data_table">
<tr class="row_odd">
<th>{{ 'Title'|get_lang }}</th>
<th>{{ 'StartDate'|get_lang }}</th>
<th>{{ 'EndDate'|get_lang }}</th>
<th class="ta-center">{{ 'Visible'|get_lang }}</th>
<th class="span2">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="span1 ta-center">{{ 'Option'|get_lang }}</th>
</tr>
{% set i = 0 %}
{% for session in sessions %}
{{ i%2 == 0 ? '<tr class="row_even">' : '<tr class="row_odd">' }}
{% set i = i + 1 %}
<td>
{{ visibility[session.visibility] }}
<a href="{{ server }}main/session/index.php?session_id={{ session.id }}">{{session.name}}</a>
</td>
<td>
{{session.date_start}}
</td>
<td>
{{session.date_end}}
</td>
<td class="ta-center">
{% if session.visible == 1 %}
<input type="checkbox" name="visible" value="1" checked="checked" size="6" />
{% else %}
<input type="checkbox" name="visible" value="1" size="6" />
{% endif %}
</td>
<td><input type="text" name="price" value="{{session.price}}" class="span1 price" /> {{ currency }}</td>
<td class=" ta-center" id="session{{ session.id }}">
<div class="confirmed"><img src="{{ confirmation_img }}" alt="ok"/></div>
<div class="modified" style="display:none"><img id="{{session.id}}" src="{{ save_img }}" alt="save" class="cursor save"/></div>
</td>
</tr>
{% endfor %}
</table>
</div>
<div class="cleared"></div>
</div>
</div>
{% endif %}

@ -3,7 +3,7 @@
<ul class="nav nav-list">
<li>
<a href="src/list.php"> {{ BuyCourses }} </a>
</li>
</li>
{% if isAdmin == 'true' %}
<li>
<a href="src/configuration.php"> {{ ConfigurationOfCoursesAndPrices }} </a>

@ -1,10 +1,27 @@
<script type='text/javascript' src="../js/buycourses.js"></script>
<link rel="stylesheet" type="text/css" href="../resources/plugin.css"/>
<div class="row">
<script>
$(function() {
/* Binds a tab id in the url */
$("#tabs").bind('tabsselect', function(event, ui) {
window.location.href=ui.tab;
});
// Generate tabs with jquery-ui
$('#tabs').tabs();
$( "#sub_tab" ).tabs();
});
</script>
{% if sessionsAreIncluded == "YES" %}
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs"> <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"> <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"> <a href="#tabs-1"> Cursos</a></li><li class="ui-state-default ui-corner-top"> <a href="#tabs-2"> Sesiones</a></li></ul>
{% endif %}
<div id="tabs-1" class="row">
<div class="span3">
<div id="course_category_well" class="well">
<ul class="nav nav-list">
<ul class="nav nav-list">
<li class="nav-header"><h4>{{ 'SearchFilter'|get_plugin_lang('BuyCoursesPlugin') }}:</h4></li>
<li class="nav-header">{{ 'CourseName'|get_lang }}:</li>
<li><input type="text" id="course_name" style="width:95%"/></li>
@ -30,7 +47,7 @@
</ul>
</div>
</div>
<div class="span9" id="course_results">
<div class="span8" id="course_results">
{% if rmessage == "YES" %}
<div class="{{ class }}">
{{ responseMessage }}
@ -79,3 +96,99 @@
{% endfor %}
</div>
</div>
{% if sessionsAreIncluded == "YES" %}
<div id="tabs-2" class="row">
<div class="span3">
<div id="course_category_well" class="well">
<ul class="nav nav-list">
<li class="nav-header"><h4>{{ 'SearchFilter'|get_plugin_lang('BuyCoursesPlugin') }}:</h4></li>
<li class="nav-header">{{ 'Nombre de la sesión'|get_lang }}:</li>
<li><input type="text" id="course_name" style="width:95%"/></li>
<li class="nav-header">{{ 'MinimumPrice'|get_plugin_lang('BuyCoursesPlugin') }}:
<input type="text" id="price_min" class="span1"/>
</li>
<li class="nav-header">{{ 'MaximumPrice'|get_plugin_lang('BuyCoursesPlugin') }}:
<input type="text" id="price_max" class="span1"/>
</li>
<li class="nav-header">{{ 'Categories'|get_lang }}:</li>
<li>
<select id="courses_category">
<option value="" selected="selected"></option>
{% for category in categories %}
<option value="{{ category.code }}">{{ category.name }}</option>
{% endfor %}
</select>
</li>
<br />
<li class="ta-center">
<input type="button" class="btn btn-primary" value="Search Courses" id="confirm_filter" />
</li>
</ul>
</div>
</div>
<div class="span8" id="session_results">
{% if rmessage == "YES" %}
<div class="{{ class }}">
{{ responseMessage }}
</div>
{% endif %}
{% for session in sessions %}
<div class="well_border span8">
<div class="row">
<div class="span4 ">
<div class="categories-course-description">
<h3>{{ session.name }}</h3>
<h5>{{ 'From'|get_lang }} {{ session.date_start }} {{ 'To'|get_lang }} {{ session.date_end }}</h5>
</div>
</div>
<div class="span right">
<div class="sprice right">
{{ session.price }} {{ currency }}
</div>
<div class="cleared"></div>
<div class="btn-toolbar right">
{% if session.enrolled == "NO" %}
<a class="btn btn-success" title="" href="{{ server }}plugin/buycourses/src/process.php?scode={{ session.session_id }}">
{{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
{% endif %}
</div>
</div>
</div>
{% for course in session.courses %}
<div class="row">
<div class="span">
<div class="thumbnail">
<a class="ajax" rel="gb_page_center[778]" title="" href="{{ server }}plugin/buycourses/src/ajax.php?code={{ course.code }}">
<img alt="" src="{{ server }}{{ course.course_img }}">
</a>
</div>
</div>
<div class="span4">
<div class="categories-course-description">
<h3>{{ course.title }}</h3>
<h5>{{ 'Teacher'|get_lang }}: {{ course.teacher }}</h5>
</div>
{% if course.enrolled == "YES" %}
<span class="label label-info">{{ 'TheUserIsAlreadyRegisteredInTheCourse'|get_plugin_lang('BuyCoursesPlugin') }}</span>
{% endif %}
{% if course.enrolled == "TMP" %}
<span class="label label-warning">{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}</span>
{% endif %}
</div>
<div class="span right">
<div class="cleared"></div>
<div class="btn-toolbar right">
<a class="ajax btn btn-primary" title="" href="{{ server }}plugin/buycourses/src/ajax.php?code={{ course.code }}">
{{ 'Description'|get_lang }}
</a>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</div>
{% endif %}

@ -18,8 +18,54 @@
</div>
<br/><br/>
<div class="well_border span8">
{% if isSession == "YES" %}
<div class="row">
<div class="span4">
<div class="categories-course-description">
<h3>{{ title }}</h3>
<h5>{{ 'From'|get_lang }} {{ session.date_start }} {{ 'To'|get_lang }} {{ session.date_end }}</h5>
</div>
</div>
<div class="span right">
<div class="sprice right">
{{ session.price }} {{ currency }}
</div>
<div class="cleared"></div>
</div>
</div>
{% for course in session.courses %}
<div class="row">
<div class="span">
<div class="thumbnail">
<a class="ajax" rel="gb_page_center[778]" title="" href="{{ server }}plugin/buycourses/src/ajax.php?code={{ course.code }}">
<img alt="" src="{{ server }}{{ course.course_img }}">
</a>
</div>
</div>
<div class="span4">
<div class="categories-course-description">
<h3>{{ course.title }}</h3>
<h5>{{ 'Teacher'|get_lang }}: {{ course.teacher }}</h5>
</div>
{% if course.enrolled == "YES" %}
<span class="label label-info">{{ 'TheUserIsAlreadyRegisteredInTheCourse'|get_plugin_lang('BuyCoursesPlugin') }}</span>
{% endif %}
{% if course.enrolled == "TMP" %}
<span class="label label-warning">{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}</span>
{% endif %}
</div>
<div class="span right">
<div class="cleared"></div>
<div class="btn-toolbar right">
<a class="ajax btn btn-primary" title="" href="{{ server }}plugin/buycourses/src/ajax.php?code={{ course.code }}">
{{ 'Description'|get_lang }}
</a>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="row">
<div class="span">
<div class="thumbnail">
@ -45,6 +91,7 @@
</div>
</div>
</div>
{% endif %}
</div>
</div>
<div class="cleared"></div>

Loading…
Cancel
Save