hotpotatoes.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Istvan Mandak
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * Code for Hotpotatoes integration.
  22. *
  23. * @author Istvan Mandak
  24. * @package dokeos.exercise
  25. ==============================================================================
  26. */
  27. $finish = (!empty($_POST['finish'])?$_POST['finish']:0);
  28. $imgcount = (!empty($_POST['imgcount'])?$_POST['imgcount']:null);
  29. $fld = (!empty($_POST['fld'])?$_POST['fld']:null);
  30. $langFile='exercice';
  31. include('../inc/global.inc.php');
  32. $this_section=SECTION_COURSES;
  33. include_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  34. include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  35. $interbreadcrumb[]= array ("url"=>"./exercice.php", "name"=> get_lang('Exercices'));
  36. $is_allowedToEdit=(!empty($is_courseAdmin)?$is_courseAdmin:false);
  37. //$dbTable = '`'.$_course['dbNameGlu']."document`";
  38. $dbTable = Database::get_course_table(DOCUMENT_TABLE);
  39. $baseServDir = $rootSys;
  40. $baseServUrl = $urlAppend."/";
  41. $document_sys_path = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  42. $uploadPath = "/HotPotatoes_files";
  43. // if user is allowed to edit
  44. if ($is_allowedToEdit)
  45. {
  46. include("hotpotatoes.lib.php");
  47. //disable document parsing(?) - obviously deprecated
  48. $enableDocumentParsing=false;
  49. if(hotpotatoes_init($document_sys_path.$uploadPath))
  50. {//if the directory doesn't exist
  51. //create the "HotPotatoes" directory
  52. $doc_id = add_document($_course, '/HotPotatoes_files','folder',0,'HotPotatoes Files');
  53. //update properties in dbase (in any case)
  54. api_item_property_update($_course,TOOL_DOCUMENT,$doc_id,'FolderCreated',$_uid);
  55. //make invisible(in any case) - why?
  56. api_item_property_update($_course,TOOL_DOCUMENT,$doc_id,'invisible',$_uid);
  57. }
  58. }
  59. /** display */
  60. // if finish is set; it's because the user came from this script in the first place (displaying hidden "finish" field)
  61. if(($is_allowedToEdit) && (($finish == 0) || ($finish == 2)))
  62. //if(($is_allowedToEdit) )
  63. {
  64. $nameTools = get_lang('HotPotatoesTests');
  65. //moved this down here as the upload handling functions give output
  66. if (isset($_POST['submit']))
  67. {
  68. //check that the submit button was pressed when the button had the "Download" value
  69. //This should be updated to "upload" here and on the button, and it would be better to
  70. // check something else than a string displayd on a button
  71. if (strcmp($_POST['submit'],get_lang('Download'))===0)
  72. {
  73. /** el kell tarolni <- english please */
  74. include_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  75. /*======================================
  76. FILEMANAGER BASIC VARIABLES DEFINITION
  77. ======================================*/
  78. include_once(api_get_path(LIBRARY_PATH)."pclzip/pclzip.lib.php");
  79. //@todo: this value should be moved to the platform admin section
  80. $maxFilledSpace = 100000000;
  81. //initialise $finish
  82. if (!isset($finish)) {$finish = 0;}
  83. //if the size is not defined, it's probably because there has been an error or no file was submitted
  84. if(!$_FILES['userFile']['size'])
  85. {
  86. $dialogBox .= get_lang('FileError').'<br />'.get_lang('Notice').' : '.get_lang('MaxFileSize').' '.ini_get('upload_max_filesize');
  87. }
  88. else
  89. {
  90. /* deprecated code
  91. if ($enableDocumentParsing==true)
  92. { $enableDocumentParsing=false;
  93. $oke=1;}
  94. else { $oke = 0; }
  95. */
  96. //$unzip = 'unzip';
  97. $unzip = 0;
  98. if(preg_match('/\.zip$/i',$_FILES['userFile']['name'])){
  99. //if it's a zip, allow zip upload
  100. $unzip = 1;
  101. }
  102. if ($finish==0)
  103. { //generate new test folder if on first step of file upload
  104. $filename = replace_dangerous_char(trim($_FILES['userFile']['name']),'strict');
  105. $fld = GenerateHpFolder($document_sys_path.$uploadPath."/");
  106. @mkdir($document_sys_path.$uploadPath."/".$fld);
  107. $doc_id = add_document($_course, '/HotPotatoes_files/'.$fld,'folder',0,$fld);
  108. api_item_property_update($_course,TOOL_DOCUMENT,$doc_id,'FolderCreated',$_uid);
  109. }
  110. else
  111. { //it is not the first step... get the filename directly from the system params
  112. $filename = $_FILES['userFile']['name'];
  113. }
  114. /*if (treat_uploaded_file($_FILES['userFile'], $document_sys_path,
  115. $uploadPath."/".$fld, $maxFilledSpace, $unzip))*/
  116. $allow_output_on_success = false;
  117. if (handle_uploaded_document($_course,$_FILES['userFile'],$document_sys_path,$uploadPath."/".$fld,$_uid,null,null,$maxFilledSpace,$unzip,'',$allow_output_on_success))
  118. {
  119. if ($finish==2)
  120. {
  121. $checked = CheckImageName($imgparams,$filename);
  122. if ($checked)
  123. { $imgcount = $imgcount-1; }
  124. else
  125. {
  126. $dialogBox .= $filename." ".get_lang('NameNotEqual');
  127. my_delete($document_sys_path.$uploadPath."/".$fld."/".$filename);
  128. update_db_info("delete", $uploadPath."/".$fld."/".$filename);
  129. }
  130. if ($imgcount==0) // all image uploaded
  131. {
  132. $finish=1;
  133. }
  134. }
  135. else
  136. { //if we are (still) on the first step of the upload process
  137. if ($finish==0)
  138. {
  139. $finish = 2;
  140. // get number and name of images from the files contents
  141. GetImgParams("/".$filename,$document_sys_path.$uploadPath."/".$fld,$imgparams,$imgcount);
  142. if ($imgcount==0) //there is no img link, so finish the upload process
  143. { $finish = 1; }
  144. else //there is still one or more img missing
  145. { $dialogBox .= get_lang('DownloadEnd'); }
  146. }
  147. }
  148. $newComment = "";
  149. $query = "UPDATE $dbTable SET comment='$newComment' WHERE path=\"".$uploadPath."/".$fld."/".$filename."\"";
  150. /*, visibility='v' */
  151. api_sql_query($query,__FILE__,__LINE__);
  152. api_item_property_update($_course, TOOL_QUIZ, $id, "QuizAdded", $_uid);
  153. }
  154. else
  155. {
  156. if ($finish==2)
  157. {
  158. // delete?
  159. //$dialogBox .= get_lang('NoImg');
  160. }
  161. $finish = 0; // error
  162. if (api_failure::get_last_failure() == 'not_enough_space')
  163. {
  164. $dialogBox .= get_lang('NoSpace');
  165. }
  166. elseif (api_failure::get_last_failure() == 'php_file_in_zip_file')
  167. {
  168. $dialogBox .= get_lang('ZipNoPhp');
  169. }
  170. }
  171. /* if ($oke==1)
  172. { $enableDocumentParsing=true; $oke=0;}
  173. */
  174. }
  175. }
  176. }
  177. if ($finish == 1)
  178. { /** ok -> send to main exercises page */
  179. header("Location: exercice.php");
  180. exit;
  181. }
  182. Display::display_header($nameTools,"Exercise");
  183. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  184. /* -----*/
  185. ?>
  186. <br />
  187. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  188. <tr>
  189. <td width="50%"><h3><?php echo $nameTools; ?></h3></td>
  190. <td width="50%" align="right">
  191. </td>
  192. </tr>
  193. </table>
  194. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  195. <tr>
  196. <?php
  197. if ($finish==2) //if we are in the img upload process
  198. {
  199. $dialogBox.= get_lang('ImgNote_st').$imgcount.get_lang('ImgNote_en')."<br>";
  200. while(list($key,$string)=each($imgparams))
  201. {
  202. $dialogBox.=$string."; ";
  203. }
  204. }
  205. if ($dialogBox)
  206. {
  207. echo "<td>\n<!-- dialog box -->\n&nbsp;\n</td>\n";
  208. Display::display_normal_message($dialogBox); //main API
  209. echo "</td>\n";
  210. }
  211. else
  212. {
  213. echo "<td>\n<!-- dialog box -->\n&nbsp;\n</td>\n";
  214. }
  215. /*--------------------------------------
  216. UPLOAD SECTION
  217. --------------------------------------*/
  218. echo "<!-- upload -->\n",
  219. "<td align=\"right\">\n",
  220. "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\">\n",
  221. "<input type=\"hidden\" name=\"uploadPath\" value=\"\">\n",
  222. "<input type=\"hidden\" name=\"fld\" value=\"$fld\">\n",
  223. "<input type=\"hidden\" name=\"imgcount\" value=\"$imgcount\">\n",
  224. "<input type=\"hidden\" name=\"finish\" value=\"$finish\">\n";
  225. echo GenerateHiddenList($imgparams);
  226. if ($finish==0){ echo get_lang('DownloadFile');}
  227. else {echo get_lang('DownloadImg');}
  228. echo " : ",
  229. "<input type=\"file\" name=\"userFile\">\n",
  230. "<input type=\"submit\" name=\"submit\" value=\"".get_lang('Download')."\"><br/>\n";
  231. ?>
  232. </td>
  233. </tr>
  234. </table>
  235. <?php
  236. Display::display_footer();
  237. }
  238. /*
  239. else
  240. {
  241. if ($finish == 1)
  242. { // ok
  243. //include("exercice.php");
  244. header("Location: exercice.php");
  245. }
  246. else
  247. {
  248. }
  249. }
  250. */
  251. ?>