message_list_util.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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-2006 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. /**
  95. * Use static vars to avoid initialisation of the array on each displayed row
  96. */
  97. static $flag_icons, $flag_values;
  98. if (!isset($flag_icons)) {
  99. // This is by no means complete...
  100. $flag_icons = array ( // Image icon name Text Icon Alt/Title Text
  101. array ('msg_new.png', '&nbsp;', '('._("New").')') ,
  102. array ('msg_read.png', '&nbsp;', '('._("Read").')'),
  103. array ('msg_new_deleted.png', _("D"), '('._("Deleted").')'),
  104. array ('msg_read_deleted.png', _("D"), '('._("Deleted").')'),
  105. array ('msg_new_reply.png', _("A"), '('._("Answered").')'),
  106. array ('msg_read_reply.png', _("A"), '('._("Answered").')'),
  107. array ('msg_read_deleted_reply.png', _("D"), '('._("Answered").')'),
  108. array ('flagged.png', _("F"), '('._("Flagged").')'),
  109. array ('flagged.png', _("F"), '('._("Flagged").')'),
  110. array ('flagged.png', _("F"), '('._("Flagged").')'),
  111. array ('flagged.png', _("F"), '('._("Flagged").')'),
  112. array ('flagged.png', _("F"), '('._("Flagged").')'),
  113. array ('flagged.png', _("F"), '('._("Flagged").')'),
  114. array ('flagged.png', _("F"), '('._("Flagged").')'),
  115. array ('flagged.png', _("F"), '('._("Flagged").')'),
  116. array ('flagged.png', _("F"), '('._("Flagged").')')
  117. );
  118. $flag_values = array('seen' => 1,
  119. 'deleted' => 2,
  120. 'answered' => 4,
  121. 'flagged' => 8,
  122. 'draft' => 16);
  123. }
  124. /**
  125. * The flags entry contain all items displayed in the flag column.
  126. */
  127. $icon = '';
  128. $index = 0;
  129. foreach ($aFlags as $flag => $flagvalue) {
  130. switch ($flag) {
  131. case 'deleted':
  132. case 'answered':
  133. case 'seen':
  134. case 'flagged': if ($flagvalue) $index += $flag_values[$flag]; break;
  135. default: break;
  136. }
  137. }
  138. if (isset($flag_icons[$index])) {
  139. $data = $flag_icons[$index];
  140. } else {
  141. $data = end($flag_icons);
  142. }
  143. $icon = getIcon($icon_theme_path, $data[0], $data[1], $data[2]);
  144. return $icon;
  145. }
  146. /**
  147. * Function to retrieve correct priority icon based on user prefs
  148. *
  149. * @param integer $priority priority value of message
  150. * @param string $icon_theme_path path to user's currently selected icon theme.
  151. * @return string $icon full HTML img tag or text icon, depending on of user prefs
  152. * @author Steve Brown
  153. */
  154. function getPriorityIcon ($priority, $icon_theme_path) {
  155. $icon = '';
  156. switch ($priority) {
  157. case 1:
  158. case 2:
  159. $icon = getIcon($icon_theme_path, 'prio_high.png', create_span('!', 'high_priority'));
  160. break;
  161. case 5:
  162. $icon = getIcon($icon_theme_path, 'prio_low.png', create_span('&#8595;', 'low_priority'));
  163. break;
  164. default:
  165. $icon = getIcon($icon_theme_path, 'transparent.png', '', '', 5);
  166. break;
  167. }
  168. return $icon;
  169. }
  170. /**
  171. * Function to retrieve correct attchment icon based on user prefs
  172. *
  173. * @param boolean $attach TRUE if the message has an attachment
  174. * @param string $icon_theme_path path to user's currently selected icon theme.
  175. * @return string $icon full HTML img tag or text icon, depending on of user prefs
  176. * @author Steve Brown
  177. */
  178. function getAttachmentIcon ($attach, $icon_theme_path) {
  179. $icon = '';
  180. $icon_file = $attach ? 'attach.png' : 'transparent.png';
  181. $text = $attach ? '+' : '';
  182. $icon = getIcon($icon_theme_path, $icon_file, $text);
  183. return $icon;
  184. }