fix_fill_blank.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. api_protect_admin_script();
  5. $table = Database::get_course_table(TABLE_QUIZ_ANSWER);
  6. $execute = isset($_GET['execute']) ? $_GET['execute'] : null;
  7. $courseId = isset($_GET['c_id']) ? $_GET['c_id'] : null;
  8. $questionId = isset($_GET['question_id']) ? $_GET['question_id'] : null;
  9. $sql2 = "SELECT * FROM $table WHERE answer LIKE '%[%]%'";
  10. if (!empty($courseId)) {
  11. $courseId = intval($courseId);
  12. $sql2 .= " AND c_id = $courseId";
  13. if (!empty($questionId)) {
  14. $questionId = intval($questionId);
  15. $sql2 .= " AND question_id = $questionId";
  16. }
  17. }
  18. var_dump($sql2);
  19. $res2 = Database::query($sql2);
  20. while ($row = Database::fetch_array($res2)) {
  21. $id = $row['id'];
  22. $courseId = $row['c_id'];
  23. $idAuto = $row['id_auto'];
  24. $answerOriginal = $row['answer'];
  25. $answer = $row['answer'];
  26. $answer = str_replace('â', '&acirc;', $answer);
  27. $answer = str_replace('à', '&agrave;', $answer);
  28. $answer = str_replace('é', '&eacute;', $answer);
  29. $answer = str_replace('ê', '&ecirc;', $answer);
  30. $answer = str_replace('è', '&egrave;', $answer);
  31. $answer = str_replace('í', '&iacute;', $answer);
  32. $answer = str_replace('ì', '&igrave;', $answer);
  33. $answer = str_replace('ó', '&oacute;', $answer);
  34. $answer = str_replace('ò', '&ograve;', $answer);
  35. $answer = str_replace('ù', '&ugrave;', $answer);
  36. $answer = str_replace('ú', '&uacute', $answer);
  37. $answer = str_replace('ç', '&ccedil;', $answer);
  38. $answer = str_replace('À', '&Agrave;', $answer);
  39. $answer = str_replace('Ç', '&Ccedil;', $answer);
  40. $answerFixedNotEscape = $answer;
  41. $answer = Database::escape_string($answer);
  42. $sql4 = "UPDATE c_quiz_answer SET
  43. answer = '$answer'
  44. WHERE id = $id AND c_id = $courseId AND id_auto = $idAuto ";
  45. if ($answerOriginal != $answerFixedNotEscape) {
  46. if (!empty($execute) && $execute == 1) {
  47. Database::query($sql4);
  48. echo '<pre>';
  49. var_dump($sql4);
  50. echo '</pre>';
  51. var_dump('executed');
  52. } else {
  53. echo "to be executed";
  54. echo '<pre>';
  55. var_dump($sql4);
  56. echo 'Original:<br />';
  57. echo($answerOriginal);
  58. echo 'Fixed:<br />';
  59. echo($answerFixedNotEscape);
  60. echo '</pre>';
  61. echo '----------<br />';
  62. }
  63. }
  64. }