distributor = sloodle_get_record('sloodle_distributor', 'sloodleid', $this->sloodle->id)) error('Failed to get SLOODLE Distributor data.'); } /** * Process any form data which has been submitted. */ function process_form() { } /** * Render the view of the Distributor. */ function render() { global $CFG, $USER; /* The version 1 method (distributor-1.0) uses a single XML-RPC channel. Presumably if you have multiple ones the most recent to update will win. Version 2 (distributor-2.0) uses the HTTP-in address that objects should already have. There may be more than one. We'll try to use the new method first, and if that fails fall back on the old one. */ $id = required_param('id', PARAM_INT); $capableobjects = SloodleActiveObject::ObjectsCapableOfTaskActiveSince( 'distributor_send_object_http_in', time()-3600, array('sloodlemoduleid'=>$id) ); // Fetch a list of all distributor entries $entries = sloodle_get_records('sloodle_distributor_entry', 'distributorid', $this->distributor->id, 'name'); // If the query failed, then assume there were simply no items available if (!is_array($entries)) $entries = array(); $numitems = count($entries); // A particular default user can be requested (by avatar name) in the HTTP parameters. // This could be used with a "send to this avatar" button on a Sloodle user profile. $defaultavatar = optional_param('defaultavatar', null, PARAM_TEXT); // // SEND OBJECT // // // If the user and object parameters are set, then try to send an object if (isset($_REQUEST['user'])) $send_user = $_REQUEST['user']; if (isset($_REQUEST['object'])) $send_object = $_REQUEST['object']; if (!empty($send_user) && !empty($send_object)) { // Convert the HTML entities back again $send_object = htmlentities(stripslashes($send_object)); $errors = array(); $ok = false; if (count($capableobjects) > 0) { foreach($capableobjects as $obj) { $v2message = new SloodleResponse(); $v2message->set_status_code(SLOODLE_CHANNEL_DISTRIBUTOR_REQUEST_GIVE_OBJECT); $v2message->set_status_descriptor('INVENTORY'); $v2message->set_request_descriptor('GIVE_INVENTORY'); $v2message->set_http_in_password($obj->httpinpassword); $v2message->set_expect_response(1); $v2message->add_data_line($send_user); $v2message->add_data_line($send_object); $v2RenderStr=""; $v2message->render_to_string($v2renderStr); //print $v2renderStr; $response = $obj->sendMessage($v2renderStr); if ($response['info']['http_code'] == 200) { // If we succeed on one, don't bother telling the user that we failed on others. if (isset($errors['messagesendingfailed'])) { unset($errors['messagesendingfailed']); } $responselines = explode("\n",$response['result']); $statusline = array_shift($responselines); if ($statusline > 0) { $ok = true; break; } else { // Other lines should be errors. // We'll ignore anything we don't understand. foreach($responselines as $line) { if (in_array($line, array('sloodleobjectnotfound', 'sloodleavatarnotfound'))) { $errors['sloodleobjectdistributor:'.$line] = true; } } } } else { $errors['messagesendingfailed'] = true; } } } if (!$ok && ( $this->distributor->channel != '' )) { // Construct and send the request $request = "1|OK\\nSENDOBJECT|$send_user|$send_object"; $ok = sloodle_send_xmlrpc_message($this->distributor->channel, 0, $request); } // What was the result? sloodle_print_box_start('generalbox boxaligncenter boxwidthnarrow centerpara'); if ($ok) { print '
';
print get_string('Object','sloodle').': '.$send_object.'
';
print get_string('uuid','sloodle').': '.$send_user.'
';
//print get_string('xmlrpc:channel','sloodle').': '.$this->distributor->channel.'
';
print '