Sin descripción

viewMoment.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. // Description: EXTRACT MOMENT ID, AND IF VALID, DISPLAY ITS INFO
  3. require_once 'processes/config.php';
  4. require_once 'processes/dbh.inc.php';
  5. require_once 'processes/checkLogin.php';
  6. // IF VIEW VARIABLE NOT GIVEN, EXIT
  7. if(!isset($_GET['view'])) {
  8. exit();
  9. }
  10. // WARNING: CHANGE QUERY TO INCLUDE "`id_researcher` = '".$dbUserData['id_researcher']."';"
  11. $momentID = mysqli_real_escape_string($connection, trim($_GET['view']));
  12. $query1 = "SELECT * FROM subquestionnair WHERE id = '$momentID';";
  13. $result1 = mysqli_query($connection, $query1) or die("Error: ".mysqli_error($connection));
  14. $row1 = mysqli_fetch_array($result1);
  15. // IF MOMENT NOT IN DATABASE, EXIT
  16. if($result1->num_rows !== 1) {
  17. exit();
  18. }
  19. // EXTRACT & DISPLAY THE NUMBER OF QUESTIONS IN THE MOMENT
  20. $queryNumQuestions = "SELECT * FROM question WHERE id IN (SELECT id_question FROM subquestionnair_question WHERE id_subquestionnair = '$momentID');";
  21. $resultNumQuestions = mysqli_query($connection, $queryNumQuestions);
  22. $numQuestions = $resultNumQuestions->num_rows;
  23. include_once 'header.php';
  24. ?>
  25. <!-- START OF viewMoment.php -->
  26. <body>
  27. <header id="main-header">
  28. <a id="logo" href=".">
  29. TANIA
  30. <img src="./img/pen_800x800.png" alt="tania logo pen" width="25" height="25">
  31. </a>
  32. <div id="account">
  33. <a class="nav-link" href="./questionnaires.php">Questionnaire Collection</a>
  34. <a class="sign-out" href="./processes/logout.php">Sign Out</a>
  35. </div>
  36. </header>
  37. <div class="container" style="margin-top: 8rem; min-height: calc(100vh - 8rem - 10vh);">
  38. <div class="row">
  39. <div class="col-sm-8">
  40. <h2>Moment</h2>
  41. <p><font size='4'><b> Title: </b> <?php echo $row1['title']; ?></font></p>
  42. <p><font size='4'><b> Description: </b> <?php echo $row1['description']; ?></font></p>
  43. <p><font size='4'><b> Due Date: </b><?php echo date("M j, Y (g:i A)", strtotime($row1['date_to_administer'])); ?></font></p>
  44. <p><font size='4'><b> Amount of Questions: </b> <?php echo $numQuestions; ?></font></p>
  45. </div>
  46. <div class="col-sm-4">
  47. <div class="hidden-xs">
  48. <br><br><br>
  49. </div>
  50. <div id="view-experience-buttons" style="max-width: 18rem;">
  51. <div data-toggle="tooltip" data-placement="top" title="Add Existing Question" id="experience-pen" onclick="nextModal('#AddQuestion')">
  52. <span class="fas fa-plus"></span>
  53. </div>
  54. <div data-toggle="tooltip" data-placement="top" title="Edit Moment" id="experience-pen" onclick="nextModal('#Edit')">
  55. <span class="fas fa-pen"></span>
  56. </div>
  57. </div>
  58. </div>
  59. </div><!--row-->
  60. <br>
  61. <div class="row">
  62. <div class="col-sm-12">
  63. <?php if($numQuestions > 0): ?>
  64. <table class="table table-hover table-striped" id="tableEvaluations">
  65. <thead>
  66. <tr>
  67. <th><h4>#</h4></th>
  68. <th><h4>Premise</h4></th>
  69. </tr>
  70. </thead>
  71. <tbody>
  72. <?php
  73. $query2 = "SELECT * FROM question WHERE id IN (SELECT id_question FROM subquestionnair_question WHERE id_subquestionnair = '$momentID');";
  74. $result2 = mysqli_query($connection, $query2);
  75. $x = 1;
  76. while($row2 = mysqli_fetch_array($result2)):
  77. $queryMinText = "SELECT value FROM question_type WHERE label = 'min_texto' AND id_question = '" . $row2['id'] . "';";
  78. $resultMinText = mysqli_query($connection, $queryMinText);
  79. $rowMinText = mysqli_fetch_array($resultMinText);
  80. $queryMaxVal = "SELECT value FROM question_type WHERE label = 'max_val' AND id_question = '" . $row2['id']. "';";
  81. $resultMaxVal = mysqli_query($connection, $queryMaxVal);
  82. $rowMaxVal = mysqli_fetch_array($resultMaxVal);
  83. $queryMaxText = "SELECT value FROM question_type WHERE label = 'max_texto' AND id_question = '" . $row2['id']. "';";
  84. $resultMaxText = mysqli_query($connection, $queryMaxText);
  85. $rowMaxText = mysqli_fetch_array($resultMaxText);
  86. ?>
  87. <tr style="cursor: pointer;" data-toggle="modal" data-target="#EditQuestion" data-question-number="<?php echo $x; ?>" data-question-id="<?php echo $row2['id']; ?>" data-premise="<?php echo $row2['premise']; ?>" data-type="<?php echo $row2['id_type']; ?>" data-min_text="<?php echo $rowMinText['value']; ?>" data-max_val="<?php echo $rowMaxVal['value']; ?>" data-max_text="<?php echo $rowMaxText['value']; ?>" data-categoryid="<?php echo $row2['id_category']; ?>" data-subcategoryid="<?php echo $row2['id_subcategory']; ?>">
  88. <th><?php echo $x; ?></th>
  89. <td><p><?php echo $row2['premise']; ?></p></td>
  90. <!-- confirmDeleteQuestionSubquestionnaire.php?del=<?php echo $row2['id']; ?>&quest=<?php echo $momentID; ?> -->
  91. </tr>
  92. <?php $x++; endwhile; ?>
  93. </tbody>
  94. </table>
  95. <?php else: ?>
  96. <h3 class="text-center"><small>It seems you haven't added any questions to this moment...</small></h3>
  97. <?php endif; ?>
  98. </div><!-- col -->
  99. </div><!-- row -->
  100. <br>
  101. <div class="row">
  102. <div class="col-sm-2 col-sm-offset-5">
  103. <div data-toggle="tooltip" data-placement="top" title="Add Existing Question" id="experience-pen" onclick="nextModal('#AddQuestion')" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  104. <span class="fas fa-plus"></span>
  105. </div>
  106. </div>
  107. </div>
  108. <br><br>
  109. </div><!-- container -->
  110. <!-- POPUP FOR EDIT MOMENT -->
  111. <form id="updateMoment" class="form-horizontal">
  112. <div class="modal fade" id="Edit" tabindex="-1" role="dialog" aria-labelledby="EditLabel" aria-hidden="true">
  113. <div class="modal-dialog" role="document">
  114. <div class="modal-content">
  115. <div class="modal-header">
  116. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  117. <span aria-hidden="true">&times;</span>
  118. </button>
  119. <h3 class="modal-title" id="EditLabel">Edit Moment</h3>
  120. </div>
  121. <div class="modal-body">
  122. <!-- ID -->
  123. <input type="hidden" name="momentID" value="<?php echo $momentID; ?>">
  124. <!-- TITLE -->
  125. <br>
  126. <div class="form-group">
  127. <label class="col-sm-offset-1 control-label col-sm-2" for="newTitle">Title:</label>
  128. <div class="col-sm-7">
  129. <input type="text" class='form-control text-center' id="newTitle" name="newTitle" value="<?php echo $row1['title']; ?>">
  130. </div>
  131. </div>
  132. <!-- DESCRIPTION -->
  133. <div class="form-group">
  134. <label class="col-sm-offset-1 control-label col-sm-2" for="newDescription">Description:</label>
  135. <div class="col-sm-7">
  136. <textarea class="form-control text-center" id="newDescription" name="newDescription" rows="2"><?php echo $row1['description']; ?></textarea>
  137. </div>
  138. </div>
  139. <br>
  140. <!-- ERROR ALERT FOR USER -->
  141. <div id="error-updateMoment" class="row" style="display: none;">
  142. <div class="col-sm-12">
  143. <div class="alert alert-danger mb-1" role="alert">
  144. <h4 class="error-lead">Error!</h4>
  145. <p class="error-description"></p>
  146. </div>
  147. </div>
  148. </div>
  149. </div><!--modal-body-->
  150. <!-- SUBMIT OR CANCEL -->
  151. <div class="modal-footer">
  152. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  153. <button type="button" class="btn btn-danger" data-dismiss="modal" onclick="nextModal('#DeleteMoment')">Delete</button>
  154. <button type="submit" class="btn btn-primary" name="updateMoment">Save Changes</button>
  155. </div>
  156. </div><!--modal-content-->
  157. </div><!--modal-dialog-->
  158. </div><!--modal-->
  159. </form>
  160. <!-- POPUP FOR DELETE MOMENT -->
  161. <form id="deleteMoment">
  162. <div class='modal fade' id='DeleteMoment' tabindex='-1' role='dialog' aria-labelledby='DeleteMomentLabel' aria-hidden='true'>
  163. <div class='modal-dialog modal-dialog-centered' role='document'>
  164. <div class='modal-content'>
  165. <div class='modal-header'>
  166. <h3 class='modal-title' id='DeleteMomentLabel'>Delete Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  167. </div>
  168. <div class='modal-body'>
  169. <!-- QUESTIONNAIRE ID -->
  170. <input type='hidden' name='momentID' value="<?php echo $momentID; ?>">
  171. <span class='text-center'>
  172. <h3>Are you sure you want to delete this Moment?</h3>
  173. <!-- <h3 id="deletePremise" style='color:#ff8f00;'></h3> -->
  174. </span>
  175. <br>
  176. <p class='alert alert-warning text-justify'>This action will delete the moment. If you have any problems, contact technical support at: <a class='alert-link' href='#'>support@tania.uprrp.edu</a>.</p>
  177. <br>
  178. <!--You should be aware of this and opt to edit manually any affected moments and experiences in the following pages: <a class='alert-link' href='#'>experience</a>.-->
  179. <!-- ERROR ALERT FOR USER -->
  180. <div id="error-deleteMoment" class="row" style="display: none;">
  181. <div class="col-sm-12">
  182. <div class="alert alert-danger mb-1" role="alert">
  183. <h4 class="error-lead">Error!</h4>
  184. <p class="error-description"></p>
  185. </div>
  186. </div>
  187. </div>
  188. </div><!--modal-body-->
  189. <!-- SUBMIT OR CANCEL -->
  190. <div class='modal-footer'>
  191. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  192. <button type='submit' class='btn btn-danger' name='deleteMoment'>Delete Anyway</button>
  193. </div>
  194. </div><!--modal-content-->
  195. </div><!--modal-dialog-->
  196. </div><!--modal-->
  197. </form>
  198. <!-- POPUP FOR ADDING QUESTION TO MOMENT -->
  199. <form id="addExistingQuestionToMoment">
  200. <div class="modal fade" id="AddQuestion" tabindex="-1" role="dialog" aria-labelledby="AddQuestionLabel" aria-hidden="true">
  201. <div class="modal-dialog" role="document">
  202. <div class="modal-content">
  203. <div class="modal-header">
  204. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  205. <span aria-hidden="true">&times;</span>
  206. </button>
  207. <h3 class="modal-title" id="AddQuestionLabel">Add Question</h3>
  208. </div>
  209. <div class="modal-body">
  210. <!-- MOMENT ID -->
  211. <input type="hidden" name="momentID" value="<?php echo $momentID; ?>">
  212. <div class="row">
  213. <div class="col-sm-12 col-sm-offset-1">
  214. <h4>Choose Existing Question</h4>
  215. </div>
  216. </div>
  217. <!-- QUESTION ID -->
  218. <div class="form-horizontal">
  219. <div class="form-group">
  220. <div class='col-sm-offset-2 col-sm-9'>
  221. <select class="form-control" id="questionID" name="questionID" style="width:100%; text-align-last:center;" required>
  222. <!-- <option disabled selected value>Select Question</option> -->
  223. <?php
  224. $queryQuestions = "SELECT * FROM `question` WHERE `id` IN (SELECT `id_question` FROM `questionnair_question` WHERE `id_questionnair` = (SELECT id_questionnair FROM subquestionnair WHERE id = '$momentID'));";
  225. $resultQuestions = mysqli_query($connection, $queryQuestions);
  226. while($rowQuestions = mysqli_fetch_assoc($resultQuestions)):
  227. ?>
  228. <option value="<?php echo $rowQuestions['id']; ?>"><?php echo $rowQuestions['premise']; ?></option>
  229. <?php endwhile; ?>
  230. </select>
  231. </div>
  232. </div>
  233. </div>
  234. <!-- ERROR ALERT FOR USER -->
  235. <div id="error-addExistingQuestionToMoment" class="row" style="display: none;">
  236. <div class="col-sm-12">
  237. <div class="alert alert-danger mb-1" role="alert">
  238. <h4 class="error-lead">Error!</h4>
  239. <p class="error-description"></p>
  240. </div>
  241. </div>
  242. </div>
  243. </div><!--modal-body-->
  244. <!-- SUBMIT OR CANCEL -->
  245. <div class="modal-footer">
  246. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  247. <button type="submit" class="btn btn-primary" name="addExistingQuestionToMoment">Add</button>
  248. </div>
  249. </div><!--modal-content-->
  250. </div><!--modal-dialog-->
  251. </div><!--modal-->
  252. </form>
  253. <!-- POPUP FOR EDIT QUESTION FROM MOMENT -->
  254. <form id="updateQuestion">
  255. <div class='modal fade' id='EditQuestion' tabindex='-1' role='dialog' aria-labelledby='EditQuestionLabel' aria-hidden='true'>
  256. <div class='modal-dialog modal-lg' role='document'>
  257. <div class='modal-content'>
  258. <div class='modal-header'>
  259. <h3 class='modal-title' id='EditQuestionLabel'>Edit Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  260. </div>
  261. <div class='modal-body'>
  262. <!-- QUESTIONNAIRE ID -->
  263. <!-- <input type='hidden' name='questionnaireID'> -->
  264. <!-- QUESTION ID -->
  265. <input type='hidden' name='questionID'>
  266. <br>
  267. <div class="row">
  268. <div class="col-sm-12 col-sm-offset-1">
  269. <h4>Question <span class="question-number"></span></h4>
  270. </div>
  271. </div>
  272. <div class="form-horizontal">
  273. <!-- PREMISE -->
  274. <div class="form-group">
  275. <label class='col-sm-offset-1 control-label col-sm-2'>Premise:</label>
  276. <div class='col-sm-8'>
  277. <input id="update_q_premise" type="text" class="form-control text-center" name="update_q_premise" placeholder="Premise" maxlength="600" required>
  278. </div>
  279. </div>
  280. <!-- TYPE -->
  281. <div class="form-group">
  282. <label class='col-sm-offset-1 control-label col-sm-2'>Question Type:</label>
  283. <div class='col-sm-8'>
  284. <select class="form-control text-center" id="update_q_type" name="update_q_type" style="width:100%; text-align-last:center;" onchange="newThing(event)" required>
  285. <!-- <option disabled selected value="">Type</option> -->
  286. <option value="1">Scaled</option>
  287. <option value="2">Open Answer</option>
  288. </select>
  289. </div>
  290. </div>
  291. </div>
  292. <!-- MIN/MAX VALUES/TEXT (OPTIONAL) -->
  293. <div class="range">
  294. <div class="form-inline col col-sm-offset-2">
  295. <div class="form-group">
  296. <label class='control-label col-sm-2'>Min. Value:</label>
  297. <div class="col-sm-8">
  298. <input type="number" class="form-control text-center" id="update_min_val" name="update_min_val" value="1" readonly>
  299. </div>
  300. </div>
  301. <div class="form-group">
  302. <label class='control-label col-sm-2'>Min. Text:</label>
  303. <div class="col-sm-8">
  304. <input type="text" class="form-control text-center" id="update_min_text" name="update_min_text" maxlength="40" placeholder="Very Dissatisfied">
  305. </div>
  306. </div>
  307. </div>
  308. <div class="form-inline col col-sm-offset-2">
  309. <div class="form-group">
  310. <label class='control-label col-sm-2'>Max. Value:</label>
  311. <div class="col-sm-1">
  312. <input type="number" class="form-control text-center" id="update_max_val" name="update_max_val" value="5" min="2">
  313. </div>
  314. </div>
  315. <div class="form-group">
  316. <label class='control-label col-sm-2'>Max. Text:</label>
  317. <div class="col-sm-1">
  318. <input type="text" class="form-control text-center" id="update_max_text" name="update_max_text" maxlength="40" placeholder="Very Satisfied">
  319. </div>
  320. </div>
  321. </div>
  322. <br>
  323. </div>
  324. <div class="form-horizontal">
  325. <!-- CORRESPONDING CATEGORY -->
  326. <div class="form-group">
  327. <label class='col-sm-offset-1 control-label col-sm-2'>Category:</label>
  328. <div class='col-sm-8'>
  329. <select class="form-control text-center" id="update_q_category" name="update_q_category" style="width: 100%; text-align-last:center;" required>
  330. <!-- <option disabled selected value="">Category</option> -->
  331. <?php
  332. $queryCategories = "SELECT * FROM category WHERE id IN (SELECT id_category FROM question WHERE id IN (SELECT id_question FROM subquestionnair_question WHERE id_subquestionnair = '$momentID'));";
  333. $resultCategories = mysqli_query($connection, $queryCategories);
  334. while($rowCategories = mysqli_fetch_array($resultCategories)):
  335. ?>
  336. <option value="<?php echo $rowCategories['id']; ?>"><?php echo $rowCategories['categoria']; ?></option>
  337. <?php endwhile; ?>
  338. </select>
  339. </div>
  340. </div>
  341. <!-- CORRESPONDING SUBCATEGORY -->
  342. <div class="form-group">
  343. <label class='col-sm-offset-1 control-label col-sm-2'>Subcategory:</label>
  344. <div class='col-sm-8'>
  345. <select class="form-control text-center" id="update_q_subcategory" name="update_q_subcategory" style="width: 100%; text-align-last:center;" required>
  346. <!-- <option disabled selected value="">Subcategory</option> -->
  347. <?php
  348. $querySubcategories = "SELECT * FROM subcategory WHERE id IN (SELECT id_subcategory FROM question WHERE id IN (SELECT id_question FROM subquestionnair_question WHERE id_subquestionnair = '$momentID'));";
  349. $resultSubcategories = mysqli_query($connection, $querySubcategories);
  350. while($rowSubcategories = mysqli_fetch_array($resultSubcategories)):
  351. ?>
  352. <option value="<?php echo $rowSubcategories['id']; ?>"><?php echo $rowSubcategories['subcategoria']; ?></option>
  353. <?php endwhile; ?>
  354. </select>
  355. </div>
  356. </div>
  357. </div>
  358. <br>
  359. <!-- ERROR ALERT FOR USER -->
  360. <div id="error-updateQuestion" class="row" style="display: none;">
  361. <div class="col-sm-12">
  362. <div class="alert alert-danger mb-1" role="alert">
  363. <h4 class="error-lead">Error!</h4>
  364. <p class="error-description"></p>
  365. </div>
  366. </div>
  367. </div>
  368. </div><!--modal-body-->
  369. <!-- SUBMIT OR CANCEL -->
  370. <div class='modal-footer'>
  371. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  372. <button type='button' class='btn btn-danger' data-dismiss='modal' onclick="nextModal('#Delete')">Remove</button>
  373. <button type='submit' class='btn btn-primary' name='updateQuestion'>Save Changes</button>
  374. </div>
  375. </div><!--modal-content-->
  376. </div><!--modal-dialog-->
  377. </div><!--modal-->
  378. </form>
  379. <!-- POPUP FOR REMOVE QUESTION FROM MOMENT -->
  380. <form id="removeQuestionFromMoment">
  381. <div class='modal fade' id='Delete' tabindex='-1' role='dialog' aria-labelledby='DeleteLabel' aria-hidden='true'>
  382. <div class='modal-dialog modal-dialog-centered' role='document'>
  383. <div class='modal-content'>
  384. <div class='modal-header'>
  385. <h3 class='modal-title' id='DeleteLabel'>Remove Question<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  386. </div>
  387. <div class='modal-body'>
  388. <!-- MOMENT ID -->
  389. <input type='hidden' name='momentID' value="<?php echo $momentID; ?>">
  390. <!-- QUESTION ID -->
  391. <input type='hidden' name='questionID'>
  392. <span class='text-center'>
  393. <h3>Are you sure you want to remove Question <span class="question-number"></span>?</h3>
  394. <!-- <h3 id="deletePremise" style='color:#ff8f00;'></h3> -->
  395. </span>
  396. <br>
  397. <p class='alert alert-warning text-justify'>This action will remove the question from this moment. If you have any problems, contact technical support at: <a class='alert-link' href='#'>support@tania.uprrp.edu</a>.</p>
  398. <br>
  399. <!-- ERROR ALERT FOR USER -->
  400. <div id="error-removeQuestionFromMoment" class="row" style="display: none;">
  401. <div class="col-sm-12">
  402. <div class="alert alert-danger mb-1" role="alert">
  403. <h4 class="error-lead">Error!</h4>
  404. <p class="error-description"></p>
  405. </div>
  406. </div>
  407. </div>
  408. </div><!--modal-body-->
  409. <!-- SUBMIT OR CANCEL -->
  410. <div class='modal-footer'>
  411. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  412. <button type='submit' class='btn btn-danger' name='removeQuestionFromMoment'>Remove Anyway</button>
  413. </div>
  414. </div><!--modal-content-->
  415. </div><!--modal-dialog-->
  416. </div><!--modal-->
  417. </form>
  418. <script src="js/viewMoment.js"></script>
  419. <script src="js/handleSubmit.js"></script>
  420. <script src="js/editQuestion.js"></script>
  421. <script>
  422. ["updateMoment", "removeQuestionFromMoment", "addExistingQuestionToMoment", "updateQuestion", "deleteMoment"].forEach(function(formName) {
  423. var form = document.getElementById(formName);
  424. if(form) {
  425. form.addEventListener('submit', function(e) {
  426. handleSubmit(e, formName);
  427. });
  428. }
  429. });
  430. </script>
  431. <!-- END OF viewMoment.php -->
  432. <?php include_once 'footer.php'; ?>