<?php  header('Content-type: text/html; charset=utf-8'); ?>
<html>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<body>
<center><table width=400><tr><td><span class="header1">Editera medlem</span><br>
<?php
	extract($_REQUEST);

	include("../scripts/sqlinfo.inc");
	mysql_connect($host, $user, $pass);
    mysql_selectdb("pyrot");

    if(!$submit && !$edit && !$new && !$spar && !$delete){

		$result=mysql_query("select col_id, namn from medlemmar where status=\"styrelse\"");
		if($r=mysql_fetch_array($result)){
			printf("<b>Styrelse</b><br>");
			do{
				printf("<a href=\"edit_member.php?id=%s&edit=1\">%s</a><br>", $r["col_id"], $r["namn"]);
			}while($r=mysql_fetch_array($result));
		}
		$result=mysql_query("select col_id, namn from medlemmar where status=\"medlem\"");
		if($r=mysql_fetch_array($result)){
			printf("<br><b>Medlemmar</b><br>");
			do{
				printf("<a href=\"edit_member.php?id=%s&edit=1\">%s</a><br>", $r["col_id"], $r["namn"]);
			}while($r=mysql_fetch_array($result));
		}
		$result=mysql_query("select col_id, namn from medlemmar where status=\"provis\"");
		if($r=mysql_fetch_array($result)){
			printf("<br><b>Provmedlemmar</b><br>");
			do{
				printf("<a href=\"edit_member.php?id=%s&edit=1\">%s</a><br>", $r["col_id"], $r["namn"]);
			}while($r=mysql_fetch_array($result));
		}
		$result=mysql_query("select col_id, namn from medlemmar where status=\"utbrand\"");
		if($r=mysql_fetch_array($result)){
			printf("<br><b>Utbrända</b><br>");
			do{
				printf("<a href=\"edit_member.php?id=%s&edit=1\">%s</a><br>", $r["col_id"], $r["namn"]);
			}while($r=mysql_fetch_array($result));
		}
	}
	else if($new){
		?>
		<form method="post" action="edit_member.php">
		<table border=0>
		<tr><td>Namn:</td><td><input type="text" name="namn"></td></tr>
		<tr><td>Telefon:</td><td><input type="text" name="tfn"></td></tr>
		<tr><td>Mobil:</td><td><input type="text" name="mobtfn"></td></tr>
		<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
		<tr><td>ICQ:</td><td><input type="text" name="icq"></td></tr>
		<tr><td>Linje:</td><td><input type="text" name="linje"></td></tr>
		<tr><td>Status:</td><td>
			<select name="status">
			<option value="styrelse">Styrelsen</option>
			<option value="medlem">Medlem</option>
			<option value="provis">Provis</option>
			<option value="utbrand">Utbränd</option>
			</select>
			</td></tr>
		<tr><td>Fotolänk</td><td><input type="text" name="photo"></td></tr>
		<tr><td>Beskrivning:</td><td><textarea name="kommentar"></textarea></td></tr>
		<tr><td> </td><td><input type="submit" name="submit" value="Spara"></td></tr>
		</table>
		</form>
		<?php
		$new=0;
	}
	else if($submit){

		$res = mysql_query("insert into medlemmar values(null, '', '', 0, '$namn', \"$icq\", \"$tfn\",
				\"$mobtfn\", \"$photo\", \"$email\", \"$linje\", \"$status\", \"$kommentar\")");
		if($res==1)
			printf("Ny medlem inlagd...");
		else
			printf("Något gick snett...");
		$submit=0;
	}
	else if($edit){

		$result=mysql_query("select * from medlemmar where col_id = " . $id);
		$r=mysql_fetch_array($result);
	?>
		<form method="post" action="edit_member.php?id=<?php echo $id; ?>">
		<table border=0>
		<input type='hidden' name='id' value='<?php echo $id; ?>'>
		<tr><td>Namn:</td><td><input type="text" name="namn" value="<?php echo $r["namn"]; ?>"></td></tr>
		<tr><td>Telefon:</td><td><input type="text" name="tfn" value="<?php echo $r["tfn"]; ?>"></td></tr>
		<tr><td>Mobil:</td><td><input type="text" name="mobtfn" value="<?php echo $r["mobtfn"]; ?>"></td></tr>
		<tr><td>Email:</td><td><input type="text" name="email" value="<?php echo $r["email"]; ?>"></td></tr>
		<tr><td>ICQ:</td><td><input type="text" name="icq" value="<?php echo $r["icq"]; ?>"></td></tr>
		<tr><td>Linje:</td><td><input type="text" name="linje" value="<?php echo $r["linje"]; ?>"></td></tr>
		<tr><td>Status:</td><td>
			<select name="status">
			<option value="<?php echo $r["status"]; ?>"><?php echo $r["status"]; ?></option>
			<option value="styrelse">Styrelsen</option>
			<option value="medlem">Medlem</option>
			<option value="provis">Provis</option>
			<option value="utbrand">Utbränd</option>
			</select>
			</td></tr>
		<tr><td>Fotolänk</td><td><input type="text" name="photo" value="<?php echo $r["photo"]; ?>"></td></tr>
		<tr><td>Beskrivning:</td><td><textarea name="kommentar"><?php echo $r["kommentar"]; ?></textarea></td></tr>
		<tr><td> </td><td><input type="submit" name="spar" value="Spara"></td></tr>
		</table>
		</form>
		<?php
		printf("<a href=\"edit_member.php?delete=1&id=%s\">Ta bort helt</a>",$id); 
		$edit=0;
	} else if($spar) {
		//mysql_query("delete from medlemmar where namn=\"$namn1\"");
		//$res = mysql_query("insert into medlemmar values(null, \"$namn\", \"$icq\", \"$tfn\",
		//		\"$mobtfn\", \"$photo\", \"$email\", \"$linje\", \"$status\", \"$kommentar\")");

		$res = mysql_query("update medlemmar set namn = '" . $namn . "', icq = '" . $icq . "', tfn = '" . $tfn . "', " .
					"mobtfn = '" . $mobtfn . "', photo = '" . $photo . "', email = '" . $email . "', " .
					"linje = '" . $linje . "', status = '" . $status . "', kommentar = '" . $kommentar . "' " .
					"where col_id = " . $id);
		if($res=1)
			printf("Medlem uppdaterad");
		else
			printf("Något gick snett...");
		$spar=0;
	}
	else if($delete){
		mysql_query("delete from medlemmar where col_id = " . $id);
		$delete=0;
	}
	printf("<br><a href=\"edit_member.php?new=1\"><b>Lägg till ny medlem<b></a><br><br>");

?>
</td></tr></table></center>
</body>
</html>
