View | Details | Raw Unified | Return to bug 8836
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 42-48 use C4::Koha qw( Link Here
42
    GetKohaAuthorisedValueLib
42
    GetKohaAuthorisedValueLib
43
);
43
);
44
use C4::Overdues qw(CalcFine UpdateFine);
44
use C4::Overdues qw(CalcFine UpdateFine);
45
use C4::RotatingCollections qw(GetCollectionItemBranches);
45
use C4::RotatingCollections;
46
use Algorithm::CheckDigits;
46
use Algorithm::CheckDigits;
47
47
48
use Data::Dumper;
48
use Data::Dumper;
(-)a/C4/RotatingCollections.pm (-44 / +521 lines)
Lines 27-32 use Modern::Perl; Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Circulation;
28
use C4::Circulation;
29
use C4::Reserves qw(GetReserveStatus);
29
use C4::Reserves qw(GetReserveStatus);
30
use C4::Biblio;
31
use C4::Branch;
32
use C4::Items;
33
use C4::Reserves;
30
34
31
use DBI;
35
use DBI;
32
36
Lines 56-68 BEGIN { Link Here
56
      GetItemsInCollection
60
      GetItemsInCollection
57
61
58
      GetCollection
62
      GetCollection
63
      GetCollectionByTitle
59
      GetCollections
64
      GetCollections
60
65
61
      AddItemToCollection
66
      AddItemToCollection
62
      RemoveItemFromCollection
67
      RemoveItemFromCollection
63
      TransferCollection
68
      TransferCollection
69
      TransferCollectionItem
70
      ReturnCollectionItemToOrigin
71
      ReturnCollectionToOrigin
64
72
65
      GetCollectionItemBranches
73
      GetCollectionItemBranches
74
75
      GetItemOriginBranch
76
      GetItemsCollection
77
78
      isItemInAnyCollection
66
    );
79
    );
67
}
80
}
68
81
Lines 82-95 BEGIN { Link Here
82
=cut
95
=cut
83
96
84
sub CreateCollection {
97
sub CreateCollection {
85
    my ( $title, $description ) = @_;
98
    my ( $title, $description, $owningbranch ) = @_;
86
99
87
    ## Check for all neccessary parameters
100
    ## Check for all neccessary parameters
88
    if ( !$title ) {
101
    if ( !$title ) {
89
        return ( 0, 1, "No Title Given" );
102
        return ( 0, 1, "No title given" );
90
    }
103
    }
91
    if ( !$description ) {
104
    if ( !$description ) {
92
        return ( 0, 2, "No Description Given" );
105
        return ( 0, 2, "No description given" );
106
    }
107
108
    if ( !$owningbranch ) {
109
        return ( 0, 3, "No owning branch given" );
110
    }
111
112
    # Check whether a collection with the given title already exists
113
    my $collections = GetCollections();
114
    for my $col (@$collections) {
115
        if ($col->{'colTitle'} eq $title) {
116
            return (0, 4, "A collection with the title '" . $title . "' already exists");
117
        }
93
    }
118
    }
94
119
95
    my $success = 1;
120
    my $success = 1;
Lines 98-107 sub CreateCollection { Link Here
98
123
99
    my $sth;
124
    my $sth;
100
    $sth = $dbh->prepare(
125
    $sth = $dbh->prepare(
101
        "INSERT INTO collections ( colId, colTitle, colDesc )
126
        "INSERT INTO collections ( colId, colTitle, colDesc, owningBranchcode )
102
                        VALUES ( NULL, ?, ? )"
127
                        VALUES ( NULL, ?, ?, ? )"
103
    );
128
    );
104
    $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() );
129
    $sth->execute( $title, $description, $owningbranch ) or return ( 0, 5, $sth->errstr() );
105
130
106
    return 1;
131
    return 1;
107
132
Lines 139-144 sub UpdateCollection { Link Here
139
        return ( 0, 3, "No Description Given" );
164
        return ( 0, 3, "No Description Given" );
140
    }
165
    }
141
166
167
    # Check whether a collection with the given title already exists
168
    my $collections = GetCollections();
169
    for my $col (@$collections) {
170
        if ($col->{'colTitle'} eq $title) {
171
            return (0, 4, "A collection with the title '" . $title . "' already exists");
172
        }
173
    }
174
142
    my $dbh = C4::Context->dbh;
175
    my $dbh = C4::Context->dbh;
143
176
144
    my $sth;
177
    my $sth;
Lines 178-183 sub DeleteCollection { Link Here
178
        return ( 0, 1, "No Collection Id Given" );
211
        return ( 0, 1, "No Collection Id Given" );
179
    }
212
    }
180
213
214
    my $collectionItems = GetItemsInCollection($colId);
215
    # KD-139: Actually remove all items from the collection before removing the collection itself.
216
    for my $item (@$collectionItems) {
217
        my $itembiblio = GetBiblioFromItemNumber(undef, $item->{'barcode'});
218
        my $itemnumber = $itembiblio->{'itemnumber'};
219
        RemoveItemFromCollection($colId, $itemnumber);
220
    }
221
181
    my $dbh = C4::Context->dbh;
222
    my $dbh = C4::Context->dbh;
182
223
183
    my $sth;
224
    my $sth;
Lines 205-216 sub DeleteCollection { Link Here
205
sub GetCollections {
246
sub GetCollections {
206
247
207
    my $dbh = C4::Context->dbh;
248
    my $dbh = C4::Context->dbh;
249
    my $query = '
250
    SELECT *
251
    FROM collections
252
    LEFT JOIN branches ON owningBranchcode = branches.branchcode
253
    ';
208
254
209
    my $sth = $dbh->prepare("SELECT * FROM collections");
255
    my $sth = $dbh->prepare($query);
210
    $sth->execute() or return ( 1, $sth->errstr() );
256
    $sth->execute() or return ( 1, $sth->errstr() );
211
257
212
    my @results;
258
    my @results;
213
    while ( my $row = $sth->fetchrow_hashref ) {
259
    while ( my $row = $sth->fetchrow_hashref ) {
260
        my $colItemCount = GetCollectionItemCount($row->{'colId'});
261
        my $itemsTransferred = GetTransferredItemCount($row->{'colId'});
262
        $row->{'colItemsCount'} = $colItemCount;
263
        $row->{'itemsTransferred'} = $itemsTransferred;
214
        push( @results, $row );
264
        push( @results, $row );
215
    }
265
    }
216
266
Lines 246-264 sub GetItemsInCollection { Link Here
246
296
247
    my $sth = $dbh->prepare(
297
    my $sth = $dbh->prepare(
248
        "SELECT
298
        "SELECT
249
                             biblio.title,
299
                            biblio.title,
250
                             items.itemcallnumber,
300
                            biblio.biblionumber,
251
                             items.barcode
301
                            items.itemcallnumber,
252
                           FROM collections, collections_tracking, items, biblio
302
                            items.barcode,
253
                           WHERE collections.colId = collections_tracking.colId
303
                            items.itemnumber,
304
                            items.holdingbranch,
305
                            items.homebranch,
306
                            branches.branchname,
307
                            collections_tracking.*
308
                           FROM collections, collections_tracking, items, biblio, branches
309
                           WHERE items.homebranch = branches.branchcode
310
                           AND collections.colId = collections_tracking.colId
254
                           AND collections_tracking.itemnumber = items.itemnumber
311
                           AND collections_tracking.itemnumber = items.itemnumber
255
                           AND items.biblionumber = biblio.biblionumber
312
                           AND items.biblionumber = biblio.biblionumber
256
                           AND collections.colId = ? ORDER BY biblio.title"
313
                           AND collections.colId = ?
314
                           ORDER BY biblio.title"
257
    );
315
    );
258
    $sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() );
316
    $sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() );
259
317
260
    my @results;
318
    my @results;
261
    while ( my $row = $sth->fetchrow_hashref ) {
319
    while ( my $row = $sth->fetchrow_hashref ) {
320
        my $originbranchname = GetBranchName($row->{'origin_branchcode'});
321
        my $holdingbranchname = GetBranchName($row->{'holdingbranch'});
322
        $row->{'holdingbranchname'} = $holdingbranchname;
323
        $row->{'origin_branchname'} = $originbranchname;
324
        $row->{'intransit'} = GetTransfers($row->{'itemnumber'});
262
        push( @results, $row );
325
        push( @results, $row );
263
    }
326
    }
264
327
Lines 296-301 sub GetCollection { Link Here
296
359
297
}
360
}
298
361
362
=head2 GetCollectionByTitle
363
364
 ($colId, $colTitle, $colDesc, $colBranchcode) = GetCollectionByTitle($colTitle);
365
366
Returns information about a collection
367
368
 Input:
369
   $colTitle: Title of the collection
370
 Output:
371
   $colId, $colTitle, $colDesc, $colBranchcode
372
373
=cut
374
375
sub GetCollectionByTitle {
376
    my ($colId) = @_;
377
378
    my $dbh = C4::Context->dbh;
379
380
    my ( $sth, @results );
381
    $sth = $dbh->prepare("SELECT * FROM collections WHERE colTitle = ?");
382
    $sth->execute($colId) or return 0;
383
384
    my $row = $sth->fetchrow_hashref;
385
386
    return (
387
        $$row{'colId'},   $$row{'colTitle'},
388
        $$row{'colDesc'}, $$row{'colBranchcode'}
389
    );
390
391
}
392
393
=head2 GetItemsCollection
394
395
$itemsCollection = GetItemsCollection($itemnumber)
396
397
Returns an item's collection if it exists
398
399
 Input:
400
   $itemnumber: itemnumber of the item
401
 Output:
402
   $colId of the item's collection or 0 if the item is not in a collection
403
404
=cut
405
406
sub GetItemsCollection {
407
    my $itemnumber = shift;
408
409
    if (!isItemInAnyCollection($itemnumber)) {
410
        return 0;
411
    }
412
413
    my $dbh = C4::Context->dbh;
414
    my $sth = $dbh->prepare("SELECT * FROM collections_tracking WHERE itemnumber = ?");
415
    $sth->execute($itemnumber) or return 0;
416
417
    my $colItem = $sth->fetchrow_hashref;
418
    if ($colItem) {
419
        return $colItem->{'colId'};
420
    }
421
    return 0;
422
}
423
299
=head2 AddItemToCollection
424
=head2 AddItemToCollection
300
425
301
 ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber );
426
 ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber );
Lines 322-334 sub AddItemToCollection { Link Here
322
    if ( !$itemnumber ) {
447
    if ( !$itemnumber ) {
323
        return ( 0, 2, "No Itemnumber Given" );
448
        return ( 0, 2, "No Itemnumber Given" );
324
    }
449
    }
325
326
    if ( isItemInThisCollection( $itemnumber, $colId ) ) {
450
    if ( isItemInThisCollection( $itemnumber, $colId ) ) {
327
        return ( 0, 2, "Item is already in the collection!" );
451
        return ( 0, 2, "Item is already in the collection!" );
328
    }
452
    }
329
    elsif ( isItemInAnyCollection($itemnumber) ) {
453
    elsif ( isItemInAnyCollection($itemnumber) ) {
330
        return ( 0, 3, "Item is already in a different collection!" );
454
        return ( 0, 3, "Item is already in a different collection!" );
331
    }
455
    }
456
    # Check item's reserve status
457
    my ($reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate) = GetReservesFromItemnumber($itemnumber);
458
    return (0, 4, "The item is waiting for pickup and cannot be added to a collection!") if ($waitingdate);
459
460
    my $itembiblio = GetBiblioFromItemNumber($itemnumber, undef);
461
    my $originbranchcode = $itembiblio->{'homebranch'};
462
    my $transferred = 0;
332
463
333
    my $dbh = C4::Context->dbh;
464
    my $dbh = C4::Context->dbh;
334
465
Lines 336-345 sub AddItemToCollection { Link Here
336
    $sth = $dbh->prepare("
467
    $sth = $dbh->prepare("
337
        INSERT INTO collections_tracking (
468
        INSERT INTO collections_tracking (
338
            colId,
469
            colId,
339
            itemnumber
470
            itemnumber,
340
        ) VALUES ( ?, ? )
471
            origin_branchcode
472
        ) VALUES (?, ?, ?)
341
    ");
473
    ");
342
    $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() );
474
    $sth->execute($colId, $itemnumber, $originbranchcode) or return ( 0, 3, $sth->errstr() );
343
475
344
    return 1;
476
    return 1;
345
477
Lines 374-381 sub RemoveItemFromCollection { Link Here
374
        return ( 0, 2, "Item is not in the collection!" );
506
        return ( 0, 2, "Item is not in the collection!" );
375
    }
507
    }
376
508
377
    my $dbh = C4::Context->dbh;
509
    # KD-139: Attempt to transfer the item being removed if it has its origin branch
510
    # set up.
511
    my $itembiblio = GetBiblioFromItemNumber($itemnumber, undef);
512
    my $currenthomebranchcode = $itembiblio->{'homebranch'};
513
    my $originbranchcode = GetItemOriginBranch($itemnumber);
514
    my $barcode = $itembiblio->{'barcode'};
515
    my ($dotransfer, $messages, $iteminformation);
516
517
    if ($originbranchcode && $barcode) {
518
        if (GetTransfers($itemnumber)) {
519
            DeleteTransfer($itemnumber)
520
        }
521
        ($dotransfer, $messages, $iteminformation) = transferbook($originbranchcode, $barcode, 1);
522
    }
378
523
524
    my $dbh = C4::Context->dbh;
379
    my $sth;
525
    my $sth;
380
    $sth = $dbh->prepare(
526
    $sth = $dbh->prepare(
381
        "DELETE FROM collections_tracking
527
        "DELETE FROM collections_tracking
Lines 383-388 sub RemoveItemFromCollection { Link Here
383
    );
529
    );
384
    $sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() );
530
    $sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() );
385
531
532
    # Transfer was not done - not considered an error here
533
    if (!$dotransfer) {
534
        return (1, 4, $messages);
535
    }
536
537
    # Change the item's homebranch back to its pre-transfer status
538
    ModItem({ homebranch => $originbranchcode }, undef, $itemnumber);
539
540
    return 1;
541
}
542
543
=head2  ReturnCollectionToOrigin
544
545
 ($success, $errorcode, $errormessage) = ReturnCollectionToOrigin($colId);
546
547
Marks a collection to be returned to their origin branch, e.g. the branch that was
548
the item's home branch when it was first added to the collection
549
550
 Input:
551
   $colId: Collection the returned item belongs to
552
553
 Output:
554
   $success: 1 if all database operations were successful, 0 otherwise
555
   $errorcode: Code for reason of failure, good for translating errors in templates
556
   $errormessages: English description of any errors with return operations
557
=cut
558
559
sub ReturnCollectionToOrigin {
560
    my $colId = shift;
561
562
    if (!$colId) {
563
        return (0, 1, "No collection id given");
564
    }
565
566
    my $collectionItems = GetItemsInCollection($colId);
567
    my $collectionItemsCount = scalar(@$collectionItems);
568
    my ($colSuccess, $errorcode, @errormessages);
569
570
    for my $item (@$collectionItems) {
571
        my $itemOriginBranch = GetItemOriginBranch($item->{'itemnumber'});
572
        my ($success, $errocode, $errormessage);
573
        if ($itemOriginBranch) {
574
            ($success, $errorcode, $errormessage) =
575
                ReturnCollectionItemToOrigin($colId, $item->{'itemnumber'});
576
            if (!$success) {
577
                push(@errormessages, $errormessage);
578
            }
579
        }
580
    }
581
    my $errorCount = scalar(@errormessages);
582
    if ($errorCount == $collectionItemsCount) {
583
        return (0, 2, "No items in collection transferred");
584
    }
585
    else {
586
        # Some items were succesfully returned - return info about failed transfers for template usage
587
        return (1, 0, \@errormessages);
588
    }
589
}
590
591
592
593
=head2  ReturnCollectionItemToOrigin
594
595
 ($success, $errorcode, $errormessage) = ReturnCollectionItemToOrigin($colId, $itemnumber);
596
597
Marks a collection item to be returned to their origin branch, e.g. the branch that was
598
the item's home branch when it was first added to the collection
599
600
 Input:
601
   $colId: Collection the returned item belongs to
602
   $itemnumber: Item in the collection to be returned to their origin branch
603
604
 Output:
605
   $success: 1 if all database operations were successful, 0 otherwise
606
   $errorCode: Code for reason of failure, good for translating errors in templates
607
   $errorMessage: English description of error
608
609
=cut
610
611
sub ReturnCollectionItemToOrigin {
612
    my ($colId, $itemnumber) = @_;
613
    my $originBranch = GetItemOriginBranch($itemnumber);
614
615
    ## Check for all neccessary parameters
616
    if (!$colId) {
617
        return (0, 1, "No collection id given");
618
    }
619
    if (!$itemnumber) {
620
        return (0, 2, "No itemnumber given");
621
    }
622
623
    if (!$originBranch) {
624
        return (0, 3, "Item has no origin branch set");
625
    }
626
627
    if (!isItemTransferred($itemnumber)) {
628
        return (0, 4, "Cannot return an item that is not transferred");
629
    }
630
631
    my $dbh = C4::Context->dbh;
632
    my $sth = $dbh->prepare(q{
633
        SELECT items.itemnumber, items.barcode, items.homebranch, items.holdingbranch FROM collections_tracking
634
        LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber
635
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
636
        WHERE issues.borrowernumber IS NULL
637
          AND collections_tracking.colId = ? AND collections_tracking.itemnumber = ?
638
    });
639
640
    $sth->execute($colId, $itemnumber) or return (0, 5, $sth->errstr);
641
    my ($dotransfer, $messages, $iteminformation);
642
    if (my $item = $sth->fetchrow_hashref) {
643
        unless (GetReserveStatus($item->{itemnumber}) eq "Waiting") {
644
            ($dotransfer, $messages, $iteminformation)
645
                = transferbook($originBranch, $item->{barcode}, 1);
646
        }
647
    }
648
    # Push all issues with the transfer into a list for template usage.
649
    if (!$dotransfer) {
650
        my @errorlist;
651
        for my $message (keys %$messages) {
652
            push(@errorlist, $message);
653
        }
654
        return (0, 6, \@errorlist);
655
    }
656
657
    $sth = $dbh->prepare(q{
658
        UPDATE collections_tracking
659
        SET
660
        transfer_branch = NULL
661
        WHERE itemnumber = ?
662
    });
663
    $sth->execute($itemnumber) or return (0, 7, $sth->errstr);
664
    ModItem({ homebranch => $originBranch }, undef, $itemnumber);
665
386
    return 1;
666
    return 1;
387
}
667
}
388
668
Lines 404-449 Transfers a collection to another branch Link Here
404
=cut
684
=cut
405
685
406
sub TransferCollection {
686
sub TransferCollection {
407
    my ( $colId, $colBranchcode ) = @_;
687
    my ($colId, $colBranchcode) = @_;
408
688
409
    ## Check for all neccessary parameters
689
    ## Check for all neccessary parameters
410
    if ( !$colId ) {
690
    if (!$colId) {
411
        return ( 0, 1, "No Id Given" );
691
        return (0, 1, "No id given");
412
    }
692
    }
413
    if ( !$colBranchcode ) {
693
    if (!$colBranchcode) {
414
        return ( 0, 2, "No Branchcode Given" );
694
        return (0, 2, "No branchcode given");
415
    }
695
    }
416
696
417
    my $dbh = C4::Context->dbh;
697
    my $colItems = GetItemsInCollection($colId);
698
    my $colItemsCount = scalar(@$colItems);
699
    my ($transfersuccess, $error, @errorlist);
700
    my $problemItemCount = 0;
701
702
    for my $item (@$colItems) {
703
  my $itemOriginBranch = GetItemOriginBranch($item->{'itemnumber'});
704
    my $itemCurHomeBranch = $item->{'homebranch'};
705
        my ($dotransfer, $errorcode, $errormessage) = TransferCollectionItem($colId, $item->{'itemnumber'}, $colBranchcode);
706
        if (!$dotransfer) {
707
            $problemItemCount++;
708
            push(@errorlist, $item->{'title'} . ":");
709
            if (ref $errormessage eq "ARRAY") {
710
                for my $message (@$errormessage) {
711
                    push(@errorlist, $message);
712
                }
713
            }
714
            else {
715
                push (@errorlist, $errormessage);
716
            }
717
        }
718
    }
418
719
419
    my $sth;
720
    if ($problemItemCount == $colItemsCount) {
420
    $sth = $dbh->prepare(
721
        return (0, 3, \@errorlist);
421
        "UPDATE collections
722
    }
422
                        SET 
723
    elsif ($problemItemCount < $colItemsCount) {
423
                        colBranchcode = ? 
724
        return (1, 0, \@errorlist);
424
                        WHERE colId = ?"
725
    }
425
    );
726
    else {
426
    $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
727
        return 1;
728
    }
729
}
427
730
428
    $sth = $dbh->prepare(q{
731
=head2 TransferItem
429
        SELECT items.itemnumber, items.barcode FROM collections_tracking
732
733
 ($success, $errorcode, $errormessage) = TransferCollection($colId, $itemnumber, $transferBranch);
734
735
Transfers an item to another branch
736
737
 Input:
738
   $colId: id of the collection to be updated
739
   $itemnumber: the itemnumber of the item in the collection being transferred
740
   $transferBranch: branch where item is moving to
741
742
 Output:
743
   $success: 1 if all database operations were successful, 0 otherwise
744
   $errorCode: Code for reason of failure, good for translating errors in templates
745
   $errorMessage: English description of error
746
747
=cut
748
749
sub TransferCollectionItem {
750
    my ($colId, $itemnumber, $transferBranch) = @_;
751
752
    if (!$colId) {
753
        return (0, 1, "No collection id given");
754
    }
755
756
    if (!$itemnumber) {
757
        return (0, 2, "No itemnumber given");
758
    }
759
760
    if (!$transferBranch) {
761
        return (0, 3, "No transfer branch given");
762
    }
763
764
    if (isItemTransferred($itemnumber)) {
765
        return (0, 4, "Item is already transferred");
766
    }
767
768
    my $dbh = C4::Context->dbh;
769
    my $sth = $dbh->prepare(q{
770
        SELECT items.itemnumber, items.barcode, items.homebranch FROM collections_tracking
430
        LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber
771
        LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber
431
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
772
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
432
        WHERE issues.borrowernumber IS NULL
773
        WHERE issues.borrowernumber IS NULL
433
          AND collections_tracking.colId = ?
774
          AND collections_tracking.colId = ? AND collections_tracking.itemnumber = ?
434
    });
775
    });
435
    $sth->execute($colId) or return ( 0, 4, $sth->errstr );
776
436
    my @results;
777
    $sth->execute($colId, $itemnumber) or return ( 0, 5, $sth->errstr );
437
    while ( my $item = $sth->fetchrow_hashref ) {
778
    my ($dotransfer, $messages, $iteminformation);
438
        transferbook( $colBranchcode, $item->{barcode},
779
    if (my $item = $sth->fetchrow_hashref) {
439
            my $ignore_reserves = 1 )
780
        unless (GetReserveStatus($item->{itemnumber}) eq "Waiting") {
440
          unless ( GetReserveStatus( $item->{itemnumber} ) eq "Waiting" );
781
            ($dotransfer, $messages, $iteminformation)
782
                = transferbook($transferBranch, $item->{barcode}, 1);
783
        }
441
    }
784
    }
442
785
443
    return 1;
786
    # Push all issues with the transfer into a list for template usage.
787
    if (!$dotransfer) {
788
        my @errorlist;
789
        for my $message (keys %$messages) {
790
            push(@errorlist, $message);
791
        }
792
        return (0, 6, \@errorlist);
793
    }
794
    my $transferred = 1;
444
795
796
    $sth = $dbh->prepare(q{
797
        UPDATE collections_tracking
798
        SET
799
        transfer_branch = ?,
800
        transferred = ?
801
        WHERE itemnumber = ?
802
    });
803
    $sth->execute($transferBranch, $transferred, $itemnumber) or return (0, 7, $sth->errstr);
804
    ModItem({ homebranch => $transferBranch }, undef, $itemnumber);
805
806
    return 1;
445
}
807
}
446
808
809
447
=head2 GetCollectionItemBranches
810
=head2 GetCollectionItemBranches
448
811
449
  my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
812
  my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
Lines 461-467 sub GetCollectionItemBranches { Link Here
461
824
462
    my ( $sth, @results );
825
    my ( $sth, @results );
463
    $sth = $dbh->prepare(
826
    $sth = $dbh->prepare(
464
"SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking
827
"SELECT holdingbranch, transfer_branch FROM items, collections, collections_tracking
465
                        WHERE items.itemnumber = collections_tracking.itemnumber
828
                        WHERE items.itemnumber = collections_tracking.itemnumber
466
                        AND collections.colId = collections_tracking.colId
829
                        AND collections.colId = collections_tracking.colId
467
                        AND items.itemnumber = ?"
830
                        AND items.itemnumber = ?"
Lines 470-476 sub GetCollectionItemBranches { Link Here
470
833
471
    my $row = $sth->fetchrow_hashref;
834
    my $row = $sth->fetchrow_hashref;
472
835
473
    return ( $$row{'holdingbranch'}, $$row{'colBranchcode'}, );
836
    return ( $$row{'holdingbranch'}, $$row{'transfer_branch'}, );
837
}
838
839
=head2 GetTransferredItemCount
840
841
  $transferredCount = GetTransferredItemCount($colId);
842
843
=cut
844
845
sub GetTransferredItemCount {
846
  my $colId = shift;
847
848
  my $dbh = C4::Context->dbh;
849
  my $query = "SELECT COUNT(*)
850
              FROM collections_tracking
851
              WHERE colId = ? AND transferred = 1
852
              ";
853
  my $sth = $dbh->prepare($query);
854
  $sth->execute($colId) or die $sth->errstr();
855
856
  my $result = $sth->fetchrow();
857
  return $result;
858
}
859
860
=head2 GetCollectionItemCount
861
862
  $colItemCount = GetCollectionItemCount($colId);
863
864
=cut
865
866
sub GetCollectionItemCount {
867
  my $colId = shift;
868
869
  my $dbh = C4::Context->dbh;
870
  my $query = "SELECT COUNT(colId)
871
              FROM collections_tracking
872
              WHERE colId = ?
873
              ";
874
  my $sth = $dbh->prepare($query);
875
  $sth->execute($colId) or die $sth->errstr();
876
877
  my $result = $sth->fetchrow();
878
  return $result;
474
}
879
}
475
880
476
=head2 isItemInThisCollection
881
=head2 isItemInThisCollection
Lines 520-525 sub isItemInAnyCollection { Link Here
520
    }
925
    }
521
}
926
}
522
927
928
=head2 isItemTramsferred
929
930
($transferred, $errorcode, $errormessage) = isItemTransferred($itemnumber);
931
932
=cut
933
934
sub isItemTransferred {
935
    my $itemnumber = shift;
936
937
    my $dbh = C4::Context->dbh;
938
    my $sth;
939
940
    my $query = '
941
    Select * FROM collections_tracking
942
    WHERE itemnumber = ?
943
    ';
944
945
    $sth = $dbh->prepare($query);
946
    $sth->execute($itemnumber) or return (0, 1, $sth->errstr);
947
    my $resultrow = $sth->fetchrow_hashref;
948
    if (!$resultrow) {
949
        return (0, 2, "Item is not in a collection");
950
    }
951
952
    if ($resultrow->{'transferred'}) {
953
        return 1;
954
    }
955
    else {
956
        return 0;
957
    }
958
959
}
960
961
962
963
=head2 GetItemOriginBranch
964
965
$originBranch = GetItemOriginBranch($itemnumber);
966
967
Kd-139: Returns the given item's origin branch, e.g. the home branch at the time it was
968
being added to a collection or 0 the item has no origin
969
970
=cut
971
972
sub GetItemOriginBranch {
973
    my $itemnumber = shift;
974
975
    my $dbh = C4::Context->dbh;
976
    my $sth;
977
978
    my $query = '
979
    SELECT *
980
    FROM collections_tracking
981
    WHERE itemnumber = ?
982
    ';
983
    $sth = $dbh->prepare($query);
984
    $sth->execute($itemnumber);
985
    my $resultrow = $sth->fetchrow_hashref;
986
987
    if (!$resultrow) {
988
        return 0;
989
    }
990
991
    my $originBranchCode = $resultrow->{'origin_branchcode'};
992
    if ($originBranchCode) {
993
        return $originBranchCode;
994
    }
995
    else {
996
        return 0;
997
    }
998
}
999
523
1;
1000
1;
524
1001
525
__END__
1002
__END__
(-)a/catalogue/detail.pl (+4 lines)
Lines 44-49 use Koha::DateUtils; Link Here
44
use C4::HTML5Media;
44
use C4::HTML5Media;
45
use C4::CourseReserves qw(GetItemCourseReservesInfo);
45
use C4::CourseReserves qw(GetItemCourseReservesInfo);
46
use C4::Acquisition qw(GetOrdersByBiblionumber);
46
use C4::Acquisition qw(GetOrdersByBiblionumber);
47
use C4::RotatingCollections qw(GetItemsCollection);
47
48
48
my $query = CGI->new();
49
my $query = CGI->new();
49
50
Lines 258-263 foreach my $item (@items) { Link Here
258
        $item->{nocancel} = 1;
259
        $item->{nocancel} = 1;
259
    }
260
    }
260
261
262
    # Check the item's rotating collection status
263
    $item->{itemsCollection} = GetItemsCollection($item->{itemnumber});
264
261
    # item has a host number if its biblio number does not match the current bib
265
    # item has a host number if its biblio number does not match the current bib
262
    if ($item->{biblionumber} ne $biblionumber){
266
    if ($item->{biblionumber} ne $biblionumber){
263
        $item->{hostbiblionumber} = $item->{biblionumber};
267
        $item->{hostbiblionumber} = $item->{biblionumber};
(-)a/circ/returns.pl (-4 / +4 lines)
Lines 600-609 $template->param( Link Here
600
    BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"),
600
    BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"),
601
);
601
);
602
602
603
my $itemnumber = GetItemnumberFromBarcode( $query->param('barcode') );
603
my $itemnumber = GetItemnumberFromBarcode($query->param('barcode'));
604
if ( $itemnumber ) {
604
if ($itemnumber) {
605
   my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
605
   my ($holdingBranch, $collectionBranch) = GetCollectionItemBranches($itemnumber);
606
    if ( ! ( $holdingBranch eq $collectionBranch ) ) {
606
    if ($holdingBranch ne $collectionBranch) {
607
        $template->param(
607
        $template->param(
608
          collectionItemNeedsTransferred => 1,
608
          collectionItemNeedsTransferred => 1,
609
          collectionBranch => GetBranchName($collectionBranch),
609
          collectionBranch => GetBranchName($collectionBranch),
(-)a/installer/data/mysql/kohastructure.sql (-3 / +10 lines)
Lines 481-494 CREATE TABLE collections ( Link Here
481
  colTitle varchar(100) NOT NULL DEFAULT '',
481
  colTitle varchar(100) NOT NULL DEFAULT '',
482
  colDesc text NOT NULL,
482
  colDesc text NOT NULL,
483
  colBranchcode varchar(10) DEFAULT NULL, -- 'branchcode for branch where item should be held.'
483
  colBranchcode varchar(10) DEFAULT NULL, -- 'branchcode for branch where item should be held.'
484
  owningBranchcode varchar(10) DEFAULT NULL,
484
  PRIMARY KEY (colId)
485
  PRIMARY KEY (colId)
485
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
486
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
486
487
487
--
488
--
488
-- Constraints for table `collections`
489
-- Constraints for table `collections`
489
--
490
--
490
ALTER TABLE `collections`
491
ALTER TABLE collections
491
  ADD CONSTRAINT `collections_ibfk_1` FOREIGN KEY (`colBranchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE;
492
  ADD CONSTRAINT collections_ibfk_1 FOREIGN KEY (colBranchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
493
  ADD CONSTRAINT collections_owning_1 FOREIGN KEY (owningBranchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
492
494
493
--
495
--
494
-- Table: collections_tracking
496
-- Table: collections_tracking
Lines 498-504 CREATE TABLE collections_tracking ( Link Here
498
  collections_tracking_id integer(11) NOT NULL auto_increment,
500
  collections_tracking_id integer(11) NOT NULL auto_increment,
499
  colId integer(11) NOT NULL DEFAULT 0 comment 'collections.colId',
501
  colId integer(11) NOT NULL DEFAULT 0 comment 'collections.colId',
500
  itemnumber integer(11) NOT NULL DEFAULT 0 comment 'items.itemnumber',
502
  itemnumber integer(11) NOT NULL DEFAULT 0 comment 'items.itemnumber',
501
  PRIMARY KEY (collections_tracking_id)
503
  origin_branchcode varchar(10) DEFAULT NULL,
504
  transfer_branch varchar(10) DEFAULT NULL,
505
  transferred tinyint(1) DEFAULT '0',
506
  PRIMARY KEY (collections_tracking_id),
507
  CONSTRAINT collections_origin_1 FOREIGN KEY (origin_branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
508
  CONSTRAINT collections_transfer_1 FOREIGN KEY (transfer_branch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
502
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
509
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
503
510
504
--
511
--
(-)a/installer/data/mysql/updatedatabase.pl (+21 lines)
Lines 8629-8634 if ( CheckVersion($DBversion) ) { Link Here
8629
    SetVersion($DBversion);
8629
    SetVersion($DBversion);
8630
}
8630
}
8631
8631
8632
$DBversion = "3.17.00.XXX";
8633
if ( CheckVersion($DBversion) ) {
8634
    $dbh->do(q{
8635
        ALTER TABLE collections_tracking
8636
            ADD origin_branchcode VARCHAR(10) NULL DEFAULT NULL,
8637
            ADD transfer_branch VARCHAR(10) NULL DEFAULT NULL,
8638
            ADD CONSTRAINT collections_origin_1 FOREIGN KEY (origin_branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
8639
            ADD CONSTRAINT collections_transfer_1 FOREIGN KEY (transfer_branch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
8640
            ADD transferred TINYINT(1) DEFAULT 0
8641
    });
8642
8643
    $dbh->do(q{
8644
        ALTER TABLE collections
8645
            ADD owningBranchcode VARCHAR(10) NULL DEFAULT NULL,
8646
            ADD CONSTRAINT collections_owning_1 FOREIGN KEY (owningBranchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
8647
    });
8648
8649
    print "Upgrade to $DBversion done (Bug 8836 - Resurrect Rotating Collections additions)\n";
8650
    SetVersion($DBversion);
8651
}
8652
8632
=head1 FUNCTIONS
8653
=head1 FUNCTIONS
8633
8654
8634
=head2 TableExists($table)
8655
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-1 / +6 lines)
Lines 580-586 function verify_images() { Link Here
580
                        </td>
580
                        </td>
581
                    [% END %]
581
                    [% END %]
582
                    <td class="location">[% UNLESS ( singlebranchmode ) %][% item.branchname %] [% END %]</td>
582
                    <td class="location">[% UNLESS ( singlebranchmode ) %][% item.branchname %] [% END %]</td>
583
                    <td class="homebranch">[% item.homebranch %]<span class="shelvingloc">[% item.location %]</span> </td>
583
                    <td class="homebranch">[% item.homebranch %]<span class="shelvingloc">[% item.location %]</span>
584
                        [% IF item.itemsCollection %]
585
                            <span class="shelvingloc">(Col.: <a href="/cgi-bin/koha/rotating_collections/addItems.pl?colId=[% item.itemsCollection %]">[% item.itemsCollection%]</a>)</span>
586
                    </td>
587
                    [% END %]
588
                    </td>
584
                    [% IF ( itemdata_ccode ) %]<td>[% item.ccode %]</td>[% END %]
589
                    [% IF ( itemdata_ccode ) %]<td>[% item.ccode %]</td>[% END %]
585
                    <td class="itemcallnumber">[% IF ( item.itemcallnumber ) %] [% item.itemcallnumber %][% END %]</td>
590
                    <td class="itemcallnumber">[% IF ( item.itemcallnumber ) %] [% item.itemcallnumber %][% END %]</td>
586
                    <td class="status">
591
                    <td class="status">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt (-23 / +317 lines)
Lines 1-11 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Add/Remove items</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Manage collection</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'datatables.inc' %]
5
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
4
<script type="text/javascript">
6
<script type="text/javascript">
5
    //<![CDATA[
7
    //<![CDATA[
6
        $( document ).ready(function() {
8
        $( document ).ready(function() {
7
            $("#barcode").focus();
9
          $("#barcode").focus();
10
11
          // KD-139: Handle button clicking events in the item table of this view.
12
          $("body").on("click", "a[id^=remove-colitem]", function() {
13
            var selectedItemBarcode = this.getAttribute("data-barcode");
14
            var selectedItemTitle = this.getAttribute("data-title");
15
            if (selectedItemBarcode) {
16
              $("#barcode").val(selectedItemBarcode);
17
              $("#modal-remove-body-message").text("Please confirm the removal of item with the barcode: " + selectedItemBarcode
18
                                            + " and title: " + selectedItemTitle + " from the collection: " + "[% colTitle %]");
19
              $("input[name^=removeItem]").prop('checked', true);
20
            }
21
          });
22
23
          $("body").on("click", "a[id^=return-colitem]", function() {
24
            var selectedItemNumber = this.getAttribute("data-itemnumber");
25
            var selectedItemTitle = this.getAttribute("data-title");
26
            var selectedItemOrigin = this.getAttribute("data-originbranch");
27
            if (selectedItemNumber && selectedItemTitle && selectedItemOrigin) {
28
              $("#btn-return-item-confirm").attr("data-itemnumber", selectedItemNumber)
29
              $("#modal-return-body-message").text("Please confirm the return of the item '" + selectedItemTitle
30
                                            + "' to  " + selectedItemOrigin);
31
            }
32
          });
33
34
          $("body").on("click", "a[id^=transfer-colitem]", function() {
35
            var selectedItemNumber = this.getAttribute("data-itemnumber");
36
            var selectedItemTitle = this.getAttribute("data-title");
37
            if (selectedItemNumber) {
38
              $("#modal-transfer-item-body-message").text("Please select a transfer location for the item: " + selectedItemTitle);
39
              $("#btn-transfer-item-confirm").attr("data-itemnumber", selectedItemNumber);
40
            }
41
          });
42
43
          $("#transfer-col").click(function() {
44
            var collectionId = "[% colId %]";
45
            var collectionTitle = "[% colTitle %]";
46
            var collectionTransferText = $("select[id='transfer-branch'] option:selected").text();
47
            var collectionTransferTo = $("select[id=transfer-branch]").val();
48
            if (collectionId && collectionTransferTo) {
49
              $("#btn-transfer-confirm").attr("data-transferto", collectionTransferTo);
50
              $("#modal-transfer-body-message").text("Please confirm the transfer of collection \'"
51
                                                      + collectionTitle + "\' to "
52
                                                      + collectionTransferText);
53
            }
54
          });
55
56
          $("#btn-transfer-confirm").click(function() {
57
            var colToTransfer = this.getAttribute('data-colid');
58
            var colToTransferTo = this.getAttribute('data-transferto');
59
            if (colToTransfer && colToTransferTo) {
60
              transferCollection(colToTransfer, colToTransferTo);
61
            }
62
          });
63
64
          $("#btn-remove-confirm").click(function() {
65
            $("form:last").submit();
66
            $("input[name^=removeItem]").prop('checked', false);
67
          });
68
69
          $("#btn-transfer-item-confirm").click(function() {
70
            var itemToTransfer = this.getAttribute("data-itemnumber");
71
            var colToTransferTo = $("select[id=transfer-item-select]").val();
72
            var colId = "[% colId %]";
73
            if (itemToTransfer && colToTransferTo) {
74
              transferItem(colId, itemToTransfer, colToTransferTo);
75
            }
76
          });
77
78
          $("#btn-return-item-confirm").click(function() {
79
            var itemToReturn = this.getAttribute("data-itemnumber");
80
            var colId = "[% colId %]";
81
            if (itemToReturn && colId) {
82
              returnItem(colId, itemToReturn);
83
            }
84
          });
85
86
          $("#btn-remove-cancel").click(function() {
87
            $("#barcode").val("");
88
            $("input[name^=removeItem]").prop('checked', false);
89
          });
90
91
          $(document).ajaxStart(function (event) {
92
            $("#alert-block").hide();
93
            $("#alert-block").after($(".loading").show());
94
          });
95
          $(document).ajaxStop(function () {
96
            $(".loading").hide();
97
            $("#alert-block").show();
98
          });
99
100
          var colTable = $("#table-col-items").dataTable($.extend(true, {}, dataTablesDefaults, {
101
            'bAutoWidth': true,
102
            "aoColumnDefs": [
103
              { 'bSortable': false, 'aTargets': [ 'nosort' ] }
104
            ]
105
          }));
106
        });
107
108
      // KD-139: Performs a transfer on a collection using a standard ajax-call
109
      function transferCollection(selectedCollectionId, selectedCollectionTransferTo) {
110
        $.post("transferCollection.pl",
111
          {
112
            colId: selectedCollectionId,
113
            toBranch: selectedCollectionTransferTo,
114
            transferAction: "collectionTransfer"
115
          })
116
          .done(function(response) {
117
            var resultMsg = $(response).find("#alert-block").html();
118
            $("#alert-block").html(resultMsg);
119
            if ($("#alert-block").find('.alert-success')) {
120
              reloadDataTable();
121
            }
122
        });
123
      }
124
125
      function transferItem(selectedCollectionId, selectedItemNumber, selectedCollectionTransferTo) {
126
        $.post("transferCollection.pl",
127
          {
128
            colId: selectedCollectionId,
129
            toBranch: selectedCollectionTransferTo,
130
            itemNumber: selectedItemNumber,
131
            transferAction: "itemTransfer"
132
          })
133
          .done(function(response) {
134
            var resultMsg = $(response).find("#alert-block").html();
135
            $("#alert-block").html(resultMsg);
136
            if ($("#alert-block").find('.alert-success')) {
137
              reloadDataTable();
138
            }
139
        });
140
      }
141
142
      function returnItem(selectedCollectionId, selectedItemNumber) {
143
        $.post("transferCollection.pl",
144
          {
145
            colId: selectedCollectionId,
146
            itemNumber: selectedItemNumber,
147
            transferAction: "itemReturn"
148
          })
149
          .done(function(response) {
150
            var resultMsg = $(response).find("#alert-block").html();
151
            $("#alert-block").html(resultMsg);
152
            if ($("#alert-block").find('.alert-success')) {
153
              reloadDataTable();
154
            }
8
        });
155
        });
156
      }
157
158
      function returnCollection(selectedCollectionId) {
159
        $.post("transferCollection.pl",
160
          {
161
            colId: selectedCollectionId,
162
            transferAction: "collectionReturn"
163
          })
164
          .done(function(response) {
165
            var resultMsg = $(response).find("#alert-block").html();
166
            $("#alert-block").html(resultMsg);
167
            if ($("#alert-block").find('.alert-success')) {
168
              reloadDataTable();
169
            }
170
        });
171
      }
172
173
      function reloadDataTable() {
174
        $.get("addItems.pl?colId=[% colId %]", function(response) {
175
          var newCollectionsTable = $(response).find("#table-col-items").parent().html();
176
          var oldCollectionsTable = $("#table-col-items").parent();
177
          oldCollectionsTable.replaceWith(newCollectionsTable);
178
          $("#table-col-items").dataTable($.extend(true, {}, dataTablesDefaults, {
179
            'bAutoWidth': true,
180
            "aoColumnDefs": [
181
              { 'bSortable': false, 'aTargets': [ 'nosort' ] }
182
            ]
183
          }));
184
        });
185
        $("#barcode").focus();
186
      }
9
    //]]>
187
    //]]>
10
</script>
188
</script>
11
</head>
189
</head>
Lines 19-48 Link Here
19
<div id="bd">
197
<div id="bd">
20
        <div class="yui-gb">
198
        <div class="yui-gb">
21
199
22
      <h1>Rotating collections: Add/Remove items</h1>
200
      <h1>Rotating collections: Manage collection</h1>
23
201
24
      <div>
202
      <div id="alert-block">
25
          <br />
203
          <br />
26
          [% IF ( previousActionAdd ) %]
204
          [% IF ( previousActionAdd ) %]
27
            [% IF ( addSuccess ) %]
205
            [% IF ( addSuccess ) %]
28
              <div>Item with barcode '[% addedBarcode %]' Added successfully!</div>
206
              <div class="alert-success">Item with barcode '[% addedBarcode %]' Added successfully!</div>
29
            [% ELSE %]
207
            [% ELSE %]
30
              <div>Failed to add item with barcode '[% addedBarcode %]'!</div>
208
              <div class="alert-error">Failed to add item with barcode '[% addedBarcode %]'!</div>
31
              <div>Reason: <strong>[% failureMessage %]</strong></div>
209
              <div class="alert-error">Reason: <strong>[% failureMessage %]</strong></div>
32
            [% END %]
210
            [% END %]
33
          [% END %]
211
          [% END %]
34
212
35
          [% IF ( previousActionRemove ) %]
213
          [% IF ( previousActionRemove ) %]
36
            [% IF ( removeSuccess ) %]
214
            [% IF ( removeSuccess ) %]
37
              <div>Item with barcode '[% addedBarcode %]' Removed successfully!</div>
215
              <div class="alert-success">Item with barcode '[% removedBarcode %]' Removed successfully!
216
                [% IF messages %]
217
                  Transfer messages:
218
                  <ul>
219
                    [% FOREACH message in messages %]
220
                      <li>[% message %]</li>
221
                    [% END %]
222
                  </ul>
223
                [% END %]
224
              </div>
38
            [% ELSE %]
225
            [% ELSE %]
39
              <div>Failed to remove item with barcode '[% removedBarcode %]'!</div>
226
              <div class="alert-error">Failed to remove item with barcode '[% removedBarcode %]'!</div>
40
              <div>Reason: <strong>[% failureMessage %]</strong></div>
227
              <div class="alert-error">Reason: <strong>[% failureMessage %]</strong></div>
41
            [% END %]
228
            [% END %]
42
          [% END %]
229
          [% END %]
43
44
          <h3>Add item to <i>[% colTitle %]</i></h3>
45
      </div>
230
      </div>
231
          <h3>Add items to <i>[% colTitle %]</i></h3>
46
232
47
      <div>
233
      <div>
48
        <form action="addItems.pl" method="post">
234
        <form action="addItems.pl" method="post">
Lines 64-83 Link Here
64
        </form>
250
        </form>
65
      </div>
251
      </div>
66
252
253
      <h2>Items in this collection</h2>
67
      <div>
254
      <div>
68
        <h2>Items in this collection</h2>
69
        [% IF ( collectionItemsLoop ) %]
255
        [% IF ( collectionItemsLoop ) %]
70
          <table>
256
          <table id="table-col-items">
71
            <tr>
257
            <thead>
72
              <th>Title</th>
258
              <tr>
73
              <th>Call number</th>
259
                <th>Title</th>
74
              <th>Barcode</th>
260
                <th>Call number</th>
75
            </tr>
261
                <th>Barcode</th>
262
                <th>Origin library</th>
263
                <th>Home library</th>
264
                <th>Current location</th>
265
                <th>Transferred</th>
266
                <th class="nosort">Transfer</th>
267
                <th class="nosort">Return</th>
268
                <th class="nosort">Remove</th>
269
              </tr>
270
            </thead>
76
            [% FOREACH collectionItemsLoo IN collectionItemsLoop %]
271
            [% FOREACH collectionItemsLoo IN collectionItemsLoop %]
77
              <tr>
272
              <tr>
78
                <td>[% collectionItemsLoo.title |html %]</td>
273
                <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% collectionItemsLoo.biblionumber %]">[% collectionItemsLoo.title |html %]</a></td>
79
                <td>[% collectionItemsLoo.itemcallnumber %]</td>
274
                <td>[% collectionItemsLoo.itemcallnumber %]</td>
80
                <td>[% collectionItemsLoo.barcode %]</td>
275
                <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% collectionItemsLoo.biblionumber %]#item[% collectionItemsLoo.itemnumber %]">[% collectionItemsLoo.barcode %]</a></td>
276
                <td>[% collectionItemsLoo.origin_branchname %]</td>
277
                <td>[% collectionItemsLoo.branchname %]</td>
278
                <td>[% collectionItemsLoo.holdingbranchname %]</td>
279
                <td>[% IF collectionItemsLoo.transferred %]Yes[% ELSE %]No[% END %]</td>
280
                <td><a id="transfer-colitem-[% collectionItemsLoo.barcode %]" data-toggle="modal" href="#transferItemModal" class="btn btn-small" data-itemnumber="[% collectionItemsLoo.itemnumber %]" data-barcode="[% collectionItemsLoo.barcode %]" data-title="[% collectionItemsLoo.title %]"><i class="icon-gift"></i> Transfer</a></td>
281
                <td><a id="return-colitem-[% collectionItemsLoo.barcode %]" data-toggle="modal" href="#returnColItemModal" class="btn btn-small" data-itemnumber="[% collectionItemsLoo.itemnumber %]" data-title="[% collectionItemsLoo.title %]" data-originbranch="[% collectionItemsLoo.origin_branchname %]"><i class="icon-repeat"></i> Return</a></td>
282
                <td><a id="remove-colitem-[% collectionItemsLoo.barcode %]" data-toggle="modal" href="#removeColItemModal" class="btn btn-small" data-barcode="[% collectionItemsLoo.barcode %]" data-title="[% collectionItemsLoo.title %]"><i class="icon-remove"></i> Remove</a></td>
81
              </tr>
283
              </tr>
82
            [% END %]
284
            [% END %]
83
          </table>
285
          </table>
Lines 88-97 Link Here
88
290
89
      <div>
291
      <div>
90
        <br/>
292
        <br/>
91
        <input type="button" value="Return to rotating collections home" onclick="window.location.href='rotatingCollections.pl'">
293
        <a href="rotatingCollections.pl" class="btn btn-small"><i class="icon-home"></i> Return to rotating collections home</a>
294
        <a href="#transferColModal" data-toggle="modal" id="transfer-col" class="btn btn-small"><i class="icon-gift"></i> Transfer this collection</a>
295
        <select name="transfer-branch" id="transfer-branch">
296
            [% FOREACH branch IN branchesLoop %]
297
              [% IF ( branch.selected ) %]
298
                <option value="[% branch.value %]" selected="selected">[% branch.branchname %]</option>
299
              [% ELSE %]
300
                <option value="[% branch.value %]">[% branch.branchname %]</option>
301
              [% END %]
302
            [% END %]
303
        </select></td>
92
      </div>
304
      </div>
93
94
</div>
305
</div>
95
</div>
306
</div>
307
<!-- Modal for confirm deletion box-->
308
<div class="modal hide" id="removeColItemModal" tabindex="-1" role="dialog" aria-labelledby="removeColItemModalLabel" aria-hidden="true">
309
    <div class="modal-header">
310
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
311
        <h3 id="removeColItemModalHeader">Confirm item removal</h3>
312
    </div>
313
    <div class="modal-body">
314
       <strong><p id="modal-remove-body-message"></p></strong>
315
    </div>
316
    <div class="modal-footer">
317
        <button type="button" class="btn btn-primary" id="btn-remove-cancel" data-dismiss="modal">Cancel</button>
318
        <button type="submit" class="btn btn-default" id="btn-remove-confirm">Remove item</button>
319
    </div>
320
</div>
321
<!-- Modal for item transfer-->
322
<div class="modal hide" id="transferItemModal" tabindex="-1" role="dialog" aria-labelledby="transferItemModalLabel" aria-hidden="true">
323
    <div class="modal-header">
324
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
325
        <h3 id="transferItemModalHeader">Select item transfer location</h3>
326
    </div>
327
    <div class="modal-body">
328
     <strong><p id="modal-transfer-item-body-message"></p></strong>
329
     <label for="transfer-item-select">Select transfer location: </label>
330
      <select name="transfer-item-select" id="transfer-item-select">
331
        [% FOREACH branch IN branchesLoop %]
332
          [% IF ( branch.selected ) %]
333
            <option value="[% branch.value %]" selected="selected">[% branch.branchname %]</option>
334
          [% ELSE %]
335
            <option value="[% branch.value %]">[% branch.branchname %]</option>
336
          [% END %]
337
        [% END %]
338
      </select>
339
    </div>
340
    <div class="modal-footer">
341
      <button type="button" class="btn btn-primary" id="btn-transfer-cancel" data-dismiss="modal">Cancel</button>
342
      <button type="submit" class="btn btn-default" id="btn-transfer-item-confirm" data-colid="[% colId %]" data-transferto="" data-itemnumber="" data-dismiss="modal">Transfer</button>
343
    </div>
344
</div>
345
<!-- Modal for confirm item return box-->
346
<div class="modal hide" id="returnColItemModal" tabindex="-1" role="dialog" aria-labelledby="returnColItemModalLabel" aria-hidden="true">
347
    <div class="modal-header">
348
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
349
        <h3 id="returnColItemModalHeader">Confirm item return</h3>
350
    </div>
351
    <div class="modal-body">
352
       <strong><p id="modal-return-body-message"></p></strong>
353
    </div>
354
    <div class="modal-footer">
355
        <button type="button" class="btn btn-primary" id="btn-return-item-cancel" data-dismiss="modal">Cancel</button>
356
        <button type="submit" class="btn btn-default" id="btn-return-item-confirm" data-itemnumber="" data-dismiss="modal">Return item</button>
357
    </div>
358
</div>
359
<!-- Modal for confirm transfer box-->
360
<div class="modal hide" id="transferColModal" tabindex="-1" role="dialog" aria-labelledby="transferColModalLabel" aria-hidden="true">
361
    <div class="modal-header">
362
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
363
        <h3 id="transferColModalHeader">Confirm collection transfer</h3>
364
    </div>
365
    <div class="modal-body">
366
       <strong><p id="modal-transfer-body-message"></p></strong>
367
       <p id="modal-transfer-body-desc"></p>
368
    </div>
369
    <div class="modal-footer">
370
        <button type="button" class="btn btn-primary" id="btn-transfer-cancel" data-dismiss="modal">Cancel</button>
371
        <button type="submit" class="btn btn-default" id="btn-transfer-confirm" data-colid="[% colId %]" data-transferto="" data-dismiss="modal">Transfer collection</button>
372
    </div>
373
</div>
374
<!-- Modal for confirm return collection box-->
375
<div class="modal hide" id="returnColModal" tabindex="-1" role="dialog" aria-labelledby="returnColModalLabel" aria-hidden="true">
376
    <div class="modal-header">
377
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
378
        <h3 id="returnColModalHeader">Confirm collection return</h3>
379
    </div>
380
    <div class="modal-body">
381
       <strong><p id="modal-return-body-message"></p></strong>
382
       <p id="modal-return-body-desc"></p>
383
    </div>
384
    <div class="modal-footer">
385
        <button type="button" class="btn btn-primary" id="btn-return-cancel" data-dismiss="modal">Cancel</button>
386
        <button type="submit" class="btn btn-default" id="btn-return-confirm" data-colid="[% colId %]" data-dismiss="modal">Return collection</button>
387
    </div>
388
</div>
389
<div class="loading hide"><strong>Processing...</strong><img src="[% interface %]/[% theme %]/img/loading.gif" /></div>
96
[% INCLUDE 'intranet-bottom.inc' %]
390
[% INCLUDE 'intranet-bottom.inc' %]
97
391
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt (-43 / +133 lines)
Lines 1-6 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Edit collections</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Edit collections</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'datatables.inc' %]
5
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6
<script type="text/javascript">
7
  //<![CDATA[
8
      $( document ).ready(function() {
9
        var my_table = $("#table-collections").dataTable($.extend(true, {}, dataTablesDefaults, {
10
          'bAutoWidth': true,
11
          'bPaginate': false,
12
          'bFilter': false,
13
          'bInfo': false,
14
          "aoColumnDefs": [
15
            { 'bSortable': false, 'aTargets': [ 'nosort' ] }
16
          ]
17
        }));
18
19
        // KD-139: Handle collection removal clicks
20
        $("button[id^=remove-col]").click(function() {
21
          var selectedCollectionId = this.getAttribute('data-colId');
22
          var selectedCollectionTitle = this.getAttribute('data-colTitle');
23
          var selectedCollectionDesc = this.getAttribute('data-colDesc');
24
          if (selectedCollectionId && selectedCollectionTitle) {
25
            $("#btn-remove-confirm").attr("data-colId", selectedCollectionId);
26
            $("#modal-remove-body-message").text("Please confirm the removal of collection: " + selectedCollectionTitle);
27
            $("#modal-remove-body-desc").text("Description: " + selectedCollectionDesc);
28
          }
29
        });
30
31
        $("#btn-remove-confirm").click(function() {
32
          var colToRemove = this.getAttribute('data-colid');
33
          if (colToRemove) {
34
            removeCollection(colToRemove);
35
          }
36
        });
37
38
        $(document).ajaxStart(function (event) {
39
            $("#alert-block").hide();
40
            $("#alert-block").after($(".loading").show());
41
        });
42
        $(document).ajaxStop(function () {
43
            $(".loading").hide();
44
            $("#alert-block").show();
45
        });
46
47
      });
48
49
      // KD-139: Removes a collection using a standard ajax-call
50
      function removeCollection(selectedCollectionId) {
51
        $.get("editCollections.pl?action=delete&colId=" + selectedCollectionId, function(response) {
52
          var resultMsg = $(response).find("#alert-block");
53
          var rowToRemove = $("button[id=remove-col-" + selectedCollectionId + "]").closest('tr');
54
          $("#alert-block").html(resultMsg);
55
          if ($("#alert-block").find('.alert-success')) {
56
            reloadDataTable();
57
          }
58
          var collectionTableRows = $('#table-collections tr').length;
59
          if (collectionTableRows < 2) {
60
            window.location.reload();
61
          }
62
        });
63
      }
64
65
      function reloadDataTable() {
66
        $(document).ready(function() {
67
          $.get("editCollections.pl", function(response) {
68
              var newCollectionsTable = $(response).find("#table-collections");
69
              var oldCollectionsTable = $("#table-collections");
70
              $("#table-collections_wrapper #table-collections").remove();
71
              $("#create-edit-collection").after(newCollectionsTable.html());
72
          });
73
        });
74
      }
75
  //]]>
76
</script>
4
</head>
77
</head>
5
<body id="rcoll_editCollections" class="tools rcoll">
78
<body id="rcoll_editCollections" class="tools rcoll">
6
[% INCLUDE 'header.inc' %]
79
[% INCLUDE 'header.inc' %]
Lines 10-76 Link Here
10
83
11
<div id="doc3">
84
<div id="doc3">
12
<div id="bd">
85
<div id="bd">
13
        <div class="yui-gb">
86
    <div class="yui-gb">
14
      <h1>Rotating collections: Edit collections</h1>
87
      <h1>Rotating collections: Edit collections</h1>
15
88
16
<!--
89
      <div id="alert-block">
17
      [% IF ( previousActionCreate ) %]
90
      [% IF ( previousActionCreate ) %]
18
        [% IF ( createSuccess ) %]
91
        [% IF ( createSuccess ) %]
19
          <div>Collection '[% createdTitle %]' Created successfully!</div>
92
          <div class="alert-success">Collection '[% createdTitle %]' Created successfully!</div>
20
        [% ELSE %]
93
        [% ELSE %]
21
          <div>Collection '[% createdTitle %]' Failed to be created!</div>
94
          <div class="alert-error">Collection '[% createdTitle %]' Failed to be created!</div>
22
          <div>Reason: <strong>[% failureMessage %]</strong></div>
95
          <div class="alert-error">Reason: <strong>[% failureMessage %]</strong></div>
23
        [% END %]
96
        [% END %]
24
      [% END %]
97
      [% END %]
25
98
26
      [% IF ( previousActionDelete ) %]
99
      [% IF ( previousActionDelete ) %]
27
        [% IF ( DeleteSuccess ) %]
100
        [% IF ( deleteSuccess ) %]
28
          <div>Collection Deleted successfully!</div>
101
          <div class="alert-success">Collection Deleted successfully!</div>
29
        [% ELSE %]
102
        [% ELSE %]
30
          <div>Collection Failed to be deleted!</div>
103
          <div class="alert-error">Collection Failed to be deleted!</div>
31
        [% END %]
104
        [% END %]
32
      [% END %]
105
      [% END %]
33
-->
106
34
107
35
      [% IF ( previousActionUpdate ) %]
108
      [% IF ( previousActionUpdate ) %]
36
        [% IF ( updateSuccess ) %]
109
        [% IF ( updateSuccess ) %]
37
          <div>Collection '[% updatedTitle %]' Updated successfully!</div>
110
          <div class="alert-success">Collection '[% updatedTitle %]' Updated successfully!</div>
38
        [% ELSE %]
111
        [% ELSE %]
39
          <div>Collection '[% updatedTitle %]' Failed to be updated!</div>
112
          <div class="alert-error">Collection '[% updatedTitle %]' Failed to be updated!</div>
40
          <div>Reason: <strong>[% failureMessage %]</strong></div>
113
          <div class="alert-error">Reason: <strong>[% failureMessage %]</strong></div>
41
        [% END %]
114
        [% END %]
42
      [% END %]
115
      [% END %]
43
116
      </div><br />
44
      <div>
117
      <div>
45
        [% IF ( collectionsLoop ) %]
46
          <table>
47
           <thead>
48
            <tr>
49
              <th>Title</th>
50
              <th>Description</th>
51
              <th>Holding library</th>
52
              <th>&nbsp;</th>
53
              <th>&nbsp;</th>
54
            </tr>
55
           <thead>
56
           <tbody>
57
            [% FOREACH collectionsLoo IN collectionsLoop %]
58
              <tr>
59
                <td>[% collectionsLoo.colTitle %]</td>
60
                <td>[% collectionsLoo.colDesc %]</td>
61
                <td>[% collectionsLoo.colBranchcode %]</td>
62
                <td><a href="editCollections.pl?action=edit&amp;colId=[% collectionsLoo.colId %]">Edit</a></td>
63
                <td><a href="editCollections.pl?action=delete&amp;colId=[% collectionsLoo.colId %]">Delete</a></td>
64
              </tr>
65
            [% END %]
66
           </tbody>
67
          </table>
68
        [% ELSE %]
69
          There are no collections currently defined.
70
        [% END %]
71
      </div>    
72
118
73
      <div>
119
      <div id="create-edit-collection">
74
        <br />
120
        <br />
75
121
76
        [% IF ( previousActionEdit ) %]
122
        [% IF ( previousActionEdit ) %]
Lines 120-132 Link Here
120
          </table>
166
          </table>
121
        </form>
167
        </form>
122
      </div>
168
      </div>
169
      <br />
170
171
        [% IF ( collectionsLoop ) %]
172
          <table id="table-collections">
173
           <thead>
174
            <tr>
175
              <th>Title</th>
176
              <th>Description</th>
177
              <th>Transferred to</th>
178
              <th class="nosort">Edit</th>
179
              <th class="nosort">Delete</th>
180
            </tr>
181
           <thead>
182
           <tbody>
183
            [% FOREACH collectionsLoo IN collectionsLoop %]
184
              <tr>
185
                <td>[% collectionsLoo.colTitle %]</td>
186
                <td>[% collectionsLoo.colDesc %]</td>
187
                <td>[% IF collectionsLoo.branchname %][% collectionsLoo.branchname %][% ELSE %]Not yet transferred[% END %]</td>
188
                <td><a class="btn btn-small" href="editCollections.pl?action=edit&amp;colId=[% collectionsLoo.colId %]"><i class="icon-edit"></i> Edit</a></td>
189
                <td><a class="btn btn-small" id="remove-col-[% collectionsLoo.colId %]" data-toggle="modal" href="#removeColModal" data-coltitle="[% collectionsLoo.colTitle %]" data-colid="[% collectionsLoo.colId %]" data-coldesc="[% collectionsLoo.colDesc %]"><i class="icon-remove"></i> Delete</a></td>
190
              </tr>
191
            [% END %]
192
           </tbody>
193
          </table>
194
        [% ELSE %]
195
          There are no collections currently defined.
196
        [% END %]
197
      </div>
123
198
124
      <div>
199
      <div>
125
        <br/>
200
        <br/>
126
        <input type="button" value="Return to rotating collections home" onclick="window.location.href='rotatingCollections.pl'">
201
        <a href="rotatingCollections.pl" class="btn btn-small"><i class="icon-home"></i> Return to rotating collections home</a>
127
      </div>
202
      </div>
128
203
129
</div>
204
</div>
130
</div>
205
</div>
206
<!-- Modal for confirm deletion box-->
207
<div class="modal hide" id="removeColModal" tabindex="-1" role="dialog" aria-labelledby="removeColModalLabel" aria-hidden="true">
208
    <div class="modal-header">
209
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
210
        <h3 id="removeColModalHeader">Confirm collection removal</h3>
211
    </div>
212
    <div class="modal-body">
213
       <strong><p id="modal-remove-body-message"></p></strong>
214
       <p id="modal-remove-body-desc"></p>
215
    </div>
216
    <div class="modal-footer">
217
        <button type="button" class="btn btn-primary" id="btn-remove-cancel" data-dismiss="modal">Cancel</button>
218
        <button type="submit" class="btn btn-default" id="btn-remove-confirm" data-colId="" data-dismiss="modal">Remove collection</button>
219
    </div>
220
</div>
221
<div class="loading hide"><strong>Processing...</strong><img src="/intranet-tmpl/prog/img/loading.gif" /></div>
131
[% INCLUDE 'intranet-bottom.inc' %]
222
[% INCLUDE 'intranet-bottom.inc' %]
132
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt (-18 / +349 lines)
Lines 1-35 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Rotating collections</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'datatables.inc' %]
5
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6
<script type="text/javascript">
7
  //<![CDATA[
8
      $(document).ready(function() {
9
10
        var collectionsTable = $("#table-collections").dataTable($.extend(true, {}, dataTablesDefaults, {
11
          'bAutoWidth': true,
12
          'bPaginate': true,
13
          'bFilter': true,
14
          'bInfo': true,
15
          "aoColumnDefs": [
16
            { 'bSortable': false, 'aTargets': [ 'nosort' ] }
17
          ]
18
        }));
19
20
        // KD-139: Handle collection removal clicks
21
        $("body").on("click", "a[id^=remove-col]", function() {
22
          var selectedCollectionId = this.getAttribute('data-colid');
23
          var selectedCollectionTitle = this.getAttribute('data-coltitle');
24
          var selectedCollectionDesc = this.getAttribute('data-coldesc');
25
          if (selectedCollectionId && selectedCollectionTitle) {
26
            $("#btn-remove-confirm").attr("data-colid", selectedCollectionId);
27
            $("#modal-remove-body-message").text("Please confirm the removal of collection: " + selectedCollectionTitle);
28
            $("#modal-remove-body-desc").text("Description: " + selectedCollectionDesc);
29
          }
30
        });
31
32
        // KD-139: Handle collection transfer clicks
33
        $("body").on("click", "a[id^=transfer-col]", function() {
34
          var selectedCollectionId = this.getAttribute('data-colid');
35
          var selectedCollectionTitle = this.getAttribute('data-coltitle');
36
          var selectedCollectionTransferText = $("select[id=transfer-branch-" + selectedCollectionId + "] option:selected").text();
37
          var selectedCollectionTransferTo = $("select[id=transfer-branch-" + selectedCollectionId + "]").val();
38
          if (selectedCollectionId && selectedCollectionTitle && selectedCollectionTransferTo) {
39
            $("#btn-transfer-confirm").attr("data-colid", selectedCollectionId);
40
            $("#btn-transfer-confirm").attr("data-transferto", selectedCollectionTransferTo);
41
            $("#modal-transfer-body-message").text("Please confirm the transfer of collection \'"
42
                                                    + selectedCollectionTitle + "\' to "
43
                                                    + selectedCollectionTransferText);
44
          }
45
        });
46
47
        // KD-139: Handle collection edit clicks
48
        $("body").on("click", "a[id^=edit-col]", function() {
49
          var selectedCollectionId = this.getAttribute('data-colid');
50
          var selectedCollectionTitle = this.getAttribute('data-coltitle');
51
          var selectedCollectionDesc = this.getAttribute('data-coldesc');
52
          if (selectedCollectionId && selectedCollectionTitle) {
53
            $("#btn-edit-confirm").attr("data-colid", selectedCollectionId);
54
            $("#modal-edit-desc").val(selectedCollectionDesc);
55
            $("#modal-edit-title").val(selectedCollectionTitle);
56
          }
57
        });
58
59
        $("#btn-transfer-confirm").click(function() {
60
          var colToTransfer = this.getAttribute('data-colid');
61
          var colToTransferTo = this.getAttribute('data-transferto');
62
          if (colToTransfer && colToTransferTo) {
63
            transferCollection(colToTransfer, colToTransferTo);
64
          }
65
        });
66
67
        $("#btn-remove-confirm").click(function() {
68
          var colToRemove = this.getAttribute('data-colid');
69
          if (colToRemove) {
70
            removeCollection(colToRemove);
71
          }
72
        });
73
74
        $("#btn-edit-confirm").click(function() {
75
          var colToEdit = this.getAttribute('data-colid');
76
          var colTitle = $("#modal-edit-title").val();
77
          var colDesc = $("#modal-edit-desc").val();
78
          if (colToEdit && colTitle) {
79
            editCollection(colToEdit, colTitle, colDesc);
80
          }
81
        });
82
83
        $("#btn-new-confirm").click(function() {
84
          var colTitle = $("#modal-new-title").val();
85
          var colDesc = $("#modal-new-desc").val();
86
          if (colTitle) {
87
            newCollection(colTitle, colDesc);
88
          }
89
        });
90
91
        $(document).ajaxStart(function (event) {
92
            $("#alert-block").hide();
93
            $("#alert-block").after($(".loading").show());
94
        });
95
        $(document).ajaxStop(function () {
96
            $(".loading").hide();
97
            $("#alert-block").show();
98
        });
99
100
      });
101
102
      // KD-139: Removes a collection using a standard ajax-call
103
      function removeCollection(selectedCollectionId) {
104
        $.get("editCollections.pl?action=delete&colId=" + selectedCollectionId, function(response) {
105
          var resultMsg = $(response).find("#alert-block");
106
          var rowToRemove = $("button[id=remove-col-" + selectedCollectionId + "]").closest('tr');
107
          $("#alert-block").html(resultMsg);
108
          if ($("#alert-block").find('.alert-success')) {
109
            reloadDataTable();
110
          }
111
          var tableRows = $("#table-collections tr").length;
112
          if (tableRows < 3) {
113
            window.location.reload();
114
          }
115
        });
116
      }
117
118
      // KD-139: Performs a transfer on a collection using a standard ajax-call
119
      function transferCollection(selectedCollectionId, selectedCollectionTransferTo) {
120
        $.post("transferCollection.pl",
121
          {
122
            colId: selectedCollectionId,
123
            toBranch: selectedCollectionTransferTo,
124
            transferAction: "collectionTransfer"
125
          })
126
          .done(function(response) {
127
            var resultMsg = $(response).find("#alert-block");
128
            $("#alert-block").html(resultMsg);
129
            if ($("#alert-block").find('.alert-success')) {
130
              reloadDataTable();
131
            }
132
        });
133
      }
134
135
      // KD-139: Edits the given item via an ajax-call
136
      function editCollection(colId, colTitle, colDesc) {
137
        $.post("editCollections.pl?action=edit&colId=" + colId,
138
          {
139
            colId: colId,
140
            title: colTitle,
141
            description: colDesc,
142
            action: 'update'
143
          })
144
          .done(function(response) {
145
            var resultMsg = $(response).find("#alert-block");
146
            $("#alert-block").html(resultMsg);
147
            if ($("#alert-block").find('.alert-success')) {
148
              reloadDataTable();
149
            }
150
        });
151
      }
152
153
      function newCollection(colTitle, colDesc) {
154
        $.post("editCollections.pl",
155
          {
156
            title: colTitle,
157
            description: colDesc,
158
            action: 'create'
159
          })
160
          .done(function(response) {
161
            var resultMsg = $(response).find("#alert-block");
162
            $("#alert-block").html(resultMsg);
163
            if ($("#alert-block").find('.alert-success')) {
164
              $("input[id^=modal-new]").val("");
165
              reloadDataTable();
166
            }
167
        });
168
      }
169
170
      function reloadDataTable() {
171
        $.get("rotatingCollections.pl", function(response) {
172
          var newCollectionsTable = $(response).find("#table-collections").parent().html();
173
          var oldCollectionsTable = $("#table-collections").parent();
174
          if (oldCollectionsTable.html()) {
175
            oldCollectionsTable.replaceWith(newCollectionsTable);
176
          }
177
          else {
178
            $("#title-main").next().remove();
179
            $("#title-main").after(newCollectionsTable);
180
          }
181
          $("#table-collections").dataTable($.extend(true, {}, dataTablesDefaults, {
182
            'bAutoWidth': true,
183
            'bPaginate': true,
184
            'bFilter': true,
185
            'bInfo': true,
186
            "aoColumnDefs": [
187
              { 'bSortable': false, 'aTargets': [ 'nosort' ] }
188
            ]
189
          }));
190
        });
191
      }
192
193
  //]]>
194
</script>
4
</head>
195
</head>
5
<body id="rcoll_rotatingCollections" class="tools rcoll">
196
<body id="rcoll_rotatingCollections" class="tools rcoll">
6
[% INCLUDE 'header.inc' %]
197
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'cat-search.inc' %]
198
[% INCLUDE 'cat-search.inc' %]
8
199
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Rotating collections</div>
200
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Rotating collections</div>
10
201
<br />
202
<div id="alert-block">
203
</div>
11
<div id="doc3">
204
<div id="doc3">
12
<div id="bd">
205
<div id="bd">
13
        <div class="yui-gb">
206
        <div class="yui-gb">
14
207
15
      <h1>Rotating collections</h1>
208
      <h1 id="title-main">Rotating collections</h1>
16
      <div>
209
      <div>
17
        [% IF ( collectionsLoop ) %]
210
        [% IF ( collectionsLoop ) %]
18
          <table>
211
          <table id="table-collections">
19
            <tr>
212
            <thead>
20
              <th><strong>Title</strong></th>
213
              <tr>
21
              <th>Description</strong></th>
214
                <th><strong>Title</strong></th>
22
              <th>Current location</th>
215
                <th>Description</strong></th>
23
              <th>Add/Remove items</th>
216
                <th>Owner</th>
24
              <th>Transfer collection</th>
217
                <th>Items</th>
25
            </tr>
218
                <th>Transferred</th>
219
<!--                <th class="nosort">Manage collection</th>-->
220
                <th class="nosort">Transfer collection</th>
221
                <th class="nosort">Edit</th>
222
                <th class="nosort">Delete</th>
223
              </tr>
224
            </thead>
26
            [% FOREACH collectionsLoo IN collectionsLoop %]
225
            [% FOREACH collectionsLoo IN collectionsLoop %]
27
              <tr>
226
              <tr>
28
                <td>[% collectionsLoo.colTitle %]</td>
227
                <td><a href="addItems.pl?colId=[% collectionsLoo.colId %]">[% collectionsLoo.colTitle %]</a></td>
29
                <td>[% collectionsLoo.colDesc %]</td>
228
                <td>[% collectionsLoo.colDesc %]</a></td>
30
                <td>[% collectionsLoo.colBranchcode %]</td>
229
                <td>[% collectionsLoo.branchname %]</td>
31
                <td><a href="addItems.pl?colId=[% collectionsLoo.colId %]">Add/Remove Items</a></td>
230
                <td>[% collectionsLoo.colItemsCount %]</td>
32
                <td><a href="transferCollection.pl?colId=[% collectionsLoo.colId %]">Transfer Collection</a></td>
231
                <td>[% IF collectionsLoo.itemsTransferred > 0 %]
232
                      [% IF collectionsLoo.itemsTransferred == collectionsLoo.colItemsCount %]
233
                        All items transferred
234
                      [% ELSE %]
235
                        [% collectionsLoo.itemsTransferred %] items transferred
236
                      [% END %]
237
                    [% ELSE  %]
238
                      None transferred yet
239
                    [% END %]
240
                </td>
241
<!--                <td><a href="addItems.pl?colId=[% collectionsLoo.colId %]">Manage collection</a></td>-->
242
                <td><a class="btn btn-small" id="transfer-col-[% collectionsLoo.colId %]" data-toggle="modal" href="#transferColModal" class="btn btn-small" data-colid="[% collectionsLoo.colId %]" data-coltitle="[% collectionsLoo.colTitle %]" data-coldesc="[% collectionsLoo.colDesc %]"><i class="icon-gift"></i> Transfer collection</a>
243
                <select name="transfer-branch-[% collectionsLoo.colId %]" id="transfer-branch-[% collectionsLoo.colId %]">
244
                    [% FOREACH branch IN branchesLoop %]
245
                      [% IF ( branch.selected ) %]
246
                        <option value="[% branch.value %]" selected="selected">[% branch.branchname %]</option>
247
                      [% ELSE %]
248
                        <option value="[% branch.value %]">[% branch.branchname %]</option>
249
                      [% END %]
250
                    [% END %]
251
                </select></td>
252
                <td><a class="btn btn-small" id="edit-col-[% collectionsLoo.colId %]" href="#editColModal" data-toggle="modal" data-coltitle="[% collectionsLoo.colTitle %]" data-colid="[% collectionsLoo.colId %]" data-coldesc="[% collectionsLoo.colDesc %]"><i class="icon-edit"></i> Edit</a></td>
253
                <td><a class="btn btn-small" id="remove-col-[% collectionsLoo.colId %]" href="#removeColModal" data-toggle="modal" data-coltitle="[% collectionsLoo.colTitle %]" data-colid="[% collectionsLoo.colId %]" data-coldesc="[% collectionsLoo.colDesc %]"><i class="icon-remove"></i> Delete</a></td>
254
              </tr>
33
              </tr>
255
              </tr>
34
            [% END %]
256
            [% END %]
35
          </table>
257
          </table>
Lines 39-47 Link Here
39
      </div>
261
      </div>
40
262
41
      <div>
263
      <div>
42
	<br/>
264
  <br/>
43
    <input type="button" value="Edit collections" onclick="window.location.href='editCollections.pl'">
265
    <a class="btn btn-small" id="table-col-add" href="#newColModal" data-toggle="modal"><i class="icon-plus"></i> New collection</a>
266
    <a class="btn btn-small" href="editCollections.pl"><i class="icon-edit"></i> Edit collections</a>
44
      </div>    
267
      </div>    
45
</div>
268
</div>
46
</div>
269
</div>
47
[% INCLUDE 'intranet-bottom.inc' %]
270
<!-- Modal for confirm deletion box-->
271
<div class="modal hide" id="removeColModal" tabindex="-1" role="dialog" aria-labelledby="removeColModalLabel" aria-hidden="true">
272
    <div class="modal-header">
273
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
274
        <h3 id="removeColModalHeader">Confirm collection removal</h3>
275
    </div>
276
    <div class="modal-body">
277
       <strong><p id="modal-remove-body-message"></p></strong>
278
       <p id="modal-remove-body-desc"></p>
279
       <p class="alert-info">
280
        <strong>Note:</strong> any currently transferred items in the removed collection will be returned to their respective origin branch
281
        via a branch transfer. Before deleting a collection, make sure that the collection is really no longer needed and that all items
282
        in it are good to go for a transfer back to their origin branch. If you're unsure about certain items in the collection, deal with
283
        those individually before deleting the collection.
284
       </p>
285
    </div>
286
    <div class="modal-footer">
287
        <button type="button" class="btn btn-primary" id="btn-remove-cancel" data-dismiss="modal">Cancel</button>
288
        <button type="submit" class="btn btn-default" id="btn-remove-confirm" data-colid="" data-dismiss="modal">Remove collection</button>
289
    </div>
290
</div>
291
<!-- Modal for confirm transfer box-->
292
<div class="modal hide" id="transferColModal" tabindex="-1" role="dialog" aria-labelledby="transferColModalLabel" aria-hidden="true">
293
    <div class="modal-header">
294
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
295
        <h3 id="transferColModalHeader">Confirm collection transfer</h3>
296
    </div>
297
    <div class="modal-body">
298
       <strong><p id="modal-transfer-body-message"></p></strong>
299
       <p id="modal-transfer-body-desc"></p>
300
       <p class="alert-info">
301
        <strong>Note:</strong> any items in the collection currently not transferred to a branch will be transferred to the selected
302
        destination branch via a branch transfer. This action transfers the whole collection to the same destination - if you need
303
        separate transfer destinations for individual items in the collection, open the collection and perform transfers on individual items.
304
       </p>
305
    </div>
306
    <div class="modal-footer">
307
        <button type="button" class="btn btn-primary" id="btn-transfer-cancel" data-dismiss="modal">Cancel</button>
308
        <button type="submit" class="btn btn-default" id="btn-transfer-confirm" data-colid="" data-transferto="" data-dismiss="modal">Transfer collection</button>
309
    </div>
310
</div>
311
<!-- Modal for edit collection box-->
312
<div class="modal hide" id="editColModal" tabindex="-1" role="dialog" aria-labelledby="editColModalLabel" aria-hidden="true">
313
    <div class="modal-header">
314
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
315
        <h3 id="editColModalHeader">Edit collection</h3>
316
    </div>
317
    <div class="modal-edit-body">
318
      <table id="modal-edit-table">
319
        <tbody>
320
          <tr>
321
            <td>
322
              <label for="title">Title: </label>
323
            </td>
324
            <td>
325
              <input id="modal-edit-title" type="text" value="" name="title">
326
            </td>
327
          </tr>
328
          <tr>
329
            <td>
330
              <label for="description">Description: </label>
331
            </td>
332
            <td>
333
              <input id="modal-edit-desc" type="text" value="" name="description" size="50">
334
            </td>
335
          </tr>
336
        </tbody>
337
      </table>
338
    </div>
339
    <div class="modal-footer">
340
        <button type="button" class="btn btn-primary" id="btn-edit-cancel" data-dismiss="modal">Cancel</button>
341
        <button type="submit" class="btn btn-default" id="btn-edit-confirm" data-colid="" data-dismiss="modal">Save</button>
342
    </div>
343
</div>
344
<!-- Modal for new collection box-->
345
<div class="modal hide" id="newColModal" tabindex="-1" role="dialog" aria-labelledby="newColModalLabel" aria-hidden="true">
346
    <div class="modal-header">
347
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
348
        <h3 id="newColModalHeader">New collection</h3>
349
    </div>
350
    <div class="modal-new-body">
351
      <table id="modal-new-table">
352
        <tbody>
353
          <tr>
354
            <td>
355
              <label for="title">Title: </label>
356
            </td>
357
            <td>
358
              <input id="modal-new-title" type="text" value="" name="title">
359
            </td>
360
          </tr>
361
          <tr>
362
            <td>
363
              <label for="description">Description: </label>
364
            </td>
365
            <td>
366
              <input id="modal-new-desc" type="text" value="" name="description" size="50">
367
            </td>
368
          </tr>
369
        </tbody>
370
      </table>
371
    </div>
372
    <div class="modal-footer">
373
        <button type="button" class="btn btn-primary" id="btn-new-cancel" data-dismiss="modal">Cancel</button>
374
        <button type="submit" class="btn btn-default" id="btn-new-confirm" data-colid="" data-dismiss="modal">Create</button>
375
    </div>
376
</div>
377
<div class="loading hide"><strong>Processing...</strong><img src="/intranet-tmpl/prog/img/loading.gif" /></div>
378
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt (-11 / +57 lines)
Lines 9-31 Link Here
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> &rsaquo; Transfer collection</div>
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> &rsaquo; Transfer collection</div>
10
<div id="doc3">
10
<div id="doc3">
11
<div id="bd">
11
<div id="bd">
12
        <div class="yui-gb">
12
  <div class="yui-gb">
13
      <h1>Rotating collections: Transfer collection</h1>
13
      <h1>Rotating collections: Transfer collection</h1>
14
    <br />
14
    <br />
15
      [% IF ( transferSuccess ) %]
15
    <div id="alert-block">
16
        <div>Collection transferred successfully</div>
16
      <!-- Success conditions -->
17
      [% END %]
17
      [% IF transferSuccess && previousAction == "collectionTransfer" %]
18
18
        <div class="alert-success">Collection transferred successfully</div>
19
      [% IF ( transferFailure ) %]
19
      [% ELSIF transferSuccess && previousAction == "itemTransfer" %]
20
        <div>Failed to transfer collection!</div>
20
        <div class="alert-success">Item transferred successfully</div>
21
        <div>Reason: <strong>[% errorMessage %]</strong></div>
21
      [% ELSIF transferSuccess && previousAction == "itemReturn" %]
22
        <div class="alert-success">Item returned successfully</div>
23
      [% ELSIF transferSuccess && previousAction == "collectionReturn" && problemItems %]
24
        <div class="alert-success">Some items returned succesfully, problematic items: <br />
25
          [% FOREACH item IN problemItems %]
26
            [% item %]<br />
27
          [% END %]
28
        </div>
29
      [% ELSIF transferSuccess && previousAction == "collectionReturn" && !problemItems %]
30
        <div class="alert-success">Collection returned succesfully</div>
31
      <!-- Cases where not all items were transferred succesfully -->
32
      [% ELSIF transferSuccess && previousAction == "collectionTransfer" && problemItems %]
33
        <div class="alert-success">Some items transferred succesfully, problematic items: <br />
34
          [% FOREACH item IN problemItems %]
35
            [% item %]<br />
36
          [% END %]
37
        </div>
38
      <!-- Failing conditions-->
39
      [% ELSIF transferFailure && previousAction == "collectionTransfer" %]
40
        <div class="alert-error">Failed to transfer any items in collection!</div>
41
        <div class="alert-error">Problems: <br />
42
          [% FOREACH item IN problemItems %]
43
            <strong>[% item %]</strong><br />
44
          [% END %]
45
        </div>
46
      [% ELSIF transferFailure && previousAction == "itemTransfer" %]
47
        <div class="alert-error">Failed to transfer item!</div>
48
        <div class="alert-error">Problems: <br />
49
          [% FOREACH error IN errorMessage %]
50
            <strong>[% error %]</strong><br />
51
          [% END %]
52
        </div>
53
      [% ELSIF transferFailure && previousAction == "itemReturn" %]
54
        <div class="alert-error">Failed to return item!</div>
55
        <div class="alert-error">Problems: <br />
56
          [% FOREACH error IN errorMessage %]
57
            <strong>[% error %]</strong><br />
58
          [% END %]
59
        </div>
60
      [% ELSIF transferFailure && previousAction == "collectionReturn" %]
61
        <div class="alert-error">Failed to return any item in collection!</div>
62
        <div class="alert-error">Problematic items: <br />
63
          [% FOREACH item IN errorMessages %]
64
            <strong>[% item %]</strong><br />
65
          [% END %]
66
        </div>
22
      [% END %]
67
      [% END %]
23
68
    </div>
24
      [% IF ( transferSuccess ) %]
69
      [% IF ( transferSuccess ) %]
25
      [% ELSE %]
70
      [% ELSE %]
26
        <div>
71
        <div>
27
          <form action="transferCollection.pl" method="post">
72
          <form action="transferCollection.pl" method="post">
28
            <input type="hidden" name="colId" value="[% colId %]">
73
            <input type="hidden" name="colId" value="[% colId %]">
74
            <input type="hidden" name="transferAction" value="collectionTransfer">
29
  
75
  
30
            <label for="toBranch">Choose your library:</label>
76
            <label for="toBranch">Choose your library:</label>
31
            <select name="toBranch">
77
            <select name="toBranch">
Lines 40-48 Link Here
40
86
41
      <div>
87
      <div>
42
        <br/>
88
        <br/>
43
        <input type="button" value="Return to rotating collections home" onclick="window.location.href='rotatingCollections.pl'">
89
        <a href="rotatingCollections.pl" class="btn btn-small"><i class="icon-home"></i> Return to rotating collections home</a>
44
      </div>
90
      </div>
45
91
</div>
46
</div>
92
</div>
47
</div>
93
</div>
48
[% INCLUDE 'intranet-bottom.inc' %]
94
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/rotating_collections/addItems.pl (-5 / +12 lines)
Lines 23-36 use C4::Auth; Link Here
23
use C4::Context;
23
use C4::Context;
24
use C4::RotatingCollections;
24
use C4::RotatingCollections;
25
use C4::Items;
25
use C4::Items;
26
use C4::Branch;
26
27
27
use CGI;
28
use CGI;
28
29
29
my $query = new CGI;
30
my $query = new CGI;
30
31
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32
    {
32
    {
33
        template_name   => "rotating_collections/addItems.tmpl",
33
        template_name   => "rotating_collections/addItems.tt",
34
        query           => $query,
34
        query           => $query,
35
        type            => "intranet",
35
        type            => "intranet",
36
        authnotrequired => 0,
36
        authnotrequired => 0,
Lines 77-87 if ( $query->param('action') eq 'addItem' ) { Link Here
77
        );
77
        );
78
78
79
        if ($success) {
79
        if ($success) {
80
            $template->param( removeSuccess => 1 );
80
            $template->param(removeSuccess => 1);
81
            # Item's transfer can fail even if the removal itself was succesful
82
            $template->param(messages => $errorMessage) if ($errorMessage);
81
        }
83
        }
82
        else {
84
        else {
83
            $template->param( removeFailure  => 1 );
85
            $template->param(removeFailure  => 1);
84
            $template->param( failureMessage => $errorMessage );
86
            $template->param(failureMessage => $errorMessage);
85
        }
87
        }
86
88
87
    }
89
    }
Lines 90-99 if ( $query->param('action') eq 'addItem' ) { Link Here
90
my ( $colId, $colTitle, $colDescription, $colBranchcode ) =
92
my ( $colId, $colTitle, $colDescription, $colBranchcode ) =
91
  GetCollection( $query->param('colId') );
93
  GetCollection( $query->param('colId') );
92
my $collectionItems = GetItemsInCollection($colId);
94
my $collectionItems = GetItemsInCollection($colId);
95
93
if ($collectionItems) {
96
if ($collectionItems) {
97
94
    $template->param( collectionItemsLoop => $collectionItems );
98
    $template->param( collectionItemsLoop => $collectionItems );
95
}
99
}
96
100
101
my $branchesLoop = GetBranchesLoop();
102
97
$template->param(
103
$template->param(
98
    intranetcolorstylesheet =>
104
    intranetcolorstylesheet =>
99
      C4::Context->preference("intranetcolorstylesheet"),
105
      C4::Context->preference("intranetcolorstylesheet"),
Lines 104-109 $template->param( Link Here
104
    colTitle       => $colTitle,
110
    colTitle       => $colTitle,
105
    colDescription => $colDescription,
111
    colDescription => $colDescription,
106
    colBranchcode  => $colBranchcode,
112
    colBranchcode  => $colBranchcode,
113
    branchesLoop   => $branchesLoop
107
);
114
);
108
115
109
output_html_with_http_headers $query, $cookie, $template->output;
116
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/rotating_collections/editCollections.pl (-3 / +4 lines)
Lines 27-36 use C4::Context; Link Here
27
use C4::RotatingCollections;
27
use C4::RotatingCollections;
28
28
29
my $query = new CGI;
29
my $query = new CGI;
30
31
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32
    {
31
    {
33
        template_name   => "rotating_collections/editCollections.tmpl",
32
        template_name   => "rotating_collections/editCollections.tt",
34
        query           => $query,
33
        query           => $query,
35
        type            => "intranet",
34
        type            => "intranet",
36
        authnotrequired => 0,
35
        authnotrequired => 0,
Lines 43-51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
43
if ( $query->param('action') eq 'create' ) {
42
if ( $query->param('action') eq 'create' ) {
44
    my $title       = $query->param('title');
43
    my $title       = $query->param('title');
45
    my $description = $query->param('description');
44
    my $description = $query->param('description');
45
    my $userenv = C4::Context->userenv;
46
    my $owningbranch = $userenv->{'branch'};
46
47
47
    my ( $createdSuccessfully, $errorCode, $errorMessage ) =
48
    my ( $createdSuccessfully, $errorCode, $errorMessage ) =
48
      CreateCollection( $title, $description );
49
      CreateCollection( $title, $description, $owningbranch );
49
50
50
    $template->param(
51
    $template->param(
51
        previousActionCreate => 1,
52
        previousActionCreate => 1,
(-)a/rotating_collections/rotatingCollections.pl (-2 / +4 lines)
Lines 23-35 use CGI; Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Context;
25
use C4::Context;
26
use C4::Branch;
26
use C4::RotatingCollections;
27
use C4::RotatingCollections;
27
28
28
my $query = new CGI;
29
my $query = new CGI;
29
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
    {
31
    {
32
        template_name   => "rotating_collections/rotatingCollections.tmpl",
32
        template_name   => "rotating_collections/rotatingCollections.tt",
33
        query           => $query,
33
        query           => $query,
34
        type            => "intranet",
34
        type            => "intranet",
35
        authnotrequired => 0,
35
        authnotrequired => 0,
Lines 39-44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
39
);
39
);
40
40
41
my $branchcode = $query->cookie('branch');
41
my $branchcode = $query->cookie('branch');
42
my $branchesLoop = GetBranchesLoop();
42
43
43
my $collections = GetCollections();
44
my $collections = GetCollections();
44
45
Lines 49-54 $template->param( Link Here
49
    IntranetNav        => C4::Context->preference("IntranetNav"),
50
    IntranetNav        => C4::Context->preference("IntranetNav"),
50
51
51
    collectionsLoop => $collections,
52
    collectionsLoop => $collections,
53
    branchesLoop => $branchesLoop
52
);
54
);
53
55
54
output_html_with_http_headers $query, $cookie, $template->output;
56
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/rotating_collections/transferCollection.pl (-16 / +93 lines)
Lines 28-39 use CGI; Link Here
28
28
29
my $query = new CGI;
29
my $query = new CGI;
30
30
31
my $colId    = $query->param('colId');
31
my $colId = $query->param('colId');
32
my $itemNumber = $query->param('itemNumber');
32
my $toBranch = $query->param('toBranch');
33
my $toBranch = $query->param('toBranch');
34
my $transferAction = $query->param('transferAction');
33
35
34
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35
    {
37
    {
36
        template_name   => "rotating_collections/transferCollection.tmpl",
38
        template_name   => "rotating_collections/transferCollection.tt",
37
        query           => $query,
39
        query           => $query,
38
        type            => "intranet",
40
        type            => "intranet",
39
        authnotrequired => 0,
41
        authnotrequired => 0,
Lines 43-69 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
43
);
45
);
44
46
45
## Transfer collection
47
## Transfer collection
46
my ( $success, $errorCode, $errorMessage );
48
if ($transferAction eq 'collectionTransfer') {
47
if ($toBranch) {
49
    my ($success, $errorCode, $problemItems);
48
    ( $success, $errorCode, $errorMessage ) =
50
    if ($toBranch) {
49
      TransferCollection( $colId, $toBranch );
51
        ($success, $errorCode, $problemItems) =
52
          TransferCollection($colId, $toBranch);
50
53
51
    if ($success) {
54
        if ($success) {
52
        $template->param( transferSuccess => 1 );
55
            $template->param(
56
                transferSuccess => 1,
57
                previousAction  => 'collectionTransfer'
58
            );
59
        }
60
        else {
61
            $template->param(
62
                transferFailure => 1,
63
                errorCode       => $errorCode,
64
                problemItems   => $problemItems,
65
                previousAction  => 'collectionTransfer'
66
            );
67
        }
53
    }
68
    }
54
    else {
69
}
55
        $template->param(
70
56
            transferFailure => 1,
71
## Transfer an item
57
            errorCode       => $errorCode,
72
if ($transferAction eq 'itemTransfer') {
58
            errorMessage    => $errorMessage
73
    my ($success, $errorCode, $errorMessage);
59
        );
74
    if ($toBranch && $itemNumber) {
75
        ($success, $errorCode, $errorMessage) =
76
            TransferCollectionItem($colId, $itemNumber, $toBranch);
77
        if ($success) {
78
            $template->param(
79
                transferSuccess => 1,
80
                previousAction  => 'itemTransfer'
81
            );
82
        }
83
        else {
84
            $template->param(
85
                transferFailure => 1,
86
                errorCode       => $errorCode,
87
                errorMessage    => $errorMessage,
88
                previousAction  => 'itemTransfer'
89
            );
90
        }
91
    }
92
}
93
94
## Return an item
95
if ($transferAction eq 'itemReturn') {
96
    my ($success, $errorCode, $errorMessage);
97
    if ($colId && $itemNumber) {
98
        ($success, $errorCode, $errorMessage) =
99
            ReturnCollectionItemToOrigin($colId, $itemNumber);
100
        if ($success) {
101
            $template->param(
102
                transferSuccess => 1,
103
                previousAction  => 'itemReturn'
104
            );
105
        }
106
        else {
107
            $template->param(
108
                transferFailure => 1,
109
                errorCode       => $errorCode,
110
                errorMessage    => $errorMessage,
111
                previousAction  => 'itemReturn'
112
            );
113
        }
114
    }
115
}
116
117
## Return a collection
118
if ($transferAction eq 'collectionReturn') {
119
    my ($success, $errorCode, $errorMessages);
120
    if ($colId) {
121
        ($success, $errorCode, $errorMessages) =
122
            ReturnCollectionToOrigin($colId);
123
        if ($success) {
124
            $template->param(
125
                transferSuccess => 1,
126
                problemItems    => $errorMessages,
127
                previousAction  => 'collectionReturn'
128
            );
129
        }
130
        else {
131
            $template->param(
132
                transferFailure => 1,
133
                errorCode       => $errorCode,
134
                errorMessages    => $errorMessages,
135
                previousAction  => 'collectionReturn'
136
            );
137
        }
60
    }
138
    }
61
}
139
}
62
140
63
## Set up the toBranch select options
141
## Set up the toBranch select options
64
my $branches = GetBranches();
142
my $branches = GetBranches();
65
my @branchoptionloop;
143
my @branchoptionloop;
66
foreach my $br ( keys %$branches ) {
144
foreach my $br ( sort(keys %$branches) ) {
67
    my %branch;
145
    my %branch;
68
    $branch{code} = $br;
146
    $branch{code} = $br;
69
    $branch{name} = $branches->{$br}->{'branchname'};
147
    $branch{name} = $branches->{$br}->{'branchname'};
70
- 

Return to bug 8836