Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9cdc1ee17d
Fetching contributors…

Cannot retrieve contributors at this time

file 92 lines (76 sloc) 2.689 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php

require_once('../init.php');

if(!logged_in())
    send_user_to("/login.php");

$class = new course($dbpdo, $_GET['id']);
$user = new user($dbpdo, $_SESSION['user_id']);

$class->get_teachers();
$class->get_owner();

if($class->owner != $user->id && !in_array($user->id,$class->teachers))
  send_user_to("/class/" . $class->id . "/" . $class->seo_string($class->value));

$success = false;
$error = array();
if(!empty($_POST))
{
  $subj = $_POST['subj'];
  $msg = $_POST['msg'];

  if(strlen($subj)*strlen($msg) == 0)
    $error[] = "you must enter a subject and a message.";
  else
  {
    $from = $user->id;
    date_default_timezone_set('UTC');
    $datetime = date("Y-m-d H:i:s");
    
    $class->mass_message($subj, $msg, $user->id);
    foreach($class->roster as $child_id)
      {
$student = new user($dbpdo, $child_id);
send_email(strtolower($user->value . "@ureddit.com"), $student->value . "@ureddit.com", $subj,process($msg));
      }
    $success = true;

    $tweet = "(" . date("U") . ") " . $user->value . " PMed the students in " . $class->value;
    if(strlen($tweet) > 115)
      $tweet = substr($tweet, 0, 115) . "...";
    $tweet .= " http://ureddit.com/c" . $class->id;
    if(strlen($tweet) < 126)
      $tweet .= " with subject line \"$subj\"";
if(strlen($tweet) > 140)
$tweet = substr($tweet, 0, 136) . "...\"";
      //$tweet .= ": \"$subj\"";
    tweet($user->config, $tweet);
  }
}

$params['title'] .= ' : Mass Message';
require('../header2.php');

?>
<div id="teach">
<div class="content">
<h1>Mass Message Class</h1>
<div style="color: red;">
<?php
if(count($error) != 0)
  foreach($error as $err)
    echo "$err<br />\n";
elseif($success == true)
  echo "your mass message was delivered<br><br>";
?>
</div><br />

<form method="post" action="<?=PREFIX ?>/teachers/msg_class.php?id=<?=$_GET['id'] ?>">
Subject:<br />
<input type="text" name="subj" class="teach" value="<?=!empty($_POST) && isset($error) && count($error) > 0 ? htmlspecialchars(stripslashes($_POST['subj'])) : "" ?>" />
<br /><br />

Message:<br />
<textarea name="msg" class="teach"><?=!empty($_POST) && isset($error) && count($error) > 0 ? htmlspecialchars(stripslashes($_POST['msg'])) : "" ?></textarea>
<br /><br />

<input type="submit" value="Send PMs" style="padding: 3px;" />
</form>
</div>
</div>
<div id="teach-side">
<div class="content" style="border-bottom: 3px solid #232323">
<h2>Note:</h2>

Please click the button only once. It may take some time to deliver a mass message to several hundred people.

<?php include('tools.php'); ?>
</div>
</div>
<?php require_once('../footer2.php'); ?>
Something went wrong with that request. Please try again.