Index: openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.tcl 2 Oct 2013 07:23:44 -0000 1.1 @@ -0,0 +1,241 @@ + +ad_proc -private ad_user_class_query { set_id } { + Takes an ns_set of key/value pairs and produces a query for the class of users specified (one user per row returned). + + @param set_id The id of a ns_set containing all the parameters of the user class. + + +} { + # we might need this + set where_clauses [list] + set join_clauses [list] + set group_clauses [list] + set having_clauses [list] + set tables [list users] + + # turn all the parameters in the ns_set into tcl vars + ad_ns_set_to_tcl_vars -duplicates fail $set_id + + # if we are using a user_class, just get the info + + # Get all the non-LOB columns. + set user_columns [list] + foreach column [db_columns users] { + if { $column ne "portrait" && $column ne "portrait_thumbnail" } { + lappend user_columns "users.$column" + } + } + + if { [info exists count_only_p] && $count_only_p } { + set select_list "count(users.user_id)" + } else { + set select_list $user_columns + } + + if { [info exists include_contact_p] && $include_contact_p} { + lappend select_list "user_contact_summary(users.user_id) as contact_summary" + } + if { [info exists include_demographics_p] && $include_demographics_p} { + lappend select_list "user_demographics_summary(users.user_id) as demographics_summary" + } + + if { [info exists user_class_id] && $user_class_id ne "" } { + set sql_post_select [db_string sql_post_select_for_user_class " + select sql_post_select + from user_classes where user_class_id = [ns_dbquotevalue $user_class_id] + "] + + return "select [join $select_list ",\n "]\n$sql_post_select" + } + + if { [info exists sql_post_select] && $sql_post_select ne "" } { + return "select [join $select_list ",\n "]\n$sql_post_select" + } + + foreach criteria [ad_user_class_parameters] { + if { [info exists $criteria] && [set $criteria] ne "" } { + switch $criteria { + "category_id" { + if {"users_interests" ni $tables} { + lappend tables "users_interests" + lappend join_clauses "users.user_id = users_interests.user_id" + } + lappend where_clauses "users_interests.category_id = [ns_dbquotevalue $category_id]" + } + "Country_code" { + if {"users_contact" ni $tables} { + lappend tables "users_contact" + lappend join_clauses "users.user_id = users_contact.user_id" + } + lappend where_clauses "users_contact.ha_country_code = [ns_dbquotevalue $country_code]" + + } + "usps_abbrev" { + if {"users_contact" ni $tables} { + lappend tables "users_contact" + lappend join_clauses "users.user_id = users_contact.user_id" + } + lappend where_clauses "(users_contact.ha_state = [ns_dbquotevalue $usps_abbrev] and (users_contact.ha_country_code is null or users_contact.ha_country_code = 'us'))" + + } + "intranet_user_p" { + if {$intranet_user_p eq "t" && [lsearch $tables "intranet_users"] == -1 } { + lappend tables "intranet_users" + lappend join_clauses "users.user_id = intranet_users.user_id" + } + } + "group_id" { + lappend tables "group_member_map" + lappend join_clauses "users.user_id = group_member_map.member_id" + lappend where_clauses "group_member_map.group_id = $group_id" + + } + + "last_name_starts_with" { + lappend where_clauses "lower(users.last_name) like lower([ns_dbquotevalue "${last_name_starts_with}%"])" + # note the added percent sign here + + } + "email_starts_with" { + lappend where_clauses "lower(users.email) like lower([ns_dbquotevalue "${email_starts_with}%"])" + # note the added percent sign here + + } + "expensive" { + if { [info exists count_only_p] && $count_only_p } { + lappend where_clauses "[parameter::get -parameter ExpensiveThreshold] < (select sum(amount) from users_charges where users_charges.user_id = users.user_id)" + } else { + if {"user_charges" ni $tables} { + lappend tables "users_charges" + lappend join_clauses "users.user_id = users_charges.user_id" + } + + set group_clauses [concat $group_clauses $user_columns] + + lappend having_clauses "sum(users_charges.amount) > [parameter::get -parameter ExpensiveThreshold]" + # only the ones where they haven't paid + lappend where_clauses "users_charges.order_id is null" + } + } + "user_state" { + lappend where_clauses "users.user_state = [ns_dbquotevalue $user_state]" + + } + "sex" { + if {"users_demographics" ni $tables} { + lappend tables "users_demographics" + lappend join_clauses "users.user_id = users_demographics.user_id" + } + lappend where_clauses "users_demographics.sex = [ns_dbquotevalue $sex]" + + + } + "age_below_years" { + if {"users_demographics" ni $tables} { + lappend tables "users_demographics" + lappend join_clauses "users.user_id = users_demographics.user_id" + } + lappend where_clauses "users_demographics.birthdate > sysdate - ([ns_dbquotevalue $age_below_years] * 365.25)" + + } + "age_above_years" { + if {"users_demographics" ni $tables} { + lappend tables "users_demographics" + lappend join_clauses "users.user_id = users_demographics.user_id" + } + lappend where_clauses "users_demographics.birthdate < sysdate - ([ns_dbquotevalue $age_above_years] * 365.25)" + + } + "registration_during_month" { + lappend where_clauses "to_char(users.registration_date,'YYYYMM') = [ns_dbquotevalue $registration_during_month]" + + } + "registration_before_days" { + lappend where_clauses "users.registration_date < sysdate - [ns_dbquotevalue $registration_before_days]" + + } + "registration_after_days" { + lappend where_clauses "users.registration_date > sysdate - [ns_dbquotevalue $registration_after_days]" + + } + "registration_after_date" { + lappend where_clauses "users.registration_date > [ns_dbquotevalue $registration_after_date]" + + } + "last_login_before_days" { + lappend where_clauses "users.last_visit < sysdate - [ns_dbquotevalue $last_login_before_days]" + + } + "last_login_after_days" { + lappend where_clauses "users.last_visit > sysdate - [ns_dbquotevalue $last_login_after_days]" + + } + "last_login_equals_days" { + lappend where_clauses "round(sysdate-last_visit) = [ns_dbquotevalue $last_login_equals_days]" + + } + "number_visits_below" { + lappend where_clauses "users.n_sessions < [ns_dbquotevalue $number_visits_below]" + + } + "number_visits_above" { + lappend where_clauses "users.n_sessions > [ns_dbquotevalue $number_visits_above]" + + } + "crm_state" { + lappend where_clauses "users.crm_state = [ns_dbquotevalue $crm_state]" + + } + "curriculum_elements_completed" { + lappend where_clauses "[ns_dbquotevalue $curriculum_elements_completed] = (select count(*) from user_curriculum_map ucm where ucm.user_id = users.user_id and ucm.curriculum_element_id in (select curriculum_element_id from curriculum))" + + } + } + } + } + #stuff related to the query itself + + if { [info exists combine_method] && $combine_method eq "or" } { + set complete_where [join $where_clauses " or "] + } else { + set complete_where [join $where_clauses " and "] + } + + + if { [info exists include_accumulated_charges_p] && $include_accumulated_charges_p && (![info exists count_only_p] || !$count_only_p) } { + # we're looking for expensive users and not just counting them + lappend select_list "sum(users_charges.amount) as accumulated_charges" + } + if { [llength $join_clauses] == 0 } { + set final_query "select [join $select_list ",\n "] + from [join $tables ", "]" + if { $complete_where ne "" } { + append final_query "\nwhere $complete_where" + } + } else { + # we're joining at + set final_query "select [join $select_list ",\n "] + from [join $tables ", "] + where [join $join_clauses "\nand "]" + if { $complete_where ne "" } { + append final_query "\n and ($complete_where)" + } + } + if { [llength $group_clauses] > 0 } { + append final_query "\ngroup by [join $group_clauses ", "]" + } + if { [llength $having_clauses] > 0 } { + append final_query "\nhaving [join $having_clauses " and "]" + } + + return $final_query +} + + +ad_proc -private ad_user_class_query_count_only { set_id } { + Takes an ns_set of key/value pairs and produces a query that will compute the number of users in the class specified. +} { + set new_set [ns_set copy $set_id] + ns_set update $new_set count_only_p 1 + return [ad_user_class_query $new_set] +} \ No newline at end of file Index: openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-outdated/tcl/acs-tcl-admin-procs.xql 2 Oct 2013 07:23:44 -0000 1.1 @@ -0,0 +1,61 @@ + + + + + + + select sql_post_select + from user_classes + where user_class_id = [ns_dbquotevalue $user_class_id] + + + + + + + select category from categories where category_id = :category_id + + + + + + + + select country_name from country_codes where iso = :country_code + + + + + + + + select state_name from states where usps_abbrev = :usps_abbrev + + + + + + + + select group_name from groups where group_id = :group_id + + + + + + + + select to_char(to_date(:registration_during_month,'YYYYMM'),'fmMonth YYYY') from dual + + + + + + + + select name from user_classes where user_class_id = :user_class_id + + + + + Index: openacs-4/packages/acs-outdated/www/acs-tcl-users-one.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-outdated/www/acs-tcl-users-one.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-outdated/www/acs-tcl-users-one.tcl 2 Oct 2013 07:23:44 -0000 1.1 @@ -0,0 +1,71 @@ +# from /packages/acs-admin/www/users/one.tcl +# The code from below is from pre-ACS 4.0 and should be revised for entry later + +# it looks like we should be doing 0or1row but actually +# we might be in an ACS installation where users_demographics +# isn't used at all + +# set contact_info [ad_user_contact_info $user_id "site_admin"] + +# if {$contact_info ne ""} { +# append whole_page "

Contact Info

\n\n$contact_info\n +# " +# } else { +# append whole_page "

Contact Info

\n\n$contact_info\n +# " +# } + +# if {[db_table_exists users_demographics]} { +# if {[db_0or1row user_demographics "select +# ud.*, +# u.first_names as referring_user_first_names, +# u.last_name as referring_user_last_name +# from users_demographics ud, users u +# where ud.user_id = $user_id +# and ud.referred_by = u.user_id(+)"]} { +# # the table exists and there is a row for this user +# set demographic_items "" +# for {set i 0} {$i<[ns_set size $selection]} {incr i} { +# set varname [ns_set key $selection $i] +# set varvalue [ns_set value $selection $i] +# if { $varname ne "user_id" && $varvalue ne "" } { +# append demographic_items "
  • $varname: $varvalue\n" +# } +# } +# if {$demographic_items ne ""} { +# append whole_page "

    Demographics

    \n\n\n" + +# } +# } +# } + +# if {[db_table_exists categories] && [db_table_exists users_interests]} { +# set category_items "" +# db_foreach users_interests "select c.category +# from categories c, users_interests ui +# where ui.user_id = $user_id +# and c.category_id = ui.category_id" { +# append category_items "
  • $category\n" +# } + +# if {$category_items ne ""} { +# append whole_page "

    Interests

    \n\n" +# } +# } + +# # randyg is brilliant! we can recycle the same handle here because the +# # inner argument is evaluated before the outer one. this should actually +# # be done with the db api. 12 june 00, richardl@arsdigita.com + +# if { [im_enabled_p] && [ad_user_group_member $db [im_employee_group_id] $user_id] } { +# # We are running an intranet enabled acs and this user is a member of the +# # employees group. Offer a link to the employee administration page +# set intranet_admin_link "
  • Update this user's employee information

    " +# } else { +# set intranet_admin_link "" +# } +