[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/feedback/ -> show_nonrespondents.php (source)

   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('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  list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  48  if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
  49      print_error('invalidcoursemodule');
  50  }
  51  
  52  //this page only can be shown on nonanonymous feedbacks in courses
  53  //we should never reach this page
  54  if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
  55      print_error('error');
  56  }
  57  
  58  $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
  59  
  60  $PAGE->set_url($url);
  61  
  62  $context = context_module::instance($cm->id);
  63  
  64  //we need the coursecontext to allow sending of mass mails
  65  $coursecontext = context_course::instance($course->id);
  66  
  67  require_login($course, true, $cm);
  68  
  69  if (($formdata = data_submitted()) AND !confirm_sesskey()) {
  70      print_error('invalidsesskey');
  71  }
  72  
  73  require_capability('mod/feedback:viewreports', $context);
  74  
  75  if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
  76      $shortname = format_string($course->shortname,
  77                              true,
  78                              array('context' => $coursecontext));
  79      $strfeedbacks = get_string("modulenameplural", "feedback");
  80  
  81      $htmlmessage = "<body id=\"email\">";
  82  
  83      $link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
  84      $link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
  85      $link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
  86  
  87      $htmlmessage .= '<div class="navbar">'.
  88      '<a target="_blank" href="'.$link1.'">'.$shortname.'</a> &raquo; '.
  89      '<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> &raquo; '.
  90      '<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
  91      '</div>';
  92  
  93      $htmlmessage .= $message;
  94      $htmlmessage .= '</body>';
  95  
  96      $good = 1;
  97      if (is_array($messageuser)) {
  98          foreach ($messageuser as $userid) {
  99              $senduser = $DB->get_record('user', array('id'=>$userid));
 100              $eventdata = new stdClass();
 101              $eventdata->name             = 'message';
 102              $eventdata->component        = 'mod_feedback';
 103              $eventdata->userfrom         = $USER;
 104              $eventdata->userto           = $senduser;
 105              $eventdata->subject          = $subject;
 106              $eventdata->fullmessage      = html_to_text($htmlmessage);
 107              $eventdata->fullmessageformat = FORMAT_PLAIN;
 108              $eventdata->fullmessagehtml  = $htmlmessage;
 109              $eventdata->smallmessage     = '';
 110              $good = $good && message_send($eventdata);
 111          }
 112          if (!empty($good)) {
 113              $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
 114          } else {
 115              $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
 116          }
 117          redirect($url, $msg, 4);
 118          exit;
 119      }
 120  }
 121  
 122  ////////////////////////////////////////////////////////
 123  //get the responses of given user
 124  ////////////////////////////////////////////////////////
 125  
 126  /// Print the page header
 127  $PAGE->set_heading($course->fullname);
 128  $PAGE->set_title($feedback->name);
 129  echo $OUTPUT->header();
 130  echo $OUTPUT->heading(format_string($feedback->name));
 131  
 132  require ('tabs.php');
 133  
 134  /// Print the main part of the page
 135  ///////////////////////////////////////////////////////////////////////////
 136  ///////////////////////////////////////////////////////////////////////////
 137  ///////////////////////////////////////////////////////////////////////////
 138  
 139  ////////////////////////////////////////////////////////
 140  /// Print the users with no responses
 141  ////////////////////////////////////////////////////////
 142  //get the effective groupmode of this course and module
 143  if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
 144      $groupmode =  $cm->groupmode;
 145  } else {
 146      $groupmode = $course->groupmode;
 147  }
 148  
 149  $groupselect = groups_print_activity_menu($cm, $url->out(), true);
 150  $mygroupid = groups_get_activity_group($cm);
 151  
 152  // preparing the table for output
 153  $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
 154  $baseurl->params(array('id'=>$id, 'showall'=>$showall));
 155  
 156  $tablecolumns = array('userpic', 'fullname', 'status');
 157  $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
 158  
 159  if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
 160      $tablecolumns[] = 'select';
 161      $tableheaders[] = get_string('select');
 162  }
 163  
 164  $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
 165  
 166  $table->define_columns($tablecolumns);
 167  $table->define_headers($tableheaders);
 168  $table->define_baseurl($baseurl);
 169  
 170  $table->sortable(true, 'lastname', SORT_DESC);
 171  $table->set_attribute('cellspacing', '0');
 172  $table->set_attribute('id', 'showentrytable');
 173  $table->set_attribute('class', 'generaltable generalbox');
 174  $table->set_control_variables(array(
 175              TABLE_VAR_SORT    => 'ssort',
 176              TABLE_VAR_IFIRST  => 'sifirst',
 177              TABLE_VAR_ILAST   => 'silast',
 178              TABLE_VAR_PAGE    => 'spage'
 179              ));
 180  
 181  $table->no_sorting('select');
 182  $table->no_sorting('status');
 183  
 184  $table->setup();
 185  
 186  if ($table->get_sql_sort()) {
 187      $sort = $table->get_sql_sort();
 188  } else {
 189      $sort = '';
 190  }
 191  
 192  //get students in conjunction with groupmode
 193  if ($groupmode > 0) {
 194      if ($mygroupid > 0) {
 195          $usedgroupid = $mygroupid;
 196      } else {
 197          $usedgroupid = false;
 198      }
 199  } else {
 200      $usedgroupid = false;
 201  }
 202  
 203  $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
 204  $table->initialbars(false);
 205  
 206  if ($showall) {
 207      $startpage = false;
 208      $pagecount = false;
 209  } else {
 210      $table->pagesize($perpage, $matchcount);
 211      $startpage = $table->get_page_start();
 212      $pagecount = $table->get_page_size();
 213  }
 214  
 215  $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
 216  //####### viewreports-start
 217  //print the list of students
 218  echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
 219  echo isset($groupselect) ? $groupselect : '';
 220  echo '<div class="clearer"></div>';
 221  
 222  if (!$students) {
 223      echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
 224  } else {
 225  
 226      if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
 227          echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
 228      }
 229      foreach ($students as $student) {
 230          $user = $DB->get_record('user', array('id'=>$student));
 231          //userpicture and link to the profilepage
 232          $profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id;
 233          $profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
 234          $data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
 235  
 236          if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
 237              $data[] = get_string('started', 'feedback');
 238          } else {
 239              $data[] = get_string('not_started', 'feedback');
 240          }
 241  
 242          //selections to bulk messaging
 243          if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
 244              $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
 245          }
 246          $table->add_data($data);
 247      }
 248      $table->print_html();
 249  
 250      $allurl = new moodle_url($baseurl);
 251  
 252      if ($showall) {
 253          $allurl->param('showall', 0);
 254          echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
 255                                      array(), 'showall');
 256  
 257      } else if ($matchcount > 0 && $perpage < $matchcount) {
 258          $allurl->param('showall', 1);
 259          echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
 260      }
 261      if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
 262          echo '<div class="buttons"><br />';
 263          echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
 264          echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
 265          echo '</div>';
 266          echo '<fieldset class="clearfix">';
 267          echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
 268          echo '<div>';
 269          echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
 270          echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
 271          echo '</div>';
 272          print_textarea(true, 15, 25, 30, 10, "message", $message);
 273          print_string('formathtml');
 274          echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
 275          echo '<br /><div class="buttons">';
 276          echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
 277          echo '</div>';
 278          echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
 279          echo '<input type="hidden" name="action" value="sendmessage" />';
 280          echo '<input type="hidden" name="id" value="'.$id.'" />';
 281          echo '</fieldset>';
 282          echo '</form>';
 283          //include the needed js
 284          $module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
 285          $PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
 286      }
 287  }
 288  
 289  /// Finish the page
 290  ///////////////////////////////////////////////////////////////////////////
 291  ///////////////////////////////////////////////////////////////////////////
 292  ///////////////////////////////////////////////////////////////////////////
 293  
 294  echo $OUTPUT->footer();
 295  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1