Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/echasl23/
Upload File :
Current File : /var/www/cesa.co.za/echasl23/CertificateEmail.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("ewcfg7.php");
include_once("ewmysql7.php");
include_once("phpfn7.php");
include_once("inc_functions.php");
include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/SchoolAttendees.php');

if (isset($_REQUEST['markAllAsAttendedPaid']) || isset($_REQUEST['markAllAsAttended']) || isset($_REQUEST['markAllAsPaid']) || 
        isset($_REQUEST['markAllAsUnpaid']) || isset($_REQUEST['markSelectedAsAttendedPaid']) ||
        isset($_REQUEST['markSelectedAsAttended']) || isset($_REQUEST['markSelectedAsPaid']) || 
        isset($_REQUEST['markAllAsNotAttendedPaid']) || isset($_REQUEST['markAllAsNotAttended']) || isset($_REQUEST['markAllAsNotPaid']) ||
        isset($_REQUEST['markSelectedAsNotAttendedPaid']) || isset($_REQUEST['markSelectedAsNotAttended']) || isset($_REQUEST['markSelectedAsNotPaid'])) {

    $server = EW_CONN_HOST;
    $user = EW_CONN_USER;
    $pass = EW_CONN_PASS;
    $db = EW_CONN_DB;

    $schoolAttendeesObject = new SchoolAttendees($sqlf);

//    var_dump($_REQUEST);
//    exit;

    $schoolAttendeesObject->chooseAttendedPaid($_REQUEST);
    ?>
    <p><span class="phpmaker"><b>Attendees Marked as Attended and/ or Paid</b></span></p>
    <p><span class="phpmaker"><a href="/echasl23/Certificateslist.php?showmaster=SchoolEvents&EventID=<?php echo $_REQUEST['EventID'] ?>">Back to certificates</a></span></p>
    <script language="Javascript">
        window.location = '/echasl23/Certificateslist.php?showmaster=SchoolEvents&EventID=<?php echo $_REQUEST['EventID'] . '&nocache=' . time(); ?>';
    </script>
    <?php
    exit;
}

include_once("Certificatesinfo.php");
include_once("SchoolEventsinfo.php");
include_once("adminusersinfo.php");
require_once($_SERVER['DOCUMENT_ROOT'] . '/contracts/fpdf184/fpdf.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/contracts/FPDI-2.3.6/src/autoload.php');

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" ?>
<?php
//if (isset($_REQUEST["EventID"]) && !empty($_REQUEST["EventID"])) {
$refer = $_SERVER['HTTP_REFERER'];
if (isset($_REQUEST["refer"]) && !empty($_REQUEST["refer"]))
    $refer = $_REQUEST["refer"];
?>
<p><SPAN class=phpmaker><A href="<?php echo $refer; ?>">Return to previous screen</A></SPAN></p>
<?php
//}

$conni = mysqli_connect(EW_CONN_HOST, EW_CONN_USER, EW_CONN_PASS, EW_CONN_DB);

$eventId = $_REQUEST["EventID"];

if (isset($_REQUEST["go"]) && ($_REQUEST["go"] == 1)) {
    
    $iEmailsSent = SchoolAttendees::sendAttendeeCertificates($_REQUEST);
    ?>
    <p><span class="phpmaker"><b><?php echo $iEmailsSent; ?> email messages sent</b></span></p>
    <?php
} else {

    if ($eventId <= 0) {
        echo '<p><span class="phpmaker"><b>No event ID specified</b></span></p>';
        exit;
    }

    $arrEmailAddresses = array();
    $arrFilenames = array();
    $arrNames = array();
    $arrBookedBy = array();
    $arrAttendeeIDs = array();
    $AttendeeIDs = array();

    if (isset($_REQUEST["AttendeeID"]) || isset($_REQUEST["AttendeeIDs"])) {

        if (isset($_REQUEST["AttendeeID"]) && $_REQUEST["AttendeeID"] > 0) {
            $AttendeeIDs = array_merge($AttendeeIDs, array($_REQUEST["AttendeeID"]));
        }

        if (isset($_REQUEST["AttendeeIDs"]) && strlen($_REQUEST["AttendeeIDs"]) > 0) {
            $AttendeeIDs = array_merge($AttendeeIDs, json_decode($_REQUEST["AttendeeIDs"], true));
        }
    }

    $sql = "SELECT AttendeeID, ContactFirstName, ContactLastName, EmailAddress, BookingEmail FROM SchoolAttendees
		WHERE SchoolAttendees.EventID='" . $_REQUEST["EventID"] . "' "
            . "AND Attended = 'y' "
            . "AND AttendeeID IN (SELECT AttendeeID FROM SchoolPayments WHERE EventID = " . $eventId . ") ";

    if (count($AttendeeIDs) > 0) {
        $sql .= " AND AttendeeID IN (" . implode(", ", $AttendeeIDs) . ")";
    }

//    echo $sql . '<br />';
//    exit;
    $recAttendees = mysqli_query($conni, $sql);

    while ($rowAttendees = mysqli_fetch_assoc($recAttendees)) {

        $AttendeeID = $rowAttendees["AttendeeID"];
        $EmailAddress = $rowAttendees["EmailAddress"];
        $ContactFirstName = $rowAttendees["ContactFirstName"];
        $ContactLastName = $rowAttendees["ContactLastName"];
        $BookingEmail = $rowAttendees["BookingEmail"];

        include("inc_gencertificate.php");

        if (empty($EmailAddress)) {
            echo '<b style="color: #FF0000;">No e-mail address for ' . $ContactFirstName . ' ' . $ContactLastName
                . '.</b> Certificate will still be processed if alternate recipients/test mode are selected.<br />';
        }

        $arrFilenames[] = $sFilename;
        $arrEmailAddresses[] = $EmailAddress;
        $arrNames[] = $ContactFirstName . " " . $ContactLastName;
        $arrBookedBy[] = $BookingEmail;
        $arrAttendeeIDs[] = $AttendeeID;
    } //while
    mysqli_free_result($recAttendees);

//    var_dump($arrAttendeeIDs);
//    exit;
//    var_dump($arrNames);
    ?>
    <form method="post" action="CertificateEmail.php">
        <input type="hidden" name="go" value="1" />
        <input type="hidden" name="refer" value="<?php echo addslashes($_SERVER["HTTP_REFERER"]); ?>" />
        <input type="hidden" name="EventID" value="<?php echo intval($eventId); ?>" />
        <input type="hidden" name="EventName" value="<?php echo addslashes($EventName); ?>" />
        <input type="hidden" name="NumMessages" value="<?php echo count($arrNames); ?>" />
        <?php
        for ($i = 1; $i <= count($arrNames); $i++) {
            ?>
            <input type="hidden" name="Name<?php echo $i; ?>" value="<?php echo addslashes($arrNames[$i - 1]); ?>" />
            <input type="hidden" name="Email<?php echo $i; ?>" value="<?php echo $arrEmailAddresses[$i - 1]; ?>" />
            <input type="hidden" name="File<?php echo $i; ?>" value="<?php echo $arrFilenames[$i - 1]; ?>" />
            <input type="hidden" name="BookedBy<?php echo $i; ?>" value="<?php echo $arrBookedBy[$i - 1]; ?>" />
            <input type="hidden" name="AttendeeID<?php echo $i; ?>" value="<?php echo $arrAttendeeIDs[$i - 1]; ?>" />
            <?php
        }
        ?>
        <p><span class="phpmaker">Email message:</span><br />
            Dear <i>name</i>,<br />
            <textarea name="EmailMessage" rows="10" cols="60"><?php
                echo SchoolAttendees::getSendCertificateBody();
                ?></textarea><br />
            <input name="sendcopysce" type="checkbox" value="yes" checked="checked" />
            Send a copy to cpdcertificates@cesa.co.za<br />
            <input name="sendcopybb" type="checkbox" value="yes" checked="checked" />
            Send a copy to "Booked By"<br />
            And send a copy to this address: <input type-"text" name="CopyExtra" value="" /><br />
            <input name="sendtestonly" type="checkbox" value="yes" />
            Send test only (do not email actual attendee address)<br />
            Test e-mail address: <input type="text" name="TestEmailAddress" value="" placeholder="test@domain.com" /><br />
            <input type="submit" value="Send Now" />
        </p>
        <p><span class-"phpmaker">Certificate/s will be emailed to the following attendees:</span></p>
        <TABLE class="ewTable ewTableSeparate" cellSpacing=0 roweditclass="ewTableEditRow" rowselectclass="ewTableSelectRow" rowhighlightclass="ewTableHighlightRow" isset="true"><THEAD><!-- Table header -->
                <TR class=ewTableHeader>
                    <TD>
                        <TABLE class=ewTableHeaderBtn cellSpacing=0>
                            <THEAD>
                                <TR>
                                    <TD>Name</TD>
                                </TR></THEAD></TABLE></TD>
                    <TD>
                        <TABLE class=ewTableHeaderBtn cellSpacing=0>
                            <THEAD>
                                <TR>
                                    <TD>Email</TD>
                                </TR></THEAD></TABLE></TD>
                    <TD>
                        <TABLE class=ewTableHeaderBtn cellSpacing=0>
                            <THEAD>
                                <TR>
                                    <TD>Preview certificate</TD>
                                </TR></THEAD></TABLE></TD>
                </TR></THEAD>
            <TBODY>
                <?php
                for ($i = 0; $i < count($arrNames); $i++) {
                    ?>
                    <TR>
                        <TD>
                            <DIV><?php echo $arrNames[$i]; ?></DIV></TD>
                        <TD>
                            <DIV><?php echo $arrEmailAddresses[$i]; ?></DIV></TD>
                        <TD>
                            <DIV><a href="certificates/files/<?php echo $arrFilenames[$i]; ?>" target="_blank"><?php echo $arrFilenames[$i]; ?></a></DIV></TD>
                    </TR>
                    <?php
                }
                ?>
            </TBODY></TABLE>
    </form>
    <?php
}
?>
<?php include "footer.php" ?>