dokeos-backup
[ class tree: dokeos-backup ] [ index: dokeos-backup ] [ all elements ]

Source for file CourseSelectForm.class.php

Documentation is available at CourseSelectForm.class.php

  1. <?php
  2. // $Id: CourseSelectForm.class.php 15429 2008-05-26 20:34:37Z yannoo $
  3. /*
  4. ============================================================================== 
  5.     Dokeos - elearning and course management software
  6.     
  7.     Copyright (c) 2004-2008 Dokeos SPRL
  8.     Copyright (c) 2003 Ghent University (UGent)
  9.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10.     Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  11.     
  12.     For a full list of contributors, see "credits.txt".
  13.     The full license can be read in "license.txt".
  14.     
  15.     This program is free software; you can redistribute it and/or
  16.     modify it under the terms of the GNU General Public License
  17.     as published by the Free Software Foundation; either version 2
  18.     of the License, or (at your option) any later version.
  19.     
  20.     See the GNU General Public License for more details.
  21.     
  22.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  23.     Mail: info@dokeos.com
  24. ============================================================================== 
  25. */
  26. require_once ('Course.class.php');
  27. /**
  28.  * Class to show a form to select resources
  29.  * @author Bart Mollet <bart.mollet@hogent.be>
  30.  * @package dokeos.backup
  31.  */
  32. {
  33.     /**
  34.      * Display the form
  35.      * @param array $hidden_fiels Hidden fields to add to the form.
  36.      */
  37.     function display_form($course$hidden_fields null)
  38.     {
  39.         $resource_titles[RESOURCE_EVENTget_lang('Events');
  40.         $resource_titles[RESOURCE_ANNOUNCEMENTget_lang('Announcements');
  41.         $resource_titles[RESOURCE_DOCUMENTget_lang('Documents');
  42.         $resource_titles[RESOURCE_LINKget_lang('Links');
  43.         $resource_titles[RESOURCE_COURSEDESCRIPTIONget_lang('CourseDescription');
  44.         $resource_titles[RESOURCE_FORUMget_lang('Forums');
  45.         $resource_titles[RESOURCE_QUIZget_lang('Tests');
  46.         $resource_titles[RESOURCE_LEARNPATHget_lang('Learnpaths');
  47.         $resource_titles[RESOURCE_SCORM'SCORM';
  48.         $resource_titles[RESOURCE_TOOL_INTROget_lang('ToolIntro');
  49.         $resource_titles[RESOURCE_SURVEYget_lang('Survey');
  50. ?>
  51.         <script language="JavaScript" type="text/javascript">
  52.             function exp(item) {
  53.                 el = document.getElementById('div_'+item);
  54.                 if (el.style.display=='none'){
  55.                     el.style.display='';
  56.                     document.getElementById('img_'+item).src='../img/1.gif';
  57.                 }
  58.                 else{
  59.                     el.style.display='none';
  60.                     document.getElementById('img_'+item).src='../img/0.gif';
  61.                 }
  62.             }
  63.             function setCheckbox(type,value) {
  64.                  d = document.course_select_form;
  65.                  for (i = 0; i < d.elements.length; i++) {
  66.                        if (d.elements[i].type == "checkbox") {
  67.                         var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  68.                          if( name.indexOf(type) > 0 || type == 'all' ){
  69.                              d.elements[i].checked = value;
  70.                         }
  71.                        }
  72.                  }
  73.             }
  74.             function checkLearnPath(message){
  75.                 d = document.course_select_form;
  76.                  for (i = 0; i < d.elements.length; i++) {
  77.                      if (d.elements[i].type == "checkbox") {
  78.                         var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  79.                          if( name.indexOf('learnpath') > 0){
  80.                              if(d.elements[i].checked == true){
  81.                                  setCheckbox('document',true);
  82.                                  alert(message);
  83.                                  break;
  84.                              }
  85.                          }
  86.                      }    
  87.                  }
  88.             }
  89.         </script>        
  90.         <?php
  91.  
  92.         echo '<p>';
  93.         echo get_lang('SelectResources');
  94.         echo '</p>';
  95.         
  96.         echo '<script language="javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
  97.         echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
  98.         
  99.         echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
  100.         
  101.         echo '<input type="hidden" name="action" value="course_select_form"/>';
  102.         echo '<input type="hidden" name="course" value="'.base64_encode(serialize($course)).'"/>';
  103.         foreach ($course->resources as $type => $resources)
  104.         {
  105.             if (count($resources0)
  106.             {
  107.                 switch ($type)
  108.                 {
  109.                     case RESOURCE_LINKCATEGORY :
  110.                     case RESOURCE_FORUMCATEGORY :
  111.                     case RESOURCE_FORUMPOST :
  112.                     case RESOURCE_FORUMTOPIC :
  113.                     case RESOURCE_QUIZQUESTION:
  114.                     case RESOURCE_SURVEYQUESTION:
  115.                     case RESOURCE_SURVEYINVITATION:
  116.                     case RESOURCE_SCORM:
  117.                         break;
  118.                     default :
  119.                         echo ' <img id="img_'.$type.'" src="../img/1.gif" onclick="javascript:exp('."'$type'".');" >';
  120.                         echo ' <b  onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
  121.                         echo '<div id="div_'.$type.'">';
  122.                         echo '<blockquote>';
  123.                         echo "[<a href=\"#\" onclick=\"javascript:setCheckbox('$type',true);\" >".get_lang('All')."</a> - <a href=\"#\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>]";
  124.                         echo '<br />';
  125.                         foreach ($resources as $id => $resource)
  126.                         {
  127.                             echo '<input type="checkbox" name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']"/>';
  128.                             echo ' <label for="resource['.$type.']['.$id.']">';
  129.                             $resource->show();
  130.                             echo '</label>';
  131.                             echo '<br />';
  132.                             echo "\n";
  133.                         }
  134.                         echo '</blockquote>';
  135.                         echo '</div>';
  136.                         echo '<script language="javascript">exp('."'$type'".')</script>';
  137.                 }
  138.             }
  139.         }
  140.         if (is_array($hidden_fields))
  141.         {
  142.             foreach ($hidden_fields as $key => $value)
  143.             {
  144.                 echo "\n";
  145.                 echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
  146.             }
  147.         }
  148.         echo '<br /><input type="submit" value="'.get_lang('Ok').'" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')"/>';
  149.         
  150.         CourseSelectForm :: display_hidden_quiz_questions($course);
  151.         CourseSelectForm :: display_hidden_scorm_directories($course);
  152.         echo '</form>';
  153.         echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
  154.     }
  155.     
  156.     
  157.     function display_hidden_quiz_questions($course)
  158.     {
  159.     
  160.         foreach ($course->resources as $type => $resources)
  161.         {
  162.             if (count($resources0)
  163.             {
  164.                 switch ($type)
  165.                 {
  166.                     case RESOURCE_QUIZQUESTION:
  167.                         foreach ($resources as $id => $resource)
  168.                         {
  169.                             echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.'] id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
  170.                         }
  171.                         break;
  172.  
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     function display_hidden_scorm_directories($course)
  178.     {
  179.         foreach ($course->resources as $type => $resources)
  180.         {
  181.             if(count($resources0)
  182.             {
  183.                 switch($type)
  184.                 {
  185.                     case RESOURCE_SCORM:
  186.                         foreach ($resources as $id=>$resource)
  187.                         {
  188.                             echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.'] id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
  189.                         }
  190.                         break;
  191.                 }
  192.             }
  193.         }
  194.     }
  195.     
  196.     
  197.     /**
  198.      * Get the posted course
  199.      * @return course The course-object with all resources selected by the user
  200.      *  in the form given by display_form(...)
  201.      */
  202.     function get_posted_course()
  203.     {
  204.         $course unserialize(base64_decode($_POST['course']));
  205.         foreach ($course->resources as $type => $resources)
  206.         {
  207.             switch ($type)
  208.             {
  209.                 case RESOURCE_SURVEYQUESTION:
  210.                     foreach($resources as $id => $obj)
  211.                     {
  212.                         if(!in_array($obj->survey_id,array_keys($_POST['resource'][RESOURCE_SURVEY])))
  213.                         {
  214.                             unset ($course->resources[$type][$id]);
  215.                         }
  216.                     }
  217.                     break;
  218.                 case RESOURCE_LINKCATEGORY :
  219.                 case RESOURCE_FORUMCATEGORY :
  220.                 case RESOURCE_FORUMPOST :
  221.                 case RESOURCE_FORUMTOPIC :
  222.                 case RESOURCE_QUIZQUESTION :
  223.                 case RESOURCE_DOCUMENT:
  224.                     // Mark folders to import which are not selected by the user to import,
  225.                     // but in which a document was selected.
  226.                     $documents $_POST['resource'][RESOURCE_DOCUMENT];
  227.                     foreach($resources as $id => $obj)
  228.                     {
  229.                         if$obj->file_type == 'folder' && isset($_POST['resource'][RESOURCE_DOCUMENT][$id]&& is_array($documents))
  230.                         {
  231.                             foreach($documents as $id_to_check => $post_value)
  232.                             {
  233.                                 $obj_to_check $resources[$id_to_check];
  234.                                 $shared_path_part substr($obj_to_check->path,0,strlen($obj->path));
  235.                                 if($id_to_check != $id && $obj->path == $shared_path_part)
  236.                                 {
  237.                                     $_POST['resource'][RESOURCE_DOCUMENT][$id1;    
  238.                                     break;
  239.                                 }    
  240.                             }    
  241.                         }
  242.                     }
  243.                 default :
  244.                     foreach ($resources as $id => $obj)
  245.                     {
  246.                         $resource_is_used_elsewhere $course->is_linked_resource($obj);
  247.                         // check if document is in a quiz (audio/video)
  248.                         if$type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ))
  249.                         {
  250.                             foreach($course->resources[RESOURCE_QUIZas $qid => $quiz)
  251.                             {
  252.                                 if($quiz->media == $id)
  253.                                 {
  254.                                     $resource_is_used_elsewhere true;    
  255.                                 }    
  256.                             }
  257.                         }
  258.                         if (!isset ($_POST['resource'][$type][$id]&& !$resource_is_used_elsewhere)
  259.                         {
  260.                             unset ($course->resources[$type][$id]);
  261.                         }
  262.                     }
  263.             }
  264.         }
  265.         return $course;
  266.     }
  267. }
  268. ?>

Documentation generated on Thu, 12 Jun 2008 13:13:49 -0500 by phpDocumentor 1.4.1