change info page basics

This commit is contained in:
Quitta 2013-07-02 16:07:55 +02:00
parent f835f4a85f
commit 8df8d37ffb
5 changed files with 97 additions and 3 deletions

View file

@ -69,6 +69,15 @@ class WebUsers extends Users{
return $row['Email']; 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(){ public function isLoggedIn(){
if(isset($_SESSION['user'])){ 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()){ 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. //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'])){ if(isset($_GET['id'])){
$result = WebUsers::getInfo($_GET['id']);
if(WebUsers::isAdmin() && ($_GET['id']!= $_SESSION['id'])){ if(WebUsers::isAdmin() && ($_GET['id']!= $_SESSION['id'])){
$result['isAdmin'] = "TRUE"; $result['isAdmin'] = "TRUE";
} }
$result['target_id'] = $_GET['id']; $result['target_id'] = $_GET['id'];
$result['current_mail'] = WebUsers::getEmail($_GET['id']); $result['current_mail'] = WebUsers::getEmail($_GET['id']);
}else{ }else{
$result = WebUsers::getInfo($_SESSION['id']);
$result['target_id'] = $_SESSION['id']; $result['target_id'] = $_SESSION['id'];
$result['current_mail'] = WebUsers::getEmail($_SESSION['id']); $result['current_mail'] = WebUsers::getEmail($_SESSION['id']);
} }

View file

@ -21,6 +21,10 @@
`Password` varchar(13) DEFAULT NULL, `Password` varchar(13) DEFAULT NULL,
`Email` varchar(255) NOT NULL DEFAULT '', `Email` varchar(255) NOT NULL DEFAULT '',
`Permission` int(3) NOT NULL DEFAULT 1, `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`) PRIMARY KEY (`UId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams';

View file

@ -136,7 +136,7 @@
</div> </div>
<div class="box-content"> <div class="box-content">
<div class="row-fluid"> <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> <legend>Change Info</legend>
<div class="control-group"> <div class="control-group">
@ -144,7 +144,7 @@
<div class="controls"> <div class="controls">
<div class="input-prepend"> <div class="input-prepend">
<span class="add-on" style="margin-left:5px;"><i class="icon-user"></i></span> <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> </div>
</div> </div>
@ -438,7 +438,8 @@
</div> </div>
<input type="hidden" name="function" value="change_info"> <input type="hidden" name="function" value="change_info">
<input type="hidden" name="target_id" value="{$target_id}">
<div class="control-group"> <div class="control-group">
<label class="control-label"></label> <label class="control-label"></label>
<div class="controls"> <div class="controls">