<?php
if (!defined('_GNUBOARD_')) exit;
include_once("{$board_skin_path}/db_update.php");
add_stylesheet('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">', 0);
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.write.css">', 0);
if (!$write['x2_ver']) {
$row_ver = sql_fetch(" select x2_ver from {$write_table} order by wr_id desc limit 1 ");
$default_ver = isset($row_ver['x2_ver']) ? $row_ver['x2_ver'] : '';
} else {
$default_ver = $write['x2_ver'];
}
$row_status = sql_fetch(" SELECT @@event_scheduler as status ");
$scheduler_state = strtoupper($row_status['status']);
$state_color = ($scheduler_state === 'ON') ? '#00d4ff' : '#ff2d55';
$registered_events = [];
$sql_reg = " select wr_subject from {$write_table} ";
$res_reg = sql_query($sql_reg);
while($row_reg = sql_fetch_array($res_reg)) {
$registered_events[] = $row_reg['wr_subject'];
}
$real_db_events = [];
$sql_evt = " SELECT EVENT_SCHEMA, EVENT_NAME
FROM information_schema.EVENTS
WHERE EVENT_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
ORDER BY EVENT_SCHEMA, EVENT_NAME ";
$res_evt = sql_query($sql_evt);
while($row_evt = sql_fetch_array($res_evt)) {
$real_db_events[] = $row_evt['EVENT_NAME'];
}
$available_list = [];
foreach ($real_db_events as $evt_name) {
if (in_array($evt_name, $registered_events) && $evt_name !== $subject) {
continue;
}
$available_list[] = $evt_name;
}
$used_db_tables = [];
$sql_used_table = " select distinct x2_db_table from {$write_table} where x2_db_table <> '' ";
if ($w === 'u' && $wr_id) {
$sql_used_table .= " and wr_id <> '".sql_escape_string($wr_id)."' ";
}
$res_used_table = sql_query($sql_used_table);
while($row_used_table = sql_fetch_array($res_used_table)) {
$used_db_tables[] = $row_used_table['x2_db_table'];
}
global $db_upbit;
$db_tables = [];
if (isset($db_upbit) && $db_upbit) {
if ($db_upbit instanceof mysqli) {
$res_tables = mysqli_query($db_upbit, "SHOW TABLES");
if ($res_tables) {
while ($row_table = mysqli_fetch_row($res_tables)) {
$db_tables[] = $row_table[0];
}
}
} else if ($db_upbit instanceof PDO) {
$stmt = $db_upbit->query("SHOW TABLES");
if ($stmt) {
while ($row_table = $stmt->fetch(PDO::FETCH_NUM)) {
$db_tables[] = $row_table[0];
}
}
}
}
$file_count = (isset($board['bo_upload_count']) && $board['bo_upload_count']) ? $board['bo_upload_count'] : 0;
$has_data = ($w == 'u' && (
trim($write['wr_content']) ||
trim($write['x2_content']) ||
trim($write['x2_content_2']) ||
trim($write['wr_link1']) ||
trim($write['wr_link2']) ||
(isset($file[0]['file']) && $file[0]['file'])
));
$memo_panel_class = (!empty($write['x2_memo_button']) || trim((string)$write['x2_memo']) !== '') ? 'is-open' : 'is-close';
?>
<div id="WRITE_WRAP">
<article id="WRITE">
<form name="fwrite" id="fwrite" action="<?php echo $action_url ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
<input type="hidden" name="w" value="<?php echo $w ?>">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl ?>">
<input type="hidden" name="stx" value="<?php echo $stx ?>">
<input type="hidden" name="spt" value="<?php echo $spt ?>">
<input type="hidden" name="sst" value="<?php echo $sst ?>">
<input type="hidden" name="sod" value="<?php echo $sod ?>">
<input type="hidden" name="page" value="<?php echo $page ?>">
<?php if ($is_notice || $is_html || $is_secret || $is_mail) { ?>
<?php if ($is_notice) { ?><input type="checkbox" id="notice" name="notice" value="1" <?php echo $notice_checked; ?>><?php } ?>
<?php if ($is_html) { ?>
<?php if ($is_dhtml_editor) { ?><input type="hidden" value="html1" name="html"><?php } else { ?><input type="checkbox" id="html" name="html" onclick="html_auto_br(this);" value="<?php echo $html_value; ?>" <?php echo $html_checked; ?>><?php } ?>
<?php } ?>
<?php if ($is_secret) { ?>
<?php if ($is_admin || $is_secret==1) { ?><input type="checkbox" id="secret" name="secret" value="secret" <?php echo $secret_checked; ?>><?php } else { ?><input type="hidden" name="secret" value="secret"><?php } ?>
<?php } ?>
<?php if ($is_mail) { ?><input type="checkbox" id="mail" name="mail" value="mail" <?php echo $recv_email_checked; ?>><?php } ?>
<?php } ?>
<div class="write-header">
<div class="write-header__title-group">
<h2 class="write-header__title"><i class="fa-solid fa-server"></i> EVENT_MANAGER</h2>
<span class="write-header__status-badge" style="--badge-color:<?php echo $state_color; ?>;">MAIN_POWER : <?php echo $scheduler_state; ?></span>
</div>
<div class="write-header__btn-group">
<button type="button" class="btn-cancel" onclick="window.history.back();">취 소</button>
<button type="submit" class="btn-submit btn-submit--small">저 장</button>
</div>
</div>
<table class="write-table">
<tr>
<td class="td-label"><i class="fa-solid fa-sliders"></i> 기본설정</td>
<td class="td-content">
<div class="form-row form-row--grouped">
<?php if ($is_category) { ?>
<div class="form-group">
<span class="form-label">거래소</span>
<select name="ca_name" id="id_ca_name" required>
<option value="">거래소 선택</option>
<?php echo $category_option; ?>
</select>
</div>
<?php } ?>
<div class="form-group">
<span class="form-label">종류</span>
<select name="x2_ca2" id="id_x2_ca2">
<option value="">종류 선택</option>
<?php
$x2_ca2_options = explode('|', $board['bo_1']);
foreach($x2_ca2_options as $opt) {
$opt = trim($opt);
if(!$opt) continue;
echo '<option value="'.$opt.'" '.($write['x2_ca2'] == $opt ? 'selected' : '').'>'.$opt.'</option>';
}
?>
</select>
</div>
<div class="form-group">
<span class="form-label">형태</span>
<select name="x2_ca3" id="id_x2_ca3">
<option value="">형태 선택</option>
<?php
$x2_ca3_options = explode('|', $board['bo_2']);
foreach($x2_ca3_options as $opt) {
$opt = trim($opt);
if(!$opt) continue;
echo '<option value="'.$opt.'" '.($write['x2_ca3'] == $opt ? 'selected' : '').'>'.$opt.'</option>';
}
?>
</select>
</div>
<div class="form-group form-group--toggle">
<span class="form-label">우선</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_top" id="id_x2_top" value="1" <?php echo !empty($write['x2_top']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<div class="form-group form-group--toggle">
<span class="form-label">라벨</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_label" id="id_x2_label" value="1" <?php echo !empty($write['x2_label']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<div class="form-group form-group--toggle">
<span class="form-label">핵심</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_core" id="id_x2_core" value="1" <?php echo !empty($write['x2_core']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<div class="form-group form-group--toggle">
<span class="form-label">메모</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_memo_button" id="id_x2_memo_button" value="1" <?php echo $memo_panel_class === 'is-open' ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
<div class="form-group form-group--right">
<span class="form-label">버전</span>
<input type="text" name="x2_ver" id="id_x2_ver" value="<?php echo $default_ver; ?>" size="12" placeholder="VERSION">
</div>
</div>
</td>
</tr>
<tr id="memo_row" class="memo-row" style="display:<?php echo $memo_panel_class === 'is-open' ? 'table-row' : 'none'; ?>;">
<td class="td-label"><i class="fa-solid fa-note-sticky"></i> 메모</td>
<td class="td-content">
<div id="memo_panel_wrap" class="memo-panel-wrap" style="display:<?php echo $memo_panel_class === 'is-open' ? 'block' : 'none'; ?>;">
<div class="memo-panel">
<div class="memo-head">
<span class="memo-title"><i class="fa-solid fa-sliders"></i> 메모 설정</span>
<div class="form-group form-group--toggle">
<span class="form-label">메모 삭제</span>
<label class="toggle-btn">
<input type="checkbox" name="x2_memo_clean" id="id_x2_memo_clean" value="1" <?php echo !empty($write['x2_memo_clean']) ? 'checked' : ''; ?>>
<span class="slider"></span>
</label>
</div>
</div>
<div class="memo-body">
<textarea name="x2_memo" id="id_x2_memo" rows="4" class="textarea-custom" placeholder="메모를 입력하세요"><?php echo isset($write['x2_memo']) ? get_text($write['x2_memo'], 0) : ''; ?></textarea>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-calendar-check"></i> 이벤트설정</td>
<td class="td-content">
<div class="form-row form-row--grouped">
<div class="form-group">
<span class="form-label">이벤트</span>
<select name="wr_subject" id="event_select" class="select-coin" required>
<option value="">SCANNING_DB_EVENTS...</option>
<?php
if (count($available_list) > 0) {
echo '<option value="" disabled>--- NEW EVENTS (' . count($available_list) . ') ---</option>';
foreach ($available_list as $evt) {
$selected = ($subject == $evt) ? 'selected' : '';
echo "<option value=\"{$evt}\" {$selected}>{$evt}</option>";
}
} else {
echo '<option value="">NO NEW EVENTS FOUND</option>';
}
if ($w == 'u' && !in_array($subject, $available_list)) {
echo "<option value=\"{$subject}\" selected>{$subject} (REGISTERED)</option>";
}
?>
</select>
</div>
<div class="form-group">
<span class="form-label">한글명</span>
<input type="text" name="wr_subject_kor" id="id_wr_subject_kor" value="<?php echo isset($write['wr_subject_kor']) ? get_text($write['wr_subject_kor']) : ''; ?>" class="input-kor" placeholder="한글명">
</div>
<div class="form-group form-group--expand">
<span class="form-label">메모</span>
<input type="text" name="wr_1" id="wr_1" value="<?php echo isset($write['wr_1']) ? $write['wr_1'] : ''; ?>" class="input-full" placeholder="MEMO / DESCRIPTION">
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-diagram-project"></i> BD 설정</td>
<td class="td-content">
<div class="form-row form-row--grouped form-row--bd">
<div class="form-group">
<span class="form-label">원장</span>
<select name="x2_db_master" id="id_x2_db_master">
<option value="">원장 : 테이블 선택</option>
<?php
foreach($db_tables as $tn) {
echo '<option value="'.$tn.'" '.($write['x2_db_master'] == $tn ? 'selected' : '').'>'.$tn.'</option>';
}
?>
</select>
</div>
<div class="arrow-icon"><i class="fa-solid fa-arrow-right-long"></i></div>
<div class="form-group">
<span class="form-label">대장</span>
<select name="x2_db_table" id="id_x2_db_table">
<option value="">대장 : 테이블 선택</option>
<?php
foreach($db_tables as $tn) {
if (in_array($tn, $used_db_tables, true)) {
continue;
}
echo '<option value="'.$tn.'" '.($write['x2_db_table'] == $tn ? 'selected' : '').'>'.$tn.'</option>';
}
?>
</select>
</div>
<div class="form-group">
<span class="form-label">대장명</span>
<input type="text" name="x2_db_table_name" id="id_x2_db_table_name" value="<?php echo isset($write['x2_db_table_name']) ? get_text($write['x2_db_table_name']) : ''; ?>" placeholder="대장명 입력">
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-tags"></i> 태그</td>
<td class="td-content">
<div class="form-group form-group--expand">
<input type="text" name="x2_tag" id="x2_tag" value="<?php echo isset($write['x2_tag']) ? $write['x2_tag'] : ''; ?>" class="input-full" placeholder="TAG">
</div>
</td>
</tr>
</table>
<button type="button" id="btn_extra_toggle" class="btn-toggle-clean">
상세 파라미터 및 페이로드 관리 <i class="fa-solid <?php echo $has_data ? 'fa-chevron-up' : 'fa-chevron-down'; ?>"></i>
</button>
<div id="extra_area" class="extra-content" style="display:<?php echo $has_data ? 'block' : 'none'; ?>;">
<table class="write-table">
<tr>
<td class="td-label"><i class="fa-solid fa-file-code"></i> 상세 설명</td>
<td class="td-content td-content--editor"><?php echo $editor_html; ?></td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-file-lines"></i> 추가 설명</td>
<td class="td-content">
<textarea name="x2_content" id="id_x2_content" class="textarea-custom" placeholder="ADDITIONAL_DESCRIPTION"><?php echo get_text($write['x2_content'], 0); ?></textarea>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-circle-exclamation"></i> 특이사항</td>
<td class="td-content">
<textarea name="x2_content_2" id="id_x2_content_2" class="textarea-custom" placeholder="SPECIAL NOTE"><?php echo get_text($write['x2_content_2'], 0); ?></textarea>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-link"></i> 링크</td>
<td class="td-content">
<div class="form-row form-row--grouped">
<div class="form-group form-group--expand">
<span class="form-label">링크1</span>
<input type="text" name="wr_link1" id="wr_link1" value="<?php echo isset($write['wr_link1']) ? get_text($write['wr_link1']) : ''; ?>" class="input-full" placeholder="https://example.com">
</div>
<div class="form-group form-group--expand">
<span class="form-label">링크2</span>
<input type="text" name="wr_link2" id="wr_link2" value="<?php echo isset($write['wr_link2']) ? get_text($write['wr_link2']) : ''; ?>" class="input-full" placeholder="https://example.com">
</div>
</div>
</td>
</tr>
<tr>
<td class="td-label"><i class="fa-solid fa-paperclip"></i> 페이로드 첨부</td>
<td class="td-content">
<div id="variableFiles">
<?php for ($i=0; $is_file && $i<$file_count; $i++) {
$is_active = ($i == 0 || (isset($file[$i]['file']) && $file[$i]['file'])) ? 'active' : '';
?>
<div class="file-box-custom <?php echo $is_active; ?>" id="f_row_<?php echo $i; ?>">
<label for="bf_file_<?php echo $i; ?>" class="file-btn-ui">FILE_SELECT</label>
<input type="file" name="bf_file[]" id="bf_file_<?php echo $i; ?>" class="file-input-hidden" onchange="updateFileInfo(this, <?php echo $i; ?>)">
<span id="f_name_<?php echo $i; ?>" class="file-info-ui">
<?php echo (isset($file[$i]['file']) && $file[$i]['file']) ? $file[$i]['source'] : 'NO_DATA_STREAMED'; ?>
</span>
<?php if ($board['bo_use_file_content']) { ?>
<input type="text" name="bf_content[]" value="<?php echo ($w == 'u') ? stripslashes($file[$i]['bf_content']) : ''; ?>" class="file-desc-ui" placeholder="FILE_DESCRIPTION">
<?php } ?>
<?php if($w == 'u' && isset($file[$i]['file']) && $file[$i]['file']) { ?>
<label class="file-del-label"><input type="checkbox" name="bf_file_del[<?php echo $i; ?>]" value="1"> DEL</label>
<?php } ?>
</div>
<?php } ?>
</div>
<button type="button" class="btn-toggle-clean btn-add-slot" onclick="addFileSlot();">+ ADD_SLOT</button>
</td>
</tr>
</table>
</div>
<div class="write-footer">
<button type="submit" class="btn-submit">SAVE CONFIG</button>
</div>
</form>
</article>
</div>
<?php include_once($board_skin_path.'/write/write.script.php'); ?>