# #---VIEWITEM.CML. View a (page of an) item, with an optional list of "next" # items. # # Copyright (C) 1996 Screen Porch LLC. All rights reserved. # # Invoked as: # .../viewitem.cml ? nch nxt cn in rn rs ix il # here # # Argument (aka) what # (1) nch unique # (defeat caching) # (2) nxt saved page index of "calling" page # (3) cn conf # ("x" to use list of items in IL) # (4) in item # ("x" ...) # (5) rn resp # ("x" ...) # (6) rs starting resp # in page ("x" to figure automatically) # (7) ix index into IL ("x" to use value from last instance) # (8) il name of list of items ("x" if none) # [ (9) rt variable contains response text (optional) ] # [(10) ty type of response text in arg(9): 'format', 'html', # or 'literal'. ] # # Purpose: # Display a selected "page" of an item (or list of items). Handle # all user interaction with the item (navigating between pages, # adding a response, marking things new or old, etc.) # # Usage: # Viewitem can be used to display a single item, or a list of items. # # There are two ways to display a page of a single item (CN IN RN): # # (1) viewitem decides exactly which responses to load in the page, # and positions the page at response RN. # viewitem?nch+nxt+CN+IN+RN+x+1+x#here # # (2) or, the caller can specify both the position and RS, the 1st # response in the page: # viewitem?nch+nxt+CN+IN+RN+RS+1+x#here # # To display a list of items (and start on the first item in the list) # set itemlist (triplet list of items to be displayed) # viewitem?nch+nxt+x+x+x+x+1+itemlist#here # # A triplet list may be (optionally) terminated by a saved page index; # in that case, when viewitem reaches the end of a triplet list, the # "pass" and "post & go" buttons will go to that saved page. # # The optional 9th argument (usually empty) is used to supply the # name of a variable containing response text. This is useful # when the caller needs to somehow supply (or restore) text # for a (proposed) response. (See upload.cml for an example.) # # Global variables (supplied by caller) # vi_markseen should viewitem mark everything in this page as seen? # Set by a previously-called page to 1. # # Internal State variables: # # How it works # Viewitem is "called" from a page; it then re-invokes itself, # via viewf.cml, as many times as necessary to perform all of # its functions. When it is finally finished, it generates a # "Location:" to the original calling page. # # For each call: # # If only the CN, IN, and RN arguments are supplied, build ITEMLIST # out of them. # # If they're not already in $arg(3-5), get the # IX'th CNUM, INUM, and RNUM values from ITEMLIST. # # Start loading the item at response RNUM - CONTEXT (unless RS has been # supplied, in which case use that value). Position the page at # response RNUM. # # Load up to CUR_PAGERESPS responses (which is usually derived from # PAGERESPS). If there's more on either side (before or after) # the page, put in the appropriate "previous page" or # "next page" buttons. # # The response entry form will only appear in the very last page of # an item. # # Layout: the CML code is broken up into lettered sections: # # (A) Determine or set up an item list, depending on the arguments. # # (B) Figure out exactly where we are in the item. # # (C) Display the current item and responses. # # (D) Put up the buttons and forms for navigation and adding # a response. # # Notes: #: CR 6/03/96 21:43 add index-to-item-list argument #: CR 10/24/96 16:45 Much new for 3.1 interface. #: CR 03/12/00 23:25 Use scrollIntoView for IE #: CR 04/12/00 15:03 Make sure there's only one 'here1' tag displayed! #========================================================================== # SECTION A: # Get or deduce the exact cnum, inum, rnum, and item list information # from the arguments. if $empty ($(href)) include $cml_dir()/startup.i viewitem.cml +$arg(9)+$arg(10) end include $(dir)/secure.i member $arg(3) set nch $unique() #set submit $word (1 $form(submit)) #---Response number -1 is a special code for "last response". if $equal ($arg(5) -1) set arg(5) $it_resps($arg(3) $arg(4)) end #---Verify that the user is a member -- if not, go straight to "join" page. if $not ($it_member($arg(3))) "%location($(href)/join.cml?$(nch)+$arg(2)+x+$arg(3)+$arg(4)+$arg(5)+x+x) " return end #---When in doubt, index into item list is always 1 (first item). if $equal ($arg(7) x) set arg(7) 1 end #---Conf/item/resp number supplied for a single item request, but no # itemlist: make up our own itemlist. if $and ($not_equal ($arg(3) x) $equal ($arg(8) x) ) set ilist $plusmod ($(ilist) 1 $(ilistmax)) set ilist$(ilist) $arg(3) $arg(4) $arg(5) $arg(2) set arg(8) ilist$(ilist) set vi_markseen 1 end set vi_cnum $arg(3) set vi_inum $arg(4) set vi_rnum $arg(5) #---If we got here w/o explicit cnum/inum/rnum's, reload this page # with them in place. (This is essential for bookmarking to work.) if $equal ($arg(3) x) set vi_temp $rest( $arg(7) $($arg(8)) ) set vi_cnum $word( 1 $(vi_temp) ) set vi_inum $word( 2 $(vi_temp) ) set vi_rnum $word( 3 $(vi_temp) ) "%location($(href)/viewitem.cml?$(nch)+$arg(2)+\ $(vi_cnum)+$(vi_inum)+$(vi_rnum)+x+$arg(7)+$arg(8)#here) return end #---At this point, we have effectively visited this page, so save it and # get NXT, the index to it (to pass on to anything *we* call). set cname $upper1 ($replace (_ 32 $cl_name($(vi_cnum)))) set nxt $page_save (1 viewitem.cml \ $arg(2)+$arg(3)+$arg(4)+$arg(5)+$arg(6)+$arg(7)+$arg(8) \ #here $(cname) Item $(vi_inum) ) #---If we got here and the item was deleted, treat it as a "pass", and go # on to the next item (via viewf.cml). if $not ($it_exists($(vi_cnum) $(vi_inum))) "%location($(href)/viewf.cml?$(nch)+$arg(2)+\ $arg(3)+$arg(4)+$arg(5)+$arg(6)+$arg(7)+$arg(8)) return end #========================================================================== # SECTION B: Figure out exactly where we are *in* the item. #---Figure out where (what response) to position the page. (That's # where the "#here" anchor will go.) if $equal (x $arg(5)) set rpos $(vi_rnum) end else set rpos $arg(5) end #---Figure out where to start loading responses... unless specified, # "go back" CONTEXT undeleted responses. set rstart $arg(6) if $equal (x $arg(6)) set rfound 0 set rstart 0 count rt 1 $(rpos) set rtest $minus ($(rpos) $(rt)) if $re_exists ($(vi_cnum) $(vi_inum) $(rtest)) set rfound $plus ($(rfound) 1) if $gt_equal ($(rfound) $(context)) set rstart $(rtest) break end end end end #---Figure out where to stop loading responses. Use the user's preference # for page size, unless (a) the EXPAND button wash pushed, in which case # load the entire item, or (b) response text was supplied through arg(9) # and arg(10), in which case make sure we get to the end of the item. set cur_pageresps $word (1 $(cur_pageresps) $(pageresps)) set rlast $it_resps($(vi_cnum) $(vi_inum)) set rstop $min ($(rlast) $plus($(rstart) $(cur_pageresps) -1) ) if $not_empty ($arg(9)) set rstop $(rlast) end set rfound 0 if $less ($(rstop) $(rlast)) set rstop $(rlast) count rtest $(rstart) $(rlast) if $re_exists($(vi_cnum) $(vi_inum) $(rtest)) set rfound $plus ($(rfound) 1) if $gt_equal ($(rfound) $(cur_pageresps)) set rstop $(rtest) break end end end end #========================================================================== # SECTION C: Actually display the (current page of the) item. #set pagename $t2hbr($re_title($(vi_cnum) \ # $(vi_inum) 0)) set pagename include $(dir)/head.i $quote($(cname) Item $(vi_inum) "$t2hbr($re_title($(vi_cnum) $(vi_inum) 0))") indvresp.js include $(dir)/body.i $arg(3) onUnload="pop_close('all');" \ $ifthen ($(is_explorer4) onLoad="document.all.here1.scrollIntoView();") #---Save the record of what the user *had* seen on this item, # in case we need to "put it back that way" later. set save_seen $minus ($it_newr ($(vi_cnum) $(vi_inum)) 1) set visible $it_visib ( $(vi_cnum) $(vi_inum) ) #---...and then mark this item as seen even as we display it... if $empty($(vi_markseen)) set vi_markseen 1 end if $and ($(vi_markseen) $gt_equal ($(rstop) $it_newr($(vi_cnum) $(vi_inum))) ) if $(visible) eval $set_it_seen( $(vi_cnum) $(vi_inum) $(rstop)) end end #---Item header, logo, and help button if $equal ( $(rpos) 0) if $(is_explorer4) " end else " end end set cnum $(vi_cnum) #---Are there pages before and after this one? set page_before $greater ($(rstart) 0) set page_after $not_equal ($(rstop) $it_resps()) #---Show the toolbar and navigation bar! include $(dir)/header.i viewitem #---Item header info. set itemcolor $conf_var ($(vi_cnum) itemcolor) "
| set color $if ($not ($or ($(vi_markseen) \ $gt_equal ($(save_seen) 0) )) COLOR="RED") " # "$(cname) Item $(vi_inum) "$t2hbr($re_title($(vi_cnum) $(vi_inum) 0)) if $not ($(visible)) "$(for_tag) end " | #---...and within-item navigation buttons, if needed... set all5 $and ($(page_before) $(page_after)) "include $(dir)/nav_item.i " | "
| # "$t2url($t2hbr($re_title($(vi_cnum) $(vi_inum) 0) )) | # "
# if $or ($equal ($cl_access($(vi_cnum)) 3) \
# $and ($(editable) $co_change($(vi_cnum)) \
# $equal ($re_owner($(vi_cnum) $(vi_inum) 0) $userid()) ) )
# "\
# | |||
set uid
set m_cnum $(cnum)
set m_inum $(vi_inum)
count response $(rstart) $(rstop)
set m_rnum $(response)
#---Is this response RPOS? If so, make sure browser scrolls to here.
if $and ($equal ($(response) $(rpos)) $greater($(response) 0) )
if $(is_explorer4)
"
end
else
"
end
end
if $re_exists($(vi_cnum) $(vi_inum) $(response))
#---Build the EDIT button text if this response is editable,
# and if it is SAFE (proper permission and within the time
# limit) to edit it.
set edit
set safe 0
if $and ($(editable) $co_change($(vi_cnum)) \
$equal ($re_owner() $userid()) \
$greater ($cl_access($(vi_cnum)) 1) )
set elapsed $re_epoch($(vi_cnum) $(vi_inum) $(response))
set safe 1
set changelimit $conf_var($(vi_cnum) changelimit)
#--- If there's no time limit, everything's editable
if $not_empty ($(changelimit))
set safe $gt_equal($(changelimit) $minus($time() $(elapsed)) )
end
end
if $or ($equal ($cl_access($(vi_cnum)) 3) $(safe))
set edit \
end
if $(show_id)
set uid ($re_owner())
end
"
"
| "There are more responses to this item on the next page " | "include $(dir)/nav_item.i " | "|||