Nessuna descrizione

bankOfQuestions.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. require_once 'processes/config.php';
  3. require_once 'processes/dbh.inc.php';
  4. require_once 'processes/checkLogin.php';
  5. include_once 'header.php';
  6. // IF USER HAS QUESTIONS, DISPLAY THEM
  7. // ELSE DON'T DISPLAY THE EMPTY TABLE
  8. // CAMBIAR $query A "SELECT * FROM `question` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  9. $query1 = "SELECT * FROM `question` WHERE `id_category` IN(SELECT `id` FROM `category`) AND `id_subcategory` IN(SELECT `id` FROM `subcategory`);";
  10. $result1 = mysqli_query($connection, $query1);
  11. $x = 1;
  12. ?>
  13. <!-- START OF bankOfQuestions.php -->
  14. <div class='container'>
  15. <div class='row'>
  16. <div class='col-sm-10'>
  17. <h2>Bank Of Questions</h2>
  18. <p>View, add, and delete any question you like so that, later on, you can create a questionnaire.</p>
  19. </div>
  20. <div class='col-sm-2'>
  21. <br><br>
  22. <button id='adding' type='button' class='btn btn-default' data-toggle='modal' data-target='#New'>Add Question</button>
  23. </div>
  24. </div><!--row-->
  25. <div class='row'><div class='col'><br><hr><br></div></div>
  26. <?php if($result1): ?>
  27. <div class='row'>
  28. <div class='col'>
  29. <table class='table table-hover table-striped' id='tableEvaluations'>
  30. <thead>
  31. <tr>
  32. <th><h4>#</h4></th>
  33. <th><h4>Premise</h4></th>
  34. <th><h4>Category</h4></th>
  35. <th><h4>Subcategory</h4></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. <?php
  40. while($row = mysqli_fetch_array($result1)):
  41. $subquery1 = "SELECT `category`.`categoria` FROM `category` WHERE `category`.`id`=(SELECT `question`.`id_category` FROM `question` WHERE `question`.`id`=".$row['id'].");";
  42. $subresult1 = mysqli_query($connection, $subquery1);
  43. $subrow1 = mysqli_fetch_array($subresult1);
  44. $subquery2 = "SELECT `subcategory`.`subcategoria` FROM `subcategory` WHERE `subcategory`.`id`=(SELECT `question`.`id_subcategory` FROM `question` WHERE `question`.`id`=".$row['id'].");";
  45. $subresult2 = mysqli_query($connection, $subquery2);
  46. $subrow2 = mysqli_fetch_array($subresult2);
  47. ?>
  48. <tr>
  49. <th><?php echo $row['id']; ?></th>
  50. <td class='text-justify' style='width:35em;'><p><?php echo $row['premise']; ?></p></td>
  51. <td style='width:18em;'><p><?php echo $subrow1['categoria']; ?></p></td>
  52. <td style='width:18em;'><p><?php echo $subrow2['subcategoria']; ?></p></td>
  53. <td style='text-align:center;width:10em;'>
  54. <div class='btn-group'>
  55. <button type='button' class='btn btn-default btn-sm' data-toggle='modal' data-target='#Edit_<?php echo $row['id']; ?>'>Edit</button>
  56. <button type='button' class='btn btn-danger btn-sm' data-toggle='modal' data-target='#Delete_<?php echo $row['id']; ?>'>Delete</button>
  57. </div>
  58. </td>
  59. </tr>
  60. <?php $x++; endwhile; ?>
  61. </tbody>
  62. </table>
  63. </div><!--col-->
  64. </div><!--row-->
  65. <?php endif; ?>
  66. </div><!--container-->
  67. <!-- POPUP FOR NEW QUESTION -->
  68. <form class='form-horizontal' action='processes/insertQuestion.php' method='POST'>
  69. <div class='modal fade' id='New' tabindex='-1' role='dialog' aria-labelledby='NewLabel' aria-hidden='true'>
  70. <div class='modal-dialog modal-dialog-centered' role='document'>
  71. <div class='modal-content'>
  72. <div class='modal-header'>
  73. <h3 class='modal-title' id='NewLabel'>New Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  74. </div>
  75. <div class='modal-body'>
  76. <br>
  77. <!-- PREMISE -->
  78. <div class='form-group'>
  79. <label class='col-sm-offset-1 control-label col-sm-2' for='question_premise'>Premise:</label>
  80. <div class='col-sm-7'>
  81. <textarea type='text' class='form-control' id='question_premise' name='question_premise' rows=4 style='resize:vertical'></textarea>
  82. </div>
  83. </div>
  84. <!-- CATEGORY -->
  85. <div class='form-group'>
  86. <label class='col-sm-offset-1 control-label col-sm-2' for='question_category'>Category:</label>
  87. <div class='col-sm-7'>
  88. <select name='question_category' id='question_category' style='width:100%;'>
  89. <option disabled selected>Select the Category</option>
  90. <?php
  91. // CAMBIAR $query A "SELECT `id`, `categoria` FROM `category` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  92. $query2 = "SELECT `id`, `categoria` FROM `category`;";
  93. $result2 = mysqli_query($connection, $query2);
  94. foreach($result2 as $categorias):
  95. ?>
  96. <option value="<?php echo $categorias['id']; ?>"><?php echo $categorias['categoria']; ?></option>
  97. <?php endforeach; ?>
  98. </select>
  99. </div>
  100. </div>
  101. <!-- SUBCATEGORY -->
  102. <div class='form-group'>
  103. <label class='col-sm-offset-1 control-label col-sm-2' for='question_subcategory'>Subcategory:</label>
  104. <div class='col-sm-7'>
  105. <select name='question_subcategory' id='question_subcategory' style='width:100%;'>
  106. <option disabled selected>Select the Subcategory</option>
  107. <?php
  108. // CAMBIAR $query A "SELECT `id`, `subcategoria` FROM `subcategory` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  109. $query3 = "SELECT `id`, `subcategoria` FROM `subcategory`;";
  110. $result3 = mysqli_query($connection, $query3);
  111. foreach($result3 as $subcategorias):
  112. ?>
  113. <option value="<?php echo $subcategorias['id']; ?>"><?php echo $subcategorias['subcategoria']; ?></option>
  114. <?php endforeach; ?>
  115. </select>
  116. </div>
  117. </div>
  118. <!-- TYPE -->
  119. <div class='form-group'>
  120. <label class='col-sm-offset-1 control-label col-sm-2' for='question_type'>Type:</label>
  121. <div class='col-sm-7'>
  122. <select name='question_type' id='question_type' style='width:100%;'>
  123. <option disabled selected>Select the Type of Question</option>
  124. <?php
  125. // CAMBIAR $query A "SELECT `id`, `description` FROM `type_of_question` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  126. $query4 = "SELECT `id`, `description` FROM `type_of_question`;";
  127. $result4 = mysqli_query($connection, $query4);
  128. foreach($result4 as $types):
  129. ?>
  130. <option value="<?php echo $types['id']; ?>"><?php echo $types['description']; ?></option>
  131. <?php endforeach; ?>
  132. </select>
  133. </div>
  134. </div>
  135. <!-- REFERENCE -->
  136. <div class='form-group'>
  137. <label class='col-sm-offset-1 control-label col-sm-2' for='question_reference'>Reference:</label>
  138. <div class='col-sm-7'>
  139. <select name='question_reference' id='question_reference' style='width:100%;'>
  140. <option disabled selected>Select the Reference</option>
  141. <?php
  142. // CAMBIAR $query A "SELECT `id`, `referencia` FROM `reference` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  143. $query5 = "SELECT `id`, `referencia` FROM `reference`;";
  144. $result5 = mysqli_query($connection, $query5);
  145. foreach($result5 as $references):
  146. ?>
  147. <option value="<?php echo $references['id']; ?>"><?php echo $references['referencia']; ?></option>
  148. <?php endforeach; ?>
  149. </select>
  150. </div>
  151. </div>
  152. <br>
  153. </div><!--modal-body-->
  154. <!-- SUBMIT OR CANCEL -->
  155. <div class='modal-footer'>
  156. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  157. <button type='submit' class='btn btn-primary' name='insertQuestion' disabled>Save</button>
  158. </div>
  159. </div><!--modal-content-->
  160. </div><!--modal-dialog-->
  161. </div><!--modal-->
  162. </form>
  163. <?php $result1 = mysqli_query($connection, $query1); ?>
  164. <?php while($row = mysqli_fetch_array($result1)): ?>
  165. <!-- POPUP FOR EDIT QUESTION -->
  166. <form class='form-horizontal' action='processes/updateQuestion.php' method='POST'>
  167. <div class='modal fade' id='Edit_<?php echo $row['id']; ?>' tabindex='-1' role='dialog' aria-labelledby='EditLabel_<?php echo $row['id']; ?>' aria-hidden='true'>
  168. <div class='modal-dialog modal-dialog-centered' role='document'>
  169. <div class='modal-content'>
  170. <div class='modal-header'>
  171. <h3 class='modal-title' id='EditLabel_<?php echo $row['id']; ?>'>Edit Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  172. </div>
  173. <div class='modal-body'>
  174. <br>
  175. <!-- PREMISE -->
  176. <div class='form-group'>
  177. <label class='col-sm-offset-1 control-label col-sm-2' for='newPremise'>Premise:</label>
  178. <div class='col-sm-7'>
  179. <textarea type='text' class='form-control' id='newPremise' name='newPremise' rows=4 style='resize:vertical'><?php echo $row['premise']; ?></textarea>
  180. </div>
  181. </div>
  182. <!-- CATEGORY -->
  183. <div class='form-group'>
  184. <label class='col-sm-offset-1 control-label col-sm-2' for='newCategory'>Category:</label>
  185. <div class='col-sm-7'>
  186. <select name='newCategory' id='newCategory' style='width:100%;'>
  187. <option disabled selected>Select the Category</option>
  188. <?php
  189. // CAMBIAR $query A "SELECT `id`, `categoria` FROM `category` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  190. $query2 = "SELECT `id`, `categoria` FROM `category`;";
  191. $result2 = mysqli_query($connection, $query2);
  192. foreach($result2 as $categorias):
  193. ?>
  194. <option value="<?php echo $categorias['id']; ?>"><?php echo $categorias['categoria']; ?></option>
  195. <?php endforeach; ?>
  196. </select>
  197. </div>
  198. </div>
  199. <!-- SUBCATEGORY -->
  200. <div class='form-group'>
  201. <label class='col-sm-offset-1 control-label col-sm-2' for='newSubcategory'>Subcategory:</label>
  202. <div class='col-sm-7'>
  203. <select name='newSubcategory' id='newSubcategory' style='width:100%;'>
  204. <option disabled selected>Select the Subcategory</option>
  205. <?php
  206. // CAMBIAR $query A "SELECT `id`, `subcategoria` FROM `subcategory` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  207. $query3 = "SELECT `id`, `subcategoria` FROM `subcategory`;";
  208. $result3 = mysqli_query($connection, $query3);
  209. foreach($result3 as $subcategorias):
  210. ?>
  211. <option value="<?php echo $subcategorias['id']; ?>"><?php echo $subcategorias['subcategoria']; ?></option>
  212. <?php endforeach; ?>
  213. </select>
  214. </div>
  215. </div>
  216. <!-- TYPE -->
  217. <div class='form-group'>
  218. <label class='col-sm-offset-1 control-label col-sm-2' for='newType'>Type:</label>
  219. <div class='col-sm-7'>
  220. <select name='newType' id='newType' style='width:100%;'>
  221. <option disabled selected>Select the Type of Question</option>
  222. <?php
  223. // CAMBIAR $query A "SELECT `id`, `description` FROM `type_of_question` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  224. $query4 = "SELECT `id`, `description` FROM `type_of_question`;";
  225. $result4 = mysqli_query($connection, $query4);
  226. foreach($result4 as $types):
  227. ?>
  228. <option value="<?php echo $types['id']; ?>"><?php echo $types['description']; ?></option>
  229. <?php endforeach; ?>
  230. </select>
  231. </div>
  232. </div>
  233. <!-- REFERENCE -->
  234. <div class='form-group'>
  235. <label class='col-sm-offset-1 control-label col-sm-2' for='newReference'>Reference:</label>
  236. <div class='col-sm-7'>
  237. <select name='newReference' id='newReference' style='width:100%;'>
  238. <option disabled selected>Select the Reference</option>
  239. <?php
  240. // CAMBIAR $query A "SELECT `id`, `referencia` FROM `reference` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  241. $query5 = "SELECT `id`, `referencia` FROM `reference`;";
  242. $result5 = mysqli_query($connection, $query5);
  243. foreach($result5 as $references):
  244. ?>
  245. <option value="<?php echo $references['id']; ?>"><?php echo $references['referencia']; ?></option>
  246. <?php endforeach; ?>
  247. </select>
  248. </div>
  249. </div>
  250. <br>
  251. </div><!--modal-body-->
  252. <!-- SUBMIT OR CANCEL -->
  253. <div class='modal-footer'>
  254. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  255. <button type='submit' class='btn btn-primary' name='updateQuestion' disabled>Save</button>
  256. </div>
  257. </div><!--modal-content-->
  258. </div><!--modal-dialog-->
  259. </div><!--modal-->
  260. </form>
  261. <!-- POPUP FOR DELETE QUESTION -->
  262. <form class='form-horizontal' action='processes/deleteQuestion.php' method='POST'>
  263. <div class='modal fade' id='Delete_<?php echo $row['id']; ?>' tabindex='-1' role='dialog' aria-labelledby='DeleteLabel_<?php echo $row['id']; ?>' aria-hidden='true'>
  264. <div class='modal-dialog modal-dialog-centered' role='document'>
  265. <div class='modal-content'>
  266. <div class='modal-header'>
  267. <h3 class='modal-title' id='DeleteLabel_<?php echo $row['id']; ?>'>Delete Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  268. </div>
  269. <div class='modal-body'>
  270. <!-- ID -->
  271. <input type='hidden' name='id' value='<?php echo $row['id']; ?>'>
  272. <span class='text-center'>
  273. <h3>Are you sure you want to delete this question?</h3>
  274. <h3 style='color:#ff8f00;'><?php echo $row['premise']; ?></h3>
  275. </span>
  276. <br>
  277. <p class='alert alert-warning text-justify'>This action will delete the question, removing it from existing <b>questionnaires and subquestionnaires</b>, while also deleting <b>all results</b> that were made from this question. You should be aware of this and opt to edit manually any affected questionnaires and subquestionnaires in the following pages: <a class='alert-link' href='bankOfQuestions.php'>questions</a> and <a class='alert-link' href='questionnaires.php'>questionnaires</a>.</p>
  278. <br>
  279. </div><!--modal-body-->
  280. <!-- SUBMIT OR CANCEL -->
  281. <div class='modal-footer'>
  282. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  283. <button type='submit' class='btn btn-danger' name='deleteQuestion' disabled>Delete Anyway</button>
  284. </div>
  285. </div><!--modal-content-->
  286. </div><!--modal-dialog-->
  287. </div><!--modal-->
  288. </form>
  289. <?php endwhile; ?>
  290. <!-- END OF bankOfQuestions.php -->
  291. <?php include_once 'footer.php'; ?>