Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / ams / func / change_receivemail.php
blob62dcfd79fcb0a9eebeef9fbe52380d808edace32
1 <?php
2 /**
3 * This function is beign used to change the users receiveMail setting.
4 * 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.
5 * it will check if the new value equals 1 or 0 and it will update the setting and redirect the page again.
6 * @author Daan Janssens, mentored by Matthew Lagoe
7 */
8 function change_receivemail(){
10 try{
11 //if logged in
12 global $INGAME_WEBPATH;
13 global $WEBPATH;
14 if(WebUsers::isLoggedIn()){
16 if(isset($_POST['target_id'])){
18 //check if the user who executed this function is the person of whom the setting is or if it's a mod/admin.
19 if( ( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) && isset($_POST['ReceiveMail']) ){
20 $user_id = filter_var($_POST['target_id'], FILTER_SANITIZE_NUMBER_INT);
21 $receiveMail = filter_var($_POST['ReceiveMail'], FILTER_SANITIZE_NUMBER_INT);
22 if($receiveMail == 0 || $receiveMail == 1){
23 WebUsers::setReceiveMail($user_id, $receiveMail);
25 if (Helpers::check_if_game_client()) {
26 header("Cache-Control: max-age=1");
27 header("Location: ".$INGAME_WEBPATH."?page=settings&id=".$user_id);
28 }else{
29 header("Cache-Control: max-age=1");
30 header("Location: ".$WEBPATH."?page=settings&id=".$user_id);
32 throw new SystemExit();
34 }else{
35 //ERROR: permission denied!
36 $_SESSION['error_code'] = "403";
37 header("Cache-Control: max-age=1");
38 header("Location: index.php?page=error");
39 throw new SystemExit();
42 }else{
43 //ERROR: The form was not filled in correclty
44 header("Cache-Control: max-age=1");
45 header("Location: index.php?page=settings");
46 throw new SystemExit();
48 }else{
49 //ERROR: user is not logged in
50 header("Cache-Control: max-age=1");
51 header("Location: index.php");
52 throw new SystemExit();
55 }catch (PDOException $e) {
56 //go to error page or something, because can't access website db
57 print_r($e);
58 throw new SystemExit();