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";
41 $lxdebug->enter_sub();
42 $_[0] =~ s/\"/\"/g;
43 $lxdebug->leave_sub();
48 $lxdebug->enter_sub();
50 $auth->assert('license_edit');
52 $form->{jsscript} = 1;
58 <form method=post action=$form->{script}>|);
59 $lxdebug->leave_sub();
63 $lxdebug->enter_sub();
65 $auth->assert('license_edit');
67 my @items = qw(old_callback previousform);
68 push(@items, @{ $form->{"hidden"} });
70 print("<input type=hidden name=$_ value=\"" . quot($form->{$_}) . "\">\n"
75 qq|<input type="hidden" name="cursor_field" value='$form->{cursor_field}'></form>
79 $lxdebug->leave_sub();
83 $lxdebug->enter_sub();
84 $form->{"hidden"} = ["comment", "validuntil", "quantity", @_];
85 $lxdebug->leave_sub();
88 sub print_part_selection {
89 $lxdebug->enter_sub();
91 $auth->assert('license_edit');
94 set_std_hidden("business");
101 <th class=listtop colspan=5>|
102 . $locale->text('Select from one of the items below') . qq|</th>
105 <tr class=listheading>
107 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
108 <th class=listheading>| . $locale->text('Description') . qq|</th>
113 for ($i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
114 %p = %{ $form->{"parts"}->[$i - 1] };
116 $checked = "checked";
122 qq|<tr class=listrow$j>
123 <td><input name=ndx class=radio type=radio value=$i $checked></td>
124 <td><input name=\"new_partnumber_$i\" type=hidden value=\"|
125 . $p{"partnumber"} . qq|\">| . $p{"partnumber"} . qq|</td>
126 <td><input name=\"new_description_$i\" type=hidden value=\"|
127 . $p{"description"} . qq|\">| . $p{"description"} . qq|</td>
128 <input name=\"new_parts_id_$i\" type=hidden value=\"| . $p{"id"} . qq|\">
135 qq|<tr><td colspan=3><hr size=3 noshade></td></tr>
138 <input type=hidden name=nextsub value=\"do_add\">
139 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
142 $lxdebug->leave_sub();
145 sub print_customer_selection {
146 $lxdebug->enter_sub();
148 $auth->assert('license_edit');
151 set_std_hidden("parts_id", "partnumber", "description");
157 <th class=listtop colspan=5>|
158 . $locale->text('Select from one of the names below') . qq|</th>
161 <tr class=listheading>
163 <th class=listheading>| . $locale->text('Customer Number') . qq|</th>
164 <th class=listheading>| . $locale->text('Company Name') . qq|</th>
165 <th class=listheading>| . $locale->text('Street') . qq|</th>
166 <th class=listheading>| . $locale->text('Zipcode') . qq|</th>
167 <th class=listheading>| . $locale->text('City') . qq|</th>
171 print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
174 for ($i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
175 %c = %{ $form->{"all_customers"}->[$i - 1] };
177 $checked = "checked";
183 qq|<tr class=listrow$j>
184 <td><input name=ndx class=radio type=radio value=$i $checked></td>
185 <td><input name=\"new_customer_id_$i\" type=hidden value=\"|
186 . $c{"id"} . qq|\">$c{"customernumber"}</td>
187 <td><input name=\"new_customer_name_$i\" type=hidden value=\"|
188 . $c{"name"} . qq|\">$c{"name"}</td>
189 <td>$c{"street"}</td>
190 <td>$c{"zipcode"}</td>
201 <input type=hidden name=nextsub value=\"do_add\">
202 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
205 $lxdebug->leave_sub();
208 sub print_license_form {
209 $lxdebug->enter_sub();
211 $auth->assert('license_edit');
217 <th class=listtop>| . $locale->text("Add License") . qq|</th>
222 <th align=right>| . $locale->text('Part Number') . qq|</th>
223 <td><input name=partnumber value=\"|
224 . quot($form->{"partnumber"}) . qq|\"></td>
227 <th align=right>| . $locale->text('Description') . qq|</th>
228 <td><input name=description value=\"|
229 . quot($form->{"description"}) . qq|\"></td>
232 <th align=right>| . $locale->text('Company Name') . qq|</th>|);
233 if ($form->{"all_customer"}) {
234 print(qq|<td><select name=\"customer\">|);
235 foreach (@{ $form->{"all_customer"} }) {
236 if (!defined($form->{"customer_id"})) {
237 $form->{"customer_id"} = $_->{"id"};
239 $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
240 print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
242 print(qq|</select></td>|);
244 print( qq|<td><input name=customer_name value=\"|
245 . quot($form->{"customer_name"})
251 <th align=right>| . $locale->text('Comment') . qq|</th>
252 <td><input name=comment value=\"|
253 . quot($form->{"comment"}) . qq|\"></td>
256 <th align=right>| . $locale->text('Valid until') . qq|</th>
257 <td><input id=validuntil name=validuntil value=\"|
258 . quot($form->{"validuntil"}) . qq|\">
259 <input type="button" name="validuntil" id="trigger_validuntil" value="?"></td>
262 <th align=right>| . $locale->text('Quantity') . qq|</th>
263 <td><input name=quantity value=\"|
264 . quot($form->{"quantity"}) . qq|\"></td>
267 <th align=right>| . $locale->text('License key') . qq|</th>
268 <td><input name=licensenumber value=\"|
269 . quot($form->{"licensenumber"}) . qq|\"></td>
272 <th align=right>| . $locale->text('Own Product') . qq|</th>
273 <td><input type=checkbox name=own_product value=1 checked></td>
277 <input type=submit name=action value=\"| . $locale->text('Update') . qq|\">
283 <input type=submit name=action value=\"|
284 . $locale->text('Save') . qq|\">\n|);
291 $form->write_trigger(\%myconfig, 1, "validuntil", "BL",
292 "trigger_validuntil"));
294 $lxdebug->leave_sub();
298 $lxdebug->enter_sub();
300 $auth->assert('license_edit');
305 'The licensing module has been deactivated in lx-erp.conf.')
309 $form->{"initial"} = 1;
312 $lxdebug->leave_sub();
316 $lxdebug->enter_sub();
318 $auth->assert('license_edit');
320 $form->{"hidden"} = ["parts_id"];
323 if ($form->{"ndx"}) {
324 $ndx = $form->{"ndx"};
325 foreach (keys(%{$form})) {
326 next unless (/^new_.*_${ndx}$/);
329 $form->{$_} = $form->{"new_${_}_${ndx}"};
333 if ($form->{"customer"}) {
334 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
337 if ($form->{"customer_name"}) {
338 LICENSES->get_customers(\%myconfig, $form);
339 if (scalar(@{ $form->{"all_customers"} }) == 1) {
340 %c = %{ $form->{"all_customers"}->[0] };
341 $form->{"customer_id"} = $c{"id"};
342 $form->{"customer_name"} = $c{"name"};
343 } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
344 $form->{"customer_name"} = "";
345 delete($form->{"customer_id"});
347 print_customer_selection();
350 } elsif (defined($form->{"customer_name"})) {
351 delete($form->{"customer_id"});
354 if ($form->{"partnumber"} || $form->{"description"}) {
355 $form->{"sort"} = "p.partnumber";
356 $form->{searchitems} = "part";
357 IC->all_parts(\%myconfig, $form);
358 if (scalar(@{ $form->{"parts"} }) == 1) {
359 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
360 ("partnumber", "description"));
361 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
363 } elsif (scalar(@{ $form->{"parts"} }) == 0) {
364 map({ $form->{$_} = ""; }("partnumber", "description", "parts_id"));
367 print_part_selection();
371 delete($form->{"parts_id"});
374 $form->all_vc(\%myconfig, "customer", "");
376 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
379 $lxdebug->leave_sub();
383 $lxdebug->enter_sub();
385 $auth->assert('license_edit');
389 $lxdebug->leave_sub();
393 $lxdebug->enter_sub();
394 call_sub($form->{"nextsub"});
395 $lxdebug->leave_sub();
399 $lxdebug->enter_sub();
401 $auth->assert('license_edit');
403 ($form->{customername}, $form->{customer_id}) = split /--/,
406 $form->isblank("customer", $locale->text('Customer missing!'));
408 if ( $form->{quantity} eq ""
409 || $form->{quantity} !~ /^[0-9]*$/
410 || $form->{quantity} < 1) {
411 $form->error($locale->text('Please enter a number of licenses.'));
414 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
415 $form->error($locale->text('Please enter a license key.'));
418 $rc = LICENSES->save_license(\%myconfig, \%$form);
420 # load previous variables
421 if ($form->{previousform}) {
423 # save the new form variables before splitting previousform
424 map { $newform{$_} = $form->{$_} } keys %$form;
426 $previousform = $form->unescape($form->{previousform});
428 # don't trample on previous variables
429 map { delete $form->{$_} } keys %newform;
431 # now take it apart and restore original values
432 foreach $item (split /&/, $previousform) {
433 ($key, $value) = split /=/, $item, 2;
435 $form->{$key} = $value;
438 $form->{"lizenzen_$form->{row}"} =
439 "<option value=$rc>$newform{licensenumber}</option>";
442 delete $form->{action};
444 # restore original callback
445 $callback = $form->unescape($form->{callback});
446 $form->{callback} = $form->unescape($form->{old_callback});
447 delete $form->{old_callback};
449 # put callback together
450 foreach $key (keys %$form) {
451 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
453 # do single escape for Apache 2.0
454 $value = $form->escape($form->{$key}, 1);
455 $callback .= qq|&$key=$value|;
457 $form->{callback} = $callback;
465 print("Die Lizenz wurde gespeichert.\n");
469 $lxdebug->leave_sub();
473 $lxdebug->enter_sub();
475 $auth->assert('license_edit');
480 'The licensing module has been deactivated in lx-erp.conf.')
490 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
495 <th align=right>| . $locale->text('Part Number') . qq|</th>
496 <td><input name=partnumber></td>
499 <th align=right>| . $locale->text('Description') . qq|</th>
500 <td><input name=description></td>
503 <th align=right>| . $locale->text('Company Name') . qq|</th>
504 <td><input name=customer_name></td>
507 <th align=right>| . $locale->text('Include in Report') . qq|</th>
508 <td><input type=radio name=all value=1 checked>|
509 . $locale->text('All')
510 . qq| <input type=radio name=all value=0>|
511 . $locale->text('Expiring in x month(s)')
512 . qq| <input size=4 name=expiring_in value="1"><br>
513 <input type=checkbox name=show_expired value=1>|
514 . $locale->text('Expired licenses') . qq|</td>
518 <tr><td colspan=4><hr size=3 noshade></td></tr>
521 <input type=hidden name=nextsub value=\"do_search\">
522 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
527 $lxdebug->leave_sub();
531 $lxdebug->enter_sub();
533 $auth->assert('license_edit');
535 LICENSES->search(\%myconfig, $form);
538 map { $callback .= "\&${_}=" . $form->escape($form->{$_}, 1) }
539 qw(db partnumber description customer_name all expiring_in show_expired);
540 $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
541 $invdetails = "is.pl?action=edit" . $callback . "\&id=";
542 $callback = $form->{"script"} . "?action=do_search" . $callback;
544 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
545 $form->{"sortasc"} *= 1;
546 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
547 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
548 if ($form->{"sortby"} eq $_) {
549 $columns{$_} .= (1 - $form->{"sortasc"});
561 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
564 if (scalar(@{ $form->{"licenses"} }) == 0) {
567 "No licenses were found that match the search criteria.")
568 . qq|</body></html>|);
577 <th class=listtop><a class=listheading href=\"|
578 . $columns{"partnumber"} . "\">"
579 . $locale->text('Part Number')
581 <th class=listtop><a class=listheading href=\"|
582 . $columns{"description"} . "\">"
583 . $locale->text('Description')
585 <th class=listtop><a class=listheading href=\"|
586 . $columns{"name"} . "\">" . $locale->text('Company Name') . qq|</a></th>
587 <th class=listtop><a class=listheading href=\"|
588 . $columns{"validuntil"} . "\">"
589 . $locale->text('Valid until')
591 <th class=listtop><a class=listheading href=\"|
592 . $columns{"invnumber"} . "\">"
593 . $locale->text('Invoice Number')
599 for ($i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
600 $ref = $form->{"licenses"}->[$i];
604 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
605 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
606 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
607 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
608 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
612 ? qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>|
620 $form->{"num_licenses"} = scalar(@{ $form->{"licenses"} });
621 push(@{ $form->{"hidden"} }, "num_licenses");
628 <td><hr size=3 noshade></td>
634 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
638 $lxdebug->leave_sub();
642 $lxdebug->enter_sub();
644 $auth->assert('license_edit');
646 LICENSES->get_license(\%myconfig, $form);
648 { $form->{$_} = $form->{"license"}->{$_}; } keys(%{ $form->{"license"} }));
656 <th class=listtop>| . $locale->text("View License") . qq|</th>
661 <th align=right>| . $locale->text('Part Number') . qq|</th>
662 <td>$form->{"partnumber"}</td>
665 <th align=right>| . $locale->text('Description') . qq|</th>
666 <td>$form->{"description"}</td>
669 <th align=right>| . $locale->text('Company Name') . qq|</th>
670 <td>$form->{"name"}</td>
673 <th align=right>| . $locale->text('Comment') . qq|</th>
674 <td>$form->{"comment"}</td>
677 <th align=right>| . $locale->text('Valid until') . qq|</th>
678 <td>$form->{"validuntil"}</td>
681 <th align=right>| . $locale->text('Quantity') . qq|</th>
682 <td>$form->{"quantity"}</td>
685 <th align=right>| . $locale->text('License key') . qq|</th>
686 <td>$form->{"licensenumber"}</td>
691 <td><hr size=3 noshade></td>
695 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
699 $lxdebug->leave_sub();