finish custom fields in edit

This commit is contained in:
xiaomlove
2021-03-04 02:27:39 +08:00
parent 723a6fadc9
commit 7c857deaf4
4 changed files with 58 additions and 19 deletions
+23 -6
View File
@@ -217,13 +217,16 @@ HEAD;
} elseif ($row['type'] == self::TYPE_TEXTAREA) {
$html .= tr($row['label'], sprintf('<textarea name="%s" rows="4" style="width: 650px">%s</textarea>', $name, $currentValue), 1);
} elseif ($row['type'] == self::TYPE_RADIO || $row['type'] == self::TYPE_CHECKBOX) {
if ($row['type'] == self::TYPE_CHECKBOX) {
$name .= '[]';
}
$part = "";
foreach (preg_split('/[\r\n]+/', trim($row['options'])) as $option) {
if (empty($option) || ($pos = strpos($option, '|')) === false) {
continue;
}
$key = substr($option, 0, $pos);
$value = substr($option, $pos + 1);
$value = substr($option, 0, $pos);
$label = substr($option, $pos + 1);
$checked = "";
if ($row['type'] == self::TYPE_RADIO && (string)$currentValue === (string)$value) {
$checked = " checked";
@@ -233,7 +236,7 @@ HEAD;
}
$part .= sprintf(
'<label style="margin-right: 4px"><input type="%s" name="%s" value="%s"%s />%s</label>',
$row['type'], $name, $key, $checked, $value
$row['type'], $name, $value, $checked, $label
);
}
$html .= tr($row['label'], $part, 1);
@@ -243,15 +246,15 @@ HEAD;
if (empty($option) || ($pos = strpos($option, '|')) === false) {
continue;
}
$key = substr($option, 0, $pos);
$value = substr($option, $pos + 1);
$value = substr($option, 0, $pos);
$label = substr($option, $pos + 1);
$selected = "";
if (in_array($value, (array)$currentValue)) {
$selected = " selected";
}
$part .= sprintf(
'<option value="%s"%s>%s</option>',
$key, $selected, $value
$value, $selected, $label
);
}
$part .= '</select>';
@@ -302,4 +305,18 @@ JS;
return $html;
}
public function listTorrentCustomField($torrentId)
{
$res = sql_query("select v.*, f.type as custom_field_type from torrents_custom_field_values v inner join torrents_custom_fields f on v.custom_field_id = f.id where torrent_id = $torrentId");
$result = [];
while ($row = mysql_fetch_assoc($res)) {
if ($row['custom_field_type'] == self::TYPE_CHECKBOX) {
$result[$row['custom_field_id']][] = $row['custom_field_value'];
} else {
$result[$row['custom_field_id']] = $row['custom_field_value'];
}
}
return $result;
}
}
+5 -5
View File
@@ -16,11 +16,9 @@ if (!$row) die();
* custom fields
* @since v1.6
*/
$customFieldValueRes = sql_query("select * from torrents_custom_field_values where torrent_id = $id");
$customFieldValues = [];
while ($row = mysql_fetch_assoc($res)) {
$customFieldValues[$row['custom_field_id']] = unserialize($row['custom_field_value']);
}
$customField = new \Nexus\Field\Field();
$customFieldValues = $customField->listTorrentCustomField($id);
//dd($customFieldValues);
if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class)
$allowmove = true; //enable moving torrent to other section
@@ -69,6 +67,8 @@ else {
echo $ptGen->renderUploadPageFormInput($row['pt_gen']);
}
$customField->renderUploadPage($customFieldValues);
if ($enablenfo_main=='yes')
tr($lang_edit['row_nfo_file'], "<font class=\"medium\"><input type=\"radio\" name=\"nfoaction\" value=\"keep\" checked=\"checked\" />".$lang_edit['radio_keep_current'].
"<input type=\"radio\" name=\"nfoaction\" value=\"remove\" />".$lang_edit['radio_remove'].
+20
View File
@@ -189,6 +189,26 @@ if(get_user_class()>=$torrentmanage_class && $CURUSER['picker'] == 'yes')
sql_query("UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
/**
* add custom fields
* @since v1.6
*/
if (!empty($_POST['custom_fields'])) {
\Nexus\Database\DB::delete('torrents_custom_field_values', "torrent_id = $id");
$now = date('Y-m-d H:i:s');
foreach ($_POST['custom_fields'] as $customField => $customValue) {
foreach ((array)$customValue as $value) {
$customData = [
'torrent_id' => $id,
'custom_field_id' => $customField,
'custom_field_value' => $value,
'created_at' => $now,
'updated_at' => $now,
];
\Nexus\Database\DB::insert('torrents_custom_field_values', $customData);
}
}
}
if($CURUSER["id"] == $row["owner"])
{
+10 -8
View File
@@ -359,14 +359,16 @@ $id = mysql_insert_id();
if (!empty($_POST['custom_fields'])) {
$now = date('Y-m-d H:i:s');
foreach ($_POST['custom_fields'] as $customField => $customValue) {
$customData = [
'torrent_id' => $id,
'custom_field_id' => $customField,
'custom_field_value' => serialize($customValue),
'created_at' => $now,
'updated_at' => $now,
];
\Nexus\Database\DB::insert('torrents_custom_field_values', $customData);
foreach ((array)$customValue as $value) {
$customData = [
'torrent_id' => $id,
'custom_field_id' => $customField,
'custom_field_value' => $value,
'created_at' => $now,
'updated_at' => $now,
];
\Nexus\Database\DB::insert('torrents_custom_field_values', $customData);
}
}
}