26 defined(
'LGV_SD_CATCHER' ) or die ( 'Cannot Execute Directly' );
28 if ( !defined('LGV_ADB_CATCHER') ) {
29 define(
'LGV_ADB_CATCHER', 1);
32 require_once(CO_Config::db_class_dir().
'/a_co_db.class.php');
46 $in_access_object = NULL
48 parent::__construct($in_pdo_object, $in_access_object);
50 $this->table_name =
'co_security_nodes';
52 $this->class_description =
'The security database class.';
69 if (CO_Config::use_personal_tokens() && !$no_personal) {
70 $fetch_sql .=
",personal_ids";
75 $sql =
'SELECT '.$fetch_sql.
' FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (id=?)';
76 $params = Array(intval($in_id));
84 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
85 $ret = isset($temp[0][
'ids']) ? explode(
',', $temp[0][
'ids']) : [];
86 if (!$no_personal && isset($temp[0][
'personal_ids'])) {
87 $ret_temp = explode(
',', $temp[0][
'personal_ids']);
88 foreach ($ret_temp as $i) {
94 if (isset($ret) && is_array($ret) && count($ret)) {
95 $ret = array_unique(array_map(
'intval', $ret));
97 foreach ($ret as $i) {
99 array_push($ret_temp, $i);
105 array_unshift($ret, $in_id);
107 $ret = Array($in_id);
122 $in_to_id = intval($in_to_id);
123 $in_id = intval($in_id);
125 if (CO_Config::use_personal_tokens()) {
126 $sql =
'SELECT ids FROM '.$this->table_name.
' WHERE (id=?)';
127 $params = [$in_to_id];
129 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
130 $ret = explode(
',', $temp[0][
'ids']);
132 if (isset($ret) && is_array($ret)) {
133 $ret = array_map(
'intval', $ret);
136 $ret = array_unique($ret);
137 $new_ids = implode(
',', array_unique($ret));
139 $sql =
'UPDATE '.$this->table_name.
' SET ids=? WHERE id=?';
140 $params = [$new_ids, $in_to_id];
142 if ($this->error == NULL) {
163 $in_to_id = intval($in_to_id);
164 $in_id = intval($in_id);
166 if (CO_Config::use_personal_tokens()) {
167 $sql =
'SELECT ids FROM '.$this->table_name.
' WHERE (id=?)';
168 $params = [$in_to_id];
170 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
171 $ret = explode(
',', $temp[0][
'ids']);
173 if (isset($ret) && is_array($ret)) {
175 $ret = array_unique(array_map(
'intval', $ret));
178 if (($key = array_search($in_id, $ret)) !==
false) {
183 $new_ids = implode(
',', $ret);
185 $sql =
'UPDATE '.$this->table_name.
' SET ids=? WHERE id=?';
186 $params = [$new_ids, $in_to_id];
188 if ($this->error == NULL) {
212 if (!CO_Config::use_personal_tokens()) {
216 $sql =
'SELECT personal_ids FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (id=?)';
219 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
220 $ret = explode(
',', $temp[0][
'personal_ids']);
221 if (isset($ret) && is_array($ret) && count($ret)) {
222 $ret = array_unique(array_map(
'intval', $ret));
224 foreach ($ret as $i) {
226 array_push($ret_temp, $i);
251 if (!CO_Config::use_personal_tokens()) {
255 $sql =
'SELECT personal_ids FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (id<>?)';
258 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
260 foreach ($temp as $i) {
261 if ($i[
'personal_ids']) {
265 $ret .= $i[
'personal_ids'];
268 $ret = explode(
",", $ret);
269 if (isset($ret) && is_array($ret) && count($ret)) {
270 $ret = array_unique(array_map(
'intval', $ret));
272 foreach ($ret as $i) {
274 array_push($ret_temp, $i);
297 if (!CO_Config::use_personal_tokens() || $this->access_object->god_mode()) {
302 $in_ids = $this->access_object->get_personal_security_ids();
303 $in_id = $this->access_object->get_login_id();
305 $sql =
'SELECT id,ids FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (id<>?)';
308 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
310 foreach ($temp as $i) {
312 if (isset($i[
'id']) && $i[
'id'] && isset($i[
'ids']) && $i[
'ids']) {
313 $key = intval($i[
'id']);
314 $ids = array_unique(array_map(
'intval', explode(
',', $i[
'ids'])));
315 if (1 < $key && count($ids)) {
318 foreach($ids as $tmp_id) {
319 if (in_array($tmp_id, $in_ids)) {
320 $tmp_ids[] = $tmp_id;
323 if (count($tmp_ids)) {
324 $ret[$key] = $tmp_ids;
345 if (!CO_Config::use_personal_tokens() || !$this->access_object->god_mode()) {
349 $sql =
'SELECT id,personal_ids FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (personal_ids IS NOT NULL) AND (personal_ids<>\'\')';
352 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
354 foreach ($temp as $i) {
356 if (isset($i[
'id']) && $i[
'id'] && isset($i[
'personal_ids']) && $i[
'personal_ids']) {
357 $key = intval($i[
'id']);
358 $ids = array_unique(array_map(
'intval', explode(
',', $i[
'personal_ids'])));
377 $sql =
'SELECT id FROM '.$this->table_name.
' WHERE (access_class LIKE \'%Login%\') AND (login_id IS NOT NULL) AND (login_id<>\'\')';
380 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
382 foreach ($temp as $i) {
390 $ret = explode(
",", $ret);
391 if (isset($ret) && is_array($ret) && count($ret)) {
392 $ret = array_unique(array_map(
'intval', $ret));
394 foreach ($ret as $i) {
396 array_push($ret_temp, $i);
417 $in_id = intval($in_id);
419 if (CO_Config::use_personal_tokens() && (1 < $in_id)) {
423 return in_array($in_id, $ret);
438 $in_id = intval($in_id);
444 return in_array($in_id, $ret);
464 if (intval($in_id)) {
465 $sql =
'SELECT write_security_id, ids FROM '.$this->table_name.
' WHERE id=?';
469 if (isset($result) && is_array($result) && (1 == count($result))) {
470 $access_ids = $this->access_object->get_security_ids();
471 $write_security_id = intval($result[0][
'write_security_id']);
472 $ids = (isset($result[0][
'ids']) && trim($result[0][
'ids'])) ? array_map(
'intval', explode(
',', trim($result[0][
'ids']))) : [];
473 $ids[] = $write_security_id;
476 $diff = array_diff($ids, $access_ids);
478 if (is_array($diff) && !count($diff)) {
497 if ($this->access_object->god_mode()) {
498 $sql =
'SELECT id FROM '.$this->table_name.
' WHERE true ORDER BY id';
500 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
502 foreach($temp as $row) {
503 $ret[] = intval($row[
'id']);
519 $sql =
'SELECT id,object_name,login_id FROM '.$this->table_name.
' WHERE';
524 $sql =
"$sql $predicate AND";
527 $sql =
"$sql login_id<>''";
530 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
531 foreach($temp as $value) {
532 $ret[$value[
"id"]] = [$value[
"object_name"], $value[
"login_id"]];
553 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE login_id=?';
554 $params = Array(trim($in_login_id));
557 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
577 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE api_key LIKE ?';
578 $params = Array(trim($in_api_key).
' - %');
581 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
583 if (isset($result) && ($result instanceof
CO_Security_Login) && $result && $result->is_api_key_valid($in_api_key)) {
584 $ret = Array(
'login_id' => $result->login_id,
'hashed_password' => $result->get_crypted_password());
585 if ($result->id() == CO_Config::god_mode_id()) {
586 $ret[
'hashed_password'] = $in_api_key;
589 $this->error = $result->error;
608 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE id=?';
611 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
634 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
655 $predicate .=
' AND ';
658 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE '.$predicate.
'(';
662 foreach ($in_login_id_array as $id) {
664 if (0 < count($params)) {
668 array_push($params, $id);
674 if (0 < count($params)) {
676 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
678 foreach ($temp as $result) {
681 array_push($ret, $result);
684 usort($ret,
function($a, $b){
return ($a->id() > $b->id());});
689 $my_id = $this->access_object->get_login_id();
690 $my_login_instance_is_manager = $this->access_object->god_mode() || ($this->access_object->get_login_item() instanceof
CO_Login_Manager);
693 if (isset($ret) && is_array($ret) && count($ret)) {
694 foreach ($ret as $instance) {
695 if (($instance->id() == $my_id) || $my_login_instance_is_manager) {
696 array_push($temp_ret, $instance);
719 $predicate .=
' AND ';
722 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE '.$predicate.
'(login_id IS NOT NULL) AND (login_id<>\'\')';
724 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
725 foreach ($temp as $result) {
728 array_push($ret, $result);
734 $my_id = $this->access_object->get_login_id();
735 $my_login_instance_is_manager = $this->access_object->god_mode() || ($this->access_object->get_login_item() instanceof
CO_Login_Manager);
738 foreach ($ret as $instance) {
739 if (($instance->id() == $my_id) || $my_login_instance_is_manager) {
740 array_push($temp_ret, $instance);
760 $in_security_token = intval($in_security_token);
762 $access_ids = $this->access_object->get_security_ids();
765 if (($this->access_object->god_mode() && $in_security_token) || in_array($in_security_token, $access_ids)) {
769 $predicate .=
' AND ';
772 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE '.$predicate.
'(login_id IS NOT NULL) AND (login_id<>\'\')';
774 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
777 foreach ($temp as $result) {
778 $id = intval($result[
'id']);
779 $id_array = Array($id);
780 $ids = explode(
',', $result[
'ids']);
781 if (isset($ids) && is_array($ids) && count($ids)) {
782 $ids = array_map(
'trim', $ids);
783 $ids = array_map(
'intval', $ids);
785 foreach ($ids as $single_id) {
786 array_push($id_array, $single_id);
790 $found = (2 > $in_security_token);
793 foreach ($id_array as $test_id) {
794 if ($test_id == $in_security_token) {
804 array_push($ret, $result);
812 $my_id = $this->access_object->get_login_id();
813 $my_login_instance_is_manager = $this->access_object->god_mode() || ($this->access_object->get_login_item() instanceof
CO_Login_Manager);
816 foreach ($ret as $instance) {
817 if (($instance->id() == $my_id) || $my_login_instance_is_manager) {
818 array_push($temp_ret, $instance);
839 $in_security_token = intval($in_security_token);
842 if (($this->access_object->god_mode() && $in_security_token) || in_array($in_security_token, $this->access_object->get_security_ids())) {
843 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE (login_id IS NOT NULL) AND (login_id<>\'\') AND (id<>?)';
844 $temp = $this->
execute_query($sql, Array(intval(CO_Config::god_mode_id())));
845 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
848 foreach ($temp as $result) {
849 $id = intval($result[
'id']);
850 $ids = explode(
',', $result[
'ids']);
851 if (isset($ids) && is_array($ids) && count($ids)) {
852 $ids = array_map(
'trim', $ids);
853 $ids = array_map(
'intval', $ids);
854 array_push($ids, $id);
855 $ids = array_unique($ids);
856 foreach ($ids as $single_id) {
857 if ($single_id == $in_security_token) {
882 $in_security_token = intval($in_security_token);
886 if (($access_instance->god_mode() && $in_security_token) || in_array($in_security_token, $access_instance->get_security_ids())) {
887 $sql =
'SELECT * FROM '.$this->table_name.
' WHERE (login_id IS NOT NULL) AND (login_id<>\'\') AND (id<>?)';
888 $temp = $this->
execute_query($sql, Array(intval(CO_Config::god_mode_id())));
889 if (isset($temp) && $temp && is_array($temp) && count($temp) ) {
890 foreach ($temp as $result) {
891 $id = intval($result[
'id']);
892 $ids = explode(
',', $result[
'ids']);
893 if (isset($ids) && is_array($ids) && count($ids)) {
894 $ids = array_map(
'trim', $ids);
895 $ids = array_map(
'intval', $ids);
896 array_push($ids, $id);
897 $ids = array_unique($ids);
898 foreach ($ids as $single_id) {
899 if ($single_id == $in_security_token) {
900 array_push($ret, $id);
909 $returnVar = array();
910 foreach ($ret as $id) {
911 $temp2 = $access_instance->get_user_from_login($id);
912 if (isset($temp2) && $temp2) {
913 array_push($returnVar, $temp2);
if(!defined( 'LGV_ADB_CATCHER'))
_create_read_security_predicate()
execute_query( $in_sql, $in_parameters=NULL, $exec_only=false)
_instantiate_record( $in_db_result)
_create_security_predicate( $write=false)
get_security_ids_for_id( $in_id, $no_personal)
get_credentials_by_api_key( $in_api_key)
is_this_a_login_id( $in_id)
get_initial_record_by_login_id( $in_login_id)
get_personal_ids_for_id( $in_id)
count_all_login_objects_with_access($in_security_token)
__construct( $in_pdo_object, $in_access_object=NULL)
get_all_user_objects_with_access($in_security_token)
get_logins_with_personal_ids()
get_logins_that_have_any_of_my_ids()
remove_personal_token_from_this_login( $in_to_id, $in_id)
get_single_record_by_login_id( $in_login_id, $and_write=false)
is_this_a_personal_id( $in_id)
get_initial_record_by_id( $in_id)
get_all_login_objects( $and_write=false)
get_all_personal_ids_except_for_id( $in_id=0)
get_all_login_objects_with_access( $in_security_token, $and_write=false)
add_personal_token_from_current_login( $in_to_id, $in_id)
get_multiple_records_by_login_id( $in_login_id_array, $and_write=false)