Нема описа

viewExperience.php 55KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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" 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. <!--
  394. <!~~ NEW TYPE ~~>
  395. <div class='form-group'>
  396. <label class='control-label col-sm-2 col-sm-offset-1'>Type:</label>
  397. <div class='col-sm-7'>
  398. <input type='text' class='form-control text-center' name='newType' required value="<?php echo $row1['type']; ?>">
  399. </div>
  400. </div>
  401. <!~~ NEW DURATION ~~>
  402. <div class='form-group'>
  403. <label class='control-label col-sm-2 col-sm-offset-1'>Duration:</label>
  404. <div class='col-sm-7'>
  405. <input type='number' class='form-control text-center' name='newDuration' required value="<?php echo $row1['duration_weeks']; ?>" readonly>
  406. </div>
  407. </div>
  408. <!~~ NEW START DATE ~~>
  409. <div class='form-group'>
  410. <label class='control-label col-sm-2 col-sm-offset-1'>Start Date:</label>
  411. <div class='col-sm-7'>
  412. <input type='date' class='form-control text-center' name='newStart' required value="<?php echo $row1['start_date']; ?>">
  413. </div>
  414. </div>
  415. <!~~ NEW END DATE ~~>
  416. <div class='form-group'>
  417. <label class='control-label col-sm-2 col-sm-offset-1'>End Date:</label>
  418. <div class='col-sm-7'>
  419. <input type='date' class='form-control text-center' name='newEnd' required value="<?php echo $row1['end_date']; ?>">
  420. </div>
  421. </div>
  422. -->
  423. </div><!--form-horizontal-->
  424. <!-- ERROR ALERT FOR USER -->
  425. <div id="error-editForm" class="row" style="display: none;">
  426. <div class="col-sm-12">
  427. <div class="alert alert-danger mb-1" role="alert">
  428. <h4 class="error-lead">Error!</h4>
  429. <p class="error-description"></p>
  430. </div>
  431. </div>
  432. </div>
  433. </div><!--modal-body-->
  434. <!-- SUBMIT OR CANCEL -->
  435. <div class="modal-footer">
  436. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  437. <button type="submit" class="btn btn-primary" name="updateExperience" disabled>Save Changes</button>
  438. </div>
  439. </div><!--modal-content-->
  440. </div><!--modal-dialog-->
  441. </div><!--modal-->
  442. </form><!--form-->
  443. <!--FORM VALIDATION FOR EDIT EXPERIENCE-->
  444. <script>
  445. let newTitle = document.querySelector('[name=newTitle]');
  446. let newDescription = document.querySelector('[name=newDescription]');
  447. // let newType = document.querySelector('[name=newType]');
  448. newTitle.addEventListener('keyup', validateEditExperience);
  449. newTitle.addEventListener('change', validateEditExperience);
  450. newDescription.addEventListener('keyup', validateEditExperience);
  451. newDescription.addEventListener('change', validateEditExperience);
  452. // newType.addEventListener('keyup', validateEditExperience);
  453. // newType.addEventListener('change', validateEditExperience);
  454. // Only enable submit button when:
  455. // 1) changes are detected,
  456. // 2) and both strings (title and description) are not empty
  457. function validateEditExperience() {
  458. let updateExperience = document.querySelector('[name=updateExperience]');
  459. updateExperience.disabled = !newTitle.checkValidity() || !newDescription.checkValidity();
  460. }
  461. </script>
  462. <!-- POPUP FOR NEW QUESTIONNAIRE 1 -->
  463. <div class="modal fade" id="NewQuestionnaire" tabindex="-1" role="dialog" aria-labelledby="NewQuestionnaireLabel" aria-hidden="true">
  464. <div class="modal-dialog modal-lg" role="document">
  465. <div class="modal-content">
  466. <div class="modal-body">
  467. <!-- CLOSE BUTTON -->
  468. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  469. <span aria-hidden='true'>&times;</span>
  470. </button>
  471. <div class="row">
  472. <div class="col-sm-10">
  473. <h2>New Questionnaire <small>(Basic Info – <em>Part 1</em>)</small></h2>
  474. </div>
  475. </div><!--row-->
  476. <hr><br>
  477. <div class="form-horizontal">
  478. <!-- TITLE -->
  479. <div class="form-group">
  480. <label class="control-label col-sm-2">Title:</label>
  481. <div class="col-sm-9">
  482. <input type="text" class="form-control text-center" name="q_title_tentative" placeholder="Title" maxlength="100" required>
  483. </div>
  484. </div>
  485. <!-- DESCRIPTION -->
  486. <div class="form-group">
  487. <label class="control-label col-sm-2">Description:</label>
  488. <div class="col-sm-9">
  489. <textarea class="form-control text-center" name="description_tentative" rows="1" placeholder="Description" maxlength="200" required></textarea>
  490. </div>
  491. </div>
  492. <!-- REFERENCE -->
  493. <div class="form-group">
  494. <label class="control-label col-sm-2">Reference:</label>
  495. <div class="col-sm-9">
  496. <input type="text" class="form-control text-center" name="referencia_tentative" placeholder="Reference" maxlength="60" required>
  497. </div>
  498. </div>
  499. <br>
  500. <!-- CATEGORIES -->
  501. <div class="form-group">
  502. <label class="control-label col-sm-2">Categories:</label>
  503. <div class="col-sm-9">
  504. <textarea id="q_categories_tentative" class="form-control text-center" name="q_categories_tentative" rows="1" placeholder="Categories (comma separated)" required></textarea>
  505. </div>
  506. </div>
  507. <!-- SUBCATEGORIES -->
  508. <div class="form-group">
  509. <label class="control-label col-sm-2">Subcategories:</label>
  510. <div class="col-sm-9">
  511. <textarea id="q_subcategories_tentative" class="form-control text-center" name="q_subcategories_tentative" rows="1" placeholder="Subcategories (comma separated)" required></textarea>
  512. </div>
  513. </div>
  514. </div>
  515. <div class="row">
  516. <div class="col col-sm-offset-2 col-sm-9">
  517. <p class="alert alert-warning text-justify">
  518. <strong>Note:</strong> You should at least have the same number of subcategories as categories.
  519. </p>
  520. </div>
  521. </div>
  522. </div><!--modal-body-->
  523. <!-- NEXT OR CANCEL -->
  524. <div class="modal-footer">
  525. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  526. <button id="nextQuestionnaire" type="button" class='btn btn-primary' data-dismiss="modal" onclick="nextModal('#NewQuestionnaire_2')" disabled>Next</button>
  527. </div>
  528. </div><!--modal-content-->
  529. </div><!--modal-dialog-->
  530. </div><!--modal-->
  531. <!-- FORM VALIDATION FOR NEW QUESTIONNAIRE (BASIC INFO) -->
  532. <script>
  533. // Fetch the inputs in the first modal
  534. let questionnaireTitle = document.querySelector('[name=q_title_tentative]');
  535. let questionnaireDescription = document.querySelector('[name=description_tentative]');
  536. let questionnaireReference = document.querySelector('[name=referencia_tentative]');
  537. let categories = document.querySelector('[name=q_categories_tentative]');
  538. let subcategories = document.querySelector('[name=q_subcategories_tentative]');
  539. // Add onchange and onkeyup event listeners to each input in the first modal
  540. questionnaireTitle.addEventListener('keyup', validateNewQuestionnaire);
  541. questionnaireTitle.addEventListener('change', validateNewQuestionnaire);
  542. questionnaireDescription.addEventListener('keyup', validateNewQuestionnaire);
  543. questionnaireDescription.addEventListener('change', validateNewQuestionnaire);
  544. questionnaireReference.addEventListener('keyup', validateNewQuestionnaire);
  545. questionnaireReference.addEventListener('change', validateNewQuestionnaire);
  546. categories.addEventListener('keyup', validateNewQuestionnaire);
  547. categories.addEventListener('change', validateNewQuestionnaire);
  548. subcategories.addEventListener('keyup', validateNewQuestionnaire);
  549. subcategories.addEventListener('change', validateNewQuestionnaire);
  550. // Pass the values from the first modal to the second, where the actual (hidden) inputs reside
  551. questionnaireTitle.addEventListener('keyup', function() {
  552. document.querySelector('[name=q_title]').value = questionnaireTitle.value;
  553. });
  554. questionnaireDescription.addEventListener('keyup', function() {
  555. document.querySelector('[name=description]').value = questionnaireDescription.value;
  556. });
  557. questionnaireReference.addEventListener('keyup', function() {
  558. document.querySelector('[name=referencia]').value = questionnaireReference.value;
  559. });
  560. categories.addEventListener('keyup', function() {
  561. document.querySelector('[name=q_categories]').value = categories.value;
  562. });
  563. subcategories.addEventListener('keyup', function() {
  564. document.querySelector('[name=q_subcategories]').value = subcategories.value;
  565. });
  566. // First modal's validation function
  567. // This basically enables the "Next" button if certain conditions are met
  568. function validateNewQuestionnaire() {
  569. // Fetch "Next" button in modal
  570. let nextButton = document.querySelector('#nextQuestionnaire');
  571. // Check validity of each input (valid if not empty strings)
  572. let validity = questionnaireTitle.checkValidity();
  573. validity &= questionnaireDescription.checkValidity();
  574. validity &= questionnaireReference.checkValidity();
  575. validity &= categories.checkValidity();
  576. validity &= subcategories.checkValidity();
  577. // Questionnaire should have at least the same number of subcategories as categories
  578. let rawCategories = categories.value.split(',');
  579. let rawSubcategories = subcategories.value.split(',');
  580. let categoriesArray = new Array();
  581. let subcategoriesArray = new Array();
  582. // IF clause is necessary to avoid array WARNINGS and ERRORS
  583. if(categories.value != '' && subcategories.value != '') {
  584. // Store the "trimmed" categories in categoriesArray
  585. for(let i = 0; i < rawCategories.length; i++) {
  586. rawCategories[i] = rawCategories[i].trim();
  587. // if string not empty and not whitespace, insert as category option
  588. if(/\S/.test(rawCategories[i])) {
  589. categoriesArray.push(rawCategories[i]);
  590. }
  591. }
  592. // Store the "trimmed" subcategories in subcategoriesArray
  593. for(let i = 0; i < rawSubcategories.length; i++) {
  594. rawSubcategories[i] = rawSubcategories[i].trim();
  595. // if string not empty and not whitespace, insert as subcategory option
  596. if(/\S/.test(rawSubcategories[i])) {
  597. subcategoriesArray.push(rawSubcategories[i]);
  598. }
  599. }
  600. // Only valid if there are less or equal number of categories to subcategories
  601. validity &= categoriesArray.length <= subcategoriesArray.length;
  602. }
  603. // Disabled if not valid, enabled otherwise
  604. nextButton.disabled = !validity;
  605. }
  606. </script>
  607. <form id="newQuestionnaire"><!--method="POST" action="processes/insertQuestionnaire.php"-->
  608. <!-- POPUP FOR NEW QUESTIONNAIRE 2 -->
  609. <div class="modal fade" id="NewQuestionnaire_2" tabindex="-1" role="dialog" aria-labelledby="NewQuestionnaireLabel_2" aria-hidden="true">
  610. <div class="modal-dialog modal-lg" role="document">
  611. <div class="modal-content">
  612. <div class="modal-body">
  613. <!-- CLOSE BUTTON -->
  614. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  615. <span aria-hidden="true">&times;</span>
  616. </button>
  617. <div class="row">
  618. <div class="col-sm-10">
  619. <h2>New Questionnaire <small>(Questions – <em>Part 2</em>)</small></h2>
  620. </div>
  621. </div><!--row-->
  622. <hr>
  623. <!-- EXPERIENCE ID -->
  624. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  625. <!-- QUESTIONNAIRE TITLE -->
  626. <input type="hidden" name="q_title" maxlength="100" required>
  627. <!-- QUESTIONNAIRE DESCRIPTION --->
  628. <input type="hidden" name="description" maxlength="200" required>
  629. <!-- QUESTIONNAIRE REFERENCE -->
  630. <input type="hidden" name="referencia" maxlength="60" required>
  631. <!-- QUESTIONNAIRE CATEGORIES -->
  632. <input id="q_categories" type="hidden" name="q_categories" required>
  633. <!-- QUESTIONNAIRE SUBCATEGORIES -->
  634. <input id="q_subcategories" type="hidden" name="q_subcategories" required>
  635. <!-- QUESTION -->
  636. <div id="q1">
  637. <div class="row">
  638. <div class="col col-sm-offset-1">
  639. <h4>Question 1</h4>
  640. </div>
  641. </div>
  642. <div class="form-horizontal">
  643. <!-- PREMISE -->
  644. <div class="form-group">
  645. <label class="col-sm-offset-1 control-label col-sm-2">Premise:</label>
  646. <div class="col-sm-8">
  647. <input id="q_premise1" type="text" class="form-control text-center" name="q_premise1" placeholder="Premise" maxlength="600" required>
  648. </div>
  649. </div>
  650. <!-- TYPE -->
  651. <div class="form-group">
  652. <label class="col-sm-offset-1 control-label col-sm-2">Question Type:</label>
  653. <div class="col-sm-8">
  654. <select class="form-control text-center" id="q_type1" name="q_type1" style="width:100%; text-align-last:center;" onchange="newThing(event)" required>
  655. <!-- <option disabled selected value="">Type</option> -->
  656. <option value="1">Scaled</option>
  657. <option value="2">Open Answer</option>
  658. </select>
  659. </div>
  660. </div>
  661. </div>
  662. <!-- MIN/MAX VALUES/TEXT (OPTIONAL) -->
  663. <div id="range1">
  664. <div class="form-inline col col-sm-offset-2">
  665. <div class="form-group">
  666. <label class="control-label col-sm-2">Min. Value:</label>
  667. <div class="col-sm-8">
  668. <input type="number" class="form-control text-center" id="min_val1" name="min_val1" value="1" readonly>
  669. </div>
  670. </div>
  671. <div class="form-group">
  672. <label class="control-label col-sm-2">Min. Text:</label>
  673. <div class="col-sm-8">
  674. <input type="text" class="form-control text-center" id="min_text1" name="min_text1" maxlength="40" placeholder="Very Dissatisfied">
  675. </div>
  676. </div>
  677. </div>
  678. <div class="form-inline col col-sm-offset-2">
  679. <div class="form-group">
  680. <label class="control-label col-sm-2">Max. Value:</label>
  681. <div class="col-sm-1">
  682. <input type="number" class="form-control text-center" id="max_val1" name="max_val1" value="5" min="2">
  683. </div>
  684. </div>
  685. <div class="form-group">
  686. <label class="control-label col-sm-2">Max. Text:</label>
  687. <div class="col-sm-1">
  688. <input type="text" class="form-control text-center" id="max_text1" name="max_text1" maxlength="40" placeholder="Very Satisfied">
  689. </div>
  690. </div>
  691. </div>
  692. <br>
  693. </div>
  694. <div class="form-horizontal">
  695. <!-- CORRESPONDING CATEGORY -->
  696. <div class="form-group">
  697. <label class="col-sm-offset-1 control-label col-sm-2">Category:</label>
  698. <div class="col-sm-8">
  699. <select class="form-control text-center" id="q_category1" name="q_category1" style="width: 100%; text-align-last:center;" required>
  700. <!-- <option disabled selected value="">Category</option> -->
  701. </select>
  702. </div>
  703. </div>
  704. <!-- CORRESPONDING SUBCATEGORY -->
  705. <div class="form-group">
  706. <label class="col-sm-offset-1 control-label col-sm-2">Subcategory:</label>
  707. <div class="col-sm-8">
  708. <select class="form-control text-center" id="q_subcategory1" name="q_subcategory1" style="width: 100%; text-align-last:center;" required>
  709. <!-- <option disabled selected value="">Subcategory</option> -->
  710. </select>
  711. </div>
  712. </div>
  713. </div>
  714. </div>
  715. <br>
  716. <div class="row">
  717. <div class="col-sm-offset-9 col-sm-2">
  718. <button type="button" class="btn btn-xs btn-default" onclick="addQuestion()">Add Question</button>
  719. </div>
  720. </div>
  721. <!-- ERROR ALERT FOR USER -->
  722. <div id="error-newQuestionnaire" class="row" style="display: none;">
  723. <div class="col-sm-12">
  724. <div class="alert alert-danger mb-1" role="alert">
  725. <h4 class="error-lead">Error!</h4>
  726. <p class="error-description"></p>
  727. </div>
  728. </div>
  729. </div>
  730. </div><!--modal-body-->
  731. <!-- SUBMIT OR PREVIOUS -->
  732. <div class="modal-footer">
  733. <button type="button" class="btn btn-default" data-dismiss="modal" onclick="nextModal('#NewQuestionnaire')">Previous</button>
  734. <button type="submit" class="btn btn-primary" name="createQuestionnaire">Create</button>
  735. </div>
  736. </div><!--modal-content-->
  737. </div><!--modal-dialog-->
  738. </div><!--modal-->
  739. </form>
  740. <!-- POPUP FOR IMPORT QUESTIONNAIRE -->
  741. <form id="importQuestionnaire" method="post" action="processes/importQuestionnaire.php" class='form-horizontal' enctype="multipart/form-data">
  742. <div class='modal fade' id='Import' tabindex='-1' role='dialog' aria-labelledby='ImportLabel' aria-hidden='true'>
  743. <div class='modal-dialog modal-dialog-centered modal-md' role='document'>
  744. <div class='modal-content'>
  745. <div class='modal-header'>
  746. <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>
  747. </div>
  748. <div class='modal-body'>
  749. <div class="form-horizontal">
  750. <!-- EXPERIENCE ID -->
  751. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>" required>
  752. <!-- PROJECT ID (0 IF THERE'S NONE) -->
  753. <input type="hidden" name="projectID" value="<?php echo ($rowProject['id_project'] ? $rowProject['id_project'] : 0); ?>" required>
  754. <div class="row">
  755. <div class="col-sm-12">
  756. <h4>Download Template</h4>
  757. <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>
  758. <a class="btn btn-primary btn-sm btn-block" href="nameOfTheQuestionnair.xlsx">Download Template</a>
  759. </div>
  760. </div><!--row-->
  761. <br>
  762. <br>
  763. <div class="form-group">
  764. <div class="col-sm-10 col-sm-offset-2">
  765. <label for="exampleInputFile">Questionnaire in xlsx format</label>
  766. <input type="file" name='import'>
  767. <p class="help-block">Choose your .xlsx file (remember it has to have the correct format).</p>
  768. </div>
  769. </div><!--form-group-->
  770. </div>
  771. <!-- ERROR ALERT FOR USER -->
  772. <div id="error-importQuestionnaire" class="row" style="display: none;">
  773. <div class="col-sm-12">
  774. <div class="alert alert-danger mb-1" role="alert">
  775. <h4 class="error-lead">Error!</h4>
  776. <p class="error-description"></p>
  777. </div>
  778. </div>
  779. </div>
  780. </div><!--modal-body-->
  781. <div class='modal-footer'>
  782. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  783. <button type='submit' class='btn btn-primary' name='insertQuestionnaire'>Import</button>
  784. </div>
  785. </div><!--modal-content-->
  786. </div><!--modal-dialog-->
  787. </div><!--modal-->
  788. </form>
  789. <!-- POPUP FOR DUPLICATE QUESTIONNAIRE -->
  790. <form id="duplicateQuestionnaire" class='form-horizontal'>
  791. <div class='modal fade' id='Duplicate' tabindex='-1' role='dialog' aria-labelledby='DuplicateLabel' aria-hidden='true'>
  792. <div class='modal-dialog modal-dialog-centered' role='document'>
  793. <div class='modal-content'>
  794. <div class='modal-header'>
  795. <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>
  796. </div>
  797. <div class='modal-body'>
  798. <span class='text-center'>
  799. <h4>Copy a questionnaire from one experience to another</h4>
  800. </span>
  801. <br>
  802. <!-- PROJECT ID (0 IF THERE'S NONE) -->
  803. <input type="hidden" name="projectID" value="<?php echo ($rowProject['id_project'] ? $rowProject['id_project'] : 0); ?>">
  804. <!-- FROM QUESTIONNAIRE -->
  805. <label for="fromQuestionnaireID">Which Questionnaire:</label>
  806. <?php
  807. // FIRST ASSUME FALSE
  808. $errorDuplicate = false;
  809. $queryQuestionnaires = "SELECT * FROM `questionnair` WHERE id IN (SELECT id_questionnair FROM experience_questionnair WHERE id_experience = '$experienceID');";
  810. $resultQuestionnaires = mysqli_query($connection, $queryQuestionnaires);
  811. if($resultQuestionnaires->num_rows > 0):
  812. ?>
  813. <select class="form-control text-center" id="fromQuestionnaireID" name="fromQuestionnaireID" style="text-align-last:center;" required>
  814. <?php while($rowQuestionnaires = mysqli_fetch_assoc($resultQuestionnaires)): ?>
  815. <option value="<?php echo $rowQuestionnaires['id']; ?>"><?php echo $rowQuestionnaires['q_title']; ?></option>
  816. <?php endwhile; ?>
  817. </select>
  818. <?php
  819. else:
  820. $errorDuplicate = true;
  821. ?>
  822. <h3 class="text-center"><small>It seems you still haven't added any questionnaires to this experience...</small></h3>
  823. <?php endif; ?>
  824. <br>
  825. <!-- TO EXPERIENCE -->
  826. <label for="toExperienceID">To What Experience:</label>
  827. <?php
  828. // CHANGE QUERY DEPENDING ON IF USER IS ADMIN OR NOT
  829. if($_SESSION['dbUserData']['admin'] === '1') {
  830. $queryExperience2 = "SELECT * FROM `experience` WHERE id != '$experienceID';";
  831. } else {
  832. $queryExperience2 = "SELECT * FROM `experience` WHERE id != '$experienceID' AND id IN (SELECT id_experience FROM researcher_experience WHERE id_researcher = '" . $_SESSION['dbUserData']['id_researcher'] . "');";
  833. }
  834. $resultExperience2 = mysqli_query($connection, $queryExperience2);
  835. if($resultExperience2->num_rows > 0):
  836. ?>
  837. <select class="form-control text-center" id="toExperienceID" name="toExperienceID" style="text-align-last:center;" required>
  838. <?php while($rowExperience2 = mysqli_fetch_assoc($resultExperience2)): ?>
  839. <option value="<?php echo $rowExperience2['id']; ?>"><?php echo $rowExperience2['title']; ?></option>
  840. <?php endwhile; ?>
  841. </select>
  842. <?php
  843. else:
  844. $errorDuplicate = true;
  845. ?>
  846. <h3 class="text-center"><small>You don't have another experience to duplicate to...</small></h3>
  847. <?php endif; ?>
  848. <br>
  849. <!-- ERROR ALERT FOR USER -->
  850. <div id="error-duplicateQuestionnaire" class="row" style="display: none;">
  851. <div class="col-sm-12">
  852. <div class="alert alert-danger mb-1" role="alert">
  853. <h4 class="error-lead">Error!</h4>
  854. <p class="error-description"></p>
  855. </div>
  856. </div>
  857. </div>
  858. </div><!--modal-body-->
  859. <!-- SUBMIT OR CANCEL -->
  860. <div class='modal-footer'>
  861. <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
  862. <button type='submit' class='btn btn-primary' name='duplicateQuestionnaire' <?php if($errorDuplicate === true) echo "disabled"; ?>>Confirm</button>
  863. </div>
  864. </div><!--modal-content-->
  865. </div><!--modal-dialog-->
  866. </div><!--modal-->
  867. </form>
  868. <!-- POPUP FOR NEW MOMENT 1 -->
  869. <form id="newMoment"><!--method='POST' action='processes/insertMoment.php'-->
  870. <div class="modal fade" id="NewMoment" tabindex="-1" role="dialog" aria-labelledby="NewMomentLabel" aria-hidden="true">
  871. <div class="modal-dialog modal-lg" role="document">
  872. <div class="modal-content">
  873. <div class="modal-body">
  874. <!-- CLOSE BUTTON -->
  875. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  876. <span aria-hidden='true'>&times;</span>
  877. </button>
  878. <div class="row">
  879. <div class="col-sm-10">
  880. <h2>New Moment <small>(Basic Info – <em>Part 1</em>)</small></h2>
  881. </div>
  882. </div><!--row-->
  883. <hr><br>
  884. <div class="form-horizontal">
  885. <!--EXPERIENCE ID-->
  886. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  887. <!-- TITLE -->
  888. <div class="form-group">
  889. <label class="control-label col-sm-2">Title:</label>
  890. <div class="col-sm-9">
  891. <input type="text" class="form-control text-center" name="m_title" maxlength="60" placeholder="Title" required>
  892. </div>
  893. </div>
  894. <!-- DESCRIPTION -->
  895. <div class="form-group">
  896. <label class="control-label col-sm-2">Description:</label>
  897. <div class="col-sm-9">
  898. <textarea class="form-control text-center" name="m_description" rows="1" style="resize:vertical;" maxlength="100" placeholder="Description" required></textarea>
  899. </div>
  900. </div>
  901. <!-- DATE TO ADMINISTER -->
  902. <div class="form-group">
  903. <label class="control-label col-sm-2">Date to Administer:</label>
  904. <div class="col-sm-9">
  905. <input type="datetime-local" class="form-control text-center" name="m_date" placeholder="YYYY-MM-DDThh:mm" required>
  906. </div>
  907. </div>
  908. <!-- CORRESPONDING QUESTIONNAIRE -->
  909. <?php
  910. $query7 = "SELECT * FROM `questionnair` WHERE `id` IN (SELECT `id_questionnair` FROM `experience_questionnair` WHERE `id_experience` = '$experienceID');";
  911. $result7 = mysqli_query($connection, $query7);
  912. // IF THE EXPERIENCE HAS AT LEAST ONE QUESTIONNAIRE ASSOCIATED TO IT, SHOW IT
  913. // ELSE, DISPLAY A MESSAGE TO THE USER LETTING THEM KNOW THEY DON'T HAVE ONE
  914. if(mysqli_num_rows($result7) > 0):
  915. ?>
  916. <div class="form-group">
  917. <label class="control-label col-sm-2">Questionnaire:</label>
  918. <div class="col-sm-9">
  919. <select class="form-control" id="m_questionnaire" name="m_questionnaire" style="width:100%; text-align-last:center;" required>
  920. <option disabled selected value>Corresponding Questionnaire</option>
  921. <?php while($row7 = mysqli_fetch_assoc($result7)): ?>
  922. <option value="<?php echo $row7['id']; ?>"><?php echo $row7['q_title']; ?></option>
  923. <?php endwhile; ?>
  924. </select>
  925. </div>
  926. </div>
  927. <?php else: ?>
  928. <div class="text-center">
  929. <h3><small>First add a questionnaire!</small></h3>
  930. </div>
  931. <?php endif; ?>
  932. </div><!--form-horizontal-->
  933. </div><!--modal-body-->
  934. <!-- NEXT OR CANCEL -->
  935. <div class="modal-footer">
  936. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  937. <button id="nextMoment" type="button" class="btn btn-primary" data-dismiss="modal" onclick="nextModal('#NewMoment_2')" disabled>Next</button>
  938. </div>
  939. </div><!--modal-content-->
  940. </div><!--modal-dialog-->
  941. </div><!--modal-->
  942. <!-- FORM VALIDATION FOR NEW MOMENT (BASIC INFO) -->
  943. <script>
  944. // Fetch the inputs in the first modal
  945. let momentTitle = document.querySelector('[name=m_title]');
  946. let momentDescription = document.querySelector('[name=m_description]');
  947. let momentDate = document.querySelector('[name=m_date]');
  948. let momentQuestionnaire = document.querySelector('[name=m_questionnaire]');
  949. // Add onchange and onkeyup event listeners to each input in the first modal
  950. momentTitle.addEventListener('keyup', validateNewMoment);
  951. momentTitle.addEventListener('change', validateNewMoment);
  952. momentDescription.addEventListener('keyup', validateNewMoment);
  953. momentDescription.addEventListener('change', validateNewMoment);
  954. momentDate.addEventListener('keyup', validateNewMoment);
  955. momentDate.addEventListener('change', validateNewMoment);
  956. // User may not have a questionnaire yet, thus momentQuestionnaire might be null
  957. if(momentQuestionnaire) {
  958. momentQuestionnaire.addEventListener('keyup', validateNewMoment);
  959. momentQuestionnaire.addEventListener('change', validateNewMoment);
  960. }
  961. // First modal's validation function
  962. // This basically enables the "Next" button if certain conditions are met
  963. function validateNewMoment() {
  964. // Fetch "Next" button in modal
  965. let nextButton = document.querySelector('#nextMoment');
  966. // Check validity of each input (valid if not empty strings & "maxlength" is set)
  967. let validity = momentTitle.checkValidity();
  968. validity &= momentDescription.checkValidity();
  969. validity &= momentDate.checkValidity();
  970. // If user doesn't have a questionnaire yet, he can't create a moment
  971. if(momentQuestionnaire) {
  972. validity &= momentQuestionnaire.checkValidity();
  973. } else {
  974. validity = false;
  975. }
  976. // Disabled if not valid, enabled otherwise
  977. nextButton.disabled = !validity;
  978. }
  979. </script>
  980. <!-- POPUP FOR NEW MOMENT 2 -->
  981. <div class="modal fade" id="NewMoment_2" tabindex="-1" role="dialog" aria-labelledby="NewMomentLabel_2" aria-hidden="true">
  982. <div class="modal-dialog modal-lg" role="document">
  983. <div class="modal-content">
  984. <div class="modal-body">
  985. <!-- CLOSE BUTTON -->
  986. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  987. <span aria-hidden='true'>&times;</span>
  988. </button>
  989. <div class="row">
  990. <div class="col-sm-10">
  991. <h2>New Moment <small>(Questions – <em>Part 2</em>)</small></h2>
  992. </div>
  993. </div><!--row-->
  994. <hr><br>
  995. <!-- QUESTION -->
  996. <div id="qq1">
  997. <div class="row">
  998. <div class="col-sm-11 col-sm-offset-1">
  999. <h4>Question 1</h4>
  1000. </div>
  1001. </div>
  1002. <!-- CHOOSE QUESTION FROM CORRESPONDING QUESTIONNAIRE -->
  1003. <div class="form-horizontal">
  1004. <div class="form-group">
  1005. <div class='col-sm-offset-2 col-sm-9'>
  1006. <select class="form-control" id="m_question_1" name="m_question_1" style="width:100%; text-align-last:center;" required>
  1007. <option disabled selected value>Select Question</option>
  1008. </select>
  1009. </div>
  1010. </div>
  1011. </div>
  1012. <br>
  1013. </div><!--#qq-->
  1014. <div class="row">
  1015. <div class="col-sm-offset-9 col-sm-2">
  1016. <button type='button' class='btn btn-xs btn-default' onclick='addSelectableQuestion()'>Add Question</button>
  1017. </div>
  1018. </div>
  1019. <!-- ERROR ALERT FOR USER -->
  1020. <div id="error-newMoment" class="row" style="display: none;">
  1021. <div class="col-sm-12">
  1022. <div class="alert alert-danger mb-1" role="alert">
  1023. <h4 class="error-lead">Error!</h4>
  1024. <p class="error-description"></p>
  1025. </div>
  1026. </div>
  1027. </div>
  1028. </div><!--modal-body-->
  1029. <!-- NEXT OR CANCEL -->
  1030. <div class="modal-footer">
  1031. <button type="button" class="btn btn-default" data-dismiss="modal" onclick="nextModal('#NewMoment')">Previous</button>
  1032. <button type="submit" class="btn btn-primary" name="newMoment" <?php if(mysqli_num_rows($result7) == 0) { echo 'disabled'; } ?>>Create</button>
  1033. </div>
  1034. </div><!--modal-content-->
  1035. </div><!--modal-dialog-->
  1036. </div><!--modal-->
  1037. </form>
  1038. <!-- POPUP FOR NEW MILESTONE -->
  1039. <form id="newMilestone">
  1040. <div class="modal fade" id="NewMilestone" tabindex="-1" role="dialog" aria-labelledby="NewMilestoneLabel" aria-hidden="true">
  1041. <div class="modal-dialog" role="document"">
  1042. <div class="modal-content">
  1043. <div class="modal-body">
  1044. <!-- CLOSE BUTTON -->
  1045. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1046. <span aria-hidden="true">&times;</span>
  1047. </button>
  1048. <div class="row">
  1049. <div class="col-sm-10">
  1050. <h2>New Milestone</h2>
  1051. </div>
  1052. </div><!--row-->
  1053. <hr><br>
  1054. <div class="form-horizontal">
  1055. <!-- EXPERIENCE ID -->
  1056. <input type="hidden" name="id_experience" value="<?php echo $experienceID; ?>">
  1057. <!-- TITLE -->
  1058. <div class="form-group">
  1059. <label class="control-label col-sm-2">Title:</label>
  1060. <div class="col-sm-9">
  1061. <input type="text" class="form-control text-center" name="mil_title" maxlength="256" placeholder="Title" required>
  1062. </div>
  1063. </div>
  1064. <!-- DATE -->
  1065. <div class="form-group">
  1066. <label class="control-label col-sm-2">Date:</label>
  1067. <div class="col-sm-9">
  1068. <input type="date" class="form-control text-center" name="mil_date" placeholder="YYYY-MM-DD" required>
  1069. </div>
  1070. </div>
  1071. </div>
  1072. <!-- ERROR ALERT FOR USER -->
  1073. <div id="error-newMilestone" class="row" style="display: none;">
  1074. <div class="col-sm-12">
  1075. <div class="alert alert-danger mb-1" role="alert">
  1076. <h4 class="error-lead">Error!</h4>
  1077. <p class="error-description"></p>
  1078. </div>
  1079. </div>
  1080. </div>
  1081. </div><!--modal-body-->
  1082. <!-- NEXT OR CANCEL -->
  1083. <div class="modal-footer">
  1084. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  1085. <button type="submit" class="btn btn-primary" name="newMilestone">Create</button>
  1086. </div>
  1087. </div><!--modal-content-->
  1088. </div><!--modal-dialog-->
  1089. </div><!--modal-->
  1090. </form>
  1091. <!-- STORE START DATE FOR CALENDAR RERENDERING LATER -->
  1092. <input id="experience_start_date" type="hidden" value="<?php echo $row1['start_date']; ?>">
  1093. <!-- FULL CALENDAR IMPORTS -->
  1094. <script src="processes/fullcalendar/packages/core/main.min.js"></script>
  1095. <script src="processes/fullcalendar/packages/daygrid/main.min.js"></script>
  1096. <script src="processes/fullcalendar/packages/timegrid/main.min.js"></script>
  1097. <script src="processes/fullcalendar/packages/interaction/main.min.js"></script>
  1098. <!-- <script src="https://unpkg.com/@fullcalendar/core/main.min.js"></script> -->
  1099. <!-- <script src="https://unpkg.com/@fullcalendar/daygrid/main.min.js"></script> -->
  1100. <!-- <script src="https://unpkg.com/@fullcalendar/timegrid@4.3.0/main.min.js"></script> -->
  1101. <!-- <script src="https://unpkg.com/@fullcalendar/interaction@4.3.0/main.min.js"></script> -->
  1102. <script src="js/viewExperience.js"></script>
  1103. <script src="js/handleSubmit.js"></script>
  1104. <script>
  1105. // Enable popovers
  1106. $(function () {
  1107. $('[data-toggle="popover"]').popover();
  1108. });
  1109. // Removed "importQuestionnaire" because of weird non-fetching behaviour of importQuestionnaire.php
  1110. ["editForm", "newQuestionnaire", "newMoment", "newMilestone", "duplicateQuestionnaire"].forEach(function(formName) {
  1111. var form = document.getElementById(formName);
  1112. if(form) {
  1113. form.addEventListener('submit', function(e) {
  1114. handleSubmit(e, formName);
  1115. });
  1116. }
  1117. });
  1118. //window.onload = function() {
  1119. // First load an empty calendar
  1120. var calendarElement = document.getElementById('actualCalendar');
  1121. var calendar = new FullCalendar.Calendar(calendarElement, {
  1122. plugins: [ 'dayGrid', 'timeGrid', 'interaction' ],
  1123. header: {
  1124. left: 'prev,next today',
  1125. center: 'title',
  1126. right: 'dayGridMonth,timeGridWeek'//,timeGridDay
  1127. },
  1128. defaultDate: document.getElementById('experience_start_date').value,
  1129. businessHours: true,
  1130. editable: true,
  1131. dragScroll: true,
  1132. eventDrop: function(eventDropInfo) {
  1133. $.post(document.location.protocol + "//tania.uprrp.edu/admin_nuevo/special4.php", {
  1134. id: eventDropInfo.event.id,
  1135. experienceID: document.querySelector('input[name=id_experience]').value,
  1136. newStartDate: Date.parse(eventDropInfo.event.start), // convert to UNIX timestamp
  1137. newEndDate: Date.parse(eventDropInfo.event.end) // convert to UNIX timestamp
  1138. }).fail(function() {
  1139. alert('An error occurred! Resetting calendar...');
  1140. eventDropInfo.revert();
  1141. });
  1142. }
  1143. });
  1144. calendar.render();
  1145. // After the rest of the page has loaded, fetch events from DB & re-render calendar
  1146. var calendarConfig;
  1147. $.post(document.location.protocol + "//tania.uprrp.edu/admin_nuevo/special2.php",
  1148. {
  1149. experienceID: document.querySelector('input[name=id_experience]').value
  1150. },
  1151. function(data, status) {
  1152. if(!isJSON(data)) {
  1153. return;
  1154. }
  1155. calendarConfig = JSON.parse(data);
  1156. }
  1157. ).done(function() {
  1158. // console.log(calendarConfig);
  1159. if(calendarConfig === undefined) {
  1160. alert("Couldn't fetch your events! Please refresh this page. If this keeps ocurring, contact the page administrator.");
  1161. return;
  1162. }
  1163. calendarConfig.events.forEach(calendarEvent => {
  1164. calendar.addEvent(calendarEvent);
  1165. });
  1166. calendar.render();
  1167. }).fail(function() {
  1168. alert("Couldn't fetch your events! Please refresh this page. If this keeps ocurring, contact the page administrator.");
  1169. });
  1170. //}//domcontentloaded//onload
  1171. </script>
  1172. <?php include_once 'footer.php'; ?>