Browse Source

Start to pretend that requests work

pjc 5 years ago
parent
commit
8f43300529
4 changed files with 496 additions and 487 deletions
  1. 157
    152
      classes/requests.class.php
  2. 97
    96
      sections/requests/new_edit.php
  3. 167
    168
      sections/requests/take_new_edit.php
  4. 75
    71
      static/functions/requests.js

+ 157
- 152
classes/requests.class.php View File

@@ -1,22 +1,24 @@
1
-<?
2
-class Requests {
3
-  /**
4
-   * Update the sphinx requests delta table for a request.
5
-   *
6
-   * @param $RequestID
7
-   */
8
-  public static function update_sphinx_requests($RequestID) {
9
-    $QueryID = G::$DB->get_query_id();
10
-
11
-    G::$DB->query("
1
+<?php
2
+class Requests
3
+{
4
+    /**
5
+     * Update the sphinx requests delta table for a request.
6
+     *
7
+     * @param $RequestID
8
+     */
9
+    public static function update_sphinx_requests($RequestID)
10
+    {
11
+        $QueryID = G::$DB->get_query_id();
12
+
13
+        G::$DB->query("
12 14
       SELECT REPLACE(t.Name, '.', '_')
13 15
       FROM tags AS t
14 16
         JOIN requests_tags AS rt ON t.ID = rt.TagID
15 17
       WHERE rt.RequestID = $RequestID");
16
-    $TagList = G::$DB->collect(0, false);
17
-    $TagList = db_string(implode(' ', $TagList));
18
+        $TagList = G::$DB->collect(0, false);
19
+        $TagList = db_string(implode(' ', $TagList));
18 20
 
19
-    G::$DB->query("
21
+        G::$DB->query("
20 22
       REPLACE INTO sphinx_requests_delta (
21 23
         ID, UserID, TimeAdded, LastVote, CategoryID, Title, TagList,
22 24
         CatalogueNumber, DLSiteID, FillerID, TorrentID,
@@ -31,7 +33,7 @@ class Requests {
31 33
         LEFT JOIN requests_votes AS rv ON rv.RequestID = r.ID
32 34
       WHERE ID = $RequestID
33 35
       GROUP BY r.ID");
34
-    G::$DB->query("
36
+        G::$DB->query("
35 37
       UPDATE sphinx_requests_delta
36 38
       SET ArtistList = (
37 39
           SELECT GROUP_CONCAT(ag.Name SEPARATOR ' ')
@@ -41,52 +43,50 @@ class Requests {
41 43
           GROUP BY NULL
42 44
           )
43 45
       WHERE ID = $RequestID");
44
-    G::$DB->set_query_id($QueryID);
45
-
46
-    G::$Cache->delete_value("request_$RequestID");
47
-  }
48
-
49
-
50
-
51
-  /**
52
-   * Function to get data from an array of $RequestIDs. Order of keys doesn't matter (let's keep it that way).
53
-   *
54
-   * @param array $RequestIDs
55
-   * @param boolean $Return if set to false, data won't be returned (ie. if we just want to prime the cache.)
56
-   * @return The array of requests.
57
-   * Format: array(RequestID => Associative array)
58
-   * To see what's exactly inside each associate array, peek inside the function. It won't bite.
59
-   */
60
-  //
61
-  //In places where the output from this is merged with sphinx filters, it will be in a different order.
62
-  public static function get_requests($RequestIDs, $Return = true) {
63
-    $Found = $NotFound = array_fill_keys($RequestIDs, false);
64
-    // Try to fetch the requests from the cache first.
65
-    foreach ($RequestIDs as $i => $RequestID) {
66
-      if (!is_number($RequestID)) {
67
-        unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]);
68
-        continue;
69
-      }
70
-      $Data = G::$Cache->get_value("request_$RequestID");
71
-      if (!empty($Data)) {
72
-        unset($NotFound[$RequestID]);
73
-        $Found[$RequestID] = $Data;
74
-      }
75
-    }
76
-    // Make sure there's something in $RequestIDs, otherwise the SQL will break
77
-    if (count($RequestIDs) === 0) {
78
-      return [];
46
+        G::$DB->set_query_id($QueryID);
47
+
48
+        G::$Cache->delete_value("request_$RequestID");
79 49
     }
80
-    $IDs = implode(',', array_keys($NotFound));
81 50
 
82
-    /*
83
-      Don't change without ensuring you change everything else that uses get_requests()
84
-    */
51
+    /**
52
+     * Function to get data from an array of $RequestIDs. Order of keys doesn't matter (let's keep it that way).
53
+     *
54
+     * @param array $RequestIDs
55
+     * @param boolean $Return if set to false, data won't be returned (ie. if we just want to prime the cache.)
56
+     * @return The array of requests.
57
+     * Format: array(RequestID => Associative array)
58
+     * To see what's exactly inside each associate array, peek inside the function. It won't bite.
59
+     */
60
+    // In places where the output from this is merged with sphinx filters, it will be in a different order.
61
+    public static function get_requests($RequestIDs, $Return = true)
62
+    {
63
+        $Found = $NotFound = array_fill_keys($RequestIDs, false);
64
+        // Try to fetch the requests from the cache first.
65
+        foreach ($RequestIDs as $i => $RequestID) {
66
+            if (!is_number($RequestID)) {
67
+                unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]);
68
+                continue;
69
+            }
70
+            $Data = G::$Cache->get_value("request_$RequestID");
71
+            if (!empty($Data)) {
72
+                unset($NotFound[$RequestID]);
73
+                $Found[$RequestID] = $Data;
74
+            }
75
+        }
76
+        // Make sure there's something in $RequestIDs, otherwise the SQL will break
77
+        if (count($RequestIDs) === 0) {
78
+            return [];
79
+        }
80
+        $IDs = implode(',', array_keys($NotFound));
81
+
82
+        /*
83
+          Don't change without ensuring you change everything else that uses get_requests()
84
+        */
85 85
 
86
-    if (count($NotFound) > 0) {
87
-      $QueryID = G::$DB->get_query_id();
86
+        if (count($NotFound) > 0) {
87
+            $QueryID = G::$DB->get_query_id();
88 88
 
89
-      G::$DB->query("
89
+            G::$DB->query("
90 90
         SELECT
91 91
           ID,
92 92
           UserID,
@@ -107,60 +107,64 @@ class Requests {
107 107
         FROM requests
108 108
         WHERE ID IN ($IDs)
109 109
         ORDER BY ID");
110
-      $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true);
111
-      $Tags = self::get_tags(G::$DB->collect('ID', false));
112
-      foreach ($Requests as $Request) {
113
-        $Request['AnonymousFill'] = false;
114
-        if ($Request['FillerID']) {
115
-          G::$DB->query("
110
+            $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true);
111
+            $Tags = self::get_tags(G::$DB->collect('ID', false));
112
+            foreach ($Requests as $Request) {
113
+                $Request['AnonymousFill'] = false;
114
+                if ($Request['FillerID']) {
115
+                    G::$DB->query("
116 116
             SELECT Anonymous
117 117
             FROM torrents
118 118
             WHERE ID = ".$Request['TorrentID']);
119
-          list($Anonymous) = G::$DB->next_record();
120
-          if ($Anonymous) $Request['AnonymousFill'] = true;
119
+                    list($Anonymous) = G::$DB->next_record();
120
+                    if ($Anonymous) {
121
+                        $Request['AnonymousFill'] = true;
122
+                    }
123
+                }
124
+                unset($NotFound[$Request['ID']]);
125
+                $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : [];
126
+                $Found[$Request['ID']] = $Request;
127
+                G::$Cache->cache_value('request_'.$Request['ID'], $Request, 0);
128
+            }
129
+            G::$DB->set_query_id($QueryID);
130
+
131
+            // Orphan requests. There shouldn't ever be any
132
+            if (count($NotFound) > 0) {
133
+                foreach (array_keys($NotFound) as $GroupID) {
134
+                    unset($Found[$GroupID]);
135
+                }
136
+            }
121 137
         }
122
-        unset($NotFound[$Request['ID']]);
123
-        $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : [];
124
-        $Found[$Request['ID']] = $Request;
125
-        G::$Cache->cache_value('request_'.$Request['ID'], $Request, 0);
126
-      }
127
-      G::$DB->set_query_id($QueryID);
128
-
129
-      // Orphan requests. There shouldn't ever be any
130
-      if (count($NotFound) > 0) {
131
-        foreach (array_keys($NotFound) as $GroupID) {
132
-          unset($Found[$GroupID]);
138
+
139
+        if ($Return) { // If we're interested in the data, and not just caching it
140
+            return $Found;
133 141
         }
134
-      }
135 142
     }
136 143
 
137
-    if ($Return) { // If we're interested in the data, and not just caching it
138
-      return $Found;
139
-    }
140
-  }
141
-
142
-  /**
143
-   * Return a single request. Wrapper for get_requests
144
-   *
145
-   * @param int $RequestID
146
-   * @return request array or false if request doesn't exist. See get_requests for a description of the format
147
-   */
148
-  public static function get_request($RequestID) {
149
-    $Request = self::get_requests(array($RequestID));
150
-    if (isset($Request[$RequestID])) {
151
-      return $Request[$RequestID];
144
+    /**
145
+     * Return a single request. Wrapper for get_requests
146
+     *
147
+     * @param int $RequestID
148
+     * @return request array or false if request doesn't exist. See get_requests for a description of the format
149
+     */
150
+    public static function get_request($RequestID)
151
+    {
152
+        $Request = self::get_requests(array($RequestID));
153
+        if (isset($Request[$RequestID])) {
154
+            return $Request[$RequestID];
155
+        }
156
+        return false;
152 157
     }
153
-    return false;
154
-  }
155
-
156
-  public static function get_artists($RequestID) {
157
-    $Artists = G::$Cache->get_value("request_artists_$RequestID");
158
-    if (is_array($Artists)) {
159
-      $Results = $Artists;
160
-    } else {
161
-      $Results = [];
162
-      $QueryID = G::$DB->get_query_id();
163
-      G::$DB->query("
158
+
159
+    public static function get_artists($RequestID)
160
+    {
161
+        $Artists = G::$Cache->get_value("request_artists_$RequestID");
162
+        if (is_array($Artists)) {
163
+            $Results = $Artists;
164
+        } else {
165
+            $Results = [];
166
+            $QueryID = G::$DB->get_query_id();
167
+            G::$DB->query("
164 168
         SELECT
165 169
           ra.ArtistID,
166 170
           ag.Name
@@ -168,26 +172,27 @@ class Requests {
168 172
           JOIN artists_group AS ag ON ra.ArtistID = ag.ArtistID
169 173
         WHERE ra.RequestID = $RequestID
170 174
         ORDER BY ag.Name ASC;");
171
-      $ArtistRaw = G::$DB->to_array();
172
-      G::$DB->set_query_id($QueryID);
173
-      foreach ($ArtistRaw as $ArtistRow) {
174
-        list($ArtistID, $ArtistName) = $ArtistRow;
175
-        $Results[] = array('id' => $ArtistID, 'name' => $ArtistName);
176
-      }
177
-      G::$Cache->cache_value("request_artists_$RequestID", $Results);
175
+            $ArtistRaw = G::$DB->to_array();
176
+            G::$DB->set_query_id($QueryID);
177
+            foreach ($ArtistRaw as $ArtistRow) {
178
+                list($ArtistID, $ArtistName) = $ArtistRow;
179
+                $Results[] = array('id' => $ArtistID, 'name' => $ArtistName);
180
+            }
181
+            G::$Cache->cache_value("request_artists_$RequestID", $Results);
182
+        }
183
+        return $Results;
178 184
     }
179
-    return $Results;
180
-  }
181 185
 
182
-  public static function get_tags($RequestIDs) {
183
-    if (empty($RequestIDs)) {
184
-      return [];
185
-    }
186
-    if (is_array($RequestIDs)) {
187
-      $RequestIDs = implode(',', $RequestIDs);
188
-    }
189
-    $QueryID = G::$DB->get_query_id();
190
-    G::$DB->query("
186
+    public static function get_tags($RequestIDs)
187
+    {
188
+        if (empty($RequestIDs)) {
189
+            return [];
190
+        }
191
+        if (is_array($RequestIDs)) {
192
+            $RequestIDs = implode(',', $RequestIDs);
193
+        }
194
+        $QueryID = G::$DB->get_query_id();
195
+        G::$DB->query("
191 196
       SELECT
192 197
         rt.RequestID,
193 198
         rt.TagID,
@@ -196,21 +201,22 @@ class Requests {
196 201
         JOIN tags AS t ON rt.TagID = t.ID
197 202
       WHERE rt.RequestID IN ($RequestIDs)
198 203
       ORDER BY rt.TagID ASC");
199
-    $Tags = G::$DB->to_array(false, MYSQLI_NUM, false);
200
-    G::$DB->set_query_id($QueryID);
201
-    $Results = [];
202
-    foreach ($Tags as $TagsRow) {
203
-      list($RequestID, $TagID, $TagName) = $TagsRow;
204
-      $Results[$RequestID][$TagID] = $TagName;
204
+        $Tags = G::$DB->to_array(false, MYSQLI_NUM, false);
205
+        G::$DB->set_query_id($QueryID);
206
+        $Results = [];
207
+        foreach ($Tags as $TagsRow) {
208
+            list($RequestID, $TagID, $TagName) = $TagsRow;
209
+            $Results[$RequestID][$TagID] = $TagName;
210
+        }
211
+        return $Results;
205 212
     }
206
-    return $Results;
207
-  }
208
-
209
-  public static function get_votes_array($RequestID) {
210
-    $RequestVotes = G::$Cache->get_value("request_votes_$RequestID");
211
-    if (!is_array($RequestVotes)) {
212
-      $QueryID = G::$DB->get_query_id();
213
-      G::$DB->query("
213
+
214
+    public static function get_votes_array($RequestID)
215
+    {
216
+        $RequestVotes = G::$Cache->get_value("request_votes_$RequestID");
217
+        if (!is_array($RequestVotes)) {
218
+            $QueryID = G::$DB->get_query_id();
219
+            G::$DB->query("
214 220
         SELECT
215 221
           rv.UserID,
216 222
           rv.Bounty,
@@ -219,27 +225,26 @@ class Requests {
219 225
           LEFT JOIN users_main AS u ON u.ID = rv.UserID
220 226
         WHERE rv.RequestID = $RequestID
221 227
         ORDER BY rv.Bounty DESC");
222
-      if (!G::$DB->has_results()) {
223
-        return array(
228
+            if (!G::$DB->has_results()) {
229
+                return array(
224 230
           'TotalBounty' => 0,
225 231
           'Voters' => []);
226
-      }
227
-      $Votes = G::$DB->to_array();
232
+            }
233
+            $Votes = G::$DB->to_array();
228 234
 
229
-      $RequestVotes = [];
230
-      $RequestVotes['TotalBounty'] = array_sum(G::$DB->collect('Bounty'));
235
+            $RequestVotes = [];
236
+            $RequestVotes['TotalBounty'] = array_sum(G::$DB->collect('Bounty'));
231 237
 
232
-      foreach ($Votes as $Vote) {
233
-        list($UserID, $Bounty, $Username) = $Vote;
234
-        $VoteArray = [];
235
-        $VotesArray[] = array('UserID' => $UserID, 'Username' => $Username, 'Bounty' => $Bounty);
236
-      }
238
+            foreach ($Votes as $Vote) {
239
+                list($UserID, $Bounty, $Username) = $Vote;
240
+                $VoteArray = [];
241
+                $VotesArray[] = array('UserID' => $UserID, 'Username' => $Username, 'Bounty' => $Bounty);
242
+            }
237 243
 
238
-      $RequestVotes['Voters'] = $VotesArray;
239
-      G::$Cache->cache_value("request_votes_$RequestID", $RequestVotes);
240
-      G::$DB->set_query_id($QueryID);
244
+            $RequestVotes['Voters'] = $VotesArray;
245
+            G::$Cache->cache_value("request_votes_$RequestID", $RequestVotes);
246
+            G::$DB->set_query_id($QueryID);
247
+        }
248
+        return $RequestVotes;
241 249
     }
242
-    return $RequestVotes;
243
-  }
244
-
245 250
 }

+ 97
- 96
sections/requests/new_edit.php View File

@@ -6,72 +6,70 @@
6 6
  * maintaining 2 copies of almost identical files.
7 7
  */
8 8
 
9
-
10 9
 $NewRequest = $_GET['action'] === 'new';
11 10
 
12 11
 if (!$NewRequest) {
13
-  $RequestID = $_GET['id'];
14
-  if (!is_number($RequestID)) {
15
-    error(404);
16
-  }
12
+    $RequestID = $_GET['id'];
13
+    if (!is_number($RequestID)) {
14
+        error(404);
15
+    }
17 16
 }
18 17
 
19 18
 $Disabled = "";
20 19
 
21 20
 if ($NewRequest && ($LoggedUser['BytesUploaded'] < 250 * 1024 * 1024 || !check_perms('site_submit_requests'))) {
22
-  error('You do not have enough uploaded to make a request.');
21
+    error('You do not have enough uploaded to make a request.');
23 22
 }
24 23
 
25 24
 if (!$NewRequest) {
26
-  if (empty($ReturnEdit)) {
27
-
28
-    $Request = Requests::get_request($RequestID);
29
-    if ($Request === false) {
30
-      error(404);
31
-    }
25
+    if (empty($ReturnEdit)) {
26
+        $Request = Requests::get_request($RequestID);
27
+        if ($Request === false) {
28
+            error(404);
29
+        }
32 30
 
33
-    // Define these variables to simplify _GET['groupid'] requests later on
34
-    $CategoryID = $Request['CategoryID'];
35
-    $Title = $Request['Title'];
36
-    $TitleRJ = $Request['TitleRJ'];
37
-    $TitleJP = $Request['TitleJP'];
38
-    $CatalogueNumber = $Request['CatalogueNumber'];
39
-    $DLsiteID = $Request['DLsiteID'];
40
-    $Image = $Request['Image'];
41
-    $GroupID = $Request['GroupID'];
31
+        // Define these variables to simplify _GET['groupid'] requests later on
32
+        $CategoryID = $Request['CategoryID'];
33
+        $Title = $Request['Title'];
34
+        $TitleRJ = $Request['TitleRJ'];
35
+        $TitleJP = $Request['TitleJP'];
36
+        $CatalogueNumber = $Request['CatalogueNumber'];
37
+        $DLsiteID = $Request['DLsiteID'];
38
+        $Image = $Request['Image'];
39
+        $GroupID = $Request['GroupID'];
42 40
 
43
-    $VoteArray = Requests::get_votes_array($RequestID);
44
-    $VoteCount = count($VoteArray['Voters']);
41
+        $VoteArray = Requests::get_votes_array($RequestID);
42
+        $VoteCount = count($VoteArray['Voters']);
45 43
 
46
-    $IsFilled = !empty($Request['TorrentID']);
47
-    $CategoryName = $Categories[$CategoryID - 1];
44
+        $IsFilled = !empty($Request['TorrentID']);
45
+        $CategoryName = $Categories[$CategoryID - 1];
48 46
 
49
-    $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && $CategoryID === '0');
50
-    $CanEdit = ((!$IsFilled && $LoggedUser['ID'] === $Request['UserID'] && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
47
+        $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && $CategoryID === '0');
48
+        $CanEdit = ((!$IsFilled && $LoggedUser['ID'] === $Request['UserID'] && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
51 49
 
52
-    if (!$CanEdit) {
53
-      error(403);
54
-    }
50
+        if (!$CanEdit) {
51
+            error(403);
52
+        }
55 53
 
56
-    $ArtistForm = Requests::get_artists($RequestID);
54
+        $ArtistForm = Requests::get_artists($RequestID);
57 55
 
58
-    $Tags = implode(', ', $Request['Tags']);
59
-  }
56
+        $Tags = implode(', ', $Request['Tags']);
57
+    }
60 58
 }
61 59
 
62 60
 if ($NewRequest && !empty($_GET['artistid']) && is_number($_GET['artistid'])) {
63
-  $DB->query("
61
+    $DB->query("
64 62
     SELECT Name
65 63
     FROM artists_group
66 64
     WHERE artistid = ".$_GET['artistid']."
67 65
     LIMIT 1");
68
-  list($ArtistName) = $DB->next_record();
69
-  $ArtistForm = array(
66
+    list($ArtistName) = $DB->next_record();
67
+    $ArtistForm = array(
70 68
     1 => array(array('name' => trim($ArtistName))),
71 69
   );
72 70
 } elseif ($NewRequest && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
73
-  $ArtistForm = Artists::get_artist($_GET['groupid']);
74
-  $DB->query("
71
+    $ArtistForm = Artists::get_artist($_GET['groupid']);
72
+    $DB->query("
75 73
     SELECT
76 74
       tg.Name,
77 75
       tg.NameRJ,
@@ -88,11 +86,11 @@ if ($NewRequest && !empty($_GET['artistid']) && is_number($_GET['artistid'])) {
88 86
       JOIN torrents_tags AS tt ON tt.GroupID = tg.ID
89 87
       JOIN tags AS t ON t.ID = tt.TagID
90 88
     WHERE tg.ID = ".$_GET['groupid']);
91
-  if (list($Title, $TitleRJ, $TitleJP, $Year, $Studio, $Series, $CatalogueNumber, $DLsiteID, $Image, $Tags, $CategoryID) = $DB->next_record()) {
92
-    $GroupID = trim($_REQUEST['groupid']);
93
-    $CategoryName = $Categories[$CategoryID - 1];
94
-    $Disabled = 'readonly="readonly"';
95
-  }
89
+    if (list($Title, $TitleRJ, $TitleJP, $Year, $Studio, $Series, $CatalogueNumber, $DLsiteID, $Image, $Tags, $CategoryID) = $DB->next_record()) {
90
+        $GroupID = trim($_REQUEST['groupid']);
91
+        $CategoryName = $Categories[$CategoryID - 1];
92
+        $Disabled = 'readonly="readonly"';
93
+    }
96 94
 }
97 95
 
98 96
 View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode,requests,form_validate');
@@ -105,9 +103,9 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode
105 103
   <div class="box pad">
106 104
     <form action="" method="post" id="request_form" onsubmit="Calculate();">
107 105
       <div>
108
-<?  if (!$NewRequest) { ?>
106
+<?php  if (!$NewRequest) { ?>
109 107
         <input type="hidden" name="requestid" value="<?=$RequestID?>" />
110
-<?  } ?>
108
+<?php  } ?>
111 109
         <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
112 110
         <input type="hidden" name="action" value="<?=($NewRequest ? 'takenew' : 'takeedit')?>" />
113 111
       </div>
@@ -116,51 +114,54 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode
116 114
         <tr>
117 115
           <td colspan="2" class="center">Please make sure your request follows <a href="rules.php?p=requests">the request rules</a>!</td>
118 116
         </tr>
119
-<?  if ($NewRequest || $CanEdit) { ?>
117
+<?php  if ($NewRequest || $CanEdit) { ?>
120 118
         <tr>
121 119
           <td class="label tooltip" title="What alphabet the sequence uses, n.b., plasmids fit in the Other category">Type</td>
122 120
           <td>
123
-<? if (!empty($Disabled)) { ?>
121
+<?php if (!empty($Disabled)) { ?>
124 122
             <input type="hidden" name="type" value="<?=$CategoryName?>" />
125 123
             <select id="categories" name="type" onchange="Categories();" disabled="disabled">
126
-<? } else { ?>
124
+<?php } else { ?>
127 125
             <select id="categories" name="type" onchange="Categories();">
128
-<? } ?>
129
-<?    foreach (Misc::display_array($Categories) as $Cat) { ?>
126
+<?php } ?>
127
+<?php    foreach (Misc::display_array($Categories) as $Cat) { ?>
130 128
               <option value="<?=$Cat?>"<?=(!empty($CategoryName) && ($CategoryName === $Cat) ? ' selected="selected"' : '')?>><?=$Cat?></option>
131
-<?    } ?>
129
+<?php    } ?>
132 130
             </select>
133 131
           </td>
134 132
         </tr>
135 133
         <tr id="cataloguenumber_tr">
136
-          <td class="label">Catalogue Number</td>
134
+          <td class="label">Accession Number</td>
137 135
           <td>
138 136
             <input type="text" id="catalogue" name="cataloguenumber" size="15" value="<?=(isset($CatalogueNumber)?$CatalogueNumber:'') ?>" <?=$Disabled?>/>
139
-<? if (empty($Disabled)) { ?>
140
-            ( <input type="button" autofill="jav" value="Autofill" style="font-size:0.8em;"></input> )
141
-<? } ?>
137
+<?php if (empty($Disabled)) { ?>
138
+          <input type="button" autofill="jav" value="Autofill"></input>
139
+<?php } ?>
142 140
           </td>
143 141
         </tr>
144 142
         <tr id="artist_tr">
145
-          <td class="label">Artist(s)</td>
143
+          <td class="label">Collaborator(s)</td>
146 144
           <td id="artistfields">
147 145
             <p id="vawarning" class="hidden">Please use the multiple artists feature rather than adding "Various Artists" as an artist; read <a href="wiki.php?action=article&amp;id=369">this</a> for more information.</p>
148
-<?
146
+<?php
149 147
     if (!empty($ArtistForm)) {
150
-      $First = true;
151
-      foreach ($ArtistForm as $Artist) {
152
-?>
153
-            <input type="text" id="artist_0" name="artists[]"<? Users::has_autocomplete_enabled('other'); ?> size="45" value="<?=display_str($Artist['name']) ?>" <?=$Disabled?>/>
154
-            <? if (empty($Disabled)) { if ($First) { ?><a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a><? } $First = false; } ?>
148
+        $First = true;
149
+        foreach ($ArtistForm as $Artist) {
150
+            ?>
151
+            <input type="text" id="artist_0" name="artists[]"<?php Users::has_autocomplete_enabled('other'); ?> size="45" value="<?=display_str($Artist['name']) ?>" <?=$Disabled?>/>
152
+            <?php if (empty($Disabled)) {
153
+                if ($First) { ?><a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a><?php }
154
+                $First = false;
155
+            } ?>
155 156
             <br />
156
-<?
157
-      }
157
+<?php
158
+        }
158 159
     } else {
159
-?>            <input type="text" id="artist_0" name="artists[]"<? Users::has_autocomplete_enabled('other'); ?> size="45" <?=$Disabled?>/>
160
-<? if (empty($Disabled)) { ?>
160
+        ?>            <input type="text" id="artist_0" name="artists[]"<?php Users::has_autocomplete_enabled('other'); ?> size="45" <?=$Disabled?>/>
161
+<?php if (empty($Disabled)) { ?>
161 162
             <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
162
-<? } ?>
163
-<?
163
+<?php } ?>
164
+<?php
164 165
     }
165 166
 ?>
166 167
           </td>
@@ -183,73 +184,74 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode
183 184
             <input type="text" id="title_jp" name="title_jp" size="45" value="<?=!empty($TitleJP)?$TitleJP:''?>" <?=$Disabled?>/>
184 185
           </td>
185 186
         </tr>
186
-<?  } ?>
187
-<?  if ($NewRequest || $CanEdit) { ?>
187
+<?php  } ?>
188
+<?php  if ($NewRequest || $CanEdit) { ?>
188 189
         <tr id="image_tr">
189 190
           <td class="label tooltip" title="A meaningful picture, e.g., of the specimen">Picture</td>
190 191
           <td>
191 192
             <input type="text" id="image" name="image" size="45" value="<?=(!empty($Image) ? $Image : '')?>" <?=$Disabled?>/>
192 193
           </td>
193 194
         </tr>
194
-<?  } ?>
195
+<?php  } ?>
195 196
         <tr>
196 197
           <td class="label tooltip" title="Comma-seperated list of tags, n.b., use vanity.house for data you produced">Tags</td>
197 198
           <td>
198
-<?
199
+<?php
199 200
   $GenreTags = $Cache->get_value('genre_tags');
200 201
   if (!$GenreTags) {
201
-    $DB->query('
202
+      $DB->query('
202 203
       SELECT Name
203 204
       FROM tags
204 205
       WHERE TagType = \'genre\'
205 206
       ORDER BY Name');
206
-    $GenreTags = $DB->collect('Name');
207
-    $Cache->cache_value('genre_tags', $GenreTags, 3600 * 6);
207
+      $GenreTags = $DB->collect('Name');
208
+      $Cache->cache_value('genre_tags', $GenreTags, 3600 * 6);
208 209
   }
209 210
 
210 211
   if (!empty($Disabled)) {
211
-?>
212
+      ?>
212 213
             <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" disabled="disabled">
213
-<? } else { ?>
214
+<?php
215
+  } else { ?>
214 216
             <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" >
215
-<? } ?>
217
+<?php } ?>
216 218
               <option>---</option>
217
-<?  foreach (Misc::display_array($GenreTags) as $Genre) { ?>
219
+<?php  foreach (Misc::display_array($GenreTags) as $Genre) { ?>
218 220
               <option value="<?=$Genre?>"><?=$Genre?></option>
219
-<?  } ?>
221
+<?php  } ?>
220 222
             </select>
221
-            <input type="text" id="tags" name="tags" size="45" value="<?=(!empty($Tags) ? display_str($Tags) : '')?>"<? Users::has_autocomplete_enabled('other'); ?> <?=$Disabled?>/>
223
+            <input type="text" id="tags" name="tags" size="45" value="<?=(!empty($Tags) ? display_str($Tags) : '')?>"<?php Users::has_autocomplete_enabled('other'); ?> <?=$Disabled?>/>
222 224
           </td>
223 225
         </tr>
224
-<?  if ($NewRequest || $CanEdit) { ?>
225
-<?  } ?>
226
+<?php  if ($NewRequest || $CanEdit) { ?>
227
+<?php  } ?>
226 228
         <tr>
227 229
           <td class="label">Description</td>
228 230
           <td>
229
-<?          new TEXTAREA_PREVIEW('description', 'req_desc', $Request['Description']??''); ?>
231
+<?php          new TEXTAREA_PREVIEW('description', 'req_desc', $Request['Description']??''); ?>
230 232
           </td>
231 233
         </tr>
232
-<?  if (check_perms('site_moderate_requests')) { ?>
234
+<?php  if (check_perms('site_moderate_requests')) { ?>
233 235
         <tr>
234
-          <td class="label">Torrent group</td>
236
+          <td class="label">Torrent Group</td>
235 237
           <td>
236 238
             <?=site_url()?>torrents.php?id=<input type="text" name="groupid" value="<?=isset($GroupID)?$GroupID:''?>" size="15"/><br />
237
-            If this request matches a torrent group <span style="font-weight: bold;">already existing</span> on the site, please indicate that here.
239
+            If this request matches a torrent group <strong>already existing</strong> on the site, please indicate that here.
238 240
           </td>
239 241
         </tr>
240
-<?  } elseif (!empty($GroupID) && ($CategoryID != 5) && ($CategoryID != 0)) { ?>
242
+<?php  } elseif (!empty($GroupID) && ($CategoryID !== 5) && ($CategoryID !== 0)) { ?>
241 243
         <tr>
242 244
           <td class="label">Torrent Group</td>
243 245
           <td>
244 246
             <a href="torrents.php?id=<?=$GroupID?>"><?=site_url()?>torrents.php?id=<?=$GroupID?></a><br />
245 247
             This request <?=($NewRequest ? 'will be' : 'is')?> associated with the above torrent group.
246
-<?    if (!$NewRequest) { ?>
248
+<?php    if (!$NewRequest) { ?>
247 249
             If this is incorrect, please <a href="reports.php?action=report&amp;type=request&amp;id=<?=$RequestID?>">report this request</a> so that staff can fix it.
248
-<?    } ?>
250
+<?php    } ?>
249 251
             <input type="hidden" name="groupid" value="<?=$GroupID?>" />
250 252
           </td>
251 253
         </tr>
252
-<?  }
254
+<?php  }
253 255
   if ($NewRequest) { ?>
254 256
         <tr id="voting">
255 257
           <td class="label tooltip" title="How much upload credit the fulfiller wins">Bounty</td>
@@ -264,7 +266,7 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode
264 266
           </td>
265 267
         </tr>
266 268
         <tr>
267
-          <td class="label">Post request information</td>
269
+          <td class="label">Post-Request Information</td>
268 270
           <td>
269 271
             <input type="hidden" id="amount" name="amount" value="<?=(!empty($Bounty) ? $Bounty : '100')?>" />
270 272
             <input type="hidden" id="current_uploaded" value="<?=$LoggedUser['BytesUploaded']?>" />
@@ -280,17 +282,16 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'bbcode
280 282
             <input type="submit" id="button" value="Create request" disabled="disabled" />
281 283
           </td>
282 284
         </tr>
283
-<?  } else { ?>
285
+<?php  } else { ?>
284 286
         <tr>
285 287
           <td colspan="2" class="center">
286 288
             <input type="submit" id="button" value="Edit request" />
287 289
           </td>
288 290
         </tr>
289
-<?  } ?>
291
+<?php  } ?>
290 292
       </table>
291 293
     </form>
292 294
   </div>
293 295
 </div>
294
-<?
296
+<?php
295 297
 View::show_footer();
296
-?>

+ 167
- 168
sections/requests/take_new_edit.php View File

@@ -1,4 +1,4 @@
1
-<?
1
+<?php
2 2
 
3 3
 //******************************************************************************//
4 4
 //----------------- Take request -----------------------------------------------//
@@ -6,171 +6,172 @@ authorize();
6 6
 
7 7
 
8 8
 if ($_POST['action'] !== 'takenew' && $_POST['action'] !== 'takeedit') {
9
-  error(0);
9
+    error(0);
10 10
 }
11 11
 
12 12
 $NewRequest = ($_POST['action'] === 'takenew');
13 13
 
14 14
 if (!$NewRequest) {
15
-  $ReturnEdit = true;
15
+    $ReturnEdit = true;
16 16
 }
17 17
 
18 18
 if ($NewRequest) {
19
-  if (!check_perms('site_submit_requests') || $LoggedUser['BytesUploaded'] < 250 * 1024 * 1024) {
20
-    error(403);
21
-  }
19
+    if (!check_perms('site_submit_requests') || $LoggedUser['BytesUploaded'] < 250 * 1024 * 1024) {
20
+        error(403);
21
+    }
22 22
 } else {
23
-  $RequestID = $_POST['requestid'];
24
-  if (!is_number($RequestID)) {
25
-    error(0);
26
-  }
23
+    $RequestID = $_POST['requestid'];
24
+    if (!is_number($RequestID)) {
25
+        error(0);
26
+    }
27 27
 
28
-  $Request = Requests::get_request($RequestID);
29
-  if ($Request === false) {
30
-    error(404);
31
-  }
32
-  $VoteArray = Requests::get_votes_array($RequestID);
33
-  $VoteCount = count($VoteArray['Voters']);
34
-  $IsFilled = !empty($Request['TorrentID']);
35
-  $CategoryName = $Categories[$Request['CategoryID'] - 1];
36
-  $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && ($Request['CategoryID'] === '0' || ($CategoryName === 'Music' && $Year === '0')));
37
-  $CanEdit = ((!$IsFilled && $LoggedUser['ID'] === $Request['UserID'] && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
38
-
39
-  if (!$CanEdit) {
40
-    error(403);
41
-  }
28
+    $Request = Requests::get_request($RequestID);
29
+    if ($Request === false) {
30
+        error(404);
31
+    }
32
+    $VoteArray = Requests::get_votes_array($RequestID);
33
+    $VoteCount = count($VoteArray['Voters']);
34
+    $IsFilled = !empty($Request['TorrentID']);
35
+    $CategoryName = $Categories[$Request['CategoryID'] - 1];
36
+    $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && ($Request['CategoryID'] === '0' || ($CategoryName === 'Music' && $Year === '0')));
37
+    $CanEdit = ((!$IsFilled && $LoggedUser['ID'] === $Request['UserID'] && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
38
+
39
+    if (!$CanEdit) {
40
+        error(403);
41
+    }
42 42
 }
43 43
 
44 44
 // Validate
45 45
 if (empty($_POST['type'])) {
46
-  error(0);
46
+    error(0);
47 47
 }
48 48
 
49 49
 $CategoryName = $_POST['type'];
50 50
 $CategoryID = (array_search($CategoryName, $Categories) + 1);
51 51
 
52 52
 if (empty($CategoryID)) {
53
-  error(0);
53
+    error(0);
54 54
 }
55 55
 
56 56
 if (empty($_POST['title']) && empty($_POST['title_rj']) && empty($_POST['title_jp'])) {
57
-  $Err = 'You must enter at least one title!';
57
+    $Err = 'You must enter at least one title!';
58 58
 }
59 59
 
60 60
 if (!empty($_POST['title'])) {
61
-  $Title = trim($_POST['title']);
61
+    $Title = trim($_POST['title']);
62 62
 }
63 63
 
64 64
 if (!empty($_POST['title_rj'])) {
65
-  $TitleRJ = trim($_POST['title_rj']);
65
+    $TitleRJ = trim($_POST['title_rj']);
66 66
 }
67 67
 
68 68
 if (!empty($_POST['title_jp'])) {
69
-  $TitleJP = trim($_POST['title_jp']);
69
+    $TitleJP = trim($_POST['title_jp']);
70 70
 }
71 71
 
72 72
 if (empty($_POST['tags'])) {
73
-  $Err = 'You forgot to enter any tags!';
73
+    $Err = 'You forgot to enter any tags!';
74 74
 } else {
75
-  $Tags = trim($_POST['tags']);
75
+    $Tags = trim($_POST['tags']);
76 76
 }
77 77
 
78 78
 if ($NewRequest) {
79
-  if (empty($_POST['amount'])) {
80
-    $Err = 'You forgot to enter any bounty!';
81
-  } else {
82
-    $Bounty = trim($_POST['amount']);
83
-    if (!is_number($Bounty)) {
84
-      $Err = 'Your entered bounty is not a number';
85
-    } elseif ($Bounty < 100 * 1024 * 1024) {
86
-      $Err = 'Minimum bounty is 100 MB.';
79
+    if (empty($_POST['amount'])) {
80
+        $Err = 'You forgot to enter any bounty!';
81
+    } else {
82
+        $Bounty = trim($_POST['amount']);
83
+        if (!is_number($Bounty)) {
84
+            $Err = 'Your entered bounty is not a number';
85
+        } elseif ($Bounty < 100 * 1024 * 1024) {
86
+            $Err = 'Minimum bounty is 100 MB.';
87
+        }
88
+        $Bytes = $Bounty; // From MB to B
87 89
     }
88
-    $Bytes = $Bounty; //From MB to B
89
-  }
90 90
 }
91 91
 
92 92
 if (empty($_POST['image'])) {
93
-  $Image = '';
93
+    $Image = '';
94 94
 } else {
95
-  ImageTools::blacklisted($_POST['image']);
96
-  if (preg_match('/'.IMAGE_REGEX.'/', trim($_POST['image'])) > 0) {
97
-      $Image = trim($_POST['image']);
98
-  } else {
99
-    $Err = display_str($_POST['image']).' does not appear to be a valid link to an image.';
100
-  }
95
+    ImageTools::blacklisted($_POST['image']);
96
+    if (preg_match('/'.IMAGE_REGEX.'/', trim($_POST['image'])) > 0) {
97
+        $Image = trim($_POST['image']);
98
+    } else {
99
+        $Err = display_str($_POST['image']).' does not appear to be a valid link to an image.';
100
+    }
101 101
 }
102 102
 
103 103
 if (empty($_POST['description'])) {
104
-  $Err = 'You forgot to enter a description.';
104
+    $Err = 'You forgot to enter a description.';
105 105
 } else {
106
-  $Description = trim($_POST['description']);
106
+    $Description = trim($_POST['description']);
107 107
 }
108 108
 
109
-if (empty($_POST['artists']) && $CategoryName != 'Other') {
110
-  $Err = 'You did not enter any artists.';
109
+if (empty($_POST['artists']) && $CategoryName !== 'Other') {
110
+    $Err = 'You did not enter any artists.';
111 111
 } else {
112
-  $Artists = $_POST['artists'];
112
+    $Artists = $_POST['artists'];
113 113
 }
114 114
 
115
-//Not required
116
-if (!empty($_POST['cataloguenumber']) && $CategoryName == 'Movies') {
117
-  $CatalogueNumber = trim($_POST['cataloguenumber']);
115
+// Not required
116
+if (!empty($_POST['cataloguenumber']) && $CategoryName === 'Movies') {
117
+    $CatalogueNumber = trim($_POST['cataloguenumber']);
118 118
 } else {
119
-  $CatalogueNumber = '';
119
+    $CatalogueNumber = '';
120 120
 }
121
-if (!empty($_POST['dlsiteid']) && $CategoryName == 'Games') {
122
-  $DLSiteID = trim($_POST['dlsiteid']);
121
+if (!empty($_POST['dlsiteid']) && $CategoryName === 'Games') {
122
+    $DLSiteID = trim($_POST['dlsiteid']);
123 123
 } else {
124
-  $DLSiteID = '';
124
+    $DLSiteID = '';
125 125
 }
126 126
 
127 127
 // GroupID
128 128
 if (!empty($_POST['groupid'])) {
129
-  $GroupID = $_POST['groupid'];
130
-  if (is_number($GroupID)) {
131
-    $DB->query("
129
+    $GroupID = $_POST['groupid'];
130
+    if (is_number($GroupID)) {
131
+        $DB->query("
132 132
       SELECT CategoryID
133 133
       FROM torrents_group
134 134
       WHERE ID = '$GroupID'");
135
-    if (!$DB->has_results()) {
136
-      $Err = 'The torrent group, if entered, must correspond to a torrent group on the site.';
135
+        if (!$DB->has_results()) {
136
+            $Err = 'The torrent group, if entered, must correspond to a torrent group on the site.';
137
+        } else {
138
+            if ($CategoryID !== $DB->to_array()[0]['CategoryID']) {
139
+                $Err = 'The category of the specified torrent group does not match the category of your request.';
140
+            }
141
+        }
137 142
     } else {
138
-      if ($CategoryID != $DB->to_array()[0]['CategoryID']) {
139
-        $Err = 'The category of the specified torrent group does not match the category of your request.';
140
-      }
143
+        $Err = 'The torrent group, if entered, must correspond to a torrent group on the site.';
141 144
     }
142
-  } else {
143
-    $Err = 'The torrent group, if entered, must correspond to a torrent group on the site.';
144
-  }
145 145
 } elseif (isset($_POST['groupid']) && $_POST['groupid'] === '0') {
146
-  $GroupID = 0;
146
+    $GroupID = 0;
147 147
 }
148 148
 
149
-//For refilling on error
149
+// For refilling on error
150 150
 $ArtistNames = [];
151 151
 $ArtistForm = [];
152 152
 for ($i = 0; $i < count($Artists); $i++) {
153
-  if (trim($Artists[$i]) !== '') {
154
-    if (!in_array($Artists[$i], $ArtistNames)) {
155
-      $ArtistForm[] = array('name' => trim($Artists[$i]));
156
-      $ArtistNames[] = trim($Artists[$i]);
153
+    if (trim($Artists[$i]) !== '') {
154
+        if (!in_array($Artists[$i], $ArtistNames)) {
155
+            $ArtistForm[] = array('name' => trim($Artists[$i]));
156
+            $ArtistNames[] = trim($Artists[$i]);
157
+        }
157 158
     }
158
-  }
159 159
 }
160 160
 if (!isset($ArtistNames[0])) {
161
-  unset($ArtistForm);
161
+    unset($ArtistForm);
162 162
 }
163 163
 
164 164
 if (!empty($Err)) {
165
-  error($Err);
166
-  $Div = $_POST['unit'] === 'mb' ? 1024 * 1024 : 1024 * 1024 * 1024;
167
-  $Bounty /= $Div;
168
-  include(SERVER_ROOT.'/sections/requests/new_edit.php');
169
-  die();
165
+    error($Err);
166
+    $Div = $_POST['unit'] === 'mb' ? 1024 * 1024 : 1024 * 1024 * 1024;
167
+    $Bounty /= $Div;
168
+    include(SERVER_ROOT.'/sections/requests/new_edit.php');
169
+    die();
170 170
 }
171 171
 
172
-//Databasify the input
173
-/*if ($CategoryName === 'Music') {
172
+// Databasify the input
173
+/*
174
+if ($CategoryName === 'Music') {
174 175
   if (empty($AllBitrates)) {
175 176
     foreach ($BitrateArray as $Index => $MasterIndex) {
176 177
       if (array_key_exists($Index, $Bitrates)) {
@@ -231,13 +232,16 @@ if (!empty($Err)) {
231 232
       $LogCue = 'Cue';
232 233
     }
233 234
   }
234
-}*/
235
+}
236
+*/
235 237
 
236
-if (!isset($GroupID)) $GroupID = '';
238
+if (!isset($GroupID)) {
239
+    $GroupID = '';
240
+}
237 241
 
238
-//Query time!
242
+// Query time!
239 243
 if ($NewRequest) {
240
-  $DB->query('
244
+    $DB->query('
241 245
     INSERT INTO requests (
242 246
       UserID, TimeAdded, LastVote, CategoryID, Title, TitleRJ, TitleJP, Image, Description,
243 247
       CatalogueNumber, DLSiteID, Visible, GroupID)
@@ -245,10 +249,9 @@ if ($NewRequest) {
245 249
       ('.$LoggedUser['ID'].", NOW(), NOW(), $CategoryID, '".db_string($Title)."', '".db_string($TitleRJ)."', '".db_string($TitleJP)."', '".db_string($Image)."', '".db_string($Description)."',
246 250
           '".db_string($CatalogueNumber)."', '".db_string($DLSiteID)."', '1', '$GroupID')");
247 251
 
248
-  $RequestID = $DB->inserted_id();
249
-
252
+    $RequestID = $DB->inserted_id();
250 253
 } else {
251
-  $DB->query("
254
+    $DB->query("
252 255
     UPDATE requests
253 256
     SET CategoryID = $CategoryID,
254 257
       Title = '".db_string($Title)."',
@@ -260,125 +263,123 @@ if ($NewRequest) {
260 263
       DLSiteID = '".db_string($DLSiteID)."'
261 264
     WHERE ID = $RequestID");
262 265
 
263
-  // We need to be able to delete artists / tags
264
-  $DB->query("
266
+    // We need to be able to delete artists/tags
267
+    $DB->query("
265 268
     SELECT ArtistID
266 269
     FROM requests_artists
267 270
     WHERE RequestID = $RequestID");
268
-  $RequestArtists = $DB->to_array();
269
-  foreach ($RequestArtists as $RequestArtist) {
270
-    $Cache->delete_value("artists_requests_".$RequestArtist['ArtistID']);
271
-  }
272
-  $DB->query("
271
+    $RequestArtists = $DB->to_array();
272
+    foreach ($RequestArtists as $RequestArtist) {
273
+        $Cache->delete_value("artists_requests_".$RequestArtist['ArtistID']);
274
+    }
275
+    $DB->query("
273 276
     DELETE FROM requests_artists
274 277
     WHERE RequestID = $RequestID");
275
-  $Cache->delete_value("request_artists_$RequestID");
278
+    $Cache->delete_value("request_artists_$RequestID");
276 279
 }
277 280
 
278 281
 if ($GroupID) {
279
-  $Cache->delete_value("requests_group_$GroupID");
282
+    $Cache->delete_value("requests_group_$GroupID");
280 283
 }
281 284
 
282 285
 /*
283 286
  * Multiple Artists!
284 287
  * For the multiple artists system, we have 3 steps:
285
- * 1. See if each artist given already exists and if it does, grab the ID.
286
- * 2. For each artist that didn't exist, create an artist.
287
- * 3. Create a row in the requests_artists table for each artist, based on the ID.
288
+ *   1. See if each artist given already exists and if it does, grab the ID.
289
+ *   2. For each artist that didn't exist, create an artist.
290
+ *   3. Create a row in the requests_artists table for each artist, based on the ID.
288 291
  */
289 292
 if (isset($ArtistForm)) {
290
-  foreach ($ArtistForm as $Num => $Artist) {
291
-    //1. See if each artist given already exists and if it does, grab the ID.
292
-    $DB->query("
293
+    foreach ($ArtistForm as $Num => $Artist) {
294
+        // 1. See if each artist given already exists and if it does, grab the ID.
295
+        $DB->query("
293 296
       SELECT
294 297
         ArtistID,
295 298
         Name
296 299
       FROM artists_group
297 300
       WHERE Name = '".db_string($Artist['name'])."'");
298 301
 
299
-    list($ArtistID, $ArtistName) = $DB->next_record(MYSQLI_NUM, false);
300
-    $ArtistForm[$Num] = array('name' => $ArtistName, 'id' => $ArtistID);
302
+        list($ArtistID, $ArtistName) = $DB->next_record(MYSQLI_NUM, false);
303
+        $ArtistForm[$Num] = array('name' => $ArtistName, 'id' => $ArtistID);
301 304
 
302
-    if (!$ArtistID) {
303
-      //2. For each artist that didn't exist, create an artist.
304
-      $DB->query("
305
+        if (!$ArtistID) {
306
+            // 2. For each artist that didn't exist, create an artist.
307
+            $DB->query("
305 308
         INSERT INTO artists_group (Name)
306 309
         VALUES ('".db_string($Artist['name'])."')");
307
-      $ArtistID = $DB->inserted_id();
310
+            $ArtistID = $DB->inserted_id();
308 311
 
309
-      $Cache->increment('stats_artist_count');
312
+            $Cache->increment('stats_artist_count');
310 313
 
311
-      $ArtistForm[$Num] = array('id' => $ArtistID, 'name' => $Artist['name']);
314
+            $ArtistForm[$Num] = array('id' => $ArtistID, 'name' => $Artist['name']);
315
+        }
312 316
     }
313
-  }
314 317
 
315
-
316
-  //3. Create a row in the requests_artists table for each artist, based on the ID.
317
-  foreach ($ArtistForm as $Num => $Artist) {
318
-    $DB->query("
318
+    // 3. Create a row in the requests_artists table for each artist, based on the ID.
319
+    foreach ($ArtistForm as $Num => $Artist) {
320
+        $DB->query("
319 321
       INSERT IGNORE INTO requests_artists
320 322
         (RequestID, ArtistID)
321 323
       VALUES
322 324
         ($RequestID, ".$Artist['id'].")");
323
-    $Cache->delete_value('artists_requests_'.$Artist['id']);
324
-  }
325
-  //End Music only
326
-
325
+        $Cache->delete_value('artists_requests_'.$Artist['id']);
326
+    }
327
+    // End Music only
327 328
 } else {
328
-  //Not a music request anymore, delete music only fields.
329
-  if (!$NewRequest) {
330
-    $DB->query("
329
+    // Not a music request anymore, delete music only fields.
330
+    if (!$NewRequest) {
331
+        $DB->query("
331 332
       SELECT ArtistID
332 333
       FROM requests_artists
333 334
       WHERE RequestID = $RequestID");
334
-    $OldArtists = $DB->collect('ArtistID');
335
-    foreach ($OldArtists as $ArtistID) {
336
-      if (empty($ArtistID)) {
337
-        continue;
338
-      }
339
-      //Get a count of how many groups or requests use the artist ID
340
-      $DB->query("
335
+        $OldArtists = $DB->collect('ArtistID');
336
+        foreach ($OldArtists as $ArtistID) {
337
+            if (empty($ArtistID)) {
338
+                continue;
339
+            }
340
+            // Get a count of how many groups or requests use the artist ID
341
+            $DB->query("
341 342
         SELECT COUNT(ag.ArtistID)
342 343
         FROM artists_group AS ag
343 344
           LEFT JOIN requests_artists AS ra ON ag.ArtistID = ra.ArtistID
344 345
         WHERE ra.ArtistID IS NOT NULL
345 346
           AND ag.ArtistID = '$ArtistID'");
346
-      list($ReqCount) = $DB->next_record();
347
-      $DB->query("
347
+            list($ReqCount) = $DB->next_record();
348
+            $DB->query("
348 349
         SELECT COUNT(ag.ArtistID)
349 350
         FROM artists_group AS ag
350 351
           LEFT JOIN torrents_artists AS ta ON ag.ArtistID = ta.ArtistID
351 352
         WHERE ta.ArtistID IS NOT NULL
352 353
           AND ag.ArtistID = '$ArtistID'");
353
-      list($GroupCount) = $DB->next_record();
354
-      if (($ReqCount + $GroupCount) == 0) {
355
-        //The only group to use this artist
356
-        Artists::delete_artist($ArtistID);
357
-      } else {
358
-        //Not the only group, still need to clear cache
359
-        $Cache->delete_value("artists_requests_$ArtistID");
360
-      }
361
-    }
362
-    $DB->query("
354
+            list($GroupCount) = $DB->next_record();
355
+            if (($ReqCount + $GroupCount) === 0) {
356
+                // The only group to use this artist
357
+                Artists::delete_artist($ArtistID);
358
+            } else {
359
+                // Not the only group, still need to clear cache
360
+                $Cache->delete_value("artists_requests_$ArtistID");
361
+            }
362
+        }
363
+        $DB->query("
363 364
       DELETE FROM requests_artists
364 365
       WHERE RequestID = $RequestID");
365
-    $Cache->delete_value("request_artists_$RequestID");
366
-  }
366
+        $Cache->delete_value("request_artists_$RequestID");
367
+    }
367 368
 }
368 369
 
369 370
 //Tags
370 371
 if (!$NewRequest) {
371
-  $DB->query("
372
+    $DB->query("
372 373
     DELETE FROM requests_tags
373 374
     WHERE RequestID = $RequestID");
374 375
 }
375 376
 
376 377
 $Tags = array_unique(explode(',', $Tags));
377 378
 foreach ($Tags as $Index => $Tag) {
378
-  $Tag = Misc::sanitize_tag($Tag);
379
-  $Tag = Misc::get_alias_tag($Tag);
380
-  $Tags[$Index] = $Tag; //For announce
381
-  $DB->query("
379
+    $Tag = Misc::sanitize_tag($Tag);
380
+    $Tag = Misc::get_alias_tag($Tag);
381
+    $Tags[$Index] = $Tag; // For announce
382
+    $DB->query("
382 383
     INSERT INTO tags
383 384
       (Name, UserID)
384 385
     VALUES
@@ -386,9 +387,9 @@ foreach ($Tags as $Index => $Tag) {
386 387
     ON DUPLICATE KEY UPDATE
387 388
       Uses = Uses + 1");
388 389
 
389
-  $TagID = $DB->inserted_id();
390
+    $TagID = $DB->inserted_id();
390 391
 
391
-  $DB->query("
392
+    $DB->query("
392 393
     INSERT IGNORE INTO requests_tags
393 394
       (TagID, RequestID)
394 395
     VALUES
@@ -396,30 +397,28 @@ foreach ($Tags as $Index => $Tag) {
396 397
 }
397 398
 
398 399
 if ($NewRequest) {
399
-  //Remove the bounty and create the vote
400
-  $DB->query("
400
+    // Remove the bounty and create the vote
401
+    $DB->query("
401 402
     INSERT INTO requests_votes
402 403
       (RequestID, UserID, Bounty)
403 404
     VALUES
404 405
       ($RequestID, ".$LoggedUser['ID'].', '.($Bytes * (1 - $RequestTax)).')');
405 406
 
406
-  $DB->query("
407
+    $DB->query("
407 408
     UPDATE users_main
408 409
     SET Uploaded = (Uploaded - $Bytes)
409 410
     WHERE ID = ".$LoggedUser['ID']);
410
-  $Cache->delete_value('user_stats_'.$LoggedUser['ID']);
411
-
412
-  $AnnounceTitle = empty($Title) ? (empty($TitleRJ) ? $TitleJP : $TitleRJ) : $Title;
411
+    $Cache->delete_value('user_stats_'.$LoggedUser['ID']);
413 412
 
414
-  $Announce = "\"$AnnounceTitle\"".(isset($ArtistForm)?(' - '.Artists::display_artists($ArtistForm, false, false)):'').' '.site_url()."requests.php?action=view&id=$RequestID - ".implode(' ', $Tags);
415
-  send_irc('PRIVMSG '.BOT_REQUEST_CHAN.' '.$Announce);
413
+    $AnnounceTitle = empty($Title) ? (empty($TitleRJ) ? $TitleJP : $TitleRJ) : $Title;
416 414
 
415
+    $Announce = "\"$AnnounceTitle\"".(isset($ArtistForm)?(' - '.Artists::display_artists($ArtistForm, false, false)):'').' '.site_url()."requests.php?action=view&id=$RequestID - ".implode(' ', $Tags);
416
+    send_irc('PRIVMSG '.BOT_REQUEST_CHAN.' '.$Announce);
417 417
 } else {
418
-  $Cache->delete_value("request_$RequestID");
419
-  $Cache->delete_value("request_artists_$RequestID");
418
+    $Cache->delete_value("request_$RequestID");
419
+    $Cache->delete_value("request_artists_$RequestID");
420 420
 }
421 421
 
422 422
 Requests::update_sphinx_requests($RequestID);
423 423
 
424 424
 header("Location: requests.php?action=view&id=$RequestID");
425
-?>

+ 75
- 71
static/functions/requests.js View File

@@ -3,7 +3,7 @@ function Vote(amount, requestid) {
3 3
     amount = parseInt($('#amount').raw().value);
4 4
   }
5 5
   if (amount == 0) {
6
-     amount = 20 * 1024 * 1024;
6
+    amount = 20 * 1024 * 1024;
7 7
   }
8 8
 
9 9
   var index;
@@ -30,33 +30,33 @@ function Vote(amount, requestid) {
30 30
   }
31 31
 
32 32
   ajax.get('requests.php?action=takevote&id=' + requestid + '&auth=' + authkey + '&amount=' + amount, function (response) {
33
-      if (response == 'bankrupt') {
34
-        save_message("You do not have sufficient upload credit to add " + get_size(amount) + " to this request", true);
35
-        return;
36
-      } else if (response == 'dupesuccess') {
37
-        //No increment
38
-      } else if (response == 'success') {
39
-        votecount.innerHTML = (parseInt(votecount.innerHTML)) + 1;
40
-      }
33
+    if (response == 'bankrupt') {
34
+      save_message("You do not have sufficient upload credit to add " + get_size(amount) + " to this request", true);
35
+      return;
36
+    } else if (response == 'dupesuccess') {
37
+      //No increment
38
+    } else if (response == 'success') {
39
+      votecount.innerHTML = (parseInt(votecount.innerHTML)) + 1;
40
+    }
41 41
 
42
-      if ($('#total_bounty').length > 0) {
43
-        totalBounty = parseInt($('#total_bounty').raw().value);
44
-        totalBounty += (amount * (1 - $('#request_tax').raw().value));
45
-        $('#total_bounty').raw().value = totalBounty;
46
-        $('#formatted_bounty').raw().innerHTML = get_size(totalBounty);
42
+    if ($('#total_bounty').length > 0) {
43
+      totalBounty = parseInt($('#total_bounty').raw().value);
44
+      totalBounty += (amount * (1 - $('#request_tax').raw().value));
45
+      $('#total_bounty').raw().value = totalBounty;
46
+      $('#formatted_bounty').raw().innerHTML = get_size(totalBounty);
47 47
 
48
-        save_message("Your vote of " + get_size(amount) + ", adding a " + get_size(amount * (1 - $('#request_tax').raw().value)) + " bounty, has been added");
49
-        $('#button').raw().disabled = true;
50
-      } else {
51
-        save_message("Your vote of " + get_size(amount) + " has been added");
52
-      }
48
+      save_message("Your vote of " + get_size(amount) + ", adding a " + get_size(amount * (1 - $('#request_tax').raw().value)) + " bounty, has been added");
49
+      $('#button').raw().disabled = true;
50
+    } else {
51
+      save_message("Your vote of " + get_size(amount) + " has been added");
53 52
     }
53
+  }
54 54
   );
55 55
 }
56 56
 
57 57
 function Calculate() {
58 58
   if (!$('#unit').raw()) { return; }
59
-  var mul = (($('#unit').raw().options[$('#unit').raw().selectedIndex].value == 'mb') ? (1024*1024) : (1024*1024*1024));
59
+  var mul = (($('#unit').raw().options[$('#unit').raw().selectedIndex].value == 'mb') ? (1024 * 1024) : (1024 * 1024 * 1024));
60 60
   var amt = Math.floor($('#amount_box').raw().value * mul);
61 61
   if (amt > $('#current_uploaded').raw().value) {
62 62
     $('#new_uploaded').raw().innerHTML = "You can't afford that request!";
@@ -64,8 +64,8 @@ function Calculate() {
64 64
     $('#bounty_after_tax').raw().innerHTML = "0.00 MB";
65 65
     $('#button').raw().disabled = true;
66 66
   } else if (isNaN($('#amount_box').raw().value)
67
-      || (window.location.search.indexOf('action=new') != -1 && $('#amount_box').raw().value * mul < 100 * 1024 * 1024)
68
-      || (window.location.search.indexOf('action=view') != -1 && $('#amount_box').raw().value * mul < 20 * 1024 * 1024)) {
67
+    || (window.location.search.indexOf('action=new') != -1 && $('#amount_box').raw().value * mul < 100 * 1024 * 1024)
68
+    || (window.location.search.indexOf('action=view') != -1 && $('#amount_box').raw().value * mul < 20 * 1024 * 1024)) {
69 69
     $('#new_uploaded').raw().innerHTML = get_size(($('#current_uploaded').raw().value));
70 70
     $('#new_bounty').raw().innerHTML = "0.00 MB";
71 71
     $('#bounty_after_tax').raw().innerHTML = "0.00 MB";
@@ -81,47 +81,48 @@ function Calculate() {
81 81
 }
82 82
 
83 83
 function AddArtistField() {
84
-    var ArtistCount = document.getElementsByName("artists[]").length;
85
-    if (ArtistCount >= 200) {
86
-      return;
87
-    }
88
-    var ArtistField = document.createElement("input");
89
-    ArtistField.type = "text";
90
-    ArtistField.id = "artist_" + ArtistCount;
91
-    ArtistField.name = "artists[]";
92
-    ArtistField.size = 45;
93
-
94
-    var x = $('#artistfields').raw();
95
-    x.appendChild(document.createElement("br"));
96
-    x.appendChild(ArtistField);
97
-
98
-    if ($("#artist").data("gazelle-autocomplete")) {
99
-      $(ArtistField).live('focus', function() {
100
-        $(ArtistField).autocomplete({
101
-          serviceUrl : 'artist.php?action=autocomplete'
102
-        });
84
+  var ArtistCount = document.getElementsByName("artists[]").length;
85
+  if (ArtistCount >= 200) {
86
+    return;
87
+  }
88
+  var ArtistField = document.createElement("input");
89
+  ArtistField.type = "text";
90
+  ArtistField.id = "artist_" + ArtistCount;
91
+  ArtistField.name = "artists[]";
92
+  ArtistField.size = 45;
93
+
94
+  var x = $('#artistfields').raw();
95
+  x.appendChild(document.createElement("br"));
96
+  x.appendChild(ArtistField);
97
+
98
+  if ($("#artist").data("gazelle-autocomplete")) {
99
+    $(ArtistField).live('focus', function () {
100
+      $(ArtistField).autocomplete({
101
+        serviceUrl: 'artist.php?action=autocomplete'
103 102
       });
104
-    }
103
+    });
104
+  }
105 105
 
106
-    ArtistCount++;
106
+  ArtistCount++;
107 107
 }
108 108
 
109 109
 function RemoveArtistField() {
110
-    var ArtistCount = document.getElementsByName("artists[]").length;
111
-    if (ArtistCount == 1) {
112
-      return;
113
-    }
114
-    var x = $('#artistfields').raw();
110
+  var ArtistCount = document.getElementsByName("artists[]").length;
111
+  if (ArtistCount == 1) {
112
+    return;
113
+  }
114
+  var x = $('#artistfields').raw();
115 115
 
116
-    while (x.lastChild.tagName != "INPUT") {
117
-      x.removeChild(x.lastChild);
118
-    }
116
+  while (x.lastChild.tagName != "INPUT") {
119 117
     x.removeChild(x.lastChild);
120
-    x.removeChild(x.lastChild); //Remove trailing new line.
121
-    ArtistCount--;
118
+  }
119
+  x.removeChild(x.lastChild);
120
+  x.removeChild(x.lastChild); // Remove trailing new line.
121
+  ArtistCount--;
122 122
 }
123 123
 
124 124
 function Categories() {
125
+  /*
125 126
   var cat = $('#categories').raw() ? $('#categories').raw().options[$('#categories').raw().selectedIndex].value : '';
126 127
   if (cat == "Movies") {
127 128
     $('#artist_tr').gshow();
@@ -148,6 +149,7 @@ function Categories() {
148 149
     $('#cataloguenumber_tr').ghide();
149 150
     $('#dlsiteid_tr').ghide();
150 151
   }
152
+  */
151 153
 }
152 154
 
153 155
 function add_tag() {
@@ -199,15 +201,17 @@ function ToggleLogScore() {
199 201
 }
200 202
 
201 203
 function JavAutofill() {
202
-   var map = { cn: 'javdb',
203
-                idols: 'artist',
204
-               title: 'title',
205
-               title_jp: 'title_jp',
206
-               image: 'image',
207
-               tags: 'tags',
208
-               description: 'req_desc' }
204
+  var map = {
205
+    cn: 'javdb',
206
+    idols: 'artist',
207
+    title: 'title',
208
+    title_jp: 'title_jp',
209
+    image: 'image',
210
+    tags: 'tags',
211
+    description: 'req_desc'
212
+  }
209 213
   var cn = $('#catalogue').raw().value.toUpperCase()
210
-  $.getJSON('/ajax.php?action=javfill&cn='+cn, function(data) {
214
+  $.getJSON('/ajax.php?action=javfill&cn=' + cn, function (data) {
211 215
     if (data.status != "success") {
212 216
       $('#catalogue').raw().value = 'Failed'
213 217
       return
@@ -218,29 +222,29 @@ function JavAutofill() {
218 222
       if (Array.isArray(data.response[i])) {
219 223
         for (j in data.response[i]) {
220 224
           if (i == 'idols') {
221
-            if (!($('#'+map[i]+'_'+j).raw())) {
225
+            if (!($('#' + map[i] + '_' + j).raw())) {
222 226
               AddArtistField()
223 227
             }
224
-            $('#'+map[i]+'_'+j).raw().value = data.response[i][j]
228
+            $('#' + map[i] + '_' + j).raw().value = data.response[i][j]
225 229
           }
226
-          if (map[i] == 'tags' && !($('#'+map[i]).raw().value)) {
227
-            $('#'+map[i]).raw().value = data.response[i].join(', ')
230
+          if (map[i] == 'tags' && !($('#' + map[i]).raw().value)) {
231
+            $('#' + map[i]).raw().value = data.response[i].join(', ')
228 232
           }
229 233
         }
230 234
       }
231
-      if (map[i] && $('#'+map[i]).raw() && !($('#'+map[i]).raw().value)) {
232
-        $('#'+map[i]).raw().value = data.response[i]
235
+      if (map[i] && $('#' + map[i]).raw() && !($('#' + map[i]).raw().value)) {
236
+        $('#' + map[i]).raw().value = data.response[i]
233 237
       }
234 238
     }
235 239
   })
236 240
 }
237 241
 
238
-$(function() {
242
+$(function () {
239 243
   Categories()
240 244
   Calculate()
241
-  document.querySelectorAll('[autofill]').forEach(function(el) {
242
-    el.addEventListener('click', function(event) {
243
-      ({'jav':JavAutofill})[el.attributes['autofill'].value]()
245
+  document.querySelectorAll('[autofill]').forEach(function (el) {
246
+    el.addEventListener('click', function (event) {
247
+      ({ 'jav': JavAutofill })[el.attributes['autofill'].value]()
244 248
     })
245 249
   })
246 250
   $(document).on('click', '.add_artist_button', AddArtistField);

Loading…
Cancel
Save