Location: PHPKode > projects > Cynus > cynus/info_func.php
<?php
/**
 * @file info_func.php -- Provides functions for self-editing users
 * @Id $Id: info_func.php,v 1.6 2004/06/25 19:13:04 jason Exp $
 *
 * Cynus - a web-based content manager
 * Copyright (C) 2003 Brett and Jason Profitt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

cynus_debug ("Loaded info_func.php", 3);

/***************************
Info Main - string info_main() -
Displays the user's information and allows them 
to edit it.
***************************/
function info_main() {
	global $user_config;
	cynus_debug ("Displaying info main menu", 3);
	$submenu=array(
		'Home' => 'index.php',
		'My Info' => ''
	);
	if($_POST['sent'] == 1) {
		cynus_debug ("Received request.  Checking...");
		#check if the passwords are equal
		#If they change it, we also need to update their password in the cookie
		if($_POST['password1'] != '' && $_POST['password2'] != '') {
			if($_POST['password1']==$_POST['password2']) {
				$enc_pass=crypt($_POST['password1']);
				setcookie('password', $enc_pass, (time() + 604800), '/');
			}
			else{
				$error .= 'Your passwords do not match.<br />' . "\n";
			}
		}
		
		if($error == '') {
			info_update($enc_pass);
			header('Location: info.php');
		}
	}
	$content .= cynus_submenu($submenu);
	$content .= <<<___eofh
<form method="POST" action="info.php">
<input type="hidden" name="sent" value="1">
<table class="table-general">
	<tr>
		<td>Real Name</td>
		<td><input type="text" name="real_name" value="$user_config[real_name]"/></td>
	</tr>
	<tr>
		<td>Password</td>
		<td><input type="password" name="password1" /></td>
	</tr>
	<tr>
		<td>Repeat</td>
		<td><input type="password" name="password2" /></td>
	</tr>
	<tr>
		<td>Email Address</td>
		<td><input type="text" name="email" value="$user_config[email]"/></td>
	</tr>
</table>
You are a
___eofh;
	
	$level = convert_access_level($user_config['level']);
	if($user_config['level']==2) {
		$content .= 'n';
	}
	$content .= <<<___eofh
 $level
 <br />
<br />
<input type="submit" value="Edit Myself" class="button"><br />
<small>Your password will only change if you supply a new one.</small><br />
<br />
</form>
___eofh;
	return $content;
}


/***************************
Info Update - info_update(string $password) -
Takes information from $_POST and updates
the user's information. We're passing $password because
it needed to be encrypted up there ^
***************************/
function info_update($password) {
	global $user_config, $config;
	if($password != '') {
		$password_query="`password`='$password', ";
	}
	$query="UPDATE `$config[sql_prefix]users` SET " . $password_query . "`real_name`='$_POST[real_name]', " . 
		"`email`='$_POST[email]' WHERE `id`='$user_config[id]'";
	mysql_query($query);

}


?>
Return current item: Cynus