PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/www/assignment_comment.php

https://github.com/mtwstudios/comtor
PHP | 118 lines | 82 code | 22 blank | 14 comment | 14 complexity | 7a7d81268f4b79ce295247c028ca6907 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. $acctTypes = array("professor", "admin");
  3. require_once("loginCheck.php");
  4. if (!isset($_SESSION['courseId']) || !isset($_SESSION['courseInfo']))
  5. {
  6. $_SESSION['msg']['error'] = 'Course not set.';
  7. header('Location: index.php');
  8. exit;
  9. }
  10. $courseId = $_SESSION['courseId'];
  11. $courseInfo = $_SESSION['courseInfo'];
  12. // Check that userEventId is set
  13. if (!isset($_GET['userEventId']))
  14. {
  15. $_SESSION['msg']['error'] = 'User event not set.';
  16. header('Location: index.php');
  17. exit;
  18. }
  19. // Connect to database
  20. require_once("connect.php");
  21. require_once("mysqlFunctions.php");
  22. // Check that the userEventId was submitted for the current course
  23. if (!isReportForCourseAssignment($_GET['userEventId'], $courseId))
  24. {
  25. $_SESSION['msg']['error'] = 'User event is not for the current course.';
  26. header('Location: index.php');
  27. exit;
  28. }
  29. // Get comment
  30. $comment = getUserEventComment($_GET['userEventId'], false);
  31. if (!empty($_POST))
  32. {
  33. // Ensure that the security random number is correct
  34. $secure = false;
  35. require_once("securityFunctions.php");
  36. if (isset($_POST['securityRand']) && isset($_POST['securityPage']))
  37. if (checkSecurity($_POST['securityPage'], $_POST['securityRand']) == 1)
  38. $secure = true;
  39. if($secure)
  40. {
  41. // Check for errors
  42. $error = array();
  43. // Check course name field for problems
  44. if (!isset($_POST['comment']))
  45. $error[] = "Comment not entered.";
  46. // Assign errors
  47. if (!empty($error))
  48. {
  49. $_SESSION['msg']['error'] = implode('<br/>', $error);
  50. }
  51. else
  52. {
  53. $comment = $_POST['comment'];
  54. // Insert comment into database
  55. switch (setUserEventComment(89, $comment))
  56. {
  57. case 0:
  58. $_SESSION['msg']['success'] = 'Comment successfully set.';
  59. break;
  60. default:
  61. $_SESSION['msg']['error'] = 'There was an error setting the comment.';
  62. break;
  63. }
  64. }
  65. }
  66. else
  67. {
  68. $_SESSION['msg']['error'] = 'Security Error.';
  69. }
  70. if (isset($_POST['loc']))
  71. header('Location: '.$_POST['loc']);
  72. else
  73. header('Location: dropbox.php');
  74. exit;
  75. }
  76. require_once("smarty/Smarty.class.php");
  77. $tpl = new Smarty();
  78. require_once("header1.php");
  79. // Assign information
  80. $tpl->assign('comment', ($comment) ? $comment : '');
  81. // Get security fields
  82. require_once("securityFunctions.php");
  83. $tpl->assign(securityFormInputs());
  84. // Assign breadcrumbs
  85. $breadcrumbs = array();
  86. $breadcrumbs[] = array('text' => 'COMTOR', 'href' => 'index.php');
  87. $breadcrumbs[] = array('text' => $courseInfo['section'] . ': ' . $courseInfo['name'], 'href' => 'courses.php?courseId='.$courseId);
  88. $breadcrumbs[] = array('text' => 'Dropbox', 'href' => isset($_GET['loc']) ? $_GET['loc'] : 'dropbox.php');
  89. $breadcrumbs[] = array('text' => 'Submission Comment', 'href' => 'assignment_comment.php');
  90. $tpl->assign('breadcrumbs', $breadcrumbs);
  91. // Fetch template
  92. $tpldata = $tpl->fetch('assignment_comment.tpl');
  93. $tpl->assign('tpldata', $tpldata);
  94. // Display template
  95. $tpl->display("htmlmain.tpl");
  96. ?>