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();
51 <form method=post action=$form->{script}>|);
52 $lxdebug->leave_sub();
56 $lxdebug->enter_sub();
57 my @items = ("path", "login", "password", "old_callback", "previousform");
58 push(@items, @{$form->{"hidden"}});
60 print("<input type=hidden name=$_ value=\"" . quot($form->{$_}) . "\">\n");
67 $lxdebug->leave_sub();
71 $lxdebug->enter_sub();
77 $lxdebug->leave_sub();
80 sub print_part_selection {
81 $lxdebug->enter_sub();
83 set_std_hidden("business");
89 <th class=listtop colspan=5>| .
90 $locale->text('Select from one of the items below') . qq|</th>
93 <tr class=listheading>
95 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
96 <th class=listheading>| . $locale->text('Description'). qq|</th>
101 for ($i = 1; $i <= scalar(@{$form->{"parts"}}); $i++) {
102 %p = %{$form->{"parts"}->[$i - 1]};
104 $checked = "checked";
109 print(qq|<tr class=listrow$j>
110 <td><input name=ndx class=radio type=radio value=$i $checked></td>
111 <td><input name=\"new_partnumber_$i\" type=hidden value=\"| .
112 $p{"partnumber"} . qq|\">| . $p{"partnumber"} . qq|</td>
113 <td><input name=\"new_description_$i\" type=hidden value=\"| .
114 $p{"description"} . qq|\">| . $p{"description"} . qq|</td>
115 <input name=\"new_parts_id_$i\" type=hidden value=\"| .
122 print(qq|<tr><td colspan=3><hr size=3 noshade></td></tr>
125 <input type=hidden name=nextsub value=\"do_add\">
126 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
129 $lxdebug->leave_sub();
132 sub print_customer_selection {
133 $lxdebug->enter_sub();
135 set_std_hidden("parts_id", "partnumber", "description");
140 <th class=listtop colspan=5>| .
141 $locale->text('Select from one of the names below') . qq|</th>
144 <tr class=listheading>
146 <th class=listheading>| . $locale->text('Customer Number') . qq|</th>
147 <th class=listheading>| . $locale->text('Company Name'). qq|</th>
148 <th class=listheading>| . $locale->text('Street'). qq|</th>
149 <th class=listheading>| . $locale->text('Zipcode'). qq|</th>
150 <th class=listheading>| . $locale->text('City'). qq|</th>
154 print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
157 for ($i = 1; $i <= scalar(@{$form->{"all_customers"}}); $i++) {
158 %c = %{$form->{"all_customers"}->[$i - 1]};
160 $checked = "checked";
165 print(qq|<tr class=listrow$j>
166 <td><input name=ndx class=radio type=radio value=$i $checked></td>
167 <td><input name=\"new_customer_id_$i\" type=hidden value=\"| .
168 $c{"id"} . qq|\">$c{"customernumber"}</td>
169 <td><input name=\"new_customer_name_$i\" type=hidden value=\"| .
170 $c{"name"} . qq|\">$c{"name"}</td>
171 <td>$c{"street"}</td>
172 <td>$c{"zipcode"}</td>
182 <input type=hidden name=nextsub value=\"do_add\">
183 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
186 $lxdebug->leave_sub();
189 sub print_license_form {
190 $lxdebug->enter_sub();
194 <th class=listtop>| . $locale->text("Add License") . qq|</th>
199 <th align=right>| . $locale->text('Part Number') . qq|</th>
200 <td><input name=partnumber value=\"| . quot($form->{"partnumber"}) .
204 <th align=right>| . $locale->text('Description') . qq|</th>
205 <td><input name=description value=\"| . quot($form->{"description"}) .
209 <th align=right>| . $locale->text('Company Name') . qq|</th>|);
210 if ($form->{"all_customer"}) {
211 print(qq|<td><select name=\"customer\">|);
212 foreach (@{$form->{"all_customer"}}) {
213 if (!defined($form->{"customer_id"})) {
214 $form->{"customer_id"} = $_->{"id"};
216 $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
217 print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
219 print(qq|</select></td>|);
221 print(qq|<td><input name=customer_name value=\"| .
222 quot($form->{"customer_name"}) . qq|\"></td>|);
226 <th align=right>| . $locale->text('Comment') . qq|</th>
227 <td><input name=comment value=\"| .
228 quot($form->{"comment"}) . qq|\"></td>
231 <th align=right>| . $locale->text('Valid until') . qq|</th>
232 <td><input name=validuntil value=\"| .
233 quot($form->{"validuntil"}) . qq|\"></td>
236 <th align=right>| . $locale->text('Quantity') . qq|</th>
237 <td><input name=quantity value=\"| .
238 quot($form->{"quantity"}) . qq|\"></td>
241 <th align=right>| . $locale->text('License key') . qq|</th>
242 <td><input name=licensenumber value=\"| .
243 quot($form->{"licensenumber"}) . qq|\"></td>
246 <th align=right>| . $locale->text('Own Product') . qq|</th>
247 <td><input type=checkbox name=own_product value=1 checked></td>
251 <input type=submit name=action value=\"| . $locale->text('Update') . qq|\">
255 <input type=submit name=action value=\"| . $locale->text('Save') .
262 $lxdebug->leave_sub();
266 $lxdebug->enter_sub();
268 $form->error($locale->text('The licensing module has been deactivated in lx-erp.conf.'));
271 $form->{"initial"} = 1;
274 $lxdebug->leave_sub();
278 $lxdebug->enter_sub();
279 $form->{"hidden"} = ["parts_id"];
282 if ($form->{"ndx"}) {
283 $ndx = $form->{"ndx"};
284 foreach (keys(%{$form})) {
285 next unless (/^new_.*_${ndx}$/);
288 $form->{$_} = $form->{"new_${_}_${ndx}"};
292 if ($form->{"customer"}) {
293 $form->{"customer_id"} = (split(/--/, $form->{"customer"}))[1];
296 if ($form->{"customer_name"}) {
297 LICENSES->get_customers(\%myconfig, $form);
298 if (scalar(@{$form->{"all_customers"}}) == 1) {
299 %c = %{$form->{"all_customers"}->[0]};
300 $form->{"customer_id"} = $c{"id"};
301 $form->{"customer_name"} = $c{"name"};
302 } elsif (scalar(@{$form->{"all_customers"}}) == 0) {
303 $form->{"customer_name"} = "";
304 delete($form->{"customer_id"});
306 print_customer_selection();
309 } elsif (defined($form->{"customer_name"})) {
310 delete($form->{"customer_id"});
313 if ($form->{"partnumber"} || $form->{"description"}) {
314 $form->{"sort"} = "p.partnumber";
315 $form->{searchitems} = "part";
316 IC->all_parts(\%myconfig, $form);
317 if (scalar(@{$form->{"parts"}}) == 1) {
318 map({ $form->{$_} = $form->{"parts"}->[0]->{$_}; }
319 ("partnumber", "description"));
320 $form->{"parts_id"} = $form->{"parts"}->[0]->{"id"};
322 } elsif (scalar(@{$form->{"parts"}}) == 0) {
323 map({ $form->{$_} = ""; } ("partnumber", "description", "parts_id"));
326 print_part_selection();
330 delete($form->{"parts_id"});
333 $form->all_vc(\%myconfig, "customer", "");
335 print_license_form($form->{"parts_id"} && $form->{"customer_id"});
338 $lxdebug->leave_sub();
342 $lxdebug->enter_sub();
344 $lxdebug->leave_sub();
348 $lxdebug->enter_sub();
349 &{ $form->{nextsub} };
350 $lxdebug->leave_sub();
354 $lxdebug->enter_sub();
356 ($form->{customername}, $form->{customer_id}) = split /--/, $form->{customer};
358 $form->isblank("customer", $locale->text('Customer missing!'));
360 if ($form->{quantity} eq "" || $form->{quantity} !~ /^[0-9]*$/ || $form->{quantity} < 1) {
361 $form->error($locale->text('Please enter a number of licenses.'));
364 if (!$form->{licensenumber} || $form->{licensenumber} eq "") {
365 $form->error($locale->text('Please enter a license key.'));
368 $rc = LICENSES->save_license(\%myconfig, \%$form);
370 # load previous variables
371 if ($form->{previousform}) {
372 # save the new form variables before splitting previousform
373 map { $newform{$_} = $form->{$_} } keys %$form;
375 $previousform = $form->unescape($form->{previousform});
377 # don't trample on previous variables
378 map { delete $form->{$_} } keys %newform;
380 # now take it apart and restore original values
381 foreach $item (split /&/, $previousform) {
382 ($key, $value) = split /=/, $item, 2;
384 $form->{$key} = $value;
387 $form->{"lizenzen_$form->{row}"} = "<option value=$rc>$newform{licensenumber}</option>";
390 delete $form->{action};
392 # restore original callback
393 $callback = $form->unescape($form->{callback});
394 $form->{callback} = $form->unescape($form->{old_callback});
395 delete $form->{old_callback};
398 # put callback together
399 foreach $key (keys %$form) {
400 # do single escape for Apache 2.0
401 $value = $form->escape($form->{$key}, 1);
402 $callback .= qq|&$key=$value|;
404 $form->{callback} = $callback;
412 print("Die Lizenz wurde gespeichert.\n");
416 $lxdebug->leave_sub();
420 $lxdebug->enter_sub();
422 $form->error($locale->text('The licensing module has been deactivated in lx-erp.conf.'));
430 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
435 <th align=right>| . $locale->text('Part Number') . qq|</th>
436 <td><input name=partnumber></td>
439 <th align=right>| . $locale->text('Description') . qq|</th>
440 <td><input name=description></td>
443 <th align=right>| . $locale->text('Company Name') . qq|</th>
444 <td><input name=customer_name></td>
447 <th align=right>| . $locale->text('Include in Report') . qq|</th>
448 <td><input type=radio name=all value=1 checked>| . $locale->text('All') .
449 qq| <input type=radio name=all value=0>| .
450 $locale->text('Expiring in x month(s)') . qq| <input size=4 name=expiring_in value="1"><br>
451 <input type=checkbox name=show_expired value=1>| .
452 $locale->text('Expired licenses') . qq|</td>
456 <tr><td colspan=4><hr size=3 noshade></td></tr>
459 <input type=hidden name=nextsub value=\"do_search\">
460 <input type=submit name=action value=\"| . $locale->text('Continue') . qq|\">
465 $lxdebug->leave_sub();
469 $lxdebug->enter_sub();
470 LICENSES->search(\%myconfig, $form);
473 foreach (("db", "path", "login", "password", "partnumber", "description",
474 "customer_name", "all", "expiring_in", "show_expired")) {
475 $callback .= "\&${_}=" . $form->escape($form->{$_}, 1);
477 $details = $form->{"script"} . "?action=details" . $callback . "\&id=";
478 $invdetails = "is.pl?action=edit" . $callback . "\&id=";
479 $callback = $form->{"script"} . "?action=do_search" . $callback;
481 $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
482 $form->{"sortasc"} *= 1;
483 foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
484 $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
485 if ($form->{"sortby"} eq $_) {
486 $columns{$_} .= (1 - $form->{"sortasc"});
497 <th class=listtop>| . $locale->text("Licenses") . qq|</th>
500 if (scalar(@{$form->{"licenses"}}) == 0) {
502 $locale->text("No licenses were found that match the search criteria.") .
511 <th class=listtop><a class=listheading href=\"| .
512 $columns{"partnumber"} . "\">" .
513 $locale->text('Part Number') . qq|</a></th>
514 <th class=listtop><a class=listheading href=\"| .
515 $columns{"description"} . "\">" .
516 $locale->text('Description') . qq|</a></th>
517 <th class=listtop><a class=listheading href=\"| .
518 $columns{"name"} . "\">" .
519 $locale->text('Company Name') . qq|</a></th>
520 <th class=listtop><a class=listheading href=\"| .
521 $columns{"validuntil"} . "\">" .
522 $locale->text('Valid until') . qq|</a></th>
523 <th class=listtop><a class=listheading href=\"| .
524 $columns{"invnumber"} . "\">" .
525 $locale->text('Invoice Number') . qq|</a></th>
530 for ($i = 0; $i < scalar(@{$form->{"licenses"}}); $i++) {
531 $ref = $form->{"licenses"}->[$i];
534 <td><input type=hidden name=id_$i value=| . $ref->{"id"} . qq|
535 <a href=\"${details}$ref->{"id"}\">$ref->{"partnumber"}</a></td>
536 <td><a href=\"${details}$ref->{"id"}\">$ref->{"description"}</a></td>
537 <td><a href=\"${details}$ref->{"id"}\">$ref->{"name"}</a></td>
538 <td><a href=\"${details}$ref->{"id"}\">$ref->{"validuntil"}</a></td>
540 ($ref->{"invnumber"} ?
541 qq|<a href=\"${invdetails}$ref->{"invnumber"}\">$ref->{"invnumber"}</a>| :
542 qq| |) . qq|</td>
547 $form->{"num_licenses"} = scalar(@{$form->{"licenses"}});
548 push(@{$form->{"hidden"}}, "num_licenses");
554 <td><hr size=3 noshade></td>
560 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
564 $lxdebug->leave_sub();
568 $lxdebug->enter_sub();
569 LICENSES->get_license(\%myconfig, $form);
570 map({ $form->{$_} = $form->{"license"}->{$_}; } keys(%{$form->{"license"}}));
577 <th class=listtop>| . $locale->text("View License") . qq|</th>
582 <th align=right>| . $locale->text('Part Number') . qq|</th>
583 <td>$form->{"partnumber"}</td>
586 <th align=right>| . $locale->text('Description') . qq|</th>
587 <td>$form->{"description"}</td>
590 <th align=right>| . $locale->text('Company Name') . qq|</th>
591 <td>$form->{"name"}</td>
594 <th align=right>| . $locale->text('Comment') . qq|</th>
595 <td>$form->{"comment"}</td>
598 <th align=right>| . $locale->text('Valid until') . qq|</th>
599 <td>$form->{"validuntil"}</td>
602 <th align=right>| . $locale->text('Quantity') . qq|</th>
603 <td>$form->{"quantity"}</td>
606 <th align=right>| . $locale->text('License key') . qq|</th>
607 <td>$form->{"licensenumber"}</td>
612 <td><hr size=3 noshade></td>
616 <input type=submit name=action value=\"| . $locale->text("Add") . qq|\">
620 $lxdebug->leave_sub();