curriculum_syncWhat it does:
Looks at input cookie and looks in database. Returns a new cookie to write to the browser. Returns empty string if a new cookie isn't necessary. Inserts rows into the database if necessary. Assumes that there is a user logged in.Defined in: /web/philip/tcl/curriculum.tcl
Source code:
set user_id [ad_get_user_id] set cookie [ns_set get [ns_conn headers] Cookie] if ![regexp {CurriculumProgress=([^;]+)} $cookie {} input_cookie] { # we had no cookie set input_cookie [list] } # initialize set new_cookie $input_cookie set new_cookie_necessary_p 0 set db [ns_db gethandle] set elts_from_database [database_to_tcl_list $db "select curriculum_element_id from user_curriculum_map where user_id = $user_id"] foreach dbelt $elts_from_database { if { [lsearch $input_cookie $dbelt] == -1 } { set new_cookie_necessary_p 1 set new_cookie [curriculum_progress_cookie_value $new_cookie $dbelt] } } foreach cookie_elt $input_cookie { if { [lsearch $elts_from_database $cookie_elt] == -1 && ![regexp {[A-z]} $cookie_elt] } { # cookie contains no alphabet chars set dupe_free_insert_sql "insert into user_curriculum_map (user_id, curriculum_element_id, completion_date) select $user_id, $cookie_elt, sysdate from dual where not exists (select 1 from user_curriculum_map where user_id = $user_id and curriculum_element_id = $cookie_elt)" if [catch { ns_db dml $db $dupe_free_insert_sql } errmsg] { # we got an error, probably because there is garbage in the user's # cookie and/or the publisher has deleted one of the curriculum elements ns_log Notice "curriculum_sync got an error from the database. The user's cookie coming in was \"$cookie\". Here's what the RDBMS had to say:\n\n$errmsg" } } } ns_db releasehandle $db if { $new_cookie_necessary_p && ($new_cookie != $input_cookie) } { return $new_cookie } else { return "" }