mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 12:37:23 +08:00
finish custom fields in edit
This commit is contained in:
+23
-6
@@ -217,13 +217,16 @@ HEAD;
|
|||||||
} elseif ($row['type'] == self::TYPE_TEXTAREA) {
|
} elseif ($row['type'] == self::TYPE_TEXTAREA) {
|
||||||
$html .= tr($row['label'], sprintf('<textarea name="%s" rows="4" style="width: 650px">%s</textarea>', $name, $currentValue), 1);
|
$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) {
|
} elseif ($row['type'] == self::TYPE_RADIO || $row['type'] == self::TYPE_CHECKBOX) {
|
||||||
|
if ($row['type'] == self::TYPE_CHECKBOX) {
|
||||||
|
$name .= '[]';
|
||||||
|
}
|
||||||
$part = "";
|
$part = "";
|
||||||
foreach (preg_split('/[\r\n]+/', trim($row['options'])) as $option) {
|
foreach (preg_split('/[\r\n]+/', trim($row['options'])) as $option) {
|
||||||
if (empty($option) || ($pos = strpos($option, '|')) === false) {
|
if (empty($option) || ($pos = strpos($option, '|')) === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$key = substr($option, 0, $pos);
|
$value = substr($option, 0, $pos);
|
||||||
$value = substr($option, $pos + 1);
|
$label = substr($option, $pos + 1);
|
||||||
$checked = "";
|
$checked = "";
|
||||||
if ($row['type'] == self::TYPE_RADIO && (string)$currentValue === (string)$value) {
|
if ($row['type'] == self::TYPE_RADIO && (string)$currentValue === (string)$value) {
|
||||||
$checked = " checked";
|
$checked = " checked";
|
||||||
@@ -233,7 +236,7 @@ HEAD;
|
|||||||
}
|
}
|
||||||
$part .= sprintf(
|
$part .= sprintf(
|
||||||
'<label style="margin-right: 4px"><input type="%s" name="%s" value="%s"%s />%s</label>',
|
'<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);
|
$html .= tr($row['label'], $part, 1);
|
||||||
@@ -243,15 +246,15 @@ HEAD;
|
|||||||
if (empty($option) || ($pos = strpos($option, '|')) === false) {
|
if (empty($option) || ($pos = strpos($option, '|')) === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$key = substr($option, 0, $pos);
|
$value = substr($option, 0, $pos);
|
||||||
$value = substr($option, $pos + 1);
|
$label = substr($option, $pos + 1);
|
||||||
$selected = "";
|
$selected = "";
|
||||||
if (in_array($value, (array)$currentValue)) {
|
if (in_array($value, (array)$currentValue)) {
|
||||||
$selected = " selected";
|
$selected = " selected";
|
||||||
}
|
}
|
||||||
$part .= sprintf(
|
$part .= sprintf(
|
||||||
'<option value="%s"%s>%s</option>',
|
'<option value="%s"%s>%s</option>',
|
||||||
$key, $selected, $value
|
$value, $selected, $label
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$part .= '</select>';
|
$part .= '</select>';
|
||||||
@@ -302,4 +305,18 @@ JS;
|
|||||||
return $html;
|
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
@@ -16,11 +16,9 @@ if (!$row) die();
|
|||||||
* custom fields
|
* custom fields
|
||||||
* @since v1.6
|
* @since v1.6
|
||||||
*/
|
*/
|
||||||
$customFieldValueRes = sql_query("select * from torrents_custom_field_values where torrent_id = $id");
|
$customField = new \Nexus\Field\Field();
|
||||||
$customFieldValues = [];
|
$customFieldValues = $customField->listTorrentCustomField($id);
|
||||||
while ($row = mysql_fetch_assoc($res)) {
|
//dd($customFieldValues);
|
||||||
$customFieldValues[$row['custom_field_id']] = unserialize($row['custom_field_value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class)
|
if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class)
|
||||||
$allowmove = true; //enable moving torrent to other section
|
$allowmove = true; //enable moving torrent to other section
|
||||||
@@ -69,6 +67,8 @@ else {
|
|||||||
echo $ptGen->renderUploadPageFormInput($row['pt_gen']);
|
echo $ptGen->renderUploadPageFormInput($row['pt_gen']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$customField->renderUploadPage($customFieldValues);
|
||||||
|
|
||||||
if ($enablenfo_main=='yes')
|
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'].
|
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'].
|
"<input type=\"radio\" name=\"nfoaction\" value=\"remove\" />".$lang_edit['radio_remove'].
|
||||||
|
|||||||
@@ -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__);
|
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"])
|
if($CURUSER["id"] == $row["owner"])
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-8
@@ -359,14 +359,16 @@ $id = mysql_insert_id();
|
|||||||
if (!empty($_POST['custom_fields'])) {
|
if (!empty($_POST['custom_fields'])) {
|
||||||
$now = date('Y-m-d H:i:s');
|
$now = date('Y-m-d H:i:s');
|
||||||
foreach ($_POST['custom_fields'] as $customField => $customValue) {
|
foreach ($_POST['custom_fields'] as $customField => $customValue) {
|
||||||
$customData = [
|
foreach ((array)$customValue as $value) {
|
||||||
'torrent_id' => $id,
|
$customData = [
|
||||||
'custom_field_id' => $customField,
|
'torrent_id' => $id,
|
||||||
'custom_field_value' => serialize($customValue),
|
'custom_field_id' => $customField,
|
||||||
'created_at' => $now,
|
'custom_field_value' => $value,
|
||||||
'updated_at' => $now,
|
'created_at' => $now,
|
||||||
];
|
'updated_at' => $now,
|
||||||
\Nexus\Database\DB::insert('torrents_custom_field_values', $customData);
|
];
|
||||||
|
\Nexus\Database\DB::insert('torrents_custom_field_values', $customData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user