Index: openacs-4/packages/project-manager/lib/search-project.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/project-manager/lib/search-project.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/project-manager/lib/search-project.tcl 24 Oct 2006 15:05:17 -0000 1.5 +++ openacs-4/packages/project-manager/lib/search-project.tcl 14 Nov 2006 16:11:10 -0000 1.6 @@ -29,27 +29,5 @@ } {return_url:text(hidden) {value $return_url}} } -on_submit { - set match_projects [db_list_of_lists get_projects { }] - set match_length [llength $match_projects] - if { [string equal $match_length 0] } { - # No Match, run additional search - set match_projects [db_list_of_lists get_projects_by_code { }] - set match_length [llength $match_projects] - if { [string equal $match_length 0] } { - # No Match just redirect - ad_returnredirect $return_url - } - } - - set project_item_id [lindex [lindex $match_projects 0] 0] - set object_package_id [acs_object::package_id -object_id $project_item_id] - - # We get the node_id from the package_id and use it - # to get the url of the project-manager - set pm_node_id [site_node::get_node_id_from_object_id -object_id $object_package_id] - set pm_url [site_node::get_url -node_id $pm_node_id] - - # Just redirect to the pm_url and project_item_id - - ad_returnredirect "${pm_url}one?project_item_id=$project_item_id" + ad_returnredirect [pm::project::search_url -keyword $keyword] } -has_submit {1} \ No newline at end of file Index: openacs-4/packages/project-manager/tcl/project-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/project-manager/tcl/project-procs-postgresql.xql,v diff -u -r1.14 -r1.15 --- openacs-4/packages/project-manager/tcl/project-procs-postgresql.xql 24 Oct 2006 13:18:04 -0000 1.14 +++ openacs-4/packages/project-manager/tcl/project-procs-postgresql.xql 14 Nov 2006 16:11:10 -0000 1.15 @@ -446,4 +446,35 @@ + + + select + i.item_id + from + cr_items i, cr_revisions r, pm_projects p + where + lower(r.title) like '%${keyword}%' + and i.latest_revision = r.revision_id + and r.revision_id = p.project_id + order by + r.title asc + + + + + + select + item_id, + o.package_id as object_package_id + from + cr_items i, acs_objects o, pm_projects p + where + lower(p.project_code) like '%${keyword}%' + and i.latest_revision = o.object_id + and o.object_id = p.project_id + order by + title asc + + + Index: openacs-4/packages/project-manager/tcl/project-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/project-manager/tcl/project-procs.tcl,v diff -u -r1.38 -r1.39 --- openacs-4/packages/project-manager/tcl/project-procs.tcl 24 Oct 2006 14:57:06 -0000 1.38 +++ openacs-4/packages/project-manager/tcl/project-procs.tcl 14 Nov 2006 16:11:10 -0000 1.39 @@ -3445,7 +3445,12 @@ set parent [lindex $subprojects $i] # Now we get the sub_projects of the sub_projects if there is any - set sub_projects [db_list get_subprojects { }] + if {$parent eq ""} { + set sub_projects [list] + } else { + set sub_projects [db_list get_subprojects { }] + } + foreach sp $sub_projects { lappend subprojects $sp } @@ -3490,3 +3495,61 @@ } } } + +ad_proc -public pm::project::search { + -keyword:required +} { + Searches for the project which matches the keyword. Returns the item_id + + @param keyword which should be in the title or the project_code + + @return item_id Item_id of the project +} { + set keyword [string tolower $keyword] + set match_projects [db_list_of_lists get_projects { }] + set match_length [llength $match_projects] + if { [string equal $match_length 0] } { + # No Match, run additional search + set match_projects [db_list_of_lists get_projects_by_code { }] + set match_length [llength $match_projects] + if { [string equal $match_length 0] } { + # No Match just return nothing + return "" + } + } + + # Return the first found project + return [lindex [lindex $match_projects 0] 0] +} + +ad_proc -public pm::project::search_url_not_cached { + -keyword:required +} { + Returns the URL for the first project found matching the keyword +} { + set project_item_id [pm::project::search -keyword $keyword] + + if {$project_item_id eq ""} { + # No project found, return nothing + return "" + } else { + set object_package_id [acs_object::package_id -object_id $project_item_id] + + # We get the node_id from the package_id and use it + # to get the url of the project-manager + set pm_node_id [site_node::get_node_id_from_object_id -object_id $object_package_id] + set pm_url [site_node::get_url -node_id $pm_node_id] + + # Just redirect to the pm_url and project_item_id + + return "${pm_url}one?project_item_id=$project_item_id" + } +} + +ad_proc -public pm::project::search_url { + -keyword:required +} { + Returns the URL for the first project found matching the keyword +} { + return [util_memoize [list pm::project::search_url_not_cached -keyword $keyword]] +}