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