Index: openacs-4/packages/dotlrn/dotlrn.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/dotlrn.info,v diff -u -N -r1.50 -r1.51 --- openacs-4/packages/dotlrn/dotlrn.info 12 Feb 2002 01:23:25 -0000 1.50 +++ openacs-4/packages/dotlrn/dotlrn.info 14 Feb 2002 18:03:07 -0000 1.51 @@ -104,6 +104,7 @@ + @@ -178,6 +179,8 @@ + + @@ -189,9 +192,13 @@ + + + + @@ -279,6 +286,7 @@ + Index: openacs-4/packages/dotlrn/tcl/dotlrn-security-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/dotlrn-security-procs.tcl,v diff -u -N -r1.24 -r1.25 --- openacs-4/packages/dotlrn/tcl/dotlrn-security-procs.tcl 11 Feb 2002 20:17:52 -0000 1.24 +++ openacs-4/packages/dotlrn/tcl/dotlrn-security-procs.tcl 14 Feb 2002 18:03:07 -0000 1.25 @@ -12,7 +12,8 @@ Procs to manage DOTLRN Security - @author ben@openforce.net + @author Ben Adida (ben@openforce.net) + @author yon (yon@milliped.com) @creation-date 2001-10-30 @version $Id$ @@ -132,7 +133,7 @@ } ad_proc -public user_remove { - user_id + {-user_id:required} } { Remove a user from the set of dotLRN users } { @@ -143,6 +144,42 @@ } } + ad_proc -public users_remove { + {-users:required} + } { + Remove a set of users from dotLRN + } { + db_transaction { + foreach user $users { + user_remove -user_id $user + } + } + } + + ad_proc -public remove_user_completely { + {-user_id:required} + } { + Remove the user from ACS as well + } { + if {[user_p -user_id $user_id]} { + user_remove -user_id $user_id + } + + acs_user::delete -user_id $user_id + } + + ad_proc -public remove_users_completely { + {-users:required} + } { + Remove a set of users from the ACS + } { + db_transaction { + foreach user $users { + remove_user_completely -user_id $user + } + } + } + ad_proc -private user_get_type { user_id } { Index: openacs-4/packages/dotlrn/tcl/spam-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/spam-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/tcl/spam-procs.tcl 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,150 @@ +# dotlrn/tcl/spam-procs.tcl + +ad_library { + + Spam support procedures. + + @author yon (yon@openforce.net) + @creation-date 2002-02-13 + @version $Id: spam-procs.tcl,v 1.1 2002/02/14 18:03:07 yon Exp $ + +} + +namespace eval spam { + + ad_proc -public interpolate { + {-values:required} + {-text:required} + } { + Interpolates a set of values into a string. + + @param values a list of tuples, each one consisting of a target string + and the value it is to be replaced with. + @param text the string that is to be interpolated + + @return the interpolated string + } { + foreach tuple $values { + regsub -all [lindex $tuple 0] $text [lindex $tuple 1] text + } + + return $text + } + + ad_proc -public send { + {-recepients:required} + {-from:required} + {-real_from:required} + {-subject:required} + {-message:required} + {-message_values:required} + } { + Send a spam to a set of users. + + @param recepients a list of party_id's; the recepients. + @param from email address to set as "From" + @param real_from real address of the sender to use in case of + errors. + @param subject the subject of the email + @param message the body of the email + @param message_values a list of tuples of key/value pairs to + interpolate into the email + } { + + set subject [interpolate -values $message_values -text $subject] + set message [interpolate -values $message_values -text $message] + + # loop through all the recepients and send them the spam + set errors "" + db_foreach select_recepient_info " + select parties.email, + decode(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + decode(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name + from parties, + acs_objects + where party_id in ([join $recepients ,]) + and parties.party_id = acs_objects.object_id + " { + # replace some values in the subject and the message + set values [list] + lappend values [list {} $email] + lappend values [list {} $first_names] + lappend values [list {} $last_name] + + set subject [interpolate -values $values -text $subject] + set message [interpolate -values $values -text $message] + + # send the email + if {[catch {ns_sendmail $email $from $subject $message} errmsg]} { + append errors " +

+Failed to deliver to $email because: +

+ [ad_quotehtml $errmsg] +
+

+ " + } + } + + # if there were any errors sending the emails, then send an email to the + # sender letting them know. + if {![empty_string_p $errors]} { + set error_subject "There were errors with this spam" + set error_message " +

+There were errors with this spam. +

+ +

+The attempted message was: +

+ +

+ + + + + + + + + +
Subject$subject
Message$message
+

+ +

+The errors were: +

+ +

+$errors +

+ " + + if {[catch {ns_sendmail $real_from $real_from $error_subject $error_message} errmsg]} { + ad_return_error $error_subject $error_message + ad_script_abort + } + } + } + +} Index: openacs-4/packages/dotlrn/www/spam-variables.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/spam-variables.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/spam-variables.adp 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,43 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
The following variables can be used to insert user/community specific data:
<sender_email> = Sender's Email Address
<community_name> = Community's Name
<community_url> = Community's Web Address
<email> = Recepient's Email
<first_names> = Recepient's First Name
<last_name> = Recepient's Last Name
+
Index: openacs-4/packages/dotlrn/www/spam.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/spam.adp,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/dotlrn/www/spam.adp 28 Jan 2002 21:57:52 -0000 1.7 +++ openacs-4/packages/dotlrn/www/spam.adp 14 Feb 2002 18:03:07 -0000 1.8 @@ -8,60 +8,4 @@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following variables can be used to insert user/community specific data:
<sender_email> = Sender's Email Address
<community_name> = Community's Name
<community_url> = Community's Web Address
<email> = Recepient's Email
<first_names> = Recepient's First Name
<last_name> = Recepient's Last Name
-
+ Index: openacs-4/packages/dotlrn/www/spam.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/spam.tcl,v diff -u -N -r1.5 -r1.6 --- openacs-4/packages/dotlrn/www/spam.tcl 31 Jan 2002 17:05:35 -0000 1.5 +++ openacs-4/packages/dotlrn/www/spam.tcl 14 Feb 2002 18:03:07 -0000 1.6 @@ -86,82 +86,21 @@ set community_url [dotlrn_community::get_community_url $community_id] # replace some values in the subject and the message - regsub -all {} $subject $from subject - regsub -all {} $message $from message -# regsub -all {} $subject $sender_first_names subject -# regsub -all {} $message $sender_first_names message -# regsub -all {} $subject $sender_last_name subject -# regsub -all {} $message $sender_last_name message - regsub -all {} $subject $community_name subject - regsub -all {} $message $community_name message - regsub -all {} $subject $community_url subject - regsub -all {} $message $community_url message + set message_values [list] + lappend message_values [list {} $from] + lappend message_values [list {} $community_name] + lappend message_values [list {} $community_url] - # loop through all the recepeints and send them the spam - set errors "" - db_foreach select_recepient_info {} { - # replace some values in the subject and the message - regsub -all {} $subject $email subject - regsub -all {} $message $email message - regsub -all {} $subject $first_names subject - regsub -all {} $message $first_names message - regsub -all {} $subject $last_name subject - regsub -all {} $message $last_name message + set recepients [db_list select_recepients {}] - # send the email - if {[catch {ns_sendmail $email $from $subject $message} errmsg]} { - append errors " -

- Failed to deliver to $email because: -

- [ad_quotehtml $errmsg] -
-

- " - } - } + spam::send \ + -recepients $recepients \ + -from $from \ + -real_from $sender_email \ + -subject $subject \ + -message $message \ + -message_values $message_values - # if there were any errors sending the emails, then send an email to the - # sender letting them know. - if {![empty_string_p $errors]} { - set error_subject "There were errors spamming community \"$community_name\"" - set error_message " -

-There were errors spamming community \"$community_name\". -

- -

-The attempted message was: -

- -

- - - - - - - - - -
Subject$subject
Message$message
-

- -

-The errors were: -

- -

-$errors -

- " - - if {[catch {ns_sendmail $sender_email $sender_email $error_subject $error_message} errmsg]} { - ad_return_error $error_subject $error_message - ad_script_abort - } - } - ad_returnredirect $referer ad_script_abort } Index: openacs-4/packages/dotlrn/www/spam.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/spam.xql,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/dotlrn/www/spam.xql 31 Jan 2002 17:05:35 -0000 1.2 +++ openacs-4/packages/dotlrn/www/spam.xql 14 Feb 2002 18:03:07 -0000 1.3 @@ -10,6 +10,17 @@ + + + select parties.party_id + from party_approved_member_map, + parties + where party_approved_member_map.party_id = :segment_id + and party_approved_member_map.member_id <> :segment_id + and party_approved_member_map.member_id = parties.party_id + + + select parties.email, Index: openacs-4/packages/dotlrn/www/admin/user-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/user-edit.tcl,v diff -u -N -r1.10 -r1.11 --- openacs-4/packages/dotlrn/www/admin/user-edit.tcl 11 Feb 2002 19:33:17 -0000 1.10 +++ openacs-4/packages/dotlrn/www/admin/user-edit.tcl 14 Feb 2002 18:03:07 -0000 1.11 @@ -64,13 +64,20 @@ db_transaction { # remove the user - dotlrn::user_remove $user_id + dotlrn::user_remove -user_id $user_id # add the user - dotlrn::user_add -id $id -type $type -access_level $access_level -user_id $user_id + dotlrn::user_add \ + -id $id \ + -type $type \ + -access_level $access_level \ + -user_id $user_id # Update permissions - acs_privacy::set_user_read_private_data -user_id $user_id -object_id [dotlrn::get_package_id] -value $read_private_data_p + acs_privacy::set_user_read_private_data \ + -user_id $user_id \ + -object_id [dotlrn::get_package_id] \ + -value $read_private_data_p } # redirect Index: openacs-4/packages/dotlrn/www/admin/users-add-to-community.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-add-to-community.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-add-to-community.adp 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,5 @@ + +Add Users to Community +@context_bar@ + + Index: openacs-4/packages/dotlrn/www/admin/users-add-to-community.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-add-to-community.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-add-to-community.tcl 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,61 @@ +# dotlrn/www/admin/add-users-to-community.tcl + +ad_page_contract { + Add a set of users to a community + + @author yon (yon@openforce.net) + @creation-date 2002-02-10 + @version $Id: users-add-to-community.tcl,v 1.1 2002/02/14 18:03:07 yon Exp $ +} -query { + users + {referer "users-search"} +} -properties { + context_bar:onevalue +} + +set context_bar {{users Users} {users-search {User Search}} {Add Users to Community}} + +form create select_community + +element create select_community users \ + -label " " \ + -datatype text \ + -widget hidden \ + -value $users + +set communities [db_list_of_lists select_all_communities { + select pretty_name, community_id + from dotlrn_communities +}] + +if {[llength $communities]} { + element create select_community community_id \ + -label "Add to" \ + -datatype text \ + -widget select \ + -options "{{} {}} $communities" +} else { + element create select_community community_id \ + -label "No communities to add to" \ + -datatype text \ + -widget hidden \ + -value "" +} + +if {[form is_valid select_community]} { + form get_values select_community \ + users community_id + + if {![empty_string_p $community_id]} { + db_transaction { + foreach user $users { + dotlrn_community::add_user $community_id $user + } + } + } + + ad_returnredirect $referer + ad_script_abort +} + +ad_return_template Index: openacs-4/packages/dotlrn/www/admin/users-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-delete.adp 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,9 @@ + +Delete Users +@context_bar@ + +

+ Are you sure you want to delete the selected users? +

+ + Index: openacs-4/packages/dotlrn/www/admin/users-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-delete.tcl 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,36 @@ +# dotlrn/www/admin/users-delete.tcl + +ad_page_contract { + Delete a set of users. + + @author yon (yon@openforce.net) + @creation-date 2002-02-14 + @version $Id: users-delete.tcl,v 1.1 2002/02/14 18:03:07 yon Exp $ +} -query { + users + {referer "users-search"} +} -properties { + context_bar:onevalue +} + +set context_bar {{users Users} {users-search {User Search}} {Delete Users}} + +form create confirm_delete + +element create confirm_delete users \ + -label " " \ + -datatype text \ + -widget hidden \ + -value $users + +if {[form is_valid confirm_delete]} { + form get_values confirm_delete \ + users + + dotlrn::remove_users_completely -users $users + + ad_returnredirect $referer + ad_script_abort +} + +ad_return_template Index: openacs-4/packages/dotlrn/www/admin/users-search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-search.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/dotlrn/www/admin/users-search.tcl 12 Feb 2002 19:08:08 -0000 1.2 +++ openacs-4/packages/dotlrn/www/admin/users-search.tcl 14 Feb 2002 18:03:07 -0000 1.3 @@ -10,6 +10,7 @@ {type "any"} {join_criteria "and"} {n_users 0} + {action "none"} } -properties { context_bar:onevalue is_request:onevalue @@ -25,36 +26,33 @@ -datatype text \ -widget checkbox -set communities [db_list_of_lists select_all_communities { - select pretty_name, community_id - from dotlrn_communities -}] +element create user_search_results action \ + -label "Action" \ + -datatype text \ + -widget radio \ + -options { + {None none} + {{Spam ...} spam} + {{Delete ...} delete} + {{Add to community ...} add_to_community} + } \ + -value $action -if {[llength $communities]} { - element create user_search_results community_id \ - -label "Add to" \ - -datatype text \ - -widget select \ - -options "{{} {}} $communities" -} else { - element create user_search_results community_id \ - -label "No communities to add to" \ - -datatype text \ - -widget hidden \ - -value "" -} - if {[form is_valid user_search_results]} { - form get_values user_search_results community_id + form get_values user_search_results action set selected_users [element get_values user_search_results selected_users] - if {![empty_string_p $community_id]} { - db_transaction { - foreach selected_user $selected_users { - dotlrn_community::add_user $community_id $selected_user - } + switch -exact $action { + "spam" { + ad_returnredirect "users-spam?[export_vars {{users $selected_users}}]" } + "delete" { + ad_returnredirect "users-delete?[export_vars {{users $selected_users}}]" + } + "add_to_community" { + ad_returnredirect "users-add-to-community?[export_vars {{users $selected_users}}]" + } } } Index: openacs-4/packages/dotlrn/www/admin/users-spam.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-spam.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-spam.adp 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,7 @@ + +Spam Users +@context_bar@ + + + + Index: openacs-4/packages/dotlrn/www/admin/users-spam.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/admin/users-spam.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn/www/admin/users-spam.tcl 14 Feb 2002 18:03:07 -0000 1.1 @@ -0,0 +1,85 @@ +# dotlrn/www/admin/users-spam.tcl + +ad_page_contract { + Spam a set of users. + + @author yon (yon@openforce.net) + @creation-date 2002-02-14 + @version $Id: users-spam.tcl,v 1.1 2002/02/14 18:03:07 yon Exp $ +} -query { + users + {referer "users-search"} +} -properties { + context_bar:onevalue +} + +set context_bar {{users Users} {users-search {User Search}} {Spam Users}} + +set sender_id [ad_conn user_id] + +db_1row select_sender_info { + select parties.email as sender_email, + persons.first_names as sender_first_names, + persons.last_name as sender_last_name + from parties, + persons + where parties.party_id = :sender_id + and persons.person_id = :sender_id +} + +form create spam_message + +element create spam_message users \ + -label " " \ + -datatype text \ + -widget hidden \ + -value $users + +element create spam_message from \ + -label From \ + -datatype text \ + -widget text \ + -html {size 60} \ + -value $sender_email + +element create spam_message subject \ + -label Subject \ + -datatype text \ + -widget text \ + -html {size 60} + +element create spam_message message \ + -label Message \ + -datatype text \ + -widget textarea \ + -html {rows 10 cols 80 wrap soft} + +element create spam_message referer \ + -label Referer \ + -datatype text \ + -widget hidden \ + -value $referer + +if {[form is_valid spam_message]} { + form get_values spam_message \ + users from subject message referer + + # YON: should redirect and close the connection here so that the user + # doesn't have to wait for the emails to get sent out. + + set message_values [list] + lappend message_values [list {} $from] + + spam::send \ + -recepients $users \ + -from $from \ + -real_from $sender_email \ + -subject $subject \ + -message $message \ + -message_values $message_values + + ad_returnredirect $referer + ad_script_abort +} + +ad_return_template