Index: openacs-4/packages/scholarship-fund/tcl/scholarship-funds-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/tcl/scholarship-funds-install-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/scholarship-fund/tcl/scholarship-funds-install-procs.tcl 19 Jun 2005 06:05:09 -0000 1.2 +++ openacs-4/packages/scholarship-fund/tcl/scholarship-funds-install-procs.tcl 3 Aug 2005 22:58:58 -0000 1.3 @@ -41,6 +41,13 @@ -pretty_plural "Account Codes" \ -column_spec "varchar(200)" + content::type::attribute::new \ + -content_type scholarship_fund \ + -attribute_name "amount" \ + -datatype text \ + -pretty_name "Amount in Fund" \ + -pretty_plural "Amount in Fund" \ + -column_spec "float" } ad_proc -private sf::install::after_instantiate { @@ -72,3 +79,35 @@ ns_log Warning "registered the content type" } +ad_proc -private sf::install::after_upgrade { + -from_version_name:required + -to_version_name:required +} { + After upgrade callback + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-08-04 + + @param from_version_name + + @param to_version_name + + @return + + @error +} { + apm_upgrade_logic \ + -from_version_name $from_version_name \ + -to_version_name $to_ersion_name \ + -spec { + 0.1d 0.1d1 { + content::type::attribute::new \ + -content_type scholarship_fund \ + -attribute_name "amount" \ + -datatype text \ + -pretty_name "Amount in Fund" \ + -pretty_plural "Amount in Fund" \ + -column_spec "float" + } + } +} Index: openacs-4/packages/scholarship-fund/www/fund-add-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/fund-add-edit.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/scholarship-fund/www/fund-add-edit.tcl 19 Jun 2005 06:05:09 -0000 1.2 +++ openacs-4/packages/scholarship-fund/www/fund-add-edit.tcl 3 Aug 2005 22:58:58 -0000 1.3 @@ -37,12 +37,13 @@ ad_form -name fund-add-edit \ -form { item_id:key - title:text - description:text(textarea) - account_code:text + {title:text {label Title}} + {description:text(textarea) {label Description}} + {account_code:text {label "Account Code"}} + {amount:float {label "Amount in Fund"}} } -edit_request { # get existing fund info - db_1row get_fund "select sf.title, sf.description, sf.account_code from scholarship_fundi sf, cr_items ci where sf.revision_id=ci.live_revision and sf.item_id=:item_id" + db_1row get_fund "select sf.title, sf.description, sf.account_code, sf.amount from scholarship_fundi sf, cr_items ci where sf.revision_id=ci.live_revision and sf.item_id=:item_id" } -new_data { #add fund content::item::new \ @@ -53,15 +54,17 @@ -description $description \ -content_type scholarship_fund \ -is_live t \ - -attributes [list [list account_code $account_code]] + -attributes [list [list account_code $account_code] \ + [list amount $amount]] } -edit_data { #update fund content::revision::new \ -item_id $item_id \ -title $title \ -description $description \ - -attributes [list [list account_code $account_code]] \ + -attributes [list [list account_code $account_code] \ + [list amount $amount]] \ -is_live t } -after_submit { Index: openacs-4/packages/scholarship-fund/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/index.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/scholarship-fund/www/index.tcl 19 Jun 2005 06:05:09 -0000 1.2 +++ openacs-4/packages/scholarship-fund/www/index.tcl 3 Aug 2005 22:58:58 -0000 1.3 @@ -44,6 +44,7 @@ -elements { title { label "Title" link_url_col one_url } description { label "Description" } + amount { label "Amount in Fund" } actions { label "Actions" display_template { Index: openacs-4/packages/scholarship-fund/www/one-fund.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/one-fund.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/scholarship-fund/www/one-fund.adp 31 May 2005 22:08:03 -0000 1.1 +++ openacs-4/packages/scholarship-fund/www/one-fund.adp 3 Aug 2005 22:58:58 -0000 1.2 @@ -3,7 +3,10 @@ @header_stuff@ @context@ @focus@ + +
Edit Fund
-@fund.title@
-@fund.description@
-@fund.account_code@
\ No newline at end of file + +

+ + \ No newline at end of file Index: openacs-4/packages/scholarship-fund/www/one-fund.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/one-fund.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/scholarship-fund/www/one-fund.tcl 19 Jun 2005 06:05:09 -0000 1.2 +++ openacs-4/packages/scholarship-fund/www/one-fund.tcl 3 Aug 2005 22:58:58 -0000 1.3 @@ -32,6 +32,42 @@ set edit_url [export_vars -base "fund-add-edit" {item_id}] +ad_form -name one -mode display -export { item_id } -has_edit 1 -form { + {title:text {label "Fund Title"}} + {description:text(textarea) {label "Description"}} + {account_code:text {label "Account Code"}} + {amount:text {label "Amount"}} +} -on_request { + db_1row get_fund "select sf.title, sf.description, sf.account_code, sf.amount from scholarship_fundi sf, cr_items ci where sf.revision_id=ci.live_revision and sf.item_id=:item_id" +} + +template::list::create \ + -name grants \ + -multirow grants \ + -no_data "No grants from this fund" \ + -actions [list Grant scholarship-grant?fund_id=$fund(fund_id) Grant] \ + -elements { + person__name { + label "User" + } + grant_date { + label "Date Granted" + } + grant_amount { + label "Amount" + } + } + +db_multirow grants grants { + select person__name(user_id), to_char(grant_date, 'Month dd, yyyy hh:miam') as grant_date, grant_amount + from scholarship_fund_grants + where fund_id in (select fund_id + from scholarship_fundi + where item_id = :item_id) + group by person__name, grant_date, grant_amount + order by scholarship_fund_grants.grant_date +} + set page_title "One Scholarship Fund" set context [list $page_title] set header_stuff "" Index: openacs-4/packages/scholarship-fund/www/scholarship-grant.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/scholarship-grant.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/scholarship-fund/www/scholarship-grant.adp 3 Aug 2005 22:58:58 -0000 1.1 @@ -0,0 +1,11 @@ + + Grant Scholarship + {Grant Scholarship} + + +

Detailed search results:

+ +

+ + + \ No newline at end of file Index: openacs-4/packages/scholarship-fund/www/scholarship-grant.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scholarship-fund/www/scholarship-grant.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/scholarship-fund/www/scholarship-grant.tcl 3 Aug 2005 22:58:58 -0000 1.1 @@ -0,0 +1,181 @@ +# packages/scholarship-fund/www/scholarship-grant.tcl + +ad_page_contract { + + Grant scholarship to user + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-08-03 + @arch-tag: b6e25b4c-1f20-4710-b9ce-bd11658bba7d + @cvs-id $Id: scholarship-grant.tcl,v 1.1 2005/08/03 22:58:58 roelc Exp $ +} { + fund_id:integer,notnull + + {user ""} + {user_id 0} + +} -properties { +} -validate { +} -errors { +} + +if { ! [empty_string_p $user] } { + # Search found users, show a more detailed list + template::list::create \ + -name users \ + -multirow users \ + -key user_id \ + -page_size 50 \ + -page_flush_p 1 \ + -no_data "No users found" \ + -page_query [subst { + select u.user_id, u.first_names, u.last_name, u.email, a.phone, a.line1, a.line2 + from dotlrn_users u + left join (select * + from ec_addresses + where address_id + in (select max(address_id) + from ec_addresses + group by user_id)) a + on (u.user_id = a.user_id) + where u.user_id != :user_id + and u.user_id != :user_id + and (case when :user is null + then true + else (lower(first_names) like lower(:user)||'%' or + lower(last_name) like lower(:user)||'%' or + lower(email) like lower(:user)||'%' or + lower(phone) like '%'||lower(:user)||'%') end) + }] -elements { + _user_id { + label "User ID" + } + email { + label "Email Address" + } + first_names { + label "First Name" + } + last_name { + label "Last Name" + } + phone { + label "Phone Number" + } + address { + label "Address" + display_template { + @users.line1@ + +
@users.line2@ +
+ } + } + action { + display_template { + Choose User + } + } + } -filters { + user_id {} + user {} + fund_id {} + } + + db_multirow -extend { add_user_url } users users [subst { + select u.user_id as _user_id, u.first_names, u.last_name, u.email, a.phone, a.line1, a.line2 + from dotlrn_users u + left join (select * + from ec_addresses + where address_id + in (select max(address_id) + from ec_addresses + group by user_id)) a + on (u.user_id = a.user_id) + where u.user_id != :user_id + and (case when :user is null + then true + else (lower(first_names) like lower(:user)||'%' or + lower(last_name) like lower(:user)||'%' or + lower(email) like lower(:user)||'%' or + lower(phone) like '%'||lower(:user)||'%') end) + [template::list::page_where_clause -and -name users -key u.user_id] + }] { + set add_user_url [export_vars -base scholarship-grant { fund_id {user_id $_user_id} { user "" } new_user_p }] + } +} + +ad_form -name grant -form { + {-section "Grant"} +} + +if { $user_id } { + + acs_user::get -user_id $user_id -array user_info + set search_url [export_vars -base scholarship-grant { fund_id {user_id 0} {user ""} }] + ad_form -extend -name grant -export { fund_id user user_id } -form { + {_participant:text(inform) {label "User"} {value "$user_info(first_names) $user_info(last_name) ($user_info(email))"} + {after_html {Search Again}} + } + } + +} else { + + ad_form -extend -name grant -export { fund_id } -form { + {user:text,optional {label "Search User"} {html {onchange "if (this.value != '') { this.form.__refreshing_p.value = 1; } else { this.form.__refreshing_p.value = 0 ; }" size 30}} + {help_text "Enter a string to search names and email addresses."} + } + } + +} + +set fund_amount [db_string fund_amount { + select amount + from scholarship_fund + where fund_id = :fund_id +} -default 0] + +ad_form -extend -name grant -validate { + {grant_amount + { $grant_amount > 0 && $grant_amount <= $fund_amount } + "Please enter an amount up to $fund_amount" + } +} -form { + {grant_amount:text {label "Amount to Grant"} + {html {size 10}} + } +} -on_submit { + db_transaction { + + set gift_certificate_id [db_nextval ec_gift_cert_id_sequence] + set random_string [ec_generate_random_string 10] + set claim_check "scholarship-$random_string-$gift_certificate_id" + set peeraddr [ns_conn peeraddr] + set gc_months [ad_parameter -package_id [ec_id] GiftCertificateMonths ecommerce] + + set viewing_user_id [ad_conn user_id] + + db_dml insert_new_gc_into_db [subst { + insert into ec_gift_certificates + (gift_certificate_id, gift_certificate_state, amount, issue_date, purchased_by, expires, last_modified, last_modifying_user, modified_ip_address, user_id) + values + (:gift_certificate_id, 'authorized', :grant_amount, current_timestamp, :viewing_user_id, current_timestamp + '$gc_months months'::interval, current_timestamp, :viewing_user_id, :peeraddr, :user_id) + }] + + db_dml insert_scholarship_grant { + insert into scholarship_fund_grants + (fund_id, user_id, gift_certificate_id, grant_amount) + values + (:fund_id, :user_id, :gift_certificate_id, :grant_amount) + } + + db_dml update_scholarship_fund { + update scholarship_fund + set amount = amount - :grant_amount + where fund_id = :fund_id + } + } + + ad_returnredirect index + ad_script_abort +} \ No newline at end of file