+ my ($cgi) = @_;
+ my %columns;
+ my $columns_def_file = "columns.def";
+ my $htdocs = C4::Context->config('intrahtdocs');
+ my $section = 'intranet';
+
+ # We need the theme and the lang
+ # Since columns.def is not in the modules directory, we cannot sent it for the $tmpl var
+ my ($theme, $lang, $availablethemes) = C4::Templates::themelanguage($htdocs, 'about.tt', $section, $cgi);
+
+ my $full_path_to_columns_def_file="$htdocs/$theme/$lang/$columns_def_file";
+ open (my $fh, $full_path_to_columns_def_file);
+ while ( my $input = <$fh> ){
+ chomp $input;
+ if ( $input =~ m|<field name="(.*)">(.*)</field>| ) {
+ my ( $field, $translation ) = ( $1, $2 );
+ $columns{$field} = $translation;
+ }
+ }
+ close $fh;
+ return \%columns;
+}
+
+=head2 build_authorised_value_list($authorised_value)
+
+Returns an arrayref - hashref pair. The hashref consists of
+various code => name lists depending on the $authorised_value.
+The arrayref is the hashref keys, in appropriate order
+
+=cut
+
+sub build_authorised_value_list {
+ my ( $authorised_value ) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my @authorised_values;
+ my %authorised_lib;
+
+ # builds list, depending on authorised value...
+ if ( $authorised_value eq "branches" ) {
+ my $branches = GetBranchesLoop();
+ foreach my $thisbranch (@$branches) {
+ push @authorised_values, $thisbranch->{value};
+ $authorised_lib{ $thisbranch->{value} } = $thisbranch->{branchname};
+ }
+ } elsif ( $authorised_value eq "itemtypes" ) {
+ my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
+ $sth->execute;
+ while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
+ push @authorised_values, $itemtype;
+ $authorised_lib{$itemtype} = $description;
+ }
+ } elsif ( $authorised_value eq "cn_source" ) {
+ my $class_sources = GetClassSources();
+ my $default_source = C4::Context->preference("DefaultClassificationSource");
+ foreach my $class_source ( sort keys %$class_sources ) {
+ next
+ unless $class_sources->{$class_source}->{'used'}
+ or ( $class_source eq $default_source );
+ push @authorised_values, $class_source;
+ $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
+ }
+ } elsif ( $authorised_value eq "categorycode" ) {
+ my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
+ $sth->execute;
+ while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
+ push @authorised_values, $categorycode;
+ $authorised_lib{$categorycode} = $description;
+ }
+
+ #---- "true" authorised value
+ } else {
+ my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
+
+ $authorised_values_sth->execute($authorised_value);
+
+ while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
+ push @authorised_values, $value;
+ $authorised_lib{$value} = $lib;
+
+ # For item location, we show the code and the libelle
+ $authorised_lib{$value} = $lib;
+ }
+ }
+
+ return (\@authorised_values, \%authorised_lib);
+}
+
+=head2 GetReservedAuthorisedValues
+
+ my %reserved_authorised_values = GetReservedAuthorisedValues();
+
+Returns a hash containig all reserved words
+
+=cut
+
+sub GetReservedAuthorisedValues {
+ my %reserved_authorised_values =
+ map { $_ => 1 } ( 'date',
+ 'branches',
+ 'itemtypes',
+ 'cn_source',
+ 'categorycode' );
+
+ return \%reserved_authorised_values;
+}
+
+
+=head2 IsAuthorisedValueValid
+
+ my $is_valid_ath_value = IsAuthorisedValueValid($authorised_value)
+
+Returns 1 if $authorised_value is on the reserved authorised values list or
+in the authorised value categories defined in
+
+=cut
+
+sub IsAuthorisedValueValid {
+
+ my $authorised_value = shift;
+ my $reserved_authorised_values = GetReservedAuthorisedValues();
+
+ if ( exists $reserved_authorised_values->{$authorised_value} ||
+ IsAuthorisedValueCategory($authorised_value) ) {
+ return 1;
+ }
+
+ return 0;
+}
+
+=head2 GetParametersFromSQL
+
+ my @sql_parameters = GetParametersFromSQL($sql)
+
+Returns an arrayref of hashes containing the keys name and authval
+
+=cut
+
+sub GetParametersFromSQL {
+
+ my $sql = shift ;
+ my @split = split(/<<|>>/,$sql);
+ my @sql_parameters = ();
+
+ for ( my $i = 0; $i < ($#split/2) ; $i++ ) {
+ my ($name,$authval) = split(/\|/,$split[$i*2+1]);
+ push @sql_parameters, { 'name' => $name, 'authval' => $authval };
+ }
+
+ return \@sql_parameters;
+}
+
+=head2 ValidateSQLParameters
+
+ my @problematic_parameters = ValidateSQLParameters($sql)
+
+Returns an arrayref of hashes containing the keys name and authval of
+those SQL parameters that do not correspond to valid authorised names