@ -17,105 +17,68 @@ $tableUser = Database::get_main_table(TABLE_MAIN_USER);
$plugin = Buy_CoursesPlugin::create();
$buy_name = $plugin->get_lang('Buy');
function quitar_html($cadena)
{
$txt = str_replace("< br / > ", chr(13) . chr(10), $cadena);
$txt = str_replace("< br > ", chr(13) . chr(10), $txt);
$txt = str_replace("< li > ", chr(13) . chr(10) . " <EFBFBD> ", $txt);
$txt = str_replace("< li > ", chr(13) . chr(10) . "<EFBFBD> ", $txt);
$txt = str_replace("< br / > ", chr(13) . chr(10), $txt);
$txt = str_replace("< / p > ", chr(13) . chr(10), $txt);
$txt = str_replace("< p > ", "", $txt);
$txt = str_replace("< / tr > ", chr(13) . chr(10), $txt);
$txt = str_replace("< / td > ", " algo ", $txt);
$txt = str_replace("< / table > ", chr(13) . chr(10), $txt);
$txt = strip_tags($txt);
$txt = str_replace(" ", " ", $txt);
$txt = str_replace("Á ", "<EFBFBD> ", $txt);
$txt = str_replace("á ", "<EFBFBD> ", $txt);
$txt = str_replace("É ", "<EFBFBD> ", $txt);
$txt = str_replace("é ", "<EFBFBD> ", $txt);
$txt = str_replace("Í ", "<EFBFBD> ", $txt);
$txt = str_replace("í ", "<EFBFBD> ", $txt);
$txt = str_replace("Ó ", "<EFBFBD> ", $txt);
$txt = str_replace("ó ", "<EFBFBD> ", $txt);
$txt = str_replace("Ú ", "<EFBFBD> ", $txt);
$txt = str_replace("ú ", "<EFBFBD> ", $txt);
$txt = str_replace("Ñ ", "<EFBFBD> ", $txt);
$txt = str_replace("ñ ", "<EFBFBD> ", $txt);
$txt = str_replace("" ", '"', $txt);
$txt = str_replace("ª ", '<EFBFBD> ', $txt);
$txt = str_replace("º ", '<EFBFBD> ', $txt);
$txt = str_replace("& ", '& ', $txt);
$txt = str_replace("• ", '<EFBFBD> ', $txt);
$txt = str_replace("€ ", '<EFBFBD> ', $txt);
return $txt;
}
if ($_REQUEST['tab'] == 'sincronizar') {
$sql = "SELECT code,title FROM $tableCourse;";
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'];
}
echo json_encode(array("status" => "true", "contenido" => $contenido ));
echo json_encode(array("status" => "true", "content" => $content));
}
if ($_REQUEST['tab'] == 'filtro_cursos ') {
$curso = $_REQUEST['curso'] ;
$priceMin = $_REQUEST['pricemin'];
$priceMax = $_REQUEST['pricemax'];
$mostrar = $_REQUEST['mostrar'] ;
$categoria = $_REQUEST['categoria'] ;
$server = $_configuration['root_web'];
$filtro = '';
if ($curso != '') {
$filtro .= "b.title LIKE '%" . $curso . "%'";
if ($_REQUEST['tab'] == 'courses_filter') {
$course = Database::escape_string($_REQUEST['course']);
$priceMin = Database::escape_string($_REQUEST['pricemin']);
$priceMax = Database::escape_string($_REQUEST['pricemax']);
$show = Database::escape_string($_REQUEST['show']);
$category = Database::escape_string($_REQUEST['category']);
$server = Database::escape_string($_configuration['root_web']);
$filter = '';
if ($course != '') {
$filter .= "b.title LIKE '%" . $course . "%'";
}
if ($priceMin != '') {
if ($filtro == '') {
$filtro .= "a.price >= '" . $priceMin . "'";
if ($filter == '') {
$filter .= "a.price >= '" . $priceMin . "'";
} else {
$filtro .= " AND a.price >= '" . $priceMin . "'";
$filter .= " AND a.price >= '" . $priceMin . "'";
}
}
if ($priceMax != '') {
if ($filtro == '') {
$filtro .= "a.price < = '" . $priceMax . "'";
if ($filter == '') {
$filter .= "a.price < = '" . $priceMax . "'";
} else {
$filtro .= " AND a.price < = '" . $priceMax . "'";
$filter .= " AND a.price < = '" . $priceMax . "'";
}
}
if ($categoria != '') {
if ($filtro == '') {
$filtro .= "b.category_code='" . $categoria . "'";
if ($category != '') {
if ($filte r == '') {
$filter .= "b.category_code='" . $category . "'";
} else {
$filtro .= " AND b.category_code='" . $categoria . "'";
$filte r .= " AND b.category_code='" . $category . "'";
}
}
if ($filtro == '') {
if ($filte r == '') {
$sql = "SELECT a.id_course, a.visible, a.price, b.*
FROM $tableBuyCourse a, $tableCourse b
WHERE a.id_course = b.id
AND a.visible = 'SI' ;";
AND a.visible = 1 ;";
} else {
$sql = "SELECT a.id_course, a.visible, a.price, b.*
FROM $tableBuyCourse a, $tableCourse b
WHERE a.id_course=b.id
AND a.visible='SI' AND " . $filtro . ";";
WHERE a.id_course = b.id
AND a.visible = 1 AND " . $filter . ";";
}
//echo $sql;
$res = Database::query($sql);
$aux = array();
while ($row = Database::fetch_assoc($res)) {
//Comprobamos profeso r
//Check teache r
$sql = "SELECT lastname, firstname
FROM $tableCourseRelUser a, $tableUser b
WHERE a.course_code = '" . $row['code'] . "'
@ -124,94 +87,94 @@ if ($_REQUEST['tab'] == 'filtro_cursos') {
AND a.user_id = b.user_id;";
$tmp = Database::query($sql);
$fila = Database::fetch_assoc($tmp);
$row['profesor'] = $fila['firstname'] . ' ' . $fila ['lastname'];
//Comprobamos si el alumno est<EFBFBD> matriculado
$rowTmp = Database::fetch_assoc($tmp);
$row['teacher'] = $rowTmp['firstname'] . ' ' . $rowTmp ['lastname'];
//Check if the student is enrolled
if (isset($_SESSION['_user']) || $_SESSION['_user']['user_id'] != '') {
$sql = "SELECT 1 FROM $tableCourseRelUser
WHERE course_code='" . $row['code'] . "'
AND user_id='" . $_SESSION['_user']['user_id'] . "' ;";
WHERE course_code = '" . $row['code'] . "'
AND user_id = " . intval($_SESSION['_user']['user_id']) . " ;";
$tmp = Database::query($sql);
if (Database::affected_rows() > 0) {
$row['matriculado '] = "SI";
$row['enrolled '] = "SI";
} else {
$row['matriculado '] = "NO";
$row['enrolled '] = "NO";
}
} else {
$row['matriculado '] = "NO";
$row['enrolled '] = "NO";
}
//Comprobamos imagen
if (file_exists("../../../courses/" . $row['code'] . "/course-pic85x85.png")) {
$row['imagen_curso '] = "courses/" . $row['code'] . "/course-pic85x85.png";
$row['course_img '] = "courses/" . $row['code'] . "/course-pic85x85.png";
} else {
$row['imagen_curso '] = "main/img/without_picture.png";
$row['course_img '] = "main/img/without_picture.png";
}
if ($mostrar == "SI" & & $row['matriculado'] == "SI ") {
//No hacemos nada
if ($show == "YES" & & $row['enrolled'] == "YES ") {
;
} else {
$aux[] = $row;
}
}
foreach ($aux as $curso) { //{% for curso in cursos %}
$contenido .= '< div class = "well_border span8" > ';
$contenido .= '< div class = "row" > ';
$contenido .= '< div class = "span" > ';
$contenido .= '< div class = "thumbnail" > ';
$contenido .= '< a class = "ajax" rel = "gb_page_center[778]" title = "" href = "' . $server . 'main/inc/ajax/course_home.ajax.php?a=show_course_information&code=' . $curso ['code'] . '" > ';
$contenido .= '< img alt = "" src = "' . $server . $curso['imagen_curso '] . '" > ';
$contenido .= '< / a > ';
$contenido .= '< / div > ';
$contenido .= '< / div > ';
$contenido .= '< div class = "span4" > ';
$contenido .= '< div class = "categories-course-description" > ';
$contenido .= '< h3 > ' . $curso ['title'] . '< / h3 > ';
$contenido .= '< h5 > Profesor: ' . $curso['profeso r'] . '< / h5 > ';
$contenido .= '< / div > ';
if ($curso['matriculado'] == "SI") { //{% if curso.matriculado == "SI" %}
$contenido .= '< span class = "label label-info" > Ya se encuentra registrado en el curso < / span > ';
} //{% endif %}
$contenido .= '< / div > ';
$contenido .= '< div class = "span right" > ';
$contenido .= '< div class = "sprice right" > ' . $curso ['price'] . ' € < / div > ';
$contenido .= '< div class = "cleared" > < / div > ';
$contenido .= '< div class = "btn-toolbar right" > ';
$contenido .= '< a class = "ajax btn btn-primary" title = "" href = "' . $server . 'main/inc/ajax/course_home.ajax.php?a=show_course_information&code=' . $curso ['code'] . '" > ' . get_lang('Description') . '< / a > ';
if ($curso['matriculado'] != "SI") { //{% if curso.matriculado != "SI" %}
$contenido .= '< a class = "btn btn-success" title = "" href = "' . $server . 'plugin/buy_courses/process.php?code=' . $curso ['id'] . '" > ' . $buy_name . '< / a > ';
} //{% endif %}
$contenido .= '< / div > ';
$contenido .= '< / div > ';
$contenido .= '< / div > ';
$contenido .= '< / div > ';
} //{% endfor %}
echo json_encode(array("status" => "true", "contenido" => $contenido ));
foreach ($aux as $course) {
$content .= '< div class = "well_border span8" > ';
$content .= '< div class = "row" > ';
$content .= '< div class = "span" > ';
$content .= '< div class = "thumbnail" > ';
$content .= '< a class = "ajax" rel = "gb_page_center[778]" title = "" href = "' . $server . 'main/inc/ajax/course_home.ajax.php?a=show_course_information&code=' . $course ['code'] . '" > ';
$content .= '< img alt = "" src = "' . $server . $course['course_img '] . '" > ';
$content .= '< / a > ';
$content .= '< / div > ';
$content .= '< / div > ';
$content .= '< div class = "span4" > ';
$content .= '< div class = "categories-course-description" > ';
$content .= '< h3 > ' . $course ['title'] . '< / h3 > ';
$content .= '< h5 > ' . get_lang('teacher') . ': ' . $course['teache r'] . '< / h5 > ';
$content .= '< / div > ';
if ($course['enrolled'] == "YES") {
$content .= '< span class = "label label-info" > ' . $plugin->get_lang('TheUserIsAlreadyRegistered') . ' < / span > ';
}
$content .= '< / div > ';
$content .= '< div class = "span right" > ';
$content .= '< div class = "sprice right" > ' . $course ['price'] . ' € < / div > ';
$content .= '< div class = "cleared" > < / div > ';
$content .= '< div class = "btn-toolbar right" > ';
$content .= '< a class = "ajax btn btn-primary" title = "" href = "' . $server . 'main/inc/ajax/course_home.ajax.php?a=show_course_information&code=' . $course ['code'] . '" > ' . get_lang('Description') . '< / a > ';
if ($course['enrolled'] != "YES") {
$content .= '< a class = "btn btn-success" title = "" href = "' . $server . 'plugin/buy_courses/process.php?code=' . $course ['id'] . '" > ' . $buy_name . '< / a > ';
}
$content .= '< / div > ';
$content .= '< / div > ';
$content .= '< / div > ';
$content .= '< / div > ';
}
echo json_encode(array("status" => "true", "content" => $content ));
}
if ($_REQUEST['tab'] == 'guardar_moneda ') {
$id = $_REQUEST['moneda '];
if ($_REQUEST['tab'] == 'save_currency ') {
$id = $_REQUEST['currency '];
$sql = "UPDATE $tableBuyCourseCountry SET status='0';";
$res = Database::query($sql);
$sql = "UPDATE $tableBuyCourseCountry SET status='1' WHERE id_country='" . $id . "';";
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al guardar el tipo de moneda: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToSaveTheCurrencyType') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
$contenido = 'Guardado' ;
echo json_encode(array("status" => "true", "contenido" => $contenido ));
$content = get_lang('Saved') ;
echo json_encode(array("status" => "true", "content" => $content ));
}
}
if ($_REQUEST['tab'] == 'guardar _paypal') {
$username = mysql_real_ escape_string($_REQUEST['username']);
$password = mysql_real_ escape_string($_REQUEST['password']);
$signature = mysql_real_ escape_string($_REQUEST['signature']);
$sandbox = mysql_real_ escape_string($_REQUEST['sandbox']);
if ($_REQUEST['tab'] == 'save _paypal') {
$username = Database:: escape_string($_REQUEST['username']);
$password = Database:: escape_string($_REQUEST['password']);
$signature = Database:: escape_string($_REQUEST['signature']);
$sandbox = Database:: escape_string($_REQUEST['sandbox']);
$sql = "UPDATE $tableBuyCoursePaypal
SET sandbox = '" . $sandbox . "',
username = '" . $username . "',
@ -221,177 +184,126 @@ if ($_REQUEST['tab'] == 'guardar_paypal') {
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al guardar los parametros de paypal: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToSaveThePaypalParameters') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
$contenido = 'Guardado' ;
echo json_encode(array("status" => "true", "contenido" => $contenido ));
$content = get_lang('Saved') ;
echo json_encode(array("status" => "true", "content" => $content ));
}
}
if ($_REQUEST['tab'] == 'add_account') {
$name = mysql_real_ escape_string($_REQUEST['name']);
$account = mysql_real_ escape_string($_REQUEST['account']);
$swift = mysql_real_ escape_string($_REQUEST['swift']);
$name = Database:: escape_string($_REQUEST['name']);
$account = Database:: escape_string($_REQUEST['account']);
$swift = Database:: escape_string($_REQUEST['swift']);
$sql = "INSERT INTO $tableBuyCourseTransference (name, account, swift)
VALUES ('" . $name . "','" . $account . "', '" . $swift . "');";
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al insertar nueva cuenta: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToInsertANewAccount') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
$contenido = 'Guardado' ;
echo json_encode(array("status" => "true", "contenido" => $contenido ));
$content = get_lang('Saved') ;
echo json_encode(array("status" => "true", "content" => $content ));
}
}
if ($_REQUEST['tab'] == 'delete_account') {
$_REQUEST['id'] = intval($_REQUEST['id']);
$id = substr($_REQUEST['id'], 6);
$sql = "DELETE FROM $tableBuyCourseTransference WHERE id='" . $id . "';";
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al borrar la cuenta: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToDeleteTheAccount') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
$contenido = 'Guardado' ;
echo json_encode(array("status" => "true", "contenido" => $contenido ));
$content = get_lang('Saved') ;
echo json_encode(array("status" => "true", "content" => $content ));
}
}
if ($_REQUEST['tab'] == 'save_mod') {
$_REQUEST['id'] = intval($_REQUEST['id']);
$id = substr($_REQUEST['id'], 5);
$visible = ($_REQUEST['visible'] == "checked") ? ('SI') : ('NO') ;
$visible = ($_REQUEST['visible'] == "checked") ? 1 : 0 ;
$price = mysql_real_escape_string($_REQUEST['price']);
$obj = $_REQUEST['obj'];
$sql = "UPDATE $tableBuyCourse
SET visible='" . $visible . "' ,
price='" . $price . "'
WHERE id_course='" . $id . "';";
SET visible = " . $visible . " ,
price = '" . $price . "'
WHERE id_course = '" . $id . "';";
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al guardar el mensaje: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToSaveTheMessage') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
echo json_encode(array("status" => "true", "id" => $id));
}
}
if ($_REQUEST['tab'] == 'borrar _variables') {
if ($_REQUEST['tab'] == 'unset _variables') {
unset($_SESSION['bc_user_id']);
unset($_SESSION['bc_registrado ']);
unset($_SESSION['bc_curso _code']);
unset($_SESSION['bc_curso _title']);
unset($_SESSION['bc_registered ']);
unset($_SESSION['bc_course _code']);
unset($_SESSION['bc_course _title']);
unset($_SESSION["Payment_Amount"]);
unset($_SESSION["currencyCodeType"]);
unset($_SESSION["PaymentType"]);
unset($_SESSION["nvpReqArray"]);
unset($_SESSION['TOKEN']);
$_SESSION['bc_exito '] = false;
$_SESSION['bc_mensaje'] = 'Cancelacionpedido ';
$_SESSION['bc_success '] = false;
$_SESSION['bc_message'] = 'CancelOrder ';
unset($_SESSION['bc_url']);
}
if ($_REQUEST['tab'] == 'borrar_pedido') {
if ($_REQUEST['tab'] == 'clear_order') {
$_REQUEST['id'] = intval($_REQUEST['id']);
$id = substr($_REQUEST['id'], 6);
$sql = "DELETE FROM $tableBuyCourseTemporal WHERE cod='" . $id . "';";
$res = Database::query($sql);
if (!res) {
$contenido = 'Problema al borrar la cuenta: ' . Database::error();
echo json_encode(array("status" => "false", "contenido" => $contenido ));
$content = $plugin->get_lang('ProblemToDeleteTheAccount') . Database::error();
echo json_encode(array("status" => "false", "content" => $content ));
} else {
$contenido = 'Guardado' ;
echo json_encode(array("status" => "true", "contenido" => $contenido ));
$content = get_lang('Saved') ;
echo json_encode(array("status" => "true", "content" => $content ));
}
}
if ($_REQUEST['tab'] == 'confirmar_pedido') {
if ($_REQUEST['tab'] == 'confirm_order') {
$_REQUEST['id'] = intval($_REQUEST['id']);
$id = substr($_REQUEST['id'], 6);
$sql = "SELECT * FROM $tableBuyCourseTemporal WHERE cod='" . $id . "';";
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
$seguir = false;
$isAllowed = false;
$user_id = $row['user_id'];
$course_code = $row['course_code'];
$all_course_information = CourseManager::get_course_information($course_code);
if (CourseManager::subscribe_user($user_id, $course_code)) {
$seguir = true;
$isAllowed = true;
} else {
$seguir = false;
$isAllowed = false;
}
//Activamos al usuario su cuenta
if ($seguir ) {
//Activate user account
if ($isAllowed ) {
// 1. set account inactive
$sql = "UPDATE $tableUser SET active='1' WHERE user_id='" . $_SESSION['bc_user_id'] . "' ";
$sql = "UPDATE $tableUser SET active = '1' WHERE user_id = " . intval($_SESSION['bc_user_id']) . " ";
Database::query($sql);
$sql = "DELETE FROM $tableBuyCourseTemporal WHERE cod='" . $id . "';";
$res = Database::query($sql);
$contenido = 'Se ha realizado con exito la subscripcion y activacion del usuario';
echo json_encode(array("status" => "true", "contenido" => $contenido));
} else {
$contenido = 'Problema subscribir al usuario ';
echo json_encode(array("status" => "false", "contenido" => $contenido));
}
}
if ($_REQUEST['tab'] == 'cargar_tpv_configuracion') {
$cod = substr($_REQUEST['cod'], 3);
$contenido = '';
$sql = "SELECT * FROM plugin_bc_tpv WHERE cod='" . $cod . "';";
$res = Database::query($sql);
$row = Database::fetch_assoc($res);
$parametros = explode(";", $row['parametros']);
$valores = explode(";", $row['valores']);
$i = 0;
$contenido .= "< table > ";
$contenido .= "< tr > < td > < / td > < td > < strong > Configuració n TPV " . $row['title'] . ":< / strong > < / td > < / tr > ";
$contenido .= "< tr > < td style = 'text-align:right; width:30%' > URL TPV: < / td > < td > < input type = 'text' id = 'action' value = '" . $row[' action ' ] . " ' / > < / td > < / tr > ";
while ($i < count ( $ parametros ) ) {
$contenido .= "< tr > < td style = 'text-align:right; width:30%' > " . $parametros[$i] . ": < / td > < td > < input type = 'text' id = 'valor_tpv" . $i . "' value = '" . $valores[$i] . "' / > < / td > < / tr > ";
$i++;
}
$contenido .= "< tr > < td > < / td > ";
$contenido .= "< td > ";
$contenido .= "< input type = 'hidden' id = 'conf_tpv' value = '" . $cod . "' / > ";
$contenido .= "< input type = 'hidden' id = 'num_parametros' value = '" . $row[' num_parametros ' ] . " ' / > ";
$contenido .= "< input type = 'button' id = 'guardar_datos_tpv' value = 'Guardar datos' class = 'btn btn-primary' / > ";
$contenido .= "< / td > < / tr > ";
$contenido .= "< / table > ";
echo json_encode(array("contenido" => $contenido));
}
if ($_REQUEST['tab'] == 'cargar_tpv_configuracion') {
$cod = $_REQUEST['cod'];
$sql = "UDPATE plugin_bc_tpv SET status='NO'";
Database::query($sql);
$sql = "UPDATE plugin_bc_tpv SET status='SI' WHERE cod='" . $cod . "';";
Database::query($sql);
}
if ($_REQUEST['tab'] == 'save_tpv') {
$cod = $_REQUEST['cod'];
$nump = $_REQUEST['nump'];
$action = $_REQUEST['action'];
$parametros = $_REQUEST['parametros'];
$valores = implode(";", $parametros);
$sql = "UPDATE plugin_bc_tpv SET action='" . $action . "', valores='" . $valores . "' WHERE cod='" . $cod . "';";
$res = Database::query($sql);
if (!$res) {
$contenido = Database::error();
$content = $plugin->get_lang('TheSubscriptionAndActivationWereDoneSuccessfully');
echo json_encode(array("status" => "true", "content" => $content));
} else {
$contenido = "Guardado";
$content = $plugin->get_lang('ProblemToSubscribeTheUser');
echo json_encode(array("status" => "false", "content" => $content));
}
echo json_encode(array("contenido" => $contenido));
}