$json->ascii(1);
$json->allow_nonref(1);
-my $SIP_DATE_FORMAT = "%Y%m%d %H%M%S";
+use constant SIP_DATE_FORMAT => "%Y%m%d %H%M%S";
# TODO: move to config / database
my $config = {
$osrf_config = shift;
}
+my $config;
my $init_complete = 0;
sub init {
return if $init_complete;
OpenSRF::System->bootstrap_client(config_file => $osrf_config);
OpenILS::Utils::CStoreEditor->init;
- return Apache2::Const::OK;
+ my $e = new_editor();
+
+ my $settings = $e->retrieve_all_config_sip_setting;
+
+ $config = {
+ institutions => []
+ };
+
+ # Institution specific settings.
+ # In addition to the options, this tells us what institutions we support.
+ for my $set (grep {$_->institution ne '*'} @$settings) {
+ my $inst = $set->institution;
+ my $value = $json->decode($set->value);
+ my $name = $set->name;
+
+ my ($inst_conf) =
+ grep {$_->id eq $inst} @{$config->{institutions}} ||
+ { id => $inst,
+ currency => 'USD',
+ supports => [],
+ options => {}
+ };
+
+ $inst_conf->{options}->{$name} = $value;
+ }
+
+ # Global options only are only used when they do not replace
+ # institution-specific options.
+ for my $set (grep {$_->institution eq '*'} @$settings) {
+ my $name = $set->name;
+ my $value = $json->decode($set->value);
+
+ for my $inst_conf (@{$config->{institutions}}) {
+ $inst_conf->{options}->{$name} = $value
+ unless exists $inst_conf->{options}->{$name};
+ }
+ }
}
sub sipdate {
my $date = shift || DateTime->now;
- return $date->strftime($SIP_DATE_FORMAT);
+ return $date->strftime(SIP_DATE_FORMAT);
}
# False == 'N'
VALUES ('sip2', 'SIP2 Client Password', FALSE, 'bf', 5);
/* EXAMPLE SETTINGS
+
+-- Example linking a SIP password to the 'admin' account.
+SELECT actor.set_passwd(1, 'sip2', 'sip_password');
+
INSERT INTO config.sip_setting (institution, name, value)
VALUES
('*', 'allow_sc_status_before_login', 'true'),
+ ('*', 'currency', 'USD'),
('example', 'due_date_use_sip_date_format', 'false'),
('example', 'patron_status_permit_loans', 'false'),
('example', 'patron_status_permit_all', 'false'),
('example', 'msg64_hold_items_available', 'false')
-);
+;
+
*/
COMMIT;