document.php 17 KB

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