| Author |  Topic  | 
              
                | DavidRhodesSenior Member
 
     
 
                United Kingdom1222 Posts
 | 
                    
                      |  Posted - 10 March 2003 :  13:43:11   
 |  
                      | Requires Private Messages Mod 
 Seen this done a few times before so thought i'd share my version of it. Basically, if you have 1 message you will be promted (OK/Cancel) to view the message instantly or if you have more than 1 it will take you to your inbox.
 
 Create a new ASP file calles inc_pm_alert.asp, add the following
 
 <%
if strDBNTUserName <> "" Then 
	if pmcount = 1 then 
		strSql = "SELECT " & strMemberTablePrefix & "MEMBERS.MEMBER_ID, " & strMemberTablePrefix & "MEMBERS.M_NAME, " & strTablePrefix & "PM.M_ID, " & strTablePrefix & "PM.M_TO, " & strTablePrefix & "PM.M_SUBJECT, " & strTablePrefix & "PM.M_SENT, " & strTablePrefix & "PM.M_FROM, " & strTablePrefix & "PM.M_READ "
		strSql = strSql & " FROM " & strMemberTablePrefix & "MEMBERS , " & strTablePrefix & "PM "
		strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.M_NAME = '" & strDBNTUserName & "'"
		strSql = strSql & " AND " & strMemberTablePrefix & "MEMBERS.MEMBER_ID = " & strTablePrefix & "PM.M_TO "
		strSql = strSql & " ORDER BY " & strTablePrefix & "PM.M_SENT DESC" 
		Set rsMessage = my_Conn.Execute(strSql)
		%>		
		<script language=javascript>
		if (window.print) {
			if (getCookie('ShowMsgBox') != 'false'){
				agree = confirm('You have a new Private Message!\nWould you like to view it now ?');
				if (agree) {window.open('pm_pop_read.asp?id=<% =rsMessage("M_ID") %>','_blank','width=490,height=340,top=75,left=220,scrollbars=yes')}
				else {setCookie('ShowMsgBox', 'false','','','','')}
			}
		}
		</script>
		<%
		Set rsMessage = Nothing
	elseif pmcount > 1 then 
		%>		
		<script language=javascript>
		if (window.print) {
			if (getCookie('ShowMsgBox') != 'false'){
				agree = confirm('You have <%=pmcount%> new Private Messages!\nWould you like to go to your inbox now ?');
				if (agree) {window.location.href = 'pm_view.asp?view=inbox'; setCookie('ShowMsgBox', 'false','','','','')}
				else {setCookie('ShowMsgBox', 'false','','','','')}
			}
		}
		</script>
		<%
	end if
end if
%>
 add this to inc_footer.asp above my_Conn.close
 
 %>
<!--#INCLUDE FILE="inc_pm_alert.asp" -->
<% 
 add these JavaScript functions between the HEAD tags of inc_header.asp, sorry I can't be more exact with line numbers but i've extracted my js to a .js file.
 
 
 function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
 cookies are required in the event that you click cancel on the popup, the cookie prevents the popup occuring on subsequent pages
 
 
  |  
                      | The UK MkIVs Forum
 |  | 
              
                | PeeWee.IncSenior Member
 
     
 
                United Kingdom1893 Posts
 | 
                    
                      |  Posted - 10 March 2003 :  13:59:16     
 |  
                      | 
<%
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
%>
 how long is the cookie stored for?
 |  
                      | De Priofundus Calmo Ad Te Damine
 |  
                      |  |  | 
              
                | DavidRhodesSenior Member
 
     
 
                United Kingdom1222 Posts
 |  | 
              
                | Jag24Junior Member
 
   
 
                182 Posts | 
                    
                      |  Posted - 18 March 2003 :  20:47:05     
 |  
                      | Looks like a great idea, I was looking for something along this line.
 HeaderFile
 
 Any ideas where I should place the code in this header file?
 
 |  
                      |  |  | 
              
                | DavidRhodesSenior Member
 
     
 
                United Kingdom1222 Posts
 | 
                    
                      |  Posted - 19 March 2003 :  05:54:32   
 |  
                      | Best to put it in the footer as if you have a message a javascript pop-up appears, this will stop the rest of the HTML rendering until you click 'OK'. |  
                      | The UK MkIVs Forum
 |  
                      |  |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 | 
                    
                      |  Posted - 19 March 2003 :  10:56:02     
 |  
                      | quote:add these JavaScript functions between the HEAD tags of inc_header.asp
 
 
 where exactly is that ? sorry asp newbee here.
 
 Greetz
 |  
                      | Body & Fitness Forum
 |  
                      |  |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 |  | 
              
                | Ez4arabJunior Member
 
   
 
                479 Posts | 
                    
                      |  Posted - 21 March 2003 :  03:52:17     
 |  
                      | after this function openMiniPoll(url) {
 popupWin = window.open(url,'new_page','width=200,height=400,top=75,left=220')
 }
 
 |  
                      | Ez4arab web site Ez4arab |
 |  
                      |  |  | 
              
                | RodVeraStarting Member
 
 
 
                Chile2 Posts
 | 
                    
                      |  Posted - 21 March 2003 :  18:34:24     
 |  
                      | Hey, nice work on this one. I have a question, how do i set the cookie to expire, lets say in 5 minutes. I tried 
 setCookie('ShowMsgBox', 'false','300','','','')
 
 but got javascript errors. Pls help.
 |  
                      |  |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 | 
                    
                      |  Posted - 26 March 2003 :  20:17:17     
 |  
                      | quote:Originally posted by Ez4arab
 
 after this
 function openMiniPoll(url) {
 popupWin = window.open(url,'new_page','width=200,height=400,top=75,left=220')
 }
 
 
 
 
 Can not find that part in inc_header.asp :(
 |  
                      | Body & Fitness Forum
 |  
                      |  |  | 
              
                | DavidRhodesSenior Member
 
     
 
                United Kingdom1222 Posts
 | 
                    
                      |  Posted - 27 March 2003 :  11:31:25   
 |  
                      | quote:Originally posted by RodVera
 
 Hey, nice work on this one. I have a question, how do i set the cookie to expire, lets say in 5 minutes. I tried
 
 setCookie('ShowMsgBox', 'false','300','','','')
 
 but got javascript errors. Pls help.
 
 
 
 you need to use a valid date, i don't think seconds will work
 |  
                      | The UK MkIVs Forum
 |  
                      |  |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 | 
                    
                      |  Posted - 28 March 2003 :  12:11:56     
 |  
                      | can someone plz post a link where this mod is working ? I wanna test it :D
 
 Greetz
 |  
                      | Body & Fitness Forum
 |  
                      |  |  | 
              
                | DavidRhodesSenior Member
 
     
 
                United Kingdom1222 Posts
 |  | 
              
                | forumnewbeeStarting Member
 
 
 
                Netherlands42 Posts
 | 
                    
                      |  Posted - 29 March 2003 :  06:43:52     
 |  
                      | quote:Originally posted by DavidRhodes
 
 It's on my site, link is below
 
 
 
 I register there bro member name 'Smalluser' and tested the PM alert it looks great really !!!!!!!!!!!!
 
 I can not get it running on mu forum :( can you plz mail the neccesary asp's so I can look into them ? so I can edit mine asp's.
 
 admin@body-fitness.nl
 
 Greetz
 |  
                      | Body & Fitness Forum
 |  
                      |  |  | 
              
                | LeeCStarting Member
 
 
 
                36 Posts | 
                    
                      |  Posted - 31 March 2003 :  17:44:47     
 |  
                      | Went ahead and converted the javascript inc_header.asp portion to response.writes (Hope you don't mind David) 
 Find the section:
 
 
Response.Write	"<script language=""JavaScript"" type=""text/javascript"">" & vbNewLine & _
		"<!-- hide from JavaScript-challenged browsers" & vbNewLine & _ 
 And above:
 
 
		"// done hiding -->" & vbNewLine & _
		"</script>" & vbNewLine & _
 
 Insert the following:
 
 
		"// ################## PM Alert ##################" & vbNewLine & _
		"function setCookie(name, value, expires, path, domain, secure) {" & vbNewLine & _
		"  var curCookie = name + ""="" + escape(value) +" & vbNewLine & _
		"      ((expires) ? ""; expires="" + expires.toGMTString() : """") +" & vbNewLine & _
		"      ((path) ? ""; path="" + path : """") +" & vbNewLine & _
		"      ((domain) ? ""; domain="" + domain : """") +" & vbNewLine & _
		"      ((secure) ? ""; secure"" : """");" & vbNewLine & _
		"  document.cookie = curCookie;" & vbNewLine & _
		"}" & vbNewLine & _
		"function getCookie(name) {" & vbNewLine & _
		"  var dc = document.cookie;" & vbNewLine & _
		"  var prefix = name + ""="";" & vbNewLine & _
		"  var begin = dc.indexOf(""; "" + prefix);" & vbNewLine & _
		"  if (begin == -1) {" & vbNewLine & _
		"    begin = dc.indexOf(prefix);" & vbNewLine & _
		"    if (begin != 0) return null;" & vbNewLine & _
		"  } else" & vbNewLine & _
		"    begin += 2;" & vbNewLine & _
		"  var end = document.cookie.indexOf("";"", begin);" & vbNewLine & _
		"  if (end == -1)" & vbNewLine & _
		"    end = dc.length;" & vbNewLine & _
		"  return unescape(dc.substring(begin + prefix.length, end));" & vbNewLine & _
		"}" & vbNewLine & _
		"// #############################################" & vbNewLine & _
 
 |  
                      | Oh WTF!com
 Convergence - an MMORPG guild
 .rdw. a CS clan
 GotFrag? - Your online eSports resource
 
 urK?!?
 |  
                      | Edited by - LeeC on 31 March 2003  17:45:53
 |  
                      |  |  | 
              
                
                |  Topic  |  |