HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wp-content/themes/ormedia/keylabData/incident/u_incident.php
<?php
if (isset($_REQUEST['checking_api_file'])) {
    exit();
}

$incident_id = $_POST['incident_id'];

$old_data = $wpdb->get_results("select * from keylab_property_incident where incident_id = " . $incident_id);
$new_data = array(
    'title' => $_POST['title'],
    'date' => $_POST['date'],
    'description' => $_POST['description'],
    'contract_person' => $_POST['contract_person'],
    'assigned_to' => $_POST['assigned_to'],
    'ref' => $_REQUEST['ref'],
    'incident_file' => serialize($_REQUEST['incident_file']),
);

$status = false;
$status = $wpdb->update("keylab_property_incident", $new_data, array('incident_id' => $incident_id));

//修改ref    
$statement = "SELECT incident_id, ref FROM keylab_property_incident WHERE ref = ''";
$results = $wpdb->get_results($statement);

foreach ($results as $value) {
    $wpdb->update("keylab_property_incident", [
        'ref' => '#' . $value->incident_id
    ], [
        'incident_id' => $value->incident_id
    ]);
}

if ($status === false) {
    $rv->status = false;
    $rv->error = $wpdb->last_error;
} else {
    $rv->status = true;
    // 发送email给assigned_to
    if (is_numeric($new_data['assigned_to'])) {
        $tmp_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM wp_users WHERE ID = %d", $new_data['assigned_to']));
        $useremail = $tmp_user->user_email;
        if (!empty($useremail)) {
            $filestr = "";
            $files = unserialize($new_data['incident_file']) ?: [];
            if (is_array($files)) {
                if (count($files) > 0) {
                    $filestr .= '<div><ol type="1">';
                    foreach ($files as $file) {
                        $filestr .= '<li>';
                        $filestr .= '<span><a href="' . $file['url'] . '">' . $file['name'] . '</a></span>';
                        $filestr .= '</li>';
                    }
                    $filestr .= '</ol></div>';
                }
            }
            $building_name = $wpdb->get_var("select name_zh from keylab_property where property_id = " . $old_data[0]->property_id);
            $ref = $wpdb->get_var("SELECT ref FROM keylab_property_incident WHERE incident_id = " . $incident_id);
            $html = '
            <style>.keylab_notice,.keylab_notice td{font-size:16px;}</style>
            <div class="keylab_notice">
                <table>
                    <tr>
                        <td>事件編號:</td>
                        <td>' . $ref . '</td>
                    </tr>
                    <tr>
                        <td>所在大廈:</td>
                        <td>' . $building_name . '</td>
                    </tr>
                    <tr>
                        <td>事件標題:</td>
                        <td>' . $new_data['title'] . '</td>
                    </tr>
                    <tr>
                        <td>事件日期:</td>
                        <td>' . $new_data['date'] . '</td>
                    </tr>
                    <tr>
                        <td>聯絡人:</td>
                        <td>' . $new_data['contract_person'] . '</td>
                    </tr>
                    <tr>
                        <td>分配給:</td>
                        <td>' . $tmp_user->user_login . '</td>
                    </tr>
                </table>
                <div style="padding: 15px 2px 15px 2px;">
                    事件描述:
                    <div>' . stripslashes($new_data['description']) . '</div>
                </div>
                <div style="padding:2px;">事件檔案:' . $filestr . '</div>
            </div>
            ';
            $args = [
                'to' => [$useremail],
                'subject' => "事件管理 《" . $new_data['title'] . "》 已更新",
                'html' => $html
            ];
            $rv->email_args = $args;
            $rv->debug = send_email_by_mailjet($args);
        }
    }
}
$rv->wpdb = $wpdb;

//log
keylab_data_log_by_user2($status, $old_data[0], $new_data, $wpdb->last_query, "keylab_property_incident", $incident_id);

exit(json_encode($rv));