[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/user/ -> messageselect.php (source)

   1  <?php // $Id: messageselect.php,v 1.15.2.5 2008/02/20 02:32:03 moodler Exp $
   2  
   3      require_once ('../config.php');
   4      require_once($CFG->dirroot.'/message/lib.php');
   5  
   6      $id = required_param('id',PARAM_INT);
   7      $messagebody = optional_param('messagebody','',PARAM_CLEANHTML);
   8      $send = optional_param('send','',PARAM_RAW);   // Content is actually treated as boolean
   9      $preview = optional_param('preview','',PARAM_RAW);   // Content is actually treated as boolean
  10      $edit = optional_param('edit','',PARAM_RAW);   // Content is actually treated as boolean
  11      $returnto = optional_param('returnto','',PARAM_LOCALURL);
  12      $format = optional_param('format',FORMAT_MOODLE,PARAM_INT);
  13      $deluser = optional_param('deluser',0,PARAM_INT);
  14  
  15      if (!$course = get_record('course','id',$id)) {
  16          error("Invalid course id");
  17      }
  18  
  19      require_login();
  20  
  21      $coursecontext = get_context_instance(CONTEXT_COURSE, $id);   // Course context
  22      $systemcontext = get_context_instance(CONTEXT_SYSTEM);   // SYSTEM context
  23      require_capability('moodle/course:bulkmessaging', $coursecontext);
  24  
  25      if (empty($SESSION->emailto)) {
  26          $SESSION->emailto = array();
  27      }
  28      if (!array_key_exists($id,$SESSION->emailto)) {
  29          $SESSION->emailto[$id] = array();
  30      }
  31  
  32      if ($deluser) {
  33          if (array_key_exists($id,$SESSION->emailto) && array_key_exists($deluser,$SESSION->emailto[$id])) {
  34              unset($SESSION->emailto[$id][$deluser]);
  35          }
  36      }
  37  
  38      if (empty($SESSION->emailselect[$id]) || $messagebody) {
  39          $SESSION->emailselect[$id] = array('messagebody' => $messagebody);
  40      }
  41  
  42      $messagebody = $SESSION->emailselect[$id]['messagebody'];
  43  
  44      $count = 0;
  45  
  46      foreach ($_POST as $k => $v) {
  47          if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) {
  48              if (!array_key_exists($m[2],$SESSION->emailto[$id])) {
  49                  if ($user = get_record_select('user','id = '.$m[2],'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
  50                      $SESSION->emailto[$id][$m[2]] = $user;
  51                      $SESSION->emailto[$id][$m[2]]->teacher = ($m[1] == 'teacher');
  52                      $count++;
  53                  }
  54              }
  55          }
  56      }
  57  
  58      $strtitle = get_string('coursemessage');
  59  
  60      if (empty($messagebody)) {
  61          $formstart = "theform.messagebody";
  62      } else {
  63          $formstart = "";
  64      }
  65  
  66      $navlinks = array();
  67      if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
  68          $navlinks[] = array('name' => get_string('participants'), 'link' => "index.php?id=$course->id", 'type' => 'misc');
  69      }
  70      $navlinks[] = array('name' => $strtitle, 'link' => null, 'type' => 'misc');
  71      $navigation = build_navigation($navlinks);
  72  
  73      print_header($strtitle,$strtitle,$navigation,$formstart);
  74  
  75      // if messaging is disabled on site, we can still allow users with capabilities to send emails instead
  76      if (empty($CFG->messaging)) {
  77          notify(get_string('messagingdisabled','message'));  
  78      }
  79  
  80      if ($count) {
  81          if ($count == 1) {
  82              $heading =  get_string('addedrecip','moodle',$count);
  83          } else {
  84              $heading = get_string('addedrecips','moodle',$count);
  85          }
  86          print_heading($heading);
  87      }
  88  
  89      if (!empty($messagebody) && !$edit && !$deluser && ($preview || $send)) {
  90          if (count($SESSION->emailto[$id])) {
  91              if (!empty($preview)) {
  92                  echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
  93  <input type="hidden" name="returnto" value="'.s($returnto).'" />
  94  <input type="hidden" name="id" value="'.$id.'" />
  95  <input type="hidden" name="format" value="'.$format.'" />
  96  ';
  97                  echo "<h3>".get_string('previewhtml')."</h3><div class=\"messagepreview\">\n".format_text(stripslashes($messagebody),$format)."\n</div>\n";
  98                  echo '<p align="center"><input type="submit" name="send" value="'.get_string('sendmessage', 'message').'" />'."\n";
  99                  echo '<input type="submit" name="edit" value="'.get_string('update').'" /></p>';
 100                  echo "\n</form>";
 101              } else if (!empty($send)) {
 102                  $good = 1;
 103                  $teachers = array();
 104                  foreach ($SESSION->emailto[$id] as $user) {
 105                      $good = $good && message_post_message($USER,$user,addslashes($messagebody),$format,'direct');
 106                      if ($user->teacher) {
 107                          $teachers[] = $user->id;
 108                      }
 109                  }
 110                  if (!empty($good)) {
 111                      print_heading(get_string('messagedselectedusers'));
 112                      unset($SESSION->emailto[$id]);
 113                      unset($SESSION->emailselect[$id]);
 114                  } else {
 115                      print_heading(get_string('messagedselectedusersfailed'));
 116                  }
 117                  echo '<p align="center"><a href="index.php?id='.$id.'">'.get_string('backtoparticipants').'</a></p>';
 118              }
 119              print_footer();
 120              exit;
 121          } else {
 122              notify(get_string('nousersyet'));
 123          }
 124      }
 125  
 126      echo '<p align="center"><a href="'.$returnto.'">'.get_string("keepsearching").'</a>'.((count($SESSION->emailto[$id])) ? ', '.get_string('usemessageform') : '').'</p>';
 127  
 128      if ((!empty($send) || !empty($preview) || !empty($edit)) && (empty($messagebody))) {
 129          notify(get_string('allfieldsrequired'));
 130      }
 131  
 132      if (count($SESSION->emailto[$id])) {
 133          $usehtmleditor = can_use_richtext_editor();
 134          require ("message.html");
 135          if ($usehtmleditor) {
 136              use_html_editor("messagebody");
 137          }
 138      }
 139  
 140      print_footer();
 141  
 142  
 143  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7