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();
49 $form->{jsscript} = 1;
55 <form method=post action=$form->{script}>|);
56 $lxdebug->leave_sub();
60 $lxdebug->enter_sub();
61 my @items = qw(login password old_callback previousform);
62 push(@items, @{ $form->{"hidden"} });
64 print("<input type=hidden name=$_ value=\"" . quot($form->{$_}) . "\">\n"
73 $lxdebug->leave_sub();
77 $lxdebug->enter_sub();
78 $form->{"hidden"} = ["comment", "validuntil", "quantity", @_];
79 $lxdebug->leave_sub();
82 sub print_part_selection {
83 $lxdebug->enter_sub();
85 set_std_hidden("business");
92 <th class=listtop colspan=5>|
93 . $locale->text('Select from one of the items below') . qq|</th>
96 <tr class=listheading>
98 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
99 <th class=listheading>| . $locale->text('Description') . qq|</th>
104 for ($i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
105 %p = %{ $form->{"parts"}->[$i - 1] };
107 $checked = "checked";
113 qq|<tr class=listrow$j>
114 <td><input name=ndx class=radio type=radio value=$i $checked></td>
115 <td><input name=\"new_partnumber_$i\" type=hidden value=\"|
116 . $p{"partnumber"} . qq|\">| . $p{"partnumber"} . qq|</td>
117 <td><input name=\"new_description_$i\" type=hidden value=\"|
118 . $p{"description"} . qq|\">| . $p{"description"} . qq|</td>
119 <input name=\"new_parts_id_$i\" type=hidden value=\"| . $p{"id"} . qq|\">
126 qq|<tr><td colspan=3><hr size=3 noshade></td></tr>
129 <input type=hidden name=nextsub value=\"do_add\">
130 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
133 $lxdebug->leave_sub();
136 sub print_customer_selection {
137 $lxdebug->enter_sub();
139 set_std_hidden("parts_id", "partnumber", "description");
145 <th class=listtop colspan=5>|
146 . $locale->text('Select from one of the names below') . qq|</th>
149 <tr class=listheading>
151 <th class=listheading>| . $locale->text('Customer Number') . qq|</th>
152 <th class=listheading>| . $locale->text('Company Name') . qq|</th>
153 <th class=listheading>| . $locale->text('Street') . qq|</th>
154 <th class=listheading>| . $locale->text('Zipcode') . qq|</th>
155 <th class=listheading>| . $locale->text('City') . qq|</th>
159 print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
162 for ($i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
163 %c = %{ $form->{"all_customers"}->[$i - 1] };
165 $checked = "checked";
171 qq|<tr class=listrow$j>
172 <td><input name=ndx class=radio type=radio value=$i $checked></td>
173 <td><input name=\"new_customer_id_$i\" type=hidden value=\"|
174 . $c{"id"} . qq|\">$c{"customernumber"}</td>
175 <td><input name=\"new_customer_name_$i\" type=hidden value=\"|
176 . $c{"name"} . qq|\">$c{"name"}</td>
177 <td>$c{"street"}</td>
178 <td>$c{"zipcode"}</td>
189 <input type=hidden name=nextsub value=\"do_add\">
190 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
193 $lxdebug->leave_sub();
196 sub print_license_form {
197 $lxdebug->enter_sub();
202 <th class=listtop>| . $locale->text("Add License") . qq|</th>
207 <th align=right>| . $locale->text('Part Number') . qq|</th>
208 <td><input name=partnumber value=\"|
209 . quot($form->{"partnumber"}) . qq|\"></td>
212 <th align=right>| . $locale->text('Description') . qq|</th>
213 <td><input name=description value=\"|
214 . quot($form->{"description"}) . qq|\"></td>
217 <th align=right>| . $locale->text('Company Name') . qq|</th>|);
218 if ($form->{"all_customer"}) {
219 print(qq|<td><select name=\"customer\">|);
220 foreach (@{ $form->{"all_customer"} }) {
221 if (!defined($form->{"customer_id"})) {
222 $form->{"customer_id"} = $_->{"id"};
224 $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
225 print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
227 print(qq|</select></td>|);
229 print( qq|<td><input name=customer_name value=\"|
230 . quot($form->{"customer_name"})
236 <th align=right>| . $locale->text('Comment') . qq|</th>
237 <td><input name=comment value=\"|
238 . quot($form->{"comment"}) . qq|\"></td>
241 <th align=right>| . $locale->text('Valid until') . qq|</th>
242 <td><input id=validuntil name=validuntil value=\"|
243 . quot($form->{"validuntil"}) . qq|\">
244 <input type="button" name="validuntil" id="trigger_validuntil" value="?"></td>
247 <th align=right>| . $locale->text('Quantity') . qq|</th>
248 <td><input name=quantity value=\"|
249 . quot($form->{"quantity"}) . qq|\"></td>
252 <th align=right>| . $locale->text('License key') . qq|</th>
253 <td><input name=licensenumber value=\"|
254 . quot($form->{"licensenumber"}) . qq|\"></td>
257 <th align=right>| . $locale->text('Own Product') . qq|</th>
258 <td><input type=checkbox name=own_product value=1 checked></td>
262 <input type=submit name=action value=\"| . $locale->text('Update') . qq|\">
268 <input type=submit name=action value=\"|
269 . $locale->text('Save') . qq|\">\n|);
276 $form->write_trigger(\%myconfig, 1, "validuntil", "BL",
277 "trigger_validuntil"));
279 $lxdebug->leave_sub();
283 $lxdebug->enter_sub();
287 'The licensing module has been deactivated in lx-erp.conf.')
291 $form->{"initial"} = 1;
294 $lxdebug->leave_sub();
298 $lxdebug->enter_sub();
299 $form->{"hidden"} = ["parts_id"];
302 if ($form->{"ndx"}) {
303 $ndx = $form->{"ndx"};
304 foreach (keys(%{$form})) {
305 next unless (/^new_.*_${ndx}$/);
308 $form->{$_} = $form->{"new_${_}_${ndx}"};
312 if ($form->{"customer"}) {
313 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
316 if ($form->{"customer_name"}) {
317 LICENSES->get_customers(\%myconfig, $form);
318 if (scalar(@{ $form->{"all_customers"} }) == 1) {
319 %c = %{ $form->{"all_customers"}->[0] };
320 $form->{"customer_id"} = $c{"id"};
321 $form->{"customer_name"} = $c{"name"};
322 } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
323 $form->{"customer_name"} = "";
324 delete($form->{"customer_id"});
326 print_customer_selection();
329 } elsif (defined($form->{"customer_name"})) {
330 delete($form->{"customer_id"});
333 if ($form->{"partnumber"} || $form->{"description"}) {
334 $form->{"sort"} = "p.partnumber";
335 $form->{searchitems} = "part";
336 IC->all_parts(\%myconfig, $form);
337 if (scalar(@{ $form->{"parts"} }) == 1) {
338 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
339 ("partnumber", "description"));
340 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
342 } elsif (scalar(@{ $form->{"parts"} }) == 0) {
343 map({ $form->{$_} = ""; }("partnumber", "description", "parts_id"));
346 print_part_selection();
350 delete($form->{"parts_id"});
353 $form->all_vc(\%myconfig, "customer", "");
355 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
358 $lxdebug->leave_sub();
362 $lxdebug->enter_sub();
364 $lxdebug->leave_sub();
368 $lxdebug->enter_sub();
369 call_sub($form->{"nextsub"});
370 $lxdebug->leave_sub();
374 $lxdebug->enter_sub();
376 ($form->{customername}, $form->{customer_id}) = split /--/,
379 $form->isblank("customer", $locale->text('Customer missing!'));
381 if ( $form->{quantity} eq ""
382 || $form->{quantity} !~ /^[0-9]*$/
383 || $form->{quantity} < 1) {
384 $form->error($locale->text('Please enter a number of licenses.'));
387 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
388 $form->error($locale->text('Please enter a license key.'));
391 $rc = LICENSES->save_license(\%myconfig, \%$form);
393 # load previous variables
394 if ($form->{previousform}) {
396 # save the new form variables before splitting previousform
397 map { $newform{$_} = $form->{$_} } keys %$form;
399 $previousform = $form->unescape($form->{previousform});
401 # don't trample on previous variables
402 map { delete $form->{$_} } keys %newform;
404 # now take it apart and restore original values
405 foreach $item (split /&/, $previousform) {
406 ($key, $value) = split /=/, $item, 2;
408 $form->{$key} = $value;
411 $form->{"lizenzen_$form->{row}"} =
412 "<option value=$rc>$newform{licensenumber}</option>";
415 delete $form->{action};
417 # restore original callback
418 $callback = $form->unescape($form->{callback});
419 $form->{callback} = $form->unescape($form->{old_callback});
420 delete $form->{old_callback};
422 # put callback together
423 foreach $key (keys %$form) {
425 # do single escape for Apache 2.0
426 $value = $form->escape($form->{$key}, 1);
427 $callback .= qq|&$key=$value|;
429 $form->{callback} = $callback;
437 print("Die Lizenz wurde gespeichert.\n");
441 $lxdebug->leave_sub();
445 $lxdebug->enter_sub();
449 'The licensing module has been deactivated in lx-erp.conf.')
459 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
464 <th align=right>| . $locale->text('Part Number') . qq|</th>
465 <td><input name=partnumber></td>
468 <th align=right>| . $locale->text('Description') . qq|</th>
469 <td><input name=description></td>
472 <th align=right>| . $locale->text('Company Name') . qq|</th>
473 <td><input name=customer_name></td>
476 <th align=right>| . $locale->text('Include in Report') . qq|</th>
477 <td><input type=radio name=all value=1 checked>|
478 . $locale->text('All')
479 . qq| <input type=radio name=all value=0>|
480 . $locale->text('Expiring in x month(s)')
481 . qq| <input size=4 name=expiring_in value="1"><br>
482 <input type=checkbox name=show_expired value=1>|
483 . $locale->text('Expired licenses') . qq|</td>
487 <tr><td colspan=4><hr size=3 noshade></td></tr>
490 <input type=hidden name=nextsub value=\"do_search\">
491 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
496 $lxdebug->leave_sub();
500 $lxdebug->enter_sub();
501 LICENSES->search(\%myconfig, $form);
504 map { $callback .= "\&${_}=" . $form->escape($form->{$_}, 1) }
505 qw(db login password partnumber description customer_name all expiring_in show_expired);
506 $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
507 $invdetails = "is.pl?action=edit" . $callback . "\&id=";
508 $callback = $form->{"script"} . "?action=do_search" . $callback;
510 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
511 $form->{"sortasc"} *= 1;
512 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
513 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
514 if ($form->{"sortby"} eq $_) {
515 $columns{$_} .= (1 - $form->{"sortasc"});
527 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
530 if (scalar(@{ $form->{"licenses"} }) == 0) {
533 "No licenses were found that match the search criteria.")
534 . qq|</body></html>|);
543 <th class=listtop><a class=listheading href=\"|
544 . $columns{"partnumber"} . "\">"
545 . $locale->text('Part Number')
547 <th class=listtop><a class=listheading href=\"|
548 . $columns{"description"} . "\">"
549 . $locale->text('Description')
551 <th class=listtop><a class=listheading href=\"|
552 . $columns{"name"} . "\">" . $locale->text('Company Name') . qq|</a></th>
553 <th class=listtop><a class=listheading href=\"|
554 . $columns{"validuntil"} . "\">"
555 . $locale->text('Valid until')
557 <th class=listtop><a class=listheading href=\"|
558 . $columns{"invnumber"} . "\">"
559 . $locale->text('Invoice Number')
565 for ($i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
566 $ref = $form->{"licenses"}->[$i];
570 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
571 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
572 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
573 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
574 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
578 ? qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>|
586 $form->{"num_licenses"} = scalar(@{ $form->{"licenses"} });
587 push(@{ $form->{"hidden"} }, "num_licenses");
594 <td><hr size=3 noshade></td>
600 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
604 $lxdebug->leave_sub();
608 $lxdebug->enter_sub();
609 LICENSES->get_license(\%myconfig, $form);
611 { $form->{$_} = $form->{"license"}->{$_}; } keys(%{ $form->{"license"} }));
619 <th class=listtop>| . $locale->text("View License") . qq|</th>
624 <th align=right>| . $locale->text('Part Number') . qq|</th>
625 <td>$form->{"partnumber"}</td>
628 <th align=right>| . $locale->text('Description') . qq|</th>
629 <td>$form->{"description"}</td>
632 <th align=right>| . $locale->text('Company Name') . qq|</th>
633 <td>$form->{"name"}</td>
636 <th align=right>| . $locale->text('Comment') . qq|</th>
637 <td>$form->{"comment"}</td>
640 <th align=right>| . $locale->text('Valid until') . qq|</th>
641 <td>$form->{"validuntil"}</td>
644 <th align=right>| . $locale->text('Quantity') . qq|</th>
645 <td>$form->{"quantity"}</td>
648 <th align=right>| . $locale->text('License key') . qq|</th>
649 <td>$form->{"licensenumber"}</td>
654 <td><hr size=3 noshade></td>
658 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
662 $lxdebug->leave_sub();