missed one more tag
[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
10 function calcMessageListColumnWidth($aOrder) {
11 /**
12 * Width of the displayed columns
13 */
14 $aWidthTpl = array(
15 SQM_COL_CHECK => 1,
16 SQM_COL_FROM => 25,
17 SQM_COL_DATE => 10,
18 SQM_COL_SUBJ => 100,
19 SQM_COL_FLAGS => 2,
20 SQM_COL_SIZE => 5,
21 SQM_COL_PRIO => 1,
22 SQM_COL_ATTACHMENT => 1,
23 SQM_COL_INT_DATE => 10,
24 SQM_COL_TO => 25,
25 SQM_COL_CC => 25,
26 SQM_COL_BCC => 25
27 );
28
29 /**
30 * Calculate the width of the subject column based on the
31 * widths of the other columns
32 */
33 if (isset($aOrder[SQM_COL_SUBJ])) {
34 foreach($aOrder as $iCol) {
35 if ($iCol != SQM_COL_SUBJ) {
36 $aWidthTpl[SQM_COL_SUBJ] -= $aWidthTpl[$iCol];
37 }
38 }
39 }
40 foreach($aOrder as $iCol) {
41 $aWidth[$iCol] = $aWidthTpl[$iCol];
42 }
43
44 $iCheckTotalWidth = $iTotalWidth = 0;
45 foreach($aOrder as $iCol) { $iTotalWidth += $aWidth[$iCol];}
46
47 $iTotalWidth = ($iTotalWidth) ? $iTotalWidth : 100; // divide by zero check. shouldn't be needed
48 // correct the width to 100%
49 foreach($aOrder as $iCol) {
50 $aWidth[$iCol] = round( (100 / $iTotalWidth) * $aWidth[$iCol] , 0);
51 $iCheckTotalWidth += $aWidth[$iCol];
52 }
53 if ($iCheckTotalWidth > 100) { // correction needed
54 $iCol = array_search(max($aWidth),$aWidth);
55 $aWidth[$iCol] -= $iCheckTotalWidth-100;
56 }
57 return $aWidth;
58 }
59
60 /**
61 * Function to retrieve the correct flag icon belonging to the set of
62 * provided flags
63 *
64 * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
65 * @param string $sImageLocation directory location of flagicons
66 * @return string $sFlags string with the correct img html tag
67 * @author Marc Groot Koerkamp
68 */
69 function getFlagIcon($aFlags, $sImageLocation) {
70 $sFlags = '';
71
72 /**
73 * 0 = unseen
74 * 1 = seen
75 * 2 = deleted
76 * 3 = deleted seen
77 * 4 = answered
78 * 5 = answered seen
79 * 6 = answered deleted
80 * 7 = answered deleted seen
81 * 8 = flagged
82 * 9 = flagged seen
83 * 10 = flagged deleted
84 * 11 = flagged deleted seen
85 * 12 = flagged answered
86 * 13 = flagged aswered seen
87 * 14 = flagged answered deleted
88 * 15 = flagged anserwed deleted seen
89 */
90
91 /**
92 * Use static vars to avoid initialisation of the array on each displayed row
93 */
94 static $aFlagImages, $aFlagValues;
95 if (!isset($aFlagImages)) {
96 $aFlagImages = array(
97 array('msg_new.png','('._("New").')'),
98 array('msg_read.png','('._("Read").')'),
99 array('msg_new_deleted.png','('._("Deleted").')'),
100 array('msg_read_deleted.png','('._("Deleted").')'),
101 array('msg_new_reply.png','('._("Answered").')'),
102 array('msg_read_reply.png','('._("Answered").')'),
103 array('msg_read_deleted_reply.png','('._("Answered").')'),
104 array('flagged.png', '('._("Flagged").')'),
105 array('flagged.png', '('._("Flagged").')'),
106 array('flagged.png', '('._("Flagged").')'),
107 array('flagged.png', '('._("Flagged").')'),
108 array('flagged.png', '('._("Flagged").')'),
109 array('flagged.png', '('._("Flagged").')'),
110 array('flagged.png', '('._("Flagged").')'),
111 array('flagged.png', '('._("Flagged").')'),
112 array('flagged.png', '('._("Flagged").')')
113 ); // as you see the list is not completed yet.
114 $aFlagValues = array('seen' => 1,
115 'deleted' => 2,
116 'answered' => 4,
117 'flagged' => 8,
118 'draft' => 16);
119 }
120
121 /**
122 * The flags entry contain all items displayed in the flag column.
123 */
124 $iFlagIndx = 0;
125 foreach ($aFlags as $flag => $flagvalue) {
126 /* FIX ME, we should use separate templates for icons */
127 switch ($flag) {
128 case 'deleted':
129 case 'answered':
130 case 'seen':
131 case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break;
132 default: break;
133 }
134 }
135 if (isset($aFlagImages[$iFlagIndx])) {
136 $aFlagEntry = $aFlagImages[$iFlagIndx];
137 } else {
138 $aFlagEntry = end($aFlagImages);
139 }
140
141 $sFlags = '<img src="' . $sImageLocation . $aFlagEntry[0].'"'.
142 ' border="0" alt="'.$aFlagEntry[1].'" title="'. $aFlagEntry[1] .'" height="12" width="18" />' ;
143 if (!$sFlags) { $sFlags = '&nbsp;'; }
144 return $sFlags;
145 }
146
147 /**
148 * Function to retrieve the correct flag text belonging to the set of
149 * provided flags
150 *
151 * @param array $aFlags associative array with seen,deleted,anwered and flag keys.
152 * @return string $sFlags string with the correct flag text
153 * @author Marc Groot Koerkamp
154 */
155 function getFlagText($aFlags) {
156 $sFlags = '';
157
158 /**
159 * 0 = unseen
160 * 1 = seen
161 * 2 = deleted
162 * 3 = deleted seen
163 * 4 = answered
164 * 5 = answered seen
165 * 6 = answered deleted
166 * 7 = answered deleted seen
167 * 8 = flagged
168 * 9 = flagged seen
169 * 10 = flagged deleted
170 * 11 = flagged deleted seen
171 * 12 = flagged answered
172 * 13 = flagged aswered seen
173 * 14 = flagged answered deleted
174 * 15 = flagged anserwed deleted seen
175 */
176 /**
177 * Use static vars to avoid initialisation of the array on each displayed row
178 */
179 static $aFlagText, $aFlagValues;
180 if (!isset($aFlagText)) {
181 $aFlagText = array(
182 array('&nbsp;', '('._("New").')'),
183 array('&nbsp;', '('._("Read").')'),
184 array(_("D") , '('._("Deleted").')'),
185 array(_("D") , '('._("Deleted").')'),
186 array(_("A") , '('._("Answered").')'),
187 array(_("A") , '('._("Answered").')'),
188 array(_("D") , '('._("Answered").')'),
189 array(_("F") , '('._("Flagged").')'),
190 array(_("F") , '('._("Flagged").')'),
191 array(_("F") , '('._("Flagged").')'),
192 array(_("F") , '('._("Flagged").')'),
193 array(_("F") , '('._("Flagged").')'),
194 array(_("F") , '('._("Flagged").')'),
195 array(_("F") , '('._("Flagged").')'),
196 array(_("F") , '('._("Flagged").')'),
197 array(_("F") , '('._("Flagged").')')
198 ); // as you see the list is not completed yet.
199 $aFlagValues = array('seen' => 1,
200 'deleted' => 2,
201 'answered' => 4,
202 'flagged' => 8,
203 'draft' => 16);
204 }
205
206 /**
207 * The flags entry contain all items displayed in the flag column.
208 */
209 $iFlagIndx = 0;
210 foreach ($aFlags as $flag => $flagvalue) {
211 /* FIX ME, we should use separate templates for icons */
212 switch ($flag) {
213 case 'deleted':
214 case 'answered':
215 case 'seen':
216 case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break;
217 default: break;
218 }
219 }
220 if (isset($aFlagText[$iFlagIndx])) {
221 $sFlags = $aFlagText[$iFlagIndx][0];
222 } else {
223 $aLast = end($aFlagText);
224 $sFlags = $aLast[0];
225 }
226 if (!$sFlags) { $sFlags = '&nbsp;'; }
227 return $sFlags;
228 }
229 ?>