It looks like you're offline.
Open Library logo
additional options menu

Borrow a Book

This doc was last edited by George February 22, 2011.

plugin upstream
Templates in the website are disabled now. Editing them will not have any effect on the live website.
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
$def with (page, loans, has_returned_recently)

$var title: $page.title

$ _x = ctx.setdefault('bodyid', 'plain')

$ available_loans = page.get_available_loans()
$ user_can_borrow_this = False
$ meta_fields = page.get_ia_meta_fields()
$if meta_fields.has_key('collection'):
    $ collection = meta_fields['collection']
$else:
    $ collection = None
$if meta_fields.has_key('contributor'):
    $ contrib = meta_fields['contributor']
$else:
    $ contrib = None

$ show_returned_message = False
$if has_returned_recently and not page.key in [loan['book'] for loan in loans]:
    $ show_returned_message = True

<div id="contentBody">

    <div class="navBorrow">
        <a href="http://openlibrary.org/" title="Return to home page"><img src="/images/logo_OL-sm.png" width="90" height="71" alt="Open Library logo" class="right"/></a>
        <a href="$page.url()"><strong>Back</strong></a>
    </div>

        <h1 class="sansserif">Borrow</h1>
        
        <div class="borrow">
            <table>
                <tbody>
                    <tr>
                        <td valign="top" style="padding-right:10px;">
                            $:render_template('covers/book_cover_small', page)
                        </td>
                        <td>
                            <span class="book">
                                <a class="borrowResults" href="$page.key">
                                <strong>$page.title</strong>
                                </a>
                            </span>
                            <span class="author">
                            $ authors = page.works[0].get_authors()
                            $:macros.AuthorList(authors)
                            </span>
                            <br/>
                            <span class="publisher">
                            $if page.publish_date or page.publishers:
                                $if page.publish_date:
                                    $page.publish_date,
                                $else:
                                    <em>Published date unknown,</em> 
                                $if page.publishers:
                                    $for p in page.publishers:
                                        $p$cond(loop.last, "", ", ")
                                $else:
                                    <em>publisher unknown</em>
                            </span>
                            $if contrib:
                                <span class="contributor small grey">
                                    from $contrib
                                </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

        $if page.key in [loan['book'] for loan in loans]:
            $# checked out by this user!
            
            $# find the loan
            $for candidate in loans:
                $if candidate['book'] == page.key:
                    $ active_loan = candidate
            
            $if can_return_resource_type(active_loan['resource_type']):
               <div class="message info">
                    <h2 class="sansserif">You have this book checked out. You can read it online or return the book.
                    <p>
                    $:macros.LoanReadForm(active_loan['book'])
                    $:macros.ReturnForm(active_loan)
                    </p>
                </div>
            $else:
                $# Currently this means ACS4
                $if active_loan['expiry'] is not None:
                    $# Has been fulfilled
                    <div class="message info">
                        <h2 class="sansserif">We show that you've borrowed this title.</h2>
                        <p>Open Adobe Digital Editions to read it or return to Open Library.</p>
                    </div>
                $else:
                    $# $$$ wording
                    <div class="message info">
                        <h2 class="sansserif">We show that you've borrowed this but haven't loaded it in Digital Editions yet.</h2>
                        <p>This loan is on hold for about 5 minutes. If you don't open it up within that time, someone else may borrow it. <a href="$active_loan['loan_link']"><strong>Download again</strong></a>?</p>
                       <p>Do you need to try <a href="http://www.adobe.com/products/digitaleditions/">downloading Adobe Digital Editions again</a>? The PDF or ePub loans will only open in that program.</p>
                    </div>

        $elif not can_borrow(page):
            $# Check for in-library
            $if 'In library' in page.works[0].get_subjects():
                $if available_loans:
                    <div class="message info">
                        $# george copy
                        $if show_returned_message:
                            <h2 class="sansserif">You've returned this book, but...</h2>
                            <p>It's part of the special "In Library" lending collection, which can only be accessed from within one of the <a href="/libraries">participating libraries</a>. (So, you'll need to go back into the library if you want to borrow it again.)
                            $ show_returned_message = False
                        $else:
                            <h2 class="sansserif">This book isn't available to borrow.</h2>
                            <p>Unless you find yourself literally sitting inside <a href="http://openlibrary.org/libraries">one of the libraries participating in the "In Library" lending program</a>. Look for something else in the <a href="/borrow">lending library</a>?</p>
                    </div>               
                $else:
                    <div class="message info">
                        <h2 class="sansserif">This title is checked out.</h2>
                        <p>It's special too, since it can only be borrowed from within a library that's participating in <a href="http://openlibrary.org/libraries">the "In Library" lending program</a>. Look for something else in the <a href="/borrow">lending library</a>?</p>
                    </div>               


            $else:
                $# not a borrowable book
                <div class="message info">
                    <h2 class="sansserif">This title is not available to borrow.</h2>
                    <p>Look for something else in the <a href="/borrow">lending library</a>?</p>
                </div>
            
        $elif not page.ocaid:
            $# overdrive-only - does not require login
            $# $$$ we could generate direct overdrive link since overdrive id is available
            <div class="message info">
                <h2 class="sansserif">An eBook may be available from your local library.</h2>
                <p><a href="this book link">Check overdrive.com</a> for availability.</p>
            </div>
            
        $elif not ctx.user:
            $# not logged in
            
            $if not available_loans:
                $# not logged in and book is checked-out
                <div class="message info">
                    <h2 class="sansserif">This title is checked out.</h2>
                    <p>But, you'll need to <a href="/account/login">log in</a> or <a href="/account/create">open a free account</a> to borrow eBooks from Open library.</p>
                </div>        

            $else:
                $# not logged in and book is available
                <div class="message alert">
                    <h2 class="sansserif">Only Open Library account holders can borrow this book.</h2>
                    <p>Log in below, or <a href="/account/create">open a new account</a>.</p>
                </div>
                <script type="text/javascript">
                \$().ready(validateForms);
                \$().ready(setup_account_create);
                \$().ready(function(){
                \$('#username').keyup(function(){
                     var value = \$(this).val();
                     \$('#userUrl').addClass('darkgreen').text(value).css('font-weight','700');
                    });
                });
                </script>
                <div class="panel">
                    <div class="head">
                        <h3>Log In</h3>
                    </div>
                    <form class="login olform" name="register" action="/account/login" method="post">
                    <div class="formElement">
                        <div class="label"><label for="username">$_("Username")</label> <span class="smaller lighter"></span></div>
                        <div class="input">
                            <input type="text" class="required" id="username" name="username" value=""/>
                        </div>
                    </div>
                    <div class="formElement">
                        <div class="label"><label for="password">$_("Password")</label> <span class="smaller lighter"></span></div>
                        <div class="input">
                            <input type="password" class="required"  id="password" name="password" value="" />
                        </div>
                    </div>
                    <div class="formElement">
                        <div class="input">
                            <input name="remember" type="checkbox" id="remember" />
                            <label for="remember" class="small">Remember me</label>
                        </div>
                    </div>
                    <input type="hidden" id="redirect" value="$page.url('/borrow')" name="redirect" />
                    <div class="clearfix"></div>
                    <div class="formElement bottom">
                        <br/>
                        <input value="$_('Log In')" type="submit" name="login" title="$_('Log In')"/>
                        &nbsp;
                        <a href="$page.key" class="smaller attn">$_("Cancel")</a>
                    </div>
                    <div class="formElement">
                        <div class="label"></div>
                        <div class="input smaller">$:_('Did you <a href="/account/password/forgot">forget your password</a>?')
                        <br/><br/>
                        $:_('Not a member of Open Library? <a href="/account/create">Sign up now</a>.')</div>
                    </div>
                    </form>            
                </div>

        $elif len(loans) >= 5:
            $# already loaned maximum number of books
            <div class="message stop">
                <h2 class="sansserif">Hang on. You've hit the lending limit of 5 concurrent titles.</h2>
                <p>You can free up space by returning one of <a href="/account/loans/" target="newWindow" title="Open link in a new browser window">your current loans</a> early.</p>
            </div>

        $elif not available_loans:
            $# book is not available for loan
            <div class="message info">
                <h2 class="sansserif">This book is checked out.</h2>
                <p>Please check back later, or browse <a href="/borrow">more books you can borrow</a>?</p>
            </div>
            $if ctx.user and ctx.user.is_admin():
                $# Stuff for adding to a list - NEED NEW WIDGET!
                <div class="Tools borrow" id="listsWork">
                    $:render_template("lists/widget", page, user_lists_only=True)
                    
                    <p id="borrowList" class="hidden">to keep an eye on it, or <a href="/subjects/lending_library">browse more titles</a>.</p>
                </div>
                <!-- 
                <p id="postBorrowList"><strong>OK!</strong> This title has been added to your <a href="LIST URL">LIST NAME</a> list.<br/>
                <a href="/borrow">Go back to browsing</a>?</p>
                -->
            
        $else:
            $# We can borrow it!
            $ user_can_borrow_this = True
            
        $if show_returned_message:
            $# May have returned this book and not currently borrowed
            <div class="message info">
                <h2 class="sansserif">You've returned this book.</h2>
                <p>Find something else to read in the <a href="/borrow">lending library</a>.</p>
            </div>
        
        $if user_can_borrow_this:
            <div class="borrow">
                <div class="postSubmit hidden center">
                    <p>Borrowing book...</p>
                    <img src="/images/ajax-loader-bar.gif" alt="Download in progress" width="220" height="19"/>
                </div>
                $:macros.LoanForm(page, available_loans)
            </div>        

        $if loans:
            $# user has outstanding loans
            <div class="clearfix"></div>
            <p class="help" style="margin-top:50px;border-top:1px dotted #615132;padding-top:10px;">You have $len(loans) of a possible 5 books out at the moment. Review <a href="/account/loans/" target="newWindow" title="Open link in a new browser window">your current loans</a>?<br/>
            <span class="smaller"><strong>Need help?</strong> Head for the <a href="/help/faq/borrow" target="newWindow" title="Open link in a new browser window">Borrowing FAQ</a>.</span></p>
        $else:
            <div class="clearfix"></div>
            <p class="help smaller" style="margin-top:50px;border-top:1px dotted #615132;padding-top:10px;"><strong>Need help?</strong> Head for the <a href="/help/faq/borrow" target="newWindow" title="Open link in a new browser window">Borrowing FAQ</a>.</p>

    $if ctx.user and ctx.user.is_admin():
        <div class="small sansserif clearfix"><br/><span class="adminOnly"><a href="borrow_admin">View loan debugging information</a></span></div>


</div>



<script type="text/javascript"> 
function update_borrow_message(){
    if (\$("#widget-lists").children().length > 0) {
        \$("#borrowList").hide();
    }
    else {
        \$("#borrowList").show();
    }
}    

\$(function(){
    \$('#widget-my-lists').children().insertBefore('#widget-my-lists').end().end().remove();
    \$('#widget-other-lists').children().insertBefore('#widget-other-lists').end().end().remove();
    if (\$('.dropit').length) {
        \$('#widget-add').addClass('contentQuarter').css('min-height','35px');
        \$('#listsWork .listLists').wrap('<div class="contentThreeQuarter" style="min-height:35px;">');
        \$('#listsWork').addClass('collapse');
    } else {
        \$('#listsWork').css('width','100%');
        \$('ul.listLists').css('width','100%')
    };
    
    update_borrow_message();
    \$(window).bind("ol.lists", update_borrow_message);
});
</script>