hotpotatoes.php 9.3 KB

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