PageRenderTime 99ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/classes.php

https://github.com/camlegleiter/Project-Pencl
PHP | 378 lines | 353 code | 13 blank | 12 comment | 10 complexity | 454a56352cd6fb6f4329490b15e67c9e MD5 | raw file
  1. <?php
  2. //Must be on top of everything to function correctly
  3. include 'includes/headerbarFunctions.php';
  4. //Include this inside the <head> tag to require user to be logged in to view the page.
  5. include 'includes/membersOnly.php';
  6. include 'includes/class_functions.php';
  7. if (isset($_GET['class']) && isset($_GET['id']))
  8. {
  9. if (strcmp(strtolower($_GET['delete']), 'notepad') == 0)
  10. {
  11. //Remove notepad from class
  12. removeNotepadFromClass($_GET['id'], $_GET['class']);
  13. }
  14. else if (strcmp(strtolower($_GET['delete']), 'user') == 0)
  15. {
  16. removeStudentFromClass($_GET['id'], $_GET['class']);
  17. }
  18. }
  19. function getClassData($classid)
  20. {
  21. $arr = array();
  22. $classid = mysql_real_escape_string($classid);
  23. $padRow = mysql_query("SELECT name,description,password,owner FROM classes WHERE id='$classid'");
  24. $row = mysql_fetch_assoc($padRow);
  25. if ($row)
  26. {
  27. $arr['name'] = $row['name'];
  28. $arr['description'] = $row['description'];
  29. $arr['password'] = $row['password'];
  30. $arr['owner'] = $row['owner'];
  31. $arr['id'] = $classid;
  32. }
  33. else
  34. {
  35. $arr['name'] = "Error: Couldn't find class name";
  36. $arr['description'] = "Error: Couldn't find class description";
  37. $arr['password'] = "";
  38. $arr['owner'] = "Error: Couldn't find class owner";
  39. $arr['id'] = $classid;
  40. }
  41. mysql_free_result($padRow);
  42. return $arr;
  43. }
  44. function printAllNotepads($classid)
  45. {
  46. $classid = mysql_real_escape_string($classid);
  47. $padRow = mysql_query("SELECT notebookid FROM classbooks WHERE classid='$classid'");
  48. $notepadHTML = "";
  49. while ($row = mysql_fetch_assoc($padRow))
  50. {
  51. $notepadHTML = $notepadHTML.getNotepadRow($row['notebookid'],$classid);
  52. }
  53. mysql_free_result($padRow);
  54. return $notepadHTML;
  55. }
  56. function printAllStudents($classid)
  57. {
  58. $classid = mysql_real_escape_string($classid);
  59. $padRow = mysql_query("SELECT userid FROM classmates WHERE classid='$classid'");
  60. $notepadHTML = "";
  61. $num = 1;
  62. while ($row = mysql_fetch_assoc($padRow))
  63. {
  64. $notepadHTML = $notepadHTML.getStudentRow($row['userid'],$classid,$num);
  65. $num++;
  66. }
  67. mysql_free_result($padRow);
  68. return $notepadHTML;
  69. }
  70. function getNotepadRow($id,$classid)
  71. {
  72. $id = mysql_real_escape_string($id);
  73. $padRow = mysql_query("SELECT name,description,created,modified,userid FROM notebooks WHERE id='$id'");
  74. $row = mysql_fetch_assoc($padRow);
  75. $rowHTML = '';
  76. if($row){
  77. $rowHTML = '
  78. <tr>
  79. <td align="left">
  80. <a href="canvas.php?id='.$id.'&classid='.$classid.'">'.$row['name'].'</a>
  81. </td>
  82. <td align="left">
  83. '.getUsername($row['userid']).'
  84. </td>
  85. <td align="center">
  86. '.getNiceTime($row['modified']).'
  87. </td>
  88. <td align="center">
  89. '.getNiceTime($row['created']).'
  90. </td>
  91. <td align="center">
  92. <a href="./classes.php?class='.$classid.'&id='.$id.'&delete=notepad" onClick="return confirmRemoveNotepad()">
  93. <img src="img/buttons/pencl_delete.png" title="Remove from class" alt="Remove">
  94. </a>
  95. </td>
  96. </tr>
  97. ';
  98. }
  99. mysql_free_result($padRow);
  100. return $rowHTML;
  101. }
  102. function getStudentRow($id,$classid,$num)
  103. {
  104. $id = mysql_real_escape_string($id);
  105. $padRow = mysql_query("SELECT username FROM users WHERE userid='$id'");
  106. $row = mysql_fetch_assoc($padRow);
  107. $rowHTML = '';
  108. if($row){
  109. $rowHTML = '
  110. <tr>
  111. <td align="center">
  112. '.$num.'
  113. </td>
  114. <td align="left">
  115. '.$row['username'].'
  116. </td>
  117. <td align="center">
  118. <a href="./classes.php?class='.$classid.'&id='.$id.'&delete=user" onClick="return confirmRemoveStudent()">
  119. <img src="img/buttons/pencl_delete.png" title="Remove student from class" alt="Remove">
  120. </a>
  121. </td>
  122. </tr>
  123. ';
  124. }
  125. mysql_free_result($padRow);
  126. return $rowHTML;
  127. }
  128. function getAllClasses()
  129. {
  130. $userid = mysql_real_escape_string($_SESSION['id']);
  131. $classRow = mysql_query("SELECT name,description,password,id FROM classes WHERE owner='$userid'");
  132. $classHTML = "";
  133. while ($row = mysql_fetch_assoc($classRow))
  134. {
  135. $classHTML = $classHTML.'
  136. <tr>
  137. <td>
  138. <a href="?class='.$row['id'].'">'.$row['name'].'</a>
  139. </td>
  140. </tr>
  141. ';
  142. }
  143. mysql_free_result($classRow);
  144. return $classHTML;
  145. }
  146. $class = getClassData($_GET['class']);
  147. ?>
  148. <!DOCTYPE html>
  149. <html>
  150. <head>
  151. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  152. <title>Notepad Selection - Pencl</title>
  153. <!-- Load jQuery -->
  154. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  155. <script type="text/javascript">
  156. google.load("jquery", "1");
  157. </script>
  158. <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen">
  159. <link rel="stylesheet" type="text/css" href="css/styles.css" media="screen">
  160. <link rel="stylesheet" type="text/css" href="css/twocolumn.css" media="screen">
  161. <link rel="stylesheet" type="text/css" href="css/dialog/jqModal.css">
  162. <script type="text/javascript" src="js/dialog/jqModal.js"></script>
  163. <?php
  164. //Must be in header!
  165. include 'includes/topbar_header.php';
  166. ?>
  167. <?php
  168. //Put this at the end of the <head> tag to track
  169. include 'includes/tracker.php';
  170. ?>
  171. </head>
  172. <body>
  173. <?php
  174. //Must be first thing in the <body> tag to function correctly
  175. include 'includes/topbar.php';
  176. ?>
  177. <div id="pagewide">
  178. <h1>Manage Classes</h1>
  179. <div class="twoColumn">
  180. <div class="left">
  181. <table>
  182. <thead>
  183. <tr class="head">
  184. <td>
  185. <strong>Classes:</strong>
  186. </td>
  187. </tr>
  188. </thead>
  189. <tbody>
  190. <?php
  191. //Grab our classes
  192. echo getAllClasses();
  193. ?>
  194. </tbody>
  195. </table>
  196. <br>
  197. <a href="createClass.php">Create a class</a>
  198. </div>
  199. <div class="right">
  200. <?php
  201. //Display table only if we are displaying a class
  202. //Start display
  203. if (is_numeric($_GET['class'])) {
  204. echo '<h1>Class: <strong>'.$class['name'].'</strong> ';
  205. echo '<a href="editClass.php?classid='.$class['id'].'">(Edit)</a>';
  206. echo '<a href= "#" onclick="deleteClass();"> (Delete)</a>';
  207. if (strlen($class['password']) > 0)
  208. {
  209. echo '<img src="img/buttons/pencl_lock.png" title="Password Protected" alt="(Password Protected)">';
  210. }
  211. echo '</h1>';
  212. echo '<p>Description: '.$class['description'].'</p>';
  213. ?>
  214. <br>
  215. <div class="notebook">
  216. <table>
  217. <thead>
  218. <tr class="head">
  219. <td>
  220. <strong>Notepad</strong>
  221. </td>
  222. <td>
  223. <strong>Creator</strong>
  224. </td>
  225. <td>
  226. <strong>Modified</strong>
  227. </td>
  228. <td>
  229. <strong>Created</strong>
  230. </td>
  231. <td>
  232. <strong>Options</strong>
  233. </td>
  234. </tr>
  235. </thead>
  236. <tbody>
  237. <?php
  238. //Grab our notepads
  239. echo printAllNotepads($_GET['class']);
  240. ?>
  241. </tbody>
  242. </table>
  243. </div>
  244. <br>
  245. <p>Tip: To add notebooks to this class, share them from your <a href="noteselection.php">notes</a></p>
  246. <br>
  247. <h1>Students enrolled:</h1>
  248. <div class="notebook">
  249. <table>
  250. <thead>
  251. <tr class="head">
  252. <td>
  253. <strong>#</strong>
  254. </td>
  255. <td>
  256. <strong>Username</strong>
  257. </td>
  258. <td>
  259. <strong>Options</strong>
  260. </td>
  261. </tr>
  262. </thead>
  263. <tbody>
  264. <?php
  265. //Grab our students
  266. echo printAllStudents($_GET['class']);
  267. ?>
  268. </tbody>
  269. </table>
  270. </div>
  271. <?php
  272. //End display
  273. }
  274. else
  275. {
  276. ?>
  277. <p>Select a class on the left, or <a href="createClass.php">create a class</a>.</p>
  278. <?php
  279. }
  280. ?>
  281. </div>
  282. </div>
  283. </div>
  284. <script type="text/javascript">
  285. function confirmRemoveStudent()
  286. {
  287. return confirm('Are you sure you want to remove this student?\nAll notepads linking to this student will also be removed!');
  288. }
  289. function confirmRemoveNotepad()
  290. {
  291. return confirm('Are you sure you want to remove this notepad?');
  292. }
  293. function confirmRemoveClass()
  294. {
  295. return confirm('Are you sure you want to Delete?');
  296. }
  297. function deleteClass()
  298. {
  299. var querystring = location.search.replace('?', '').split('&');
  300. var queryObj ={};
  301. for (var i = 0; i < querystring.length; i++) {
  302. var name = querystring[i].split('=')[0];
  303. var value = querystring[i].split('=')[1];
  304. queryObj[name] = value;
  305. }
  306. $.ajax({
  307. type: 'POST',
  308. url: './util/classPost.php',
  309. data: {
  310. action: 'delete',
  311. classid: parseInt(queryObj['class'])
  312. },
  313. statusCode: {
  314. 404: function() {
  315. alert('Page not found!');
  316. // Hide progress
  317. //tinymce.get('elm1').setProgressState(0);
  318. },
  319. 409: function(jqXHR, status, error) {
  320. alert('Error: ' + error);
  321. // Hide progress
  322. //tinymce.get('elm1').setProgressState(0);
  323. },
  324. 200: function(data) {
  325. alert(data);
  326. // Hide progress
  327. //window.setTimeout(function() {tinymce.get('elm1').setProgressState(0)}, 500);
  328. }
  329. }
  330. });
  331. confirmRemoveClass();
  332. var url = window.location.href;
  333. var newUrl = url.split('?');
  334. window.location.href = newUrl[0];
  335. }
  336. </script>
  337. </body>
  338. </html>