Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cceconvenors/
Upload File :
Current File : /var/www/cesa.co.za/cceconvenors/sendmessage.php

<?php

// ini_set('display_errors', 1);
// error_reporting(E_ALL);

session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/ewcfg7.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/ewmysql7.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/phpfn7.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/CCEMessagesinfo.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/CCEModulesinfo.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/userfn7.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cceconvenors/inc_functions.php");

if (!isset($_SESSION[EW_SESSION_STATUS]) || ($_SESSION[EW_SESSION_STATUS] != "login")) {
    header("Location: /cceconvenors/login.php");
    die();
}

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include "header.php" ?>
<p><b><a href="cstFacilitatorMessageslist.php?cmd=resetall">View All Messages</a></b></p>
<h1> Send a Message</h1>
<?php
$conni = mysqli_connect(EW_CONN_HOST, EW_CONN_USER, EW_CONN_PASS, EW_CONN_DB);

$showComposeForm = true;

if (isset($_POST["go"]) && ($_POST["go"] == 1)) {
    include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/Utils.php');

    $arrSendTo = isset($_POST["sendto"]) ? $_POST["sendto"] : array();
    $cceMessageSendResult = array();

    if (!is_array($arrSendTo) || count($arrSendTo) == 0) {
        echo '<p><b><span style="color:red;">Please select at least one recipient.</span></b></p>';
    } elseif (empty($_POST["message"])) {
        echo '<p><b><span style="color:red;">Please enter a message to be sent.</span></b></p>';
    } else {
        $sql = "SELECT FacilitatorID, FullName FROM CCEFacilitatorUsers WHERE Username='" . $_SESSION[EW_SESSION_USER_NAME] . "'";
        $recFrom = mysqli_query($conni, $sql);
        if ($rowFrom = mysqli_fetch_assoc($recFrom)) {
            $sFrom = $rowFrom["FullName"];
            $SentByFacilitatorID = $rowFrom["FacilitatorID"];
        }
        mysqli_free_result($recFrom);

        include($_SERVER['DOCUMENT_ROOT'] . "/cceadmin/inc_sendmessage.php");
        echo renderCceMessageSendFeedback($cceMessageSendResult, false);

        if (!empty($cceMessageSendResult['ok'])) {
            $showComposeForm = false;
            echo '<p><a href="sendmessage.php">Compose another message</a> | '
                . '<a href="cstFacilitatorMessageslist.php?cmd=resetall">View all messages</a></p>';
        }
    }
}

if ($showComposeForm) {
    include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/Utils.php');
    ?>
    <form action="sendmessage.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
        <input type="hidden" name="go" value="1" />
        <table border="0" cellspacing="0" cellpadding="5">
            <tr>
                <td>Module:</td>
                <td><label>
                        <select name="modid" id="modid">
                            <option value="" <?php if (!isset($_GET["id"])) echo " checked"; ?>>General</option>
                            <?php
                            $sql = "SELECT * FROM CCEModules
	ORDER BY CCEModules.ModuleNum";
                            $recMod = mysqli_query($conni, $sql);
                            while ($rowMod = mysqli_fetch_assoc($recMod)) {
                            ?>
                                <option value="<?php echo $rowMod["CCEModuleID"]; ?>" <?php if (isset($_GET["id"]) && ($_GET["id"] == $rowMod["CCEModuleID"])) echo " checked"; ?>><?php echo $rowMod["ModuleName"]; ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </label></td>
            </tr>
            <tr>
                <td valign="top">Send To:</td>
                <td>
                    <div style="font-size:11px">
                        <?php
                        $iSelectFacilitatorID = 0;
                        $iSelectStudentID = 0;
                        $sReplyHtml = "";
                        $sForwardHtml = "";
                        $sReplySubject = "";
                        $arrReplyAll = array();
                        if (isset($_GET["replyto"])) {
                            $sql = "SELECT * FROM CCEMessages WHERE CCEMessageID='" . $_GET["replyto"] . "'";
                            $rec = mysqli_query($conni, $sql);
                            if ($row = mysqli_fetch_assoc($rec)) {
                                $iSelectFacilitatorID = $row["SentByFacilitatorID"];
                                $iSelectStudentID = $row["SentByStudentID"];
                                if (isset($_GET["all"]) && ($_GET["all"] == 1))
                                    $arrReplyAll = explode(",", $row["SentTo"]);
                                $sReplyHtml = quoteCceMessageHtmlForEditor(
                                    $row["MessageText"],
                                    $row["SentDateTime"],
                                    $row["SentByName"]
                                );
                                $sReplySubject = "RE: " . $row["MessageSubject"];
                            }
                            mysqli_free_result($rec);
                        }

                        for ($raCnt = 0; $raCnt < count($arrReplyAll); $raCnt++) {
                            $arrReplyAll[$raCnt] = trim($arrReplyAll[$raCnt]);
                        }

                        if (isset($_GET["fwd"])) {
                            $sql = "SELECT * FROM CCEMessages WHERE CCEMessageID='" . $_GET["fwd"] . "'";
                            $rec = mysqli_query($conni, $sql);
                            if ($row = mysqli_fetch_assoc($rec)) {
                                $sForwardHtml = quoteCceMessageHtmlForEditor(
                                    $row["MessageText"],
                                    $row["SentDateTime"],
                                    $row["SentByName"]
                                );
                                $sReplySubject = "FWD: " . $row["MessageSubject"];
                            }
                            mysqli_free_result($rec);
                        }

                        if (isset($$_POST["sendto"]) && is_array($$_POST["sendto"]) && count($$_POST["sendto"]) > 0) {
                            $arrReplyAll = array_merge($arrReplyAll, $_POST["sendto"]);
                        }

                        //                        var_dump($arrReplyAll);
                        ?>
                        <table border=0>
                            <tr>
                                <td valign="top">
                                    <!-- <input type="checkbox" name="sendto[]"
                                        value="CESA" <?php if (in_array("CESA Programme Coordinator", $arrReplyAll)) echo " checked"; ?>>BCE Programme Coordinators<br>
                                     -->
                                        <input type="checkbox" name="sendto[]" value="blessings"
                                        <?php if (in_array("blessings", $arrReplyAll)) echo " checked"; ?>>Blessings Banda<br>
                                    <input type="checkbox" name="sendto[]" value="brenda"
                                        <?php if (in_array("brenda", $arrReplyAll)) echo " checked"; ?>>Brenda Lacey-Smith<br>
                                    
                                    <!-- <input type="checkbox" name="sendto[]" value="melissa"
                                        <?php if (in_array("melissa", $arrReplyAll)) echo " checked"; ?>>Melissa Jardine<br> -->

                                    <br>
                                    <?php
                                    if (strpos(' ' . $_SERVER['REQUEST_URI'], 'cceconvenors') > 0) {
                                        $sql = "SELECT * FROM CCEFacilitators WHERE Archived=0 ORDER BY FacilitatorName";
                                        $rec = mysqli_query($conni, $sql);
                                        while ($row = mysqli_fetch_assoc($rec)) {
                                    ?>
                                            <input type="checkbox" name="sendto[]" value="F<?php echo $row["FacilitatorID"]; ?>" <?php if (($iSelectFacilitatorID == $row["FacilitatorID"]) || in_array($row["FacilitatorName"], $arrReplyAll)) echo " checked"; ?>>
                                            Convenor: <?php echo $row["FacilitatorName"]; ?><br>
                                    <?php
                                        } //while
                                    } //if
                                    ?>
                                    <p><i>Note: Convenors / facilitators will be <br>
                                            CCed on inter-student communications.</i></p>
                                </td>
                                <td valign="top">
                                    <input type="checkbox" name="sendto[]" value="FAll" <?php if (in_array("All Convenors", $arrReplyAll)) echo " checked"; ?>>All Convenors<br>
                                    <br>
                                    <?php
                                    $sql = "SELECT * FROM CCEStudents WHERE BlockAccess='n' AND Archived=0 AND CCEStudentID<>54 ORDER BY " . CCEStudentDisplayOrder::sqlOrderByDisplayName('CCEStudents') . " LIMIT 0,15";
                                    $rec = mysqli_query($conni, $sql);
                                    while ($row = mysqli_fetch_assoc($rec)) {
                                    ?>
                                        <input type="checkbox" name="sendto[]" value="S<?php echo $row["CCEStudentID"]; ?>" <?php if (($iSelectStudentID == $row["CCEStudentID"]) || in_array($row["FirstName"] . " " . $row["Surname"], $arrReplyAll) || in_array($row["KnownAs"] . " " . $row["Surname"], $arrReplyAll)) echo " checked"; ?>>
                                        Student: <?php echo $row["KnownAs"] . " " . $row["Surname"]; ?><br>
                                    <?php
                                    }
                                    ?>
                                </td>
                                <td valign="top">
                                    <input type="checkbox" name="sendto[]" value="SAll" <?php if (in_array("All Students", $arrReplyAll)) echo " checked"; ?>>All Students<br>
                                    <br>
                                    <?php
                                    $sql = "SELECT * FROM CCEStudents WHERE BlockAccess='n' AND Archived=0 AND CCEStudentID<>54 ORDER BY " . CCEStudentDisplayOrder::sqlOrderByDisplayName('CCEStudents') . " LIMIT 15,100";
                                    $rec = mysqli_query($conni, $sql);
                                    while ($row = mysqli_fetch_assoc($rec)) {
                                    ?>
                                        <input type="checkbox" name="sendto[]" value="S<?php echo $row["CCEStudentID"]; ?>" <?php if (($iSelectStudentID == $row["CCEStudentID"]) || in_array($row["KnownAs"] . " " . $row["Surname"], $arrReplyAll)) echo " checked"; ?>>Student: <?php echo $row["KnownAs"] . " " . $row["Surname"]; ?><br>
                                    <?php
                                    }
                                    ?>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
            <tr>
                <td>Subject:</td>
                <td><label>
                        <input name="subject" type="text" id="subject" size="60" value="<?php echo $sReplySubject; ?>" />
                    </label></td>
            </tr>
            <tr>
                <td>Message:</td>
                <td><label>
                        <textarea name="message" id="message" cols="75" rows="10"><?php
                                                                                    if (isset($_POST["message"])) {
                                                                                        echo $_POST["message"];
                                                                                    } elseif (!empty($sReplyHtml) || !empty($sForwardHtml)) {
                                                                                        echo $sReplyHtml . $sForwardHtml;
                                                                                    }
                                                                                    ?></textarea>
                    </label></td>
            </tr>
            <tr>
                <td valign="top">Attachments:</td>
                <td><?php include $_SERVER['DOCUMENT_ROOT'] . '/php/includes/cceMessageAttachmentUpload.inc.php'; ?></td>
            </tr>
        </table>
        <p>
            <label>
                <input type="submit" name="button" id="button" value="Send Now" />
            </label>
        </p>
    </form>

    <script>
        var allowSubmit = true;

        $(document).ready(function() {

            $('#form1').on('submit', function() {
                if (allowSubmit) {
                    allowSubmit = false;
                    $('#button').attr('value', 'Sending now ...');
                    $('#button').attr('disabled', 'disabled');
                    return true;
                } else {
                    return false;
                }
            });
        });

    </script>
    <?php include $_SERVER['DOCUMENT_ROOT'] . '/php/includes/cceMessageEditor.inc.php'; ?>
<?php
}
?>
<p>&nbsp;</p>

<?php include "footer.php" ?>