/** * Save the selected setting * * @param string $data The selected site * @return string empty string or error message */ public function write_setting($data) { global $DB, $CFG; //for install cli script, $CFG->defaultuserroleid is not set so do nothing if (empty($CFG->defaultuserroleid)) { return ''; } $servicename = MOODLE_OFFICIAL_MOBILE_SERVICE; require_once $CFG->dirroot . '/webservice/lib.php'; $webservicemanager = new webservice(); if ((string) $data === $this->yes) { //code run when enable mobile web service //enable web service systeme if necessary set_config('enablewebservices', true); //enable mobile service $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE); $mobileservice->enabled = 1; $webservicemanager->update_external_service($mobileservice); //enable xml-rpc server $activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); if (!in_array('xmlrpc', $activeprotocols)) { $activeprotocols[] = 'xmlrpc'; set_config('webserviceprotocols', implode(',', $activeprotocols)); } //allow xml-rpc:use capability for authenticated user $this->set_xmlrpc_cap(true); } else { //disable web service system if no other services are enabled $otherenabledservices = $DB->get_records_select('external_services', 'enabled = :enabled AND (shortname != :shortname OR shortname IS NULL)', array('enabled' => 1, 'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE)); if (empty($otherenabledservices)) { set_config('enablewebservices', false); //also disable xml-rpc server $activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); $protocolkey = array_search('xmlrpc', $activeprotocols); if ($protocolkey !== false) { unset($activeprotocols[$protocolkey]); set_config('webserviceprotocols', implode(',', $activeprotocols)); } //disallow xml-rpc:use capability for authenticated user $this->set_xmlrpc_cap(false); } //disable the mobile service $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE); $mobileservice->enabled = 0; $webservicemanager->update_external_service($mobileservice); } return parent::write_setting($data); }
redirect($returnurl); } /// EDIT/CREATE/CANCEL operations => at the end redirect to add function page / main service page $mform = new external_service_form(null, $service); if ($mform->is_cancelled()) { redirect($returnurl); } else { if ($servicedata = $mform->get_data()) { $servicedata = (object) $servicedata; if (!empty($servicedata->requiredcapability) && $servicedata->requiredcapability == "norequiredcapability") { $servicedata->requiredcapability = ""; } //create operation if (empty($servicedata->id)) { $servicedata->id = $webservicemanager->add_external_service($servicedata); add_to_log(SITEID, 'webservice', 'add', $returnurl, get_string('addservice', 'webservice', $servicedata)); //redirect to the 'add functions to service' page $addfunctionpage = new moodle_url($CFG->wwwroot . '/' . $CFG->admin . '/webservice/service_functions.php', array('id' => $servicedata->id)); $returnurl = $addfunctionpage->out(false); } else { //update operation $webservicemanager->update_external_service($servicedata); add_to_log(SITEID, 'webservice', 'edit', $returnurl, get_string('editservice', 'webservice', $servicedata)); } redirect($returnurl); } } //OUTPUT edit/create form echo $OUTPUT->header(); $mform->display(); echo $OUTPUT->footer();