Mike Pelletier
|
| Posted: 01/27/2006, 7:47 AM |
|
I am using Codecharge Studio 3 and ASP. Does anyone have any ideas on how to create reoccuring calendar events? I have someone who wants to schedule Gym usage, the same group may use the gym every monday at 3:00, my user wants to be able to just type in a number for the number of weeks this should reoccur. I can use the dateadd function of sql to sequence the weeks, however what would be the best way to sequence through? Use a stored procedure or trigger? New to me, so if there is another easier way that would be better. I am not a programmer but have picked up a bunch using ccs2 and can usually muddle through so be gentle on the code. Thanks for any help.
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 8:09 AM |
|
www.duhbelul.nl/calendar
read the intro text, have a peek.
I can give you the way to do this in pseudo-language and SQL.
Not ASP though.
Walter K
<MikePelletier@forum.codecharge (Mike Pelletier)> schreef in bericht
news:643da408b52d45@news.codecharge.com...
>I am using Codecharge Studio 3 and ASP. Does anyone have any ideas on how
>to
> create reoccuring calendar events? I have someone who wants to schedule
> Gym
> usage, the same group may use the gym every monday at 3:00, my user wants
> to be
> able to just type in a number for the number of weeks this should reoccur.
> I
> can use the dateadd function of sql to sequence the weeks, however what
> would
> be the best way to sequence through? Use a stored procedure or trigger?
> New to
> me, so if there is another easier way that would be better. I am not a
> programmer but have picked up a bunch using ccs2 and can usually muddle
> through
> so be gentle on the code. Thanks for any help.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 10:59 AM |
|
ok, I was looking for something like this as well - but was way too lazy at the time - here I think a solution that might work:
what if we create a stored procedure, pass it the begin and end date, with an interval in days. We then loop the insert instruction incrementing the date by the interval until the newly incremented date is greater than the passed end date.
valiadtion to ensure that the end date is bigger and not 1000's of years in the furure should make this pretty safe?
|
 |
 |
Mike Pelletier
|
| Posted: 01/27/2006, 10:59 AM |
|
Walter,
sql would work, I clicked on your link however and got a connot find page or DNS error.
|
|
|
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 10:59 AM |
|
@ walter, can't access your url - DNS error?
|
 |
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:02 AM |
|
typo:
http://www.dubbellul.nl/calendar
"TheunisP" <TheunisP@forum.codecharge> schreef in bericht
news:643da6da7f3faa@news.codecharge.com...
>@ walter, can't access your url - DNS error?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:04 AM |
|
My principle is described, in part, at the index page.
"Walter Kempees" <kempe819@planet.nl> schreef in bericht
news:drdqop$4s5$1@news.codecharge.com...
> typo:
>
> http://www.dubbellul.nl/calendar
>
>
> "TheunisP" <TheunisP@forum.codecharge> schreef in bericht
>news:643da6da7f3faa@news.codecharge.com...
>>@ walter, can't access your url - DNS error?
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>
|
|
|
 |
Mike Pelletier
|
| Posted: 01/27/2006, 11:06 AM |
|
TheunisP,
I was thinking along those lines myself, but have the user enter the number of reoccuring instances, then use a while function with the insert embedded and a counter incrementing up, also use the counter integer in the dateadd function to incremment up the day. While counter <= number entered execute. My problem is I have never used stored procedures and my first attempt at winging it was less than impressive.
|
|
|
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 11:10 AM |
|
so W, you let CSS do the 1st one and do the rest yourself, correct? cool
|
 |
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 11:12 AM |
|
@m, I like Walter's solution - I suppose someone will tell us that the SP solution is better, but W's solution as is, will work, will be fast to implement and you can use an interval and number of inserts or date limiter.
|
 |
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:17 AM |
|
Beware though, this one is built to display only one objects calendar at a
time.
Only a slight modification will display several spawned events.
The day will no longer be colored but below it (event) will be a
yellow,red,green bar.
"TheunisP" <TheunisP@forum.codecharge> schreef in bericht
news:643da700983a60@news.codecharge.com...
> so W, you let CSS do the 1st one and do the rest yourself, correct? cool
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 11:18 AM |
|
@w, ok you have me, how did you detect duplicate bookings - I checked, you use more than just the start date
Do you try and do the insert and roll-back if failed, or.....
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 01/27/2006, 11:26 AM |
|

From the text on the index page.......
an object has booking, the booking has a booking_id.
The object has an object_id.
When a booking is changed, status or period, I do a CCDLlookup in the calender table for every day in the (bookings) period where the booking_id of that calender record is not equal to the booking_id I am currently changing.
$ccdlookupwhere = " object_id = " . $DBConnection1->ToSQL($cal_object_booking->object_id->GetValue(), ccsInteger);
$ccdlookupwhere .= " and (date_from >=". $DBConnection1->ToSQL($cal_object_booking->date_from->GetValue(),ccsDate) ;
$ccdlookupwhere .= " and date_from < ". $DBConnection1->ToSQL($cal_object_booking->date_to->GetValue(),ccsDate) . ")" ;
if (CCGetFromGet(booking_id,""))
$ccdlookupwhere .= " and booking_id <> " . CCGetFromGet(booking_id,"");
$result = CCDLookup("count(*)", "cal_calendar", $ccdlookupwhere, $DBConnection1);
if ($result) {
$cal_object_booking->{Errors}->addError($CCSLocales->GetText('Period_not_available'));
}
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 01/27/2006, 11:32 AM |
|
My trick is in the INSERT SQL though.
Using a while loop I insert a row into the calendertable
incrementing the date field by 1 day each pass
until the inserted day reaches the date_to.
My companion in this is mktime() in PhP
Lots of mind busters though in handling the MySQL and Screen dates.
What you don't see is that the whole thing is multi language as well.
And uses <td> clourization

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 01/27/2006, 11:35 AM |
|
And Peterr, no crashes, no failing HTML editors no funny dissapearing lines, just good old stable an much appreciated CCS3.0.2.2
Thanks Yes.
.
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 11:41 AM |
|
wait... CCS3.0.2.2?
|
 |
 |
Mike Pelletier
|
| Posted: 01/27/2006, 11:41 AM |
|
wkempees
where did you use the while function? In your ccs3 project or at the sql server?
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:43 AM |
|
In the project, I started off saying not ASP, I'm on PhP MySQL.
No stored procedures available to me.
<MikePelletier@forum.codecharge (Mike Pelletier)> schreef in bericht
news:643da776581383@news.codecharge.com...
> wkempees
> where did you use the while function? In your ccs3 project or at the sql
> server?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:44 AM |
|
It's in the Booking AfterInsert, AfterUpdate and AfterDelete that I call my
function.
<MikePelletier@forum.codecharge (Mike Pelletier)> schreef in bericht
news:643da776581383@news.codecharge.com...
> wkempees
> where did you use the while function? In your ccs3 project or at the sql
> server?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
TheunisP
Posts: 342
|
| Posted: 01/27/2006, 11:46 AM |
|
strange I thought I did all the upgrades - anyhow downloading now...
@w, you say you check in the change to the table, on_validate event?
|
 |
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:48 AM |
|
//End cal_object_booking_ds_AfterExecuteInsert
//Custom Code @16-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
$LastBookingID = mysql_insert_id();
Insert_Calendar($LastBookingID);
//End Custom Code
//End cal_object_booking_ds_AfterExecuteDelete
//Custom Code @17-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
$db = new clsDBConnection1;
Delete_Calendar(CCGetFromGet(booking_id,""));
//End Custom Code
//End cal_object_booking_ds_AfterExecuteUpdate
//Custom Code @18-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
$Booking_id = CCGetFromGet(booking_id);
Delete_Calendar( $Booking_id );
Insert_Calendar( $Booking_id );
//End Custom Code
"Walter Kempees" <kempe819@planet.nl> schreef in bericht
news:drdt7c$6ds$1@news.codecharge.com...
> It's in the Booking AfterInsert, AfterUpdate and AfterDelete that I call
> my function.
>
>
> <MikePelletier@forum.codecharge (Mike Pelletier)> schreef in bericht
>news:643da776581383@news.codecharge.com...
>> wkempees
>> where did you use the while function? In your ccs3 project or at the sql
>> server?
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:49 AM |
|
@T
Yes it's in the Booking onValidate
> @w, you say you check in the change to the table, on_validate event?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Mike Pelletier
|
| Posted: 01/27/2006, 11:50 AM |
|
Thanks,
I think I will look at this approach next week.
|
|
|
 |
Walter Kempees
|
| Posted: 01/27/2006, 11:55 AM |
|
The function, in PhP.
Some debugging code still in there.
function Delete_Calendar($booking_id)
{
$db = new clsDBConnection1;
$SQL="DELETE from cal_calendar WHERE booking_id =". $booking_id;
$db->query($SQL);
$db->close();
}
function Insert_Calendar($booking_id)
{
$db = new clsDBConnection1;
$object_id =
CCDLookup("object_id","cal_object_booking","booking_id=".$booking_id, $db);
$DateFrom =
CCDLookup("date_from","cal_object_booking","booking_id=".$booking_id, $db);
$DateTo =
CCDLookup("date_to","cal_object_booking","booking_id=".$booking_id, $db);
$status_id =
CCDLookup("status_id","cal_object_booking","booking_id=".$booking_id, $db);
// date is in yyyy-mm-dd format, php substring position 0 is the first
character of the string
$year = substr($DateFrom, 0, 4);
$month = substr($DateFrom, 5, 2);
$day = substr($DateFrom, 8, 2);
$t1 = mktime(0, 0, 0, $month, $day, $year); // is the given date_from
in seconds since epoch()
$year = substr($DateTo, 0, 4);
$month = substr($DateTo, 5, 2);
$day = substr($DateTo, 8, 2);
$t2 = mktime(0, 0, 0, $month, $day, $year); // is the given date_to
in seconds since epoch()
/* this is for debug only
echo $DateFrom;
echo "<br>". $year;
echo "<br>". $month;
echo "<br>". $day;
echo "<br>". $t1;
echo "<br>". $t2;
*/
While ($t1 < $t2) { // $t1 is
manipulated within the following lines thus changing, incrementing
$SQL = "INSERT INTO cal_calendar ("
. "booking_id, "
. "object_id, "
. "date_from, "
. "status_id "
. ") VALUES ("
. $db->ToSQL($booking_id, ccsInteger) . ", "
. $db->ToSQL($object_id, ccsInteger) . ", "
. $db->ToSQL(Date("Y-m-d",$t1), ccsDate) . ", "
. $db->ToSQL($status_id, ccsInteger) . ")";
// echo $SQL . "<br>"; //debug
$db->query($SQL);
$t1 = mktime(
date('h', $t1),
date('i', $t1),
date('s', $t1),
date('m', $t1),
date('d', $t1) + 1, // this is where one day is added
and month and year automaically increment when needed
date('Y', $t1)
);
} // end WHILE
}
?>
TTTTTTTT That's all folks.
|
|
|
 |
|