説明なし

updateQuestionnaire.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!---
  2. Developer: Coralys Cubero Rivera
  3. Fall 2018
  4. This scripts updates any changes made to a questionnaire when editing its information.
  5. Updated by: Víctor A. Hernández
  6. Summer 2019
  7. --->
  8. <?php
  9. require_once 'processes/config.php';
  10. require_once 'processes/dbh.inc.php';
  11. // IF USER ENTERS PAGE AFTER SUBMIT BUTTON HAS BEEN PRESSED (FROM editQuestionnaire.php), EDIT QUESTIONNAIRE FROM DATABASE
  12. // ELSE DO NOTHING
  13. if(isset($_POST['submitQuestionnaire'])) {
  14. // RECIBIR TODOS LOS INPUTS DE newQuestionnaire.php (TÍTULO, DESCRIPCIÓN Y CADA PREGUNTA A AÑADIRSE AL CUESTIONARSE)
  15. $keys = array();
  16. $values = array();
  17. foreach($_POST as $key => $value) {
  18. //echo "$value";
  19. $keys[] = $key;
  20. $values[] = $value;
  21. }
  22. // ######ESTO NO OVERWRITEARÍA LOS FIELDS QUE NO ESTÁN SETEADOS?????#####
  23. if(isset($_POST['newTitle']) OR isset($_POST['newDescription']) OR isset($_POST['question'])) {
  24. // CAMBIAR EL TÍTULO Y LA DESCRIPCIÓN DEL CUESTIONARIO EN LA TABLA questionair
  25. $newTitle = $values[0];
  26. $newDescription = $values[1];
  27. $id_questionnaire = $values[2];
  28. $query = "UPDATE `questionnair` SET `q_title`='".$newTitle."', `description`='".$newDescription."' WHERE `id`='".$id_questionnaire."';";
  29. $result = mysqli_query($connection, $query);
  30. if(!$result) die("Error: ".mysqli_error($connection));
  31. // "INSERTAR" CADA PREGUNTA (ADICIONAL) DESEADA AL CUESTIONARIO EN CUESTIÓN (ASOCIANDO LOS ids CON LA TABLA questionnair_question)
  32. $num_questions = sizeof($values);
  33. for ($x = 3; $x < $num_questions - 1; $x++) {
  34. $query = "INSERT INTO `questionnair_question` (`id_questionnair`, `id_question`) VALUES ('".$id_questionnaire."', '".$values[$x]."');";
  35. $result = mysqli_query($connection, $query);
  36. if (!$result) die("Error: ".mysqli_error($connection));
  37. }
  38. }
  39. // WHY NOT USE header INSTEAD OF window.top.location?
  40. //header('Location: http://emaapp.online/admin_nuevo/questionnaires.php');
  41. //exit();
  42. echo "<script>window.top.location='http://emaapp.online/admin_nuevo/questionnaires.php'</script>";
  43. }