to-ladder /functions/invitemember.php

Language PHP Lines 253
MD5 Hash baf990780fc5f5b645c50fe093f5eb8f Estimated Cost $4,907 (why?)
Repository https://bitbucket.org/verax/to-ladder.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?
function invite_member($teamid){
    global $dir, $file, $url, $out, $plyr, $site;
    if(!$teamid){
        include("$dir[func]/error.php");
        display_error("Invalid Team ID.<br>");
    }

    //CHECK IF LEADER
    if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid='$plyr[id]' AND status <='2'")) < 1){
        include("$dir[func]/error.php");
        display_error("You are not allowed to invite members to this team.<br>");
    }

    $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
    $tinfo=mysql_fetch_array($teaminfo);
    if(!$tinfo[teamname]){
        include("$dir[func]/error.php");
        display_error("Unknown Team.<br>");
    }

    $ladders=mysql_query("SELECT id,laddername,maxmembers FROM ladders");
    while($row = mysql_fetch_array($ladders)){
        $teams=mysql_query("SELECT id FROM ladder_$row[id] WHERE id='$teamid'");
        if(mysql_fetch_array($teams)){
            if (mysql_num_rows(mysql_query("SELECT playerid FROM teammembers WHERE teamid='$teamid'")) >= $row[maxmembers]){
                include("$dir[func]/error.php");
                display_error("Your team has the maximum allowed team members<br> on the $row[laddername] ladder. <br><br> No new members can be added to your team.");
            }

        }

    }

    $tablehead=table_head("show","300","","left");
    $tablefoot=table_foot("show");
    $bannerhead=table_head("show","488","80","center");
    $bannerfoot=table_foot("show");
    $out[body]=$out[body]."
    <center>
    $bannerhead
    $out[banner]
    $bannerfoot
    <br>
    $tablehead
    &nbsp; &nbsp;<strong><font class='catfont'>Invite a Member to $tinfo[teamname]</font></strong><br>
    <hr class='catfont' size='1'>
    <table width='300' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
    <form method='post'>
    <tr>
    <td width='100%' height='100%' valign='top' align='center'>
    Member Id: <input type='text' name='inviteid' value='' size='25' maxlength='15'>
    <input type='hidden' name='teamid' value='$teamid'>
    <input type='hidden' name='action' value='inviteb'>
    <br><br>
    <input type='submit' name='' value='Invite Player'>
    </td>
    </tr>
    </form>
    </table>
    $tablefoot
    </center>";
    include("$dir[curtheme]");
}

function invite_memberb($teamid,$inviteid){
    global $dir, $file, $url, $out, $plyr, $site;
    if(!$teamid){
        include("$dir[func]/error.php");
        display_error("Invalid Team ID.<br>");
    }

    if(!$inviteid){
        include("$dir[func]/error.php");
        display_error("Invalid Invited Player ID.<br>");
    }

    if($inviteid=="$plyr[id]"){
        include("$dir[func]/error.php");
        display_error("You cannot invite yourself.<br>");
    }

    //CHECK IF LEADER
    if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$teamid' AND playerid='$plyr[id]' AND status <='2'")) < 1){
        include("$dir[func]/error.php");
        display_error("You are not allowed to invite players to this team.<br>");
    }

    $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
    $tinfo=mysql_fetch_array($teaminfo);
    if(!$tinfo[teamname]){
        include("$dir[func]/error.php");
        display_error("Unknown Team.<br>");
    }

    //CHECK IF MAX MEMBERS EXISTS
    $ladders=mysql_query("SELECT id,laddername,maxmembers FROM ladders");
    while($row = mysql_fetch_array($ladders)){
        $teams=mysql_query("SELECT id FROM ladder_$row[id] WHERE id='$teamid'");
        if(mysql_fetch_array($teams)){
            if (mysql_num_rows(mysql_query("SELECT playerid FROM teammembers WHERE teamid='$teamid'")) >= $row[maxmembers]){
                include("$dir[func]/error.php");
                display_error("Your team has the maximum allowed team members<br> on the $row[laddername] ladder. <br><br> No new members can be added to your team.");
            }

        }

    }

    // CHECK INVITED PLAYER INFO
    $invitedinfo=mysql_query("SELECT alias,email FROM users WHERE id='$inviteid'");
    $iinfo=mysql_fetch_array($invitedinfo);
    if(!$iinfo[alias]){
        include("$dir[func]/error.php");
        display_error("Unknown Player.<br>");
    }

    //CHECK IF ON TEAM
    if (mysql_num_rows(mysql_query("SELECT playerid FROM teammembers WHERE teamid='$teamid' AND playerid='$inviteid'")) > 0){
        include("$dir[func]/error.php");
        display_error("This Player is already on your team.<br>");
    }

    $ladders=mysql_query("SELECT id,laddername FROM ladders");
    while($row = mysql_fetch_array($ladders)){
        $teams=mysql_query("SELECT id FROM ladder_$row[id] WHERE id='$teamid'");
        if(mysql_fetch_array($teams)){
            $teamson = mysql_query("SELECT teamid FROM teammembers WHERE playerid='$inviteid'");
            while($teamslist = mysql_fetch_array($teamson)){
                $check=mysql_query("SELECT id FROM ladder_$row[id] WHERE id='$teamslist[teamid]'");
                if(mysql_fetch_array($check)){
                    include("$dir[func]/error.php");
                    display_error("This Player is already on a ladder (<a href='$url[base]/$file[ladder]?ladderid=$row[id]'>$row[laddername]</a>)<br> that your team is on. <br><br> Players cannot be on the same ladder more than once.<br>");
                }

            }

        }

    }

    //CHECK IF ALREADY INVITED
    if (mysql_num_rows(mysql_query("SELECT playerid FROM teammembersinv WHERE teamid='$teamid' AND playerid='$inviteid'")) > 0){
        include("$dir[func]/error.php");
        display_error("This Player ($iinfo[alias]) is already invited to your team.<br>They have 7 days to accept before the invitation expires.<br>");
    }

   //DO MEMBER INVITE 

	$tday=date("Y-m-d H:i:s");
	mysql_query("INSERT INTO teammembersinv VALUES (

	'$teamid',
	'$inviteid',
	'$plyr[id]',
	'$tday');");

	$tablehead=table_head("show","500","","left");
	$tablefoot=table_foot("show");

	$bannerhead=table_head("show","488","80","center");
	$bannerfoot=table_foot("show");

	$out[body]=$out[body]."
	<center>
	$bannerhead
	$out[banner]
	$bannerfoot



	<br>
	$tablehead
	<center>
	<font class='catfont'><strong>Member Invited</strong></font>
	<br>

	<br>
	$iinfo[alias] has been sent an email inviting them to your team. <br>They have 7 days to respond before the invite expires.<br>
	<br>
	</center>
	$tablefoot
	</center>";
	include("$dir[curtheme]");


	//Email Invited Player

	$emailbody="$iinfo[alias],
	You have been invited to join a team on $site[shortname]! \n
	Team Name: $tinfo[teamname]
	Ladder Name: $linfo[laddername]
	Team Stats: $url[base]/$file[teams]?teamid=$teamid \n
	If you wish to join this team, please click here: $url[base]/$file[teams]?teamid=$teamid?inviteid=$plyr[id]\n
	You may also join at any time within the next 7 days via your Player Manager.
	";


	include("$dir[func]/email.php");
	send_email($iinfo[alias], $iinfo[email], "Team Addition", $emailbody);
}

    function accept_invite($teamid,$inviteid){
        global $dir, $file, $url, $out, $plyr, $site;
        $tday=date("Y-m-d H:i:s");
        $datech = mysql_query("SELECT invitedate FROM teammembersinv WHERE teamid='$teamid' AND playerid='$inviteid'");
        $checkd=mysql_fetch_array($datech);

        /*
        if($tday > ($checkd[invitedate]-$expiry)){
            mysql_query("DELETE FROM teammembersinv WHERE teamid='$teamid' AND playerid='$inviteid'");
        }
        */

        $accinfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
        $ainfo=mysql_fetch_array($accinfo);
        if (mysql_num_rows(mysql_query("SELECT playerid FROM teammembersinv WHERE teamid='$teamid' AND playerid='$inviteid'")) > 0){
            mysql_query("INSERT INTO teammembers VALUES (
            '$teamid',
            '$inviteid',
            '5',
            '$tday');");
            mysql_query("DELETE FROM teammembersinv WHERE teamid='$teamid' AND playerid='$inviteid'");
            $tablehead=table_head("show","500","","left");
            $tablefoot=table_foot("show");
            $bannerhead=table_head("show","488","80","center");
            $bannerfoot=table_foot("show");
            $out[body]=$out[body]."
            <center>
            $bannerhead
            $out[banner]
            $bannerfoot
            <br>
            $tablehead
            <center>
            <font class='catfont'><strong>Member Added</strong></font>
            <br>
            <br>
            You have been successfully added to the team, $ainfo[teamname].
            <br>
            </center>
            $tablefoot
            </center>";
            include("$dir[curtheme]");
        }

        else{
            include("$dir[func]/error.php");
            display_error("This Invite does not exist or has expired.<br>You will need to have your team invite you again.<br>");
        }

    }
?>
Back to Top