feedback = $_SESSION['sloodle_presenter_feedback']; unset($_SESSION['sloodle_presenter_feedback']); // Construct a SLOODLE Session and load a module $this->_session = new SloodleSession(false); $this->presenter = new SloodleModulePresenter($this->_session); if (!$this->presenter->load($this->cm->id)) return false; $this->_session->module = $this->presenter; // Load available Presenter plugins if (!$this->_session->plugins->load_plugins('presenter')) { print_error('Failed to load Presenter plugins.'); return false; } } /** * 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', PARAM_TEXT); } 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') { sloodle_require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.js'); sloodle_require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.uploadify.js'); sloodle_require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.checkboxes.js'); sloodle_require_js($CFG->wwwroot .'/mod/sloodle/lib/multiplefileupload/extra.js'); sloodle_require_js($CFG->wwwroot .'/lib/filelib.php'); } if ( $this->presenter_mode == 'addfiles') { sloodle_require_js($CFG->wwwroot .'/mod/sloodle/lib/js/presenter_addfiles.js"'); } // Should we process any incoming editing commands? if ($this->canedit) { // 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', PARAM_RAW) != sesskey()) { print_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', PARAM_RAW) != sesskey()) { print_error('Invalid session key'); exit(); } // Fetch the IDs of the slides which are being deleted if (isset($_REQUEST['entriesstr'])) $entryids = explode(',',$_REQUEST['entriesstr']); else print_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; } // for New File Manager if (isset($_REQUEST['sloodlemultiupdate'])) { global $DB, $USER; if (!confirm_sesskey()) { print_error('Invalid session key'); exit(); } // $contextid = (int)required_param('id', PARAM_INT); $maxfiles = (int)optional_param('maxfiles', 1, PARAM_INT); $insertnum = (int)optional_param('insertnum', '-1', PARAM_INT); // File Manager. see lib/filelib.php $picid = file_get_submitted_draft_itemid('picfile'); file_save_draft_area_files($picid, $contextid, 'mod_sloodle', 'presenter', $picid, array('maxfiles'=>$maxfiles)); $condition = "itemid=$picid AND contextid=$contextid AND component='mod_sloodle' AND filearea='presenter' AND ". "filename!='\\.' AND filesize!='0' AND source!='NULL'"; $query_str = 'SELECT * FROM '.$CFG->prefix.'files WHERE '.$condition; // $files = array(); $files_num = 0; if ($stores = $DB->get_records_sql($query_str)) { foreach($stores as $store) { $files[$files_num]['fileid'] = $store->id; $files[$files_num]['contextid'] = $store->contextid; $files[$files_num]['filename'] = $store->filename; $files_num++; } } for ($i=0; $i<$files_num; $i++) { $path = '@@PLUGINFILE@@/'.$files[$i]['filename']; $files[$i]['url'] = file_rewrite_pluginfile_urls($path, 'pluginfile.php', $files[$i]['contextid'], 'mod_sloodle', 'presenter', $picid); } foreach ($files as $file) { $info = new SplFileInfo($file['filename']); $extension = $info->getExtension(); $ftype = strtolower($extension); switch ($ftype){ case "mov" : $ftype = "video"; break; case "mpg" : $ftype = "video"; break; case "jpg" : $ftype = "image"; break; case "png" : $ftype = "image"; break; case "gif" : $ftype = "image"; break; case "bmp" : $ftype = "image"; break; case "mp4" : $ftype = "video"; break; case "htm" : $ftype = "web"; break; case "html": $ftype = "web"; break; } $this->presenter->add_entry(sloodle_clean_for_db($file['url']), $ftype, sloodle_clean_for_db($file['filename']), $insertnum); if ($insertnum>=0) $insertnum++; } $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(); } } } /** * Render the View of the Presenter. * Called from with the {@link render()} function when necessary. */ function render_view() { //display any feedback if (!empty($this->feedback)) echo $this->feedback; // Get a list of entry slides in this presenter $entries = $this->presenter->get_slides(); if (!is_array($entries)) $entries = array(); $numentries = count($entries); // Open the presentation box //sloodle_print_box_start('generalbox boxaligncenter boxwidthwide'); // Was a specific entry requested? This is the number of entry within the presentation, NOT entry ID. // They start at 1 and go up from there within each presentation. if (isset($_REQUEST['sloodledisplayentry'])) { $displayentrynum = (int)$_REQUEST['sloodledisplayentry']; if ($displayentrynum < 1 || $displayentrynum > $numentries) $displayentrynum = 1; } else { $displayentrynum = 1; } // Do we have any entries to work with? if ($numentries > 0) { // Yes - go through them to figure out which entry to display $currententry = null; foreach ($entries as $entryid => $entry) { // Check if this is our current entry if ($displayentrynum == $entry->slideposition) { $currententry = $entry; } } // Display the entry header echo "
'; // if ($displayentrynum > 1) echo "cm->id}&sloodledisplayentry=",$displayentrynum - 1,"#slide\" title=\"{$strviewprev}\">←"; // else echo "←"; // echo " {$displayentrynum} {$strof} {$numentries} "; // if ($displayentrynum < $numentries) echo "cm->id}&sloodledisplayentry=",$displayentrynum + 1,"#slide\" title=\"{$strviewnext}\">→"; //else echo "→"; echo "
\n"; echo '';
$entrynumcounter=1;
$jumpNumber=5;
//display >>
$arrowLinks = new stdClass();
$arrowLinks->class='texrender';
$arrowLinks->size = array('40px', '40px','40px','40px','40px');
$arrowLinks->cellpadding='1';
$arrowLinks->width='500px';
$slideLinks= new stdClass();
$slideLinks->class='texrender';
$slideLinks->size = array('20px', '20px','20px','20px','20px','20px','20px');
$slideLinks->cellpadding='1';
$row = array();
$arow = array();
$start = $displayentrynum - $jumpNumber-1;
if ($start>=0) $arow[]= "cm->id}&sloodledisplayentry={$start}#slide\" title=\"{$strviewjumpback} ".$jumpNumber." slides\">![]() ![]() ![]() ![]()
![]() ![]() ![]() ![]() ';
sloodle_print_table($arrowLinks);
echo ' ';
echo ""; echo ' |
',get_string('unknowntype','sloodle'),': presenter-slide::',$currententry->type, '
'; } // Display a direct link to the media echo ""; print ''; print_string('trydirectlink', 'sloodle'); print ""; echo "
\n"; echo "'.get_string('presenter:clickaddslide', 'sloodle').'
'; } } /** * Render the Edit mode of the Presenter (lists all the slides and allows re-ordering). * Called from with the {@link render()} function when necessary. */ function render_edit() { /* global $DB, $CFG, $USER; // POST by Fumi.Hax if (data_submitted() && confirm_sesskey()) { // $contextid = (int)required_param('id', PARAM_INT); $maxfiles = (int)optional_param('maxfiles', 1, PARAM_INT); $insertnum = (int)optional_param('insertnum', '-1', PARAM_INT); // File Manager. see lib/filelib.php $picid = file_get_submitted_draft_itemid('picfile'); file_save_draft_area_files($picid, $contextid, 'mod_sloodle', 'presenter', $picid, array('maxfiles'=>$maxfiles)); $condition = "itemid=$picid AND contextid=$contextid AND component='mod_sloodle' AND filearea='presenter' AND ". "filename!='\\.' AND filesize!='0' AND source!='NULL'"; $query_str = 'SELECT * FROM '.$CFG->prefix.'files WHERE '.$condition; // $files = array(); $files_num = 0; if ($stores = $DB->get_records_sql($query_str)) { foreach($stores as $store) { $files[$files_num]['fileid'] = $store->id; $files[$files_num]['contextid'] = $store->contextid; $files[$files_num]['filename'] = $store->filename; $files_num++; } } for ($i=0; $i<$files_num; $i++) { $path = '@@PLUGINFILE@@/'.$files[$i]['filename']; $files[$i]['url'] = file_rewrite_pluginfile_urls($path, 'pluginfile.php', $files[$i]['contextid'], 'mod_sloodle', 'presenter', $picid); } foreach ($files as $file) { $info = new SplFileInfo($file['filename']); $extension = $info->getExtension(); $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($file['url']), $ftype, sloodle_clean_for_db($file['filename']), $insertnum); if ($insertnum>=0) $insertnum++; } } */ //display any feedback if (!empty($this->feedback)) echo $this->feedback; global $CFG, $OUTPUT; $streditpresenter = get_string('presenter:edit', 'sloodle'); $strviewanddelete = get_string('presenter:viewanddelete', 'sloodle'); $strnoentries = get_string('noentries', 'sloodle'); $strnoslides = get_string('presenter:empty', 'sloodle'); $strdelete = get_string('delete', 'sloodle'); $stradd = get_string('presenter:add', 'sloodle'); $straddatend = get_string('presenter:addatend', 'sloodle'); $straddbefore = get_string('presenter:addbefore', 'sloodle'); $strtype = get_string('type', 'sloodle'); $strurl = get_string('url', 'sloodle'); $strname = get_string('name', 'sloodle'); $stryes = get_string('yes'); $strno = get_string('no'); $strmove = get_string('move'); $stredit = get_string('edit', 'sloodle'); $strview = get_string('view', 'sloodle'); $strdelete = get_string('delete'); $strmoveslide = get_string('presenter:moveslide', 'sloodle'); $streditslide = get_string('presenter:editslide', 'sloodle'); $strviewslide = get_string('presenter:viewslide', 'sloodle'); $strdeleteslide = get_string('presenter:deleteslide', 'sloodle'); // pixpath breaks in Moodle 2. if ( SLOODLE_IS_ENVIRONMENT_MOODLE_2 ) { $moveheregif = $OUTPUT->pix_url('movehere'); $movegif = $OUTPUT->pix_url('t/move'); $editgif = $OUTPUT->pix_url('t/edit'); $previewgif = $OUTPUT->pix_url('t/preview'); $deletegif = $OUTPUT->pix_url('t/delete'); } else { $moveheregif = "{$CFG->pixpath}/movehere.gif"; $movegif = "{$CFG->pixpath}/t/move.gif"; $editgif = "{$CFG->pixpath}/t/edit.gif"; $previewgif = "{$CFG->pixpath}/t/preview.gif"; $deletegif = "{$CFG->pixpath}/t/delete.gif"; } // Get a list of entry URLs $entries = $this->presenter->get_slides(); if (!is_array($entries)) $entries = array(); $numentries = count($entries); // Any images to display? if ($entries === false || count($entries) == 0) { echo '", get_string('presenter:movingslide', 'sloodle', $entries[$this->movingentryid]->name), "
\n"; echo "\n"; sloodle_print_box_end(); } // Setup a table object to display Presenter entries $entriesTable = new stdClass(); $entriesTable->head = array(get_string('position', 'sloodle'),'', get_string('name', 'sloodle'), get_string('type', 'sloodle'), get_string('actions', 'sloodle')); $entriesTable->align = array('center', 'center', 'left', 'left', 'center'); $entriesTable->size = array('5%', '5%', '30%', '20%', '30%'); // Go through each entry $numentries = count($entries); foreach ($entries as $entryid => $entry) { // Create a new row for the table $row = array(); // Extract the entry data $slideplugin = $this->_session->plugins->get_plugin('presenter-slide', $entry->type); if (is_object($slideplugin)) $entrytypename = $slideplugin->get_plugin_name(); else $entrytypename = '(unknown type)'; // Construct the link to the entry source $entrylink = "source}\" title=\"{$entry->source}\">{$entry->name}"; // If this is the slide being moved, then completely ignore it if ($this->movingentryid == $entryid) { continue; } // If we are in move mode, then add a 'move here' row before this slide if ($this->presenter_mode == 'moveslide') { $movelink = SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&mode=setslideposition&entry={$this->movingentryid}&position={$entry->slideposition}"; $movebutton = "'.get_string('presenter:uploadInstructions','sloodle').'
'; // We'll post the data straight back to this page echo ''; // Add a button to let us cancel and go back to the main edit tab echo ''; } /** * Render the slide editing form of the Presenter (lets you edit a single slide). * Called from with the {@link render()} function when necessary. */ function render_slide_edit() { // Setup variables to store the data $entryid = 0; $entryname = ''; $entryurl = ''; $entrytype = ''; // Fetch a list of existing slides $entries = $this->presenter->get_slides(); // Check what position we are adding the new slide to // (default to negative, which puts it at the end) $position = (int)optional_param('sloodleentryposition', '-1', PARAM_INT); // Are we adding a slide, or editing one? $newslide = false; if ($this->presenter_mode == 'addslide') { // Adding a new slide $newslide = true; // Grab the last added type from session data if (isset($_SESSION['sloodle_presenter_add_type'])) $entrytype = $_SESSION['sloodle_presenter_add_type']; } else { // Editing an existing slide $entryid = (int)required_param('entry', PARAM_INT); // Fetch the slide details if (!isset($entries[$entryid])) { print_error("Cannot find entry {$entryid} in the database."); exit(); } $entryurl = $entries[$entryid]->source; $entrytype = $entries[$entryid]->type; $entryname = $entries[$entryid]->name; } // Fetch our translation strings $streditpresenter = get_string('presenter:edit', 'sloodle'); $strviewanddelete = get_string('presenter:viewanddelete', 'sloodle'); $strnoentries = get_string('noentries', 'sloodle'); $strdelete = get_string('delete', 'sloodle'); $stradd = get_string('presenter:add', 'sloodle'); $strtype = get_string('type', 'sloodle'); $strurl = get_string('url', 'sloodle'); $strname = get_string('name', 'sloodle'); $strposition = get_string('position', 'sloodle'); $strsave = get_string('save', 'sloodle'); $strend = get_string('end', 'sloodle'); $stryes = get_string('yes'); $strno = get_string('no'); $strcancel = get_string('cancel'); $strmove = get_string('move'); $stredit = get_string('edit', 'sloodle'); $strview = get_string('view', 'sloodle'); $strdelete = get_string('delete'); // Construct an array of available entry types, associating the identifier to the human-readable name. $availabletypes = array(); $pluginids = $this->_session->plugins->get_plugin_ids('presenter-slide'); if (!$pluginids) exit('Failed to query for SLOODLE Presenter slide plugins.'); foreach ($pluginids as $pluginid) { // Fetch the plugin and store its human-readable name $plugin = $this->_session->plugins->get_plugin('presenter-slide', $pluginid); $availabletypes[$pluginid] = $plugin->get_plugin_name(); } // We'll post the data straight back to this page echo ''; // Add a button to let us cancel and go back to the main edit tab echo ''; } /** * Render the tab for importing slides from some source. * If necessary, this will first display a form letting the user select which importer to use. * It will then rely on the plugin to sort out everything else. */ function render_import_slides() { global $CFG; // Construct an array of available importers, associating the identifier to the human-readable name. $availableimporters = array(); $pluginids = $this->_session->plugins->get_plugin_ids('presenter-importer'); if (!$pluginids) print_error('Failed to load any SLOODLE Presenter importer plugins. Please check your plugins folder.'); foreach ($pluginids as $pluginid) { // Fetch the plugin and store its human-readable name $plugin = $this->_session->plugins->get_plugin('presenter-importer', $pluginid); $availableimporters[$pluginid] = $plugin->get_plugin_name(); } // We are expecting a few parameters $position = (int)optional_param('sloodleentryposition', '-1', PARAM_INT); $plugintype = strtolower(optional_param('sloodleplugintype', '', PARAM_CLEAN)); // Fetch translation strings $strselectimporter = get_string('presenter:selectimporter', 'sloodle'); $strsubmit = get_string('submit'); $strincompatible = get_string('incompatible', 'sloodle'); $strcompatible = get_string('compatible', 'sloodle'); $strincompatibleplugin = get_string('incompatibleplugin', 'sloodle'); $strcheck = get_string('check', 'sloodle'); $strclicktocheck = get_string('clicktocheckcompatibility', 'sloodle'); $strclicktochecknoperm = get_string('clicktocheckcompatibility:nopermission', 'sloodle'); // Do we have a valid plugin type already specified? if (empty($plugintype) || !array_key_exists($plugintype, $availableimporters)) { // No - display a menu to select the desired importer // Sort the list of importers by name natcasesort($availableimporters); // Setup a base link for all importer types $baselink = "{$CFG->wwwroot}/mod/sloodle/view.php?id={$this->cm->id}&mode=importslides"; // Setup a base link for checking compatibility $checklink = "{$CFG->wwwroot}/mod/sloodle/view.php?id={$this->cm->id}&mode=compatibility"; // Make sure this user has site configuration permission, as running this test may reveal sensitive information about server architecture //$module_context = get_context_instance(CONTEXT_MODULE, $this->cm->id); $module_context = context_module::instance($this->cm->id); $cancheckcompatibility = (bool)has_capability('moodle/site:config', $module_context); // Go through each one and display it in a menu $table = new stdClass(); $table->head = array(get_string('name', 'sloodle'), get_string('description'), get_string('compatibility', 'sloodle')); $table->size = array('20%', '70%', '10%'); $table->align = array('center', 'left', 'center'); $table->data = array(); foreach ($availableimporters as $importerident => $importername) { // Get the description of the plugin $plugin = $this->_session->plugins->get_plugin('presenter-importer', $importerident); $desc = $plugin->get_plugin_description(); // Check the compatibility of the plugin $linkclass = ''; $compatibility = ''; if (!$plugin->check_compatibility()) { $linkclass = ' class="dimmed"'; $compatibility = '[ '.$strincompatible.' ]'; } // Construct this line of the table $line = array(); // Add the name of the importer to the table as a link $link = "{$baselink}&sloodleplugintype={$importerident}"; $line[] = "{$importername}