#!/usr/bin/perl -w
=item
command to update all the sites:

for i in `ls /etc/opals/conf/`; do cp -p /www/opals/script/update_insert_AmazonId /tmp/urt; perl -pi -e "s/_MY_SITE_/$i/" /tmp/urt; sudo /tmp/urt; done

=cut

use lib "/www/opals/module";
use Opals::Context("/etc/opals/conf/_MY_SITE_");

use strict;
use DBI;
use Getopt::Std;
use POSIX qw(
    ceil
);
use Opals::CollectionStats qw(
    colStats_Fill
);

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

$| = 1;
# Codes start...





my $date =`date '+%Y-%m-%d %H:%M:%S'`;
   Update_insertTables($dbh);
   colStats_Fill($dbh);
my $date2 =`date '+%Y-%m-%d %H:%M:%S'`;

print "start at: $date  ends at $date2\n";

# Codes end.

exit 0;
############################################################
sub Update_insertTables{
    my($dbh)=@_;

$dbh->do("ALTER TABLE `opl_marcRecord` ADD  `print` SET(
             'print','fiction','nonFiction','pro','ref','serial','shortStories') DEFAULT 'print' 
        "); 

$dbh->do("ALTER TABLE `opl_marcRecord` ADD  `nonPrint` SET(
         'nonPrint','video','audio','multiMedia','cassette','kit','mixedMaterial','notatedMusic','map'
         ) DEFAULT 'nonPrint'");

$dbh->do("DROP TABLE `opl_collectionStats` ");
$dbh->do("CREATE TABLE `opl_collectionStats` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `onDate` date NOT NULL,
  `status` enum('add','lost','delete','found') NOT NULL,
  `record_Holding` enum('record','holding') NOT NULL default 'holding',
  `print` int(10) unsigned default '0',
  `nonPrint` int(10) unsigned default '0',
  `fiction` int(10) unsigned default '0',
  `nonFiction` int(10) unsigned default '0',
  `pro` int(10) unsigned default '0',
  `ref` int(10) unsigned default '0',
  `serial` int(10) unsigned default '0',
  `shortStories` int(10) unsigned default '0',
  `video` int(10) unsigned default '0',
  `audio` int(10) unsigned default '0',
  `multiMedia` int(10) unsigned default '0',
  `cassette` int(10) unsigned default '0',
  `kit` int(10) unsigned default '0',
  `mixedMaterial` int(10) unsigned default '0',
  `notatedMusic` int(10) unsigned default '0',
  `map` int(10) unsigned default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=37 DEFAULT CHARSET=latin1
");

}

############################################################
#////////////////////////////////////////////////////////////////////////////
