sub update {
$lxdebug->enter_sub();
- &check_salesman($form->{salesman});
-
- # $form->get_salesman(\%myconfig, $form->{salesman});
&display();
$lxdebug->leave_sub();
}
-sub check_salesman {
- $lxdebug->enter_sub();
-
- my ($name) = @_;
-
- my ($new_name, $new_id) = split /--/, $form->{$name};
- my $i = 0;
-
- # check name, combine name and id
- if ($form->{"oldsalesman"} ne $form->{"salesman"}) {
-
- # return one name or a list of names in $form->{name_list}
- if (($i = $form->get_salesman(\%myconfig, $name)) > 1) {
- &select_salesman($name);
- exit;
- }
-
- if ($i == 1) {
-
- # we got one name
- $form->{"salesman_id"} = $form->{salesman_list}[0]->{id};
- $form->{salesman} = $form->{salesman_list}[0]->{name};
- $form->{"oldsalesman"} = $form->{salesman};
-
- } else {
-
- # name is not on file
- # $locale->text('Customer not on file or locked!')
- # $locale->text('Vendor not on file or locked!')
- $msg = ucfirst $name . " not on file or locked!";
- $form->error($locale->text($msg));
- }
- }
-
- $lxdebug->leave_sub();
-
- return $i;
-}
-
-sub select_salesman {
- $lxdebug->enter_sub();
-
- my ($table) = @_;
-
- @column_index = qw(ndx name);
-
- $label = ucfirst $table;
- $column_data{ndx} = qq|<th> </th>|;
- $column_data{name} =
- qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
-
- # list items with radio button on a form
- $form->header;
-
- $title = $locale->text('Select from one of the names below');
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <th class=listtop>$title</th>
- </tr>
- <tr space=5></tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- map { print "\n$column_data{$_}" } @column_index;
-
- print qq|
- </tr>
-|;
-
- my $i = 0;
- foreach $ref (@{ $form->{salesman_list} }) {
- $checked = ($i++) ? "" : "checked";
-
- $ref->{name} =~ s/\"/"/g;
-
- $column_data{ndx} =
- qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{name} =
- qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
-
- $j++;
- $j %= 2;
- print qq|
- <tr class=listrow$j>|;
-
- map { print "\n$column_data{$_}" } @column_index;
-
- print qq|
- </tr>
-
-<input name="new_id_$i" type=hidden value=$ref->{id}>
-
-|;
-
- }
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input name=lastndx type=hidden value=$i>
-
-|;
-
- # delete variables
- map { delete $form->{$_} } qw(action name_list header);
-
- # save all other form variables
- foreach $key (keys %${form}) {
- $form->{$key} =~ s/\"/"/g;
- print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
- }
-
- print qq|
-<input type=hidden name=nextsub value=salesman_selected>
-
-<input type=hidden name=vc value=$table>
-<br>
-<input class=submit type=submit name=action value="|
- . $locale->text('Continue') . qq|">
-</form>
-
-</body>
-</html>
-|;
-
- $lxdebug->leave_sub();
-}
-
-sub salesman_selected {
- $lxdebug->enter_sub();
-
- # replace the variable with the one checked
-
- # index for new item
- $i = $form->{ndx};
-
- $form->{salesman} = $form->{"new_name_$i"};
- $form->{"salesman_id"} = $form->{"new_id_$i"};
- $form->{"oldsalesman"} = $form->{salesman};
-
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- map { delete $form->{"new_${_}_$i"} } (id, name);
- }
-
- map { delete $form->{$_} } qw(ndx lastndx nextsub);
-
- &update(1);
-
- $lxdebug->leave_sub();
-}
-
sub get_contact {
$lxdebug->enter_sub();