. */ if( isset($setup) ) { if( is_after("SelectFromDate") AND is_before_ex("EventDateStart") AND $setup['AutoSelection'] ) { $out.="\n\n=== Doing auto selection of participants ===\n"; // Check first if there is free places available, if not, no reason to proceed $query="SELECT COUNT(`PersonID`) as `total` FROM `persons` WHERE `Accepted`='yes' OR `Accepted`='pending' OR `Accepted`='confirmed' OR `Accepted`='arrived'"; if( @mysql_num_rows( $res=doquery($query) )!=1 ) { $out.="Failed loading number of accepted participants, not doing auto selection\n"; }else { $row = mysql_fetch_array($res); $totalaccepted = $row['total']; if( $totalaccepted>=$setup['TotalPlaces'] ) { $out.="There are no free places, not doing auto selection today (".$totalaccepted." accepted for ".$setup['TotalPlaces']." places).\n"; }else { // Found free places, read the data we need. Start with loading all the bodies and their data $query="SELECT `BodyCode`, `BodyName`, `BodyStatus`, `BodyCategory`, `BodyCategoryOrder`, `MemberNo`, `MemberClaimed`, `NoDelegates`, `NoEnvoys`, `NoVisitors`, `NoObservers` FROM `ab_bodies` ORDER BY `BodyCategoryOrder`, `BodyNameAscii`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $body = array(); while( $row = mysql_fetch_array($res) ) { $body[ $row['BodyCode'] ] = getParticipantNum($row); $body[ $row['BodyCode'] ]['NoFixed'] = $body[ $row['BodyCode'] ]['NoDelegates'] + $body[ $row['BodyCode'] ]['NoEnvoys'] + $body[ $row['BodyCode'] ]['NoObservers']; if( $row['BodyCategoryOrder']==7 ) { if( $setup['UseFixedPlaces'] ) $body[ $row['BodyCode'] ]['FixedSelector'] = $body[ $row['BodyCode'] ]['NoFixed'] + $setup['SelectionFixedPlaces']; else $body[ $row['BodyCode'] ]['FixedSelector'] = $setup['SelectionFixedPlaces']; } $body[ $row['BodyCode'] ]['BodyName'] = $row['BodyName']; $body[ $row['BodyCode'] ]['BodyStatus'] = $row['BodyStatus']; $body[ $row['BodyCode'] ]['BodyCategory'] = $row['BodyCategory']; $body[ $row['BodyCode'] ]['BodyCategoryOrder'] = $row['BodyCategoryOrder']; if( $row['MemberClaimed']>0 ) $body[ $row['BodyCode'] ]['MemberNo'] = $row['MemberClaimed']; elseif( $row['MemberNo']>0 ) $body[ $row['BodyCode'] ]['MemberNo'] = floor($row['MemberNo']*(1-($setup['LowerNotClaimed']/100))); else $body[ $row['BodyCode'] ]['MemberNo'] = 0; $body[ $row['BodyCode'] ]['Accepted']['delegate'] = 0; $body[ $row['BodyCode'] ]['Accepted']['envoy'] = 0; $body[ $row['BodyCode'] ]['Accepted']['visitor'] = 0; $body[ $row['BodyCode'] ]['Accepted']['observer'] = 0; $body[ $row['BodyCode'] ]['Accepted']['-'] = 0; $body[ $row['BodyCode'] ]['Waiting']['delegate'] = 0; $body[ $row['BodyCode'] ]['Waiting']['envoy'] = 0; $body[ $row['BodyCode'] ]['Waiting']['visitor'] = 0; $body[ $row['BodyCode'] ]['Waiting']['observer'] = 0; $body[ $row['BodyCode'] ]['Places'] = 0; if( ($setup['MaxPlacesPercentageOfMembers']/100*$body[ $row['BodyCode'] ]['MemberNo'])<$setup['MaxPlacesPerLocal'] ) $body[ $row['BodyCode'] ]['MaxPlaces'] = round($setup['MaxPlacesPerLocal']); else $body[ $row['BodyCode'] ]['MaxPlaces'] = round($setup['MaxPlacesPercentageOfMembers']/100*$body[ $row['BodyCode'] ]['MemberNo']); } // Now we have the bodies, check their number of accepted and waiting list people $query="SELECT COUNT(`PersonID`) as `num`, `BodyCode`, `Accepted`, `ParticipantType` FROM `persons` GROUP BY `BodyCode`, `Accepted`, `ParticipantType`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_array($res) ) { if( $row['Accepted']=='yes' OR $row['Accepted']=='arrived' OR $row['Accepted']=='pending' OR $row['Accepted']=='confirmed' ) $body[ $row['BodyCode'] ]['Accepted'][ $row['ParticipantType'] ] = $row['num']; elseif( $row['Accepted']=="-" ) $body[ $row['BodyCode'] ]['Waiting'][ $row['ParticipantType'] ] = $row['num']; } $acc = array_keys($body); // Find the total for waiting list and accepted list. Remove locals from the list that don't have waiting people $totalaccepted = 0; $totalwaiting = 0; $totaltoaccept = 0; $locals = array(); for( $i=0; $i=$body[ $acc[$i] ]['MaxPlaces'] ) { // Nobody on waiting list, or already maximum accepted, don't handle this body unset($body[ $acc[$i] ]); }else { if( $body[ $acc[$i] ]['BodyCategoryOrder']==7 ) $locals[] = $acc[$i]; } } // ### Ok, we have all information gathered! ### // Calculate the places per body we can divide $acc = array_keys($body); if( get_sql_date($setup['SelectFromDate'])==date("Y-m-d") OR $totalaccepted<50 ) { // This is the first day we do auto selection. All delegates, envoys and observers are accepted for sure, including fixed visitor places $out.="First day of running autoselect, all delegates, envoys and observers will be selected now.\n"; for( $i=0; $i 0 ) { $out.="Places left: ".($setup['TotalPlaces'] - $totalaccepted - $totaltoaccept)."\n"; $out.="Potential to divide: ".$totalpotential."\n"; $out.="Multiply by: ".(($setup['TotalPlaces'] - $totalaccepted - $totaltoaccept) / $totalpotential)."\n"; $remain = array(); $multiplier = ($setup['TotalPlaces'] - $totalaccepted - $totaltoaccept) / $totalpotential; for( $i=0; $i$body[ $acc[$i] ]['MaxPlaces'] ) { $body[ $acc[$i] ]['Places'] = $body[ $acc[$i] ]['MaxPlaces'] - $body[ $acc[$i] ]['Accepted']['total']; $remain[ $acc[$i] ]=NULL; } } // divide remaining places arsort($remain); $key = array_keys($remain); for( $i=0; $i0 ) { $body[ $key[$i] ]['Places']++; $totaltoaccept++; } } }else { $out.="Nothing potential left to divide!\n"; $out.="Places left: ".($setup['TotalPlaces'] - $totalaccepted - $totaltoaccept)."\n"; $out.="Potential to divide: ".$totalpotential."\n"; } } // Ok, we know the numbers, now really accept some asses $acc = array_keys($body); for( $i=0; $i0 ) { if( !(get_sql_date($setup['SelectFromDate'])==date("Y-m-d") OR $totalaccepted<50) AND $setup['ShowParticipantList']) { // This is not the first day selection is running, and the participants list is already published. Maybe it is nice to inform the person as well // Select already now the people that will be accepted, after accepting we cannot find them back any more $query = "SELECT `PersonID`, `FirstName`, `LastName`, `Email`, `ParticipantType` FROM `persons` WHERE `BodyCode`='".addslashes($acc[$i])."' AND `Accepted`='-' AND `ParticipantType`!='-' AND `MemberlistConfirmed`='yes' ORDER BY `ParticipantType`, `ParticipantOrder` LIMIT ".addslashes($body[ $acc[$i] ]['Places']); $res = doquery($query); } $query = "UPDATE `persons` SET `Accepted`='yes', `Log`=CONCAT(`Log`,'\n".date("Y-m-d H:i:s").": set accepted status to yes by rundaily (mass accepter)') WHERE `BodyCode`='".addslashes($acc[$i])."' AND `Accepted`='-' AND `ParticipantType`!='-' ORDER BY `ParticipantType`, `ParticipantOrder` LIMIT ".addslashes($body[ $acc[$i] ]['Places']); if( doquery($query) ) { $out.="Accepted ".getaffected()." people from ".$body[ $acc[$i] ]['BodyName']."\n"; if( !(get_sql_date($setup['SelectFromDate'])==date("Y-m-d") OR $totalaccepted<50) AND $setup['ShowParticipantList']) { // This is not the first day selection is running, and the participants list is already published. Maybe it is nice to inform the person as well while( $row = mysql_fetch_array($res) ) { $mail = new Mail($setup['MailReturnpath'], $row['Email']); $mail->setSubject(Mail::encodeHeader("Selection result for ".$setup['EventSubject'])); $mail->addHeader("To", "\"".Mail::encodeHeader($row['FirstName']." ".$row['LastName'])."\" <".$row['Email'].">"); $mail->addHeader("From", "\"".$setup['SetupEventType']." Application Mailer\" <".$setup['EventApplFromEmail'].">"); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "accepted to participant"); $mail->addHeader("X-ApplicationID", $row['PersonID']); $mail->addHeader("X-Signature", get_signature("accepted to participant", $row['PersonID'])); $msg = "Hi ".$row['FirstName'].",\n\n"; $msg .= "We are happy to inform you that you have been *accepted* as participant for ".$setup['EventSubject'].", taking place from ".$setup['EventDateStart']." until ".$setup['EventDateEnd'].".\n\n"; $msg .= "Please start booking your tickets now. If you log in to the applications page, you can fill in your real arrival and departure time. This will help the organizers a lot.\n\n"; $msg .= "If for any reason you are not able to come, please cancel your application via the applications website. You can cancel your application by logging in with your ".$ldap->getSystemName()." account. If this fails, please contact the organizers to cancel your application. Other people will be happy to take your place if you cannot come. Next to that, if you don't arrive at the registration desk of this event, your local might receive less places for next statutory events.\n\n"; $msg .= "You can find the applications page, including the full participants list at\n\n"; $msg .= "\thttp://".$FULL_URL."\n\n"; $msg .= "See you at the ".$setup['SetupEventType']."!\n\n"; $msg .= "Greetings,\n\n"; $msg .= "The webmaster\n"; $mail->setMessage($msg); $mail->send(true); } } }else { $out.="Failed accepting ".$body[ $acc[$i] ]['Places']." people from ".$body[ $acc[$i] ]['BodyName']."\n"; } } } ############################### #echo "
"; #$acc = array_keys($body); #echo "

Total places: ".$setup['TotalPlaces']; #echo "
Total accepted: ".$totalaccepted; #echo "
Total waiting: ".$totalwaiting; #echo "
Total to accept: ".$totaltoaccept; #echo "
SelectionExponentialPlaces: ".$setup['SelectionExponentialPlaces']; #echo "
SelectionFixedPlaces: ".$setup['SelectionFixedPlaces']; #echo "
UseFixedPlaces: ".$setup['UseFixedPlaces']; #echo "
SelectFromDate: ".$setup['SelectFromDate']; #echo "

All locals that will receive places in this run:"; #echo "
"; #$h = array(); #for( $i=0; $i"; # if( $b['Places'] < $b['Waiting']['total'] AND $b['BodyCategoryOrder']==7 ) $h[ $acc[$i] ]=$b['MemberNo']; #} #echo "
codeBodycategoryMembersPlaceswait delegatewait envoywait observwait visit
".$acc[$i]."".substr($b['BodyName'], 0, 20)."".$b['BodyCategory']."".$b['MemberNo']."".$b['Places']." / ".$b['Waiting']['total']."".$b['Waiting']['delegate']."".$b['Waiting']['envoy']."".$b['Waiting']['observer']."".$b['Waiting']['visitor']."
"; #echo "

Locals only, that do not get as many places as they have applications, ordered by number of members we use for the calculation (lowered in case not filled in)"; #echo "
"; #asort($h); #$hk = array_keys($h); #for( $i=0; $i"; #} #echo "
codeBodycategoryMembersPlaceswait delegatewait envoywait observwait visit
".$hk[$i]."".substr($b['BodyName'], 0, 20)."".$b['BodyCategory']." (".$b['BodyStatus'].")".$b['MemberNo']."".$b['Places']." / ".$b['Waiting']['total']."".$b['Waiting']['delegate']."".$b['Waiting']['envoy']."".$b['Waiting']['observer']."".$b['Waiting']['visitor']."
"; #echo "

Body:".nl2br(strtr(print_r($body, true), array(" " => " ")))."

"; }else { $out.="Failed loading current participant numbers\n"; } }else { $out.="Failed loading body data\n"; } } } if( $setup['SetupWSNumber']>0 AND $setup['WorkshopSelectFirstChoice']=="yes" ) { $out.="\n\n=== Doing auto selection of participants for their first workshop choice ===\n"; $query = "UPDATE `persons` SET `WorkshopIDSlot1`=`WorkshopID1`, `WorkshopIDSlot2`=`WorkshopID3` WHERE `WorkshopIDSlot1`<1 AND `WorkshopIDSlot2`<1 AND (`Accepted`='yes' OR `Accepted`='pending' OR `Accepted`='confirmed')"; if( doquery($query) ) { $out .= "Selected ".getaffected()." people for their first workshop choice.\n"; }else { $out .= "Failed selecting people for their first workshop choice.\n"; } } } } function selectplaces($body, $run=0) { global $setup; if( $run<1 ) $run = 1; if( $body['Waiting']['total'] <= $body['Places'] ) return 0; if( $body['BodyCategoryOrder']==7 ) { // Local if( $run == 1 ) return max(0, (pow($body['MemberNo'],($setup['SelectionExponentialPlaces']/100))+$body['FixedSelector']) - ($body['Places'] + $body['Accepted']['total'])); else return max(0, ($run * pow($body['MemberNo']+1,($setup['SelectionExponentialPlaces']/100))+$body['FixedSelector']) - ($body['Places'] + $body['Accepted']['total'])); }else { // Non-local return max(0, $body['NoFixed'] - ($body['Places'] + $body['Accepted']['total'])); } } ?>