. */ function event_add($event) { global $out; $ekeys=array_keys($event); for( $i=0; $i ".$event[ $ekeys[$i] ]."\n"; $query.="`".addslashes($ekeys[$i])."`='".addslashes($event[ $ekeys[$i] ])."', "; } } $query=substr($query, 0, -2)." WHERE `eventcode`='".addslashes($event['eventcode'])."'"; if( strlen($outupdate)>0 ) { // Event data changed if( doquery($query) ) { $out.="Updated event ".$event['eventcode']." (".$row['title']."):\n".$outupdate; }else { $out.="Failed updating event ".$event['eventcode']." (".$row['title']."):\n".$outupdate; } } }else { $out.="Did not update event\n"; } }else { // Not found, this is a new event if( $event['datestart']>date("Y-m-d", strtotime("+2 weeks")) ) { //$out.="Not adding ".$event['eventcode']." yet, too far in future (starting ".get_date($event['datestart'])."; max 2 weeks in advance)\n"; }elseif( $event=event_check($event) ) { $query="INSERT INTO `event` (`eventcode`, `bodycode`, `bodycode2`, `title`, `topic`, `projectname`, `location`, `datestart`, `dateend`, `eventtype`, `calofficial`, `certainty`, `area`, `eventrating`, `documentid`, `email`, `url`) VALUES ('".addslashes($event['eventcode'])."', '".addslashes($event['bodycode'])."', '".addslashes($event['bodycode2'])."', '".addslashes($event['title'])."', '".addslashes($event['topic'])."', '".addslashes($event['projectname'])."', '".addslashes($event['location'])."', '".addslashes($event['datestart'])."', '".addslashes($event['dateend'])."', '".addslashes($event['eventtype'])."', '".addslashes($event['calofficial'])."', '".addslashes($event['certainty'])."', '".addslashes($event['area'])."', '".addslashes($event['eventrating'])."', '".addslashes($event['documentid'])."', '".addslashes($event['email'])."', '".addslashes($event['url'])."')"; if( doquery($query) ) { $out.="Inserted event ".$event['eventcode']."\n"; }else { $out.="Failed adding event ".$event['eventcode']."\n"; } $out.="- Organizer 1: ".$event['bodycode']."\n"; $out.="- Organizer 2: ".$event['bodycode2']."\n"; $out.="- Title: ".$event['title']."\n"; $out.="- Topic: ".$event['topic']."\n"; $out.="- Project name: ".$event['projectname']."\n"; $out.="- Location: ".$event['location']."\n"; $out.="- Date start: ".$event['datestart']."\n"; $out.="- Date end: ".$event['dateend']."\n"; $out.="- Event type: ".$event['eventtype']."\n"; $out.="- Official calendar: ".$event['calofficial']."\n"; $out.="- Certainty: ".$event['certainty']."\n"; $out.="- Area: ".$event['area']."\n"; $out.="- eventrating: ".$event['eventrating']."\n"; $out.="- document ID: ".$event['documentid']."\n"; $out.="- email: ".$event['email']."\n"; $out.="- url: ".$event['url']."\n"; }else { $out.="Did not add event\n"; } } } function event_check($event) { global $out; if( !preg_match("/^(EV|SU|XX)([0-9]{2})([A-Z]{3})([0-9]{1,2})$/", $event['eventcode']) ) { $out.="Invalid event code: ".$event['eventcode']." (title: ".$event['title'].")\n"; return false; } if( !preg_match("/^[A-Z0-9]{3}$/", $event['bodycode']) ) { $out.=$event['eventcode']." (".$event['title']."): invalid organizer 1: ".$event['bodycode']."\n"; return false; } if( !preg_match("/^[A-Z0-9]{3}$/", $event['bodycode2']) AND $event['bodycode2']!="" ) { $out.=$event['eventcode']." (".$event['title']."): invalid organizer 2: ".$event['bodycode2']."\n"; $event['bodycode2']=NULL; #return false; } if( strlen( $event['title'] )>128 ) { $out.=$event['eventcode']." (".$event['title']."): title is too long (".strlen($event['title'])."; max 128 characters)\n"; return false; } if( strlen( $event['topic'] )>128 ) { $out.=$event['eventcode']." (".$event['title']."): topic is too long (".strlen($event['topic'])."; max 128 characters)\n"; $event['topic']=NULL; #return false; } if( strlen( $event['projectname'] )>64 ) { $out.=$event['eventcode']." (".$event['title']."): project name is too long (".strlen($event['projectname'])."; max 64 characters)\n"; #return false; } if( strlen( $event['location'] )>128 ) { $out.=$event['eventcode']." (".$event['title']."): location is too long (".strlen($event['location'])."; max 128 characters)\n"; $event['location']=NULL; #return false; } if( !preg_match("/^((19|20)([0-9]{2}))-([0-1][0-9])-([0-3][0-9])$/", $event['datestart']) ) { $out.=$event['eventcode']." (".$event['title']."): date start is invalid (".$event['datestart'].")\n"; return false; } if( !preg_match("/^((19|20)([0-9]{2}))-([0-1][0-9])-([0-3][0-9])$/", $event['dateend']) ) { $out.=$event['eventcode']." (".$event['title']."): date end is invalid (".$event['dateend'].")\n"; return false; } if( strlen( $event['eventtype'] )>24 ) { $out.=$event['eventcode']." (".$event['title']."): event type is too long (".strlen($event['eventtype'])."; max 24 characters)\n"; $event['eventtype']=NULL; #return false; } if( $event['calofficial']!="" AND $event['calofficial']!="yes" AND $event['calofficial']!="no" AND $event['calofficial']!="under evaluation" ) { $out.=$event['eventcode']." (".$event['title']."): official calendar is invalid (".$event['calofficial'].")\n"; return false; } if( $event['certainty']!="" AND $event['certainty']!="definite" AND $event['certainty']!="likely" AND $event['certainty']!="preliminary" AND $event['certainty']!="unlikely" AND $event['certainty']!="cancelled" ) { $out.=$event['eventcode']." (".$event['title']."): certainty is invalid (".$event['certainty'].")\n"; return false; } if( $event['area']!="" AND $event['area']!="local" AND $event['area']!="national" AND $event['area']!="regional" AND $event['area']!="european" AND $event['area']!="international" ) { $out.=$event['eventcode']." (".$event['title']."): area is invalid (".$event['area'].")\n"; return false; } if( $event['eventrating']!="" AND $event['eventrating']!="standard event" AND $event['eventrating']!="yearplan event" AND $event['eventrating']!="priority event" AND $event['eventrating']!="summer university" ) { $out.=$event['eventcode']." (".$event['title']."): event rating is invalid (".$event['eventrating'].")\n"; return false; } if( strlen( $event['documentid'] )!=32 ) { $out.=$event['eventcode']." (".$event['title']."): document ID is wrong length (".strlen($event['documentid'])."; should be 32 characters)\n"; return false; } if( strlen( $event['email'] )>64 OR !check_email($event['email']) ) { $out.=$event['eventcode']." (".$event['title']."): email is too long or invalid (".$event['email'].": ".strlen($event['email'])."; max 64 characters)\n"; $event['email']=NULL; #return false; } if( strlen( $event['url'] )>64 ) { $out.=$event['eventcode']." (".$event['title']."): url is too long (".strlen($event['url'])."; max 64 characters)\n"; $event['url']=NULL; #return false; } return $event; } ?>