commit
653a5ff3f7
|
After Width: | Height: | Size: 988 B |
@ -0,0 +1,42 @@ |
||||
$(document).ready(function() { |
||||
var objects = $(document).find('object'); |
||||
var pathname = location.pathname; |
||||
var coursePath = pathname.substr(0, pathname.indexOf('/courses/')); |
||||
var url = "http://"+location.host + coursePath+"/courses/proxy.php?"; |
||||
|
||||
objects.each(function (value, obj) { |
||||
var dialogId = this.id +'_dialog'; |
||||
var openerId = this.id +'_opener'; |
||||
var link = '<a id="'+openerId+'" href="#">If video does not work, try clicking here.</a>'; |
||||
var embed = $("#"+this.id).find('embed').first(); |
||||
|
||||
var height = embed.attr('height'); |
||||
var width = embed.attr('width'); |
||||
var src = embed.attr('src').replace('https', 'http'); |
||||
|
||||
var completeUrl = url + 'width='+embed.attr('width')+ |
||||
'&height='+height+ |
||||
'&id='+this.id+ |
||||
'&flashvars='+encodeURIComponent(embed.attr('flashvars'))+ |
||||
'&src='+src+ |
||||
'&width='+width; |
||||
|
||||
/*var iframe = '<iframe ' + |
||||
'style="border: 0px;" width="100%" height="100%" ' + |
||||
'src="'+completeUrl+ |
||||
'">' + |
||||
'</iframe>'; |
||||
|
||||
var content = '<div id="'+dialogId+'">' + iframe+'</div>';*/ |
||||
var result = $("#"+this.id).find('#'+openerId); |
||||
|
||||
if (result.length == 0) { |
||||
$("#" + this.id).append('<br />' + link); |
||||
|
||||
$('#' + openerId).click(function () { |
||||
var window = window.open(completeUrl, "Video", "width=" + width + ", " + "height=" + height + ""); |
||||
window.document.title = 'Video'; |
||||
}); |
||||
} |
||||
}); |
||||
}); |
||||
@ -1,36 +0,0 @@ |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* JS library for the Chamilo buy-courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
$(document).ready(function () { |
||||
$(".bc-button-save").click(function () { |
||||
var currentRow = $(this).closest("tr"); |
||||
var courseOrSessionObject = { |
||||
tab: "save_mod", |
||||
visible: currentRow.find("[name='visible']").is(':checked') ? 1 : 0, |
||||
price: currentRow.find("[name='price']").val() |
||||
}; |
||||
|
||||
var itemField = currentRow.data('type') + '_id'; |
||||
|
||||
courseOrSessionObject[itemField] = currentRow.data('item') || 0; |
||||
|
||||
$.post( |
||||
"function.php", |
||||
courseOrSessionObject, |
||||
function (data) { |
||||
if (!data.status) { |
||||
return; |
||||
} |
||||
|
||||
currentRow.addClass('success'); |
||||
|
||||
window.setTimeout(function () { |
||||
currentRow.removeClass('success'); |
||||
}, 3000); |
||||
}, |
||||
"json" |
||||
); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,220 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
/** |
||||
* Configuration script for the Buy Courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
/** |
||||
* Initialization |
||||
*/ |
||||
$cidReset = true; |
||||
|
||||
require_once '../config.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
if (!isset($_REQUEST['t'], $_REQUEST['i'])) { |
||||
die; |
||||
} |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true'; |
||||
|
||||
$editingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE; |
||||
$editingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION; |
||||
|
||||
$entityManager = Database::getManager(); |
||||
$userRepo = $entityManager->getRepository('ChamiloUserBundle:User'); |
||||
|
||||
$currency = $plugin->getSelectedCurrency(); |
||||
$currencyIso = null; |
||||
|
||||
if ($editingCourse) { |
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $_REQUEST['i']); |
||||
|
||||
if (!$course) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
if (!$plugin->isValidCourse($course)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$courseItem = $plugin->getCourseForConfiguration($course, $currency); |
||||
$defaultBeneficiaries = []; |
||||
$teachers = $course->getTeachers(); |
||||
$teachersOptions = []; |
||||
|
||||
foreach ($teachers as $courseTeacher) { |
||||
$teacher = $courseTeacher->getUser(); |
||||
|
||||
$teachersOptions[] = [ |
||||
'text' => $teacher->getCompleteName(), |
||||
'value' => $teacher->getId() |
||||
]; |
||||
|
||||
$defaultBeneficiaries[] = $teacher->getId(); |
||||
} |
||||
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); |
||||
|
||||
if (!empty($currentBeneficiaries)) { |
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
||||
} |
||||
|
||||
$currencyIso = $courseItem['currency']; |
||||
$formDefaults = [ |
||||
'product_type' => get_lang('Course'), |
||||
'i' => $courseItem['course_id'], |
||||
't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, |
||||
'name' => $courseItem['course_title'], |
||||
'visible' => $courseItem['visible'], |
||||
'price' => $courseItem['price'], |
||||
'beneficiaries' => $defaultBeneficiaries |
||||
]; |
||||
} elseif ($editingSession) { |
||||
if (!$includeSession) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $_REQUEST['i']); |
||||
|
||||
if (!$session) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sessionItem = $plugin->getSessionForConfiguration($session, $currency); |
||||
$generalCoach = $session->getGeneralCoach(); |
||||
$generalCoachOption = [ |
||||
'text' => $generalCoach->getCompleteName(), |
||||
'value' => $generalCoach->getId() |
||||
]; |
||||
$defaultBeneficiaries = [ |
||||
$generalCoach->getId() |
||||
]; |
||||
$courseCoachesOptions = []; |
||||
$sessionCourses = $session->getCourses(); |
||||
|
||||
foreach ($sessionCourses as $sessionCourse) { |
||||
$courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse->getCourse()); |
||||
|
||||
foreach ($courseCoaches as $courseCoach) { |
||||
if ($generalCoach->getId() === $courseCoach->getId()) { |
||||
continue; |
||||
} |
||||
|
||||
$courseCoachesOptions[] = [ |
||||
'text' => $courseCoach->getCompleteName(), |
||||
'value' => $courseCoach->getId() |
||||
]; |
||||
$defaultBeneficiaries[] = $courseCoach->getId(); |
||||
} |
||||
} |
||||
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); |
||||
|
||||
if (!empty($currentBeneficiaries)) { |
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
||||
} |
||||
|
||||
$currencyIso = $sessionItem['currency']; |
||||
$formDefaults = [ |
||||
'product_type' => get_lang('Session'), |
||||
'i' => $session->getId(), |
||||
't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, |
||||
'name' => $sessionItem['session_name'], |
||||
'visible' => $sessionItem['visible'], |
||||
'price' => $sessionItem['price'], |
||||
'beneficiaries' => $defaultBeneficiaries |
||||
]; |
||||
} else { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$form = new FormValidator('beneficiaries'); |
||||
$form->addText('product_type', $plugin->get_lang('ProductType'), false); |
||||
$form->addText('name', get_lang('Name'), false); |
||||
$visibleCheckbox = $form->addCheckBox( |
||||
'visible', |
||||
$plugin->get_lang('VisibleInCatalog'), |
||||
$plugin->get_lang('ShowOnCourseCatalog') |
||||
); |
||||
$form->addElement( |
||||
'number', |
||||
'price', |
||||
[$plugin->get_lang('Price'), null, $currencyIso], |
||||
['step' => 0.01] |
||||
); |
||||
$beneficiariesSelect = $form->addSelect( |
||||
'beneficiaries', |
||||
$plugin->get_lang('Beneficiaries'), |
||||
null, |
||||
['multiple' => 'multiple'] |
||||
); |
||||
|
||||
if ($editingCourse) { |
||||
$beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers')); |
||||
} elseif ($editingSession) { |
||||
$beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach')); |
||||
$beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach')); |
||||
} |
||||
|
||||
$form->addHidden('t', null); |
||||
$form->addHidden('i', null); |
||||
$form->addButtonSave(get_lang('Save')); |
||||
$form->freeze(['product_type', 'name']); |
||||
|
||||
if ($form->validate()) { |
||||
$formValues = $form->exportValues(); |
||||
$productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']); |
||||
|
||||
if (isset($formValues['visible'])) { |
||||
if (!empty($productItem)) { |
||||
$plugin->updateItem( |
||||
['price' => floatval($formValues['price'])], |
||||
$formValues['i'], |
||||
$formValues['t'] |
||||
); |
||||
} else { |
||||
$itemId = $plugin->registerItem([ |
||||
'currency_id' => $currency['id'], |
||||
'product_type' => $formValues['t'], |
||||
'product_id' => intval($formValues['i']), |
||||
'price' => floatval($_POST['price']) |
||||
]); |
||||
$productItem['id'] = $itemId; |
||||
} |
||||
|
||||
$plugin->deleteItemBeneficiaries($productItem['id']); |
||||
|
||||
if (isset($formValues['beneficiaries'])) { |
||||
$plugin->registerItemBeneficiaries($productItem['id'], $formValues['beneficiaries']); |
||||
} |
||||
} else { |
||||
$plugin->deleteItem($productItem['id']); |
||||
} |
||||
|
||||
header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/configuration.php'); |
||||
exit; |
||||
} |
||||
|
||||
$form->setDefaults($formDefaults); |
||||
|
||||
//View |
||||
$templateName = $plugin->get_lang('AvailableCourse'); |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => 'paymentsetup.php', |
||||
'name' => get_lang('Configuration') |
||||
]; |
||||
$interbreadcrumb[] = [ |
||||
'url' => 'configuration.php', |
||||
'name' => $plugin->get_lang('AvailableCourses') |
||||
]; |
||||
|
||||
$template = new Template($templateName); |
||||
$template->assign('header', $templateName); |
||||
$template->assign('content', $form->returnForm()); |
||||
$template->display_one_col_template(); |
||||
@ -1,85 +0,0 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
/** |
||||
* Functions for the Buy Courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
/** |
||||
* Init |
||||
*/ |
||||
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; |
||||
} |
||||
@ -1,80 +1,75 @@ |
||||
<link rel="stylesheet" type="text/css" href="resources/css/style.css"/> |
||||
{% if _u.is_admin %} |
||||
<div class="row"> |
||||
<div class="col-md-12"> |
||||
<article class="jumbotron"> |
||||
<h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3> |
||||
<p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p> |
||||
<ul class="list-unstyled"> |
||||
<li> |
||||
{{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} |
||||
<ul> |
||||
<li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
</ul> |
||||
</li> |
||||
</ul> |
||||
</article> |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
|
||||
<div class="row"> |
||||
<div class="col-md-12"> |
||||
{% if _u.is_admin %} |
||||
<div class="help-bycourse"> |
||||
<div class="row"> |
||||
<div class="col-md-7"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
<h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3> |
||||
<p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p> |
||||
<p> </p> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-5"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-heading"> |
||||
{{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} |
||||
</div> |
||||
<div class="panel-body"> |
||||
<ul> |
||||
<li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/course_catalog.php"> |
||||
<img src="resources/img/128/buycourses.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="row"> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/course_catalog.php"> |
||||
<img src="resources/img/128/buycourses.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</div> |
||||
{% if _u.is_admin %} |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/configuration.php"> |
||||
<img src="resources/img/128/settings.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
</div> |
||||
|
||||
{% if _u.is_admin %} |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/configuration.php"> |
||||
<img src="resources/img/128/settings.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/paymentsetup.php"> |
||||
<img src="resources/img/128/paymentsettings.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }} </a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/paymentsetup.php"> |
||||
<img src="resources/img/128/paymentsettings.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/sales_report.php"> |
||||
<img src="resources/img/128/backlogs.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }} </a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/sales_report.php"> |
||||
<img src="resources/img/128/backlogs.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
|
||||
@ -0,0 +1,139 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* This script removes previous tasks from disk to clear space. |
||||
* Configure the date on lines 22-23 to change the dates after/before which |
||||
* to delete. |
||||
* This works based on sessions dates (it will not delete tasks from |
||||
* base courses). |
||||
* This script should be located inside the tests/scripts/ folder to work |
||||
* @author Paul Patrocinio <ppatrocino@icpna.edu.pe> |
||||
* @author Percy Santiago <psantiago@icpna.edu.pe> |
||||
* @author Yannick Warnier <yannick.warnier@beeznest.com> |
||||
*/ |
||||
exit(); //remove this line to execute from the command line |
||||
if (PHP_SAPI !== 'cli') { |
||||
die('This script can only be executed from the command line'); |
||||
} |
||||
|
||||
require __DIR__.'/../../main/inc/conf/configuration.php'; |
||||
|
||||
// Dates |
||||
$expiryDate = '2015-06-01'; //session start date must be < to be considered |
||||
$fromDate = '2011-01-01'; //session start date must be > to be considered |
||||
|
||||
$sessionCourses = array(); |
||||
$coursesCodes = array(); |
||||
$coursesDirs = array(); |
||||
if (!$conexion = mysql_connect($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password'])) { |
||||
echo 'Could not connect to database'; |
||||
exit; |
||||
} |
||||
|
||||
if (!mysql_select_db($_configuration['main_database'], $conexion)) { |
||||
echo 'Could not select database '.$_configuration['main_database']; |
||||
exit; |
||||
} |
||||
echo "[".time()."] Querying sessions\n"; |
||||
$sql = "SELECT id FROM session where access_start_date < '$expiryDate' AND access_start_date > '$fromDate'"; |
||||
|
||||
$res = mysql_query($sql, $conexion); |
||||
if ($res === false) { |
||||
//die("Error querying sessions: ".Database::error($res)."\n"); |
||||
} |
||||
|
||||
$countSessions = mysql_num_rows($res); |
||||
$sql = "SELECT count(*) FROM session"; |
||||
$resc = mysql_query($sql, $conexion); |
||||
if ($resc === false) { |
||||
//die("Error querying sessions: ".Database::error($res)."\n"); |
||||
} |
||||
$countAllSessions = mysql_result($resc, 0, 0); |
||||
echo "[".time()."] Found $countSessions sessions between $fromDate and $expiryDate on a total of $countAllSessions sessions."."\n"; |
||||
|
||||
while ($session = mysql_fetch_assoc($res)) { |
||||
$sql2 = "SELECT c.id AS cid, c.code as ccode, c.directory as cdir |
||||
FROM course c, session_rel_course s |
||||
WHERE s.id_session = ".$session['id']." |
||||
AND s.course_code = c.code"; |
||||
$res2 = mysql_query($sql2, $conexion); //Database::query($sql2); |
||||
|
||||
if ($res2 === false) { |
||||
die("Error querying courses for session ".$session['id'].": ".mysql_error($res2)."\n"); |
||||
} |
||||
|
||||
if (mysql_num_rows($res2) > 0) { |
||||
while ($course = mysql_fetch_assoc($res2)) { |
||||
$sessionCourses[$session['id']] = $course['cid']; |
||||
//$_SESSION['session_course'] = $sessionCourses; |
||||
|
||||
if (empty($coursesCodes[$course['cid']])) { |
||||
$coursesCodes[$course['cid']] = $course['ccode']; |
||||
} |
||||
if (empty($coursesDirs[$course['cid']])) { |
||||
$coursesDirs[$course['cid']] = $course['cdir']; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
echo "[".time()."] Filled courses arrays. Now checking tasks...\n"; |
||||
/** |
||||
* Locate and destroy the expired tasks |
||||
*/ |
||||
//$sessionCourse = $_SESSION['session_course']; |
||||
|
||||
$totalSize = 0; |
||||
foreach ($sessionCourses as $sid => $cid) { |
||||
// Check if a folder already exists in this session |
||||
// Folders are exclusive to sessions. If a folder already exists in |
||||
// another session, you will not be allowed to create the same folder in |
||||
// another session. As such, folders belong to one and only one session. |
||||
$sql = "SELECT id, url FROM c_student_publication |
||||
WHERE filetype = 'folder' |
||||
AND c_id = $cid |
||||
AND session_id = $sid |
||||
AND active = 1 |
||||
AND url LIKE '%ALP%'"; |
||||
|
||||
$resCarpetas = mysql_query($sql, $conexion); //Database::query($sql); |
||||
|
||||
if (mysql_num_rows($resCarpetas) > 0) { |
||||
while ($rowDemo = mysql_fetch_assoc($resCarpetas)) { |
||||
|
||||
$carpetaAlpElimina = $_configuration['root_sys'].'courses/'.$coursesDirs[$cid].'/work'.$rowDemo['url']; |
||||
|
||||
//echo "rm -rf ".$carpetaAlpElimina."\n"; |
||||
$size = folderSize($carpetaAlpElimina); |
||||
$totalSize += $size; |
||||
echo "Freeing $size of a total $totalSize bytes in $carpetaAlpElimina\n"; |
||||
exec('rm -rf '.$carpetaAlpElimina); |
||||
} |
||||
|
||||
$sqldel = "DELETE FROM c_student_publication |
||||
WHERE |
||||
c_id = $cid |
||||
AND session_id = $sid AND active = 1;"; |
||||
$resdel = mysql_query($sqldel); |
||||
if ($resdel === false) { |
||||
echo "Error querying sessions: ".Database::error($resdel)."\n"; |
||||
} |
||||
} |
||||
} |
||||
echo "[".time()."] Deleted tasks from $countSessions sessions between $fromDate and $expiryDate on a total of $countAllSessions sessions."."\n"; |
||||
|
||||
/** |
||||
* Helper function to calculate size of a folder |
||||
* @author See php.net comments on filesize() |
||||
*/ |
||||
function folderSize($dir) { |
||||
$size = 0; |
||||
$contents = glob(rtrim($dir, '/').'/*', GLOB_NOSORT); |
||||
foreach ($contents as $contents_value) { |
||||
if (is_file($contents_value)) { |
||||
$size += filesize($contents_value); |
||||
} else { |
||||
$size += folderSize($contents_value); |
||||
} |
||||
} |
||||
return $size; |
||||
} |
||||
Loading…
Reference in new issue