'.mysqli_error($db));
}
mysqli_select_db($db, $mysql_database) or die('Failed to select database
'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
$sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
$result = mysqli_query($db, $sql);
if ($data = mysqli_fetch_array($result))
{
$error_message = 'Meno a priezvisko sa už používa. Pridajte nejaký Váš osobný údaj, napríklad rok narodenia.';
}
}
if (empty($error_message))
{
$crypt_pass = md5($newpassword);
$newusername = mysqli_real_escape_string($db, $newusername);
$newemail = mysqli_real_escape_string($db, $newemail);
$newfullname = mysqli_real_escape_string($db, $newfullname);
$sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`, `code`, `role`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 0, '$code', 'Member')";
$result = mysqli_query($db, $sql);
mysqli_close($db);
$subject = 'Váš účet';
$message = 'Nový podielnik do spoločenstva';
$message .= "\r\nUsername: ";
$message .= $newusername;
$message .= "\r\nPassword: ";
$message .= $newpassword;
$message .= "\r\n";
$header = "From: webmaster@yourwebsite.com"."\r\n";
$header .= "Reply-To: webmaster@yourwebsite.com"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($newemail, $subject, $message, $header);
mail('starosta@krivany.sk', $subject, $message, $header);
header('Location: '.$success_page);
exit;
}
}
session_start();
if (!isset($_SESSION['username']))
{
$accessdenied_page = '';
header('Location: '.$accessdenied_page);
exit;
}
$mysql_server = '46.229.230.163';
$mysql_username = 'op021100';
$mysql_password = 'ryregono';
$mysql_database = 'op021100db';
$mysql_table = 'Krivany';
$error_message = '';
$db_username = '';
$db_fullname = '';
$db_email = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'editprofileform')
{
$success_page = '';
$oldusername = $_SESSION['username'];
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
if ($newpassword != $confirmpassword)
{
$error_message = 'Password and Confirm Password are not the same!';
}
else
if (!preg_match("/^[A-Za-z0-9-_!@$]{1,50}$/", $newusername))
{
$error_message = 'Username is not valid, please check and try again!';
}
else
if (!empty($newpassword) && !preg_match("/^[A-Za-z0-9-_!@$]{1,50}$/", $newpassword))
{
$error_message = 'Password is not valid, please check and try again!';
}
else
if (!preg_match("/^[A-Za-z0-9-_!@$.' &]{1,50}$/", $newfullname))
{
$error_message = 'Fullname is not valid, please check and try again!';
}
else
if (!preg_match("/^.+@.+\..+$/", $newemail))
{
$error_message = 'Email is not a valid email address. Please check and try again.';
}
else
{
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!
'.mysqli_error($db));
}
mysqli_select_db($db, $mysql_database) or die('Failed to select database
'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
if ($oldusername != $newusername)
{
$sql = "SELECT username FROM ".$mysql_table." WHERE username = '".mysqli_real_escape_string($db, $newusername)."'";
$result = mysqli_query($db, $sql);
if ($data = mysqli_fetch_array($result))
{
$error_message = 'Username already used. Please select another username.';
}
}
if (empty($error_message))
{
$crypt_pass = md5($newpassword);
$newusername = mysqli_real_escape_string($db, $newusername);
$newemail = mysqli_real_escape_string($db, $newemail);
$newfullname = mysqli_real_escape_string($db, $newfullname);
$sql = "UPDATE `".$mysql_table."` SET `username` = '$newusername', `fullname` = '$newfullname', `email` = '$newemail' WHERE `username` = '$oldusername'";
mysqli_query($db, $sql);
if (!empty($newpassword))
{
$sql = "UPDATE `".$mysql_table."` SET `password` = '$crypt_pass' WHERE `username` = '$oldusername'";
mysqli_query($db, $sql);
}
}
mysqli_close($db);
if (empty($error_message))
{
$_SESSION['username'] = $newusername;
$_SESSION['fullname'] = $newfullname;
header('Location: '.$success_page);
exit;
}
}
}
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!
'.mysqli_error($db));
}
mysqli_select_db($db, $mysql_database) or die('Failed to select database
'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
$sql = "SELECT * FROM ".$mysql_table." WHERE username = '".$_SESSION['username']."'";
$result = mysqli_query($db, $sql);
if ($data = mysqli_fetch_array($result))
{
$db_username = $data['username'];
$db_fullname = $data['fullname'];
$db_email = $data['email'];
}
mysqli_close($db);
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'loginform')
{
$success_page = './podielnici.html';
$error_page = basename(__FILE__);
$mysql_server = '46.229.230.163';
$mysql_username = 'op021100';
$mysql_password = 'ryregono';
$mysql_database = 'op021100db';
$mysql_table = 'Krivany';
$crypt_pass = md5($_POST['password']);
$found = false;
$fullname = '';
$role = '';
$avatar = '';
$session_timeout = 600;
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!
'.mysqli_error($db));
}
mysqli_select_db($db, $mysql_database) or die('Failed to select database
'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
$sql = "SELECT * FROM ".$mysql_table." WHERE username = '".mysqli_real_escape_string($db, $_POST['username'])."'";
$result = mysqli_query($db, $sql);
if ($data = mysqli_fetch_array($result))
{
if ($crypt_pass == $data['password'] && $data['active'] != 0)
{
$found = true;
$fullname = $data['fullname'];
$role = $data['role'];
$folder = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1);
$avatar = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$folder" . "avatars/" . $data['avatar'];
}
}
mysqli_close($db);
if ($found == false)
{
header('Location: '.$error_page);
exit;
}
else
{
$_SESSION['username'] = $_POST['username'];
$_SESSION['fullname'] = $fullname;
$_SESSION['role'] = $role;
$_SESSION['avatar'] = $avatar;
$_SESSION['expires_by'] = time() + $session_timeout;
$_SESSION['expires_timeout'] = $session_timeout;
$rememberme = isset($_POST['rememberme']) ? true : false;
if ($rememberme)
{
setcookie('username', $_POST['username'], time() + 3600*24*30);
setcookie('password', $_POST['password'], time() + 3600*24*30);
}
header('Location: '.$success_page);
exit;
}
}
$username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
$password = isset($_COOKIE['password']) ? $_COOKIE['password'] : '';
?>