コード例 #1
0
require_once SLOODLE_LIBROOT . '/sloodle_session.php';
// Authenticate the request, and load a chat module
$sloodle = new SloodleSession();
$sloodle->authenticate_request();
$sloodle->load_module('chat', true);
// Attempt to validate the user
// (this will auto-register/enrol users where necessary and allowed)
// If server access level is public, then validation is not essential... otherwise, it is
$sloodleserveraccesslevel = $sloodle->request->get_server_access_level(false);
if ($sloodleserveraccesslevel == 0) {
    $sloodle->validate_user(false);
} else {
    $sloodle->validate_user(true);
}
// Has an incoming message been provided?
$message = sloodle_clean_for_db($sloodle->request->optional_param('message', null));
if ($message != null) {
    // Add it to the chatroom.
    if (!$sloodle->module->add_message($message)) {
        add_to_log($sloodle->course->get_course_id(), 'sloodle', 'add message', '', 'Added chat message to chatroom', $sloodle->request->get_module_id());
    } else {
        add_to_log($sloodle->course->get_course_id(), 'sloodle', 'add message', '', 'Failed to add chat message to chatroom', $sloodle->request->get_module_id());
    }
}
// Start preparing the response
$sloodle->response->set_status_code(1);
$sloodle->response->set_status_descriptor('OK');
// Fetch a chat history.
// Always limit it to the last 60 seconds, but optionally also ignore everything before a certain point.
$messages = $sloodle->module->get_chat_history(60, $sloodle->request->optional_param('firstmessageid', 0));
foreach ($messages as $m) {
コード例 #2
0
 /**
  * Process any form data which has been submitted.
  */
 function process_form()
 {
     global $CFG;
     // Slight hack to put this here. We need to have the permissions checked before we do this.
     // Default to view mode. Only allow other types if the user has sufficient permission
     if ($this->canedit) {
         $this->presenter_mode = optional_param('mode', 'view');
     } else {
         $this->presenter_mode = 'view';
     }
     // If we're in moving mode, then grab the entry ID
     if ($this->presenter_mode == 'moveslide') {
         $this->movingentryid = (int) optional_param('entry', 0);
     }
     // Make sure Moodle includes our JavaScript files if necessary
     if ($this->presenter_mode == 'edit' || $this->presenter_mode == 'addfiles') {
         require_js($CFG->wwwroot . '/mod/sloodle/lib/jquery/jquery.js');
         require_js($CFG->wwwroot . '/mod/sloodle/lib/jquery/jquery.uploadify.js');
         require_js($CFG->wwwroot . '/mod/sloodle/lib/jquery/jquery.checkboxes.js');
         require_js($CFG->wwwroot . '/mod/sloodle/lib/multiplefileupload/extra.js');
         require_js($CFG->wwwroot . '/lib/filelib.php');
     }
     // Should we process any incoming editing commands?
     if ($this->canedit) {
         // Has an operation been cancelled?
         if (isset($_REQUEST['sloodlecancel'])) {
             if (!headers_sent()) {
                 header("Location: " . SLOODLE_WWWROOT . "/view.php?id={$this->cm->id}&mode=edit");
             }
             exit("Redirection failed.");
         }
         // We may want to redirect afterwards to prevent an argument showing up in the address bar
         $redirect = false;
         // Are we deleting a single slide?
         if ($this->presenter_mode == 'deleteslide') {
             // Make sure the session key is specified and valid
             if (required_param('sesskey') != sesskey()) {
                 error('Invalid session key');
                 exit;
             }
             // Determine what slide is to be deleted
             $entryid = (int) required_param('entry', PARAM_INT);
             // Get the requested slide from the presentation
             $entry = $this->presenter->get_slide($entryid);
             if ($entry) {
                 // Delete the slide
                 $this->presenter->delete_entry($entryid);
                 // Set our feedback information, so the user knows it has been successful
                 $_SESSION['sloodle_presenter_feedback'] = get_string('presenter:deletedslide', 'sloodle', $entry->name);
             } else {
                 // Set our feedback information, so the user knows it has not been successful;
                 $_SESSION['sloodle_presenter_feedback'] = get_string('presenter:deletedslides', 'sloodle', 0);
             }
             // Redirect back to the edit tab to get rid of our messy request parameters (and to prevent accidental repeat of the operation)
             $redirect = true;
         }
         // Are we deleting multiple slides?
         if ($this->presenter_mode == 'deletemultiple') {
             // Make sure the session key is specified and valid
             if (required_param('sesskey') != sesskey()) {
                 error('Invalid session key');
                 exit;
             }
             // Fetch the IDs of the slides which are being deleted
             if (isset($_REQUEST['entries'])) {
                 $entryids = $_REQUEST['entries'];
             } else {
                 error("Expected HTTP parameter 'entries' not found.");
             }
             // Go through the given entry IDs and attempt to delete them
             $numdeleted = 0;
             foreach ($entryids as $entryid) {
                 if ($this->presenter->delete_entry($entryid)) {
                     $numdeleted++;
                 }
             }
             // Set our feedback information so the user knows whether or not this was successful
             $_SESSION['sloodle_presenter_feedback'] = get_string('presenter:deletedslides', 'sloodle', $numdeleted);
             // Redirect back to the edit tab to get rid of our messy request parameters (and to prevent accidental repeat of the operation)
             $redirect = true;
         }
         // Are we relocating an entry?
         if ($this->presenter_mode == 'setslideposition') {
             $entryid = (int) required_param('entry', PARAM_INT);
             $position = (int) required_param('position', PARAM_INT);
             $this->presenter->relocate_entry($entryid, $position);
             $redirect = true;
         }
         // Has a new entry been added?
         if (isset($_REQUEST['fileaddentry']) || isset($_REQUEST['sloodleaddentry'])) {
             if (isset($_REQUEST['fileaddentry'])) {
                 $urls = $_REQUEST['fileurl'];
                 $names = $_REQUEST['filename'];
                 $i = 0;
                 foreach ($urls as $u) {
                     $fnamelen = strlen($u);
                     $extension = substr($u, $fnamelen - 4);
                     $ftype = strtolower($extension);
                     switch ($ftype) {
                         case ".mov":
                             $ftype = "video";
                             break;
                         case ".mp4":
                             $ftype = "video";
                             break;
                         case ".jpg":
                             $ftype = "image";
                             break;
                         case ".png":
                             $ftype = "image";
                             break;
                         case ".gif":
                             $ftype = "image";
                             break;
                         case ".bmp":
                             $ftype = "image";
                             break;
                         case ".htm":
                             $ftype = "web";
                             break;
                         case "html":
                             $ftype = "web";
                             break;
                     }
                     $this->presenter->add_entry(sloodle_clean_for_db($u), $ftype, sloodle_clean_for_db($names[$i++]));
                 }
                 $redirect = true;
             }
             if (isset($_REQUEST['sloodleaddentry'])) {
                 if ($_REQUEST['sloodleentryurl'] != '') {
                     $sloodleentryurl = sloodle_clean_for_db($_REQUEST['sloodleentryurl']);
                     $sloodleentrytype = sloodle_clean_for_db($_REQUEST['sloodleentrytype']);
                     $sloodleentryname = sloodle_clean_for_db($_REQUEST['sloodleentryname']);
                     $sloodleentryposition = (int) $_REQUEST['sloodleentryposition'];
                     // Store the type in session data for next time we're adding a slide
                     $_SESSION['sloodle_presenter_add_type'] = $sloodleentrytype;
                     $this->presenter->add_entry($sloodleentryurl, $sloodleentrytype, $sloodleentryname, $sloodleentryposition);
                 }
             }
             $redirect = true;
         }
         // Has an existing entry been edited?
         if (isset($_REQUEST['sloodleeditentry'])) {
             $sloodleentryid = (int) $_REQUEST['sloodleentryid'];
             $sloodleentryurl = sloodle_clean_for_db($_REQUEST['sloodleentryurl']);
             $sloodleentrytype = sloodle_clean_for_db($_REQUEST['sloodleentrytype']);
             $sloodleentryname = sloodle_clean_for_db($_REQUEST['sloodleentryname']);
             $sloodleentryposition = (int) $_REQUEST['sloodleentryposition'];
             $this->presenter->edit_entry($sloodleentryid, $sloodleentryurl, $sloodleentrytype, $sloodleentryname, $sloodleentryposition);
             $redirect = true;
         }
         // Redirect back to the edit page -- this is used to get rid of intermediate parameters.
         if ($redirect && headers_sent() == false) {
             header("Location: " . SLOODLE_WWWROOT . "/view.php?id={$this->cm->id}&mode=edit");
             exit;
         }
     }
 }
コード例 #3
0
 /**
  * Sets the list of objects in this Distributor
  * @param array $objects An array of strings, each string containing the name of an object in the Distributor.
  * @return bool True if successful, or false if not
  */
 function set_objects($objects)
 {
     // Delete all existing records for this Distributor
     delete_records('sloodle_distributor_entry', 'distributorid', $this->sloodle_distributor_instance->id);
     // Go through each new entry
     $result = true;
     foreach ($objects as $o) {
         // Construct the new record
         $rec = new stdClass();
         $rec->distributorid = $this->sloodle_distributor_instance->id;
         $rec->name = sloodle_clean_for_db($o);
         // Insert it
         if (!insert_record('sloodle_distributor_entry', $rec)) {
             $result = false;
         }
     }
     return $result;
 }