919ef20b by Insu Mun

Add language selection for new notification page.

1 parent 7cc54a60
......@@ -132,7 +132,8 @@ function display_page()
);
update_post_meta($id, 'send_status', $entry->details['status']);
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
// update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
update_post_meta($id, 'execute_date', strtotime($executeDate));
update_post_meta($id, 'trigger', $trigger);
update_post_meta($id, 'email', $emailData);
......@@ -288,15 +289,17 @@ function create_notification()
foreach (['en', 'fr'] as $lang) {
$validation->set_rules($lang.'_subject', 'Subject', 'trim');
$validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]');
$validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]');
// $validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]');
// $validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]');
$validation->set_rules($lang.'_text', 'Text Version', 'trim');
$validation->set_rules($lang.'_html', 'HTML Version', 'trim');
$validation->set_rules($lang.'_system', 'System Message', 'trim|min_length[16]');
}
if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) {
$form_error = true;
require_once(__DIR__.'/views/create.php');
} else {
// if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) {
// $form_error = true;
// require_once(__DIR__.'/views/create.php');
// } else {
if ($validation->run() == true) {
// Clean up the data before saving
......@@ -385,7 +388,9 @@ function create_notification()
);
update_post_meta($id, 'send_status', 'pending');
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
// update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
update_post_meta($id, 'execute_date', strtotime($executeDate));
update_post_meta($id, 'trigger', $trigger);
update_post_meta($id, 'email', $emailData);
......@@ -396,5 +401,5 @@ function create_notification()
} else {
require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php');
}
}
// }
}
......
......@@ -309,7 +309,6 @@ class Validation
// Did we end up with any errors?
$total_errors = count($this->_error_array);
if ($total_errors > 0) {
$this->_safe_form_data = true;
}
......
......@@ -2,6 +2,11 @@
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Settings;
function getInputFormValues($validation, $name) {
return ($validation->set_value($name) != '') ? $validation->set_value($name) : (!empty($_POST[$name])) ? $_POST[$name] : '';
}
?>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
......@@ -40,12 +45,12 @@ use Tz\WordPress\Tools\Notifications\Settings;
<td>
<select name="type" id="notif_type" class="wide-input-field"
onchange="updateNotificationType();">
<option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled")
<option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled" || $_POST['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")
<option value="triggered" <?php echo ($validation->set_value('type') == "triggered" || $_POST['type'] == 'triggered')
? 'selected="selected"' : ""; ?>>System Triggered Notification
</option>
<?php endif; ?>
......@@ -56,9 +61,9 @@ use Tz\WordPress\Tools\Notifications\Settings;
<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>
value="<?php echo getInputFormValues($validation, 'title'); ?>"/>
<?php echo $validation->form_error('title'); ?>
</td>
</tr>
<tr class="scheduled_sendto">
<td>Sent To:</td>
......@@ -83,107 +88,167 @@ use Tz\WordPress\Tools\Notifications\Settings;
<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>
readonly="readonly" value="<?php echo getInputFormValues($validation, '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>
value="<?php echo getInputFormValues($validation, '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>
<div id="tabs">
<ul>
<li>
<a href="#tab-1">English</a>
</li>
<li>
<a href="#tab-2">French</a>
</li>
</ul>
<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>
<?php foreach (['en', 'fr'] as $index => $lang): ?>
<div id="tab-<?php echo $index + 1; ?>">
<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 (getInputFormValues($validation, $lang . '_subject')) ||
getInputFormValues($validation, $lang . '_text') ||
getInputFormValues($validation, $lang . '_html') ? '' : 'display: none;'; ?>;">
<tr>
<td width="150">Subject Line</td>
<td>
<input type="text" name="<?php echo $lang; ?>_subject"
class="wide-input-field" style="width: 100%;"
value="<?php echo getInputFormValues($validation, $lang . '_subject'); ?>"/>
<?php echo $validation->form_error($lang.'_subject'); ?>
</td>
</tr>
<tr>
<td>Text Version</td>
<td>
<textarea name="<?php echo $lang; ?>_text"
class="wide-input-field" rows="10"
style="width: 100%;"><?php echo getInputFormValues($validation, $lang . '_text'); ?>
</textarea><?php echo $validation->form_error($lang.'_text'); ?>
</td>
</tr>
<tr>
<td>HTML Version (optional)</td>
<td>
<textarea name="<?php echo $lang; ?>_html"
id="htmlversion" class="wide-input-field" rows="10"
style="width: 100%;"><?php echo getInputFormValues($validation, $lang . '_html'); ?>
</textarea><?php echo $validation->form_error($lang.'_html'); ?>
</td>
</tr>
<tr>
<td width="150">Attachments</td>
<td>&nbsp;</td>
</tr>
<?php
$attachments = $entry->email[$lang.'_attachments'];
$allowedAttachments = 3;
foreach ($attachments as $attachment): ?>
<tr>
<td>&nbsp;</td>
<td>
<?php echo $attachment; ?> &nbsp; (<a href="#"
entry_id="<?php echo $_GET['page_id'] ?>"
class="attachment"
rel="<?php echo $attachment; ?>">remove</a>)
</td>
</tr>
<?php
$allowedAttachments--;
endforeach;
?>
<?php for ($a = 1; $a <= $allowedAttachments; $a++): ?>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="<?php echo $lang; ?>_attachment[]"/></td>
</tr>
<?php endfor; ?>
</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(
$lang.'_system',
$entry->system[$lang.'_message']
) == '')
? 'display: none'
: ''; ?>;">
<tr>
<td>Message Type</td>
<td>
<?php if ($lang == 'en'): ?>
<select name="system_message_type" class="wide-input-field">
<option value="none" <?php echo ($validation->set_value(
'system_message_type',
$entry->system['system_message_type']
) == 'none') ? 'selected="selected"' : ''; ?>>
General Message
</option>
<option value="action_required" <?php echo ($validation->set_value(
'system_message_type',
$entry->system['system_message_type']
) == 'action_required') ? 'selected="selected"' : ''; ?>>
Action Required
</option>
<option value="e-flash" <?php echo ($validation->set_value(
'system_message_type',
$entry->system['system_message_type']
) == 'e-flash') ? 'selected="selected"' : ''; ?>>
E-Flash
</option>
<option value="new_event" <?php echo ($validation->set_value(
'system_message_type',
$entry->system['system_message_type']
) == 'new_event') ? 'selected="selected"' : ''; ?>>
New Event
</option>
</select>
<?php else: ?>
<span class="system_message_type_value"></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td>Message (Text/HTML)</td>
<td>
<textarea name="<?php echo $lang; ?>_system" class="wide-input-field" rows="4"
style="width:100%;"><?php echo $validation->set_value(
$lang.'_system',
isset($entry->system[$lang.'_message'])
? $entry->system[$lang.'_message']
: ''
); ?></textarea><?php echo $validation->form_error($lang.'_system'); ?>
</td>
</tr>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
<p>
......@@ -197,15 +262,54 @@ use Tz\WordPress\Tools\Notifications\Settings;
</div>
<script>
jQuery(document).ready(function () {
jQuery('#execute_date').datetimepicker({
stepMinute: 30,
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm:ss'
});
jQuery(document).ready(function ($) {
$('#tabs').tabs();
// Update system message type clone when changing the message type
$('[name="system_message_type"]').change(function () {
$('.system_message_type_value').text($(this).find(':selected').text());
}).change();
//
// jQuery('#execute_date').datetimepicker({
// stepMinute: 30,
// dateFormat: 'yy-mm-dd',
// timeFormat: 'hh:mm:ss'
// });
updateNotificationType();
$('.attachment').live('click', function (e) {
e.preventDefault();
var $link = $(this);
var options = {
action: 'remove_attachment',
ajax: 'yes',
id: $link.attr('entry_id'),
file: $link.attr('rel')
};
var file_element = '<input type="file" name="attachment[]" />';
var c = confirm('Are you sure you want to remove this attachment?');
if (c) {
$.ajax({
url: '/wp-admin/admin-ajax.php',
data: (options),
type: 'POST',
dataType: 'json',
success: function (data) {
if (data.success == "true") {
$link.parent().html(file_element);
}
}
});
}
return false;
});
jQuery('table.expandable thead th').click(function () {
var $table = jQuery(this).parent().parent().parent();
if (jQuery('tbody', $table).is(':visible')) {
......@@ -229,6 +333,11 @@ use Tz\WordPress\Tools\Notifications\Settings;
jQuery('.scheduled-extended').show();
jQuery('.trigger-extended').hide();
jQuery('.scheduled_sendto').show();
jQuery('#execute_date').datetimepicker({
format: 'Y-m-d, H:i',
defaultDate: new Date()
});
}
}
</script>
......