208 lines
7.4 KiB
PHP
208 lines
7.4 KiB
PHP
|
<?php
|
||
|
if( !isset( $_SESSION ) ) session_start();
|
||
|
$_SESSION['messagep']='';
|
||
|
$_SESSION['messagee']='';
|
||
|
$_SESSION['messagea']='';
|
||
|
$_SESSION['messageas']='';
|
||
|
$_SESSION['messageam']='';
|
||
|
$_SESSION['messageab']='';
|
||
|
$_SESSION['messagefb']='';
|
||
|
$_SESSION['messagetw']='';
|
||
|
if(empty($_SESSION['user'])){
|
||
|
header('Location: login.php');
|
||
|
}
|
||
|
include "../settings/db_connect.php";
|
||
|
|
||
|
$user=$_SESSION['user'];
|
||
|
$password=$_SESSION['password'];
|
||
|
$data = mysqli_query($mysqli, "SELECT * FROM user WHERE password='$password' AND username='$user'");
|
||
|
$row = mysqli_fetch_array($data);
|
||
|
$about_short = $row['about_short'];
|
||
|
$about_me = $row['about_me'];
|
||
|
$about_blog = $row['about_blog'];
|
||
|
|
||
|
if(isset($_POST['password_change'])){
|
||
|
if(!empty($_POST['password']) && !empty($_POST['newpassword']) && !empty($_POST['confirmpassword'])) {
|
||
|
if($password != md5($_POST['newpassword'])) {
|
||
|
if($_POST['newpassword'] == $_POST['confirmpassword']) {
|
||
|
if(md5($_POST['password']) == $password) {
|
||
|
$newpassword=md5($_POST['newpassword']);
|
||
|
$sql = "UPDATE user SET password='$newpassword' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['user']=$user;
|
||
|
$_SESSION['password']=$newpassword;
|
||
|
$_SESSION['loggedIn']=1;
|
||
|
$_SESSION['messagep'] = "Hasło zostało zmienione!";
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagep'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
mysqli_close($mysqli);
|
||
|
}
|
||
|
else {
|
||
|
$_SESSION['messagep'] = "Błędne hasło!";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagep'] = "Potwierdź hasło ponownie";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagep'] = "Nowe hasło nie może być takie samo jak obecne";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagep'] = "Należy wypełnić wszystkie wmagane pola";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['email_change'])){
|
||
|
$email=$row['email'];
|
||
|
if(!empty($_POST['password']) && !empty($_POST['newemail']) && !empty($_POST['confirmemail'])) {
|
||
|
if($email != md5($_POST['newemail'])) {
|
||
|
if($_POST['newemail'] == $_POST['confirmemail']) {
|
||
|
if(md5($_POST['password']) == $password) {
|
||
|
$newemail=$_POST['newemail'];
|
||
|
$sql = "UPDATE user SET email='$newemail' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messagee'] = "email został zmieniony!";
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagee'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
mysqli_close($mysqli);
|
||
|
}
|
||
|
else {
|
||
|
$_SESSION['messagee'] = "Błędne hasło!";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagee'] = "Potwierdź email ponownie";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagee'] = "Nowy email nie może być taki sam jak obecny";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagee'] = "Należy wypełnić wszystkie wmagane pola";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['avatar_change'])){
|
||
|
$currentavatar = $row['avatar'];
|
||
|
$avatar_path = $mysqli->real_escape_string('../images/avatars/'.$_FILES['avatar']['name']);
|
||
|
if (preg_match("!image!", $_FILES['avatar']['type'])){
|
||
|
if(copy($_FILES['avatar']['tmp_name'], $avatar_path)){
|
||
|
$sql = "UPDATE user SET avatar='$avatar_path' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
if($currentavatar != $avatar_path){
|
||
|
unlink($currentavatar);
|
||
|
}
|
||
|
$_SESSION['messagea'] = "avatar został zmieniony!";
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagea'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
mysqli_close($mysqli);
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagea'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagea'] = "Plik musi byc graficzny\n";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['aboutshort_change'])){
|
||
|
$newabout_short = $_POST['aboutshort'];
|
||
|
if($about_short != $newabout_short){
|
||
|
$sql = "UPDATE user SET about_short='$newabout_short' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messageas'] = "Zmiany zostały zatwierdzone!";
|
||
|
$about_short = $row['about_short'];
|
||
|
header('Location: account_settings.php');
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageas'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageas'] = "Brak zmian";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['aboutme_change'])){
|
||
|
$newabout_me = $_POST['aboutme'];
|
||
|
if($about_me != $newabout_me){
|
||
|
$sql = "UPDATE user SET about_me='$newabout_me' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messageam'] = "Zmiany zostały zatwierdzone!";
|
||
|
$about_me = $row['about_me'];
|
||
|
header('Location: account_settings.php');
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageam'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageam'] = "Brak zmian";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['aboutblog_change'])){
|
||
|
$newabout_blog = $_POST['aboutblog'];
|
||
|
if($about_blog != $newabout_blog){
|
||
|
$sql = "UPDATE user SET about_blog='$newabout_blog' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messageab'] = "Zmiany zostały zatwierdzone!";
|
||
|
$about_blog = $row['about_blog'];
|
||
|
header('Location: account_settings.php');
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageab'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messageab'] = "Brak zmian";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(isset($_POST['face_change'])){
|
||
|
if(!empty($_POST['FB'])) {
|
||
|
$face = $row['FB'];
|
||
|
$newface = $_POST['FB'];
|
||
|
if($face != $newface) {
|
||
|
$sql = "UPDATE user SET FB='$newface' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messagefb'] = "Zmiany zostały zatwierdzone!";
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagefb'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagefb'] = "Brak zmian";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(isset($_POST['twit_change'])){
|
||
|
if(!empty($_POST['TW'])) {
|
||
|
$twit = $row['FB'];
|
||
|
$newtwit = $_POST['TW'];
|
||
|
if($twit != $newtwit) {
|
||
|
$sql = "UPDATE user SET TW='$newtwit' WHERE password='$password' AND username='$user'";
|
||
|
if($mysqli->query($sql) === true){
|
||
|
$_SESSION['messagetw'] = "Zmiany zostały zatwierdzone!";
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagetw'] = "Coś poszło nie tak, spróbuj ponownie później.";
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['messagetw'] = "Brak zmian";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|