$expire)) { session_destroy(); header("Location: login.php"); exit; } $_SESSION['login_time'] = time(); $userName = htmlspecialchars($_SESSION['username']); $userRoleId = $_SESSION['role_id']; // 全局配置库连接 $dbConfigHost = "10.150.117.190"; $dbConfigUser = "root"; $dbConfigPwd = "hp93000"; $dbConfigName = "alert_mail_stat"; $connConfig = mysqli_connect($dbConfigHost, $dbConfigUser, $dbConfigPwd, $dbConfigName); if(!$connConfig){ die("配置库连接失败"); } mysqli_set_charset($connConfig, "utf8mb4"); // 自动创建SMTP配置表,不存在则新建 mysqli_query($connConfig, "CREATE TABLE IF NOT EXISTS sys_smtp_config ( id INT PRIMARY KEY AUTO_INCREMENT, smtp_host VARCHAR(200) NOT NULL DEFAULT '', smtp_port INT NOT NULL DEFAULT 25, smtp_ssl TINYINT NOT NULL DEFAULT 0, smtp_user VARCHAR(200) NOT NULL DEFAULT '', smtp_pass VARCHAR(200) NOT NULL DEFAULT '', send_from VARCHAR(200) NOT NULL DEFAULT '' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); $checkRow = mysqli_fetch_assoc(mysqli_query($connConfig, "SELECT id FROM sys_smtp_config LIMIT 1")); if (empty($checkRow)) { mysqli_query($connConfig, "INSERT INTO sys_smtp_config (id) VALUES (1)"); } // 自动创建工单推送通知表 mysqli_query($connConfig, "CREATE TABLE IF NOT EXISTS sys_workorder_notify ( id INT PRIMARY KEY AUTO_INCREMENT, dingtalk_webhook VARCHAR(500) NOT NULL DEFAULT '', dingtalk_secret VARCHAR(200) NOT NULL DEFAULT '', wecom_webhook VARCHAR(500) NOT NULL DEFAULT '', wecom_mention VARCHAR(300) NOT NULL DEFAULT '', notify_open TINYINT NOT NULL DEFAULT 0, update_time DATETIME NOT NULL DEFAULT NOW() ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); $configSql = "SELECT k,v FROM sys_config"; $configRes = mysqli_query($connConfig, $configSql); $sysConfig = []; while ($row = mysqli_fetch_assoc($configRes)) { $sysConfig[$row['k']] = $row['v']; } // 安全读取SMTP配置,杜绝mysqli警告 $smtpRow = []; $sqlSmtp = "SELECT * FROM sys_smtp_config WHERE id=1"; if (!empty(trim($sqlSmtp))) { $smtpQuery = mysqli_query($connConfig, $sqlSmtp); if ($smtpQuery !== false && $smtpQuery instanceof mysqli_result) { $smtpRow = mysqli_fetch_assoc($smtpQuery) ?: []; } } $smtpConfig = $smtpRow ?? []; // 安全读取推送通知配置 $notifyConfig = []; $notifyQuery = mysqli_query($connConfig, "SELECT * FROM sys_workorder_notify LIMIT 1"); if ($notifyQuery instanceof mysqli_result) { $notifyConfig = mysqli_fetch_assoc($notifyQuery) ?: []; } $pageTitle = htmlspecialchars($sysConfig['page_subtitle'] ?? "工单消息通知配置"); $currentLang = $sysConfig['lang'] ?? "zh"; $sidebarRawLinks = $sysConfig['sidebar_links'] ?? ""; mysqli_close($connConfig); // 多语言词典(菜单文字全部替换:SMTP配置 → 工单消息通知配置) $langMap = [ 'zh' => [ 'html_lang' => 'zh-CN', 'page_subtitle' => '工单消息通知配置', 'monitor_panel' => '监控面板', 'alert_overview' => '告警总览', 'quick_link' => '快捷外链', 'system_manage' => '系统管理', 'notify_config' => '工单消息通知配置', 'current_user' => '当前用户:', 'sys_time' => '系统时间:', 'refresh_all' => '刷新页面', 'export_csv' => '导出CSV', 'logout' => '退出登录', 'lang_text' => '语言:', 'work_order_mgr' => '工单系统', 'save_all' => '保存全部通知配置', 'card_title' => '工单消息推送 & 发件邮箱统一配置', 'group_mail' => '邮箱SMTP发件设置', 'smtp_host' => 'SMTP服务器', 'smtp_port' => '端口', 'smtp_ssl' => '启用SSL/TLS加密', 'smtp_account' => '登录账号', 'smtp_pwd' => '授权密码', 'smtp_from' => '发件人邮箱', 'group_push' => '工单变更推送配置', 'notify_switch' => '开启工单变更自动推送', 'dingtalk_webhook' => '钉钉Webhook地址', 'dingtalk_secret' => '钉钉安全密钥(可选)', 'wecom_webhook' => '企业微信Webhook地址', 'wecom_mention' => '@提醒人员(多个逗号分隔,all=全员)', 'placeholder_webhook' => '输入完整Webhook链接', 'placeholder_secret' => '无安全校验则留空', 'placeholder_mention' => '填写手机号,all代表所有人', 'save_success' => '配置保存成功' ], 'en' => [ 'html_lang' => 'en', 'page_subtitle' => 'Work Order Notification Config', 'monitor_panel' => 'Monitor Panel', 'alert_overview' => 'Alert Overview', 'quick_link' => 'Quick Links', 'system_manage' => 'System Manage', 'notify_config' => 'Work Order Notification Config', 'current_user' => 'User: ', 'sys_time' => 'System Time: ', 'refresh_all' => 'Refresh', 'export_csv' => 'Export CSV', 'logout' => 'Logout', 'lang_text' => 'Lang: ', 'work_order_mgr' => 'Work Order System', 'save_all' => 'Save All Notification Config', 'card_title' => 'Work Order Push & Mail Sender Config', 'group_mail' => 'SMTP Mail Sender', 'smtp_host' => 'SMTP Host', 'smtp_port' => 'Port', 'smtp_ssl' => 'Enable SSL/TLS', 'smtp_account' => 'Account', 'smtp_pwd' => 'Auth Password', 'smtp_from' => 'Sender Email', 'group_push' => 'Work Order Push Setting', 'notify_switch' => 'Auto push on order change', 'dingtalk_webhook' => 'DingTalk Webhook', 'dingtalk_secret' => 'DingTalk Secret (Optional)', 'wecom_webhook' => 'WeCom Webhook', 'wecom_mention' => 'Mention user (split by comma, all=everyone)', 'placeholder_webhook' => 'Full webhook url', 'placeholder_secret' => 'Leave empty if no secret', 'placeholder_mention' => 'Mobile number or all', 'save_success' => 'Config saved successfully' ] ]; $t = $langMap[$currentLang]; // 解析外链菜单 $sidebarLinkList = []; if (!empty($sidebarRawLinks)) { $lines = explode("\n", $sidebarRawLinks); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; $item = explode("|", $line, 2); if (count($item) === 2) { $sidebarLinkList[] = ["name" => trim($item[0]), "url" => trim($item[1])]; } } } // 统一保存表单提交逻辑(SMTP+推送一次保存) if ($_POST['act'] === "save_all") { // 更新SMTP邮箱配置 $host = trim($_POST['smtp_host'] ?? ''); $port = intval($_POST['smtp_port'] ?? 25); $ssl = intval($_POST['smtp_ssl'] ?? 0); $user = trim($_POST['smtp_user'] ?? ''); $pwd = trim($_POST['smtp_pass'] ?? ''); $from = trim($_POST['smtp_from'] ?? ''); mysqli_query($connConfig, "UPDATE sys_smtp_config SET smtp_host='$host',smtp_port=$port,smtp_ssl=$ssl,smtp_user='$user',smtp_pass='$pwd',send_from='$from' WHERE id=1"); // 更新工单推送配置 $ding_webhook = trim($_POST['dingtalk_webhook'] ?? ''); $ding_secret = trim($_POST['dingtalk_secret'] ?? ''); $wecom_webhook = trim($_POST['wecom_webhook'] ?? ''); $wecom_mention = trim($_POST['wecom_mention'] ?? ''); $notify_open = intval($_POST['notify_open'] ?? 0); $existNotify = mysqli_fetch_assoc(mysqli_query($connConfig, "SELECT id FROM sys_workorder_notify LIMIT 1")); if ($existNotify) { mysqli_query($connConfig, "UPDATE sys_workorder_notify SET dingtalk_webhook='$ding_webhook', dingtalk_secret='$ding_secret', wecom_webhook='$wecom_webhook', wecom_mention='$wecom_mention', notify_open=$notify_open, update_time=NOW() WHERE id = {$existNotify['id']}"); } else { mysqli_query($connConfig, "INSERT INTO sys_workorder_notify (dingtalk_webhook,dingtalk_secret,wecom_webhook,wecom_mention,notify_open) VALUES ('$ding_webhook','$ding_secret','$wecom_webhook','$wecom_mention',$notify_open)"); } echo ""; exit; } ?>