Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
rebelt
Worker
Worker


Joined: May 07, 2006
Posts: 172

PostPosted: Sun Jan 22, 2012 10:05 am Reply with quote

Have a script writen years ago and after upgrade I receive errors on this part.

Code:
   // Constructor

   //
   function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
   {

      $this->persistency = $persistency;
      $this->user = $sqluser;
      $this->password = $sqlpassword;
      $this->server = $sqlserver;
      $this->dbname = $database;

      if($this->persistency)
      {
         $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
      }
      else
      {
         $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
      }
      if($this->db_connect_id)
      {
         if($database != '')
         {
            $this->dbname = $database;
            $dbselect = @mysql_select_db($this->dbname);
            if(!$dbselect)
            {
               @mysql_close($this->db_connect_id);
               $this->db_connect_id = $dbselect;
            }
         }
         return $this->db_connect_id;
      }
      else
      {
         return false;
      }
   }


As well as
Code:
 mysql_free_result($result);

Quote:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in


Obviously it goes on with file and line.

Good job I only upgraded the test site. Smile

Full File
Code:
<?PHP

// includes the mainfile functions and the header junk
if (!isset($mainfile)) { include("mainfile.php"); }
define('INDEX_FILE', true);
### Main Page
### Main Page 
### Main Page

function mainpage() {
 include ('header.php');

maintheader();

echo "<center><B>This online service will be used to add and update Weston Pool League team names, members and venues.<br /> By registering with Weston Pool League, you acknowledge that the league, those who run it and members, are not responsible for access to any venue. <br />If you are new to this process, get started by creating your team using the first option below.<br /><h3>Please make sure the player is ONLY registered to play for your team.</h3><br /><h3><blink><B>Important!</b></blink><br/>DO NOT enter any team detail, until the notice appears on the fromt page telling you the database is ready.</h3></center>";

echo "<BR><table width=100%>";


   echo "<a href=\"?op=CreateTeam&step=Venue\">1. Create New Team</a><BR><BR>
   <a href=\"?op=ListVenues\">2. List All Venues</a><BR><BR>
   <a href=\"?op=ShowMyTeam\">3. Show My Team</a><BR><BR>
   <a href=\"?op=ListTeams\">4. List All Teams</a><BR><BR>";

echo "</table>";

maintfooter();

 mysql_free_result($result);
 include ('footer.php');
}

### List Teams
### List Teams   
### List Teams

function listteams() {
 include ('header.php');

maintheader();

$result = mysql_query("select team_id, team_name, division from team_names2 order by division, team_name");

$lastdivision="A";

while (list($teamid, $teamname, $division) = mysql_fetch_row($result))
 {
  if ($division!=$lastdivision)
  {
   if ($division=='0')
   {
    echo "<BR><B>Division Unallocated Teams</b> (divisions are usually allocated towards the beginning of the season)<BR><BR>";
   }
   else
   {
    echo "<BR><B>Division $division Teams</b><BR><BR>";
   }
  }
  echo "<a href=\"?op=ShowTeam&teamid=$teamid\">$teamname</a><BR>";
  $lastdivision=$division;
 }

 maintfooter();
 mysql_free_result($result);
 include ('footer.php');
}

### Show My Team
### Show My Team 
### Show My Team

function showmyteam($user) {
 include ('header.php');
 maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

## Check to see if user is author on a team

$teamresult = mysql_query("select COUNT(*) from team_authorisation where authorisation_user='$username'");
$teamcount=mysql_fetch_array($teamresult);
$existsonteam= $teamcount[0];

if ($existsonteam)
 {

$result = mysql_query("select authorisation_teamid from team_authorisation where authorisation_user='$username'");

while (list($authorisation_teamid) = mysql_fetch_row($result))
 {
 $url = "http://mysite.co.uk/maintenance.php?op=ShowTeam&teamid=$authorisation_teamid";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
 }
}
else
{
echo "Unfortunately we cannot find your user ID attached to any existing team. You either need to create a new team or ask the person who administers your team to add your user ID to the list of authorised users.";
exit;
}

 mysql_free_result($result);
 include ('footer.php');
}



### List Venues
### List Venues
### List Venues

function listvenues() {
 include ('header.php');

maintheader();

$result = mysql_query("select venue_name, venue_id from team_venues order by venue_name");
while (list($venuename, $venueid) = mysql_fetch_row($result))
{
 echo  "<a href=\"?op=ShowVenue&venueid=$venueid\">$venuename</a><BR>";
}
 maintfooter();
 mysql_free_result($result);
 include ('footer.php');
}


### Show Team
### Show Team 
### Show Team

function showteam($teamid, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

echo "<h3><B>Show Team Details</b></h3>";
$result = mysql_query("select team_venue_id, team_name, team_name_old, division, division_old, team_email, team_telephone, team_alternate_telephone from team_names2 where team_id='$teamid' order by team_id limit 1");
while (list($teamvenueid, $teamname, $teamnameold, $division, $divisionold, $teamemail, $teamtelephone, $teamalternatetelephone) = mysql_fetch_row($result))
{
 echo  "<B>Team Name:</b> $teamname<BR>";
 echo  "<B>Team Email Contact:</b> $teamemail<BR>";
 echo  "<B>Team Telephone Contact:</b> $teamtelephone<BR>";
 echo  "<B>Alternate Team Telephone Contact:</b> $teamalternatetelephone<BR>";
 if ($teamnameold!='') echo  "<B>Old Team Name:</b> $teamnameold<BR>";
 echo "<B>Division This Season:</b>";
 if ($division==0) {echo " not yet allocated<BR>";}
 else {echo " $division<BR>";}
 if ($divisionold!=0) echo "<B>Division Last Season:</b> $divisionold<BR>";

echo "<BR><b>Plays From:</b><BR><BR>";

$result = mysql_query("select venue_name, venue_oldname, venue_address, venue_town,
venue_postcode, venue_telephone from team_venues where venue_id='$teamvenueid'");
while (list($venuename, $venueoldname, $venueaddress, $venuetown,
$venuepostcode, $venuetelephone) = mysql_fetch_row($result))
{
 echo  "<table><tr><TD><B>Venue Name:</b> $venuename<BR>
<B>Old Venue Name:</b> $venueoldname<BR>
<B>Venue Address:</b> $venueaddress<BR>
<B>Venue Town:</b> $venuetown<BR>
<B>Venue Postcode:</b> $venuepostcode<BR>
<B>Venue Contact Telephone:</b> $venuetelephone<BR></td><td>
<a href=\"http://uk.multimap.com/map/browse.cgi?client=public&db=pc&cidr_client=none&lang=&pc=".$venuepostcode."\" target=\"_blank\"><img src=\"/images/minimap.jpg\" border=\"0\"><BR>map it</a></td></tr></table>";
}
echo "<BR><BR>";
$x=1;

$result = mysql_query("select players_playerid, players_playername, players_playerstartdate from team_players where players_teamid='$teamid' order by players_playerid");
while (list($playersplayerid, $playersplayername, $playersplayerstartdate) = mysql_fetch_row($result))
{
 $box.="<TR><td>$playersplayername</td><td>".date("Y-m-d", strtotime($playersplayerstartdate))."</td><td>";
 if ($x==1){$box.=" (Captain)";}
 $box.="</td></tr>";
 $x++;
}
if ($box){
echo "<table border=0><tr><td><B>Player Name</b></td><td><B>Valid For games From</b></td><td></td></tr>";
echo $box;
echo "</table>";
}
else
{
echo "No registered players";
}

echo "<BR><BR><B>Current authors:</b><BR>";

# Read existing authors in

$result = mysql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
while (list($authorisation_user) = mysql_fetch_row($result))
{
 echo "$authorisation_user<BR>";
 if (trim($authorisation_user)==trim($username)) {$author=1;}
}

if ($author){echo "<BR><B><h3><a href=\"http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddPlayers&teamid=$teamid&teamname=$teamname\">add players</a> | <a href=\"http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname\">add authors</a> | <a href=\"http://mysite.co.uk/maintenance.php\">main menu</a></B></h3>";}
else{echo "<BR><B><h3>To edit this team you must be logged in and listed as a team author. </b></h3>";}
}
maintfooter();
 include ('footer.php');
}


### Show Venue
### Show Venue 
### Show Venue

function showvenue($venueid) {
include ('header.php');
maintheader();
echo "<h3><B>Venue Details</b></h3>";

$result = mysql_query("select venue_name, venue_oldname, venue_address, venue_town,
venue_postcode, venue_telephone from team_venues where venue_id='$venueid'");
while (list($venuename, $venueoldname, $venueaddress, $venuetown,
$venuepostcode, $venuetelephone) = mysql_fetch_row($result))
{
 echo  "<table><tr><td><B>Venue Name:</b> $venuename<BR>
<B>Old Venue Name:</b> $venueoldname<BR>
<B>Venue Address:</b> $venueaddress<BR>
<B>Venue Town:</b> $venuetown<BR>
<B>Venue Postcode:</b> $venuepostcode<BR>
<B>Venue Contact Telephone:</b> $venuetelephone<BR></td><td>
<a href=\"http://uk.multimap.com/map/browse.cgi?client=public&db=pc&cidr_client=none&lang=&pc=".$venuepostcode."\" target=\"_blank\"><img src=\"/images/minimap.jpg\" border=\"0\"><BR>map it</a></td></tr></table>";
}

maintfooter();
 include ('footer.php');
}




### Select Venue
### Select Venue   
### Select Venue

function selectvenue($user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

echo "<SCRIPT LANGUAGE=\"JavaScript\">\n
function Validate(thisForm)\n
{\n";
echo "thisForm.venuename.value=thisForm.venueid.options[thisForm.venueid.selectedIndex].text;\n";
echo "if (thisForm.venuename.value==\"Other...\" || thisForm.venuename.value==\"Select One\"){return (false)};\n";
echo "return (true);\n
}\n
\n
function Validate2(thisForm)\n
{\n";
echo "if (thisForm.venuename.value==\"\" || thisForm.venueaddress.value==\"\" || thisForm.venuetown.value==\"\" || thisForm.venuepostcode.value==\"\" || thisForm.venuetelephone.value==\"\"){alert(\"It is very important that you fill all these fields in so that other site users can find your venue when playing you at home.\"); return (false) };\n";
echo "return (true);\n
}\n
\n
function unhide(thisField, thisObject)\n
{\n
if (thisField.options[thisField.selectedIndex].text==\"Other...\"){thisObject.style.display=\"\";}\n
else\n
{thisObject.style.display=\"none\"}
}\n

function websearch(placename)\n
{\n
url=\"http://www.google.co.uk/search?hl=en&q=\"+placename+\"+weston+super+mare&meta=cr%3DcountryUK%7CcountryGB\";
url2=\"http://www.yell.com/ucs/UcsSearchAction.do?searchType=classic&ooa=on&keywords=&companyName=\"+placename+\"&location=Weston-Super-Mare\"
winRef = window.open(url, \"Websearch\");\n
winRef2 = window.open(url2, \"Websearch2\");\n
}\n
\n

</SCRIPT>";

echo "<center><img src=\"/images/step1.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

echo "<h3><B>Create New Team: Select Venue</b></h3>";
echo "<FORM ONSUBMIT=\"return Validate(this)\" ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"SelectVenue\">
<BR>
My team plays from the following venue:<select name=\"venueid\" onChange=\"unhide(venueid, hiddensection)\";><option selected>Select One</option>";
$result = mysql_query("select venue_id, venue_name from team_venues order by venue_name");
while (list($venueid, $venuename) = mysql_fetch_row($result))
 {
  echo "<option value=\"$venueid\">$venuename</option>";
 }
echo "<option value=\"other\" default>Other...</option>";
 echo "</select>";
 echo  "<input name=\"venuename\" type=\"hidden\">
 <input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"VenueSelected\">
<INPUT TYPE=\"submit\" value=\"Next Step->\">";

echo "</form>";
echo "<h3><B>Please make sure your venue is not in the above dropdown list, BEFORE you enter any details below.  Venues entered more than once delays fixtures.</b></h3>";

echo "<FORM ACTION=\"maintenance.php\" ONSUBMIT=\"return Validate2(this)\" METHOD=\"POST\" NAME=\"NewVenue\">";
echo "<P ID=\"hiddensection\" STYLE=\"display:none;\">";
echo "Venue not listed? Add it here:<BR><BR><table>
<TR><td><B>Venue Name:</b> </td><td><input type=text NAME=\"venuename\" size=30></td></tr>
<TR><td><B>Old Venue Name:</b> </td><td><input type=text NAME=\"venueoldname\" size=30> (optional)</td></tr>
<TR><td><B>Venue Address:</b> </td><td><input type=text NAME=\"venueaddress\" size=30> <a href=\"javascript:websearch(NewVenue.venuename.value)\" title=\"Clicking here will open search windows to Google and Yell\">Click here to search the web for the address</a></td></tr>
<TR><td><B>Venue Town:</b> </td><td><input type=text NAME=\"venuetown\" size=30></td></tr>
<TR><td><B>Venue Postcode:</b> </td><td><input type=text NAME=\"venuepostcode\" size=30></td></tr>
<TR><td><B>Venue Contact Telephone:</b> </td><td><input type=text NAME=\"venuetelephone\" size=30></td></tr></table>";
echo  "<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedVenue\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Add Venue\">";
echo "</p>";

echo "</form>";

maintfooter();
 include ('footer.php');
}

### Submitted Venue
### Submitted Venue
### Submitted Venue

function submittedvenue($venuename, $venueoldname, $venueaddress, $venuetown, $venuepostcode, $venuetelephone, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

$venuename=ucwords(strtolower($venuename));
$venueoldname=ucwords(strtolower($venueoldname));
$venueaddress=ucwords(strtolower($venueaddress));
$venuetown=ucwords(strtolower($venuetown));

$venuepostcode=strtoupper(str_replace ( "-", "", $venuepostcode));


##
## Make sure all fields are filled in
##
if ($venuename=='' or $venueaddress=='' or $venuetown=='' or $venuepostcode=='' or $venuetelephone=='')
{
 echo "Somehow you have got this far without filling in all the fields on the previous form. Please return to the previous page and fill in all the fields.";
exit;
}

 $result=mysql_query("insert into team_venues values (NULL, '$venuename', '$venueoldname', '$venueaddress', '$venuetown', '$venuepostcode', '$venuetelephone')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }

### Read back in
$result = mysql_query("select venue_id from team_venues where venue_name='$venuename' AND venue_oldname='$venueoldname' AND venue_address='$venueaddress' AND venue_town='$venuetown' AND venue_postcode='$venuepostcode' AND venue_telephone='$venuetelephone' limit 1");

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=Venue";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Venue Selected
### Venue Selected 
### Venue Selected

function venueselected($venueid, $venuename, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

###
### 'Teams already allocated' code
###
$teams_already_created.="<B>Teams already created for this venue:</b><BR>";

$result = mysql_query("select team_id, team_name, division from team_names2 where team_venue_id='$venueid' order by division, team_name");
$jarraynumber=0;
$jarray.="var existingteams = new Array()\n";
while (list($teamid, $teamname, $division) = mysql_fetch_row($result))
 {
  $teams_already_created.="<a href=\"?op=ShowTeam&teamid=$teamid\">$teamname</a><BR>";
  $jarray.="existingteams[$jarraynumber]=\"$teamname\"\n";
  $jarraynumber++;
 }
##
## end
##

###
### Error checking
###
echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
echo $jarray;

echo "\n function Validate(thisForm)
{\n";

echo "for (var i=0; i<existingteams.length; i++)
{
var left=thisForm.teamname.value;
var right=existingteams[i];

 if (left.toUpperCase()==right.toUpperCase())
 {
  alert (\"Team name already exists for this venue\");
  thisForm.teamname.focus();
  return (false);
 }
}\n";

 echo "if (thisForm.teamname.value==\"\")
 {
  alert (\"Team name must be filled in\");
  thisForm.teamname.focus();
  return (false);
 }\n";
 
 echo "if (thisForm.teamemail.value==\"\")
 {
  alert (\"Team email must be filled in\");
  thisForm.teamemail.focus();
  return (false);
 }\n";

 echo "if (thisForm.teamtelephone.value==\"\")
 {
  alert (\"Team telephone must be filled in\");
  thisForm.teamtelephone.focus();
  return (false);
 }
}
</SCRIPT>\n";

###
### end
###
echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

echo "<h3><B>Create New Team: Team Details</b></h3>";

 echo "<FORM ONSUBMIT=\"return Validate(this)\" ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddTeam\">
<BR>
<b>Venue:</b> <input type=text NAME=\"venuename\" size=30 value=\"".stripslashes($venuename)."\" disabled><BR>
<input type=hidden NAME=\"venueid\" value=\"$venueid\">
<B>Created By: </b> <input type=text NAME=\"username\" size=30 value=\"".$username."\" disabled><BR>
<BR>
<table>
<TR><td><b>Team Name This Season: </b></td><TD><input type=text NAME=\"teamname\" size=30></td></tr>
<TR><td><b>Team Contact Email: </b></td><TD> <input type=text NAME=\"teamemail\" size=30></td></tr>
<TR><td><b>Team Telephone Contact:</b> </td><TD><input type=text NAME=\"teamtelephone\" size=30></td></tr>
<TR><td><b>Alternative Team Telephone Contact:</b> </td><TD><input type=text NAME=\"teamalternatetelephone\" size=30></td></tr>
<TR><td></td><TD></td></tr>
<TR><td><b>Team Name Last Season:</b> </td><TD><input type=text NAME=\"teamnameold\" size=30> (leave blank if new team)</td></tR>
<TR><td><B>Division Last Season:</b> </td><TD><input type=text NAME=\"divisionold\" size=1> (leave blank if new team)</td></tr>
</table><BR>";

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedTeamName\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Next Step-->\">";

echo "</form>";
echo $teams_already_created;

maintfooter();
 include ('footer.php');
}

### Submitted Team Name
### Submitted Team Name
### Submitted Team Name

function submittedteamname($venueid, $teamname, $teamemail, $teamtelephone, $teamalternatetelephone, $teamnameold, $divisionold, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}
$teamname=ucwords(strtolower($teamname));
$teamnameold=ucwords(strtolower($teamnameold));

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

##
## Make sure all fields are filled in
##
if ($teamname=='')
{
 echo "Somehow you have got this far without filling in all the fields on the previous form. Please return to the previous page and fill in all the fields.";
exit;
}

### Check if team name at venue already exists, then stop from writing new record

$teamresult = mysql_query("select COUNT(*) from team_names2 where team_name='$teamname' AND team_venue_id='$venueid'");
$teamcount=mysql_fetch_array($teamresult);
$nameexists= $teamcount[0];

if ($nameexists){echo "Sorry, the team name you specified has already been allocated. Please click the back button on your browser and choose another name."; exit;}

### Write team record
 $result=mysql_query("insert into team_names2 values (NULL, $venueid, '$teamname', '$teamnameold', '0', '$divisionold', '$teamemail', '$teamtelephone', '$teamalternatetelephone')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }

### Read back in
$result = mysql_query("select team_id from team_names2 where team_venue_id='$venueid' AND team_name='$teamname' AND team_name_old='$teamnameold' AND division_old='$divisionold' limit 1");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }
while (list($teamid2) = mysql_fetch_row($result))
 {
### Add user to authority file
$teamid=$teamid2;
$result=mysql_query("insert into team_authorisation values ('$teamid', '$username')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }
 }

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddPlayers&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Add Players
### Add Players 
### Add Players

function addplayers($teamid, $teamname, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

 echo "<h3><b>Create New Team: Add Players</b></h3>";
 echo "<B>Player names entered here CANNOT be changed. If you do not know the exact name of some of your team members do not enter them. You can come back to this page at any time and add more members to your team without penalty.</b><BR><BR>";

 echo "<FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddPlayers\">;
<input type=hidden NAME=\"teamid\" value=\"$teamid\">
Team Name: <input type=text NAME=\"teamname2\" value=\"$teamname\" disabled>
<input type=hidden NAME=\"teamname\" value=\"$teamname\">
<input type=hidden NAME=\"user\" value=\"$username\"><BR><BR>";
echo "<b>Players added now will only be elligible to play in games from tomorrow.<BR><BR></b>";
 echo "<h4><b>Please enter First and Last names.  Not just initial (e.g. John Smith not J.Smith)</b> </h4>
<BR>";

# Read existing players in
$x=1;

$result = mysql_query("select players_playerid, players_playername, players_playerstartdate from team_players where players_teamid='$teamid' order by players_playerid");

while (list($playersplayerid, $playersplayername, $playersplayerstartdate) = mysql_fetch_row($result))
{
 echo "<B>Player $x: </b> <input type=text NAME=\"fixedplayer$x\" size=30 value=\"$playersplayername\" disabled>";
  if ($x==1){echo " (Captain)";}
  echo "<BR><BR>";
 $x++;
}

while ($x<21)
{
 echo "<B>Player $x: </b> <input type=text NAME=\"player$x\" size=30 value=\"\">";
 if ($x==1){echo " (Captain)";}
 echo "<BR><BR>";
 $x++;
 }

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedPlayers\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Next Step-->\">";

 echo "</form>";

maintfooter();
 include ('footer.php');
}


### Submitted Players
### Submitted Players   
### Submitted Players

function submittedplayers($teamid, $teamname, $player1, $player2, $player3, $player4, $player5, $player6, $player7, $player8, $player9, $player10, $player11, $player12, $player13, $player14, $player15, $player16, $player17, $player18, $player19, $player20, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

##
## Make sure all fields are filled in
##
#if ($teamname=='')
#{
# echo "Somehow you have got this far without filling in all the fields on the previous form. Please #return to the previous page and fill in all the fields.";
#exit;
#}

# Count existing players
   $playerresult = mysql_query("select COUNT(*) from team_players where players_teamid='$teamid'");
   $playercount=mysql_fetch_array($playerresult);
   $y= $playercount[0];
$x=$y+1;
$tomorrow = date("Y-m-d", strtotime("tomorrow"));
while($x<21)
{

#$thisplayer=str_replace ( ".", " ", ${"player".$x});
#$thisplayer=ucwords(strtolower($thisplayer));
#$thisplayer=ucwords(strtolower(${"player".$x}));
$thisplayer=ucwords(strtolower(str_replace("."," ",${"player".$x})));

### Write player records
 if ($thisplayer!=''){
    $y++;
 $result=mysql_query("insert into team_players values ('$y', '$teamid', '$thisplayer', '$tomorrow')");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
  }
  else
  {
  }
 }
 $x++;
}
### Read back in
#$result = mysql_query("select team_id from team_names2 where team_venue_id='$venueid' AND team_name='$teamname' AND teamname_old='$teamnameold' AND division_old='$divisionold' limit 1");
#while (list($teamid) = mysql_fetch_row($result))
# {
#### Add user to authority file
#$result=mysql_query("insert into team_authorisation values ('$teamid', '$username')");
# }

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Add Authors
### Add Authors 
### Add Authors

function addauthors($teamid, $teamname, $user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4.jpg\"  align=absmiddle></center>";

 echo "<h3><B>Create New Team: Add Team Authors</b></h3>";

 echo "<FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddAuthors\">
Using this form you can add or delete site members as editors of your team. If you do not add any more only you will be able to amend the details about your team. If you do not wish to add them now you can add them at any time in the future.<BR><BR>
<input type=hidden NAME=\"teamid\" value=\"$teamid\">
Team Name: <input type=text NAME=\"teamname2\" value=\"$teamname\" disabled>
<input type=hidden NAME=\"teamname\" value=\"$teamname\">
<input type=hidden NAME=\"user\" value=\"$username\"><BR><BR><B>Current authors:</b><BR>";

# Read existing authors in

$x=0;
$result = mysql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
while (list($authorisation_user) = mysql_fetch_row($result))
{
 echo "<input type=text NAME=\"author$x\" size=30 value=\"$authorisation_user\" disabled>";
 if ($authorisation_user!=$username){ echo "<a href=\"?op=CreateTeam&step=RemoveAuthor&teamid=$teamid&authorid=$authorisation_user&teamname=$teamname\">remove</a>";}
 echo "<BR><BR>";
$author{$x}=$authorisation_user;
$x++;
}

echo "<select name=\"addauthor\" size=\"10\">";

$result = mysql_query("select username from rebelt_users");
$authorexists=0;

while (list($allusers) = mysql_fetch_row($result))
{
 for ($i = 0; $i <= $x; $i++)
 {
  if ($allusers==$author{$i}){$authorexists=1;}
 }
 if (!($authorexists)){echo "<option>$allusers</option>";}

$authorexists=0;
}
echo "</select>";

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedAuthor\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Add Author\"></form><BR><FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddAuthors\"><input type=hidden name=\"op\" value=\"Finished\"><input type=hidden name=\"teamid\" value=\"$teamid\"><INPUT TYPE=\"submit\" value=\"Finished-->\">";

 echo "</form>";

maintfooter();
 include ('footer.php');
}


### Submitted Author
### Submitted Author
### Submitted Author

function submittedauthor($teamid, $teamname, $user, $addauthor) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}
if ($addauthor==$username){echo "Your name is already in the authors list."; exit;}

##
## Make sure all fields are filled in
##
if ($addauthor=='')
{
 echo "You must select a name from the list in order to add an additional team author. If you do not have any more authors to add, just click the 'Finished' button.";
exit;
}

# Count existing players
   $playerresult = mysql_query("select COUNT(*) from team_players where players_teamid='$teamid'");
   $playercount=mysql_fetch_array($playerresult);
   $y= $playercount[0];

   $result=mysql_query("insert into team_authorisation values ('$teamid', '$addauthor')");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
  }
 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}



### Finished
### Finished
### Finished

function finished($teamid) {
include ('header.php');
maintheader();

 $url = "http://mysite.co.uk/league_cup_exclude.php";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}





###
### Page Header
###
function maintheader(){
echo "<center><H2><B>Pool Team Maintenance</b></h2></center>";
}

###
### Page Footer
###
function maintfooter(){
echo "<BR><BR><center><table width=90% border=1><tr><td align=center width=50%><a href=\"http://mysite.co.uk/maintenance.php\">Home</a></td><td align=center><a href=\"http://mysite.co.uk/maintenance.php?op=ShowMyTeam\">Show My Team</a></td></tr></table></center><BR><BR><BR><BR>";
}


### Get Username
### Get Username
### Get Username
function getusername($user)
{
 $user2 = base64_decode($user);
 $user2 = addslashes($user2);
 $user2 = explode(":", $user2);
 return $user2[1];
}


### URL Forward
### URL Forward
### URL Forward
function urlforward($url)
{
 $delay = "0";
 return "<meta http-equiv=\"refresh\" content=\"".$delay.";url=".$url."\">";
}

### Check authorisation
### Check authorisation
### Check authorisation

function isauthorised($teamid, $username)
{
 $result = mysql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
 while (list($authorisation_user) = mysql_fetch_row($result))
 {
  if ($authorisation_user==$username){ return true;}
 }
 return false;
}


###
### Main Entry
###

switch($op) {

    case "CreateTeam":

        switch($step) {
                case "Venue":
                selectvenue($user);
                break;

                case "SubmittedVenue":
                submittedvenue($venuename, $venueoldname, $venueaddress, $venuetown, $venuepostcode, $venuetelephone, $user);
                break;

                case "VenueSelected":
                venueselected($venueid, $venuename, $user);
                break;

                case "SubmittedTeamName":
                submittedteamname($venueid, $teamname, $teamemail, $teamtelephone, $teamalternatetelephone, $teamnameold, $divisionold, $user);
                break;

                case "AddPlayers":
                addplayers($teamid, $teamname, $user);
                break;

                case "SubmittedPlayers":
                submittedplayers($teamid, $teamname, $player1, $player2, $player3, $player4, $player5, $player6, $player7, $player8, $player9, $player10, $player11, $player12, $player13, $player14, $player15, $player16, $player17, $player18, $player19, $player20, $user);
                break;

                case "AddAuthors":
                addauthors($teamid, $teamname, $user);
                break;

                case "SubmittedAuthor":
                submittedauthor($teamid, $teamname, $user, $addauthor);
                break;

                case "RemoveAuthor":
                removeauthor($teamid, $teamname, $user, $authorid);
                break;



}

        case "Admin":

                switch($step)
{
                case "List":
                listrecords($user);
                break;

                case "Allocate":
                allocate($user);
                break;

                case "SubmittedTeamAllocations":
                submittedteamallocations($user, $allchanges);
                break;

                case "AdminDelete":
                admin_delete_team($id, $user);
                break;

                case "Summarise":
                summarise($user);
                break;

      case "RemoveVenue":
      removevenue($venueid, $user);
      break;

      case "RemovePlayer":
                removeplayer($playerid, $teamid, $user);
                break;

                default:
                adminoptions($user);
                break;
}


    case "ListTeams":
        listteams();
        break;

    case "ShowTeam":
        showteam($teamid, $user);
        break;

    case "ShowMyTeam":
        showmyteam($user);
        break;

    case "ListVenues":
        listvenues();
        break;

    case "ShowVenue":
        showvenue($venueid);
        break;

    case "Finished":
        finished($teamid);
        break;

    case "FAQ":
        FAQ();
        break;

    default:
        mainpage();
        break;

}

?>


Suggestions anyone.

_________________
I wish I knew what I was doing LOL 
View user's profile Send private message Visit poster's website
nuken
RavenNuke(tm) Development Team


Joined: Mar 11, 2007
Posts: 2024
Location: North Carolina

PostPosted: Sun Jan 22, 2012 11:15 am Reply with quote

See if this fixes you up.

Code:


<?PHP
// includes the mainfile functions and the header junk
if (!isset($mainfile)) { include("mainfile.php"); }
define('INDEX_FILE', true);
### Main Page
### Main Page
### Main Page

function mainpage() {
global $db;
 include ('header.php');

maintheader();

echo "<center><B>This online service will be used to add and update Weston Pool League team names, members and venues.<br /> By registering with Weston Pool League, you acknowledge that the league, those who run it and members, are not responsible for access to any venue. <br />If you are new to this process, get started by creating your team using the first option below.<br /><h3>Please make sure the player is ONLY registered to play for your team.</h3><br /><h3><blink><B>Important!</b></blink><br/>DO NOT enter any team detail, until the notice appears on the fromt page telling you the database is ready.</h3></center>";

echo "<BR><table width=100%>";


   echo "<a href=\"?op=CreateTeam&step=Venue\">1. Create New Team</a><BR><BR>
   <a href=\"?op=ListVenues\">2. List All Venues</a><BR><BR>
   <a href=\"?op=ShowMyTeam\">3. Show My Team</a><BR><BR>
   <a href=\"?op=ListTeams\">4. List All Teams</a><BR><BR>";

echo "</table>";

maintfooter();

 $db->sql_freeresult($result);
 include ('footer.php');
}

### List Teams
### List Teams   
### List Teams

function listteams() {
global $db;
 include ('header.php');

maintheader();

$result = $db->sql_query("select team_id, team_name, division from team_names2 order by division, team_name");

$lastdivision="A";

while (list($teamid, $teamname, $division) = $db->sql_fetchrow($result))
 {
  if ($division!=$lastdivision)
  {
   if ($division=='0')
   {
    echo "<BR><B>Division Unallocated Teams</b> (divisions are usually allocated towards the beginning of the season)<BR><BR>";
   }
   else
   {
    echo "<BR><B>Division $division Teams</b><BR><BR>";
   }
  }
  echo "<a href=\"?op=ShowTeam&teamid=$teamid\">$teamname</a><BR>";
  $lastdivision=$division;
 }

 maintfooter();
 $db->sql_freeresult($result);
 include ('footer.php');
}

### Show My Team
### Show My Team
### Show My Team

function showmyteam($user) {
global $db;
 include ('header.php');
 maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

## Check to see if user is author on a team

$teamresult = $db->sql_query("select COUNT(*) from team_authorisation where authorisation_user='$username'");
$teamcount=$db->sql_fetchrow($teamresult);
$existsonteam= $teamcount[0];

if ($existsonteam)
 {

$result = $db->sql_query("select authorisation_teamid from team_authorisation where authorisation_user='$username'");

while (list($authorisation_teamid) = $db->sql_fetchrow($result))
 {
 $url = "http://mysite.co.uk/maintenance.php?op=ShowTeam&teamid=$authorisation_teamid";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
 }
}
else
{
echo "Unfortunately we cannot find your user ID attached to any existing team. You either need to create a new team or ask the person who administers your team to add your user ID to the list of authorised users.";
exit;
}

 $db->sql_freeresult($result);
 include ('footer.php');
}



### List Venues
### List Venues
### List Venues

function listvenues() {
global $db;
 include ('header.php');

maintheader();

$result = $db->sql_query("select venue_name, venue_id from team_venues order by venue_name");
while (list($venuename, $venueid) = $db->sql_fetchrow($result))
{
 echo  "<a href=\"?op=ShowVenue&venueid=$venueid\">$venuename</a><BR>";
}
 maintfooter();
 $db->sql_freeresult($result);
 include ('footer.php');
}


### Show Team
### Show Team
### Show Team

function showteam($teamid, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

echo "<h3><B>Show Team Details</b></h3>";
$result = $db->sql_query("select team_venue_id, team_name, team_name_old, division, division_old, team_email, team_telephone, team_alternate_telephone from team_names2 where team_id='$teamid' order by team_id limit 1");
while (list($teamvenueid, $teamname, $teamnameold, $division, $divisionold, $teamemail, $teamtelephone, $teamalternatetelephone) = $db->sql_fetchrow($result))
{
 echo  "<B>Team Name:</b> $teamname<BR>";
 echo  "<B>Team Email Contact:</b> $teamemail<BR>";
 echo  "<B>Team Telephone Contact:</b> $teamtelephone<BR>";
 echo  "<B>Alternate Team Telephone Contact:</b> $teamalternatetelephone<BR>";
 if ($teamnameold!='') echo  "<B>Old Team Name:</b> $teamnameold<BR>";
 echo "<B>Division This Season:</b>";
 if ($division==0) {echo " not yet allocated<BR>";}
 else {echo " $division<BR>";}
 if ($divisionold!=0) echo "<B>Division Last Season:</b> $divisionold<BR>";

echo "<BR><b>Plays From:</b><BR><BR>";

$result = $db->sql_query("select venue_name, venue_oldname, venue_address, venue_town,
venue_postcode, venue_telephone from team_venues where venue_id='$teamvenueid'");
while (list($venuename, $venueoldname, $venueaddress, $venuetown,
$venuepostcode, $venuetelephone) = $db->sql_fetchrow($result))
{
 echo  "<table><tr><TD><B>Venue Name:</b> $venuename<BR>
<B>Old Venue Name:</b> $venueoldname<BR>
<B>Venue Address:</b> $venueaddress<BR>
<B>Venue Town:</b> $venuetown<BR>
<B>Venue Postcode:</b> $venuepostcode<BR>
<B>Venue Contact Telephone:</b> $venuetelephone<BR></td><td>
<a href=\"http://uk.multimap.com/map/browse.cgi?client=public&db=pc&cidr_client=none&lang=&pc=".$venuepostcode."\" target=\"_blank\"><img src=\"/images/minimap.jpg\" border=\"0\"><BR>map it</a></td></tr></table>";
}
echo "<BR><BR>";
$x=1;

$result = $db->sql_query("select players_playerid, players_playername, players_playerstartdate from team_players where players_teamid='$teamid' order by players_playerid");
while (list($playersplayerid, $playersplayername, $playersplayerstartdate) = $db->sql_fetchrow($result))
{
 $box.="<TR><td>$playersplayername</td><td>".date("Y-m-d", strtotime($playersplayerstartdate))."</td><td>";
 if ($x==1){$box.=" (Captain)";}
 $box.="</td></tr>";
 $x++;
}
if ($box){
echo "<table border=0><tr><td><B>Player Name</b></td><td><B>Valid For games From</b></td><td></td></tr>";
echo $box;
echo "</table>";
}
else
{
echo "No registered players";
}

echo "<BR><BR><B>Current authors:</b><BR>";

# Read existing authors in

$result = $db->sql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
while (list($authorisation_user) = $db->sql_fetchrow($result))
{
 echo "$authorisation_user<BR>";
 if (trim($authorisation_user)==trim($username)) {$author=1;}
}

if ($author){echo "<BR><B><h3><a href=\"http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddPlayers&teamid=$teamid&teamname=$teamname\">add players</a> | <a href=\"http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname\">add authors</a> | <a href=\"http://mysite.co.uk/maintenance.php\">main menu</a></B></h3>";}
else{echo "<BR><B><h3>To edit this team you must be logged in and listed as a team author. </b></h3>";}
}
maintfooter();
 include ('footer.php');
}


### Show Venue
### Show Venue
### Show Venue

function showvenue($venueid) {
global $db;
include ('header.php');
maintheader();
echo "<h3><B>Venue Details</b></h3>";

$result = $db->sql_query("select venue_name, venue_oldname, venue_address, venue_town,
venue_postcode, venue_telephone from team_venues where venue_id='$venueid'");
while (list($venuename, $venueoldname, $venueaddress, $venuetown,
$venuepostcode, $venuetelephone) = $db->sql_fetchrow($result))
{
 echo  "<table><tr><td><B>Venue Name:</b> $venuename<BR>
<B>Old Venue Name:</b> $venueoldname<BR>
<B>Venue Address:</b> $venueaddress<BR>
<B>Venue Town:</b> $venuetown<BR>
<B>Venue Postcode:</b> $venuepostcode<BR>
<B>Venue Contact Telephone:</b> $venuetelephone<BR></td><td>
<a href=\"http://uk.multimap.com/map/browse.cgi?client=public&db=pc&cidr_client=none&lang=&pc=".$venuepostcode."\" target=\"_blank\"><img src=\"/images/minimap.jpg\" border=\"0\"><BR>map it</a></td></tr></table>";
}

maintfooter();
 include ('footer.php');
}




### Select Venue
### Select Venue   
### Select Venue

function selectvenue($user) {
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

echo "<SCRIPT LANGUAGE=\"JavaScript\">\n
function Validate(thisForm)\n
{\n";
echo "thisForm.venuename.value=thisForm.venueid.options[thisForm.venueid.selectedIndex].text;\n";
echo "if (thisForm.venuename.value==\"Other...\" || thisForm.venuename.value==\"Select One\"){return (false)};\n";
echo "return (true);\n
}\n
\n
function Validate2(thisForm)\n
{\n";
echo "if (thisForm.venuename.value==\"\" || thisForm.venueaddress.value==\"\" || thisForm.venuetown.value==\"\" || thisForm.venuepostcode.value==\"\" || thisForm.venuetelephone.value==\"\"){alert(\"It is very important that you fill all these fields in so that other site users can find your venue when playing you at home.\"); return (false) };\n";
echo "return (true);\n
}\n
\n
function unhide(thisField, thisObject)\n
{\n
if (thisField.options[thisField.selectedIndex].text==\"Other...\"){thisObject.style.display=\"\";}\n
else\n
{thisObject.style.display=\"none\"}
}\n

function websearch(placename)\n
{\n
url=\"http://www.google.co.uk/search?hl=en&q=\"+placename+\"+weston+super+mare&meta=cr%3DcountryUK%7CcountryGB\";
url2=\"http://www.yell.com/ucs/UcsSearchAction.do?searchType=classic&ooa=on&keywords=&companyName=\"+placename+\"&location=Weston-Super-Mare\"
winRef = window.open(url, \"Websearch\");\n
winRef2 = window.open(url2, \"Websearch2\");\n
}\n
\n

</SCRIPT>";

echo "<center><img src=\"/images/step1.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

echo "<h3><B>Create New Team: Select Venue</b></h3>";
echo "<FORM ONSUBMIT=\"return Validate(this)\" ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"SelectVenue\">
<BR>
My team plays from the following venue:<select name=\"venueid\" onChange=\"unhide(venueid, hiddensection)\";><option selected>Select One</option>";
$result = $db->sql_query("select venue_id, venue_name from team_venues order by venue_name");
while (list($venueid, $venuename) = $db->sql_fetchrow($result))
 {
  echo "<option value=\"$venueid\">$venuename</option>";
 }
echo "<option value=\"other\" default>Other...</option>";
 echo "</select>";
 echo  "<input name=\"venuename\" type=\"hidden\">
 <input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"VenueSelected\">
<INPUT TYPE=\"submit\" value=\"Next Step->\">";

echo "</form>";
echo "<h3><B>Please make sure your venue is not in the above dropdown list, BEFORE you enter any details below.  Venues entered more than once delays fixtures.</b></h3>";

echo "<FORM ACTION=\"maintenance.php\" ONSUBMIT=\"return Validate2(this)\" METHOD=\"POST\" NAME=\"NewVenue\">";
echo "<P ID=\"hiddensection\" STYLE=\"display:none;\">";
echo "Venue not listed? Add it here:<BR><BR><table>
<TR><td><B>Venue Name:</b> </td><td><input type=text NAME=\"venuename\" size=30></td></tr>
<TR><td><B>Old Venue Name:</b> </td><td><input type=text NAME=\"venueoldname\" size=30> (optional)</td></tr>
<TR><td><B>Venue Address:</b> </td><td><input type=text NAME=\"venueaddress\" size=30> <a href=\"javascript:websearch(NewVenue.venuename.value)\" title=\"Clicking here will open search windows to Google and Yell\">Click here to search the web for the address</a></td></tr>
<TR><td><B>Venue Town:</b> </td><td><input type=text NAME=\"venuetown\" size=30></td></tr>
<TR><td><B>Venue Postcode:</b> </td><td><input type=text NAME=\"venuepostcode\" size=30></td></tr>
<TR><td><B>Venue Contact Telephone:</b> </td><td><input type=text NAME=\"venuetelephone\" size=30></td></tr></table>";
echo  "<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedVenue\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Add Venue\">";
echo "</p>";

echo "</form>";

maintfooter();
 include ('footer.php');
}

### Submitted Venue
### Submitted Venue
### Submitted Venue

function submittedvenue($venuename, $venueoldname, $venueaddress, $venuetown, $venuepostcode, $venuetelephone, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

$venuename=ucwords(strtolower($venuename));
$venueoldname=ucwords(strtolower($venueoldname));
$venueaddress=ucwords(strtolower($venueaddress));
$venuetown=ucwords(strtolower($venuetown));

$venuepostcode=strtoupper(str_replace ( "-", "", $venuepostcode));


##
## Make sure all fields are filled in
##
if ($venuename=='' or $venueaddress=='' or $venuetown=='' or $venuepostcode=='' or $venuetelephone=='')
{
 echo "Somehow you have got this far without filling in all the fields on the previous form. Please return to the previous page and fill in all the fields.";
exit;
}

 $result=$db->sql_query("insert into team_venues values (NULL, '$venuename', '$venueoldname', '$venueaddress', '$venuetown', '$venuepostcode', '$venuetelephone')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }

### Read back in
$result = $db->sql_query("select venue_id from team_venues where venue_name='$venuename' AND venue_oldname='$venueoldname' AND venue_address='$venueaddress' AND venue_town='$venuetown' AND venue_postcode='$venuepostcode' AND venue_telephone='$venuetelephone' limit 1");

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=Venue";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Venue Selected
### Venue Selected
### Venue Selected

function venueselected($venueid, $venuename, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

###
### 'Teams already allocated' code
###
$teams_already_created.="<B>Teams already created for this venue:</b><BR>";

$result = $db->sql_query("select team_id, team_name, division from team_names2 where team_venue_id='$venueid' order by division, team_name");
$jarraynumber=0;
$jarray.="var existingteams = new Array()\n";
while (list($teamid, $teamname, $division) = $db->sql_fetchrow($result))
 {
  $teams_already_created.="<a href=\"?op=ShowTeam&teamid=$teamid\">$teamname</a><BR>";
  $jarray.="existingteams[$jarraynumber]=\"$teamname\"\n";
  $jarraynumber++;
 }
##
## end
##

###
### Error checking
###
echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
echo $jarray;

echo "\n function Validate(thisForm)
{\n";

echo "for (var i=0; i<existingteams.length; i++)
{
var left=thisForm.teamname.value;
var right=existingteams[i];

 if (left.toUpperCase()==right.toUpperCase())
 {
  alert (\"Team name already exists for this venue\");
  thisForm.teamname.focus();
  return (false);
 }
}\n";

 echo "if (thisForm.teamname.value==\"\")
 {
  alert (\"Team name must be filled in\");
  thisForm.teamname.focus();
  return (false);
 }\n";
 
 echo "if (thisForm.teamemail.value==\"\")
 {
  alert (\"Team email must be filled in\");
  thisForm.teamemail.focus();
  return (false);
 }\n";

 echo "if (thisForm.teamtelephone.value==\"\")
 {
  alert (\"Team telephone must be filled in\");
  thisForm.teamtelephone.focus();
  return (false);
 }
}
</SCRIPT>\n";

###
### end
###
echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

echo "<h3><B>Create New Team: Team Details</b></h3>";

 echo "<FORM ONSUBMIT=\"return Validate(this)\" ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddTeam\">
<BR>
<b>Venue:</b> <input type=text NAME=\"venuename\" size=30 value=\"".stripslashes($venuename)."\" disabled><BR>
<input type=hidden NAME=\"venueid\" value=\"$venueid\">
<B>Created By: </b> <input type=text NAME=\"username\" size=30 value=\"".$username."\" disabled><BR>
<BR>
<table>
<TR><td><b>Team Name This Season: </b></td><TD><input type=text NAME=\"teamname\" size=30></td></tr>
<TR><td><b>Team Contact Email: </b></td><TD> <input type=text NAME=\"teamemail\" size=30></td></tr>
<TR><td><b>Team Telephone Contact:</b> </td><TD><input type=text NAME=\"teamtelephone\" size=30></td></tr>
<TR><td><b>Alternative Team Telephone Contact:</b> </td><TD><input type=text NAME=\"teamalternatetelephone\" size=30></td></tr>
<TR><td></td><TD></td></tr>
<TR><td><b>Team Name Last Season:</b> </td><TD><input type=text NAME=\"teamnameold\" size=30> (leave blank if new team)</td></tR>
<TR><td><B>Division Last Season:</b> </td><TD><input type=text NAME=\"divisionold\" size=1> (leave blank if new team)</td></tr>
</table><BR>";

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedTeamName\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Next Step-->\">";

echo "</form>";
echo $teams_already_created;

maintfooter();
 include ('footer.php');
}

### Submitted Team Name
### Submitted Team Name
### Submitted Team Name

function submittedteamname($venueid, $teamname, $teamemail, $teamtelephone, $teamalternatetelephone, $teamnameold, $divisionold, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}
$teamname=ucwords(strtolower($teamname));
$teamnameold=ucwords(strtolower($teamnameold));

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

##
## Make sure all fields are filled in
##
if ($teamname=='')
{
 echo "Somehow you have got this far without filling in all the fields on the previous form. Please return to the previous page and fill in all the fields.";
exit;
}

### Check if team name at venue already exists, then stop from writing new record

$teamresult = $db->sql_query("select COUNT(*) from team_names2 where team_name='$teamname' AND team_venue_id='$venueid'");
$teamcount=$db->sql_fetchrow($teamresult);
$nameexists= $teamcount[0];

if ($nameexists){echo "Sorry, the team name you specified has already been allocated. Please click the back button on your browser and choose another name."; exit;}

### Write team record
 $result=$db->sql_query("insert into team_names2 values (NULL, $venueid, '$teamname', '$teamnameold', '0', '$divisionold', '$teamemail', '$teamtelephone', '$teamalternatetelephone')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }

### Read back in
$result = $db->sql_query("select team_id from team_names2 where team_venue_id='$venueid' AND team_name='$teamname' AND team_name_old='$teamnameold' AND division_old='$divisionold' limit 1");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }
while (list($teamid2) = $db->sql_fetchrow($result))
 {
### Add user to authority file
$teamid=$teamid2;
$result=$db->sql_query("insert into team_authorisation values ('$teamid', '$username')");

 if (!$result) {
   die('Could not write record: ' . mysql_error());
 }
 }

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddPlayers&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Add Players
### Add Players
### Add Players

function addplayers($teamid, $teamname, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3.jpg\"  align=absmiddle><img src=\"/images/step4grey.jpg\"  align=absmiddle></center>";

 echo "<h3><b>Create New Team: Add Players</b></h3>";
 echo "<B>Player names entered here CANNOT be changed. If you do not know the exact name of some of your team members do not enter them. You can come back to this page at any time and add more members to your team without penalty.</b><BR><BR>";

 echo "<FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddPlayers\">;
<input type=hidden NAME=\"teamid\" value=\"$teamid\">
Team Name: <input type=text NAME=\"teamname2\" value=\"$teamname\" disabled>
<input type=hidden NAME=\"teamname\" value=\"$teamname\">
<input type=hidden NAME=\"user\" value=\"$username\"><BR><BR>";
echo "<b>Players added now will only be elligible to play in games from tomorrow.<BR><BR></b>";
 echo "<h4><b>Please enter First and Last names.  Not just initial (e.g. John Smith not J.Smith)</b> </h4>
<BR>";

# Read existing players in
$x=1;

$result = $db->sql_query("select players_playerid, players_playername, players_playerstartdate from team_players where players_teamid='$teamid' order by players_playerid");

while (list($playersplayerid, $playersplayername, $playersplayerstartdate) = $db->sql_fetchrow($result))
{
 echo "<B>Player $x: </b> <input type=text NAME=\"fixedplayer$x\" size=30 value=\"$playersplayername\" disabled>";
  if ($x==1){echo " (Captain)";}
  echo "<BR><BR>";
 $x++;
}

while ($x<21)
{
 echo "<B>Player $x: </b> <input type=text NAME=\"player$x\" size=30 value=\"\">";
 if ($x==1){echo " (Captain)";}
 echo "<BR><BR>";
 $x++;
 }

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedPlayers\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Next Step-->\">";

 echo "</form>";

maintfooter();
 include ('footer.php');
}


### Submitted Players
### Submitted Players   
### Submitted Players

function submittedplayers($teamid, $teamname, $player1, $player2, $player3, $player4, $player5, $player6, $player7, $player8, $player9, $player10, $player11, $player12, $player13, $player14, $player15, $player16, $player17, $player18, $player19, $player20, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

##
## Make sure all fields are filled in
##
#if ($teamname=='')
#{
# echo "Somehow you have got this far without filling in all the fields on the previous form. Please #return to the previous page and fill in all the fields.";
#exit;
#}

# Count existing players
   $playerresult = $db->sql_query("select COUNT(*) from team_players where players_teamid='$teamid'");
   $playercount=$db->sql_fetchrow($playerresult);
   $y= $playercount[0];
$x=$y+1;
$tomorrow = date("Y-m-d", strtotime("tomorrow"));
while($x<21)
{

#$thisplayer=str_replace ( ".", " ", ${"player".$x});
#$thisplayer=ucwords(strtolower($thisplayer));
#$thisplayer=ucwords(strtolower(${"player".$x}));
$thisplayer=ucwords(strtolower(str_replace("."," ",${"player".$x})));

### Write player records
 if ($thisplayer!=''){
    $y++;
 $result=$db->sql_query("insert into team_players values ('$y', '$teamid', '$thisplayer', '$tomorrow')");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
  }
  else
  {
  }
 }
 $x++;
}
### Read back in
#$result = $db->sql_query("select team_id from team_names2 where team_venue_id='$venueid' AND team_name='$teamname' AND teamname_old='$teamnameold' AND division_old='$divisionold' limit 1");
#while (list($teamid) = $db->sql_fetchrow($result))
# {
#### Add user to authority file
#$result=$db->sql_query("insert into team_authorisation values ('$teamid', '$username')");
# }

 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}


### Add Authors
### Add Authors
### Add Authors

function addauthors($teamid, $teamname, $user) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}

echo "<center><img src=\"/images/step1grey.jpg\"  align=absmiddle><img src=\"/images/step2grey.jpg\"  align=absmiddle><img src=\"/images/step3grey.jpg\"  align=absmiddle><img src=\"/images/step4.jpg\"  align=absmiddle></center>";

 echo "<h3><B>Create New Team: Add Team Authors</b></h3>";

 echo "<FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddAuthors\">
Using this form you can add or delete site members as editors of your team. If you do not add any more only you will be able to amend the details about your team. If you do not wish to add them now you can add them at any time in the future.<BR><BR>
<input type=hidden NAME=\"teamid\" value=\"$teamid\">
Team Name: <input type=text NAME=\"teamname2\" value=\"$teamname\" disabled>
<input type=hidden NAME=\"teamname\" value=\"$teamname\">
<input type=hidden NAME=\"user\" value=\"$username\"><BR><BR><B>Current authors:</b><BR>";

# Read existing authors in

$x=0;
$result = $db->sql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
while (list($authorisation_user) = $db->sql_fetchrow($result))
{
 echo "<input type=text NAME=\"author$x\" size=30 value=\"$authorisation_user\" disabled>";
 if ($authorisation_user!=$username){ echo "<a href=\"?op=CreateTeam&step=RemoveAuthor&teamid=$teamid&authorid=$authorisation_user&teamname=$teamname\">remove</a>";}
 echo "<BR><BR>";
$author{$x}=$authorisation_user;
$x++;
}

echo "<select name=\"addauthor\" size=\"10\">";

$result = $db->sql_query("select username from rebelt_users");
$authorexists=0;

while (list($allusers) = $db->sql_fetchrow($result))
{
 for ($i = 0; $i <= $x; $i++)
 {
  if ($allusers==$author{$i}){$authorexists=1;}
 }
 if (!($authorexists)){echo "<option>$allusers</option>";}

$authorexists=0;
}
echo "</select>";

echo  "
<input type=hidden name=\"op\" value=\"CreateTeam\">
<input type=hidden name=\"step\" value=\"SubmittedAuthor\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Add Author\"></form><BR><FORM ACTION=\"maintenance.php\" METHOD=\"POST\" NAME=\"AddAuthors\"><input type=hidden name=\"op\" value=\"Finished\"><input type=hidden name=\"teamid\" value=\"$teamid\"><INPUT TYPE=\"submit\" value=\"Finished-->\">";

 echo "</form>";

maintfooter();
 include ('footer.php');
}


### Submitted Author
### Submitted Author
### Submitted Author

function submittedauthor($teamid, $teamname, $user, $addauthor) {
global $db;
include ('header.php');
maintheader();

### registered user or email address
$username=getusername($user);
if ($username!=''){$email=$username;}

if (!($username)){echo "Sorry, you need to be a registered user to use this area of the site."; exit;}

if (!(isauthorised($teamid, $username))){echo "Not authorised."; exit;}
if ($addauthor==$username){echo "Your name is already in the authors list."; exit;}

##
## Make sure all fields are filled in
##
if ($addauthor=='')
{
 echo "You must select a name from the list in order to add an additional team author. If you do not have any more authors to add, just click the 'Finished' button.";
exit;
}

# Count existing players
   $playerresult = $db->sql_query("select COUNT(*) from team_players where players_teamid='$teamid'");
   $playercount=$db->sql_fetchrow($playerresult);
   $y= $playercount[0];

   $result=$db->sql_query("insert into team_authorisation values ('$teamid', '$addauthor')");
 if (!$result) {
   die('Could not write record: ' . mysql_error());
  }
 $url = "http://mysite.co.uk/maintenance.php?op=CreateTeam&step=AddAuthors&teamid=$teamid&teamname=$teamname";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}



### Finished
### Finished
### Finished

function finished($teamid) {
global $db;
include ('header.php');
maintheader();

 $url = "http://mysite.co.uk/league_cup_exclude.php";
 $delay = "0";
 echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

maintfooter();
 include ('footer.php');
}





###
### Page Header
###
function maintheader(){
echo "<center><H2><B>Pool Team Maintenance</b></h2></center>";
}

###
### Page Footer
###
function maintfooter(){
echo "<BR><BR><center><table width=90% border=1><tr><td align=center width=50%><a href=\"http://mysite.co.uk/maintenance.php\">Home</a></td><td align=center><a href=\"http://mysite.co.uk/maintenance.php?op=ShowMyTeam\">Show My Team</a></td></tr></table></center><BR><BR><BR><BR>";
}


### Get Username
### Get Username
### Get Username
function getusername($user)
{
 $user2 = base64_decode($user);
 $user2 = addslashes($user2);
 $user2 = explode(":", $user2);
 return $user2[1];
}


### URL Forward
### URL Forward
### URL Forward
function urlforward($url)
{
 $delay = "0";
 return "<meta http-equiv=\"refresh\" content=\"".$delay.";url=".$url."\">";
}

### Check authorisation
### Check authorisation
### Check authorisation

function isauthorised($teamid, $username)
global $db;
{
 $result = $db->sql_query("select authorisation_user from team_authorisation where authorisation_teamid='$teamid'");
 while (list($authorisation_user) = $db->sql_fetchrow($result))
 {
  if ($authorisation_user==$username){ return true;}
 }
 return false;
}


###
### Main Entry
###

switch($op) {

    case "CreateTeam":

        switch($step) {
                case "Venue":
                selectvenue($user);
                break;

                case "SubmittedVenue":
                submittedvenue($venuename, $venueoldname, $venueaddress, $venuetown, $venuepostcode, $venuetelephone, $user);
                break;

                case "VenueSelected":
                venueselected($venueid, $venuename, $user);
                break;

                case "SubmittedTeamName":
                submittedteamname($venueid, $teamname, $teamemail, $teamtelephone, $teamalternatetelephone, $teamnameold, $divisionold, $user);
                break;

                case "AddPlayers":
                addplayers($teamid, $teamname, $user);
                break;

                case "SubmittedPlayers":
                submittedplayers($teamid, $teamname, $player1, $player2, $player3, $player4, $player5, $player6, $player7, $player8, $player9, $player10, $player11, $player12, $player13, $player14, $player15, $player16, $player17, $player18, $player19, $player20, $user);
                break;

                case "AddAuthors":
                addauthors($teamid, $teamname, $user);
                break;

                case "SubmittedAuthor":
                submittedauthor($teamid, $teamname, $user, $addauthor);
                break;

                case "RemoveAuthor":
                removeauthor($teamid, $teamname, $user, $authorid);
                break;



}

        case "Admin":

                switch($step)
{
                case "List":
                listrecords($user);
                break;

                case "Allocate":
                allocate($user);
                break;

                case "SubmittedTeamAllocations":
                submittedteamallocations($user, $allchanges);
                break;

                case "AdminDelete":
                admin_delete_team($id, $user);
                break;

                case "Summarise":
                summarise($user);
                break;

      case "RemoveVenue":
      removevenue($venueid, $user);
      break;

      case "RemovePlayer":
                removeplayer($playerid, $teamid, $user);
                break;

                default:
                adminoptions($user);
                break;
}


    case "ListTeams":
        listteams();
        break;

    case "ShowTeam":
        showteam($teamid, $user);
        break;

    case "ShowMyTeam":
        showmyteam($user);
        break;

    case "ListVenues":
        listvenues();
        break;

    case "ShowVenue":
        showvenue($venueid);
        break;

    case "Finished":
        finished($teamid);
        break;

    case "FAQ":
        FAQ();
        break;

    default:
        mainpage();
        break;

}

?>

_________________
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Send e-mail Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17086

PostPosted: Wed Jan 25, 2012 9:38 pm Reply with quote

Hey guys. Here's an idea Idea How about, next time, with this amount of code, you put the code in a .txt file and just supply a link? Wink killing me
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©