opensco.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php // $id: $
  2. /*
  3. ----------------------------------------------------------------------
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) Denes Nagy (darkden@freemail.hu)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ----------------------------------------------------------------------
  16. */
  17. /**
  18. ==============================================================================
  19. * @package dokeos.scorm
  20. * Opens a scorm lesson
  21. ==============================================================================
  22. */
  23. //Maritime :if you open the first, done it, then the second, then the first and not done it and then the second, then //your access is denied (the scos behave this way) !!
  24. //error_log($_SERVER['REQUEST_URI'],0);
  25. $langFile = "scorm";
  26. include('../inc/global.inc.php');
  27. $this_section=SECTION_COURSES;
  28. include('XMLencode.php');
  29. $charset = GetXMLEncode($_GET['file']);
  30. header('Content-Type: text/html; charset='. $charset);
  31. //error_log("Opensco start... s_identifier is now:".$_SESSION['s_identifier']." and old s_identifier is now:".$_SESSION['old_sco_identifier'],0);
  32. //$TBL_SCORM_SCO_DATA=$scormDbName."`.`scorm_sco_data";
  33. $TBL_SCORM_SCO_DATA = Database::get_scorm_sco_data_table();
  34. $sco_href = base64_decode($_GET['sco_href']);
  35. $sco_identifier = $_GET['sco_identifier'];
  36. $file = $_GET['file'];
  37. $edoceo = $_GET['edoceo'];
  38. $items = $_SESSION['items'];
  39. $_uid = $_SESSION['_uid'];
  40. $contentId = $_SESSION['contentId'];
  41. $openDir = $_REQUEST['openDir'];
  42. //prepare those variables for scormfunctions.php
  43. $_SESSION['file']=$file;
  44. $charset_lang = 'ISO-8859-15';
  45. /*
  46. * Small utility function to position the menu on a sensible item (several elements before the current one)
  47. * @param string sco_id of the target element
  48. * @param array reference to the items array
  49. * @param array reference to the sco_id inverse-index array
  50. * @param integer Optional number of elements we want before the selected element
  51. * @return string sco_id (and HTML anchor ID) of the element to which the menu should point
  52. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  53. *
  54. function get_better_anchor_target($my_id, &$my_items, &$my_items_dictionary, $num = 6){
  55. $k = $my_items_dictionary[$my_id];
  56. if( ( $k<$num ) || (!is_array($my_items[$k-$num]))){
  57. return $my_items[1]['identifier'];
  58. }else{
  59. return $my_items[$k-$num]['identifier'];
  60. }
  61. return $my_items[1]['identifier'];
  62. }
  63. Function apparently useless to call from here
  64. */
  65. if(!is_array($items)){
  66. //error_log('$items is not an array!!!',0);
  67. }
  68. //the problem is that it is not sure that the closesco.php is called, maybe not, the user can click to any other sco
  69. //without finishing the current one, that is why that this code looks ugly
  70. /*======================================
  71. SEARCHING FOR PREREQUISITIES OF COURSE
  72. ======================================*/
  73. //$i=0;
  74. $i=$_SESSION['items_dictionary'][$sco_identifier];
  75. //do {
  76. // $i++;
  77. //} while (($items[$i]['identifier'] != $sco_identifier) and ($i <= count($items)));
  78. //while goes on if it is true, it stops at false
  79. //we search the prerequisites of the current course (now only working for scorm 1.2 ; scorm 1.3 use another method)
  80. $prereq=$items[$i]['prereq'];
  81. $title=$items[$i]['title'];
  82. //$i=0;
  83. $i=$_SESSION['items_dictionary'][$prereq];
  84. //do {
  85. // $i++;
  86. //} while (($items[$i]['identifier'] != $prereq) and ($i <= count($items)));
  87. $prereqtitle=$items[$i]['title'];
  88. if ($prereq != '') {
  89. $result = api_sql_query("SELECT status FROM $TBL_SCORM_SCO_DATA
  90. WHERE (scoIdentifier='$prereq' and studentId='$_uid' and contentId='$contentId')",__FILE__,__LINE__);
  91. //echo "SELECT status FROM `$TBL_SCORM_SCO_DATA` WHERE (scoIdentifier='$prereq' and studentId='$_uid' and contentId='$contentId')";
  92. $ar=mysql_fetch_array($result);
  93. $status=$ar['status'];
  94. if ($status=='completed' or $status='passed') { $openpage=true; } else { $openpage=false; }
  95. } else {
  96. $openpage=true;
  97. }
  98. /*==============================
  99. OPENING THE PAGE IF ACCESSIBLE
  100. ==============================*/
  101. if ($openpage) {
  102. api_session_unregister('s_href');
  103. //api_session_unregister('s_identifier');
  104. //unset($_SESSION['s_identifier']);
  105. //If the user clicked on an item directly in the menu, then we didn't pass through
  106. //content.php, and consequently $_SESSION['s_identifier'] has not been renewed.
  107. //It is important to reset $_SESSION['s_identifier'] and $_SESSION['old_sco_identifier']
  108. //before loading scormfunctions.php, which will use them to call closesco.php
  109. if($sco_identifier != $_SESSION['s_identifier']){
  110. $_SESSION['s_identifier'] = $sco_identifier;
  111. $_SESSION['old_sco_identifier'] = $sco_identifier;
  112. }
  113. $s_href=$sco_href;
  114. //$_SESSION['s_identifier']=$sco_identifier;
  115. //check that file actually exists on this system (or if it doesn't start with the domain name
  116. // of this system, leave it to the risk of generating a crappy apache list page - we cannot be sure)
  117. $my_href = str_replace(api_get_path(WEB_PATH),api_get_path(SYS_PATH),$sco_href);
  118. if(($my_href == $sco_href) or (is_file(preg_replace('/(.*)\?.*/','$1',$my_href)))){
  119. //ok
  120. }else{
  121. $sco_href = 'blank.php';
  122. }
  123. api_session_register('s_href');
  124. //api_session_register('s_identifier');
  125. $pos=strpos($sco_href,'http:',5); //in case of external sco_hrefs, we cut the Dokoes-related part off
  126. if ($pos === false) {
  127. } else {
  128. $sco_href=substr($sco_href,$pos);
  129. }
  130. echo "<html><head><link rel='stylesheet' type='text/css' href='../css/scorm.css'></head><body>",
  131. "<script type='text/javascript'>\n/* <![CDATA[ */\n";
  132. //ok that the session has the s_href and the s_identifier but the scormfunction.php ran before this and
  133. //these new variables are not written in the hidden scormfunction.php in the hidden frame, so we must
  134. //refresh it in order to be able to use these variables ! here is the refresh :
  135. if ($edoceo=="no") {
  136. echo
  137. "apiwindow=open('scormfunctions.php','API');",
  138. "api1484window=open('scormfunctions.php','API_1484_11');";
  139. }
  140. //$target_identifier = get_better_anchor_target($sco_identifier, $_SESSION['items'], $_SESSION['items_dictionary'],6);
  141. echo
  142. "zwindow=open('$sco_href','sco');",
  143. "cwindow=open('contents.php?file=$file&edoceo=$edoceo&openDir=$openDir','contents');",
  144. // "parent.load.document.location=parent.load.document.location;",
  145. "\n/* ]]> */\n</script>",
  146. "<div class='message'><font color='black'>$title</font></div></body></html>";
  147. //error_log("Opensco ending... s_identifier is now:".$_SESSION['s_identifier']." and old s_identifier is now:".$_SESSION['old_sco_identifier'],0);
  148. } else {
  149. //ugly patch with htmlentities here for the accentuated characters bug. See contents.php for a tip on how
  150. // to improve this.
  151. echo "<html><head><link rel='stylesheet' type='text/css' href='../css/scorm.css'></head><body>",
  152. "<div class='message_thin'>".htmlentities(get_lang('ScormToEnter'),ENT_QUOTES,$charset_lang)
  153. ." <b>$title</b> ".htmlentities(get_lang('ScormFirstNeedTo'),ENT_QUOTES,$charset_lang)
  154. ." <b>$prereqtitle</b></div>.</body></html>";
  155. //error_log("Opensco ending (prereqs)... s_identifier is now:".$_SESSION['s_identifier']." and old s_identifier is now:".$_SESSION['old_sco_identifier'],0);
  156. }
  157. ?>