finish field management

This commit is contained in:
xiaomlove
2021-03-03 01:56:07 +08:00
parent 528d559f24
commit 7b8a6a7ce2
5 changed files with 60 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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 .= '</tbody></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(
'<label style="margin-right: 4px;"><input type="checkbox" name="%s" value="%s"%s>%s</label>',
$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']);
}
}

View File

@@ -233,6 +233,8 @@ function print_category_editor($type, $row='')
}
tr($lang_catmanage['row_searchbox_name']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"name\" value=\"".htmlspecialchars($name)."\" style=\"width: 300px\" /> " . $lang_catmanage['text_searchbox_name_note'], 1);
tr($lang_catmanage['row_show_sub_category'], "<input type=\"checkbox\" name=\"showsource\" value=\"1\"".($showsource ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_sources'] . "<input type=\"checkbox\" name=\"showmedium\" value=\"1\"".($showmedium ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_media'] . "<input type=\"checkbox\" name=\"showcodec\" value=\"1\"".($showcodec ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_codecs'] . "<input type=\"checkbox\" name=\"showstandard\" value=\"1\"".($showstandard ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_standards'] . "<input type=\"checkbox\" name=\"showprocessing\" value=\"1\"".($showprocessing ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_processings'] . "<input type=\"checkbox\" name=\"showteam\" value=\"1\"".($showteam ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_teams'] . "<input type=\"checkbox\" name=\"showaudiocodec\" value=\"1\"".($showaudiocodec ? " checked=\"checked\"" : "")." /> " . $lang_catmanage['text_audio_codecs']."<br />".$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']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"catsperrow\" value=\"".$catsperrow."\" style=\"width: 100px\" /> " . $lang_catmanage['text_items_per_row_note'], 1);
tr($lang_catmanage['row_padding_between_items']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"catpadding\" value=\"".$catpadding."\" style=\"width: 100px\" /> " . $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

View File

@@ -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=');
}

View File

@@ -66,6 +66,9 @@ stdhead($lang_upload['head_upload']);
}
if ($enablenfo_main=='yes')
tr($lang_upload['row_nfo_file'], "<input type=\"file\" class=\"file\" name=\"nfo\" /><br /><font class=\"medium\">".$lang_upload['text_only_viewed_by'].get_user_class_name($viewnfo_class,false,true,true).$lang_upload['text_or_above']."</font>", 1);
$field = new \Nexus\Field\Field();
print("<tr><td class=\"rowhead\" style='padding: 3px' valign=\"top\">".$lang_upload['row_description']."<font color=\"red\">*</font></td><td class=\"rowfollow\">");
textbbcode("upload","descr","",false);
print("</td></tr>\n");