Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/plugin/buycourses/src/function.php

86 lines
2.3 KiB

<?php
/* For license terms, see /license.txt */
/**
* Functions for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
/**
* Init
*/
12 years ago
require_once '../config.php';
$itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
$plugin = BuyCoursesPlugin::create();
$currency = $plugin->getSelectedCurrency();
if ($_REQUEST['tab'] == 'save_mod') {
if (isset($_REQUEST['course_id'])) {
$productId = $_REQUEST['course_id'];
$productType = BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
} else {
$productId = $_REQUEST['session_id'];
$productType = BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
}
$affectedRows = false;
if ($_POST['visible'] == 1) {
$item = Database::select(
'COUNT(1) AS qty',
$itemTable,
[
'where' => [
'product_id = ? AND ' => intval($productId),
'product_type = ?' => $productType
]
],
'first'
);
if ($item['qty'] > 0) {
$affectedRows = Database::update(
$itemTable,
['price' => floatval($_POST['price'])],
[
'product_id = ? AND ' => intval($productId),
'product_type' => $productType
]
);
} else {
$affectedRows = Database::insert(
$itemTable,
[
'currency_id' => $currency['id'],
'product_type' => $productType,
'product_id' => intval($productId),
'price' => floatval($_POST['price'])
]
);
}
} else {
$affectedRows = Database::delete(
$itemTable,
[
'product_id = ? AND ' => intval($productId),
'product_type = ?' => $productType
]
);
}
if ($affectedRows > 0) {
$jsonResult = [
"status" => true,
"itemId" => $productId
];
} else {
$jsonResult = [
"status" => false,
"content" => $plugin->get_lang('ItemNotSaved')
];
}
echo json_encode($jsonResult);
exit;
}