function delete_site($id, $unregistercourses = false) { global $CFG; require_once $CFG->dirroot . '/local/hub/locallib.php'; $sitetodelete = $this->get_site($id); //unregister the courses first if (!empty($unregistercourses)) { $this->delete_courses($sitetodelete->id); } $sitetohubcommunication = $this->get_communication(WSSERVER, REGISTEREDSITE, $sitetodelete->url); if (!empty($sitetohubcommunication)) { //delete the token for this site require_once $CFG->dirroot . '/webservice/lib.php'; $webservice_manager = new webservice(); $tokentodelete = $webservice_manager->get_user_ws_token($sitetohubcommunication->token); $webservice_manager->delete_user_ws_token($tokentodelete->id); //delete the communications to this hub $this->delete_communication($sitetohubcommunication); } // Send email to the site administrator. $contactuser = local_hub_create_contact_user($sitetodelete->contactemail ? $sitetodelete->contactemail : $CFG->noreplyaddress, $sitetodelete->contactname ? $sitetodelete->contactname : get_string('noreplyname')); $emailinfo = new stdClass(); $hubinfo = $this->get_info(); $emailinfo->hubname = $hubinfo['name']; $emailinfo->huburl = $hubinfo['url']; $emailinfo->sitename = $sitetodelete->name; $emailinfo->siteurl = $sitetodelete->url; $emailinfo->unregisterpagelink = $sitetodelete->url . '/admin/registration/index.php?huburl=' . $hubinfo['url'] . '&force=1&unregistration=1'; email_to_user($contactuser, get_admin(), get_string('emailtitlesitedeleted', 'local_hub', $emailinfo), get_string('emailmessagesitedeleted', 'local_hub', $emailinfo)); $this->unregister_site($sitetodelete); }
// Otherwise throw an error (to avoid spam attack). throw new moodle_exception('freshmoodleregistrationerror2', 'local_hub', new moodle_url($url)); } } else { //create a temporary registration token to identify the previously registered site administrator //The previously registered site admin will receive an email with a link //when clicking on the link he will be able to update the registration. $freshmoodletoken = md5(uniqid(rand(), 1)); $sitevalues['secret'] = $sitevalues['token']; unset($sitevalues['password']); unset($sitevalues['token']); set_config($sitewithsameurl->id, serialize(array('newsite' => $sitevalues, 'oldsite' => $sitewithsameurl, 'freshmoodletoken' => $freshmoodletoken, 'time' => time())), 'local_hub_unregistration'); } //alert existing "secret" site administrator require_once $CFG->dirroot . '/local/hub/locallib.php'; $contactuser = local_hub_create_contact_user($sitewithsameurl->contactemail, $sitewithsameurl->contactname); $emailinfo = new stdClass(); $emailinfo->existingsite = $sitewithsameurl->name; $emailinfo->hubname = get_config('local_hub', 'name'); $freshregistrationurl = new moodle_url('/local/hub/siteregistration.php', array('freshmoodletoken' => $freshmoodletoken, 'id' => $sitewithsameurl->id)); $emailinfo->deletesiteregistration = $freshregistrationurl->out(false); $emailinfo->url = $sitewithsameurl->url; email_to_user($contactuser, get_admin(), get_string('emailtitleurlalreadyexists', 'local_hub', $emailinfo), get_string('emailmessageurlalreadyexists', 'local_hub', $emailinfo)); throw new moodle_exception('freshmoodleregistrationerror', 'local_hub', new moodle_url($url), $sitewithsameurl); } } if (get_config('local_hub', 'hubrecaptcha')) { //fill the "recaptcha" Moodle form with hub values $siteconfirmationform = new site_registration_confirmation_form('', $sitevalues); $fromform = $siteconfirmationform->get_data(); if (!empty($fromform)) {