Нет описания

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. require_once 'processes/config.php';
  3. require_once 'processes/dbh.inc.php';
  4. require_once 'processes/checkLogin.php';
  5. // IF USER IS DOESN'T HAVE ADMINISTRATOR PERMISIONS, EXIT
  6. if($_SESSION['dbUserData']['admin'] !== '1') {
  7. echo "You are unauthorized to view this page.";
  8. exit();
  9. }
  10. include_once 'header.php';
  11. ?>
  12. <!--START OF users.php -->
  13. <body>
  14. <header id="main-header">
  15. <a id="logo" href=".">
  16. TANIA
  17. <img src="./img/pen_800x800.png" alt="tania logo pen" width="25" height="25">
  18. </a>
  19. <div id="account">
  20. <a class="nav-link" href="#" onclick="location='home.php'"><i class="fas fa-arrow-left"></i> Back</a>
  21. <a class="sign-out" href="./processes/logout.php">Sign Out</a>
  22. </div>
  23. </header>
  24. <div class="container" style="margin-top: 8rem; min-height: calc(100vh - 8rem - 8rem);">
  25. <br>
  26. <div class="row">
  27. <div class="col-sm-12">
  28. <h2 class="text-muted"><?php echo $_SESSION['dbUserData']['name']; ?></h2>
  29. <!-- <p>Add new users, view their info and manage permissions!</p> -->
  30. </div>
  31. </div>
  32. <hr>
  33. <div class="row">
  34. <div class="col-sm-12">
  35. <h3>Add Researcher</h3>
  36. </div>
  37. </div>
  38. <form id="addUser" class="form-horizontal" method="POST" action="processes/addUser.php" onsubmit="addUser(event)">
  39. <div class="form-group">
  40. <label class="col-sm-2 control-label" for="exampleInputEmail1">Name</label>
  41. <div class="col-sm-10">
  42. <input type="text" name="name" class="form-control text-center" placeholder="i.e. Juan del Pueblo Villa" required autocomplete="off">
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-sm-2 control-label for="exampleInputEmail1">Email</label>
  47. <div class="col-sm-10">
  48. <input type="email" name="email" class="form-control text-center" placeholder="i.e. juan.delpueblo@upr.edu" required autocomplete="off">
  49. </div>
  50. </div>
  51. <div class="row">
  52. <div class="col-sm-4 col-sm-offset-5">
  53. <button type="submit" name="addUser" class="btn btn-primary btn-block">Add User</button>
  54. </div>
  55. </div>
  56. </form>
  57. <br>
  58. <!-- ERROR ALERT FOR USER -->
  59. <div id="error-addUser" class="row" style="display: none;">
  60. <div class="col-sm-10 col-sm-offset-2">
  61. <div class="alert alert-danger mb-1" role="alert">
  62. <h4 class="error-lead">Error!</h4>
  63. <p class="error-description"></p>
  64. </div>
  65. </div>
  66. </div>
  67. <br>
  68. <div class="row">
  69. <div class="col-sm-12">
  70. <h3>Researchers</h3>
  71. </div>
  72. <div class="col-sm-12">
  73. <table class="table table-hover table-striped table-responsive">
  74. <thead>
  75. <tr>
  76. <th style="text-align: center;"><h4>Name</h4></th>
  77. <th style="text-align: center;"><h4>Email</h4></th>
  78. <th style="text-align: center;"><h4>Manage</h4></th>
  79. </tr>
  80. </thead>
  81. <tbody>
  82. <?php
  83. $queryResearchers = "SELECT * FROM researcher;";
  84. $resultResearchers = mysqli_query($connection, $queryResearchers);
  85. while($rowResearchers = mysqli_fetch_assoc($resultResearchers)):
  86. ?>
  87. <tr>
  88. <td style="text-align: center;"><h5><?php echo $rowResearchers['name']; ?></h5></td>
  89. <td style="text-align: center;"><h5><a class="email" href="mailto:<?php echo $rowResearchers['email']; ?>"><?php echo $rowResearchers['email']; ?></a></h5></td>
  90. <td style="text-align: center;">
  91. <?php if($rowResearchers['admin'] === '1'): ?>
  92. <h5><sm class="text-muted">Already manager...</sm></h5>
  93. <?php else: ?>
  94. <button class="btn btn-sm btn-default" data-researcher="<?php echo $rowResearchers['id_researcher']; ?>" onclick="makeManager(event)">Make Manager</button>
  95. <?php endif; ?>
  96. </td>
  97. </tr>
  98. <?php endwhile; ?>
  99. </tbody>
  100. </table>
  101. </div><!--col-->
  102. </div><!--row-->
  103. <br><br><br>
  104. </div><!--container-->
  105. <style>
  106. .email {
  107. color: #333;
  108. transition: color 300ms ease;
  109. }
  110. .email:hover {
  111. color: #999;
  112. }
  113. </style>
  114. <script src="js/handleSubmit.js"></script>
  115. <script>
  116. ["addUser"].forEach(function(formName) {
  117. var form = document.getElementById(formName);
  118. if(form) {
  119. form.addEventListener('submit', function(e) {
  120. handleSubmit(e, formName);
  121. });
  122. }
  123. });
  124. function foo(e) {
  125. e.preventDefault();
  126. console.log(e.srcElement);
  127. return false;
  128. }
  129. function makeManager(e) {
  130. let button = e.currentTarget;
  131. let researcherID = button.getAttribute('data-researcher');
  132. // Create loader
  133. let loader = document.createElement('div');
  134. loader.style.display = "flex";
  135. loader.style.alignItems = "center";
  136. loader.style.justifyContent = "center";
  137. loader.style.height = "35px";
  138. let span = document.createElement('span');
  139. span.classList.add('loader');
  140. loader.appendChild(span);
  141. // Insert loader and remove button
  142. button.insertAdjacentElement('afterend', loader);
  143. button.remove();
  144. let URL = document.location.protocol + "//tania.uprrp.edu/admin_nuevo/processes/makeManager.php";
  145. let fields = {
  146. researcherID: researcherID
  147. };
  148. $.post(URL, fields)
  149. .done(function(data, text) {
  150. // Create Done!
  151. let h5 = document.createElement('h5');
  152. let sm = document.createElement('sm');
  153. sm.classList.add('text-success');
  154. sm.innerText = "Done!";
  155. h5.appendChild(sm);
  156. // Insert Done! and remove loader
  157. loader.insertAdjacentElement('afterend', h5);
  158. loader.remove();
  159. })
  160. .fail(function(request, status, error) {
  161. // Create Retry
  162. let retry = document.createElement('button');
  163. retry.className = "btn btn-sm btn-primary";
  164. retry.setAttribute('data-researcher', researcherID);
  165. retry.setAttribute('onclick', 'makeManager(event)');
  166. retry.innerText = "Retry";
  167. // Insert Retry and remove loader
  168. loader.insertAdjacentElement('afterend', retry);
  169. loader.remove();
  170. });
  171. }
  172. </script>
  173. <!-- END OF users.php -->
  174. <?php include_once 'footer.php'; ?>