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