Adding a note field in serial table.
[koha.git] / updater / updatedatabase
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Database Updater
6 # This script checks for required updates to the database.
7
8 # Part of the Koha Library Software www.koha.org
9 # Licensed under the GPL.
10
11 # Bugs/ToDo:
12 # - Would also be a good idea to offer to do a backup at this time...
13
14 # NOTE:  If you do something more than once in here, make it table driven.
15 use strict;
16
17 # CPAN modules
18 use DBI;
19 use Getopt::Long;
20 # Koha modules
21 use C4::Context;
22
23 use MARC::Record;
24 use MARC::File::XML;
25
26 # FIXME - The user might be installing a new database, so can't rely
27 # on /etc/koha.conf anyway.
28
29 my $debug = 0;
30
31 my (
32     $sth, $sti,
33     $query,
34     %existingtables,    # tables already in database
35     %types,
36     $table,
37     $column,
38     $type, $null, $key, $default, $extra,
39     $prefitem,          # preference item in systempreferences table
40 );
41
42 my $silent;
43 GetOptions(
44         's' =>\$silent
45         );
46 my $dbh = C4::Context->dbh;
47 print "connected to your DB. Checking & modifying it\n" unless $silent;
48 $|=1; # flushes output
49
50 #-------------------
51 # Defines
52
53 # Tables to add if they don't exist
54 my %requiretables = (
55     categorytable       => "(categorycode char(5) NOT NULL default '',
56                              description text default '',
57                              itemtypecodes text default '',
58                              PRIMARY KEY (categorycode)
59                             )",
60     subcategorytable       => "(subcategorycode char(5) NOT NULL default '',
61                              description text default '',
62                              itemtypecodes text default '',
63                              PRIMARY KEY (subcategorycode)
64                             )",
65     mediatypetable       => "(mediatypecode char(5) NOT NULL default '',
66                              description text default '',
67                              itemtypecodes text default '',
68                              PRIMARY KEY (mediatypecode)
69                             )",
70     action_logs         => "(
71                                     `timestamp` TIMESTAMP NOT NULL ,
72                                     `user` INT( 11 ) NOT NULL ,
73                                     `module` TEXT default '',
74                                     `action` TEXT default '' ,
75                                     `object` INT(11) default '' ,
76                                     `info` TEXT default '' ,
77                                     PRIMARY KEY ( `timestamp` , `user` )
78                             )",
79         letter          => "(
80                                         module varchar(20) NOT NULL default '',
81                                         code varchar(20) NOT NULL default '',
82                                         name varchar(100) NOT NULL default '',
83                                         title varchar(200) NOT NULL default '',
84                                         content text,
85                                         PRIMARY KEY  (module,code)
86                                 )",
87         alert           =>"(
88                                         alertid int(11) NOT NULL auto_increment,
89                                         borrowernumber int(11) NOT NULL default '0',
90                                         type varchar(10) NOT NULL default '',
91                                         externalid varchar(20) NOT NULL default '',
92                                         PRIMARY KEY  (alertid),
93                                         KEY borrowernumber (borrowernumber),
94                                         KEY type (type,externalid)
95                                 )",
96
97 );
98
99 my %requirefields = (
100         subscription => { 'letter' => 'char(20) NULL'},
101 #    tablename        => { 'field' => 'fieldtype' },
102 );
103
104 my %dropable_table = (
105 # tablename => 'tablename',
106 );
107
108 my %uselessfields = (
109 # tablename => "field1,field2",
110         );
111 # the other hash contains other actions that can't be done elsewhere. they are done
112 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
113
114 # The tabledata hash contains data that should be in the tables.
115 # The uniquefieldrequired hash entry is used to determine which (if any) fields
116 # must not exist in the table for this row to be inserted.  If the
117 # uniquefieldrequired entry is already in the table, the existing data is not
118 # modified, unless the forceupdate hash entry is also set.  Fields in the
119 # anonymous "forceupdate" hash will be forced to be updated to the default
120 # values given in the %tabledata hash.
121
122 my %tabledata = (
123 # tablename => [
124 #       {       uniquefielrequired => 'fieldname', # the primary key in the table
125 #               fieldname => fieldvalue,
126 #               fieldname2 => fieldvalue2,
127 #       },
128 # ],
129     systempreferences => [
130                 {
131             uniquefieldrequired => 'variable',
132             variable            => 'Activate_Log',
133             value               => 'On',
134             forceupdate         => { 'explanation' => 1,
135                                      'type' => 1},
136             explanation         => 'Turn Log Actions on DB On an Off',
137             type                => 'YesNo',
138         },
139         {
140             uniquefieldrequired => 'variable',
141             variable            => 'IndependantBranches',
142             value               => 0,
143             forceupdate         => { 'explanation' => 1,
144                                      'type' => 1},
145             explanation         => 'Turn Branch independancy management On an Off',
146             type                => 'YesNo',
147         },
148                 {
149             uniquefieldrequired => 'variable',
150             variable            => 'ReturnBeforeExpiry',
151             value               => 'Off',
152             forceupdate         => { 'explanation' => 1,
153                                      'type' => 1},
154             explanation         => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
155             type                => 'YesNo',
156         },
157     ],
158
159 );
160
161 my %fielddefinitions = (
162 # fieldname => [
163 #       {                 field => 'fieldname',
164 #             type    => 'fieldtype',
165 #             null    => '',
166 #             key     => '',
167 #             default => ''
168 #         },
169 #     ],
170         serial => [
171         {
172             field   => 'notes',
173             type    => 'TEXT',
174             null    => 'NULL',
175             key     => '',
176             default => '',
177             extra   => ''
178         },
179     ],
180 );
181
182 #-------------------
183 # Initialize
184
185 # Start checking
186
187 # Get version of MySQL database engine.
188 my $mysqlversion = `mysqld --version`;
189 $mysqlversion =~ /Ver (\S*) /;
190 $mysqlversion = $1;
191 if ( $mysqlversion ge '3.23' ) {
192     print "Could convert to MyISAM database tables...\n" unless $silent;
193 }
194
195 #---------------------------------
196 # Tables
197
198 # Collect all tables into a list
199 $sth = $dbh->prepare("show tables");
200 $sth->execute;
201 while ( my ($table) = $sth->fetchrow ) {
202     $existingtables{$table} = 1;
203 }
204
205
206 # Now add any missing tables
207 foreach $table ( keys %requiretables ) {
208     unless ( $existingtables{$table} ) {
209         print "Adding $table table...\n" unless $silent;
210         my $sth = $dbh->prepare("create table $table $requiretables{$table}");
211         $sth->execute;
212         if ( $sth->err ) {
213             print "Error : $sth->errstr \n";
214             $sth->finish;
215         }    # if error
216     }    # unless exists
217 }    # foreach
218
219 # now drop useless tables
220 foreach $table ( keys %dropable_table ) {
221         if ( $existingtables{$table} ) {
222                 print "Dropping unused table $table\n" if $debug and not $silent;
223                 $dbh->do("drop table $table");
224                 if ( $dbh->err ) {
225                         print "Error : $dbh->errstr \n";
226                 }
227         }
228 }
229
230 #---------------------------------
231 # Columns
232
233 foreach $table ( keys %requirefields ) {
234     print "Check table $table\n" if $debug and not $silent;
235     $sth = $dbh->prepare("show columns from $table");
236     $sth->execute();
237     undef %types;
238     while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
239     {
240         $types{$column} = $type;
241     }    # while
242     foreach $column ( keys %{ $requirefields{$table} } ) {
243         print "  Check column $column  [$types{$column}]\n" if $debug and not $silent;
244         if ( !$types{$column} ) {
245
246             # column doesn't exist
247             print "Adding $column field to $table table...\n" unless $silent;
248             $query = "alter table $table
249                         add column $column " . $requirefields{$table}->{$column};
250             print "Execute: $query\n" if $debug;
251             my $sti = $dbh->prepare($query);
252             $sti->execute;
253             if ( $sti->err ) {
254                 print "**Error : $sti->errstr \n";
255                 $sti->finish;
256             }    # if error
257         }    # if column
258     }    # foreach column
259 }    # foreach table
260
261 foreach $table ( keys %fielddefinitions ) {
262         print "Check table $table\n" if $debug;
263         $sth = $dbh->prepare("show columns from $table");
264         $sth->execute();
265         my $definitions;
266         while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
267         {
268                 $definitions->{$column}->{type}    = $type;
269                 $definitions->{$column}->{null}    = $null;
270                 $definitions->{$column}->{key}     = $key;
271                 $definitions->{$column}->{default} = $default;
272                 $definitions->{$column}->{extra}   = $extra;
273         }    # while
274         my $fieldrow = $fielddefinitions{$table};
275         foreach my $row (@$fieldrow) {
276                 my $field   = $row->{field};
277                 my $type    = $row->{type};
278                 my $null    = $row->{null};
279                 my $key     = $row->{key};
280                 my $default = $row->{default};
281                 $default="''" unless $default;
282                 my $extra   = $row->{extra};
283                 my $def     = $definitions->{$field};
284                 unless ( $type eq $def->{type}
285                         && $null eq $def->{null}
286                         && $key eq $def->{key}
287                         && $default eq $def->{default}
288                         && $extra eq $def->{extra} )
289                 {
290
291                         if ( $null eq '' ) {
292                                 $null = 'NOT NULL';
293                         }
294                         if ( $key eq 'PRI' ) {
295                                 $key = 'PRIMARY KEY';
296                         }
297                         unless ( $extra eq 'auto_increment' ) {
298                                 $extra = '';
299                         }
300                         # if it's a new column use "add", if it's an old one, use "change".
301                         my $action;
302                         if ($definitions->{$field}->{type}) {
303                                 $action="change $field"
304                         } else {
305                                 $action="add";
306                         }
307 # if it's a primary key, drop the previous pk, before altering the table
308                         my $sth;
309                         if ($key ne 'PRIMARY KEY') {
310                                 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ?");
311                         } else {
312                                 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ?");
313                         }
314                         $sth->execute($default);
315                         print "  Alter $field in $table\n" unless $silent;
316                 }
317         }
318 }
319
320
321 # Populate tables with required data
322 foreach my $table ( keys %tabledata ) {
323     print "Checking for data required in table $table...\n" unless $silent;
324     my $tablerows = $tabledata{$table};
325     foreach my $row (@$tablerows) {
326         my $uniquefieldrequired = $row->{uniquefieldrequired};
327         my $uniquevalue         = $row->{$uniquefieldrequired};
328         my $forceupdate         = $row->{forceupdate};
329         my $sth                 =
330           $dbh->prepare(
331 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
332         );
333         $sth->execute($uniquevalue);
334         if ($sth->rows) {
335             foreach my $field (keys %$forceupdate) {
336                 if ($forceupdate->{$field}) {
337                     my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
338                     $sth->execute($row->{$field}, $uniquevalue);
339                 }
340             }
341         } else {
342             print "Adding row to $table: " unless $silent;
343             my @values;
344             my $fieldlist;
345             my $placeholders;
346             foreach my $field ( keys %$row ) {
347                 next if $field eq 'uniquefieldrequired';
348                 next if $field eq 'forceupdate';
349                 my $value = $row->{$field};
350                 push @values, $value;
351                 print "  $field => $value" unless $silent;
352                 $fieldlist .= "$field,";
353                 $placeholders .= "?,";
354             }
355             print "\n" unless $silent;
356             $fieldlist    =~ s/,$//;
357             $placeholders =~ s/,$//;
358             my $sth =
359               $dbh->prepare(
360                 "insert into $table ($fieldlist) values ($placeholders)");
361             $sth->execute(@values);
362         }
363     }
364 }
365
366 #
367 # SPECIFIC STUFF
368 #
369 #
370 # create frameworkcode row in biblio table & fill it with marc_biblio.frameworkcode.
371 #
372
373 # 1st, get how many biblio we will have to do...
374 $sth = $dbh->prepare('select count(*) from marc_biblio');
375 $sth->execute;
376 my ($totaltodo) = $sth->fetchrow;
377
378 $sth = $dbh->prepare("show columns from biblio");
379 $sth->execute();
380 my $definitions;
381 my $bibliofwexist=0;
382 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
383         $bibliofwexist=1 if $column eq 'frameworkcode';
384 }
385 unless ($bibliofwexist) {
386         print "moving biblioframework to biblio table\n";
387         $dbh->do('ALTER TABLE `biblio` ADD `frameworkcode` VARCHAR( 4 ) NOT NULL AFTER `biblionumber`');
388         $sth = $dbh->prepare('select biblionumber,frameworkcode from marc_biblio');
389         $sth->execute;
390         my $sth_update = $dbh->prepare('update biblio set frameworkcode=? where biblionumber=?');
391         my $totaldone=0;
392         while (my ($biblionumber,$frameworkcode) = $sth->fetchrow) {
393                 $sth_update->execute($frameworkcode,$biblionumber);
394                 $totaldone++;
395                 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
396         }
397         print "\rdone\n";
398 }
399
400 #
401 # moving MARC data from marc_subfield_table to biblioitems.marc
402 #
403 $sth = $dbh->prepare("show columns from biblioitems");
404 $sth->execute();
405 my $definitions;
406 my $marcdone=0;
407 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
408         $marcdone=1 if ($type eq 'blob' && $column eq 'marc') ;
409 }
410 unless ($marcdone) {
411         print "moving MARC record to biblioitems table\n";
412         # changing marc field type
413         $dbh->do('ALTER TABLE `biblioitems` CHANGE `marc` `marc` BLOB NULL DEFAULT NULL ');
414         # adding marc xml, just for convenience
415         $dbh->do('ALTER TABLE `biblioitems` ADD `marcxml` TEXT NOT NULL');
416         # moving data from marc_subfield_value to biblio
417         $sth = $dbh->prepare('select bibid,biblionumber from marc_biblio');
418         $sth->execute;
419         my $sth_update = $dbh->prepare('update biblioitems set marc=?, marcxml=? where biblionumber=?');
420         my $totaldone=0;
421         while (my ($bibid,$biblionumber) = $sth->fetchrow) {
422                 my $record = MARCgetbiblio($dbh,$bibid);
423                 $sth_update->execute($record->as_usmarc(),$record->as_xml(),$biblionumber);
424                 $totaldone++;
425                 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
426         }
427         print "\rdone\n";
428 }
429
430 # at last, remove useless fields
431 foreach $table ( keys %uselessfields ) {
432         my @fields = split /,/,$uselessfields{$table};
433         my $fields;
434         my $exists;
435         foreach my $fieldtodrop (@fields) {
436                 $fieldtodrop =~ s/\t//g;
437                 $fieldtodrop =~ s/\n//g;
438                 $exists =0;
439                 $sth = $dbh->prepare("show columns from $table");
440                 $sth->execute;
441                 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
442                 {
443                         $exists =1 if ($column eq $fieldtodrop);
444                 }
445                 if ($exists) {
446                         print "deleting $fieldtodrop field in $table...\n" unless $silent;
447                         my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
448                         $sth->execute;
449                 }
450         }
451 }    # foreach
452
453
454 $sth->finish;
455
456 #
457 # those 2 subs are a copy of Biblio.pm, version 2.2.4
458 # they are useful only once, for moving from 2.2 to 3.0
459 # the MARCgetbiblio & MARCgetitem subs in Biblio.pm
460 # are still here, but uses other tables
461 # (the ones that are filled by updatedatabase !)
462 #
463 sub MARCgetbiblio {
464
465     # Returns MARC::Record of the biblio passed in parameter.
466     my ( $dbh, $bibid ) = @_;
467     my $record = MARC::Record->new();
468 #       warn "". $bidid;
469
470     my $sth =
471       $dbh->prepare(
472 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
473                                  from marc_subfield_table
474                                  where bibid=? order by tag,tagorder,subfieldorder
475                          "
476     );
477     my $sth2 =
478       $dbh->prepare(
479         "select subfieldvalue from marc_blob_subfield where blobidlink=?");
480     $sth->execute($bibid);
481     my $prevtagorder = 1;
482     my $prevtag      = 'XXX';
483     my $previndicator;
484     my $field;        # for >=10 tags
485     my $prevvalue;    # for <10 tags
486     while ( my $row = $sth->fetchrow_hashref ) {
487
488         if ( $row->{'valuebloblink'} ) {    #---- search blob if there is one
489             $sth2->execute( $row->{'valuebloblink'} );
490             my $row2 = $sth2->fetchrow_hashref;
491             $sth2->finish;
492             $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
493         }
494         if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
495             $previndicator .= "  ";
496             if ( $prevtag < 10 ) {
497                                 if ($prevtag ne '000') {
498                         $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX";    # ignore the 1st loop
499                                 } else {
500                                         $record->leader(sprintf("%24s",$prevvalue));
501                                 }
502             }
503             else {
504                 $record->add_fields($field) unless $prevtag eq "XXX";
505             }
506             undef $field;
507             $prevtagorder  = $row->{tagorder};
508             $prevtag       = $row->{tag};
509             $previndicator = $row->{tag_indicator};
510             if ( $row->{tag} < 10 ) {
511                 $prevvalue = $row->{subfieldvalue};
512             }
513             else {
514                 $field = MARC::Field->new(
515                     ( sprintf "%03s", $prevtag ),
516                     substr( $row->{tag_indicator} . '  ', 0, 1 ),
517                     substr( $row->{tag_indicator} . '  ', 1, 1 ),
518                     $row->{'subfieldcode'},
519                     $row->{'subfieldvalue'}
520                 );
521             }
522         }
523         else {
524             if ( $row->{tag} < 10 ) {
525                 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
526                     $row->{'subfieldvalue'} );
527             }
528             else {
529                 $field->add_subfields( $row->{'subfieldcode'},
530                     $row->{'subfieldvalue'} );
531             }
532             $prevtag       = $row->{tag};
533             $previndicator = $row->{tag_indicator};
534         }
535     }
536
537     # the last has not been included inside the loop... do it now !
538     if ( $prevtag ne "XXX" )
539     { # check that we have found something. Otherwise, prevtag is still XXX and we
540          # must return an empty record, not make MARC::Record fail because we try to
541          # create a record with XXX as field :-(
542         if ( $prevtag < 10 ) {
543             $record->add_fields( $prevtag, $prevvalue );
544         }
545         else {
546
547             #           my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
548             $record->add_fields($field);
549         }
550     }
551     return $record;
552 }
553
554 sub MARCgetitem {
555
556     # Returns MARC::Record of the biblio passed in parameter.
557     my ( $dbh, $bibid, $itemnumber ) = @_;
558     my $record = MARC::Record->new();
559
560     # search MARC tagorder
561     my $sth2 =
562       $dbh->prepare(
563 "select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"
564     );
565     $sth2->execute( $bibid, $itemnumber );
566     my ($tagorder) = $sth2->fetchrow_array();
567
568     #---- TODO : the leader is missing
569     my $sth =
570       $dbh->prepare(
571 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
572                                  from marc_subfield_table
573                                  where bibid=? and tagorder=? order by subfieldcode,subfieldorder
574                          "
575     );
576     $sth2 =
577       $dbh->prepare(
578         "select subfieldvalue from marc_blob_subfield where blobidlink=?");
579     $sth->execute( $bibid, $tagorder );
580     while ( my $row = $sth->fetchrow_hashref ) {
581         if ( $row->{'valuebloblink'} ) {    #---- search blob if there is one
582             $sth2->execute( $row->{'valuebloblink'} );
583             my $row2 = $sth2->fetchrow_hashref;
584             $sth2->finish;
585             $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
586         }
587         if ( $record->field( $row->{'tag'} ) ) {
588             my $field;
589
590 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
591             #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
592             if ( length( $row->{'tag'} ) < 3 ) {
593                 $row->{'tag'} = "0" . $row->{'tag'};
594             }
595             $field = $record->field( $row->{'tag'} );
596             if ($field) {
597                 my $x =
598                   $field->add_subfields( $row->{'subfieldcode'},
599                     $row->{'subfieldvalue'} );
600                 $record->delete_field($field);
601                 $record->add_fields($field);
602             }
603         }
604         else {
605             if ( length( $row->{'tag'} ) < 3 ) {
606                 $row->{'tag'} = "0" . $row->{'tag'};
607             }
608             my $temp =
609               MARC::Field->new( $row->{'tag'}, " ", " ",
610                 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
611             $record->add_fields($temp);
612         }
613
614     }
615     return $record;
616 }
617
618
619 exit;
620
621 # $Log$
622 # Revision 1.121  2005/08/24 08:49:03  hdl
623 # Adding a note field in serial table.
624 # This will allow librarian to mention a note on a peculiar waiting serial number.
625 #
626 # Revision 1.120  2005/08/09 14:10:32  tipaul
627 # 1st commit to go to zebra.
628 # don't update your cvs if you want to have a working head...
629 #
630 # this commit contains :
631 # * updater/updatedatabase : get rid with marc_* tables, but DON'T remove them. As a lot of things uses them, it would not be a good idea for instance to drop them. If you really want to play, you can rename them to test head without them but being still able to reintroduce them...
632 # * Biblio.pm : modify MARCgetbiblio to find the raw marc record in biblioitems.marc field, not from marc_subfield_table, modify MARCfindframeworkcode to find frameworkcode in biblio.frameworkcode, modify some other subs to use biblio.biblionumber & get rid of bibid.
633 # * other files : get rid of bibid and use biblionumber instead.
634 #
635 # What is broken :
636 # * does not do anything on zebra yet.
637 # * if you rename marc_subfield_table, you can't search anymore.
638 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
639 # * don't try to add a biblio, it would add data poorly... (don't try to delete either, it may work, but that would be a surprise ;-) )
640 #
641 # IMPORTANT NOTE : you need MARC::XML package (http://search.cpan.org/~esummers/MARC-XML-0.7/lib/MARC/File/XML.pm), that requires a recent version of MARC::Record
642 # Updatedatabase stores the iso2709 data in biblioitems.marc field & an xml version in biblioitems.marcxml Not sure we will keep it when releasing the stable version, but I think it's a good idea to have something readable in sql, at least for development stage.
643 #
644 # Revision 1.119  2005/08/04 16:07:58  tipaul
645 # Synch really broke this script...
646 #
647 # Revision 1.118  2005/08/04 16:02:55  tipaul
648 # oops... error in synch between 2.2 and head
649 #
650 # Revision 1.117  2005/08/04 14:24:39  tipaul
651 # synch'ing 2.2 and head
652 #
653 # Revision 1.116  2005/08/04 08:55:54  tipaul
654 # Letters / alert system, continuing...
655 #
656 # * adding a package Letters.pm, that manages Letters & alerts.
657 # * adding feature : it's now possible to define a "letter" for any subscription created. If a letter is defined, users in OPAC can put an alert on the subscription. When an issue is marked "arrived", all users in the alert will recieve a mail (as defined in the "letter"). This last part (= send the mail) is not yet developped. (Should be done this week)
658 # * adding feature : it's now possible to "put to an alert" in OPAC, for any serial subscription. The alert is stored in a new table, called alert. An alert can be put only if the librarian has activated them in subscription (and they activate it just by choosing a "letter" to sent to borrowers on new issues)
659 # * adding feature : librarian can see in borrower detail which alerts they have put, and a user can see in opac-detail which alert they have put too.
660 #
661 # Note that the system should be generic enough to manage any type of alert.
662 # I plan to extend it soon to virtual shelves : a borrower will be able to put an alert on a virtual shelf, to be warned when something is changed in the virtual shelf (mail being sent once a day by cron, or manually by the shelf owner. Anyway, a mail won't be sent on every change, users would be spammed by Koha ;-) )
663 #
664 # Revision 1.115  2005/08/02 16:15:34  tipaul
665 # adding 2 fields to letter system :
666 # * module (acquisition, catalogue...) : it will be usefull to show the librarian only letters he may be interested by.
667 # * title, that will be used as mail subject.
668 #
669 # Revision 1.114  2005/07/28 15:10:13  tipaul
670 # Introducing new "Letters" system : Letters will be used everytime you want to sent something to someone (through mail or paper). For example, sending a mail for overdues use letter that you can put as parameters. Sending a mail to a borrower when a suggestion is validated uses a letter too.
671 # the letter table contains 3 fields :
672 # * code => the code of the letter
673 # * name => the complete name of the letter
674 # * content => the complete text. It's a TEXT field type, so has no limits.
675 #
676 # My next goal now is to work on point 2-I "serial issue alert"
677 # With this feature, in serials, a user can subscribe the "issue alert". For every issue arrived/missing, a mail is sent to all subscribers of this list. The mail warns the user that the issue is arrive or missing. Will be in head.
678 # (see mail on koha-devel, 2005/04/07)
679 #
680 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
681 #
682 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
683 #
684 # Revision 1.113  2005/07/28 08:38:41  tipaul
685 # For instance, the return date does not rely on the borrower expiration date. A systempref will be added in Koha, to modify return date calculation schema :
686 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
687 # * ReturnBeforeExpiry = no  => return date can be after expiry date
688 #
689 # Revision 1.112  2005/07/26 08:19:47  hdl
690 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
691 #
692 # Revision 1.111  2005/07/25 15:35:38  tipaul
693 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
694 # So, the updatedatabase script can highly be cleaned (90% removed).
695 # Let's play with the new Koha DB structure now ;-)
696 #