26 defined(
'LGV_ACCESS_CATCHER' ) or die ( 'Cannot Execute Directly' );
30 if ( !defined('LGV_MD_CATCHER') ) {
31 define(
'LGV_MD_CATCHER', 1);
34 require_once(CO_Config::db_class_dir().
'/co_main_data_db.class.php');
36 if ( !defined(
'LGV_SD_CATCHER') ) {
37 define(
'LGV_SD_CATCHER', 1);
40 require_once(CO_Config::db_class_dir().
'/co_security_db.class.php');
42 if ( !defined(
'LGV_LANG_CATCHER') ) {
43 define(
'LGV_LANG_CATCHER', 1);
46 require_once(CO_Config::badger_lang_class_dir().
'/common.inc.php');
98 $in_hashed_password = NULL,
99 $in_raw_password = NULL,
102 $this->class_description =
'The main data access class.';
104 $this->_login_id = NULL;
105 $this->_data_db_object = NULL;
106 $this->_security_db_object = NULL;
108 $this->valid =
false;
111 if ( !defined(
'LGV_ERROR_CATCHER') ) {
112 define(
'LGV_ERROR_CATCHER', 1);
115 require_once(CO_Config::badger_shared_class_dir().
'/error.class.php');
117 if ( !defined(
'LGV_DB_CATCHER') ) {
118 define(
'LGV_DB_CATCHER', 1);
121 require_once(CO_Config::db_class_dir().
'/co_pdo.class.php');
124 if ((isset($in_login_id) && $in_login_id) && ((isset($in_hashed_password) && $in_hashed_password) || (isset($in_raw_password) && $in_raw_password)) || (isset($in_api_key) && $in_api_key)) {
126 $pdo_security_db =
new CO_PDO(CO_Config::$sec_db_type, CO_Config::$sec_db_host, CO_Config::$sec_db_name, CO_Config::$sec_db_login, CO_Config::$sec_db_password);
127 $this->_security_db_object =
new CO_Security_DB($pdo_security_db, $this);
128 $dont_create_new_api_key =
false;
132 if (isset($in_api_key) && $in_api_key) {
133 $api_results = $this->_security_db_object->get_credentials_by_api_key($in_api_key);
135 if (isset($api_results) && is_array($api_results) && (2 == count($api_results))) {
136 $in_login_id = $api_results[
'login_id'];
137 $in_hashed_password = $api_results[
'hashed_password'];
138 $dont_create_new_api_key =
true;
142 $login_record = $this->_security_db_object->get_initial_record_by_login_id($in_login_id);
143 if ($this->_security_db_object->error) {
144 $this->error = $this->_security_db_object->error;
149 if (!$login_record->is_login_valid($in_login_id, $in_hashed_password, $in_raw_password, $dont_create_new_api_key)) {
154 $this->_security_db_object = NULL;
162 $this->_security_db_object = NULL;
166 $this->_login_id = $login_record->id();
167 $login_record->update_db();
168 }
catch (Exception $exception) {
172 $exception->getFile(),
173 $exception->getLine(),
174 $exception->getMessage());
175 $this->_security_db_object = NULL;
181 $pdo_data_db =
new CO_PDO(CO_Config::$data_db_type, CO_Config::$data_db_host, CO_Config::$data_db_name, CO_Config::$data_db_login, CO_Config::$data_db_password);
183 }
catch (Exception $exception) {
187 $exception->getFile(),
188 $exception->getLine(),
189 $exception->getMessage());
190 $this->_data_db_object = NULL;
191 $this->_security_db_object = NULL;
207 $in_visibility_test =
false
209 return $this->_data_db_object->item_exists($in_id, $in_visibility_test);
228 if (isset($login_id) && $login_id && $this->_security_db_object) {
229 $ret = $this->_security_db_object->get_security_ids_for_id($this->
get_login_id(), $no_personal);
231 if ($this->_security_db_object->error) {
232 $this->error = $this->_security_db_object->error;
236 array_unshift($ret, 1);
254 if (CO_Config::use_personal_tokens()) {
256 if (isset($login_id) && $login_id && $this->_security_db_object) {
257 $ret = $this->_security_db_object->get_personal_ids_for_id($login_id);
259 if ($this->_security_db_object->error) {
260 $this->error = $this->_security_db_object->error;
278 $ret = $this->_security_db_object->get_all_personal_ids_except_for_id($in_id);
280 if ($this->_security_db_object->error) {
281 $this->error = $this->_security_db_object->error;
296 $ret = $this->_security_db_object->get_logins_with_personal_ids();
298 if ($this->_security_db_object->error) {
299 $this->error = $this->_security_db_object->error;
314 $ret = $this->_security_db_object->is_this_a_personal_id($in_id);
316 if ($this->_security_db_object->error) {
317 $this->error = $this->_security_db_object->error;
335 $ret = $this->_security_db_object->add_personal_token_from_current_login($in_to_id, $in_id);
337 if ($this->_security_db_object->error) {
338 $this->error = $this->_security_db_object->error;
357 $ret = $this->_security_db_object->remove_personal_token_from_this_login($in_to_id, $in_id);
359 if ($this->_security_db_object->error) {
360 $this->error = $this->_security_db_object->error;
376 return $this->_security_db_object->get_logins_that_have_any_of_my_ids();
387 $ret = $this->_security_db_object->is_this_a_login_id($in_id);
389 if ($this->_security_db_object->error) {
390 $this->error = $this->_security_db_object->error;
409 $logins = $this->_security_db_object->get_all_readable_records();
411 foreach ($logins as $login) {
412 $ret[] = $login->id();
416 if (isset($login_id) && $login_id && $this->_security_db_object) {
417 $ret = $this->_security_db_object->get_security_ids_for_id($this->
get_login_id(), $no_personal);
419 if ($this->_security_db_object->error) {
420 $this->error = $this->_security_db_object->error;
431 $ret = array_values(array_unique($ret));
452 $in_login_id = intval($in_login_id);
461 $ret = $record->id();
480 if (isset($in_login_id) && (0 < intval($in_login_id))) {
481 $login_id = intval($in_login_id);
502 $ret = $login_item->get_lang();
514 return intval($this->_login_id) == intval(CO_Config::god_mode_id());
528 if ($this->_security_db_object->get_initial_record_by_id(intval($in_login_id))) {
556 if ($this->_security_db_object->get_initial_record_by_login_id($in_login_id_string)) {
573 $ret = $this->_security_db_object->get_single_record_by_login_id($in_login_id_string);
590 } elseif (
true == $ret) {
591 $ret = $this->_data_db_object->see_if_user_exists($in_login_id);
611 $filename = CO_Config::db_classes_class_dir().
'/'.strtolower($in_classname).
'.class.php';
612 if (!class_exists($in_classname)) {
613 if (!file_exists($filename)) {
616 $dir_array = CO_Config::db_classes_extension_class_dir();
618 if (!is_array($dir_array)) {
619 $dir_array = Array($dir_array);
622 foreach ($dir_array as $dir) {
623 $filename = $dir.
'/'.strtolower($in_classname).
'.class.php';
624 if (file_exists($filename)) {
625 require_once($filename);
632 require_once($filename);
647 if (class_exists($in_classname) && $this->_data_db_object && $this->_security_db_object) {
648 $test_instance =
new $in_classname();
651 $ret =
new $in_classname($this->_data_db_object);
653 $ret =
new $in_classname($this->_security_db_object);
657 $ret->write_security_id = intval($this->
get_login_id());
668 } elseif (!$this->_security_db_object) {
702 if (isset($this->_data_db_object) && $this->_data_db_object) {
703 $ret = $this->_data_db_object->get_multiple_records_by_id($in_id_array);
704 if ($this->_data_db_object->error) {
705 $this->error = $this->_data_db_object->error;
725 if (isset($tmp) && is_array($tmp) && (1 == count($tmp))) {
743 if (isset($this->_data_db_object) && $this->_data_db_object) {
744 $ret = $this->_data_db_object->get_access_class_by_id($in_id);
745 $this->error = $this->_data_db_object->error;
762 if (isset($this->_security_db_object) && $this->_security_db_object) {
763 $ret = $this->_security_db_object->get_access_class_by_id($in_id);
764 $this->error = $this->_security_db_object->error;
782 if (isset($this->_data_db_object) && $this->_data_db_object) {
783 $ret = $this->_data_db_object->can_i_see_this_record($in_id);
784 $this->error = $this->_data_db_object->error;
802 if (isset($this->_security_db_object) && $this->_security_db_object) {
803 $ret = $this->_security_db_object->can_i_see_this_record($in_id);
804 $this->error = $this->_security_db_object->error;
821 if (isset($this->_data_db_object) && $this->_data_db_object) {
822 $ret = $this->_data_db_object->get_all_readable_records($open_only, $in_this_id);
823 $this->error = $this->_data_db_object->error;
839 if (isset($this->_data_db_object) && $this->_data_db_object) {
840 $ret = $this->_data_db_object->get_all_writeable_records($in_this_id);
842 if ($this->_data_db_object->error) {
843 $this->error = $this->_data_db_object->error;
870 if (!$ret && isset($in_token_to_test) && ctype_digit(strval($in_token_to_test))) {
871 if (0 == intval($in_token_to_test)) {
873 } elseif (1 == intval($in_token_to_test)) {
878 if (isset($tokens) && is_array($tokens) && count($tokens)) {
879 $ret = in_array(intval($in_token_to_test), $tokens);
899 if (isset($this->_security_db_object) && $this->_security_db_object) {
900 $ret = $this->_security_db_object->get_multiple_records_by_id($in_id_array);
902 if ($this->_security_db_object->error) {
903 $this->error = $this->_security_db_object->error;
924 if (isset($tmp) && is_array($tmp) && (1 == count($tmp))) {
941 if (isset($this->_security_db_object) && $this->_security_db_object) {
942 $ret = $this->_security_db_object->get_all_readable_records($in_this_id);
944 if ($this->_security_db_object->error) {
945 $this->error = $this->_security_db_object->error;
964 if (isset($this->_security_db_object) && $this->_security_db_object) {
965 $ret = $this->_security_db_object->get_all_writeable_records($in_this_id);
967 if ($this->_security_db_object->error) {
968 $this->error = $this->_security_db_object->error;
991 if (isset($this->_data_db_object) && $this->_data_db_object) {
992 $ret = $this->_data_db_object->write_record($params_associative_array);
993 $this->error = $this->_data_db_object->error;
1009 if (isset($this->_data_db_object) && $this->_data_db_object) {
1010 $ret = $this->_data_db_object->delete_record($id);
1011 $this->error = $this->_data_db_object->error;
1057 $and_writeable =
false,
1058 $count_only =
false,
1063 if (isset($this->_data_db_object) && $this->_data_db_object) {
1064 $ret = $this->_data_db_object->generic_search($in_search_parameters, $or_search, $page_size, $initial_page, $and_writeable, $count_only, $ids_only);
1065 $this->error = $this->_data_db_object->error;
1079 if (!isset($this->_security_db_object) || !$this->_security_db_object) {
1083 return $this->_security_db_object->get_all_login_objects($and_write);
1093 return $this->_security_db_object->get_all_tokens();
1107 if (!isset($this->_security_db_object) || !$this->_security_db_object) {
1111 return $this->_security_db_object->get_all_login_objects_with_access($in_security_token, $and_write);
1124 if (!isset($this->_security_db_object) || !$this->_security_db_object) {
1128 return $this->_security_db_object->get_all_user_objects_with_access($in_security_token);
if(!defined( 'LGV_MD_CATCHER'))
This class provides a genericized interface to the PHP PDO toolkit.
static $access_error_code_class_not_created
static $access_error_code_user_not_authorized
static $pdo_error_code_invalid_login
static $pdo_error_code_failed_to_open_data_db
static $access_error_code_class_file_not_found
static $pdo_error_code_failed_to_open_security_db
static $pdo_error_name_failed_to_open_security_db
static $pdo_error_name_failed_to_open_data_db
static $pdo_error_desc_failed_to_open_security_db
static $pdo_error_name_invalid_login
static $access_error_name_user_not_authorized
static $access_error_name_class_file_not_found
static $pdo_error_desc_failed_to_open_data_db
static $access_error_desc_class_file_not_found
static $access_error_name_class_not_created
static $access_error_desc_user_not_authorized
static $access_error_desc_class_not_created
static $pdo_error_desc_invalid_login
$_data_db_object
This is the instance of the class representing the "data" database. This will always be instantiated.
generic_search( $in_search_parameters=NULL, $or_search=false, $page_size=0, $initial_page=0, $and_writeable=false, $count_only=false, $ids_only=false)
get_all_personal_ids_except_for_id( $in_id=0)
make_new_blank_record( $in_classname)
get_all_data_readable_records( $open_only=false, $in_this_id=NULL)
check_login_exists_by_login_string( $in_login_id_string)
get_available_tokens($no_personal=false)
get_login_item_by_login_string( $in_login_id_string)
get_multiple_security_records_by_id( $in_id_array)
get_all_user_objects_with_access( $in_security_token)
get_data_access_class_by_id( $in_id)
can_i_see_this_security_record( $in_id)
__construct( $in_login_id=NULL, $in_hashed_password=NULL, $in_raw_password=NULL, $in_api_key=NULL)
$version
This will contain the BADGER Version.
get_remaining_time($in_login_id=NULL)
item_exists( $in_id, $in_visibility_test=false)
get_all_security_readable_records( $in_this_id=NULL)
$class_description
This is a brief textual description of the class.
get_login_item( $in_login_id=NULL)
is_this_a_login_id( $in_id)
$_login_id
This is an integer, containing the security DB ID of the logged-in user. It will be NULL for no login...
check_login_exists( $in_login_id)
get_logins_with_personal_ids()
write_data_record( $params_associative_array)
get_multiple_data_records_by_id( $in_id_array)
remove_personal_token_from_this_login( $in_to_id, $in_id)
add_personal_token_from_current_login( $in_to_id, $in_id)
get_logins_that_have_any_of_my_ids()
check_user_exists( $in_login_id)
$_security_db_object
This is the instance of the class representing the "scurity" database. This may not be instantiated,...
get_all_login_objects( $and_write=false)
get_all_login_objects_with_access( $in_security_token, $and_write=false)
$error
If there was an error, it will be held here.
is_this_a_personal_id( $in_id)
get_all_data_writeable_records( $in_this_id=NULL)
can_i_see_this_data_record( $in_id)
get_security_access_class_by_id( $in_id)
get_login_id( $in_login_id=NULL)
$valid
This will be true, if the instance is "valid" (has at least an initialized "data" database).
get_lang( $in_login_id=NULL)
i_have_this_token( $in_token_to_test)
get_all_security_writeable_records( $in_this_id=NULL)
get_single_security_record_by_id( $in_id)
get_single_data_record_by_id( $in_id)
get_personal_security_ids()
get_security_ids($no_personal=false)
This class provides a general error report, with file, method and error information.