document.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <?php //$id:$
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2005 Dokeos S.A.
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2004 Denes Nagy
  8. Copyright (c) 2003 Ghent University (UGent)
  9. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This file was origially the copy of document.php, but many modifications happened since then ;
  23. * the direct file view is not any more needed, if the user uploads a scorm zip file, a directory
  24. * will be automatically created for it, and the files will be uncompressed there for example ;
  25. *
  26. * @package dokeos.learnpath
  27. * @author Yannick Warnier <ywarnier@beeznest.org>
  28. ==============================================================================
  29. */
  30. /**
  31. * Script
  32. */
  33. // name of the language file that needs to be included
  34. $language_file = "scormdocument";
  35. //flag to allow for anonymous user - needs to be set before global.inc.php
  36. $use_anonymous = true;
  37. require('back_compat.inc.php');
  38. include('learnpath_functions.inc.php');
  39. include_once('scorm.lib.php');
  40. $courseDir = api_get_course_path().'/scorm';
  41. $baseWordDir = $courseDir;
  42. require_once('learnpathList.class.php');
  43. require_once('learnpath.class.php');
  44. require_once('learnpathItem.class.php');
  45. // storing the tables names in variables.
  46. $tbl_document = Database::get_course_table(TABLE_SCORMDOC);
  47. $tbl_learnpath_main = Database::get_course_table(TABLE_LEARNPATH_MAIN);
  48. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  49. $default_visibility="v";
  50. $show_description_field=0;
  51. /**
  52. * Display initialisation and security checks
  53. */
  54. //extra javascript functions for in html head:
  55. $htmlHeadXtra[] =
  56. "<script language='javascript' type='text/javascript'>
  57. function confirmation (name)
  58. {
  59. if (confirm(\" ".get_lang('AreYouSureToDelete')." \"+ name + \" ?\"))
  60. {return true;}
  61. else
  62. {return false;}
  63. }
  64. </script>";
  65. // Define the 'doc.inc.php' as language file
  66. //$nameTools = get_lang("Doc");
  67. // When GET['learnpath_id'] is defined, it means that
  68. // a learnpath has been chosen, so we redirect to
  69. // learnpath_handler - we possibly lose the $dialogBox warning here
  70. if(!empty($_GET['learnpath_id']))
  71. {
  72. header('location:../learnpath/learnpath_handler.php?'
  73. .'learnpath_id='.$_GET['learnpath_id']);
  74. exit();
  75. }
  76. event_access_tool(TOOL_LEARNPATH);
  77. if (! $is_allowed_in_course) api_not_allowed();
  78. /**
  79. * Now checks have been done, prepare the data to be displayed
  80. */
  81. if(!empty($openDir))
  82. {
  83. //prevent going higher than allowed in the hierarchy
  84. //if the requested dir is found inside the base course dir, use course dir
  85. //error_log($courseDir." against ".$openDir,0);
  86. if((strstr($courseDir,$openDir)===false) and (strstr($openDir,'.')===false) ){
  87. $curDirPath = $openDir;
  88. }else{
  89. $curDirPath = $courseDir;
  90. }
  91. }
  92. else
  93. {
  94. $curDirPath= $courseDir;
  95. }
  96. if ($curDirPath == "/" || $curDirPath == "\\" || strstr($curDirPath, ".."))
  97. {
  98. $curDirPath =""; // manage the root directory problem
  99. /*
  100. * The strstr($curDirPath, "..") prevent malicious users to go to the root directory
  101. */
  102. }
  103. $curDirName = basename($curDirPath);
  104. $parentDir = dirname($curDirPath);
  105. if ($parentDir == "/" || $parentDir == "\\")
  106. {
  107. $parentDir =""; // manage the root directory problem
  108. }
  109. /* Search infos in the DB about the current directory the user is in */
  110. $result = mysql_query ("SELECT * FROM $tbl_document
  111. WHERE path LIKE '".$curDirPath."/%'
  112. AND path NOT LIKE '".$curDirPath."/%/%'");
  113. if ($result) while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  114. {
  115. $attribute['path' ][] = $row['path' ];
  116. $attribute['visibility'][] = $row['visibility'];
  117. $attribute['comment' ][] = $row['comment' ];
  118. }
  119. $fileList = get_scorm_paths_from_dir($baseWorkDir.$curDirPath,$attribute);
  120. if(!isset($fileList)){
  121. die("<center>
  122. <b>Wrong directory !</b>
  123. <br> Please contact your platform administrator.
  124. </center>");
  125. }
  126. /*
  127. * Sort alphabetically the File list
  128. */
  129. if (is_array($fileList) && count($fileList)>0)
  130. {
  131. array_multisort($fileList['type'], $fileList['name'],
  132. $fileList['size'], $fileList['date'],
  133. $fileList['comment'],$fileList['visibility']);
  134. }
  135. /*----------------------------------------
  136. CHECK BASE INTEGRITY
  137. --------------------------------------*/
  138. /* commented until we know what it's for
  139. if ( is_array($attribute) && ( count($attribute['path']) > 0 ) )
  140. {
  141. $queryClause = ' WHERE path IN ( "'.implode('" , "' , $attribute['path']).'" )';
  142. api_sql_query("DELETE FROM $tbl_document ".$queryClause,__FILE__,__LINE__);
  143. api_sql_query("DELETE FROM $tbl_document WHERE comment LIKE '' AND visibility LIKE 'v'",__FILE__,__LINE__);
  144. // The second query clean the DB 'in case of' empty records (no comment an visibility=v)
  145. // These kind of records should'nt be there, but we never know...
  146. } // end if sizeof($attribute['path']) > 0
  147. */
  148. unset($attribute);
  149. /**
  150. * Display
  151. */
  152. Display::display_header($nameTools,"Path");
  153. $dspCurDirName = htmlentities($curDirName);
  154. $cmdCurDirPath = rawurlencode($curDirPath);
  155. $cmdParentDir = rawurlencode($parentDir);
  156. $ob_string = '';
  157. api_display_tool_title($nameTools);
  158. /*
  159. -----------------------------------------------------------
  160. Introduction section
  161. (editable by course admins)
  162. -----------------------------------------------------------
  163. */
  164. if($my_version=='1.8'){
  165. Display::display_introduction_section(TOOL_LEARNPATH);
  166. }else{
  167. api_introductionsection(TOOL_LEARNPATH);
  168. }
  169. if(api_is_allowed_to_edit())
  170. {
  171. /*--------------------------------------
  172. UPLOAD SECTION - displays file upload box
  173. --------------------------------------*/
  174. echo "<!-- upload -->",
  175. "<p align=\"right\">",
  176. "<form action=\"".api_get_self()."?openDir=", rawurlencode($openDir),
  177. "&subdirs=$subdirs\" method=\"post\" enctype=\"multipart/form-data\">",
  178. "<input type=\"hidden\" name=\"uploadPath\" value=\"$curDirPath\" />",
  179. get_lang('DownloadFile'),"&nbsp;:&nbsp;",
  180. "<input type=\"file\" name=\"userFile\" />",
  181. "<input type=\"submit\" value=\"".get_lang('Download')."\" />&nbsp;",
  182. "</p></form>";
  183. /*--------------------------------------
  184. DIALOG BOX SECTION
  185. --------------------------------------*/
  186. if ($dialogBox)
  187. {
  188. Display::display_normal_message($dialogBox);
  189. }
  190. echo "<table border='0' cellspacing='2' cellpadding='4'>
  191. <tr>
  192. <td valign='bottom'>
  193. <a href='".api_get_self()."?action=add'>",
  194. "<img src='../img/scormbuilder.gif' border=\"0\" align=\"absmiddle\" alt='scormbuilder'>".get_lang('_add_learnpath')."</a>
  195. </td>",
  196. "<td valign='bottom'>&nbsp;&nbsp;&nbsp;<a href='".api_get_self()."?createDir=$cmdCurDirPath'>",
  197. "<img src=\"../img/dossier.gif\" border=\"0\" align=\"absmiddle\">",
  198. "",get_lang("CreateDir"),"</a>
  199. </td>
  200. </tr>
  201. </table>";
  202. }
  203. echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" class='data_table'>";
  204. api_is_allowed_to_edit() ? $colspan = 9 : $colspan = 3;
  205. if ($curDirName) /* if the $curDirName is empty, we're in the root point
  206. and we can't go to a parent dir */
  207. {
  208. ?>
  209. <!-- parent dir -->
  210. <a href="<?php echo api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdParentDir.'&subdirs=yes'; ?>">
  211. <img src="../img/folder_up.gif" border="0" align="absbottom" hspace="5" alt="parent" />
  212. <?php echo get_lang("Up"); ?></a>&nbsp;
  213. <?php
  214. }
  215. if ($curDirPath)
  216. {
  217. if(substr($curDirPath,1,1)=='/'){
  218. $tmpcurDirPath=substr($curDirPath,1,strlen($curDirPath));
  219. }else{
  220. $tmpcurDirPath = $curDirPath;
  221. }
  222. ?>
  223. <!-- current dir name -->
  224. <tr>
  225. <td colspan="<?php echo $colspan ?>" align="left" bgcolor="#4171B5">
  226. <img src="../img/opendir.gif" align="absbottom" vspace="2" hspace="3" alt="open_dir" />
  227. <font color="#ffffff"><b><?php echo $tmpcurDirPath ?></b></font>
  228. </td>
  229. </tr>
  230. <?php
  231. }
  232. /* CURRENT DIRECTORY */
  233. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">";
  234. echo "<td width='290'><b>",get_lang("Name"),"</b></td>\n",
  235. "<td><b>",get_lang("Description"),"</b></td>\n";
  236. if (api_is_allowed_to_edit())
  237. {
  238. echo "<td><b>",get_lang("ExportShort"),"</b></td>\n",
  239. "<td width='200'><b>",get_lang("Modify"),"</b></td>\n";
  240. }
  241. echo "</tr>\n";
  242. /*--------------------------------------
  243. DISPLAY SCORM LIST
  244. --------------------------------------*/
  245. if ($fileList)
  246. {
  247. $counter=0;
  248. while (list($fileKey, $fileName) = each ($fileList['name']))
  249. {
  250. $counter++;
  251. if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  252. if ($fileList['type'][$fileKey] == A_FILE) continue; // RH: added
  253. $dspFileName = htmlentities($fileName);
  254. $cmdFileName = rawurlencode($curDirPath."/".$fileName);
  255. if ($fileList['visibility'][$fileKey] == "i")
  256. {
  257. if (api_is_allowed_to_edit())
  258. {
  259. $style=" class='invisible'";
  260. }
  261. else
  262. {
  263. continue; // skip the display of this file
  264. }
  265. }
  266. else
  267. {
  268. $style="";
  269. }
  270. $manifestRoute = $baseWorkDir.$curDirPath."/".$fileName.'/imsmanifest.xml';
  271. $plantyndir1 = $baseWorkDir.$curDirPath."/".$fileName.'/LMS';
  272. $plantyndir2 = $baseWorkDir.$curDirPath."/".$fileName.'/REF';
  273. $plantyndir3 = $baseWorkDir.$curDirPath."/".$fileName.'/SCO';
  274. $aiccdir = $baseWorkDir.$curDirPath."/".$fileName.'/aicc';
  275. $indexRoute1 = $indexRoute2 = $indexRouteA = '';
  276. if ((file_exists($plantyndir1)) and (file_exists($plantyndir2)) and (file_exists($plantyndir3))) {
  277. $indexRoute1 = $baseWorkDir.$curDirPath."/".$fileName.'/index.htm';
  278. $indexRoute2 = $baseWorkDir.$curDirPath."/".$fileName.'/index.html';
  279. }
  280. if (file_exists($aiccdir)) {
  281. $indexRouteA = $baseWorkDir.$curDirPath."/".$fileName.'/start.htm';
  282. }
  283. if (file_exists($indexRoute1)) {
  284. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=index.htm';
  285. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  286. } elseif (file_exists($indexRoute2)) {
  287. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=index.html';
  288. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  289. } elseif (file_exists($indexRouteA)) {
  290. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=start.htm';
  291. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  292. } elseif (file_exists($manifestRoute)) {
  293. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName;
  294. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  295. } else {
  296. $urlFileName = api_get_self().'?'.api_get_cidreq().'&subdirs=yes&openDir='.$cmdFileName;
  297. $image="<img src=\"../img/dossier.gif\" border=\"0\" hspace=\"3\" align=\"absmiddle\" alt='scorm'>";
  298. }
  299. if ($curDirPath) {
  300. $sqlpath=$curDirPath."/".$fileList['name'][$fileKey]."";
  301. } else {
  302. $sqlpath="/".$fileList['name'][$fileKey]."";
  303. }
  304. $sql="SELECT name FROM $tbl_document WHERE ((path='$sqlpath') and (filetype='folder'))";
  305. $result=api_sql_query($sql,__FILE__,__LINE__);
  306. $row=mysql_fetch_array($result);
  307. if ($row['name']) { $name=$row['name']; } else { $name=$dspFileName; }
  308. echo "<tr align=\"center\"", " class=".$oddclass.">\n",
  309. "<td align=\"left\" valign='middle'>&nbsp;",
  310. "<a href=\"".$urlFileName."\" ".$style.">",
  311. "",$image,"</a>&nbsp;<a href=\"".$urlFileName."\" ".$style.">",$name,"</a>",
  312. "</td>\n";
  313. /* NB : Before tracking implementation the url above was simply
  314. * "<a href=\"",$urlFileName,"\"",$style,">"
  315. */
  316. $desc=$fileList['comment'][$fileKey];
  317. /* DESCRIPTION */
  318. echo "<td>$desc",
  319. "</td>\n";
  320. if(api_is_allowed_to_edit())
  321. {
  322. $fileExtension=explode('.',$dspFileName);
  323. $fileExtension=strtolower($fileExtension[sizeof($fileExtension)-1]);
  324. /* export */
  325. echo "<td align='center'><a href='".api_get_self()."?action=exportscorm&".api_get_cidreq()."&path=".$cmdFileName."'><img src=\"../img/save_zip.gif\" border=\"0\" title=\"".get_lang('Export')."\"></a>";
  326. /* edit title and description */
  327. echo "<td align='center'>",
  328. "<a href='".api_get_self()."?action=editscorm&path=".$cmdFileName."'><img src=\"../img/edit.gif\" border=\"0\" title=\"".get_lang('_edit_learnpath')."\"></a>";
  329. /* DELETE COMMAND */
  330. echo
  331. "<a href=\"".api_get_self()."?delete=",$cmdFileName,"\" ",
  332. "onClick=\"return confirmation('",addslashes($dspFileName),"');\">",
  333. "<img src=\"../img/delete.gif\" border=\"0\" title=\"".get_lang('_delete_learnpath')."\" />",
  334. "</a>";
  335. /* VISIBILITY COMMAND */
  336. if ($fileList['visibility'][$fileKey] == "i")
  337. {
  338. echo "<a href=\"".api_get_self()."?make_directory_visible=",$cmdFileName,"\">",
  339. "<img src=\"../img/invisible.gif\" border=\"0\" title=\"".get_lang('_publish')."\" />",
  340. "</a>";
  341. }
  342. else
  343. {
  344. echo "<a href=\"".api_get_self()."?make_directory_invisible=",$cmdFileName,"\">",
  345. "<img src=\"../img/visible.gif\" border=\"0\" title=\"".get_lang('_no_publish')."\" />",
  346. "</a>";
  347. }
  348. } // end if($is_allowedToEdit)
  349. echo "</tr>\n";
  350. } // end each ($fileList)
  351. }// end if ( $fileList)
  352. //display learning paths
  353. if (!$curDirPath) {
  354. echo "<tr><td colspan='4'>&nbsp;</td></tr>";
  355. $sql="select * from $tbl_learnpath_main";
  356. $result=api_sql_query($sql,__FILE__,__LINE__);
  357. $counter=0;
  358. while ($row=mysql_fetch_array($result)) {
  359. $counter++;
  360. if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  361. $id=$row["learnpath_id"];
  362. $sql2="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
  363. $result2=api_sql_query($sql2,__FILE__,__LINE__);
  364. $row2=mysql_fetch_array($result2);
  365. $name=$row2['learnpath_name'];
  366. $sql3="SELECT * FROM $tbl_tool where (name=\"$name\" and image='scormbuilder.gif')";
  367. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  368. $row3=mysql_fetch_array($result3);
  369. if ((api_is_allowed_to_edit()) or ((!api_is_allowed_to_edit()) and ($row3["visibility"] == '1'))) {
  370. $row['learnpath_name']=str_replace(' ','&nbsp;',$row['learnpath_name']);
  371. if ($row3["visibility"] != '1') { $style=' class="invisible"'; } else { $style=''; }
  372. echo "<tr align=\"center\" class=".$oddclass.">\n",
  373. "<td align='left'>&nbsp;",
  374. "<a href=\"../learnpath/learnpath_handler.php?".api_get_cidreq()."&learnpath_id={$row['learnpath_id']}\" $style>",
  375. "<img src='../img/scormbuilder.gif' border=\"0\" alt='scormbuilder'></a>&nbsp;",
  376. "<a href=\"../learnpath/learnpath_handler.php?".api_get_cidreq()."&learnpath_id={$row['learnpath_id']}\" $style>{$row['learnpath_name']}</a></td>",
  377. "<td>&nbsp;{$row['learnpath_description']}</td>";
  378. }
  379. if(api_is_allowed_to_edit()) {
  380. //no init of $circle1 here
  381. echo "<td align='center'><a href='".api_get_self()."?action=exportpath&id=".$row["learnpath_id"]."'><img src=\"../img/save_zip.gif\" border=\"0\" title=\"".get_lang('Export')."\"></a>";
  382. echo "<td align='center'><a href='".api_get_self()."?action=editpath&id=".$row["learnpath_id"]."'><img src=\"../img/edit.gif\" border=\"0\" title=\"".get_lang('_edit_learnpath')."\"></a>";
  383. echo "<a href='".api_get_self()."?action=deletepath&id=".$row["learnpath_id"]."'><img src=\"../img/delete.gif\" border=\"0\" title=\"".get_lang('_delete_learnpath')."\" onClick=\"return confirmation('".$row2['learnpath_name']."');\"></a>";
  384. if (($row3["visibility"])=='1') {
  385. echo "<a href='".api_get_self()."?action=publishpath&set_visibility=i&id=".$row["learnpath_id"]."'><img src=\"../img/visible.gif\" border=\"0\" alt=\"".get_lang('_no_publish')."\" title=\"".get_lang('_no_publish')."\"></a>";
  386. } else {
  387. echo "<a href='".api_get_self()."?action=publishpath&set_visibility=v&id=".$row["learnpath_id"]."'><img src=\"../img/invisible.gif\" border=\"0\" alt=\"".get_lang('_publish')."\" title=\"".get_lang('_publish')."\"></a>";
  388. }
  389. echo "</td>";
  390. }
  391. echo "</tr>";
  392. }
  393. }
  394. echo "</table>";
  395. // echo "</div>"; /* *** end of the div opened earlier, if needed then uncomment*/
  396. echo "<br/><br/>";
  397. /*
  398. ==============================================================================
  399. FOOTER
  400. ==============================================================================
  401. */
  402. Display::display_footer();
  403. ?>