[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1589] trunk



Revision: 1589
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1589&view=rev
Author:   aurynn_cmd
Date:     2007-09-13 15:08:33 -0700 (Thu, 13 Sep 2007)

Log Message:
-----------
Adding dbobject/admin.pm

Modified Paths:
--------------
    trunk/sql/Pg-database.sql

Added Paths:
-----------
    trunk/LedgerSMB/DBObject/Admin.pm

Added: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	                        (rev 0)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2007-09-13 22:08:33 UTC (rev 1589)
@@ -0,0 +1,182 @@
+package LedgerSMB::DBObject::Admin;
+
+use base LedgerSMB::DBObject;
+
+use LedgerSMB::Location;
+use LedgerSMB::DBObject::Employee;
+use LedgerSMB::Contact;
+
+sub save_user {
+    
+    my $self = shift @_;
+    
+    my $entity_id = shift @{ $self->exec_method( procname => "save_user" ) };
+    $self->merge($entity_id);
+    
+    my $employee = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'list',
+        merge=>[
+            'salutation',
+            'first_name',
+            'last_name',
+            'employeenumber',
+        ]    
+    );
+    
+    $employee->{entity_id} = $entity_id->{id};    
+    $employee->save_employee();
+        
+    my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list', 
+        merge=>[
+            'address1',
+            'address2',
+            'city',
+            'state',
+            'zipcode',
+            'country',
+            'companyname',            
+        ]
+    );
+    $loc->save_location();
+    $loc->join_to_person(person=>$employee);
+    
+    
+    my $workphone = LedgerSMB::Contact->new(base=>$self);
+    my $homephone = LedgerSMB::Contact->new(base=>$self);
+    my $email = LedgerSMB::Contact->new(base=>$self);
+    
+    $workphone->set(person=>$employee, class=>1, contact=>$self->{workphone});
+    $homephone->set(person=>$employee, class=>11, contact=>$self->{homephone});
+    $email->set(person=>$employee, class=>12, contact=>$self->{email});
+    $workphone->save();
+    $homephone->save();
+    $email->save();
+    
+    my $roles = $self->exec_method( procname => "all_roles" );
+    my $user_roles = $self->exec_method(procname => "get_user_roles", args=>[ $self->{ modifying_user } ] );
+    
+    my %active_roles;
+    for my $role (@{$user_roles}) {
+       
+       # These are our user's roles.
+        
+       $active_roles{$role} = 1;
+    }
+    
+    my $status;
+    
+    for my $role ( @{ $roles } ) {
+        
+        # These roles are were ALL checked on the page, so they're the active ones.
+        
+        if ($active_roles{$role} && $self->{incoming_roles}->{$role}) {
+            
+            # do nothing.
+        }
+        elsif ($active_roles{$role} && !($self->{incoming_roles}->{$role} )) {
+            
+            # do remove function
+            $status = $self->exec_method(procname => "remove_user_from_role",
+                args=>[ $self->{ modifying_user }, $role ] 
+        }
+        elsif ($self->{incoming_roles}->{$role} and !($active_roles{$role} )) {
+            
+            # do add function
+            $status = $self->exec_method(procname => "add_user_to_role",
+               args=>[ $self->{ modifying_user }, $role ] 
+            );
+        }         
+    }
+}
+
+sub save_group {
+    
+     my $self = shift @_;
+     
+     my $existant = shift @{ $self->exec_method (procname=> "is_group", args=>[$self->{modifying_group}]) };
+     
+     my $group = shift @{ $self->exec_method (procname=> "save_group") };
+     
+     # first we grab all roles
+     
+     my $roles = $self->exec_method( procname => "all_roles" );
+     my $user_roles = $self->exec_method(procname => "get_user_roles", 
+        args=>[ $self->{ group_name } ] 
+    );
+
+     my %active_roles;
+     for my $role (@{$user_roles}) {
+
+        # These are our user's roles.
+
+        $active_roles{$role} = 1;
+     }
+
+     my $status;
+
+     for my $role ( @{ $roles } ) {
+
+         # These roles are were ALL checked on the page, so they're the active ones.
+
+         if ($active_roles{$role} && $self->{incoming_roles}->{$role}) {
+
+             # we don't need to do anything.
+         }
+         elsif ($active_roles{$role} && !($self->{incoming_roles}->{$role} )) {
+
+             # do remove function
+             $status = $self->exec_method(
+                 procname => "remove_group_from_role",
+                 args=>[ $self->{ modifying_user }, $role ] 
+             );
+         }
+         elsif ($self->{incoming_roles}->{$role} and !($active_roles{$role} )) {
+
+             # do add function
+             $status = $self->exec_method(
+                 procname => "add_group_to_role",
+                 args=>[ $self->{ modifying_user }, $role ] 
+             );
+         }         
+     }     
+}
+
+
+sub delete_user {
+    
+    my $self = shift @_;
+    
+    my $status = shift @{ $self->exec_method(procname=>'delete_user', 
+        args=>[$self->{modifying_user}]) 
+    };
+    
+    if ($status) {
+        
+        return 1;
+    } else {
+        
+        my $error = LedgerSMB::Error->new("Delete user failed.");
+        $error->set_status($status);
+        return $error;
+    }
+}
+
+sub delete_group {
+    
+    my $self = shift @_;
+    
+    my $status = shift @{ $self->exec_method(procname=>'delete_group', 
+        args=>[$self->{groupname}]) }
+    ;
+    
+    if ($status) {
+        
+        return 1;
+    } else {
+        
+        my $error = LedgerSMB::Error->new("Delete group failed.");
+        $error->set_status($status);
+        return $error;
+    }
+}
+
+1;
\ No newline at end of file

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2007-09-13 22:05:20 UTC (rev 1588)
+++ trunk/sql/Pg-database.sql	2007-09-13 22:08:33 UTC (rev 1589)
@@ -6,8 +6,44 @@
 -- can be named anything.
 
 -- USERS stuff --
-CREATE TABLE users (id serial UNIQUE, username varchar(30) primary key);
+CREATE TABLE users (
+    id serial UNIQUE, 
+    username varchar(30) primary key
+    entity_id not null references entity(id) on delete cascade
+);
 COMMENT ON TABLE users IS $$username is the actual primary key here because we do not want duplicate users$$;
+
+create table user_connection (
+    user_id int not null references user(id) on delete cascade,
+    dbname text not null,
+    host text not null default 'localhost',
+    port int not null default '5432'
+);
+
+CREATE VIEW users_conf as
+    select 
+        user.id, 
+        loc.address1 || '\n'|| loc.address2 ||'\n' || loc.address3,
+        em.employeenumber,
+        company,
+        loc.country,
+        currency,
+        dateformat,
+        'Pg',
+        u_cx.host
+        u_cx.dbname,
+        u_cx.dbport,
+        user.username,
+        p.email,
+        p.fax,
+        50,
+        p.first_name || ' ' || p.last_name,
+        p.number_format,
+        '', -- password
+        
+        
+;
+
 CREATE TABLE users_conf(id integer primary key references users(id) deferrable initially deferred,
                         acs text,
                         address text,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.