No Description

viewExperience.php 56KB

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