~ubuntu-branches/debian/wheezy/alpine/wheezy

« back to all changes in this revision

Viewing changes to web/cgi/alpine-2.0/conduit/contactlist.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2010-10-03 15:31:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101003153155-2exypc96j1e8tw0p
Tags: 2.02-1
* New upstream release, based on re-alpine project
* Updated debian/copyright to reflect this fact
* re-alpine removed the non-free from the tarball, so now
  we do not repack the upstream tarball. (Yay!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!./tclsh
2
 
# $Id: contactlist.tcl 1150 2008-08-20 00:27:11Z mikes@u.washington.edu $
3
 
# ========================================================================
4
 
# Copyright 2008 University of Washington
5
 
#
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
9
 
#
10
 
#     http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
# ========================================================================
13
 
 
14
 
#  contactlist.tcl
15
 
#
16
 
#  Purpose:  CGI script that generates a page displaying a 
17
 
#            list of contacts in the requested address book
18
 
#
19
 
#  Input:    PATH_INFO: /booknumber
20
 
#            along with possible search parameters:
21
 
set contactlist_args {
22
 
  {op           {}      "noop"}
23
 
  {book         ""      0}
24
 
  {ai           ""      -1}
25
 
  {entryList    ""      ""}
26
 
  {contactNick  ""      ""}
27
 
  {origNick     ""      ""}
28
 
  {contactName  ""      ""}
29
 
  {contactEmail ""      ""}
30
 
  {contactFcc   ""      ""}
31
 
  {contactNotes ""      ""}
32
 
  {hdr          {}      "off"}
33
 
  {sendto       {}      "off"}
34
 
  {canedit      {}      "off"}
35
 
}
36
 
 
37
 
# inherit global config
38
 
source ../alpine.tcl
39
 
source ../common.tcl
40
 
 
41
 
# TEST
42
 
proc cgi_suffix {args} {
43
 
  return ""
44
 
}
45
 
 
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"
52
 
      }
53
 
    }
54
 
  }
55
 
}
56
 
 
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"
62
 
    } else {
63
 
      # grok parameters
64
 
      foreach item $contactlist_args {
65
 
        if {[catch {eval WPImport $item} importerr]} {
66
 
          set harderr "Cannot init session: $importerr"
67
 
          break
68
 
        }
69
 
      }
70
 
    }
71
 
  } else {
72
 
    set harderr "Bad Address Book Request: $env(PATH_INFO)"
73
 
  }
74
 
} else {
75
 
  set harderr "No Address Book Specified"
76
 
}
77
 
 
78
 
puts stdout "Content-type: text/html; charset=\"UTF-8\"\n"
79
 
 
80
 
if {[info exists harderr]} {
81
 
  puts stdout "<b>ERROR: $harderr</b>"
82
 
  exit
83
 
}
84
 
 
85
 
switch -- $op {
86
 
  delete {
87
 
    set result ""
88
 
    # grok delete format: \[(book)index\],
89
 
    if {[regexp {^[0-9\.,]+$} $entryList]} {
90
 
      # collect by book
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
95
 
        }
96
 
      }
97
 
 
98
 
      # delete by book in DECREASING index order
99
 
      if {[catch {deleteByBook delbooks} result] || [string length $result]} {
100
 
        WPCmd PEInfo statmsg "$result"
101
 
      } else {
102
 
        if {[llength $entryList] > 1} {
103
 
          WPCmd PEInfo statmsg "Contacts Deleted"
104
 
        } else {
105
 
          WPCmd PEInfo statmsg "Contact Deleted"
106
 
        }
107
 
      }
108
 
    } else {
109
 
      WPCmd PEInfo statmsg "Invalid entry list format: >>>>$entryList<<<<"
110
 
    }
111
 
  }
112
 
  add {
113
 
    if {[catch {WPCmd PEAddress edit $book $contactNick $ai $contactName $contactEmail $contactFcc $contactNotes 1} result]} {
114
 
      WPCmd PEInfo statmsg "Add failed: $result"
115
 
    }
116
 
  }
117
 
  change {
118
 
    if {[catch {WPCmd PEAddress edit $book $contactNick $ai $contactName $contactEmail $contactFcc $contactNotes 0 $origNick} result]} {
119
 
      WPCmd PEInfo statmsg "Change failed: $result"
120
 
    }
121
 
  }
122
 
  noop {
123
 
  }
124
 
  default {
125
 
    WPCmd PEInfo statmsg "Unrecognized option: $op"
126
 
  }
127
 
}
128
 
 
129
 
# remainder is director to list
130
 
if {[catch {WPCmd PEAddress books} booklist]} {
131
 
  WPCmd PEInfo statmsg "Cannot get list of Addressbooks"
132
 
} else {
133
 
  set books [llength $booklist]
134
 
  for {set i 0} {$i < $booklist} {incr i} {
135
 
    if {$i == $abook} {
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"
139
 
      }
140
 
 
141
 
      if {[catch {WPCmd PEAddress format [lindex $thisbook 0]} format]} {
142
 
        WPCmd PEInfo statmsg "Cannot get Contacts format: $format"
143
 
      }
144
 
 
145
 
      break
146
 
    }
147
 
  }
148
 
 
149
 
  if {[info exists thisbook]} {
150
 
    cgi_division class="clistContext" {
151
 
      if {$books == 1} {
152
 
        cgi_put "[cgi_span "class=sp spfcl spfcl1" [cgi_span "style=display:none;" "Folders: "]][cgi_span "Contact List"]"
153
 
      } else {
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]]
156
 
      }
157
 
    }
158
 
 
159
 
    cgi_division class=clistContacts id=clistContacts {
160
 
      cgi_table cellspacing="0" cellpadding="0" "class=\"listTbl divider clt\"" {
161
 
        cgi_puts "<tbody>"
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] {
168
 
                  nick {
169
 
                    cgi_puts "Nickname"
170
 
                  }
171
 
                  full {
172
 
                    cgi_puts "Display Name"
173
 
                    if {0 == [string compare $canedit on]} {
174
 
                      cgi_puts " (click to edit)"
175
 
                    }
176
 
                  }
177
 
                  addr {
178
 
                    cgi_put "Email"
179
 
                    if {0 == [string compare $sendto on]} {
180
 
                      cgi_puts " (click email to send)"
181
 
                    }
182
 
                  }
183
 
                  default {
184
 
                    cgi_puts [index $field 0]
185
 
                  }
186
 
                }
187
 
              }
188
 
            }
189
 
          }
190
 
        }
191
 
 
192
 
        set aindex 0
193
 
        foreach contact $clist {
194
 
          cgi_table_row "class=\"clr\"" {
195
 
            set nfields [llength $format]
196
 
 
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);\""
200
 
            }
201
 
 
202
 
            for {set i 0} {$i < $nfields} {incr i} {
203
 
              set field [lindex $format $i]
204
 
              set data [lindex $contact [expr $i + 1]]
205
 
 
206
 
              cgi_table_data "class=\"wap clcd\"" {
207
 
                switch -- [lindex $field 0] {
208
 
                  addr {
209
 
                    switch -- [lindex [lindex $contact 0] 1] {
210
 
                      single {
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]
214
 
                        } else {
215
 
                          cgi_puts "<label for=$label>$addr</label>"
216
 
                        }
217
 
                      }
218
 
                      list {
219
 
                        foreach addr $data {
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]"
223
 
                          }
224
 
                        }
225
 
                      }
226
 
                      default {
227
 
                        cgi_puts "Unknown contact type"
228
 
                      }
229
 
                    }
230
 
                  }
231
 
                  full {
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]
235
 
                      } else {
236
 
                        cgi_puts "<label for=$label>[cgi_quote_html $data]</label>"
237
 
                      }
238
 
                    } else {
239
 
                      cgi_puts [cgi_nbspace]
240
 
                    }
241
 
                  }
242
 
                  default {
243
 
                    if {[string length $data]} {
244
 
                      cgi_puts "<label for=$label>[cgi_quote_html $data]</label>"
245
 
                    } else {
246
 
                      cgi_puts [cgi_nbspace]
247
 
                    }
248
 
                  }
249
 
                }
250
 
              }
251
 
            }
252
 
          }
253
 
          incr aindex
254
 
        }
255
 
        cgi_puts "</tbody>"
256
 
      }
257
 
    }
258
 
  } else {
259
 
    WPCmd PEInfo statmsg "Unknown Address Book"
260
 
  }
261
 
}
262
 
cgi_puts "<script>"
263
 
wpStatusAndNewmailJavascript
264
 
cgi_puts "if(window.updateContactCount) updateContactCount('$books','[llength $clist]');"
265
 
cgi_puts "</script>"