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

Source for file document.php

Documentation is available at document.php

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

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