Location: PHPKode > projects > WH Community > wh_community/address_book.php
<?php require('layout/header.php'); ?>

    <script type="text/javascript">
    	function showSuccessMessage() {
    	showNotification({
    	type : "success",
    	message: "<?php echo $lang['succes_address']; ?>"
    	});
        }

    function showErrorMessage() {
    	showNotification({
    	type : "error",
    	message: "<?php echo $lang['couldnot_adress']; ?>"
    	});
        }
    </script>

<div id="content_wrapper">
    <div class="content"><?php
    
        if(!isset($_SESSION['signed_in'])) {

		echo '<p class="false">' . $lang['just_for_users'] . '!</p>
              <p>' . $lang['you_need_to'] . ' <a href="signin.php">' . $lang['signin_s'] . '</a>.
              - ' . $lang['not_yet'] . ' <a href="signup.php">' . $lang['registered'] . '</a>?</p>';

		}else{

		echo '<h1>' . $lang['address_book'] . '</h1><br>';
		
		$id = $_SESSION['user_id'];

		if($_SERVER['REQUEST_METHOD'] != 'POST') {

		echo '<form method="post" action="">
		      <table width="100%" border="0">
		      <tr>
    		  <td width="20%"><label for="name"><strong><small>' . $lang['name'] . '</small></strong></label><input type="text" name="name" id="name" size="25" maxlength="80" class="fields_address"></td>
    		  <td width="20%"><label for="email"><strong><small>' . $lang['email_adress'] . '</small></strong></label><input type="text" name="email" id="email" size="25" maxlength="100" class="fields_address"></td>
    		  <td width="20%"><label for="phone"><strong><small>' . $lang['phone'] . '</small></strong></label><input type="text" name="phone" id="phone" size="25" maxlength="50" class="fields_address"></td>
    		  <td width="40%"><label for="address"><strong><small>' . $lang['address'] . '</small></strong></label><input type="text" name="address" id="address" size="25" maxlength="120" class="fields_address"> 
    		  <input type="submit" name="' . $lang['add_address'] . '" id="' . $lang['add_address'] . '" class="button_adress" value="' . $lang['add_address'] . '"></td>
              </form>
              </tr>
              </table>';

    		}else{
            
            $errors = array();
            
    		if(isset($_POST['name'])) {
                if(trim($_POST['name']) == "") {
                $errors[] = '<p>' . $lang['enter_a_name'] . '.</p>';
                }
        
        if(!empty($errors)) {

    	echo '<p class="false"><u>' . $lang['not_filled_all'] . '</u></p>
    	      <p>[ <a href="javascript:history.back();">' . $lang['back'] . '</a> ]</p><br>';
    	echo '<ul>';

    	foreach($errors as $key => $value) {
    	echo '<li>' . $value . '</li>';
    	}
    	echo '</ul>';
    	

    		}else{
    		
    		$addbook = "INSERT INTO
					        address(add_id2, name, email, phone, address)
        				VALUES ('" . $id . "',
        					'" . mysql_real_escape_string($_POST["name"]) . "',
        					'" . mysql_real_escape_string($_POST["email"]) . "',
        					'" . mysql_real_escape_string($_POST["phone"]) . "',
        					'" . mysql_real_escape_string($_POST["address"]) . "'
        					)";

		    mysql_query($addbook) OR die(mysql_error());
    		
    		if(mysql_affected_rows() == 1) {
    		
    		$autoforward = 3;
            
    		echo '<p class="right">' . $lang['succes_address'] . '</p>
                  <p><meta http-equiv="refresh" content="' . $autoforward . '; URL=address_book.php">
			      <small>' . $lang['redirected_in'] . ' ' . $autoforward . ' ' . $lang['seconds'] . '...</small></p>';
    		echo "<script type=\"text/javascript\">showSuccessMessage();</script>";
    
    			}else{
    
    			echo '<p class="false">' . $lang['couldnot_adress'] . '</p>';
    			echo "<script type=\"text/javascript\">showErrorMessage();</script>";
    		
            }}}}
        
		$sql = "SELECT * FROM address WHERE add_id2 = '" . $id . "' ORDER BY name DESC";
		
		$result = mysql_query($sql) OR die(mysql_error());
		
		if(intval(mysql_num_rows($result)) == 0) {

		echo '<br><br><p class="false">&nbsp;' . $lang['no_address'] . '.</p>';

			}else{
			
			echo '<br><br>
                  <table width="100%" class="pmtable" cellpadding="5" border="0">
                  <tr>
                  <td width="17%"><strong>' . $lang['name'] . '</strong></td>
                  <td width="28%"><strong>' . $lang['email_adress'] . '</strong></td>
                  <td width="15%"><strong>' . $lang['phone'] . '</strong></td>
                  <td width="30%"><strong>' . $lang['address'] . '</strong></td>
                  <td width="10%" align="right"><strong>' . $lang['delete'] . '</strong></td>
                  </tr>
                  </table>';
            
            echo '<table width="100%" class="addresstable" cellpadding="5" border="0">';

			while($row = mysql_fetch_assoc($result)) {
                
                echo '<tr>
                      <td width="17%"><span class="blue">' . htmlentities($row['name'], ENT_QUOTES) . '</span></td>
                      <td width="28%"><a href="mailto:' . htmlentities($row['email'], ENT_QUOTES) . '">' . htmlentities($row['email'], ENT_QUOTES) . '</a></td>
                      <td width="15%">' . htmlentities($row['phone'], ENT_QUOTES) . '</td>
                      <td width="30%">' . htmlentities($row['address'], ENT_QUOTES) . '</td>
                      <td width="10%" align="right"><a href="delete_add.php?add_id=' . (int)$row['add_id'] . '&add_id2=' . $id . '"><img src="images/delete.png" border="0" title="' . $lang['delete'] . '"></a></td>
                      </tr>';
			          }
			
			echo '</table>';	
            }
		}
        
		echo '<div class="spacer_div">&nbsp;</div>';

		?>
    </div>
</div>

<div id="infobox_wrapper">
    <div class="infobox">
        <?php include('layout/infobox.php'); ?>
    </div>
</div>

<?php require('layout/footer.php'); ?>
Return current item: WH Community