2009-09-09 02:38:57 +00:00
< ?
function db_update_131_pre ()
{
global $config ;
$year = $config [ 'FAIRYEAR' ];
//since there's only ever been award sponsors in the system, we can
//add a sponsorship entry with a value of the total sum of the prizes given
//for each sponsor
2024-12-12 21:24:45 +00:00
$q = $pdo -> prepare ( " SELECT * FROM sponsors " );
$q -> execute ();
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
2009-09-09 02:38:57 +00:00
$total = 0 ;
2024-12-12 21:24:45 +00:00
$awardq = $pdo -> prepare ( " SELECT * FROM award_awards WHERE sponsors_id=' $r->id ' AND year=' $year ' " );
$awardq -> execute ();
while ( $awardr = $awardq -> fetch ( PDO :: FETCH_OBJ )) {
$prizeq = $pdo -> prepare ( " SELECT cash,scholarship,value,number FROM award_prizes WHERE award_awards_id=' $awardr->id ' " );
$prizeq -> execute ();
while ( $prizer = $prizeq -> fetch ( PDO :: FETCH_OBJ )) {
2009-09-09 02:38:57 +00:00
//some people never set the value for some reason, i dunno why..
$realvalue = max ( $prizer -> cash + $prizer -> scholarship , $prizer -> value );
$totalvalue = $realvalue * $prizer -> number ;
$total += $totalvalue ;
}
}
echo " Creating sponsorship for ID: $r->id value: $total\n " ;
2024-12-12 21:24:45 +00:00
$pdo -> prepare ( " INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES (
2009-09-09 02:38:57 +00:00
'$r->id' ,
2009-10-22 16:46:32 +00:00
'sfawards' ,
2009-09-09 02:38:57 +00:00
'$total' ,
'pending' ,
'25' ,
'$year' ) " );
2024-12-12 21:24:45 +00:00
$pdo -> execute ( 0 ;)
$stmt = $pdo -> prepare ( " INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES (' $r->id ',NOW(),0,'Automatically created sponsorship from existing sponsor. type=award, value= \$ $total , status=pending, probability=25%') " );
$stmt -> execute ();
2009-09-09 02:38:57 +00:00
}
}
?>