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 $form->{title} = $locale->text('Add License');
328 if (!$main::lizenzen) {
331 'The licensing module has been deactivated in lx-erp.conf.')
335 $form->{"initial"} = 1;
338 $main::lxdebug->leave_sub();
342 $main::lxdebug->enter_sub();
344 $main::auth->assert('license_edit');
346 my $form = $main::form;
347 my %myconfig = %main::myconfig;
349 $form->{"hidden"} = ["parts_id"];
352 if ($form->{"ndx"}) {
353 my $ndx = $form->{"ndx"};
354 foreach (keys(%{$form})) {
355 next unless (/^new_.*_${ndx}$/);
358 $form->{$_} = $form->{"new_${_}_${ndx}"};
362 if ($form->{"customer"}) {
363 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
366 if ($form->{"customer_name"}) {
367 LICENSES->get_customers(\%myconfig, $form);
368 if (scalar(@{ $form->{"all_customers"} }) == 1) {
369 my %c = %{ $form->{"all_customers"}->[0] };
370 $form->{"customer_id"} = $c{"id"};
371 $form->{"customer_name"} = $c{"name"};
372 } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
373 $form->{"customer_name"} = "";
374 delete($form->{"customer_id"});
376 print_customer_selection();
379 } elsif (defined($form->{"customer_name"})) {
380 delete($form->{"customer_id"});
383 if ($form->{"partnumber"} || $form->{"description"}) {
384 $form->{"sort"} = "p.partnumber";
385 $form->{searchitems} = "part";
386 IC->all_parts(\%myconfig, $form);
387 if (scalar(@{ $form->{"parts"} }) == 1) {
388 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
389 ("partnumber", "description"));
390 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
392 } elsif (scalar(@{ $form->{"parts"} }) == 0) {
393 map({ $form->{$_} = ""; }("partnumber", "description", "parts_id"));
396 print_part_selection();
400 delete($form->{"parts_id"});
403 $form->all_vc(\%myconfig, "customer", "");
405 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
408 $main::lxdebug->leave_sub();
412 $main::lxdebug->enter_sub();
414 $main::auth->assert('license_edit');
416 my $form = $main::form;
420 $main::lxdebug->leave_sub();
424 $main::lxdebug->enter_sub();
426 my $form = $main::form;
428 call_sub($form->{"nextsub"});
429 $main::lxdebug->leave_sub();
433 $main::lxdebug->enter_sub();
435 $main::auth->assert('license_edit');
437 my $form = $main::form;
438 my %myconfig = %main::myconfig;
439 my $locale = $main::locale;
441 ($form->{customername}, $form->{customer_id}) = split /--/,
444 $form->isblank("customer", $locale->text('Customer missing!'));
446 if ( $form->{quantity} eq ""
447 || $form->{quantity} !~ /^[0-9]*$/
448 || $form->{quantity} < 1) {
449 $form->error($locale->text('Please enter a number of licenses.'));
452 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
453 $form->error($locale->text('Please enter a license key.'));
456 my $rc = LICENSES->save_license(\%myconfig, \%$form);
458 # load previous variables
459 if ($form->{previousform}) {
461 # save the new form variables before splitting previousform
463 map { $newform{$_} = $form->{$_} } keys %$form;
465 my $previousform = $form->unescape($form->{previousform});
467 # don't trample on previous variables
468 map { delete $form->{$_} } keys %newform;
470 # now take it apart and restore original values
471 foreach my $item (split /&/, $previousform) {
472 my ($key, $value) = split /=/, $item, 2;
474 $form->{$key} = $value;
477 $form->{"lizenzen_$form->{row}"} =
478 "<option value=$rc>$newform{licensenumber}</option>";
481 delete $form->{action};
483 # restore original callback
484 my $callback = $form->unescape($form->{callback});
485 $form->{callback} = $form->unescape($form->{old_callback});
486 delete $form->{old_callback};
488 # put callback together
489 foreach my $key (keys %$form) {
490 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
492 # do single escape for Apache 2.0
493 my $value = $form->escape($form->{$key}, 1);
494 $callback .= qq|&$key=$value|;
496 $form->{callback} = $callback;
504 print("Die Lizenz wurde gespeichert.\n");
508 $main::lxdebug->leave_sub();
512 $main::lxdebug->enter_sub();
514 $main::auth->assert('license_edit');
516 my $form = $main::form;
517 my $locale = $main::locale;
519 $form->{title} = $locale->text('Licenses');
521 if (!$main::lizenzen) {
524 'The licensing module has been deactivated in lx-erp.conf.')
534 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
539 <th align=right>| . $locale->text('Part Number') . qq|</th>
540 <td><input name=partnumber></td>
543 <th align=right>| . $locale->text('Description') . qq|</th>
544 <td><input name=description></td>
547 <th align=right>| . $locale->text('Company Name') . qq|</th>
548 <td><input name=customer_name></td>
551 <th align=right>| . $locale->text('Include in Report') . qq|</th>
552 <td><input type=radio name=all value=1 checked>|
553 . $locale->text('All')
554 . qq| <input type=radio name=all value=0>|
555 . $locale->text('Expiring in x month(s)')
556 . qq| <input size=4 name=expiring_in value="1"><br>
557 <input type=checkbox name=show_expired value=1>|
558 . $locale->text('Expired licenses') . qq|</td>
562 <tr><td colspan=4><hr size=3 noshade></td></tr>
565 <input type=hidden name=nextsub value=\"do_search\">
566 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
571 $main::lxdebug->leave_sub();
575 $main::lxdebug->enter_sub();
577 $main::auth->assert('license_edit');
579 my $form = $main::form;
580 my %myconfig = %main::myconfig;
581 my $locale = $main::locale;
583 LICENSES->search(\%myconfig, $form);
586 map { $callback .= "\&${_}=" . $form->escape($form->{$_}, 1) }
587 qw(db partnumber description customer_name all expiring_in show_expired);
588 my $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
589 my $invdetails = "is.pl?action=edit" . $callback . "\&id=";
590 $callback = $form->{"script"} . "?action=do_search" . $callback;
592 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
593 $form->{"sortasc"} *= 1;
595 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
596 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
597 if ($form->{"sortby"} eq $_) {
598 $columns{$_} .= (1 - $form->{"sortasc"});
610 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
613 if (scalar(@{ $form->{"licenses"} }) == 0) {
616 "No licenses were found that match the search criteria.")
617 . qq|</body></html>|);
626 <th class=listtop><a class=listheading href=\"|
627 . $columns{"partnumber"} . "\">"
628 . $locale->text('Part Number')
630 <th class=listtop><a class=listheading href=\"|
631 . $columns{"description"} . "\">"
632 . $locale->text('Description')
634 <th class=listtop><a class=listheading href=\"|
635 . $columns{"name"} . "\">" . $locale->text('Company Name') . qq|</a></th>
636 <th class=listtop><a class=listheading href=\"|
637 . $columns{"validuntil"} . "\">"
638 . $locale->text('Valid until')
640 <th class=listtop><a class=listheading href=\"|
641 . $columns{"invnumber"} . "\">"
642 . $locale->text('Invoice Number')
648 for (my $i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
649 my $ref = $form->{"licenses"}->[$i];
653 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
654 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
655 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
656 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
657 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
661 ? qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>|
669 $form->{"num_licenses"} = scalar(@{ $form->{"licenses"} });
670 push(@{ $form->{"hidden"} }, "num_licenses");
677 <td><hr size=3 noshade></td>
683 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
687 $main::lxdebug->leave_sub();
691 $main::lxdebug->enter_sub();
693 $main::auth->assert('license_edit');
695 my $form = $main::form;
696 my %myconfig = %main::myconfig;
697 my $locale = $main::locale;
699 LICENSES->get_license(\%myconfig, $form);
701 { $form->{$_} = $form->{"license"}->{$_}; } keys(%{ $form->{"license"} }));
709 <th class=listtop>| . $locale->text("View License") . qq|</th>
714 <th align=right>| . $locale->text('Part Number') . qq|</th>
715 <td>$form->{"partnumber"}</td>
718 <th align=right>| . $locale->text('Description') . qq|</th>
719 <td>$form->{"description"}</td>
722 <th align=right>| . $locale->text('Company Name') . qq|</th>
723 <td>$form->{"name"}</td>
726 <th align=right>| . $locale->text('Comment') . qq|</th>
727 <td>$form->{"comment"}</td>
730 <th align=right>| . $locale->text('Valid until') . qq|</th>
731 <td>$form->{"validuntil"}</td>
734 <th align=right>| . $locale->text('Quantity') . qq|</th>
735 <td>$form->{"quantity"}</td>
738 <th align=right>| . $locale->text('License key') . qq|</th>
739 <td>$form->{"licensenumber"}</td>
744 <td><hr size=3 noshade></td>
748 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
752 $main::lxdebug->leave_sub();