2013-08-18 22:02:55 +00:00
|
|
|
<?php
|
2013-09-13 22:39:03 +00:00
|
|
|
/**
|
|
|
|
* This function is beign used to change the users receiveMail setting.
|
|
|
|
* It will first check if the user who executed this function is the person of whom the setting is or if it's a mod/admin. If this is not the case the page will be redirected to an error page.
|
|
|
|
* it will check if the new value equals 1 or 0 and it will update the setting and redirect the page again.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-08-18 22:02:55 +00:00
|
|
|
function change_receivemail(){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
try{
|
|
|
|
//if logged in
|
2013-09-09 01:47:32 +00:00
|
|
|
global $INGAME_WEBPATH;
|
|
|
|
global $WEBPATH;
|
2013-08-18 22:02:55 +00:00
|
|
|
if(WebUsers::isLoggedIn()){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
if(isset($_POST['target_id'])){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-09-13 22:39:03 +00:00
|
|
|
//check if the user who executed this function is the person of whom the setting is or if it's a mod/admin.
|
2013-09-09 01:47:32 +00:00
|
|
|
if( ( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) && isset($_POST['ReceiveMail']) ){
|
2013-08-18 22:02:55 +00:00
|
|
|
$user_id = filter_var($_POST['target_id'], FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$receiveMail = filter_var($_POST['ReceiveMail'], FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
if($receiveMail == 0 || $receiveMail == 1){
|
|
|
|
WebUsers::setReceiveMail($user_id, $receiveMail);
|
|
|
|
}
|
2013-09-09 01:47:32 +00:00
|
|
|
if (Helpers::check_if_game_client()) {
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-09-09 01:47:32 +00:00
|
|
|
header("Location: ".$INGAME_WEBPATH."?page=settings&id=".$user_id);
|
|
|
|
}else{
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-09-09 01:47:32 +00:00
|
|
|
header("Location: ".$WEBPATH."?page=settings&id=".$user_id);
|
|
|
|
}
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: permission denied!
|
|
|
|
$_SESSION['error_code'] = "403";
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-08-18 22:02:55 +00:00
|
|
|
header("Location: index.php?page=error");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-08-18 22:02:55 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: The form was not filled in correclty
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-08-18 22:02:55 +00:00
|
|
|
header("Location: index.php?page=settings");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
2013-08-18 22:02:55 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: user is not logged in
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-08-18 22:02:55 +00:00
|
|
|
header("Location: index.php");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-08-18 22:02:55 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
}catch (PDOException $e) {
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
print_r($e);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-08-18 22:02:55 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-18 22:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|