Location: PHPKode > projects > GWAAU > medlemmer.php
<?php

require_once('lib/main.php');
require_once('lib/database.php');
require_once('pre.php');

$arr_heads["Medlemmer"] = "medlemmer";
$arr_tails[""] = "";

switch ($_REQUEST["mode"]) {
  case "view_all":
  print content(liste());
  break;
  
  case "edit":
		$arr_tails["Oversigt"] = "view_all";
		print content(edit($_REQUEST["user_id"]));
  break;
  
  case "viseditpass":
		$arr_tails["Oversigt"] = "view_all";
		print content(viseditpass($_REQUEST["user_id"]));
  break;
  
  case "editpass":
		$arr_tails["Oversigt"] = "view_all";
		print content(editpass ($_REQUEST["new_pass1"],$_REQUEST["new_pass2"],$_REQUEST["old_pass"],getUsername($_REQUEST["user_id"])));
  break;

  case "update":
	    print content(edit_update($_REQUEST["user_id"], $_REQUEST["navn"], $_REQUEST["adresse"], $_REQUEST["postnummer"], $_REQUEST["tlf"], $_REQUEST["email"]));
  break;
  
  case "view_one":
		$arr_tails["Oversigt"] = "view_all";
		if (strtolower($_REQUEST["user_name"])==strtolower(getUsername($_REQUEST["user_id"]))){
		$arr_tails["Ret personlige oplysninger"] = "edit&user_id=$_REQUEST[user_id]";
		$arr_tails["Skift kodeord"] = "viseditpass&user_id=$_REQUEST[user_id]";
		}
		print content(info($_REQUEST["user_id"], $_REQUEST["user_id"]));
  break;
  default:
//			print info(1);
				print content(liste());
}


function liste() {
  $output="<table width='100%'>";
  $sql="SELECT * FROM user ORDER BY real_name";
  $result=db_query($sql);
	while ($field = db_fetch_array($result)) {
    	$output.="<tr><td><a href='?mode=view_one&user_id=$field[user_id]' title='Vis information om medlemmet'>".$field[real_name]. "</a><br></td></tr>"; 
		   }
		
		return $output;	
}

function info($user_id) {
    $output="";
  $sql="SELECT * FROM user WHERE user_id=$user_id";
//  $sql="SELECT * FROM user";
  $result=db_query($sql);
  if ($arr_field = db_fetch_array($result)) {
   	$output.="<table width='100%'>
			<tr>
				<td>&nbsp;</td>
				<td colspan='2'>Personlige oplysninger:</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>Navn:</td>
				<td>$arr_field[real_name]</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>Adresse:</td>
				<td>$arr_field[adresse]</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>Post nr.:</td>
				<td>$arr_field[postnummer]</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>Tlf. Nr.:</td>
				<td>$arr_field[telefonnummer]</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>Email:</td>
				<td><a href=mailto:$arr_field[email]>$arr_field[email]</a></td>
				<td>&nbsp;</td>
			</tr>
			</table>";
	
	return $output;
  }
}

function edit($user_id) {
  $output="";
  $sql="SELECT * FROM user WHERE user_id=$user_id";
  $result=db_query($sql);
  if ($arr_field = db_fetch_array($result)) {
    $output.="<FORM action='?mode=update' method='POST'>";
	$output.="<input type='hidden' name='user_id' value='$arr_field[user_id]'>";
	$output.="<table width='100%'>";
	$output.="<tr>
				<td>&nbsp;</td>
				<td colspan='2'>Ret personlige oplysninger</td>
				
				</tr>
			<tr>
				<td>Navn:</td>
				<td><input type='text' name='navn' value='$arr_field[real_name]'></td>
			</tr>
			
			<tr>
				<td>Adresse:</td>
				<td><input type='text' name='adresse' value='$arr_field[adresse]'></td>
			</tr>
			
			<tr>
				<td>Post nr.:</td>
				<td><input type='text' name='postnummer' value='$arr_field[postnummer]'></td>
			</tr>
			
			<tr>
				<td>Tlf.:</td>
				<td><input type='text' name='tlf' value='$arr_field[telefonnummer]'></td>
			</tr>
			
			<tr>
			<td>Email:</td>
				<td><input type='text' name='email' value='$arr_field[email]'></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type='submit' value='Gem' class='button'></td>
				<td>&nbsp;</td>
			</tr>
			</table></form>";

	return $output;
  }
}

//Lars' funktion til at vise en skærm hvor man kan ændre password

function viseditpass($user_id) {
  $output="";
    $output.="<FORM action='?mode=editpass' method='POST'>";
	$output.="<input type='hidden' name='user_id' value='$user_id'>";
	$output.="<table width='100%'>";
	$output.='<H3>Skift kodeord</H3>
	<P>
	Udfyld følgende form, for at skifte dit nuværende kodeord.
	<P>
	<B>Gammelt kodeord:</B><BR>
	<INPUT TYPE="password" NAME="old_pass" VALUE="" SIZE="10" MAXLENGTH="15">
	<P>
	<B>Nyt kodeord:</B><BR>
	<INPUT TYPE="password" NAME="new_pass1" VALUE="" SIZE="10" MAXLENGTH="15">
	<P>
	<B>Gentag nyt kodeord:</B><BR>
	<INPUT TYPE="password" NAME="new_pass2" VALUE="" SIZE="10" MAXLENGTH="15">
	<P>
	<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Skift kodeord">
	</FORM>';
  
	return $output;
	}

//funktion der foretager rettelser i password
function editpass($new_pass1,$new_pass2,$old_pass,$user_name) {
	global $feedback;
	//new passwords present and match?
	if ($new_pass1 && ($new_pass1==$new_pass2)) {
		//is this password long enough?
			if  ($old_pass) {
				$old_pass=strtolower($old_pass);
				$new_pass1=strtolower($new_pass1);
				$new_pass2=strtolower($new_pass2);
				$sql="SELECT * FROM user WHERE user_name='$user_name' AND password='". md5($old_pass) ."'";
				$result=db_query($sql);
				if (!$result || db_numrows($result) < 1) {
					$feedback .= ' Forkert brugernavn eller password '.db_error();
					return false;
				} else {
					$sql="UPDATE user SET password='". md5($new_pass1). "' ".
						"WHERE user_name='$user_name' AND password='". md5($old_pass). "'";
					$result=db_query($sql);
					if (!$result || db_affected_rows($result) < 1) {
						$feedback .= ' Der er ikke foretaget nogle ændringer '.db_error();
						return false;
					} else {
						$feedback .= ' Dit kodeord er ændret ';
						//return true;
					}
				}
			} else {
				$feedback .= ' Mangler gammelt kodeord ';
				return false;
			}
		} else {
			$feedback .= ' Der opstod et problem med dit nye kodeord ';
			return false;
		}
}


function getUsername($user_id)
{
	$sql = "SELECT * FROM user WHERE user_id=$user_id";
	$result=db_query($sql);
	return db_result($result, 0, "user_name");
}


function edit_update($user_id,$navn,$adresse,$postnummer,$tlf,$email)
{
	$sql = "UPDATE user SET real_name='$navn', adresse='$adresse',postnummer='$postnummer',telefonnummer='$tlf',email='$email'  WHERE user_id=$user_id";
	
	if ( db_query($sql) ) {
		
		header("location:medlemmer.php?mode=view_one&user_id=$user_id");
	}
	else {
		
		return $sql."<hr/>";
	}
}

?>
Return current item: GWAAU