summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/1.0/fldrbrowse.tcl
blob: 58d6d8fba9a98e92b8bfbeb74a5969d5c93be56d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# $Id: fldrbrowse.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
# ========================================================================
# Copyright 2006 University of Washington
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# ========================================================================

#  folders.tcl
#
#  Purpose:  CGI script to generate html output associated with folder
#	     and collection management
#
#  Input:
set folder_vars {
  {uid		{}	0}
  {show		{}	""}
  {expand	{}	""}
  {contract	{}	""}
  {target	{}	""}
  {onselect	{}	"compose"}
  {oncancel	{}	"index"}
  {controls	{}	1}
  {reload}
}

#  Output:
#
#	HTML/Javascript/CSS data representing the message specified
#	by the 'uid' argument

# the name of this script
set me [file tail [info script]]

set indention 18

proc pretty_folder_name {collections folder} {
  set fcolid [lindex $folder 0]
  for {set i 0} {$i < [llength $collections]} {incr i} {
    set col [lindex $collections $i]
    if {$fcolid == [lindex $col 0]} {
      set coltext [lindex $col 1]
    }
  }    
  return "${coltext}:[join [lrange $folder 1 end] /]"
}


set key [WPCmd PEInfo key]


#
# Display the given folder list in a table (w/ mihodge mods)
#
proc blat_folder_list {colid flist shown path baseurl scroll anchorcntref onselect depth} {

  global key border indention _wp target

  set mbox [WPCmd PEMailbox mailboxname]

  upvar $anchorcntref anchorcnt

  set rownum 0

  foreach folder $flist {
    set t [lindex $folder 0]
    set f [lindex $folder 1]
    set ff [linsert $path [llength $path] $f]
    set index -1

    # initial pad=12, expand/contract control is 9px wide
    set cellpad [expr {12 + ($depth * $indention)}]

    if {[string first F $t] >= 0} {
      set delim [WPCmd PEFolder delimiter $colid]
      set fullpath [join [lrange $ff 1 end] $delim]
      regsub -all {(')} [lrange $ff 1 end] {\\\\\1} ef
      set celldata [cgi_url $f wp.tcl?page=[join ${onselect} {&}]&f_colid=${colid}&f_name=[WPPercentQuote [join $ef $delim]]&target=${target}&cid=$key target=${target}]
    } else {
      set celldata $f
    }

    if {[string first D $t] >= 0} {

      if {[set index [lsearch $shown $ff]] < 0} {
	set control expand
      } else {
	set control contract
      }

      set celldata "[cgi_url [cgi_imglink $control] "${baseurl}${control}=[WPPercentQuote $ff]#f_[WPPercentQuote $ff]" name=f_[WPPercentQuote $ff] "style=\"padding-right:10px\""]$celldata"
      incr cellpad -19
    }

    cgi_table_row {
      cgi_table_data {
	cgi_put [cgi_img [WPimg dot2] height=1]
      }

      cgi_table_data align=left "style=\"padding-left: ${cellpad}px\"" nowrap {
	cgi_put $celldata
      }

      cgi_table_data valign=top nowrap {
	cgi_puts [cgi_nbspace]
      }
    }

    if {[string first D $t] >= 0 && $index >= 0} {
      set nflist [eval WPCmd PEFolder list $ff]
      set newpath $path
      lappend newpath $f
      blat_folder_list $colid $nflist $shown $newpath $baseurl $scroll anchorcnt $onselect [expr {$depth + 1}]
    }

    catch {unset control}
  }
}

#
# Command Menu definition for Message View Screen
#
set folder_menu {
}

set common_menu {
  {
    {expr {$controls == 1}}
    {
      {
	# * * * * CANCEL * * * *
	cgi_puts [cgi_url Cancel wp.tcl?page=$oncancel&cid=[WPCmd PEInfo key] class=navbar target=_top]
      }
    }
  }
  {}
  {
    {}
    {
      {
	cgi_puts "Get Help"
      }
    }
  }
}


## read vars
foreach item $folder_vars {
  if {[catch {cgi_import [lindex $item 0].x}]} {
    if {[catch {eval WPImport $item} errstr]} {
      error [list _action "Impart Variable" $errstr]
    }
  } else {
    set [lindex $item 0] 1
  }
}

if {[catch {WPNewMail $reload} newmail]} {
  error [list _action "new mail" $newmail]
}


# perform any requested actions

# preserve vars that my have been overridden with cgi parms

if {[catch {WPCmd PEFolder collections} collections]} {
  error [list _action "Collection list" $collections]
}

set shown [split $show ,]
set scroll {}
set anchorcnt 0

# mihodge: process actions
if {[llength $expand]} {
  lappend shown $expand
  set scroll $expand
}

if {[llength $contract]} {
  if {[set index [lsearch $shown $contract]] >= 0} {
    set shown [lreplace $shown $index $index]
    set scroll $contract
  }
}

set baseurl wp.tcl?page=fldrbrowse&onselect=[WPPercentQuote ${onselect}]&oncancel=${oncancel}&controls=${controls}&target=${target}&

if {[llength $shown]} {
  append baseurl "show=[WPPercentQuote [join $shown ,]]&"
}


# paint the page
cgi_http_head {
  WPStdHttpHdrs text/html
}

cgi_html {
  cgi_head {
    WPStdHtmlHdr "Folder List" folders
    if {$controls == 1} {
      WPHtmlHdrReload "$_wp(appdir)/$_wp(ui1dir)/wp.tcl?page=folders"
    }

    WPStyleSheets
  }

  cgi_body bgcolor=$_wp(bordercolor) {

    catch {WPCmd PEInfo set help_context folders}

    # prepare context and navigation information

    set navops ""

    if {$controls == 1} {
      WPTFTitle "Browse Folder" $newmail
    }

    cgi_table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%" {
      cgi_table_row {
	if {$controls > 0} {
	  cgi_table_data rowspan=2 valign=top class=navbar {
	    cgi_table bgcolor=$_wp(menucolor) border=0 cellspacing=0 cellpadding=0 {
	      # next comes the menu down the left side, with suitable
	      cgi_table_row {
		eval {
		  cgi_table_data $_wp(menuargs) class=navbar {
		    WPTFCommandMenu folder_menu common_menu
		  }
		}
	      }
	    }
	  }
	}

	# down the right side of the table is the window's contents
	cgi_table_data width="100%" align=center valign=top class=dialog {

	  # then the table representing the folders
	  cgi_table width=75% border=0 cellspacing=0 cellpadding=2 align=center {

	    cgi_table_row {
	      cgi_table_data height=80 align=center valign=middle class=dialog {
		switch $controls {
		  0 -
		  2 { set task "the Saved message" }
		  default { set task "your composition's [cgi_italic "File Carbon Copy"] (Fcc)" }
		}

		cgi_puts "Click a folder name below to use it as the destination for $task, or click [cgi_italic Cancel]"
		cgi_puts "to return without choosing anything."
	      }
	    }

	    if {$controls != 1} {
	      cgi_table_row {
		cgi_table_data align=center valign=top height=40 class=navbar {
		  cgi_form $_wp(appdir)/$_wp(ui1dir)/wp method=get target=$target {
		    cgi_text page=$oncancel type=hidden notab
		    cgi_text cid=[WPCmd PEInfo key] type=hidden notab
		    cgi_submit_button cancel=Cancel
		  }
		}
	      }
	    }

	    cgi_table_row {
	      cgi_table_data {
		cgi_table border=0 cellspacing=0 cellpadding=2 align=center {
		  for {set i 0} {$i < [llength $collections]} {incr i} {
		    set col [lindex $collections $i]
		    set colid [lindex $col 0]

		    cgi_table_row {
		      cgi_table_data width=18 valign=top {
			if {[llength $collections] > 1} {
			  if {[set index [lsearch $shown $colid]] < 0} {
			    cgi_puts [cgi_url [cgi_imglink expand] "${baseurl}expand=$colid"]
			  } else {
			    cgi_puts [cgi_url [cgi_imglink contract] "${baseurl}contract=$colid"]
			  }
			} else {
			  cgi_puts [cgi_nbspace]
			}
		      }
		      
		      cgi_table_data align=left {
			if {[llength $collections] == 1} {
			  set menu "c"
			  set flist 1
			} else {
			  if {[set index [lsearch $shown $colid]] < 0} {
			    set menu "ce"
			    set flist {}
			  } else {
			    set menu "cc"
			    set flist 1
			  }
			}

			if {[llength $flist]} {
			  set flist [WPCmd PEFolder list $colid]
			}

			if {$scroll == $colid} {
			  #cgi_javascript {cgi_puts {scroll = window.document.anchors.length;}}
			}

			cgi_puts [cgi_font face=Helvetica size=+1 "[lindex $col 1]<A NAME=\"f_$colid\">&nbsp;</A>"]

			incr anchorcnt

			if {[llength $flist]} {
			  blat_folder_list $colid $flist $shown $colid $baseurl $scroll anchorcnt $onselect 1
			}
		      }
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
}