<?php
/**
 * Changing language By Session And check if exist HTTP_REFERER redirect to it
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    10-08-2020
 * @edited_by      Mohammad aljaouni
 * @last_edit_date 10-08-2020
 * @todo           Nothing
 */
ob_start();
session_start();
if(empty($_GET['setNewLanguage'])) {
    header("location: index.php");
    exit;
} else {
    $newLanguage = (int) $_GET['setNewLanguage'];
    if(empty($newLanguage)) {
        header("location: index.php");
        exit;
    } else {
        /**
         * Check if language not 1 or 2 (1: Arabic, 2: English) set lang 1 as default language
         * Note: If change language settings in includeInformation.php file you must edit this page
         */
        if(!in_array($newLanguage, range(1,2))) {
            $_SESSION["language"] = 1;
        } else {
            $_SESSION['language'] = $newLanguage;
        }
    }
    if(!empty($_SERVER['HTTP_REFERER'])) {
        header("Location: ".$_SERVER['HTTP_REFERER']."");
        exit;
    } else{
        header("Location: index.php");
        exit;
    }
}
ob_end_flush();
?>
