$serviceid = optional_param('serviceid', '', PARAM_FORMAT);
+$remove = optional_param('remove', '', PARAM_FORMAT);
$pagename = 'webservicessettings';
print_error('confirmsesskeybad', '', $baseurl);
}
+if (!empty($remove)) {
+ $functionserviceid = optional_param('functionserviceid', '', PARAM_FORMAT);
+ if (!empty($functionserviceid)) {
+ $DB->delete_records('external_services_functions',array('id' => $functionserviceid));
+ }
+}
+
if (!empty($serviceid)) {
admin_externalpage_print_header();
}
//display service functions
- $servicesfunctions = $DB->get_records_sql("SELECT fs.id as id, f.component as component, fs.enabled as enabled, s.name as servicename, s.id as serviceid, f.name as functionname, f.id as functionid
+ $servicesfunctions = $DB->get_records_sql("SELECT fs.id as id, f.component as component, s.name as servicename, s.id as serviceid, f.name as functionname, f.id as functionid
FROM {external_services} s, {external_functions} f, {external_services_functions} fs
- WHERE fs.externalserviceid = s.id AND fs.externalfunctionid = f.id AND s.id = ?", array($serviceid));
+ WHERE fs.externalserviceid = s.id AND fs.functionname = f.name AND s.id = ?", array($serviceid));
//save the administrator changes
$saved = optional_param('saved', 0, PARAM_NUMBER);
$data = array();
reset($servicesfunctions);
- foreach($servicesfunctions as $function) {
- $checkbox = html_select_option::make_checkbox($function->functionid, $function->enabled, 'functionenabled');
+ foreach($servicesfunctions as $servicefunction) {
+ $checkbox = html_select_option::make_checkbox($servicefunction->functionid, $servicefunction->enabled, 'functionenabled');
$checkbox->label->add_class('accesshide');
- $data[] = array($function->functionname, $function->component, $OUTPUT->checkbox($checkbox, $function->functionname));
+ $checkbox->disabled;
+ $checkboxhtml = $OUTPUT->checkbox($checkbox, $servicefunction->functionname);
+ $data[] = array($servicefunction->functionname, $servicefunction->component, "<a href=?sesskey=".sesskey()."&serviceid=".$serviceid."&remove=1&functionserviceid=".$servicefunction->id.">".get_string("removefunctionfromservice","webservice")."</a>");
}
$table = new html_table();
- $table->head = array(get_string('functionname', 'webservice'), get_string('component', 'webservice'), get_string('enabled', 'webservice'));
+ $table->head = array(get_string('functionname', 'webservice'), get_string('component', 'webservice'), get_string('actions', 'webservice'));
$table->size = array('40%', '40%', '20%');
$table->align = array('left', 'left', 'left');
//$table->width = '30%';
//retrieve all services
// $services = $DB->get_records('external_services',null,'custom DESC');
- $servicesfunctions = $DB->get_records_sql("SELECT fs.id as id, s.id as serviceid, s.custom as custom, s.name as servicename, s.enabled as serviceenabled, f.name as functionname, fs.enabled as functionenabled
+ $servicesfunctions = $DB->get_records_sql("SELECT fs.id as id, s.id as serviceid, s.component as component, s.name as servicename, s.enabled as serviceenabled, f.name as functionname
FROM {external_services} s, {external_functions} f, {external_services_functions} fs
- WHERE fs.externalserviceid = s.id AND fs.externalfunctionid = f.id ORDER BY s.name ASC");
+ WHERE fs.externalserviceid = s.id AND fs.functionname = f.name ORDER BY s.name ASC");
//create a services array
$services = array();
class moodle_user_external extends external_api {
public static function create_users_parameters() {
-
-//TODO: the format of the description is not decided yet
-
- $userpreference = array();
- $userpreference->name = array(PARAM_ALPHANUMEXT, 'The name of the preference to set');
- $userpreference->value = array(PARAM_RAW, 'The value of the preference');
-
- $usercustomfields = new object();
- $usercustomfields->name = array(PARAM_ALPHANUMEXT, 'The name of the custom field (must exist)');
- $usercustomfields->value = array(PARAM_RAW, 'The value of the custom field');
-
- $usertocreate = new object();
- $usertocreate->username = array(PARAM_USERNAME, 'Username policy is defined in Moodle security config', REQUIRED);
- $usertocreate->password = array(PARAM_RAW, 'Moodle passwords can consist of any character', REQUIRED);
- $usertocreate->firstname = array(PARAM_NOTAGS, 'The first name(s) of the user', REQUIRED);
- $usertocreate->lastname = array(PARAM_NOTAGS, 'The family name of the user', REQUIRED);
- $usertocreate->email = array(PARAM_EMAIL, 'A valid and unique email address', REQUIRED);
- $usertocreate->auth = array(PARAM_AUTH, 'Auth plugins include manual, ldap, imap, etc');
- $usertocreate->confirmed = array(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise');
- $usertocreate->idnumber = array(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution');
- $usertocreate->emailstop = array(PARAM_NUMBER, 'Email is blocked: 1 is blocked and 0 otherwise');
- $usertocreate->lang = array(PARAM_LANG, 'Language code such as "en_utf8", must exist on server');
- $usertocreate->theme = array(PARAM_THEME, 'Theme name such as "standard", must exist on server');
- $usertocreate->timezone = array(PARAM_ALPHANUMEXT, 'Timezone code such as Australia/Perth, or 99 for default');
- $usertocreate->mailformat = array(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc');
- $usertocreate->description = array(PARAM_TEXT, 'User profile description, as HTML');
- $usertocreate->city = array(PARAM_NOTAGS, 'Home city of the user');
- $usertocreate->country = array(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ');
- $usertocreate->preferences = array('multiple' => $userpreference);
- $usertocreate->custom = array('multiple' => $usercustomfields);
-
- $createusersparams = new object();
- $createusersparams->users = array('multiple' => $usertocreate);
-
- return $createusersparams;
+ return new external_function_parameters(
+ array(
+ 'users' => new external_multiple_structure(
+ new external_single_structure(
+ array(
+ 'username' => new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config'),
+ 'password' => new external_value(PARAM_RAW, 'Moodle passwords can consist of any character'),
+ 'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
+ 'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user'),
+ 'email' => new external_value(PARAM_EMAIL, 'A valid and unique email address'),
+ 'auth' => new external_value(PARAM_AUTH, 'Auth plugins include manual, ldap, imap, etc', false),
+ 'confirmed' => new external_value(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise', false),
+ 'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', false),
+ 'emailstop' => new external_value(PARAM_NUMBER, 'Email is blocked: 1 is blocked and 0 otherwise', false),
+ 'lang' => new external_value(PARAM_LANG, 'Language code such as "en_utf8", must exist on server', false),
+ 'theme' => new external_value(PARAM_THEME, 'Theme name such as "standard", must exist on server', false),
+ 'timezone' => new external_value(PARAM_ALPHANUMEXT, 'Timezone code such as Australia/Perth, or 99 for default', false),
+ 'mailformat' => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc', false),
+ 'description' => new external_value(PARAM_TEXT, 'User profile description, as HTML', false),
+ 'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', false),
+ 'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', false),
+ 'preferences' => new external_multiple_structure(
+ new external_single_structure(
+ array(
+ 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'),
+ 'value' => new external_value(PARAM_RAW, 'The value of the preference')
+ )
+ ), 'User preferences', false),
+ 'customfields' => new external_multiple_structure(
+ new external_single_structure(
+ array(
+ 'type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'),
+ 'value' => new external_value(PARAM_RAW, 'The value of the custom field')
+ )
+ ), 'User custom fields', false)
+ )
+ )
+ )
+ )
+ );
}
/**
* Create one or more users
*
- * @param $params An array of users to create. Each user is defined by $usertocreate above.
+ * @param array $params An array of users to create. Each user is defined by $usertocreate above.
*
- * @return $return An array of userids, one for each user that was created
+ * @return array An array of userids, one for each user that was created
*/
- public static function create_users($params) {
+ public static function create_users($userlist) {
global $CFG, $DB;
-
+ //varlog('I\'m in create_users()');
// Ensure the current user is allowed to run this function
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/user:create', $context);
// 2) All required items were sent
// 3) All data passes clean_param without changes (yes this is strict)
// If any problems are found then exceptions are thrown with helpful error messages
- $params = self::validate_parameters(self::create_users_parameters(), $params);
+ $params = self::validate_parameters(self::create_users_parameters(), array('users'=>$userlist));
// Perform further checks and build up a clean array of user data
// Nothing is actually performed until the whole dataset is checked
$users = array();
- foreach ($params['users'] as $user) {
+ foreach ($userlist as $user) {
// Empty or no auth is assumed to be manual
if (empty($user['auth'])) {
if (empty($enable)) {
die;
}
- global $CFG;
- include_once "Zend/Loader.php";
- Zend_Loader::registerAutoload();
+ global $CFG, $DB;
+ //include_once "Zend/Loader/Autoloader.php";
+ //Zend_Loader_Autoloader::autoload('Zend_Loader');
+
+ include_once "Zend/Soap/Server.php";
+ include_once "Zend/Soap/AutoDiscover.php";
// retrieve the token from the url
// if the token doesn't exist, set a class containing only get_token()
$autodiscover->setClass('ws_authentication');
$autodiscover->handle();
} else {
-
- $soap = new Zend_Soap_Server($CFG->wwwroot."/webservice/soap/server.php?wsdl"); // this current file here
+ $soap = new Zend_Soap_Server($CFG->wwwroot."/webservice/soap/server.php?wsdl=true"); // this current file here
$soap->registerFaultException('moodle_exception');
} else { // if token exist, do the authentication here
/// TODO: following function will need to be modified
$user = webservice_lib::mock_check_token($token);
+ // varlog($user);
if (empty($user)) {
throw new moodle_exception('wrongidentification');
} else {
global $USER;
$USER = $user;
}
- //retrieve the api name
- if (empty($classpath)) {
- $classpath = optional_param('classpath',null,PARAM_ALPHANUM);
- }
- require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php');
+
+ //load the service functions that the user can access
+ $sql = 'SELECT f.id, f.classname, f.classpath, f.methodname FROM {external_functions} f, {external_services} s, {external_services_functions} sf, {external_services_users} su
+ WHERE s.enabled = 1 AND f.id = sf.id AND sf.externalserviceid = su.externalserviceid AND s.id = su.externalserviceid AND su.userid = ?';
+ $functions = $DB->get_records_sql($sql,array($USER->id));
+ $classlist = array(); //key is the classname, value is the class path
+ foreach($functions as $function) {
+ $classlist[$function->classname] = $function->classpath;
+ }
+ //varlog('List of services that '.$USER->username.' can access:');
+ //varlog($classlist);
+
/// run the server
if(isset($_GET['wsdl'])) {
$autodiscover = new Zend_Soap_AutoDiscover();
//this is a hack, because there is a bug in Zend framework (http://framework.zend.com/issues/browse/ZF-5736)
- $autodiscover->setUri($CFG->wwwroot."/webservice/soap/server.php/".$token."/".$classpath);
- $autodiscover->setClass($classpath."_external");
+ $autodiscover->setUri($CFG->wwwroot."/webservice/soap/server.php/".$token);
+
+ //we loading all class contaning the requested function
+ foreach ($classlist as $classname => $classpath) {
+ require_once($CFG->dirroot."/".$classpath);
+ $autodiscover->setClass($classname);
+ }
+
+ //$autodiscover->setClass($classpath."_external");
$autodiscover->handle();
} else {
- $soap = new Zend_Soap_Server($CFG->wwwroot."/webservice/soap/server.php?token=".$token."&classpath=".$classpath."&wsdl"); // this current file here
- $soap->setClass($classpath."_external");
+ $soap = new Zend_Soap_Server($CFG->wwwroot."/webservice/soap/server.php?token=".$token."&wsdl"); // this current file here
+ foreach ($classlist as $classname => $classpath) {
+ require_once($CFG->dirroot."/".$classpath);
+ $soap->setClass($classname);
+ }
$soap->registerFaultException('moodle_exception');
$soap->handle();
}
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once('lib.php');
-
+ini_set("soap.wsdl_cache_enabled", "0"); //must not cache wsdl
if (empty($CFG->enablewebservices)) {
die;
}
require_once('../../lib.php');
-
-include "Zend/Loader.php";
-Zend_Loader::registerAutoload();
+ini_set("soap.wsdl_cache_enabled", "0");
+include_once "Zend/Soap/Client.php";
$PAGE->set_course($COURSE);
$PAGE->set_url('webservice/soap/testclient/zend/zend_soap_client.php');
/// authenticate => get a conversation token from the server
/// You need a wsuser/wspassword user in the remote Moodle
-$client = new Zend_Soap_Client($CFG->wwwroot."/webservice/soap/server.php?wsdl");
+$client = new Zend_Soap_Client($CFG->wwwroot."/webservice/soap/server.php?wsdl=true");
try {
$params = new stdClass();
/// build the Zend SOAP client from the remote WSDL
-$client = new Zend_Soap_Client($CFG->wwwroot."/webservice/soap/server.php?token=".$token."&classpath=user&wsdl");
+$client = new Zend_Soap_Client($CFG->wwwroot."/webservice/soap/server.php?token=".$token."&wsdl=true");
print "<br><br><strong>You are accessing the WSDL: </strong>";
print "<br><br>".$CFG->wwwroot."/webservice/soap/server.php?token=".$token."&classpath=user&wsdl<br>";
/// Get any user with string "admin"
-print "<br><br><strong>Get users:</strong>";
-print "<pre>\n";
-try {
- $params = new stdClass();
- $params->search = "admin";
- var_dump($client->get_users($params));
-} catch (exception $exception) {
- print $exception;
- print "<br><br><strong>An exception occured: \n</strong>";
- printLastRequestResponse($client);
-}
-print "</pre>";
+//print "<br><br><strong>Get users:</strong>";
+//print "<pre>\n";
+//try {
+// $params = new stdClass();
+// $params->search = "admin";
+// var_dump($client->get_users($params));
+//} catch (exception $exception) {
+// print $exception;
+// print "<br><br><strong>An exception occured: \n</strong>";
+// printLastRequestResponse($client);
+//}
+//print "</pre>";
/// Create a user with "mockuser66" username
print "<br><br><strong>Create user:</strong>";
print "<pre>\n";
try {
-
- $user = new stdClass();
- $user->password = "password6";
- $user->email = "mockuser6@mockuser6.com";
- $user->username = "mockuser66";
- $user->firstname = "firstname6";
- $user->lastname = "lastname6";
+ $user = array();
+ $user['password'] = "password6";
+ $user['email'] = "mockuser6@mockuser6.com";
+ $user['username'] = "mockuser66";
+ $user['firstname'] = "firstname6";
+ $user['lastname'] = "lastname6";
$params = new stdClass();
$params->users = array($user);
- var_dump($client->create_users($params));
+ $userlist = array();
+ $userlist[] = $user;
+ var_dump($client->create_users($userlist));
} catch (exception $exception) {
print $exception;
print "<br><br><strong>An exception occured: \n</strong>";
- printLastRequestResponse($client);
+ //printLastRequestResponse($client);
}
print "</pre>";
-/// Update this user
-print "<br><br><strong>Update user:</strong>";
-print "<pre>\n";
-try {
- $usertoupdate = new stdClass();
- $usertoupdate->email = "mockuser6@mockuser6.com";
- $usertoupdate->username = "mockuser66";
- $usertoupdate->newusername = 'mockuser6b';
- $usertoupdate->firstname = "firstname6b";
- $params = new stdClass();
- $params->users = array($usertoupdate);
- var_dump($client->update_users($params));
-} catch (exception $exception) {
- print $exception;
- print "<br><br><strong>An exception occured: \n</strong>";
- printLastRequestResponse($client);
-}
-print "</pre>";
-
-/// Delete this user
-print "<br><br><strong>Delete user:</strong>";
-print "<pre>\n";
-try {
- $params = new stdClass();
- $params->usernames = array("mockuser6b");
- var_dump($client->delete_users($params));
-} catch (exception $exception) {
- print $exception;
- print "<br><br><strong>An exception occured: \n</strong>";
- printLastRequestResponse($client);
-}
-print "</pre>";
+///// Update this user
+//print "<br><br><strong>Update user:</strong>";
+//print "<pre>\n";
+//try {
+// $usertoupdate = new stdClass();
+// $usertoupdate->email = "mockuser6@mockuser6.com";
+// $usertoupdate->username = "mockuser66";
+// $usertoupdate->newusername = 'mockuser6b';
+// $usertoupdate->firstname = "firstname6b";
+// $params = new stdClass();
+// $params->users = array($usertoupdate);
+// var_dump($client->update_users($params));
+//} catch (exception $exception) {
+// print $exception;
+// print "<br><br><strong>An exception occured: \n</strong>";
+// printLastRequestResponse($client);
+//}
+//print "</pre>";
+//
+///// Delete this user
+//print "<br><br><strong>Delete user:</strong>";
+//print "<pre>\n";
+//try {
+// $params = new stdClass();
+// $params->usernames = array("mockuser6b");
+// var_dump($client->delete_users($params));
+//} catch (exception $exception) {
+// print $exception;
+// print "<br><br><strong>An exception occured: \n</strong>";
+// printLastRequestResponse($client);
+//}
+//print "</pre>";
/// Display Moodle page footer
echo $OUTPUT->footer();