No Description

viewExperience.php 51KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. <?php
  2. // Description: EXTRACT EXPERIENCE 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. // FETCH EXPERIENCE
  11. $experienceID = mysqli_real_escape_string($connection, trim($_GET['view']));
  12. $query1 = "SELECT * FROM `experience` WHERE `id` = '$experienceID';";
  13. $result1 = mysqli_query($connection, $query1) or die("Error: ".mysqli_error($connection));
  14. $row1 = mysqli_fetch_array($result1);
  15. // IF EXPERIENCE NOT IN DATABASE, EXIT
  16. if($result1->num_rows !== 1) {
  17. echo "Requested experience does not exist.";
  18. exit();
  19. }
  20. // IF EXPERIENCE DOESN'T BELONG TO USER (WHO IS NOT AN ADMIN), EXIT
  21. if($_SESSION['dbUserData']['admin'] !== '1') {
  22. $queryCheckUser = "SELECT id FROM experience WHERE id = '$experienceID' AND id IN (SELECT id_experience FROM researcher_experience WHERE id_researcher = '" . $_SESSION['dbUserData']['id_researcher'] . "');";
  23. if(mysqli_query($connection, $queryCheckUser)->num_rows === 0) {
  24. echo "You are not authorized to view this experience.";
  25. exit();
  26. }
  27. }
  28. include_once 'header.php';
  29. ?>
  30. <!--START OF viewExperience.php -->
  31. <body>
  32. <header id="main-header">
  33. <a id="logo" href=".">
  34. TANIA
  35. <img src="./img/pen_800x800.png" alt="tania logo pen" width="25" height="25">
  36. </a>
  37. <div id="account">
  38. <a class="sign-out" href="./processes/logout.php">Sign Out</a>
  39. </div>
  40. </header>
  41. <div class="container-fluid" id="view-experience-showcase">
  42. <div class="row">
  43. <div class="col-sm-12">
  44. <h2><?php echo $row1['title']; ?></h2>
  45. <div class="row">
  46. <div class="col-sm-7 col-md-8 col-lg-9">
  47. <blockquote style="color:rgb(216,216,216); margin: 0;">
  48. <h4><b style="color:#fff;">Description:</b> <span style="color:rgb(216,216,216);"><?php echo $row1['description']; ?></span></h4>
  49. <h4><b style="color:#fff;">Type:</b> <span style="color:rgb(216,216,216);"><?php echo $row1['type']; ?></span></h4>
  50. <h4><b style="color:#fff;">Duration:</b> <span style="color:rgb(216,216,216);"><?php echo $row1['duration_weeks']; ?> week<?php if((int)$row1['duration_weeks'] > 1) echo "s"; ?></span></h4>
  51. </blockquote>
  52. </div><!--col-->
  53. <div class="col-sm-5 col-md-4 col-lg-3">
  54. <div id="view-experience-buttons">
  55. <div data-toggle="tooltip" data-placement="top" title="View Results" id="experience-pen" onclick="window.location='respuestas.php?exp=<?php echo $experienceID; ?>'">
  56. <span class="fas fa-poll-h"></span>
  57. </div>
  58. <div data-toggle="tooltip" data-placement="top" title="Edit Experience" id="experience-pen" onclick="nextModal('#Edit')">
  59. <span class="fas fa-pen"></span>
  60. </div>
  61. <div data-toggle="tooltip" data-placement="top" title="Share Experience" id="experience-pen" onclick="prompt('Press Ctrl + C to copy to clipboard!','https://tania.uprrp.edu/enrollInExp.php?id=<?php echo $row1['hash_id']; ?>')">
  62. <span class="fas fa-link"></span>
  63. </div>
  64. </div>
  65. </div><!--col-->
  66. </div><!--row-->
  67. <br>
  68. <div class="row hidden-xs" id="view-experience-tabs">
  69. <a class="active" href="#calendar">Calendar</a>
  70. <a href="#questionnaires">Questionnaires</a>
  71. <a href="#moments">Moments</a>
  72. <a href="#milestones">Milestones</a>
  73. </div><!--row-->
  74. </div><!--col-->
  75. </div><!--row-->
  76. </div><!--container-->
  77. <br>
  78. <!-- CALENDAR-->
  79. <div id="calendar" class="main-content-box show hidden-xs">
  80. <div class="container">
  81. <div class="row">
  82. <h3 class="col-sm-12">Schedule Your Experience</h3>
  83. </div><!--row-->
  84. <br>
  85. <div class="row">
  86. <div class="col-sm-12">
  87. <div id="actualCalendar"></div>
  88. </div>
  89. </div>
  90. <br><br><br><br>
  91. </div><!--container-->
  92. </div>
  93. <!--QUESTIONNAIRES-->
  94. <div id="questionnaires" class="main-content-box">
  95. <div class="container">
  96. <div class="row">
  97. <h3 class="col-xs-7 col-sm-9 col-md-9">Active Questionnaires</h3>
  98. <div class="col-xs-5 col-sm-3 col-md-3">
  99. <!--
  100. <span data-toggle="modal" data-target="#Import" style="margin-right: 1em;">
  101. <button type="button" class="btn btn-lg btn-default" data-toggle="tooltip" data-placement="top" title="Import Questionnaire">
  102. <span class="glyphicon glyphicon-open-file"></span>
  103. </button>
  104. </span>
  105. <span data-toggle="modal" data-target="#Duplicate">
  106. <button type="button" class="btn btn-lg btn-default" data-toggle="tooltip" data-placement="top" title="Duplicate Questionnaire">
  107. <span class="glyphicon glyphicon-paste"></span>
  108. </button>
  109. </span>
  110. -->
  111. <div id="view-experience-buttons">
  112. <div data-toggle="tooltip" data-placement="top" title="Import Questionnaire" id="experience-pen" onclick="nextModal('#Import')" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  113. <span class="fas fa-file-import"></span>
  114. </div>
  115. <div data-toggle="tooltip" data-placement="top" title="Duplicate Questionnaire" id="experience-pen" onclick="nextModal('#Duplicate')" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  116. <span class="fas fa-copy"></span>
  117. </div>
  118. </div>
  119. </div>
  120. </div><!--row-->
  121. <br>
  122. <div class="row">
  123. <div class="col-sm-12">
  124. <?php
  125. $query2 = "SELECT * FROM questionnair WHERE `id` IN (SELECT `id_questionnair` FROM experience_questionnair WHERE `id_experience` = '$experienceID');";
  126. $result2 = mysqli_query($connection, $query2);
  127. // IF THE EXPERIENCE HAS AT LEAST ONE QUESTIONNAIRE ASSOCIATED TO IT, SHOW IT
  128. // ELSE, DISPLAY A MESSAGE TO THE USER LETTING THEM KNOW THEY DON'T HAVE ONE
  129. if(mysqli_num_rows($result2) > 0):
  130. ?>
  131. <table class="table table-hover table-striped table-responsive">
  132. <thead>
  133. <tr>
  134. <th style="text-align: center;"><h4>Questionnaire</h4></th>
  135. <th style="text-align: center;"><h4>Questions</h4></th>
  136. </tr>
  137. </thead>
  138. <tbody>
  139. <?php while($row2 = mysqli_fetch_assoc($result2)): ?>
  140. <tr style="cursor: pointer;" onclick="location='viewQuestionnaire.php?view=<?php echo $row2['id']?>'">
  141. <td style="text-align: center;"><h5><?php echo $row2['q_title']; ?></h5></td>
  142. <?php
  143. $query3 = "SELECT * FROM questionnair_question WHERE id_questionnair = ".$row2['id'];
  144. $result3 = mysqli_query($connection, $query3);
  145. ?>
  146. <td style="text-align: center;"><h5><?php echo mysqli_num_rows($result3); ?></h5></td>
  147. </tr>
  148. <?php endwhile; ?>
  149. </tbody>
  150. </table>
  151. <?php else: ?>
  152. <h3 class="text-center"><small>It seems you still haven't added a questionnaire to this experience...</small></h3>
  153. <?php endif; ?>
  154. <br>
  155. <div class="row">
  156. <div class="col-sm-2 col-sm-offset-5">
  157. <div data-toggle="tooltip" data-placement="top" title="Create Questionnaire" onclick="nextModal('#NewQuestionnaire')" id="experience-pen" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  158. <span class="fas fa-plus"></span>
  159. </div>
  160. </div>
  161. </div>
  162. </div><!--col-sm-12-->
  163. </div><!--row-->
  164. <br><br>
  165. <div class="row">
  166. <div class="col-sm-offset-2 col-sm-8">
  167. <div class="alert alert-warning alert-dismisible mb-1 hidden-xs" role="alert">
  168. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  169. <span aria-hidden="true">&times;</span>
  170. </button>
  171. <h4>Tips on Questionnaires</h4>
  172. <hr>
  173. <ul>
  174. <li>These are the questionnaires that are associated to this experience.</li>
  175. <br>
  176. <li>Once you have your questionnaire, you can create your moments.</li>
  177. <br>
  178. <li>You can create new questionnaires with the plus button...
  179. <ul>
  180. <li>or import questionnaires from an Excel file!</li>
  181. <li>or copy a questionnaire from one experience to another!</li>
  182. </ul>
  183. </li>
  184. <br>
  185. </ul>
  186. </div><!--alert-->
  187. </div><!--col-sm-8-->
  188. </div><!--row-->
  189. <br>
  190. </div><!--container-->
  191. </div>
  192. <!--MOMENTS-->
  193. <div id="moments" class="main-content-box">
  194. <div class="container">
  195. <div class="row">
  196. <h3 class="col-sm-12">Active Moments</h3>
  197. </div>
  198. <div class="row">
  199. <div class="col-sm-12">
  200. <?php
  201. $query4 = "SELECT * FROM subquestionnair WHERE `id_questionnair` IN (SELECT `id_questionnair` FROM experience_questionnair WHERE `id_experience` = '$experienceID') ORDER BY date_to_administer ASC;";
  202. $result4 = mysqli_query($connection, $query4);
  203. // IF THE EXPERIENCE HAS AT LEAST ONE MOMENT ASSOCIATED TO IT, SHOW IT
  204. // ELSE, DISPLAY A MESSAGE TO THE USER LETTING THEM KNOW THEY DON'T HAVE ONE
  205. if(mysqli_num_rows($result4) > 0):
  206. ?>
  207. <table class="table table-hover table-striped table-responsive">
  208. <thead>
  209. <tr>
  210. <th style="text-align: center;"><h4>Moment</h4></th>
  211. <th style="text-align: center;"><h4>Questions</h4></th>
  212. <th style="text-align: center;"><h4>Date</h4></th>
  213. </tr>
  214. </thead>
  215. <tbody>
  216. <?php while($row4 = mysqli_fetch_assoc($result4)): ?>
  217. <tr style="cursor: pointer;" onclick="location='viewMoment.php?view=<?php echo $row4['id']?>'">
  218. <td style="text-align: center;"><h5><?php echo $row4['title']; ?></h5></td>
  219. <?php
  220. $query5 = "SELECT * FROM subquestionnair_question WHERE `id_subquestionnair` = ".$row4['id'];
  221. $result5 = mysqli_query($connection, $query5);
  222. ?>
  223. <td style="text-align: center;"><h5><?php echo mysqli_num_rows($result5); ?></h5></td>
  224. <td style="text-align: center;"><h5><?php echo date("M j, Y (g:i A)", strtotime($row4['date_to_administer'])); ?></h5></td>
  225. </tr>
  226. <?php endwhile; ?>
  227. </tbody>
  228. </table>
  229. <?php else: ?>
  230. <h3 class="text-center"><small>It seems you still haven't added any moments to this experience...</small></h3>
  231. <?php endif; ?>
  232. <br>
  233. <div class="row">
  234. <div class="col-sm-2 col-sm-offset-5">
  235. <div data-toggle="tooltip" data-placement="top" title="Create Moment" onclick="nextModal('#NewMoment')" id="experience-pen" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  236. <span class="fas fa-plus"></span>
  237. </div>
  238. </div>
  239. </div>
  240. </div><!--col-sm-12-->
  241. </div><!--row-->
  242. <br><br>
  243. <div class="row">
  244. <div class="col-sm-offset-2 col-sm-8">
  245. <div class="alert alert-warning alert-dismisible mb-1 hidden-xs" role="alert">
  246. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  247. <span aria-hidden="true">&times;</span>
  248. </button>
  249. <h4>Tips on Moments</h4>
  250. <hr>
  251. <ul>
  252. <li>These are the moments that are associated to this experience.</li>
  253. <br>
  254. <li>Once they're answered, you can track the results with the results button above.</li>
  255. <br>
  256. <li>You can create new moments with the plus button.</li>
  257. <br>
  258. </ul>
  259. </div><!--alert-->
  260. </div><!--col-sm-8-->
  261. </div><!--row-->
  262. <br>
  263. </div><!--container-->
  264. </div>
  265. <!--MILESTONES-->
  266. <div id="milestones" class="main-content-box">
  267. <div class="container">
  268. <div class="row">
  269. <h3 class="col-sm-12">Active Milestones</h3>
  270. </div>
  271. <div class="row">
  272. <div class="col-sm-12">
  273. <?php
  274. $query6 = "SELECT * FROM `milestone` WHERE `id_experience` = '$experienceID' ORDER BY date ASC;";
  275. $result6 = mysqli_query($connection, $query6);
  276. // IF THE EXPERIENCE HAS AT LEAST ONE MILESTONE ASSOCIATED TO IT, SHOW IT
  277. // ELSE, DISPLAY A MESSAGE TO THE USER LETTING THEM KNOW THEY DON'T HAVE ONE
  278. if(mysqli_num_rows($result6) > 0):
  279. ?>
  280. <table class="table table-hover table-striped table-responsive">
  281. <thead>
  282. <tr>
  283. <th style="text-align: center;"><h4>Milestone</h4></th>
  284. <th style="text-align: center;"><h4>Date</h4></th>
  285. </tr>
  286. </thead>
  287. <tbody>
  288. <?php while($row6 = mysqli_fetch_assoc($result6)): ?>
  289. <tr style="cursor: pointer;">
  290. <td style="text-align: center;"><h5><?php echo $row6['title']; ?></h5></td>
  291. <td style="text-align: center;"><h5><?php echo date("M j, Y", strtotime($row6['date'])); ?></h5></td>
  292. </tr>
  293. <?php endwhile; ?>
  294. </tbody>
  295. </table>
  296. <?php else: ?>
  297. <h3 class="text-center"><small>It seems you still haven't added any milestones to this experience...</small></h3>
  298. <?php endif; ?>
  299. <br>
  300. <div class="row">
  301. <div class="col-sm-2 col-sm-offset-5">
  302. <div data-toggle="tooltip" data-placement="top" title="Create Milestone" onclick="nextModal('#NewMilestone')" id="experience-pen" style="padding: 0.5em; margin: 0 auto; width: 60px;">
  303. <span class="fas fa-plus"></span>
  304. </div>
  305. </div>
  306. </div>
  307. </div><!--col-sm-12-->
  308. </div><!--row-->
  309. <br><br>
  310. <div class="row">
  311. <div class="col-sm-offset-2 col-sm-8">
  312. <div class="alert alert-warning alert-dismisible mb-1 hidden-xs" role="alert">
  313. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  314. <span aria-hidden="true">&times;</span>
  315. </button>
  316. <h4>Tips on Milestones</h4>
  317. <hr>
  318. <ul>
  319. <li>These are the milestones of the students involved in this experience.</li>
  320. <br>
  321. <li>Once your moments are answered you can track the impact the milestones had on the answers, if any.</li>
  322. <br>
  323. <li>You can create new milestones with the plus button.</li>
  324. <br>
  325. </ul>
  326. </div><!--alert-->
  327. </div><!--col-sm-8-->
  328. </div><!--row-->
  329. <br>
  330. </div><!--container-->
  331. </div>
  332. <br><br><br><br><br>
  333. <!-- POPUP FOR EDIT EXPERIENCE -->
  334. <form id="editForm"><!--method='POST' action='processes/updateExperience.php'-->
  335. <div class="modal fade" id="Edit" tabindex="-1" role="dialog" aria-labelledby="EditLabel" aria-hidden="true">
  336. <div class="modal-dialog" role="document">
  337. <div class="modal-content">
  338. <div class="modal-body">
  339. <!-- CLOSE BUTTON -->
  340. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  341. <span aria-hidden="true">&times;</span>
  342. </button>
  343. <div class="row">
  344. <div class="col-sm-10">
  345. <h2>Edit Experience <small>(Basic Info)</small></h2>
  346. </div>
  347. </div><!--row-->
  348. <hr><br>
  349. <div class="form-horizontal">
  350. <!-- ID -->
  351. <input type="hidden" name="id" value="<?php echo $row1['id']; ?>">
  352. <!-- NEW TITLE -->
  353. <div class="form-group">
  354. <label class="control-label col-sm-2 col-sm-offset-1">Title:</label>
  355. <div class="col-sm-7">
  356. <input type="text" class="form-control text-center" name="newTitle" maxlength="60" value="<?php echo $row1['title']; ?>" required>
  357. </div>
  358. </div>
  359. <!-- NEW DESCRIPTION -->
  360. <div class="form-group">
  361. <label class="control-label col-sm-2 col-sm-offset-1">Description:</label>
  362. <div class="col-sm-7">
  363. <textarea class="form-control text-center" name="newDescription" rows="4" style="resize: vertical;" maxlength="100" required><?php echo $row1['description']; ?></textarea>
  364. </div>
  365. </div>
  366. <!--
  367. <!~~ NEW TYPE ~~>
  368. <div class='form-group'>
  369. <label class='control-label col-sm-2 col-sm-offset-1'>Type:</label>
  370. <div class='col-sm-7'>
  371. <input type='text' class='form-control text-center' name='newType' required value="<?php echo $row1['type']; ?>">
  372. </div>
  373. </div>
  374. <!~~ NEW DURATION ~~>
  375. <div class='form-group'>
  376. <label class='control-label col-sm-2 col-sm-offset-1'>Duration:</label>
  377. <div class='col-sm-7'>
  378. <input type='number' class='form-control text-center' name='newDuration' required value="<?php echo $row1['duration_weeks']; ?>" readonly>
  379. </div>
  380. </div>
  381. <!~~ NEW START DATE ~~>
  382. <div class='form-group'>
  383. <label class='control-label col-sm-2 col-sm-offset-1'>Start Date:</label>
  384. <div class='col-sm-7'>
  385. <input type='date' class='form-control text-center' name='newStart' required value="<?php echo $row1['start_date']; ?>">
  386. </div>
  387. </div>
  388. <!~~ NEW END DATE ~~>
  389. <div class='form-group'>
  390. <label class='control-label col-sm-2 col-sm-offset-1'>End Date:</label>
  391. <div class='col-sm-7'>
  392. <input type='date' class='form-control text-center' name='newEnd' required value="<?php echo $row1['end_date']; ?>">
  393. </div>
  394. </div>
  395. -->
  396. </div><!--form-horizontal-->
  397. <!-- ERROR ALERT FOR USER -->
  398. <div id="error-editForm" class="row" style="display: none;">
  399. <div class="col-sm-12">
  400. <div class="alert alert-danger mb-1" role="alert">
  401. <h4 class="error-lead">Error!</h4>
  402. <p class="error-description"></p>
  403. </div>
  404. </div>
  405. </div>
  406. </div><!--modal-body-->
  407. <!-- SUBMIT OR CANCEL -->
  408. <div class="modal-footer">
  409. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  410. <button type="submit" class="btn btn-primary" name="updateExperience" disabled>Save Changes</button>
  411. </div>
  412. </div><!--modal-content-->
  413. </div><!--modal-dialog-->
  414. </div><!--modal-->
  415. </form><!--form-->
  416. <!--FORM VALIDATION FOR EDIT EXPERIENCE-->
  417. <script>
  418. let newTitle = document.querySelector('[name=newTitle]');
  419. let newDescription = document.querySelector('[name=newDescription]');
  420. // let newType = document.querySelector('[name=newType]');
  421. newTitle.addEventListener('keyup', validateEditExperience);
  422. newTitle.addEventListener('change', validateEditExperience);
  423. newDescription.addEventListener('keyup', validateEditExperience);
  424. newDescription.addEventListener('change', validateEditExperience);
  425. // newType.addEventListener('keyup', validateEditExperience);
  426. // newType.addEventListener('change', validateEditExperience);
  427. // Only enable submit button when:
  428. // 1) changes are detected,
  429. // 2) and both strings (title and description) are not empty
  430. function validateEditExperience() {
  431. let updateExperience = document.querySelector('[name=updateExperience]');
  432. updateExperience.disabled = !newTitle.checkValidity() || !newDescription.checkValidity();
  433. }
  434. </script>
  435. <!-- POPUP FOR NEW QUESTIONNAIRE 1 -->
  436. <div class="modal fade" id="NewQuestionnaire" tabindex="-1" role="dialog" aria-labelledby="NewQuestionnaireLabel" aria-hidden="true">
  437. <div class="modal-dialog modal-lg" role="document">
  438. <div class="modal-content">
  439. <div class="modal-body">
  440. <!-- CLOSE BUTTON -->
  441. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  442. <span aria-hidden='true'>&times;</span>
  443. </button>
  444. <div class="row">
  445. <div class="col-sm-10">
  446. <h2>New Questionnaire <small>(Basic Info – <em>Part 1</em>)</small></h2>
  447. </div>
  448. </div><!--row-->
  449. <hr><br>
  450. <div class="form-horizontal">
  451. <!-- TITLE -->
  452. <div class="form-group">
  453. <label class="control-label col-sm-2">Title:</label>
  454. <div class="col-sm-9">
  455. <input type="text" class="form-control text-center" name="q_title_tentative" placeholder="Title" maxlength="100" required>
  456. </div>
  457. </div>
  458. <!-- DESCRIPTION -->
  459. <div class="form-group">
  460. <label class="control-label col-sm-2">Description:</label>
  461. <div class="col-sm-9">
  462. <textarea class="form-control text-center" name="description_tentative" rows="1" placeholder="Description" maxlength="200" required></textarea>
  463. </div>
  464. </div>
  465. <!-- REFERENCE -->
  466. <div class="form-group">
  467. <label class="control-label col-sm-2">Reference:</label>
  468. <div class="col-sm-9">
  469. <input type="text" class="form-control text-center" name="referencia_tentative" placeholder="Reference" maxlength="60" required>
  470. </div>
  471. </div>
  472. <br>
  473. <!-- CATEGORIES -->
  474. <div class="form-group">
  475. <label class="control-label col-sm-2">Categories:</label>
  476. <div class="col-sm-9">
  477. <textarea id="q_categories_tentative" class="form-control text-center" name="q_categories_tentative" rows="1" placeholder="Categories (comma separated)" required></textarea>
  478. </div>
  479. </div>
  480. <!-- SUBCATEGORIES -->
  481. <div class="form-group">
  482. <label class="control-label col-sm-2">Subcategories:</label>
  483. <div class="col-sm-9">
  484. <textarea id="q_subcategories_tentative" class="form-control text-center" name="q_subcategories_tentative" rows="1" placeholder="Subcategories (comma separated)" required></textarea>
  485. </div>
  486. </div>
  487. </div>
  488. <div class="row">
  489. <div class="col col-sm-offset-2 col-sm-9">
  490. <p class="alert alert-warning text-justify">
  491. <strong>Note:</strong> You should at least have the same number of subcategories as categories.
  492. </p>
  493. </div>
  494. </div>
  495. </div><!--modal-body-->
  496. <!-- NEXT OR CANCEL -->
  497. <div class="modal-footer">
  498. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  499. <button id="nextQuestionnaire" type="button" class='btn btn-primary' data-dismiss="modal" onclick="nextModal('#NewQuestionnaire_2')" disabled>Next</button>
  500. </div>
  501. </div><!--modal-content-->
  502. </div><!--modal-dialog-->
  503. </div><!--modal-->
  504. <!-- FORM VALIDATION FOR NEW QUESTIONNAIRE (BASIC INFO) -->
  505. <script>
  506. // Fetch the inputs in the first modal
  507. let questionnaireTitle = document.querySelector('[name=q_title_tentative]');
  508. let questionnaireDescription = document.querySelector('[name=description_tentative]');
  509. let questionnaireReference = document.querySelector('[name=referencia_tentative]');
  510. let categories = document.querySelector('[name=q_categories_tentative]');
  511. let subcategories = document.querySelector('[name=q_subcategories_tentative]');
  512. // Add onchange and onkeyup event listeners to each input in the first modal
  513. questionnaireTitle.addEventListener('keyup', validateNewQuestionnaire);
  514. questionnaireTitle.addEventListener('change', validateNewQuestionnaire);
  515. questionnaireDescription.addEventListener('keyup', validateNewQuestionnaire);
  516. questionnaireDescription.addEventListener('change', validateNewQuestionnaire);
  517. questionnaireReference.addEventListener('keyup', validateNewQuestionnaire);
  518. questionnaireReference.addEventListener('change', validateNewQuestionnaire);
  519. categories.addEventListener('keyup', validateNewQuestionnaire);
  520. categories.addEventListener('change', validateNewQuestionnaire);
  521. subcategories.addEventListener('keyup', validateNewQuestionnaire);
  522. subcategories.addEventListener('change', validateNewQuestionnaire);
  523. // Pass the values from the first modal to the second, where the actual (hidden) inputs reside
  524. questionnaireTitle.addEventListener('keyup', function() {
  525. document.querySelector('[name=q_title]').value = questionnaireTitle.value;
  526. });
  527. questionnaireDescription.addEventListener('keyup', function() {
  528. document.querySelector('[name=description]').value = questionnaireDescription.value;
  529. });
  530. questionnaireReference.addEventListener('keyup', function() {
  531. document.querySelector('[name=referencia]').value = questionnaireReference.value;
  532. });
  533. categories.addEventListener('keyup', function() {
  534. document.querySelector('[name=q_categories]').value = categories.value;
  535. });
  536. subcategories.addEventListener('keyup', function() {
  537. document.querySelector('[name=q_subcategories]').value = subcategories.value;
  538. });
  539. // First modal's validation function
  540. // This basically enables the "Next" button if certain conditions are met
  541. function validateNewQuestionnaire() {
  542. // Fetch "Next" button in modal
  543. let nextButton = document.querySelector('#nextQuestionnaire');
  544. // Check validity of each input (valid if not empty strings)
  545. let validity = questionnaireTitle.checkValidity();
  546. validity &= questionnaireDescription.checkValidity();
  547. validity &= questionnaireReference.checkValidity();
  548. validity &= categories.checkValidity();
  549. validity &= subcategories.checkValidity();
  550. // Questionnaire should have at least the same number of subcategories as categories
  551. let rawCategories = categories.value.split(',');
  552. let rawSubcategories = subcategories.value.split(',');
  553. let categoriesArray = new Array();
  554. let subcategoriesArray = new Array();
  555. // IF clause is necessary to avoid array WARNINGS and ERRORS
  556. if(categories.value != '' && subcategories.value != '') {
  557. // Store the "trimmed" categories in categoriesArray
  558. for(let i = 0; i < rawCategories.length; i++) {
  559. rawCategories[i] = rawCategories[i].trim();
  560. // if string not empty and not whitespace, insert as category option
  561. if(/\S/.test(rawCategories[i])) {
  562. categoriesArray.push(rawCategories[i]);
  563. }
  564. }
  565. // Store the "trimmed" subcategories in subcategoriesArray
  566. for(let i = 0; i < rawSubcategories.length; i++) {
  567. rawSubcategories[i] = rawSubcategories[i].trim();
  568. // if string not empty and not whitespace, insert as subcategory option
  569. if(/\S/.test(rawSubcategories[i])) {
  570. subcategoriesArray.push(rawSubcategories[i]);
  571. }
  572. }
  573. // Only valid if there are less or equal number of categories to subcategories
  574. validity &= categoriesArray.length <= subcategoriesArray.length;
  575. }
  576. // Disabled if not valid, enabled otherwise
  577. nextButton.disabled = !validity;
  578. }
  579. </script>
  580. <form id="newQuestionnaire"><!--method="POST" action="processes/insertQuestionnaire.php"-->
  581. <!-- POPUP FOR NEW QUESTIONNAIRE 2 -->
  582. <div class="modal fade" id="NewQuestionnaire_2" tabindex="-1" role="dialog" aria-labelledby="NewQuestionnaireLabel_2" aria-hidden="true">
  583. <div class="modal-dialog modal-lg" role="document">
  584. <div class="modal-content">
  585. <div class="modal-body">
  586. <!-- CLOSE BUTTON -->
  587. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  588. <span aria-hidden="true">&times;</span>
  589. </button>
  590. <div class="row">
  591. <div class="col-sm-10">
  592. <h2>New Questionnaire <small>(Questions – <em>Part 2</em>)</small></h2>
  593. </div>
  594. </div><!--row-->
  595. <hr>
  596. <!-- EXPERIENCE ID -->
  597. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  598. <!-- QUESTIONNAIRE TITLE -->
  599. <input type="hidden" name="q_title" maxlength="100" required>
  600. <!-- QUESTIONNAIRE DESCRIPTION --->
  601. <input type="hidden" name="description" maxlength="200" required>
  602. <!-- QUESTIONNAIRE REFERENCE -->
  603. <input type="hidden" name="referencia" maxlength="60" required>
  604. <!-- QUESTIONNAIRE CATEGORIES -->
  605. <input id="q_categories" type="hidden" name="q_categories" required>
  606. <!-- QUESTIONNAIRE SUBCATEGORIES -->
  607. <input id="q_subcategories" type="hidden" name="q_subcategories" required>
  608. <!-- QUESTION -->
  609. <div id="q1">
  610. <div class="row">
  611. <div class="col col-sm-offset-1">
  612. <h4>Question 1</h4>
  613. </div>
  614. </div>
  615. <div class="form-horizontal">
  616. <!-- PREMISE -->
  617. <div class="form-group">
  618. <label class="col-sm-offset-1 control-label col-sm-2">Premise:</label>
  619. <div class="col-sm-8">
  620. <input id="q_premise1" type="text" class="form-control text-center" name="q_premise1" placeholder="Premise" maxlength="600" required>
  621. </div>
  622. </div>
  623. <!-- TYPE -->
  624. <div class="form-group">
  625. <label class="col-sm-offset-1 control-label col-sm-2">Question Type:</label>
  626. <div class="col-sm-8">
  627. <select class="form-control text-center" id="q_type1" name="q_type1" style="width:100%; text-align-last:center;" onchange="newThing(event)" required>
  628. <!-- <option disabled selected value="">Type</option> -->
  629. <option value="1">Scaled</option>
  630. <option value="2">Open Answer</option>
  631. </select>
  632. </div>
  633. </div>
  634. </div>
  635. <!-- MIN/MAX VALUES/TEXT (OPTIONAL) -->
  636. <div id="range1">
  637. <div class="form-inline col col-sm-offset-2">
  638. <div class="form-group">
  639. <label class="control-label col-sm-2">Min. Value:</label>
  640. <div class="col-sm-8">
  641. <input type="number" class="form-control text-center" id="min_val1" name="min_val1" value="1" readonly>
  642. </div>
  643. </div>
  644. <div class="form-group">
  645. <label class="control-label col-sm-2">Min. Text:</label>
  646. <div class="col-sm-8">
  647. <input type="text" class="form-control text-center" id="min_text1" name="min_text1" maxlength="40" placeholder="Very Dissatisfied">
  648. </div>
  649. </div>
  650. </div>
  651. <div class="form-inline col col-sm-offset-2">
  652. <div class="form-group">
  653. <label class="control-label col-sm-2">Max. Value:</label>
  654. <div class="col-sm-1">
  655. <input type="number" class="form-control text-center" id="max_val1" name="max_val1" value="5" min="2">
  656. </div>
  657. </div>
  658. <div class="form-group">
  659. <label class="control-label col-sm-2">Max. Text:</label>
  660. <div class="col-sm-1">
  661. <input type="text" class="form-control text-center" id="max_text1" name="max_text1" maxlength="40" placeholder="Very Satisfied">
  662. </div>
  663. </div>
  664. </div>
  665. <br>
  666. </div>
  667. <div class="form-horizontal">
  668. <!-- CORRESPONDING CATEGORY -->
  669. <div class="form-group">
  670. <label class="col-sm-offset-1 control-label col-sm-2">Category:</label>
  671. <div class="col-sm-8">
  672. <select class="form-control text-center" id="q_category1" name="q_category1" style="width: 100%; text-align-last:center;" required>
  673. <!-- <option disabled selected value="">Category</option> -->
  674. </select>
  675. </div>
  676. </div>
  677. <!-- CORRESPONDING SUBCATEGORY -->
  678. <div class="form-group">
  679. <label class="col-sm-offset-1 control-label col-sm-2">Subcategory:</label>
  680. <div class="col-sm-8">
  681. <select class="form-control text-center" id="q_subcategory1" name="q_subcategory1" style="width: 100%; text-align-last:center;" required>
  682. <!-- <option disabled selected value="">Subcategory</option> -->
  683. </select>
  684. </div>
  685. </div>
  686. </div>
  687. </div>
  688. <br>
  689. <div class="row">
  690. <div class="col-sm-offset-9 col-sm-2">
  691. <button type="button" class="btn btn-xs btn-default" onclick="addQuestion()">Add Question</button>
  692. </div>
  693. </div>
  694. <!-- ERROR ALERT FOR USER -->
  695. <div id="error-newQuestionnaire" class="row" style="display: none;">
  696. <div class="col-sm-12">
  697. <div class="alert alert-danger mb-1" role="alert">
  698. <h4 class="error-lead">Error!</h4>
  699. <p class="error-description"></p>
  700. </div>
  701. </div>
  702. </div>
  703. </div><!--modal-body-->
  704. <!-- SUBMIT OR PREVIOUS -->
  705. <div class="modal-footer">
  706. <button type="button" class="btn btn-default" data-dismiss="modal" onclick="nextModal('#NewQuestionnaire')">Previous</button>
  707. <button type="submit" class="btn btn-primary" name="createQuestionnaire">Create</button>
  708. </div>
  709. </div><!--modal-content-->
  710. </div><!--modal-dialog-->
  711. </div><!--modal-->
  712. </form>
  713. <!-- POPUP FOR IMPORT QUESTIONNAIRE -->
  714. <form class='form-horizontal' action='processes/importQuestionnaire.php' method='POST' enctype="multipart/form-data">
  715. <div class='modal fade' id='Import' tabindex='-1' role='dialog' aria-labelledby='ImportLabel' aria-hidden='true'>
  716. <div class='modal-dialog modal-dialog-centered modal-md' role='document'>
  717. <div class='modal-content'>
  718. <div class='modal-header'>
  719. <h3 class='modal-title' id='ImportLabel'>Import Questionnaire<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  720. </div>
  721. <div class='modal-body'>
  722. <div class="form-horizontal">
  723. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  724. <div class="row">
  725. <div class="col-sm-12">
  726. <h4>Download Template</h4>
  727. <p>Use this template to fill out your questionnaire and we'll do the heavy lifting for you! Once you're done, <strong>submit</strong> it using the "<em>import</em>" button below.</p>
  728. <a class="btn btn-primary btn-sm btn-block" href="nameOfTheQuestionnair.xlsx">Download Template</a>
  729. </div>
  730. </div><!--row-->
  731. <br>
  732. <br>
  733. <div class="form-group">
  734. <div class="col-sm-10 col-sm-offset-2">
  735. <label for="exampleInputFile">Questionnaire in xlsx format</label>
  736. <input type="file" name='import'>
  737. <p class="help-block">Choose your .xlsx file (remember it has to have the correct format).</p>
  738. </div>
  739. </div><!--form-group-->
  740. </div>
  741. </div><!--modal-body-->
  742. <div class='modal-footer'>
  743. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  744. <button type='submit' class='btn btn-primary' name='insertQuestionnaire'>Import</button>
  745. </div>
  746. </div><!--modal-content-->
  747. </div><!--modal-dialog-->
  748. </div><!--modal-->
  749. <!-- POPUP FOR DUPLICATE QUESTIONNAIRE -->
  750. <form class='form-horizontal' action='processes/duplicateQuestionnaire.php' method='POST'>
  751. <div class='modal fade' id='Duplicate' tabindex='-1' role='dialog' aria-labelledby='DuplicateLabel' aria-hidden='true'>
  752. <div class='modal-dialog modal-dialog-centered' role='document'>
  753. <div class='modal-content'>
  754. <div class='modal-header'>
  755. <h3 class='modal-title' id='DuplicateLabel'>Duplicate Questionnaire<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></h3>
  756. </div>
  757. <div class='modal-body'>
  758. <span class='text-center'>
  759. <h4>Copy a questionnaire from one experience to another</h4>
  760. </span>
  761. <br>
  762. <!-- FROM QUESTIONNAIRE -->
  763. <label for="fromQuestionnaireID">Which Questionnaire:</label>
  764. <?php
  765. // FIRST ASSUME FALSE
  766. $errorDuplicate = false;
  767. $queryQuestionnaires = "SELECT * FROM `questionnair` WHERE id IN (SELECT id_questionnair FROM experience_questionnair WHERE id_experience = '$experienceID');";
  768. $resultQuestionnaires = mysqli_query($connection, $queryQuestionnaires);
  769. if($resultQuestionnaires->num_rows > 0):
  770. ?>
  771. <select class="form-control text-center" id="fromQuestionnaireID" name="fromQuestionnaireID" style="text-align-last:center;" required>
  772. <?php while($rowQuestionnaires = mysqli_fetch_assoc($resultQuestionnaires)): ?>
  773. <option value="<?php echo $rowQuestionnaires['id']; ?>"><?php echo $rowQuestionnaires['q_title']; ?></option>
  774. <?php endwhile; ?>
  775. </select>
  776. <?php
  777. else:
  778. $errorDuplicate = true;
  779. ?>
  780. <h3 class="text-center"><small>It seems you still haven't added any questionnaires to this experience...</small></h3>
  781. <?php endif; ?>
  782. <br>
  783. <!-- TO EXPERIENCE -->
  784. <label for="toExperienceID">To What Experience:</label>
  785. <?php
  786. // CHANGE QUERY DEPENDING ON IF USER IS ADMIN OR NOT
  787. if($_SESSION['dbUserData']['admin'] === '1') {
  788. $queryExperience2 = "SELECT * FROM `experience` WHERE id != '$experienceID';";
  789. } else {
  790. $queryExperience2 = "SELECT * FROM `experience` WHERE id != '$experienceID' AND id IN (SELECT id_experience FROM researcher_experience WHERE id_researcher = '" . $_SESSION['dbUserData']['id_researcher'] . "');";
  791. }
  792. $resultExperience2 = mysqli_query($connection, $queryExperience2);
  793. if($resultExperience2->num_rows > 0):
  794. ?>
  795. <select class="form-control text-center" id="toExperienceID" name="toExperienceID" style="text-align-last:center;" required>
  796. <?php while($rowExperience2 = mysqli_fetch_assoc($resultExperience2)): ?>
  797. <option value="<?php echo $rowExperience2['id']; ?>"><?php echo $rowExperience2['title']; ?></option>
  798. <?php endwhile; ?>
  799. </select>
  800. <?php
  801. else:
  802. $errorDuplicate = true;
  803. ?>
  804. <h3 class="text-center"><small>You don't have another experience to duplicate to...</small></h3>
  805. <?php endif; ?>
  806. </div><!--modal-body-->
  807. <!-- SUBMIT OR CANCEL -->
  808. <div class='modal-footer'>
  809. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  810. <button type='submit' class='btn btn-primary' name='duplicateQuestionnaire' <?php if($errorDuplicate === true) echo "disabled"; ?>>Confirm</button>
  811. </div>
  812. </div><!--modal-content-->
  813. </div><!--modal-dialog-->
  814. </div><!--modal-->
  815. </form>
  816. <!-- POPUP FOR NEW MOMENT 1 -->
  817. <form id="newMoment"><!--method='POST' action='processes/insertMoment.php'-->
  818. <div class="modal fade" id="NewMoment" tabindex="-1" role="dialog" aria-labelledby="NewMomentLabel" aria-hidden="true">
  819. <div class="modal-dialog modal-lg" role="document">
  820. <div class="modal-content">
  821. <div class="modal-body">
  822. <!-- CLOSE BUTTON -->
  823. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  824. <span aria-hidden='true'>&times;</span>
  825. </button>
  826. <div class="row">
  827. <div class="col-sm-10">
  828. <h2>New Moment <small>(Basic Info – <em>Part 1</em>)</small></h2>
  829. </div>
  830. </div><!--row-->
  831. <hr><br>
  832. <div class="form-horizontal">
  833. <!--EXPERIENCE ID-->
  834. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  835. <!-- TITLE -->
  836. <div class="form-group">
  837. <label class="control-label col-sm-2">Title:</label>
  838. <div class="col-sm-9">
  839. <input type="text" class="form-control text-center" name="m_title" maxlength="60" placeholder="Title" required>
  840. </div>
  841. </div>
  842. <!-- DESCRIPTION -->
  843. <div class="form-group">
  844. <label class="control-label col-sm-2">Description:</label>
  845. <div class="col-sm-9">
  846. <textarea class="form-control text-center" name="m_description" rows="1" style="resize:vertical;" maxlength="100" placeholder="Description" required></textarea>
  847. </div>
  848. </div>
  849. <!-- DATE TO ADMINISTER -->
  850. <div class="form-group">
  851. <label class="control-label col-sm-2">Date to Administer:</label>
  852. <div class="col-sm-9">
  853. <input type="datetime-local" class="form-control text-center" name="m_date" maxlength="16" placeholder="YYYY-MM-DDThh:mm" required>
  854. </div>
  855. </div>
  856. <!-- CORRESPONDING QUESTIONNAIRE -->
  857. <?php
  858. $query7 = "SELECT * FROM `questionnair` WHERE `id` IN (SELECT `id_questionnair` FROM `experience_questionnair` WHERE `id_experience` = '$experienceID');";
  859. $result7 = mysqli_query($connection, $query7);
  860. // IF THE EXPERIENCE HAS AT LEAST ONE QUESTIONNAIRE ASSOCIATED TO IT, SHOW IT
  861. // ELSE, DISPLAY A MESSAGE TO THE USER LETTING THEM KNOW THEY DON'T HAVE ONE
  862. if(mysqli_num_rows($result7) > 0):
  863. ?>
  864. <div class="form-group">
  865. <label class="control-label col-sm-2">Questionnaire:</label>
  866. <div class="col-sm-9">
  867. <select class="form-control" id="m_questionnaire" name="m_questionnaire" style="width:100%; text-align-last:center;" required>
  868. <option disabled selected value>Corresponding Questionnaire</option>
  869. <?php while($row7 = mysqli_fetch_assoc($result7)): ?>
  870. <option value="<?php echo $row7['id']; ?>"><?php echo $row7['q_title']; ?></option>
  871. <?php endwhile; ?>
  872. </select>
  873. </div>
  874. </div>
  875. <?php else: ?>
  876. <div class="text-center">
  877. <h3><small>First add a questionnaire!</small></h3>
  878. </div>
  879. <?php endif; ?>
  880. </div><!--form-horizontal-->
  881. </div><!--modal-body-->
  882. <!-- NEXT OR CANCEL -->
  883. <div class="modal-footer">
  884. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  885. <button id="nextMoment" type="button" class="btn btn-primary" data-dismiss="modal" onclick="nextModal('#NewMoment_2')" disabled>Next</button>
  886. </div>
  887. </div><!--modal-content-->
  888. </div><!--modal-dialog-->
  889. </div><!--modal-->
  890. <!-- FORM VALIDATION FOR NEW MOMENT (BASIC INFO) -->
  891. <script>
  892. // Fetch the inputs in the first modal
  893. let momentTitle = document.querySelector('[name=m_title]');
  894. let momentDescription = document.querySelector('[name=m_description]');
  895. let momentDate = document.querySelector('[name=m_date]');
  896. let momentQuestionnaire = document.querySelector('[name=m_questionnaire]');
  897. // Add onchange and onkeyup event listeners to each input in the first modal
  898. momentTitle.addEventListener('keyup', validateNewMoment);
  899. momentTitle.addEventListener('change', validateNewMoment);
  900. momentDescription.addEventListener('keyup', validateNewMoment);
  901. momentDescription.addEventListener('change', validateNewMoment);
  902. momentDate.addEventListener('keyup', validateNewMoment);
  903. momentDate.addEventListener('change', validateNewMoment);
  904. momentQuestionnaire.addEventListener('keyup', validateNewMoment);
  905. momentQuestionnaire.addEventListener('change', validateNewMoment);
  906. // First modal's validation function
  907. // This basically enables the "Next" button if certain conditions are met
  908. function validateNewMoment() {
  909. // Fetch "Next" button in modal
  910. let nextButton = document.querySelector('#nextMoment');
  911. // Check validity of each input (valid if not empty strings & "maxlength" is set)
  912. let validity = momentTitle.checkValidity();
  913. validity &= momentDescription.checkValidity();
  914. validity &= momentDate.checkValidity();
  915. validity &= momentQuestionnaire.checkValidity();
  916. // Disabled if not valid, enabled otherwise
  917. nextButton.disabled = !validity;
  918. }
  919. </script>
  920. <!-- POPUP FOR NEW MOMENT 2 -->
  921. <div class="modal fade" id="NewMoment_2" tabindex="-1" role="dialog" aria-labelledby="NewMomentLabel_2" aria-hidden="true">
  922. <div class="modal-dialog modal-lg" role="document">
  923. <div class="modal-content">
  924. <div class="modal-body">
  925. <!-- CLOSE BUTTON -->
  926. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  927. <span aria-hidden='true'>&times;</span>
  928. </button>
  929. <div class="row">
  930. <div class="col-sm-10">
  931. <h2>New Moment <small>(Questions – <em>Part 2</em>)</small></h2>
  932. </div>
  933. </div><!--row-->
  934. <hr><br>
  935. <!-- QUESTION -->
  936. <div id="qq1" >
  937. <div class="row">
  938. <div class="col col-sm-offset-1">
  939. <h4>Question 1</h4>
  940. </div>
  941. </div>
  942. <!-- CHOOSE QUESTION FROM CORRESPONDING QUESTIONNAIRE -->
  943. <div class="form-horizontal">
  944. <div class="form-group">
  945. <div class='col-sm-offset-2 col-sm-9'>
  946. <select class="form-control" id="m_question_1" name="m_question_1" style="width:100%; text-align-last:center;" required>
  947. <option disabled selected value>Select Question</option>
  948. </select>
  949. </div>
  950. </div>
  951. </div>
  952. </div>
  953. <br>
  954. <div class="row">
  955. <div class="col-sm-offset-9 col-sm-2">
  956. <button type='button' class='btn btn-xs btn-default' onclick='addSelectableQuestion()'>Add Question</button>
  957. </div>
  958. </div>
  959. <!-- ERROR ALERT FOR USER -->
  960. <div id="error-newMoment" class="row" style="display: none;">
  961. <div class="col-sm-12">
  962. <div class="alert alert-danger mb-1" role="alert">
  963. <h4 class="error-lead">Error!</h4>
  964. <p class="error-description"></p>
  965. </div>
  966. </div>
  967. </div>
  968. </div><!--modal-body-->
  969. <!-- NEXT OR CANCEL -->
  970. <div class="modal-footer">
  971. <button type="button" class="btn btn-default" data-dismiss="modal" onclick="nextModal('#NewMoment')">Previous</button>
  972. <button type="submit" class="btn btn-primary" name="newMoment" <?php if(mysqli_num_rows($result7) == 0) { echo 'disabled'; } ?>>Create</button>
  973. </div>
  974. </div><!--modal-content-->
  975. </div><!--modal-dialog-->
  976. </div><!--modal-->
  977. </form>
  978. <!-- POPUP FOR NEW MILESTONE -->
  979. <form id="newMilestone">
  980. <div class="modal fade" id="NewMilestone" tabindex="-1" role="dialog" aria-labelledby="NewMilestoneLabel" aria-hidden="true">
  981. <div class="modal-dialog" role="document"">
  982. <div class="modal-content">
  983. <div class="modal-body">
  984. <!-- CLOSE BUTTON -->
  985. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  986. <span aria-hidden="true">&times;</span>
  987. </button>
  988. <div class="row">
  989. <div class="col-sm-10">
  990. <h2>New Milestone</h2>
  991. </div>
  992. </div><!--row-->
  993. <hr><br>
  994. <div class="form-horizontal">
  995. <!-- EXPERIENCE ID -->
  996. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  997. <!-- TITLE -->
  998. <div class="form-group">
  999. <label class="control-label col-sm-2">Title:</label>
  1000. <div class="col-sm-9">
  1001. <input type="text" class="form-control text-center" name="mil_title" maxlength="256" placeholder="Title" required>
  1002. </div>
  1003. </div>
  1004. <!-- DATE -->
  1005. <div class="form-group">
  1006. <label class="control-label col-sm-2">Date:</label>
  1007. <div class="col-sm-9">
  1008. <input type="date" class="form-control text-center" name="mil_date" placeholder="YYYY-MM-DD" required>
  1009. </div>
  1010. </div>
  1011. </div>
  1012. <!-- ERROR ALERT FOR USER -->
  1013. <div id="error-newMilestone" class="row" style="display: none;">
  1014. <div class="col-sm-12">
  1015. <div class="alert alert-danger mb-1" role="alert">
  1016. <h4 class="error-lead">Error!</h4>
  1017. <p class="error-description"></p>
  1018. </div>
  1019. </div>
  1020. </div>
  1021. </div><!--modal-body-->
  1022. <!-- NEXT OR CANCEL -->
  1023. <div class="modal-footer">
  1024. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  1025. <button type="submit" class="btn btn-primary" name="newMilestone">Create</button>
  1026. </div>
  1027. </div><!--modal-content-->
  1028. </div><!--modal-dialog-->
  1029. </div><!--modal-->
  1030. </form>
  1031. <!-- STORE START DATE FOR CALENDAR RERENDERING LATER -->
  1032. <input id="experience_start_date" type="hidden" value="<?php echo $row1['start_date']; ?>">
  1033. <!-- FULL CALENDAR IMPORTS -->
  1034. <script src="processes/fullcalendar/packages/core/main.min.js"></script>
  1035. <script src="processes/fullcalendar/packages/daygrid/main.min.js"></script>
  1036. <script src="processes/fullcalendar/packages/timegrid/main.min.js"></script>
  1037. <script src="processes/fullcalendar/packages/interaction/main.min.js"></script>
  1038. <!-- <script src="https://unpkg.com/@fullcalendar/core/main.min.js"></script> -->
  1039. <!-- <script src="https://unpkg.com/@fullcalendar/daygrid/main.min.js"></script> -->
  1040. <!-- <script src="https://unpkg.com/@fullcalendar/timegrid@4.3.0/main.min.js"></script> -->
  1041. <!-- <script src="https://unpkg.com/@fullcalendar/interaction@4.3.0/main.min.js"></script> -->
  1042. <script src="js/viewExperience.js"></script>
  1043. <script src="js/handleSubmit.js"></script>
  1044. <script>
  1045. ["editForm", "newQuestionnaire", "newMoment", "newMilestone"].forEach(function(formName) {
  1046. var form = document.getElementById(formName);
  1047. if(form) {
  1048. form.addEventListener('submit', function(e) {
  1049. handleSubmit(e, formName);
  1050. });
  1051. }
  1052. });
  1053. //window.onload = function() {
  1054. // First load an empty calendar
  1055. var calendarElement = document.getElementById('actualCalendar');
  1056. var calendar = new FullCalendar.Calendar(calendarElement, {
  1057. plugins: [ 'dayGrid', 'timeGrid', 'interaction' ],
  1058. header: {
  1059. left: 'prev,next today',
  1060. center: 'title',
  1061. right: 'dayGridMonth,timeGridWeek,timeGridDay'
  1062. },
  1063. defaultDate: document.getElementById('experience_start_date').value,
  1064. businessHours: true,
  1065. editable: true,
  1066. dragScroll: true,
  1067. eventDrop: function(eventDropInfo) {
  1068. $.post(document.location.protocol + "//tania.uprrp.edu/admin_nuevo/special4.php", {
  1069. id: eventDropInfo.event.id,
  1070. experienceID: document.querySelector('input[name=id_experience]').value,
  1071. newStartDate: Date.parse(eventDropInfo.event.start), // convert to UNIX timestamp
  1072. newEndDate: Date.parse(eventDropInfo.event.end) // convert to UNIX timestamp
  1073. }).fail(function() {
  1074. alert('An error occurred! Resetting calendar...');
  1075. eventDropInfo.revert();
  1076. });
  1077. }
  1078. });
  1079. calendar.render();
  1080. // After the rest of the page has loaded, fetch events from DB & re-render calendar
  1081. var calendarConfig;
  1082. $.post(document.location.protocol + "//tania.uprrp.edu/admin_nuevo/special2.php",
  1083. {
  1084. experienceID: document.querySelector('input[name=id_experience]').value
  1085. },
  1086. function(data, status) {
  1087. if(!isJSON(data)) {
  1088. return;
  1089. }
  1090. calendarConfig = JSON.parse(data);
  1091. }
  1092. ).done(function() {
  1093. // console.log(calendarConfig);
  1094. if(calendarConfig === undefined) {
  1095. alert("Couldn't fetch your events! Please refresh this page. If this keeps ocurring, contact the page administrator.");
  1096. return;
  1097. }
  1098. calendarConfig.events.forEach(calendarEvent => {
  1099. calendar.addEvent(calendarEvent);
  1100. });
  1101. calendar.render();
  1102. }).fail(function() {
  1103. alert("Couldn't fetch your events! Please refresh this page. If this keeps ocurring, contact the page administrator.");
  1104. });
  1105. //}//domcontentloaded//onload
  1106. </script>
  1107. <?php include_once 'footer.php'; ?>