Location: PHPKode > projects > Guild DKP System > dkpsystem1.4/includes/admin/continueraid.php
<?php
$Complete = $_POST[Complete];
$StartRaid = $_POST[StartRaid];
$sessionid = $_GET[sessionid];
/*******************
 * Start a new Raid
 *******************/
if(isset($StartRaid)) {
	$index = $_POST[txtIndex];
	$txtBonus = $_POST[txtBonus];
	$raidid = $_POST[selectRaid];
	$bossid = $_POST[selectBoss];
	$playing = $_POST[playing];
	$total_users = count($playing);
	//Verification Process
	$sql = $db->query("SELECT * FROM dkp_sessions WHERE id=\"$raidid\"");
	if($db->count_rows($sql) > 0) {
		$sql = $db->query("SELECT * FROM dkp_sessionvalues WHERE id=\"$bossid\"");
		if($db->count_rows($sql) > 0) {
			$sql = $db->query("SELECT * FROM dkp_sessionhistory WHERE raidid=\"$raidid\"");
			if($db->count_rows($sql) < 1) {
				//Raid Information
				$raidName = @mysql_result($db->query("SELECT raid FROM dkp_sessions WHERE id=\"$raidid\""), 0);
				$raidSessions = @mysql_result($db->query("SELECT sessions FROM dkp_sessions WHERE id=\"$raidid\""), 0);
				$bossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE id=\"$bossid\""), 0);
				//Raid Process
				$db->query("INSERT INTO dkp_sessionhistory (raidid, session, status) VALUES ('$raidid', '$index', '1')");
				$sessionid = @mysql_result($db->query("SELECT id FROM dkp_sessionhistory WHERE raidid=\"$raidid\""), 0);
				for($i=0; $i<$total_users; $i++) {
					$userid = $playing[$i];
					$db->query("INSERT INTO dkp_userhistory (userid, raidid, status) VALUES ('$userid', '$raidid', '1')");
					if($txtBonus > 0) {
						$reason = $raidName . ": On time bonus";
						$db->query("INSERT INTO dkp_tempadjustments (userid, raidid, sessionid, reason, value, pool) VALUES ('$userid', '$raidid', '$sessionid', \"$reason\", '$txtBonus', '3')");
					}
				}
			}
			else {
				die(systemMessage("Raid Error", "There is already a raid saved using this instance.", "?d=admin&s=startraid"));
			}
		}
		else {
			die(systemMessage("Raid Error", "The boss that you have selected to start from, can not be found.", "?d=admin&s=startraid"));
		}
	}
	else {
		die(systemMessage("Raid Error", "The instance that you have selected to raid, can not be found.", "?d=admin&s=startraid"));
	}
}
/**********************
 * Continue a live raid
 **********************/
elseif(isset($Continue)) {
	$raidid = $_POST[live_raidid];
	$sessionid = $_POST[live_sessionid];
	$old_bossid = $_POST[live_bossid];
	$playing = $_POST[playing];
	$total_users = count($playing);
	$sql = $db->query("SELECT id FROM dkp_sessionhistory WHERE raidid=\"$raidid\"");
	if($db->count_rows($sql) > 0) {
		//Raid Information
		$bossid = @mysql_result($db->query("SELECT MIN(id) FROM dkp_sessionvalues WHERE id>\"$old_bossid\""), 0);
		$raidName = @mysql_result($db->query("SELECT raid FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$raidSessions = @mysql_result($db->query("SELECT sessions FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$oldBossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE id=\"$old_bossid\""), 0);
		$bossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE id=\"$bossid\""), 0);
		$bossValue = @mysql_result($db->query("SELECT value FROM dkp_sessionvalues WHERE id=\"$old_bossid\""), 0);
		$index = @mysql_result($db->query("SELECT session FROM dkp_sessionhistory WHERE id=\"$sessionid\""), 0);
		$index++;
		//Raid stats
		$totalOccurances = @mysql_result($db->query("SELECT occurances FROM dkp_stats WHERE raidid=\"$raidid\""), 0);
		$totalOccurances++;
		$db->query("UPDATE dkp_stats SET occurances=\"$totalOccurances\" WHERE raidid=\"$raidid\"");
		//Raid Process
		$db->query("UPDATE dkp_sessionhistory SET session=\"$index\" WHERE id=\"$sessionid\"");
		$db->query("UPDATE dkp_userhistory SET status='0' WHERE raidid=\"$raidid\"");
		for($i=0; $i<$total_users; $i++) {
			$userid = $playing[$i];
			$sql2 = $db->query("SELECT id FROM dkp_userhistory WHERE userid=\"$userid\"");
			//User was recently checked off, add him to the session history
			if($db->count_rows($sql2) < 1) { $db->query("INSERT INTO dkp_userhistory (userid, raidid, status) VALUES (\"$userid\", \"$raidid\", 1)"); }
			//Update users in raid
			$db->query("UPDATE dkp_userhistory SET status='1' WHERE userid=\"$userid\" AND raidid=\"$raidid\"");
			//Update user history
			$reason = $raidName . ": " . $oldBossName;
			$db->query("INSERT INTO dkp_tempadjustments (userid, raidid, sessionid, reason, value, pool) VALUES (\"$userid\", \"$raidid\", \"$sessionid\", \"$reason\", \"$bossValue\", '3')");
			$totalEvents = @mysql_result($db->query("SELECT events FROM dkp_users WHERE id=\"$userid\""), 0);
			$totalEvents++;
			$db->query("UPDATE dkp_users SET events=\"$totalEvents\" WHERE id=\"$userid\"");
		}
	}
	else {
		die(systemMessage("Raid Error", "The raid that you are trying to continue, no longer exists.", "?d=admin&s=startraid"));
	}
}
/**********************
 * Complete a live Raid
 **********************/
elseif(isset($Complete)) {
	$raidid = $_POST[live_raidid];
	$sessionid = $_POST[live_sessionid];
	$old_bossid = $_POST[live_bossid];
	$playing = $_POST[playing];
	$total_users = count($playing);
	$sql = $db->query("SELECT id FROM dkp_sessionhistory WHERE raidid=\"$raidid\"");
	if($db->count_rows($sql) > 0) {
		//Raid Information
		$bossid = @mysql_result($db->query("SELECT MIN(id) FROM dkp_sessionvalues WHERE id>\"$old_bossid\""), 0);
		$raidName = @mysql_result($db->query("SELECT raid FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$raidSessions = @mysql_result($db->query("SELECT sessions FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$oldBossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE id=\"$old_bossid\""), 0);
		$bossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE id=\"$bossid\""), 0);
		$bossValue = @mysql_result($db->query("SELECT value FROM dkp_sessionvalues WHERE id=\"$old_bossid\""), 0);
		$index = @mysql_result($db->query("SELECT session FROM dkp_sessionhistory WHERE id=\"$sessionid\""), 0);
		$index++;
		//Raid stats
		$totalOccurances = @mysql_result($db->query("SELECT occurances FROM dkp_stats WHERE raidid=\"$raidid\""), 0);
		$totalOccurances++;
		$db->query("UPDATE dkp_stats SET occurances=\"$totalOccurances\" WHERE raidid=\"$raidid\"");
		//Raid Process
		$db->query("UPDATE dkp_sessionhistory SET session=\"$index\" WHERE id=\"$sessionid\"");
		$db->query("UPDATE dkp_userhistory SET status='0' WHERE raidid=\"$raidid\"");
		for($i=0; $i<$total_users; $i++) {
			$userid = $playing[$i];
			$sql2 = $db->query("SELECT id FROM dkp_userhistory WHERE userid=\"$userid\"");
			//User was recently checked off, add him to the session history
			if($db->count_rows($sql2) < 1) { $db->query("INSERT INTO dkp_userhistory (userid, raidid, status) VALUES (\"$userid\", \"$raidid\", 1)"); }
			//Update users in raid
			$db->query("UPDATE dkp_userhistory SET status='1' WHERE userid=\"$userid\" AND raidid=\"$raidid\"");
			//Update user history
			$reason = $raidName . ": " . $oldBossName;
			$db->query("INSERT INTO dkp_tempadjustments (userid, raidid, sessionid, reason, value, pool) VALUES (\"$userid\", \"$raidid\", \"$sessionid\", \"$reason\", \"$bossValue\", '3')");
			$totalEvents = @mysql_result($db->query("SELECT events FROM dkp_users WHERE id=\"$userid\""), 0);
			$totalEvents++;
			$db->query("UPDATE dkp_users SET events=\"$totalEvents\" WHERE id=\"$userid\"");
		}
		//Prepare text file for download
		$last_raid = date("m/d/y");
		$datestamp = date("mdY");
		$timestamp = time();
		$history_filename = "raid-$raidid-$datestamp-$timestamp.txt";
		//Transfer data from temp rows to permanent rows
		$sql = mysql_query("SELECT * FROM dkp_tempadjustments WHERE raidid=\"$raidid\" ORDER BY userid ASC, id ASC");
		while($row = mysql_fetch_array($sql)) {	
			//update user points
			$class_points = mysql_result($db->query("SELECT class_points FROM dkp_users WHERE id=\"$row[userid]\""), 0) + $row[value];
			$general_points = mysql_result($db->query("SELECT class_points_general FROM dkp_users WHERE id=\"$row[userid]\""), 0) + $row[value];
			$db->query("UPDATE dkp_users SET class_points=\"$class_points\", class_points_general=\"$general_points\", last_raid_date=\"$last_raid\" WHERE id=\"$row[userid]\"");
			$db->query("INSERT INTO dkp_realadjustments (userid, raidid, reason, value, pool, date) VALUES (\"$row[userid]\", \"$row[raidid]\", \"$row[reason]\", \"$row[value]\", \"$row[pool]\", \"$row[date]\")");
			//** text file **//
			mysql_query("INSERT INTO dkp_raidhistory (raidid, filename) VALUES (\"$row[raidid]\", \"$datestamp\", \"$history_filename\")");
			//$userName = mysql_result(mysql_query("SELECT name FROM dkp_users WHERE id=\"$row[userid]\""), 0);
			//$file = fopen($history_filename, "a+");
			//fputs($file, $row['date'] . " - Character: " . $userName . ", Session: " . $row[reason] . ", Stats: (C)" . $class_points . " (G)" . $general_points . " (O)" . $overall_points . "\n");
		}
		//Delete temp data
		if(!$db->query("DELETE FROM dkp_userhistory WHERE raidid=\"$raidid\"")) { die(systemMessage("Database Error", mysql_error())); }
		if(!$db->query("DELETE FROM dkp_sessionhistory WHERE raidid=\"$raidid\"")) { die(systemMessage("Database Error", mysql_error())); }
		if(!$db->query("DELETE FROM dkp_tempadjustments WHERE raidid=\"$raidid\"")) { die(systemMessage("Database Error", mysql_error())); }
		die(systemMessage("Raid Complete", "Points have been automatically updated.", "?d=admin&s=startraid"));
	}
	else {
		die(systemMessage("Raid Error", "The raid that you are trying to continue, no longer exists.", "?d=admin&s=startraid"));
	}
}
/**************************************
 * Continue a saved Raid
 * -Must be executed last
 * -otherwise, you wouldn't be able to
 * -complete a saved raid since it would
 * -never execute.
 **************************************/
elseif(isset($sessionid)) {
	$sql = $db->query("SELECT id FROM dkp_sessionhistory WHERE id=\"$sessionid\"");
	if($db->count_rows($sql) > 0) {
		$raidid = @mysql_result($db->query("SELECT raidid FROM dkp_sessionhistory WHERE id=\"$sessionid\""), 0);
		$raidName = @mysql_result($db->query("SELECT raid FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$index = @mysql_result($db->query("SELECT session FROM dkp_sessionhistory WHERE id=\"$sessionid\""), 0);
		$raidSessions = @mysql_result($db->query("SELECT sessions FROM dkp_sessions WHERE id=\"$raidid\""), 0);
		$bossValue = @mysql_result($db->query("SELECT value FROM dkp_sessionvalues WHERE raidid=\"$raidid\""), $index-1);
		$bossName = @mysql_result($db->query("SELECT boss FROM dkp_sessionvalues WHERE raidid=\"$raidid\""), $index-1);
		$bossid = @mysql_result($db->query("SELECT id FROM dkp_sessionvalues WHERE raidid=\"$raidid\""), $index-1);
	}
	else {
		die(systemMessage("Raid Error", "Can not load the raid that you have chosen.<br>".mysql_error(), "?d=admin&s=startraid"));
	}
}
/************************
 * Error - Raid not found
 ************************/
else {
	die(systemMessage("Raid Error", "The raid that you are trying to continue can not be found.", "?d=admin&s=startraid"));
}
?>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
  <tr>
    <td bgcolor="#003366"><font color="#FFFFFF" size="2" face="Tahoma"><strong>Continue 
      Raid</strong></font></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
  <tr> 
    <td colspan="2" bgcolor="#003366"><font color="#CCCCCC" size="1" face="Tahoma"><strong>Raid Details</strong></font></td>
  </tr>
  <tr> 
    <td width="15%" bgcolor="#999999"><u><strong><font size="1" face="Tahoma">Instance</font></strong></u></td>
    <td bgcolor="#CCCCCC"><strong><font size="1" face="Tahoma"><?php echo $raidName; ?></font></strong></td>
  </tr>
  <tr> 
    <td bgcolor="#999999"><u><strong><font size="1" face="Tahoma">Boss</font></strong></u></td>
    <td bgcolor="#CCCCCC"><strong><font size="1" face="Tahoma"><?php echo $bossName; ?></font></strong></td>
  </tr>
  <tr> 
    <td bgcolor="#999999"><u><strong><font size="1" face="Tahoma">Status</font></strong></u></td>
    <td bgcolor="#CCCCCC"><strong><font size="1" face="Tahoma"><?php echo $index; ?> / <?php echo $raidSessions; ?></font></strong></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><form action="" method="post" name="formContinueRaid" id="formContinueRaid">
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td colspan="4" bgcolor="#003366"><font color="#CCCCCC" size="1" face="Tahoma"><strong>Participating 
              Players </strong></font></td>
          </tr>
          <tr> 
            <td bgcolor="#999999"><div align="center"><u><strong><font size="1" face="Tahoma">P</font></strong></u></div></td>
            <td width="33%" bgcolor="#999999"><u><strong><font size="1" face="Tahoma">Character</font></strong></u></td>
            <td width="33%" bgcolor="#999999"><u><strong><font size="1" face="Tahoma">Class 
              Points</font></strong></u></td>
            <td width="33%" bgcolor="#999999"><u><strong><font size="1" face="Tahoma">General 
              Points</font></strong></u></td>
          </tr>
<?php
$dir = "ASC";
$sort = "name" . " " . $dir;
$sql = $db->query("SELECT * FROM dkp_users ORDER BY $sort");
if($db->count_rows($sql) > 0) {
	while($row = mysql_fetch_array($sql)) {
		$userid = $row[id];
		$character = $row[name];
		$class_points = $row[class_points];
		$general_points = $row[class_points_general];
		
		$sql2 = $db->query("SELECT * FROM dkp_userhistory WHERE userid=\"$userid\" AND status='1' AND raidid=\"$raidid\"");
		if($db->count_rows($sql2) > 0) { $isPlaying = true; }
		else { $isPlaying = false; }
?>		  
          <tr> 
            <td bgcolor="#CCCCCC"><input name="playing[]" type="checkbox" id="playing[]" value="<?php echo $userid; ?>" <?php if($isPlaying) { echo "checked"; } ?>></td>
            <td bgcolor="#CCCCCC"><a href="?d=admin&s=awardloot&userid=<?php echo $userid; ?>&raidid=<?php echo $raidid; ?>&sessionid=<?php echo $sessionid; ?>"><font color="#000000" size="1" face="Tahoma"><strong><?php echo $character; ?></strong></font></a></td>
            <td bgcolor="#CCCCCC"><strong><font size="1" face="Tahoma"><?php echo $class_points; ?></font></strong></td>
            <td bgcolor="#CCCCCC"><strong><font size="1" face="Tahoma"><?php echo $general_points; ?></font></strong></td>
          </tr>
<?php
	}
}
else {
?>		  
          <tr> 
            <td colspan="4" bgcolor="#CCCCCC"><font color="#000000" size="1" face="Tahoma"><strong>There 
              are no players in this category.</strong></font></td>
          </tr>
<?php
}
?>
          <tr> 
            <td colspan="4" bgcolor="#CCCCCC"><?php if($index < $raidSessions) {?><input name="Continue" type="submit" id="Continue" value="Continue"><?php } ?>
              <input name="Complete" type="submit" id="Complete" value="Complete">
              <input name="live_raidid" type="hidden" id="live_raidid" value="<?php echo $raidid; ?>">
              <input name="live_bossid" type="hidden" id="live_bossid" value="<?php echo $bossid; ?>">
              <input name="live_sessionid" type="hidden" id="live_sessionid" value="<?php echo $sessionid; ?>">
            </td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
Return current item: Guild DKP System