change info page basics

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-07-02 16:07:55 +02:00
parent a1a052dd72
commit d3b12f74a4
5 changed files with 97 additions and 3 deletions

View file

@ -69,6 +69,15 @@ class WebUsers extends Users{
return $row['Email'];
}
public function getInfo($id){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
$result = Array('FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Gender' => $row['Gender'], 'Country' => $row['Country']);
return $result;
}
public function isLoggedIn(){
if(isset($_SESSION['user'])){

View file

@ -0,0 +1,78 @@
<?php
function change_info(){
try{
//if logged in
if(WebUsers::isLoggedIn()){
if(isset($_POST['target_id'])){
if( ($_POST['target_id'] == $_SESSION['id']) || WebUsers::isAdmin() ){
if($_POST['target_id'] == $_SESSION['id']){
$target_username = $_SESSION['user'];
}else{
$target_username = WebUsers::getUsername($_POST['target_id']);
}
$webUser = new WebUsers();
$reply = $webUser->checkEmail($_POST['NewEmail']);
if ( $reply != "success" ){
$result['EMAIL_ERROR'] = 'TRUE';
}else{
$result['EMAIL_ERROR'] = 'FALSE';
}
$result['prevNewEmail'] = $_POST["NewEmail"];
if ($reply== "success"){
$status = WebUsers::setEmail($target_username, $_POST["NewEmail"] );
if($status == 'ok'){
$result['SUCCESS_MAIL'] = "OK";
}else if($status == 'shardoffline'){
$result['SUCCESS_MAIL'] = "SHARDOFF";
}
$result['permission'] = $_SESSION['permission'];
$result['no_visible_elements'] = 'FALSE';
$result['target_id'] = $_POST['target_id'];
if(isset($_GET['id'])){
if(WebUsers::isAdmin() && ($_POST['target_id'] != $_SESSION['id'])){
$result['isAdmin'] = "TRUE";
}
}
helpers :: loadtemplate( 'settings', $result);
exit;
}else{
$result['EMAIL'] = $reply;
$result['permission'] = $_SESSION['permission'];
$result['no_visible_elements'] = 'FALSE';
$return['username'] = $_SESSION['user'];
$result['target_id'] = $_POST['target_id'];
if(isset($_GET['id'])){
if(WebUsers::isAdmin() && ($_POST['target_id'] != $_SESSION['id'])){
$result['isAdmin'] = "TRUE";
}
}
helpers :: loadtemplate( 'settings', $result);
exit;
}
}else{
//ERROR: permission denied!
}
}else{
//ERROR: The form was not filled in correclty
}
}else{
//ERROR: user is not logged in
exit;
}
}catch (PDOException $e) {
//go to error page or something, because can't access website db
print_r($e);
exit;
}
}

View file

@ -4,12 +4,14 @@ function settings(){
if(WebUsers::isLoggedIn()){
//in case id-GET param set it's value as target_id, if no id-param is given, ue the session id.
if(isset($_GET['id'])){
$result = WebUsers::getInfo($_GET['id']);
if(WebUsers::isAdmin() && ($_GET['id']!= $_SESSION['id'])){
$result['isAdmin'] = "TRUE";
}
$result['target_id'] = $_GET['id'];
$result['current_mail'] = WebUsers::getEmail($_GET['id']);
}else{
$result = WebUsers::getInfo($_SESSION['id']);
$result['target_id'] = $_SESSION['id'];
$result['current_mail'] = WebUsers::getEmail($_SESSION['id']);
}

View file

@ -21,6 +21,10 @@
`Password` varchar(13) DEFAULT NULL,
`Email` varchar(255) NOT NULL DEFAULT '',
`Permission` int(3) NOT NULL DEFAULT 1,
`FirstName` varchar(255) NOT NULL DEFAULT '',
`LastName` varchar(255) NOT NULL DEFAULT '',
`Gender` tinyint(1) unsigned NOT NULL DEFAULT '0',
`Country` char(2) NOT NULL DEFAULT '',
PRIMARY KEY (`UId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams';

View file

@ -136,7 +136,7 @@
</div>
<div class="box-content">
<div class="row-fluid">
<form id="changeEmail" class="form-vertical" method="post" action="index.php">
<form id="changeEmail" class="form-vertical" method="post" action="index.php?page=settings&id={$target_id}">
<legend>Change Info</legend>
<div class="control-group">
@ -144,7 +144,7 @@
<div class="controls">
<div class="input-prepend">
<span class="add-on" style="margin-left:5px;"><i class="icon-user"></i></span>
<input type="text" class="input-xlarge" id="Firstname" name="Firstname" placeholder="Your firstname">
<input type="text" class="input-xlarge" id="Firstname" name="Firstname" placeholder="Your firstname" {if isset($FirstName) and $FirstName neq ""}value="{$FirstName}"{/if}>
</div>
</div>
</div>
@ -439,6 +439,7 @@
<input type="hidden" name="function" value="change_info">
<input type="hidden" name="target_id" value="{$target_id}">
<div class="control-group">
<label class="control-label"></label>
<div class="controls">