<?php
    require_once('common/header.php');


    if(isset($_POST) && !empty($_POST)){
        if(MailingList::emailList()){
            $session->message("Your message has been sent!");
            redirect_to("dashboard.php");
        }else{
            $session->message("Your message was not sent!");
            foreach(MailingList::$errors as $error){
                $session->message($error);
            }
            redirect_to("send_mailing_list.php");
        }
    }

    $mailingListTable = new Table('cmsgen_mailing_list_groups');
    $mailingListGroups = $mailingListTable->findAll();
?>


<form action="" method="post" enctype="multipart/form-data" id="AdministratorsEdit">
    <h1 class="title">Mailing List</h1>
    <div class="form round drop_shadow" id="list">
        <table cellpadding="4" width="100%" style="font-size:12px;">
            <tr>
                <td><h2>Group List:</h2></td>
                <td>
                    <select name="group_id">
                        <option value="0">No Group</option>
                        <?php foreach($mailingListGroups as $group) : ?>
                            <option value="<?php echo $group['id']; ?>"><?php echo $group['name']; ?></option>
                            <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td></tr>
            <tr>
                <td><h2>Subject</h2></td>
                <td><input type="text" name="mailingListSubject" /></td>
            </tr>
            <tr>
                <td><h2>Message</h2></td>
                <td><textarea class="mceEditor" cols="60" rows="6" name="mailingListMessage"></textarea></td>
            </tr>

        </table>
        <div class="clear"></div>
        <br />
        <input type="submit" name="save" class="submit round drop_shadow" value="Email Mailing List!" style="float:left;margin-left:4px;" /><br><br><br><br>
        <div class="clear"></div>
    </div>

</form>
<script type="text/javascript" src="<?php echo ADMIN_PATH_HTML;?>/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
    initMCE();

</script>
<?php require_once('common/footer.php'); ?>