summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2008-09-23 23:23:03 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2008-09-23 23:23:03 +0000
commit0a1573bd053a30b3ba2690fcf3545be02cb2eaa8 (patch)
treee449b9d1099e01686a6059720750ccd495ec45d8
parent9937eb3c4ef04f15ceb7cd1106d6bffb10304355 (diff)
Lots of fixes for editing users. Minor changes to Person.sql, specifically person__save_contact.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2339 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/DBObject/Admin.pm9
-rw-r--r--LedgerSMB/DBObject/Location.pm1
-rw-r--r--LedgerSMB/DBObject/User.pm16
-rw-r--r--UI/Admin/edit_user.html12
-rw-r--r--scripts/admin.pl60
-rw-r--r--sql/modules/Person.sql53
6 files changed, 107 insertions, 44 deletions
diff --git a/LedgerSMB/DBObject/Admin.pm b/LedgerSMB/DBObject/Admin.pm
index 5ab869b0..e16e5dea 100644
--- a/LedgerSMB/DBObject/Admin.pm
+++ b/LedgerSMB/DBObject/Admin.pm
@@ -264,4 +264,11 @@ sub get_countries {
$self->debug({file => '/tmp/user'});
return $self->{countries};
}
-1;
+sub get_contact_classes {
+
+ my $self = shift @_;
+ my $sth = $self->{dbh}->prepare("select id, class as classname from contact_class");
+ my $code = $sth->execute();
+ return $sth->fetchall_arrayref({});
+}
+1; \ No newline at end of file
diff --git a/LedgerSMB/DBObject/Location.pm b/LedgerSMB/DBObject/Location.pm
index 3deb967f..1b7e2699 100644
--- a/LedgerSMB/DBObject/Location.pm
+++ b/LedgerSMB/DBObject/Location.pm
@@ -69,5 +69,6 @@ sub get_all {
my $type = shift @_;
my @locations = $self->exec_method(funcname=>$type."__all_locations", args=>[$user_id]);
+ return \@locations;
}
1; \ No newline at end of file
diff --git a/LedgerSMB/DBObject/User.pm b/LedgerSMB/DBObject/User.pm
index 7682acbe..0ca6bcfc 100644
--- a/LedgerSMB/DBObject/User.pm
+++ b/LedgerSMB/DBObject/User.pm
@@ -141,4 +141,20 @@ sub roles {
}
+sub save_contact {
+
+ my $self = shift @_;
+ my $id = shift @_;
+ my $contact = shift @_;
+
+ 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 c77406a2..536b8ffa 100644
--- a/UI/Admin/edit_user.html
+++ b/UI/Admin/edit_user.html
@@ -195,11 +195,13 @@
<tr>
<td></td>
<td>
- <select name="class">
- <?lsmb FOREACH class IN contact_classes?>
- <option name="<?lsmb class.id?>" <?lsmb IF contact.contact_class_id == class.id?>selected<?lsmb END?>><?lsmb class.contact?></option>
- <?lsmb END?>
- </select>
+ <?lsmb PROCESS select element_data = {
+ name = "contact_class"
+ options = contact_classes
+ default_values = [contact.contact_class_id]
+ value_attr = "id"
+ text_attr = "classname"
+ } ?>
</td>
<td>
<input type="textarea" name="contact" value="<?lsmb contact.contact?>"/>
diff --git a/scripts/admin.pl b/scripts/admin.pl
index 9a09f40f..3a92425c 100644
--- a/scripts/admin.pl
+++ b/scripts/admin.pl
@@ -62,9 +62,9 @@ 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 = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
-
- $user->get($request->{user_id});
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
+ $user_obj->{company} = $request->{company};
+ $user_obj->get($request->{user_id});
my @all_roles = $admin->get_roles();
@@ -75,16 +75,19 @@ sub edit_user {
format => 'HTML',
path=>'UI'
);
-
+ my $location = LedgerSMB::DBObject::Location->new(base=>$request);
my $template_data =
{
- user=>$user,
+ user=>$user_obj,
roles=>@all_roles,
countries=>$admin->get_countries(),
- user_roles=>$user->{roles},
+ user_roles=>$user_obj->{roles},
salutations=>$admin->get_salutations(),
- locations=>$location->get_all($u_id,"person"),
+ contact_classes=>$admin->get_contact_classes(),
+ locations=>$location->get_all($user_obj->{entity_id},"person"),
};
+ print STDERR Dumper($template_data->{contact_classes});
+ print STDERR Dumper($template_data->{user_roles});
if ($request->type() eq 'POST') {
$admin->save_user();
@@ -94,10 +97,8 @@ sub edit_user {
else {
# print STDERR Dumper($user);
# print STDERR Dumper(@all_roles);
- my $loc;
- my $location = LedgerSMB::DBObject::Location->new(base=>$request);
if ($request->{location_id}) {
- $loc = $location->get($request->{location_id});
+ $template_data->{location} = $location->get($request->{location_id});
}
$template->render($template_data);
}
@@ -248,7 +249,7 @@ sub main {
$template->render( { users=>$user->{users} } );
}
-sub edit_contact {
+sub save_contact {
my $request = shift @_;
@@ -258,13 +259,39 @@ sub edit_contact {
# We have a contact ID, ie, something we made up.
my $c_id = $request->{contact_id};
my $u_id = $request->{user_id};
- my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
- $user->get($u_id);
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'list', merge=>['user_id','company']);
+ $user_obj->get($u_id);
# so we have a user object.
# ->{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->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);
}
}
@@ -293,13 +320,6 @@ sub delete_contact {
}
}
-sub new_contact {
-
- my $request = shift @_;
-
-
-}
-
sub save_location {
my $request = shift @_;
diff --git a/sql/modules/Person.sql b/sql/modules/Person.sql
index f942b137..546398e9 100644
--- a/sql/modules/Person.sql
+++ b/sql/modules/Person.sql
@@ -117,32 +117,49 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
+--
+
CREATE OR REPLACE FUNCTION person__save_contact
-(in_entity_id int, in_contact_class int, in_contact text)
+(in_entity_id int, in_contact_class int, in_contact_orig text, in_contact_new TEXT)
RETURNS INT AS
$$
-DECLARE out_id int;
+DECLARE
+ out_id int;
+ v_orig person_to_contact;
BEGIN
- INSERT INTO person_to_contact(person_id, contact_class_id, contact)
- SELECT id, in_contact_class, in_contact FROM person
- WHERE entity_id = in_entity_id;
-
- RETURN 1;
+
+ SELECT cc.* into v_orig
+ FROM contact_class cc, person p
+ WHERE p.entity_id = in_entity_id
+ and contact_class = in_contact_class
+ AND contact = in_contact_orig
+ AND cc.person_id = p.id;
+ IF NOT FOUND THEN
+
+ -- create
+ INSERT INTO person_to_contact(person_id, contact_class_id, contact)
+ VALUES (
+ (SELECT id FROM person WHERE entity_id = in_entity_id),
+ in_contact_class,
+ in_contact_new
+ );
+ return 1;
+ ELSE
+ -- edit.
+ UPDATE person_to_contact
+ SET contact = in_contact_new
+ WHERE
+ contact = in_contact_orig
+ AND person_id = v_orig.person_id
+ AND contact_class = in_contact_class;
+ return 0;
+ END IF;
+
END;
$$ LANGUAGE PLPGSQL;
+--
-/*(
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown)
-
-*/
create or replace function person__save_location(
in_entity_id int,
in_location_id int,