$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); require_login($course); require_capability('moodle/course:enrolconfig', $context); require_capability('enrol/jwc:config', $context); $PAGE->set_url('/enrol/jwc/addinstance.php', array('id' => $course->id)); $PAGE->set_pagelayout('admin'); navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id' => $course->id))); // Try and make the manage instances node on the navigation active $courseadmin = $PAGE->settingsnav->get('courseadmin'); if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) { $courseadmin->get('users')->get('manageinstances')->make_active(); } $enrol = enrol_get_plugin('jwc'); if (!$enrol->get_newinstance_link($course->id)) { redirect(new moodle_url('/enrol/instances.php', array('id' => $course->id))); } $mform = new enrol_jwc_addinstance_form(NULL, $course); if ($mform->is_cancelled()) { redirect(new moodle_url('/enrol/instances.php', array('id' => $course->id))); } else { if ($data = $mform->get_data()) { $enrol->add_instance($course, array('customchar1' => $data->coursenumber, 'roleid' => $data->roleid)); enrol_jwc_sync($course->id); redirect(new moodle_url('/enrol/instances.php', array('id' => $course->id))); } } $PAGE->set_heading($course->fullname); $PAGE->set_title(get_string('pluginname', 'enrol_jwc')); echo $OUTPUT->header(); $mform->display(); echo $OUTPUT->footer();
/** * Called after updating/inserting course. * * @param bool $inserted true if course just inserted * @param object $course * @param object $data form data * @return void */ public function course_updated($inserted, $course, $data) { global $CFG, $DB; if (!$inserted) { if (!empty($course->idnumber)) { $instance = $DB->get_record('enrol', array('enrol' => 'jwc', 'courseid' => $course->id, 'customchar1' => $course->idnumber), '*', IGNORE_MULTIPLE); if (!$instance) { // Always keep old instance and add new instance if idnumber changed $this->add_instance($course, array('customchar1' => $course->idnumber, 'roleid' => $this->get_config('roleid'))); } } // sync jwc enrols require_once "{$CFG->dirroot}/enrol/jwc/locallib.php"; enrol_jwc_sync($course->id); } else { if (!empty($course->idnumber)) { $this->add_instance($course, array('customchar1' => $course->idnumber, 'roleid' => $this->get_config('roleid'))); } } }
// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * CLI sync for full external database synchronisation. * * Sample cron entry: * # 5 minutes past 4am * 5 4 * * * $sudo -u www-data /usr/bin/php /var/www/moodle/enrol/database/cli/sync.php * * Notes: * - it is required to use the web server account when executing PHP CLI scripts * - you need to change the "www-data" to match the apache user account * - use "su" if "sudo" not available * * @package enrol * @subpackage database * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; if (!enrol_is_enabled('jwc')) { die('enrol_jwc plugin is disabled, sync is disabled'); } require_once "{$CFG->dirroot}/enrol/jwc/locallib.php"; enrol_jwc_sync();