Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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      throw new \moodle_exception('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      throw new \moodle_exception('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  $actionbar = new \mod_feedback\output\responses_action_bar($cm->id, $url);
  74  
  75  if (($formdata = data_submitted()) AND !confirm_sesskey()) {
  76      throw new \moodle_exception('invalidsesskey');
  77  }
  78  
  79  require_capability('mod/feedback:viewreports', $context);
  80  
  81  $canbulkmessaging = has_capability('moodle/course:bulkmessaging', $coursecontext);
  82  if ($action == 'sendmessage' AND $canbulkmessaging) {
  83      $shortname = format_string($course->shortname,
  84                              true,
  85                              array('context' => $coursecontext));
  86      $strfeedbacks = get_string("modulenameplural", "feedback");
  87  
  88      $htmlmessage = "<body id=\"email\">";
  89  
  90      $link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
  91      $link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
  92      $link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
  93  
  94      $htmlmessage .= '<div class="navbar">'.
  95      '<a target="_blank" href="'.$link1.'">'.$shortname.'</a> &raquo; '.
  96      '<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> &raquo; '.
  97      '<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
  98      '</div>';
  99  
 100      $htmlmessage .= $message;
 101      $htmlmessage .= '</body>';
 102  
 103      $good = 1;
 104      if (is_array($messageuser)) {
 105          foreach ($messageuser as $userid) {
 106              $senduser = $DB->get_record('user', array('id'=>$userid));
 107              $eventdata = new \core\message\message();
 108              $eventdata->courseid         = $course->id;
 109              $eventdata->name             = 'message';
 110              $eventdata->component        = 'mod_feedback';
 111              $eventdata->userfrom         = $USER;
 112              $eventdata->userto           = $senduser;
 113              $eventdata->subject          = $subject;
 114              $eventdata->fullmessage      = html_to_text($htmlmessage);
 115              $eventdata->fullmessageformat = FORMAT_PLAIN;
 116              $eventdata->fullmessagehtml  = $htmlmessage;
 117              $eventdata->smallmessage     = '';
 118              $eventdata->courseid         = $course->id;
 119              $eventdata->contexturl       = $link3;
 120              $eventdata->contexturlname   = $feedback->name;
 121              $good = $good && message_send($eventdata);
 122          }
 123          if (!empty($good)) {
 124              $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
 125          } else {
 126              $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
 127          }
 128          redirect($url, $msg, 4);
 129          exit;
 130      }
 131  }
 132  
 133  ////////////////////////////////////////////////////////
 134  //get the responses of given user
 135  ////////////////////////////////////////////////////////
 136  
 137  /// Print the page header
 138  $PAGE->set_heading($course->fullname);
 139  $PAGE->set_title($feedback->name);
 140  $PAGE->set_secondary_active_tab('responses');
 141  if ($responsesnode = $PAGE->settingsnav->find('responses', navigation_node::TYPE_CUSTOM)) {
 142      $responsesnode->make_active();
 143  }
 144  $PAGE->activityheader->set_attrs([
 145      'hidecompletion' => true,
 146      'description' => ''
 147  ]);
 148  echo $OUTPUT->header();
 149  
 150  /** @var \mod_feedback\output\renderer $renderer */
 151  $renderer = $PAGE->get_renderer('mod_feedback');
 152  echo $renderer->main_action_bar($actionbar);
 153  
 154  /// Print the main part of the page
 155  ///////////////////////////////////////////////////////////////////////////
 156  ///////////////////////////////////////////////////////////////////////////
 157  ///////////////////////////////////////////////////////////////////////////
 158  
 159  ////////////////////////////////////////////////////////
 160  /// Print the users with no responses
 161  ////////////////////////////////////////////////////////
 162  //get the effective groupmode of this course and module
 163  if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
 164      $groupmode =  $cm->groupmode;
 165  } else {
 166      $groupmode = $course->groupmode;
 167  }
 168  
 169  $groupselect = groups_print_activity_menu($cm, $url->out(), true);
 170  $mygroupid = groups_get_activity_group($cm);
 171  
 172  // preparing the table for output
 173  $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
 174  $baseurl->params(array('id'=>$id, 'showall'=>$showall));
 175  
 176  $tablecolumns = array('userpic', 'fullname', 'status');
 177  $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
 178  
 179  if ($canbulkmessaging) {
 180      $tablecolumns[] = 'select';
 181  
 182      // Build the select/deselect all control.
 183      $selectallid = 'selectall-non-respondents';
 184      $mastercheckbox = new \core\output\checkbox_toggleall('feedback-non-respondents', true, [
 185          'id' => $selectallid,
 186          'name' => $selectallid,
 187          'value' => 1,
 188          'label' => get_string('select'),
 189          // Consistent label to prevent the select column from resizing.
 190          'selectall' => get_string('select'),
 191          'deselectall' => get_string('select'),
 192          'labelclasses' => 'm-0',
 193      ]);
 194      $tableheaders[] = $OUTPUT->render($mastercheckbox);
 195  }
 196  
 197  $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
 198  
 199  $table->define_columns($tablecolumns);
 200  $table->define_headers($tableheaders);
 201  $table->define_baseurl($baseurl);
 202  
 203  $table->sortable(true, 'lastname', SORT_DESC);
 204  $table->set_attribute('cellspacing', '0');
 205  $table->set_attribute('id', 'showentrytable');
 206  $table->set_attribute('class', 'generaltable generalbox');
 207  $table->set_control_variables(array(
 208              TABLE_VAR_SORT    => 'ssort',
 209              TABLE_VAR_IFIRST  => 'sifirst',
 210              TABLE_VAR_ILAST   => 'silast',
 211              TABLE_VAR_PAGE    => 'spage'
 212              ));
 213  
 214  $table->no_sorting('select');
 215  $table->no_sorting('status');
 216  
 217  $table->setup();
 218  
 219  if ($table->get_sql_sort()) {
 220      $sort = $table->get_sql_sort();
 221  } else {
 222      $sort = '';
 223  }
 224  
 225  //get students in conjunction with groupmode
 226  if ($groupmode > 0) {
 227      if ($mygroupid > 0) {
 228          $usedgroupid = $mygroupid;
 229      } else {
 230          $usedgroupid = false;
 231      }
 232  } else {
 233      $usedgroupid = false;
 234  }
 235  
 236  $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
 237  $table->initialbars(false);
 238  
 239  if ($showall) {
 240      $startpage = false;
 241      $pagecount = false;
 242  } else {
 243      $table->pagesize($perpage, $matchcount);
 244      $startpage = $table->get_page_start();
 245      $pagecount = $table->get_page_size();
 246  }
 247  
 248  // Return students record including if they started or not the feedback.
 249  $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount, true);
 250  //####### viewreports-start
 251  //print the list of students
 252  echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
 253  echo isset($groupselect) ? $groupselect : '';
 254  echo '<div class="clearer"></div>';
 255  
 256  if (empty($students)) {
 257      echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
 258  } else {
 259  
 260      if ($canbulkmessaging) {
 261          echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
 262      }
 263  
 264      foreach ($students as $student) {
 265          //userpicture and link to the profilepage
 266          $profileurl = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
 267          $profilelink = '<strong><a href="'.$profileurl.'">'.fullname($student).'</a></strong>';
 268          $data = array($OUTPUT->user_picture($student, array('courseid' => $course->id)), $profilelink);
 269  
 270          if ($student->feedbackstarted) {
 271              $data[] = get_string('started', 'feedback');
 272          } else {
 273              $data[] = get_string('not_started', 'feedback');
 274          }
 275  
 276          //selections to bulk messaging
 277          if ($canbulkmessaging) {
 278              $checkbox = new \core\output\checkbox_toggleall('feedback-non-respondents', false, [
 279                  'id' => 'messageuser-' . $student->id,
 280                  'name' => 'messageuser[]',
 281                  'classes' => 'mr-1',
 282                  'value' => $student->id,
 283                  'label' => get_string('includeuserinrecipientslist', 'mod_feedback', fullname($student)),
 284                  'labelclasses' => 'accesshide',
 285              ]);
 286              $data[] = $OUTPUT->render($checkbox);
 287          }
 288          $table->add_data($data);
 289      }
 290      $table->print_html();
 291  
 292      $allurl = new moodle_url($baseurl);
 293  
 294      if ($showall) {
 295          $allurl->param('showall', 0);
 296          echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
 297                                      array(), 'showall');
 298  
 299      } else if ($matchcount > 0 && $perpage < $matchcount) {
 300          $allurl->param('showall', 1);
 301          echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
 302      }
 303      if ($canbulkmessaging) {
 304          echo '<fieldset class="clearfix">';
 305          echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
 306          echo '<div>';
 307          echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
 308          echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.s($subject).'" />';
 309          echo '</div>';
 310          echo $OUTPUT->print_textarea('message', 'edit-message', $message, 15, 25);
 311          print_string('formathtml');
 312          echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
 313          echo '<br /><div class="buttons">';
 314          echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" class="btn btn-secondary" />';
 315          echo '</div>';
 316          echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
 317          echo '<input type="hidden" name="action" value="sendmessage" />';
 318          echo '<input type="hidden" name="id" value="'.$id.'" />';
 319          echo '</fieldset>';
 320          echo '</form>';
 321      }
 322  }
 323  
 324  /// Finish the page
 325  ///////////////////////////////////////////////////////////////////////////
 326  ///////////////////////////////////////////////////////////////////////////
 327  ///////////////////////////////////////////////////////////////////////////
 328  
 329  echo $OUTPUT->footer();
 330