Index: openacs-4/contrib/packages/photobook/www/new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/photobook/www/new.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/photobook/www/new.tcl 3 Nov 2003 20:10:56 -0000 1.1 +++ openacs-4/contrib/packages/photobook/www/new.tcl 18 Mar 2004 22:45:43 -0000 1.2 @@ -19,6 +19,11 @@ set efl {} +set name_display_mode "" +set alias_display_mode "" +set only_one_msg "" +set existing_efl_p 0 +set existing_alias_p 0 if {[empty_string_p $item_id] && [ db_0or1row current_data { select item_id, latest_revision @@ -31,13 +36,26 @@ select efl, alias, outside from sloan_email where user_id = :user_id } ] } { - # Is this users email or alias already defined - if {![string equal {} $efl] - || ![string equal {} $alias] - } { - ad_returnredirect "[phb::package_url]ae?form_type=a" - ad_script_abort - } + # handle case where they already have an EFL and/or an alias defined + if {![string equal {} $efl]} { + # they have an EFL but might not have an alias + if {![string equal {} $alias]} { + # they do have both, send them on their way + ad_returnredirect + ad_script_abort + } else { + set existing_efl_p 1 + set name_display_mode "display" + set only_one_msg "

You already have an EFL, so we just need you to enter your alias:

" + } + } else { + # no efl, but perhaps an alias + if {![string equal {} $alias]} { + set existing_alias_p 1 + set alias_display_mode "display" + set only_one_msg "

You already have an alias, so we just need you to enter your name for your EFL:

" + } + } } if {[empty_string_p $item_id]} { @@ -51,6 +69,8 @@ ad_return_error Error "User id $user_id does not exist" ad_script_abort } +# get alias if user already has one +set alias [db_string get-alias "select alias from sloan_email where user_id = :user_id" -default ""] ad_form -name new-user -export { item_id @@ -64,25 +84,28 @@ return_url } -form { {first_name:text(text) + {mode $name_display_mode} {label "First name"} {html {size 60 maxsize 200}} {value {[lindex $first_names 0]}} } - {middle_name:text(text) + {middle_name:text(text),optional + {mode $name_display_mode} {label "Middle names"} {html {size 60 maxsize 200}} {value {[lrange $first_names 1 end]}} - {optional} } {last_name:text(text) + {mode $name_display_mode} {label "Last name"} {html {size 60 maxsize 200}} {value $last_name} } - {alias:text(text) + {alias:text(text),optional + {mode $alias_display_mode} {label "Choose an email alias"} {html {size 60 maxsize 200}} - {optional} + {value $alias} } } -validate { {alias {[regexp {^[A-Za-z0-9_]*$} [string trim $alias]]} {Your email alias may only contain letters, numbers, and "_".}} @@ -98,7 +121,9 @@ db_transaction { # Need to lock excl the email table here. - phb::email_available $alias [ad_conn user_id] + if { !$existing_alias_p } { + phb::email_available $alias [ad_conn user_id] + } if {[empty_string_p $efl]} { set efl [phb::get_sloan_efl $first_name $middle_name $last_name $user_id] } @@ -108,7 +133,11 @@ cr::item::set_latest_revision_live -item_id $id # create the email record - db_dml create_sloan_email {insert into sloan_email(user_id, efl, alias, outside, last_updated) values (:user_id, :efl, :alias, :outside, sysdate)} + if { [db_string email_row_ck "select count(*) from sloan_email where user_id = :user_id"] == 0 } { + db_dml insert_sloan { insert into sloan_email (user_id, outside, efl, alias, last_updated) values (:user_id, :outside, :efl, :alias, sysdate) } + } else { + db_dml update_sloan { update sloan_email set outside = :outside, efl = :efl, alias = :alias, last_updated = sysdate where user_id = :user_id} + } set email_alias "$alias@sloan.mit.edu" db_dml update_default_mail { update parties set email = :email_alias where party_id = :user_id }