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