summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/1.0/addredit.tcl
blob: d0fb3865d8b5779e68563a30294cf90023eb1839 (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
#!./tclsh
# $Id: addredit.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
#
# ========================================================================

#  addredit.tcl
#
#  Purpose:  CGI script to generate html form used to view/set
#	     individual addressbook entries
#
#  Input: 
set ae_vars {
    {book	{} -1}
    {nick       {} ""}
    {add        {} 0}
    {fn         {} ""}
    {addrs      {} ""}
    {fcc        {} ""}
    {comment    {} ""}
    {take       {} 0}
    {newnick    {} ""}
    {ai         {} -1}
}

set ae_fields {
    {0 "newnick" "Nickname<sup class=notice>*</sup>"}
    {1 "fn" "Full Name&nbsp;"}
    {2 "addrs" "Addresses<sup class=notice>*</sup>"}
    {3 "fcc" "Fcc&nbsp;"}
    {4 "comment" "Comments&nbsp;"}
}    

# inherit global config
source ./alpine.tcl
source cmdfunc.tcl

#  Output: 
#
#

set ae_menu {
  {
    {}
    {
      {
	cgi_image_button help=[WPimg help_trans] border=0 alt="Help"
      }
    }
  }
}

WPEval $ae_vars {

  if {$book < 0} {
    if {[catch {WPCmd PEInfo set ae_help_state} ae_help_state] == 0} {
      foreach v $ae_help_state {
	eval set [lindex $v 0] [list [lindex $v 1]]
      }

      set addrinfo [list "$newnick"  "$fn" [list "$addrs"] "$fcc" "$comment"]
      WPCmd PEInfo unset ae_help_state
    } else {
      return [list _action "Web Alpine" "Unspecified Address Book"]
    }
  }

  catch {WPCmd PEInfo unset ae_help_state}

  if {![info exists addrinfo]} {
    if {$take != 0} {
      set addrinfo [list "$newnick"  "$fn" [list "$addrs"] "$fcc" "$comment"]
    } elseif {$add == 0} {
      if {[catch {WPCmd PEAddress fullentry $book $nick $ai} addrinfo]} {
	if {[string length $addrinfo]} {
	  set entryerror "Address Error: $addrinfo"
	} else {
	  set entryerror "Nickname $nick does not exist"
	}

	set addrinfo [list "" "" [list ""] "" ""]
      }
    } else {
      set addrinfo [list "" "" [list ""] "" ""]
    }
  }

  cgi_http_head {
    WPStdHttpHdrs
  }

  cgi_html {
    cgi_head {
      WPStdHtmlHdr "Addressbook Update"
      WPStyleSheets
    }

    if {$take == 1} {
      set onload "onLoad=document.addredit.newnick.focus()"
    } else {
      set onload ""
    }

    cgi_body BGCOLOR="$_wp(bordercolor)" $onload {
      set books [WPCmd PEAddress books]
      set readwrite [lindex [lindex $books $book] 3]

      catch {WPCmd PEInfo set help_context addredit}
      cgi_table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%" {
	cgi_form $_wp(appdir)/$_wp(ui1dir)/wp method=post enctype=multipart/form-data name=addredit target=_top {
	  cgi_table_row {
	    #
	    # next comes the menu down the left side
	    #
	    eval {
	      cgi_table_data $_wp(menuargs) rowspan=1000 {
		WPTFCommandMenu ae_menu {}
	      }
	    }

	    cgi_table_row {
	      cgi_table_data valign=top width="100%" class=dialog {
		if {[info exists entryerror]} {
		  cgi_division class=notice align=center {
		    cgi_puts $entryerror
		  }
		}


		if {$take == 1} {
		  lappend tmptxt "Edit the new entry below as necessary (note, some are required).  To create a list entry, simply add each desired address to the [cgi_italic Addresses] field separated by a comma."
		  lappend tmptxt "When finished, click [cgi_italic Save] to update your address book, or [cgi_italic Cancel] to return to the message view."
		} elseif {$add == 1} {
		  lappend tmptxt "The address book entry editor is used to create a new address book entry.  Fill in the fields as desired below (note, some are required).  To create a list entry, simply add each desired address to the [cgi_italic Addresses] field separated by a comma."
		  lappend tmptxt "When finished, click [cgi_italic Save] to update your address book, or [cgi_italic Cancel] to return to your unchanged address book."
		} elseif {$readwrite == 0} {
		  set tmptxt "These are the current settings for the selected entry"
		} else {
		  lappend tmptxt "The address book entry editor is used to edit an existing address book entry.  Edit the fields as desired below (note, some are required)."
		  lappend tmptxt " then click [cgi_italic Save] to update your address book, or [cgi_italic Cancel] to return to your unchanged address book."
		}

		cgi_table align=center width=75% cellpadding=10 border=0 {
		  foreach t $tmptxt {
		    cgi_table_row {
		      cgi_table_data align=center {
			cgi_puts $t
		      }
		    }
		  }
		}

		cgi_table border=0 cellspacing=0 cellpadding=5 align=center {
		  cgi_text "page=addrsave" type=hidden notab

		  if {$take == 1} {
		    cgi_text "oncancel=main" type=hidden notab
		    cgi_text "take=1" type=hidden notab
		  } else {
		    cgi_text "oncancel=addrbook" type=hidden notab
		  }

		  cgi_text "book=$book" type=hidden notab
		  if {$add == 0} {cgi_text "nick=$nick" type=hidden notab}
		  if {$add != 0} {cgi_text "add=1" type=hidden notab}
		  cgi_text "ai=${ai}" type=hidden notab
		  cgi_text "cid=[WPCmd PEInfo key]" type=hidden notab

		  foreach fieldval $ae_fields {
		    cgi_table_row {
		      cgi_table_data valign=top align=right width="30%" class=dialog {
			#						    cgi_puts [cgi_font face=tahoma,verdana,geneva size=+1 "[lindex $fieldval 2]:"]
			cgi_puts [cgi_bold "[lindex $fieldval 2]:"]
		      }
		      cgi_table_data align=left {
			switch -regexp [lindex $fieldval 1] {
			  ^addrs$ {
			    set addrvals [lindex $addrinfo [lindex $fieldval 0]]
			    set line [join $addrvals ", "]
			    cgi_text "[lindex $fieldval 1]=${line}" size=50
			  }
			  default {
			    cgi_text "[lindex $fieldval 1]=[lindex $addrinfo [lindex $fieldval 0]]" size=50
			  }
			}
		      }
		    }
		  }
		  cgi_table_row {
		    cgi_table_data align=right {
		      cgi_puts [cgi_font class=notice size=-1 "* Required field"]
		    }
		  }
		  cgi_table_row {
		    cgi_table_data align=center colspan=2 {
		      if {$readwrite} {
			cgi_submit_button "save=Save Entry"
			cgi_put [cgi_img [WPimg dot2] border=0 alt="" width=10]
		      }

		      if {$readwrite && $add == 0 && $take == 0} {
			cgi_submit_button "delete=Delete Entry"
			cgi_put [cgi_img [WPimg dot2] border=0 alt="" width=10]
		      }

		      cgi_submit_button "cancel=Cancel"
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
}