Bank statement for on has been approved!
Clear date Transaction Type Our Balance Their Balance Error Corrections Error Code
summaryrefslogtreecommitdiff
path: root/bin/admin.pl
blob: 5a89da020d3a6618c7a9cf70d439cd491c57b263 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # Copyright (C) 2006
  8. # This work contains copyrighted information from a number of sources all used
  9. # with permission.
  10. #
  11. # This file contains source code included with or based on SQL-Ledger which
  12. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  13. # under the GNU General Public License version 2 or, at your option, any later
  14. # version. For a full list including contact information of contributors,
  15. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  16. #
  17. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  18. # Copyright (c) 2000
  19. #
  20. # Author: DWS Systems Inc.
  21. # Web: http://www.sql-ledger.org
  22. #
  23. # Contributors:
  24. #
  25. #
  26. #======================================================================
  27. #
  28. # This file has undergone whitespace cleanup.
  29. #
  30. #======================================================================
  31. #
  32. # setup module
  33. # add/edit/delete users
  34. #
  35. #======================================================================
  36. use LedgerSMB::Form;
  37. use LedgerSMB::Locale;
  38. use LedgerSMB::User;
  39. use LedgerSMB::Session;
  40. $form = new Form;
  41. $locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
  42. or
  43. $form->error( __FILE__ . ':' . __LINE__ . ': ' . "Locale not loaded: $!\n" );
  44. $locale->encoding('UTF-8');
  45. $form->{charset} = 'UTF-8';
  46. eval { require DBI; };
  47. $form->error(
  48. __FILE__ . ':' . __LINE__ . ': ' . $locale->text('DBI not installed!') )
  49. if ($@);
  50. $form->{stylesheet} = "ledgersmb.css";
  51. $form->{favicon} = "favicon.ico";
  52. $form->{timeout} = 600;
  53. require "bin/pw.pl";
  54. # customization
  55. if ( -f "bin/custom/$form->{script}" ) {
  56. eval { require "bin/custom/$form->{script}"; };
  57. $form->error( __FILE__ . ':' . __LINE__ . ': ' . $@ ) if ($@);
  58. }
  59. if ( $form->{action} ) {
  60. &check_password unless $form->{action} eq 'logout';
  61. &{ $form->{action} };
  62. }
  63. else {
  64. # if there are no drivers bail out
  65. $form->error( __FILE__ . ':' . __LINE__ . ': '
  66. . $locale->text('No Database Drivers available!') )
  67. unless ( LedgerSMB::User->dbdrivers );
  68. $root = LedgerSMB::User->new('admin');
  69. &adminlogin;
  70. }
  71. 1;
  72. # end
  73. sub adminlogin {
  74. my ($errorMessage) = @_;
  75. $form->{title} =
  76. qq|LedgerSMB $form->{version} | . $locale->text('Administration');
  77. $myheaderadd = qq|
  78. <script language="JavaScript" type="text/javascript">
  79. <!--
  80. function sf(){
  81. document.admin.password.focus();
  82. }
  83. // End -->
  84. </script>
  85. |;
  86. $form->header( undef, $myheaderadd );
  87. print qq|
  88. <body class="admin" onload="sf()">
  89. <div align="center">
  90. <a href="http://www.ledgersmb.org/"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  91. <h1 class="login">|
  92. . $locale->text('Version')
  93. . qq| $form->{version} <br />|
  94. . $locale->text('Administration')
  95. . qq|</h1>
  96. <form method="post" action="admin.pl" name="admin">
  97. <table>
  98. <tr>
  99. <th>| . $locale->text('Password') . qq|</th>
  100. <td><input type="password" name="password" /></td>
  101. <td><button type="submit" class="submit" name="action" value="login">|
  102. . $locale->text('Login')
  103. . qq|</button></td>
  104. </tr>
  105. </table>
  106. <input type="hidden" name="action" value="login" />
  107. <input type="hidden" name="path" value="$form->{path}" />
  108. </form>
  109. |;
  110. if ($errorMessage) {
  111. print
  112. qq|<p><span style="font-weight:bold; color:red;">$errorMessage</span></p><br />|;
  113. }
  114. print qq|
  115. <br /><br />
  116. <p><a href="login.pl"
  117. >| . $locale->text("Application Login") . qq|</a></p>
  118. <br /><br />
  119. <a style="font-size: 0.8em;" href="http://www.ledgersmb.org/">|
  120. . $locale->text('LedgerSMB website') . qq|</a>
  121. </div>
  122. </body>
  123. </html>
  124. |;
  125. }
  126. sub login {
  127. &list_users;
  128. }
  129. sub logout {
  130. $form->{login} = 'admin';
  131. $form->{callback} = "admin.pl?action=adminlogin";
  132. Session::session_destroy($form);
  133. $form->redirect( $locale->text('You are logged out') );
  134. }
  135. sub add_user {
  136. $form->{title} =
  137. "LedgerSMB "
  138. . $locale->text('Accounting') . " "
  139. . $locale->text('Administration') . " / "
  140. . $locale->text('Add User');
  141. if ( -f "css/ledgersmb.css" ) {
  142. $myconfig->{stylesheet} = "ledgersmb.css";
  143. }
  144. $myconfig->{vclimit} = 1000;
  145. $myconfig->{menuwidth} = 155;
  146. $myconfig->{timeout} = 3600;
  147. &form_header;
  148. &form_footer;
  149. }
  150. sub edit {
  151. $form->{title} =
  152. "LedgerSMB "
  153. . $locale->text('Accounting') . " "
  154. . $locale->text('Administration') . " / "
  155. . $locale->text('Edit User');
  156. $form->{edit} = 1;
  157. &form_header;
  158. &form_footer;
  159. }
  160. sub form_footer {
  161. if ( $form->{edit} ) {
  162. $delete =
  163. qq|<button type="submit" class="submit" name="action" value="delete">|
  164. . $locale->text('Delete')
  165. . qq|</button>
  166. <input type="hidden" name="edit" value="1" />|;
  167. }
  168. print qq|
  169. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}" />
  170. <input type="hidden" name="path" value="$form->{path}" />
  171. <button type="submit" class="submit" name="action" value="save">|
  172. . $locale->text('Save')
  173. . qq|</button>
  174. $delete
  175. </form>
  176. </body>
  177. </html>
  178. |;
  179. }
  180. sub list_users {
  181. # use the central database handle
  182. my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
  183. my $fetchMembers = $dbh->selectall_arrayref(
  184. "SELECT uc.name, uc.company, uc.templates,
  185. uc.dbuser, uc.dbdriver, uc.dbname,
  186. uc.dbhost, u.username
  187. FROM users as u, users_conf as uc
  188. WHERE u.id = uc.id
  189. AND u.id > 1
  190. ORDER BY u.username;", { Slice => {} }
  191. );
  192. my @memberArray = ();
  193. my @member = ();
  194. foreach my $memberArray (@$fetchMembers) {
  195. $member{ $memberArray->{username} } = $memberArray;
  196. }
  197. # type=submit $locale->text('Pg Database Administration')
  198. # type=submit $locale->text('PgPP Database Administration')
  199. foreach $item ( LedgerSMB::User->dbdrivers ) {
  200. $dbdrivers .=
  201. qq|<button name="action" type="submit" class="submit" value="|
  202. . ( lc $item )
  203. . '_database_administration">'
  204. . $locale->text("$item Database Administration")
  205. . qq|</button>|;
  206. }
  207. $column_header{login} = qq|<th>| . $locale->text('Login') . qq|</th>|;
  208. $column_header{name} = qq|<th>| . $locale->text('Name') . qq|</th>|;
  209. $column_header{company} = qq|<th>| . $locale->text('Company') . qq|</th>|;
  210. $column_header{dbdriver} = qq|<th>| . $locale->text('Driver') . qq|</th>|;
  211. $column_header{dbhost} = qq|<th>| . $locale->text('Host') . qq|</th>|;
  212. $column_header{dataset} = qq|<th>| . $locale->text('Dataset') . qq|</th>|;
  213. $column_header{templates} =
  214. qq|<th>| . $locale->text('Templates') . qq|</th>|;
  215. @column_index = qw(login name company dbdriver dbhost dataset templates);
  216. $form->{title} =
  217. "LedgerSMB "
  218. . $locale->text('Accounting') . " "
  219. . $locale->text('Administration');
  220. $form->{login} = "admin";
  221. $form->header;
  222. print qq|
  223. <body class="admin">
  224. <form method="post" action="$form->{script}">
  225. <table width="100%">
  226. <tr class="listheading">
  227. <th>$form->{title}</th>
  228. </tr>
  229. <tr size="5"></tr>
  230. <tr>
  231. <td>
  232. <table width="100%">
  233. <tr class="listheading">|;
  234. for (@column_index) { print "$column_header{$_}\n" }
  235. print qq| </tr>|;
  236. foreach $key ( sort keys %member ) {
  237. $href = "$script?action=edit&amp;login=$key&amp;path=$form->{path}";
  238. $href =~ s/ /%20/g;
  239. $member{$key}{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
  240. $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
  241. $column_data{name} = qq|<td>$member{$key}{name}</td>|;
  242. $column_data{company} = qq|<td>$member{$key}{company}</td>|;
  243. $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
  244. $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
  245. $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
  246. $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
  247. $i++;
  248. $i %= 2;
  249. print qq| <tr class="listrow$i">|;
  250. for (@column_index) { print "$column_data{$_}\n"; }
  251. print qq| </tr>|;
  252. }
  253. print qq| </table>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td><hr size="3" noshade /></td>
  258. </tr>
  259. </table>
  260. <input type="hidden" name="path" value="$form->{path}" />
  261. <br />
  262. <button type="submit" class="submit" name="action" value="add_user">|
  263. . $locale->text('Add User')
  264. . qq|</button>
  265. <button type="submit" class="submit" name="action" value="change_admin_password">|
  266. . $locale->text('Change Admin Password')
  267. . qq|</button>
  268. $dbdrivers
  269. <button type="submit" class="submit" name="action" value="logout">|
  270. . $locale->text('Logout')
  271. . qq|</button>
  272. </form>
  273. | . $locale->text('Click on login name to edit!') . qq|
  274. <br />
  275. |
  276. . $locale->text(
  277. 'To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.'
  278. )
  279. . qq|
  280. </body>
  281. </html>|;
  282. }
  283. sub form_header {
  284. # if there is a login, get user
  285. if ( $form->{login} ) {
  286. # get user
  287. %{$myconfig} = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
  288. for (qw(company address signature)) {
  289. $myconfig->{$_} = $form->quote( $myconfig->{$_} );
  290. }
  291. for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
  292. # strip basedir from templates directory
  293. $myconfig->{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
  294. }
  295. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
  296. {
  297. $dateformat .=
  298. ( $item eq $myconfig->{dateformat} )
  299. ? "<option selected>$item</option>\n"
  300. : "<option>$item</option>\n";
  301. }
  302. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);