Browse Source

Add preliminary slave management page

spaghetti 7 years ago
parent
commit
2bc3c0d49b
4 changed files with 92 additions and 0 deletions
  1. 13
    0
      classes/slaves.class.php
  2. 16
    0
      sections/slaves/index.php
  3. 60
    0
      sections/slaves/slaves.php
  4. 3
    0
      slaves.php

+ 13
- 0
classes/slaves.class.php View File

@@ -0,0 +1,13 @@
1
+<?
2
+class Slaves {
3
+  public static function get_level($SlaveID) {
4
+    G::$DB->query("
5
+      SELECT u.Uploaded, u.Downloaded, u.BonusPoints, COUNT(t.UserID)
6
+      FROM users_main AS u
7
+      LEFT JOIN torrents AS t ON u.ID=t.UserID
8
+      WHERE u.ID = $SlaveID");
9
+    list($Upload, $Download, $Points, $Uploads) = G::$DB->next_record();
10
+    return intval(((($Uploads**0.35)*1.5)+1) * max(($Upload+($Points*1000000)-$Download)/(1024**3),1));
11
+  }
12
+};
13
+?>

+ 16
- 0
sections/slaves/index.php View File

@@ -0,0 +1,16 @@
1
+<?
2
+enforce_login();
3
+
4
+if (isset($_REQUEST['action'])) {
5
+  switch ($_REQUEST['action']) {
6
+    case '':
7
+      include('upload_1GB.php');
8
+      break;
9
+    default:
10
+      error(404);
11
+      break;
12
+  }
13
+} else {
14
+  require(SERVER_ROOT.'/sections/slaves/slaves.php');
15
+}
16
+?>

+ 60
- 0
sections/slaves/slaves.php View File

@@ -0,0 +1,60 @@
1
+<?
2
+$DB->query("SELECT OwnerID FROM slaves WHERE UserID = $UserID");
3
+if ($DB->has_results()) {
4
+  list($Owner) = $DB->next_record();
5
+}
6
+
7
+$UserLevel = Slaves::get_level($UserID);
8
+
9
+$DB->query("SELECT UserID FROM slaves WHERE OwnerID = $UserID");
10
+$Slaves = $DB->collect('UserID');
11
+
12
+if (isset($_POST['release'])) {
13
+  if (in_array($_POST['release'], $Slaves)) {
14
+    $DB->query("
15
+      DELETE FROM slaves
16
+      WHERE UserID = ".db_string($_POST['release'])."
17
+      AND OwnerID = '$UserID'");
18
+  }
19
+  $Slaves = array_diff($Slaves, [$_POST['release']]);
20
+}
21
+
22
+foreach ($Slaves as $i => $Slave) {
23
+  $Level = slaves::get_level($Slave);
24
+  $Slaves[$i] = ['ID' => $Slave, 'Level' => $Level];
25
+}
26
+
27
+View::show_header('Slaves');
28
+?>
29
+<div class="thin">
30
+  <h2>Slavery</h2>
31
+  <div class="box pad">
32
+<?  if (isset($Owner)) { ?>
33
+    <h3>You are owned by <?=Users::format_username($Owner, false, true, true)?></h3>
34
+<?  } else { ?>
35
+    <h3>You are free</h3>
36
+<?  } ?>
37
+  </div>
38
+<?  if (sizeof($Slaves) == 0) { ?>
39
+  <h3>You have no slaves</h3>
40
+<?  } else { ?>
41
+  <h2>Your slaves</h2>
42
+  <div class="box">
43
+    <table>
44
+      <tr class="colhead">
45
+        <td>Slave</td>
46
+        <td>Level</td>
47
+        <td>Release</td>
48
+      </tr>
49
+<?    foreach ($Slaves as $Slave) { ?>
50
+      <tr>
51
+        <td><?=Users::format_username($Slave['ID'], false, true, true)?></td>
52
+        <td><?=number_format($Slave['Level'])?></td>
53
+        <td><form method="post"><button type="submit" name="release" value=<?=$Slave['ID']?>>Release</button></form></td>
54
+      </tr>
55
+<?    } ?>
56
+    </table>
57
+  </div>
58
+<?  } ?>
59
+</div>
60
+<? View::show_footer(); ?>

+ 3
- 0
slaves.php View File

@@ -0,0 +1,3 @@
1
+<?
2
+define('ERROR_EXCEPTION', true);
3
+require('classes/script_start.php');

Loading…
Cancel
Save