cvs: /php3/functions php3_mcal.c php3_mcal.h

From: Date: Wed, 08 Sep 1999 15:42:42 +0000
Subject: cvs: /php3/functions php3_mcal.c php3_mcal.h
Groups: php.dev 
Request: Send a blank email to php-dev+get-10721@lists.php.net to get a copy of this message
musone Wed Sep 8 11:42:42 1999 EDT Modified files: /php3/functions php3_mcal.c php3_mcal.h Log: added recurrence functions, added weekday/month constants, cleaned up code Index: php3/functions/php3_mcal.c diff -u php3/functions/php3_mcal.c:1.18 php3/functions/php3_mcal.c:1.19 --- php3/functions/php3_mcal.c:1.18 Tue Sep 7 16:43:15 1999 +++ php3/functions/php3_mcal.c Wed Sep 8 11:42:42 1999 @@ -83,6 +83,7 @@ function_entry mcal_functions[] = { PHP_FE(mcal_open,NULL) +PHP_FE(mcal_close,NULL) PHP_FE(mcal_popen,NULL) PHP_FE(mcal_reopen,NULL) PHP_FE(mcal_fetch_event,NULL) @@ -109,6 +110,12 @@ PHP_FE(mcal_day_of_year,NULL) PHP_FE(mcal_date_compare,NULL) PHP_FE(mcal_event_init,NULL) +PHP_FE(mcal_next_recurrence,NULL) +PHP_FE(mcal_event_set_recur_daily,NULL) +PHP_FE(mcal_event_set_recur_weekly,NULL) +PHP_FE(mcal_event_set_recur_monthly_mday,NULL) +PHP_FE(mcal_event_set_recur_monthly_mday,NULL) +PHP_FE(mcal_event_set_recur_yearly,NULL) {NULL, NULL, NULL} }; @@ -154,6 +161,27 @@ le_mcal = register_list_destructors(cal_close_it,NULL); + REGISTER_MAIN_LONG_CONSTANT("MCAL_SUNDAY",SUNDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_MONDAY",MONDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_TUESDAY",TUESDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_WEDNESDAY",WEDNESDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_THURSDAY",THURSDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_FRIDAY",FRIDAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_SATURDAY",SATURDAY, CONST_PERSISTENT | CONST_CS); + + REGISTER_MAIN_LONG_CONSTANT("MCAL_JANUARY",JANUARY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_FEBRUARY",FEBRUARY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_MARCH",MARCH, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_APRIL",APRIL, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_MAY",MAY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_JUNE",JUNE, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_JULY",JULY, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_AUGUST",AUGUST, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_SEPTEMBER",SEPTEMBER, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_OCTOBER",OCTOBER, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_NOVEMBER",NOVEMBER, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("MCAL_DECEMBER",DECEMBER, CONST_PERSISTENT | CONST_CS); + return SUCCESS; } @@ -351,56 +379,67 @@ convert_to_long(options); } cal_fetch(mcal_le_struct->mcal_stream,eventid->value.lval,&myevent); + calevent_free(mcal_le_struct->event); + mcal_le_struct->event=myevent; + make_event_object(return_value,mcal_le_struct->event); - object_init(return_value); - add_property_long(return_value,"id",myevent->id); - add_property_long(return_value,"public",myevent->public); - object_init(&start); - - if(myevent->start.has_date) - { - add_property_long(&start,"year",myevent->start.year); - add_property_long(&start,"month",myevent->start.mon); - add_property_long(&start,"mday",myevent->start.mday); - } - if(myevent->start.has_time) - { - add_property_long(&start,"hour",myevent->start.hour); - add_property_long(&start,"min",myevent->start.min); - add_property_long(&start,"sec",myevent->start.sec); - } - - - add_assoc_object(return_value, "start",start); +} +/* }}} */ - object_init(&end); - if(myevent->end.has_date) - { - add_property_long(&end,"year",myevent->end.year); - add_property_long(&end,"month",myevent->end.mon); - add_property_long(&end,"mday",myevent->end.mday); - } - if(myevent->end.has_time) - { - add_property_long(&end,"hour",myevent->end.hour); - add_property_long(&end,"min",myevent->end.min); - add_property_long(&end,"sec",myevent->end.sec); - } - add_assoc_object(return_value, "end",end); +void make_event_object(pval *mypvalue,CALEVENT *event) +{ + pval start,end; + object_init(mypvalue); + add_property_long(mypvalue,"id",event->id); + add_property_long(mypvalue,"public",event->public); + object_init(&start); + + if(event->start.has_date) + { + add_property_long(&start,"year",event->start.year); + add_property_long(&start,"month",event->start.mon); + add_property_long(&start,"mday",event->start.mday); + } + if(event->start.has_time) + { + add_property_long(&start,"hour",event->start.hour); + add_property_long(&start,"min",event->start.min); + add_property_long(&start,"sec",event->start.sec); + } + + + add_assoc_object(mypvalue, "start",start); + + object_init(&end); + if(event->end.has_date) + { + add_property_long(&end,"year",event->end.year); + add_property_long(&end,"month",event->end.mon); + add_property_long(&end,"mday",event->end.mday); + } + if(event->end.has_time) + { + add_property_long(&end,"hour",event->end.hour); + add_property_long(&end,"min",event->end.min); + add_property_long(&end,"sec",event->end.sec); + } + add_assoc_object(mypvalue, "end",end); + - add_property_string(return_value,"category",myevent->category,1); - add_property_string(return_value,"title",myevent->title,1); - add_property_string(return_value,"description",myevent->description,1); - add_property_long(return_value,"alarm",myevent->alarm); + add_property_string(mypvalue,"category",event->category,1); + add_property_string(mypvalue,"title",event->title,1); + add_property_string(mypvalue,"description",event->description,1); + add_property_long(mypvalue,"alarm",event->alarm); } -/* }}} */ + + /* {{{ proto array mcal_list_events(int stream_id,int begindate, [int enddate]) Returns list of UIDs for that day or range of days */ void php3_mcal_list_events(INTERNAL_FUNCTION_PARAMETERS) { - pval *streamind,*begindate,*enddate; + pval *streamind,*begindate,*enddate,*recurrence; pval *pvalue; int ind, ind_type; unsigned long i; @@ -409,16 +448,18 @@ unsigned int msgno; pils *mcal_le_struct; cal_list_t *my_cal_list; + CALEVENT *event; datetime_t begincal,endcal; int myargc; myargc=ARG_COUNT(ht); - if (myargc <2 || myargc > 3 || getParameters(ht,myargc,&streamind,&begindate,&enddate) == FAILURE) { + if (myargc <2 || myargc > 4 || getParameters(ht,myargc,&streamind,&begindate,&enddate,&recurrence) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(streamind); convert_to_array(begindate); - if(myargc == 3) convert_to_array(enddate); + if(myargc >= 3) convert_to_array(enddate); + if(myargc == 4) convert_to_long(recurrence); ind = streamind->value.lval; mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); @@ -467,11 +508,28 @@ } -g_cal_list=NULL; + g_cal_list=NULL; cal_search_range(mcal_le_struct->mcal_stream,&begincal,&endcal); my_cal_list=g_cal_list; while(my_cal_list != NULL) { + if(myargc ==4 && recurrence->value.lval ==1) + { + cal_fetch(mcal_le_struct->mcal_stream,my_cal_list->uid,&event); + if(event->recur_type!=RECUR_NONE) + { + datetime_t clamp = begincal; + calevent_next_recurrence(event,&clamp,SUNDAY); + while(dt_hasdate(&clamp) && clamp.year == mcal_le_struct->event->start.year && clamp.mon == mcal_le_struct->event->start.mon) + { + add_next_index_long(return_value,my_cal_list->uid); + clamp.mday++; + if(clamp.mday > endcal.mday) + break; + calevent_next_recurrence(event,&clamp,SUNDAY); + } + } + } add_next_index_long(return_value,my_cal_list->uid); my_cal_list=my_cal_list->next; free(g_cal_list); @@ -1456,6 +1514,259 @@ /* }}} */ + + +/* {{{ proto object mcal_next_recurrence(int stream_id, object event,int weekstart) + returns an object filled with the next date the event occurs, on or + after the supplied date. Returns empty date field if event does not + occur or something is invalid. + */ +void php3_mcal_next_recurrence(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*weekstart; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t next; + weekday_t startofweek; + myargc=ARG_COUNT(ht); + if (myargc !=2 || getParameters(ht,myargc,&streamind,&weekstart) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_long(weekstart); + + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_next_recurrence(mcal_le_struct->event,&next,weekstart->value.lval); + object_init(return_value); + if(next.has_date) + { + add_property_long(return_value,"year",next.year); + add_property_long(return_value,"month",next.mon); + add_property_long(return_value,"mday",next.mday); + } + if(next.has_time) + { + add_property_long(return_value,"hour",next.hour); + add_property_long(return_value,"min",next.min); + add_property_long(return_value,"sec",next.sec); + } +} + /* }}} */ + + + +/* {{{ proto string mcal_event_set_recur_daily(int stream_id,object enddate,int interval + create a daily recurrence */ +void php3_mcal_event_set_recur_daily(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*enddate,*interval; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t endtime; + myargc=ARG_COUNT(ht); + if (myargc !=3 || getParameters(ht,myargc,&streamind,&enddate,&interval) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_object(enddate); + convert_to_long(interval); + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_recur_daily(mcal_le_struct->event, &endtime, + interval->value.lval); + +} + /* }}} */ + +/* {{{ proto string mcal_event_set_recur_weekly(int stream_id,object enddate,int interval, int weekdays + create a weekly recurrence */ +void php3_mcal_event_set_recur_weekly(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*enddate,*interval,*weekdays; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t endtime; + myargc=ARG_COUNT(ht); + if (myargc !=4 || getParameters(ht,myargc,&streamind,&enddate,&interval,&weekdays) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_object(enddate); + convert_to_long(interval); + convert_to_long(weekdays); + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_recur_weekly(mcal_le_struct->event, &endtime, + interval->value.lval,weekdays->value.lval); + +} + /* }}} */ + +/* {{{ proto string mcal_event_set_recur_monthly_mday(int stream_id,object enddate,int interval + create a monthly by day recurrence */ +void php3_mcal_event_set_recur_monthly_mday(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*enddate,*interval; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t endtime; + myargc=ARG_COUNT(ht); + if (myargc !=3 || getParameters(ht,myargc,&streamind,&enddate,&interval) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_object(enddate); + convert_to_long(interval); + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_recur_monthly_mday(mcal_le_struct->event, &endtime, + interval->value.lval); + +} + /* }}} */ + +/* {{{ proto string mcal_event_set_recur_monthly_wday(int stream_id,object enddate,int interval + create a monthy by week recurrence */ +void php3_mcal_event_set_recur_monthly_wday(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*enddate,*interval; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t endtime; + myargc=ARG_COUNT(ht); + if (myargc !=3 || getParameters(ht,myargc,&streamind,&enddate,&interval) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_object(enddate); + convert_to_long(interval); + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_recur_monthly_wday(mcal_le_struct->event, &endtime, + interval->value.lval); + +} + /* }}} */ + +/* {{{ proto string mcal_event_set_recur_yearly(int stream_id,object enddate,int interval + create a yearly recurrence */ +void php3_mcal_event_set_recur_yearly(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind,*enddate,*interval; + int ind, ind_type; + unsigned long i; + char *t; + int mcal_folders=0; + unsigned int msgno; + pils *mcal_le_struct; + pval *pvalue,*temppvalue; + cal_list_t *my_cal_list; + int myargc; + unsigned long uid; + CALEVENT *myevent; + datetime_t endtime; + myargc=ARG_COUNT(ht); + if (myargc !=3 || getParameters(ht,myargc,&streamind,&enddate,&interval) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_object(enddate); + convert_to_long(interval); + ind = streamind->value.lval; + + mcal_le_struct = (pils *)php3_list_find(ind, &ind_type); + + if (!mcal_le_struct ) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + calevent_recur_yearly(mcal_le_struct->event, &endtime, + interval->value.lval); + +} + /* }}} */ /* Interfaces to callbacks */ Index: php3/functions/php3_mcal.h diff -u php3/functions/php3_mcal.h:1.7 php3/functions/php3_mcal.h:1.8 --- php3/functions/php3_mcal.h:1.7 Tue Sep 7 16:43:15 1999 +++ php3/functions/php3_mcal.h Wed Sep 8 11:42:42 1999 @@ -1,4 +1,4 @@ -/* $Id: php3_mcal.h,v 1.7 1999/09/07 20:43:15 musone Exp $ */ +/* $Id: php3_mcal.h,v 1.8 1999/09/08 15:42:42 musone Exp $ */ #ifndef _INCLUDED_MCAL_H #define _INCLUDED_MCAL_H @@ -29,6 +29,8 @@ extern int mcal_init_request(INIT_FUNC_ARGS); extern int mcal_end_request(void); +void make_event_object(); + void php3_mcal_open(INTERNAL_FUNCTION_PARAMETERS); void php3_mcal_popen(INTERNAL_FUNCTION_PARAMETERS); void php3_mcal_reopen(INTERNAL_FUNCTION_PARAMETERS); @@ -57,7 +59,12 @@ void php3_mcal_day_of_year(INTERNAL_FUNCTION_PARAMETERS); void php3_mcal_date_compare(INTERNAL_FUNCTION_PARAMETERS); void php3_mcal_event_init(INTERNAL_FUNCTION_PARAMETERS); - +void php3_mcal_next_recurrence(INTERNAL_FUNCTION_PARAMETERS); +void php3_mcal_event_set_recur_daily(INTERNAL_FUNCTION_PARAMETERS); +void php3_mcal_event_set_recur_weekly(INTERNAL_FUNCTION_PARAMETERS); +void php3_mcal_event_set_recur_monthly_mday(INTERNAL_FUNCTION_PARAMETERS); +void php3_mcal_event_set_recur_monthly_wday(INTERNAL_FUNCTION_PARAMETERS); +void php3_mcal_event_set_recur_yearly(INTERNAL_FUNCTION_PARAMETERS);

« previous php.dev (#10721) next »