hotpotatoes.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 13477 2007-10-12 12:20:24Z 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=api_is_allowed_to_edit();
  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. $perm = api_get_setting('permissions_for_new_directories');
  103. $perm = octdec(!empty($perm)?$perm:'0770');
  104. chmod ($document_sys_path.$uploadPath."/".$fld,$perm);
  105. $doc_id = add_document($_course, '/HotPotatoes_files/'.$fld,'folder',0,$fld);
  106. api_item_property_update($_course,TOOL_DOCUMENT,$doc_id,'FolderCreated',$_user['user_id']);
  107. }
  108. else
  109. { //it is not the first step... get the filename directly from the system params
  110. $filename = $_FILES['userFile']['name'];
  111. }
  112. /*if (treat_uploaded_file($_FILES['userFile'], $document_sys_path,
  113. $uploadPath."/".$fld, $maxFilledSpace, $unzip))*/
  114. $allow_output_on_success = false;
  115. if (handle_uploaded_document($_course,$_FILES['userFile'],$document_sys_path,$uploadPath."/".$fld,$_user['user_id'],null,null,$maxFilledSpace,$unzip,'',$allow_output_on_success))
  116. {
  117. if ($finish==2)
  118. {
  119. $imgparams = $_POST['imgparams'];
  120. $checked = CheckImageName($imgparams,$filename);
  121. if ($checked)
  122. { $imgcount = $imgcount-1; }
  123. else
  124. {
  125. $dialogBox .= $filename." ".get_lang('NameNotEqual');
  126. my_delete($document_sys_path.$uploadPath."/".$fld."/".$filename);
  127. update_db_info("delete", $uploadPath."/".$fld."/".$filename);
  128. }
  129. if ($imgcount==0) // all image uploaded
  130. {
  131. $finish=1;
  132. }
  133. }
  134. else
  135. { //if we are (still) on the first step of the upload process
  136. if ($finish==0)
  137. {
  138. $finish = 2;
  139. // get number and name of images from the files contents
  140. GetImgParams("/".$filename,$document_sys_path.$uploadPath."/".$fld,$imgparams,$imgcount);
  141. if ($imgcount==0) //there is no img link, so finish the upload process
  142. { $finish = 1; }
  143. else //there is still one or more img missing
  144. { $dialogBox .= get_lang('DownloadEnd'); }
  145. }
  146. }
  147. $newComment = "";
  148. $query = "UPDATE $dbTable SET comment='$newComment' WHERE path=\"".$uploadPath."/".$fld."/".$filename."\"";
  149. /*, visibility='v' */
  150. api_sql_query($query,__FILE__,__LINE__);
  151. api_item_property_update($_course, TOOL_QUIZ, $id, "QuizAdded", $_user['user_id']);
  152. }
  153. else
  154. {
  155. if ($finish==2)
  156. {
  157. // delete?
  158. //$dialogBox .= get_lang('NoImg');
  159. }
  160. $finish = 0; // error
  161. if (api_failure::get_last_failure() == 'not_enough_space')
  162. {
  163. $dialogBox .= get_lang('NoSpace');
  164. }
  165. elseif (api_failure::get_last_failure() == 'php_file_in_zip_file')
  166. {
  167. $dialogBox .= get_lang('ZipNoPhp');
  168. }
  169. }
  170. /* if ($oke==1)
  171. { $enableDocumentParsing=true; $oke=0;}
  172. */
  173. }
  174. }
  175. }
  176. if ($finish == 1)
  177. { /** ok -> send to main exercises page */
  178. header("Location: exercice.php");
  179. exit;
  180. }
  181. Display::display_header($nameTools,"Exercise");
  182. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  183. /* -----*/
  184. ?>
  185. <br />
  186. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  187. <tr>
  188. <td width="50%"><h3><?php echo $nameTools; ?></h3></td>
  189. <td width="50%" align="right">
  190. </td>
  191. </tr>
  192. </table>
  193. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  194. <tr>
  195. <?php
  196. if ($finish==2) //if we are in the img upload process
  197. {
  198. $dialogBox.= get_lang('ImgNote_st').$imgcount.get_lang('ImgNote_en')."<br>";
  199. while(list($key,$string)=each($imgparams))
  200. {
  201. $dialogBox.=$string."; ";
  202. }
  203. }
  204. if ($dialogBox)
  205. {
  206. echo "<td>\n<!-- dialog box -->\n&nbsp;\n</td>\n";
  207. Display::display_normal_message($dialogBox, false); //main API
  208. echo "</td>\n";
  209. }
  210. else
  211. {
  212. echo "<td>\n<!-- dialog box -->\n&nbsp;\n</td>\n";
  213. }
  214. /*--------------------------------------
  215. UPLOAD SECTION
  216. --------------------------------------*/
  217. echo "<!-- upload -->\n",
  218. "<td align=\"left\" height=\"150\" style=\"background-image: url('../img/hotpotatoes.jpg'); background-repeat: no-repeat; background-position: 600px;\" valign=\"middle\">\n",
  219. "<form action=\"".api_get_self()."\" method=\"post\" enctype=\"multipart/form-data\" >\n",
  220. "<input type=\"hidden\" name=\"uploadPath\" value=\"\">\n",
  221. "<input type=\"hidden\" name=\"fld\" value=\"$fld\">\n",
  222. "<input type=\"hidden\" name=\"imgcount\" value=\"$imgcount\">\n",
  223. "<input type=\"hidden\" name=\"finish\" value=\"$finish\">\n";
  224. echo GenerateHiddenList($imgparams);
  225. /*if ($finish==0){ echo get_lang('DownloadFile');}
  226. else {echo get_lang('DownloadImg');}
  227. echo " : ",
  228. "<input type=\"file\" name=\"userFile\">\n",
  229. "<input type=\"submit\" name=\"submit\" value=\"".get_lang('Send')."\"><br/>\n";*/
  230. echo '<table>';
  231. echo '<tr>';
  232. echo '<td width="250">';
  233. if ($finish==0){
  234. echo get_lang('DownloadFile').' : ';
  235. }
  236. else{
  237. echo get_lang('DownloadImg').' : ';
  238. }
  239. echo '</td>';
  240. echo '<td>';
  241. echo '<input type="file" name="userFile">';
  242. echo '</td>';
  243. echo '</tr>';
  244. echo '<tr>';
  245. echo '<td width="250">';
  246. echo '</td>';
  247. echo '<td>';
  248. echo '<input type="submit" name="submit" value="'.get_lang('Send').'">';
  249. echo '</td>';
  250. echo '</tr>';
  251. echo '</table>';
  252. ?>
  253. </td>
  254. </tr>
  255. </table>
  256. <?php
  257. Display::display_footer();
  258. }
  259. /*
  260. else
  261. {
  262. if ($finish == 1)
  263. { // ok
  264. //include("exercice.php");
  265. header("Location: exercice.php");
  266. }
  267. else
  268. {
  269. }
  270. }
  271. */
  272. ?>