1
# $Id: addrsave.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
2
# ========================================================================
3
# Copyright 2006 University of Washington
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# ========================================================================
15
# Purpose: CGI script to handle address book change/save
16
# via addredit generated form
20
{cid "Missing Command ID"}
35
foreach item $abs_vars {
36
if {[catch {cgi_import [lindex $item 0].x}]} {
37
if {[catch {eval WPImport $item} result]} {
38
error [list _action "Impart Variable" $result]
41
set [lindex $item 0] 1
45
if {$cid != [WPCmd PEInfo key]} {
46
catch {WPCmd PEInfo statmsg "Invalid Command ID"}
64
lappend ae_help_state [list [lindex $i 0] [subst $[lindex $i 0]]]
67
foreach i $save_vars {
69
lappend ae_help_state [list [lindex $i 0] [subst $[lindex $i 0]]]
72
WPCmd PEInfo set ae_help_state $ae_help_state
74
set _cgi_uservar(topic) takeedit
75
set _cgi_uservar(oncancel) addredit
77
set _cgi_uservar(index) none
82
} elseif {$save == 1 || [string compare [string tolower $save] "save entry"] == 0} {
90
if {[catch {cgi_import_cookie add}] != 0} {set add 0}
91
if {[catch {cgi_import_cookie nick}] != 0} {set nick ""}
93
if {![string length $newnick]} {
94
WPCmd PEInfo statmsg "No entry created. New entries must include a Nickname."
97
if {!$take || [catch {WPCmd PEAddress entry $book $newnick $ai} result] || ![llength $result]} {
99
if {[catch {WPCmd PEAddress edit $book $newnick $ai $fn $addrs $fcc $comment $add $nick} result]} {
100
catch {WPCmd PEInfo statmsg "Address Set Failure: $result"}
102
} elseif {[string length $result]} {
103
catch {WPCmd PEInfo statmsg "$result"}
108
if {[info exists adderr]} {
109
WPCmd PEInfo statmsg "No address book entry changed: $adderr"
111
WPCmd PEInfo statmsg "New address book entry \"$newnick\" created."
118
if {$take == 1 && ![info exists src]} {
122
} elseif {$delete == 1 || [string compare [string tolower $delete] "delete entry"] == 0} {
128
if {[catch {WPCmd PEAddress delete $book $nick $ai} result]} {
129
catch {WPCmd PEInfo statmsg "Address Set Failure $result"}
130
} elseif {[string compare $result ""]} {
131
catch {WPCmd PEInfo statmsg "$result"}
133
} elseif {[string compare [string tolower $replace] "replace entry"] == 0} {
142
if {[catch {cgi_import_cookie add}] != 0} {set add 0}
143
if {[catch {cgi_import_cookie nick}] != 0} {set nick ""}
145
if {![string length $newnick]} {
146
WPCmd PEInfo statmsg "No entry created. New entries must include a Nickname."
149
if {[catch {WPCmd PEAddress delete $book $newnick $ai} result]} {
153
if {[catch {WPCmd PEAddress edit $book $newnick $ai $fn $addrs $fcc $comment $add $nick} result]} {
154
catch {WPCmd PEInfo statmsg "Address Set Failure result"}
156
} elseif {[string length $result]} {
157
catch {WPCmd PEInfo statmsg "$result"}
163
if {[info exists adderr]} {
164
WPCmd PEInfo statmsg "No address book entry changed: $adderr."
166
WPCmd PEInfo statmsg "Address book entry \"$newnick\" replaced."
169
if {![info exists src]} {
174
} elseif {[string compare [string tolower $replace] "add to entry"] == 0} {
182
if {[catch {cgi_import_cookie add}] != 0} {set add 0}
183
if {[catch {cgi_import_cookie nick}] != 0} {set nick ""}
185
if {![string length $newnick]} {
186
WPCmd PEInfo statmsg "No entry created. New entries must include a Nickname."
189
if {[catch {WPCmd PEAddress fullentry $book $newnick $ai} result] || ![llength $result]} {
190
if {[string length $result]} {
193
set adderr "No pre-existing entry"
196
set fn [lindex $result 1]
197
set newaddrs [join [lindex $result 2] ","]
198
append newaddrs ", $addrs"
199
set fcc [lindex $result 3]
200
set comment [lindex $result 4]
202
if {[catch {WPCmd PEAddress edit $book $newnick $ai $fn $newaddrs $fcc $comment 0 $newnick} result]} {
204
} elseif {[string length $result]} {
205
catch {WPCmd PEInfo statmsg "$result"}
211
if {[info exists adderr]} {
212
WPCmd PEInfo statmsg "No address book entry created: $adderr."
214
WPCmd PEInfo statmsg "Address book entry \"$newnick\" appended"
217
if {![info exists src]} {
222
} elseif {[string compare [string tolower $replace] edit] == 0} {
224
} elseif {$compose == 1} {
225
set oncancel addrbook
227
} elseif {$cancel == 1 || [string compare [string tolower $cancel] cancel] == 0} {
229
set act "Take Address"
231
set act "Address Edit"
234
catch {WPCmd PEInfo statmsg "$act cancelled. Address book unchanged."}
237
catch {WPCmd PEInfo statmsg "Unknown Address Book Operation"}
240
if {![info exists src]} {
244
source [WPTFScript $src]