Created
April 26, 2017 19:20
-
-
Save marcelloinfoweb/96fd0d690de104b66d1d29d4dbf1e254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../config.php'; | |
global $DB; | |
$DB->set_debug(true); | |
function desable_enrol($userid,$courseid,$dataInicio,$dataFinal) | |
{ | |
global $DB, $CFG; | |
$dataAtual = strtotime('NOW'); | |
$sql = "UPDATE mdl_user_enrolments | |
SET timestart='$dataInicio',timeend='$dataFinal', timemodified='$dataAtual' | |
WHERE userid='$userid' | |
AND enrolid | |
IN (SELECT id FROM mdl_enrol WHERE courseid=$courseid)"; | |
$result = $DB->execute($sql); | |
return $result; | |
} | |
$validData = $DB->get_recordset_sql("SELECT u.id AS userid,e.enrol,e.name AS enrolname,ue.timestart,ue.timeend,ue.timecreated,mc.shortname,e.courseid,ue.userid | |
FROM mdl_user_enrolments ue | |
INNER JOIN mdl_enrol e ON ue.enrolid=e.id | |
INNER JOIN mdl_user u ON u.id=ue.userid | |
INNER JOIN mdl_course mc ON e.courseid=mc.id | |
WHERE ue.timeend=0 AND ue.timestart=0 and ue.timecreated <= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 90 day))"); | |
foreach ($validData AS $row) | |
{ | |
$dataInicio = $row->timecreated; | |
$userid = $row->userid; | |
$courseid = $row->courseid; | |
if($dataInicio != 0) | |
{ | |
$dataFinal = strtotime('+92 day',$dataInicio); | |
desable_enrol($userid,$courseid,$dataInicio,$dataFinal); | |
} | |
} | |
$validData->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment