// ====================================================================== // // Tell A Friend - Enhancement to ShopZone Online Store // // Copyright (c) 2000 by William Atchison. All Rights Reserved // // Atchison Consulting // http://www.atchison.net // // ====================================================================== DEFAULT_COMMENTS="I saw this item and thought you might be interested."; MAX_TELL_FRIEND=5; // set this value to the maximum emails that any user can send from one session // keeping a low number less than 20 can stop potential serious abuse of this // feature CC_WEBMASTER=1; // Set to 1 to CC the webmaster on all TellFriend emails // Set to 0 to disable CC'ing copies to the webmaster main() { configread("config.ini"); l_found=0; if( s_tellfriend_count >= MAX_TELL_FRIEND ) { printtag("HEADER"); printtag( "EXCEED_MAX" ); printtag("TOOLBAR"); printtag("FOOTER"); exit(); } l_found=FindProduct(); if ( (stateget("s_sys_userlogon") == "True") || (stateget("VALIDLOGON") == "True") ) { if( YOUR_NAME=="" ) YOUR_NAME = s_sys_firstname & " " & s_sys_lastname; if( YOUR_EMAIL=="" ) YOUR_EMAIL = s_sys_email; } printtag("HEADER"); if( (parmcount()>1) && (parm("p_prodid")=="") ) { printtag("NO_PROD"); printtag("TOOLBAR"); printtag("FOOTER"); exit(); } if( toupper(func)=="SUBMIT" ) { send_err=TellFriend(l_found); if( send_err==1 ) { printtag("BODY"); if( l_found ) printtag("PRODUCT"); printtag("COMMENTS"); } else { if( send_err!=2 ) { printtag("SUBMIT_CONFIRM" ); if( l_found ) printtag("SUBMIT_CONFIRM_PRODUCT" ); printtag("SUBMIT_CONFIRM_FOOTER" ); } } } else { if( COMMENTS=="" ) COMMENTS=DEFAULT_COMMENTS; printtag("BODY"); if( l_found ) printtag("PRODUCT"); printtag("COMMENTS"); } printtag("TOOLBAR"); printtag("FOOTER"); } TellFriend( l_found ) { // If a session Cookie isn't detected enable the // ShopZone 3 style URL session tracking if( checksession()=="False" ) { enablesession(); } if( s_tellfriend_count == "" ) stateset("s_tellfriend_count",0 ); if( s_tellfriend_count >= MAX_TELL_FRIEND ) { printtag( "EXCEED_MAX" ); return(2); } stateset("s_tellfriend_count", s_tellfriend_count+1 ); l_req_fields = ""; // all fields required if ( strip(COMMENTS)=="" ) { l_req_fields = l_req_fields & "Comments"; comma = ", "; } if ( strip(YOUR_NAME)=="" ) { l_req_fields = l_req_fields & comma & "Your Name"; comma = ", "; } if ( strip(YOUR_EMAIL)=="" ) { l_req_fields = l_req_fields & comma & "Your Email Address"; comma = ", "; } if ( strip(SEND_TO_EM)=="" ) { l_req_fields = l_req_fields & comma & "Your Friend's Email Address"; comma = ", "; } if (l_req_fields != "") { print("

Please fill in the required field(s): " & l_req_fields & "

"); return(1); } // validate field: YOUR_EMAIL if (!validate(YOUR_EMAIL, "E" )) { print("Validation failed for the field: " & "Your Email Address " & "
"); print( "Only Email addresses can be entered for this field "); return(1); } // validate field: SEND_TO_EM if (!validate(SEND_TO_EM, "E" )) { print("Validation failed for the field: " & "Your Friend's Email Address " & "
"); print( "Only Email addresses can be entered for this field "); return(1); } // send email EMAIL_TEMPLATE = "TellFriend_EMAIL.txt"; EMAIL_TO = SEND_TO_EM; EMAIL_SUBJECT = "Product Image from "; EMAIL_FROM = YOUR_EMAIL; l_filename = tmpnam(); l_fp = fopen(l_filename, "w"); if (l_fp != 0) { fprinttag(l_fp, "EMAIL_TEMPLATE", EMAIL_TEMPLATE); if( l_found ) fprinttag(l_fp, "EMAIL_PRODUCT", EMAIL_TEMPLATE); fprinttag(l_fp, "EMAIL_FOOTER", EMAIL_TEMPLATE); l_msg=vprinttag("EMAIL_TEMPLATE", EMAIL_TEMPLATE); if( l_found ) l_msg=lmsg & vprinttag(l_fp, "EMAIL_PRODUCT", EMAIL_TEMPLATE); l_msg=lmsg & vprinttag(l_fp, "EMAIL_FOOTER", EMAIL_TEMPLATE); l_msg=translate(l_msg,"\n","
\n"); gvarset( "l_msg", l_msg ); fclose(l_fp); rc=mail(l_filename, EMAIL_TO, EMAIL_SUBJECT, "" , // don't CC EMAIL_FROM ); remove(l_filename); if (rc == 50) { printtag("MAIL_ERROR", "err.html"); printtag("SUBMIT_ERROR"); return(2); } if( CC_WEBMASTER==1 ) { l_fp = fopen(l_filename, "w"); if (l_fp != 0) { fprinttag(l_fp, "EMAIL_TEMPLATE", EMAIL_TEMPLATE); if( l_found ) fprinttag(l_fp, "EMAIL_PRODUCT", EMAIL_TEMPLATE); fprinttag(l_fp, "EMAIL_FOOTER", EMAIL_TEMPLATE); fclose(l_fp); rc=mail(l_filename, WEBMASTER, EMAIL_SUBJECT & " ( sent to " & EMAIL_TO & " )", "" , // don't CC EMAIL_FROM ); remove(l_filename); if (rc == 50) { printtag("MAIL_ERROR", "err.html"); printtag("SUBMIT_ERROR"); return(2); } } } // end CC webmaster } else { printtag("SUBMIT_ERROR"); } } FindProduct() { if( p_prodid=="" ) return(0); // search for product information search( DB_DIR, "*", "ST_PRODUCTS", "ID=:p_prodid", "", "") { l_discount = ::st_prod::getdiscount(p_prodid, ST_PRODUCTS.GID, ST_PRODUCTS.PRICE, 0); l_product.price = ST_PRODUCTS.PRICE; if (l_discount.price > 0) { l_product.price = format("%.2f", l_product.price - l_discount.price); } gvarset("l_price",l_product.price ); gvarset("l_product",ST_PRODUCTS.NAME ); } if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE); return(1); }