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

Source for file hotpotatoes.php

Documentation is available at hotpotatoes.php

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

Documentation generated on Thu, 12 Jun 2008 13:39:17 -0500 by phpDocumentor 1.4.1