message_list_util.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /**
  3. * message_list_util.php
  4. *
  5. * Helper functions for message list templates.
  6. *
  7. * The following functions are utility functions for templates. Do not
  8. * echo output in these functions.
  9. *
  10. * @copyright &copy; 2005-2009 The SquirrelMail Project Team
  11. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  12. * @version $Id$
  13. * @package squirrelmail
  14. */
  15. /**
  16. * @param array $aOrder
  17. * @return array
  18. */
  19. function calcMessageListColumnWidth($aOrder) {
  20. /**
  21. * Width of the displayed columns
  22. */
  23. $aWidthTpl = array(
  24. SQM_COL_CHECK => 1,
  25. SQM_COL_FROM => 25,
  26. SQM_COL_DATE => 15,
  27. SQM_COL_SUBJ => 100,
  28. SQM_COL_FLAGS => 2,
  29. SQM_COL_SIZE => 5,
  30. SQM_COL_PRIO => 1,
  31. SQM_COL_ATTACHMENT => 1,
  32. SQM_COL_INT_DATE => 15,
  33. SQM_COL_TO => 25,
  34. SQM_COL_CC => 25,
  35. SQM_COL_BCC => 25
  36. );
  37. /**
  38. * Calculate the width of the subject column based on the
  39. * widths of the other columns
  40. */
  41. if (isset($aOrder[SQM_COL_SUBJ])) {
  42. foreach($aOrder as $iCol) {
  43. if ($iCol != SQM_COL_SUBJ) {
  44. $aWidthTpl[SQM_COL_SUBJ] -= $aWidthTpl[$iCol];
  45. }
  46. }
  47. }
  48. $aWidth = array();
  49. foreach($aOrder as $iCol) {
  50. $aWidth[$iCol] = $aWidthTpl[$iCol];
  51. }
  52. $iCheckTotalWidth = $iTotalWidth = 0;
  53. foreach($aOrder as $iCol) { $iTotalWidth += $aWidth[$iCol];}
  54. $iTotalWidth = ($iTotalWidth) ? $iTotalWidth : 100; // divide by zero check. shouldn't be needed
  55. // correct the width to 100%
  56. foreach($aOrder as $iCol) {
  57. $aWidth[$iCol] = round( (100 / $iTotalWidth) * $aWidth[$iCol] , 0);
  58. $iCheckTotalWidth += $aWidth[$iCol];
  59. }
  60. if ($iCheckTotalWidth > 100) { // correction needed
  61. $iCol = array_search(max($aWidth),$aWidth);
  62. $aWidth[$iCol] -= $iCheckTotalWidth-100;
  63. }
  64. return $aWidth;
  65. }
  66. /**
  67. * Function to retrieve correct icon based on provided message flags. This is
  68. * a merge/replacement for getFlagIcon() and getFlagText() functions.
  69. *
  70. * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
  71. * @param string $icon_theme_path path to user's currently selected icon theme.
  72. * @return string $icon full HTML img tag or text icon, depending on of user prefs
  73. * @author Steve Brown
  74. */
  75. function getFlagIcon ($aFlags, $icon_theme_path) {
  76. /**
  77. * 0 = unseen
  78. * 1 = seen
  79. * 2 = deleted
  80. * 3 = deleted seen
  81. * 4 = answered
  82. * 5 = answered seen
  83. * 6 = answered deleted
  84. * 7 = answered deleted seen
  85. * 8 = flagged
  86. * 9 = flagged seen
  87. * 10 = flagged deleted
  88. * 11 = flagged deleted seen
  89. * 12 = flagged answered
  90. * 13 = flagged aswered seen
  91. * 14 = flagged answered deleted
  92. * 15 = flagged anserwed deleted seen
  93. * ...
  94. * 32 = forwarded
  95. * 33 = forwarded seen
  96. * 34 = forwarded deleted
  97. * 35 = forwarded deleted seen
  98. * ...
  99. * 41 = flagged forwarded seen
  100. * 42 = flagged forwarded deleted
  101. * 43 = flagged forwarded deleted seen
  102. */
  103. /**
  104. * Use static vars to avoid initialisation of the array on each displayed row
  105. */
  106. global $nbsp;
  107. static $flag_icons, $flag_values;
  108. if (!isset($flag_icons)) {
  109. // This is by no means complete...
  110. $flag_icons = array (
  111. // Image icon name Text Icon Alt/Title Text
  112. // --------------- --------- --------------
  113. array ('msg_new.png', $nbsp, '('._("New").')') ,
  114. array ('msg_read.png', $nbsp, '('._("Read").')'),
  115. array ('msg_new_deleted.png', _("D"), '('._("Deleted").')'),
  116. array ('msg_read_deleted.png', _("D"), '('._("Deleted").')'),
  117. array ('msg_new_reply.png', _("A"), '('._("Answered").')'),
  118. array ('msg_read_reply.png', _("A"), '('._("Answered").')'),
  119. array ('msg_new_deleted_reply.png', _("D"), '('._("Answered").')'),
  120. array ('msg_read_deleted_reply.png', _("D"), '('._("Answered").')'),
  121. array ('flagged.png', _("F"), '('._("Flagged").')'),
  122. array ('flagged.png', _("F"), '('._("Flagged").')'),
  123. array ('flagged.png', _("F"), '('._("Flagged").')'),
  124. array ('flagged.png', _("F"), '('._("Flagged").')'),
  125. array ('flagged.png', _("F"), '('._("Flagged").')'),
  126. array ('flagged.png', _("F"), '('._("Flagged").')'),
  127. array ('flagged.png', _("F"), '('._("Flagged").')'),
  128. array ('flagged.png', _("F"), '('._("Flagged").')'),
  129. FALSE,
  130. FALSE,
  131. FALSE,
  132. FALSE,
  133. FALSE,
  134. FALSE,
  135. FALSE,
  136. FALSE,
  137. FALSE,
  138. FALSE,
  139. FALSE,
  140. FALSE,
  141. FALSE,
  142. FALSE,
  143. FALSE,
  144. FALSE,
  145. array ('msg_new_forwarded.png', _("O"), '('._("Forwarded").')'),
  146. array ('msg_read_forwarded.png', _("O"), '('._("Forwarded").')'),
  147. array ('msg_new_deleted_forwarded.png', _("D"), '('._("Forwarded").')'),
  148. array ('msg_read_deleted_forwarded.png', _("D"), '('._("Forwarded").')'),
  149. FALSE,
  150. FALSE,
  151. FALSE,
  152. FALSE,
  153. FALSE,
  154. array ('flagged.png', _("F"), '('._("Flagged").')'),
  155. array ('flagged.png', _("F"), '('._("Flagged").')'),
  156. array ('flagged.png', _("F"), '('._("Flagged").')'),
  157. );
  158. $flag_values = array('seen' => 1,
  159. 'deleted' => 2,
  160. 'answered' => 4,
  161. 'flagged' => 8,
  162. 'draft' => 16,
  163. 'forwarded' => 32);
  164. }
  165. /**
  166. * The flags entry contain all items displayed in the flag column.
  167. */
  168. $icon = '';
  169. $index = 0;
  170. foreach ($aFlags as $flag => $flagvalue) {
  171. switch ($flag) {
  172. case 'deleted':
  173. case 'answered':
  174. case 'forwarded':
  175. case 'seen':
  176. case 'flagged': if ($flagvalue) $index += $flag_values[$flag]; break;
  177. default: break;
  178. }
  179. }
  180. if (!empty($flag_icons[$index])) {
  181. $data = $flag_icons[$index];
  182. } else {
  183. //FIXME: previously this default was set to the last value of the $flag_icons array (when it was index 15 - flagged anserwed deleted seen) but I don't understand why... am changing it to flagged (index 15 just shows (only) the flag icon anyway)
  184. $data = $flag_icons[8]; // default to just flagged
  185. }
  186. $icon = getIcon($icon_theme_path, $data[0], $data[1], $data[2]);
  187. return $icon;
  188. }
  189. /**
  190. * Function to retrieve correct priority icon based on user prefs
  191. *
  192. * @param integer $priority priority value of message
  193. * @param string $icon_theme_path path to user's currently selected icon theme.
  194. * @return string $icon full HTML img tag or text icon, depending on of user prefs
  195. * @author Steve Brown
  196. */
  197. function getPriorityIcon ($priority, $icon_theme_path) {
  198. $icon = '';
  199. switch ($priority) {
  200. case 1:
  201. case 2:
  202. $icon = getIcon($icon_theme_path, 'prio_high.png', create_span('!', 'high_priority'), _("High priority"));
  203. break;
  204. case 5:
  205. $icon = getIcon($icon_theme_path, 'prio_low.png', create_span('&#8595;', 'low_priority'), _("Low priority"));
  206. break;
  207. default:
  208. $icon = getIcon($icon_theme_path, 'transparent.png', '', _("Normal priority"), 5);
  209. break;
  210. }
  211. return $icon;
  212. }
  213. /**
  214. * Function to retrieve correct attchment icon based on user prefs
  215. *
  216. * @param boolean $attach TRUE if the message has an attachment
  217. * @param string $icon_theme_path path to user's currently selected icon theme.
  218. * @return string $icon full HTML img tag or text icon, depending on of user prefs
  219. * @author Steve Brown
  220. */
  221. function getAttachmentIcon ($attach, $icon_theme_path) {
  222. $icon = '';
  223. $icon_file = $attach ? 'attach.png' : 'transparent.png';
  224. $alt_text = $attach ? _("Attachment") : _("No attachment");
  225. $text = $attach ? '+' : '';
  226. $icon = getIcon($icon_theme_path, $icon_file, $text, $alt_text);
  227. return $icon;
  228. }