Revision 4671a79f
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
bin/mozilla/ct.pl | ||
---|---|---|
1471 | 1471 |
sub update { |
1472 | 1472 |
$lxdebug->enter_sub(); |
1473 | 1473 |
|
1474 |
&check_salesman($form->{salesman}); |
|
1475 |
|
|
1476 |
# $form->get_salesman(\%myconfig, $form->{salesman}); |
|
1477 | 1474 |
&display(); |
1478 | 1475 |
$lxdebug->leave_sub(); |
1479 | 1476 |
} |
1480 | 1477 |
|
1481 |
sub check_salesman { |
|
1482 |
$lxdebug->enter_sub(); |
|
1483 |
|
|
1484 |
my ($name) = @_; |
|
1485 |
|
|
1486 |
my ($new_name, $new_id) = split /--/, $form->{$name}; |
|
1487 |
my $i = 0; |
|
1488 |
|
|
1489 |
# check name, combine name and id |
|
1490 |
if ($form->{"oldsalesman"} ne $form->{"salesman"}) { |
|
1491 |
|
|
1492 |
# return one name or a list of names in $form->{name_list} |
|
1493 |
if (($i = $form->get_salesman(\%myconfig, $name)) > 1) { |
|
1494 |
&select_salesman($name); |
|
1495 |
exit; |
|
1496 |
} |
|
1497 |
|
|
1498 |
if ($i == 1) { |
|
1499 |
|
|
1500 |
# we got one name |
|
1501 |
$form->{"salesman_id"} = $form->{salesman_list}[0]->{id}; |
|
1502 |
$form->{salesman} = $form->{salesman_list}[0]->{name}; |
|
1503 |
$form->{"oldsalesman"} = $form->{salesman}; |
|
1504 |
|
|
1505 |
} else { |
|
1506 |
|
|
1507 |
# name is not on file |
|
1508 |
# $locale->text('Customer not on file or locked!') |
|
1509 |
# $locale->text('Vendor not on file or locked!') |
|
1510 |
$msg = ucfirst $name . " not on file or locked!"; |
|
1511 |
$form->error($locale->text($msg)); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
|
|
1515 |
$lxdebug->leave_sub(); |
|
1516 |
|
|
1517 |
return $i; |
|
1518 |
} |
|
1519 |
|
|
1520 |
sub select_salesman { |
|
1521 |
$lxdebug->enter_sub(); |
|
1522 |
|
|
1523 |
my ($table) = @_; |
|
1524 |
|
|
1525 |
@column_index = qw(ndx name); |
|
1526 |
|
|
1527 |
$label = ucfirst $table; |
|
1528 |
$column_data{ndx} = qq|<th> </th>|; |
|
1529 |
$column_data{name} = |
|
1530 |
qq|<th class=listheading>| . $locale->text($label) . qq|</th>|; |
|
1531 |
|
|
1532 |
# list items with radio button on a form |
|
1533 |
$form->header; |
|
1534 |
|
|
1535 |
$title = $locale->text('Select from one of the names below'); |
|
1536 |
|
|
1537 |
print qq| |
|
1538 |
<body> |
|
1539 |
|
|
1540 |
<form method=post action=$form->{script}> |
|
1541 |
|
|
1542 |
<table width=100%> |
|
1543 |
<tr> |
|
1544 |
<th class=listtop>$title</th> |
|
1545 |
</tr> |
|
1546 |
<tr space=5></tr> |
|
1547 |
<tr> |
|
1548 |
<td> |
|
1549 |
<table width=100%> |
|
1550 |
<tr class=listheading>|; |
|
1551 |
|
|
1552 |
map { print "\n$column_data{$_}" } @column_index; |
|
1553 |
|
|
1554 |
print qq| |
|
1555 |
</tr> |
|
1556 |
|; |
|
1557 |
|
|
1558 |
my $i = 0; |
|
1559 |
foreach $ref (@{ $form->{salesman_list} }) { |
|
1560 |
$checked = ($i++) ? "" : "checked"; |
|
1561 |
|
|
1562 |
$ref->{name} =~ s/\"/"/g; |
|
1563 |
|
|
1564 |
$column_data{ndx} = |
|
1565 |
qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|; |
|
1566 |
$column_data{name} = |
|
1567 |
qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|; |
|
1568 |
|
|
1569 |
$j++; |
|
1570 |
$j %= 2; |
|
1571 |
print qq| |
|
1572 |
<tr class=listrow$j>|; |
|
1573 |
|
|
1574 |
map { print "\n$column_data{$_}" } @column_index; |
|
1575 |
|
|
1576 |
print qq| |
|
1577 |
</tr> |
|
1578 |
|
|
1579 |
<input name="new_id_$i" type=hidden value=$ref->{id}> |
|
1580 |
|
|
1581 |
|; |
|
1582 |
|
|
1583 |
} |
|
1584 |
|
|
1585 |
print qq| |
|
1586 |
</table> |
|
1587 |
</td> |
|
1588 |
</tr> |
|
1589 |
<tr> |
|
1590 |
<td><hr size=3 noshade></td> |
|
1591 |
</tr> |
|
1592 |
</table> |
|
1593 |
|
|
1594 |
<input name=lastndx type=hidden value=$i> |
|
1595 |
|
|
1596 |
|; |
|
1597 |
|
|
1598 |
# delete variables |
|
1599 |
map { delete $form->{$_} } qw(action name_list header); |
|
1600 |
|
|
1601 |
# save all other form variables |
|
1602 |
foreach $key (keys %${form}) { |
|
1603 |
$form->{$key} =~ s/\"/"/g; |
|
1604 |
print qq|<input name=$key type=hidden value="$form->{$key}">\n|; |
|
1605 |
} |
|
1606 |
|
|
1607 |
print qq| |
|
1608 |
<input type=hidden name=nextsub value=salesman_selected> |
|
1609 |
|
|
1610 |
<input type=hidden name=vc value=$table> |
|
1611 |
<br> |
|
1612 |
<input class=submit type=submit name=action value="| |
|
1613 |
. $locale->text('Continue') . qq|"> |
|
1614 |
</form> |
|
1615 |
|
|
1616 |
</body> |
|
1617 |
</html> |
|
1618 |
|; |
|
1619 |
|
|
1620 |
$lxdebug->leave_sub(); |
|
1621 |
} |
|
1622 |
|
|
1623 |
sub salesman_selected { |
|
1624 |
$lxdebug->enter_sub(); |
|
1625 |
|
|
1626 |
# replace the variable with the one checked |
|
1627 |
|
|
1628 |
# index for new item |
|
1629 |
$i = $form->{ndx}; |
|
1630 |
|
|
1631 |
$form->{salesman} = $form->{"new_name_$i"}; |
|
1632 |
$form->{"salesman_id"} = $form->{"new_id_$i"}; |
|
1633 |
$form->{"oldsalesman"} = $form->{salesman}; |
|
1634 |
|
|
1635 |
# delete all the new_ variables |
|
1636 |
for $i (1 .. $form->{lastndx}) { |
|
1637 |
map { delete $form->{"new_${_}_$i"} } (id, name); |
|
1638 |
} |
|
1639 |
|
|
1640 |
map { delete $form->{$_} } qw(ndx lastndx nextsub); |
|
1641 |
|
|
1642 |
&update(1); |
|
1643 |
|
|
1644 |
$lxdebug->leave_sub(); |
|
1645 |
} |
|
1646 |
|
|
1647 | 1478 |
sub get_contact { |
1648 | 1479 |
$lxdebug->enter_sub(); |
1649 | 1480 |
|
Auch abrufbar als: Unified diff
Überflüssigen Code bzgl. salesman entfernt (wird eh nicht benutzt, wenn Auswahl über Drop-Down-Box erfolgt).