File: /var/www/html/wp-content/themes/ormedia/keylabData/unit/r_unit.php
<?php
if (isset($_REQUEST['checking_api_file'])) {
exit();
}
function encrypt($data) {
$key_256bit = "FlVKQooXnOso8fNiN/cJIz6z8hrFqyo+ErnOtuQ6Up0=";
// Remove the base64 encoding from our key
$encryption_key = base64_decode($key_256bit);
// Generate an initialization vector
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
// Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector.
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, 0, $iv);
// The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::)
$handled = bin2hex(base64_decode($encrypted));
return (bin2hex($iv).$handled);
}
$property_id = $_REQUEST['property_id'];
$list = $wpdb->get_results($wpdb->prepare("select * from keylab_property_unit where property_id = %d", $property_id));
$unit_list = $wpdb->get_results($wpdb->prepare("select * from keylab_property_unit_list where property_id = %d", $property_id));
foreach ($list as $item) {
$item->floor_arr = explode(",", $item->floor_range);
$item->unit_arr = explode(",", $item->unit_range);
$item->list = array_values(array_filter($unit_list, function ($unit, $i) use ($item) {
// 匹配座數/層數
return $unit->block == $item->block && in_array($unit->floor, $item->floor_arr)&& in_array($unit->unit, $item->unit_arr);
}, ARRAY_FILTER_USE_BOTH));
foreach ($item->list as $subItem) {
$subItem->unit_url = encrypt($subItem->unit_id);
$tmpFile = unserialize($subItem->file);
$subItem->file = is_array($tmpFile) ? $tmpFile : [];
//has unit user
$keyman_user = $wpdb->get_row("SELECT id, username FROM keyman_user WHERE uid = '{$subItem->unit_id}'");
$subItem->keyman_user = $keyman_user;
if(isset($keyman_user->id)) {
$subItem->has_user = 1;
$subItem->user_login = $keyman_user->username;
}else {
$subItem->has_user = 0;
$subItem->user_login = '';
}
}
}
$rv->list = $list;
exit(json_encode($rv));