Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.30 KB | None | 0 0
  1. <?php
  2. // This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
  3. //
  4. // VPL for Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // VPL for Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
  16.  
  17. /**
  18. * Grade submission
  19. *
  20. * @package mod_vpl
  21. * @copyright 2012 Juan Carlos Rodríguez-del-Pino
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. * @author Juan Carlos Rodríguez-del-Pino <jcrodriguez@dis.ulpgc.es>
  24. */
  25.  
  26. //******************Student Contribution*************************//
  27. //connect to moodle db
  28. require_once 'DBconnect.php';
  29. //******************Student Contribution*************************//
  30.  
  31.  
  32. require_once dirname(__FILE__) . '/../../../config.php';
  33. require_once dirname(__FILE__) . '/../locallib.php';
  34. require_once dirname(__FILE__) . '/grade_form.php';
  35. require_once dirname(__FILE__) . '/../vpl.class.php';
  36. require_once dirname(__FILE__) . '/../vpl_submission.class.php';
  37. require_once dirname(__FILE__) . '/../views/sh_factory.class.php';
  38.  
  39. function vpl_grade_header($vpl, $inpopup)
  40. {
  41. if ($inpopup) {
  42. $vpl->print_header_simple();
  43. } else {
  44. $vpl->print_header(get_string('grade'));
  45. $vpl->print_view_tabs(basename(__FILE__));
  46. }
  47. }
  48. require_login();
  49. $PAGE->requires->css(new moodle_url('/mod/vpl/css/grade.css'));
  50. vpl_include_jsfile('grade.js', false);
  51. vpl_include_jsfile('hide_footer.js', false);
  52. vpl_include_jsfile('updatesublist.js', false);
  53. vpl_sh_factory::include_js();
  54.  
  55. $id = required_param('id', PARAM_INT);
  56. $userid = required_param('userid', PARAM_INT);
  57. $vpl = new mod_vpl($id);
  58. $vpl->prepare_page('forms/gradesubmission.php', array(
  59. 'id' => $id,
  60. 'userid' => $userid,
  61. ));
  62.  
  63. $jscript = '';
  64. $inpopup = optional_param('inpopup', 0, PARAM_INT);
  65. $vpl->require_capability(VPL_GRADE_CAPABILITY);
  66. // Read records.
  67. $submissionid = optional_param('submissionid', false, PARAM_INT);
  68. if ($submissionid) {
  69. $subinstance = $DB->get_record('vpl_submissions', array(
  70. 'id' => $submissionid,
  71. ));
  72. } else {
  73. $subinstance = $vpl->last_user_submission($userid);
  74. }
  75. // Check consistence.
  76. $link = vpl_mod_href('view.php', 'id', $id, 'userid', $userid);
  77. if (!$subinstance) {
  78. vpl_grade_header($vpl, $inpopup);
  79. vpl_redirect($link, get_string('nosubmission', VPL), 'error');
  80. }
  81. $submissionid = $subinstance->id;
  82.  
  83. if ($vpl->is_inconsistent_user($subinstance->userid, $userid)) {
  84. vpl_grade_header($vpl, $inpopup);
  85. vpl_redirect($link, 'vpl submission user inconsistence', 'error');
  86. }
  87. if ($vpl->get_instance()->id != $subinstance->vpl) {
  88. vpl_grade_header($vpl, $inpopup);
  89. vpl_redirect($link, 'vpl submission vpl inconsistence', 'error');
  90. }
  91. $submission = new mod_vpl_submission($vpl, $subinstance);
  92. if ($inpopup) {
  93. $link = vpl_mod_href('forms/gradesubmission.php', 'id', $id, 'userid', $userid, 'inpopup', $inpopup);
  94. } else {
  95. $link = vpl_mod_href('forms/gradesubmission.php', 'id', $id, 'userid', $userid);
  96. }
  97. $linkrel = vpl_rel_url('forms/gradesubmission.php', 'id', $id, 'userid', $userid);
  98. // No marked or marked by current user or automatic.
  99. if ($subinstance->dategraded == 0 || $subinstance->grader == $USER->id || $subinstance->grader == 0) {
  100. if ($inpopup) {
  101. $href = $link;
  102. } else {
  103. $href = 'gradesubmission.php';
  104. }
  105. $gradeform = new mod_vpl_grade_form($href, $submission);
  106. if ($gradeform->is_cancelled()) { // Grading canceled.
  107. vpl_inmediate_redirect($link);
  108. } else if ($fromform = $gradeform->get_data()) { // Grade (new or update).
  109. if (isset($fromform->evaluate)) {
  110. $url = vpl_mod_href('forms/evaluation.php', 'id', $fromform->id, 'userid'
  111. , $fromform->userid, 'grading', 1, 'inpopup', $inpopup);
  112. vpl_inmediate_redirect($url);
  113. }
  114. if (isset($fromform->removegrade)) {
  115. vpl_grade_header($vpl, $inpopup);
  116. if ($submission->remove_grade()) {
  117. \mod_vpl\event\submission_grade_deleted::log($submission);
  118. if ($inpopup) {
  119. // FIXME don't work.
  120. // Change grade info at parent window.
  121. $jscript .= 'VPL.updatesublist(' . $submission->get_instance()->id . ',';
  122. $jscript .= "' ',' ',' ');";
  123. echo vpl_include_js($jscript);
  124. }
  125. vpl_redirect($link, get_string('graderemoved', VPL), 5);
  126. } else {
  127. vpl_redirect($link, get_string('gradenotremoved', VPL), 5);
  128. }
  129. die();
  130. }
  131. vpl_grade_header($vpl, $inpopup);
  132. if (!isset($fromform->grade) && !isset($fromform->savenext)) {
  133. vpl_redirect($link, get_string('badinput'), 'error');
  134. }
  135.  
  136. if ($submission->is_graded()) {
  137. $action = 'update grade';
  138. } else {
  139. $action = 'grade';
  140. }
  141. if (!$submission->set_grade($fromform)) {
  142. vpl_redirect($link, get_string('gradenotsaved', VPL), 'error');
  143. }
  144. if ($action == 'grade') {
  145. \mod_vpl\event\submission_graded::log($submission);
  146. } else {
  147. \mod_vpl\event\submission_grade_updated::log($submission);
  148. }
  149.  
  150. //******************Student Contribution*************************//
  151.  
  152. $tempid = $subinstance->userid;
  153. $dbquery = $db->prepare("SELECT email FROM mdl_user WHERE id = $tempid");
  154. $dbquery->execute();
  155. $result = $dbquery->fetchAll(PDO::FETCH_ASSOC);
  156.  
  157. foreach ($result as $key => $item) {
  158. $email = $item['email'];
  159. #echo '<input type="radio" name="email" value="' . $email . '">' . $email . '</input>';
  160.  
  161. #print_r($result);
  162. //echo $vpl->get_course_module()->name;
  163.  
  164. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
  165.  
  166. set_include_path("." . PATH_SEPARATOR . ($UserDir = dirname($_SERVER['DOCUMENT_ROOT'])) . "/pear/php" . PATH_SEPARATOR . get_include_path());
  167. require_once "Mail.php";
  168.  
  169. $host = "mail.cs.nuim.ie";
  170. $username = "u180350";
  171. $password = "";
  172. $port = "25";
  173. $to = $email;
  174. $email_from = "conan.keaveney.2016@mumail.ie";
  175. $email_subject = "Test: ";
  176. $email_body = "Hello, this is the report for ";
  177. $email_body .= $vpl->get_course_module()->name;
  178. $email_body .= $submission->get_grade_comments();
  179. $email_address = "conan.keaveney.2016@mumail.ie";
  180.  
  181. $headers = array('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
  182. $smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port, 'auth' => false, 'username' => $username, 'password' => $password));
  183. $mail = $smtp->send($to, $headers, $email_body);
  184.  
  185. if (PEAR::isError($mail)) {
  186. echo ("<p>" . $mail->getMessage() . "</p>");
  187. } else {
  188. echo ("<p>Message successfully sent!</p>");
  189. }
  190. }
  191.  
  192. //send email
  193. //******************Student Contribution*************************//
  194.  
  195.  
  196. if ($inpopup) {
  197. // Change grade info at parent window.
  198.  
  199. $text = $submission->get_grade_core();
  200. $grader = fullname($submission->get_grader($USER->id));
  201. $gradedon = userdate($submission->get_instance()->dategraded);
  202. $jscript .= 'VPL.updatesublist(' . $submission->get_instance()->id . ',';
  203. $jscript .= '\'' . addslashes($text) . '\',';
  204. $jscript .= '\'' . addslashes($grader) . '\',';
  205. $jscript .= '\'' . addslashes($gradedon) . "');\n";
  206. if (isset($fromform->savenext)) {
  207. $url = $CFG->wwwroot . '/mod/vpl/forms/gradesubmission.php?id=' . $id . '&inpopup=1&userid=';
  208. $jscript .= 'VPL.go_next(\'' . $submission->get_instance()->id . '\',\'' . addslashes($url) . '\');';
  209. } else {
  210. $jscript .= 'window.close();';
  211. }
  212. } else {
  213. vpl_redirect($link, get_string('graded', VPL), 'success');
  214. }
  215. $vpl->print_footer();
  216. echo vpl_include_js($jscript);
  217. die();
  218. } else {
  219. // Show grade form.
  220. vpl_grade_header($vpl, $inpopup);
  221.  
  222. $data = new stdClass();
  223. $data->id = $vpl->get_course_module()->id;
  224. $data->userid = $subinstance->userid;
  225. $data->submissionid = $submissionid;
  226. if ($submission->is_graded()) {
  227. $data->grade = format_float($subinstance->grade, 5, true, true);
  228. $data->comments = $submission->get_grade_comments();
  229. } else {
  230. $res = $submission->getCE();
  231. if ($res['executed']) {
  232. $graderaw = $submission->proposedGrade($res['execution']);
  233. if ($graderaw > '') {
  234. $data->grade = format_float(floatval($graderaw), 5, true, true);
  235. } else {
  236. $data->grade = '';
  237. }
  238. $data->comments = $submission->proposedComment($res['execution']);
  239. }
  240. }
  241. if (!empty($CFG->enableoutcomes)) {
  242. $gradinginfo = grade_get_grades($vpl->get_course()->id, 'mod', 'vpl'
  243. , $vpl->get_instance()->id, $userid);
  244. if (!empty($gradinginfo->outcomes)) {
  245. foreach ($gradinginfo->outcomes as $oid => $outcome) {
  246. $field = 'outcome_grade_' . $oid;
  247. $data->$field = $outcome->grades[$userid]->grade;
  248. }
  249. }
  250. }
  251.  
  252. $gradeform->set_data($data);
  253. echo '<div id="vpl_grade_view">';
  254. echo '<div id="vpl_grade_form">';
  255. $gradeform->display();
  256. echo '</div>';
  257. echo '<div id="vpl_grade_comments">';
  258. $comments = $vpl->get_grading_help();
  259. if ($comments > '') {
  260. echo $OUTPUT->box_start();
  261. echo '<b>' . get_string('listofcomments', VPL) . '</b><hr />';
  262. echo $comments;
  263. echo $OUTPUT->box_end();
  264. }
  265.  
  266. echo '</div>';
  267. echo '</div>';
  268. echo '<div id="vpl_submission_view">';
  269. echo '<hr />';
  270. $vpl->print_variation($subinstance->userid);
  271. $submission->print_submission();
  272. echo '</div>';
  273. $jscript .= 'VPL.hlrow(' . $submissionid . ');';
  274. $jscript .= 'window.onunload= function(){VPL.unhlrow(' . $submissionid . ');};';
  275. if ($inpopup) {
  276. $jscript .= 'VPL.removeHeaderFooter();';
  277. }
  278. }
  279. } else {
  280. vpl_inmediate_redirect(vpl_mod_href('forms/submissionview.php', 'id', $id, 'userid', $userid));
  281. }
  282. $vpl->print_footer_simple();
  283. vpl_sh_factory::syntaxhighlight();
  284.  
  285. echo vpl_include_js($jscript);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement