$hide = optional_param('hide', '', PARAM_ALPHANUM);
$username = optional_param('username', '', PARAM_ALPHANUM);
+$settings = optional_param('settings', '', PARAM_ALPHANUM);
$pagename = 'managews';
$mform->display();
print_simple_box_end();
+} else if (!empty($settings)) {
+/// Server settings page
+ admin_externalpage_print_header();
+
+ $mform = new wssettings_form('', array('settings' => $settings)); // load the server settings form
+
+ if ($mform->is_cancelled()){
+ /// user pressed cancel button and return to the security web service page
+ redirect($baseurl);
+ exit;
+ }
+
+ $fromform = $mform->get_data();
+
+ if (!empty($fromform)) {
+ /// save the new setting
+ require_once($CFG->dirroot . '/webservice/'. $settings . '/lib.php');
+ $settingnames = call_user_func(array($settings.'_server', 'get_setting_names'));
+ foreach($settingnames as $settingname) {
+ if (empty($fromform->$settingname)) {
+ set_config($settingname, null, $settings);
+ } else {
+ set_config($settingname, $fromform->$settingname, $settings);
+ }
+ }
+
+ redirect($baseurl,get_string("changessaved")); // return to the security web service page
+ }
+/// display the server settings form
+ print_simple_box_start();
+ $mform->display();
+ print_simple_box_end();
+} else {
+ $return = true;
}
if (!empty($return)) {
$string['fail'] = 'FAIL';
$string['wsuserreminder'] = 'Reminder: the Moodle administrator of this site needs to give you moodle/site:usewebservices capability.';
$string['debugdisplayon'] = '\"Display debug messages\" is set On. The XMLRPC server will not work. The other web service servers could also return some problems. <br/>Alert the Moodle administrator to set it Off.';
+$string['amfdebug'] = 'AMF server debug mode';
+
?>
require_once("../webservice/lib.php");
$protocols = webservice_lib::get_list_protocols();
$table = new StdClass;
- $table->head = array($namestr, $hiddenstr);
- $table->align = array('left', 'center');
+ $table->head = array($namestr, $hiddenstr, $settingsstr);
+ $table->align = array('left', 'center', 'center');
$table->data = array();
foreach ($protocols as $i) {
- $hidetitle = $i->get_protocolname() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository');
- $hiddenshow = ' <a href="' . $this->baseurl . '&hide=' . $i->get_protocolname() . '">'
+ $hidetitle = $i->get_protocolid() ? get_string('clicktohide', 'repository') : get_string('clicktoshow', 'repository');
+ $hiddenshow = ' <a href="' . $this->baseurl . '&hide=' . $i->get_protocolid() . '">'
.'<img src="' . $CFG->pixpath . '/i/' . ($i->get_enable() ? 'hide' : 'show') . '.gif"'
.' alt="' . $hidetitle . '" '
.' title="' . $hidetitle . '" />'
.'</a>' . "\n";
- $table->data[] = array($i->get_protocolname(), $hiddenshow);
+ $settingnames = $i->get_setting_names();
+ if (!empty($settingnames)) {
+ $settingsshow = ' <a href="' . $this->baseurl . '&settings=' . $i->get_protocolid() . '">'
+ .$settingsstr
+ .'</a>' . "\n";
+ } else {
+ $settingsshow = "";
+ }
+ $table->data[] = array($i->get_protocolname(), $hiddenshow, $settingsshow);
//display a grey row if the type is defined as not visible
if (!$i->get_enable()){
public function __construct() {
//set web service proctol name
$this->set_protocolname("Amf");
+ $this->set_protocolid("amf");
}
/**
/// run the Zend AMF server
$server = new Zend_Amf_Server();
+ $debugmode = get_config($this->get_protocolid(),'debug');
+ if (!empty($debugmode)) {
+ $server->setProduction(false);
+ } else {
+ $server->setProduction(true);
+ }
$server->setClass($classpath."_external");
$response = $server->handle();
echo $response;
}
-}
+ /**
+ * Names of the server settings
+ * @return array
+ */
+ public static function get_setting_names() {
+ return array('debug');
+ }
+ public function settings_form(&$mform) {
+ $debug = get_config($this->get_protocolid(), 'debug');
+ $debug = true;
+ if (empty($debug)) {
+ $debug = false;
+ }
+ $mform->addElement('checkbox', 'debug', get_string('amfdebug', 'webservice'));
+ }
+}
?>
}
}
-// echo "<pre>";
-// var_dump($description);
-// echo "</pre>";
+ // echo "<pre>";
+ // var_dump($description);
+ // echo "</pre>";
return $description;
}
echo "<br/>";
foreach(webservice_lib::get_list_protocols() as $wsprotocol) {
- if (strtolower($wsprotocol->get_protocolname()) == strtolower($protocol)) {
- echo get_string('protocolenable','webservice',array($wsprotocol->get_protocolname())).": ";
- if ( get_config($wsprotocol-> get_protocolname(), "enable")) {
+ if (strtolower($wsprotocol->get_protocolid()) == strtolower($protocol)) {
+ echo get_string('protocolenable','webservice',array($wsprotocol->get_protocolid())).": ";
+ if ( get_config($wsprotocol-> get_protocolid(), "enable")) {
echo "<strong style=\"color:green\">".get_string('ok','webservice')."</strong>";
} else {
echo "<strong style=\"color:red\">".get_string('fail','webservice')."</strong>";
*/
private $protocolname;
+ /**
+ * Web Service Protocol id (eg. soap, rest, xmlrpc...)
+ * @var String
+ */
+ private $protocolid;
+
public function __construct() {
}
return $this->protocolname;
}
+ public function get_protocolid() {
+ return $this->protocolid;
+ }
+
public function set_protocolname($protocolname) {
$this->protocolname = $protocolname;
}
+ public function set_protocolid($protocolid) {
+ $this->protocolid = $protocolid;
+ }
+
public function get_enable() {
- return get_config($this->get_protocolname(), "enable");
+ return get_config($this->get_protocolid(), "enable");
}
public function set_enable($enable) {
- set_config("enable", $enable, $this->get_protocolname());
+ set_config("enable", $enable, $this->get_protocolid());
+ }
+
+ /**
+ * Names of the server settings
+ * @return array
+ */
+ public static function get_setting_names() {
+ return array();
+ }
+
+ public function settings_form(&$mform) {
}
}
$this->username = $this->_customdata['username'];
$mform =& $this->_form;
- $strrequired = get_string('required');
-
$mform->addElement('hidden', 'username', $this->username);
$param = new stdClass();
$param->username = $this->username;
}
}
+/**
+ * Form for web service server settings (administration)
+ */
+final class wssettings_form extends moodleform {
+ protected $settings;
+
+ /**
+ * Definition of the moodleform
+ */
+ public function definition() {
+ global $DB,$CFG;
+ $settings = $this->_customdata['settings'];
+ $mform =& $this->_form;
+
+ $mform->addElement('hidden', 'settings', $settings);
+ $param = new stdClass();
+
+ require_once($CFG->dirroot . '/webservice/'. $settings . '/lib.php');
+ $servername = $settings.'_server';
+ $server = new $servername();
+ $server->settings_form($mform);
+
+ // set the data if we have some.
+ $data = array();
+ $option_names = $server->get_setting_names();
+ foreach ($option_names as $config) {
+ $data[$config] = get_config($settings, $config);
+ }
+ $this->set_data($data);
+
+
+ $this->add_action_buttons(true, get_string('savechanges','admin'));
+ }
+}
+
?>
public function __construct() {
$this->set_protocolname("Rest");
+ $this->set_protocolid("rest");
}
/**
public function __construct() {
$this->set_protocolname("Soap");
+ $this->set_protocolid("soap");
}
public function __construct() {
- $this->set_protocolname("XMLRPC");
+ $this->set_protocolname("XML-RPC");
+ $this->set_protocolid("xmlrpc");
}
public function run() {