This file is indexed.

/usr/lib/interchange/Vend/Options.pm is in interchange 5.7.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Vend::Options - Interchange item options base module
#
# $Id: Options.pm,v 2.8 2007-08-09 13:40:53 pajamian Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA  02110-1301  USA.

package Vend::Options;
require Exporter;

$VERSION = substr(q$Revision: 2.8 $, 10);

@ISA = qw(Exporter);

@EXPORT = qw(
				find_joiner
				find_options_type
				find_sort
				inventory_function
				option_cost
				remap_option_record
		);

use Vend::Util;
use Vend::Data;
use Vend::Interpolate;
use strict;

sub remap_option_record {
	my ($record, $map) = @_;

	my %rec;
	my @del;
	my ($k, $v);
	while (($k, $v) = each %$map) {
		next unless defined $record->{$v};
		$rec{$k} = $record->{$v};
		push @del, $v;
	}
	delete @{$record}{@del};
	@{$record}{keys %rec} = (values %rec);
	
	return;
}

sub find_options_type {
	my ($item, $opt) = @_;

	my $attrib;
	return $item->{$attrib}
		if	$attrib = $Vend::Cfg->{OptionsAttribute}
		and defined $item->{$attrib};

	my $sku = $item->{mv_sku} || $item->{code};

	$opt = get_option_hash($opt);

	my $module;

	if($Vend::Cfg->{OptionsEnable}) {
		my ($tab, $field) = split /:+/, $Vend::Cfg->{OptionsEnable};
		if(! $field) {
			$field = $tab;
			undef $tab;
		}
		elsif($tab =~ /=/) {
			my $att;
			($att, $tab) = split /\s*=\s*/, $tab;
			$attrib ||= $att;
		}
		$attrib ||= $field;
		$Vend::Cfg->{OptionsAttribute} ||= $attrib;

		if(! defined $item->{$attrib}) {
			$tab = $item->{mv_ib} || product_code_exists_tag($sku)
					or do {
						logOnce('error', "options: Unknown product %s.", $sku);
						return;
					};
			$item->{$attrib} = tag_data($tab, $field, $sku);
		}
		$module = $item->{$attrib} || '';
	}
	else {
		## Old style options
		my $loc = $Vend::Cfg->{Options_repository}{Old48} || {};
		my $table = $opt->{table}
				  ||= (
				  		$loc->{table} || $::Variable->{MV_OPTION_TABLE} || 'options'
					);
		my $db = $Vend::Interpolate::Db{$table} || database_exists_ref($table)
				or return;
		$db->record_exists($sku)
				or return;
		my $record = $opt->{options_record} = $db->row_hash($sku)
				or return;
		$opt->{options_db} = $db;
		remap_option_record($record, $loc->{map})
			if  $loc->{remap};

		return '' unless $record->{o_enable};

		$module = 'Old48';

		if($record->{o_matrix}) {
			$opt->{display_routine}
				= 'Vend::Options::Old48::display_options_matrix';
		}
		elsif($record->{o_modular}) {
			$module = 'Modular';
		}
		else {
			$opt->{display_routine}
				= 'Vend::Options::Old48::display_options_simple';
		}
	}

	return $module;
}

sub inventory_function {
	my $opt = shift;
	return unless $opt->{inventory};
	my $inv_func;
	my ($t, $c) = split /[.:]+/, $opt->{inventory};
	my $idb;
	if($idb = database_exists_ref($t)) {
		$inv_func = $idb->field_accessor($c);
	}
	return $inv_func;
}

sub find_joiner {
	my $opt = shift;
	if($opt->{report}) {
		$opt->{joiner}		||= ', ';
		$opt->{separator} 	||= ': ';
		$opt->{type}		||= 'display';
	}
	else {
		$opt->{joiner} ||= "<br$Vend::Xtrailer>";
	}
	return;
}

sub find_sort {
	my $opt = shift;
	my $db = shift;
	my $loc = shift || $Vend::Cfg->{Options_repository}{$opt->{options_type}} || {};
#::logDebug("called find_sort from " . scalar(caller()) . ", opt=" . ::uneval($opt));
	$opt->{sort} = defined $opt->{sort} ? $opt->{sort} : $loc->{sort};
	return '' unless $opt->{sort};
	my @fields = split /\s*,\s*/, $opt->{sort};
	my $map = $loc->{map} ||= {};
	for(@fields) {
		my $extra; 
		$extra = ' DESC' if s/\s+(r(?:ev(?:erse)?)?|desc(?:ending)?)//i;
		$_ = $map->{$_} || $_;
		unless (defined $db->test_column($_)) {
			logOnce(
				"%s options sort field %s does not exist, returning unsorted",
				'Matrix',
				$_,
				);
			return undef;
		}
		$_ .= $extra if $extra;
	}

	return "ORDER BY " . join(",", @fields);
}

sub tag_options {
	my ($sku, $opt) = @_;
	my $item;
	if(ref $sku) {
		$item = $sku;
		$sku = $item->{mv_sku} || $item->{code};
	}
	$item ||= { code => $sku };
	$opt = get_option_hash($opt);
	find_joiner($opt);

	my $module = find_options_type($item, $opt)
		or return '';
	$opt->{options_type} = $module;
#::logDebug("tag_options module=$module");

	my $loc = $Vend::Cfg->{Options_repository}{$module} || {};
	no strict 'refs';
	my $routine;
	if($opt->{admin_page}) {
		$opt->{routine_description} ||= "admin page";
		$routine = $opt->{admin_page_routine}
			||= "Vend::Options::${module}::admin_page";
	}
	else {
		$opt->{routine_description} ||= "display";
		$routine = $opt->{display_routine};
		$routine ||= $loc->{display_routine}
				||= "Vend::Options::${module}::display_options";
#::logDebug("tag_options display routine=$routine");
	}
	my $sub = \&{"$routine"};
	if(! defined $sub) {
		::logOnce(
			"Options type %s %s routine %s not found, aborting options for %s.",
			$module,
			$opt->{routine_description},
			$routine,
			$sku,
			);
		return undef;
	}
#::logDebug("main tag_options item=" . ::uneval($item) . ", opt=" . ::uneval($opt));
	return $sub->($item, $opt, $loc);
}

sub option_cost {
	my ($item, $table, $final) = @_;

	my $module = find_options_type($item)
		or return undef;
#::logDebug("price_options module=$module");
	my $loc = $Vend::Cfg->{Options_repository}{$module} || {};
	return undef if $loc->{no_pricing};
	no strict 'refs';
	my $routine = $loc->{price_routine};
	$routine ||= "Vend::Options::${module}::price_options";
	my $sub = \&{"$routine"};
#::logDebug("price_options sub=$sub");

	if(! defined $sub) {
		::logOnce(
			"Options type %s not found, aborting option_cost for %s.",
			$module,
			$item->{code},
			);
		return undef;
	}
	return $sub->($item, $table, $final, $loc);
}

1;
__END__