b43072e0 by Marty Penner

Make notifications translatable

1 parent a1a85c5a
......@@ -26,9 +26,6 @@ function display_page()
{
if (isset($_GET['action']) && $_GET['action'] == "edit") {
/** @var \wpdb $wpdb */
global $wpdb;
/** @var \StdClass $entry */
$entry = get_post($_GET['page_id']);
......@@ -42,26 +39,26 @@ function display_page()
$entry->email = $email;
$entry->system = $system;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type', 'Notification Type', 'required');
$validation->set_rules('title', 'Description', 'trim|required|min_length[4]');
$validation->set_rules('type', 'Notification Type', 'required');
$validation->set_rules('sendto', 'Send To', 'required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$type_val = ($_POST && $_POST['type'] == 'scheduled') ? 'required' : '';
$validation->set_rules('execute_date', 'Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$trigger_val = ($_POST && $_POST['type'] == 'triggered') ? 'required' : '';
$validation->set_rules('trigger', 'Trigger', $trigger_val);
$validation->set_rules('subject', 'Subject', 'trim');
$validation->set_rules('text', 'Text Version', 'trim|min_length[16]');
$validation->set_rules('html', 'HTML Version', 'trim|min_length[16]');
$validation->set_rules('system_message_type', 'System Message Type', 'trim');
$validation->set_rules('system', 'System Message', 'trim|min_length[16]');
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.'_system', 'System Message', 'trim|min_length[16]');
}
//details
if ($validation->run() == true) {
......@@ -69,73 +66,77 @@ function display_page()
// Clean up data before saving
Tools\tzClean($_POST);
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type == "scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type == "scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = [];
$upload_dir = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'notifications'.DIRECTORY_SEPARATOR;
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if ($file['name'] != "") {
move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']);
$attachments[] = $file['name'];
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$executeDate = ($type == 'scheduled') ? $_POST['execute_date'] : '0000-00-00 00:00:00';
$trigger = ($type == 'scheduled') ? 'scheduled-cron-job' : $_POST['trigger'];
$emailData = [];
$systemMessageData = [];
foreach (['en', 'fr'] as $lang) {
// email
$subject = $_POST[$lang.'_subject'];
$text = $_POST[$lang.'_text'];
$html = $_POST[$lang.'_html'];
$attachments = [];
$uploadDir = __DIR__.'/../../../uploads/notifications/';
fixFilesArray($_FILES[$lang.'_attachment']);
foreach ($_FILES[$lang.'_attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if ($file['name'] != '') {
move_uploaded_file($file['tmp_name'], $uploadDir.$file['name']);
$attachments[] = $file['name'];
}
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
// system
$systemMessageType = $_POST['system_message_type'];
$system = $_POST[$lang.'_system'];
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
if (count($entry->email[$lang.'_attachments']) > 0) {
$attachments = array_merge($entry->email[$lang.'_attachments'], $attachments);
}
$emailData = array_merge(
$emailData,
[
$lang.'_subject' => $subject,
$lang.'_text' => $text,
$lang.'_html' => $html,
$lang.'_attachments' => $attachments
]
);
$systemMessageData = array_merge(
$systemMessageData,
[
'system_message_type' => $systemMessageType,
$lang.'_message' => $system
]
);
}
update_post_meta(
$id,
"details",
'details',
[
'type' => $type,
'sendto' => $sendto,
'status' => $entry->details['status'],
'trigger' => $trigger,
'execute_date' => $execute_date
'execute_date' => $executeDate
]
);
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, 'trigger', $trigger);
if (count($entry->email['attachments']) > 0) {
$attachments = array_merge($entry->email['attachments'], $attachments);
}
update_post_meta(
$id,
'email',
[
'subject' => $subject,
'text' => $text,
'html' => $html,
'attachments' => $attachments
]
);
update_post_meta(
$id,
'system',
[
'system_message_type' => $system_message_type,
'message' => $system
]
);
update_post_meta($id, 'email', $emailData);
update_post_meta($id, 'system', $systemMessageData);
$update = [];
$update['ID'] = $id;
......@@ -152,17 +153,15 @@ function display_page()
$entry->email = $email;
$entry->system = $system;
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
$flash = '<strong>Notification Saved Successfully!</strong><br /><a href=""/wp-admin/admin.php?page=notifications">Click here</a> to view all notifications.</a>';
require_once(__DIR__.'/views/form.php');
} else {
require_once(__DIR__.'/views/form.php');
}
} else {
if (isset($_GET['action']) && $_GET['action'] == "delete") {
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
wp_delete_post($_GET['page_id'], true);
} elseif (isset($_GET['action']) && $_GET['action'] == "archive") {
} elseif (isset($_GET['action']) && $_GET['action'] == 'archive') {
$id = $_GET['page_id'];
$postdata = get_post_meta($id, 'details', true);
......@@ -197,12 +196,12 @@ function display_page()
$system = get_post_meta($id, 'system', true);
$entry->trigger = $details['trigger'];
$entry->status = isset($details['status']) ? $details['status'] : "active";
$entry->status = isset($details['status']) ? $details['status'] : 'active';
$entry->type = $details['type'];
$entry->sendto = $details['sendto'];
$entry->is_email = (($email['text'] != '' || $email['html'] != '')) ? true : false;
$entry->is_system = (isset($system['message']) && $system['message'] != '') ? true : false;
$entry->is_email = (($email['en_text'] != '' || $email['en_html'] != '')) ? true : false;
$entry->is_system = (isset($system['en_message']) && $system['en_message'] != '') ? true : false;
$entry->execute_date = $details['execute_date'];
......@@ -273,28 +272,26 @@ function notification_settings()
function create_notification()
{
/** @var \wpdb $wpdb */
global $wpdb;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type', 'Notification Type', 'required');
$validation->set_rules('title', 'Description', 'trim|required|min_length[16]');
$validation->set_rules('type', 'Notification Type', 'required');
$validation->set_rules('title', 'Description', 'trim|required|min_length[4]');
$validation->set_rules('sendto', 'Send To', 'required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$type_val = ($_POST && $_POST['type'] == 'scheduled') ? 'required' : '';
$validation->set_rules('execute_date', 'Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$trigger_val = ($_POST && $_POST['type'] == 'triggered') ? 'required' : '';
$validation->set_rules('trigger', 'Trigger', $trigger_val);
$validation->set_rules('subject', 'Subject', 'trim');
$validation->set_rules('text', 'Text Version', 'trim|min_length[16]');
$validation->set_rules('html', 'HTML Version', 'trim|min_length[16]');
$validation->set_rules('system_message_type', 'System Message Type', 'trim');
$validation->set_rules('system', 'System Message', 'trim|min_length[16]');
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.'_system', 'System Message', 'trim|min_length[16]');
}
if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) {
$form_error = true;
......@@ -306,7 +303,7 @@ function create_notification()
Tools\tzClean($_POST);
// ok, so now we need to create the notification.
class postTemplate
class PostTemplate
{
var $post_title = '';
var $post_content = '';
......@@ -315,79 +312,84 @@ function create_notification()
var $comment_status = 'closed';
}
//details
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type == "scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type == "scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = [];
$upload_dir = __DIR__.'/uploads/';
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if ($file['name'] != "") {
move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']);
$attachments[] = $file['name'];
// details
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$executeDate = ($type == 'scheduled') ? $_POST['execute_date'] : '0000-00-00 00:00:00';
$trigger = ($type == 'scheduled') ? 'scheduled-cron-job' : $_POST['trigger'];
$emailData = [];
$systemMessageData = [];
foreach (['en', 'fr'] as $lang) {
// email
$subject = $_POST[$lang.'_subject'];
$text = $_POST[$lang.'_text'];
$html = $_POST[$lang.'_html'];
$attachments = [];
$uploadDir = __DIR__.'/../../../uploads/notifications/';
fixFilesArray($_FILES[$lang.'_attachment']);
foreach ($_FILES[$lang.'_attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if ($file['name'] != '') {
move_uploaded_file($file['tmp_name'], $uploadDir.$file['name']);
$attachments[] = $file['name'];
}
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
// system
$systemMessageType = $_POST['system_message_type'];
$system = $_POST[$lang.'_system'];
$emailData = array_merge(
$emailData,
[
$lang.'_subject' => $subject,
$lang.'_text' => $text,
$lang.'_html' => $html,
$lang.'_attachments' => $attachments
]
);
$systemMessageData = array_merge(
$systemMessageData,
[
'system_message_type' => $systemMessageType,
$lang.'_message' => $system
]
);
}
// make post...
$notification = new postTemplate();
$notification = new PostTemplate();
$notification->post_title = $title;
$notification->post_content = "Notification created ".date(
$notification->post_content = 'Notification created '.date(
'Y-m-d H:i:s'
)." --- to be sent on $execute_date";
$notification->post_date_gmt = date("Y-m-d H:i:s", time());
$id = wp_insert_post($notification);
)." --- to be sent on $executeDate";
$notification->post_date_gmt = date('Y-m-d H:i:s', time());
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
$id = wp_insert_post((array)$notification);
add_post_meta(
update_post_meta(
$id,
"details",
'details',
[
'type' => $type,
'sendto' => $sendto,
'status' => 'pending',
'trigger' => $trigger,
'execute_date' => $execute_date
'execute_date' => $executeDate
]
);
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, 'trigger', $trigger);
add_post_meta(
$id,
"email",
[
'subject' => $subject,
'text' => $text,
'html' => $html,
'attachments' => $attachments
]
);
update_post_meta(
$id,
"system",
[
'system_message_type' => $system_message_type,
'message' => $system
]
);
update_post_meta($id, 'email', $emailData);
update_post_meta($id, 'system', $systemMessageData);
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once(__DIR__.'/views/create.php');
......
......@@ -79,7 +79,9 @@ function print_user_notices($showOnlyUnread = false)
}
$system = get_post_meta($notice['notification_id'], 'system', true);
$content = $system['message'];
$content = isset($system[ICL_LANGUAGE_CODE.'_message'])
? $system[ICL_LANGUAGE_CODE.'_message']
: $system['en_message'];
if (isset($notice['args']) && count($notice['args']) > 0) {
foreach ($notice['args'] as $key => $val) {
......@@ -214,6 +216,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
/** @var \wpdb $wpdb */
global $wpdb;
// LANGTODO: get this from the user's preference. As it stands, if an admin triggers this, the notification will be in whatever language the admin is viewing the page as
$lang = ICL_LANGUAGE_CODE;
/** @var \StdClass $notification */
$notification = get_notification_by_trigger($trigger);
......@@ -228,10 +233,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
$notification->status = isset($details['status']) ? $details['status'] : 'active';
$notification->type = $details['type'];
$notification->sendto = @$details['sendto'];
$notification->is_email = (($email['text'] != '' || $email['html'] != '') && $email['subject'] != '')
? true
: false;
$notification->is_system = (isset($system['message']) && $system['message'] != '') ? true : false;
$notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != '');
$notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != '');
// if is_system ==========================================
if ($notification->is_system && $uid != 0) {
......@@ -257,52 +260,59 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
// if is_email ===========================================
if ($notification->is_email) {
if ($uid == 0 && !isset($args['email'])) {
return;
} elseif ($uid == 0 && isset($args['email'])) {
$to_email = $args['email'];
$toEmail = $args['email'];
} else {
$user = new User\Account($uid);
$email_address_preference = get_user_meta($user->ID, 'email_address_preference', true);
if (empty($email_address_preference)) {
$to_email = $user->user_email;
$toEmail = $user->user_email;
} else {
$pp = strtolower($email_address_preference).'_';
$toEmail = get_user_meta($user->ID, $pp.'email', true);
$pp = strtolower($email_address_preference)."_";
$to_email = get_user_meta($user->ID, $pp.'email', true);
if (empty($to_email)) {
$to_email = $user->user_email;
if (empty($toEmail)) {
$toEmail = $user->user_email;
}
}
}
$contents = $email;
$from_email = get_bloginfo('admin_email');
$subject = strip_tags($contents['subject']);
$html = @$contents['html'];
$alttext = strip_tags($contents['text']);
$fromEmail = get_bloginfo('admin_email');
$subject = strip_tags(
isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject'])
? $contents[$lang.'_subject']
: $contents['en_subject']
);
$html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html'])
? $contents[$lang.'_html']
: @$contents['en_html'];
$altText = strip_tags(
isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text'])
? $contents[$lang.'_text']
: $contents['en_text']
);
foreach ($args as $key => $val) {
if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) {
$html = str_replace("{".$key."}", "<a href='".$val."'>".$val."</a>", $html);
$html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html);
} else {
$html = str_replace("{".$key."}", $val, $html);
$alttext = str_replace("{".$key."}", $val, $alttext);
$subject = str_replace("{".$key."}", $val, $subject);
$html = str_replace('{'.$key.'}', $val, $html);
$altText = str_replace('{'.$key.'}', $val, $altText);
$subject = str_replace('{'.$key.'}', $val, $subject);
}
}
$attachments = [];
if (isset($contents['attachments'])) {
$attachments = $contents['attachments'];
}
$att1 = isset($attachments[0]) ? $attachments[0] : '';
$att2 = isset($attachments[1]) ? $attachments[1] : '';
$att3 = isset($attachments[2]) ? $attachments[2] : '';
$attachments = isset($contents[$lang.'_attachments'])
? $contents[$lang.'_attachments']
: $contents['en_attachments'];
$att1 = isset($attachments[0]) ? $attachments[0] : '';
$att2 = isset($attachments[1]) ? $attachments[1] : '';
$att3 = isset($attachments[2]) ? $attachments[2] : '';
$attachments = array_map(
function ($attachmentPath) {
......@@ -313,7 +323,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
$sentSuccessfully = false;
if (CBV\system_can_send_emails()) {
$response = \wpMandrill::mail($to_email, $subject, !empty($html) ? $html : $alttext, [], $attachments);
$response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments);
if (
is_array($response)
&& isset($response[0]['status'])
......@@ -328,10 +338,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
'wp_mail_daemon',
[
'notification_id' => $nid,
'from_email' => $from_email,
'to_email' => $to_email,
'from_email' => $fromEmail,
'to_email' => $toEmail,
'subject' => $subject,
'text' => $alttext,
'text' => $altText,
'html' => $html,
'attachment1' => $att1,
'attachment2' => $att2,
......
......@@ -9,7 +9,7 @@ use Tz\WordPress\Tools\Notifications\Settings;
<div class="wrap">
<h2>Notifications - Create New</h2>
<?php if (isset($flash) && $flash != ""): ?>
<?php if (isset($flash) && $flash != ''): ?>
<div class="post-success">
<?php echo $flash; ?>
</div>
......@@ -231,4 +231,4 @@ use Tz\WordPress\Tools\Notifications\Settings;
jQuery('.scheduled_sendto').show();
}
}
</script>
\ No newline at end of file
</script>
......
......@@ -2,6 +2,7 @@
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__) ?>"/>
......@@ -14,11 +15,15 @@ use Tz\WordPress\Tools\Notifications\Settings;
<?php echo $flash; ?>
</div>
<?php endif; ?>
<?php if ($validation->validation_errors() != "" || isset($form_error)): ?>
<?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>
<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>
<p class="post-errors-content">
You must include either an Email, System or SMS message.
</p>
<?php endif; ?>
</div>
<?php endif; ?>
......@@ -27,7 +32,7 @@ use Tz\WordPress\Tools\Notifications\Settings;
action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id'] ?>">
<input type="hidden" name="_POSTED_" value="yes"/>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<table cellspacing="0" class="widefat post fixed" style="margin-top: 15px;">
<thead>
<tr>
<th width="150">Notification Details</th>
......@@ -43,7 +48,8 @@ use Tz\WordPress\Tools\Notifications\Settings;
<option value="scheduled" <?php echo ($validation->set_value(
'type',
$entry->details['type']
) == 'scheduled') ? 'selected="selected"' : ''; ?>>Scheduled Notification
) == 'scheduled') ? 'selected="selected"' : ''; ?>>
Scheduled Notification
</option>
<?php if (current_user_can(
Settings\MANAGE_SYSTEM_NOTIFICATIONS
......@@ -52,7 +58,8 @@ use Tz\WordPress\Tools\Notifications\Settings;
<option value="triggered" <?php echo ($validation->set_value(
'type',
$entry->details['type']
) == 'triggered') ? 'selected="selected"' : ''; ?>>System Triggered Notification
) == 'triggered') ? 'selected="selected"' : ''; ?>>
System Triggered Notification
</option>
<?php endif; ?>
</select>
......@@ -61,11 +68,13 @@ use Tz\WordPress\Tools\Notifications\Settings;
</tr>
<tr>
<td width="150">Notification Description</td>
<td><input type="text" name="title" class="wide-input-field"
<td>
<input type="text" name="title" class="wide-input-field"
value="<?php echo $validation->set_value(
'title',
$entry->post_title
); ?>"/><?php echo $validation->form_error('title'); ?></td>
); ?>"/><?php echo $validation->form_error('title'); ?>
</td>
</tr>
<tr class="scheduled_sendto">
<td>Sent To:</td>
......@@ -80,7 +89,8 @@ use Tz\WordPress\Tools\Notifications\Settings;
<option value="allusers" <?php echo ($validation->set_value(
'sendto',
$entry->details['sendto']
) == 'allusers') ? 'selected="selected"' : ''; ?>>All Users
) == 'allusers') ? 'selected="selected"' : ''; ?>>
All Users
</option>
<optgroup label="By Group:">
<?php foreach (Notifications\getGroups() as $group_id => $group_name): ?>
......@@ -101,146 +111,194 @@ 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"
<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',
$entry->details['execute_date']
); ?>"/><?php echo $validation->form_error('execute_date'); ?></td>
); ?>"/><?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"
<td>
<input type="text" name="trigger" id="trigger" class="wide-input-field"
value="<?php echo $validation->set_value(
'trigger',
$entry->details['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',
$entry->email['subject']
) != '' || $validation->set_value('text', $entry->email['text']) != '' || $validation->set_value(
'html',
$entry->email['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',
$entry->email['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',
$entry->email['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',
$entry->email['html']
); ?></textarea><?php echo $validation->form_error('html'); ?></td>
</tr>
<tr>
<td width="150">Attachments</td>
<td>&nbsp;</td>
</tr>
<?php
$attachements = $entry->email['attachments'];
$allowed_attachments = 3;
foreach ($attachements 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 $allowed_attachments--; endforeach; ?>
<?php for ($a = 1; $a <= $allowed_attachments; $a++): ?>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="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('system', $entry->system['message']) == "") ? "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',
$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 echo $validation->form_error('trigger'); ?>
</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',
isset($entry->system['message'])
? $entry->system['message']
: ""
); ?></textarea><?php echo $validation->form_error('system'); ?></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>
<?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 ($validation->set_value(
$lang.'_subject',
$entry->email[$lang.'_subject']
) != '' || $validation->set_value(
$lang.'_text',
$entry->email[$lang.'_text']
) != '' || $validation->set_value(
$lang.'_html',
$entry->email[$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 $validation->set_value(
$lang.'_subject',
$entry->email[$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 $validation->set_value(
$lang.'_text',
$entry->email[$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 $validation->set_value(
$lang.'_html',
$entry->email[$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>
<input type="submit" value=" Update "/><input type="button" value=" Cancel "
onclick="document.location.href='/wp-admin/admin.php?page=notifications';"/>
<input type="submit" value=" Update "/>
<input type="button" value=" Cancel "
onclick="document.location.href='/wp-admin/admin.php?page=notifications';"/>
</p>
</form>
......@@ -249,6 +307,13 @@ use Tz\WordPress\Tools\Notifications\Settings;
<script>
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();
updateNotificationType();
$('.attachment').live('click', function (e) {
......@@ -292,7 +357,6 @@ use Tz\WordPress\Tools\Notifications\Settings;
jQuery('tbody', $table).fadeIn();
}
});
});
function updateNotificationType() {
......@@ -313,4 +377,4 @@ use Tz\WordPress\Tools\Notifications\Settings;
});
}
}
</script>
\ No newline at end of file
</script>
......