Beispiel #1
0
 /**
  * EP_Controller::__construct()
  *
  * @return - No Return Value
  */
 public function __construct()
 {
     parent::__construct();
     if ('CLI' === APPLICATION) {
         set_error_handler('errorsHandler', E_ALL);
         set_exception_handler('exceptionsHandler');
     }
     // this is loaded at this point so we can use it to determine what EMR we're accessing
     $this->load->helper('url');
     if ('EMR' === APPLICATION || 'ADMIN' === APPLICATION) {
         // this returns the domain from the url only
         //$sDomain = $_SERVER['HTTP_HOST'];
         $sDomain = parse_url(base_url(), PHP_URL_HOST);
         //die($sDomain);
         if (isset($_SERVER['HOSTIGNORE'])) {
             $sDomain = str_replace($_SERVER['HOSTIGNORE'] . '.', '', $sDomain);
         }
         $aDomainPieces = explode('.', $sDomain);
         $aDomainPieces = array_reverse($aDomainPieces);
         // remove the last two pieces of the domain the host and the extension
         $aDomainPieces = array_slice($aDomainPieces, 2);
         // determine the environment
         $this->sEnvironment = ENVIRONMENT;
         if (count($aDomainPieces) > 1) {
             $aDomainPieces = array_slice($aDomainPieces, 1);
         }
         // if the server environment variable has been set use it to override the environment
         if (isset($_SERVER['ENVIRONMENT'])) {
             $this->sEnvironment = $_SERVER['ENVIRONMENT'];
         }
         if (isset($_SERVER['PREFIX'])) {
             $this->sPrefix = $_SERVER['PREFIX'] . '_';
         }
         // make sure there's at least one domain piece working so that we can attempt to find an account
         // also make sure the array element isn't an empty string or something similar
         if (count($aDomainPieces) > 0 && !empty($aDomainPieces[0])) {
             $sSubdomain = $aDomainPieces[0];
         } else {
             exit("<tt style=\"color: red; font-weight: bold\">Account Not Found</tt>.");
         }
     }
     // build up the configuration information here
     $this->load->database();
     //$this->load->config('database', FALSE, TRUE);
     //$this->load->config($this->getEnvironment(), FALSE, TRUE);
     if ('PORTAL' !== APPLICATION) {
         // setup the connection to ep_master
         $this->switchDatabase('ep_master');
     }
     if ('EMR' === APPLICATION) {
         // query the database for the correct account information
         $this->db->from('subdomain');
         $this->db->join('account', 'subdomain.account_id = account.id', 'left');
         $this->db->where('value', $sSubdomain);
         $oQuery = $this->db->get();
         // query the database for the maintenance_mode information
         $this->db->from('maintenance_mode');
         $pQuery = $this->db->get();
         $pRow = $pQuery->row();
         // make sure that only one result is found
         if (1 !== $oQuery->num_rows()) {
             exit("<tt style=\"color: red; font-weight: bold\">Account Not Found</tt>.");
         }
         // actually get the result
         $oRow = $oQuery->row();
         $this->nAccount = $oRow->id;
         if ($oRow->maintenance_mode || $pRow->maintenance_mode) {
             while (ob_get_level()) {
                 ob_end_clean();
             }
             include APPPATH . '/errors/maintenance.php';
             exit(0);
         }
         if ($oRow->is_disabled) {
             while (ob_get_level()) {
                 ob_end_clean();
             }
             include APPPATH . '/errors/account_canceled.php';
             exit(0);
         }
         /*
         			if ($row->is_cancelled)
         			{
         				exit("<tt style=\"color: red; font-weight: bold\">This account is currently unavailable.  Please contact support.</tt>.");
         			}
         */
         // switch to the client's database for future accesses
         $this->switchDatabase($oRow->db_name);
     }
     // set the current instance of the object to this if it's not already set
     if (!isset(self::$_instance)) {
         self::$_instance =& $this;
     }
     // load any remaining libraries that are necessary
     $this->loadLibraries();
     $this->load->model('UserSettings');
     if ('EMR' === APPLICATION) {
         // if there is no session id, then it means we aren't logged in and should redirect to the login page
         /*	        if (!$this->input->is_ajax_request())
         			{
         				if (!isset($_SESSION['id']) || (isset($_SESSION['id']) && 0 == $_SESSION['id']))
         				{
         					header("Location: /user/login");
         				}
         			}
         */
         $sUri = substr($_SERVER['REQUEST_URI'], 0, 35);
         if (!isset($_SESSION['id']) || isset($_SESSION['id']) && 0 == $_SESSION['id']) {
             // allow ajax and hijack requests to go through, otherwise redirect to login
             if ($this->input->is_ajax_request() || '/user/hijack' === substr($sUri, 0, 12)) {
                 // do nothing
             } else {
                 if ('/user/' !== substr($sUri, 0, 6)) {
                     // redirect to the login page
                     redirect('/user/login');
                 }
             }
         }
         // set the public instance of the user id that is stored in the session
         if (isset($_SESSION['id'])) {
             $this->nUserId = $_SESSION['id'];
         }
         // set the public instance of the user name that is stored in the session
         if (isset($_SESSION['uname'])) {
             $this->sUserName = $_SESSION['uname'];
         }
         // if it's an AJAX POST or an application page request, reset the session time
         if ($this->input->is_ajax_request() && 'POST' === $_SERVER['REQUEST_METHOD'] || !$this->input->is_ajax_request()) {
             EP_Session::extendSession();
         }
         if (FALSE === self::$environment_flag) {
             $this->js->addJsCode('var environment_flag = "' . ENVIRONMENT . '";');
             $this->js->addJsCode('var show_prerelease = ' . ($this->config->item('show_prerelease') ? 1 : 0) . ';');
             $emr_version = $this->config->item('emr_version');
             $this->js->addJsCode('var emr_version = ' . (!empty($emr_version) ? $emr_version : 1.4));
             self::$environment_flag = true;
         }
     } else {
         if ('ADMIN' === APPLICATION) {
             $ip_address = explode('.', $this->input->ip_address());
             $ip_whitelist = new ip_whitelist();
             $ip = '';
             for ($i = 0; $i < count($ip_address); $i++) {
                 if (0 !== $i) {
                     $ip .= '.';
                 }
                 $ip .= $ip_address[$i];
                 $ip_whitelist->orWhere('value', $ip);
             }
             $ip_whitelist->result();
             if (0 === $ip_whitelist->count()) {
                 log_message('error', 'User Failed IP Check with IP of ' . $this->input->ip_address());
                 die('You don\'t have permission to access this application please contact the administrator.');
             }
             if (isset($this->session->userdata)) {
                 $this->nUserId = intval($this->session->userdata('user_id'));
             }
         }
     }
     // set up any library path chaining for specific applications
     switch (APPLICATION) {
         case 'CLI':
             $this->load->_ci_library_paths[] = SHAREPATH . '/library/';
             // this is supposed to fall through
         // this is supposed to fall through
         case 'ADMIN':
             //		case 'PORTAL':
             //log_message('error', 'adding [' . dirname(SHAREPATH) . '/application/] to model paths');
             $this->load->_ci_model_paths[] = dirname(SHAREPATH) . '/application/';
             //log_message('error', '  paths=' . var_export($this->load->_ci_model_paths, TRUE));
             break;
         case 'EMR':
             $this->load->_ci_library_paths[] = SHAREPATH . '/library/';
             break;
     }
 }