function activate_registration() { global $registrantid; global $SEASON; $playerExists = true; //We will asume true to avoid any accidental duplicate insertion global $Link; #See if player already exists. Do not wanna any duplicates. $playerExistsCheckSQL = 'SELECT playerID FROM ' . PLAYER . ' WHERE registrationId=' . $registrantid . ' AND seasonId=' . $SEASON; $playerExistsCheckResult = mysql_query($playerExistsCheckSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); if ($playerExistsCheckResult) { if (mysql_num_rows($playerExistsCheckResult) > 0) { $playerExists = true; } else { $playerExists = false; } } else { //Error selecting from database } #Create new player if (!$playerExists) { $newPlayerSQL = 'SELECT fName, lName, skillLevel, paymentPlan FROM ' . REGISTRATION . ' WHERE registrationId=' . $registrantid; $newPlayerResult = mysql_query($newPlayerSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); if ($newPlayerResult) { if (mysql_num_rows($newPlayerResult) > 0) { $newPlayer = mysql_fetch_assoc($newPlayerResult); $newPlayerFName = $newPlayer['fName']; $newPlayerLName = $newPlayer['lName']; $newPlayerSkillLevel = $newPlayer['skillLevel']; $newPlayerPaymentPlan = $newPlayer['paymentPlan']; $createPlayerColumns = '`playerFName`,`playerLName`,`playerSkillLevel`,`registrationId`,`seasonId`'; $createPlayerSQL = 'INSERT INTO ' . PLAYER . ' (' . $createPlayerColumns . ') '; $createPlayerSQL .= 'VALUES("' . $newPlayerFName . '",'; $createPlayerSQL .= '"' . $newPlayerLName . '",'; $createPlayerSQL .= '' . $newPlayerSkillLevel . ','; $createPlayerSQL .= '' . $registrantid . ','; $createPlayerSQL .= '' . $SEASON; $createPlayerSQL .= ')'; $createPlayerResult = mysql_query($createPlayerSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); #If new player was created we want to set the playerId for that registrant in registration table. if ($createPlayerResult) { $playerId = mysql_insert_id(); $setPlayerIdSQL = 'UPDATE ' . REGISTRATION . ' SET playerId=' . $playerId . ', registrationApproved=1 WHERE registrationId=' . $registrantid; $setPlayerIdResult = mysql_query($setPlayerIdSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); // Insert player into payment table insert_player_into_payment_table($registrantid, $newPlayerPaymentPlan); } } } } }
function activate_former_registration() { global $registrantid; global $playerid; global $SEASON; $playerExists = true; //We will asume true to avoid any accidental duplicate insertion global $Link; #See if player already exists. Do not wanna any duplicates. $playerExistsCheckSQL = 'SELECT playerID FROM ' . PLAYER . ' WHERE registrationId=' . $registrantid . ' AND seasonId=' . $SEASON; $playerExistsCheckResult = mysql_query($playerExistsCheckSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); if ($playerExistsCheckResult) { if (mysql_num_rows($playerExistsCheckResult) > 0) { $playerExists = true; } else { $playerExists = false; } } else { //Error selecting from database } #Create new player if (!$playerExists) { //$updatePlayerSQL = 'UPDATE '.PLAYER.' SET registrationId='.$registrantid.', seasonId='.$SEASON.' WHERE playerID='.$playerid; $updatePlayerSQL = 'SELECT skillLevel, paymentPlan FROM ' . REGISTRATION . ' WHERE registrationId=' . $registrantid; $updatePlayerResult = mysql_query($updatePlayerSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); if ($updatePlayerResult) { if (mysql_num_rows($updatePlayerResult) > 0) { $updatePlayer = mysql_fetch_assoc($updatePlayerResult); $updatePlayerSkillLevel = $updatePlayer['skillLevel']; $updatePlayerPaymentPlan = $updatePlayer['paymentPlan']; //$createPlayerColumns = '`playerFName`,`playerLName`,`playerSkillLevel`,`registrationId`,`seasonId`'; $updateFormerPlayerSQL = 'UPDATE ' . PLAYER . ' '; $updateFormerPlayerSQL .= 'SET playerSkillLevel=' . $updatePlayerSkillLevel . ','; $updateFormerPlayerSQL .= 'registrationId=' . $registrantid . ','; $updateFormerPlayerSQL .= 'seasonId=' . $SEASON; $updateFormerPlayerSQL .= ' WHERE playerID=' . $playerid; $updateFormerPlayerResult = mysql_query($updateFormerPlayerSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); #If new player was created we want to set the playerId for that registrant in registration table. if ($updateFormerPlayerResult) { $setPlayerIdSQL = 'UPDATE ' . REGISTRATION . ' SET playerId=' . $playerid . ', registrationApproved=1 WHERE registrationId=' . $registrantid; $setPlayerIdResult = mysql_query($setPlayerIdSQL, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error()); // Insert player into payment table insert_player_into_payment_table($registrantid, $updatePlayerPaymentPlan); } } } } $success = array(); $success[] = "Registration of former player approved successfully."; return $success; }