+
+
+
+
+
+
+
+
Index: openacs-4/packages/bookshelf/lib/master.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/lib/master.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/lib/master.tcl 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,15 @@
+# Expects "title" and "header" and "context_bar"
+
+if { ![info exists title] } {
+ set title ""
+}
+
+if { ![info exists header] } {
+ set header $title
+}
+
+if { ![info exists context_bar] } {
+ set header $context_bar
+}
+
+ad_return_template
Index: openacs-4/packages/bookshelf/lib/nav-bar.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/lib/nav-bar.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/lib/nav-bar.adp 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,13 @@
+
+
+
\ No newline at end of file
Index: openacs-4/packages/bookshelf/lib/nav-bar.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/lib/nav-bar.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/lib/nav-bar.tcl 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,27 @@
+# Nav bar, to be included on all pages
+
+set package_id [ad_conn package_id]
+set package_url [ad_conn package_url]
+
+if { ![ad_permission_p $package_id create] && ![ad_permission_p $package_id write] && ![ad_permission_p $package_id admin] } {
+ set show_navbar_p 0
+} else {
+ set show_navbar_p 1
+}
+
+multirow create links name url
+
+multirow append links "List" [ad_conn package_url]
+
+if { [ad_permission_p $package_id create] } {
+ multirow append links "New Book" "[ad_conn package_url]book-edit"
+}
+
+if { [ad_conn user_id] != 0 } {
+ multirow append links "My Books" "[ad_conn package_url]?[export_vars -url { { creation_user {[ad_conn user_id]} } }]"
+}
+if { [ad_permission_p $package_id admin] } {
+ multirow append links "Admin" "[ad_conn package_url]admin/"
+}
+
+ad_return_template
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-create.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,68 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+-- The tables for Bookshelf books
+--
+
+create table bookshelf_books (
+ book_id integer not null
+ constraint bookshelf_book_id_fk
+ references acs_objects (object_id)
+ on delete cascade
+ constraint bookshelf_book_pk
+ primary key,
+ book_no integer not null,
+ isbn varchar(500),
+ book_author text,
+ book_title text not null,
+ main_entry text,
+ additional_entry text,
+ excerpt text,
+ publish_status varchar(50) not null
+ constraint bookshelf_book_publish_ck
+ check (publish_status in ('draft', 'publish'))
+ default 'draft',
+ read_status varchar(50) not null
+ constraint bookshelf_book_read_ck
+ check (read_status in ('queue', 'hand', 'shelf'))
+ default 'queue',
+ image_width integer,
+ image_height integer,
+ package_id integer not null
+ constraint bookshelf_book_package_fk
+ references apm_packages (package_id)
+ on delete cascade,
+ constraint bookshelf_book_no_un
+ unique (package_id, book_no)
+);
+
+create view bookshelf_books_published
+as
+ select *
+ from bookshelf_books
+ where publish_status = 'publish';
+
+create function inline_0 ()
+returns integer as '
+begin
+ perform acs_object_type__create_type(
+ ''bookshelf_book'',
+ ''Bookshelf Book'',
+ ''Bookshelf Books'',
+ ''acs_object'',
+ ''bookshelf_books'',
+ ''book_id'',
+ ''bookshelf_book'',
+ ''f'',
+ null,
+ ''bookshelf_book__name''
+ );
+
+ return null;
+end;' language 'plpgsql';
+
+select inline_0();
+drop function inline_0 ();
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-drop.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-drop.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,24 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+-- Dropping the tables for Bookshelf books
+--
+
+drop view bookshelf_books_published;
+drop table bookshelf_books;
+
+create function inline_0 ()
+returns integer as '
+begin
+ perform acs_object_type__drop_type (
+ ''bookshelf_book'', ''f''
+ );
+
+ return null;
+end;' language 'plpgsql';
+
+select inline_0();
+drop function inline_0 ();
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-create.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,198 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+-- The Package for Bookshelf books
+--
+
+select define_function_args ('bookshelf_book__new', 'book_id,object_type;bookshelf_book,package_id,isbn,book_author,book_title,main_entry,additional_entry,excerpt,publish_status,read_status,creation_date,creation_user,creation_ip,context_id');
+
+create function bookshelf_book__new (
+ integer, -- book_id
+ varchar, -- object_type
+ integer, -- package_id
+ varchar, -- isbn
+ text, -- book_author
+ text, -- book_title
+ text, -- main_entry
+ text, -- additional_entry
+ text, -- excerpt
+ varchar, -- publish_status
+ varchar, -- read_status
+ date, -- creation_date
+ integer, -- creation_user
+ varchar, -- creation_ip
+ integer -- context_id
+)
+returns integer as '
+declare
+ p_book_id alias for $1;
+ p_object_type alias for $2;
+ p_package_id alias for $3;
+ p_isbn alias for $4;
+ p_book_title alias for $5;
+ p_book_author alias for $6;
+ p_main_entry alias for $7;
+ p_additional_entry alias for $8;
+ p_excerpt alias for $9;
+ p_publish_status alias for $10;
+ p_read_status alias for $11;
+ p_creation_date alias for $12;
+ p_creation_user alias for $13;
+ p_creation_ip alias for $14;
+ p_context_id alias for $15;
+ v_book_id integer;
+ v_book_no integer;
+ v_creation_date date;
+begin
+ if p_creation_date is null then
+ v_creation_date := now();
+ else
+ v_creation_date := p_creation_date;
+ end if;
+
+ v_book_id := acs_object__new(
+ p_book_id,
+ p_object_type,
+ v_creation_date,
+ p_creation_user,
+ p_creation_ip,
+ coalesce(p_context_id, p_package_id)
+ );
+
+ select coalesce(max(book_no),0) + 1
+ into v_book_no
+ from bookshelf_books
+ where package_id = p_package_id;
+
+ insert into bookshelf_books
+ (book_id, book_no, isbn, book_author, book_title, main_entry, additional_entry, excerpt,
+ publish_status, read_status, package_id)
+ values
+ (v_book_id, v_book_no, p_isbn, p_book_author, p_book_title, p_main_entry, p_additional_entry, p_excerpt,
+ p_publish_status, p_read_status, p_package_id);
+
+ return v_book_id;
+end;
+' language 'plpgsql';
+
+
+
+
+
+select define_function_args ('bookshelf_book__delete', 'message_id');
+
+create function bookshelf_book__delete (integer)
+returns integer as '
+declare
+ p_book_id alias for $1;
+begin
+ perform acs_object__delete(p_book_id);
+ return 0;
+end;
+' language 'plpgsql';
+
+
+
+
+
+select define_function_args('bookshelf_book__name','book_id');
+
+create function bookshelf_book__name (integer)
+returns varchar as '
+declare
+ p_book_id alias for $1;
+begin
+ return book_author || '': '' || book_title from bookshelf_books where book_id = p_book_id;
+end;
+' language 'plpgsql';
+
+
+
+
+create function bookshelf_book__read_status_sort_order(
+ varchar -- read_status
+) returns integer
+as '
+declare
+ p_read_status alias for $1;
+ v_sort_order integer;
+begin
+ v_sort_order := case p_read_status
+ when ''queue'' then 1
+ when ''hand'' then 2
+ when ''shelf'' then 3
+ else 4
+ end;
+
+ return v_sort_order;
+end;
+' language 'plpgsql';
+
+
+
+
+create function bookshelf_book__read_status_pretty(
+ varchar -- read_status
+) returns varchar
+as '
+declare
+ p_read_status alias for $1;
+ v_read_status_pretty varchar;
+begin
+ v_read_status_pretty := case p_read_status
+ when ''queue'' then ''in the queue''
+ when ''hand'' then ''in hand/reading''
+ when ''shelf'' then ''in mind/on shelf''
+ else ''''
+ end;
+
+ return v_read_status_pretty;
+end;
+' language 'plpgsql';
+
+
+
+create function bookshelf_book__pub_status_sort_order(
+ varchar -- publish_status
+) returns integer
+as '
+declare
+ p_publish_status alias for $1;
+ v_sort_order integer;
+begin
+ v_sort_order := case p_publish_status
+ when ''draft'' then 1
+ when ''publish'' then 2
+ else 4
+ end;
+
+ return v_sort_order;
+end;
+' language 'plpgsql';
+
+
+
+
+create function bookshelf_book__pub_status_pretty(
+ varchar -- publish_status
+) returns varchar
+as '
+declare
+ p_publish_status alias for $1;
+ v_publish_status_pretty varchar;
+begin
+ v_publish_status_pretty := case p_publish_status
+ when ''draft'' then ''draft''
+ when ''publish'' then ''published''
+ else ''''
+ end;
+
+ return v_publish_status_pretty;
+end;
+' language 'plpgsql';
+
+
+
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-drop.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-books-package-drop.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,38 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+-- Dropping the Package for Bookshelf books
+--
+
+drop function bookshelf_book__new(
+ integer, -- book_id
+ varchar, -- object_type
+ integer, -- package_id
+ varchar, -- isbn
+ text, -- book_title
+ text, -- book_author
+ text, -- main_entry
+ text, -- additional_entry
+ text, -- excerpt
+ varchar, -- publish_status
+ varchar, -- read_status
+ date, -- creation_date
+ integer, -- creation_user
+ varchar, -- creation_ip
+ integer -- context_id
+);
+
+drop function bookshelf_book__delete (integer);
+
+drop function bookshelf_book__name (integer);
+
+drop function bookshelf_book__read_status_sort_order (varchar);
+
+drop function bookshelf_book__read_status_pretty (varchar);
+
+drop function bookshelf_book__pub_status_sort_order(varchar);
+
+drop function bookshelf_book__pub_status_pretty(varchar);
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-create.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,10 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+
+-- The books
+\i bookshelf-books-create.sql
+\i bookshelf-books-package-create.sql
Index: openacs-4/packages/bookshelf/sql/postgresql/bookshelf-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/sql/postgresql/bookshelf-drop.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/sql/postgresql/bookshelf-drop.sql 30 Sep 2002 18:10:54 -0000 1.1
@@ -0,0 +1,10 @@
+--
+-- The Bookshelf Package
+--
+-- @author Lars Pind (lars@pinds.com)
+-- @creation-date 2002-09-08
+--
+
+-- The books
+\i bookshelf-books-package-drop.sql
+\i bookshelf-books-drop.sql
Index: openacs-4/packages/bookshelf/tcl/amazon-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/tcl/amazon-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/tcl/amazon-procs.tcl 30 Sep 2002 18:10:55 -0000 1.1
@@ -0,0 +1,105 @@
+ad_library {
+
+ Bookshelf Library - Amazon integration
+
+ @creation-date 2002-09-08
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: amazon-procs.tcl,v 1.1 2002/09/30 18:10:55 lars Exp $
+
+}
+
+namespace eval bookshelf::amazon {
+
+ ad_proc get_image_url {
+ isbn
+ } {
+ return "http://images.amazon.com/images/P/$isbn.01.MZZZZZZZ.gif"
+ }
+
+ ad_proc get_book_url {
+ {-associate_id "pindsdotcom"}
+ isbn
+ } {
+ set url "http://www.amazon.com/exec/obidos/ASIN/$isbn"
+ if { ![empty_string_p $associate_id] } {
+ append url "/ref=nosim/$associate_id"
+ }
+ return $url
+ }
+
+ ad_proc get_image_info {
+ -array:required
+ isbn
+ } {
+ Find title, author, along with image_width and image_height
+ for the cover thumbnail.
+ } {
+ # Select the info into the upvar'ed Tcl Array
+ upvar $array row
+
+ # Download image to temp file
+
+ set filename "[ns_mktemp "/tmp/gifXXXXXX"].gif"
+ set url [get_image_url $isbn]
+ set httpopen_result [ns_httpopen GET $url]
+
+ set readfd [lindex $httpopen_result 0]
+ set writefd [lindex $httpopen_result 1]
+ close $writefd
+
+ set tmpfilefd [open $filename w]
+
+ fcopy $readfd $tmpfilefd
+
+ close $tmpfilefd
+ close $readfd
+
+ # Figure out the size
+
+ # Hmm. it's actually a JPEG, though it's named GIF
+ if { [catch {
+ set gifsize [ns_jpegsize $filename]
+ }] } {
+ # Oops, and then sometimes it *is* a GIF ...
+ set gifsize [ns_gifsize $filename]
+ }
+
+ # Delete tmp file
+ file delete $filename
+
+
+ set row(image_width) [lindex $gifsize 0]
+ set row(image_height) [lindex $gifsize 1]
+ }
+
+ ad_proc get_book_info {
+ -array:required
+ isbn
+ } {
+ Find title and author from Amazon.
+ for the cover thumbnail.
+ } {
+ # Select the info into the upvar'ed Tcl Array
+ upvar $array row
+
+ # Grab book info page from Amazon
+
+ set url [get_book_url $isbn]
+
+ set amazon_info_page [ns_httpget $url]
+
+ if { ![regexp {\s*Amazon.com: buying info: ([^<]*)\s*} $amazon_info_page match title] } {
+ set row(book_title) "-"
+ } else {
+ set row(book_title) [string trim $title]
+ }
+
+
+ if { ![regexp {by ([^<]+)} $amazon_info_page match author] } {
+ set row(book_author) "-"
+ } else {
+ set row(book_author) [string trim $author]
+ }
+
+ }
+}
Index: openacs-4/packages/bookshelf/tcl/bookshelf-books-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/tcl/bookshelf-books-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/tcl/bookshelf-books-procs.tcl 30 Sep 2002 18:10:55 -0000 1.1
@@ -0,0 +1,193 @@
+ad_library {
+
+ Bookshelf Library - for Books
+
+ @creation-date 2002-09-08
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: bookshelf-books-procs.tcl,v 1.1 2002/09/30 18:10:55 lars Exp $
+
+}
+
+namespace eval bookshelf::book {
+
+ ad_proc -public new {
+ {-package_id ""}
+ {-book_id ""}
+ {-isbn ""}
+ {-book_author ""}
+ {-book_title:required}
+ {-main_entry ""}
+ {-additional_entry ""}
+ {-excerpt ""}
+ {-publish_status ""}
+ {-read_status ""}
+ {-user_id ""}
+ } {
+ Create a new book.
+ } {
+ # Default values
+ if { [empty_string_p $user_id] } {
+ set user_id [ad_conn user_id]
+ }
+ if { [empty_string_p $package_id] } {
+ set package_id [ad_conn package_id]
+ }
+
+ # Prepare the variables for instantiation
+ set extra_vars [ns_set create]
+ oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {package_id book_id isbn book_author book_title main_entry additional_entry excerpt publish_status read_status user_id}
+
+ set book_id [package_instantiate_object -extra_vars $extra_vars bookshelf_book]
+
+ return $book_id
+ }
+
+ ad_proc -public edit {
+ {-book_id}
+ {-book_no}
+ {-book_package_id}
+ {-isbn ""}
+ {-book_author ""}
+ {-book_title:required}
+ {-main_entry ""}
+ {-additional_entry ""}
+ {-excerpt ""}
+ {-publish_status ""}
+ {-read_status ""}
+ } {
+ Editing a book.
+ } {
+ if { [exists_and_not_null book_id] } {
+ db_dml update_book_by_id {
+ update bookshelf_books
+ set isbn = :isbn,
+ book_author = :book_author,
+ book_title = :book_title,
+ main_entry = :main_entry,
+ additional_entry = :additional_entry,
+ excerpt = :excerpt,
+ publish_status = :publish_status,
+ read_status = :read_status
+ where book_id = :book_id
+ }
+ } else {
+ if { ![exists_and_not_null book_no]} {
+ error "You must supply either book_id or book_no"
+ }
+ if { ![exists_and_not_null package_id] } {
+ set package_id [ad_conn package_id]
+ }
+ db_dml update_book_by_no {
+ update bookshelf_books
+ set isbn = :isbn,
+ book_author = :book_author,
+ book_title = :book_title,
+ main_entry = :main_entry,
+ additional_entry = :additional_entry,
+ excerpt = :excerpt,
+ publish_status = :publish_status,
+ read_status = :read_status
+ where book_no = :book_no
+ and package_id = :package_id
+ }
+ }
+
+ }
+
+ ad_proc -public publish {
+ {-book_id}
+ {-book_no}
+ {-package_id}
+ {-publish_status "publish"}
+ } {
+ Publishing a book.
+ } {
+ if { [exists_and_not_null book_id] } {
+ db_dml publish_book_by_id {
+ update bookshelf_books
+ set publish_status = :publish_status
+ where book_id = :book_id
+ }
+ } else {
+ if { ![exists_and_not_null book_no]} {
+ error "You must supply either book_id or book_no"
+ }
+ if { ![exists_and_not_null package_id] } {
+ set package_id [ad_conn package_id]
+ }
+ db_dml publish_book_by_no {
+ update bookshelf_books
+ set publish_status = :publish_status
+ where book_no = :book_no
+ and package_id = :package_id
+ }
+ }
+ }
+
+ ad_proc -public get {
+ {-book_id ""}
+ {-book_no ""}
+ {-package_id ""}
+ {-array:required}
+ } {
+ Get the fields for a book
+ } {
+ # Select the info into the upvar'ed Tcl Array
+ upvar $array row
+
+ if { [exists_and_not_null book_id] } {
+ db_1row select_book_by_id {
+ select b.book_id,
+ b.book_no,
+ b.isbn,
+ b.book_author,
+ b.book_title,
+ b.main_entry,
+ b.additional_entry,
+ b.excerpt,
+ b.publish_status,
+ b.read_status,
+ o.creation_user,
+ u.first_names as creation_user_first_names,
+ u.last_name as creation_user_last_name,
+ o.creation_date,
+ to_char(o.creation_date, 'fmMonth DDfm, YYYY') as creation_date_pretty
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where book_id = :book_id
+ } -column_array row
+ } else {
+ if { ![exists_and_not_null book_no]} {
+ error "You must supply either book_id or book_no"
+ }
+ if { ![exists_and_not_null package_id] } {
+ set package_id [ad_conn package_id]
+ }
+ db_1row select_book_by_no {
+ select b.book_id,
+ b.book_no,
+ b.isbn,
+ b.book_author,
+ b.book_title,
+ b.main_entry,
+ b.additional_entry,
+ b.excerpt,
+ b.publish_status,
+ b.read_status,
+ o.creation_user,
+ u.first_names as creation_user_first_names,
+ u.last_name as creation_user_last_name,
+ o.creation_date,
+ to_char(o.creation_date, 'fmMonth DDfm, YYYY') as creation_date_pretty
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where book_no = :book_no
+ and package_id = :package_id
+ } -column_array row
+ }
+ }
+
+
+}
Index: openacs-4/packages/bookshelf/www/book-chunk.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-chunk.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-chunk.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,33 @@
+
+
+
+ @book.book_title@
+ by @book.book_author@
+ |
+
+
+
+
+ |
+
+ @book.main_entry@
+
+
+ @book.additional_entry@
+
+
+
+
+
+ Posted by @book.creation_user_first_names@ @book.creation_user_last_name@ on @book.creation_date_pretty@
+ - Edit
+ - Publish
+ - Draft
+
+
+ # -
+ G
+
+ |
+
+
Index: openacs-4/packages/bookshelf/www/book-chunk.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-chunk.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-chunk.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,27 @@
+# Expects:
+# book:onerow
+
+set package_id [ad_conn package_id]
+set write_p [ad_permission_p $package_id write]
+
+set book(url) [bookshelf::amazon::get_book_url $book(isbn)]
+
+set book(image_url) [bookshelf::amazon::get_image_url $book(isbn)]
+
+bookshelf::amazon::get_image_info -array amazon_info $book(isbn)
+
+set book(image_width) $amazon_info(image_width)
+set book(image_height) $amazon_info(image_height)
+
+set perma_url "[ad_url][ad_conn package_url]book-view?[export_vars { book_no }]"
+set google_url "http://www.google.com/search?[export_vars { {q $book(book_title) } }]"
+
+if { $write_p } {
+ set edit_url "book-edit?[export_vars { book_no }]"
+ if { [string equal $book(publish_status) "draft"] } {
+ set publish_url "book-publish?[export_vars { {book_no $book(book_no)} }]"
+ } else {
+ set draft_url "book-publish?[export_vars { {book_no $book(book_no)} { publish_status "draft"} }]"
+ }
+}
+
Index: openacs-4/packages/bookshelf/www/book-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-edit.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-edit.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,20 @@
+
+@page_title@
+@context_bar@
+book.isbn
+
+
+
+
+
+
+
+
+
+
Index: openacs-4/packages/bookshelf/www/book-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-edit.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-edit.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,93 @@
+ad_page_contract {
+ Add or edit a book.
+
+ @creation-date 2002-09-08
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: book-edit.tcl,v 1.1 2002/09/30 18:10:56 lars Exp $
+} {
+ book_no:integer,optional
+} -properties {
+ page_title
+ context_bar
+ image_url
+ book_url
+}
+
+set package_id [ad_conn package_id]
+
+if { [info exists book_no] } {
+ db_1row book_id {
+ select book_id
+ from bookshelf_books
+ where book_no = :book_no
+ and package_id = :package_id
+ }
+ set page_title "Edit book"
+} else {
+ set page_title "Add book"
+ set image_url ""
+}
+
+set context_bar [ad_context_bar $page_title]
+
+ad_form -name book -form {
+ book_id:key(acs_object_id_seq)
+ {isbn:text {label "ISBN"} {after_html {(update info from Amazon.com)}}}
+ {__isbn_update_flag:integer(hidden) {value 0}}
+ {book_author:text {label "Author"} {html { size 50 }} optional }
+ {book_title:text {label "Title"} {html { size 50 }} }
+ {main_entry:text(textarea) {label "Main entry"} {html { rows 10 cols 60 }} optional }
+ {additional_entry:text(textarea) {label "Additional entry"} {html { rows 10 cols 60 }} optional }
+ {excerpt:text(textarea) {label "Excerpt"} {html { rows 5 cols 60 }} optional }
+ {publish_status:text(select) {label "Publish status"} {options { { "Draft" draft } { "Publish" publish } } } }
+ {read_status:text(select) {label "Read status"} {options { { "In the queue" queue } { "In hand" hand } { "On shelf" shelf } } } }
+} -edit_request {
+ bookshelf::book::get -book_id $book_id -array book
+ unset book(creation_date)
+ unset book(creation_date_pretty)
+ unset book(creation_user)
+ unset book(creation_user_first_names)
+ unset book(creation_user_last_name)
+ unset book(book_no)
+ form set_values book book
+} -new_data {
+ bookshelf::book::new \
+ -book_id $book_id \
+ -isbn $isbn \
+ -book_author $book_author \
+ -book_title $book_title \
+ -main_entry $main_entry \
+ -additional_entry $additional_entry \
+ -excerpt $excerpt \
+ -publish_status $publish_status \
+ -read_status $read_status
+
+ ad_returnredirect "."
+ return
+} -edit_data {
+ bookshelf::book::edit \
+ -book_id $book_id \
+ -isbn $isbn \
+ -book_author $book_author \
+ -book_title $book_title \
+ -main_entry $main_entry \
+ -additional_entry $additional_entry \
+ -excerpt $excerpt \
+ -publish_status $publish_status \
+ -read_status $read_status
+
+ ad_returnredirect "."
+ return
+}
+
+
+form get_values book isbn __isbn_update_flag
+if { $__isbn_update_flag && [exists_and_not_null isbn] } {
+ set image_url [bookshelf::amazon::get_image_url $isbn]
+ set book_url [bookshelf::amazon::get_book_url $isbn]
+
+ bookshelf::amazon::get_book_info -array amazon_book_info $isbn
+ element set_value book book_author $amazon_book_info(book_author)
+ element set_value book book_title $amazon_book_info(book_title)
+}
+
Index: openacs-4/packages/bookshelf/www/book-publish.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-publish.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-publish.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,37 @@
+ad_page_contract {
+ Publish or unpublish a book.
+
+ @creation-date 2002-09-29
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: book-publish.tcl,v 1.1 2002/09/30 18:10:56 lars Exp $
+} {
+ book_no:integer
+ {publish_status "publish"}
+ {return_url {book-view?[export_vars { book_no }]}}
+} -validate {
+ publish_status_allowed -requires { publish_status } {
+ if { ![string equal $publish_status "publish"] && ![string equal $publish_status "draft"] } {
+ ad_complain "Publish status must be 'publish' or 'draft'"
+ }
+ }
+}
+
+set package_id [ad_conn package_id]
+
+set found_p [db_0or1row book_id {
+ select book_id
+ from bookshelf_books
+ where book_no = :book_no
+ and package_id = :package_id
+}]
+
+if { !$found_p } {
+ ad_return_error "Bad book no" "Can't find any book with this book number."
+ ad_script_abort
+}
+
+bookshelf::book::publish \
+ -book_id $book_id \
+ -publish_status $publish_status
+
+ad_returnredirect $return_url
Index: openacs-4/packages/bookshelf/www/book-view.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-view.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-view.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,6 @@
+
+@page_title@
+@context_bar@
+
+
+
Index: openacs-4/packages/bookshelf/www/book-view.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/book-view.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/book-view.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,22 @@
+ad_page_contract {
+ View a book.
+
+ @creation-date 2002-09-08
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: book-view.tcl,v 1.1 2002/09/30 18:10:56 lars Exp $
+} {
+ book_no:integer
+} -properties {
+ page_title
+ context_bar
+ book
+}
+
+set package_id [ad_conn package_id]
+
+set page_title "One Book"
+
+set context_bar [ad_context_bar $page_title]
+
+bookshelf::book::get -book_no $book_no -array book
+
Index: openacs-4/packages/bookshelf/www/bookshelf-include.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf-include.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf-include.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,8 @@
+
+ @book.read_status_pretty@
+
+
+
+
+
+
Index: openacs-4/packages/bookshelf/www/bookshelf-include.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf-include.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf-include.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,42 @@
+# Include template
+#
+# Lists the books in this package
+
+# Expects:
+# package_id:optional
+
+if { ![exists_and_not_null package_id] } {
+ set package_id [ad_conn package_id]
+}
+
+db_multirow -extend { view_url } book books {
+ select b.book_id,
+ b.book_no,
+ b.isbn,
+ b.book_author,
+ b.book_title,
+ b.main_entry,
+ b.additional_entry,
+ b.excerpt,
+ b.publish_status,
+ b.read_status,
+ bookshelf_book__read_status_pretty(b.read_status) as read_status_pretty,
+ o.creation_user,
+ o.creation_date,
+ to_char(o.creation_date, 'fmMonth DDfm, YYYY') as creation_date_pretty,
+ u.first_names as creation_user_first_names,
+ u.last_name as creation_user_last_name
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where package_id = :package_id
+ and publish_status = 'publish'
+ order by bookshelf_book__read_status_sort_order(b.read_status) desc, o.creation_date desc
+} {
+ if { [empty_string_p $excerpt] } {
+ set excerpt [string_truncate -len 300 $main_entry]
+ }
+ set read_status_pretty [string totitle $read_status_pretty]
+ set view_url "book-view?[export_vars { book_no }]"
+}
+
Index: openacs-4/packages/bookshelf/www/bookshelf-titles-include.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf-titles-include.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf-titles-include.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,6 @@
+
+ @book.read_status_pretty@
+
+ - @book.book_title@
+
+
\ No newline at end of file
Index: openacs-4/packages/bookshelf/www/bookshelf-titles-include.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf-titles-include.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf-titles-include.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,40 @@
+# Include template
+#
+# Lists the book titles in this package
+
+# Expects:
+# package_id:optional
+
+if { ![exists_and_not_null package_id] } {
+ set package_id [ad_conn package_id]
+}
+
+db_multirow -extend { view_url } book books {
+ select b.book_id,
+ b.book_no,
+ b.isbn,
+ b.book_author,
+ b.book_title,
+ b.main_entry,
+ b.additional_entry,
+ b.excerpt,
+ b.publish_status,
+ b.read_status,
+ bookshelf_book__read_status_pretty(b.read_status) as read_status_pretty,
+ o.creation_user,
+ o.creation_date,
+ u.first_names || ' ' || u.last_name as creation_user_name
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where package_id = :package_id
+ and publish_status = 'publish'
+ order by bookshelf_book__read_status_sort_order(b.read_status), o.creation_date desc
+} {
+ if { [empty_string_p $excerpt] } {
+ set excerpt [string_truncate -len 300 $main_entry]
+ }
+ set read_status_pretty [string totitle $read_status_pretty]
+ set view_url "book-view?[export_vars { book_no }]"
+}
+
Index: openacs-4/packages/bookshelf/www/bookshelf.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,5 @@
+
+ Bookshelf
+ @context_bar@
+
+
Index: openacs-4/packages/bookshelf/www/bookshelf.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/bookshelf.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/bookshelf.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,6 @@
+ad_page_contract {
+ Bookshelf page
+}
+
+set context_bar [ad_context_bar]
+
Index: openacs-4/packages/bookshelf/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/index.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/index.adp 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,79 @@
+
+ @page_title@
+ @context_bar@
+
+
+
+
+ Summary:
+
+
+
+
+ @stats.stat_name@
+ |
+
+
+
+
+ @stats.name@
+ |
+
+ @stats.num_books@
+ |
+
+
+
+
+
+ |
+ |
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ @book.book_title@
+ (Edit)
+
+ @book.excerpt@
+ Reviewed by: @book.creation_user_first_names@ @book.creation_user_last_name@
+
+ Read Status:
+ @book.read_status_pretty@
+ DRAFT
+
+ |
+
+
+
+
+
+
+ No book match these criteria.
+ |
+
+
+
+ |
+
+
Index: openacs-4/packages/bookshelf/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/index.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/index.tcl 30 Sep 2002 18:10:56 -0000 1.1
@@ -0,0 +1,148 @@
+ad_page_contract {
+ Bookshelf: List books
+
+ @creation-date 2002-09-08
+ @author Lars Pind (lars@pinds.com)
+ @cvs-id $Id: index.tcl,v 1.1 2002/09/30 18:10:56 lars Exp $
+} {
+ creation_user:integer,optional
+ read_status:optional
+ publish_status:optional
+}
+
+set package_id [ad_conn package_id]
+set write_p [ad_permission_p $package_id write]
+
+if { !$write_p } {
+ ad_return_template bookshelf
+ return
+}
+
+set context_bar [ad_context_bar]
+
+db_1row instance_name {
+ select instance_name
+ from apm_packages
+ where package_id = :package_id
+}
+
+set page_title $instance_name
+
+set human_readable_filter "All books"
+set where_clauses [list "package_id = :package_id"]
+set filters_p 0
+
+if { [info exists read_status] } {
+ lappend where_clauses "b.read_status = :read_status"
+ db_1row read_status_pretty {
+ select bookshelf_book__read_status_pretty(:read_status) as read_status_pretty
+ }
+ append human_readable_filter " $read_status_pretty"
+ set filters_p 1
+}
+
+if { [info exists creation_user] } {
+ lappend where_clauses "o.creation_user = :creation_user"
+ if { $creation_user == [ad_conn user_id] } {
+ append human_readable_filter " reviewed by me"
+ } else {
+ db_1row creation_user_name {
+ select first_names || ' ' || last_name as creation_user_name from cc_users where user_id = :creation_user
+ }
+ append human_readable_filter " reviewed by $creation_user_name"
+ }
+ set filters_p 1
+}
+
+if { [info exists publish_status] } {
+ lappend where_clauses "b.publish_status = :publish_status"
+ if { [string equal $publish_status "draft"] } {
+ append human_readable_filter " that are not yet published"
+ set filters_p 1
+ }
+} elseif { !$write_p } {
+ # if you don't have write permission, then we only show published books
+ lappend where_clauses "b.publish_status = 'publish'"
+}
+
+if { $filters_p } {
+ set clear_filters_url "."
+} else {
+ set clear_filters_url {}
+}
+
+set sql "
+ select b.book_id,
+ b.book_no,
+ b.isbn,
+ b.book_author,
+ b.book_title,
+ b.main_entry,
+ b.additional_entry,
+ b.excerpt,
+ b.publish_status,
+ b.read_status,
+ bookshelf_book__read_status_pretty(b.read_status) as read_status_pretty,
+ o.creation_user,
+ o.creation_date,
+ to_char(o.creation_date, 'fmMonth DDfm, YYYY') as creation_date_pretty,
+ u.first_names as creation_user_first_names,
+ u.last_name as creation_user_last_name
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where [join $where_clauses " and "]
+ order by o.creation_date desc
+"
+
+db_multirow -extend { view_url edit_url } book books $sql {
+ if { [empty_string_p $excerpt] } {
+ set excerpt [string_truncate -len 300 $main_entry]
+ }
+ set read_status_pretty [string totitle $read_status_pretty]
+ set view_url "book-view?[export_vars { book_no }]"
+ set edit_url "book-edit?[export_vars { book_no }]"
+}
+
+db_multirow -extend { name_url stat_name } stats stats_by_read_status {
+ select b.read_status as unique_id,
+ bookshelf_book__read_status_pretty(b.read_status) as name,
+ count(b.book_id) as num_books
+ from bookshelf_books b
+ where b.package_id = :package_id
+ group by unique_id
+ order by bookshelf_book__read_status_sort_order(b.read_status)
+} {
+ set stat_name "Read status"
+ set name [string totitle $name]
+ set name_url ".?[export_vars -url { { read_status $unique_id } }]"
+}
+
+db_multirow -extend { name_url stat_name } -append stats stats_by_publish_status {
+ select b.publish_status as unique_id,
+ bookshelf_book__pub_status_pretty(b.publish_status) as name,
+ count(b.book_id) as num_books
+ from bookshelf_books b
+ where b.package_id = :package_id
+ group by unique_id
+ order by bookshelf_book__pub_status_sort_order(b.publish_status)
+} {
+ set stat_name "Publish status"
+ set name [string totitle $name]
+ set name_url ".?[export_vars -url { { publish_status $unique_id } }]"
+}
+
+db_multirow -extend { name_url stat_name } -append stats stats_by_reviewer {
+ select o.creation_user as unique_id,
+ u.first_names || ' ' || u.last_name as name,
+ count(b.book_id) as num_books
+ from bookshelf_books b join
+ acs_objects o on (o.object_id = b.book_id) join
+ cc_users u on (u.user_id = o.creation_user)
+ where b.package_id = :package_id
+ group by unique_id, name
+ order by name
+} {
+ set stat_name "Reviewed By"
+ set name_url ".?[export_vars -url { { creation_user $unique_id } }]"
+}
Index: openacs-4/packages/bookshelf/www/doc/index.html
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookshelf/www/doc/index.html,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/bookshelf/www/doc/index.html 30 Sep 2002 18:10:57 -0000 1.1
@@ -0,0 +1,106 @@
+
+
+Bookshelf Documentation
+
+
+Bookshelf Documentation
+By Lars Pind.
+
+
+Why
+
+
+ I wrote this bookshelf package for my own web site at pinds.com. For background
+ information, please visit http://www.pinds.com/download.
+
+
+Download
+
+
+ The latest version lives in the OpenACS CVS repository.
+
+
+Getting started
+
+
+ Install the package on your system, mount a new instance somewhere
+ on the site map, make sure you have admin permission on the
+ instance, and then visit the URL where you mounted it. Now you can
+ add your first book.
+
+
+
+ It's meant to support both single-user publish-to-the-world style
+ bookshelf, and a collaboratively maintained bookshelf for members of
+ a community.
+
+
+Putting it on some other page
+
+
+ If you want to inlcude your bookshelf on, say, your blog page, you
+ can get it in two versions:
+
+
+
+ -
+ <include src="/packages/bookshelf/www/bookshelf-include">
+ gives you the full version with reviews and all.
+
+ -
+ <include
+ src="/packages/bookshelf/www/bookshelf-titles-include"> gives
+ you the short version which just lists the titles.
+
+
+
+
+Technical Info
+
+
+ The package fully supports multiple instances, i.e., you can mount
+ several instances in your site map, and they'll stay properly
+ isolated from each other.
+
+
+
+ Only supports PostgreSQL (please do port to Oracle if you want to).
+
+
+
+Road Map
+
+
+
+ - Adding categories
+
+ - Adding notifications
+
+ - Adding a calendar widget, perhaps
+
+ -
+ Technical detail: Refactoring some of the common features between this
+ package and bug-tracker and lars-blogger into a common, reusable
+ substrate
+
+
+
+
+Version History
+
+
+ - 0.2: First released version.
+
+
+License
+
+Released under the GPL.
+
+
+
+lars@pinds.com
+
+
\ No newline at end of file