/**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: sloodle instance
     if (!($this->sloodle_instance = get_record('sloodle', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load Sloodle module with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     // Load from the secondary table: sloodle_presenter
     if (!($this->presenter = get_record('sloodle_presenter', 'sloodleid', $this->cm->instance))) {
         sloodle_debug("Failed to load secondary module table with instance ID #{$this->cm->instance}.<br/>");
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) {
         sloodle_debug("Failed to load controler course module.<br>");
         return false;
     }
     // Load from the primary table: Sloodle instance
     if (!($this->sloodle_module_instance = get_record('sloodle', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load controller Sloodle module instance.<br>");
         return false;
     }
     // Check that it is the correct type
     if ($this->sloodle_module_instance->type != SLOODLE_TYPE_CTRL) {
         sloodle_debug("Loaded Sloodle module instance is not a controller.<br>");
         return false;
     }
     // Load from the secondary table: Controller instance
     if (!($this->sloodle_controller_instance = get_record('sloodle_controller', 'sloodleid', $this->cm->instance))) {
         sloodle_debug("Failed to load controller secondary data table.<br>");
         return false;
     }
     return true;
 }
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible chatrooms on the course
    // Get the ID of the chat type
    $rec = get_record('modules', 'name', 'chat');
    if (!$rec) {
        sloodle_debug("Failed to get chatroom module type.");
        exit;
    }
    $chatmoduleid = $rec->id;
    // Get all visible chatrooms in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$chatmoduleid} AND visible = 1");
    if (!$recs) {
        error(get_string('nochatrooms', 'sloodle'));
        exit;
    }
    $chatrooms = array();
    foreach ($recs as $cm) {
        // Fetch the chatroom instance
        $inst = get_record('chat', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Store the chatroom details
        $chatrooms[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($chatrooms);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlelistentoobjects = (int) sloodle_get_value($settings, 'sloodlelistentoobjects', 0);
    $sloodleautodeactivate = (int) sloodle_get_value($settings, 'sloodleautodeactivate', 1);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a chatroom
    echo get_string('selectchatroom', 'sloodle') . ': ';
    choose_from_menu($chatrooms, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    // Listening to object chat
    echo get_string('listentoobjects', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodlelistentoobjects', $sloodlelistentoobjects);
    echo "<br><br>\n";
    // Allowing auto-deactivation
    echo get_string('allowautodeactivation', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodleautodeactivate', $sloodleautodeactivate);
    echo "<br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings);
}
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible choices on the course
    // Get the ID of the choice type
    $rec = get_record('modules', 'name', 'choice');
    if (!$rec) {
        sloodle_debug("Failed to get choice module type.");
        exit;
    }
    $choicemoduleid = $rec->id;
    // Get all visible choices in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$choicemoduleid} AND visible = 1");
    if (!$recs) {
        error(get_string('nochoices', 'sloodle'));
        exit;
    }
    $choices = array();
    foreach ($recs as $cm) {
        // Fetch the choice instance
        $inst = get_record('choice', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Store the choice details
        $choices[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($choices);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlerefreshtime = (int) sloodle_get_value($settings, 'sloodlerefreshtime', 600);
    $sloodlerelative = (int) sloodle_get_value($settings, 'sloodlerelative', 0);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a choice
    echo get_string('selectchoice', 'sloodle') . ': ';
    choose_from_menu($choices, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    // Ask the user for a refresh period (# seconds between automatic updates)
    echo get_string('refreshtimeseconds', 'sloodle') . ': ';
    echo '<input type="text" name="sloodlerefreshtime" value="' . $sloodlerefreshtime . '" size="8" maxlength="8" />';
    echo "<br><br>\n";
    // Show relative results
    echo get_string('relativeresults', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodlerelative', $sloodlerelative);
    echo "<br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings, true, false, true);
}
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible Sloodle Object assignments on the course
    // Get the ID of the assignment type
    $rec = get_record('modules', 'name', 'assignment');
    if (!$rec) {
        sloodle_debug("Failed to get assignment module type.");
        exit;
    }
    $assignmentmoduleid = $rec->id;
    // Get all visible assignments in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$assignmentmoduleid} AND visible = 1");
    if (!$recs) {
        error(get_string('noassignments', 'sloodle'));
        exit;
    }
    $assignments = array();
    foreach ($recs as $cm) {
        // Fetch the assignment instance
        $inst = get_record('assignment', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Ignore anything except Sloodle Object assignments
        if ($inst->assignmenttype != 'sloodleobject') {
            continue;
        }
        // Store the assignment details
        $assignments[$cm->id] = $inst->name;
    }
    // Make sure that we got some Sloodle Object assignments
    if (count($assignments) == 0) {
        error(get_string('nosloodleassignments', 'sloodle'));
        exit;
    }
    // Sort the list by name
    natcasesort($assignments);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select an assignment
    echo get_string('selectassignment', 'sloodle') . ': ';
    choose_from_menu($assignments, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings);
}
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible distributors on the course
    // Get the ID of the Sloodle type
    $rec = get_record('modules', 'name', 'sloodle');
    if (!$rec) {
        sloodle_debug("Failed to get Sloodle module type.");
        exit;
    }
    // Get all visible Sloodle modules in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$rec->id} AND visible = 1");
    if (!is_array($recs)) {
        $recs = array();
    }
    $distributors = array();
    foreach ($recs as $cm) {
        // Fetch the distributor instance
        $inst = get_record('sloodle', 'id', $cm->instance, 'type', SLOODLE_TYPE_DISTRIB);
        if (!$inst) {
            continue;
        }
        // Store the distributor details
        $distributors[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($distributors);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlerefreshtime = (int) sloodle_get_value($settings, 'sloodlerefreshtime', 3600);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a distributor
    echo get_string('selectdistributor', 'sloodle') . ': ';
    choose_from_menu($distributors, 'sloodlemoduleid', $sloodlemoduleid, '<i>(' . get_string('nodistributorinterface', 'sloodle') . ')</i>', '', 0);
    echo "<br><br>\n";
    // Ask the user for a refresh period (# seconds between automatic updates)
    echo get_string('refreshtimeseconds', 'sloodle') . ': ';
    echo '<input type="text" name="sloodlerefreshtime" value="' . $sloodlerefreshtime . '" size="8" maxlength="8" />';
    echo "<br><br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    // There is no need for server access controls, as users cannot access the server through the object
    // (server access is entirely done through Moodle for this one)
    sloodle_print_access_level_options($settings, true, true, false);
}
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('choice', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: choice instance
     if (!($this->moodle_choice_instance = get_record('choice', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load choice with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     // Fetch options
     $this->options = array();
     if ($options = get_records('choice_options', 'choiceid', $this->moodle_choice_instance->id)) {
         // Get response data (this uses the standard choice function, in "moodle/mod/choice/lib.php")
         $allresponses = choice_get_response_data($this->moodle_choice_instance, $this->cm, 0);
         foreach ($options as $opt) {
             // Create our option object and add our data
             $this->options[$opt->id] = new SloodleChoiceOption();
             $this->options[$opt->id]->id = $opt->id;
             $this->options[$opt->id]->text = $opt->text;
             $this->options[$opt->id]->maxselections = $opt->maxanswers;
             $this->options[$opt->id]->timemodified = (int) $opt->timemodified;
             // Count the number of selections made
             $numsels = 0;
             if (isset($allresponses[$opt->id])) {
                 $numsels = count($allresponses[$opt->id]);
             }
             $this->options[$opt->id]->numselections = $numsels;
         }
     }
     // Determine how many people on the course have not yet answered
     $users = get_course_users($this->cm->course);
     if (!is_array($users)) {
         $users = array();
     }
     $num_users = count($users);
     $numanswers = (int) count_records('choice_answers', 'choiceid', $this->moodle_choice_instance->id);
     $this->numunanswered = max(0, $num_users - $numanswers);
     return true;
 }
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible presenters on the course
    // Get the ID of the chat type
    $rec = get_record('modules', 'name', 'sloodle');
    if (!$rec) {
        sloodle_debug("Failed to get Sloodle module type.");
        exit;
    }
    $sloodlemoduleid = $rec->id;
    // Get all visible presenters in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$sloodlemoduleid} AND visible = 1");
    $presenters = array();
    foreach ($recs as $cm) {
        // Fetch the Sloodle instance
        $inst = get_record('sloodle', 'id', $cm->instance, 'type', SLOODLE_TYPE_PRESENTER);
        if (!$inst) {
            continue;
        }
        // Store the Sloodle details
        $presenters[$cm->id] = $inst->name;
    }
    // Make sure there are some presenters to be had
    if (count($presenters) < 1) {
        error(get_string('nopresenters', 'sloodle'));
        exit;
    }
    // Sort the list by name
    natcasesort($presenters);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlelistentoobjects = (int) sloodle_get_value($settings, 'sloodlelistentoobjects', 0);
    $sloodleautodeactivate = (int) sloodle_get_value($settings, 'sloodleautodeactivate', 1);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a Slideshow
    echo get_string('selectpresenter', 'sloodle') . ': ';
    choose_from_menu($presenters, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings, false, true, false);
}
Пример #9
0
/**
 * Constructs a appropriate Sloodle module object based on the named type.
 * @param string $type The type of module to construct - typically a short name, such as 'chat' or 'blog'
 * @param SloodleSession &$_session The {@link SloodleSession} object to pass to the module on construction, or just null
 * @param mixed $id The identifier of the module instance to load from the database (or null if there is no module data)
 * @return SloodleModule|bool Returns the cosntructed module object, or false if it fails
 */
function sloodle_load_module($type, &$_session, $id = null)
{
    global $SLOODLE_MODULE_CLASS;
    // Abort if the type is not recognised
    if (!array_key_exists($type, $SLOODLE_MODULE_CLASS)) {
        sloodle_debug("Module load failed - type \"{$type}\" not recognised.<br/>");
        return false;
    }
    // Construct the object, based on the class name in our array
    $module = new $SLOODLE_MODULE_CLASS[$type]($_session);
    // Load the data from the database, if necessary
    if ($id != null) {
        if ($module->load((int) $id)) {
            return $module;
        }
        sloodle_debug("Failed to load module data from database with ID {$id}.<br/>");
        return false;
    }
    // Everything seems OK
    return $module;
}
Пример #10
0
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('chat', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: chat instance
     if (!($this->moodle_chat_instance = get_record('chat', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load chatroom with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     return true;
 }
        }
    }
    if ($authid) {
        $sloodle->response->set_status_code(1);
        $sloodle->response->set_status_descriptor('OK');
        $sloodle->response->add_data_line($authid);
        $sloodle->response->add_data_line($alreadyconfigured);
    } else {
        $sloodle->response->set_status_code(-201);
        $sloodle->response->set_status_descriptor('OBJECT_AUTH');
        $sloodle->response->add_data_line('Failed to register new active object.');
    }
} else {
    // Create a new unauthorised entry
    $authid = $sloodle->course->controller->register_unauth_object($sloodleobjuuid, $sloodleobjname, $sloodleobjpwd, $sloodleobjtype);
    if ($authid != 0) {
        $sloodle->response->set_status_code(1);
        $sloodle->response->set_status_descriptor('OK');
        $sloodle->response->add_data_line($authid);
        $sloodle->response->add_data_line($alreadyconfigured = "0");
    } else {
        $sloodle->response->set_status_code(-201);
        $sloodle->response->set_status_descriptor('OBJECT_AUTH');
        $sloodle->response->add_data_line('Failed to register new active object.');
    }
}
// Render the output
sloodle_debug('<pre>');
$sloodle->response->render_to_output();
sloodle_debug('</pre>');
Пример #12
0
 /**
  * Imports the given file using the ImageMagick command line programs if possible. (Internal only)
  * @param SloodleModulePresenter $presenter An object representing the Presenter we are importing into.
  * @param string $srcfile Full path of the PDF file we are importing
  * @param string $destpath Folder path to which the imported files will be added.
  * @param string $viewurl URl of the folder in which the files can be viewed
  * @param string $destfile Name for the output files (excluding extension, such as .jpg). The page numbers will be appended automatically, before the extension
  * @param string $destfileext Extension for destination files, not including the dot. (e.g. "jpg" or "png").
  * @param string $destname Basic name to use for each imported slide. The page numbers will be appended automatically.
  * @param integer $position The position within the Presentation to add the new slides. Optional. Default is to put them at the end.
  * @return integer|bool If successful, an integer indicating the number of slides loaded is displayed. If the import does not (or cannot) work, then boolean false is returned.
  * @access private
  */
 function _import_ImageMagick($presenter, $srcfile, $destpath, $viewurl, $destfile, $destfileext, $destname, $position = -1)
 {
     global $IMAGICK_CONVERT_PATH;
     // Do a security check -- has command-line execution of IMagick been disabled by the admin?
     sloodle_debug("<br/><strong>Attempting to use ImageMagick by command-line.</strong><br/>");
     if (empty($IMAGICK_CONVERT_PATH)) {
         sloodle_debug(" ERROR: path to ImageMagick \\'convert\\' program is blank.");
         return false;
     }
     // Now make sure there are no quotation marks in the source/destination file and path names
     //  (these could be used to execute malicious commands on the server)
     if (strpos($srcfile, "\"") !== false || strpos($destpath, "\"") !== false || strpos($destfile, "\"") !== false || strpos($destfileext, "\"") != false) {
         error("Invalid file name -- please remove quotation marks from file names.");
     }
     // Construct the conversion command
     $cmd = "\"{$IMAGICK_CONVERT_PATH}\" -verbose \"{$srcfile}\" \"{$destpath}/{$destfile}-%d.{$destfileext}\"";
     if (substr(php_uname(), 0, 7) == "Windows") {
         $cmd = 'start /B "" ' . $cmd;
     }
     // Windows compatibility
     sloodle_debug(" Executing shell command: {$cmd}<br/>");
     $output = array();
     $result = exec($cmd, $output);
     // If all the output is empty, then execution failed
     if (empty($result) && empty($output)) {
         sloodle_debug(" ERROR: execution of the shell command failed.<br/>");
         echo "<hr><pre>";
         print_r($output);
         echo "</pre><hr>";
         return false;
     }
     // Quick validation - position should start at 1. (-ve numbers mean "at the end")
     if ($position == 0) {
         $position = 1;
     }
     // Go through each page which was created.
     // Stop when we encounter a file which wasn't created -- that will be the end of the document.
     $pagenum = 0;
     $page_position = -1;
     $stop = false;
     while ($stop == false && $pagenum < 10000) {
         // Determine this page's position in the Presentation
         if ($position > 0) {
             $page_position = $position + $pagenum;
         }
         // Construct the file and slide names for this page
         $page_filename = "{$destpath}/{$destfile}-{$pagenum}.{$destfileext}";
         // Where it gets uploaded to
         $page_slidesource = "{$viewurl}/{$destfile}-{$pagenum}.{$destfileext}";
         // The URL to access it publicly
         $page_slidename = "{$destname} (" . ($pagenum + 1) . ")";
         // Was this file created?
         if (file_exists($page_filename)) {
             // Add it to the Presenter
             $presenter->add_entry($page_slidesource, 'image', $page_slidename, $page_position);
             $pagenum++;
         } else {
             $stop = true;
         }
     }
     return $pagenum;
 }
Пример #13
0
 /**
  * Loads course and controller data by the unqiue site-wide identifier of a Sloodle controller.
  * @param mixed $controllerid The unique site-wide identifier for a Sloodle Controller. (For Moodle, an integer cmi)
  * @return bool True if successful, or false on failure.        
  */
 function load_by_controller($controllerid)
 {
     // Clear out all our data
     $this->course_object = null;
     $this->sloodle_course_data = null;
     // Construct a new controller object, and attempt to load its data
     $this->controller = new SloodleController();
     if (!$this->controller->load($controllerid)) {
         sloodle_debug("Failed to load controller.<br>");
         return false;
     }
     // Now attempt to load all the course data
     if (!$this->load($this->controller->get_course_id())) {
         sloodle_debug("Failed to load course data.<br>");
         return false;
     }
     return true;
 }
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // If your object is going to link into an existing module in Moodle, e.g. chatrooms, then you need to get a list all such module instances in the course.
    // We will be using chatrooms for this example.
    // First, we need to figure out what the ID number for the 'chat' type is.
    $rec = get_record('modules', 'name', 'chat');
    if (!$rec) {
        sloodle_debug("Failed to get chatroom module type.");
        exit;
    }
    $chatmoduleid = $rec->id;
    // Get all visible chatrooms in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$chatmoduleid} AND visible = 1");
    if (!$recs) {
        // No visible chatrooms -- output an error message
        error(get_string('nochatrooms', 'sloodle'));
        // This comes from the SLOODLE language pack
        exit;
    }
    // Go through each chatroom we were given
    $chatrooms = array();
    foreach ($recs as $cm) {
        // Fetch the chatroom instance
        $inst = get_record('chat', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Store the chatroom details
        $chatrooms[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($chatrooms);
    // We now have an alphabetically-sorted array, associating course module instance IDs with chatroom names.
    // We can use that to let the user know what chatrooms are available.
    //--------------------------------------------------------
    // FORM
    // If the object is already configured, then we need to get its current configuration.
    // This function will grab an array of configuration settings from the database.
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Use the "sloodle_get_value" function to extract specific settings from the array.
    // The second argument names the parameter, and the 3rd gives the default initial value.
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlerandomtext = sloodle_get_value($settings, 'sloodlerandomtext', 'foobar');
    $sloodleshowhovertext = (int) sloodle_get_value($settings, 'sloodleshowhovertext', 1);
    ///// GENERAL CONFIGURATION /////
    // We will now display the configuration form.
    // Create a new section box for general configuration options
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Display a drop-down menu (using a Moodle function) to let the user choose the module.
    // In this case, we are showing them a list of chatrooms.
    // This is a very common part of the configuration form.
    echo get_string('selectchatroom', 'sloodle') . ': ';
    choose_from_menu($chatrooms, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    // Display a text box for some random text
    echo 'Enter some text: ';
    // Ideally this should be replaced by "get_string(...)"
    echo '<input type="text" name="sloodlerandomtext" id="sloodlerandomtext" value="' . $sloodlerandomtext . '" size="20" maxlength="20" />';
    echo "<br><br>\n";
    // Display a yes/no drop down menu.
    // NOTE: we can't use checkboxes! Yes/no responses must be done as drop-down menus.
    echo 'Show hover text? ';
    // Ideally this should be replaced by "get_string(...)"
    choose_from_menu_yesno('sloodleshowhovertext', $sloodleshowhovertext);
    echo "<br>\n";
    // Close the general section
    print_box_end();
    ///// ACCESS LEVELS /////
    // This is common to nearly all objects, although variations are possible.
    // There are 3 access settings, in two categories:
    //  In-world: use and control
    //  Server: access
    //
    // The in-world 'use' setting determines who can generally use the object, whether it is public, limited to an SL group, or owner-only. (Public by default)
    // The in-world 'control' setting determines who has authority to control the object, which can similarly be public, group, or owner-only. (Owner-only by default)
    // The server access lets you limit usage to avatars which are registered or enrolled, or to members of staff. By default though, it is public.
    //
    // The following function displays the appropriate form data.
    // We pass in the existing settings so that it can setup defaults.
    // The subsequent 3 parameters determine if each type of access setting should be visible, in the order specified above.
    // They are optional, and all default to true if not specified.
    sloodle_print_access_level_options($settings, true, true, true);
}
Пример #15
0
    if (!empty($sloodleblogbody)) {
        $sloodle->request->required_param('sloodleblogsubject');
    } else {
        // Neither parameter was specified
        $sloodle->response->quick_output(1, 'OK', '', false);
        exit;
    }
}
// We need to know if all header data was retrieved
$use_slurl = isset($_SERVER['HTTP_X_SECONDLIFE_REGION']) && isset($_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION']);
// Use the HTTP headers added by SL to get the region and position data, and construct a SLurl from them
if ($use_slurl) {
    $region = $_SERVER['HTTP_X_SECONDLIFE_REGION'];
    $region = substr($region, 0, strpos($region, '(') - 1);
    $position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'];
    sloodle_debug('Constructing SLurl...<br/>');
    sscanf($position, "(%f, %f, %f)", $x, $y, $z);
    $slurl = "http://slurl.com/secondlife/" . $region . "/" . $x . "/" . $y . "/" . $z;
    $slurl = '<a href="' . $slurl . '">' . $region . '</a>';
} else {
    $slurl = '[' . get_string('unknown', 'sloodle') . ']';
}
// Construct the final blog body
$sloodleblogbody = get_string('postedfromsl', 'sloodle') . ': ' . $slurl . "\n\n" . $sloodleblogbody;
// Make all string data safe
$sloodleblogsubject = addslashes(clean_text(stripslashes($sloodleblogsubject), FORMAT_PLAIN));
$sloodleblogbody = addslashes(clean_text(stripslashes($sloodleblogbody), FORMAT_MOODLE));
$sloodleblogvisibility = addslashes(clean_text(stripslashes($sloodleblogvisibility), FORMAT_PLAIN));
// Write the entry to the database
if ($sloodle->module->add_entry($sloodleblogsubject, $sloodleblogbody, $sloodleblogvisibility)) {
    $sloodle->response->set_status_code(103);
// The information will relate to whatever course the accessed controller belongs to.
// (This is for security, to ensure course data cannot be retrieved unauthorised).
// The autoreg and autoenrol values will be 0 or 1, indicate whether each feature is disabled or enabled on the course.
/** Lets Sloodle know we are in a linker script. */
define('SLOODLE_LINKER_SCRIPT', true);
/** Grab the Sloodle/Moodle configuration. */
require_once '../sl_config.php';
/** Include the Sloodle PHP API. */
require_once SLOODLE_LIBROOT . '/sloodle_session.php';
// Authenticate the request
$sloodle = new SloodleSession();
$sloodle->authenticate_request();
// Make sure Sloodle is actually installed
$moduleinfo = get_record('modules', 'name', 'sloodle');
if (!$moduleinfo) {
    sloodle_debug('ERROR: Sloodle not installed<br/>');
    $sloodle->response->quick_output(-106, 'SYSTEM', 'The Sloodle module is not installed on this Moodle site.', false);
    exit;
}
// Check out autoreg and autoenrol settings
$autoreg = '0';
$autoenrol = '0';
if ($sloodle->course->check_autoreg()) {
    $autoreg = '1';
}
if ($sloodle->course->check_autoenrol()) {
    $autoenrol = '1';
}
// Prepare the output
$sloodle->response->set_status_code(1);
$sloodle->response->set_status_descriptor('OK');
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('assignment', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: assignment instance
     if (!($this->moodle_assignment_instance = get_record('assignment', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load assignment with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     // Make sure this assignment is of the correct type
     if ($this->moodle_assignment_instance->assignmenttype != 'sloodleobject') {
         sloodle_debug("ERROR assignment \"{$this->moodle_assignment_instance->name}\" is not of type 'sloodleobject' (actual type: '{$this->moodle_assignment_instance->assignmenttype}').");
         return false;
     }
     // Attempt to construct the assignment object
     $this->assignment = new assignment_sloodleobject($this->cm->id, $this->moodle_assignment_instance, $this->cm);
     return true;
 }
Пример #18
0
        if (!has_capability('mod/sloodle:registeravatar', get_context_instance(CONTEXT_SYSTEM))) {
            $sloodle->response->set_status_code(-331);
            $sloodle->response->set_status_descriptor('USER_AUTH');
            $sloodle->response->add_data_line('User does not have permission to register an avatar.');
        } else {
            // Add the avatar to our database
            if ($sloodle->user->add_linked_avatar($sloodle->user->get_user_id(), $sloodleuuid, $sloodleavname)) {
                // Delete the LoginZone allocation now
                $sloodle->course->delete_loginzone_allocation($sloodle->user);
                // We've been successful
                $sloodle->response->set_status_code(1);
                $sloodle->response->set_status_descriptor('OK');
            } else {
                // Failed to add the avatar
                $sloodle->response->set_status_code(-102);
                $sloodle->response->set_status_descriptor('SYSTEM');
                $sloodle->response->add_data_line('Failed to add avatar to database');
            }
        }
    } else {
        // Report the problem back in the response
        $sloodle->response->set_status_code(-301);
        $sloodle->response->set_status_descriptor('USER_AUTH');
        $sloodle->response->add_data_line('No user found with specified Login Position.');
    }
}
// Output the response
sloodle_debug("<pre>");
$sloodle->response->render_to_output();
sloodle_debug("</pre>");
exit;
Пример #19
0
/**
 * Render a page viewing a particular feature, or a SLOODLE module.
 * Outputs error text in SLOODLE debug mode.
 * @param string $feature The name of a feature to view ("course", "user", "users"), or "module" to indicate that we are viewing some kind of module. Note: features should contain only alphanumric characters.
 * @return bool True if successful, or false if not.
 */
function sloodle_view($feature)
{
    global $CFG, $USER;
    // Make sure the parameter is safe -- nothing but alphanumeric characters.
    if (!ctype_alnum($feature)) {
        sloodle_debug('sloodle_view(..): Invalid characters in view feature, "' . $feature . '"');
        return false;
    }
    if (empty($feature)) {
        sloodle_debug('sloodle_view(..): No feature name specified.');
        return false;
    }
    $feature = trim($feature);
    // Has a module been requested?
    if (strcasecmp($feature, 'module') == 0) {
        // We should have an ID parameter, indicating which module has been requested
        $id = required_param('id', PARAM_INT);
        // Query the database for the SLOODLE module sub-type
        $instanceid = get_field('course_modules', 'instance', 'id', $id);
        if ($instanceid === false) {
            error('Course module instance ' . $id . ' not found.');
        }
        $type = get_field('sloodle', 'type', 'id', $instanceid);
        if ($type === false) {
            error('SLOODLE module instance ' . $instanceid . ' not found.');
        }
        // We will just use the type as a feature name now.
        // This means the following words are unavailable as module sub-types: course, user, users
        $feature = $type;
    }
    // Attempt to include the relevant viewing class
    $filename = SLOODLE_DIRROOT . "/view/{$feature}.php";
    if (!file_exists($filename)) {
        error("SLOODLE file not found: view/{$feature}.php");
        exit;
    }
    require_once $filename;
    // Create and execute the viewing instance
    $classname = 'sloodle_view_' . $feature;
    if (!class_exists($classname)) {
        error("SLOODLE class missing: {$classname}");
        exit;
    }
    $viewer = new $classname();
    $viewer->view();
    return true;
}
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible quizzes on the course
    // Get the ID of the chat type
    $rec = get_record('modules', 'name', 'quiz');
    if (!$rec) {
        sloodle_debug("Failed to get quiz module type.");
        exit;
    }
    $quizmoduleid = $rec->id;
    // Get all visible quizzes in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$quizmoduleid} AND visible = 1");
    if (!$recs) {
        error(get_string('noquizzes', 'sloodle'));
        exit;
    }
    $quizzes = array();
    foreach ($recs as $cm) {
        // Fetch the quiz instance
        $inst = get_record('quiz', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Store the quiz details
        $quizzes[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($quizzes);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlerepeat = (int) sloodle_get_value($settings, 'sloodlerepeat', 0);
    $sloodlerandomize = (int) sloodle_get_value($settings, 'sloodlerandomize', 1);
    $sloodledialog = (int) sloodle_get_value($settings, 'sloodledialog', 1);
    $sloodleplaysound = (int) sloodle_get_value($settings, 'sloodleplaysound', 0);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a quiz
    echo get_string('selectquiz', 'sloodle') . ': ';
    choose_from_menu($quizzes, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    // Repeat the quiz
    echo get_string('repeatquiz', 'sloodle') . ' ';
    choose_from_menu_yesno('sloodlerepeat', $sloodlerepeat);
    echo "<br><br>\n";
    // Randomize the question order
    echo get_string('randomquestionorder', 'sloodle') . ' ';
    choose_from_menu_yesno('sloodlerandomize', $sloodlerandomize);
    echo "<br><br>\n";
    // Use dialogs
    echo get_string('usedialogs', 'sloodle') . ' ';
    choose_from_menu_yesno('sloodledialog', $sloodledialog);
    echo "<br><br>\n";
    // Play sounds
    echo get_string('playsounds', 'sloodle') . ' ';
    choose_from_menu_yesno('sloodleplaysound', $sloodleplaysound);
    echo "<br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings, true, false, true);
}
Пример #21
0
    if ($curslidenum == $sloodleslidenum) {
        $outputslide = $curslide;
        break;
    }
    $curslidenum++;
}
// Output the basic presenter information
$sloodle->response->set_status_code(1);
$sloodle->response->set_status_descriptor('OK');
$sloodle->response->add_data_line(array($numslides, sloodle_clean_for_output($sloodle->module->get_name())));
// Our plugin data will be store in these variables
$slidetype = '';
$slidesource = '';
// Attempt to load the plugin required by our current slide
sloodle_debug("Attempting to load plugin \"{$outputslide->type}\"...");
$slideplugin = $sloodle->plugins->get_plugin('presenter-slide', $outputslide->type);
if ($slideplugin === false) {
    // Indicate the error as a side effect, and specify the type as an error
    sloodle_debug("Failed to load Presenter slide plugin.\n");
    $sloodle->response->add_side_effect(-132);
    $slidetype = 'ERROR';
    $slidesource = '';
} else {
    // Load the slide data from the plugin
    sloodle_debug("Loaded plugin OK\n");
    list($slidetype, $slidesource) = $slideplugin->render_slide_for_sl($outputslide);
}
// Output the slide data
$sloodle->response->add_data_line(array($sloodleslidenum, sloodle_clean_for_output($slidetype), sloodle_clean_for_output($slidesource), sloodle_clean_for_output($outputslide->name)));
$sloodle->response->render_to_output();
exit;
Пример #22
0
        $slidetype = strtolower($slide->type);
        switch ($slidetype) {
            case 'presenterslideimage':
            case 'sloodlepluginpresenterslideimage':
                $slidetype = 'image';
                break;
            case 'presenterslideweb':
            case 'sloodlepluginpresenterslideweb':
                $slidetype = 'web';
                break;
            case 'presenterslidevideo':
            case 'sloodlepluginpresenterslidevideo':
                $slidetype = 'video';
                break;
        }
        // Attempt to load the plugin for this type
        $slideplugin = $sloodle->plugins->get_plugin('presenter-slide', $slidetype);
        if ($slideplugin === false) {
            // Indicate the error as a side effect, and specify the type as an error
            sloodle_debug("Failed to load Presenter slide plugin.\n");
            $sloodle->response->add_side_effect(-132);
            $entrytype = 'ERROR';
            $entrysource = '';
        } else {
            list($mimetype, $slidesource) = $slideplugin->render_slide_for_sl($slide);
        }
        $sloodle->response->add_data_line(array($slidetype, $slidesource, $slide->name));
    }
}
// Output our response
$sloodle->response->render_to_output();
function sloodle_display_config_form($sloodleauthid, $auth_obj)
{
    //--------------------------------------------------------
    // SETUP
    // Determine which course is being accessed
    $courseid = $auth_obj->course->get_course_id();
    // We need to fetch a list of visible glossaries on the course
    // Get the ID of the chat type
    $rec = get_record('modules', 'name', 'glossary');
    if (!$rec) {
        sloodle_debug("Failed to get glossary module type.");
        exit;
    }
    $glossarymoduleid = $rec->id;
    // Get all visible glossary in the current course
    $recs = get_records_select('course_modules', "course = {$courseid} AND module = {$glossarymoduleid} AND visible = 1");
    if (!$recs) {
        error(get_string('noglossaries', 'sloodle'));
        exit;
    }
    $glossaries = array();
    foreach ($recs as $cm) {
        // Fetch the chatroom instance
        $inst = get_record('glossary', 'id', $cm->instance);
        if (!$inst) {
            continue;
        }
        // Store the glossary details
        $glossaries[$cm->id] = $inst->name;
    }
    // Sort the list by name
    natcasesort($glossaries);
    //--------------------------------------------------------
    // FORM
    // Get the current object configuration
    $settings = SloodleController::get_object_configuration($sloodleauthid);
    // Setup our default values
    $sloodlemoduleid = (int) sloodle_get_value($settings, 'sloodlemoduleid', 0);
    $sloodlepartialmatches = (int) sloodle_get_value($settings, 'sloodlepartialmatches', 1);
    $sloodlesearchaliases = (int) sloodle_get_value($settings, 'sloodlesearchaliases', 0);
    $sloodlesearchdefinitions = (int) sloodle_get_value($settings, 'sloodlesearchdefinitions', 0);
    $sloodleidletimeout = (int) sloodle_get_value($settings, 'sloodleidletimeout', 120);
    ///// GENERAL CONFIGURATION /////
    print_box_start('generalbox boxaligncenter');
    echo '<h3>' . get_string('generalconfiguration', 'sloodle') . '</h3>';
    // Ask the user to select a chatroom
    echo get_string('selectglossary', 'sloodle') . ': ';
    choose_from_menu($glossaries, 'sloodlemoduleid', $sloodlemoduleid, '');
    echo "<br><br>\n";
    // Show partial matches
    echo get_string('showpartialmatches', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodlepartialmatches', $sloodlepartialmatches);
    echo "<br><br>\n";
    // Search aliases
    echo get_string('searchaliases', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodlesearchaliases', $sloodlesearchaliases);
    echo "<br><br>\n";
    // Search definitions
    echo get_string('searchdefinitions', 'sloodle') . ': ';
    choose_from_menu_yesno('sloodlesearchdefinitions', $sloodlesearchdefinitions);
    echo "<br><br>\n";
    // Ask the user for an idle timeout period (# seconds of no activity before automatic shutdown)
    echo get_string('idletimeoutseconds', 'sloodle') . ': ';
    echo '<input type="text" name="sloodleidletimeout" value="' . $sloodleidletimeout . '" size="8" maxlength="8" />';
    echo "<br>\n";
    print_box_end();
    ///// ACCESS LEVELS /////
    sloodle_print_access_level_options($settings);
}