/** * Render the view of the Distributor. */ function render() { global $CFG, $USER; // Fetch a list of all distributor entries $entries = 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)); // 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? print_box_start('generalbox boxaligncenter boxwidthnarrow centerpara'); if ($ok) { print '<h3 style="color:green;text-align:center;">' . get_string('sloodleobjectdistributor:successful', 'sloodle') . '</h3>'; } else { print '<h3 style="color:red;text-align:center;">' . get_string('sloodleobjectdistributor:failed', 'sloodle') . '</h3>'; } print '<p style="text-align:center;">'; print get_string('Object', 'sloodle') . ': ' . $send_object . '<br/>'; print get_string('uuid', 'sloodle') . ': ' . $send_user . '<br/>'; print get_string('xmlrpc:channel', 'sloodle') . ': ' . $this->distributor->channel . '<br/>'; print '</p>'; print_box_end(); } // // ----------- // // // If there are no items in the distributor, then simply display an error message if ($numitems < 1) { print_box('<span style="font-weight:bold; color:red;">' . get_string('sloodleobjectdistributor:noobjects', 'sloodle') . '</span>', '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)) { print_box('<span style="font-weight:bold; color:red;">' . get_string('sloodleobjectdistributor:nochannel', 'sloodle') . '</span>', 'generalbox boxaligncenter boxwidthnormal centerpara'); $disabledattr = 'disabled="true"'; } // Construct the selection box of items $selection_items = '<select name="object" size="1">'; foreach ($entries as $e) { $escapedname = stripslashes($e->name); $selection_items .= "<option value=\"{$e->name}\">{$escapedname}</option>\n"; } $selection_items .= '</select>'; // Get a list of all avatars on the site $avatars = get_records('sloodle_users', '', '', 'avname'); if (!$avatars) { $avatars = array(); } // Construct the selection box of avatars $selection_avatars = '<select name="user" size="1">'; foreach ($avatars as $a) { // Skip avatars who do not have a UUID or associated Moodle account if (empty($a->uuid) || empty($a->userid)) { continue; } // Make sure the associated Moodle user can view the current course if (!has_capability('moodle/course:view', $this->course_context, $a->userid)) { continue; } // Make sure the associated Moodle user does not have a guest role if (has_capability('moodle/legacy:guest', $this->course_context, $a->userid, false)) { continue; } $sel = ''; if ($a->avname == $defaultavatar) { $sel = 'selected="true"'; } $selection_avatars .= "<option value=\"{$a->uuid}\" {$sel}>{$a->avname}</option>\n"; } $selection_avatars .= '</select>'; // 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 print_box_start('generalbox boxaligncenter boxwidthnormal centerpara'); // // SEND TO SELF // // // Start the form echo '<form action="" method="POST">'; // 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 = get_record('sloodle_users', 'userid', $USER->id); if (!$this->sloodleuser) { $table_sendtoself->data[] = array('<span style="color:red;">' . get_string('avatarnotlinked', 'sloodle') . '</span>'); } else { // Output the hidden form data echo <<<XXXEODXXX <input type="hidden" name="s" value="{$this->sloodle->id}"> <input type="hidden" name="user" value="{$this->sloodleuser->uuid}"> XXXEODXXX; // Object selection box $table_sendtoself->data[] = array(get_string('selectobject', 'sloodle') . ': ' . $selection_items); // Submit button $table_sendtoself->data[] = array('<input type="submit" ' . $disabledattr . ' value="' . get_string('sloodleobjectdistributor:sendtomyavatar', 'sloodle') . ' (' . $this->sloodleuser->avname . ')" />'); } // Print the table print_table($table_sendtoself); // End the form echo "</form>"; // Only show the other options if the user has permission to edit stuff if ($this->canedit) { // // SEND TO ANOTHER AVATAR // // // Start the form echo '<br><form action="" method="POST">'; // 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('<span style="color:red;">' . get_string('nosloodleusers', 'sloodle') . '</span>'); } else { // Output the hidden form data echo <<<XXXEODXXX <input type="hidden" name="s" value="{$this->sloodle->id}"> 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('<input type="submit" ' . $disabledattr . ' value="' . get_string('sloodleobjectdistributor:sendtoanotheravatar', 'sloodle') . '" />'); } // Print the table print_table($table); // End the form echo "</form>"; // // SEND TO A CUSTOM AVATAR // // // Start the form echo '<br><form action="" method="post">'; // 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 <input type="hidden" name="s" value="{$this->sloodle->id}"> XXXEODXXX; // UUID box $table->data[] = array(get_string('uuid', 'sloodle') . ': ' . '<input type="text" name="user" size="46" maxlength="36" />'); // Object selection box $table->data[] = array(get_string('selectobject', 'sloodle') . ': ' . $selection_items); // Submit button $table->data[] = array('<input type="submit" ' . $disabledattr . ' value="' . get_string('sloodleobjectdistributor:sendtocustomavatar', 'sloodle') . '" />'); // Print the table print_table($table); // End the form echo "</form>"; // // ---------- // // } print_box_end(); }
/** * Request that the specified object be sent to the specified avatar. * @param string $objname Name of the object to send * @param string $uuid UUID of the avatar to send the object to * @return bool True if successful, or false if not. */ function send_object($objname, $uuid) { // Check that the object exists in this distributor if (!record_exists('sloodle_distributor_entry', 'distributorid', $this->distrib_id, 'name', addslashes($objname))) { return false; } // Send the XMLRPC request return sloodle_send_xmlrpc_message($this->sloodle_distributor_instance->channel, 0, "1|OK\\nSENDOBJECT|{$uuid}|{$objname}"); }
/// /// END MOODLE-SPECIFIC /// /// echo "<div style=\"text-align:center; font-size:140%;\">\n"; echo get_string('welcometosloodle', 'sloodle') . ', ' . $pa->avname . '<br /><br />' . get_string('userlinksuccessful', 'sloodle'); echo "</div>\n"; // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done. // (Parameter name: sloodlechannel) if (is_string($sloodlechannel) && !empty($sloodlechannel)) { flush(); // XMLRPC messages going into SL strip \n, so we use \\n instead $sloodle->response->set_line_separator("\\n"); // Prepare a response as a string $str = ''; $sloodle->response->set_status_code(1); $sloodle->response->set_status_descriptor('USER_AUTH'); $sloodle->response->add_data_line('User has been successfully registered.'); $sloodle->response->render_to_string($str); // Send the message $xmlrpcresult = sloodle_send_xmlrpc_message($channel, 0, $str); if (!$xmlrpcresult) { echo '<div style="text-align:center;">'; echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.'; echo '</div>'; } } // We we asked to enrol the user as well? if ($sloodlecourseid != NULL) { echo "<br/><br/><br/>"; redirect("{$CFG->wwwroot}/course/enrol.php?id={$sloodlecourseid}", get_string('nowenrol', 'sloodle'), 3); } print_footer(); exit;