create.php 10.5 KB
<?php
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Settings;
?>

<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>

<div class="wrap">
    <h2>Notifications - Create New</h2>

    <?php if (isset($flash) && $flash != ""): ?>
        <div class="post-success">
            <?php echo $flash; ?>
        </div>
    <?php endif; ?>
    <?php if ($validation->validation_errors() != "" || isset($form_error)): ?>
        <div class="post-errors">
            <div class="post-errors-title"><strong>Oops.</strong> There was an error saving your notification.</div>
            <?php if (isset($form_error)): ?>
                <p class="post-errors-content">You must include either an Email, System or SMS message.</p>
            <?php endif; ?>
        </div>
    <?php endif; ?>

    <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new">

        <input type="hidden" name="_POSTED_" value="yes"/>

        <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
            <thead>
                <tr>
                    <th width="150">Notification Details</th>
                    <th>&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td width="150">Notification Type</td>
                    <td>
                        <select name="type" id="notif_type" class="wide-input-field"
                                onchange="updateNotificationType();">
                            <option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled")
                                ? 'selected="selected"' : ""; ?>>Scheduled Notification
                            </option>

                            <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
                                <option value="triggered" <?php echo ($validation->set_value('type') == "triggered")
                                    ? 'selected="selected"' : ""; ?>>System Triggered Notification
                                </option>
                            <?php endif; ?>
                        </select>
                        <?php echo $validation->form_error('type'); ?>
                    </td>
                </tr>
                <tr>
                    <td width="150">Notification Description</td>
                    <td><input type="text" name="title" class="wide-input-field"
                               value="<?php echo $validation->set_value(
                                   'title'
                               ); ?>"/><?php echo $validation->form_error('title'); ?></td>
                </tr>
                <tr class="scheduled_sendto">
                    <td>Sent To:</td>
                    <td>
                        <select name="sendto" class="wide-input-field">
                            <option value="allusers" <?php echo ($validation->set_value('sendto') == "allusers")
                                ? 'selected="selected"' : ""; ?>>All Users
                            </option>
                            <optgroup label="By Group:">
                                <?php foreach (Notifications\getGroups() as $group_id => $group_name): ?>
                                    <option value="<?php echo $group_id ?>"  <?php echo ($validation->set_value(
                                            'sendto'
                                        ) == $group_id) ? 'selected="selected"'
                                        : ""; ?>><?php echo $group_name; ?></option>
                                <?php endforeach; ?>
                            </optgroup>
                        </select>
                        <?php echo $validation->form_error('sendto'); ?>
                    </td>
                </tr>

                <tr class="scheduled-extended">
                    <td>Execute Date / Time</td>
                    <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick"
                               readonly="readonly" value="<?php echo $validation->set_value(
                            'execute_date'
                        ); ?>"/><?php echo $validation->form_error('execute_date'); ?></td>
                </tr>

                <tr class="trigger-extended">
                    <td>Trigger</td>
                    <td><input type="text" name="trigger" id="trigger" class="wide-input-field"
                               value="<?php echo $validation->set_value(
                                   'trigger'
                               ); ?>"/><?php echo $validation->form_error('trigger'); ?></td>
                </tr>

            </tbody>
        </table>

        <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
            <thead>
                <tr>
                    <th width="150" class="toggle"><h6>Email</h6></th>
                    <th class="action-bar">&nbsp;</th>
                </tr>
            </thead>
            <tbody style="<?php echo ($validation->set_value('subject') != "" || $validation->set_value(
                    'text'
                ) != "" || $validation->set_value('html') != "") ? "" : "display:none"; ?>;">
                <tr>
                    <td width="150">Subject Line</td>
                    <td><input type="text" name="subject" class="wide-input-field" style="width:100%;"
                               value="<?php echo $validation->set_value(
                                   'subject'
                               ); ?>"/><?php echo $validation->form_error('subject'); ?></td>
                </tr>
                <tr>
                    <td>Text Version</td>
                    <td><textarea name="text" class="wide-input-field" rows="10"
                                  style="width:100%;"><?php echo $validation->set_value(
                                'text'
                            ); ?></textarea><?php echo $validation->form_error('text'); ?></td>
                </tr>
                <tr>
                    <td>HTML Version (optional)</td>
                    <td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10"
                                  style="width:100%;"><?php echo $validation->set_value(
                                'html'
                            ); ?></textarea><?php echo $validation->form_error('html'); ?></td>
                </tr>
                <tr>
                    <td width="150">Attachments</td>
                    <td><input type="file" name="attachment[]"/></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="file" name="attachment[]"/></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="file" name="attachment[]"/></td>
                </tr>
            </tbody>
        </table>

        <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
            <thead>
                <tr>
                    <th width="150" class="toggle"><h6>System Message</h6></th>
                    <th class="action-bar">&nbsp;</th>
                </tr>
            </thead>
            <tbody style="<?php echo ($validation->set_value('system') == "") ? "display:none" : ""; ?>;">
                <tr>
                    <td>Message Type</td>
                    <td>
                        <select name="system_message_type" class="wide-input-field">
                            <option value="none" <?php echo ($validation->set_value('system_message_type') == "none")
                                ? 'selected="selected"' : ""; ?>>General Message
                            </option>
                            <option value="action_required" <?php echo ($validation->set_value(
                                    'system_message_type'
                                ) == "action_required") ? 'selected="selected"' : ""; ?>>Action Required
                            </option>
                            <option value="e-flash" <?php echo ($validation->set_value(
                                    'system_message_type'
                                ) == "e-flash") ? 'selected="selected"' : ""; ?>>E-Flash
                            </option>
                            <option value="new_event" <?php echo ($validation->set_value(
                                    'system_message_type'
                                ) == "new_event") ? 'selected="selected"' : ""; ?>>New Event
                            </option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Message (Text/HTML)</td>
                    <td><textarea name="system" class="wide-input-field" rows="4"
                                  style="width:100%;"><?php echo $validation->set_value(
                                'system'
                            ); ?></textarea><?php echo $validation->form_error('system'); ?></td>
                </tr>
            </tbody>
        </table>


        <p>
            <input type="submit" value="  Save  "/>
            <input type="button" value="  Cancel  "
                   onclick="document.location.href='/wp-admin/admin.php?page=notifications';"/>
        </p>

    </form>

</div>

<script>
    jQuery(document).ready(function () {
        jQuery('#execute_date').datetimepicker({
            stepMinute: 30,
            dateFormat: 'yy-mm-dd',
            timeFormat: 'hh:mm:ss'
        });

        updateNotificationType();

        jQuery('table.expandable thead th').click(function () {
            var $table = jQuery(this).parent().parent().parent();
            if (jQuery('tbody', $table).is(':visible')) {
                jQuery('thead', $table).removeClass('open');
                jQuery('tbody', $table).fadeOut();
            } else {
                jQuery('thead', $table).addClass('open');
                jQuery('tbody', $table).fadeIn();
            }
        });
    });

    function updateNotificationType() {
        var type = jQuery('#notif_type').val();

        if (type == "triggered") {
            jQuery('.scheduled-extended').hide();
            jQuery('.scheduled_sendto').hide();
            jQuery('.trigger-extended').show();
        } else {
            jQuery('.scheduled-extended').show();
            jQuery('.trigger-extended').hide();
            jQuery('.scheduled_sendto').show();
        }
    }
</script>