summaryrefslogtreecommitdiff
path: root/scripts/admin.pl
blob: 49274abf52278af7d4b23d29178674b5e58c6318 (plain)
  1. #!/usr/bin/perl
  2. package LedgerSMB::Scripts::admin;
  3. require 'lsmb-request.pl';
  4. use LedgerSMB::Template;
  5. use LedgerSMB::DBObject::Admin;
  6. use LedgerSMB::DBObject::User;
  7. sub new_user {
  8. # uses the same page as create_user, only pre-populated.
  9. #my ($class, $request) = @_;
  10. my $request = shift @_;
  11. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
  12. my $sal = $admin->get_salutations();
  13. if ($request->type() eq 'POST') {
  14. # do the save stuff
  15. my $entity = $admin->save_user();
  16. my $template = LedgerSMB::Template->new( user => $user,
  17. template => 'Admin/edit_user', language => $user->{ language },
  18. format => 'HTML', path=>'UI');
  19. $template->render(
  20. {
  21. user=>$entity,
  22. salutations=> $sal
  23. }
  24. );
  25. } else {
  26. my $template = LedgerSMB::Template->new( user => $user,
  27. template => 'Admin/edit_user', language => $user->{language},
  28. format => 'HTML', path=>'UI');
  29. $template->render(
  30. {
  31. salutations=>$sal
  32. }
  33. );
  34. }
  35. }
  36. sub edit_user {
  37. # uses the same page as create_user, only pre-populated.
  38. my ($class, $request) = @_;
  39. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
  40. my $edited_user = $admin->get_entire_user();
  41. my $all_roles = $admin->role_list();
  42. my $template = LedgerSMB::Template->new( user => $user,
  43. template => 'Admin/edit_user', language => $user->{language},
  44. format => 'HTML', path=>'UI');
  45. $template->render($edited_user, $all_roles);
  46. }
  47. sub edit_group {
  48. my ($class, $request) = @_;
  49. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
  50. my $all_roles = $admin->role_list();
  51. my $group = $admin->get_group();
  52. my $template = LedgerSMB::Template->new( user => $user,
  53. template => 'Admin/edit_group', language => $user->{language},
  54. format => 'HTML', path=>'UI');
  55. $template->render($all_roles);
  56. }
  57. sub create_group {
  58. my ($class, $request) = @_;
  59. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
  60. my $all_roles = $admin->role_list();
  61. my $template = LedgerSMB::Template->new( user => $user,
  62. template => 'Admin/edit_group', language => $user->{language},
  63. format => 'HTML', path=>'UI');
  64. $template->render($all_roles);
  65. }
  66. sub delete_group {
  67. my ($class, $request) = @_;
  68. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
  69. # requires the field modifying_user to be set.
  70. my $status = $admin->delete_group($request->{modifying_user});
  71. # status can either be 1, or an error.
  72. # if there's an error, $status->throw() is called by admin.pm. Or possibly
  73. # in the template itself.
  74. my $template = LedgerSMB::Template->new ( user=>$user,
  75. template=>'Admin/delete_group', language=>$user->{language},
  76. format=>'HTML', path=>'UI');
  77. $template->render($status);
  78. }
  79. sub delete_user {
  80. my ($class, $request) = @_;
  81. my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
  82. # requires the field modifying_user to be set.
  83. my $status = $admin->delete_user($request->{modifying_user});
  84. # status can either be 1, or an error.
  85. # if there's an error, $status->throw() is called by admin.pm. Or possibly
  86. # in the template itself.
  87. my $template = LedgerSMB::Template->new ( user=>$user,
  88. template=>'Admin/delete_user', language=>$user->{language},
  89. format=>'HTML', path=>'UI');
  90. $template->render($status);
  91. }
  92. sub new_group {
  93. my ($class, $request) = @_;
  94. my $template = LedgerSMB::Template->new( user=>$user,
  95. template=>'Admin/new_group', language=>$user->{language},
  96. format=>'HTML', path=>'UI');
  97. $template->render();
  98. }
  99. sub cancel {
  100. __default(@_);
  101. }
  102. sub __default {
  103. my ($class, $request) = @_;
  104. my $template;
  105. my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'all');
  106. $user->get_all_users();
  107. $template = LedgerSMB::Template->new( user=>$user,
  108. template=>'Admin/main', language=>$user->{language},
  109. format=>'HTML', path=>'UI');
  110. $template->render($user);
  111. }
  112. eval { do "scripts/custom/admin.pl"};
  113. 1;