<?php
switch ($data['Register']) {
case "Register your group": 
{
/*connecting, selecting database*/

$link = database_open();

/* find highest id */
$temp = @mysql_query("SELECT MAX(id) FROM directory");
$id = (@mysql_result($temp,0)) +1;

// first check that we're not trying to duplicate a group...

$query = "SELECT id FROM directory WHERE name = '" . $data['name']."'";
$result = mysql_query($query);
if (mysql_num_rows($result)==0)
{
	// we're clear, so off we go...

	/*compose strings from checked boxes : */

	$focus = "";
	if (array_key_exists('focus', $data))
	{
		foreach($data['focus'] as $temp) {$focus = $focus . $temp . " ";}
	}

	$methods = "";
	if (array_key_exists('method', $data))
	{
		foreach($data['method'] as $temp) {$methods = $methods . $temp . " ";}
	}

	$today=date('Y-m-d');

	if (trim($data['founded']) == "") $data['founded'] = "\0";

	/*create query*/

	$query = "INSERT into directory values ('{$id}', '{$data['name']}', '{$data['contact']}', '{$data['description']}', '{$data['location']}', '-', '{$data['country']}', '{$data['tel']}', '{$data['fax']}', '{$data['email']}', '{$data['web']}', '{$data['founded']}', '{$focus}', '{$data['languages']}', '{$methods}', '{$data['extent']}', '{$data['org_is']}', '0', '{$today}', '0', '{$data['webcomments']}')";

	/* perform insert and report back*/
	if (mysql_query($query))
	{ ?>
      <h1>Thank you for registering your group</h1>
<p>Your directory entry has been successfully processed. It will be reviewed before going onto
the web site, so you will not see it in the directory immediately.</p>

<p>Please consider placing one of our <a href="Javascript:changeTabs(7)">logos</a> on your website in order to promote these Carfree Green Pages. We appreciate your support.</p>
<form method="post" action="<?echo $PHP_SELF?>">
<input type=submit class="go" value="Show Form Again" name="Register">
</form>
<?php
	} else clean_die("Could not execute query (" . mysql_error() . ")");
}
else
{
	// already have an entry like this... ?>
     <h1>Could not submit registration</h1>
<p>A group with this name already exists within the database. Please contact us at <SCRIPT TYPE="text/javascript">
  email1=('web'); email2=('worldcarfree.net')	
  document.write(
    '<A href="mailto:' + email1 + '&#64;' + email2 + '">' 
    + email1 + '&#64;' + email2 + '</a>'
  )
</SCRIPT> if there is a problem. To update an existing record, please select "Update Record".</p>
<form method="post" action="<?echo $PHP_SELF?>">
<input type=submit class="go" value="Try Again" name="Register">
</form>
<?php
}
/* Closing connection */
@mysql_close($link);
}
break;
case "Try Again":
case "Register another group":
default:
 {
?>

<form method="post" action="<?echo $PHP_SELF?>">
<table>
<tr> <td width=30% align=right> &nbsp; </td>
<td width = 70%><a href="Javascript:changeTabs(4)">See the guidelines to
filling in this form.</a></td> </tr>

<tr> <td width=30% align=right><em>Name of the group</em></td>
<td width = 70%><input type=text class=text name="name" size="43"></td> </tr>

<tr> <td width=30% align=right valign=top><em>Address<BR>(Use <b>English</b> city name)</em></td>
<td width = 70%><textarea name="location" cols=40 rows=3></textarea></td> </tr>

<tr> <td width=30% align=right><em>Country</em></td>
<td width = 70%><select name="country">
<option name=country selected value="">Select a country</option>
<?php 
foreach ($countries as $key => $value)
  $result1 = array_merge($result1,$value);
 sort($result1);
 while (list($key,$val) = each($result1))
  printf("<option name=country value=\"%s\">%s\n",$val,$val);
?>
</select>
</td> </tr>

<tr> <td width=30% align=right><em>Contact Name</em></td>
<td width = 70%><input type=text class=text name="contact" size = "43"></td> </tr>

<tr> <td width=30% align=right><em>Telephone no</em></td>
<td width = 70%><input type=text class=text name="tel" size="43"></td> </tr>

<tr> <td width=30% align=right><em>Fax no</em></td>
<td width = 70%><input type=text class=text name="fax" size="43"></td> </tr>

<tr> <td width=30% align=right><em>E-mail</em></td>
<td width = 70%><input type=text class=text name="email" size="43">&nbsp;<em>(Our directory is spam-proof)</em></td> </tr>

<tr> <td width=30% align=right><em>Web address</em></td>
<td width = 70%><input type=text class=text name="web" size="43"></td> </tr>

<tr> <td width=30% align=right valign=top><em>Year organisation founded<br><font size=-1>(if known)</font></em></td>
<td width = 70%><input type=text class=text name="founded" size = "43"></td> </tr>

<tr> <td width=30% align=right valign=top><em>Select area(s) of focus:<BR>(No more than <b>three</b>)</em></td>
<td width = 70%>
<table>
<tr><td align = left>
<!--
<input type=checkbox name="focus[]" value="AIRT"> Air Transport<br>
-->
<input type=checkbox name="focus[]" value="TECH"> Alternative Technologies<BR>
<input type=checkbox name="focus[]" value="CORP"> Anti-Corporate/Globalisation<BR>
<input type=checkbox name="focus[]" value="CARF"> Car-Free/Anti-Car<BR>
<input type=checkbox name="focus[]" value="CITI"> Cities & Public Space<BR>
<input type=checkbox name="focus[]" value="CLIM"> Climate Change<BR>
<input type=checkbox name="focus[]" value="CYCL"> Cycling<BR>
<!--
<input type=checkbox name="focus[]" value="INDU"> Oil/Auto Industries<BR>-->
</td><td align=left>
<input type=checkbox name="focus[]" value="PEDE"> Pedestrians/Walking<BR>
<!--
<input type=checkbox name="focus[]" value="POLL"> Pollution/Heath<BR>
-->
<input type=checkbox name="focus[]" value="PUBT"> Public Transport<BR>
<!--
<input type=checkbox name="focus[]" value="RESD"> Resource Depletion<BR>
-->
<input type=checkbox name="focus[]" value="RDBL"> Road Building/Habitat Protection<BR>
<input type=checkbox name="focus[]" value="RDSF"> Road Safety/Road Deaths<BR>
<input type=checkbox name="focus[]" value="TRAF"> Traffic Reduction/Calming<BR>
</td></tr></table>
</td> </tr>

<tr> <td width=30% align=right valign=top><em>Please give a <strong>short</strong> description of the group:<br><font size=-1>(please name any publications you produce)</font></em></td>
<td width = 70%><textarea name="description" wrap=virtual cols=40 rows=5></textarea><br><font size=-1>Long descriptions may by edited down.</font></td> </tr>

<tr></tr>

<tr> <td width=30% align=right valign=top><em>Language(s) spoken by your organisation</em></td>
<td width = 70%><input type=text class=text name="languages" size = "43"><br><i><font size=-1>Please give language names in <b>English</b></font></i></td> </tr>

<tr></tr>

<tr> <td width=30% align=right  valign=top><em>Please select which activities your group engages in:<BR>(No more than <b>three</b>)</em></td>
<td width = 70% align=left>
<input type=checkbox name="method[]" value="PLAN"> Consultancy/Urban Planning<BR>
<input type=checkbox name="method[]" value="DIRA"> Direct Action (Protests)<br>
<input type=checkbox name="method[]" value="EDUC"> Education/Training<BR>
<input type=checkbox name="method[]" value="MONI"> Industry Monitoring<BR>
<input type=checkbox name="method[]" value="LOBB"> Lobbying/Political Advocacy<BR>
<input type=checkbox name="method[]" value="MEDI"> Information (Publications, websites)<BR>
<input type=checkbox name="method[]" value="INFO"> Public Media Campaigns<BR>
<input type=checkbox name="method[]" value="RESE"> Research/Scientific Studies<BR>
</td> </tr>

<tr></tr>

<tr> <td width=30% align=right valign=top><em>Geographic Scope:</em></td>
<td width = 70% align=left>
<input type=radio name="extent" value = "L" checked> Local/Regional<BR>
<input type=radio name="extent" value = "N"> National<BR>
<input type=radio name="extent" value = "I"> International<BR>
</td></tr>

<tr></tr>

<tr> <td width=30% align=right valign=top><em>Type of Organisation:</em></td>
<td width = 70% align=left>
<input type=radio name="org is" value = "N" checked> Non-profit<BR>
<input type=radio name="org is" value = "G"> Governmental<BR>
<input type=radio name="org is" value = "C"> Commercial<BR>
<input type=radio name="org is" value = "A"> Academic<BR>
<input type=radio name="org is" value = "W"> Website (blog, etc.)<BR>
<input type=radio name="org is" value = "O"> Other<BR>
</td></tr>

<tr> <td width=30% align=right valign=top> &nbsp; </td>
<td width = 70% align=left> 
<input type=submit class="go" value="Register your group" name="Register"></td></tr>
</table>
</form>
<p>World Carfree Network reserves the right to determine which groups are appropriate for inclusion in the Carfree Green Pages.</p>
<?php } 
break;
}
?>