diff --git a/nexus/Database/DB.php b/nexus/Database/DB.php index 8060185d..07df4361 100644 --- a/nexus/Database/DB.php +++ b/nexus/Database/DB.php @@ -164,4 +164,20 @@ class DB return mysql_affected_rows(); } + public static function getOne($table, $whereStr, $fields = '*') + { + if ($fields != '*') { + if (is_array($fields)) { + $fields = implode(', ', $fields); + } + } + if (empty($fields)) { + do_log("args: " . json_encode(func_get_args())); + throw new DatabaseException("empty fields."); + } + $sql = "select $fields from $table where $whereStr limit 1"; + $res = sql_query($sql); + return mysql_fetch_assoc($res); + } + } \ No newline at end of file diff --git a/nexus/Field/Field.php b/nexus/Field/Field.php index 405b19c5..afecb07b 100644 --- a/nexus/Field/Field.php +++ b/nexus/Field/Field.php @@ -75,7 +75,7 @@ HTML; $perPage = 10; $total = get_row_count('torrents_custom_fields'); list($paginationTop, $paginationBottom, $limit) = pager($perPage, $total, "?"); - $sql = "select * from torrents_custom_fields order by id desc $limit"; + $sql = "select * from torrents_custom_fields order by id asc $limit"; $res = sql_query($sql); $header = [ 'id' => $lang_fields['col_id'], @@ -178,4 +178,33 @@ HEAD; $table .= ''; return $table; } + + public function buildFieldCheckbox($name, $current = []) + { + $sql = 'select * from torrents_custom_fields'; + $res = sql_query($sql); + $checkbox = []; + if (!is_array($current)) { + $current = explode(',', $current); + } + while ($row = mysql_fetch_assoc($res)) { + $checkbox[] = sprintf( + '', + $name, $row['id'], in_array($row['id'], $current) ? ' checked' : '', "{$row['label']}({$row['id']})" + ); + } + return implode('', $checkbox); + + } + + public function renderUploadPage() + { + $searchBoxId = get_setting('main.browsecat'); + $searchBox = DB::getOne('searchbox', "id = $searchBoxId"); + if (empty($searchBox)) { + throw new \RuntimeException("Invalid search box: $searchBoxId"); + } + $customFieldIdArr = explode(',', $searchBox['custom_fields']); + + } } \ No newline at end of file diff --git a/public/catmanage.php b/public/catmanage.php index d865b9d6..03c2f363 100644 --- a/public/catmanage.php +++ b/public/catmanage.php @@ -233,6 +233,8 @@ function print_category_editor($type, $row='') } tr($lang_catmanage['row_searchbox_name']."*", " " . $lang_catmanage['text_searchbox_name_note'], 1); tr($lang_catmanage['row_show_sub_category'], " " . $lang_catmanage['text_sources'] . " " . $lang_catmanage['text_media'] . " " . $lang_catmanage['text_codecs'] . " " . $lang_catmanage['text_standards'] . " " . $lang_catmanage['text_processings'] . " " . $lang_catmanage['text_teams'] . " " . $lang_catmanage['text_audio_codecs']."
".$lang_catmanage['text_show_sub_category_note'], 1); + $field = new \Nexus\Field\Field(); + tr('显示自字义字段', $field->buildFieldCheckbox('custom_fields[]', $row['custom_fields']), 1); tr($lang_catmanage['row_items_per_row']."*", " " . $lang_catmanage['text_items_per_row_note'], 1); tr($lang_catmanage['row_padding_between_items']."*", " " . $lang_catmanage['text_padding_between_items_note'], 1); } @@ -700,6 +702,7 @@ elseif($action == 'submit') $updateset[] = "showprocessing=".sqlesc($showprocessing); $updateset[] = "showteam=".sqlesc($showteam); $updateset[] = "showaudiocodec=".sqlesc($showaudiocodec); + $updateset[] = "custom_fields=" . sqlesc(implode(',', $_POST['custom_fields'] ?? [])); if ($showsource || $showmedium || $showcodec || $showstandard || $showprocessing || $showteam || $showaudiocodec) $updateset[] = "showsubcat=1"; else diff --git a/public/fields.php b/public/fields.php index f965c871..b066712e 100644 --- a/public/fields.php +++ b/public/fields.php @@ -41,6 +41,14 @@ if ($action == 'view') { stdhead($lang_fields['field_management']." - ".$lang_fields['text_edit']); begin_main_frame(); echo $field->buildFieldForm($row); +} elseif ($action == 'del') { + $id = intval($_GET['id'] ?? 0); + if ($id == 0) { + stderr($lang_fields['field_management'], "invalid id"); + } + $sql = "delete from torrents_custom_fields where id = $id"; + $res = sql_query($sql); + redirect('fields.php?action=view&type='); } diff --git a/public/upload.php b/public/upload.php index 72386476..6a4f6188 100644 --- a/public/upload.php +++ b/public/upload.php @@ -66,6 +66,9 @@ stdhead($lang_upload['head_upload']); } if ($enablenfo_main=='yes') tr($lang_upload['row_nfo_file'], "
".$lang_upload['text_only_viewed_by'].get_user_class_name($viewnfo_class,false,true,true).$lang_upload['text_or_above']."", 1); + + $field = new \Nexus\Field\Field(); + print("".$lang_upload['row_description']."*"); textbbcode("upload","descr","",false); print("\n");