<?php
	session_start();
	include_once('../../db/saucerer.php');

  // Define variables and initialize with empty values
$id = $name = $token = $access = "";
$id_err = $name_err = $token_err = $access = "";


//IP Address Protocol
$ip_address = $_SERVER["REMOTE_ADDR"];

// Check if the "mobile" word exists in User-Agent 
$isMob = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "mobile")); 
  
// Check if the "tablet" word exists in User-Agent 
$isTab = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "tablet")); 
 

// Platform check  
$isWin = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "windows")); 
$isAndroid = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "android")); 
$isIPhone = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "iphone")); 
$isIPad = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "ipad")); 
$isIOS = $isIPhone || $isIPad; 
  
    if($isTab){ 
        if ($isIPad) {
        $device = 'iPad';
    } else {
        $device = 'Tablet'; 
    }
  } elseif($isMob){ 
    if ($isIPhone) {
        $device = 'iPhone';
    } else {
        $device = 'Phone'; 
    }

  } else{ 
        $device = 'Desktop'; 
} 
 
if($isIOS){ 
    $system = 'iOS'; 
}elseif($isAndroid){ 
    $system = 'ANDROID'; 
}elseif($isWin){ 
    $system = 'WINDOWS'; 
}



 $user = $_SESSION['name'];
 $token = $_SESSION['token'];
 $access = $_SESSION['access'];

	if(isset($_GET['id'])){

    	$name = $_GET['name'];
		$nav = $_GET['id']+1;

		$sql = "UPDATE contact SET star='1' WHERE id = '".$_GET['id']."'";

		//use for MySQLi OOP
		if($conn->query($sql)){
			$_SESSION['success'] = 'Message from '.$name.' starred successfully';

        $result = "Success";
        $channel = "Notifications";
        $link = "contact";
        $summary = "Message from ".$name." has been starred";

		}
		
		else{
			$_SESSION['error'] = 'Error in starring a message from '.$name.'';

        $result = "Error";
        $channel = "System";
        $link = "#!";
        $summary = "System error starring a message from ".$name."";

		}

        $attempt = "Star";
        $action = "Star";
        $filter = "Client";
        $category = "Message";

        $sql = "INSERT INTO secure (name, token, access, attempt, action, user, handler, result, filter, category, channel, summary, link, ip_address, device_name, system_name) 

                VALUES ('$name', '$token', '$access', '$attempt', '$action', '$user', 'Admin', '$result', '$filter', '$category', '$channel', '$summary', '$link', '$ip_address', '$device', '$system')";
                mysqli_query($mysqli, $sql);

	}

	header('location: ../#nav_'.$nav.'');
?>