Nav apraksta

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 CATEGORIES, DISPLAY THEM
  7. // ELSE DON'T DISPLAY THE EMPTY TABLE
  8. // CAMBIAR $query A "SELECT * FROM `category` WHERE `id_researcher`='".$dbUserData['id_researcher']."';"
  9. $query1 = "SELECT * FROM `category`;";
  10. $result1 = mysqli_query($connection, $query1);
  11. $x = 1;
  12. ?>
  13. <!-- START OF categories.php -->
  14. <div class='container'>
  15. <div class='row'>
  16. <div class='col-sm-10'>
  17. <h2>Categories</h2>
  18. <p>View, add, and delete any category you like so that, later on, you can categorize a question. You can also view, add, or delete any subcategory.</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 Category</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. <!-- DISPLAY AVAILABLE CATEGORIES -->
  30. <table class='table table-hover table-striped' id='tableEvaluations' align='center'>
  31. <thead>
  32. <tr>
  33. <th><h4>#</h4></th>
  34. <th><h4>Category</h4></th>
  35. <th><h4>Related Subcategories</h4></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. <?php while($row = mysqli_fetch_array($result1)): ?>
  40. <tr>
  41. <th><?php echo $row['id']; ?></th>
  42. <td><?php echo $row['categoria']; ?></td>
  43. <td>
  44. <ul>
  45. <?php
  46. $query2 = "SELECT * FROM `subcategory` WHERE `id_categoria`=".$row['id'].";";
  47. $result2 = mysqli_query($connection, $query2);
  48. while($subrow = mysqli_fetch_array($result2)):
  49. ?>
  50. <li><?php echo $subrow['subcategoria']; ?></li>
  51. <?php endwhile; ?>
  52. </ul>
  53. </td>
  54. <td style='text-align:center;'>
  55. <div class='btn-group'>
  56. <button type='button' class='btn btn-default btn-sm' data-toggle='modal' data-target='#Edit_<?php echo $row['id']; ?>'>Edit</button>
  57. <button type='button' class='btn btn-danger btn-sm' data-toggle='modal' data-target='#Delete_<?php echo $row['id']; ?>'>Delete</button>
  58. </div>
  59. </td>
  60. </tr>
  61. <?php $x++; endwhile; ?>
  62. </tbody>
  63. </table>
  64. </div><!--col-->
  65. </div><!--row-->
  66. <?php endif; ?>
  67. </div><!--container-->
  68. <!-- POPUP FOR NEW CATEGORY -->
  69. <form class='form-horizontal' action='processes/insertCategory.php' method='POST'>
  70. <div class='modal fade' id='New' tabindex='-1' role='dialog' aria-labelledby='NewLabel' aria-hidden='true'>
  71. <div class='modal-dialog modal-dialog-centered modal-lg' role='document'>
  72. <div class='modal-content'>
  73. <div class='modal-body'>
  74. <!-- CLOSE BUTTON -->
  75. <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
  76. <!-- NEW TITLE -->
  77. <br>
  78. <div class='form-group'>
  79. <label class='col-sm-2 control-label'>Title:</label>
  80. <div class='col-sm-7'>
  81. <input class='form-control' type='text' name='categoria'>
  82. </div>
  83. <button type='submit' class='btn btn-primary' name='insertCategory' disabled>Save</button>
  84. </div>
  85. </div><!--modal-body-->
  86. </div><!--modal-content-->
  87. </div><!--modal-dialog-->
  88. </div><!--modal-->
  89. </form>
  90. <?php $result1 = mysqli_query($connection, $query1); ?>
  91. <?php while($row = mysqli_fetch_array($result1)): ?>
  92. <!-- POPUP FOR EDIT CATEGORY -->
  93. <form class='form-horizontal' action='processes/updateCategory.php' method='POST'>
  94. <div class='modal fade' id='Edit_<?php echo $row['id']; ?>' tabindex='-1' role='dialog' aria-labelledby='EditLabel_<?php echo $row['id']; ?>' aria-hidden='true'>
  95. <div class='modal-dialog modal-dialog-centered' role='document'>
  96. <div class='modal-content'>
  97. <div class='modal-header'>
  98. <h3 class='modal-title' id='EditLabel_<?php echo $row['id']; ?>'>Edit Category<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  99. </div>
  100. <div class='modal-body'>
  101. <span class='text-center'>
  102. <h3 style='color:#ff8f00;'><?php echo $row['categoria']; ?></h3>
  103. <br>
  104. <h4>Subcategories:</h4>
  105. <h6>(check the ones you wish to delete)</h6>
  106. </span>
  107. <br>
  108. <div class='row'>
  109. <div class='col'>
  110. <ul>
  111. <?php
  112. $query2 = "SELECT * FROM `subcategory` WHERE `id_categoria`=".$row['id'].";";
  113. $result2 = mysqli_query($connection, $query2);
  114. while($subrow = mysqli_fetch_array($result2)):
  115. ?>
  116. <div class='row'>
  117. <li class='col-sm-offset-3 col-sm-5'><?php echo $subrow['subcategoria']; ?></li>
  118. <input class='col-sm-1' type='checkbox' name='deleteSubcategory_<?php $subrow['id']; ?>' value='<?php $subrow['id']; ?>'>
  119. <!--<li style='list-style:none;' class='col-sm-3'><a class='btn btn-danger btn-xs' href='#'>Remove</a></li>-->
  120. </div>
  121. <br>
  122. <?php endwhile; ?>
  123. </ul>
  124. </div>
  125. </div>
  126. <br>
  127. <div class='form-group'>
  128. <label class='col-sm-offset-1 control-label col-sm-3' for='newSubcategory'>Add Subcategory:</label>
  129. <div class='col-sm-5' id='addQuestionnaires'>
  130. <!-- OJO TENGO QUE NOMBRAR EL ID DEL SELECT DIFERENTE-->
  131. <select id='questionnaire' name='newSubcategory' style='width:100%;'>
  132. <option disabled selected>Select the Subcategory</option>
  133. <?php
  134. // CAMBIAR $query A "SELECT * FROM `subcategory` WHERE `id_categoria`=".$row['id']." AND `id_researcher`='".$dbUserData['id_researcher']."';"
  135. $query3 = "SELECT * FROM `subcategory`;";
  136. $result3 = mysqli_query($connection, $query3);
  137. foreach($result3 as $subcategories):
  138. ?>
  139. <option value="<?php echo $subcategories['id']; ?>"><?php echo $subcategories['subcategoria']; ?></option>
  140. <?php endforeach; ?>
  141. </select>
  142. </div>
  143. <!-- ADD MORE SUBCATEGORIES -->
  144. <div class='col-sm-2'>
  145. <button type='button' class='btn btn-xs btn-warning' onclick='AddQuestionnaire()' style='color: white;'><b>Add More</b></button>
  146. </div>
  147. </div>
  148. <br>
  149. <p class='alert alert-warning text-justify'>Deleting any selected subcategory will change every <b>question</b> associated with it to have an <b>unknown subcategory</b>. You should be aware of this and opt to edit manually any affected question in the following page: <a class='alert-link' href='bankOfQuestions.php'>questions</a>.</p>
  150. <br>
  151. </div><!--modal-body-->
  152. <!-- SUBMIT OR CANCEL -->
  153. <div class='modal-footer'>
  154. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  155. <button type='submit' class='btn btn-primary' name='updateCategory' disabled>Save</button>
  156. </div>
  157. </div><!--modal-content-->
  158. </div><!--modal-dialog-->
  159. </div><!--modal-->
  160. </form>
  161. <!-- POPUP FOR DELETE CATEGORY -->
  162. <form class='form-horizontal' action='processes/deleteCategory.php' method='POST'>
  163. <div class='modal fade' id='Delete_<?php echo $row['id']; ?>' tabindex='-1' role='dialog' aria-labelledby='DeleteLabel_<?php echo $row['id']; ?>' aria-hidden='true'>
  164. <div class='modal-dialog modal-dialog-centered' role='document'>
  165. <div class='modal-content'>
  166. <div class='modal-header'>
  167. <h3 class='modal-title' id='DeleteLabel_<?php echo $row['id']; ?>'>Delete Category<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  168. </div>
  169. <div class='modal-body'>
  170. <!-- ID -->
  171. <input type='hidden' name='id' value='<?php echo $row['id']; ?>'>
  172. <span class='text-center'>
  173. <h3>Are you sure you want to delete this category?</h3>
  174. <h3 style='color:#ff8f00;'><?php echo $row['categoria']; ?></h3>
  175. </span>
  176. <br>
  177. <p class='alert alert-warning text-justify'>This action will delete the category and change every <b>question</b> associated with it to have an <b>unknown category (and subcategory)</b>. It will also delete any associated subcategory stored in the database. You should be aware of this and opt to edit manually any affected question in the following page: <a class='alert-link' href='bankOfQuestions.php'>questions</a>.</p>
  178. <br>
  179. </div><!--modal-body-->
  180. <!-- SUBMIT OR CANCEL -->
  181. <div class='modal-footer'>
  182. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  183. <button type='submit' class='btn btn-danger' name='deleteCategory' disabled>Delete Anyway</button>
  184. </div>
  185. </div><!--modal-content-->
  186. </div><!--modal-dialog-->
  187. </div><!--modal-->
  188. </form>
  189. <?php endwhile; ?>
  190. <!-- END OF categories.php -->
  191. <?php
  192. include_once 'footer.php';
  193. ?>