copyright update
[squirrelmail.git] / templates / util_message_list.php
1 <?php
2
3 /**
4 * Template logic
5 *
6 * The following functions are utility functions for this template. Do not
7 * echo output in those functions.
8 *
9 * @copyright &copy; 2005-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
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 => 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 /**
70 * Function to retrieve the correct flag icon belonging to the set of
71 * provided flags
72 *
73 * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
74 * @param string $sImageLocation directory location of flagicons
75 * @return string $sFlags string with the correct img html tag
76 * @author Marc Groot Koerkamp
77 */
78 function getFlagIcon($aFlags, $sImageLocation) {
79 $sFlags = '';
80
81 /**
82 * 0 = unseen
83 * 1 = seen
84 * 2 = deleted
85 * 3 = deleted seen
86 * 4 = answered
87 * 5 = answered seen
88 * 6 = answered deleted
89 * 7 = answered deleted seen
90 * 8 = flagged
91 * 9 = flagged seen
92 * 10 = flagged deleted
93 * 11 = flagged deleted seen
94 * 12 = flagged answered
95 * 13 = flagged aswered seen
96 * 14 = flagged answered deleted
97 * 15 = flagged anserwed deleted seen
98 */
99
100 /**
101 * Use static vars to avoid initialisation of the array on each displayed row
102 */
103 static $aFlagImages, $aFlagValues;
104 if (!isset($aFlagImages)) {
105 $aFlagImages = array(
106 array('msg_new.png','('._("New").')'),
107 array('msg_read.png','('._("Read").')'),
108 array('msg_new_deleted.png','('._("Deleted").')'),
109 array('msg_read_deleted.png','('._("Deleted").')'),
110 array('msg_new_reply.png','('._("Answered").')'),
111 array('msg_read_reply.png','('._("Answered").')'),
112 array('msg_read_deleted_reply.png','('._("Answered").')'),
113 array('flagged.png', '('._("Flagged").')'),
114 array('flagged.png', '('._("Flagged").')'),
115 array('flagged.png', '('._("Flagged").')'),
116 array('flagged.png', '('._("Flagged").')'),
117 array('flagged.png', '('._("Flagged").')'),
118 array('flagged.png', '('._("Flagged").')'),
119 array('flagged.png', '('._("Flagged").')'),
120 array('flagged.png', '('._("Flagged").')'),
121 array('flagged.png', '('._("Flagged").')')
122 ); // as you see the list is not completed yet.
123 $aFlagValues = array('seen' => 1,
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 */
133 $iFlagIndx = 0;
134 foreach ($aFlags as $flag => $flagvalue) {
135 /* FIX ME, we should use separate templates for icons */
136 switch ($flag) {
137 case 'deleted':
138 case 'answered':
139 case 'seen':
140 case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break;
141 default: break;
142 }
143 }
144 if (isset($aFlagImages[$iFlagIndx])) {
145 $aFlagEntry = $aFlagImages[$iFlagIndx];
146 } else {
147 $aFlagEntry = end($aFlagImages);
148 }
149
150 $sFlags = '<img src="' . $sImageLocation . $aFlagEntry[0].'"'.
151 ' border="0" alt="'.$aFlagEntry[1].'" title="'. $aFlagEntry[1] .'" height="12" width="18" />' ;
152 if (!$sFlags) { $sFlags = '&nbsp;'; }
153 return $sFlags;
154 }
155
156 /**
157 * Function to retrieve the correct flag text belonging to the set of
158 * provided flags
159 *
160 * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
161 * @return string $sFlags string with the correct flag text
162 * @author Marc Groot Koerkamp
163 */
164 function getFlagText($aFlags) {
165 $sFlags = '';
166
167 /**
168 * 0 = unseen
169 * 1 = seen
170 * 2 = deleted
171 * 3 = deleted seen
172 * 4 = answered
173 * 5 = answered seen
174 * 6 = answered deleted
175 * 7 = answered deleted seen
176 * 8 = flagged
177 * 9 = flagged seen
178 * 10 = flagged deleted
179 * 11 = flagged deleted seen
180 * 12 = flagged answered
181 * 13 = flagged aswered seen
182 * 14 = flagged answered deleted
183 * 15 = flagged anserwed deleted seen
184 */
185 /**
186 * Use static vars to avoid initialisation of the array on each displayed row
187 */
188 static $aFlagText, $aFlagValues;
189 if (!isset($aFlagText)) {
190 $aFlagText = array(
191 array('&nbsp;', '('._("New").')'),
192 array('&nbsp;', '('._("Read").')'),
193 array(_("D") , '('._("Deleted").')'),
194 array(_("D") , '('._("Deleted").')'),
195 array(_("A") , '('._("Answered").')'),
196 array(_("A") , '('._("Answered").')'),
197 array(_("D") , '('._("Answered").')'),
198 array(_("F") , '('._("Flagged").')'),
199 array(_("F") , '('._("Flagged").')'),
200 array(_("F") , '('._("Flagged").')'),
201 array(_("F") , '('._("Flagged").')'),
202 array(_("F") , '('._("Flagged").')'),
203 array(_("F") , '('._("Flagged").')'),
204 array(_("F") , '('._("Flagged").')'),
205 array(_("F") , '('._("Flagged").')'),
206 array(_("F") , '('._("Flagged").')')
207 ); // as you see the list is not completed yet.
208 $aFlagValues = array('seen' => 1,
209 'deleted' => 2,
210 'answered' => 4,
211 'flagged' => 8,
212 'draft' => 16);
213 }
214
215 /**
216 * The flags entry contain all items displayed in the flag column.
217 */
218 $iFlagIndx = 0;
219 foreach ($aFlags as $flag => $flagvalue) {
220 /* FIX ME, we should use separate templates for icons */
221 switch ($flag) {
222 case 'deleted':
223 case 'answered':
224 case 'seen':
225 case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break;
226 default: break;
227 }
228 }
229 if (isset($aFlagText[$iFlagIndx])) {
230 $sFlags = $aFlagText[$iFlagIndx][0];
231 } else {
232 $aLast = end($aFlagText);
233 $sFlags = $aLast[0];
234 }
235 if (!$sFlags) { $sFlags = '&nbsp;'; }
236 return $sFlags;
237 }
238 ?>