#!/usr/bin/perl -w

use strict;

use lib "/www/opals-20140429-110405/module";
use Opals::Context("/etc/opals-20140429-110405/conf/_SITECODE_");
use Opals::Context;

my $dbh = Opals::Context->dbh();;
END {
    if ($dbh) {
        $dbh->disconnect();
    }
}

$| = 1;
# Codes start...
my ($count)=$dbh->selectrow_array("select count(*) from opl_preference where var='ILL_Messaging'");
if($count ==0){
    $dbh->do("replace into opl_preference values ('ILL_Messaging','0','Disable','0|1','radio','enable/disabled  ILL messaging',0,8,8)");
    $dbh->do("replace INTO opl_prefFormParam values ('ILL_Messaging',0,'Enable','1'),('ILL_Messaging',1,'Disable','0')");
}

($count)=$dbh->selectrow_array("select count(*) from opl_preference where var='libname_css'");
if($count ==0){
    my $fvMap={libname_css=> 'font-size:18pt;text-shadow: 0 3px 3px black; color:#00CCFF;font-family: arial',
               slogan_css => 'font-size:12pt;text-shadow: 0 3px 3px black; color:white;font-family: arial;',
               headerLogo_pos=>'left',
               headerbg_class=> 'gradient_gray'
               };

    my $sth = $dbh->prepare("replace into opl_preference set val=? ,valShow=?,var=?,hidden=1");

    foreach my $fname(keys %$fvMap){
        $sth->execute($fvMap->{$fname},$fvMap->{$fname},$fname);
    }
   
   
   
    $dbh->do("replace into opl_preference values ('ILL_Messaging','0','Disable','0|1','radio','enable/disabled  ILL messaging',0,8,8)");
    $dbh->do("replace INTO opl_prefFormParam values ('ILL_Messaging',0,'Enable','1'),('ILL_Messaging',1,'Disable','0')");
}


   my ($db_name, $db_host, $db_port, $db_user, $db_password);
    
    $db_name     =Opals::Context->config('db_name');
    $db_host     =Opals::Context->config('db_host');
    $db_port     =Opals::Context->config('db_port')   || '3306';
    $db_user     =Opals::Context->config('db_user');
    $db_password =Opals::Context->config('db_password');


print "$db_host\n";
system("mysql -h$db_host -u$db_user -p$db_password $db_name < /www/oopals-20140429-110405/script/sql/update_mars_2014.sql") == 0
    or die "Failed: $?";
# Codes end.

exit 0;


