modification for 0.7.9 that keeps resting players in the ladder
Hi Matt and everyone. We have been using 0.7.9 for our local club tennis ladder. Although this modification will probably not be compatible with 0.8.2, I am posting the modification that I made in case anyone wants to use it.
What this modification does:
When a player chooses to rest from the ladder, instead of dropping out, they remain in the ladder. They immediately give up one rung by going on rest, switching places with the player below them (if there is one). A bolded blue 'r' appears by their name on the rankings much like the red 'c' for players under challenge. They cannot be challenged. When they return to the ladder the 'r' disappears. (In our club the administrator also will demote players another rung for every two weeks of rest, but this is done in MYSQL. It would be pretty easy to make this automated if anyone wanted to do it, but with the size of our ladder it is easier to do it manually)
BEFORE INSTALLING BACK EVERYTHING UP!!!!!!!!!
I tried to record the changes as I made them, but I may have made a mistake.
The basic operating principle is that instead of designating the rest state with a '0' for player position, the mod changes the challenge flag of resting players to '5'.
HERE IT IS:
----------------------------------------
BEFORE INSTALLING USE A TEXT EDITOR TO FIND AND CHANGE THE <* AND *> TO REGULAR HTML
----------------------------------------
//changes to break.php
//old 35
<*p class="pagetext"*>This means that you will remain on the system
as a 'resting' player. <*br*>
You can rejoin the ladder later at any time but when you rejoin<*br*>
you will be placed at the bottom of the ladder.<*/p*>
//new 35
<*p class="pagetext"*>You will remain on the ladder as a resting player, and you will be immune from challenges. <*b*>However, you will immediately lose one rank.<*/b*> And for every two weeks of cumulative rest, you will drop another position.<*/p*>
----------------------------------------
//changes to break2.php
//old 55
if (!rejiggle($_SESSION[valid_user], "break",''))
//new 55
if (!set_rest($_SESSION[valid_user]))
----------------------------------------
//changes to functions.php
//ADD THIS FUNCTION AT THE END BEFORE THE FINAL ?*>
/************************************************************************/
/* set rest function*/
/************************************************************************/
function set_rest($email){
global $clubprefix;
global $full_path;
$user=get_player('', $email, '');
$mychall = $user[chall_flag];
$currchall= $user[chall_dat];
$myID = $user[ID];
// If you are under challenge that challenge needs to be cancelled or forfeited
if ($mychall==1)
{
// Find the open challenge
$challid=get_challID($email, '', '');
// Get the challenge deatils from that challenge ID
$chall_detail=get_chall_detail($challid, $clubprefix);
$cle_id=$chall_detail[cle_id];
$ch_t=$chall_detail[ct];
//////////////////////////////////////////////////////////////////////////////////////////
if ($chall_detail[clr_id]== $myID)
{
// I'm the challenger so therefore just cancel challenge
$cle_id=$chall_detail[cle_id];
// Email the challenger/challengee to inform them challenge cancelled
$errors = mailer("11", $challid, $clubprefix, '');
//set the challenger and challengee's flags and dates to 0
$result = mysql_query( "update `$clubprefix"."_player`
set chall_flag = '5', chall_dat =''
where ID = '$myID'");
$result = mysql_query( "update `$clubprefix"."_player`
set chall_flag = '0', chall_dat =''
where `ID` = '$cle_id'");
// Need to delete challenge in challenge table
$result = mysql_query("DELETE FROM `$clubprefix"."_challenges` WHERE `time` = '$ch_t' AND `ChallengerID` = '$myID' AND `ChallengeeID` = '$cle_id'");
// Need to set the $count as $pos as I'm the one that gets moved.
$count=$pos;
}
//////////////////////////////////////////////////////////////////////////////////////////
elseif ($chall_detail[cle_id] == $myID)
{
// I'm the challnegee therefore I have to forfeit the match NB. Chall flags reset to 0 in the forefiet function
$_SESSION[msg_tit]='Challenge forfeited';
$_SESSION[msg_bod]= 'You have forfeited your exiting open challenge by taking a break from the ladder and therefore lost the match. An email has been sent to the person you challenged to inform them of this. Your positions on the ladder have swapped. You are both now free to make further challenges.';
$errors = mailer("7", $challid, $clubprefix, '');
forfeit($ch_t, $chall_detail[clr_id], $chall_detail[cle_id], $chall_detail[clr_pos], $chall_detail[cle_pos], '');
// Need to set the $count as the postion (for taking a break from the ladder). NB. This could be after a swap or a shuffle type outcome hence need to check position again.
$user=get_player('', $email, '');
$count=$user[Position];
}
else
{
echo 'error';
return false;
}
// NOT under challenge so just get out
}
//set resting player challenge flag
$result = mysql_query( "update `$clubprefix"."_player`
set chall_flag = '5', chall_dat =''
where ID = '$myID'");
//get current user position
$count=$user[Position];
//get lowest position called $bottom_pos
$qres = mysql_query("SELECT * FROM `$clubprefix"."_player` ORDER BY `Position` DESC LIMIT 0, 1");
$row = mysql_fetch_array ($qres, MYSQL_ASSOC);
$bottom_pos = $row[Position];
//if user is not bottom then switch down one
if ($count!==$bottom_pos){
$demot_pos = $count + 1;
//elevate player below
$qres = mysql_query("SELECT * FROM `$clubprefix"."_player` WHERE Position='$demot_pos'");
$row = mysql_fetch_array ($qres, MYSQL_ASSOC);
$nextemail = $row[Email];
$result = mysql_query( "update `$clubprefix"."_player`
set Position = '$count'
where Email = '$nextemail' ");
//demote resting player
$qres = mysql_query("SELECT * FROM `$clubprefix"."_player` WHERE ID='$myID'");
$result = mysql_query( "update `$clubprefix"."_player`
set Position = '$demot_pos'
where ID = '$myID' ");
}
return true;
}
------------------------------------------
//changes to player_inf.php
//137 ADD following
$mychall = $player[chall_flag];
if ($mychall == 5){
echo '<*strong*><*br*>'.$title.' is taking a break from the ladder.<*/strong*>';
}
------------------------------------------
//changes to rankings.php
//old 91
if ($pos==0)
//new 91
if ($mychall==5)
//old 128
<*td class="pageheading"*><*p align="left" class="pagetext"*> A <*font color="#FF0000"*><*strong*>c<*/strong*><*/font*> by a player's name indicates they are currently under challenge and you can't therefore challenge them.<*br*><*br*>Click on the rank number to view individual stats and learn who is challenging whom.<*/p*>
//new 128
<*td class="pageheading"*><*p align="left" class="pagetext"*> A <*font color="#FF0000"*><*strong*>c<*/strong*><*/font*> or <*font color="#00FF00"*><*strong*>r<*/strong*><*/font*> by a player's name indicates they are currently under challenge or resting and you can't therefore challenge them.<*br*><*br*>Click on the rank number to view individual stats and learn who is challenging whom.<*/p*>
------------------------------------------
//changes to rank.php
after 73 and similarly at or around lines 120 and 150 and 188
<*font color="blue"*><*strong*>
<*?
if ($row[chall_flag]==5) echo 'r'; ?*>
<*/strong*><*/font*>
------------------------------------------
//changes to useradmin.php
//old 69
if ($row[Position] != 0)
//new
if ($row[chall_flag] != 5)
------------------------------------------
//changes to rejoin.php
replace between the divs with the following
<*div align="center" class="pageheading"*>
<*p*>You have rejoined the ladder<*/p*><*?
//check not refreshed and pos still 0
$qres = mysql_query("select * from `$clubprefix"."_player` where Email='$_SESSION[valid_user]'");
$row = mysql_fetch_array ($qres, MYSQL_ASSOC);
$chall_flag=$row[chall_flag];
if ($row[chall_flag] == 5)
{
//reset chall flag
//set resting player challenge flag
$result = mysql_query( "update `$clubprefix"."_player`
set chall_flag = '0', chall_dat =''
where Email='$_SESSION[valid_user]'");
}?*>
<*/div*>
If you run into problems you can email me at wetzel @ wisebridgelearning . com

Thanks
Nice piece of work wetzel.
Thanks!
Matt