Nav apraksta

home.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. // RETRIEVE USER'S NAME AND PICTURE
  7. $query1 = "SELECT * FROM `researcher` WHERE `email` = '" . $_SESSION['email'] . "';";
  8. $result1 = mysqli_query($connection, $query1);
  9. $dbUserData = mysqli_fetch_assoc($result1);
  10. // IF USER NOT IN DATABASE, EXIT
  11. if($result1->num_rows !== 1) {
  12. exit();
  13. }
  14. ?>
  15. <!-- START OF home.php -->
  16. <body>
  17. <header id="main-header">
  18. <a id="logo" href=".">
  19. TANIA
  20. <img src="./img/pen_800x800.png" alt="tania logo pen" width="25" height="25">
  21. </a>
  22. <div id="account">
  23. <a class="nav-link" href="./questionnaires.php">Questionnaire Collection</a>
  24. <a class="sign-out" href="./processes/logout.php">Sign Out</a>
  25. </div>
  26. </header>
  27. <section id="welcome">
  28. <div id="welcome-text">
  29. <img id="welcome-image" src="<?php echo $dbUserData["picture"]; ?>" alt="User">
  30. <h2 id="welcome-user">Welcome <?php echo explode(" ", $dbUserData['name'])[0]; ?></h2>
  31. </div>
  32. </section>
  33. <main id="experience-main">
  34. <div class="experience-lead">
  35. <h2>Manage Your Experiences</h2>
  36. </div>
  37. <div id="experience-content">
  38. <!--change to #New when using experience as templates has been implemented-->
  39. <div class="grid-box" id="new-experience" onclick="nextModal('#New_2')">
  40. <span class="fas fa-plus"></span>
  41. <h4>New</h4>
  42. </div>
  43. <?php
  44. // WARNING: CHANGE QUERY TO INCLUDE "`id_researcher`='".$dbUserData['id_researcher']."';"
  45. $query2 = "SELECT * FROM `experience`;";
  46. $result2 = mysqli_query($connection, $query2);
  47. // IF USER HAS EXPERIENCES, SHOW ALL OF THEM
  48. // ELSE PROMPT USER TO CREATE A NEW EXPERIENCE
  49. if($result2->num_rows > 0): // USER HAS EXPERIENCE (STANDARD PAGE)
  50. ?>
  51. <?php while($row = mysqli_fetch_array($result2)): ?>
  52. <div class="grid-box" onclick="location='viewExperience.php?view=<?php echo $row['id']; ?>'">
  53. <?php if(mb_strlen($row['title']) == 0): ?>
  54. <span class="box-title" onclick="location='viewExperience.php?view=<?php echo $row['id']; ?>'"><small>N/A</small></span>
  55. <?php elseif(mb_strlen($row['title']) < 21): ?>
  56. <span class="box-title" onclick="location='viewExperience.php?view=<?php echo $row['id']; ?>'"><?php echo $row['title']; ?></span>
  57. <?php else: ?>
  58. <!--style="white-space: nowrap;"--><span class="box-title" onclick="location='viewExperience.php?view=<?php echo $row['id']; ?>'"><?php echo substr($row['title'], 0, 30)."<small>...</small>"; ?></span>
  59. <?php endif; ?>
  60. <div class="box-dates" onclick="location='viewExperience.php?view=<?php echo $row['id']; ?>'">
  61. <p style="margin-bottom: 0;">• Starts: <?php echo date("M j, Y", strtotime($row['start_date'])); ?></p>
  62. <p>• Ends: <?php echo date("M j, Y", strtotime($row['end_date'])); ?></p>
  63. </div>
  64. <?php
  65. $x = (strtotime($row['end_date']) - strtotime('now')) / 604800;
  66. if($x <= 0):
  67. ?>
  68. <span class="box-weeks warning">Finished</span>
  69. <?php else: ?>
  70. <span class="box-weeks"><?php echo round($x); ?> week<?php if(round($x) > 1) echo 's'; ?> remaining</span>
  71. <?php endif; ?>
  72. <span class="box-edit" style="background: none;">
  73. <a>
  74. <i class="fas fa-pen"></i>
  75. </a>
  76. </span>
  77. </div>
  78. <?php endwhile; ?>
  79. <?php else: // USER DOESN'T HAVE EXPERIENCES YET (ALTERNATE PAGE) ?>
  80. <script> setTimeout(() => $('#FirstTime').modal('show'), 1000); </script>
  81. <?php endif; ?>
  82. </div>
  83. <br><br>
  84. </main>
  85. <!-- POPUP FOR FIRST TIME -->
  86. <div class='modal fade' id='FirstTime' tabindex='-1' role='dialog' aria-labelledby='FirstTimeLabel' aria-hidden='true'>
  87. <div class='modal-dialog modal-sm' role='document'>
  88. <div class='modal-content'>
  89. <div class='modal-body'>
  90. <!-- CLOSE BUTTON -->
  91. <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
  92. <div class="row text-center">
  93. <h3>You don't have any experiences yet!</h3>
  94. <h5>Press below to create a new one!</h5>
  95. <button type="button" class='btn btn-default' data-dismiss='modal' onclick="nextModal('#New_2')">New</button>
  96. </div>
  97. </div><!--modal-body-->
  98. </div><!--modal-content-->
  99. </div><!--modal-dialog-->
  100. </div><!--modal-->
  101. <!--
  102. <!~~ POPUP FOR NEW EXPERIENCE 1 ~~>
  103. <div class='modal fade' id='New' tabindex='-1' role='dialog' aria-labelledby='NewLabel' aria-hidden='true'>
  104. <div class='modal-dialog modal-sm' role='document'>
  105. <div class='modal-content'>
  106. <div class='modal-body'>
  107. <!~~ CLOSE BUTTON ~~>
  108. <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
  109. <h4 class='text-center'>Want to add another experience?</h4>
  110. <!~~ CHOOSE: BRAND NEW EXPERIENCE OR USE A TEMPLATE~~>
  111. <div class='row text-center'>
  112. <div class='btn-group'>
  113. <button type="button" class='btn btn-default' data-dismiss="modal" onclick="nextModal('#New_2')">Brand New</button>
  114. <a href='#' class='btn btn-default'>Use Template</a>
  115. </div>
  116. </div>
  117. <br>
  118. </div><!~~modal-body~~>
  119. </div><!~~modal-content~~>
  120. </div><!~~modal-dialog~~>
  121. </div><!~~modal~~>
  122. -->
  123. <form id="newExperience"><!--method='POST' action='processes/insertExperience.php'-->
  124. <!-- POPUP FOR NEW EXPERIENCE 2 -->
  125. <div class='modal fade' id='New_2' tabindex='-1' role='dialog' aria-labelledby='NewLabel_2' aria-hidden='true'>
  126. <div class='modal-dialog modal-lg' role='document'>
  127. <div class='modal-content'>
  128. <div class='modal-body'>
  129. <!-- CLOSE BUTTON -->
  130. <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
  131. <div class='row'>
  132. <div class='col-sm-10'>
  133. <h2>Brand New Experience <small>(Basic Info)</small></h2>
  134. <!-- <h3><small>Start creating a new experience by first adding its basic info.</small></h3> -->
  135. </div>
  136. </div><!--row-->
  137. <hr><br>
  138. <div class="form-horizontal">
  139. <!-- TITLE -->
  140. <div class='form-group'>
  141. <label class='control-label col-sm-2' for='e_title'>Title:</label>
  142. <div class='col-sm-9'>
  143. <input type='text' class='form-control text-center' id='e_title' name='title' placeholder='Title' maxlength="60" required>
  144. </div>
  145. </div>
  146. <!-- DESCRIPTION -->
  147. <div class='form-group'>
  148. <label class='control-label col-sm-2' for='e_description'>Description:</label>
  149. <div class='col-sm-9'>
  150. <textarea class='form-control text-center' id='e_description' name='description' rows='1' style='resize:vertical;' placeholder='Description' maxlength="100" required></textarea>
  151. </div>
  152. </div>
  153. <!-- TYPE -->
  154. <div class='form-group'>
  155. <label class='control-label col-sm-2' for='e_description'>Type:</label>
  156. <div class='col-sm-9'>
  157. <select class="form-control text-center" style="text-align-last: center;" id='e_type' name='type' required>
  158. <option selected value="Course-Based Research">Course-Based Research</option>
  159. <option value="Independent Research">Independent Research</option>
  160. </select>
  161. </div>
  162. </div>
  163. <!-- DURATION -->
  164. <div class='form-group'>
  165. <label class='control-label col-sm-2' for='e_description'>Duration:</label>
  166. <div class='col-sm-9'>
  167. <input type='number' class='form-control text-center' id='e_duration' name='duration' placeholder='Duration' min="0" required readonly>
  168. </div>
  169. </div>
  170. <!-- START DATE -->
  171. <div class='form-group'>
  172. <label class='control-label col-sm-2' for='e_start'>Start Date:</label>
  173. <div class='col-sm-9'>
  174. <input type='date' class='form-control text-center' id='e_start' name='start' placeholder="YYYY-MM-DD" required>
  175. </div>
  176. </div>
  177. <!-- END DATE -->
  178. <div class='form-group'>
  179. <label class='control-label col-sm-2' for='e_end'>End Date:</label>
  180. <div class='col-sm-9'>
  181. <input type='date' class='form-control text-center' id='e_end' name='end' placeholder="YYYY-MM-DD" required>
  182. </div>
  183. </div>
  184. <!-- INSTITUTION -->
  185. <div class='form-group'>
  186. <label class='control-label col-sm-2' for='e_institution'>Institution:</label>
  187. <div class='col-sm-9'>
  188. <select class="form-control" id='e_institution' name='institution' style='width:100%; text-align-last: center;' required>
  189. <option disabled selected value>Institution</option>
  190. <?php
  191. $query = "SELECT * FROM `institution`;";
  192. $result = mysqli_query($connection, $query);
  193. while($row = mysqli_fetch_assoc($result)):
  194. ?>
  195. <option value='<?php echo $row['id']; ?>'><?php echo $row['name']; ?></option>
  196. <?php endwhile; ?>
  197. </select>
  198. </div>
  199. </div>
  200. <br><hr style="width: 80%"><br><br>
  201. <!-- EXPIRY TIME -->
  202. <div class='form-group'>
  203. <label class='control-label col-sm-3' for='e_description'>Expiry Time:</label>
  204. <div class='col-sm-7 input-groupd'>
  205. <select class="form-control" style="text-align-last: center;" id="expiry_time" name="expiry_time" required>
  206. <option selected value="30">30 min</option>
  207. <option value="60">1 hour</option>
  208. <option value="120">2 hours</option>
  209. <option value="180">3 hours</option>
  210. <!-- <option value="240">4 hours</option> -->
  211. <!-- <option value="300">5 hours</option> -->
  212. <option value="360">6 hours</option>
  213. <option value="720">12 hours</option>
  214. <option value="1080">18 hours</option>
  215. <option value="1440">1 day</option>
  216. </select>
  217. </div>
  218. </div>
  219. </div>
  220. <br>
  221. <!--. Each Moment will need to have a <strong>predetermined expiry time</strong>; -->
  222. <p class='alert alert-warning text-justify' style="width: 80%; margin: 0 auto;">We require that you specify a <strong>Moment Expiry Time</strong>. That is, the amount of time you, the researcher, will allot your subjects to answer a given Moment. The <strong>minimum</strong> we allow is 30 min, while the <strong>maximum</strong> is a whole day. Please keep in mind you should provide your subjects </strong>enough time</strong> so that they are allowed to answer properly, but do not allocate <strong>excessive time</strong>, as your subjects' answers may vary greatly with time.</p>
  223. <br>
  224. <!-- ERROR ALERT FOR USER -->
  225. <div id="error-newExperience" class="row" style="display: none;">
  226. <div class="col-sm-12">
  227. <div class="alert alert-danger mb-1" role="alert">
  228. <h4 class="error-lead">Error!</h4>
  229. <p class="error-description"></p>
  230. </div>
  231. </div>
  232. </div>
  233. </div><!--modal-body-->
  234. <!-- SUBMIT OR CANCEL -->
  235. <div class='modal-footer'>
  236. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  237. <button type='submit' class='btn btn-primary' name='newExperience'>Create</button>
  238. <!-- <button type='button' class='btn btn-primary' data-dismiss='modal' onclick="nextModal('#New_3')">Next</button> -->
  239. </div>
  240. </div><!--modal-content-->
  241. </div><!--modal-dialog-->
  242. </div><!--modal-->
  243. </form><!--form-->
  244. <script src="js/home.js"></script>
  245. <script src="js/handleSubmit.js"></script>
  246. <script>
  247. ["newExperience"].forEach(function(formName) {
  248. var form = document.getElementById(formName);
  249. if(form) {
  250. form.addEventListener('submit', function(e) {
  251. handleSubmit(e, formName);
  252. });
  253. }
  254. });
  255. window.onload = function() {
  256. // Start Date
  257. setStartDateRange();
  258. // End Date
  259. startDate.addEventListener('change', setEndDateRange);
  260. // Duration
  261. startDate.addEventListener('change', setDuration);
  262. endDate.addEventListener('change', setDuration);
  263. }
  264. </script>
  265. <!-- END OF home.php -->
  266. <?php include_once 'footer.php'; ?>