Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.49 KB | None | 0 0
  1. <?
  2. /*************************************************************************\
  3. //--------------Schedule page -------------------------------------------//
  4.  
  5. This page is run every 15 minutes, by cron.
  6.  
  7. \*************************************************************************/
  8.  
  9. function next_biweek() {
  10. $Date = gmdate('d');
  11. if($Date < 22 && $Date >=8) {
  12. $Return = 22;
  13. } else {
  14. $Return = 8;
  15. }
  16. return $Return;
  17. }
  18.  
  19. function next_day() {
  20. $Tomorrow = gmmktime(0,0,0,gmdate('m'),gmdate('d')+1,gmdate('Y'));
  21. return gmdate('d', $Tomorrow);
  22. }
  23.  
  24. function next_hour() {
  25. $Hour = gmmktime(gmdate('H')+1,0,0,gmdate('m'),gmdate('d'),gmdate('Y'));
  26. return gmdate('H', $Hour);
  27. }
  28.  
  29. if ($argv[1]!=SCHEDULE_KEY && !check_perms('admin_schedule')) { // authorization, Fix to allow people with perms hit this page.
  30. error(403);
  31. }
  32.  
  33.  
  34. header('Content-type: text/plain');
  35.  
  36. $DB->query("SELECT NextHour, NextDay, NextBiWeekly FROM schedule");
  37. list($Hour, $Day, $BiWeek) = $DB->next_record();
  38.  
  39. echo format_time(gmmktime())."\n";
  40.  
  41.  
  42. /*************************************************************************\
  43. //--------------Run every time ------------------------------------------//
  44.  
  45. These functions are run every time the script is executed (every 15
  46. minutes).
  47.  
  48. \*************************************************************************/
  49.  
  50. echo "Ran every-time functions\n";
  51.  
  52. //------------- Delete unpopular tags -----------------------------------//
  53. $DB->query("DELETE FROM torrents_tags WHERE NegativeVotes>PositiveVotes");
  54.  
  55. //------------- Put users on ratio watch --------------------------------//
  56.  
  57. // $RatioRequirements is defined in config.php
  58.  
  59. $DownloadBarrier = 1024*1024*1024*1024*1024; // one petabyte
  60. while(list($Download, $Ratio, $JoinDate) = array_shift($RatioRequirements)){
  61. // Take user off ratio watch if he meets the standards
  62. $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
  63. SET i.RatioWatchEnds='0000-00-00 00:00:00',
  64. i.RatioWatchDownload='0'
  65. WHERE m.Downloaded >= '$Download'
  66. AND m.Downloaded <= '$DownloadBarrier'
  67. AND m.Uploaded/m.Downloaded >= '$Ratio'
  68. AND i.RatioWatchEnds!='0000-00-00 00:00:00'");
  69.  
  70. // Put user on ratio watch if he doesn't meet the standards
  71. $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
  72. SET i.RatioWatchEnds='".time_plus(60*60*24*14)."',
  73. i.RatioWatchTimes = i.RatioWatchTimes+1,
  74. i.RatioWatchDownload = m.Downloaded
  75. WHERE m.Downloaded >= '$Download'
  76. AND m.Uploaded/m.Downloaded <= '$Ratio'
  77. AND i.RatioWatchEnds='0000-00-00 00:00:00'
  78. AND i.JoinDate<'$JoinDate'");
  79.  
  80. $DownloadBarrier = $Download;
  81. }
  82.  
  83. //------------- Disable users on ratio watch ----------------------------//
  84.  
  85. // If a user hasn't been taken off ratio watch in the two weeks since he was put on, banhammer
  86. $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
  87. SET m.Enabled='2',
  88. i.BanDate='".sqltime()."',
  89. i.BanReason='2',
  90. i.RatioWatchDownload='0',
  91. i.RatioWatchEnds='0000-00-00 00:00:00',
  92. m.can_leech='0',
  93. i.AdminComment=CONCAT('".sqltime()." - Disabled by ratio watch system
  94. ', i.AdminComment)
  95. WHERE i.RatioWatchEnds!='0000-00-00 00:00:00'
  96. AND i.RatioWatchEnds<'".sqltime()."'
  97. And m.Enabled='1'");
  98.  
  99. // If a user has downloaded more than 10 gigs while on ratio watch, banhammer
  100. $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
  101. SET m.Enabled='2',
  102. i.BanDate='".sqltime()."',
  103. i.BanReason='3',
  104. i.RatioWatchDownload='0',
  105. i.RatioWatchEnds='0000-00-00 00:00:00',
  106. m.can_leech='0',
  107. i.AdminComment=CONCAT('".sqltime()." - Disabled by ratio watch system for downloading more than 10 gigs on ratio watch
  108. ', i.AdminComment)
  109. WHERE i.RatioWatchEnds!='0000-00-00 00:00:00'
  110. AND i.RatioWatchDownload+10*1024*1024*1024<m.Downloaded
  111. And m.Enabled='1'");
  112.  
  113. //------------- Build Torrent Hash Table --------------------------------//
  114.  
  115. if(!$_GET['nohash']) {
  116. $HashTime=gmmktime();
  117. $DB->query("DELETE g FROM torrents_group AS g LEFT JOIN torrents AS t ON t.GroupID = g.ID WHERE t.ID IS NULL");
  118.  
  119. $DB->query("UPDATE torrents_group SET TagList=(
  120. SELECT CONCAT('|',GROUP_CONCAT(tags.Name SEPARATOR '|'),'|')
  121. FROM torrents_tags AS t
  122. INNER JOIN tags ON tags.ID=t.TagID
  123. WHERE t.GroupID=torrents_group.ID
  124. GROUP BY t.GroupID)");
  125.  
  126. $DB->query("SELECT
  127. g.ID,
  128. g.Name,
  129. g.Year,
  130. g.CategoryID,
  131. g.Time,
  132. MAX(t.Size),
  133. SUM(t.Snatched),
  134. SUM(t.Seeders),
  135. SUM(t.Leechers),
  136. a.ID,
  137. a.Name,
  138. a.CatIcon,
  139. GROUP_CONCAT(t.ID ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  140. g.TagList,
  141. CONCAT('|',GROUP_CONCAT(t.Media ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  142. CONCAT('|',GROUP_CONCAT(t.Format ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  143. CONCAT('|',GROUP_CONCAT(t.Encoding ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  144. GROUP_CONCAT(t.Year ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  145. GROUP_CONCAT(t.Remastered ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  146. CONCAT('|',GROUP_CONCAT(t.RemasterTitle ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  147. GROUP_CONCAT(t.Scene ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  148. CONCAT('|',GROUP_CONCAT(t.HasLog ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  149. CONCAT('|',GROUP_CONCAT(t.HasCue ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  150. GROUP_CONCAT(t.FileCount ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  151. GROUP_CONCAT(t.Size ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  152. GROUP_CONCAT(t.Leechers ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  153. GROUP_CONCAT(t.Seeders ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  154. GROUP_CONCAT(t.Snatched ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  155. CONCAT('|',GROUP_CONCAT(t.FreeTorrent ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|'),
  156. GROUP_CONCAT(t.Time ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  157. CONCAT_WS(' ',a.Name,g.Name,g.Year),
  158. GROUP_CONCAT(t.exclusive ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),
  159. CONCAT('|',GROUP_CONCAT(t.Checked ORDER BY t.Format DESC, t.Encoding, t.ID SEPARATOR '|'),'|')
  160. FROM torrents AS t
  161. LEFT JOIN torrents_group AS g ON g.ID=t.GroupID
  162. LEFT JOIN artists AS a ON a.ID=g.ArtistID
  163. GROUP BY t.GroupID
  164. INTO OUTFILE '".TMP_DIR."/th_".$HashTime.".txt'");
  165.  
  166. $DB->query("LOAD DATA INFILE '".TMP_DIR."/th_".$HashTime.".txt' REPLACE INTO TABLE torrent_hash");
  167.  
  168. @unlink(TMP_DIR.'/th_'.$HashTime.'.txt');
  169.  
  170. $DB->query("DELETE h FROM torrent_hash AS h LEFT JOIN torrents_group AS g ON g.ID=h.GroupID WHERE g.ID IS NULL");
  171.  
  172. // Special characters don't survive the outfile/infile transition
  173. $DB->query("
  174. INSERT INTO torrent_hash (GroupID, GroupName, ArtistName)
  175. SELECT g.ID, g.Name, a.Name
  176. FROM torrents_group AS g
  177. LEFT JOIN artists AS a ON a.ID=g.ArtistID
  178. ON DUPLICATE KEY UPDATE
  179. GroupName=VALUES(GroupName),
  180. ArtistName=VALUES(ArtistName)");
  181.  
  182. $DB->query("UPDATE torrent_hash SET SearchText=CONCAT_WS(' ',ArtistName, GroupName, GroupYear)");
  183.  
  184. // Replace special characters with latin equilavents
  185. $Query = 'SearchText';
  186. while(list($K, list($Search, $Replace)) = each($SpecialChars)){
  187. $Query = 'REPLACE('.$Query.", '$Search', '$Replace')";
  188. }
  189. $Query = "UPDATE torrent_hash SET SearchText=".$Query;
  190. $DB->query($Query);
  191.  
  192. $DB->query("UPDATE torrents_group AS g, torrent_hash AS h SET g.SearchText=h.SearchText WHERE g.ID=h.GroupID");
  193.  
  194. //-----------------------------------------------------------------*/
  195.  
  196. echo "Hash built in ".(gmmktime()-$HashTime)." seconds\n";
  197.  
  198. $Cache->clear_browse_cache();
  199.  
  200. //---------------------------------------------------------//
  201. //---------------- Donation meter values ------------------//
  202.  
  203. $Cache->delete_value(donation_meter_total);
  204. $Cache->delete_value(donation_meter_percent);
  205.  
  206. $dmonth = date('m');
  207. $dyear = date('y');
  208. $DB->query("SELECT SUM(Amount) FROM donations WHERE Month = $dmonth AND Year = $dyear");
  209. $total = (array_sum(list($Amount) = $DB->next_record())/2);
  210.  
  211. // Site cost = $200, divide donations by 200 to get decimal percent
  212. $percent = round((($total/200)*100), 0);
  213.  
  214. $Cache->cache_value(donation_meter_total, $total, 3600);
  215. $Cache->cache_value(donation_meter_percent, $percent, 3600);
  216.  
  217. // value of donation meter
  218. // percent of donations
  219. $wutvalue = $Cache->get_value(donation_meter_total);
  220. $wutpercent = $Cache->get_value(donation_meter_percent);
  221. echo "Donations for this month: $" . $wutvalue . " ( " . $wutpercent . "% ) \n";
  222. echo 'Set donation SQL cache' . "\n";
  223.  
  224. //---------------------------------------------------------//
  225. //---------------- Remove expired donation status----------//
  226.  
  227. $RunTime = time();
  228. $DB->query("UPDATE users_info SET Donor = 0 WHERE DonorEnd < '".$RunTime."'");
  229. echo $RunTime . "\n";
  230.  
  231. // Get user count for signup page
  232. $DB->query("SELECT COUNT(ID) FROM users_main WHERE Enabled='1'");
  233. list($UserCount) = $DB->next_record();
  234. $Cache->cache_value(signup_count, $UserCount, 3600);
  235. echo $Cache->get_value(signup_count) . ' users enabled, openreg closed' . "\n";
  236.  
  237. $DB->query("DELETE FROM xbt_files_users WHERE mtime< UNIX_TIMESTAMP(NOW()-INTERVAL .5 HOUR)");
  238.  
  239. $DB->query('SELECT uid FROM xbt_files_users WHERE remaining=0 AND active=1');
  240. $count=$DB->record_count();
  241. echo $count / 4 . " credits will be awarded" . "\n";
  242. //------------------- Give bonus points -------------------------------//
  243. $DB->query('INSERT INTO users_info (UserID) SELECT uid FROM xbt_files_users WHERE remaining=0 AND active=1 ON DUPLICATE KEY UPDATE BonusPoints=BonusPoints+.25');
  244.  
  245. }
  246.  
  247. /*************************************************************************\
  248. //--------------Run every hour ------------------------------------------//
  249.  
  250. These functions are run every hour.
  251.  
  252. \*************************************************************************/
  253. if($Hour != next_hour() || $_GET['runhour']){
  254. echo "Ran hourly functions\n";
  255.  
  256.  
  257. //------------- Delete dead torrents ------------------------------------//
  258.  
  259. //------------- Promote users -------------------------------------------//
  260.  
  261. $Criteria = array();
  262. $Criteria[]=array('From'=>USER, 'To'=>MEMBER, 'MinUpload'=>20*1024*1024*1024, 'MinRatio'=>1.0, 'MinUploads'=>1, 'MaxTime'=>time_minus(3600*24*7*2));
  263. $Criteria[]=array('From'=>MEMBER, 'To'=>POWER, 'MinUpload'=>35*1024*1024*1024, 'MinRatio'=>1.7, 'MinUploads'=>5, 'MaxTime'=>time_minus(3600*24*7*6));
  264. $Criteria[]=array('From'=>POWER, 'To'=>LEGEND, 'MinUpload'=>100*1024*1024*1024, 'MinRatio'=>2.5, 'MinUploads'=>15, 'MaxTime'=>time_minus(3600*24*7*12));
  265.  
  266.  
  267. foreach($Criteria as $L){ // $L = Level
  268. $DB->query("UPDATE users_main JOIN users_info ON users_main.ID = users_info.UserID SET
  269. PermissionID='$L[To]'
  270. WHERE PermissionID='$L[From]'
  271. AND Warned= '0000-00-00 00:00:00'
  272. AND Uploaded>='$L[MinUpload]'
  273. AND Uploaded/Downloaded >='$L[MinRatio]'
  274. AND JoinDate<'$L[MaxTime]'
  275. AND (SELECT COUNT(ID) FROM torrents WHERE UserID=users_main.ID)>='$L[MinUploads]'
  276. AND Enabled='1'");
  277. }
  278.  
  279.  
  280. //------------- Expire invites ------------------------------------------//
  281. $DB->query('SELECT InviterID FROM invites WHERE Expires<\''.sqltime().'\'');
  282. $Users = $DB->to_array();
  283. while(list($UserID) = array_shift($Users)) {
  284. $DB->query("UPDATE users_main SET Invites=Invites+1 WHERE ID=$UserID");
  285. }
  286. $DB->query('DELETE FROM invites WHERE Expires<\''.sqltime().'\'');
  287.  
  288.  
  289. //------------- Hide old requests ---------------------------------------//
  290. $DB->query('UPDATE requests SET Visible=\'0\' WHERE TimeFilled<\''.time_minus(3600*24*3).'\' AND TimeFilled<>\'0000-00-00 00:00:00\'');
  291.  
  292. //------------- Remove dead peers ---------------------------------------//
  293.  
  294. $DB->query("DELETE FROM xbt_files_users WHERE mtime< UNIX_TIMESTAMP(NOW()-INTERVAL 1 HOUR)");
  295.  
  296. //------------- Lower Login Attempts ------------------------------------//
  297.  
  298. $DB->query("UPDATE login_attempts SET Attempts=Attempts-1 WHERE Attempts>0");
  299.  
  300. $Hour = next_hour();
  301. }
  302. /*************************************************************************\
  303. //--------------Run every day -------------------------------------------//
  304.  
  305. These functions are run in the first 15 minutes of every day.
  306.  
  307. \*************************************************************************/
  308.  
  309. if($Day != next_day() || $_GET['runday']){
  310. echo "Ran daily functions\n";
  311. if($Day%2 == 0){ // If we should generate the drive database (at the end)
  312. $GenerateDriveDB = true;
  313. }
  314. //------------- Remove expired warnings ---------------------------------//
  315. $DB->query("UPDATE users_info SET Warned='0000-00-00 00:00:00' WHERE Warned<'".sqltime()."'");
  316.  
  317. //------------- Disable inactive user accounts --------------------------//
  318.  
  319. $DB->query("UPDATE users_info AS ui JOIN users_main AS um ON um.ID=ui.UserID
  320. SET um.Enabled='2',
  321. ui.BanDate='".sqltime()."',
  322. ui.BanReason='3',
  323. ui.AdminComment=CONCAT('".sqltime()." - Disabled for inactivity
  324.  
  325. ', ui.AdminComment)
  326. WHERE um.PermissionID IN ('".USER."', '".MEMBER ."')
  327. AND um.LastAccess<'".time_minus(60*60*24*7*10)."'
  328. AND um.LastAccess!='0000-00-00 00:00:00'
  329. AND ui.Donor='0'
  330. AND um.Enabled!='2'");
  331.  
  332. //------------- Disable unconfirmed users ------------------------------//
  333.  
  334. $DB->query("UPDATE users_info AS ui JOIN users_main AS um ON um.ID=ui.UserID
  335. SET um.Enabled='2',
  336. ui.BanDate='".sqltime()."',
  337. ui.BanReason='3',
  338. ui.AdminComment=CONCAT('".sqltime()." - Disabled for inactivity (never logged in)
  339.  
  340. ', ui.AdminComment)
  341. WHERE um.LastAccess='0000-00-00 00:00:00'
  342. AND ui.JoinDate<'".time_minus(60*60*24*7)."'
  343. AND um.Enabled!='2'
  344. ");
  345.  
  346. //------------- Demote users --------------------------------------------//
  347.  
  348.  
  349. $DB->query('UPDATE users_main SET PermissionID='.USER.' WHERE PermissionID IN('.MEMBER.', '.POWER.', '.ELITE.', '.TORRENT_MASTER.') AND Uploaded/Downloaded < 1.0 OR PermissionID IN('.MEMBER.', '.POWER.', '.ELITE.', '.TORRENT_MASTER.') AND Uploaded < 20*1024*1024*1024) OR PermissionID IN('.MEMBER.', '.POWER.', '.ELITE.', '.TORRENT_MASTER.') AND MinUploads > 1');
  350. $DB->query('UPDATE users_main SET PermissionID='.USER.' WHERE PermissionID IN('.MEMBER.', '.POWER.', '.ELITE.', '.TORRENT_MASTER.') AND Uploaded/Downloaded < 0.8');
  351.  
  352.  
  353. //------------- Lock old threads ----------------------------------------//
  354.  
  355. $DB->query("UPDATE forums_topics
  356. SET IsLocked='1'
  357. WHERE IsSticky='0'
  358. AND LastPostTime<NOW()-INTERVAL 4 WEEK
  359. AND IsLocked='0'
  360. ");
  361.  
  362. //------------- Take a ratio history dump -------------------------------//
  363.  
  364. $DB->query("SELECT MAX(Sequence) FROM users_history_ratio");
  365. list($Sequence) = $DB->next_record();
  366. $LastSequence = $Sequence;
  367. $Sequence++;
  368. if(!$Sequence){
  369. $Sequence = 1;
  370. }
  371.  
  372. $DB->query("INSERT INTO users_history_ratio(Sequence, UserID, Uploaded, Downloaded, UpChange, DownChange, Time)
  373. SELECT '$Sequence', m.ID, m.Uploaded, m.Downloaded, (m.Uploaded - r.Uploaded), (m.Downloaded - r.Downloaded), '".sqltime()."'
  374. FROM users_main AS m
  375. LEFT JOIN users_history_ratio AS r ON r.UserID=m.ID AND r.Sequence='$LastSequence'");
  376.  
  377. if(($Sequence-48)>0) {
  378. $DB->query("DELETE FROM users_history_ratio_hourly WHERE Sequence<=".($Sequence-48));
  379. }
  380.  
  381. //------------- Delete dead torrents ------------------------------------//
  382.  
  383. $i = 0;
  384. $DB->query("SELECT
  385. t.ID,
  386. t.GroupID,
  387. tg.Name,
  388. a.Name,
  389. t.last_action
  390. FROM torrents AS t
  391. JOIN torrents_group AS tg ON tg.ID=t.GroupID
  392. LEFT JOIN artists AS a ON a.ID=tg.ArtistID
  393. WHERE t.last_action<'".time_minus(3600*24*14)."'
  394. AND t.last_action!='0000-00-00 00:00:00'");
  395. $TorrentIDs = $DB->to_array();
  396.  
  397. while(list($ID, $GroupID, $Name, $ArtistName, $LastAction) = array_shift($TorrentIDs)) {
  398. if($ArtistName) {
  399. $Name = $ArtistName.' - '.$Name;
  400. }
  401. delete_torrent($ID, $GroupID);
  402. write_log('Torrent '.$ID.' ('.$Name.') was deleted for inactivity (not seeded in 2 weeks)');
  403. ++$i;
  404. }
  405. echo "\nDeleted $i torrents for inactivity\n";
  406.  
  407. $DB->query("SELECT SimilarID FROM artists_similar_scores WHERE Score<=0");
  408. $SimilarIDs = implode(',',$DB->collect('SimilarID'));
  409.  
  410. if(count($SimilarIDs)>0) {
  411. $DB->query("DELETE FROM artists_similar WHERE SimilarID IN($SimilarIDs)");
  412. $DB->query("DELETE FROM artists_similar_scores WHERE SimilarID IN($SimilarIDs)");
  413. $DB->query("DELETE FROM artists_similar_votes WHERE SimilarID IN($SimilarIDs)");
  414. }
  415. $Day = next_day();
  416. }
  417. /*************************************************************************\
  418. //--------------Run twice per month -------------------------------------//
  419.  
  420. These functions are twice per month, on the 8th and the 22nd.
  421.  
  422. \*************************************************************************/
  423.  
  424. if($BiWeek != next_biweek()) {
  425. echo "Ran bi-weekly functions\n";
  426.  
  427. //------------- Cycle auth keys -----------------------------------------//
  428.  
  429. $DB->query("UPDATE users_info
  430. SET AuthKey =
  431. MD5(
  432. CONCAT(
  433. AuthKey, RAND(), '".db_string(make_secret())."',
  434. SHA1(
  435. CONCAT(
  436. RAND(), RAND(), '".db_string(make_secret())."'
  437. )
  438. )
  439. )
  440. );"
  441. );
  442.  
  443. //------------- Give out invites! ---------------------------------------//
  444.  
  445. /*
  446. Every month, on the 8th, each Power User gets one invite (max of 4).
  447. Every month, on the 8th and the 22nd, each Elite User gets one invite (max of 4).
  448. Every month, on the 8th and the 22nd, each TorrentMaster gets two invites (max of 8).
  449.  
  450. Then, every month, on the 8th and the 22nd, we give out bonus invites like this:
  451.  
  452. Every Power User, Elite User or TorrentMaster whose total invitee ratio is above 0.75 and total invitee upload is over 2 gigs gets one invite.
  453. Every Power User, Elite User or TorrentMaster whose total invitee ratio is above 2.0 and total invitee upload is over 10 gigs gets one invite.
  454. Every Power User, Elite User or TorrentMaster whose total invitee ratio is above 3.0 and total invitee upload is over 20 gigs gets one invite.
  455.  
  456.  
  457. This cascades, so if you qualify for the last bonus group, you also qualify for the first two and will receive three bonus invites.
  458. So a TorrentMaster who fits in the last bonus category gets 5 invites every month on the 8th and the 22nd, whereas a power user who fits in the first category gets two invites on the 8th and one on the 22nd. A power user whose invitees suck only gets one invite per month.
  459.  
  460. There is a hard maximum of 10 invites for all classes, that cannot be exceeded by bonus invites.
  461.  
  462. */
  463. // Power users
  464. /*
  465. if($BiWeek == 8){
  466. $DB->query("UPDATE
  467. users_main AS um
  468. JOIN users_info AS ui ON ui.UserID=um.ID
  469. SET um.Invites=um.Invites+1
  470. WHERE PermissionID=".POWER."
  471. AND um.Enabled='1'
  472. AND ui.DisableInvites='0'
  473. AND um.Invites<4");
  474. }
  475. // Elite users
  476. $DB->query("UPDATE
  477. users_main AS um
  478. JOIN users_info AS ui ON ui.UserID=um.ID
  479. SET um.Invites=um.Invites+1
  480. WHERE PermissionID=".ELITE."
  481. AND um.Enabled='1'
  482. AND ui.DisableInvites='0'
  483. AND um.Invites<4");
  484.  
  485.  
  486. //TorrentMasters
  487. $DB->query("UPDATE
  488. users_main AS um
  489. JOIN users_info AS ui ON ui.UserID=um.ID
  490. SET um.Invites=um.Invites+1
  491. WHERE PermissionID=".TORRENT_MASTER."
  492. AND um.Enabled='1'
  493. AND ui.DisableInvites='0'
  494. AND um.Invites=7");
  495.  
  496. $DB->query("UPDATE
  497. users_main AS um
  498. JOIN users_info AS ui ON ui.UserID=um.ID
  499. SET um.Invites=um.Invites+2
  500. WHERE PermissionID=".TORRENT_MASTER."
  501. AND um.Enabled='1'
  502. AND ui.DisableInvites='0'
  503. AND um.Invites<7");
  504.  
  505.  
  506. // Handle bonus invites
  507.  
  508. $BonusReqs = array(
  509. array(0.75, 2*1024*1024*1024),
  510. array(2.0, 10*1024*1024*1024),
  511. array(3.0, 20*1024*1024*1024));
  512.  
  513. // In case you didn't know, MySQL sucks shit through a straw.
  514. // Since MySQL doesn't like subselecting from the target table during an update, we must create a temporary table.
  515. // \o/
  516.  
  517. $DB->query("CREATE TEMPORARY TABLE u
  518. SELECT SUM(Uploaded) AS Upload,SUM(Downloaded) AS Download,Inviter
  519. FROM users_main AS um JOIN users_info AS ui ON ui.UserID=um.ID
  520. GROUP BY Inviter");
  521.  
  522. while(list($Ratio, $Upload) = array_shift($BonusReqs)) {
  523. $DB->query("
  524. UPDATE users_main AS um
  525. JOIN users_info AS ui ON ui.UserID=um.ID
  526. JOIN u ON u.Inviter=um.ID
  527. SET um.Invites=um.Invites+1
  528. WHERE
  529. u.Upload/u.Download>$Ratio
  530. AND u.Upload>$Upload
  531. AND um.PermissionID IN(".POWER.", ".ELITE.", ".TORRENT_MASTER.")
  532. AND um.Enabled='1'
  533. AND ui.DisableInvites='0'
  534. AND um.Invites<10
  535. ");
  536. } */
  537.  
  538. $BiWeek = next_biweek();
  539. }
  540. $DB->query("UPDATE schedule SET NextHour = $Hour, NextDay = $Day, NextBiWeekly = $BiWeek");
  541.  
  542. echo "-------------------------\n\n";
  543.  
  544. ?>
Add Comment
Please, Sign In to add comment