Subversion Repositories ORC

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#######################################################################
2
# A set of functions to assist the scan data display tool.
3
#	Kept here to unclutter the main script.
4
#######################################################################
5
#
6
#
7
# $Log: scanFunctions.pm,v $
8
#
9
 
10
use DBI ();
11
 
12
my $internalDBH = &getDBConnection || die "Unable to connect to Database\n\n";
13
my $nowhan = $internalDBH->prepare("select now()");
14
$nowhan->execute();
15
our ($now) = $nowhan->fetchrow;
16
$now =~ s/ / at /;
17
 
18
 
19
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b};	}
20
 
21
 
22
sub fetchColEntries {
23
	my $colName = shift;
24
	my $selection = shift;
25
	my $table = $DBTABLE;
26
	my $optionList = "";
27
 
28
	# project table in new DB?
29
#	my $cathan = $internalDBH->prepare("select distinct $colName from $table where $colName <> '' and isNull($colName) = 0 order by $colName");
30
	my $cathan = $internalDBH->prepare("select distinct $colName from $table order by $colName");
31
 
32
	$cathan->execute();
33
	while (my ($cat) = $cathan->fetchrow) {
34
	  if ($cat eq "") { $cat = "-blank-"; }
35
	  if ($cat eq $selection) {
36
	    $optionList .= "<OPTION selected>$cat</OPTION>";
37
	  } else {
38
		  $optionList .= "<OPTION>$cat</OPTION>";
39
		}
40
	}
41
 
42
	return $optionList;
43
}
44
 
45
sub fetchDerbyNameWithRCid {
46
	my $optionList = "";
47
 
48
	my $cathan = $internalDBH->prepare("select RCid, derby_name from official order by derby_name");
49
 
50
	$cathan->execute();
51
	while (my ($id, $cat) = $cathan->fetchrow) {
52
		$optionList .= "<OPTION value=$id>$cat</OPTION>";
53
	}
54
 
55
	return $optionList;
56
}
57
 
58
 
59
sub generica {
60
	my $colName = shift;
61
	my $filter = shift;
62
 
63
	if ($colFilterTypeHash{$colName} eq 'select')
64
	{
65
		if (defined $filter)	{
66
			if ($filter eq "-blank-") {
67
				return "($colName = '' or isNull($colName) = 1)";
68
			}
69
#			$filter = s/'/\'/g;
70
			return "$colName = \"$filter\"";
71
		}
72
		else
73
		{
74
			my $thing = "filter-${colName}";
75
			my $categories = &fetchColEntries($colName, $FORM{$thing});
76
			my $Options = "<OPTION></OPTION>".$categories;
77
 
78
			$Options =~ s/>($FORM{$thing})/ selected>$1/;
79
			return "<SELECT name=filter-${colName} $auto2>$Options</SELECT>";
80
		}
81
	} elsif ($colFilterTypeHash{$colName} eq 'text') {
82
		if (defined $filter)
83
		{
84
			if ($filter =~ s/^=\s*//) { return "$colName = \"$filter\""; }
85
 
86
			if ($filter !~ s/^\^\s*//) { $filter = "\%$filter"; }
87
			if ($filter !~ s/\s*\$$//) { $filter = "$filter\%"; }
88
			$filter =~ s/\*/%/g;
89
 
90
			return "$colName like \"$filter\"";
91
		}
92
		else
93
		{
94
			my $thing = "filter-${colName}";
95
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $auto2>";
96
		}
97
	} elsif ($colFilterTypeHash{$colName} eq 'number') {
98
		if (defined $filter)
99
		{
100
			if ($filter =~ /^[>=<]\s*/) { return "$colName $filter"; }
101
			else { return "$colName = $filter"; }
102
		}
103
		else
104
		{
105
			my $thing = "filter-${colName}";
106
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $auto2>";
107
		}
108
	} elsif ($colFilterTypeHash{$colName} eq 'date') {
109
		if (defined $filter)
110
		{
111
			if ($filter =~ s/^<\s*//) { return "$colName < '$filter'"; }
112
			if ($filter =~ s/^>\s*//) { return "$colName > '$filter'"; }
113
 
114
			return "$colName = '$filter'";
115
		}
116
		else
117
		{
118
			my $thing = "filter-${colName}";
119
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $auto2>";
120
		}
121
	} elsif ($colFilterTypeHash{$colName} eq 'ERROR') {
122
		return "<center><strong><font color=red>ERROR!</font>";
123
	}
124
}
125
 
126
 
127
sub getData {
128
	my $fields = shift;
129
	my $whereClause = shift;
130
	my $table = shift;
131
	my $orderby = shift;
132
#	my $RCid = shift;
133
#	my $SecLvl = shift;
134
 
135
#	my $selected = join ", ",  @{$fields};
136
	my $selected = '*';
137
	$whereClause = scalar @{$whereClause} > 0 ? "where ".join " and ", @{$whereClause} : '';
138
        # project in new DB?
139
	# my $getMe = "select distinct $selected from HOST left join PRODUCT_INSTANCE on HOST.server = PRODUCT_INSTANCE.server left join project on hostID = projectHostID $whereClause";
140
	#my $getMe = "select distinct $selected from HOST left join PRODUCT_INSTANCE on HOST.server=PRODUCT_INSTANCE.server $whereClause and HOST.page=HOST.maxPage and PRODUCT_INSTANCE.page = PRODUCT_INSTANCE.maxPage";
141
 
142
	$orderby = $orderby eq "" ? "" : "order by $orderby";
143
#	my $getMe = "select distinct $selected from $table $whereClause $orderby";
144
	my $getMe = "select distinct * from $table $whereClause $orderby";
145
#warn($getMe);
146
 
147
	my $limhan = $internalDBH->prepare($getMe);			# Get the tickets from the DB
148
	$limhan->execute();
149
 
150
	my @results = ();
151
	while (my $P = $limhan->fetchrow_hashref)
152
	{
153
#		if ($P->{assignee_id} == $RCid or ($SecLvl >= 3 and $P->{derby_name})) {
154
#			$P->{derby_name} = "$P->{derby_name} <A HREF='#' onClick=\"window.open('make_lead_shift_change.pl?change=del&shift=$P->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[DROP]</a>";
155
#		} elsif (!$P->{derby_name}) {
156
#			$P->{derby_name} = "<A HREF='#' onClick=\"window.open('make_lead_shift_change.pl?change=add&shift=$P->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[SIGN UP]</a>";
157
#		}
158
 
159
		push @results, $P;
160
	}
161
 
162
	return \@results;
163
}
164
 
165
 
166
 
167
sub getDBConnection {
7 - 168
    $dbh = DBI->connect('DBI:mysql:database=rollerco_data;host=qnap.home.lan;port=3306', 'root', 'Jopy666!'
2 - 169
                   ) || die "Could not connect to database: $DBI::errstr";
170
    return $dbh;
171
}
172
 
173
 
174
sub inArray {
175
	my $item = shift;
176
	my $array = shift;
177
	foreach (@{$array})
178
	{
179
		return 1 if $item eq $_;
180
	}
181
	return 0;
182
}
183
 
184
sub whereInArray {
185
	my $item = shift;
186
	my $array = shift;
187
	my $i = 0;
188
	foreach (@{$array})
189
	{
190
		return $i if $item eq $_;
191
		$i++;
192
	}
193
	return -1;
194
}
195
 
196
 
197
 
198
# Leave this alone, it's needed to compile correctly
199
return 1;