Moodle plugin, allowing collaborative annotations in PDF files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

392 lines
18 KiB

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // 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. // 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package mod_pdfannotator
  18. * @copyright 2018 RWTH Aachen, Anna Heynkes (see README.md)
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20. */
  21. defined('MOODLE_INTERNAL') || die();
  22. $action = optional_param('action', 'view', PARAM_ALPHA); // The default action is 'view'.
  23. $taburl = new moodle_url('/mod/pdfannotator/view.php', array('id' => $id));
  24. $myrenderer = $PAGE->get_renderer('mod_pdfannotator');
  25. /* *********************************************** Display overview page *********************************************** */
  26. if ($action === 'overview') {
  27. $action = 'overviewquestions';
  28. }
  29. /*
  30. * This section prints a subpage of overview called 'unsolved questions'.
  31. */
  32. if ($action === 'overviewquestions') {
  33. global $OUTPUT;
  34. require_once($CFG->libdir . '/tablelib.php');
  35. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  36. global $CFG;
  37. $currentpage = optional_param('page', 0, PARAM_INT);
  38. $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
  39. $thisannotator = $pdfannotator->id;
  40. $thiscourse = $pdfannotator->course;
  41. $cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
  42. pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
  43. echo $OUTPUT->heading(get_string('questionstab', 'pdfannotator').' '.
  44. $OUTPUT->help_icon('questionstabicon', 'mod_pdfannotator'));
  45. $questions = pdfannotator_get_unsolved_questions($thiscourse);
  46. if (empty($questions)) {
  47. $info = get_string('noquestions_overview', 'pdfannotator');
  48. echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
  49. } else {
  50. $urlparams = array('action' => 'overviewquestions', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
  51. pdfannotator_print_questions($questions, $thiscourse, $urlparams, $currentpage, $itemsperpage);
  52. }
  53. }
  54. /*
  55. * This section prints a subpage of overview called 'answers'. It lists all answers to questions the current
  56. * user asked or subscribed to.
  57. */
  58. if ($action === 'overviewanswers') {
  59. require_once($CFG->libdir . '/tablelib.php');
  60. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  61. global $CFG, $OUTPUT;
  62. $currentpage = optional_param('page', 0, PARAM_INT);
  63. $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
  64. $thisannotator = $pdfannotator->id;
  65. $thiscourse = $pdfannotator->course;
  66. $cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
  67. pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
  68. echo $OUTPUT->heading(get_string('answerstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('answerstabicon', 'pdfannotator'));
  69. $data = pdfannotator_get_answers_for_this_user($thiscourse);
  70. if (empty($data)) {
  71. $info = get_string('noanswers', 'pdfannotator');
  72. echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
  73. } else {
  74. $urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
  75. $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
  76. pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $itemsperpage);
  77. }
  78. }
  79. /*
  80. * This section prints a subpage of overview called "My posts".
  81. */
  82. if ($action === 'overviewownposts') {
  83. require_once($CFG->libdir . '/tablelib.php');
  84. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  85. global $CFG, $OUTPUT;
  86. $currentpage = optional_param('page', 0, PARAM_INT);
  87. $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
  88. $thisannotator = $pdfannotator->id;
  89. $thiscourse = $pdfannotator->course;
  90. $cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
  91. pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
  92. echo $OUTPUT->heading(get_string('ownpoststab', 'pdfannotator').' '.$OUTPUT->help_icon('ownpoststabicon', 'mod_pdfannotator'));
  93. $posts = pdfannotator_get_posts_by_this_user($thiscourse);
  94. if (empty($posts)) {
  95. $info = get_string('nomyposts', 'pdfannotator');
  96. echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
  97. } else {
  98. $urlparams = array('action' => 'overviewownposts', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
  99. $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
  100. pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $currentpage, $itemsperpage);
  101. }
  102. }
  103. /*
  104. * This section prints a subpage of overview called "Reports" were comments that were reported as inappropriate are listed.
  105. */
  106. if ($action === 'overviewreports') {
  107. require_once($CFG->libdir . '/tablelib.php');
  108. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  109. global $CFG, $OUTPUT;
  110. $currentpage = optional_param('page', 0, PARAM_INT);
  111. $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
  112. $thisannotator = $pdfannotator->id;
  113. $thiscourse = $pdfannotator->course;
  114. $cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
  115. pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
  116. echo $OUTPUT->heading(get_string('reportstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('reportstabicon', 'mod_pdfannotator'));
  117. $reports = pdfannotator_get_reports($thiscourse);
  118. if (empty($reports)) {
  119. $info = get_string('noreports', 'pdfannotator');
  120. echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
  121. } else {
  122. $urlparams = array('action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
  123. $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
  124. pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage);
  125. }
  126. }
  127. /* This section prints a subpage of overview called "Read" were comments that were reported as inappropriate are listed
  128. * after they were marked as seen/read/ackknowledged.
  129. */
  130. if ($action === 'overviewrecyclebin') {
  131. require_once($CFG->libdir . '/tablelib.php');
  132. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  133. global $CFG, $USER, $OUTPUT;
  134. $currentpage = optional_param('page', 0, PARAM_INT);
  135. $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
  136. $currentview = optional_param('currentview', 0, PARAM_INT); // Answers or reports.
  137. $thisannotator = $pdfannotator->id;
  138. $thiscourse = $pdfannotator->course;
  139. $cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
  140. pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
  141. echo $OUTPUT->heading(get_string('recyclebintab', 'pdfannotator').' '.$OUTPUT->help_icon('recyclebintabicon', 'pdfannotator'));
  142. if (has_capability('mod/pdfannotator:viewreports', $context)) {
  143. $reports = pdfannotator_get_reports($thiscourse, 1);
  144. if (empty($reports)) {
  145. $info = get_string('nohiddenreports', 'pdfannotator');
  146. echo "<div><span class='notification'><div class='alert alert-info".
  147. "alert-block fade in' role='alert'>$info</div></span></div>";
  148. } else {
  149. $urlparams = array('action' => 'overviewrecyclebin', 'id' => $cmid, 'page' => $currentpage,
  150. 'currentview' => $currentview, 'itemsperpage' => $itemsperpage);
  151. $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
  152. pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage, true);
  153. }
  154. }
  155. }
  156. /* *********************************** Display the pdf in its editor (default action) *************************************** */
  157. if ($action === 'view') { // Default.
  158. $PAGE->set_title("annotatorview");
  159. echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
  160. pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page, $annoid, $commid);
  161. }
  162. /* *********************************************** Display statistics *********************************************** */
  163. if ($action === 'statistic') {
  164. require_capability('mod/pdfannotator:viewstatistics', $context);
  165. require_once($CFG->dirroot . '/mod/pdfannotator/model/statistics.class.php');
  166. require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/statistics.php');
  167. echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
  168. $PAGE->set_title("statisticview");
  169. echo $OUTPUT->heading(get_string('activities', 'pdfannotator'));
  170. // Give javascript access to the language string repository.
  171. $stringman = get_string_manager();
  172. $strings = $stringman->load_component_strings('pdfannotator', 'en'); // Method gets the strings of the language files.
  173. $PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
  174. $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));
  175. $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/statistic.js"));
  176. $myrenderer = $PAGE->get_renderer('mod_pdfannotator');
  177. $capabilities = new stdClass();
  178. $capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
  179. $capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
  180. $capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
  181. $capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
  182. $capabilities->viewteacherstatistics = has_capability('mod/pdfannotator:viewteacherstatistics', $context);
  183. // Param 'statistics' is a renderable/templatable.
  184. echo $myrenderer->render_statistic(new statistics($cm->instance, $course->id, $capabilities, $id));
  185. }
  186. /* ****************************************** Display form for reporting a comment ******************************************** */
  187. if ($action === 'report') {
  188. require_once($CFG->dirroot . '/mod/pdfannotator/reportform.php');
  189. require_once($CFG->dirroot . '/mod/pdfannotator/model/comment.class.php');
  190. require_once($CFG->dirroot . '/mod/pdfannotator/model/report.class.php');
  191. // Get comment id.
  192. $commentid = optional_param('commentid', 0, PARAM_INT);
  193. // Contextual data to pass on to the report form.
  194. $data = new stdClass();
  195. $data->course = $cm->course;
  196. $data->pdfannotatorid = $cm->instance;
  197. $data->pdfname = $cm->name;
  198. $data->commentid = $commentid;
  199. $data->id = $id; // Course module id.
  200. $data->action = 'report';
  201. // Initialise mform and pass on $data-object to it.
  202. $mform = new pdfannotator_reportform();
  203. $mform->set_data($data);
  204. /* ******************** Form processing and displaying is done here ************************ */
  205. if ($mform->is_cancelled()) {
  206. $action = 'view';
  207. echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
  208. pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
  209. } else if ($report = $mform->get_data()) {
  210. // In this case you process validated data. $mform->get_data() returns data posted in form.
  211. global $DB, $USER;
  212. // 1. Notify course manager(s).
  213. $recipients = get_enrolled_users($context, 'mod/pdfannotator:administrateuserinput');
  214. $name = 'newreport';
  215. $report->reportinguser = fullname($USER);
  216. $report->urltoreport = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overview';
  217. $messagetext = new stdClass();
  218. $messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context,
  219. get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
  220. $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context,
  221. get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
  222. $messagetext->url = $report->url;
  223. try {
  224. foreach ($recipients as $recipient) {
  225. $messageid = pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagetext);
  226. }
  227. // 2. Notify the reporting user that their report has been sent off (display blue toast box at top of page).
  228. \core\notification::info(get_string('reportwassentoff', 'pdfannotator'));
  229. } catch (Exception $ex) {
  230. $info = $ex->getMessage();
  231. \core\notification::error($info);
  232. }
  233. // 3. Save report in db.
  234. $record = new stdClass();
  235. $record->commentid = $report->commentid;
  236. $record->courseid = $cm->course;
  237. $record->pdfannotatorid = $cm->instance;
  238. $record->message = $report->message;
  239. $record->userid = $USER->id;
  240. $record->timecreated = time();
  241. $record->seen = 0;
  242. $reportid = $DB->insert_record('pdfannotator_reports', $record, $returnid = true, $bulk = false);
  243. if (empty($reportid)) {
  244. \core\notification::error(get_string('error:reportComment', 'pdfannotator'));
  245. }
  246. $action = 'view';
  247. echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
  248. pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
  249. } else { // This branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
  250. // or on the first display of the form.
  251. $PAGE->set_title("reportform");
  252. echo $OUTPUT->heading(get_string('titleforreportcommentform', 'pdfannotator'));
  253. // Get information about the comment to be reported.
  254. $comment = new pdfannotator_comment($commentid);
  255. $info = pdfannotator_comment_info::make_from_comment($comment);
  256. // Display it in a table.
  257. $myrenderer = $PAGE->get_renderer('mod_pdfannotator');
  258. echo $myrenderer->render_pdfannotator_comment_info($info);
  259. // Now display the complaint form itself.
  260. $mform->display();
  261. }
  262. return;
  263. }
  264. /* *********************************************** Display feedback page *********************************************** */
  265. if ($action === 'feedback') {
  266. global $PAGE;
  267. require_once($CFG->dirroot . '/mod/pdfannotator/feedback_form.php');
  268. $PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));
  269. // Contextual data to pass on to the feedback form.
  270. $data = new stdClass();
  271. $data->id = $id;
  272. $data->course = $cm->course;
  273. $data->pdfid = $cm->instance;
  274. $data->pdfname = $cm->name;
  275. $data->action = 'feedback';
  276. $mform = new pdfannotator_feedback_form();
  277. $mform->set_data($data);
  278. if ($mform->is_cancelled()) {
  279. echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name);
  280. pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
  281. } else if ($formdata = $mform->get_data()) {
  282. global $USER;
  283. // 1. Send email to Ahmad, Rabea and Anna.
  284. $formdata = $mform->get_data();
  285. pdfannotator_send_feedbackmail($formdata);
  286. // 2. Thank user for their feedback (display 'blue box' at top of page).
  287. \core\notification::info(get_string('feedbackwassentoff', 'pdfannotator'));
  288. // 3. Display pdf once more.
  289. echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name, $context);
  290. pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
  291. } else {
  292. $PAGE->set_title("feedback");
  293. echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
  294. $capabilities = new stdClass();
  295. $capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
  296. $capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
  297. $capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
  298. $capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
  299. $stringman = get_string_manager();
  300. // With this method you get the strings of the language-Files.
  301. $strings = $stringman->load_component_strings('pdfannotator', 'en');
  302. // Method to use the language-strings in javascript.
  303. $PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator');
  304. $PAGE->requires->js_init_call('addDropdownNavigation', array($capabilities, $id), true);
  305. echo "<p>" . get_string('pleaforfeedback', 'pdfannotator') . "</p>";
  306. $mform->display();
  307. }
  308. }