Location: PHPKode > projects > Guild DKP System > dkpsystem1.4/includes/admin/updatesessions.php
<?php
$Save = $_POST[Save];
$Create = $_POST[Create];
$action = $_GET[action];
if(isset($Save)) {
	$txtInstance = $_POST[txtInstance];
	$selectSessions = $_POST[selectSessions];
	$sessionid = $_POST[sessionid];
	$totalinstances = count($txtInstance);
	
	for($i=0; $i<$totalinstances; $i++) {
		$instance = $txtInstance[$i];
		$sessions = $selectSessions[$i];
		$id = $sessionid[$i];
		$sql = $db->query("UPDATE dkp_sessions SET raid=\"$instance\", sessions=\"$sessions\" WHERE id=\"$id\"");
		if(!$sql) {
			die(systemMessage("Database Error", mysql_error()));
		}
	}
	die(systemMessage("Sessions Updated", "Your settings have been saved."));
}
elseif(isset($Create)) {
	$txtInstance = $_POST[txtInstance];
	$sql = $db->query("INSERT INTO dkp_sessions (raid, sessions) VALUE (\"$txtInstance\", \"20\")");
	if(!$sql) {
		die(systemMessage("Database Error", mysql_error()));
	}
	$raidid = @mysql_result($db->query("SELECT id FROM dkp_sessions WHERE raid=\"$txtInstance\""), 0);
	$db->query("INSERT INTO dkp_stats (raidid) VALUES (\"$raidid\")");
	for($i=1; $i<=20; $i++) {
		$sql2 = $db->query("INSERT INTO dkp_sessionvalues (raidid, boss, value) VALUES (\"$raidid\", \"Boss Name\", \"Boss Value\")");
		if(!$sql2) {
			die(systemMessage("Database Error", mysql_error()));
		}
	}
	die(systemMessage("Sessions Updated", "You have successfully created a new session named '$txtInstance'"));
}
elseif(isset($action) && $action == "delete") {
	$sessionid = $_GET[sessionid];
	$sql = $db->query("SELECT id FROM dkp_sessions WHERE id=\"$sessionid\"");
	if($db->count_rows($sql) > 0) {
		$db->query("DELETE FROM dkp_sessionvalues WHERE raidid=\"$sessionid\"");
		$db->query("DELETE FROM dkp_sessions WHERE id=\"$sessionid\"");
	}
	die(systemMessage("Session Deleted", "You have successfully deleted this session."));
}
?>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
  <tr>
    <td bgcolor="#003366"><font color="#FFFFFF" size="2" face="Tahoma"><strong>Update Sessions</strong></font></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><form action="" method="post" name="formUpdateSessions" id="formUpdateSessions">
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td colspan="2" bgcolor="#003366"><font color="#CCCCCC" size="1" face="Tahoma"><strong>Current 
              Sessions</strong></font></td>
          </tr>
          <?php
$sql = $db->query("SELECT * FROM dkp_sessions ORDER BY raid ASC");
if($db->count_rows($sql) > 0) {
	while($row = mysql_fetch_array($sql)) {
		$sessionid = $row[id];
		$instance = $row[raid];
		$sessions = $row[sessions];
		
		$color1 = "#CCCCCC";
		$color2 = "#D7D7D7";
		$row_color = ($row_count % 2) ? $color1 : $color2;
		$row_count++;
?>
          <tr bgcolor="<?php echo $row_color; ?>"> 
            <td width="15%"> <input name="txtInstance[]" type="text" id="txtInstance[]" value="<?php echo $instance; ?>" size="35"></td>
            <td> <select name="selectSessions[]" id="selectSessions[]">
                <option><?php echo $sessions; ?></option>
                <option>--</option>
                <?php
				for($i=1; $i<=20; $i++) {
					echo "<option value=\"$i\">$i</option>\n";
				}
				?>
              </select>
              <input name="sessionid[]" type="hidden" id="sessionid[]" value="<?php echo $sessionid; ?>">
              <a href="?d=admin&s=updatesessions&action=delete&sessionid=<?php echo $sessionid; ?>"><font color="#000000" size="1" face="Tahoma"><strong>remove</strong></font></a></td>
          </tr>
          <?php
	}
?>
        <tr bgcolor="#CCCCCC"> 
            <td colspan="2"><font color="#000000" size="1" face="Tahoma">
              <input name="Save" type="submit" id="Save3" value="Save">
              </font></td>
          </tr>
<?php
}
else {
?>
  
          <tr bgcolor="#CCCCCC"> 
            <td colspan="2"><font color="#000000" size="1" face="Tahoma"><strong>There 
              are no instances recorded.</strong></font> <font color="#000000" size="1" face="Tahoma">&nbsp; 
              </font></td>
          </tr>
          <?php
}
?>
        </table>
      </form></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><form action="" method="post" name="formNewSession" id="formNewSession">
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td bgcolor="#003366"><font color="#CCCCCC" size="1" face="Tahoma"><strong>Create 
              Session</strong></font></td>
          </tr>
          <tr> 
            <td bgcolor="#CCCCCC"><input name="txtInstance" type="text" id="txtInstance" size="35"></td>
          </tr>
          <tr>
            <td bgcolor="#CCCCCC"><input name="Create" type="submit" id="Create" value="Create"></td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
Return current item: Guild DKP System