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 '

'.get_string('sloodleobjectdistributor:successful','sloodle').'

'; } else { print '

'.get_string('sloodleobjectdistributor:failed','sloodle').'

'; } 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 '

'; sloodle_print_box_end(); } // // ----------- // // // If there are no items in the distributor, then simply display an error message if ($numitems < 1) sloodle_print_box(''.get_string('sloodleobjectdistributor:noobjects','sloodle').'', 'generalbox boxaligncenter boxwidthnormal centerpara'); //error(get_string('sloodleobjectdistributor:noobjects','sloodle')); // If there is no XMLRPC channel specified, then display a warning message $disabledattr = ''; if ( empty($this->distributor->channel) && (count($capableobjects) == 0) ) { sloodle_print_box(''.get_string('sloodleobjectdistributor:nochannel','sloodle').'', 'generalbox boxaligncenter boxwidthnormal centerpara'); $disabledattr = 'disabled="true"'; } // Construct the selection box of items $selection_items = ''; // Get a list of all avatars on the site $avatars = sloodle_get_records('sloodle_users', '', '', 'avname'); if (!$avatars) $avatars = array(); // Construct the selection box of avatars $selection_avatars = ''; // There will be 3 forms: // - send to self // - send to another avatar on the course // - send to custom UUID // The first 1 will be available to any registered user whose avatar is in the database. // The other 2 will only be available to those with the activity management capability. // Furthermore, the 2nd form will only be available if there is at least 1 avatar registered on the site. // Start of the sending forms sloodle_print_box_start('generalbox boxaligncenter boxwidthnormal centerpara'); // // SEND TO SELF // // // Start the form echo '
'; // Use a table for layout $table_sendtoself = new stdClass(); $table_sendtoself->head = array(get_string('sloodleobjectdistributor:sendtomyavatar','sloodle')); $table_sendtoself->align = array('center'); // Fetch the current user's Sloodle info $this->sloodleuser = sloodle_get_record('sloodle_users', 'userid', $USER->id); if (!$this->sloodleuser) { $table_sendtoself->data[] = array(''.get_string('avatarnotlinked','sloodle').''); } else { // Output the hidden form data echo << XXXEODXXX; // Object selection box $table_sendtoself->data[] = array(get_string('selectobject','sloodle').': '.$selection_items); // Submit button $table_sendtoself->data[] = array(''); } // Print the table sloodle_print_table($table_sendtoself); // End the form echo ""; // Only show the other options if the user has permission to edit stuff if ($this->canedit) { // // SEND TO ANOTHER AVATAR // // // Start the form echo '
'; // Use a table for layout $table = new stdClass(); $table->head = array(get_string('sloodleobjectdistributor:sendtoanotheravatar','sloodle')); $table->align = array('center'); // Do we have any avatars? if (count($avatars) < 1) { $table->data[] = array(''.get_string('nosloodleusers','sloodle').''); } else { // Output the hidden form data echo << XXXEODXXX; // Avatar selection box $table->data[] = array(get_string('selectuser','sloodle').': '.$selection_avatars); // Object selection box $table->data[] = array(get_string('selectobject','sloodle').': '.$selection_items); // Submit button $table->data[] = array(''); } // Print the table sloodle_print_table($table); // End the form echo ""; // // SEND TO A CUSTOM AVATAR // // // Start the form echo '
'; // Use a table for layout $table = new stdClass(); $table->head = array(get_string('sloodleobjectdistributor:sendtocustomavatar','sloodle')); $table->align = array('center'); // Output the hidden form data echo << XXXEODXXX; // UUID box $table->data[] = array(get_string('uuid','sloodle').': '.''); // Object selection box $table->data[] = array(get_string('selectobject','sloodle').': '.$selection_items); // Submit button $table->data[] = array(''); // Print the table sloodle_print_table($table); // End the form echo ""; // // ---------- // // } sloodle_print_box_end(); } } ?>