Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 17 Jul 2003 21:30:13 -0000 1.2 @@ -244,13 +244,8 @@ set object_id [db_exec_plsql insert_content_item {}] set cr_item_id $object_id - ns_log Warning "item_id IS: $cr_item_id" - if {$cr_subclass_p} { set object_id [db_exec_plsql insert_content_revision {}] - set foobar [db_1row ct "SELECT count(*) from cr_items where latest_revision = $cr_item_id"] - - ns_log Warning "object_id NOW IS (revision): $object_id. In cr_items? $foobar" } # RBM: If a category was passed, assign the ad to it. @@ -746,5 +741,35 @@ return [ad_context_bar_html [concat $context $args]] } + ad_proc validate_isbn { isbn } { + Does a simple check-digit verigication of isbn. + @author Ben Bytheway + } { + set isbn [string trim $isbn] + regsub -all {(\D&^Xi&^x)} $isbn "" isbn + + if {![regexp {^(\d|X|x){10}$} $isbn]} { + return 1 + } + + set check 0 + set test_isbn [split $isbn ""] + + if {[lindex $test_isbn end] == "x" || [lindex $test_isbn end] == "X"} { + set test_isbn [lreplace $test_isbn end end 10 ] + } + + for {set i 0} {$i <= 9} {incr i} { + set digit [lindex $test_isbn $i] + set check [expr ($digit * (10 - $i)) + $check] + } + set check [expr $check % 11] + + if { !$check && [string index $isbn 0] != 6} { + return 0 + } else { + return 1 + } + } }