Source for file presenter.php

Documentation is available at presenter.php

  1. <?php
  2. /**
  3. * Defines a class for viewing the SLOODLE Presenter module in Moodle.
  4. * Derived from the module view base class.
  5. *
  6. @package sloodle
  7. @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. @contributor Peter R. Bloomfield
  11. */
  12.  
  13.  
  14. //
  15. // The mode of operation is defined by the "mode" HTTP parameter.
  16. // The available modes are as follows:
  17. //
  18. //  - view = viewing the Presentation (default)
  19. //  - edit = editing the Presentation
  20. //  - editslide = editing a particular slide
  21. //  - addslide = adding a new slide
  22. //  - addfiles = uploading multiple slides
  23. //  - moveslide = moving a slide (part of 'edit' mode)
  24. //  - deleteslide = deleting a particular slide (asking user for confirmation) (part of 'edit' mode)
  25. //  - confirmdeleteslide = user has confirmed they want to delete a slide (part of 'edit' mode)
  26. //  - importslides = add new slides using an importer plugin
  27. //
  28.  
  29.  
  30. /** The base module view class */
  31. require_once(SLOODLE_DIRROOT.'/view/base/base_view_module.php');
  32. /** The SLOODLE Session data structures */
  33. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  34.  
  35. /** ID of the 'view' tab for the Presenter. */
  36. define('SLOODLE_PRESENTER_TAB_VIEW'1);
  37. /** ID of the 'edit' tab for the Presenter */
  38. define('SLOODLE_PRESENTER_TAB_EDIT'2);
  39. /** ID of the 'edit slide' tab for the Presenter */
  40. define('SLOODLE_PRESENTER_TAB_EDIT_SLIDE'3);
  41. /** ID of the 'add slide' tab for the Presenter */
  42. define('SLOODLE_PRESENTER_TAB_ADD_SLIDE'4);
  43. /** ID of the 'bulk upload' tab for the Presenter */
  44. define('SLOODLE_PRESENTER_TAB_ADD_FILES'5);
  45. /** ID of the 'import slides' tab for the Presenter */
  46. define('SLOODLE_PRESENTER_TAB_IMPORT_SLIDES'6);
  47.  
  48.  
  49.  
  50. /**
  51. * Class for rendering a view of a Presenter module in Moodle.
  52. @package sloodle
  53. */
  54. {
  55.     /**
  56.     * A Presenter object (secondary table).
  57.     * @var object 
  58.     * @access private
  59.     */
  60.     var $presenter = null;
  61.    
  62.     /**
  63.     * Our current mode of access to the Presenter.
  64.     * This can be 'view', 'edit', 'editslide', 'bulkupload', 'upload'.
  65.     * NOTE: 'edit' mode is for the presentation as a whole (slide order), while 'editslide' shows the slide editing form.
  66.     * @var string 
  67.     * @access private
  68.     */
  69.     var $presenter_mode = 'view';
  70.     
  71.     /**
  72.     * ID of the entry we are moving.
  73.     * @var int 
  74.     * @access private
  75.     */
  76.     var $movingentryid = 0;
  77.  
  78.     /**
  79.     * A SLOODLE session object to give us access to plugins and other functionality.
  80.     * @var SloodleSession 
  81.     * @access private
  82.     */
  83.     var $_session = null;
  84.     
  85.     /**
  86.     * Stores an optional feedback string which we may pick up from session data.
  87.     * @var string 
  88.     * @access private
  89.     */
  90.     var $feedback = '';
  91.  
  92.     /**
  93.     * Constructor.
  94.     */
  95.     function sloodle_view_presenter()
  96.     {
  97.     }
  98.  
  99.     /**
  100.     * Processes request data to determine which Presenter is being accessed.
  101.     */
  102.     function process_request()
  103.     {
  104.         // Process the basic data
  105.         parent::process_request();
  106.  
  107.         // Grab any feedback left from a previous action
  108.         if (!empty($_SESSION['sloodle_presenter_feedback'])) $this->feedback = $_SESSION['sloodle_presenter_feedback'];
  109.         unset($_SESSION['sloodle_presenter_feedback']);
  110.  
  111.         // Construct a SLOODLE Session and load a module
  112.         $this->_session = new SloodleSession(false);
  113.         $this->presenter = new SloodleModulePresenter($this->_session);
  114.         if (!$this->presenter->load($this->cm->id)) return false;
  115.         $this->_session->module = $this->presenter;
  116.  
  117.         // Load available Presenter plugins
  118.         if (!$this->_session->plugins->load_plugins('presenter')) {
  119.             error('Failed to load Presenter plugins.');
  120.             return false;
  121.         }
  122.     }
  123.  
  124.     
  125.     
  126.     
  127.     
  128.     /**
  129.     * Process any form data which has been submitted.
  130.     */
  131.     function process_form()
  132.     {
  133.         global $CFG;
  134.               
  135.         // Slight hack to put this here. We need to have the permissions checked before we do this.
  136.         // Default to view mode. Only allow other types if the user has sufficient permission
  137.         if ($this->canedit{
  138.             $this->presenter_mode = optional_param('mode''view');
  139.         else {
  140.             $this->presenter_mode = 'view';
  141.         }
  142.         // If we're in moving mode, then grab the entry ID
  143.         if ($this->presenter_mode == 'moveslide'$this->movingentryid = (int)optional_param('entry'0);
  144.  
  145.         // Make sure Moodle includes our JavaScript files if necessary
  146.         if ($this->presenter_mode == 'addfiles' || $this->presenter_mode == 'edit'{
  147.             // Require the jquery javascript files
  148.             require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.js');
  149.             require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.uploadify.js');
  150.             require_js($CFG->wwwroot .'/mod/sloodle/lib/jquery/jquery.checkboxes.js');
  151.             require_js($CFG->wwwroot .'/mod/sloodle/lib/multiplefileupload/extra.js');      
  152.             if ($this->presenter_mode == 'edit'{
  153.                 require_js($CFG->wwwroot .'/lib/filelib.php');      
  154.             }                    
  155.         }
  156.  
  157.  
  158.         // Should we process any incoming editing commands?
  159.         if ($this->canedit{
  160.  
  161.             // We may want to redirect afterwards to prevent an argument showing up in the address bar
  162.             $redirect false;
  163.         
  164.             // Are we attempting to delete an entry?
  165.             if ($this->presenter_mode == 'deleteslide'{
  166.                 // Make sure the session key is specified and valid
  167.                 if (required_param('sesskey'!= sesskey()) {
  168.                     error('Invalid session key');
  169.                     exit();
  170.                 }
  171.                 
  172.                 // Delete the slide
  173.                 $entryid = (int)required_param('entry'PARAM_INT);
  174.                 $this->presenter->delete_entry($entryid);
  175.                 
  176.                 $redirect true;
  177.             }
  178.             
  179.             // Are we relocating an entry?
  180.             if ($this->presenter_mode == 'setslideposition'{
  181.                 $entryid = (int)required_param('entry'PARAM_INT);
  182.                 $position = (int)required_param('position'PARAM_INT);
  183.                 $this->presenter->relocate_entry($entryid$position);
  184.                 
  185.                 $redirect true;
  186.             }
  187.             
  188.             
  189.             
  190.              // Has a new entry been added?
  191.             if (isset($_REQUEST['fileaddentry']||isset($_REQUEST['sloodleaddentry'])) {
  192.                if (isset($_REQUEST['fileaddentry']))
  193.                     $urls $_REQUEST['fileurl'];                    
  194.                     $names =  $_REQUEST['filename']
  195.                     $i 0;                   
  196.                     foreach ($urls as $u){    
  197.                          $fnamelenstrlen($u);
  198.                          $extensionsubstr($u,$fnamelen-4)
  199.                          $ftype strtolower($extension);
  200.                          switch ($ftype){
  201.                             case ".mov"$ftype "video"break;   
  202.                             case ".jpg"$ftype "image"break;
  203.                             case ".png"$ftype "image"break;
  204.                             case ".gif"$ftype "image"break;
  205.                             case ".htm"$ftype "web";   break;
  206.                             case "html"$ftype "web";   break;                              
  207.                          }
  208.                          $this->presenter->add_entry(sloodle_clean_for_db($u)$ftypesloodle_clean_for_db($names[$i++]));                         
  209.                          
  210.                     }     
  211.                }
  212.                if (isset($_REQUEST['sloodleaddentry'])){  
  213.                 if ($_REQUEST['sloodleentryurl']!=''){
  214.                     $sloodleentryurl sloodle_clean_for_db($_REQUEST['sloodleentryurl']);
  215.                     $sloodleentrytype sloodle_clean_for_db($_REQUEST['sloodleentrytype']);
  216.                     $sloodleentryname sloodle_clean_for_db($_REQUEST['sloodleentryname']);
  217.                     $sloodleentryposition = (int)$_REQUEST['sloodleentryposition'];
  218.                     // Store the type in session data for next time we're adding a slide
  219.                     $_SESSION['sloodle_presenter_add_type'$sloodleentrytype;
  220.                     $this->presenter->add_entry($sloodleentryurl$sloodleentrytype$sloodleentryname$sloodleentryposition);
  221.                 }
  222.                
  223.                  $redirect true
  224.             }
  225.             
  226.             
  227.             // Has an existing entry been edited?
  228.             if (isset($_REQUEST['sloodleeditentry'])) {
  229.                 $sloodleentryid = (int)$_REQUEST['sloodleentryid'];
  230.                 $sloodleentryurl sloodle_clean_for_db($_REQUEST['sloodleentryurl']);
  231.                 $sloodleentrytype sloodle_clean_for_db($_REQUEST['sloodleentrytype']);
  232.                 $sloodleentryname sloodle_clean_for_db($_REQUEST['sloodleentryname']);
  233.                 $sloodleentryposition = (int)$_REQUEST['sloodleentryposition'];
  234.  
  235.                 $this->presenter->edit_entry($sloodleentryid$sloodleentryurl$sloodleentrytype$sloodleentryname$sloodleentryposition);
  236.                 $redirect true;
  237.             }
  238.             
  239.             //are we editing multiple files?  Mode: "Multiple edit"" is set as an input value when the multiple edit select field
  240.             // is submitted      
  241.             if (optional_param('mode')=='multiple edit')  {
  242.                 //check what value was submitted from the select input
  243.                 $multipleAction optional_param('multipleProcessor');
  244.                 $selectedSlides $_REQUEST['selectedSlides'];
  245.                 switch ($multipleAction{                    
  246.                     case "multidelete":
  247.                         //get all selected slides to trash                
  248.                         $slides $this->presenter->get_slides();                        
  249.                         $deleted get_string("presenter:deleted",sloodle);
  250.                         $fromTheServer get_string("presenter:fromtheserver",sloodle);
  251.                         $feedback "";
  252.                         foreach ($selectedSlides as $selectedSlide){
  253.                             //get slide source so we can delete it from the server   
  254.                             foreach ($slides as $slide){
  255.                                    if ($slide->id==$selectedSlide){
  256.                                        //delete file
  257.                                          $fileLocation $CFG->dataroot;
  258.                                          //here the $slide->source url has moodle's file.php handler in it
  259.                                          //we must therefore convert the slide source into a real file path
  260.                                          //do so by removing "file.php" from the file path string
  261.                                          $floc strstr($slide->source,"file.php");
  262.                                          //now delete "file.php" from the path
  263.                                          $floc substr($floc,8,strlen($floc));
  264.                                          //now add this to the data route to finish re-creating the true file path
  265.                                          $fileLocation.=$floc;
  266.                                          //finally we can delete the file
  267.                                          unlink($fileLocation);
  268.                                         //build feedback string
  269.                                         $feedback.=$deleted ." "$slide->name ." "$fromTheServer ."<br>";     
  270.                                    }                           
  271.                                }
  272.                                //delete from database
  273.                                $this->presenter->delete_entry($selectedSlide);                                
  274.                         }     
  275.                         // Store the feedback as a session variable for the next time the page is loaded
  276.                         $_SESSION['sloodle_presenter_feedback'$feedback;
  277.                         //set redirect so we go back to the edit tab
  278.                         $redirect true;         
  279.                     break;
  280.  
  281.                     case "none":
  282.                         // User didn't select anything
  283.                     break;
  284.  
  285.                     default:
  286.                          //must be a slide number so we will move the selected slides to the new position
  287.                          //get slide position to move slides to
  288.                          $moveTo = (int)$multipleAction;                                                  
  289.                          if ($moveTo <= 0break// Make sure it's a valid position
  290.                          $i=0;
  291.                          //move each slide to the new position
  292.                          foreach ($selectedSlides as $r{
  293.                             $m $moveTo $i;
  294.                             $this->presenter->relocate_entry($r$moveTo+$i);
  295.                             $i++;
  296.                          }
  297.                          $redirect=true;
  298.                     break;
  299.                     
  300.                 }    
  301.             }
  302.               //$this->presenter->delete_entry()
  303.  
  304.             // Redirect back to self, if possible
  305.             if ($redirect && headers_sent(== false{
  306.                 header("Location: ".SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&mode=edit");
  307.                 exit();
  308.             }
  309.         }            
  310.             
  311.     }
  312.     
  313.     
  314.     /**
  315.     * Render the View of the Presenter.
  316.     * Called from with the {@link render()} function when necessary.
  317.     */
  318.     function render_view()
  319.     {        
  320.         
  321.         //display any feedback
  322.         if (!empty($this->feedback)) echo $this->feedback;
  323.         
  324.           // Get a list of entry slides in this presenter
  325.         $entries $this->presenter->get_slides();
  326.         if (!is_array($entries)) $entries array();
  327.         $numentries count($entries);
  328.         // Open the presentation box
  329.         //print_box_start('generalbox boxaligncenter boxwidthwide');
  330.  
  331.         // Was a specific entry requested? This is the number of entry within the presentation, NOT entry ID.
  332.         // They start at 1 and go up from there within each presentation.
  333.         if (isset($_REQUEST['sloodledisplayentry'])) {
  334.             $displayentrynum = (int)$_REQUEST['sloodledisplayentry'];
  335.             if ($displayentrynum || $displayentrynum $numentries$displayentrynum 1;
  336.         else {
  337.             $displayentrynum 1;
  338.         }
  339.         
  340.         // Do we have any entries to work with?
  341.         if ($numentries 0{
  342.             // Yes - go through them to figure out which entry to display
  343.              $currententry null;
  344.           foreach ($entries as $entryid => $entry{
  345.                 // Check if this is our current entry
  346.               if ($displayentrynum == $entry->slideposition{                  
  347.                     $currententry $entry;
  348.                 }
  349.  
  350.            
  351.             }
  352.     
  353.             // Display the entry header
  354.             echo "<div style=\"text-align:center;\">";
  355.            echo "<h2 id=\"slide\">\"<a href=\"{$currententry->source}\" title=\"".get_string('directlink''sloodle')."\">{$currententry->name}</a>\"</h2>\n";
  356.  
  357.             // Display the presentation controls
  358.             $strof get_string('of''sloodle');
  359.             $strviewprev get_string('viewprev''sloodle');
  360.             $strviewnext get_string('viewnext''sloodle');
  361.             $strviewjumpforward get_string('jumpforward''sloodle');
  362.             $strviewjumpback get_string('jumpback''sloodle');
  363.             echo '<p style="font-size:200%; font-weight:bold;">';
  364.            // if ($displayentrynum > 1) echo "<a href=\"?id={$this->cm->id}&sloodledisplayentry=",$displayentrynum - 1,"#slide\" title=\"{$strviewprev}\">&larr;</a>";
  365.            // else echo "<span style=\"color:#bbbbbb;\">&larr;</span>";
  366.            // echo "&nbsp;{$displayentrynum} {$strof} {$numentries}&nbsp;";
  367.            //  if ($displayentrynum < $numentries) echo "<a href=\"?id={$this->cm->id}&sloodledisplayentry=",$displayentrynum + 1,"#slide\" title=\"{$strviewnext}\">&rarr;</a>";
  368.  
  369.             //else echo "<span style=\"color:#bbbbbb;\">&rarr;</span>";            
  370.             echo "</p>\n";
  371.             
  372.             $entrynumcounter=1;            
  373.             $jumpNumber=5;
  374.             //display >>
  375.             $arrowLinks new stdClass();       
  376.             $arrowLinks->class='texrender';     
  377.             $arrowLinks->size array('40px''40px','40px','40px');
  378.             $arrowLinks->cellpadding='1';
  379.             $arrowLinks->width='500px';
  380.             
  381.             $slideLinksnew stdClass();
  382.             $slideLinks->class='texrender';     
  383.             $slideLinks->size array('20px''20px','20px','20px','20px','20px','20px');
  384.             $slideLinks->cellpadding='1';
  385.             $row array()
  386.             $arow array()
  387.             
  388.             $start $displayentrynum $jumpNumber-1;
  389.             if ($start>=0$arow[]"<a href=\"?id={$this->cm->id}&sloodledisplayentry={$start}#slide\" title=\"{$strviewjumpback} ".$jumpNumber." slides\"><img style=\"vertical-align:middle;\" alt=\"{$strviewjumpback} ".$jumpNumber." slides\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_rewind.gif\" width=\"50\" height=\"50\"></a>"
  390.             else $arow[]="<img style=\"vertical-align:middle;\" alt=\"{$strviewjumpback} ".$jumpNumber." slides\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_rewind.gif\" width=\"50\" height=\"50\">"
  391.             $prev=$displayentrynum-1;
  392.             if ($displayentrynum>=2$arow[]"<a href=\"?id={$this->cm->id}&sloodledisplayentry={$prev}#slide\" title=\"{$strviewprev}\"><img alt=\"{$strviewprev}\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_prev.gif\" width=\"40\" height=\"40\"></a>  "
  393.             else $arow[]"<img alt=\"{$strviewprev}\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_prev.gif\" width=\"40\" height=\"40\">"
  394.             
  395.             // display hyperlinks for each slide
  396.             $row="<table width='400px'><tr>";
  397.             foreach ($entries as $entryid => $entry{
  398.                 //get start and end slides                 
  399.                 $start $displayentrynum $jumpNumber;
  400.                 if ($start<0$start =0;
  401.                 $end $displayentrynum $jumpNumber;
  402.                 if ($end>$numentries$end =$numentries;
  403.                 if (($entrynumcounter >= $start)&& ($entrynumcounter<=$end)){
  404.                     if ($entrynumcounter==$displayentrynum$row.= "<td style=\"font-weight:bold; font-size:larger;\">"."<a href=\"?id={$this->cm->id}&sloodledisplayentry=".$entrynumcounter."#slide\" title=\"{$entry->name}\">{$entrynumcounter}</a></td>";
  405.                     else $row.= "<td><a href=\"?id={$this->cm->id}&sloodledisplayentry=".$entrynumcounter."#slide\" title=\"{$entry->name}\">{$entrynumcounter}</td>";
  406.                 }
  407.                 $entrynumcounter++;
  408.             }
  409.             $row.="</tr></table>";
  410.             $arow[]=$row;
  411.             $end $displayentrynum $jumpNumber+1;
  412.             $next=$displayentrynum+1;
  413.             
  414.             if ($displayentrynum+<=$numentries$arow[]"<a href=\"?id={$this->cm->id}&sloodledisplayentry={$next}#slide\" title=\"{$strviewnext}\"><img alt=\"{$strviewnext}\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_next.gif\" width=\"40\" height=\"40\"></a>  "
  415.             else $arow[]="<img alt=\"{$strviewnext}\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/greycons_next.gif\" width=\"40\" height=\"40\">"
  416.             if ($end<=$numentries$arow[]"<a href=\"?id={$this->cm->id}&sloodledisplayentry=".$end."#slide\" title=\"{$strviewjumpforward} ".$jumpNumber." slides\"><img alt=\"{$strviewjumpforward} ".$jumpNumber."\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/bluecons_fastforward.gif\" width=\"50\" height=\"50\"></a>  "
  417.             else $arow[]="<img alt=\"{$strviewjumpforward} ".$jumpNumber."\" style=\"vertical-align:middle;\" src=\"".SLOODLE_WWWROOT."/lib/media/greycons_fastforward.gif\" width=\"50\" height=\"50\">"
  418.             
  419.             
  420.             //$slideLinks->data[]=$row;
  421.             $arrowLinks->data[]=$arow;
  422.             
  423.             print_table($arrowLinks)
  424.             echo "<br><br>";
  425.             // Get the frame dimensions for this Presenter
  426.             $framewidth $this->presenter->get_frame_width();
  427.             $frameheight $this->presenter->get_frame_height();            
  428.  
  429.             // Get the plugin for this slide
  430.             $slideplugin $this->_session->plugins->get_plugin($currententry->type);
  431.             if ($slideplugin{
  432.                 // Render the content for the web
  433.                 echo $slideplugin->render_slide_for_browser($currententry);
  434.             else {
  435.                 echo '<p style="font-size:150%; font-weight:bold; color:#880000;">',get_string('unknowntype','sloodle'),': '$currententry->type'</p>';
  436.             }
  437.             
  438.  
  439.             // Display a direct link to the media
  440.             echo "<p>";
  441.            print_string('trydirectlink''sloodle'$currententry->source);
  442.             echo "</p>\n";
  443.             echo "</div>";
  444.     
  445.         else {
  446.             echo '<h4>'.get_string('presenter:empty''sloodle').'</h4>';
  447.              if ($this->caneditecho '<p>'.get_string('presenter:clickaddslide''sloodle').'</p>';
  448.         }
  449.  
  450.         
  451.     }
  452.  
  453.     /**
  454.     * Render the Edit mode of the Presenter (lists all the slides and allows re-ordering).
  455.     * Called from with the {@link render()} function when necessary.
  456.     */
  457.     function render_edit()
  458.     {
  459.         //display any feedback
  460.         if (!empty($this->feedback)) echo $this->feedback;
  461.  
  462.         global $CFG;      
  463.         $streditpresenter get_string('presenter:edit''sloodle');
  464.         $strviewanddelete get_string('presenter:viewanddelete''sloodle');
  465.         $strnoentries get_string('noentries''sloodle');
  466.         $strnoslides get_string('presenter:empty''sloodle');
  467.         $strdelete get_string('delete''sloodle');
  468.         $stradd get_string('presenter:add''sloodle');
  469.         $straddatend get_string('presenter:addatend''sloodle');
  470.         $straddbefore get_string('presenter:addbefore''sloodle');
  471.         $strtype get_string('type''sloodle');
  472.         $strurl get_string('url''sloodle');
  473.         $strname get_string('name''sloodle');
  474.         
  475.         $stryes get_string('yes');
  476.         $strno get_string('no');
  477.         
  478.         $strmove get_string('move');
  479.         $stredit get_string('edit''sloodle');
  480.         $strview get_string('view''sloodle');
  481.         $strdelete get_string('delete');
  482.         
  483.         $strmoveslide get_string('presenter:moveslide''sloodle');
  484.         $streditslide get_string('presenter:editslide''sloodle');
  485.         $strviewslide get_string('presenter:viewslide''sloodle');
  486.         $strdeleteslide get_string('presenter:deleteslide''sloodle');
  487.         
  488.          // Get a list of entry URLs
  489.         $entries $this->presenter->get_slides();
  490.         if (!is_array($entries)) $entries array();
  491.         $numentries count($entries);
  492.         // Any images to display?
  493.         if ($entries === false || count($entries== 0{
  494.             echo '<h4>'.$strnoslides.'</h4>';
  495.             echo '<h4><a href="'.SLOODLE_WWWROOT.'/view.php?id='.$this->cm->id.'&amp;mode=addslide">'.$stradd.'</a></h4><br>';
  496.         else {
  497.         
  498.             // Are we being asked to confirm the deletion of a slide?
  499.             if ($this->presenter_mode == 'confirmdeleteslide'{
  500.                 // Make sure the session key is specified and valid
  501.                 if (required_param('sesskey'!= sesskey()) {
  502.                     error('Invalid session key');
  503.                     exit();
  504.                 }
  505.                 // Determine which slide is being deleted
  506.                 $entryid = (int)required_param('entry'PARAM_INT);
  507.                 
  508.                 // Make sure the specified entry is recognised
  509.                 if (isset($entries[$entryid])) {
  510.                     // Construct our links
  511.                     $linkYes SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=deleteslide&amp;entry={$entryid}&amp;sesskey=".sesskey();
  512.                     $linkNo SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=edit";
  513.     
  514.  
  515.                     // Output our confirmation form
  516.                     notice_yesno(get_string('presenter:confirmdelete''sloodle'$entries[$entryid]->name)$linkYes$linkNo);
  517.                     echo "<br/>";
  518.                 }
  519.             }
  520.             
  521.             // Are we currently moving a slide?
  522.             if ($this->presenter_mode == 'moveslide'{
  523.               
  524.                 $linkCancel SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=edit";
  525.                 $strcancel get_string('cancel');
  526.                 // Display a message and an optional 'cancel' link
  527.                 print_box_start('generalbox''notice');
  528.                 echo "<p>"get_string('presenter:movingslide''sloodle'$entries[$this->movingentryid]->name)"</p>\n";
  529.                 echo "<p>(<a href=\"{$linkCancel}\">{$strcancel}</a>)</p>\n";
  530.                 print_box_end();
  531.             }
  532.         
  533.             // Setup a table object to display Presenter entries
  534.             $entriesTable new stdClass();
  535.             $entriesTable->head array(get_string('position''sloodle'),'<div id="selectboxes"><a href="#"><div style=\'text-align:center;\' id="selectall">Select All</div><div style=\'text-align:center;\' id="unselectall">Unselect All</div></a></div>'get_string('name''sloodle')get_string('type''sloodle')get_string('actions''sloodle'));
  536.             $entriesTable->align array('center''center''left''left''center');
  537.             $entriesTable->size array('5%''5%''30%''20%''30%');
  538.             
  539.             // Go through each entry
  540.             $numentries count($entries);
  541.               foreach ($entries as $entryid => $entry{
  542.                 // Create a new row for the table
  543.                 $row array();
  544.                 
  545.                 // Extract the entry data
  546.                 $slideplugin $this->_session->plugins->get_plugin($entry->type);
  547.                 if ($slideplugin$entrytypename $slideplugin->get_plugin_name();
  548.                 else $entrytypename '(unknown type)';
  549.                 // Construct the link to the entry source
  550.                 $entrylink "<a href=\"{$entry->source}\" title=\"{$entry->source}\">{$entry->name}</a>";
  551.                 // If this is the slide being moved, then completely ignore iti
  552.                 if ($this->movingentryid == $entryid{
  553.                     continue;
  554.                 }
  555.                 
  556.     
  557.                 // If we are in move mode, then add a 'move here' row before this slide
  558.                 if ($this->presenter_mode == 'moveslide'
  559.                     $movelink SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=setslideposition&amp;entry={$this->movingentryid}&amp;position={$entry->slideposition}";
  560.                     $movebutton = "<a href=\"{$movelink}\" title=\"{$strmove}\"><img src=\"{$CFG->pixpath}/movehere.gif\" class=\"\" alt=\"{$strmove}\" /></a>\n";
  561.                     $entriesTable->data[array(''''$movebutton'''''');
  562.  
  563.                     // If the current row belongs to the slide being moved, then emphasise it, and append (moving) to the end
  564.                      if ($entryid == $this->movingentryid$entrylink "<strong>{$entrylink}</strong> <em>(".get_string('moving','sloodle').')</em>';
  565.                 }
  566.                 
  567.                 // Define our action links
  568.                 $actionBaseLink = SLOODLE_WWWROOT."/view.php?id={$this->cm->id}";
  569.                 $actionLinkMove = $actionBaseLink."&amp;mode=moveslide&amp;entry={$entryid}";
  570.                 $actionLinkEdit = $actionBaseLink."&amp;mode=editslide&amp;entry={$entryid}";
  571.                 $actionLinkView = $actionBaseLink."&amp;mode=view&amp;sloodledisplayentry={$entry->slideposition}#slide";
  572.                 $actionLinkDelete = $actionBaseLink."&amp;mode=confirmdeleteslide&amp;entry={$entryid}&amp;sesskey=".sesskey();
  573.                 
  574.                
  575.                 // Prepare the add buttons separately
  576.                 $actionLinkAdd = $actionBaseLink."&amp;mode=addslide&amp;sloodleentryposition={$entry->slideposition}";
  577.                 $addButtons = "<a href=\"{$actionLinkAdd}\" title=\"{$straddbefore}\"><img src=\"".SLOODLE_WWWROOT."/lib/media/add.png\" alt=\"{$stradd}\" /></a>\n";
  578.                 
  579.                 // Construct our list of action buttons
  580.                 $actionButtons = '';
  581.                 $actionButtons .= "<a href=\"{$actionLinkMove}\" title=\"{$strmoveslide}\"><img src=\"{$CFG->pixpath}/t/move.gif\" class=\"iconsmall\" alt=\"{$strmove}\" /></a>\n";
  582.                 $actionButtons .= "<a href=\"{$actionLinkEdit}\" title=\"{$streditslide}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" class=\"iconsmall\" alt=\"{$stredit}\" /></a>\n";
  583.                 $actionButtons .= "<a href=\"{$actionLinkView}\" title=\"{$strviewslide}\"><img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strview}\" /></a>\n";
  584.                 $actionButtons .= "<a href=\"{$actionLinkDelete}\" title=\"{$strdeleteslide}\"><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>\n";
  585.                 $actionButtons .= $addButtons;
  586.  
  587.                
  588.                 //create checkbox for multiple edit functions
  589.                 $checkbox = "<div style='text-align:center;'><input  type=\"checkbox\" name=\"selectedSlides[]\" value=\"{$entryid}\" /></div>";
  590.                 // Add each item of data to our table row.
  591.                 //the first item is a check box for multiple deletes
  592.                 // The second items are the position and the name of the entry, hyperlinked to the resource.
  593.                 // The next is the name of the entry type.
  594.                 // The last is a list of action buttons -- move, edit, view, and delete.
  595.                 
  596.                 $row[] = $entry->slideposition;
  597.                 $row[$checkbox;  
  598.                 $row[$entrylink;
  599.                 $row[$entrytypename;
  600.                 $row[$actionButtons;
  601.                 
  602.                 
  603.                 // Add the row to our table
  604.                 $entriesTable->data[$row;
  605.             }
  606.               
  607.             
  608.             // If we are in move mode, then add a final 'move here' row at the bottom
  609.   // We need to add a final row at the bottom
  610.             // Prepare the action link for this row
  611.             $endentrynum = $entry->slideposition 1;
  612.             $actionLinkAdd $actionBaseLink."&amp;mode=addslide&amp;sloodleentryposition={$endentrynum}";
  613.             $addButtons = "<a href=\"{$actionLinkAdd}\" title=\"{$straddatend}\"><img src=\"".SLOODLE_WWWROOT."/lib/media/add.png\" alt=\"{$stradd}\" /></a>\n";
  614.             $sloodleInsert = get_string("presenter:sloodleinsert","sloodle");
  615.             // It will contain a last 'add' button, and possibly a 'move here' button too (if we are in move mode)
  616.             $movebutton = '';
  617.             if ($this->presenter_mode == 'moveslide'{
  618.                 $movelink = SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=setslideposition&amp;entry={$this->movingentryid}&amp;position={$endentrynum}";
  619.                 $movebutton = "<a href=\"{$movelink}\" title=\"{$strmove}\"><img src=\"{$CFG->pixpath}/movehere.gif\" class=\"\" alt=\"{$strmove}\" /></a>\n";
  620.             }
  621.             //display drop down box with options to actions on a group of slides
  622.                 //build options list for multi action select box
  623.                 //with Selected is used as a UI element so user knows what this select is for
  624.                 $optionList ='<option value="none">     With Selected  </option>';    
  625.                 //add multiple delete option
  626.                 $optionList.='<option value="multidelete">*** DELETE SELECTED ***</option>';    
  627.                 //add options for each slide position
  628.                 foreach ($entries as $curentryid => $curentry) {
  629.                       // Add this entry to the list
  630.                       $optionList.= "<option value=\"{$curentry->slideposition}\"";              
  631.                       $optionList.=">{$sloodleInsert} {$curentry->slideposition}</option>\n"; 
  632.                 }
  633.                 //create select input
  634.                 $selectInput = "<select name='multipleProcessor' id='multipleProcessor'>{$optionList}</select>";
  635.                 //add a submit button
  636.                 $selectInput .= "    <input type='submit' id='Go' name='Go' value='Go'>";                   
  637.                 //add select input to table
  638.                 $entriesTable->data[array('',$movebutton ' <div id="selectboxes2"><a href="#"><div style=\'text-align:center;\' id="selectall2">Select All</div><div style=\'text-align:center;\' id="unselectall2">Unselect All</div></a></div>',$selectInput''$addButtons);
  639.                 //encase in a form
  640.                 echo '<form action="" ,method="POST" id="editform" name="editform">';
  641.                 print_table($entriesTable);
  642.                 //add course module id so moodle knows what to do with this post
  643.                 echo "<input type=\"hidden\" name=\"id\" value=\"{$this->cm->id}\" />";
  644.                 //set the mode for multiple edit so process_form knows what to do
  645.                 echo "<input type=\"hidden\" name=\"mode\" value=\"multiple edit\" />";
  646.                 echo '</form>';                
  647.            
  648.         }
  649.         
  650.     }
  651.     
  652.     /**
  653.     * Render the slide editing form of the Presenter (lets you edit a single slide).
  654.     * Called from with the {@link render()} function when necessary.
  655.     */        
  656.     function render_add_files()
  657.     {
  658.         global $CFG;
  659.  
  660.  
  661.  
  662.         // Setup variables to store the data
  663.         $entryid = 0;
  664.         $entryname = '';
  665.         $entryurl = '';
  666.         $entrytype = '';
  667.  
  668.         // Fetch a list of existing slides
  669.         $entries = $this->presenter->get_entry_urls();
  670.         // Check what position we are adding the new slide to
  671.         // (default to negative, which puts it at the end)
  672.         $position = (int)optional_param('sloodleentryposition''-1'PARAM_INT);
  673.  
  674.       
  675.         // Fetch our translation strings
  676.         $streditpresenter get_string('presenter:edit''sloodle');
  677.         $strviewanddelete get_string('presenter:viewanddelete''sloodle');
  678.         $strnoentries get_string('noentries''sloodle');
  679.         $strdelete get_string('delete''sloodle');
  680.         $strBulkUpload get_string('presenter:bulkupload''sloodle');
  681.         $stradd get_string('presenter:addfiles''sloodle');
  682.         $strtype get_string('type''sloodle');
  683.         $strurl get_string('url''sloodle');
  684.         $strname get_string('name''sloodle');
  685.         $strposition get_string('position''sloodle');
  686.         $strsave get_string('save''sloodle');
  687.         $strend get_string('end''sloodle');
  688.         
  689.         $stryes get_string('yes');
  690.         $strno get_string('no');
  691.         $strcancel get_string('cancel');
  692.         
  693.         $strmove get_string('move');
  694.         $stredit get_string('edit''sloodle');
  695.         $strview get_string('view''sloodle');
  696.         $strdelete get_string('delete');
  697.  
  698.         // Construct an array of available entry types, associating the identifier to the humand-readable name.
  699.         // In future, this will be built from a list of plugins, but for now we'll hard code it.
  700.         $availabletypes array();
  701.         $availabletypes['image'get_string('presenter:type:image','sloodle');
  702.         $availabletypes['video'get_string('presenter:type:video','sloodle');
  703.         $availabletypes['web'get_string('presenter:type:web','sloodle');
  704.         //display instructions
  705.         echo get_string('presenter:uploadInstructions','sloodle');
  706.         // We'll post the data straight back to this page
  707.         echo '<form action="" method="post"><fieldset style="border-style:none;">';
  708.         
  709.         
  710.         // Identify the module
  711.     
  712.     /*
  713.     * Uploadify Multiple File uploader added by Paul Preibisch
  714.     * @see http://www.uploadify.com/documentation
  715.     * 
  716.     * @var uploadWwwDir         - place to store files
  717.     * @var uploadArray[]          - array to hold complete file names  
  718.     * @var extension            - temp var to hold extension type of current file
  719.     * @var tableData            - used to construct table rows
  720.     * @uses upload.php          - upload.php is the upload handler script
  721.     * @uses uploader.swf        - enables multiple file uploading     
  722.     */   
  723.     echo '<script type="text/javascript">';                                                           
  724.     echo 'var uploadWwwDir="'.$CFG->wwwroot.'/file.php/1/presenter/'.$this->cm->id.'/";';
  725.     echo ' var uploadArray = [];';
  726.     echo ' var qSize=0;';
  727.     echo 'var uploadLimit='.((integer)INI_GET('post_max_size')*1000000).';';
  728.  
  729.     echo ' var uploadArrayLen=0;';
  730.     echo ' var counter=0;';
  731.     echo ' var extension=\'\';';  
  732.     echo ' var tableData=\'\';';
  733.     
  734.     ?>
  735.     function startUpload(id){  ;
  736.         if (qSize < uploadLimit)
  737.             $('#fileInput').fileUploadStart();
  738.     }        <?php
  739.     // when DOM is fully loaded, JQuery ready function executes our code     
  740.     echo '$(document).ready(function() {';
  741.          
  742.         echo '$("#uploadButton").hide();';
  743.        echo '$(\'#fileInput\').fileUpload ({';       
  744.         echo "'uploader'  : 'lib/multiplefileupload/uploader.swf',";        
  745.         echo "'script'    : 'lib/multiplefileupload/upload.php',";
  746.          //sends moduleID:cm->id to upload.php upload handler
  747.         echo "'scriptData' : {'moduleId':'".$this->cm->id."'},";
  748.         //enable multiple uploads 
  749.         echo "'multi'     :  true,";
  750.         //set cancel button image
  751.         echo "'cancelImg' : 'lib/multiplefileupload/cancel.png',";
  752.         //set button text
  753.         echo "'buttonText': 'Select Files',";
  754.         //start uploading automatically after items are selected            
  755.         echo "'auto'      : false,";
  756.         //this folder variable is required, but in our case, not used because we set the upload folder in the upload.php upload handler
  757.         echo "'folder'    : 'uploads',";
  758.         //allowable file types (must also modify upload.php upload handler to accept these)
  759.         echo "'fileDesc'  : 'jpg;png;gif;htm;html;mov',";
  760.         //the allowable extensions in the file dialog view
  761.         echo "'fileExt'   :   '*.jpg;*.png;*.gif;*.htm;*.html;*.mov',";
  762.         //Send an alert on all errors
  763.         ?>onError: function (a, b, c, d) {
  764.          if (d.status == 404)
  765.             alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
  766.          else if (d.type === "HTTP")
  767.             alert('error '+d.type+": "+d.status);
  768.          else if (d.type ==="File Size")
  769.             alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
  770.          else
  771.             alert('error '+d.type+": "+d.text);
  772. },        <?php
  773.         /*
  774.         * onAllComplete will trigger after all uploads are done
  775.         * When all uploaded, sort file names into alphabetical order
  776.         * 
  777.         */
  778.         echo "'onAllComplete': function() {";
  779.         //Files could have uploaded in a random order, therefore, lets sort the array of file names and display them alphabetically 
  780.         echo "uploadArray.sort();";  
  781.         //bind a variable fileDisplayArea to the tag <div id="filesUploaded"> so we can refer to it easily
  782.         echo 'var fileDisplayArea = $("#filesUploaded");';
  783.         //now append another div tag inside of it called fileTables - here we will put all fields for each item uploaded
  784.         //<dif id="fileTables></div> is necessary because everytime the user presses Select files button, we must delete all elements in the div and redisplay so that all items are sorted properly
  785.         echo 'fileDisplayArea.append($ (\'<div id="fileTables"></div>\'));';       
  786.         //bind a variable fileTables to the tag <div id="fileTables"> so we can refer to it easily
  787.         echo 'var jList = $( "#fileTables" );';   
  788.         //iterate through all files uploaded
  789.         echo '$.each(uploadArray,';
  790.         echo 'function( intIndex, objValue ){';
  791.               //get the extension of the uploaded file             
  792.               echo 'var start = objValue.length-4;';                                     
  793.               echo 'extension=objValue.substr(start,4);';
  794.               echo 'extension=extension.toLowerCase();';   
  795.               echo  'var fname = objValue.substr(0,objValue.length-4);';       
  796.              //Construct the Name row
  797.              //replace all spaces with underscores
  798.              echo  'tableData= \'<table ><tr><td width=100>Name:</td><td> <input type="text" id="filename"  name="filename[]" value="\'+fname.replace(\' \(\',\'_\(\').replace(\'\) \',\'\)_\').replace(\' \',\'_\').replace(\' \',\'_\')+\'" size="60" maxlength="255" /></td><td width="100">\';';                         
  799.              //Construct the Image row if this file is an image
  800.              echo 'if ((extension==\'.jpg\') || (extension==\'.gif\') || (extension==\'.png\')) {';                        
  801.                        echo 'tableData += \'<label>Type:</label><select name="ftype[]" id="type" size="1"><option name=""  value="">image</option></select></td></tr></table>\';';                                   
  802.                        echo 'tableData += \'<table ><tr><td><img src="\'+uploadWwwDir+objValue.replace(\' \(\',\'_\(\').replace(\'\) \',\'\)_\').replace(\' \',\'_\')+\'" width="100" height="100"></td></tr></table>\';';                           
  803.             echo  '}';
  804.             //Construct movie row if this is a movie
  805.             echo ' else if (extension==\'.mov\') {';
  806.                        echo 'tableData+=  \'<label>Type:</label><select name="" id="type" size="1"><option name="" value="">video</option></select></td></tr></table>\';';          
  807.                        //quicktime embed tag added
  808.                        //replace all spaces with underscores
  809.                        echo 'tableData += \'<table ><tr><td><embed src="\'+uploadWwwDir+objValue.replace(\' \(\',\'_\(\').replace(\'\) \',\'\)_\').replace(\' \',\'_\')+\'" width="100" height="100" autohref="false"></td></tr></table>\'';                       
  810.             echo  '}';
  811.             //Construct movie row if this is an htm or html page            
  812.             echo ' else if ((extension==\'.htm\') ||(extension==\'html\'))  {';
  813.                         echo 'tableData+= \'<label>Type:</label><select name="" id="type" size="1"><option name=""   value="">web</option></select></td></tr></table>\';';            
  814.             echo  '}'
  815.             //Now add the constructed row (tableData) to the list of fields                         
  816.             echo 'tableData+=\'<table ><tr><td width=100>Url:</td><td><input type="text"  id="fileurl" name="fileurl[]" value="\'+uploadWwwDir+objValue.replace(\' \(\',\'_\(\').replace(\'\) \',\'\)_\').replace(\' \',\'_\').replace(\' \',\'_\')+\'" size="60" maxlength="255" /></td></tr></table><HR>\';';                                                
  817.             //insert the table data into <div id="fileTables"></div>
  818.             echo 'jList.append($ (tableData));';
  819.             
  820.             
  821.             
  822.        echo ' });';                     
  823.             //insert a submit button into <div id="fileTables"></div>
  824.             echo  'jList.append($ (\'<input type="submit" value="'.$stradd.'" name="fileaddentry" />\'));';
  825.             echo ' $("#uploadButton").hide();';
  826.             echo ' $("#qSize").hide();';  
  827.             echo 'qSize=0;';
  828.         echo ' },';
  829.         ?>
  830.                 'onSelect': function (event,queueID,fileObj){
  831.                    $("#qSize").show();
  832.               qSize += fileObj.size;
  833.                if (qSize > uploadLimit){
  834.                  $("#uploadButton").hide();
  835.                  $("#qSize").css("color","red");
  836.                  $("#qSize").text("Error: You have selected "+qSize+ " bytes to upload. Bulk upload size is limited to: "+uploadLimit);
  837.               } else 
  838.               { 
  839.                 $("#uploadButton").show();
  840.                 $("#qSize").css("color","blue");
  841.                 $("#qSize").html(qSize+" bytes selected. <b>"+(uploadLimit-qSize) + "</b> bytes available to queue");
  842.               }
  843.  
  844.         
  845.         },
  846.         
  847.                'onCancel': function (event,queueID,fileObj){
  848.               qSize -= fileObj.size;
  849.               
  850.               if (qSize > uploadLimit){
  851.                 $("#uploadButton").hide();
  852.                 $("#qSize").css("color","red");
  853.                 $("#qSize").text("Error: You have selected "+qSize+ " bytes to upload. Bulk upload size is limited to: "+uploadLimit);
  854.               } else 
  855.               { 
  856.                 $("#uploadButton").show();
  857.                 $("#qSize").css("color","blue");
  858.                 $("#qSize").html(qSize+" bytes selected. <b>"+(uploadLimit-qSize) + "</b> bytes available to queue");
  859.               }
  860.               
  861.         
  862.         },
  863.         <?php
  864.         /*
  865.         * onComplete will trigger after each upload is done
  866.         * When a file is uploaded, add it to the uploadArray array
  867.         * 
  868.         */  
  869.          echo "'onComplete': function(event, queueID, fileObj, response, data) {";
  870.          // add this file to our uploadArray            
  871.            echo "uploadArray[uploadArrayLen]=fileObj.name;";                                
  872.            echo "uploadArrayLen++;";         
  873.            //clear the fileTables div so we can re-display all files in proper order           
  874.            echo "$('#fileTables').remove();";  
  875.            echo "}   ";
  876.         echo" });   });";     
  877.         echo "</script>";
  878.                  
  879.         echo '<input type="file" name="fileInput" id="fileInput" />';
  880.         //this div is where the uploaded files will be displayed
  881.         echo '<div name="filesUploaded" id="filesUploaded"><div name="fileTables" id="fileTables"></div></div>';             
  882.         echo '<div name="qSize" id="qSize"></div></fieldset>';          
  883.         echo '<div style="display:none;" name="uploadButton" id="uploadButton"><a href="javascript:startUpload(\'fileUpload\')">Start Upload</a></div></form>';
  884.         // Add a button to let us cancel and go back to the main edit tab
  885.         echo '<form action="" method="get"><fieldset style="border-style:none;">';
  886.         echo "<input type=\"hidden\" name=\"id\" value=\"{$this->cm->id}\" />";
  887.         echo "<input type=\"hidden\" name=\"mode\" value=\"edit\" />";
  888.         echo "<input type=\"submit\" value=\"{$strcancel}\" />";        
  889.         echo '</fieldset></form>';   
  890.         
  891.  
  892.     }         
  893.     /**
  894.     * Render the slide editing form of the Presenter (lets you edit a single slide).
  895.     * Called from with the {@link render()} function when necessary.
  896.     */
  897.     function render_slide_edit()
  898.     {
  899.         // Setup variables to store the data
  900.         $entryid = 0;
  901.         $entryname = '';
  902.         $entryurl = '';
  903.         $entrytype = '';
  904.         // Fetch a list of existing slides
  905.         $entries = $this->presenter->get_slides();
  906.         // Check what position we are adding the new slide to
  907.         // (default to negative, which puts it at the end)
  908.         $position = (int)optional_param('sloodleentryposition''-1'PARAM_INT);
  909.  
  910.         // Are we adding a slide, or editing one?
  911.         $newslide false;
  912.         if ($this->presenter_mode == 'addslide'{
  913.             // Adding a new slide
  914.             $newslide = true;
  915.             // Grab the last added type from session data
  916.             if (isset($_SESSION['sloodle_presenter_add_type'])) $entrytype = $_SESSION['sloodle_presenter_add_type'];
  917.  
  918.         } else {
  919.             // Editing an existing slide
  920.             $entryid = (int)required_param('entry', PARAM_INT);
  921.             // Fetch the slide details
  922.             if (!isset($entries[$entryid])) {
  923.                 error("Cannot find entry {$entryid} in the database.");
  924.                 exit();
  925.             }
  926.            $entryurl = $entries[$entryid]->source;
  927.            $entrytype $entries[$entryid]->type;
  928.            $entryname $entries[$entryid]->name;
  929.         }
  930.         // Fetch our translation strings
  931.         $streditpresenter = get_string('presenter:edit', 'sloodle');
  932.         $strviewanddelete = get_string('presenter:viewanddelete', 'sloodle');
  933.         $strnoentries = get_string('noentries', 'sloodle');
  934.         $strdelete = get_string('delete', 'sloodle');
  935.         $stradd = get_string('presenter:add', 'sloodle');
  936.         $strtype = get_string('type', 'sloodle');
  937.         $strurl = get_string('url', 'sloodle');
  938.         $strname = get_string('name', 'sloodle');
  939.         $strposition = get_string('position', 'sloodle');
  940.         $strsave = get_string('save', 'sloodle');
  941.         $strend = get_string('end', 'sloodle');
  942.         
  943.         $stryes = get_string('yes');
  944.         $strno = get_string('no');
  945.         $strcancel = get_string('cancel');
  946.         
  947.         $strmove = get_string('move');
  948.         $stredit = get_string('edit', 'sloodle');
  949.         $strview = get_string('view', 'sloodle');
  950.         $strdelete = get_string('delete');
  951.  
  952.         // Construct an array of available entry types, associating the identifier to the human-readable name.
  953.         $availabletypes = array();
  954.         $pluginnames = $this->_session->plugins->get_plugin_names('SloodlePluginBasePresenterSlide');
  955.         if (!$pluginnamesexit('Failed to query for SLOODLE Presenter slide plugins.');
  956.         foreach ($pluginnames as $pluginname{
  957.             // Fetch the plugin and store its human-readable name
  958.             $plugin = $this->_session->plugins->get_plugin($pluginname);
  959.             $availabletypes[$pluginname$plugin->get_plugin_name();
  960.         }       
  961.         // We'll post the data straight back to this page
  962.         echo '<form action="" method="post"><fieldset style="border-style:none;">';
  963.         // Identify the module
  964.         echo "<input type=\"hidden\" name=\"id\" value=\"{$this->cm->id}\" />";
  965.         // Identify the entry being edited, if appropriate
  966.         if (!$newslide) echo "<input type=\"hidden\" name=\"sloodleentryid\" value=\"{$entryid}\" />";
  967.         // Add boxes for the URL and name of the entry
  968.         echo '<label for="sloodleentryname">'.$strname.': </label> <input type="text" id="sloodleentryname" name="sloodleentryname" value="'.$entryname.'" size="100" maxlength="255" /><br/><br/>'; 
  969.         echo '<label for="sloodleentryurl">'.$strurl.': </label> <input type="text" id="sloodleentryurl" name="sloodleentryurl" value="'.$entryurl.'" size="100" maxlength="255" /><br/><br/>'; 
  970.         // Add a selection box for the entry type
  971.         echo '<label for="sloodleentrytype">'.$strtype.': </label> <select name="sloodleentrytype" id="sloodleentrytype" size="1">';
  972.         foreach ($availabletypes as $typeident => $typename) {
  973.             echo "<option value=\"{$typeident}\"";
  974.             if ($typeident == $entrytype) echo " selected=\"selected\"";
  975.             echo ">{$typename}</option>";
  976.         }
  977.         echo '</select><br/><br/>';
  978.  
  979.         // Add a selection box to let the user change the position of the entry
  980.         echo '<label for="sloodleentryposition">'.$strposition.': </label> <select name="sloodleentryposition" id="sloodleentryposition" size="1">'."\n";
  981.         $selected = false;
  982.         foreach ($entries as $curentryid => $curentry) {
  983.             // Add this entry to the list
  984.             echo "<option value=\"{$curentry->slideposition}\"";
  985.             if ($curentry->slideposition == $position || $curentryid == $entryid{
  986.                 echo ' selected="selected"';
  987.                 $selected = true;
  988.             }
  989.             echo ">{$curentry->slideposition}: {$curentry->name}</option>\n";
  990.         }
  991.         // Add an 'end' option so that the entry can be placed at the end of the presentation
  992.         $endentrynum = $curentry->slideposition 1;
  993.         echo "<option value=\"{$endentrynum}\"";
  994.         if (!$selected) echo " selected=\"selected\"";
  995.         echo ">--{$strend}--</option>\n";
  996.         echo "</select><br/><br/>\n";
  997.  
  998.         // Display an appropriate submit button
  999.         if ($newslide) echo ' <input type="submit" value="'.$stradd.'" name="sloodleaddentry" />';
  1000.         else echo ' <input type="submit" value="'.$strsave.'" name="sloodleeditentry" />';
  1001.         // Close the form
  1002.         echo '</fieldset></form>';
  1003.  
  1004.         // Add a button to let us cancel and go back to the main edit tab
  1005.         echo '<form action="" method="get"><fieldset style="border-style:none;">';
  1006.         echo "<input type=\"hidden\" name=\"id\" value=\"{$this->cm->id}\" />";
  1007.         echo "<input type=\"hidden\" name=\"mode\" value=\"edit\" />";
  1008.         echo "<input type=\"submit\" value=\"{$strcancel}\" />";
  1009.         echo '</fieldset></form>'; 
  1010.     }
  1011.  
  1012.  
  1013.     /**
  1014.     * Render the tab for importing slides from some source.
  1015.     * If necessary, this will first display a form letting the user select which importer to use.
  1016.     * It will then rely on the plugin to sort out everything else.
  1017.     */
  1018.     function render_import_slides()
  1019.     {
  1020.         global $CFG;
  1021.  
  1022.         // Construct an array of available importers, associating the identifier to the human-readable name.
  1023.         $availableimporters = array();
  1024.         $pluginnames = $this->_session->plugins->get_plugin_names('SloodlePluginBasePresenterImporter');
  1025.         if (!$pluginnameserror('Failed to load any SLOODLE Presenter importer plugins. Please check your plugins folder.');
  1026.         foreach ($pluginnames as $pluginname{
  1027.             // Fetch the plugin and store its human-readable name
  1028.             $plugin = $this->_session->plugins->get_plugin($pluginname);
  1029.             $availableimporters[$pluginname$plugin->get_plugin_name();
  1030.         }
  1031.  
  1032.         // We are expecting a few parameters
  1033.         $position = (int)optional_param('sloodleentryposition', '-1', PARAM_INT);
  1034.         $plugintype = optional_param('sloodleplugintype', '', PARAM_CLEAN);
  1035.  
  1036.         // Fetch translation strings
  1037.         $strselectimporter = get_string('presenter:selectimporter', 'sloodle');
  1038.         $strsubmit = get_string('submit');
  1039.         
  1040.         // Do we have a valid plugin type already specified?
  1041.         if (empty($plugintype) || !array_key_exists($plugintype, $availableimporters)) {
  1042.             // No - display a menu to select the desired importer
  1043.             
  1044.             // Sort the list of importers by name
  1045.             natcasesort($availableimporters);
  1046.             // Setup a base link for all importer types
  1047.             $baselink = "{$CFG->wwwroot}/mod/sloodle/view.php?id={$this->cm->id}&amp;mode=importslides";
  1048.  
  1049.             // Go through each one and display it in a menu
  1050.             $table = new stdClass();
  1051.             $table->head array('Name''Description');
  1052.             $table->size array('25%''75%');
  1053.             $table->align array('center''left');
  1054.             $table->data array();
  1055.             foreach ($availableimporters as $importerident => $importername{
  1056.  
  1057.                 // Get the description of the plugin
  1058.                 $plugin = $this->_session->plugins->get_plugin($importerident);
  1059.                 $desc $plugin->get_plugin_description();
  1060.  
  1061.                 // Add the name of the importer to the table as a link
  1062.                 $link "{$baselink}&amp;sloodleplugintype={$importerident}";
  1063.                 $line = array();
  1064.                 $line[] = "<span style=\"font-size:120%; font-weight:bold;\"><a href=\"{$link}\" title=\"{$desc}\">{$importername}</a></span>";
  1065.                 // Add the description
  1066.                 $line[] = $desc;
  1067.  
  1068.                 $table->data[$line;
  1069.             }
  1070.  
  1071.             echo "<h4>{$strselectimporter}: </h4>\n";
  1072.             print_table($table);
  1073.             
  1074.  
  1075.             return;
  1076.         }
  1077.         
  1078.         // Grab the importer plugin object
  1079.         $importer = $this->_session->plugins->get_plugin($plugintype);
  1080.  
  1081.         // Display a heading for this importer
  1082.         echo '<h2 style="margin-bottom:0px; padding-bottom:0px;">'.$importer->get_plugin_name()."</h2>\n";
  1083.  
  1084.         // Render the plugin display
  1085.         $importer->render("{$CFG->wwwroot}/mod/sloodle/view.php?id={$this->cm->id}", $this->presenter);
  1086.         
  1087.     }
  1088.  
  1089.     /**
  1090.     * Render the view of the Presenter.
  1091.     */
  1092.     function render()
  1093.     {
  1094.         global $CFG;
  1095.         
  1096.         // Setup our list of tabs
  1097.         // We will always have a view option
  1098.         $presenterTabs = array(); // Top level is rows of tabs
  1099.         $presenterTabs[0] = array(); // Second level is individual tabs in a row
  1100.         $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_VIEW, SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=view", get_string('view', 'sloodle'), get_string('presenter:viewpresentation', 'sloodle'), true);
  1101.         // Does the user have authority to edit this module?
  1102.         if ($this->canedit{
  1103.             // Add the 'Edit' tab, for editing the presentation as a whole
  1104.             $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_EDIT, SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=edit", get_string('edit', 'sloodle'), get_string('presenter:edit', 'sloodle'), true);
  1105.  
  1106.             // Add the 'Add Slide' tab
  1107.             $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_ADD_SLIDE, SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=addslide", get_string('presenter:add', 'sloodle'), get_string('presenter:add', 'sloodle'), true);
  1108.  
  1109.             // Add the 'Bulk Upload' tab
  1110.             $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_ADD_FILES, SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=addfiles", get_string('presenter:bulkupload', 'sloodle'), get_string('presenter:bulkupload', 'sloodle'), true);
  1111.  
  1112.             // Add the 'Import Slides' tab
  1113.             $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_IMPORT_SLIDES, SLOODLE_WWWROOT."/view.php?id={$this->cm->id}&amp;mode=importslides", get_string('presenter:importslides', 'sloodle'), get_string('presenter:importslides', 'sloodle'), true);
  1114.  
  1115.             // If we are editing a slide, then add the 'Edit Slide' tab
  1116.             if ($this->presenter_mode == 'editslide'{
  1117.                 $presenterTabs[0][] = new tabobject(SLOODLE_PRESENTER_TAB_EDIT_SLIDE, '', get_string('editslide', 'sloodle'), '', false);
  1118.             }
  1119.         }
  1120.         // Determine which tab should be active
  1121.         $selectedtab = SLOODLE_PRESENTER_TAB_VIEW;
  1122.         switch ($this->presenter_mode)
  1123.         {
  1124.         case 'edit'$selectedtab = SLOODLE_PRESENTER_TAB_EDIT; break;
  1125.         case 'addslide'$selectedtab = SLOODLE_PRESENTER_TAB_ADD_SLIDE; break;
  1126.         case 'addfiles'$selectedtab = SLOODLE_PRESENTER_TAB_ADD_FILES; break;
  1127.         case 'editslide'$selectedtab = SLOODLE_PRESENTER_TAB_EDIT_SLIDE; break;
  1128.         case 'moveslide'$selectedtab = SLOODLE_PRESENTER_TAB_EDIT; break;
  1129.         case 'deleteslide'$selectedtab = SLOODLE_PRESENTER_TAB_EDIT; break;
  1130.         case 'confirmdeleteslide'$selectedtab = SLOODLE_PRESENTER_TAB_EDIT; break;
  1131.         case 'importslides'$selectedtab = SLOODLE_PRESENTER_TAB_IMPORT_SLIDES; break;
  1132.         }
  1133.         
  1134.         // Display the tabs
  1135.         print_tabs($presenterTabs, $selectedtab);
  1136.         echo "<div style=\"text-align:center;\">\n";
  1137.         
  1138.         // Call the appropriate render function, based on our mode
  1139.         switch ($this->presenter_mode)
  1140.         {
  1141.         case 'edit'$this->render_edit()break;
  1142.         case 'addslide'$this->render_slide_edit()break;
  1143.         case 'addfiles'$this->render_add_files()break;
  1144.         case 'editslide'$this->render_slide_edit()break;
  1145.         case 'moveslide'$this->render_edit()break;
  1146.         case 'deleteslide'$this->render_edit()break;
  1147.         case 'confirmdeleteslide'$this->render_edit()break;
  1148.         case 'importslides'$this->render_import_slides()break;
  1149.         default$this->render_view()break;
  1150.         }
  1151.         
  1152.         echo "</div>\n";
  1153.     }
  1154.  
  1155. }
  1156.  
  1157.  

Documentation generated on Fri, 17 Jul 2009 11:02:24 +0100 by phpDocumentor 1.4.0