summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2008-09-25 23:08:34 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2008-09-25 23:08:34 +0000
commita316a97097bf8bcf9a4f809faf30dd756e60563d (patch)
tree044e4ccae8fc9faf724970464e4bc8dab468c58f
parent899c61eba210d60d8212dcd086fd74fc7a1c9812 (diff)
Saving locations and contacts to a user now works as expected.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2342 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/DBObject/Admin.pm2
-rw-r--r--LedgerSMB/DBObject/Location.pm6
-rw-r--r--LedgerSMB/DBObject/User.pm57
-rw-r--r--UI/Admin/edit_user.html65
-rw-r--r--scripts/admin.pl101
-rw-r--r--sql/Pg-database.sql2
-rw-r--r--sql/modules/Location.sql38
-rw-r--r--sql/modules/Person.sql12
8 files changed, 192 insertions, 91 deletions
diff --git a/LedgerSMB/DBObject/Admin.pm b/LedgerSMB/DBObject/Admin.pm
index e16e5dea..362d0c39 100644
--- a/LedgerSMB/DBObject/Admin.pm
+++ b/LedgerSMB/DBObject/Admin.pm
@@ -267,7 +267,7 @@ sub get_countries {
sub get_contact_classes {
my $self = shift @_;
- my $sth = $self->{dbh}->prepare("select id, class as classname from contact_class");
+ my $sth = $self->{dbh}->prepare("select id, class as name from contact_class");
my $code = $sth->execute();
return $sth->fetchall_arrayref({});
}
diff --git a/LedgerSMB/DBObject/Location.pm b/LedgerSMB/DBObject/Location.pm
index 1b7e2699..64ac9f01 100644
--- a/LedgerSMB/DBObject/Location.pm
+++ b/LedgerSMB/DBObject/Location.pm
@@ -17,6 +17,7 @@ sub save {
my ($ret) = $self->exec_method(funcname=>$type."__save_location", args=>[
$self->{user_id}, # entity_id
$self->{location_id}, # location_id
+ 3, # location_class, currently being set to "shipping"
$self->{address1},
$self->{address2},
$self->{address3}, # address info
@@ -25,7 +26,8 @@ sub save {
$self->{zipcode},
$self->{country} # obviously, country.
]);
- $self->{id} = $ret->[0];
+ $self->{id} = $ret->{$type."__save_location"};
+ $self->{dbh}->commit();
return $self->{id};
}
@@ -59,7 +61,7 @@ sub get {
my ($ret) = $self->exec_method(funcname=>"location__get", args=>[$id]);
- return $ret->[0];
+ return $ret->{location__get};
}
sub get_all {
diff --git a/LedgerSMB/DBObject/User.pm b/LedgerSMB/DBObject/User.pm
index 0ca6bcfc..00a7e9db 100644
--- a/LedgerSMB/DBObject/User.pm
+++ b/LedgerSMB/DBObject/User.pm
@@ -90,6 +90,7 @@ sub get {
}
$self->{roles} = \@rolstore;
+ $self->{entity_id} = $self->{entity}->{id};
print STDERR "Got all user information";
#$user->{user} = $u->get($id);
@@ -145,16 +146,56 @@ sub save_contact {
my $self = shift @_;
my $id = shift @_;
+ my $class = shift @_;
my $contact = shift @_;
+ my @ret;
+
+ print STDERR Dumper($self->{entity}->{id});
+ if ($id) {
+ print STDERR "Found ID..";
+ @ret = $self->exec_method(funcname=>"person__save_contact",
+ args=>[
+ $self->{entity}->{id},
+ $self->{contacts}->[$id]->{contact_class},
+ $self->{contacts}->[$id]->{contact},
+ $contact
+ ]
+ );
+ }
+ else{
+ print STDERR "Did not find an ID, attempting to save a new contact..\n";
+ print STDERR ($class."\n");
+ print STDERR ($contact."\n");
+ print STDERR ($self->{entity_id}."\n");
+ @ret = $self->exec_method(funcname=>"person__save_contact",
+ args=>[
+ $self->{entity_id},
+ $class,
+ undef,
+ $contact
+ ]
+ );
+ }
+ print STDERR Dumper(\@ret);
+ if ($ret[0]->{person__save_contact} == 1){
+ $self->{dbh}->commit();
+ }
+ else{
+ $self->error("Couldn't save contact...");
+ }
+ return 1;
+}
+
+sub delete_contact {
+
+ my $self = shift @_;
+ my $id = shift @_;
+
+ # Okay
+ # ID doesn't actually conform to any database entry
+ # We're basically cheating outrageously here.
+
- my @ret = $self->exec_method(funcname=>"person__save_contact",
- args=>[
- $self->{entity_id},
- $self->{contacts}->[$id]->{contact_class},
- $self->{contacts}->[$id]->{contact},
- $contact
- ]
- );
}
1;
diff --git a/UI/Admin/edit_user.html b/UI/Admin/edit_user.html
index 536b8ffa..df166cf7 100644
--- a/UI/Admin/edit_user.html
+++ b/UI/Admin/edit_user.html
@@ -62,7 +62,7 @@
<input type="hidden" name="location_id" value="<?lsmb location.id?>"/>
<?lsmb END?>
<input type="hidden" name="action" value="save_location"/>
- <input type="hidden" name="user_id" value="<?lsmb user.user.entity_id?>"/>
+ <input type="hidden" name="user_id" value="<?lsmb user.user.id?>"/>
<table>
<tr>
@@ -90,8 +90,7 @@
Country
</td>
</tr>
-
-
+
<?lsmb FOR location IN user.locations ?>
<tr>
@@ -200,7 +199,7 @@
options = contact_classes
default_values = [contact.contact_class_id]
value_attr = "id"
- text_attr = "classname"
+ text_attr = "name"
} ?>
</td>
<td>
@@ -219,33 +218,35 @@
</tr>
</form>
</table>
+ <form name="groups" method="POST" action="admin.pl">
+ <input type="hidden" name="action" value="save_groups"/>
+ <table>
+ <!-- Groups section -->
+ <tr>
+ <?lsmb FOREACH role IN roles ?>
+ <?lsmb IF loop.count % 2 == 0?>
+ </tr>
+ <tr>
+ <?lsmb END?>
+ <td>
+ <input type="checkbox" name="<?lsmb loop.index?>" value="1"
+ <?lsmb FOREACH rolname IN user.roles ?>
+ <?lsmb IF role == rolname?>
+ checked
+ <?lsmb END?>
+ <?lsmb END?> />
+ <?lsmb role?>
+ </td>
+ <?lsmb END?>
+ </tr>
+ </table>
- <table>
- <!-- Groups section -->
- <tr>
- <?lsmb FOREACH role IN roles ?>
- <?lsmb IF loop.count % 2 == 0?>
- </tr>
- <tr>
- <?lsmb END?>
- <td>
- <input type="checkbox" name="<?lsmb loop.index?>" value="1"
- <?lsmb FOREACH rolname IN user.roles ?>
- <?lsmb IF role == rolname?>
- checked
- <?lsmb END?>
- <?lsmb END?> />
- <?lsmb role?>
- </td>
- <?lsmb END?>
- </tr>
- </table>
-
- <table>
- <tr>
- <td><button value="new_user">Submit</button></td>
- <td><button name="method" value="cancel">Cancel</td>
- </tr>
- </table>
- <?lsmb END?>
+ <table>
+ <tr>
+ <td><button value="groups">Save Groups</button></td>
+ <td><button name="method" value="cancel">Cancel</td>
+ </tr>
+ </table>
+ </form>
+<?lsmb END?>
</div>
diff --git a/scripts/admin.pl b/scripts/admin.pl
index 3a92425c..d8c5d499 100644
--- a/scripts/admin.pl
+++ b/scripts/admin.pl
@@ -9,6 +9,56 @@ use LedgerSMB::DBObject::User;
use LedgerSMB::DBObject::Location;
use Data::Dumper;
+sub __edit_page {
+
+
+ my ($request, $otd) = @_;
+
+ # otd stands for Other Template Data.
+
+ my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'list', merge=>['user_id','company']);
+ $user_obj->{company} = $request->{company};
+ $user_obj->get($request->{user_id});
+
+ my @all_roles = $admin->get_roles();
+
+ my $template = LedgerSMB::Template->new(
+ user => $user,
+ template => 'Admin/edit_user',
+ language => $user->{language},
+ format => 'HTML',
+ path=>'UI'
+ );
+ my $location = LedgerSMB::DBObject::Location->new(base=>$request);
+ my $template_data =
+ {
+ user=>$user_obj,
+ roles=>@all_roles,
+ countries=>$admin->get_countries(),
+ user_roles=>$user_obj->{roles},
+ salutations=>$admin->get_salutations(),
+ contact_classes=>$admin->get_contact_classes(),
+ locations=>$location->get_all($user_obj->{entity_id},"person"),
+ };
+ open (FOO,">/tmp/dump.txt");
+ print STDERR Dumper($template_data->{contact_classes});
+ print FOO Dumper($template_data);
+
+ for my $key (keys(%{$otd})) {
+
+ $template_data->{$key} = $otd->{$key};
+ }
+ my $template = LedgerSMB::Template->new(
+ user => $user,
+ template => 'Admin/edit_user',
+ language => $user->{language},
+ format => 'HTML',
+ path=>'UI'
+ );
+ $template->render($template_data);
+}
+
sub new_user {
# uses the same page as create_user, only pre-populated.
@@ -62,7 +112,7 @@ sub edit_user {
# uses the same page as create_user, only pre-populated.
my ($request) = @_;
my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
- my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'list', merge=>['user_id','company']);
$user_obj->{company} = $request->{company};
$user_obj->get($request->{user_id});
@@ -86,13 +136,14 @@ sub edit_user {
contact_classes=>$admin->get_contact_classes(),
locations=>$location->get_all($user_obj->{entity_id},"person"),
};
+ open (FOO,">/tmp/dump.txt");
print STDERR Dumper($template_data->{contact_classes});
- print STDERR Dumper($template_data->{user_roles});
+ print FOO Dumper($template_data);
if ($request->type() eq 'POST') {
$admin->save_user();
$admin->save_roles();
- $template->render($test_data);
+ $template->render($template_data);
}
else {
# print STDERR Dumper($user);
@@ -266,32 +317,9 @@ sub save_contact {
# ->{contacts} is an arrayref to the list of contacts this user has
# $request->{contact_id} is a reference to this structure.
- $user_obj->save_contact($c_id);
-
- my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
+ $user_obj->save_contact($c_id, $request->{contact_class}, $request->{contact});
- $user_obj->get($request->{user_id});
-
- my @all_roles = $admin->get_roles();
-
- my $template = LedgerSMB::Template->new(
- user => $user,
- template => 'Admin/edit_user',
- language => $user->{language},
- format => 'HTML',
- path=>'UI'
- );
- my $template_data =
- {
- user=>$user_obj,
- roles=>@all_roles,
- countries=>$admin->get_countries(),
- user_roles=>$user_obj->{roles},
- salutations=>$admin->get_salutations(),
- contact_classes=>$admin->get_contact_classes(),
- locations=>$location->get_all($user_obj->{entity_id},"person"),
- };
- $template->render($template_data);
+ __edit_page($request,{});
}
}
@@ -316,7 +344,8 @@ sub delete_contact {
$user->delete_contact($c_id);
# Boom. Done.
# Now, just call the main edit user page.
- edit_user($request);
+
+ __edit_page($request,undef,);
}
}
@@ -328,9 +357,9 @@ sub save_location {
if ($request->type eq "POST") {
my $u_id = $request->{user_id}; # this is an entity_id
-
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
my $location = LedgerSMB::DBObject::Location->new(base=>$request, copy=>'all');
-
+ $user_obj->get($request->{user_id});
# So there's a pile of stuff we need.
# lineone
# linetwo
@@ -339,14 +368,16 @@ sub save_location {
# state
# zipcode
# country
+ # u_id isn't an entity_it, though.
print STDERR "Attempting to save location...\n";
+ $location->{user_id} = $user_obj->{user}->{entity_id};
+ print STDERR $location->{user_id}."\n";
my $id = $location->save("person");
# Done and done.
my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
- my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
- $user->get($request->{user_id});
+
my @all_roles = $admin->get_roles();
@@ -359,9 +390,9 @@ sub save_location {
);
$template->render(
{
- user=>$user,
+ user=>$user_obj,
roles=>@all_roles,
- user_roles=>$user->{roles},
+ user_roles=>$user_obj->{roles},
salutations=>$admin->get_salutations(),
locations=>$location->get_all($u_id,"person"),
location=>$location->get($id),
diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql
index e81ee254..3373b01b 100644
--- a/sql/Pg-database.sql
+++ b/sql/Pg-database.sql
@@ -156,7 +156,7 @@ CREATE TABLE location (
state text check(state ~ '[[:alnum:]_]'),
country_id integer not null REFERENCES country(id),
mail_code text not null check (mail_code ~ '[[:alnum:]_]'),
- created date not null,
+ created date not null default now(),
inactive_date timestamp default null,
active boolean not null default TRUE
);
diff --git a/sql/modules/Location.sql b/sql/modules/Location.sql
index e266f277..0597a241 100644
--- a/sql/modules/Location.sql
+++ b/sql/modules/Location.sql
@@ -46,8 +46,8 @@ BEGIN
line_three,
city,
state,
- zipcode,
- country)
+ mail_code,
+ country_id)
VALUES (
location_id,
in_address1,
@@ -64,7 +64,7 @@ BEGIN
SELECT * INTO location_row WHERE id = in_location_id;
IF NOT FOUND THEN
-- Tricky users are lying to us.
- RAISE EXCEPTION "location_save called with nonexistant location ID %", in_location_id;
+ RAISE EXCEPTION 'location_save called with nonexistant location ID %', in_location_id;
ELSE
-- Okay, we're good.
@@ -74,8 +74,8 @@ BEGIN
line_three = in_address3,
city = in_city,
state = in_state,
- zipcode = in_zipcode,
- country = in_country
+ mail_code = in_zipcode,
+ country_id = in_country
WHERE id = in_location_id;
return in_location_id;
END IF;
@@ -156,8 +156,32 @@ CREATE TYPE location_result AS (
line_three text,
city text,
state text,
- mail_code text,
+ mail_code text,
country text,
- class text
);
+CREATE OR REPLACE FUNCTION location__get(in_id int) returns location_result AS $$
+
+declare
+ l_row location_result;
+begin
+ FOR l_row IN
+ SELECT
+ l.id,
+ l.line_one,
+ l.line_two,
+ l.line_three,
+ l.city,
+ l.state,
+ l.mail_code,
+ c.name as country,
+ NULL
+ FROM location l
+ JOIN country c on l.country_id = c.id
+ WHERE l.id = in_id
+ LOOP
+
+ return l_row;
+ END LOOP;
+END;
+$$ language plpgsql ; \ No newline at end of file
diff --git a/sql/modules/Person.sql b/sql/modules/Person.sql
index 546398e9..9bdc9e1f 100644
--- a/sql/modules/Person.sql
+++ b/sql/modules/Person.sql
@@ -129,11 +129,12 @@ DECLARE
BEGIN
SELECT cc.* into v_orig
- FROM contact_class cc, person p
+ FROM person_to_contact cc, person p
WHERE p.entity_id = in_entity_id
- and contact_class = in_contact_class
- AND contact = in_contact_orig
+ and cc.contact_class_id = in_contact_class
+ AND cc.contact = in_contact_orig
AND cc.person_id = p.id;
+
IF NOT FOUND THEN
-- create
@@ -163,6 +164,7 @@ $$ LANGUAGE PLPGSQL;
create or replace function person__save_location(
in_entity_id int,
in_location_id int,
+ in_location_class int,
in_line_one text,
in_line_two text,
in_line_three text,
@@ -197,8 +199,8 @@ create or replace function person__save_location(
in_country_code);
INSERT INTO person_to_location
- (person_id, location_id)
- VALUES (t_person_id, l_id);
+ (person_id, location_id, location_class)
+ VALUES (t_person_id, l_id, in_location_class);
ELSE
l_id := location_save(
in_location_id,