No Description

home.php 13KB

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