Advertisement
Guest User

memberpage.php

a guest
Nov 14th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.13 KB | None | 0 0
  1. <?php require('includes/config.php');
  2.  
  3. //if not logged in redirect to login page
  4. if(!$user->is_logged_in()){ header('Location: login.php'); exit(); }
  5.  
  6. $editmode = false;
  7. $restricted = false;
  8. $dialogContent = "";
  9. $changessaved = false;
  10. if(isset($_POST['submit'])) {
  11. if (isset($_POST['hwtitle']) && isset($_POST['hwdetails']) && isset($_POST['hwdonedate'])) {
  12. $name = $_POST['hwtitle'];
  13. $details = $_POST['hwdetails'];
  14. $donedate = $_POST['hwdonedate'];
  15. $owner = $_SESSION['username'];
  16. $stmt = $db->prepare('INSERT INTO homeworks (name,owner,details,donedate,done) VALUES (:name,:owner, :details, :donedate, :done)');
  17. $stmt->execute(array(
  18.  
  19. ':name' => $name,
  20. ':owner' => $owner,
  21. ':details' => $details,
  22. ':donedate' => $donedate,
  23. ':done' => '0'
  24. ));
  25. $id = $db->lastInsertId('homeworkID');
  26. header('Location: memberpage.php?savedsuccess=true');
  27. }
  28. } else if (isset($_GET['edit'])) {
  29. $stmt = $db->prepare('SELECT * FROM homeworks WHERE homeworkID = :id');
  30. $stmt->execute(array(':id' => $_GET['edit']));
  31. $row2edit = $stmt->fetch(PDO::FETCH_ASSOC);
  32.  
  33.  
  34. if ($row2edit['owner'] == $_SESSION['username']) {
  35. $editmode = true;
  36. $hwid = $_GET['edit'];
  37. $name = $row2edit['name'];
  38. $details = $row2edit['details'];
  39. $donedate = $row2edit['donedate'];
  40. $done= $row2edit['done'];
  41. $checked = "";
  42. if (!isset($done)) {
  43. $checked = "checked";
  44. }
  45. $dialogContent = " <div class=\"modal-header\">
  46. <h4 class=\"modal-title\" id=\"editModalLabel\">Muokkaa Läksy</h4>
  47. </div>
  48. <div class=\"modal-body\">
  49. <form action='https://developerfromjokela.com/homework/web/edithw.php' method=\"post\">
  50. <div class=\"form-group\">
  51. <label for=\"hwtitle\">Läksyn otsikko</label>
  52. <input type=\"text\" class=\"form-control\" name=\"hwtitle\" id=\"hwtitle\" placeholder=\"Biologian läksy...\" value=\"$name\"/>
  53. </div>
  54.  
  55. <div class=\"form-group\">
  56. <label for=\"hwdetails\">Läksyn tiedot</label>
  57. <input type=\"text\" class=\"form-control\" name=\"hwdetails\" id=\"hwdetails\" placeholder=\"Sivu 12 tehtävä 1 luettavaksi...\" value=\"$details\"/>
  58. </div>
  59.  
  60. <div class=\"form-group\">
  61. <label class=\"label-control\">Palautuspäivä</label>
  62. <input type=\"date\" name=\"hwdonedate\" value=\"$donedate\"/>
  63. </div>
  64. <div style='visibility: hidden;'>
  65. <input type='text' name='hwid' value='$hwid'/>
  66. </div>
  67.  
  68.  
  69. <label class=\"mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect\" for=\"checkbox-1\">
  70. <input type=\"checkbox\" id=\"checkbox-1\" name=\"done\" value=\"1\" class=\"mdl-checkbox__input\" $checked />
  71. <span class=\"mdl-checkbox__label\">Tehty</span>
  72. </label>
  73.  
  74.  
  75. <input type=\"submit\" name='submit' class=\"btn btn-primary\" value='Tallenna'/>
  76. <a href='memberpage.php' class='btn btn-primary'>Takaisin</a>
  77. </form>
  78. </div>";
  79. } else {
  80. $restricted = true;
  81. $dialogContent = "<div class=\"modal-header\">
  82. <h3 class=\"modal-title\" id=\"editModalLabel\">Virhe!</h3>
  83. </div>
  84. <div class=\"modal-body\">
  85.  
  86. <h1 class=\"modal-title\"> Sinulla ei ole oikeutta muokata henkilön ".$row2edit['owner']." läksyä! </h1>
  87. <a href='memberpage.php' class='btn btn-primary'>Takaisin</a>
  88. </div>";
  89.  
  90. }
  91.  
  92.  
  93. } else if (isset($_GET['restricted'])) {
  94. $dialogContent = "<div class=\"modal-header\">
  95. <h3 class=\"modal-title\" id=\"editModalLabel\">Virhe!</h3>
  96. </div>
  97. <div class=\"modal-body\">
  98.  
  99. <h1 class=\"modal-title\"> Sinulla ei ole oikeutta muokata henkilön " . $_GET['restricted'] . " läksyjä! </h1>
  100. <button type='button' data-dismiss=\"modal\" class='btn btn-primary'>Sulje</button>
  101. </div>";
  102. }
  103.  
  104. $stmt = $db->prepare('SELECT * FROM homeworks WHERE owner = :username');
  105. $stmt->execute(array(':username' => $_SESSION['username']));
  106.  
  107.  
  108.  
  109. //include header template
  110. include('layout/header2.php');
  111.  
  112.  
  113. ?>
  114. <div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
  115. <header class="demo-header mdl-layout__header mdl-color--grey-100 mdl-color-text--grey-600">
  116. <div class="mdl-layout__header-row">
  117. <span class="mdl-layout-title"><?php echo htmlspecialchars($_SESSION['name'], ENT_QUOTES); ?> - Läksyvihko</span>
  118. <div class="mdl-layout-spacer"></div>
  119. <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" id="hdrbtn">
  120. <i class="material-icons">more_vert</i>
  121. </button>
  122. <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right" for="hdrbtn">
  123. <li class="mdl-menu__item">Tietoja Läksyvihosta</li>
  124. </ul>
  125. </div>
  126. </header>
  127. <div class="demo-drawer mdl-layout__drawer mdl-color--blue-grey-900 mdl-color-text--blue-grey-50">
  128. <header class="demo-drawer-header">
  129. <img src="images/user.jpg" class="demo-avatar">
  130. <div class="demo-avatar-dropdown">
  131. <span style="text-overflow: ellipsis; white-space: nowrap;"><?php $out = strlen(htmlspecialchars($_SESSION['email'], ENT_QUOTES)) > 21 ? substr(htmlspecialchars($_SESSION['email'], ENT_QUOTES),0,21)."..." : htmlspecialchars($_SESSION['email'], ENT_QUOTES); echo $out ?></span>
  132. <br>
  133. <div class="mdl-layout-spacer"></div>
  134. <button id="accbtn" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
  135. <i class="material-icons" role="presentation">arrow_drop_down</i>
  136. <span class="visuallyhidden">Tilit</span>
  137. </button>
  138. <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="accbtn">
  139. <li class="mdl-menu__item"><?php $out = strlen(htmlspecialchars($_SESSION['username'], ENT_QUOTES)) > 21 ? substr(htmlspecialchars($_SESSION['username'], ENT_QUOTES),0,21)."..." : htmlspecialchars($_SESSION['username'], ENT_QUOTES); echo $out ?></li>
  140. <a class="mdl-menu__item" href="logout.php"><i class="material-icons">exit_to_app</i>Kirjaudu Ulos</a>
  141. </ul>
  142. </div>
  143. </header>
  144. <nav class="demo-navigation mdl-navigation mdl-color--blue-grey-800">
  145. <a class="mdl-navigation__link" href=""><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">home</i>Kotisivu</a>
  146. <a class="mdl-navigation__link" href=""><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">people</i>Profiilitiedot</a>
  147. <div class="mdl-layout-spacer"></div>
  148. </nav>
  149. </div>
  150. <main class="mdl-layout__content mdl-color--grey-100">
  151. <div class="mdl-grid demo-content">
  152.  
  153. <div class="demo-options mdl-card mdl-color--deep-purple-500 mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
  154. <div class="mdl-card__supporting-text mdl-color-text--blue-grey-50">
  155. <h3>Läksyt</h3>
  156.  
  157. <style>
  158. .demo-list-two {
  159. width: auto;
  160. }
  161. </style>
  162.  
  163. <ul class="demo-list-two mdl-list">
  164.  
  165.  
  166. <?php
  167. if ($stmt->rowCount() > 0) {
  168. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  169.  
  170.  
  171. $name = $row['name'];
  172. $details = $row['details'];
  173. $done = $row['done'];
  174. $hwid = $row['homeworkID'];
  175. $donedate = date_create($row['donedate']);
  176. $icon = "done_outline";
  177. if (isset($done)) {
  178. $icon = "done_outline";
  179. } else {
  180. $icon = "done";
  181. }
  182. echo(' <li class="mdl-list__item mdl-list__item--two-line">
  183. <span class="mdl-list__item-primary-content">
  184. <i class="material-icons mdl-list__item-avatar">book</i>
  185. <span style="color: white;">'.$name.'</span>
  186. <span class="mdl-list__item-sub-title" style="color: white;">'.$details.'</span>
  187. <span style="color: white;"><i class="material-icons">access_alarm</i>'.date_format($donedate, 'd.m.Y').'</span>
  188.  
  189.  
  190. </span>
  191. <span class="mdl-list__item-secondary-content">
  192. <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">'.$icon.'</i></a>
  193. <a class="mdl-list__item-secondary-action" href="memberpage.php?edit='.$hwid.'"><i class="material-icons">edit</i></a>
  194. </span> </li>');
  195. }
  196. } else {
  197. echo'<script>
  198. (function() {
  199. var snackbarContainer = document.querySelector(\'#saved_snackbar\');
  200. var handler = function(event) {
  201. }
  202. var data = {
  203. message: \'Ei läksyjä!\',
  204. timeout: 2000,
  205. actionHandler: handler,
  206. };
  207. snackbarContainer.MaterialSnackbar.showSnackbar(data);
  208.  
  209. }());
  210.  
  211.  
  212. </script>';
  213. echo(' <li class="mdl-list__item mdl-list__item--two-line">
  214. <span class="mdl-list__item-primary-content" style="color: white;">
  215. <i class="material-icons mdl-list__item-avatar">assignment_turned_in</i>
  216. <span style="color: white;">Ei läksyjä!</span>
  217. </span>
  218.  
  219. </li>');
  220. }
  221. ?>
  222.  
  223. </div>
  224. <div class="mdl-card__actions mdl-card--border">
  225. <button type="button" data-toggle="modal" data-target="#exampleModal" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-color-text--blue-grey-50">
  226. Lisää läksy
  227. </button>
  228. </div>
  229.  
  230. </div>
  231.  
  232. </div>
  233. <div id="saved_snackbar" class="mdl-js-snackbar mdl-snackbar">
  234. <div class="mdl-snackbar__text"></div>
  235. <button class="mdl-snackbar__action" type="button"></button>
  236. </div>
  237. </div>
  238. <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  239. <div class="modal-dialog" role="document">
  240. <div class="modal-content">
  241. <div class="modal-header">
  242. <h4 class="modal-title" id="exampleModalLabel">Lisää Läksy</h4>
  243. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  244. <span aria-hidden="true">&times;</span>
  245. </button>
  246. </div>
  247. <div class="modal-body">
  248. <form action="" method="post" id="">
  249. <div class="form-group">
  250. <label for="hwtitle">Läksyn otsikko</label>
  251. <input type="text" class="form-control" name="hwtitle" id="hwtitle" placeholder="Biologian läksy..."/>
  252. </div>
  253.  
  254. <div class="form-group">
  255. <label for="hwdetails">Läksyn tiedot</label>
  256. <input type="text" class="form-control" name="hwdetails" id="hwdetails" placeholder="Sivu 12 tehtävä 1 luettavaksi..."/>
  257. </div>
  258.  
  259. <div class="form-group">
  260. <label class="label-control">Palautuspäivä</label>
  261. <input type="date" name="hwdonedate"/>
  262. </div>
  263.  
  264.  
  265. <input type="submit" name="submit" class="btn btn-primary" value="Tallenna"/>
  266. </div>
  267. <div class="modal-footer">
  268. <button type="button" class="btn btn-secondary" data-dismiss="modal">Peruuta</button>
  269.  
  270. </div>
  271.  
  272. </div>
  273. </div>
  274. </div>
  275.  
  276. <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModal" aria-hidden="true">
  277. <div class="modal-dialog" role="document">
  278. <div class="modal-content">
  279. <?php
  280. if ($restricted === true) {
  281. echo ($dialogContent);
  282. } else if ($editmode === true) {
  283. echo ($dialogContent);
  284. }
  285. ?>
  286.  
  287. </div>
  288. </div>
  289. </div>
  290.  
  291. <?php
  292. if (isset($_GET['savedsuccess'])) {
  293. echo "<script>
  294. $(document).ready(function(){
  295. console.log('Jee');
  296. 'use strict';
  297. var snackbarContainer = document.querySelector('#saved_snackbar');
  298. var data = {
  299. message: 'Tallennettu Onnistuneesti!',
  300. timeout: 2000,
  301. actionHandler: handler
  302. };
  303. snackbarContainer.MaterialSnackbar.showSnackbar(data);}
  304. </script>";
  305.  
  306. } else if (isset($_GET['restricted'])) {
  307. $myCookie = $_COOKIE[$_SESSION['USERNAME']];
  308. echo "<script type='text/javascript'>
  309. $(document).ready(function(){
  310. $('#editModal').modal('show');
  311. });
  312. </script>";
  313. } else if ($editmode === true) {echo "<script type='text/javascript'>
  314. $(document).ready(function(){
  315. $('#editModal').modal('show');
  316. });
  317. </script>";
  318.  
  319. } else if ($restricted === true) {
  320. echo "<script type='text/javascript'>
  321. $(document).ready(function(){
  322. $('#editModal').modal('show');
  323. });</script>";
  324. }
  325.  
  326. //include header template
  327. require('layout/footer2.php');
  328. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement