Leser: 1
8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
my ($dbh, $sth);
my %software;
my @installed;
my $iid = '1'; # Inventar-ID
# main
$dbh = &connect();
&fetch_software();
&fetch_installed($iid);
&html_selection();
$dbh->disconnect();
exit(0);
# subs
sub is_in {
# is_in gibt die Anzahl an Übereinstimmungen eines Elementes
# zu einer Menge in einem Array zurück.
my $test = shift @_;
my @in = @_;
my $answer = 0;
for (@in) {
$answer++ if ($test eq $_);
}
return $answer;
}
sub connect {
return DBI->connect ("DBI:mysql:host=192.168.0.1;database=meine",
"ich", "geheim", {PrintError => 0, RaiseError => 1});
}
sub fetch_installed {
my $iid = shift @_;
$sth = $dbh->prepare (" SELECT SOID
FROM nutzt_software
WHERE IID = $iid
");
$sth->execute();
while (my ($soid) = $sth->fetchrow_array()) { push @installed, $soid; }
$sth->finish();
}
sub fetch_software {
$sth = $dbh->prepare (" SELECT SOID, Produkt
FROM Software ");
$sth->execute();
while (my ($soid, $produkt) = $sth->fetchrow_array()) {
$software{$soid}=$produkt;
}
$sth->finish();
}
sub html_selection {
print "<select name='Installationen'>\n";
for (sort(keys(%software))) {
if (&is_in($_, @installed)) {
print "<option selected>$software{$_}</option>\n";
} else {
print "<option>$software{$_}</option>\n";
}
}
print "</select>\n";
}
QuoteCode: (dl )1
2
3
4
5
6
7
8
9
10
11sub html_selection {
print "<select name='Installationen'>\n";
for (sort(keys(%software))) {
if (&is_in($_, @installed)) {
print "<option selected>$software{$_}</option>\n";
} else {
print "<option>$software{$_}</option>\n";
}
}
print "</select>\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use CGI qw/:all/;
my %software = qw/ldms LanDeskManagement sap SAP_GUI_6.2 notes LotusNotes/;
my @installed = qw/ldms notes/;
my $select = scrolling_list(-name=>'Installationen',
-multiple=>1,
-values=>[sort keys %software],
-default=>[@installed],
-labels=>\%software
);
print $select;
_ _ END _ _
<select name="Installationen" size="3" multiple="multiple">
<option selected="selected" value="ldms">LanDeskManagement</option>
<option selected="selected" value="notes">LotusNotes</option>
<option value="sap">SAP_GUI_6.2</option>
</select>
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl -w
use strict;
use warnings;
my %hash = ( 1=>'Acrobat', 2=>'Notes', 3=>'CorelDraw' );
my @array;
for (keys(%hash)) { push @array, "$hash{$_}#$_"; }
for (sort(@array)) {
m/(\w+)\#(\d+)/;
print "<option value='$2'>$1</option>\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use strict;
use CGI qw/:all/;
my %software = qw/2 LanDeskManagement 3 SAP_GUI_6.2 1 LotusNotes/;
my @installed = qw/3 2/;
my $select = scrolling_list(-name=>'Installationen',
-multiple=>1,
-values=>[sort {$software{$a} cmp $software{$b}} keys %software],
-default=>[@installed],
-labels=>\%software
);
print $select;
_ _ END _ _
<select name="Installationen" size="3" multiple="multiple">
<option selected="selected" value="2">LanDeskManagement</option>
<option value="1">LotusNotes</option>
<option selected="selected" value="3">SAP_GUI_6.2</option>
</select>
8 Einträge, 1 Seite |