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