DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Need Help with ASP automatic .VCS file creation in Calendar App

This is a discussion on Need Help with ASP automatic .VCS file creation in Calendar App within the ASP Development forums, part of the Programming & Scripting category; the links in the program all say "?event_id=" so it seems like the original eventID initialization should work... but its ...

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development


Reply

 

LinkBack Thread Tools Display Modes
  #11  
Old June 9th, 2009, 09:59 PM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default

the links in the program all say "?event_id=" so it seems like the original eventID initialization should work... but its not... maybe i'll try printing the EventID variable into the vcs file to make sure its reading correctly.... otherwise i think i'll maybe ask somewhere else?
Reply With Quote
  #12  
Old June 9th, 2009, 10:21 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

What is displayed if you do this:
Code:
Dim EventID : EventID = Request.Querystring("event_id")
Response.Write("The EventID is: " & EventID)
Response.End
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #13  
Old June 10th, 2009, 11:17 AM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default

Quote:
Originally Posted by jmurrayhead View Post
What is displayed if you do this:
Code:
Dim EventID : EventID = Request.Querystring("event_id")
Response.Write("The EventID is: " & EventID)
Response.End
okay, i figured out that the problem with referencing the event_id when creating a new event is that the event_id isn't created until the event is added. when I tried updating an existing event, it created the .vcs file correctly named. hmm... now i need to figure out how to call the generatecalendarfile subfunction when the event is added and the event exists. i wonder if that could also be the problem with my event time as well.
Reply With Quote
  #14  
Old June 11th, 2009, 04:41 PM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default

Okay, So instead of calling the generateCalendarFile subroutine when the new event is being created, I've decided that I'm going to call it when anyone views an event, and I'm going to move the subroutine to the file event_view_popup_events.asp, which, in theory, will be called with the event_id value, so the .vcs file will be named correctly after initializing eventID with a CCGetFromGet or similar command, and it will also have all of the information that I was previously missing: time, description, etc., because the file was previously being created before the information had been saved from the new event form.

The only problem I foresee with this is that I know it isn't "good" programming to re-write the file every time someone views the event details, but it should just overwrite the file that is already there, and .vcs files aren't more than a couple kilobytes to begin with. However, this will allow the user to download the latest file while viewing the event details and it will make sure that any updates are included. Plus, I'm way out of practice and I really just don't want to sift through this code anymore.... any thoughts?

Last edited by MaxxMills84; June 11th, 2009 at 04:45 PM.
Reply With Quote
  #15  
Old June 11th, 2009, 05:19 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

I would put a link or a button on the "View Event" page that will do one of the following:

1. If you use a link, it will have a querystring appended (events.asp?event_id=13&do=download). Then check if CCGetFromGet("do","") = "download", generate the file.

2. If you use a button, set the value of the button to "download". Then check if CCGetFromPost("buttonname", "") = "download", generate the file.

Does that make sense?
Reply With Quote
  #16  
Old June 12th, 2009, 05:03 PM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default

Quote:
Originally Posted by jmurrayhead View Post
I would put a link or a button on the "View Event" page that will do one of the following:

1. If you use a link, it will have a querystring appended (events.asp?event_id=13&do=download). Then check if CCGetFromGet("do","") = "download", generate the file.

2. If you use a button, set the value of the button to "download". Then check if CCGetFromPost("buttonname", "") = "download", generate the file.

Does that make sense?
Thanks I may work in the file generation on request when I get to that point. Here's where I'm stuck now:

okay, so I got it to call the function in the right place. Now its correctly naming the .vcs files (which I changed to .ics per new 2.0 standards) and the files have all of the information getting written into them with no errors, but now I am having trouble getting the time and date in the correct format.

here's the format that I already have the time and date in from the calendar program: 6/12/2009 1:00:00 PM

here's the format that it should be in for the .ICS/.VCS file: 20090612T130000Z

Here's the function that gets passed the two strings to turn into one:
Code:
function vCalDate(strDt, strTime)
        dim arDate
        arDate = split( strDt, "/" )
        strDt = ""
        dim j
        for j = 0 to 2
                if len( arDate( j ) ) = 1 then arDate( j ) = "0" & arDate( j )
                strDt = strDt & arDate( j )
        next
       
        strTime = replace( strTime, ":", "" )
        strTime = cLng( strTime ) + 40000
        if strTime > 240000 then
                strDt = cStr( cLng( strDt ) + 1     )
                strTime = strTime - 240000
        end if
        strTime = cStr( strTime )
        if len( strTime ) < 6 then
                do until len( strTime ) = 6
                        strTime = "0" & strTime
                loop
        end if
        vCalDate = strDt & "T" & strTime & "Z"
end function
I think that the code I found is expecting the time and date to be in a different format than they are. When I pass the time and date to the vCalDate function, I get an error that 'j' is outside of its specified value or range or something like that.

i think all i'd have to do for the date is split the date by the forward slashes "/", then rearrange them without the slashes, and if any number is less than 10, append a "0" in front of it.

for the time, if think I'd maybe need to check for AM vs PM somehow, and then convert to 24-hour time, and remove the colons ":"

then put the two together with a T and Z as it currently does... I haven't done this kinda stuff in a while, could anyone give me a hand with this function?
Reply With Quote
  #17  
Old June 12th, 2009, 05:48 PM
Wolffy's Avatar
Wolfmaster
 
Join Date: Mar 2008
Real name: Wolff
Location: Peoria, IL
Posts: 779
Blog Entries: 1
Rep Power: 9
Wolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to behold
Default

That function seems overly complicated. Try this:
Code:
function vCalDate(inp)
   if IsDate(inp) then
     d = CDate(inp)
     ds = (Year(d) * 10000) + (Month(d) * 100) + Day(d)
     ts = (Hour(d) * 10000) + (Minute(d) * 100) + Second(d)
     vCalDate = (CStr(ds) & "T" & CStr(ts) & "Z")
   end if
end function
document.write(vCalDate("6/12/2009 1:00:00 PM"))
Output: 20090612T130000Z

Comments on this post
MaxxMills84 agrees: Thanked Post
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
The Following User Says Thank You to Wolffy For This Useful Post:
MaxxMills84 (June 12th, 2009)
  #18  
Old June 19th, 2009, 03:26 PM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default

Quote:
Originally Posted by Wolffy View Post
That function seems overly complicated. Try this:
Code:
function vCalDate(inp)
   if IsDate(inp) then
     d = CDate(inp)
     ds = (Year(d) * 10000) + (Month(d) * 100) + Day(d)
     ts = (Hour(d) * 10000) + (Minute(d) * 100) + Second(d)
     vCalDate = (CStr(ds) & "T" & CStr(ts) & "Z")
   end if
end function
document.write(vCalDate("6/12/2009 1:00:00 PM"))
Output: 20090612T130000Z
well I thought that this code worked at first (which it did do for the limited example that I gave), but it turns out that something wasn't right...

1. This code did not account for AM/PM, because AM times should read as 0700 and this code would make them 700.
2. When importing the event into Outlook or iCal the events would be -4 hours off for some reason, even though the actual data of the .ics file was correct.

So, here's how I corrected these problems:

1. Changed code by adding a simple if statement below:
Code:
function vCalDate(inp)
dim d, ds, ts
   if IsDate(inp) then
     d = CDate(inp)
     ds = (Year(d) * 10000) + (Month(d) * 100) + Day(d)
    if Hour(d) >= 10 then
	 ts = (Hour(d) * 10000) + (Minute(d) * 100) + Second(d)
	else 
	  ts = (Hour(d) * 10000) + (Minute(d) * 100) + Second(d)
	  ts = "0" & ts
	 end if
     vCalDate = (CStr(ds) & "T" & CStr(ts))
   end if
end function
This took care of the AM/PM problem.

2. The "Z" appended to the end of the time was actually telling the program that it should read it as UTC Z time zone which, on the east coast, is GMT -5 + 1 for daylight savings = -4 hours difference. Solution: remove "Z" from the end of the string.

Now that the files are all being named correctly, the event data is correct, and I'm not getting any errors from Outlook or iCal when importing them, all that's left is to insert a link to the .ics file in the event details page. This should be the easy part but I'll let y'all know if I have any trouble with that too. Thanks again for the feedback
Reply With Quote
  #19  
Old June 23rd, 2009, 03:26 PM
Barn Newbie
 
Join Date: Jun 2009
Posts: 46
Rep Power: 1
MaxxMills84 is an unknown quantity at this point
Default How to create link to .ics file

Okay, So I'm now having trouble with how to create and display the link to the .ics file...

The .asp code is very long and complex, but here's the portion where I called the function to generate the calendar file, because I'm sure that the data is loaded into the variables from the database at this point.
Code:
'eventGrid Show Method @5-D26D48C9
    Sub Show(Tpl)
        Dim HasNext
        If NOT Visible Then Exit Sub

        Dim RowBlock

        With DataSource
            .Parameters("urlevent_id") = CCGetRequestParam("event_id", ccsGET)
            .Parameters("seslocale") = Session("locale")
            .Parameters("urlevents_category_id") = CCGetRequestParam("events_category_id", ccsGET)
        End With

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeSelect", Me)
        Set Recordset = DataSource.Open(Command)
        If DataSource.Errors.Count = 0 Then IsDSEmpty = Recordset.EOF

        Set TemplateBlock = Tpl.Block("Grid " & ComponentName)
        If TemplateBlock is Nothing Then Exit Sub
        Set RowBlock = TemplateBlock.Block("Row")
        Set StaticControls = CCCreateCollection(TemplateBlock, Null, ccsParseOverwrite, _
            Array(event_title, edit))
            event_title.Value = Recordset.Fields("event_title")
            
            edit_event.Parameters = CCGetQueryString("QueryString", Array("ccsForm"))
            edit_event.Parameters = CCAddParam(edit_event.Parameters, "event_id", CCGetRequestParam("event_id", ccsGET))
            edit_event.Page = "events.asp"
        Set RowControls = CCCreateCollection(RowBlock, Null, ccsParseAccumulate, _
            Array(event_date, event_time, event_time_end, category_id, user_id, event_desc, PanelLocation, PanelCost, PanelURL, PanelTextBox1, PanelTextBox2, PanelTextBox3, PanelTextArea1, PanelTextArea2, PanelTextArea3, PanelCheckBox1, PanelCheckBox2, PanelCheckBox3))

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me)
        If NOT Visible Then Exit Sub

        RowControls.PreserveControlsVisible
        Errors.AddErrors DataSource.Errors
        If Errors.Count > 0 Then
            TemplateBlock.HTML = CCFormatError("Grid " & ComponentName, Errors)
        Else

            ' Show NoRecords block if no records are found
            If Recordset.EOF Then
                TemplateBlock.Block("NoRecords").Parse ccsParseOverwrite
            End If
            HasNext = HasNextRow()
            ForceIteration = False
            Do While ForceIteration Or HasNext
                If HasNext Then
                    event_date.Value = Recordset.Fields("event_date")
                    event_time.Value = Recordset.Fields("event_time")
                    event_time_end.Value = Recordset.Fields("event_time_end")
                    category_id.Value = Recordset.Fields("category_id")
                    user_id.Value = Recordset.Fields("user_id")
                    event_desc.Value = Recordset.Fields("event_desc")
                    
                    event_Location.Value = Recordset.Fields("event_Location")
                    
                    event_Cost.Value = Recordset.Fields("event_Cost")
                    
                    event_URL.Value = Recordset.Fields("event_URL")
                    event_URL.Link = ""
                    event_URL.Page = Recordset.Fields("event_url")
                    
                    event_TextBox1.Value = Recordset.Fields("event_TextBox1")
                    
                    event_TextBox2.Value = Recordset.Fields("event_TextBox2")
                    
                    event_TextBox3.Value = Recordset.Fields("event_TextBox3")
                    
                    event_TextArea1.Value = Recordset.Fields("event_TextArea1")
                    
                    event_TextArea2.Value = Recordset.Fields("event_TextArea2")
                    
                    event_TextArea3.Value = Recordset.Fields("event_TextArea3")
                    
                    event_CheckBox1.Value = Recordset.Fields("event_CheckBox1")
                    
                    event_CheckBox2.Value = Recordset.Fields("event_CheckBox2")
                    
                    event_CheckBox3.Value = Recordset.Fields("event_CheckBox3")
                End If
                CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShowRow", Me)
                RowControls.Show
                If HasNext Then Recordset.MoveNext
                ShownRecords = ShownRecords + 1
                HasNext = HasNextRow()
            Loop
            StaticControls.Show
        End If
     generateCalendarFile
    End Sub
'End eventGrid Show Method
So I'm thinking that I should somehow create a link to the file in there somewhere. Here's the HTML:
Code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>{event_name}</title>
<meta content="CodeCharge Studio 3.0.2.2" name="GENERATOR">

<link media="screen" href="Styles/{CCS_Style}/Style.css" type="text/css" rel="stylesheet">
<link media="print" href="ccsprint.css" type="text/css" rel="stylesheet">

<script language="JavaScript">
function parent_redirect(url) {
	window.opener.location.href=url;
	self.close();
}
</script>
</head>
<body>
<!-- BEGIN Grid eventGrid -->
<table class="Header" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td class="HeaderLeft"><img src="Styles/{CCS_Style}/Images/Spacer.gif" border="0"></td> 
    <th>{event_title}</th>
 
    <td class="HeaderRight"><img src="Styles/{CCS_Style}/Images/Spacer.gif" border="0"></td>
  </tr>
</table>
<table class="Grid" cellspacing="0" cellpadding="0">
  <!-- BEGIN Row -->
  <tr class="Row">
    <td><b>{event_date} 
      <!-- BEGIN Label event_time -->, {event_time}<!-- END Label event_time -->
      <!-- BEGIN Label event_time_end -->- {event_time_end} <!-- END Label event_time_end --></b><br>
      <!-- BEGIN Label category_id --><b>{res:cal_category}:</b> {category_id}. <br>
      <!-- END Label category_id --><b>{res:cal_addedby}:</b> {user_id}<br>
      <br>
      {event_desc} 
      <!-- BEGIN Panel PanelLocation --><br>
      <br>
      <b>{LabelLocation}:</b> {event_Location}<!-- END Panel PanelLocation -->
      <!-- BEGIN Panel PanelCost --><br>
      <br>
      <b>{LabelCost}:</b> {event_Cost}<!-- END Panel PanelCost -->
      <!-- BEGIN Panel PanelURL --><br>
      <br>
      <b>{LabelURL}:</b> <a href="{event_URL_Src}">{event_URL}</a><!-- END Panel PanelURL -->
      <!-- BEGIN Panel PanelTextBox1 --><br>
      <br>
      <b>{LabelTextBox1}:</b> {event_TextBox1}<!-- END Panel PanelTextBox1 -->
      <!-- BEGIN Panel PanelTextBox2 --><br>
      <br>
      <b>{LabelTextBox2}:</b> {event_TextBox2}<!-- END Panel PanelTextBox2 -->
      <!-- BEGIN Panel PanelTextBox3 --><br>
      <br>
      <b>{LabelTextBox3}:</b> {event_TextBox3}<!-- END Panel PanelTextBox3 -->
      <!-- BEGIN Panel PanelTextArea1 --><br>
      <br>
      <b>{LabelTextArea1}</b> {event_TextArea1}<!-- END Panel PanelTextArea1 -->
      <!-- BEGIN Panel PanelTextArea2 --><br>
      <br>
      <b>{LabelTextArea2}:</b> {event_TextArea2}<!-- END Panel PanelTextArea2 -->
      <!-- BEGIN Panel PanelTextArea3 --><br>
      <br>
      <b>{LabelTextArea3}:</b> {event_TextArea3}<!-- END Panel PanelTextArea3 -->
      <!-- BEGIN Panel PanelCheckBox1 --><br>
      <br>
      <b>{LabelCheckBox1}:</b> {event_CheckBox1}<!-- END Panel PanelCheckBox1 -->
      <!-- BEGIN Panel PanelCheckBox2 --><br>
      <br>
      <b>{LabelCheckBox2}:</b> {event_CheckBox2}<!-- END Panel PanelCheckBox2 -->
      <!-- BEGIN Panel PanelCheckBox3 --><br>
      <br>
      <b>{LabelCheckBox3}:</b> {event_CheckBox3}<!-- END Panel PanelCheckBox3 --></td>
  </tr>
 <!-- END Row -->
  <!-- BEGIN Panel edit -->
  <tr class="Row">
    <td align="right">
	<div class="noprint"><a href="javascript:parent_redirect('{edit_event_Src}')">{res:cal_edit_event}</a></div>
	</td>
  </tr>
 <!-- END Panel edit -->
  <!-- BEGIN NoRecords -->
  <tr class="NoRecords">
    <td>{res:CCS_NoRecords}</td>
  </tr>
  <!-- END NoRecords -->
</table>
<!-- END Grid eventGrid -->
<br>
<div class="noprint" align="left"><a href="{close_link_Src}">{res:close_window}</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="{print_link_Src}">{res:print}</a></div>
</body>
</html>
It seems like pretty simple code, but I just don't know enough about ASP and CSS to figure out how these two are talking to each other....

Basically, I just need the html to display a link in the form:
Code:
<a href="Event_{event_id}.ics">Click here to download the event into your Outlook calendar.</a>
Reply With Quote
  #20  
Old June 23rd, 2009, 03:37 PM
Wolffy's Avatar
Wolfmaster
 
Join Date: Mar 2008
Real name: Wolff
Location: Peoria, IL
Posts: 779
Blog Entries: 1
Rep Power: 9
Wolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to behold
Default

I'm no ASP'er but I think the following should work:
Code:
<%
  Response.Write(
"<a href="Event_" & event_id & ".ics">Click here to download the event into your Outlook calendar.</a>")
%>
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Calendar for date entry alex motilal Microsoft Access 1 March 3rd, 2009 09:59 AM
Access 2007 Calendar Year wrong coolcatkelso Microsoft Access 3 February 9th, 2009 08:04 AM
Custom Calendar Control AOG123 Access Database Samples 6 December 10th, 2008 05:34 PM


All times are GMT -4. The time now is 10:59 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2