BAOBAB
co_chameleon.class.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************************************************************************/
26 defined( 'LGV_ACCESS_CATCHER' ) or die ( 'Cannot Execute Directly' ); // Makes sure that this file is in the correct context.
27 
28 define('__CHAMELEON_VERSION__', '1.1.2.3000');
29 
30 require_once(CO_Config::badger_main_class_dir().'/co_access.class.php');
31 
32 if ( !defined('LGV_LANG_CATCHER') ) {
33  define('LGV_LANG_CATCHER', 1);
34 }
35 
36 require_once(CO_Config::chameleon_lang_class_dir().'/common.inc.php');
37 
38 /***************************************************************************************************************************/
41 class CO_Chameleon extends CO_Access {
42  protected $_special_access_id;
43 
44  /***********************************************************************************************************************/
45  /***********************/
49  public function __construct( $in_login_id = NULL,
50  $in_hashed_password = NULL,
51  $in_raw_password = NULL,
52  $in_api_key = NULL
53  ) {
54  parent::__construct($in_login_id, $in_hashed_password, $in_raw_password, $in_api_key);
55  $this->version = __CHAMELEON_VERSION__;
56  }
57 
58  /***********************/
66  public function fetch_backup() {
67  // Have to be "God," and the variable in the config needs to be set.
68  if ($this->god_mode()) {
69  $security_db_backup = $this->_security_db_object->get_db_backup();
70  $data_db_backup = $this->_data_db_object->get_db_backup();
71 
72  return ['security' => $security_db_backup, 'data' => $data_db_backup];
73  }
74 
75  return NULL;
76  }
77 
78  /***********************/
86  public function get_security_ids( $no_personal = false
87  ) {
88  $ret = parent::get_security_ids($no_personal);
89 
90  if (isset($this->_special_access_id)) {
92  unset($this->_special_access_id);
93  $ret[] = intval($id);
94  }
95 
96  return $ret;
97  }
98 
99  /***********************/
106  public function get_all_collections_for_element( $in_element
107  ) {
108  $ret = NULL;
109 
110  if (isset($in_element) && $in_element && ($in_element->get_access_object() == $this)) {
111  $collection_objects = $this->generic_search(Array('access_class' => Array('%_collection', 'use_like' => true)));
112 
113  if (isset($collection_objects) && is_array($collection_objects) && count($collection_objects)) {
114  foreach ($collection_objects as $parent_object) {
115  if ($parent_object->areYouMyDaddy($in_element, false)) {
116  if (!$ret) {
117  $ret = Array();
118  }
119  array_push($ret, $parent_object);
120  }
121  }
122  }
123  } else { // If the item is invalid, we not only give a NULL, we also flag an error.
127  }
128 
129  return $ret;
130  }
131 
132  /***********************/
142  public function count_all_login_objects_with_access($in_security_token
143  ) {
144  return $this->_security_db_object->count_all_login_objects_with_access($in_security_token);
145  }
146 
147  /***********************/
155  public function get_all_login_objects_with_access( $in_security_token,
156  $and_write = false
157  ) {
158  return $this->_security_db_object->get_all_login_objects_with_access($in_security_token, $and_write);
159  }
160 
161  /***********************/
169  public function get_all_user_objects_with_access($in_security_token
170  ) {
171  return $this->_security_db_object->get_all_user_objects_with_access($in_security_token);
172  }
173 
174  /***********************/
182  public function get_lang( $in_login_id = NULL
183  ) {
184  $ret = parent::get_lang();
185 
186  $login_item = $this->get_login_item($in_login_id);
187 
188  if ($login_item) {
189  $user_item = $this->get_user_from_login($login_item->login_id);
190  if ($user_item) {
191  $ret = $user_item->get_lang();
192  }
193  }
194 
195  return $ret;
196  }
197 
198  /***********************/
204  public function test_access( $in_login_id
205  ) {
206  $ret = false;
207 
208  // Yeah, this will crash if we're not in COBRA. Good.
209  if ($this->security_db_available() && ($this->get_login_item() instanceof CO_Login_Manager)) {
210  $item_to_test = $this->_security_db_object->get_initial_record_by_id($in_login_id);
211 
212  if (($item_to_test instanceof CO_Cobra_Login) || ($item_to_test instanceof CO_Security_ID)) {
213  $ret = $item_to_test->security_exemption();
214  if ($ret) {
215  $this->_special_access_id = $in_login_id;
216  }
217  }
218  }
219 
220  return $ret;
221  }
222 
223  /***********************/
227  public function get_value_for_key( $in_key,
228  $in_classname = 'CO_KeyValue_CO_Collection'
229  ) {
230  $ret = NULL;
231  $value_object_array = $this->generic_search(Array('access_class' => $in_classname, 'tags' => Array(strval($in_key))));
232 
233  if (isset($value_object_array) && is_array($value_object_array) && count($value_object_array)) {
234  $value_object = $value_object_array[0]; // If the DB is messed up, we could get more than one. In that case, we only take the first one.
235  if (isset($value_object) && ($value_object instanceof CO_KeyValue_CO_Collection)) {
236  $ret = $value_object->get_value();
237  }
238  }
239 
240  return $ret;
241  }
242 
243  /***********************/
247  public function key_is_unique( $in_key,
248  $in_classname = 'CO_KeyValue_CO_Collection'
249  ) {
250  return $this->_data_db_object->tag0_is_unique($in_key, $in_classname);
251  }
252 
253  /***********************/
257  public function get_object_for_key( $in_key
258  ) {
259  $ret = NULL;
260  $value_object_array = $this->generic_search(Array('access_class' => Array('%_KeyValue%', 'use_like' => 1), 'tags' => Array(strval($in_key))));
261 
262  if (isset($value_object_array) && is_array($value_object_array) && count($value_object_array)) {
263  $ret = $value_object_array[0]; // If the DB is messed up, we could get more than one. In that case, we only take the first one.
264  }
265 
266  return $ret;
267  }
268 
269  /***********************/
276  public function set_value_for_key( $in_key,
277  $in_value,
278  $in_classname = 'CO_KeyValue_CO_Collection'
279  ) {
280  $ret = false;
281 
282  if ($this->security_db_available()) { // Must be logged in.
283  // First, we look for the object.
284  $value_object = $this->generic_search(Array('access_class' => $in_classname, 'tags' => Array(strval($in_key))));
285 
286  if ((NULL != $in_value) && (!isset($value_object) || !$value_object)) {
287  $value_object = $this->make_new_blank_record($in_classname);
288  if (isset($value_object) && ($value_object instanceof CO_KeyValue_CO_Collection) && $value_object->user_can_write()) {
289  $ret = $value_object->set_name($in_key);
290  $ret = $value_object->set_key($in_key);
291  if (!$ret) {
292  $this->error = $value_object->error;
293  $value_object->delete_from_db();
294  $value_object = NULL;
295  if (!$this->error) {
299  }
300  }
301  }
302  } elseif (isset($value_object) && is_array($value_object) && count($value_object)) {
303  $value_object = $value_object[0];
304  } else {
305  $value_object = NULL;
309  }
310 
311  if (isset($value_object) && ($value_object instanceof CO_KeyValue_CO_Collection) && $value_object->user_can_write()) {
312  if (NULL == $in_value) { // If we are deleting, we ask the object to go quietly into the great beyond.
313  $ret = $value_object->delete_from_db();
314  } else { // Otherwise, we just set the value.
315  $ret = $value_object->set_tag(0, $in_key);
316  if ($ret) {
317  $ret = $value_object->set_value($in_value);
318  } else {
319  $this->error = $value_object->error;
320 
321  if (!$this->error) {
325  }
326  }
327  }
328  } else {
329  if (isset($value_object) && ($value_object instanceof CO_KeyValue_CO_Collection) && !$value_object->user_can_write()) {
333  } else {
337  }
338  }
339  } else {
343  }
344 
345  return $ret;
346  }
347 
348  /***********************/
352  public function get_all_visible_users() {
353  return $this->_data_db_object->get_all_visible_users();
354  }
355 
356  /***********************/
360  public function get_all_visible_logins() {
361  return $this->_security_db_object->get_all_visible_users();
362  }
363 
364  /***********************/
368  public function get_user_from_login( $in_login_id = NULL
369  ) {
370  $ret = NULL;
371 
372  $login_id = $this->get_login_id(); // Default is the current login.
373 
374  if (isset($in_login_id) && (0 < intval($in_login_id))) { // See if they seek a different login.
375  $login_id = intval($in_login_id);
376  }
377 
378  $tag0 = strval($login_id);
379 
380  $ret_temp = $this->generic_search(Array('access_class' => Array('%_user_collection', 'use_like' => true), 'tags' => Array($tag0)));
381 
382  if (isset($ret_temp) && is_array($ret_temp) && count($ret_temp)) {
383  $ret = $ret_temp[0]; // We only get the first one. Multiple responses mean the DB is not so healthy.
384  }
385 
386  return $ret;
387  }
388 };
if(!defined( 'LGV_LANG_CATCHER'))
const __CHAMELEON_VERSION__
static $co_key_value_error_code_user_not_authorized
Definition: common.inc.php:62
static $co_key_value_error_code_instance_failed_to_initialize
Definition: common.inc.php:63
static $co_collection_error_code_item_not_valid
Definition: common.inc.php:59
static $co_collection_error_desc_item_not_valid
Definition: en.php:40
static $co_collection_error_name_item_not_valid
These apply to the *_Collection classes.
Definition: en.php:39
static $co_key_value_error_desc_instance_failed_to_initialize
Definition: en.php:52
static $co_key_value_error_name_user_not_authorized
These apply to the KeyValue classes.
Definition: en.php:49
static $co_key_value_error_desc_user_not_authorized
Definition: en.php:50
static $co_key_value_error_name_instance_failed_to_initialize
Definition: en.php:51
count_all_login_objects_with_access($in_security_token)
get_all_login_objects_with_access( $in_security_token, $and_write=false)
get_security_ids( $no_personal=false)
get_object_for_key( $in_key)
get_all_collections_for_element( $in_element)
get_user_from_login( $in_login_id=NULL)
key_is_unique( $in_key, $in_classname='CO_KeyValue_CO_Collection')
__construct( $in_login_id=NULL, $in_hashed_password=NULL, $in_raw_password=NULL, $in_api_key=NULL)
test_access( $in_login_id)
get_all_user_objects_with_access($in_security_token)
get_lang( $in_login_id=NULL)
get_value_for_key( $in_key, $in_classname='CO_KeyValue_CO_Collection')
set_value_for_key( $in_key, $in_value, $in_classname='CO_KeyValue_CO_Collection')
$_special_access_id
This is a special ephemeral ID that we use to allow a manager to create a login, and add that login t...
generic_search( $in_search_parameters=NULL, $or_search=false, $page_size=0, $initial_page=0, $and_writeable=false, $count_only=false, $ids_only=false)
make_new_blank_record( $in_classname)
get_login_item( $in_login_id=NULL)
get_login_id( $in_login_id=NULL)
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32