1 # ===================================================================== 2 # cartView: W-TW shopping cart lister. 3 # 4 # Copyright (c) 2009,2010 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.group.literal = () 27 28 # ===================================================================== 29 # Main program 30 # ===================================================================== 31 32 csaGetArgs GET 33 34 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 35 #~ $REMOTE_ADDR 192.168.1.2 || csaExit.fault 0031 36 37 . $CSA_ROOT/lib/group-stuff.rc 38 39 . $CSA_ROOT/lib/group-editor.rc 40 41 # Set template vars to their final values. 42 tpl.var.tw.page = tw-shop-cartview 43 tpl.var.tw.page.object = $'tpl.var.tw.page' 44 tpl.var.html.title = $'tpl.var.tw.group'/$'tpl.var.tw.page' 45 46 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-shop-cartview.txt) { 47 # custom template. 48 tpl.include.html.body = $CSA_TPL_ROOT/tw-shop-cartview.txt 49 } else { 50 # default template. 51 tpl.include.html.body = $tw_dstem/tw-shop-cartview.txt 52 } 53 54 . $CSA_ROOT/lib/tpl-stuff.rc 55 56 # Set default, effective immediately. 57 ~ $CSA_SESSION(19) tag:* || csaSession.set $CSA_GUID 19 immediate 58 59 # If cart does not exist it is to be treated as an error here. 60 csaIsFullPath --exists --quiet $TMPDIR/$CSA_SESSION(19)^-crt || 61 csaExit.fault 1040 62 63 # Update cart's mtime. There is a slight potential for races between 64 # the previous line of code and this one, but it is harmless. 65 touch $TMPDIR/$CSA_SESSION(19)^-crt || csaExit.fault 0003 touch 66 67 # Test for empty cart. This should not be an error exit, as we 68 # will land here when the user has intentionally removed all 69 # items from her cart. 70 71 ~ `{wc -l < $TMPDIR/$CSA_SESSION(19)^-crt} 0 1 && csaExit.ok 1040 72 73 sorttable --input $TMPDIR/$CSA_SESSION(19)^-crt | 74 jointable $tw_gstem/page+dat | awktable -- ' 75 # Exclude unavailable (or no-longer available) items from output. 76 $p_store ~ /^[^:]*:0/ { next } 77 # Force unit qty on downloadables. 78 $p_store ~ /^[^:]*:-1/ { $cart_qty = 1 } 79 # Remove any explicit exclusion directive. 80 {sub(/^ *! */,"",$p_descr)} 81 # Unconditionally exclude hidden/redirected pages from output. 82 $p_descr !~ /(^ *-|\(:redirect )/ { 83 print $k_page,$cart_qty,$p_name,$p_uri,$p_descr,$p_link,$p_store 84 }' > $tmp1 85 86 csaStatus || csaExit.fault 0003 sorttable/jointable/awktable 87 88 #csaExit.pcdata $tmp1 89 90 cart_tmp = $tmp1 91 92 # This view does not correspond to an actual page on disk, 93 # so we need to toggle unapplicable sections in templates. 94 95 tpl.if.tw.ispage = '(::DEL:)' 96 tpl.fi.tw.ispage = '(:DEL::)' 97 tpl.if.tw.printable = '(::DEL:)' 98 tpl.fi.tw.printable = '(:DEL::)' 99 tpl.if.tw.isview = () 100 tpl.fi.tw.isview = () 101 102 # Set the "continue shopping" URL. 103 if (~ $CSA_SESSION(20) http://* https://* && !~ $CSA_SESSION(20) */tw-cart) { 104 tpl.var.tw.cart.more = $CSA_SESSION(20) 105 } else { 106 # Default is pagemap. 107 tpl.var.tw.cart.more = $CSA_RPC_URI/$CSA_LANG/$'cgi.group'/5 108 csaSession.set $'tpl.var.tw.cart.more' 20 109 } 110 111 csaMkTemp tpl.include.tw.page 112 113 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 114 csaExit.ok --table $cart_tmp $tpl_file 115 116 #EOF