1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Moritz Bunkus
12 # Email: m.bunkus@linet-services.de
13 # Web: http://www.linet-services.de/
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Software license module
32 #======================================================================
38 require "bin/mozilla/common.pl";
43 $main::lxdebug->enter_sub();
44 $_[0] =~ s/\"/\"/g;
45 $main::lxdebug->leave_sub();
50 $main::lxdebug->enter_sub();
52 $main::auth->assert('license_edit');
54 my $form = $main::form;
56 $form->{jsscript} = 1;
62 <form method=post action=$form->{script}>|);
63 $main::lxdebug->leave_sub();
67 $main::lxdebug->enter_sub();
69 $main::auth->assert('license_edit');
71 my $form = $main::form;
73 my @items = qw(old_callback previousform);
74 push @items, @{ $form->{"hidden"} } if ref $form->{hidden} eq 'ARRAY';
76 print("<input type=hidden name=$_ value=\"" . quot($form->{$_}) . "\">\n"
81 qq|<input type="hidden" name="cursor_field" value='$form->{cursor_field}'></form>
85 $main::lxdebug->leave_sub();
89 $main::lxdebug->enter_sub();
91 my $form = $main::form;
93 $form->{"hidden"} = ["comment", "validuntil", "quantity", @_];
94 $main::lxdebug->leave_sub();
97 sub print_part_selection {
98 $main::lxdebug->enter_sub();
100 $main::auth->assert('license_edit');
102 my $form = $main::form;
103 my $locale = $main::locale;
106 set_std_hidden("business");
113 <th class=listtop colspan=5>|
114 . $locale->text('Select from one of the items below') . qq|</th>
117 <tr class=listheading>
119 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
120 <th class=listheading>| . $locale->text('Description') . qq|</th>
125 for (my $i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
126 my %p = %{ $form->{"parts"}->[$i - 1] };
129 $checked = "checked";
135 qq|<tr class=listrow$j>
136 <td><input name=ndx class=radio type=radio value=$i $checked></td>
137 <td><input name=\"new_partnumber_$i\" type=hidden value=\"|
138 . $p{"partnumber"} . qq|\">| . $p{"partnumber"} . qq|</td>
139 <td><input name=\"new_description_$i\" type=hidden value=\"|
140 . $p{"description"} . qq|\">| . $p{"description"} . qq|</td>
141 <input name=\"new_parts_id_$i\" type=hidden value=\"| . $p{"id"} . qq|\">
148 qq|<tr><td colspan=3><hr size=3 noshade></td></tr>
151 <input type=hidden name=nextsub value=\"do_add\">
152 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
155 $main::lxdebug->leave_sub();
158 sub print_customer_selection {
159 $main::lxdebug->enter_sub();
161 $main::auth->assert('license_edit');
163 my $form = $main::form;
164 my $locale = $main::locale;
167 set_std_hidden("parts_id", "partnumber", "description");
173 <th class=listtop colspan=5>|
174 . $locale->text('Select from one of the names below') . qq|</th>
177 <tr class=listheading>
179 <th class=listheading>| . $locale->text('Customer Number') . qq|</th>
180 <th class=listheading>| . $locale->text('Company Name') . qq|</th>
181 <th class=listheading>| . $locale->text('Street') . qq|</th>
182 <th class=listheading>| . $locale->text('Zipcode') . qq|</th>
183 <th class=listheading>| . $locale->text('City') . qq|</th>
187 print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
190 for (my $i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
191 my %c = %{ $form->{"all_customers"}->[$i - 1] };
194 $checked = "checked";
200 qq|<tr class=listrow$j>
201 <td><input name=ndx class=radio type=radio value=$i $checked></td>
202 <td><input name=\"new_customer_id_$i\" type=hidden value=\"|
203 . $c{"id"} . qq|\">$c{"customernumber"}</td>
204 <td><input name=\"new_customer_name_$i\" type=hidden value=\"|
205 . $c{"name"} . qq|\">$c{"name"}</td>
206 <td>$c{"street"}</td>
207 <td>$c{"zipcode"}</td>
218 <input type=hidden name=nextsub value=\"do_add\">
219 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
222 $main::lxdebug->leave_sub();
225 sub print_license_form {
226 $main::lxdebug->enter_sub();
228 $main::auth->assert('license_edit');
230 my $form = $main::form;
231 my %myconfig = %main::myconfig;
232 my $locale = $main::locale;
238 <th class=listtop>| . $locale->text("Add License") . qq|</th>
243 <th align=right>| . $locale->text('Part Number') . qq|</th>
244 <td><input name=partnumber value=\"|
245 . quot($form->{"partnumber"}) . qq|\"></td>
248 <th align=right>| . $locale->text('Description') . qq|</th>
249 <td><input name=description value=\"|
250 . quot($form->{"description"}) . qq|\"></td>
253 <th align=right>| . $locale->text('Company Name') . qq|</th>|);
254 if ($form->{"all_customer"}) {
255 print(qq|<td><select name=\"customer\">|);
256 foreach (@{ $form->{"all_customer"} }) {
257 if (!defined($form->{"customer_id"})) {
258 $form->{"customer_id"} = $_->{"id"};
260 my $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
261 print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
263 print(qq|</select></td>|);
265 print( qq|<td><input name=customer_name value=\"|
266 . quot($form->{"customer_name"})
272 <th align=right>| . $locale->text('Comment') . qq|</th>
273 <td><input name=comment value=\"|
274 . quot($form->{"comment"}) . qq|\"></td>
277 <th align=right>| . $locale->text('Valid until') . qq|</th>
278 <td><input id=validuntil name=validuntil value=\"|
279 . quot($form->{"validuntil"}) . qq|\">
280 <input type="button" name="validuntil" id="trigger_validuntil" value="?"></td>
283 <th align=right>| . $locale->text('Quantity') . qq|</th>
284 <td><input name=quantity value=\"|
285 . quot($form->{"quantity"}) . qq|\"></td>
288 <th align=right>| . $locale->text('License key') . qq|</th>
289 <td><input name=licensenumber value=\"|
290 . quot($form->{"licensenumber"}) . qq|\"></td>
293 <th align=right>| . $locale->text('Own Product') . qq|</th>
294 <td><input type=checkbox name=own_product value=1 checked></td>
298 <input type=submit name=action value=\"| . $locale->text('Update') . qq|\">
304 <input type=submit name=action value=\"|
305 . $locale->text('Save') . qq|\">\n|);
312 $form->write_trigger(\%myconfig, 1, "validuntil", "BL",
313 "trigger_validuntil"));
315 $main::lxdebug->leave_sub();
319 $main::lxdebug->enter_sub();
321 $main::auth->assert('license_edit');
323 my $form = $main::form;
324 my $locale = $main::locale;
326 if (!$main::lizenzen) {
329 'The licensing module has been deactivated in lx-erp.conf.')
333 $form->{"initial"} = 1;
336 $main::lxdebug->leave_sub();
340 $main::lxdebug->enter_sub();
342 $main::auth->assert('license_edit');
344 my $form = $main::form;
345 my %myconfig = %main::myconfig;
347 $form->{"hidden"} = ["parts_id"];
350 if ($form->{"ndx"}) {
351 my $ndx = $form->{"ndx"};
352 foreach (keys(%{$form})) {
353 next unless (/^new_.*_${ndx}$/);
356 $form->{$_} = $form->{"new_${_}_${ndx}"};
360 if ($form->{"customer"}) {
361 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
364 if ($form->{"customer_name"}) {
365 LICENSES->get_customers(\%myconfig, $form);
366 if (scalar(@{ $form->{"all_customers"} }) == 1) {
367 my %c = %{ $form->{"all_customers"}->[0] };
368 $form->{"customer_id"} = $c{"id"};
369 $form->{"customer_name"} = $c{"name"};
370 } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
371 $form->{"customer_name"} = "";
372 delete($form->{"customer_id"});
374 print_customer_selection();
377 } elsif (defined($form->{"customer_name"})) {
378 delete($form->{"customer_id"});
381 if ($form->{"partnumber"} || $form->{"description"}) {
382 $form->{"sort"} = "p.partnumber";
383 $form->{searchitems} = "part";
384 IC->all_parts(\%myconfig, $form);
385 if (scalar(@{ $form->{"parts"} }) == 1) {
386 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
387 ("partnumber", "description"));
388 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
390 } elsif (scalar(@{ $form->{"parts"} }) == 0) {
391 map({ $form->{$_} = ""; }("partnumber", "description", "parts_id"));
394 print_part_selection();
398 delete($form->{"parts_id"});
401 $form->all_vc(\%myconfig, "customer", "");
403 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
406 $main::lxdebug->leave_sub();
410 $main::lxdebug->enter_sub();
412 $main::auth->assert('license_edit');
414 my $form = $main::form;
418 $main::lxdebug->leave_sub();
422 $main::lxdebug->enter_sub();
424 my $form = $main::form;
426 call_sub($form->{"nextsub"});
427 $main::lxdebug->leave_sub();
431 $main::lxdebug->enter_sub();
433 $main::auth->assert('license_edit');
435 my $form = $main::form;
436 my %myconfig = %main::myconfig;
437 my $locale = $main::locale;
439 ($form->{customername}, $form->{customer_id}) = split /--/,
442 $form->isblank("customer", $locale->text('Customer missing!'));
444 if ( $form->{quantity} eq ""
445 || $form->{quantity} !~ /^[0-9]*$/
446 || $form->{quantity} < 1) {
447 $form->error($locale->text('Please enter a number of licenses.'));
450 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
451 $form->error($locale->text('Please enter a license key.'));
454 my $rc = LICENSES->save_license(\%myconfig, \%$form);
456 # load previous variables
457 if ($form->{previousform}) {
459 # save the new form variables before splitting previousform
461 map { $newform{$_} = $form->{$_} } keys %$form;
463 my $previousform = $form->unescape($form->{previousform});
465 # don't trample on previous variables
466 map { delete $form->{$_} } keys %newform;
468 # now take it apart and restore original values
469 foreach my $item (split /&/, $previousform) {
470 my ($key, $value) = split /=/, $item, 2;
472 $form->{$key} = $value;
475 $form->{"lizenzen_$form->{row}"} =
476 "<option value=$rc>$newform{licensenumber}</option>";
479 delete $form->{action};
481 # restore original callback
482 my $callback = $form->unescape($form->{callback});
483 $form->{callback} = $form->unescape($form->{old_callback});
484 delete $form->{old_callback};
486 # put callback together
487 foreach my $key (keys %$form) {
488 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
490 # do single escape for Apache 2.0
491 my $value = $form->escape($form->{$key}, 1);
492 $callback .= qq|&$key=$value|;
494 $form->{callback} = $callback;
502 print("Die Lizenz wurde gespeichert.\n");
506 $main::lxdebug->leave_sub();
510 $main::lxdebug->enter_sub();
512 $main::auth->assert('license_edit');
514 my $form = $main::form;
515 my $locale = $main::locale;
517 if (!$main::lizenzen) {
520 'The licensing module has been deactivated in lx-erp.conf.')
530 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
535 <th align=right>| . $locale->text('Part Number') . qq|</th>
536 <td><input name=partnumber></td>
539 <th align=right>| . $locale->text('Description') . qq|</th>
540 <td><input name=description></td>
543 <th align=right>| . $locale->text('Company Name') . qq|</th>
544 <td><input name=customer_name></td>
547 <th align=right>| . $locale->text('Include in Report') . qq|</th>
548 <td><input type=radio name=all value=1 checked>|
549 . $locale->text('All')
550 . qq| <input type=radio name=all value=0>|
551 . $locale->text('Expiring in x month(s)')
552 . qq| <input size=4 name=expiring_in value="1"><br>
553 <input type=checkbox name=show_expired value=1>|
554 . $locale->text('Expired licenses') . qq|</td>
558 <tr><td colspan=4><hr size=3 noshade></td></tr>
561 <input type=hidden name=nextsub value=\"do_search\">
562 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
567 $main::lxdebug->leave_sub();
571 $main::lxdebug->enter_sub();
573 $main::auth->assert('license_edit');
575 my $form = $main::form;
576 my %myconfig = %main::myconfig;
577 my $locale = $main::locale;
579 LICENSES->search(\%myconfig, $form);
582 map { $callback .= "\&${_}=" . $form->escape($form->{$_}, 1) }
583 qw(db partnumber description customer_name all expiring_in show_expired);
584 my $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
585 my $invdetails = "is.pl?action=edit" . $callback . "\&id=";
586 $callback = $form->{"script"} . "?action=do_search" . $callback;
588 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
589 $form->{"sortasc"} *= 1;
591 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
592 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
593 if ($form->{"sortby"} eq $_) {
594 $columns{$_} .= (1 - $form->{"sortasc"});
606 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
609 if (scalar(@{ $form->{"licenses"} }) == 0) {
612 "No licenses were found that match the search criteria.")
613 . qq|</body></html>|);
622 <th class=listtop><a class=listheading href=\"|
623 . $columns{"partnumber"} . "\">"
624 . $locale->text('Part Number')
626 <th class=listtop><a class=listheading href=\"|
627 . $columns{"description"} . "\">"
628 . $locale->text('Description')
630 <th class=listtop><a class=listheading href=\"|
631 . $columns{"name"} . "\">" . $locale->text('Company Name') . qq|</a></th>
632 <th class=listtop><a class=listheading href=\"|
633 . $columns{"validuntil"} . "\">"
634 . $locale->text('Valid until')
636 <th class=listtop><a class=listheading href=\"|
637 . $columns{"invnumber"} . "\">"
638 . $locale->text('Invoice Number')
644 for (my $i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
645 my $ref = $form->{"licenses"}->[$i];
649 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
650 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
651 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
652 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
653 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
657 ? qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>|
665 $form->{"num_licenses"} = scalar(@{ $form->{"licenses"} });
666 push(@{ $form->{"hidden"} }, "num_licenses");
673 <td><hr size=3 noshade></td>
679 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
683 $main::lxdebug->leave_sub();
687 $main::lxdebug->enter_sub();
689 $main::auth->assert('license_edit');
691 my $form = $main::form;
692 my %myconfig = %main::myconfig;
693 my $locale = $main::locale;
695 LICENSES->get_license(\%myconfig, $form);
697 { $form->{$_} = $form->{"license"}->{$_}; } keys(%{ $form->{"license"} }));
705 <th class=listtop>| . $locale->text("View License") . qq|</th>
710 <th align=right>| . $locale->text('Part Number') . qq|</th>
711 <td>$form->{"partnumber"}</td>
714 <th align=right>| . $locale->text('Description') . qq|</th>
715 <td>$form->{"description"}</td>
718 <th align=right>| . $locale->text('Company Name') . qq|</th>
719 <td>$form->{"name"}</td>
722 <th align=right>| . $locale->text('Comment') . qq|</th>
723 <td>$form->{"comment"}</td>
726 <th align=right>| . $locale->text('Valid until') . qq|</th>
727 <td>$form->{"validuntil"}</td>
730 <th align=right>| . $locale->text('Quantity') . qq|</th>
731 <td>$form->{"quantity"}</td>
734 <th align=right>| . $locale->text('License key') . qq|</th>
735 <td>$form->{"licensenumber"}</td>
740 <td><hr size=3 noshade></td>
744 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
748 $main::lxdebug->leave_sub();