Index: openacs-4/packages/contacts/contacts.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/contacts.info,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/contacts.info 13 Jan 2005 13:56:59 -0000 1.2 +++ openacs-4/packages/contacts/contacts.info 18 May 2005 16:45:49 -0000 1.3 @@ -5,25 +5,18 @@ Contacts Contacts f - t - contacts - - + f + + Matthew Geddert This application lets you collaboratively view, edit and categorize contacts. 2004-07-28 - Contacts is an application for managing all those people and or organization you need to keep track of. It has a complete UI for storing and categorizing contacts. Each contact can have an arbitrary number of custom attributes associated with it, including other contacts (i.e. a certain contact "belongs" to a certain organization). It also functions as a service contract provider for attributes related to users in your system - + Contacts is an application for managing all those people and or organization you need to keep track of. It has a complete UI for storing, grouping, relating and doing advanced searches for contacts. It also provides emailing and letter mail merge functionality. Each contact can have an arbitrary number of attributes associated with it via the AMS package (Attribute Management System). + - + - - - - - - Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/catalog/contacts.de_DE.ISO-8859-1.xml'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/attributes-create.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/attributes-drop.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/attributes-package-create.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/attributes-populate.sql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/sql/postgresql/contacts-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/sql/postgresql/contacts-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/sql/postgresql/contacts-create.sql 13 Jan 2005 13:57:00 -0000 1.2 +++ openacs-4/packages/contacts/sql/postgresql/contacts-create.sql 18 May 2005 16:45:49 -0000 1.3 @@ -7,70 +7,175 @@ -- -create table contact_archives ( - party_id integer - constraint contact_archives_party_id_fk references parties(party_id) - constraint contact_archives_party_id_pk primary key +-- all contacts are parties. we are making parties content repository items, +-- so we need party revisions + +create table contact_party_revisions ( + party_revision_id integer + constraint contact_party_revisions_id_fk references cr_revisions(revision_id) + constraint contact_party_revisions_id_pk primary key ); --- this is used to create forms for orgs and persons (since they need object_ids) to map to. -create table contact_object_types ( - object_id integer not null - constraint contact_object_type_object_id_fk references acs_objects(object_id) - constraint contact_object_type_object_id_pk primary key, - object_type varchar(100) not null, - UNIQUE(object_type) +-- create the content type +select content_type__create_type ( + 'contact_party_revision', -- content_type + 'content_revision', -- supertype + 'Party Revision', -- pretty_name + 'Party Revisions', -- pretty_plural + 'contact_party_revisions', -- table_name (should this be pm_task?) + 'party_revision_id', -- id_column + 'contact_party_revision__name' -- name_method ); +-- i need to create the content_folder contact_parties, it is not bound to a package_id +-- since the package_id is not used by contacts - which uses the groups system for package +-- maintenance. +-- contrary to "most" packages that use the content repository, we will not be +-- specifying new item_ids. Since all contacts are parties, we are going to set +-- all parties that use the contacts system to have an content_items(item_id) +-- that is equal to the parties(party_id). -\i contacts-package-create.sql +-- since all contacts are parties we already have good "group" mechanisms built into the core +-- however, we do not want people to view all groups at once, so the calendar instance +-- administrator can selectively give certain calendar instances access to certain groups +-- +-- by default each new contacts instance will be given access to its subsite's group. For +-- example: all users on a default openacs install are memembers of the "Main Site Members" +-- group. If a calendar instance were mounted under that subsite, all "Main Site Members" +-- would be accessible to that calendar instance. +-- +-- just as is the case with the calendar package all "users" of contacts (i.e. users that +-- have write access to at least one contacts instance will be assigned a private calendar) +-- +-- which calendars can be viewed by which calendar instance is handled via parameters - unlike +-- many packages. This allows for more flexable instance and sharing management - where +-- one instances shared calendar can also be accesible to another instance. -create view contacts as - select organization_id as party_id, - 'organization' as object_type, - name, - name as organization_name, - legal_name, - reg_number, - null as first_names, - null as last_name, - name as sort_first_names, - name as sort_last_name, - contact__party_email(organization_id) as email, - contact__party_url(organization_id) as url, - 'f' as user_p, - contact__status(organization_id) as status - from organizations -union - select person_id as party_id, - 'person' as object_type, - first_names || ' ' || last_name as name, - null as organization_name, - null as legal_name, - null as reg_number, - first_names as first_names, - last_name as last_name, - first_names || ' ' || last_name as sort_first_names, - last_name || ', ' || first_names as sort_last_name, - contact__party_email(person_id) as email, - contact__party_url(person_id) as url, - contact__person_is_user_p(person_id) as user_p, - contact__status(person_id) as status - from persons - where person_id != '0' +create table contact_groups ( + group_id integer + constraint contact_groups_id_fk references groups(group_id) + constraint contact_groups_id_nn not null, + default_p boolean default 'f' + constraint contact_groups_default_p_nn not null, + package_id integer + constraint contact_groups_package_id_fk references apm_packages(package_id) + constraint contact_groups_package_id_nn not null, + unique(group_id,package_id) +); + +create table contact_groups_allowed_rels ( + group_id integer + constraint contact_groups_id_fk references groups(group_id) + constraint contact_groups_id_nn not null, + rel_type varchar(100) + constraint contact_groups_allowed_rels_type_fk references acs_rel_types(rel_type), + package_id integer + constraint contact_groups_package_id_fk references apm_packages(package_id) + constraint contact_groups_package_id_nn not null, + unique(group_id,package_id) +); + + +create table contact_signatures ( + signature_id integer + constraint contact_signatures_id_pk primary key, + title varchar(255) + constraint contact_signatures_title_nn not null, + signature varchar(1000) + constraint contact_signatures_signature_nn not null, + default_p boolean default 'f' + constraint contact_signatures_default_p_nn not null, + party_id integer + constraint contact_signatures_party_id_fk references parties(party_id) + constraint contact_signatures_party_id_nn not null, + unique(party_id,title,signature) +); + +-- this view greatly simplifies getting available roles for various contact types +create view contact_rel_types as +( select rel_type, + object_type_one as primary_object_type, + role_one as primary_role, + object_type_two as secondary_object_type, + role_two as secondary_role + from acs_rel_types + where rel_type in ( select object_type from acs_object_types where supertype = 'contact_rel') +) +UNION +( select rel_type, + object_type_two as primary_object_type, + role_two as primary_role, + object_type_one as secondary_object_type, + role_one as secondary_role + from acs_rel_types + where rel_type in ( select object_type from acs_object_types where supertype = 'contact_rel') +) ; +create table contact_rels ( + rel_id integer + constraint contact_rels_rel_id_fk references acs_rels(rel_id) on delete cascade + constraint contact_rels_rel_id_pk primary key, + comment text, + comment_format varchar(50) default 'text/plain' +); --- The attribute structure. -\i attributes-create.sql -\i attributes-package-create.sql +select acs_rel_type__create_type ( + 'contact_rel', + 'Contact Relationship', + 'Contact Relationships', + 'relationship', + 'contact_rels', + 'rel_id', + 'contact_rel', + NULL, + 'party', + 0, + null::integer, + 'party', + 0, + null::integer +); -\i attributes-populate.sql +create table organization_rels ( + rel_id integer + constraint organization_rels_rel_id_fk references membership_rels(rel_id) on delete cascade + constraint organization_rels_rel_id_pk primary key +); -\i views-create.sql +select acs_rel_type__create_role ( + 'organization', + 'Organization', + 'Organizations' +); -\i telecom-number-missing-plsql.sql +select acs_rel_type__create_type ( + 'organization_rel', + 'Organization Relationship', + 'Organization Relationships', + 'membership_rel', + 'organization_rels', + 'rel_id', + 'organization_rel', + NULL, + 'group', + 0, + null::integer, + 'organization', + 0, + null::integer +); + + +-- create table contact_groups_package_map ( +-- group_id +-- ); +\i contacts-package-create.sql +\i contacts-search-create.sql + + + Index: openacs-4/packages/contacts/sql/postgresql/contacts-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/sql/postgresql/contacts-drop.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/sql/postgresql/contacts-drop.sql 13 Jan 2005 13:57:00 -0000 1.2 +++ openacs-4/packages/contacts/sql/postgresql/contacts-drop.sql 18 May 2005 16:45:49 -0000 1.3 @@ -6,30 +6,24 @@ -- -- +drop table contact_search_conditions; +drop table contact_searches; +select drop_package('contact_search'); +select acs_object__delete(search_id) from contact_searches; +select acs_object_type__drop_type('contact_search','t'); --- The view structure. -\i views-drop.sql +drop view contact_rel_types; +drop table contact_signatures; +drop table contact_groups; +drop table contact_rels; +drop table organization_rels; +select content_type__drop_type ('contact_party_revision','t','t'); +--drop table contact_party_revisions; +select acs_rel_type__drop_type('organization_rel','t'); +select acs_rel_type__drop_type(object_type,'t') from acs_object_types where supertype = 'contact_rel'; +select acs_rel_type__drop_type('contact_rel','t'); --- The attribute structure. -\i attributes-drop.sql - - -drop view contacts; -drop table contact_archives; -drop table contact_object_types; - +-- procedure drop_type select drop_package('contact'); - -delete from acs_objects where object_type = 'contact_object_type'; -create function inline_0 () -returns integer as ' -begin - - PERFORM acs_object_type__drop_type (''contact_object_type'',''f''); - - return 0; -end;' language 'plpgsql'; - -select inline_0 (); -drop function inline_0 (); - +select drop_package('contact_rel'); +select drop_package('contact_party_revision'); Index: openacs-4/packages/contacts/sql/postgresql/contacts-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/sql/postgresql/contacts-package-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/sql/postgresql/contacts-package-create.sql 13 Jan 2005 13:57:01 -0000 1.2 +++ openacs-4/packages/contacts/sql/postgresql/contacts-package-create.sql 18 May 2005 16:45:49 -0000 1.3 @@ -7,130 +7,234 @@ -- -create function inline_1 () -returns integer as ' -begin +select define_function_args('contact_party_revision__new', 'party_id,party_revision_id,creation_date;now(),creation_user,creation_ip'); - PERFORM acs_object_type__create_type ( - ''contact_object_type'', - ''Contact Object Type'', - ''Contact Object Types'', - ''acs_object'', - ''contact_object_types'', - ''object_id'', - null, - ''f'', - null, - ''contact__object_type_name'' - ); - return 0; - -end;' language 'plpgsql'; -select inline_1 (); -drop function inline_1 (); - - - - -create or replace function contact__object_type_create (integer,varchar,timestamptz,integer,varchar,integer) -returns integer as ' +create or replace function contact_party_revision__new ( + integer, -- party_id + integer, -- party_revision_id + timestamptz, -- creation_date + integer, -- creation_user + varchar -- creation_ip +) returns integer +as ' declare - p_object_id alias for $1; - p_object_type alias for $2; - p_creation_date alias for $3; - p_creation_user alias for $4; - p_creation_ip alias for $5; - p_context_id alias for $6; - v_object_id integer; + p_party_id alias for $1; + p_party_revision_id alias for $2; + p_creation_date alias for $3; + p_creation_user alias for $4; + p_creation_ip alias for $5; + v_party_revision_id cr_revisions.revision_id%TYPE; + v_party_id cr_items.item_id%TYPE; begin - v_object_id := acs_object__new ( - p_object_id, - ''contact_object_type'', + v_party_id := contact_party_revision__item_id ( + p_party_id, p_creation_date, p_creation_user, - P_creation_ip, - p_context_id + p_creation_ip ); + v_party_revision_id := content_revision__new ( + NULL, -- title + NULL, -- description + now(), -- publish_date + NULL, -- mime_type + NULL, -- nls_language + NULL, -- data + v_party_id, -- item_id + p_party_revision_id, -- revision_id + p_creation_date, -- creation_date + p_creation_user, -- creation_user + p_creation_ip -- creation_ip + ); - insert into contact_object_types - (object_id,object_type) - values - (v_object_id,p_object_type); + PERFORM content_item__set_live_revision (v_party_revision_id); - return v_object_id; + insert into contact_party_revisions ( party_revision_id ) values ( v_party_revision_id ); + + return v_party_revision_id; end;' language 'plpgsql'; +create or replace function contact_party_revision__item_id ( + integer, -- party_id + timestamptz, -- creation_date + integer, -- creation_user + varchar -- creation_ip +) returns integer +as ' +declare + p_party_id alias for $1; + p_creation_date alias for $2; + p_creation_user alias for $3; + p_creation_ip alias for $4; + v_exists_p boolean; +begin + v_exists_p := ''1'' from cr_items where item_id = p_party_id; -create or replace function contact__object_type_name (integer) -returns varchar as ' + if v_exists_p is not true then + insert into cr_items + (item_id,parent_id,name,content_type) + values + (p_party_id,contact_party_revision__folder_id(),p_party_id::varchar,''contact_party_revision''); + end if; + + return p_party_id; +end;' language 'plpgsql'; + +create or replace function contact_party_revision__name ( + integer -- revision_id +) returns varchar +as ' declare - p_object_id alias for $1; - v_name varchar; + p_revision_id alias for $1; + v_first_names varchar; + v_last_name varchar; + v_organization varchar; + v_name varchar; begin - v_name := object_type from contact_object_types where object_id = p_object_id; + + v_name := contact__name(item_id) || '' revision '' || to_char(revision_id,''FM9999999999999999999'') from cr_revisions where item_id = p_revision_id; return v_name; end;' language 'plpgsql'; +create or replace function contact_party_revision__folder_id () returns integer +as ' +declare + v_folder_id integer; +begin + v_folder_id := cf.folder_id from cr_items ci, cr_folders cf + where ci.item_id = cf.folder_id + and ci.parent_id = ''0'' + and ci.name = ''contacts''; + if v_folder_id is null then + v_folder_id := content_folder__new ( + ''contacts'', + ''Contacts'', + NULL, + ''0'' + ); + end if; -create or replace function contact__party_email (integer) -returns varchar as ' + return v_folder_id; +end;' language 'plpgsql'; + +create or replace function contact__name ( + varchar, -- first_names + varchar, -- last_name + varchar, -- organization + boolean -- recursive_p +) returns varchar +as ' declare - email__party_id alias for $1; + p_first_names alias for $1; + p_last_name alias for $2; + p_organization alias for $3; + p_recursive_p alias for $4; + v_name varchar; begin - return email from parties where party_id = email__party_id; + if p_recursive_p then + if p_first_names is null and p_last_name is null then + v_name := p_organization; + else + v_name := p_last_name; + if p_first_names is not null and p_last_name is not null then + v_name := v_name || '', ''; + end if; + v_name := v_name || p_first_names; + end if; + else + if p_first_names is null and p_last_name is null then + v_name := p_organization; + else + v_name := p_first_names; + if p_first_names is not null and p_last_name is not null then + v_name := v_name || '' ''; + end if; + v_name := v_name || p_last_name; + end if; + end if; -end;' language 'plpgsql' stable strict; + return v_name; +end;' language 'plpgsql'; -create or replace function contact__party_url (integer) -returns varchar as ' +create or replace function contact__name ( + integer -- party_id +) returns varchar +as ' declare - url__party_id alias for $1; + p_party_id alias for $1; + v_name varchar; begin + v_name := contact__name(p_party_id,''f''); - return url from parties where party_id = url__party_id; + return v_name; +end;' language 'plpgsql'; -end;' language 'plpgsql' stable strict; - -create or replace function contact__status (integer) -returns varchar as ' +create or replace function contact__name ( + integer, -- party_id + boolean -- recursive_p +) returns varchar +as ' declare - p_party_id alias for $1; - v_archived_p boolean; + p_party_id alias for $1; + p_recursive_p alias for $2; + v_first_names varchar; + v_last_name varchar; + v_organization varchar; + v_name varchar; begin - v_archived_p := ''1'' from contact_archives where party_id = p_party_id; + select first_names, last_name + into v_first_names, v_last_name + from persons where person_id = p_party_id; - if v_archived_p then - return ''archived''; - else - return ''current''; - end if; + select name + into v_organization + from organizations where organization_id = p_party_id; -end;' language 'plpgsql' stable strict; + v_name := contact__name(v_first_names,v_last_name,v_organization,p_recursive_p); + return v_name; +end;' language 'plpgsql'; -create or replace function contact__person_is_user_p (integer) -returns boolean as ' + +create or replace function contact_group__member_count ( + integer -- group_id +) returns integer +as ' declare - p_person_id alias for $1; - v_result boolean; + p_group_id alias for $1; + v_member_count integer; begin + v_member_count := count(*) from group_distinct_member_map where group_id = p_group_id ; - v_result := ''1'' from users where user_id = p_person_id; + return v_member_count; +end;' language 'plpgsql'; - if v_result then - return ''t''; - else - return ''f''; - end if; -end;' language 'plpgsql' stable strict; +create or replace function contact_group__member_p (integer,integer) returns boolean +as ' +declare + p_group_id alias for $1; + p_member_id alias for $2; + v_member_p boolean; +begin + + v_member_p := ''1'' from group_distinct_member_map where group_id = p_group_id and member_id = p_member_id; + + if v_member_p is true then + v_member_p := ''1''; + else + v_member_p := ''0''; + end if; + + return v_member_p; +end;' language 'plpgsql'; + Index: openacs-4/packages/contacts/sql/postgresql/contacts-search-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/sql/postgresql/contacts-search-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/sql/postgresql/contacts-search-create.sql 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,83 @@ +-- contacts-search-create.sql +-- +-- @author Matthew Geddert openacs@geddert.com +-- @creation-date 2004-07-28 +-- @cvs-id $Id: contacts-search-create.sql,v 1.1 2005/05/18 16:45:49 matthewg Exp $ +-- +-- + +create table contact_searches ( + search_id integer + constraint contact_searches_id_fk references acs_objects(object_id) on delete cascade + constraint contact_searches_id_pk primary key, + title varchar(255), + owner_id integer + constraint contact_searches_owner_id_fk references acs_objects(object_id) on delete cascade + constraint contact_searches_owner_id_nn not null, + all_or_any varchar(20) + constraint contact_searches_and_or_all_nn not null, + object_type varchar(1000) + constraint contact_searches_object_type_nn not null +); + +-- create the content type +select acs_object_type__create_type ( + 'contact_search', -- content_type + 'Contacts Search', -- pretty_name + 'Contacts Searches', -- pretty_plural + 'acs_object', -- supertype + 'contact_searches', -- table_name (should this be pm_task?) + 'search_id', -- id_column + 'contact_search', -- package_name + 'f', -- abstract_p + NULL, -- type_extension_table + NULL -- name_method +); + +create table contact_search_conditions ( + condition_id integer + constraint contact_search_conditions_id_pk primary key, + search_id integer + constraint contact_search_conditions_search_id_fk references contact_searches(search_id) on delete cascade + constraint contact_search_conditions_search_id_nn not null, + type varchar(255) + constraint contact_search_conditions_type_nn not null, + var_list text + constraint contact_search_conditions_var_list_nn not null +); + + +select define_function_args ('contact_search__new', 'search_id,title,owner_id,all_or_any,object_type,creation_date,creation_user,creation_ip,context_id'); + +create or replace function contact_search__new (integer,varchar,integer,varchar,varchar,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_search_id alias for $1; + p_title alias for $2; + p_owner_id alias for $3; + p_all_or_any alias for $4; + p_object_type alias for $5; + p_creation_date alias for $6; + p_creation_user alias for $7; + p_creation_ip alias for $8; + p_context_id alias for $9; + v_search_id contact_searches.search_id%TYPE; +begin + v_search_id := acs_object__new( + p_search_id, + ''contact_search'', + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_owner_id) + ); + + insert into contact_searches + (search_id,title,owner_id,all_or_any,object_type) + values + (p_search_id,p_title,p_owner_id,p_all_or_any,p_object_type); + + return v_search_id; + +end;' language 'plpgsql'; + Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/telecom-number-missing-plsql.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/views-create.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/sql/postgresql/views-drop.sql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.4 refers to a dead (removed) revision in file `openacs-4/packages/contacts/tcl/address-procs-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/tcl/address-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/tcl/attribute-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/attribute-procs-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/attribute-procs-postgresql.xql 27 Feb 2005 17:07:18 -0000 1.3 +++ openacs-4/packages/contacts/tcl/attribute-procs-postgresql.xql 18 May 2005 16:45:49 -0000 1.4 @@ -1,122 +1,121 @@ - - - -postgresql7.2 - - - - select contact__attribute_create ( - null, - :widget_id, - :label, - :help_text, - :help_p, - :html, - :format, - now(), - :creation_user, - :creation_ip - ) - - - - - - - select contact__attribute_delete ( - :attribute_id - ) - - - - - - - select name from contact_attribute_names where attribute_id = :attribute_id and locale = :locale - - - - - - - select name from contact_view_names where attribute_id = :attribute_id and locale = :locale - - - - - - - select contact__attribute_value_save ( - :party_id, - :attribute_id, - :option_map_id, - :address_id, - :number_id, - :time, - :value, - :deleted_p, - now(), - :creation_user, - :creation_ip - ) - - - - - - - select postal_address__new ( - :additional_text, - null, - :country_code, - :delivery_address, - :municipality, - null, - :postal_code, - :postal_type, - :region, - :creation_user, - :creation_ip, - null - ) - - - - - - - select * from postal_addresses where address_id = :address_id - - - - - - - select telecom_number__new ( - :area_city_code, - :best_contact_time, - :extension, - :itu_id, - :location, - :national_number, - null, - null, - null, - :sms_enabled_p, - :subscriber_number, - :creation_user, - :creation_ip, - null - ) - - - - - - - select * from telecom_numbers where number_id = :number_id - - - - - + + + + + + + select contact__attribute_create ( + null, + :widget_id, + :label, + :help_text, + :help_p, + :html, + :format, + now(), + :creation_user, + :creation_ip + ) + + + + + + + select contact__attribute_delete ( + :attribute_id + ) + + + + + + + select name from contact_attribute_names where attribute_id = :attribute_id and locale = :locale + + + + + + + select name from contact_view_names where attribute_id = :attribute_id and locale = :locale + + + + + + + select contact__attribute_value_save ( + :party_id, + :attribute_id, + :option_map_id, + :address_id, + :number_id, + :time, + :value, + :deleted_p, + now(), + :creation_user, + :creation_ip + ) + + + + + + + select postal_address__new ( + :additional_text, + null, + :country_code, + :delivery_address, + :municipality, + null, + :postal_code, + :postal_type, + :region, + :creation_user, + :creation_ip, + null + ) + + + + + + + select * from postal_addresses where address_id = :address_id + + + + + + + select telecom_number__new ( + :area_city_code, + :best_contact_time, + :extension, + :itu_id, + :location, + :national_number, + null, + null, + null, + :sms_enabled_p, + :subscriber_number, + :creation_user, + :creation_ip, + null + ) + + + + + + + select * from telecom_numbers where number_id = :number_id + + + + + Index: openacs-4/packages/contacts/tcl/attribute-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/attribute-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/attribute-procs.tcl 13 Jan 2005 13:57:02 -0000 1.2 +++ openacs-4/packages/contacts/tcl/attribute-procs.tcl 18 May 2005 16:45:49 -0000 1.3 @@ -1,190 +1,190 @@ -ad_library { - - Support procs for attributes in the contacts package - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} - -namespace eval contacts::attribute { - - ad_proc -private create { - {-widget_id:required} - {-label:required} - {-help_text ""} - {-help_p ""} - {-html ""} - {-format ""} - } { - this code creates a new attributes - } { - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - return [db_exec_plsql create_attribute {}] - } - - - ad_proc -private delete { - {-attribute_id:required} - } { - this code deletes an attribute - } { - return [db_exec_plsql delete_attribute {} ] - } - - - ad_proc -public name { - {-locale ""} - attribute_id - } { - this code returns the name of an attribute - } { - - if { ![exists_and_not_null locale] } { - set locale [lang::conn::locale -site_wide] - } - - db_0or1row get_attribute_name {} - - if { ![exists_and_not_null name] } { - set locale "en_US" - db_0or1row get_view_name {} - } - - return $name - - } - - - - -} - - -namespace eval contacts::attribute::value { - - ad_proc -private save { - {-party_id:required} - {-attribute_id:required} - {-option_map_id ""} - {-address_id ""} - {-number_id ""} - {-time ""} - {-value ""} - {-deleted_p "f"} - } { - this code creates a new attributes - } { - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - return [db_exec_plsql attribute_value_save {}] - } - - -} - -namespace eval contacts::postal_address { - - - ad_proc -private new { - {-additional_text ""} - {-country_code ""} - {-delivery_address ""} - {-municipality ""} - {-postal_code ""} - {-postal_type ""} - {-region ""} - } { - this code saves a contact's address - } { - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - - return [db_exec_plsql postal_address_new {}] - } - - ad_proc -public get { - {-address_id:required} - {-array:required} - } { - get the info from addresses - } { - upvar $array row - - db_1row select_address_info {} -column_array row - } - -} - - - - -namespace eval contacts::telecom_number { - - ad_proc -private new { - {-area_city_code ""} - {-best_contact_time ""} - {-extension ""} - {-itu_id ""} - {-location ""} - {-national_number ""} - {-sms_enabled_p ""} - {-subscriber_number ""} - } { - this code saves a contact's phone_number - } { - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - - return [db_exec_plsql telecom_number_new {}] - } - - - - ad_proc -public get { - {-number_id:required} - {-array:required} - } { - get the variables from phone_numbers - } { - upvar $array row - db_0or1row select_telecom_number_info {} -column_array row - } - -} - - -namespace eval contacts::date { - - ad_proc -private sqlify { - {-date:required} - } { - this turns a form date into a timestamp postgresql likes - } { - set year [template::util::date::get_property year $date] - set month [template::util::date::get_property month $date] - set day [template::util::date::get_property day $date] - set hours [template::util::date::get_property hours $date] - set minutes [template::util::date::get_property minutes $date] - - set date "$year-$month-$day $hours:$minutes" - if { $date == "-- :" } { - set date "" - } - return $date - } - - -} - - - - - - - - - - +ad_library { + + Support procs for attributes in the contacts package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} + +namespace eval contacts::attribute { + + ad_proc -private create { + {-widget_id:required} + {-label:required} + {-help_text ""} + {-help_p ""} + {-html ""} + {-format ""} + } { + this code creates a new attributes + } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + return [db_exec_plsql create_attribute {}] + } + + + ad_proc -private delete { + {-attribute_id:required} + } { + this code deletes an attribute + } { + return [db_exec_plsql delete_attribute {} ] + } + + + ad_proc -public name { + {-locale ""} + attribute_id + } { + this code returns the name of an attribute + } { + + if { ![exists_and_not_null locale] } { + set locale [lang::conn::locale -site_wide] + } + + db_0or1row get_attribute_name {} + + if { ![exists_and_not_null name] } { + set locale "en_US" + db_0or1row get_view_name {} + } + + return $name + + } + + + + +} + + +namespace eval contacts::attribute::value { + + ad_proc -private save { + {-party_id:required} + {-attribute_id:required} + {-option_map_id ""} + {-address_id ""} + {-number_id ""} + {-time ""} + {-value ""} + {-deleted_p "f"} + } { + this code creates a new attributes + } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + return [db_exec_plsql attribute_value_save {}] + } + + +} + +namespace eval contacts::postal_address { + + + ad_proc -private new { + {-additional_text ""} + {-country_code ""} + {-delivery_address ""} + {-municipality ""} + {-postal_code ""} + {-postal_type ""} + {-region ""} + } { + this code saves a contact's address + } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + + return [db_exec_plsql postal_address_new {}] + } + + ad_proc -public get { + {-address_id:required} + {-array:required} + } { + get the info from addresses + } { + upvar $array row + + db_1row select_address_info {} -column_array row + } + +} + + + + +namespace eval contacts::telecom_number { + + ad_proc -private new { + {-area_city_code ""} + {-best_contact_time ""} + {-extension ""} + {-itu_id ""} + {-location ""} + {-national_number ""} + {-sms_enabled_p ""} + {-subscriber_number ""} + } { + this code saves a contact's phone_number + } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + + return [db_exec_plsql telecom_number_new {}] + } + + + + ad_proc -public get { + {-number_id:required} + {-array:required} + } { + get the variables from phone_numbers + } { + upvar $array row + db_0or1row select_telecom_number_info {} -column_array row + } + +} + + +namespace eval contacts::date { + + ad_proc -private sqlify { + {-date:required} + } { + this turns a form date into a timestamp postgresql likes + } { + set year [template::util::date::get_property year $date] + set month [template::util::date::get_property month $date] + set day [template::util::date::get_property day $date] + set hours [template::util::date::get_property hours $date] + set minutes [template::util::date::get_property minutes $date] + + set date "$year-$month-$day $hours:$minutes" + if { $date == "-- :" } { + set date "" + } + return $date + } + + +} + + + + + + + + + + Index: openacs-4/packages/contacts/tcl/category-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/category-procs-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/category-procs-postgresql.xql 27 Feb 2005 17:07:18 -0000 1.3 +++ openacs-4/packages/contacts/tcl/category-procs-postgresql.xql 18 May 2005 16:45:49 -0000 1.4 @@ -1,31 +1,29 @@ - - - -postgresql7.2 - - - - SELECT - t.name as cat_name, - t.category_id as cat_id, - tm.tree_id, - tt.name as tree_name - FROM - category_tree_map tm, - categories c, - category_translations t, - category_tree_translations tt - WHERE - c.tree_id = tm.tree_id and - c.category_id = t.category_id and - tm.object_id = :package_id and - tm.tree_id = tt.tree_id and - c.deprecated_p = 'f' - ORDER BY - tt.name, - t.name - - - - - + + + + + + SELECT + t.name as cat_name, + t.category_id as cat_id, + tm.tree_id, + tt.name as tree_name + FROM + category_tree_map tm, + categories c, + category_translations t, + category_tree_translations tt + WHERE + c.tree_id = tm.tree_id and + c.category_id = t.category_id and + tm.object_id = :package_id and + tm.tree_id = tt.tree_id and + c.deprecated_p = 'f' + ORDER BY + tt.name, + t.name + + + + + Index: openacs-4/packages/contacts/tcl/category-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/category-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/category-procs.tcl 13 Jan 2005 13:57:02 -0000 1.2 +++ openacs-4/packages/contacts/tcl/category-procs.tcl 18 May 2005 16:45:49 -0000 1.3 @@ -1,75 +1,75 @@ -ad_library { - - Support procs for the categorys in the contacts package - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} - - -namespace eval contacts::categories:: { - - - ad_proc -public enabled_p { - } { - returns 1 if categories are enabled or 0 if not - } { - if { [empty_string_p [category_tree::get_mapped_trees [ad_conn package_id]]] } { - return 0 - } else { - return 1 - } - } - - - ad_proc -public get_selects { - {-export_vars ""} - {-category_id ""} - } { - } { - # this is borrowed from project-manager but will be re-written - - - # Categories are arranged into category trees. - # Set up an array for each tree. The array contains the category for each tree - set package_id [ad_conn package_id] - - set category_select "" - set number_of_categories 0 - set last_tree "" - set category_select "" - - db_foreach get_categories {} { - - if {![string equal $tree_name $last_tree] } { - append category_select "" - } - - if {[string equal $cat_id $category_id]} { - set select "selected" - } else { - set select "" - } - - append category_select "" - - set last_tree $tree_name - incr number_of_categories - } - - if {$number_of_categories < 1} { - return "" - } - - set return_val "
$export_vars -
" - - return $return_val -} - -} - +ad_library { + + Support procs for the categorys in the contacts package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} + + +namespace eval contacts::categories:: { + + + ad_proc -public enabled_p { + } { + returns 1 if categories are enabled or 0 if not + } { + if { [empty_string_p [category_tree::get_mapped_trees [ad_conn package_id]]] } { + return 0 + } else { + return 1 + } + } + + + ad_proc -public get_selects { + {-export_vars ""} + {-category_id ""} + } { + } { + # this is borrowed from project-manager but will be re-written + + + # Categories are arranged into category trees. + # Set up an array for each tree. The array contains the category for each tree + set package_id [ad_conn package_id] + + set category_select "" + set number_of_categories 0 + set last_tree "" + set category_select "" + + db_foreach get_categories {} { + + if {![string equal $tree_name $last_tree] } { + append category_select "" + } + + if {[string equal $cat_id $category_id]} { + set select "selected" + } else { + set select "" + } + + append category_select "" + + set last_tree $tree_name + incr number_of_categories + } + + if {$number_of_categories < 1} { + return "" + } + + set return_val "
$export_vars +
" + + return $return_val +} + +} + Index: openacs-4/packages/contacts/tcl/contact-search-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-search-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/tcl/contact-search-procs.tcl 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,405 @@ +ad_library { + + Support procs for the contacts package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact-search-procs.tcl,v 1.1 2005/05/18 16:45:49 matthewg Exp $ + +} + +namespace eval contact:: {} +namespace eval contact::search:: {} +namespace eval contact::search::condition:: {} + + +ad_proc -public contact::search::new { + {-search_id ""} + {-title ""} + {-owner_id ""} + {-all_or_any} + {-object_type} +} { + create a contact search +} { + if { [exists_and_not_null owner_id] } { + set owner_id [ad_conn user_id] + } + set var_list [list \ + [list search_id $search_id] \ + [list title $title] \ + [list owner_id $owner_id] \ + [list all_or_any $all_or_any] \ + [list object_type $object_type] \ + ] + + return [package_instantiate_object -var_list $var_list contact_search] +} + +ad_proc -public contact::search::update { + {-search_id ""} + {-title ""} + {-owner_id ""} + {-all_or_any} +} { + create a contact search +} { + if { [contact::search::exists_p -search_id $search_id] } { + db_dml update_search { + update contact_searches + set title = :title, + owner_id = :owner_id, + all_or_any = :all_or_any + where search_id = :search_id + } + } +} + +ad_proc -public contact::search::delete { + {-search_id ""} +} { + create a contact search +} { + return [db_0or1row delete_it { select acs_object__delete(search_id) from contact_searches where search_id = :search_id }] +} + +ad_proc -public contact::search::exists_p { + {-search_id ""} +} { + create a contact search +} { + if { [db_0or1row exists_p { select 1 from contact_searches where search_id = :search_id }] } { + return 1 + } else { + return 0 + } +} + + +ad_proc -public contact::search::condition::new { + {-search_id} + {-type} + {-var_list} +} { + create a contact search +} { + if { [string is false [contact::search::condition::exists_p -search_id $search_id -type $type -var_list $var_list]] } { + db_dml insert_condition { + insert into contact_search_conditions + ( condition_id, search_id, type, var_list ) + values + ( (select acs_object_id_seq.nextval), :search_id, :type, :var_list ) + } + } +} + + +ad_proc -public contact::search::condition::delete { + {-condition_id} +} { + create a contact search +} { + db_dml insert_condition { + delete from contact_search_conditions where condition_id = :condition_id + } +} + +ad_proc -public contact::search::condition::exists_p { + {-search_id} + {-type} + {-var_list} +} { +} { + if { [db_0or1row exists_p { select 1 from contact_search_conditions where search_id = :search_id and type = :type and var_list = :var_list }] } { + return 1 + } else { + return 0 + } +} + + + + +ad_proc -public contact::search::where_clauses { + {-search_id} + {-and:boolean} + {-party_id} + {-revision_id} +} { +} { + db_1row get_em { select title, owner_id, all_or_any, object_type from contact_searches where search_id = :search_id } + if { $all_or_any == "any" } { + set operator "or" + } else { + set operator "and" + } + set where_clause "" + set first_condition_p 1 + db_foreach selectqueries { + select type, var_list from contact_search_conditions where search_id = :search_id + } { + if { [string is false $first_condition_p] } { + append where_clause "\n${operator} " + } + append where_clause [contact::search::translate -type $type -var_list $var_list -to code -revision_id $revision_id -party_id $party_id] + set first_condition_p 0 + } + if { [exists_and_not_null where_clause] } { + if { $and_p } { + set where_clause "\n and ( $where_clause )" + } else { + set where_clause "\n ( $where_clause )" + } + } + return $where_clause + +} + +ad_proc -public contact::search::translate { + {-type} + {-var_list} + {-to "code"} + {-party_id} + {-revision_id} +} { + returns the group_id for which this group is a component, if none then it return null +} { + set output_code "" + set output_pretty "" + switch $type { + attribute { + set attribute_id [lindex $var_list 0] + if { $to == "pretty" } { + set attribute_pretty [attribute::pretty_name -attribute_id $attribute_id] + } else { + set attribute_pretty "irrelevant" + } + + set operand [lindex $var_list 1] + set value [string tolower [lindex $var_list 2]] + + switch $operand { + set { + set output_pretty "$attribute_pretty is set" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'" + } + not_set { + set output_pretty "$attribute_pretty is not set" + set output_code "$revision_id not in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'" + } + default { + ams::attribute::get -attribute_id $attribute_id -array "attr_info" + set value_method [ams::widget -widget $attr_info(widget) -request "value_method"] + + switch $value_method { + ams_value__options { + if { $to == "pretty" } { + set option_pretty [ams::option::name -option_id $value] + } else { + set option_pretty "" + } + + switch $operand { + selected { + set output_pretty "$attribute_pretty is: $option_pretty" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_options ao${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = ao${attribute_id}.value_id and ao${attribute_id}.option_id = '$value' )" + } + not_selected { + set output_pretty "$attribute_pretty is not: $option_pretty" + set output_code "$revision_id not in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_options ao${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = ao${attribute_id}.value_id and ao${attribute_id}.option_id = '$value' )" + } + } + } + ams_value__telecom_number { + switch $operand { + area_code_equals { + set output_pretty "$attribute_pretty area code is: $option_pretty" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, telecom_numbers tn${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav.${attribute_id}.value_id = tn${attribute_id}.number_id and tn${attribute_id}.area_city_code = '$value' )" + } + not_area_code_equals { + set output_pretty "$attribute_pretty area code is not: $option_pretty" + set output_code "$revision_id not in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, telecom_numbers tn${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav.${attribute_id}.value_id = tn${attribute_id}.number_id and tn${attribute_id}.area_city_code = '$value' )" + } + country_code_equals { + set output_pretty "$attribute_pretty country code is: $option_pretty" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, telecom_numbers tn${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav.${attribute_id}.value_id = tn${attribute_id}.number_id and tn${attribute_id}.country_code = '$value' )" + } + not_country_code_equals { + set output_pretty "$attribute_pretty country code is not: $option_pretty" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, telecom_numbers tn${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav.${attribute_id}.value_id = tn${attribute_id}.number_id and tn${attribute_id}.area_city_code = '$value' )" + } + } + } + ams_value__text { + switch $operand { + contains { + set output_pretty "$attribute_pretty contains: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_texts at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and lower(at${attribute_id}.text) like ('\%$value\%')\n)" + } + not_contains { + set output_pretty "$attribute_pretty does not contain: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_texts at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and lower(at${attribute_id}.text) not like ('\%$value\%')\n)" + } + } + } + ams_value__postal_address { + set value [string toupper $value] + switch $operand { + country_is { + set output_pretty "$attribute_pretty country is: [_ ams.country_${value}]" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.country_code = '$value' )" + } + country_is_not { + set output_pretty "$attribute_pretty country is not: [_ ams.country_${value}]" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.country_code = '$value' )" + } + state_is { + set output_pretty "$attribute_pretty state/province is: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.region = '$value' )" + } + state_is_not { + set output_pretty "$attribute_pretty state/province is not: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.region = '$value' )" + } + zip_is { + set output_pretty "$attribute_pretty zip/postal starts with: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.postal_code like ('$value\%') )" + } + zip_is_not { + set output_pretty "$attribute_pretty zip/postal does not start with: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, postal_addresses pa${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}' and aav${attribute_id}.value_id = pa${attribute_id}.address_id and pa${attribute_id}.postal_code like ('$value\%') )" + } + } + } + ams_value__number { + switch $operand { + is { + set output_pretty "$attribute_pretty is: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_numbers an${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = an${attribute_id}.value_id\n and an${attribute_id}.number = '$value' )" + } + greater_than { + set output_pretty "$attribute_pretty is greater than: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_numbers an${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = an${attribute_id}.value_id\n and an${attribute_id}.number > '$value' )" + } + less_than { + set output_pretty "$attribute_pretty is less than: $value" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_numbers an${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = an${attribute_id}.value_id\n and an${attribute_id}.number < '$value' )" + } + } + } + ams_value__time { + set interval "$value [string tolower [lindex $var_list 3]]" + switch $operand { + less_than { + set output_pretty "$attribute_pretty is less than $interval ago" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_times at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and at${attribute_id}.time > ( now() - '$interval'::interval ) )" + } + more_than { + set output_pretty "$attribute_pretty is less than $interval ago" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_times at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and at${attribute_id}.time < ( now() - '$interval'::interval ) )" + } + after { + set output_pretty "$attribute_pretty is after: [lc_time_fmt $value %q]" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_times at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and at${attribute_id}.time > '$value'::timestamptz )" + } + before { + set output_pretty "$attribute_pretty is before: [lc_time_fmt $value %q]" + set output_code "$revision_id in (\n\select aav${attribute_id}.object_id\n from ams_attribute_values aav${attribute_id}, ams_times at${attribute_id}\n where aav${attribute_id}.attribute_id = '${attribute_id}'\n and aav${attribute_id}.value_id = at${attribute_id}.value_id\n and at${attribute_id}.time < '$value'::timestamptz )" + } + } + } + } + } + } + } + contact { + set operand [lindex $var_list 0] + set interval "[lindex $var_list 1] [lindex $var_list 2]" + switch $operand { + update { + set output_pretty "Contact updated in the last: $interval" + set output_code "CASE WHEN ( select creation_date from acs_objects where object_id = $revision_id ) > ( now() - '$interval'::interval ) THEN 't'::boolean ELSE 'f'::boolean END" + } + not_update { + set output_pretty "Contact not updated in the last: $interval" + set output_code "CASE WHEN ( select creation_date from acs_objects where object_id = $revision_id ) > ( now() - '$interval'::interval ) THEN 'f'::boolean ELSE 't'::boolean END" + } + comment { + set output_pretty "Contact commented on in the last: $interval" + set output_code "CASE WHEN (select creation_date from acs_objects where object_id in ( select comment_id from general_comments where object_id = $party_id ) order by creation_date desc limit 1 ) > ( now() - '$interval'::interval ) THEN 't'::boolean ELSE 'f'::boolean END" + } + not_comment { + set output_pretty "Contact not commented on in the last: $interval" + set output_code "CASE WHEN (select creation_date from acs_objects where object_id in ( select comment_id from general_comments where object_id = $party_id ) order by creation_date desc limit 1 ) > ( now() - '$interval'::interval ) THEN 'f'::boolean ELSE 't'::boolean END" + } + created { + set output_pretty "Contact created in the last: $interval" + set output_code "CASE WHEN ( select scrr.creation_date from acs_objects where object_id = $party_id ) > ( now() - '$interval'::interval ) THEN 't'::boolean ELSE 'f'::boolean END" + } + not_created { + set output_pretty "Contact not created in the last: $interval" + set output_code "CASE WHEN ( select scrr.creation_date from acs_objects where object_id = $party_id ) > ( now() - '$interval'::interval ) THEN 'f'::boolean ELSE 't'::boolean END" + } + login { + set output_pretty "Contact has logged in" + set output_code "CASE WHEN ( select n_sessions from users where user_id = $party_id ) > 1 or ( select last_visit from users where user_id = $party_id ) is not null THEN 't'::boolean ELSE 'f'::boolean END" + } + not_login { + set output_pretty "Contact has never logged in" + set output_code "CASE WHEN ( select n_sessions from users where user_id = $party_id ) > 1 or ( select last_visit from users where user_id = $party_id ) is not null THEN 'f'::boolean ELSE 't'::boolean END" + } + login_time { + set output_pretty "Contact has logged in within the last: $interval" + set output_code "CASE WHEN ( select last_visit from users where user_id = $party_id ) > ( now() - '$interval'::interval ) THEN 't'::boolean ELSE 'f'::boolean END" + } + not_login_time { + set output_pretty "Contact has not logged in within the last: $interval" + set output_code "CASE WHEN ( select last_visit from users where user_id = $party_id ) > ( now() - '$interval'::interval ) THEN 'f'::boolean ELSE 't'::boolean END" + } + } + } + group { + set operand [lindex $var_list 0] + set group_id [lindex $var_list 1] + if { $to == "pretty" } { + set group_pretty [db_string select_group_name { select group_name from groups where group_id = :group_id }] + } else { + set group_pretty "" + } + switch $operand { + in { + set output_pretty "The contact is in the group: $group_pretty" + set output_code "$party_id in ( select member_id from group_distinct_member_map where group_id = '$group_id')" + } + not_in { + set output_pretty "The contact is NOT in the group: $group_pretty" + set output_code "$party_id not in ( select member_id from group_distinct_member_map where group_id = '$group_id')" + } + } + } + tasks { + switch $to { + pretty { + set output $var_list + } + code { + set output $var_list + } + } + } + } + if { ![exists_and_not_null output_pretty] || ![exists_and_not_null output_code] } { + if { [exists_and_not_null error_message] } { + error "The query \"$type $var_list\" is no longer valid because: $error_message" + } else { + error "The query \"$type $var_list\" is no longer valid. Contact an admin." + } + } else { + switch $to { + code { return $output_code } + pretty { return $output_pretty } + } + } +} + + Index: openacs-4/packages/contacts/tcl/contacts-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-init.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/contacts-init.tcl 13 Jan 2005 13:57:02 -0000 1.2 +++ openacs-4/packages/contacts/tcl/contacts-init.tcl 18 May 2005 16:45:49 -0000 1.3 @@ -7,5 +7,88 @@ @cvs-id $Id$ } -# set up contacts -contacts::view::init + +set attribute_id [attribute::new \ + -object_type "person" \ + -attribute_name "first_names" \ + -datatype "string" \ + -pretty_name "First Names" \ + -pretty_plural "First Names" \ + -table_name "" \ + -column_name "" \ + -default_value "" \ + -min_n_values "0" \ + -max_n_values "1" \ + -sort_order "1" \ + -storage "type_specific" \ + -static_p "f" \ + -if_does_not_exist] + +ams::attribute::new \ + -attribute_id $attribute_id \ + -widget "textbox" \ + -dynamic_p "f" + +set attribute_id [attribute::new \ + -object_type "person" \ + -attribute_name "last_name" \ + -datatype "string" \ + -pretty_name "Last Name" \ + -pretty_plural "Last Names" \ + -table_name "" \ + -column_name "" \ + -default_value "" \ + -min_n_values "0" \ + -max_n_values "1" \ + -sort_order "1" \ + -storage "type_specific" \ + -static_p "f" \ + -if_does_not_exist] + +ams::attribute::new \ + -attribute_id $attribute_id \ + -widget "textbox" \ + -dynamic_p "f" + +set attribute_id [attribute::new \ + -object_type "party" \ + -attribute_name "email" \ + -datatype "string" \ + -pretty_name "Email Address" \ + -pretty_plural "Email Addresses" \ + -table_name "" \ + -column_name "" \ + -default_value "" \ + -min_n_values "0" \ + -max_n_values "1" \ + -sort_order "1" \ + -storage "type_specific" \ + -static_p "f" \ + -if_does_not_exist] + +ams::attribute::new \ + -attribute_id $attribute_id \ + -widget "email" \ + -dynamic_p "f" + +set attribute_id [attribute::new \ + -object_type "organization" \ + -attribute_name "name" \ + -datatype "string" \ + -pretty_name "Name" \ + -pretty_plural "Names" \ + -table_name "" \ + -column_name "" \ + -default_value "" \ + -min_n_values "1" \ + -max_n_values "1" \ + -sort_order "1" \ + -storage "generic" \ + -static_p "f" \ + -if_does_not_exist] + +ams::attribute::new \ + -attribute_id $attribute_id \ + -widget "textbox" \ + -dynamic_p "t" + Index: openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 27 Feb 2005 17:07:18 -0000 1.3 +++ openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 18 May 2005 16:45:49 -0000 1.4 @@ -1,372 +1,69 @@ -postgresql7.2 - - + - select 1 from contacts where party_id = :party_id + select groups.group_id, + groups.group_name, + ( select count(distinct gamm.member_id) from group_approved_member_map gamm where gamm.group_id = groups.group_id ) as member_count, + ( select count(distinct gcm.component_id) from group_component_map gcm where gcm.group_id = groups.group_id) as component_count, + CASE WHEN package_id is not null THEN '1' ELSE '0' END as mapped_p, + CASE WHEN default_p THEN '1' ELSE '0' END as default_p + from groups left join contact_groups on ( groups.group_id = contact_groups.group_id ) + where groups.group_id != '-1' + and groups.group_id not in ( select gcm.component_id from group_component_map gcm where gcm.group_id != -1 ) + and acs_permission__permission_p(groups.group_id,:user_id,:privilege_required) + order by CASE WHEN contact_groups.default_p THEN '000000000' ELSE upper(groups.group_name) END - - + - select * from contacts where party_id = :party_id + select groups.group_id, + groups.group_name, + ( select count(distinct gamm.member_id) from group_approved_member_map gamm where gamm.group_id = groups.group_id ) as member_count, + CASE WHEN package_id is not null THEN '1' ELSE '0' END as mapped_p, + CASE WHEN default_p THEN '1' ELSE '0' END as default_p + from groups left join contact_groups on ( groups.group_id = contact_groups.group_id ), group_component_map + where group_component_map.group_id = :group_id + and group_component_map.component_id = groups.group_id + order by upper(groups.group_name) - - + - select * from contacts where party_id = :party_id + select group_id + from group_component_map + where component_id = :group_id + and group_id != '-1' - - + - select '1' from users where user_id = :party_id + select acs_group__new ( + :group_id, + 'group', + now(), + :creation_user, + :creation_ip, + :email, + :url, + :group_name, + :join_policy, + :context_id + ) - - + - select nextval from acs_object_id_seq - - - - - - - select object_id from contact_object_types where object_type = 'organization' - - - - - - - select object_id from contact_object_types where object_type = 'person' - - - - - - - select * - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom, - contact_attribute_names can - where caom.object_id = :object_id - and ca.attribute_id = can.attribute_id - and can.locale = :locale - and caom.attribute_id = ca.attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.attribute_id,:user_id,'write') - order by caom.sort_order - - - - - - - - select ca.attribute_id, - ca.attribute, - cav.option_map_id, - cav.address_id, - cav.number_id, - to_char(cav.time,'YYYY MM DD') as time, - cav.value, - cav.value_format, - cw.storage_column - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom left join - ( select * - from contact_attribute_values - where party_id = :party_id - and not deleted_p ) cav - on (caom.attribute_id = cav.attribute_id) - where caom.object_id = '$object_id' - and caom.attribute_id = ca.attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and ( - cav.option_map_id is not null - or cav.address_id is not null - or cav.number_id is not null - or cav.value is not null - or cav.time is not null - or ca.attribute in ($custom_field_sql_list) - ) - and acs_permission__permission_p(ca.attribute_id,'$user_id','$permission') - order by caom.sort_order - - - - - - - select name - from organizations - where organization_id = :party_id - - - - - - - select legal_name - from organizations - where organization_id = :party_id - - - - - - - select reg_number - from organizations - where organization_id = :party_id - - - - - - - select first_names - from persons - where person_id = :party_id - - - - - - - select cao.option_id, cao.option - from contact_attribute_options cao, - organization_types ot, - organization_type_map otm - where cao.option = ot.type - and cao.attribute_id = :attribute_id - and otm.organization_type_id = ot.organization_type_id - and otm.organization_id = :party_id - - - - - - - select first_names - from persons - where person_id = :party_id - - - - - - - select last_name - from persons - where person_id = :party_id - - - - - - - select email - from parties - where party_id = :party_id - - - - - - - select url - from parties - where party_id = :party_id - - - - - - - select cao.option, cao.option_id - from contact_attribute_options cao, - contact_attribute_option_map caom - where caom.option_id = cao.option_id - and caom.option_map_id = :option_map_id - - - - - - select * - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom, - contact_attribute_names can - where caom.object_id = :object_id - and ca.attribute_id = can.attribute_id - and can.locale = :locale - and caom.attribute_id = ca.attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.attribute_id,:user_id,'write') - order by caom.sort_order - - - - - - - select cav.address_id as old_address_id - from contact_attribute_values cav, - postal_addresses pa - where cav.party_id = :party_id - and cav.attribute_id = :attribute_id - and not cav.deleted_p - and cav.address_id = pa.address_id - and pa.delivery_address = :delivery_address - and pa.municipality = :municipality - and pa.region = :region - and pa.postal_code = :postal_code - and pa.country_code = :country_code - - - - - - - select cav.number_id as old_number_id - from contact_attribute_values cav, - telecom_numbers tn - where cav.party_id = :party_id - and cav.attribute_id = :attribute_id - and not cav.deleted_p - and cav.number_id = tn.number_id - and tn.subscriber_number = :attribute_value_temp - - - - - - - select option_map_id - from contact_attribute_values - where party_id = :party_id - and attribute_id = :attribute_id and not deleted_p - - - - - - - select option_id - from contact_attribute_option_map - where option_map_id = :option_map_id - - - - - - - select nextval('contact_attribute_option_map_id_seq') as option_map_id - - - - - - - insert into contact_attribute_option_map - (option_map_id,party_id,option_id) + insert into contact_groups + (group_id,owner_id,group_type,deprecated_p,package_id) values - (:option_map_id,:party_id,:option_id) + (:group_id,:owner_id,:group_type,:deprecated_p,:package_id) - - - - update parties set email = :attribute_value_temp where party_id = :party_id - - - - - - - update parties set url = :attribute_value_temp where party_id = :party_id - - - - - - - update organizations set name = :attribute_value_temp where organization_id = :party_id - - - - - - - update organizations set legal_name = :attribute_value_temp where organization_id = :party_id - - - - - - - update organizations set reg_number = :attribute_value_temp where organization_id = :party_id - - - - - - - delete from organization_type_map where organization_id = :party_id - - - - - - - select organization_type_id - from contact_attribute_options cao, - organization_types ot - where cao.option = ot.type - and cao.option_id = :option_id - - - - - - - insert into organization_type_map - (organization_id, organization_type_id) - values - (:party_id, :organization_type_id) - - - - - - - update persons set first_names = :attribute_value_temp where person_id = :party_id - - - - - - - update persons set last_name = :attribute_value_temp where person_id = :party_id - - - - Index: openacs-4/packages/contacts/tcl/contacts-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 13 Jan 2005 13:57:05 -0000 1.2 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 18 May 2005 16:45:49 -0000 1.3 @@ -8,718 +8,351 @@ } -namespace eval contact:: { +namespace eval contacts:: {} +namespace eval contact:: {} +namespace eval contact::util:: {} +namespace eval contact::group:: {} +namespace eval contact::revision:: {} +namespace eval contact::special_attributes:: {} - ad_proc -public name { - party_id - } { - this returns the contact's name - } { - return [contact::get::name $party_id] - } - ad_proc -public exists_p { - party_id - } { - this code returns 1 if the party_id exists - } { - return [db_0or1row exists_p {}] +ad_proc -public contacts::default_group { + {-package_id ""} +} { + returns the group_id for which this group is a component, if none then it return null +} { + if { [string is false [exists_and_not_null package_id]] } { + set package_id [ad_conn package_id] } + return [db_string get_default_group { select group_id from contact_groups where package_id =:package_id and default_p } -default {}] +} - ad_proc -public get { - party_id - } { - get the info on the contact - } { - db_0or1row get_contact_info {} - set contact_info [ns_set create] - ns_set put $contact_info party_id $party_id - ns_set put $contact_info object_type $object_type - ns_set put $contact_info name $name - ns_set put $contact_info legal_name $legal_name - ns_set put $contact_info reg_number $reg_number - ns_set put $contact_info first_names $first_names - ns_set put $contact_info last_name $last_name - ns_set put $contact_info sort_first_names $sort_first_names - ns_set put $contact_info sort_last_name $sort_last_name - ns_set put $contact_info email $email - ns_set put $contact_info url $url - ns_set put $contact_info user_p $user_p +ad_proc -private contact::util::interpolate { + {-values:required} + {-text:required} +} { + Interpolates a set of values into a string. This is directly copied from the bulk mail package - # Now, set the variables in the caller's environment - ad_ns_set_to_tcl_vars -level 2 $contact_info - ns_set free $contact_info + @param values a list of key, value pairs, 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 pair $values { + regsub -all [lindex $pair 0] $text [lindex $pair 1] text } + return $text +} - +ad_proc -public contact::name { + {-party_id:required} +} { + this returns the contact's name +} { + if { [contact::person_p -party_id $party_id] } { + return [person::name -person_id $party_id] + } else { + # if there is an org the name is returned otherwise null is returned + return [db_string get_org_name { select name from organizations where organization_id = :party_id } -default {}] + } } -namespace eval contact::get:: { - - ad_proc -public array { - party_id - array - } { - get the info from addresses - } { - upvar $array row - db_0or1row select_address_info {} -column_array row +ad_proc -public contact::type { + {-party_id:required} +} { + this returns the contact's name +} { + if { [contact::person_p -party_id $party_id] } { + return "person" + } elseif { [contact::organization_p -party_id $party_id] } { + return "organization" + } else { + return "" } +} - - ad_proc -public object_type { - party_id - } { - returns the parties object_type - } { - contact::get $party_id - return $object_type +ad_proc -public contact::exists_p { + {-party_id:required} +} { + does this contact exist? +} { + # persons can be organizations so we need to do the check this way + if { [contact::person_p -party_id $party_id] } { + return 1 + } elseif { [contact::organization_p -party_id $party_id] } { + return 1 + } else { + return 0 } +} - ad_proc -public name { - party_id - } { - returns the parties sort_first_names - } { - contact::get $party_id - return $sort_first_names +ad_proc -public contact::person_p { + {-party_id:required} +} { + this returns the contact's name +} { + if { [db_0or1row contact_person_exists_p { select '1' from persons where person_id = :party_id }] } { + return 1 + } else { + return 0 } +} - ad_proc -public custom_field_list { - party_id - } { - set custom_field_list [list email url] - set object_type [contact::get::object_type $party_id] - if { $object_type == "organization" } { - lappend custom_field_list "organization_type" - lappend custom_field_list "organization_name" - lappend custom_field_list "legal_name" - lappend custom_field_list "reg_number" - } - if { $object_type == "person" } { - lappend custom_field_list "first_names" - lappend custom_field_list "last_name" - } - return $custom_field_list +ad_proc -public contact::organization_p { + {-party_id:required} +} { + this returns the contact's name +} { + if { [contact::person_p -party_id $party_id] } { + return 0 + } else { + if { [db_0or1row contact_org_exists_p { select '1' from organizations where organization_id = :party_id }] } { + return 1 + } else { + return 0 + } + } } - +ad_proc -public contact::url { + {-party_id:required} +} { + create a contact revision +} { + return [export_vars -url -base contact {party_id}] } - +ad_proc -public contact::revision::new { + {-party_id:required} + {-party_revision_id ""} +} { + create a contact revision +} { + set extra_vars [ns_set create] + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list { party_id party_revision_id } + return [package_instantiate_object -extra_vars $extra_vars contact_party_revision] +} -namespace eval contacts::util:: { +ad_proc -public contact::live_revision { + {-party_id:required} +} { + create a contact revision +} { + if { [db_0or1row revision_exists_p { select 1 from cr_items where item_id = :party_id }] } { + return [item::get_live_revision $party_id] + } else { + return "" + } +} - ad_proc -public party_is_user_p { - party_id - } { - returns 1 if the party is a user and 0 if not - } { - return [db_0or1row get_party_is_user_p {} ] +ad_proc -public contact::subsite_user_group { + {-party_id:required} +} { + create a contact revision +} { + if { [db_0or1row revision_exists_p { select 1 from cr_items where item_id = :party_id }] } { + return [item::get_live_revision $party_id] + } else { + return "" } +} - ad_proc -public next_object_id { - } { - returns the next available object_id - } { - db_1row get_next_object_id {} - return $nextval - } - +ad_proc -private contact::group::new { + {-group_id ""} + {-email ""} + {-url ""} + -group_name:required + {-join_policy "open"} + {-context_id:required} +} { + this creates a new group for use with contacts (and the permissions system) +} { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + return [db_string create_group {}] +} - ad_proc -public organization_object_id { - } { - returns the object_id of the organization contact_object_type - } { - db_1row get_organization_object_id {} - return $object_id +ad_proc -public contact::group::map { + -group_id:required + {-owner_id ""} + {-group_type "private"} + {-package_id ""} +} { + this creates a new group for use with contacts (and the permissions system) +} { + if { [exists_and_not_null owner_id] } { + set owner_id [ad_conn user_id] } - - ad_proc -public person_object_id { - } { - returns the object_id of the organization contact_object_type - } { - db_1row get_object_id {} - return $object_id + if { [exists_and_not_null package_id] } { + set package_id [ad_conn package_id] } - - # some of this codes was borrowed from the directory module - ad_proc -public letter_bar { - {-export_vars ""} - {-letter ""} - {-initial_list:required} - } { - Returns an A-Z bar with greyed out letters not - in initial_list and bolds "letter". - - Includes all existing url vars except those in - the "excluded_vars" list. - } { - set all_letters [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] - - set html_list [list] - foreach l $all_letters { - if { [lsearch -exact $initial_list $l] == -1 } { - # This means no user has this initial - lappend html_list "$l" - } elseif { [string compare $l $letter] == 0 } { - lappend html_list "$l" - } else { - lappend html_list "$l" - } - } - if { [empty_string_p $letter] || [string compare $letter "all"] == 0 } { - lappend html_list "\#contacts.All\#" - } else { - lappend html_list "\#contacts.All\#" - } - return "[join $html_list " | "]" - } - + db_dml map_group {} +} - ad_proc -public sqlify_list { - variable_list - } { - set output_list {} - foreach item $variable_list { - if { [exists_and_not_null output_list] } { - append output_list ", " - } - append output_list "'$item'" - } - return $output_list - } - +ad_proc -public contact::group::parent { + -group_id:required +} { + returns the group_id for which this group is a component, if none then it return null +} { + return [db_string get_parent {} -default {}] } - - -namespace eval contacts::get { - - ad_proc -public ad_form_elements { - object_id - party_id - } { - this code lists the form elements for a contact (after checking whether or not the user has permission to edit/add this info) - } { - - - set locale [lang::conn::locale -site_wide] - set user_id [ad_conn user_id] - - set active_group_id "" - - set element_list "" - if { [string is true [contact::exists_p $party_id]] } { - set object_type [contact::get::object_type $party_id] - } else { - # since the party doesn't exist yet, we assume that - # contacts is calling this proc to create a person - # or an organization - if { $object_id == [contacts::util::organization_object_id] } { - set object_type "organization" - } else { - set object_type "person" +ad_proc -public contact::groups { + {-expand "all"} + {-indent_with "..."} + {-privilege_required "read"} + {-output "list"} + {-all:boolean} +} { +} { + set user_id [ad_conn user_id] + set group_list [list] + db_foreach get_groups {} { + if { $mapped_p || $all_p } { + lappend group_list [list $group_name $group_id $member_count "1" $mapped_p $default_p] + if { $component_count > 0 && ( $expand == "all" || $expand == $group_id ) } { + db_foreach get_components {} { + lappend group_list [list "$indent_with$group_name" $group_id $member_count "2" $mapped_p $default_p] + } } } - db_foreach select_attributes {} { - - if { [lsearch [list first_names last_name email url] $attribute] >= 0 } { - if { [contacts::util::party_is_user_p $party_id] } { - if { ![string compare $party_id [ad_conn user_id]] } { - set help_text "This will change your account info." - } elseif { [acs_user::site_wide_admin_p] } { - set help_text "This will change [person::name -person_id $party_id]'s account info." - } else { -# set help_text "You may not edit this information since [person::name -person_id $party_id] is a user of this system." - set widget "inform" - } - } + } + switch $output { + list { + set list_output [list] + foreach group $group_list { + lappend list_output [list [lindex $group 0] [lindex $group 1] [lindex $group 2]] } - - - if { [contacts::util::party_is_user_p $party_id] && ![string compare $attribute "email"] } { - set required_p 1 + return $list_output + } + ad_form { + set ad_form_output [list] + foreach group $group_list { + lappend ad_form_output [list [lindex $group 0] [lindex $group 1]] } - if { $object_type == "person" } { - if { [lsearch [list first_names last_name] $attribute] >= 0 } { - set required_p 1 - } - } - if { $object_type == "organization" } { - if { [lsearch [list organization_name organization_type] $attribute] >= 0 } { - set required_p 1 - } - } - - - - - - - set widget_string "contact_attribute__$attribute\:$datatype\($widget\)" - - - if { ![exists_and_not_null required_p] } { - append widget_string ",optional" - } else { - if { [string is false $required_p] } { - append widget_string ",optional" - } - } - if { [exists_and_not_null multiple_p] } { - if { [string is true $multiple_p] } { - append widget_string ",multiple" - } - } - - if { [exists_and_not_null nospell_p] } { - if { [string is true $nospell_p] } { - append widget_string ",nospell" - } - } - - - set temp_element [list $widget_string [list "label" "$name"]] - - if { $storage_column == "option_map_id" } { - lappend temp_element [list "options" [db_list_of_lists select_element_options { - select option, option_id - from contact_attribute_options - where attribute_id = :attribute_id - order by sort_order - } ]] - } - - if { [exists_and_not_null help_p] } { - if { [string is true $help_p] } { - lappend temp_element "help" - } - } - - if { [exists_and_not_null help_text] } { - lappend temp_element [list "help_text" $help_text] - } - - if { $datatype == "date" && [exists_and_not_null format] } { - lappend temp_element [list "format" "$format"] - } - - if { [exists_and_not_null html] } { - set temp_html "" - foreach element [lrange $html 0 [llength $html]] { - lappend temp_html "[lindex $element 0]" - } - if { [exists_and_not_null temp_html] } { - lappend temp_element [list "html" $temp_html] - } - } - - if { [exists_and_not_null heading] } { - lappend temp_element [list "section" "$heading"] - } - - lappend element_list "$temp_element" + return $ad_form_output } - - return $element_list + default { + return $group_list + } } +} +ad_proc -public contact::special_attributes::ad_form_values { + -party_id:required + -form:required +} { +} { + set object_type [contact::type -party_id $party_id] + db_1row get_extra_info { + select email, url + from parties + where party_id = :party_id + } + set element_list [list email url] + if { $object_type == "person" } { - ad_proc -public ad_form_values { - object_id - party_id - } { - get the attribute_values for a contact - } { + array set person [person::get -person_id $party_id] + set first_names $person(first_names) + set last_name $person(last_name) - if { [string is true [contact::exists_p $party_id]] } { - set user_id [ad_conn user_id] - + lappend element_list first_names last_name - contacts::get::values::multirow -multirow_name "ad_form_values" -party_id $party_id -object_id $object_id -permission "write" + } elseif { $object_type == "organization" } { + db_0or1row get_org_info { + select name, legal_name, reg_number, notes + from organizations + where organization_id = :party_id + } + lappend element_list name legal_name reg_number notes - set courses_info_set [ns_set create] - - template::multirow -unclobber foreach ad_form_values { - ns_set put $courses_info_set contact_attribute__$attribute_name $ad_form_value - } - - # Now, set the variables in the caller's environment - ad_ns_set_to_tcl_vars -level 2 $courses_info_set - ns_set free $courses_info_set - - } } - - -} - - -namespace eval contacts::get::values:: { - - ad_proc multirow { - {-multirow_name} - {-permission "read"} - {-object_id} - {-party_id} - {-orderby "sort_order,asc"} - } { - Returns a multirow - } { - - set user_id [ad_conn user_id] - - template::multirow create $multirow_name attribute_name attribute_id pretty_attribute_name ad_form_value pretty_value pretty_value_html sort_order sort_key - - set custom_field_list [contact::get::custom_field_list $party_id] - set custom_field_sql_list [contacts::util::sqlify_list $custom_field_list] - - set sort_order "0" - - db_foreach select_attribute_values "" { - - set attribute_name $attribute - set attribute_id $attribute_id - set pretty_attribute_name [contacts::attribute::name $attribute_id] - - if { [lsearch $custom_field_list $attribute] >= 0 } { - - if { $attribute == "organization_name" } { - set ad_form_value [db_string organization_name_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "organization_type" } { - set ad_form_value [list] - set pretty_value {} - db_foreach organization_types_from_party_and_attribute_id {} { - if { [llength $ad_form_value] > 0 } { - append pretty_value "\n" - } - lappend ad_form_value $option_id - append pretty_value $option - } - } - if { $attribute == "legal_name" } { - set ad_form_value [db_string legal_name_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "reg_number" } { - set ad_form_value [db_string reg_number_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "first_names" } { - set ad_form_value [db_string first_names_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "last_name" } { - set ad_form_value [db_string last_name_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "email" } { - set ad_form_value [db_string email_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - if { $attribute == "url" } { - set ad_form_value [db_string url_from_party_id {} -default {}] - set pretty_value $ad_form_value - } - - } else { - - set pretty_value $value - set ad_form_value $value - - if { $storage_column == "address_id" } { - contacts::postal_address::get -address_id "$address_id" -array "address_info" - set ad_form_value [list $address_info(delivery_address) $address_info(municipality) $address_info(region) $address_info(postal_code) $address_info(country_code)] - set pretty_value "$address_info(delivery_address)\n$address_info(municipality), $address_info(region) $address_info(postal_code)\n$address_info(country_code)" - } - if { $storage_column == "number_id" && [exists_and_not_null number_id] } { - contacts::telecom_number::get -number_id $number_id -array "telecom_info" - set ad_form_value $telecom_info(subscriber_number) - set pretty_value $telecom_info(subscriber_number) - } - if { $storage_column == "time" && [exists_and_not_null time] } { - set ad_form_value $time - set pretty_value $time - } - if { $storage_column == "option_map_id" && [exists_and_not_null option_map_id] } { - set pretty_value {} - set ad_form_value [list] - db_foreach select_options_from_map {} { - if { [llength $ad_form_value] > 0 } { - # we know there has been a previous entry so we can put in a comma - append pretty_value "\n" - } - append pretty_value $option - lappend ad_form_value $option_id - } - } - - } - if { [exists_and_not_null ad_form_value] || [exists_and_not_null pretty_value] } { - incr sort_order - set pretty_value_html [ad_convert_to_html $pretty_value] - template::multirow append $multirow_name $attribute_name $attribute_id $pretty_attribute_name $ad_form_value $pretty_value $pretty_value_html $sort_order - } - - } - - set orderby [split $orderby ","] - set orderby_field [lindex $orderby 0] - if { [lindex $orderby 1] == "asc" } { - set orderby_direction {-increasing} - } else { - set orderby_direction {-decreasing} - } - template::multirow sort $multirow_name -dictionary $orderby_direction $orderby_field - + foreach element $element_list { + if { [exists_and_not_null $element] } { + if { [template::element::exists $form $element] } { + template::element::set_value $form $element [set $element] + } + } } - - } - -namespace eval contacts::save::ad_form { - - ad_proc -public values { - object_id - party_id - - } { - this code saves attributes input in a form - } { - - set user_id [ad_conn user_id] - - if { [exists_and_not_null party_id] } { - if { ![contact::exists_p $party_id] } { - set party_id [contacts::contact::create -party_id $party_id] - } - } else { - set party_id [contacts::contact::create] +ad_proc -public contact::special_attributes::ad_form_save { + -party_id:required + -form:required +} { +} { + set object_type [contact::type -party_id $party_id] + set element_list [list email url] + if { $object_type == "person" } { + lappend element_list first_names last_name + } elseif { $object_type == "organization" } { + lappend element_list name legal_name reg_number notes + } + foreach element $element_list { + if { [template::element::exists $form $element] } { + set value [template::element::get_value $form $element] + switch $element { + email { + if { [db_0or1row party_is_user_p { select '1' from users where user_id = :party_id }] } { + if { [exists_and_not_null value] } { + set username $value + } else { + set username $party_id + } + acs_user::update -user_id $party_id -username $username + } + party::update -party_id $party_id -email $value -url [db_string get_url { select url from parties where party_id = :party_id } -default {}] + } + url { + party::update -party_id $party_id -email [db_string get_email { select email from parties where party_id = :party_id } -default {}] -url $value + } + default { + set $element $value + } + } } - - - set locale [lang::conn::locale -site_wide] - - set object_type [contact::get::object_type $party_id] - - set attr_value_temp "" - - db_foreach select_attributes {} { - - set attribute_value_temp [string trim [template::element::get_value entry "contact_attribute__$attribute"]] - - if { $storage_column == "address_id" } { - - # I need to verify that something has changed here - - set delivery_address [string trim [template::util::address::get_property delivery_address $attribute_value_temp]] - set municipality [string trim [template::util::address::get_property municipality $attribute_value_temp]] - set region [string trim [template::util::address::get_property region $attribute_value_temp]] - set postal_code [string trim [template::util::address::get_property postal_code $attribute_value_temp]] - set country_code [string trim [template::util::address::get_property country_code $attribute_value_temp]] - - - set old_address_id "" - db_0or1row select_old_address_id {} - if { [exists_and_not_null old_address_id] } { - # the address in the database is the same - set address_id $old_address_id - } else { - # the address in the database is different so we need to add one - if { [exists_and_not_null delivery_address] && [exists_and_not_null country_code] } { - set address_id [contacts::postal_address::new \ - -delivery_address $delivery_address \ - -municipality $municipality \ - -region $region \ - -postal_code $postal_code \ - -country_code $country_code ] - } else { - set address_id "" - } - } - - contacts::attribute::value::save \ - -attribute_id $attribute_id \ - -party_id $party_id \ - -address_id $address_id - - } - if { $storage_column == "number_id" } { - - set old_number_id "" - db_0or1row select_old_number_id {} - if { [exists_and_not_null old_number_id] } { - # the number in the database is the same - set number_id $old_number_id - } else { - # the telecom_number in the database is different so we need to add one - if { [exists_and_not_null attribute_value_temp] } { - set number_id [contacts::telecom_number::new -subscriber_number $attribute_value_temp ] - } else { - set number_id "" - } - } - - contacts::attribute::value::save \ - -attribute_id $attribute_id \ - -party_id $party_id \ - -number_id $number_id - } - if { $storage_column == "option_map_id" } { - - set attribute_value_temp [string trim [template::element::get_values entry "contact_attribute__$attribute"]] - - if { [exists_and_not_null attribute_value_temp] } { - - # first we verify that the address has changed. otherwise we pass on the old option_map_id - db_0or1row get_option_map_id {} - - if { [exists_and_not_null option_map_id] } { - # we know that a previous entry exists - - set old_option_ids "" - db_foreach get_old_options {} { - lappend old_option_ids $option_id - } - set new_option_ids $attribute_value_temp - - set same_count 0 - foreach option_id $old_option_ids { - if {![empty_string_p $option_id]} { - if { [regsub -all $option_id $new_option_ids $option_id new_option_ids] } { - incr same_count - } - } - } - if { [llength $new_option_ids] == $same_count && [llength $old_option_ids] == $same_count } { - # the lists have the same values - do nothing - } else { - # the lists are different - db_1row get_new_option_map_id {} - - foreach option_id $attribute_value_temp { - if {![empty_string_p $option_id]} { - db_dml insert_options_map {} - } - } - } - } else { - # there is no previous entry in the database - db_1row get_new_option_map_id {} - - foreach option_id $attribute_value_temp { - if {![empty_string_p $option_id]} { - db_dml insert_options_map { - insert into contact_attribute_option_map - (option_map_id,party_id,option_id) - values - (:option_map_id,:party_id,:option_id) - } - } - } - } - - set attribute_value_temp $option_map_id - } - - contacts::attribute::value::save \ - -attribute_id $attribute_id \ - -party_id $party_id \ - -option_map_id $attribute_value_temp - } - if { $storage_column == "time" } { - contacts::attribute::value::save \ - -attribute_id $attribute_id \ - -party_id $party_id \ - -time [contacts::date::sqlify -date $attribute_value_temp] - } - if { $storage_column == "value" } { - contacts::attribute::value::save \ - -attribute_id $attribute_id \ - -party_id $party_id \ - -value $attribute_value_temp - } - - - - - - set custom_fields [list organization_name legal_name reg_number organization_type first_names last_name email url] - - if { [lsearch $custom_fields $attribute] >= 0 } { - if { $attribute == "email" } { - db_dml update_parties_email {} - } - if { $attribute == "url" } { - db_dml update_parties_url {} - } - if { $object_type == "organization" } { - # [list organization_name legal_name reg_number organization_type] - if { $attribute == "organization_name" } { - db_dml update_organizations_name {} - } - if { $attribute == "legal_name" } { - db_dml update_organizations_legal_name {} - } - if { $attribute == "reg_number" } { - db_dml update_organizations_reg_number {} - } - if { $attribute == "organization_type" } { - db_dml delete_org_type_maps {} - set attribute_value_temp [string trim [template::element::get_values entry "contact_attribute__$attribute"]] - foreach option_id $attribute_value_temp { - if {![empty_string_p $option_id]} { - db_1row get_organization_type_id {} - - - db_dml insert_mapping {} - } - } - } - } - if { $object_type == "person" } { - # [list first_names last_name] - if { $attribute == "first_names" } { - db_dml update_persons_first_names {} - } - if { $attribute == "last_name" } { - db_dml update_persons_last_name {} - } - - - } - - - } - - - - - - - - - } - - return $party_id - } + if { $object_type == "person" } { + # first_names and last_name are required + if { [exists_and_not_null first_names] && [exists_and_not_null last_name] } { + person::update -person_id $party_id -first_names $first_names -last_name $last_name + } else { + if { ![exists_and_not_null first_names] } { + error "The object type was person but first_names (a required element) did not exist" + } + if { ![exists_and_not_null last_name] } { + error "The object type was person but first_names (a required element) did not exist" + } + } + } elseif { $object_type == "organization" } { + # name is required + if { [exists_and_not_null name] } { + if { ![exists_and_not_null legal_name] } { set legal_name "" } + if { ![exists_and_not_null reg_number] } { set reg_number "" } + if { ![exists_and_not_null notes] } { set notes "" } + db_dml update_org { + update organizations + set name = :name, + legal_name = :legal_name, + reg_number = :reg_number, + notes = :notes + where organization_id = :party_id + } + } else { + error "The object type was organization but name (a required element) did not exist" + } + } - } Index: openacs-4/packages/contacts/tcl/view-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/Attic/view-procs-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/view-procs-postgresql.xql 27 Feb 2005 17:07:18 -0000 1.3 +++ openacs-4/packages/contacts/tcl/view-procs-postgresql.xql 18 May 2005 16:45:49 -0000 1.4 @@ -1,87 +1,85 @@ - - - -postgresql7.2 - - - - select sort_order - from contact_views - where contact_object_type = :contact_object_type - order by sort_order desc limit 1 - - - - - - - select contact__view_create( - null, - :src, - :privilege_required, - :privilege_object_id, - :contact_object_type, - :package_id, - :sort_order, - now(), - :creation_user, - :creation_ip, - :context_id) as view_id - - - - - - - select contact__view_name_save( - :view_id, - :locale, - :name - ) - - - - - - - select '1' from contact_views limit 1 - - - - - - - select package_id from apm_packages where package_key = 'contacts' - - - - - - - select 1 from contact_views where view_id = :view_id and contact_object_type = :object_type - - - - - - - select * - from contact_views - where view_id = :view_id - - - - - - - select name from contact_view_names where view_id = :view_id and locale = :locale - - - - - - select view_id from contact_views where contact_object_type = :object_type order by sort_order limit 1 - - - - + + + + + + select sort_order + from contact_views + where contact_object_type = :contact_object_type + order by sort_order desc limit 1 + + + + + + + select contact__view_create( + null, + :src, + :privilege_required, + :privilege_object_id, + :contact_object_type, + :package_id, + :sort_order, + now(), + :creation_user, + :creation_ip, + :context_id) as view_id + + + + + + + select contact__view_name_save( + :view_id, + :locale, + :name + ) + + + + + + + select '1' from contact_views limit 1 + + + + + + + select package_id from apm_packages where package_key = 'contacts' + + + + + + + select 1 from contact_views where view_id = :view_id and contact_object_type = :object_type + + + + + + + select * + from contact_views + where view_id = :view_id + + + + + + + select name from contact_view_names where view_id = :view_id and locale = :locale + + + + + + select view_id from contact_views where contact_object_type = :object_type order by sort_order limit 1 + + + + Index: openacs-4/packages/contacts/tcl/view-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/Attic/view-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/view-procs.tcl 13 Jan 2005 13:57:05 -0000 1.2 +++ openacs-4/packages/contacts/tcl/view-procs.tcl 18 May 2005 16:45:49 -0000 1.3 @@ -1,177 +1,177 @@ -ad_library { - - Support procs for the contacts package - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} - - -namespace eval contacts::view:: { - - ad_proc -public create { - {-src} - {-privilege_required "read"} - {-privilege_object_id} - {-contact_object_type} - {-package_id ""} - {-sort_order ""} - {-creation_user ""} - {-creation_ip ""} - {-context_id ""} - } { - this code returns 1 if the view_id exists for this object_type - } { - if { ![exists_and_not_null package_id] } { set package_id [ad_conn package_id] } - if { ![exists_and_not_null sort_order] } { - db_0or1row select_last_sort_order_value {} - if { [exists_and_not_null sort_order] } { - incr sort_order - } else { - set sort_order "1" - } - } - - db_1row create_contact_view {} - return $view_id - - } - - ad_proc -public name { - {-view_id} - {-locale "en_US"} - {-name} - } { - this code returns 1 if the view_id exists for this object_type - } { - db_1row save_view_name {} - - } - - ad_proc -private init {} { - initialize views - } { - - if { [string is false [db_0or1row views_exist_p {} ]] } { - - db_1row get_package_id {} - - set view_id [contacts::view::create -src "/packages/contacts/www/view/contact-view" \ - -privilege_required "read" \ - -privilege_object_id $package_id \ - -contact_object_type "organization" \ - -package_id $package_id \ - -sort_order "1"] - contacts::view::name -view_id $view_id -name "Contact Info" - - set view_id [contacts::view::create -src "/packages/contacts/www/view/comments-view" \ - -privilege_required "read" \ - -privilege_object_id $package_id \ - -contact_object_type "organization" \ - -package_id $package_id \ - -sort_order "1"] - contacts::view::name -view_id $view_id -name "Comments" - - set view_id [contacts::view::create -src "/packages/contacts/www/view/contact-view" \ - -privilege_required "read" \ - -privilege_object_id $package_id \ - -contact_object_type "person" \ - -package_id $package_id \ - -sort_order "1"] - contacts::view::name -view_id $view_id -name "Contact Info" - - set view_id [contacts::view::create -src "/packages/contacts/www/view/comments-view" \ - -privilege_required "read" \ - -privilege_object_id $package_id \ - -contact_object_type "person" \ - -package_id $package_id \ - -sort_order "1"] - contacts::view::name -view_id $view_id -name "Comments" - - } - - } - - ad_proc -public exists_p { - {-object_type ""} - view_id - } { - this code returns 1 if the view_id exists for this object_type - } { - return [db_0or1row exists_p_select {}] - } - - ad_proc -public get { - {-locale ""} - view_id - } { - get the info on the view - } { - - db_0or1row get_view_info {} - - if { ![exists_and_not_null locale] } { - set locale [lang::conn::locale -site_wide] - } - set view_name [contacts::view::get::name -locale $locale $view_id] - - set view_info [ns_set create] - ns_set put $view_info src $src - ns_set put $view_info privilege_required $privilege_required - ns_set put $view_info privilege_object_id $privilege_object_id - ns_set put $view_info contact_object_type $contact_object_type - ns_set put $view_info sort_order $sort_order - ns_set put $view_info view_name $view_name - - # Now, set the variables in the caller's environment - ad_ns_set_to_tcl_vars -level 2 $view_info - ns_set free $view_info - - } - - - -} - - -namespace eval contacts::view::get:: { - - ad_proc -public name { - {-locale ""} - view_id - } { - get the view name - } { - - if { ![exists_and_not_null locale] } { - set locale [lang::conn::locale -site_wide] - } - - db_0or1row get_view_name {} - - if { ![exists_and_not_null name] } { - set locale "en_US" - db_0or1row get_view_name { - select name from contact_view_names where view_id = :view_id and locale = :locale - } - } - - return $name - - } - - ad_proc -public first_view_id { - object_type - } { - get the first object type view_id - } { - - return [db_string get_first_view_id {}] - - } - - -} - +ad_library { + + Support procs for the contacts package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} + + +namespace eval contacts::view:: { + + ad_proc -public create { + {-src} + {-privilege_required "read"} + {-privilege_object_id} + {-contact_object_type} + {-package_id ""} + {-sort_order ""} + {-creation_user ""} + {-creation_ip ""} + {-context_id ""} + } { + this code returns 1 if the view_id exists for this object_type + } { + if { ![exists_and_not_null package_id] } { set package_id [ad_conn package_id] } + if { ![exists_and_not_null sort_order] } { + db_0or1row select_last_sort_order_value {} + if { [exists_and_not_null sort_order] } { + incr sort_order + } else { + set sort_order "1" + } + } + + db_1row create_contact_view {} + return $view_id + + } + + ad_proc -public name { + {-view_id} + {-locale "en_US"} + {-name} + } { + this code returns 1 if the view_id exists for this object_type + } { + db_1row save_view_name {} + + } + + ad_proc -private init {} { + initialize views + } { + + if { [string is false [db_0or1row views_exist_p {} ]] } { + + db_1row get_package_id {} + + set view_id [contacts::view::create -src "/packages/contacts/www/view/contact-view" \ + -privilege_required "read" \ + -privilege_object_id $package_id \ + -contact_object_type "organization" \ + -package_id $package_id \ + -sort_order "1"] + contacts::view::name -view_id $view_id -name "Contact Info" + + set view_id [contacts::view::create -src "/packages/contacts/www/view/comments-view" \ + -privilege_required "read" \ + -privilege_object_id $package_id \ + -contact_object_type "organization" \ + -package_id $package_id \ + -sort_order "1"] + contacts::view::name -view_id $view_id -name "Comments" + + set view_id [contacts::view::create -src "/packages/contacts/www/view/contact-view" \ + -privilege_required "read" \ + -privilege_object_id $package_id \ + -contact_object_type "person" \ + -package_id $package_id \ + -sort_order "1"] + contacts::view::name -view_id $view_id -name "Contact Info" + + set view_id [contacts::view::create -src "/packages/contacts/www/view/comments-view" \ + -privilege_required "read" \ + -privilege_object_id $package_id \ + -contact_object_type "person" \ + -package_id $package_id \ + -sort_order "1"] + contacts::view::name -view_id $view_id -name "Comments" + + } + + } + + ad_proc -public exists_p { + {-object_type ""} + view_id + } { + this code returns 1 if the view_id exists for this object_type + } { + return [db_0or1row exists_p_select {}] + } + + ad_proc -public get { + {-locale ""} + view_id + } { + get the info on the view + } { + + db_0or1row get_view_info {} + + if { ![exists_and_not_null locale] } { + set locale [lang::conn::locale -site_wide] + } + set view_name [contacts::view::get::name -locale $locale $view_id] + + set view_info [ns_set create] + ns_set put $view_info src $src + ns_set put $view_info privilege_required $privilege_required + ns_set put $view_info privilege_object_id $privilege_object_id + ns_set put $view_info contact_object_type $contact_object_type + ns_set put $view_info sort_order $sort_order + ns_set put $view_info view_name $view_name + + # Now, set the variables in the caller's environment + ad_ns_set_to_tcl_vars -level 2 $view_info + ns_set free $view_info + + } + + + +} + + +namespace eval contacts::view::get:: { + + ad_proc -public name { + {-locale ""} + view_id + } { + get the view name + } { + + if { ![exists_and_not_null locale] } { + set locale [lang::conn::locale -site_wide] + } + + db_0or1row get_view_name {} + + if { ![exists_and_not_null name] } { + set locale "en_US" + db_0or1row get_view_name { + select name from contact_view_names where view_id = :view_id and locale = :locale + } + } + + return $name + + } + + ad_proc -public first_view_id { + object_type + } { + get the first object type view_id + } { + + return [db_string get_first_view_id {}] + + } + + +} + Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/comment-add.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/www/comments.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/comments.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/comments.adp 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,4 @@ + +@party_id@ + + Index: openacs-4/packages/contacts/www/comments.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/comments.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/comments.tcl 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: comments.tcl,v 1.1 2005/05/18 16:45:49 matthewg Exp $ + + +} { + {party_id:integer} + {page "comments"} +} -validate { + contact_exists -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] } { + ad_complain "The contact specified does not exist" + } + } +} + +ad_return_template Index: openacs-4/packages/contacts/www/contact-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-add.adp 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,9 @@ + +@title@ +@context@ + + + +party_ae.first_names + + Index: openacs-4/packages/contacts/www/contact-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-add.tcl 18 May 2005 16:45:49 -0000 1.1 @@ -0,0 +1,187 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact-add.tcl,v 1.1 2005/05/18 16:45:49 matthewg Exp $ + + +} { + {object_type "person"} +} -validate { + valid_type -requires {object_type} { + if { [lsearch [list organization person] $object_type] < 0 } { + ad_complain "You have not specified a valid contact type" + } + } +} + +if { $object_type == "person" } { + set title "Add a Person" +} else { + set title "Add an Organization" +} +set user_id [ad_conn user_id] +set context [list $title] + +set form "[ad_conn package_id]__[contacts::default_group]" + +set form_elements [ams::ad_form::elements -package_key "contacts" -object_type $object_type -list_name $form -key party_id] + +lappend form_elements {object_type:text(hidden)} + +ad_form -name party_ae \ + -mode "edit" \ + -cancel_label "Cancel" \ + -cancel_url [export_vars -base contact -url {party_id}] \ + -edit_buttons [list [list Save save] [list "Save and Add Another" save_add_another]] \ + -form $form_elements \ + -on_request { + + if { $object_type == "person" } { + set required_attributes [list first_names last_name email] + } else { + set required_attributes [list name] + } + + set missing_elements [list] + foreach attribute $required_attributes { + if { [string is false [template::element::exists party_ae $attribute]] } { + lappend missing_elements $attribute + } + } + # make the error message multiple item aware + if { [llength $missing_elements] > 0 } { + ad_return_error "Configuration Error" "Some of the required elements for this form are missing. Please contact an administrator and make sure that the following attributes are included in the default group's form for this object type:
  • [join $missing_elements "
  • "]
" + } + } -edit_request { + } -on_submit { + + # MGEDDERT: I NEED TO MAKE SURE THAT VALUES THAT NEED TO BE UNIQUE ARE UNIQUE + + # for orgs name needs to be unique + # for all of them email needs to be unique + + if { $object_type == "person" } { + if { ![exists_and_not_null first_names] } { + template::element::set_error party_ae first_names "First Names is required" + } + if { ![exists_and_not_null last_name] } { + template::element::set_error party_ae last_name "Last Name is required" + } + } else { + if { ![exists_and_not_null name] } { + template::element::set_error party_ae name "Name is required" + } + } + if { ![template::form::is_valid party_ae] } { + break + } + + } -new_data { + + if { $object_type == "person" } { + if { [string is false [exists_and_not_null email]] } { + set email "$party_id@bogusdomain.com" + set username $party_id + } + if { [string is false [exists_and_not_null username]] } { + set username $email + } + if { [string is false [exists_and_not_null url]] } { + set url "" + } + db_transaction { + array set creation_info [auth::create_user \ + -user_id $party_id \ + -verify_password_confirm \ + -username $email \ + -email $email \ + -first_names $first_names \ + -last_name $last_name \ + -screen_name "" \ + -password "" \ + -password_confirm "" \ + -url $url \ + -secret_question "" \ + -secret_answer ""] + + + if { "$email" == "$party_id@bogusdomain.com" } { + # we need to delete the party email address + party::update -party_id $party_id -email "" -url [db_string get_url { select url from parties where party_id = :party_id } -default {}] + } + + if { [string equal $creation_info(creation_status) "ok"] } { + group::add_member \ + -group_id [application_group::group_id_from_package_id -package_id [ad_conn subsite_id]] \ + -user_id $party_id \ + -rel_type "membership_rel" + } else { + ns_log warning "contacts/www/contact add user error: \n creation_status \n $creation_info(creation_status) \n creation_message \n $creation_info(creation_message) \n element_messages \n $creation_info(element_messages)" + error $creation_info(creation_status) + } + } on_error { + ad_return_error "Error" "The error was: $errmsg" + } + } else { + # name is not included in this list because its required and checked for above + set elements_for_insert [list legal_name notes reg_number email url] + foreach element_for_insert $elements_for_insert { + if { [string is false [exists_and_not_null $element_for_insert]] } { + set $element_for_insert "" + } + } + set peeraddr [ad_conn peeraddr] + set package_id [ad_conn package_id] + db_transaction { + set party_id [db_exec_plsql do_insert_org { + select organization__new ( + :legal_name, + :name, + :notes, + null, + null, + :reg_number, + :email, + :url, + :user_id, + :peeraddr, + :package_id + ) + }] + + + set group_id [application_group::group_id_from_package_id -package_id [ad_conn subsite_id]] + set rel_id [db_string insert_rels { select acs_rel__new (NULL::integer,'organization_rel',:group_id,:party_id,NULL,:user_id,:peeraddr) as org_rel_id }] +# db_1row insert_member { select acs_rel__new (NULL::integer,'membership_rel',:group_id,:party_id,NULL,:user_id,:peeraddr) } + db_dml insert_state { insert into membership_rels (rel_id,member_state) values (:rel_id,'approved') } + } + } + + contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" + ams::ad_form::save -package_key "contacts" \ + -object_type $object_type \ + -list_name $form \ + -form_name "party_ae" \ + -object_id [contact::revision::new -party_id $party_id] + + util_user_message -html -message "The $object_type [contact::name -party_id $party_id] was added" + + } -after_submit { + if { [exists_and_not_null formbutton\:save_add_another] } { + ad_returnredirect "contact-add?object_type=${object_type}" + } else { + ad_returnredirect "./" + } + ad_script_abort + } + + + + + + + + + +ad_return_template Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-ae-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-ae.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-ae.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-archive-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-archive.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-archive.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-current-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-current.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/contact-current.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/www/contact-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-edit.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,5 @@ + +@party_id@ + + + Index: openacs-4/packages/contacts/www/contact-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-edit.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,139 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact-edit.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + + +} { + {party_id:integer,notnull} +} -validate { + contact_exists -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] && ![ad_form_new_p -key party_id] } { + ad_complain "The contact specified does not exist" + } + } +} + + +set object_type [contact::type -party_id $party_id] +#set attach_url [attachments::add_attachment_url \ +# -object_id $party_id \ +# -return_url [contact::url -party_id $party_id] \ +# -pretty_name [contact::name -party_id $party_id]] + + + +set object_type [contact::type -party_id $party_id] +set user_id [ad_conn user_id] +set package_id [ad_conn package_id] + +# set form_elements [ams::ad_form::elements -package_key "contacts" -object_type $object_type -list_name "${object_type}_[ad_conn package_id]" -key party_id] + +set groups_belonging_to [db_list get_party_groups { select group_id from group_distinct_member_map where member_id = :party_id }] + +set form_elements {party_id:key} +lappend form_elements {object_type:text(hidden)} + + +set ams_forms [list] +foreach group [contact::groups -expand "all" -privilege_required "read"] { + set group_id [lindex $group 1] + if { [lsearch $groups_belonging_to $group_id] >= 0 } { + lappend ams_forms "${package_id}__${group_id}" + } +} + +foreach form $ams_forms { + append form_elements " " + append form_elements [ams::ad_form::elements -package_key "contacts" -object_type $object_type -list_name $form] +} +#ad_return_error "ERROR" $form_elements +ad_form -name party_ae \ + -mode "edit" \ + -form $form_elements \ + -has_edit "1" \ + -on_request { + + if { $object_type == "person" } { + set required_attributes [list first_names last_name email] + } else { + set required_attributes [list name] + } + + set missing_elements [list] + foreach attribute $required_attributes { + if { [string is false [template::element::exists party_ae $attribute]] } { + lappend missing_elements $attribute + } + } + # make the error message multiple item aware + if { [llength $missing_elements] > 0 } { + ad_return_error "Configuration Error" "Some of the required elements for this form are missing. Please contact an administrator and make sure that the following attributes are included:
  • [join $missing_elements "
  • "]
" + } + + } -edit_request { + set revision_id [contact::live_revision -party_id $party_id] + foreach form $ams_forms { + ams::ad_form::values -package_key "contacts" \ + -object_type $object_type \ + -list_name $form \ + -form_name "party_ae" \ + -object_id $revision_id + } + contact::special_attributes::ad_form_values -party_id $party_id -form "party_ae" + + } -on_submit { + + # MGEDDERT: I NEED TO MAKE SURE THAT VALUES THAT NEED TO BE UNIQUE ARE UNIQUE + + # for orgs name needs to be unique + # for all of them email needs to be unique + + if { $object_type == "person" } { + if { ![exists_and_not_null first_names] } { + template::element::set_error party_ae first_names "First Names is required" + } + if { ![exists_and_not_null last_name] } { + template::element::set_error party_ae last_name "Last Name is required" + } + } else { + if { ![exists_and_not_null name] } { + template::element::set_error party_ae name "Name is required" + } + } + if { ![template::form::is_valid party_ae] } { + break + } + + } -new_data { + } -edit_data { + + contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" + set revision_id [contact::revision::new -party_id $party_id] + foreach form $ams_forms { + ams::ad_form::save -package_key "contacts" \ + -object_type $object_type \ + -list_name $form \ + -form_name "party_ae" \ + -object_id $revision_id + } + util_user_message -html -message "The $object_type [contact::name -party_id $party_id] was updated" + + } -after_submit { + ad_returnredirect [contact::url -party_id $party_id] + ad_script_abort + } + + + + + + + + + + + + +ad_return_template Index: openacs-4/packages/contacts/www/contact-groups.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-groups.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-groups.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,4 @@ + +@party_id@ + + Index: openacs-4/packages/contacts/www/contact-groups.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-groups.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-groups.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,76 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact-groups.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,notnull} + {return_url "./"} +} + +set user_id [ad_conn user_id] +set package_id [ad_conn package_id] +set recipients [list] + +lappend recipients "[contact::name -party_id $party_id]" + +set recipients [join $recipients ", "] + + +set group_options [contact::groups -expand "all" -privilege_required "create"] + +set groups_belonging_to [db_list get_party_groups { select group_id from group_distinct_member_map where member_id = :party_id }] + +set groups_to_add [list [list "-- select a group --" ""]] +foreach group $group_options { + if { [lsearch "$groups_belonging_to" [lindex $group 1]] >= 0 } { + # the party is part of this group + lappend groups_in [list [lindex $group 0] [lindex $group 1] [lindex $group 2]] + } else { + lappend groups_to_add [list [lindex $group 0] [lindex $group 1]] + } +} + +if { [llength $group_options] == "0" } { + ad_return_error "Insufficient Permissions" "You do not have permission to add users to groups" +} + +set form_elements { +} +set edit_buttons [list [list "Add to Selected Group" create]] + + + + +ad_form -action group-parties-add \ + -name add_to_group \ + -edit_buttons $edit_buttons \ + -form { + party_id:integer(hidden) + return_url:text(hidden) + {group_ids:text(select) {label ""} {options $groups_to_add}} + } -on_request { + } -on_submit { + db_transaction { + foreach group_id $group_ids { + foreach party_id $party_ids { + # relation_add verifies that they aren't already in the group + switch [contact::type -party_id $party_id] { + person { + set rel_type "membership_rel" + } + organization { + set rel_type "organization_rel" + } + } + relation_add -member_state "approved" $rel_type $group_id $party_id + } + } + } + } -after_submit { + ad_returnredirect $return_url + ad_script_abort + } + + Index: openacs-4/packages/contacts/www/contact-rels.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-rels.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-rels.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,14 @@ + +@party_id@ +search.searchterm + + +

+ +

+ + + + + + Index: openacs-4/packages/contacts/www/contact-rels.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-rels.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-rels.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,232 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact-rels.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,notnull} + {party_two:optional} + {role_two ""} + {buttonsearch:optional} + {buttonme:optional} + {query ""} +} -validate { + contact_one_exists -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] } { + ad_complain "The first contact specified does not exist" + } + } + contact_two_exists -requires {party_two} { + if { ![contact::exists_p -party_id $party_two] } { + ad_complain "The second contact specified does not exist" + } + } + +} + +set contact_type [contact::type -party_id $party_id] +set contact_name [contact::name -party_id $party_id] +set contact_url [contact::url -party_id $party_id] + + + + + + +set pretty_plural_list_name "contacts" +# create rel_type if the role requires a certain object_type +if { [exists_and_not_null role_two] } { + set valid_object_types [db_list valid_object_types { select primary_object_type from contact_rel_types where primary_role = :role_two }] + set person_valid_p 0 + set org_valid_p 0 + foreach type $valid_object_types { + switch $type { + party { + set person_valid_p 1 + set org_valid_p 1 + } + person { + set person_valid_p 1 + } + organization { + set org_valid_p 1 + } + } + } + if { $org_valid_p && $person_valid_p } { + # we do nothing + } else { + if { $org_valid_p } { + set rel_type "organization_rel" + set pretty_plural_list_name "organizations" + } elseif { $person_valid_p } { + set rel_type "membership_rel" + set pretty_plural_list_name "people" + } else { + error "neither person nor org type is valid, what happened admin?" + } + } +} + + + + + + + + + + + +if { [exists_and_not_null orderby] } { + if { $orderby == "first_names,asc" } { + set name_order 0 + } else { + set name_order 1 + } +} else { + set name_order 0 +} + +set member_state "approved" +set format "normal" + +set admin_p [ad_permission_p [ad_conn package_id] admin] +#set default_group_id [contacts::default_group_id] +set title "Contacts" +set context {} + + + +set search_clause [list] +lappend search_clause "and party_id in ( select member_id from group_distinct_member_map where group_id = '-2' )" +if { [exists_and_not_null rel_type] } { + set rel_valid_p 0 + set group_id "-2" + db_foreach dbqd.contacts.www.index.get_rels {} { + if { $rel_type == $relation_type } { + set rel_valid_p 1 + } + } + if { $rel_valid_p } { + lappend search_clause "and party_id in ( select member_id from group_member_map where rel_type = '$rel_type' )" + } else { + set rel_type "" + } +} + +if { [exists_and_not_null query] } { + set search [string trim $query] + foreach term $query { + if { [string is integer $query] } { + lappend search_clause "and party_id = $term" + } else { + lappend search_clause "and upper(contact__name(party_id)) like upper('%${term}%')" + } + } +} + +set search_clause [join $search_clause "\n"] +#ad_return_error "Error" $search_clause + + +set primary_party $party_id + +template::list::create \ + -html {width 100%} \ + -name "contacts" \ + -multirow "contacts" \ + -row_pretty_plural "$pretty_plural_list_name found in search, please try again or add a new contact" \ + -checkbox_name checkbox \ + -selected_format ${format} \ + -key party_id \ + -elements { + type { + label {} + display_template { + + } + } + contact { + label {} + display_template { + @contacts.party_id@">@contacts.name@ \[Select\] + @contacts.email@ + } + } + contact_id { + display_col party_id + } + first_names { + display_col first_names + } + last_name { + display_col last_name + } + organization { + display_col organization + } + email { + display_col email + } + } -filters { + } -orderby { + first_names { + label "First Name" + orderby_asc "lower(contact__name(party_id,'f')) asc" + orderby_desc "lower(contact__name(party_id,'f')) asc" + } + last_name { + label "Last Name" + orderby_asc "lower(contact__name(party_id,'t')) asc" + orderby_desc "lower(contact__name(party_id,'t')) asc" + } + default_value first_names,asc + } -formats { + normal { + label "Table" + layout table + row { + contact {} + } + } + } + +#ns_log notice [db_map contacts_select] +set original_party_id $party_id + +#ad_return_error "ERROR" [db_map dbqd.contacts.www.index.contacts_select] +db_multirow -extend {map_url} -unclobber contacts dbqd.contacts.www.index.contacts_select {} { + set map_url [export_vars -base "relationship-add" -url {{party_one $original_party_id} {party_two $party_id} {role_two $role_two}}] +} + + + + + +set rel_options [db_list_of_lists get_rels { + select acs_rel_type__role_pretty_name(primary_role), + primary_role + from contact_rel_types + where secondary_object_type in ( :contact_type, 'party' ) + order by upper(acs_rel_type__role_pretty_name(primary_role)) +}] + +set rel_options "{{-Select One-} {}} $rel_options" + + + + + + +ad_form -name "search" -method "GET" -export {party_id} -form { + {role_two:text(select) {label "Add: "} {options $rel_options}} + {query:text(text) {label ""} {html {size 24}}} + {search:text(submit) {label "Search"}} +} -on_request { +} -edit_request { +} -on_refresh { +} -on_submit { +} -after_submit { +} Index: openacs-4/packages/contacts/www/contact.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,29 @@ + +@party_id@ + + + + + + +
+ + + + + + + + + + + + + +
+

Last updated: @update_date@

+ + + +@admin_url;noquote@ + Index: openacs-4/packages/contacts/www/contact.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,142 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: contact.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + + +} { + {party_id:integer,notnull} +} -validate { + contact_exists -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] && ![ad_form_new_p -key party_id] } { + ad_complain "The contact specified does not exist" + } + } +} + +#set attach_url [attachments::add_attachment_url \ +# -object_id $party_id \ +# -return_url [contact::url -party_id $party_id] \ +# -pretty_name [contact::name -party_id $party_id]] + +set admin_url [acs_community_member_admin_link -user_id $party_id -label "Admin Page"] +set object_type [contact::type -party_id $party_id] +set user_id [ad_conn user_id] +set package_id [ad_conn package_id] + +# set form_elements [ams::ad_form::elements -package_key "contacts" -object_type $object_type -list_name "${object_type}_[ad_conn package_id]" -key party_id] + +set groups_belonging_to [db_list get_party_groups { select group_id from group_distinct_member_map where member_id = :party_id }] +if { [lsearch $groups_belonging_to -2] < 0 } { + ad_return_error "This users has not been approved" "This user is awaiting administrator approval" +} +set form_elements {party_id:key} +lappend form_elements {object_type:text(hidden)} + + +set ams_forms [list] +foreach group [contact::groups -expand "all" -privilege_required "read"] { + set group_id [lindex $group 1] + if { [lsearch $groups_belonging_to $group_id] >= 0 } { + lappend ams_forms "${package_id}__${group_id}" + } +} + +foreach form $ams_forms { + append form_elements " " + append form_elements [ams::ad_form::elements -package_key "contacts" -object_type $object_type -list_name $form] +} +#ad_return_error "ERROR" $form_elements +ad_form -name party_ae \ + -mode "display" \ + -form $form_elements \ + -has_edit "1" \ + -on_request { + + if { $object_type == "person" } { + set required_attributes [list first_names last_name email] + } else { + set required_attributes [list name] + } + + set missing_elements [list] + foreach attribute $required_attributes { + if { [string is false [template::element::exists party_ae $attribute]] } { + lappend missing_elements $attribute + } + } + # make the error message multiple item aware + if { [llength $missing_elements] > 0 } { + ad_return_error "Configuration Error" "Some of the required elements for this form are missing. Please contact an administrator and make sure that the following attributes are included:
  • [join $missing_elements "
  • "]
" + } + + } -edit_request { + set revision_id [contact::live_revision -party_id $party_id] + foreach form $ams_forms { + ams::ad_form::values -package_key "contacts" \ + -object_type $object_type \ + -list_name $form \ + -form_name "party_ae" \ + -object_id $revision_id + } + contact::special_attributes::ad_form_values -party_id $party_id -form "party_ae" + + } -on_submit { + } -new_data { + } -edit_data { + } -after_submit { + ad_returnredirect "./" + } + + +if { $object_type == "person" } { + template::element::set_properties party_ae first_names widget hidden + template::element::set_properties party_ae last_name widget hidden +} else { + template::element::set_properties party_ae name widget hidden +} +foreach element [template::form::get_elements party_ae] { + # ns_log notice $element [template::element::get_value party_ae $element] + if { [template::element::get_value party_ae $element] == "" } { + template::element::set_properties party_ae $element widget hidden + } +} +# now we clean up the section headings (if necessary) +foreach element [template::form::get_elements party_ae] { + set section [template::element::get_property party_ae $element section] + set value [template::element::get_value party_ae $element] + if { ( $value == "" || $element == "first_names" || $element == "last_name" ) && $section != "" } { + # there is a section heading for a "non-existant" element + set carry_over_section $section + template::element::set_properties party_ae $element section "" + } else { + if { [exists_and_not_null carry_over_section] && $value != "" && [template::element::get_property party_ae $element widget] != "hidden" } { + if { ![exists_and_not_null section] } { set section $carry_over_section } + template::element::set_properties party_ae $element section $section + set carry_over_section "" + set section "" + } + } + set sec [template::element::get_property party_ae $element section] + ns_log notice "mgeddert: $element section $sec" +} + + + + + + +set live_revision [contact::live_revision -party_id $party_id] +if { [exists_and_not_null live_revision] } { + set update_date [db_string get_update_date { select to_char(publish_date,'Mon FMDD, YYYY at FMHH12:MIam') from cr_revisions where revision_id = :live_revision } -default {}] +} + + + + + + + + +ad_return_template Index: openacs-4/packages/contacts/www/group-parties-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-parties-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-parties-add.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,10 @@ + + +@title@ +@context@ + + + + + + Index: openacs-4/packages/contacts/www/group-parties-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-parties-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-parties-add.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,85 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-parties-add.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,multiple,optional} + {party_ids:optional} + {return_url "./"} +} -validate { + valid_party_submission { + if { ![exists_and_not_null party_id] && ![exists_and_not_null party_ids] } { + ad_complain "Your need to provide some contacts to send a message" + } + } +} +if { [exists_and_not_null party_id] } { + set party_ids [list] + foreach party_id $party_id { + lappend party_ids $party_id + } +} + + + +set title "Add to Group" +set user_id [ad_conn user_id] +set context [list $title] +set package_id [ad_conn package_id] +set recipients [list] +foreach party_id $party_ids { + lappend recipients "[contact::name -party_id $party_id]" +} +set recipients [join $recipients ", "] + +set form_elements { + party_ids:text(hidden) + return_url:text(hidden) + {recipients:text(inform),optional {label "Contacts"}} +} + +set group_options [contact::groups -expand "all" -privilege_required "create"] +if { [llength $group_options] == "0" } { + ad_return_error "Insufficient Permissions" "You do not have permission to add users to groups" +} + +append form_elements { + {group_ids:text(checkbox),multiple {label "Add to Group(s)"} {options $group_options}} +} +set edit_buttons [list [list "Add to Selected Group(s)" create]] + + + + +ad_form -action group-parties-add \ + -name add_to_group \ + -cancel_label "Cancel" \ + -cancel_url $return_url \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -on_submit { + db_transaction { + foreach group_id $group_ids { + foreach party_id $party_ids { + # relation_add verifies that they aren't already in the group + switch [contact::type -party_id $party_id] { + person { + set rel_type "membership_rel" + } + organization { + set rel_type "organization_rel" + } + } + relation_add -member_state "approved" $rel_type $group_id $party_id + } + } + } + } -after_submit { + ad_returnredirect $return_url + ad_script_abort + } + + Index: openacs-4/packages/contacts/www/group-parties-remove.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-parties-remove.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-parties-remove.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,10 @@ + + +@title@ +@context@ + + + + + + Index: openacs-4/packages/contacts/www/group-parties-remove.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-parties-remove.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-parties-remove.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,77 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-parties-remove.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,multiple,optional} + {party_ids:optional} + {return_url "./"} + {group_id:optional} +} -validate { + valid_party_submission { + if { ![exists_and_not_null party_id] && ![exists_and_not_null party_ids] } { + ad_complain "Your need to provide some contacts to send a message" + } + } +} +if { [exists_and_not_null party_id] } { + set party_ids [list] + foreach party_id $party_id { + lappend party_ids $party_id + } +} + + + +set title "Remove From to Group" +set user_id [ad_conn user_id] +set context [list $title] +set package_id [ad_conn package_id] +set recipients [list] +foreach party_id $party_ids { + lappend recipients "[contact::name -party_id $party_id]" +} +set recipients [join $recipients ", "] + +set form_elements { + party_ids:text(hidden) + return_url:text(hidden) + {recipients:text(inform),optional {label "Contacts"}} +} + +set group_options [contact::groups -expand "all" -privilege_required "create"] +if { [llength $group_options] == "0" } { + ad_return_error "Insufficient Permissions" "You do not have permission to add users to groups" +} + +append form_elements { + {group_ids:text(checkbox),multiple {label "Add to Group(s)"} {options $group_options}} +} +set edit_buttons [list [list "Remove from Selected Group(s)" create]] + + + + +ad_form -action group-parties-remove \ + -name remove_from_group \ + -cancel_label "Cancel" \ + -cancel_url $return_url \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -on_submit { + db_transaction { + foreach group_id $group_ids { + foreach party_id $party_ids { + # relation_add verifies that they aren't already in the group + group::remove_member -group_id $group_id -user_id $party_id + } + } + } + } -after_submit { + ad_returnredirect $return_url + } + + Index: openacs-4/packages/contacts/www/group-party-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-party-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-party-add.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,24 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-party-add.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:multiple,integer,notnull} + {group_id:integer,notnull} +} + +set party_id [lindex $party_id 0] +switch [contact::type -party_id $party_id] { + person { + set rel_type "membership_rel" + } + organization { + set rel_type "organization_rel" + } +} +relation_add -member_state "approved" $rel_type $group_id $party_id + +ad_returnredirect [contact::url -party_id $party_id] + Index: openacs-4/packages/contacts/www/group-party.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/group-party.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/group-party.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,80 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-party.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,multiple} + {group_id:integer,multiple} + {return_url "./"} +} -validate { +} +if { [exists_and_not_null party_id] } { + set party_ids [list] + foreach party_id $party_id { + lappend party_ids $party_id + } +} + + + +set title "Add to Group" +set user_id [ad_conn user_id] +set context [list $title] +set package_id [ad_conn package_id] +set recipients [list] +foreach party_id $party_ids { + lappend recipients "[contact::name -party_id $party_id]" +} +set recipients [join $recipients ", "] + +set form_elements { + party_ids:text(hidden) + return_url:text(hidden) + {recipients:text(inform),optional {label "Contacts"}} +} + +set group_options [contact::groups -expand "all" -privilege_required "create"] +if { [llength $group_options] == "0" } { + ad_return_error "Insufficient Permissions" "You do not have permission to add users to groups" +} + +append form_elements { + {group_ids:text(checkbox),multiple {label "Add to Group(s)"} {options $group_options}} +} +set edit_buttons [list [list "Add to Selected Groups" create]] + + + + +ad_form -action group-parties-add \ + -name add_to_group \ + -cancel_label "Cancel" \ + -cancel_url $return_url \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -on_submit { + db_transaction { + foreach group_id $group_ids { + foreach party_id $party_ids { + # relation_add verifies that they aren't already in the group + switch [contact::type -party_id $party_id] { + person { + set rel_type "membership_rel" + } + organization { + set rel_type "organization_rel" + } + } + relation_add -member_state "approved" $rel_type $group_id $party_id + } + } + } + } -after_submit { + ad_returnredirect $return_url + ad_script_abort + } + + Index: openacs-4/packages/contacts/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/www/index.adp 13 Jan 2005 13:57:07 -0000 1.2 +++ openacs-4/packages/contacts/www/index.adp 18 May 2005 16:45:50 -0000 1.3 @@ -5,83 +5,20 @@ - - - -
-[ Admin ] +search.query + - +

- - - - - - - - - - -
- - - -

- - - - - - - -
- #contacts.Search# (clear) - -
-
- - @export_vars_search_form;noquote@ - -
-
-

- - - -

- - - - - - - -
- #contacts.Limit_Contacts_to# (clear) -
- @category_select;noquote@ -
-

-
+ - - -
-
-

@letter_bar;noquote@

- -

#contacts.Showing# @first_row@ - @last_row@ #contacts.of# @total_rows@ -| Prev -| Next -

-
-
- - -
- - - Index: openacs-4/packages/contacts/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/www/index.tcl 13 Jan 2005 13:57:08 -0000 1.2 +++ openacs-4/packages/contacts/www/index.tcl 18 May 2005 16:45:50 -0000 1.3 @@ -1,357 +1,323 @@ ad_page_contract { + List and manage contacts. - @author Matthew Geddert openacs@geddert.com @creation-date 2004-07-28 @cvs-id $Id$ - } { - {searchterm ""} - {letter ""} - {num_rows "20"} - {start_row:naturalnum "0"} - {category_id:multiple,optional} - {groupby:optional} - {orderby:optional} - {sortby "first_names"} + {rel_type:optional} + {orderby "first_names,asc"} {format "normal"} - {status "current"} - {object_type ""} + {query_id:integer ""} + {query ""} + {page:optional} + {page_size:integer "25"} + {tasks_interval:integer "7"} } -set admin_p [ad_permission_p [ad_conn package_id] admin] set title "Contacts" set context {} -set valid_numrows [list 10 20 50 100 ALL] -if { [lsearch $valid_numrows $num_rows] < 0 } { - set num_rows 50 +if { [exists_and_not_null query_id] } { + if { [contact::search::exists_p -search_id $query_id] } { + set search_id $query_id + set query_type "search" + } else { + set group_id $query_id + set query_type "group" + } +} else { +# set group_id [application_group::group_id_from_package_id -package_id [ad_conn subsite_id]] + set group_id [contacts::default_group] + set query_id $group_id + set query_type "group" + if { ![exists_and_not_null group_id] } { + ad_return_error "Not Configured" "Your administrator must map and add a default group in the admin pages" + } } +if { $orderby == "first_names,asc" } { + set name_order 0 + set name_label "Sort by: First Names | Last Name" +} else { + set name_order 1 + set name_label "Sort by: First Names | Last Name" +} +append name_label "    Show: " +set first_p 1 +foreach page_s [list 25 50 100 500] { + if { [string is false $first_p] } { + append name_label " | " + } + if { $page_size == $page_s } { + append name_label $page_s + } else { + append name_label "$page_s" + } + set first_p 0 +} +append name_label "   Get: CSV" -if { $num_rows == "ALL" } { - set start_row 0 +set tasks_url [export_vars -base "/tasks/query" -url {query_id query rel_type}] + + + +# SEARCH CLAUSE + +set search_clause [list] + +if { $query_type == "group" } { + if { $group_id != "-2" } { + lappend search_clause "and party_id in ( select member_id from group_distinct_member_map where group_id = '$group_id' )" + } + if { [exists_and_not_null rel_type] } { + set rel_valid_p 0 + db_foreach get_rels {} { + if { $rel_type == $relation_type } { + set rel_valid_p 1 + } + } + if { $rel_valid_p } { + lappend search_clause "and party_id in ( select member_id from group_member_map where rel_type = '$rel_type' )" + } else { + set rel_type "" + } + } +} elseif { $query_type == "search" } { + lappend search_clause [contact::search::where_clauses -and -search_id $search_id -party_id "parties.party_id" -revision_id "revision_id"] } +if { [exists_and_not_null query] } { + set search [string trim $query] + foreach term $query { + if { [string is integer $query] } { + lappend search_clause "and party_id = $term" + } else { + lappend search_clause "and upper(contact__name(party_id)) like upper('%${term}%')" + } + } +} +set search_clause [join $search_clause "\n"] -set export_vars_page_nav [export_vars -url { category_id format letter num_rows object_type orderby searchterm sortby status }] -set export_vars_search_form [export_vars -form { category_id format num_rows object_type orderby sortby status }] -set export_vars_search_url [export_vars -url { category_id format num_rows object_type orderby sortby status }] -set export_vars_letter_url [export_vars -url { category_id format num_rows object_type orderby sortby status }] -set export_vars_sortby_url [export_vars -url { category_id format letter num_rows object_type orderby searchterm status }] -set export_vars_num_rows_url [export_vars -url { category_id format letter object_type orderby searchterm sortby status }] -set export_vars_category_form [export_vars -form { format letter num_rows object_type orderby searchterm sortby status }] -set export_vars_category_url [export_vars -url { format letter num_rows object_type orderby searchterm sortby status }] -if {[exists_and_not_null category_id]} { - set category_id_filter "party_id in ( select object_id from category_object_map where category_id = $category_id )" - set temp_category_id $category_id -} else { - set category_id_filter "" - set temp_category_id "" -} -set categories_p [contacts::categories::enabled_p] -if { [string is true $categories_p] } { -set category_select [contacts::categories::get_selects -export_vars $export_vars_category_form -category_id $temp_category_id] -} -set searchterm_filter "upper(sort_$sortby) like upper('%$searchterm%')" -set letter_filter "upper(sort_$sortby) like upper('$letter%')" -if { [lsearch [list organization person] $object_type] < 0 } { - set object_type_filter "" -} else { - set object_type_filter "object_type = '$object_type'" -} -if { [lsearch [list current archived] $status] < 0 } { - set status_filter "" -} else { - set status_filter "status = '$status'" -} +# LIST CODE -if { $status == "archived" } { +#set actions [list \ +# "Add Person" "contact-add?object_type=person" "Add a Person" \ +# "Add Organization" "contact-add?object_type=organization" "Add an Organization" \ +# "Advanced Search" "search" "Advanced Search" \ +# "Settings" "settings" "Modify Settings" \ +# "Admin" "admin" "Administration"] +set actions "" set bulk_actions [list \ - "\#contacts.Make_Current\#" "contact-current" "\#contacts.Make_the_checked_contacts_current\#"] -} else { -set bulk_actions [list \ - "\#contacts.Archive\#" "contact-archive" "\#contacts.Archive_the_checked_contacts\#"] -} -# "\#contacts.Add_to_Category\#" "contacts-category-add" "\#contacts.Add_the_selected_contacts_to_a_category\#" -# "\#contacts.Send_Email\#" "bulk-email" "\#contacts.Send_an_email_message_to_the_selected_contacts\#" \ + "Add to Group" "group-parties-add" "Add to group" \ + "Remove From Group" "group-parties-remove" "Remove from this Group" \ + "Delete" "delete" "Delete the selected Contacts" \ + "Mail Merge" "message" "E-mail or Mail the selected contacts" \ + ] - -list::create \ - -html { width 100% } \ - -name entries \ - -multirow entries \ - -key party_id \ - -row_pretty_plural "Contacts" \ +template::list::create \ + -html {width 100%} \ + -name "contacts" \ + -multirow "contacts" \ + -row_pretty_plural "contacts" \ -checkbox_name checkbox \ - -selected_format $format \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - variable - } -actions { - "\#contacts.Add_a_Person\#" "contact-ae?object_type=person" "\#contacts.Add_a_Person\#" - "\#contacts.Add_an_Organization\#" "contact-ae?object_type=organization" "\#contacts.Add_an_Organization\#" - } -bulk_actions $bulk_actions \ + -selected_format ${format} \ + -key party_id \ + -page_size $page_size \ + -page_flush_p t \ + -page_query_name contacts_pagination \ + -actions $actions \ + -bulk_actions $bulk_actions \ + -bulk_action_method post \ + -bulk_action_export_vars { group_id } \ -elements { - edit { - label {} + rownum { + label {} + display_col rownum + } + type { + label {} + display_template { + + } + } + contact { + label "$name_label" display_template { - Edit - } - + @contacts.party_id@">@contacts.name@ \[Edit\] + @contacts.email@ + } } - contact_name { - display_col contact_name - link_url_eval $contact_url - label "\#contacts.Contact\#" - } + contact_id { + display_col party_id + } first_names { - display_col first_names - label "First Names" - } + display_col first_names + } last_name { - display_col last_name - label "Last Name" - } - organization_name { - display_col name - label "Organization" - } + display_col last_name + } + organization { + display_col organization + } email { - display_template { - @entries.email_url;noquote@ - } - label "\#contacts.Email_Address\#" - } - contact_type { - display_template { - \#contacts.Organization\# - \#contacts.Person\# - } - label "\#contacts.Contact_Type\#" - } + display_col email + } } -filters { - sortby { - label "\#contacts.Sort_By\#" - values { - {{\#contacts.First_Names\#} first_names} - {{\#contacts.Last_Name\#} last_name} - } - where_clause {} - } - start_row {} - category_id { - label Categories - where_clause {$category_id_filter} - } - letter { - label "Letter" - where_clause {$letter_filter} - } - object_type { - label "\#contacts.Contact_Type\#" - values { - {{\#contacts.Organization\#} organization} - {{\#contacts.Person\#} person} - } - where_clause {$object_type_filter} - } - searchterm { - label "Search" - where_clause {$searchterm_filter} - } - status { - label "\#contacts.Status\#" - values { - {{\#contacts.Current\#} current} - {{\#contacts.Archived\#} archived} - } - where_clause {$status_filter} - } - num_rows { - label "\#contacts.Number_of_Rows\#" - values { - {10 10} - {20 20} - {50 50} - {100 100} - {500 500} - {All ALL} - } - } - } -groupby { } -orderby { - default_value contact_name,asc - contact_name { - label "\#contacts.Contact\#" - orderby_desc "contacts.sort_$sortby desc, contacts.object_type desc, contacts.email desc" - orderby_asc "contacts.sort_$sortby asc, contacts.object_type desc, contacts.email desc" - default_direction asc + first_names { + label "First Name" + orderby_asc "lower(contact__name(party_id,'f')) asc" + orderby_desc "lower(contact__name(party_id,'f')) asc" } - email { - label "\#contacts.Email_Address\#" - orderby_desc "contacts.email desc, contacts.sort_$sortby desc, contacts.object_type desc" - orderby_asc "contacts.email asc, contacts.sort_$sortby desc, contacts.object_type desc" - default_direction asc + last_name { + label "Last Name" + orderby_asc "lower(contact__name(party_id,'t')) asc" + orderby_desc "lower(contact__name(party_id,'t')) asc" } - contact_type { - label "\#contacts.Contact_Type\#" - orderby_desc "contacts.object_type desc, contacts.sort_$sortby desc, contacts.email desc" - orderby_asc "contacts.object_type asc, contacts.sort_$sortby desc, contacts.email desc" - default_direction asc - } + default_value first_names,asc } -formats { - normal { - label "Table" - layout table + normal { + label "Table" + layout table + row { + checkbox {} + contact {} + } + } + tasks { + label "Table" + layout table + row { + checkbox {} + contact {} + } + } + csv { + label "CSV" + output csv + page_size 0 row { - checkbox {} - edit {} - contact_name {} - email {} - contact_type {} - } - } - csv { - label "CSV" - output csv - row { - contact_name {} + contact_id {} first_names {} last_name {} - organization_name {} + organization {} email {} - contact_type {} - } - } + } + } } -# This query will override the ad_page_contract value entry_id +db_multirow -unclobber contacts contacts_select {} -# left join category_object_map c on (contact_attrs.party_id = c.object_id) -set multirow_query " -" -# [template::list::sortby_clause -sortby -name entries] +# TOTAL COUNT CODE +set contacts_total_count [db_string contacts_total_count {}] -db_multirow -extend { contact_url email_url object_type_pretty } -unclobber entries get_contact_info {} { - set contact_url "view/$party_id" - if { [exists_and_not_null email] } { - set email_url "$email" - } - if { $object_type == "organization" } { - set object_type_pretty "\#contacts.Organization\#" +if { [exists_and_not_null query] && [template::multirow size contacts] == 1 } { + if { $query_type == "group" } { + set query_name [db_string get_it { select group_name from groups where group_id = :group_id }] } else { - set object_type_pretty "\#contacts.Person\#" + set query_name [db_string get_it { select title from contact_searches where search_id = :search_id }] } + + ad_returnredirect -message "in '$query_name' only this contact matched your query of '$query'" [contact::url -party_id [template::multirow get contacts 1 party_id]] + ad_script_abort } -set initial_list_query " -select distinct upper(substr(sort_$sortby,1,1)) - from contacts - where party_id is not null -" -if { [exists_and_not_null category_id_filter ] } { - append initial_list_query "and $category_id_filter\n" -} -# we cannot use the letter filter because it defeats the purpose -#if { [exists_and_not_null letter_filter ] } { -# append initial_list_query "and $category_id_filter" -# -#} -if { [exists_and_not_null object_type_filter ] } { - append initial_list_query "and $object_type_filter\n" -} -if { [exists_and_not_null searchterm_filter ] } { - append initial_list_query "and $searchterm_filter\n" -} -if { [exists_and_not_null status_filter ] } { - append initial_list_query "and $status_filter\n" -} -set initial_list [db_list_of_lists get_list_of_starting_letters $initial_list_query] +if { $query_type == "group" } { + # roles + set rel_options [list] + lappend rel_options [list "All" "" ""] + db_foreach get_rels {} { + if { $relation_type == "membership_rel" } { + set pretty_plural "People" + } + lappend rel_options [list \ + [lang::util::localize $pretty_plural] \ + ${relation_type} \ + ${member_count}] + } +} -set letter_bar [contacts::util::letter_bar -letter $letter -export_vars $export_vars_letter_url -initial_list $initial_list] +set owner_id [ad_conn user_id] +set group_options [list [list "-- Groups --------------------------" ""]] +append group_options " [contact::groups -expand "all"]" +lappend group_options [list "" ""] +lappend group_options [list "-- My Searches ---------------------" ""] +append group_options " [db_list_of_lists get_my_searches {}]" -# pagination - hopefully once list builder has pagination documenation -# this can be built into list builder -db_1row get_total_rows " -select count(*) as total_rows - from contacts - where party_id is not null - [template::list::filter_where_clauses -and -name entries] -" -if { $num_rows != "ALL" } { +append form_elements { + {query_id:integer(select),optional {label ""} {options $group_options} {html {onClick "javascript:acs_FormRefresh('search')"}}} +} - set first_row [expr $start_row + 1] - set last_row [expr $start_row + $num_rows] - if { $num_rows >= $total_rows } { - set first_row 1 - set last_row $total_rows - set start_row 0 +if { [exists_and_not_null rel_options] && $query_type == "group" } { + append form_elements { + {rel_type:text(select),optional {label ""} {options $rel_options} {html {onClick "javascript:acs_FormRefresh('search')"}}} } +} +append form_elements { + {query:text(text),optional {label ""} {html {size 20 maxlength 255}}} + {save:text(submit) {label {Go}} {value "go"}} +} +# {format:text(select),optional {label "   Output"} {options {{Default normal} {CSV csv}}} {html {onClick "javascript:acs_FormRefresh('search')"}}} - if { $last_row >= $total_rows } { - set next_link_p 0 - set last_row $total_rows - } else { - set next_link_p 1 - set next_link_url "?start_row=$last_row&$export_vars_page_nav" +switch $format { + normal { + append form_elements { + {tasks_interval:integer(hidden),optional} + } + if { $contacts_total_count > 0 } { + append form_elements { + {result_count:integer(inform),optional {label "  Results:"} {value "$contacts_total_count"}} + } + } + } - if { $start_row == "0" } { - set prev_link_p 0 - } else { - set prev_link_p 1 - set prev_link_start_row [expr $start_row - $num_rows] - if { $prev_link_start_row < "0" } { - set prev_link_start_row "0" - } - set prev_link_url "?start_row=$prev_link_start_row&$export_vars_page_nav" + tasks { + append form_elements { + {tasks_interval:integer(text),optional {label "  View next"} {after_html "days"} {html {size 2 maxlength 3 onChange "javascript:acs_FormRefresh('search')"}}} + } } - -} else { - set next_link_p 0 - set prev_link_p 0 - set first_row 1 - set last_row $total_rows + csv { + # This spits out the CSV if we happen to be in CSV layout + list::write_output -name contacts + ad_script_abort + } + default { + } } -template::list::write_output -name entries - - - - - - - -ad_return_template - - +ad_form -name "search" -method "GET" -export {orderby page_size page format} -form $form_elements \ + -on_request { + } -edit_request { + } -on_refresh { + } -on_submit { + } -after_submit { + } Index: openacs-4/packages/contacts/www/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/www/index.xql 13 Jan 2005 13:57:09 -0000 1.2 +++ openacs-4/packages/contacts/www/index.xql 18 May 2005 16:45:50 -0000 1.3 @@ -1,18 +1,94 @@ - - -select contacts.*, sort_$sortby as contact_name - from contacts - where party_id is not null - [template::list::filter_where_clauses -and -name entries] - [template::list::orderby_clause -orderby -name entries] - limit $num_rows offset $start_row - - + + +select parties.party_id + from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ) , group_distinct_member_map + where parties.party_id = group_distinct_member_map.member_id + and group_distinct_member_map.group_id = '-2' +$search_clause +[template::list::orderby_clause -orderby -name "contacts"] + + + + +select count(*) + from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ) , group_distinct_member_map + where parties.party_id = group_distinct_member_map.member_id + and group_distinct_member_map.group_id = '-2' +$search_clause + + - + + + select admin_role.pretty_name as admin_role_pretty, + member_role.pretty_name as member_role_pretty + from acs_rel_roles admin_role, acs_rel_roles member_role + where admin_role.role = 'admin' + and member_role.role = 'member' + + + + + + select title, search_id + from contact_searches + where owner_id = :owner_id + and title is not null + order by lower(title) + + + + + + + select arr.pretty_plural, + art.rel_type as relation_type, + ( select count(distinct gmm.member_id) from group_approved_member_map gmm where gmm.group_id = :group_id and gmm.rel_type = art.rel_type ) as member_count + from acs_rel_types art, + acs_rel_roles arr + where art.rel_type in ( select distinct gmm.rel_type from group_approved_member_map gmm where gmm.group_id = :group_id ) + and art.role_two = arr.role + + + + + + +select contact__name(parties.party_id), + parties.party_id, + cr_revisions.revision_id, + contact__name(parties.party_id,:name_order) as name, + parties.email, + ( select first_names from persons where person_id = party_id ) as first_names, + ( select last_name from persons where person_id = party_id ) as last_name, + ( select name from organizations where organization_id = party_id ) as organization + from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ) , group_distinct_member_map + where parties.party_id = group_distinct_member_map.member_id + and group_distinct_member_map.group_id = '-2' +$search_clause +[template::list::page_where_clause -and -name "contacts" -key "party_id"] +[template::list::orderby_clause -orderby -name "contacts"] + + + + + + + select mr.member_state as state, + count(mr.rel_id) as num_contacts + from membership_rels mr, acs_rels r + where r.rel_id = mr.rel_id + and r.object_id_one = :group_id + and r.rel_type = 'membership_rel' + group by mr.member_state + + + + + Index: openacs-4/packages/contacts/www/map-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/map-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/map-delete.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,15 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: map-delete.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,notnull} + {rel_id:integer,notnull} +} -validate { +} + +relation_remove $rel_id +ad_returnredirect -message "relation deleted" [contact::url -party_id $party_id] +ad_script_abort Index: openacs-4/packages/contacts/www/message-messages.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message-messages.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/message-messages.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,25 @@ + + +Mail Merge Results + + + + + + +
+@messages.content;noquote@ +
+
+ +
+From:    @from@
+To:      @messages.to@
+Subject: @messages.subject@
+
+@messages.content@
+
+



+
+
+ Index: openacs-4/packages/contacts/www/message.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/message.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,16 @@ + + +@title@ +@context@ + + + + + + +@party_ids@ + +comment_add.comment + + + Index: openacs-4/packages/contacts/www/message.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/message.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,199 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: message.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_id:integer,multiple,optional} + {party_ids:optional} + {message_id:integer,optional} + {message_type:optional} + {message:optional} + {return_url "./"} +} -validate { + valid_message_type -requires {message_type} { + if { [lsearch [list email letter label] $message_type] < 0 } { + ad_complain "Your provided an invalid Message Type" + } + } + valid_party_submission { + if { ![exists_and_not_null party_id] && ![exists_and_not_null party_ids] } { + ad_complain "Your need to provide some contacts to send a message" + } + } +} +if { [exists_and_not_null party_id] } { + set party_ids [list] + foreach party_id $party_id { + lappend party_ids $party_id + } +} + +set party_count [llength $party_ids] + + +set title "Messages" +set user_id [ad_conn user_id] +set context [list $title] + +set recipients [list] +foreach party_id $party_ids { + lappend recipients "[contact::name -party_id $party_id]" +} +set recipients [join $recipients ", "] + +set form_elements { + message_id:key + party_ids:text(hidden) + return_url:text(hidden) + {to:text(inform),optional {label "Recipients"} {value $recipients}} +} + + +if { [string is false [exists_and_not_null message_type]] } { + append form_elements { + {message_type:text(select) {label "Type"} {options {{Email email} {Letter letter} {Label label}}}} + } + set title [_ contacts.create_a_message] +} else { + append form_elements { + {message_type:text(hidden)} + } + set title [_ contacts.create_$message_type] +} +set context [list $title] + +if { [string is false [exists_and_not_null message]] } { + append form_elements { + {message:text(select) {label "Message"} {options {{{-- Create New Message --} new}}}} + } + set edit_buttons [list [list "Next" create]] +} else { + append form_elements { + {message:text(hidden)} + } + if { $message_type == "email" } { + append form_elements { + {subject:text(text),optional + {label "Subject"} + {html {size 55}} + } + {content:text(textarea),optional + {label "Message"} + {html {cols 55 rows 18}} + {help_text {remember that you can use mail merge substitutions. the most common wildcards are \{name\} \{first_names\}, \{last_name\}, \{home_address\} and \{date\}}} + } + } + } elseif { $message_type == "letter" } { + set todays_date [lc_time_fmt [dt_sysdate] "%q"] + append form_elements { + {paper_type:text(select),optional + {label "Paper Type"} + {options {{{Letter} letter} {Letterhead letterhead}}} + } + {date:text(inform),optional + {label "Date"} + {value $todays_date} + } + {address:text(inform),optional + {label "Address"} + {value "{name}
{mailing_address}"} + {help_text {The recipeints name and mailing address will automatically be included so that they work with window envelopes}} + } + {content:richtext(richtext),optional + {label "Message"} + {html {cols 70 rows 24}} + {help_text {remember that you can use mail merge substitutions. the most common wildcards are \{name\} \{first_names\}, \{last_name\}, \{home_address\} and \{date\}}} + } + } + } else { + error "labels are not implemented yet" + } + set sig_options "{{-- no not include a signature --} \"none\"} [db_list_of_lists select_sigs {select title, signature from contact_signatures where party_id = :user_id}]" + append form_elements { + {include_signature:text(select),optional {label "Signature"} {options $sig_options} {help_text {you may modify your signatures}}} + {save_as:text(text),optional {label "Save Message As"} {html {size 35}}} + } + append form_elements + set edit_buttons [list [list "Preview" create]] +} + + + + + +ad_form -action message \ + -name message \ + -cancel_label "Cancel" \ + -cancel_url $return_url \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -new_request { + } -edit_request { + } -on_submit { + if { [exists_and_not_null include_signature] } { + # we need to do validation + switch $message_type { + letter { + set content_raw [string trim \ + [ad_html_text_convert \ + -from [template::util::richtext::get_property format $content] \ + -to "text/plain" \ + [template::util::richtext::get_property content $content] \ + ] \ + ] + if { $content_raw == "" } { + template::element set_error message content "Message is required" + } + } + email { + if { [string trim $subject] == "" } { + template::element set_error message subject "Subject is required" + } + if { [string trim $content] == "" } { + template::element set_error message content "Message is required" + } + } + } + } + } + + + + +if { [string is false [::template::form::is_valid message]] } { + ad_return_template message +} else { + if { [exists_and_not_null include_signature] } { + # we had good input + switch $message_type { + letter { + set content [ad_html_text_convert -from [template::util::richtext::get_property format $content] -to "text/html" [template::util::richtext::get_property content $content]] + set subject "" + } + email { + set this_subject [string trim $subject] + } + } + set from [contact::name -party_id [ad_conn user_id]] + template::multirow create messages message_type to subject content + foreach party_id $party_ids { + set name [contact::name -party_id $party_id] + set first_names [lindex $name 0] + set last_name [lindex $name 1] + set date [lc_time_fmt [dt_sysdate] "%q"] + set to $name + set values [list] + foreach element [list first_names last_name name date] { + lappend values [list "{$element}" [set $element]] + } + template::multirow append messages $message_type $to [contact::util::interpolate -text $subject -values $values] [contact::util::interpolate -text $content -values $values] + } + + ad_return_template message-messages + } else { + ad_return_template message + } +} Index: openacs-4/packages/contacts/www/my-searches.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/my-searches.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/my-searches.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,9 @@ + +@title@ +@context@ + + + + + + Index: openacs-4/packages/contacts/www/my-searches.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/my-searches.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/my-searches.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,77 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: my-searches.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + orderby:optional +} -validate { +} + +set title "My Searches" +set context [list [list "search" "Advanced Search"] $title] + +template::list::create \ + -name "searches" \ + -multirow "searches" \ + -row_pretty_plural "searches" \ + -selected_format "normal" \ + -key party_id \ + -actions [list \ + "Add Search" "search" "Add Search"] \ + -elements { + object_type { + label {Type} + display_col object_type + } + title { + label {Title} + display_col title + link_url_eval "search?search_id=$search_id" + } + query { + label {Query} + display_col query;noquote + } + } -filters { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + } + } + } + + +#multirow create searches search_id object_type title query + +set owner_id [ad_conn user_id] + +db_multirow -extend {query} -unclobber searches get_searches { +( select search_id, title, upper(title) as order_title, all_or_any, object_type + from contact_searches + where owner_id = :owner_id + and title is not null +) union ( + select search_id, 'Search \#' || to_char(search_id,'FM9999999999999999999') || ' on ' || to_char(creation_date,'Mon FMDD') as title, 'zzzzzzzzzzz' as order_title, all_or_any, contact_searches.object_type + from contact_searches, acs_objects + where owner_id = :owner_id + and search_id = object_id + and contact_searches.title is null + limit 10 +) + order by order_title +} { + db_foreach selectqueries { + select type as query_type, var_list as query_var_list from contact_search_conditions where search_id = :search_id + } { + if { [exists_and_not_null query] } { + append query "
" + } + append query "[contact::search::translate -type $query_type -var_list $query_var_list -to pretty -party_id "party_id" -revision_id "cr.revisions.revision_id"]" + } +} + Index: openacs-4/packages/contacts/www/person-groups-ae.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/person-groups-ae.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/person-groups-ae.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,7 @@ + +@title@ +@context@ + + + + Index: openacs-4/packages/contacts/www/person-groups-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/person-groups-ae.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/person-groups-ae.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,83 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: person-groups-ae.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + + +} { + {person_id:integer,optional} +} + + +if { [exists_and_not_null person_id] } { + set admin_user_url [acs_community_member_admin_url -user_id $person_id] + set user_url [acs_community_member_url -user_id $person_id] +} else { + set admin_user_url "" + set user_url "" +} + +set list_name "person_[ad_conn package_id]" +set object_type "person" +set package_key "contacts" + +if { [ad_form_new_p -key person_id] } { + set title "Add a Person" + set mode "edit" +} else { + set title [person::name -person_id $person_id] + set mode "display" +} +set context [list $title] + + + + + + + + +# groups +ad_form -name groups_ae \ + -mode "display" \ + -has_edit "t" \ + -actions { + {"Add to Group" "formbutton:edit"} + } -form { + {person_id:key} + } + +set package_id [ad_conn package_id] +set group_options [db_list_of_lists get_groups { + select groups.group_name, + groups.group_id, + ( select count(distinct member_id) from group_member_map where group_member_map.group_id = groups.group_id ) as member_count + from groups left join ( select group_id, owner_id, group_type, deprecated_p + from contact_groups + where package_id = :package_id ) contact_groups on (groups.group_id = contact_groups.group_id) + where groups.group_id != '-1' +}] + +set groups_available [db_list_of_lists get_groups { + select groups.group_name, + groups.group_id, + ( select count(distinct member_id) from group_member_map where group_member_map.group_id = groups.group_id ) as member_count + from groups left join ( select group_id, owner_id, group_type, deprecated_p + from contact_groups + where package_id = :package_id ) contact_groups on (groups.group_id = contact_groups.group_id) + where groups.group_id != '-1' +}] +ad_form -extend -name groups_ae -form { + {group_id:integer(checkbox),multiple {label "Groups"} {options $group_options}} + } -edit_request { + set group_id [db_list get_them { select distinct group_id from group_member_map where member_id = :person_id }] + #ad_return_error $group_id $group_id + } -on_submit { + } -after_submit { + ad_returnredirect -message "Group Information Saved." [export_vars -base "person-ae" -url {person_id}] + } + + + +ad_return_template Index: openacs-4/packages/contacts/www/relationship-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-add.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,9 @@ + +@party_id@ + +

What role does @contact_name_one@ have when @contact_name_two@ is a @secondary_role_pretty@:

+ Index: openacs-4/packages/contacts/www/relationship-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-add.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,128 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: relationship-add.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {party_one:integer,notnull} + {role_one:optional} + {party_two:integer,notnull} + {role_two:notnull} + {rel_type:optional} + {comment ""} + {comment_format "text/plain"} + {return_url ""} +} -validate { + contact_one_exists -requires {party_one} { + if { ![contact::exists_p -party_id $party_one] } { + ad_complain "The first contact specified does not exist" + } + } + contact_two_exists -requires {party_two} { + if { ![contact::exists_p -party_id $party_two] } { + ad_complain "The second contact specified does not exist" + } + } + role_one_exists -requires {role_one} { + if { ![db_0or1row role_exists {select 1 from contact_rel_types where primary_role = :role_one}] } { + ad_complain "The first role specified does not exist" + } + } + role_two_exists -requires {role_two} { + if { ![db_0or1row role_exists {select 1 from contact_rel_types where primary_role = :role_two}] } { + ad_complain "The second role specified does not exist" + } + } +} + +set party_id $party_one +set contact_name_one [contact::name -party_id $party_id] +set contact_name_two [contact::name -party_id $party_two] +set contact_type_one [contact::type -party_id $party_id] +set contact_type_two [contact::type -party_id $party_two] +set secondary_role_pretty [db_string getit { select acs_rel_type__role_pretty_name(:role_two) as secondary_role_pretty }] +if { ![exists_and_not_null rel_type] } { + set options_list [db_list_of_lists get_rel_type { + select rel_type, + primary_role, + acs_rel_type__role_pretty_name(primary_role) as primary_role_pretty + from contact_rel_types + where secondary_role = :role_two + and secondary_object_type in (:contact_type_two,'party') + and primary_object_type in (:contact_type_one,'party') + }] + set options_length [llength $options_list] + if { $options_length == "0" } { + ad_return_error "Error" "There was a problem with your input. this type of relationship cannot exist." + } elseif { $options_length == "1" } { + set rel_type [lindex [lindex $options_list 0] 0] + set role_one [lindex [lindex $options_list 0] 1] + } else { + multirow create rel_types rel_type primary_role_pretty url + foreach rel $options_list { + set temp_rel_type [lindex $rel 0] + set temp_role_one [lindex $rel 1] + set temp_role_pretty [lindex $rel 2] + multirow append rel_types $temp_rel_type $temp_role_pretty [export_vars -base "relationship-add" -url {party_one party_two role_two {role_one $temp_role_one} {rel_type $temp_rel_type}}] + } + } +} + + + + +if { [exists_and_not_null rel_type] } { + + db_1row get_roles { + select role_one as db_role_one, + role_two as db_role_two + from acs_rel_types + where rel_type = :rel_type + } + + if { $db_role_one == $role_one } { + set object_id_one $party_one + set object_id_two $party_two + } else { + set object_id_one $party_two + set object_id_two $party_one + } + set existing_rel_id [db_string rel_exists { + select rel_id + from acs_rels + where rel_type = :rel_type + and object_id_one = :object_id_one + and object_id_two = :object_id_two + } -default {}] + + if { [empty_string_p $existing_rel_id] } { + set rel_id {} + set context_id {} + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + set rel_id [db_exec_plsql create_rel { + select acs_rel__new ( + :rel_id, + :rel_type, + :object_id_one, + :object_id_two, + :context_id, + :creation_user, + :creation_ip + ) + }] + db_dml insert_rel { + insert into contact_rels + (rel_id,comment,comment_format) + values + (:rel_id,:comment,:comment_format) + } + } + if { ![exists_and_not_null return_url] } { + set return_url [export_vars -base "contact-rels" -url {{party_id $party_one}}] + ad_returnredirect -message "Relationship Added" $return_url + } + ad_script_abort +} + Index: openacs-4/packages/contacts/www/search-help.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search-help.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search-help.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,29 @@ + + +@title@ +@context@ + + + +

All searches are case insensitive, capitalization does not matter. If more than one contact match the search a list of results is returned. If only one contact meets the search criteria you are redirected to that contact.

+

Normal Searches

+

Entering a string in the normal search box means that a search will be performed where:

+
    +
  1. "First Names" contains "Search_Word" or +
  2. "Last Name" contains "Search_Word" or +
  3. "Organization Name" contains "Search_Word" or +
  4. "Party ID" equals "Search_Word" +
+

If multiple words are used then all words must match the above critera. So, for example if our contacts database contains these entries: +

+Contact ID    | First Names    | Last Name     | Organization Name
+--------------+----------------+---------------+---------------------------------
+123           | Jane           | Doe           |
+234           | John           | Doe           |
+345           | Alfred         | Hitchcock     |
+456           |                |               | United States Treasury
+
+

If in a normal search we search for "D Jane". The first Search_Word ("D") matches contacts 123 (via "Doe"), 234 (via "Doe"), and 345 (via "Alfred"). And the second Search_Word ("Jane") matches only contact 123. Thus only one contact meets both requirements and "Jane Doe" (contact 123) is returned.

+ +

Advanced Searches

+

Advanced searches are very powerful but in return they require very specific input... Index: openacs-4/packages/contacts/www/search-help.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search-help.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search-help.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,14 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: search-help.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { +} -validate { +} +set admin_p [ad_permission_p [ad_conn package_id] admin] +#set default_group_id [contacts::default_group_id] +set title "Search Help" +set context [list $title] + Index: openacs-4/packages/contacts/www/search-redirect.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/search-redirect.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search-redirect.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,25 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: search-redirect.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {query:notnull} + {object_type:notnull} + {all_any:notnull} +} -validate { +} +#ad_return_error "Error" $query +#ad_returnredirect [export_vars -base "search" -url {query object_type all_any}] +rp_internal_redirect search +ad_script_abort + + + + + + + + + Index: openacs-4/packages/contacts/www/search.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,16 @@ + + +@page_title@ +@context@ + + + + +

My Searches

+ + + +

Debugging Code - Only SW Admins See This

+ +@query_code;noquote@ +
Index: openacs-4/packages/contacts/www/search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,518 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: search.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {search_id:integer,optional} + {type ""} + {var1 ""} + {var2 ""} + {var3 ""} + {var4 ""} + {var5 ""} + {save ""} + {add ""} + {next ""} + {clear ""} + {delete ""} + {search ""} + {object_type ""} + {all_or_any ""} + {title ""} + {owner_id ""} +} -validate { +} + +set page_title "Advanced Search" +set context [list $page_title] +set sw_admin_p [acs_user::site_wide_admin_p] + +if { [exists_and_not_null clear] } { + ad_returnredirect "search" +} + +if { [exists_and_not_null delete] } { + contact::search::delete -search_id $search_id + ad_returnredirect "my-searches" +} + +if { [exists_and_not_null search] } { + ad_returnredirect ".?query_id=$search_id" +} + + +set search_exists_p 0 +# set query_pretty [list] +if { [exists_and_not_null search_id] } { + if { [contact::search::exists_p -search_id $search_id] } { + db_1row get_em { select title, owner_id, all_or_any, object_type from contact_searches where search_id = :search_id } + set search_exists_p 1 + } +} + + + + + +if { [exists_and_not_null add] } { + set action "add" +} else { + set action "next" +} +switch $object_type { + party { set object_type_pretty "People or Organizations" } + person { set object_type_pretty "People" } + organization { set object_type_pretty "Organizations" } + default { + if { [exists_and_not_null object_type] } { + ad_return_error "Invalid Object Type" "You have specified an invalid Object Type" + } + } +} + +if { ![exists_and_not_null owner_id] } { + set owner_id [ad_conn user_id] +} + + +# FORM HEADER +set form_elements { + {search_id:key} + {owner_id:integer(hidden)} +} +if { [exists_and_not_null object_type] } { + append form_elements { + {object_type:text(hidden) {value $object_type}} + {object_type_pretty:text(inform) {label {Search for}} {value "$object_type_pretty"} {after_html " which match"}} + {all_or_any:text(select),optional {label ""} {options {{All all} {Any any}}} {after_html "of the following conditions:
"}} + } +} else { +# {{People or Organizations} party} + append form_elements { + {object_type:text(select) {label {Search for}} {options { + {{People} person} + {{Organizations} organization} + }} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } +} + + + +# set query_pretty [list] +if { $search_exists_p } { + set query_pretty "
    " + db_foreach selectqueries { + select type as query_type, var_list as query_var_list from contact_search_conditions where search_id = :search_id + } { + append query_pretty "
  • [contact::search::translate -type $query_type -var_list $query_var_list -to pretty -party_id "party_id" -revision_id "cr.revisions.revision_id"]
  • " + } + append query_pretty "
" + append form_elements { + {query:text(hidden),optional} + {query_pretty:text(inform),optional {label {}} {value $query_pretty}} + } + if { $sw_admin_p } { + set query_code " +
+
+
+select contact__name(party_id), party_id, revision_id
+  from parties, cr_items, cr_revisions
+ where party_id = cr_items.item_id
+   and cr_items.latest_revision = cr_revisions.revision_id
+[contact::search::where_clauses -and -search_id $search_id -party_id "party_id" -revision_id "cr.revisions.revision_id"]
+
+
+
+" + } +} + + + + + + + + + + + + + + + +if { [exists_and_not_null object_type] } { + + # QUERY TYPE + set type_options [list \ + [list "Attribute ->" "attribute"] \ + [list "Contact ->" "contact"] \ + [list "Group ->" "group"] \ + ] + +# [list "Tasks ->" "tasks"] + append form_elements { + {type:text(select),optional {label {}} {options $type_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } +} + + +# each type must specify when to save a query +set add_p 0 + +switch $type { + attribute { + + + set attribute_options [db_list_of_lists get_attributes { + select pretty_name || ' ->' , attribute_id + from ams_attributes + where object_type in ('organization','party','person','user') + and ams_attribute_id is not null + order by upper (pretty_name) + }] + + append form_elements { + {var1:text(select),optional {label {}} {options $attribute_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + + if { [exists_and_not_null var1] } { + set attribute_id $var1 + ams::attribute::get -attribute_id $attribute_id -array "attr_info" + set value_method [ams::widget -widget $attr_info(widget) -request "value_method"] + + switch $value_method { + ams_value__options { + set operand_options [list \ + [list "is ->" "selected"] \ + [list "is not ->" "not_selected"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } else { + set option_options [ams::widget_options -attribute_id $attribute_id] + append form_elements { + {var3:text(select) {label {}} {options $option_options}} + } + } + set add_p 1 + } + + } + ams_value__telecom_number { + set operand_options [list \ + [list "area code is ->" "area_code_equals"] \ + [list "area code is not ->" "not_area_code_equals"] \ + [list "country code is ->" "country_code_equals"] \ + [list "country code is not ->" "not_country_code_equals"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } else { + append form_elements { + {var3:integer(text) {label {}} {html {size 3 maxlength 3}}} + } + } + set add_p 1 + } + + } + ams_value__text { + set operand_options [list \ + [list "contains ->" "contains"] \ + [list "does not contain ->" "not_contains"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } else { + append form_elements { + {var3:text(text) {label {}}} + } + } + set add_p 1 + } + + } + ams_value__postal_address { + set operand_options [list \ + [list "country is ->" "country_is"] \ + [list "country is not ->" "country_is_not"] \ + [list "state/province is ->" "state_is"] \ + [list "state/province is not ->" "state_is_not"] \ + [list "zip/postal starts with ->" "zip_is"] \ + [list "zip/postal does not start with ->" "zip_is_not"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } elseif { $var2 == "state_is" || $var2 == "state_is_not" } { + append form_elements { + {var3:text(text) {label {}} {html {size 2 maxlength 2}}} + } + } elseif { $var2 == "country_is" || $var2 == "country_is_not" } { + set country_options [template::util::address::country_options] + append form_elements { + {var3:text(select) {label {}} {options $country_options}} + } + } else { + append form_elements { + {var3:text(text) {label {}} {html {size 7 maxlength 7}}} + } + } + set add_p 1 + } + + } + ams_value__number { + set operand_options [list \ + [list "is ->" "is"] \ + [list "is greater than ->" "greater_than"] \ + [list "is less than ->" "less_than"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } else { + append form_elements { + {var3:integer(text) {label {}} {html {size 4 maxlength 20}}} + } + } + set add_p 1 + } + + } + ams_value__time { + set operand_options [list \ + [list "is less than ->" "less_than"] \ + [list "is more than ->" "more_than"] \ + [list "is after ->" "after"] \ + [list "is before ->" "before"] \ + [list "is set" "set"] \ + [list "is not set" "not_set"] \ + ] + append form_elements { + {var2:text(select),optional {label {}} {options $operand_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + if { [exists_and_not_null var2] } { + if { $var2 == "exists" || $var2 == "not_exists" } { + set action "add" + } else { + if { $var2 == "more_than" || $var2 == "less_than" } { + set interval_options { + {years years} + {months months} + {days days} + } + append form_elements { + {var3:integer(text) {label {}} {html {size 2 maxlength 3}}} + {var4:text(select) {label {}} {options $interval_options} {after_html {ago}}} + } + } else { + append form_elements { + {var3:date(date) {label {}}} + } + } + } + set add_p 1 + } + + } + } + + + } + } + contact { + set contact_options [list \ + [list "updated in the last ->" "update"] \ + [list "not updated in the last ->" "not_update"] \ + [list "commented on in last ->" "comment"] \ + [list "not commented on in last ->" "not_comment"] \ + [list "created in the last ->" "created"] \ + [list "not created in the last ->" "not_created"] \ + ] + if { $object_type == "person" } { + lappend contact_options [list "has logged in" "login"] + lappend contact_options [list "has never logged in" "not_login"] + lappend contact_options [list "has logged in within ->" "login_time"] + lappend contact_options [list "has not logged in within ->" "not_login_time"] + } + append form_elements { + {var1:text(select) {label {}} {options $contact_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}} + } + + if { [exists_and_not_null var1] } { + if { $var1 == "login" || $var1 == "not_login" } { + set action "add" + } else { + set interval_options { + {days days} + {months months} + {years years} + } + append form_elements { + {var2:integer(text) {label {}} {html {size 3 maxlength 4}}} + {var3:text(select) {label {}} {options $interval_options}} + } + } + set add_p 1 + } + } + group { + set operand_options [list \ + [list "contact is in ->" "in"] \ + [list "contact is not in ->" "not_in"] \ + ] + + set group_options [contact::groups -expand "all" -privilege_required "read"] + set add_p 1 + append form_elements { + {var1:text(select) {label {}} {options $operand_options}} + {var2:text(select) {label {}} {options $group_options}} + } + + } + tasks { + set contact_options [list \ + [list "" ""] \ + [list "" ""] \ + [list "" ""] \ + [list "" ""] \ + [list "" ""] \ + [list "" ""] \ + ] + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +if { $add_p } { + append form_elements { + {add:text(submit) {label "Add Condition"} {value "add"}} + } +} else { + append form_elements { + {next:text(submit) {label "Next"} {value "next"}} + } +} + + + + + + + + + + + + + + + +if { $search_exists_p } { + append form_elements { + {title:text(text),optional {label "

save this search as"} {html {size 40 maxlength 255}}} + {save:text(submit) {label {Save}} {value "save"}} + {search:text(submit) {label {Search}} {value "search"}} + {clear:text(submit) {label {Clear}} {value "clear"}} + {delete:text(submit) {label {Delete}} {value "delete"}} + } +} +ad_form -name "advanced_search" -method "GET" -form $form_elements \ + -on_request { + } -edit_request { + } -on_refresh { + } -on_submit { + if { [contact::search::exists_p -search_id $search_id] } { + contact::search::update -search_id $search_id -title $title -owner_id $owner_id -all_or_any $all_or_any + } + if { $action == "add" } { + if { [string is false [contact::search::exists_p -search_id $search_id]] } { + set search_id [contact::search::new -search_id $search_id -title $title -owner_id $owner_id -all_or_any $all_or_any -object_type $object_type] + } + set var_list $var1 + set vars [list var2 var3 var4 var5] + foreach var $vars { + if { [set $var] != "" } { + if { [template::element::get_property advanced_search $var widget] == "date" } { + set $var [join [template::util::date::get_property linear_date_no_time [set $var]] "-"] + } + lappend var_list [set $var] + } + } + contact::search::condition::new -search_id $search_id -type $type -var_list $var_list + } + } -after_submit { + if { $action == "add" } { +# rp_internal_redirect search + ad_returnredirect [export_vars -base "search" -url {search_id object_type all_or_any}] + ad_script_abort + } + } + Index: openacs-4/packages/contacts/www/search.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/search.xql 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,90 @@ + + + + + + select gmm.member_id as party_id + from group_member_map gmm, + membership_rels mr + where gmm.rel_id = mr.rel_id + [template::list::filter_where_clauses -and -name "contacts"] + [template::list::orderby_clause -orderby -name "contacts"] + + + + + + + select admin_role.pretty_name as admin_role_pretty, + member_role.pretty_name as member_role_pretty + from acs_rel_roles admin_role, acs_rel_roles member_role + where admin_role.role = 'admin' + and member_role.role = 'member' + + + + + + + + select groups.group_name, + groups.group_id, + ( select count(distinct member_id) from group_approved_member_map where group_approved_member_map.group_id = groups.group_id ) as member_count + from groups left join ( select group_id, default_p + from contact_groups + where package_id = :package_id ) contact_groups on (groups.group_id = contact_groups.group_id) + where groups.group_id != '-1' + order by CASE WHEN groups.group_id = '-2' THEN '000000000' ELSE upper(groups.group_name) END + + + + + + + + select arr.pretty_plural, + art.rel_type as relation_type, + ( select count(distinct gmm.member_id) from group_approved_member_map gmm where gmm.group_id = :group_id and gmm.rel_type = art.rel_type ) as member_count + from acs_rel_types art, + acs_rel_roles arr + where art.rel_type in ( select distinct gmm.rel_type from group_approved_member_map gmm where gmm.group_id = :group_id ) + and art.role_two = arr.role + + + + + + + select gmm.member_id as party_id, + gmm.group_id, + gmm.rel_id, + gmm.rel_type, + contact__name(gmm.member_id,:name_order) as name, + mr.member_state, + party__email(gmm.member_id) as email, + ( select first_names from persons where person_id = gmm.member_id ) as first_names, + ( select last_name from persons where person_id = gmm.member_id ) as last_name, + ( select name from organizations where organization_id = gmm.member_id ) as organization + from group_member_map gmm, + membership_rels mr + where gmm.rel_id = mr.rel_id + [template::list::filter_where_clauses -and -name "contacts"] + [template::list::page_where_clause -and -name "contacts" -key "gmm.member_id"] + + + + + + + select mr.member_state as state, + count(mr.rel_id) as num_contacts + from membership_rels mr, acs_rels r + where r.rel_id = mr.rel_id + and r.object_id_one = :group_id + and r.rel_type = 'membership_rel' + group by mr.member_state + + + + + Index: openacs-4/packages/contacts/www/settings.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/settings.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/settings.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,12 @@ + +@title@ +@context@ + +

+Add Signature +Administer Contacts +

+

My Signatures

+ + + Index: openacs-4/packages/contacts/www/settings.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/settings.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/settings.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,59 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: settings.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + + +} { +} + +set title "Settings" +set context [list $title] +set package_id [ad_conn package_id] +set party_id [ad_conn user_id] +set admin_p [ad_permission_p [ad_conn package_id] admin] + +template::list::create \ + -name "signatures" \ + -multirow "signatures" \ + -row_pretty_plural "signatures" \ + -elements { + default_p { + label "" + display_template { + + Default Signature + + } + } + title { + label "" + display_col title + link_url_eval $signature_url + } + signature { + label "" + display_col signature;noquote + } + } -filters { + } -orderby { + } + + +db_multirow -extend { signature_url } signatures select_signatures { + select signature_id, + title, + signature, + default_p + from contact_signatures + where party_id = :party_id + order by default_p, upper(title), upper(signature) +} { + set signature [ad_convert_to_html $signature] + set signature_url [export_vars -base signature -url {signature_id }] +} + + + +ad_return_template Index: openacs-4/packages/contacts/www/signature.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/signature.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/signature.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,10 @@ + + +@page_title@ +@context@ + + + +signature.title + + Index: openacs-4/packages/contacts/www/signature.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/signature.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/signature.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,68 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: signature.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ +} { + {signature_id:integer,optional} +} -validate { + valid_signature_id -requires {signature_id} { + set party_id [ad_conn user_id] + if { ![ad_form_new_p -key signature_id] } { + if { [string is false [db_0or1row sig_is_mine_p {select '1' from contact_signatures where signature_id = :signature_id and party_id = :party_id}]] } { + ad_complain "This signature specified either does not exist or does not belong to you" + } + } + } +} + + +if { [ad_form_new_p -key signature_id] } { + set page_title "Create a Signature" + set edit_buttons [list [list "Create" save]] +} else { + set page_title "Edit a Signature" + set edit_buttons [list [list "Save" save] [list "Delete" delete]] +} + +set context [list $page_title] +set party_id [ad_conn user_id] +set form_elements { + signature_id:key + {title:text(text) {label "Save As"} {html {size 35 maxlength 35}}} + {signature:text(textarea) {label "Signature"} {html {cols 45 rows 5}}} + {default_p:boolean(checkbox),optional {label ""} {options {{{this is my default signature} 1}}}} +} + + +ad_form -action signature \ + -name signature \ + -cancel_label "Cancel" \ + -cancel_url "settings" \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -new_request { + } -edit_request { + db_1row get_sig_info { select * from contact_signatures where signature_id = :signature_id } + } -on_submit { + if { [ns_queryget "formbutton:delete"] != "" } { + db_dml delete_it { delete from contact_signatures where signature_id = :signature_id and party_id = :party_id } + ad_returnredirect "settings" + ad_script_abort + } + if { [string is false [exists_and_not_null default_p]] } { + set default_p 0 + } else { + # its true and we reset the default + db_dml update_defaults { update contact_signatures set default_p = 'f' where party_id = :party_id } + } + } -new_data { + db_dml insert_sig { insert into contact_signatures values ( :signature_id, :title, :signature, :default_p, :party_id ) } + } -edit_data { + db_dml update_sig { update contact_signatures set title = :title, signature = :signature, default_p = :default_p where signature_id = :signature_id } + } -after_submit { + ad_returnredirect "settings" + } + Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-add-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-add.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-add.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-ae-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-ae.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-ae.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-depreciate-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-depreciate.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-restore-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attribute-restore.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attributes-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attributes.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/admin/attributes.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/www/admin/group-ae.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/group-ae.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/admin/group-ae.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,7 @@ + + +@title@ +@context@ + + + Index: openacs-4/packages/contacts/www/admin/group-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/group-ae.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/admin/group-ae.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,113 @@ +ad_page_contract { + + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-ae.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + +} { + {group_id:integer,optional} + {object_type ""} + {return_url "./"} +} +set user_id [auth::require_login] + +set form_elements { + group_id:key + title:text(hidden),optional + context:text(hidden),optional + return_url:text(hidden),optional +} + +if { [ad_form_new_p -key group_id] } { + set parents "{{-- top level group --} {}} [contact::groups -expand "none" -output "ad_form" -privilege_required "admin"]" + append form_elements { + {parent:integer(select),optional {label "Parent Group"} {options $parents}} + } +} else { + set parent_id [contact::group::parent -group_id $group_id] + if { [exists_and_not_null parent_id] } { + set parent [acs_object_name $parent_id] + append form_elements { + {parent:text(inform),optional {label "Parent Group"}} + } + } +} + +#append form_elements { +# permitted_rels,text(checkbox) +#} + +append form_elements { + {group_name:text(text) {label "Group Name"}} + join_policy:text(hidden) + url:text(hidden),optional + email:text(hidden),optional +} +ad_form -name group_ae -action group-ae -form $form_elements \ +-new_request { + set title "Add a Group" + set context [list $title] + set join_policy "open" +} -edit_request { + + db_1row select_group_info { + select group_name, join_policy, + url, email + from groups, + parties + where groups.group_id = parties.party_id + and groups.group_id = :group_id + } + + set title "Edit ${group_name}" + set context [list [list groups "Groups"] $title] + +} -validate { +} -new_data { + + db_transaction { + contact::group::new \ + -group_id $group_id \ + -email $email \ + -url $url \ + -group_name $group_name \ + -join_policy $join_policy \ + -context_id "" + + if { [exists_and_not_null parent] } { + relation_add -member_state "approved" "composition_rel" $parent $group_id + } + } + set message "Group '${group_name}' Created" + +} -edit_data { + + db_dml update_group { + update groups + set group_name = :group_name, + join_policy = :join_policy + where group_id = :group_id + } + + db_dml update_group_extras { + update parties + set email = :email, + url = :url + where party_id = :group_id + } + + set message "Group '${group_name}' Updated" + +} -after_submit { + + ad_returnredirect -message ${message} ${return_url} + ad_script_abort + +} + + + + + +ad_return_template Index: openacs-4/packages/contacts/www/admin/group-map.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/group-map.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/admin/group-map.adp 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,7 @@ + + +@title@ +@context@ + + + Index: openacs-4/packages/contacts/www/admin/group-map.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/group-map.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/admin/group-map.tcl 18 May 2005 16:45:50 -0000 1.1 @@ -0,0 +1,87 @@ +ad_page_contract { + + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: group-map.tcl,v 1.1 2005/05/18 16:45:50 matthewg Exp $ + +} { + {group_id:integer,notnull} + {action:notnull} + {return_url "./"} +} -validate { + action_valid -requires {action} { + if { [lsearch [list map unmap makedefault] $action] < 0 } { + ad_complain "the action supplied is not valid" + } + } + action_appropriate -requires {action} { + set package_id [ad_conn package_id] + set default_p [db_string group_mapped { select default_p from contact_groups where group_id = :group_id and package_id = :package_id } -default {}] + set parent_id [contact::group::parent -group_id $group_id] + + if { [exists_and_not_null default_p] } { + # the group is mapped + if { $default_p && $action == "makedefault" } { + ad_complain "This group is already the default" + } + if { [exists_and_not_null parent_id] && $action == "makedefault" } { + ad_complain "You cannot make sub groups the default group" + } + if { $default_p && $action == "unmap" } { + ad_complain "You cannot unmap the default group" + } + if { $action == "map" } { + ad_complain "This group is already mapped" + } + } else { + if { $action != "map" } { + ad_complain "This action cannot be taken for unmapped groups" + } + if { [exists_and_not_null parent_id] } { + if { ![db_0or1row parent_mapped { select 1 from contact_groups where group_id = :parent_id and package_id = :package_id }] } { + ad_complain "You cannot map groups whose parent groups are not mapped" + } + } + } + } +} + + + +set package_id [ad_conn package_id] + +switch $action { + map { + # if the group is the only one for this package it needs to be made the default + set count [db_string get_count { select count(*) from contact_groups where package_id = :package_id } -default "0"] + if { $count == 0 } { + set default_p "1" + } else { + set default_p "0" + } + db_dml insert_map { + insert into contact_groups + (group_id,default_p,package_id) + values + (:group_id,:default_p,:package_id) + } + } + unmap { + db_dml delete_map { + delete from contact_groups where group_id = :group_id and package_id = :package_id + + } + } + makedefault { + db_dml remove_other_defaults { + update contact_groups set default_p = 'f' where package_id = :package_id + } + db_dml make_default { + update contact_groups set default_p = 't' where package_id = :package_id and group_id = :group_id + } + } +} + + +ad_returnredirect $return_url Index: openacs-4/packages/contacts/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/index.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/www/admin/index.adp 13 Jan 2005 13:57:12 -0000 1.2 +++ openacs-4/packages/contacts/www/admin/index.adp 18 May 2005 16:45:50 -0000 1.3 @@ -1,15 +1,17 @@ - @title@ @context@ -