Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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  /**
  18   * print the single entries
  19   *
  20   * @author Andreas Grabs
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package mod_feedback
  23   */
  24  
  25  require_once("../../config.php");
  26  require_once ("lib.php");
  27  require_once($CFG->libdir.'/tablelib.php');
  28  
  29  ////////////////////////////////////////////////////////
  30  //get the params
  31  ////////////////////////////////////////////////////////
  32  $id = required_param('id', PARAM_INT);
  33  $subject = optional_param('subject', '', PARAM_CLEANHTML);
  34  $message = optional_param_array('message', '', PARAM_CLEANHTML);
  35  $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
  36  $messageuser = optional_param_array('messageuser', false, PARAM_INT);
  37  $action = optional_param('action', '', PARAM_ALPHA);
  38  $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
  39  $showall = optional_param('showall', false, PARAM_INT);  // should we show all users
  40  // $SESSION->feedback->current_tab = $do_show;
  41  $current_tab = 'nonrespondents';
  42  
  43  ////////////////////////////////////////////////////////
  44  //get the objects
  45  ////////////////////////////////////////////////////////
  46  
  47  if ($message) {
  48      $message = $message['text'];
  49  }
  50  
  51  list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  52  if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
  53      print_error('invalidcoursemodule');
  54  }
  55  
  56  //this page only can be shown on nonanonymous feedbacks in courses
  57  //we should never reach this page
  58  if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
  59      print_error('error');
  60  }
  61  
  62  $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
  63  
  64  $PAGE->set_url($url);
  65  
  66  $context = context_module::instance($cm->id);
  67  
  68  //we need the coursecontext to allow sending of mass mails
  69  $coursecontext = context_course::instance($course->id);
  70  
  71  require_login($course, true, $cm);
  72  
  73  if (($formdata = data_submitted()) AND !confirm_sesskey()) {
  74      print_error('invalidsesskey');
  75  }
  76  
  77  require_capability('mod/feedback:viewreports', $context);
  78  
  79  $canbulkmessaging = has_capability('moodle/course:bulkmessaging', $coursecontext);
  80  if ($action == 'sendmessage' AND $canbulkmessaging) {
  81      $shortname = format_string($course->shortname,
  82                              true,
  83                              array('context' => $coursecontext));
  84      $strfeedbacks = get_string("modulenameplural", "feedback");
  85  
  86      $htmlmessage = "<body id=\"email\">";
  87  
  88      $link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
  89      $link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
  90      $link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
  91  
  92      $htmlmessage .= '<div class="navbar">'.
  93      '<a target="_blank" href="'.$link1.'">'.$shortname.'</a> &raquo; '.
  94      '<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> &raquo; '.
  95      '<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
  96      '</div>';
  97  
  98      $htmlmessage .= $message;
  99      $htmlmessage .= '</body>';
 100  
 101      $good = 1;
 102      if (is_array($messageuser)) {
 103          foreach ($messageuser as $userid) {
 104              $senduser = $DB->get_record('user', array('id'=>$userid));
 105              $eventdata = new \core\message\message();
 106              $eventdata->courseid         = $course->id;
 107              $eventdata->name             = 'message';
 108              $eventdata->component        = 'mod_feedback';
 109              $eventdata->userfrom         = $USER;
 110              $eventdata->userto           = $senduser;
 111              $eventdata->subject          = $subject;
 112              $eventdata->fullmessage      = html_to_text($htmlmessage);
 113              $eventdata->fullmessageformat = FORMAT_PLAIN;
 114              $eventdata->fullmessagehtml  = $htmlmessage;
 115              $eventdata->smallmessage     = '';
 116              $eventdata->courseid         = $course->id;
 117              $eventdata->contexturl       = $link3;
 118              $eventdata->contexturlname   = $feedback->name;
 119              $good = $good && message_send($eventdata);
 120          }
 121          if (!empty($good)) {
 122              $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
 123          } else {
 124              $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
 125          }
 126          redirect($url, $msg, 4);
 127          exit;
 128      }
 129  }
 130  
 131  ////////////////////////////////////////////////////////
 132  //get the responses of given user
 133  ////////////////////////////////////////////////////////
 134  
 135  /// Print the page header
 136  $PAGE->set_heading($course->fullname);
 137  $PAGE->set_title($feedback->name);
 138  echo $OUTPUT->header();
 139  echo $OUTPUT->heading(format_string($feedback->name));
 140  
 141  require ('tabs.php');
 142  
 143  /// Print the main part of the page
 144  ///////////////////////////////////////////////////////////////////////////
 145  ///////////////////////////////////////////////////////////////////////////
 146  ///////////////////////////////////////////////////////////////////////////
 147  
 148  ////////////////////////////////////////////////////////
 149  /// Print the users with no responses
 150  ////////////////////////////////////////////////////////
 151  //get the effective groupmode of this course and module
 152  if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
 153      $groupmode =  $cm->groupmode;
 154  } else {
 155      $groupmode = $course->groupmode;
 156  }
 157  
 158  $groupselect = groups_print_activity_menu($cm, $url->out(), true);
 159  $mygroupid = groups_get_activity_group($cm);
 160  
 161  // preparing the table for output
 162  $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
 163  $baseurl->params(array('id'=>$id, 'showall'=>$showall));
 164  
 165  $tablecolumns = array('userpic', 'fullname', 'status');
 166  $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
 167  
 168  if ($canbulkmessaging) {
 169      $tablecolumns[] = 'select';
 170  
 171      // Build the select/deselect all control.
 172      $selectallid = 'selectall-non-respondents';
 173      $mastercheckbox = new \core\output\checkbox_toggleall('feedback-non-respondents', true, [
 174          'id' => $selectallid,
 175          'name' => $selectallid,
 176          'value' => 1,
 177          'label' => get_string('select'),
 178          // Consistent label to prevent the select column from resizing.
 179          'selectall' => get_string('select'),
 180          'deselectall' => get_string('select'),
 181          'labelclasses' => 'm-0',
 182      ]);
 183      $tableheaders[] = $OUTPUT->render($mastercheckbox);
 184  }
 185  
 186  $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
 187  
 188  $table->define_columns($tablecolumns);
 189  $table->define_headers($tableheaders);
 190  $table->define_baseurl($baseurl);
 191  
 192  $table->sortable(true, 'lastname', SORT_DESC);
 193  $table->set_attribute('cellspacing', '0');
 194  $table->set_attribute('id', 'showentrytable');
 195  $table->set_attribute('class', 'generaltable generalbox');
 196  $table->set_control_variables(array(
 197              TABLE_VAR_SORT    => 'ssort',
 198              TABLE_VAR_IFIRST  => 'sifirst',
 199              TABLE_VAR_ILAST   => 'silast',
 200              TABLE_VAR_PAGE    => 'spage'
 201              ));
 202  
 203  $table->no_sorting('select');
 204  $table->no_sorting('status');
 205  
 206  $table->setup();
 207  
 208  if ($table->get_sql_sort()) {
 209      $sort = $table->get_sql_sort();
 210  } else {
 211      $sort = '';
 212  }
 213  
 214  //get students in conjunction with groupmode
 215  if ($groupmode > 0) {
 216      if ($mygroupid > 0) {
 217          $usedgroupid = $mygroupid;
 218      } else {
 219          $usedgroupid = false;
 220      }
 221  } else {
 222      $usedgroupid = false;
 223  }
 224  
 225  $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
 226  $table->initialbars(false);
 227  
 228  if ($showall) {
 229      $startpage = false;
 230      $pagecount = false;
 231  } else {
 232      $table->pagesize($perpage, $matchcount);
 233      $startpage = $table->get_page_start();
 234      $pagecount = $table->get_page_size();
 235  }
 236  
 237  // Return students record including if they started or not the feedback.
 238  $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount, true);
 239  //####### viewreports-start
 240  //print the list of students
 241  echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
 242  echo isset($groupselect) ? $groupselect : '';
 243  echo '<div class="clearer"></div>';
 244  
 245  if (empty($students)) {
 246      echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
 247  } else {
 248  
 249      if ($canbulkmessaging) {
 250          echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
 251      }
 252  
 253      foreach ($students as $student) {
 254          //userpicture and link to the profilepage
 255          $profileurl = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
 256          $profilelink = '<strong><a href="'.$profileurl.'">'.fullname($student).'</a></strong>';
 257          $data = array($OUTPUT->user_picture($student, array('courseid' => $course->id)), $profilelink);
 258  
 259          if ($student->feedbackstarted) {
 260              $data[] = get_string('started', 'feedback');
 261          } else {
 262              $data[] = get_string('not_started', 'feedback');
 263          }
 264  
 265          //selections to bulk messaging
 266          if ($canbulkmessaging) {
 267              $checkbox = new \core\output\checkbox_toggleall('feedback-non-respondents', false, [
 268                  'id' => 'messageuser-' . $student->id,
 269                  'name' => 'messageuser[]',
 270                  'classes' => 'mr-1',
 271                  'value' => $student->id,
 272                  'label' => get_string('includeuserinrecipientslist', 'mod_feedback', fullname($student)),
 273                  'labelclasses' => 'accesshide',
 274              ]);
 275              $data[] = $OUTPUT->render($checkbox);
 276          }
 277          $table->add_data($data);
 278      }
 279      $table->print_html();
 280  
 281      $allurl = new moodle_url($baseurl);
 282  
 283      if ($showall) {
 284          $allurl->param('showall', 0);
 285          echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
 286                                      array(), 'showall');
 287  
 288      } else if ($matchcount > 0 && $perpage < $matchcount) {
 289          $allurl->param('showall', 1);
 290          echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
 291      }
 292      if ($canbulkmessaging) {
 293          echo '<fieldset class="clearfix">';
 294          echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
 295          echo '<div>';
 296          echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
 297          echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.s($subject).'" />';
 298          echo '</div>';
 299          echo $OUTPUT->print_textarea('message', 'edit-message', $message, 15, 25);
 300          print_string('formathtml');
 301          echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
 302          echo '<br /><div class="buttons">';
 303          echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" class="btn btn-secondary" />';
 304          echo '</div>';
 305          echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
 306          echo '<input type="hidden" name="action" value="sendmessage" />';
 307          echo '<input type="hidden" name="id" value="'.$id.'" />';
 308          echo '</fieldset>';
 309          echo '</form>';
 310      }
 311  }
 312  
 313  /// Finish the page
 314  ///////////////////////////////////////////////////////////////////////////
 315  ///////////////////////////////////////////////////////////////////////////
 316  ///////////////////////////////////////////////////////////////////////////
 317  
 318  echo $OUTPUT->footer();
 319