Index: openacs-4/contrib/packages/mailing-lists/www/madmin/list-subscribe.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/mailing-lists/www/madmin/list-subscribe.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/mailing-lists/www/madmin/list-subscribe.tcl 21 Jan 2004 19:22:15 -0000 1.2 +++ openacs-4/contrib/packages/mailing-lists/www/madmin/list-subscribe.tcl 21 Jan 2004 23:24:47 -0000 1.3 @@ -1,116 +1,115 @@ -ad_page_contract { -} - -set user_id [ad_maybe_redirect_for_registration] -set package_id [ad_conn package_id] -permission::require_permission -object_id $package_id -privilege mailing_list_admin - -set context_bar [list [list "." Administration] "Mass Subscribe to Mailing List"] - -set lists [db_list_of_lists get_mailing_lists {}] - - -ad_form -name list_mass_subscribe_form -action list-subscribe -form { - {list_id:text(select) {label "Mailing List"} {options $lists}} - {xx:text(inform) {label " "} {value "Enter emails, first names and last names as a list (csv)"}} - {emails:text(textarea) {label "Emails"} {html {rows 30 cols 80}}} - {confirmation_p:text(checkbox),optional {label "Send confirmation?"} {options {{"Yes" t}}}} - {no_emails_p:text(checkbox),optional {label "Suppress all emails?"} {options {{"Yes" t}}}} -} -validate { - {emails { - [empty_string_p [set invalid_list [mailing_list::util::check_valid_emails -emails $emails]]]} - "Invalid emails: [join $invalid_list , ]"} -} -on_submit { - permission::require_permission -object_id $list_id -privilege read - - if {[exists_and_not_null no_emails_p]} { - set no_emails_p t - set confirmed_p t - } else { - set no_emails_p f - if {[exists_and_not_null confirmation_p]} { - set confirmed_p f - } else { - set confirmed_p t - } - } - - set default_first_names "first_names" - set default_last_name "last_name" - - db_1row get_list_mail_data {} - - # generate tmp-file for csv-processing - set tmp_file [ns_tmpnam] - set fd [open $tmp_file w] - puts $fd $emails - close $fd - set fd [open $tmp_file r] - - set unsubscribe_link "[ad_url][ad_conn package_url]" - - db_transaction { - # process every line of the email list - while {[ns_getcsv $fd line] > 0} { - - set user_id "" - # grap the email of the current line - util_unlist $line email user_first_names user_last_name - if {[empty_string_p "$user_first_names$user_last_name"]} { - set user_first_names $default_first_names - set user_last_name $default_last_name - } - - # check if user already exists - set user_id [db_string get_user_id {} -default ""] - - if {[empty_string_p $user_id]} { - # user doesn't exist, so create him - set user_password [ad_generate_random_string] - set user_id [db_nextval acs_object_id_seq] - - array set creation_info [auth::create_user \ - -user_id $user_id \ - -email $email \ - -first_names $user_first_names \ - -last_name $user_last_name \ - -password $user_password \ - -email_verified_p $confirmed_p] - - if {$creation_info(creation_status) != "ok"} { - # something went wrong during user creation - ns_log notice "list-subscribe: could not create user $email: $creation_info(element_messages)" - } - array unset creation_info - } else { - set user_password "" - } - - set confirmation_link "[ad_url][ad_conn package_url]confirm?[export_url_vars list_id user_id]" - - # subscribe user. check if user already has a map entry - if {[mailing_list::add_user -list_id $list_id -user_id $user_id -confirmed_p $confirmed_p]} { - if {$no_emails_p == "f"} { - # user is newly added to this list - # now send confirmation message to user if requested - if {$confirmed_p == "f"} { - mailing_list::util::send_mail -user_id $user_id -from_email $sender_email -subject $confirm_subject -body $confirm_body -mime_type $confirm_mime_type -charset $mime_charset -link $confirmation_link -new_password $user_password - } else { - # send welcome message if no confirmation needed - mailing_list::util::send_mail -user_id $user_id -from_email $sender_email -subject $welcome_subject -body $welcome_body -mime_type $welcome_mime_type -charset $mime_charset -link "$unsubscribe_link?[export_url_vars user_id]" -new_password $user_password - } - } - } - } - } - - # remove tmp-file for csv processing - close $fd - ns_unlink $tmp_file -} -after_submit { - ad_returnredirect "." - ad_script_abort -} - -ad_return_template - +ad_page_contract { +} + +set user_id [ad_maybe_redirect_for_registration] +set package_id [ad_conn package_id] +permission::require_permission -object_id $package_id -privilege mailing_list_admin + +set context_bar [list [list "." Administration] "Mass Subscribe to Mailing List"] + +set lists [db_list_of_lists get_mailing_lists {}] + + +ad_form -name list_mass_subscribe_form -action list-subscribe -form { + {list_id:text(select) {label "Mailing List"} {options $lists}} + {xx:text(inform) {label " "} {value "Enter emails, first names and last names as a list (csv)"}} + {emails:text(textarea) {label "Emails"} {html {rows 30 cols 80}}} + {confirmation_p:text(checkbox),optional {label "Send confirmation?"} {options {{"Yes" t}}}} + {no_emails_p:text(checkbox),optional {label "Suppress all emails?"} {options {{"Yes" t}}}} +} -validate { + {emails { + [empty_string_p [set invalid_list [mailing_list::util::check_valid_emails -emails $emails]]]} + "Invalid emails: [join $invalid_list , ]"} +} -on_submit { + permission::require_permission -object_id $list_id -privilege read + + if {[exists_and_not_null no_emails_p]} { + set no_emails_p t + set confirmed_p t + } else { + set no_emails_p f + if {[exists_and_not_null confirmation_p]} { + set confirmed_p f + } else { + set confirmed_p t + } + } + + set default_first_names "first_names" + set default_last_name "last_name" + + db_1row get_list_mail_data {} + + # generate tmp-file for csv-processing + set tmp_file [ns_tmpnam] + set fd [open $tmp_file w] + puts $fd $emails + close $fd + set fd [open $tmp_file r] + + set unsubscribe_link "[ad_url][ad_conn package_url]" + + db_transaction { + # process every line of the email list + while {[ns_getcsv $fd line] > 0} { + + set user_id "" + # grap the email of the current line + util_unlist $line email user_first_names user_last_name + if {[empty_string_p "$user_first_names$user_last_name"]} { + set user_first_names $default_first_names + set user_last_name $default_last_name + } + + # check if user already exists + set user_id [db_string get_user_id {} -default ""] + + if {[empty_string_p $user_id]} { + # user doesn't exist, so create him + set user_password [ad_generate_random_string] + set user_id [db_nextval acs_object_id_seq] + + array set creation_info [auth::create_user \ + -user_id $user_id \ + -email $email \ + -first_names $user_first_names \ + -last_name $user_last_name \ + -password $user_password \ + -email_verified_p $confirmed_p] + + if {$creation_info(creation_status) != "ok"} { + # something went wrong during user creation + ns_log notice "list-subscribe: could not create user $email: $creation_info(element_messages)" + } + array unset creation_info + } else { + set user_password "" + } + + set confirmation_link "[ad_url][ad_conn package_url]confirm?[export_url_vars list_id user_id]" + + # subscribe user. check if user already has a map entry + if {[mailing_list::add_user -list_id $list_id -user_id $user_id -confirmed_p $confirmed_p]} { + if {$no_emails_p == "f"} { + # user is newly added to this list + # now send confirmation message to user if requested + if {$confirmed_p == "f"} { + mailing_list::util::send_mail -user_id $user_id -from_email $sender_email -subject $confirm_subject -body $confirm_body -mime_type $confirm_mime_type -charset $mime_charset -link $confirmation_link -new_password $user_password + } else { + # send welcome message if no confirmation needed + mailing_list::util::send_mail -user_id $user_id -from_email $sender_email -subject $welcome_subject -body $welcome_body -mime_type $welcome_mime_type -charset $mime_charset -link "$unsubscribe_link?[export_url_vars user_id]" -new_password $user_password + } + } + } + } + } + + # remove tmp-file for csv processing + close $fd + ns_unlink $tmp_file +} -after_submit { + ad_returnredirect "." + ad_script_abort +} + +ad_return_template \ No newline at end of file