Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
inbox_edit_fns.inc
1 <?php
2 
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
20 
34 {
35 
36 
41  function Inbox_Edit_Fns()
42  {
43  $this->Asset_Edit_Fns();
44 
45  $this->static_screens = Array ('details' => Array ('name' => translate('inbox'), 'use_tab' => TRUE, 'force_unlock' => FALSE, 'lock_type' => 'mail',),);
46 
47  }//end constructor
48 
49 
60  function paintNewMessage(&$asset, &$o, $prefix)
61  {
62  $user = $asset->_getUser();
63 
64  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
65  $messages = $ms->getMessages($user->id, NULL, Array (SQ_MSG_UNREAD, SQ_MSG_READ), Array (), NULL, NULL, 'name');
66  $write_access = $asset->writeAccess('mail');
67  if ($write_access) {
68 ?>
69  <style type="text/css">
70  @import url(<?php echo sq_web_path('data')?>/asset_types/inbox/css/inbox.css.php);
71  </style>
72 
73  <table border="0" cellspacing="2" cellpadding="2" width="100%">
74  <tr>
75  <td valign="top"><?php echo translate('to'); ?>:</td>
76  <td>
77  <?php multiple_asset_finder($prefix.'_To', Array(), Array('user' => 'D')); ?>
78  </td>
79  </tr>
80  <tr>
81  <td valign="top"><?php echo translate('subject'); ?>:</td>
82  <td>
83  <input type="text" id="<?php echo $prefix; ?>_Subject" name="<?php echo $prefix; ?>_Subject" style="width:300px" />
84  </td>
85  </tr>
86  <tr>
87  <td valign="top"><?php echo translate('priority'); ?>:</td>
88  <td>
89  <select id="<?php echo $prefix; ?>_Priority" name="<?php echo $prefix; ?>_Priority" style="float:left; width: 100px;">
90  <option value="1"><?php echo translate('highest'); ?></option>
91  <option value="2"><?php echo translate('high'); ?></option>
92  <option value="3" selected="selected"><?php echo translate('standard'); ?></option>
93  <option value="4"><?php echo translate('low'); ?></option>
94  <option value="5"><?php echo translate('lowest'); ?></option>
95  </select>
96  </td>
97  </tr>
98  <tr>
99  <td colspan="2">
100  <textarea cols="3" rows="3" style="clear:both; width: 95%; height: 250px" id="<?php echo $prefix; ?>_Content" name="<?php echo $prefix; ?>_Content"></textarea>
101  </td>
102  </tr>
103  </table>
104  <?php
105 
106  } else {
107 ?>
108  <div style="text-align: center"><?php echo translate('inbox_lock'); ?></div>
109  <?php
110 
111  }
112 
113  return $write_access;
114 
115  }//end paintNewMessage()
116 
117 
128  function processNewMessage(&$asset, &$o, $prefix)
129  {
130  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
131  // send the message
132  $noaction = TRUE;
133  if (isset ($_POST[$prefix.'_To'])) {
134  $userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
135 
136  $recepients = Array ();
137  foreach ($_POST[$prefix.'_To'] as $key => $sender) {
138  $recepients[] = $sender['assetid'];
139  }
140 
141  $msg_reps = Array(
142  'subject' => $_POST[$prefix.'_Subject'],
143  'body' => $_POST[$prefix.'_Content'],
144  );
145 
146  $message = $ms->newMessage($recepients, 'inbox.message', $msg_reps);
147  $message->priority = $_POST[$prefix.'_Priority'];
148  $message->send();
149 
150  foreach ($recepients as $key => $sender) {
151  if (empty ($sender)) continue;
152  $noaction = TRUE;
153  $message = $ms->newMessage(Array ($userid), 'inbox.sent', $msg_reps);
154  $message->from = $sender;
155  $message->status = 'R';
156  $message->priority = $_POST[$prefix.'_Priority'];
157  $message->send();
158  }
159 
160  }
161  if ($noaction) echo '<!-- ###No Action### -->';
162 
163  }//end processNewMessage()
164 
165 
176  function paintSent(&$asset, &$o, $prefix)
177  {
178  $user = $asset->_getUser();
179 
180  $priority = Array ('', 'Highest', 'High', 'Normal', 'Low', 'Lowest');
181 
182  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
183  $messages = $ms->getMessages($user->id, NULL, Array (SQ_MSG_UNREAD, SQ_MSG_READ), Array (), NULL, NULL, 'name');
184  $write_access = $asset->writeAccess('mail');
185  $num_messages = count($messages);
186 ?>
187  <style type="text/css">
188  @import url(<?php echo sq_web_path('data')?>/asset_types/inbox/css/inbox.css.php);
189  </style>
190  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/js/JsHttpConnector.js"></script>
191  <script type="text/javascript">
192  //<![CDATA[
193  var prefix = "<?php echo $prefix; ?>";
194  var Bodies = new Object();
195  //]]>
196  </script>
197  <script type="text/javascript" src="<?php echo sq_web_path('data'); ?>/asset_types/inbox/js/inbox.js"></script>
198  <div id="inbox_container">
199  <table border="0" cellspacing="0" cellpadding="1" width="100%" id="inbox_table">
200  <tr>
201  <td class="sq-backend-table-header"><?php echo strtoupper(translate('to')); ?></td>
202  <td class="sq-backend-table-header"><?php echo strtoupper(translate('subject')); ?></td>
203  <td class="sq-backend-table-header"><?php echo strtoupper(translate('sent')); ?></td>
204  <?php
205 
206  if ($write_access) {
207 ?>
208  <td class="sq-backend-table-header">
209  <?php check_box($prefix.'_delete_all', '1', FALSE, 'changeAllDelStatuses(this.checked)'); ?>
210  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="trashIcon" class="trash" onclick="changeAllStatuses()" />
211  <?php echo strtoupper(translate('delete')); ?>
212  </td>
213  <?php
214 
215  }
216 ?>
217  </tr>
218  <?php
219 
220 
221  for ($i = 0; $i < $num_messages; $i ++) {
222 
223  $data = $messages[$i];
224  if ($data['type'] != 'inbox.sent') continue;
225 
226  // work out the sender icon
227  $sender_img = $GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($data['type_code']);
228  // work out the message body
229  $body = preg_replace("/[\n\t\r]/im", '<br />', $data['body']);
230  $body = str_replace('"', '&quot;', $body);
231 ?>
232  <script type="text/javascript">
233  //<![CDATA[
234  Bodies["<?php echo $data['msgid'];?>"] = "<?php echo $body; ?>";
235  //]]>
236  </script>
237  <tr>
238  <td class="sq-backend-table-cell" nowrap="nowrap" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
239  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/internal_message/priority_'.$data['priority'].'.png', 16, 16, '', $priority[$data['priority']].' priority') ?>
240  <?php sq_print_icon($sender_img, 16, 16) ?>
241  <a name="msg_<?php echo $data['msgid'];?>"></a>
242  &nbsp;<?php echo $data['from_name'];?>
243  <?php hidden_field($prefix.'_messages['.$data['msgid'].']', '1'); ?>
244  </td>
245  <td class="sq-backend-table-cell" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
246  &nbsp;<?php echo $data['subject'];?>
247  </td>
248  <td class="sq-backend-table-cell" nowrap="nowrap" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
249  &nbsp;<?php echo $GLOBALS['SQ_SYSTEM']->datetime($data['sent']); ?>
250  </td>
251  <?php
252 
253  if ($write_access) {
254 ?>
255  <td class="sq-backend-table-cell" nowrap="nowrap">
256  <?php check_box($prefix.'_delete['.$data['msgid'].']', '1', FALSE, 'changeStatus('.$data['msgid'].')'); ?>
257  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="trashIcon<?php echo $data['msgid'];?>" class="trash" onclick="changeStatus('<?php echo $data['msgid'];?>')" />
258  </td>
259  <?php
260 
261  }
262 ?>
263  </tr>
264  <?php
265 
266  }//end for - each message
267 ?>
268  </table>
269  </div>
270  <div id="sq_message_body"></div>
271  <?php
272 
273 
274  return $write_access;
275 
276  }//end paintSent()
277 
278 
289  function processSent(&$asset, &$o, $prefix)
290  {
291  $delete = (isset ($_POST[$prefix.'_delete'])) ? array_keys($_POST[$prefix.'_delete']) : Array();
292 
293  if (empty($delete)) {
294  return;
295  }
296 
297  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
298 
299  foreach ($delete as $messageid) {
300  // delete message
301  $message = $ms->getMessageById($messageid);
302  if (!$message->updateStatus(SQ_MSG_DELETED)) {
303  trigger_localised_error('CORE0063', E_USER_WARNING, $messageid);
304  }
305  }
306 
307  return TRUE;
308 
309  }//end processSent()
310 
311 
322  function paintInbox(&$asset, &$o, $prefix)
323  {
324  $user = $asset->_getUser();
325 
326  $priority = Array ('', 'Highest', 'High', 'Normal', 'Low', 'Lowest');
327 
328  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
329  $messages = $ms->getMessages($user->id, NULL, Array (SQ_MSG_UNREAD, SQ_MSG_READ), Array (), NULL, NULL, 'name');
330  $write_access = $asset->writeAccess('mail');
331 
332  $allread = TRUE;
333  $num_messages = count($messages);
334  $num_sent = 0;
335  $num_inbox = 0;
336  for ($i = 0; $i < $num_messages; $i ++) {
337  $data = $messages[$i];
338  if ($data['status'] == SQ_MSG_UNREAD) {
339  $allread = FALSE;
340  }
341  if ($data['type'] == 'inbox.sent') {
342  $num_sent ++;
343  } else {
344  $num_inbox ++;
345  }
346  }
347 ?>
348  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/js/JsHttpConnector.js"></script>
349  <script type="text/javascript">
350  //<![CDATA[
351  var prefix = "<?php echo urlencode($prefix); ?>";
352  var Bodies = new Object();
353  //]]>
354  </script>
355  <script type="text/javascript" src="<?php echo sq_web_path('data'); ?>/asset_types/inbox/js/inbox.js"></script>
356  <style type="text/css">
357  @import url(<?php echo sq_web_path('data')?>/asset_types/inbox/css/inbox.css.php);
358  </style>
359  <div id="inbox_container">
360  <?php
361 
362  if ($num_inbox == 0) {
363  echo '<div style="text-align: center">Your inbox is empty.</div></div>';
364  } else {
365  $num_per_page = $GLOBALS['SQ_SYSTEM']->getUserPrefs('inbox', 'SQ_INBOX_MAIL_PER_PAGE');
366  if (empty($num_per_page)) $num_per_page = 20;
367  $total_assets = $num_inbox;
368  $num_pages = ceil($total_assets / $num_per_page);
369 
370  $link_offset = array_get_index($_POST, $prefix.'_link_offset', 0);
371 
372  // if the page number is greater to the total of pages
373  if ( (round(($link_offset + $num_per_page) / $num_per_page)) > (ceil($total_assets / $num_per_page)) ) {
374  $link_offset = (ceil($total_assets / $num_per_page)-1)*$num_per_page;
375  }
376 ?>
377  <!-- start print pagination bar top -->
378  <table class="sq-backend-table">
379  <tr><td class="sq-backend-table-header-header"><b>
380  <?php
381  hidden_field($prefix.'_link_offset', $link_offset);
382  if ($link_offset > 0) {
383  ?>
384  <a title="<?php echo translate('pagination_go_to_first') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '0'); set_hidden_field('process_form', '0'); submit_form(); return false;">
385  <?php
386  } else {
387  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
388  }
389  ?>
390  &lt;&lt;
391  <?php
392  if ($link_offset > 0) {
393  ?></a><?php
394  } else {
395  ?></span><?php
396  }
397  ?> &nbsp; &nbsp; <?php
398  if ($link_offset > 0) {
399  ?><a title="<?php echo translate('pagination_go_to_previous') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset - $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
400  } else {
401  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
402  }
403  ?>
404  &lt;
405  <?php
406  if ($link_offset > 0) {
407  ?></a><?php
408  } else {
409  ?></span><?php
410  }
411  ?>
412  &nbsp; &nbsp; <?php echo translate('page_number', round(($link_offset + $num_per_page) / $num_per_page), ceil($total_assets / $num_per_page)); ?> &nbsp; &nbsp;
413  <?php
414  if (($link_offset + $num_per_page) < $total_assets) {
415  ?><a title="<?php echo translate('pagination_go_to_next') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset + $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
416  } else {
417  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
418  }
419  ?>
420  &gt;
421  <?php
422  if (($link_offset + $num_per_page) < $total_assets) {
423  ?></a><?php
424  } else {
425  ?></span><?php
426  }
427  ?> &nbsp; &nbsp; <?php
428  if (($link_offset + $num_per_page) < $total_assets) {
429  ?><a title="<?php echo translate('pagination_go_to_last') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo ($num_pages - 1) * $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
430  } else {
431  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
432  }
433  ?>
434  &gt;&gt;
435  <?php
436  if (($link_offset + $num_per_page) < $total_assets) {
437  ?></a><?php
438  } else {
439  ?></span><?php
440  }
441  ?>
442  </b></td><tr>
443  </table>
444  <!-- end print pagination bar -->
445  <table border="0" cellspacing="0" cellpadding="1" id="inbox_table">
446  <tr>
447  <td class="sq-backend-table-header"><?php echo strtoupper(translate('from')); ?></td>
448  <td class="sq-backend-table-header"><?php echo strtoupper(translate('subject')); ?></td>
449  <td class="sq-backend-table-header"><?php echo strtoupper(translate('sent')); ?></td>
450  <td class="sq-backend-table-header">
451  <?php
452 
453  if ($write_access) {
454 ?>
455  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="letterIcon" class="read" />
456  <?php
457 
458  }
459 ?>
460  &nbsp;<?php echo strtoupper(translate('read')); ?>
461  </td>
462  <?php
463 
464  if ($write_access) {
465 ?>
466  <td class="sq-backend-table-header">
467  <?php check_box($prefix.'_delete_all', '1', FALSE, 'changeAllDelStatuses(this.checked)'); ?>
468  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="trashIcon" class="trash" />
469  <?php echo strtoupper(translate('delete')); ?>
470  </td>
471  <?php
472 
473  }
474 ?>
475  </tr>
476  <?php
477 
478  $total_assets = 0;
479  for ($i = 0; $i < $num_messages; $i ++) {
480 
481  $data = $messages[$i];
482  if ($data['type'] == 'inbox.sent') continue;
483 
484  if (($total_assets < $link_offset) || (($link_offset+$num_per_page-1) < $total_assets)) {
485  $total_assets++;
486  continue;
487  }
488 
489  // work out the sender icon
490  $sender_img = $GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($data['type_code']);
491  $body = preg_replace("/[\n\t\r]/im", '<br />', $data['body']);
492  $body = str_replace('"', '\"', $body);
493 ?>
494  <script type="text/javascript">
495  //<![CDATA[
496  // adding body text of the messages into JS array.
497  Bodies["<?php echo $data['msgid'];?>"] = "<?php echo $body; ?>";
498  //]]>
499  </script>
500  <tr>
501  <td class="sq-backend-table-cell" nowrap="nowrap" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
502  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/internal_message/priority_'.$data['priority'].'.png', 16, 16, '', $priority[$data['priority']].' priority') ?>
503  <?php sq_print_icon($sender_img, 16, 16) ?>
504  <a name="msg_<?php echo $data['msgid'];?>"></a>
505  &nbsp;<?php echo $data['from_name'];?>
506  <?php hidden_field($prefix.'_messages['.$data['msgid'].']', '1'); ?>
507  </td>
508  <td class="sq-backend-table-cell" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
509  &nbsp;<?php echo $data['subject'];?>
510  </td>
511  <td class="sq-backend-table-cell" nowrap="nowrap" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
512  &nbsp;<?php echo $GLOBALS['SQ_SYSTEM']->datetime($data['sent']); ?>
513  </td>
514  <td class="sq-backend-table-cell" nowrap="nowrap">
515  <?php
516 
517  check_box(urlencode($prefix).'_mark_as_read['.$data['msgid'].']', '1', ($data['status'] == SQ_MSG_READ), 'readClick(this)', ($write_access) ? '' : 'style="display:none"');
518 ?>
519  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="letterIcon[<?php echo $data['msgid'];?>]" class="<?php echo (($data['status'] == SQ_MSG_UNREAD) ? 'un' : ''); ?>read" onclick="readClick(this)" />
520  </td>
521  <?php
522 
523  if ($write_access) {
524 ?>
525  <td class="sq-backend-table-cell" nowrap="nowrap">
526  <?php check_box($prefix.'_delete['.$data['msgid'].']', '1', FALSE, 'changeStatus('.$data['msgid'].')'); ?>
527  <img src="<?php echo sq_web_path('lib'); ?>/web/images/blank.gif" alt="" id="trashIcon[<?php echo $data['msgid'];?>]" class="trash" onclick="changeStatus('<?php echo $data['msgid'];?>', 'delete')" />
528  </td>
529  <?php
530 
531  }
532 ?>
533  </tr>
534  <?php
535  $total_assets++;
536  }//end for - each message
537 ?>
538  </table>
539  </div>
540  <script type="text/javascript">
541  //<![CDATA[
542  refreshAllStatus();
543  //]]>
544  </script>
545  <div id="sq_message_body"></div>
546  <?php
547 
548  }//end else - if empty inbox
549 
550  $this->_processReadStatus($asset, $prefix);
551 
552  return $write_access;
553 
554  }//end paintInbox()
555 
556 
566  function _processReadStatus(&$asset, $prefix)
567  {
568  $msgs = (isset ($_REQUEST[$prefix.'_messages'])) ? array_keys($_REQUEST[$prefix.'_messages']) : Array ();
569  $read = (isset ($_REQUEST[$prefix.'_mark_as_read'])) ? array_keys($_REQUEST[$prefix.'_mark_as_read']) : Array ();
570 
571  if (empty($msgs)) {
572  return;
573  }
574 
575  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
576 
577  foreach ($msgs as $msgid) {
578  $message = $ms->getMessageById($msgid);
579  if (in_array($msgid, $read) && $message->status == SQ_MSG_UNREAD) {
580  if (!$message->updateStatus(SQ_MSG_READ)) {
581  trigger_localised_error('CORE0076', E_USER_WARNING, $msgid);
582  }
583  continue;
584  }
585  if (!in_array($msgid, $read) && $message->status == SQ_MSG_READ) {
586  if (!$message->updateStatus(SQ_MSG_UNREAD)) {
587  trigger_localised_error('CORE0076', E_USER_WARNING, $msgid);
588  }
589  }
590  }
591 
592  }//end _processReadStatus()
593 
594 
605  function processInbox(&$asset, &$o, $prefix)
606  {
607  $msgs = (isset ($_POST[$prefix.'_messages'])) ? array_keys($_POST[$prefix.'_messages']) : Array ();
608  $delete = (isset ($_POST[$prefix.'_delete'])) ? array_keys($_POST[$prefix.'_delete']) : Array ();
609 
610  if (empty($msgs)) {
611  return;
612  }
613 
614  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
615 
616  foreach ($msgs as $msgid) {
617  $message = $ms->getMessageById($msgid);
618  if (in_array($msgid, $delete) && $message->status != SQ_MSG_DELETED) {
619  if (!$message->updateStatus(SQ_MSG_DELETED)) {
620  trigger_localised_error('CORE0063', E_USER_WARNING, $data['msgid']);
621  }
622  }
623  }
624 
625  $o->addOnLoad('if (parent.frames["sidenav"] && parent.frames["sidenav"].refresh_internal_messages) parent.frames["sidenav"].refresh_internal_messages();');
626 
627  return TRUE;
628 
629  }//end processInbox()
630 
631 
642  function paintTrash(&$asset, &$o, $prefix)
643  {
644  $user = $asset->_getUser();
645 
646  $priority = Array('', 'Highest', 'High', 'Normal', 'Low', 'Lowest');
647 
648  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
649  $messages = $ms->getMessages($user->id, NULL, Array(SQ_MSG_DELETED), Array(), NULL, NULL, 'name');
650  $write_access = $asset->writeAccess('mail');
651 ?>
652  <style type="text/css">
653  @import url(<?php echo sq_web_path('data')?>/asset_types/inbox/css/inbox.css.php);
654  </style>
655  <script type="text/javascript" >
656  //<![CDATA[
657  var Bodies = new Object();
658  var prefix = "<?php echo $prefix; ?>";
659  //]]>
660  </script>
661  <script type="text/javascript" src="<?php echo sq_web_path('data'); ?>/asset_types/inbox/js/inbox.js"></script>
662  <?php
663 
664  if (empty($messages)) {
665  ?><div style="text-align: center"><?php echo translate('inbox_trash_empty'); ?></div><?php
666  return FALSE;
667  } else {
668 ?>
669  <div id="inbox_container">
670 
671  <table border="0" cellspacing="0" cellpadding="1" id="inbox_table">
672  <tr>
673  <td class="sq-backend-table-header"><?php echo strtoupper(translate('from')); ?></td>
674  <td class="sq-backend-table-header"><?php echo strtoupper(translate('subject')); ?></td>
675  <td class="sq-backend-table-header"><?php echo strtoupper(translate('sent')); ?></td>
676  <?php
677 
678  if ($write_access) {
679 ?>
680  <td class="sq-backend-table-header">
681  <?php check_box($prefix.'_select_all_recover', '1', FALSE, 'check_all(document.main_form, "'.$prefix.'_recover", this.checked);'); ?>
682  <?php echo strtoupper(translate('recover')); ?>
683  </td>
684  <td class="sq-backend-table-header">
685  <?php check_box($prefix.'_select_all_purge', '1', FALSE, 'check_all(document.main_form, "'.$prefix.'_purge", this.checked);'); ?>
686  <?php echo strtoupper(translate('purge')); ?>
687  </td>
688  <?php
689 
690  }
691 ?>
692  </tr>
693  <?php
694 
695  $num_messages = count($messages);
696 
697  for ($i = 0; $i < $num_messages; $i ++) {
698 
699  $data = $messages[$i];
700 
701  // work out the sender icon
702  $sender_img = $GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($data['type_code']);
703 
704  $body = preg_replace("/[\n\t\r]/im", '<br />', $data['body']);
705  $body = str_replace('"', '\"', $body);
706 ?>
707  <script type="text/javascript">
708  //<![CDATA[
709  Bodies["<?php echo $data['msgid'];?>"] = "<?php echo $body; ?>";
710  //]]>
711  </script>
712  <tr>
713  <td class="sq-backend-table-cell" nowrap="nowrap" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
714  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/internal_message/priority_'.$data['priority'].'.png', 16, 16, '', $priority[$data['priority']].' priority') ?>
715  <?php sq_print_icon($sender_img, 16, 16) ?>
716  <a name="msg_<?php echo $data['msgid'];?>"></a>
717  &nbsp;<?php echo $data['from_name'];?>
718  <?php hidden_field($prefix.'_messages['.$data['msgid'].']', '1'); ?>
719  </td>
720  <td class="sq-backend-table-cell" onclick="showBody('<?php echo $data['msgid'];?>', this)" style="cursor: pointer">
721  &nbsp;<?php echo $data['subject'];?>
722  </td>
723  <td class="sq-backend-table-cell" onclick="showBody('<?php echo $data['msgid'];?>', this);" style="cursor: pointer;white-space: nowrap;">
724  &nbsp;<?php echo $GLOBALS['SQ_SYSTEM']->datetime($data['sent']); ?>
725  </td>
726 
727  <?php
728 
729  if ($write_access) {
730 ?>
731  <td class="sq-backend-table-cell" nowrap>
732  <?php
733 
734  if ($asset->writeAccess('mail')) {
735  check_box($prefix.'_recover['.$data['msgid'].']');
736  } else {
737  echo '&nbsp;';
738  }
739 
740 ?>
741  </td>
742  <td class="sq-backend-table-cell" nowrap>
743  <?php check_box($prefix.'_purge['.$data['msgid'].']'); ?>
744  </td>
745  <?php
746 
747  }
748 ?>
749  </tr>
750  <?php
751 
752  }//end for - each message
753 ?>
754  </table>
755  </div>
756  <div id="sq_message_body"></div>
757  <?php
758 
759  }//end else - if trash empty
760 
761  return TRUE;
762 
763  }//end paintTrash()
764 
765 
776  function processTrash(&$asset, &$o, $prefix)
777  {
778  $msgs = (isset ($_POST[$prefix.'_messages'])) ? array_keys($_POST[$prefix.'_messages']) : Array();
779  $recover = (isset ($_POST[$prefix.'_recover'])) ? array_keys($_POST[$prefix.'_recover']) : Array();
780  $purge = (isset ($_POST[$prefix.'_purge'])) ? array_keys($_POST[$prefix.'_purge']) : Array();
781 
782  if (empty($msgs)) {
783  return;
784  }
785 
786  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
787 
788  if (!empty ($recover)) {
789  foreach ($recover as $messageid) {
790  // recover messages to inbox
791  $message = $ms->getMessageById($messageid);
792  if (!$message->updateStatus(SQ_MSG_READ)) {
793  trigger_localised_error('CORE0064', E_USER_WARNING, $messageid);
794  }
795  }
796  }
797 
798  if (!empty ($purge)) {
799  foreach ($purge as $messageid) {
800  // delete messsage FOREVER
801  $message = $ms->getMessageById($messageid);
802  if (!$message->delete()) {
803  trigger_localised_error('CORE0063', E_USER_WARNING, $data['msgid']);
804  }
805  }
806  }
807  return TRUE;
808 
809  }//end processTrash()
810 
811 
812 }//end class
813 
814 ?>