diff --git a/nexus/Field/Field.php b/nexus/Field/Field.php index 26ea53d2..8258fb8e 100644 --- a/nexus/Field/Field.php +++ b/nexus/Field/Field.php @@ -217,13 +217,16 @@ HEAD; } elseif ($row['type'] == self::TYPE_TEXTAREA) { $html .= tr($row['label'], sprintf('', $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( '', - $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( '', - $key, $selected, $value + $value, $selected, $label ); } $part .= ''; @@ -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; + } + } \ No newline at end of file diff --git a/public/edit.php b/public/edit.php index 4189c9fb..c362dd25 100644 --- a/public/edit.php +++ b/public/edit.php @@ -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'], "".$lang_edit['radio_keep_current']. "".$lang_edit['radio_remove']. diff --git a/public/takeedit.php b/public/takeedit.php index 3af9101f..7b74dfa6 100644 --- a/public/takeedit.php +++ b/public/takeedit.php @@ -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"]) { diff --git a/public/takeupload.php b/public/takeupload.php index f0f4843f..78cfef6d 100644 --- a/public/takeupload.php +++ b/public/takeupload.php @@ -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); + } } }