document.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. //TODO: check see if we need, it seems not working here
  162. $fck_attribute['Width'] = '100%';
  163. $fck_attribute['Height'] = '400';
  164. $fck_attribute['ToolbarSet'] = 'LearnPath';
  165. // TODO: These settings to be checked when it is possible.
  166. $fck_attribute['Config']['InDocument'] = false;
  167. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/';
  168. $fck_attribute['Config']['CreateDocumentDir'] = '../../courses/'.api_get_course_path().'/document/';
  169. $fck_attribute['Config']['BaseHref'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/';
  170. if($my_version=='1.8'){
  171. Display::display_introduction_section(TOOL_LEARNPATH);
  172. }else{
  173. api_introductionsection(TOOL_LEARNPATH);
  174. }
  175. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  176. if(api_is_allowed_to_edit())
  177. {
  178. /*--------------------------------------
  179. UPLOAD SECTION - displays file upload box
  180. --------------------------------------*/
  181. echo "<!-- upload -->",
  182. "<p align=\"right\">",
  183. "<form action=\"".api_get_self()."?openDir=", rawurlencode($openDir),
  184. "&subdirs=$subdirs\" method=\"post\" enctype=\"multipart/form-data\">",
  185. "<input type=\"hidden\" name=\"uploadPath\" value=\"$curDirPath\" />",
  186. get_lang('DownloadFile'),"&nbsp;:&nbsp;",
  187. "<input type=\"file\" name=\"userFile\" />",
  188. "<input type=\"submit\" value=\"".get_lang('Download')."\" />&nbsp;",
  189. "</p></form>";
  190. /*--------------------------------------
  191. DIALOG BOX SECTION
  192. --------------------------------------*/
  193. if ($dialogBox)
  194. {
  195. Display::display_normal_message($dialogBox);
  196. }
  197. echo "<table border='0' cellspacing='2' cellpadding='4'>
  198. <tr>
  199. <td valign='bottom'>
  200. <a href='".api_get_self()."?action=add'>",
  201. "<img src='../img/scormbuilder.gif' border=\"0\" align=\"absmiddle\" alt='scormbuilder' />".get_lang('_add_learnpath')."</a>
  202. </td>",
  203. "<td valign='bottom'>&nbsp;&nbsp;&nbsp;<a href='".api_get_self()."?createDir=$cmdCurDirPath'>",
  204. "<img src=\"../img/dossier.gif\" border=\"0\" align=\"absmiddle\" />",
  205. "",get_lang("CreateDir"),"</a>
  206. </td>
  207. </tr>
  208. </table>";
  209. }
  210. echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" class='data_table'>";
  211. api_is_allowed_to_edit() ? $colspan = 9 : $colspan = 3;
  212. if ($curDirName) /* if the $curDirName is empty, we're in the root point
  213. and we can't go to a parent dir */
  214. {
  215. ?>
  216. <!-- parent dir -->
  217. <a href="<?php echo api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdParentDir.'&subdirs=yes'; ?>">
  218. <img src="../img/folder_up.gif" border="0" align="absbottom" hspace="5" alt="parent" />
  219. <?php echo get_lang("Up"); ?></a>&nbsp;
  220. <?php
  221. }
  222. if ($curDirPath)
  223. {
  224. if(substr($curDirPath,1,1)=='/'){
  225. $tmpcurDirPath=substr($curDirPath,1,strlen($curDirPath));
  226. }else{
  227. $tmpcurDirPath = $curDirPath;
  228. }
  229. ?>
  230. <!-- current dir name -->
  231. <tr>
  232. <td colspan="<?php echo $colspan ?>" align="left" bgcolor="#4171B5">
  233. <img src="../img/opendir.gif" align="absbottom" vspace="2" hspace="3" alt="open_dir" />
  234. <?php echo $tmpcurDirPath ?>
  235. </td>
  236. </tr>
  237. <?php
  238. }
  239. /* CURRENT DIRECTORY */
  240. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">";
  241. echo "<td width='290'><b>",get_lang("Name"),"</b></td>\n",
  242. "<td><b>",get_lang("Description"),"</b></td>\n";
  243. if (api_is_allowed_to_edit())
  244. {
  245. echo "<td><b>",get_lang("ExportShort"),"</b></td>\n",
  246. "<td width='200'><b>",get_lang("Modify"),"</b></td>\n";
  247. }
  248. echo "</tr>\n";
  249. /*--------------------------------------
  250. DISPLAY SCORM LIST
  251. --------------------------------------*/
  252. if ($fileList)
  253. {
  254. $counter=0;
  255. while (list($fileKey, $fileName) = each ($fileList['name']))
  256. {
  257. $counter++;
  258. if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  259. if ($fileList['type'][$fileKey] == A_FILE) continue; // RH: added
  260. $dspFileName = htmlentities($fileName);
  261. $cmdFileName = rawurlencode($curDirPath."/".$fileName);
  262. if ($fileList['visibility'][$fileKey] == "i")
  263. {
  264. if (api_is_allowed_to_edit())
  265. {
  266. $style=" class='invisible'";
  267. }
  268. else
  269. {
  270. continue; // skip the display of this file
  271. }
  272. }
  273. else
  274. {
  275. $style="";
  276. }
  277. $manifestRoute = $baseWorkDir.$curDirPath."/".$fileName.'/imsmanifest.xml';
  278. $plantyndir1 = $baseWorkDir.$curDirPath."/".$fileName.'/LMS';
  279. $plantyndir2 = $baseWorkDir.$curDirPath."/".$fileName.'/REF';
  280. $plantyndir3 = $baseWorkDir.$curDirPath."/".$fileName.'/SCO';
  281. $aiccdir = $baseWorkDir.$curDirPath."/".$fileName.'/aicc';
  282. $indexRoute1 = $indexRoute2 = $indexRouteA = '';
  283. if ((file_exists($plantyndir1)) and (file_exists($plantyndir2)) and (file_exists($plantyndir3))) {
  284. $indexRoute1 = $baseWorkDir.$curDirPath."/".$fileName.'/index.htm';
  285. $indexRoute2 = $baseWorkDir.$curDirPath."/".$fileName.'/index.html';
  286. }
  287. if (file_exists($aiccdir)) {
  288. $indexRouteA = $baseWorkDir.$curDirPath."/".$fileName.'/start.htm';
  289. }
  290. if (file_exists($indexRoute1)) {
  291. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=index.htm';
  292. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm' />";
  293. } elseif (file_exists($indexRoute2)) {
  294. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=index.html';
  295. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  296. } elseif (file_exists($indexRouteA)) {
  297. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName.'&indexRoute=start.htm';
  298. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  299. } elseif (file_exists($manifestRoute)) {
  300. $urlFileName = api_get_self().'?'.api_get_cidreq().'&openDir='.$cmdFileName;
  301. $image="<img src=\"./../img/scorm_logo.gif\" border=\"0\" align=\"absmiddle\" alt='scorm'>";
  302. } else {
  303. $urlFileName = api_get_self().'?'.api_get_cidreq().'&subdirs=yes&openDir='.$cmdFileName;
  304. $image="<img src=\"../img/dossier.gif\" border=\"0\" hspace=\"3\" align=\"absmiddle\" alt='scorm'>";
  305. }
  306. if ($curDirPath) {
  307. $sqlpath=$curDirPath."/".$fileList['name'][$fileKey]."";
  308. } else {
  309. $sqlpath="/".$fileList['name'][$fileKey]."";
  310. }
  311. $sql="SELECT name FROM $tbl_document WHERE ((path='$sqlpath') and (filetype='folder'))";
  312. $result=api_sql_query($sql,__FILE__,__LINE__);
  313. $row=mysql_fetch_array($result);
  314. if ($row['name']) { $name=$row['name']; } else { $name=$dspFileName; }
  315. echo "<tr align=\"center\"", " class=".$oddclass.">\n",
  316. "<td align=\"left\" valign='middle'>&nbsp;",
  317. "<a href=\"".$urlFileName."\" ".$style.">",
  318. "",$image,"</a>&nbsp;<a href=\"".$urlFileName."\" ".$style.">",$name,"</a>",
  319. "</td>\n";
  320. /* NB : Before tracking implementation the url above was simply
  321. * "<a href=\"",$urlFileName,"\"",$style,">"
  322. */
  323. $desc=$fileList['comment'][$fileKey];
  324. /* DESCRIPTION */
  325. echo "<td>$desc",
  326. "</td>\n";
  327. if(api_is_allowed_to_edit())
  328. {
  329. $fileExtension=explode('.',$dspFileName);
  330. $fileExtension=strtolower($fileExtension[sizeof($fileExtension)-1]);
  331. /* export */
  332. 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>";
  333. /* edit title and description */
  334. echo "<td align='center'>",
  335. "<a href='".api_get_self()."?action=editscorm&path=".$cmdFileName."'><img src=\"../img/edit.gif\" border=\"0\" title=\"".get_lang('_edit_learnpath')."\"></a>";
  336. /* DELETE COMMAND */
  337. echo
  338. "<a href=\"".api_get_self()."?delete=",$cmdFileName,"\" ",
  339. "onClick=\"return confirmation('",addslashes($dspFileName),"');\">",
  340. "<img src=\"../img/delete.gif\" border=\"0\" title=\"".get_lang('_delete_learnpath')."\" />",
  341. "</a>";
  342. /* VISIBILITY COMMAND */
  343. if ($fileList['visibility'][$fileKey] == "i")
  344. {
  345. echo "<a href=\"".api_get_self()."?make_directory_visible=",$cmdFileName,"\">",
  346. "<img src=\"../img/invisible.gif\" border=\"0\" title=\"".get_lang('_publish')."\" />",
  347. "</a>";
  348. }
  349. else
  350. {
  351. echo "<a href=\"".api_get_self()."?make_directory_invisible=",$cmdFileName,"\">",
  352. "<img src=\"../img/visible.gif\" border=\"0\" title=\"".get_lang('_no_publish')."\" />",
  353. "</a>";
  354. }
  355. } // end if($is_allowedToEdit)
  356. echo "</tr>\n";
  357. } // end each ($fileList)
  358. }// end if ( $fileList)
  359. //display learning paths
  360. if (!$curDirPath) {
  361. echo "<tr><td colspan='4'>&nbsp;</td></tr>";
  362. $sql="select * from $tbl_learnpath_main";
  363. $result=api_sql_query($sql,__FILE__,__LINE__);
  364. $counter=0;
  365. while ($row=mysql_fetch_array($result)) {
  366. $counter++;
  367. if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  368. $id=$row["learnpath_id"];
  369. $sql2="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
  370. $result2=api_sql_query($sql2,__FILE__,__LINE__);
  371. $row2=mysql_fetch_array($result2);
  372. $name=$row2['learnpath_name'];
  373. $sql3="SELECT * FROM $tbl_tool where (name=\"$name\" and image='scormbuilder.gif')";
  374. $result3=api_sql_query($sql3,__FILE__,__LINE__);
  375. $row3=mysql_fetch_array($result3);
  376. if ((api_is_allowed_to_edit()) or ((!api_is_allowed_to_edit()) and ($row3["visibility"] == '1'))) {
  377. $row['learnpath_name']=str_replace(' ','&nbsp;',$row['learnpath_name']);
  378. if ($row3["visibility"] != '1') { $style=' class="invisible"'; } else { $style=''; }
  379. echo "<tr align=\"center\" class=".$oddclass.">\n",
  380. "<td align='left'>&nbsp;",
  381. "<a href=\"../learnpath/learnpath_handler.php?".api_get_cidreq()."&learnpath_id={$row['learnpath_id']}\" $style>",
  382. "<img src='../img/scormbuilder.gif' border=\"0\" alt='scormbuilder'></a>&nbsp;",
  383. "<a href=\"../learnpath/learnpath_handler.php?".api_get_cidreq()."&learnpath_id={$row['learnpath_id']}\" $style>{$row['learnpath_name']}</a></td>",
  384. "<td>&nbsp;{$row['learnpath_description']}</td>";
  385. }
  386. if(api_is_allowed_to_edit()) {
  387. //no init of $circle1 here
  388. 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>";
  389. 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>";
  390. 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>";
  391. if (($row3["visibility"])=='1') {
  392. 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>";
  393. } else {
  394. 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>";
  395. }
  396. echo "</td>";
  397. }
  398. echo "</tr>";
  399. }
  400. }
  401. echo "</table>";
  402. // echo "</div>"; /* *** end of the div opened earlier, if needed then uncomment*/
  403. echo "<br/><br/>";
  404. /*
  405. ==============================================================================
  406. FOOTER
  407. ==============================================================================
  408. */
  409. Display::display_footer();
  410. ?>