2
# $Id: contactlist.tcl 1150 2008-08-20 00:27:11Z mikes@u.washington.edu $
3
# ========================================================================
4
# Copyright 2008 University of Washington
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# ========================================================================
16
# Purpose: CGI script that generates a page displaying a
17
# list of contacts in the requested address book
19
# Input: PATH_INFO: /booknumber
20
# along with possible search parameters:
21
set contactlist_args {
37
# inherit global config
42
proc cgi_suffix {args} {
46
proc deleteByBook {_delbooks} {
47
upvar 1 $_delbooks delbooks
48
foreach dbn [array names delbooks] {
49
foreach dbi [lsort -integer -decreasing $delbooks($dbn)] {
50
if {[catch {WPCmd PEAddress delete $dbn "" $dbi} result]} {
51
error "Address Delete Failure: $result"
57
if {[info exists env(PATH_INFO)] && [string length $env(PATH_INFO)]} {
58
if {[regexp {^/([0-9]+)$} $env(PATH_INFO) dummy abook]} {
59
# Import data validate it and get session id
60
if {[catch {WPGetInputAndID sessid}]} {
61
set harderr "No Session ID: $sessid"
64
foreach item $contactlist_args {
65
if {[catch {eval WPImport $item} importerr]} {
66
set harderr "Cannot init session: $importerr"
72
set harderr "Bad Address Book Request: $env(PATH_INFO)"
75
set harderr "No Address Book Specified"
78
puts stdout "Content-type: text/html; charset=\"UTF-8\"\n"
80
if {[info exists harderr]} {
81
puts stdout "<b>ERROR: $harderr</b>"
88
# grok delete format: \[(book)index\],
89
if {[regexp {^[0-9\.,]+$} $entryList]} {
91
set entryList [split $entryList ","]
92
foreach e $entryList {
93
if {[regexp {^([0-9]+)\.([0-9]+)} $e dummy eb ei]} {
94
lappend delbooks($eb) $ei
98
# delete by book in DECREASING index order
99
if {[catch {deleteByBook delbooks} result] || [string length $result]} {
100
WPCmd PEInfo statmsg "$result"
102
if {[llength $entryList] > 1} {
103
WPCmd PEInfo statmsg "Contacts Deleted"
105
WPCmd PEInfo statmsg "Contact Deleted"
109
WPCmd PEInfo statmsg "Invalid entry list format: >>>>$entryList<<<<"
113
if {[catch {WPCmd PEAddress edit $book $contactNick $ai $contactName $contactEmail $contactFcc $contactNotes 1} result]} {
114
WPCmd PEInfo statmsg "Add failed: $result"
118
if {[catch {WPCmd PEAddress edit $book $contactNick $ai $contactName $contactEmail $contactFcc $contactNotes 0 $origNick} result]} {
119
WPCmd PEInfo statmsg "Change failed: $result"
125
WPCmd PEInfo statmsg "Unrecognized option: $op"
129
# remainder is director to list
130
if {[catch {WPCmd PEAddress books} booklist]} {
131
WPCmd PEInfo statmsg "Cannot get list of Addressbooks"
133
set books [llength $booklist]
134
for {set i 0} {$i < $booklist} {incr i} {
136
set thisbook [lindex $booklist $i]
137
if {[catch {WPCmd PEAddress list [lindex $thisbook 0]} clist]} {
138
WPCmd PEInfo statmsg "Cannot get Contacts list: $clist"
141
if {[catch {WPCmd PEAddress format [lindex $thisbook 0]} format]} {
142
WPCmd PEInfo statmsg "Cannot get Contacts format: $format"
149
if {[info exists thisbook]} {
150
cgi_division class="clistContext" {
152
cgi_put "[cgi_span "class=sp spfcl spfcl1" [cgi_span "style=display:none;" "Folders: "]][cgi_span "Contact List"]"
154
cgi_put "[cgi_span "class=sp spfcl spfcl1" "style=border-bottom: 1px solid #003399;" [cgi_span "style=display:none;" "Contacts: "]]"
155
cgi_put [cgi_span id=clistName [lindex $thisbook 1]]
159
cgi_division class=clistContacts id=clistContacts {
160
cgi_table cellspacing="0" cellpadding="0" "class=\"listTbl divider clt\"" {
162
if {![string compare $hdr on]} {
163
cgi_table_row "class=\"contactHeader\"" {
164
cgi_table_head "class=\"wap colHdr\"" {}
165
foreach field $format {
166
cgi_table_head "class=\"wap colHdr lt\"" {
167
switch -- [lindex $field 0] {
172
cgi_puts "Display Name"
173
if {0 == [string compare $canedit on]} {
174
cgi_puts " (click to edit)"
179
if {0 == [string compare $sendto on]} {
180
cgi_puts " (click email to send)"
184
cgi_puts [index $field 0]
193
foreach contact $clist {
194
cgi_table_row "class=\"clr\"" {
195
set nfields [llength $format]
197
cgi_table_data class=wap {
198
set label "ab${abook}.${aindex}"
199
cgi_checkbox "nickList=$abook.$aindex.[lindex [lindex $contact 0] 0]" id=$label "onclick=\"return boxChecked(this);\""
202
for {set i 0} {$i < $nfields} {incr i} {
203
set field [lindex $format $i]
204
set data [lindex $contact [expr $i + 1]]
206
cgi_table_data "class=\"wap clcd\"" {
207
switch -- [lindex $field 0] {
209
switch -- [lindex [lindex $contact 0] 1] {
211
set addr [cgi_quote_html $data]
212
if {0 == [string compare $sendto on]} {
213
cgi_puts [cgi_url $addr compose?contacts=${abook}.${aindex} class=wap]
215
cgi_puts "<label for=$label>$addr</label>"
220
set addr [cgi_quote_html $addr]
221
if {0 == [string compare $sendto on]} {
222
cgi_puts "[cgi_url $addr compose?contacts=${abook}.${aindex} class=wap][cgi_nl]"
227
cgi_puts "Unknown contact type"
232
if {[string length $data]} {
233
if {0 == [string compare $canedit on]} {
234
cgi_puts [cgi_url [cgi_quote_html $data] # "onClick=return editContact({book:${abook},index:${aindex}});" class=wap]
236
cgi_puts "<label for=$label>[cgi_quote_html $data]</label>"
239
cgi_puts [cgi_nbspace]
243
if {[string length $data]} {
244
cgi_puts "<label for=$label>[cgi_quote_html $data]</label>"
246
cgi_puts [cgi_nbspace]
259
WPCmd PEInfo statmsg "Unknown Address Book"
263
wpStatusAndNewmailJavascript
264
cgi_puts "if(window.updateContactCount) updateContactCount('$books','[llength $clist]');"