File: /var/www/html/wp-content/themes/ormedia/keylabData/propman/c_propman.php
<?php
if (isset($_REQUEST['checking_api_file'])) {
exit();
}
$identity_card_results = $wpdb->get_results("select identity_card from keylab_property_propman_security");
if(!empty($_REQUEST['identity_card'])){
foreach($identity_card_results as $value){
if(!empty($value->identity_card) && $value->identity_card == trim($_REQUEST['identity_card'])){
$rv->status = false;
$rv->code = -2;
$rv->error = 'identity_card diff';
exit(json_encode($rv));
}
}
}
$status = false;
$propman_status = [
'在職', '離職'
];
if(empty($_REQUEST['propman_status'])){
$new_data = array(
'property_id' => $_REQUEST['property_id'],
'user_id' => $_REQUEST['user_id'],
'position' => $_REQUEST['position'],
'propman_status' => $propman_status[0],
'propman_day' => date("Y-m-d"),
'remarks' => $_REQUEST['remarks'],
'MPF_date' => $_REQUEST['MPF_date'],
'MPF_file' => serialize($_REQUEST['MPF_file']),
);
}else{
if(in_array($_REQUEST['propman_status'], $propman_status)){
$new_data = array(
'property_id' => $_REQUEST['property_id'],
'user_id' => $_REQUEST['user_id'],
'position' => $_REQUEST['position'],
'propman_status' => $_REQUEST['propman_status'],
'propman_day' => $_REQUEST['propman_status']=='在職'?date("Y-m-d"):'0000-00-00',
'remarks' => $_REQUEST['remarks'],
'MPF_date' => $_REQUEST['MPF_date'],
'MPF_file' => serialize($_REQUEST['MPF_file']),
);
}else{
$rv->status = false;
$rv->code = -3;
$rv->error = 'propman_status undefined';
exit(json_encode($rv));
}
}
$status = $wpdb->insert("keylab_property_propman", $new_data);
$sql = $wpdb->last_query;
$log_id = $wpdb->insert_id;
$admin_wp_id = $wpdb->get_var("SELECT admin_wp_id from keylab_property where `property_id` = '".$_REQUEST['property_id']."'");
$temp_result = $wpdb->get_results("SELECT ID as id,user_login,user_email from wp_users where `ID` = '$admin_wp_id'");
if($_REQUEST['position'] == '保安員' && $status !== false){
$last_propman_id = $wpdb->insert_id;
$status = insert_calendar([
"property_id" => $_REQUEST['property_id'],
"time" => $_REQUEST['cert_due_date'].' 00:00:00',
"priority" => '0',
"type" => 2,
"description" => $_REQUEST['name_zh'].' 的保安證過期時間',
"notification" => 1,
"source" => serialize([
"keylab_property_propman",
$wpdb->insert_id
]),
"cal_type" => 1,
"ann_list" => serialize($temp_result)
]);
if($status !== false){
$status = $wpdb->insert("keylab_property_propman_security", array(
'propman_id' => $last_propman_id,
'shift' => $_REQUEST['shift'],
'birth_date' => $_REQUEST['birth_date'],
'cert_due_date' => $_REQUEST['cert_due_date'],
'cert_due_date2' => $_REQUEST['cert_due_date2'],
'cert_due_date3' => $_REQUEST['cert_due_date3'],
'cert_due_date4' => $_REQUEST['cert_due_date4'],
'physical_date' => $_REQUEST['physical_date'],
'cert_no' => $_REQUEST['cert_no'],
'identity_card' => trim($_REQUEST['identity_card']),
'body_check_file' => serialize($_REQUEST['body_check_file']),
'calendar_id' => $wpdb->insert_id,
'propman_no'=> $_REQUEST['propman_no'],
'separation'=> $_REQUEST['separation'],
'exchange_date'=> $_REQUEST['exchange_date'],
'departure_date'=> $_REQUEST['departure_date'],
'on_work_time'=> $_REQUEST['on_work_time'],
'out_work_time'=> $_REQUEST['out_work_time'],
'morning' => $_REQUEST['morning'],
'noon' => $_REQUEST['noon'],
'extra' => $_REQUEST['extra'],
'daily_wage' => $_REQUEST['daily_wage'],
'wage' => $_REQUEST['wage'],
'address' => $_REQUEST['address'],
'post_rank' => $_REQUEST['post_rank'],
'HKID' => $_REQUEST['post_rank'],
'license_no' => $_REQUEST['license_no'],
'certificate' => $_REQUEST['certificate'],
'QAS' => $_REQUEST['QAS'],
'bank_account' => $_REQUEST['bank_account'],
'bank_name' => $_REQUEST['bank_name'],
'personal_file' => serialize($_REQUEST['personal_file']),
));
}else{
$status = $wpdb->insert("keylab_property_propman_security", array(
'propman_id' => $last_propman_id,
'shift' => $_REQUEST['shift'],
'birth_date' => $_REQUEST['birth_date'],
'cert_due_date' => $_REQUEST['cert_due_date'],
'cert_due_date2' => $_REQUEST['cert_due_date2'],
'cert_due_date3' => $_REQUEST['cert_due_date3'],
'cert_due_date4' => $_REQUEST['cert_due_date4'],
'physical_date' => $_REQUEST['physical_date'],
'cert_no' => $_REQUEST['cert_no'],
'identity_card' => trim($_REQUEST['identity_card']),
'body_check_file' => serialize($_REQUEST['body_check_file']),
'propman_no'=> $_REQUEST['propman_no'],
'separation'=> $_REQUEST['separation'],
'exchange_date'=> $_REQUEST['exchange_date'],
'departure_date'=> $_REQUEST['departure_date'],
'on_work_time'=> $_REQUEST['on_work_time'],
'out_work_time'=> $_REQUEST['out_work_time'],
'morning' => $_REQUEST['morning'],
'noon' => $_REQUEST['noon'],
'extra' => $_REQUEST['extra'],
'daily_wage' => $_REQUEST['daily_wage'],
'wage' => $_REQUEST['wage'],
'address' => $_REQUEST['address'],
'post_rank' => $_REQUEST['post_rank'],
'HKID' => $_REQUEST['post_rank'],
'license_no' => $_REQUEST['license_no'],
'certificate' => $_REQUEST['certificate'],
'QAS' => $_REQUEST['QAS'],
'bank_account' => $_REQUEST['bank_account'],
'bank_name' => $_REQUEST['bank_name'],
'personal_file' => serialize($_REQUEST['personal_file']),
));
}
}
if ($status === false) {
$rv->status = false;
$rv->code = -1;
$rv->error = $wpdb->last_error;
} else {
$rv->status = true;
$rv->code = 0;
}
//log
keylab_data_log_by_user2($status, false, $new_data, $sql, "keylab_property_propman",$log_id);
exit(json_encode($rv));
?>