private function setSession($user_id = NULL)
 {
     $cookie = $this->getCookie();
     if (!empty($user_id)) {
         $user_id = (int) $user_id;
         $user_sess_code = $this->user_sess_code;
         $user_http_agent = $_SERVER['HTTP_USER_AGENT'];
         $user = Application::DB()->update(['table' => self::USER_SESSIONS_TABLE, 'fields' => [self::USER_SESS_CODE => $user_sess_code, self::USER_HTTP_AGENT => $user_http_agent], 'where' => [self::USER_ID => $user_id, self::USER_STATUS => self::STATUS_ACTIVE]]);
         $_SESSION[self::USER_ID] = $user_id;
         $_SESSION[self::USER_SESS_CODE] = $user_sess_code;
         $this->setCookie();
         return true;
     } else {
         if (isset($cookie[self::USER_ID]) and isset($cookie[self::USER_SESS_CODE])) {
             $cookie_user_id = Helper::screen($cookie[self::USER_ID]);
             $cookie_sess_code = Helper::screen($cookie[self::USER_SESS_CODE]);
             $user_http_agent = $_SERVER['HTTP_USER_AGENT'];
             $user = Application::DB()->selectOne(['table' => self::USER_SESSIONS_TABLE, 'fields' => [self::USER_SESS_CODE, self::USER_HTTP_AGENT], 'where' => [self::USER_ID => $cookie_user_id, self::USER_SESS_CODE => $cookie_sess_code, self::USER_HTTP_AGENT => $user_http_agent, self::USER_STATUS => self::STATUS_ACTIVE]]);
             if (sizeof($user) > 0) {
                 $_SESSION[self::USER_ID] = $cookie_user_id;
                 $_SESSION[self::USER_SESS_CODE] = $user[self::USER_SESS_CODE];
                 $this->setCookie();
                 return true;
             }
         }
     }
     return false;
 }