|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 00028 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); 00029 require_once($CFG->libdir.'/adminlib.php'); 00030 require_once($CFG->dirroot . '/admin/mnet/services_form.php'); 00031 $mnet = get_mnet_environment(); 00032 00033 require_login(); 00034 admin_externalpage_setup('mnetpeers'); 00035 00036 $context = get_context_instance(CONTEXT_SYSTEM); 00037 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions"); 00038 00039 $hostid = required_param('hostid', PARAM_INT); 00040 00041 $mnet_peer = new mnet_peer(); 00042 $mnet_peer->set_id($hostid); 00043 00044 $mform = new mnet_services_form(null, array('peer' => $mnet_peer)); 00045 if ($formdata = $mform->get_data()) { 00046 if (!isset($formdata->publish)) { 00047 $formdata->publish = array(); 00048 } 00049 if (!isset($formdata->subscribe)) { 00050 $formdata->subscribe = array(); 00051 } 00052 foreach($formdata->exists as $key => $value) { 00053 $host2service = $DB->get_record('mnet_host2service', array('hostid'=>$hostid, 'serviceid'=>$key)); 00054 $publish = (array_key_exists($key, $formdata->publish)) ? $formdata->publish[$key] : 0; 00055 $subscribe = (array_key_exists($key, $formdata->subscribe)) ? $formdata->subscribe[$key] : 0; 00056 00057 if ($publish != 1 && $subscribe != 1) { 00058 if (false == $host2service) { 00059 // We don't have or need a record - do nothing! 00060 } else { 00061 // We don't need the record - delete it 00062 $DB->delete_records('mnet_host2service', array('hostid' => $hostid, 'serviceid'=>$key)); 00063 } 00064 } elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) { 00065 $host2service = new stdClass(); 00066 $host2service->hostid = $hostid; 00067 $host2service->serviceid = $key; 00068 00069 $host2service->publish = $publish; 00070 $host2service->subscribe = $subscribe; 00071 00072 $host2service->id = $DB->insert_record('mnet_host2service', $host2service); 00073 } elseif ($host2service->publish != $publish || $host2service->subscribe != $subscribe) { 00074 $host2service->publish = $publish; 00075 $host2service->subscribe = $subscribe; 00076 $DB->update_record('mnet_host2service', $host2service); 00077 } 00078 } 00079 $redirecturl = new moodle_url('/admin/mnet/services.php?hostid=' . $hostid); 00080 redirect($redirecturl, get_string('changessaved')); 00081 } 00082 00083 echo $OUTPUT->header(); 00084 $currenttab = 'mnetservices'; 00085 require_once($CFG->dirroot . '/admin/mnet/tabs.php'); 00086 echo $OUTPUT->box_start(); 00087 $s = mnet_get_service_info($mnet_peer, false); // basic data only 00088 $mform->set_data($s); 00089 $mform->display(); 00090 echo $OUTPUT->box_end(); 00091 00092 echo $OUTPUT->footer();