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 #======================================================================
39 $lxdebug->enter_sub();
40 $_[0] =~ s/\"/\"/g;
41 $lxdebug->leave_sub();
46 $lxdebug->enter_sub();
47 $form->{jsscript} = 1;
53 <form method=post action=$form->{script}>|);
54 $lxdebug->leave_sub();
58 $lxdebug->enter_sub();
59 my @items = ("path", "login", "password", "old_callback", "previousform");
60 push(@items, @{ $form->{"hidden"} });
62 print("<input type=hidden name=$_ value=\"" . quot($form->{$_}) . "\">\n"
71 $lxdebug->leave_sub();
75 $lxdebug->enter_sub();
76 $form->{"hidden"} = ["comment", "validuntil", "quantity", @_];
77 $lxdebug->leave_sub();
80 sub print_part_selection {
81 $lxdebug->enter_sub();
83 set_std_hidden("business");
90 <th class=listtop colspan=5>|
91 . $locale->text('Select from one of the items below') . qq|</th>
94 <tr class=listheading>
96 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
97 <th class=listheading>| . $locale->text('Description') . qq|</th>
102 for ($i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
103 %p = %{ $form->{"parts"}->[$i - 1] };
105 $checked = "checked";
111 qq|<tr class=listrow$j>
112 <td><input name=ndx class=radio type=radio value=$i $checked></td>
113 <td><input name=\"new_partnumber_$i\" type=hidden value=\"|
114 . $p{"partnumber"} . qq|\">| . $p{"partnumber"} . qq|</td>
115 <td><input name=\"new_description_$i\" type=hidden value=\"|
116 . $p{"description"} . qq|\">| . $p{"description"} . qq|</td>
117 <input name=\"new_parts_id_$i\" type=hidden value=\"| . $p{"id"} . qq|\">
124 qq|<tr><td colspan=3><hr size=3 noshade></td></tr>
127 <input type=hidden name=nextsub value=\"do_add\">
128 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
131 $lxdebug->leave_sub();
134 sub print_customer_selection {
135 $lxdebug->enter_sub();
137 set_std_hidden("parts_id", "partnumber", "description");
143 <th class=listtop colspan=5>|
144 . $locale->text('Select from one of the names below') . qq|</th>
147 <tr class=listheading>
149 <th class=listheading>| . $locale->text('Customer Number') . qq|</th>
150 <th class=listheading>| . $locale->text('Company Name') . qq|</th>
151 <th class=listheading>| . $locale->text('Street') . qq|</th>
152 <th class=listheading>| . $locale->text('Zipcode') . qq|</th>
153 <th class=listheading>| . $locale->text('City') . qq|</th>
157 print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
160 for ($i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
161 %c = %{ $form->{"all_customers"}->[$i - 1] };
163 $checked = "checked";
169 qq|<tr class=listrow$j>
170 <td><input name=ndx class=radio type=radio value=$i $checked></td>
171 <td><input name=\"new_customer_id_$i\" type=hidden value=\"|
172 . $c{"id"} . qq|\">$c{"customernumber"}</td>
173 <td><input name=\"new_customer_name_$i\" type=hidden value=\"|
174 . $c{"name"} . qq|\">$c{"name"}</td>
175 <td>$c{"street"}</td>
176 <td>$c{"zipcode"}</td>
187 <input type=hidden name=nextsub value=\"do_add\">
188 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
191 $lxdebug->leave_sub();
194 sub print_license_form {
195 $lxdebug->enter_sub();
200 <th class=listtop>| . $locale->text("Add License") . qq|</th>
205 <th align=right>| . $locale->text('Part Number') . qq|</th>
206 <td><input name=partnumber value=\"|
207 . quot($form->{"partnumber"}) . qq|\"></td>
210 <th align=right>| . $locale->text('Description') . qq|</th>
211 <td><input name=description value=\"|
212 . quot($form->{"description"}) . qq|\"></td>
215 <th align=right>| . $locale->text('Company Name') . qq|</th>|);
216 if ($form->{"all_customer"}) {
217 print(qq|<td><select name=\"customer\">|);
218 foreach (@{ $form->{"all_customer"} }) {
219 if (!defined($form->{"customer_id"})) {
220 $form->{"customer_id"} = $_->{"id"};
222 $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
223 print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
225 print(qq|</select></td>|);
227 print( qq|<td><input name=customer_name value=\"|
228 . quot($form->{"customer_name"})
234 <th align=right>| . $locale->text('Comment') . qq|</th>
235 <td><input name=comment value=\"|
236 . quot($form->{"comment"}) . qq|\"></td>
239 <th align=right>| . $locale->text('Valid until') . qq|</th>
240 <td><input id=validuntil name=validuntil value=\"|
241 . quot($form->{"validuntil"}) . qq|\">
242 <input type="button" name="validuntil" id="trigger_validuntil" value="?"></td>
245 <th align=right>| . $locale->text('Quantity') . qq|</th>
246 <td><input name=quantity value=\"|
247 . quot($form->{"quantity"}) . qq|\"></td>
250 <th align=right>| . $locale->text('License key') . qq|</th>
251 <td><input name=licensenumber value=\"|
252 . quot($form->{"licensenumber"}) . qq|\"></td>
255 <th align=right>| . $locale->text('Own Product') . qq|</th>
256 <td><input type=checkbox name=own_product value=1 checked></td>
260 <input type=submit name=action value=\"| . $locale->text('Update') . qq|\">
266 <input type=submit name=action value=\"|
267 . $locale->text('Save') . qq|\">\n|);
274 $form->write_trigger(\%myconfig, 1, "validuntil", "BL",
275 "trigger_validuntil"));
277 $lxdebug->leave_sub();
281 $lxdebug->enter_sub();
285 'The licensing module has been deactivated in lx-erp.conf.')
289 $form->{"initial"} = 1;
292 $lxdebug->leave_sub();
296 $lxdebug->enter_sub();
297 $form->{"hidden"} = ["parts_id"];
300 if ($form->{"ndx"}) {
301 $ndx = $form->{"ndx"};
302 foreach (keys(%{$form})) {
303 next unless (/^new_.*_${ndx}$/);
306 $form->{$_} = $form->{"new_${_}_${ndx}"};
310 if ($form->{"customer"}) {
311 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
314 if ($form->{"customer_name"}) {
315 LICENSES->get_customers(\%myconfig, $form);
316 if (scalar(@{ $form->{"all_customers"} }) == 1) {
317 %c = %{ $form->{"all_customers"}->[0] };
318 $form->{"customer_id"} = $c{"id"};
319 $form->{"customer_name"} = $c{"name"};
320 } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
321 $form->{"customer_name"} = "";
322 delete($form->{"customer_id"});
324 print_customer_selection();
327 } elsif (defined($form->{"customer_name"})) {
328 delete($form->{"customer_id"});
331 if ($form->{"partnumber"} || $form->{"description"}) {
332 $form->{"sort"} = "p.partnumber";
333 $form->{searchitems} = "part";
334 IC->all_parts(\%myconfig, $form);
335 if (scalar(@{ $form->{"parts"} }) == 1) {
336 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
337 ("partnumber", "description"));
338 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
340 } elsif (scalar(@{ $form->{"parts"} }) == 0) {
341 map({ $form->{$_} = ""; }("partnumber", "description", "parts_id"));
344 print_part_selection();
348 delete($form->{"parts_id"});
351 $form->all_vc(\%myconfig, "customer", "");
353 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
356 $lxdebug->leave_sub();
360 $lxdebug->enter_sub();
362 $lxdebug->leave_sub();
366 $lxdebug->enter_sub();
367 &{ $form->{nextsub} };
368 $lxdebug->leave_sub();
372 $lxdebug->enter_sub();
374 ($form->{customername}, $form->{customer_id}) = split /--/,
377 $form->isblank("customer", $locale->text('Customer missing!'));
379 if ( $form->{quantity} eq ""
380 || $form->{quantity} !~ /^[0-9]*$/
381 || $form->{quantity} < 1) {
382 $form->error($locale->text('Please enter a number of licenses.'));
385 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
386 $form->error($locale->text('Please enter a license key.'));
389 $rc = LICENSES->save_license(\%myconfig, \%$form);
391 # load previous variables
392 if ($form->{previousform}) {
394 # save the new form variables before splitting previousform
395 map { $newform{$_} = $form->{$_} } keys %$form;
397 $previousform = $form->unescape($form->{previousform});
399 # don't trample on previous variables
400 map { delete $form->{$_} } keys %newform;
402 # now take it apart and restore original values
403 foreach $item (split /&/, $previousform) {
404 ($key, $value) = split /=/, $item, 2;
406 $form->{$key} = $value;
409 $form->{"lizenzen_$form->{row}"} =
410 "<option value=$rc>$newform{licensenumber}</option>";
413 delete $form->{action};
415 # restore original callback
416 $callback = $form->unescape($form->{callback});
417 $form->{callback} = $form->unescape($form->{old_callback});
418 delete $form->{old_callback};
420 # put callback together
421 foreach $key (keys %$form) {
423 # do single escape for Apache 2.0
424 $value = $form->escape($form->{$key}, 1);
425 $callback .= qq|&$key=$value|;
427 $form->{callback} = $callback;
435 print("Die Lizenz wurde gespeichert.\n");
439 $lxdebug->leave_sub();
443 $lxdebug->enter_sub();
447 'The licensing module has been deactivated in lx-erp.conf.')
457 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
462 <th align=right>| . $locale->text('Part Number') . qq|</th>
463 <td><input name=partnumber></td>
466 <th align=right>| . $locale->text('Description') . qq|</th>
467 <td><input name=description></td>
470 <th align=right>| . $locale->text('Company Name') . qq|</th>
471 <td><input name=customer_name></td>
474 <th align=right>| . $locale->text('Include in Report') . qq|</th>
475 <td><input type=radio name=all value=1 checked>|
476 . $locale->text('All')
477 . qq| <input type=radio name=all value=0>|
478 . $locale->text('Expiring in x month(s)')
479 . qq| <input size=4 name=expiring_in value="1"><br>
480 <input type=checkbox name=show_expired value=1>|
481 . $locale->text('Expired licenses') . qq|</td>
485 <tr><td colspan=4><hr size=3 noshade></td></tr>
488 <input type=hidden name=nextsub value=\"do_search\">
489 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
494 $lxdebug->leave_sub();
498 $lxdebug->enter_sub();
499 LICENSES->search(\%myconfig, $form);
503 ("db", "path", "login", "password",
504 "partnumber", "description", "customer_name", "all",
505 "expiring_in", "show_expired")
507 $callback .= "\&${_}=" . $form->escape($form->{$_}, 1);
509 $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
510 $invdetails = "is.pl?action=edit" . $callback . "\&id=";
511 $callback = $form->{"script"} . "?action=do_search" . $callback;
513 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
514 $form->{"sortasc"} *= 1;
515 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
516 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
517 if ($form->{"sortby"} eq $_) {
518 $columns{$_} .= (1 - $form->{"sortasc"});
530 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
533 if (scalar(@{ $form->{"licenses"} }) == 0) {
536 "No licenses were found that match the search criteria.")
537 . qq|</body></html>|);
546 <th class=listtop><a class=listheading href=\"|
547 . $columns{"partnumber"} . "\">"
548 . $locale->text('Part Number')
550 <th class=listtop><a class=listheading href=\"|
551 . $columns{"description"} . "\">"
552 . $locale->text('Description')
554 <th class=listtop><a class=listheading href=\"|
555 . $columns{"name"} . "\">" . $locale->text('Company Name') . qq|</a></th>
556 <th class=listtop><a class=listheading href=\"|
557 . $columns{"validuntil"} . "\">"
558 . $locale->text('Valid until')
560 <th class=listtop><a class=listheading href=\"|
561 . $columns{"invnumber"} . "\">"
562 . $locale->text('Invoice Number')
568 for ($i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
569 $ref = $form->{"licenses"}->[$i];
573 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
574 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
575 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
576 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
577 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
581 ? qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>|
589 $form->{"num_licenses"} = scalar(@{ $form->{"licenses"} });
590 push(@{ $form->{"hidden"} }, "num_licenses");
597 <td><hr size=3 noshade></td>
603 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
607 $lxdebug->leave_sub();
611 $lxdebug->enter_sub();
612 LICENSES->get_license(\%myconfig, $form);
614 { $form->{$_} = $form->{"license"}->{$_}; } keys(%{ $form->{"license"} }));
622 <th class=listtop>| . $locale->text("View License") . qq|</th>
627 <th align=right>| . $locale->text('Part Number') . qq|</th>
628 <td>$form->{"partnumber"}</td>
631 <th align=right>| . $locale->text('Description') . qq|</th>
632 <td>$form->{"description"}</td>
635 <th align=right>| . $locale->text('Company Name') . qq|</th>
636 <td>$form->{"name"}</td>
639 <th align=right>| . $locale->text('Comment') . qq|</th>
640 <td>$form->{"comment"}</td>
643 <th align=right>| . $locale->text('Valid until') . qq|</th>
644 <td>$form->{"validuntil"}</td>
647 <th align=right>| . $locale->text('Quantity') . qq|</th>
648 <td>$form->{"quantity"}</td>
651 <th align=right>| . $locale->text('License key') . qq|</th>
652 <td>$form->{"licensenumber"}</td>
657 <td><hr size=3 noshade></td>
661 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
665 $lxdebug->leave_sub();