Calendar layout improvements.
[openemr.git] / interface / main / calendar / modules / PostCalendar / pninit.php
blobb44b608155a1efde98d5e015065e0214dfb88cac
1 <?php
2 @define('__POSTCALENDAR__','PostCalendar');
3 /**
4 * $Id$
6 * PostCalendar::PostNuke Events Calendar Module
7 * Copyright (C) 2002 The PostCalendar Team
8 * http://postcalendar.tv
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * To read the license please read the docs/license.txt or visit
25 * http://www.gnu.org/copyleft/gpl.html
29 /**
30 * Initializes a new install of PostCalendar
32 * This function will initialize a new installation of PostCalendar.
33 * It is accessed via the PostNuke Admin interface and should
34 * not be called directly.
36 * @return boolean true/false
37 * @access public
38 * @author Roger Raymond <iansym@yahoo.com>
39 * @copyright The PostCalendar Team 2002
41 function postcalendar_init()
43 list($dbconn) = pnDBGetConn();
44 $pntable = pnDBGetTables();
45 $events_table = $pntable['postcalendar_events'];
46 $cat_table = $pntable['postcalendar_categories'];
48 // after reading some posts i've decided to adopt the new
49 // $pntable style which does not append table names.
50 // if you use joins in your SQL please remember this!
51 $sql = "CREATE TABLE $events_table (
52 pc_eid int(11) unsigned NOT NULL auto_increment,
53 pc_catid int(11) NOT NULL default '0',
54 pc_aid varchar(30) NOT NULL default '',
55 pc_title varchar(150) default '',
56 pc_time datetime,
57 pc_hometext text default '',
58 pc_comments int(11) default '0',
59 pc_counter mediumint(8) unsigned default '0',
60 pc_topic int(3) NOT NULL default '1',
61 pc_informant varchar(20) NOT NULL default '',
62 pc_eventDate date NOT NULL default '0000-00-00',
63 pc_endDate date NOT NULL default '0000-00-00',
64 pc_duration bigint(20) NOT NULL default '0',
65 pc_recurrtype int(1) NOT NULL default '0',
66 pc_recurrspec text default '',
67 pc_recurrfreq int(3) NOT NULL default '0',
68 pc_startTime time,
69 pc_endTime time,
70 pc_alldayevent int(1) NOT NULL default '0',
71 pc_location text default '',
72 pc_conttel varchar(50) default '',
73 pc_contname varchar(50) default '',
74 pc_contemail varchar(255) default '',
75 pc_website varchar(255) default '',
76 pc_fee varchar(50) default '',
77 pc_eventstatus int(11) NOT NULL default '0',
78 pc_sharing int(11) NOT NULL default '0',
79 pc_language varchar(30) default '',
80 PRIMARY KEY (pc_eid),
81 KEY basic_event (pc_catid,pc_aid,pc_eventDate,pc_endDate,pc_eventstatus,pc_sharing,pc_topic)
82 )";
83 $dbconn->Execute($sql);
84 if ($dbconn->ErrorNo() != 0) {
85 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
86 return false;
89 // create the category table
90 $sql = "CREATE TABLE $cat_table (
91 pc_catid int(11) unsigned NOT NULL auto_increment,
92 pc_catname varchar(100) NOT NULL default 'Undefined',
93 pc_catcolor varchar(50) NOT NULL default '#EEEEEE',
94 pc_catdesc text default '',
95 PRIMARY KEY (pc_catid),
96 KEY basic_cat (pc_catname,pc_catcolor)
97 )";
98 $dbconn->Execute($sql);
99 if ($dbconn->ErrorNo() != 0) {
100 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
101 return false;
104 // insert default category
105 $catid = $dbconn->GenID($cat_table);
106 $sql = "INSERT INTO $cat_table (pc_catid, pc_catname, pc_catcolor, pc_catdesc)
107 VALUES($catid,'Default','#EEEEEE','Default Category')";
108 $dbconn->Execute($sql);
109 if ($dbconn->ErrorNo() != 0) {
110 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
111 return false;
114 // PostCalendar Default Settings
115 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', '0');
116 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', '0');
117 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', '0');
118 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
119 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', '#EEEEEE');
120 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', '1');
121 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', '0');
122 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
123 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', '15');
124 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
125 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
126 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
127 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
128 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
129 pnModSetVar(__POSTCALENDAR__, 'pcUseCache', '1');
130 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', '3600');
131 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', 'month');
132 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0');
133 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail'));
134 return true;
138 * Upgrades an old install of PostCalendar
140 * This function is used to upgrade an old version
141 * of PostCalendar. It is accessed via the PostNuke
142 * Admin interface and should not be called directly.
144 * @return boolean true/false
145 * @param string $oldversion Version we're upgrading
146 * @access public
147 * @author Roger Raymond <iansym@yahoo.com>
148 * @copyright The PostCalendar Team 2002
150 function postcalendar_upgrade($oldversion)
153 * Until PostNuke fixes the bugs
154 * with the module upgrade we are
155 * going to have to do it ourselves.
157 * Please do not use the Modules admin
158 * to upgrade PostCalendar. Use the
159 * link provided in the PostCalendar
160 * Admin section.
162 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
163 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
165 list($dbconn) = pnDBGetConn();
166 $pntable = pnDBGetTables();
167 $events_table = $pntable['postcalendar_events'];
168 $cat_table = $pntable['postcalendar_categories'];
170 switch($oldversion) {
172 case '3.0' :
173 case '3.01' :
174 case '3.02' :
175 case '3.03' :
176 case '3.04' :
178 // we need the Date_Calc class
179 require_once("modules/$pcDir/pnincludes/Date/Calc.php");
181 // Update PostCalendar Variables
182 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', pnModGetVar(__POSTCALENDAR__,'time24hours'));
183 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__,'eventsopeninnewwindow'));
184 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__,'useinternationaldates'));
185 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', pnModGetVar(__POSTCALENDAR__,'firstdayofweek'));
186 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__,'dayhighlightcolor'));
187 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', pnModGetVar(__POSTCALENDAR__,'usepopups'));
188 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', pnModGetVar(__POSTCALENDAR__,'displaytopics'));
189 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
190 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__,'listhowmanyevents'));
191 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
192 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
193 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
194 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
195 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
196 pnModSetVar(__POSTCALENDAR__, 'pcUseCache','1');
197 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime','3600');
198 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView','month');
199 pnModSetVar(__POSTCALENDAR__, 'pcSafeMode','0');
201 // alter the events table and change some old columns
202 $sql = "ALTER TABLE $events_table
203 ADD pc_catid int(11) default '0' NOT NULL,
204 ADD pc_duration bigint(20) default '0' NOT NULL,
205 ADD pc_sharing int(11) default '0' NOT NULL,
206 ADD pc_language varchar(30) default '',
207 CHANGE pc_eid pc_eid int(11) unsigned NOT NULL auto_increment,
208 CHANGE pc_location pc_location text,
209 CHANGE pc_conttel pc_conttel varchar(50),
210 CHANGE pc_contname pc_contname varchar(150),
211 CHANGE pc_contemail pc_contemail varchar(255),
212 CHANGE pc_website pc_website varchar(255),
213 CHANGE pc_fee pc_fee varchar(50),
214 CHANGE pc_recurrspec pc_recurrspec text default ''
217 $dbconn->Execute($sql);
218 if ($dbconn->ErrorNo() != 0) {
219 die('event table alter error : '.$dbconn->ErrorMsg());
220 return false;
223 // create the new categories table
224 $sql = "CREATE TABLE $cat_table (
225 pc_catid int(11) unsigned NOT NULL auto_increment,
226 pc_catname varchar(100) NOT NULL default 'Undefined',
227 pc_catcolor varchar(50) NOT NULL default '#EEEEEE',
228 pc_catdesc text default '',
229 PRIMARY KEY(pc_catid)
231 $dbconn->Execute($sql);
232 if ($dbconn->ErrorNo() != 0) {
233 die('cat table create error : '.$dbconn->ErrorMsg());
234 return false;
237 // insert the current hardcoded categories into the new categories table
238 $category1 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category1'));
239 $category2 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category2'));
240 $category3 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category3'));
241 $category4 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category4'));
242 $category5 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category5'));
244 $inserts = array(
245 "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('1','$category1','#EEEEEE')",
246 "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('2','$category2','#00ff00')",
247 "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('3','$category3','#0000ff')",
248 "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('4','$category4','#ffffff')",
249 "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('5','$category5','#ffcc00')"
252 foreach($inserts as $insert) {
253 $dbconn->Execute($insert);
254 if ($dbconn->ErrorNo() != 0) {
255 die('cat table insert error : '.$dbconn->ErrorMsg());
256 return false;
260 // update the current events to reflect the category system change
261 $updates = array(
262 "UPDATE $events_table SET pc_catid = 1 WHERE pc_barcolor = 'r' ",
263 "UPDATE $events_table SET pc_catid = 2 WHERE pc_barcolor = 'g' ",
264 "UPDATE $events_table SET pc_catid = 3 WHERE pc_barcolor = 'b' ",
265 "UPDATE $events_table SET pc_catid = 4 WHERE pc_barcolor = 'w' ",
266 "UPDATE $events_table SET pc_catid = 5 WHERE pc_barcolor = 'y' "
269 foreach($updates as $update) {
270 $dbconn->Execute($update);
271 if ($dbconn->ErrorNo() != 0) {
272 die('event table update error : '.$dbconn->ErrorMsg());
273 return false;
277 // alter the events table and drop the old barcolor column
278 $sql = "ALTER TABLE $events_table DROP pc_barcolor";
279 $dbconn->Execute($sql);
280 if ($dbconn->ErrorNo() != 0) {
281 die('cat table alter error : '.$dbconn->ErrorMsg());
282 return false;
285 // remove the old vars as they are no longer needed
286 pnModDelVar(__POSTCALENDAR__,'category1');
287 pnModDelVar(__POSTCALENDAR__,'category2');
288 pnModDelVar(__POSTCALENDAR__,'category3');
289 pnModDelVar(__POSTCALENDAR__,'category4');
290 pnModDelVar(__POSTCALENDAR__,'category5');
291 pnModDelVar(__POSTCALENDAR__,'time24hours');
292 pnModDelVar(__POSTCALENDAR__,'eventsopeninnewwindow');
293 pnModDelVar(__POSTCALENDAR__,'useinternationaldates');
294 pnModDelVar(__POSTCALENDAR__,'firstdayofweek');
295 pnModDelVar(__POSTCALENDAR__,'dayhighlightcolor');
296 pnModDelVar(__POSTCALENDAR__,'displaytopics');
297 pnModDelVar(__POSTCALENDAR__,'usepopups');
298 pnModDelVar(__POSTCALENDAR__,'listhowmanyevents');
299 pnModDelVar(__POSTCALENDAR__,'allowdirectsubmit');
300 pnModDelVar(__POSTCALENDAR__,'showeventsinyear');
302 //======================================================
303 // now, ideally, we will convert old events to the new
304 // style. this consists of reconfiguring the repeating
305 // events vars.
307 // we need to establish the current repeating
308 // conditions and convert them to the new system
309 //======================================================
310 // old repeating defines
311 //======================================================
312 @define('_EVENT_NONE', -1);
313 @define('_EVENT_DAILY', 0);
314 @define('_EVENT_WEEKLY', 1);
315 @define('_EVENT_MONTHLY', 2);
316 @define('_EVENT_YEARLY', 3);
317 @define('_RECUR_SAME_DAY', 0);
318 @define('_RECUR_SAME_DATE', 1);
319 //======================================================
320 // new repeating defines
321 // $recurrspec['event_repeat']
322 //======================================================
323 @define('NO_REPEAT', 0);
324 @define('REPEAT', 1);
325 @define('REPEAT_ON', 2);
326 //======================================================
327 // $recurrspec['event_repeat_freq']
328 //======================================================
329 @define('REPEAT_EVERY', 1);
330 @define('REPEAT_EVERY_OTHER', 2);
331 @define('REPEAT_EVERY_THIRD', 3);
332 @define('REPEAT_EVERY_FOURTH', 4);
333 //======================================================
334 // $recurrspec['event_repeat_freq_type']
335 //======================================================
336 @define('REPEAT_EVERY_DAY', 0);
337 @define('REPEAT_EVERY_WEEK', 1);
338 @define('REPEAT_EVERY_MONTH', 2);
339 @define('REPEAT_EVERY_YEAR', 3);
340 //======================================================
341 // $recurrspec['event_repeat_on_num']
342 //======================================================
343 @define('REPEAT_ON_1ST', 1);
344 @define('REPEAT_ON_2ND', 2);
345 @define('REPEAT_ON_3RD', 3);
346 @define('REPEAT_ON_4TH', 4);
347 @define('REPEAT_ON_LAST', 5);
348 //======================================================
349 // $recurrspec['event_repeat_on_day']
350 //======================================================
351 @define('REPEAT_ON_SUN', 0);
352 @define('REPEAT_ON_MON', 1);
353 @define('REPEAT_ON_TUE', 2);
354 @define('REPEAT_ON_WED', 3);
355 @define('REPEAT_ON_THU', 4);
356 @define('REPEAT_ON_FRI', 5);
357 @define('REPEAT_ON_SAT', 6);
358 //======================================================
359 // $recurrspec['event_repeat_on_freq']
360 //======================================================
361 @define('REPEAT_ON_MONTH', 1);
362 @define('REPEAT_ON_2MONTH', 2);
363 @define('REPEAT_ON_3MONTH', 3);
364 @define('REPEAT_ON_4MONTH', 4);
365 @define('REPEAT_ON_6MONTH', 6);
366 @define('REPEAT_ON_YEAR', 12);
367 //======================================================
368 // Set Sharing Paramaters
369 //======================================================
370 @define('SHARING_PRIVATE', 0);
371 @define('SHARING_PUBLIC', 1);
372 @define('SHARING_BUSY', 2);
373 @define('SHARING_GLOBAL', 3);
374 //======================================================
375 // Here's some psuedo-code for the conversion
377 // if _EVENT_NONE
378 // $rtype = NO_REPEAT
379 // $rspec = 0 for all;
380 // $duration = endTime - startTime
382 // if _EVENT_DAILY
383 // $rtype = REPEAT
384 // $rspec = REPEAT_EVERY|REPEAT_EVERY_DAY
385 // $duration = endTime - startTime
387 // if _EVENT_WEEKLY
388 // $rtype = REPEAT
389 // $rspec = REPEAT_EVERY|REPEAT_EVERY_WEEK
390 // $duration = endTime - startTime
392 // if _EVENT_MONTHLY
393 // if _RECUR_SAME_DAY
394 // $rtype = REPEAT_ON
395 // $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
396 // if _RECUR_SAME_DATE
397 // $rtype = REPEAT
398 // $rspec = REPEAT_EVERY|REPEAT_EVERY_MONTH
399 // $duration = endTime - startTime
401 // if _EVENT_YEARLY
402 // if _RECUR_SAME_DAY
403 // $rtype = REPEAT_ON
404 // $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
405 // if _RECUR_SAME_DATE
406 // $rtype = REPEAT
407 // $rspec = REPEAT_EVERY|REPEAT_EVERY_YEAR
408 // $duration = endTime - startTime
409 //======================================================
410 // attempt reconfiguration
411 //======================================================
412 $sql = "SELECT pc_eid, pc_eventDate, pc_startTime, pc_endTime, pc_recurrtype, pc_recurrfreq
413 FROM $events_table";
414 $result = $dbconn->Execute($sql);
415 if($dbconn->ErrorNo() != 0) {
416 die($dbconn->ErrorMsg());
417 return false;
419 if(!isset($result)) return false;
420 // grab the results and start the conversion
421 for(; !$result->EOF; $result->MoveNext()) {
422 $recurrspec = array();
423 list($eid,$eventdate,$start,$end,$rtype,$rfreq) = $result->fields;
425 if($rtype == null) $rtype = _EVENT_NONE;
426 switch($rtype) {
428 case _EVENT_NONE :
429 $recurrtype = NO_REPEAT;
430 $recurrspec['event_repeat_freq'] = 0;
431 $recurrspec['event_repeat_freq_type'] = 0;
432 $recurrspec['event_repeat_on_num'] = 0;
433 $recurrspec['event_repeat_on_day'] = 0;
434 $recurrspec['event_repeat_on_freq'] = 0;
435 break;
437 case _EVENT_DAILY :
438 $recurrtype = REPEAT;
439 $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
440 $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_DAY;
441 $recurrspec['event_repeat_on_num'] = 0;
442 $recurrspec['event_repeat_on_day'] = 0;
443 $recurrspec['event_repeat_on_freq'] = 0;
444 break;
446 case _EVENT_WEEKLY :
447 $recurrtype = REPEAT;
448 $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
449 $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_WEEK;
450 $recurrspec['event_repeat_on_num'] = 0;
451 $recurrspec['event_repeat_on_day'] = 0;
452 $recurrspec['event_repeat_on_freq'] = 0;
453 break;
455 case _EVENT_MONTHLY :
456 if($rfreq == _RECUR_SAME_DATE) {
457 $recurrtype = REPEAT;
458 $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
459 $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_MONTH;
460 $recurrspec['event_repeat_on_num'] = 0;
461 $recurrspec['event_repeat_on_day'] = 0;
462 $recurrspec['event_repeat_on_freq'] = 0;
463 } elseif($rfreq == _RECUR_SAME_DAY) {
464 $recurrtype = REPEAT_ON;
465 list($y,$m,$d) = explode('-',$eventdate);
466 $recurrspec['event_repeat_freq'] = 0;
467 $recurrspec['event_repeat_freq_type'] = 0;
468 // event day of week
469 $edow = Date_Calc::dayOfWeek($d,$m,$y);
470 // date of first event day of week
471 $firstDay = Date_Calc::NWeekdayOfMonth(1,$edow,$m,$y,'%Y-%m-%d');
472 // find difference between 1st day and event day
473 list($y2,$m2,$d2) = explode('-',$firstDay);
474 $diff = Date_Calc::dateDiff($d,$m,$y,$d2,$m2,$y2);
475 // assuming $diff is going to be a multiple of 7
476 if($diff > 0) { $diff/=7; }
477 if($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; }
478 $recurrspec['event_repeat_on_num'] = $diff;
479 $recurrspec['event_repeat_on_day'] = $edow;
480 $recurrspec['event_repeat_on_freq'] = REPEAT_ON_MONTH;
482 break;
484 case _EVENT_YEARLY :
485 if($rfreq == _RECUR_SAME_DATE) {
486 $recurrtype = REPEAT;
487 $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
488 $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_YEAR;
489 $recurrspec['event_repeat_on_num'] = 0;
490 $recurrspec['event_repeat_on_day'] = 0;
491 $recurrspec['event_repeat_on_freq'] = 0;
492 } elseif($rfreq == _RECUR_SAME_DAY) {
493 $recurrtype = REPEAT_ON;
494 list($y,$m,$d) = explode('-',$eventdate);
495 $recurrspec['event_repeat_freq'] = 0;
496 $recurrspec['event_repeat_freq_type'] = 0;
497 // event day of week
498 $edow = Date_Calc::dayOfWeek($d,$m,$y);
499 // date of first event day of week
500 $firstDay = Date_Calc::NWeekdayOfMonth(1,$edow,$m,$y,'%Y-%m-%d');
501 // find difference between 1st day and event day
502 list($y2,$m2,$d2) = explode('-',$firstDay);
503 $diff = Date_Calc::dateDiff($d,$m,$y,$d2,$m2,$y2);
504 // assuming $diff is going to be a multiple of 7
505 if($diff > 0) { $diff/=7; }
506 if($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; }
507 $recurrspec['event_repeat_on_num'] = $diff;
508 $recurrspec['event_repeat_on_day'] = $edow;
509 $recurrspec['event_repeat_on_freq'] = REPEAT_ON_YEAR;
511 break;
513 // ok, figure out the event's duration
514 list($sh,$sm,$ss) = explode(':',$start);
515 list($eh,$em,$es) = explode(':',$end);
516 $stime = mktime($sh,$sm,$ss,1,1,1970);
517 // if the ending hour is less than the starting hour
518 // assume that the event spans to the next day
519 if($eh < $sh) {
520 $etime = mktime($eh,$em,$es,1,2,1970);
521 } else {
522 $etime = mktime($eh,$em,$es,1,1,1970);
524 $duration = $etime - $stime;
525 // prep the vars for the sql statement
526 $eid = pnVarPrepForStore($eid);
527 $recurrtype = pnVarPrepForStore($recurrtype);
528 $recurrspec = pnVarPrepForStore(serialize($recurrspec));
529 // create our sql statement
530 $updatesql = "UPDATE $events_table SET
531 pc_aid = '0',
532 pc_recurrtype = $recurrtype,
533 pc_recurrspec = '$recurrspec',
534 pc_duration = $duration,
535 pc_sharing = ".SHARING_GLOBAL."
536 WHERE pc_eid = $eid";
537 // execute our sql statement
538 $dbconn->Execute($updatesql);
539 if ($dbconn->ErrorNo() != 0) {
540 die($dbconn->ErrorMsg());
541 return false;
543 // next event please
545 // all done, proceed with next upgrade step if available/necessary
546 return postcalendar_upgrade('3.1');
547 break;
549 case '3.1' :
550 case '3.1.1' :
551 case '3.1.2' :
552 case '3.1.3' :
553 case '3.1.4' :
554 return postcalendar_upgrade('3.9.0');
555 break;
557 case '3.9.0' :
558 case '3.9.1' :
559 case '3.9.2' :
560 // ading pcSafeMode
561 pnModSetVar(__POSTCALENDAR__, 'pcSafeMode','0');
562 return postcalendar_upgrade('3.9.3');
563 break;
565 case '3.9.3' :
566 case '3.9.3.1' :
567 // adding indexes
568 $sql = "ALTER TABLE $events_table
569 ADD INDEX basic_event (pc_catid,pc_aid,pc_eventDate,pc_endDate,pc_eventstatus,pc_sharing,pc_topic)";
570 $dbconn->Execute($sql);
571 if ($dbconn->ErrorNo() != 0) {
572 die($dbconn->ErrorMsg());
573 return false;
575 // adding indexes
576 $sql = "ALTER TABLE $cat_table
577 ADD INDEX basic_cat (pc_catname, pc_catcolor)";
578 $dbconn->Execute($sql);
579 if ($dbconn->ErrorNo() != 0) {
580 die($dbconn->ErrorMsg());
581 return false;
583 return postcalendar_upgrade('3.9.4');
584 break;
586 case '3.9.4':
587 case '3.9.5':
588 case '3.9.6':
589 case '3.9.7':
590 return postcalendar_upgrade('3.9.8');
591 break;
593 case '3.9.8':
594 pnModDelVar(__POSTCALENDAR__, 'pcSafeMode');
595 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0');
596 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail'));
597 break;
599 case '3.9.9':
600 break;
603 // if we get this far - load the userapi and clear the cache
604 if(!pnModAPILoad(__POSTCALENDAR__,'user')) {
605 return false;
607 $tpl =& new pcSmarty();
608 $tpl->clear_all_cache();
609 $tpl->clear_compiled_tpl();
610 return true;
614 * Deletes an install of PostCalendar
616 * This function removes PostCalendar from you
617 * PostNuke install and should be accessed via
618 * the PostNuke Admin interface
620 * @return boolean true/false
621 * @access public
622 * @author Roger Raymond <iansym@yahoo.com>
623 * @copyright The PostCalendar Team 2002
625 function postcalendar_delete()
627 list($dbconn) = pnDBGetConn();
628 $pntable = pnDBGetTables();
629 $events_table = $pntable['postcalendar_events'];
630 $cat_table = $pntable['postcalendar_categories'];
631 $blocks_table = $pntable['blocks'];
632 $blocks_column =& $pntable['blocks_column'];
634 // get the module id
635 $modid = pnModGetIDFromName(__POSTCALENDAR__);
637 // remove the PostCalendar events table
638 $sql = "DROP TABLE $events_table";
639 $dbconn->Execute($sql);
640 if ($dbconn->ErrorNo() != 0) {
641 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
642 return false;
645 // remove the PostCalendar categories table
646 $sql = "DROP TABLE $cat_table";
647 $dbconn->Execute($sql);
648 if ($dbconn->ErrorNo() != 0) {
649 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
650 return false;
653 // remove all the PostCalendar variables from the DB
654 pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
655 pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
656 pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
657 pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
658 pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
659 pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
660 pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
661 pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
662 pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
663 pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
664 pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
665 pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
666 pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
667 pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
668 pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
669 pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
670 pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
671 pnModDelVar(__POSTCALENDAR__, 'pcSafeMode');
672 pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
673 pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
675 // remove any blocks associated with PostCalendar
676 // Seems the core does not clean up installed blocks so I will.
677 // I appologize for accessing core tables directly.
678 $sql = "DELETE FROM $blocks_table WHERE $blocks_column[mid] = '$modid'";
679 $dbconn->Execute($sql);
680 if ($dbconn->ErrorNo() != 0) {
681 pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
682 return false;
685 // Deletion successful
686 return true;