hotpotatoes.php 9.1 KB

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