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