summaryrefslogtreecommitdiff
path: root/bin/admin.pl
blob: ce96cd6e6fa9a97bea9a130c1fee7361cbdee028 (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. $menufile = "menu.ini";
  37. use LedgerSMB::Form;
  38. use LedgerSMB::Locale;
  39. use LedgerSMB::User;
  40. $form = new Form;
  41. $locale = LedgerSMB::Locale->get_handle($language);
  42. $locale->encoding('UTF-8');
  43. $form->{charset} = 'UTF-8';
  44. #$form->{charset} = $locale->encoding;
  45. eval { require DBI; };
  46. $form->error($locale->text('DBI not installed!')) if ($@);
  47. $form->{stylesheet} = "ledger-smb.css";
  48. $form->{favicon} = "favicon.ico";
  49. $form->{timeout} = 600;
  50. require "bin/pw.pl";
  51. # customization
  52. if (-f "bin/custom/$form->{script}") {
  53. eval { require "bin/custom/$form->{script}"; };
  54. $form->error($@) if ($@);
  55. }
  56. if ($form->{action}) {
  57. &check_password unless $form->{action} eq 'logout';
  58. &{ $form->{action} };
  59. } else {
  60. # if there are no drivers bail out
  61. $form->error($locale->text('No Database Drivers available!')) unless (User->dbdrivers);
  62. # create memberfile
  63. if (! -f $memberfile) {
  64. open(FH, ">$memberfile") or $form->error("$memberfile : $!");
  65. print FH qq|# LedgerSMB Accounting members
  66. [root login]
  67. password=
  68. |;
  69. close FH;
  70. }
  71. $root = new User "$memberfile", "root login";
  72. unless($root && $root->{password}) {
  73. &setup_initial_password();
  74. exit;
  75. }
  76. &adminlogin;
  77. }
  78. 1;
  79. # end
  80. sub setup_initial_password {
  81. $form->header();
  82. print qq|
  83. <body class="admin" onload="sf()">
  84. <div align="center">
  85. <a href="http://www.ledgersmb.org/"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  86. <h1 class="login">|.$locale->text('Version').qq| $form->{version} <br />|.$locale->text('Administration').qq|</h1>
  87. <fieldset><legend>Change password</legend>
  88. <p>This is your first time logging into LedgerSMB. Please set your administrative password</p>
  89. <form method="post" action="$form->{script}" name="admin">
  90. <table>
  91. <tr>
  92. <th align="right">|.$locale->text('Password').qq|</th>
  93. <td><input type="password" name="new_password" /></td>
  94. </tr>
  95. <tr>
  96. <th align="right">|.$locale->text('Confirm').qq|</th>
  97. <td><input type="password" name="confirm_password" /></td>
  98. </tr>
  99. </table>
  100. <input type="hidden" name="path" value="$form->{path}" />
  101. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  102. <p><button type="submit" class="submit" name="action" value="change_password">|.$locale->text('Change Password').qq|</button></p>
  103. </form>
  104. <a href="http://www.ledgersmb.org/">LedgerSMB |.$locale->text('website').qq|</a>
  105. </div>
  106. </body>
  107. </html>
  108. |;
  109. }
  110. sub adminlogin {
  111. $form->{title} = qq|LedgerSMB $form->{version} |.$locale->text('Administration');
  112. $myheaderadd = qq|
  113. <script language="JavaScript" type="text/javascript">
  114. <!--
  115. function sf(){
  116. document.admin.password.focus();
  117. }
  118. // End -->
  119. </script>
  120. |;
  121. $form->header(undef, $myheaderadd);
  122. print qq|
  123. <body class="admin" onload="sf()">
  124. <div align="center">
  125. <a href="http://www.ledgersmb.org/"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  126. <h1 class="login">|.$locale->text('Version').qq| $form->{version} <br />|.$locale->text('Administration').qq|</h1>
  127. <form method="post" action="$form->{script}" name="admin">
  128. <table>
  129. <tr>
  130. <th>|.$locale->text('Password').qq|</th>
  131. <td><input type="password" name="password" /></td>
  132. <td><button type="submit" class="submit" name="action" value="login">|.$locale->text('Login').qq|</button></td>
  133. </tr>
  134. </table>
  135. <input type="hidden" name="action" value="login" />
  136. <input type="hidden" name="path" value="$form->{path}" />
  137. </form>
  138. <p><a href="login.pl"
  139. >|.$locale->text("Application Login").qq|</a></p>
  140. <a href="http://www.ledgersmb.org/">LedgerSMB |.$locale->text('website').qq|</a>
  141. </div>
  142. </body>
  143. </html>
  144. |;
  145. }
  146. sub login {
  147. &list_users;
  148. }
  149. sub logout {
  150. $form->{callback} = "$form->{script}?path=$form->{path}&amp;endsession=1";
  151. unlink "$userspath/adminhash";
  152. print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
  153. $form->redirect($locale->text('You are logged out'));
  154. }
  155. sub add_user {
  156. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User');
  157. if (-f "css/ledger-smb.css") {
  158. $myconfig->{stylesheet} = "ledger-smb.css";
  159. }
  160. $myconfig->{vclimit} = 1000;
  161. $myconfig->{menuwidth} = 155;
  162. $myconfig->{timeout} = 3600;
  163. &form_header;
  164. &form_footer;
  165. }
  166. sub edit {
  167. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User');
  168. $form->{edit} = 1;
  169. &form_header;
  170. &form_footer;
  171. }
  172. sub form_footer {
  173. if ($form->{edit}) {
  174. $delete = qq|<button type="submit" class="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>
  175. <input type="hidden" name="edit" value="1" />|;
  176. }
  177. print qq|
  178. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  179. <input type="hidden" name="path" value="$form->{path}" />
  180. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  181. <button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
  182. $delete
  183. </form>
  184. </body>
  185. </html>
  186. |;
  187. }
  188. sub list_users {
  189. open(FH, "$memberfile") or $form->error("$memberfile : $!");
  190. $nologin = qq|<button type="submit" class="submit" name="action" value="lock_system">|.$locale->text('Lock System').qq|</button>|;
  191. if (-e "$userspath/nologin") {
  192. $nologin = qq|<button type="submit" class="submit" name="action" value="unlock_system">|.$locale->text('Unlock System').qq|</button>|;
  193. }
  194. while (<FH>) {
  195. chop;
  196. if (/^\[.*\]/) {
  197. $login = $_;
  198. $login =~ s/(\[|\])//g;
  199. }
  200. if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
  201. chop ($var = $&);
  202. ($null, $member{$login}{$var}) = split /=/, $_, 2;
  203. }
  204. }
  205. close(FH);
  206. # type=submit $locale->text('Pg Database Administration')
  207. # type=submit $locale->text('PgPP Database Administration')
  208. foreach $item (User->dbdrivers) {
  209. $dbdrivers .= qq|<button name="action" type="submit" class="submit" value="|.(lc $item).'_database_administration">'.$locale->text("$item Database Administration").qq|</button>|;
  210. }
  211. $column_header{login} = qq|<th>|.$locale->text('Login').qq|</th>|;
  212. $column_header{name} = qq|<th>|.$locale->text('Name').qq|</th>|;
  213. $column_header{company} = qq|<th>|.$locale->text('Company').qq|</th>|;
  214. $column_header{dbdriver} = qq|<th>|.$locale->text('Driver').qq|</th>|;
  215. $column_header{dbhost} = qq|<th>|.$locale->text('Host').qq|</th>|;
  216. $column_header{dataset} = qq|<th>|.$locale->text('Dataset').qq|</th>|;
  217. $column_header{templates} = qq|<th>|.$locale->text('Templates').qq|</th>|;
  218. @column_index = qw(login name company dbdriver dbhost dataset templates);
  219. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration');
  220. $form->{login} = "root login";
  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}&amp;sessionid=$form->{sessionid}";
  238. $href =~ s/ /%20/g;
  239. $member{$key}{templates} =~ s/^$templates\///;
  240. $member{$key}{dbhost} = $locale->text('localhost') unless $member{$key}{dbhost};
  241. $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
  242. $column_data{name} = qq|<td>$member{$key}{name}</td>|;
  243. $column_data{company} = qq|<td>$member{$key}{company}</td>|;
  244. $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
  245. $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
  246. $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
  247. $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
  248. $i++; $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. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  262. <br />
  263. <button type="submit" class="submit" name="action" value="add_user">|.$locale->text('Add User').qq|</button>
  264. <button type="submit" class="submit" name="action" value="change_admin_password">|.$locale->text('Change Admin Password').qq|</button>
  265. $dbdrivers
  266. $nologin
  267. <button type="submit" class="submit" name="action" value="logout">|.$locale->text('Logout').qq|</button>
  268. </form>
  269. |.$locale->text('Click on login name to edit!').qq|
  270. <br />
  271. |.$locale->text('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.').qq|
  272. </body>
  273. </html>|;
  274. }
  275. sub form_header {
  276. # if there is a login, get user
  277. if ($form->{login}) {
  278. # get user
  279. $myconfig = new User "$memberfile", "$form->{login}";
  280. for (qw(company address signature)) { $myconfig->{$_} = $form->quote($myconfig->{$_}) }
  281. for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
  282. # strip basedir from templates directory
  283. $myconfig->{templates} =~ s/^$templates\///;
  284. $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
  285. }
  286. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
  287. $dateformat .= ($item eq $myconfig->{dateformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
  288. }
  289. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  290. push @formats, '1 000.00';
  291. foreach $item (@formats) {
  292. $numberformat .= ($item eq $myconfig->{numberformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
  293. }
  294. %countrycodes = User->country_codes;
  295. $countrycodes = "";
  296. foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
  297. $countrycodes .= ($myconfig->{countrycode} eq $key) ? qq|<option selected value="$key">$countrycodes{$key}</option>|
  298. : qq|<option value="$key">$countrycodes{$key}</option>|;
  299. }
  300. $countrycodes = qq|<option value="">English</option>\n$countrycodes|;
  301. # is there a templates basedir
  302. if (! -d "$templates") {
  303. $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
  304. }
  305. opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
  306. @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
  307. closedir TEMPLATEDIR;
  308. @allhtml = sort grep /\.html/, @all;
  309. @alldir = ();
  310. for (@all) {
  311. if (-d "$templates/$_") {
  312. push @alldir, $_;
  313. }
  314. }
  315. @allhtml = reverse grep !/Default/, @allhtml;
  316. push @allhtml, 'Default';
  317. @allhtml = reverse @allhtml;
  318. foreach $item (sort @alldir) {
  319. if ($item eq $myconfig->{templates}) {
  320. $usetemplates .= qq|<option selected value="$item">$item</option>\n|;
  321. } else {
  322. $usetemplates .= qq|<option value="$item">$item</option>\n|;
  323. }
  324. }
  325. $lastitem = $allhtml[0];
  326. $lastitem =~ s/-.*//g;
  327. $mastertemplates = qq|<option value="$lastitem">$lastitem</option>\n|;
  328. foreach $item (@allhtml) {
  329. $item =~ s/-.*//g;
  330. if ($item ne $lastitem) {
  331. $mastertemplates .= qq|<option value="$item">$item</option>\n|;
  332. $lastitem = $item;
  333. }
  334. }
  335. opendir CSS, "css/.";
  336. @all = grep /.*\.css$/, readdir CSS;
  337. closedir CSS;
  338. foreach $item (@all) {
  339. if ($item eq $myconfig->{stylesheet}) {
  340. $selectstylesheet .= qq|<option selected value="$item">$item</option>\n|;
  341. } else {
  342. $selectstylesheet .= qq|<option value="$item">$item</option>\n|;
  343. }
  344. }
  345. $selectstylesheet .= "<option></option>\n";
  346. if (%printer && $latex) {
  347. $selectprinter = "<option></option>\n";
  348. foreach $item (sort keys %printer) {
  349. if ($myconfig->{printer} eq $item) {
  350. $selectprinter .= qq|<option value="$item" selected>$item</option>\n|;
  351. } else {
  352. $selectprinter .= qq|<option value="$item">$item</option>\n|;
  353. }
  354. }
  355. $printer = qq|
  356. <tr>
  357. <th align="right">|.$locale->text('Printer').qq|</th>
  358. <td><select name="printer">$selectprinter</select></td>
  359. </tr>
  360. |;
  361. }
  362. $user = $form->{login};
  363. $form->{login} = "root login";
  364. $form->header;
  365. $form->{login} = $user;
  366. print qq|
  367. <body class="admin">
  368. <form method="post" action="$form->{script}">
  369. <table width="100%">
  370. <tr class="listheading"><th colspan="2">$form->{title}</th></tr>
  371. <tr size="5"></tr>
  372. <tr valign="top">
  373. <td>
  374. <table>
  375. <tr>
  376. <th align="right">|.$locale->text('Login').qq|</th>
  377. <td><input name="login" value="$myconfig->{login}" /></td>
  378. </tr>
  379. <tr>
  380. <th align="right">|.$locale->text('Password').qq|</th>
  381. <td><input type="password" name="new_password" size="8" value="$myconfig->{password}" /></td>
  382. <input type="hidden" name="old_password" value="$myconfig->{password}" />
  383. </tr>
  384. <tr>
  385. <th align="right">|.$locale->text('Name').qq|</th>
  386. <td><input name="name" size="15" value="$myconfig->{name}" /></td>
  387. </tr>
  388. <tr>
  389. <th align="right">|.$locale->text('E-mail').qq|</th>
  390. <td><input name="email" size="30" value="$myconfig->{email}" /></td>
  391. </tr>
  392. <tr valign="top">
  393. <th align="right">|.$locale->text('Signature').qq|</th>
  394. <td><textarea name="signature" rows="3" cols="35">$myconfig->{signature}</textarea></td>
  395. </tr>
  396. <tr>
  397. <th align="right">|.$locale->text('Phone').qq|</th>
  398. <td><input name="tel" size="14" value="$myconfig->{tel}" /></td>
  399. </tr>
  400. <tr>
  401. <th align="right">|.$locale->text('Fax').qq|</th>
  402. <td><input name="fax" size="14" value="$myconfig->{fax}" /></td>
  403. </tr>
  404. <tr>
  405. <th align="right">|.$locale->text('Company').qq|</th>
  406. <td><input name="company" size="35" value="$myconfig->{company}" /></td>
  407. </tr>
  408. <tr valign="top">
  409. <th align="right">|.$locale->text('Address').qq|</th>
  410. <td><textarea name="address" rows="4" cols="35">$myconfig->{address}</textarea></td>
  411. </tr>
  412. </table>
  413. </td>
  414. <td>
  415. <table>
  416. <tr>
  417. <th align="right">|.$locale->text('Date Format').qq|</th>
  418. <td><select name="dateformat">$dateformat</select></td>
  419. </tr>
  420. <tr>
  421. <th align="right">|.$locale->text('Number Format').qq|</th>
  422. <td><select name="numberformat">$numberformat</select></td>
  423. </tr>
  424. <tr>
  425. <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
  426. <td><input name="vclimit" value="$myconfig->{vclimit}" /></td>
  427. </tr>
  428. <tr>
  429. <th align="right">|.$locale->text('Menu Width').qq|</th>
  430. <td><input name="menuwidth" value="$myconfig->{menuwidth}" /></td>
  431. </tr>
  432. <tr>
  433. <th align="right">|.$locale->text('Language').qq|</th>
  434. <td><select name="countrycode">$countrycodes</select></td>
  435. </tr>
  436. <tr>
  437. <th align="right">|.$locale->text('Session Timeout').qq|</th>
  438. <td><input name="newtimeout" value="$myconfig->{timeout}" /></td>
  439. </tr>
  440. <tr>
  441. <th align="right">|.$locale->text('Stylesheet').qq|</th>
  442. <td><select name="userstylesheet">$selectstylesheet</select></td>
  443. </tr>
  444. $printer
  445. <tr>
  446. <th align="right">|.$locale->text('Use Templates').qq|</th>
  447. <td><select name="usetemplates">$usetemplates</select></td>
  448. </tr>
  449. <tr>
  450. <th align="right">|.$locale->text('New Templates').qq|</th>
  451. <td><input name="newtemplates" /></td>
  452. </tr>
  453. <tr>
  454. <th align="right">|.$locale->text('Setup Templates').qq|</th>
  455. <td><select name="mastertemplates">$mastertemplates</select></td>
  456. </tr>
  457. </table>
  458. <input type="hidden" name="templates" value="$myconfig->{templates}" />
  459. </td>
  460. </tr>
  461. <tr class="listheading">
  462. <th colspan="2">|.$locale->text('Database').qq|</th>
  463. </tr>|;
  464. # list section for database drivers
  465. foreach $item (User->dbdrivers) {
  466. print qq|
  467. <tr>
  468. <td colspan="2">
  469. <table>
  470. <tr>|;
  471. $checked = "checked";
  472. if ($myconfig->{dbdriver} eq $item) {
  473. for (qw(dbhost dbport dbuser dbpasswd dbname sid)) { $form->{"${item}_$_"} = $myconfig->{$_} }
  474. $checked = "checked";
  475. }
  476. print qq|
  477. <th align="right">|.$locale->text('Driver').qq|</th>
  478. <td><input name="dbdriver" type="radio" class="radio" value="$item" $checked />&nbsp;$item</td>
  479. <th align="right">|.$locale->text('Host').qq|</th>
  480. <td><input name="${item}_dbhost" size="30" value="$form->{"${item}_dbhost"}" /></td>
  481. </tr>
  482. <tr>|;
  483. print qq|
  484. <th align="right">|.$locale->text('Dataset').qq|</th>
  485. <td><input name="${item}_dbname" size="15" value="$form->{"${item}_dbname"}" /></td>
  486. <th align="right">|.$locale->text('Port').qq|</th>
  487. <td><input name="${item}_dbport" size="4" value="$form->{"${item}_dbport"}" /></td>
  488. </tr>
  489. <tr>
  490. <th align="right">|.$locale->text('User').qq|</th>
  491. <td><input name="${item}_dbuser" size="15" value="$form->{"${item}_dbuser"}" /></td>
  492. <th align="right">|.$locale->text('Password').qq|</th>
  493. <td><input name="${item}_dbpasswd" type="password" size="10" value="$form->{"${item}_dbpasswd"}" /></td>
  494. </tr>|;
  495. print qq|
  496. </table>
  497. <input type="hidden" name="old_dbpasswd" value="$myconfig->{dbpasswd}" />
  498. </td>
  499. </tr>
  500. <tr>
  501. <td colspan="2"><hr size="2" noshade /></td>
  502. </tr>
  503. |;
  504. }
  505. # access control
  506. open(FH, $menufile) or $form->error("$menufile : $!");
  507. # scan for first menu level
  508. @a = <FH>;
  509. close(FH);
  510. if (open(FH, "custom_$menufile")) {
  511. push @a, <FH>;
  512. }
  513. close(FH);
  514. foreach $item (@a) {
  515. next unless $item =~ /\[\w+/;
  516. next if $item =~ /\#/;
  517. $item =~ s/(\[|\])//g;
  518. chop $item;
  519. if ($item =~ /--/) {
  520. ($level, $menuitem) = split /--/, $item, 2;
  521. } else {
  522. $level = $item;
  523. $menuitem = $item;
  524. push @acsorder, $item;
  525. }
  526. push @{ $acs{$level} }, $menuitem;
  527. }
  528. %role = ( 'admin' => $locale->text('Administrator'),
  529. 'user' => $locale->text('User'),
  530. 'supervisor' => $locale->text('Supervisor'),
  531. 'manager' => $locale->text('Manager'));
  532. $selectrole = "";
  533. foreach $item (qw(user admin supervisor manager)) {
  534. $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=\"$item\">$role{$item}</option>\n"
  535. : "<option value=\"$item\">$role{$item}</option>\n";
  536. }
  537. print qq|
  538. <tr class="listheading">
  539. <th colspan="2">|.$locale->text('Access Control').qq|</th>
  540. </tr>
  541. <tr>
  542. <td><select name="role">$selectrole</select></td>
  543. </tr>
  544. |;
  545. foreach $item (split /;/, $myconfig->{acs}) {
  546. ($key, $value) = split /--/, $item, 2;
  547. $excl{$key}{$value} = 1;
  548. }
  549. foreach $key (@acsorder) {
  550. $checked = "checked";
  551. if ($form->{login}) {
  552. $checked = ($excl{$key}{$key}) ? "" : "checked";
  553. }
  554. # can't have variable names with & and spaces
  555. $item = $form->escape("${key}--$key",1);
  556. $acsheading = $key;
  557. $acsheading =~ s/ /&nbsp;/g;
  558. $acsheading = qq|
  559. <td align="left" nowrap="nowrap" style="background-color: #C7E9F7" colspan="2">
  560. <input name="$item" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$acsheading</td><tr><td>\n|;
  561. $menuitems .= "$item;";
  562. $acsdata = "<td style=\"background-color: #F0F0F0\">";
  563. foreach $item (@{ $acs{$key} }) {
  564. next if ($key eq $item);
  565. $checked = "checked";
  566. if ($form->{login}) {
  567. $checked = ($excl{$key}{$item}) ? "" : "checked";
  568. }
  569. $acsitem = $form->escape("${key}--$item",1);
  570. $acsdata .= qq|<br /><input name="$acsitem" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$item|;
  571. $menuitems .= "$acsitem;";
  572. }
  573. $acsdata .= "
  574. </td>";
  575. print qq|
  576. <tr valign="top">$acsheading $acsdata
  577. </tr>
  578. |;
  579. }
  580. print qq|<input type="hidden" name="acs" value="$menuitems" />
  581. <tr>
  582. <td colspan="2"><hr size="3" noshade /></td>
  583. </tr>
  584. </table>
  585. </div>
  586. |;
  587. }
  588. sub save {
  589. # no driver checked
  590. $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver};
  591. # no spaces allowed in login name
  592. $form->{login} =~ s/ //g;
  593. $form->isblank("login", $locale->text('Login name missing!'));
  594. # check for duplicates
  595. if (!$form->{edit}) {
  596. $temp = new User "$memberfile", "$form->{login}";
  597. if ($temp->{login}) {
  598. $form->error("$form->{login} ".$locale->text('is already a member!'));
  599. }
  600. }
  601. # no spaces allowed in directories
  602. $form->{newtemplates} =~ s/( |\.\.|\*)//g;
  603. if ($form->{newtemplates} ne "") {
  604. $form->{templates} = $form->{newtemplates};
  605. } else {
  606. $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
  607. }
  608. # is there a basedir
  609. if (! -d "$templates") {
  610. $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
  611. }
  612. # add base directory to $form->{templates}
  613. $form->{templates} = "$templates/$form->{templates}";
  614. $myconfig = new User "$memberfile", "$form->{login}";
  615. # redo acs variable and delete all the acs codes
  616. @acs = split /;/, $form->{acs};
  617. $form->{acs} = "";
  618. foreach $item (@acs) {
  619. $item = $form->escape($item,1);
  620. if (!$form->{$item}) {
  621. $form->{acs} .= $form->unescape($form->unescape("$item")).";";
  622. }
  623. delete $form->{$item};
  624. }
  625. # check which database was filled in
  626. $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
  627. $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
  628. $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
  629. $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
  630. $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
  631. $form->isblank("dbname", $locale->text('Dataset missing!'));
  632. $form->isblank("dbuser", $locale->text('Database User missing!'));
  633. foreach $item (keys %{$form}) {
  634. $myconfig->{$item} = $form->{$item};
  635. }
  636. $myconfig->{password} = $form->{old_password};
  637. $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password};
  638. $myconfig->{timeout} = $form->{newtimeout};
  639. delete $myconfig->{stylesheet};
  640. if ($form->{userstylesheet}) {
  641. $myconfig->{stylesheet} = $form->{userstylesheet};
  642. }
  643. $myconfig->{packpw} = 1;
  644. $myconfig->save_member($memberfile, $userspath);
  645. # create user template directory and copy master files
  646. if (! -d "$form->{templates}") {
  647. umask(002);
  648. if (mkdir "$form->{templates}", oct("771")) {
  649. umask(007);
  650. # copy templates to the directory
  651. opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
  652. @templates = grep /$form->{mastertemplates}-/, readdir TEMPLATEDIR;
  653. closedir TEMPLATEDIR;
  654. foreach $file (@templates) {
  655. open(TEMP, "$templates/$file") or $form->error("$templates/$file : $!");
  656. $file =~ s/$form->{mastertemplates}-//;
  657. open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!");
  658. while ($line = <TEMP>) {
  659. print NEW $line;
  660. }
  661. close(TEMP);
  662. close(NEW);
  663. }
  664. } else {
  665. $form->error("$form->{templates} : $!");
  666. }
  667. }
  668. $form->redirect($locale->text('User saved!'));
  669. }
  670. sub delete {
  671. $form->{templates} = ($form->{templates}) ? "$templates/$form->{templates}" : "$templates/$form->{login}";
  672. $form->error("$memberfile ".$locale->text('locked!')) if (-f ${memberfile}.LCK);
  673. open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
  674. close(FH);
  675. if (! open(CONF, "+<$memberfile")) {
  676. unlink "${memberfile}.LCK";
  677. $form->error("$memberfile : $!");
  678. }
  679. @config = <CONF>;
  680. seek(CONF, 0, 0);
  681. truncate(CONF, 0);
  682. while ($line = shift @config) {
  683. chop $line;
  684. if ($line =~ /^\[/) {
  685. last if ($line eq "[$form->{login}]");
  686. $login = &login_name($line);
  687. }
  688. if ($line =~ /^templates=/) {
  689. ($null, $user{$login}) = split /=/, $line, 2;
  690. }
  691. print CONF "$line\n";
  692. }
  693. # remove everything up to next login or EOF
  694. # and save template variable
  695. while ($line = shift @config) {
  696. chop $line;
  697. ($key, $value) = split /=/, $line, 2;
  698. $myconfig{$key} = $value;
  699. last if ($line =~ /^\[/);
  700. }
  701. # this one is either the next login or EOF
  702. print CONF "$line\n";
  703. $login = &login_name($line);
  704. while ($line = shift @config) {
  705. chop $line;
  706. if ($line =~ /^\[/) {
  707. $login = &login_name($line);
  708. }
  709. if ($line =~ /^templates=/) {
  710. ($null, $user{$login}) = split /=/, $line, 2;
  711. }
  712. print CONF "$line\n";
  713. }
  714. close(CONF);
  715. unlink "${memberfile}.LCK";
  716. # scan %user for $templatedir
  717. foreach $login (keys %user) {
  718. last if ($found = ($form->{templates} eq $user{$login}));
  719. }
  720. # if found keep directory otherwise delete
  721. if (!$found) {
  722. # delete it if there is a template directory
  723. $dir = "$form->{templates}";
  724. if (-d "$dir") {
  725. unlink <$dir/*>;
  726. rmdir "$dir";
  727. }
  728. }
  729. if ($myconfig{dbconnect}) {
  730. $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
  731. for (keys %myconfig) { $form->{$_} = $myconfig{$_} }
  732. User->delete_login(\%$form);
  733. # delete config file for user
  734. unlink "$userspath/$form->{login}.conf";
  735. }
  736. $form->redirect($locale->text('User deleted!'));
  737. }
  738. sub login_name {
  739. my $login = shift;
  740. $login =~ s/\[\]//g;
  741. return ($login) ? $login : undef;
  742. }
  743. sub change_admin_password {
  744. $form->{title} = qq|LedgerSMB |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password');
  745. $form->{login} = "root login";
  746. $form->header;
  747. print qq|
  748. <body class="admin">
  749. <form method="post" action="$form->{script}">
  750. <table>
  751. <tr class="listheading">
  752. <th>|.$locale->text('Change Password').qq|</th>
  753. </tr>
  754. <tr size="5"></tr>
  755. <tr>
  756. <td>
  757. <table width="100%">
  758. <tr>
  759. <th align="right">|.$locale->text('Password').qq|</th>
  760. <td><input type="password" name="new_password" /></td>
  761. </tr>
  762. <tr>
  763. <th align="right">|.$locale->text('Confirm').qq|</th>
  764. <td><input type="password" name="confirm_password" /></td>
  765. </tr>
  766. </table>
  767. </td>
  768. </tr>
  769. </table>
  770. <br />
  771. <hr size="3" noshade />
  772. <input type="hidden" name="path" value="$form->{path}" />
  773. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  774. <p><button type="submit" class="submit" name="action" value="change_password">|.$locale->text('Change Password').qq|</button></p>
  775. </form>
  776. </body>
  777. </html>
  778. |;
  779. }
  780. sub change_password {
  781. $form->error($locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password};
  782. $root->{password} = $form->{new_password};
  783. $root->{'root login'} = 1;
  784. $root->save_member($memberfile);
  785. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  786. $form->redirect($locale->text('Password changed!'));
  787. }
  788. sub get_hash {
  789. use Digest::MD5;
  790. $form->{hash} = Digest::MD5::md5_hex rand();
  791. }
  792. sub check_password {
  793. $root = new User "$memberfile", "root login";
  794. if ($root->{password}) {
  795. if ($form->{password}) {
  796. $form->{callback} .= "&amp;password=$form->{password}" if $form->{callback};
  797. $form->{sessionid} = time;
  798. if ($root->{password} ne crypt $form->{password}, 'ro') {
  799. &getpassword;
  800. exit;
  801. }
  802. &get_hash;
  803. open(HASHFILE, "> $userspath/adminhash") || $form->error("Can't Open Hashfile: $!");
  804. print HASHFILE $form->{hash};
  805. print qq|Set-Cookie: LedgerSMB=$form->{hash}; path=/;\n|;
  806. } else {
  807. if ($ENV{HTTP_USER_AGENT}) {
  808. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  809. %cookie = split /[=;]/, $ENV{HTTP_COOKIE}; # Changeme to %cookies
  810. $cookie = ($form->{path} eq 'bin/lynx') ? $cookie{login} : $cookie{"LedgerSMB-root login"};
  811. #fixes problem with first login and such
  812. if (!(-f "$userspath/adminhash")) {
  813. &get_hash;
  814. open(HASHFILE, "> $userspath/adminhash") || $form->error("Can't Open Hashfile: $!");
  815. print HASHFILE $form->{hash};
  816. close(HASHFILE);
  817. }
  818. open (HASHFILE, "< $userspath/adminhash") || $form->error("Can't Open Hashfile: $!");
  819. chomp($form->{hash} = <HASHFILE>);
  820. %cookies = split /[=;]/, $ENV{HTTP_COOKIE};
  821. if (! $cookie || $cookie ne $form->{sessionid} || $form->{hash} ne $cookies{LedgerSMB}) {
  822. &getpassword;
  823. exit;
  824. }
  825. }
  826. }
  827. }
  828. }
  829. sub pg_database_administration {
  830. $form->{dbdriver} = 'Pg';
  831. &dbselect_source;
  832. }
  833. sub pgpp_database_administration {
  834. $form->{dbdriver} = 'PgPP';
  835. &dbselect_source;
  836. }
  837. sub dbdriver_defaults {
  838. # load some defaults for the selected driver
  839. %driverdefaults = ( 'Pg' => { dbport => '',
  840. dbuser => 'ledger-smb',
  841. dbdefault => 'template1',
  842. dbhost => '',
  843. connectstring => $locale->text('Connect to')
  844. } );
  845. $driverdefaults{PgPP} = $driverdefaults{Pg};
  846. for (keys %{ $driverdefaults{Pg} }) { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} }
  847. }
  848. sub dbselect_source {
  849. &dbdriver_defaults;
  850. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." / ".$locale->text('Database Administration');
  851. $form->{login} = "root login";
  852. $form->header;
  853. #an insane amount of table nesting here, this should be cleaned up.
  854. print qq|
  855. <body class="admin">
  856. <center>
  857. <h2>$form->{title}</h2>
  858. <form method="post" action="$form->{script}" />
  859. <table>
  860. <tr>
  861. <td>
  862. <table>
  863. <tr class="listheading">
  864. <th colspan="4">|.$locale->text('Database').qq|</th>
  865. </tr>
  866. <tr>
  867. <td>
  868. <table>
  869. <tr>
  870. <th align="right">|.$locale->text('Host').qq|</th>
  871. <td><input name="dbhost" size="25" value="$form->{dbhost}" /></td>
  872. <th align="right">|.$locale->text('Port').qq|</th>
  873. <td><input name="dbport" size="5" value="$form->{dbport}" /></td>
  874. </tr>
  875. <tr>
  876. <th align="right">|.$locale->text('User').qq|</th>
  877. <td><input name="dbuser" size="10" value="$form->{dbuser}" /></td>
  878. <th align="right">|.$locale->text('Password').qq|</th>
  879. <td><input type="password" name="dbpasswd" size="10" /></td>
  880. </tr>
  881. <tr>
  882. <th align="right">$form->{connectstring}</th>
  883. <td colspan="3"><input name="dbdefault" size="10" value="$form->{dbdefault}" /></td>
  884. </tr>
  885. <th align="right">|.$locale->text("Superuser").qq|</th>
  886. <td><input name="dbsuperuser" size="10" value="$form->{dbsuperuser}" /></td>
  887. <th align="right">|.$locale->text('Password').qq|</th>
  888. <td><input type="password" name="dbsuperpasswd" size="10" /></td>
  889. </table>
  890. </td>
  891. </tr>
  892. </table>
  893. </td>
  894. </tr>
  895. </table>
  896. <input type="hidden" name="dbdriver" value="$form->{dbdriver}" />
  897. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  898. <input type="hidden" name="path" value="$form->{path}" />
  899. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  900. <br />
  901. <button type="submit" class="submit" name="action" value="create_dataset">|.$locale->text('Create Dataset').qq|</button>
  902. <button type="submit" class="submit" name="action" value="delete_dataset">|.$locale->text('Delete Dataset').qq|</button>
  903. </form>
  904. <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!')
  905. .qq|</p>
  906. </center>
  907. </body>
  908. </html>
  909. |;
  910. }
  911. sub continue {
  912. &{ $form->{nextsub} };
  913. }
  914. sub dbupdate {
  915. User->dbupdate(\%$form);
  916. $form->redirect($locale->text('Dataset updated!'));
  917. }
  918. sub create_dataset {
  919. @dbsources = sort User->dbsources(\%$form);
  920. opendir SQLDIR, "sql/." or $form->error($!);
  921. foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {
  922. next if ($item eq 'Default-chart.sql');
  923. $item =~ s/-chart\.sql//;
  924. push @charts, qq|<input name="chart" class="radio" type="radio" value="$item" />$item|;
  925. }
  926. closedir SQLDIR;
  927. # add Default at beginning
  928. unshift @charts, qq|<input name="chart" class="radio" type="radio" value="Default" checked />Default|;
  929. $selectencoding = qq|<option></option>
  930. <option value="SQL_ASCII">ASCII</option>
  931. <option value="EUC_JP">Japanese EUC</option>
  932. <option value="EUC_CN">Chinese EUC</option>
  933. <option value="EUC_KR">Korean EUC</option>
  934. <option value="JOHAB">Korean EUC (Hangle base)</option>
  935. <option value="EUC_TW">Taiwan EUC</option>
  936. <option value="UNICODE">Unicode (UTF-8)</option>
  937. <option value="MULE_INTERNAL">Mule internal type</option>
  938. <option value="LATIN1">ISO 8859-1/ECMA 94 (Latin alphabet no. 1)</option>
  939. <option value="LATIN2">ISO 8859-2/ECMA 94 (Latin alphabet no. 2)</option>
  940. <option value="LATIN3">ISO 8859-3/ECMA 94 (Latin alphabet no. 3)</option>
  941. <option value="LATIN4">ISO 8859-4/ECMA 94 (Latin alphabet no. 4)</option>
  942. <option value="LATIN5">ISO 8859-9/ECMA 128 (Latin alphabet no. 5)</option>
  943. <option value="LATIN6">ISO 8859-10/ECMA 144 (Latin alphabet no. 6)</option>
  944. <option value="LATIN7">ISO 8859-13 (Latin alphabet no. 7)</option>
  945. <option value="LATIN8">ISO 8859-14 (Latin alphabet no. 8)</option>
  946. <option value="LATIN9">ISO 8859-15 (Latin alphabet no. 9)</option>
  947. <option value="LATIN10">ISO 8859-16/ASRO SR 14111 (Latin alphabet no. 10)</option>
  948. <option value="ISO_8859_5">ISO 8859-5/ECMA 113 (Latin/Cyrillic)</option>
  949. <option value="ISO_8859_6">ISO 8859-6/ECMA 114 (Latin/Arabic)</option>
  950. <option value="ISO_8859_7">ISO 8859-7/ECMA 118 (Latin/Greek)</option>
  951. <option value="ISO_8859_8">ISO 8859-8/ECMA 121 (Latin/Hebrew)</option>
  952. <option value="KOI8">KOI8-R(U)</option>
  953. <option value="WIN">Windows CP1251</option>
  954. <option value="ALT">Windows CP866</option>
  955. <option value="WIN1256">Windows CP1256 (Arabic)</option>
  956. <option value="TCVN">Windows CP1258 (Vietnamese)</option>
  957. <option value="WIN874">Windows CP874 (Thai)</option>
  958. |;
  959. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  960. ." ".$locale->text('Database Administration')
  961. ." / ".$locale->text('Create Dataset');
  962. $form->{login} = "root login";
  963. $form->header;
  964. print qq|
  965. <body class="admin">
  966. <center>
  967. <h2>$form->{title}</h2>
  968. <form method="post" action="$form->{script}" />
  969. <table width="100%">
  970. <tr class="listheading">
  971. <th colspan="2">&nbsp;</th>
  972. </tr>
  973. <tr>
  974. <th align="right" nowrap="nowrap">|.$locale->text('Existing Datasets').qq|</th>
  975. <td>
  976. |;
  977. for (@dbsources) { print "[&nbsp;$_&nbsp;] " }
  978. print qq|
  979. </td>
  980. </tr>
  981. <tr>
  982. <th align="right" nowrap="nowrap">|.$locale->text('Create Dataset').qq|</th>
  983. <td><input name="db" /></td>
  984. </tr>
  985. <tr>
  986. <th align="right" nowrap="nowrap">|.$locale->text('Multibyte Encoding').qq|</th>
  987. <td><select name="encoding">$selectencoding</select></td>
  988. </tr>
  989. <tr>
  990. <th align="right" nowrap="nowrap">|.$locale->text('Create Chart of Accounts').qq|</th>
  991. <td>
  992. <table>
  993. |;
  994. while (@charts) {
  995. print qq| <tr>|;
  996. for (0 .. 2) { print "<td>$charts[$_]</td>\n" }
  997. print qq| </tr>|;
  998. splice @charts, 0, 3;
  999. }
  1000. print qq| </table>
  1001. </td>
  1002. </tr>
  1003. <tr>
  1004. <td colspan="2">
  1005. <hr size="3" noshade />
  1006. </td>
  1007. </tr>
  1008. </table>
  1009. |;
  1010. $form->hide_form(qw(dbdriver dbsuperuser dbsuperpasswd dbuser dbhost dbport dbpasswd dbdefault path sessionid));
  1011. print qq|
  1012. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  1013. <input type="hidden" name="nextsub" value="dbcreate" />
  1014. <br />
  1015. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1016. </form>
  1017. </body>
  1018. </html>
  1019. |;
  1020. }
  1021. sub dbcreate {
  1022. $form->isblank("db", $locale->text('Dataset missing!'));
  1023. User->dbcreate(\%$form);
  1024. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1025. ." ".$locale->text('Database Administration')
  1026. ." / ".$locale->text('Create Dataset');
  1027. $form->{login} = "root login";
  1028. $form->header;
  1029. print qq|
  1030. <body class="admin">
  1031. <center>
  1032. <h2>$form->{title}</h2>
  1033. <form method="post" action="$form->{script}">|
  1034. .$locale->text('Dataset')." $form->{db} ".$locale->text('successfully created!')
  1035. .qq|
  1036. <input type="hidden" name="path" value="$form->{path}" />
  1037. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1038. <input type="hidden" name="nextsub" value="list_users" />
  1039. <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
  1040. </form>
  1041. </center>
  1042. </body>
  1043. </html>
  1044. |;
  1045. }
  1046. sub delete_dataset {
  1047. if (@dbsources = User->dbsources_unused(\%$form, $memberfile)) {
  1048. foreach $item (sort @dbsources) {
  1049. $dbsources .= qq|<input name="db" class="radio" type="radio" value="$item" />&nbsp;$item |;
  1050. }
  1051. } else {
  1052. $form->error($locale->text('Nothing to delete!'));
  1053. }
  1054. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1055. ." ".$locale->text('Database Administration')
  1056. ." / ".$locale->text('Delete Dataset');
  1057. $form->{login} = "root login";
  1058. $form->header;
  1059. print qq|
  1060. <body class="admin">
  1061. <h2>$form->{title}</h2>
  1062. <form method="post" action="$form->{script}" />
  1063. <input type="hidden" name="dbdriver" value="$form->{dbdriver}" />
  1064. <input type="hidden" name="dbuser" value="$form->{dbuser}" />
  1065. <input type="hidden" name="dbhost" value="$form->{dbhost}" />
  1066. <input type="hidden" name="dbport" value="$form->{dbport}" />
  1067. <input type="hidden" name="dbpasswd" value="$form->{dbpasswd}" />
  1068. <input type="hidden" name="dbdefault" value="$form->{dbdefault}" />
  1069. <input name=callback type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}">
  1070. <input type="hidden" name="path" value="$form->{path}" />
  1071. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1072. <input type="hidden" name="nextsub" value="dbdelete" />
  1073. <table width="100%">
  1074. <tr class="listheading">
  1075. <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>
  1076. </tr>
  1077. <tr>
  1078. <td>
  1079. $dbsources
  1080. </td>
  1081. </tr>
  1082. <tr>
  1083. <td>
  1084. <hr size="3" noshade />
  1085. <br />
  1086. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1087. </td>
  1088. </tr>
  1089. </table>
  1090. </form>
  1091. </body>
  1092. </html>
  1093. |;
  1094. }
  1095. sub dbdelete {
  1096. if (!$form->{db}) {
  1097. $form->error($locale->text('No Dataset selected!'));
  1098. }
  1099. User->dbdelete(\%$form);
  1100. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1101. ." ".$locale->text('Database Administration')
  1102. ." / ".$locale->text('Delete Dataset');
  1103. $form->{login} = "root login";
  1104. $form->header;
  1105. print qq|
  1106. <body class="admin">
  1107. <center>
  1108. <h2>$form->{title}</h2>
  1109. $form->{db} |.$locale->text('successfully deleted!')
  1110. .qq|
  1111. <form method="post" action="$form->{script}" />
  1112. <input type="hidden" name="path" value="$form->{path}" />
  1113. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1114. <input type="hidden" name="nextsub" value="list_users" />
  1115. <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
  1116. </form>
  1117. </body>
  1118. </html>
  1119. |;
  1120. }
  1121. sub unlock_system {
  1122. unlink "$userspath/nologin";
  1123. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  1124. $form->redirect($locale->text('Lockfile removed!'));
  1125. }
  1126. sub lock_system {
  1127. open(FH, ">$userspath/nologin") or $form->error($locale->text('Cannot create Lock!'));
  1128. close(FH);
  1129. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  1130. $form->redirect($locale->text('Lockfile created!'));
  1131. }