PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/leaveteam.php

https://bitbucket.org/verax/to-ladder
PHP | 126 lines | 101 code | 18 blank | 7 comment | 11 complexity | f23923fd1892425ac5e08e41289020e6 MD5 | raw file
  1. <?
  2. function leave_team($teamid){
  3. global $dir, $file, $url, $out, $plyr, $misc;
  4. if(!$teamid){
  5. include("$dir[func]/error.php");
  6. display_error("Invalid Team ID.<br>");
  7. }
  8. $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
  9. $tinfo=mysql_fetch_array($teaminfo);
  10. if(!$tinfo[teamname]){
  11. include("$dir[func]/error.php");
  12. display_error("Unknown Team ID.<br>");
  13. }
  14. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid='$plyr[id]'")) < 1){
  15. include("$dir[func]/error.php");
  16. display_error("You are not on this team.<br>");
  17. }
  18. //CHECK IF OTHER MEMBERS EXIST
  19. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid!='$plyr[id]'")) < 1){
  20. if($misc[deleteteam]=="yes"){
  21. //NO OTHER MEMBERS - TEAM WILL BE DELETED
  22. $leavemessage="There are no other members on this team.<br>
  23. If you leave the team it will be deleted.<br>
  24. Click the button below to delete this team.<br>";
  25. $buttonsay="<input type='submit' name='' value='Delete this Team'>";
  26. }else{
  27. //NO OTHER MEMBERS - CANNOT DELETE TEAM
  28. $leavemessage="You cannot leave this team.<br>
  29. There are no other members and deleting of teams is not permitted.<br>";
  30. $buttonsay="";
  31. }
  32. }else{
  33. //CHECK IF LEADER WILL EXIST
  34. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid!='$plyr[id]' AND status='1'")) < 1){
  35. include("$dir[func]/error.php");
  36. display_error("This team must have a leader.<br>");
  37. }
  38. //JUST DELETING TEAM MEMBER
  39. $leavemessage="Click the button below to confirm you wish to leave this team.<br>";
  40. $buttonsay="<input type='submit' name='' value='Leave this Team'>";
  41. }
  42. $tablehead=table_head("show","500","","left");
  43. $tablefoot=table_foot("show");
  44. $bannerhead=table_head("show","488","80","center");
  45. $bannerfoot=table_foot("show");
  46. $out[body]=$out[body]."
  47. <center>
  48. $bannerhead
  49. $out[banner]
  50. $bannerfoot
  51. <br>
  52. $tablehead
  53. <center>
  54. <font class='catfont'><strong>Leave Team $tinfo[teamname]</strong></font><br>
  55. <br>
  56. $leavemessage
  57. <br>
  58. <form method='post'>
  59. <input type='hidden' name='teamid' value='$teamid'>
  60. <input type='hidden' name='action' value='leaveb'>
  61. $buttonsay
  62. </center>
  63. $tablefoot
  64. </form>
  65. ";
  66. include("$dir[curtheme]");
  67. }
  68. function leave_teamb($teamid){
  69. global $dir, $file, $url, $out, $misc, $plyr;
  70. if(!$teamid){
  71. include("$dir[func]/error.php");
  72. display_error("Invalid Team ID.<br>");
  73. }
  74. $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
  75. $tinfo=mysql_fetch_array($teaminfo);
  76. if(!$tinfo[teamname]){
  77. include("$dir[func]/error.php");
  78. display_error("Unknown Team ID.<br>");
  79. }
  80. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid='$plyr[id]'")) < 1){
  81. include("$dir[func]/error.php");
  82. display_error("You are not on this team.<br>");
  83. }
  84. //CHECK IF OTHER MEMBERS EXIST
  85. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid!='$plyr[id]'")) < 1){
  86. delete_team($teamid);
  87. }else{
  88. //CHECK IF LEADER WILL EXIST
  89. if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid!='$plyr[id]' AND status='1'")) < 1){
  90. include("$dir[func]/error.php");
  91. display_error("This team must have a leader.<br>");
  92. }
  93. delete_member($teamid);
  94. }
  95. }
  96. function delete_member($teamid){
  97. global $dir, $plyr, $site;
  98. mysql_query("DELETE FROM teammembers WHERE teamid='$teamid' AND playerid='$plyr[id]'");
  99. include("$dir[func]/finishmessage.php");
  100. display_message("You have been removed from this team",$site[home]);
  101. }
  102. function delete_team($teamid){
  103. global $dir;
  104. mysql_query("DELETE FROM teammembers WHERE teamid='$teamid'");
  105. include("$dir[func]/finishmessage.php");
  106. display_message("Your team has been deleted","phome");
  107. }
  108. ?>