919ef20b by Insu Mun

Add language selection for new notification page.

1 parent 7cc54a60
...@@ -132,7 +132,8 @@ function display_page() ...@@ -132,7 +132,8 @@ function display_page()
132 ); 132 );
133 update_post_meta($id, 'send_status', $entry->details['status']); 133 update_post_meta($id, 'send_status', $entry->details['status']);
134 update_post_meta($id, 'notif_type', $type); 134 update_post_meta($id, 'notif_type', $type);
135 update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate)); 135 // update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
136 update_post_meta($id, 'execute_date', strtotime($executeDate));
136 update_post_meta($id, 'trigger', $trigger); 137 update_post_meta($id, 'trigger', $trigger);
137 138
138 update_post_meta($id, 'email', $emailData); 139 update_post_meta($id, 'email', $emailData);
...@@ -288,15 +289,17 @@ function create_notification() ...@@ -288,15 +289,17 @@ function create_notification()
288 289
289 foreach (['en', 'fr'] as $lang) { 290 foreach (['en', 'fr'] as $lang) {
290 $validation->set_rules($lang.'_subject', 'Subject', 'trim'); 291 $validation->set_rules($lang.'_subject', 'Subject', 'trim');
291 $validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]'); 292 // $validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]');
292 $validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]'); 293 // $validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]');
294 $validation->set_rules($lang.'_text', 'Text Version', 'trim');
295 $validation->set_rules($lang.'_html', 'HTML Version', 'trim');
293 $validation->set_rules($lang.'_system', 'System Message', 'trim|min_length[16]'); 296 $validation->set_rules($lang.'_system', 'System Message', 'trim|min_length[16]');
294 } 297 }
295 298
296 if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) { 299 // if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) {
297 $form_error = true; 300 // $form_error = true;
298 require_once(__DIR__.'/views/create.php'); 301 // require_once(__DIR__.'/views/create.php');
299 } else { 302 // } else {
300 if ($validation->run() == true) { 303 if ($validation->run() == true) {
301 304
302 // Clean up the data before saving 305 // Clean up the data before saving
...@@ -385,7 +388,9 @@ function create_notification() ...@@ -385,7 +388,9 @@ function create_notification()
385 ); 388 );
386 update_post_meta($id, 'send_status', 'pending'); 389 update_post_meta($id, 'send_status', 'pending');
387 update_post_meta($id, 'notif_type', $type); 390 update_post_meta($id, 'notif_type', $type);
388 update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate)); 391 // update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate));
392 update_post_meta($id, 'execute_date', strtotime($executeDate));
393
389 update_post_meta($id, 'trigger', $trigger); 394 update_post_meta($id, 'trigger', $trigger);
390 395
391 update_post_meta($id, 'email', $emailData); 396 update_post_meta($id, 'email', $emailData);
...@@ -396,5 +401,5 @@ function create_notification() ...@@ -396,5 +401,5 @@ function create_notification()
396 } else { 401 } else {
397 require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php'); 402 require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php');
398 } 403 }
399 } 404 // }
400 } 405 }
......
...@@ -309,7 +309,6 @@ class Validation ...@@ -309,7 +309,6 @@ class Validation
309 309
310 // Did we end up with any errors? 310 // Did we end up with any errors?
311 $total_errors = count($this->_error_array); 311 $total_errors = count($this->_error_array);
312
313 if ($total_errors > 0) { 312 if ($total_errors > 0) {
314 $this->_safe_form_data = true; 313 $this->_safe_form_data = true;
315 } 314 }
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
2 use Tz\WordPress\Tools; 2 use Tz\WordPress\Tools;
3 use Tz\WordPress\Tools\Notifications; 3 use Tz\WordPress\Tools\Notifications;
4 use Tz\WordPress\Tools\Notifications\Settings; 4 use Tz\WordPress\Tools\Notifications\Settings;
5
6 function getInputFormValues($validation, $name) {
7 return ($validation->set_value($name) != '') ? $validation->set_value($name) : (!empty($_POST[$name])) ? $_POST[$name] : '';
8 }
9
5 ?> 10 ?>
6 11
7 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/> 12 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
...@@ -40,12 +45,12 @@ use Tz\WordPress\Tools\Notifications\Settings; ...@@ -40,12 +45,12 @@ use Tz\WordPress\Tools\Notifications\Settings;
40 <td> 45 <td>
41 <select name="type" id="notif_type" class="wide-input-field" 46 <select name="type" id="notif_type" class="wide-input-field"
42 onchange="updateNotificationType();"> 47 onchange="updateNotificationType();">
43 <option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled") 48 <option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled" || $_POST['type'] == 'scheduled')
44 ? 'selected="selected"' : ""; ?>>Scheduled Notification 49 ? 'selected="selected"' : ""; ?>>Scheduled Notification
45 </option> 50 </option>
46 51
47 <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> 52 <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
48 <option value="triggered" <?php echo ($validation->set_value('type') == "triggered") 53 <option value="triggered" <?php echo ($validation->set_value('type') == "triggered" || $_POST['type'] == 'triggered')
49 ? 'selected="selected"' : ""; ?>>System Triggered Notification 54 ? 'selected="selected"' : ""; ?>>System Triggered Notification
50 </option> 55 </option>
51 <?php endif; ?> 56 <?php endif; ?>
...@@ -56,9 +61,9 @@ use Tz\WordPress\Tools\Notifications\Settings; ...@@ -56,9 +61,9 @@ use Tz\WordPress\Tools\Notifications\Settings;
56 <tr> 61 <tr>
57 <td width="150">Notification Description</td> 62 <td width="150">Notification Description</td>
58 <td><input type="text" name="title" class="wide-input-field" 63 <td><input type="text" name="title" class="wide-input-field"
59 value="<?php echo $validation->set_value( 64 value="<?php echo getInputFormValues($validation, 'title'); ?>"/>
60 'title' 65 <?php echo $validation->form_error('title'); ?>
61 ); ?>"/><?php echo $validation->form_error('title'); ?></td> 66 </td>
62 </tr> 67 </tr>
63 <tr class="scheduled_sendto"> 68 <tr class="scheduled_sendto">
64 <td>Sent To:</td> 69 <td>Sent To:</td>
...@@ -83,107 +88,167 @@ use Tz\WordPress\Tools\Notifications\Settings; ...@@ -83,107 +88,167 @@ use Tz\WordPress\Tools\Notifications\Settings;
83 <tr class="scheduled-extended"> 88 <tr class="scheduled-extended">
84 <td>Execute Date / Time</td> 89 <td>Execute Date / Time</td>
85 <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" 90 <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick"
86 readonly="readonly" value="<?php echo $validation->set_value( 91 readonly="readonly" value="<?php echo getInputFormValues($validation, 'execute_date'); ?>"/><?php echo $validation->form_error('execute_date'); ?></td>
87 'execute_date'
88 ); ?>"/><?php echo $validation->form_error('execute_date'); ?></td>
89 </tr> 92 </tr>
90 93
91 <tr class="trigger-extended"> 94 <tr class="trigger-extended">
92 <td>Trigger</td> 95 <td>Trigger</td>
93 <td><input type="text" name="trigger" id="trigger" class="wide-input-field" 96 <td><input type="text" name="trigger" id="trigger" class="wide-input-field"
94 value="<?php echo $validation->set_value( 97 value="<?php echo getInputFormValues($validation, 'trigger'); ?>"/>
95 'trigger' 98 <?php echo $validation->form_error('trigger'); ?></td>
96 ); ?>"/><?php echo $validation->form_error('trigger'); ?></td>
97 </tr> 99 </tr>
98 100
99 </tbody> 101 </tbody>
100 </table> 102 </table>
101 103
102 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> 104 <div id="tabs">
103 <thead> 105 <ul>
104 <tr> 106 <li>
105 <th width="150" class="toggle"><h6>Email</h6></th> 107 <a href="#tab-1">English</a>
106 <th class="action-bar">&nbsp;</th> 108 </li>
107 </tr> 109 <li>
108 </thead> 110 <a href="#tab-2">French</a>
109 <tbody style="<?php echo ($validation->set_value('subject') != "" || $validation->set_value( 111 </li>
110 'text' 112 </ul>
111 ) != "" || $validation->set_value('html') != "") ? "" : "display:none"; ?>;">
112 <tr>
113 <td width="150">Subject Line</td>
114 <td><input type="text" name="subject" class="wide-input-field" style="width:100%;"
115 value="<?php echo $validation->set_value(
116 'subject'
117 ); ?>"/><?php echo $validation->form_error('subject'); ?></td>
118 </tr>
119 <tr>
120 <td>Text Version</td>
121 <td><textarea name="text" class="wide-input-field" rows="10"
122 style="width:100%;"><?php echo $validation->set_value(
123 'text'
124 ); ?></textarea><?php echo $validation->form_error('text'); ?></td>
125 </tr>
126 <tr>
127 <td>HTML Version (optional)</td>
128 <td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10"
129 style="width:100%;"><?php echo $validation->set_value(
130 'html'
131 ); ?></textarea><?php echo $validation->form_error('html'); ?></td>
132 </tr>
133 <tr>
134 <td width="150">Attachments</td>
135 <td><input type="file" name="attachment[]"/></td>
136 </tr>
137 <tr>
138 <td>&nbsp;</td>
139 <td><input type="file" name="attachment[]"/></td>
140 </tr>
141 <tr>
142 <td>&nbsp;</td>
143 <td><input type="file" name="attachment[]"/></td>
144 </tr>
145 </tbody>
146 </table>
147 113
148 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> 114 <?php foreach (['en', 'fr'] as $index => $lang): ?>
149 <thead> 115 <div id="tab-<?php echo $index + 1; ?>">
150 <tr> 116 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top: 15px;">
151 <th width="150" class="toggle"><h6>System Message</h6></th> 117 <thead>
152 <th class="action-bar">&nbsp;</th> 118 <tr>
153 </tr> 119 <th width="150" class="toggle"><h6>Email</h6></th>
154 </thead> 120 <th class="action-bar">&nbsp;</th>
155 <tbody style="<?php echo ($validation->set_value('system') == "") ? "display:none" : ""; ?>;"> 121 </tr>
156 <tr> 122 </thead>
157 <td>Message Type</td> 123 <tbody style="<?php echo (getInputFormValues($validation, $lang . '_subject')) ||
158 <td> 124 getInputFormValues($validation, $lang . '_text') ||
159 <select name="system_message_type" class="wide-input-field"> 125 getInputFormValues($validation, $lang . '_html') ? '' : 'display: none;'; ?>;">
160 <option value="none" <?php echo ($validation->set_value('system_message_type') == "none") 126 <tr>
161 ? 'selected="selected"' : ""; ?>>General Message 127 <td width="150">Subject Line</td>
162 </option> 128 <td>
163 <option value="action_required" <?php echo ($validation->set_value( 129 <input type="text" name="<?php echo $lang; ?>_subject"
164 'system_message_type' 130 class="wide-input-field" style="width: 100%;"
165 ) == "action_required") ? 'selected="selected"' : ""; ?>>Action Required 131 value="<?php echo getInputFormValues($validation, $lang . '_subject'); ?>"/>
166 </option> 132 <?php echo $validation->form_error($lang.'_subject'); ?>
167 <option value="e-flash" <?php echo ($validation->set_value( 133 </td>
168 'system_message_type' 134 </tr>
169 ) == "e-flash") ? 'selected="selected"' : ""; ?>>E-Flash 135 <tr>
170 </option> 136 <td>Text Version</td>
171 <option value="new_event" <?php echo ($validation->set_value( 137 <td>
172 'system_message_type' 138 <textarea name="<?php echo $lang; ?>_text"
173 ) == "new_event") ? 'selected="selected"' : ""; ?>>New Event 139 class="wide-input-field" rows="10"
174 </option> 140 style="width: 100%;"><?php echo getInputFormValues($validation, $lang . '_text'); ?>
175 </select> 141 </textarea><?php echo $validation->form_error($lang.'_text'); ?>
176 </td> 142 </td>
177 </tr> 143 </tr>
178 <tr> 144 <tr>
179 <td>Message (Text/HTML)</td> 145 <td>HTML Version (optional)</td>
180 <td><textarea name="system" class="wide-input-field" rows="4" 146 <td>
181 style="width:100%;"><?php echo $validation->set_value( 147 <textarea name="<?php echo $lang; ?>_html"
182 'system' 148 id="htmlversion" class="wide-input-field" rows="10"
183 ); ?></textarea><?php echo $validation->form_error('system'); ?></td> 149 style="width: 100%;"><?php echo getInputFormValues($validation, $lang . '_html'); ?>
184 </tr> 150 </textarea><?php echo $validation->form_error($lang.'_html'); ?>
185 </tbody> 151 </td>
186 </table> 152 </tr>
153
154 <tr>
155 <td width="150">Attachments</td>
156 <td>&nbsp;</td>
157 </tr>
158
159 <?php
160 $attachments = $entry->email[$lang.'_attachments'];
161 $allowedAttachments = 3;
162 foreach ($attachments as $attachment): ?>
163 <tr>
164 <td>&nbsp;</td>
165 <td>
166 <?php echo $attachment; ?> &nbsp; (<a href="#"
167 entry_id="<?php echo $_GET['page_id'] ?>"
168 class="attachment"
169 rel="<?php echo $attachment; ?>">remove</a>)
170 </td>
171 </tr>
172 <?php
173 $allowedAttachments--;
174 endforeach;
175 ?>
176
177 <?php for ($a = 1; $a <= $allowedAttachments; $a++): ?>
178 <tr>
179 <td>&nbsp;</td>
180 <td><input type="file" name="<?php echo $lang; ?>_attachment[]"/></td>
181 </tr>
182 <?php endfor; ?>
183
184 </tbody>
185 </table>
186
187 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top: 15px;">
188 <thead>
189 <tr>
190 <th width="150" class="toggle"><h6>System Message</h6></th>
191 <th class="action-bar">&nbsp;</th>
192 </tr>
193 </thead>
194 <tbody style="<?php echo ($validation->set_value(
195 $lang.'_system',
196 $entry->system[$lang.'_message']
197 ) == '')
198 ? 'display: none'
199 : ''; ?>;">
200 <tr>
201 <td>Message Type</td>
202 <td>
203 <?php if ($lang == 'en'): ?>
204 <select name="system_message_type" class="wide-input-field">
205 <option value="none" <?php echo ($validation->set_value(
206 'system_message_type',
207 $entry->system['system_message_type']
208 ) == 'none') ? 'selected="selected"' : ''; ?>>
209 General Message
210 </option>
211 <option value="action_required" <?php echo ($validation->set_value(
212 'system_message_type',
213 $entry->system['system_message_type']
214 ) == 'action_required') ? 'selected="selected"' : ''; ?>>
215 Action Required
216 </option>
217 <option value="e-flash" <?php echo ($validation->set_value(
218 'system_message_type',
219 $entry->system['system_message_type']
220 ) == 'e-flash') ? 'selected="selected"' : ''; ?>>
221 E-Flash
222 </option>
223 <option value="new_event" <?php echo ($validation->set_value(
224 'system_message_type',
225 $entry->system['system_message_type']
226 ) == 'new_event') ? 'selected="selected"' : ''; ?>>
227 New Event
228 </option>
229 </select>
230 <?php else: ?>
231 <span class="system_message_type_value"></span>
232 <?php endif; ?>
233 </td>
234 </tr>
235 <tr>
236 <td>Message (Text/HTML)</td>
237 <td>
238 <textarea name="<?php echo $lang; ?>_system" class="wide-input-field" rows="4"
239 style="width:100%;"><?php echo $validation->set_value(
240 $lang.'_system',
241 isset($entry->system[$lang.'_message'])
242 ? $entry->system[$lang.'_message']
243 : ''
244 ); ?></textarea><?php echo $validation->form_error($lang.'_system'); ?>
245 </td>
246 </tr>
247 </tbody>
248 </table>
249 </div>
250 <?php endforeach; ?>
251 </div>
187 252
188 253
189 <p> 254 <p>
...@@ -197,15 +262,54 @@ use Tz\WordPress\Tools\Notifications\Settings; ...@@ -197,15 +262,54 @@ use Tz\WordPress\Tools\Notifications\Settings;
197 </div> 262 </div>
198 263
199 <script> 264 <script>
200 jQuery(document).ready(function () { 265 jQuery(document).ready(function ($) {
201 jQuery('#execute_date').datetimepicker({ 266 $('#tabs').tabs();
202 stepMinute: 30, 267
203 dateFormat: 'yy-mm-dd', 268 // Update system message type clone when changing the message type
204 timeFormat: 'hh:mm:ss' 269 $('[name="system_message_type"]').change(function () {
205 }); 270 $('.system_message_type_value').text($(this).find(':selected').text());
271 }).change();
272
273 //
274 // jQuery('#execute_date').datetimepicker({
275 // stepMinute: 30,
276 // dateFormat: 'yy-mm-dd',
277 // timeFormat: 'hh:mm:ss'
278 // });
206 279
207 updateNotificationType(); 280 updateNotificationType();
208 281
282 $('.attachment').live('click', function (e) {
283 e.preventDefault();
284 var $link = $(this);
285 var options = {
286 action: 'remove_attachment',
287 ajax: 'yes',
288 id: $link.attr('entry_id'),
289 file: $link.attr('rel')
290 };
291
292 var file_element = '<input type="file" name="attachment[]" />';
293
294 var c = confirm('Are you sure you want to remove this attachment?');
295 if (c) {
296 $.ajax({
297 url: '/wp-admin/admin-ajax.php',
298 data: (options),
299 type: 'POST',
300 dataType: 'json',
301
302 success: function (data) {
303 if (data.success == "true") {
304 $link.parent().html(file_element);
305 }
306 }
307 });
308 }
309
310 return false;
311 });
312
209 jQuery('table.expandable thead th').click(function () { 313 jQuery('table.expandable thead th').click(function () {
210 var $table = jQuery(this).parent().parent().parent(); 314 var $table = jQuery(this).parent().parent().parent();
211 if (jQuery('tbody', $table).is(':visible')) { 315 if (jQuery('tbody', $table).is(':visible')) {
...@@ -229,6 +333,11 @@ use Tz\WordPress\Tools\Notifications\Settings; ...@@ -229,6 +333,11 @@ use Tz\WordPress\Tools\Notifications\Settings;
229 jQuery('.scheduled-extended').show(); 333 jQuery('.scheduled-extended').show();
230 jQuery('.trigger-extended').hide(); 334 jQuery('.trigger-extended').hide();
231 jQuery('.scheduled_sendto').show(); 335 jQuery('.scheduled_sendto').show();
336
337 jQuery('#execute_date').datetimepicker({
338 format: 'Y-m-d, H:i',
339 defaultDate: new Date()
340 });
232 } 341 }
233 } 342 }
234 </script> 343 </script>
......